function PYATableMAJ($DB,$table,$typedit,$tbKeys=array()) {
	// construction du set, necessite uniquement le nom du champ ..
	$rq1=db_query("SELECT * from DESC_TABLES where NM_TABLE='$table' AND NM_CHAMP!='TABLE0COMM' AND (TYPEAFF!='HID' OR ( TT_PDTMAJ!='' AND TT_PDTMAJ!= NULL)) ORDER BY ORDAFF, LIBELLE");

	$key = implode("_",$tbKeys)."_";
	$tbset = array();
	$tbWhK = array();
	while ($res1 = db_fetch_array($rq1)) {
		$PYAoMAJ=new PYAobj(); // recréée l'objet pour RAZ ses propriétés !!!
		$PYAoMAJ->NmBase=$DB;
		$PYAoMAJ->NmTable=$table;
		$PYAoMAJ->TypEdit=$typedit;
		if (MaxFileSize>0) $PYAoMAJ->MaxFSize=MaxFileSize;

		$NOMC = $res1['NM_CHAMP']; // nom variable=nom du champ
		$PYAoMAJ->NmChamp = $NOMC;
		$PYAoMAJ->InitPO($_REQUEST[$NOMC],$res1); // init l'objet, sa valeur, lui passe le tableau d'infos du champ pr éviter une requete suppl.
		if (array_key_exists($NOMC,$tbKeys)) {
			$tbWhK = array_merge($tbWhK,$PYAoMAJ->RetSet($key."_",true));
		} 
		$PYAoMAJ->ValChp=$_REQUEST[$NOMC]; // sinon en new ca bugue
		if ($PYAoMAJ->TypeAff=="FICFOT") {
			if ($_FILES[$NOMC]['name']!="" && $_FILES[$NOMC]['error']!="0") {
				$error=$_FILES[$NOMC]['error'];
				$err_lbl="Erreur sur le champ $NOMC de type http";
			}
			$PYAoMAJ->ValChp=($_FILES[$NOMC]['tmp_name']!="" ? $_FILES[$NOMC]['tmp_name'] : $PYAoMAJ->ValChp);
			$PYAoMAJ->Fok=$_REQUEST["Fok".$NOMC];
			$PYAoMAJ->Fname=$_FILES[$NOMC]['name'];
			$PYAoMAJ->Fsize=$_FILES[$NOMC]['size'];
			$PYAoMAJ->OFN=$_REQUEST["Old".$NOMC];
			// recup infos pour les pj dans le mail     
			$size=($PYAoMAJ->Fsize >0 ? " (".round($PYAoMAJ->Fsize / 1000)."Ko) " : "");
			$chemfich="http://".$_SERVER["SERVER_NAME"].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']).$PYAoMAJ->Valeurs;
			$fich=($PYAoMAJ->Fname != "" ? $key."_".$PYAoMAJ->Fname : $PYAoMAJ->ValChp);
		}
		$tbset=array_merge($tbset,$PYAoMAJ->RetSet($key."_",true)); // key sert �la gestion des fichiers li�
		if ($PYAoMAJ->error) {
			$error=true;
			$err_lbl="Erreur sur le champ $NOMC genree par pya :".$PYAoMAJ->error;
			$PYAoMAJ->error="";
		}
	} // fin boucle sur les champs
	
	if (count($tbWhK)>0) {
		foreach ($tbWhK as $chp=>$val) $lchp[]=$chp."=$val";
		
		$where= " where ".implode(" AND ",$lchp);
	}
	// GROS BUG  $where=" where ".$key.($where_sup=="" ? "" : " and $where_sup");
	//echovar("_REQUEST['typeditrcr']");
	if ($typedit=="M") { // UPDATE
		$strqaj="UPDATE $table SET ".tbset2set($tbset)." $where";
	} elseif ($typedit==-1) { // SUPPRESSION
		$strqaj="DELETE FROM $table $where";
	} elseif ($typedit=="N") { //INSERTION
		$strqaj="INSERT INTO $table ".tbset2insert($tbset)." ON DUPLICATE KEY UPDATE ".tbset2set($tbset);
	}
//	echo "requete sql: $strqaj";
	db_query($strqaj);
	if ($typedit == "N") return(mysql_insert_id());
}
        if ($_REQUEST['modif'] == -1) {
            // suppression de l'enregistrement
            $rqncs = msq("select " . $PYAoMAJ->NmChamp . " from " . $PYAoMAJ->NmTable . " where " . stripslashes($_REQUEST['key']));
            $rwncs = db_fetch_row($rqncs);
            $PYAoMAJ->Fname = $rwncs[0];
        }
    }
    $tbset = array_merge($tbset, $PYAoMAJ->RetSet($keycopy, true));
    // key copy sert �la gestion des fichiers li�
    // la gestion des fichiers est faite aussi l�dedans
}
// fin boucle sur les champs
//echovar("tbset");
$_REQUEST['key'] = stripslashes($_REQUEST['key']);
//echo "Cl� $_REQUEST['key'] <BR>";
// GROS BUG  $where=" where ".$_REQUEST['key'].($where_sup=="" ? "" : " and $where_sup");
$where = " where " . $_REQUEST['key'];
if ($_REQUEST['modif'] == 1) {
    $strqaj = "UPDATE {$CSpIC}{$NM_TABLE}{$CSpIC} SET " . tbset2set($tbset) . " {$where}";
} else {
    if ($_REQUEST['modif'] == -1) {
        $strqaj = "DELETE FROM {$CSpIC}{$NM_TABLE}{$CSpIC} {$where}";
    } else {
        // Ajout dans la table Mysql
        $strqaj = "INSERT INTO {$CSpIC}{$NM_TABLE}{$CSpIC} " . tbset2insert($tbset);
    }
}
//echo "requete sql: $strqaj";
db_query($strqaj);
header("location:" . ($lc_adrramact ? $lc_adrramact : ret_adrr("edit_table.php") . "?cfp=amact"));
// lc_adrramact=sp�ial e-toil*/
Beispiel #3
0
            $PYAoMAJ->Fname = $rwncs[0];
        }
    }
    $tbset = array_merge($tbset, $PYAoMAJ->RetSet($keycopy, true));
    // key copy sert à la gestion des fichiers liés
    // la gestion des fichiers est faite aussi là-dedans
}
// fin boucle sur les champs
//echovar("tbset");
$key = stripslashes($key);
if ($debug) {
    echo "Clé: {$key} <BR>";
}
// GROS BUG  $where=" where ".$key.($where_sup=="" ? "" : " and $where_sup");
$where = " where " . $key;
if ($modif == 1) {
    $strqaj = "UPDATE " . $_REQUEST['NM_TABLE'] . " SET " . tbset2set($tbset) . " {$where}";
} else {
    if ($modif == -1) {
        $strqaj = "DELETE FROM " . $_REQUEST['NM_TABLE'] . " {$where}";
    } else {
        // Ajout dans la table Mysql
        $strqaj = "INSERT INTO " . $_REQUEST['NM_TABLE'] . " " . tbset2insert($tbset);
    }
}
if ($debug) {
    echo "requete sql: {$strqaj}";
}
msq($strqaj);
header("location:" . $_REQUEST['adrr_majt']);
//
            if ($modif == -1) {
                // suppression de l'enregistrement
                $rqncs = msq("select " . $PYAoMAJ->NmChamp . " from " . $PYAoMAJ->NmTable . " where {$key} ");
                $rwncs = db_fetch_row($rqncs);
                $PYAoMAJ->Fname = $rwncs[0];
            }
        }
        $tbset = array_merge($tbset, $PYAoMAJ->RetSet($keycopy, true));
    }
    // fin boucle sur les champs
    $set = substr($set, 0, -2);
    // enlève la dernière virgule et esp en trop à la fin
    if ($_GET['action'] == 'ajout') {
        $db->query("INSERT INTO `ENTITES` SET " . tbset2set($tbset));
    } elseif ($_GET['action'] == 'edition') {
        $db->query("UPDATE `ENTITES` SET " . tbset2set($tbset) . " WHERE `ENT_ID`='" . (int) $_GET['id'] . "'");
    }
    // ferme la fenetre & rafraichie la fenetre parent
    echo '<script language="javascript">window.opener.location.reload();window.close();</script>';
}
// initialisation de ts les objets PYA de la table
$sqlpo = 'SELECT * FROM `DESC_TABLES` WHERE `NM_TABLE`="ENTITES" AND `NM_CHAMP`!="TABLE0COMM" ORDER BY `ORDAFF`';
$rep = $db->query($sqlpo);
while ($data = $db->fetch_array()) {
    $NM_CHAMP = $data['NM_CHAMP'];
    $CIL[$NM_CHAMP] = new PYAobj();
    $CIL[$NM_CHAMP]->NmBase = $DBName;
    $CIL[$NM_CHAMP]->NmTable = 'ENTITES';
    $CIL[$NM_CHAMP]->NmChamp = $NM_CHAMP;
    //	$CIL[$NM_CHAMP]->TypEdit='';
    $CIL[$NM_CHAMP]->InitPO();
             $VarFsize = $NOMC . "_size";
             // ancienne méthode
             $PYAoMAJ->Fsize = ${$VarFsize} != "" ? ${$VarFsize} : $_FILES[$NOMC][size];
             $VarOldFName = "Old" . $NOMC;
             $PYAoMAJ->OFN = ${$VarOldFName};
             if ($modif == -1) {
                 // suppression de l'enregistrement
                 $rqncs = msq("select " . $PYAoMAJ->NmChamp . " from " . $PYAoMAJ->NmTable . " where {$key} ");
                 $rwncs = db_fetch_row($rqncs);
                 $PYAoMAJ->Fname = $rwncs[0];
             }
         }
         $tbset = array_merge($tbset, $PYAoMAJ->RetSet($keycopy, true));
     }
     // fin boucle sur les champs
     $db->query('INSERT INTO `PERSONNES` SET ' . tbset2set($tbset));
     $_SESSION['per_id'] = mysql_insert_id();
 }
 // traitement des champs spécifique
 // ----------------------------------------
 $aep_fonction = addslashes($_POST['AEP_FONCTION']);
 $aep_tel = addslashes($_POST['AEP_TEL']);
 $aep_fax = addslashes($_POST['AEP_FAX']);
 $aep_mobile = addslashes($_POST['AEP_MOBILE']);
 $aep_abrege = addslashes($_POST['AEP_ABREGE']);
 $aep_email = addslashes($_POST['AEP_EMAIL']);
 $aep_privatecomment = addslashes($_POST['AEP_PRIVATECOMMENT']);
 $set = '`AEP_FONCTION`="' . $aep_fonction . '",`AEP_TEL`="' . $aep_tel . '",`AEP_FAX`="' . $aep_fax . '",`AEP_MOBILE`="' . $aep_mobile . '",`AEP_ABREGE`="' . $aep_abrege . '",`AEP_EMAIL`="' . $aep_email . '",`AEP_PRIVATECOMMENT`="' . $aep_privatecomment . '" , `PERSONNES_PER_ID`="' . $_SESSION['per_id'] . '", `ENTITES_ENT_ID`="' . $_SESSION['ent_id'] . '", `AEP_DTCREA`=CURDATE(), `AEP_COOPE`="' . $_SESSION['auth_id'] . '" ';
 $db->query('INSERT INTO `AFFECTE_ENTITES_PERSONNES` SET ' . $set);
 $_SESSION['per_id'] = '';
 $_SESSION['ent_id'] = '';
            $VarFsize = $NOMC . "_size";
            // ancienne méthode
            $PYAoMAJ->Fsize = ${$VarFsize} != "" ? ${$VarFsize} : $_FILES[$NOMC][size];
            $VarOldFName = "Old" . $NOMC;
            $PYAoMAJ->OFN = ${$VarOldFName};
            if ($modif == -1) {
                // suppression de l'enregistrement
                $rqncs = msq("select " . $PYAoMAJ->NmChamp . " from " . $PYAoMAJ->NmTable . " where {$key} ");
                $rwncs = db_fetch_row($rqncs);
                $PYAoMAJ->Fname = $rwncs[0];
            }
        }
        $tbset = array_merge($tbset, $PYAoMAJ->RetSet($keycopy, true));
    }
    // fin boucle sur les champs
    $db->query("UPDATE `PERSONNES` SET " . tbset2set($tbset) . " WHERE `PER_ID`='" . $_GET['per_id'] . "'");
    // traitement des champs spécifique
    // ----------------------------------------
    $aep_fonction = addslashes($_POST['AEP_FONCTION']);
    $aep_tel = addslashes($_POST['AEP_TEL']);
    $aep_fax = addslashes($_POST['AEP_FAX']);
    $aep_mobile = addslashes($_POST['AEP_MOBILE']);
    $aep_abrege = addslashes($_POST['AEP_ABREGE']);
    $aep_email = addslashes($_POST['AEP_EMAIL']);
    $aep_privatecomment = addslashes($_POST['AEP_PRIVATECOMMENT']);
    $set = '`AEP_FONCTION`="' . $aep_fonction . '",`AEP_TEL`="' . $aep_tel . '",`AEP_FAX`="' . $aep_fax . '",`AEP_MOBILE`="' . $aep_mobile . '",`AEP_ABREGE`="' . $aep_abrege . '",`AEP_EMAIL`="' . $aep_email . '",`AEP_PRIVATECOMMENT`="' . $aep_privatecomment . '", `AEP_DTCREA`=CURDATE(),`AEP_COOPE`="' . $_SESSION['auth_id'] . '"';
    $db->query('UPDATE `AFFECTE_ENTITES_PERSONNES` SET ' . $set . ' WHERE `PERSONNES_PER_ID`="' . $_GET['per_id'] . '" AND `ENTITES_ENT_ID`="' . $_GET['ent_id'] . '" ');
    // ferme la fenetre & rafraichie la fenetre parent
    echo '<script language="javascript">window.opener.location.reload();window.close();</script>';
} else {
    echo '<h2>Informations communes<h2>';