@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * \brief File of class to manage fiscal years |
22 | 22 | */ |
23 | 23 | |
24 | -require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; |
|
24 | +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Class to manage fiscal year |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @var string ID to identify managed object |
33 | 33 | */ |
34 | - public $element='fiscalyear'; |
|
34 | + public $element = 'fiscalyear'; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @var string Name of table without prefix where object is stored |
38 | 38 | */ |
39 | - public $table_element='accounting_fiscalyear'; |
|
39 | + public $table_element = 'accounting_fiscalyear'; |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @var int Name of subtable line |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | public $date_start; |
68 | 68 | public $date_end; |
69 | 69 | public $datec; |
70 | - public $statut; // 0=open, 1=closed |
|
70 | + public $statut; // 0=open, 1=closed |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @var int Entity |
74 | 74 | */ |
75 | 75 | public $entity; |
76 | 76 | |
77 | - public $statuts=array(); |
|
78 | - public $statuts_short=array(); |
|
77 | + public $statuts = array(); |
|
78 | + public $statuts_short = array(); |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Constructor |
@@ -104,27 +104,27 @@ discard block |
||
104 | 104 | |
105 | 105 | $error = 0; |
106 | 106 | |
107 | - $now=dol_now(); |
|
107 | + $now = dol_now(); |
|
108 | 108 | |
109 | 109 | $this->db->begin(); |
110 | 110 | |
111 | 111 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear ("; |
112 | - $sql.= "label"; |
|
113 | - $sql.= ", date_start"; |
|
114 | - $sql.= ", date_end"; |
|
115 | - $sql.= ", statut"; |
|
116 | - $sql.= ", entity"; |
|
117 | - $sql.= ", datec"; |
|
118 | - $sql.= ", fk_user_author"; |
|
119 | - $sql.= ") VALUES ("; |
|
120 | - $sql.= " '".$this->db->escape($this->label)."'"; |
|
121 | - $sql.= ", '".$this->db->idate($this->date_start)."'"; |
|
122 | - $sql.= ", ".($this->date_end ? "'".$this->db->idate($this->date_end)."'":"null"); |
|
123 | - $sql.= ", 0"; |
|
124 | - $sql.= ", ".$conf->entity; |
|
125 | - $sql.= ", '".$this->db->idate($now)."'"; |
|
126 | - $sql.= ", ". $user->id; |
|
127 | - $sql.= ")"; |
|
112 | + $sql .= "label"; |
|
113 | + $sql .= ", date_start"; |
|
114 | + $sql .= ", date_end"; |
|
115 | + $sql .= ", statut"; |
|
116 | + $sql .= ", entity"; |
|
117 | + $sql .= ", datec"; |
|
118 | + $sql .= ", fk_user_author"; |
|
119 | + $sql .= ") VALUES ("; |
|
120 | + $sql .= " '".$this->db->escape($this->label)."'"; |
|
121 | + $sql .= ", '".$this->db->idate($this->date_start)."'"; |
|
122 | + $sql .= ", ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null"); |
|
123 | + $sql .= ", 0"; |
|
124 | + $sql .= ", ".$conf->entity; |
|
125 | + $sql .= ", '".$this->db->idate($now)."'"; |
|
126 | + $sql .= ", ".$user->id; |
|
127 | + $sql .= ")"; |
|
128 | 128 | |
129 | 129 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
130 | 130 | $result = $this->db->query($sql); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | { |
133 | 133 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear"); |
134 | 134 | |
135 | - $result=$this->update($user); |
|
135 | + $result = $this->update($user); |
|
136 | 136 | if ($result > 0) |
137 | 137 | { |
138 | 138 | $this->db->commit(); |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | } |
141 | 141 | else |
142 | 142 | { |
143 | - $this->error=$this->db->lasterror(); |
|
143 | + $this->error = $this->db->lasterror(); |
|
144 | 144 | $this->db->rollback(); |
145 | 145 | return $result; |
146 | 146 | } |
147 | 147 | } |
148 | 148 | else |
149 | 149 | { |
150 | - $this->error=$this->db->lasterror()." sql=".$sql; |
|
150 | + $this->error = $this->db->lasterror()." sql=".$sql; |
|
151 | 151 | $this->db->rollback(); |
152 | 152 | return -1; |
153 | 153 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | // Check parameters |
167 | 167 | if (empty($this->date_start) && empty($this->date_end)) |
168 | 168 | { |
169 | - $this->error='ErrorBadParameter'; |
|
169 | + $this->error = 'ErrorBadParameter'; |
|
170 | 170 | return -1; |
171 | 171 | } |
172 | 172 | |
@@ -176,9 +176,9 @@ discard block |
||
176 | 176 | $sql .= " SET label = '".$this->db->escape($this->label)."'"; |
177 | 177 | $sql .= ", date_start = '".$this->db->idate($this->date_start)."'"; |
178 | 178 | $sql .= ", date_end = ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null"); |
179 | - $sql .= ", statut = '".$this->db->escape($this->statut?$this->statut:0)."'"; |
|
180 | - $sql .= ", datec = " . ($this->datec != '' ? "'".$this->db->idate($this->datec)."'" : 'null'); |
|
181 | - $sql .= ", fk_user_modif = " . $user->id; |
|
179 | + $sql .= ", statut = '".$this->db->escape($this->statut ? $this->statut : 0)."'"; |
|
180 | + $sql .= ", datec = ".($this->datec != '' ? "'".$this->db->idate($this->datec)."'" : 'null'); |
|
181 | + $sql .= ", fk_user_modif = ".$user->id; |
|
182 | 182 | $sql .= " WHERE rowid = ".$this->id; |
183 | 183 | |
184 | 184 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | } |
191 | 191 | else |
192 | 192 | { |
193 | - $this->error=$this->db->lasterror(); |
|
193 | + $this->error = $this->db->lasterror(); |
|
194 | 194 | dol_syslog($this->error, LOG_ERR); |
195 | 195 | $this->db->rollback(); |
196 | 196 | return -1; |
@@ -206,27 +206,27 @@ discard block |
||
206 | 206 | function fetch($id) |
207 | 207 | { |
208 | 208 | $sql = "SELECT rowid, label, date_start, date_end, statut"; |
209 | - $sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear"; |
|
210 | - $sql.= " WHERE rowid = ".$id; |
|
209 | + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear"; |
|
210 | + $sql .= " WHERE rowid = ".$id; |
|
211 | 211 | |
212 | 212 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
213 | 213 | $result = $this->db->query($sql); |
214 | - if ( $result ) |
|
214 | + if ($result) |
|
215 | 215 | { |
216 | 216 | $obj = $this->db->fetch_object($result); |
217 | 217 | |
218 | - $this->id = $obj->rowid; |
|
219 | - $this->ref = $obj->rowid; |
|
218 | + $this->id = $obj->rowid; |
|
219 | + $this->ref = $obj->rowid; |
|
220 | 220 | $this->date_start = $this->db->jdate($obj->date_start); |
221 | - $this->date_end = $this->db->jdate($obj->date_end); |
|
222 | - $this->label = $obj->label; |
|
221 | + $this->date_end = $this->db->jdate($obj->date_end); |
|
222 | + $this->label = $obj->label; |
|
223 | 223 | $this->statut = $obj->statut; |
224 | 224 | |
225 | 225 | return 1; |
226 | 226 | } |
227 | 227 | else |
228 | 228 | { |
229 | - $this->error=$this->db->lasterror(); |
|
229 | + $this->error = $this->db->lasterror(); |
|
230 | 230 | return -1; |
231 | 231 | } |
232 | 232 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | } |
253 | 253 | else |
254 | 254 | { |
255 | - $this->error=$this->db->lasterror(); |
|
255 | + $this->error = $this->db->lasterror(); |
|
256 | 256 | $this->db->rollback(); |
257 | 257 | return -1; |
258 | 258 | } |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto |
265 | 265 | * @return string Label |
266 | 266 | */ |
267 | - function getLibStatut($mode=0) |
|
267 | + function getLibStatut($mode = 0) |
|
268 | 268 | { |
269 | - return $this->LibStatut($this->statut,$mode); |
|
269 | + return $this->LibStatut($this->statut, $mode); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto |
278 | 278 | * @return string Label |
279 | 279 | */ |
280 | - function LibStatut($statut,$mode=0) |
|
280 | + function LibStatut($statut, $mode = 0) |
|
281 | 281 | { |
282 | 282 | // phpcs:enable |
283 | 283 | global $langs; |
@@ -292,23 +292,23 @@ discard block |
||
292 | 292 | } |
293 | 293 | elseif ($mode == 2) |
294 | 294 | { |
295 | - if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]); |
|
296 | - elseif ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts_short[$statut]); |
|
295 | + if ($statut == 0) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4').' '.$langs->trans($this->statuts_short[$statut]); |
|
296 | + elseif ($statut == 1) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut8').' '.$langs->trans($this->statuts_short[$statut]); |
|
297 | 297 | } |
298 | 298 | elseif ($mode == 3) |
299 | 299 | { |
300 | - if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); |
|
301 | - elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8'); |
|
300 | + if ($statut == 0 && !empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4'); |
|
301 | + elseif ($statut == 1 && !empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut8'); |
|
302 | 302 | } |
303 | 303 | elseif ($mode == 4) |
304 | 304 | { |
305 | - if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]); |
|
306 | - elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts[$statut]); |
|
305 | + if ($statut == 0 && !empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4').' '.$langs->trans($this->statuts[$statut]); |
|
306 | + elseif ($statut == 1 && !empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut8').' '.$langs->trans($this->statuts[$statut]); |
|
307 | 307 | } |
308 | 308 | elseif ($mode == 5) |
309 | 309 | { |
310 | - if ($statut==0 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); |
|
311 | - elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); |
|
310 | + if ($statut == 0 && !empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]), 'statut4'); |
|
311 | + elseif ($statut == 1 && !empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]), 'statut6'); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | function info($id) |
322 | 322 | { |
323 | 323 | $sql = 'SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,'; |
324 | - $sql.= ' fy.tms'; |
|
325 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy'; |
|
326 | - $sql.= ' WHERE fy.rowid = '.$id; |
|
324 | + $sql .= ' fy.tms'; |
|
325 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy'; |
|
326 | + $sql .= ' WHERE fy.rowid = '.$id; |
|
327 | 327 | |
328 | 328 | dol_syslog(get_class($this)."::fetch info", LOG_DEBUG); |
329 | 329 | $result = $this->db->query($sql); |
@@ -369,10 +369,10 @@ discard block |
||
369 | 369 | global $conf; |
370 | 370 | |
371 | 371 | $sql = "SELECT count(DISTINCT piece_num) as nb"; |
372 | - $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping "; |
|
373 | - $sql.= " WHERE doc_date >= '".$datestart."' and doc_date <= '".$dateend."'"; |
|
372 | + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping "; |
|
373 | + $sql .= " WHERE doc_date >= '".$datestart."' and doc_date <= '".$dateend."'"; |
|
374 | 374 | |
375 | - $resql=$this->db->query($sql); |
|
375 | + $resql = $this->db->query($sql); |
|
376 | 376 | if ($resql) |
377 | 377 | { |
378 | 378 | $obj = $this->db->fetch_object($resql); |
@@ -395,10 +395,10 @@ discard block |
||
395 | 395 | global $conf; |
396 | 396 | |
397 | 397 | $sql = "SELECT count(rowid) as nb"; |
398 | - $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping "; |
|
399 | - $sql.= " WHERE doc_date >= '".$datestart."' AND doc_date <= '".$dateend."'"; |
|
398 | + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping "; |
|
399 | + $sql .= " WHERE doc_date >= '".$datestart."' AND doc_date <= '".$dateend."'"; |
|
400 | 400 | |
401 | - $resql=$this->db->query($sql); |
|
401 | + $resql = $this->db->query($sql); |
|
402 | 402 | if ($resql) |
403 | 403 | { |
404 | 404 | $obj = $this->db->fetch_object($resql); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @var string Error code (or message) |
37 | 37 | */ |
38 | - public $error=''; |
|
38 | + public $error = ''; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @var string[] Error codes (or messages) |
@@ -76,18 +76,18 @@ discard block |
||
76 | 76 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
77 | 77 | * @return int <0 if KO, Id of created object if OK |
78 | 78 | */ |
79 | - function create($user, $notrigger=0) |
|
79 | + function create($user, $notrigger = 0) |
|
80 | 80 | { |
81 | 81 | global $conf, $langs; |
82 | - $error=0; |
|
82 | + $error = 0; |
|
83 | 83 | |
84 | 84 | // Clean parameters |
85 | 85 | |
86 | - if (isset($this->id)) $this->id=trim($this->id); |
|
87 | - if (isset($this->code)) $this->code=trim($this->code); |
|
88 | - if (isset($this->libelle)) $this->libelle=trim($this->libelle); |
|
89 | - if (isset($this->active)) $this->active=trim($this->active); |
|
90 | - if (isset($this->module)) $this->module=trim($this->module); |
|
86 | + if (isset($this->id)) $this->id = trim($this->id); |
|
87 | + if (isset($this->code)) $this->code = trim($this->code); |
|
88 | + if (isset($this->libelle)) $this->libelle = trim($this->libelle); |
|
89 | + if (isset($this->active)) $this->active = trim($this->active); |
|
90 | + if (isset($this->module)) $this->module = trim($this->module); |
|
91 | 91 | |
92 | 92 | |
93 | 93 | |
@@ -97,35 +97,35 @@ discard block |
||
97 | 97 | // Insert request |
98 | 98 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_typent("; |
99 | 99 | |
100 | - $sql.= "id,"; |
|
101 | - $sql.= "code,"; |
|
102 | - $sql.= "libelle,"; |
|
103 | - $sql.= "active,"; |
|
104 | - $sql.= "module"; |
|
100 | + $sql .= "id,"; |
|
101 | + $sql .= "code,"; |
|
102 | + $sql .= "libelle,"; |
|
103 | + $sql .= "active,"; |
|
104 | + $sql .= "module"; |
|
105 | 105 | |
106 | 106 | |
107 | - $sql.= ") VALUES ("; |
|
107 | + $sql .= ") VALUES ("; |
|
108 | 108 | |
109 | - $sql.= " ".(! isset($this->id)?'NULL':"'".$this->db->escape($this->id)."'").","; |
|
110 | - $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").","; |
|
111 | - $sql.= " ".(! isset($this->libelle)?'NULL':"'".$this->db->escape($this->libelle)."'").","; |
|
112 | - $sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->active($this->active)."'").","; |
|
113 | - $sql.= " ".(! isset($this->module)?'NULL':"'".$this->db->escape($this->module)."'").""; |
|
109 | + $sql .= " ".(!isset($this->id) ? 'NULL' : "'".$this->db->escape($this->id)."'").","; |
|
110 | + $sql .= " ".(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").","; |
|
111 | + $sql .= " ".(!isset($this->libelle) ? 'NULL' : "'".$this->db->escape($this->libelle)."'").","; |
|
112 | + $sql .= " ".(!isset($this->active) ? 'NULL' : "'".$this->db->active($this->active)."'").","; |
|
113 | + $sql .= " ".(!isset($this->module) ? 'NULL' : "'".$this->db->escape($this->module)."'").""; |
|
114 | 114 | |
115 | 115 | |
116 | - $sql.= ")"; |
|
116 | + $sql .= ")"; |
|
117 | 117 | |
118 | 118 | $this->db->begin(); |
119 | 119 | |
120 | 120 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
121 | - $resql=$this->db->query($sql); |
|
122 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
121 | + $resql = $this->db->query($sql); |
|
122 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
123 | 123 | |
124 | - if (! $error) |
|
124 | + if (!$error) |
|
125 | 125 | { |
126 | 126 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_typent"); |
127 | 127 | |
128 | - if (! $notrigger) |
|
128 | + if (!$notrigger) |
|
129 | 129 | { |
130 | 130 | // Uncomment this and change MYOBJECT to your own tag if you |
131 | 131 | // want this action call a trigger. |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | // Commit or rollback |
143 | 143 | if ($error) |
144 | 144 | { |
145 | - foreach($this->errors as $errmsg) |
|
145 | + foreach ($this->errors as $errmsg) |
|
146 | 146 | { |
147 | 147 | dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); |
148 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
148 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
149 | 149 | } |
150 | 150 | $this->db->rollback(); |
151 | - return -1*$error; |
|
151 | + return -1 * $error; |
|
152 | 152 | } |
153 | 153 | else |
154 | 154 | { |
@@ -166,29 +166,29 @@ discard block |
||
166 | 166 | * @param string $label Label |
167 | 167 | * @return int <0 if KO, >0 if OK |
168 | 168 | */ |
169 | - function fetch($id,$code='',$label='') |
|
169 | + function fetch($id, $code = '', $label = '') |
|
170 | 170 | { |
171 | 171 | global $langs; |
172 | 172 | $sql = "SELECT"; |
173 | - $sql.= " t.id,"; |
|
174 | - $sql.= " t.code,"; |
|
175 | - $sql.= " t.libelle as label,"; |
|
176 | - $sql.= " t.fk_country as country_id,"; |
|
177 | - $sql.= " t.active,"; |
|
178 | - $sql.= " t.module"; |
|
179 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_typent as t"; |
|
180 | - if ($id) $sql.= " WHERE t.id = ".$id; |
|
181 | - elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
182 | - elseif ($label) $sql.= " WHERE t.libelle = '".$this->db->escape($label)."'"; |
|
183 | - |
|
184 | - $resql=$this->db->query($sql); |
|
173 | + $sql .= " t.id,"; |
|
174 | + $sql .= " t.code,"; |
|
175 | + $sql .= " t.libelle as label,"; |
|
176 | + $sql .= " t.fk_country as country_id,"; |
|
177 | + $sql .= " t.active,"; |
|
178 | + $sql .= " t.module"; |
|
179 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_typent as t"; |
|
180 | + if ($id) $sql .= " WHERE t.id = ".$id; |
|
181 | + elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
182 | + elseif ($label) $sql .= " WHERE t.libelle = '".$this->db->escape($label)."'"; |
|
183 | + |
|
184 | + $resql = $this->db->query($sql); |
|
185 | 185 | if ($resql) |
186 | 186 | { |
187 | 187 | if ($this->db->num_rows($resql)) |
188 | 188 | { |
189 | 189 | $obj = $this->db->fetch_object($resql); |
190 | 190 | |
191 | - $this->id = $obj->id; |
|
191 | + $this->id = $obj->id; |
|
192 | 192 | $this->code = $obj->code; |
193 | 193 | $this->libelle = $obj->label; |
194 | 194 | $this->country_id = $obj->country_id; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | else |
203 | 203 | { |
204 | - $this->error="Error ".$this->db->lasterror(); |
|
204 | + $this->error = "Error ".$this->db->lasterror(); |
|
205 | 205 | return -1; |
206 | 206 | } |
207 | 207 | } |
@@ -214,16 +214,16 @@ discard block |
||
214 | 214 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
215 | 215 | * @return int <0 if KO, >0 if OK |
216 | 216 | */ |
217 | - function update($user=null, $notrigger=0) |
|
217 | + function update($user = null, $notrigger = 0) |
|
218 | 218 | { |
219 | 219 | global $conf, $langs; |
220 | - $error=0; |
|
220 | + $error = 0; |
|
221 | 221 | |
222 | 222 | // Clean parameters |
223 | - if (isset($this->code)) $this->code=trim($this->code); |
|
224 | - if (isset($this->libelle)) $this->libelle=trim($this->libelle); |
|
225 | - if (isset($this->active)) $this->active=trim($this->active); |
|
226 | - if (isset($this->module)) $this->module=trim($this->module); |
|
223 | + if (isset($this->code)) $this->code = trim($this->code); |
|
224 | + if (isset($this->libelle)) $this->libelle = trim($this->libelle); |
|
225 | + if (isset($this->active)) $this->active = trim($this->active); |
|
226 | + if (isset($this->module)) $this->module = trim($this->module); |
|
227 | 227 | |
228 | 228 | |
229 | 229 | // Check parameters |
@@ -231,21 +231,21 @@ discard block |
||
231 | 231 | |
232 | 232 | // Update request |
233 | 233 | $sql = "UPDATE ".MAIN_DB_PREFIX."c_typent SET"; |
234 | - $sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").","; |
|
235 | - $sql.= " libelle=".(isset($this->libelle)?"'".$this->db->escape($this->libelle)."'":"null").","; |
|
236 | - $sql.= " active=".(isset($this->active)?$this->active:"null").","; |
|
237 | - $sql.= " module=".(isset($this->module)?"'".$this->db->escape($this->module)."'":"null").""; |
|
238 | - $sql.= " WHERE id=".$this->id; |
|
234 | + $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; |
|
235 | + $sql .= " libelle=".(isset($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : "null").","; |
|
236 | + $sql .= " active=".(isset($this->active) ? $this->active : "null").","; |
|
237 | + $sql .= " module=".(isset($this->module) ? "'".$this->db->escape($this->module)."'" : "null").""; |
|
238 | + $sql .= " WHERE id=".$this->id; |
|
239 | 239 | |
240 | 240 | $this->db->begin(); |
241 | 241 | |
242 | 242 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
243 | 243 | $resql = $this->db->query($sql); |
244 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
244 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
245 | 245 | |
246 | - if (! $error) |
|
246 | + if (!$error) |
|
247 | 247 | { |
248 | - if (! $notrigger) |
|
248 | + if (!$notrigger) |
|
249 | 249 | { |
250 | 250 | // Uncomment this and change MYOBJECT to your own tag if you |
251 | 251 | // want this action call a trigger. |
@@ -262,13 +262,13 @@ discard block |
||
262 | 262 | // Commit or rollback |
263 | 263 | if ($error) |
264 | 264 | { |
265 | - foreach($this->errors as $errmsg) |
|
265 | + foreach ($this->errors as $errmsg) |
|
266 | 266 | { |
267 | 267 | dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
268 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
268 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
269 | 269 | } |
270 | 270 | $this->db->rollback(); |
271 | - return -1*$error; |
|
271 | + return -1 * $error; |
|
272 | 272 | } |
273 | 273 | else |
274 | 274 | { |
@@ -285,23 +285,23 @@ discard block |
||
285 | 285 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
286 | 286 | * @return int <0 if KO, >0 if OK |
287 | 287 | */ |
288 | - function delete($user, $notrigger=0) |
|
288 | + function delete($user, $notrigger = 0) |
|
289 | 289 | { |
290 | 290 | global $conf, $langs; |
291 | - $error=0; |
|
291 | + $error = 0; |
|
292 | 292 | |
293 | 293 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_typent"; |
294 | - $sql.= " WHERE id=".$this->id; |
|
294 | + $sql .= " WHERE id=".$this->id; |
|
295 | 295 | |
296 | 296 | $this->db->begin(); |
297 | 297 | |
298 | 298 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
299 | 299 | $resql = $this->db->query($sql); |
300 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
300 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
301 | 301 | |
302 | - if (! $error) |
|
302 | + if (!$error) |
|
303 | 303 | { |
304 | - if (! $notrigger) |
|
304 | + if (!$notrigger) |
|
305 | 305 | { |
306 | 306 | // Uncomment this and change MYOBJECT to your own tag if you |
307 | 307 | // want this action call a trigger. |
@@ -318,13 +318,13 @@ discard block |
||
318 | 318 | // Commit or rollback |
319 | 319 | if ($error) |
320 | 320 | { |
321 | - foreach($this->errors as $errmsg) |
|
321 | + foreach ($this->errors as $errmsg) |
|
322 | 322 | { |
323 | 323 | dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
324 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
324 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
325 | 325 | } |
326 | 326 | $this->db->rollback(); |
327 | - return -1*$error; |
|
327 | + return -1 * $error; |
|
328 | 328 | } |
329 | 329 | else |
330 | 330 | { |
@@ -37,7 +37,7 @@ |
||
37 | 37 | /** |
38 | 38 | * @var string Error code (or message) |
39 | 39 | */ |
40 | - public $error=''; |
|
40 | + public $error = ''; |
|
41 | 41 | |
42 | 42 | |
43 | 43 | /** |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @var string Error code (or message) |
34 | 34 | */ |
35 | - public $error=''; |
|
35 | + public $error = ''; |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @var string[] Array of error strings |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * Tableau des serveurs (IP addresses ou nom d'hotes) |
44 | 44 | */ |
45 | - var $server=array(); |
|
45 | + var $server = array(); |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Base DN (e.g. "dc=foo,dc=com") |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | var $uacf; |
98 | 98 | var $pwdlastset; |
99 | 99 | |
100 | - var $ldapcharset='UTF-8'; // LDAP should be UTF-8 encoded |
|
100 | + var $ldapcharset = 'UTF-8'; // LDAP should be UTF-8 encoded |
|
101 | 101 | |
102 | 102 | |
103 | 103 | /** |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | global $conf; |
119 | 119 | |
120 | 120 | // Server |
121 | - if (! empty($conf->global->LDAP_SERVER_HOST)) $this->server[] = $conf->global->LDAP_SERVER_HOST; |
|
122 | - if (! empty($conf->global->LDAP_SERVER_HOST_SLAVE)) $this->server[] = $conf->global->LDAP_SERVER_HOST_SLAVE; |
|
121 | + if (!empty($conf->global->LDAP_SERVER_HOST)) $this->server[] = $conf->global->LDAP_SERVER_HOST; |
|
122 | + if (!empty($conf->global->LDAP_SERVER_HOST_SLAVE)) $this->server[] = $conf->global->LDAP_SERVER_HOST_SLAVE; |
|
123 | 123 | $this->serverPort = $conf->global->LDAP_SERVER_PORT; |
124 | 124 | $this->ldapProtocolVersion = $conf->global->LDAP_SERVER_PROTOCOLVERSION; |
125 | 125 | $this->dn = $conf->global->LDAP_SERVER_DN; |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | $this->people = $conf->global->LDAP_USER_DN; |
131 | 131 | $this->groups = $conf->global->LDAP_GROUP_DN; |
132 | 132 | |
133 | - $this->filter = $conf->global->LDAP_FILTER_CONNECTION; // Filter on user |
|
134 | - $this->filtermember = $conf->global->LDAP_MEMBER_FILTER; // Filter on member |
|
133 | + $this->filter = $conf->global->LDAP_FILTER_CONNECTION; // Filter on user |
|
134 | + $this->filtermember = $conf->global->LDAP_MEMBER_FILTER; // Filter on member |
|
135 | 135 | |
136 | 136 | // Users |
137 | 137 | $this->attr_login = $conf->global->LDAP_FIELD_LOGIN; //unix |
@@ -162,22 +162,22 @@ discard block |
||
162 | 162 | // phpcs:enable |
163 | 163 | global $langs, $conf; |
164 | 164 | |
165 | - $connected=0; |
|
166 | - $this->bind=0; |
|
165 | + $connected = 0; |
|
166 | + $this->bind = 0; |
|
167 | 167 | |
168 | 168 | // Check parameters |
169 | 169 | if (count($this->server) == 0 || empty($this->server[0])) |
170 | 170 | { |
171 | - $this->error='LDAP setup (file conf.php) is not complete'; |
|
171 | + $this->error = 'LDAP setup (file conf.php) is not complete'; |
|
172 | 172 | dol_syslog(get_class($this)."::connect_bind ".$this->error, LOG_WARNING); |
173 | 173 | return -1; |
174 | 174 | } |
175 | 175 | |
176 | - if (! function_exists("ldap_connect")) |
|
176 | + if (!function_exists("ldap_connect")) |
|
177 | 177 | { |
178 | - $this->error='LDAPFunctionsNotAvailableOnPHP'; |
|
178 | + $this->error = 'LDAPFunctionsNotAvailableOnPHP'; |
|
179 | 179 | dol_syslog(get_class($this)."::connect_bind ".$this->error, LOG_WARNING); |
180 | - $return=-1; |
|
180 | + $return = -1; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | if (empty($this->error)) |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | if (is_resource($this->connection)) |
197 | 197 | { |
198 | 198 | // Begin TLS if requested by the configuration |
199 | - if (! empty($conf->global->LDAP_SERVER_USE_TLS)) |
|
199 | + if (!empty($conf->global->LDAP_SERVER_USE_TLS)) |
|
200 | 200 | { |
201 | - if (! ldap_start_tls($this->connection)) |
|
201 | + if (!ldap_start_tls($this->connection)) |
|
202 | 202 | { |
203 | 203 | dol_syslog(get_class($this)."::connect_bind failed to start tls", LOG_WARNING); |
204 | 204 | $connected = 0; |
@@ -213,18 +213,18 @@ discard block |
||
213 | 213 | |
214 | 214 | if ($this->serverType == "activedirectory") |
215 | 215 | { |
216 | - $result=$this->setReferrals(); |
|
217 | - dol_syslog(get_class($this)."::connect_bind try bindauth for activedirectory on ".$host." user=".$this->searchUser." password=".preg_replace('/./','*',$this->searchPassword),LOG_DEBUG); |
|
218 | - $this->result=$this->bindauth($this->searchUser,$this->searchPassword); |
|
216 | + $result = $this->setReferrals(); |
|
217 | + dol_syslog(get_class($this)."::connect_bind try bindauth for activedirectory on ".$host." user=".$this->searchUser." password=".preg_replace('/./', '*', $this->searchPassword), LOG_DEBUG); |
|
218 | + $this->result = $this->bindauth($this->searchUser, $this->searchPassword); |
|
219 | 219 | if ($this->result) |
220 | 220 | { |
221 | - $this->bind=$this->result; |
|
222 | - $connected=2; |
|
221 | + $this->bind = $this->result; |
|
222 | + $connected = 2; |
|
223 | 223 | break; |
224 | 224 | } |
225 | 225 | else |
226 | 226 | { |
227 | - $this->error=ldap_errno($this->connection).' '.ldap_error($this->connection); |
|
227 | + $this->error = ldap_errno($this->connection).' '.ldap_error($this->connection); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | else |
@@ -232,51 +232,51 @@ discard block |
||
232 | 232 | // Try in auth mode |
233 | 233 | if ($this->searchUser && $this->searchPassword) |
234 | 234 | { |
235 | - dol_syslog(get_class($this)."::connect_bind try bindauth on ".$host." user=".$this->searchUser." password=".preg_replace('/./','*',$this->searchPassword),LOG_DEBUG); |
|
236 | - $this->result=$this->bindauth($this->searchUser,$this->searchPassword); |
|
235 | + dol_syslog(get_class($this)."::connect_bind try bindauth on ".$host." user=".$this->searchUser." password=".preg_replace('/./', '*', $this->searchPassword), LOG_DEBUG); |
|
236 | + $this->result = $this->bindauth($this->searchUser, $this->searchPassword); |
|
237 | 237 | if ($this->result) |
238 | 238 | { |
239 | - $this->bind=$this->result; |
|
240 | - $connected=2; |
|
239 | + $this->bind = $this->result; |
|
240 | + $connected = 2; |
|
241 | 241 | break; |
242 | 242 | } |
243 | 243 | else |
244 | 244 | { |
245 | - $this->error=ldap_errno($this->connection).' '.ldap_error($this->connection); |
|
245 | + $this->error = ldap_errno($this->connection).' '.ldap_error($this->connection); |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | // Try in anonymous |
249 | - if (! $this->bind) |
|
249 | + if (!$this->bind) |
|
250 | 250 | { |
251 | - dol_syslog(get_class($this)."::connect_bind try bind on ".$host,LOG_DEBUG); |
|
252 | - $result=$this->bind(); |
|
251 | + dol_syslog(get_class($this)."::connect_bind try bind on ".$host, LOG_DEBUG); |
|
252 | + $result = $this->bind(); |
|
253 | 253 | if ($result) |
254 | 254 | { |
255 | - $this->bind=$this->result; |
|
256 | - $connected=1; |
|
255 | + $this->bind = $this->result; |
|
256 | + $connected = 1; |
|
257 | 257 | break; |
258 | 258 | } |
259 | 259 | else |
260 | 260 | { |
261 | - $this->error=ldap_errno($this->connection).' '.ldap_error($this->connection); |
|
261 | + $this->error = ldap_errno($this->connection).' '.ldap_error($this->connection); |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | } |
265 | 265 | } |
266 | 266 | |
267 | - if (! $connected) $this->close(); |
|
267 | + if (!$connected) $this->close(); |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
271 | 271 | if ($connected) |
272 | 272 | { |
273 | - $return=$connected; |
|
273 | + $return = $connected; |
|
274 | 274 | dol_syslog(get_class($this)."::connect_bind return=".$return, LOG_DEBUG); |
275 | 275 | } |
276 | 276 | else |
277 | 277 | { |
278 | - $this->error='Failed to connect to LDAP'.($this->error?': '.$this->error:''); |
|
279 | - $return=-1; |
|
278 | + $this->error = 'Failed to connect to LDAP'.($this->error ? ': '.$this->error : ''); |
|
279 | + $return = -1; |
|
280 | 280 | dol_syslog(get_class($this)."::connect_bind return=".$return.' - '.$this->error, LOG_WARNING); |
281 | 281 | } |
282 | 282 | return $return; |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | */ |
293 | 293 | function close() |
294 | 294 | { |
295 | - if ($this->connection && ! @ldap_close($this->connection)) |
|
295 | + if ($this->connection && !@ldap_close($this->connection)) |
|
296 | 296 | { |
297 | 297 | return false; |
298 | 298 | } |
@@ -310,11 +310,11 @@ discard block |
||
310 | 310 | */ |
311 | 311 | function bind() |
312 | 312 | { |
313 | - if (! $this->result=@ldap_bind($this->connection)) |
|
313 | + if (!$this->result = @ldap_bind($this->connection)) |
|
314 | 314 | { |
315 | 315 | $this->ldapErrorCode = ldap_errno($this->connection); |
316 | 316 | $this->ldapErrorText = ldap_error($this->connection); |
317 | - $this->error=$this->ldapErrorCode." ".$this->ldapErrorText; |
|
317 | + $this->error = $this->ldapErrorCode." ".$this->ldapErrorText; |
|
318 | 318 | return false; |
319 | 319 | } |
320 | 320 | else |
@@ -333,13 +333,13 @@ discard block |
||
333 | 333 | * @param string $pass Password |
334 | 334 | * @return boolean true or false |
335 | 335 | */ |
336 | - function bindauth($bindDn,$pass) |
|
336 | + function bindauth($bindDn, $pass) |
|
337 | 337 | { |
338 | - if (! $this->result = @ldap_bind($this->connection, $bindDn, $pass)) |
|
338 | + if (!$this->result = @ldap_bind($this->connection, $bindDn, $pass)) |
|
339 | 339 | { |
340 | 340 | $this->ldapErrorCode = ldap_errno($this->connection); |
341 | 341 | $this->ldapErrorText = ldap_error($this->connection); |
342 | - $this->error=$this->ldapErrorCode." ".$this->ldapErrorText; |
|
342 | + $this->error = $this->ldapErrorCode." ".$this->ldapErrorText; |
|
343 | 343 | return false; |
344 | 344 | } |
345 | 345 | else |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | */ |
356 | 356 | function unbind() |
357 | 357 | { |
358 | - if (!$this->result=@ldap_unbind($this->connection)) |
|
358 | + if (!$this->result = @ldap_unbind($this->connection)) |
|
359 | 359 | { |
360 | 360 | return false; |
361 | 361 | } else { |
@@ -414,31 +414,31 @@ discard block |
||
414 | 414 | { |
415 | 415 | global $conf; |
416 | 416 | |
417 | - dol_syslog(get_class($this)."::add dn=".$dn." info=".join(',',$info)); |
|
417 | + dol_syslog(get_class($this)."::add dn=".$dn." info=".join(',', $info)); |
|
418 | 418 | |
419 | 419 | // Check parameters |
420 | - if (! $this->connection) |
|
420 | + if (!$this->connection) |
|
421 | 421 | { |
422 | - $this->error="NotConnected"; |
|
422 | + $this->error = "NotConnected"; |
|
423 | 423 | return -2; |
424 | 424 | } |
425 | - if (! $this->bind) |
|
425 | + if (!$this->bind) |
|
426 | 426 | { |
427 | - $this->error="NotConnected"; |
|
427 | + $this->error = "NotConnected"; |
|
428 | 428 | return -3; |
429 | 429 | } |
430 | 430 | |
431 | 431 | // Encode to LDAP page code |
432 | - $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); |
|
433 | - foreach($info as $key => $val) |
|
432 | + $dn = $this->convFromOutputCharset($dn, $this->ldapcharset); |
|
433 | + foreach ($info as $key => $val) |
|
434 | 434 | { |
435 | - if (! is_array($val)) $info[$key]=$this->convFromOutputCharset($val,$this->ldapcharset); |
|
435 | + if (!is_array($val)) $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset); |
|
436 | 436 | } |
437 | 437 | |
438 | - $this->dump($dn,$info); |
|
438 | + $this->dump($dn, $info); |
|
439 | 439 | |
440 | 440 | //print_r($info); |
441 | - $result=@ldap_add($this->connection, $dn, $info); |
|
441 | + $result = @ldap_add($this->connection, $dn, $info); |
|
442 | 442 | |
443 | 443 | if ($result) |
444 | 444 | { |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | { |
450 | 450 | $this->ldapErrorCode = @ldap_errno($this->connection); |
451 | 451 | $this->ldapErrorText = @ldap_error($this->connection); |
452 | - $this->error=$this->ldapErrorCode." ".$this->ldapErrorText; |
|
452 | + $this->error = $this->ldapErrorCode." ".$this->ldapErrorText; |
|
453 | 453 | dol_syslog(get_class($this)."::add failed: ".$this->error, LOG_ERR); |
454 | 454 | return -1; |
455 | 455 | } |
@@ -468,31 +468,31 @@ discard block |
||
468 | 468 | { |
469 | 469 | global $conf; |
470 | 470 | |
471 | - dol_syslog(get_class($this)."::modify dn=".$dn." info=".join(',',$info)); |
|
471 | + dol_syslog(get_class($this)."::modify dn=".$dn." info=".join(',', $info)); |
|
472 | 472 | |
473 | 473 | // Check parameters |
474 | - if (! $this->connection) |
|
474 | + if (!$this->connection) |
|
475 | 475 | { |
476 | - $this->error="NotConnected"; |
|
476 | + $this->error = "NotConnected"; |
|
477 | 477 | return -2; |
478 | 478 | } |
479 | - if (! $this->bind) |
|
479 | + if (!$this->bind) |
|
480 | 480 | { |
481 | - $this->error="NotConnected"; |
|
481 | + $this->error = "NotConnected"; |
|
482 | 482 | return -3; |
483 | 483 | } |
484 | 484 | |
485 | 485 | // Encode to LDAP page code |
486 | - $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); |
|
487 | - foreach($info as $key => $val) |
|
486 | + $dn = $this->convFromOutputCharset($dn, $this->ldapcharset); |
|
487 | + foreach ($info as $key => $val) |
|
488 | 488 | { |
489 | - if (! is_array($val)) $info[$key]=$this->convFromOutputCharset($val,$this->ldapcharset); |
|
489 | + if (!is_array($val)) $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset); |
|
490 | 490 | } |
491 | 491 | |
492 | - $this->dump($dn,$info); |
|
492 | + $this->dump($dn, $info); |
|
493 | 493 | |
494 | 494 | //print_r($info); |
495 | - $result=@ldap_modify($this->connection, $dn, $info); |
|
495 | + $result = @ldap_modify($this->connection, $dn, $info); |
|
496 | 496 | |
497 | 497 | if ($result) |
498 | 498 | { |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | } |
502 | 502 | else |
503 | 503 | { |
504 | - $this->error=@ldap_error($this->connection); |
|
504 | + $this->error = @ldap_error($this->connection); |
|
505 | 505 | dol_syslog(get_class($this)."::modify failed: ".$this->error, LOG_ERR); |
506 | 506 | return -1; |
507 | 507 | } |
@@ -522,27 +522,27 @@ discard block |
||
522 | 522 | { |
523 | 523 | global $conf; |
524 | 524 | |
525 | - dol_syslog(get_class($this)."::modify dn=".$dn." newrdn=".$newrdn." newparent=".$newparent." deleteoldrdn=".($deleteoldrdn?1:0)); |
|
525 | + dol_syslog(get_class($this)."::modify dn=".$dn." newrdn=".$newrdn." newparent=".$newparent." deleteoldrdn=".($deleteoldrdn ? 1 : 0)); |
|
526 | 526 | |
527 | 527 | // Check parameters |
528 | - if (! $this->connection) |
|
528 | + if (!$this->connection) |
|
529 | 529 | { |
530 | - $this->error="NotConnected"; |
|
530 | + $this->error = "NotConnected"; |
|
531 | 531 | return -2; |
532 | 532 | } |
533 | - if (! $this->bind) |
|
533 | + if (!$this->bind) |
|
534 | 534 | { |
535 | - $this->error="NotConnected"; |
|
535 | + $this->error = "NotConnected"; |
|
536 | 536 | return -3; |
537 | 537 | } |
538 | 538 | |
539 | 539 | // Encode to LDAP page code |
540 | - $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); |
|
541 | - $newrdn=$this->convFromOutputCharset($newrdn,$this->ldapcharset); |
|
542 | - $newparent=$this->convFromOutputCharset($newparent,$this->ldapcharset); |
|
540 | + $dn = $this->convFromOutputCharset($dn, $this->ldapcharset); |
|
541 | + $newrdn = $this->convFromOutputCharset($newrdn, $this->ldapcharset); |
|
542 | + $newparent = $this->convFromOutputCharset($newparent, $this->ldapcharset); |
|
543 | 543 | |
544 | 544 | //print_r($info); |
545 | - $result=@ldap_rename($this->connection, $dn, $newrdn, $newparent, $deleteoldrdn); |
|
545 | + $result = @ldap_rename($this->connection, $dn, $newrdn, $newparent, $deleteoldrdn); |
|
546 | 546 | |
547 | 547 | if ($result) |
548 | 548 | { |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | } |
552 | 552 | else |
553 | 553 | { |
554 | - $this->error=@ldap_error($this->connection); |
|
554 | + $this->error = @ldap_error($this->connection); |
|
555 | 555 | dol_syslog(get_class($this)."::rename failed: ".$this->error, LOG_ERR); |
556 | 556 | return -1; |
557 | 557 | } |
@@ -569,27 +569,27 @@ discard block |
||
569 | 569 | * @param string $newparent New parent (ou=xxx,dc=aaa,dc=bbb) (for ldap_rename) |
570 | 570 | * @return int <0 if KO, >0 if OK |
571 | 571 | */ |
572 | - function update($dn, $info, $user, $olddn, $newrdn=false, $newparent=false) |
|
572 | + function update($dn, $info, $user, $olddn, $newrdn = false, $newparent = false) |
|
573 | 573 | { |
574 | 574 | global $conf; |
575 | 575 | |
576 | 576 | dol_syslog(get_class($this)."::update dn=".$dn." olddn=".$olddn); |
577 | 577 | |
578 | 578 | // Check parameters |
579 | - if (! $this->connection) |
|
579 | + if (!$this->connection) |
|
580 | 580 | { |
581 | - $this->error="NotConnected"; |
|
581 | + $this->error = "NotConnected"; |
|
582 | 582 | return -2; |
583 | 583 | } |
584 | - if (! $this->bind) |
|
584 | + if (!$this->bind) |
|
585 | 585 | { |
586 | - $this->error="NotConnected"; |
|
586 | + $this->error = "NotConnected"; |
|
587 | 587 | return -3; |
588 | 588 | } |
589 | 589 | |
590 | - if (! $olddn || $olddn != $dn) |
|
590 | + if (!$olddn || $olddn != $dn) |
|
591 | 591 | { |
592 | - if (! empty($olddn) && ! empty($newrdn) && ! empty($newparent) && $conf->global->LDAP_SERVER_PROTOCOLVERSION === '3') |
|
592 | + if (!empty($olddn) && !empty($newrdn) && !empty($newparent) && $conf->global->LDAP_SERVER_PROTOCOLVERSION === '3') |
|
593 | 593 | { |
594 | 594 | // This function currently only works with LDAPv3 |
595 | 595 | $result = $this->rename($olddn, $newrdn, $newparent, $user, true); |
@@ -598,19 +598,19 @@ discard block |
||
598 | 598 | { |
599 | 599 | // If change we make is rename the key of LDAP record, we create new one and if ok, we delete old one. |
600 | 600 | $result = $this->add($dn, $info, $user); |
601 | - if ($result > 0 && $olddn && $olddn != $dn) $result = $this->delete($olddn); // If add fails, we do not try to delete old one |
|
601 | + if ($result > 0 && $olddn && $olddn != $dn) $result = $this->delete($olddn); // If add fails, we do not try to delete old one |
|
602 | 602 | } |
603 | 603 | } |
604 | 604 | else |
605 | 605 | { |
606 | 606 | //$result = $this->delete($olddn); |
607 | - $result = $this->add($dn, $info, $user); // If record has been deleted from LDAP, we recreate it. We ignore error if it already exists. |
|
608 | - $result = $this->modify($dn, $info, $user); // We use add/modify instead of delete/add when olddn is received |
|
607 | + $result = $this->add($dn, $info, $user); // If record has been deleted from LDAP, we recreate it. We ignore error if it already exists. |
|
608 | + $result = $this->modify($dn, $info, $user); // We use add/modify instead of delete/add when olddn is received |
|
609 | 609 | } |
610 | 610 | if ($result <= 0) |
611 | 611 | { |
612 | 612 | $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection)." ".$this->error; |
613 | - dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR); |
|
613 | + dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR); |
|
614 | 614 | //print_r($info); |
615 | 615 | return -1; |
616 | 616 | } |
@@ -636,21 +636,21 @@ discard block |
||
636 | 636 | dol_syslog(get_class($this)."::delete Delete LDAP entry dn=".$dn); |
637 | 637 | |
638 | 638 | // Check parameters |
639 | - if (! $this->connection) |
|
639 | + if (!$this->connection) |
|
640 | 640 | { |
641 | - $this->error="NotConnected"; |
|
641 | + $this->error = "NotConnected"; |
|
642 | 642 | return -2; |
643 | 643 | } |
644 | - if (! $this->bind) |
|
644 | + if (!$this->bind) |
|
645 | 645 | { |
646 | - $this->error="NotConnected"; |
|
646 | + $this->error = "NotConnected"; |
|
647 | 647 | return -3; |
648 | 648 | } |
649 | 649 | |
650 | 650 | // Encode to LDAP page code |
651 | - $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); |
|
651 | + $dn = $this->convFromOutputCharset($dn, $this->ldapcharset); |
|
652 | 652 | |
653 | - $result=@ldap_delete($this->connection, $dn); |
|
653 | + $result = @ldap_delete($this->connection, $dn); |
|
654 | 654 | |
655 | 655 | if ($result) return 1; |
656 | 656 | return -1; |
@@ -667,33 +667,33 @@ discard block |
||
667 | 667 | function dump_content($dn, $info) |
668 | 668 | { |
669 | 669 | // phpcs:enable |
670 | - $content=''; |
|
670 | + $content = ''; |
|
671 | 671 | |
672 | 672 | // Create file content |
673 | - if (preg_match('/^ldap/',$this->server[0])) |
|
673 | + if (preg_match('/^ldap/', $this->server[0])) |
|
674 | 674 | { |
675 | - $target="-H ".join(',',$this->server); |
|
675 | + $target = "-H ".join(',', $this->server); |
|
676 | 676 | } |
677 | 677 | else |
678 | 678 | { |
679 | - $target="-h ".join(',',$this->server)." -p ".$this->serverPort; |
|
679 | + $target = "-h ".join(',', $this->server)." -p ".$this->serverPort; |
|
680 | 680 | } |
681 | - $content.="# ldapadd $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"; |
|
682 | - $content.="# ldapmodify $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"; |
|
683 | - $content.="# ldapdelete $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"; |
|
684 | - if (in_array('localhost',$this->server)) $content.="# If commands fails to connect, try without -h and -p\n"; |
|
685 | - $content.="dn: ".$dn."\n"; |
|
686 | - foreach($info as $key => $value) |
|
681 | + $content .= "# ldapadd $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"; |
|
682 | + $content .= "# ldapmodify $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"; |
|
683 | + $content .= "# ldapdelete $target -c -v -D ".$this->searchUser." -W -f ldapinput.in\n"; |
|
684 | + if (in_array('localhost', $this->server)) $content .= "# If commands fails to connect, try without -h and -p\n"; |
|
685 | + $content .= "dn: ".$dn."\n"; |
|
686 | + foreach ($info as $key => $value) |
|
687 | 687 | { |
688 | - if (! is_array($value)) |
|
688 | + if (!is_array($value)) |
|
689 | 689 | { |
690 | - $content.="$key: $value\n"; |
|
690 | + $content .= "$key: $value\n"; |
|
691 | 691 | } |
692 | 692 | else |
693 | 693 | { |
694 | - foreach($value as $valuekey => $valuevalue) |
|
694 | + foreach ($value as $valuekey => $valuevalue) |
|
695 | 695 | { |
696 | - $content.="$key: $valuevalue\n"; |
|
696 | + $content .= "$key: $valuevalue\n"; |
|
697 | 697 | } |
698 | 698 | } |
699 | 699 | } |
@@ -712,18 +712,18 @@ discard block |
||
712 | 712 | global $conf; |
713 | 713 | |
714 | 714 | // Create content |
715 | - $content=$this->dump_content($dn, $info); |
|
715 | + $content = $this->dump_content($dn, $info); |
|
716 | 716 | |
717 | 717 | //Create file |
718 | - $result=dol_mkdir($conf->ldap->dir_temp); |
|
718 | + $result = dol_mkdir($conf->ldap->dir_temp); |
|
719 | 719 | |
720 | - $outputfile=$conf->ldap->dir_temp.'/ldapinput.in'; |
|
721 | - $fp=fopen($outputfile,"w"); |
|
720 | + $outputfile = $conf->ldap->dir_temp.'/ldapinput.in'; |
|
721 | + $fp = fopen($outputfile, "w"); |
|
722 | 722 | if ($fp) |
723 | 723 | { |
724 | 724 | fputs($fp, $content); |
725 | 725 | fclose($fp); |
726 | - if (! empty($conf->global->MAIN_UMASK)) |
|
726 | + if (!empty($conf->global->MAIN_UMASK)) |
|
727 | 727 | @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
728 | 728 | return 1; |
729 | 729 | } |
@@ -741,14 +741,14 @@ discard block |
||
741 | 741 | * @param int $timeout Timeout in second (default 1s) |
742 | 742 | * @return boolean true or false |
743 | 743 | */ |
744 | - function serverPing($host, $port=389, $timeout=1) |
|
744 | + function serverPing($host, $port = 389, $timeout = 1) |
|
745 | 745 | { |
746 | 746 | // Replace ldaps:// by ssl:// |
747 | - if (preg_match('/^ldaps:\/\/([^\/]+)\/?$/',$host, $regs)) { |
|
747 | + if (preg_match('/^ldaps:\/\/([^\/]+)\/?$/', $host, $regs)) { |
|
748 | 748 | $host = 'ssl://'.$regs[1]; |
749 | 749 | } |
750 | 750 | // Remove ldap:// |
751 | - if (preg_match('/^ldap:\/\/([^\/]+)\/?$/',$host, $regs)) { |
|
751 | + if (preg_match('/^ldap:\/\/([^\/]+)\/?$/', $host, $regs)) { |
|
752 | 752 | $host = $regs[1]; |
753 | 753 | } |
754 | 754 | $op = @fsockopen($host, $port, $errno, $errstr, $timeout); |
@@ -775,31 +775,31 @@ discard block |
||
775 | 775 | { |
776 | 776 | global $conf; |
777 | 777 | |
778 | - dol_syslog(get_class($this)."::addAttribute dn=".$dn." info=".join(',',$info)); |
|
778 | + dol_syslog(get_class($this)."::addAttribute dn=".$dn." info=".join(',', $info)); |
|
779 | 779 | |
780 | 780 | // Check parameters |
781 | - if (! $this->connection) |
|
781 | + if (!$this->connection) |
|
782 | 782 | { |
783 | - $this->error="NotConnected"; |
|
783 | + $this->error = "NotConnected"; |
|
784 | 784 | return -2; |
785 | 785 | } |
786 | - if (! $this->bind) |
|
786 | + if (!$this->bind) |
|
787 | 787 | { |
788 | - $this->error="NotConnected"; |
|
788 | + $this->error = "NotConnected"; |
|
789 | 789 | return -3; |
790 | 790 | } |
791 | 791 | |
792 | 792 | // Encode to LDAP page code |
793 | - $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); |
|
794 | - foreach($info as $key => $val) |
|
793 | + $dn = $this->convFromOutputCharset($dn, $this->ldapcharset); |
|
794 | + foreach ($info as $key => $val) |
|
795 | 795 | { |
796 | - if (! is_array($val)) $info[$key]=$this->convFromOutputCharset($val,$this->ldapcharset); |
|
796 | + if (!is_array($val)) $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset); |
|
797 | 797 | } |
798 | 798 | |
799 | - $this->dump($dn,$info); |
|
799 | + $this->dump($dn, $info); |
|
800 | 800 | |
801 | 801 | //print_r($info); |
802 | - $result=@ldap_mod_add($this->connection, $dn, $info); |
|
802 | + $result = @ldap_mod_add($this->connection, $dn, $info); |
|
803 | 803 | |
804 | 804 | if ($result) |
805 | 805 | { |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | } |
809 | 809 | else |
810 | 810 | { |
811 | - $this->error=@ldap_error($this->connection); |
|
811 | + $this->error = @ldap_error($this->connection); |
|
812 | 812 | dol_syslog(get_class($this)."::add_attribute failed: ".$this->error, LOG_ERR); |
813 | 813 | return -1; |
814 | 814 | } |
@@ -827,31 +827,31 @@ discard block |
||
827 | 827 | { |
828 | 828 | global $conf; |
829 | 829 | |
830 | - dol_syslog(get_class($this)."::updateAttribute dn=".$dn." info=".join(',',$info)); |
|
830 | + dol_syslog(get_class($this)."::updateAttribute dn=".$dn." info=".join(',', $info)); |
|
831 | 831 | |
832 | 832 | // Check parameters |
833 | - if (! $this->connection) |
|
833 | + if (!$this->connection) |
|
834 | 834 | { |
835 | - $this->error="NotConnected"; |
|
835 | + $this->error = "NotConnected"; |
|
836 | 836 | return -2; |
837 | 837 | } |
838 | - if (! $this->bind) |
|
838 | + if (!$this->bind) |
|
839 | 839 | { |
840 | - $this->error="NotConnected"; |
|
840 | + $this->error = "NotConnected"; |
|
841 | 841 | return -3; |
842 | 842 | } |
843 | 843 | |
844 | 844 | // Encode to LDAP page code |
845 | - $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); |
|
846 | - foreach($info as $key => $val) |
|
845 | + $dn = $this->convFromOutputCharset($dn, $this->ldapcharset); |
|
846 | + foreach ($info as $key => $val) |
|
847 | 847 | { |
848 | - if (! is_array($val)) $info[$key]=$this->convFromOutputCharset($val,$this->ldapcharset); |
|
848 | + if (!is_array($val)) $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset); |
|
849 | 849 | } |
850 | 850 | |
851 | - $this->dump($dn,$info); |
|
851 | + $this->dump($dn, $info); |
|
852 | 852 | |
853 | 853 | //print_r($info); |
854 | - $result=@ldap_mod_replace($this->connection, $dn, $info); |
|
854 | + $result = @ldap_mod_replace($this->connection, $dn, $info); |
|
855 | 855 | |
856 | 856 | if ($result) |
857 | 857 | { |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | } |
861 | 861 | else |
862 | 862 | { |
863 | - $this->error=@ldap_error($this->connection); |
|
863 | + $this->error = @ldap_error($this->connection); |
|
864 | 864 | dol_syslog(get_class($this)."::updateAttribute failed: ".$this->error, LOG_ERR); |
865 | 865 | return -1; |
866 | 866 | } |
@@ -879,31 +879,31 @@ discard block |
||
879 | 879 | { |
880 | 880 | global $conf; |
881 | 881 | |
882 | - dol_syslog(get_class($this)."::deleteAttribute dn=".$dn." info=".join(',',$info)); |
|
882 | + dol_syslog(get_class($this)."::deleteAttribute dn=".$dn." info=".join(',', $info)); |
|
883 | 883 | |
884 | 884 | // Check parameters |
885 | - if (! $this->connection) |
|
885 | + if (!$this->connection) |
|
886 | 886 | { |
887 | - $this->error="NotConnected"; |
|
887 | + $this->error = "NotConnected"; |
|
888 | 888 | return -2; |
889 | 889 | } |
890 | - if (! $this->bind) |
|
890 | + if (!$this->bind) |
|
891 | 891 | { |
892 | - $this->error="NotConnected"; |
|
892 | + $this->error = "NotConnected"; |
|
893 | 893 | return -3; |
894 | 894 | } |
895 | 895 | |
896 | 896 | // Encode to LDAP page code |
897 | - $dn=$this->convFromOutputCharset($dn,$this->ldapcharset); |
|
898 | - foreach($info as $key => $val) |
|
897 | + $dn = $this->convFromOutputCharset($dn, $this->ldapcharset); |
|
898 | + foreach ($info as $key => $val) |
|
899 | 899 | { |
900 | - if (! is_array($val)) $info[$key]=$this->convFromOutputCharset($val,$this->ldapcharset); |
|
900 | + if (!is_array($val)) $info[$key] = $this->convFromOutputCharset($val, $this->ldapcharset); |
|
901 | 901 | } |
902 | 902 | |
903 | - $this->dump($dn,$info); |
|
903 | + $this->dump($dn, $info); |
|
904 | 904 | |
905 | 905 | //print_r($info); |
906 | - $result=@ldap_mod_del($this->connection, $dn, $info); |
|
906 | + $result = @ldap_mod_del($this->connection, $dn, $info); |
|
907 | 907 | |
908 | 908 | if ($result) |
909 | 909 | { |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | } |
913 | 913 | else |
914 | 914 | { |
915 | - $this->error=@ldap_error($this->connection); |
|
915 | + $this->error = @ldap_error($this->connection); |
|
916 | 916 | dol_syslog(get_class($this)."::deleteAttribute failed: ".$this->error, LOG_ERR); |
917 | 917 | return -1; |
918 | 918 | } |
@@ -925,21 +925,21 @@ discard block |
||
925 | 925 | * @param string $filter Filter |
926 | 926 | * @return int|array <0 or false if KO, array if OK |
927 | 927 | */ |
928 | - function getAttribute($dn,$filter) |
|
928 | + function getAttribute($dn, $filter) |
|
929 | 929 | { |
930 | 930 | // Check parameters |
931 | - if (! $this->connection) |
|
931 | + if (!$this->connection) |
|
932 | 932 | { |
933 | - $this->error="NotConnected"; |
|
933 | + $this->error = "NotConnected"; |
|
934 | 934 | return -2; |
935 | 935 | } |
936 | - if (! $this->bind) |
|
936 | + if (!$this->bind) |
|
937 | 937 | { |
938 | - $this->error="NotConnected"; |
|
938 | + $this->error = "NotConnected"; |
|
939 | 939 | return -3; |
940 | 940 | } |
941 | 941 | |
942 | - $search = ldap_search($this->connection,$dn,$filter); |
|
942 | + $search = ldap_search($this->connection, $dn, $filter); |
|
943 | 943 | |
944 | 944 | // Only one entry should ever be returned |
945 | 945 | $entry = ldap_first_entry($this->connection, $search); |
@@ -948,11 +948,11 @@ discard block |
||
948 | 948 | { |
949 | 949 | $this->ldapErrorCode = -1; |
950 | 950 | $this->ldapErrorText = "Couldn't find entry"; |
951 | - return 0; // Couldn't find entry... |
|
951 | + return 0; // Couldn't find entry... |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | // Get values |
955 | - if (! $values = ldap_get_attributes($this->connection, $entry)) |
|
955 | + if (!$values = ldap_get_attributes($this->connection, $entry)) |
|
956 | 956 | { |
957 | 957 | $this->ldapErrorCode = ldap_errno($this->connection); |
958 | 958 | $this->ldapErrorText = ldap_error($this->connection); |
@@ -970,13 +970,13 @@ discard block |
||
970 | 970 | * @param string $attribute Attributes |
971 | 971 | * @return void |
972 | 972 | */ |
973 | - function getAttributeValues($filterrecord,$attribute) |
|
973 | + function getAttributeValues($filterrecord, $attribute) |
|
974 | 974 | { |
975 | - $attributes=array(); |
|
975 | + $attributes = array(); |
|
976 | 976 | $attributes[0] = $attribute; |
977 | 977 | |
978 | 978 | // We need to search for this user in order to get their entry. |
979 | - $this->result = @ldap_search($this->connection,$this->people,$filterrecord,$attributes); |
|
979 | + $this->result = @ldap_search($this->connection, $this->people, $filterrecord, $attributes); |
|
980 | 980 | |
981 | 981 | // Pourquoi cette ligne ? |
982 | 982 | //$info = ldap_get_entries($this->connection, $this->result); |
@@ -988,11 +988,11 @@ discard block |
||
988 | 988 | { |
989 | 989 | $this->ldapErrorCode = -1; |
990 | 990 | $this->ldapErrorText = "Couldn't find user"; |
991 | - return false; // Couldn't find the user... |
|
991 | + return false; // Couldn't find the user... |
|
992 | 992 | } |
993 | 993 | |
994 | 994 | // Get values |
995 | - if (! $values = @ldap_get_values($this->connection, $entry, $attribute)) |
|
995 | + if (!$values = @ldap_get_values($this->connection, $entry, $attribute)) |
|
996 | 996 | { |
997 | 997 | $this->ldapErrorCode = ldap_errno($this->connection); |
998 | 998 | $this->ldapErrorText = ldap_error($this->connection); |
@@ -1015,11 +1015,11 @@ discard block |
||
1015 | 1015 | * @param array $attributeAsArray Array of fields wanted as an array not a string |
1016 | 1016 | * @return array Array of [id_record][ldap_field]=value |
1017 | 1017 | */ |
1018 | - function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter=0, $attributeAsArray=array()) |
|
1018 | + function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter = 0, $attributeAsArray = array()) |
|
1019 | 1019 | { |
1020 | - $fulllist=array(); |
|
1020 | + $fulllist = array(); |
|
1021 | 1021 | |
1022 | - dol_syslog(get_class($this)."::getRecords search=".$search." userDn=".$userDn." useridentifier=".$useridentifier." attributeArray=array(".join(',',$attributeArray).") activefilter=".$activefilter); |
|
1022 | + dol_syslog(get_class($this)."::getRecords search=".$search." userDn=".$userDn." useridentifier=".$useridentifier." attributeArray=array(".join(',', $attributeArray).") activefilter=".$activefilter); |
|
1023 | 1023 | |
1024 | 1024 | // if the directory is AD, then bind first with the search user first |
1025 | 1025 | if ($this->serverType == "activedirectory") |
@@ -1029,7 +1029,7 @@ discard block |
||
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | // Define filter |
1032 | - if (! empty($activefilter)) |
|
1032 | + if (!empty($activefilter)) |
|
1033 | 1033 | { |
1034 | 1034 | if (((string) $activefilter == '1' || (string) $activefilter == 'user') && $this->filter) |
1035 | 1035 | { |
@@ -1052,8 +1052,8 @@ discard block |
||
1052 | 1052 | if (is_array($attributeArray)) |
1053 | 1053 | { |
1054 | 1054 | // Return list with required fields |
1055 | - $attributeArray=array_values($attributeArray); // This is to force to have index reordered from 0 (not make ldap_search fails) |
|
1056 | - dol_syslog(get_class($this)."::getRecords connection=".$this->connection." userDn=".$userDn." filter=".$filter. " attributeArray=(".join(',',$attributeArray).")"); |
|
1055 | + $attributeArray = array_values($attributeArray); // This is to force to have index reordered from 0 (not make ldap_search fails) |
|
1056 | + dol_syslog(get_class($this)."::getRecords connection=".$this->connection." userDn=".$userDn." filter=".$filter." attributeArray=(".join(',', $attributeArray).")"); |
|
1057 | 1057 | //var_dump($attributeArray); |
1058 | 1058 | $this->result = @ldap_search($this->connection, $userDn, $filter, $attributeArray); |
1059 | 1059 | } |
@@ -1077,35 +1077,35 @@ discard block |
||
1077 | 1077 | |
1078 | 1078 | for ($i = 0; $i < $info["count"]; $i++) |
1079 | 1079 | { |
1080 | - $recordid=$this->convToOutputCharset($info[$i][$useridentifier][0],$this->ldapcharset); |
|
1080 | + $recordid = $this->convToOutputCharset($info[$i][$useridentifier][0], $this->ldapcharset); |
|
1081 | 1081 | if ($recordid) |
1082 | 1082 | { |
1083 | 1083 | //print "Found record with key $useridentifier=".$recordid."<br>\n"; |
1084 | - $fulllist[$recordid][$useridentifier]=$recordid; |
|
1084 | + $fulllist[$recordid][$useridentifier] = $recordid; |
|
1085 | 1085 | |
1086 | 1086 | // Add to the array for each attribute in my list |
1087 | 1087 | $num = count($attributeArray); |
1088 | 1088 | for ($j = 0; $j < $num; $j++) |
1089 | 1089 | { |
1090 | - $keyattributelower=strtolower($attributeArray[$j]); |
|
1090 | + $keyattributelower = strtolower($attributeArray[$j]); |
|
1091 | 1091 | //print " Param ".$attributeArray[$j]."=".$info[$i][$keyattributelower][0]."<br>\n"; |
1092 | 1092 | |
1093 | 1093 | //permet de recuperer le SID avec Active Directory |
1094 | 1094 | if ($this->serverType == "activedirectory" && $keyattributelower == "objectsid") |
1095 | 1095 | { |
1096 | 1096 | $objectsid = $this->getObjectSid($recordid); |
1097 | - $fulllist[$recordid][$attributeArray[$j]] = $objectsid; |
|
1097 | + $fulllist[$recordid][$attributeArray[$j]] = $objectsid; |
|
1098 | 1098 | } |
1099 | 1099 | else |
1100 | 1100 | { |
1101 | - if(in_array($attributeArray[$j], $attributeAsArray) && is_array($info[$i][$keyattributelower])) { |
|
1101 | + if (in_array($attributeArray[$j], $attributeAsArray) && is_array($info[$i][$keyattributelower])) { |
|
1102 | 1102 | $valueTab = array(); |
1103 | - foreach($info[$i][$keyattributelower] as $key => $value) { |
|
1104 | - $valueTab[$key] = $this->convToOutputCharset($value,$this->ldapcharset); |
|
1103 | + foreach ($info[$i][$keyattributelower] as $key => $value) { |
|
1104 | + $valueTab[$key] = $this->convToOutputCharset($value, $this->ldapcharset); |
|
1105 | 1105 | } |
1106 | 1106 | $fulllist[$recordid][$attributeArray[$j]] = $valueTab; |
1107 | 1107 | } else { |
1108 | - $fulllist[$recordid][$attributeArray[$j]] = $this->convToOutputCharset($info[$i][$keyattributelower][0],$this->ldapcharset); |
|
1108 | + $fulllist[$recordid][$attributeArray[$j]] = $this->convToOutputCharset($info[$i][$keyattributelower][0], $this->ldapcharset); |
|
1109 | 1109 | } |
1110 | 1110 | } |
1111 | 1111 | } |
@@ -1125,8 +1125,8 @@ discard block |
||
1125 | 1125 | */ |
1126 | 1126 | function littleEndian($hex) |
1127 | 1127 | { |
1128 | - for ($x=dol_strlen($hex)-2; $x >= 0; $x=$x-2) { |
|
1129 | - $result .= substr($hex,$x,2); |
|
1128 | + for ($x = dol_strlen($hex) - 2; $x >= 0; $x = $x - 2) { |
|
1129 | + $result .= substr($hex, $x, 2); |
|
1130 | 1130 | } |
1131 | 1131 | return $result; |
1132 | 1132 | } |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | */ |
1142 | 1142 | function getObjectSid($ldapUser) |
1143 | 1143 | { |
1144 | - $criteria = '('.$this->getUserIdentifier().'='.$ldapUser.')'; |
|
1144 | + $criteria = '('.$this->getUserIdentifier().'='.$ldapUser.')'; |
|
1145 | 1145 | $justthese = array("objectsid"); |
1146 | 1146 | |
1147 | 1147 | // if the directory is AD, then bind first with the search user first |
@@ -1200,14 +1200,14 @@ discard block |
||
1200 | 1200 | */ |
1201 | 1201 | function binSIDtoText($binsid) |
1202 | 1202 | { |
1203 | - $hex_sid=bin2hex($binsid); |
|
1204 | - $rev = hexdec(substr($hex_sid,0,2)); // Get revision-part of SID |
|
1205 | - $subcount = hexdec(substr($hex_sid,2,2)); // Get count of sub-auth entries |
|
1206 | - $auth = hexdec(substr($hex_sid,4,12)); // SECURITY_NT_AUTHORITY |
|
1203 | + $hex_sid = bin2hex($binsid); |
|
1204 | + $rev = hexdec(substr($hex_sid, 0, 2)); // Get revision-part of SID |
|
1205 | + $subcount = hexdec(substr($hex_sid, 2, 2)); // Get count of sub-auth entries |
|
1206 | + $auth = hexdec(substr($hex_sid, 4, 12)); // SECURITY_NT_AUTHORITY |
|
1207 | 1207 | $result = "$rev-$auth"; |
1208 | - for ($x=0;$x < $subcount; $x++) |
|
1208 | + for ($x = 0; $x < $subcount; $x++) |
|
1209 | 1209 | { |
1210 | - $result .= "-".hexdec($this->littleEndian(substr($hex_sid,16+($x*8),8))); // get all SECURITY_NT_AUTHORITY |
|
1210 | + $result .= "-".hexdec($this->littleEndian(substr($hex_sid, 16 + ($x * 8), 8))); // get all SECURITY_NT_AUTHORITY |
|
1211 | 1211 | } |
1212 | 1212 | return $result; |
1213 | 1213 | } |
@@ -1228,8 +1228,8 @@ discard block |
||
1228 | 1228 | { |
1229 | 1229 | dol_syslog(get_class($this)."::search checkDn=".$checkDn." filter=".$filter); |
1230 | 1230 | |
1231 | - $checkDn=$this->convFromOutputCharset($checkDn,$this->ldapcharset); |
|
1232 | - $filter=$this->convFromOutputCharset($filter,$this->ldapcharset); |
|
1231 | + $checkDn = $this->convFromOutputCharset($checkDn, $this->ldapcharset); |
|
1232 | + $filter = $this->convFromOutputCharset($filter, $this->ldapcharset); |
|
1233 | 1233 | |
1234 | 1234 | // if the directory is AD, then bind first with the search user first |
1235 | 1235 | if ($this->serverType == "activedirectory") { |
@@ -1239,7 +1239,7 @@ discard block |
||
1239 | 1239 | $this->result = @ldap_search($this->connection, $checkDn, $filter); |
1240 | 1240 | |
1241 | 1241 | $result = @ldap_get_entries($this->connection, $this->result); |
1242 | - if (! $result) |
|
1242 | + if (!$result) |
|
1243 | 1243 | { |
1244 | 1244 | $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection); |
1245 | 1245 | return -1; |
@@ -1260,7 +1260,7 @@ discard block |
||
1260 | 1260 | * Examples: &(objectClass=inetOrgPerson) &(objectClass=user)(objectCategory=person) &(isMemberOf=cn=Sales,ou=Groups,dc=opencsi,dc=com) |
1261 | 1261 | * @return int >0 if OK, <0 if KO |
1262 | 1262 | */ |
1263 | - function fetch($user,$filter) |
|
1263 | + function fetch($user, $filter) |
|
1264 | 1264 | { |
1265 | 1265 | // Perform the search and get the entry handles |
1266 | 1266 | |
@@ -1269,10 +1269,10 @@ discard block |
||
1269 | 1269 | $this->bindauth($this->searchUser, $this->searchPassword); |
1270 | 1270 | } |
1271 | 1271 | |
1272 | - $searchDN = $this->people; // TODO Why searching in people then domain ? |
|
1272 | + $searchDN = $this->people; // TODO Why searching in people then domain ? |
|
1273 | 1273 | |
1274 | 1274 | $result = ''; |
1275 | - $i=0; |
|
1275 | + $i = 0; |
|
1276 | 1276 | while ($i <= 2) |
1277 | 1277 | { |
1278 | 1278 | dol_syslog(get_class($this)."::fetch search with searchDN=".$searchDN." filter=".$filter); |
@@ -1291,7 +1291,7 @@ discard block |
||
1291 | 1291 | return -1; |
1292 | 1292 | } |
1293 | 1293 | |
1294 | - if (! $result) |
|
1294 | + if (!$result) |
|
1295 | 1295 | { |
1296 | 1296 | // Si pas de resultat on cherche dans le domaine |
1297 | 1297 | $searchDN = $this->domain; |
@@ -1303,42 +1303,42 @@ discard block |
||
1303 | 1303 | } |
1304 | 1304 | } |
1305 | 1305 | |
1306 | - if (! $result) |
|
1306 | + if (!$result) |
|
1307 | 1307 | { |
1308 | 1308 | $this->error = ldap_errno($this->connection)." ".ldap_error($this->connection); |
1309 | 1309 | return -1; |
1310 | 1310 | } |
1311 | 1311 | else |
1312 | 1312 | { |
1313 | - $this->name = $this->convToOutputCharset($result[0][$this->attr_name][0],$this->ldapcharset); |
|
1314 | - $this->firstname = $this->convToOutputCharset($result[0][$this->attr_firstname][0],$this->ldapcharset); |
|
1315 | - $this->login = $this->convToOutputCharset($result[0][$this->attr_login][0],$this->ldapcharset); |
|
1316 | - $this->phone = $this->convToOutputCharset($result[0][$this->attr_phone][0],$this->ldapcharset); |
|
1317 | - $this->skype = $this->convToOutputCharset($result[0][$this->attr_skype][0],$this->ldapcharset); |
|
1318 | - $this->fax = $this->convToOutputCharset($result[0][$this->attr_fax][0],$this->ldapcharset); |
|
1319 | - $this->mail = $this->convToOutputCharset($result[0][$this->attr_mail][0],$this->ldapcharset); |
|
1320 | - $this->mobile = $this->convToOutputCharset($result[0][$this->attr_mobile][0],$this->ldapcharset); |
|
1313 | + $this->name = $this->convToOutputCharset($result[0][$this->attr_name][0], $this->ldapcharset); |
|
1314 | + $this->firstname = $this->convToOutputCharset($result[0][$this->attr_firstname][0], $this->ldapcharset); |
|
1315 | + $this->login = $this->convToOutputCharset($result[0][$this->attr_login][0], $this->ldapcharset); |
|
1316 | + $this->phone = $this->convToOutputCharset($result[0][$this->attr_phone][0], $this->ldapcharset); |
|
1317 | + $this->skype = $this->convToOutputCharset($result[0][$this->attr_skype][0], $this->ldapcharset); |
|
1318 | + $this->fax = $this->convToOutputCharset($result[0][$this->attr_fax][0], $this->ldapcharset); |
|
1319 | + $this->mail = $this->convToOutputCharset($result[0][$this->attr_mail][0], $this->ldapcharset); |
|
1320 | + $this->mobile = $this->convToOutputCharset($result[0][$this->attr_mobile][0], $this->ldapcharset); |
|
1321 | 1321 | |
1322 | - $this->uacf = $this->parseUACF($this->convToOutputCharset($result[0]["useraccountcontrol"][0],$this->ldapcharset)); |
|
1322 | + $this->uacf = $this->parseUACF($this->convToOutputCharset($result[0]["useraccountcontrol"][0], $this->ldapcharset)); |
|
1323 | 1323 | if (isset($result[0]["pwdlastset"][0])) // If expiration on password exists |
1324 | 1324 | { |
1325 | - $this->pwdlastset = ($result[0]["pwdlastset"][0] != 0)?$this->convert_time($this->convToOutputCharset($result[0]["pwdlastset"][0],$this->ldapcharset)):0; |
|
1325 | + $this->pwdlastset = ($result[0]["pwdlastset"][0] != 0) ? $this->convert_time($this->convToOutputCharset($result[0]["pwdlastset"][0], $this->ldapcharset)) : 0; |
|
1326 | 1326 | } |
1327 | 1327 | else |
1328 | 1328 | { |
1329 | 1329 | $this->pwdlastset = -1; |
1330 | 1330 | } |
1331 | 1331 | if (!$this->name && !$this->login) $this->pwdlastset = -1; |
1332 | - $this->badpwdtime = $this->convert_time($this->convToOutputCharset($result[0]["badpasswordtime"][0],$this->ldapcharset)); |
|
1332 | + $this->badpwdtime = $this->convert_time($this->convToOutputCharset($result[0]["badpasswordtime"][0], $this->ldapcharset)); |
|
1333 | 1333 | |
1334 | 1334 | // FQDN domain |
1335 | - $domain = str_replace('dc=','',$this->domain); |
|
1336 | - $domain = str_replace(',','.',$domain); |
|
1335 | + $domain = str_replace('dc=', '', $this->domain); |
|
1336 | + $domain = str_replace(',', '.', $domain); |
|
1337 | 1337 | $this->domainFQDN = $domain; |
1338 | 1338 | |
1339 | 1339 | // Set ldapUserDn (each user can have a different dn) |
1340 | 1340 | //var_dump($result[0]);exit; |
1341 | - $this->ldapUserDN=$result[0]['dn']; |
|
1341 | + $this->ldapUserDN = $result[0]['dn']; |
|
1342 | 1342 | |
1343 | 1343 | ldap_free_result($this->result); |
1344 | 1344 | return 1; |
@@ -1433,7 +1433,7 @@ discard block |
||
1433 | 1433 | break; |
1434 | 1434 | } |
1435 | 1435 | } |
1436 | - if (empty($retval)) $retval = "UNKNOWN_TYPE_" . $samtype; |
|
1436 | + if (empty($retval)) $retval = "UNKNOWN_TYPE_".$samtype; |
|
1437 | 1437 | |
1438 | 1438 | return($retval); |
1439 | 1439 | } |
@@ -1448,10 +1448,10 @@ discard block |
||
1448 | 1448 | function convert_time($value) |
1449 | 1449 | { |
1450 | 1450 | // phpcs:enable |
1451 | - $dateLargeInt=$value; // nano secondes depuis 1601 !!!! |
|
1451 | + $dateLargeInt = $value; // nano secondes depuis 1601 !!!! |
|
1452 | 1452 | $secsAfterADEpoch = $dateLargeInt / (10000000); // secondes depuis le 1 jan 1601 |
1453 | - $ADToUnixConvertor=((1970-1601) * 365.242190) * 86400; // UNIX start date - AD start date * jours * secondes |
|
1454 | - $unixTimeStamp=intval($secsAfterADEpoch-$ADToUnixConvertor); // Unix time stamp |
|
1453 | + $ADToUnixConvertor = ((1970 - 1601) * 365.242190) * 86400; // UNIX start date - AD start date * jours * secondes |
|
1454 | + $unixTimeStamp = intval($secsAfterADEpoch - $ADToUnixConvertor); // Unix time stamp |
|
1455 | 1455 | return $unixTimeStamp; |
1456 | 1456 | } |
1457 | 1457 | |
@@ -1463,11 +1463,11 @@ discard block |
||
1463 | 1463 | * @param string $pagecodefrom Page code of src string |
1464 | 1464 | * @return string Converted string |
1465 | 1465 | */ |
1466 | - private function convToOutputCharset($str,$pagecodefrom='UTF-8') |
|
1466 | + private function convToOutputCharset($str, $pagecodefrom = 'UTF-8') |
|
1467 | 1467 | { |
1468 | 1468 | global $conf; |
1469 | - if ($pagecodefrom == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') $str=utf8_encode($str); |
|
1470 | - if ($pagecodefrom == 'UTF-8' && $conf->file->character_set_client == 'ISO-8859-1') $str=utf8_decode($str); |
|
1469 | + if ($pagecodefrom == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') $str = utf8_encode($str); |
|
1470 | + if ($pagecodefrom == 'UTF-8' && $conf->file->character_set_client == 'ISO-8859-1') $str = utf8_decode($str); |
|
1471 | 1471 | return $str; |
1472 | 1472 | } |
1473 | 1473 | |
@@ -1478,11 +1478,11 @@ discard block |
||
1478 | 1478 | * @param string $pagecodeto Page code for result string |
1479 | 1479 | * @return string Converted string |
1480 | 1480 | */ |
1481 | - function convFromOutputCharset($str,$pagecodeto='UTF-8') |
|
1481 | + function convFromOutputCharset($str, $pagecodeto = 'UTF-8') |
|
1482 | 1482 | { |
1483 | 1483 | global $conf; |
1484 | - if ($pagecodeto == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') $str=utf8_decode($str); |
|
1485 | - if ($pagecodeto == 'UTF-8' && $conf->file->character_set_client == 'ISO-8859-1') $str=utf8_encode($str); |
|
1484 | + if ($pagecodeto == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') $str = utf8_decode($str); |
|
1485 | + if ($pagecodeto == 'UTF-8' && $conf->file->character_set_client == 'ISO-8859-1') $str = utf8_encode($str); |
|
1486 | 1486 | return $str; |
1487 | 1487 | } |
1488 | 1488 | |
@@ -1493,25 +1493,25 @@ discard block |
||
1493 | 1493 | * @param string $keygroup Key of group |
1494 | 1494 | * @return int gid number |
1495 | 1495 | */ |
1496 | - function getNextGroupGid($keygroup='LDAP_KEY_GROUPS') |
|
1496 | + function getNextGroupGid($keygroup = 'LDAP_KEY_GROUPS') |
|
1497 | 1497 | { |
1498 | 1498 | global $conf; |
1499 | 1499 | |
1500 | - if (empty($keygroup)) $keygroup='LDAP_KEY_GROUPS'; |
|
1500 | + if (empty($keygroup)) $keygroup = 'LDAP_KEY_GROUPS'; |
|
1501 | 1501 | |
1502 | - $search='('.$conf->global->$keygroup.'=*)'; |
|
1503 | - $result = $this->search($this->groups,$search); |
|
1502 | + $search = '('.$conf->global->$keygroup.'=*)'; |
|
1503 | + $result = $this->search($this->groups, $search); |
|
1504 | 1504 | if ($result) |
1505 | 1505 | { |
1506 | 1506 | $c = $result['count']; |
1507 | 1507 | $gids = array(); |
1508 | - for($i=0;$i<$c;$i++) |
|
1508 | + for ($i = 0; $i < $c; $i++) |
|
1509 | 1509 | { |
1510 | 1510 | $gids[] = $result[$i]['gidnumber'][0]; |
1511 | 1511 | } |
1512 | 1512 | rsort($gids); |
1513 | 1513 | |
1514 | - return $gids[0]+1; |
|
1514 | + return $gids[0] + 1; |
|
1515 | 1515 | } |
1516 | 1516 | |
1517 | 1517 | return 0; |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * @var string Error code (or message) |
35 | 35 | */ |
36 | - public $error=''; |
|
36 | + public $error = ''; |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @var string[] Error codes (or messages) |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | function __construct($db) |
59 | 59 | { |
60 | - $this->db=$db; |
|
60 | + $this->db = $db; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -82,17 +82,17 @@ discard block |
||
82 | 82 | return -97; |
83 | 83 | } |
84 | 84 | |
85 | - $fullcommand=$this->getCliCommand($file); |
|
85 | + $fullcommand = $this->getCliCommand($file); |
|
86 | 86 | //$fullcommand='"c:\Program Files (x86)\ClamWin\bin\clamscan.exe" --database="C:\Program Files (x86)\ClamWin\lib" "c:\temp\aaa.txt"'; |
87 | - $fullcommand.=' 2>&1'; // This is to get error output |
|
87 | + $fullcommand .= ' 2>&1'; // This is to get error output |
|
88 | 88 | |
89 | - $output=array(); |
|
90 | - $return_var=0; |
|
91 | - $safemode=ini_get("safe_mode"); |
|
89 | + $output = array(); |
|
90 | + $return_var = 0; |
|
91 | + $safemode = ini_get("safe_mode"); |
|
92 | 92 | // Create a clean fullcommand |
93 | - dol_syslog("AntiVir::dol_avscan_file Run command=".$fullcommand." with safe_mode ".($safemode?"on":"off")); |
|
93 | + dol_syslog("AntiVir::dol_avscan_file Run command=".$fullcommand." with safe_mode ".($safemode ? "on" : "off")); |
|
94 | 94 | // Run CLI command. If run of Windows, you can get return with echo %ERRORLEVEL% |
95 | - $lastline=exec($fullcommand, $output, $return_var); |
|
95 | + $lastline = exec($fullcommand, $output, $return_var); |
|
96 | 96 | |
97 | 97 | //print "x".$lastline." - ".join(',',$output)." - ".$return_var."y";exit; |
98 | 98 | |
@@ -126,18 +126,18 @@ discard block |
||
126 | 126 | } |
127 | 127 | */ |
128 | 128 | |
129 | - dol_syslog("AntiVir::dol_avscan_file Result return_var=".$return_var." output=".join(',',$output)); |
|
129 | + dol_syslog("AntiVir::dol_avscan_file Result return_var=".$return_var." output=".join(',', $output)); |
|
130 | 130 | |
131 | - $returncodevirus=1; |
|
131 | + $returncodevirus = 1; |
|
132 | 132 | if ($return_var == $returncodevirus) // Virus found |
133 | 133 | { |
134 | - $this->errors=$output; |
|
134 | + $this->errors = $output; |
|
135 | 135 | return -99; |
136 | 136 | } |
137 | 137 | |
138 | 138 | if ($return_var > 0) // If other error |
139 | 139 | { |
140 | - $this->errors=$output; |
|
140 | + $this->errors = $output; |
|
141 | 141 | return -98; |
142 | 142 | } |
143 | 143 | |
@@ -157,28 +157,28 @@ discard block |
||
157 | 157 | { |
158 | 158 | global $conf; |
159 | 159 | |
160 | - $maxreclevel = 5 ; // maximal recursion level |
|
161 | - $maxfiles = 1000; // maximal number of files to be scanned within archive |
|
162 | - $maxratio = 200; // maximal compression ratio |
|
163 | - $bz2archivememlim = 0; // limit memory usage for bzip2 (0/1) |
|
164 | - $maxfilesize = 10485760; // archived files larger than this value (in bytes) will not be scanned |
|
160 | + $maxreclevel = 5; // maximal recursion level |
|
161 | + $maxfiles = 1000; // maximal number of files to be scanned within archive |
|
162 | + $maxratio = 200; // maximal compression ratio |
|
163 | + $bz2archivememlim = 0; // limit memory usage for bzip2 (0/1) |
|
164 | + $maxfilesize = 10485760; // archived files larger than this value (in bytes) will not be scanned |
|
165 | 165 | |
166 | - $command=$conf->global->MAIN_ANTIVIRUS_COMMAND; |
|
167 | - $param=$conf->global->MAIN_ANTIVIRUS_PARAM; |
|
166 | + $command = $conf->global->MAIN_ANTIVIRUS_COMMAND; |
|
167 | + $param = $conf->global->MAIN_ANTIVIRUS_PARAM; |
|
168 | 168 | |
169 | - $param=preg_replace('/%maxreclevel/',$maxreclevel,$param); |
|
170 | - $param=preg_replace('/%maxfiles/',$maxfiles,$param); |
|
171 | - $param=preg_replace('/%maxratio/',$maxratio,$param); |
|
172 | - $param=preg_replace('/%bz2archivememlim/',$bz2archivememlim,$param); |
|
173 | - $param=preg_replace('/%maxfilesize/',$maxfilesize,$param); |
|
174 | - $param=preg_replace('/%file/',trim($file),$param); |
|
169 | + $param = preg_replace('/%maxreclevel/', $maxreclevel, $param); |
|
170 | + $param = preg_replace('/%maxfiles/', $maxfiles, $param); |
|
171 | + $param = preg_replace('/%maxratio/', $maxratio, $param); |
|
172 | + $param = preg_replace('/%bz2archivememlim/', $bz2archivememlim, $param); |
|
173 | + $param = preg_replace('/%maxfilesize/', $maxfilesize, $param); |
|
174 | + $param = preg_replace('/%file/', trim($file), $param); |
|
175 | 175 | |
176 | - if (! preg_match('/%file/',$conf->global->MAIN_ANTIVIRUS_PARAM)) |
|
177 | - $param=$param." ".escapeshellarg(trim($file)); |
|
176 | + if (!preg_match('/%file/', $conf->global->MAIN_ANTIVIRUS_PARAM)) |
|
177 | + $param = $param." ".escapeshellarg(trim($file)); |
|
178 | 178 | |
179 | - if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command. Using escapeshellcmd fails. |
|
179 | + if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // Use quotes on command. Using escapeshellcmd fails. |
|
180 | 180 | |
181 | - $ret=$command.' '.$param; |
|
181 | + $ret = $command.' '.$param; |
|
182 | 182 | //$ret=$command.' '.$param.' 2>&1'; |
183 | 183 | //print "xx".$ret."xx";exit; |
184 | 184 |
@@ -39,48 +39,48 @@ discard block |
||
39 | 39 | */ |
40 | 40 | class DolGraph |
41 | 41 | { |
42 | - public $type=array(); // Array with type of each series. Example: array('bars', 'lines', ...) |
|
43 | - public $mode='side'; // Mode bars graph: side, depth |
|
44 | - private $_library='jflot'; // Graphic library to use (jflot, artichow) |
|
42 | + public $type = array(); // Array with type of each series. Example: array('bars', 'lines', ...) |
|
43 | + public $mode = 'side'; // Mode bars graph: side, depth |
|
44 | + private $_library = 'jflot'; // Graphic library to use (jflot, artichow) |
|
45 | 45 | |
46 | 46 | //! Array of data |
47 | - public $data; // Data of graph: array(array('abs1',valA1,valB1), array('abs2',valA2,valB2), ...) |
|
48 | - public $title; // Title of graph |
|
49 | - public $cssprefix=''; // To add into css styles |
|
50 | - public $width=380; |
|
51 | - public $height=200; |
|
52 | - public $MaxValue=0; |
|
53 | - public $MinValue=0; |
|
54 | - public $SetShading=0; |
|
55 | - |
|
56 | - public $PrecisionY=-1; |
|
57 | - |
|
58 | - public $horizTickIncrement=-1; |
|
59 | - public $SetNumXTicks=-1; |
|
60 | - public $labelInterval=-1; |
|
61 | - |
|
62 | - public $hideXGrid=false; |
|
63 | - public $hideYGrid=false; |
|
64 | - |
|
65 | - public $Legend=array(); |
|
66 | - public $LegendWidthMin=0; |
|
67 | - public $showlegend=1; |
|
68 | - public $showpointvalue=1; |
|
69 | - public $showpercent=0; |
|
70 | - public $combine=0; // 0.05 if you want to combine records < 5% into "other" |
|
71 | - public $graph; // Objet Graph (Artichow, Phplot...) |
|
47 | + public $data; // Data of graph: array(array('abs1',valA1,valB1), array('abs2',valA2,valB2), ...) |
|
48 | + public $title; // Title of graph |
|
49 | + public $cssprefix = ''; // To add into css styles |
|
50 | + public $width = 380; |
|
51 | + public $height = 200; |
|
52 | + public $MaxValue = 0; |
|
53 | + public $MinValue = 0; |
|
54 | + public $SetShading = 0; |
|
55 | + |
|
56 | + public $PrecisionY = -1; |
|
57 | + |
|
58 | + public $horizTickIncrement = -1; |
|
59 | + public $SetNumXTicks = -1; |
|
60 | + public $labelInterval = -1; |
|
61 | + |
|
62 | + public $hideXGrid = false; |
|
63 | + public $hideYGrid = false; |
|
64 | + |
|
65 | + public $Legend = array(); |
|
66 | + public $LegendWidthMin = 0; |
|
67 | + public $showlegend = 1; |
|
68 | + public $showpointvalue = 1; |
|
69 | + public $showpercent = 0; |
|
70 | + public $combine = 0; // 0.05 if you want to combine records < 5% into "other" |
|
71 | + public $graph; // Objet Graph (Artichow, Phplot...) |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @var string Error code (or message) |
75 | 75 | */ |
76 | - public $error=''; |
|
76 | + public $error = ''; |
|
77 | 77 | |
78 | - public $bordercolor; // array(R,G,B) |
|
79 | - public $bgcolor; // array(R,G,B) |
|
80 | - public $bgcolorgrid=array(255,255,255); // array(R,G,B) |
|
81 | - public $datacolor; // array(array(R,G,B),...) |
|
78 | + public $bordercolor; // array(R,G,B) |
|
79 | + public $bgcolor; // array(R,G,B) |
|
80 | + public $bgcolorgrid = array(255, 255, 255); // array(R,G,B) |
|
81 | + public $datacolor; // array(array(R,G,B),...) |
|
82 | 82 | |
83 | - private $stringtoshow; // To store string to output graph into HTML page |
|
83 | + private $stringtoshow; // To store string to output graph into HTML page |
|
84 | 84 | |
85 | 85 | |
86 | 86 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @param string $library 'jflot' (default) or 'artichow' (no more supported) |
90 | 90 | */ |
91 | - function __construct($library='jflot') |
|
91 | + function __construct($library = 'jflot') |
|
92 | 92 | { |
93 | 93 | global $conf; |
94 | 94 | global $theme_bordercolor, $theme_datacolor, $theme_bgcolor, $theme_bgcoloronglet; |
@@ -96,25 +96,25 @@ discard block |
||
96 | 96 | // To use old feature |
97 | 97 | if ($library == 'artichow') |
98 | 98 | { |
99 | - $this->_library='artichow'; |
|
99 | + $this->_library = 'artichow'; |
|
100 | 100 | |
101 | 101 | // Test if module GD present |
102 | 102 | $modules_list = get_loaded_extensions(); |
103 | - $isgdinstalled=0; |
|
103 | + $isgdinstalled = 0; |
|
104 | 104 | foreach ($modules_list as $module) |
105 | 105 | { |
106 | - if ($module == 'gd') $isgdinstalled=1; |
|
106 | + if ($module == 'gd') $isgdinstalled = 1; |
|
107 | 107 | } |
108 | - if (! $isgdinstalled) |
|
108 | + if (!$isgdinstalled) |
|
109 | 109 | { |
110 | - $this->error="Error: PHP GD module is not available. It is required to build graphics."; |
|
110 | + $this->error = "Error: PHP GD module is not available. It is required to build graphics."; |
|
111 | 111 | return -1; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | - $this->bordercolor = array(235,235,224); |
|
116 | - $this->datacolor = array(array(120,130,150), array(160,160,180), array(190,190,220)); |
|
117 | - $this->bgcolor = array(235,235,224); |
|
115 | + $this->bordercolor = array(235, 235, 224); |
|
116 | + $this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220)); |
|
117 | + $this->bgcolor = array(235, 235, 224); |
|
118 | 118 | |
119 | 119 | $color_file = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/graph-color.php'; |
120 | 120 | if (is_readable($color_file)) |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | */ |
449 | 449 | function setShowLegend($showlegend) |
450 | 450 | { |
451 | - $this->showlegend=$showlegend; |
|
451 | + $this->showlegend = $showlegend; |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | */ |
460 | 460 | function setShowPointValue($showpointvalue) |
461 | 461 | { |
462 | - $this->showpointvalue=$showpointvalue; |
|
462 | + $this->showpointvalue = $showpointvalue; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | */ |
471 | 471 | function setShowPercent($showpercent) |
472 | 472 | { |
473 | - $this->showpercent=$showpercent; |
|
473 | + $this->showpercent = $showpercent; |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | |
@@ -482,12 +482,12 @@ discard block |
||
482 | 482 | * @param array $bg_color array(R,G,B) ou 'onglet' ou 'default' |
483 | 483 | * @return void |
484 | 484 | */ |
485 | - function SetBgColor($bg_color = array(255,255,255)) |
|
485 | + function SetBgColor($bg_color = array(255, 255, 255)) |
|
486 | 486 | { |
487 | 487 | // phpcs:enable |
488 | - global $theme_bgcolor,$theme_bgcoloronglet; |
|
488 | + global $theme_bgcolor, $theme_bgcoloronglet; |
|
489 | 489 | |
490 | - if (! is_array($bg_color)) |
|
490 | + if (!is_array($bg_color)) |
|
491 | 491 | { |
492 | 492 | if ($bg_color == 'onglet') |
493 | 493 | { |
@@ -512,12 +512,12 @@ discard block |
||
512 | 512 | * @param array $bg_colorgrid array(R,G,B) ou 'onglet' ou 'default' |
513 | 513 | * @return void |
514 | 514 | */ |
515 | - function SetBgColorGrid($bg_colorgrid = array(255,255,255)) |
|
515 | + function SetBgColorGrid($bg_colorgrid = array(255, 255, 255)) |
|
516 | 516 | { |
517 | 517 | // phpcs:enable |
518 | - global $theme_bgcolor,$theme_bgcoloronglet; |
|
518 | + global $theme_bgcolor, $theme_bgcoloronglet; |
|
519 | 519 | |
520 | - if (! is_array($bg_colorgrid)) |
|
520 | + if (!is_array($bg_colorgrid)) |
|
521 | 521 | { |
522 | 522 | if ($bg_colorgrid == 'onglet') |
523 | 523 | { |
@@ -562,11 +562,11 @@ discard block |
||
562 | 562 | $nblines = count($this->data); |
563 | 563 | $nbvalues = count($this->data[0]) - 1; |
564 | 564 | |
565 | - for ($j = 0 ; $j < $nblines ; $j++) |
|
565 | + for ($j = 0; $j < $nblines; $j++) |
|
566 | 566 | { |
567 | - for ($i = 0 ; $i < $nbvalues ; $i++) |
|
567 | + for ($i = 0; $i < $nbvalues; $i++) |
|
568 | 568 | { |
569 | - $vals[$k] = $this->data[$j][$i+1]; |
|
569 | + $vals[$k] = $this->data[$j][$i + 1]; |
|
570 | 570 | $k++; |
571 | 571 | } |
572 | 572 | } |
@@ -589,11 +589,11 @@ discard block |
||
589 | 589 | $nblines = count($this->data); |
590 | 590 | $nbvalues = count($this->data[0]) - 1; |
591 | 591 | |
592 | - for ($j = 0 ; $j < $nblines ; $j++) |
|
592 | + for ($j = 0; $j < $nblines; $j++) |
|
593 | 593 | { |
594 | - for ($i = 0 ; $i < $nbvalues ; $i++) |
|
594 | + for ($i = 0; $i < $nbvalues; $i++) |
|
595 | 595 | { |
596 | - $vals[$k] = $this->data[$j][$i+1]; |
|
596 | + $vals[$k] = $this->data[$j][$i + 1]; |
|
597 | 597 | $k++; |
598 | 598 | } |
599 | 599 | } |
@@ -612,15 +612,15 @@ discard block |
||
612 | 612 | // phpcs:enable |
613 | 613 | $max = $this->GetMaxValueInData(); |
614 | 614 | if ($max != 0) $max++; |
615 | - $size=dol_strlen(abs(ceil($max))); |
|
616 | - $factor=1; |
|
617 | - for ($i=0; $i < ($size-1); $i++) |
|
615 | + $size = dol_strlen(abs(ceil($max))); |
|
616 | + $factor = 1; |
|
617 | + for ($i = 0; $i < ($size - 1); $i++) |
|
618 | 618 | { |
619 | - $factor*=10; |
|
619 | + $factor *= 10; |
|
620 | 620 | } |
621 | 621 | |
622 | - $res=0; |
|
623 | - if (is_numeric($max)) $res=ceil($max/$factor)*$factor; |
|
622 | + $res = 0; |
|
623 | + if (is_numeric($max)) $res = ceil($max / $factor) * $factor; |
|
624 | 624 | |
625 | 625 | //print "max=".$max." res=".$res; |
626 | 626 | return $res; |
@@ -636,16 +636,16 @@ discard block |
||
636 | 636 | { |
637 | 637 | // phpcs:enable |
638 | 638 | $min = $this->GetMinValueInData(); |
639 | - if ($min == '') $min=0; |
|
639 | + if ($min == '') $min = 0; |
|
640 | 640 | if ($min != 0) $min--; |
641 | - $size=dol_strlen(abs(floor($min))); |
|
642 | - $factor=1; |
|
643 | - for ($i=0; $i < ($size-1); $i++) |
|
641 | + $size = dol_strlen(abs(floor($min))); |
|
642 | + $factor = 1; |
|
643 | + for ($i = 0; $i < ($size - 1); $i++) |
|
644 | 644 | { |
645 | - $factor*=10; |
|
645 | + $factor *= 10; |
|
646 | 646 | } |
647 | 647 | |
648 | - $res=floor($min/$factor)*$factor; |
|
648 | + $res = floor($min / $factor) * $factor; |
|
649 | 649 | |
650 | 650 | //print "min=".$min." res=".$res; |
651 | 651 | return $res; |
@@ -658,27 +658,27 @@ discard block |
||
658 | 658 | * @param string $fileurl Url path to show image if saved onto disk |
659 | 659 | * @return integer|null |
660 | 660 | */ |
661 | - function draw($file, $fileurl='') |
|
661 | + function draw($file, $fileurl = '') |
|
662 | 662 | { |
663 | 663 | if (empty($file)) |
664 | 664 | { |
665 | - $this->error="Call to draw method was made with empty value for parameter file."; |
|
665 | + $this->error = "Call to draw method was made with empty value for parameter file."; |
|
666 | 666 | dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR); |
667 | 667 | return -2; |
668 | 668 | } |
669 | - if (! is_array($this->data)) |
|
669 | + if (!is_array($this->data)) |
|
670 | 670 | { |
671 | - $this->error="Call to draw method was made but SetData was not called or called with an empty dataset for parameters"; |
|
671 | + $this->error = "Call to draw method was made but SetData was not called or called with an empty dataset for parameters"; |
|
672 | 672 | dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR); |
673 | 673 | return -1; |
674 | 674 | } |
675 | 675 | if (count($this->data) < 1) |
676 | 676 | { |
677 | - $this->error="Call to draw method was made but SetData was is an empty dataset"; |
|
677 | + $this->error = "Call to draw method was made but SetData was is an empty dataset"; |
|
678 | 678 | dol_syslog(get_class($this)."::draw ".$this->error, LOG_WARNING); |
679 | 679 | } |
680 | 680 | $call = "draw_".$this->_library; |
681 | - call_user_func_array(array($this,$call), array($file,$fileurl)); |
|
681 | + call_user_func_array(array($this, $call), array($file, $fileurl)); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | |
@@ -690,31 +690,31 @@ discard block |
||
690 | 690 | * @param string $fileurl Url path to show image if saved onto disk |
691 | 691 | * @return void |
692 | 692 | */ |
693 | - private function draw_artichow($file,$fileurl) |
|
693 | + private function draw_artichow($file, $fileurl) |
|
694 | 694 | { |
695 | 695 | // phpcs:enable |
696 | 696 | global $artichow_defaultfont; |
697 | 697 | |
698 | - dol_syslog(get_class($this)."::draw_artichow this->type=".join(',',$this->type)); |
|
698 | + dol_syslog(get_class($this)."::draw_artichow this->type=".join(',', $this->type)); |
|
699 | 699 | |
700 | - if (! defined('SHADOW_RIGHT_TOP')) define('SHADOW_RIGHT_TOP',3); |
|
701 | - if (! defined('LEGEND_BACKGROUND')) define('LEGEND_BACKGROUND',2); |
|
702 | - if (! defined('LEGEND_LINE')) define('LEGEND_LINE',1); |
|
700 | + if (!defined('SHADOW_RIGHT_TOP')) define('SHADOW_RIGHT_TOP', 3); |
|
701 | + if (!defined('LEGEND_BACKGROUND')) define('LEGEND_BACKGROUND', 2); |
|
702 | + if (!defined('LEGEND_LINE')) define('LEGEND_LINE', 1); |
|
703 | 703 | |
704 | 704 | // Create graph |
705 | - $classname=''; |
|
706 | - if (! isset($this->type[0]) || $this->type[0] == 'bars') $classname='BarPlot'; // Only one type (first one) is supported by artichow |
|
707 | - else if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') $classname='LinePlot'; |
|
708 | - else $classname='TypeUnknown'; |
|
705 | + $classname = ''; |
|
706 | + if (!isset($this->type[0]) || $this->type[0] == 'bars') $classname = 'BarPlot'; // Only one type (first one) is supported by artichow |
|
707 | + else if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') $classname = 'LinePlot'; |
|
708 | + else $classname = 'TypeUnknown'; |
|
709 | 709 | include_once ARTICHOW_PATH.$classname.'.class.php'; |
710 | 710 | |
711 | 711 | // Definition de couleurs |
712 | - $bgcolor=new Color($this->bgcolor[0],$this->bgcolor[1],$this->bgcolor[2]); |
|
713 | - $bgcolorgrid=new Color($this->bgcolorgrid[0],$this->bgcolorgrid[1],$this->bgcolorgrid[2]); |
|
714 | - $colortrans=new Color(0,0,0,100); |
|
715 | - $colorsemitrans=new Color(255,255,255,60); |
|
716 | - $colorgradient= new LinearGradient(new Color(235, 235, 235),new Color(255, 255, 255),0); |
|
717 | - $colorwhite=new Color(255,255,255); |
|
712 | + $bgcolor = new Color($this->bgcolor[0], $this->bgcolor[1], $this->bgcolor[2]); |
|
713 | + $bgcolorgrid = new Color($this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]); |
|
714 | + $colortrans = new Color(0, 0, 0, 100); |
|
715 | + $colorsemitrans = new Color(255, 255, 255, 60); |
|
716 | + $colorgradient = new LinearGradient(new Color(235, 235, 235), new Color(255, 255, 255), 0); |
|
717 | + $colorwhite = new Color(255, 255, 255); |
|
718 | 718 | |
719 | 719 | // Graph |
720 | 720 | $graph = new Graph($this->width, $this->height); |
@@ -733,13 +733,13 @@ discard block |
||
733 | 733 | $group = new PlotGroup; |
734 | 734 | //$group->setSpace(5, 5, 0, 0); |
735 | 735 | |
736 | - $paddleft=50; |
|
737 | - $paddright=10; |
|
738 | - $strl=dol_strlen(max(abs($this->MaxValue),abs($this->MinValue))); |
|
736 | + $paddleft = 50; |
|
737 | + $paddright = 10; |
|
738 | + $strl = dol_strlen(max(abs($this->MaxValue), abs($this->MinValue))); |
|
739 | 739 | if ($strl > 6) $paddleft += ($strl * 4); |
740 | - $group->setPadding($paddleft, $paddright); // Width on left and right for Y axis values |
|
740 | + $group->setPadding($paddleft, $paddright); // Width on left and right for Y axis values |
|
741 | 741 | $group->legend->setSpace(0); |
742 | - $group->legend->setPadding(2,2,2,2); |
|
742 | + $group->legend->setPadding(2, 2, 2, 2); |
|
743 | 743 | $group->legend->setPosition(null, 0.1); |
744 | 744 | $group->legend->setBackgroundColor($colorsemitrans); |
745 | 745 | |
@@ -750,26 +750,26 @@ discard block |
||
750 | 750 | if ($this->hideYGrid) $group->grid->hideHorizontal(true); |
751 | 751 | |
752 | 752 | // On boucle sur chaque lot de donnees |
753 | - $legends=array(); |
|
754 | - $i=0; |
|
755 | - $nblot=count($this->data[0])-1; |
|
753 | + $legends = array(); |
|
754 | + $i = 0; |
|
755 | + $nblot = count($this->data[0]) - 1; |
|
756 | 756 | |
757 | 757 | while ($i < $nblot) |
758 | 758 | { |
759 | - $x=0; |
|
760 | - $values=array(); |
|
761 | - foreach($this->data as $key => $valarray) |
|
759 | + $x = 0; |
|
760 | + $values = array(); |
|
761 | + foreach ($this->data as $key => $valarray) |
|
762 | 762 | { |
763 | 763 | $legends[$x] = $valarray[0]; |
764 | - $values[$x] = $valarray[$i+1]; |
|
764 | + $values[$x] = $valarray[$i + 1]; |
|
765 | 765 | $x++; |
766 | 766 | } |
767 | 767 | |
768 | 768 | // We fix unknown values to null |
769 | - $newvalues=array(); |
|
770 | - foreach($values as $val) |
|
769 | + $newvalues = array(); |
|
770 | + foreach ($values as $val) |
|
771 | 771 | { |
772 | - $newvalues[]=(is_numeric($val) ? $val : null); |
|
772 | + $newvalues[] = (is_numeric($val) ? $val : null); |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | |
@@ -779,14 +779,14 @@ discard block |
||
779 | 779 | //print_r($values); |
780 | 780 | //print '<br>'; |
781 | 781 | |
782 | - $color=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2],20); |
|
783 | - $colorbis=new Color(min($this->datacolor[$i][0]+50,255),min($this->datacolor[$i][1]+50,255),min($this->datacolor[$i][2]+50,255),50); |
|
782 | + $color = new Color($this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2], 20); |
|
783 | + $colorbis = new Color(min($this->datacolor[$i][0] + 50, 255), min($this->datacolor[$i][1] + 50, 255), min($this->datacolor[$i][2] + 50, 255), 50); |
|
784 | 784 | |
785 | - $colorgrey=new Color(100,100,100); |
|
786 | - $colorborder=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2]); |
|
785 | + $colorgrey = new Color(100, 100, 100); |
|
786 | + $colorborder = new Color($this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]); |
|
787 | 787 | |
788 | - if ($this->mode == 'side') $plot = new BarPlot($newvalues, $i+1, $nblot); |
|
789 | - if ($this->mode == 'depth') $plot = new BarPlot($newvalues, 1, 1, ($nblot-$i-1)*5); |
|
788 | + if ($this->mode == 'side') $plot = new BarPlot($newvalues, $i + 1, $nblot); |
|
789 | + if ($this->mode == 'depth') $plot = new BarPlot($newvalues, 1, 1, ($nblot - $i - 1) * 5); |
|
790 | 790 | |
791 | 791 | $plot->barBorder->setColor($colorgrey); |
792 | 792 | //$plot->setBarColor($color); |
@@ -811,9 +811,9 @@ discard block |
||
811 | 811 | |
812 | 812 | if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') |
813 | 813 | { |
814 | - $color=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2],20); |
|
815 | - $colorbis=new Color(min($this->datacolor[$i][0]+20,255),min($this->datacolor[$i][1]+20,255),min($this->datacolor[$i][2]+20,255),60); |
|
816 | - $colorter=new Color(min($this->datacolor[$i][0]+50,255),min($this->datacolor[$i][1]+50,255),min($this->datacolor[$i][2]+50,255),90); |
|
814 | + $color = new Color($this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2], 20); |
|
815 | + $colorbis = new Color(min($this->datacolor[$i][0] + 20, 255), min($this->datacolor[$i][1] + 20, 255), min($this->datacolor[$i][2] + 20, 255), 60); |
|
816 | + $colorter = new Color(min($this->datacolor[$i][0] + 50, 255), min($this->datacolor[$i][1] + 50, 255), min($this->datacolor[$i][2] + 50, 255), 90); |
|
817 | 817 | |
818 | 818 | $plot = new LinePlot($newvalues); |
819 | 819 | //$plot->setSize(1, 0.96); |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | // Generate file |
860 | 860 | $graph->draw($file); |
861 | 861 | |
862 | - $this->stringtoshow='<!-- Build using '.$this->_library.' --><img src="'.$fileurl.'" title="'.dol_escape_htmltag($this->title?$this->title:$this->YLabel).'" alt="'.dol_escape_htmltag($this->title?$this->title:$this->YLabel).'">'; |
|
862 | + $this->stringtoshow = '<!-- Build using '.$this->_library.' --><img src="'.$fileurl.'" title="'.dol_escape_htmltag($this->title ? $this->title : $this->YLabel).'" alt="'.dol_escape_htmltag($this->title ? $this->title : $this->YLabel).'">'; |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | // phpcs:enable |
886 | 886 | global $artichow_defaultfont; |
887 | 887 | |
888 | - dol_syslog(get_class($this)."::draw_jflot this->type=".join(',',$this->type)." this->MaxValue=".$this->MaxValue); |
|
888 | + dol_syslog(get_class($this)."::draw_jflot this->type=".join(',', $this->type)." this->MaxValue=".$this->MaxValue); |
|
889 | 889 | |
890 | 890 | if (empty($this->width) && empty($this->height)) |
891 | 891 | { |
@@ -893,87 +893,87 @@ discard block |
||
893 | 893 | return; |
894 | 894 | } |
895 | 895 | |
896 | - $legends=array(); |
|
897 | - $nblot=count($this->data[0])-1; // -1 to remove legend |
|
896 | + $legends = array(); |
|
897 | + $nblot = count($this->data[0]) - 1; // -1 to remove legend |
|
898 | 898 | if ($nblot < 0) dol_syslog('Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING); |
899 | - $firstlot=0; |
|
899 | + $firstlot = 0; |
|
900 | 900 | // Works with line but not with bars |
901 | 901 | //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x |
902 | 902 | |
903 | - $i=$firstlot; |
|
904 | - $serie=array(); |
|
903 | + $i = $firstlot; |
|
904 | + $serie = array(); |
|
905 | 905 | while ($i < $nblot) // Loop on each serie |
906 | 906 | { |
907 | - $values=array(); // Array with horizontal y values (specific values of a serie) for each abscisse x |
|
908 | - $serie[$i]="var d".$i." = [];\n"; |
|
907 | + $values = array(); // Array with horizontal y values (specific values of a serie) for each abscisse x |
|
908 | + $serie[$i] = "var d".$i." = [];\n"; |
|
909 | 909 | |
910 | 910 | // Fill array $values |
911 | - $x=0; |
|
912 | - foreach($this->data as $valarray) // Loop on each x |
|
911 | + $x = 0; |
|
912 | + foreach ($this->data as $valarray) // Loop on each x |
|
913 | 913 | { |
914 | 914 | $legends[$x] = $valarray[0]; |
915 | - $values[$x] = (is_numeric($valarray[$i+1]) ? $valarray[$i+1] : null); |
|
915 | + $values[$x] = (is_numeric($valarray[$i + 1]) ? $valarray[$i + 1] : null); |
|
916 | 916 | $x++; |
917 | 917 | } |
918 | 918 | |
919 | 919 | // TODO Avoid push by adding generated long array... |
920 | 920 | if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') |
921 | 921 | { |
922 | - foreach($values as $x => $y) { |
|
923 | - if (isset($y)) $serie[$i].='d'.$i.'.push({"label":"'.dol_escape_js($legends[$x]).'", "data":'.$y.'});'."\n"; |
|
922 | + foreach ($values as $x => $y) { |
|
923 | + if (isset($y)) $serie[$i] .= 'd'.$i.'.push({"label":"'.dol_escape_js($legends[$x]).'", "data":'.$y.'});'."\n"; |
|
924 | 924 | } |
925 | 925 | } |
926 | 926 | else |
927 | 927 | { |
928 | - foreach($values as $x => $y) { |
|
929 | - if (isset($y)) $serie[$i].='d'.$i.'.push(['.$x.', '.$y.']);'."\n"; |
|
928 | + foreach ($values as $x => $y) { |
|
929 | + if (isset($y)) $serie[$i] .= 'd'.$i.'.push(['.$x.', '.$y.']);'."\n"; |
|
930 | 930 | } |
931 | 931 | } |
932 | 932 | |
933 | 933 | unset($values); |
934 | 934 | $i++; |
935 | 935 | } |
936 | - $tag=dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file),'_',array('-','.')))); |
|
936 | + $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); |
|
937 | 937 | |
938 | - $this->stringtoshow ='<!-- Build using '.$this->_library.' -->'."\n"; |
|
939 | - if (! empty($this->title)) $this->stringtoshow.='<div align="center" class="dolgraphtitle'.(empty($this->cssprefix)?'':' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>'; |
|
940 | - if (! empty($this->shownographyet)) |
|
938 | + $this->stringtoshow = '<!-- Build using '.$this->_library.' -->'."\n"; |
|
939 | + if (!empty($this->title)) $this->stringtoshow .= '<div align="center" class="dolgraphtitle'.(empty($this->cssprefix) ? '' : ' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>'; |
|
940 | + if (!empty($this->shownographyet)) |
|
941 | 941 | { |
942 | - $this->stringtoshow.='<div style="width:'.$this->width.'px;height:'.$this->height.'px;" class="nographyet"></div>'; |
|
943 | - $this->stringtoshow.='<div class="nographyettext">'.$langs->trans("NotEnoughDataYet").'</div>'; |
|
942 | + $this->stringtoshow .= '<div style="width:'.$this->width.'px;height:'.$this->height.'px;" class="nographyet"></div>'; |
|
943 | + $this->stringtoshow .= '<div class="nographyettext">'.$langs->trans("NotEnoughDataYet").'</div>'; |
|
944 | 944 | return; |
945 | 945 | } |
946 | - $this->stringtoshow.='<div id="placeholder_'.$tag.'" style="width:'.$this->width.'px;height:'.$this->height.'px;" class="dolgraph'.(empty($this->cssprefix)?'':' dolgraph'.$this->cssprefix).'"></div>'."\n"; |
|
946 | + $this->stringtoshow .= '<div id="placeholder_'.$tag.'" style="width:'.$this->width.'px;height:'.$this->height.'px;" class="dolgraph'.(empty($this->cssprefix) ? '' : ' dolgraph'.$this->cssprefix).'"></div>'."\n"; |
|
947 | 947 | |
948 | - $this->stringtoshow.='<script id="'.$tag.'">'."\n"; |
|
949 | - $this->stringtoshow.='$(function () {'."\n"; |
|
950 | - $i=$firstlot; |
|
948 | + $this->stringtoshow .= '<script id="'.$tag.'">'."\n"; |
|
949 | + $this->stringtoshow .= '$(function () {'."\n"; |
|
950 | + $i = $firstlot; |
|
951 | 951 | if ($nblot < 0) |
952 | 952 | { |
953 | - $this->stringtoshow.='<!-- No series of data -->'; |
|
953 | + $this->stringtoshow .= '<!-- No series of data -->'; |
|
954 | 954 | } |
955 | 955 | else |
956 | 956 | { |
957 | 957 | while ($i < $nblot) |
958 | 958 | { |
959 | - $this->stringtoshow.=$serie[$i]; |
|
959 | + $this->stringtoshow .= $serie[$i]; |
|
960 | 960 | $i++; |
961 | 961 | } |
962 | 962 | } |
963 | - $this->stringtoshow.="\n"; |
|
963 | + $this->stringtoshow .= "\n"; |
|
964 | 964 | |
965 | 965 | // Special case for Graph of type 'pie' |
966 | 966 | if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') |
967 | 967 | { |
968 | - $datacolor=array(); |
|
969 | - foreach($this->datacolor as $val) $datacolor[]="#".sprintf("%02x%02x%02x",$val[0],$val[1],$val[2]); |
|
968 | + $datacolor = array(); |
|
969 | + foreach ($this->datacolor as $val) $datacolor[] = "#".sprintf("%02x%02x%02x", $val[0], $val[1], $val[2]); |
|
970 | 970 | |
971 | - $urltemp=''; // TODO Add support for url link into labels |
|
972 | - $showlegend=$this->showlegend; |
|
973 | - $showpointvalue=$this->showpointvalue; |
|
974 | - $showpercent=$this->showpercent; |
|
971 | + $urltemp = ''; // TODO Add support for url link into labels |
|
972 | + $showlegend = $this->showlegend; |
|
973 | + $showpointvalue = $this->showpointvalue; |
|
974 | + $showpercent = $this->showpercent; |
|
975 | 975 | |
976 | - $this->stringtoshow.= ' |
|
976 | + $this->stringtoshow .= ' |
|
977 | 977 | function plotWithOptions_'.$tag.'() { |
978 | 978 | $.plot($("#placeholder_'.$tag.'"), d0, |
979 | 979 | { |
@@ -984,7 +984,7 @@ discard block |
||
984 | 984 | '.($this->combine ? ' |
985 | 985 | combine: { |
986 | 986 | threshold: '.$this->combine.' |
987 | - },' : '') . ' |
|
987 | + },' : '').' |
|
988 | 988 | label: { |
989 | 989 | show: true, |
990 | 990 | radius: 0.9, |
@@ -992,15 +992,15 @@ discard block |
||
992 | 992 | var percent=Math.round(series.percent); |
993 | 993 | var number=series.data[0][1]; |
994 | 994 | return \''; |
995 | - $this->stringtoshow.='<span style="font-size:8pt;text-align:center;padding:2px;color:black;">'; |
|
996 | - if ($urltemp) $this->stringtoshow.='<a style="color: #FFFFFF;" border="0" href="'.$urltemp.'">'; |
|
997 | - $this->stringtoshow.='\'+'; |
|
998 | - $this->stringtoshow.=($showlegend?'':'label+\' \'+'); // Hide label if already shown in legend |
|
999 | - $this->stringtoshow.=($showpointvalue?'number+':''); |
|
1000 | - $this->stringtoshow.=($showpercent?'\'<br/>\'+percent+\'%\'+':''); |
|
1001 | - $this->stringtoshow.='\''; |
|
1002 | - if ($urltemp) $this->stringtoshow.='</a>'; |
|
1003 | - $this->stringtoshow.='</span>\'; |
|
995 | + $this->stringtoshow .= '<span style="font-size:8pt;text-align:center;padding:2px;color:black;">'; |
|
996 | + if ($urltemp) $this->stringtoshow .= '<a style="color: #FFFFFF;" border="0" href="'.$urltemp.'">'; |
|
997 | + $this->stringtoshow .= '\'+'; |
|
998 | + $this->stringtoshow .= ($showlegend ? '' : 'label+\' \'+'); // Hide label if already shown in legend |
|
999 | + $this->stringtoshow .= ($showpointvalue ? 'number+' : ''); |
|
1000 | + $this->stringtoshow .= ($showpercent ? '\'<br/>\'+percent+\'%\'+' : ''); |
|
1001 | + $this->stringtoshow .= '\''; |
|
1002 | + if ($urltemp) $this->stringtoshow .= '</a>'; |
|
1003 | + $this->stringtoshow .= '</span>\'; |
|
1004 | 1004 | }, |
1005 | 1005 | background: { |
1006 | 1006 | opacity: 0.0, |
@@ -1017,9 +1017,9 @@ discard block |
||
1017 | 1017 | },'; |
1018 | 1018 | if (count($datacolor)) |
1019 | 1019 | { |
1020 | - $this->stringtoshow.='colors: '.(! empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)).','; |
|
1020 | + $this->stringtoshow .= 'colors: '.(!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)).','; |
|
1021 | 1021 | } |
1022 | - $this->stringtoshow.='legend: {show: '.($showlegend?'true':'false').', position: \'ne\' } |
|
1022 | + $this->stringtoshow .= 'legend: {show: '.($showlegend ? 'true' : 'false').', position: \'ne\' } |
|
1023 | 1023 | }); |
1024 | 1024 | }'."\n"; |
1025 | 1025 | } |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | { |
1029 | 1029 | // Add code to support tooltips |
1030 | 1030 | // TODO: remove js css and use graph-tooltip-inner class instead by adding css in each themes |
1031 | - $this->stringtoshow.=' |
|
1031 | + $this->stringtoshow .= ' |
|
1032 | 1032 | function showTooltip_'.$tag.'(x, y, contents) { |
1033 | 1033 | $(\'<div class="graph-tooltip-inner" id="tooltip_'.$tag.'">\' + contents + \'</div>\').css({ |
1034 | 1034 | position: \'absolute\', |
@@ -1060,10 +1060,10 @@ discard block |
||
1060 | 1060 | var y = item.datapoint[1].toFixed(2); |
1061 | 1061 | var z = item.series.xaxis.ticks[item.dataIndex].label; |
1062 | 1062 | '; |
1063 | - if ($this->showpointvalue > 0) $this->stringtoshow.=' |
|
1063 | + if ($this->showpointvalue > 0) $this->stringtoshow .= ' |
|
1064 | 1064 | showTooltip_'.$tag.'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y); |
1065 | 1065 | '; |
1066 | - $this->stringtoshow.=' |
|
1066 | + $this->stringtoshow .= ' |
|
1067 | 1067 | } |
1068 | 1068 | } |
1069 | 1069 | else { |
@@ -1073,50 +1073,50 @@ discard block |
||
1073 | 1073 | }); |
1074 | 1074 | '; |
1075 | 1075 | |
1076 | - $this->stringtoshow.='var stack = null, steps = false;'."\n"; |
|
1076 | + $this->stringtoshow .= 'var stack = null, steps = false;'."\n"; |
|
1077 | 1077 | |
1078 | - $this->stringtoshow.='function plotWithOptions_'.$tag.'() {'."\n"; |
|
1079 | - $this->stringtoshow.='$.plot($("#placeholder_'.$tag.'"), [ '."\n"; |
|
1080 | - $i=$firstlot; |
|
1078 | + $this->stringtoshow .= 'function plotWithOptions_'.$tag.'() {'."\n"; |
|
1079 | + $this->stringtoshow .= '$.plot($("#placeholder_'.$tag.'"), [ '."\n"; |
|
1080 | + $i = $firstlot; |
|
1081 | 1081 | while ($i < $nblot) |
1082 | 1082 | { |
1083 | - if ($i > $firstlot) $this->stringtoshow.=', '."\n"; |
|
1084 | - $color=sprintf("%02x%02x%02x",$this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2]); |
|
1085 | - $this->stringtoshow.='{ '; |
|
1086 | - if (! isset($this->type[$i]) || $this->type[$i] == 'bars') $this->stringtoshow.='bars: { lineWidth: 1, show: true, align: "'.($i==$firstlot?'center':'left').'", barWidth: 0.5 }, '; |
|
1087 | - if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) $this->stringtoshow.='lines: { show: true, fill: false }, points: { show: '.($this->type[$i] == 'linesnopoint' ? 'false' : 'true').' }, '; |
|
1088 | - $this->stringtoshow.='color: "#'.$color.'", label: "'.(isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '').'", data: d'.$i.' }'; |
|
1083 | + if ($i > $firstlot) $this->stringtoshow .= ', '."\n"; |
|
1084 | + $color = sprintf("%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]); |
|
1085 | + $this->stringtoshow .= '{ '; |
|
1086 | + if (!isset($this->type[$i]) || $this->type[$i] == 'bars') $this->stringtoshow .= 'bars: { lineWidth: 1, show: true, align: "'.($i == $firstlot ? 'center' : 'left').'", barWidth: 0.5 }, '; |
|
1087 | + if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) $this->stringtoshow .= 'lines: { show: true, fill: false }, points: { show: '.($this->type[$i] == 'linesnopoint' ? 'false' : 'true').' }, '; |
|
1088 | + $this->stringtoshow .= 'color: "#'.$color.'", label: "'.(isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '').'", data: d'.$i.' }'; |
|
1089 | 1089 | $i++; |
1090 | 1090 | } |
1091 | 1091 | // shadowSize: 0 -> Drawing is faster without shadows |
1092 | - $this->stringtoshow.="\n".' ], { series: { shadowSize: 0, stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6 } }'."\n"; |
|
1092 | + $this->stringtoshow .= "\n".' ], { series: { shadowSize: 0, stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6 } }'."\n"; |
|
1093 | 1093 | |
1094 | 1094 | // Xaxis |
1095 | - $this->stringtoshow.=', xaxis: { ticks: ['."\n"; |
|
1096 | - $x=0; |
|
1097 | - foreach($this->data as $key => $valarray) |
|
1095 | + $this->stringtoshow .= ', xaxis: { ticks: ['."\n"; |
|
1096 | + $x = 0; |
|
1097 | + foreach ($this->data as $key => $valarray) |
|
1098 | 1098 | { |
1099 | - if ($x > 0) $this->stringtoshow.=', '."\n"; |
|
1100 | - $this->stringtoshow.= ' ['.$x.', "'.$valarray[0].'"]'; |
|
1099 | + if ($x > 0) $this->stringtoshow .= ', '."\n"; |
|
1100 | + $this->stringtoshow .= ' ['.$x.', "'.$valarray[0].'"]'; |
|
1101 | 1101 | $x++; |
1102 | 1102 | } |
1103 | - $this->stringtoshow.='] }'."\n"; |
|
1103 | + $this->stringtoshow .= '] }'."\n"; |
|
1104 | 1104 | |
1105 | 1105 | // Yaxis |
1106 | - $this->stringtoshow.=', yaxis: { min: '.$this->MinValue.', max: '.($this->MaxValue).' }'."\n"; |
|
1106 | + $this->stringtoshow .= ', yaxis: { min: '.$this->MinValue.', max: '.($this->MaxValue).' }'."\n"; |
|
1107 | 1107 | |
1108 | 1108 | // Background color |
1109 | - $color1=sprintf("%02x%02x%02x",$this->bgcolorgrid[0],$this->bgcolorgrid[0],$this->bgcolorgrid[2]); |
|
1110 | - $color2=sprintf("%02x%02x%02x",$this->bgcolorgrid[0],$this->bgcolorgrid[1],$this->bgcolorgrid[2]); |
|
1111 | - $this->stringtoshow.=', grid: { hoverable: true, backgroundColor: { colors: ["#'.$color1.'", "#'.$color2.'"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }'."\n"; |
|
1109 | + $color1 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]); |
|
1110 | + $color2 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]); |
|
1111 | + $this->stringtoshow .= ', grid: { hoverable: true, backgroundColor: { colors: ["#'.$color1.'", "#'.$color2.'"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }'."\n"; |
|
1112 | 1112 | //$this->stringtoshow.=', shadowSize: 20'."\n"; TODO Uncommet this |
1113 | - $this->stringtoshow.='});'."\n"; |
|
1114 | - $this->stringtoshow.='}'."\n"; |
|
1113 | + $this->stringtoshow .= '});'."\n"; |
|
1114 | + $this->stringtoshow .= '}'."\n"; |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | - $this->stringtoshow.='plotWithOptions_'.$tag.'();'."\n"; |
|
1118 | - $this->stringtoshow.='});'."\n"; |
|
1119 | - $this->stringtoshow.='</script>'."\n"; |
|
1117 | + $this->stringtoshow .= 'plotWithOptions_'.$tag.'();'."\n"; |
|
1118 | + $this->stringtoshow .= '});'."\n"; |
|
1119 | + $this->stringtoshow .= '</script>'."\n"; |
|
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | |
@@ -1127,14 +1127,14 @@ discard block |
||
1127 | 1127 | * @param int $shownographyet Show graph to say there is not enough data |
1128 | 1128 | * @return string HTML string to show graph |
1129 | 1129 | */ |
1130 | - function show($shownographyet=0) |
|
1130 | + function show($shownographyet = 0) |
|
1131 | 1131 | { |
1132 | 1132 | global $langs; |
1133 | 1133 | |
1134 | 1134 | if ($shownographyet) |
1135 | 1135 | { |
1136 | - $s= '<div class="nographyet" style="width:'.(preg_match('/%/',$this->width)?$this->width:$this->width.'px').'; height:'.(preg_match('/%/',$this->height)?$this->height:$this->height.'px').';"></div>'; |
|
1137 | - $s.='<div class="nographyettext">'.$langs->trans("NotEnoughDataYet").'</div>'; |
|
1136 | + $s = '<div class="nographyet" style="width:'.(preg_match('/%/', $this->width) ? $this->width : $this->width.'px').'; height:'.(preg_match('/%/', $this->height) ? $this->height : $this->height.'px').';"></div>'; |
|
1137 | + $s .= '<div class="nographyettext">'.$langs->trans("NotEnoughDataYet").'</div>'; |
|
1138 | 1138 | return $s; |
1139 | 1139 | } |
1140 | 1140 | |
@@ -1149,18 +1149,18 @@ discard block |
||
1149 | 1149 | * @param string $defaultsize Value we want as default size |
1150 | 1150 | * @return int Value of width or height to use by default |
1151 | 1151 | */ |
1152 | - static function getDefaultGraphSizeForStats($direction,$defaultsize='') |
|
1152 | + static function getDefaultGraphSizeForStats($direction, $defaultsize = '') |
|
1153 | 1153 | { |
1154 | 1154 | global $conf; |
1155 | 1155 | |
1156 | 1156 | if ($direction == 'width') |
1157 | 1157 | { |
1158 | 1158 | if (empty($conf->dol_optimize_smallscreen)) return ($defaultsize ? $defaultsize : '500'); |
1159 | - else return (empty($_SESSION['dol_screen_width']) ? '280' : ($_SESSION['dol_screen_width']-40)); |
|
1159 | + else return (empty($_SESSION['dol_screen_width']) ? '280' : ($_SESSION['dol_screen_width'] - 40)); |
|
1160 | 1160 | } |
1161 | 1161 | if ($direction == 'height') |
1162 | 1162 | { |
1163 | - return (empty($conf->dol_optimize_smallscreen)?($defaultsize?$defaultsize:'200'):'160'); |
|
1163 | + return (empty($conf->dol_optimize_smallscreen) ? ($defaultsize ? $defaultsize : '200') : '160'); |
|
1164 | 1164 | } |
1165 | 1165 | return 0; |
1166 | 1166 | } |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | /** |
95 | 95 | * @var string Error code (or message) |
96 | 96 | */ |
97 | - public $error=''; |
|
97 | + public $error = ''; |
|
98 | 98 | |
99 | 99 | var $errno; |
100 | 100 | |
101 | 101 | |
102 | - public static $type2label=array( |
|
102 | + public static $type2label = array( |
|
103 | 103 | 'varchar'=>'String', |
104 | 104 | 'text'=>'TextLong', |
105 | 105 | 'html'=>'HtmlText', |
@@ -171,29 +171,29 @@ discard block |
||
171 | 171 | * @param string $enabled Condition to have the field enabled or not |
172 | 172 | * @return int <=0 if KO, >0 if OK |
173 | 173 | */ |
174 | - function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $computed='', $entity='', $langfile='', $enabled='1') |
|
174 | + function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique = 0, $required = 0, $default_value = '', $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $computed = '', $entity = '', $langfile = '', $enabled = '1') |
|
175 | 175 | { |
176 | 176 | if (empty($attrname)) return -1; |
177 | 177 | if (empty($label)) return -1; |
178 | 178 | |
179 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
180 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
179 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
180 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
181 | 181 | |
182 | 182 | // Create field into database except for separator type which is not stored in database |
183 | 183 | if ($type != 'separate') |
184 | 184 | { |
185 | - $result=$this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $computed, $help); |
|
185 | + $result = $this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $computed, $help); |
|
186 | 186 | } |
187 | - $err1=$this->errno; |
|
187 | + $err1 = $this->errno; |
|
188 | 188 | if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate') |
189 | 189 | { |
190 | 190 | // Add declaration of field into table |
191 | - $result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $help, $default_value, $computed, $entity, $langfile, $enabled); |
|
192 | - $err2=$this->errno; |
|
191 | + $result2 = $this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $help, $default_value, $computed, $entity, $langfile, $enabled); |
|
192 | + $err2 = $this->errno; |
|
193 | 193 | if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS')) |
194 | 194 | { |
195 | - $this->error=''; |
|
196 | - $this->errno=0; |
|
195 | + $this->error = ''; |
|
196 | + $this->errno = 0; |
|
197 | 197 | return 1; |
198 | 198 | } |
199 | 199 | else return -2; |
@@ -221,69 +221,69 @@ discard block |
||
221 | 221 | * @param string $computed Computed value |
222 | 222 | * @return int <=0 if KO, >0 if OK |
223 | 223 | */ |
224 | - private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='',$param='', $perms='', $list='0', $computed='') |
|
224 | + private function create($attrname, $type = 'varchar', $length = 255, $elementtype = 'member', $unique = 0, $required = 0, $default_value = '', $param = '', $perms = '', $list = '0', $computed = '') |
|
225 | 225 | { |
226 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
227 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
228 | - |
|
229 | - $table=$elementtype.'_extrafields'; |
|
230 | - if ($elementtype == 'categorie') $table='categories_extrafields'; |
|
231 | - |
|
232 | - if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/",$attrname) && ! is_numeric($attrname)) |
|
233 | - { |
|
234 | - if ($type=='boolean') { |
|
235 | - $typedb='int'; |
|
236 | - $lengthdb='1'; |
|
237 | - } elseif($type=='price') { |
|
238 | - $typedb='double'; |
|
239 | - $lengthdb='24,8'; |
|
240 | - } elseif($type=='phone') { |
|
241 | - $typedb='varchar'; |
|
242 | - $lengthdb='20'; |
|
243 | - } elseif($type=='mail') { |
|
244 | - $typedb='varchar'; |
|
245 | - $lengthdb='128'; |
|
246 | - } elseif($type=='url') { |
|
247 | - $typedb='varchar'; |
|
248 | - $lengthdb='255'; |
|
249 | - } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') ||($type=='checkbox') ||($type=='chkbxlst')){ |
|
250 | - $typedb='varchar'; |
|
251 | - $lengthdb='255'; |
|
252 | - } elseif ($type=='link') { |
|
253 | - $typedb='int'; |
|
254 | - $lengthdb='11'; |
|
255 | - } elseif ($type=='html') { |
|
256 | - $typedb='text'; |
|
257 | - $lengthdb=$length; |
|
258 | - } elseif($type=='password') { |
|
259 | - $typedb='varchar'; |
|
260 | - $lengthdb='128'; |
|
226 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
227 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
228 | + |
|
229 | + $table = $elementtype.'_extrafields'; |
|
230 | + if ($elementtype == 'categorie') $table = 'categories_extrafields'; |
|
231 | + |
|
232 | + if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/", $attrname) && !is_numeric($attrname)) |
|
233 | + { |
|
234 | + if ($type == 'boolean') { |
|
235 | + $typedb = 'int'; |
|
236 | + $lengthdb = '1'; |
|
237 | + } elseif ($type == 'price') { |
|
238 | + $typedb = 'double'; |
|
239 | + $lengthdb = '24,8'; |
|
240 | + } elseif ($type == 'phone') { |
|
241 | + $typedb = 'varchar'; |
|
242 | + $lengthdb = '20'; |
|
243 | + } elseif ($type == 'mail') { |
|
244 | + $typedb = 'varchar'; |
|
245 | + $lengthdb = '128'; |
|
246 | + } elseif ($type == 'url') { |
|
247 | + $typedb = 'varchar'; |
|
248 | + $lengthdb = '255'; |
|
249 | + } elseif (($type == 'select') || ($type == 'sellist') || ($type == 'radio') || ($type == 'checkbox') || ($type == 'chkbxlst')) { |
|
250 | + $typedb = 'varchar'; |
|
251 | + $lengthdb = '255'; |
|
252 | + } elseif ($type == 'link') { |
|
253 | + $typedb = 'int'; |
|
254 | + $lengthdb = '11'; |
|
255 | + } elseif ($type == 'html') { |
|
256 | + $typedb = 'text'; |
|
257 | + $lengthdb = $length; |
|
258 | + } elseif ($type == 'password') { |
|
259 | + $typedb = 'varchar'; |
|
260 | + $lengthdb = '128'; |
|
261 | 261 | } else { |
262 | - $typedb=$type; |
|
263 | - $lengthdb=$length; |
|
264 | - if ($type == 'varchar' && empty($lengthdb)) $lengthdb='255'; |
|
262 | + $typedb = $type; |
|
263 | + $lengthdb = $length; |
|
264 | + if ($type == 'varchar' && empty($lengthdb)) $lengthdb = '255'; |
|
265 | 265 | } |
266 | 266 | $field_desc = array( |
267 | 267 | 'type'=>$typedb, |
268 | 268 | 'value'=>$lengthdb, |
269 | - 'null'=>($required?'NOT NULL':'NULL'), |
|
269 | + 'null'=>($required ? 'NOT NULL' : 'NULL'), |
|
270 | 270 | 'default' => $default_value |
271 | 271 | ); |
272 | 272 | |
273 | - $result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); |
|
273 | + $result = $this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); |
|
274 | 274 | if ($result > 0) |
275 | 275 | { |
276 | 276 | if ($unique) |
277 | 277 | { |
278 | - $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; |
|
279 | - $resql=$this->db->query($sql,1,'dml'); |
|
278 | + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; |
|
279 | + $resql = $this->db->query($sql, 1, 'dml'); |
|
280 | 280 | } |
281 | 281 | return 1; |
282 | 282 | } |
283 | 283 | else |
284 | 284 | { |
285 | - $this->error=$this->db->lasterror(); |
|
286 | - $this->errno=$this->db->lasterrno(); |
|
285 | + $this->error = $this->db->lasterror(); |
|
286 | + $this->errno = $this->db->lasterrno(); |
|
287 | 287 | return -1; |
288 | 288 | } |
289 | 289 | } |
@@ -317,22 +317,22 @@ discard block |
||
317 | 317 | * @param string $enabled Condition to have the field enabled or not |
318 | 318 | * @return int <=0 if KO, >0 if OK |
319 | 319 | */ |
320 | - private function create_label($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $default='', $computed='',$entity='', $langfile='', $enabled='1') |
|
320 | + private function create_label($attrname, $label = '', $type = '', $pos = 0, $size = 0, $elementtype = 'member', $unique = 0, $required = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1') |
|
321 | 321 | { |
322 | 322 | // phpcs:enable |
323 | - global $conf,$user; |
|
323 | + global $conf, $user; |
|
324 | 324 | |
325 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
326 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
325 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
326 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
327 | 327 | |
328 | 328 | // Clean parameters |
329 | - if (empty($pos)) $pos=0; |
|
330 | - if (empty($list)) $list='0'; |
|
331 | - if (empty($required)) $required=0; |
|
332 | - if (empty($unique)) $unique=0; |
|
333 | - if (empty($alwayseditable)) $alwayseditable=0; |
|
329 | + if (empty($pos)) $pos = 0; |
|
330 | + if (empty($list)) $list = '0'; |
|
331 | + if (empty($required)) $required = 0; |
|
332 | + if (empty($unique)) $unique = 0; |
|
333 | + if (empty($alwayseditable)) $alwayseditable = 0; |
|
334 | 334 | |
335 | - if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname) && ! is_numeric($attrname)) |
|
335 | + if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname) && !is_numeric($attrname)) |
|
336 | 336 | { |
337 | 337 | if (is_array($param) && count($param) > 0) |
338 | 338 | { |
@@ -344,54 +344,54 @@ discard block |
||
344 | 344 | } |
345 | 345 | else |
346 | 346 | { |
347 | - $params=''; |
|
347 | + $params = ''; |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; |
351 | - $sql.= " name,"; |
|
352 | - $sql.= " label,"; |
|
353 | - $sql.= " type,"; |
|
354 | - $sql.= " pos,"; |
|
355 | - $sql.= " size,"; |
|
356 | - $sql.= " entity,"; |
|
357 | - $sql.= " elementtype,"; |
|
358 | - $sql.= " fieldunique,"; |
|
359 | - $sql.= " fieldrequired,"; |
|
360 | - $sql.= " param,"; |
|
361 | - $sql.= " alwayseditable,"; |
|
362 | - $sql.= " perms,"; |
|
363 | - $sql.= " langs,"; |
|
364 | - $sql.= " list,"; |
|
365 | - $sql.= " fielddefault,"; |
|
366 | - $sql.= " fieldcomputed,"; |
|
367 | - $sql.= " fk_user_author,"; |
|
368 | - $sql.= " fk_user_modif,"; |
|
369 | - $sql.= " datec,"; |
|
370 | - $sql.= " enabled,"; |
|
371 | - $sql.= " help"; |
|
372 | - $sql.= " )"; |
|
373 | - $sql.= " VALUES('".$attrname."',"; |
|
374 | - $sql.= " '".$this->db->escape($label)."',"; |
|
375 | - $sql.= " '".$this->db->escape($type)."',"; |
|
376 | - $sql.= " ".$pos.","; |
|
377 | - $sql.= " '".$this->db->escape($size)."',"; |
|
378 | - $sql.= " ".($entity===''?$conf->entity:$entity).","; |
|
379 | - $sql.= " '".$this->db->escape($elementtype)."',"; |
|
380 | - $sql.= " ".$unique.","; |
|
381 | - $sql.= " ".$required.","; |
|
382 | - $sql.= " '".$this->db->escape($params)."',"; |
|
383 | - $sql.= " ".$alwayseditable.","; |
|
384 | - $sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").","; |
|
385 | - $sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").","; |
|
386 | - $sql.= " '".$this->db->escape($list)."',"; |
|
387 | - $sql.= " ".($default?"'".$this->db->escape($default)."'":"null").","; |
|
388 | - $sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").","; |
|
389 | - $sql .= " " . (is_object($user) ? $user->id : 0). ","; |
|
390 | - $sql .= " " . (is_object($user) ? $user->id : 0). ","; |
|
391 | - $sql .= "'" . $this->db->idate(dol_now()) . "',"; |
|
392 | - $sql.= " ".($enabled?"'".$this->db->escape($enabled)."'":"1").","; |
|
393 | - $sql.= " ".($help?"'".$this->db->escape($help)."'":"null"); |
|
394 | - $sql.=')'; |
|
351 | + $sql .= " name,"; |
|
352 | + $sql .= " label,"; |
|
353 | + $sql .= " type,"; |
|
354 | + $sql .= " pos,"; |
|
355 | + $sql .= " size,"; |
|
356 | + $sql .= " entity,"; |
|
357 | + $sql .= " elementtype,"; |
|
358 | + $sql .= " fieldunique,"; |
|
359 | + $sql .= " fieldrequired,"; |
|
360 | + $sql .= " param,"; |
|
361 | + $sql .= " alwayseditable,"; |
|
362 | + $sql .= " perms,"; |
|
363 | + $sql .= " langs,"; |
|
364 | + $sql .= " list,"; |
|
365 | + $sql .= " fielddefault,"; |
|
366 | + $sql .= " fieldcomputed,"; |
|
367 | + $sql .= " fk_user_author,"; |
|
368 | + $sql .= " fk_user_modif,"; |
|
369 | + $sql .= " datec,"; |
|
370 | + $sql .= " enabled,"; |
|
371 | + $sql .= " help"; |
|
372 | + $sql .= " )"; |
|
373 | + $sql .= " VALUES('".$attrname."',"; |
|
374 | + $sql .= " '".$this->db->escape($label)."',"; |
|
375 | + $sql .= " '".$this->db->escape($type)."',"; |
|
376 | + $sql .= " ".$pos.","; |
|
377 | + $sql .= " '".$this->db->escape($size)."',"; |
|
378 | + $sql .= " ".($entity === '' ? $conf->entity : $entity).","; |
|
379 | + $sql .= " '".$this->db->escape($elementtype)."',"; |
|
380 | + $sql .= " ".$unique.","; |
|
381 | + $sql .= " ".$required.","; |
|
382 | + $sql .= " '".$this->db->escape($params)."',"; |
|
383 | + $sql .= " ".$alwayseditable.","; |
|
384 | + $sql .= " ".($perms ? "'".$this->db->escape($perms)."'" : "null").","; |
|
385 | + $sql .= " ".($langfile ? "'".$this->db->escape($langfile)."'" : "null").","; |
|
386 | + $sql .= " '".$this->db->escape($list)."',"; |
|
387 | + $sql .= " ".($default ? "'".$this->db->escape($default)."'" : "null").","; |
|
388 | + $sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").","; |
|
389 | + $sql .= " ".(is_object($user) ? $user->id : 0).","; |
|
390 | + $sql .= " ".(is_object($user) ? $user->id : 0).","; |
|
391 | + $sql .= "'".$this->db->idate(dol_now())."',"; |
|
392 | + $sql .= " ".($enabled ? "'".$this->db->escape($enabled)."'" : "1").","; |
|
393 | + $sql .= " ".($help ? "'".$this->db->escape($help)."'" : "null"); |
|
394 | + $sql .= ')'; |
|
395 | 395 | |
396 | 396 | dol_syslog(get_class($this)."::create_label", LOG_DEBUG); |
397 | 397 | if ($this->db->query($sql)) |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | } |
401 | 401 | else |
402 | 402 | { |
403 | - $this->error=$this->db->lasterror(); |
|
404 | - $this->errno=$this->db->lasterrno(); |
|
403 | + $this->error = $this->db->lasterror(); |
|
404 | + $this->errno = $this->db->lasterrno(); |
|
405 | 405 | return -1; |
406 | 406 | } |
407 | 407 | } |
@@ -414,31 +414,31 @@ discard block |
||
414 | 414 | * @param string $elementtype Element type ('member', 'product', 'thirdparty', 'contact', ...) |
415 | 415 | * @return int < 0 if KO, 0 if nothing is done, 1 if OK |
416 | 416 | */ |
417 | - function delete($attrname, $elementtype='member') |
|
417 | + function delete($attrname, $elementtype = 'member') |
|
418 | 418 | { |
419 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
420 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
419 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
420 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
421 | 421 | |
422 | - $table=$elementtype.'_extrafields'; |
|
423 | - if ($elementtype == 'categorie') $table='categories_extrafields'; |
|
422 | + $table = $elementtype.'_extrafields'; |
|
423 | + if ($elementtype == 'categorie') $table = 'categories_extrafields'; |
|
424 | 424 | |
425 | - $error=0; |
|
425 | + $error = 0; |
|
426 | 426 | |
427 | - if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
|
427 | + if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) |
|
428 | 428 | { |
429 | - $result=$this->delete_label($attrname,$elementtype); |
|
429 | + $result = $this->delete_label($attrname, $elementtype); |
|
430 | 430 | if ($result < 0) |
431 | 431 | { |
432 | - $this->error=$this->db->lasterror(); |
|
432 | + $this->error = $this->db->lasterror(); |
|
433 | 433 | $error++; |
434 | 434 | } |
435 | 435 | |
436 | - if (! $error) |
|
436 | + if (!$error) |
|
437 | 437 | { |
438 | 438 | $sql = "SELECT COUNT(rowid) as nb"; |
439 | - $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; |
|
440 | - $sql.= " WHERE elementtype = '".$elementtype."'"; |
|
441 | - $sql.= " AND name = '".$attrname."'"; |
|
439 | + $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; |
|
440 | + $sql .= " WHERE elementtype = '".$elementtype."'"; |
|
441 | + $sql .= " AND name = '".$attrname."'"; |
|
442 | 442 | //$sql.= " AND entity IN (0,".$conf->entity.")"; Do not test on entity here. We want to see if there is still on field remaning in other entities before deleting field in table |
443 | 443 | $resql = $this->db->query($sql); |
444 | 444 | if ($resql) |
@@ -446,10 +446,10 @@ discard block |
||
446 | 446 | $obj = $this->db->fetch_object($resql); |
447 | 447 | if ($obj->nb <= 0) |
448 | 448 | { |
449 | - $result=$this->db->DDLDropField(MAIN_DB_PREFIX.$table,$attrname); // This also drop the unique key |
|
449 | + $result = $this->db->DDLDropField(MAIN_DB_PREFIX.$table, $attrname); // This also drop the unique key |
|
450 | 450 | if ($result < 0) |
451 | 451 | { |
452 | - $this->error=$this->db->lasterror(); |
|
452 | + $this->error = $this->db->lasterror(); |
|
453 | 453 | $error++; |
454 | 454 | } |
455 | 455 | } |
@@ -472,23 +472,23 @@ discard block |
||
472 | 472 | * @param string $elementtype Element type ('member', 'product', 'thirdparty', ...) |
473 | 473 | * @return int < 0 if KO, 0 if nothing is done, 1 if OK |
474 | 474 | */ |
475 | - private function delete_label($attrname, $elementtype='member') |
|
475 | + private function delete_label($attrname, $elementtype = 'member') |
|
476 | 476 | { |
477 | 477 | // phpcs:enable |
478 | 478 | global $conf; |
479 | 479 | |
480 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
481 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
480 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
481 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
482 | 482 | |
483 | - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
|
483 | + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) |
|
484 | 484 | { |
485 | 485 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; |
486 | - $sql.= " WHERE name = '".$attrname."'"; |
|
487 | - $sql.= " AND entity IN (0,".$conf->entity.')'; |
|
488 | - $sql.= " AND elementtype = '".$elementtype."'"; |
|
486 | + $sql .= " WHERE name = '".$attrname."'"; |
|
487 | + $sql .= " AND entity IN (0,".$conf->entity.')'; |
|
488 | + $sql .= " AND elementtype = '".$elementtype."'"; |
|
489 | 489 | |
490 | 490 | dol_syslog(get_class($this)."::delete_label", LOG_DEBUG); |
491 | - $resql=$this->db->query($sql); |
|
491 | + $resql = $this->db->query($sql); |
|
492 | 492 | if ($resql) |
493 | 493 | { |
494 | 494 | return 1; |
@@ -529,82 +529,82 @@ discard block |
||
529 | 529 | * @param int $totalizable Is extrafield totalizable on list |
530 | 530 | * @return int >0 if OK, <=0 if KO |
531 | 531 | */ |
532 | - function update($attrname, $label, $type, $length, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='', $help='', $default='', $computed='', $entity='', $langfile='', $enabled='1', $totalizable=0) |
|
532 | + function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0) |
|
533 | 533 | { |
534 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
535 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
536 | - |
|
537 | - $table=$elementtype.'_extrafields'; |
|
538 | - if ($elementtype == 'categorie') $table='categories_extrafields'; |
|
539 | - |
|
540 | - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
|
541 | - { |
|
542 | - if ($type=='boolean') { |
|
543 | - $typedb='int'; |
|
544 | - $lengthdb='1'; |
|
545 | - } elseif($type=='price') { |
|
546 | - $typedb='double'; |
|
547 | - $lengthdb='24,8'; |
|
548 | - } elseif($type=='phone') { |
|
549 | - $typedb='varchar'; |
|
550 | - $lengthdb='20'; |
|
551 | - } elseif($type=='mail') { |
|
552 | - $typedb='varchar'; |
|
553 | - $lengthdb='128'; |
|
554 | - } elseif($type=='url') { |
|
555 | - $typedb='varchar'; |
|
556 | - $lengthdb='255'; |
|
557 | - } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') || ($type=='checkbox') || ($type=='chkbxlst')) { |
|
558 | - $typedb='varchar'; |
|
559 | - $lengthdb='255'; |
|
534 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
535 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
536 | + |
|
537 | + $table = $elementtype.'_extrafields'; |
|
538 | + if ($elementtype == 'categorie') $table = 'categories_extrafields'; |
|
539 | + |
|
540 | + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) |
|
541 | + { |
|
542 | + if ($type == 'boolean') { |
|
543 | + $typedb = 'int'; |
|
544 | + $lengthdb = '1'; |
|
545 | + } elseif ($type == 'price') { |
|
546 | + $typedb = 'double'; |
|
547 | + $lengthdb = '24,8'; |
|
548 | + } elseif ($type == 'phone') { |
|
549 | + $typedb = 'varchar'; |
|
550 | + $lengthdb = '20'; |
|
551 | + } elseif ($type == 'mail') { |
|
552 | + $typedb = 'varchar'; |
|
553 | + $lengthdb = '128'; |
|
554 | + } elseif ($type == 'url') { |
|
555 | + $typedb = 'varchar'; |
|
556 | + $lengthdb = '255'; |
|
557 | + } elseif (($type == 'select') || ($type == 'sellist') || ($type == 'radio') || ($type == 'checkbox') || ($type == 'chkbxlst')) { |
|
558 | + $typedb = 'varchar'; |
|
559 | + $lengthdb = '255'; |
|
560 | 560 | } elseif ($type == 'html') { |
561 | - $typedb='text'; |
|
562 | - } elseif ($type=='link') { |
|
563 | - $typedb='int'; |
|
564 | - $lengthdb='11'; |
|
565 | - } elseif($type=='password') { |
|
566 | - $typedb='varchar'; |
|
567 | - $lengthdb='50'; |
|
561 | + $typedb = 'text'; |
|
562 | + } elseif ($type == 'link') { |
|
563 | + $typedb = 'int'; |
|
564 | + $lengthdb = '11'; |
|
565 | + } elseif ($type == 'password') { |
|
566 | + $typedb = 'varchar'; |
|
567 | + $lengthdb = '50'; |
|
568 | 568 | } else { |
569 | - $typedb=$type; |
|
570 | - $lengthdb=$length; |
|
569 | + $typedb = $type; |
|
570 | + $lengthdb = $length; |
|
571 | 571 | } |
572 | - $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'), 'default'=>$default); |
|
572 | + $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required ? 'NOT NULL' : 'NULL'), 'default'=>$default); |
|
573 | 573 | |
574 | 574 | if ($type != 'separate') // No table update when separate type |
575 | 575 | { |
576 | - $result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); |
|
576 | + $result = $this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); |
|
577 | 577 | } |
578 | 578 | if ($result > 0 || $type == 'separate') |
579 | 579 | { |
580 | 580 | if ($label) |
581 | 581 | { |
582 | - $result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$help,$default,$computed,$entity,$langfile,$enabled, $totalizable); |
|
582 | + $result = $this->update_label($attrname, $label, $type, $length, $elementtype, $unique, $required, $pos, $param, $alwayseditable, $perms, $list, $help, $default, $computed, $entity, $langfile, $enabled, $totalizable); |
|
583 | 583 | } |
584 | 584 | if ($result > 0) |
585 | 585 | { |
586 | - $sql=''; |
|
586 | + $sql = ''; |
|
587 | 587 | if ($unique) |
588 | 588 | { |
589 | - $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; |
|
589 | + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; |
|
590 | 590 | } |
591 | 591 | else |
592 | 592 | { |
593 | - $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname; |
|
593 | + $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname; |
|
594 | 594 | } |
595 | 595 | dol_syslog(get_class($this).'::update', LOG_DEBUG); |
596 | - $resql=$this->db->query($sql,1,'dml'); |
|
596 | + $resql = $this->db->query($sql, 1, 'dml'); |
|
597 | 597 | return 1; |
598 | 598 | } |
599 | 599 | else |
600 | 600 | { |
601 | - $this->error=$this->db->lasterror(); |
|
601 | + $this->error = $this->db->lasterror(); |
|
602 | 602 | return -1; |
603 | 603 | } |
604 | 604 | } |
605 | 605 | else |
606 | 606 | { |
607 | - $this->error=$this->db->lasterror(); |
|
607 | + $this->error = $this->db->lasterror(); |
|
608 | 608 | return -1; |
609 | 609 | } |
610 | 610 | } |
@@ -639,26 +639,26 @@ discard block |
||
639 | 639 | * @param int $totalizable Is extrafield totalizable on list |
640 | 640 | * @return int <=0 if KO, >0 if OK |
641 | 641 | */ |
642 | - private function update_label($attrname,$label,$type,$size,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0,$perms='',$list='0',$help='',$default='',$computed='',$entity='',$langfile='',$enabled='1', $totalizable=0) |
|
642 | + private function update_label($attrname, $label, $type, $size, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '0', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0) |
|
643 | 643 | { |
644 | 644 | // phpcs:enable |
645 | 645 | global $conf, $user; |
646 | 646 | dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable); |
647 | 647 | |
648 | 648 | // Clean parameters |
649 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
650 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
649 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
650 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
651 | 651 | |
652 | - if (empty($pos)) $pos=0; |
|
653 | - if (empty($list)) $list='0'; |
|
652 | + if (empty($pos)) $pos = 0; |
|
653 | + if (empty($list)) $list = '0'; |
|
654 | 654 | if (empty($totalizable)) { |
655 | 655 | $totalizable = 0; |
656 | 656 | } |
657 | - if (empty($required)) $required=0; |
|
658 | - if (empty($unique)) $unique=0; |
|
659 | - if (empty($alwayseditable)) $alwayseditable=0; |
|
657 | + if (empty($required)) $required = 0; |
|
658 | + if (empty($unique)) $unique = 0; |
|
659 | + if (empty($alwayseditable)) $alwayseditable = 0; |
|
660 | 660 | |
661 | - if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
|
661 | + if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) |
|
662 | 662 | { |
663 | 663 | $this->db->begin(); |
664 | 664 | |
@@ -672,76 +672,76 @@ discard block |
||
672 | 672 | } |
673 | 673 | else |
674 | 674 | { |
675 | - $params=''; |
|
675 | + $params = ''; |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | if ($entity === '' || $entity != '0') |
679 | 679 | { |
680 | 680 | // We dont want on all entities, we delete all and current |
681 | 681 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; |
682 | - $sql_del.= " WHERE name = '".$attrname."'"; |
|
683 | - $sql_del.= " AND entity IN (0, ".($entity===''?$conf->entity:$entity).")"; |
|
684 | - $sql_del.= " AND elementtype = '".$elementtype."'"; |
|
682 | + $sql_del .= " WHERE name = '".$attrname."'"; |
|
683 | + $sql_del .= " AND entity IN (0, ".($entity === '' ? $conf->entity : $entity).")"; |
|
684 | + $sql_del .= " AND elementtype = '".$elementtype."'"; |
|
685 | 685 | } |
686 | 686 | else |
687 | 687 | { |
688 | 688 | // We want on all entities ($entities = '0'), we delete on all only (we keep setup specific to each entity) |
689 | 689 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; |
690 | - $sql_del.= " WHERE name = '".$attrname."'"; |
|
691 | - $sql_del.= " AND entity = 0"; |
|
692 | - $sql_del.= " AND elementtype = '".$elementtype."'"; |
|
690 | + $sql_del .= " WHERE name = '".$attrname."'"; |
|
691 | + $sql_del .= " AND entity = 0"; |
|
692 | + $sql_del .= " AND elementtype = '".$elementtype."'"; |
|
693 | 693 | } |
694 | - $resql1=$this->db->query($sql_del); |
|
694 | + $resql1 = $this->db->query($sql_del); |
|
695 | 695 | |
696 | 696 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; |
697 | - $sql.= " name,"; // This is code |
|
698 | - $sql.= " entity,"; |
|
699 | - $sql.= " label,"; |
|
700 | - $sql.= " type,"; |
|
701 | - $sql.= " size,"; |
|
702 | - $sql.= " elementtype,"; |
|
703 | - $sql.= " fieldunique,"; |
|
704 | - $sql.= " fieldrequired,"; |
|
705 | - $sql.= " perms,"; |
|
706 | - $sql.= " langs,"; |
|
707 | - $sql.= " pos,"; |
|
708 | - $sql.= " alwayseditable,"; |
|
709 | - $sql.= " param,"; |
|
710 | - $sql.= " list,"; |
|
711 | - $sql.= " totalizable,"; |
|
712 | - $sql.= " fielddefault,"; |
|
713 | - $sql.= " fieldcomputed,"; |
|
714 | - $sql.= " fk_user_author,"; |
|
715 | - $sql.= " fk_user_modif,"; |
|
716 | - $sql.= " datec,"; |
|
717 | - $sql.= " enabled,"; |
|
718 | - $sql.= " help"; |
|
719 | - $sql.= ") VALUES ("; |
|
720 | - $sql.= "'".$attrname."',"; |
|
721 | - $sql.= " ".($entity===''?$conf->entity:$entity).","; |
|
722 | - $sql.= " '".$this->db->escape($label)."',"; |
|
723 | - $sql.= " '".$this->db->escape($type)."',"; |
|
724 | - $sql.= " '".$this->db->escape($size)."',"; |
|
725 | - $sql.= " '".$this->db->escape($elementtype)."',"; |
|
726 | - $sql.= " ".$unique.","; |
|
727 | - $sql.= " ".$required.","; |
|
728 | - $sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").","; |
|
729 | - $sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").","; |
|
730 | - $sql.= " ".$pos.","; |
|
731 | - $sql.= " '".$this->db->escape($alwayseditable)."',"; |
|
732 | - $sql.= " '".$this->db->escape($params)."',"; |
|
733 | - $sql.= " '".$this->db->escape($list)."', "; |
|
734 | - $sql.= " ".$totalizable.","; |
|
735 | - $sql.= " ".(($default!='')?"'".$this->db->escape($default)."'":"null").","; |
|
736 | - $sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").","; |
|
737 | - $sql .= " " . $user->id . ","; |
|
738 | - $sql .= " " . $user->id . ","; |
|
739 | - $sql .= "'" . $this->db->idate(dol_now()) . "',"; |
|
740 | - $sql .= "'" . $this->db->escape($enabled). "',"; |
|
741 | - $sql.= " ".($help?"'".$this->db->escape($help)."'":"null"); |
|
742 | - $sql.= ")"; |
|
743 | - |
|
744 | - $resql2=$this->db->query($sql); |
|
697 | + $sql .= " name,"; // This is code |
|
698 | + $sql .= " entity,"; |
|
699 | + $sql .= " label,"; |
|
700 | + $sql .= " type,"; |
|
701 | + $sql .= " size,"; |
|
702 | + $sql .= " elementtype,"; |
|
703 | + $sql .= " fieldunique,"; |
|
704 | + $sql .= " fieldrequired,"; |
|
705 | + $sql .= " perms,"; |
|
706 | + $sql .= " langs,"; |
|
707 | + $sql .= " pos,"; |
|
708 | + $sql .= " alwayseditable,"; |
|
709 | + $sql .= " param,"; |
|
710 | + $sql .= " list,"; |
|
711 | + $sql .= " totalizable,"; |
|
712 | + $sql .= " fielddefault,"; |
|
713 | + $sql .= " fieldcomputed,"; |
|
714 | + $sql .= " fk_user_author,"; |
|
715 | + $sql .= " fk_user_modif,"; |
|
716 | + $sql .= " datec,"; |
|
717 | + $sql .= " enabled,"; |
|
718 | + $sql .= " help"; |
|
719 | + $sql .= ") VALUES ("; |
|
720 | + $sql .= "'".$attrname."',"; |
|
721 | + $sql .= " ".($entity === '' ? $conf->entity : $entity).","; |
|
722 | + $sql .= " '".$this->db->escape($label)."',"; |
|
723 | + $sql .= " '".$this->db->escape($type)."',"; |
|
724 | + $sql .= " '".$this->db->escape($size)."',"; |
|
725 | + $sql .= " '".$this->db->escape($elementtype)."',"; |
|
726 | + $sql .= " ".$unique.","; |
|
727 | + $sql .= " ".$required.","; |
|
728 | + $sql .= " ".($perms ? "'".$this->db->escape($perms)."'" : "null").","; |
|
729 | + $sql .= " ".($langfile ? "'".$this->db->escape($langfile)."'" : "null").","; |
|
730 | + $sql .= " ".$pos.","; |
|
731 | + $sql .= " '".$this->db->escape($alwayseditable)."',"; |
|
732 | + $sql .= " '".$this->db->escape($params)."',"; |
|
733 | + $sql .= " '".$this->db->escape($list)."', "; |
|
734 | + $sql .= " ".$totalizable.","; |
|
735 | + $sql .= " ".(($default != '') ? "'".$this->db->escape($default)."'" : "null").","; |
|
736 | + $sql .= " ".($computed ? "'".$this->db->escape($computed)."'" : "null").","; |
|
737 | + $sql .= " ".$user->id.","; |
|
738 | + $sql .= " ".$user->id.","; |
|
739 | + $sql .= "'".$this->db->idate(dol_now())."',"; |
|
740 | + $sql .= "'".$this->db->escape($enabled)."',"; |
|
741 | + $sql .= " ".($help ? "'".$this->db->escape($help)."'" : "null"); |
|
742 | + $sql .= ")"; |
|
743 | + |
|
744 | + $resql2 = $this->db->query($sql); |
|
745 | 745 | |
746 | 746 | if ($resql1 && $resql2) |
747 | 747 | { |
@@ -770,34 +770,34 @@ discard block |
||
770 | 770 | * @param boolean $forceload Force load of extra fields whatever is option MAIN_EXTRAFIELDS_DISABLED. Deprecated. Should not be required. |
771 | 771 | * @return array Array of attributes keys+label for all extra fields. |
772 | 772 | */ |
773 | - function fetch_name_optionals_label($elementtype,$forceload=false) |
|
773 | + function fetch_name_optionals_label($elementtype, $forceload = false) |
|
774 | 774 | { |
775 | 775 | // phpcs:enable |
776 | 776 | global $conf; |
777 | 777 | |
778 | 778 | if (empty($elementtype)) return array(); |
779 | 779 | |
780 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
781 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
782 | - if ($elementtype == 'order_supplier') $elementtype='commande_fournisseur'; |
|
780 | + if ($elementtype == 'thirdparty') $elementtype = 'societe'; |
|
781 | + if ($elementtype == 'contact') $elementtype = 'socpeople'; |
|
782 | + if ($elementtype == 'order_supplier') $elementtype = 'commande_fournisseur'; |
|
783 | 783 | |
784 | - $array_name_label=array(); |
|
784 | + $array_name_label = array(); |
|
785 | 785 | |
786 | 786 | // To avoid conflicts with external modules. TODO Remove this. |
787 | 787 | if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; |
788 | 788 | |
789 | 789 | // Set array of label of entity |
790 | 790 | // TODO Remove completely loading of label. This should be done by presentation. |
791 | - $labelmulticompany=array(); |
|
791 | + $labelmulticompany = array(); |
|
792 | 792 | if (!empty($conf->multicompany->enabled)) |
793 | 793 | { |
794 | - $sql_entity_name='SELECT rowid, label FROM '.MAIN_DB_PREFIX.'entity WHERE rowid in (0,'.$conf->entity.')'; |
|
795 | - $resql_entity_name=$this->db->query($sql_entity_name); |
|
794 | + $sql_entity_name = 'SELECT rowid, label FROM '.MAIN_DB_PREFIX.'entity WHERE rowid in (0,'.$conf->entity.')'; |
|
795 | + $resql_entity_name = $this->db->query($sql_entity_name); |
|
796 | 796 | if ($resql_entity_name) |
797 | 797 | { |
798 | 798 | while ($obj = $this->db->fetch_object($resql_entity_name)) |
799 | 799 | { |
800 | - $labelmulticompany[$obj->rowid]=$obj->label; |
|
800 | + $labelmulticompany[$obj->rowid] = $obj->label; |
|
801 | 801 | } |
802 | 802 | } |
803 | 803 | } |
@@ -806,12 +806,12 @@ discard block |
||
806 | 806 | dol_syslog("fetch_name_optionals_label elementtype=".$elementtype); |
807 | 807 | |
808 | 808 | $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help"; |
809 | - $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; |
|
810 | - $sql.= " WHERE entity IN (0,".$conf->entity.")"; |
|
811 | - if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; // Filed with object->table_element |
|
812 | - $sql.= " ORDER BY pos"; |
|
809 | + $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; |
|
810 | + $sql .= " WHERE entity IN (0,".$conf->entity.")"; |
|
811 | + if ($elementtype) $sql .= " AND elementtype = '".$elementtype."'"; // Filed with object->table_element |
|
812 | + $sql .= " ORDER BY pos"; |
|
813 | 813 | |
814 | - $resql=$this->db->query($sql); |
|
814 | + $resql = $this->db->query($sql); |
|
815 | 815 | if ($resql) |
816 | 816 | { |
817 | 817 | if ($this->db->num_rows($resql)) |
@@ -821,57 +821,57 @@ discard block |
||
821 | 821 | // We can add this attribute to object. TODO Remove this and return $this->attributes[$elementtype]['label'] |
822 | 822 | if ($tab->type != 'separate') |
823 | 823 | { |
824 | - $array_name_label[$tab->name]=$tab->label; |
|
824 | + $array_name_label[$tab->name] = $tab->label; |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | // Old usage |
828 | - $this->attribute_type[$tab->name]=$tab->type; |
|
829 | - $this->attribute_label[$tab->name]=$tab->label; |
|
830 | - $this->attribute_size[$tab->name]=$tab->size; |
|
831 | - $this->attribute_elementtype[$tab->name]=$tab->elementtype; |
|
832 | - $this->attribute_default[$tab->name]=$tab->fielddefault; |
|
833 | - $this->attribute_computed[$tab->name]=$tab->fieldcomputed; |
|
834 | - $this->attribute_unique[$tab->name]=$tab->fieldunique; |
|
835 | - $this->attribute_required[$tab->name]=$tab->fieldrequired; |
|
836 | - $this->attribute_param[$tab->name]=($tab->param ? unserialize($tab->param) : ''); |
|
837 | - $this->attribute_pos[$tab->name]=$tab->pos; |
|
838 | - $this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable; |
|
839 | - $this->attribute_perms[$tab->name]=(strlen($tab->perms) == 0 ? 1 : $tab->perms); |
|
840 | - $this->attribute_langfile[$tab->name]=$tab->langs; |
|
841 | - $this->attribute_list[$tab->name]=$tab->list; |
|
842 | - $this->attribute_totalizable[$tab->name]=$tab->totalizable; |
|
843 | - $this->attribute_entityid[$tab->name]=$tab->entity; |
|
844 | - $this->attribute_entitylabel[$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]); |
|
828 | + $this->attribute_type[$tab->name] = $tab->type; |
|
829 | + $this->attribute_label[$tab->name] = $tab->label; |
|
830 | + $this->attribute_size[$tab->name] = $tab->size; |
|
831 | + $this->attribute_elementtype[$tab->name] = $tab->elementtype; |
|
832 | + $this->attribute_default[$tab->name] = $tab->fielddefault; |
|
833 | + $this->attribute_computed[$tab->name] = $tab->fieldcomputed; |
|
834 | + $this->attribute_unique[$tab->name] = $tab->fieldunique; |
|
835 | + $this->attribute_required[$tab->name] = $tab->fieldrequired; |
|
836 | + $this->attribute_param[$tab->name] = ($tab->param ? unserialize($tab->param) : ''); |
|
837 | + $this->attribute_pos[$tab->name] = $tab->pos; |
|
838 | + $this->attribute_alwayseditable[$tab->name] = $tab->alwayseditable; |
|
839 | + $this->attribute_perms[$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms); |
|
840 | + $this->attribute_langfile[$tab->name] = $tab->langs; |
|
841 | + $this->attribute_list[$tab->name] = $tab->list; |
|
842 | + $this->attribute_totalizable[$tab->name] = $tab->totalizable; |
|
843 | + $this->attribute_entityid[$tab->name] = $tab->entity; |
|
844 | + $this->attribute_entitylabel[$tab->name] = (empty($labelmulticompany[$tab->entity]) ? 'Entity'.$tab->entity : $labelmulticompany[$tab->entity]); |
|
845 | 845 | |
846 | 846 | // New usage |
847 | - $this->attributes[$tab->elementtype]['type'][$tab->name]=$tab->type; |
|
848 | - $this->attributes[$tab->elementtype]['label'][$tab->name]=$tab->label; |
|
849 | - $this->attributes[$tab->elementtype]['size'][$tab->name]=$tab->size; |
|
850 | - $this->attributes[$tab->elementtype]['elementtype'][$tab->name]=$tab->elementtype; |
|
851 | - $this->attributes[$tab->elementtype]['default'][$tab->name]=$tab->fielddefault; |
|
852 | - $this->attributes[$tab->elementtype]['computed'][$tab->name]=$tab->fieldcomputed; |
|
853 | - $this->attributes[$tab->elementtype]['unique'][$tab->name]=$tab->fieldunique; |
|
854 | - $this->attributes[$tab->elementtype]['required'][$tab->name]=$tab->fieldrequired; |
|
855 | - $this->attributes[$tab->elementtype]['param'][$tab->name]=($tab->param ? unserialize($tab->param) : ''); |
|
856 | - $this->attributes[$tab->elementtype]['pos'][$tab->name]=$tab->pos; |
|
857 | - $this->attributes[$tab->elementtype]['alwayseditable'][$tab->name]=$tab->alwayseditable; |
|
858 | - $this->attributes[$tab->elementtype]['perms'][$tab->name]=(strlen($tab->perms) == 0 ? 1 : $tab->perms); |
|
859 | - $this->attributes[$tab->elementtype]['langfile'][$tab->name]=$tab->langs; |
|
860 | - $this->attributes[$tab->elementtype]['list'][$tab->name]=$tab->list; |
|
861 | - $this->attributes[$tab->elementtype]['totalizable'][$tab->name]=$tab->totalizable; |
|
862 | - $this->attributes[$tab->elementtype]['entityid'][$tab->name]=$tab->entity; |
|
863 | - $this->attributes[$tab->elementtype]['entitylabel'][$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]); |
|
864 | - $this->attributes[$tab->elementtype]['enabled'][$tab->name]=$tab->enabled; |
|
865 | - $this->attributes[$tab->elementtype]['help'][$tab->name]=$tab->help; |
|
866 | - |
|
867 | - $this->attributes[$tab->elementtype]['loaded']=1; |
|
847 | + $this->attributes[$tab->elementtype]['type'][$tab->name] = $tab->type; |
|
848 | + $this->attributes[$tab->elementtype]['label'][$tab->name] = $tab->label; |
|
849 | + $this->attributes[$tab->elementtype]['size'][$tab->name] = $tab->size; |
|
850 | + $this->attributes[$tab->elementtype]['elementtype'][$tab->name] = $tab->elementtype; |
|
851 | + $this->attributes[$tab->elementtype]['default'][$tab->name] = $tab->fielddefault; |
|
852 | + $this->attributes[$tab->elementtype]['computed'][$tab->name] = $tab->fieldcomputed; |
|
853 | + $this->attributes[$tab->elementtype]['unique'][$tab->name] = $tab->fieldunique; |
|
854 | + $this->attributes[$tab->elementtype]['required'][$tab->name] = $tab->fieldrequired; |
|
855 | + $this->attributes[$tab->elementtype]['param'][$tab->name] = ($tab->param ? unserialize($tab->param) : ''); |
|
856 | + $this->attributes[$tab->elementtype]['pos'][$tab->name] = $tab->pos; |
|
857 | + $this->attributes[$tab->elementtype]['alwayseditable'][$tab->name] = $tab->alwayseditable; |
|
858 | + $this->attributes[$tab->elementtype]['perms'][$tab->name] = (strlen($tab->perms) == 0 ? 1 : $tab->perms); |
|
859 | + $this->attributes[$tab->elementtype]['langfile'][$tab->name] = $tab->langs; |
|
860 | + $this->attributes[$tab->elementtype]['list'][$tab->name] = $tab->list; |
|
861 | + $this->attributes[$tab->elementtype]['totalizable'][$tab->name] = $tab->totalizable; |
|
862 | + $this->attributes[$tab->elementtype]['entityid'][$tab->name] = $tab->entity; |
|
863 | + $this->attributes[$tab->elementtype]['entitylabel'][$tab->name] = (empty($labelmulticompany[$tab->entity]) ? 'Entity'.$tab->entity : $labelmulticompany[$tab->entity]); |
|
864 | + $this->attributes[$tab->elementtype]['enabled'][$tab->name] = $tab->enabled; |
|
865 | + $this->attributes[$tab->elementtype]['help'][$tab->name] = $tab->help; |
|
866 | + |
|
867 | + $this->attributes[$tab->elementtype]['loaded'] = 1; |
|
868 | 868 | } |
869 | 869 | } |
870 | - if ($elementtype) $this->attributes[$elementtype]['loaded']=1; // If nothing found, we also save tag 'loaded' |
|
870 | + if ($elementtype) $this->attributes[$elementtype]['loaded'] = 1; // If nothing found, we also save tag 'loaded' |
|
871 | 871 | } |
872 | 872 | else |
873 | 873 | { |
874 | - $this->error=$this->db->lasterror(); |
|
874 | + $this->error = $this->db->lasterror(); |
|
875 | 875 | dol_syslog(get_class($this)."::fetch_name_optionals_label ".$this->error, LOG_ERR); |
876 | 876 | } |
877 | 877 | |
@@ -893,57 +893,57 @@ discard block |
||
893 | 893 | * @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data |
894 | 894 | * @return string |
895 | 895 | */ |
896 | - function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='', $objectid=0, $extrafieldsobjectkey='') |
|
896 | + function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $extrafieldsobjectkey = '') |
|
897 | 897 | { |
898 | - global $conf,$langs,$form; |
|
898 | + global $conf, $langs, $form; |
|
899 | 899 | |
900 | - if (! is_object($form)) |
|
900 | + if (!is_object($form)) |
|
901 | 901 | { |
902 | 902 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
903 | - $form=new Form($this->db); |
|
903 | + $form = new Form($this->db); |
|
904 | 904 | } |
905 | 905 | |
906 | - $out=''; |
|
906 | + $out = ''; |
|
907 | 907 | |
908 | - $keyprefix = $keyprefix.'options_'; // Because we work on extrafields |
|
908 | + $keyprefix = $keyprefix.'options_'; // Because we work on extrafields |
|
909 | 909 | |
910 | - if (! empty($extrafieldsobjectkey)) |
|
910 | + if (!empty($extrafieldsobjectkey)) |
|
911 | 911 | { |
912 | - $label=$this->attributes[$extrafieldsobjectkey]['label'][$key]; |
|
913 | - $type=$this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
914 | - $size=$this->attributes[$extrafieldsobjectkey]['size'][$key]; |
|
915 | - $default=$this->attributes[$extrafieldsobjectkey]['default'][$key]; |
|
916 | - $computed=$this->attributes[$extrafieldsobjectkey]['computed'][$key]; |
|
917 | - $unique=$this->attributes[$extrafieldsobjectkey]['unique'][$key]; |
|
918 | - $required=$this->attributes[$extrafieldsobjectkey]['required'][$key]; |
|
919 | - $param=$this->attributes[$extrafieldsobjectkey]['param'][$key]; |
|
920 | - $perms=dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); |
|
921 | - $langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key]; |
|
922 | - $list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); |
|
923 | - $totalizable=$this->attributes[$extrafieldsobjectkey]['totalizable'][$key]; |
|
924 | - $help=$this->attributes[$extrafieldsobjectkey]['help'][$key]; |
|
925 | - $hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
912 | + $label = $this->attributes[$extrafieldsobjectkey]['label'][$key]; |
|
913 | + $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
914 | + $size = $this->attributes[$extrafieldsobjectkey]['size'][$key]; |
|
915 | + $default = $this->attributes[$extrafieldsobjectkey]['default'][$key]; |
|
916 | + $computed = $this->attributes[$extrafieldsobjectkey]['computed'][$key]; |
|
917 | + $unique = $this->attributes[$extrafieldsobjectkey]['unique'][$key]; |
|
918 | + $required = $this->attributes[$extrafieldsobjectkey]['required'][$key]; |
|
919 | + $param = $this->attributes[$extrafieldsobjectkey]['param'][$key]; |
|
920 | + $perms = dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); |
|
921 | + $langfile = $this->attributes[$extrafieldsobjectkey]['langfile'][$key]; |
|
922 | + $list = dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); |
|
923 | + $totalizable = $this->attributes[$extrafieldsobjectkey]['totalizable'][$key]; |
|
924 | + $help = $this->attributes[$extrafieldsobjectkey]['help'][$key]; |
|
925 | + $hidden = (empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
926 | 926 | } |
927 | 927 | else // Old usage |
928 | 928 | { |
929 | - $label=$this->attribute_label[$key]; |
|
930 | - $type =$this->attribute_type[$key]; |
|
931 | - $size =$this->attribute_size[$key]; |
|
932 | - $elementtype=$this->attribute_elementtype[$key]; // Seems not used |
|
933 | - $default=$this->attribute_default[$key]; |
|
934 | - $computed=$this->attribute_computed[$key]; |
|
935 | - $unique=$this->attribute_unique[$key]; |
|
936 | - $required=$this->attribute_required[$key]; |
|
937 | - $param=$this->attribute_param[$key]; |
|
938 | - $langfile=$this->attribute_langfile[$key]; |
|
939 | - $list=$this->attribute_list[$key]; |
|
940 | - $totalizable=$this->attribute_totalizable[$key]; |
|
941 | - $hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
929 | + $label = $this->attribute_label[$key]; |
|
930 | + $type = $this->attribute_type[$key]; |
|
931 | + $size = $this->attribute_size[$key]; |
|
932 | + $elementtype = $this->attribute_elementtype[$key]; // Seems not used |
|
933 | + $default = $this->attribute_default[$key]; |
|
934 | + $computed = $this->attribute_computed[$key]; |
|
935 | + $unique = $this->attribute_unique[$key]; |
|
936 | + $required = $this->attribute_required[$key]; |
|
937 | + $param = $this->attribute_param[$key]; |
|
938 | + $langfile = $this->attribute_langfile[$key]; |
|
939 | + $list = $this->attribute_list[$key]; |
|
940 | + $totalizable = $this->attribute_totalizable[$key]; |
|
941 | + $hidden = (empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | if ($computed) |
945 | 945 | { |
946 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
946 | + if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
947 | 947 | else return ''; |
948 | 948 | } |
949 | 949 | |
@@ -957,21 +957,21 @@ discard block |
||
957 | 957 | { |
958 | 958 | $morecss = 'minwidth200imp'; |
959 | 959 | } |
960 | - elseif (in_array($type,array('int','integer','double','price'))) |
|
960 | + elseif (in_array($type, array('int', 'integer', 'double', 'price'))) |
|
961 | 961 | { |
962 | 962 | $morecss = 'maxwidth75'; |
963 | 963 | } |
964 | 964 | elseif ($type == 'password') |
965 | 965 | { |
966 | - $morecss='maxwidth100'; |
|
966 | + $morecss = 'maxwidth100'; |
|
967 | 967 | } |
968 | 968 | elseif ($type == 'url') |
969 | 969 | { |
970 | - $morecss='minwidth400'; |
|
970 | + $morecss = 'minwidth400'; |
|
971 | 971 | } |
972 | 972 | elseif ($type == 'boolean') |
973 | 973 | { |
974 | - $morecss=''; |
|
974 | + $morecss = ''; |
|
975 | 975 | } |
976 | 976 | else |
977 | 977 | { |
@@ -990,12 +990,12 @@ discard block |
||
990 | 990 | } |
991 | 991 | } |
992 | 992 | |
993 | - if (in_array($type,array('date','datetime'))) |
|
993 | + if (in_array($type, array('date', 'datetime'))) |
|
994 | 994 | { |
995 | - $tmp=explode(',',$size); |
|
996 | - $newsize=$tmp[0]; |
|
995 | + $tmp = explode(',', $size); |
|
996 | + $newsize = $tmp[0]; |
|
997 | 997 | |
998 | - $showtime = in_array($type,array('datetime')) ? 1 : 0; |
|
998 | + $showtime = in_array($type, array('datetime')) ? 1 : 0; |
|
999 | 999 | |
1000 | 1000 | // Do not show current date when field not required (see selectDate() method) |
1001 | 1001 | if (!$required && $value == '') $value = '-1'; |
@@ -1003,244 +1003,244 @@ discard block |
||
1003 | 1003 | // TODO Must also support $moreparam |
1004 | 1004 | $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
1005 | 1005 | } |
1006 | - elseif (in_array($type,array('int','integer'))) |
|
1006 | + elseif (in_array($type, array('int', 'integer'))) |
|
1007 | 1007 | { |
1008 | - $tmp=explode(',',$size); |
|
1009 | - $newsize=$tmp[0]; |
|
1010 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
1008 | + $tmp = explode(',', $size); |
|
1009 | + $newsize = $tmp[0]; |
|
1010 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').'>'; |
|
1011 | 1011 | } |
1012 | 1012 | elseif (preg_match('/varchar/', $type)) |
1013 | 1013 | { |
1014 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
1014 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').'>'; |
|
1015 | 1015 | } |
1016 | 1016 | elseif (in_array($type, array('mail', 'phone', 'url'))) |
1017 | 1017 | { |
1018 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
1018 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
1019 | 1019 | } |
1020 | 1020 | elseif ($type == 'text') |
1021 | 1021 | { |
1022 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
1022 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
1023 | 1023 | { |
1024 | 1024 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
1025 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
1026 | - $out=$doleditor->Create(1); |
|
1025 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); |
|
1026 | + $out = $doleditor->Create(1); |
|
1027 | 1027 | } |
1028 | 1028 | else |
1029 | 1029 | { |
1030 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
1030 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
1031 | 1031 | } |
1032 | 1032 | } |
1033 | 1033 | elseif ($type == 'html') |
1034 | 1034 | { |
1035 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
1035 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
1036 | 1036 | { |
1037 | 1037 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
1038 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%'); |
|
1039 | - $out=$doleditor->Create(1); |
|
1038 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); |
|
1039 | + $out = $doleditor->Create(1); |
|
1040 | 1040 | } |
1041 | 1041 | else |
1042 | 1042 | { |
1043 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
1043 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
1044 | 1044 | } |
1045 | 1045 | } |
1046 | 1046 | elseif ($type == 'boolean') |
1047 | 1047 | { |
1048 | - $checked=''; |
|
1048 | + $checked = ''; |
|
1049 | 1049 | if (!empty($value)) { |
1050 | - $checked=' checked value="1" '; |
|
1050 | + $checked = ' checked value="1" '; |
|
1051 | 1051 | } else { |
1052 | - $checked=' value="1" '; |
|
1052 | + $checked = ' value="1" '; |
|
1053 | 1053 | } |
1054 | - $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
1054 | + $out = '<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>'; |
|
1055 | 1055 | } |
1056 | 1056 | elseif ($type == 'price') |
1057 | 1057 | { |
1058 | 1058 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
1059 | - $value=price($value); |
|
1059 | + $value = price($value); |
|
1060 | 1060 | } |
1061 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
|
1061 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '.$langs->getCurrencySymbol($conf->currency); |
|
1062 | 1062 | } |
1063 | 1063 | elseif ($type == 'double') |
1064 | 1064 | { |
1065 | 1065 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
1066 | - $value=price($value); |
|
1066 | + $value = price($value); |
|
1067 | 1067 | } |
1068 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
1068 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '; |
|
1069 | 1069 | } |
1070 | 1070 | elseif ($type == 'select') |
1071 | 1071 | { |
1072 | 1072 | $out = ''; |
1073 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
1073 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
1074 | 1074 | { |
1075 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
1076 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
1075 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
1076 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
1077 | 1077 | } |
1078 | 1078 | |
1079 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
1080 | - $out.='<option value="0"> </option>'; |
|
1079 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
1080 | + $out .= '<option value="0"> </option>'; |
|
1081 | 1081 | foreach ($param['options'] as $key => $val) |
1082 | 1082 | { |
1083 | 1083 | if ((string) $key == '') continue; |
1084 | 1084 | list($val, $parent) = explode('|', $val); |
1085 | - $out.='<option value="'.$key.'"'; |
|
1086 | - $out.= (((string) $value == (string) $key)?' selected':''); |
|
1087 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
1088 | - $out.='>'; |
|
1089 | - if ($langfile && $val) $out.=$langs->trans($val); |
|
1090 | - else $out.=$val; |
|
1091 | - $out.='</option>'; |
|
1085 | + $out .= '<option value="'.$key.'"'; |
|
1086 | + $out .= (((string) $value == (string) $key) ? ' selected' : ''); |
|
1087 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
1088 | + $out .= '>'; |
|
1089 | + if ($langfile && $val) $out .= $langs->trans($val); |
|
1090 | + else $out .= $val; |
|
1091 | + $out .= '</option>'; |
|
1092 | 1092 | } |
1093 | - $out.='</select>'; |
|
1093 | + $out .= '</select>'; |
|
1094 | 1094 | } |
1095 | 1095 | elseif ($type == 'sellist') |
1096 | 1096 | { |
1097 | 1097 | $out = ''; |
1098 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
1098 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
1099 | 1099 | { |
1100 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
1101 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
1100 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
1101 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
1104 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
1105 | 1105 | if (is_array($param['options'])) |
1106 | 1106 | { |
1107 | - $param_list=array_keys($param['options']); |
|
1107 | + $param_list = array_keys($param['options']); |
|
1108 | 1108 | $InfoFieldList = explode(":", $param_list[0]); |
1109 | - $parentName=''; |
|
1110 | - $parentField=''; |
|
1109 | + $parentName = ''; |
|
1110 | + $parentField = ''; |
|
1111 | 1111 | // 0 : tableName |
1112 | 1112 | // 1 : label field name |
1113 | 1113 | // 2 : key fields name (if differ of rowid) |
1114 | 1114 | // 3 : key field parent (for dependent lists) |
1115 | 1115 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
1116 | - $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
1116 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
1117 | 1117 | |
1118 | 1118 | |
1119 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
1119 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) |
|
1120 | 1120 | { |
1121 | 1121 | if (strpos($InfoFieldList[4], 'extra.') !== false) |
1122 | 1122 | { |
1123 | - $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
1123 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
1124 | 1124 | } else { |
1125 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
1125 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
1126 | 1126 | } |
1127 | 1127 | } |
1128 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
1128 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) |
|
1129 | 1129 | { |
1130 | 1130 | list($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
1131 | - $keyList.= ', '.$parentField; |
|
1131 | + $keyList .= ', '.$parentField; |
|
1132 | 1132 | } |
1133 | 1133 | |
1134 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
1134 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
1135 | 1135 | if (is_array($fields_label)) |
1136 | 1136 | { |
1137 | - $keyList .=', '; |
|
1137 | + $keyList .= ', '; |
|
1138 | 1138 | $keyList .= implode(', ', $fields_label); |
1139 | 1139 | } |
1140 | 1140 | |
1141 | - $sqlwhere=''; |
|
1141 | + $sqlwhere = ''; |
|
1142 | 1142 | $sql = 'SELECT '.$keyList; |
1143 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
1143 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
1144 | 1144 | if (!empty($InfoFieldList[4])) |
1145 | 1145 | { |
1146 | 1146 | // can use curent entity filter |
1147 | - if (strpos($InfoFieldList[4], '$ENTITY$')!==false) { |
|
1148 | - $InfoFieldList[4]=str_replace('$ENTITY$',$conf->entity,$InfoFieldList[4]); |
|
1147 | + if (strpos($InfoFieldList[4], '$ENTITY$') !== false) { |
|
1148 | + $InfoFieldList[4] = str_replace('$ENTITY$', $conf->entity, $InfoFieldList[4]); |
|
1149 | 1149 | } |
1150 | 1150 | // can use SELECT request |
1151 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
1152 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
1151 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
1152 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
1153 | 1153 | } |
1154 | 1154 | |
1155 | 1155 | // current object id can be use into filter |
1156 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
1157 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
1156 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
1157 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
1158 | 1158 | } else { |
1159 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
1159 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
1160 | 1160 | } |
1161 | 1161 | //We have to join on extrafield table |
1162 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
1162 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
1163 | 1163 | { |
1164 | - $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
1165 | - $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
1164 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
1165 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
1166 | 1166 | } |
1167 | 1167 | else |
1168 | 1168 | { |
1169 | - $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
1169 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | else |
1173 | 1173 | { |
1174 | - $sqlwhere.= ' WHERE 1=1'; |
|
1174 | + $sqlwhere .= ' WHERE 1=1'; |
|
1175 | 1175 | } |
1176 | 1176 | // Some tables may have field, some other not. For the moment we disable it. |
1177 | - if (in_array($InfoFieldList[0],array('tablewithentity'))) |
|
1177 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
1178 | 1178 | { |
1179 | - $sqlwhere.= ' AND entity = '.$conf->entity; |
|
1179 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
1180 | 1180 | } |
1181 | - $sql.=$sqlwhere; |
|
1181 | + $sql .= $sqlwhere; |
|
1182 | 1182 | //print $sql; |
1183 | 1183 | |
1184 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label); |
|
1184 | + $sql .= ' ORDER BY '.implode(', ', $fields_label); |
|
1185 | 1185 | |
1186 | 1186 | dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
1187 | 1187 | $resql = $this->db->query($sql); |
1188 | 1188 | if ($resql) |
1189 | 1189 | { |
1190 | - $out.='<option value="0"> </option>'; |
|
1190 | + $out .= '<option value="0"> </option>'; |
|
1191 | 1191 | $num = $this->db->num_rows($resql); |
1192 | 1192 | $i = 0; |
1193 | 1193 | while ($i < $num) |
1194 | 1194 | { |
1195 | - $labeltoshow=''; |
|
1195 | + $labeltoshow = ''; |
|
1196 | 1196 | $obj = $this->db->fetch_object($resql); |
1197 | 1197 | |
1198 | 1198 | // Several field into label (eq table:code|libelle:rowid) |
1199 | 1199 | $notrans = false; |
1200 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
1200 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
1201 | 1201 | if (is_array($fields_label)) |
1202 | 1202 | { |
1203 | 1203 | $notrans = true; |
1204 | 1204 | foreach ($fields_label as $field_toshow) |
1205 | 1205 | { |
1206 | - $labeltoshow.= $obj->$field_toshow.' '; |
|
1206 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
1207 | 1207 | } |
1208 | 1208 | } |
1209 | 1209 | else |
1210 | 1210 | { |
1211 | - $labeltoshow=$obj->{$InfoFieldList[1]}; |
|
1211 | + $labeltoshow = $obj->{$InfoFieldList[1]}; |
|
1212 | 1212 | } |
1213 | - $labeltoshow=dol_trunc($labeltoshow,45); |
|
1213 | + $labeltoshow = dol_trunc($labeltoshow, 45); |
|
1214 | 1214 | |
1215 | 1215 | if ($value == $obj->rowid) |
1216 | 1216 | { |
1217 | 1217 | foreach ($fields_label as $field_toshow) |
1218 | 1218 | { |
1219 | - $translabel=$langs->trans($obj->$field_toshow); |
|
1220 | - if ($translabel!=$obj->$field_toshow) { |
|
1221 | - $labeltoshow=dol_trunc($translabel,18).' '; |
|
1222 | - }else { |
|
1223 | - $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
1219 | + $translabel = $langs->trans($obj->$field_toshow); |
|
1220 | + if ($translabel != $obj->$field_toshow) { |
|
1221 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
1222 | + } else { |
|
1223 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
1224 | 1224 | } |
1225 | 1225 | } |
1226 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
1226 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
1227 | 1227 | } |
1228 | 1228 | else |
1229 | 1229 | { |
1230 | - if (! $notrans) |
|
1230 | + if (!$notrans) |
|
1231 | 1231 | { |
1232 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
1233 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
1234 | - $labeltoshow=dol_trunc($translabel,18); |
|
1232 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
1233 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
1234 | + $labeltoshow = dol_trunc($translabel, 18); |
|
1235 | 1235 | } |
1236 | 1236 | else { |
1237 | - $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18); |
|
1237 | + $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]},18); |
|
1238 | 1238 | } |
1239 | 1239 | } |
1240 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
1241 | - if ($value==$obj->rowid) |
|
1240 | + if (empty($labeltoshow)) $labeltoshow = '(not defined)'; |
|
1241 | + if ($value == $obj->rowid) |
|
1242 | 1242 | { |
1243 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
1243 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | if (!empty($InfoFieldList[3]) && $parentField) |
@@ -1248,10 +1248,10 @@ discard block |
||
1248 | 1248 | $parent = $parentName.':'.$obj->{$parentField}; |
1249 | 1249 | } |
1250 | 1250 | |
1251 | - $out.='<option value="'.$obj->rowid.'"'; |
|
1252 | - $out.= ($value==$obj->rowid?' selected':''); |
|
1253 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
1254 | - $out.='>'.$labeltoshow.'</option>'; |
|
1251 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
1252 | + $out .= ($value == $obj->rowid ? ' selected' : ''); |
|
1253 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
1254 | + $out .= '>'.$labeltoshow.'</option>'; |
|
1255 | 1255 | } |
1256 | 1256 | |
1257 | 1257 | $i++; |
@@ -1262,23 +1262,23 @@ discard block |
||
1262 | 1262 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
1263 | 1263 | } |
1264 | 1264 | } |
1265 | - $out.='</select>'; |
|
1265 | + $out .= '</select>'; |
|
1266 | 1266 | } |
1267 | 1267 | elseif ($type == 'checkbox') |
1268 | 1268 | { |
1269 | - $value_arr=explode(',',$value); |
|
1270 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
1269 | + $value_arr = explode(',', $value); |
|
1270 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
1271 | 1271 | } |
1272 | 1272 | elseif ($type == 'radio') |
1273 | 1273 | { |
1274 | - $out=''; |
|
1274 | + $out = ''; |
|
1275 | 1275 | foreach ($param['options'] as $keyopt => $val) |
1276 | 1276 | { |
1277 | - $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
1278 | - $out.=' value="'.$keyopt.'"'; |
|
1279 | - $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
1280 | - $out.= ($value==$keyopt?'checked':''); |
|
1281 | - $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
1277 | + $out .= '<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : ''); |
|
1278 | + $out .= ' value="'.$keyopt.'"'; |
|
1279 | + $out .= ' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
1280 | + $out .= ($value == $keyopt ? 'checked' : ''); |
|
1281 | + $out .= '/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
1282 | 1282 | } |
1283 | 1283 | } |
1284 | 1284 | elseif ($type == 'chkbxlst') |
@@ -1293,24 +1293,24 @@ discard block |
||
1293 | 1293 | if (is_array($param['options'])) { |
1294 | 1294 | $param_list = array_keys($param['options']); |
1295 | 1295 | $InfoFieldList = explode(":", $param_list[0]); |
1296 | - $parentName=''; |
|
1297 | - $parentField=''; |
|
1296 | + $parentName = ''; |
|
1297 | + $parentField = ''; |
|
1298 | 1298 | // 0 : tableName |
1299 | 1299 | // 1 : label field name |
1300 | 1300 | // 2 : key fields name (if differ of rowid) |
1301 | 1301 | // 3 : key field parent (for dependent lists) |
1302 | 1302 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
1303 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
1303 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
1304 | 1304 | |
1305 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) { |
|
1306 | - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]); |
|
1307 | - $keyList .= ', ' . $parentField; |
|
1305 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { |
|
1306 | + list ($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
|
1307 | + $keyList .= ', '.$parentField; |
|
1308 | 1308 | } |
1309 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) { |
|
1309 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { |
|
1310 | 1310 | if (strpos($InfoFieldList[4], 'extra.') !== false) { |
1311 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
1311 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
1312 | 1312 | } else { |
1313 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
1313 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
1314 | 1314 | } |
1315 | 1315 | } |
1316 | 1316 | |
@@ -1321,59 +1321,59 @@ discard block |
||
1321 | 1321 | } |
1322 | 1322 | |
1323 | 1323 | $sqlwhere = ''; |
1324 | - $sql = 'SELECT ' . $keyList; |
|
1325 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
1326 | - if (! empty($InfoFieldList[4])) { |
|
1324 | + $sql = 'SELECT '.$keyList; |
|
1325 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
1326 | + if (!empty($InfoFieldList[4])) { |
|
1327 | 1327 | |
1328 | 1328 | // can use SELECT request |
1329 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
1330 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
1329 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
1330 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
1331 | 1331 | } |
1332 | 1332 | |
1333 | 1333 | // current object id can be use into filter |
1334 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
1335 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
1336 | - } else if (preg_match("#^.*list.php$#",$_SERVER["DOCUMENT_URI"])) { |
|
1334 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
1335 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
1336 | + } else if (preg_match("#^.*list.php$#", $_SERVER["DOCUMENT_URI"])) { |
|
1337 | 1337 | // Pattern for word=$ID$ |
1338 | 1338 | $word = '\b[a-zA-Z0-9-\.-_]+\b=\$ID\$'; |
1339 | 1339 | |
1340 | 1340 | // Removing space arount =, ( and ) |
1341 | - $InfoFieldList[4]=preg_replace('# *(=|\(|\)) *#','$1', $InfoFieldList[4]); |
|
1341 | + $InfoFieldList[4] = preg_replace('# *(=|\(|\)) *#', '$1', $InfoFieldList[4]); |
|
1342 | 1342 | |
1343 | 1343 | $nbPreg = 1; |
1344 | 1344 | // While we have parenthesis |
1345 | - while ($nbPreg!=0) { |
|
1345 | + while ($nbPreg != 0) { |
|
1346 | 1346 | // Init des compteurs |
1347 | 1347 | $nbPregRepl = $nbPregSel = 0; |
1348 | 1348 | // On retire toutes les parenthèses sans = avant |
1349 | - $InfoFieldList[4]=preg_replace( '#([^=])(\([^)^(]*(' . $word . ')[^)^(]*\))#','$1 $3 ',$InfoFieldList[4],-1,$nbPregRepl); |
|
1349 | + $InfoFieldList[4] = preg_replace('#([^=])(\([^)^(]*('.$word.')[^)^(]*\))#', '$1 $3 ', $InfoFieldList[4], -1, $nbPregRepl); |
|
1350 | 1350 | // On retire les espaces autour des = et parenthèses |
1351 | - $InfoFieldList[4]=preg_replace('# *(=|\(|\)) *#','$1', $InfoFieldList[4]); |
|
1351 | + $InfoFieldList[4] = preg_replace('# *(=|\(|\)) *#', '$1', $InfoFieldList[4]); |
|
1352 | 1352 | // On retire toutes les parenthèses avec = avant |
1353 | - $InfoFieldList[4]=preg_replace( '#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*(' . $word . ')[^)^(]*\)#','$1 ',$InfoFieldList[4], -1, $nbPregSel); |
|
1353 | + $InfoFieldList[4] = preg_replace('#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*('.$word.')[^)^(]*\)#', '$1 ', $InfoFieldList[4], -1, $nbPregSel); |
|
1354 | 1354 | // On retire les espaces autour des = et parenthèses |
1355 | - $InfoFieldList[4]=preg_replace('# *(=|\(|\)) *#','$1', $InfoFieldList[4]); |
|
1355 | + $InfoFieldList[4] = preg_replace('# *(=|\(|\)) *#', '$1', $InfoFieldList[4]); |
|
1356 | 1356 | |
1357 | 1357 | // Calcul du compteur général pour la boucle |
1358 | 1358 | $nbPreg = $nbPregRepl + $nbPregSel; |
1359 | 1359 | } |
1360 | 1360 | |
1361 | 1361 | // Si l'on a un AND ou un OR, avant ou après |
1362 | - preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#',$InfoFieldList[4],$matchCondition); |
|
1363 | - while(!empty($matchCondition[0])) { |
|
1362 | + preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#', $InfoFieldList[4], $matchCondition); |
|
1363 | + while (!empty($matchCondition[0])) { |
|
1364 | 1364 | // If the two sides differ but are not empty |
1365 | - if (! empty($matchCondition[1]) && ! empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3] ) { |
|
1365 | + if (!empty($matchCondition[1]) && !empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3]) { |
|
1366 | 1366 | // Nobody sain would do that without parentheses |
1367 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
1367 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
1368 | 1368 | } |
1369 | 1369 | else { |
1370 | - if (! empty($matchCondition[1])) { |
|
1371 | - $boolCond =(( $matchCondition[1] == "AND" )?' AND 1 ':' OR 0 '); |
|
1372 | - $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond.$matchCondition[3],$InfoFieldList[4]); |
|
1370 | + if (!empty($matchCondition[1])) { |
|
1371 | + $boolCond = (($matchCondition[1] == "AND") ? ' AND 1 ' : ' OR 0 '); |
|
1372 | + $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond.$matchCondition[3], $InfoFieldList[4]); |
|
1373 | 1373 | } |
1374 | - else if (! empty($matchCondition[3])) { |
|
1375 | - $boolCond =(( $matchCondition[3] == "AND" )?' 1 AND ':' 0 OR'); |
|
1376 | - $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond,$InfoFieldList[4]); |
|
1374 | + else if (!empty($matchCondition[3])) { |
|
1375 | + $boolCond = (($matchCondition[3] == "AND") ? ' 1 AND ' : ' 0 OR'); |
|
1376 | + $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond, $InfoFieldList[4]); |
|
1377 | 1377 | } |
1378 | 1378 | else { |
1379 | 1379 | $InfoFieldList[4] = 1; |
@@ -1381,41 +1381,41 @@ discard block |
||
1381 | 1381 | } |
1382 | 1382 | |
1383 | 1383 | // Si l'on a un AND ou un OR, avant ou après |
1384 | - preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#',$InfoFieldList[4],$matchCondition); |
|
1384 | + preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#', $InfoFieldList[4], $matchCondition); |
|
1385 | 1385 | } |
1386 | 1386 | } |
1387 | 1387 | else { |
1388 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
1388 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
1389 | 1389 | } |
1390 | 1390 | |
1391 | 1391 | // We have to join on extrafield table |
1392 | 1392 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
1393 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
1394 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
1393 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
1394 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
1395 | 1395 | } else { |
1396 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
1396 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
1397 | 1397 | } |
1398 | 1398 | } else { |
1399 | 1399 | $sqlwhere .= ' WHERE 1=1'; |
1400 | 1400 | } |
1401 | 1401 | // Some tables may have field, some other not. For the moment we disable it. |
1402 | - if (in_array($InfoFieldList[0], array ('tablewithentity'))) |
|
1402 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
1403 | 1403 | { |
1404 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
1404 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
1405 | 1405 | } |
1406 | 1406 | // $sql.=preg_replace('/^ AND /','',$sqlwhere); |
1407 | 1407 | // print $sql; |
1408 | 1408 | |
1409 | 1409 | $sql .= $sqlwhere; |
1410 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
1410 | + dol_syslog(get_class($this).'::showInputField type=chkbxlst', LOG_DEBUG); |
|
1411 | 1411 | $resql = $this->db->query($sql); |
1412 | 1412 | if ($resql) { |
1413 | 1413 | $num = $this->db->num_rows($resql); |
1414 | 1414 | $i = 0; |
1415 | 1415 | |
1416 | - $data=array(); |
|
1416 | + $data = array(); |
|
1417 | 1417 | |
1418 | - while ( $i < $num ) { |
|
1418 | + while ($i < $num) { |
|
1419 | 1419 | $labeltoshow = ''; |
1420 | 1420 | $obj = $this->db->fetch_object($resql); |
1421 | 1421 | |
@@ -1424,8 +1424,8 @@ discard block |
||
1424 | 1424 | $fields_label = explode('|', $InfoFieldList[1]); |
1425 | 1425 | if (is_array($fields_label)) { |
1426 | 1426 | $notrans = true; |
1427 | - foreach ( $fields_label as $field_toshow ) { |
|
1428 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
1427 | + foreach ($fields_label as $field_toshow) { |
|
1428 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
1429 | 1429 | } |
1430 | 1430 | } else { |
1431 | 1431 | $labeltoshow = $obj->{$InfoFieldList[1]}; |
@@ -1433,18 +1433,18 @@ discard block |
||
1433 | 1433 | $labeltoshow = dol_trunc($labeltoshow, 45); |
1434 | 1434 | |
1435 | 1435 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
1436 | - foreach ( $fields_label as $field_toshow ) { |
|
1436 | + foreach ($fields_label as $field_toshow) { |
|
1437 | 1437 | $translabel = $langs->trans($obj->$field_toshow); |
1438 | 1438 | if ($translabel != $obj->$field_toshow) { |
1439 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
1439 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
1440 | 1440 | } else { |
1441 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
1441 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
1442 | 1442 | } |
1443 | 1443 | } |
1444 | 1444 | |
1445 | - $data[$obj->rowid]=$labeltoshow; |
|
1445 | + $data[$obj->rowid] = $labeltoshow; |
|
1446 | 1446 | } else { |
1447 | - if (! $notrans) { |
|
1447 | + if (!$notrans) { |
|
1448 | 1448 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
1449 | 1449 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
1450 | 1450 | $labeltoshow = dol_trunc($translabel, 18); |
@@ -1456,40 +1456,40 @@ discard block |
||
1456 | 1456 | $labeltoshow = '(not defined)'; |
1457 | 1457 | |
1458 | 1458 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
1459 | - $data[$obj->rowid]=$labeltoshow; |
|
1459 | + $data[$obj->rowid] = $labeltoshow; |
|
1460 | 1460 | } |
1461 | 1461 | |
1462 | - if (! empty($InfoFieldList[3]) && $parentField) { |
|
1463 | - $parent = $parentName . ':' . $obj->{$parentField}; |
|
1462 | + if (!empty($InfoFieldList[3]) && $parentField) { |
|
1463 | + $parent = $parentName.':'.$obj->{$parentField}; |
|
1464 | 1464 | } |
1465 | 1465 | |
1466 | - $data[$obj->rowid]=$labeltoshow; |
|
1466 | + $data[$obj->rowid] = $labeltoshow; |
|
1467 | 1467 | } |
1468 | 1468 | |
1469 | - $i ++; |
|
1469 | + $i++; |
|
1470 | 1470 | } |
1471 | 1471 | $this->db->free($resql); |
1472 | 1472 | |
1473 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
1473 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
1474 | 1474 | } else { |
1475 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
1475 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
1476 | 1476 | } |
1477 | 1477 | } |
1478 | 1478 | } |
1479 | 1479 | elseif ($type == 'link') |
1480 | 1480 | { |
1481 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
1482 | - $showempty=(($required && $default != '')?0:1); |
|
1483 | - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
1481 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
1482 | + $showempty = (($required && $default != '') ? 0 : 1); |
|
1483 | + $out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
1484 | 1484 | } |
1485 | 1485 | elseif ($type == 'password') |
1486 | 1486 | { |
1487 | 1487 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
1488 | - $out='<input style="display:none" type="text" name="fakeusernameremembered">'; // Hidden field to reduce impact of evil Google Chrome autopopulate bug. |
|
1489 | - $out.='<input autocomplete="new-password" type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
1488 | + $out = '<input style="display:none" type="text" name="fakeusernameremembered">'; // Hidden field to reduce impact of evil Google Chrome autopopulate bug. |
|
1489 | + $out .= '<input autocomplete="new-password" type="'.($keyprefix == 'search_' ? 'text' : 'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>'; |
|
1490 | 1490 | } |
1491 | 1491 | if (!empty($hidden)) { |
1492 | - $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
1492 | + $out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
1493 | 1493 | } |
1494 | 1494 | /* Add comments |
1495 | 1495 | if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
@@ -1508,44 +1508,44 @@ discard block |
||
1508 | 1508 | * @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data |
1509 | 1509 | * @return string Formated value |
1510 | 1510 | */ |
1511 | - function showOutputField($key, $value, $moreparam='', $extrafieldsobjectkey='') |
|
1511 | + function showOutputField($key, $value, $moreparam = '', $extrafieldsobjectkey = '') |
|
1512 | 1512 | { |
1513 | - global $conf,$langs; |
|
1514 | - |
|
1515 | - if (! empty($extrafieldsobjectkey)) |
|
1516 | - { |
|
1517 | - $label=$this->attributes[$extrafieldsobjectkey]['label'][$key]; |
|
1518 | - $type=$this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
1519 | - $size=$this->attributes[$extrafieldsobjectkey]['size'][$key]; |
|
1520 | - $default=$this->attributes[$extrafieldsobjectkey]['default'][$key]; |
|
1521 | - $computed=$this->attributes[$extrafieldsobjectkey]['computed'][$key]; |
|
1522 | - $unique=$this->attributes[$extrafieldsobjectkey]['unique'][$key]; |
|
1523 | - $required=$this->attributes[$extrafieldsobjectkey]['required'][$key]; |
|
1524 | - $param=$this->attributes[$extrafieldsobjectkey]['param'][$key]; |
|
1525 | - $perms=dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); |
|
1526 | - $langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key]; |
|
1527 | - $list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); |
|
1528 | - $help=$this->attributes[$extrafieldsobjectkey]['help'][$key]; |
|
1529 | - $hidden=(empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
1513 | + global $conf, $langs; |
|
1514 | + |
|
1515 | + if (!empty($extrafieldsobjectkey)) |
|
1516 | + { |
|
1517 | + $label = $this->attributes[$extrafieldsobjectkey]['label'][$key]; |
|
1518 | + $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
1519 | + $size = $this->attributes[$extrafieldsobjectkey]['size'][$key]; |
|
1520 | + $default = $this->attributes[$extrafieldsobjectkey]['default'][$key]; |
|
1521 | + $computed = $this->attributes[$extrafieldsobjectkey]['computed'][$key]; |
|
1522 | + $unique = $this->attributes[$extrafieldsobjectkey]['unique'][$key]; |
|
1523 | + $required = $this->attributes[$extrafieldsobjectkey]['required'][$key]; |
|
1524 | + $param = $this->attributes[$extrafieldsobjectkey]['param'][$key]; |
|
1525 | + $perms = dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); |
|
1526 | + $langfile = $this->attributes[$extrafieldsobjectkey]['langfile'][$key]; |
|
1527 | + $list = dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); |
|
1528 | + $help = $this->attributes[$extrafieldsobjectkey]['help'][$key]; |
|
1529 | + $hidden = (empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
1530 | 1530 | } |
1531 | 1531 | else // Old usage |
1532 | 1532 | { |
1533 | - $label=$this->attribute_label[$key]; |
|
1534 | - $type=$this->attribute_type[$key]; |
|
1535 | - $size=$this->attribute_size[$key]; |
|
1536 | - $default=$this->attribute_default[$key]; |
|
1537 | - $computed=$this->attribute_computed[$key]; |
|
1538 | - $unique=$this->attribute_unique[$key]; |
|
1539 | - $required=$this->attribute_required[$key]; |
|
1540 | - $param=$this->attribute_param[$key]; |
|
1541 | - $perms=dol_eval($this->attribute_perms[$key], 1); |
|
1542 | - $langfile=$this->attribute_langfile[$key]; |
|
1543 | - $list=dol_eval($this->attribute_list[$key], 1); |
|
1544 | - $help=''; // Not supported with old syntax |
|
1545 | - $hidden=(empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
1533 | + $label = $this->attribute_label[$key]; |
|
1534 | + $type = $this->attribute_type[$key]; |
|
1535 | + $size = $this->attribute_size[$key]; |
|
1536 | + $default = $this->attribute_default[$key]; |
|
1537 | + $computed = $this->attribute_computed[$key]; |
|
1538 | + $unique = $this->attribute_unique[$key]; |
|
1539 | + $required = $this->attribute_required[$key]; |
|
1540 | + $param = $this->attribute_param[$key]; |
|
1541 | + $perms = dol_eval($this->attribute_perms[$key], 1); |
|
1542 | + $langfile = $this->attribute_langfile[$key]; |
|
1543 | + $list = dol_eval($this->attribute_list[$key], 1); |
|
1544 | + $help = ''; // Not supported with old syntax |
|
1545 | + $hidden = (empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
1546 | 1546 | } |
1547 | 1547 | |
1548 | - if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method. |
|
1548 | + if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method. |
|
1549 | 1549 | |
1550 | 1550 | // If field is a computed field, value must become result of compute |
1551 | 1551 | if ($computed) |
@@ -1555,88 +1555,88 @@ discard block |
||
1555 | 1555 | $value = dol_eval($computed, 1, 0); |
1556 | 1556 | } |
1557 | 1557 | |
1558 | - $showsize=0; |
|
1558 | + $showsize = 0; |
|
1559 | 1559 | if ($type == 'date') |
1560 | 1560 | { |
1561 | - $showsize=10; |
|
1562 | - $value=dol_print_date($value, 'day'); |
|
1561 | + $showsize = 10; |
|
1562 | + $value = dol_print_date($value, 'day'); |
|
1563 | 1563 | } |
1564 | 1564 | elseif ($type == 'datetime') |
1565 | 1565 | { |
1566 | - $showsize=19; |
|
1567 | - $value=dol_print_date($value, 'dayhour'); |
|
1566 | + $showsize = 19; |
|
1567 | + $value = dol_print_date($value, 'dayhour'); |
|
1568 | 1568 | } |
1569 | 1569 | elseif ($type == 'int') |
1570 | 1570 | { |
1571 | - $showsize=10; |
|
1571 | + $showsize = 10; |
|
1572 | 1572 | } |
1573 | 1573 | elseif ($type == 'double') |
1574 | 1574 | { |
1575 | 1575 | if (!empty($value)) { |
1576 | - $value=price($value); |
|
1576 | + $value = price($value); |
|
1577 | 1577 | } |
1578 | 1578 | } |
1579 | 1579 | elseif ($type == 'boolean') |
1580 | 1580 | { |
1581 | - $checked=''; |
|
1581 | + $checked = ''; |
|
1582 | 1582 | if (!empty($value)) { |
1583 | - $checked=' checked '; |
|
1583 | + $checked = ' checked '; |
|
1584 | 1584 | } |
1585 | - $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
1585 | + $value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>'; |
|
1586 | 1586 | } |
1587 | 1587 | elseif ($type == 'mail') |
1588 | 1588 | { |
1589 | - $value=dol_print_email($value, 0, 0, 0, 64, 1, 1); |
|
1589 | + $value = dol_print_email($value, 0, 0, 0, 64, 1, 1); |
|
1590 | 1590 | } |
1591 | 1591 | elseif ($type == 'url') |
1592 | 1592 | { |
1593 | - $value=dol_print_url($value,'_blank',32,1); |
|
1593 | + $value = dol_print_url($value, '_blank', 32, 1); |
|
1594 | 1594 | } |
1595 | 1595 | elseif ($type == 'phone') |
1596 | 1596 | { |
1597 | - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
1597 | + $value = dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
1598 | 1598 | } |
1599 | 1599 | elseif ($type == 'price') |
1600 | 1600 | { |
1601 | - $value=price($value, 0, $langs, 0, 0, -1, $conf->currency); |
|
1601 | + $value = price($value, 0, $langs, 0, 0, -1, $conf->currency); |
|
1602 | 1602 | } |
1603 | 1603 | elseif ($type == 'select') |
1604 | 1604 | { |
1605 | - if ($langfile && $param['options'][$value]) $value=$langs->trans($param['options'][$value]); |
|
1606 | - else $value=$param['options'][$value]; |
|
1605 | + if ($langfile && $param['options'][$value]) $value = $langs->trans($param['options'][$value]); |
|
1606 | + else $value = $param['options'][$value]; |
|
1607 | 1607 | } |
1608 | 1608 | elseif ($type == 'sellist') |
1609 | 1609 | { |
1610 | - $param_list=array_keys($param['options']); |
|
1610 | + $param_list = array_keys($param['options']); |
|
1611 | 1611 | $InfoFieldList = explode(":", $param_list[0]); |
1612 | 1612 | |
1613 | - $selectkey="rowid"; |
|
1614 | - $keyList='rowid'; |
|
1613 | + $selectkey = "rowid"; |
|
1614 | + $keyList = 'rowid'; |
|
1615 | 1615 | |
1616 | - if (count($InfoFieldList)>=3) |
|
1616 | + if (count($InfoFieldList) >= 3) |
|
1617 | 1617 | { |
1618 | 1618 | $selectkey = $InfoFieldList[2]; |
1619 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
1619 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
1620 | 1620 | } |
1621 | 1621 | |
1622 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
1623 | - if(is_array($fields_label)) { |
|
1624 | - $keyList .=', '; |
|
1622 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
1623 | + if (is_array($fields_label)) { |
|
1624 | + $keyList .= ', '; |
|
1625 | 1625 | $keyList .= implode(', ', $fields_label); |
1626 | 1626 | } |
1627 | 1627 | |
1628 | 1628 | $sql = 'SELECT '.$keyList; |
1629 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
1630 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
1629 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
1630 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
1631 | 1631 | { |
1632 | - $sql.= ' as main'; |
|
1632 | + $sql .= ' as main'; |
|
1633 | 1633 | } |
1634 | - if ($selectkey=='rowid' && empty($value)) { |
|
1635 | - $sql.= " WHERE ".$selectkey."=0"; |
|
1636 | - } elseif ($selectkey=='rowid') { |
|
1637 | - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
1638 | - }else { |
|
1639 | - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
1634 | + if ($selectkey == 'rowid' && empty($value)) { |
|
1635 | + $sql .= " WHERE ".$selectkey."=0"; |
|
1636 | + } elseif ($selectkey == 'rowid') { |
|
1637 | + $sql .= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
1638 | + } else { |
|
1639 | + $sql .= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
1640 | 1640 | } |
1641 | 1641 | |
1642 | 1642 | //$sql.= ' AND entity = '.$conf->entity; |
@@ -1645,38 +1645,38 @@ discard block |
||
1645 | 1645 | $resql = $this->db->query($sql); |
1646 | 1646 | if ($resql) |
1647 | 1647 | { |
1648 | - $value=''; // value was used, so now we reste it to use it to build final output |
|
1648 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
1649 | 1649 | |
1650 | 1650 | $obj = $this->db->fetch_object($resql); |
1651 | 1651 | |
1652 | 1652 | // Several field into label (eq table:code|libelle:rowid) |
1653 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
1653 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
1654 | 1654 | |
1655 | - if(is_array($fields_label) && count($fields_label)>1) |
|
1655 | + if (is_array($fields_label) && count($fields_label) > 1) |
|
1656 | 1656 | { |
1657 | 1657 | foreach ($fields_label as $field_toshow) |
1658 | 1658 | { |
1659 | - $translabel=''; |
|
1659 | + $translabel = ''; |
|
1660 | 1660 | if (!empty($obj->$field_toshow)) { |
1661 | - $translabel=$langs->trans($obj->$field_toshow); |
|
1661 | + $translabel = $langs->trans($obj->$field_toshow); |
|
1662 | 1662 | } |
1663 | - if ($translabel!=$field_toshow) { |
|
1664 | - $value.=dol_trunc($translabel,18).' '; |
|
1665 | - }else { |
|
1666 | - $value.=$obj->$field_toshow.' '; |
|
1663 | + if ($translabel != $field_toshow) { |
|
1664 | + $value .= dol_trunc($translabel, 18).' '; |
|
1665 | + } else { |
|
1666 | + $value .= $obj->$field_toshow.' '; |
|
1667 | 1667 | } |
1668 | 1668 | } |
1669 | 1669 | } |
1670 | 1670 | else |
1671 | 1671 | { |
1672 | - $translabel=''; |
|
1672 | + $translabel = ''; |
|
1673 | 1673 | if (!empty($obj->{$InfoFieldList[1]})) { |
1674 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
1674 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
1675 | 1675 | } |
1676 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
1677 | - $value=dol_trunc($translabel,18); |
|
1678 | - }else { |
|
1679 | - $value=$obj->{$InfoFieldList[1]}; |
|
1676 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
1677 | + $value = dol_trunc($translabel, 18); |
|
1678 | + } else { |
|
1679 | + $value = $obj->{$InfoFieldList[1]}; |
|
1680 | 1680 | } |
1681 | 1681 | } |
1682 | 1682 | } |
@@ -1684,20 +1684,20 @@ discard block |
||
1684 | 1684 | } |
1685 | 1685 | elseif ($type == 'radio') |
1686 | 1686 | { |
1687 | - $value=$param['options'][$value]; |
|
1687 | + $value = $param['options'][$value]; |
|
1688 | 1688 | } |
1689 | 1689 | elseif ($type == 'checkbox') |
1690 | 1690 | { |
1691 | - $value_arr=explode(',',$value); |
|
1692 | - $value=''; |
|
1693 | - $toprint=array(); |
|
1691 | + $value_arr = explode(',', $value); |
|
1692 | + $value = ''; |
|
1693 | + $toprint = array(); |
|
1694 | 1694 | if (is_array($value_arr)) |
1695 | 1695 | { |
1696 | 1696 | foreach ($value_arr as $keyval=>$valueval) { |
1697 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
1697 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
1698 | 1698 | } |
1699 | 1699 | } |
1700 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
1700 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
1701 | 1701 | } |
1702 | 1702 | elseif ($type == 'chkbxlst') |
1703 | 1703 | { |
@@ -1711,7 +1711,7 @@ discard block |
||
1711 | 1711 | |
1712 | 1712 | if (count($InfoFieldList) >= 3) { |
1713 | 1713 | $selectkey = $InfoFieldList[2]; |
1714 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
1714 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
1715 | 1715 | } |
1716 | 1716 | |
1717 | 1717 | $fields_label = explode('|', $InfoFieldList[1]); |
@@ -1720,74 +1720,74 @@ discard block |
||
1720 | 1720 | $keyList .= implode(', ', $fields_label); |
1721 | 1721 | } |
1722 | 1722 | |
1723 | - $sql = 'SELECT ' . $keyList; |
|
1724 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
1723 | + $sql = 'SELECT '.$keyList; |
|
1724 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
1725 | 1725 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
1726 | 1726 | $sql .= ' as main'; |
1727 | 1727 | } |
1728 | 1728 | // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
1729 | 1729 | // $sql.= ' AND entity = '.$conf->entity; |
1730 | 1730 | |
1731 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
1731 | + dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); |
|
1732 | 1732 | $resql = $this->db->query($sql); |
1733 | 1733 | if ($resql) { |
1734 | 1734 | $value = ''; // value was used, so now we reste it to use it to build final output |
1735 | - $toprint=array(); |
|
1736 | - while ( $obj = $this->db->fetch_object($resql) ) { |
|
1735 | + $toprint = array(); |
|
1736 | + while ($obj = $this->db->fetch_object($resql)) { |
|
1737 | 1737 | |
1738 | 1738 | // Several field into label (eq table:code|libelle:rowid) |
1739 | 1739 | $fields_label = explode('|', $InfoFieldList[1]); |
1740 | 1740 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
1741 | 1741 | if (is_array($fields_label) && count($fields_label) > 1) { |
1742 | - foreach ( $fields_label as $field_toshow ) { |
|
1742 | + foreach ($fields_label as $field_toshow) { |
|
1743 | 1743 | $translabel = ''; |
1744 | - if (! empty($obj->$field_toshow)) { |
|
1744 | + if (!empty($obj->$field_toshow)) { |
|
1745 | 1745 | $translabel = $langs->trans($obj->$field_toshow); |
1746 | 1746 | } |
1747 | 1747 | if ($translabel != $field_toshow) { |
1748 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
1748 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
1749 | 1749 | } else { |
1750 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
1750 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
1751 | 1751 | } |
1752 | 1752 | } |
1753 | 1753 | } else { |
1754 | 1754 | $translabel = ''; |
1755 | - if (! empty($obj->{$InfoFieldList[1]})) { |
|
1755 | + if (!empty($obj->{$InfoFieldList[1]})) { |
|
1756 | 1756 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
1757 | 1757 | } |
1758 | 1758 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
1759 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
1759 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
1760 | 1760 | } else { |
1761 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
1761 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
1762 | 1762 | } |
1763 | 1763 | } |
1764 | 1764 | } |
1765 | 1765 | } |
1766 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
1766 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
1767 | 1767 | } else { |
1768 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
1768 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
1769 | 1769 | } |
1770 | 1770 | } |
1771 | 1771 | elseif ($type == 'link') |
1772 | 1772 | { |
1773 | - $out=''; |
|
1773 | + $out = ''; |
|
1774 | 1774 | |
1775 | 1775 | // Only if something to display (perf) |
1776 | 1776 | if ($value) // If we have -1 here, pb is into sert, not into ouptu |
1777 | 1777 | { |
1778 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
1778 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
1779 | 1779 | |
1780 | 1780 | $InfoFieldList = explode(":", $param_list[0]); |
1781 | - $classname=$InfoFieldList[0]; |
|
1782 | - $classpath=$InfoFieldList[1]; |
|
1783 | - if (! empty($classpath)) |
|
1781 | + $classname = $InfoFieldList[0]; |
|
1782 | + $classpath = $InfoFieldList[1]; |
|
1783 | + if (!empty($classpath)) |
|
1784 | 1784 | { |
1785 | 1785 | dol_include_once($InfoFieldList[1]); |
1786 | 1786 | if ($classname && class_exists($classname)) |
1787 | 1787 | { |
1788 | 1788 | $object = new $classname($this->db); |
1789 | 1789 | $object->fetch($value); |
1790 | - $value=$object->getNomUrl(3); |
|
1790 | + $value = $object->getNomUrl(3); |
|
1791 | 1791 | } |
1792 | 1792 | } |
1793 | 1793 | else |
@@ -1799,24 +1799,24 @@ discard block |
||
1799 | 1799 | } |
1800 | 1800 | elseif ($type == 'text') |
1801 | 1801 | { |
1802 | - $value=dol_htmlentitiesbr($value); |
|
1802 | + $value = dol_htmlentitiesbr($value); |
|
1803 | 1803 | } |
1804 | 1804 | elseif ($type == 'html') |
1805 | 1805 | { |
1806 | - $value=dol_htmlentitiesbr($value); |
|
1806 | + $value = dol_htmlentitiesbr($value); |
|
1807 | 1807 | } |
1808 | 1808 | elseif ($type == 'password') |
1809 | 1809 | { |
1810 | - $value=dol_trunc(preg_replace('/./i','*',$value), 8, 'right', 'UTF-8', 1); |
|
1810 | + $value = dol_trunc(preg_replace('/./i', '*', $value), 8, 'right', 'UTF-8', 1); |
|
1811 | 1811 | } |
1812 | 1812 | else |
1813 | 1813 | { |
1814 | - $showsize=round($size); |
|
1815 | - if ($showsize > 48) $showsize=48; |
|
1814 | + $showsize = round($size); |
|
1815 | + if ($showsize > 48) $showsize = 48; |
|
1816 | 1816 | } |
1817 | 1817 | |
1818 | 1818 | //print $type.'-'.$size; |
1819 | - $out=$value; |
|
1819 | + $out = $value; |
|
1820 | 1820 | |
1821 | 1821 | return $out; |
1822 | 1822 | } |
@@ -1828,46 +1828,46 @@ discard block |
||
1828 | 1828 | * @param string $extrafieldsobjectkey If defined, use the new method to get extrafields data |
1829 | 1829 | * @return string Formated value |
1830 | 1830 | */ |
1831 | - function getAlignFlag($key, $extrafieldsobjectkey='') |
|
1831 | + function getAlignFlag($key, $extrafieldsobjectkey = '') |
|
1832 | 1832 | { |
1833 | - global $conf,$langs; |
|
1833 | + global $conf, $langs; |
|
1834 | 1834 | |
1835 | - if (! empty($extrafieldsobjectkey)) $type=$this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
1836 | - else $type=$this->attribute_type[$key]; |
|
1835 | + if (!empty($extrafieldsobjectkey)) $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
1836 | + else $type = $this->attribute_type[$key]; |
|
1837 | 1837 | |
1838 | - $align=''; |
|
1838 | + $align = ''; |
|
1839 | 1839 | |
1840 | 1840 | if ($type == 'date') |
1841 | 1841 | { |
1842 | - $align="center"; |
|
1842 | + $align = "center"; |
|
1843 | 1843 | } |
1844 | 1844 | elseif ($type == 'datetime') |
1845 | 1845 | { |
1846 | - $align="center"; |
|
1846 | + $align = "center"; |
|
1847 | 1847 | } |
1848 | 1848 | elseif ($type == 'int') |
1849 | 1849 | { |
1850 | - $align="right"; |
|
1850 | + $align = "right"; |
|
1851 | 1851 | } |
1852 | 1852 | elseif ($type == 'double') |
1853 | 1853 | { |
1854 | - $align="right"; |
|
1854 | + $align = "right"; |
|
1855 | 1855 | } |
1856 | 1856 | elseif ($type == 'boolean') |
1857 | 1857 | { |
1858 | - $align="center"; |
|
1858 | + $align = "center"; |
|
1859 | 1859 | } |
1860 | 1860 | elseif ($type == 'radio') |
1861 | 1861 | { |
1862 | - $align="center"; |
|
1862 | + $align = "center"; |
|
1863 | 1863 | } |
1864 | 1864 | elseif ($type == 'checkbox') |
1865 | 1865 | { |
1866 | - $align="center"; |
|
1866 | + $align = "center"; |
|
1867 | 1867 | } |
1868 | 1868 | elseif ($type == 'price') |
1869 | 1869 | { |
1870 | - $align="right"; |
|
1870 | + $align = "right"; |
|
1871 | 1871 | } |
1872 | 1872 | |
1873 | 1873 | return $align; |
@@ -1885,8 +1885,8 @@ discard block |
||
1885 | 1885 | global $langs; |
1886 | 1886 | |
1887 | 1887 | $out = '<tr class="trextrafieldseparator trextrafieldseparator'.$key.'"><td colspan="2"><strong>'; |
1888 | - $out.= $langs->trans($this->attributes[$object->table_element]['label'][$key]); |
|
1889 | - $out.= '</strong></td></tr>'; |
|
1888 | + $out .= $langs->trans($this->attributes[$object->table_element]['label'][$key]); |
|
1889 | + $out .= '</strong></td></tr>'; |
|
1890 | 1890 | return $out; |
1891 | 1891 | } |
1892 | 1892 | |
@@ -1898,20 +1898,20 @@ discard block |
||
1898 | 1898 | * @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset. |
1899 | 1899 | * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) |
1900 | 1900 | */ |
1901 | - function setOptionalsFromPost($extralabels, &$object, $onlykey='') |
|
1901 | + function setOptionalsFromPost($extralabels, &$object, $onlykey = '') |
|
1902 | 1902 | { |
1903 | 1903 | global $_POST, $langs; |
1904 | - $nofillrequired='';// For error when required field left blank |
|
1904 | + $nofillrequired = ''; // For error when required field left blank |
|
1905 | 1905 | $error_field_required = array(); |
1906 | 1906 | |
1907 | - if (is_array($this->attributes[$object->table_element]['label'])) $extralabels=$this->attributes[$object->table_element]['label']; |
|
1907 | + if (is_array($this->attributes[$object->table_element]['label'])) $extralabels = $this->attributes[$object->table_element]['label']; |
|
1908 | 1908 | |
1909 | 1909 | if (is_array($extralabels)) |
1910 | 1910 | { |
1911 | 1911 | // Get extra fields |
1912 | 1912 | foreach ($extralabels as $key => $value) |
1913 | 1913 | { |
1914 | - if (! empty($onlykey) && $key != $onlykey) continue; |
|
1914 | + if (!empty($onlykey) && $key != $onlykey) continue; |
|
1915 | 1915 | |
1916 | 1916 | $key_type = $this->attributes[$object->table_element]['type'][$key]; |
1917 | 1917 | if ($key_type == 'separate') continue; |
@@ -1932,7 +1932,7 @@ discard block |
||
1932 | 1932 | if ($this->attributes[$object->table_element]['required'][$key]) // Value is required |
1933 | 1933 | { |
1934 | 1934 | // Check if empty without using GETPOST, value can be alpha, int, array, etc... |
1935 | - if ((! is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $_POST["options_".$key] != '0') |
|
1935 | + if ((!is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $_POST["options_".$key] != '0') |
|
1936 | 1936 | || (is_array($_POST["options_".$key]) && empty($_POST["options_".$key]))) |
1937 | 1937 | { |
1938 | 1938 | //print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key]; |
@@ -1941,43 +1941,43 @@ discard block |
||
1941 | 1941 | } |
1942 | 1942 | } |
1943 | 1943 | |
1944 | - if (in_array($key_type,array('date'))) |
|
1944 | + if (in_array($key_type, array('date'))) |
|
1945 | 1945 | { |
1946 | 1946 | // Clean parameters |
1947 | 1947 | // TODO GMT date in memory must be GMT so we should add gm=true in parameters |
1948 | - $value_key=dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
|
1948 | + $value_key = dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
|
1949 | 1949 | } |
1950 | - elseif (in_array($key_type,array('datetime'))) |
|
1950 | + elseif (in_array($key_type, array('datetime'))) |
|
1951 | 1951 | { |
1952 | 1952 | // Clean parameters |
1953 | 1953 | // TODO GMT date in memory must be GMT so we should add gm=true in parameters |
1954 | - $value_key=dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
|
1954 | + $value_key = dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
|
1955 | 1955 | } |
1956 | - else if (in_array($key_type,array('checkbox','chkbxlst'))) |
|
1956 | + else if (in_array($key_type, array('checkbox', 'chkbxlst'))) |
|
1957 | 1957 | { |
1958 | - $value_arr=GETPOST("options_".$key, 'array'); // check if an array |
|
1958 | + $value_arr = GETPOST("options_".$key, 'array'); // check if an array |
|
1959 | 1959 | if (!empty($value_arr)) { |
1960 | - $value_key=implode($value_arr,','); |
|
1961 | - }else { |
|
1962 | - $value_key=''; |
|
1960 | + $value_key = implode($value_arr, ','); |
|
1961 | + } else { |
|
1962 | + $value_key = ''; |
|
1963 | 1963 | } |
1964 | 1964 | } |
1965 | - else if (in_array($key_type,array('price','double'))) |
|
1965 | + else if (in_array($key_type, array('price', 'double'))) |
|
1966 | 1966 | { |
1967 | - $value_arr=GETPOST("options_".$key, 'alpha'); |
|
1968 | - $value_key=price2num($value_arr); |
|
1967 | + $value_arr = GETPOST("options_".$key, 'alpha'); |
|
1968 | + $value_key = price2num($value_arr); |
|
1969 | 1969 | } |
1970 | 1970 | else |
1971 | 1971 | { |
1972 | - $value_key=GETPOST("options_".$key); |
|
1972 | + $value_key = GETPOST("options_".$key); |
|
1973 | 1973 | } |
1974 | 1974 | |
1975 | - $object->array_options["options_".$key]=$value_key; |
|
1975 | + $object->array_options["options_".$key] = $value_key; |
|
1976 | 1976 | } |
1977 | 1977 | |
1978 | 1978 | if ($nofillrequired) { |
1979 | 1979 | $langs->load('errors'); |
1980 | - setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ',$error_field_required), null, 'errors'); |
|
1980 | + setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ', $error_field_required), null, 'errors'); |
|
1981 | 1981 | return -1; |
1982 | 1982 | } |
1983 | 1983 | else { |
@@ -1997,7 +1997,7 @@ discard block |
||
1997 | 1997 | * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
1998 | 1998 | * @return array|int array_options set or 0 if no value |
1999 | 1999 | */ |
2000 | - function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix='', $keysuffix='') |
|
2000 | + function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix = '', $keysuffix = '') |
|
2001 | 2001 | { |
2002 | 2002 | global $_POST; |
2003 | 2003 | |
@@ -2023,29 +2023,29 @@ discard block |
||
2023 | 2023 | $key_type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
2024 | 2024 | } |
2025 | 2025 | |
2026 | - if (in_array($key_type,array('date','datetime'))) |
|
2026 | + if (in_array($key_type, array('date', 'datetime'))) |
|
2027 | 2027 | { |
2028 | 2028 | // Clean parameters |
2029 | - $value_key=dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]); |
|
2029 | + $value_key = dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]); |
|
2030 | 2030 | } |
2031 | - else if (in_array($key_type,array('checkbox', 'chkbxlst'))) |
|
2031 | + else if (in_array($key_type, array('checkbox', 'chkbxlst'))) |
|
2032 | 2032 | { |
2033 | - $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix); |
|
2033 | + $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix); |
|
2034 | 2034 | // Make sure we get an array even if there's only one checkbox |
2035 | - $value_arr=(array) $value_arr; |
|
2036 | - $value_key=implode(',', $value_arr); |
|
2035 | + $value_arr = (array) $value_arr; |
|
2036 | + $value_key = implode(',', $value_arr); |
|
2037 | 2037 | } |
2038 | - else if (in_array($key_type,array('price','double'))) |
|
2038 | + else if (in_array($key_type, array('price', 'double'))) |
|
2039 | 2039 | { |
2040 | - $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix); |
|
2041 | - $value_key=price2num($value_arr); |
|
2040 | + $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix); |
|
2041 | + $value_key = price2num($value_arr); |
|
2042 | 2042 | } |
2043 | 2043 | else |
2044 | 2044 | { |
2045 | - $value_key=GETPOST($keysuffix."options_".$key.$keyprefix); |
|
2045 | + $value_key = GETPOST($keysuffix."options_".$key.$keyprefix); |
|
2046 | 2046 | } |
2047 | 2047 | |
2048 | - $array_options[$keysuffix."options_".$key]=$value_key; // No keyprefix here. keyprefix is used only for read. |
|
2048 | + $array_options[$keysuffix."options_".$key] = $value_key; // No keyprefix here. keyprefix is used only for read. |
|
2049 | 2049 | } |
2050 | 2050 | |
2051 | 2051 | return $array_options; |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * @var string ID to identify managed object |
39 | 39 | */ |
40 | - public $element='events'; |
|
40 | + public $element = 'events'; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @var string Name of table without prefix where object is stored |
44 | 44 | */ |
45 | - public $table_element='events'; |
|
45 | + public $table_element = 'events'; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @var int ID |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * @var string Error code (or message) |
59 | 59 | */ |
60 | - public $error=''; |
|
60 | + public $error = ''; |
|
61 | 61 | |
62 | 62 | public $tms; |
63 | 63 | public $type; |
@@ -75,20 +75,20 @@ discard block |
||
75 | 75 | public $description; |
76 | 76 | |
77 | 77 | // List of all Audit/Security events supported by triggers |
78 | - public $eventstolog=array( |
|
79 | - array('id'=>'USER_LOGIN', 'test'=>1), |
|
80 | - array('id'=>'USER_LOGIN_FAILED', 'test'=>1), |
|
81 | - array('id'=>'USER_LOGOUT', 'test'=>1), |
|
82 | - array('id'=>'USER_CREATE', 'test'=>1), |
|
83 | - array('id'=>'USER_MODIFY', 'test'=>1), |
|
84 | - array('id'=>'USER_NEW_PASSWORD', 'test'=>1), |
|
85 | - array('id'=>'USER_ENABLEDISABLE', 'test'=>1), |
|
86 | - array('id'=>'USER_DELETE', 'test'=>1), |
|
78 | + public $eventstolog = array( |
|
79 | + array('id'=>'USER_LOGIN', 'test'=>1), |
|
80 | + array('id'=>'USER_LOGIN_FAILED', 'test'=>1), |
|
81 | + array('id'=>'USER_LOGOUT', 'test'=>1), |
|
82 | + array('id'=>'USER_CREATE', 'test'=>1), |
|
83 | + array('id'=>'USER_MODIFY', 'test'=>1), |
|
84 | + array('id'=>'USER_NEW_PASSWORD', 'test'=>1), |
|
85 | + array('id'=>'USER_ENABLEDISABLE', 'test'=>1), |
|
86 | + array('id'=>'USER_DELETE', 'test'=>1), |
|
87 | 87 | /* array('id'=>'USER_SETINGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY |
88 | 88 | array('id'=>'USER_REMOVEFROMGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY */ |
89 | - array('id'=>'GROUP_CREATE', 'test'=>1), |
|
90 | - array('id'=>'GROUP_MODIFY', 'test'=>1), |
|
91 | - array('id'=>'GROUP_DELETE', 'test'=>1), |
|
89 | + array('id'=>'GROUP_CREATE', 'test'=>1), |
|
90 | + array('id'=>'GROUP_MODIFY', 'test'=>1), |
|
91 | + array('id'=>'GROUP_DELETE', 'test'=>1), |
|
92 | 92 | /* array('id'=>'ACTION_CREATE', 'test'=>$conf->societe->enabled), |
93 | 93 | array('id'=>'COMPANY_CREATE', 'test'=>$conf->societe->enabled), |
94 | 94 | array('id'=>'CONTRACT_VALIDATE', 'test'=>$conf->contrat->enabled), |
@@ -136,33 +136,33 @@ discard block |
||
136 | 136 | global $conf, $langs; |
137 | 137 | |
138 | 138 | // Clean parameters |
139 | - $this->description=trim($this->description); |
|
140 | - if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT']; |
|
139 | + $this->description = trim($this->description); |
|
140 | + if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent = $_SERVER['HTTP_USER_AGENT']; |
|
141 | 141 | |
142 | 142 | // Check parameters |
143 | - if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; } |
|
143 | + if (empty($this->description)) { $this->error = 'ErrorBadValueForParameterCreateEventDesc'; return -1; } |
|
144 | 144 | |
145 | 145 | // Insert request |
146 | 146 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."events("; |
147 | - $sql.= "type,"; |
|
148 | - $sql.= "entity,"; |
|
149 | - $sql.= "ip,"; |
|
150 | - $sql.= "user_agent,"; |
|
151 | - $sql.= "dateevent,"; |
|
152 | - $sql.= "fk_user,"; |
|
153 | - $sql.= "description"; |
|
154 | - $sql.= ") VALUES ("; |
|
155 | - $sql.= " '".$this->db->escape($this->type)."',"; |
|
156 | - $sql.= " ".$conf->entity.","; |
|
157 | - $sql.= " '".$this->db->escape(getUserRemoteIP())."',"; |
|
158 | - $sql.= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent,250))."'" : 'NULL').","; |
|
159 | - $sql.= " '".$this->db->idate($this->dateevent)."',"; |
|
160 | - $sql.= " ".($user->id?"'".$this->db->escape($user->id)."'":'NULL').","; |
|
161 | - $sql.= " '".$this->db->escape(dol_trunc($this->description,250))."'"; |
|
162 | - $sql.= ")"; |
|
147 | + $sql .= "type,"; |
|
148 | + $sql .= "entity,"; |
|
149 | + $sql .= "ip,"; |
|
150 | + $sql .= "user_agent,"; |
|
151 | + $sql .= "dateevent,"; |
|
152 | + $sql .= "fk_user,"; |
|
153 | + $sql .= "description"; |
|
154 | + $sql .= ") VALUES ("; |
|
155 | + $sql .= " '".$this->db->escape($this->type)."',"; |
|
156 | + $sql .= " ".$conf->entity.","; |
|
157 | + $sql .= " '".$this->db->escape(getUserRemoteIP())."',"; |
|
158 | + $sql .= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent, 250))."'" : 'NULL').","; |
|
159 | + $sql .= " '".$this->db->idate($this->dateevent)."',"; |
|
160 | + $sql .= " ".($user->id ? "'".$this->db->escape($user->id)."'" : 'NULL').","; |
|
161 | + $sql .= " '".$this->db->escape(dol_trunc($this->description, 250))."'"; |
|
162 | + $sql .= ")"; |
|
163 | 163 | |
164 | 164 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
165 | - $resql=$this->db->query($sql); |
|
165 | + $resql = $this->db->query($sql); |
|
166 | 166 | if ($resql) |
167 | 167 | { |
168 | 168 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events"); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | } |
171 | 171 | else |
172 | 172 | { |
173 | - $this->error="Error ".$this->db->lasterror(); |
|
173 | + $this->error = "Error ".$this->db->lasterror(); |
|
174 | 174 | return -1; |
175 | 175 | } |
176 | 176 | } |
@@ -183,30 +183,30 @@ discard block |
||
183 | 183 | * @param int $notrigger 0=no, 1=yes (no update trigger) |
184 | 184 | * @return int <0 if KO, >0 if OK |
185 | 185 | */ |
186 | - function update($user=null, $notrigger=0) |
|
186 | + function update($user = null, $notrigger = 0) |
|
187 | 187 | { |
188 | 188 | global $conf, $langs; |
189 | 189 | |
190 | 190 | // Clean parameters |
191 | - $this->id=trim($this->id); |
|
192 | - $this->type=trim($this->type); |
|
193 | - $this->description=trim($this->description); |
|
191 | + $this->id = trim($this->id); |
|
192 | + $this->type = trim($this->type); |
|
193 | + $this->description = trim($this->description); |
|
194 | 194 | |
195 | 195 | // Check parameters |
196 | 196 | // Put here code to add control on parameters values |
197 | 197 | |
198 | 198 | // Update request |
199 | 199 | $sql = "UPDATE ".MAIN_DB_PREFIX."events SET"; |
200 | - $sql.= " type='".$this->db->escape($this->type)."',"; |
|
201 | - $sql.= " dateevent='".$this->db->idate($this->dateevent)."',"; |
|
202 | - $sql.= " description='".$this->db->escape($this->description)."'"; |
|
203 | - $sql.= " WHERE rowid=".$this->id; |
|
200 | + $sql .= " type='".$this->db->escape($this->type)."',"; |
|
201 | + $sql .= " dateevent='".$this->db->idate($this->dateevent)."',"; |
|
202 | + $sql .= " description='".$this->db->escape($this->description)."'"; |
|
203 | + $sql .= " WHERE rowid=".$this->id; |
|
204 | 204 | |
205 | 205 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
206 | 206 | $resql = $this->db->query($sql); |
207 | - if (! $resql) |
|
207 | + if (!$resql) |
|
208 | 208 | { |
209 | - $this->error="Error ".$this->db->lasterror(); |
|
209 | + $this->error = "Error ".$this->db->lasterror(); |
|
210 | 210 | return -1; |
211 | 211 | } |
212 | 212 | return 1; |
@@ -220,31 +220,31 @@ discard block |
||
220 | 220 | * @param User $user User that load |
221 | 221 | * @return int <0 if KO, >0 if OK |
222 | 222 | */ |
223 | - function fetch($id, $user=null) |
|
223 | + function fetch($id, $user = null) |
|
224 | 224 | { |
225 | 225 | global $langs; |
226 | 226 | |
227 | 227 | $sql = "SELECT"; |
228 | - $sql.= " t.rowid,"; |
|
229 | - $sql.= " t.tms,"; |
|
230 | - $sql.= " t.type,"; |
|
231 | - $sql.= " t.entity,"; |
|
232 | - $sql.= " t.dateevent,"; |
|
233 | - $sql.= " t.description,"; |
|
234 | - $sql.= " t.ip,"; |
|
235 | - $sql.= " t.user_agent"; |
|
236 | - $sql.= " FROM ".MAIN_DB_PREFIX."events as t"; |
|
237 | - $sql.= " WHERE t.rowid = ".$id; |
|
228 | + $sql .= " t.rowid,"; |
|
229 | + $sql .= " t.tms,"; |
|
230 | + $sql .= " t.type,"; |
|
231 | + $sql .= " t.entity,"; |
|
232 | + $sql .= " t.dateevent,"; |
|
233 | + $sql .= " t.description,"; |
|
234 | + $sql .= " t.ip,"; |
|
235 | + $sql .= " t.user_agent"; |
|
236 | + $sql .= " FROM ".MAIN_DB_PREFIX."events as t"; |
|
237 | + $sql .= " WHERE t.rowid = ".$id; |
|
238 | 238 | |
239 | 239 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
240 | - $resql=$this->db->query($sql); |
|
240 | + $resql = $this->db->query($sql); |
|
241 | 241 | if ($resql) |
242 | 242 | { |
243 | 243 | if ($this->db->num_rows($resql)) |
244 | 244 | { |
245 | 245 | $obj = $this->db->fetch_object($resql); |
246 | 246 | |
247 | - $this->id = $obj->rowid; |
|
247 | + $this->id = $obj->rowid; |
|
248 | 248 | $this->tms = $this->db->jdate($obj->tms); |
249 | 249 | $this->type = $obj->type; |
250 | 250 | $this->entity = $obj->entity; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | } |
260 | 260 | else |
261 | 261 | { |
262 | - $this->error="Error ".$this->db->lasterror(); |
|
262 | + $this->error = "Error ".$this->db->lasterror(); |
|
263 | 263 | return -1; |
264 | 264 | } |
265 | 265 | } |
@@ -276,13 +276,13 @@ discard block |
||
276 | 276 | global $conf, $langs; |
277 | 277 | |
278 | 278 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."events"; |
279 | - $sql.= " WHERE rowid=".$this->id; |
|
279 | + $sql .= " WHERE rowid=".$this->id; |
|
280 | 280 | |
281 | 281 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
282 | 282 | $resql = $this->db->query($sql); |
283 | - if (! $resql) |
|
283 | + if (!$resql) |
|
284 | 284 | { |
285 | - $this->error="Error ".$this->db->lasterror(); |
|
285 | + $this->error = "Error ".$this->db->lasterror(); |
|
286 | 286 | return -1; |
287 | 287 | } |
288 | 288 | |
@@ -299,11 +299,11 @@ discard block |
||
299 | 299 | */ |
300 | 300 | function initAsSpecimen() |
301 | 301 | { |
302 | - $this->id=0; |
|
302 | + $this->id = 0; |
|
303 | 303 | |
304 | - $this->tms=time(); |
|
305 | - $this->type=''; |
|
306 | - $this->dateevent=time(); |
|
307 | - $this->description='This is a specimen event'; |
|
304 | + $this->tms = time(); |
|
305 | + $this->type = ''; |
|
306 | + $this->dateevent = time(); |
|
307 | + $this->description = 'This is a specimen event'; |
|
308 | 308 | } |
309 | 309 | } |
@@ -99,18 +99,18 @@ discard block |
||
99 | 99 | // Put here code to add control on parameters values |
100 | 100 | |
101 | 101 | // Insert request |
102 | - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; |
|
102 | + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; |
|
103 | 103 | |
104 | - $sql.= 'code,'; |
|
105 | - $sql.= 'label'; |
|
106 | - $sql.= 'active'; |
|
104 | + $sql .= 'code,'; |
|
105 | + $sql .= 'label'; |
|
106 | + $sql .= 'active'; |
|
107 | 107 | |
108 | 108 | |
109 | 109 | $sql .= ') VALUES ('; |
110 | 110 | |
111 | - $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").','; |
|
112 | - $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; |
|
113 | - $sql .= ' '.(! isset($this->active)?'NULL':$this->active); |
|
111 | + $sql .= ' '.(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").','; |
|
112 | + $sql .= ' '.(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").','; |
|
113 | + $sql .= ' '.(!isset($this->active) ? 'NULL' : $this->active); |
|
114 | 114 | |
115 | 115 | |
116 | 116 | $sql .= ')'; |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | |
120 | 120 | $resql = $this->db->query($sql); |
121 | 121 | if (!$resql) { |
122 | - $error ++; |
|
123 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
124 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
122 | + $error++; |
|
123 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
124 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | if (!$error) { |
128 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
128 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
129 | 129 | |
130 | 130 | // Uncomment this and change MYOBJECT to your own tag if you |
131 | 131 | // want this action to call a trigger. |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | if ($error) { |
143 | 143 | $this->db->rollback(); |
144 | 144 | |
145 | - return - 1 * $error; |
|
145 | + return -1 * $error; |
|
146 | 146 | } else { |
147 | 147 | $this->db->commit(); |
148 | 148 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return int <0 if KO, 0 if not found, >0 if OK |
161 | 161 | */ |
162 | - public function fetch($id,$code='',$label='') |
|
162 | + public function fetch($id, $code = '', $label = '') |
|
163 | 163 | { |
164 | 164 | dol_syslog(__METHOD__, LOG_DEBUG); |
165 | 165 | |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | $sql .= " t.active"; |
172 | 172 | |
173 | 173 | |
174 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
|
175 | - if ($id) $sql.= " WHERE t.id = ".$id; |
|
176 | - elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
177 | - elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
174 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
|
175 | + if ($id) $sql .= " WHERE t.id = ".$id; |
|
176 | + elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
177 | + elseif ($label) $sql .= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
178 | 178 | |
179 | 179 | |
180 | 180 | $resql = $this->db->query($sql); |
@@ -204,10 +204,10 @@ discard block |
||
204 | 204 | return 0; |
205 | 205 | } |
206 | 206 | } else { |
207 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
208 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
207 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
208 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
209 | 209 | |
210 | - return - 1; |
|
210 | + return -1; |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return int <0 if KO, >0 if OK |
225 | 225 | */ |
226 | - public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') |
|
226 | + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') |
|
227 | 227 | { |
228 | 228 | dol_syslog(__METHOD__, LOG_DEBUG); |
229 | 229 | |
@@ -235,24 +235,24 @@ discard block |
||
235 | 235 | $sql .= " t.active"; |
236 | 236 | |
237 | 237 | |
238 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; |
|
238 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
|
239 | 239 | |
240 | 240 | // Manage filter |
241 | 241 | $sqlwhere = array(); |
242 | 242 | if (count($filter) > 0) { |
243 | 243 | foreach ($filter as $key => $value) { |
244 | - $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; |
|
244 | + $sqlwhere [] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | 248 | if (count($sqlwhere) > 0) { |
249 | - $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); |
|
249 | + $sql .= ' WHERE '.implode(' '.$filtermode.' ', $sqlwhere); |
|
250 | 250 | } |
251 | 251 | if (!empty($sortfield)) { |
252 | - $sql .= $this->db->order($sortfield,$sortorder); |
|
252 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
253 | 253 | } |
254 | 254 | if (!empty($limit)) { |
255 | - $sql .= ' ' . $this->db->plimit($limit, $offset); |
|
255 | + $sql .= ' '.$this->db->plimit($limit, $offset); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | $resql = $this->db->query($sql); |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | |
273 | 273 | return $num; |
274 | 274 | } else { |
275 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
276 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
275 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
276 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
277 | 277 | |
278 | - return - 1; |
|
278 | + return -1; |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
@@ -309,22 +309,22 @@ discard block |
||
309 | 309 | // Put here code to add a control on parameters values |
310 | 310 | |
311 | 311 | // Update request |
312 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; |
|
312 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
313 | 313 | |
314 | - $sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").','; |
|
315 | - $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").','; |
|
316 | - $sql .= ' active = '.(isset($this->active)?$this->active:"null"); |
|
314 | + $sql .= ' code = '.(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").','; |
|
315 | + $sql .= ' label = '.(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").','; |
|
316 | + $sql .= ' active = '.(isset($this->active) ? $this->active : "null"); |
|
317 | 317 | |
318 | 318 | |
319 | - $sql .= ' WHERE rowid=' . $this->id; |
|
319 | + $sql .= ' WHERE rowid='.$this->id; |
|
320 | 320 | |
321 | 321 | $this->db->begin(); |
322 | 322 | |
323 | 323 | $resql = $this->db->query($sql); |
324 | 324 | if (!$resql) { |
325 | - $error ++; |
|
326 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
327 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
325 | + $error++; |
|
326 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
327 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | // Uncomment this and change MYOBJECT to your own tag if you |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | if ($error) { |
342 | 342 | $this->db->rollback(); |
343 | 343 | |
344 | - return - 1 * $error; |
|
344 | + return -1 * $error; |
|
345 | 345 | } else { |
346 | 346 | $this->db->commit(); |
347 | 347 | |
@@ -378,14 +378,14 @@ discard block |
||
378 | 378 | // If you need to delete child tables to, you can insert them here |
379 | 379 | |
380 | 380 | if (!$error) { |
381 | - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; |
|
382 | - $sql .= ' WHERE rowid=' . $this->id; |
|
381 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
382 | + $sql .= ' WHERE rowid='.$this->id; |
|
383 | 383 | |
384 | 384 | $resql = $this->db->query($sql); |
385 | 385 | if (!$resql) { |
386 | - $error ++; |
|
387 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
388 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
386 | + $error++; |
|
387 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
388 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | if ($error) { |
394 | 394 | $this->db->rollback(); |
395 | 395 | |
396 | - return - 1 * $error; |
|
396 | + return -1 * $error; |
|
397 | 397 | } else { |
398 | 398 | $this->db->commit(); |
399 | 399 | |
@@ -431,9 +431,9 @@ discard block |
||
431 | 431 | |
432 | 432 | // Other options |
433 | 433 | if ($result < 0) { |
434 | - $error ++; |
|
434 | + $error++; |
|
435 | 435 | $this->errors = $object->errors; |
436 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
436 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | // End |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | } else { |
445 | 445 | $this->db->rollback(); |
446 | 446 | |
447 | - return - 1; |
|
447 | + return -1; |
|
448 | 448 | } |
449 | 449 | } |
450 | 450 |