146 lines
4 KiB
PHP
146 lines
4 KiB
PHP
<?php
|
|
if (!defined("LIBLISTEDA_INC")){
|
|
define(LIBLISTEDA_INC,1);
|
|
|
|
/*
|
|
* classe qui correspond a une liste de DA
|
|
*/
|
|
class ListeDA {
|
|
var $_numDA;
|
|
var $_liste;
|
|
var $_id_mag;
|
|
var $_libelle;
|
|
|
|
function ListeDA($libelle,$id_mag) {
|
|
$this->_numDA=0;
|
|
$this->_liste=array();
|
|
// si id_mag < 0 alors on prend tous les id_mag
|
|
$this->_id_mag=$id_mag;
|
|
$this->_libelle=$libelle;
|
|
}
|
|
|
|
|
|
function ajouteDA($da) {
|
|
//$da = new DemandeAchat(0);
|
|
$this->_liste[$this->_numDA]=&$da;
|
|
$this->_numDA++;
|
|
}
|
|
|
|
function supprimeDA($Cases_supp) {
|
|
// on cherche les lignes selectionnees pour la suppression
|
|
if (is_array($Cases_supp)){
|
|
while( list($case,$val) = each($Cases_supp) ){
|
|
// on supprime les DA selectionnees de la BD
|
|
|
|
// tout d'abord de la BD
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
|
|
if(!$connexion) {
|
|
echo "Erreur serveur mysql $connexion";
|
|
}
|
|
|
|
// on supprime également les états des lignes d'achat
|
|
// associees
|
|
$requete="SELECT numero_lda FROM Ligne_d_achat "
|
|
."WHERE numero_da='$val'";
|
|
$result=mysql_db_query(SQL_BASE, $requete, $connexion)
|
|
or die(mysql_error($connexion));
|
|
|
|
while($row=mysql_fetch_object($result)) {
|
|
$requete_ela="DELETE FROM Etats_LA "
|
|
."WHERE numero_lda='".$row->numero_lda."'";
|
|
$result_ela=mysql_db_query(SQL_BASE, $requete_ela, $connexion);
|
|
if (!$result_ela){
|
|
print "<span class=\"error\">";
|
|
print mysql_error($connexion);
|
|
print "</span>";
|
|
}
|
|
|
|
}
|
|
// ainsi que les LDA elles-même
|
|
$requete_lda="DELETE FROM Ligne_d_achat "
|
|
."WHERE numero_da='$val'";
|
|
$resultat=mysql_db_query(SQL_BASE, $requete_lda, $connexion);
|
|
if (!$resultat){
|
|
print "<span class=\"error\">";
|
|
print mysql_error($connexion);
|
|
print "</span>";
|
|
}
|
|
|
|
// et enfin la demande
|
|
$requete="DELETE FROM Demande_d_achat "
|
|
."WHERE numero_da='$val'";
|
|
//.$this->_liste[$idx]->_numero."'";
|
|
$result=mysql_db_query(SQL_BASE, $requete, $connexion)
|
|
or die(mysql_error($connexion));
|
|
|
|
// ensuite du tableau liste
|
|
}
|
|
|
|
// on reindexe le tableau
|
|
$this->loadListe();
|
|
}
|
|
}
|
|
|
|
function loadListe() {
|
|
// rempli l'objet ListeDA a partir de la base pour l'id id_mag
|
|
$connexion = @mysql_connect(SQL_SERVER,SQL_USER,SQL_PASSWD);
|
|
|
|
if(!$connexion) {
|
|
echo "Erreur serveur mysql $connexion";
|
|
}
|
|
|
|
if($libelle!="TOUTES") {
|
|
$requete="SELECT Ligne_d_achat.numero_da "
|
|
."FROM Ligne_d_achat, Etats_LA, Demande_d_achat "
|
|
."WHERE Libelle='".$this->_libelle."' ";
|
|
if ($this->_id_mag>0){
|
|
$requete.="AND Demande_d_achat.id_magasinier='".$this->_id_mag."' ";
|
|
}
|
|
$requete.="AND Demande_d_achat.numero_da=Ligne_d_achat.numero_da "
|
|
."AND Ligne_d_achat.numero_lda=Etats_LA.numero_lda "
|
|
."GROUP BY Ligne_d_achat.numero_da";
|
|
}
|
|
else {
|
|
$requete="SELECT numero_da FROM Demande_d_achat";
|
|
if ($this->_id_mag>0){
|
|
$requete.=" WHERE id_magasinier='".$this->_id_mag."'";
|
|
}
|
|
}
|
|
|
|
$result=mysql_db_query(SQL_BASE, $requete, $connexion)
|
|
or die(mysql_error($connexion));
|
|
|
|
$this->_numDA=0;
|
|
$this->_liste=array();
|
|
while($row=mysql_fetch_array($result)) {
|
|
$da=new DemandeAchat($this->_id_mag);
|
|
$da->_numero=$row[0];
|
|
$da->load($row[0]);
|
|
$this->ajouteDA($da);
|
|
}
|
|
|
|
}
|
|
|
|
function toHTML($editable=1) {
|
|
for($i=0; $i<$this->_numDA; $i++) {
|
|
$content.="<fieldset>";
|
|
$content.="<legend>\n";
|
|
if ($editable) {
|
|
$content.="<input type=\"checkbox\" "
|
|
."id=\"demande_achat[]\" "
|
|
."name=\"demande_achat[]\" "
|
|
."value=\"".$this->_liste[$i]->_numero."\" "
|
|
.">";
|
|
}
|
|
$content.="Demande Achat n°".$this->_liste[$i]->_numero."</legend>\n";
|
|
$content.=$this->_liste[$i]->toHTML(0);
|
|
$content.="</fieldset>";
|
|
$content.="<br />";
|
|
}
|
|
return $content;
|
|
}
|
|
}// fin classe ListeDA
|
|
|
|
}
|
|
?>
|