//$VarFname=$NOMC."_name"; // ancienne m�hode
        //$PYAoMAJ->Fname=($$VarFname !="" ? $$VarFname : $_FILES[$NOMC]['name']);
        $PYAoMAJ->Fname = $_FILES[$NOMC]['name'];
        //$VarFsize=$NOMC."_size";// ancienne m�hode
        //$PYAoMAJ->Fsize=($$VarFsize!="" ? $$VarFsize : $_FILES[$NOMC]['size']);
        $PYAoMAJ->Fsize = $_FILES[$NOMC]['size'];
        $VarOldFName = "Old" . $NOMC;
        $PYAoMAJ->OFN = ${$VarOldFName};
        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 {
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());
}
Esempio n. 3
0
  if ($PYAoMAJ->TypeAff=="FICFOT") {
     $VarFok="Fok".$NOMC;
     $PYAoMAJ->Fok=$$VarFok;
     $VarFname=$NOMC."_name";
     $PYAoMAJ->Fname=$$VarFname;
     $VarFsize=$NOMC."_size";
     $PYAoMAJ->Fsize=$$VarFsize;
     $VarOldFName="Old".$NOMC;
     $PYAoMAJ->OFN=$$VarOldFName;
     if ($modif==-1) { // suppression de l'enregistrement
        $rqncs=msq("select ".$PYAoMAJ->NmChamp." from ".$PYAoMAJ->NmTable." where $key ");
        $rwncs=mysql_fetch_array($rqncs);
        $PYAoMAJ->Fname=$rwncs[0];
        }
     }
  $set.=$PYAoMAJ->RetSet($keycopy); // key copy sert à la gestion des fichiers liés
  // la gestion des fichiers est faite aussi là-dedans

  } // fin boucle sur les champs
  
$set= substr($set,0,-2); // enlève la dernière virgule et esp en trop à la fin

$key="SOC_NUSOCIE='$SOC_NUSOCIE'";
$where=" where ".$key;

if ($modif==1) // Si on vient d'une édition
  {
  $strqaj="UPDATE $NM_TABLE SET $set $where";
  }
else if ($modif==-1) // // Si on vient d'une suppression
  {