@@ -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) |
@@ -31,21 +31,21 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | class DeplacementStats extends Stats |
| 33 | 33 | { |
| 34 | - public $table_element; |
|
| 34 | + public $table_element; |
|
| 35 | 35 | |
| 36 | - var $socid; |
|
| 37 | - var $userid; |
|
| 36 | + var $socid; |
|
| 37 | + var $userid; |
|
| 38 | 38 | |
| 39 | - var $from; |
|
| 40 | - var $field; |
|
| 41 | - var $where; |
|
| 39 | + var $from; |
|
| 40 | + var $field; |
|
| 41 | + var $where; |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Constructor |
| 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 mixed $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) |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | global $conf; |
| 54 | 54 | |
| 55 | 55 | $this->db = $db; |
| 56 | - $this->socid = $socid; |
|
| 57 | - $this->userid = $userid; |
|
| 56 | + $this->socid = $socid; |
|
| 57 | + $this->userid = $userid; |
|
| 58 | 58 | |
| 59 | 59 | $object=new Deplacement($this->db); |
| 60 | 60 | $this->from = MAIN_DB_PREFIX.$object->table_element; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $this->where.=" AND fk_soc = ".$this->socid; |
| 68 | 68 | } |
| 69 | 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; |
|
| 70 | + else if ($this->userid > 0) $this->where.=' AND fk_user = '.$this->userid; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $sql.= " WHERE YEAR(dated) = ".$year; |
| 101 | 101 | $sql.= " AND ".$this->where; |
| 102 | 102 | $sql.= " GROUP BY dm"; |
| 103 | - $sql.= $this->db->order('dm','DESC'); |
|
| 103 | + $sql.= $this->db->order('dm','DESC'); |
|
| 104 | 104 | |
| 105 | 105 | $res=$this->_getNbByMonth($year, $sql); |
| 106 | 106 | //var_dump($res);print '<br>'; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $sql.= " WHERE date_format(dated,'%Y') = '".$year."'"; |
| 142 | 142 | $sql.= " AND ".$this->where; |
| 143 | 143 | $sql.= " GROUP BY dm"; |
| 144 | - $sql.= $this->db->order('dm','DESC'); |
|
| 144 | + $sql.= $this->db->order('dm','DESC'); |
|
| 145 | 145 | |
| 146 | 146 | return $this->_getAverageByMonth($year, $sql); |
| 147 | 147 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | $sql.= " FROM ".$this->from; |
| 158 | 158 | $sql.= " WHERE ".$this->where; |
| 159 | 159 | $sql.= " GROUP BY year"; |
| 160 | - $sql.= $this->db->order('year','DESC'); |
|
| 160 | + $sql.= $this->db->order('year','DESC'); |
|
| 161 | 161 | |
| 162 | 162 | return $this->_getAllByYear($sql); |
| 163 | 163 | } |
@@ -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 | } |
@@ -66,8 +66,11 @@ |
||
| 66 | 66 | { |
| 67 | 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) { |
|
| 70 | + $this->where.=' AND fk_user IN ('.join(',',$this->userid).')'; |
|
| 71 | + } else if ($this->userid > 0) { |
|
| 72 | + $this->where.=' AND fk_user = '.$this->userid; |
|
| 73 | + } |
|
| 71 | 74 | } |
| 72 | 75 | |
| 73 | 76 | |
@@ -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 | */ |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public $table_element_line='contratdet'; |
| 46 | 46 | public $fk_element='fk_contrat'; |
| 47 | 47 | protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
| 48 | - public $picto='contract'; |
|
| 48 | + public $picto='contract'; |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * {@inheritdoc} |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | foreach($this->lines as $contratline) |
| 315 | 315 | { |
| 316 | 316 | // Close lines not already closed |
| 317 | - if ($contratline->statut != 5) |
|
| 318 | - { |
|
| 317 | + if ($contratline->statut != 5) |
|
| 318 | + { |
|
| 319 | 319 | $contratline->date_cloture=dol_now(); |
| 320 | 320 | $contratline->fk_user_cloture=$user->id; |
| 321 | 321 | $contratline->statut='5'; |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | $ok=false; |
| 326 | 326 | break; |
| 327 | 327 | } |
| 328 | - } |
|
| 328 | + } |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | if ($this->statut == 0) |
@@ -334,17 +334,17 @@ discard block |
||
| 334 | 334 | if ($result < 0) $ok=false; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - if ($ok) |
|
| 338 | - { |
|
| 339 | - $this->db->commit(); |
|
| 340 | - return 1; |
|
| 341 | - } |
|
| 342 | - else |
|
| 343 | - { |
|
| 344 | - dol_print_error($this->db,'Error in closeAll function'); |
|
| 345 | - $this->db->rollback(); |
|
| 346 | - return -1; |
|
| 347 | - } |
|
| 337 | + if ($ok) |
|
| 338 | + { |
|
| 339 | + $this->db->commit(); |
|
| 340 | + return 1; |
|
| 341 | + } |
|
| 342 | + else |
|
| 343 | + { |
|
| 344 | + dol_print_error($this->db,'Error in closeAll function'); |
|
| 345 | + $this->db->rollback(); |
|
| 346 | + return -1; |
|
| 347 | + } |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | * |
| 353 | 353 | * @param User $user Objet User |
| 354 | 354 | * @param string $force_number Reference to force on contract (not implemented yet) |
| 355 | - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers |
|
| 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 | 358 | function validate($user, $force_number='', $notrigger=0) |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | { |
| 383 | 383 | $num = $this->ref; |
| 384 | 384 | } |
| 385 | - $this->newref = $num; |
|
| 385 | + $this->newref = $num; |
|
| 386 | 386 | |
| 387 | 387 | if ($num) |
| 388 | 388 | { |
@@ -402,15 +402,15 @@ discard block |
||
| 402 | 402 | // Trigger calls |
| 403 | 403 | if (! $error && ! $notrigger) |
| 404 | 404 | { |
| 405 | - // Call trigger |
|
| 406 | - $result=$this->call_trigger('CONTRACT_VALIDATE',$user); |
|
| 407 | - if ($result < 0) { $error++; } |
|
| 408 | - // End call triggers |
|
| 405 | + // Call trigger |
|
| 406 | + $result=$this->call_trigger('CONTRACT_VALIDATE',$user); |
|
| 407 | + if ($result < 0) { $error++; } |
|
| 408 | + // End call triggers |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | if (! $error) |
| 412 | 412 | { |
| 413 | - $this->oldref = $this->ref; |
|
| 413 | + $this->oldref = $this->ref; |
|
| 414 | 414 | |
| 415 | 415 | // Rename directory if dir was a temporary ref |
| 416 | 416 | if (preg_match('/^[\(]?PROV/i', $this->ref)) |
@@ -428,16 +428,16 @@ discard block |
||
| 428 | 428 | if (@rename($dirsource, $dirdest)) |
| 429 | 429 | { |
| 430 | 430 | dol_syslog("Rename ok"); |
| 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) |
|
| 434 | - { |
|
| 435 | - $dirsource=$fileentry['name']; |
|
| 436 | - $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource); |
|
| 437 | - $dirsource=$fileentry['path'].'/'.$dirsource; |
|
| 438 | - $dirdest=$fileentry['path'].'/'.$dirdest; |
|
| 439 | - @rename($dirsource, $dirdest); |
|
| 440 | - } |
|
| 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) |
|
| 434 | + { |
|
| 435 | + $dirsource=$fileentry['name']; |
|
| 436 | + $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource); |
|
| 437 | + $dirsource=$fileentry['path'].'/'.$dirsource; |
|
| 438 | + $dirdest=$fileentry['path'].'/'.$dirdest; |
|
| 439 | + @rename($dirsource, $dirdest); |
|
| 440 | + } |
|
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | } |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | * Unvalidate a contract |
| 475 | 475 | * |
| 476 | 476 | * @param User $user Objet User |
| 477 | - * @param int $notrigger 1=Does not execute triggers, 0=execute triggers |
|
| 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 | 480 | function reopen($user, $notrigger=0) |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | $extralabelsline=$extrafieldsline->fetch_name_optionals_label($line->table_element,true); |
| 675 | 675 | |
| 676 | 676 | $this->lines=array(); |
| 677 | - $pos = 0; |
|
| 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,"; |
@@ -775,8 +775,8 @@ discard block |
||
| 775 | 775 | if ($line->statut == 5) $this->nbofservicesclosed++; |
| 776 | 776 | |
| 777 | 777 | $total_ttc+=$objp->total_ttc; // TODO Not saved into database |
| 778 | - $total_vat+=$objp->total_tva; |
|
| 779 | - $total_ht+=$objp->total_ht; |
|
| 778 | + $total_vat+=$objp->total_tva; |
|
| 779 | + $total_ht+=$objp->total_ht; |
|
| 780 | 780 | |
| 781 | 781 | $i++; |
| 782 | 782 | $pos++; |
@@ -875,11 +875,11 @@ discard block |
||
| 875 | 875 | $this->lines_id_index_mapper[$line->id] = $pos; |
| 876 | 876 | |
| 877 | 877 | $total_ttc+=$objp->total_ttc; |
| 878 | - $total_vat+=$objp->total_tva; |
|
| 879 | - $total_ht+=$objp->total_ht; |
|
| 878 | + $total_vat+=$objp->total_tva; |
|
| 879 | + $total_ht+=$objp->total_ht; |
|
| 880 | 880 | |
| 881 | - $i++; |
|
| 882 | - $pos++; |
|
| 881 | + $i++; |
|
| 882 | + $pos++; |
|
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | $this->db->free($result); |
@@ -892,9 +892,9 @@ discard block |
||
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 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 |
|
| 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 | } |
@@ -982,107 +982,107 @@ discard block |
||
| 982 | 982 | |
| 983 | 983 | if (! $error) |
| 984 | 984 | { |
| 985 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used |
|
| 986 | - { |
|
| 987 | - $result=$this->insertExtraFields(); |
|
| 988 | - if ($result < 0) |
|
| 989 | - { |
|
| 990 | - $error++; |
|
| 991 | - } |
|
| 992 | - } |
|
| 985 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used |
|
| 986 | + { |
|
| 987 | + $result=$this->insertExtraFields(); |
|
| 988 | + if ($result < 0) |
|
| 989 | + { |
|
| 990 | + $error++; |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | 995 | // Insert contacts commerciaux ('SALESREPSIGN','contrat') |
| 996 | 996 | if (! $error) |
| 997 | 997 | { |
| 998 | - $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal'); |
|
| 999 | - if ($result < 0) $error++; |
|
| 998 | + $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal'); |
|
| 999 | + if ($result < 0) $error++; |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | // Insert contacts commerciaux ('SALESREPFOLL','contrat') |
| 1003 | 1003 | if (! $error) |
| 1004 | 1004 | { |
| 1005 | - $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal'); |
|
| 1006 | - if ($result < 0) $error++; |
|
| 1005 | + $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal'); |
|
| 1006 | + if ($result < 0) $error++; |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | if (! $error) |
| 1010 | 1010 | { |
| 1011 | - // Add object linked |
|
| 1012 | - if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) |
|
| 1013 | - { |
|
| 1014 | - foreach($this->linked_objects as $origin => $tmp_origin_id) |
|
| 1015 | - { |
|
| 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 | - { |
|
| 1018 | - foreach($tmp_origin_id as $origin_id) |
|
| 1019 | - { |
|
| 1020 | - $ret = $this->add_object_linked($origin, $origin_id); |
|
| 1021 | - if (! $ret) |
|
| 1022 | - { |
|
| 1023 | - dol_print_error($this->db); |
|
| 1024 | - $error++; |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1027 | - } |
|
| 1028 | - else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) |
|
| 1029 | - { |
|
| 1030 | - $origin_id = $tmp_origin_id; |
|
| 1031 | - $ret = $this->add_object_linked($origin, $origin_id); |
|
| 1032 | - if (! $ret) |
|
| 1033 | - { |
|
| 1034 | - dol_print_error($this->db); |
|
| 1035 | - $error++; |
|
| 1036 | - } |
|
| 1037 | - } |
|
| 1038 | - } |
|
| 1039 | - } |
|
| 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 |
|
| 1042 | - { |
|
| 1043 | - $originforcontact = $this->origin; |
|
| 1044 | - $originidforcontact = $this->origin_id; |
|
| 1045 | - if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order |
|
| 1046 | - { |
|
| 1047 | - require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; |
|
| 1048 | - $exp = new Expedition($db); |
|
| 1049 | - $exp->fetch($this->origin_id); |
|
| 1050 | - $exp->fetchObjectLinked(); |
|
| 1051 | - if (count($exp->linkedObjectsIds['commande']) > 0) |
|
| 1052 | - { |
|
| 1053 | - foreach ($exp->linkedObjectsIds['commande'] as $key => $value) |
|
| 1054 | - { |
|
| 1055 | - $originforcontact = 'commande'; |
|
| 1056 | - $originidforcontact = $value->id; |
|
| 1057 | - break; // We take first one |
|
| 1058 | - } |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 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."'"; |
|
| 1064 | - |
|
| 1065 | - $resqlcontact = $this->db->query($sqlcontact); |
|
| 1066 | - if ($resqlcontact) |
|
| 1067 | - { |
|
| 1068 | - while($objcontact = $this->db->fetch_object($resqlcontact)) |
|
| 1069 | - { |
|
| 1070 | - if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) continue; // ignore this, already forced previously |
|
| 1071 | - |
|
| 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 |
|
| 1074 | - } |
|
| 1075 | - } |
|
| 1076 | - else dol_print_error($resqlcontact); |
|
| 1077 | - } |
|
| 1011 | + // Add object linked |
|
| 1012 | + if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) |
|
| 1013 | + { |
|
| 1014 | + foreach($this->linked_objects as $origin => $tmp_origin_id) |
|
| 1015 | + { |
|
| 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 | + { |
|
| 1018 | + foreach($tmp_origin_id as $origin_id) |
|
| 1019 | + { |
|
| 1020 | + $ret = $this->add_object_linked($origin, $origin_id); |
|
| 1021 | + if (! $ret) |
|
| 1022 | + { |
|
| 1023 | + dol_print_error($this->db); |
|
| 1024 | + $error++; |
|
| 1025 | + } |
|
| 1026 | + } |
|
| 1027 | + } |
|
| 1028 | + else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) |
|
| 1029 | + { |
|
| 1030 | + $origin_id = $tmp_origin_id; |
|
| 1031 | + $ret = $this->add_object_linked($origin, $origin_id); |
|
| 1032 | + if (! $ret) |
|
| 1033 | + { |
|
| 1034 | + dol_print_error($this->db); |
|
| 1035 | + $error++; |
|
| 1036 | + } |
|
| 1037 | + } |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 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 |
|
| 1042 | + { |
|
| 1043 | + $originforcontact = $this->origin; |
|
| 1044 | + $originidforcontact = $this->origin_id; |
|
| 1045 | + if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order |
|
| 1046 | + { |
|
| 1047 | + require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; |
|
| 1048 | + $exp = new Expedition($db); |
|
| 1049 | + $exp->fetch($this->origin_id); |
|
| 1050 | + $exp->fetchObjectLinked(); |
|
| 1051 | + if (count($exp->linkedObjectsIds['commande']) > 0) |
|
| 1052 | + { |
|
| 1053 | + foreach ($exp->linkedObjectsIds['commande'] as $key => $value) |
|
| 1054 | + { |
|
| 1055 | + $originforcontact = 'commande'; |
|
| 1056 | + $originidforcontact = $value->id; |
|
| 1057 | + break; // We take first one |
|
| 1058 | + } |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 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."'"; |
|
| 1064 | + |
|
| 1065 | + $resqlcontact = $this->db->query($sqlcontact); |
|
| 1066 | + if ($resqlcontact) |
|
| 1067 | + { |
|
| 1068 | + while($objcontact = $this->db->fetch_object($resqlcontact)) |
|
| 1069 | + { |
|
| 1070 | + if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) continue; // ignore this, already forced previously |
|
| 1071 | + |
|
| 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 |
|
| 1074 | + } |
|
| 1075 | + } |
|
| 1076 | + else dol_print_error($resqlcontact); |
|
| 1077 | + } |
|
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | 1080 | if (! $error) |
| 1081 | 1081 | { |
| 1082 | - // Call trigger |
|
| 1083 | - $result=$this->call_trigger('CONTRACT_CREATE',$user); |
|
| 1084 | - if ($result < 0) { $error++; } |
|
| 1085 | - // End call triggers |
|
| 1082 | + // Call trigger |
|
| 1083 | + $result=$this->call_trigger('CONTRACT_CREATE',$user); |
|
| 1084 | + if ($result < 0) { $error++; } |
|
| 1085 | + // End call triggers |
|
| 1086 | 1086 | |
| 1087 | 1087 | if (! $error) |
| 1088 | 1088 | { |
@@ -1129,10 +1129,10 @@ discard block |
||
| 1129 | 1129 | |
| 1130 | 1130 | $this->db->begin(); |
| 1131 | 1131 | |
| 1132 | - // Call trigger |
|
| 1133 | - $result=$this->call_trigger('CONTRACT_DELETE',$user); |
|
| 1134 | - if ($result < 0) { $error++; } |
|
| 1135 | - // End call triggers |
|
| 1132 | + // Call trigger |
|
| 1133 | + $result=$this->call_trigger('CONTRACT_DELETE',$user); |
|
| 1134 | + if ($result < 0) { $error++; } |
|
| 1135 | + // End call triggers |
|
| 1136 | 1136 | |
| 1137 | 1137 | if (! $error) |
| 1138 | 1138 | { |
@@ -1301,7 +1301,7 @@ discard block |
||
| 1301 | 1301 | // Put here code to add a control on parameters values |
| 1302 | 1302 | |
| 1303 | 1303 | // Update request |
| 1304 | - $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET"; |
|
| 1304 | + $sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET"; |
|
| 1305 | 1305 | $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; |
| 1306 | 1306 | $sql.= " ref_customer=".(isset($this->ref_customer)?"'".$this->db->escape($this->ref_customer)."'":"null").","; |
| 1307 | 1307 | $sql.= " ref_supplier=".(isset($this->ref_supplier)?"'".$this->db->escape($this->ref_supplier)."'":"null").","; |
@@ -1427,7 +1427,7 @@ discard block |
||
| 1427 | 1427 | if (empty($pu_ttc)) $pu_ttc=0; |
| 1428 | 1428 | if (empty($txtva) || ! is_numeric($txtva)) $txtva=0; |
| 1429 | 1429 | if (empty($txlocaltax1) || ! is_numeric($txlocaltax1)) $txlocaltax1=0; |
| 1430 | - if (empty($txlocaltax2) || ! is_numeric($txlocaltax2)) $txlocaltax2=0; |
|
| 1430 | + if (empty($txlocaltax2) || ! is_numeric($txlocaltax2)) $txlocaltax2=0; |
|
| 1431 | 1431 | |
| 1432 | 1432 | if ($price_base_type=='HT') |
| 1433 | 1433 | { |
@@ -1448,13 +1448,13 @@ discard block |
||
| 1448 | 1448 | |
| 1449 | 1449 | $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->societe, $mysoc); |
| 1450 | 1450 | |
| 1451 | - // Clean vat code |
|
| 1452 | - $vat_src_code=''; |
|
| 1453 | - if (preg_match('/\((.*)\)/', $txtva, $reg)) |
|
| 1454 | - { |
|
| 1455 | - $vat_src_code = $reg[1]; |
|
| 1456 | - $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. |
|
| 1457 | - } |
|
| 1451 | + // Clean vat code |
|
| 1452 | + $vat_src_code=''; |
|
| 1453 | + if (preg_match('/\((.*)\)/', $txtva, $reg)) |
|
| 1454 | + { |
|
| 1455 | + $vat_src_code = $reg[1]; |
|
| 1456 | + $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. |
|
| 1457 | + } |
|
| 1458 | 1458 | |
| 1459 | 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]; |
@@ -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 |
@@ -1549,13 +1549,13 @@ discard block |
||
| 1549 | 1549 | } |
| 1550 | 1550 | |
| 1551 | 1551 | if (empty($error)) { |
| 1552 | - // Call trigger |
|
| 1553 | - $result=$this->call_trigger('LINECONTRACT_INSERT',$user); |
|
| 1554 | - if ($result < 0) |
|
| 1555 | - { |
|
| 1556 | - $error++; |
|
| 1557 | - } |
|
| 1558 | - // End call triggers |
|
| 1552 | + // Call trigger |
|
| 1553 | + $result=$this->call_trigger('LINECONTRACT_INSERT',$user); |
|
| 1554 | + if ($result < 0) |
|
| 1555 | + { |
|
| 1556 | + $error++; |
|
| 1557 | + } |
|
| 1558 | + // End call triggers |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | if ($error) |
@@ -1666,11 +1666,11 @@ discard block |
||
| 1666 | 1666 | $price = price2num(round($pu, 2)); |
| 1667 | 1667 | if (dol_strlen($remise_percent) > 0) |
| 1668 | 1668 | { |
| 1669 | - $remise = round(($pu * $remise_percent / 100), 2); |
|
| 1670 | - $price = $pu - $remise; |
|
| 1669 | + $remise = round(($pu * $remise_percent / 100), 2); |
|
| 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) |
@@ -1736,14 +1736,14 @@ discard block |
||
| 1736 | 1736 | } |
| 1737 | 1737 | |
| 1738 | 1738 | if (empty($error)) { |
| 1739 | - // Call trigger |
|
| 1740 | - $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
| 1741 | - if ($result < 0) |
|
| 1742 | - { |
|
| 1743 | - $this->db->rollback(); |
|
| 1744 | - return -3; |
|
| 1745 | - } |
|
| 1746 | - // End call triggers |
|
| 1739 | + // Call trigger |
|
| 1740 | + $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
| 1741 | + if ($result < 0) |
|
| 1742 | + { |
|
| 1743 | + $this->db->rollback(); |
|
| 1744 | + return -3; |
|
| 1745 | + } |
|
| 1746 | + // End call triggers |
|
| 1747 | 1747 | |
| 1748 | 1748 | $this->db->commit(); |
| 1749 | 1749 | return 1; |
@@ -1781,12 +1781,12 @@ discard block |
||
| 1781 | 1781 | if ($this->statut >= 0) |
| 1782 | 1782 | { |
| 1783 | 1783 | |
| 1784 | - // Call trigger |
|
| 1785 | - $result=$this->call_trigger('LINECONTRACT_DELETE',$user); |
|
| 1786 | - if ($result < 0) return -1; |
|
| 1787 | - // End call triggers |
|
| 1784 | + // Call trigger |
|
| 1785 | + $result=$this->call_trigger('LINECONTRACT_DELETE',$user); |
|
| 1786 | + if ($result < 0) return -1; |
|
| 1787 | + // End call triggers |
|
| 1788 | 1788 | |
| 1789 | - $this->db->begin(); |
|
| 1789 | + $this->db->begin(); |
|
| 1790 | 1790 | |
| 1791 | 1791 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."contratdet"; |
| 1792 | 1792 | $sql.= " WHERE rowid=".$idline; |
@@ -1940,8 +1940,8 @@ discard block |
||
| 1940 | 1940 | * |
| 1941 | 1941 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
| 1942 | 1942 | * @param int $maxlength Max length of ref |
| 1943 | - * @param int $notooltip 1=Disable tooltip |
|
| 1944 | - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
|
| 1943 | + * @param int $notooltip 1=Disable tooltip |
|
| 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 | 1947 | function getNomUrl($withpicto=0, $maxlength=0, $notooltip=0, $save_lastsearch_value=-1) |
@@ -1961,35 +1961,35 @@ discard block |
||
| 1961 | 1961 | //} |
| 1962 | 1962 | |
| 1963 | 1963 | $picto = 'contract'; |
| 1964 | - $label = ''; |
|
| 1965 | - |
|
| 1966 | - if ($user->rights->contrat->lire) { |
|
| 1967 | - $label = '<u>'.$langs->trans("ShowContract").'</u>'; |
|
| 1968 | - $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref; |
|
| 1969 | - $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client); |
|
| 1970 | - $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_supplier; |
|
| 1971 | - if (!empty($this->total_ht)) { |
|
| 1972 | - $label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); |
|
| 1973 | - } |
|
| 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); |
|
| 1976 | - } |
|
| 1977 | - if (!empty($this->total_ttc)) { |
|
| 1978 | - $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); |
|
| 1979 | - } |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - $linkclose=''; |
|
| 1983 | - if (empty($notooltip) && $user->rights->contrat->lire) |
|
| 1984 | - { |
|
| 1985 | - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
| 1986 | - { |
|
| 1987 | - $label=$langs->trans("ShowOrder"); |
|
| 1988 | - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
| 1989 | - } |
|
| 1990 | - $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
| 1991 | - $linkclose.=' class="classfortooltip"'; |
|
| 1992 | - } |
|
| 1964 | + $label = ''; |
|
| 1965 | + |
|
| 1966 | + if ($user->rights->contrat->lire) { |
|
| 1967 | + $label = '<u>'.$langs->trans("ShowContract").'</u>'; |
|
| 1968 | + $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref; |
|
| 1969 | + $label .= '<br><b>'.$langs->trans('RefCustomer').':</b> '.($this->ref_customer ? $this->ref_customer : $this->ref_client); |
|
| 1970 | + $label .= '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_supplier; |
|
| 1971 | + if (!empty($this->total_ht)) { |
|
| 1972 | + $label .= '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); |
|
| 1973 | + } |
|
| 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); |
|
| 1976 | + } |
|
| 1977 | + if (!empty($this->total_ttc)) { |
|
| 1978 | + $label .= '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); |
|
| 1979 | + } |
|
| 1980 | + } |
|
| 1981 | + |
|
| 1982 | + $linkclose=''; |
|
| 1983 | + if (empty($notooltip) && $user->rights->contrat->lire) |
|
| 1984 | + { |
|
| 1985 | + if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
| 1986 | + { |
|
| 1987 | + $label=$langs->trans("ShowOrder"); |
|
| 1988 | + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
| 1989 | + } |
|
| 1990 | + $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
| 1991 | + $linkclose.=' class="classfortooltip"'; |
|
| 1992 | + } |
|
| 1993 | 1993 | |
| 1994 | 1994 | $linkstart = '<a href="'.$url.'"'; |
| 1995 | 1995 | $linkstart.=$linkclose.'>'; |
@@ -2126,11 +2126,11 @@ discard block |
||
| 2126 | 2126 | |
| 2127 | 2127 | |
| 2128 | 2128 | /** |
| 2129 | - * Load indicators for dashboard (this->nbtodo and this->nbtodolate) |
|
| 2130 | - * |
|
| 2131 | - * @param User $user Objet user |
|
| 2132 | - * @param string $mode "inactive" pour services a activer, "expired" pour services expires |
|
| 2133 | - * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK |
|
| 2129 | + * Load indicators for dashboard (this->nbtodo and this->nbtodolate) |
|
| 2130 | + * |
|
| 2131 | + * @param User $user Objet user |
|
| 2132 | + * @param string $mode "inactive" pour services a activer, "expired" pour services expires |
|
| 2133 | + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK |
|
| 2134 | 2134 | */ |
| 2135 | 2135 | function load_board($user,$mode) |
| 2136 | 2136 | { |
@@ -2233,7 +2233,7 @@ discard block |
||
| 2233 | 2233 | { |
| 2234 | 2234 | $this->nb["Contracts"]=$obj->nb; |
| 2235 | 2235 | } |
| 2236 | - $this->db->free($resql); |
|
| 2236 | + $this->db->free($resql); |
|
| 2237 | 2237 | return 1; |
| 2238 | 2238 | } |
| 2239 | 2239 | else |
@@ -2269,17 +2269,17 @@ discard block |
||
| 2269 | 2269 | |
| 2270 | 2270 | |
| 2271 | 2271 | /** |
| 2272 | - * Initialise an instance with random values. |
|
| 2273 | - * Used to build previews or test instances. |
|
| 2274 | - * id must be 0 if object instance is a specimen. |
|
| 2275 | - * |
|
| 2276 | - * @return void |
|
| 2272 | + * Initialise an instance with random values. |
|
| 2273 | + * Used to build previews or test instances. |
|
| 2274 | + * id must be 0 if object instance is a specimen. |
|
| 2275 | + * |
|
| 2276 | + * @return void |
|
| 2277 | 2277 | */ |
| 2278 | 2278 | function initAsSpecimen() |
| 2279 | 2279 | { |
| 2280 | 2280 | global $user,$langs,$conf; |
| 2281 | 2281 | |
| 2282 | - // Load array of products prodids |
|
| 2282 | + // Load array of products prodids |
|
| 2283 | 2283 | $num_prods = 0; |
| 2284 | 2284 | $prodids = array(); |
| 2285 | 2285 | $sql = "SELECT rowid"; |
@@ -2334,10 +2334,10 @@ discard block |
||
| 2334 | 2334 | $line->date_fin_validite = dol_now() + 500000; |
| 2335 | 2335 | $line->date_cloture = dol_now() - 100000; |
| 2336 | 2336 | if ($num_prods > 0) |
| 2337 | - { |
|
| 2337 | + { |
|
| 2338 | 2338 | $prodid = mt_rand(1, $num_prods); |
| 2339 | 2339 | $line->fk_product=$prodids[$prodid]; |
| 2340 | - } |
|
| 2340 | + } |
|
| 2341 | 2341 | $this->lines[$xnbp]=$line; |
| 2342 | 2342 | $xnbp++; |
| 2343 | 2343 | } |
@@ -2411,7 +2411,7 @@ discard block |
||
| 2411 | 2411 | $this->fetch($this->id); |
| 2412 | 2412 | // Load dest object |
| 2413 | 2413 | $clonedObj = clone $this; |
| 2414 | - $clonedObj->socid = $socid; |
|
| 2414 | + $clonedObj->socid = $socid; |
|
| 2415 | 2415 | |
| 2416 | 2416 | $this->db->begin(); |
| 2417 | 2417 | |
@@ -2446,13 +2446,13 @@ discard block |
||
| 2446 | 2446 | $this->error = $clonedObj->error; |
| 2447 | 2447 | $this->errors[] = $clonedObj->error; |
| 2448 | 2448 | } else { |
| 2449 | - // copy external contacts if same company |
|
| 2450 | - if ($this->socid == $clonedObj->socid) { |
|
| 2451 | - if ($clonedObj->copy_linked_contact($this, 'external') < 0) { |
|
| 2452 | - $error++; |
|
| 2453 | - } |
|
| 2454 | - } |
|
| 2455 | - } |
|
| 2449 | + // copy external contacts if same company |
|
| 2450 | + if ($this->socid == $clonedObj->socid) { |
|
| 2451 | + if ($clonedObj->copy_linked_contact($this, 'external') < 0) { |
|
| 2452 | + $error++; |
|
| 2453 | + } |
|
| 2454 | + } |
|
| 2455 | + } |
|
| 2456 | 2456 | |
| 2457 | 2457 | if (! $error) { |
| 2458 | 2458 | foreach ( $this->lines as $line ) { |
@@ -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; |
@@ -2577,9 +2577,9 @@ discard block |
||
| 2577 | 2577 | |
| 2578 | 2578 | |
| 2579 | 2579 | /** |
| 2580 | - * Constructor |
|
| 2581 | - * |
|
| 2582 | - * @param DoliDb $db Database handler |
|
| 2580 | + * Constructor |
|
| 2581 | + * |
|
| 2582 | + * @param DoliDb $db Database handler |
|
| 2583 | 2583 | */ |
| 2584 | 2584 | function __construct($db) |
| 2585 | 2585 | { |
@@ -2667,22 +2667,22 @@ discard block |
||
| 2667 | 2667 | * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
| 2668 | 2668 | * @param int $maxlength Max length |
| 2669 | 2669 | * @return string Chaine avec URL |
| 2670 | - */ |
|
| 2670 | + */ |
|
| 2671 | 2671 | function getNomUrl($withpicto=0,$maxlength=0) |
| 2672 | 2672 | { |
| 2673 | 2673 | global $langs; |
| 2674 | 2674 | |
| 2675 | 2675 | $result=''; |
| 2676 | - $label=$langs->trans("ShowContractOfService").': '.$this->label; |
|
| 2677 | - if (empty($label)) $label=$this->description; |
|
| 2676 | + $label=$langs->trans("ShowContractOfService").': '.$this->label; |
|
| 2677 | + if (empty($label)) $label=$this->description; |
|
| 2678 | 2678 | |
| 2679 | - $link = '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$this->fk_contrat.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
| 2679 | + $link = '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$this->fk_contrat.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
| 2680 | 2680 | $linkend='</a>'; |
| 2681 | 2681 | |
| 2682 | 2682 | $picto='service'; |
| 2683 | 2683 | if ($this->type == 0) $picto='product'; |
| 2684 | 2684 | |
| 2685 | - if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
| 2685 | + if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
| 2686 | 2686 | if ($withpicto && $withpicto != 2) $result.=' '; |
| 2687 | 2687 | if ($withpicto != 2) $result.=$link.($this->product_ref?$this->product_ref.' ':'').($this->label?$this->label:$this->description).$linkend; |
| 2688 | 2688 | return $result; |
@@ -2878,7 +2878,7 @@ discard block |
||
| 2878 | 2878 | $this->total_localtax1= $tabprice[9]; |
| 2879 | 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) |
@@ -2961,15 +2961,15 @@ discard block |
||
| 2961 | 2961 | if (empty($error)) { |
| 2962 | 2962 | if (! $notrigger) |
| 2963 | 2963 | { |
| 2964 | - // Call trigger |
|
| 2965 | - $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
| 2966 | - if ($result < 0) { $error++; $this->db->rollback(); return -1; } |
|
| 2967 | - // End call triggers |
|
| 2964 | + // Call trigger |
|
| 2965 | + $result=$this->call_trigger('LINECONTRACT_UPDATE',$user); |
|
| 2966 | + if ($result < 0) { $error++; $this->db->rollback(); return -1; } |
|
| 2967 | + // End call triggers |
|
| 2968 | 2968 | } |
| 2969 | 2969 | } |
| 2970 | 2970 | |
| 2971 | 2971 | if (empty($error)) { |
| 2972 | - $this->db->commit(); |
|
| 2972 | + $this->db->commit(); |
|
| 2973 | 2973 | return 1; |
| 2974 | 2974 | } else { |
| 2975 | 2975 | $this->db->rollback(); |
@@ -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) { |
@@ -200,15 +200,13 @@ discard block |
||
| 200 | 200 | if ( $numref != "") |
| 201 | 201 | { |
| 202 | 202 | return $numref; |
| 203 | - } |
|
| 204 | - else |
|
| 203 | + } else |
|
| 205 | 204 | { |
| 206 | 205 | $this->error = $obj->error; |
| 207 | 206 | dol_print_error($db,get_class($this)."::getNextValue ".$obj->error); |
| 208 | 207 | return ""; |
| 209 | 208 | } |
| 210 | - } |
|
| 211 | - else |
|
| 209 | + } else |
|
| 212 | 210 | { |
| 213 | 211 | $langs->load("errors"); |
| 214 | 212 | print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete"); |
@@ -256,7 +254,9 @@ discard block |
||
| 256 | 254 | */ |
| 257 | 255 | function activateAll($user, $date_start='') |
| 258 | 256 | { |
| 259 | - if (empty($date_start)) $date_start = dol_now(); |
|
| 257 | + if (empty($date_start)) { |
|
| 258 | + $date_start = dol_now(); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | 261 | $this->db->begin(); |
| 262 | 262 | |
@@ -281,15 +281,16 @@ discard block |
||
| 281 | 281 | if ($this->statut == 0) |
| 282 | 282 | { |
| 283 | 283 | $result=$this->validate($user); |
| 284 | - if ($result < 0) $ok=false; |
|
| 284 | + if ($result < 0) { |
|
| 285 | + $ok=false; |
|
| 286 | + } |
|
| 285 | 287 | } |
| 286 | 288 | |
| 287 | 289 | if ($ok) |
| 288 | 290 | { |
| 289 | 291 | $this->db->commit(); |
| 290 | 292 | return 1; |
| 291 | - } |
|
| 292 | - else |
|
| 293 | + } else |
|
| 293 | 294 | { |
| 294 | 295 | dol_print_error($this->db,'Error in activateAll function'); |
| 295 | 296 | $this->db->rollback(); |
@@ -331,15 +332,16 @@ discard block |
||
| 331 | 332 | if ($this->statut == 0) |
| 332 | 333 | { |
| 333 | 334 | $result=$this->validate($user); |
| 334 | - if ($result < 0) $ok=false; |
|
| 335 | + if ($result < 0) { |
|
| 336 | + $ok=false; |
|
| 337 | + } |
|
| 335 | 338 | } |
| 336 | 339 | |
| 337 | 340 | if ($ok) |
| 338 | 341 | { |
| 339 | 342 | $this->db->commit(); |
| 340 | 343 | return 1; |
| 341 | - } |
|
| 342 | - else |
|
| 344 | + } else |
|
| 343 | 345 | { |
| 344 | 346 | dol_print_error($this->db,'Error in closeAll function'); |
| 345 | 347 | $this->db->rollback(); |
@@ -374,11 +376,12 @@ discard block |
||
| 374 | 376 | $result=$this->thirdparty->set_as_client(); |
| 375 | 377 | |
| 376 | 378 | // 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 |
|
| 379 | + if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { |
|
| 380 | + // empty should not happened, but when it occurs, the test save life |
|
| 378 | 381 | { |
| 379 | 382 | $num = $this->getNextNumRef($this->thirdparty); |
| 380 | 383 | } |
| 381 | - else |
|
| 384 | + } else |
|
| 382 | 385 | { |
| 383 | 386 | $num = $this->ref; |
| 384 | 387 | } |
@@ -451,8 +454,7 @@ discard block |
||
| 451 | 454 | $this->brouillon=0; |
| 452 | 455 | $this->date_validation=$now; |
| 453 | 456 | } |
| 454 | - } |
|
| 455 | - else |
|
| 457 | + } else |
|
| 456 | 458 | { |
| 457 | 459 | $error++; |
| 458 | 460 | } |
@@ -461,8 +463,7 @@ discard block |
||
| 461 | 463 | { |
| 462 | 464 | $this->db->commit(); |
| 463 | 465 | return 1; |
| 464 | - } |
|
| 465 | - else |
|
| 466 | + } else |
|
| 466 | 467 | { |
| 467 | 468 | $this->db->rollback(); |
| 468 | 469 | return -1; |
@@ -527,8 +528,7 @@ discard block |
||
| 527 | 528 | { |
| 528 | 529 | $this->db->commit(); |
| 529 | 530 | return 1; |
| 530 | - } |
|
| 531 | - else |
|
| 531 | + } else |
|
| 532 | 532 | { |
| 533 | 533 | $this->db->rollback(); |
| 534 | 534 | return -1; |
@@ -555,8 +555,11 @@ discard block |
||
| 555 | 555 | $sql.= " fk_commercial_signature, fk_commercial_suivi,"; |
| 556 | 556 | $sql.= " note_private, note_public, model_pdf, extraparams"; |
| 557 | 557 | $sql.= " FROM ".MAIN_DB_PREFIX."contrat"; |
| 558 | - if (! $id) $sql.=" WHERE entity IN (".getEntity('contract', 0).")"; |
|
| 559 | - else $sql.= " WHERE rowid=".$id; |
|
| 558 | + if (! $id) { |
|
| 559 | + $sql.=" WHERE entity IN (".getEntity('contract', 0).")"; |
|
| 560 | + } else { |
|
| 561 | + $sql.= " WHERE rowid=".$id; |
|
| 562 | + } |
|
| 560 | 563 | if ($ref_customer) |
| 561 | 564 | { |
| 562 | 565 | $sql.= " AND ref_customer = '".$this->db->escape($ref_customer)."'"; |
@@ -633,15 +636,13 @@ discard block |
||
| 633 | 636 | } |
| 634 | 637 | |
| 635 | 638 | return $this->id; |
| 636 | - } |
|
| 637 | - else |
|
| 639 | + } else |
|
| 638 | 640 | { |
| 639 | 641 | dol_syslog(get_class($this)."::Fetch Erreur contrat non trouve"); |
| 640 | 642 | $this->error="Contract not found"; |
| 641 | 643 | return 0; |
| 642 | 644 | } |
| 643 | - } |
|
| 644 | - else |
|
| 645 | + } else |
|
| 645 | 646 | { |
| 646 | 647 | dol_syslog(get_class($this)."::Fetch Erreur lecture contrat"); |
| 647 | 648 | $this->error=$this->db->error(); |
@@ -769,10 +770,18 @@ discard block |
||
| 769 | 770 | //dol_syslog("1 ".$line->desc); |
| 770 | 771 | //dol_syslog("2 ".$line->product_desc); |
| 771 | 772 | |
| 772 | - if ($line->statut == 0) $this->nbofserviceswait++; |
|
| 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++; |
|
| 775 | - if ($line->statut == 5) $this->nbofservicesclosed++; |
|
| 773 | + if ($line->statut == 0) { |
|
| 774 | + $this->nbofserviceswait++; |
|
| 775 | + } |
|
| 776 | + if ($line->statut == 4 && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) { |
|
| 777 | + $this->nbofservicesopened++; |
|
| 778 | + } |
|
| 779 | + if ($line->statut == 4 && (! empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) { |
|
| 780 | + $this->nbofservicesexpired++; |
|
| 781 | + } |
|
| 782 | + if ($line->statut == 5) { |
|
| 783 | + $this->nbofservicesclosed++; |
|
| 784 | + } |
|
| 776 | 785 | |
| 777 | 786 | $total_ttc+=$objp->total_ttc; // TODO Not saved into database |
| 778 | 787 | $total_vat+=$objp->total_tva; |
@@ -782,8 +791,7 @@ discard block |
||
| 782 | 791 | $pos++; |
| 783 | 792 | } |
| 784 | 793 | $this->db->free($result); |
| 785 | - } |
|
| 786 | - else |
|
| 794 | + } else |
|
| 787 | 795 | { |
| 788 | 796 | dol_syslog(get_class($this)."::Fetch Erreur lecture des lignes de contrats liees aux produits"); |
| 789 | 797 | return -3; |
@@ -859,10 +867,18 @@ discard block |
||
| 859 | 867 | $line->date_fin_reel = $this->db->jdate($objp->date_cloture); |
| 860 | 868 | $line->fk_unit = $objp->fk_unit; |
| 861 | 869 | |
| 862 | - if ($line->statut == 0) $this->nbofserviceswait++; |
|
| 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++; |
|
| 865 | - if ($line->statut == 5) $this->nbofservicesclosed++; |
|
| 870 | + if ($line->statut == 0) { |
|
| 871 | + $this->nbofserviceswait++; |
|
| 872 | + } |
|
| 873 | + if ($line->statut == 4 && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) { |
|
| 874 | + $this->nbofservicesopened++; |
|
| 875 | + } |
|
| 876 | + if ($line->statut == 4 && (! empty($line->date_fin_prevue) && $line->date_fin_prevue < $now)) { |
|
| 877 | + $this->nbofservicesexpired++; |
|
| 878 | + } |
|
| 879 | + if ($line->statut == 5) { |
|
| 880 | + $this->nbofservicesclosed++; |
|
| 881 | + } |
|
| 866 | 882 | |
| 867 | 883 | |
| 868 | 884 | // Retreive all extrafield for propal |
@@ -883,8 +899,7 @@ discard block |
||
| 883 | 899 | } |
| 884 | 900 | |
| 885 | 901 | $this->db->free($result); |
| 886 | - } |
|
| 887 | - else |
|
| 902 | + } else |
|
| 888 | 903 | { |
| 889 | 904 | dol_syslog(get_class($this)."::Fetch Erreur lecture des lignes de contrat non liees aux produits"); |
| 890 | 905 | $this->error=$this->db->error(); |
@@ -924,7 +939,9 @@ discard block |
||
| 924 | 939 | $this->error.=$langs->trans("ErrorFieldRequired",$langs->trans("SalesRepresentativeFollowUp")); |
| 925 | 940 | $paramsok=0; |
| 926 | 941 | } |
| 927 | - if (! $paramsok) return -1; |
|
| 942 | + if (! $paramsok) { |
|
| 943 | + return -1; |
|
| 944 | + } |
|
| 928 | 945 | |
| 929 | 946 | |
| 930 | 947 | $this->db->begin(); |
@@ -982,9 +999,11 @@ discard block |
||
| 982 | 999 | |
| 983 | 1000 | if (! $error) |
| 984 | 1001 | { |
| 985 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used |
|
| 1002 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 1003 | + // For avoid conflicts if trigger used |
|
| 986 | 1004 | { |
| 987 | 1005 | $result=$this->insertExtraFields(); |
| 1006 | + } |
|
| 988 | 1007 | if ($result < 0) |
| 989 | 1008 | { |
| 990 | 1009 | $error++; |
@@ -996,14 +1015,18 @@ discard block |
||
| 996 | 1015 | if (! $error) |
| 997 | 1016 | { |
| 998 | 1017 | $result=$this->add_contact($this->commercial_signature_id,'SALESREPSIGN','internal'); |
| 999 | - if ($result < 0) $error++; |
|
| 1018 | + if ($result < 0) { |
|
| 1019 | + $error++; |
|
| 1020 | + } |
|
| 1000 | 1021 | } |
| 1001 | 1022 | |
| 1002 | 1023 | // Insert contacts commerciaux ('SALESREPFOLL','contrat') |
| 1003 | 1024 | if (! $error) |
| 1004 | 1025 | { |
| 1005 | 1026 | $result=$this->add_contact($this->commercial_suivi_id,'SALESREPFOLL','internal'); |
| 1006 | - if ($result < 0) $error++; |
|
| 1027 | + if ($result < 0) { |
|
| 1028 | + $error++; |
|
| 1029 | + } |
|
| 1007 | 1030 | } |
| 1008 | 1031 | |
| 1009 | 1032 | if (! $error) |
@@ -1013,19 +1036,20 @@ discard block |
||
| 1013 | 1036 | { |
| 1014 | 1037 | foreach($this->linked_objects as $origin => $tmp_origin_id) |
| 1015 | 1038 | { |
| 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, ...)) |
|
| 1039 | + if (is_array($tmp_origin_id)) { |
|
| 1040 | + // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) |
|
| 1017 | 1041 | { |
| 1018 | 1042 | foreach($tmp_origin_id as $origin_id) |
| 1019 | 1043 | { |
| 1020 | 1044 | $ret = $this->add_object_linked($origin, $origin_id); |
| 1045 | + } |
|
| 1021 | 1046 | if (! $ret) |
| 1022 | 1047 | { |
| 1023 | 1048 | dol_print_error($this->db); |
| 1024 | 1049 | $error++; |
| 1025 | 1050 | } |
| 1026 | 1051 | } |
| 1027 | - } |
|
| 1028 | - else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) |
|
| 1052 | + } else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) |
|
| 1029 | 1053 | { |
| 1030 | 1054 | $origin_id = $tmp_origin_id; |
| 1031 | 1055 | $ret = $this->add_object_linked($origin, $origin_id); |
@@ -1038,13 +1062,17 @@ discard block |
||
| 1038 | 1062 | } |
| 1039 | 1063 | } |
| 1040 | 1064 | |
| 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 |
|
| 1065 | + if (! $error && $this->id && ! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && ! empty($this->origin) && ! empty($this->origin_id)) { |
|
| 1066 | + // Get contact from origin object |
|
| 1042 | 1067 | { |
| 1043 | 1068 | $originforcontact = $this->origin; |
| 1069 | + } |
|
| 1044 | 1070 | $originidforcontact = $this->origin_id; |
| 1045 | - if ($originforcontact == 'shipping') // shipment and order share the same contacts. If creating from shipment we take data of order |
|
| 1071 | + if ($originforcontact == 'shipping') { |
|
| 1072 | + // shipment and order share the same contacts. If creating from shipment we take data of order |
|
| 1046 | 1073 | { |
| 1047 | 1074 | require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; |
| 1075 | + } |
|
| 1048 | 1076 | $exp = new Expedition($db); |
| 1049 | 1077 | $exp->fetch($this->origin_id); |
| 1050 | 1078 | $exp->fetchObjectLinked(); |
@@ -1067,13 +1095,17 @@ discard block |
||
| 1067 | 1095 | { |
| 1068 | 1096 | while($objcontact = $this->db->fetch_object($resqlcontact)) |
| 1069 | 1097 | { |
| 1070 | - if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) continue; // ignore this, already forced previously |
|
| 1098 | + if ($objcontact->source == 'internal' && in_array($objcontact->code, array('SALESREPSIGN', 'SALESREPFOLL'))) { |
|
| 1099 | + continue; |
|
| 1100 | + } |
|
| 1101 | + // ignore this, already forced previously |
|
| 1071 | 1102 | |
| 1072 | 1103 | //print $objcontact->code.'-'.$objcontact->source.'-'.$objcontact->fk_socpeople."\n"; |
| 1073 | 1104 | $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 | 1105 | } |
| 1106 | + } else { |
|
| 1107 | + dol_print_error($resqlcontact); |
|
| 1075 | 1108 | } |
| 1076 | - else dol_print_error($resqlcontact); |
|
| 1077 | 1109 | } |
| 1078 | 1110 | } |
| 1079 | 1111 | |
@@ -1088,23 +1120,20 @@ discard block |
||
| 1088 | 1120 | { |
| 1089 | 1121 | $this->db->commit(); |
| 1090 | 1122 | return $this->id; |
| 1091 | - } |
|
| 1092 | - else |
|
| 1123 | + } else |
|
| 1093 | 1124 | { |
| 1094 | 1125 | dol_syslog(get_class($this)."::create - 30 - ".$this->error, LOG_ERR); |
| 1095 | 1126 | $this->db->rollback(); |
| 1096 | 1127 | return -3; |
| 1097 | 1128 | } |
| 1098 | - } |
|
| 1099 | - else |
|
| 1129 | + } else |
|
| 1100 | 1130 | { |
| 1101 | 1131 | $this->error="Failed to add contact"; |
| 1102 | 1132 | dol_syslog(get_class($this)."::create - 20 - ".$this->error, LOG_ERR); |
| 1103 | 1133 | $this->db->rollback(); |
| 1104 | 1134 | return -2; |
| 1105 | 1135 | } |
| 1106 | - } |
|
| 1107 | - else |
|
| 1136 | + } else |
|
| 1108 | 1137 | { |
| 1109 | 1138 | $this->error=$langs->trans("UnknownError: ".$this->db->error()." -", LOG_DEBUG); |
| 1110 | 1139 | |
@@ -1149,7 +1178,9 @@ discard block |
||
| 1149 | 1178 | { |
| 1150 | 1179 | // Delete linked object |
| 1151 | 1180 | $res = $this->deleteObjectLinked(); |
| 1152 | - if ($res < 0) $error++; |
|
| 1181 | + if ($res < 0) { |
|
| 1182 | + $error++; |
|
| 1183 | + } |
|
| 1153 | 1184 | } |
| 1154 | 1185 | |
| 1155 | 1186 | if (! $error) |
@@ -1258,8 +1289,7 @@ discard block |
||
| 1258 | 1289 | { |
| 1259 | 1290 | $this->db->commit(); |
| 1260 | 1291 | return 1; |
| 1261 | - } |
|
| 1262 | - else |
|
| 1292 | + } else |
|
| 1263 | 1293 | { |
| 1264 | 1294 | $this->error=$this->db->lasterror(); |
| 1265 | 1295 | $this->db->rollback(); |
@@ -1280,21 +1310,51 @@ discard block |
||
| 1280 | 1310 | $error=0; |
| 1281 | 1311 | |
| 1282 | 1312 | // 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); |
|
| 1313 | + if (isset($this->ref)) { |
|
| 1314 | + $this->ref=trim($this->ref); |
|
| 1315 | + } |
|
| 1316 | + if (isset($this->ref_customer)) { |
|
| 1317 | + $this->ref_customer=trim($this->ref_customer); |
|
| 1318 | + } |
|
| 1319 | + if (isset($this->ref_supplier)) { |
|
| 1320 | + $this->ref_supplier=trim($this->ref_supplier); |
|
| 1321 | + } |
|
| 1322 | + if (isset($this->ref_ext)) { |
|
| 1323 | + $this->ref_ext=trim($this->ref_ext); |
|
| 1324 | + } |
|
| 1325 | + if (isset($this->entity)) { |
|
| 1326 | + $this->entity=trim($this->entity); |
|
| 1327 | + } |
|
| 1328 | + if (isset($this->statut)) { |
|
| 1329 | + $this->statut=(int) $this->statut; |
|
| 1330 | + } |
|
| 1331 | + if (isset($this->fk_soc)) { |
|
| 1332 | + $this->fk_soc=trim($this->fk_soc); |
|
| 1333 | + } |
|
| 1334 | + if (isset($this->fk_projet)) { |
|
| 1335 | + $this->fk_projet=trim($this->fk_projet); |
|
| 1336 | + } |
|
| 1337 | + if (isset($this->fk_commercial_signature)) { |
|
| 1338 | + $this->fk_commercial_signature=trim($this->fk_commercial_signature); |
|
| 1339 | + } |
|
| 1340 | + if (isset($this->fk_commercial_suivi)) { |
|
| 1341 | + $this->fk_commercial_suivi=trim($this->fk_commercial_suivi); |
|
| 1342 | + } |
|
| 1343 | + if (isset($this->fk_user_mise_en_service)) { |
|
| 1344 | + $this->fk_user_mise_en_service=trim($this->fk_user_mise_en_service); |
|
| 1345 | + } |
|
| 1346 | + if (isset($this->fk_user_cloture)) { |
|
| 1347 | + $this->fk_user_cloture=trim($this->fk_user_cloture); |
|
| 1348 | + } |
|
| 1349 | + if (isset($this->note_private)) { |
|
| 1350 | + $this->note_private=trim($this->note_private); |
|
| 1351 | + } |
|
| 1352 | + if (isset($this->note_public)) { |
|
| 1353 | + $this->note_public=trim($this->note_public); |
|
| 1354 | + } |
|
| 1355 | + if (isset($this->import_key)) { |
|
| 1356 | + $this->import_key=trim($this->import_key); |
|
| 1357 | + } |
|
| 1298 | 1358 | //if (isset($this->extraparams)) $this->extraparams=trim($this->extraparams); |
| 1299 | 1359 | |
| 1300 | 1360 | // Check parameters |
@@ -1343,18 +1403,22 @@ discard block |
||
| 1343 | 1403 | } |
| 1344 | 1404 | } |
| 1345 | 1405 | |
| 1346 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used |
|
| 1406 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) { |
|
| 1407 | + // For avoid conflicts if trigger used |
|
| 1347 | 1408 | { |
| 1348 | 1409 | $result=$this->insertExtraFields(); |
| 1410 | + } |
|
| 1349 | 1411 | if ($result < 0) |
| 1350 | 1412 | { |
| 1351 | 1413 | $error++; |
| 1352 | 1414 | } |
| 1353 | 1415 | } |
| 1354 | 1416 | |
| 1355 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used |
|
| 1417 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) { |
|
| 1418 | + // For avoid conflicts if trigger used |
|
| 1356 | 1419 | { |
| 1357 | 1420 | $result=$this->insertExtraFields(); |
| 1421 | + } |
|
| 1358 | 1422 | if ($result < 0) |
| 1359 | 1423 | { |
| 1360 | 1424 | $error++; |
@@ -1371,8 +1435,7 @@ discard block |
||
| 1371 | 1435 | } |
| 1372 | 1436 | $this->db->rollback(); |
| 1373 | 1437 | return -1*$error; |
| 1374 | - } |
|
| 1375 | - else |
|
| 1438 | + } else |
|
| 1376 | 1439 | { |
| 1377 | 1440 | $this->db->commit(); |
| 1378 | 1441 | return 1; |
@@ -1421,25 +1484,40 @@ discard block |
||
| 1421 | 1484 | $txlocaltax2=price2num($txlocaltax2); |
| 1422 | 1485 | $remise_percent=price2num($remise_percent); |
| 1423 | 1486 | $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; |
|
| 1487 | + if (empty($qty)) { |
|
| 1488 | + $qty=1; |
|
| 1489 | + } |
|
| 1490 | + if (empty($info_bits)) { |
|
| 1491 | + $info_bits=0; |
|
| 1492 | + } |
|
| 1493 | + if (empty($pu_ht) || ! is_numeric($pu_ht)) { |
|
| 1494 | + $pu_ht=0; |
|
| 1495 | + } |
|
| 1496 | + if (empty($pu_ttc)) { |
|
| 1497 | + $pu_ttc=0; |
|
| 1498 | + } |
|
| 1499 | + if (empty($txtva) || ! is_numeric($txtva)) { |
|
| 1500 | + $txtva=0; |
|
| 1501 | + } |
|
| 1502 | + if (empty($txlocaltax1) || ! is_numeric($txlocaltax1)) { |
|
| 1503 | + $txlocaltax1=0; |
|
| 1504 | + } |
|
| 1505 | + if (empty($txlocaltax2) || ! is_numeric($txlocaltax2)) { |
|
| 1506 | + $txlocaltax2=0; |
|
| 1507 | + } |
|
| 1431 | 1508 | |
| 1432 | 1509 | if ($price_base_type=='HT') |
| 1433 | 1510 | { |
| 1434 | 1511 | $pu=$pu_ht; |
| 1435 | - } |
|
| 1436 | - else |
|
| 1512 | + } else |
|
| 1437 | 1513 | { |
| 1438 | 1514 | $pu=$pu_ttc; |
| 1439 | 1515 | } |
| 1440 | 1516 | |
| 1441 | 1517 | // Check parameters |
| 1442 | - if (empty($remise_percent)) $remise_percent=0; |
|
| 1518 | + if (empty($remise_percent)) { |
|
| 1519 | + $remise_percent=0; |
|
| 1520 | + } |
|
| 1443 | 1521 | |
| 1444 | 1522 | // Calcul du total TTC et de la TVA pour la ligne a partir de |
| 1445 | 1523 | // qty, pu, remise_percent et txtva |
@@ -1476,7 +1554,9 @@ discard block |
||
| 1476 | 1554 | $price = $pu_ht - $remise; |
| 1477 | 1555 | } |
| 1478 | 1556 | |
| 1479 | - if (empty($pa_ht)) $pa_ht=0; |
|
| 1557 | + if (empty($pa_ht)) { |
|
| 1558 | + $pa_ht=0; |
|
| 1559 | + } |
|
| 1480 | 1560 | |
| 1481 | 1561 | |
| 1482 | 1562 | // if buy price not defined, define buyprice as configured in margin admin |
@@ -1485,8 +1565,7 @@ discard block |
||
| 1485 | 1565 | if (($result = $this->defineBuyPrice($pu_ht, $remise_percent, $fk_product)) < 0) |
| 1486 | 1566 | { |
| 1487 | 1567 | return $result; |
| 1488 | - } |
|
| 1489 | - else |
|
| 1568 | + } else |
|
| 1490 | 1569 | { |
| 1491 | 1570 | $pa_ht = $result; |
| 1492 | 1571 | } |
@@ -1517,10 +1596,16 @@ discard block |
||
| 1517 | 1596 | $sql.= " ".price2num($total_ht).",".price2num($total_tva).",".price2num($total_localtax1).",".price2num($total_localtax2).",".price2num($total_ttc).","; |
| 1518 | 1597 | $sql.= " '".$info_bits."',"; |
| 1519 | 1598 | $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'; |
|
| 1599 | + if (isset($fk_fournprice)) { |
|
| 1600 | + $sql.= ' '.$fk_fournprice.','; |
|
| 1601 | + } else { |
|
| 1602 | + $sql.= ' null,'; |
|
| 1603 | + } |
|
| 1604 | + if (isset($pa_ht)) { |
|
| 1605 | + $sql.= ' '.price2num($pa_ht); |
|
| 1606 | + } else { |
|
| 1607 | + $sql.= ' null'; |
|
| 1608 | + } |
|
| 1524 | 1609 | if ($date_start > 0) { $sql.= ",'".$this->db->idate($date_start)."'"; } |
| 1525 | 1610 | if ($date_end > 0) { $sql.= ",'".$this->db->idate($date_end)."'"; } |
| 1526 | 1611 | $sql.= ", ".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null"); |
@@ -1535,9 +1620,11 @@ discard block |
||
| 1535 | 1620 | if ($result > 0) |
| 1536 | 1621 | { |
| 1537 | 1622 | |
| 1538 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used |
|
| 1623 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) { |
|
| 1624 | + // For avoid conflicts if trigger used |
|
| 1539 | 1625 | { |
| 1540 | 1626 | $contractline = new ContratLigne($this->db); |
| 1627 | + } |
|
| 1541 | 1628 | $contractline->array_options=$array_options; |
| 1542 | 1629 | $contractline->id=$contractlineid; |
| 1543 | 1630 | $result=$contractline->insertExtraFields(); |
@@ -1562,27 +1649,23 @@ discard block |
||
| 1562 | 1649 | { |
| 1563 | 1650 | $this->db->rollback(); |
| 1564 | 1651 | return -1; |
| 1565 | - } |
|
| 1566 | - else |
|
| 1652 | + } else |
|
| 1567 | 1653 | { |
| 1568 | 1654 | $this->db->commit(); |
| 1569 | 1655 | return $contractlineid; |
| 1570 | 1656 | } |
| 1571 | - } |
|
| 1572 | - else |
|
| 1657 | + } else |
|
| 1573 | 1658 | { |
| 1574 | 1659 | $this->db->rollback(); |
| 1575 | 1660 | return -1; |
| 1576 | 1661 | } |
| 1577 | - } |
|
| 1578 | - else |
|
| 1662 | + } else |
|
| 1579 | 1663 | { |
| 1580 | 1664 | $this->db->rollback(); |
| 1581 | 1665 | $this->error=$this->db->error()." sql=".$sql; |
| 1582 | 1666 | return -1; |
| 1583 | 1667 | } |
| 1584 | - } |
|
| 1585 | - else |
|
| 1668 | + } else |
|
| 1586 | 1669 | { |
| 1587 | 1670 | dol_syslog(get_class($this)."::addline ErrorTryToAddLineOnValidatedContract", LOG_ERR); |
| 1588 | 1671 | return -2; |
@@ -1632,8 +1715,7 @@ discard block |
||
| 1632 | 1715 | { |
| 1633 | 1716 | $remise = round(($pu * $remise_percent / 100), 2); |
| 1634 | 1717 | $price = $pu - $remise; |
| 1635 | - } |
|
| 1636 | - else |
|
| 1718 | + } else |
|
| 1637 | 1719 | { |
| 1638 | 1720 | $remise_percent=0; |
| 1639 | 1721 | } |
@@ -1670,7 +1752,9 @@ discard block |
||
| 1670 | 1752 | $price = $pu - $remise; |
| 1671 | 1753 | } |
| 1672 | 1754 | |
| 1673 | - if (empty($pa_ht)) $pa_ht=0; |
|
| 1755 | + if (empty($pa_ht)) { |
|
| 1756 | + $pa_ht=0; |
|
| 1757 | + } |
|
| 1674 | 1758 | |
| 1675 | 1759 | // if buy price not defined, define buyprice as configured in margin admin |
| 1676 | 1760 | if ($this->pa_ht == 0) |
@@ -1678,8 +1762,7 @@ discard block |
||
| 1678 | 1762 | if (($result = $this->defineBuyPrice($pu_ht, $remise_percent)) < 0) |
| 1679 | 1763 | { |
| 1680 | 1764 | return $result; |
| 1681 | - } |
|
| 1682 | - else |
|
| 1765 | + } else |
|
| 1683 | 1766 | { |
| 1684 | 1767 | $pa_ht = $result; |
| 1685 | 1768 | } |
@@ -1703,14 +1786,10 @@ discard block |
||
| 1703 | 1786 | $sql.= ", total_ttc='". price2num($total_ttc)."'"; |
| 1704 | 1787 | $sql.= ", fk_product_fournisseur_price='".$fk_fournprice."'"; |
| 1705 | 1788 | $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"; } |
|
| 1789 | + if ($date_start > 0) { $sql.= ",date_ouverture_prevue='".$this->db->idate($date_start)."'"; } else { $sql.=",date_ouverture_prevue=null"; } |
|
| 1790 | + if ($date_end > 0) { $sql.= ",date_fin_validite='".$this->db->idate($date_end)."'"; } else { $sql.=",date_fin_validite=null"; } |
|
| 1791 | + if ($date_debut_reel > 0) { $sql.= ",date_ouverture='".$this->db->idate($date_debut_reel)."'"; } else { $sql.=",date_ouverture=null"; } |
|
| 1792 | + if ($date_fin_reel > 0) { $sql.= ",date_cloture='".$this->db->idate($date_fin_reel)."'"; } else { $sql.=",date_cloture=null"; } |
|
| 1714 | 1793 | $sql .= ", fk_unit=".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null"); |
| 1715 | 1794 | $sql .= " WHERE rowid = ".$rowid; |
| 1716 | 1795 | |
@@ -1722,9 +1801,11 @@ discard block |
||
| 1722 | 1801 | if ($result >= 0) |
| 1723 | 1802 | { |
| 1724 | 1803 | |
| 1725 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used |
|
| 1804 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) { |
|
| 1805 | + // For avoid conflicts if trigger used |
|
| 1726 | 1806 | { |
| 1727 | 1807 | $contractline = new ContratLigne($this->db); |
| 1808 | + } |
|
| 1728 | 1809 | $contractline->array_options=$array_options; |
| 1729 | 1810 | $contractline->id= $rowid; |
| 1730 | 1811 | $result=$contractline->insertExtraFields(); |
@@ -1748,15 +1829,13 @@ discard block |
||
| 1748 | 1829 | $this->db->commit(); |
| 1749 | 1830 | return 1; |
| 1750 | 1831 | } |
| 1751 | - } |
|
| 1752 | - else |
|
| 1832 | + } else |
|
| 1753 | 1833 | { |
| 1754 | 1834 | $this->db->rollback(); |
| 1755 | 1835 | dol_syslog(get_class($this)."::updateligne Erreur -2"); |
| 1756 | 1836 | return -2; |
| 1757 | 1837 | } |
| 1758 | - } |
|
| 1759 | - else |
|
| 1838 | + } else |
|
| 1760 | 1839 | { |
| 1761 | 1840 | $this->db->rollback(); |
| 1762 | 1841 | $this->error=$this->db->error(); |
@@ -1783,7 +1862,9 @@ discard block |
||
| 1783 | 1862 | |
| 1784 | 1863 | // Call trigger |
| 1785 | 1864 | $result=$this->call_trigger('LINECONTRACT_DELETE',$user); |
| 1786 | - if ($result < 0) return -1; |
|
| 1865 | + if ($result < 0) { |
|
| 1866 | + return -1; |
|
| 1867 | + } |
|
| 1787 | 1868 | // End call triggers |
| 1788 | 1869 | |
| 1789 | 1870 | $this->db->begin(); |
@@ -1801,9 +1882,11 @@ discard block |
||
| 1801 | 1882 | |
| 1802 | 1883 | if (empty($error)) { |
| 1803 | 1884 | // Remove extrafields |
| 1804 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used |
|
| 1885 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 1886 | + // For avoid conflicts if trigger used |
|
| 1805 | 1887 | { |
| 1806 | 1888 | $contractline = new ContratLigne($this->db); |
| 1889 | + } |
|
| 1807 | 1890 | $contractline->id= $idline; |
| 1808 | 1891 | $result=$contractline->deleteExtraFields(); |
| 1809 | 1892 | if ($result < 0) |
@@ -1822,8 +1905,7 @@ discard block |
||
| 1822 | 1905 | $this->db->rollback(); |
| 1823 | 1906 | return -1; |
| 1824 | 1907 | } |
| 1825 | - } |
|
| 1826 | - else |
|
| 1908 | + } else |
|
| 1827 | 1909 | { |
| 1828 | 1910 | return -2; |
| 1829 | 1911 | } |
@@ -1842,7 +1924,9 @@ discard block |
||
| 1842 | 1924 | dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING); |
| 1843 | 1925 | |
| 1844 | 1926 | // If draft, we keep it (should not happen) |
| 1845 | - if ($this->statut == 0) return 1; |
|
| 1927 | + if ($this->statut == 0) { |
|
| 1928 | + return 1; |
|
| 1929 | + } |
|
| 1846 | 1930 | |
| 1847 | 1931 | // Load $this->lines array |
| 1848 | 1932 | // $this->fetch_lines(); |
@@ -1956,8 +2040,12 @@ discard block |
||
| 1956 | 2040 | //{ |
| 1957 | 2041 | // Add param to save lastsearch_values or not |
| 1958 | 2042 | $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'; |
|
| 2043 | + if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) { |
|
| 2044 | + $add_save_lastsearch_values=1; |
|
| 2045 | + } |
|
| 2046 | + if ($add_save_lastsearch_values) { |
|
| 2047 | + $url.='&save_lastsearch_values=1'; |
|
| 2048 | + } |
|
| 1961 | 2049 | //} |
| 1962 | 2050 | |
| 1963 | 2051 | $picto = 'contract'; |
@@ -1995,8 +2083,12 @@ discard block |
||
| 1995 | 2083 | $linkstart.=$linkclose.'>'; |
| 1996 | 2084 | $linkend='</a>'; |
| 1997 | 2085 | |
| 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.=' '; |
|
| 2086 | + if ($withpicto) { |
|
| 2087 | + $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); |
|
| 2088 | + } |
|
| 2089 | + if ($withpicto && $withpicto != 2) { |
|
| 2090 | + $result.=' '; |
|
| 2091 | + } |
|
| 2000 | 2092 | $result.=$linkstart.$this->ref.$linkend; |
| 2001 | 2093 | return $result; |
| 2002 | 2094 | } |
@@ -2043,8 +2135,7 @@ discard block |
||
| 2043 | 2135 | |
| 2044 | 2136 | $this->db->free($result); |
| 2045 | 2137 | |
| 2046 | - } |
|
| 2047 | - else |
|
| 2138 | + } else |
|
| 2048 | 2139 | { |
| 2049 | 2140 | dol_print_error($this->db); |
| 2050 | 2141 | } |
@@ -2063,7 +2154,9 @@ discard block |
||
| 2063 | 2154 | $sql = "SELECT cd.rowid"; |
| 2064 | 2155 | $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; |
| 2065 | 2156 | $sql.= " WHERE fk_contrat =".$this->id; |
| 2066 | - if ($statut >= 0) $sql.= " AND statut = '$statut'"; |
|
| 2157 | + if ($statut >= 0) { |
|
| 2158 | + $sql.= " AND statut = '$statut'"; |
|
| 2159 | + } |
|
| 2067 | 2160 | |
| 2068 | 2161 | dol_syslog(get_class($this)."::array_detail()", LOG_DEBUG); |
| 2069 | 2162 | $resql=$this->db->query($sql); |
@@ -2078,8 +2171,7 @@ discard block |
||
| 2078 | 2171 | $i++; |
| 2079 | 2172 | } |
| 2080 | 2173 | return $tab; |
| 2081 | - } |
|
| 2082 | - else |
|
| 2174 | + } else |
|
| 2083 | 2175 | { |
| 2084 | 2176 | $this->error=$this->db->error(); |
| 2085 | 2177 | return -1; |
@@ -2099,7 +2191,9 @@ discard block |
||
| 2099 | 2191 | $sql = "SELECT c.rowid, c.ref"; |
| 2100 | 2192 | $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c"; |
| 2101 | 2193 | $sql.= " WHERE fk_soc =".$this->socid; |
| 2102 | - if ($option == 'others') $sql.= " AND c.rowid != ".$this->id; |
|
| 2194 | + if ($option == 'others') { |
|
| 2195 | + $sql.= " AND c.rowid != ".$this->id; |
|
| 2196 | + } |
|
| 2103 | 2197 | |
| 2104 | 2198 | dol_syslog(get_class($this)."::getOtherContracts()", LOG_DEBUG); |
| 2105 | 2199 | $resql=$this->db->query($sql); |
@@ -2116,8 +2210,7 @@ discard block |
||
| 2116 | 2210 | $i++; |
| 2117 | 2211 | } |
| 2118 | 2212 | return $tab; |
| 2119 | - } |
|
| 2120 | - else |
|
| 2213 | + } else |
|
| 2121 | 2214 | { |
| 2122 | 2215 | $this->error=$this->db->error(); |
| 2123 | 2216 | return -1; |
@@ -2139,7 +2232,9 @@ discard block |
||
| 2139 | 2232 | $this->from = " FROM ".MAIN_DB_PREFIX."contrat as c"; |
| 2140 | 2233 | $this->from.= ", ".MAIN_DB_PREFIX."contratdet as cd"; |
| 2141 | 2234 | $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"; |
|
| 2235 | + if (!$user->rights->societe->client->voir && !$user->societe_id) { |
|
| 2236 | + $this->from.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 2237 | + } |
|
| 2143 | 2238 | |
| 2144 | 2239 | if ($mode == 'inactives') |
| 2145 | 2240 | { |
@@ -2160,8 +2255,12 @@ discard block |
||
| 2160 | 2255 | } |
| 2161 | 2256 | $sql.= " AND c.fk_soc = s.rowid"; |
| 2162 | 2257 | $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; |
|
| 2258 | + if ($user->societe_id) { |
|
| 2259 | + $sql.=" AND c.fk_soc = ".$user->societe_id; |
|
| 2260 | + } |
|
| 2261 | + if (!$user->rights->societe->client->voir && !$user->societe_id) { |
|
| 2262 | + $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; |
|
| 2263 | + } |
|
| 2165 | 2264 | $resql=$this->db->query($sql); |
| 2166 | 2265 | if ($resql) |
| 2167 | 2266 | { |
@@ -2194,8 +2293,7 @@ discard block |
||
| 2194 | 2293 | } |
| 2195 | 2294 | |
| 2196 | 2295 | return $response; |
| 2197 | - } |
|
| 2198 | - else |
|
| 2296 | + } else |
|
| 2199 | 2297 | { |
| 2200 | 2298 | dol_print_error($this->db); |
| 2201 | 2299 | $this->error=$this->db->error(); |
@@ -2235,8 +2333,7 @@ discard block |
||
| 2235 | 2333 | } |
| 2236 | 2334 | $this->db->free($resql); |
| 2237 | 2335 | return 1; |
| 2238 | - } |
|
| 2239 | - else |
|
| 2336 | + } else |
|
| 2240 | 2337 | { |
| 2241 | 2338 | dol_print_error($this->db); |
| 2242 | 2339 | $this->error=$this->db->error(); |
@@ -2474,8 +2571,9 @@ discard block |
||
| 2474 | 2571 | ); |
| 2475 | 2572 | $action = ''; |
| 2476 | 2573 | $reshook = $hookmanager->executeHooks('createFrom', $parameters, $clonedObj, $action); // Note that $action and $object may have been modified by some hooks |
| 2477 | - if ($reshook < 0) |
|
| 2478 | - $error ++; |
|
| 2574 | + if ($reshook < 0) { |
|
| 2575 | + $error ++; |
|
| 2576 | + } |
|
| 2479 | 2577 | } |
| 2480 | 2578 | |
| 2481 | 2579 | } |
@@ -2674,17 +2772,27 @@ discard block |
||
| 2674 | 2772 | |
| 2675 | 2773 | $result=''; |
| 2676 | 2774 | $label=$langs->trans("ShowContractOfService").': '.$this->label; |
| 2677 | - if (empty($label)) $label=$this->description; |
|
| 2775 | + if (empty($label)) { |
|
| 2776 | + $label=$this->description; |
|
| 2777 | + } |
|
| 2678 | 2778 | |
| 2679 | 2779 | $link = '<a href="'.DOL_URL_ROOT.'/contrat/card.php?id='.$this->fk_contrat.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
| 2680 | 2780 | $linkend='</a>'; |
| 2681 | 2781 | |
| 2682 | 2782 | $picto='service'; |
| 2683 | - if ($this->type == 0) $picto='product'; |
|
| 2783 | + if ($this->type == 0) { |
|
| 2784 | + $picto='product'; |
|
| 2785 | + } |
|
| 2684 | 2786 | |
| 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; |
|
| 2787 | + if ($withpicto) { |
|
| 2788 | + $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
| 2789 | + } |
|
| 2790 | + if ($withpicto && $withpicto != 2) { |
|
| 2791 | + $result.=' '; |
|
| 2792 | + } |
|
| 2793 | + if ($withpicto != 2) { |
|
| 2794 | + $result.=$link.($this->product_ref?$this->product_ref.' ':'').($this->label?$this->label:$this->description).$linkend; |
|
| 2795 | + } |
|
| 2688 | 2796 | return $result; |
| 2689 | 2797 | } |
| 2690 | 2798 | |
@@ -2699,7 +2807,9 @@ discard block |
||
| 2699 | 2807 | { |
| 2700 | 2808 | |
| 2701 | 2809 | // Check parameters |
| 2702 | - if (empty($id) && empty($ref)) return -1; |
|
| 2810 | + if (empty($id) && empty($ref)) { |
|
| 2811 | + return -1; |
|
| 2812 | + } |
|
| 2703 | 2813 | |
| 2704 | 2814 | $sql = "SELECT"; |
| 2705 | 2815 | $sql.= " t.rowid,"; |
@@ -2745,8 +2855,12 @@ discard block |
||
| 2745 | 2855 | $sql.= " t.commentaire,"; |
| 2746 | 2856 | $sql.= " t.fk_unit"; |
| 2747 | 2857 | $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)."'"; |
|
| 2858 | + if ($id) { |
|
| 2859 | + $sql.= " WHERE t.rowid = ".$id; |
|
| 2860 | + } |
|
| 2861 | + if ($ref) { |
|
| 2862 | + $sql.= " WHERE t.rowid = '".$this->db->escape($ref)."'"; |
|
| 2863 | + } |
|
| 2750 | 2864 | |
| 2751 | 2865 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
| 2752 | 2866 | $resql=$this->db->query($sql); |
@@ -2805,8 +2919,7 @@ discard block |
||
| 2805 | 2919 | $this->db->free($resql); |
| 2806 | 2920 | |
| 2807 | 2921 | return 1; |
| 2808 | - } |
|
| 2809 | - else |
|
| 2922 | + } else |
|
| 2810 | 2923 | { |
| 2811 | 2924 | $this->error="Error ".$this->db->lasterror(); |
| 2812 | 2925 | return -1; |
@@ -2854,13 +2967,27 @@ discard block |
||
| 2854 | 2967 | $this->fk_user_cloture=trim($this->fk_user_cloture); |
| 2855 | 2968 | $this->commentaire=trim($this->commentaire); |
| 2856 | 2969 | //if (empty($this->subprice)) $this->subprice = 0; |
| 2857 | - if (empty($this->price_ht)) $this->price_ht = 0; |
|
| 2858 | - if (empty($this->total_ht)) $this->total_ht = 0; |
|
| 2859 | - if (empty($this->total_tva)) $this->total_tva = 0; |
|
| 2860 | - if (empty($this->total_ttc)) $this->total_ttc = 0; |
|
| 2861 | - if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; |
|
| 2862 | - if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; |
|
| 2863 | - if (empty($this->remise_percent)) $this->remise_percent = 0; |
|
| 2970 | + if (empty($this->price_ht)) { |
|
| 2971 | + $this->price_ht = 0; |
|
| 2972 | + } |
|
| 2973 | + if (empty($this->total_ht)) { |
|
| 2974 | + $this->total_ht = 0; |
|
| 2975 | + } |
|
| 2976 | + if (empty($this->total_tva)) { |
|
| 2977 | + $this->total_tva = 0; |
|
| 2978 | + } |
|
| 2979 | + if (empty($this->total_ttc)) { |
|
| 2980 | + $this->total_ttc = 0; |
|
| 2981 | + } |
|
| 2982 | + if (empty($this->localtax1_tx)) { |
|
| 2983 | + $this->localtax1_tx = 0; |
|
| 2984 | + } |
|
| 2985 | + if (empty($this->localtax2_tx)) { |
|
| 2986 | + $this->localtax2_tx = 0; |
|
| 2987 | + } |
|
| 2988 | + if (empty($this->remise_percent)) { |
|
| 2989 | + $this->remise_percent = 0; |
|
| 2990 | + } |
|
| 2864 | 2991 | |
| 2865 | 2992 | // Check parameters |
| 2866 | 2993 | // Put here code to add control on parameters values |
@@ -2878,7 +3005,9 @@ discard block |
||
| 2878 | 3005 | $this->total_localtax1= $tabprice[9]; |
| 2879 | 3006 | $this->total_localtax2= $tabprice[10]; |
| 2880 | 3007 | |
| 2881 | - if (empty($this->pa_ht)) $this->pa_ht=0; |
|
| 3008 | + if (empty($this->pa_ht)) { |
|
| 3009 | + $this->pa_ht=0; |
|
| 3010 | + } |
|
| 2882 | 3011 | |
| 2883 | 3012 | // if buy price not defined, define buyprice as configured in margin admin |
| 2884 | 3013 | if ($this->pa_ht == 0) |
@@ -2886,8 +3015,7 @@ discard block |
||
| 2886 | 3015 | if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) |
| 2887 | 3016 | { |
| 2888 | 3017 | return $result; |
| 2889 | - } |
|
| 2890 | - else |
|
| 3018 | + } else |
|
| 2891 | 3019 | { |
| 2892 | 3020 | $this->pa_ht = $result; |
| 2893 | 3021 | } |
@@ -2940,18 +3068,19 @@ discard block |
||
| 2940 | 3068 | $contrat=new Contrat($this->db); |
| 2941 | 3069 | $contrat->fetch($this->fk_contrat); |
| 2942 | 3070 | $result=$contrat->update_statut($user); |
| 2943 | - } |
|
| 2944 | - else |
|
| 3071 | + } else |
|
| 2945 | 3072 | { |
| 2946 | 3073 | $this->error="Error ".$this->db->lasterror(); |
| 2947 | 3074 | $error++; |
| 2948 | 3075 | //return -1; |
| 2949 | 3076 | } |
| 2950 | 3077 | |
| 2951 | - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used |
|
| 3078 | + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) { |
|
| 3079 | + // For avoid conflicts if trigger used |
|
| 2952 | 3080 | { |
| 2953 | 3081 | |
| 2954 | 3082 | $result=$this->insertExtraFields(); |
| 3083 | + } |
|
| 2955 | 3084 | if ($result < 0) |
| 2956 | 3085 | { |
| 2957 | 3086 | $error++; |
@@ -3005,8 +3134,7 @@ discard block |
||
| 3005 | 3134 | { |
| 3006 | 3135 | $this->db->commit(); |
| 3007 | 3136 | return 1; |
| 3008 | - } |
|
| 3009 | - else |
|
| 3137 | + } else |
|
| 3010 | 3138 | { |
| 3011 | 3139 | $this->error=$this->db->error(); |
| 3012 | 3140 | $this->db->rollback(); |
@@ -3047,10 +3175,16 @@ discard block |
||
| 3047 | 3175 | $sql.= " ".price2num($this->total_ht).",".price2num($this->total_tva).",".price2num($this->total_localtax1).",".price2num($this->total_localtax2).",".price2num($this->total_ttc).","; |
| 3048 | 3176 | $sql.= " '".$this->db->escape($this->info_bits)."',"; |
| 3049 | 3177 | $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'; |
|
| 3178 | + if ($this->fk_fournprice > 0) { |
|
| 3179 | + $sql.= ' '.$this->fk_fournprice.','; |
|
| 3180 | + } else { |
|
| 3181 | + $sql.= ' null,'; |
|
| 3182 | + } |
|
| 3183 | + if ($this->pa_ht > 0) { |
|
| 3184 | + $sql.= ' '.price2num($this->pa_ht); |
|
| 3185 | + } else { |
|
| 3186 | + $sql.= ' null'; |
|
| 3187 | + } |
|
| 3054 | 3188 | if ($this->date_ouverture_prevue > 0) { $sql.= ",'".$this->db->idate($this->date_ouverture_prevue)."'"; } |
| 3055 | 3189 | if ($this->date_fin_validite > 0) { $sql.= ",'".$this->db->idate($this->date_fin_validite)."'"; } |
| 3056 | 3190 | $sql.= ")"; |
@@ -3077,8 +3211,7 @@ discard block |
||
| 3077 | 3211 | |
| 3078 | 3212 | $this->db->commit(); |
| 3079 | 3213 | return 1; |
| 3080 | - } |
|
| 3081 | - else |
|
| 3214 | + } else |
|
| 3082 | 3215 | { |
| 3083 | 3216 | $this->db->rollback(); |
| 3084 | 3217 | $this->error=$this->db->error()." sql=".$sql; |
@@ -3112,7 +3245,9 @@ discard block |
||
| 3112 | 3245 | |
| 3113 | 3246 | $sql = "UPDATE " . MAIN_DB_PREFIX . "contratdet SET statut = 4,"; |
| 3114 | 3247 | $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") . ","; |
|
| 3248 | + if ($date_end >= 0) { |
|
| 3249 | + $sql .= " date_fin_validite = " . (dol_strlen($date_end) != 0 ? "'" . $this->db->idate($date_end) . "'" : "null") . ","; |
|
| 3250 | + } |
|
| 3116 | 3251 | $sql .= " fk_user_ouverture = " . $user->id . ","; |
| 3117 | 3252 | $sql .= " date_cloture = null,"; |
| 3118 | 3253 | $sql .= " commentaire = '" . $this->db->escape($comment) . "'"; |
@@ -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 | { |
@@ -27,19 +27,19 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class FormIntervention |
| 29 | 29 | { |
| 30 | - var $db; |
|
| 31 | - var $error; |
|
| 30 | + var $db; |
|
| 31 | + var $error; |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor |
|
| 36 | - * |
|
| 37 | - * @param DoliDB $db Database handler |
|
| 38 | - */ |
|
| 39 | - public function __construct($db) |
|
| 40 | - { |
|
| 41 | - $this->db = $db; |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor |
|
| 36 | + * |
|
| 37 | + * @param DoliDB $db Database handler |
|
| 38 | + */ |
|
| 39 | + public function __construct($db) |
|
| 40 | + { |
|
| 41 | + $this->db = $db; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -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 | } |
@@ -66,8 +66,11 @@ discard block |
||
| 66 | 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') { |
|
| 70 | + $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)"; |
|
| 71 | + } else { |
|
| 72 | + $sql.= " AND f.fk_soc = ".$socid; |
|
| 73 | + } |
|
| 71 | 74 | } |
| 72 | 75 | |
| 73 | 76 | dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG); |
@@ -75,7 +78,9 @@ discard block |
||
| 75 | 78 | if ($resql) |
| 76 | 79 | { |
| 77 | 80 | $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">'; |
| 78 | - if ($showempty) $out.='<option value="0"> </option>'; |
|
| 81 | + if ($showempty) { |
|
| 82 | + $out.='<option value="0"> </option>'; |
|
| 83 | + } |
|
| 79 | 84 | $num = $db->num_rows($resql); |
| 80 | 85 | $i = 0; |
| 81 | 86 | if ($num) |
@@ -87,15 +92,13 @@ discard block |
||
| 87 | 92 | if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire) |
| 88 | 93 | { |
| 89 | 94 | // Do nothing |
| 90 | - } |
|
| 91 | - else |
|
| 95 | + } else |
|
| 92 | 96 | { |
| 93 | 97 | $labeltoshow=dol_trunc($obj->ref,18); |
| 94 | 98 | if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0) |
| 95 | 99 | { |
| 96 | 100 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
| 97 | - } |
|
| 98 | - else |
|
| 101 | + } else |
|
| 99 | 102 | { |
| 100 | 103 | $disabled=0; |
| 101 | 104 | if (! $obj->fk_statut > 0) |
@@ -112,11 +115,12 @@ discard block |
||
| 112 | 115 | if ($hideunselectables && $disabled) |
| 113 | 116 | { |
| 114 | 117 | $resultat=''; |
| 115 | - } |
|
| 116 | - else |
|
| 118 | + } else |
|
| 117 | 119 | { |
| 118 | 120 | $resultat='<option value="'.$obj->rowid.'"'; |
| 119 | - if ($disabled) $resultat.=' disabled'; |
|
| 121 | + if ($disabled) { |
|
| 122 | + $resultat.=' disabled'; |
|
| 123 | + } |
|
| 120 | 124 | $resultat.='>'.$labeltoshow; |
| 121 | 125 | $resultat.='</option>'; |
| 122 | 126 | } |
@@ -129,8 +133,7 @@ discard block |
||
| 129 | 133 | $out.='</select>'; |
| 130 | 134 | $db->free($resql); |
| 131 | 135 | return $out; |
| 132 | - } |
|
| 133 | - else |
|
| 136 | + } else |
|
| 134 | 137 | { |
| 135 | 138 | dol_print_error($db); |
| 136 | 139 | return ''; |
@@ -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 | { |
@@ -28,21 +28,21 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | class FormMargin |
| 30 | 30 | { |
| 31 | - var $db; |
|
| 32 | - var $error; |
|
| 31 | + var $db; |
|
| 32 | + var $error; |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor |
|
| 37 | - * |
|
| 38 | - * @param DoliDB $db Database handler |
|
| 39 | - */ |
|
| 40 | - function __construct($db) |
|
| 41 | - { |
|
| 42 | - $this->db = $db; |
|
| 35 | + /** |
|
| 36 | + * Constructor |
|
| 37 | + * |
|
| 38 | + * @param DoliDB $db Database handler |
|
| 39 | + */ |
|
| 40 | + function __construct($db) |
|
| 41 | + { |
|
| 42 | + $this->db = $db; |
|
| 43 | 43 | |
| 44 | - return 1; |
|
| 45 | - } |
|
| 44 | + return 1; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | //} |
| 143 | 143 | //else |
| 144 | 144 | //{ |
| 145 | - $marginInfos['margin_on_products'] += $pv - $pa; |
|
| 145 | + $marginInfos['margin_on_products'] += $pv - $pa; |
|
| 146 | 146 | //} |
| 147 | 147 | } |
| 148 | 148 | elseif ($type == 1) { // service |
@@ -192,26 +192,26 @@ discard block |
||
| 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 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
|
| 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 | 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 | - $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>'; |
|
| 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>'; |
|
| 209 | 209 | |
| 210 | - print '<script>$(document).ready(function() { |
|
| 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");})}); |
| 212 | 212 | $("span#hideMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 1); $(".margininfos").hide(); $("span#hideMarginInfos").addClass("hideobject"); $("span#showMarginInfos").removeClass("hideobject");})}); |
| 213 | 213 | });</script>'; |
| 214 | - if (!empty($hidemargininfos)) print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>'; |
|
| 214 | + if (!empty($hidemargininfos)) print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>'; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | print '<!-- Margin table -->'."\n"; |
@@ -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>'; |
@@ -83,10 +83,12 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
| 85 | 85 | $product = new ProductFournisseur($db); |
| 86 | - if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) |
|
| 87 | - $line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100); |
|
| 88 | - if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0) |
|
| 89 | - $line->pa_ht += $product->fourn_unitcharges; |
|
| 86 | + if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) { |
|
| 87 | + $line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100); |
|
| 88 | + } |
|
| 89 | + if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0) { |
|
| 90 | + $line->pa_ht += $product->fourn_unitcharges; |
|
| 91 | + } |
|
| 90 | 92 | } |
| 91 | 93 | // si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente |
| 92 | 94 | if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { |
@@ -111,8 +113,7 @@ discard block |
||
| 111 | 113 | //} |
| 112 | 114 | //else |
| 113 | 115 | $marginInfos['margin_on_products'] += $pv - $pa; |
| 114 | - } |
|
| 115 | - elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service |
|
| 116 | + } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service |
|
| 116 | 117 | $marginInfos['pa_services'] += $pa; |
| 117 | 118 | $marginInfos['pv_services'] += $pv; |
| 118 | 119 | $marginInfos['pa_total'] += $pa; |
@@ -122,13 +123,11 @@ discard block |
||
| 122 | 123 | // $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); |
| 123 | 124 | //else |
| 124 | 125 | $marginInfos['margin_on_services'] += $pv - $pa; |
| 125 | - } |
|
| 126 | - elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total |
|
| 126 | + } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total |
|
| 127 | 127 | $marginInfos['pa_total'] += $pa; |
| 128 | 128 | $marginInfos['pv_total'] += $pv; |
| 129 | 129 | } |
| 130 | - } |
|
| 131 | - else { |
|
| 130 | + } else { |
|
| 132 | 131 | $type=$line->product_type?$line->product_type:$line->fk_product_type; |
| 133 | 132 | if ($type == 0) { // product |
| 134 | 133 | $marginInfos['pa_products'] += $pa; |
@@ -144,8 +143,7 @@ discard block |
||
| 144 | 143 | //{ |
| 145 | 144 | $marginInfos['margin_on_products'] += $pv - $pa; |
| 146 | 145 | //} |
| 147 | - } |
|
| 148 | - elseif ($type == 1) { // service |
|
| 146 | + } elseif ($type == 1) { // service |
|
| 149 | 147 | $marginInfos['pa_services'] += $pa; |
| 150 | 148 | $marginInfos['pv_services'] += $pv; |
| 151 | 149 | $marginInfos['pa_total'] += $pa; |
@@ -158,25 +156,31 @@ discard block |
||
| 158 | 156 | } |
| 159 | 157 | } |
| 160 | 158 | } |
| 161 | - if ($marginInfos['pa_products'] > 0) |
|
| 162 | - $marginInfos['margin_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pa_products']; |
|
| 163 | - if ($marginInfos['pv_products'] > 0) |
|
| 164 | - $marginInfos['mark_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pv_products']; |
|
| 159 | + if ($marginInfos['pa_products'] > 0) { |
|
| 160 | + $marginInfos['margin_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pa_products']; |
|
| 161 | + } |
|
| 162 | + if ($marginInfos['pv_products'] > 0) { |
|
| 163 | + $marginInfos['mark_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pv_products']; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - if ($marginInfos['pa_services'] > 0) |
|
| 167 | - $marginInfos['margin_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pa_services']; |
|
| 168 | - if ($marginInfos['pv_services'] > 0) |
|
| 169 | - $marginInfos['mark_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pv_services']; |
|
| 166 | + if ($marginInfos['pa_services'] > 0) { |
|
| 167 | + $marginInfos['margin_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pa_services']; |
|
| 168 | + } |
|
| 169 | + if ($marginInfos['pv_services'] > 0) { |
|
| 170 | + $marginInfos['mark_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pv_services']; |
|
| 171 | + } |
|
| 170 | 172 | |
| 171 | 173 | // if credit note, margin = -1 * (abs(selling_price) - buying_price) |
| 172 | 174 | //if ($marginInfos['pv_total'] < 0) |
| 173 | 175 | // $marginInfos['total_margin'] = -1 * (abs($marginInfos['pv_total']) - $marginInfos['pa_total']); |
| 174 | 176 | //else |
| 175 | 177 | $marginInfos['total_margin'] = $marginInfos['pv_total'] - $marginInfos['pa_total']; |
| 176 | - if ($marginInfos['pa_total'] > 0) |
|
| 177 | - $marginInfos['total_margin_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pa_total']; |
|
| 178 | - if ($marginInfos['pv_total'] > 0) |
|
| 179 | - $marginInfos['total_mark_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pv_total']; |
|
| 178 | + if ($marginInfos['pa_total'] > 0) { |
|
| 179 | + $marginInfos['total_margin_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pa_total']; |
|
| 180 | + } |
|
| 181 | + if ($marginInfos['pv_total'] > 0) { |
|
| 182 | + $marginInfos['total_mark_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pv_total']; |
|
| 183 | + } |
|
| 180 | 184 | |
| 181 | 185 | return $marginInfos; |
| 182 | 186 | } |
@@ -192,17 +196,23 @@ discard block |
||
| 192 | 196 | { |
| 193 | 197 | global $langs, $conf, $user; |
| 194 | 198 | |
| 195 | - if (! empty($user->societe_id)) return; |
|
| 199 | + if (! empty($user->societe_id)) { |
|
| 200 | + return; |
|
| 201 | + } |
|
| 196 | 202 | |
| 197 | - if (! $user->rights->margins->liretous) return; |
|
| 203 | + if (! $user->rights->margins->liretous) { |
|
| 204 | + return; |
|
| 205 | + } |
|
| 198 | 206 | |
| 199 | 207 | $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); |
| 200 | 208 | |
| 201 | 209 | $marginInfo = $this->getMarginInfosArray($object, $force_price); |
| 202 | 210 | |
| 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 |
|
| 211 | + if (! empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) { |
|
| 212 | + // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better |
|
| 204 | 213 | { |
| 205 | 214 | print $langs->trans('ShowMarginInfos').' : '; |
| 215 | + } |
|
| 206 | 216 | $hidemargininfos = $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']; |
| 207 | 217 | print '<span id="showMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'':'hideobject').'">'.img_picto($langs->trans("Disabled"),'switch_off').'</span>'; |
| 208 | 218 | print '<span id="hideMarginInfos" class="linkobject '.(!empty($hidemargininfos)?'hideobject':'').'">'.img_picto($langs->trans("Enabled"),'switch_on').'</span>'; |
@@ -211,7 +221,9 @@ discard block |
||
| 211 | 221 | $("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");})}); |
| 212 | 222 | $("span#hideMarginInfos").click(function() { $.getScript( "'.dol_buildpath('/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js', 1).'", function( data, textStatus, jqxhr ) { $.cookie("DOLUSER_MARGININFO_HIDE_SHOW", 1); $(".margininfos").hide(); $("span#hideMarginInfos").addClass("hideobject"); $("span#showMarginInfos").removeClass("hideobject");})}); |
| 213 | 223 | });</script>'; |
| 214 | - if (!empty($hidemargininfos)) print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>'; |
|
| 224 | + if (!empty($hidemargininfos)) { |
|
| 225 | + print '<script>$(document).ready(function() {$(".margininfos").hide();});</script>'; |
|
| 226 | + } |
|
| 215 | 227 | } |
| 216 | 228 | |
| 217 | 229 | print '<!-- Margin table -->'."\n"; |
@@ -219,15 +231,18 @@ discard block |
||
| 219 | 231 | print '<tr class="liste_titre">'; |
| 220 | 232 | print '<td class="liste_titre">'.$langs->trans('Margins').'</td>'; |
| 221 | 233 | print '<td class="liste_titre" align="right">'.$langs->trans('SellingPrice').'</td>'; |
| 222 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 223 | - print '<td class="liste_titre" align="right">'.$langs->trans('BuyingPrice').'</td>'; |
|
| 224 | - else |
|
| 225 | - print '<td class="liste_titre" align="right">'.$langs->trans('CostPrice').'</td>'; |
|
| 234 | + if ($conf->global->MARGIN_TYPE == "1") { |
|
| 235 | + print '<td class="liste_titre" align="right">'.$langs->trans('BuyingPrice').'</td>'; |
|
| 236 | + } else { |
|
| 237 | + print '<td class="liste_titre" align="right">'.$langs->trans('CostPrice').'</td>'; |
|
| 238 | + } |
|
| 226 | 239 | print '<td class="liste_titre" align="right">'.$langs->trans('Margin').'</td>'; |
| 227 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
| 228 | - print '<td class="liste_titre" align="right">'.$langs->trans('MarginRate').'</td>'; |
|
| 229 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
| 230 | - print '<td class="liste_titre" align="right">'.$langs->trans('MarkRate').'</td>'; |
|
| 240 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 241 | + print '<td class="liste_titre" align="right">'.$langs->trans('MarginRate').'</td>'; |
|
| 242 | + } |
|
| 243 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 244 | + print '<td class="liste_titre" align="right">'.$langs->trans('MarkRate').'</td>'; |
|
| 245 | + } |
|
| 231 | 246 | print '</tr>'; |
| 232 | 247 | |
| 233 | 248 | if (! empty($conf->product->enabled)) |
@@ -238,10 +253,12 @@ discard block |
||
| 238 | 253 | print '<td align="right">'.price($marginInfo['pv_products'], null, null, null, null, $rounding).'</td>'; |
| 239 | 254 | print '<td align="right">'.price($marginInfo['pa_products'], null, null, null, null, $rounding).'</td>'; |
| 240 | 255 | 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>'; |
|
| 256 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 257 | + print '<td align="right">'.(($marginInfo['margin_rate_products'] == '')?'':price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 258 | + } |
|
| 259 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 260 | + print '<td align="right">'.(($marginInfo['mark_rate_products'] == '')?'':price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 261 | + } |
|
| 245 | 262 | print '</tr>'; |
| 246 | 263 | } |
| 247 | 264 | |
@@ -252,10 +269,12 @@ discard block |
||
| 252 | 269 | print '<td align="right">'.price($marginInfo['pv_services'], null, null, null, null, $rounding).'</td>'; |
| 253 | 270 | print '<td align="right">'.price($marginInfo['pa_services'], null, null, null, null, $rounding).'</td>'; |
| 254 | 271 | 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>'; |
|
| 272 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 273 | + print '<td align="right">'.(($marginInfo['margin_rate_services'] == '')?'':price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 274 | + } |
|
| 275 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 276 | + print '<td align="right">'.(($marginInfo['mark_rate_services'] == '')?'':price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 277 | + } |
|
| 259 | 278 | print '</tr>'; |
| 260 | 279 | } |
| 261 | 280 | |
@@ -266,10 +285,12 @@ discard block |
||
| 266 | 285 | print '<td align="right">'.price($marginInfo['pv_total'], null, null, null, null, $rounding).'</td>'; |
| 267 | 286 | print '<td align="right">'.price($marginInfo['pa_total'], null, null, null, null, $rounding).'</td>'; |
| 268 | 287 | 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>'; |
|
| 288 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
|
| 289 | + print '<td align="right">'.(($marginInfo['total_margin_rate'] == '')?'':price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 290 | + } |
|
| 291 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
|
| 292 | + print '<td align="right">'.(($marginInfo['total_mark_rate'] == '')?'':price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'</td>'; |
|
| 293 | + } |
|
| 273 | 294 | print '</tr>'; |
| 274 | 295 | } |
| 275 | 296 | 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 | |
@@ -119,8 +119,7 @@ discard block |
||
| 119 | 119 | dol_syslog('',0,1); |
| 120 | 120 | } |
| 121 | 121 | return $ret; |
| 122 | - } |
|
| 123 | - else |
|
| 122 | + } else |
|
| 124 | 123 | { |
| 125 | 124 | $this->transaction_opened++; |
| 126 | 125 | dol_syslog('',0,1); |
@@ -145,13 +144,11 @@ discard block |
||
| 145 | 144 | $this->transaction_opened=0; |
| 146 | 145 | dol_syslog("COMMIT Transaction".($log?' '.$log:''),LOG_DEBUG); |
| 147 | 146 | return 1; |
| 148 | - } |
|
| 149 | - else |
|
| 147 | + } else |
|
| 150 | 148 | { |
| 151 | 149 | return 0; |
| 152 | 150 | } |
| 153 | - } |
|
| 154 | - else |
|
| 151 | + } else |
|
| 155 | 152 | { |
| 156 | 153 | $this->transaction_opened--; |
| 157 | 154 | return 1; |
@@ -173,8 +170,7 @@ discard block |
||
| 173 | 170 | $this->transaction_opened=0; |
| 174 | 171 | dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); |
| 175 | 172 | return $ret; |
| 176 | - } |
|
| 177 | - else |
|
| 173 | + } else |
|
| 178 | 174 | { |
| 179 | 175 | $this->transaction_opened--; |
| 180 | 176 | return 1; |
@@ -191,10 +187,17 @@ discard block |
||
| 191 | 187 | function plimit($limit=0,$offset=0) |
| 192 | 188 | { |
| 193 | 189 | global $conf; |
| 194 | - if (empty($limit)) return ""; |
|
| 195 | - if ($limit < 0) $limit=$conf->liste_limit; |
|
| 196 | - if ($offset > 0) return " LIMIT $offset,$limit "; |
|
| 197 | - else return " LIMIT $limit "; |
|
| 190 | + if (empty($limit)) { |
|
| 191 | + return ""; |
|
| 192 | + } |
|
| 193 | + if ($limit < 0) { |
|
| 194 | + $limit=$conf->liste_limit; |
|
| 195 | + } |
|
| 196 | + if ($offset > 0) { |
|
| 197 | + return " LIMIT $offset,$limit "; |
|
| 198 | + } else { |
|
| 199 | + return " LIMIT $limit "; |
|
| 200 | + } |
|
| 198 | 201 | } |
| 199 | 202 | |
| 200 | 203 | /** |
@@ -234,8 +237,11 @@ discard block |
||
| 234 | 237 | $i=0; |
| 235 | 238 | foreach($fields as $val) |
| 236 | 239 | { |
| 237 | - if (! $return) $return.=' ORDER BY '; |
|
| 238 | - else $return.=', '; |
|
| 240 | + if (! $return) { |
|
| 241 | + $return.=' ORDER BY '; |
|
| 242 | + } else { |
|
| 243 | + $return.=', '; |
|
| 244 | + } |
|
| 239 | 245 | |
| 240 | 246 | $return.=preg_replace('/[^0-9a-z_\.]/i','',$val); |
| 241 | 247 | |
@@ -251,8 +257,7 @@ discard block |
||
| 251 | 257 | $i++; |
| 252 | 258 | } |
| 253 | 259 | return $return; |
| 254 | - } |
|
| 255 | - else |
|
| 260 | + } else |
|
| 256 | 261 | { |
| 257 | 262 | return ''; |
| 258 | 263 | } |
@@ -279,7 +284,9 @@ discard block |
||
| 279 | 284 | */ |
| 280 | 285 | function jdate($string, $gm=false) |
| 281 | 286 | { |
| 282 | - if ($string==0 || $string=="0000-00-00 00:00:00") return ''; |
|
| 287 | + if ($string==0 || $string=="0000-00-00 00:00:00") { |
|
| 288 | + return ''; |
|
| 289 | + } |
|
| 283 | 290 | $string=preg_replace('/([^0-9])/i','',$string); |
| 284 | 291 | $tmp=$string.'000000'; |
| 285 | 292 | $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); |
@@ -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 | { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | /** @var resource Resultset of last query */ |
| 45 | 45 | private $_results; |
| 46 | 46 | |
| 47 | - /** |
|
| 47 | + /** |
|
| 48 | 48 | * Constructor. |
| 49 | 49 | * This create an opened connexion to a database server and eventually to a database |
| 50 | 50 | * |
@@ -54,14 +54,14 @@ discard block |
||
| 54 | 54 | * @param string $pass Mot de passe |
| 55 | 55 | * @param string $name Nom de la database |
| 56 | 56 | * @param int $port Port of database server |
| 57 | - */ |
|
| 57 | + */ |
|
| 58 | 58 | function __construct($type, $host, $user, $pass, $name='', $port=0) |
| 59 | 59 | { |
| 60 | 60 | global $langs; |
| 61 | 61 | |
| 62 | 62 | $this->database_user=$user; |
| 63 | - $this->database_host=$host; |
|
| 64 | - $this->database_port=$port; |
|
| 63 | + $this->database_host=$host; |
|
| 64 | + $this->database_port=$port; |
|
| 65 | 65 | $this->transaction_opened=0; |
| 66 | 66 | |
| 67 | 67 | if (! function_exists("mssql_connect")) |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | return $this->ok; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Convert a SQL request in Mysql syntax to native syntax |
|
| 132 | - * |
|
| 133 | - * @param string $line SQL request line to convert |
|
| 134 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 135 | - * @return string SQL request line converted |
|
| 136 | - */ |
|
| 130 | + /** |
|
| 131 | + * Convert a SQL request in Mysql syntax to native syntax |
|
| 132 | + * |
|
| 133 | + * @param string $line SQL request line to convert |
|
| 134 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 135 | + * @return string SQL request line converted |
|
| 136 | + */ |
|
| 137 | 137 | static function convertSQLFromMysql($line,$type='ddl') |
| 138 | 138 | { |
| 139 | 139 | return $line; |
@@ -173,11 +173,11 @@ discard block |
||
| 173 | 173 | //$this->query('SET NAMES '.$this->forcecharset); |
| 174 | 174 | //print "Resultat fonction connect: ".$this->db; |
| 175 | 175 | $set_options=array('SET ANSI_PADDING ON;', |
| 176 | - "SET ANSI_NULLS ON;", |
|
| 177 | - "SET ANSI_WARNINGS ON;", |
|
| 178 | - "SET ARITHABORT ON;", |
|
| 179 | - "SET CONCAT_NULL_YIELDS_NULL ON;", |
|
| 180 | - "SET QUOTED_IDENTIFIER ON;" |
|
| 176 | + "SET ANSI_NULLS ON;", |
|
| 177 | + "SET ANSI_WARNINGS ON;", |
|
| 178 | + "SET ARITHABORT ON;", |
|
| 179 | + "SET CONCAT_NULL_YIELDS_NULL ON;", |
|
| 180 | + "SET QUOTED_IDENTIFIER ON;" |
|
| 181 | 181 | ); |
| 182 | 182 | mssql_query(implode(' ',$set_options),$this->db); |
| 183 | 183 | |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | $resql=$this->query("SELECT @@VERSION"); |
| 195 | 195 | if ($resql) |
| 196 | 196 | { |
| 197 | - $version=$this->fetch_array($resql); |
|
| 198 | - return $version['computed']; |
|
| 197 | + $version=$this->fetch_array($resql); |
|
| 198 | + return $version['computed']; |
|
| 199 | 199 | } |
| 200 | 200 | else return ''; |
| 201 | 201 | } |
@@ -210,22 +210,22 @@ discard block |
||
| 210 | 210 | return 'php mssql driver'; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Close database connexion |
|
| 215 | - * |
|
| 216 | - * @return bool True if disconnect successfull, false otherwise |
|
| 217 | - * @see connect |
|
| 218 | - */ |
|
| 219 | - function close() |
|
| 220 | - { |
|
| 221 | - if ($this->db) |
|
| 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; |
|
| 225 | - return mssql_close($this->db); |
|
| 226 | - } |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 213 | + /** |
|
| 214 | + * Close database connexion |
|
| 215 | + * |
|
| 216 | + * @return bool True if disconnect successfull, false otherwise |
|
| 217 | + * @see connect |
|
| 218 | + */ |
|
| 219 | + function close() |
|
| 220 | + { |
|
| 221 | + if ($this->db) |
|
| 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; |
|
| 225 | + return mssql_close($this->db); |
|
| 226 | + } |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,12 +236,12 @@ 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 | - if ($this->transaction_opened == 0) |
|
| 242 | + if ($this->transaction_opened == 0) |
|
| 243 | 243 | { |
| 244 | - //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTIONS ON' generate also a mess |
|
| 244 | + //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTIONS ON' generate also a mess |
|
| 245 | 245 | $ret=mssql_query("SET IMPLICIT_TRANSACTIONS OFF;BEGIN TRANSACTION;",$this->db); |
| 246 | 246 | if ($ret) |
| 247 | 247 | { |
@@ -256,19 +256,19 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | - * Validate a database transaction |
|
| 260 | - * |
|
| 261 | - * @param string $log Add more log to default log line |
|
| 262 | - * @return bool true if validation is OK or transaction level no started, false if ERROR |
|
| 259 | + * Validate a database transaction |
|
| 260 | + * |
|
| 261 | + * @param string $log Add more log to default log line |
|
| 262 | + * @return bool true if validation is OK or transaction level no started, false if ERROR |
|
| 263 | 263 | */ |
| 264 | 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 | - //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTION ON' generate also a mess |
|
| 271 | + //return 1; //There is a mess with auto_commit and 'SET IMPLICIT_TRANSACTION ON' generate also a mess |
|
| 272 | 272 | $ret=mssql_query("COMMIT TRANSACTION",$this->db); |
| 273 | 273 | if ($ret) |
| 274 | 274 | { |
@@ -296,8 +296,8 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 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 | { |
@@ -314,13 +314,13 @@ discard block |
||
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
| 317 | - * Execute a SQL request and return the resultset |
|
| 318 | - * |
|
| 319 | - * @param string $query SQL query string |
|
| 320 | - * @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). |
|
| 321 | - * 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. |
|
| 322 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 323 | - * @return false|resource|true Resultset of answer |
|
| 317 | + * Execute a SQL request and return the resultset |
|
| 318 | + * |
|
| 319 | + * @param string $query SQL query string |
|
| 320 | + * @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). |
|
| 321 | + * 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. |
|
| 322 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 323 | + * @return false|resource|true Resultset of answer |
|
| 324 | 324 | */ |
| 325 | 325 | function query($query,$usesavepoint=0,$type='auto') |
| 326 | 326 | { |
@@ -337,85 +337,85 @@ discard block |
||
| 337 | 337 | |
| 338 | 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)) |
|
| 349 | - { |
|
| 350 | - $original_query=$query; |
|
| 351 | - $query="CREATE ".trim($matches[2])." INDEX [".trim($matches[3])."] ON [".trim($matches[1])."] (".trim($matches[4]).")"; |
|
| 352 | - if ($matches[2]) { |
|
| 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) { |
|
| 359 | - if ($fld->IS_NULLABLE == 'YES') { |
|
| 360 | - $query_comp[]=$fld->COLUMN_NAME." IS NOT NULL"; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - if (! empty($query_comp)) |
|
| 364 | - $query.=" WHERE ".implode(" AND ",$query_comp); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - else |
|
| 368 | - { |
|
| 369 | - if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+PRIMARY\h+KEY\h+(\w+?)\h*\((.+)\)/is', $query, $matches)) |
|
| 370 | - { |
|
| 371 | - $original_query=$query; |
|
| 372 | - $query="ALTER TABLE [".$matches[1]."] ADD CONSTRAINT [".$matches[2]."] PRIMARY KEY CLUSTERED (".$matches[3].")"; |
|
| 373 | - } |
|
| 374 | - } |
|
| 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 | + { |
|
| 350 | + $original_query=$query; |
|
| 351 | + $query="CREATE ".trim($matches[2])." INDEX [".trim($matches[3])."] ON [".trim($matches[1])."] (".trim($matches[4]).")"; |
|
| 352 | + if ($matches[2]) { |
|
| 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) { |
|
| 359 | + if ($fld->IS_NULLABLE == 'YES') { |
|
| 360 | + $query_comp[]=$fld->COLUMN_NAME." IS NOT NULL"; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + if (! empty($query_comp)) |
|
| 364 | + $query.=" WHERE ".implode(" AND ",$query_comp); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + else |
|
| 368 | + { |
|
| 369 | + if (preg_match('/ALTER TABLE\h+(\w+?)\h+ADD\h+PRIMARY\h+KEY\h+(\w+?)\h*\((.+)\)/is', $query, $matches)) |
|
| 370 | + { |
|
| 371 | + $original_query=$query; |
|
| 372 | + $query="ALTER TABLE [".$matches[1]."] ADD CONSTRAINT [".$matches[2]."] PRIMARY KEY CLUSTERED (".$matches[3].")"; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | if ($type=="auto" || $type='ddl') |
| 379 | 379 | { |
| 380 | - $itemfound = stripos($query, " limit "); |
|
| 381 | - if ($itemfound !== false) { |
|
| 382 | - // Extraire le nombre limite |
|
| 383 | - $number = stristr($query, " limit "); |
|
| 384 | - $number = substr($number, 7); |
|
| 385 | - // Inserer l'instruction TOP et le nombre limite |
|
| 386 | - $query = str_ireplace("select ", "select top ".$number." ", $query); |
|
| 387 | - // Supprimer l'instruction MySql |
|
| 388 | - $query = str_ireplace(" limit ".$number, "", $query); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - $itemfound = stripos($query, " week("); |
|
| 392 | - if ($itemfound !== false) { |
|
| 393 | - // Recreer une requete sans instruction Mysql |
|
| 394 | - $positionMySql = stripos($query, " week("); |
|
| 395 | - $newquery = substr($query, 0, $positionMySql); |
|
| 396 | - |
|
| 397 | - // Recuperer la date passee en parametre |
|
| 398 | - $extractvalue = stristr($query, " week("); |
|
| 399 | - $extractvalue = substr($extractvalue, 6); |
|
| 400 | - $positionMySql = stripos($extractvalue, ")"); |
|
| 401 | - // Conserver la fin de la requete |
|
| 402 | - $endofquery = substr($extractvalue, $positionMySql); |
|
| 403 | - $extractvalue = substr($extractvalue, 0, $positionMySql); |
|
| 404 | - |
|
| 405 | - // Remplacer l'instruction MySql en Sql Server |
|
| 406 | - // Inserer la date en parametre et le reste de la requete |
|
| 407 | - $query = $newquery." DATEPART(week, ".$extractvalue.$endofquery; |
|
| 408 | - } |
|
| 409 | - if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i',$query,$matches)) |
|
| 410 | - { |
|
| 411 | - //var_dump($query); |
|
| 412 | - //var_dump($matches); |
|
| 413 | - //if (stripos($query,'llx_c_departements') !== false) var_dump($query); |
|
| 414 | - $sql='SET IDENTITY_INSERT ['.trim($matches[1]).'] ON;'; |
|
| 415 | - @mssql_query($sql, $this->db); |
|
| 416 | - $post_query='SET IDENTITY_INSERT ['.trim($matches[1]).'] OFF;'; |
|
| 417 | - |
|
| 418 | - } |
|
| 380 | + $itemfound = stripos($query, " limit "); |
|
| 381 | + if ($itemfound !== false) { |
|
| 382 | + // Extraire le nombre limite |
|
| 383 | + $number = stristr($query, " limit "); |
|
| 384 | + $number = substr($number, 7); |
|
| 385 | + // Inserer l'instruction TOP et le nombre limite |
|
| 386 | + $query = str_ireplace("select ", "select top ".$number." ", $query); |
|
| 387 | + // Supprimer l'instruction MySql |
|
| 388 | + $query = str_ireplace(" limit ".$number, "", $query); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + $itemfound = stripos($query, " week("); |
|
| 392 | + if ($itemfound !== false) { |
|
| 393 | + // Recreer une requete sans instruction Mysql |
|
| 394 | + $positionMySql = stripos($query, " week("); |
|
| 395 | + $newquery = substr($query, 0, $positionMySql); |
|
| 396 | + |
|
| 397 | + // Recuperer la date passee en parametre |
|
| 398 | + $extractvalue = stristr($query, " week("); |
|
| 399 | + $extractvalue = substr($extractvalue, 6); |
|
| 400 | + $positionMySql = stripos($extractvalue, ")"); |
|
| 401 | + // Conserver la fin de la requete |
|
| 402 | + $endofquery = substr($extractvalue, $positionMySql); |
|
| 403 | + $extractvalue = substr($extractvalue, 0, $positionMySql); |
|
| 404 | + |
|
| 405 | + // Remplacer l'instruction MySql en Sql Server |
|
| 406 | + // Inserer la date en parametre et le reste de la requete |
|
| 407 | + $query = $newquery." DATEPART(week, ".$extractvalue.$endofquery; |
|
| 408 | + } |
|
| 409 | + if (preg_match('/^insert\h+(?:INTO)?\h*(\w+?)\h*\(.*\b(?:row)?id\b.*\)\h+VALUES/i',$query,$matches)) |
|
| 410 | + { |
|
| 411 | + //var_dump($query); |
|
| 412 | + //var_dump($matches); |
|
| 413 | + //if (stripos($query,'llx_c_departements') !== false) var_dump($query); |
|
| 414 | + $sql='SET IDENTITY_INSERT ['.trim($matches[1]).'] ON;'; |
|
| 415 | + @mssql_query($sql, $this->db); |
|
| 416 | + $post_query='SET IDENTITY_INSERT ['.trim($matches[1]).'] OFF;'; |
|
| 417 | + |
|
| 418 | + } |
|
| 419 | 419 | } |
| 420 | 420 | //print "<!--".$query."-->"; |
| 421 | 421 | |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | |
| 434 | 434 | if (!empty($post_query)) |
| 435 | 435 | { |
| 436 | - @mssql_query($post_query, $this->db); |
|
| 436 | + @mssql_query($post_query, $this->db); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | $result = mssql_query("SELECT @@ERROR as code", $this->db); |
| 445 | 445 | $row = mssql_fetch_array($result); |
| 446 | 446 | |
| 447 | - $this->lastqueryerror = $query; |
|
| 447 | + $this->lastqueryerror = $query; |
|
| 448 | 448 | $this->lasterror = $this->error(); |
| 449 | 449 | $this->lasterrno = $row["code"]; |
| 450 | 450 | |
@@ -473,10 +473,10 @@ discard block |
||
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | /** |
| 476 | - * Return datas as an array |
|
| 477 | - * |
|
| 478 | - * @param resource $resultset Resultset of request |
|
| 479 | - * @return array|false Array or false if KO or end of cursor |
|
| 476 | + * Return datas as an array |
|
| 477 | + * |
|
| 478 | + * @param resource $resultset Resultset of request |
|
| 479 | + * @return array|false Array or false if KO or end of cursor |
|
| 480 | 480 | */ |
| 481 | 481 | function fetch_array($resultset) |
| 482 | 482 | { |
@@ -487,10 +487,10 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | |
| 489 | 489 | /** |
| 490 | - * Return datas as an array |
|
| 491 | - * |
|
| 492 | - * @param resource $resultset Resultset of request |
|
| 493 | - * @return array|false Array or false if KO or end of cursor |
|
| 490 | + * Return datas as an array |
|
| 491 | + * |
|
| 492 | + * @param resource $resultset Resultset of request |
|
| 493 | + * @return array|false Array or false if KO or end of cursor |
|
| 494 | 494 | */ |
| 495 | 495 | function fetch_row($resultset) |
| 496 | 496 | { |
@@ -500,11 +500,11 @@ discard block |
||
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
| 503 | - * Return number of lines for result of a SELECT |
|
| 504 | - * |
|
| 505 | - * @param resource $resultset Resulset of requests |
|
| 506 | - * @return int Nb of lines |
|
| 507 | - * @see affected_rows |
|
| 503 | + * Return number of lines for result of a SELECT |
|
| 504 | + * |
|
| 505 | + * @param resource $resultset Resulset of requests |
|
| 506 | + * @return int Nb of lines |
|
| 507 | + * @see affected_rows |
|
| 508 | 508 | */ |
| 509 | 509 | function num_rows($resultset) |
| 510 | 510 | { |
@@ -571,9 +571,9 @@ discard block |
||
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
| 574 | - * Return generic error code of last operation. |
|
| 575 | - * |
|
| 576 | - * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
| 574 | + * Return generic error code of last operation. |
|
| 575 | + * |
|
| 576 | + * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
| 577 | 577 | */ |
| 578 | 578 | function errno() |
| 579 | 579 | { |
@@ -660,12 +660,12 @@ discard block |
||
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | /** |
| 663 | - * Encrypt sensitive data in database |
|
| 664 | - * Warning: This function includes the escape, so it must use direct value |
|
| 665 | - * |
|
| 666 | - * @param string $fieldorvalue Field name or value to encrypt |
|
| 667 | - * @param int $withQuotes Return string with quotes |
|
| 668 | - * @return string XXX(field) or XXX('value') or field or 'value' |
|
| 663 | + * Encrypt sensitive data in database |
|
| 664 | + * Warning: This function includes the escape, so it must use direct value |
|
| 665 | + * |
|
| 666 | + * @param string $fieldorvalue Field name or value to encrypt |
|
| 667 | + * @param int $withQuotes Return string with quotes |
|
| 668 | + * @return string XXX(field) or XXX('value') or field or 'value' |
|
| 669 | 669 | */ |
| 670 | 670 | function encrypt($fieldorvalue, $withQuotes=0) |
| 671 | 671 | { |
@@ -682,10 +682,10 @@ discard block |
||
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | /** |
| 685 | - * Decrypt sensitive data in database |
|
| 686 | - * |
|
| 687 | - * @param string $value Value to decrypt |
|
| 688 | - * @return string Decrypted value if used |
|
| 685 | + * Decrypt sensitive data in database |
|
| 686 | + * |
|
| 687 | + * @param string $value Value to decrypt |
|
| 688 | + * @return string Decrypted value if used |
|
| 689 | 689 | */ |
| 690 | 690 | function decrypt($value) |
| 691 | 691 | { |
@@ -712,8 +712,8 @@ discard block |
||
| 712 | 712 | $resql=$this->query('SELECT CONNECTION_ID()'); |
| 713 | 713 | if ($resql) |
| 714 | 714 | { |
| 715 | - $row=$this->fetch_row($resql); |
|
| 716 | - return $row[0]; |
|
| 715 | + $row=$this->fetch_row($resql); |
|
| 716 | + return $row[0]; |
|
| 717 | 717 | } |
| 718 | 718 | else return '?'; |
| 719 | 719 | } |
@@ -731,12 +731,12 @@ discard block |
||
| 731 | 731 | */ |
| 732 | 732 | function DDLCreateDb($database,$charset='',$collation='',$owner='') |
| 733 | 733 | { |
| 734 | - /*if (empty($charset)) $charset=$this->forcecharset; |
|
| 734 | + /*if (empty($charset)) $charset=$this->forcecharset; |
|
| 735 | 735 | if (empty($collation)) $collation=$this->forcecollate; |
| 736 | 736 | */ |
| 737 | 737 | |
| 738 | 738 | $sql = 'CREATE DATABASE '.$this->EscapeFieldName($database); |
| 739 | - //TODO: Check if we need to force a charset |
|
| 739 | + //TODO: Check if we need to force a charset |
|
| 740 | 740 | //$sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation; |
| 741 | 741 | $ret=$this->query($sql); |
| 742 | 742 | |
@@ -747,11 +747,11 @@ discard block |
||
| 747 | 747 | mssql_query($sql,$this->db); |
| 748 | 748 | |
| 749 | 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); |
|
| 750 | + @mssql_query($sql,$this->db); |
|
| 751 | + $sql="ALTER DATABASE [$database] SET ANSI_NULL ON;"; |
|
| 752 | + @mssql_query($sql,$this->db); |
|
| 753 | 753 | |
| 754 | - return $ret; |
|
| 754 | + return $ret; |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | /** |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | * |
| 760 | 760 | * @param string $database Name of database |
| 761 | 761 | * @param string $table Nmae of table filter ('xxx%') |
| 762 | - * @return array List of tables in an array |
|
| 762 | + * @return array List of tables in an array |
|
| 763 | 763 | */ |
| 764 | 764 | function DDLListTables($database,$table='') |
| 765 | 765 | { |
@@ -968,48 +968,48 @@ discard block |
||
| 968 | 968 | */ |
| 969 | 969 | function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
| 970 | 970 | { |
| 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) |
|
| 975 | - { |
|
| 976 | - if ($this->lasterrno != '15025') |
|
| 977 | - { |
|
| 978 | - return -1; |
|
| 979 | - } |
|
| 980 | - else |
|
| 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) |
|
| 975 | + { |
|
| 976 | + if ($this->lasterrno != '15025') |
|
| 981 | 977 | { |
| 982 | - // If user already exists, we continue to set permissions |
|
| 983 | - dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - $sql="SELECT name from sys.databases where name='".$dolibarr_main_db_name."'"; |
|
| 987 | - $ressql=$this->query($sql); |
|
| 988 | - if (! $ressql) |
|
| 989 | - { |
|
| 990 | - dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
| 991 | - return -1; |
|
| 992 | - } |
|
| 993 | - else |
|
| 994 | - { |
|
| 995 | - if ($num) |
|
| 996 | - { |
|
| 997 | - $this->select_db($dolibarr_main_db_name); |
|
| 998 | - $sql="CREATE USER [$dolibarr_main_db_user] FOR LOGIN [$dolibarr_main_db_user]"; |
|
| 999 | - $this->query($sql); |
|
| 1000 | - $sql="ALTER ROLE [db_owner] ADD MEMBER [$dolibarr_main_db_user]"; |
|
| 1001 | - $this->query($sql); |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - return 1; |
|
| 978 | + return -1; |
|
| 979 | + } |
|
| 980 | + else |
|
| 981 | + { |
|
| 982 | + // If user already exists, we continue to set permissions |
|
| 983 | + dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + $sql="SELECT name from sys.databases where name='".$dolibarr_main_db_name."'"; |
|
| 987 | + $ressql=$this->query($sql); |
|
| 988 | + if (! $ressql) |
|
| 989 | + { |
|
| 990 | + dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
| 991 | + return -1; |
|
| 992 | + } |
|
| 993 | + else |
|
| 994 | + { |
|
| 995 | + if ($num) |
|
| 996 | + { |
|
| 997 | + $this->select_db($dolibarr_main_db_name); |
|
| 998 | + $sql="CREATE USER [$dolibarr_main_db_user] FOR LOGIN [$dolibarr_main_db_user]"; |
|
| 999 | + $this->query($sql); |
|
| 1000 | + $sql="ALTER ROLE [db_owner] ADD MEMBER [$dolibarr_main_db_user]"; |
|
| 1001 | + $this->query($sql); |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + return 1; |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | - /** |
|
| 1008 | - * Return charset used to store data in database |
|
| 1009 | - * |
|
| 1010 | - * @return string Charset |
|
| 1011 | - */ |
|
| 1012 | - function getDefaultCharacterSetDatabase() |
|
| 1007 | + /** |
|
| 1008 | + * Return charset used to store data in database |
|
| 1009 | + * |
|
| 1010 | + * @return string Charset |
|
| 1011 | + */ |
|
| 1012 | + function getDefaultCharacterSetDatabase() |
|
| 1013 | 1013 | { |
| 1014 | 1014 | // FIXME: Dummy method |
| 1015 | 1015 | // TODO: Implement |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | // FIXME: Dummy method |
| 1070 | 1070 | // TODO: Implement |
| 1071 | 1071 | |
| 1072 | - return ''; |
|
| 1072 | + return ''; |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | /** |
@@ -1082,7 +1082,7 @@ discard block |
||
| 1082 | 1082 | // FIXME: Dummy method |
| 1083 | 1083 | // TODO: Implement |
| 1084 | 1084 | |
| 1085 | - return ''; |
|
| 1085 | + return ''; |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | /** |
@@ -1123,7 +1123,7 @@ discard block |
||
| 1123 | 1123 | * @return string field's name escaped |
| 1124 | 1124 | */ |
| 1125 | 1125 | function EscapeFieldName($fieldname) { |
| 1126 | - return "[".$fieldname."]"; |
|
| 1126 | + return "[".$fieldname."]"; |
|
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | 1129 | |
@@ -1135,28 +1135,28 @@ discard block |
||
| 1135 | 1135 | * @return false|object |
| 1136 | 1136 | */ |
| 1137 | 1137 | function GetFieldInformation($table,$fields) { |
| 1138 | - $sql="SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$this->escape($table)."' AND COLUMN_NAME"; |
|
| 1139 | - if (is_array($fields)) |
|
| 1140 | - { |
|
| 1141 | - $where=" IN ('".implode("','",$fields)."')"; |
|
| 1142 | - } |
|
| 1143 | - else |
|
| 1144 | - { |
|
| 1145 | - $where="='".$this->escape($fields)."'"; |
|
| 1146 | - } |
|
| 1147 | - $result=array(); |
|
| 1148 | - $ret=mssql_query($sql.$where,$this->db); |
|
| 1149 | - if ($ret) |
|
| 1150 | - { |
|
| 1151 | - while($obj=mssql_fetch_object($ret)) |
|
| 1152 | - { |
|
| 1153 | - $result[]=$obj; |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - else |
|
| 1157 | - return false; |
|
| 1158 | - |
|
| 1159 | - return $result; |
|
| 1138 | + $sql="SELECT * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$this->escape($table)."' AND COLUMN_NAME"; |
|
| 1139 | + if (is_array($fields)) |
|
| 1140 | + { |
|
| 1141 | + $where=" IN ('".implode("','",$fields)."')"; |
|
| 1142 | + } |
|
| 1143 | + else |
|
| 1144 | + { |
|
| 1145 | + $where="='".$this->escape($fields)."'"; |
|
| 1146 | + } |
|
| 1147 | + $result=array(); |
|
| 1148 | + $ret=mssql_query($sql.$where,$this->db); |
|
| 1149 | + if ($ret) |
|
| 1150 | + { |
|
| 1151 | + while($obj=mssql_fetch_object($ret)) |
|
| 1152 | + { |
|
| 1153 | + $result[]=$obj; |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + else |
|
| 1157 | + return false; |
|
| 1158 | + |
|
| 1159 | + return $result; |
|
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | } |
@@ -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 |
@@ -90,8 +90,7 @@ discard block |
||
| 90 | 90 | // (La base Dolibarr a ete forcee en this->forcecharset a l'install) |
| 91 | 91 | $this->connected = true; |
| 92 | 92 | $this->ok = true; |
| 93 | - } |
|
| 94 | - else |
|
| 93 | + } else |
|
| 95 | 94 | { |
| 96 | 95 | // host, login ou password incorrect |
| 97 | 96 | $this->connected = false; |
@@ -108,8 +107,7 @@ discard block |
||
| 108 | 107 | $this->database_selected = true; |
| 109 | 108 | $this->database_name = $name; |
| 110 | 109 | $this->ok = true; |
| 111 | - } |
|
| 112 | - else |
|
| 110 | + } else |
|
| 113 | 111 | { |
| 114 | 112 | $this->database_selected = false; |
| 115 | 113 | $this->database_name = ''; |
@@ -117,8 +115,7 @@ discard block |
||
| 117 | 115 | $this->error=$this->error(); |
| 118 | 116 | dol_syslog(get_class($this)."::DoliDBMssql : Erreur Select_db ".$this->error,LOG_ERR); |
| 119 | 117 | } |
| 120 | - } |
|
| 121 | - else |
|
| 118 | + } else |
|
| 122 | 119 | { |
| 123 | 120 | // Pas de selection de base demandee, ok ou ko |
| 124 | 121 | $this->database_selected = false; |
@@ -165,7 +162,9 @@ discard block |
||
| 165 | 162 | { |
| 166 | 163 | dol_syslog(get_class($this)."::connect host=$host, port=$port, login=$login, passwd=--hidden--, name=$name"); |
| 167 | 164 | $newhost=$host; |
| 168 | - if ($port) $newhost.=':'.$port; |
|
| 165 | + if ($port) { |
|
| 166 | + $newhost.=':'.$port; |
|
| 167 | + } |
|
| 169 | 168 | $this->db = @mssql_connect($newhost, $login, $passwd); |
| 170 | 169 | //force les enregistrement en latin1 si la base est en utf8 par defaut |
| 171 | 170 | // Supprime car plante sur mon PHP-Mysql. De plus, la base est forcement en latin1 avec |
@@ -196,8 +195,9 @@ discard block |
||
| 196 | 195 | { |
| 197 | 196 | $version=$this->fetch_array($resql); |
| 198 | 197 | return $version['computed']; |
| 198 | + } else { |
|
| 199 | + return ''; |
|
| 199 | 200 | } |
| 200 | - else return ''; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -220,7 +220,9 @@ 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); |
|
| 223 | + if ($this->transaction_opened > 0) { |
|
| 224 | + dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
| 225 | + } |
|
| 224 | 226 | $this->connected=false; |
| 225 | 227 | return mssql_close($this->db); |
| 226 | 228 | } |
@@ -248,8 +250,7 @@ discard block |
||
| 248 | 250 | dol_syslog("BEGIN Transaction",LOG_DEBUG); |
| 249 | 251 | } |
| 250 | 252 | return $ret; |
| 251 | - } |
|
| 252 | - else |
|
| 253 | + } else |
|
| 253 | 254 | { |
| 254 | 255 | return true; |
| 255 | 256 | } |
@@ -274,13 +275,11 @@ discard block |
||
| 274 | 275 | { |
| 275 | 276 | dol_syslog("COMMIT Transaction",LOG_DEBUG); |
| 276 | 277 | return true; |
| 277 | - } |
|
| 278 | - else |
|
| 278 | + } else |
|
| 279 | 279 | { |
| 280 | 280 | return false; |
| 281 | 281 | } |
| 282 | - } |
|
| 283 | - elseif ($this->transaction_opened > 1) |
|
| 282 | + } elseif ($this->transaction_opened > 1) |
|
| 284 | 283 | { |
| 285 | 284 | return true; |
| 286 | 285 | } |
@@ -304,8 +303,7 @@ discard block |
||
| 304 | 303 | $ret=mssql_query("ROLLBACK TRANSACTION",$this->db); |
| 305 | 304 | dol_syslog("ROLLBACK Transaction".($log?' '.$log:''),LOG_DEBUG); |
| 306 | 305 | return $ret; |
| 307 | - } |
|
| 308 | - elseif ($this->transaction_opened > 1) |
|
| 306 | + } elseif ($this->transaction_opened > 1) |
|
| 309 | 307 | { |
| 310 | 308 | return true; |
| 311 | 309 | } |
@@ -326,7 +324,9 @@ discard block |
||
| 326 | 324 | { |
| 327 | 325 | $query = trim($query); |
| 328 | 326 | |
| 329 | - if (preg_match('/^--/',$query)) return true; |
|
| 327 | + if (preg_match('/^--/',$query)) { |
|
| 328 | + return true; |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | 331 | // Conversion syntaxe MySql vers MSDE. |
| 332 | 332 | $query = str_ireplace("now()", "getdate()", $query); |
@@ -360,11 +360,11 @@ discard block |
||
| 360 | 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 | - else |
|
| 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 | { |
@@ -419,14 +419,15 @@ discard block |
||
| 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'))) { |
|
| 423 | + dol_syslog('sql='.$query, LOG_DEBUG); |
|
| 424 | + } |
|
| 423 | 425 | |
| 424 | 426 | if (! $this->database_name) |
| 425 | 427 | { |
| 426 | 428 | // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
| 427 | 429 | $ret = mssql_query($query, $this->db); |
| 428 | - } |
|
| 429 | - else |
|
| 430 | + } else |
|
| 430 | 431 | { |
| 431 | 432 | $ret = mssql_query($query, $this->db); |
| 432 | 433 | } |
@@ -449,7 +450,9 @@ discard block |
||
| 449 | 450 | $this->lasterrno = $row["code"]; |
| 450 | 451 | |
| 451 | 452 | dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); |
| 452 | - if ($original_query) dol_syslog(get_class($this)."::query SQL Original query: ".$original_query, LOG_ERR); |
|
| 453 | + if ($original_query) { |
|
| 454 | + dol_syslog(get_class($this)."::query SQL Original query: ".$original_query, LOG_ERR); |
|
| 455 | + } |
|
| 453 | 456 | dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR); |
| 454 | 457 | } |
| 455 | 458 | $this->lastquery=$query; |
@@ -543,7 +546,9 @@ discard block |
||
| 543 | 546 | // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
| 544 | 547 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
| 545 | 548 | // Si resultset en est un, on libere la memoire |
| 546 | - if (is_resource($resultset)) mssql_free_result($resultset); |
|
| 549 | + if (is_resource($resultset)) { |
|
| 550 | + mssql_free_result($resultset); |
|
| 551 | + } |
|
| 547 | 552 | } |
| 548 | 553 | |
| 549 | 554 | /** |
@@ -581,8 +586,7 @@ discard block |
||
| 581 | 586 | { |
| 582 | 587 | // Si il y a eu echec de connexion, $this->db n'est pas valide. |
| 583 | 588 | return 'DB_ERROR_FAILED_TO_CONNECT'; |
| 584 | - } |
|
| 585 | - else |
|
| 589 | + } else |
|
| 586 | 590 | { |
| 587 | 591 | // Constants to convert a MSSql error code to a generic Dolibarr error code |
| 588 | 592 | $errorcode_map = array( |
@@ -633,8 +637,7 @@ discard block |
||
| 633 | 637 | if (! $this->connected) { |
| 634 | 638 | // Si il y a eu echec de connexion, $this->db n'est pas valide pour mssql_get_last_message. |
| 635 | 639 | return 'Not connected. Check setup parameters in conf/conf.php file and your mssql client and server versions'; |
| 636 | - } |
|
| 637 | - else { |
|
| 640 | + } else { |
|
| 638 | 641 | return mssql_get_last_message(); |
| 639 | 642 | } |
| 640 | 643 | } |
@@ -652,8 +655,7 @@ discard block |
||
| 652 | 655 | if ($res && $data = $this->fetch_array($res)) |
| 653 | 656 | { |
| 654 | 657 | return $data["id"]; |
| 655 | - } |
|
| 656 | - else |
|
| 658 | + } else |
|
| 657 | 659 | { |
| 658 | 660 | return -1; |
| 659 | 661 | } |
@@ -714,8 +716,9 @@ discard block |
||
| 714 | 716 | { |
| 715 | 717 | $row=$this->fetch_row($resql); |
| 716 | 718 | return $row[0]; |
| 719 | + } else { |
|
| 720 | + return '?'; |
|
| 717 | 721 | } |
| 718 | - else return '?'; |
|
| 719 | 722 | } |
| 720 | 723 | |
| 721 | 724 | /** |
@@ -808,26 +811,27 @@ discard block |
||
| 808 | 811 | { |
| 809 | 812 | $sqlfields[$i] = $field_name." "; |
| 810 | 813 | $sqlfields[$i] .= $field_desc['type']; |
| 811 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 812 | - $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
| 813 | - else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 814 | - $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
| 815 | - else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 814 | + if( preg_match("/^[^\s]/i",$field_desc['value'])) { |
|
| 815 | + $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
| 816 | + } else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) { |
|
| 817 | + $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
| 818 | + } else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 816 | 819 | { |
| 817 | - if(preg_match("/null/i",$field_desc['default'])) |
|
| 818 | - $sqlfields[$i] .= " default ".$field_desc['default']; |
|
| 819 | - else |
|
| 820 | - $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
| 820 | + if(preg_match("/null/i",$field_desc['default'])) { |
|
| 821 | + $sqlfields[$i] .= " default ".$field_desc['default']; |
|
| 822 | + } else { |
|
| 823 | + $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
| 824 | + } |
|
| 825 | + } else if( preg_match("/^[^\s]/i",$field_desc['null'])) { |
|
| 826 | + $sqlfields[$i] .= " ".$field_desc['null']; |
|
| 827 | + } else if( preg_match("/^[^\s]/i",$field_desc['extra'])) { |
|
| 828 | + $sqlfields[$i] .= " ".$field_desc['extra']; |
|
| 821 | 829 | } |
| 822 | - else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 823 | - $sqlfields[$i] .= " ".$field_desc['null']; |
|
| 824 | - |
|
| 825 | - else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 826 | - $sqlfields[$i] .= " ".$field_desc['extra']; |
|
| 827 | 830 | $i++; |
| 828 | 831 | } |
| 829 | - if($primary_key != "") |
|
| 830 | - $pk = "primary key(".$primary_key.")"; |
|
| 832 | + if($primary_key != "") { |
|
| 833 | + $pk = "primary key(".$primary_key.")"; |
|
| 834 | + } |
|
| 831 | 835 | |
| 832 | 836 | if(is_array($unique_keys)) |
| 833 | 837 | { |
@@ -848,19 +852,23 @@ discard block |
||
| 848 | 852 | } |
| 849 | 853 | } |
| 850 | 854 | $sql .= implode(',',$sqlfields); |
| 851 | - if($primary_key != "") |
|
| 852 | - $sql .= ",".$pk; |
|
| 853 | - if(is_array($unique_keys)) |
|
| 854 | - $sql .= ",".implode(',',$sqluq); |
|
| 855 | - if(is_array($keys)) |
|
| 856 | - $sql .= ",".implode(',',$sqlk); |
|
| 855 | + if($primary_key != "") { |
|
| 856 | + $sql .= ",".$pk; |
|
| 857 | + } |
|
| 858 | + if(is_array($unique_keys)) { |
|
| 859 | + $sql .= ",".implode(',',$sqluq); |
|
| 860 | + } |
|
| 861 | + if(is_array($keys)) { |
|
| 862 | + $sql .= ",".implode(',',$sqlk); |
|
| 863 | + } |
|
| 857 | 864 | $sql .=") type=".$type; |
| 858 | 865 | |
| 859 | 866 | dol_syslog($sql); |
| 860 | - if(! $this -> query($sql)) |
|
| 861 | - return -1; |
|
| 862 | - else |
|
| 863 | - return 1; |
|
| 867 | + if(! $this -> query($sql)) { |
|
| 868 | + return -1; |
|
| 869 | + } else { |
|
| 870 | + return 1; |
|
| 871 | + } |
|
| 864 | 872 | } |
| 865 | 873 | |
| 866 | 874 | /** |
@@ -894,25 +902,31 @@ discard block |
||
| 894 | 902 | // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
| 895 | 903 | $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
| 896 | 904 | $sql .= $field_desc['type']; |
| 897 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 898 | - $sql .= "(".$field_desc['value'].")"; |
|
| 899 | - if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 900 | - $sql .= " ".$field_desc['attribute']; |
|
| 901 | - if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 902 | - $sql .= " ".$field_desc['null']; |
|
| 903 | - if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 904 | - if(preg_match("/null/i",$field_desc['default'])) |
|
| 905 | + if( preg_match("/^[^\s]/i",$field_desc['value'])) { |
|
| 906 | + $sql .= "(".$field_desc['value'].")"; |
|
| 907 | + } |
|
| 908 | + if( preg_match("/^[^\s]/i",$field_desc['attribute'])) { |
|
| 909 | + $sql .= " ".$field_desc['attribute']; |
|
| 910 | + } |
|
| 911 | + if( preg_match("/^[^\s]/i",$field_desc['null'])) { |
|
| 912 | + $sql .= " ".$field_desc['null']; |
|
| 913 | + } |
|
| 914 | + if( preg_match("/^[^\s]/i",$field_desc['default'])) { |
|
| 915 | + if(preg_match("/null/i",$field_desc['default'])) |
|
| 905 | 916 | $sql .= " default ".$field_desc['default']; |
| 906 | - else |
|
| 907 | - $sql .= " default '".$field_desc['default']."'"; |
|
| 908 | - if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 909 | - $sql .= " ".$field_desc['extra']; |
|
| 917 | + } else { |
|
| 918 | + $sql .= " default '".$field_desc['default']."'"; |
|
| 919 | + } |
|
| 920 | + if( preg_match("/^[^\s]/i",$field_desc['extra'])) { |
|
| 921 | + $sql .= " ".$field_desc['extra']; |
|
| 922 | + } |
|
| 910 | 923 | $sql .= " ".$field_position; |
| 911 | 924 | |
| 912 | - if(! $this -> query($sql)) |
|
| 913 | - return -1; |
|
| 914 | - else |
|
| 915 | - return 1; |
|
| 925 | + if(! $this -> query($sql)) { |
|
| 926 | + return -1; |
|
| 927 | + } else { |
|
| 928 | + return 1; |
|
| 929 | + } |
|
| 916 | 930 | } |
| 917 | 931 | |
| 918 | 932 | /** |
@@ -932,10 +946,11 @@ discard block |
||
| 932 | 946 | } |
| 933 | 947 | |
| 934 | 948 | dol_syslog($sql,LOG_DEBUG); |
| 935 | - if (! $this->query($sql)) |
|
| 936 | - return -1; |
|
| 937 | - else |
|
| 938 | - return 1; |
|
| 949 | + if (! $this->query($sql)) { |
|
| 950 | + return -1; |
|
| 951 | + } else { |
|
| 952 | + return 1; |
|
| 953 | + } |
|
| 939 | 954 | } |
| 940 | 955 | |
| 941 | 956 | /** |
@@ -953,8 +968,9 @@ discard block |
||
| 953 | 968 | { |
| 954 | 969 | $this->error=$this->lasterror(); |
| 955 | 970 | return -1; |
| 971 | + } else { |
|
| 972 | + return 1; |
|
| 956 | 973 | } |
| 957 | - else return 1; |
|
| 958 | 974 | } |
| 959 | 975 | |
| 960 | 976 | /** |
@@ -976,8 +992,7 @@ discard block |
||
| 976 | 992 | if ($this->lasterrno != '15025') |
| 977 | 993 | { |
| 978 | 994 | return -1; |
| 979 | - } |
|
| 980 | - else |
|
| 995 | + } else |
|
| 981 | 996 | { |
| 982 | 997 | // If user already exists, we continue to set permissions |
| 983 | 998 | dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
@@ -989,8 +1004,7 @@ discard block |
||
| 989 | 1004 | { |
| 990 | 1005 | dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
| 991 | 1006 | return -1; |
| 992 | - } |
|
| 993 | - else |
|
| 1007 | + } else |
|
| 994 | 1008 | { |
| 995 | 1009 | if ($num) |
| 996 | 1010 | { |
@@ -1139,8 +1153,7 @@ discard block |
||
| 1139 | 1153 | if (is_array($fields)) |
| 1140 | 1154 | { |
| 1141 | 1155 | $where=" IN ('".implode("','",$fields)."')"; |
| 1142 | - } |
|
| 1143 | - else |
|
| 1156 | + } else |
|
| 1144 | 1157 | { |
| 1145 | 1158 | $where="='".$this->escape($fields)."'"; |
| 1146 | 1159 | } |
@@ -1152,9 +1165,9 @@ discard block |
||
| 1152 | 1165 | { |
| 1153 | 1166 | $result[]=$obj; |
| 1154 | 1167 | } |
| 1168 | + } else { |
|
| 1169 | + return false; |
|
| 1155 | 1170 | } |
| 1156 | - else |
|
| 1157 | - return false; |
|
| 1158 | 1171 | |
| 1159 | 1172 | return $result; |
| 1160 | 1173 | } |
@@ -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 | { |
@@ -34,16 +34,16 @@ discard block |
||
| 34 | 34 | { |
| 35 | 35 | /** @var mysqli Database object */ |
| 36 | 36 | public $db; |
| 37 | - //! Database type |
|
| 38 | - public $type='mysqli'; |
|
| 39 | - //! Database label |
|
| 40 | - const LABEL='MySQL or MariaDB'; |
|
| 41 | - //! Version min database |
|
| 42 | - const VERSIONMIN='5.0.3'; |
|
| 37 | + //! Database type |
|
| 38 | + public $type='mysqli'; |
|
| 39 | + //! Database label |
|
| 40 | + const LABEL='MySQL or MariaDB'; |
|
| 41 | + //! Version min database |
|
| 42 | + const VERSIONMIN='5.0.3'; |
|
| 43 | 43 | /** @var mysqli_result Resultset of last query */ |
| 44 | 44 | private $_results; |
| 45 | 45 | |
| 46 | - /** |
|
| 46 | + /** |
|
| 47 | 47 | * Constructor. |
| 48 | 48 | * This create an opened connexion to a database server and eventually to a database |
| 49 | 49 | * |
@@ -53,38 +53,38 @@ discard block |
||
| 53 | 53 | * @param string $pass Mot de passe |
| 54 | 54 | * @param string $name Nom de la database |
| 55 | 55 | * @param int $port Port of database server |
| 56 | - */ |
|
| 57 | - function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
| 58 | - { |
|
| 59 | - global $conf,$langs; |
|
| 60 | - |
|
| 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; |
|
| 64 | - |
|
| 65 | - $this->database_user=$user; |
|
| 66 | - $this->database_host=$host; |
|
| 67 | - $this->database_port=$port; |
|
| 68 | - |
|
| 69 | - $this->transaction_opened=0; |
|
| 70 | - |
|
| 71 | - //print "Name DB: $host,$user,$pass,$name<br>"; |
|
| 72 | - |
|
| 73 | - if (! class_exists('mysqli')) |
|
| 74 | - { |
|
| 75 | - $this->connected = false; |
|
| 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); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if (! $host) |
|
| 82 | - { |
|
| 83 | - $this->connected = false; |
|
| 84 | - $this->ok = false; |
|
| 85 | - $this->error=$langs->trans("ErrorWrongHostParameter"); |
|
| 86 | - dol_syslog(get_class($this)."::DoliDBMysqli : Connect error, wrong host parameters",LOG_ERR); |
|
| 87 | - } |
|
| 56 | + */ |
|
| 57 | + function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
| 58 | + { |
|
| 59 | + global $conf,$langs; |
|
| 60 | + |
|
| 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; |
|
| 64 | + |
|
| 65 | + $this->database_user=$user; |
|
| 66 | + $this->database_host=$host; |
|
| 67 | + $this->database_port=$port; |
|
| 68 | + |
|
| 69 | + $this->transaction_opened=0; |
|
| 70 | + |
|
| 71 | + //print "Name DB: $host,$user,$pass,$name<br>"; |
|
| 72 | + |
|
| 73 | + if (! class_exists('mysqli')) |
|
| 74 | + { |
|
| 75 | + $this->connected = false; |
|
| 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); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if (! $host) |
|
| 82 | + { |
|
| 83 | + $this->connected = false; |
|
| 84 | + $this->ok = false; |
|
| 85 | + $this->error=$langs->trans("ErrorWrongHostParameter"); |
|
| 86 | + dol_syslog(get_class($this)."::DoliDBMysqli : Connect error, wrong host parameters",LOG_ERR); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | // Try server connection |
| 90 | 90 | // We do not try to connect to database, only to server. Connect to database is done later in constrcutor |
@@ -101,61 +101,61 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // If server connection is ok, we try to connect to the database |
| 104 | - if ($this->connected && $name) |
|
| 105 | - { |
|
| 106 | - if ($this->select_db($name)) |
|
| 107 | - { |
|
| 108 | - $this->database_selected = true; |
|
| 109 | - $this->database_name = $name; |
|
| 110 | - $this->ok = true; |
|
| 111 | - |
|
| 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'; |
|
| 104 | + if ($this->connected && $name) |
|
| 105 | + { |
|
| 106 | + if ($this->select_db($name)) |
|
| 107 | + { |
|
| 108 | + $this->database_selected = true; |
|
| 109 | + $this->database_name = $name; |
|
| 110 | + $this->ok = true; |
|
| 111 | + |
|
| 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'; |
|
| 116 | 116 | if ($this->db->character_set_name() != $clientmustbe) { |
| 117 | 117 | $this->db->set_charset($clientmustbe); |
| 118 | 118 | } |
| 119 | - } |
|
| 120 | - else |
|
| 121 | - { |
|
| 122 | - $this->database_selected = false; |
|
| 123 | - $this->database_name = ''; |
|
| 124 | - $this->ok = false; |
|
| 125 | - $this->error=$this->error(); |
|
| 126 | - dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error,LOG_ERR); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - else |
|
| 130 | - { |
|
| 131 | - // Pas de selection de base demandee, ok ou ko |
|
| 132 | - $this->database_selected = false; |
|
| 133 | - |
|
| 134 | - if ($this->connected) |
|
| 135 | - { |
|
| 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'; |
|
| 119 | + } |
|
| 120 | + else |
|
| 121 | + { |
|
| 122 | + $this->database_selected = false; |
|
| 123 | + $this->database_name = ''; |
|
| 124 | + $this->ok = false; |
|
| 125 | + $this->error=$this->error(); |
|
| 126 | + dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error,LOG_ERR); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + else |
|
| 130 | + { |
|
| 131 | + // Pas de selection de base demandee, ok ou ko |
|
| 132 | + $this->database_selected = false; |
|
| 133 | + |
|
| 134 | + if ($this->connected) |
|
| 135 | + { |
|
| 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'; |
|
| 140 | 140 | if ($this->db->character_set_name() != $clientmustbe) { |
| 141 | 141 | $this->db->set_charset($clientmustbe); |
| 142 | 142 | } |
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Convert a SQL request in Mysql syntax to native syntax |
|
| 150 | - * |
|
| 151 | - * @param string $line SQL request line to convert |
|
| 152 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 153 | - * @return string SQL request line converted |
|
| 154 | - */ |
|
| 155 | - static function convertSQLFromMysql($line,$type='ddl') |
|
| 156 | - { |
|
| 157 | - return $line; |
|
| 158 | - } |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Convert a SQL request in Mysql syntax to native syntax |
|
| 150 | + * |
|
| 151 | + * @param string $line SQL request line to convert |
|
| 152 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 153 | + * @return string SQL request line converted |
|
| 154 | + */ |
|
| 155 | + static function convertSQLFromMysql($line,$type='ddl') |
|
| 156 | + { |
|
| 157 | + return $line; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | 160 | /** |
| 161 | 161 | * Select a database |
@@ -163,11 +163,11 @@ discard block |
||
| 163 | 163 | * @param string $database Name of database |
| 164 | 164 | * @return boolean true if OK, false if KO |
| 165 | 165 | */ |
| 166 | - function select_db($database) |
|
| 167 | - { |
|
| 168 | - dol_syslog(get_class($this)."::select_db database=".$database, LOG_DEBUG); |
|
| 169 | - return $this->db->select_db($database); |
|
| 170 | - } |
|
| 166 | + function select_db($database) |
|
| 167 | + { |
|
| 168 | + dol_syslog(get_class($this)."::select_db database=".$database, LOG_DEBUG); |
|
| 169 | + return $this->db->select_db($database); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -188,360 +188,360 @@ discard block |
||
| 188 | 188 | return new mysqli($host, $login, $passwd, $name, $port); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - /** |
|
| 191 | + /** |
|
| 192 | 192 | * Return version of database server |
| 193 | 193 | * |
| 194 | 194 | * @return string Version string |
| 195 | - */ |
|
| 196 | - function getVersion() |
|
| 197 | - { |
|
| 198 | - return $this->db->server_info; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Return version of database client driver |
|
| 203 | - * |
|
| 204 | - * @return string Version string |
|
| 205 | - */ |
|
| 195 | + */ |
|
| 196 | + function getVersion() |
|
| 197 | + { |
|
| 198 | + return $this->db->server_info; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Return version of database client driver |
|
| 203 | + * |
|
| 204 | + * @return string Version string |
|
| 205 | + */ |
|
| 206 | 206 | function getDriverInfo() |
| 207 | 207 | { |
| 208 | 208 | return $this->db->client_info; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Close database connexion |
|
| 214 | - * |
|
| 215 | - * @return bool True if disconnect successfull, false otherwise |
|
| 216 | - * @see connect |
|
| 217 | - */ |
|
| 218 | - function close() |
|
| 219 | - { |
|
| 220 | - if ($this->db) |
|
| 221 | - { |
|
| 222 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
| 223 | - $this->connected=false; |
|
| 224 | - return $this->db->close(); |
|
| 225 | - } |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Execute a SQL request and return the resultset |
|
| 231 | - * |
|
| 232 | - * @param string $query SQL query string |
|
| 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 | - * 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 | - * @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 |
|
| 237 | - */ |
|
| 238 | - function query($query,$usesavepoint=0,$type='auto') |
|
| 239 | - { |
|
| 240 | - global $conf; |
|
| 241 | - |
|
| 242 | - $query = trim($query); |
|
| 243 | - |
|
| 244 | - if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
| 245 | - |
|
| 246 | - if (! $this->database_name) |
|
| 247 | - { |
|
| 248 | - // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
|
| 249 | - $ret = $this->db->query($query); |
|
| 250 | - } |
|
| 251 | - else |
|
| 252 | - { |
|
| 253 | - $ret = $this->db->query($query); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
| 257 | - { |
|
| 258 | - // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
| 259 | - if (! $ret) |
|
| 260 | - { |
|
| 261 | - $this->lastqueryerror = $query; |
|
| 262 | - $this->lasterror = $this->error(); |
|
| 263 | - $this->lasterrno = $this->errno(); |
|
| 212 | + /** |
|
| 213 | + * Close database connexion |
|
| 214 | + * |
|
| 215 | + * @return bool True if disconnect successfull, false otherwise |
|
| 216 | + * @see connect |
|
| 217 | + */ |
|
| 218 | + function close() |
|
| 219 | + { |
|
| 220 | + if ($this->db) |
|
| 221 | + { |
|
| 222 | + if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
| 223 | + $this->connected=false; |
|
| 224 | + return $this->db->close(); |
|
| 225 | + } |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Execute a SQL request and return the resultset |
|
| 231 | + * |
|
| 232 | + * @param string $query SQL query string |
|
| 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 | + * 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 | + * @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 |
|
| 237 | + */ |
|
| 238 | + function query($query,$usesavepoint=0,$type='auto') |
|
| 239 | + { |
|
| 240 | + global $conf; |
|
| 241 | + |
|
| 242 | + $query = trim($query); |
|
| 243 | + |
|
| 244 | + if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
| 245 | + |
|
| 246 | + if (! $this->database_name) |
|
| 247 | + { |
|
| 248 | + // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
|
| 249 | + $ret = $this->db->query($query); |
|
| 250 | + } |
|
| 251 | + else |
|
| 252 | + { |
|
| 253 | + $ret = $this->db->query($query); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
| 257 | + { |
|
| 258 | + // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
| 259 | + if (! $ret) |
|
| 260 | + { |
|
| 261 | + $this->lastqueryerror = $query; |
|
| 262 | + $this->lasterror = $this->error(); |
|
| 263 | + $this->lasterrno = $this->errno(); |
|
| 264 | 264 | |
| 265 | 265 | 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 |
| 266 | - dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterrno." ".$this->lasterror, LOG_ERR); |
|
| 267 | - } |
|
| 268 | - $this->lastquery=$query; |
|
| 269 | - $this->_results = $ret; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return $ret; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Renvoie la ligne courante (comme un objet) pour le curseur resultset |
|
| 277 | - * |
|
| 278 | - * @param mysqli_result $resultset Curseur de la requete voulue |
|
| 279 | - * @return object|null Object result line or null if KO or end of cursor |
|
| 280 | - */ |
|
| 281 | - function fetch_object($resultset) |
|
| 282 | - { |
|
| 283 | - // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
|
| 284 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 266 | + dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterrno." ".$this->lasterror, LOG_ERR); |
|
| 267 | + } |
|
| 268 | + $this->lastquery=$query; |
|
| 269 | + $this->_results = $ret; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return $ret; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Renvoie la ligne courante (comme un objet) pour le curseur resultset |
|
| 277 | + * |
|
| 278 | + * @param mysqli_result $resultset Curseur de la requete voulue |
|
| 279 | + * @return object|null Object result line or null if KO or end of cursor |
|
| 280 | + */ |
|
| 281 | + function fetch_object($resultset) |
|
| 282 | + { |
|
| 283 | + // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
|
| 284 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 285 | 285 | return $resultset->fetch_object(); |
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Return datas as an array |
|
| 291 | - * |
|
| 292 | - * @param mysqli_result $resultset Resultset of request |
|
| 293 | - * @return array|null Array or null if KO or end of cursor |
|
| 294 | - */ |
|
| 295 | - function fetch_array($resultset) |
|
| 296 | - { |
|
| 297 | - // If resultset not provided, we take the last used by connexion |
|
| 298 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 299 | - return $resultset->fetch_array(); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Return datas as an array |
|
| 304 | - * |
|
| 305 | - * @param mysqli_result $resultset Resultset of request |
|
| 306 | - * @return array|null|0 Array or null if KO or end of cursor or 0 if resultset is bool |
|
| 307 | - */ |
|
| 308 | - function fetch_row($resultset) |
|
| 309 | - { |
|
| 310 | - // If resultset not provided, we take the last used by connexion |
|
| 311 | - if (! is_bool($resultset)) |
|
| 312 | - { |
|
| 313 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 314 | - return $resultset->fetch_row(); |
|
| 315 | - } |
|
| 316 | - else |
|
| 317 | - { |
|
| 318 | - // si le curseur est un booleen on retourne la valeur 0 |
|
| 319 | - return 0; |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Return number of lines for result of a SELECT |
|
| 325 | - * |
|
| 326 | - * @param mysqli_result $resultset Resulset of requests |
|
| 327 | - * @return int Nb of lines |
|
| 328 | - * @see affected_rows |
|
| 329 | - */ |
|
| 330 | - function num_rows($resultset) |
|
| 331 | - { |
|
| 332 | - // If resultset not provided, we take the last used by connexion |
|
| 333 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 334 | - return $resultset->num_rows; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE |
|
| 339 | - * |
|
| 340 | - * @param mysqli_result $resultset Curseur de la requete voulue |
|
| 341 | - * @return int Nombre de lignes |
|
| 342 | - * @see num_rows |
|
| 343 | - */ |
|
| 344 | - function affected_rows($resultset) |
|
| 345 | - { |
|
| 346 | - // If resultset not provided, we take the last used by connexion |
|
| 347 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 348 | - // mysql necessite un link de base pour cette fonction contrairement |
|
| 349 | - // a pqsql qui prend un resultset |
|
| 350 | - return $this->db->affected_rows; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Libere le dernier resultset utilise sur cette connexion |
|
| 356 | - * |
|
| 357 | - * @param mysqli_result $resultset Curseur de la requete voulue |
|
| 358 | - * @return void |
|
| 359 | - */ |
|
| 360 | - function free($resultset=null) |
|
| 361 | - { |
|
| 362 | - // If resultset not provided, we take the last used by connexion |
|
| 363 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 364 | - // Si resultset en est un, on libere la memoire |
|
| 365 | - if (is_object($resultset)) $resultset->free_result(); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * Escape a string to insert data |
|
| 370 | - * |
|
| 371 | - * @param string $stringtoencode String to escape |
|
| 372 | - * @return string String escaped |
|
| 373 | - */ |
|
| 374 | - function escape($stringtoencode) |
|
| 375 | - { |
|
| 376 | - return $this->db->real_escape_string($stringtoencode); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Return generic error code of last operation. |
|
| 381 | - * |
|
| 382 | - * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
| 383 | - */ |
|
| 384 | - function errno() |
|
| 385 | - { |
|
| 386 | - if (! $this->connected) { |
|
| 387 | - // Si il y a eu echec de connexion, $this->db n'est pas valide. |
|
| 388 | - return 'DB_ERROR_FAILED_TO_CONNECT'; |
|
| 389 | - } else { |
|
| 390 | - // Constants to convert a MySql error code to a generic Dolibarr error code |
|
| 391 | - $errorcode_map = array( |
|
| 392 | - 1004 => 'DB_ERROR_CANNOT_CREATE', |
|
| 393 | - 1005 => 'DB_ERROR_CANNOT_CREATE', |
|
| 394 | - 1006 => 'DB_ERROR_CANNOT_CREATE', |
|
| 395 | - 1007 => 'DB_ERROR_ALREADY_EXISTS', |
|
| 396 | - 1008 => 'DB_ERROR_CANNOT_DROP', |
|
| 397 | - 1022 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', |
|
| 398 | - 1025 => 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP', |
|
| 399 | - 1044 => 'DB_ERROR_ACCESSDENIED', |
|
| 400 | - 1046 => 'DB_ERROR_NODBSELECTED', |
|
| 401 | - 1048 => 'DB_ERROR_CONSTRAINT', |
|
| 402 | - 1050 => 'DB_ERROR_TABLE_ALREADY_EXISTS', |
|
| 403 | - 1051 => 'DB_ERROR_NOSUCHTABLE', |
|
| 404 | - 1054 => 'DB_ERROR_NOSUCHFIELD', |
|
| 405 | - 1060 => 'DB_ERROR_COLUMN_ALREADY_EXISTS', |
|
| 406 | - 1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', |
|
| 407 | - 1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS', |
|
| 408 | - 1064 => 'DB_ERROR_SYNTAX', |
|
| 409 | - 1068 => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS', |
|
| 410 | - 1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY', |
|
| 411 | - 1091 => 'DB_ERROR_NOSUCHFIELD', |
|
| 412 | - 1100 => 'DB_ERROR_NOT_LOCKED', |
|
| 413 | - 1136 => 'DB_ERROR_VALUE_COUNT_ON_ROW', |
|
| 414 | - 1146 => 'DB_ERROR_NOSUCHTABLE', |
|
| 415 | - 1215 => 'DB_ERROR_CANNOT_ADD_FOREIGN_KEY_CONSTRAINT', |
|
| 416 | - 1216 => 'DB_ERROR_NO_PARENT', |
|
| 417 | - 1217 => 'DB_ERROR_CHILD_EXISTS', |
|
| 418 | - 1396 => 'DB_ERROR_USER_ALREADY_EXISTS', // When creating user already existing |
|
| 419 | - 1451 => 'DB_ERROR_CHILD_EXISTS' |
|
| 420 | - ); |
|
| 421 | - |
|
| 422 | - if (isset($errorcode_map[$this->db->errno])) { |
|
| 423 | - return $errorcode_map[$this->db->errno]; |
|
| 424 | - } |
|
| 425 | - $errno=$this->db->errno; |
|
| 426 | - return ($errno?'DB_ERROR_'.$errno:'0'); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Return datas as an array |
|
| 291 | + * |
|
| 292 | + * @param mysqli_result $resultset Resultset of request |
|
| 293 | + * @return array|null Array or null if KO or end of cursor |
|
| 294 | + */ |
|
| 295 | + function fetch_array($resultset) |
|
| 296 | + { |
|
| 297 | + // If resultset not provided, we take the last used by connexion |
|
| 298 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 299 | + return $resultset->fetch_array(); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Return datas as an array |
|
| 304 | + * |
|
| 305 | + * @param mysqli_result $resultset Resultset of request |
|
| 306 | + * @return array|null|0 Array or null if KO or end of cursor or 0 if resultset is bool |
|
| 307 | + */ |
|
| 308 | + function fetch_row($resultset) |
|
| 309 | + { |
|
| 310 | + // If resultset not provided, we take the last used by connexion |
|
| 311 | + if (! is_bool($resultset)) |
|
| 312 | + { |
|
| 313 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 314 | + return $resultset->fetch_row(); |
|
| 315 | + } |
|
| 316 | + else |
|
| 317 | + { |
|
| 318 | + // si le curseur est un booleen on retourne la valeur 0 |
|
| 319 | + return 0; |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Return number of lines for result of a SELECT |
|
| 325 | + * |
|
| 326 | + * @param mysqli_result $resultset Resulset of requests |
|
| 327 | + * @return int Nb of lines |
|
| 328 | + * @see affected_rows |
|
| 329 | + */ |
|
| 330 | + function num_rows($resultset) |
|
| 331 | + { |
|
| 332 | + // If resultset not provided, we take the last used by connexion |
|
| 333 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 334 | + return $resultset->num_rows; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Renvoie le nombre de lignes dans le resultat d'une requete INSERT, DELETE ou UPDATE |
|
| 339 | + * |
|
| 340 | + * @param mysqli_result $resultset Curseur de la requete voulue |
|
| 341 | + * @return int Nombre de lignes |
|
| 342 | + * @see num_rows |
|
| 343 | + */ |
|
| 344 | + function affected_rows($resultset) |
|
| 345 | + { |
|
| 346 | + // If resultset not provided, we take the last used by connexion |
|
| 347 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 348 | + // mysql necessite un link de base pour cette fonction contrairement |
|
| 349 | + // a pqsql qui prend un resultset |
|
| 350 | + return $this->db->affected_rows; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Libere le dernier resultset utilise sur cette connexion |
|
| 356 | + * |
|
| 357 | + * @param mysqli_result $resultset Curseur de la requete voulue |
|
| 358 | + * @return void |
|
| 359 | + */ |
|
| 360 | + function free($resultset=null) |
|
| 361 | + { |
|
| 362 | + // If resultset not provided, we take the last used by connexion |
|
| 363 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 364 | + // Si resultset en est un, on libere la memoire |
|
| 365 | + if (is_object($resultset)) $resultset->free_result(); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Escape a string to insert data |
|
| 370 | + * |
|
| 371 | + * @param string $stringtoencode String to escape |
|
| 372 | + * @return string String escaped |
|
| 373 | + */ |
|
| 374 | + function escape($stringtoencode) |
|
| 375 | + { |
|
| 376 | + return $this->db->real_escape_string($stringtoencode); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Return generic error code of last operation. |
|
| 381 | + * |
|
| 382 | + * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
| 383 | + */ |
|
| 384 | + function errno() |
|
| 385 | + { |
|
| 386 | + if (! $this->connected) { |
|
| 387 | + // Si il y a eu echec de connexion, $this->db n'est pas valide. |
|
| 388 | + return 'DB_ERROR_FAILED_TO_CONNECT'; |
|
| 389 | + } else { |
|
| 390 | + // Constants to convert a MySql error code to a generic Dolibarr error code |
|
| 391 | + $errorcode_map = array( |
|
| 392 | + 1004 => 'DB_ERROR_CANNOT_CREATE', |
|
| 393 | + 1005 => 'DB_ERROR_CANNOT_CREATE', |
|
| 394 | + 1006 => 'DB_ERROR_CANNOT_CREATE', |
|
| 395 | + 1007 => 'DB_ERROR_ALREADY_EXISTS', |
|
| 396 | + 1008 => 'DB_ERROR_CANNOT_DROP', |
|
| 397 | + 1022 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', |
|
| 398 | + 1025 => 'DB_ERROR_NO_FOREIGN_KEY_TO_DROP', |
|
| 399 | + 1044 => 'DB_ERROR_ACCESSDENIED', |
|
| 400 | + 1046 => 'DB_ERROR_NODBSELECTED', |
|
| 401 | + 1048 => 'DB_ERROR_CONSTRAINT', |
|
| 402 | + 1050 => 'DB_ERROR_TABLE_ALREADY_EXISTS', |
|
| 403 | + 1051 => 'DB_ERROR_NOSUCHTABLE', |
|
| 404 | + 1054 => 'DB_ERROR_NOSUCHFIELD', |
|
| 405 | + 1060 => 'DB_ERROR_COLUMN_ALREADY_EXISTS', |
|
| 406 | + 1061 => 'DB_ERROR_KEY_NAME_ALREADY_EXISTS', |
|
| 407 | + 1062 => 'DB_ERROR_RECORD_ALREADY_EXISTS', |
|
| 408 | + 1064 => 'DB_ERROR_SYNTAX', |
|
| 409 | + 1068 => 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS', |
|
| 410 | + 1075 => 'DB_ERROR_CANT_DROP_PRIMARY_KEY', |
|
| 411 | + 1091 => 'DB_ERROR_NOSUCHFIELD', |
|
| 412 | + 1100 => 'DB_ERROR_NOT_LOCKED', |
|
| 413 | + 1136 => 'DB_ERROR_VALUE_COUNT_ON_ROW', |
|
| 414 | + 1146 => 'DB_ERROR_NOSUCHTABLE', |
|
| 415 | + 1215 => 'DB_ERROR_CANNOT_ADD_FOREIGN_KEY_CONSTRAINT', |
|
| 416 | + 1216 => 'DB_ERROR_NO_PARENT', |
|
| 417 | + 1217 => 'DB_ERROR_CHILD_EXISTS', |
|
| 418 | + 1396 => 'DB_ERROR_USER_ALREADY_EXISTS', // When creating user already existing |
|
| 419 | + 1451 => 'DB_ERROR_CHILD_EXISTS' |
|
| 420 | + ); |
|
| 421 | + |
|
| 422 | + if (isset($errorcode_map[$this->db->errno])) { |
|
| 423 | + return $errorcode_map[$this->db->errno]; |
|
| 424 | + } |
|
| 425 | + $errno=$this->db->errno; |
|
| 426 | + return ($errno?'DB_ERROR_'.$errno:'0'); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | 431 | * Return description of last error |
| 432 | 432 | * |
| 433 | 433 | * @return string Error text |
| 434 | - */ |
|
| 435 | - function error() |
|
| 436 | - { |
|
| 437 | - if (! $this->connected) { |
|
| 438 | - // Si il y a eu echec de connexion, $this->db n'est pas valide pour mysqli_error. |
|
| 439 | - return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions'; |
|
| 440 | - } |
|
| 441 | - else { |
|
| 442 | - return $this->db->error; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 434 | + */ |
|
| 435 | + function error() |
|
| 436 | + { |
|
| 437 | + if (! $this->connected) { |
|
| 438 | + // Si il y a eu echec de connexion, $this->db n'est pas valide pour mysqli_error. |
|
| 439 | + return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions'; |
|
| 440 | + } |
|
| 441 | + else { |
|
| 442 | + return $this->db->error; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | 447 | * Get last ID after an insert INSERT |
| 448 | 448 | * |
| 449 | 449 | * @param string $tab Table name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql |
| 450 | 450 | * @param string $fieldid Field name |
| 451 | 451 | * @return int|string Id of row |
| 452 | - */ |
|
| 453 | - function last_insert_id($tab,$fieldid='rowid') |
|
| 454 | - { |
|
| 455 | - return $this->db->insert_id; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Encrypt sensitive data in database |
|
| 460 | - * Warning: This function includes the escape, so it must use direct value |
|
| 461 | - * |
|
| 462 | - * @param string $fieldorvalue Field name or value to encrypt |
|
| 463 | - * @param int $withQuotes Return string with quotes |
|
| 464 | - * @return string XXX(field) or XXX('value') or field or 'value' |
|
| 465 | - * |
|
| 466 | - */ |
|
| 467 | - function encrypt($fieldorvalue, $withQuotes=0) |
|
| 468 | - { |
|
| 469 | - global $conf; |
|
| 470 | - |
|
| 471 | - // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
| 472 | - $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
| 473 | - |
|
| 474 | - //Encryption key |
|
| 475 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
| 476 | - |
|
| 477 | - $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
| 478 | - |
|
| 479 | - if ($cryptType && !empty($cryptKey)) |
|
| 480 | - { |
|
| 481 | - if ($cryptType == 2) |
|
| 482 | - { |
|
| 483 | - $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
| 484 | - } |
|
| 485 | - else if ($cryptType == 1) |
|
| 486 | - { |
|
| 487 | - $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - return $return; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Decrypt sensitive data in database |
|
| 496 | - * |
|
| 497 | - * @param string $value Value to decrypt |
|
| 498 | - * @return string Decrypted value if used |
|
| 499 | - */ |
|
| 500 | - function decrypt($value) |
|
| 501 | - { |
|
| 502 | - global $conf; |
|
| 503 | - |
|
| 504 | - // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
| 505 | - $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
| 506 | - |
|
| 507 | - //Encryption key |
|
| 508 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
| 509 | - |
|
| 510 | - $return = $value; |
|
| 511 | - |
|
| 512 | - if ($cryptType && !empty($cryptKey)) |
|
| 513 | - { |
|
| 514 | - if ($cryptType == 2) |
|
| 515 | - { |
|
| 516 | - $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
| 517 | - } |
|
| 518 | - else if ($cryptType == 1) |
|
| 519 | - { |
|
| 520 | - $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - return $return; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 452 | + */ |
|
| 453 | + function last_insert_id($tab,$fieldid='rowid') |
|
| 454 | + { |
|
| 455 | + return $this->db->insert_id; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Encrypt sensitive data in database |
|
| 460 | + * Warning: This function includes the escape, so it must use direct value |
|
| 461 | + * |
|
| 462 | + * @param string $fieldorvalue Field name or value to encrypt |
|
| 463 | + * @param int $withQuotes Return string with quotes |
|
| 464 | + * @return string XXX(field) or XXX('value') or field or 'value' |
|
| 465 | + * |
|
| 466 | + */ |
|
| 467 | + function encrypt($fieldorvalue, $withQuotes=0) |
|
| 468 | + { |
|
| 469 | + global $conf; |
|
| 470 | + |
|
| 471 | + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
| 472 | + $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
| 473 | + |
|
| 474 | + //Encryption key |
|
| 475 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
| 476 | + |
|
| 477 | + $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
| 478 | + |
|
| 479 | + if ($cryptType && !empty($cryptKey)) |
|
| 480 | + { |
|
| 481 | + if ($cryptType == 2) |
|
| 482 | + { |
|
| 483 | + $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
| 484 | + } |
|
| 485 | + else if ($cryptType == 1) |
|
| 486 | + { |
|
| 487 | + $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + return $return; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Decrypt sensitive data in database |
|
| 496 | + * |
|
| 497 | + * @param string $value Value to decrypt |
|
| 498 | + * @return string Decrypted value if used |
|
| 499 | + */ |
|
| 500 | + function decrypt($value) |
|
| 501 | + { |
|
| 502 | + global $conf; |
|
| 503 | + |
|
| 504 | + // Type of encryption (2: AES (recommended), 1: DES , 0: no encryption) |
|
| 505 | + $cryptType = (!empty($conf->db->dolibarr_main_db_encryption)?$conf->db->dolibarr_main_db_encryption:0); |
|
| 506 | + |
|
| 507 | + //Encryption key |
|
| 508 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
| 509 | + |
|
| 510 | + $return = $value; |
|
| 511 | + |
|
| 512 | + if ($cryptType && !empty($cryptKey)) |
|
| 513 | + { |
|
| 514 | + if ($cryptType == 2) |
|
| 515 | + { |
|
| 516 | + $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
| 517 | + } |
|
| 518 | + else if ($cryptType == 1) |
|
| 519 | + { |
|
| 520 | + $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + return $return; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | 529 | * Return connexion ID |
| 530 | 530 | * |
| 531 | 531 | * @return string Id connexion |
| 532 | - */ |
|
| 533 | - function DDLGetConnectId() |
|
| 534 | - { |
|
| 535 | - $resql=$this->query('SELECT CONNECTION_ID()'); |
|
| 536 | - if ($resql) |
|
| 537 | - { |
|
| 538 | - $row=$this->fetch_row($resql); |
|
| 539 | - return $row[0]; |
|
| 540 | - } |
|
| 541 | - else return '?'; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /** |
|
| 532 | + */ |
|
| 533 | + function DDLGetConnectId() |
|
| 534 | + { |
|
| 535 | + $resql=$this->query('SELECT CONNECTION_ID()'); |
|
| 536 | + if ($resql) |
|
| 537 | + { |
|
| 538 | + $row=$this->fetch_row($resql); |
|
| 539 | + return $row[0]; |
|
| 540 | + } |
|
| 541 | + else return '?'; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | 545 | * Create a new database |
| 546 | 546 | * Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated |
| 547 | 547 | * We force to create database with charset this->forcecharset and collate this->forcecollate |
@@ -551,79 +551,79 @@ discard block |
||
| 551 | 551 | * @param string $collation Charset used to sort data |
| 552 | 552 | * @param string $owner Username of database owner |
| 553 | 553 | * @return bool|mysqli_result resource defined if OK, null if KO |
| 554 | - */ |
|
| 555 | - function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
| 556 | - { |
|
| 557 | - if (empty($charset)) $charset=$this->forcecharset; |
|
| 558 | - if (empty($collation)) $collation=$this->forcecollate; |
|
| 554 | + */ |
|
| 555 | + function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
| 556 | + { |
|
| 557 | + if (empty($charset)) $charset=$this->forcecharset; |
|
| 558 | + if (empty($collation)) $collation=$this->forcecollate; |
|
| 559 | 559 | |
| 560 | - // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
|
| 560 | + // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
|
| 561 | 561 | $sql = "CREATE DATABASE `".$this->escape($database)."`"; |
| 562 | 562 | $sql.= " DEFAULT CHARACTER SET `".$this->escape($charset)."` DEFAULT COLLATE `".$this->escape($collation)."`"; |
| 563 | 563 | |
| 564 | - dol_syslog($sql,LOG_DEBUG); |
|
| 565 | - $ret=$this->query($sql); |
|
| 566 | - if (! $ret) |
|
| 567 | - { |
|
| 568 | - // We try again for compatibility with Mysql < 4.1.1 |
|
| 569 | - $sql = "CREATE DATABASE `".$this->escape($database)."`"; |
|
| 570 | - dol_syslog($sql,LOG_DEBUG); |
|
| 571 | - $ret=$this->query($sql); |
|
| 572 | - } |
|
| 573 | - return $ret; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - /** |
|
| 564 | + dol_syslog($sql,LOG_DEBUG); |
|
| 565 | + $ret=$this->query($sql); |
|
| 566 | + if (! $ret) |
|
| 567 | + { |
|
| 568 | + // We try again for compatibility with Mysql < 4.1.1 |
|
| 569 | + $sql = "CREATE DATABASE `".$this->escape($database)."`"; |
|
| 570 | + dol_syslog($sql,LOG_DEBUG); |
|
| 571 | + $ret=$this->query($sql); |
|
| 572 | + } |
|
| 573 | + return $ret; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | 577 | * List tables into a database |
| 578 | 578 | * |
| 579 | 579 | * @param string $database Name of database |
| 580 | 580 | * @param string $table Nmae of table filter ('xxx%') |
| 581 | 581 | * @return array List of tables in an array |
| 582 | - */ |
|
| 583 | - function DDLListTables($database, $table='') |
|
| 584 | - { |
|
| 585 | - $listtables=array(); |
|
| 586 | - |
|
| 587 | - $like = ''; |
|
| 588 | - if ($table) $like = "LIKE '".$table."'"; |
|
| 589 | - $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
| 590 | - //print $sql; |
|
| 591 | - $result = $this->query($sql); |
|
| 592 | - if ($result) |
|
| 593 | - { |
|
| 594 | - while($row = $this->fetch_row($result)) |
|
| 595 | - { |
|
| 596 | - $listtables[] = $row[0]; |
|
| 597 | - } |
|
| 598 | - } |
|
| 599 | - return $listtables; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - /** |
|
| 582 | + */ |
|
| 583 | + function DDLListTables($database, $table='') |
|
| 584 | + { |
|
| 585 | + $listtables=array(); |
|
| 586 | + |
|
| 587 | + $like = ''; |
|
| 588 | + if ($table) $like = "LIKE '".$table."'"; |
|
| 589 | + $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
| 590 | + //print $sql; |
|
| 591 | + $result = $this->query($sql); |
|
| 592 | + if ($result) |
|
| 593 | + { |
|
| 594 | + while($row = $this->fetch_row($result)) |
|
| 595 | + { |
|
| 596 | + $listtables[] = $row[0]; |
|
| 597 | + } |
|
| 598 | + } |
|
| 599 | + return $listtables; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | 603 | * List information of columns into a table. |
| 604 | 604 | * |
| 605 | 605 | * @param string $table Name of table |
| 606 | 606 | * @return array Tableau des informations des champs de la table |
| 607 | - */ |
|
| 608 | - function DDLInfoTable($table) |
|
| 609 | - { |
|
| 610 | - $infotables=array(); |
|
| 611 | - |
|
| 612 | - $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
| 613 | - |
|
| 614 | - dol_syslog($sql,LOG_DEBUG); |
|
| 615 | - $result = $this->query($sql); |
|
| 616 | - if ($result) |
|
| 617 | - { |
|
| 618 | - while($row = $this->fetch_row($result)) |
|
| 619 | - { |
|
| 620 | - $infotables[] = $row; |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - return $infotables; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - /** |
|
| 607 | + */ |
|
| 608 | + function DDLInfoTable($table) |
|
| 609 | + { |
|
| 610 | + $infotables=array(); |
|
| 611 | + |
|
| 612 | + $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
| 613 | + |
|
| 614 | + dol_syslog($sql,LOG_DEBUG); |
|
| 615 | + $result = $this->query($sql); |
|
| 616 | + if ($result) |
|
| 617 | + { |
|
| 618 | + while($row = $this->fetch_row($result)) |
|
| 619 | + { |
|
| 620 | + $infotables[] = $row; |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + return $infotables; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | 627 | * Create a table into database |
| 628 | 628 | * |
| 629 | 629 | * @param string $table Nom de la table |
@@ -634,18 +634,18 @@ discard block |
||
| 634 | 634 | * @param array $fulltext_keys Tableau des Nom de champs qui seront indexes en fulltext |
| 635 | 635 | * @param array $keys Tableau des champs cles noms => valeur |
| 636 | 636 | * @return int <0 if KO, >=0 if OK |
| 637 | - */ |
|
| 638 | - function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
| 639 | - { |
|
| 640 | - // FIXME: $fulltext_keys parameter is unused |
|
| 641 | - |
|
| 642 | - // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
|
| 643 | - // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
| 644 | - $sql = "CREATE TABLE ".$table."("; |
|
| 645 | - $i=0; |
|
| 646 | - foreach($fields as $field_name => $field_desc) |
|
| 647 | - { |
|
| 648 | - $sqlfields[$i] = $field_name." "; |
|
| 637 | + */ |
|
| 638 | + function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
| 639 | + { |
|
| 640 | + // FIXME: $fulltext_keys parameter is unused |
|
| 641 | + |
|
| 642 | + // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
|
| 643 | + // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
| 644 | + $sql = "CREATE TABLE ".$table."("; |
|
| 645 | + $i=0; |
|
| 646 | + foreach($fields as $field_name => $field_desc) |
|
| 647 | + { |
|
| 648 | + $sqlfields[$i] = $field_name." "; |
|
| 649 | 649 | $sqlfields[$i] .= $field_desc['type']; |
| 650 | 650 | if( preg_match("/^[^\s]/i",$field_desc['value'])) { |
| 651 | 651 | $sqlfields[$i] .= "(".$field_desc['value'].")"; |
@@ -668,61 +668,61 @@ discard block |
||
| 668 | 668 | if( preg_match("/^[^\s]/i",$field_desc['extra'])) { |
| 669 | 669 | $sqlfields[$i] .= " ".$field_desc['extra']; |
| 670 | 670 | } |
| 671 | - $i++; |
|
| 672 | - } |
|
| 673 | - if($primary_key != "") |
|
| 674 | - $pk = "primary key(".$primary_key.")"; |
|
| 675 | - |
|
| 676 | - if(is_array($unique_keys)) { |
|
| 677 | - $i = 0; |
|
| 678 | - foreach($unique_keys as $key => $value) |
|
| 679 | - { |
|
| 680 | - $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
|
| 681 | - $i++; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - if(is_array($keys)) |
|
| 685 | - { |
|
| 686 | - $i = 0; |
|
| 687 | - foreach($keys as $key => $value) |
|
| 688 | - { |
|
| 689 | - $sqlk[$i] = "KEY ".$key." (".$value.")"; |
|
| 690 | - $i++; |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - $sql .= implode(',',$sqlfields); |
|
| 694 | - if($primary_key != "") |
|
| 695 | - $sql .= ",".$pk; |
|
| 696 | - if($unique_keys != "") |
|
| 697 | - $sql .= ",".implode(',',$sqluq); |
|
| 698 | - if(is_array($keys)) |
|
| 699 | - $sql .= ",".implode(',',$sqlk); |
|
| 700 | - $sql .=") engine=".$type; |
|
| 701 | - |
|
| 702 | - dol_syslog($sql,LOG_DEBUG); |
|
| 703 | - if(! $this -> query($sql)) |
|
| 704 | - return -1; |
|
| 705 | - else |
|
| 706 | - return 1; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 671 | + $i++; |
|
| 672 | + } |
|
| 673 | + if($primary_key != "") |
|
| 674 | + $pk = "primary key(".$primary_key.")"; |
|
| 675 | + |
|
| 676 | + if(is_array($unique_keys)) { |
|
| 677 | + $i = 0; |
|
| 678 | + foreach($unique_keys as $key => $value) |
|
| 679 | + { |
|
| 680 | + $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
|
| 681 | + $i++; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + if(is_array($keys)) |
|
| 685 | + { |
|
| 686 | + $i = 0; |
|
| 687 | + foreach($keys as $key => $value) |
|
| 688 | + { |
|
| 689 | + $sqlk[$i] = "KEY ".$key." (".$value.")"; |
|
| 690 | + $i++; |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + $sql .= implode(',',$sqlfields); |
|
| 694 | + if($primary_key != "") |
|
| 695 | + $sql .= ",".$pk; |
|
| 696 | + if($unique_keys != "") |
|
| 697 | + $sql .= ",".implode(',',$sqluq); |
|
| 698 | + if(is_array($keys)) |
|
| 699 | + $sql .= ",".implode(',',$sqlk); |
|
| 700 | + $sql .=") engine=".$type; |
|
| 701 | + |
|
| 702 | + dol_syslog($sql,LOG_DEBUG); |
|
| 703 | + if(! $this -> query($sql)) |
|
| 704 | + return -1; |
|
| 705 | + else |
|
| 706 | + return 1; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | 710 | * Return a pointer of line with description of a table or field |
| 711 | 711 | * |
| 712 | 712 | * @param string $table Name of table |
| 713 | 713 | * @param string $field Optionnel : Name of field if we want description of field |
| 714 | 714 | * @return bool|mysqli_result Resultset x (x->Field, x->Type, ...) |
| 715 | - */ |
|
| 716 | - function DDLDescTable($table,$field="") |
|
| 717 | - { |
|
| 718 | - $sql="DESC ".$table." ".$field; |
|
| 715 | + */ |
|
| 716 | + function DDLDescTable($table,$field="") |
|
| 717 | + { |
|
| 718 | + $sql="DESC ".$table." ".$field; |
|
| 719 | 719 | |
| 720 | - dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
| 721 | - $this->_results = $this->query($sql); |
|
| 722 | - return $this->_results; |
|
| 723 | - } |
|
| 720 | + dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
| 721 | + $this->_results = $this->query($sql); |
|
| 722 | + return $this->_results; |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | - /** |
|
| 725 | + /** |
|
| 726 | 726 | * Create a new field into table |
| 727 | 727 | * |
| 728 | 728 | * @param string $table Name of table |
@@ -730,105 +730,105 @@ discard block |
||
| 730 | 730 | * @param string $field_desc Tableau associatif de description du champ a inserer[nom du parametre][valeur du parametre] |
| 731 | 731 | * @param string $field_position Optionnel ex.: "after champtruc" |
| 732 | 732 | * @return int <0 if KO, >0 if OK |
| 733 | - */ |
|
| 734 | - function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
| 735 | - { |
|
| 736 | - // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
|
| 737 | - // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
| 738 | - $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
| 739 | - $sql.= $field_desc['type']; |
|
| 740 | - if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 741 | - if (! in_array($field_desc['type'],array('date','datetime'))) |
|
| 742 | - { |
|
| 743 | - $sql.= "(".$field_desc['value'].")"; |
|
| 744 | - } |
|
| 745 | - if(preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 746 | - $sql.= " ".$field_desc['attribute']; |
|
| 747 | - if(preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 748 | - $sql.= " ".$field_desc['null']; |
|
| 749 | - if(preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 750 | - { |
|
| 751 | - if(preg_match("/null/i",$field_desc['default'])) |
|
| 752 | - $sql.= " default ".$field_desc['default']; |
|
| 753 | - else |
|
| 754 | - $sql.= " default '".$field_desc['default']."'"; |
|
| 755 | - } |
|
| 756 | - if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 757 | - $sql.= " ".$field_desc['extra']; |
|
| 758 | - $sql.= " ".$field_position; |
|
| 759 | - |
|
| 760 | - dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
| 761 | - if($this->query($sql)) { |
|
| 762 | - return 1; |
|
| 763 | - } |
|
| 764 | - return -1; |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - /** |
|
| 733 | + */ |
|
| 734 | + function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
| 735 | + { |
|
| 736 | + // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
|
| 737 | + // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
| 738 | + $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
|
| 739 | + $sql.= $field_desc['type']; |
|
| 740 | + if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 741 | + if (! in_array($field_desc['type'],array('date','datetime'))) |
|
| 742 | + { |
|
| 743 | + $sql.= "(".$field_desc['value'].")"; |
|
| 744 | + } |
|
| 745 | + if(preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 746 | + $sql.= " ".$field_desc['attribute']; |
|
| 747 | + if(preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 748 | + $sql.= " ".$field_desc['null']; |
|
| 749 | + if(preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 750 | + { |
|
| 751 | + if(preg_match("/null/i",$field_desc['default'])) |
|
| 752 | + $sql.= " default ".$field_desc['default']; |
|
| 753 | + else |
|
| 754 | + $sql.= " default '".$field_desc['default']."'"; |
|
| 755 | + } |
|
| 756 | + if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 757 | + $sql.= " ".$field_desc['extra']; |
|
| 758 | + $sql.= " ".$field_position; |
|
| 759 | + |
|
| 760 | + dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
| 761 | + if($this->query($sql)) { |
|
| 762 | + return 1; |
|
| 763 | + } |
|
| 764 | + return -1; |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + /** |
|
| 768 | 768 | * Update format of a field into a table |
| 769 | 769 | * |
| 770 | 770 | * @param string $table Name of table |
| 771 | 771 | * @param string $field_name Name of field to modify |
| 772 | 772 | * @param string $field_desc Array with description of field format |
| 773 | 773 | * @return int <0 if KO, >0 if OK |
| 774 | - */ |
|
| 775 | - function DDLUpdateField($table,$field_name,$field_desc) |
|
| 776 | - { |
|
| 777 | - $sql = "ALTER TABLE ".$table; |
|
| 778 | - $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
|
| 779 | - if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
|
| 780 | - $sql.="(".$field_desc['value'].")"; |
|
| 781 | - } |
|
| 782 | - if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') |
|
| 783 | - { |
|
| 784 | - // 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 |
|
| 785 | - if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
|
| 786 | - { |
|
| 787 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
| 788 | - $this->query($sqlbis); |
|
| 789 | - } |
|
| 790 | - elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
| 791 | - { |
|
| 792 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
| 793 | - $this->query($sqlbis); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - $sql.=" NOT NULL"; |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - if ($field_desc['default'] != '') |
|
| 800 | - { |
|
| 774 | + */ |
|
| 775 | + function DDLUpdateField($table,$field_name,$field_desc) |
|
| 776 | + { |
|
| 777 | + $sql = "ALTER TABLE ".$table; |
|
| 778 | + $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
|
| 779 | + if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
|
| 780 | + $sql.="(".$field_desc['value'].")"; |
|
| 781 | + } |
|
| 782 | + if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') |
|
| 783 | + { |
|
| 784 | + // 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 |
|
| 785 | + if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
|
| 786 | + { |
|
| 787 | + $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
| 788 | + $this->query($sqlbis); |
|
| 789 | + } |
|
| 790 | + elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
| 791 | + { |
|
| 792 | + $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
| 793 | + $this->query($sqlbis); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + $sql.=" NOT NULL"; |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + if ($field_desc['default'] != '') |
|
| 800 | + { |
|
| 801 | 801 | if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']); |
| 802 | - elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
| 803 | - } |
|
| 802 | + elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
| 803 | + } |
|
| 804 | 804 | |
| 805 | - dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
| 806 | - if (! $this->query($sql)) |
|
| 807 | - return -1; |
|
| 808 | - else |
|
| 809 | - return 1; |
|
| 810 | - } |
|
| 805 | + dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
| 806 | + if (! $this->query($sql)) |
|
| 807 | + return -1; |
|
| 808 | + else |
|
| 809 | + return 1; |
|
| 810 | + } |
|
| 811 | 811 | |
| 812 | - /** |
|
| 812 | + /** |
|
| 813 | 813 | * Drop a field from table |
| 814 | 814 | * |
| 815 | 815 | * @param string $table Name of table |
| 816 | 816 | * @param string $field_name Name of field to drop |
| 817 | 817 | * @return int <0 if KO, >0 if OK |
| 818 | - */ |
|
| 819 | - function DDLDropField($table,$field_name) |
|
| 820 | - { |
|
| 821 | - $sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
| 822 | - dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG); |
|
| 823 | - if ($this->query($sql)) { |
|
| 824 | - return 1; |
|
| 825 | - } |
|
| 826 | - $this->error=$this->lasterror(); |
|
| 827 | - return -1; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - |
|
| 831 | - /** |
|
| 818 | + */ |
|
| 819 | + function DDLDropField($table,$field_name) |
|
| 820 | + { |
|
| 821 | + $sql= "ALTER TABLE ".$table." DROP COLUMN `".$field_name."`"; |
|
| 822 | + dol_syslog(get_class($this)."::DDLDropField ".$sql,LOG_DEBUG); |
|
| 823 | + if ($this->query($sql)) { |
|
| 824 | + return 1; |
|
| 825 | + } |
|
| 826 | + $this->error=$this->lasterror(); |
|
| 827 | + return -1; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | 832 | * Create a user and privileges to connect to database (even if database does not exists yet) |
| 833 | 833 | * |
| 834 | 834 | * @param string $dolibarr_main_db_host Ip server or '%' |
@@ -836,213 +836,213 @@ discard block |
||
| 836 | 836 | * @param string $dolibarr_main_db_pass Mot de passe user a creer |
| 837 | 837 | * @param string $dolibarr_main_db_name Database name where user must be granted |
| 838 | 838 | * @return int <0 if KO, >=0 if OK |
| 839 | - */ |
|
| 840 | - function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
| 841 | - { |
|
| 842 | - $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'"; |
|
| 843 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
| 844 | - $resql=$this->query($sql); |
|
| 845 | - if (! $resql) |
|
| 846 | - { |
|
| 847 | - if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS') |
|
| 848 | - { |
|
| 849 | - return -1; |
|
| 850 | - } |
|
| 851 | - else |
|
| 839 | + */ |
|
| 840 | + function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
| 841 | + { |
|
| 842 | + $sql = "CREATE USER '".$this->escape($dolibarr_main_db_user)."'"; |
|
| 843 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
| 844 | + $resql=$this->query($sql); |
|
| 845 | + if (! $resql) |
|
| 846 | + { |
|
| 847 | + if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS') |
|
| 848 | + { |
|
| 849 | + return -1; |
|
| 850 | + } |
|
| 851 | + else |
|
| 852 | + { |
|
| 853 | + // If user already exists, we continue to set permissions |
|
| 854 | + dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + $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)."'"; |
|
| 858 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
| 859 | + $resql=$this->query($sql); |
|
| 860 | + if (! $resql) |
|
| 861 | + { |
|
| 862 | + return -1; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + $sql="FLUSH Privileges"; |
|
| 866 | + |
|
| 867 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
| 868 | + $resql=$this->query($sql); |
|
| 869 | + if (! $resql) |
|
| 870 | + { |
|
| 871 | + return -1; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + return 1; |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * Return charset used to store data in current database (same result than using SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = "databasename";) |
|
| 879 | + * |
|
| 880 | + * @return string Charset |
|
| 881 | + * @see getDefaultCollationDatabase |
|
| 882 | + */ |
|
| 883 | + function getDefaultCharacterSetDatabase() |
|
| 884 | + { |
|
| 885 | + $resql=$this->query('SHOW VARIABLES LIKE \'character_set_database\''); |
|
| 886 | + if (!$resql) |
|
| 887 | + { |
|
| 888 | + // version Mysql < 4.1.1 |
|
| 889 | + return $this->forcecharset; |
|
| 890 | + } |
|
| 891 | + $liste=$this->fetch_array($resql); |
|
| 892 | + $tmpval = $liste['Value']; |
|
| 893 | + |
|
| 894 | + return $tmpval; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * Return list of available charset that can be used to store data in database |
|
| 899 | + * |
|
| 900 | + * @return array|null List of Charset |
|
| 901 | + */ |
|
| 902 | + function getListOfCharacterSet() |
|
| 903 | + { |
|
| 904 | + $resql=$this->query('SHOW CHARSET'); |
|
| 905 | + $liste = array(); |
|
| 906 | + if ($resql) |
|
| 907 | + { |
|
| 908 | + $i = 0; |
|
| 909 | + while ($obj = $this->fetch_object($resql) ) |
|
| 910 | + { |
|
| 911 | + $liste[$i]['charset'] = $obj->Charset; |
|
| 912 | + $liste[$i]['description'] = $obj->Description; |
|
| 913 | + $i++; |
|
| 914 | + } |
|
| 915 | + $this->free($resql); |
|
| 916 | + } else { |
|
| 917 | + // version Mysql < 4.1.1 |
|
| 918 | + return null; |
|
| 919 | + } |
|
| 920 | + return $liste; |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * Return collation used in current database |
|
| 925 | + * |
|
| 926 | + * @return string Collation value |
|
| 927 | + * @see getDefaultCharacterSetDatabase |
|
| 928 | + */ |
|
| 929 | + function getDefaultCollationDatabase() |
|
| 930 | + { |
|
| 931 | + $resql=$this->query('SHOW VARIABLES LIKE \'collation_database\''); |
|
| 932 | + if (!$resql) |
|
| 933 | + { |
|
| 934 | + // version Mysql < 4.1.1 |
|
| 935 | + return $this->forcecollate; |
|
| 936 | + } |
|
| 937 | + $liste=$this->fetch_array($resql); |
|
| 938 | + $tmpval = $liste['Value']; |
|
| 939 | + |
|
| 940 | + return $tmpval; |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * Return list of available collation that can be used for database |
|
| 945 | + * |
|
| 946 | + * @return array|null Liste of Collation |
|
| 947 | + */ |
|
| 948 | + function getListOfCollation() |
|
| 949 | + { |
|
| 950 | + $resql=$this->query('SHOW COLLATION'); |
|
| 951 | + $liste = array(); |
|
| 952 | + if ($resql) |
|
| 953 | + { |
|
| 954 | + $i = 0; |
|
| 955 | + while ($obj = $this->fetch_object($resql) ) |
|
| 852 | 956 | { |
| 853 | - // If user already exists, we continue to set permissions |
|
| 854 | - dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - $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)."'"; |
|
| 858 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); // No sql to avoid password in log |
|
| 859 | - $resql=$this->query($sql); |
|
| 860 | - if (! $resql) |
|
| 861 | - { |
|
| 862 | - return -1; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - $sql="FLUSH Privileges"; |
|
| 866 | - |
|
| 867 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
| 868 | - $resql=$this->query($sql); |
|
| 869 | - if (! $resql) |
|
| 870 | - { |
|
| 871 | - return -1; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - return 1; |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * Return charset used to store data in current database (same result than using SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = "databasename";) |
|
| 879 | - * |
|
| 880 | - * @return string Charset |
|
| 881 | - * @see getDefaultCollationDatabase |
|
| 882 | - */ |
|
| 883 | - function getDefaultCharacterSetDatabase() |
|
| 884 | - { |
|
| 885 | - $resql=$this->query('SHOW VARIABLES LIKE \'character_set_database\''); |
|
| 886 | - if (!$resql) |
|
| 887 | - { |
|
| 888 | - // version Mysql < 4.1.1 |
|
| 889 | - return $this->forcecharset; |
|
| 890 | - } |
|
| 891 | - $liste=$this->fetch_array($resql); |
|
| 892 | - $tmpval = $liste['Value']; |
|
| 893 | - |
|
| 894 | - return $tmpval; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * Return list of available charset that can be used to store data in database |
|
| 899 | - * |
|
| 900 | - * @return array|null List of Charset |
|
| 901 | - */ |
|
| 902 | - function getListOfCharacterSet() |
|
| 903 | - { |
|
| 904 | - $resql=$this->query('SHOW CHARSET'); |
|
| 905 | - $liste = array(); |
|
| 906 | - if ($resql) |
|
| 907 | - { |
|
| 908 | - $i = 0; |
|
| 909 | - while ($obj = $this->fetch_object($resql) ) |
|
| 910 | - { |
|
| 911 | - $liste[$i]['charset'] = $obj->Charset; |
|
| 912 | - $liste[$i]['description'] = $obj->Description; |
|
| 913 | - $i++; |
|
| 914 | - } |
|
| 915 | - $this->free($resql); |
|
| 916 | - } else { |
|
| 917 | - // version Mysql < 4.1.1 |
|
| 918 | - return null; |
|
| 919 | - } |
|
| 920 | - return $liste; |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * Return collation used in current database |
|
| 925 | - * |
|
| 926 | - * @return string Collation value |
|
| 927 | - * @see getDefaultCharacterSetDatabase |
|
| 928 | - */ |
|
| 929 | - function getDefaultCollationDatabase() |
|
| 930 | - { |
|
| 931 | - $resql=$this->query('SHOW VARIABLES LIKE \'collation_database\''); |
|
| 932 | - if (!$resql) |
|
| 933 | - { |
|
| 934 | - // version Mysql < 4.1.1 |
|
| 935 | - return $this->forcecollate; |
|
| 936 | - } |
|
| 937 | - $liste=$this->fetch_array($resql); |
|
| 938 | - $tmpval = $liste['Value']; |
|
| 939 | - |
|
| 940 | - return $tmpval; |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * Return list of available collation that can be used for database |
|
| 945 | - * |
|
| 946 | - * @return array|null Liste of Collation |
|
| 947 | - */ |
|
| 948 | - function getListOfCollation() |
|
| 949 | - { |
|
| 950 | - $resql=$this->query('SHOW COLLATION'); |
|
| 951 | - $liste = array(); |
|
| 952 | - if ($resql) |
|
| 953 | - { |
|
| 954 | - $i = 0; |
|
| 955 | - while ($obj = $this->fetch_object($resql) ) |
|
| 956 | - { |
|
| 957 | - $liste[$i]['collation'] = $obj->Collation; |
|
| 958 | - $i++; |
|
| 959 | - } |
|
| 960 | - $this->free($resql); |
|
| 961 | - } else { |
|
| 962 | - // version Mysql < 4.1.1 |
|
| 963 | - return null; |
|
| 964 | - } |
|
| 965 | - return $liste; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - /** |
|
| 957 | + $liste[$i]['collation'] = $obj->Collation; |
|
| 958 | + $i++; |
|
| 959 | + } |
|
| 960 | + $this->free($resql); |
|
| 961 | + } else { |
|
| 962 | + // version Mysql < 4.1.1 |
|
| 963 | + return null; |
|
| 964 | + } |
|
| 965 | + return $liste; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + /** |
|
| 969 | 969 | * Return full path of dump program |
| 970 | 970 | * |
| 971 | 971 | * @return string Full path of dump program |
| 972 | - */ |
|
| 973 | - function getPathOfDump() |
|
| 974 | - { |
|
| 975 | - $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
| 976 | - |
|
| 977 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
| 978 | - if ($resql) |
|
| 979 | - { |
|
| 980 | - $liste=$this->fetch_array($resql); |
|
| 981 | - $basedir=$liste['Value']; |
|
| 982 | - $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
| 983 | - } |
|
| 984 | - return $fullpathofdump; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * Return full path of restore program |
|
| 989 | - * |
|
| 990 | - * @return string Full path of restore program |
|
| 991 | - */ |
|
| 992 | - function getPathOfRestore() |
|
| 993 | - { |
|
| 994 | - $fullpathofimport='/pathtomysql/mysql'; |
|
| 995 | - |
|
| 996 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
| 997 | - if ($resql) |
|
| 998 | - { |
|
| 999 | - $liste=$this->fetch_array($resql); |
|
| 1000 | - $basedir=$liste['Value']; |
|
| 1001 | - $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
| 1002 | - } |
|
| 1003 | - return $fullpathofimport; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * Return value of server parameters |
|
| 1008 | - * |
|
| 1009 | - * @param string $filter Filter list on a particular value |
|
| 972 | + */ |
|
| 973 | + function getPathOfDump() |
|
| 974 | + { |
|
| 975 | + $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
| 976 | + |
|
| 977 | + $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
| 978 | + if ($resql) |
|
| 979 | + { |
|
| 980 | + $liste=$this->fetch_array($resql); |
|
| 981 | + $basedir=$liste['Value']; |
|
| 982 | + $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
| 983 | + } |
|
| 984 | + return $fullpathofdump; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * Return full path of restore program |
|
| 989 | + * |
|
| 990 | + * @return string Full path of restore program |
|
| 991 | + */ |
|
| 992 | + function getPathOfRestore() |
|
| 993 | + { |
|
| 994 | + $fullpathofimport='/pathtomysql/mysql'; |
|
| 995 | + |
|
| 996 | + $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
| 997 | + if ($resql) |
|
| 998 | + { |
|
| 999 | + $liste=$this->fetch_array($resql); |
|
| 1000 | + $basedir=$liste['Value']; |
|
| 1001 | + $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
| 1002 | + } |
|
| 1003 | + return $fullpathofimport; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * Return value of server parameters |
|
| 1008 | + * |
|
| 1009 | + * @param string $filter Filter list on a particular value |
|
| 1010 | 1010 | * @return array Array of key-values (key=>value) |
| 1011 | - */ |
|
| 1012 | - function getServerParametersValues($filter='') |
|
| 1013 | - { |
|
| 1014 | - $result=array(); |
|
| 1015 | - |
|
| 1016 | - $sql='SHOW VARIABLES'; |
|
| 1017 | - if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
| 1018 | - $resql=$this->query($sql); |
|
| 1019 | - if ($resql) |
|
| 1020 | - { |
|
| 1021 | - while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - return $result; |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - /** |
|
| 1028 | - * Return value of server status (current indicators on memory, cache...) |
|
| 1029 | - * |
|
| 1030 | - * @param string $filter Filter list on a particular value |
|
| 1011 | + */ |
|
| 1012 | + function getServerParametersValues($filter='') |
|
| 1013 | + { |
|
| 1014 | + $result=array(); |
|
| 1015 | + |
|
| 1016 | + $sql='SHOW VARIABLES'; |
|
| 1017 | + if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
| 1018 | + $resql=$this->query($sql); |
|
| 1019 | + if ($resql) |
|
| 1020 | + { |
|
| 1021 | + while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + return $result; |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + /** |
|
| 1028 | + * Return value of server status (current indicators on memory, cache...) |
|
| 1029 | + * |
|
| 1030 | + * @param string $filter Filter list on a particular value |
|
| 1031 | 1031 | * @return array Array of key-values (key=>value) |
| 1032 | - */ |
|
| 1033 | - function getServerStatusValues($filter='') |
|
| 1034 | - { |
|
| 1035 | - $result=array(); |
|
| 1036 | - |
|
| 1037 | - $sql='SHOW STATUS'; |
|
| 1038 | - if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
| 1039 | - $resql=$this->query($sql); |
|
| 1040 | - if ($resql) |
|
| 1041 | - { |
|
| 1042 | - while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - return $result; |
|
| 1046 | - } |
|
| 1032 | + */ |
|
| 1033 | + function getServerStatusValues($filter='') |
|
| 1034 | + { |
|
| 1035 | + $result=array(); |
|
| 1036 | + |
|
| 1037 | + $sql='SHOW STATUS'; |
|
| 1038 | + if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
| 1039 | + $resql=$this->query($sql); |
|
| 1040 | + if ($resql) |
|
| 1041 | + { |
|
| 1042 | + while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + return $result; |
|
| 1046 | + } |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
@@ -59,8 +59,12 @@ discard block |
||
| 59 | 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)) { |
|
| 63 | + $this->forcecharset=$conf->db->character_set; |
|
| 64 | + } |
|
| 65 | + if (! empty($conf->db->dolibarr_main_db_collation)) { |
|
| 66 | + $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
|
| 67 | + } |
|
| 64 | 68 | |
| 65 | 69 | $this->database_user=$user; |
| 66 | 70 | $this->database_host=$host; |
@@ -111,13 +115,16 @@ discard block |
||
| 111 | 115 | |
| 112 | 116 | // If client connected with different charset than Dolibarr HTML output |
| 113 | 117 | $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'; |
|
| 118 | + if (preg_match('/UTF-8/i',$conf->file->character_set_client)) { |
|
| 119 | + $clientmustbe='utf8'; |
|
| 120 | + } |
|
| 121 | + if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) { |
|
| 122 | + $clientmustbe='latin1'; |
|
| 123 | + } |
|
| 116 | 124 | if ($this->db->character_set_name() != $clientmustbe) { |
| 117 | 125 | $this->db->set_charset($clientmustbe); |
| 118 | 126 | } |
| 119 | - } |
|
| 120 | - else |
|
| 127 | + } else |
|
| 121 | 128 | { |
| 122 | 129 | $this->database_selected = false; |
| 123 | 130 | $this->database_name = ''; |
@@ -125,8 +132,7 @@ discard block |
||
| 125 | 132 | $this->error=$this->error(); |
| 126 | 133 | dol_syslog(get_class($this)."::DoliDBMysqli : Select_db error ".$this->error,LOG_ERR); |
| 127 | 134 | } |
| 128 | - } |
|
| 129 | - else |
|
| 135 | + } else |
|
| 130 | 136 | { |
| 131 | 137 | // Pas de selection de base demandee, ok ou ko |
| 132 | 138 | $this->database_selected = false; |
@@ -135,8 +141,12 @@ discard block |
||
| 135 | 141 | { |
| 136 | 142 | // If client connected with different charset than Dolibarr HTML output |
| 137 | 143 | $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'; |
|
| 144 | + if (preg_match('/UTF-8/i',$conf->file->character_set_client)) { |
|
| 145 | + $clientmustbe='utf8'; |
|
| 146 | + } |
|
| 147 | + if (preg_match('/ISO-8859-1/i',$conf->file->character_set_client)) { |
|
| 148 | + $clientmustbe='latin1'; |
|
| 149 | + } |
|
| 140 | 150 | if ($this->db->character_set_name() != $clientmustbe) { |
| 141 | 151 | $this->db->set_charset($clientmustbe); |
| 142 | 152 | } |
@@ -219,7 +229,9 @@ discard block |
||
| 219 | 229 | { |
| 220 | 230 | if ($this->db) |
| 221 | 231 | { |
| 222 | - if ($this->transaction_opened > 0) dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
| 232 | + if ($this->transaction_opened > 0) { |
|
| 233 | + dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
| 234 | + } |
|
| 223 | 235 | $this->connected=false; |
| 224 | 236 | return $this->db->close(); |
| 225 | 237 | } |
@@ -241,14 +253,15 @@ discard block |
||
| 241 | 253 | |
| 242 | 254 | $query = trim($query); |
| 243 | 255 | |
| 244 | - if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
| 256 | + if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) { |
|
| 257 | + dol_syslog('sql='.$query, LOG_DEBUG); |
|
| 258 | + } |
|
| 245 | 259 | |
| 246 | 260 | if (! $this->database_name) |
| 247 | 261 | { |
| 248 | 262 | // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
| 249 | 263 | $ret = $this->db->query($query); |
| 250 | - } |
|
| 251 | - else |
|
| 264 | + } else |
|
| 252 | 265 | { |
| 253 | 266 | $ret = $this->db->query($query); |
| 254 | 267 | } |
@@ -262,7 +275,10 @@ discard block |
||
| 262 | 275 | $this->lasterror = $this->error(); |
| 263 | 276 | $this->lasterrno = $this->errno(); |
| 264 | 277 | |
| 265 | - 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 |
|
| 278 | + if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) { |
|
| 279 | + dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); |
|
| 280 | + } |
|
| 281 | + // Log of request was not yet done previously |
|
| 266 | 282 | dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterrno." ".$this->lasterror, LOG_ERR); |
| 267 | 283 | } |
| 268 | 284 | $this->lastquery=$query; |
@@ -312,8 +328,7 @@ discard block |
||
| 312 | 328 | { |
| 313 | 329 | if (! is_object($resultset)) { $resultset=$this->_results; } |
| 314 | 330 | return $resultset->fetch_row(); |
| 315 | - } |
|
| 316 | - else |
|
| 331 | + } else |
|
| 317 | 332 | { |
| 318 | 333 | // si le curseur est un booleen on retourne la valeur 0 |
| 319 | 334 | return 0; |
@@ -362,7 +377,9 @@ discard block |
||
| 362 | 377 | // If resultset not provided, we take the last used by connexion |
| 363 | 378 | if (! is_object($resultset)) { $resultset=$this->_results; } |
| 364 | 379 | // Si resultset en est un, on libere la memoire |
| 365 | - if (is_object($resultset)) $resultset->free_result(); |
|
| 380 | + if (is_object($resultset)) { |
|
| 381 | + $resultset->free_result(); |
|
| 382 | + } |
|
| 366 | 383 | } |
| 367 | 384 | |
| 368 | 385 | /** |
@@ -437,8 +454,7 @@ discard block |
||
| 437 | 454 | if (! $this->connected) { |
| 438 | 455 | // Si il y a eu echec de connexion, $this->db n'est pas valide pour mysqli_error. |
| 439 | 456 | return 'Not connected. Check setup parameters in conf/conf.php file and your mysql client and server versions'; |
| 440 | - } |
|
| 441 | - else { |
|
| 457 | + } else { |
|
| 442 | 458 | return $this->db->error; |
| 443 | 459 | } |
| 444 | 460 | } |
@@ -481,8 +497,7 @@ discard block |
||
| 481 | 497 | if ($cryptType == 2) |
| 482 | 498 | { |
| 483 | 499 | $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
| 484 | - } |
|
| 485 | - else if ($cryptType == 1) |
|
| 500 | + } else if ($cryptType == 1) |
|
| 486 | 501 | { |
| 487 | 502 | $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
| 488 | 503 | } |
@@ -514,8 +529,7 @@ discard block |
||
| 514 | 529 | if ($cryptType == 2) |
| 515 | 530 | { |
| 516 | 531 | $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
| 517 | - } |
|
| 518 | - else if ($cryptType == 1) |
|
| 532 | + } else if ($cryptType == 1) |
|
| 519 | 533 | { |
| 520 | 534 | $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
| 521 | 535 | } |
@@ -537,8 +551,9 @@ discard block |
||
| 537 | 551 | { |
| 538 | 552 | $row=$this->fetch_row($resql); |
| 539 | 553 | return $row[0]; |
| 554 | + } else { |
|
| 555 | + return '?'; |
|
| 540 | 556 | } |
| 541 | - else return '?'; |
|
| 542 | 557 | } |
| 543 | 558 | |
| 544 | 559 | /** |
@@ -554,8 +569,12 @@ discard block |
||
| 554 | 569 | */ |
| 555 | 570 | function DDLCreateDb($database,$charset='',$collation='',$owner='') |
| 556 | 571 | { |
| 557 | - if (empty($charset)) $charset=$this->forcecharset; |
|
| 558 | - if (empty($collation)) $collation=$this->forcecollate; |
|
| 572 | + if (empty($charset)) { |
|
| 573 | + $charset=$this->forcecharset; |
|
| 574 | + } |
|
| 575 | + if (empty($collation)) { |
|
| 576 | + $collation=$this->forcecollate; |
|
| 577 | + } |
|
| 559 | 578 | |
| 560 | 579 | // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
| 561 | 580 | $sql = "CREATE DATABASE `".$this->escape($database)."`"; |
@@ -585,7 +604,9 @@ discard block |
||
| 585 | 604 | $listtables=array(); |
| 586 | 605 | |
| 587 | 606 | $like = ''; |
| 588 | - if ($table) $like = "LIKE '".$table."'"; |
|
| 607 | + if ($table) { |
|
| 608 | + $like = "LIKE '".$table."'"; |
|
| 609 | + } |
|
| 589 | 610 | $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
| 590 | 611 | //print $sql; |
| 591 | 612 | $result = $this->query($sql); |
@@ -657,8 +678,7 @@ discard block |
||
| 657 | 678 | { |
| 658 | 679 | if ((preg_match("/null/i",$field_desc['default'])) || (preg_match("/CURRENT_TIMESTAMP/i",$field_desc['default']))) { |
| 659 | 680 | $sqlfields[$i] .= " default ".$field_desc['default']; |
| 660 | - } |
|
| 661 | - else { |
|
| 681 | + } else { |
|
| 662 | 682 | $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
| 663 | 683 | } |
| 664 | 684 | } |
@@ -670,8 +690,9 @@ discard block |
||
| 670 | 690 | } |
| 671 | 691 | $i++; |
| 672 | 692 | } |
| 673 | - if($primary_key != "") |
|
| 674 | - $pk = "primary key(".$primary_key.")"; |
|
| 693 | + if($primary_key != "") { |
|
| 694 | + $pk = "primary key(".$primary_key.")"; |
|
| 695 | + } |
|
| 675 | 696 | |
| 676 | 697 | if(is_array($unique_keys)) { |
| 677 | 698 | $i = 0; |
@@ -691,19 +712,23 @@ discard block |
||
| 691 | 712 | } |
| 692 | 713 | } |
| 693 | 714 | $sql .= implode(',',$sqlfields); |
| 694 | - if($primary_key != "") |
|
| 695 | - $sql .= ",".$pk; |
|
| 696 | - if($unique_keys != "") |
|
| 697 | - $sql .= ",".implode(',',$sqluq); |
|
| 698 | - if(is_array($keys)) |
|
| 699 | - $sql .= ",".implode(',',$sqlk); |
|
| 715 | + if($primary_key != "") { |
|
| 716 | + $sql .= ",".$pk; |
|
| 717 | + } |
|
| 718 | + if($unique_keys != "") { |
|
| 719 | + $sql .= ",".implode(',',$sqluq); |
|
| 720 | + } |
|
| 721 | + if(is_array($keys)) { |
|
| 722 | + $sql .= ",".implode(',',$sqlk); |
|
| 723 | + } |
|
| 700 | 724 | $sql .=") engine=".$type; |
| 701 | 725 | |
| 702 | 726 | dol_syslog($sql,LOG_DEBUG); |
| 703 | - if(! $this -> query($sql)) |
|
| 704 | - return -1; |
|
| 705 | - else |
|
| 706 | - return 1; |
|
| 727 | + if(! $this -> query($sql)) { |
|
| 728 | + return -1; |
|
| 729 | + } else { |
|
| 730 | + return 1; |
|
| 731 | + } |
|
| 707 | 732 | } |
| 708 | 733 | |
| 709 | 734 | /** |
@@ -737,24 +762,29 @@ discard block |
||
| 737 | 762 | // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
| 738 | 763 | $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
| 739 | 764 | $sql.= $field_desc['type']; |
| 740 | - if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 741 | - if (! in_array($field_desc['type'],array('date','datetime'))) |
|
| 765 | + if(preg_match("/^[^\s]/i",$field_desc['value'])) { |
|
| 766 | + if (! in_array($field_desc['type'],array('date','datetime'))) |
|
| 742 | 767 | { |
| 743 | 768 | $sql.= "(".$field_desc['value'].")"; |
| 769 | + } |
|
| 744 | 770 | } |
| 745 | - if(preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 746 | - $sql.= " ".$field_desc['attribute']; |
|
| 747 | - if(preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 748 | - $sql.= " ".$field_desc['null']; |
|
| 771 | + if(preg_match("/^[^\s]/i",$field_desc['attribute'])) { |
|
| 772 | + $sql.= " ".$field_desc['attribute']; |
|
| 773 | + } |
|
| 774 | + if(preg_match("/^[^\s]/i",$field_desc['null'])) { |
|
| 775 | + $sql.= " ".$field_desc['null']; |
|
| 776 | + } |
|
| 749 | 777 | if(preg_match("/^[^\s]/i",$field_desc['default'])) |
| 750 | 778 | { |
| 751 | - if(preg_match("/null/i",$field_desc['default'])) |
|
| 752 | - $sql.= " default ".$field_desc['default']; |
|
| 753 | - else |
|
| 754 | - $sql.= " default '".$field_desc['default']."'"; |
|
| 779 | + if(preg_match("/null/i",$field_desc['default'])) { |
|
| 780 | + $sql.= " default ".$field_desc['default']; |
|
| 781 | + } else { |
|
| 782 | + $sql.= " default '".$field_desc['default']."'"; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + if(preg_match("/^[^\s]/i",$field_desc['extra'])) { |
|
| 786 | + $sql.= " ".$field_desc['extra']; |
|
| 755 | 787 | } |
| 756 | - if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 757 | - $sql.= " ".$field_desc['extra']; |
|
| 758 | 788 | $sql.= " ".$field_position; |
| 759 | 789 | |
| 760 | 790 | dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
@@ -786,8 +816,7 @@ discard block |
||
| 786 | 816 | { |
| 787 | 817 | $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
| 788 | 818 | $this->query($sqlbis); |
| 789 | - } |
|
| 790 | - elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
| 819 | + } elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
| 791 | 820 | { |
| 792 | 821 | $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
| 793 | 822 | $this->query($sqlbis); |
@@ -798,15 +827,20 @@ discard block |
||
| 798 | 827 | |
| 799 | 828 | if ($field_desc['default'] != '') |
| 800 | 829 | { |
| 801 | - if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') $sql.=" DEFAULT ".$this->escape($field_desc['default']); |
|
| 802 | - elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
| 830 | + if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') { |
|
| 831 | + $sql.=" DEFAULT ".$this->escape($field_desc['default']); |
|
| 832 | + } elseif ($field_desc['type'] == 'text') { |
|
| 833 | + $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; |
|
| 834 | + } |
|
| 835 | + // Default not supported on text fields |
|
| 803 | 836 | } |
| 804 | 837 | |
| 805 | 838 | dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
| 806 | - if (! $this->query($sql)) |
|
| 807 | - return -1; |
|
| 808 | - else |
|
| 809 | - return 1; |
|
| 839 | + if (! $this->query($sql)) { |
|
| 840 | + return -1; |
|
| 841 | + } else { |
|
| 842 | + return 1; |
|
| 843 | + } |
|
| 810 | 844 | } |
| 811 | 845 | |
| 812 | 846 | /** |
@@ -847,8 +881,7 @@ discard block |
||
| 847 | 881 | if ($this->lasterrno != 'DB_ERROR_USER_ALREADY_EXISTS') |
| 848 | 882 | { |
| 849 | 883 | return -1; |
| 850 | - } |
|
| 851 | - else |
|
| 884 | + } else |
|
| 852 | 885 | { |
| 853 | 886 | // If user already exists, we continue to set permissions |
| 854 | 887 | dol_syslog(get_class($this)."::DDLCreateUser sql=".$sql, LOG_WARNING); |
@@ -1014,11 +1047,15 @@ discard block |
||
| 1014 | 1047 | $result=array(); |
| 1015 | 1048 | |
| 1016 | 1049 | $sql='SHOW VARIABLES'; |
| 1017 | - if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
| 1050 | + if ($filter) { |
|
| 1051 | + $sql.=" LIKE '".$this->escape($filter)."'"; |
|
| 1052 | + } |
|
| 1018 | 1053 | $resql=$this->query($sql); |
| 1019 | 1054 | if ($resql) |
| 1020 | 1055 | { |
| 1021 | - while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
| 1056 | + while($obj=$this->fetch_object($resql)) { |
|
| 1057 | + $result[$obj->Variable_name]=$obj->Value; |
|
| 1058 | + } |
|
| 1022 | 1059 | } |
| 1023 | 1060 | |
| 1024 | 1061 | return $result; |
@@ -1035,11 +1072,15 @@ discard block |
||
| 1035 | 1072 | $result=array(); |
| 1036 | 1073 | |
| 1037 | 1074 | $sql='SHOW STATUS'; |
| 1038 | - if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
|
| 1075 | + if ($filter) { |
|
| 1076 | + $sql.=" LIKE '".$this->escape($filter)."'"; |
|
| 1077 | + } |
|
| 1039 | 1078 | $resql=$this->query($sql); |
| 1040 | 1079 | if ($resql) |
| 1041 | 1080 | { |
| 1042 | - while($obj=$this->fetch_object($resql)) $result[$obj->Variable_name]=$obj->Value; |
|
| 1081 | + while($obj=$this->fetch_object($resql)) { |
|
| 1082 | + $result[$obj->Variable_name]=$obj->Value; |
|
| 1083 | + } |
|
| 1043 | 1084 | } |
| 1044 | 1085 | |
| 1045 | 1086 | return $result; |
@@ -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 | { |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | class DoliDBPgsql extends DoliDB |
| 37 | 37 | { |
| 38 | - //! Database type |
|
| 38 | + //! Database type |
|
| 39 | 39 | public $type='pgsql'; // Name of manager |
| 40 | - //! Database label |
|
| 40 | + //! Database label |
|
| 41 | 41 | const LABEL='PostgreSQL'; // Label of manager |
| 42 | 42 | //! Charset |
| 43 | 43 | var $forcecharset='UTF8'; // Can't be static as it may be forced with a dynamic value |
| 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 |
|
| 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 |
|
| 46 | 46 | //! Version min database |
| 47 | 47 | const VERSIONMIN='9.0.0'; // Version min database |
| 48 | 48 | /** @var resource Resultset of last query */ |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | global $conf,$langs; |
| 68 | 68 | |
| 69 | - // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
|
| 69 | + // Note that having "static" property for "$forcecharset" and "$forcecollate" will make error here in strict mode, so they are not static |
|
| 70 | 70 | if (! empty($conf->db->character_set)) $this->forcecharset=$conf->db->character_set; |
| 71 | 71 | if (! empty($conf->db->dolibarr_main_db_collation)) $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
| 72 | 72 | |
| 73 | 73 | $this->database_user=$user; |
| 74 | - $this->database_host=$host; |
|
| 75 | - $this->database_port=$port; |
|
| 74 | + $this->database_host=$host; |
|
| 75 | + $this->database_port=$port; |
|
| 76 | 76 | |
| 77 | 77 | $this->transaction_opened=0; |
| 78 | 78 | |
@@ -142,14 +142,14 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Convert a SQL request in Mysql syntax to native syntax |
|
| 147 | - * |
|
| 148 | - * @param string $line SQL request line to convert |
|
| 149 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 150 | - * @param bool $unescapeslashquot Unescape slash quote with quote quote |
|
| 151 | - * @return string SQL request line converted |
|
| 152 | - */ |
|
| 145 | + /** |
|
| 146 | + * Convert a SQL request in Mysql syntax to native syntax |
|
| 147 | + * |
|
| 148 | + * @param string $line SQL request line to convert |
|
| 149 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 150 | + * @param bool $unescapeslashquot Unescape slash quote with quote quote |
|
| 151 | + * @return string SQL request line converted |
|
| 152 | + */ |
|
| 153 | 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 |
@@ -165,149 +165,149 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | // group_concat support (PgSQL >= 9.0) |
| 167 | 167 | // Replace group_concat(x) or group_concat(x SEPARATOR ',') with string_agg(x, ',') |
| 168 | - $line = preg_replace('/GROUP_CONCAT/i', 'STRING_AGG', $line); |
|
| 168 | + $line = preg_replace('/GROUP_CONCAT/i', 'STRING_AGG', $line); |
|
| 169 | 169 | $line = preg_replace('/ SEPARATOR/i', ',', $line); |
| 170 | 170 | $line = preg_replace('/STRING_AGG\(([^,\)]+)\)/i', 'STRING_AGG(\\1, \',\')', $line); |
| 171 | 171 | //print $line."\n"; |
| 172 | 172 | |
| 173 | - if ($type == 'auto') |
|
| 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'; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - $line=preg_replace('/ as signed\)/i',' as integer)',$line); |
|
| 181 | - |
|
| 182 | - if ($type == 'dml') |
|
| 183 | - { |
|
| 184 | - $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
| 185 | - |
|
| 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); |
|
| 191 | - } |
|
| 192 | - |
|
| 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); |
|
| 196 | - //$line = "-- ".$line." replaced by --\n".$newline; |
|
| 197 | - $line=$newline; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // tinyint type conversion |
|
| 201 | - $line=preg_replace('/tinyint\(?[0-9]*\)?/','smallint',$line); |
|
| 202 | - $line=preg_replace('/tinyint/i','smallint',$line); |
|
| 203 | - |
|
| 204 | - // nuke unsigned |
|
| 205 | - $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
| 206 | - |
|
| 207 | - // blob -> text |
|
| 208 | - $line=preg_replace('/\w*blob/i','text',$line); |
|
| 209 | - |
|
| 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); |
|
| 214 | - |
|
| 215 | - $line=preg_replace('/text\([0-9]+\)/i','text',$line); |
|
| 216 | - |
|
| 217 | - // change not null datetime field to null valid ones |
|
| 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); |
|
| 221 | - |
|
| 222 | - // double -> numeric |
|
| 223 | - $line=preg_replace('/^double/i','numeric',$line); |
|
| 224 | - $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
| 225 | - // float -> numeric |
|
| 226 | - $line=preg_replace('/^float/i','numeric',$line); |
|
| 227 | - $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
| 228 | - |
|
| 229 | - //Check tms timestamp field case (in Mysql this field is defautled to now and |
|
| 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); |
|
| 232 | - |
|
| 233 | - // nuke ON UPDATE CURRENT_TIMESTAMP |
|
| 234 | - $line=preg_replace('/(\s*)on(\s*)update(\s*)CURRENT_TIMESTAMP/i','\\1',$line); |
|
| 235 | - |
|
| 236 | - // unique index(field1,field2) |
|
| 237 | - if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
| 238 | - { |
|
| 239 | - $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // We remove end of requests "AFTER fieldxxx" |
|
| 243 | - $line=preg_replace('/\sAFTER [a-z0-9_]+/i','',$line); |
|
| 244 | - |
|
| 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); |
|
| 247 | - |
|
| 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)) |
|
| 250 | - { |
|
| 251 | - $line = "-- ".$line." replaced by --\n"; |
|
| 252 | - $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
| 253 | - } |
|
| 254 | - |
|
| 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)) |
|
| 257 | - { |
|
| 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; |
|
| 266 | - // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // alter table add primary key (field1, field2 ...) -> We remove the primary key name not accepted by PostGreSQL |
|
| 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)) |
|
| 272 | - { |
|
| 273 | - $line = "-- ".$line." replaced by --\n"; |
|
| 274 | - $line.= "ALTER TABLE ".$reg[1]." ADD PRIMARY KEY (".$reg[3]; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // Translate order to drop foreign keys |
|
| 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)) |
|
| 280 | - { |
|
| 281 | - $line = "-- ".$line." replaced by --\n"; |
|
| 282 | - $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - // Translate order to add foreign keys |
|
| 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)) |
|
| 288 | - { |
|
| 289 | - $line=preg_replace('/;$/','',$line); |
|
| 290 | - $line.=" DEFERRABLE INITIALLY IMMEDIATE;"; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // alter table add [unique] [index] (field1, field2 ...) |
|
| 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)) |
|
| 296 | - { |
|
| 297 | - $fieldlist=$reg[4]; |
|
| 298 | - $idxname=$reg[3]; |
|
| 299 | - $tablename=$reg[1]; |
|
| 300 | - $line = "-- ".$line." replaced by --\n"; |
|
| 301 | - $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - // To have postgresql case sensitive |
|
| 306 | - $line=str_replace(' LIKE \'',' ILIKE \'',$line); |
|
| 307 | - $line=str_replace(' LIKE BINARY \'',' LIKE \'',$line); |
|
| 308 | - |
|
| 309 | - // Replace INSERT IGNORE into INSERT |
|
| 310 | - $line=preg_replace('/^INSERT IGNORE/','INSERT',$line); |
|
| 173 | + if ($type == 'auto') |
|
| 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'; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + $line=preg_replace('/ as signed\)/i',' as integer)',$line); |
|
| 181 | + |
|
| 182 | + if ($type == 'dml') |
|
| 183 | + { |
|
| 184 | + $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
| 185 | + |
|
| 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); |
|
| 191 | + } |
|
| 192 | + |
|
| 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); |
|
| 196 | + //$line = "-- ".$line." replaced by --\n".$newline; |
|
| 197 | + $line=$newline; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // tinyint type conversion |
|
| 201 | + $line=preg_replace('/tinyint\(?[0-9]*\)?/','smallint',$line); |
|
| 202 | + $line=preg_replace('/tinyint/i','smallint',$line); |
|
| 203 | + |
|
| 204 | + // nuke unsigned |
|
| 205 | + $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
| 206 | + |
|
| 207 | + // blob -> text |
|
| 208 | + $line=preg_replace('/\w*blob/i','text',$line); |
|
| 209 | + |
|
| 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); |
|
| 214 | + |
|
| 215 | + $line=preg_replace('/text\([0-9]+\)/i','text',$line); |
|
| 216 | + |
|
| 217 | + // change not null datetime field to null valid ones |
|
| 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); |
|
| 221 | + |
|
| 222 | + // double -> numeric |
|
| 223 | + $line=preg_replace('/^double/i','numeric',$line); |
|
| 224 | + $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
| 225 | + // float -> numeric |
|
| 226 | + $line=preg_replace('/^float/i','numeric',$line); |
|
| 227 | + $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
| 228 | + |
|
| 229 | + //Check tms timestamp field case (in Mysql this field is defautled to now and |
|
| 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); |
|
| 232 | + |
|
| 233 | + // nuke ON UPDATE CURRENT_TIMESTAMP |
|
| 234 | + $line=preg_replace('/(\s*)on(\s*)update(\s*)CURRENT_TIMESTAMP/i','\\1',$line); |
|
| 235 | + |
|
| 236 | + // unique index(field1,field2) |
|
| 237 | + if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
| 238 | + { |
|
| 239 | + $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // We remove end of requests "AFTER fieldxxx" |
|
| 243 | + $line=preg_replace('/\sAFTER [a-z0-9_]+/i','',$line); |
|
| 244 | + |
|
| 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); |
|
| 247 | + |
|
| 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)) |
|
| 250 | + { |
|
| 251 | + $line = "-- ".$line." replaced by --\n"; |
|
| 252 | + $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
| 253 | + } |
|
| 254 | + |
|
| 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)) |
|
| 257 | + { |
|
| 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; |
|
| 266 | + // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // alter table add primary key (field1, field2 ...) -> We remove the primary key name not accepted by PostGreSQL |
|
| 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)) |
|
| 272 | + { |
|
| 273 | + $line = "-- ".$line." replaced by --\n"; |
|
| 274 | + $line.= "ALTER TABLE ".$reg[1]." ADD PRIMARY KEY (".$reg[3]; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // Translate order to drop foreign keys |
|
| 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)) |
|
| 280 | + { |
|
| 281 | + $line = "-- ".$line." replaced by --\n"; |
|
| 282 | + $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + // Translate order to add foreign keys |
|
| 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)) |
|
| 288 | + { |
|
| 289 | + $line=preg_replace('/;$/','',$line); |
|
| 290 | + $line.=" DEFERRABLE INITIALLY IMMEDIATE;"; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // alter table add [unique] [index] (field1, field2 ...) |
|
| 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)) |
|
| 296 | + { |
|
| 297 | + $fieldlist=$reg[4]; |
|
| 298 | + $idxname=$reg[3]; |
|
| 299 | + $tablename=$reg[1]; |
|
| 300 | + $line = "-- ".$line." replaced by --\n"; |
|
| 301 | + $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + // To have postgresql case sensitive |
|
| 306 | + $line=str_replace(' LIKE \'',' ILIKE \'',$line); |
|
| 307 | + $line=str_replace(' LIKE BINARY \'',' LIKE \'',$line); |
|
| 308 | + |
|
| 309 | + // Replace INSERT IGNORE into INSERT |
|
| 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 |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | /** |
| 355 | 355 | * Select a database |
| 356 | - * Ici postgresql n'a aucune fonction equivalente de mysql_select_db |
|
| 357 | - * On compare juste manuellement si la database choisie est bien celle activee par la connexion |
|
| 356 | + * Ici postgresql n'a aucune fonction equivalente de mysql_select_db |
|
| 357 | + * On compare juste manuellement si la database choisie est bien celle activee par la connexion |
|
| 358 | 358 | * |
| 359 | 359 | * @param string $database Name of database |
| 360 | 360 | * @return bool true if OK, false if KO |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | // if local connection failed or not requested, use TCP/IP |
| 402 | 402 | if (! $this->db) |
| 403 | 403 | { |
| 404 | - if (! $host) $host = "localhost"; |
|
| 404 | + if (! $host) $host = "localhost"; |
|
| 405 | 405 | if (! $port) $port = 5432; |
| 406 | 406 | |
| 407 | 407 | $con_string = "host='".$host."' port='".$port."' dbname='".$name."' user='".$login."' password='".$passwd."'"; |
@@ -445,29 +445,29 @@ discard block |
||
| 445 | 445 | return 'pgsql php driver'; |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | - /** |
|
| 449 | - * Close database connexion |
|
| 450 | - * |
|
| 451 | - * @return boolean True if disconnect successfull, false otherwise |
|
| 452 | - * @see connect |
|
| 453 | - */ |
|
| 454 | - function close() |
|
| 455 | - { |
|
| 456 | - if ($this->db) |
|
| 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; |
|
| 460 | - return pg_close($this->db); |
|
| 461 | - } |
|
| 462 | - return false; |
|
| 463 | - } |
|
| 448 | + /** |
|
| 449 | + * Close database connexion |
|
| 450 | + * |
|
| 451 | + * @return boolean True if disconnect successfull, false otherwise |
|
| 452 | + * @see connect |
|
| 453 | + */ |
|
| 454 | + function close() |
|
| 455 | + { |
|
| 456 | + if ($this->db) |
|
| 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; |
|
| 460 | + return pg_close($this->db); |
|
| 461 | + } |
|
| 462 | + return false; |
|
| 463 | + } |
|
| 464 | 464 | |
| 465 | 465 | /** |
| 466 | 466 | * Convert request to PostgreSQL syntax, execute it and return the resultset |
| 467 | 467 | * |
| 468 | 468 | * @param string $query SQL query string |
| 469 | 469 | * @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). |
| 470 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 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 | 473 | function query($query,$usesavepoint=0,$type='auto') |
@@ -509,16 +509,16 @@ discard block |
||
| 509 | 509 | { |
| 510 | 510 | if (! $ret) |
| 511 | 511 | { |
| 512 | - if ($this->errno() != 'DB_ERROR_25P02') // Do not overwrite errors if this is a consecutive error |
|
| 513 | - { |
|
| 514 | - $this->lastqueryerror = $query; |
|
| 515 | - $this->lasterror = $this->error(); |
|
| 516 | - $this->lasterrno = $this->errno(); |
|
| 512 | + if ($this->errno() != 'DB_ERROR_25P02') // Do not overwrite errors if this is a consecutive error |
|
| 513 | + { |
|
| 514 | + $this->lastqueryerror = $query; |
|
| 515 | + $this->lasterror = $this->error(); |
|
| 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 | + } |
|
| 522 | 522 | |
| 523 | 523 | if ($usesavepoint && $this->transaction_opened) // Warning, after that errno will be erased |
| 524 | 524 | { |
@@ -540,29 +540,29 @@ discard block |
||
| 540 | 540 | */ |
| 541 | 541 | function fetch_object($resultset) |
| 542 | 542 | { |
| 543 | - // If resultset not provided, we take the last used by connexion |
|
| 543 | + // If resultset not provided, we take the last used by connexion |
|
| 544 | 544 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
| 545 | 545 | return pg_fetch_object($resultset); |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
| 549 | - * Return datas as an array |
|
| 550 | - * |
|
| 551 | - * @param resource $resultset Resultset of request |
|
| 552 | - * @return false|array Array |
|
| 549 | + * Return datas as an array |
|
| 550 | + * |
|
| 551 | + * @param resource $resultset Resultset of request |
|
| 552 | + * @return false|array Array |
|
| 553 | 553 | */ |
| 554 | 554 | function fetch_array($resultset) |
| 555 | 555 | { |
| 556 | - // If resultset not provided, we take the last used by connexion |
|
| 556 | + // If resultset not provided, we take the last used by connexion |
|
| 557 | 557 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
| 558 | 558 | return pg_fetch_array($resultset); |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
| 562 | - * Return datas as an array |
|
| 563 | - * |
|
| 564 | - * @param resource $resultset Resultset of request |
|
| 565 | - * @return false|array Array |
|
| 562 | + * Return datas as an array |
|
| 563 | + * |
|
| 564 | + * @param resource $resultset Resultset of request |
|
| 565 | + * @return false|array Array |
|
| 566 | 566 | */ |
| 567 | 567 | function fetch_row($resultset) |
| 568 | 568 | { |
@@ -572,15 +572,15 @@ discard block |
||
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
| 575 | - * Return number of lines for result of a SELECT |
|
| 576 | - * |
|
| 577 | - * @param resourse $resultset Resulset of requests |
|
| 578 | - * @return int Nb of lines, -1 on error |
|
| 579 | - * @see affected_rows |
|
| 575 | + * Return number of lines for result of a SELECT |
|
| 576 | + * |
|
| 577 | + * @param resourse $resultset Resulset of requests |
|
| 578 | + * @return int Nb of lines, -1 on error |
|
| 579 | + * @see affected_rows |
|
| 580 | 580 | */ |
| 581 | 581 | function num_rows($resultset) |
| 582 | 582 | { |
| 583 | - // If resultset not provided, we take the last used by connexion |
|
| 583 | + // If resultset not provided, we take the last used by connexion |
|
| 584 | 584 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
| 585 | 585 | return pg_num_rows($resultset); |
| 586 | 586 | } |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | */ |
| 595 | 595 | function affected_rows($resultset) |
| 596 | 596 | { |
| 597 | - // If resultset not provided, we take the last used by connexion |
|
| 597 | + // If resultset not provided, we take the last used by connexion |
|
| 598 | 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 |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | */ |
| 611 | 611 | function free($resultset=null) |
| 612 | 612 | { |
| 613 | - // If resultset not provided, we take the last used by connexion |
|
| 613 | + // If resultset not provided, we take the last used by connexion |
|
| 614 | 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); |
@@ -618,16 +618,16 @@ discard block |
||
| 618 | 618 | |
| 619 | 619 | |
| 620 | 620 | /** |
| 621 | - * Define limits and offset of request |
|
| 622 | - * |
|
| 623 | - * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) |
|
| 624 | - * @param int $offset Numero of line from where starting fetch |
|
| 625 | - * @return string String with SQL syntax to add a limit and offset |
|
| 621 | + * Define limits and offset of request |
|
| 622 | + * |
|
| 623 | + * @param int $limit Maximum number of lines returned (-1=conf->liste_limit, 0=no limit) |
|
| 624 | + * @param int $offset Numero of line from where starting fetch |
|
| 625 | + * @return string String with SQL syntax to add a limit and offset |
|
| 626 | 626 | */ |
| 627 | 627 | function plimit($limit=0,$offset=0) |
| 628 | 628 | { |
| 629 | 629 | global $conf; |
| 630 | - if (empty($limit)) return ""; |
|
| 630 | + if (empty($limit)) return ""; |
|
| 631 | 631 | if ($limit < 0) $limit=$conf->liste_limit; |
| 632 | 632 | if ($offset > 0) return " LIMIT ".$limit." OFFSET ".$offset." "; |
| 633 | 633 | else return " LIMIT $limit "; |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | return pg_escape_string($stringtoencode); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - /** |
|
| 648 | + /** |
|
| 649 | 649 | * Convert (by PHP) a GM Timestamp date into a GM string date to insert into a date field. |
| 650 | 650 | * Function to use to build INSERT, UPDATE or WHERE predica |
| 651 | 651 | * |
@@ -658,8 +658,8 @@ discard block |
||
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
| 661 | - * Format a SQL IF |
|
| 662 | - * |
|
| 661 | + * Format a SQL IF |
|
| 662 | + * |
|
| 663 | 663 | * @param string $test Test string (example: 'cd.statut=0', 'field IS NULL') |
| 664 | 664 | * @param string $resok resultat si test egal |
| 665 | 665 | * @param string $resko resultat si test non egal |
@@ -768,12 +768,12 @@ discard block |
||
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
| 771 | - * Encrypt sensitive data in database |
|
| 772 | - * Warning: This function includes the escape, so it must use direct value |
|
| 773 | - * |
|
| 774 | - * @param string $fieldorvalue Field name or value to encrypt |
|
| 775 | - * @param int $withQuotes Return string with quotes |
|
| 776 | - * @return string XXX(field) or XXX('value') or field or 'value' |
|
| 771 | + * Encrypt sensitive data in database |
|
| 772 | + * Warning: This function includes the escape, so it must use direct value |
|
| 773 | + * |
|
| 774 | + * @param string $fieldorvalue Field name or value to encrypt |
|
| 775 | + * @param int $withQuotes Return string with quotes |
|
| 776 | + * @return string XXX(field) or XXX('value') or field or 'value' |
|
| 777 | 777 | */ |
| 778 | 778 | function encrypt($fieldorvalue, $withQuotes=0) |
| 779 | 779 | { |
@@ -836,7 +836,7 @@ discard block |
||
| 836 | 836 | */ |
| 837 | 837 | function DDLCreateDb($database,$charset='',$collation='',$owner='') |
| 838 | 838 | { |
| 839 | - if (empty($charset)) $charset=$this->forcecharset; |
|
| 839 | + if (empty($charset)) $charset=$this->forcecharset; |
|
| 840 | 840 | if (empty($collation)) $collation=$this->forcecollate; |
| 841 | 841 | |
| 842 | 842 | // Test charset match LC_TYPE (pgsql error otherwise) |
@@ -862,13 +862,13 @@ discard block |
||
| 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 | - if ($result) |
|
| 866 | - { |
|
| 867 | - while($row = $this->fetch_row($result)) |
|
| 868 | - { |
|
| 869 | - $listtables[] = $row[0]; |
|
| 870 | - } |
|
| 871 | - } |
|
| 865 | + if ($result) |
|
| 866 | + { |
|
| 867 | + while($row = $this->fetch_row($result)) |
|
| 868 | + { |
|
| 869 | + $listtables[] = $row[0]; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | 872 | return $listtables; |
| 873 | 873 | } |
| 874 | 874 | |
@@ -903,12 +903,12 @@ discard block |
||
| 903 | 903 | $result = $this->query($sql); |
| 904 | 904 | if ($result) |
| 905 | 905 | { |
| 906 | - while($row = $this->fetch_row($result)) |
|
| 907 | - { |
|
| 908 | - $infotables[] = $row; |
|
| 909 | - } |
|
| 906 | + while($row = $this->fetch_row($result)) |
|
| 907 | + { |
|
| 908 | + $infotables[] = $row; |
|
| 909 | + } |
|
| 910 | 910 | } |
| 911 | - return $infotables; |
|
| 911 | + return $infotables; |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | |
@@ -1049,10 +1049,10 @@ discard block |
||
| 1049 | 1049 | $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
| 1050 | 1050 | $sql .= $field_desc['type']; |
| 1051 | 1051 | if(preg_match("/^[^\s]/i",$field_desc['value'])) |
| 1052 | - if (! in_array($field_desc['type'],array('int','date','datetime'))) |
|
| 1053 | - { |
|
| 1054 | - $sql.= "(".$field_desc['value'].")"; |
|
| 1055 | - } |
|
| 1052 | + if (! in_array($field_desc['type'],array('int','date','datetime'))) |
|
| 1053 | + { |
|
| 1054 | + $sql.= "(".$field_desc['value'].")"; |
|
| 1055 | + } |
|
| 1056 | 1056 | if (preg_match("/^[^\s]/i",$field_desc['attribute'])) |
| 1057 | 1057 | $sql .= " ".$field_desc['attribute']; |
| 1058 | 1058 | if (preg_match("/^[^\s]/i",$field_desc['null'])) |
@@ -1090,23 +1090,23 @@ discard block |
||
| 1090 | 1090 | |
| 1091 | 1091 | if ($field_desc['null'] == 'not null' || $field_desc['null'] == 'NOT NULL') |
| 1092 | 1092 | { |
| 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 | - if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
|
| 1095 | - { |
|
| 1096 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
| 1097 | - $this->query($sqlbis); |
|
| 1098 | - } |
|
| 1099 | - elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
| 1100 | - { |
|
| 1101 | - $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
| 1102 | - $this->query($sqlbis); |
|
| 1103 | - } |
|
| 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 | + if ($field_desc['type'] == 'varchar' || $field_desc['type'] == 'text') |
|
| 1095 | + { |
|
| 1096 | + $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
|
| 1097 | + $this->query($sqlbis); |
|
| 1098 | + } |
|
| 1099 | + elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
| 1100 | + { |
|
| 1101 | + $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
|
| 1102 | + $this->query($sqlbis); |
|
| 1103 | + } |
|
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | if ($field_desc['default'] != '') |
| 1107 | 1107 | { |
| 1108 | 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 |
|
| 1109 | + elseif ($field_desc['type'] == 'text') $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; // Default not supported on text fields |
|
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | dol_syslog($sql,LOG_DEBUG); |
@@ -1144,8 +1144,8 @@ discard block |
||
| 1144 | 1144 | $resql=$this->query('SHOW SERVER_ENCODING'); |
| 1145 | 1145 | if ($resql) |
| 1146 | 1146 | { |
| 1147 | - $liste=$this->fetch_array($resql); |
|
| 1148 | - return $liste['server_encoding']; |
|
| 1147 | + $liste=$this->fetch_array($resql); |
|
| 1148 | + return $liste['server_encoding']; |
|
| 1149 | 1149 | } |
| 1150 | 1150 | else return ''; |
| 1151 | 1151 | } |
@@ -1185,7 +1185,7 @@ discard block |
||
| 1185 | 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 ''; |
@@ -1226,28 +1226,28 @@ discard block |
||
| 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 | - // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
|
| 1234 | - $resql=$this->query('SHOW data_directory'); |
|
| 1235 | - if ($resql) |
|
| 1236 | - { |
|
| 1237 | - $liste=$this->fetch_array($resql); |
|
| 1238 | - $basedir=$liste['data_directory']; |
|
| 1239 | - $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/pg_dump'; |
|
| 1240 | - } |
|
| 1233 | + // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
|
| 1234 | + $resql=$this->query('SHOW data_directory'); |
|
| 1235 | + if ($resql) |
|
| 1236 | + { |
|
| 1237 | + $liste=$this->fetch_array($resql); |
|
| 1238 | + $basedir=$liste['data_directory']; |
|
| 1239 | + $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/pg_dump'; |
|
| 1240 | + } |
|
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | return $fullpathofdump; |
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | - /** |
|
| 1247 | - * Return full path of restore program |
|
| 1248 | - * |
|
| 1249 | - * @return string Full path of restore program |
|
| 1250 | - */ |
|
| 1246 | + /** |
|
| 1247 | + * Return full path of restore program |
|
| 1248 | + * |
|
| 1249 | + * @return string Full path of restore program |
|
| 1250 | + */ |
|
| 1251 | 1251 | function getPathOfRestore() |
| 1252 | 1252 | { |
| 1253 | 1253 | //$tool='pg_restore'; |
@@ -1255,21 +1255,21 @@ discard block |
||
| 1255 | 1255 | |
| 1256 | 1256 | $fullpathofdump='/pathtopgrestore/'.$tool; |
| 1257 | 1257 | |
| 1258 | - if (file_exists('/usr/bin/'.$tool)) |
|
| 1259 | - { |
|
| 1260 | - $fullpathofdump='/usr/bin/'.$tool; |
|
| 1261 | - } |
|
| 1262 | - else |
|
| 1263 | - { |
|
| 1264 | - // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
|
| 1265 | - $resql=$this->query('SHOW data_directory'); |
|
| 1266 | - if ($resql) |
|
| 1267 | - { |
|
| 1268 | - $liste=$this->fetch_array($resql); |
|
| 1269 | - $basedir=$liste['data_directory']; |
|
| 1270 | - $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/'.$tool; |
|
| 1271 | - } |
|
| 1272 | - } |
|
| 1258 | + if (file_exists('/usr/bin/'.$tool)) |
|
| 1259 | + { |
|
| 1260 | + $fullpathofdump='/usr/bin/'.$tool; |
|
| 1261 | + } |
|
| 1262 | + else |
|
| 1263 | + { |
|
| 1264 | + // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
|
| 1265 | + $resql=$this->query('SHOW data_directory'); |
|
| 1266 | + if ($resql) |
|
| 1267 | + { |
|
| 1268 | + $liste=$this->fetch_array($resql); |
|
| 1269 | + $basedir=$liste['data_directory']; |
|
| 1270 | + $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/'.$tool; |
|
| 1271 | + } |
|
| 1272 | + } |
|
| 1273 | 1273 | |
| 1274 | 1274 | return $fullpathofdump; |
| 1275 | 1275 | } |
@@ -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'; |
@@ -67,8 +67,12 @@ discard block |
||
| 67 | 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)) { |
|
| 71 | + $this->forcecharset=$conf->db->character_set; |
|
| 72 | + } |
|
| 73 | + if (! empty($conf->db->dolibarr_main_db_collation)) { |
|
| 74 | + $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
|
| 75 | + } |
|
| 72 | 76 | |
| 73 | 77 | $this->database_user=$user; |
| 74 | 78 | $this->database_host=$host; |
@@ -104,8 +108,7 @@ discard block |
||
| 104 | 108 | { |
| 105 | 109 | $this->connected = true; |
| 106 | 110 | $this->ok = true; |
| 107 | - } |
|
| 108 | - else |
|
| 111 | + } else |
|
| 109 | 112 | { |
| 110 | 113 | // host, login ou password incorrect |
| 111 | 114 | $this->connected = false; |
@@ -122,8 +125,7 @@ discard block |
||
| 122 | 125 | $this->database_selected = true; |
| 123 | 126 | $this->database_name = $name; |
| 124 | 127 | $this->ok = true; |
| 125 | - } |
|
| 126 | - else |
|
| 128 | + } else |
|
| 127 | 129 | { |
| 128 | 130 | $this->database_selected = false; |
| 129 | 131 | $this->database_name = ''; |
@@ -131,8 +133,7 @@ discard block |
||
| 131 | 133 | $this->error=$this->error(); |
| 132 | 134 | dol_syslog(get_class($this)."::DoliDBPgsql : Erreur Select_db ".$this->error,LOG_ERR); |
| 133 | 135 | } |
| 134 | - } |
|
| 135 | - else |
|
| 136 | + } else |
|
| 136 | 137 | { |
| 137 | 138 | // Pas de selection de base demandee, ok ou ko |
| 138 | 139 | $this->database_selected = false; |
@@ -172,9 +173,13 @@ discard block |
||
| 172 | 173 | |
| 173 | 174 | if ($type == 'auto') |
| 174 | 175 | { |
| 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'; |
|
| 176 | + if (preg_match('/ALTER TABLE/i',$line)) { |
|
| 177 | + $type='dml'; |
|
| 178 | + } else if (preg_match('/CREATE TABLE/i',$line)) { |
|
| 179 | + $type='dml'; |
|
| 180 | + } else if (preg_match('/DROP TABLE/i',$line)) { |
|
| 181 | + $type='dml'; |
|
| 182 | + } |
|
| 178 | 183 | } |
| 179 | 184 | |
| 180 | 185 | $line=preg_replace('/ as signed\)/i',' as integer)',$line); |
@@ -313,10 +318,12 @@ discard block |
||
| 313 | 318 | // DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable |
| 314 | 319 | if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg)) |
| 315 | 320 | { |
| 316 | - if ($reg[1] == $reg[2]) // If same table, we remove second one |
|
| 321 | + if ($reg[1] == $reg[2]) { |
|
| 322 | + // If same table, we remove second one |
|
| 317 | 323 | { |
| 318 | 324 | $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line); |
| 319 | 325 | } |
| 326 | + } |
|
| 320 | 327 | } |
| 321 | 328 | |
| 322 | 329 | // Remove () in the tables in FROM if 1 table |
@@ -343,7 +350,9 @@ discard block |
||
| 343 | 350 | // By default we do not (should be already done by db->escape function if required |
| 344 | 351 | // except for sql insert in data file that are mysql escaped so we removed them to |
| 345 | 352 | // be compatible with standard_conforming_strings=on that considers \ as ordinary character). |
| 346 | - if ($unescapeslashquot) $line=preg_replace("/\\\'/","''",$line); |
|
| 353 | + if ($unescapeslashquot) { |
|
| 354 | + $line=preg_replace("/\\\'/","''",$line); |
|
| 355 | + } |
|
| 347 | 356 | |
| 348 | 357 | //print "type=".$type." newline=".$line."<br>\n"; |
| 349 | 358 | } |
@@ -361,8 +370,11 @@ discard block |
||
| 361 | 370 | */ |
| 362 | 371 | function select_db($database) |
| 363 | 372 | { |
| 364 | - if ($database == $this->database_name) return true; |
|
| 365 | - else return false; |
|
| 373 | + if ($database == $this->database_name) { |
|
| 374 | + return true; |
|
| 375 | + } else { |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 366 | 378 | } |
| 367 | 379 | |
| 368 | 380 | /** |
@@ -389,7 +401,10 @@ discard block |
||
| 389 | 401 | $name = str_replace(array("\\", "'"), array("\\\\", "\\'"), $name); |
| 390 | 402 | $port = str_replace(array("\\", "'"), array("\\\\", "\\'"), $port); |
| 391 | 403 | |
| 392 | - if (! $name) $name="postgres"; // When try to connect using admin user |
|
| 404 | + if (! $name) { |
|
| 405 | + $name="postgres"; |
|
| 406 | + } |
|
| 407 | + // When try to connect using admin user |
|
| 393 | 408 | |
| 394 | 409 | // try first Unix domain socket (local) |
| 395 | 410 | if ((! empty($host) && $host == "socket") && ! defined('NOLOCALSOCKETPGCONNECT')) |
@@ -401,8 +416,12 @@ discard block |
||
| 401 | 416 | // if local connection failed or not requested, use TCP/IP |
| 402 | 417 | if (! $this->db) |
| 403 | 418 | { |
| 404 | - if (! $host) $host = "localhost"; |
|
| 405 | - if (! $port) $port = 5432; |
|
| 419 | + if (! $host) { |
|
| 420 | + $host = "localhost"; |
|
| 421 | + } |
|
| 422 | + if (! $port) { |
|
| 423 | + $port = 5432; |
|
| 424 | + } |
|
| 406 | 425 | |
| 407 | 426 | $con_string = "host='".$host."' port='".$port."' dbname='".$name."' user='".$login."' password='".$passwd."'"; |
| 408 | 427 | $this->db = @pg_connect($con_string); |
@@ -455,7 +474,9 @@ discard block |
||
| 455 | 474 | { |
| 456 | 475 | if ($this->db) |
| 457 | 476 | { |
| 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); |
|
| 477 | + if ($this->transaction_opened > 0) { |
|
| 478 | + dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
| 479 | + } |
|
| 459 | 480 | $this->connected=false; |
| 460 | 481 | return pg_close($this->db); |
| 461 | 482 | } |
@@ -490,8 +511,9 @@ discard block |
||
| 490 | 511 | { |
| 491 | 512 | $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 | 513 | dol_syslog("Warning: Bad formed request converted into ".$query,LOG_WARNING); |
| 514 | + } else { |
|
| 515 | + $loop=false; |
|
| 493 | 516 | } |
| 494 | - else $loop=false; |
|
| 495 | 517 | } |
| 496 | 518 | } |
| 497 | 519 | |
@@ -500,30 +522,39 @@ discard block |
||
| 500 | 522 | @pg_query($this->db, 'SAVEPOINT mysavepoint'); |
| 501 | 523 | } |
| 502 | 524 | |
| 503 | - if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) dol_syslog('sql='.$query, LOG_DEBUG); |
|
| 525 | + if (! in_array($query,array('BEGIN','COMMIT','ROLLBACK'))) { |
|
| 526 | + dol_syslog('sql='.$query, LOG_DEBUG); |
|
| 527 | + } |
|
| 504 | 528 | |
| 505 | 529 | $ret = @pg_query($this->db, $query); |
| 506 | 530 | |
| 507 | 531 | //print $query; |
| 508 | - if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
| 532 | + if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) { |
|
| 533 | + // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
| 509 | 534 | { |
| 510 | 535 | if (! $ret) |
| 511 | 536 | { |
| 512 | 537 | if ($this->errno() != 'DB_ERROR_25P02') // Do not overwrite errors if this is a consecutive error |
| 513 | 538 | { |
| 514 | 539 | $this->lastqueryerror = $query; |
| 540 | + } |
|
| 515 | 541 | $this->lasterror = $this->error(); |
| 516 | 542 | $this->lasterrno = $this->errno(); |
| 517 | 543 | |
| 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 |
|
| 544 | + if ($conf->global->SYSLOG_LEVEL < LOG_DEBUG) { |
|
| 545 | + dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); |
|
| 546 | + } |
|
| 547 | + // Log of request was not yet done previously |
|
| 519 | 548 | dol_syslog(get_class($this)."::query SQL Error message: ".$this->lasterror." (".$this->lasterrno.")", LOG_ERR); |
| 520 | 549 | dol_syslog(get_class($this)."::query SQL Error usesavepoint = ".$usesavepoint, LOG_ERR); |
| 521 | 550 | } |
| 522 | 551 | |
| 523 | - if ($usesavepoint && $this->transaction_opened) // Warning, after that errno will be erased |
|
| 552 | + if ($usesavepoint && $this->transaction_opened) { |
|
| 553 | + // Warning, after that errno will be erased |
|
| 524 | 554 | { |
| 525 | 555 | @pg_query($this->db, 'ROLLBACK TO SAVEPOINT mysavepoint'); |
| 526 | 556 | } |
| 557 | + } |
|
| 527 | 558 | } |
| 528 | 559 | $this->lastquery=$query; |
| 529 | 560 | $this->_results = $ret; |
@@ -613,7 +644,9 @@ discard block |
||
| 613 | 644 | // If resultset not provided, we take the last used by connexion |
| 614 | 645 | if (! is_resource($resultset)) { $resultset=$this->_results; } |
| 615 | 646 | // Si resultset en est un, on libere la memoire |
| 616 | - if (is_resource($resultset)) pg_free_result($resultset); |
|
| 647 | + if (is_resource($resultset)) { |
|
| 648 | + pg_free_result($resultset); |
|
| 649 | + } |
|
| 617 | 650 | } |
| 618 | 651 | |
| 619 | 652 | |
@@ -627,10 +660,17 @@ discard block |
||
| 627 | 660 | function plimit($limit=0,$offset=0) |
| 628 | 661 | { |
| 629 | 662 | global $conf; |
| 630 | - if (empty($limit)) return ""; |
|
| 631 | - if ($limit < 0) $limit=$conf->liste_limit; |
|
| 632 | - if ($offset > 0) return " LIMIT ".$limit." OFFSET ".$offset." "; |
|
| 633 | - else return " LIMIT $limit "; |
|
| 663 | + if (empty($limit)) { |
|
| 664 | + return ""; |
|
| 665 | + } |
|
| 666 | + if ($limit < 0) { |
|
| 667 | + $limit=$conf->liste_limit; |
|
| 668 | + } |
|
| 669 | + if ($offset > 0) { |
|
| 670 | + return " LIMIT ".$limit." OFFSET ".$offset." "; |
|
| 671 | + } else { |
|
| 672 | + return " LIMIT $limit "; |
|
| 673 | + } |
|
| 634 | 674 | } |
| 635 | 675 | |
| 636 | 676 | |
@@ -680,8 +720,7 @@ discard block |
||
| 680 | 720 | if (! $this->connected) { |
| 681 | 721 | // Si il y a eu echec de connexion, $this->db n'est pas valide. |
| 682 | 722 | return 'DB_ERROR_FAILED_TO_CONNECT'; |
| 683 | - } |
|
| 684 | - else { |
|
| 723 | + } else { |
|
| 685 | 724 | // Constants to convert error code to a generic Dolibarr error code |
| 686 | 725 | $errorcode_map = array( |
| 687 | 726 | 1004 => 'DB_ERROR_CANNOT_CREATE', |
@@ -836,8 +875,12 @@ discard block |
||
| 836 | 875 | */ |
| 837 | 876 | function DDLCreateDb($database,$charset='',$collation='',$owner='') |
| 838 | 877 | { |
| 839 | - if (empty($charset)) $charset=$this->forcecharset; |
|
| 840 | - if (empty($collation)) $collation=$this->forcecollate; |
|
| 878 | + if (empty($charset)) { |
|
| 879 | + $charset=$this->forcecharset; |
|
| 880 | + } |
|
| 881 | + if (empty($collation)) { |
|
| 882 | + $collation=$this->forcecollate; |
|
| 883 | + } |
|
| 841 | 884 | |
| 842 | 885 | // Test charset match LC_TYPE (pgsql error otherwise) |
| 843 | 886 | //print $charset.' '.setlocale(LC_CTYPE,'0'); exit; |
@@ -860,7 +903,9 @@ discard block |
||
| 860 | 903 | $listtables=array(); |
| 861 | 904 | |
| 862 | 905 | $like = ''; |
| 863 | - if ($table) $like = " AND table_name LIKE '".$table."'"; |
|
| 906 | + if ($table) { |
|
| 907 | + $like = " AND table_name LIKE '".$table."'"; |
|
| 908 | + } |
|
| 864 | 909 | $result = pg_query($this->db, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'".$like." ORDER BY table_name"); |
| 865 | 910 | if ($result) |
| 866 | 911 | { |
@@ -936,26 +981,27 @@ discard block |
||
| 936 | 981 | { |
| 937 | 982 | $sqlfields[$i] = $field_name." "; |
| 938 | 983 | $sqlfields[$i] .= $field_desc['type']; |
| 939 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 940 | - $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
| 941 | - else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 942 | - $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
| 943 | - else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 984 | + if( preg_match("/^[^\s]/i",$field_desc['value'])) { |
|
| 985 | + $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
| 986 | + } else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) { |
|
| 987 | + $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
| 988 | + } else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 944 | 989 | { |
| 945 | - if(preg_match("/null/i",$field_desc['default'])) |
|
| 946 | - $sqlfields[$i] .= " default ".$field_desc['default']; |
|
| 947 | - else |
|
| 948 | - $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
| 990 | + if(preg_match("/null/i",$field_desc['default'])) { |
|
| 991 | + $sqlfields[$i] .= " default ".$field_desc['default']; |
|
| 992 | + } else { |
|
| 993 | + $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
| 994 | + } |
|
| 995 | + } else if( preg_match("/^[^\s]/i",$field_desc['null'])) { |
|
| 996 | + $sqlfields[$i] .= " ".$field_desc['null']; |
|
| 997 | + } else if( preg_match("/^[^\s]/i",$field_desc['extra'])) { |
|
| 998 | + $sqlfields[$i] .= " ".$field_desc['extra']; |
|
| 949 | 999 | } |
| 950 | - else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 951 | - $sqlfields[$i] .= " ".$field_desc['null']; |
|
| 952 | - |
|
| 953 | - else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 954 | - $sqlfields[$i] .= " ".$field_desc['extra']; |
|
| 955 | 1000 | $i++; |
| 956 | 1001 | } |
| 957 | - if($primary_key != "") |
|
| 958 | - $pk = "primary key(".$primary_key.")"; |
|
| 1002 | + if($primary_key != "") { |
|
| 1003 | + $pk = "primary key(".$primary_key.")"; |
|
| 1004 | + } |
|
| 959 | 1005 | |
| 960 | 1006 | if(is_array($unique_keys)) |
| 961 | 1007 | { |
@@ -976,19 +1022,23 @@ discard block |
||
| 976 | 1022 | } |
| 977 | 1023 | } |
| 978 | 1024 | $sql .= implode(',',$sqlfields); |
| 979 | - if($primary_key != "") |
|
| 980 | - $sql .= ",".$pk; |
|
| 981 | - if(is_array($unique_keys)) |
|
| 982 | - $sql .= ",".implode(',',$sqluq); |
|
| 983 | - if(is_array($keys)) |
|
| 984 | - $sql .= ",".implode(',',$sqlk); |
|
| 1025 | + if($primary_key != "") { |
|
| 1026 | + $sql .= ",".$pk; |
|
| 1027 | + } |
|
| 1028 | + if(is_array($unique_keys)) { |
|
| 1029 | + $sql .= ",".implode(',',$sqluq); |
|
| 1030 | + } |
|
| 1031 | + if(is_array($keys)) { |
|
| 1032 | + $sql .= ",".implode(',',$sqlk); |
|
| 1033 | + } |
|
| 985 | 1034 | $sql .=") type=".$type; |
| 986 | 1035 | |
| 987 | 1036 | dol_syslog($sql,LOG_DEBUG); |
| 988 | - if(! $this->query($sql)) |
|
| 989 | - return -1; |
|
| 990 | - else |
|
| 991 | - return 1; |
|
| 1037 | + if(! $this->query($sql)) { |
|
| 1038 | + return -1; |
|
| 1039 | + } else { |
|
| 1040 | + return 1; |
|
| 1041 | + } |
|
| 992 | 1042 | } |
| 993 | 1043 | |
| 994 | 1044 | /** |
@@ -1026,7 +1076,9 @@ discard block |
||
| 1026 | 1076 | { |
| 1027 | 1077 | $sql ="SELECT attname FROM pg_attribute, pg_type WHERE typname = '".$table."' AND attrelid = typrelid"; |
| 1028 | 1078 | $sql.=" AND attname NOT IN ('cmin', 'cmax', 'ctid', 'oid', 'tableoid', 'xmin', 'xmax')"; |
| 1029 | - if ($field) $sql.= " AND attname = '".$field."'"; |
|
| 1079 | + if ($field) { |
|
| 1080 | + $sql.= " AND attname = '".$field."'"; |
|
| 1081 | + } |
|
| 1030 | 1082 | |
| 1031 | 1083 | dol_syslog($sql,LOG_DEBUG); |
| 1032 | 1084 | $this->_results = $this->query($sql); |
@@ -1048,27 +1100,33 @@ discard block |
||
| 1048 | 1100 | // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
| 1049 | 1101 | $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
| 1050 | 1102 | $sql .= $field_desc['type']; |
| 1051 | - if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 1052 | - if (! in_array($field_desc['type'],array('int','date','datetime'))) |
|
| 1103 | + if(preg_match("/^[^\s]/i",$field_desc['value'])) { |
|
| 1104 | + if (! in_array($field_desc['type'],array('int','date','datetime'))) |
|
| 1053 | 1105 | { |
| 1054 | 1106 | $sql.= "(".$field_desc['value'].")"; |
| 1107 | + } |
|
| 1055 | 1108 | } |
| 1056 | - if (preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 1057 | - $sql .= " ".$field_desc['attribute']; |
|
| 1058 | - if (preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 1059 | - $sql .= " ".$field_desc['null']; |
|
| 1060 | - if (preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 1061 | - if (preg_match("/null/i",$field_desc['default'])) |
|
| 1109 | + if (preg_match("/^[^\s]/i",$field_desc['attribute'])) { |
|
| 1110 | + $sql .= " ".$field_desc['attribute']; |
|
| 1111 | + } |
|
| 1112 | + if (preg_match("/^[^\s]/i",$field_desc['null'])) { |
|
| 1113 | + $sql .= " ".$field_desc['null']; |
|
| 1114 | + } |
|
| 1115 | + if (preg_match("/^[^\s]/i",$field_desc['default'])) { |
|
| 1116 | + if (preg_match("/null/i",$field_desc['default'])) |
|
| 1062 | 1117 | $sql .= " default ".$field_desc['default']; |
| 1063 | - else |
|
| 1064 | - $sql .= " default '".$field_desc['default']."'"; |
|
| 1065 | - if (preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 1066 | - $sql .= " ".$field_desc['extra']; |
|
| 1118 | + } else { |
|
| 1119 | + $sql .= " default '".$field_desc['default']."'"; |
|
| 1120 | + } |
|
| 1121 | + if (preg_match("/^[^\s]/i",$field_desc['extra'])) { |
|
| 1122 | + $sql .= " ".$field_desc['extra']; |
|
| 1123 | + } |
|
| 1067 | 1124 | $sql .= " ".$field_position; |
| 1068 | 1125 | |
| 1069 | 1126 | dol_syslog($sql,LOG_DEBUG); |
| 1070 | - if(! $this -> query($sql)) |
|
| 1071 | - return -1; |
|
| 1127 | + if(! $this -> query($sql)) { |
|
| 1128 | + return -1; |
|
| 1129 | + } |
|
| 1072 | 1130 | return 1; |
| 1073 | 1131 | } |
| 1074 | 1132 | |
@@ -1095,8 +1153,7 @@ discard block |
||
| 1095 | 1153 | { |
| 1096 | 1154 | $sqlbis="UPDATE ".$table." SET ".$field_name." = '".$this->escape($field_desc['default'] ? $field_desc['default'] : '')."' WHERE ".$field_name." IS NULL"; |
| 1097 | 1155 | $this->query($sqlbis); |
| 1098 | - } |
|
| 1099 | - elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
| 1156 | + } elseif ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') |
|
| 1100 | 1157 | { |
| 1101 | 1158 | $sqlbis="UPDATE ".$table." SET ".$field_name." = ".((int) $this->escape($field_desc['default'] ? $field_desc['default'] : 0))." WHERE ".$field_name." IS NULL"; |
| 1102 | 1159 | $this->query($sqlbis); |
@@ -1105,13 +1162,18 @@ discard block |
||
| 1105 | 1162 | |
| 1106 | 1163 | if ($field_desc['default'] != '') |
| 1107 | 1164 | { |
| 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 |
|
| 1165 | + if ($field_desc['type'] == 'double' || $field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int') { |
|
| 1166 | + $sql.=" DEFAULT ".$this->escape($field_desc['default']); |
|
| 1167 | + } elseif ($field_desc['type'] == 'text') { |
|
| 1168 | + $sql.=" DEFAULT '".$this->escape($field_desc['default'])."'"; |
|
| 1169 | + } |
|
| 1170 | + // Default not supported on text fields |
|
| 1110 | 1171 | } |
| 1111 | 1172 | |
| 1112 | 1173 | dol_syslog($sql,LOG_DEBUG); |
| 1113 | - if (! $this->query($sql)) |
|
| 1114 | - return -1; |
|
| 1174 | + if (! $this->query($sql)) { |
|
| 1175 | + return -1; |
|
| 1176 | + } |
|
| 1115 | 1177 | return 1; |
| 1116 | 1178 | } |
| 1117 | 1179 | |
@@ -1146,8 +1208,9 @@ discard block |
||
| 1146 | 1208 | { |
| 1147 | 1209 | $liste=$this->fetch_array($resql); |
| 1148 | 1210 | return $liste['server_encoding']; |
| 1211 | + } else { |
|
| 1212 | + return ''; |
|
| 1149 | 1213 | } |
| 1150 | - else return ''; |
|
| 1151 | 1214 | } |
| 1152 | 1215 | |
| 1153 | 1216 | /** |
@@ -1187,8 +1250,9 @@ discard block |
||
| 1187 | 1250 | { |
| 1188 | 1251 | $liste=$this->fetch_array($resql); |
| 1189 | 1252 | return $liste['lc_collate']; |
| 1253 | + } else { |
|
| 1254 | + return ''; |
|
| 1190 | 1255 | } |
| 1191 | - else return ''; |
|
| 1192 | 1256 | } |
| 1193 | 1257 | |
| 1194 | 1258 | /** |
@@ -1227,8 +1291,7 @@ discard block |
||
| 1227 | 1291 | if (file_exists('/usr/bin/pg_dump')) |
| 1228 | 1292 | { |
| 1229 | 1293 | $fullpathofdump='/usr/bin/pg_dump'; |
| 1230 | - } |
|
| 1231 | - else |
|
| 1294 | + } else |
|
| 1232 | 1295 | { |
| 1233 | 1296 | // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
| 1234 | 1297 | $resql=$this->query('SHOW data_directory'); |
@@ -1258,8 +1321,7 @@ discard block |
||
| 1258 | 1321 | if (file_exists('/usr/bin/'.$tool)) |
| 1259 | 1322 | { |
| 1260 | 1323 | $fullpathofdump='/usr/bin/'.$tool; |
| 1261 | - } |
|
| 1262 | - else |
|
| 1324 | + } else |
|
| 1263 | 1325 | { |
| 1264 | 1326 | // TODO L'utilisateur de la base doit etre un superadmin pour lancer cette commande |
| 1265 | 1327 | $resql=$this->query('SHOW data_directory'); |
@@ -1285,11 +1347,15 @@ discard block |
||
| 1285 | 1347 | $result=array(); |
| 1286 | 1348 | |
| 1287 | 1349 | $resql='select name,setting from pg_settings'; |
| 1288 | - if ($filter) $resql.=" WHERE name = '".$this->escape($filter)."'"; |
|
| 1350 | + if ($filter) { |
|
| 1351 | + $resql.=" WHERE name = '".$this->escape($filter)."'"; |
|
| 1352 | + } |
|
| 1289 | 1353 | $resql=$this->query($resql); |
| 1290 | 1354 | if ($resql) |
| 1291 | 1355 | { |
| 1292 | - while ($obj=$this->fetch_object($resql)) $result[$obj->name]=$obj->setting; |
|
| 1356 | + while ($obj=$this->fetch_object($resql)) { |
|
| 1357 | + $result[$obj->name]=$obj->setting; |
|
| 1358 | + } |
|
| 1293 | 1359 | } |
| 1294 | 1360 | |
| 1295 | 1361 | return $result; |
@@ -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); |
@@ -32,48 +32,48 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | class DoliDBSqlite3 extends DoliDB |
| 34 | 34 | { |
| 35 | - //! Database type |
|
| 36 | - public $type='sqlite3'; |
|
| 37 | - //! Database label |
|
| 38 | - const LABEL='Sqlite3'; |
|
| 39 | - //! Version min database |
|
| 40 | - const VERSIONMIN='3.0.0'; |
|
| 35 | + //! Database type |
|
| 36 | + public $type='sqlite3'; |
|
| 37 | + //! Database label |
|
| 38 | + const LABEL='Sqlite3'; |
|
| 39 | + //! Version min database |
|
| 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; |
|
| 45 | - const WEEK_YEAR = 2; |
|
| 46 | - const WEEK_FIRST_WEEKDAY=4; |
|
| 44 | + const WEEK_MONDAY_FIRST=1; |
|
| 45 | + const WEEK_YEAR = 2; |
|
| 46 | + const WEEK_FIRST_WEEKDAY=4; |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 49 | + /** |
|
| 50 | 50 | * Constructor. |
| 51 | 51 | * This create an opened connexion to a database server and eventually to a database |
| 52 | - * |
|
| 52 | + * |
|
| 53 | 53 | * @param string $type Type of database (mysql, pgsql...) |
| 54 | 54 | * @param string $host Address of database server |
| 55 | 55 | * @param string $user Nom de l'utilisateur autorise |
| 56 | 56 | * @param string $pass Mot de passe |
| 57 | 57 | * @param string $name Nom de la database |
| 58 | 58 | * @param int $port Port of database server |
| 59 | - */ |
|
| 60 | - function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
| 61 | - { |
|
| 62 | - global $conf; |
|
| 59 | + */ |
|
| 60 | + function __construct($type, $host, $user, $pass, $name='', $port=0) |
|
| 61 | + { |
|
| 62 | + global $conf; |
|
| 63 | 63 | |
| 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; |
|
| 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; |
|
| 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 | - //print "Name DB: $host,$user,$pass,$name<br>"; |
|
| 74 | + //print "Name DB: $host,$user,$pass,$name<br>"; |
|
| 75 | 75 | |
| 76 | - /*if (! function_exists("sqlite_query")) |
|
| 76 | + /*if (! function_exists("sqlite_query")) |
|
| 77 | 77 | { |
| 78 | 78 | $this->connected = false; |
| 79 | 79 | $this->ok = false; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | return $this->ok; |
| 83 | 83 | }*/ |
| 84 | 84 | |
| 85 | - /*if (! $host) |
|
| 85 | + /*if (! $host) |
|
| 86 | 86 | { |
| 87 | 87 | $this->connected = false; |
| 88 | 88 | $this->ok = false; |
@@ -91,229 +91,229 @@ discard block |
||
| 91 | 91 | return $this->ok; |
| 92 | 92 | }*/ |
| 93 | 93 | |
| 94 | - // Essai connexion serveur |
|
| 95 | - // We do not try to connect to database, only to server. Connect to database is done later in constrcutor |
|
| 96 | - $this->db = $this->connect($host, $user, $pass, $name, $port); |
|
| 94 | + // Essai connexion serveur |
|
| 95 | + // We do not try to connect to database, only to server. Connect to database is done later in constrcutor |
|
| 96 | + $this->db = $this->connect($host, $user, $pass, $name, $port); |
|
| 97 | + |
|
| 98 | + if ($this->db) |
|
| 99 | + { |
|
| 100 | + $this->connected = true; |
|
| 101 | + $this->ok = true; |
|
| 102 | + $this->database_selected = true; |
|
| 103 | + $this->database_name = $name; |
|
| 104 | + |
|
| 105 | + $this->addCustomFunction('IF'); |
|
| 106 | + $this->addCustomFunction('MONTH'); |
|
| 107 | + $this->addCustomFunction('CURTIME'); |
|
| 108 | + $this->addCustomFunction('CURDATE'); |
|
| 109 | + $this->addCustomFunction('WEEK', 1); |
|
| 110 | + $this->addCustomFunction('WEEK', 2); |
|
| 111 | + $this->addCustomFunction('WEEKDAY'); |
|
| 112 | + $this->addCustomFunction('date_format'); |
|
| 113 | + //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 114 | + } |
|
| 115 | + else |
|
| 116 | + { |
|
| 117 | + // host, login ou password incorrect |
|
| 118 | + $this->connected = false; |
|
| 119 | + $this->ok = false; |
|
| 120 | + $this->database_selected = false; |
|
| 121 | + $this->database_name = ''; |
|
| 122 | + //$this->error=sqlite_connect_error(); |
|
| 123 | + dol_syslog(get_class($this)."::DoliDBSqlite3 : Error Connect ".$this->error,LOG_ERR); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return $this->ok; |
|
| 127 | + } |
|
| 97 | 128 | |
| 98 | - if ($this->db) |
|
| 99 | - { |
|
| 100 | - $this->connected = true; |
|
| 101 | - $this->ok = true; |
|
| 102 | - $this->database_selected = true; |
|
| 103 | - $this->database_name = $name; |
|
| 104 | - |
|
| 105 | - $this->addCustomFunction('IF'); |
|
| 106 | - $this->addCustomFunction('MONTH'); |
|
| 107 | - $this->addCustomFunction('CURTIME'); |
|
| 108 | - $this->addCustomFunction('CURDATE'); |
|
| 109 | - $this->addCustomFunction('WEEK', 1); |
|
| 110 | - $this->addCustomFunction('WEEK', 2); |
|
| 111 | - $this->addCustomFunction('WEEKDAY'); |
|
| 112 | - $this->addCustomFunction('date_format'); |
|
| 113 | - //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 114 | - } |
|
| 115 | - else |
|
| 116 | - { |
|
| 117 | - // host, login ou password incorrect |
|
| 118 | - $this->connected = false; |
|
| 119 | - $this->ok = false; |
|
| 120 | - $this->database_selected = false; |
|
| 121 | - $this->database_name = ''; |
|
| 122 | - //$this->error=sqlite_connect_error(); |
|
| 123 | - dol_syslog(get_class($this)."::DoliDBSqlite3 : Error Connect ".$this->error,LOG_ERR); |
|
| 124 | - } |
|
| 125 | 129 | |
| 126 | - return $this->ok; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Convert a SQL request in Mysql syntax to native syntax |
|
| 132 | - * |
|
| 133 | - * @param string $line SQL request line to convert |
|
| 134 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 135 | - * @return string SQL request line converted |
|
| 136 | - */ |
|
| 137 | - static function convertSQLFromMysql($line,$type='ddl') |
|
| 138 | - { |
|
| 139 | - // Removed empty line if this is a comment line for SVN tagging |
|
| 140 | - if (preg_match('/^--\s\$Id/i',$line)) { |
|
| 141 | - return ''; |
|
| 142 | - } |
|
| 143 | - // Return line if this is a comment |
|
| 144 | - if (preg_match('/^#/i',$line) || preg_match('/^$/i',$line) || preg_match('/^--/i',$line)) |
|
| 145 | - { |
|
| 146 | - return $line; |
|
| 147 | - } |
|
| 148 | - if ($line != "") |
|
| 149 | - { |
|
| 150 | - if ($type == 'auto') |
|
| 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'; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if ($type == 'dml') |
|
| 158 | - { |
|
| 159 | - $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
| 160 | - |
|
| 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); |
|
| 166 | - } |
|
| 167 | - |
|
| 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); |
|
| 171 | - //$line = "-- ".$line." replaced by --\n".$newline; |
|
| 172 | - $line=$newline; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // tinyint type conversion |
|
| 176 | - $line=str_replace('tinyint','smallint',$line); |
|
| 177 | - |
|
| 178 | - // nuke unsigned |
|
| 179 | - $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
| 180 | - |
|
| 181 | - // blob -> text |
|
| 182 | - $line=preg_replace('/\w*blob/i','text',$line); |
|
| 183 | - |
|
| 184 | - // tinytext/mediumtext -> text |
|
| 185 | - $line=preg_replace('/tinytext/i','text',$line); |
|
| 186 | - $line=preg_replace('/mediumtext/i','text',$line); |
|
| 187 | - |
|
| 188 | - // change not null datetime field to null valid ones |
|
| 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); |
|
| 192 | - |
|
| 193 | - // double -> numeric |
|
| 194 | - $line=preg_replace('/^double/i','numeric',$line); |
|
| 195 | - $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
| 196 | - // float -> numeric |
|
| 197 | - $line=preg_replace('/^float/i','numeric',$line); |
|
| 198 | - $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
| 199 | - |
|
| 200 | - // unique index(field1,field2) |
|
| 201 | - if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
| 202 | - { |
|
| 203 | - $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // We remove end of requests "AFTER fieldxxx" |
|
| 207 | - $line=preg_replace('/AFTER [a-z0-9_]+/i','',$line); |
|
| 208 | - |
|
| 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); |
|
| 211 | - |
|
| 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)) |
|
| 214 | - { |
|
| 215 | - $line = "-- ".$line." replaced by --\n"; |
|
| 216 | - $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // Translate order to modify field format |
|
| 220 | - if (preg_match('/ALTER TABLE ([a-z0-9_]+) MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg)) |
|
| 221 | - { |
|
| 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; |
|
| 230 | - // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // alter table add primary key (field1, field2 ...) -> We create a unique index instead as dynamic creation of primary key is not supported |
|
| 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)) |
|
| 236 | - { |
|
| 237 | - $line = "-- ".$line." replaced by --\n"; |
|
| 238 | - $line.= "CREATE UNIQUE INDEX ".$reg[2]." ON ".$reg[1]."(".$reg[3]; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // Translate order to drop foreign keys |
|
| 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)) |
|
| 244 | - { |
|
| 245 | - $line = "-- ".$line." replaced by --\n"; |
|
| 246 | - $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // alter table add [unique] [index] (field1, field2 ...) |
|
| 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)) |
|
| 252 | - { |
|
| 253 | - $fieldlist=$reg[4]; |
|
| 254 | - $idxname=$reg[3]; |
|
| 255 | - $tablename=$reg[1]; |
|
| 256 | - $line = "-- ".$line." replaced by --\n"; |
|
| 257 | - $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
| 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)) { |
|
| 260 | - // Pour l'instant les contraintes ne sont pas créées |
|
| 261 | - dol_syslog(get_class().'::query line emptied'); |
|
| 262 | - $line = 'SELECT 0;'; |
|
| 263 | - |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - //if (preg_match('/rowid\s+.*\s+PRIMARY\s+KEY,/i', $line)) { |
|
| 267 | - //preg_replace('/(rowid\s+.*\s+PRIMARY\s+KEY\s*,)/i', '/* \\1 */', $line); |
|
| 268 | - //} |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Delete using criteria on other table must not declare twice the deleted table |
|
| 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)) |
|
| 274 | - { |
|
| 130 | + /** |
|
| 131 | + * Convert a SQL request in Mysql syntax to native syntax |
|
| 132 | + * |
|
| 133 | + * @param string $line SQL request line to convert |
|
| 134 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 135 | + * @return string SQL request line converted |
|
| 136 | + */ |
|
| 137 | + static function convertSQLFromMysql($line,$type='ddl') |
|
| 138 | + { |
|
| 139 | + // Removed empty line if this is a comment line for SVN tagging |
|
| 140 | + if (preg_match('/^--\s\$Id/i',$line)) { |
|
| 141 | + return ''; |
|
| 142 | + } |
|
| 143 | + // Return line if this is a comment |
|
| 144 | + if (preg_match('/^#/i',$line) || preg_match('/^$/i',$line) || preg_match('/^--/i',$line)) |
|
| 145 | + { |
|
| 146 | + return $line; |
|
| 147 | + } |
|
| 148 | + if ($line != "") |
|
| 149 | + { |
|
| 150 | + if ($type == 'auto') |
|
| 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'; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if ($type == 'dml') |
|
| 158 | + { |
|
| 159 | + $line=preg_replace('/\s/',' ',$line); // Replace tabulation with space |
|
| 160 | + |
|
| 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); |
|
| 166 | + } |
|
| 167 | + |
|
| 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); |
|
| 171 | + //$line = "-- ".$line." replaced by --\n".$newline; |
|
| 172 | + $line=$newline; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // tinyint type conversion |
|
| 176 | + $line=str_replace('tinyint','smallint',$line); |
|
| 177 | + |
|
| 178 | + // nuke unsigned |
|
| 179 | + $line=preg_replace('/(int\w+|smallint)\s+unsigned/i','\\1',$line); |
|
| 180 | + |
|
| 181 | + // blob -> text |
|
| 182 | + $line=preg_replace('/\w*blob/i','text',$line); |
|
| 183 | + |
|
| 184 | + // tinytext/mediumtext -> text |
|
| 185 | + $line=preg_replace('/tinytext/i','text',$line); |
|
| 186 | + $line=preg_replace('/mediumtext/i','text',$line); |
|
| 187 | + |
|
| 188 | + // change not null datetime field to null valid ones |
|
| 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); |
|
| 192 | + |
|
| 193 | + // double -> numeric |
|
| 194 | + $line=preg_replace('/^double/i','numeric',$line); |
|
| 195 | + $line=preg_replace('/(\s*)double/i','\\1numeric',$line); |
|
| 196 | + // float -> numeric |
|
| 197 | + $line=preg_replace('/^float/i','numeric',$line); |
|
| 198 | + $line=preg_replace('/(\s*)float/i','\\1numeric',$line); |
|
| 199 | + |
|
| 200 | + // unique index(field1,field2) |
|
| 201 | + if (preg_match('/unique index\s*\((\w+\s*,\s*\w+)\)/i',$line)) |
|
| 202 | + { |
|
| 203 | + $line=preg_replace('/unique index\s*\((\w+\s*,\s*\w+)\)/i','UNIQUE\(\\1\)',$line); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // We remove end of requests "AFTER fieldxxx" |
|
| 207 | + $line=preg_replace('/AFTER [a-z0-9_]+/i','',$line); |
|
| 208 | + |
|
| 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); |
|
| 211 | + |
|
| 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)) |
|
| 214 | + { |
|
| 215 | + $line = "-- ".$line." replaced by --\n"; |
|
| 216 | + $line.= "ALTER TABLE ".$reg[1]." RENAME COLUMN ".$reg[2]." TO ".$reg[3]; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // Translate order to modify field format |
|
| 220 | + if (preg_match('/ALTER TABLE ([a-z0-9_]+) MODIFY(?: COLUMN)? ([a-z0-9_]+) (.*)$/i',$line,$reg)) |
|
| 221 | + { |
|
| 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; |
|
| 230 | + // TODO Add alter to set default value or null/not null if there is this in $reg[3] |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // alter table add primary key (field1, field2 ...) -> We create a unique index instead as dynamic creation of primary key is not supported |
|
| 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)) |
|
| 236 | + { |
|
| 237 | + $line = "-- ".$line." replaced by --\n"; |
|
| 238 | + $line.= "CREATE UNIQUE INDEX ".$reg[2]." ON ".$reg[1]."(".$reg[3]; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // Translate order to drop foreign keys |
|
| 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)) |
|
| 244 | + { |
|
| 245 | + $line = "-- ".$line." replaced by --\n"; |
|
| 246 | + $line.= "ALTER TABLE ".$reg[1]." DROP CONSTRAINT ".$reg[2]; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // alter table add [unique] [index] (field1, field2 ...) |
|
| 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)) |
|
| 252 | + { |
|
| 253 | + $fieldlist=$reg[4]; |
|
| 254 | + $idxname=$reg[3]; |
|
| 255 | + $tablename=$reg[1]; |
|
| 256 | + $line = "-- ".$line." replaced by --\n"; |
|
| 257 | + $line.= "CREATE ".(preg_match('/UNIQUE/',$reg[2])?'UNIQUE ':'')."INDEX ".$idxname." ON ".$tablename." (".$fieldlist.")"; |
|
| 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)) { |
|
| 260 | + // Pour l'instant les contraintes ne sont pas créées |
|
| 261 | + dol_syslog(get_class().'::query line emptied'); |
|
| 262 | + $line = 'SELECT 0;'; |
|
| 263 | + |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + //if (preg_match('/rowid\s+.*\s+PRIMARY\s+KEY,/i', $line)) { |
|
| 267 | + //preg_replace('/(rowid\s+.*\s+PRIMARY\s+KEY\s*,)/i', '/* \\1 */', $line); |
|
| 268 | + //} |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Delete using criteria on other table must not declare twice the deleted table |
|
| 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)) |
|
| 274 | + { |
|
| 275 | 275 | if ($reg[1] == $reg[2]) // If same table, we remove second one |
| 276 | - { |
|
| 277 | - $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line); |
|
| 278 | - } |
|
| 279 | - } |
|
| 276 | + { |
|
| 277 | + $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | 280 | |
| 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); |
|
| 283 | - //print $line."\n"; |
|
| 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); |
|
| 283 | + //print $line."\n"; |
|
| 284 | 284 | |
| 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); |
|
| 287 | - //print $line."\n"; |
|
| 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); |
|
| 287 | + //print $line."\n"; |
|
| 288 | 288 | |
| 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); |
|
| 291 | - //print $line."\n"; |
|
| 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); |
|
| 291 | + //print $line."\n"; |
|
| 292 | 292 | |
| 293 | - //print "type=".$type." newline=".$line."<br>\n"; |
|
| 294 | - } |
|
| 293 | + //print "type=".$type." newline=".$line."<br>\n"; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - return $line; |
|
| 297 | - } |
|
| 296 | + return $line; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 299 | + /** |
|
| 300 | 300 | * Select a database |
| 301 | - * |
|
| 301 | + * |
|
| 302 | 302 | * @param string $database Name of database |
| 303 | 303 | * @return boolean true if OK, false if KO |
| 304 | - */ |
|
| 305 | - function select_db($database) |
|
| 306 | - { |
|
| 307 | - dol_syslog(get_class($this)."::select_db database=".$database, LOG_DEBUG); |
|
| 308 | - // sqlite_select_db() does not exist |
|
| 309 | - //return sqlite_select_db($this->db,$database); |
|
| 310 | - return true; |
|
| 311 | - } |
|
| 304 | + */ |
|
| 305 | + function select_db($database) |
|
| 306 | + { |
|
| 307 | + dol_syslog(get_class($this)."::select_db database=".$database, LOG_DEBUG); |
|
| 308 | + // sqlite_select_db() does not exist |
|
| 309 | + //return sqlite_select_db($this->db,$database); |
|
| 310 | + return true; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | 313 | |
| 314 | - /** |
|
| 314 | + /** |
|
| 315 | 315 | * Connexion to server |
| 316 | - * |
|
| 316 | + * |
|
| 317 | 317 | * @param string $host database server host |
| 318 | 318 | * @param string $login login |
| 319 | 319 | * @param string $passwd password |
@@ -321,310 +321,310 @@ discard block |
||
| 321 | 321 | * @param integer $port Port of database server |
| 322 | 322 | * @return SQLite3 Database access handler |
| 323 | 323 | * @see close |
| 324 | - */ |
|
| 325 | - function connect($host, $login, $passwd, $name, $port=0) |
|
| 326 | - { |
|
| 327 | - global $main_data_dir; |
|
| 328 | - |
|
| 329 | - dol_syslog(get_class($this)."::connect name=".$name,LOG_DEBUG); |
|
| 330 | - |
|
| 331 | - $dir=$main_data_dir; |
|
| 332 | - if (empty($dir)) $dir=DOL_DATA_ROOT; |
|
| 333 | - // With sqlite, port must be in connect parameters |
|
| 334 | - //if (! $newport) $newport=3306; |
|
| 335 | - $database_name = $dir.'/database_'.$name.'.sdb'; |
|
| 336 | - try { |
|
| 337 | - /*** connect to SQLite database ***/ |
|
| 338 | - //$this->db = new PDO("sqlite:".$dir.'/database_'.$name.'.sdb'); |
|
| 324 | + */ |
|
| 325 | + function connect($host, $login, $passwd, $name, $port=0) |
|
| 326 | + { |
|
| 327 | + global $main_data_dir; |
|
| 328 | + |
|
| 329 | + dol_syslog(get_class($this)."::connect name=".$name,LOG_DEBUG); |
|
| 330 | + |
|
| 331 | + $dir=$main_data_dir; |
|
| 332 | + if (empty($dir)) $dir=DOL_DATA_ROOT; |
|
| 333 | + // With sqlite, port must be in connect parameters |
|
| 334 | + //if (! $newport) $newport=3306; |
|
| 335 | + $database_name = $dir.'/database_'.$name.'.sdb'; |
|
| 336 | + try { |
|
| 337 | + /*** connect to SQLite database ***/ |
|
| 338 | + //$this->db = new PDO("sqlite:".$dir.'/database_'.$name.'.sdb'); |
|
| 339 | 339 | $this->db = new SQLite3($database_name); |
| 340 | - //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 341 | - } |
|
| 342 | - catch(Exception $e) |
|
| 343 | - { |
|
| 344 | - $this->error= self::LABEL.' '.$e->getMessage().' current dir='.$database_name; |
|
| 345 | - return ''; |
|
| 346 | - } |
|
| 340 | + //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 341 | + } |
|
| 342 | + catch(Exception $e) |
|
| 343 | + { |
|
| 344 | + $this->error= self::LABEL.' '.$e->getMessage().' current dir='.$database_name; |
|
| 345 | + return ''; |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - //print "Resultat fonction connect: ".$this->db; |
|
| 349 | - return $this->db; |
|
| 350 | - } |
|
| 348 | + //print "Resultat fonction connect: ".$this->db; |
|
| 349 | + return $this->db; |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | 352 | |
| 353 | - /** |
|
| 353 | + /** |
|
| 354 | 354 | * Return version of database server |
| 355 | - * |
|
| 355 | + * |
|
| 356 | 356 | * @return string Version string |
| 357 | - */ |
|
| 358 | - function getVersion() |
|
| 359 | - { |
|
| 360 | - $tmp=$this->db->version(); |
|
| 361 | - return $tmp['versionString']; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Return version of database client driver |
|
| 366 | - * |
|
| 367 | - * @return string Version string |
|
| 368 | - */ |
|
| 369 | - function getDriverInfo() |
|
| 370 | - { |
|
| 371 | - return 'sqlite3 php driver'; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Close database connexion |
|
| 377 | - * |
|
| 378 | - * @return bool True if disconnect successfull, false otherwise |
|
| 379 | - * @see connect |
|
| 380 | - */ |
|
| 381 | - function close() |
|
| 382 | - { |
|
| 383 | - if ($this->db) |
|
| 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; |
|
| 387 | - $this->db->close(); |
|
| 388 | - unset($this->db); // Clean this->db |
|
| 389 | - return true; |
|
| 390 | - } |
|
| 391 | - return false; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Execute a SQL request and return the resultset |
|
| 396 | - * |
|
| 397 | - * @param string $query SQL query string |
|
| 398 | - * @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). |
|
| 399 | - * 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. |
|
| 400 | - * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 401 | - * @return SQLite3Result Resultset of answer |
|
| 402 | - */ |
|
| 403 | - function query($query,$usesavepoint=0,$type='auto') |
|
| 404 | - { |
|
| 405 | - $ret=null; |
|
| 406 | - $query = trim($query); |
|
| 407 | - $this->error = 0; |
|
| 408 | - |
|
| 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)) { |
|
| 411 | - // Ajout d'une clef étrangère à la table |
|
| 412 | - // procédure de remplacement de la table pour ajouter la contrainte |
|
| 413 | - // Exemple : ALTER TABLE llx_adherent ADD CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid) |
|
| 414 | - // -> CREATE TABLE ( ... ,CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid)) |
|
| 415 | - $foreignFields = $reg[5]; |
|
| 416 | - $foreignTable = $reg[4]; |
|
| 417 | - $localfields = $reg[3]; |
|
| 418 | - $constraintname=trim($reg[2]); |
|
| 419 | - $tablename=trim($reg[1]); |
|
| 420 | - |
|
| 421 | - $descTable = $this->db->querySingle("SELECT sql FROM sqlite_master WHERE name='" . $tablename . "'"); |
|
| 422 | - |
|
| 423 | - // 1- Renommer la table avec un nom temporaire |
|
| 424 | - $this->query('ALTER TABLE ' . $tablename . ' RENAME TO tmp_' . $tablename); |
|
| 425 | - |
|
| 426 | - // 2- Recréer la table avec la contrainte ajoutée |
|
| 427 | - |
|
| 428 | - // on bricole la requete pour ajouter la contrainte |
|
| 429 | - $descTable = substr($descTable, 0, strlen($descTable) - 1); |
|
| 430 | - $descTable .= ", CONSTRAINT " . $constraintname . " FOREIGN KEY (" . $localfields . ") REFERENCES " .$foreignTable . "(" . $foreignFields . ")"; |
|
| 431 | - |
|
| 432 | - // fermeture de l'instruction |
|
| 433 | - $descTable .= ')'; |
|
| 434 | - |
|
| 435 | - // Création proprement dite de la table |
|
| 436 | - $this->query($descTable); |
|
| 437 | - |
|
| 438 | - // 3- Transférer les données |
|
| 439 | - $this->query('INSERT INTO ' . $tablename . ' SELECT * FROM tmp_' . $tablename); |
|
| 440 | - |
|
| 441 | - // 4- Supprimer la table temporaire |
|
| 442 | - $this->query('DROP TABLE tmp_' . $tablename); |
|
| 443 | - |
|
| 444 | - // dummy statement |
|
| 445 | - $query="SELECT 0"; |
|
| 446 | - |
|
| 447 | - } else { |
|
| 448 | - $query=$this->convertSQLFromMysql($query,$type); |
|
| 449 | - } |
|
| 450 | - //print "After convertSQLFromMysql:\n".$query."<br>\n"; |
|
| 357 | + */ |
|
| 358 | + function getVersion() |
|
| 359 | + { |
|
| 360 | + $tmp=$this->db->version(); |
|
| 361 | + return $tmp['versionString']; |
|
| 362 | + } |
|
| 451 | 363 | |
| 452 | - dol_syslog('sql='.$query, LOG_DEBUG); |
|
| 364 | + /** |
|
| 365 | + * Return version of database client driver |
|
| 366 | + * |
|
| 367 | + * @return string Version string |
|
| 368 | + */ |
|
| 369 | + function getDriverInfo() |
|
| 370 | + { |
|
| 371 | + return 'sqlite3 php driver'; |
|
| 372 | + } |
|
| 453 | 373 | |
| 454 | - // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
|
| 455 | - try { |
|
| 456 | - //$ret = $this->db->exec($query); |
|
| 457 | - $ret = $this->db->query($query); // $ret is a Sqlite3Result |
|
| 458 | - if ($ret) { |
|
| 459 | - $ret->queryString = $query; |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - catch(Exception $e) |
|
| 463 | - { |
|
| 464 | - $this->error=$this->db->lastErrorMsg(); |
|
| 465 | - } |
|
| 466 | 374 | |
| 467 | - if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
| 468 | - { |
|
| 469 | - // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
| 470 | - if (! is_object($ret) || $this->error) |
|
| 471 | - { |
|
| 472 | - $this->lastqueryerror = $query; |
|
| 473 | - $this->lasterror = $this->error(); |
|
| 474 | - $this->lasterrno = $this->errno(); |
|
| 375 | + /** |
|
| 376 | + * Close database connexion |
|
| 377 | + * |
|
| 378 | + * @return bool True if disconnect successfull, false otherwise |
|
| 379 | + * @see connect |
|
| 380 | + */ |
|
| 381 | + function close() |
|
| 382 | + { |
|
| 383 | + if ($this->db) |
|
| 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; |
|
| 387 | + $this->db->close(); |
|
| 388 | + unset($this->db); // Clean this->db |
|
| 389 | + return true; |
|
| 390 | + } |
|
| 391 | + return false; |
|
| 392 | + } |
|
| 475 | 393 | |
| 476 | - dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); |
|
| 394 | + /** |
|
| 395 | + * Execute a SQL request and return the resultset |
|
| 396 | + * |
|
| 397 | + * @param string $query SQL query string |
|
| 398 | + * @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). |
|
| 399 | + * 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. |
|
| 400 | + * @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...) |
|
| 401 | + * @return SQLite3Result Resultset of answer |
|
| 402 | + */ |
|
| 403 | + function query($query,$usesavepoint=0,$type='auto') |
|
| 404 | + { |
|
| 405 | + $ret=null; |
|
| 406 | + $query = trim($query); |
|
| 407 | + $this->error = 0; |
|
| 408 | + |
|
| 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)) { |
|
| 411 | + // Ajout d'une clef étrangère à la table |
|
| 412 | + // procédure de remplacement de la table pour ajouter la contrainte |
|
| 413 | + // Exemple : ALTER TABLE llx_adherent ADD CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid) |
|
| 414 | + // -> CREATE TABLE ( ... ,CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid)) |
|
| 415 | + $foreignFields = $reg[5]; |
|
| 416 | + $foreignTable = $reg[4]; |
|
| 417 | + $localfields = $reg[3]; |
|
| 418 | + $constraintname=trim($reg[2]); |
|
| 419 | + $tablename=trim($reg[1]); |
|
| 420 | + |
|
| 421 | + $descTable = $this->db->querySingle("SELECT sql FROM sqlite_master WHERE name='" . $tablename . "'"); |
|
| 422 | + |
|
| 423 | + // 1- Renommer la table avec un nom temporaire |
|
| 424 | + $this->query('ALTER TABLE ' . $tablename . ' RENAME TO tmp_' . $tablename); |
|
| 425 | + |
|
| 426 | + // 2- Recréer la table avec la contrainte ajoutée |
|
| 427 | + |
|
| 428 | + // on bricole la requete pour ajouter la contrainte |
|
| 429 | + $descTable = substr($descTable, 0, strlen($descTable) - 1); |
|
| 430 | + $descTable .= ", CONSTRAINT " . $constraintname . " FOREIGN KEY (" . $localfields . ") REFERENCES " .$foreignTable . "(" . $foreignFields . ")"; |
|
| 431 | + |
|
| 432 | + // fermeture de l'instruction |
|
| 433 | + $descTable .= ')'; |
|
| 434 | + |
|
| 435 | + // Création proprement dite de la table |
|
| 436 | + $this->query($descTable); |
|
| 437 | + |
|
| 438 | + // 3- Transférer les données |
|
| 439 | + $this->query('INSERT INTO ' . $tablename . ' SELECT * FROM tmp_' . $tablename); |
|
| 440 | + |
|
| 441 | + // 4- Supprimer la table temporaire |
|
| 442 | + $this->query('DROP TABLE tmp_' . $tablename); |
|
| 443 | + |
|
| 444 | + // dummy statement |
|
| 445 | + $query="SELECT 0"; |
|
| 446 | + |
|
| 447 | + } else { |
|
| 448 | + $query=$this->convertSQLFromMysql($query,$type); |
|
| 449 | + } |
|
| 450 | + //print "After convertSQLFromMysql:\n".$query."<br>\n"; |
|
| 451 | + |
|
| 452 | + dol_syslog('sql='.$query, LOG_DEBUG); |
|
| 453 | + |
|
| 454 | + // Ordre SQL ne necessitant pas de connexion a une base (exemple: CREATE DATABASE) |
|
| 455 | + try { |
|
| 456 | + //$ret = $this->db->exec($query); |
|
| 457 | + $ret = $this->db->query($query); // $ret is a Sqlite3Result |
|
| 458 | + if ($ret) { |
|
| 459 | + $ret->queryString = $query; |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + catch(Exception $e) |
|
| 463 | + { |
|
| 464 | + $this->error=$this->db->lastErrorMsg(); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + if (! preg_match("/^COMMIT/i",$query) && ! preg_match("/^ROLLBACK/i",$query)) |
|
| 468 | + { |
|
| 469 | + // Si requete utilisateur, on la sauvegarde ainsi que son resultset |
|
| 470 | + if (! is_object($ret) || $this->error) |
|
| 471 | + { |
|
| 472 | + $this->lastqueryerror = $query; |
|
| 473 | + $this->lasterror = $this->error(); |
|
| 474 | + $this->lasterrno = $this->errno(); |
|
| 475 | + |
|
| 476 | + dol_syslog(get_class($this)."::query SQL Error query: ".$query, LOG_ERR); |
|
| 477 | + |
|
| 478 | + $errormsg = get_class($this)."::query SQL Error message: ".$this->lasterror; |
|
| 479 | + |
|
| 480 | + if (preg_match('/[0-9]/',$this->lasterrno)) { |
|
| 481 | + $errormsg .= ' ('.$this->lasterrno.')'; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + dol_syslog($errormsg, LOG_ERR); |
|
| 485 | + } |
|
| 486 | + $this->lastquery=$query; |
|
| 487 | + $this->_results = $ret; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + return $ret; |
|
| 491 | + } |
|
| 477 | 492 | |
| 478 | - $errormsg = get_class($this)."::query SQL Error message: ".$this->lasterror; |
|
| 493 | + /** |
|
| 494 | + * Renvoie la ligne courante (comme un objet) pour le curseur resultset |
|
| 495 | + * |
|
| 496 | + * @param SQLite3Result $resultset Curseur de la requete voulue |
|
| 497 | + * @return false|object Object result line or false if KO or end of cursor |
|
| 498 | + */ |
|
| 499 | + function fetch_object($resultset) |
|
| 500 | + { |
|
| 501 | + // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
|
| 502 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 503 | + //return $resultset->fetch(PDO::FETCH_OBJ); |
|
| 504 | + $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
|
| 505 | + if ($ret) { |
|
| 506 | + return (object) $ret; |
|
| 507 | + } |
|
| 508 | + return false; |
|
| 509 | + } |
|
| 479 | 510 | |
| 480 | - if (preg_match('/[0-9]/',$this->lasterrno)) { |
|
| 481 | - $errormsg .= ' ('.$this->lasterrno.')'; |
|
| 482 | - } |
|
| 483 | 511 | |
| 484 | - dol_syslog($errormsg, LOG_ERR); |
|
| 485 | - } |
|
| 486 | - $this->lastquery=$query; |
|
| 487 | - $this->_results = $ret; |
|
| 488 | - } |
|
| 512 | + /** |
|
| 513 | + * Return datas as an array |
|
| 514 | + * |
|
| 515 | + * @param SQLite3Result $resultset Resultset of request |
|
| 516 | + * @return false|array Array or false if KO or end of cursor |
|
| 517 | + */ |
|
| 518 | + function fetch_array($resultset) |
|
| 519 | + { |
|
| 520 | + // If resultset not provided, we take the last used by connexion |
|
| 521 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 522 | + //return $resultset->fetch(PDO::FETCH_ASSOC); |
|
| 523 | + $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
|
| 524 | + return $ret; |
|
| 525 | + } |
|
| 489 | 526 | |
| 490 | - return $ret; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * Renvoie la ligne courante (comme un objet) pour le curseur resultset |
|
| 495 | - * |
|
| 496 | - * @param SQLite3Result $resultset Curseur de la requete voulue |
|
| 497 | - * @return false|object Object result line or false if KO or end of cursor |
|
| 498 | - */ |
|
| 499 | - function fetch_object($resultset) |
|
| 500 | - { |
|
| 501 | - // Si le resultset n'est pas fourni, on prend le dernier utilise sur cette connexion |
|
| 502 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 503 | - //return $resultset->fetch(PDO::FETCH_OBJ); |
|
| 504 | - $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
|
| 505 | - if ($ret) { |
|
| 506 | - return (object) $ret; |
|
| 507 | - } |
|
| 508 | - return false; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Return datas as an array |
|
| 514 | - * |
|
| 515 | - * @param SQLite3Result $resultset Resultset of request |
|
| 516 | - * @return false|array Array or false if KO or end of cursor |
|
| 517 | - */ |
|
| 518 | - function fetch_array($resultset) |
|
| 519 | - { |
|
| 520 | - // If resultset not provided, we take the last used by connexion |
|
| 521 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 522 | - //return $resultset->fetch(PDO::FETCH_ASSOC); |
|
| 523 | - $ret = $resultset->fetchArray(SQLITE3_ASSOC); |
|
| 524 | - return $ret; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * Return datas as an array |
|
| 529 | - * |
|
| 530 | - * @param SQLite3Result $resultset Resultset of request |
|
| 531 | - * @return false|array Array or false if KO or end of cursor |
|
| 532 | - */ |
|
| 533 | - function fetch_row($resultset) |
|
| 534 | - { |
|
| 535 | - // If resultset not provided, we take the last used by connexion |
|
| 536 | - if (! is_bool($resultset)) |
|
| 537 | - { |
|
| 538 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 539 | - return $resultset->fetchArray(SQLITE3_NUM); |
|
| 540 | - } |
|
| 541 | - else |
|
| 542 | - { |
|
| 543 | - // si le curseur est un booleen on retourne la valeur 0 |
|
| 544 | - return false; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Return number of lines for result of a SELECT |
|
| 550 | - * |
|
| 551 | - * @param SQLite3Result $resultset Resulset of requests |
|
| 552 | - * @return int Nb of lines |
|
| 553 | - * @see affected_rows |
|
| 554 | - */ |
|
| 555 | - function num_rows($resultset) |
|
| 556 | - { |
|
| 557 | - // FIXME: SQLite3Result does not have a queryString member |
|
| 558 | - |
|
| 559 | - // If resultset not provided, we take the last used by connexion |
|
| 560 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 561 | - if (preg_match("/^SELECT/i", $resultset->queryString)) { |
|
| 562 | - return $this->db->querySingle("SELECT count(*) FROM (" . $resultset->queryString . ") q"); |
|
| 563 | - } |
|
| 564 | - return 0; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Return number of lines for result of a SELECT |
|
| 569 | - * |
|
| 570 | - * @param SQLite3Result $resultset Resulset of requests |
|
| 571 | - * @return int Nb of lines |
|
| 572 | - * @see affected_rows |
|
| 573 | - */ |
|
| 574 | - function affected_rows($resultset) |
|
| 575 | - { |
|
| 576 | - // FIXME: SQLite3Result does not have a queryString member |
|
| 577 | - |
|
| 578 | - // If resultset not provided, we take the last used by connexion |
|
| 579 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 580 | - if (preg_match("/^SELECT/i", $resultset->queryString)) { |
|
| 581 | - return $this->num_rows($resultset); |
|
| 582 | - } |
|
| 583 | - // mysql necessite un link de base pour cette fonction contrairement |
|
| 584 | - // a pqsql qui prend un resultset |
|
| 585 | - return $this->db->changes(); |
|
| 586 | - } |
|
| 527 | + /** |
|
| 528 | + * Return datas as an array |
|
| 529 | + * |
|
| 530 | + * @param SQLite3Result $resultset Resultset of request |
|
| 531 | + * @return false|array Array or false if KO or end of cursor |
|
| 532 | + */ |
|
| 533 | + function fetch_row($resultset) |
|
| 534 | + { |
|
| 535 | + // If resultset not provided, we take the last used by connexion |
|
| 536 | + if (! is_bool($resultset)) |
|
| 537 | + { |
|
| 538 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 539 | + return $resultset->fetchArray(SQLITE3_NUM); |
|
| 540 | + } |
|
| 541 | + else |
|
| 542 | + { |
|
| 543 | + // si le curseur est un booleen on retourne la valeur 0 |
|
| 544 | + return false; |
|
| 545 | + } |
|
| 546 | + } |
|
| 587 | 547 | |
| 548 | + /** |
|
| 549 | + * Return number of lines for result of a SELECT |
|
| 550 | + * |
|
| 551 | + * @param SQLite3Result $resultset Resulset of requests |
|
| 552 | + * @return int Nb of lines |
|
| 553 | + * @see affected_rows |
|
| 554 | + */ |
|
| 555 | + function num_rows($resultset) |
|
| 556 | + { |
|
| 557 | + // FIXME: SQLite3Result does not have a queryString member |
|
| 558 | + |
|
| 559 | + // If resultset not provided, we take the last used by connexion |
|
| 560 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 561 | + if (preg_match("/^SELECT/i", $resultset->queryString)) { |
|
| 562 | + return $this->db->querySingle("SELECT count(*) FROM (" . $resultset->queryString . ") q"); |
|
| 563 | + } |
|
| 564 | + return 0; |
|
| 565 | + } |
|
| 588 | 566 | |
| 589 | - /** |
|
| 567 | + /** |
|
| 568 | + * Return number of lines for result of a SELECT |
|
| 569 | + * |
|
| 570 | + * @param SQLite3Result $resultset Resulset of requests |
|
| 571 | + * @return int Nb of lines |
|
| 572 | + * @see affected_rows |
|
| 573 | + */ |
|
| 574 | + function affected_rows($resultset) |
|
| 575 | + { |
|
| 576 | + // FIXME: SQLite3Result does not have a queryString member |
|
| 577 | + |
|
| 578 | + // If resultset not provided, we take the last used by connexion |
|
| 579 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 580 | + if (preg_match("/^SELECT/i", $resultset->queryString)) { |
|
| 581 | + return $this->num_rows($resultset); |
|
| 582 | + } |
|
| 583 | + // mysql necessite un link de base pour cette fonction contrairement |
|
| 584 | + // a pqsql qui prend un resultset |
|
| 585 | + return $this->db->changes(); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | 590 | * Free last resultset used. |
| 591 | - * |
|
| 591 | + * |
|
| 592 | 592 | * @param SQLite3Result $resultset Curseur de la requete voulue |
| 593 | 593 | * @return void |
| 594 | - */ |
|
| 595 | - function free($resultset=null) |
|
| 596 | - { |
|
| 597 | - // If resultset not provided, we take the last used by connexion |
|
| 598 | - if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 599 | - // Si resultset en est un, on libere la memoire |
|
| 600 | - if ($resultset && is_object($resultset)) $resultset->finalize(); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /** |
|
| 594 | + */ |
|
| 595 | + function free($resultset=null) |
|
| 596 | + { |
|
| 597 | + // If resultset not provided, we take the last used by connexion |
|
| 598 | + if (! is_object($resultset)) { $resultset=$this->_results; } |
|
| 599 | + // Si resultset en est un, on libere la memoire |
|
| 600 | + if ($resultset && is_object($resultset)) $resultset->finalize(); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | 604 | * Escape a string to insert data |
| 605 | - * |
|
| 605 | + * |
|
| 606 | 606 | * @param string $stringtoencode String to escape |
| 607 | 607 | * @return string String escaped |
| 608 | - */ |
|
| 609 | - function escape($stringtoencode) |
|
| 610 | - { |
|
| 611 | - return Sqlite3::escapeString($stringtoencode); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Renvoie le code erreur generique de l'operation precedente. |
|
| 616 | - * |
|
| 617 | - * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
| 618 | - */ |
|
| 619 | - function errno() |
|
| 620 | - { |
|
| 621 | - if (! $this->connected) { |
|
| 622 | - // Si il y a eu echec de connexion, $this->db n'est pas valide. |
|
| 623 | - return 'DB_ERROR_FAILED_TO_CONNECT'; |
|
| 624 | - } |
|
| 625 | - else { |
|
| 626 | - // Constants to convert error code to a generic Dolibarr error code |
|
| 627 | - /*$errorcode_map = array( |
|
| 608 | + */ |
|
| 609 | + function escape($stringtoencode) |
|
| 610 | + { |
|
| 611 | + return Sqlite3::escapeString($stringtoencode); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Renvoie le code erreur generique de l'operation precedente. |
|
| 616 | + * |
|
| 617 | + * @return string Error code (Exemples: DB_ERROR_TABLE_ALREADY_EXISTS, DB_ERROR_RECORD_ALREADY_EXISTS...) |
|
| 618 | + */ |
|
| 619 | + function errno() |
|
| 620 | + { |
|
| 621 | + if (! $this->connected) { |
|
| 622 | + // Si il y a eu echec de connexion, $this->db n'est pas valide. |
|
| 623 | + return 'DB_ERROR_FAILED_TO_CONNECT'; |
|
| 624 | + } |
|
| 625 | + else { |
|
| 626 | + // Constants to convert error code to a generic Dolibarr error code |
|
| 627 | + /*$errorcode_map = array( |
|
| 628 | 628 | 1004 => 'DB_ERROR_CANNOT_CREATE', |
| 629 | 629 | 1005 => 'DB_ERROR_CANNOT_CREATE', |
| 630 | 630 | 1006 => 'DB_ERROR_CANNOT_CREATE', |
@@ -656,220 +656,220 @@ discard block |
||
| 656 | 656 | { |
| 657 | 657 | return $errorcode_map[$this->db->errorCode()]; |
| 658 | 658 | }*/ |
| 659 | - $errno=$this->db->lastErrorCode(); |
|
| 659 | + $errno=$this->db->lastErrorCode(); |
|
| 660 | 660 | if ($errno=='HY000' || $errno == 0) |
| 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'; |
|
| 665 | - } |
|
| 666 | - if ($errno=='23000') |
|
| 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'; |
|
| 670 | - } |
|
| 671 | - if ($errno > 1) { |
|
| 672 | - // TODO Voir la liste des messages d'erreur |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - return ($errno?'DB_ERROR_'.$errno:'0'); |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * Renvoie le texte de l'erreur mysql de l'operation precedente. |
|
| 681 | - * |
|
| 682 | - * @return string Error text |
|
| 683 | - */ |
|
| 684 | - function error() |
|
| 685 | - { |
|
| 686 | - if (! $this->connected) { |
|
| 687 | - // Si il y a eu echec de connexion, $this->db n'est pas valide pour sqlite_error. |
|
| 688 | - return 'Not connected. Check setup parameters in conf/conf.php file and your sqlite version'; |
|
| 689 | - } |
|
| 690 | - else { |
|
| 691 | - return $this->error; |
|
| 692 | - } |
|
| 693 | - } |
|
| 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'; |
|
| 665 | + } |
|
| 666 | + if ($errno=='23000') |
|
| 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'; |
|
| 670 | + } |
|
| 671 | + if ($errno > 1) { |
|
| 672 | + // TODO Voir la liste des messages d'erreur |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + return ($errno?'DB_ERROR_'.$errno:'0'); |
|
| 676 | + } |
|
| 677 | + } |
|
| 694 | 678 | |
| 695 | - /** |
|
| 696 | - * Get last ID after an insert INSERT |
|
| 697 | - * |
|
| 679 | + /** |
|
| 680 | + * Renvoie le texte de l'erreur mysql de l'operation precedente. |
|
| 681 | + * |
|
| 682 | + * @return string Error text |
|
| 683 | + */ |
|
| 684 | + function error() |
|
| 685 | + { |
|
| 686 | + if (! $this->connected) { |
|
| 687 | + // Si il y a eu echec de connexion, $this->db n'est pas valide pour sqlite_error. |
|
| 688 | + return 'Not connected. Check setup parameters in conf/conf.php file and your sqlite version'; |
|
| 689 | + } |
|
| 690 | + else { |
|
| 691 | + return $this->error; |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Get last ID after an insert INSERT |
|
| 697 | + * |
|
| 698 | 698 | * @param string $tab Table name concerned by insert. Ne sert pas sous MySql mais requis pour compatibilite avec Postgresql |
| 699 | 699 | * @param string $fieldid Field name |
| 700 | 700 | * @return int Id of row |
| 701 | - */ |
|
| 702 | - function last_insert_id($tab,$fieldid='rowid') |
|
| 703 | - { |
|
| 704 | - return $this->db->lastInsertRowId(); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * Encrypt sensitive data in database |
|
| 709 | - * Warning: This function includes the escape, so it must use direct value |
|
| 710 | - * |
|
| 711 | - * @param string $fieldorvalue Field name or value to encrypt |
|
| 712 | - * @param int $withQuotes Return string with quotes |
|
| 713 | - * @return string XXX(field) or XXX('value') or field or 'value' |
|
| 714 | - */ |
|
| 715 | - function encrypt($fieldorvalue, $withQuotes=0) |
|
| 716 | - { |
|
| 717 | - global $conf; |
|
| 718 | - |
|
| 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); |
|
| 721 | - |
|
| 722 | - //Encryption key |
|
| 723 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
| 724 | - |
|
| 725 | - $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
| 726 | - |
|
| 727 | - if ($cryptType && !empty($cryptKey)) |
|
| 728 | - { |
|
| 729 | - if ($cryptType == 2) |
|
| 730 | - { |
|
| 731 | - $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
| 732 | - } |
|
| 733 | - else if ($cryptType == 1) |
|
| 734 | - { |
|
| 735 | - $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
| 736 | - } |
|
| 737 | - } |
|
| 701 | + */ |
|
| 702 | + function last_insert_id($tab,$fieldid='rowid') |
|
| 703 | + { |
|
| 704 | + return $this->db->lastInsertRowId(); |
|
| 705 | + } |
|
| 738 | 706 | |
| 739 | - return $return; |
|
| 740 | - } |
|
| 707 | + /** |
|
| 708 | + * Encrypt sensitive data in database |
|
| 709 | + * Warning: This function includes the escape, so it must use direct value |
|
| 710 | + * |
|
| 711 | + * @param string $fieldorvalue Field name or value to encrypt |
|
| 712 | + * @param int $withQuotes Return string with quotes |
|
| 713 | + * @return string XXX(field) or XXX('value') or field or 'value' |
|
| 714 | + */ |
|
| 715 | + function encrypt($fieldorvalue, $withQuotes=0) |
|
| 716 | + { |
|
| 717 | + global $conf; |
|
| 741 | 718 | |
| 742 | - /** |
|
| 743 | - * Decrypt sensitive data in database |
|
| 744 | - * |
|
| 745 | - * @param string $value Value to decrypt |
|
| 746 | - * @return string Decrypted value if used |
|
| 747 | - */ |
|
| 748 | - function decrypt($value) |
|
| 749 | - { |
|
| 750 | - global $conf; |
|
| 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); |
|
| 751 | 721 | |
| 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); |
|
| 722 | + //Encryption key |
|
| 723 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
| 754 | 724 | |
| 755 | - //Encryption key |
|
| 756 | - $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
| 725 | + $return = ($withQuotes?"'":"").$this->escape($fieldorvalue).($withQuotes?"'":""); |
|
| 757 | 726 | |
| 758 | - $return = $value; |
|
| 727 | + if ($cryptType && !empty($cryptKey)) |
|
| 728 | + { |
|
| 729 | + if ($cryptType == 2) |
|
| 730 | + { |
|
| 731 | + $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
| 732 | + } |
|
| 733 | + else if ($cryptType == 1) |
|
| 734 | + { |
|
| 735 | + $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
|
| 736 | + } |
|
| 737 | + } |
|
| 759 | 738 | |
| 760 | - if ($cryptType && !empty($cryptKey)) |
|
| 761 | - { |
|
| 762 | - if ($cryptType == 2) |
|
| 763 | - { |
|
| 764 | - $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
| 765 | - } |
|
| 766 | - else if ($cryptType == 1) |
|
| 767 | - { |
|
| 768 | - $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
| 769 | - } |
|
| 770 | - } |
|
| 739 | + return $return; |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * Decrypt sensitive data in database |
|
| 744 | + * |
|
| 745 | + * @param string $value Value to decrypt |
|
| 746 | + * @return string Decrypted value if used |
|
| 747 | + */ |
|
| 748 | + function decrypt($value) |
|
| 749 | + { |
|
| 750 | + global $conf; |
|
| 751 | + |
|
| 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); |
|
| 754 | + |
|
| 755 | + //Encryption key |
|
| 756 | + $cryptKey = (!empty($conf->db->dolibarr_main_db_cryptkey)?$conf->db->dolibarr_main_db_cryptkey:''); |
|
| 757 | + |
|
| 758 | + $return = $value; |
|
| 771 | 759 | |
| 772 | - return $return; |
|
| 773 | - } |
|
| 760 | + if ($cryptType && !empty($cryptKey)) |
|
| 761 | + { |
|
| 762 | + if ($cryptType == 2) |
|
| 763 | + { |
|
| 764 | + $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
| 765 | + } |
|
| 766 | + else if ($cryptType == 1) |
|
| 767 | + { |
|
| 768 | + $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
|
| 769 | + } |
|
| 770 | + } |
|
| 774 | 771 | |
| 772 | + return $return; |
|
| 773 | + } |
|
| 775 | 774 | |
| 776 | - /** |
|
| 777 | - * Return connexion ID |
|
| 778 | - * |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * Return connexion ID |
|
| 778 | + * |
|
| 779 | 779 | * @return string Id connexion |
| 780 | - */ |
|
| 781 | - function DDLGetConnectId() |
|
| 782 | - { |
|
| 783 | - return '?'; |
|
| 784 | - } |
|
| 780 | + */ |
|
| 781 | + function DDLGetConnectId() |
|
| 782 | + { |
|
| 783 | + return '?'; |
|
| 784 | + } |
|
| 785 | 785 | |
| 786 | 786 | |
| 787 | - /** |
|
| 787 | + /** |
|
| 788 | 788 | * Create a new database |
| 789 | 789 | * Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated |
| 790 | 790 | * We force to create database with charset this->forcecharset and collate this->forcecollate |
| 791 | - * |
|
| 791 | + * |
|
| 792 | 792 | * @param string $database Database name to create |
| 793 | 793 | * @param string $charset Charset used to store data |
| 794 | 794 | * @param string $collation Charset used to sort data |
| 795 | 795 | * @param string $owner Username of database owner |
| 796 | 796 | * @return SQLite3Result resource defined if OK, null if KO |
| 797 | - */ |
|
| 798 | - function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
| 799 | - { |
|
| 800 | - if (empty($charset)) $charset=$this->forcecharset; |
|
| 801 | - if (empty($collation)) $collation=$this->forcecollate; |
|
| 802 | - |
|
| 803 | - // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
|
| 804 | - $sql = 'CREATE DATABASE '.$database; |
|
| 805 | - $sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation; |
|
| 806 | - |
|
| 807 | - dol_syslog($sql,LOG_DEBUG); |
|
| 808 | - $ret=$this->query($sql); |
|
| 809 | - if (! $ret) |
|
| 810 | - { |
|
| 811 | - // We try again for compatibility with Mysql < 4.1.1 |
|
| 812 | - $sql = 'CREATE DATABASE '.$database; |
|
| 813 | - $ret=$this->query($sql); |
|
| 814 | - dol_syslog($sql,LOG_DEBUG); |
|
| 815 | - } |
|
| 816 | - return $ret; |
|
| 817 | - } |
|
| 797 | + */ |
|
| 798 | + function DDLCreateDb($database,$charset='',$collation='',$owner='') |
|
| 799 | + { |
|
| 800 | + if (empty($charset)) $charset=$this->forcecharset; |
|
| 801 | + if (empty($collation)) $collation=$this->forcecollate; |
|
| 802 | + |
|
| 803 | + // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
|
| 804 | + $sql = 'CREATE DATABASE '.$database; |
|
| 805 | + $sql.= ' DEFAULT CHARACTER SET '.$charset.' DEFAULT COLLATE '.$collation; |
|
| 806 | + |
|
| 807 | + dol_syslog($sql,LOG_DEBUG); |
|
| 808 | + $ret=$this->query($sql); |
|
| 809 | + if (! $ret) |
|
| 810 | + { |
|
| 811 | + // We try again for compatibility with Mysql < 4.1.1 |
|
| 812 | + $sql = 'CREATE DATABASE '.$database; |
|
| 813 | + $ret=$this->query($sql); |
|
| 814 | + dol_syslog($sql,LOG_DEBUG); |
|
| 815 | + } |
|
| 816 | + return $ret; |
|
| 817 | + } |
|
| 818 | 818 | |
| 819 | - /** |
|
| 820 | - * List tables into a database |
|
| 821 | - * |
|
| 819 | + /** |
|
| 820 | + * List tables into a database |
|
| 821 | + * |
|
| 822 | 822 | * @param string $database Name of database |
| 823 | 823 | * @param string $table Name of table filter ('xxx%') |
| 824 | 824 | * @return array List of tables in an array |
| 825 | - */ |
|
| 826 | - function DDLListTables($database, $table='') |
|
| 827 | - { |
|
| 828 | - $listtables=array(); |
|
| 829 | - |
|
| 830 | - $like = ''; |
|
| 831 | - if ($table) $like = "LIKE '".$table."'"; |
|
| 832 | - $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
| 833 | - //print $sql; |
|
| 834 | - $result = $this->query($sql); |
|
| 835 | - if ($result) |
|
| 836 | - { |
|
| 837 | - while($row = $this->fetch_row($result)) |
|
| 838 | - { |
|
| 839 | - $listtables[] = $row[0]; |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - return $listtables; |
|
| 843 | - } |
|
| 825 | + */ |
|
| 826 | + function DDLListTables($database, $table='') |
|
| 827 | + { |
|
| 828 | + $listtables=array(); |
|
| 829 | + |
|
| 830 | + $like = ''; |
|
| 831 | + if ($table) $like = "LIKE '".$table."'"; |
|
| 832 | + $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
|
| 833 | + //print $sql; |
|
| 834 | + $result = $this->query($sql); |
|
| 835 | + if ($result) |
|
| 836 | + { |
|
| 837 | + while($row = $this->fetch_row($result)) |
|
| 838 | + { |
|
| 839 | + $listtables[] = $row[0]; |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + return $listtables; |
|
| 843 | + } |
|
| 844 | 844 | |
| 845 | - /** |
|
| 845 | + /** |
|
| 846 | 846 | * List information of columns into a table. |
| 847 | - * |
|
| 847 | + * |
|
| 848 | 848 | * @param string $table Name of table |
| 849 | 849 | * @return array Tableau des informations des champs de la table |
| 850 | 850 | * TODO modify for sqlite |
| 851 | - */ |
|
| 852 | - function DDLInfoTable($table) |
|
| 853 | - { |
|
| 854 | - $infotables=array(); |
|
| 855 | - |
|
| 856 | - $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
| 857 | - |
|
| 858 | - dol_syslog($sql,LOG_DEBUG); |
|
| 859 | - $result = $this->query($sql); |
|
| 860 | - if ($result) |
|
| 861 | - { |
|
| 862 | - while($row = $this->fetch_row($result)) |
|
| 863 | - { |
|
| 864 | - $infotables[] = $row; |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - return $infotables; |
|
| 868 | - } |
|
| 851 | + */ |
|
| 852 | + function DDLInfoTable($table) |
|
| 853 | + { |
|
| 854 | + $infotables=array(); |
|
| 855 | + |
|
| 856 | + $sql="SHOW FULL COLUMNS FROM ".$table.";"; |
|
| 857 | + |
|
| 858 | + dol_syslog($sql,LOG_DEBUG); |
|
| 859 | + $result = $this->query($sql); |
|
| 860 | + if ($result) |
|
| 861 | + { |
|
| 862 | + while($row = $this->fetch_row($result)) |
|
| 863 | + { |
|
| 864 | + $infotables[] = $row; |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + return $infotables; |
|
| 868 | + } |
|
| 869 | 869 | |
| 870 | - /** |
|
| 870 | + /** |
|
| 871 | 871 | * Create a table into database |
| 872 | - * |
|
| 872 | + * |
|
| 873 | 873 | * @param string $table Nom de la table |
| 874 | 874 | * @param array $fields Tableau associatif [nom champ][tableau des descriptions] |
| 875 | 875 | * @param string $primary_key Nom du champ qui sera la clef primaire |
@@ -878,367 +878,367 @@ discard block |
||
| 878 | 878 | * @param array $fulltext_keys Tableau des Nom de champs qui seront indexes en fulltext |
| 879 | 879 | * @param array $keys Tableau des champs cles noms => valeur |
| 880 | 880 | * @return int <0 if KO, >=0 if OK |
| 881 | - */ |
|
| 882 | - function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
| 883 | - { |
|
| 884 | - // FIXME: $fulltext_keys parameter is unused |
|
| 885 | - |
|
| 886 | - // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
|
| 887 | - // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
| 888 | - $sql = "create table ".$table."("; |
|
| 889 | - $i=0; |
|
| 890 | - foreach($fields as $field_name => $field_desc) |
|
| 891 | - { |
|
| 892 | - $sqlfields[$i] = $field_name." "; |
|
| 893 | - $sqlfields[$i] .= $field_desc['type']; |
|
| 894 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 895 | - $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
| 896 | - else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 897 | - $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
| 898 | - else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 899 | - { |
|
| 900 | - if(preg_match("/null/i",$field_desc['default'])) |
|
| 901 | - $sqlfields[$i] .= " default ".$field_desc['default']; |
|
| 902 | - else |
|
| 903 | - $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
| 904 | - } |
|
| 905 | - else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 906 | - $sqlfields[$i] .= " ".$field_desc['null']; |
|
| 907 | - |
|
| 908 | - else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 909 | - $sqlfields[$i] .= " ".$field_desc['extra']; |
|
| 910 | - $i++; |
|
| 911 | - } |
|
| 912 | - if($primary_key != "") |
|
| 913 | - $pk = "primary key(".$primary_key.")"; |
|
| 881 | + */ |
|
| 882 | + function DDLCreateTable($table,$fields,$primary_key,$type,$unique_keys=null,$fulltext_keys=null,$keys=null) |
|
| 883 | + { |
|
| 884 | + // FIXME: $fulltext_keys parameter is unused |
|
| 885 | + |
|
| 886 | + // cles recherchees dans le tableau des descriptions (fields) : type,value,attribute,null,default,extra |
|
| 887 | + // ex. : $fields['rowid'] = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
|
| 888 | + $sql = "create table ".$table."("; |
|
| 889 | + $i=0; |
|
| 890 | + foreach($fields as $field_name => $field_desc) |
|
| 891 | + { |
|
| 892 | + $sqlfields[$i] = $field_name." "; |
|
| 893 | + $sqlfields[$i] .= $field_desc['type']; |
|
| 894 | + if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 895 | + $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
| 896 | + else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 897 | + $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
| 898 | + else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 899 | + { |
|
| 900 | + if(preg_match("/null/i",$field_desc['default'])) |
|
| 901 | + $sqlfields[$i] .= " default ".$field_desc['default']; |
|
| 902 | + else |
|
| 903 | + $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
| 904 | + } |
|
| 905 | + else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 906 | + $sqlfields[$i] .= " ".$field_desc['null']; |
|
| 907 | + |
|
| 908 | + else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 909 | + $sqlfields[$i] .= " ".$field_desc['extra']; |
|
| 910 | + $i++; |
|
| 911 | + } |
|
| 912 | + if($primary_key != "") |
|
| 913 | + $pk = "primary key(".$primary_key.")"; |
|
| 914 | + |
|
| 915 | + if(is_array($unique_keys)) |
|
| 916 | + { |
|
| 917 | + $i = 0; |
|
| 918 | + foreach($unique_keys as $key => $value) |
|
| 919 | + { |
|
| 920 | + $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
|
| 921 | + $i++; |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + if(is_array($keys)) |
|
| 925 | + { |
|
| 926 | + $i = 0; |
|
| 927 | + foreach($keys as $key => $value) |
|
| 928 | + { |
|
| 929 | + $sqlk[$i] = "KEY ".$key." (".$value.")"; |
|
| 930 | + $i++; |
|
| 931 | + } |
|
| 932 | + } |
|
| 933 | + $sql .= implode(',',$sqlfields); |
|
| 934 | + if($primary_key != "") |
|
| 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)) |
|
| 944 | + return -1; |
|
| 945 | + return 1; |
|
| 946 | + } |
|
| 914 | 947 | |
| 915 | - if(is_array($unique_keys)) |
|
| 916 | - { |
|
| 917 | - $i = 0; |
|
| 918 | - foreach($unique_keys as $key => $value) |
|
| 919 | - { |
|
| 920 | - $sqluq[$i] = "UNIQUE KEY '".$key."' ('".$value."')"; |
|
| 921 | - $i++; |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - if(is_array($keys)) |
|
| 925 | - { |
|
| 926 | - $i = 0; |
|
| 927 | - foreach($keys as $key => $value) |
|
| 928 | - { |
|
| 929 | - $sqlk[$i] = "KEY ".$key." (".$value.")"; |
|
| 930 | - $i++; |
|
| 931 | - } |
|
| 932 | - } |
|
| 933 | - $sql .= implode(',',$sqlfields); |
|
| 934 | - if($primary_key != "") |
|
| 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)) |
|
| 944 | - return -1; |
|
| 945 | - return 1; |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - /** |
|
| 948 | + /** |
|
| 949 | 949 | * Return a pointer of line with description of a table or field |
| 950 | - * |
|
| 950 | + * |
|
| 951 | 951 | * @param string $table Name of table |
| 952 | 952 | * @param string $field Optionnel : Name of field if we want description of field |
| 953 | 953 | * @return SQLite3Result Resource |
| 954 | - */ |
|
| 955 | - function DDLDescTable($table,$field="") |
|
| 956 | - { |
|
| 957 | - $sql="DESC ".$table." ".$field; |
|
| 954 | + */ |
|
| 955 | + function DDLDescTable($table,$field="") |
|
| 956 | + { |
|
| 957 | + $sql="DESC ".$table." ".$field; |
|
| 958 | 958 | |
| 959 | - dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
| 960 | - $this->_results = $this->query($sql); |
|
| 961 | - return $this->_results; |
|
| 962 | - } |
|
| 959 | + dol_syslog(get_class($this)."::DDLDescTable ".$sql,LOG_DEBUG); |
|
| 960 | + $this->_results = $this->query($sql); |
|
| 961 | + return $this->_results; |
|
| 962 | + } |
|
| 963 | 963 | |
| 964 | - /** |
|
| 964 | + /** |
|
| 965 | 965 | * Create a new field into table |
| 966 | - * |
|
| 966 | + * |
|
| 967 | 967 | * @param string $table Name of table |
| 968 | 968 | * @param string $field_name Name of field to add |
| 969 | 969 | * @param string $field_desc Tableau associatif de description du champ a inserer[nom du parametre][valeur du parametre] |
| 970 | 970 | * @param string $field_position Optionnel ex.: "after champtruc" |
| 971 | 971 | * @return int <0 if KO, >0 if OK |
| 972 | - */ |
|
| 973 | - function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
| 974 | - { |
|
| 975 | - // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
|
| 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'))) |
|
| 981 | - { |
|
| 982 | - $sql.= "(".$field_desc['value'].")"; |
|
| 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'])) |
|
| 989 | - { |
|
| 990 | - if(preg_match("/null/i",$field_desc['default'])) |
|
| 991 | - $sql.= " default ".$field_desc['default']; |
|
| 992 | - else |
|
| 993 | - $sql.= " default '".$field_desc['default']."'"; |
|
| 994 | - } |
|
| 995 | - if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 996 | - $sql.= " ".$field_desc['extra']; |
|
| 997 | - $sql.= " ".$field_position; |
|
| 998 | - |
|
| 999 | - dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
| 1000 | - if(! $this->query($sql)) |
|
| 1001 | - { |
|
| 1002 | - return -1; |
|
| 1003 | - } |
|
| 1004 | - return 1; |
|
| 1005 | - } |
|
| 972 | + */ |
|
| 973 | + function DDLAddField($table,$field_name,$field_desc,$field_position="") |
|
| 974 | + { |
|
| 975 | + // cles recherchees dans le tableau des descriptions (field_desc) : type,value,attribute,null,default,extra |
|
| 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'))) |
|
| 981 | + { |
|
| 982 | + $sql.= "(".$field_desc['value'].")"; |
|
| 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'])) |
|
| 989 | + { |
|
| 990 | + if(preg_match("/null/i",$field_desc['default'])) |
|
| 991 | + $sql.= " default ".$field_desc['default']; |
|
| 992 | + else |
|
| 993 | + $sql.= " default '".$field_desc['default']."'"; |
|
| 994 | + } |
|
| 995 | + if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 996 | + $sql.= " ".$field_desc['extra']; |
|
| 997 | + $sql.= " ".$field_position; |
|
| 998 | + |
|
| 999 | + dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
|
| 1000 | + if(! $this->query($sql)) |
|
| 1001 | + { |
|
| 1002 | + return -1; |
|
| 1003 | + } |
|
| 1004 | + return 1; |
|
| 1005 | + } |
|
| 1006 | 1006 | |
| 1007 | - /** |
|
| 1007 | + /** |
|
| 1008 | 1008 | * Update format of a field into a table |
| 1009 | - * |
|
| 1009 | + * |
|
| 1010 | 1010 | * @param string $table Name of table |
| 1011 | 1011 | * @param string $field_name Name of field to modify |
| 1012 | 1012 | * @param string $field_desc Array with description of field format |
| 1013 | 1013 | * @return int <0 if KO, >0 if OK |
| 1014 | - */ |
|
| 1015 | - function DDLUpdateField($table,$field_name,$field_desc) |
|
| 1016 | - { |
|
| 1017 | - $sql = "ALTER TABLE ".$table; |
|
| 1018 | - $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
|
| 1019 | - if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
|
| 1020 | - $sql.="(".$field_desc['value'].")"; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
| 1024 | - if (! $this->query($sql)) |
|
| 1025 | - return -1; |
|
| 1026 | - return 1; |
|
| 1027 | - } |
|
| 1014 | + */ |
|
| 1015 | + function DDLUpdateField($table,$field_name,$field_desc) |
|
| 1016 | + { |
|
| 1017 | + $sql = "ALTER TABLE ".$table; |
|
| 1018 | + $sql .= " MODIFY COLUMN ".$field_name." ".$field_desc['type']; |
|
| 1019 | + if ($field_desc['type'] == 'tinyint' || $field_desc['type'] == 'int' || $field_desc['type'] == 'varchar') { |
|
| 1020 | + $sql.="(".$field_desc['value'].")"; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
|
| 1024 | + if (! $this->query($sql)) |
|
| 1025 | + return -1; |
|
| 1026 | + return 1; |
|
| 1027 | + } |
|
| 1028 | 1028 | |
| 1029 | - /** |
|
| 1029 | + /** |
|
| 1030 | 1030 | * Drop a field from table |
| 1031 | - * |
|
| 1031 | + * |
|
| 1032 | 1032 | * @param string $table Name of table |
| 1033 | 1033 | * @param string $field_name Name of field to drop |
| 1034 | 1034 | * @return int <0 if KO, >0 if OK |
| 1035 | - */ |
|
| 1036 | - function DDLDropField($table,$field_name) |
|
| 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)) |
|
| 1041 | - { |
|
| 1042 | - $this->error=$this->lasterror(); |
|
| 1043 | - return -1; |
|
| 1044 | - } |
|
| 1045 | - return 1; |
|
| 1046 | - } |
|
| 1035 | + */ |
|
| 1036 | + function DDLDropField($table,$field_name) |
|
| 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)) |
|
| 1041 | + { |
|
| 1042 | + $this->error=$this->lasterror(); |
|
| 1043 | + return -1; |
|
| 1044 | + } |
|
| 1045 | + return 1; |
|
| 1046 | + } |
|
| 1047 | 1047 | |
| 1048 | 1048 | |
| 1049 | - /** |
|
| 1049 | + /** |
|
| 1050 | 1050 | * Create a user and privileges to connect to database (even if database does not exists yet) |
| 1051 | - * |
|
| 1051 | + * |
|
| 1052 | 1052 | * @param string $dolibarr_main_db_host Ip serveur |
| 1053 | 1053 | * @param string $dolibarr_main_db_user Nom user a creer |
| 1054 | 1054 | * @param string $dolibarr_main_db_pass Mot de passe user a creer |
| 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 | - */ |
|
| 1058 | - function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
| 1059 | - { |
|
| 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')"; |
|
| 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) |
|
| 1068 | - { |
|
| 1069 | - return -1; |
|
| 1070 | - } |
|
| 1071 | - |
|
| 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')"; |
|
| 1076 | - |
|
| 1077 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
| 1078 | - $resql=$this->query($sql); |
|
| 1079 | - if (! $resql) |
|
| 1080 | - { |
|
| 1081 | - return -1; |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - $sql="FLUSH Privileges"; |
|
| 1085 | - |
|
| 1086 | - dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
| 1087 | - $resql=$this->query($sql); |
|
| 1088 | - if (! $resql) |
|
| 1089 | - { |
|
| 1090 | - return -1; |
|
| 1091 | - } |
|
| 1092 | - return 1; |
|
| 1093 | - } |
|
| 1057 | + */ |
|
| 1058 | + function DDLCreateUser($dolibarr_main_db_host,$dolibarr_main_db_user,$dolibarr_main_db_pass,$dolibarr_main_db_name) |
|
| 1059 | + { |
|
| 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')"; |
|
| 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) |
|
| 1068 | + { |
|
| 1069 | + return -1; |
|
| 1070 | + } |
|
| 1071 | + |
|
| 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')"; |
|
| 1076 | + |
|
| 1077 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
| 1078 | + $resql=$this->query($sql); |
|
| 1079 | + if (! $resql) |
|
| 1080 | + { |
|
| 1081 | + return -1; |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + $sql="FLUSH Privileges"; |
|
| 1085 | + |
|
| 1086 | + dol_syslog(get_class($this)."::DDLCreateUser", LOG_DEBUG); |
|
| 1087 | + $resql=$this->query($sql); |
|
| 1088 | + if (! $resql) |
|
| 1089 | + { |
|
| 1090 | + return -1; |
|
| 1091 | + } |
|
| 1092 | + return 1; |
|
| 1093 | + } |
|
| 1094 | 1094 | |
| 1095 | - /** |
|
| 1095 | + /** |
|
| 1096 | 1096 | * Return charset used to store data in database |
| 1097 | - * |
|
| 1097 | + * |
|
| 1098 | 1098 | * @return string Charset |
| 1099 | - */ |
|
| 1100 | - function getDefaultCharacterSetDatabase() |
|
| 1101 | - { |
|
| 1102 | - return 'UTF-8'; |
|
| 1103 | - } |
|
| 1099 | + */ |
|
| 1100 | + function getDefaultCharacterSetDatabase() |
|
| 1101 | + { |
|
| 1102 | + return 'UTF-8'; |
|
| 1103 | + } |
|
| 1104 | 1104 | |
| 1105 | - /** |
|
| 1105 | + /** |
|
| 1106 | 1106 | * Return list of available charset that can be used to store data in database |
| 1107 | - * |
|
| 1107 | + * |
|
| 1108 | 1108 | * @return array List of Charset |
| 1109 | - */ |
|
| 1110 | - function getListOfCharacterSet() |
|
| 1111 | - { |
|
| 1112 | - $liste = array(); |
|
| 1113 | - $i=0; |
|
| 1114 | - $liste[$i]['charset'] = 'UTF-8'; |
|
| 1115 | - $liste[$i]['description'] = 'UTF-8'; |
|
| 1116 | - return $liste; |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - /** |
|
| 1109 | + */ |
|
| 1110 | + function getListOfCharacterSet() |
|
| 1111 | + { |
|
| 1112 | + $liste = array(); |
|
| 1113 | + $i=0; |
|
| 1114 | + $liste[$i]['charset'] = 'UTF-8'; |
|
| 1115 | + $liste[$i]['description'] = 'UTF-8'; |
|
| 1116 | + return $liste; |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + /** |
|
| 1120 | 1120 | * Return collation used in database |
| 1121 | - * |
|
| 1121 | + * |
|
| 1122 | 1122 | * @return string Collation value |
| 1123 | - */ |
|
| 1124 | - function getDefaultCollationDatabase() |
|
| 1125 | - { |
|
| 1126 | - return 'UTF-8'; |
|
| 1127 | - } |
|
| 1123 | + */ |
|
| 1124 | + function getDefaultCollationDatabase() |
|
| 1125 | + { |
|
| 1126 | + return 'UTF-8'; |
|
| 1127 | + } |
|
| 1128 | 1128 | |
| 1129 | - /** |
|
| 1129 | + /** |
|
| 1130 | 1130 | * Return list of available collation that can be used for database |
| 1131 | - * |
|
| 1131 | + * |
|
| 1132 | 1132 | * @return array List of Collation |
| 1133 | - */ |
|
| 1134 | - function getListOfCollation() |
|
| 1135 | - { |
|
| 1136 | - $liste = array(); |
|
| 1137 | - $i=0; |
|
| 1138 | - $liste[$i]['charset'] = 'UTF-8'; |
|
| 1139 | - $liste[$i]['description'] = 'UTF-8'; |
|
| 1140 | - return $liste; |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - /** |
|
| 1133 | + */ |
|
| 1134 | + function getListOfCollation() |
|
| 1135 | + { |
|
| 1136 | + $liste = array(); |
|
| 1137 | + $i=0; |
|
| 1138 | + $liste[$i]['charset'] = 'UTF-8'; |
|
| 1139 | + $liste[$i]['description'] = 'UTF-8'; |
|
| 1140 | + return $liste; |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + /** |
|
| 1144 | 1144 | * Return full path of dump program |
| 1145 | - * |
|
| 1145 | + * |
|
| 1146 | 1146 | * @return string Full path of dump program |
| 1147 | - */ |
|
| 1148 | - function getPathOfDump() |
|
| 1149 | - { |
|
| 1150 | - // FIXME: not for SQLite |
|
| 1151 | - $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
| 1152 | - |
|
| 1153 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
| 1154 | - if ($resql) |
|
| 1155 | - { |
|
| 1156 | - $liste=$this->fetch_array($resql); |
|
| 1157 | - $basedir=$liste['Value']; |
|
| 1158 | - $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
| 1159 | - } |
|
| 1160 | - return $fullpathofdump; |
|
| 1161 | - } |
|
| 1147 | + */ |
|
| 1148 | + function getPathOfDump() |
|
| 1149 | + { |
|
| 1150 | + // FIXME: not for SQLite |
|
| 1151 | + $fullpathofdump='/pathtomysqldump/mysqldump'; |
|
| 1152 | + |
|
| 1153 | + $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
| 1154 | + if ($resql) |
|
| 1155 | + { |
|
| 1156 | + $liste=$this->fetch_array($resql); |
|
| 1157 | + $basedir=$liste['Value']; |
|
| 1158 | + $fullpathofdump=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysqldump'; |
|
| 1159 | + } |
|
| 1160 | + return $fullpathofdump; |
|
| 1161 | + } |
|
| 1162 | 1162 | |
| 1163 | - /** |
|
| 1163 | + /** |
|
| 1164 | 1164 | * Return full path of restore program |
| 1165 | - * |
|
| 1165 | + * |
|
| 1166 | 1166 | * @return string Full path of restore program |
| 1167 | - */ |
|
| 1168 | - function getPathOfRestore() |
|
| 1169 | - { |
|
| 1170 | - // FIXME: not for SQLite |
|
| 1171 | - $fullpathofimport='/pathtomysql/mysql'; |
|
| 1172 | - |
|
| 1173 | - $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
| 1174 | - if ($resql) |
|
| 1175 | - { |
|
| 1176 | - $liste=$this->fetch_array($resql); |
|
| 1177 | - $basedir=$liste['Value']; |
|
| 1178 | - $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
| 1179 | - } |
|
| 1180 | - return $fullpathofimport; |
|
| 1181 | - } |
|
| 1167 | + */ |
|
| 1168 | + function getPathOfRestore() |
|
| 1169 | + { |
|
| 1170 | + // FIXME: not for SQLite |
|
| 1171 | + $fullpathofimport='/pathtomysql/mysql'; |
|
| 1172 | + |
|
| 1173 | + $resql=$this->query('SHOW VARIABLES LIKE \'basedir\''); |
|
| 1174 | + if ($resql) |
|
| 1175 | + { |
|
| 1176 | + $liste=$this->fetch_array($resql); |
|
| 1177 | + $basedir=$liste['Value']; |
|
| 1178 | + $fullpathofimport=$basedir.(preg_match('/\/$/',$basedir)?'':'/').'bin/mysql'; |
|
| 1179 | + } |
|
| 1180 | + return $fullpathofimport; |
|
| 1181 | + } |
|
| 1182 | 1182 | |
| 1183 | - /** |
|
| 1184 | - * Return value of server parameters |
|
| 1185 | - * |
|
| 1183 | + /** |
|
| 1184 | + * Return value of server parameters |
|
| 1185 | + * |
|
| 1186 | 1186 | * @param string $filter Filter list on a particular value |
| 1187 | 1187 | * @return array Array of key-values (key=>value) |
| 1188 | - */ |
|
| 1189 | - function getServerParametersValues($filter='') |
|
| 1190 | - { |
|
| 1191 | - $result=array(); |
|
| 1192 | - static $pragmas; |
|
| 1193 | - if (! isset($pragmas)) { |
|
| 1194 | - // Définition de la liste des pragmas utilisés qui ne retournent qu'une seule valeur |
|
| 1195 | - // indépendante de la base de données. |
|
| 1196 | - // cf. http://www.sqlite.org/pragma.html |
|
| 1197 | - $pragmas = array( |
|
| 1198 | - 'application_id', 'auto_vacuum', 'automatic_index', 'busy_timeout', 'cache_size', |
|
| 1199 | - 'cache_spill', 'case_sensitive_like', 'checkpoint_fullsync', 'collation_list', |
|
| 1188 | + */ |
|
| 1189 | + function getServerParametersValues($filter='') |
|
| 1190 | + { |
|
| 1191 | + $result=array(); |
|
| 1192 | + static $pragmas; |
|
| 1193 | + if (! isset($pragmas)) { |
|
| 1194 | + // Définition de la liste des pragmas utilisés qui ne retournent qu'une seule valeur |
|
| 1195 | + // indépendante de la base de données. |
|
| 1196 | + // cf. http://www.sqlite.org/pragma.html |
|
| 1197 | + $pragmas = array( |
|
| 1198 | + 'application_id', 'auto_vacuum', 'automatic_index', 'busy_timeout', 'cache_size', |
|
| 1199 | + 'cache_spill', 'case_sensitive_like', 'checkpoint_fullsync', 'collation_list', |
|
| 1200 | 1200 | 'compile_options', 'data_version', /*'database_list',*/ |
| 1201 | - 'defer_foreign_keys', 'encoding', 'foreign_key_check', 'freelist_count', |
|
| 1202 | - 'full_column_names', 'fullsync', 'ingore_check_constraints', 'integrity_check', |
|
| 1203 | - 'journal_mode', 'journal_size_limit', 'legacy_file_format', 'locking_mode', |
|
| 1204 | - 'max_page_count', 'page_count', 'page_size', 'parser_trace', |
|
| 1205 | - 'query_only', 'quick_check', 'read_uncommitted', 'recursive_triggers', |
|
| 1206 | - 'reverse_unordered_selects', 'schema_version', 'user_version', |
|
| 1207 | - 'secure_delete', 'short_column_names', 'shrink_memory', 'soft_heap_limit', |
|
| 1208 | - 'synchronous', 'temp_store', /*'temp_store_directory',*/ 'threads', |
|
| 1209 | - 'vdbe_addoptrace', 'vdbe_debug', 'vdbe_listing', 'vdbe_trace', |
|
| 1210 | - 'wal_autocheckpoint', |
|
| 1211 | - ); |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - // TODO prendre en compte le filtre |
|
| 1215 | - foreach($pragmas as $var) { |
|
| 1216 | - $sql = "PRAGMA $var"; |
|
| 1217 | - $resql=$this->query($sql); |
|
| 1218 | - if ($resql) |
|
| 1219 | - { |
|
| 1220 | - $obj = $this->fetch_row($resql); |
|
| 1221 | - //dol_syslog(get_class($this)."::select_db getServerParametersValues $var=". print_r($obj, true), LOG_DEBUG); |
|
| 1222 | - $result[$var] = $obj[0]; |
|
| 1223 | - } |
|
| 1224 | - else { |
|
| 1225 | - // TODO Récupérer le message |
|
| 1226 | - $result[$var] = 'FAIL'; |
|
| 1227 | - } |
|
| 1228 | - } |
|
| 1229 | - return $result; |
|
| 1230 | - } |
|
| 1201 | + 'defer_foreign_keys', 'encoding', 'foreign_key_check', 'freelist_count', |
|
| 1202 | + 'full_column_names', 'fullsync', 'ingore_check_constraints', 'integrity_check', |
|
| 1203 | + 'journal_mode', 'journal_size_limit', 'legacy_file_format', 'locking_mode', |
|
| 1204 | + 'max_page_count', 'page_count', 'page_size', 'parser_trace', |
|
| 1205 | + 'query_only', 'quick_check', 'read_uncommitted', 'recursive_triggers', |
|
| 1206 | + 'reverse_unordered_selects', 'schema_version', 'user_version', |
|
| 1207 | + 'secure_delete', 'short_column_names', 'shrink_memory', 'soft_heap_limit', |
|
| 1208 | + 'synchronous', 'temp_store', /*'temp_store_directory',*/ 'threads', |
|
| 1209 | + 'vdbe_addoptrace', 'vdbe_debug', 'vdbe_listing', 'vdbe_trace', |
|
| 1210 | + 'wal_autocheckpoint', |
|
| 1211 | + ); |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + // TODO prendre en compte le filtre |
|
| 1215 | + foreach($pragmas as $var) { |
|
| 1216 | + $sql = "PRAGMA $var"; |
|
| 1217 | + $resql=$this->query($sql); |
|
| 1218 | + if ($resql) |
|
| 1219 | + { |
|
| 1220 | + $obj = $this->fetch_row($resql); |
|
| 1221 | + //dol_syslog(get_class($this)."::select_db getServerParametersValues $var=". print_r($obj, true), LOG_DEBUG); |
|
| 1222 | + $result[$var] = $obj[0]; |
|
| 1223 | + } |
|
| 1224 | + else { |
|
| 1225 | + // TODO Récupérer le message |
|
| 1226 | + $result[$var] = 'FAIL'; |
|
| 1227 | + } |
|
| 1228 | + } |
|
| 1229 | + return $result; |
|
| 1230 | + } |
|
| 1231 | 1231 | |
| 1232 | - /** |
|
| 1233 | - * Return value of server status |
|
| 1234 | - * |
|
| 1232 | + /** |
|
| 1233 | + * Return value of server status |
|
| 1234 | + * |
|
| 1235 | 1235 | * @param string $filter Filter list on a particular value |
| 1236 | 1236 | * @return array Array of key-values (key=>value) |
| 1237 | - */ |
|
| 1238 | - function getServerStatusValues($filter='') |
|
| 1239 | - { |
|
| 1240 | - $result=array(); |
|
| 1241 | - /* |
|
| 1237 | + */ |
|
| 1238 | + function getServerStatusValues($filter='') |
|
| 1239 | + { |
|
| 1240 | + $result=array(); |
|
| 1241 | + /* |
|
| 1242 | 1242 | $sql='SHOW STATUS'; |
| 1243 | 1243 | if ($filter) $sql.=" LIKE '".$this->escape($filter)."'"; |
| 1244 | 1244 | $resql=$this->query($sql); |
@@ -1248,79 +1248,79 @@ discard block |
||
| 1248 | 1248 | } |
| 1249 | 1249 | */ |
| 1250 | 1250 | |
| 1251 | - return $result; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Permet le chargement d'une fonction personnalisee dans le moteur de base de donnees. |
|
| 1256 | - * Note: le nom de la fonction personnalisee est prefixee par 'db'. La fonction doit être |
|
| 1257 | - * statique et publique. Le nombre de parametres est determine automatiquement. |
|
| 1258 | - * |
|
| 1259 | - * @param string $name Le nom de la fonction a definir dans Sqlite |
|
| 1260 | - * @param int $arg_count Arg count |
|
| 1261 | - * @return void |
|
| 1262 | - */ |
|
| 1263 | - private function addCustomFunction($name, $arg_count = -1) |
|
| 1264 | - { |
|
| 1265 | - if ($this->db) |
|
| 1266 | - { |
|
| 1267 | - $newname=preg_replace('/_/','',$name); |
|
| 1268 | - $localname = __CLASS__ . '::' . 'db' . $newname; |
|
| 1269 | - $reflectClass = new ReflectionClass(__CLASS__); |
|
| 1270 | - $reflectFunction = $reflectClass->getMethod('db' . $newname); |
|
| 1271 | - if ($arg_count < 0) { |
|
| 1272 | - $arg_count = $reflectFunction->getNumberOfParameters(); |
|
| 1273 | - } |
|
| 1274 | - if (!$this->db->createFunction($name, $localname, $arg_count)) |
|
| 1275 | - { |
|
| 1276 | - $this->error = "unable to create custom function '$name'"; |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * calc_daynr |
|
| 1283 | - * |
|
| 1284 | - * @param int $year Year |
|
| 1285 | - * @param int $month Month |
|
| 1286 | - * @param int $day Day |
|
| 1287 | - * @return int Formatted date |
|
| 1288 | - */ |
|
| 1289 | - private static function calc_daynr($year, $month, $day) { |
|
| 1290 | - $y = $year; |
|
| 1291 | - if ($y == 0 && $month == 0) return 0; |
|
| 1292 | - $num = (365* $y + 31 * ($month - 1) + $day); |
|
| 1293 | - if ($month <= 2) { |
|
| 1294 | - $y--; } |
|
| 1295 | - else { |
|
| 1296 | - $num -= floor(($month * 4 + 23) / 10); |
|
| 1297 | - } |
|
| 1298 | - $temp = floor(($y / 100 + 1) * 3 / 4); |
|
| 1299 | - return $num + floor($y / 4) - $temp; |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - /** |
|
| 1303 | - * calc_weekday |
|
| 1304 | - * |
|
| 1305 | - * @param int $daynr ??? |
|
| 1306 | - * @param bool $sunday_first_day_of_week ??? |
|
| 1307 | - * @return int |
|
| 1308 | - */ |
|
| 1309 | - private static function calc_weekday($daynr, $sunday_first_day_of_week) { |
|
| 1310 | - $ret = floor(($daynr + 5 + ($sunday_first_day_of_week ? 1 : 0)) % 7); |
|
| 1311 | - return $ret; |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - /** |
|
| 1315 | - * calc_days_in_year |
|
| 1316 | - * |
|
| 1317 | - * @param string $year Year |
|
| 1318 | - * @return int Nb of days in year |
|
| 1319 | - */ |
|
| 1320 | - private static function calc_days_in_year($year) |
|
| 1321 | - { |
|
| 1322 | - return (($year & 3) == 0 && ($year%100 || ($year%400 == 0 && $year)) ? 366 : 365); |
|
| 1323 | - } |
|
| 1251 | + return $result; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Permet le chargement d'une fonction personnalisee dans le moteur de base de donnees. |
|
| 1256 | + * Note: le nom de la fonction personnalisee est prefixee par 'db'. La fonction doit être |
|
| 1257 | + * statique et publique. Le nombre de parametres est determine automatiquement. |
|
| 1258 | + * |
|
| 1259 | + * @param string $name Le nom de la fonction a definir dans Sqlite |
|
| 1260 | + * @param int $arg_count Arg count |
|
| 1261 | + * @return void |
|
| 1262 | + */ |
|
| 1263 | + private function addCustomFunction($name, $arg_count = -1) |
|
| 1264 | + { |
|
| 1265 | + if ($this->db) |
|
| 1266 | + { |
|
| 1267 | + $newname=preg_replace('/_/','',$name); |
|
| 1268 | + $localname = __CLASS__ . '::' . 'db' . $newname; |
|
| 1269 | + $reflectClass = new ReflectionClass(__CLASS__); |
|
| 1270 | + $reflectFunction = $reflectClass->getMethod('db' . $newname); |
|
| 1271 | + if ($arg_count < 0) { |
|
| 1272 | + $arg_count = $reflectFunction->getNumberOfParameters(); |
|
| 1273 | + } |
|
| 1274 | + if (!$this->db->createFunction($name, $localname, $arg_count)) |
|
| 1275 | + { |
|
| 1276 | + $this->error = "unable to create custom function '$name'"; |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * calc_daynr |
|
| 1283 | + * |
|
| 1284 | + * @param int $year Year |
|
| 1285 | + * @param int $month Month |
|
| 1286 | + * @param int $day Day |
|
| 1287 | + * @return int Formatted date |
|
| 1288 | + */ |
|
| 1289 | + private static function calc_daynr($year, $month, $day) { |
|
| 1290 | + $y = $year; |
|
| 1291 | + if ($y == 0 && $month == 0) return 0; |
|
| 1292 | + $num = (365* $y + 31 * ($month - 1) + $day); |
|
| 1293 | + if ($month <= 2) { |
|
| 1294 | + $y--; } |
|
| 1295 | + else { |
|
| 1296 | + $num -= floor(($month * 4 + 23) / 10); |
|
| 1297 | + } |
|
| 1298 | + $temp = floor(($y / 100 + 1) * 3 / 4); |
|
| 1299 | + return $num + floor($y / 4) - $temp; |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + /** |
|
| 1303 | + * calc_weekday |
|
| 1304 | + * |
|
| 1305 | + * @param int $daynr ??? |
|
| 1306 | + * @param bool $sunday_first_day_of_week ??? |
|
| 1307 | + * @return int |
|
| 1308 | + */ |
|
| 1309 | + private static function calc_weekday($daynr, $sunday_first_day_of_week) { |
|
| 1310 | + $ret = floor(($daynr + 5 + ($sunday_first_day_of_week ? 1 : 0)) % 7); |
|
| 1311 | + return $ret; |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + /** |
|
| 1315 | + * calc_days_in_year |
|
| 1316 | + * |
|
| 1317 | + * @param string $year Year |
|
| 1318 | + * @return int Nb of days in year |
|
| 1319 | + */ |
|
| 1320 | + private static function calc_days_in_year($year) |
|
| 1321 | + { |
|
| 1322 | + return (($year & 3) == 0 && ($year%100 || ($year%400 == 0 && $year)) ? 366 : 365); |
|
| 1323 | + } |
|
| 1324 | 1324 | |
| 1325 | 1325 | /** |
| 1326 | 1326 | * calc_week |
@@ -1332,44 +1332,44 @@ discard block |
||
| 1332 | 1332 | * @param string $calc_year ??? |
| 1333 | 1333 | * @return string ??? |
| 1334 | 1334 | */ |
| 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; |
|
| 1341 | - |
|
| 1342 | - $weekday=self::calc_weekday($first_daynr, !$monday_first); |
|
| 1343 | - $calc_year=$year; |
|
| 1344 | - |
|
| 1345 | - if ($month == 1 && $day <= 7-$weekday) |
|
| 1346 | - { |
|
| 1347 | - if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4))) |
|
| 1348 | - return 0; |
|
| 1349 | - $week_year= 1; |
|
| 1350 | - $calc_year--; |
|
| 1351 | - $first_daynr-= ($days=self::calc_days_in_year($calc_year)); |
|
| 1352 | - $weekday= ($weekday + 53*7- $days) % 7; |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - if (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)) { |
|
| 1356 | - $days= $daynr - ($first_daynr+ (7-$weekday)); |
|
| 1357 | - } |
|
| 1358 | - else { |
|
| 1359 | - $days= $daynr - ($first_daynr - $weekday); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - if ($week_year && $days >= 52*7) |
|
| 1363 | - { |
|
| 1364 | - $weekday= ($weekday + self::calc_days_in_year($calc_year)) % 7; |
|
| 1365 | - if ((!$first_weekday && $weekday < 4) || ($first_weekday && $weekday == 0)) |
|
| 1366 | - { |
|
| 1367 | - $calc_year++; |
|
| 1368 | - return 1; |
|
| 1369 | - } |
|
| 1370 | - } |
|
| 1371 | - return floor($days/7+1); |
|
| 1372 | - } |
|
| 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; |
|
| 1341 | + |
|
| 1342 | + $weekday=self::calc_weekday($first_daynr, !$monday_first); |
|
| 1343 | + $calc_year=$year; |
|
| 1344 | + |
|
| 1345 | + if ($month == 1 && $day <= 7-$weekday) |
|
| 1346 | + { |
|
| 1347 | + if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4))) |
|
| 1348 | + return 0; |
|
| 1349 | + $week_year= 1; |
|
| 1350 | + $calc_year--; |
|
| 1351 | + $first_daynr-= ($days=self::calc_days_in_year($calc_year)); |
|
| 1352 | + $weekday= ($weekday + 53*7- $days) % 7; |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + if (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)) { |
|
| 1356 | + $days= $daynr - ($first_daynr+ (7-$weekday)); |
|
| 1357 | + } |
|
| 1358 | + else { |
|
| 1359 | + $days= $daynr - ($first_daynr - $weekday); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + if ($week_year && $days >= 52*7) |
|
| 1363 | + { |
|
| 1364 | + $weekday= ($weekday + self::calc_days_in_year($calc_year)) % 7; |
|
| 1365 | + if ((!$first_weekday && $weekday < 4) || ($first_weekday && $weekday == 0)) |
|
| 1366 | + { |
|
| 1367 | + $calc_year++; |
|
| 1368 | + return 1; |
|
| 1369 | + } |
|
| 1370 | + } |
|
| 1371 | + return floor($days/7+1); |
|
| 1372 | + } |
|
| 1373 | 1373 | |
| 1374 | 1374 | } |
| 1375 | 1375 | |
@@ -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 | } |
@@ -62,8 +62,12 @@ discard block |
||
| 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)) { |
|
| 66 | + $this->forcecharset=$conf->db->character_set; |
|
| 67 | + } |
|
| 68 | + if (! empty($conf->db->dolibarr_main_db_collation)) { |
|
| 69 | + $this->forcecollate=$conf->db->dolibarr_main_db_collation; |
|
| 70 | + } |
|
| 67 | 71 | |
| 68 | 72 | $this->database_user=$user; |
| 69 | 73 | $this->database_host=$host; |
@@ -111,8 +115,7 @@ discard block |
||
| 111 | 115 | $this->addCustomFunction('WEEKDAY'); |
| 112 | 116 | $this->addCustomFunction('date_format'); |
| 113 | 117 | //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 114 | - } |
|
| 115 | - else |
|
| 118 | + } else |
|
| 116 | 119 | { |
| 117 | 120 | // host, login ou password incorrect |
| 118 | 121 | $this->connected = false; |
@@ -149,9 +152,13 @@ discard block |
||
| 149 | 152 | { |
| 150 | 153 | if ($type == 'auto') |
| 151 | 154 | { |
| 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 | + if (preg_match('/ALTER TABLE/i',$line)) { |
|
| 156 | + $type='dml'; |
|
| 157 | + } else if (preg_match('/CREATE TABLE/i',$line)) { |
|
| 158 | + $type='dml'; |
|
| 159 | + } else if (preg_match('/DROP TABLE/i',$line)) { |
|
| 160 | + $type='dml'; |
|
| 161 | + } |
|
| 155 | 162 | } |
| 156 | 163 | |
| 157 | 164 | if ($type == 'dml') |
@@ -272,9 +279,11 @@ discard block |
||
| 272 | 279 | // DELETE FROM tabletodelete USING tabletodelete, othertable -> DELETE FROM tabletodelete USING othertable |
| 273 | 280 | if (preg_match('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i',$line,$reg)) |
| 274 | 281 | { |
| 275 | - if ($reg[1] == $reg[2]) // If same table, we remove second one |
|
| 282 | + if ($reg[1] == $reg[2]) { |
|
| 283 | + // If same table, we remove second one |
|
| 276 | 284 | { |
| 277 | 285 | $line=preg_replace('/DELETE FROM ([a-z_]+) USING ([a-z_]+), ([a-z_]+)/i','DELETE FROM \\1 USING \\3', $line); |
| 286 | + } |
|
| 278 | 287 | } |
| 279 | 288 | } |
| 280 | 289 | |
@@ -329,7 +338,9 @@ discard block |
||
| 329 | 338 | dol_syslog(get_class($this)."::connect name=".$name,LOG_DEBUG); |
| 330 | 339 | |
| 331 | 340 | $dir=$main_data_dir; |
| 332 | - if (empty($dir)) $dir=DOL_DATA_ROOT; |
|
| 341 | + if (empty($dir)) { |
|
| 342 | + $dir=DOL_DATA_ROOT; |
|
| 343 | + } |
|
| 333 | 344 | // With sqlite, port must be in connect parameters |
| 334 | 345 | //if (! $newport) $newport=3306; |
| 335 | 346 | $database_name = $dir.'/database_'.$name.'.sdb'; |
@@ -338,8 +349,7 @@ discard block |
||
| 338 | 349 | //$this->db = new PDO("sqlite:".$dir.'/database_'.$name.'.sdb'); |
| 339 | 350 | $this->db = new SQLite3($database_name); |
| 340 | 351 | //$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 341 | - } |
|
| 342 | - catch(Exception $e) |
|
| 352 | + } catch(Exception $e) |
|
| 343 | 353 | { |
| 344 | 354 | $this->error= self::LABEL.' '.$e->getMessage().' current dir='.$database_name; |
| 345 | 355 | return ''; |
@@ -382,7 +392,9 @@ discard block |
||
| 382 | 392 | { |
| 383 | 393 | if ($this->db) |
| 384 | 394 | { |
| 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); |
|
| 395 | + if ($this->transaction_opened > 0) { |
|
| 396 | + dol_syslog(get_class($this)."::close Closing a connection with an opened transaction depth=".$this->transaction_opened,LOG_ERR); |
|
| 397 | + } |
|
| 386 | 398 | $this->connected=false; |
| 387 | 399 | $this->db->close(); |
| 388 | 400 | unset($this->db); // Clean this->db |
@@ -458,8 +470,7 @@ discard block |
||
| 458 | 470 | if ($ret) { |
| 459 | 471 | $ret->queryString = $query; |
| 460 | 472 | } |
| 461 | - } |
|
| 462 | - catch(Exception $e) |
|
| 473 | + } catch(Exception $e) |
|
| 463 | 474 | { |
| 464 | 475 | $this->error=$this->db->lastErrorMsg(); |
| 465 | 476 | } |
@@ -537,8 +548,7 @@ discard block |
||
| 537 | 548 | { |
| 538 | 549 | if (! is_object($resultset)) { $resultset=$this->_results; } |
| 539 | 550 | return $resultset->fetchArray(SQLITE3_NUM); |
| 540 | - } |
|
| 541 | - else |
|
| 551 | + } else |
|
| 542 | 552 | { |
| 543 | 553 | // si le curseur est un booleen on retourne la valeur 0 |
| 544 | 554 | return false; |
@@ -597,7 +607,9 @@ discard block |
||
| 597 | 607 | // If resultset not provided, we take the last used by connexion |
| 598 | 608 | if (! is_object($resultset)) { $resultset=$this->_results; } |
| 599 | 609 | // Si resultset en est un, on libere la memoire |
| 600 | - if ($resultset && is_object($resultset)) $resultset->finalize(); |
|
| 610 | + if ($resultset && is_object($resultset)) { |
|
| 611 | + $resultset->finalize(); |
|
| 612 | + } |
|
| 601 | 613 | } |
| 602 | 614 | |
| 603 | 615 | /** |
@@ -621,8 +633,7 @@ discard block |
||
| 621 | 633 | if (! $this->connected) { |
| 622 | 634 | // Si il y a eu echec de connexion, $this->db n'est pas valide. |
| 623 | 635 | return 'DB_ERROR_FAILED_TO_CONNECT'; |
| 624 | - } |
|
| 625 | - else { |
|
| 636 | + } else { |
|
| 626 | 637 | // Constants to convert error code to a generic Dolibarr error code |
| 627 | 638 | /*$errorcode_map = array( |
| 628 | 639 | 1004 => 'DB_ERROR_CANNOT_CREATE', |
@@ -659,14 +670,21 @@ discard block |
||
| 659 | 670 | $errno=$this->db->lastErrorCode(); |
| 660 | 671 | if ($errno=='HY000' || $errno == 0) |
| 661 | 672 | { |
| 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'; |
|
| 673 | + if (preg_match('/table.*already exists/i',$this->error)) { |
|
| 674 | + return 'DB_ERROR_TABLE_ALREADY_EXISTS'; |
|
| 675 | + } elseif (preg_match('/index.*already exists/i',$this->error)) { |
|
| 676 | + return 'DB_ERROR_KEY_NAME_ALREADY_EXISTS'; |
|
| 677 | + } elseif (preg_match('/syntax error/i',$this->error)) { |
|
| 678 | + return 'DB_ERROR_SYNTAX'; |
|
| 679 | + } |
|
| 665 | 680 | } |
| 666 | 681 | if ($errno=='23000') |
| 667 | 682 | { |
| 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'; |
|
| 683 | + if (preg_match('/column.* not unique/i',$this->error)) { |
|
| 684 | + return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
| 685 | + } elseif (preg_match('/PRIMARY KEY must be unique/i',$this->error)) { |
|
| 686 | + return 'DB_ERROR_RECORD_ALREADY_EXISTS'; |
|
| 687 | + } |
|
| 670 | 688 | } |
| 671 | 689 | if ($errno > 1) { |
| 672 | 690 | // TODO Voir la liste des messages d'erreur |
@@ -686,8 +704,7 @@ discard block |
||
| 686 | 704 | if (! $this->connected) { |
| 687 | 705 | // Si il y a eu echec de connexion, $this->db n'est pas valide pour sqlite_error. |
| 688 | 706 | return 'Not connected. Check setup parameters in conf/conf.php file and your sqlite version'; |
| 689 | - } |
|
| 690 | - else { |
|
| 707 | + } else { |
|
| 691 | 708 | return $this->error; |
| 692 | 709 | } |
| 693 | 710 | } |
@@ -729,8 +746,7 @@ discard block |
||
| 729 | 746 | if ($cryptType == 2) |
| 730 | 747 | { |
| 731 | 748 | $return = 'AES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
| 732 | - } |
|
| 733 | - else if ($cryptType == 1) |
|
| 749 | + } else if ($cryptType == 1) |
|
| 734 | 750 | { |
| 735 | 751 | $return = 'DES_ENCRYPT('.$return.',\''.$cryptKey.'\')'; |
| 736 | 752 | } |
@@ -762,8 +778,7 @@ discard block |
||
| 762 | 778 | if ($cryptType == 2) |
| 763 | 779 | { |
| 764 | 780 | $return = 'AES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
| 765 | - } |
|
| 766 | - else if ($cryptType == 1) |
|
| 781 | + } else if ($cryptType == 1) |
|
| 767 | 782 | { |
| 768 | 783 | $return = 'DES_DECRYPT('.$value.',\''.$cryptKey.'\')'; |
| 769 | 784 | } |
@@ -797,8 +812,12 @@ discard block |
||
| 797 | 812 | */ |
| 798 | 813 | function DDLCreateDb($database,$charset='',$collation='',$owner='') |
| 799 | 814 | { |
| 800 | - if (empty($charset)) $charset=$this->forcecharset; |
|
| 801 | - if (empty($collation)) $collation=$this->forcecollate; |
|
| 815 | + if (empty($charset)) { |
|
| 816 | + $charset=$this->forcecharset; |
|
| 817 | + } |
|
| 818 | + if (empty($collation)) { |
|
| 819 | + $collation=$this->forcecollate; |
|
| 820 | + } |
|
| 802 | 821 | |
| 803 | 822 | // ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci |
| 804 | 823 | $sql = 'CREATE DATABASE '.$database; |
@@ -828,7 +847,9 @@ discard block |
||
| 828 | 847 | $listtables=array(); |
| 829 | 848 | |
| 830 | 849 | $like = ''; |
| 831 | - if ($table) $like = "LIKE '".$table."'"; |
|
| 850 | + if ($table) { |
|
| 851 | + $like = "LIKE '".$table."'"; |
|
| 852 | + } |
|
| 832 | 853 | $sql="SHOW TABLES FROM ".$database." ".$like.";"; |
| 833 | 854 | //print $sql; |
| 834 | 855 | $result = $this->query($sql); |
@@ -891,26 +912,27 @@ discard block |
||
| 891 | 912 | { |
| 892 | 913 | $sqlfields[$i] = $field_name." "; |
| 893 | 914 | $sqlfields[$i] .= $field_desc['type']; |
| 894 | - if( preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 895 | - $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
| 896 | - else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) |
|
| 897 | - $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
| 898 | - else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 915 | + if( preg_match("/^[^\s]/i",$field_desc['value'])) { |
|
| 916 | + $sqlfields[$i] .= "(".$field_desc['value'].")"; |
|
| 917 | + } else if( preg_match("/^[^\s]/i",$field_desc['attribute'])) { |
|
| 918 | + $sqlfields[$i] .= " ".$field_desc['attribute']; |
|
| 919 | + } else if( preg_match("/^[^\s]/i",$field_desc['default'])) |
|
| 899 | 920 | { |
| 900 | - if(preg_match("/null/i",$field_desc['default'])) |
|
| 901 | - $sqlfields[$i] .= " default ".$field_desc['default']; |
|
| 902 | - else |
|
| 903 | - $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
| 921 | + if(preg_match("/null/i",$field_desc['default'])) { |
|
| 922 | + $sqlfields[$i] .= " default ".$field_desc['default']; |
|
| 923 | + } else { |
|
| 924 | + $sqlfields[$i] .= " default '".$field_desc['default']."'"; |
|
| 925 | + } |
|
| 926 | + } else if( preg_match("/^[^\s]/i",$field_desc['null'])) { |
|
| 927 | + $sqlfields[$i] .= " ".$field_desc['null']; |
|
| 928 | + } else if( preg_match("/^[^\s]/i",$field_desc['extra'])) { |
|
| 929 | + $sqlfields[$i] .= " ".$field_desc['extra']; |
|
| 904 | 930 | } |
| 905 | - else if( preg_match("/^[^\s]/i",$field_desc['null'])) |
|
| 906 | - $sqlfields[$i] .= " ".$field_desc['null']; |
|
| 907 | - |
|
| 908 | - else if( preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 909 | - $sqlfields[$i] .= " ".$field_desc['extra']; |
|
| 910 | 931 | $i++; |
| 911 | 932 | } |
| 912 | - if($primary_key != "") |
|
| 913 | - $pk = "primary key(".$primary_key.")"; |
|
| 933 | + if($primary_key != "") { |
|
| 934 | + $pk = "primary key(".$primary_key.")"; |
|
| 935 | + } |
|
| 914 | 936 | |
| 915 | 937 | if(is_array($unique_keys)) |
| 916 | 938 | { |
@@ -931,17 +953,21 @@ discard block |
||
| 931 | 953 | } |
| 932 | 954 | } |
| 933 | 955 | $sql .= implode(',',$sqlfields); |
| 934 | - if($primary_key != "") |
|
| 935 | - $sql .= ",".$pk; |
|
| 936 | - if(is_array($unique_keys)) |
|
| 937 | - $sql .= ",".implode(',',$sqluq); |
|
| 938 | - if(is_array($keys)) |
|
| 939 | - $sql .= ",".implode(',',$sqlk); |
|
| 956 | + if($primary_key != "") { |
|
| 957 | + $sql .= ",".$pk; |
|
| 958 | + } |
|
| 959 | + if(is_array($unique_keys)) { |
|
| 960 | + $sql .= ",".implode(',',$sqluq); |
|
| 961 | + } |
|
| 962 | + if(is_array($keys)) { |
|
| 963 | + $sql .= ",".implode(',',$sqlk); |
|
| 964 | + } |
|
| 940 | 965 | $sql .=") type=".$type; |
| 941 | 966 | |
| 942 | 967 | dol_syslog($sql,LOG_DEBUG); |
| 943 | - if(! $this -> query($sql)) |
|
| 944 | - return -1; |
|
| 968 | + if(! $this -> query($sql)) { |
|
| 969 | + return -1; |
|
| 970 | + } |
|
| 945 | 971 | return 1; |
| 946 | 972 | } |
| 947 | 973 | |
@@ -976,24 +1002,29 @@ discard block |
||
| 976 | 1002 | // ex. : $field_desc = array('type'=>'int','value'=>'11','null'=>'not null','extra'=> 'auto_increment'); |
| 977 | 1003 | $sql= "ALTER TABLE ".$table." ADD ".$field_name." "; |
| 978 | 1004 | $sql.= $field_desc['type']; |
| 979 | - if(preg_match("/^[^\s]/i",$field_desc['value'])) |
|
| 980 | - if (! in_array($field_desc['type'],array('date','datetime'))) |
|
| 1005 | + if(preg_match("/^[^\s]/i",$field_desc['value'])) { |
|
| 1006 | + if (! in_array($field_desc['type'],array('date','datetime'))) |
|
| 981 | 1007 | { |
| 982 | 1008 | $sql.= "(".$field_desc['value'].")"; |
| 983 | 1009 | } |
| 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']; |
|
| 1010 | + } |
|
| 1011 | + if(preg_match("/^[^\s]/i",$field_desc['attribute'])) { |
|
| 1012 | + $sql.= " ".$field_desc['attribute']; |
|
| 1013 | + } |
|
| 1014 | + if(preg_match("/^[^\s]/i",$field_desc['null'])) { |
|
| 1015 | + $sql.= " ".$field_desc['null']; |
|
| 1016 | + } |
|
| 988 | 1017 | if(preg_match("/^[^\s]/i",$field_desc['default'])) |
| 989 | 1018 | { |
| 990 | - if(preg_match("/null/i",$field_desc['default'])) |
|
| 991 | - $sql.= " default ".$field_desc['default']; |
|
| 992 | - else |
|
| 993 | - $sql.= " default '".$field_desc['default']."'"; |
|
| 1019 | + if(preg_match("/null/i",$field_desc['default'])) { |
|
| 1020 | + $sql.= " default ".$field_desc['default']; |
|
| 1021 | + } else { |
|
| 1022 | + $sql.= " default '".$field_desc['default']."'"; |
|
| 1023 | + } |
|
| 1024 | + } |
|
| 1025 | + if(preg_match("/^[^\s]/i",$field_desc['extra'])) { |
|
| 1026 | + $sql.= " ".$field_desc['extra']; |
|
| 994 | 1027 | } |
| 995 | - if(preg_match("/^[^\s]/i",$field_desc['extra'])) |
|
| 996 | - $sql.= " ".$field_desc['extra']; |
|
| 997 | 1028 | $sql.= " ".$field_position; |
| 998 | 1029 | |
| 999 | 1030 | dol_syslog(get_class($this)."::DDLAddField ".$sql,LOG_DEBUG); |
@@ -1021,8 +1052,9 @@ discard block |
||
| 1021 | 1052 | } |
| 1022 | 1053 | |
| 1023 | 1054 | dol_syslog(get_class($this)."::DDLUpdateField ".$sql,LOG_DEBUG); |
| 1024 | - if (! $this->query($sql)) |
|
| 1025 | - return -1; |
|
| 1055 | + if (! $this->query($sql)) { |
|
| 1056 | + return -1; |
|
| 1057 | + } |
|
| 1026 | 1058 | return 1; |
| 1027 | 1059 | } |
| 1028 | 1060 | |
@@ -1220,8 +1252,7 @@ discard block |
||
| 1220 | 1252 | $obj = $this->fetch_row($resql); |
| 1221 | 1253 | //dol_syslog(get_class($this)."::select_db getServerParametersValues $var=". print_r($obj, true), LOG_DEBUG); |
| 1222 | 1254 | $result[$var] = $obj[0]; |
| 1223 | - } |
|
| 1224 | - else { |
|
| 1255 | + } else { |
|
| 1225 | 1256 | // TODO Récupérer le message |
| 1226 | 1257 | $result[$var] = 'FAIL'; |
| 1227 | 1258 | } |
@@ -1288,11 +1319,12 @@ discard block |
||
| 1288 | 1319 | */ |
| 1289 | 1320 | private static function calc_daynr($year, $month, $day) { |
| 1290 | 1321 | $y = $year; |
| 1291 | - if ($y == 0 && $month == 0) return 0; |
|
| 1322 | + if ($y == 0 && $month == 0) { |
|
| 1323 | + return 0; |
|
| 1324 | + } |
|
| 1292 | 1325 | $num = (365* $y + 31 * ($month - 1) + $day); |
| 1293 | 1326 | if ($month <= 2) { |
| 1294 | - $y--; } |
|
| 1295 | - else { |
|
| 1327 | + $y--; } else { |
|
| 1296 | 1328 | $num -= floor(($month * 4 + 23) / 10); |
| 1297 | 1329 | } |
| 1298 | 1330 | $temp = floor(($y / 100 + 1) * 3 / 4); |
@@ -1344,8 +1376,9 @@ discard block |
||
| 1344 | 1376 | |
| 1345 | 1377 | if ($month == 1 && $day <= 7-$weekday) |
| 1346 | 1378 | { |
| 1347 | - if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4))) |
|
| 1348 | - return 0; |
|
| 1379 | + if (!$week_year && (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4))) { |
|
| 1380 | + return 0; |
|
| 1381 | + } |
|
| 1349 | 1382 | $week_year= 1; |
| 1350 | 1383 | $calc_year--; |
| 1351 | 1384 | $first_daynr-= ($days=self::calc_days_in_year($calc_year)); |
@@ -1354,8 +1387,7 @@ discard block |
||
| 1354 | 1387 | |
| 1355 | 1388 | if (($first_weekday && $weekday != 0) || (!$first_weekday && $weekday >= 4)) { |
| 1356 | 1389 | $days= $daynr - ($first_daynr+ (7-$weekday)); |
| 1357 | - } |
|
| 1358 | - else { |
|
| 1390 | + } else { |
|
| 1359 | 1391 | $days= $daynr - ($first_daynr - $weekday); |
| 1360 | 1392 | } |
| 1361 | 1393 | |
@@ -1213,7 +1213,7 @@ |
||
| 1213 | 1213 | |
| 1214 | 1214 | // TODO prendre en compte le filtre |
| 1215 | 1215 | foreach($pragmas as $var) { |
| 1216 | - $sql = "PRAGMA $var"; |
|
| 1216 | + $sql = "pragma $var"; |
|
| 1217 | 1217 | $resql=$this->query($sql); |
| 1218 | 1218 | if ($resql) |
| 1219 | 1219 | { |