@@ -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) |
@@ -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 | */ |
@@ -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 | { |
@@ -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 | { |
@@ -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 | { |
@@ -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 | { |
@@ -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 | { |
@@ -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; |
@@ -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 | { |
@@ -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); |
@@ -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 |