-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec_ajouter_fiche.php
68 lines (55 loc) · 1.83 KB
/
exec_ajouter_fiche.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once("connexion.php");
$etudes=new MesEtudes;
function formater($type,$valeur) {
$valeur= str_replace("'","''", $valeur);
if (strpos($type,'date')!== false) {
$valeur= str_replace("/","-", $valeur);
if(($valeur=='--') OR ($valeur=='')){return 'NULL';};
$fdate = explode('-',$valeur);
return "'".$fdate[0].'-'.$fdate[1].'-'.$fdate[2]."'";
};
if (strpos($type,'montant')!== false) {
$valeur= str_replace(",",".", $valeur);
$valeur= str_replace(" ","", $valeur);
if ($valeur=='') {return "0.00";};
return number_format($valeur, 2, '.', '');
};
if (strpos($type,'pourcentage')!== false) {
$valeur= str_replace(",",".", $valeur);
$valeur= str_replace(" ","", $valeur);
$valeur = round($valeur,0);
return $valeur;
};
if (strpos($type,'abandon')!== false) {
if ($valeur=='oui') {return 'true';};
return 'false';
};
if (strpos($type,'priorite')!== false) {
if ($valeur=='') {$valeur =0;};
return $valeur;
};
if ((strpos($type,'service')!== false) or (strpos($type,'pilotage_ddtm')!== false)) {
$valeur= str_replace('\"','"', $valeur);
}
return "'". $valeur."'";
}
$nomtable=$etudes->get_nomtablecomplet("etudes");
$id_etude = $etudes->get_value("id_etude");
$champ = explode(',',$etudes->_liste_champs_etude);
$values ="[]";
$champs_retenus ="[]";
foreach($champ as $element) {
if (isset($_GET[$element])) {
$values .=",".formater($element,$_GET[$element]);
$champs_retenus.=",".$element;
};
}
$values=str_replace('[],','',$values);
$champs_retenus=str_replace('[],','',$champs_retenus);
$requete = 'insert into ' . $nomtable . ' ('.$champs_retenus.') VALUES ('.$values.') returning '.$id_etude;
$result = $etudes->exec_requete($requete) ;
$row = $result->fetch(PDO::FETCH_ASSOC);
echo $row[$id_etude];
//echo $requete;
?>