1 |
<?php |
2 |
//$Id$ |
3 |
//gen openMairie le 02/05/2013 15:03 |
4 |
|
5 |
require_once ("../gen/obj/document_numerise.class.php"); |
6 |
|
7 |
class document_numerise extends document_numerise_gen { |
8 |
|
9 |
function document_numerise($id,&$db,$debug) { |
10 |
$this->constructeur($id,$db,$debug); |
11 |
}// fin constructeur |
12 |
|
13 |
function setType(&$form,$maj) { |
14 |
parent::setType($form,$maj); |
15 |
//type |
16 |
if ($maj==0){ //ajout |
17 |
$form->setType('nom_fichier','hidden'); |
18 |
if($this->retourformulaire == "") { |
19 |
$form->setType('uid','upload'); |
20 |
} else { |
21 |
$form->setType('uid','upload2'); |
22 |
} |
23 |
if($this->retourformulaire=='dossier_instruction' |
24 |
and $form->val['dossier'] == $this->getParameter('idxformulaire')) { |
25 |
$form->setType('dossier','hidden'); |
26 |
} else { |
27 |
$form->setType('dossier','select'); |
28 |
} |
29 |
}// fin ajout |
30 |
if ($maj==1){ //modifier |
31 |
$form->setType('nom_fichier','hiddenstatic'); |
32 |
if($this->retourformulaire == "") { |
33 |
$form->setType('uid','upload'); |
34 |
} else { |
35 |
$form->setType('uid','upload2'); |
36 |
} |
37 |
if($this->retourformulaire=='dossier_instruction' |
38 |
and $form->val['dossier'] == $this->getParameter('idxformulaire')) { |
39 |
$form->setType('dossier','hidden'); |
40 |
} else { |
41 |
$form->setType('dossier','select'); |
42 |
} |
43 |
}// fin modifier |
44 |
|
45 |
// Mode supprimer |
46 |
if ($maj==2){ |
47 |
$form->setType('nom_fichier','filestatic'); |
48 |
} |
49 |
|
50 |
if ($maj==3){ //modifier |
51 |
$form->setType('nom_fichier','hiddenstatic'); |
52 |
} |
53 |
} |
54 |
|
55 |
function setValsousformulaire(&$form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,&$db,$DEBUG=null){ |
56 |
parent::setValsousformulaire($form,$maj,$validation,$idxformulaire,$retourformulaire,$typeformulaire,$db,$DEBUG); |
57 |
$this->retourformulaire = $retourformulaire; |
58 |
if($validation == 0) { |
59 |
if($retourformulaire =='dossier' OR $retourformulaire =='dossier_instruction') { |
60 |
$form->setVal('dossier', $idxformulaire); |
61 |
} |
62 |
}// fin validation |
63 |
}// fin setValsousformulaire |
64 |
|
65 |
|
66 |
/** |
67 |
* Méthode de traitement des données retournées par le formulaire |
68 |
*/ |
69 |
function setvalF($val) { |
70 |
parent::setvalF($val); |
71 |
|
72 |
//Génération automatique nom du fichier |
73 |
$this->valF['nom_fichier'] = $this->generateFilename($this->valF["date_creation"], $this->get_document_numerise_type_code_by_id($this->valF["document_numerise_type"])); |
74 |
|
75 |
} |
76 |
|
77 |
/** |
78 |
* Surcharge du bouton retour des sous-formulaire |
79 |
*/ |
80 |
function retoursousformulaire($idxformulaire, $retourformulaire, $val, |
81 |
$objsf, $premiersf, $tricolsf, $validation, |
82 |
$idx, $maj, $retour) { |
83 |
|
84 |
if( $maj = 1 && $retourformulaire === "dossier_instruction") { |
85 |
|
86 |
echo "\n<a class=\"retour\" "; |
87 |
echo "href=\"#\" "; |
88 |
|
89 |
echo "onclick=\"ajaxIt('".$objsf."', '"; |
90 |
echo "../app/document_numerise.view.php" |
91 |
."?retourformulaire=$retourformulaire" |
92 |
."&idxformulaire=$idxformulaire');\""; |
93 |
echo "\" "; |
94 |
echo ">"; |
95 |
// |
96 |
echo _("Retour"); |
97 |
// |
98 |
echo "</a>\n"; |
99 |
|
100 |
} else { |
101 |
parent::retoursousformulaire($idxformulaire, $retourformulaire, $val, |
102 |
$objsf, $premiersf, $tricolsf, $validation, |
103 |
$idx, $maj, $retour); |
104 |
} |
105 |
} |
106 |
|
107 |
/** |
108 |
* Ajout des contraintes spécifiques pour l'ajout d'un fichier en retour de |
109 |
* consultation |
110 |
*/ |
111 |
function setSelect(&$form, $maj,&$db,$debug) { |
112 |
parent::setSelect($form, $maj,$db,$debug); |
113 |
|
114 |
//Seulement dans le cas d'un retour d'avis |
115 |
if($this->retourformulaire == "dossier_instruction") { |
116 |
|
117 |
//Tableau des contraintes spécifiques |
118 |
$params = array( |
119 |
"constraint" => array( |
120 |
"extension" => ".pdf" |
121 |
), |
122 |
"metadata" => array() |
123 |
); |
124 |
|
125 |
$form->setSelect("uid", $params); |
126 |
} |
127 |
} |
128 |
|
129 |
/** |
130 |
* Génère le nom du fichier avec les information du formulaire |
131 |
* @param string $date Date de création du document |
132 |
* @param string $codeDoc Code du type de document |
133 |
* @return string Nom du fichier |
134 |
*/ |
135 |
private function generateFilename($date, $codeDoc) { |
136 |
|
137 |
//Change le format de la date |
138 |
$date = date("Ymd", strtotime($date)); |
139 |
//Compose le nom du fichier date + code document + extension |
140 |
$filename = $date.$codeDoc.'.pdf'; |
141 |
|
142 |
//Retourne le nom du fichier |
143 |
return $filename; |
144 |
} |
145 |
|
146 |
/** |
147 |
* Permet de recupérer le code du type de document par la clé primaire |
148 |
* @param int $document_numerise_type Clé primaire d'un donnée de document_numerise_type |
149 |
* @return string Code du type de document |
150 |
*/ |
151 |
private function get_document_numerise_type_code_by_id($document_numerise_type) { |
152 |
|
153 |
//Requête sql |
154 |
$sql = "SELECT code |
155 |
FROM ".DB_PREFIXE."document_numerise_type |
156 |
WHERE document_numerise_type = ".$document_numerise_type; |
157 |
$document_numerise_type_code = $this->db->getOne($sql); |
158 |
$this->addToLog("db->getone(\"".$sql."\");", VERBOSE_MODE); |
159 |
if (database::isError($document_numerise_type_code)) { |
160 |
die(); |
161 |
} |
162 |
|
163 |
//Retourne le code du type de document |
164 |
return $document_numerise_type_code; |
165 |
|
166 |
} |
167 |
|
168 |
}// fin classe |
169 |
?> |