@@ -45,7 +45,7 @@ |
||
45 | 45 | * |
46 | 46 | * @param DoliDB $db Database handler |
47 | 47 | * @param int $socid Id third party |
48 | - * @param mixed $userid Id user for filter or array of user ids |
|
48 | + * @param integer $userid Id user for filter or array of user ids |
|
49 | 49 | * @return void |
50 | 50 | */ |
51 | 51 | function __construct($db, $socid=0, $userid=0) |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | * \ingroup factures |
23 | 23 | * \brief Fichier de la classe de gestion des stats des deplacement et notes de frais |
24 | 24 | */ |
25 | -include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php'; |
|
26 | -include_once DOL_DOCUMENT_ROOT . '/compta/deplacement/class/deplacement.class.php'; |
|
25 | +include_once DOL_DOCUMENT_ROOT.'/core/class/stats.class.php'; |
|
26 | +include_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * \class DeplacementStats |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param mixed $userid Id user for filter or array of user ids |
49 | 49 | * @return void |
50 | 50 | */ |
51 | - function __construct($db, $socid=0, $userid=0) |
|
51 | + function __construct($db, $socid = 0, $userid = 0) |
|
52 | 52 | { |
53 | 53 | global $conf; |
54 | 54 | |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | $this->socid = $socid; |
57 | 57 | $this->userid = $userid; |
58 | 58 | |
59 | - $object=new Deplacement($this->db); |
|
59 | + $object = new Deplacement($this->db); |
|
60 | 60 | $this->from = MAIN_DB_PREFIX.$object->table_element; |
61 | - $this->field='km'; |
|
61 | + $this->field = 'km'; |
|
62 | 62 | |
63 | 63 | $this->where = " fk_statut > 0"; |
64 | - $this->where.= " AND entity = ".$conf->entity; |
|
64 | + $this->where .= " AND entity = ".$conf->entity; |
|
65 | 65 | if ($this->socid) |
66 | 66 | { |
67 | - $this->where.=" AND fk_soc = ".$this->socid; |
|
67 | + $this->where .= " AND fk_soc = ".$this->socid; |
|
68 | 68 | } |
69 | - if (is_array($this->userid) && count($this->userid) > 0) $this->where.=' AND fk_user IN ('.join(',',$this->userid).')'; |
|
70 | - else if ($this->userid > 0) $this->where.=' AND fk_user = '.$this->userid; |
|
69 | + if (is_array($this->userid) && count($this->userid) > 0) $this->where .= ' AND fk_user IN ('.join(',', $this->userid).')'; |
|
70 | + else if ($this->userid > 0) $this->where .= ' AND fk_user = '.$this->userid; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | function getNbByYear() |
80 | 80 | { |
81 | 81 | $sql = "SELECT YEAR(dated) as dm, count(*)"; |
82 | - $sql.= " FROM ".$this->from; |
|
83 | - $sql.= " GROUP BY dm DESC"; |
|
84 | - $sql.= " WHERE ".$this->where; |
|
82 | + $sql .= " FROM ".$this->from; |
|
83 | + $sql .= " GROUP BY dm DESC"; |
|
84 | + $sql .= " WHERE ".$this->where; |
|
85 | 85 | |
86 | 86 | return $this->_getNbByYear($sql); |
87 | 87 | } |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | function getNbByMonth($year) |
97 | 97 | { |
98 | 98 | $sql = "SELECT MONTH(dated) as dm, count(*)"; |
99 | - $sql.= " FROM ".$this->from; |
|
100 | - $sql.= " WHERE YEAR(dated) = ".$year; |
|
101 | - $sql.= " AND ".$this->where; |
|
102 | - $sql.= " GROUP BY dm"; |
|
103 | - $sql.= $this->db->order('dm','DESC'); |
|
99 | + $sql .= " FROM ".$this->from; |
|
100 | + $sql .= " WHERE YEAR(dated) = ".$year; |
|
101 | + $sql .= " AND ".$this->where; |
|
102 | + $sql .= " GROUP BY dm"; |
|
103 | + $sql .= $this->db->order('dm', 'DESC'); |
|
104 | 104 | |
105 | - $res=$this->_getNbByMonth($year, $sql); |
|
105 | + $res = $this->_getNbByMonth($year, $sql); |
|
106 | 106 | //var_dump($res);print '<br>'; |
107 | 107 | return $res; |
108 | 108 | } |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | function getAmountByMonth($year) |
118 | 118 | { |
119 | 119 | $sql = "SELECT date_format(dated,'%m') as dm, sum(".$this->field.")"; |
120 | - $sql.= " FROM ".$this->from; |
|
121 | - $sql.= " WHERE date_format(dated,'%Y') = '".$year."'"; |
|
122 | - $sql.= " AND ".$this->where; |
|
123 | - $sql.= " GROUP BY dm"; |
|
124 | - $sql.= $this->db->order('dm','DESC'); |
|
120 | + $sql .= " FROM ".$this->from; |
|
121 | + $sql .= " WHERE date_format(dated,'%Y') = '".$year."'"; |
|
122 | + $sql .= " AND ".$this->where; |
|
123 | + $sql .= " GROUP BY dm"; |
|
124 | + $sql .= $this->db->order('dm', 'DESC'); |
|
125 | 125 | |
126 | - $res=$this->_getAmountByMonth($year, $sql); |
|
126 | + $res = $this->_getAmountByMonth($year, $sql); |
|
127 | 127 | //var_dump($res);print '<br>'; |
128 | 128 | return $res; |
129 | 129 | } |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | function getAverageByMonth($year) |
138 | 138 | { |
139 | 139 | $sql = "SELECT date_format(dated,'%m') as dm, avg(".$this->field.")"; |
140 | - $sql.= " FROM ".$this->from; |
|
141 | - $sql.= " WHERE date_format(dated,'%Y') = '".$year."'"; |
|
142 | - $sql.= " AND ".$this->where; |
|
143 | - $sql.= " GROUP BY dm"; |
|
144 | - $sql.= $this->db->order('dm','DESC'); |
|
140 | + $sql .= " FROM ".$this->from; |
|
141 | + $sql .= " WHERE date_format(dated,'%Y') = '".$year."'"; |
|
142 | + $sql .= " AND ".$this->where; |
|
143 | + $sql .= " GROUP BY dm"; |
|
144 | + $sql .= $this->db->order('dm', 'DESC'); |
|
145 | 145 | |
146 | 146 | return $this->_getAverageByMonth($year, $sql); |
147 | 147 | } |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | function getAllByYear() |
155 | 155 | { |
156 | 156 | $sql = "SELECT date_format(dated,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; |
157 | - $sql.= " FROM ".$this->from; |
|
158 | - $sql.= " WHERE ".$this->where; |
|
159 | - $sql.= " GROUP BY year"; |
|
160 | - $sql.= $this->db->order('year','DESC'); |
|
157 | + $sql .= " FROM ".$this->from; |
|
158 | + $sql .= " WHERE ".$this->where; |
|
159 | + $sql .= " GROUP BY year"; |
|
160 | + $sql .= $this->db->order('year', 'DESC'); |
|
161 | 161 | |
162 | 162 | return $this->_getAllByYear($sql); |
163 | 163 | } |
@@ -1285,7 +1285,7 @@ discard block |
||
1285 | 1285 | * @param int $info_bits Bits de type de lignes |
1286 | 1286 | * @param int $fk_fournprice Fourn price id |
1287 | 1287 | * @param int $pa_ht Buying price HT |
1288 | - * @param array $array_options extrafields array |
|
1288 | + * @param integer $array_options extrafields array |
|
1289 | 1289 | * @param string $fk_unit Code of the unit to use. Null to use the default one |
1290 | 1290 | * @return int <0 si erreur, >0 si ok |
1291 | 1291 | */ |
@@ -1474,7 +1474,7 @@ discard block |
||
1474 | 1474 | * @param int $info_bits Bits de type de lignes |
1475 | 1475 | * @param int $fk_fournprice Fourn price id |
1476 | 1476 | * @param int $pa_ht Buying price HT |
1477 | - * @param array $array_options extrafields array |
|
1477 | + * @param integer $array_options extrafields array |
|
1478 | 1478 | * @param string $fk_unit Code of the unit to use. Null to use the default one |
1479 | 1479 | * @return int < 0 si erreur, > 0 si ok |
1480 | 1480 | */ |
@@ -30,22 +30,22 @@ discard block |
||
30 | 30 | * \brief File of class to manage contracts |
31 | 31 | */ |
32 | 32 | |
33 | -require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; |
|
33 | +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; |
|
34 | 34 | require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php"; |
35 | -require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php'; |
|
36 | -require_once DOL_DOCUMENT_ROOT . '/margin/lib/margins.lib.php'; |
|
35 | +require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
|
36 | +require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php'; |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Class to manage contracts |
40 | 40 | */ |
41 | 41 | class Contrat extends CommonObject |
42 | 42 | { |
43 | - public $element='contrat'; |
|
44 | - public $table_element='contrat'; |
|
45 | - public $table_element_line='contratdet'; |
|
46 | - public $fk_element='fk_contrat'; |
|
47 | - protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
48 | - public $picto='contract'; |
|
43 | + public $element = 'contrat'; |
|
44 | + public $table_element = 'contrat'; |
|
45 | + public $table_element_line = 'contratdet'; |
|
46 | + public $fk_element = 'fk_contrat'; |
|
47 | + protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
48 | + public $picto = 'contract'; |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * {@inheritdoc} |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | * @var int |
70 | 70 | */ |
71 | 71 | var $socid; |
72 | - var $societe; // Objet societe |
|
72 | + var $societe; // Objet societe |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Status of the contract |
76 | 76 | * @var int |
77 | 77 | */ |
78 | - var $statut=0; // 0=Draft, |
|
78 | + var $statut = 0; // 0=Draft, |
|
79 | 79 | var $product; |
80 | 80 | |
81 | 81 | /** |
@@ -135,18 +135,18 @@ discard block |
||
135 | 135 | */ |
136 | 136 | var $fk_projet; |
137 | 137 | |
138 | - var $extraparams=array(); |
|
138 | + var $extraparams = array(); |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * @var ContratLigne[] Contract lines |
142 | 142 | */ |
143 | - var $lines=array(); |
|
143 | + var $lines = array(); |
|
144 | 144 | |
145 | 145 | /** |
146 | 146 | * Maps ContratLigne IDs to $this->lines indexes |
147 | 147 | * @var int[] |
148 | 148 | */ |
149 | - protected $lines_id_index_mapper=array(); |
|
149 | + protected $lines_id_index_mapper = array(); |
|
150 | 150 | |
151 | 151 | |
152 | 152 | /** |
@@ -185,26 +185,26 @@ discard block |
||
185 | 185 | $dir = dol_buildpath($reldir."core/modules/contract/"); |
186 | 186 | |
187 | 187 | // Load file with numbering class (if found) |
188 | - $mybool|=@include_once $dir.$file; |
|
188 | + $mybool |= @include_once $dir.$file; |
|
189 | 189 | } |
190 | 190 | |
191 | - if (! $mybool) |
|
191 | + if (!$mybool) |
|
192 | 192 | { |
193 | - dol_print_error('',"Failed to include file ".$file); |
|
193 | + dol_print_error('', "Failed to include file ".$file); |
|
194 | 194 | return ''; |
195 | 195 | } |
196 | 196 | |
197 | 197 | $obj = new $classname(); |
198 | - $numref = $obj->getNextValue($soc,$this); |
|
198 | + $numref = $obj->getNextValue($soc, $this); |
|
199 | 199 | |
200 | - if ( $numref != "") |
|
200 | + if ($numref != "") |
|
201 | 201 | { |
202 | 202 | return $numref; |
203 | 203 | } |
204 | 204 | else |
205 | 205 | { |
206 | 206 | $this->error = $obj->error; |
207 | - dol_print_error($db,get_class($this)."::getNextValue ".$obj->error); |
|
207 | + dol_print_error($db, get_class($this)."::getNextValue ".$obj->error); |
|
208 | 208 | return ""; |
209 | 209 | } |
210 | 210 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @param string $comment A comment typed by user |
227 | 227 | * @return int <0 if KO, >0 if OK |
228 | 228 | */ |
229 | - function active_line($user, $line_id, $date, $date_end='', $comment='') |
|
229 | + function active_line($user, $line_id, $date, $date_end = '', $comment = '') |
|
230 | 230 | { |
231 | 231 | return $this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date, $date_end, $comment); |
232 | 232 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param string $comment A comment typed by user |
242 | 242 | * @return int <0 if KO, >0 if OK |
243 | 243 | */ |
244 | - function close_line($user, $line_id, $date_end, $comment='') |
|
244 | + function close_line($user, $line_id, $date_end, $comment = '') |
|
245 | 245 | { |
246 | 246 | return $this->lines[$this->lines_id_index_mapper[$line_id]]->close_line($user, $date_end, $comment); |
247 | 247 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * @param int|string $date_start Date start (now if empty) |
255 | 255 | * @return int <0 if KO, >0 if OK |
256 | 256 | */ |
257 | - function activateAll($user, $date_start='') |
|
257 | + function activateAll($user, $date_start = '') |
|
258 | 258 | { |
259 | 259 | if (empty($date_start)) $date_start = dol_now(); |
260 | 260 | |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | // Load lines |
264 | 264 | $this->fetch_lines(); |
265 | 265 | |
266 | - $ok=true; |
|
267 | - foreach($this->lines as $contratline) |
|
266 | + $ok = true; |
|
267 | + foreach ($this->lines as $contratline) |
|
268 | 268 | { |
269 | 269 | // Open lines not already open |
270 | 270 | if ($contratline->statut != 4) |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $result = $contratline->active_line($user, $date_start, -1); |
273 | 273 | if ($result < 0) |
274 | 274 | { |
275 | - $ok=false; |
|
275 | + $ok = false; |
|
276 | 276 | break; |
277 | 277 | } |
278 | 278 | } |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | |
281 | 281 | if ($this->statut == 0) |
282 | 282 | { |
283 | - $result=$this->validate($user); |
|
284 | - if ($result < 0) $ok=false; |
|
283 | + $result = $this->validate($user); |
|
284 | + if ($result < 0) $ok = false; |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | if ($ok) |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | } |
292 | 292 | else |
293 | 293 | { |
294 | - dol_print_error($this->db,'Error in activateAll function'); |
|
294 | + dol_print_error($this->db, 'Error in activateAll function'); |
|
295 | 295 | $this->db->rollback(); |
296 | 296 | return -1; |
297 | 297 | } |
@@ -310,19 +310,19 @@ discard block |
||
310 | 310 | // Load lines |
311 | 311 | $this->fetch_lines(); |
312 | 312 | |
313 | - $ok=true; |
|
314 | - foreach($this->lines as $contratline) |
|
313 | + $ok = true; |
|
314 | + foreach ($this->lines as $contratline) |
|
315 | 315 | { |
316 | 316 | // Close lines not already closed |
317 | 317 | if ($contratline->statut != 5) |
318 | 318 | { |
319 | - $contratline->date_cloture=dol_now(); |
|
320 | - $contratline->fk_user_cloture=$user->id; |
|
321 | - $contratline->statut='5'; |
|
322 | - $result=$contratline->update($user); |
|
319 | + $contratline->date_cloture = dol_now(); |
|
320 | + $contratline->fk_user_cloture = $user->id; |
|
321 | + $contratline->statut = '5'; |
|
322 | + $result = $contratline->update($user); |
|
323 | 323 | if ($result < 0) |
324 | 324 | { |
325 | - $ok=false; |
|
325 | + $ok = false; |
|
326 | 326 | break; |
327 | 327 | } |
328 | 328 | } |
@@ -330,8 +330,8 @@ discard block |
||
330 | 330 | |
331 | 331 | if ($this->statut == 0) |
332 | 332 | { |
333 | - $result=$this->validate($user); |
|
334 | - if ($result < 0) $ok=false; |
|
333 | + $result = $this->validate($user); |
|
334 | + if ($result < 0) $ok = false; |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | if ($ok) |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | } |
342 | 342 | else |
343 | 343 | { |
344 | - dol_print_error($this->db,'Error in closeAll function'); |
|
344 | + dol_print_error($this->db, 'Error in closeAll function'); |
|
345 | 345 | $this->db->rollback(); |
346 | 346 | return -1; |
347 | 347 | } |
@@ -355,14 +355,14 @@ discard block |
||
355 | 355 | * @param int $notrigger 1=Does not execute triggers, 0= execute triggers |
356 | 356 | * @return int <0 if KO, >0 if OK |
357 | 357 | */ |
358 | - function validate($user, $force_number='', $notrigger=0) |
|
358 | + function validate($user, $force_number = '', $notrigger = 0) |
|
359 | 359 | { |
360 | 360 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
361 | 361 | global $langs, $conf; |
362 | 362 | |
363 | - $now=dol_now(); |
|
363 | + $now = dol_now(); |
|
364 | 364 | |
365 | - $error=0; |
|
365 | + $error = 0; |
|
366 | 366 | dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number); |
367 | 367 | |
368 | 368 | |
@@ -371,10 +371,10 @@ discard block |
||
371 | 371 | $this->fetch_thirdparty(); |
372 | 372 | |
373 | 373 | // A contract is validated so we can move thirdparty to status customer |
374 | - $result=$this->thirdparty->set_as_client(); |
|
374 | + $result = $this->thirdparty->set_as_client(); |
|
375 | 375 | |
376 | 376 | // Define new ref |
377 | - if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life |
|
377 | + if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life |
|
378 | 378 | { |
379 | 379 | $num = $this->getNextNumRef($this->thirdparty); |
380 | 380 | } |
@@ -388,27 +388,27 @@ discard block |
||
388 | 388 | { |
389 | 389 | $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET ref = '".$num."', statut = 1"; |
390 | 390 | //$sql.= ", fk_user_valid = ".$user->id.", date_valid = '".$this->db->idate($now)."'"; |
391 | - $sql .= " WHERE rowid = ".$this->id . " AND statut = 0"; |
|
391 | + $sql .= " WHERE rowid = ".$this->id." AND statut = 0"; |
|
392 | 392 | |
393 | 393 | dol_syslog(get_class($this)."::validate", LOG_DEBUG); |
394 | 394 | $resql = $this->db->query($sql); |
395 | - if (! $resql) |
|
395 | + if (!$resql) |
|
396 | 396 | { |
397 | 397 | dol_print_error($this->db); |
398 | 398 | $error++; |
399 | - $this->error=$this->db->lasterror(); |
|
399 | + $this->error = $this->db->lasterror(); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | // Trigger calls |
403 | - if (! $error && ! $notrigger) |
|
403 | + if (!$error && !$notrigger) |
|
404 | 404 | { |
405 | 405 | // Call trigger |
406 | - $result=$this->call_trigger('CONTRACT_VALIDATE',$user); |
|
406 | + $result = $this->call_trigger('CONTRACT_VALIDATE', $user); |
|
407 | 407 | if ($result < 0) { $error++; } |
408 | 408 | // End call triggers |
409 | 409 | } |
410 | 410 | |
411 | - if (! $error) |
|
411 | + if (!$error) |
|
412 | 412 | { |
413 | 413 | $this->oldref = $this->ref; |
414 | 414 | |
@@ -429,13 +429,13 @@ discard block |
||
429 | 429 | { |
430 | 430 | dol_syslog("Rename ok"); |
431 | 431 | // Rename docs starting with $oldref with $newref |
432 | - $listoffiles=dol_dir_list($conf->contract->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/')); |
|
433 | - foreach($listoffiles as $fileentry) |
|
432 | + $listoffiles = dol_dir_list($conf->contract->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); |
|
433 | + foreach ($listoffiles as $fileentry) |
|
434 | 434 | { |
435 | - $dirsource=$fileentry['name']; |
|
436 | - $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource); |
|
437 | - $dirsource=$fileentry['path'].'/'.$dirsource; |
|
438 | - $dirdest=$fileentry['path'].'/'.$dirdest; |
|
435 | + $dirsource = $fileentry['name']; |
|
436 | + $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); |
|
437 | + $dirsource = $fileentry['path'].'/'.$dirsource; |
|
438 | + $dirdest = $fileentry['path'].'/'.$dirdest; |
|
439 | 439 | @rename($dirsource, $dirdest); |
440 | 440 | } |
441 | 441 | } |
@@ -444,12 +444,12 @@ discard block |
||
444 | 444 | } |
445 | 445 | |
446 | 446 | // Set new ref and define current statut |
447 | - if (! $error) |
|
447 | + if (!$error) |
|
448 | 448 | { |
449 | 449 | $this->ref = $num; |
450 | - $this->statut=1; |
|
451 | - $this->brouillon=0; |
|
452 | - $this->date_validation=$now; |
|
450 | + $this->statut = 1; |
|
451 | + $this->brouillon = 0; |
|
452 | + $this->date_validation = $now; |
|
453 | 453 | } |
454 | 454 | } |
455 | 455 | else |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | $error++; |
458 | 458 | } |
459 | 459 | |
460 | - if (! $error) |
|
460 | + if (!$error) |
|
461 | 461 | { |
462 | 462 | $this->db->commit(); |
463 | 463 | return 1; |
@@ -477,14 +477,14 @@ discard block |
||
477 | 477 | * @param int $notrigger 1=Does not execute triggers, 0=execute triggers |
478 | 478 | * @return int <0 if KO, >0 if OK |
479 | 479 | */ |
480 | - function reopen($user, $notrigger=0) |
|
480 | + function reopen($user, $notrigger = 0) |
|
481 | 481 | { |
482 | 482 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
483 | 483 | global $langs, $conf; |
484 | 484 | |
485 | - $now=dol_now(); |
|
485 | + $now = dol_now(); |
|
486 | 486 | |
487 | - $error=0; |
|
487 | + $error = 0; |
|
488 | 488 | dol_syslog(get_class($this).'::reopen user='.$user->id); |
489 | 489 | |
490 | 490 | $this->db->begin(); |
@@ -493,22 +493,22 @@ discard block |
||
493 | 493 | |
494 | 494 | $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET statut = 0"; |
495 | 495 | //$sql.= ", fk_user_valid = null, date_valid = null"; |
496 | - $sql .= " WHERE rowid = ".$this->id . " AND statut = 1"; |
|
496 | + $sql .= " WHERE rowid = ".$this->id." AND statut = 1"; |
|
497 | 497 | |
498 | 498 | dol_syslog(get_class($this)."::validate", LOG_DEBUG); |
499 | 499 | $resql = $this->db->query($sql); |
500 | - if (! $resql) |
|
500 | + if (!$resql) |
|
501 | 501 | { |
502 | 502 | dol_print_error($this->db); |
503 | 503 | $error++; |
504 | - $this->error=$this->db->lasterror(); |
|
504 | + $this->error = $this->db->lasterror(); |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | // Trigger calls |
508 | - if (! $error && ! $notrigger) |
|
508 | + if (!$error && !$notrigger) |
|
509 | 509 | { |
510 | 510 | // Call trigger |
511 | - $result=$this->call_trigger('CONTRACT_REOPEN',$user); |
|
511 | + $result = $this->call_trigger('CONTRACT_REOPEN', $user); |
|
512 | 512 | if ($result < 0) { |
513 | 513 | $error++; |
514 | 514 | } |
@@ -516,14 +516,14 @@ discard block |
||
516 | 516 | } |
517 | 517 | |
518 | 518 | // Set new ref and define current statut |
519 | - if (! $error) |
|
519 | + if (!$error) |
|
520 | 520 | { |
521 | - $this->statut=0; |
|
522 | - $this->brouillon=1; |
|
523 | - $this->date_validation=$now; |
|
521 | + $this->statut = 0; |
|
522 | + $this->brouillon = 1; |
|
523 | + $this->date_validation = $now; |
|
524 | 524 | } |
525 | 525 | |
526 | - if (! $error) |
|
526 | + if (!$error) |
|
527 | 527 | { |
528 | 528 | $this->db->commit(); |
529 | 529 | return 1; |
@@ -544,30 +544,30 @@ discard block |
||
544 | 544 | * @param string $ref_supplier Supplier ref |
545 | 545 | * @return int <0 if KO, 0 if not found, Id of contract if OK |
546 | 546 | */ |
547 | - function fetch($id, $ref='', $ref_customer='', $ref_supplier='') |
|
547 | + function fetch($id, $ref = '', $ref_customer = '', $ref_supplier = '') |
|
548 | 548 | { |
549 | 549 | $sql = "SELECT rowid, statut, ref, fk_soc, mise_en_service as datemise,"; |
550 | - $sql.= " ref_supplier, ref_customer,"; |
|
551 | - $sql.= " ref_ext,"; |
|
552 | - $sql.= " fk_user_mise_en_service, date_contrat as datecontrat,"; |
|
553 | - $sql.= " fk_user_author, fin_validite, date_cloture,"; |
|
554 | - $sql.= " fk_projet,"; |
|
555 | - $sql.= " fk_commercial_signature, fk_commercial_suivi,"; |
|
556 | - $sql.= " note_private, note_public, model_pdf, extraparams"; |
|
557 | - $sql.= " FROM ".MAIN_DB_PREFIX."contrat"; |
|
558 | - if (! $id) $sql.=" WHERE entity IN (".getEntity('contract', 0).")"; |
|
559 | - else $sql.= " WHERE rowid=".$id; |
|
550 | + $sql .= " ref_supplier, ref_customer,"; |
|
551 | + $sql .= " ref_ext,"; |
|
552 | + $sql .= " fk_user_mise_en_service, date_contrat as datecontrat,"; |
|
553 | + $sql .= " fk_user_author, fin_validite, date_cloture,"; |
|
554 | + $sql .= " fk_projet,"; |
|
555 | + $sql .= " fk_commercial_signature, fk_commercial_suivi,"; |
|
556 | + $sql .= " note_private, note_public, model_pdf, extraparams"; |
|
557 | + $sql .= " FROM ".MAIN_DB_PREFIX."contrat"; |
|
558 | + if (!$id) $sql .= " WHERE entity IN (".getEntity('contract', 0).")"; |
|
559 | + else $sql .= " WHERE rowid=".$id; |
|
560 | 560 | if ($ref_customer) |
561 | 561 | { |
562 | - $sql.= " AND ref_customer = '".$this->db->escape($ref_customer)."'"; |
|
562 | + $sql .= " AND ref_customer = '".$this->db->escape($ref_customer)."'"; |
|
563 | 563 | } |
564 | 564 | if ($ref_supplier) |
565 | 565 | { |
566 | - $sql.= " AND ref_supplier = '".$this->db->escape($ref_supplier)."'"; |
|
566 | + $sql .= " AND ref_supplier = '".$this->db->escape($ref_supplier)."'"; |
|
567 | 567 | } |
568 | 568 | if ($ref) |
569 | 569 | { |
570 | - $sql.= " AND ref='".$this->db->escape($ref)."'"; |
|
570 | + $sql .= " AND ref='".$this->db->escape($ref)."'"; |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
@@ -578,57 +578,57 @@ discard block |
||
578 | 578 | |
579 | 579 | if ($result) |
580 | 580 | { |
581 | - $this->id = $result["rowid"]; |
|
582 | - $this->ref = (!isset($result["ref"]) || !$result["ref"]) ? $result["rowid"] : $result["ref"]; |
|
581 | + $this->id = $result["rowid"]; |
|
582 | + $this->ref = (!isset($result["ref"]) || !$result["ref"]) ? $result["rowid"] : $result["ref"]; |
|
583 | 583 | $this->ref_customer = $result["ref_customer"]; |
584 | 584 | $this->ref_supplier = $result["ref_supplier"]; |
585 | - $this->ref_ext = $result["ref_ext"]; |
|
586 | - $this->statut = $result["statut"]; |
|
587 | - $this->mise_en_service = $this->db->jdate($result["datemise"]); |
|
585 | + $this->ref_ext = $result["ref_ext"]; |
|
586 | + $this->statut = $result["statut"]; |
|
587 | + $this->mise_en_service = $this->db->jdate($result["datemise"]); |
|
588 | 588 | |
589 | 589 | $this->date_contrat = $this->db->jdate($result["datecontrat"]); |
590 | - $this->date_creation = $this->db->jdate($result["datecontrat"]); |
|
590 | + $this->date_creation = $this->db->jdate($result["datecontrat"]); |
|
591 | 591 | |
592 | 592 | $this->fin_validite = $this->db->jdate($result["fin_validite"]); |
593 | 593 | $this->date_cloture = $this->db->jdate($result["date_cloture"]); |
594 | 594 | |
595 | 595 | |
596 | - $this->user_author_id = $result["fk_user_author"]; |
|
596 | + $this->user_author_id = $result["fk_user_author"]; |
|
597 | 597 | |
598 | - $this->commercial_signature_id = $result["fk_commercial_signature"]; |
|
599 | - $this->commercial_suivi_id = $result["fk_commercial_suivi"]; |
|
598 | + $this->commercial_signature_id = $result["fk_commercial_signature"]; |
|
599 | + $this->commercial_suivi_id = $result["fk_commercial_suivi"]; |
|
600 | 600 | |
601 | - $this->note_private = $result["note_private"]; |
|
602 | - $this->note_public = $result["note_public"]; |
|
601 | + $this->note_private = $result["note_private"]; |
|
602 | + $this->note_public = $result["note_public"]; |
|
603 | 603 | $this->modelpdf = $result["model_pdf"]; |
604 | 604 | |
605 | 605 | $this->fk_projet = $result["fk_projet"]; // deprecated |
606 | - $this->fk_project = $result["fk_projet"]; |
|
606 | + $this->fk_project = $result["fk_projet"]; |
|
607 | 607 | |
608 | - $this->socid = $result["fk_soc"]; |
|
609 | - $this->fk_soc = $result["fk_soc"]; |
|
608 | + $this->socid = $result["fk_soc"]; |
|
609 | + $this->fk_soc = $result["fk_soc"]; |
|
610 | 610 | |
611 | - $this->extraparams = (array) json_decode($result["extraparams"], true); |
|
611 | + $this->extraparams = (array) json_decode($result["extraparams"], true); |
|
612 | 612 | |
613 | 613 | $this->db->free($resql); |
614 | 614 | |
615 | 615 | // Retreive all extrafield for thirdparty |
616 | 616 | // fetch optionals attributes and labels |
617 | 617 | require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); |
618 | - $extrafields=new ExtraFields($this->db); |
|
619 | - $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); |
|
620 | - $this->fetch_optionals($this->id,$extralabels); |
|
618 | + $extrafields = new ExtraFields($this->db); |
|
619 | + $extralabels = $extrafields->fetch_name_optionals_label($this->table_element, true); |
|
620 | + $this->fetch_optionals($this->id, $extralabels); |
|
621 | 621 | |
622 | 622 | /* |
623 | 623 | * Lines |
624 | 624 | */ |
625 | 625 | |
626 | - $this->lines = array(); |
|
626 | + $this->lines = array(); |
|
627 | 627 | |
628 | - $result=$this->fetch_lines(); |
|
628 | + $result = $this->fetch_lines(); |
|
629 | 629 | if ($result < 0) |
630 | 630 | { |
631 | - $this->error=$this->db->lasterror(); |
|
631 | + $this->error = $this->db->lasterror(); |
|
632 | 632 | return -3; |
633 | 633 | } |
634 | 634 | |
@@ -637,14 +637,14 @@ discard block |
||
637 | 637 | else |
638 | 638 | { |
639 | 639 | dol_syslog(get_class($this)."::Fetch Erreur contrat non trouve"); |
640 | - $this->error="Contract not found"; |
|
640 | + $this->error = "Contract not found"; |
|
641 | 641 | return 0; |
642 | 642 | } |
643 | 643 | } |
644 | 644 | else |
645 | 645 | { |
646 | 646 | dol_syslog(get_class($this)."::Fetch Erreur lecture contrat"); |
647 | - $this->error=$this->db->error(); |
|
647 | + $this->error = $this->db->error(); |
|
648 | 648 | return -1; |
649 | 649 | } |
650 | 650 | |
@@ -657,43 +657,43 @@ discard block |
||
657 | 657 | */ |
658 | 658 | function fetch_lines() |
659 | 659 | { |
660 | - $this->nbofserviceswait=0; |
|
661 | - $this->nbofservicesopened=0; |
|
662 | - $this->nbofservicesexpired=0; |
|
663 | - $this->nbofservicesclosed=0; |
|
660 | + $this->nbofserviceswait = 0; |
|
661 | + $this->nbofservicesopened = 0; |
|
662 | + $this->nbofservicesexpired = 0; |
|
663 | + $this->nbofservicesclosed = 0; |
|
664 | 664 | |
665 | - $total_ttc=0; |
|
666 | - $total_vat=0; |
|
667 | - $total_ht=0; |
|
665 | + $total_ttc = 0; |
|
666 | + $total_vat = 0; |
|
667 | + $total_ht = 0; |
|
668 | 668 | |
669 | - $now=dol_now(); |
|
669 | + $now = dol_now(); |
|
670 | 670 | |
671 | 671 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
672 | - $extrafieldsline=new ExtraFields($this->db); |
|
672 | + $extrafieldsline = new ExtraFields($this->db); |
|
673 | 673 | $line = new ContratLigne($this->db); |
674 | - $extralabelsline=$extrafieldsline->fetch_name_optionals_label($line->table_element,true); |
|
674 | + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($line->table_element, true); |
|
675 | 675 | |
676 | - $this->lines=array(); |
|
676 | + $this->lines = array(); |
|
677 | 677 | $pos = 0; |
678 | 678 | |
679 | 679 | // Selectionne les lignes contrats liees a un produit |
680 | 680 | $sql = "SELECT p.label as product_label, p.description as product_desc, p.ref as product_ref,"; |
681 | - $sql.= " d.rowid, d.fk_contrat, d.statut, d.description, d.price_ht, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.remise_percent, d.subprice, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht,"; |
|
682 | - $sql.= " d.total_ht,"; |
|
683 | - $sql.= " d.total_tva,"; |
|
684 | - $sql.= " d.total_localtax1,"; |
|
685 | - $sql.= " d.total_localtax2,"; |
|
686 | - $sql.= " d.total_ttc,"; |
|
687 | - $sql.= " d.info_bits, d.fk_product,"; |
|
688 | - $sql.= " d.date_ouverture_prevue, d.date_ouverture,"; |
|
689 | - $sql.= " d.date_fin_validite, d.date_cloture,"; |
|
690 | - $sql.= " d.fk_user_author,"; |
|
691 | - $sql.= " d.fk_user_ouverture,"; |
|
692 | - $sql.= " d.fk_user_cloture,"; |
|
693 | - $sql.= " d.fk_unit"; |
|
694 | - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as d, ".MAIN_DB_PREFIX."product as p"; |
|
695 | - $sql.= " WHERE d.fk_contrat = ".$this->id ." AND d.fk_product = p.rowid"; |
|
696 | - $sql.= " ORDER by d.rowid ASC"; |
|
681 | + $sql .= " d.rowid, d.fk_contrat, d.statut, d.description, d.price_ht, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.remise_percent, d.subprice, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht,"; |
|
682 | + $sql .= " d.total_ht,"; |
|
683 | + $sql .= " d.total_tva,"; |
|
684 | + $sql .= " d.total_localtax1,"; |
|
685 | + $sql .= " d.total_localtax2,"; |
|
686 | + $sql .= " d.total_ttc,"; |
|
687 | + $sql .= " d.info_bits, d.fk_product,"; |
|
688 | + $sql .= " d.date_ouverture_prevue, d.date_ouverture,"; |
|
689 | + $sql .= " d.date_fin_validite, d.date_cloture,"; |
|
690 | + $sql .= " d.fk_user_author,"; |
|
691 | + $sql .= " d.fk_user_ouverture,"; |
|
692 | + $sql .= " d.fk_user_cloture,"; |
|
693 | + $sql .= " d.fk_unit"; |
|
694 | + $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as d, ".MAIN_DB_PREFIX."product as p"; |
|
695 | + $sql .= " WHERE d.fk_contrat = ".$this->id." AND d.fk_product = p.rowid"; |
|
696 | + $sql .= " ORDER by d.rowid ASC"; |
|
697 | 697 | |
698 | 698 | dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); |
699 | 699 | $result = $this->db->query($sql); |
@@ -707,47 +707,47 @@ discard block |
||
707 | 707 | $objp = $this->db->fetch_object($result); |
708 | 708 | |
709 | 709 | $line = new ContratLigne($this->db); |
710 | - $line->id = $objp->rowid; |
|
710 | + $line->id = $objp->rowid; |
|
711 | 711 | $line->ref = $objp->rowid; |
712 | - $line->fk_contrat = $objp->fk_contrat; |
|
713 | - $line->desc = $objp->description; // Description ligne |
|
712 | + $line->fk_contrat = $objp->fk_contrat; |
|
713 | + $line->desc = $objp->description; // Description ligne |
|
714 | 714 | $line->qty = $objp->qty; |
715 | - $line->vat_src_code = $objp->vat_src_code ; |
|
716 | - $line->tva_tx = $objp->tva_tx; |
|
715 | + $line->vat_src_code = $objp->vat_src_code; |
|
716 | + $line->tva_tx = $objp->tva_tx; |
|
717 | 717 | $line->localtax1_tx = $objp->localtax1_tx; |
718 | 718 | $line->localtax2_tx = $objp->localtax2_tx; |
719 | 719 | $line->localtax1_type = $objp->localtax1_type; |
720 | 720 | $line->localtax2_type = $objp->localtax2_type; |
721 | 721 | $line->subprice = $objp->subprice; |
722 | - $line->statut = $objp->statut; |
|
722 | + $line->statut = $objp->statut; |
|
723 | 723 | $line->remise_percent = $objp->remise_percent; |
724 | 724 | $line->price_ht = $objp->price_ht; |
725 | - $line->price = $objp->price_ht; // For backward compatibility |
|
725 | + $line->price = $objp->price_ht; // For backward compatibility |
|
726 | 726 | $line->total_ht = $objp->total_ht; |
727 | 727 | $line->total_tva = $objp->total_tva; |
728 | 728 | $line->total_localtax1 = $objp->total_localtax1; |
729 | 729 | $line->total_localtax2 = $objp->total_localtax2; |
730 | 730 | $line->total_ttc = $objp->total_ttc; |
731 | - $line->fk_product = $objp->fk_product; |
|
731 | + $line->fk_product = $objp->fk_product; |
|
732 | 732 | $line->info_bits = $objp->info_bits; |
733 | 733 | |
734 | - $line->fk_fournprice = $objp->fk_fournprice; |
|
734 | + $line->fk_fournprice = $objp->fk_fournprice; |
|
735 | 735 | $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht); |
736 | - $line->pa_ht = $marginInfos[0]; |
|
736 | + $line->pa_ht = $marginInfos[0]; |
|
737 | 737 | |
738 | - $line->fk_user_author = $objp->fk_user_author; |
|
739 | - $line->fk_user_ouverture= $objp->fk_user_ouverture; |
|
738 | + $line->fk_user_author = $objp->fk_user_author; |
|
739 | + $line->fk_user_ouverture = $objp->fk_user_ouverture; |
|
740 | 740 | $line->fk_user_cloture = $objp->fk_user_cloture; |
741 | - $line->fk_unit = $objp->fk_unit; |
|
741 | + $line->fk_unit = $objp->fk_unit; |
|
742 | 742 | |
743 | - $line->ref = $objp->product_ref; // deprecated |
|
744 | - $line->label = $objp->product_label; // deprecated |
|
745 | - $line->libelle = $objp->product_label; // deprecated |
|
746 | - $line->product_ref = $objp->product_ref; // Ref product |
|
747 | - $line->product_desc = $objp->product_desc; // Description product |
|
743 | + $line->ref = $objp->product_ref; // deprecated |
|
744 | + $line->label = $objp->product_label; // deprecated |
|
745 | + $line->libelle = $objp->product_label; // deprecated |
|
746 | + $line->product_ref = $objp->product_ref; // Ref product |
|
747 | + $line->product_desc = $objp->product_desc; // Description product |
|
748 | 748 | $line->product_label = $objp->product_label; // Label product |
749 | 749 | |
750 | - $line->description = $objp->description; |
|
750 | + $line->description = $objp->description; |
|
751 | 751 | |
752 | 752 | $line->date_ouverture_prevue = $this->db->jdate($objp->date_ouverture_prevue); |
753 | 753 | $line->date_ouverture = $this->db->jdate($objp->date_ouverture); |
@@ -761,9 +761,9 @@ discard block |
||
761 | 761 | |
762 | 762 | // Retreive all extrafield for propal |
763 | 763 | // fetch optionals attributes and labels |
764 | - $line->fetch_optionals($line->id,$extralabelsline); |
|
764 | + $line->fetch_optionals($line->id, $extralabelsline); |
|
765 | 765 | |
766 | - $this->lines[$pos] = $line; |
|
766 | + $this->lines[$pos] = $line; |
|
767 | 767 | $this->lines_id_index_mapper[$line->id] = $pos; |
768 | 768 | |
769 | 769 | //dol_syslog("1 ".$line->desc); |
@@ -771,12 +771,12 @@ discard block |
||
771 | 771 | |
772 | 772 | if ($line->statut == 0) $this->nbofserviceswait++; |
773 | 773 | if ($line->statut == 4 && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) $this->nbofservicesopened++; |
774 | - if ($line->statut == 4 && (! empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) $this->nbofservicesexpired++; |
|
774 | + if ($line->statut == 4 && (!empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) $this->nbofservicesexpired++; |
|
775 | 775 | if ($line->statut == 5) $this->nbofservicesclosed++; |
776 | 776 | |
777 | - $total_ttc+=$objp->total_ttc; // TODO Not saved into database |
|
778 | - $total_vat+=$objp->total_tva; |
|
779 | - $total_ht+=$objp->total_ht; |
|
777 | + $total_ttc += $objp->total_ttc; // TODO Not saved into database |
|
778 | + $total_vat += $objp->total_tva; |
|
779 | + $total_ht += $objp->total_ht; |
|
780 | 780 | |
781 | 781 | $i++; |
782 | 782 | $pos++; |
@@ -791,21 +791,21 @@ discard block |
||
791 | 791 | |
792 | 792 | // Selectionne les lignes contrat liees a aucun produit |
793 | 793 | $sql = "SELECT d.rowid, d.fk_contrat, d.statut, d.qty, d.description, d.price_ht, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.rowid, d.remise_percent, d.subprice,"; |
794 | - $sql.= " d.total_ht,"; |
|
795 | - $sql.= " d.total_tva,"; |
|
796 | - $sql.= " d.total_localtax1,"; |
|
797 | - $sql.= " d.total_localtax2,"; |
|
798 | - $sql.= " d.total_ttc,"; |
|
799 | - $sql.= " d.info_bits, d.fk_product,"; |
|
800 | - $sql.= " d.date_ouverture_prevue, d.date_ouverture,"; |
|
801 | - $sql.= " d.date_fin_validite, d.date_cloture,"; |
|
802 | - $sql.= " d.fk_user_author,"; |
|
803 | - $sql.= " d.fk_user_ouverture,"; |
|
804 | - $sql.= " d.fk_user_cloture,"; |
|
805 | - $sql.= " d.fk_unit"; |
|
806 | - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as d"; |
|
807 | - $sql.= " WHERE d.fk_contrat = ".$this->id; |
|
808 | - $sql.= " AND (d.fk_product IS NULL OR d.fk_product = 0)"; // fk_product = 0 gardee pour compatibilitee |
|
794 | + $sql .= " d.total_ht,"; |
|
795 | + $sql .= " d.total_tva,"; |
|
796 | + $sql .= " d.total_localtax1,"; |
|
797 | + $sql .= " d.total_localtax2,"; |
|
798 | + $sql .= " d.total_ttc,"; |
|
799 | + $sql .= " d.info_bits, d.fk_product,"; |
|
800 | + $sql .= " d.date_ouverture_prevue, d.date_ouverture,"; |
|
801 | + $sql .= " d.date_fin_validite, d.date_cloture,"; |
|
802 | + $sql .= " d.fk_user_author,"; |
|
803 | + $sql .= " d.fk_user_ouverture,"; |
|
804 | + $sql .= " d.fk_user_cloture,"; |
|
805 | + $sql .= " d.fk_unit"; |
|
806 | + $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as d"; |
|
807 | + $sql .= " WHERE d.fk_contrat = ".$this->id; |
|
808 | + $sql .= " AND (d.fk_product IS NULL OR d.fk_product = 0)"; // fk_product = 0 gardee pour compatibilitee |
|
809 | 809 | |
810 | 810 | $result = $this->db->query($sql); |
811 | 811 | if ($result) |
@@ -815,15 +815,15 @@ discard block |
||
815 | 815 | |
816 | 816 | while ($i < $num) |
817 | 817 | { |
818 | - $objp = $this->db->fetch_object($result); |
|
818 | + $objp = $this->db->fetch_object($result); |
|
819 | 819 | |
820 | 820 | $line = new ContratLigne($this->db); |
821 | - $line->id = $objp->rowid; |
|
821 | + $line->id = $objp->rowid; |
|
822 | 822 | $line->fk_contrat = $objp->fk_contrat; |
823 | 823 | $line->libelle = $objp->description; |
824 | 824 | $line->desc = $objp->description; |
825 | 825 | $line->qty = $objp->qty; |
826 | - $line->statut = $objp->statut; |
|
826 | + $line->statut = $objp->statut; |
|
827 | 827 | $line->ref = ''; |
828 | 828 | $line->tva_tx = $objp->tva_tx; |
829 | 829 | $line->localtax1_tx = $objp->localtax1_tx; |
@@ -833,20 +833,20 @@ discard block |
||
833 | 833 | $line->subprice = $objp->subprice; |
834 | 834 | $line->remise_percent = $objp->remise_percent; |
835 | 835 | $line->price_ht = $objp->price_ht; |
836 | - $line->price = (isset($objp->price)?$objp->price:null); // For backward compatibility |
|
836 | + $line->price = (isset($objp->price) ? $objp->price : null); // For backward compatibility |
|
837 | 837 | $line->total_ht = $objp->total_ht; |
838 | 838 | $line->total_tva = $objp->total_tva; |
839 | - $line->total_localtax1= $objp->total_localtax1; |
|
840 | - $line->total_localtax2= $objp->total_localtax2; |
|
839 | + $line->total_localtax1 = $objp->total_localtax1; |
|
840 | + $line->total_localtax2 = $objp->total_localtax2; |
|
841 | 841 | $line->total_ttc = $objp->total_ttc; |
842 | 842 | $line->fk_product = 0; |
843 | 843 | $line->info_bits = $objp->info_bits; |
844 | 844 | |
845 | 845 | $line->fk_user_author = $objp->fk_user_author; |
846 | - $line->fk_user_ouverture= $objp->fk_user_ouverture; |
|
846 | + $line->fk_user_ouverture = $objp->fk_user_ouverture; |
|
847 | 847 | $line->fk_user_cloture = $objp->fk_user_cloture; |
848 | 848 | |
849 | - $line->description = $objp->description; |
|
849 | + $line->description = $objp->description; |
|
850 | 850 | |
851 | 851 | $line->date_ouverture_prevue = $this->db->jdate($objp->date_ouverture_prevue); |
852 | 852 | $line->date_ouverture = $this->db->jdate($objp->date_ouverture); |
@@ -857,26 +857,26 @@ discard block |
||
857 | 857 | $line->date_debut_reel = $this->db->jdate($objp->date_ouverture); |
858 | 858 | $line->date_fin_prevue = $this->db->jdate($objp->date_fin_validite); |
859 | 859 | $line->date_fin_reel = $this->db->jdate($objp->date_cloture); |
860 | - $line->fk_unit = $objp->fk_unit; |
|
860 | + $line->fk_unit = $objp->fk_unit; |
|
861 | 861 | |
862 | 862 | if ($line->statut == 0) $this->nbofserviceswait++; |
863 | 863 | if ($line->statut == 4 && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) $this->nbofservicesopened++; |
864 | - if ($line->statut == 4 && (! empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) $this->nbofservicesexpired++; |
|
864 | + if ($line->statut == 4 && (!empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) $this->nbofservicesexpired++; |
|
865 | 865 | if ($line->statut == 5) $this->nbofservicesclosed++; |
866 | 866 | |
867 | 867 | |
868 | 868 | // Retreive all extrafield for propal |
869 | 869 | // fetch optionals attributes and labels |
870 | 870 | |
871 | - $line->fetch_optionals($line->id,$extralabelsline); |
|
871 | + $line->fetch_optionals($line->id, $extralabelsline); |
|
872 | 872 | |
873 | 873 | |
874 | - $this->lines[$pos] = $line; |
|
874 | + $this->lines[$pos] = $line; |
|
875 | 875 | $this->lines_id_index_mapper[$line->id] = $pos; |
876 | 876 | |
877 | - $total_ttc+=$objp->total_ttc; |
|
878 | - $total_vat+=$objp->total_tva; |
|
879 | - $total_ht+=$objp->total_ht; |
|
877 | + $total_ttc += $objp->total_ttc; |
|
878 | + $total_vat += $objp->total_tva; |
|
879 | + $total_ht += $objp->total_ht; |
|
880 | 880 | |
881 | 881 | $i++; |
882 | 882 | $pos++; |
@@ -887,14 +887,14 @@ discard block |
||
887 | 887 | else |
888 | 888 | { |
889 | 889 | dol_syslog(get_class($this)."::Fetch Erreur lecture des lignes de contrat non liees aux produits"); |
890 | - $this->error=$this->db->error(); |
|
890 | + $this->error = $this->db->error(); |
|
891 | 891 | return -2; |
892 | 892 | } |
893 | 893 | |
894 | - $this->nbofservices=count($this->lines); |
|
895 | - $this->total_ttc = price2num($total_ttc); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
896 | - $this->total_vat = price2num($total_vat); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
897 | - $this->total_ht = price2num($total_ht); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
894 | + $this->nbofservices = count($this->lines); |
|
895 | + $this->total_ttc = price2num($total_ttc); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
896 | + $this->total_vat = price2num($total_vat); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
897 | + $this->total_ht = price2num($total_ht); // TODO For the moment value is false as value is not stored in database for line linked to products |
|
898 | 898 | |
899 | 899 | return $this->lines; |
900 | 900 | } |
@@ -907,62 +907,62 @@ discard block |
||
907 | 907 | */ |
908 | 908 | function create($user) |
909 | 909 | { |
910 | - global $conf,$langs,$mysoc; |
|
910 | + global $conf, $langs, $mysoc; |
|
911 | 911 | |
912 | 912 | // Check parameters |
913 | - $paramsok=1; |
|
913 | + $paramsok = 1; |
|
914 | 914 | if ($this->commercial_signature_id <= 0) |
915 | 915 | { |
916 | 916 | $langs->load("commercial"); |
917 | - $this->error.=$langs->trans("ErrorFieldRequired",$langs->trans("SalesRepresentativeSignature")); |
|
918 | - $paramsok=0; |
|
917 | + $this->error .= $langs->trans("ErrorFieldRequired", $langs->trans("SalesRepresentativeSignature")); |
|
918 | + $paramsok = 0; |
|
919 | 919 | } |
920 | 920 | if ($this->commercial_suivi_id <= 0) |
921 | 921 | { |
922 | 922 | $langs->load("commercial"); |
923 | - $this->error.=($this->error?"<br>":''); |
|
924 | - $this->error.=$langs->trans("ErrorFieldRequired",$langs->trans("SalesRepresentativeFollowUp")); |
|
925 | - $paramsok=0; |
|
923 | + $this->error .= ($this->error ? "<br>" : ''); |
|
924 | + $this->error .= $langs->trans("ErrorFieldRequired", $langs->trans("SalesRepresentativeFollowUp")); |
|
925 | + $paramsok = 0; |
|
926 | 926 | } |
927 | - if (! $paramsok) return -1; |
|
927 | + if (!$paramsok) return -1; |
|
928 | 928 | |
929 | 929 | |
930 | 930 | $this->db->begin(); |
931 | 931 | |
932 | - $now=dol_now(); |
|
932 | + $now = dol_now(); |
|
933 | 933 | |
934 | 934 | // Insert contract |
935 | 935 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."contrat (datec, fk_soc, fk_user_author, date_contrat,"; |
936 | - $sql.= " fk_commercial_signature, fk_commercial_suivi, fk_projet,"; |
|
937 | - $sql.= " ref, entity, note_private, note_public, ref_customer, ref_supplier, ref_ext)"; |
|
938 | - $sql.= " VALUES ('".$this->db->idate($now)."',".$this->socid.",".$user->id; |
|
939 | - $sql.= ", ".(dol_strlen($this->date_contrat)!=0 ? "'".$this->db->idate($this->date_contrat)."'" : "NULL"); |
|
940 | - $sql.= ",".($this->commercial_signature_id>0?$this->commercial_signature_id:"NULL"); |
|
941 | - $sql.= ",".($this->commercial_suivi_id>0?$this->commercial_suivi_id:"NULL"); |
|
942 | - $sql.= ",".($this->fk_project>0?$this->fk_project:"NULL"); |
|
943 | - $sql.= ", ".(dol_strlen($this->ref)<=0 ? "null" : "'".$this->db->escape($this->ref)."'"); |
|
944 | - $sql.= ", ".$conf->entity; |
|
945 | - $sql.= ", ".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL"); |
|
946 | - $sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL"); |
|
947 | - $sql.= ", ".(!empty($this->ref_customer)?("'".$this->db->escape($this->ref_customer)."'"):"NULL"); |
|
948 | - $sql.= ", ".(!empty($this->ref_supplier)?("'".$this->db->escape($this->ref_supplier)."'"):"NULL"); |
|
949 | - $sql.= ", ".(!empty($this->ref_ext)?("'".$this->db->escape($this->ref_ext)."'"):"NULL"); |
|
950 | - $sql.= ")"; |
|
951 | - $resql=$this->db->query($sql); |
|
936 | + $sql .= " fk_commercial_signature, fk_commercial_suivi, fk_projet,"; |
|
937 | + $sql .= " ref, entity, note_private, note_public, ref_customer, ref_supplier, ref_ext)"; |
|
938 | + $sql .= " VALUES ('".$this->db->idate($now)."',".$this->socid.",".$user->id; |
|
939 | + $sql .= ", ".(dol_strlen($this->date_contrat) != 0 ? "'".$this->db->idate($this->date_contrat)."'" : "NULL"); |
|
940 | + $sql .= ",".($this->commercial_signature_id > 0 ? $this->commercial_signature_id : "NULL"); |
|
941 | + $sql .= ",".($this->commercial_suivi_id > 0 ? $this->commercial_suivi_id : "NULL"); |
|
942 | + $sql .= ",".($this->fk_project > 0 ? $this->fk_project : "NULL"); |
|
943 | + $sql .= ", ".(dol_strlen($this->ref) <= 0 ? "null" : "'".$this->db->escape($this->ref)."'"); |
|
944 | + $sql .= ", ".$conf->entity; |
|
945 | + $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL"); |
|
946 | + $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL"); |
|
947 | + $sql .= ", ".(!empty($this->ref_customer) ? ("'".$this->db->escape($this->ref_customer)."'") : "NULL"); |
|
948 | + $sql .= ", ".(!empty($this->ref_supplier) ? ("'".$this->db->escape($this->ref_supplier)."'") : "NULL"); |
|
949 | + $sql .= ", ".(!empty($this->ref_ext) ? ("'".$this->db->escape($this->ref_ext)."'") : "NULL"); |
|
950 | + $sql .= ")"; |
|
951 | + $resql = $this->db->query($sql); |
|
952 | 952 | if ($resql) |
953 | 953 | { |
954 | - $error=0; |
|
954 | + $error = 0; |
|
955 | 955 | |
956 | 956 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat"); |
957 | 957 | |
958 | 958 | |
959 | 959 | // Load object modContract |
960 | - $module=(! empty($conf->global->CONTRACT_ADDON)?$conf->global->CONTRACT_ADDON:'mod_contract_serpis'); |
|
960 | + $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis'); |
|
961 | 961 | if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') |
962 | 962 | { |
963 | - $module = substr($module, 0, dol_strlen($module)-4); |
|
963 | + $module = substr($module, 0, dol_strlen($module) - 4); |
|
964 | 964 | } |
965 | - $result=dol_include_once('/core/modules/contract/'.$module.'.php'); |
|
965 | + $result = dol_include_once('/core/modules/contract/'.$module.'.php'); |
|
966 | 966 | if ($result > 0) |
967 | 967 | { |
968 | 968 | $modCodeContract = new $module(); |
@@ -975,16 +975,16 @@ discard block |
||
975 | 975 | { |
976 | 976 | if ($this->id) |
977 | 977 | { |
978 | - $this->ref="(PROV".$this->id.")"; |
|
978 | + $this->ref = "(PROV".$this->id.")"; |
|
979 | 979 | } |
980 | 980 | } |
981 | 981 | } |
982 | 982 | |
983 | - if (! $error) |
|
983 | + if (!$error) |
|
984 | 984 | { |
985 | 985 | if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used |
986 | 986 | { |
987 | - $result=$this->insertExtraFields(); |
|
987 | + $result = $this->insertExtraFields(); |
|
988 | 988 | if ($result < 0) |
989 | 989 | { |
990 | 990 | $error++; |
@@ -993,32 +993,32 @@ discard block |
||
993 | 993 | } |
994 | 994 | |
995 | 995 | // Insert contacts commerciaux ('SALESREPSIGN','contrat') |
996 | - if (! $error) |
|
996 | + if (!$error) |
|
997 | 997 | { |
998 | - $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal'); |
|
998 | + $result = $this->add_contact($this->commercial_signature_id, 'SALESREPSIGN', 'internal'); |
|
999 | 999 | if ($result < 0) $error++; |
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | // Insert contacts commerciaux ('SALESREPFOLL','contrat') |
1003 | - if (! $error) |
|
1003 | + if (!$error) |
|
1004 | 1004 | { |
1005 | - $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal'); |
|
1005 | + $result = $this->add_contact($this->commercial_suivi_id, 'SALESREPFOLL', 'internal'); |
|
1006 | 1006 | if ($result < 0) $error++; |
1007 | 1007 | } |
1008 | 1008 | |
1009 | - if (! $error) |
|
1009 | + if (!$error) |
|
1010 | 1010 | { |
1011 | 1011 | // Add object linked |
1012 | - if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) |
|
1012 | + if (!$error && $this->id && is_array($this->linked_objects) && !empty($this->linked_objects)) |
|
1013 | 1013 | { |
1014 | - foreach($this->linked_objects as $origin => $tmp_origin_id) |
|
1014 | + foreach ($this->linked_objects as $origin => $tmp_origin_id) |
|
1015 | 1015 | { |
1016 | 1016 | if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) |
1017 | 1017 | { |
1018 | - foreach($tmp_origin_id as $origin_id) |
|
1018 | + foreach ($tmp_origin_id as $origin_id) |
|
1019 | 1019 | { |
1020 | 1020 | $ret = $this->add_object_linked($origin, $origin_id); |
1021 | - if (! $ret) |
|
1021 | + if (!$ret) |
|
1022 | 1022 | { |
1023 | 1023 | dol_print_error($this->db); |
1024 | 1024 | $error++; |
@@ -1029,7 +1029,7 @@ discard block |
||
1029 | 1029 | { |
1030 | 1030 | $origin_id = $tmp_origin_id; |
1031 | 1031 | $ret = $this->add_object_linked($origin, $origin_id); |
1032 | - if (! $ret) |
|
1032 | + if (!$ret) |
|
1033 | 1033 | { |
1034 | 1034 | dol_print_error($this->db); |
1035 | 1035 | $error++; |
@@ -1038,13 +1038,13 @@ discard block |
||
1038 | 1038 | } |
1039 | 1039 | } |
1040 | 1040 | |
1041 | - if (! $error && $this->id && ! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && ! empty($this->origin) && ! empty($this->origin_id)) // Get contact from origin object |
|
1041 | + if (!$error && $this->id && !empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && !empty($this->origin) && !empty($this->origin_id)) // Get contact from origin object |
|
1042 | 1042 | { |
1043 | 1043 | $originforcontact = $this->origin; |
1044 | 1044 | $originidforcontact = $this->origin_id; |
1045 | 1045 | if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order |
1046 | 1046 | { |
1047 | - require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; |
|
1047 | + require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; |
|
1048 | 1048 | $exp = new Expedition($db); |
1049 | 1049 | $exp->fetch($this->origin_id); |
1050 | 1050 | $exp->fetchObjectLinked(); |
@@ -1060,31 +1060,31 @@ discard block |
||
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; |
1063 | - $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; |
|
1063 | + $sqlcontact .= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; |
|
1064 | 1064 | |
1065 | 1065 | $resqlcontact = $this->db->query($sqlcontact); |
1066 | 1066 | if ($resqlcontact) |
1067 | 1067 | { |
1068 | - while($objcontact = $this->db->fetch_object($resqlcontact)) |
|
1068 | + while ($objcontact = $this->db->fetch_object($resqlcontact)) |
|
1069 | 1069 | { |
1070 | - if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) continue; // ignore this, already forced previously |
|
1070 | + if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) continue; // ignore this, already forced previously |
|
1071 | 1071 | |
1072 | 1072 | //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; |
1073 | - $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object |
|
1073 | + $this->add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source); // May failed because of duplicate key or because code of contact type does not exists for new object |
|
1074 | 1074 | } |
1075 | 1075 | } |
1076 | 1076 | else dol_print_error($resqlcontact); |
1077 | 1077 | } |
1078 | 1078 | } |
1079 | 1079 | |
1080 | - if (! $error) |
|
1080 | + if (!$error) |
|
1081 | 1081 | { |
1082 | 1082 | // Call trigger |
1083 | - $result=$this->call_trigger('CONTRACT_CREATE',$user); |
|
1083 | + $result = $this->call_trigger('CONTRACT_CREATE', $user); |
|
1084 | 1084 | if ($result < 0) { $error++; } |
1085 | 1085 | // End call triggers |
1086 | 1086 | |
1087 | - if (! $error) |
|
1087 | + if (!$error) |
|
1088 | 1088 | { |
1089 | 1089 | $this->db->commit(); |
1090 | 1090 | return $this->id; |
@@ -1098,7 +1098,7 @@ discard block |
||
1098 | 1098 | } |
1099 | 1099 | else |
1100 | 1100 | { |
1101 | - $this->error="Failed to add contact"; |
|
1101 | + $this->error = "Failed to add contact"; |
|
1102 | 1102 | dol_syslog(get_class($this)."::create - 20 - ".$this->error, LOG_ERR); |
1103 | 1103 | $this->db->rollback(); |
1104 | 1104 | return -2; |
@@ -1106,7 +1106,7 @@ discard block |
||
1106 | 1106 | } |
1107 | 1107 | else |
1108 | 1108 | { |
1109 | - $this->error=$langs->trans("UnknownError: ".$this->db->error()." -", LOG_DEBUG); |
|
1109 | + $this->error = $langs->trans("UnknownError: ".$this->db->error()." -", LOG_DEBUG); |
|
1110 | 1110 | |
1111 | 1111 | $this->db->rollback(); |
1112 | 1112 | return -1; |
@@ -1123,18 +1123,18 @@ discard block |
||
1123 | 1123 | function delete($user) |
1124 | 1124 | { |
1125 | 1125 | global $conf, $langs; |
1126 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
|
1126 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
1127 | 1127 | |
1128 | - $error=0; |
|
1128 | + $error = 0; |
|
1129 | 1129 | |
1130 | 1130 | $this->db->begin(); |
1131 | 1131 | |
1132 | 1132 | // Call trigger |
1133 | - $result=$this->call_trigger('CONTRACT_DELETE',$user); |
|
1133 | + $result = $this->call_trigger('CONTRACT_DELETE', $user); |
|
1134 | 1134 | if ($result < 0) { $error++; } |
1135 | 1135 | // End call triggers |
1136 | 1136 | |
1137 | - if (! $error) |
|
1137 | + if (!$error) |
|
1138 | 1138 | { |
1139 | 1139 | // Delete linked contacts |
1140 | 1140 | $res = $this->delete_linked_contact(); |
@@ -1145,14 +1145,14 @@ discard block |
||
1145 | 1145 | } |
1146 | 1146 | } |
1147 | 1147 | |
1148 | - if (! $error) |
|
1148 | + if (!$error) |
|
1149 | 1149 | { |
1150 | 1150 | // Delete linked object |
1151 | 1151 | $res = $this->deleteObjectLinked(); |
1152 | 1152 | if ($res < 0) $error++; |
1153 | 1153 | } |
1154 | 1154 | |
1155 | - if (! $error) |
|
1155 | + if (!$error) |
|
1156 | 1156 | { |
1157 | 1157 | // Delete contratdet_log |
1158 | 1158 | /* |
@@ -1161,73 +1161,73 @@ discard block |
||
1161 | 1161 | $sql.= " WHERE cdl.fk_contratdet=cd.rowid AND cd.fk_contrat=".$this->id; |
1162 | 1162 | */ |
1163 | 1163 | $sql = "SELECT cdl.rowid as cdlrowid "; |
1164 | - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet_log as cdl, ".MAIN_DB_PREFIX."contratdet as cd"; |
|
1165 | - $sql.= " WHERE cdl.fk_contratdet=cd.rowid AND cd.fk_contrat=".$this->id; |
|
1164 | + $sql .= " FROM ".MAIN_DB_PREFIX."contratdet_log as cdl, ".MAIN_DB_PREFIX."contratdet as cd"; |
|
1165 | + $sql .= " WHERE cdl.fk_contratdet=cd.rowid AND cd.fk_contrat=".$this->id; |
|
1166 | 1166 | |
1167 | 1167 | dol_syslog(get_class($this)."::delete contratdet_log", LOG_DEBUG); |
1168 | - $resql=$this->db->query($sql); |
|
1169 | - if (! $resql) |
|
1168 | + $resql = $this->db->query($sql); |
|
1169 | + if (!$resql) |
|
1170 | 1170 | { |
1171 | - $this->error=$this->db->error(); |
|
1171 | + $this->error = $this->db->error(); |
|
1172 | 1172 | $error++; |
1173 | 1173 | } |
1174 | - $numressql=$this->db->num_rows($resql); |
|
1175 | - if (! $error && $numressql ) |
|
1174 | + $numressql = $this->db->num_rows($resql); |
|
1175 | + if (!$error && $numressql) |
|
1176 | 1176 | { |
1177 | - $tab_resql=array(); |
|
1178 | - for($i=0;$i<$numressql;$i++) |
|
1177 | + $tab_resql = array(); |
|
1178 | + for ($i = 0; $i < $numressql; $i++) |
|
1179 | 1179 | { |
1180 | - $objresql=$this->db->fetch_object($resql); |
|
1181 | - $tab_resql[]= $objresql->cdlrowid; |
|
1180 | + $objresql = $this->db->fetch_object($resql); |
|
1181 | + $tab_resql[] = $objresql->cdlrowid; |
|
1182 | 1182 | } |
1183 | 1183 | $this->db->free($resql); |
1184 | 1184 | |
1185 | - $sql= "DELETE FROM ".MAIN_DB_PREFIX."contratdet_log "; |
|
1186 | - $sql.= " WHERE ".MAIN_DB_PREFIX."contratdet_log.rowid IN (".implode(",",$tab_resql).")"; |
|
1185 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet_log "; |
|
1186 | + $sql .= " WHERE ".MAIN_DB_PREFIX."contratdet_log.rowid IN (".implode(",", $tab_resql).")"; |
|
1187 | 1187 | |
1188 | 1188 | dol_syslog(get_class($this)."::delete contratdet_log", LOG_DEBUG); |
1189 | - $resql=$this->db->query($sql); |
|
1190 | - if (! $resql) |
|
1189 | + $resql = $this->db->query($sql); |
|
1190 | + if (!$resql) |
|
1191 | 1191 | { |
1192 | - $this->error=$this->db->error(); |
|
1192 | + $this->error = $this->db->error(); |
|
1193 | 1193 | $error++; |
1194 | 1194 | } |
1195 | 1195 | } |
1196 | 1196 | } |
1197 | 1197 | |
1198 | - if (! $error) |
|
1198 | + if (!$error) |
|
1199 | 1199 | { |
1200 | 1200 | // Delete contratdet |
1201 | 1201 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet"; |
1202 | - $sql.= " WHERE fk_contrat=".$this->id; |
|
1202 | + $sql .= " WHERE fk_contrat=".$this->id; |
|
1203 | 1203 | |
1204 | 1204 | dol_syslog(get_class($this)."::delete contratdet", LOG_DEBUG); |
1205 | - $resql=$this->db->query($sql); |
|
1206 | - if (! $resql) |
|
1205 | + $resql = $this->db->query($sql); |
|
1206 | + if (!$resql) |
|
1207 | 1207 | { |
1208 | - $this->error=$this->db->error(); |
|
1208 | + $this->error = $this->db->error(); |
|
1209 | 1209 | $error++; |
1210 | 1210 | } |
1211 | 1211 | } |
1212 | 1212 | |
1213 | - if (! $error) |
|
1213 | + if (!$error) |
|
1214 | 1214 | { |
1215 | 1215 | // Delete contrat |
1216 | 1216 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."contrat"; |
1217 | - $sql.= " WHERE rowid=".$this->id; |
|
1217 | + $sql .= " WHERE rowid=".$this->id; |
|
1218 | 1218 | |
1219 | 1219 | dol_syslog(get_class($this)."::delete contrat", LOG_DEBUG); |
1220 | - $resql=$this->db->query($sql); |
|
1221 | - if (! $resql) |
|
1220 | + $resql = $this->db->query($sql); |
|
1221 | + if (!$resql) |
|
1222 | 1222 | { |
1223 | - $this->error=$this->db->error(); |
|
1223 | + $this->error = $this->db->error(); |
|
1224 | 1224 | $error++; |
1225 | 1225 | } |
1226 | 1226 | } |
1227 | 1227 | |
1228 | 1228 | // Removed extrafields |
1229 | - if (! $error) { |
|
1230 | - $result=$this->deleteExtraFields(); |
|
1229 | + if (!$error) { |
|
1230 | + $result = $this->deleteExtraFields(); |
|
1231 | 1231 | if ($result < 0) |
1232 | 1232 | { |
1233 | 1233 | $error++; |
@@ -1235,33 +1235,33 @@ discard block |
||
1235 | 1235 | } |
1236 | 1236 | } |
1237 | 1237 | |
1238 | - if (! $error) |
|
1238 | + if (!$error) |
|
1239 | 1239 | { |
1240 | 1240 | // We remove directory |
1241 | 1241 | $ref = dol_sanitizeFileName($this->ref); |
1242 | 1242 | if ($conf->contrat->dir_output) |
1243 | 1243 | { |
1244 | - $dir = $conf->contrat->dir_output . "/" . $ref; |
|
1244 | + $dir = $conf->contrat->dir_output."/".$ref; |
|
1245 | 1245 | if (file_exists($dir)) |
1246 | 1246 | { |
1247 | - $res=@dol_delete_dir_recursive($dir); |
|
1248 | - if (! $res) |
|
1247 | + $res = @dol_delete_dir_recursive($dir); |
|
1248 | + if (!$res) |
|
1249 | 1249 | { |
1250 | - $this->error='ErrorFailToDeleteDir'; |
|
1250 | + $this->error = 'ErrorFailToDeleteDir'; |
|
1251 | 1251 | $error++; |
1252 | 1252 | } |
1253 | 1253 | } |
1254 | 1254 | } |
1255 | 1255 | } |
1256 | 1256 | |
1257 | - if (! $error) |
|
1257 | + if (!$error) |
|
1258 | 1258 | { |
1259 | 1259 | $this->db->commit(); |
1260 | 1260 | return 1; |
1261 | 1261 | } |
1262 | 1262 | else |
1263 | 1263 | { |
1264 | - $this->error=$this->db->lasterror(); |
|
1264 | + $this->error = $this->db->lasterror(); |
|
1265 | 1265 | $this->db->rollback(); |
1266 | 1266 | return -1; |
1267 | 1267 | } |
@@ -1274,27 +1274,27 @@ discard block |
||
1274 | 1274 | * @param int $notrigger 0=launch triggers after, 1=disable triggers |
1275 | 1275 | * @return int <0 if KO, >0 if OK |
1276 | 1276 | */ |
1277 | - function update($user=null, $notrigger=0) |
|
1277 | + function update($user = null, $notrigger = 0) |
|
1278 | 1278 | { |
1279 | 1279 | global $conf, $langs; |
1280 | - $error=0; |
|
1280 | + $error = 0; |
|
1281 | 1281 | |
1282 | 1282 | // Clean parameters |
1283 | - if (isset($this->ref)) $this->ref=trim($this->ref); |
|
1284 | - if (isset($this->ref_customer)) $this->ref_customer=trim($this->ref_customer); |
|
1285 | - if (isset($this->ref_supplier)) $this->ref_supplier=trim($this->ref_supplier); |
|
1286 | - if (isset($this->ref_ext)) $this->ref_ext=trim($this->ref_ext); |
|
1287 | - if (isset($this->entity)) $this->entity=trim($this->entity); |
|
1288 | - if (isset($this->statut)) $this->statut=(int) $this->statut; |
|
1289 | - if (isset($this->fk_soc)) $this->fk_soc=trim($this->fk_soc); |
|
1290 | - if (isset($this->fk_projet)) $this->fk_projet=trim($this->fk_projet); |
|
1291 | - if (isset($this->fk_commercial_signature)) $this->fk_commercial_signature=trim($this->fk_commercial_signature); |
|
1292 | - if (isset($this->fk_commercial_suivi)) $this->fk_commercial_suivi=trim($this->fk_commercial_suivi); |
|
1293 | - if (isset($this->fk_user_mise_en_service)) $this->fk_user_mise_en_service=trim($this->fk_user_mise_en_service); |
|
1294 | - if (isset($this->fk_user_cloture)) $this->fk_user_cloture=trim($this->fk_user_cloture); |
|
1295 | - if (isset($this->note_private)) $this->note_private=trim($this->note_private); |
|
1296 | - if (isset($this->note_public)) $this->note_public=trim($this->note_public); |
|
1297 | - if (isset($this->import_key)) $this->import_key=trim($this->import_key); |
|
1283 | + if (isset($this->ref)) $this->ref = trim($this->ref); |
|
1284 | + if (isset($this->ref_customer)) $this->ref_customer = trim($this->ref_customer); |
|
1285 | + if (isset($this->ref_supplier)) $this->ref_supplier = trim($this->ref_supplier); |
|
1286 | + if (isset($this->ref_ext)) $this->ref_ext = trim($this->ref_ext); |
|
1287 | + if (isset($this->entity)) $this->entity = trim($this->entity); |
|
1288 | + if (isset($this->statut)) $this->statut = (int) $this->statut; |
|
1289 | + if (isset($this->fk_soc)) $this->fk_soc = trim($this->fk_soc); |
|
1290 | + if (isset($this->fk_projet)) $this->fk_projet = trim($this->fk_projet); |
|
1291 | + if (isset($this->fk_commercial_signature)) $this->fk_commercial_signature = trim($this->fk_commercial_signature); |
|
1292 | + if (isset($this->fk_commercial_suivi)) $this->fk_commercial_suivi = trim($this->fk_commercial_suivi); |
|
1293 | + if (isset($this->fk_user_mise_en_service)) $this->fk_user_mise_en_service = trim($this->fk_user_mise_en_service); |
|
1294 | + if (isset($this->fk_user_cloture)) $this->fk_user_cloture = trim($this->fk_user_cloture); |
|
1295 | + if (isset($this->note_private)) $this->note_private = trim($this->note_private); |
|
1296 | + if (isset($this->note_public)) $this->note_public = trim($this->note_public); |
|
1297 | + if (isset($this->import_key)) $this->import_key = trim($this->import_key); |
|
1298 | 1298 | //if (isset($this->extraparams)) $this->extraparams=trim($this->extraparams); |
1299 | 1299 | |
1300 | 1300 | // Check parameters |
@@ -1302,36 +1302,36 @@ discard block |
||
1302 | 1302 | |
1303 | 1303 | // Update request |
1304 | 1304 | $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET"; |
1305 | - $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; |
|
1306 | - $sql.= " ref_customer=".(isset($this->ref_customer)?"'".$this->db->escape($this->ref_customer)."'":"null").","; |
|
1307 | - $sql.= " ref_supplier=".(isset($this->ref_supplier)?"'".$this->db->escape($this->ref_supplier)."'":"null").","; |
|
1308 | - $sql.= " ref_ext=".(isset($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null").","; |
|
1309 | - $sql.= " entity=".$conf->entity.","; |
|
1310 | - $sql.= " date_contrat=".(dol_strlen($this->date_contrat)!=0 ? "'".$this->db->idate($this->date_contrat)."'" : 'null').","; |
|
1311 | - $sql.= " statut=".(isset($this->statut)?$this->statut:"null").","; |
|
1312 | - $sql.= " mise_en_service=".(dol_strlen($this->mise_en_service)!=0 ? "'".$this->db->idate($this->mise_en_service)."'" : 'null').","; |
|
1313 | - $sql.= " fin_validite=".(dol_strlen($this->fin_validite)!=0 ? "'".$this->db->idate($this->fin_validite)."'" : 'null').","; |
|
1314 | - $sql.= " date_cloture=".(dol_strlen($this->date_cloture)!=0 ? "'".$this->db->idate($this->date_cloture)."'" : 'null').","; |
|
1315 | - $sql.= " fk_soc=".(isset($this->fk_soc)?$this->fk_soc:"null").","; |
|
1316 | - $sql.= " fk_projet=".(isset($this->fk_projet)?$this->fk_projet:"null").","; |
|
1317 | - $sql.= " fk_commercial_signature=".(isset($this->fk_commercial_signature)?$this->fk_commercial_signature:"null").","; |
|
1318 | - $sql.= " fk_commercial_suivi=".(isset($this->fk_commercial_suivi)?$this->fk_commercial_suivi:"null").","; |
|
1319 | - $sql.= " fk_user_mise_en_service=".(isset($this->fk_user_mise_en_service)?$this->fk_user_mise_en_service:"null").","; |
|
1320 | - $sql.= " fk_user_cloture=".(isset($this->fk_user_cloture)?$this->fk_user_cloture:"null").","; |
|
1321 | - $sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").","; |
|
1322 | - $sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").","; |
|
1323 | - $sql.= " import_key=".(isset($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null").""; |
|
1305 | + $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; |
|
1306 | + $sql .= " ref_customer=".(isset($this->ref_customer) ? "'".$this->db->escape($this->ref_customer)."'" : "null").","; |
|
1307 | + $sql .= " ref_supplier=".(isset($this->ref_supplier) ? "'".$this->db->escape($this->ref_supplier)."'" : "null").","; |
|
1308 | + $sql .= " ref_ext=".(isset($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").","; |
|
1309 | + $sql .= " entity=".$conf->entity.","; |
|
1310 | + $sql .= " date_contrat=".(dol_strlen($this->date_contrat) != 0 ? "'".$this->db->idate($this->date_contrat)."'" : 'null').","; |
|
1311 | + $sql .= " statut=".(isset($this->statut) ? $this->statut : "null").","; |
|
1312 | + $sql .= " mise_en_service=".(dol_strlen($this->mise_en_service) != 0 ? "'".$this->db->idate($this->mise_en_service)."'" : 'null').","; |
|
1313 | + $sql .= " fin_validite=".(dol_strlen($this->fin_validite) != 0 ? "'".$this->db->idate($this->fin_validite)."'" : 'null').","; |
|
1314 | + $sql .= " date_cloture=".(dol_strlen($this->date_cloture) != 0 ? "'".$this->db->idate($this->date_cloture)."'" : 'null').","; |
|
1315 | + $sql .= " fk_soc=".(isset($this->fk_soc) ? $this->fk_soc : "null").","; |
|
1316 | + $sql .= " fk_projet=".(isset($this->fk_projet) ? $this->fk_projet : "null").","; |
|
1317 | + $sql .= " fk_commercial_signature=".(isset($this->fk_commercial_signature) ? $this->fk_commercial_signature : "null").","; |
|
1318 | + $sql .= " fk_commercial_suivi=".(isset($this->fk_commercial_suivi) ? $this->fk_commercial_suivi : "null").","; |
|
1319 | + $sql .= " fk_user_mise_en_service=".(isset($this->fk_user_mise_en_service) ? $this->fk_user_mise_en_service : "null").","; |
|
1320 | + $sql .= " fk_user_cloture=".(isset($this->fk_user_cloture) ? $this->fk_user_cloture : "null").","; |
|
1321 | + $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; |
|
1322 | + $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; |
|
1323 | + $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null").""; |
|
1324 | 1324 | //$sql.= " extraparams=".(isset($this->extraparams)?"'".$this->db->escape($this->extraparams)."'":"null").""; |
1325 | - $sql.= " WHERE rowid=".$this->id; |
|
1325 | + $sql .= " WHERE rowid=".$this->id; |
|
1326 | 1326 | |
1327 | 1327 | $this->db->begin(); |
1328 | 1328 | |
1329 | 1329 | $resql = $this->db->query($sql); |
1330 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
1330 | + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } |
|
1331 | 1331 | |
1332 | - if (! $error) |
|
1332 | + if (!$error) |
|
1333 | 1333 | { |
1334 | - if (! $notrigger) |
|
1334 | + if (!$notrigger) |
|
1335 | 1335 | { |
1336 | 1336 | // Uncomment this and change MYOBJECT to your own tag if you |
1337 | 1337 | // want this action calls a trigger. |
@@ -1343,18 +1343,18 @@ discard block |
||
1343 | 1343 | } |
1344 | 1344 | } |
1345 | 1345 | |
1346 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used |
|
1346 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) // For avoid conflicts if trigger used |
|
1347 | 1347 | { |
1348 | - $result=$this->insertExtraFields(); |
|
1348 | + $result = $this->insertExtraFields(); |
|
1349 | 1349 | if ($result < 0) |
1350 | 1350 | { |
1351 | 1351 | $error++; |
1352 | 1352 | } |
1353 | 1353 | } |
1354 | 1354 | |
1355 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used |
|
1355 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) // For avoid conflicts if trigger used |
|
1356 | 1356 | { |
1357 | - $result=$this->insertExtraFields(); |
|
1357 | + $result = $this->insertExtraFields(); |
|
1358 | 1358 | if ($result < 0) |
1359 | 1359 | { |
1360 | 1360 | $error++; |
@@ -1364,13 +1364,13 @@ discard block |
||
1364 | 1364 | // Commit or rollback |
1365 | 1365 | if ($error) |
1366 | 1366 | { |
1367 | - foreach($this->errors as $errmsg) |
|
1367 | + foreach ($this->errors as $errmsg) |
|
1368 | 1368 | { |
1369 | 1369 | dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); |
1370 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
1370 | + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); |
|
1371 | 1371 | } |
1372 | 1372 | $this->db->rollback(); |
1373 | - return -1*$error; |
|
1373 | + return -1 * $error; |
|
1374 | 1374 | } |
1375 | 1375 | else |
1376 | 1376 | { |
@@ -1402,7 +1402,7 @@ discard block |
||
1402 | 1402 | * @param string $fk_unit Code of the unit to use. Null to use the default one |
1403 | 1403 | * @return int <0 si erreur, >0 si ok |
1404 | 1404 | */ |
1405 | - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $fk_fournprice=null, $pa_ht = 0,$array_options=0, $fk_unit = null) |
|
1405 | + function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type = 'HT', $pu_ttc = 0.0, $info_bits = 0, $fk_fournprice = null, $pa_ht = 0, $array_options = 0, $fk_unit = null) |
|
1406 | 1406 | { |
1407 | 1407 | global $user, $langs, $conf, $mysoc; |
1408 | 1408 | |
@@ -1413,58 +1413,58 @@ discard block |
||
1413 | 1413 | $this->db->begin(); |
1414 | 1414 | |
1415 | 1415 | // Clean parameters |
1416 | - $pu_ht=price2num($pu_ht); |
|
1417 | - $pu_ttc=price2num($pu_ttc); |
|
1418 | - $pa_ht=price2num($pa_ht); |
|
1419 | - $txtva=price2num($txtva); |
|
1420 | - $txlocaltax1=price2num($txlocaltax1); |
|
1421 | - $txlocaltax2=price2num($txlocaltax2); |
|
1422 | - $remise_percent=price2num($remise_percent); |
|
1423 | - $qty=price2num($qty); |
|
1424 | - if (empty($qty)) $qty=1; |
|
1425 | - if (empty($info_bits)) $info_bits=0; |
|
1426 | - if (empty($pu_ht) || ! is_numeric($pu_ht)) $pu_ht=0; |
|
1427 | - if (empty($pu_ttc)) $pu_ttc=0; |
|
1428 | - if (empty($txtva) || ! is_numeric($txtva)) $txtva=0; |
|
1429 | - if (empty($txlocaltax1) || ! is_numeric($txlocaltax1)) $txlocaltax1=0; |
|
1430 | - if (empty($txlocaltax2) || ! is_numeric($txlocaltax2)) $txlocaltax2=0; |
|
1431 | - |
|
1432 | - if ($price_base_type=='HT') |
|
1416 | + $pu_ht = price2num($pu_ht); |
|
1417 | + $pu_ttc = price2num($pu_ttc); |
|
1418 | + $pa_ht = price2num($pa_ht); |
|
1419 | + $txtva = price2num($txtva); |
|
1420 | + $txlocaltax1 = price2num($txlocaltax1); |
|
1421 | + $txlocaltax2 = price2num($txlocaltax2); |
|
1422 | + $remise_percent = price2num($remise_percent); |
|
1423 | + $qty = price2num($qty); |
|
1424 | + if (empty($qty)) $qty = 1; |
|
1425 | + if (empty($info_bits)) $info_bits = 0; |
|
1426 | + if (empty($pu_ht) || !is_numeric($pu_ht)) $pu_ht = 0; |
|
1427 | + if (empty($pu_ttc)) $pu_ttc = 0; |
|
1428 | + if (empty($txtva) || !is_numeric($txtva)) $txtva = 0; |
|
1429 | + if (empty($txlocaltax1) || !is_numeric($txlocaltax1)) $txlocaltax1 = 0; |
|
1430 | + if (empty($txlocaltax2) || !is_numeric($txlocaltax2)) $txlocaltax2 = 0; |
|
1431 | + |
|
1432 | + if ($price_base_type == 'HT') |
|
1433 | 1433 | { |
1434 | - $pu=$pu_ht; |
|
1434 | + $pu = $pu_ht; |
|
1435 | 1435 | } |
1436 | 1436 | else |
1437 | 1437 | { |
1438 | - $pu=$pu_ttc; |
|
1438 | + $pu = $pu_ttc; |
|
1439 | 1439 | } |
1440 | 1440 | |
1441 | 1441 | // Check parameters |
1442 | - if (empty($remise_percent)) $remise_percent=0; |
|
1442 | + if (empty($remise_percent)) $remise_percent = 0; |
|
1443 | 1443 | |
1444 | 1444 | // Calcul du total TTC et de la TVA pour la ligne a partir de |
1445 | 1445 | // qty, pu, remise_percent et txtva |
1446 | 1446 | // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker |
1447 | 1447 | // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. |
1448 | 1448 | |
1449 | - $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->societe, $mysoc); |
|
1449 | + $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->societe, $mysoc); |
|
1450 | 1450 | |
1451 | 1451 | // Clean vat code |
1452 | - $vat_src_code=''; |
|
1452 | + $vat_src_code = ''; |
|
1453 | 1453 | if (preg_match('/\((.*)\)/', $txtva, $reg)) |
1454 | 1454 | { |
1455 | 1455 | $vat_src_code = $reg[1]; |
1456 | - $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. |
|
1456 | + $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. |
|
1457 | 1457 | } |
1458 | 1458 | |
1459 | - $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1,$mysoc, $localtaxes_type); |
|
1459 | + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1, $mysoc, $localtaxes_type); |
|
1460 | 1460 | $total_ht = $tabprice[0]; |
1461 | 1461 | $total_tva = $tabprice[1]; |
1462 | 1462 | $total_ttc = $tabprice[2]; |
1463 | - $total_localtax1= $tabprice[9]; |
|
1464 | - $total_localtax2= $tabprice[10]; |
|
1463 | + $total_localtax1 = $tabprice[9]; |
|
1464 | + $total_localtax2 = $tabprice[10]; |
|
1465 | 1465 | |
1466 | - $localtax1_type=$localtaxes_type[0]; |
|
1467 | - $localtax2_type=$localtaxes_type[2]; |
|
1466 | + $localtax1_type = $localtaxes_type[0]; |
|
1467 | + $localtax2_type = $localtaxes_type[2]; |
|
1468 | 1468 | |
1469 | 1469 | // TODO A virer |
1470 | 1470 | // Anciens indicateurs: $price, $remise (a ne plus utiliser) |
@@ -1476,7 +1476,7 @@ discard block |
||
1476 | 1476 | $price = $pu_ht - $remise; |
1477 | 1477 | } |
1478 | 1478 | |
1479 | - if (empty($pa_ht)) $pa_ht=0; |
|
1479 | + if (empty($pa_ht)) $pa_ht = 0; |
|
1480 | 1480 | |
1481 | 1481 | |
1482 | 1482 | // if buy price not defined, define buyprice as configured in margin admin |
@@ -1494,63 +1494,63 @@ discard block |
||
1494 | 1494 | |
1495 | 1495 | // Insertion dans la base |
1496 | 1496 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet"; |
1497 | - $sql.= " (fk_contrat, label, description, fk_product, qty, tva_tx, vat_src_code,"; |
|
1498 | - $sql.= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice,"; |
|
1499 | - $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,"; |
|
1500 | - $sql.= " info_bits,"; |
|
1501 | - $sql.= " price_ht, remise, fk_product_fournisseur_price, buy_price_ht"; |
|
1502 | - if ($date_start > 0) { $sql.= ",date_ouverture_prevue"; } |
|
1503 | - if ($date_end > 0) { $sql.= ",date_fin_validite"; } |
|
1504 | - $sql.= ", fk_unit"; |
|
1505 | - $sql.= ") VALUES ("; |
|
1506 | - $sql.= $this->id.", '', '" . $this->db->escape($desc) . "',"; |
|
1507 | - $sql.= ($fk_product>0 ? $fk_product : "null").","; |
|
1508 | - $sql.= " ".$qty.","; |
|
1509 | - $sql.= " ".$txtva.","; |
|
1510 | - $sql.= " ".($vat_src_code?"'".$vat_src_code."'":"null").","; |
|
1511 | - $sql.= " ".$txlocaltax1.","; |
|
1512 | - $sql.= " ".$txlocaltax2.","; |
|
1513 | - $sql.= " '".$localtax1_type."',"; |
|
1514 | - $sql.= " '".$localtax2_type."',"; |
|
1515 | - $sql.= " ".price2num($remise_percent).","; |
|
1516 | - $sql.= " ".price2num($pu_ht).","; |
|
1517 | - $sql.= " ".price2num($total_ht).",".price2num($total_tva).",".price2num($total_localtax1).",".price2num($total_localtax2).",".price2num($total_ttc).","; |
|
1518 | - $sql.= " '".$info_bits."',"; |
|
1519 | - $sql.= " ".price2num($price).",".price2num($remise).","; |
|
1520 | - if (isset($fk_fournprice)) $sql.= ' '.$fk_fournprice.','; |
|
1521 | - else $sql.= ' null,'; |
|
1522 | - if (isset($pa_ht)) $sql.= ' '.price2num($pa_ht); |
|
1523 | - else $sql.= ' null'; |
|
1524 | - if ($date_start > 0) { $sql.= ",'".$this->db->idate($date_start)."'"; } |
|
1525 | - if ($date_end > 0) { $sql.= ",'".$this->db->idate($date_end)."'"; } |
|
1526 | - $sql.= ", ".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null"); |
|
1527 | - $sql.= ")"; |
|
1528 | - |
|
1529 | - $resql=$this->db->query($sql); |
|
1497 | + $sql .= " (fk_contrat, label, description, fk_product, qty, tva_tx, vat_src_code,"; |
|
1498 | + $sql .= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice,"; |
|
1499 | + $sql .= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,"; |
|
1500 | + $sql .= " info_bits,"; |
|
1501 | + $sql .= " price_ht, remise, fk_product_fournisseur_price, buy_price_ht"; |
|
1502 | + if ($date_start > 0) { $sql .= ",date_ouverture_prevue"; } |
|
1503 | + if ($date_end > 0) { $sql .= ",date_fin_validite"; } |
|
1504 | + $sql .= ", fk_unit"; |
|
1505 | + $sql .= ") VALUES ("; |
|
1506 | + $sql .= $this->id.", '', '".$this->db->escape($desc)."',"; |
|
1507 | + $sql .= ($fk_product > 0 ? $fk_product : "null").","; |
|
1508 | + $sql .= " ".$qty.","; |
|
1509 | + $sql .= " ".$txtva.","; |
|
1510 | + $sql .= " ".($vat_src_code ? "'".$vat_src_code."'" : "null").","; |
|
1511 | + $sql .= " ".$txlocaltax1.","; |
|
1512 | + $sql .= " ".$txlocaltax2.","; |
|
1513 | + $sql .= " '".$localtax1_type."',"; |
|
1514 | + $sql .= " '".$localtax2_type."',"; |
|
1515 | + $sql .= " ".price2num($remise_percent).","; |
|
1516 | + $sql .= " ".price2num($pu_ht).","; |
|
1517 | + $sql .= " ".price2num($total_ht).",".price2num($total_tva).",".price2num($total_localtax1).",".price2num($total_localtax2).",".price2num($total_ttc).","; |
|
1518 | + $sql .= " '".$info_bits."',"; |
|
1519 | + $sql .= " ".price2num($price).",".price2num($remise).","; |
|
1520 | + if (isset($fk_fournprice)) $sql .= ' '.$fk_fournprice.','; |
|
1521 | + else $sql .= ' null,'; |
|
1522 | + if (isset($pa_ht)) $sql .= ' '.price2num($pa_ht); |
|
1523 | + else $sql .= ' null'; |
|
1524 | + if ($date_start > 0) { $sql .= ",'".$this->db->idate($date_start)."'"; } |
|
1525 | + if ($date_end > 0) { $sql .= ",'".$this->db->idate($date_end)."'"; } |
|
1526 | + $sql .= ", ".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null"); |
|
1527 | + $sql .= ")"; |
|
1528 | + |
|
1529 | + $resql = $this->db->query($sql); |
|
1530 | 1530 | if ($resql) |
1531 | 1531 | { |
1532 | 1532 | $contractlineid = $this->db->last_insert_id(MAIN_DB_PREFIX."contratdet"); |
1533 | 1533 | |
1534 | - $result=$this->update_statut($user); |
|
1534 | + $result = $this->update_statut($user); |
|
1535 | 1535 | if ($result > 0) |
1536 | 1536 | { |
1537 | 1537 | |
1538 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used |
|
1538 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used |
|
1539 | 1539 | { |
1540 | 1540 | $contractline = new ContratLigne($this->db); |
1541 | - $contractline->array_options=$array_options; |
|
1542 | - $contractline->id=$contractlineid; |
|
1543 | - $result=$contractline->insertExtraFields(); |
|
1541 | + $contractline->array_options = $array_options; |
|
1542 | + $contractline->id = $contractlineid; |
|
1543 | + $result = $contractline->insertExtraFields(); |
|
1544 | 1544 | if ($result < 0) |
1545 | 1545 | { |
1546 | - $this->error[]=$contractline->error; |
|
1546 | + $this->error[] = $contractline->error; |
|
1547 | 1547 | $error++; |
1548 | 1548 | } |
1549 | 1549 | } |
1550 | 1550 | |
1551 | 1551 | if (empty($error)) { |
1552 | 1552 | // Call trigger |
1553 | - $result=$this->call_trigger('LINECONTRACT_INSERT',$user); |
|
1553 | + $result = $this->call_trigger('LINECONTRACT_INSERT', $user); |
|
1554 | 1554 | if ($result < 0) |
1555 | 1555 | { |
1556 | 1556 | $error++; |
@@ -1578,7 +1578,7 @@ discard block |
||
1578 | 1578 | else |
1579 | 1579 | { |
1580 | 1580 | $this->db->rollback(); |
1581 | - $this->error=$this->db->error()." sql=".$sql; |
|
1581 | + $this->error = $this->db->error()." sql=".$sql; |
|
1582 | 1582 | return -1; |
1583 | 1583 | } |
1584 | 1584 | } |
@@ -1612,19 +1612,19 @@ discard block |
||
1612 | 1612 | * @param string $fk_unit Code of the unit to use. Null to use the default one |
1613 | 1613 | * @return int < 0 si erreur, > 0 si ok |
1614 | 1614 | */ |
1615 | - function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $tvatx, $localtax1tx=0.0, $localtax2tx=0.0, $date_debut_reel='', $date_fin_reel='', $price_base_type='HT', $info_bits=0, $fk_fournprice=null, $pa_ht = 0,$array_options=0, $fk_unit = null) |
|
1615 | + function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $tvatx, $localtax1tx = 0.0, $localtax2tx = 0.0, $date_debut_reel = '', $date_fin_reel = '', $price_base_type = 'HT', $info_bits = 0, $fk_fournprice = null, $pa_ht = 0, $array_options = 0, $fk_unit = null) |
|
1616 | 1616 | { |
1617 | 1617 | global $user, $conf, $langs, $mysoc; |
1618 | 1618 | |
1619 | 1619 | // Nettoyage parametres |
1620 | - $qty=trim($qty); |
|
1621 | - $desc=trim($desc); |
|
1622 | - $desc=trim($desc); |
|
1620 | + $qty = trim($qty); |
|
1621 | + $desc = trim($desc); |
|
1622 | + $desc = trim($desc); |
|
1623 | 1623 | $price = price2num($pu); |
1624 | 1624 | $tvatx = price2num($tvatx); |
1625 | 1625 | $localtax1tx = price2num($localtax1tx); |
1626 | 1626 | $localtax2tx = price2num($localtax2tx); |
1627 | - $pa_ht=price2num($pa_ht); |
|
1627 | + $pa_ht = price2num($pa_ht); |
|
1628 | 1628 | |
1629 | 1629 | $subprice = $price; |
1630 | 1630 | $remise = 0; |
@@ -1635,7 +1635,7 @@ discard block |
||
1635 | 1635 | } |
1636 | 1636 | else |
1637 | 1637 | { |
1638 | - $remise_percent=0; |
|
1638 | + $remise_percent = 0; |
|
1639 | 1639 | } |
1640 | 1640 | |
1641 | 1641 | dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $date_debut_reel, $date_fin_reel, $tvatx, $localtax1tx, $localtax2tx, $price_base_type, $info_bits"); |
@@ -1647,18 +1647,18 @@ discard block |
||
1647 | 1647 | // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker |
1648 | 1648 | // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. |
1649 | 1649 | |
1650 | - $localtaxes_type=getLocalTaxesFromRate($tvatx, 0, $this->societe, $mysoc); |
|
1651 | - $tvatx = preg_replace('/\s*\(.*\)/','',$tvatx); // Remove code into vatrate. |
|
1650 | + $localtaxes_type = getLocalTaxesFromRate($tvatx, 0, $this->societe, $mysoc); |
|
1651 | + $tvatx = preg_replace('/\s*\(.*\)/', '', $tvatx); // Remove code into vatrate. |
|
1652 | 1652 | |
1653 | - $tabprice=calcul_price_total($qty, $pu, $remise_percent, $tvatx, $localtax1tx, $localtax2tx, 0, $price_base_type, $info_bits, 1, $mysoc, $localtaxes_type); |
|
1653 | + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $tvatx, $localtax1tx, $localtax2tx, 0, $price_base_type, $info_bits, 1, $mysoc, $localtaxes_type); |
|
1654 | 1654 | $total_ht = $tabprice[0]; |
1655 | 1655 | $total_tva = $tabprice[1]; |
1656 | 1656 | $total_ttc = $tabprice[2]; |
1657 | - $total_localtax1= $tabprice[9]; |
|
1658 | - $total_localtax2= $tabprice[10]; |
|
1657 | + $total_localtax1 = $tabprice[9]; |
|
1658 | + $total_localtax2 = $tabprice[10]; |
|
1659 | 1659 | |
1660 | - $localtax1_type=$localtaxes_type[0]; |
|
1661 | - $localtax2_type=$localtaxes_type[2]; |
|
1660 | + $localtax1_type = $localtaxes_type[0]; |
|
1661 | + $localtax2_type = $localtaxes_type[2]; |
|
1662 | 1662 | |
1663 | 1663 | // TODO A virer |
1664 | 1664 | // Anciens indicateurs: $price, $remise (a ne plus utiliser) |
@@ -1670,7 +1670,7 @@ discard block |
||
1670 | 1670 | $price = $pu - $remise; |
1671 | 1671 | } |
1672 | 1672 | |
1673 | - if (empty($pa_ht)) $pa_ht=0; |
|
1673 | + if (empty($pa_ht)) $pa_ht = 0; |
|
1674 | 1674 | |
1675 | 1675 | // if buy price not defined, define buyprice as configured in margin admin |
1676 | 1676 | if ($this->pa_ht == 0) |
@@ -1686,58 +1686,58 @@ discard block |
||
1686 | 1686 | } |
1687 | 1687 | |
1688 | 1688 | $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet set description='".$this->db->escape($desc)."'"; |
1689 | - $sql.= ",price_ht='" . price2num($price)."'"; |
|
1690 | - $sql.= ",subprice='" . price2num($subprice)."'"; |
|
1691 | - $sql.= ",remise='" . price2num($remise)."'"; |
|
1692 | - $sql.= ",remise_percent='".price2num($remise_percent)."'"; |
|
1693 | - $sql.= ",qty='".$qty."'"; |
|
1694 | - $sql.= ",tva_tx='". price2num($tvatx)."'"; |
|
1695 | - $sql.= ",localtax1_tx='". price2num($localtax1tx)."'"; |
|
1696 | - $sql.= ",localtax2_tx='". price2num($localtax2tx)."'"; |
|
1697 | - $sql.= ",localtax1_type='".$localtax1_type."'"; |
|
1698 | - $sql.= ",localtax2_type='".$localtax2_type."'"; |
|
1699 | - $sql.= ", total_ht='". price2num($total_ht)."'"; |
|
1700 | - $sql.= ", total_tva='". price2num($total_tva)."'"; |
|
1701 | - $sql.= ", total_localtax1='".price2num($total_localtax1)."'"; |
|
1702 | - $sql.= ", total_localtax2='".price2num($total_localtax2)."'"; |
|
1703 | - $sql.= ", total_ttc='". price2num($total_ttc)."'"; |
|
1704 | - $sql.= ", fk_product_fournisseur_price='".$fk_fournprice."'"; |
|
1705 | - $sql.= ", buy_price_ht='".price2num($pa_ht)."'"; |
|
1706 | - if ($date_start > 0) { $sql.= ",date_ouverture_prevue='".$this->db->idate($date_start)."'"; } |
|
1707 | - else { $sql.=",date_ouverture_prevue=null"; } |
|
1708 | - if ($date_end > 0) { $sql.= ",date_fin_validite='".$this->db->idate($date_end)."'"; } |
|
1709 | - else { $sql.=",date_fin_validite=null"; } |
|
1710 | - if ($date_debut_reel > 0) { $sql.= ",date_ouverture='".$this->db->idate($date_debut_reel)."'"; } |
|
1711 | - else { $sql.=",date_ouverture=null"; } |
|
1712 | - if ($date_fin_reel > 0) { $sql.= ",date_cloture='".$this->db->idate($date_fin_reel)."'"; } |
|
1713 | - else { $sql.=",date_cloture=null"; } |
|
1714 | - $sql .= ", fk_unit=".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null"); |
|
1689 | + $sql .= ",price_ht='".price2num($price)."'"; |
|
1690 | + $sql .= ",subprice='".price2num($subprice)."'"; |
|
1691 | + $sql .= ",remise='".price2num($remise)."'"; |
|
1692 | + $sql .= ",remise_percent='".price2num($remise_percent)."'"; |
|
1693 | + $sql .= ",qty='".$qty."'"; |
|
1694 | + $sql .= ",tva_tx='".price2num($tvatx)."'"; |
|
1695 | + $sql .= ",localtax1_tx='".price2num($localtax1tx)."'"; |
|
1696 | + $sql .= ",localtax2_tx='".price2num($localtax2tx)."'"; |
|
1697 | + $sql .= ",localtax1_type='".$localtax1_type."'"; |
|
1698 | + $sql .= ",localtax2_type='".$localtax2_type."'"; |
|
1699 | + $sql .= ", total_ht='".price2num($total_ht)."'"; |
|
1700 | + $sql .= ", total_tva='".price2num($total_tva)."'"; |
|
1701 | + $sql .= ", total_localtax1='".price2num($total_localtax1)."'"; |
|
1702 | + $sql .= ", total_localtax2='".price2num($total_localtax2)."'"; |
|
1703 | + $sql .= ", total_ttc='".price2num($total_ttc)."'"; |
|
1704 | + $sql .= ", fk_product_fournisseur_price='".$fk_fournprice."'"; |
|
1705 | + $sql .= ", buy_price_ht='".price2num($pa_ht)."'"; |
|
1706 | + if ($date_start > 0) { $sql .= ",date_ouverture_prevue='".$this->db->idate($date_start)."'"; } |
|
1707 | + else { $sql .= ",date_ouverture_prevue=null"; } |
|
1708 | + if ($date_end > 0) { $sql .= ",date_fin_validite='".$this->db->idate($date_end)."'"; } |
|
1709 | + else { $sql .= ",date_fin_validite=null"; } |
|
1710 | + if ($date_debut_reel > 0) { $sql .= ",date_ouverture='".$this->db->idate($date_debut_reel)."'"; } |
|
1711 | + else { $sql .= ",date_ouverture=null"; } |
|
1712 | + if ($date_fin_reel > 0) { $sql .= ",date_cloture='".$this->db->idate($date_fin_reel)."'"; } |
|
1713 | + else { $sql .= ",date_cloture=null"; } |
|
1714 | + $sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null"); |
|
1715 | 1715 | $sql .= " WHERE rowid = ".$rowid; |
1716 | 1716 | |
1717 | 1717 | dol_syslog(get_class($this)."::updateline", LOG_DEBUG); |
1718 | 1718 | $result = $this->db->query($sql); |
1719 | 1719 | if ($result) |
1720 | 1720 | { |
1721 | - $result=$this->update_statut($user); |
|
1721 | + $result = $this->update_statut($user); |
|
1722 | 1722 | if ($result >= 0) |
1723 | 1723 | { |
1724 | 1724 | |
1725 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used |
|
1725 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used |
|
1726 | 1726 | { |
1727 | 1727 | $contractline = new ContratLigne($this->db); |
1728 | - $contractline->array_options=$array_options; |
|
1729 | - $contractline->id= $rowid; |
|
1730 | - $result=$contractline->insertExtraFields(); |
|
1728 | + $contractline->array_options = $array_options; |
|
1729 | + $contractline->id = $rowid; |
|
1730 | + $result = $contractline->insertExtraFields(); |
|
1731 | 1731 | if ($result < 0) |
1732 | 1732 | { |
1733 | - $this->error[]=$contractline->error; |
|
1733 | + $this->error[] = $contractline->error; |
|
1734 | 1734 | $error++; |
1735 | 1735 | } |
1736 | 1736 | } |
1737 | 1737 | |
1738 | 1738 | if (empty($error)) { |
1739 | 1739 | // Call trigger |
1740 | - $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
1740 | + $result = $this->call_trigger('LINECONTRACT_UPDATE', $user); |
|
1741 | 1741 | if ($result < 0) |
1742 | 1742 | { |
1743 | 1743 | $this->db->rollback(); |
@@ -1759,7 +1759,7 @@ discard block |
||
1759 | 1759 | else |
1760 | 1760 | { |
1761 | 1761 | $this->db->rollback(); |
1762 | - $this->error=$this->db->error(); |
|
1762 | + $this->error = $this->db->error(); |
|
1763 | 1763 | dol_syslog(get_class($this)."::updateligne Erreur -1"); |
1764 | 1764 | return -1; |
1765 | 1765 | } |
@@ -1772,30 +1772,30 @@ discard block |
||
1772 | 1772 | * @param User $user User that delete |
1773 | 1773 | * @return int >0 if OK, <0 if KO |
1774 | 1774 | */ |
1775 | - function deleteline($idline,$user) |
|
1775 | + function deleteline($idline, $user) |
|
1776 | 1776 | { |
1777 | 1777 | global $conf, $langs; |
1778 | 1778 | |
1779 | - $error=0; |
|
1779 | + $error = 0; |
|
1780 | 1780 | |
1781 | 1781 | if ($this->statut >= 0) |
1782 | 1782 | { |
1783 | 1783 | |
1784 | 1784 | // Call trigger |
1785 | - $result=$this->call_trigger('LINECONTRACT_DELETE',$user); |
|
1785 | + $result = $this->call_trigger('LINECONTRACT_DELETE', $user); |
|
1786 | 1786 | if ($result < 0) return -1; |
1787 | 1787 | // End call triggers |
1788 | 1788 | |
1789 | 1789 | $this->db->begin(); |
1790 | 1790 | |
1791 | 1791 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet"; |
1792 | - $sql.= " WHERE rowid=".$idline; |
|
1792 | + $sql .= " WHERE rowid=".$idline; |
|
1793 | 1793 | |
1794 | 1794 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
1795 | 1795 | $resql = $this->db->query($sql); |
1796 | - if (! $resql) |
|
1796 | + if (!$resql) |
|
1797 | 1797 | { |
1798 | - $this->error="Error ".$this->db->lasterror(); |
|
1798 | + $this->error = "Error ".$this->db->lasterror(); |
|
1799 | 1799 | $error++; |
1800 | 1800 | } |
1801 | 1801 | |
@@ -1804,12 +1804,12 @@ discard block |
||
1804 | 1804 | if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used |
1805 | 1805 | { |
1806 | 1806 | $contractline = new ContratLigne($this->db); |
1807 | - $contractline->id= $idline; |
|
1808 | - $result=$contractline->deleteExtraFields(); |
|
1807 | + $contractline->id = $idline; |
|
1808 | + $result = $contractline->deleteExtraFields(); |
|
1809 | 1809 | if ($result < 0) |
1810 | 1810 | { |
1811 | 1811 | $error++; |
1812 | - $this->error="Error ".get_class($this)."::delete deleteExtraFields error -4 ".$contractline->error; |
|
1812 | + $this->error = "Error ".get_class($this)."::delete deleteExtraFields error -4 ".$contractline->error; |
|
1813 | 1813 | } |
1814 | 1814 | } |
1815 | 1815 | } |
@@ -1839,7 +1839,7 @@ discard block |
||
1839 | 1839 | */ |
1840 | 1840 | function update_statut($user) |
1841 | 1841 | { |
1842 | - dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING); |
|
1842 | + dol_syslog(__METHOD__." is deprecated", LOG_WARNING); |
|
1843 | 1843 | |
1844 | 1844 | // If draft, we keep it (should not happen) |
1845 | 1845 | if ($this->statut == 0) return 1; |
@@ -1865,7 +1865,7 @@ discard block |
||
1865 | 1865 | */ |
1866 | 1866 | function getLibStatut($mode) |
1867 | 1867 | { |
1868 | - return $this->LibStatut($this->statut,$mode); |
|
1868 | + return $this->LibStatut($this->statut, $mode); |
|
1869 | 1869 | } |
1870 | 1870 | |
1871 | 1871 | /** |
@@ -1875,7 +1875,7 @@ discard block |
||
1875 | 1875 | * @param int $mode 0=Long label, 1=Short label, 2=Picto + Libelle court, 3=Picto, 4=Picto + Long label of all services, 5=Libelle court + Picto, 6=Picto of all services, 7=Same than 6 with fixed length |
1876 | 1876 | * @return string Label |
1877 | 1877 | */ |
1878 | - function LibStatut($statut,$mode) |
|
1878 | + function LibStatut($statut, $mode) |
|
1879 | 1879 | { |
1880 | 1880 | global $langs; |
1881 | 1881 | $langs->load("contracts"); |
@@ -1893,44 +1893,44 @@ discard block |
||
1893 | 1893 | } |
1894 | 1894 | if ($mode == 2) |
1895 | 1895 | { |
1896 | - if ($statut == 0) { return img_picto($langs->trans('ContractStatusDraft'),'statut0').' '.$langs->trans("ContractStatusDraft"); } |
|
1897 | - if ($statut == 1) { return img_picto($langs->trans('ContractStatusValidated'),'statut4').' '.$langs->trans("ContractStatusValidated"); } |
|
1898 | - if ($statut == 2) { return img_picto($langs->trans('ContractStatusClosed'),'statut6').' '.$langs->trans("ContractStatusClosed"); } |
|
1896 | + if ($statut == 0) { return img_picto($langs->trans('ContractStatusDraft'), 'statut0').' '.$langs->trans("ContractStatusDraft"); } |
|
1897 | + if ($statut == 1) { return img_picto($langs->trans('ContractStatusValidated'), 'statut4').' '.$langs->trans("ContractStatusValidated"); } |
|
1898 | + if ($statut == 2) { return img_picto($langs->trans('ContractStatusClosed'), 'statut6').' '.$langs->trans("ContractStatusClosed"); } |
|
1899 | 1899 | } |
1900 | 1900 | if ($mode == 3) |
1901 | 1901 | { |
1902 | - if ($statut == 0) { return img_picto($langs->trans('ContractStatusDraft'),'statut0'); } |
|
1903 | - if ($statut == 1) { return img_picto($langs->trans('ContractStatusValidated'),'statut4'); } |
|
1904 | - if ($statut == 2) { return img_picto($langs->trans('ContractStatusClosed'),'statut6'); } |
|
1902 | + if ($statut == 0) { return img_picto($langs->trans('ContractStatusDraft'), 'statut0'); } |
|
1903 | + if ($statut == 1) { return img_picto($langs->trans('ContractStatusValidated'), 'statut4'); } |
|
1904 | + if ($statut == 2) { return img_picto($langs->trans('ContractStatusClosed'), 'statut6'); } |
|
1905 | 1905 | } |
1906 | 1906 | if ($mode == 4 || $mode == 6 || $mode == 7) |
1907 | 1907 | { |
1908 | - $line=new ContratLigne($this->db); |
|
1909 | - $text=''; |
|
1908 | + $line = new ContratLigne($this->db); |
|
1909 | + $text = ''; |
|
1910 | 1910 | if ($mode == 4) |
1911 | 1911 | { |
1912 | - $text ='<span class="hideonsmartphone">'; |
|
1913 | - $text.=($this->nbofserviceswait+$this->nbofservicesopened+$this->nbofservicesexpired+$this->nbofservicesclosed); |
|
1914 | - $text.=' '.$langs->trans("Services"); |
|
1915 | - $text.=': '; |
|
1916 | - $text.='</span>'; |
|
1917 | - } |
|
1918 | - $text.=($mode == 7?'<div class="inline-block">':''); |
|
1919 | - $text.=($mode != 7 || $this->nbofserviceswait > 0) ? ($this->nbofserviceswait.$line->LibStatut(0,3,-1,'class="paddingleft2 inline-block valigntextbottom"')).(($mode != 7 || $this->nbofservicesopened || $this->nbofservicesexpired || $this->nbofservicesclosed)?' ':'') : ''; |
|
1920 | - $text.=($mode == 7?'</div><div class="inline-block">':''); |
|
1921 | - $text.=($mode != 7 || $this->nbofservicesopened > 0) ? ($this->nbofservicesopened.$line->LibStatut(4,3,0,'class="paddingleft2 inline-block valigntextbottom"')).(($mode != 7 || $this->nbofservicesexpired || $this->nbofservicesclosed)?' ':'') : ''; |
|
1922 | - $text.=($mode == 7?'</div><div class="inline-block">':''); |
|
1923 | - $text.=($mode != 7 || $this->nbofservicesexpired > 0) ? ($this->nbofservicesexpired.$line->LibStatut(4,3,1,'class="paddingleft2 inline-block valigntextbottom"')).(($mode != 7 || $this->nbofservicesclosed)?' ':'') : ''; |
|
1924 | - $text.=($mode == 7?'</div><div class="inline-block">':''); |
|
1925 | - $text.=($mode != 7 || $this->nbofservicesclosed > 0) ? ($this->nbofservicesclosed.$line->LibStatut(5,3,-1,'class="paddingleft2 inline-block valigntextbottom"')) : ''; |
|
1926 | - $text.=($mode == 7?'</div>':''); |
|
1912 | + $text = '<span class="hideonsmartphone">'; |
|
1913 | + $text .= ($this->nbofserviceswait + $this->nbofservicesopened + $this->nbofservicesexpired + $this->nbofservicesclosed); |
|
1914 | + $text .= ' '.$langs->trans("Services"); |
|
1915 | + $text .= ': '; |
|
1916 | + $text .= '</span>'; |
|
1917 | + } |
|
1918 | + $text .= ($mode == 7 ? '<div class="inline-block">' : ''); |
|
1919 | + $text .= ($mode != 7 || $this->nbofserviceswait > 0) ? ($this->nbofserviceswait.$line->LibStatut(0, 3, -1, 'class="paddingleft2 inline-block valigntextbottom"')).(($mode != 7 || $this->nbofservicesopened || $this->nbofservicesexpired || $this->nbofservicesclosed) ? ' ' : '') : ''; |
|
1920 | + $text .= ($mode == 7 ? '</div><div class="inline-block">' : ''); |
|
1921 | + $text .= ($mode != 7 || $this->nbofservicesopened > 0) ? ($this->nbofservicesopened.$line->LibStatut(4, 3, 0, 'class="paddingleft2 inline-block valigntextbottom"')).(($mode != 7 || $this->nbofservicesexpired || $this->nbofservicesclosed) ? ' ' : '') : ''; |
|
1922 | + $text .= ($mode == 7 ? '</div><div class="inline-block">' : ''); |
|
1923 | + $text .= ($mode != 7 || $this->nbofservicesexpired > 0) ? ($this->nbofservicesexpired.$line->LibStatut(4, 3, 1, 'class="paddingleft2 inline-block valigntextbottom"')).(($mode != 7 || $this->nbofservicesclosed) ? ' ' : '') : ''; |
|
1924 | + $text .= ($mode == 7 ? '</div><div class="inline-block">' : ''); |
|
1925 | + $text .= ($mode != 7 || $this->nbofservicesclosed > 0) ? ($this->nbofservicesclosed.$line->LibStatut(5, 3, -1, 'class="paddingleft2 inline-block valigntextbottom"')) : ''; |
|
1926 | + $text .= ($mode == 7 ? '</div>' : ''); |
|
1927 | 1927 | return $text; |
1928 | 1928 | } |
1929 | 1929 | if ($mode == 5) |
1930 | 1930 | { |
1931 | - if ($statut == 0) { return $langs->trans("ContractStatusDraft").' '.img_picto($langs->trans('ContractStatusDraft'),'statut0'); } |
|
1932 | - if ($statut == 1) { return $langs->trans("ContractStatusValidated").' '.img_picto($langs->trans('ContractStatusValidated'),'statut4'); } |
|
1933 | - if ($statut == 2) { return $langs->trans("ContractStatusClosed").' '.img_picto($langs->trans('ContractStatusClosed'),'statut6'); } |
|
1931 | + if ($statut == 0) { return $langs->trans("ContractStatusDraft").' '.img_picto($langs->trans('ContractStatusDraft'), 'statut0'); } |
|
1932 | + if ($statut == 1) { return $langs->trans("ContractStatusValidated").' '.img_picto($langs->trans('ContractStatusValidated'), 'statut4'); } |
|
1933 | + if ($statut == 2) { return $langs->trans("ContractStatusClosed").' '.img_picto($langs->trans('ContractStatusClosed'), 'statut6'); } |
|
1934 | 1934 | } |
1935 | 1935 | } |
1936 | 1936 | |
@@ -1944,20 +1944,20 @@ discard block |
||
1944 | 1944 | * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
1945 | 1945 | * @return string Chaine avec URL |
1946 | 1946 | */ |
1947 | - function getNomUrl($withpicto=0, $maxlength=0, $notooltip=0, $save_lastsearch_value=-1) |
|
1947 | + function getNomUrl($withpicto = 0, $maxlength = 0, $notooltip = 0, $save_lastsearch_value = -1) |
|
1948 | 1948 | { |
1949 | 1949 | global $conf, $langs, $user; |
1950 | 1950 | |
1951 | - $result=''; |
|
1951 | + $result = ''; |
|
1952 | 1952 | |
1953 | 1953 | $url = DOL_URL_ROOT.'/contrat/card.php?id='.$this->id; |
1954 | 1954 | |
1955 | 1955 | //if ($option !== 'nolink') |
1956 | 1956 | //{ |
1957 | 1957 | // Add param to save lastsearch_values or not |
1958 | - $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); |
|
1959 | - if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; |
|
1960 | - if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; |
|
1958 | + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
|
1959 | + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; |
|
1960 | + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; |
|
1961 | 1961 | //} |
1962 | 1962 | |
1963 | 1963 | $picto = 'contract'; |
@@ -1972,32 +1972,32 @@ discard block |
||
1972 | 1972 | $label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); |
1973 | 1973 | } |
1974 | 1974 | if (!empty($this->total_tva)) { |
1975 | - $label .= '<br><b>'.$langs->trans('VAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); |
|
1975 | + $label .= '<br><b>'.$langs->trans('VAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); |
|
1976 | 1976 | } |
1977 | 1977 | if (!empty($this->total_ttc)) { |
1978 | 1978 | $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); |
1979 | 1979 | } |
1980 | 1980 | } |
1981 | 1981 | |
1982 | - $linkclose=''; |
|
1982 | + $linkclose = ''; |
|
1983 | 1983 | if (empty($notooltip) && $user->rights->contrat->lire) |
1984 | 1984 | { |
1985 | - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
1985 | + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
1986 | 1986 | { |
1987 | - $label=$langs->trans("ShowOrder"); |
|
1988 | - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
1987 | + $label = $langs->trans("ShowOrder"); |
|
1988 | + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
1989 | 1989 | } |
1990 | - $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
1991 | - $linkclose.=' class="classfortooltip"'; |
|
1990 | + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
1991 | + $linkclose .= ' class="classfortooltip"'; |
|
1992 | 1992 | } |
1993 | 1993 | |
1994 | 1994 | $linkstart = '<a href="'.$url.'"'; |
1995 | - $linkstart.=$linkclose.'>'; |
|
1996 | - $linkend='</a>'; |
|
1995 | + $linkstart .= $linkclose.'>'; |
|
1996 | + $linkend = '</a>'; |
|
1997 | 1997 | |
1998 | - if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); |
|
1999 | - if ($withpicto && $withpicto != 2) $result.=' '; |
|
2000 | - $result.=$linkstart.$this->ref.$linkend; |
|
1998 | + if ($withpicto) $result .= ($linkstart.img_object(($notooltip ? '' : $label), $picto, ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend); |
|
1999 | + if ($withpicto && $withpicto != 2) $result .= ' '; |
|
2000 | + $result .= $linkstart.$this->ref.$linkend; |
|
2001 | 2001 | return $result; |
2002 | 2002 | } |
2003 | 2003 | |
@@ -2010,12 +2010,12 @@ discard block |
||
2010 | 2010 | function info($id) |
2011 | 2011 | { |
2012 | 2012 | $sql = "SELECT c.rowid, c.ref, c.datec, c.date_cloture,"; |
2013 | - $sql.= " c.tms as date_modification,"; |
|
2014 | - $sql.= " fk_user_author, fk_user_cloture"; |
|
2015 | - $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c"; |
|
2016 | - $sql.= " WHERE c.rowid = ".$id; |
|
2013 | + $sql .= " c.tms as date_modification,"; |
|
2014 | + $sql .= " fk_user_author, fk_user_cloture"; |
|
2015 | + $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c"; |
|
2016 | + $sql .= " WHERE c.rowid = ".$id; |
|
2017 | 2017 | |
2018 | - $result=$this->db->query($sql); |
|
2018 | + $result = $this->db->query($sql); |
|
2019 | 2019 | if ($result) |
2020 | 2020 | { |
2021 | 2021 | if ($this->db->num_rows($result)) |
@@ -2027,7 +2027,7 @@ discard block |
||
2027 | 2027 | if ($obj->fk_user_author) { |
2028 | 2028 | $cuser = new User($this->db); |
2029 | 2029 | $cuser->fetch($obj->fk_user_author); |
2030 | - $this->user_creation = $cuser; |
|
2030 | + $this->user_creation = $cuser; |
|
2031 | 2031 | } |
2032 | 2032 | |
2033 | 2033 | if ($obj->fk_user_cloture) { |
@@ -2035,7 +2035,7 @@ discard block |
||
2035 | 2035 | $cuser->fetch($obj->fk_user_cloture); |
2036 | 2036 | $this->user_cloture = $cuser; |
2037 | 2037 | } |
2038 | - $this->ref = (! $obj->ref) ? $obj->rowid : $obj->ref; |
|
2038 | + $this->ref = (!$obj->ref) ? $obj->rowid : $obj->ref; |
|
2039 | 2039 | $this->date_creation = $this->db->jdate($obj->datec); |
2040 | 2040 | $this->date_modification = $this->db->jdate($obj->date_modification); |
2041 | 2041 | $this->date_cloture = $this->db->jdate($obj->date_cloture); |
@@ -2056,32 +2056,32 @@ discard block |
||
2056 | 2056 | * @param int $statut Status of lines to get |
2057 | 2057 | * @return array Array of line's rowid |
2058 | 2058 | */ |
2059 | - function array_detail($statut=-1) |
|
2059 | + function array_detail($statut = -1) |
|
2060 | 2060 | { |
2061 | - $tab=array(); |
|
2061 | + $tab = array(); |
|
2062 | 2062 | |
2063 | 2063 | $sql = "SELECT cd.rowid"; |
2064 | - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; |
|
2065 | - $sql.= " WHERE fk_contrat =".$this->id; |
|
2066 | - if ($statut >= 0) $sql.= " AND statut = '$statut'"; |
|
2064 | + $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; |
|
2065 | + $sql .= " WHERE fk_contrat =".$this->id; |
|
2066 | + if ($statut >= 0) $sql .= " AND statut = '$statut'"; |
|
2067 | 2067 | |
2068 | 2068 | dol_syslog(get_class($this)."::array_detail()", LOG_DEBUG); |
2069 | - $resql=$this->db->query($sql); |
|
2069 | + $resql = $this->db->query($sql); |
|
2070 | 2070 | if ($resql) |
2071 | 2071 | { |
2072 | - $num=$this->db->num_rows($resql); |
|
2073 | - $i=0; |
|
2072 | + $num = $this->db->num_rows($resql); |
|
2073 | + $i = 0; |
|
2074 | 2074 | while ($i < $num) |
2075 | 2075 | { |
2076 | 2076 | $obj = $this->db->fetch_object($resql); |
2077 | - $tab[$i]=$obj->rowid; |
|
2077 | + $tab[$i] = $obj->rowid; |
|
2078 | 2078 | $i++; |
2079 | 2079 | } |
2080 | 2080 | return $tab; |
2081 | 2081 | } |
2082 | 2082 | else |
2083 | 2083 | { |
2084 | - $this->error=$this->db->error(); |
|
2084 | + $this->error = $this->db->error(); |
|
2085 | 2085 | return -1; |
2086 | 2086 | } |
2087 | 2087 | } |
@@ -2092,34 +2092,34 @@ discard block |
||
2092 | 2092 | * @param string $option 'all' or 'others' |
2093 | 2093 | * @return array Array of contracts id |
2094 | 2094 | */ |
2095 | - function getListOfContracts($option='all') |
|
2095 | + function getListOfContracts($option = 'all') |
|
2096 | 2096 | { |
2097 | - $tab=array(); |
|
2097 | + $tab = array(); |
|
2098 | 2098 | |
2099 | 2099 | $sql = "SELECT c.rowid, c.ref"; |
2100 | - $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c"; |
|
2101 | - $sql.= " WHERE fk_soc =".$this->socid; |
|
2102 | - if ($option == 'others') $sql.= " AND c.rowid != ".$this->id; |
|
2100 | + $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c"; |
|
2101 | + $sql .= " WHERE fk_soc =".$this->socid; |
|
2102 | + if ($option == 'others') $sql .= " AND c.rowid != ".$this->id; |
|
2103 | 2103 | |
2104 | 2104 | dol_syslog(get_class($this)."::getOtherContracts()", LOG_DEBUG); |
2105 | - $resql=$this->db->query($sql); |
|
2105 | + $resql = $this->db->query($sql); |
|
2106 | 2106 | if ($resql) |
2107 | 2107 | { |
2108 | - $num=$this->db->num_rows($resql); |
|
2109 | - $i=0; |
|
2108 | + $num = $this->db->num_rows($resql); |
|
2109 | + $i = 0; |
|
2110 | 2110 | while ($i < $num) |
2111 | 2111 | { |
2112 | 2112 | $obj = $this->db->fetch_object($resql); |
2113 | - $contrat=new Contrat($this->db); |
|
2113 | + $contrat = new Contrat($this->db); |
|
2114 | 2114 | $contrat->fetch($obj->rowid); |
2115 | - $tab[]=$contrat; |
|
2115 | + $tab[] = $contrat; |
|
2116 | 2116 | $i++; |
2117 | 2117 | } |
2118 | 2118 | return $tab; |
2119 | 2119 | } |
2120 | 2120 | else |
2121 | 2121 | { |
2122 | - $this->error=$this->db->error(); |
|
2122 | + $this->error = $this->db->error(); |
|
2123 | 2123 | return -1; |
2124 | 2124 | } |
2125 | 2125 | } |
@@ -2132,41 +2132,41 @@ discard block |
||
2132 | 2132 | * @param string $mode "inactive" pour services a activer, "expired" pour services expires |
2133 | 2133 | * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK |
2134 | 2134 | */ |
2135 | - function load_board($user,$mode) |
|
2135 | + function load_board($user, $mode) |
|
2136 | 2136 | { |
2137 | 2137 | global $conf, $langs; |
2138 | 2138 | |
2139 | 2139 | $this->from = " FROM ".MAIN_DB_PREFIX."contrat as c"; |
2140 | - $this->from.= ", ".MAIN_DB_PREFIX."contratdet as cd"; |
|
2141 | - $this->from.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
2142 | - if (!$user->rights->societe->client->voir && !$user->societe_id) $this->from.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
2140 | + $this->from .= ", ".MAIN_DB_PREFIX."contratdet as cd"; |
|
2141 | + $this->from .= ", ".MAIN_DB_PREFIX."societe as s"; |
|
2142 | + if (!$user->rights->societe->client->voir && !$user->societe_id) $this->from .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
2143 | 2143 | |
2144 | 2144 | if ($mode == 'inactives') |
2145 | 2145 | { |
2146 | 2146 | $sql = "SELECT cd.rowid, cd.date_ouverture_prevue as datefin"; |
2147 | - $sql.= $this->from; |
|
2148 | - $sql.= " WHERE c.statut = 1"; |
|
2149 | - $sql.= " AND c.rowid = cd.fk_contrat"; |
|
2150 | - $sql.= " AND cd.statut = 0"; |
|
2147 | + $sql .= $this->from; |
|
2148 | + $sql .= " WHERE c.statut = 1"; |
|
2149 | + $sql .= " AND c.rowid = cd.fk_contrat"; |
|
2150 | + $sql .= " AND cd.statut = 0"; |
|
2151 | 2151 | } |
2152 | 2152 | if ($mode == 'expired') |
2153 | 2153 | { |
2154 | 2154 | $sql = "SELECT cd.rowid, cd.date_fin_validite as datefin"; |
2155 | - $sql.= $this->from; |
|
2156 | - $sql.= " WHERE c.statut = 1"; |
|
2157 | - $sql.= " AND c.rowid = cd.fk_contrat"; |
|
2158 | - $sql.= " AND cd.statut = 4"; |
|
2159 | - $sql.= " AND cd.date_fin_validite < '".$this->db->idate(time())."'"; |
|
2160 | - } |
|
2161 | - $sql.= " AND c.fk_soc = s.rowid"; |
|
2162 | - $sql.= " AND c.entity = ".$conf->entity; |
|
2163 | - if ($user->societe_id) $sql.=" AND c.fk_soc = ".$user->societe_id; |
|
2164 | - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; |
|
2165 | - $resql=$this->db->query($sql); |
|
2155 | + $sql .= $this->from; |
|
2156 | + $sql .= " WHERE c.statut = 1"; |
|
2157 | + $sql .= " AND c.rowid = cd.fk_contrat"; |
|
2158 | + $sql .= " AND cd.statut = 4"; |
|
2159 | + $sql .= " AND cd.date_fin_validite < '".$this->db->idate(time())."'"; |
|
2160 | + } |
|
2161 | + $sql .= " AND c.fk_soc = s.rowid"; |
|
2162 | + $sql .= " AND c.entity = ".$conf->entity; |
|
2163 | + if ($user->societe_id) $sql .= " AND c.fk_soc = ".$user->societe_id; |
|
2164 | + if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; |
|
2165 | + $resql = $this->db->query($sql); |
|
2166 | 2166 | if ($resql) |
2167 | 2167 | { |
2168 | 2168 | $langs->load("contracts"); |
2169 | - $now=dol_now(); |
|
2169 | + $now = dol_now(); |
|
2170 | 2170 | |
2171 | 2171 | if ($mode == 'inactives') { |
2172 | 2172 | $warning_delay = $conf->contrat->services->inactifs->warning_delay; |
@@ -2179,12 +2179,12 @@ discard block |
||
2179 | 2179 | } |
2180 | 2180 | |
2181 | 2181 | $response = new WorkboardResponse(); |
2182 | - $response->warning_delay = $warning_delay/60/60/24; |
|
2182 | + $response->warning_delay = $warning_delay / 60 / 60 / 24; |
|
2183 | 2183 | $response->label = $label; |
2184 | 2184 | $response->url = $url; |
2185 | - $response->img = img_object('',"contract"); |
|
2185 | + $response->img = img_object('', "contract"); |
|
2186 | 2186 | |
2187 | - while ($obj=$this->db->fetch_object($resql)) |
|
2187 | + while ($obj = $this->db->fetch_object($resql)) |
|
2188 | 2188 | { |
2189 | 2189 | $response->nbtodo++; |
2190 | 2190 | |
@@ -2198,7 +2198,7 @@ discard block |
||
2198 | 2198 | else |
2199 | 2199 | { |
2200 | 2200 | dol_print_error($this->db); |
2201 | - $this->error=$this->db->error(); |
|
2201 | + $this->error = $this->db->error(); |
|
2202 | 2202 | return -1; |
2203 | 2203 | } |
2204 | 2204 | } |
@@ -2212,26 +2212,26 @@ discard block |
||
2212 | 2212 | { |
2213 | 2213 | global $conf, $user; |
2214 | 2214 | |
2215 | - $this->nb=array(); |
|
2215 | + $this->nb = array(); |
|
2216 | 2216 | $clause = "WHERE"; |
2217 | 2217 | |
2218 | 2218 | $sql = "SELECT count(c.rowid) as nb"; |
2219 | - $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c"; |
|
2220 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid"; |
|
2219 | + $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c"; |
|
2220 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid"; |
|
2221 | 2221 | if (!$user->rights->societe->client->voir && !$user->societe_id) |
2222 | 2222 | { |
2223 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; |
|
2224 | - $sql.= " WHERE sc.fk_user = " .$user->id; |
|
2223 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; |
|
2224 | + $sql .= " WHERE sc.fk_user = ".$user->id; |
|
2225 | 2225 | $clause = "AND"; |
2226 | 2226 | } |
2227 | - $sql.= " ".$clause." c.entity = ".$conf->entity; |
|
2227 | + $sql .= " ".$clause." c.entity = ".$conf->entity; |
|
2228 | 2228 | |
2229 | - $resql=$this->db->query($sql); |
|
2229 | + $resql = $this->db->query($sql); |
|
2230 | 2230 | if ($resql) |
2231 | 2231 | { |
2232 | - while ($obj=$this->db->fetch_object($resql)) |
|
2232 | + while ($obj = $this->db->fetch_object($resql)) |
|
2233 | 2233 | { |
2234 | - $this->nb["Contracts"]=$obj->nb; |
|
2234 | + $this->nb["Contracts"] = $obj->nb; |
|
2235 | 2235 | } |
2236 | 2236 | $this->db->free($resql); |
2237 | 2237 | return 1; |
@@ -2239,7 +2239,7 @@ discard block |
||
2239 | 2239 | else |
2240 | 2240 | { |
2241 | 2241 | dol_print_error($this->db); |
2242 | - $this->error=$this->db->error(); |
|
2242 | + $this->error = $this->db->error(); |
|
2243 | 2243 | return -1; |
2244 | 2244 | } |
2245 | 2245 | } |
@@ -2254,7 +2254,7 @@ discard block |
||
2254 | 2254 | */ |
2255 | 2255 | function getIdBillingContact() |
2256 | 2256 | { |
2257 | - return $this->getIdContact('external','BILLING'); |
|
2257 | + return $this->getIdContact('external', 'BILLING'); |
|
2258 | 2258 | } |
2259 | 2259 | |
2260 | 2260 | /** |
@@ -2264,7 +2264,7 @@ discard block |
||
2264 | 2264 | */ |
2265 | 2265 | function getIdServiceContact() |
2266 | 2266 | { |
2267 | - return $this->getIdContact('external','SERVICE'); |
|
2267 | + return $this->getIdContact('external', 'SERVICE'); |
|
2268 | 2268 | } |
2269 | 2269 | |
2270 | 2270 | |
@@ -2277,15 +2277,15 @@ discard block |
||
2277 | 2277 | */ |
2278 | 2278 | function initAsSpecimen() |
2279 | 2279 | { |
2280 | - global $user,$langs,$conf; |
|
2280 | + global $user, $langs, $conf; |
|
2281 | 2281 | |
2282 | 2282 | // Load array of products prodids |
2283 | 2283 | $num_prods = 0; |
2284 | 2284 | $prodids = array(); |
2285 | 2285 | $sql = "SELECT rowid"; |
2286 | - $sql.= " FROM ".MAIN_DB_PREFIX."product"; |
|
2287 | - $sql.= " WHERE entity IN (".getEntity('product').")"; |
|
2288 | - $sql.= " AND tosell = 1"; |
|
2286 | + $sql .= " FROM ".MAIN_DB_PREFIX."product"; |
|
2287 | + $sql .= " WHERE entity IN (".getEntity('product').")"; |
|
2288 | + $sql .= " AND tosell = 1"; |
|
2289 | 2289 | $resql = $this->db->query($sql); |
2290 | 2290 | if ($resql) |
2291 | 2291 | { |
@@ -2300,35 +2300,35 @@ discard block |
||
2300 | 2300 | } |
2301 | 2301 | |
2302 | 2302 | // Initialise parametres |
2303 | - $this->id=0; |
|
2304 | - $this->specimen=1; |
|
2303 | + $this->id = 0; |
|
2304 | + $this->specimen = 1; |
|
2305 | 2305 | |
2306 | 2306 | $this->ref = 'SPECIMEN'; |
2307 | 2307 | $this->ref_customer = 'SPECIMENCUST'; |
2308 | 2308 | $this->ref_supplier = 'SPECIMENSUPP'; |
2309 | 2309 | $this->socid = 1; |
2310 | - $this->statut= 0; |
|
2310 | + $this->statut = 0; |
|
2311 | 2311 | $this->date_creation = (dol_now() - 3600 * 24 * 7); |
2312 | 2312 | $this->date_contrat = dol_now(); |
2313 | 2313 | $this->commercial_signature_id = 1; |
2314 | 2314 | $this->commercial_suivi_id = 1; |
2315 | - $this->note_private='This is a comment (private)'; |
|
2316 | - $this->note_public='This is a comment (public)'; |
|
2315 | + $this->note_private = 'This is a comment (private)'; |
|
2316 | + $this->note_public = 'This is a comment (public)'; |
|
2317 | 2317 | $this->fk_projet = 0; |
2318 | 2318 | // Lines |
2319 | 2319 | $nbp = 5; |
2320 | 2320 | $xnbp = 0; |
2321 | 2321 | while ($xnbp < $nbp) |
2322 | 2322 | { |
2323 | - $line=new ContratLigne($this->db); |
|
2324 | - $line->qty=1; |
|
2325 | - $line->subprice=100; |
|
2326 | - $line->price=100; |
|
2327 | - $line->tva_tx=19.6; |
|
2328 | - $line->remise_percent=10; |
|
2329 | - $line->total_ht=90; |
|
2330 | - $line->total_ttc=107.64; // 90 * 1.196 |
|
2331 | - $line->total_tva=17.64; |
|
2323 | + $line = new ContratLigne($this->db); |
|
2324 | + $line->qty = 1; |
|
2325 | + $line->subprice = 100; |
|
2326 | + $line->price = 100; |
|
2327 | + $line->tva_tx = 19.6; |
|
2328 | + $line->remise_percent = 10; |
|
2329 | + $line->total_ht = 90; |
|
2330 | + $line->total_ttc = 107.64; // 90 * 1.196 |
|
2331 | + $line->total_tva = 17.64; |
|
2332 | 2332 | $line->date_ouverture = dol_now() - 200000; |
2333 | 2333 | $line->date_ouverture_prevue = dol_now() - 500000; |
2334 | 2334 | $line->date_fin_validite = dol_now() + 500000; |
@@ -2336,9 +2336,9 @@ discard block |
||
2336 | 2336 | if ($num_prods > 0) |
2337 | 2337 | { |
2338 | 2338 | $prodid = mt_rand(1, $num_prods); |
2339 | - $line->fk_product=$prodids[$prodid]; |
|
2339 | + $line->fk_product = $prodids[$prodid]; |
|
2340 | 2340 | } |
2341 | - $this->lines[$xnbp]=$line; |
|
2341 | + $this->lines[$xnbp] = $line; |
|
2342 | 2342 | $xnbp++; |
2343 | 2343 | } |
2344 | 2344 | } |
@@ -2353,19 +2353,19 @@ discard block |
||
2353 | 2353 | * @param int $hideref Hide ref |
2354 | 2354 | * @return int 0 if KO, 1 if OK |
2355 | 2355 | */ |
2356 | - public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) |
|
2356 | + public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
2357 | 2357 | { |
2358 | - global $conf,$langs; |
|
2358 | + global $conf, $langs; |
|
2359 | 2359 | |
2360 | 2360 | $langs->load("contracts"); |
2361 | 2361 | |
2362 | - if (! dol_strlen($modele)) { |
|
2362 | + if (!dol_strlen($modele)) { |
|
2363 | 2363 | |
2364 | 2364 | $modele = 'strato'; |
2365 | 2365 | |
2366 | 2366 | if ($this->modelpdf) { |
2367 | 2367 | $modele = $this->modelpdf; |
2368 | - } elseif (! empty($conf->global->CONTRACT_ADDON_PDF)) { |
|
2368 | + } elseif (!empty($conf->global->CONTRACT_ADDON_PDF)) { |
|
2369 | 2369 | $modele = $conf->global->CONTRACT_ADDON_PDF; |
2370 | 2370 | } |
2371 | 2371 | } |
@@ -2399,7 +2399,7 @@ discard block |
||
2399 | 2399 | * @param int $notrigger 1=Does not execute triggers, 0= execute triggers |
2400 | 2400 | * @return int New id of clone |
2401 | 2401 | */ |
2402 | - function createFromClone($socid = 0, $notrigger=0) { |
|
2402 | + function createFromClone($socid = 0, $notrigger = 0) { |
|
2403 | 2403 | global $db, $user, $langs, $conf, $hookmanager; |
2404 | 2404 | |
2405 | 2405 | dol_include_once('/projet/class/project.class.php'); |
@@ -2422,27 +2422,27 @@ discard block |
||
2422 | 2422 | // $clonedObj->id=0; |
2423 | 2423 | $clonedObj->statut = 0; |
2424 | 2424 | |
2425 | - if (empty($conf->global->CONTRACT_ADDON) || ! is_readable(DOL_DOCUMENT_ROOT . "/core/modules/contract/" . $conf->global->CONTRACT_ADDON . ".php")) { |
|
2425 | + if (empty($conf->global->CONTRACT_ADDON) || !is_readable(DOL_DOCUMENT_ROOT."/core/modules/contract/".$conf->global->CONTRACT_ADDON.".php")) { |
|
2426 | 2426 | $this->error = 'ErrorSetupNotComplete'; |
2427 | 2427 | dol_syslog($this->error); |
2428 | - return - 1; |
|
2428 | + return -1; |
|
2429 | 2429 | } |
2430 | 2430 | |
2431 | 2431 | // Set ref |
2432 | - require_once DOL_DOCUMENT_ROOT . "/core/modules/contract/" . $conf->global->CONTRACT_ADDON . '.php'; |
|
2432 | + require_once DOL_DOCUMENT_ROOT."/core/modules/contract/".$conf->global->CONTRACT_ADDON.'.php'; |
|
2433 | 2433 | $obj = $conf->global->CONTRACT_ADDON; |
2434 | 2434 | $modContract = new $obj(); |
2435 | 2435 | $clonedObj->ref = $modContract->getNextValue($objsoc, $clonedObj); |
2436 | 2436 | |
2437 | 2437 | // get extrafields so they will be clone |
2438 | - foreach ( $this->lines as $line ) { |
|
2438 | + foreach ($this->lines as $line) { |
|
2439 | 2439 | $line->fetch_optionals($line->rowid); |
2440 | 2440 | } |
2441 | 2441 | |
2442 | 2442 | // Create clone |
2443 | 2443 | $result = $clonedObj->create($user); |
2444 | 2444 | if ($result < 0) { |
2445 | - $error ++; |
|
2445 | + $error++; |
|
2446 | 2446 | $this->error = $clonedObj->error; |
2447 | 2447 | $this->errors[] = $clonedObj->error; |
2448 | 2448 | } else { |
@@ -2454,39 +2454,39 @@ discard block |
||
2454 | 2454 | } |
2455 | 2455 | } |
2456 | 2456 | |
2457 | - if (! $error) { |
|
2458 | - foreach ( $this->lines as $line ) { |
|
2457 | + if (!$error) { |
|
2458 | + foreach ($this->lines as $line) { |
|
2459 | 2459 | $result = $clonedObj->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->date_ouverture, $line->date_cloture, 'HT', 0, $line->info_bits, $line->fk_fournprice, $line->pa_ht, $line->array_options, $line->fk_unit); |
2460 | 2460 | if ($result < 0) { |
2461 | - $error ++; |
|
2461 | + $error++; |
|
2462 | 2462 | $this->error = $clonedObj->error; |
2463 | 2463 | $this->errors[] = $clonedObj->error; |
2464 | 2464 | } |
2465 | 2465 | } |
2466 | 2466 | } |
2467 | 2467 | |
2468 | - if (! $error) { |
|
2468 | + if (!$error) { |
|
2469 | 2469 | // Hook of thirdparty module |
2470 | 2470 | if (is_object($hookmanager)) { |
2471 | - $parameters = array ( |
|
2471 | + $parameters = array( |
|
2472 | 2472 | 'objFrom' => $this, |
2473 | 2473 | 'clonedObj' => $clonedObj |
2474 | 2474 | ); |
2475 | 2475 | $action = ''; |
2476 | 2476 | $reshook = $hookmanager->executeHooks('createFrom', $parameters, $clonedObj, $action); // Note that $action and $object may have been modified by some hooks |
2477 | 2477 | if ($reshook < 0) |
2478 | - $error ++; |
|
2478 | + $error++; |
|
2479 | 2479 | } |
2480 | 2480 | |
2481 | 2481 | } |
2482 | 2482 | |
2483 | - if (! $notrigger && empty($error)) |
|
2483 | + if (!$notrigger && empty($error)) |
|
2484 | 2484 | { |
2485 | 2485 | // Call trigger |
2486 | - $clonedObj->old_copy=$this; |
|
2486 | + $clonedObj->old_copy = $this; |
|
2487 | 2487 | $result = $clonedObj->call_trigger('CONTRACT_CLONE', $user); |
2488 | 2488 | if ($result < 0) { |
2489 | - $error ++; |
|
2489 | + $error++; |
|
2490 | 2490 | } |
2491 | 2491 | // End call triggers |
2492 | 2492 | } |
@@ -2494,12 +2494,12 @@ discard block |
||
2494 | 2494 | unset($this->context['createfromclone']); |
2495 | 2495 | |
2496 | 2496 | // End |
2497 | - if (! $error) { |
|
2497 | + if (!$error) { |
|
2498 | 2498 | $this->db->commit(); |
2499 | 2499 | return $clonedObj->id; |
2500 | 2500 | } else { |
2501 | 2501 | $this->db->rollback(); |
2502 | - return - 1; |
|
2502 | + return -1; |
|
2503 | 2503 | } |
2504 | 2504 | } |
2505 | 2505 | } |
@@ -2510,8 +2510,8 @@ discard block |
||
2510 | 2510 | */ |
2511 | 2511 | class ContratLigne extends CommonObjectLine |
2512 | 2512 | { |
2513 | - public $element='contratdet'; |
|
2514 | - public $table_element='contratdet'; |
|
2513 | + public $element = 'contratdet'; |
|
2514 | + public $table_element = 'contratdet'; |
|
2515 | 2515 | |
2516 | 2516 | var $id; |
2517 | 2517 | var $ref; |
@@ -2519,8 +2519,8 @@ discard block |
||
2519 | 2519 | |
2520 | 2520 | var $fk_contrat; |
2521 | 2521 | var $fk_product; |
2522 | - var $statut; // 0 inactive, 4 active, 5 closed |
|
2523 | - var $type; // 0 for product, 1 for service |
|
2522 | + var $statut; // 0 inactive, 4 active, 5 closed |
|
2523 | + var $type; // 0 for product, 1 for service |
|
2524 | 2524 | var $label; |
2525 | 2525 | /** |
2526 | 2526 | * @var string |
@@ -2535,21 +2535,21 @@ discard block |
||
2535 | 2535 | var $product_label; |
2536 | 2536 | |
2537 | 2537 | var $date_commande; |
2538 | - var $date_ouverture_prevue; // date start planned |
|
2539 | - var $date_ouverture; // date start real |
|
2540 | - var $date_fin_validite; // date end planned |
|
2541 | - var $date_cloture; // date end real |
|
2538 | + var $date_ouverture_prevue; // date start planned |
|
2539 | + var $date_ouverture; // date start real |
|
2540 | + var $date_fin_validite; // date end planned |
|
2541 | + var $date_cloture; // date end real |
|
2542 | 2542 | var $tva_tx; |
2543 | 2543 | var $localtax1_tx; |
2544 | 2544 | var $localtax2_tx; |
2545 | - var $localtax1_type; // Local tax 1 type |
|
2546 | - var $localtax2_type; // Local tax 2 type |
|
2545 | + var $localtax1_type; // Local tax 1 type |
|
2546 | + var $localtax2_type; // Local tax 2 type |
|
2547 | 2547 | var $qty; |
2548 | 2548 | var $remise_percent; |
2549 | 2549 | var $remise; |
2550 | 2550 | var $fk_remise_except; |
2551 | 2551 | |
2552 | - var $subprice; // Unit price HT |
|
2552 | + var $subprice; // Unit price HT |
|
2553 | 2553 | |
2554 | 2554 | /** |
2555 | 2555 | * @var float |
@@ -2595,7 +2595,7 @@ discard block |
||
2595 | 2595 | */ |
2596 | 2596 | function getLibStatut($mode) |
2597 | 2597 | { |
2598 | - return $this->LibStatut($this->statut,$mode,((! empty($this->date_fin_validite))?($this->date_fin_validite < dol_now()?1:0):-1)); |
|
2598 | + return $this->LibStatut($this->statut, $mode, ((!empty($this->date_fin_validite)) ? ($this->date_fin_validite < dol_now() ? 1 : 0) : -1)); |
|
2599 | 2599 | } |
2600 | 2600 | |
2601 | 2601 | /** |
@@ -2607,7 +2607,7 @@ discard block |
||
2607 | 2607 | * @param string $moreatt More attribute |
2608 | 2608 | * @return string Libelle |
2609 | 2609 | */ |
2610 | - function LibStatut($statut,$mode,$expired=-1,$moreatt='') |
|
2610 | + function LibStatut($statut, $mode, $expired = -1, $moreatt = '') |
|
2611 | 2611 | { |
2612 | 2612 | global $langs; |
2613 | 2613 | $langs->load("contracts"); |
@@ -2615,49 +2615,49 @@ discard block |
||
2615 | 2615 | { |
2616 | 2616 | if ($statut == 0) { return $langs->trans("ServiceStatusInitial"); } |
2617 | 2617 | if ($statut == 4 && $expired == -1) { return $langs->trans("ServiceStatusRunning"); } |
2618 | - if ($statut == 4 && $expired == 0) { return $langs->trans("ServiceStatusNotLate"); } |
|
2619 | - if ($statut == 4 && $expired == 1) { return $langs->trans("ServiceStatusLate"); } |
|
2620 | - if ($statut == 5) { return $langs->trans("ServiceStatusClosed"); } |
|
2618 | + if ($statut == 4 && $expired == 0) { return $langs->trans("ServiceStatusNotLate"); } |
|
2619 | + if ($statut == 4 && $expired == 1) { return $langs->trans("ServiceStatusLate"); } |
|
2620 | + if ($statut == 5) { return $langs->trans("ServiceStatusClosed"); } |
|
2621 | 2621 | } |
2622 | 2622 | if ($mode == 1) |
2623 | 2623 | { |
2624 | 2624 | if ($statut == 0) { return $langs->trans("ServiceStatusInitial"); } |
2625 | 2625 | if ($statut == 4 && $expired == -1) { return $langs->trans("ServiceStatusRunning"); } |
2626 | - if ($statut == 4 && $expired == 0) { return $langs->trans("ServiceStatusNotLateShort"); } |
|
2627 | - if ($statut == 4 && $expired == 1) { return $langs->trans("ServiceStatusLateShort"); } |
|
2628 | - if ($statut == 5) { return $langs->trans("ServiceStatusClosed"); } |
|
2626 | + if ($statut == 4 && $expired == 0) { return $langs->trans("ServiceStatusNotLateShort"); } |
|
2627 | + if ($statut == 4 && $expired == 1) { return $langs->trans("ServiceStatusLateShort"); } |
|
2628 | + if ($statut == 5) { return $langs->trans("ServiceStatusClosed"); } |
|
2629 | 2629 | } |
2630 | 2630 | if ($mode == 2) |
2631 | 2631 | { |
2632 | - if ($statut == 0) { return img_picto($langs->trans('ServiceStatusInitial'),'statut0').' '.$langs->trans("ServiceStatusInitial"); } |
|
2633 | - if ($statut == 4 && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'),'statut4').' '.$langs->trans("ServiceStatusRunning"); } |
|
2634 | - if ($statut == 4 && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'),'statut4').' '.$langs->trans("ServiceStatusNotLateShort"); } |
|
2635 | - if ($statut == 4 && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'),'statut3').' '.$langs->trans("ServiceStatusLateShort"); } |
|
2636 | - if ($statut == 5) { return img_picto($langs->trans('ServiceStatusClosed'),'statut6') .' '.$langs->trans("ServiceStatusClosed"); } |
|
2632 | + if ($statut == 0) { return img_picto($langs->trans('ServiceStatusInitial'), 'statut0').' '.$langs->trans("ServiceStatusInitial"); } |
|
2633 | + if ($statut == 4 && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'), 'statut4').' '.$langs->trans("ServiceStatusRunning"); } |
|
2634 | + if ($statut == 4 && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'), 'statut4').' '.$langs->trans("ServiceStatusNotLateShort"); } |
|
2635 | + if ($statut == 4 && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'), 'statut3').' '.$langs->trans("ServiceStatusLateShort"); } |
|
2636 | + if ($statut == 5) { return img_picto($langs->trans('ServiceStatusClosed'), 'statut6').' '.$langs->trans("ServiceStatusClosed"); } |
|
2637 | 2637 | } |
2638 | 2638 | if ($mode == 3) |
2639 | 2639 | { |
2640 | - if ($statut == 0) { return img_picto($langs->trans('ServiceStatusInitial'),'statut0',$moreatt); } |
|
2641 | - if ($statut == 4 && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'),'statut4',$moreatt); } |
|
2642 | - if ($statut == 4 && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'),'statut4',$moreatt); } |
|
2643 | - if ($statut == 4 && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'),'statut3',$moreatt); } |
|
2644 | - if ($statut == 5) { return img_picto($langs->trans('ServiceStatusClosed'),'statut6',$moreatt); } |
|
2640 | + if ($statut == 0) { return img_picto($langs->trans('ServiceStatusInitial'), 'statut0', $moreatt); } |
|
2641 | + if ($statut == 4 && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'), 'statut4', $moreatt); } |
|
2642 | + if ($statut == 4 && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'), 'statut4', $moreatt); } |
|
2643 | + if ($statut == 4 && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'), 'statut3', $moreatt); } |
|
2644 | + if ($statut == 5) { return img_picto($langs->trans('ServiceStatusClosed'), 'statut6', $moreatt); } |
|
2645 | 2645 | } |
2646 | 2646 | if ($mode == 4) |
2647 | 2647 | { |
2648 | - if ($statut == 0) { return img_picto($langs->trans('ServiceStatusInitial'),'statut0').' '.$langs->trans("ServiceStatusInitial"); } |
|
2649 | - if ($statut == 4 && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'),'statut4').' '.$langs->trans("ServiceStatusRunning"); } |
|
2650 | - if ($statut == 4 && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'),'statut4').' '.$langs->trans("ServiceStatusNotLate"); } |
|
2651 | - if ($statut == 4 && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'),'statut3').' '.$langs->trans("ServiceStatusLate"); } |
|
2652 | - if ($statut == 5) { return img_picto($langs->trans('ServiceStatusClosed'),'statut6') .' '.$langs->trans("ServiceStatusClosed"); } |
|
2648 | + if ($statut == 0) { return img_picto($langs->trans('ServiceStatusInitial'), 'statut0').' '.$langs->trans("ServiceStatusInitial"); } |
|
2649 | + if ($statut == 4 && $expired == -1) { return img_picto($langs->trans('ServiceStatusRunning'), 'statut4').' '.$langs->trans("ServiceStatusRunning"); } |
|
2650 | + if ($statut == 4 && $expired == 0) { return img_picto($langs->trans('ServiceStatusNotLate'), 'statut4').' '.$langs->trans("ServiceStatusNotLate"); } |
|
2651 | + if ($statut == 4 && $expired == 1) { return img_picto($langs->trans('ServiceStatusLate'), 'statut3').' '.$langs->trans("ServiceStatusLate"); } |
|
2652 | + if ($statut == 5) { return img_picto($langs->trans('ServiceStatusClosed'), 'statut6').' '.$langs->trans("ServiceStatusClosed"); } |
|
2653 | 2653 | } |
2654 | 2654 | if ($mode == 5) |
2655 | 2655 | { |
2656 | - if ($statut == 0) { return $langs->trans("ServiceStatusInitial").' '.img_picto($langs->trans('ServiceStatusInitial'),'statut0'); } |
|
2657 | - if ($statut == 4 && $expired == -1) { return $langs->trans("ServiceStatusRunning").' '.img_picto($langs->trans('ServiceStatusRunning'),'statut4'); } |
|
2658 | - if ($statut == 4 && $expired == 0) { return $langs->trans("ServiceStatusNotLateShort").' '.img_picto($langs->trans('ServiceStatusNotLateShort'),'statut4'); } |
|
2659 | - if ($statut == 4 && $expired == 1) { return $langs->trans("ServiceStatusLateShort").' '.img_picto($langs->trans('ServiceStatusLate'),'statut3'); } |
|
2660 | - if ($statut == 5) { return $langs->trans("ServiceStatusClosed").' '.img_picto($langs->trans('ServiceStatusClosed'),'statut6'); } |
|
2656 | + if ($statut == 0) { return $langs->trans("ServiceStatusInitial").' '.img_picto($langs->trans('ServiceStatusInitial'), 'statut0'); } |
|
2657 | + if ($statut == 4 && $expired == -1) { return $langs->trans("ServiceStatusRunning").' '.img_picto($langs->trans('ServiceStatusRunning'), 'statut4'); } |
|
2658 | + if ($statut == 4 && $expired == 0) { return $langs->trans("ServiceStatusNotLateShort").' '.img_picto($langs->trans('ServiceStatusNotLateShort'), 'statut4'); } |
|
2659 | + if ($statut == 4 && $expired == 1) { return $langs->trans("ServiceStatusLateShort").' '.img_picto($langs->trans('ServiceStatusLate'), 'statut3'); } |
|
2660 | + if ($statut == 5) { return $langs->trans("ServiceStatusClosed").' '.img_picto($langs->trans('ServiceStatusClosed'), 'statut6'); } |
|
2661 | 2661 | } |
2662 | 2662 | } |
2663 | 2663 | |
@@ -2668,23 +2668,23 @@ discard block |
||
2668 | 2668 | * @param int $maxlength Max length |
2669 | 2669 | * @return string Chaine avec URL |
2670 | 2670 | */ |
2671 | - function getNomUrl($withpicto=0,$maxlength=0) |
|
2671 | + function getNomUrl($withpicto = 0, $maxlength = 0) |
|
2672 | 2672 | { |
2673 | 2673 | global $langs; |
2674 | 2674 | |
2675 | - $result=''; |
|
2676 | - $label=$langs->trans("ShowContractOfService").': '.$this->label; |
|
2677 | - if (empty($label)) $label=$this->description; |
|
2675 | + $result = ''; |
|
2676 | + $label = $langs->trans("ShowContractOfService").': '.$this->label; |
|
2677 | + if (empty($label)) $label = $this->description; |
|
2678 | 2678 | |
2679 | 2679 | $link = '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$this->fk_contrat.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
2680 | - $linkend='</a>'; |
|
2680 | + $linkend = '</a>'; |
|
2681 | 2681 | |
2682 | - $picto='service'; |
|
2683 | - if ($this->type == 0) $picto='product'; |
|
2682 | + $picto = 'service'; |
|
2683 | + if ($this->type == 0) $picto = 'product'; |
|
2684 | 2684 | |
2685 | - if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
2686 | - if ($withpicto && $withpicto != 2) $result.=' '; |
|
2687 | - if ($withpicto != 2) $result.=$link.($this->product_ref?$this->product_ref.' ':'').($this->label?$this->label:$this->description).$linkend; |
|
2685 | + if ($withpicto) $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
2686 | + if ($withpicto && $withpicto != 2) $result .= ' '; |
|
2687 | + if ($withpicto != 2) $result .= $link.($this->product_ref ? $this->product_ref.' ' : '').($this->label ? $this->label : $this->description).$linkend; |
|
2688 | 2688 | return $result; |
2689 | 2689 | } |
2690 | 2690 | |
@@ -2695,61 +2695,61 @@ discard block |
||
2695 | 2695 | * @param string $ref Ref of contract |
2696 | 2696 | * @return int <0 if KO, >0 if OK |
2697 | 2697 | */ |
2698 | - function fetch($id, $ref='') |
|
2698 | + function fetch($id, $ref = '') |
|
2699 | 2699 | { |
2700 | 2700 | |
2701 | 2701 | // Check parameters |
2702 | 2702 | if (empty($id) && empty($ref)) return -1; |
2703 | 2703 | |
2704 | 2704 | $sql = "SELECT"; |
2705 | - $sql.= " t.rowid,"; |
|
2706 | - |
|
2707 | - $sql.= " t.tms,"; |
|
2708 | - $sql.= " t.fk_contrat,"; |
|
2709 | - $sql.= " t.fk_product,"; |
|
2710 | - $sql.= " t.statut,"; |
|
2711 | - $sql.= " t.label,"; // This field is not used. Only label of product |
|
2712 | - $sql.= " p.ref as product_ref,"; |
|
2713 | - $sql.= " p.label as product_label,"; |
|
2714 | - $sql.= " p.description as product_desc,"; |
|
2715 | - $sql.= " p.fk_product_type as product_type,"; |
|
2716 | - $sql.= " t.description,"; |
|
2717 | - $sql.= " t.date_commande,"; |
|
2718 | - $sql.= " t.date_ouverture_prevue as date_ouverture_prevue,"; |
|
2719 | - $sql.= " t.date_ouverture as date_ouverture,"; |
|
2720 | - $sql.= " t.date_fin_validite as date_fin_validite,"; |
|
2721 | - $sql.= " t.date_cloture as date_cloture,"; |
|
2722 | - $sql.= " t.tva_tx,"; |
|
2723 | - $sql.= " t.vat_src_code,"; |
|
2724 | - $sql.= " t.localtax1_tx,"; |
|
2725 | - $sql.= " t.localtax2_tx,"; |
|
2726 | - $sql.= " t.localtax1_type,"; |
|
2727 | - $sql.= " t.localtax2_type,"; |
|
2728 | - $sql.= " t.qty,"; |
|
2729 | - $sql.= " t.remise_percent,"; |
|
2730 | - $sql.= " t.remise,"; |
|
2731 | - $sql.= " t.fk_remise_except,"; |
|
2732 | - $sql.= " t.subprice,"; |
|
2733 | - $sql.= " t.price_ht,"; |
|
2734 | - $sql.= " t.total_ht,"; |
|
2735 | - $sql.= " t.total_tva,"; |
|
2736 | - $sql.= " t.total_localtax1,"; |
|
2737 | - $sql.= " t.total_localtax2,"; |
|
2738 | - $sql.= " t.total_ttc,"; |
|
2739 | - $sql.= " t.fk_product_fournisseur_price as fk_fournprice,"; |
|
2740 | - $sql.= " t.buy_price_ht as pa_ht,"; |
|
2741 | - $sql.= " t.info_bits,"; |
|
2742 | - $sql.= " t.fk_user_author,"; |
|
2743 | - $sql.= " t.fk_user_ouverture,"; |
|
2744 | - $sql.= " t.fk_user_cloture,"; |
|
2745 | - $sql.= " t.commentaire,"; |
|
2746 | - $sql.= " t.fk_unit"; |
|
2747 | - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as t LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = t.fk_product"; |
|
2748 | - if ($id) $sql.= " WHERE t.rowid = ".$id; |
|
2749 | - if ($ref) $sql.= " WHERE t.rowid = '".$this->db->escape($ref)."'"; |
|
2705 | + $sql .= " t.rowid,"; |
|
2706 | + |
|
2707 | + $sql .= " t.tms,"; |
|
2708 | + $sql .= " t.fk_contrat,"; |
|
2709 | + $sql .= " t.fk_product,"; |
|
2710 | + $sql .= " t.statut,"; |
|
2711 | + $sql .= " t.label,"; // This field is not used. Only label of product |
|
2712 | + $sql .= " p.ref as product_ref,"; |
|
2713 | + $sql .= " p.label as product_label,"; |
|
2714 | + $sql .= " p.description as product_desc,"; |
|
2715 | + $sql .= " p.fk_product_type as product_type,"; |
|
2716 | + $sql .= " t.description,"; |
|
2717 | + $sql .= " t.date_commande,"; |
|
2718 | + $sql .= " t.date_ouverture_prevue as date_ouverture_prevue,"; |
|
2719 | + $sql .= " t.date_ouverture as date_ouverture,"; |
|
2720 | + $sql .= " t.date_fin_validite as date_fin_validite,"; |
|
2721 | + $sql .= " t.date_cloture as date_cloture,"; |
|
2722 | + $sql .= " t.tva_tx,"; |
|
2723 | + $sql .= " t.vat_src_code,"; |
|
2724 | + $sql .= " t.localtax1_tx,"; |
|
2725 | + $sql .= " t.localtax2_tx,"; |
|
2726 | + $sql .= " t.localtax1_type,"; |
|
2727 | + $sql .= " t.localtax2_type,"; |
|
2728 | + $sql .= " t.qty,"; |
|
2729 | + $sql .= " t.remise_percent,"; |
|
2730 | + $sql .= " t.remise,"; |
|
2731 | + $sql .= " t.fk_remise_except,"; |
|
2732 | + $sql .= " t.subprice,"; |
|
2733 | + $sql .= " t.price_ht,"; |
|
2734 | + $sql .= " t.total_ht,"; |
|
2735 | + $sql .= " t.total_tva,"; |
|
2736 | + $sql .= " t.total_localtax1,"; |
|
2737 | + $sql .= " t.total_localtax2,"; |
|
2738 | + $sql .= " t.total_ttc,"; |
|
2739 | + $sql .= " t.fk_product_fournisseur_price as fk_fournprice,"; |
|
2740 | + $sql .= " t.buy_price_ht as pa_ht,"; |
|
2741 | + $sql .= " t.info_bits,"; |
|
2742 | + $sql .= " t.fk_user_author,"; |
|
2743 | + $sql .= " t.fk_user_ouverture,"; |
|
2744 | + $sql .= " t.fk_user_cloture,"; |
|
2745 | + $sql .= " t.commentaire,"; |
|
2746 | + $sql .= " t.fk_unit"; |
|
2747 | + $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as t LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = t.fk_product"; |
|
2748 | + if ($id) $sql .= " WHERE t.rowid = ".$id; |
|
2749 | + if ($ref) $sql .= " WHERE t.rowid = '".$this->db->escape($ref)."'"; |
|
2750 | 2750 | |
2751 | 2751 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
2752 | - $resql=$this->db->query($sql); |
|
2752 | + $resql = $this->db->query($sql); |
|
2753 | 2753 | if ($resql) |
2754 | 2754 | { |
2755 | 2755 | if ($this->db->num_rows($resql)) |
@@ -2767,7 +2767,7 @@ discard block |
||
2767 | 2767 | $this->product_label = $obj->product_label; |
2768 | 2768 | $this->product_description = $obj->product_description; |
2769 | 2769 | $this->product_type = $obj->product_type; |
2770 | - $this->label = $obj->label; // deprecated. We do not use this field. Only ref and label of product, and description of contract line |
|
2770 | + $this->label = $obj->label; // deprecated. We do not use this field. Only ref and label of product, and description of contract line |
|
2771 | 2771 | $this->description = $obj->description; |
2772 | 2772 | $this->date_commande = $this->db->jdate($obj->date_commande); |
2773 | 2773 | $this->date_ouverture_prevue = $this->db->jdate($obj->date_ouverture_prevue); |
@@ -2799,7 +2799,7 @@ discard block |
||
2799 | 2799 | $this->fk_fournprice = $obj->fk_fournprice; |
2800 | 2800 | $marginInfos = getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->fk_fournprice, $obj->pa_ht); |
2801 | 2801 | $this->pa_ht = $marginInfos[0]; |
2802 | - $this->fk_unit = $obj->fk_unit; |
|
2802 | + $this->fk_unit = $obj->fk_unit; |
|
2803 | 2803 | |
2804 | 2804 | } |
2805 | 2805 | $this->db->free($resql); |
@@ -2808,7 +2808,7 @@ discard block |
||
2808 | 2808 | } |
2809 | 2809 | else |
2810 | 2810 | { |
2811 | - $this->error="Error ".$this->db->lasterror(); |
|
2811 | + $this->error = "Error ".$this->db->lasterror(); |
|
2812 | 2812 | return -1; |
2813 | 2813 | } |
2814 | 2814 | } |
@@ -2821,38 +2821,38 @@ discard block |
||
2821 | 2821 | * @param int $notrigger 0=no, 1=yes (no update trigger) |
2822 | 2822 | * @return int <0 if KO, >0 if OK |
2823 | 2823 | */ |
2824 | - function update($user, $notrigger=0) |
|
2824 | + function update($user, $notrigger = 0) |
|
2825 | 2825 | { |
2826 | 2826 | global $conf, $langs, $mysoc; |
2827 | 2827 | |
2828 | - $error=0; |
|
2828 | + $error = 0; |
|
2829 | 2829 | |
2830 | 2830 | // Clean parameters |
2831 | - $this->fk_contrat=trim($this->fk_contrat); |
|
2832 | - $this->fk_product=trim($this->fk_product); |
|
2833 | - $this->statut=(int) $this->statut; |
|
2834 | - $this->label=trim($this->label); |
|
2835 | - $this->description=trim($this->description); |
|
2836 | - $this->vat_src_code=trim($this->vat_src_code); |
|
2837 | - $this->tva_tx=trim($this->tva_tx); |
|
2838 | - $this->localtax1_tx=trim($this->localtax1_tx); |
|
2839 | - $this->localtax2_tx=trim($this->localtax2_tx); |
|
2840 | - $this->qty=trim($this->qty); |
|
2841 | - $this->remise_percent=trim($this->remise_percent); |
|
2842 | - $this->remise=trim($this->remise); |
|
2843 | - $this->fk_remise_except=trim($this->fk_remise_except); |
|
2844 | - $this->subprice=price2num($this->subprice); |
|
2845 | - $this->price_ht=price2num($this->price_ht); |
|
2846 | - $this->total_ht=trim($this->total_ht); |
|
2847 | - $this->total_tva=trim($this->total_tva); |
|
2848 | - $this->total_localtax1=trim($this->total_localtax1); |
|
2849 | - $this->total_localtax2=trim($this->total_localtax2); |
|
2850 | - $this->total_ttc=trim($this->total_ttc); |
|
2851 | - $this->info_bits=trim($this->info_bits); |
|
2852 | - $this->fk_user_author=trim($this->fk_user_author); |
|
2853 | - $this->fk_user_ouverture=trim($this->fk_user_ouverture); |
|
2854 | - $this->fk_user_cloture=trim($this->fk_user_cloture); |
|
2855 | - $this->commentaire=trim($this->commentaire); |
|
2831 | + $this->fk_contrat = trim($this->fk_contrat); |
|
2832 | + $this->fk_product = trim($this->fk_product); |
|
2833 | + $this->statut = (int) $this->statut; |
|
2834 | + $this->label = trim($this->label); |
|
2835 | + $this->description = trim($this->description); |
|
2836 | + $this->vat_src_code = trim($this->vat_src_code); |
|
2837 | + $this->tva_tx = trim($this->tva_tx); |
|
2838 | + $this->localtax1_tx = trim($this->localtax1_tx); |
|
2839 | + $this->localtax2_tx = trim($this->localtax2_tx); |
|
2840 | + $this->qty = trim($this->qty); |
|
2841 | + $this->remise_percent = trim($this->remise_percent); |
|
2842 | + $this->remise = trim($this->remise); |
|
2843 | + $this->fk_remise_except = trim($this->fk_remise_except); |
|
2844 | + $this->subprice = price2num($this->subprice); |
|
2845 | + $this->price_ht = price2num($this->price_ht); |
|
2846 | + $this->total_ht = trim($this->total_ht); |
|
2847 | + $this->total_tva = trim($this->total_tva); |
|
2848 | + $this->total_localtax1 = trim($this->total_localtax1); |
|
2849 | + $this->total_localtax2 = trim($this->total_localtax2); |
|
2850 | + $this->total_ttc = trim($this->total_ttc); |
|
2851 | + $this->info_bits = trim($this->info_bits); |
|
2852 | + $this->fk_user_author = trim($this->fk_user_author); |
|
2853 | + $this->fk_user_ouverture = trim($this->fk_user_ouverture); |
|
2854 | + $this->fk_user_cloture = trim($this->fk_user_cloture); |
|
2855 | + $this->commentaire = trim($this->commentaire); |
|
2856 | 2856 | //if (empty($this->subprice)) $this->subprice = 0; |
2857 | 2857 | if (empty($this->price_ht)) $this->price_ht = 0; |
2858 | 2858 | if (empty($this->total_ht)) $this->total_ht = 0; |
@@ -2871,14 +2871,14 @@ discard block |
||
2871 | 2871 | // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. |
2872 | 2872 | $localtaxes_type = getLocalTaxesFromRate($this->txtva, 0, $this->societe, $mysoc); |
2873 | 2873 | |
2874 | - $tabprice=calcul_price_total($this->qty, $this->price_ht, $this->remise_percent, $this->tva_tx, $this->localtax1_tx, $this->localtax2_tx, 0, 'HT', 0, 1, $mysoc, $localtaxes_type); |
|
2874 | + $tabprice = calcul_price_total($this->qty, $this->price_ht, $this->remise_percent, $this->tva_tx, $this->localtax1_tx, $this->localtax2_tx, 0, 'HT', 0, 1, $mysoc, $localtaxes_type); |
|
2875 | 2875 | $this->total_ht = $tabprice[0]; |
2876 | 2876 | $this->total_tva = $tabprice[1]; |
2877 | 2877 | $this->total_ttc = $tabprice[2]; |
2878 | - $this->total_localtax1= $tabprice[9]; |
|
2879 | - $this->total_localtax2= $tabprice[10]; |
|
2878 | + $this->total_localtax1 = $tabprice[9]; |
|
2879 | + $this->total_localtax2 = $tabprice[10]; |
|
2880 | 2880 | |
2881 | - if (empty($this->pa_ht)) $this->pa_ht=0; |
|
2881 | + if (empty($this->pa_ht)) $this->pa_ht = 0; |
|
2882 | 2882 | |
2883 | 2883 | // if buy price not defined, define buyprice as configured in margin admin |
2884 | 2884 | if ($this->pa_ht == 0) |
@@ -2898,60 +2898,60 @@ discard block |
||
2898 | 2898 | |
2899 | 2899 | // Update request |
2900 | 2900 | $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET"; |
2901 | - $sql.= " fk_contrat=".$this->fk_contrat.","; |
|
2902 | - $sql.= " fk_product=".($this->fk_product?"'".$this->db->escape($this->fk_product)."'":'null').","; |
|
2903 | - $sql.= " statut=".$this->statut.","; |
|
2904 | - $sql.= " label='".$this->db->escape($this->label)."',"; |
|
2905 | - $sql.= " description='".$this->db->escape($this->description)."',"; |
|
2906 | - $sql.= " date_commande=".($this->date_commande!=''?"'".$this->db->idate($this->date_commande)."'":"null").","; |
|
2907 | - $sql.= " date_ouverture_prevue=".($this->date_ouverture_prevue!=''?"'".$this->db->idate($this->date_ouverture_prevue)."'":"null").","; |
|
2908 | - $sql.= " date_ouverture=".($this->date_ouverture!=''?"'".$this->db->idate($this->date_ouverture)."'":"null").","; |
|
2909 | - $sql.= " date_fin_validite=".($this->date_fin_validite!=''?"'".$this->db->idate($this->date_fin_validite)."'":"null").","; |
|
2910 | - $sql.= " date_cloture=".($this->date_cloture!=''?"'".$this->db->idate($this->date_cloture)."'":"null").","; |
|
2911 | - $sql.= " vat_src_code='".$this->db->escape($this->vat_src_code)."',"; |
|
2912 | - $sql.= " tva_tx=".price2num($this->tva_tx).","; |
|
2913 | - $sql.= " localtax1_tx=".price2num($this->localtax1_tx).","; |
|
2914 | - $sql.= " localtax2_tx=".price2num($this->localtax2_tx).","; |
|
2915 | - $sql.= " qty=".price2num($this->qty).","; |
|
2916 | - $sql.= " remise_percent=".price2num($this->remise_percent).","; |
|
2917 | - $sql.= " remise=".($this->remise?price2num($this->remise):"null").","; |
|
2918 | - $sql.= " fk_remise_except=".($this->fk_remise_except > 0?$this->fk_remise_except:"null").","; |
|
2919 | - $sql.= " subprice=".($this->subprice != '' ? $this->subprice : "null").","; |
|
2920 | - $sql.= " price_ht=".($this->price_ht != '' ? $this->price_ht : "null").","; |
|
2921 | - $sql.= " total_ht=".$this->total_ht.","; |
|
2922 | - $sql.= " total_tva=".$this->total_tva.","; |
|
2923 | - $sql.= " total_localtax1=".$this->total_localtax1.","; |
|
2924 | - $sql.= " total_localtax2=".$this->total_localtax2.","; |
|
2925 | - $sql.= " total_ttc=".$this->total_ttc.","; |
|
2926 | - $sql.= " fk_product_fournisseur_price=".(!empty($this->fk_fournprice)?$this->fk_fournprice:"NULL").","; |
|
2927 | - $sql.= " buy_price_ht='".price2num($this->pa_ht)."',"; |
|
2928 | - $sql.= " info_bits='".$this->db->escape($this->info_bits)."',"; |
|
2929 | - $sql.= " fk_user_author=".($this->fk_user_author >= 0?$this->fk_user_author:"NULL").","; |
|
2930 | - $sql.= " fk_user_ouverture=".($this->fk_user_ouverture > 0?$this->fk_user_ouverture:"NULL").","; |
|
2931 | - $sql.= " fk_user_cloture=".($this->fk_user_cloture > 0?$this->fk_user_cloture:"NULL").","; |
|
2932 | - $sql.= " commentaire='".$this->db->escape($this->commentaire)."',"; |
|
2933 | - $sql.= " fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); |
|
2934 | - $sql.= " WHERE rowid=".$this->id; |
|
2901 | + $sql .= " fk_contrat=".$this->fk_contrat.","; |
|
2902 | + $sql .= " fk_product=".($this->fk_product ? "'".$this->db->escape($this->fk_product)."'" : 'null').","; |
|
2903 | + $sql .= " statut=".$this->statut.","; |
|
2904 | + $sql .= " label='".$this->db->escape($this->label)."',"; |
|
2905 | + $sql .= " description='".$this->db->escape($this->description)."',"; |
|
2906 | + $sql .= " date_commande=".($this->date_commande != '' ? "'".$this->db->idate($this->date_commande)."'" : "null").","; |
|
2907 | + $sql .= " date_ouverture_prevue=".($this->date_ouverture_prevue != '' ? "'".$this->db->idate($this->date_ouverture_prevue)."'" : "null").","; |
|
2908 | + $sql .= " date_ouverture=".($this->date_ouverture != '' ? "'".$this->db->idate($this->date_ouverture)."'" : "null").","; |
|
2909 | + $sql .= " date_fin_validite=".($this->date_fin_validite != '' ? "'".$this->db->idate($this->date_fin_validite)."'" : "null").","; |
|
2910 | + $sql .= " date_cloture=".($this->date_cloture != '' ? "'".$this->db->idate($this->date_cloture)."'" : "null").","; |
|
2911 | + $sql .= " vat_src_code='".$this->db->escape($this->vat_src_code)."',"; |
|
2912 | + $sql .= " tva_tx=".price2num($this->tva_tx).","; |
|
2913 | + $sql .= " localtax1_tx=".price2num($this->localtax1_tx).","; |
|
2914 | + $sql .= " localtax2_tx=".price2num($this->localtax2_tx).","; |
|
2915 | + $sql .= " qty=".price2num($this->qty).","; |
|
2916 | + $sql .= " remise_percent=".price2num($this->remise_percent).","; |
|
2917 | + $sql .= " remise=".($this->remise ?price2num($this->remise) : "null").","; |
|
2918 | + $sql .= " fk_remise_except=".($this->fk_remise_except > 0 ? $this->fk_remise_except : "null").","; |
|
2919 | + $sql .= " subprice=".($this->subprice != '' ? $this->subprice : "null").","; |
|
2920 | + $sql .= " price_ht=".($this->price_ht != '' ? $this->price_ht : "null").","; |
|
2921 | + $sql .= " total_ht=".$this->total_ht.","; |
|
2922 | + $sql .= " total_tva=".$this->total_tva.","; |
|
2923 | + $sql .= " total_localtax1=".$this->total_localtax1.","; |
|
2924 | + $sql .= " total_localtax2=".$this->total_localtax2.","; |
|
2925 | + $sql .= " total_ttc=".$this->total_ttc.","; |
|
2926 | + $sql .= " fk_product_fournisseur_price=".(!empty($this->fk_fournprice) ? $this->fk_fournprice : "NULL").","; |
|
2927 | + $sql .= " buy_price_ht='".price2num($this->pa_ht)."',"; |
|
2928 | + $sql .= " info_bits='".$this->db->escape($this->info_bits)."',"; |
|
2929 | + $sql .= " fk_user_author=".($this->fk_user_author >= 0 ? $this->fk_user_author : "NULL").","; |
|
2930 | + $sql .= " fk_user_ouverture=".($this->fk_user_ouverture > 0 ? $this->fk_user_ouverture : "NULL").","; |
|
2931 | + $sql .= " fk_user_cloture=".($this->fk_user_cloture > 0 ? $this->fk_user_cloture : "NULL").","; |
|
2932 | + $sql .= " commentaire='".$this->db->escape($this->commentaire)."',"; |
|
2933 | + $sql .= " fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); |
|
2934 | + $sql .= " WHERE rowid=".$this->id; |
|
2935 | 2935 | |
2936 | 2936 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
2937 | 2937 | $resql = $this->db->query($sql); |
2938 | 2938 | if ($resql) |
2939 | 2939 | { |
2940 | - $contrat=new Contrat($this->db); |
|
2940 | + $contrat = new Contrat($this->db); |
|
2941 | 2941 | $contrat->fetch($this->fk_contrat); |
2942 | - $result=$contrat->update_statut($user); |
|
2942 | + $result = $contrat->update_statut($user); |
|
2943 | 2943 | } |
2944 | 2944 | else |
2945 | 2945 | { |
2946 | - $this->error="Error ".$this->db->lasterror(); |
|
2946 | + $this->error = "Error ".$this->db->lasterror(); |
|
2947 | 2947 | $error++; |
2948 | 2948 | //return -1; |
2949 | 2949 | } |
2950 | 2950 | |
2951 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used |
|
2951 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) // For avoid conflicts if trigger used |
|
2952 | 2952 | { |
2953 | 2953 | |
2954 | - $result=$this->insertExtraFields(); |
|
2954 | + $result = $this->insertExtraFields(); |
|
2955 | 2955 | if ($result < 0) |
2956 | 2956 | { |
2957 | 2957 | $error++; |
@@ -2959,10 +2959,10 @@ discard block |
||
2959 | 2959 | } |
2960 | 2960 | |
2961 | 2961 | if (empty($error)) { |
2962 | - if (! $notrigger) |
|
2962 | + if (!$notrigger) |
|
2963 | 2963 | { |
2964 | 2964 | // Call trigger |
2965 | - $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
2965 | + $result = $this->call_trigger('LINECONTRACT_UPDATE', $user); |
|
2966 | 2966 | if ($result < 0) { $error++; $this->db->rollback(); return -1; } |
2967 | 2967 | // End call triggers |
2968 | 2968 | } |
@@ -2973,7 +2973,7 @@ discard block |
||
2973 | 2973 | return 1; |
2974 | 2974 | } else { |
2975 | 2975 | $this->db->rollback(); |
2976 | - $this->errors[]=$this->error; |
|
2976 | + $this->errors[] = $this->error; |
|
2977 | 2977 | return -1; |
2978 | 2978 | } |
2979 | 2979 | } |
@@ -2991,16 +2991,16 @@ discard block |
||
2991 | 2991 | |
2992 | 2992 | // Mise a jour ligne en base |
2993 | 2993 | $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET"; |
2994 | - $sql.= " total_ht=".price2num($this->total_ht,'MT').""; |
|
2995 | - $sql.= ",total_tva=".price2num($this->total_tva,'MT').""; |
|
2996 | - $sql.= ",total_localtax1=".price2num($this->total_localtax1,'MT').""; |
|
2997 | - $sql.= ",total_localtax2=".price2num($this->total_localtax2,'MT').""; |
|
2998 | - $sql.= ",total_ttc=".price2num($this->total_ttc,'MT').""; |
|
2999 | - $sql.= " WHERE rowid = ".$this->id; |
|
2994 | + $sql .= " total_ht=".price2num($this->total_ht, 'MT').""; |
|
2995 | + $sql .= ",total_tva=".price2num($this->total_tva, 'MT').""; |
|
2996 | + $sql .= ",total_localtax1=".price2num($this->total_localtax1, 'MT').""; |
|
2997 | + $sql .= ",total_localtax2=".price2num($this->total_localtax2, 'MT').""; |
|
2998 | + $sql .= ",total_ttc=".price2num($this->total_ttc, 'MT').""; |
|
2999 | + $sql .= " WHERE rowid = ".$this->id; |
|
3000 | 3000 | |
3001 | 3001 | dol_syslog(get_class($this)."::update_total", LOG_DEBUG); |
3002 | 3002 | |
3003 | - $resql=$this->db->query($sql); |
|
3003 | + $resql = $this->db->query($sql); |
|
3004 | 3004 | if ($resql) |
3005 | 3005 | { |
3006 | 3006 | $this->db->commit(); |
@@ -3008,7 +3008,7 @@ discard block |
||
3008 | 3008 | } |
3009 | 3009 | else |
3010 | 3010 | { |
3011 | - $this->error=$this->db->error(); |
|
3011 | + $this->error = $this->db->error(); |
|
3012 | 3012 | $this->db->rollback(); |
3013 | 3013 | return -2; |
3014 | 3014 | } |
@@ -3027,37 +3027,37 @@ discard block |
||
3027 | 3027 | |
3028 | 3028 | // Insertion dans la base |
3029 | 3029 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet"; |
3030 | - $sql.= " (fk_contrat, label, description, fk_product, qty, vat_src_code, tva_tx,"; |
|
3031 | - $sql.= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice,"; |
|
3032 | - $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,"; |
|
3033 | - $sql.= " info_bits,"; |
|
3034 | - $sql.= " price_ht, remise, fk_product_fournisseur_price, buy_price_ht"; |
|
3035 | - if ($this->date_ouverture_prevue > 0) { $sql.= ",date_ouverture_prevue"; } |
|
3036 | - if ($this->date_fin_validite > 0) { $sql.= ",date_fin_validite"; } |
|
3037 | - $sql.= ") VALUES ($this->fk_contrat, '', '" . $this->db->escape($this->description) . "',"; |
|
3038 | - $sql.= ($this->fk_product>0 ? $this->fk_product : "null").","; |
|
3039 | - $sql.= " '".$this->db->escape($this->qty)."',"; |
|
3040 | - $sql.= " '".$this->db->escape($this->vat_src_code)."',"; |
|
3041 | - $sql.= " '".$this->db->escape($this->tva_tx)."',"; |
|
3042 | - $sql.= " '".$this->db->escape($this->localtax1_tx)."',"; |
|
3043 | - $sql.= " '".$this->db->escape($this->localtax2_tx)."',"; |
|
3044 | - $sql.= " '".$this->db->escape($this->localtax1_type)."',"; |
|
3045 | - $sql.= " '".$this->db->escape($this->localtax2_type)."',"; |
|
3046 | - $sql.= " ".price2num($this->remise_percent).",".price2num($this->subprice).","; |
|
3047 | - $sql.= " ".price2num($this->total_ht).",".price2num($this->total_tva).",".price2num($this->total_localtax1).",".price2num($this->total_localtax2).",".price2num($this->total_ttc).","; |
|
3048 | - $sql.= " '".$this->db->escape($this->info_bits)."',"; |
|
3049 | - $sql.= " ".price2num($this->price_ht).",".price2num($this->remise).","; |
|
3050 | - if ($this->fk_fournprice > 0) $sql.= ' '.$this->fk_fournprice.','; |
|
3051 | - else $sql.= ' null,'; |
|
3052 | - if ($this->pa_ht > 0) $sql.= ' '.price2num($this->pa_ht); |
|
3053 | - else $sql.= ' null'; |
|
3054 | - if ($this->date_ouverture_prevue > 0) { $sql.= ",'".$this->db->idate($this->date_ouverture_prevue)."'"; } |
|
3055 | - if ($this->date_fin_validite > 0) { $sql.= ",'".$this->db->idate($this->date_fin_validite)."'"; } |
|
3056 | - $sql.= ")"; |
|
3030 | + $sql .= " (fk_contrat, label, description, fk_product, qty, vat_src_code, tva_tx,"; |
|
3031 | + $sql .= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice,"; |
|
3032 | + $sql .= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,"; |
|
3033 | + $sql .= " info_bits,"; |
|
3034 | + $sql .= " price_ht, remise, fk_product_fournisseur_price, buy_price_ht"; |
|
3035 | + if ($this->date_ouverture_prevue > 0) { $sql .= ",date_ouverture_prevue"; } |
|
3036 | + if ($this->date_fin_validite > 0) { $sql .= ",date_fin_validite"; } |
|
3037 | + $sql .= ") VALUES ($this->fk_contrat, '', '".$this->db->escape($this->description)."',"; |
|
3038 | + $sql .= ($this->fk_product > 0 ? $this->fk_product : "null").","; |
|
3039 | + $sql .= " '".$this->db->escape($this->qty)."',"; |
|
3040 | + $sql .= " '".$this->db->escape($this->vat_src_code)."',"; |
|
3041 | + $sql .= " '".$this->db->escape($this->tva_tx)."',"; |
|
3042 | + $sql .= " '".$this->db->escape($this->localtax1_tx)."',"; |
|
3043 | + $sql .= " '".$this->db->escape($this->localtax2_tx)."',"; |
|
3044 | + $sql .= " '".$this->db->escape($this->localtax1_type)."',"; |
|
3045 | + $sql .= " '".$this->db->escape($this->localtax2_type)."',"; |
|
3046 | + $sql .= " ".price2num($this->remise_percent).",".price2num($this->subprice).","; |
|
3047 | + $sql .= " ".price2num($this->total_ht).",".price2num($this->total_tva).",".price2num($this->total_localtax1).",".price2num($this->total_localtax2).",".price2num($this->total_ttc).","; |
|
3048 | + $sql .= " '".$this->db->escape($this->info_bits)."',"; |
|
3049 | + $sql .= " ".price2num($this->price_ht).",".price2num($this->remise).","; |
|
3050 | + if ($this->fk_fournprice > 0) $sql .= ' '.$this->fk_fournprice.','; |
|
3051 | + else $sql .= ' null,'; |
|
3052 | + if ($this->pa_ht > 0) $sql .= ' '.price2num($this->pa_ht); |
|
3053 | + else $sql .= ' null'; |
|
3054 | + if ($this->date_ouverture_prevue > 0) { $sql .= ",'".$this->db->idate($this->date_ouverture_prevue)."'"; } |
|
3055 | + if ($this->date_fin_validite > 0) { $sql .= ",'".$this->db->idate($this->date_fin_validite)."'"; } |
|
3056 | + $sql .= ")"; |
|
3057 | 3057 | |
3058 | 3058 | dol_syslog(get_class($this)."::insert", LOG_DEBUG); |
3059 | 3059 | |
3060 | - $resql=$this->db->query($sql); |
|
3060 | + $resql = $this->db->query($sql); |
|
3061 | 3061 | if ($resql) |
3062 | 3062 | { |
3063 | 3063 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'contratdet'); |
@@ -3081,7 +3081,7 @@ discard block |
||
3081 | 3081 | else |
3082 | 3082 | { |
3083 | 3083 | $this->db->rollback(); |
3084 | - $this->error=$this->db->error()." sql=".$sql; |
|
3084 | + $this->error = $this->db->error()." sql=".$sql; |
|
3085 | 3085 | return -1; |
3086 | 3086 | } |
3087 | 3087 | } |
@@ -3110,15 +3110,15 @@ discard block |
||
3110 | 3110 | |
3111 | 3111 | $this->db->begin(); |
3112 | 3112 | |
3113 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = 4,"; |
|
3114 | - $sql .= " date_ouverture = " . (dol_strlen($date) != 0 ? "'" . $this->db->idate($date) . "'" : "null") . ","; |
|
3115 | - if ($date_end >= 0) $sql .= " date_fin_validite = " . (dol_strlen($date_end) != 0 ? "'" . $this->db->idate($date_end) . "'" : "null") . ","; |
|
3116 | - $sql .= " fk_user_ouverture = " . $user->id . ","; |
|
3113 | + $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = 4,"; |
|
3114 | + $sql .= " date_ouverture = ".(dol_strlen($date) != 0 ? "'".$this->db->idate($date)."'" : "null").","; |
|
3115 | + if ($date_end >= 0) $sql .= " date_fin_validite = ".(dol_strlen($date_end) != 0 ? "'".$this->db->idate($date_end)."'" : "null").","; |
|
3116 | + $sql .= " fk_user_ouverture = ".$user->id.","; |
|
3117 | 3117 | $sql .= " date_cloture = null,"; |
3118 | - $sql .= " commentaire = '" . $this->db->escape($comment) . "'"; |
|
3119 | - $sql .= " WHERE rowid = " . $this->id . " AND (statut = 0 OR statut = 3 OR statut = 5)"; |
|
3118 | + $sql .= " commentaire = '".$this->db->escape($comment)."'"; |
|
3119 | + $sql .= " WHERE rowid = ".$this->id." AND (statut = 0 OR statut = 3 OR statut = 5)"; |
|
3120 | 3120 | |
3121 | - dol_syslog(get_class($this) . "::active_line", LOG_DEBUG); |
|
3121 | + dol_syslog(get_class($this)."::active_line", LOG_DEBUG); |
|
3122 | 3122 | $resql = $this->db->query($sql); |
3123 | 3123 | if ($resql) { |
3124 | 3124 | // Call trigger |
@@ -3162,11 +3162,11 @@ discard block |
||
3162 | 3162 | |
3163 | 3163 | $this->db->begin(); |
3164 | 3164 | |
3165 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = 5,"; |
|
3166 | - $sql .= " date_cloture = '" . $this->db->idate($date_end) . "',"; |
|
3167 | - $sql .= " fk_user_cloture = " . $user->id . ","; |
|
3168 | - $sql .= " commentaire = '" . $this->db->escape($comment) . "'"; |
|
3169 | - $sql .= " WHERE rowid = " . $this->id . " AND statut = 4"; |
|
3165 | + $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = 5,"; |
|
3166 | + $sql .= " date_cloture = '".$this->db->idate($date_end)."',"; |
|
3167 | + $sql .= " fk_user_cloture = ".$user->id.","; |
|
3168 | + $sql .= " commentaire = '".$this->db->escape($comment)."'"; |
|
3169 | + $sql .= " WHERE rowid = ".$this->id." AND statut = 4"; |
|
3170 | 3170 | |
3171 | 3171 | $resql = $this->db->query($sql); |
3172 | 3172 | if ($resql) { |
@@ -50,7 +50,7 @@ |
||
50 | 50 | * @param string $htmlname Nom de la zone html |
51 | 51 | * @param int $maxlength Maximum length of label |
52 | 52 | * @param int $showempty Show empty line |
53 | - * @return int Nbre of project if OK, <0 if KO |
|
53 | + * @return string Nbre of project if OK, <0 if KO |
|
54 | 54 | */ |
55 | 55 | function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1) |
56 | 56 | { |
@@ -52,30 +52,30 @@ discard block |
||
52 | 52 | * @param int $showempty Show empty line |
53 | 53 | * @return int Nbre of project if OK, <0 if KO |
54 | 54 | */ |
55 | - function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1) |
|
55 | + function select_interventions($socid = -1, $selected = '', $htmlname = 'interventionid', $maxlength = 16, $showempty = 1) |
|
56 | 56 | { |
57 | - global $db,$user,$conf,$langs; |
|
57 | + global $db, $user, $conf, $langs; |
|
58 | 58 | |
59 | - $out=''; |
|
59 | + $out = ''; |
|
60 | 60 | |
61 | - $hideunselectables=false; |
|
61 | + $hideunselectables = false; |
|
62 | 62 | |
63 | 63 | // Search all contacts |
64 | 64 | $sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut'; |
65 | - $sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f'; |
|
66 | - $sql.= " WHERE f.entity = ".$conf->entity; |
|
65 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinter as f'; |
|
66 | + $sql .= " WHERE f.entity = ".$conf->entity; |
|
67 | 67 | if ($socid != '') |
68 | 68 | { |
69 | - if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
70 | - else $sql.= " AND f.fk_soc = ".$socid; |
|
69 | + if ($socid == '0') $sql .= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
70 | + else $sql .= " AND f.fk_soc = ".$socid; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG); |
74 | - $resql=$db->query($sql); |
|
74 | + $resql = $db->query($sql); |
|
75 | 75 | if ($resql) |
76 | 76 | { |
77 | - $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
|
78 | - if ($showempty) $out.='<option value="0"> </option>'; |
|
77 | + $out .= '<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
|
78 | + if ($showempty) $out .= '<option value="0"> </option>'; |
|
79 | 79 | $num = $db->num_rows($resql); |
80 | 80 | $i = 0; |
81 | 81 | if ($num) |
@@ -84,49 +84,49 @@ discard block |
||
84 | 84 | { |
85 | 85 | $obj = $db->fetch_object($resql); |
86 | 86 | // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. |
87 | - if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) |
|
87 | + if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire) |
|
88 | 88 | { |
89 | 89 | // Do nothing |
90 | 90 | } |
91 | 91 | else |
92 | 92 | { |
93 | - $labeltoshow=dol_trunc($obj->ref,18); |
|
93 | + $labeltoshow = dol_trunc($obj->ref, 18); |
|
94 | 94 | if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
95 | 95 | { |
96 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
96 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
97 | 97 | } |
98 | 98 | else |
99 | 99 | { |
100 | - $disabled=0; |
|
101 | - if (! $obj->fk_statut > 0) |
|
100 | + $disabled = 0; |
|
101 | + if (!$obj->fk_statut > 0) |
|
102 | 102 | { |
103 | - $disabled=1; |
|
104 | - $labeltoshow.=' ('.$langs->trans("Draft").')'; |
|
103 | + $disabled = 1; |
|
104 | + $labeltoshow .= ' ('.$langs->trans("Draft").')'; |
|
105 | 105 | } |
106 | - if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
106 | + if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) |
|
107 | 107 | { |
108 | - $disabled=1; |
|
109 | - $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); |
|
108 | + $disabled = 1; |
|
109 | + $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany"); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | if ($hideunselectables && $disabled) |
113 | 113 | { |
114 | - $resultat=''; |
|
114 | + $resultat = ''; |
|
115 | 115 | } |
116 | 116 | else |
117 | 117 | { |
118 | - $resultat='<option value="'.$obj->rowid.'"'; |
|
119 | - if ($disabled) $resultat.=' disabled'; |
|
120 | - $resultat.='>'.$labeltoshow; |
|
121 | - $resultat.='</option>'; |
|
118 | + $resultat = '<option value="'.$obj->rowid.'"'; |
|
119 | + if ($disabled) $resultat .= ' disabled'; |
|
120 | + $resultat .= '>'.$labeltoshow; |
|
121 | + $resultat .= '</option>'; |
|
122 | 122 | } |
123 | - $out.=$resultat; |
|
123 | + $out .= $resultat; |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | $i++; |
127 | 127 | } |
128 | 128 | } |
129 | - $out.='</select>'; |
|
129 | + $out .= '</select>'; |
|
130 | 130 | $db->free($resql); |
131 | 131 | return $out; |
132 | 132 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | * |
52 | 52 | * @param CommonObject $object Object we want to get margin information for |
53 | 53 | * @param boolean $force_price True of not |
54 | - * @return array Array with info |
|
54 | + * @return integer Array with info |
|
55 | 55 | */ |
56 | 56 | function getMarginInfosArray($object, $force_price=false) |
57 | 57 | { |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param boolean $force_price True of not |
55 | 55 | * @return array Array with info |
56 | 56 | */ |
57 | - function getMarginInfosArray($object, $force_price=false) |
|
57 | + function getMarginInfosArray($object, $force_price = false) |
|
58 | 58 | { |
59 | 59 | global $conf, $db; |
60 | 60 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'total_mark_rate' => '' |
78 | 78 | ); |
79 | 79 | |
80 | - foreach($object->lines as $line) |
|
80 | + foreach ($object->lines as $line) |
|
81 | 81 | { |
82 | 82 | if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price) |
83 | 83 | { |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | $pv = $line->qty * $line->subprice * (1 - $line->remise_percent / 100); |
97 | - $pa_ht = ($pv < 0 ? - $line->pa_ht : $line->pa_ht); // We choosed to have line->pa_ht always positive in database, so we guess the correct sign |
|
97 | + $pa_ht = ($pv < 0 ? -$line->pa_ht : $line->pa_ht); // We choosed to have line->pa_ht always positive in database, so we guess the correct sign |
|
98 | 98 | $pa = $line->qty * $pa_ht; |
99 | 99 | |
100 | 100 | // calcul des marges |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit |
103 | 103 | $marginInfos['pa_products'] += $pa; |
104 | 104 | $marginInfos['pv_products'] += $pv; |
105 | - $marginInfos['pa_total'] += $pa; |
|
106 | - $marginInfos['pv_total'] += $pv; |
|
105 | + $marginInfos['pa_total'] += $pa; |
|
106 | + $marginInfos['pv_total'] += $pv; |
|
107 | 107 | // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
108 | 108 | //if ($pv < 0) |
109 | 109 | //{ |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service |
116 | 116 | $marginInfos['pa_services'] += $pa; |
117 | 117 | $marginInfos['pv_services'] += $pv; |
118 | - $marginInfos['pa_total'] += $pa; |
|
119 | - $marginInfos['pv_total'] += $pv; |
|
118 | + $marginInfos['pa_total'] += $pa; |
|
119 | + $marginInfos['pv_total'] += $pv; |
|
120 | 120 | // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
121 | 121 | //if ($pv < 0) |
122 | 122 | // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | } |
130 | 130 | } |
131 | 131 | else { |
132 | - $type=$line->product_type?$line->product_type:$line->fk_product_type; |
|
132 | + $type = $line->product_type ? $line->product_type : $line->fk_product_type; |
|
133 | 133 | if ($type == 0) { // product |
134 | 134 | $marginInfos['pa_products'] += $pa; |
135 | 135 | $marginInfos['pv_products'] += $pv; |
136 | - $marginInfos['pa_total'] += $pa; |
|
137 | - $marginInfos['pv_total'] += $pv; |
|
136 | + $marginInfos['pa_total'] += $pa; |
|
137 | + $marginInfos['pv_total'] += $pv; |
|
138 | 138 | // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
139 | 139 | //if ($pv < 0) |
140 | 140 | //{ |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | elseif ($type == 1) { // service |
149 | 149 | $marginInfos['pa_services'] += $pa; |
150 | 150 | $marginInfos['pv_services'] += $pv; |
151 | - $marginInfos['pa_total'] += $pa; |
|
152 | - $marginInfos['pv_total'] += $pv; |
|
151 | + $marginInfos['pa_total'] += $pa; |
|
152 | + $marginInfos['pv_total'] += $pv; |
|
153 | 153 | // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
154 | 154 | //if ($pv < 0) |
155 | 155 | // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); |
@@ -188,24 +188,24 @@ discard block |
||
188 | 188 | * @param boolean $force_price Force price |
189 | 189 | * @return void |
190 | 190 | */ |
191 | - function displayMarginInfos($object, $force_price=false) |
|
191 | + function displayMarginInfos($object, $force_price = false) |
|
192 | 192 | { |
193 | 193 | global $langs, $conf, $user; |
194 | 194 | |
195 | - if (! empty($user->societe_id)) return; |
|
195 | + if (!empty($user->societe_id)) return; |
|
196 | 196 | |
197 | - if (! $user->rights->margins->liretous) return; |
|
197 | + if (!$user->rights->margins->liretous) return; |
|
198 | 198 | |
199 | 199 | $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
200 | 200 | |
201 | 201 | $marginInfo = $this->getMarginInfosArray($object, $force_price); |
202 | 202 | |
203 | - if (! empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better |
|
203 | + if (!empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better |
|
204 | 204 | { |
205 | 205 | print $langs->trans('ShowMarginInfos').' : '; |
206 | 206 | $hidemargininfos = $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']; |
207 | - print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'':'hideobject').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>'; |
|
208 | - print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'hideobject':'').'">'.img_picto($langs->trans("Enabled"),'switch_on').'</span>'; |
|
207 | + print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos) ? '' : 'hideobject').'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</span>'; |
|
208 | + print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos) ? 'hideobject' : '').'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</span>'; |
|
209 | 209 | |
210 | 210 | print '<script>$(document).ready(function() { |
211 | 211 | $("span#showMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 0); $(".margininfos").show(); $("span#showMarginInfos").addClass("hideobject"); $("span#hideMarginInfos").removeClass("hideobject");})}); |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | else |
225 | 225 | print '<td class="liste_titre" align="right">'.$langs->trans('CostPrice').'</td>'; |
226 | 226 | print '<td class="liste_titre" align="right">'.$langs->trans('Margin').'</td>'; |
227 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
227 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
228 | 228 | print '<td class="liste_titre" align="right">'.$langs->trans('MarginRate').'</td>'; |
229 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
229 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
230 | 230 | print '<td class="liste_titre" align="right">'.$langs->trans('MarkRate').'</td>'; |
231 | 231 | print '</tr>'; |
232 | 232 | |
233 | - if (! empty($conf->product->enabled)) |
|
233 | + if (!empty($conf->product->enabled)) |
|
234 | 234 | { |
235 | 235 | //if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) { |
236 | 236 | print '<tr class="oddeven">'; |
@@ -238,38 +238,38 @@ discard block |
||
238 | 238 | print '<td align="right">'.price($marginInfo['pv_products'], null, null, null, null, $rounding).'</td>'; |
239 | 239 | print '<td align="right">'.price($marginInfo['pa_products'], null, null, null, null, $rounding).'</td>'; |
240 | 240 | print '<td align="right">'.price($marginInfo['margin_on_products'], null, null, null, null, $rounding).'</td>'; |
241 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
242 | - print '<td align="right">'.(($marginInfo['margin_rate_products'] == '')?'':price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
243 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
244 | - print '<td align="right">'.(($marginInfo['mark_rate_products'] == '')?'':price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
241 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
242 | + print '<td align="right">'.(($marginInfo['margin_rate_products'] == '') ? '' : price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
243 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
244 | + print '<td align="right">'.(($marginInfo['mark_rate_products'] == '') ? '' : price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
245 | 245 | print '</tr>'; |
246 | 246 | } |
247 | 247 | |
248 | - if (! empty($conf->service->enabled)) |
|
248 | + if (!empty($conf->service->enabled)) |
|
249 | 249 | { |
250 | 250 | print '<tr class="oddeven">'; |
251 | 251 | print '<td>'.$langs->trans('MarginOnServices').'</td>'; |
252 | 252 | print '<td align="right">'.price($marginInfo['pv_services'], null, null, null, null, $rounding).'</td>'; |
253 | 253 | print '<td align="right">'.price($marginInfo['pa_services'], null, null, null, null, $rounding).'</td>'; |
254 | 254 | print '<td align="right">'.price($marginInfo['margin_on_services'], null, null, null, null, $rounding).'</td>'; |
255 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
256 | - print '<td align="right">'.(($marginInfo['margin_rate_services'] == '')?'':price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
257 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
258 | - print '<td align="right">'.(($marginInfo['mark_rate_services'] == '')?'':price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
255 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
256 | + print '<td align="right">'.(($marginInfo['margin_rate_services'] == '') ? '' : price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
257 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
258 | + print '<td align="right">'.(($marginInfo['mark_rate_services'] == '') ? '' : price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
259 | 259 | print '</tr>'; |
260 | 260 | } |
261 | 261 | |
262 | - if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) |
|
262 | + if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) |
|
263 | 263 | { |
264 | 264 | print '<tr class="liste_total">'; |
265 | 265 | print '<td>'.$langs->trans('TotalMargin').'</td>'; |
266 | 266 | print '<td align="right">'.price($marginInfo['pv_total'], null, null, null, null, $rounding).'</td>'; |
267 | 267 | print '<td align="right">'.price($marginInfo['pa_total'], null, null, null, null, $rounding).'</td>'; |
268 | 268 | print '<td align="right">'.price($marginInfo['total_margin'], null, null, null, null, $rounding).'</td>'; |
269 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
270 | - print '<td align="right">'.(($marginInfo['total_margin_rate'] == '')?'':price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
271 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
272 | - print '<td align="right">'.(($marginInfo['total_mark_rate'] == '')?'':price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
269 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
270 | + print '<td align="right">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
271 | + if (!empty($conf->global->DISPLAY_MARK_RATES)) |
|
272 | + print '<td align="right">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
273 | 273 | print '</tr>'; |
274 | 274 | } |
275 | 275 | print '</table>'; |
@@ -95,7 +95,7 @@ |
||
95 | 95 | /** |
96 | 96 | * Return last error code |
97 | 97 | * |
98 | - * @return string lasterrno |
|
98 | + * @return integer lasterrno |
|
99 | 99 | */ |
100 | 100 | function lasterrno() |
101 | 101 | { |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * \brief Class file to manage Dolibarr database access |
23 | 23 | */ |
24 | 24 | |
25 | -require_once DOL_DOCUMENT_ROOT .'/core/db/Database.interface.php'; |
|
25 | +require_once DOL_DOCUMENT_ROOT.'/core/db/Database.interface.php'; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Class to manage Dolibarr database access |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | /** @var string Database type */ |
35 | 35 | public $type; |
36 | 36 | /** @var string Charset used to force charset when creating database */ |
37 | - public $forcecharset='utf8'; |
|
37 | + public $forcecharset = 'utf8'; |
|
38 | 38 | /** @var string Collate used to force collate when creating database */ |
39 | - public $forcecollate='utf8_unicode_ci'; |
|
39 | + public $forcecollate = 'utf8_unicode_ci'; |
|
40 | 40 | /** @var resource Resultset of last query */ |
41 | 41 | private $_results; |
42 | 42 | /** @var bool true if connected, else false */ |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @param string $resko resultat si test non egal |
76 | 76 | * @return string SQL string |
77 | 77 | */ |
78 | - function ifsql($test,$resok,$resko) |
|
78 | + function ifsql($test, $resok, $resko) |
|
79 | 79 | { |
80 | 80 | return 'IF('.$test.','.$resok.','.$resko.')'; |
81 | 81 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | function idate($param) |
91 | 91 | { |
92 | - return dol_print_date($param,"%Y%m%d%H%M%S"); |
|
92 | + return dol_print_date($param, "%Y%m%d%H%M%S"); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -109,21 +109,21 @@ discard block |
||
109 | 109 | */ |
110 | 110 | function begin() |
111 | 111 | { |
112 | - if (! $this->transaction_opened) |
|
112 | + if (!$this->transaction_opened) |
|
113 | 113 | { |
114 | - $ret=$this->query("BEGIN"); |
|
114 | + $ret = $this->query("BEGIN"); |
|
115 | 115 | if ($ret) |
116 | 116 | { |
117 | 117 | $this->transaction_opened++; |
118 | - dol_syslog("BEGIN Transaction",LOG_DEBUG); |
|
119 | - dol_syslog('',0,1); |
|
118 | + dol_syslog("BEGIN Transaction", LOG_DEBUG); |
|
119 | + dol_syslog('', 0, 1); |
|
120 | 120 | } |
121 | 121 | return $ret; |
122 | 122 | } |
123 | 123 | else |
124 | 124 | { |
125 | 125 | $this->transaction_opened++; |
126 | - dol_syslog('',0,1); |
|
126 | + dol_syslog('', 0, 1); |
|
127 | 127 | return 1; |
128 | 128 | } |
129 | 129 | } |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | * @param string $log Add more log to default log line |
135 | 135 | * @return int 1 if validation is OK or transaction level no started, 0 if ERROR |
136 | 136 | */ |
137 | - function commit($log='') |
|
137 | + function commit($log = '') |
|
138 | 138 | { |
139 | - dol_syslog('',0,-1); |
|
140 | - if ($this->transaction_opened<=1) |
|
139 | + dol_syslog('', 0, -1); |
|
140 | + if ($this->transaction_opened <= 1) |
|
141 | 141 | { |
142 | - $ret=$this->query("COMMIT"); |
|
142 | + $ret = $this->query("COMMIT"); |
|
143 | 143 | if ($ret) |
144 | 144 | { |
145 | - $this->transaction_opened=0; |
|
146 | - dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); |
|
145 | + $this->transaction_opened = 0; |
|
146 | + dol_syslog("COMMIT Transaction".($log ? ' '.$log : ''), LOG_DEBUG); |
|
147 | 147 | return 1; |
148 | 148 | } |
149 | 149 | else |
@@ -164,14 +164,14 @@ discard block |
||
164 | 164 | * @param string $log Add more log to default log line |
165 | 165 | * @return resource|int 1 si annulation ok ou transaction non ouverte, 0 en cas d'erreur |
166 | 166 | */ |
167 | - function rollback($log='') |
|
167 | + function rollback($log = '') |
|
168 | 168 | { |
169 | - dol_syslog('',0,-1); |
|
170 | - if ($this->transaction_opened<=1) |
|
169 | + dol_syslog('', 0, -1); |
|
170 | + if ($this->transaction_opened <= 1) |
|
171 | 171 | { |
172 | - $ret=$this->query("ROLLBACK"); |
|
173 | - $this->transaction_opened=0; |
|
174 | - dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); |
|
172 | + $ret = $this->query("ROLLBACK"); |
|
173 | + $this->transaction_opened = 0; |
|
174 | + dol_syslog("ROLLBACK Transaction".($log ? ' '.$log : ''), LOG_DEBUG); |
|
175 | 175 | return $ret; |
176 | 176 | } |
177 | 177 | else |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | * @param int $offset Numero of line from where starting fetch |
189 | 189 | * @return string String with SQL syntax to add a limit and offset |
190 | 190 | */ |
191 | - function plimit($limit=0,$offset=0) |
|
191 | + function plimit($limit = 0, $offset = 0) |
|
192 | 192 | { |
193 | 193 | global $conf; |
194 | 194 | if (empty($limit)) return ""; |
195 | - if ($limit < 0) $limit=$conf->liste_limit; |
|
195 | + if ($limit < 0) $limit = $conf->liste_limit; |
|
196 | 196 | if ($offset > 0) return " LIMIT $offset,$limit "; |
197 | 197 | else return " LIMIT $limit "; |
198 | 198 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | function getVersionArray() |
206 | 206 | { |
207 | - return preg_split("/[\.,-]/",$this->getVersion()); |
|
207 | + return preg_split("/[\.,-]/", $this->getVersion()); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -224,20 +224,20 @@ discard block |
||
224 | 224 | * @param 'ASC'|'DESC' $sortorder Sort order |
225 | 225 | * @return string String to provide syntax of a sort sql string |
226 | 226 | */ |
227 | - function order($sortfield=null,$sortorder=null) |
|
227 | + function order($sortfield = null, $sortorder = null) |
|
228 | 228 | { |
229 | - if (! empty($sortfield)) |
|
229 | + if (!empty($sortfield)) |
|
230 | 230 | { |
231 | - $return=''; |
|
232 | - $fields=explode(',',$sortfield); |
|
233 | - $orders=explode(',',$sortorder); |
|
234 | - $i=0; |
|
235 | - foreach($fields as $val) |
|
231 | + $return = ''; |
|
232 | + $fields = explode(',', $sortfield); |
|
233 | + $orders = explode(',', $sortorder); |
|
234 | + $i = 0; |
|
235 | + foreach ($fields as $val) |
|
236 | 236 | { |
237 | - if (! $return) $return.=' ORDER BY '; |
|
238 | - else $return.=', '; |
|
237 | + if (!$return) $return .= ' ORDER BY '; |
|
238 | + else $return .= ', '; |
|
239 | 239 | |
240 | - $return.=preg_replace('/[^0-9a-z_\.]/i','',$val); |
|
240 | + $return .= preg_replace('/[^0-9a-z_\.]/i', '', $val); |
|
241 | 241 | |
242 | 242 | $tmpsortorder = trim($orders[$i]); |
243 | 243 | |
@@ -277,12 +277,12 @@ discard block |
||
277 | 277 | * @param bool $gm 1=Input informations are GMT values, otherwise local to server TZ |
278 | 278 | * @return int|string Date TMS or '' |
279 | 279 | */ |
280 | - function jdate($string, $gm=false) |
|
280 | + function jdate($string, $gm = false) |
|
281 | 281 | { |
282 | - if ($string==0 || $string=="0000-00-00 00:00:00") return ''; |
|
283 | - $string=preg_replace('/([^0-9])/i','',$string); |
|
284 | - $tmp=$string.'000000'; |
|
285 | - $date=dol_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),$gm); |
|
282 | + if ($string == 0 || $string == "0000-00-00 00:00:00") return ''; |
|
283 | + $string = preg_replace('/([^0-9])/i', '', $string); |
|
284 | + $tmp = $string.'000000'; |
|
285 | + $date = dol_mktime(substr($tmp, 8, 2), substr($tmp, 10, 2), substr($tmp, 12, 2), substr($tmp, 4, 2), substr($tmp, 6, 2), substr($tmp, 0, 4), $gm); |
|
286 | 286 | return $date; |
287 | 287 | } |
288 | 288 |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
320 | 320 | * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
321 | 321 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
322 | - * @return false|resource|true Resultset of answer |
|
322 | + * @return resource Resultset of answer |
|
323 | 323 | */ |
324 | 324 | function query($query,$usesavepoint=0,$type='auto') |
325 | 325 | { |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | * Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE |
517 | 517 | * |
518 | 518 | * @param resource $resultset Curseur de la requete voulue |
519 | - * @return int Nombre de lignes |
|
519 | + * @return string Nombre de lignes |
|
520 | 520 | * @see num_rows |
521 | 521 | */ |
522 | 522 | function affected_rows($resultset) |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * Free last resultset used. |
536 | 536 | * |
537 | 537 | * @param resource $resultset Curseur de la requete voulue |
538 | - * @return bool |
|
538 | + * @return boolean|null |
|
539 | 539 | */ |
540 | 540 | function free($resultset=null) |
541 | 541 | { |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | /** |
1016 | 1016 | * Return list of available charset that can be used to store data in database |
1017 | 1017 | * |
1018 | - * @return array List of Charset |
|
1018 | + * @return string List of Charset |
|
1019 | 1019 | */ |
1020 | 1020 | function getListOfCharacterSet() |
1021 | 1021 | { |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * \brief Fichier de la classe permettant de gerer une base MSSQL |
25 | 25 | */ |
26 | 26 | |
27 | -require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php'; |
|
27 | +require_once DOL_DOCUMENT_ROOT.'/core/db/DoliDB.class.php'; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Classe de gestion de la database de dolibarr |
@@ -32,15 +32,15 @@ discard block |
||
32 | 32 | class DoliDBMssql extends DoliDB |
33 | 33 | { |
34 | 34 | //! Database type |
35 | - public $type='mssql'; |
|
35 | + public $type = 'mssql'; |
|
36 | 36 | //! Database label |
37 | - const LABEL='MSSQL'; |
|
37 | + const LABEL = 'MSSQL'; |
|
38 | 38 | //! Charset used to force charset when creating database |
39 | - var $forcecharset='latin1'; // Can't be static as it may be forced with a dynamic value |
|
39 | + var $forcecharset = 'latin1'; // Can't be static as it may be forced with a dynamic value |
|
40 | 40 | //! Collate used to force collate when creating database |
41 | - var $forcecollate='latin1_swedish_ci'; // Can't be static as it may be forced with a dynamic value |
|
41 | + var $forcecollate = 'latin1_swedish_ci'; // Can't be static as it may be forced with a dynamic value |
|
42 | 42 | //! Version min database |
43 | - const VERSIONMIN='2000'; |
|
43 | + const VERSIONMIN = '2000'; |
|
44 | 44 | /** @var resource Resultset of last query */ |
45 | 45 | private $_results; |
46 | 46 | |
@@ -55,30 +55,30 @@ discard block |
||
55 | 55 | * @param string $name Nom de la database |
56 | 56 | * @param int $port Port of database server |
57 | 57 | */ |
58 | - function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
58 | + function __construct($type, $host, $user, $pass, $name = '', $port = 0) |
|
59 | 59 | { |
60 | 60 | global $langs; |
61 | 61 | |
62 | - $this->database_user=$user; |
|
63 | - $this->database_host=$host; |
|
64 | - $this->database_port=$port; |
|
65 | - $this->transaction_opened=0; |
|
62 | + $this->database_user = $user; |
|
63 | + $this->database_host = $host; |
|
64 | + $this->database_port = $port; |
|
65 | + $this->transaction_opened = 0; |
|
66 | 66 | |
67 | - if (! function_exists("mssql_connect")) |
|
67 | + if (!function_exists("mssql_connect")) |
|
68 | 68 | { |
69 | 69 | $this->connected = false; |
70 | 70 | $this->ok = false; |
71 | - $this->error="Mssql PHP functions for using MSSql driver are not available in this version of PHP"; |
|
72 | - dol_syslog(get_class($this)."::DoliDBMssql : MSsql PHP functions for using MSsql driver are not available in this version of PHP",LOG_ERR); |
|
71 | + $this->error = "Mssql PHP functions for using MSSql driver are not available in this version of PHP"; |
|
72 | + dol_syslog(get_class($this)."::DoliDBMssql : MSsql PHP functions for using MSsql driver are not available in this version of PHP", LOG_ERR); |
|
73 | 73 | return $this->ok; |
74 | 74 | } |
75 | 75 | |
76 | - if (! $host) |
|
76 | + if (!$host) |
|
77 | 77 | { |
78 | 78 | $this->connected = false; |
79 | 79 | $this->ok = false; |
80 | - $this->error=$langs->trans("ErrorWrongHostParameter"); |
|
81 | - dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect, wrong host parameters",LOG_ERR); |
|
80 | + $this->error = $langs->trans("ErrorWrongHostParameter"); |
|
81 | + dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect, wrong host parameters", LOG_ERR); |
|
82 | 82 | return $this->ok; |
83 | 83 | } |
84 | 84 | |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | // host, login ou password incorrect |
97 | 97 | $this->connected = false; |
98 | 98 | $this->ok = false; |
99 | - $this->error=mssql_get_last_message(); |
|
100 | - dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect mssql_get_last_message=".$this->error,LOG_ERR); |
|
99 | + $this->error = mssql_get_last_message(); |
|
100 | + dol_syslog(get_class($this)."::DoliDBMssql : Erreur Connect mssql_get_last_message=".$this->error, LOG_ERR); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | // Si connexion serveur ok et si connexion base demandee, on essaie connexion base |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | $this->database_selected = false; |
115 | 115 | $this->database_name = ''; |
116 | 116 | $this->ok = false; |
117 | - $this->error=$this->error(); |
|
118 | - dol_syslog(get_class($this)."::DoliDBMssql : Erreur Select_db ".$this->error,LOG_ERR); |
|
117 | + $this->error = $this->error(); |
|
118 | + dol_syslog(get_class($this)."::DoliDBMssql : Erreur Select_db ".$this->error, LOG_ERR); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | else |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
135 | 135 | * @return string SQL request line converted |
136 | 136 | */ |
137 | - static function convertSQLFromMysql($line,$type='ddl') |
|
137 | + static function convertSQLFromMysql($line, $type = 'ddl') |
|
138 | 138 | { |
139 | 139 | return $line; |
140 | 140 | } |
@@ -161,25 +161,25 @@ discard block |
||
161 | 161 | * @return false|resource|true Database access handler |
162 | 162 | * @see close |
163 | 163 | */ |
164 | - function connect($host, $login, $passwd, $name, $port=0) |
|
164 | + function connect($host, $login, $passwd, $name, $port = 0) |
|
165 | 165 | { |
166 | 166 | dol_syslog(get_class($this)."::connect host=$host, port=$port, login=$login, passwd=--hidden--, name=$name"); |
167 | - $newhost=$host; |
|
168 | - if ($port) $newhost.=':'.$port; |
|
169 | - $this->db = @mssql_connect($newhost, $login, $passwd); |
|
167 | + $newhost = $host; |
|
168 | + if ($port) $newhost .= ':'.$port; |
|
169 | + $this->db = @mssql_connect($newhost, $login, $passwd); |
|
170 | 170 | //force les enregistrement en latin1 si la base est en utf8 par defaut |
171 | 171 | // Supprime car plante sur mon PHP-Mysql. De plus, la base est forcement en latin1 avec |
172 | 172 | // les nouvelles version de Dolibarr car force par l'install Dolibarr. |
173 | 173 | //$this->query('SET NAMES '.$this->forcecharset); |
174 | 174 | //print "Resultat fonction connect: ".$this->db; |
175 | - $set_options=array('SET ANSI_PADDING ON;', |
|
175 | + $set_options = array('SET ANSI_PADDING ON;', |
|
176 | 176 | "SET ANSI_NULLS ON;", |
177 | 177 | "SET ANSI_WARNINGS ON;", |
178 | 178 | "SET ARITHABORT ON;", |
179 | 179 | "SET CONCAT_NULL_YIELDS_NULL ON;", |
180 | 180 | "SET QUOTED_IDENTIFIER ON;" |
181 | 181 | ); |
182 | - mssql_query(implode(' ',$set_options),$this->db); |
|
182 | + mssql_query(implode(' ', $set_options), $this->db); |
|
183 | 183 | |
184 | 184 | return $this->db; |
185 | 185 | } |
@@ -191,10 +191,10 @@ discard block |
||
191 | 191 | */ |
192 | 192 | function getVersion() |
193 | 193 | { |
194 | - $resql=$this->query("SELECT @@VERSION"); |
|
194 | + $resql = $this->query("SELECT @@VERSION"); |
|
195 | 195 | if ($resql) |
196 | 196 | { |
197 | - $version=$this->fetch_array($resql); |
|
197 | + $version = $this->fetch_array($resql); |
|
198 | 198 | return $version['computed']; |
199 | 199 | } |
200 | 200 | else return ''; |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | { |
221 | 221 | if ($this->db) |
222 | 222 | { |
223 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
224 | - $this->connected=false; |
|
223 | + if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR); |
|
224 | + $this->connected = false; |
|
225 | 225 | return mssql_close($this->db); |
226 | 226 | } |
227 | 227 | return false; |
@@ -236,16 +236,16 @@ discard block |
||
236 | 236 | function begin() |
237 | 237 | { |
238 | 238 | |
239 | - $res=mssql_query('select @@TRANCOUNT'); |
|
240 | - $this->transaction_opened=mssql_result($res, 0, 0); |
|
239 | + $res = mssql_query('select @@TRANCOUNT'); |
|
240 | + $this->transaction_opened = mssql_result($res, 0, 0); |
|
241 | 241 | |
242 | 242 | if ($this->transaction_opened == 0) |
243 | 243 | { |
244 | 244 | //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTIONS ON' generate also a mess |
245 | - $ret=mssql_query("SET IMPLICIT_TRANSACTIONS OFF;BEGIN TRANSACTION;",$this->db); |
|
245 | + $ret = mssql_query("SET IMPLICIT_TRANSACTIONS OFF;BEGIN TRANSACTION;", $this->db); |
|
246 | 246 | if ($ret) |
247 | 247 | { |
248 | - dol_syslog("BEGIN Transaction",LOG_DEBUG); |
|
248 | + dol_syslog("BEGIN Transaction", LOG_DEBUG); |
|
249 | 249 | } |
250 | 250 | return $ret; |
251 | 251 | } |
@@ -261,18 +261,18 @@ discard block |
||
261 | 261 | * @param string $log Add more log to default log line |
262 | 262 | * @return bool true if validation is OK or transaction level no started, false if ERROR |
263 | 263 | */ |
264 | - function commit($log='') |
|
264 | + function commit($log = '') |
|
265 | 265 | { |
266 | - $res=mssql_query('select @@TRANCOUNT'); |
|
267 | - $this->transaction_opened=mssql_result($res, 0, 0); |
|
266 | + $res = mssql_query('select @@TRANCOUNT'); |
|
267 | + $this->transaction_opened = mssql_result($res, 0, 0); |
|
268 | 268 | |
269 | 269 | if ($this->transaction_opened == 1) |
270 | 270 | { |
271 | 271 | //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTION ON' generate also a mess |
272 | - $ret=mssql_query("COMMIT TRANSACTION",$this->db); |
|
272 | + $ret = mssql_query("COMMIT TRANSACTION", $this->db); |
|
273 | 273 | if ($ret) |
274 | 274 | { |
275 | - dol_syslog("COMMIT Transaction",LOG_DEBUG); |
|
275 | + dol_syslog("COMMIT Transaction", LOG_DEBUG); |
|
276 | 276 | return true; |
277 | 277 | } |
278 | 278 | else |
@@ -294,15 +294,15 @@ discard block |
||
294 | 294 | * @param string $log Add more log to default log line |
295 | 295 | * @return bool true si annulation ok ou transaction non ouverte, false en cas d'erreur |
296 | 296 | */ |
297 | - function rollback($log='') |
|
297 | + function rollback($log = '') |
|
298 | 298 | { |
299 | - $res=mssql_query('select @@TRANCOUNT'); |
|
300 | - $this->transaction_opened=mssql_result($res, 0, 0); |
|
299 | + $res = mssql_query('select @@TRANCOUNT'); |
|
300 | + $this->transaction_opened = mssql_result($res, 0, 0); |
|
301 | 301 | |
302 | 302 | if ($this->transaction_opened == 1) |
303 | 303 | { |
304 | - $ret=mssql_query("ROLLBACK TRANSACTION",$this->db); |
|
305 | - dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); |
|
304 | + $ret = mssql_query("ROLLBACK TRANSACTION", $this->db); |
|
305 | + dol_syslog("ROLLBACK Transaction".($log ? ' '.$log : ''), LOG_DEBUG); |
|
306 | 306 | return $ret; |
307 | 307 | } |
308 | 308 | elseif ($this->transaction_opened > 1) |
@@ -322,60 +322,60 @@ discard block |
||
322 | 322 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
323 | 323 | * @return false|resource|true Resultset of answer |
324 | 324 | */ |
325 | - function query($query,$usesavepoint=0,$type='auto') |
|
325 | + function query($query, $usesavepoint = 0, $type = 'auto') |
|
326 | 326 | { |
327 | 327 | $query = trim($query); |
328 | 328 | |
329 | - if (preg_match('/^--/',$query)) return true; |
|
329 | + if (preg_match('/^--/', $query)) return true; |
|
330 | 330 | |
331 | 331 | // Conversion syntaxe MySql vers MSDE. |
332 | 332 | $query = str_ireplace("now()", "getdate()", $query); |
333 | 333 | // Erreur SQL: cannot update timestamp field |
334 | 334 | $query = str_ireplace(", tms = tms", "", $query); |
335 | 335 | |
336 | - $query=preg_replace("/([. ,\t(])(percent|file|public)([. ,=\t)])/","$1[$2]$3",$query); |
|
336 | + $query = preg_replace("/([. ,\t(])(percent|file|public)([. ,=\t)])/", "$1[$2]$3", $query); |
|
337 | 337 | |
338 | - if ($type=="auto" || $type='dml') |
|
338 | + if ($type == "auto" || $type = 'dml') |
|
339 | 339 | { |
340 | - $query=preg_replace('/AUTO_INCREMENT/i','IDENTITY',$query); |
|
341 | - $query=preg_replace('/double/i','float',$query); |
|
342 | - $query=preg_replace('/float\((.*)\)/','numeric($1)',$query); |
|
343 | - $query=preg_replace('/([ \t])unsigned|IF NOT EXISTS[ \t]/i','$1',$query); |
|
344 | - $query=preg_replace('/([ \t])(MEDIUM|TINY|LONG){0,1}TEXT([ \t,])/i',"$1VARCHAR(MAX)$3",$query); |
|
345 | - |
|
346 | - $matches=array(); |
|
347 | - $original_query=''; |
|
348 | - if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+(?:(UNIQUE)|INDEX)\h+(?:INDEX)?\h*(\w+?)\h*\((.+)\)/is', $query,$matches)) |
|
340 | + $query = preg_replace('/AUTO_INCREMENT/i', 'IDENTITY', $query); |
|
341 | + $query = preg_replace('/double/i', 'float', $query); |
|
342 | + $query = preg_replace('/float\((.*)\)/', 'numeric($1)', $query); |
|
343 | + $query = preg_replace('/([ \t])unsigned|IF NOT EXISTS[ \t]/i', '$1', $query); |
|
344 | + $query = preg_replace('/([ \t])(MEDIUM|TINY|LONG){0,1}TEXT([ \t,])/i', "$1VARCHAR(MAX)$3", $query); |
|
345 | + |
|
346 | + $matches = array(); |
|
347 | + $original_query = ''; |
|
348 | + if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+(?:(UNIQUE)|INDEX)\h+(?:INDEX)?\h*(\w+?)\h*\((.+)\)/is', $query, $matches)) |
|
349 | 349 | { |
350 | - $original_query=$query; |
|
351 | - $query="CREATE ".trim($matches[2])." INDEX [".trim($matches[3])."] ON [".trim($matches[1])."] (".trim($matches[4]).")"; |
|
350 | + $original_query = $query; |
|
351 | + $query = "CREATE ".trim($matches[2])." INDEX [".trim($matches[3])."] ON [".trim($matches[1])."] (".trim($matches[4]).")"; |
|
352 | 352 | if ($matches[2]) { |
353 | 353 | //check if columun is nullable cause Sql server only allow 1 null value if unique index. |
354 | - $fields=explode(",",trim($matches[4])); |
|
355 | - $fields_clear=array_map('trim',$fields); |
|
356 | - $infos=$this->GetFieldInformation(trim($matches[1]), $fields_clear); |
|
357 | - $query_comp=array(); |
|
358 | - foreach($infos as $fld) { |
|
354 | + $fields = explode(",", trim($matches[4])); |
|
355 | + $fields_clear = array_map('trim', $fields); |
|
356 | + $infos = $this->GetFieldInformation(trim($matches[1]), $fields_clear); |
|
357 | + $query_comp = array(); |
|
358 | + foreach ($infos as $fld) { |
|
359 | 359 | if ($fld->IS_NULLABLE == 'YES') { |
360 | - $query_comp[]=$fld->COLUMN_NAME." IS NOT NULL"; |
|
360 | + $query_comp[] = $fld->COLUMN_NAME." IS NOT NULL"; |
|
361 | 361 | } |
362 | 362 | } |
363 | - if (! empty($query_comp)) |
|
364 | - $query.=" WHERE ".implode(" AND ",$query_comp); |
|
363 | + if (!empty($query_comp)) |
|
364 | + $query .= " WHERE ".implode(" AND ", $query_comp); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | else |
368 | 368 | { |
369 | 369 | if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+PRIMARY\h+KEY\h+(\w+?)\h*\((.+)\)/is', $query, $matches)) |
370 | 370 | { |
371 | - $original_query=$query; |
|
372 | - $query="ALTER TABLE [".$matches[1]."] ADD CONSTRAINT [".$matches[2]."] PRIMARY KEY CLUSTERED (".$matches[3].")"; |
|
371 | + $original_query = $query; |
|
372 | + $query = "ALTER TABLE [".$matches[1]."] ADD CONSTRAINT [".$matches[2]."] PRIMARY KEY CLUSTERED (".$matches[3].")"; |
|
373 | 373 | } |
374 | 374 | } |
375 | 375 | |
376 | 376 | } |
377 | 377 | |
378 | - if ($type=="auto" || $type='ddl') |
|
378 | + if ($type == "auto" || $type = 'ddl') |
|
379 | 379 | { |
380 | 380 | $itemfound = stripos($query, " limit "); |
381 | 381 | if ($itemfound !== false) { |
@@ -406,22 +406,22 @@ discard block |
||
406 | 406 | // Inserer la date en parametre et le reste de la requete |
407 | 407 | $query = $newquery." DATEPART(week, ".$extractvalue.$endofquery; |
408 | 408 | } |
409 | - if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i',$query,$matches)) |
|
409 | + if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i', $query, $matches)) |
|
410 | 410 | { |
411 | 411 | //var_dump($query); |
412 | 412 | //var_dump($matches); |
413 | 413 | //if (stripos($query,'llx_c_departements') !== false) var_dump($query); |
414 | - $sql='SET IDENTITY_INSERT ['.trim($matches[1]).'] ON;'; |
|
414 | + $sql = 'SET IDENTITY_INSERT ['.trim($matches[1]).'] ON;'; |
|
415 | 415 | @mssql_query($sql, $this->db); |
416 | - $post_query='SET IDENTITY_INSERT ['.trim($matches[1]).'] OFF;'; |
|
416 | + $post_query = 'SET IDENTITY_INSERT ['.trim($matches[1]).'] OFF;'; |
|
417 | 417 | |
418 | 418 | } |
419 | 419 | } |
420 | 420 | //print "<!--".$query."-->"; |
421 | 421 | |
422 | - if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
422 | + if (!in_array($query, array('BEGIN', 'COMMIT', 'ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
423 | 423 | |
424 | - if (! $this->database_name) |
|
424 | + if (!$this->database_name) |
|
425 | 425 | { |
426 | 426 | // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
427 | 427 | $ret = mssql_query($query, $this->db); |
@@ -436,10 +436,10 @@ discard block |
||
436 | 436 | @mssql_query($post_query, $this->db); |
437 | 437 | } |
438 | 438 | |
439 | - if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
439 | + if (!preg_match("/^COMMIT/i", $query) && !preg_match("/^ROLLBACK/i", $query)) |
|
440 | 440 | { |
441 | 441 | // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
442 | - if (! $ret) |
|
442 | + if (!$ret) |
|
443 | 443 | { |
444 | 444 | $result = mssql_query("SELECT @@ERROR as code", $this->db); |
445 | 445 | $row = mssql_fetch_array($result); |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | if ($original_query) dol_syslog(get_class($this)."::query SQL Original query: ".$original_query, LOG_ERR); |
453 | 453 | dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR); |
454 | 454 | } |
455 | - $this->lastquery=$query; |
|
455 | + $this->lastquery = $query; |
|
456 | 456 | $this->_results = $ret; |
457 | 457 | } |
458 | 458 | |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | function fetch_object($resultset) |
469 | 469 | { |
470 | 470 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
471 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
471 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
472 | 472 | return mssql_fetch_object($resultset); |
473 | 473 | } |
474 | 474 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | function fetch_array($resultset) |
482 | 482 | { |
483 | 483 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
484 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
484 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
485 | 485 | return mssql_fetch_array($resultset); |
486 | 486 | } |
487 | 487 | |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | function fetch_row($resultset) |
496 | 496 | { |
497 | 497 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
498 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
498 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
499 | 499 | return @mssql_fetch_row($resultset); |
500 | 500 | } |
501 | 501 | |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | function num_rows($resultset) |
510 | 510 | { |
511 | 511 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
512 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
512 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
513 | 513 | return mssql_num_rows($resultset); |
514 | 514 | } |
515 | 515 | |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | function affected_rows($resultset) |
524 | 524 | { |
525 | 525 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
526 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
526 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
527 | 527 | // mssql necessite un link de base pour cette fonction contrairement |
528 | 528 | // a pqsql qui prend un resultset |
529 | 529 | $rsRows = mssql_query("select @@rowcount as rows", $this->db); |
@@ -538,10 +538,10 @@ discard block |
||
538 | 538 | * @param resource $resultset Curseur de la requete voulue |
539 | 539 | * @return bool |
540 | 540 | */ |
541 | - function free($resultset=null) |
|
541 | + function free($resultset = null) |
|
542 | 542 | { |
543 | 543 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
544 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
544 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
545 | 545 | // Si resultset en est un, on libere la memoire |
546 | 546 | if (is_resource($resultset)) mssql_free_result($resultset); |
547 | 547 | } |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | */ |
568 | 568 | function idate($param) |
569 | 569 | { |
570 | - return dol_print_date($param,"%Y-%m-%d %H:%M:%S"); |
|
570 | + return dol_print_date($param, "%Y-%m-%d %H:%M:%S"); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | */ |
578 | 578 | function errno() |
579 | 579 | { |
580 | - if (! $this->connected) |
|
580 | + if (!$this->connected) |
|
581 | 581 | { |
582 | 582 | // Si il y a eu echec de connexion, $this->db n'est pas valide. |
583 | 583 | return 'DB_ERROR_FAILED_TO_CONNECT'; |
@@ -618,8 +618,8 @@ discard block |
||
618 | 618 | { |
619 | 619 | return $errorcode_map[$this->lasterrno]; |
620 | 620 | } |
621 | - $errno=$this->lasterrno; |
|
622 | - return ($errno?'DB_ERROR_'.$errno:'0'); |
|
621 | + $errno = $this->lasterrno; |
|
622 | + return ($errno ? 'DB_ERROR_'.$errno : '0'); |
|
623 | 623 | } |
624 | 624 | } |
625 | 625 | |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | */ |
631 | 631 | function error() |
632 | 632 | { |
633 | - if (! $this->connected) { |
|
633 | + if (!$this->connected) { |
|
634 | 634 | // Si il y a eu echec de connexion, $this->db n'est pas valide pour mssql_get_last_message. |
635 | 635 | return 'Not connected. Check setup parameters in conf/conf.php file and your mssql client and server versions'; |
636 | 636 | } |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | * @param string $fieldid Field name |
647 | 647 | * @return int Id of row or -1 on error |
648 | 648 | */ |
649 | - function last_insert_id($tab,$fieldid='rowid') |
|
649 | + function last_insert_id($tab, $fieldid = 'rowid') |
|
650 | 650 | { |
651 | 651 | $res = $this->query("SELECT @@IDENTITY as id"); |
652 | 652 | if ($res && $data = $this->fetch_array($res)) |
@@ -667,18 +667,18 @@ discard block |
||
667 | 667 | * @param int $withQuotes Return string with quotes |
668 | 668 | * @return string XXX(field) or XXX('value') or field or 'value' |
669 | 669 | */ |
670 | - function encrypt($fieldorvalue, $withQuotes=0) |
|
670 | + function encrypt($fieldorvalue, $withQuotes = 0) |
|
671 | 671 | { |
672 | 672 | global $conf; |
673 | 673 | |
674 | 674 | // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
675 | - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
675 | + $cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0); |
|
676 | 676 | |
677 | 677 | //Encryption key |
678 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
678 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : ''); |
|
679 | 679 | |
680 | 680 | $return = $fieldorvalue; |
681 | - return ($withQuotes?"'":"").$this->escape($return).($withQuotes?"'":""); |
|
681 | + return ($withQuotes ? "'" : "").$this->escape($return).($withQuotes ? "'" : ""); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
@@ -692,10 +692,10 @@ discard block |
||
692 | 692 | global $conf; |
693 | 693 | |
694 | 694 | // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
695 | - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
695 | + $cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0); |
|
696 | 696 | |
697 | 697 | //Encryption key |
698 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
698 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : ''); |
|
699 | 699 | |
700 | 700 | $return = $value; |
701 | 701 | return $return; |
@@ -709,10 +709,10 @@ discard block |
||
709 | 709 | */ |
710 | 710 | function DDLGetConnectId() |
711 | 711 | { |
712 | - $resql=$this->query('SELECT CONNECTION_ID()'); |
|
712 | + $resql = $this->query('SELECT CONNECTION_ID()'); |
|
713 | 713 | if ($resql) |
714 | 714 | { |
715 | - $row=$this->fetch_row($resql); |
|
715 | + $row = $this->fetch_row($resql); |
|
716 | 716 | return $row[0]; |
717 | 717 | } |
718 | 718 | else return '?'; |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | * @param string $owner Username of database owner |
730 | 730 | * @return false|resource|true resource defined if OK, false if KO |
731 | 731 | */ |
732 | - function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
732 | + function DDLCreateDb($database, $charset = '', $collation = '', $owner = '') |
|
733 | 733 | { |
734 | 734 | /*if (empty($charset)) $charset=$this->forcecharset; |
735 | 735 | if (empty($collation)) $collation=$this->forcecollate; |
@@ -738,18 +738,18 @@ discard block |
||
738 | 738 | $sql = 'CREATE DATABASE '.$this->EscapeFieldName($database); |
739 | 739 | //TODO: Check if we need to force a charset |
740 | 740 | //$sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation; |
741 | - $ret=$this->query($sql); |
|
741 | + $ret = $this->query($sql); |
|
742 | 742 | |
743 | 743 | $this->select_db($database); |
744 | - $sql="CREATE USER [$owner] FOR LOGIN [$owner]"; |
|
745 | - mssql_query($sql,$this->db); |
|
746 | - $sql="ALTER ROLE [db_owner] ADD MEMBER [$owner]"; |
|
747 | - mssql_query($sql,$this->db); |
|
744 | + $sql = "CREATE USER [$owner] FOR LOGIN [$owner]"; |
|
745 | + mssql_query($sql, $this->db); |
|
746 | + $sql = "ALTER ROLE [db_owner] ADD MEMBER [$owner]"; |
|
747 | + mssql_query($sql, $this->db); |
|
748 | 748 | |
749 | - $sql="ALTER DATABASE [$database] SET ANSI_NULL_DEFAULT ON;"; |
|
750 | - @mssql_query($sql,$this->db); |
|
751 | - $sql="ALTER DATABASE [$database] SET ANSI_NULL ON;"; |
|
752 | - @mssql_query($sql,$this->db); |
|
749 | + $sql = "ALTER DATABASE [$database] SET ANSI_NULL_DEFAULT ON;"; |
|
750 | + @mssql_query($sql, $this->db); |
|
751 | + $sql = "ALTER DATABASE [$database] SET ANSI_NULL ON;"; |
|
752 | + @mssql_query($sql, $this->db); |
|
753 | 753 | |
754 | 754 | return $ret; |
755 | 755 | } |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | * @param string $table Nmae of table filter ('xxx%') |
762 | 762 | * @return array List of tables in an array |
763 | 763 | */ |
764 | - function DDLListTables($database,$table='') |
|
764 | + function DDLListTables($database, $table = '') |
|
765 | 765 | { |
766 | 766 | $this->_results = mssql_list_tables($database, $this->db); |
767 | 767 | return $this->_results; |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | // TODO: Implement |
781 | 781 | // May help: https://stackoverflow.com/questions/600446/sql-server-how-do-you-return-the-column-names-from-a-table |
782 | 782 | |
783 | - $infotables=array(); |
|
783 | + $infotables = array(); |
|
784 | 784 | return $infotables; |
785 | 785 | } |
786 | 786 | |
@@ -796,68 +796,68 @@ discard block |
||
796 | 796 | * @param array $keys Tableau des champs cles noms => valeur |
797 | 797 | * @return int <0 if KO, >=0 if OK |
798 | 798 | */ |
799 | - function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
799 | + function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null) |
|
800 | 800 | { |
801 | 801 | // FIXME: $fulltext_keys parameter is unused |
802 | 802 | |
803 | 803 | // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
804 | 804 | // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
805 | 805 | $sql = "create table ".$table."("; |
806 | - $i=0; |
|
807 | - foreach($fields as $field_name => $field_desc) |
|
806 | + $i = 0; |
|
807 | + foreach ($fields as $field_name => $field_desc) |
|
808 | 808 | { |
809 | 809 | $sqlfields[$i] = $field_name." "; |
810 | 810 | $sqlfields[$i] .= $field_desc['type']; |
811 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
811 | + if (preg_match("/^[^\s]/i", $field_desc['value'])) |
|
812 | 812 | $sqlfields[$i] .= "(".$field_desc['value'].")"; |
813 | - else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
813 | + else if (preg_match("/^[^\s]/i", $field_desc['attribute'])) |
|
814 | 814 | $sqlfields[$i] .= " ".$field_desc['attribute']; |
815 | - else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
815 | + else if (preg_match("/^[^\s]/i", $field_desc['default'])) |
|
816 | 816 | { |
817 | - if(preg_match("/null/i",$field_desc['default'])) |
|
817 | + if (preg_match("/null/i", $field_desc['default'])) |
|
818 | 818 | $sqlfields[$i] .= " default ".$field_desc['default']; |
819 | 819 | else |
820 | 820 | $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
821 | 821 | } |
822 | - else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
822 | + else if (preg_match("/^[^\s]/i", $field_desc['null'])) |
|
823 | 823 | $sqlfields[$i] .= " ".$field_desc['null']; |
824 | 824 | |
825 | - else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
825 | + else if (preg_match("/^[^\s]/i", $field_desc['extra'])) |
|
826 | 826 | $sqlfields[$i] .= " ".$field_desc['extra']; |
827 | 827 | $i++; |
828 | 828 | } |
829 | - if($primary_key != "") |
|
829 | + if ($primary_key != "") |
|
830 | 830 | $pk = "primary key(".$primary_key.")"; |
831 | 831 | |
832 | - if(is_array($unique_keys)) |
|
832 | + if (is_array($unique_keys)) |
|
833 | 833 | { |
834 | 834 | $i = 0; |
835 | - foreach($unique_keys as $key => $value) |
|
835 | + foreach ($unique_keys as $key => $value) |
|
836 | 836 | { |
837 | 837 | $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
838 | 838 | $i++; |
839 | 839 | } |
840 | 840 | } |
841 | - if(is_array($keys)) |
|
841 | + if (is_array($keys)) |
|
842 | 842 | { |
843 | 843 | $i = 0; |
844 | - foreach($keys as $key => $value) |
|
844 | + foreach ($keys as $key => $value) |
|
845 | 845 | { |
846 | 846 | $sqlk[$i] = "KEY ".$key." (".$value.")"; |
847 | 847 | $i++; |
848 | 848 | } |
849 | 849 | } |
850 | - $sql .= implode(',',$sqlfields); |
|
851 | - if($primary_key != "") |
|
850 | + $sql .= implode(',', $sqlfields); |
|
851 | + if ($primary_key != "") |
|
852 | 852 | $sql .= ",".$pk; |
853 | - if(is_array($unique_keys)) |
|
854 | - $sql .= ",".implode(',',$sqluq); |
|
855 | - if(is_array($keys)) |
|
856 | - $sql .= ",".implode(',',$sqlk); |
|
857 | - $sql .=") type=".$type; |
|
853 | + if (is_array($unique_keys)) |
|
854 | + $sql .= ",".implode(',', $sqluq); |
|
855 | + if (is_array($keys)) |
|
856 | + $sql .= ",".implode(',', $sqlk); |
|
857 | + $sql .= ") type=".$type; |
|
858 | 858 | |
859 | 859 | dol_syslog($sql); |
860 | - if(! $this -> query($sql)) |
|
860 | + if (!$this -> query($sql)) |
|
861 | 861 | return -1; |
862 | 862 | else |
863 | 863 | return 1; |
@@ -870,9 +870,9 @@ discard block |
||
870 | 870 | * @param string $field Optionnel : Name of field if we want description of field |
871 | 871 | * @return false|resource|true Resource |
872 | 872 | */ |
873 | - function DDLDescTable($table,$field="") |
|
873 | + function DDLDescTable($table, $field = "") |
|
874 | 874 | { |
875 | - $sql="DESC ".$table." ".$field; |
|
875 | + $sql = "DESC ".$table." ".$field; |
|
876 | 876 | |
877 | 877 | dol_syslog($sql); |
878 | 878 | $this->_results = $this->query($sql); |
@@ -888,28 +888,28 @@ discard block |
||
888 | 888 | * @param string $field_position Optionnel ex.: "after champtruc" |
889 | 889 | * @return int <0 if KO, >0 if OK |
890 | 890 | */ |
891 | - function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
891 | + function DDLAddField($table, $field_name, $field_desc, $field_position = "") |
|
892 | 892 | { |
893 | 893 | // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
894 | 894 | // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
895 | - $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
895 | + $sql = "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
896 | 896 | $sql .= $field_desc['type']; |
897 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
897 | + if (preg_match("/^[^\s]/i", $field_desc['value'])) |
|
898 | 898 | $sql .= "(".$field_desc['value'].")"; |
899 | - if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
899 | + if (preg_match("/^[^\s]/i", $field_desc['attribute'])) |
|
900 | 900 | $sql .= " ".$field_desc['attribute']; |
901 | - if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
901 | + if (preg_match("/^[^\s]/i", $field_desc['null'])) |
|
902 | 902 | $sql .= " ".$field_desc['null']; |
903 | - if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
904 | - if(preg_match("/null/i",$field_desc['default'])) |
|
903 | + if (preg_match("/^[^\s]/i", $field_desc['default'])) |
|
904 | + if (preg_match("/null/i", $field_desc['default'])) |
|
905 | 905 | $sql .= " default ".$field_desc['default']; |
906 | 906 | else |
907 | 907 | $sql .= " default '".$field_desc['default']."'"; |
908 | - if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
908 | + if (preg_match("/^[^\s]/i", $field_desc['extra'])) |
|
909 | 909 | $sql .= " ".$field_desc['extra']; |
910 | 910 | $sql .= " ".$field_position; |
911 | 911 | |
912 | - if(! $this -> query($sql)) |
|
912 | + if (!$this -> query($sql)) |
|
913 | 913 | return -1; |
914 | 914 | else |
915 | 915 | return 1; |
@@ -923,16 +923,16 @@ discard block |
||
923 | 923 | * @param string $field_desc Array with description of field format |
924 | 924 | * @return int <0 if KO, >0 if OK |
925 | 925 | */ |
926 | - function DDLUpdateField($table,$field_name,$field_desc) |
|
926 | + function DDLUpdateField($table, $field_name, $field_desc) |
|
927 | 927 | { |
928 | 928 | $sql = "ALTER TABLE ".$table; |
929 | 929 | $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
930 | 930 | if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
931 | - $sql.="(".$field_desc['value'].")"; |
|
931 | + $sql .= "(".$field_desc['value'].")"; |
|
932 | 932 | } |
933 | 933 | |
934 | - dol_syslog($sql,LOG_DEBUG); |
|
935 | - if (! $this->query($sql)) |
|
934 | + dol_syslog($sql, LOG_DEBUG); |
|
935 | + if (!$this->query($sql)) |
|
936 | 936 | return -1; |
937 | 937 | else |
938 | 938 | return 1; |
@@ -945,13 +945,13 @@ discard block |
||
945 | 945 | * @param string $field_name Name of field to drop |
946 | 946 | * @return int <0 if KO, >0 if OK |
947 | 947 | */ |
948 | - function DDLDropField($table,$field_name) |
|
948 | + function DDLDropField($table, $field_name) |
|
949 | 949 | { |
950 | - $sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
951 | - dol_syslog($sql,LOG_DEBUG); |
|
952 | - if (! $this->query($sql)) |
|
950 | + $sql = "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
951 | + dol_syslog($sql, LOG_DEBUG); |
|
952 | + if (!$this->query($sql)) |
|
953 | 953 | { |
954 | - $this->error=$this->lasterror(); |
|
954 | + $this->error = $this->lasterror(); |
|
955 | 955 | return -1; |
956 | 956 | } |
957 | 957 | else return 1; |
@@ -966,12 +966,12 @@ discard block |
||
966 | 966 | * @param string $dolibarr_main_db_name Database name where user must be granted |
967 | 967 | * @return int <0 if KO, >=0 if OK |
968 | 968 | */ |
969 | - function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
969 | + function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name) |
|
970 | 970 | { |
971 | 971 | $sql = "CREATE LOGIN ".$this->EscapeFieldName($dolibarr_main_db_user)." WITH PASSWORD='$dolibarr_main_db_pass'"; |
972 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
973 | - $resql=$this->query($sql); |
|
974 | - if (! $resql) |
|
972 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
973 | + $resql = $this->query($sql); |
|
974 | + if (!$resql) |
|
975 | 975 | { |
976 | 976 | if ($this->lasterrno != '15025') |
977 | 977 | { |
@@ -983,9 +983,9 @@ discard block |
||
983 | 983 | dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
984 | 984 | } |
985 | 985 | } |
986 | - $sql="SELECT name from sys.databases where name='".$dolibarr_main_db_name."'"; |
|
987 | - $ressql=$this->query($sql); |
|
988 | - if (! $ressql) |
|
986 | + $sql = "SELECT name from sys.databases where name='".$dolibarr_main_db_name."'"; |
|
987 | + $ressql = $this->query($sql); |
|
988 | + if (!$ressql) |
|
989 | 989 | { |
990 | 990 | dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
991 | 991 | return -1; |
@@ -995,9 +995,9 @@ discard block |
||
995 | 995 | if ($num) |
996 | 996 | { |
997 | 997 | $this->select_db($dolibarr_main_db_name); |
998 | - $sql="CREATE USER [$dolibarr_main_db_user] FOR LOGIN [$dolibarr_main_db_user]"; |
|
998 | + $sql = "CREATE USER [$dolibarr_main_db_user] FOR LOGIN [$dolibarr_main_db_user]"; |
|
999 | 999 | $this->query($sql); |
1000 | - $sql="ALTER ROLE [db_owner] ADD MEMBER [$dolibarr_main_db_user]"; |
|
1000 | + $sql = "ALTER ROLE [db_owner] ADD MEMBER [$dolibarr_main_db_user]"; |
|
1001 | 1001 | $this->query($sql); |
1002 | 1002 | } |
1003 | 1003 | } |
@@ -1037,12 +1037,12 @@ discard block |
||
1037 | 1037 | */ |
1038 | 1038 | function getDefaultCollationDatabase() |
1039 | 1039 | { |
1040 | - $resql=$this->query("SELECT SERVERPROPERTY('collation')"); |
|
1040 | + $resql = $this->query("SELECT SERVERPROPERTY('collation')"); |
|
1041 | 1041 | if (!$resql) |
1042 | 1042 | { |
1043 | 1043 | return $this->forcecollate; |
1044 | 1044 | } |
1045 | - $liste=$this->fetch_array($resql); |
|
1045 | + $liste = $this->fetch_array($resql); |
|
1046 | 1046 | return $liste['computed']; |
1047 | 1047 | } |
1048 | 1048 | |
@@ -1091,13 +1091,13 @@ discard block |
||
1091 | 1091 | * @param string $filter Filter list on a particular value |
1092 | 1092 | * @return array Array of key-values (key=>value) |
1093 | 1093 | */ |
1094 | - function getServerParametersValues($filter='') |
|
1094 | + function getServerParametersValues($filter = '') |
|
1095 | 1095 | { |
1096 | 1096 | // FIXME: Dummy method |
1097 | 1097 | // TODO: Implement |
1098 | 1098 | // May help: SELECT SERVERPROPERTY |
1099 | 1099 | |
1100 | - $result=array(); |
|
1100 | + $result = array(); |
|
1101 | 1101 | return $result; |
1102 | 1102 | } |
1103 | 1103 | |
@@ -1107,7 +1107,7 @@ discard block |
||
1107 | 1107 | * @param string $filter Filter list on a particular value |
1108 | 1108 | * @return array Array of key-values (key=>value) |
1109 | 1109 | */ |
1110 | - function getServerStatusValues($filter='') |
|
1110 | + function getServerStatusValues($filter = '') |
|
1111 | 1111 | { |
1112 | 1112 | // FIXME: Dummy method |
1113 | 1113 | // TODO: Implement |
@@ -1134,23 +1134,23 @@ discard block |
||
1134 | 1134 | * @param mixed $fields String for one field or array of string for multiple field |
1135 | 1135 | * @return false|object |
1136 | 1136 | */ |
1137 | - function GetFieldInformation($table,$fields) { |
|
1138 | - $sql="SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$this->escape($table)."' AND COLUMN_NAME"; |
|
1137 | + function GetFieldInformation($table, $fields) { |
|
1138 | + $sql = "SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$this->escape($table)."' AND COLUMN_NAME"; |
|
1139 | 1139 | if (is_array($fields)) |
1140 | 1140 | { |
1141 | - $where=" IN ('".implode("','",$fields)."')"; |
|
1141 | + $where = " IN ('".implode("','", $fields)."')"; |
|
1142 | 1142 | } |
1143 | 1143 | else |
1144 | 1144 | { |
1145 | - $where="='".$this->escape($fields)."'"; |
|
1145 | + $where = "='".$this->escape($fields)."'"; |
|
1146 | 1146 | } |
1147 | - $result=array(); |
|
1148 | - $ret=mssql_query($sql.$where,$this->db); |
|
1147 | + $result = array(); |
|
1148 | + $ret = mssql_query($sql.$where, $this->db); |
|
1149 | 1149 | if ($ret) |
1150 | 1150 | { |
1151 | - while($obj=mssql_fetch_object($ret)) |
|
1151 | + while ($obj = mssql_fetch_object($ret)) |
|
1152 | 1152 | { |
1153 | - $result[]=$obj; |
|
1153 | + $result[] = $obj; |
|
1154 | 1154 | } |
1155 | 1155 | } |
1156 | 1156 | else |
@@ -233,7 +233,7 @@ |
||
233 | 233 | * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollbock to savepoint if error (this allow to have some request with errors inside global transactions). |
234 | 234 | * Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints. |
235 | 235 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
236 | - * @return bool|mysqli_result Resultset of answer |
|
236 | + * @return mysqli_result|null Resultset of answer |
|
237 | 237 | */ |
238 | 238 | function query($query,$usesavepoint=0,$type='auto') |
239 | 239 | { |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * \brief Class file to manage Dolibarr database access for a MySQL database |
26 | 26 | */ |
27 | 27 | |
28 | -require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php'; |
|
28 | +require_once DOL_DOCUMENT_ROOT.'/core/db/DoliDB.class.php'; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Class to manage Dolibarr database access for a MySQL database using the MySQLi extension |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | /** @var mysqli Database object */ |
36 | 36 | public $db; |
37 | 37 | //! Database type |
38 | - public $type='mysqli'; |
|
38 | + public $type = 'mysqli'; |
|
39 | 39 | //! Database label |
40 | - const LABEL='MySQL or MariaDB'; |
|
40 | + const LABEL = 'MySQL or MariaDB'; |
|
41 | 41 | //! Version min database |
42 | - const VERSIONMIN='5.0.3'; |
|
42 | + const VERSIONMIN = '5.0.3'; |
|
43 | 43 | /** @var mysqli_result Resultset of last query */ |
44 | 44 | private $_results; |
45 | 45 | |
@@ -54,36 +54,36 @@ discard block |
||
54 | 54 | * @param string $name Nom de la database |
55 | 55 | * @param int $port Port of database server |
56 | 56 | */ |
57 | - function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
57 | + function __construct($type, $host, $user, $pass, $name = '', $port = 0) |
|
58 | 58 | { |
59 | - global $conf,$langs; |
|
59 | + global $conf, $langs; |
|
60 | 60 | |
61 | 61 | // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
62 | - if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set; |
|
63 | - if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
|
62 | + if (!empty($conf->db->character_set)) $this->forcecharset = $conf->db->character_set; |
|
63 | + if (!empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate = $conf->db->dolibarr_main_db_collation; |
|
64 | 64 | |
65 | - $this->database_user=$user; |
|
66 | - $this->database_host=$host; |
|
67 | - $this->database_port=$port; |
|
65 | + $this->database_user = $user; |
|
66 | + $this->database_host = $host; |
|
67 | + $this->database_port = $port; |
|
68 | 68 | |
69 | - $this->transaction_opened=0; |
|
69 | + $this->transaction_opened = 0; |
|
70 | 70 | |
71 | 71 | //print "Name DB: $host,$user,$pass,$name<br>"; |
72 | 72 | |
73 | - if (! class_exists('mysqli')) |
|
73 | + if (!class_exists('mysqli')) |
|
74 | 74 | { |
75 | 75 | $this->connected = false; |
76 | 76 | $this->ok = false; |
77 | - $this->error="Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver."; |
|
78 | - dol_syslog(get_class($this)."::DoliDBMysqli : Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.",LOG_ERR); |
|
77 | + $this->error = "Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver."; |
|
78 | + dol_syslog(get_class($this)."::DoliDBMysqli : Mysqli PHP functions for using Mysqli driver are not available in this version of PHP. Try to use another driver.", LOG_ERR); |
|
79 | 79 | } |
80 | 80 | |
81 | - if (! $host) |
|
81 | + if (!$host) |
|
82 | 82 | { |
83 | 83 | $this->connected = false; |
84 | 84 | $this->ok = false; |
85 | - $this->error=$langs->trans("ErrorWrongHostParameter"); |
|
86 | - dol_syslog(get_class($this)."::DoliDBMysqli : Connect error, wrong host parameters",LOG_ERR); |
|
85 | + $this->error = $langs->trans("ErrorWrongHostParameter"); |
|
86 | + dol_syslog(get_class($this)."::DoliDBMysqli : Connect error, wrong host parameters", LOG_ERR); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | // Try server connection |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $this->connected = false; |
95 | 95 | $this->ok = false; |
96 | 96 | $this->error = $this->db->connect_error; |
97 | - dol_syslog(get_class($this) . "::DoliDBMysqli Connect error: " . $this->error, LOG_ERR); |
|
97 | + dol_syslog(get_class($this)."::DoliDBMysqli Connect error: ".$this->error, LOG_ERR); |
|
98 | 98 | } else { |
99 | 99 | $this->connected = true; |
100 | 100 | $this->ok = true; |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | $this->ok = true; |
111 | 111 | |
112 | 112 | // If client connected with different charset than Dolibarr HTML output |
113 | - $clientmustbe=''; |
|
114 | - if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8'; |
|
115 | - if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1'; |
|
113 | + $clientmustbe = ''; |
|
114 | + if (preg_match('/UTF-8/i', $conf->file->character_set_client)) $clientmustbe = 'utf8'; |
|
115 | + if (preg_match('/ISO-8859-1/i', $conf->file->character_set_client)) $clientmustbe = 'latin1'; |
|
116 | 116 | if ($this->db->character_set_name() != $clientmustbe) { |
117 | 117 | $this->db->set_charset($clientmustbe); |
118 | 118 | } |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | $this->database_selected = false; |
123 | 123 | $this->database_name = ''; |
124 | 124 | $this->ok = false; |
125 | - $this->error=$this->error(); |
|
126 | - dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error,LOG_ERR); |
|
125 | + $this->error = $this->error(); |
|
126 | + dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error, LOG_ERR); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | else |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | if ($this->connected) |
135 | 135 | { |
136 | 136 | // If client connected with different charset than Dolibarr HTML output |
137 | - $clientmustbe=''; |
|
138 | - if (preg_match('/UTF-8/i',$conf->file->character_set_client)) $clientmustbe='utf8'; |
|
139 | - if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) $clientmustbe='latin1'; |
|
137 | + $clientmustbe = ''; |
|
138 | + if (preg_match('/UTF-8/i', $conf->file->character_set_client)) $clientmustbe = 'utf8'; |
|
139 | + if (preg_match('/ISO-8859-1/i', $conf->file->character_set_client)) $clientmustbe = 'latin1'; |
|
140 | 140 | if ($this->db->character_set_name() != $clientmustbe) { |
141 | 141 | $this->db->set_charset($clientmustbe); |
142 | 142 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
153 | 153 | * @return string SQL request line converted |
154 | 154 | */ |
155 | - static function convertSQLFromMysql($line,$type='ddl') |
|
155 | + static function convertSQLFromMysql($line, $type = 'ddl') |
|
156 | 156 | { |
157 | 157 | return $line; |
158 | 158 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | function connect($host, $login, $passwd, $name, $port = 0) |
185 | 185 | { |
186 | - dol_syslog(get_class($this) . "::connect host=$host, port=$port, login=$login, passwd=--hidden--, name=$name", LOG_DEBUG); |
|
186 | + dol_syslog(get_class($this)."::connect host=$host, port=$port, login=$login, passwd=--hidden--, name=$name", LOG_DEBUG); |
|
187 | 187 | |
188 | 188 | // Can also be |
189 | 189 | // mysqli::init(); mysql::options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0'); mysqli::options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | { |
223 | 223 | if ($this->db) |
224 | 224 | { |
225 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
226 | - $this->connected=false; |
|
225 | + if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR); |
|
226 | + $this->connected = false; |
|
227 | 227 | return $this->db->close(); |
228 | 228 | } |
229 | 229 | return false; |
@@ -238,15 +238,15 @@ discard block |
||
238 | 238 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
239 | 239 | * @return bool|mysqli_result Resultset of answer |
240 | 240 | */ |
241 | - function query($query,$usesavepoint=0,$type='auto') |
|
241 | + function query($query, $usesavepoint = 0, $type = 'auto') |
|
242 | 242 | { |
243 | 243 | global $conf; |
244 | 244 | |
245 | 245 | $query = trim($query); |
246 | 246 | |
247 | - if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
247 | + if (!in_array($query, array('BEGIN', 'COMMIT', 'ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
248 | 248 | |
249 | - if (! $this->database_name) |
|
249 | + if (!$this->database_name) |
|
250 | 250 | { |
251 | 251 | // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
252 | 252 | $ret = $this->db->query($query); |
@@ -256,19 +256,19 @@ discard block |
||
256 | 256 | $ret = $this->db->query($query); |
257 | 257 | } |
258 | 258 | |
259 | - if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
259 | + if (!preg_match("/^COMMIT/i", $query) && !preg_match("/^ROLLBACK/i", $query)) |
|
260 | 260 | { |
261 | 261 | // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
262 | - if (! $ret) |
|
262 | + if (!$ret) |
|
263 | 263 | { |
264 | 264 | $this->lastqueryerror = $query; |
265 | 265 | $this->lasterror = $this->error(); |
266 | 266 | $this->lasterrno = $this->errno(); |
267 | 267 | |
268 | - if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); // Log of request was not yet done previously |
|
268 | + if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); // Log of request was not yet done previously |
|
269 | 269 | dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterrno." ".$this->lasterror, LOG_ERR); |
270 | 270 | } |
271 | - $this->lastquery=$query; |
|
271 | + $this->lastquery = $query; |
|
272 | 272 | $this->_results = $ret; |
273 | 273 | } |
274 | 274 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | function fetch_object($resultset) |
285 | 285 | { |
286 | 286 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
287 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
287 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
288 | 288 | return $resultset->fetch_object(); |
289 | 289 | } |
290 | 290 | |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | function fetch_array($resultset) |
299 | 299 | { |
300 | 300 | // If resultset not provided, we take the last used by connexion |
301 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
301 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
302 | 302 | return $resultset->fetch_array(); |
303 | 303 | } |
304 | 304 | |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | function fetch_row($resultset) |
312 | 312 | { |
313 | 313 | // If resultset not provided, we take the last used by connexion |
314 | - if (! is_bool($resultset)) |
|
314 | + if (!is_bool($resultset)) |
|
315 | 315 | { |
316 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
316 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
317 | 317 | return $resultset->fetch_row(); |
318 | 318 | } |
319 | 319 | else |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | function num_rows($resultset) |
334 | 334 | { |
335 | 335 | // If resultset not provided, we take the last used by connexion |
336 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
336 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
337 | 337 | return $resultset->num_rows; |
338 | 338 | } |
339 | 339 | |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | function affected_rows($resultset) |
348 | 348 | { |
349 | 349 | // If resultset not provided, we take the last used by connexion |
350 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
350 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
351 | 351 | // mysql necessite un link de base pour cette fonction contrairement |
352 | 352 | // a pqsql qui prend un resultset |
353 | 353 | return $this->db->affected_rows; |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | * @param mysqli_result $resultset Curseur de la requete voulue |
361 | 361 | * @return void |
362 | 362 | */ |
363 | - function free($resultset=null) |
|
363 | + function free($resultset = null) |
|
364 | 364 | { |
365 | 365 | // If resultset not provided, we take the last used by connexion |
366 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
366 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
367 | 367 | // Si resultset en est un, on libere la memoire |
368 | 368 | if (is_object($resultset)) $resultset->free_result(); |
369 | 369 | } |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | */ |
387 | 387 | function errno() |
388 | 388 | { |
389 | - if (! $this->connected) { |
|
389 | + if (!$this->connected) { |
|
390 | 390 | // Si il y a eu echec de connexion, $this->db n'est pas valide. |
391 | 391 | return 'DB_ERROR_FAILED_TO_CONNECT'; |
392 | 392 | } else { |
@@ -418,15 +418,15 @@ discard block |
||
418 | 418 | 1215 => 'DB_ERROR_CANNOT_ADD_FOREIGN_KEY_CONSTRAINT', |
419 | 419 | 1216 => 'DB_ERROR_NO_PARENT', |
420 | 420 | 1217 => 'DB_ERROR_CHILD_EXISTS', |
421 | - 1396 => 'DB_ERROR_USER_ALREADY_EXISTS', // When creating user already existing |
|
421 | + 1396 => 'DB_ERROR_USER_ALREADY_EXISTS', // When creating user already existing |
|
422 | 422 | 1451 => 'DB_ERROR_CHILD_EXISTS' |
423 | 423 | ); |
424 | 424 | |
425 | 425 | if (isset($errorcode_map[$this->db->errno])) { |
426 | 426 | return $errorcode_map[$this->db->errno]; |
427 | 427 | } |
428 | - $errno=$this->db->errno; |
|
429 | - return ($errno?'DB_ERROR_'.$errno:'0'); |
|
428 | + $errno = $this->db->errno; |
|
429 | + return ($errno ? 'DB_ERROR_'.$errno : '0'); |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | */ |
438 | 438 | function error() |
439 | 439 | { |
440 | - if (! $this->connected) { |
|
440 | + if (!$this->connected) { |
|
441 | 441 | // Si il y a eu echec de connexion, $this->db n'est pas valide pour mysqli_error. |
442 | 442 | return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions'; |
443 | 443 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | * @param string $fieldid Field name |
454 | 454 | * @return int|string Id of row |
455 | 455 | */ |
456 | - function last_insert_id($tab,$fieldid='rowid') |
|
456 | + function last_insert_id($tab, $fieldid = 'rowid') |
|
457 | 457 | { |
458 | 458 | return $this->db->insert_id; |
459 | 459 | } |
@@ -467,17 +467,17 @@ discard block |
||
467 | 467 | * @return string XXX(field) or XXX('value') or field or 'value' |
468 | 468 | * |
469 | 469 | */ |
470 | - function encrypt($fieldorvalue, $withQuotes=0) |
|
470 | + function encrypt($fieldorvalue, $withQuotes = 0) |
|
471 | 471 | { |
472 | 472 | global $conf; |
473 | 473 | |
474 | 474 | // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
475 | - $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
475 | + $cryptType = (!empty($conf->db->dolibarr_main_db_encryption) ? $conf->db->dolibarr_main_db_encryption : 0); |
|
476 | 476 | |
477 | 477 | //Encryption key |
478 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
478 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : ''); |
|
479 | 479 | |
480 | - $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
480 | + $return = ($withQuotes ? "'" : "").$this->escape($fieldorvalue).($withQuotes ? "'" : ""); |
|
481 | 481 | |
482 | 482 | if ($cryptType && !empty($cryptKey)) |
483 | 483 | { |
@@ -505,10 +505,10 @@ discard block |
||
505 | 505 | global $conf; |
506 | 506 | |
507 | 507 | // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
508 | - $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
508 | + $cryptType = (!empty($conf->db->dolibarr_main_db_encryption) ? $conf->db->dolibarr_main_db_encryption : 0); |
|
509 | 509 | |
510 | 510 | //Encryption key |
511 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
511 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : ''); |
|
512 | 512 | |
513 | 513 | $return = $value; |
514 | 514 | |
@@ -535,10 +535,10 @@ discard block |
||
535 | 535 | */ |
536 | 536 | function DDLGetConnectId() |
537 | 537 | { |
538 | - $resql=$this->query('SELECT CONNECTION_ID()'); |
|
538 | + $resql = $this->query('SELECT CONNECTION_ID()'); |
|
539 | 539 | if ($resql) |
540 | 540 | { |
541 | - $row=$this->fetch_row($resql); |
|
541 | + $row = $this->fetch_row($resql); |
|
542 | 542 | return $row[0]; |
543 | 543 | } |
544 | 544 | else return '?'; |
@@ -555,23 +555,23 @@ discard block |
||
555 | 555 | * @param string $owner Username of database owner |
556 | 556 | * @return bool|mysqli_result resource defined if OK, null if KO |
557 | 557 | */ |
558 | - function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
558 | + function DDLCreateDb($database, $charset = '', $collation = '', $owner = '') |
|
559 | 559 | { |
560 | - if (empty($charset)) $charset=$this->forcecharset; |
|
561 | - if (empty($collation)) $collation=$this->forcecollate; |
|
560 | + if (empty($charset)) $charset = $this->forcecharset; |
|
561 | + if (empty($collation)) $collation = $this->forcecollate; |
|
562 | 562 | |
563 | 563 | // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
564 | 564 | $sql = "CREATE DATABASE `".$this->escape($database)."`"; |
565 | - $sql.= " DEFAULT CHARACTER SET `".$this->escape($charset)."` DEFAULT COLLATE `".$this->escape($collation)."`"; |
|
565 | + $sql .= " DEFAULT CHARACTER SET `".$this->escape($charset)."` DEFAULT COLLATE `".$this->escape($collation)."`"; |
|
566 | 566 | |
567 | - dol_syslog($sql,LOG_DEBUG); |
|
568 | - $ret=$this->query($sql); |
|
569 | - if (! $ret) |
|
567 | + dol_syslog($sql, LOG_DEBUG); |
|
568 | + $ret = $this->query($sql); |
|
569 | + if (!$ret) |
|
570 | 570 | { |
571 | 571 | // We try again for compatibility with Mysql < 4.1.1 |
572 | 572 | $sql = "CREATE DATABASE `".$this->escape($database)."`"; |
573 | - dol_syslog($sql,LOG_DEBUG); |
|
574 | - $ret=$this->query($sql); |
|
573 | + dol_syslog($sql, LOG_DEBUG); |
|
574 | + $ret = $this->query($sql); |
|
575 | 575 | } |
576 | 576 | return $ret; |
577 | 577 | } |
@@ -583,18 +583,18 @@ discard block |
||
583 | 583 | * @param string $table Nmae of table filter ('xxx%') |
584 | 584 | * @return array List of tables in an array |
585 | 585 | */ |
586 | - function DDLListTables($database, $table='') |
|
586 | + function DDLListTables($database, $table = '') |
|
587 | 587 | { |
588 | - $listtables=array(); |
|
588 | + $listtables = array(); |
|
589 | 589 | |
590 | 590 | $like = ''; |
591 | 591 | if ($table) $like = "LIKE '".$table."'"; |
592 | - $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
592 | + $sql = "SHOW TABLES FROM ".$database." ".$like.";"; |
|
593 | 593 | //print $sql; |
594 | 594 | $result = $this->query($sql); |
595 | 595 | if ($result) |
596 | 596 | { |
597 | - while($row = $this->fetch_row($result)) |
|
597 | + while ($row = $this->fetch_row($result)) |
|
598 | 598 | { |
599 | 599 | $listtables[] = $row[0]; |
600 | 600 | } |
@@ -610,15 +610,15 @@ discard block |
||
610 | 610 | */ |
611 | 611 | function DDLInfoTable($table) |
612 | 612 | { |
613 | - $infotables=array(); |
|
613 | + $infotables = array(); |
|
614 | 614 | |
615 | - $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
615 | + $sql = "SHOW FULL COLUMNS FROM ".$table.";"; |
|
616 | 616 | |
617 | - dol_syslog($sql,LOG_DEBUG); |
|
617 | + dol_syslog($sql, LOG_DEBUG); |
|
618 | 618 | $result = $this->query($sql); |
619 | 619 | if ($result) |
620 | 620 | { |
621 | - while($row = $this->fetch_row($result)) |
|
621 | + while ($row = $this->fetch_row($result)) |
|
622 | 622 | { |
623 | 623 | $infotables[] = $row; |
624 | 624 | } |
@@ -638,72 +638,72 @@ discard block |
||
638 | 638 | * @param array $keys Tableau des champs cles noms => valeur |
639 | 639 | * @return int <0 if KO, >=0 if OK |
640 | 640 | */ |
641 | - function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
641 | + function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null) |
|
642 | 642 | { |
643 | 643 | // FIXME: $fulltext_keys parameter is unused |
644 | 644 | |
645 | 645 | // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
646 | 646 | // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
647 | 647 | $sql = "CREATE TABLE ".$table."("; |
648 | - $i=0; |
|
649 | - foreach($fields as $field_name => $field_desc) |
|
648 | + $i = 0; |
|
649 | + foreach ($fields as $field_name => $field_desc) |
|
650 | 650 | { |
651 | 651 | $sqlfields[$i] = $field_name." "; |
652 | - $sqlfields[$i] .= $field_desc['type']; |
|
653 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) { |
|
652 | + $sqlfields[$i] .= $field_desc['type']; |
|
653 | + if (preg_match("/^[^\s]/i", $field_desc['value'])) { |
|
654 | 654 | $sqlfields[$i] .= "(".$field_desc['value'].")"; |
655 | 655 | } |
656 | - if( preg_match("/^[^\s]/i",$field_desc['attribute'])) { |
|
656 | + if (preg_match("/^[^\s]/i", $field_desc['attribute'])) { |
|
657 | 657 | $sqlfields[$i] .= " ".$field_desc['attribute']; |
658 | 658 | } |
659 | - if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
659 | + if (preg_match("/^[^\s]/i", $field_desc['default'])) |
|
660 | 660 | { |
661 | - if ((preg_match("/null/i",$field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i",$field_desc['default']))) { |
|
661 | + if ((preg_match("/null/i", $field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i", $field_desc['default']))) { |
|
662 | 662 | $sqlfields[$i] .= " default ".$field_desc['default']; |
663 | 663 | } |
664 | 664 | else { |
665 | 665 | $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
666 | 666 | } |
667 | 667 | } |
668 | - if( preg_match("/^[^\s]/i",$field_desc['null'])) { |
|
668 | + if (preg_match("/^[^\s]/i", $field_desc['null'])) { |
|
669 | 669 | $sqlfields[$i] .= " ".$field_desc['null']; |
670 | 670 | } |
671 | - if( preg_match("/^[^\s]/i",$field_desc['extra'])) { |
|
671 | + if (preg_match("/^[^\s]/i", $field_desc['extra'])) { |
|
672 | 672 | $sqlfields[$i] .= " ".$field_desc['extra']; |
673 | 673 | } |
674 | 674 | $i++; |
675 | 675 | } |
676 | - if($primary_key != "") |
|
676 | + if ($primary_key != "") |
|
677 | 677 | $pk = "primary key(".$primary_key.")"; |
678 | 678 | |
679 | - if(is_array($unique_keys)) { |
|
679 | + if (is_array($unique_keys)) { |
|
680 | 680 | $i = 0; |
681 | - foreach($unique_keys as $key => $value) |
|
681 | + foreach ($unique_keys as $key => $value) |
|
682 | 682 | { |
683 | 683 | $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
684 | 684 | $i++; |
685 | 685 | } |
686 | 686 | } |
687 | - if(is_array($keys)) |
|
687 | + if (is_array($keys)) |
|
688 | 688 | { |
689 | 689 | $i = 0; |
690 | - foreach($keys as $key => $value) |
|
690 | + foreach ($keys as $key => $value) |
|
691 | 691 | { |
692 | 692 | $sqlk[$i] = "KEY ".$key." (".$value.")"; |
693 | 693 | $i++; |
694 | 694 | } |
695 | 695 | } |
696 | - $sql .= implode(',',$sqlfields); |
|
697 | - if($primary_key != "") |
|
696 | + $sql .= implode(',', $sqlfields); |
|
697 | + if ($primary_key != "") |
|
698 | 698 | $sql .= ",".$pk; |
699 | - if($unique_keys != "") |
|
700 | - $sql .= ",".implode(',',$sqluq); |
|
701 | - if(is_array($keys)) |
|
702 | - $sql .= ",".implode(',',$sqlk); |
|
703 | - $sql .=") engine=".$type; |
|
704 | - |
|
705 | - dol_syslog($sql,LOG_DEBUG); |
|
706 | - if(! $this -> query($sql)) |
|
699 | + if ($unique_keys != "") |
|
700 | + $sql .= ",".implode(',', $sqluq); |
|
701 | + if (is_array($keys)) |
|
702 | + $sql .= ",".implode(',', $sqlk); |
|
703 | + $sql .= ") engine=".$type; |
|
704 | + |
|
705 | + dol_syslog($sql, LOG_DEBUG); |
|
706 | + if (!$this -> query($sql)) |
|
707 | 707 | return -1; |
708 | 708 | else |
709 | 709 | return 1; |
@@ -716,11 +716,11 @@ discard block |
||
716 | 716 | * @param string $field Optionnel : Name of field if we want description of field |
717 | 717 | * @return bool|mysqli_result Resultset x (x->Field, x->Type, ...) |
718 | 718 | */ |
719 | - function DDLDescTable($table,$field="") |
|
719 | + function DDLDescTable($table, $field = "") |
|
720 | 720 | { |
721 | - $sql="DESC ".$table." ".$field; |
|
721 | + $sql = "DESC ".$table." ".$field; |
|
722 | 722 | |
723 | - dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
723 | + dol_syslog(get_class($this)."::DDLDescTable ".$sql, LOG_DEBUG); |
|
724 | 724 | $this->_results = $this->query($sql); |
725 | 725 | return $this->_results; |
726 | 726 | } |
@@ -734,34 +734,34 @@ discard block |
||
734 | 734 | * @param string $field_position Optionnel ex.: "after champtruc" |
735 | 735 | * @return int <0 if KO, >0 if OK |
736 | 736 | */ |
737 | - function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
737 | + function DDLAddField($table, $field_name, $field_desc, $field_position = "") |
|
738 | 738 | { |
739 | 739 | // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
740 | 740 | // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
741 | - $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
742 | - $sql.= $field_desc['type']; |
|
743 | - if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
744 | - if (! in_array($field_desc['type'],array('date','datetime'))) |
|
741 | + $sql = "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
742 | + $sql .= $field_desc['type']; |
|
743 | + if (preg_match("/^[^\s]/i", $field_desc['value'])) |
|
744 | + if (!in_array($field_desc['type'], array('date', 'datetime'))) |
|
745 | 745 | { |
746 | - $sql.= "(".$field_desc['value'].")"; |
|
746 | + $sql .= "(".$field_desc['value'].")"; |
|
747 | 747 | } |
748 | - if(preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
749 | - $sql.= " ".$field_desc['attribute']; |
|
750 | - if(preg_match("/^[^\s]/i",$field_desc['null'])) |
|
751 | - $sql.= " ".$field_desc['null']; |
|
752 | - if(preg_match("/^[^\s]/i",$field_desc['default'])) |
|
748 | + if (preg_match("/^[^\s]/i", $field_desc['attribute'])) |
|
749 | + $sql .= " ".$field_desc['attribute']; |
|
750 | + if (preg_match("/^[^\s]/i", $field_desc['null'])) |
|
751 | + $sql .= " ".$field_desc['null']; |
|
752 | + if (preg_match("/^[^\s]/i", $field_desc['default'])) |
|
753 | 753 | { |
754 | - if(preg_match("/null/i",$field_desc['default'])) |
|
755 | - $sql.= " default ".$field_desc['default']; |
|
754 | + if (preg_match("/null/i", $field_desc['default'])) |
|
755 | + $sql .= " default ".$field_desc['default']; |
|
756 | 756 | else |
757 | - $sql.= " default '".$field_desc['default']."'"; |
|
757 | + $sql .= " default '".$field_desc['default']."'"; |
|
758 | 758 | } |
759 | - if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
760 | - $sql.= " ".$field_desc['extra']; |
|
761 | - $sql.= " ".$field_position; |
|
759 | + if (preg_match("/^[^\s]/i", $field_desc['extra'])) |
|
760 | + $sql .= " ".$field_desc['extra']; |
|
761 | + $sql .= " ".$field_position; |
|
762 | 762 | |
763 | - dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
764 | - if($this->query($sql)) { |
|
763 | + dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG); |
|
764 | + if ($this->query($sql)) { |
|
765 | 765 | return 1; |
766 | 766 | } |
767 | 767 | return -1; |
@@ -775,38 +775,38 @@ discard block |
||
775 | 775 | * @param string $field_desc Array with description of field format |
776 | 776 | * @return int <0 if KO, >0 if OK |
777 | 777 | */ |
778 | - function DDLUpdateField($table,$field_name,$field_desc) |
|
778 | + function DDLUpdateField($table, $field_name, $field_desc) |
|
779 | 779 | { |
780 | 780 | $sql = "ALTER TABLE ".$table; |
781 | 781 | $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
782 | 782 | if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
783 | - $sql.="(".$field_desc['value'].")"; |
|
783 | + $sql .= "(".$field_desc['value'].")"; |
|
784 | 784 | } |
785 | 785 | if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') |
786 | 786 | { |
787 | 787 | // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL |
788 | 788 | if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
789 | 789 | { |
790 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
790 | + $sqlbis = "UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
791 | 791 | $this->query($sqlbis); |
792 | 792 | } |
793 | 793 | elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
794 | 794 | { |
795 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
795 | + $sqlbis = "UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
796 | 796 | $this->query($sqlbis); |
797 | 797 | } |
798 | 798 | |
799 | - $sql.=" NOT NULL"; |
|
799 | + $sql .= " NOT NULL"; |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | if ($field_desc['default'] != '') |
803 | 803 | { |
804 | - if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']); |
|
805 | - elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
804 | + if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql .= " DEFAULT ".$this->escape($field_desc['default']); |
|
805 | + elseif ($field_desc['type'] == 'text') $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
806 | 806 | } |
807 | 807 | |
808 | - dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
809 | - if (! $this->query($sql)) |
|
808 | + dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG); |
|
809 | + if (!$this->query($sql)) |
|
810 | 810 | return -1; |
811 | 811 | else |
812 | 812 | return 1; |
@@ -819,14 +819,14 @@ discard block |
||
819 | 819 | * @param string $field_name Name of field to drop |
820 | 820 | * @return int <0 if KO, >0 if OK |
821 | 821 | */ |
822 | - function DDLDropField($table,$field_name) |
|
822 | + function DDLDropField($table, $field_name) |
|
823 | 823 | { |
824 | - $sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
825 | - dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG); |
|
824 | + $sql = "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
825 | + dol_syslog(get_class($this)."::DDLDropField ".$sql, LOG_DEBUG); |
|
826 | 826 | if ($this->query($sql)) { |
827 | 827 | return 1; |
828 | 828 | } |
829 | - $this->error=$this->lasterror(); |
|
829 | + $this->error = $this->lasterror(); |
|
830 | 830 | return -1; |
831 | 831 | } |
832 | 832 | |
@@ -840,12 +840,12 @@ discard block |
||
840 | 840 | * @param string $dolibarr_main_db_name Database name where user must be granted |
841 | 841 | * @return int <0 if KO, >=0 if OK |
842 | 842 | */ |
843 | - function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
843 | + function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name) |
|
844 | 844 | { |
845 | 845 | $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'"; |
846 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
847 | - $resql=$this->query($sql); |
|
848 | - if (! $resql) |
|
846 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
847 | + $resql = $this->query($sql); |
|
848 | + if (!$resql) |
|
849 | 849 | { |
850 | 850 | if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS') |
851 | 851 | { |
@@ -858,18 +858,18 @@ discard block |
||
858 | 858 | } |
859 | 859 | } |
860 | 860 | $sql = "GRANT ALL PRIVILEGES ON ".$this->escape($dolibarr_main_db_name).".* TO '".$this->escape($dolibarr_main_db_user)."'@'".$this->escape($dolibarr_main_db_host)."' IDENTIFIED BY '".$this->escape($dolibarr_main_db_pass)."'"; |
861 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
862 | - $resql=$this->query($sql); |
|
863 | - if (! $resql) |
|
861 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
862 | + $resql = $this->query($sql); |
|
863 | + if (!$resql) |
|
864 | 864 | { |
865 | 865 | return -1; |
866 | 866 | } |
867 | 867 | |
868 | - $sql="FLUSH Privileges"; |
|
868 | + $sql = "FLUSH Privileges"; |
|
869 | 869 | |
870 | 870 | dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
871 | - $resql=$this->query($sql); |
|
872 | - if (! $resql) |
|
871 | + $resql = $this->query($sql); |
|
872 | + if (!$resql) |
|
873 | 873 | { |
874 | 874 | return -1; |
875 | 875 | } |
@@ -885,13 +885,13 @@ discard block |
||
885 | 885 | */ |
886 | 886 | function getDefaultCharacterSetDatabase() |
887 | 887 | { |
888 | - $resql=$this->query('SHOW VARIABLES LIKE \'character_set_database\''); |
|
888 | + $resql = $this->query('SHOW VARIABLES LIKE \'character_set_database\''); |
|
889 | 889 | if (!$resql) |
890 | 890 | { |
891 | 891 | // version Mysql < 4.1.1 |
892 | 892 | return $this->forcecharset; |
893 | 893 | } |
894 | - $liste=$this->fetch_array($resql); |
|
894 | + $liste = $this->fetch_array($resql); |
|
895 | 895 | $tmpval = $liste['Value']; |
896 | 896 | |
897 | 897 | return $tmpval; |
@@ -904,12 +904,12 @@ discard block |
||
904 | 904 | */ |
905 | 905 | function getListOfCharacterSet() |
906 | 906 | { |
907 | - $resql=$this->query('SHOW CHARSET'); |
|
907 | + $resql = $this->query('SHOW CHARSET'); |
|
908 | 908 | $liste = array(); |
909 | 909 | if ($resql) |
910 | 910 | { |
911 | 911 | $i = 0; |
912 | - while ($obj = $this->fetch_object($resql) ) |
|
912 | + while ($obj = $this->fetch_object($resql)) |
|
913 | 913 | { |
914 | 914 | $liste[$i]['charset'] = $obj->Charset; |
915 | 915 | $liste[$i]['description'] = $obj->Description; |
@@ -931,13 +931,13 @@ discard block |
||
931 | 931 | */ |
932 | 932 | function getDefaultCollationDatabase() |
933 | 933 | { |
934 | - $resql=$this->query('SHOW VARIABLES LIKE \'collation_database\''); |
|
934 | + $resql = $this->query('SHOW VARIABLES LIKE \'collation_database\''); |
|
935 | 935 | if (!$resql) |
936 | 936 | { |
937 | 937 | // version Mysql < 4.1.1 |
938 | 938 | return $this->forcecollate; |
939 | 939 | } |
940 | - $liste=$this->fetch_array($resql); |
|
940 | + $liste = $this->fetch_array($resql); |
|
941 | 941 | $tmpval = $liste['Value']; |
942 | 942 | |
943 | 943 | return $tmpval; |
@@ -950,12 +950,12 @@ discard block |
||
950 | 950 | */ |
951 | 951 | function getListOfCollation() |
952 | 952 | { |
953 | - $resql=$this->query('SHOW COLLATION'); |
|
953 | + $resql = $this->query('SHOW COLLATION'); |
|
954 | 954 | $liste = array(); |
955 | 955 | if ($resql) |
956 | 956 | { |
957 | 957 | $i = 0; |
958 | - while ($obj = $this->fetch_object($resql) ) |
|
958 | + while ($obj = $this->fetch_object($resql)) |
|
959 | 959 | { |
960 | 960 | $liste[$i]['collation'] = $obj->Collation; |
961 | 961 | $i++; |
@@ -975,14 +975,14 @@ discard block |
||
975 | 975 | */ |
976 | 976 | function getPathOfDump() |
977 | 977 | { |
978 | - $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
978 | + $fullpathofdump = '/pathtomysqldump/mysqldump'; |
|
979 | 979 | |
980 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
980 | + $resql = $this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
981 | 981 | if ($resql) |
982 | 982 | { |
983 | - $liste=$this->fetch_array($resql); |
|
984 | - $basedir=$liste['Value']; |
|
985 | - $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
983 | + $liste = $this->fetch_array($resql); |
|
984 | + $basedir = $liste['Value']; |
|
985 | + $fullpathofdump = $basedir.(preg_match('/\/$/', $basedir) ? '' : '/').'bin/mysqldump'; |
|
986 | 986 | } |
987 | 987 | return $fullpathofdump; |
988 | 988 | } |
@@ -994,14 +994,14 @@ discard block |
||
994 | 994 | */ |
995 | 995 | function getPathOfRestore() |
996 | 996 | { |
997 | - $fullpathofimport='/pathtomysql/mysql'; |
|
997 | + $fullpathofimport = '/pathtomysql/mysql'; |
|
998 | 998 | |
999 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
999 | + $resql = $this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
1000 | 1000 | if ($resql) |
1001 | 1001 | { |
1002 | - $liste=$this->fetch_array($resql); |
|
1003 | - $basedir=$liste['Value']; |
|
1004 | - $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
1002 | + $liste = $this->fetch_array($resql); |
|
1003 | + $basedir = $liste['Value']; |
|
1004 | + $fullpathofimport = $basedir.(preg_match('/\/$/', $basedir) ? '' : '/').'bin/mysql'; |
|
1005 | 1005 | } |
1006 | 1006 | return $fullpathofimport; |
1007 | 1007 | } |
@@ -1012,16 +1012,16 @@ discard block |
||
1012 | 1012 | * @param string $filter Filter list on a particular value |
1013 | 1013 | * @return array Array of key-values (key=>value) |
1014 | 1014 | */ |
1015 | - function getServerParametersValues($filter='') |
|
1015 | + function getServerParametersValues($filter = '') |
|
1016 | 1016 | { |
1017 | - $result=array(); |
|
1017 | + $result = array(); |
|
1018 | 1018 | |
1019 | - $sql='SHOW VARIABLES'; |
|
1020 | - if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
1021 | - $resql=$this->query($sql); |
|
1019 | + $sql = 'SHOW VARIABLES'; |
|
1020 | + if ($filter) $sql .= " LIKE '".$this->escape($filter)."'"; |
|
1021 | + $resql = $this->query($sql); |
|
1022 | 1022 | if ($resql) |
1023 | 1023 | { |
1024 | - while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
1024 | + while ($obj = $this->fetch_object($resql)) $result[$obj->Variable_name] = $obj->Value; |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | return $result; |
@@ -1033,16 +1033,16 @@ discard block |
||
1033 | 1033 | * @param string $filter Filter list on a particular value |
1034 | 1034 | * @return array Array of key-values (key=>value) |
1035 | 1035 | */ |
1036 | - function getServerStatusValues($filter='') |
|
1036 | + function getServerStatusValues($filter = '') |
|
1037 | 1037 | { |
1038 | - $result=array(); |
|
1038 | + $result = array(); |
|
1039 | 1039 | |
1040 | - $sql='SHOW STATUS'; |
|
1041 | - if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
1042 | - $resql=$this->query($sql); |
|
1040 | + $sql = 'SHOW STATUS'; |
|
1041 | + if ($filter) $sql .= " LIKE '".$this->escape($filter)."'"; |
|
1042 | + $resql = $this->query($sql); |
|
1043 | 1043 | if ($resql) |
1044 | 1044 | { |
1045 | - while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
1045 | + while ($obj = $this->fetch_object($resql)) $result[$obj->Variable_name] = $obj->Value; |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | return $result; |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * @param string $query SQL query string |
465 | 465 | * @param int $usesavepoint 0=Default mode, 1=Run a savepoint before and a rollback to savepoint if error (this allow to have some request with errors inside global transactions). |
466 | 466 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
467 | - * @return false|resource Resultset of answer |
|
467 | + * @return resource|null Resultset of answer |
|
468 | 468 | */ |
469 | 469 | function query($query,$usesavepoint=0,$type='auto') |
470 | 470 | { |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | * Decrypt sensitive data in database |
791 | 791 | * |
792 | 792 | * @param int $value Value to decrypt |
793 | - * @return string Decrypted value if used |
|
793 | + * @return integer Decrypted value if used |
|
794 | 794 | */ |
795 | 795 | function decrypt($value) |
796 | 796 | { |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * \brief Fichier de la classe permettant de gerer une base pgsql |
29 | 29 | */ |
30 | 30 | |
31 | -require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php'; |
|
31 | +require_once DOL_DOCUMENT_ROOT.'/core/db/DoliDB.class.php'; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Class to drive a Postgresql database for Dolibarr |
@@ -36,15 +36,15 @@ discard block |
||
36 | 36 | class DoliDBPgsql extends DoliDB |
37 | 37 | { |
38 | 38 | //! Database type |
39 | - public $type='pgsql'; // Name of manager |
|
39 | + public $type = 'pgsql'; // Name of manager |
|
40 | 40 | //! Database label |
41 | - const LABEL='PostgreSQL'; // Label of manager |
|
41 | + const LABEL = 'PostgreSQL'; // Label of manager |
|
42 | 42 | //! Charset |
43 | - var $forcecharset='UTF8'; // Can't be static as it may be forced with a dynamic value |
|
43 | + var $forcecharset = 'UTF8'; // Can't be static as it may be forced with a dynamic value |
|
44 | 44 | //! Collate used to force collate when creating database |
45 | - var $forcecollate=''; // Can't be static as it may be forced with a dynamic value |
|
45 | + var $forcecollate = ''; // Can't be static as it may be forced with a dynamic value |
|
46 | 46 | //! Version min database |
47 | - const VERSIONMIN='9.0.0'; // Version min database |
|
47 | + const VERSIONMIN = '9.0.0'; // Version min database |
|
48 | 48 | /** @var resource Resultset of last query */ |
49 | 49 | private $_results; |
50 | 50 | |
@@ -62,37 +62,37 @@ discard block |
||
62 | 62 | * @param string $name Nom de la database |
63 | 63 | * @param int $port Port of database server |
64 | 64 | */ |
65 | - function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
65 | + function __construct($type, $host, $user, $pass, $name = '', $port = 0) |
|
66 | 66 | { |
67 | - global $conf,$langs; |
|
67 | + global $conf, $langs; |
|
68 | 68 | |
69 | 69 | // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
70 | - if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set; |
|
71 | - if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
|
70 | + if (!empty($conf->db->character_set)) $this->forcecharset = $conf->db->character_set; |
|
71 | + if (!empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate = $conf->db->dolibarr_main_db_collation; |
|
72 | 72 | |
73 | - $this->database_user=$user; |
|
74 | - $this->database_host=$host; |
|
75 | - $this->database_port=$port; |
|
73 | + $this->database_user = $user; |
|
74 | + $this->database_host = $host; |
|
75 | + $this->database_port = $port; |
|
76 | 76 | |
77 | - $this->transaction_opened=0; |
|
77 | + $this->transaction_opened = 0; |
|
78 | 78 | |
79 | 79 | //print "Name DB: $host,$user,$pass,$name<br>"; |
80 | 80 | |
81 | - if (! function_exists("pg_connect")) |
|
81 | + if (!function_exists("pg_connect")) |
|
82 | 82 | { |
83 | 83 | $this->connected = false; |
84 | 84 | $this->ok = false; |
85 | - $this->error="Pgsql PHP functions are not available in this version of PHP"; |
|
86 | - dol_syslog(get_class($this)."::DoliDBPgsql : Pgsql PHP functions are not available in this version of PHP",LOG_ERR); |
|
85 | + $this->error = "Pgsql PHP functions are not available in this version of PHP"; |
|
86 | + dol_syslog(get_class($this)."::DoliDBPgsql : Pgsql PHP functions are not available in this version of PHP", LOG_ERR); |
|
87 | 87 | return $this->ok; |
88 | 88 | } |
89 | 89 | |
90 | - if (! $host) |
|
90 | + if (!$host) |
|
91 | 91 | { |
92 | 92 | $this->connected = false; |
93 | 93 | $this->ok = false; |
94 | - $this->error=$langs->trans("ErrorWrongHostParameter"); |
|
95 | - dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Connect, wrong host parameters",LOG_ERR); |
|
94 | + $this->error = $langs->trans("ErrorWrongHostParameter"); |
|
95 | + dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Connect, wrong host parameters", LOG_ERR); |
|
96 | 96 | return $this->ok; |
97 | 97 | } |
98 | 98 | |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | // host, login ou password incorrect |
111 | 111 | $this->connected = false; |
112 | 112 | $this->ok = false; |
113 | - $this->error='Host, login or password incorrect'; |
|
114 | - dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Connect ".$this->error,LOG_ERR); |
|
113 | + $this->error = 'Host, login or password incorrect'; |
|
114 | + dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Connect ".$this->error, LOG_ERR); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | // Si connexion serveur ok et si connexion base demandee, on essaie connexion base |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | $this->database_selected = false; |
129 | 129 | $this->database_name = ''; |
130 | 130 | $this->ok = false; |
131 | - $this->error=$this->error(); |
|
132 | - dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Select_db ".$this->error,LOG_ERR); |
|
131 | + $this->error = $this->error(); |
|
132 | + dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Select_db ".$this->error, LOG_ERR); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | else |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | * @param bool $unescapeslashquot Unescape slash quote with quote quote |
151 | 151 | * @return string SQL request line converted |
152 | 152 | */ |
153 | - static function convertSQLFromMysql($line,$type='auto',$unescapeslashquot=false) |
|
153 | + static function convertSQLFromMysql($line, $type = 'auto', $unescapeslashquot = false) |
|
154 | 154 | { |
155 | 155 | // Removed empty line if this is a comment line for SVN tagging |
156 | - if (preg_match('/^--\s\$Id/i',$line)) { |
|
156 | + if (preg_match('/^--\s\$Id/i', $line)) { |
|
157 | 157 | return ''; |
158 | 158 | } |
159 | 159 | // Return line if this is a comment |
160 | - if (preg_match('/^#/i',$line) || preg_match('/^$/i',$line) || preg_match('/^--/i',$line)) |
|
160 | + if (preg_match('/^#/i', $line) || preg_match('/^$/i', $line) || preg_match('/^--/i', $line)) |
|
161 | 161 | { |
162 | 162 | return $line; |
163 | 163 | } |
@@ -172,178 +172,178 @@ discard block |
||
172 | 172 | |
173 | 173 | if ($type == 'auto') |
174 | 174 | { |
175 | - if (preg_match('/ALTER TABLE/i',$line)) $type='dml'; |
|
176 | - else if (preg_match('/CREATE TABLE/i',$line)) $type='dml'; |
|
177 | - else if (preg_match('/DROP TABLE/i',$line)) $type='dml'; |
|
175 | + if (preg_match('/ALTER TABLE/i', $line)) $type = 'dml'; |
|
176 | + else if (preg_match('/CREATE TABLE/i', $line)) $type = 'dml'; |
|
177 | + else if (preg_match('/DROP TABLE/i', $line)) $type = 'dml'; |
|
178 | 178 | } |
179 | 179 | |
180 | - $line=preg_replace('/ as signed\)/i',' as integer)',$line); |
|
180 | + $line = preg_replace('/ as signed\)/i', ' as integer)', $line); |
|
181 | 181 | |
182 | 182 | if ($type == 'dml') |
183 | 183 | { |
184 | - $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
184 | + $line = preg_replace('/\s/', ' ', $line); // Replace tabulation with space |
|
185 | 185 | |
186 | 186 | // we are inside create table statement so lets process datatypes |
187 | - if (preg_match('/(ISAM|innodb)/i',$line)) { // end of create table sequence |
|
188 | - $line=preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i',');',$line); |
|
189 | - $line=preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i',');',$line); |
|
190 | - $line=preg_replace('/,$/','',$line); |
|
187 | + if (preg_match('/(ISAM|innodb)/i', $line)) { // end of create table sequence |
|
188 | + $line = preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i', ');', $line); |
|
189 | + $line = preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb).*;/i', ');', $line); |
|
190 | + $line = preg_replace('/,$/', '', $line); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..." |
194 | - if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i',$line,$reg)) { |
|
195 | - $newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 SERIAL PRIMARY KEY',$line); |
|
194 | + if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i', $line, $reg)) { |
|
195 | + $newline = preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i', '\\1 \\2 SERIAL PRIMARY KEY', $line); |
|
196 | 196 | //$line = "-- ".$line." replaced by --\n".$newline; |
197 | - $line=$newline; |
|
197 | + $line = $newline; |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | // tinyint type conversion |
201 | - $line=preg_replace('/tinyint\(?[0-9]*\)?/','smallint',$line); |
|
202 | - $line=preg_replace('/tinyint/i','smallint',$line); |
|
201 | + $line = preg_replace('/tinyint\(?[0-9]*\)?/', 'smallint', $line); |
|
202 | + $line = preg_replace('/tinyint/i', 'smallint', $line); |
|
203 | 203 | |
204 | 204 | // nuke unsigned |
205 | - $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
205 | + $line = preg_replace('/(int\w+|smallint)\s+unsigned/i', '\\1', $line); |
|
206 | 206 | |
207 | 207 | // blob -> text |
208 | - $line=preg_replace('/\w*blob/i','text',$line); |
|
208 | + $line = preg_replace('/\w*blob/i', 'text', $line); |
|
209 | 209 | |
210 | 210 | // tinytext/mediumtext -> text |
211 | - $line=preg_replace('/tinytext/i','text',$line); |
|
212 | - $line=preg_replace('/mediumtext/i','text',$line); |
|
213 | - $line=preg_replace('/longtext/i','text',$line); |
|
211 | + $line = preg_replace('/tinytext/i', 'text', $line); |
|
212 | + $line = preg_replace('/mediumtext/i', 'text', $line); |
|
213 | + $line = preg_replace('/longtext/i', 'text', $line); |
|
214 | 214 | |
215 | - $line=preg_replace('/text\([0-9]+\)/i','text',$line); |
|
215 | + $line = preg_replace('/text\([0-9]+\)/i', 'text', $line); |
|
216 | 216 | |
217 | 217 | // change not null datetime field to null valid ones |
218 | 218 | // (to support remapping of "zero time" to null |
219 | - $line=preg_replace('/datetime not null/i','datetime',$line); |
|
220 | - $line=preg_replace('/datetime/i','timestamp',$line); |
|
219 | + $line = preg_replace('/datetime not null/i', 'datetime', $line); |
|
220 | + $line = preg_replace('/datetime/i', 'timestamp', $line); |
|
221 | 221 | |
222 | 222 | // double -> numeric |
223 | - $line=preg_replace('/^double/i','numeric',$line); |
|
224 | - $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
223 | + $line = preg_replace('/^double/i', 'numeric', $line); |
|
224 | + $line = preg_replace('/(\s*)double/i', '\\1numeric', $line); |
|
225 | 225 | // float -> numeric |
226 | - $line=preg_replace('/^float/i','numeric',$line); |
|
227 | - $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
226 | + $line = preg_replace('/^float/i', 'numeric', $line); |
|
227 | + $line = preg_replace('/(\s*)float/i', '\\1numeric', $line); |
|
228 | 228 | |
229 | 229 | //Check tms timestamp field case (in Mysql this field is defautled to now and |
230 | 230 | // on update defaulted by now |
231 | - $line=preg_replace('/(\s*)tms(\s*)timestamp/i','\\1tms timestamp without time zone DEFAULT now() NOT NULL',$line); |
|
231 | + $line = preg_replace('/(\s*)tms(\s*)timestamp/i', '\\1tms timestamp without time zone DEFAULT now() NOT NULL', $line); |
|
232 | 232 | |
233 | 233 | // nuke ON UPDATE CURRENT_TIMESTAMP |
234 | - $line=preg_replace('/(\s*)on(\s*)update(\s*)CURRENT_TIMESTAMP/i','\\1',$line); |
|
234 | + $line = preg_replace('/(\s*)on(\s*)update(\s*)CURRENT_TIMESTAMP/i', '\\1', $line); |
|
235 | 235 | |
236 | 236 | // unique index(field1,field2) |
237 | - if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
237 | + if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i', $line)) |
|
238 | 238 | { |
239 | - $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
239 | + $line = preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i', 'UNIQUE\(\\1\)', $line); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | // We remove end of requests "AFTER fieldxxx" |
243 | - $line=preg_replace('/\sAFTER [a-z0-9_]+/i','',$line); |
|
243 | + $line = preg_replace('/\sAFTER [a-z0-9_]+/i', '', $line); |
|
244 | 244 | |
245 | 245 | // We remove start of requests "ALTER TABLE tablexxx" if this is a DROP INDEX |
246 | - $line=preg_replace('/ALTER TABLE [a-z0-9_]+\s+DROP INDEX/i','DROP INDEX',$line); |
|
246 | + $line = preg_replace('/ALTER TABLE [a-z0-9_]+\s+DROP INDEX/i', 'DROP INDEX', $line); |
|
247 | 247 | |
248 | 248 | // Translate order to rename fields |
249 | - if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i',$line,$reg)) |
|
249 | + if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i', $line, $reg)) |
|
250 | 250 | { |
251 | 251 | $line = "-- ".$line." replaced by --\n"; |
252 | - $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
252 | + $line .= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | // Translate order to modify field format |
256 | - if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg)) |
|
256 | + if (preg_match('/ALTER TABLE ([a-z0-9_]+)\s+MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i', $line, $reg)) |
|
257 | 257 | { |
258 | 258 | $line = "-- ".$line." replaced by --\n"; |
259 | - $newreg3=$reg[3]; |
|
260 | - $newreg3=preg_replace('/ DEFAULT NULL/i','',$newreg3); |
|
261 | - $newreg3=preg_replace('/ NOT NULL/i','',$newreg3); |
|
262 | - $newreg3=preg_replace('/ NULL/i','',$newreg3); |
|
263 | - $newreg3=preg_replace('/ DEFAULT 0/i','',$newreg3); |
|
264 | - $newreg3=preg_replace('/ DEFAULT \'?[0-9a-zA-Z_@]*\'?/i','',$newreg3); |
|
265 | - $line.= "ALTER TABLE ".$reg[1]." ALTER COLUMN ".$reg[2]." TYPE ".$newreg3; |
|
259 | + $newreg3 = $reg[3]; |
|
260 | + $newreg3 = preg_replace('/ DEFAULT NULL/i', '', $newreg3); |
|
261 | + $newreg3 = preg_replace('/ NOT NULL/i', '', $newreg3); |
|
262 | + $newreg3 = preg_replace('/ NULL/i', '', $newreg3); |
|
263 | + $newreg3 = preg_replace('/ DEFAULT 0/i', '', $newreg3); |
|
264 | + $newreg3 = preg_replace('/ DEFAULT \'?[0-9a-zA-Z_@]*\'?/i', '', $newreg3); |
|
265 | + $line .= "ALTER TABLE ".$reg[1]." ALTER COLUMN ".$reg[2]." TYPE ".$newreg3; |
|
266 | 266 | // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
267 | 267 | } |
268 | 268 | |
269 | 269 | // alter table add primary key (field1, field2 ...) -> We remove the primary key name not accepted by PostGreSQL |
270 | 270 | // ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY pk_dolibarr_modules (numero, entity) |
271 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i',$line,$reg)) |
|
271 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i', $line, $reg)) |
|
272 | 272 | { |
273 | 273 | $line = "-- ".$line." replaced by --\n"; |
274 | - $line.= "ALTER TABLE ".$reg[1]." ADD PRIMARY KEY (".$reg[3]; |
|
274 | + $line .= "ALTER TABLE ".$reg[1]." ADD PRIMARY KEY (".$reg[3]; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | // Translate order to drop foreign keys |
278 | 278 | // ALTER TABLE llx_dolibarr_modules DROP FOREIGN KEY fk_xxx |
279 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i',$line,$reg)) |
|
279 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i', $line, $reg)) |
|
280 | 280 | { |
281 | 281 | $line = "-- ".$line." replaced by --\n"; |
282 | - $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
282 | + $line .= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | // Translate order to add foreign keys |
286 | 286 | // ALTER TABLE llx_tablechild ADD CONSTRAINT fk_tablechild_fk_fieldparent FOREIGN KEY (fk_fieldparent) REFERENCES llx_tableparent (rowid) |
287 | - if (preg_match('/ALTER\s+TABLE\s+(.*)\s*ADD CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*(.*)$/i',$line,$reg)) |
|
287 | + if (preg_match('/ALTER\s+TABLE\s+(.*)\s*ADD CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*(.*)$/i', $line, $reg)) |
|
288 | 288 | { |
289 | - $line=preg_replace('/;$/','',$line); |
|
290 | - $line.=" DEFERRABLE INITIALLY IMMEDIATE;"; |
|
289 | + $line = preg_replace('/;$/', '', $line); |
|
290 | + $line .= " DEFERRABLE INITIALLY IMMEDIATE;"; |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | // alter table add [unique] [index] (field1, field2 ...) |
294 | 294 | // ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version) |
295 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i',$line,$reg)) |
|
295 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i', $line, $reg)) |
|
296 | 296 | { |
297 | - $fieldlist=$reg[4]; |
|
298 | - $idxname=$reg[3]; |
|
299 | - $tablename=$reg[1]; |
|
297 | + $fieldlist = $reg[4]; |
|
298 | + $idxname = $reg[3]; |
|
299 | + $tablename = $reg[1]; |
|
300 | 300 | $line = "-- ".$line." replaced by --\n"; |
301 | - $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
301 | + $line .= "CREATE ".(preg_match('/UNIQUE/', $reg[2]) ? 'UNIQUE ' : '')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | 305 | // To have postgresql case sensitive |
306 | - $line=str_replace(' LIKE \'',' ILIKE \'',$line); |
|
307 | - $line=str_replace(' LIKE BINARY \'',' LIKE \'',$line); |
|
306 | + $line = str_replace(' LIKE \'', ' ILIKE \'', $line); |
|
307 | + $line = str_replace(' LIKE BINARY \'', ' LIKE \'', $line); |
|
308 | 308 | |
309 | 309 | // Replace INSERT IGNORE into INSERT |
310 | - $line=preg_replace('/^INSERT IGNORE/','INSERT',$line); |
|
310 | + $line = preg_replace('/^INSERT IGNORE/', 'INSERT', $line); |
|
311 | 311 | |
312 | 312 | // Delete using criteria on other table must not declare twice the deleted table |
313 | 313 | // DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable |
314 | - if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg)) |
|
314 | + if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i', $line, $reg)) |
|
315 | 315 | { |
316 | 316 | if ($reg[1] == $reg[2]) // If same table, we remove second one |
317 | 317 | { |
318 | - $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line); |
|
318 | + $line = preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i', 'DELETE FROM \\1 USING \\3', $line); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
322 | 322 | // Remove () in the tables in FROM if 1 table |
323 | - $line=preg_replace('/FROM\s*\((([a-z_]+)\s+as\s+([a-z_]+)\s*)\)/i','FROM \\1',$line); |
|
323 | + $line = preg_replace('/FROM\s*\((([a-z_]+)\s+as\s+([a-z_]+)\s*)\)/i', 'FROM \\1', $line); |
|
324 | 324 | //print $line."\n"; |
325 | 325 | |
326 | 326 | // Remove () in the tables in FROM if 2 table |
327 | - $line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2',$line); |
|
327 | + $line = preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2', $line); |
|
328 | 328 | //print $line."\n"; |
329 | 329 | |
330 | 330 | // Remove () in the tables in FROM if 3 table |
331 | - $line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2, \\3',$line); |
|
331 | + $line = preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2, \\3', $line); |
|
332 | 332 | //print $line."\n"; |
333 | 333 | |
334 | 334 | // Remove () in the tables in FROM if 4 table |
335 | - $line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2, \\3, \\4',$line); |
|
335 | + $line = preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2, \\3, \\4', $line); |
|
336 | 336 | //print $line."\n"; |
337 | 337 | |
338 | 338 | // Remove () in the tables in FROM if 5 table |
339 | - $line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2, \\3, \\4, \\5',$line); |
|
339 | + $line = preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2, \\3, \\4, \\5', $line); |
|
340 | 340 | //print $line."\n"; |
341 | 341 | |
342 | 342 | // Replace espacing \' by ''. |
343 | 343 | // By default we do not (should be already done by db->escape function if required |
344 | 344 | // except for sql insert in data file that are mysql escaped so we removed them to |
345 | 345 | // be compatible with standard_conforming_strings=on that considers \ as ordinary character). |
346 | - if ($unescapeslashquot) $line=preg_replace("/\\\'/","''",$line); |
|
346 | + if ($unescapeslashquot) $line = preg_replace("/\\\'/", "''", $line); |
|
347 | 347 | |
348 | 348 | //print "type=".$type." newline=".$line."<br>\n"; |
349 | 349 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | * @return false|resource Database access handler |
377 | 377 | * @see close |
378 | 378 | */ |
379 | - function connect($host, $login, $passwd, $name, $port=0) |
|
379 | + function connect($host, $login, $passwd, $name, $port = 0) |
|
380 | 380 | { |
381 | 381 | // use pg_pconnect() instead of pg_connect() if you want to use persistent connection costing 1ms, instead of 30ms for non persistent |
382 | 382 | |
@@ -389,20 +389,20 @@ discard block |
||
389 | 389 | $name = str_replace(array("\\", "'"), array("\\\\", "\\'"), $name); |
390 | 390 | $port = str_replace(array("\\", "'"), array("\\\\", "\\'"), $port); |
391 | 391 | |
392 | - if (! $name) $name="postgres"; // When try to connect using admin user |
|
392 | + if (!$name) $name = "postgres"; // When try to connect using admin user |
|
393 | 393 | |
394 | 394 | // try first Unix domain socket (local) |
395 | - if ((! empty($host) && $host == "socket") && ! defined('NOLOCALSOCKETPGCONNECT')) |
|
395 | + if ((!empty($host) && $host == "socket") && !defined('NOLOCALSOCKETPGCONNECT')) |
|
396 | 396 | { |
397 | - $con_string = "dbname='".$name."' user='".$login."' password='".$passwd."'"; // $name may be empty |
|
397 | + $con_string = "dbname='".$name."' user='".$login."' password='".$passwd."'"; // $name may be empty |
|
398 | 398 | $this->db = @pg_connect($con_string); |
399 | 399 | } |
400 | 400 | |
401 | 401 | // if local connection failed or not requested, use TCP/IP |
402 | - if (! $this->db) |
|
402 | + if (!$this->db) |
|
403 | 403 | { |
404 | - if (! $host) $host = "localhost"; |
|
405 | - if (! $port) $port = 5432; |
|
404 | + if (!$host) $host = "localhost"; |
|
405 | + if (!$port) $port = 5432; |
|
406 | 406 | |
407 | 407 | $con_string = "host='".$host."' port='".$port."' dbname='".$name."' user='".$login."' password='".$passwd."'"; |
408 | 408 | $this->db = @pg_connect($con_string); |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | if ($this->db) |
413 | 413 | { |
414 | 414 | $this->database_name = $name; |
415 | - pg_set_error_verbosity($this->db, PGSQL_ERRORS_VERBOSE); // Set verbosity to max |
|
415 | + pg_set_error_verbosity($this->db, PGSQL_ERRORS_VERBOSE); // Set verbosity to max |
|
416 | 416 | pg_query($this->db, "set datestyle = 'ISO, YMD';"); |
417 | 417 | } |
418 | 418 | |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | */ |
427 | 427 | function getVersion() |
428 | 428 | { |
429 | - $resql=$this->query('SHOW server_version'); |
|
429 | + $resql = $this->query('SHOW server_version'); |
|
430 | 430 | if ($resql) |
431 | 431 | { |
432 | - $liste=$this->fetch_array($resql); |
|
432 | + $liste = $this->fetch_array($resql); |
|
433 | 433 | return $liste['server_version']; |
434 | 434 | } |
435 | 435 | return ''; |
@@ -455,8 +455,8 @@ discard block |
||
455 | 455 | { |
456 | 456 | if ($this->db) |
457 | 457 | { |
458 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
459 | - $this->connected=false; |
|
458 | + if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR); |
|
459 | + $this->connected = false; |
|
460 | 460 | return pg_close($this->db); |
461 | 461 | } |
462 | 462 | return false; |
@@ -470,28 +470,28 @@ discard block |
||
470 | 470 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
471 | 471 | * @return false|resource Resultset of answer |
472 | 472 | */ |
473 | - function query($query,$usesavepoint=0,$type='auto') |
|
473 | + function query($query, $usesavepoint = 0, $type = 'auto') |
|
474 | 474 | { |
475 | 475 | global $conf; |
476 | 476 | |
477 | 477 | $query = trim($query); |
478 | 478 | |
479 | 479 | // Convert MySQL syntax to PostgresSQL syntax |
480 | - $query=$this->convertSQLFromMysql($query,$type,($this->unescapeslashquot && $this->standard_conforming_strings)); |
|
480 | + $query = $this->convertSQLFromMysql($query, $type, ($this->unescapeslashquot && $this->standard_conforming_strings)); |
|
481 | 481 | //print "After convertSQLFromMysql:\n".$query."<br>\n"; |
482 | 482 | |
483 | - if (! empty($conf->global->MAIN_DB_AUTOFIX_BAD_SQL_REQUEST)) |
|
483 | + if (!empty($conf->global->MAIN_DB_AUTOFIX_BAD_SQL_REQUEST)) |
|
484 | 484 | { |
485 | 485 | // Fix bad formed requests. If request contains a date without quotes, we fix this but this should not occurs. |
486 | - $loop=true; |
|
486 | + $loop = true; |
|
487 | 487 | while ($loop) |
488 | 488 | { |
489 | - if (preg_match('/([^\'])([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])/',$query)) |
|
489 | + if (preg_match('/([^\'])([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])/', $query)) |
|
490 | 490 | { |
491 | - $query=preg_replace('/([^\'])([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])/','\\1\'\\2\'',$query); |
|
492 | - dol_syslog("Warning: Bad formed request converted into ".$query,LOG_WARNING); |
|
491 | + $query = preg_replace('/([^\'])([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])/', '\\1\'\\2\'', $query); |
|
492 | + dol_syslog("Warning: Bad formed request converted into ".$query, LOG_WARNING); |
|
493 | 493 | } |
494 | - else $loop=false; |
|
494 | + else $loop = false; |
|
495 | 495 | } |
496 | 496 | } |
497 | 497 | |
@@ -500,14 +500,14 @@ discard block |
||
500 | 500 | @pg_query($this->db, 'SAVEPOINT mysavepoint'); |
501 | 501 | } |
502 | 502 | |
503 | - if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
503 | + if (!in_array($query, array('BEGIN', 'COMMIT', 'ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
504 | 504 | |
505 | 505 | $ret = @pg_query($this->db, $query); |
506 | 506 | |
507 | 507 | //print $query; |
508 | - if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
508 | + if (!preg_match("/^COMMIT/i", $query) && !preg_match("/^ROLLBACK/i", $query)) // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
509 | 509 | { |
510 | - if (! $ret) |
|
510 | + if (!$ret) |
|
511 | 511 | { |
512 | 512 | if ($this->errno() != 'DB_ERROR_25P02') // Do not overwrite errors if this is a consecutive error |
513 | 513 | { |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | $this->lasterror = $this->error(); |
516 | 516 | $this->lasterrno = $this->errno(); |
517 | 517 | |
518 | - if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); // Log of request was not yet done previously |
|
518 | + if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); // Log of request was not yet done previously |
|
519 | 519 | dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR); |
520 | 520 | dol_syslog(get_class($this)."::query SQL Error usesavepoint = ".$usesavepoint, LOG_ERR); |
521 | 521 | } |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | @pg_query($this->db, 'ROLLBACK TO SAVEPOINT mysavepoint'); |
526 | 526 | } |
527 | 527 | } |
528 | - $this->lastquery=$query; |
|
528 | + $this->lastquery = $query; |
|
529 | 529 | $this->_results = $ret; |
530 | 530 | } |
531 | 531 | |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | function fetch_object($resultset) |
542 | 542 | { |
543 | 543 | // If resultset not provided, we take the last used by connexion |
544 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
544 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
545 | 545 | return pg_fetch_object($resultset); |
546 | 546 | } |
547 | 547 | |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | function fetch_array($resultset) |
555 | 555 | { |
556 | 556 | // If resultset not provided, we take the last used by connexion |
557 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
557 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
558 | 558 | return pg_fetch_array($resultset); |
559 | 559 | } |
560 | 560 | |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | function fetch_row($resultset) |
568 | 568 | { |
569 | 569 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
570 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
570 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
571 | 571 | return pg_fetch_row($resultset); |
572 | 572 | } |
573 | 573 | |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | function num_rows($resultset) |
582 | 582 | { |
583 | 583 | // If resultset not provided, we take the last used by connexion |
584 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
584 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
585 | 585 | return pg_num_rows($resultset); |
586 | 586 | } |
587 | 587 | |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | function affected_rows($resultset) |
596 | 596 | { |
597 | 597 | // If resultset not provided, we take the last used by connexion |
598 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
598 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
599 | 599 | // pgsql necessite un resultset pour cette fonction contrairement |
600 | 600 | // a mysql qui prend un link de base |
601 | 601 | return pg_affected_rows($resultset); |
@@ -608,10 +608,10 @@ discard block |
||
608 | 608 | * @param resource $resultset Result set of request |
609 | 609 | * @return void |
610 | 610 | */ |
611 | - function free($resultset=null) |
|
611 | + function free($resultset = null) |
|
612 | 612 | { |
613 | 613 | // If resultset not provided, we take the last used by connexion |
614 | - if (! is_resource($resultset)) { $resultset=$this->_results; } |
|
614 | + if (!is_resource($resultset)) { $resultset = $this->_results; } |
|
615 | 615 | // Si resultset en est un, on libere la memoire |
616 | 616 | if (is_resource($resultset)) pg_free_result($resultset); |
617 | 617 | } |
@@ -624,11 +624,11 @@ discard block |
||
624 | 624 | * @param int $offset Numero of line from where starting fetch |
625 | 625 | * @return string String with SQL syntax to add a limit and offset |
626 | 626 | */ |
627 | - function plimit($limit=0,$offset=0) |
|
627 | + function plimit($limit = 0, $offset = 0) |
|
628 | 628 | { |
629 | 629 | global $conf; |
630 | 630 | if (empty($limit)) return ""; |
631 | - if ($limit < 0) $limit=$conf->liste_limit; |
|
631 | + if ($limit < 0) $limit = $conf->liste_limit; |
|
632 | 632 | if ($offset > 0) return " LIMIT ".$limit." OFFSET ".$offset." "; |
633 | 633 | else return " LIMIT $limit "; |
634 | 634 | } |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | */ |
655 | 655 | function idate($param) |
656 | 656 | { |
657 | - return dol_print_date($param,"%Y-%m-%d %H:%M:%S"); |
|
657 | + return dol_print_date($param, "%Y-%m-%d %H:%M:%S"); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | * @param string $resko resultat si test non egal |
666 | 666 | * @return string chaine formate SQL |
667 | 667 | */ |
668 | - function ifsql($test,$resok,$resko) |
|
668 | + function ifsql($test, $resok, $resko) |
|
669 | 669 | { |
670 | 670 | return '(CASE WHEN '.$test.' THEN '.$resok.' ELSE '.$resko.' END)'; |
671 | 671 | } |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | */ |
678 | 678 | function errno() |
679 | 679 | { |
680 | - if (! $this->connected) { |
|
680 | + if (!$this->connected) { |
|
681 | 681 | // Si il y a eu echec de connexion, $this->db n'est pas valide. |
682 | 682 | return 'DB_ERROR_FAILED_TO_CONNECT'; |
683 | 683 | } |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | 42701=> 'DB_ERROR_COLUMN_ALREADY_EXISTS', |
700 | 700 | '42710' => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', |
701 | 701 | '23505' => 'DB_ERROR_RECORD_ALREADY_EXISTS', |
702 | - '42704' => 'DB_ERROR_NO_INDEX_TO_DROP', // May also be Type xxx does not exists |
|
702 | + '42704' => 'DB_ERROR_NO_INDEX_TO_DROP', // May also be Type xxx does not exists |
|
703 | 703 | '42601' => 'DB_ERROR_SYNTAX', |
704 | 704 | '42P16' => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS', |
705 | 705 | 1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY', |
@@ -713,18 +713,18 @@ discard block |
||
713 | 713 | '42P04' => 'DB_DATABASE_ALREADY_EXISTS' |
714 | 714 | ); |
715 | 715 | |
716 | - $errorlabel=pg_last_error($this->db); |
|
717 | - $errorcode=''; |
|
718 | - if (preg_match('/: *([0-9P]+):/',$errorlabel,$reg)) |
|
716 | + $errorlabel = pg_last_error($this->db); |
|
717 | + $errorcode = ''; |
|
718 | + if (preg_match('/: *([0-9P]+):/', $errorlabel, $reg)) |
|
719 | 719 | { |
720 | - $errorcode=$reg[1]; |
|
720 | + $errorcode = $reg[1]; |
|
721 | 721 | if (isset($errorcode_map[$errorcode])) |
722 | 722 | { |
723 | 723 | return $errorcode_map[$errorcode]; |
724 | 724 | } |
725 | 725 | } |
726 | - $errno=$errorcode?$errorcode:$errorlabel; |
|
727 | - return ($errno?'DB_ERROR_'.$errno:'0'); |
|
726 | + $errno = $errorcode ? $errorcode : $errorlabel; |
|
727 | + return ($errno ? 'DB_ERROR_'.$errno : '0'); |
|
728 | 728 | } |
729 | 729 | // '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => 'DB_ERROR_NOSUCHTABLE', |
730 | 730 | // '/table [\"\'].*[\"\'] does not exist/' => 'DB_ERROR_NOSUCHTABLE', |
@@ -753,17 +753,17 @@ discard block |
||
753 | 753 | * @param string $fieldid Field name |
754 | 754 | * @return string Id of row |
755 | 755 | */ |
756 | - function last_insert_id($tab,$fieldid='rowid') |
|
756 | + function last_insert_id($tab, $fieldid = 'rowid') |
|
757 | 757 | { |
758 | 758 | //$result = pg_query($this->db,"SELECT MAX(".$fieldid.") FROM ".$tab); |
759 | - $result = pg_query($this->db,"SELECT currval('".$tab."_".$fieldid."_seq')"); |
|
760 | - if (! $result) |
|
759 | + $result = pg_query($this->db, "SELECT currval('".$tab."_".$fieldid."_seq')"); |
|
760 | + if (!$result) |
|
761 | 761 | { |
762 | 762 | print pg_last_error($this->db); |
763 | 763 | exit; |
764 | 764 | } |
765 | 765 | //$nbre = pg_num_rows($result); |
766 | - $row = pg_fetch_result($result,0,0); |
|
766 | + $row = pg_fetch_result($result, 0, 0); |
|
767 | 767 | return $row; |
768 | 768 | } |
769 | 769 | |
@@ -775,18 +775,18 @@ discard block |
||
775 | 775 | * @param int $withQuotes Return string with quotes |
776 | 776 | * @return string XXX(field) or XXX('value') or field or 'value' |
777 | 777 | */ |
778 | - function encrypt($fieldorvalue, $withQuotes=0) |
|
778 | + function encrypt($fieldorvalue, $withQuotes = 0) |
|
779 | 779 | { |
780 | 780 | global $conf; |
781 | 781 | |
782 | 782 | // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
783 | - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
783 | + $cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0); |
|
784 | 784 | |
785 | 785 | //Encryption key |
786 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
786 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : ''); |
|
787 | 787 | |
788 | 788 | $return = $fieldorvalue; |
789 | - return ($withQuotes?"'":"").$this->escape($return).($withQuotes?"'":""); |
|
789 | + return ($withQuotes ? "'" : "").$this->escape($return).($withQuotes ? "'" : ""); |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | |
@@ -801,10 +801,10 @@ discard block |
||
801 | 801 | global $conf; |
802 | 802 | |
803 | 803 | // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
804 | - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
804 | + $cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0); |
|
805 | 805 | |
806 | 806 | //Encryption key |
807 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
807 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : ''); |
|
808 | 808 | |
809 | 809 | $return = $value; |
810 | 810 | return $return; |
@@ -834,17 +834,17 @@ discard block |
||
834 | 834 | * @param string $owner Username of database owner |
835 | 835 | * @return false|resource resource defined if OK, null if KO |
836 | 836 | */ |
837 | - function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
837 | + function DDLCreateDb($database, $charset = '', $collation = '', $owner = '') |
|
838 | 838 | { |
839 | - if (empty($charset)) $charset=$this->forcecharset; |
|
840 | - if (empty($collation)) $collation=$this->forcecollate; |
|
839 | + if (empty($charset)) $charset = $this->forcecharset; |
|
840 | + if (empty($collation)) $collation = $this->forcecollate; |
|
841 | 841 | |
842 | 842 | // Test charset match LC_TYPE (pgsql error otherwise) |
843 | 843 | //print $charset.' '.setlocale(LC_CTYPE,'0'); exit; |
844 | 844 | |
845 | - $sql='CREATE DATABASE "'.$database.'" OWNER "'.$owner.'" ENCODING \''.$charset.'\''; |
|
846 | - dol_syslog($sql,LOG_DEBUG); |
|
847 | - $ret=$this->query($sql); |
|
845 | + $sql = 'CREATE DATABASE "'.$database.'" OWNER "'.$owner.'" ENCODING \''.$charset.'\''; |
|
846 | + dol_syslog($sql, LOG_DEBUG); |
|
847 | + $ret = $this->query($sql); |
|
848 | 848 | return $ret; |
849 | 849 | } |
850 | 850 | |
@@ -855,16 +855,16 @@ discard block |
||
855 | 855 | * @param string $table Name of table filter ('xxx%') |
856 | 856 | * @return array List of tables in an array |
857 | 857 | */ |
858 | - function DDLListTables($database, $table='') |
|
858 | + function DDLListTables($database, $table = '') |
|
859 | 859 | { |
860 | - $listtables=array(); |
|
860 | + $listtables = array(); |
|
861 | 861 | |
862 | 862 | $like = ''; |
863 | 863 | if ($table) $like = " AND table_name LIKE '".$table."'"; |
864 | 864 | $result = pg_query($this->db, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'".$like." ORDER BY table_name"); |
865 | 865 | if ($result) |
866 | 866 | { |
867 | - while($row = $this->fetch_row($result)) |
|
867 | + while ($row = $this->fetch_row($result)) |
|
868 | 868 | { |
869 | 869 | $listtables[] = $row[0]; |
870 | 870 | } |
@@ -881,29 +881,29 @@ discard block |
||
881 | 881 | */ |
882 | 882 | function DDLInfoTable($table) |
883 | 883 | { |
884 | - $infotables=array(); |
|
885 | - |
|
886 | - $sql="SELECT "; |
|
887 | - $sql.=" infcol.column_name as \"Column\","; |
|
888 | - $sql.=" CASE WHEN infcol.character_maximum_length IS NOT NULL THEN infcol.udt_name || '('||infcol.character_maximum_length||')'"; |
|
889 | - $sql.=" ELSE infcol.udt_name"; |
|
890 | - $sql.=" END as \"Type\","; |
|
891 | - $sql.=" infcol.collation_name as \"Collation\","; |
|
892 | - $sql.=" infcol.is_nullable as \"Null\","; |
|
893 | - $sql.=" '' as \"Key\","; |
|
894 | - $sql.=" infcol.column_default as \"Default\","; |
|
895 | - $sql.=" '' as \"Extra\","; |
|
896 | - $sql.=" '' as \"Privileges\""; |
|
897 | - $sql.=" FROM information_schema.columns infcol"; |
|
898 | - $sql.=" WHERE table_schema='public' "; |
|
899 | - $sql.=" AND table_name='".$table."'"; |
|
900 | - $sql.=" ORDER BY ordinal_position;"; |
|
901 | - |
|
902 | - dol_syslog($sql,LOG_DEBUG); |
|
884 | + $infotables = array(); |
|
885 | + |
|
886 | + $sql = "SELECT "; |
|
887 | + $sql .= " infcol.column_name as \"Column\","; |
|
888 | + $sql .= " CASE WHEN infcol.character_maximum_length IS NOT NULL THEN infcol.udt_name || '('||infcol.character_maximum_length||')'"; |
|
889 | + $sql .= " ELSE infcol.udt_name"; |
|
890 | + $sql .= " END as \"Type\","; |
|
891 | + $sql .= " infcol.collation_name as \"Collation\","; |
|
892 | + $sql .= " infcol.is_nullable as \"Null\","; |
|
893 | + $sql .= " '' as \"Key\","; |
|
894 | + $sql .= " infcol.column_default as \"Default\","; |
|
895 | + $sql .= " '' as \"Extra\","; |
|
896 | + $sql .= " '' as \"Privileges\""; |
|
897 | + $sql .= " FROM information_schema.columns infcol"; |
|
898 | + $sql .= " WHERE table_schema='public' "; |
|
899 | + $sql .= " AND table_name='".$table."'"; |
|
900 | + $sql .= " ORDER BY ordinal_position;"; |
|
901 | + |
|
902 | + dol_syslog($sql, LOG_DEBUG); |
|
903 | 903 | $result = $this->query($sql); |
904 | 904 | if ($result) |
905 | 905 | { |
906 | - while($row = $this->fetch_row($result)) |
|
906 | + while ($row = $this->fetch_row($result)) |
|
907 | 907 | { |
908 | 908 | $infotables[] = $row; |
909 | 909 | } |
@@ -924,68 +924,68 @@ discard block |
||
924 | 924 | * @param array $keys Tableau des champs cles noms => valeur |
925 | 925 | * @return int <0 if KO, >=0 if OK |
926 | 926 | */ |
927 | - function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
927 | + function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null) |
|
928 | 928 | { |
929 | 929 | // FIXME: $fulltext_keys parameter is unused |
930 | 930 | |
931 | 931 | // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
932 | 932 | // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
933 | 933 | $sql = "create table ".$table."("; |
934 | - $i=0; |
|
935 | - foreach($fields as $field_name => $field_desc) |
|
934 | + $i = 0; |
|
935 | + foreach ($fields as $field_name => $field_desc) |
|
936 | 936 | { |
937 | 937 | $sqlfields[$i] = $field_name." "; |
938 | 938 | $sqlfields[$i] .= $field_desc['type']; |
939 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
939 | + if (preg_match("/^[^\s]/i", $field_desc['value'])) |
|
940 | 940 | $sqlfields[$i] .= "(".$field_desc['value'].")"; |
941 | - else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
941 | + else if (preg_match("/^[^\s]/i", $field_desc['attribute'])) |
|
942 | 942 | $sqlfields[$i] .= " ".$field_desc['attribute']; |
943 | - else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
943 | + else if (preg_match("/^[^\s]/i", $field_desc['default'])) |
|
944 | 944 | { |
945 | - if(preg_match("/null/i",$field_desc['default'])) |
|
945 | + if (preg_match("/null/i", $field_desc['default'])) |
|
946 | 946 | $sqlfields[$i] .= " default ".$field_desc['default']; |
947 | 947 | else |
948 | 948 | $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
949 | 949 | } |
950 | - else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
950 | + else if (preg_match("/^[^\s]/i", $field_desc['null'])) |
|
951 | 951 | $sqlfields[$i] .= " ".$field_desc['null']; |
952 | 952 | |
953 | - else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
953 | + else if (preg_match("/^[^\s]/i", $field_desc['extra'])) |
|
954 | 954 | $sqlfields[$i] .= " ".$field_desc['extra']; |
955 | 955 | $i++; |
956 | 956 | } |
957 | - if($primary_key != "") |
|
957 | + if ($primary_key != "") |
|
958 | 958 | $pk = "primary key(".$primary_key.")"; |
959 | 959 | |
960 | - if(is_array($unique_keys)) |
|
960 | + if (is_array($unique_keys)) |
|
961 | 961 | { |
962 | 962 | $i = 0; |
963 | - foreach($unique_keys as $key => $value) |
|
963 | + foreach ($unique_keys as $key => $value) |
|
964 | 964 | { |
965 | 965 | $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
966 | 966 | $i++; |
967 | 967 | } |
968 | 968 | } |
969 | - if(is_array($keys)) |
|
969 | + if (is_array($keys)) |
|
970 | 970 | { |
971 | 971 | $i = 0; |
972 | - foreach($keys as $key => $value) |
|
972 | + foreach ($keys as $key => $value) |
|
973 | 973 | { |
974 | 974 | $sqlk[$i] = "KEY ".$key." (".$value.")"; |
975 | 975 | $i++; |
976 | 976 | } |
977 | 977 | } |
978 | - $sql .= implode(',',$sqlfields); |
|
979 | - if($primary_key != "") |
|
978 | + $sql .= implode(',', $sqlfields); |
|
979 | + if ($primary_key != "") |
|
980 | 980 | $sql .= ",".$pk; |
981 | - if(is_array($unique_keys)) |
|
982 | - $sql .= ",".implode(',',$sqluq); |
|
983 | - if(is_array($keys)) |
|
984 | - $sql .= ",".implode(',',$sqlk); |
|
985 | - $sql .=") type=".$type; |
|
986 | - |
|
987 | - dol_syslog($sql,LOG_DEBUG); |
|
988 | - if(! $this->query($sql)) |
|
981 | + if (is_array($unique_keys)) |
|
982 | + $sql .= ",".implode(',', $sqluq); |
|
983 | + if (is_array($keys)) |
|
984 | + $sql .= ",".implode(',', $sqlk); |
|
985 | + $sql .= ") type=".$type; |
|
986 | + |
|
987 | + dol_syslog($sql, LOG_DEBUG); |
|
988 | + if (!$this->query($sql)) |
|
989 | 989 | return -1; |
990 | 990 | else |
991 | 991 | return 1; |
@@ -1000,14 +1000,14 @@ discard block |
||
1000 | 1000 | * @param string $dolibarr_main_db_name Database name where user must be granted |
1001 | 1001 | * @return int <0 if KO, >=0 if OK |
1002 | 1002 | */ |
1003 | - function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
1003 | + function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name) |
|
1004 | 1004 | { |
1005 | 1005 | // Note: using ' on user does not works with pgsql |
1006 | 1006 | $sql = "CREATE USER ".$this->escape($dolibarr_main_db_user)." with password '".$this->escape($dolibarr_main_db_pass)."'"; |
1007 | 1007 | |
1008 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
1009 | - $resql=$this->query($sql); |
|
1010 | - if (! $resql) |
|
1008 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
1009 | + $resql = $this->query($sql); |
|
1010 | + if (!$resql) |
|
1011 | 1011 | { |
1012 | 1012 | return -1; |
1013 | 1013 | } |
@@ -1022,13 +1022,13 @@ discard block |
||
1022 | 1022 | * @param string $field Optionnel : Name of field if we want description of field |
1023 | 1023 | * @return false|resource Resultset x (x->attname) |
1024 | 1024 | */ |
1025 | - function DDLDescTable($table,$field="") |
|
1025 | + function DDLDescTable($table, $field = "") |
|
1026 | 1026 | { |
1027 | - $sql ="SELECT attname FROM pg_attribute, pg_type WHERE typname = '".$table."' AND attrelid = typrelid"; |
|
1028 | - $sql.=" AND attname NOT IN ('cmin', 'cmax', 'ctid', 'oid', 'tableoid', 'xmin', 'xmax')"; |
|
1029 | - if ($field) $sql.= " AND attname = '".$field."'"; |
|
1027 | + $sql = "SELECT attname FROM pg_attribute, pg_type WHERE typname = '".$table."' AND attrelid = typrelid"; |
|
1028 | + $sql .= " AND attname NOT IN ('cmin', 'cmax', 'ctid', 'oid', 'tableoid', 'xmin', 'xmax')"; |
|
1029 | + if ($field) $sql .= " AND attname = '".$field."'"; |
|
1030 | 1030 | |
1031 | - dol_syslog($sql,LOG_DEBUG); |
|
1031 | + dol_syslog($sql, LOG_DEBUG); |
|
1032 | 1032 | $this->_results = $this->query($sql); |
1033 | 1033 | return $this->_results; |
1034 | 1034 | } |
@@ -1042,32 +1042,32 @@ discard block |
||
1042 | 1042 | * @param string $field_position Optionnel ex.: "after champtruc" |
1043 | 1043 | * @return int <0 if KO, >0 if OK |
1044 | 1044 | */ |
1045 | - function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
1045 | + function DDLAddField($table, $field_name, $field_desc, $field_position = "") |
|
1046 | 1046 | { |
1047 | 1047 | // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
1048 | 1048 | // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
1049 | - $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
1049 | + $sql = "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
1050 | 1050 | $sql .= $field_desc['type']; |
1051 | - if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
1052 | - if (! in_array($field_desc['type'],array('int','date','datetime'))) |
|
1051 | + if (preg_match("/^[^\s]/i", $field_desc['value'])) |
|
1052 | + if (!in_array($field_desc['type'], array('int', 'date', 'datetime'))) |
|
1053 | 1053 | { |
1054 | - $sql.= "(".$field_desc['value'].")"; |
|
1054 | + $sql .= "(".$field_desc['value'].")"; |
|
1055 | 1055 | } |
1056 | - if (preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
1056 | + if (preg_match("/^[^\s]/i", $field_desc['attribute'])) |
|
1057 | 1057 | $sql .= " ".$field_desc['attribute']; |
1058 | - if (preg_match("/^[^\s]/i",$field_desc['null'])) |
|
1058 | + if (preg_match("/^[^\s]/i", $field_desc['null'])) |
|
1059 | 1059 | $sql .= " ".$field_desc['null']; |
1060 | - if (preg_match("/^[^\s]/i",$field_desc['default'])) |
|
1061 | - if (preg_match("/null/i",$field_desc['default'])) |
|
1060 | + if (preg_match("/^[^\s]/i", $field_desc['default'])) |
|
1061 | + if (preg_match("/null/i", $field_desc['default'])) |
|
1062 | 1062 | $sql .= " default ".$field_desc['default']; |
1063 | 1063 | else |
1064 | 1064 | $sql .= " default '".$field_desc['default']."'"; |
1065 | - if (preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
1065 | + if (preg_match("/^[^\s]/i", $field_desc['extra'])) |
|
1066 | 1066 | $sql .= " ".$field_desc['extra']; |
1067 | 1067 | $sql .= " ".$field_position; |
1068 | 1068 | |
1069 | - dol_syslog($sql,LOG_DEBUG); |
|
1070 | - if(! $this -> query($sql)) |
|
1069 | + dol_syslog($sql, LOG_DEBUG); |
|
1070 | + if (!$this -> query($sql)) |
|
1071 | 1071 | return -1; |
1072 | 1072 | return 1; |
1073 | 1073 | } |
@@ -1080,12 +1080,12 @@ discard block |
||
1080 | 1080 | * @param string $field_desc Array with description of field format |
1081 | 1081 | * @return int <0 if KO, >0 if OK |
1082 | 1082 | */ |
1083 | - function DDLUpdateField($table,$field_name,$field_desc) |
|
1083 | + function DDLUpdateField($table, $field_name, $field_desc) |
|
1084 | 1084 | { |
1085 | 1085 | $sql = "ALTER TABLE ".$table; |
1086 | 1086 | $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
1087 | 1087 | if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
1088 | - $sql.="(".$field_desc['value'].")"; |
|
1088 | + $sql .= "(".$field_desc['value'].")"; |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') |
@@ -1093,24 +1093,24 @@ discard block |
||
1093 | 1093 | // We will try to change format of column to NOT NULL. To be sure the ALTER works, we try to update fields that are NULL |
1094 | 1094 | if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
1095 | 1095 | { |
1096 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
1096 | + $sqlbis = "UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
1097 | 1097 | $this->query($sqlbis); |
1098 | 1098 | } |
1099 | 1099 | elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
1100 | 1100 | { |
1101 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
1101 | + $sqlbis = "UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
1102 | 1102 | $this->query($sqlbis); |
1103 | 1103 | } |
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | if ($field_desc['default'] != '') |
1107 | 1107 | { |
1108 | - if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']); |
|
1109 | - elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
1108 | + if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql .= " DEFAULT ".$this->escape($field_desc['default']); |
|
1109 | + elseif ($field_desc['type'] == 'text') $sql .= " DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
1110 | 1110 | } |
1111 | 1111 | |
1112 | - dol_syslog($sql,LOG_DEBUG); |
|
1113 | - if (! $this->query($sql)) |
|
1112 | + dol_syslog($sql, LOG_DEBUG); |
|
1113 | + if (!$this->query($sql)) |
|
1114 | 1114 | return -1; |
1115 | 1115 | return 1; |
1116 | 1116 | } |
@@ -1122,13 +1122,13 @@ discard block |
||
1122 | 1122 | * @param string $field_name Name of field to drop |
1123 | 1123 | * @return int <0 if KO, >0 if OK |
1124 | 1124 | */ |
1125 | - function DDLDropField($table,$field_name) |
|
1125 | + function DDLDropField($table, $field_name) |
|
1126 | 1126 | { |
1127 | - $sql= "ALTER TABLE ".$table." DROP COLUMN ".$field_name; |
|
1128 | - dol_syslog($sql,LOG_DEBUG); |
|
1129 | - if (! $this->query($sql)) |
|
1127 | + $sql = "ALTER TABLE ".$table." DROP COLUMN ".$field_name; |
|
1128 | + dol_syslog($sql, LOG_DEBUG); |
|
1129 | + if (!$this->query($sql)) |
|
1130 | 1130 | { |
1131 | - $this->error=$this->lasterror(); |
|
1131 | + $this->error = $this->lasterror(); |
|
1132 | 1132 | return -1; |
1133 | 1133 | } |
1134 | 1134 | return 1; |
@@ -1141,10 +1141,10 @@ discard block |
||
1141 | 1141 | */ |
1142 | 1142 | function getDefaultCharacterSetDatabase() |
1143 | 1143 | { |
1144 | - $resql=$this->query('SHOW SERVER_ENCODING'); |
|
1144 | + $resql = $this->query('SHOW SERVER_ENCODING'); |
|
1145 | 1145 | if ($resql) |
1146 | 1146 | { |
1147 | - $liste=$this->fetch_array($resql); |
|
1147 | + $liste = $this->fetch_array($resql); |
|
1148 | 1148 | return $liste['server_encoding']; |
1149 | 1149 | } |
1150 | 1150 | else return ''; |
@@ -1157,7 +1157,7 @@ discard block |
||
1157 | 1157 | */ |
1158 | 1158 | function getListOfCharacterSet() |
1159 | 1159 | { |
1160 | - $resql=$this->query('SHOW SERVER_ENCODING'); |
|
1160 | + $resql = $this->query('SHOW SERVER_ENCODING'); |
|
1161 | 1161 | $liste = array(); |
1162 | 1162 | if ($resql) |
1163 | 1163 | { |
@@ -1182,10 +1182,10 @@ discard block |
||
1182 | 1182 | */ |
1183 | 1183 | function getDefaultCollationDatabase() |
1184 | 1184 | { |
1185 | - $resql=$this->query('SHOW LC_COLLATE'); |
|
1185 | + $resql = $this->query('SHOW LC_COLLATE'); |
|
1186 | 1186 | if ($resql) |
1187 | 1187 | { |
1188 | - $liste=$this->fetch_array($resql); |
|
1188 | + $liste = $this->fetch_array($resql); |
|
1189 | 1189 | return $liste['lc_collate']; |
1190 | 1190 | } |
1191 | 1191 | else return ''; |
@@ -1198,12 +1198,12 @@ discard block |
||
1198 | 1198 | */ |
1199 | 1199 | function getListOfCollation() |
1200 | 1200 | { |
1201 | - $resql=$this->query('SHOW LC_COLLATE'); |
|
1201 | + $resql = $this->query('SHOW LC_COLLATE'); |
|
1202 | 1202 | $liste = array(); |
1203 | 1203 | if ($resql) |
1204 | 1204 | { |
1205 | 1205 | $i = 0; |
1206 | - while ($obj = $this->fetch_object($resql) ) |
|
1206 | + while ($obj = $this->fetch_object($resql)) |
|
1207 | 1207 | { |
1208 | 1208 | $liste[$i]['collation'] = $obj->lc_collate; |
1209 | 1209 | $i++; |
@@ -1222,21 +1222,21 @@ discard block |
||
1222 | 1222 | */ |
1223 | 1223 | function getPathOfDump() |
1224 | 1224 | { |
1225 | - $fullpathofdump='/pathtopgdump/pg_dump'; |
|
1225 | + $fullpathofdump = '/pathtopgdump/pg_dump'; |
|
1226 | 1226 | |
1227 | 1227 | if (file_exists('/usr/bin/pg_dump')) |
1228 | 1228 | { |
1229 | - $fullpathofdump='/usr/bin/pg_dump'; |
|
1229 | + $fullpathofdump = '/usr/bin/pg_dump'; |
|
1230 | 1230 | } |
1231 | 1231 | else |
1232 | 1232 | { |
1233 | 1233 | // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
1234 | - $resql=$this->query('SHOW data_directory'); |
|
1234 | + $resql = $this->query('SHOW data_directory'); |
|
1235 | 1235 | if ($resql) |
1236 | 1236 | { |
1237 | - $liste=$this->fetch_array($resql); |
|
1238 | - $basedir=$liste['data_directory']; |
|
1239 | - $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/pg_dump'; |
|
1237 | + $liste = $this->fetch_array($resql); |
|
1238 | + $basedir = $liste['data_directory']; |
|
1239 | + $fullpathofdump = preg_replace('/data$/', 'bin', $basedir).'/pg_dump'; |
|
1240 | 1240 | } |
1241 | 1241 | } |
1242 | 1242 | |
@@ -1251,23 +1251,23 @@ discard block |
||
1251 | 1251 | function getPathOfRestore() |
1252 | 1252 | { |
1253 | 1253 | //$tool='pg_restore'; |
1254 | - $tool='psql'; |
|
1254 | + $tool = 'psql'; |
|
1255 | 1255 | |
1256 | - $fullpathofdump='/pathtopgrestore/'.$tool; |
|
1256 | + $fullpathofdump = '/pathtopgrestore/'.$tool; |
|
1257 | 1257 | |
1258 | 1258 | if (file_exists('/usr/bin/'.$tool)) |
1259 | 1259 | { |
1260 | - $fullpathofdump='/usr/bin/'.$tool; |
|
1260 | + $fullpathofdump = '/usr/bin/'.$tool; |
|
1261 | 1261 | } |
1262 | 1262 | else |
1263 | 1263 | { |
1264 | 1264 | // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
1265 | - $resql=$this->query('SHOW data_directory'); |
|
1265 | + $resql = $this->query('SHOW data_directory'); |
|
1266 | 1266 | if ($resql) |
1267 | 1267 | { |
1268 | - $liste=$this->fetch_array($resql); |
|
1269 | - $basedir=$liste['data_directory']; |
|
1270 | - $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/'.$tool; |
|
1268 | + $liste = $this->fetch_array($resql); |
|
1269 | + $basedir = $liste['data_directory']; |
|
1270 | + $fullpathofdump = preg_replace('/data$/', 'bin', $basedir).'/'.$tool; |
|
1271 | 1271 | } |
1272 | 1272 | } |
1273 | 1273 | |
@@ -1280,16 +1280,16 @@ discard block |
||
1280 | 1280 | * @param string $filter Filter list on a particular value |
1281 | 1281 | * @return array Array of key-values (key=>value) |
1282 | 1282 | */ |
1283 | - function getServerParametersValues($filter='') |
|
1283 | + function getServerParametersValues($filter = '') |
|
1284 | 1284 | { |
1285 | - $result=array(); |
|
1285 | + $result = array(); |
|
1286 | 1286 | |
1287 | - $resql='select name,setting from pg_settings'; |
|
1288 | - if ($filter) $resql.=" WHERE name = '".$this->escape($filter)."'"; |
|
1289 | - $resql=$this->query($resql); |
|
1287 | + $resql = 'select name,setting from pg_settings'; |
|
1288 | + if ($filter) $resql .= " WHERE name = '".$this->escape($filter)."'"; |
|
1289 | + $resql = $this->query($resql); |
|
1290 | 1290 | if ($resql) |
1291 | 1291 | { |
1292 | - while ($obj=$this->fetch_object($resql)) $result[$obj->name]=$obj->setting; |
|
1292 | + while ($obj = $this->fetch_object($resql)) $result[$obj->name] = $obj->setting; |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | return $result; |
@@ -1301,7 +1301,7 @@ discard block |
||
1301 | 1301 | * @param string $filter Filter list on a particular value |
1302 | 1302 | * @return array Array of key-values (key=>value) |
1303 | 1303 | */ |
1304 | - function getServerStatusValues($filter='') |
|
1304 | + function getServerStatusValues($filter = '') |
|
1305 | 1305 | { |
1306 | 1306 | /* This is to return current running requests. |
1307 | 1307 | $sql='SELECT datname,procpid,current_query FROM pg_stat_activity ORDER BY procpid'; |
@@ -1449,7 +1449,7 @@ |
||
1449 | 1449 | * |
1450 | 1450 | * @param int $daynr ??? |
1451 | 1451 | * @param bool $sunday_first_day_of_week ??? |
1452 | - * @return int |
|
1452 | + * @return double |
|
1453 | 1453 | */ |
1454 | 1454 | private static function calc_weekday($daynr, $sunday_first_day_of_week) { |
1455 | 1455 | $ret = floor(($daynr + 5 + ($sunday_first_day_of_week ? 1 : 0)) % 7); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * \brief Class file to manage Dolibarr database access for a SQLite database |
26 | 26 | */ |
27 | 27 | |
28 | -require_once DOL_DOCUMENT_ROOT .'/core/db/DoliDB.class.php'; |
|
28 | +require_once DOL_DOCUMENT_ROOT.'/core/db/DoliDB.class.php'; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Class to manage Dolibarr database access for a SQLite database |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | class DoliDBSqlite3 extends DoliDB |
34 | 34 | { |
35 | 35 | //! Database type |
36 | - public $type='sqlite3'; |
|
36 | + public $type = 'sqlite3'; |
|
37 | 37 | //! Database label |
38 | - const LABEL='Sqlite3'; |
|
38 | + const LABEL = 'Sqlite3'; |
|
39 | 39 | //! Version min database |
40 | - const VERSIONMIN='3.0.0'; |
|
40 | + const VERSIONMIN = '3.0.0'; |
|
41 | 41 | /** @var SQLite3Result Resultset of last query */ |
42 | 42 | private $_results; |
43 | 43 | |
44 | - const WEEK_MONDAY_FIRST=1; |
|
44 | + const WEEK_MONDAY_FIRST = 1; |
|
45 | 45 | const WEEK_YEAR = 2; |
46 | - const WEEK_FIRST_WEEKDAY=4; |
|
46 | + const WEEK_FIRST_WEEKDAY = 4; |
|
47 | 47 | |
48 | 48 | |
49 | 49 | /** |
@@ -57,19 +57,19 @@ discard block |
||
57 | 57 | * @param string $name Nom de la database |
58 | 58 | * @param int $port Port of database server |
59 | 59 | */ |
60 | - function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
60 | + function __construct($type, $host, $user, $pass, $name = '', $port = 0) |
|
61 | 61 | { |
62 | 62 | global $conf; |
63 | 63 | |
64 | 64 | // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
65 | - if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set; |
|
66 | - if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
|
65 | + if (!empty($conf->db->character_set)) $this->forcecharset = $conf->db->character_set; |
|
66 | + if (!empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate = $conf->db->dolibarr_main_db_collation; |
|
67 | 67 | |
68 | - $this->database_user=$user; |
|
69 | - $this->database_host=$host; |
|
70 | - $this->database_port=$port; |
|
68 | + $this->database_user = $user; |
|
69 | + $this->database_host = $host; |
|
70 | + $this->database_port = $port; |
|
71 | 71 | |
72 | - $this->transaction_opened=0; |
|
72 | + $this->transaction_opened = 0; |
|
73 | 73 | |
74 | 74 | //print "Name DB: $host,$user,$pass,$name<br>"; |
75 | 75 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $this->database_selected = false; |
121 | 121 | $this->database_name = ''; |
122 | 122 | //$this->error=sqlite_connect_error(); |
123 | - dol_syslog(get_class($this)."::DoliDBSqlite3 : Error Connect ".$this->error,LOG_ERR); |
|
123 | + dol_syslog(get_class($this)."::DoliDBSqlite3 : Error Connect ".$this->error, LOG_ERR); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | return $this->ok; |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
135 | 135 | * @return string SQL request line converted |
136 | 136 | */ |
137 | - static function convertSQLFromMysql($line,$type='ddl') |
|
137 | + static function convertSQLFromMysql($line, $type = 'ddl') |
|
138 | 138 | { |
139 | 139 | // Removed empty line if this is a comment line for SVN tagging |
140 | - if (preg_match('/^--\s\$Id/i',$line)) { |
|
140 | + if (preg_match('/^--\s\$Id/i', $line)) { |
|
141 | 141 | return ''; |
142 | 142 | } |
143 | 143 | // Return line if this is a comment |
144 | - if (preg_match('/^#/i',$line) || preg_match('/^$/i',$line) || preg_match('/^--/i',$line)) |
|
144 | + if (preg_match('/^#/i', $line) || preg_match('/^$/i', $line) || preg_match('/^--/i', $line)) |
|
145 | 145 | { |
146 | 146 | return $line; |
147 | 147 | } |
@@ -149,114 +149,114 @@ discard block |
||
149 | 149 | { |
150 | 150 | if ($type == 'auto') |
151 | 151 | { |
152 | - if (preg_match('/ALTER TABLE/i',$line)) $type='dml'; |
|
153 | - else if (preg_match('/CREATE TABLE/i',$line)) $type='dml'; |
|
154 | - else if (preg_match('/DROP TABLE/i',$line)) $type='dml'; |
|
152 | + if (preg_match('/ALTER TABLE/i', $line)) $type = 'dml'; |
|
153 | + else if (preg_match('/CREATE TABLE/i', $line)) $type = 'dml'; |
|
154 | + else if (preg_match('/DROP TABLE/i', $line)) $type = 'dml'; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | if ($type == 'dml') |
158 | 158 | { |
159 | - $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
159 | + $line = preg_replace('/\s/', ' ', $line); // Replace tabulation with space |
|
160 | 160 | |
161 | 161 | // we are inside create table statement so lets process datatypes |
162 | - if (preg_match('/(ISAM|innodb)/i',$line)) { // end of create table sequence |
|
163 | - $line=preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb);/i',');',$line); |
|
164 | - $line=preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb);/i',');',$line); |
|
165 | - $line=preg_replace('/,$/','',$line); |
|
162 | + if (preg_match('/(ISAM|innodb)/i', $line)) { // end of create table sequence |
|
163 | + $line = preg_replace('/\)[\s\t]*type[\s\t]*=[\s\t]*(MyISAM|innodb);/i', ');', $line); |
|
164 | + $line = preg_replace('/\)[\s\t]*engine[\s\t]*=[\s\t]*(MyISAM|innodb);/i', ');', $line); |
|
165 | + $line = preg_replace('/,$/', '', $line); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // Process case: "CREATE TABLE llx_mytable(rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,code..." |
169 | - if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i',$line,$reg)) { |
|
170 | - $newline=preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i','\\1 \\2 integer PRIMARY KEY AUTOINCREMENT',$line); |
|
169 | + if (preg_match('/[\s\t\(]*(\w*)[\s\t]+int.*auto_increment/i', $line, $reg)) { |
|
170 | + $newline = preg_replace('/([\s\t\(]*)([a-zA-Z_0-9]*)[\s\t]+int.*auto_increment[^,]*/i', '\\1 \\2 integer PRIMARY KEY AUTOINCREMENT', $line); |
|
171 | 171 | //$line = "-- ".$line." replaced by --\n".$newline; |
172 | - $line=$newline; |
|
172 | + $line = $newline; |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | // tinyint type conversion |
176 | - $line=str_replace('tinyint','smallint',$line); |
|
176 | + $line = str_replace('tinyint', 'smallint', $line); |
|
177 | 177 | |
178 | 178 | // nuke unsigned |
179 | - $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
179 | + $line = preg_replace('/(int\w+|smallint)\s+unsigned/i', '\\1', $line); |
|
180 | 180 | |
181 | 181 | // blob -> text |
182 | - $line=preg_replace('/\w*blob/i','text',$line); |
|
182 | + $line = preg_replace('/\w*blob/i', 'text', $line); |
|
183 | 183 | |
184 | 184 | // tinytext/mediumtext -> text |
185 | - $line=preg_replace('/tinytext/i','text',$line); |
|
186 | - $line=preg_replace('/mediumtext/i','text',$line); |
|
185 | + $line = preg_replace('/tinytext/i', 'text', $line); |
|
186 | + $line = preg_replace('/mediumtext/i', 'text', $line); |
|
187 | 187 | |
188 | 188 | // change not null datetime field to null valid ones |
189 | 189 | // (to support remapping of "zero time" to null |
190 | - $line=preg_replace('/datetime not null/i','datetime',$line); |
|
191 | - $line=preg_replace('/datetime/i','timestamp',$line); |
|
190 | + $line = preg_replace('/datetime not null/i', 'datetime', $line); |
|
191 | + $line = preg_replace('/datetime/i', 'timestamp', $line); |
|
192 | 192 | |
193 | 193 | // double -> numeric |
194 | - $line=preg_replace('/^double/i','numeric',$line); |
|
195 | - $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
194 | + $line = preg_replace('/^double/i', 'numeric', $line); |
|
195 | + $line = preg_replace('/(\s*)double/i', '\\1numeric', $line); |
|
196 | 196 | // float -> numeric |
197 | - $line=preg_replace('/^float/i','numeric',$line); |
|
198 | - $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
197 | + $line = preg_replace('/^float/i', 'numeric', $line); |
|
198 | + $line = preg_replace('/(\s*)float/i', '\\1numeric', $line); |
|
199 | 199 | |
200 | 200 | // unique index(field1,field2) |
201 | - if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
201 | + if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i', $line)) |
|
202 | 202 | { |
203 | - $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
203 | + $line = preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i', 'UNIQUE\(\\1\)', $line); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // We remove end of requests "AFTER fieldxxx" |
207 | - $line=preg_replace('/AFTER [a-z0-9_]+/i','',$line); |
|
207 | + $line = preg_replace('/AFTER [a-z0-9_]+/i', '', $line); |
|
208 | 208 | |
209 | 209 | // We remove start of requests "ALTER TABLE tablexxx" if this is a DROP INDEX |
210 | - $line=preg_replace('/ALTER TABLE [a-z0-9_]+ DROP INDEX/i','DROP INDEX',$line); |
|
210 | + $line = preg_replace('/ALTER TABLE [a-z0-9_]+ DROP INDEX/i', 'DROP INDEX', $line); |
|
211 | 211 | |
212 | 212 | // Translate order to rename fields |
213 | - if (preg_match('/ALTER TABLE ([a-z0-9_]+) CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i',$line,$reg)) |
|
213 | + if (preg_match('/ALTER TABLE ([a-z0-9_]+) CHANGE(?: COLUMN)? ([a-z0-9_]+) ([a-z0-9_]+)(.*)$/i', $line, $reg)) |
|
214 | 214 | { |
215 | 215 | $line = "-- ".$line." replaced by --\n"; |
216 | - $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
216 | + $line .= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | // Translate order to modify field format |
220 | - if (preg_match('/ALTER TABLE ([a-z0-9_]+) MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg)) |
|
220 | + if (preg_match('/ALTER TABLE ([a-z0-9_]+) MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i', $line, $reg)) |
|
221 | 221 | { |
222 | 222 | $line = "-- ".$line." replaced by --\n"; |
223 | - $newreg3=$reg[3]; |
|
224 | - $newreg3=preg_replace('/ DEFAULT NULL/i','',$newreg3); |
|
225 | - $newreg3=preg_replace('/ NOT NULL/i','',$newreg3); |
|
226 | - $newreg3=preg_replace('/ NULL/i','',$newreg3); |
|
227 | - $newreg3=preg_replace('/ DEFAULT 0/i','',$newreg3); |
|
228 | - $newreg3=preg_replace('/ DEFAULT \'[0-9a-zA-Z_@]*\'/i','',$newreg3); |
|
229 | - $line.= "ALTER TABLE ".$reg[1]." ALTER COLUMN ".$reg[2]." TYPE ".$newreg3; |
|
223 | + $newreg3 = $reg[3]; |
|
224 | + $newreg3 = preg_replace('/ DEFAULT NULL/i', '', $newreg3); |
|
225 | + $newreg3 = preg_replace('/ NOT NULL/i', '', $newreg3); |
|
226 | + $newreg3 = preg_replace('/ NULL/i', '', $newreg3); |
|
227 | + $newreg3 = preg_replace('/ DEFAULT 0/i', '', $newreg3); |
|
228 | + $newreg3 = preg_replace('/ DEFAULT \'[0-9a-zA-Z_@]*\'/i', '', $newreg3); |
|
229 | + $line .= "ALTER TABLE ".$reg[1]." ALTER COLUMN ".$reg[2]." TYPE ".$newreg3; |
|
230 | 230 | // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
231 | 231 | } |
232 | 232 | |
233 | 233 | // alter table add primary key (field1, field2 ...) -> We create a unique index instead as dynamic creation of primary key is not supported |
234 | 234 | // ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY pk_dolibarr_modules (numero, entity); |
235 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i',$line,$reg)) |
|
235 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+PRIMARY\s+KEY\s*(.*)\s*\((.*)$/i', $line, $reg)) |
|
236 | 236 | { |
237 | 237 | $line = "-- ".$line." replaced by --\n"; |
238 | - $line.= "CREATE UNIQUE INDEX ".$reg[2]." ON ".$reg[1]."(".$reg[3]; |
|
238 | + $line .= "CREATE UNIQUE INDEX ".$reg[2]." ON ".$reg[1]."(".$reg[3]; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | // Translate order to drop foreign keys |
242 | 242 | // ALTER TABLE llx_dolibarr_modules DROP FOREIGN KEY fk_xxx; |
243 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i',$line,$reg)) |
|
243 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*DROP\s+FOREIGN\s+KEY\s*(.*)$/i', $line, $reg)) |
|
244 | 244 | { |
245 | 245 | $line = "-- ".$line." replaced by --\n"; |
246 | - $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
246 | + $line .= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | // alter table add [unique] [index] (field1, field2 ...) |
250 | 250 | // ALTER TABLE llx_accountingaccount ADD INDEX idx_accountingaccount_fk_pcg_version (fk_pcg_version) |
251 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i',$line,$reg)) |
|
251 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+(UNIQUE INDEX|INDEX|UNIQUE)\s+(.*)\s*\(([\w,\s]+)\)/i', $line, $reg)) |
|
252 | 252 | { |
253 | - $fieldlist=$reg[4]; |
|
254 | - $idxname=$reg[3]; |
|
255 | - $tablename=$reg[1]; |
|
253 | + $fieldlist = $reg[4]; |
|
254 | + $idxname = $reg[3]; |
|
255 | + $tablename = $reg[1]; |
|
256 | 256 | $line = "-- ".$line." replaced by --\n"; |
257 | - $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
257 | + $line .= "CREATE ".(preg_match('/UNIQUE/', $reg[2]) ? 'UNIQUE ' : '')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
258 | 258 | } |
259 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i',$line, $reg)) { |
|
259 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i', $line, $reg)) { |
|
260 | 260 | // Pour l'instant les contraintes ne sont pas créées |
261 | 261 | dol_syslog(get_class().'::query line emptied'); |
262 | 262 | $line = 'SELECT 0;'; |
@@ -270,24 +270,24 @@ discard block |
||
270 | 270 | |
271 | 271 | // Delete using criteria on other table must not declare twice the deleted table |
272 | 272 | // DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable |
273 | - if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg)) |
|
273 | + if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i', $line, $reg)) |
|
274 | 274 | { |
275 | 275 | if ($reg[1] == $reg[2]) // If same table, we remove second one |
276 | 276 | { |
277 | - $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line); |
|
277 | + $line = preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i', 'DELETE FROM \\1 USING \\3', $line); |
|
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | 281 | // Remove () in the tables in FROM if one table |
282 | - $line=preg_replace('/FROM\s*\((([a-z_]+)\s+as\s+([a-z_]+)\s*)\)/i','FROM \\1',$line); |
|
282 | + $line = preg_replace('/FROM\s*\((([a-z_]+)\s+as\s+([a-z_]+)\s*)\)/i', 'FROM \\1', $line); |
|
283 | 283 | //print $line."\n"; |
284 | 284 | |
285 | 285 | // Remove () in the tables in FROM if two table |
286 | - $line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2',$line); |
|
286 | + $line = preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2', $line); |
|
287 | 287 | //print $line."\n"; |
288 | 288 | |
289 | 289 | // Remove () in the tables in FROM if two table |
290 | - $line=preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i','FROM \\1, \\2, \\3',$line); |
|
290 | + $line = preg_replace('/FROM\s*\(([a-z_]+\s+as\s+[a-z_]+)\s*,\s*([a-z_]+\s+as\s+[a-z_]+\s*),\s*([a-z_]+\s+as\s+[a-z_]+\s*)\)/i', 'FROM \\1, \\2, \\3', $line); |
|
291 | 291 | //print $line."\n"; |
292 | 292 | |
293 | 293 | //print "type=".$type." newline=".$line."<br>\n"; |
@@ -322,14 +322,14 @@ discard block |
||
322 | 322 | * @return SQLite3 Database access handler |
323 | 323 | * @see close |
324 | 324 | */ |
325 | - function connect($host, $login, $passwd, $name, $port=0) |
|
325 | + function connect($host, $login, $passwd, $name, $port = 0) |
|
326 | 326 | { |
327 | 327 | global $main_data_dir; |
328 | 328 | |
329 | - dol_syslog(get_class($this)."::connect name=".$name,LOG_DEBUG); |
|
329 | + dol_syslog(get_class($this)."::connect name=".$name, LOG_DEBUG); |
|
330 | 330 | |
331 | - $dir=$main_data_dir; |
|
332 | - if (empty($dir)) $dir=DOL_DATA_ROOT; |
|
331 | + $dir = $main_data_dir; |
|
332 | + if (empty($dir)) $dir = DOL_DATA_ROOT; |
|
333 | 333 | // With sqlite, port must be in connect parameters |
334 | 334 | //if (! $newport) $newport=3306; |
335 | 335 | $database_name = $dir.'/database_'.$name.'.sdb'; |
@@ -339,9 +339,9 @@ discard block |
||
339 | 339 | $this->db = new SQLite3($database_name); |
340 | 340 | //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
341 | 341 | } |
342 | - catch(Exception $e) |
|
342 | + catch (Exception $e) |
|
343 | 343 | { |
344 | - $this->error= self::LABEL.' '.$e->getMessage().' current dir='.$database_name; |
|
344 | + $this->error = self::LABEL.' '.$e->getMessage().' current dir='.$database_name; |
|
345 | 345 | return ''; |
346 | 346 | } |
347 | 347 | |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | */ |
358 | 358 | function getVersion() |
359 | 359 | { |
360 | - $tmp=$this->db->version(); |
|
360 | + $tmp = $this->db->version(); |
|
361 | 361 | return $tmp['versionString']; |
362 | 362 | } |
363 | 363 | |
@@ -382,10 +382,10 @@ discard block |
||
382 | 382 | { |
383 | 383 | if ($this->db) |
384 | 384 | { |
385 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
386 | - $this->connected=false; |
|
385 | + if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened, LOG_ERR); |
|
386 | + $this->connected = false; |
|
387 | 387 | $this->db->close(); |
388 | - unset($this->db); // Clean this->db |
|
388 | + unset($this->db); // Clean this->db |
|
389 | 389 | return true; |
390 | 390 | } |
391 | 391 | return false; |
@@ -400,14 +400,14 @@ discard block |
||
400 | 400 | * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
401 | 401 | * @return SQLite3Result Resultset of answer |
402 | 402 | */ |
403 | - function query($query,$usesavepoint=0,$type='auto') |
|
403 | + function query($query, $usesavepoint = 0, $type = 'auto') |
|
404 | 404 | { |
405 | - $ret=null; |
|
405 | + $ret = null; |
|
406 | 406 | $query = trim($query); |
407 | 407 | $this->error = 0; |
408 | 408 | |
409 | 409 | // Convert MySQL syntax to SQLite syntax |
410 | - if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i',$query, $reg)) { |
|
410 | + if (preg_match('/ALTER\s+TABLE\s*(.*)\s*ADD\s+CONSTRAINT\s+(.*)\s*FOREIGN\s+KEY\s*\(([\w,\s]+)\)\s*REFERENCES\s+(\w+)\s*\(([\w,\s]+)\)/i', $query, $reg)) { |
|
411 | 411 | // Ajout d'une clef étrangère à la table |
412 | 412 | // procédure de remplacement de la table pour ajouter la contrainte |
413 | 413 | // Exemple : ALTER TABLE llx_adherent ADD CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid) |
@@ -415,19 +415,19 @@ discard block |
||
415 | 415 | $foreignFields = $reg[5]; |
416 | 416 | $foreignTable = $reg[4]; |
417 | 417 | $localfields = $reg[3]; |
418 | - $constraintname=trim($reg[2]); |
|
419 | - $tablename=trim($reg[1]); |
|
418 | + $constraintname = trim($reg[2]); |
|
419 | + $tablename = trim($reg[1]); |
|
420 | 420 | |
421 | - $descTable = $this->db->querySingle("SELECT sql FROM sqlite_master WHERE name='" . $tablename . "'"); |
|
421 | + $descTable = $this->db->querySingle("SELECT sql FROM sqlite_master WHERE name='".$tablename."'"); |
|
422 | 422 | |
423 | 423 | // 1- Renommer la table avec un nom temporaire |
424 | - $this->query('ALTER TABLE ' . $tablename . ' RENAME TO tmp_' . $tablename); |
|
424 | + $this->query('ALTER TABLE '.$tablename.' RENAME TO tmp_'.$tablename); |
|
425 | 425 | |
426 | 426 | // 2- Recréer la table avec la contrainte ajoutée |
427 | 427 | |
428 | 428 | // on bricole la requete pour ajouter la contrainte |
429 | 429 | $descTable = substr($descTable, 0, strlen($descTable) - 1); |
430 | - $descTable .= ", CONSTRAINT " . $constraintname . " FOREIGN KEY (" . $localfields . ") REFERENCES " .$foreignTable . "(" . $foreignFields . ")"; |
|
430 | + $descTable .= ", CONSTRAINT ".$constraintname." FOREIGN KEY (".$localfields.") REFERENCES ".$foreignTable."(".$foreignFields.")"; |
|
431 | 431 | |
432 | 432 | // fermeture de l'instruction |
433 | 433 | $descTable .= ')'; |
@@ -436,16 +436,16 @@ discard block |
||
436 | 436 | $this->query($descTable); |
437 | 437 | |
438 | 438 | // 3- Transférer les données |
439 | - $this->query('INSERT INTO ' . $tablename . ' SELECT * FROM tmp_' . $tablename); |
|
439 | + $this->query('INSERT INTO '.$tablename.' SELECT * FROM tmp_'.$tablename); |
|
440 | 440 | |
441 | 441 | // 4- Supprimer la table temporaire |
442 | - $this->query('DROP TABLE tmp_' . $tablename); |
|
442 | + $this->query('DROP TABLE tmp_'.$tablename); |
|
443 | 443 | |
444 | 444 | // dummy statement |
445 | - $query="SELECT 0"; |
|
445 | + $query = "SELECT 0"; |
|
446 | 446 | |
447 | 447 | } else { |
448 | - $query=$this->convertSQLFromMysql($query,$type); |
|
448 | + $query = $this->convertSQLFromMysql($query, $type); |
|
449 | 449 | } |
450 | 450 | //print "After convertSQLFromMysql:\n".$query."<br>\n"; |
451 | 451 | |
@@ -454,20 +454,20 @@ discard block |
||
454 | 454 | // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
455 | 455 | try { |
456 | 456 | //$ret = $this->db->exec($query); |
457 | - $ret = $this->db->query($query); // $ret is a Sqlite3Result |
|
457 | + $ret = $this->db->query($query); // $ret is a Sqlite3Result |
|
458 | 458 | if ($ret) { |
459 | 459 | $ret->queryString = $query; |
460 | 460 | } |
461 | 461 | } |
462 | - catch(Exception $e) |
|
462 | + catch (Exception $e) |
|
463 | 463 | { |
464 | - $this->error=$this->db->lastErrorMsg(); |
|
464 | + $this->error = $this->db->lastErrorMsg(); |
|
465 | 465 | } |
466 | 466 | |
467 | - if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
467 | + if (!preg_match("/^COMMIT/i", $query) && !preg_match("/^ROLLBACK/i", $query)) |
|
468 | 468 | { |
469 | 469 | // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
470 | - if (! is_object($ret) || $this->error) |
|
470 | + if (!is_object($ret) || $this->error) |
|
471 | 471 | { |
472 | 472 | $this->lastqueryerror = $query; |
473 | 473 | $this->lasterror = $this->error(); |
@@ -477,13 +477,13 @@ discard block |
||
477 | 477 | |
478 | 478 | $errormsg = get_class($this)."::query SQL Error message: ".$this->lasterror; |
479 | 479 | |
480 | - if (preg_match('/[0-9]/',$this->lasterrno)) { |
|
480 | + if (preg_match('/[0-9]/', $this->lasterrno)) { |
|
481 | 481 | $errormsg .= ' ('.$this->lasterrno.')'; |
482 | 482 | } |
483 | 483 | |
484 | 484 | dol_syslog($errormsg, LOG_ERR); |
485 | 485 | } |
486 | - $this->lastquery=$query; |
|
486 | + $this->lastquery = $query; |
|
487 | 487 | $this->_results = $ret; |
488 | 488 | } |
489 | 489 | |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | function fetch_object($resultset) |
500 | 500 | { |
501 | 501 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
502 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
502 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
503 | 503 | //return $resultset->fetch(PDO::FETCH_OBJ); |
504 | 504 | $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
505 | 505 | if ($ret) { |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | function fetch_array($resultset) |
519 | 519 | { |
520 | 520 | // If resultset not provided, we take the last used by connexion |
521 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
521 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
522 | 522 | //return $resultset->fetch(PDO::FETCH_ASSOC); |
523 | 523 | $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
524 | 524 | return $ret; |
@@ -533,9 +533,9 @@ discard block |
||
533 | 533 | function fetch_row($resultset) |
534 | 534 | { |
535 | 535 | // If resultset not provided, we take the last used by connexion |
536 | - if (! is_bool($resultset)) |
|
536 | + if (!is_bool($resultset)) |
|
537 | 537 | { |
538 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
538 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
539 | 539 | return $resultset->fetchArray(SQLITE3_NUM); |
540 | 540 | } |
541 | 541 | else |
@@ -557,9 +557,9 @@ discard block |
||
557 | 557 | // FIXME: SQLite3Result does not have a queryString member |
558 | 558 | |
559 | 559 | // If resultset not provided, we take the last used by connexion |
560 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
560 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
561 | 561 | if (preg_match("/^SELECT/i", $resultset->queryString)) { |
562 | - return $this->db->querySingle("SELECT count(*) FROM (" . $resultset->queryString . ") q"); |
|
562 | + return $this->db->querySingle("SELECT count(*) FROM (".$resultset->queryString.") q"); |
|
563 | 563 | } |
564 | 564 | return 0; |
565 | 565 | } |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | // FIXME: SQLite3Result does not have a queryString member |
577 | 577 | |
578 | 578 | // If resultset not provided, we take the last used by connexion |
579 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
579 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
580 | 580 | if (preg_match("/^SELECT/i", $resultset->queryString)) { |
581 | 581 | return $this->num_rows($resultset); |
582 | 582 | } |
@@ -592,10 +592,10 @@ discard block |
||
592 | 592 | * @param SQLite3Result $resultset Curseur de la requete voulue |
593 | 593 | * @return void |
594 | 594 | */ |
595 | - function free($resultset=null) |
|
595 | + function free($resultset = null) |
|
596 | 596 | { |
597 | 597 | // If resultset not provided, we take the last used by connexion |
598 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
598 | + if (!is_object($resultset)) { $resultset = $this->_results; } |
|
599 | 599 | // Si resultset en est un, on libere la memoire |
600 | 600 | if ($resultset && is_object($resultset)) $resultset->finalize(); |
601 | 601 | } |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | */ |
619 | 619 | function errno() |
620 | 620 | { |
621 | - if (! $this->connected) { |
|
621 | + if (!$this->connected) { |
|
622 | 622 | // Si il y a eu echec de connexion, $this->db n'est pas valide. |
623 | 623 | return 'DB_ERROR_FAILED_TO_CONNECT'; |
624 | 624 | } |
@@ -656,23 +656,23 @@ discard block |
||
656 | 656 | { |
657 | 657 | return $errorcode_map[$this->db->errorCode()]; |
658 | 658 | }*/ |
659 | - $errno=$this->db->lastErrorCode(); |
|
660 | - if ($errno=='HY000' || $errno == 0) |
|
659 | + $errno = $this->db->lastErrorCode(); |
|
660 | + if ($errno == 'HY000' || $errno == 0) |
|
661 | 661 | { |
662 | - if (preg_match('/table.*already exists/i',$this->error)) return 'DB_ERROR_TABLE_ALREADY_EXISTS'; |
|
663 | - elseif (preg_match('/index.*already exists/i',$this->error)) return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'; |
|
664 | - elseif (preg_match('/syntax error/i',$this->error)) return 'DB_ERROR_SYNTAX'; |
|
662 | + if (preg_match('/table.*already exists/i', $this->error)) return 'DB_ERROR_TABLE_ALREADY_EXISTS'; |
|
663 | + elseif (preg_match('/index.*already exists/i', $this->error)) return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'; |
|
664 | + elseif (preg_match('/syntax error/i', $this->error)) return 'DB_ERROR_SYNTAX'; |
|
665 | 665 | } |
666 | - if ($errno=='23000') |
|
666 | + if ($errno == '23000') |
|
667 | 667 | { |
668 | - if (preg_match('/column.* not unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
669 | - elseif (preg_match('/PRIMARY KEY must be unique/i',$this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
668 | + if (preg_match('/column.* not unique/i', $this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
669 | + elseif (preg_match('/PRIMARY KEY must be unique/i', $this->error)) return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
670 | 670 | } |
671 | 671 | if ($errno > 1) { |
672 | 672 | // TODO Voir la liste des messages d'erreur |
673 | 673 | } |
674 | 674 | |
675 | - return ($errno?'DB_ERROR_'.$errno:'0'); |
|
675 | + return ($errno ? 'DB_ERROR_'.$errno : '0'); |
|
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | */ |
684 | 684 | function error() |
685 | 685 | { |
686 | - if (! $this->connected) { |
|
686 | + if (!$this->connected) { |
|
687 | 687 | // Si il y a eu echec de connexion, $this->db n'est pas valide pour sqlite_error. |
688 | 688 | return 'Not connected. Check setup parameters in conf/conf.php file and your sqlite version'; |
689 | 689 | } |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | * @param string $fieldid Field name |
700 | 700 | * @return int Id of row |
701 | 701 | */ |
702 | - function last_insert_id($tab,$fieldid='rowid') |
|
702 | + function last_insert_id($tab, $fieldid = 'rowid') |
|
703 | 703 | { |
704 | 704 | return $this->db->lastInsertRowId(); |
705 | 705 | } |
@@ -712,17 +712,17 @@ discard block |
||
712 | 712 | * @param int $withQuotes Return string with quotes |
713 | 713 | * @return string XXX(field) or XXX('value') or field or 'value' |
714 | 714 | */ |
715 | - function encrypt($fieldorvalue, $withQuotes=0) |
|
715 | + function encrypt($fieldorvalue, $withQuotes = 0) |
|
716 | 716 | { |
717 | 717 | global $conf; |
718 | 718 | |
719 | 719 | // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
720 | - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
720 | + $cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0); |
|
721 | 721 | |
722 | 722 | //Encryption key |
723 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
723 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : ''); |
|
724 | 724 | |
725 | - $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
725 | + $return = ($withQuotes ? "'" : "").$this->escape($fieldorvalue).($withQuotes ? "'" : ""); |
|
726 | 726 | |
727 | 727 | if ($cryptType && !empty($cryptKey)) |
728 | 728 | { |
@@ -750,10 +750,10 @@ discard block |
||
750 | 750 | global $conf; |
751 | 751 | |
752 | 752 | // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
753 | - $cryptType = ($conf->db->dolibarr_main_db_encryption?$conf->db->dolibarr_main_db_encryption:0); |
|
753 | + $cryptType = ($conf->db->dolibarr_main_db_encryption ? $conf->db->dolibarr_main_db_encryption : 0); |
|
754 | 754 | |
755 | 755 | //Encryption key |
756 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
756 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey) ? $conf->db->dolibarr_main_db_cryptkey : ''); |
|
757 | 757 | |
758 | 758 | $return = $value; |
759 | 759 | |
@@ -795,23 +795,23 @@ discard block |
||
795 | 795 | * @param string $owner Username of database owner |
796 | 796 | * @return SQLite3Result resource defined if OK, null if KO |
797 | 797 | */ |
798 | - function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
798 | + function DDLCreateDb($database, $charset = '', $collation = '', $owner = '') |
|
799 | 799 | { |
800 | - if (empty($charset)) $charset=$this->forcecharset; |
|
801 | - if (empty($collation)) $collation=$this->forcecollate; |
|
800 | + if (empty($charset)) $charset = $this->forcecharset; |
|
801 | + if (empty($collation)) $collation = $this->forcecollate; |
|
802 | 802 | |
803 | 803 | // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
804 | 804 | $sql = 'CREATE DATABASE '.$database; |
805 | - $sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation; |
|
805 | + $sql .= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation; |
|
806 | 806 | |
807 | - dol_syslog($sql,LOG_DEBUG); |
|
808 | - $ret=$this->query($sql); |
|
809 | - if (! $ret) |
|
807 | + dol_syslog($sql, LOG_DEBUG); |
|
808 | + $ret = $this->query($sql); |
|
809 | + if (!$ret) |
|
810 | 810 | { |
811 | 811 | // We try again for compatibility with Mysql < 4.1.1 |
812 | 812 | $sql = 'CREATE DATABASE '.$database; |
813 | - $ret=$this->query($sql); |
|
814 | - dol_syslog($sql,LOG_DEBUG); |
|
813 | + $ret = $this->query($sql); |
|
814 | + dol_syslog($sql, LOG_DEBUG); |
|
815 | 815 | } |
816 | 816 | return $ret; |
817 | 817 | } |
@@ -823,18 +823,18 @@ discard block |
||
823 | 823 | * @param string $table Name of table filter ('xxx%') |
824 | 824 | * @return array List of tables in an array |
825 | 825 | */ |
826 | - function DDLListTables($database, $table='') |
|
826 | + function DDLListTables($database, $table = '') |
|
827 | 827 | { |
828 | - $listtables=array(); |
|
828 | + $listtables = array(); |
|
829 | 829 | |
830 | 830 | $like = ''; |
831 | 831 | if ($table) $like = "LIKE '".$table."'"; |
832 | - $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
832 | + $sql = "SHOW TABLES FROM ".$database." ".$like.";"; |
|
833 | 833 | //print $sql; |
834 | 834 | $result = $this->query($sql); |
835 | 835 | if ($result) |
836 | 836 | { |
837 | - while($row = $this->fetch_row($result)) |
|
837 | + while ($row = $this->fetch_row($result)) |
|
838 | 838 | { |
839 | 839 | $listtables[] = $row[0]; |
840 | 840 | } |
@@ -851,15 +851,15 @@ discard block |
||
851 | 851 | */ |
852 | 852 | function DDLInfoTable($table) |
853 | 853 | { |
854 | - $infotables=array(); |
|
854 | + $infotables = array(); |
|
855 | 855 | |
856 | - $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
856 | + $sql = "SHOW FULL COLUMNS FROM ".$table.";"; |
|
857 | 857 | |
858 | - dol_syslog($sql,LOG_DEBUG); |
|
858 | + dol_syslog($sql, LOG_DEBUG); |
|
859 | 859 | $result = $this->query($sql); |
860 | 860 | if ($result) |
861 | 861 | { |
862 | - while($row = $this->fetch_row($result)) |
|
862 | + while ($row = $this->fetch_row($result)) |
|
863 | 863 | { |
864 | 864 | $infotables[] = $row; |
865 | 865 | } |
@@ -879,68 +879,68 @@ discard block |
||
879 | 879 | * @param array $keys Tableau des champs cles noms => valeur |
880 | 880 | * @return int <0 if KO, >=0 if OK |
881 | 881 | */ |
882 | - function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
882 | + function DDLCreateTable($table, $fields, $primary_key, $type, $unique_keys = null, $fulltext_keys = null, $keys = null) |
|
883 | 883 | { |
884 | 884 | // FIXME: $fulltext_keys parameter is unused |
885 | 885 | |
886 | 886 | // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
887 | 887 | // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
888 | 888 | $sql = "create table ".$table."("; |
889 | - $i=0; |
|
890 | - foreach($fields as $field_name => $field_desc) |
|
889 | + $i = 0; |
|
890 | + foreach ($fields as $field_name => $field_desc) |
|
891 | 891 | { |
892 | 892 | $sqlfields[$i] = $field_name." "; |
893 | 893 | $sqlfields[$i] .= $field_desc['type']; |
894 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
894 | + if (preg_match("/^[^\s]/i", $field_desc['value'])) |
|
895 | 895 | $sqlfields[$i] .= "(".$field_desc['value'].")"; |
896 | - else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
896 | + else if (preg_match("/^[^\s]/i", $field_desc['attribute'])) |
|
897 | 897 | $sqlfields[$i] .= " ".$field_desc['attribute']; |
898 | - else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
898 | + else if (preg_match("/^[^\s]/i", $field_desc['default'])) |
|
899 | 899 | { |
900 | - if(preg_match("/null/i",$field_desc['default'])) |
|
900 | + if (preg_match("/null/i", $field_desc['default'])) |
|
901 | 901 | $sqlfields[$i] .= " default ".$field_desc['default']; |
902 | 902 | else |
903 | 903 | $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
904 | 904 | } |
905 | - else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
905 | + else if (preg_match("/^[^\s]/i", $field_desc['null'])) |
|
906 | 906 | $sqlfields[$i] .= " ".$field_desc['null']; |
907 | 907 | |
908 | - else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
908 | + else if (preg_match("/^[^\s]/i", $field_desc['extra'])) |
|
909 | 909 | $sqlfields[$i] .= " ".$field_desc['extra']; |
910 | 910 | $i++; |
911 | 911 | } |
912 | - if($primary_key != "") |
|
912 | + if ($primary_key != "") |
|
913 | 913 | $pk = "primary key(".$primary_key.")"; |
914 | 914 | |
915 | - if(is_array($unique_keys)) |
|
915 | + if (is_array($unique_keys)) |
|
916 | 916 | { |
917 | 917 | $i = 0; |
918 | - foreach($unique_keys as $key => $value) |
|
918 | + foreach ($unique_keys as $key => $value) |
|
919 | 919 | { |
920 | 920 | $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
921 | 921 | $i++; |
922 | 922 | } |
923 | 923 | } |
924 | - if(is_array($keys)) |
|
924 | + if (is_array($keys)) |
|
925 | 925 | { |
926 | 926 | $i = 0; |
927 | - foreach($keys as $key => $value) |
|
927 | + foreach ($keys as $key => $value) |
|
928 | 928 | { |
929 | 929 | $sqlk[$i] = "KEY ".$key." (".$value.")"; |
930 | 930 | $i++; |
931 | 931 | } |
932 | 932 | } |
933 | - $sql .= implode(',',$sqlfields); |
|
934 | - if($primary_key != "") |
|
933 | + $sql .= implode(',', $sqlfields); |
|
934 | + if ($primary_key != "") |
|
935 | 935 | $sql .= ",".$pk; |
936 | - if(is_array($unique_keys)) |
|
937 | - $sql .= ",".implode(',',$sqluq); |
|
938 | - if(is_array($keys)) |
|
939 | - $sql .= ",".implode(',',$sqlk); |
|
940 | - $sql .=") type=".$type; |
|
941 | - |
|
942 | - dol_syslog($sql,LOG_DEBUG); |
|
943 | - if(! $this -> query($sql)) |
|
936 | + if (is_array($unique_keys)) |
|
937 | + $sql .= ",".implode(',', $sqluq); |
|
938 | + if (is_array($keys)) |
|
939 | + $sql .= ",".implode(',', $sqlk); |
|
940 | + $sql .= ") type=".$type; |
|
941 | + |
|
942 | + dol_syslog($sql, LOG_DEBUG); |
|
943 | + if (!$this -> query($sql)) |
|
944 | 944 | return -1; |
945 | 945 | return 1; |
946 | 946 | } |
@@ -952,11 +952,11 @@ discard block |
||
952 | 952 | * @param string $field Optionnel : Name of field if we want description of field |
953 | 953 | * @return SQLite3Result Resource |
954 | 954 | */ |
955 | - function DDLDescTable($table,$field="") |
|
955 | + function DDLDescTable($table, $field = "") |
|
956 | 956 | { |
957 | - $sql="DESC ".$table." ".$field; |
|
957 | + $sql = "DESC ".$table." ".$field; |
|
958 | 958 | |
959 | - dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
959 | + dol_syslog(get_class($this)."::DDLDescTable ".$sql, LOG_DEBUG); |
|
960 | 960 | $this->_results = $this->query($sql); |
961 | 961 | return $this->_results; |
962 | 962 | } |
@@ -970,34 +970,34 @@ discard block |
||
970 | 970 | * @param string $field_position Optionnel ex.: "after champtruc" |
971 | 971 | * @return int <0 if KO, >0 if OK |
972 | 972 | */ |
973 | - function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
973 | + function DDLAddField($table, $field_name, $field_desc, $field_position = "") |
|
974 | 974 | { |
975 | 975 | // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
976 | 976 | // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
977 | - $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
978 | - $sql.= $field_desc['type']; |
|
979 | - if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
980 | - if (! in_array($field_desc['type'],array('date','datetime'))) |
|
977 | + $sql = "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
978 | + $sql .= $field_desc['type']; |
|
979 | + if (preg_match("/^[^\s]/i", $field_desc['value'])) |
|
980 | + if (!in_array($field_desc['type'], array('date', 'datetime'))) |
|
981 | 981 | { |
982 | - $sql.= "(".$field_desc['value'].")"; |
|
982 | + $sql .= "(".$field_desc['value'].")"; |
|
983 | 983 | } |
984 | - if(preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
985 | - $sql.= " ".$field_desc['attribute']; |
|
986 | - if(preg_match("/^[^\s]/i",$field_desc['null'])) |
|
987 | - $sql.= " ".$field_desc['null']; |
|
988 | - if(preg_match("/^[^\s]/i",$field_desc['default'])) |
|
984 | + if (preg_match("/^[^\s]/i", $field_desc['attribute'])) |
|
985 | + $sql .= " ".$field_desc['attribute']; |
|
986 | + if (preg_match("/^[^\s]/i", $field_desc['null'])) |
|
987 | + $sql .= " ".$field_desc['null']; |
|
988 | + if (preg_match("/^[^\s]/i", $field_desc['default'])) |
|
989 | 989 | { |
990 | - if(preg_match("/null/i",$field_desc['default'])) |
|
991 | - $sql.= " default ".$field_desc['default']; |
|
990 | + if (preg_match("/null/i", $field_desc['default'])) |
|
991 | + $sql .= " default ".$field_desc['default']; |
|
992 | 992 | else |
993 | - $sql.= " default '".$field_desc['default']."'"; |
|
993 | + $sql .= " default '".$field_desc['default']."'"; |
|
994 | 994 | } |
995 | - if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
996 | - $sql.= " ".$field_desc['extra']; |
|
997 | - $sql.= " ".$field_position; |
|
995 | + if (preg_match("/^[^\s]/i", $field_desc['extra'])) |
|
996 | + $sql .= " ".$field_desc['extra']; |
|
997 | + $sql .= " ".$field_position; |
|
998 | 998 | |
999 | - dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
1000 | - if(! $this->query($sql)) |
|
999 | + dol_syslog(get_class($this)."::DDLAddField ".$sql, LOG_DEBUG); |
|
1000 | + if (!$this->query($sql)) |
|
1001 | 1001 | { |
1002 | 1002 | return -1; |
1003 | 1003 | } |
@@ -1012,16 +1012,16 @@ discard block |
||
1012 | 1012 | * @param string $field_desc Array with description of field format |
1013 | 1013 | * @return int <0 if KO, >0 if OK |
1014 | 1014 | */ |
1015 | - function DDLUpdateField($table,$field_name,$field_desc) |
|
1015 | + function DDLUpdateField($table, $field_name, $field_desc) |
|
1016 | 1016 | { |
1017 | 1017 | $sql = "ALTER TABLE ".$table; |
1018 | 1018 | $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
1019 | 1019 | if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
1020 | - $sql.="(".$field_desc['value'].")"; |
|
1020 | + $sql .= "(".$field_desc['value'].")"; |
|
1021 | 1021 | } |
1022 | 1022 | |
1023 | - dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
1024 | - if (! $this->query($sql)) |
|
1023 | + dol_syslog(get_class($this)."::DDLUpdateField ".$sql, LOG_DEBUG); |
|
1024 | + if (!$this->query($sql)) |
|
1025 | 1025 | return -1; |
1026 | 1026 | return 1; |
1027 | 1027 | } |
@@ -1033,13 +1033,13 @@ discard block |
||
1033 | 1033 | * @param string $field_name Name of field to drop |
1034 | 1034 | * @return int <0 if KO, >0 if OK |
1035 | 1035 | */ |
1036 | - function DDLDropField($table,$field_name) |
|
1036 | + function DDLDropField($table, $field_name) |
|
1037 | 1037 | { |
1038 | - $sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
1039 | - dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG); |
|
1040 | - if (! $this->query($sql)) |
|
1038 | + $sql = "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
1039 | + dol_syslog(get_class($this)."::DDLDropField ".$sql, LOG_DEBUG); |
|
1040 | + if (!$this->query($sql)) |
|
1041 | 1041 | { |
1042 | - $this->error=$this->lasterror(); |
|
1042 | + $this->error = $this->lasterror(); |
|
1043 | 1043 | return -1; |
1044 | 1044 | } |
1045 | 1045 | return 1; |
@@ -1055,37 +1055,37 @@ discard block |
||
1055 | 1055 | * @param string $dolibarr_main_db_name Database name where user must be granted |
1056 | 1056 | * @return int <0 if KO, >=0 if OK |
1057 | 1057 | */ |
1058 | - function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
1058 | + function DDLCreateUser($dolibarr_main_db_host, $dolibarr_main_db_user, $dolibarr_main_db_pass, $dolibarr_main_db_name) |
|
1059 | 1059 | { |
1060 | 1060 | $sql = "INSERT INTO user "; |
1061 | - $sql.= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; |
|
1062 | - $sql.= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_user)."',password('".addslashes($dolibarr_main_db_pass)."')"; |
|
1063 | - $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; |
|
1061 | + $sql .= "(Host,User,password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; |
|
1062 | + $sql .= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_user)."',password('".addslashes($dolibarr_main_db_pass)."')"; |
|
1063 | + $sql .= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; |
|
1064 | 1064 | |
1065 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
1066 | - $resql=$this->query($sql); |
|
1067 | - if (! $resql) |
|
1065 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
1066 | + $resql = $this->query($sql); |
|
1067 | + if (!$resql) |
|
1068 | 1068 | { |
1069 | 1069 | return -1; |
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | $sql = "INSERT INTO db "; |
1073 | - $sql.= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; |
|
1074 | - $sql.= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_name)."','".addslashes($dolibarr_main_db_user)."'"; |
|
1075 | - $sql.= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; |
|
1073 | + $sql .= "(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Index_Priv,Alter_priv,Lock_tables_priv)"; |
|
1074 | + $sql .= " VALUES ('".$this->escape($dolibarr_main_db_host)."','".$this->escape($dolibarr_main_db_name)."','".addslashes($dolibarr_main_db_user)."'"; |
|
1075 | + $sql .= ",'Y','Y','Y','Y','Y','Y','Y','Y','Y')"; |
|
1076 | 1076 | |
1077 | 1077 | dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
1078 | - $resql=$this->query($sql); |
|
1079 | - if (! $resql) |
|
1078 | + $resql = $this->query($sql); |
|
1079 | + if (!$resql) |
|
1080 | 1080 | { |
1081 | 1081 | return -1; |
1082 | 1082 | } |
1083 | 1083 | |
1084 | - $sql="FLUSH Privileges"; |
|
1084 | + $sql = "FLUSH Privileges"; |
|
1085 | 1085 | |
1086 | 1086 | dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
1087 | - $resql=$this->query($sql); |
|
1088 | - if (! $resql) |
|
1087 | + $resql = $this->query($sql); |
|
1088 | + if (!$resql) |
|
1089 | 1089 | { |
1090 | 1090 | return -1; |
1091 | 1091 | } |
@@ -1110,7 +1110,7 @@ discard block |
||
1110 | 1110 | function getListOfCharacterSet() |
1111 | 1111 | { |
1112 | 1112 | $liste = array(); |
1113 | - $i=0; |
|
1113 | + $i = 0; |
|
1114 | 1114 | $liste[$i]['charset'] = 'UTF-8'; |
1115 | 1115 | $liste[$i]['description'] = 'UTF-8'; |
1116 | 1116 | return $liste; |
@@ -1134,7 +1134,7 @@ discard block |
||
1134 | 1134 | function getListOfCollation() |
1135 | 1135 | { |
1136 | 1136 | $liste = array(); |
1137 | - $i=0; |
|
1137 | + $i = 0; |
|
1138 | 1138 | $liste[$i]['charset'] = 'UTF-8'; |
1139 | 1139 | $liste[$i]['description'] = 'UTF-8'; |
1140 | 1140 | return $liste; |
@@ -1148,14 +1148,14 @@ discard block |
||
1148 | 1148 | function getPathOfDump() |
1149 | 1149 | { |
1150 | 1150 | // FIXME: not for SQLite |
1151 | - $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
1151 | + $fullpathofdump = '/pathtomysqldump/mysqldump'; |
|
1152 | 1152 | |
1153 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
1153 | + $resql = $this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
1154 | 1154 | if ($resql) |
1155 | 1155 | { |
1156 | - $liste=$this->fetch_array($resql); |
|
1157 | - $basedir=$liste['Value']; |
|
1158 | - $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
1156 | + $liste = $this->fetch_array($resql); |
|
1157 | + $basedir = $liste['Value']; |
|
1158 | + $fullpathofdump = $basedir.(preg_match('/\/$/', $basedir) ? '' : '/').'bin/mysqldump'; |
|
1159 | 1159 | } |
1160 | 1160 | return $fullpathofdump; |
1161 | 1161 | } |
@@ -1168,14 +1168,14 @@ discard block |
||
1168 | 1168 | function getPathOfRestore() |
1169 | 1169 | { |
1170 | 1170 | // FIXME: not for SQLite |
1171 | - $fullpathofimport='/pathtomysql/mysql'; |
|
1171 | + $fullpathofimport = '/pathtomysql/mysql'; |
|
1172 | 1172 | |
1173 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
1173 | + $resql = $this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
1174 | 1174 | if ($resql) |
1175 | 1175 | { |
1176 | - $liste=$this->fetch_array($resql); |
|
1177 | - $basedir=$liste['Value']; |
|
1178 | - $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
1176 | + $liste = $this->fetch_array($resql); |
|
1177 | + $basedir = $liste['Value']; |
|
1178 | + $fullpathofimport = $basedir.(preg_match('/\/$/', $basedir) ? '' : '/').'bin/mysql'; |
|
1179 | 1179 | } |
1180 | 1180 | return $fullpathofimport; |
1181 | 1181 | } |
@@ -1186,18 +1186,18 @@ discard block |
||
1186 | 1186 | * @param string $filter Filter list on a particular value |
1187 | 1187 | * @return array Array of key-values (key=>value) |
1188 | 1188 | */ |
1189 | - function getServerParametersValues($filter='') |
|
1189 | + function getServerParametersValues($filter = '') |
|
1190 | 1190 | { |
1191 | - $result=array(); |
|
1191 | + $result = array(); |
|
1192 | 1192 | static $pragmas; |
1193 | - if (! isset($pragmas)) { |
|
1193 | + if (!isset($pragmas)) { |
|
1194 | 1194 | // Définition de la liste des pragmas utilisés qui ne retournent qu'une seule valeur |
1195 | 1195 | // indépendante de la base de données. |
1196 | 1196 | // cf. http://www.sqlite.org/pragma.html |
1197 | 1197 | $pragmas = array( |
1198 | 1198 | 'application_id', 'auto_vacuum', 'automatic_index', 'busy_timeout', 'cache_size', |
1199 | 1199 | 'cache_spill', 'case_sensitive_like', 'checkpoint_fullsync', 'collation_list', |
1200 | - 'compile_options', 'data_version', /*'database_list',*/ |
|
1200 | + 'compile_options', 'data_version', /*'database_list',*/ |
|
1201 | 1201 | 'defer_foreign_keys', 'encoding', 'foreign_key_check', 'freelist_count', |
1202 | 1202 | 'full_column_names', 'fullsync', 'ingore_check_constraints', 'integrity_check', |
1203 | 1203 | 'journal_mode', 'journal_size_limit', 'legacy_file_format', 'locking_mode', |
@@ -1212,9 +1212,9 @@ discard block |
||
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // TODO prendre en compte le filtre |
1215 | - foreach($pragmas as $var) { |
|
1215 | + foreach ($pragmas as $var) { |
|
1216 | 1216 | $sql = "PRAGMA $var"; |
1217 | - $resql=$this->query($sql); |
|
1217 | + $resql = $this->query($sql); |
|
1218 | 1218 | if ($resql) |
1219 | 1219 | { |
1220 | 1220 | $obj = $this->fetch_row($resql); |
@@ -1235,9 +1235,9 @@ discard block |
||
1235 | 1235 | * @param string $filter Filter list on a particular value |
1236 | 1236 | * @return array Array of key-values (key=>value) |
1237 | 1237 | */ |
1238 | - function getServerStatusValues($filter='') |
|
1238 | + function getServerStatusValues($filter = '') |
|
1239 | 1239 | { |
1240 | - $result=array(); |
|
1240 | + $result = array(); |
|
1241 | 1241 | /* |
1242 | 1242 | $sql='SHOW STATUS'; |
1243 | 1243 | if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
@@ -1264,10 +1264,10 @@ discard block |
||
1264 | 1264 | { |
1265 | 1265 | if ($this->db) |
1266 | 1266 | { |
1267 | - $newname=preg_replace('/_/','',$name); |
|
1268 | - $localname = __CLASS__ . '::' . 'db' . $newname; |
|
1267 | + $newname = preg_replace('/_/', '', $name); |
|
1268 | + $localname = __CLASS__.'::'.'db'.$newname; |
|
1269 | 1269 | $reflectClass = new ReflectionClass(__CLASS__); |
1270 | - $reflectFunction = $reflectClass->getMethod('db' . $newname); |
|
1270 | + $reflectFunction = $reflectClass->getMethod('db'.$newname); |
|
1271 | 1271 | if ($arg_count < 0) { |
1272 | 1272 | $arg_count = $reflectFunction->getNumberOfParameters(); |
1273 | 1273 | } |
@@ -1289,7 +1289,7 @@ discard block |
||
1289 | 1289 | private static function calc_daynr($year, $month, $day) { |
1290 | 1290 | $y = $year; |
1291 | 1291 | if ($y == 0 && $month == 0) return 0; |
1292 | - $num = (365* $y + 31 * ($month - 1) + $day); |
|
1292 | + $num = (365 * $y + 31 * ($month - 1) + $day); |
|
1293 | 1293 | if ($month <= 2) { |
1294 | 1294 | $y--; } |
1295 | 1295 | else { |
@@ -1319,7 +1319,7 @@ discard block |
||
1319 | 1319 | */ |
1320 | 1320 | private static function calc_days_in_year($year) |
1321 | 1321 | { |
1322 | - return (($year & 3) == 0 && ($year%100 || ($year%400 == 0 && $year)) ? 366 : 365); |
|
1322 | + return (($year & 3) == 0 && ($year % 100 || ($year % 400 == 0 && $year)) ? 366 : 365); |
|
1323 | 1323 | } |
1324 | 1324 | |
1325 | 1325 | /** |
@@ -1333,42 +1333,42 @@ discard block |
||
1333 | 1333 | * @return string ??? |
1334 | 1334 | */ |
1335 | 1335 | private static function calc_week($year, $month, $day, $week_behaviour, &$calc_year) { |
1336 | - $daynr=self::calc_daynr($year,$month,$day); |
|
1337 | - $first_daynr=self::calc_daynr($year,1,1); |
|
1338 | - $monday_first= ($week_behaviour & self::WEEK_MONDAY_FIRST) ? 1 : 0; |
|
1339 | - $week_year= ($week_behaviour & self::WEEK_YEAR) ? 1 : 0; |
|
1340 | - $first_weekday= ($week_behaviour & self::WEEK_FIRST_WEEKDAY) ? 1 : 0; |
|
1336 | + $daynr = self::calc_daynr($year, $month, $day); |
|
1337 | + $first_daynr = self::calc_daynr($year, 1, 1); |
|
1338 | + $monday_first = ($week_behaviour & self::WEEK_MONDAY_FIRST) ? 1 : 0; |
|
1339 | + $week_year = ($week_behaviour & self::WEEK_YEAR) ? 1 : 0; |
|
1340 | + $first_weekday = ($week_behaviour & self::WEEK_FIRST_WEEKDAY) ? 1 : 0; |
|
1341 | 1341 | |
1342 | - $weekday=self::calc_weekday($first_daynr, !$monday_first); |
|
1343 | - $calc_year=$year; |
|
1342 | + $weekday = self::calc_weekday($first_daynr, !$monday_first); |
|
1343 | + $calc_year = $year; |
|
1344 | 1344 | |
1345 | - if ($month == 1 && $day <= 7-$weekday) |
|
1345 | + if ($month == 1 && $day <= 7 - $weekday) |
|
1346 | 1346 | { |
1347 | 1347 | if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4))) |
1348 | 1348 | return 0; |
1349 | - $week_year= 1; |
|
1349 | + $week_year = 1; |
|
1350 | 1350 | $calc_year--; |
1351 | - $first_daynr-= ($days=self::calc_days_in_year($calc_year)); |
|
1352 | - $weekday= ($weekday + 53*7- $days) % 7; |
|
1351 | + $first_daynr -= ($days = self::calc_days_in_year($calc_year)); |
|
1352 | + $weekday = ($weekday + 53 * 7 - $days) % 7; |
|
1353 | 1353 | } |
1354 | 1354 | |
1355 | 1355 | if (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)) { |
1356 | - $days= $daynr - ($first_daynr+ (7-$weekday)); |
|
1356 | + $days = $daynr - ($first_daynr + (7 - $weekday)); |
|
1357 | 1357 | } |
1358 | 1358 | else { |
1359 | - $days= $daynr - ($first_daynr - $weekday); |
|
1359 | + $days = $daynr - ($first_daynr - $weekday); |
|
1360 | 1360 | } |
1361 | 1361 | |
1362 | - if ($week_year && $days >= 52*7) |
|
1362 | + if ($week_year && $days >= 52 * 7) |
|
1363 | 1363 | { |
1364 | - $weekday= ($weekday + self::calc_days_in_year($calc_year)) % 7; |
|
1364 | + $weekday = ($weekday + self::calc_days_in_year($calc_year)) % 7; |
|
1365 | 1365 | if ((!$first_weekday && $weekday < 4) || ($first_weekday && $weekday == 0)) |
1366 | 1366 | { |
1367 | 1367 | $calc_year++; |
1368 | 1368 | return 1; |
1369 | 1369 | } |
1370 | 1370 | } |
1371 | - return floor($days/7+1); |
|
1371 | + return floor($days / 7 + 1); |
|
1372 | 1372 | } |
1373 | 1373 | |
1374 | 1374 | } |