@@ -70,7 +70,9 @@ discard block |
||
| 70 | 70 | $sql = "SELECT id, code, libelle"; |
| 71 | 71 | $sql.= " FROM ".MAIN_DB_PREFIX."c_typent"; |
| 72 | 72 | $sql.= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id)?'0':$mysoc->country_id).")"; |
| 73 | - if ($filter) $sql.=" ".$filter; |
|
| 73 | + if ($filter) { |
|
| 74 | + $sql.=" ".$filter; |
|
| 75 | + } |
|
| 74 | 76 | $sql.= " ORDER by position, id"; |
| 75 | 77 | dol_syslog(get_class($this).'::typent_array', LOG_DEBUG); |
| 76 | 78 | $resql=$this->db->query($sql); |
@@ -82,11 +84,19 @@ discard block |
||
| 82 | 84 | while ($i < $num) |
| 83 | 85 | { |
| 84 | 86 | $objp = $this->db->fetch_object($resql); |
| 85 | - if (! $mode) $key=$objp->id; |
|
| 86 | - else $key=$objp->code; |
|
| 87 | - if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code); |
|
| 88 | - else $effs[$key] = $objp->libelle; |
|
| 89 | - if ($effs[$key]=='-') $effs[$key]=''; |
|
| 87 | + if (! $mode) { |
|
| 88 | + $key=$objp->id; |
|
| 89 | + } else { |
|
| 90 | + $key=$objp->code; |
|
| 91 | + } |
|
| 92 | + if ($langs->trans($objp->code) != $objp->code) { |
|
| 93 | + $effs[$key] = $langs->trans($objp->code); |
|
| 94 | + } else { |
|
| 95 | + $effs[$key] = $objp->libelle; |
|
| 96 | + } |
|
| 97 | + if ($effs[$key]=='-') { |
|
| 98 | + $effs[$key]=''; |
|
| 99 | + } |
|
| 90 | 100 | $i++; |
| 91 | 101 | } |
| 92 | 102 | $this->db->free($resql); |
@@ -111,7 +121,9 @@ discard block |
||
| 111 | 121 | $sql = "SELECT id, code, libelle"; |
| 112 | 122 | $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif"; |
| 113 | 123 | $sql.= " WHERE active = 1"; |
| 114 | - if ($filter) $sql.=" ".$filter; |
|
| 124 | + if ($filter) { |
|
| 125 | + $sql.=" ".$filter; |
|
| 126 | + } |
|
| 115 | 127 | $sql .= " ORDER BY id ASC"; |
| 116 | 128 | dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG); |
| 117 | 129 | $resql=$this->db->query($sql); |
@@ -123,8 +135,11 @@ discard block |
||
| 123 | 135 | while ($i < $num) |
| 124 | 136 | { |
| 125 | 137 | $objp = $this->db->fetch_object($resql); |
| 126 | - if (! $mode) $key=$objp->id; |
|
| 127 | - else $key=$objp->code; |
|
| 138 | + if (! $mode) { |
|
| 139 | + $key=$objp->id; |
|
| 140 | + } else { |
|
| 141 | + $key=$objp->code; |
|
| 142 | + } |
|
| 128 | 143 | |
| 129 | 144 | $effs[$key] = $objp->libelle!='-'?$objp->libelle:''; |
| 130 | 145 | $i++; |
@@ -179,9 +194,12 @@ discard block |
||
| 179 | 194 | } |
| 180 | 195 | |
| 181 | 196 | print Form::selectarray($htmlname, $options, $selected); |
| 197 | + } else { |
|
| 198 | + dol_print_error($this->db); |
|
| 199 | + } |
|
| 200 | + if (! empty($htmlname) && $user->admin) { |
|
| 201 | + print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 182 | 202 | } |
| 183 | - else dol_print_error($this->db); |
|
| 184 | - if (! empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 185 | 203 | print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; |
| 186 | 204 | print '</form>'; |
| 187 | 205 | } |
@@ -235,15 +253,23 @@ discard block |
||
| 235 | 253 | $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c"; |
| 236 | 254 | $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid"; |
| 237 | 255 | $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1"; |
| 238 | - if ($country_codeid && is_numeric($country_codeid)) $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'"; |
|
| 239 | - if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'"; |
|
| 256 | + if ($country_codeid && is_numeric($country_codeid)) { |
|
| 257 | + $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'"; |
|
| 258 | + } |
|
| 259 | + if ($country_codeid && ! is_numeric($country_codeid)) { |
|
| 260 | + $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'"; |
|
| 261 | + } |
|
| 240 | 262 | $sql .= " ORDER BY c.code, d.code_departement"; |
| 241 | 263 | |
| 242 | 264 | $result=$this->db->query($sql); |
| 243 | 265 | if ($result) |
| 244 | 266 | { |
| 245 | - if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">'; |
|
| 246 | - if ($country_codeid) $out.= '<option value="0"> </option>'; |
|
| 267 | + if (!empty($htmlname)) { |
|
| 268 | + $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">'; |
|
| 269 | + } |
|
| 270 | + if ($country_codeid) { |
|
| 271 | + $out.= '<option value="0"> </option>'; |
|
| 272 | + } |
|
| 247 | 273 | $num = $this->db->num_rows($result); |
| 248 | 274 | $i = 0; |
| 249 | 275 | dol_syslog(get_class($this)."::select_departement num=".$num,LOG_DEBUG); |
@@ -253,11 +279,12 @@ discard block |
||
| 253 | 279 | while ($i < $num) |
| 254 | 280 | { |
| 255 | 281 | $obj = $this->db->fetch_object($result); |
| 256 | - if ($obj->code == '0') // Le code peut etre une chaine |
|
| 282 | + if ($obj->code == '0') { |
|
| 283 | + // Le code peut etre une chaine |
|
| 257 | 284 | { |
| 258 | 285 | $out.= '<option value="0"> </option>'; |
| 259 | 286 | } |
| 260 | - else { |
|
| 287 | + } else { |
|
| 261 | 288 | if (! $country || $country != $obj->country) |
| 262 | 289 | { |
| 263 | 290 | // Affiche la rupture si on est en mode liste multipays |
@@ -272,8 +299,7 @@ discard block |
||
| 272 | 299 | || (empty($selected) && ! empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid)) |
| 273 | 300 | { |
| 274 | 301 | $out.= '<option value="'.$obj->rowid.'" selected>'; |
| 275 | - } |
|
| 276 | - else |
|
| 302 | + } else |
|
| 277 | 303 | { |
| 278 | 304 | $out.= '<option value="'.$obj->rowid.'">'; |
| 279 | 305 | } |
@@ -283,16 +309,13 @@ discard block |
||
| 283 | 309 | ($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) { |
| 284 | 310 | if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) { |
| 285 | 311 | $out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); |
| 286 | - } |
|
| 287 | - else { |
|
| 312 | + } else { |
|
| 288 | 313 | $out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); |
| 289 | 314 | } |
| 290 | - } |
|
| 291 | - else { |
|
| 315 | + } else { |
|
| 292 | 316 | if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) { |
| 293 | 317 | $out.= $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); |
| 294 | - } |
|
| 295 | - else { |
|
| 318 | + } else { |
|
| 296 | 319 | $out.= ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:'')); |
| 297 | 320 | } |
| 298 | 321 | } |
@@ -302,10 +325,13 @@ discard block |
||
| 302 | 325 | $i++; |
| 303 | 326 | } |
| 304 | 327 | } |
| 305 | - if (! empty($htmlname)) $out.= '</select>'; |
|
| 306 | - if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 307 | - } |
|
| 308 | - else |
|
| 328 | + if (! empty($htmlname)) { |
|
| 329 | + $out.= '</select>'; |
|
| 330 | + } |
|
| 331 | + if (! empty($htmlname) && $user->admin) { |
|
| 332 | + $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 333 | + } |
|
| 334 | + } else |
|
| 309 | 335 | { |
| 310 | 336 | dol_print_error($this->db); |
| 311 | 337 | } |
@@ -358,8 +384,7 @@ discard block |
||
| 358 | 384 | $obj = $this->db->fetch_object($resql); |
| 359 | 385 | if ($obj->code == 0) { |
| 360 | 386 | print '<option value="0"> </option>'; |
| 361 | - } |
|
| 362 | - else { |
|
| 387 | + } else { |
|
| 363 | 388 | if ($country == '' || $country != $obj->country) |
| 364 | 389 | { |
| 365 | 390 | // Show break |
@@ -372,8 +397,7 @@ discard block |
||
| 372 | 397 | if ($selected > 0 && $selected == $obj->code) |
| 373 | 398 | { |
| 374 | 399 | print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>'; |
| 375 | - } |
|
| 376 | - else |
|
| 400 | + } else |
|
| 377 | 401 | { |
| 378 | 402 | print '<option value="'.$obj->code.'">'.$obj->label.'</option>'; |
| 379 | 403 | } |
@@ -382,8 +406,7 @@ discard block |
||
| 382 | 406 | } |
| 383 | 407 | } |
| 384 | 408 | print '</select>'; |
| 385 | - } |
|
| 386 | - else |
|
| 409 | + } else |
|
| 387 | 410 | { |
| 388 | 411 | dol_print_error($this->db); |
| 389 | 412 | } |
@@ -425,8 +448,7 @@ discard block |
||
| 425 | 448 | if ($selected == $obj->code) |
| 426 | 449 | { |
| 427 | 450 | $out.= '<option value="'.$obj->code.'" selected>'; |
| 428 | - } |
|
| 429 | - else |
|
| 451 | + } else |
|
| 430 | 452 | { |
| 431 | 453 | $out.= '<option value="'.$obj->code.'">'; |
| 432 | 454 | } |
@@ -437,9 +459,10 @@ discard block |
||
| 437 | 459 | } |
| 438 | 460 | } |
| 439 | 461 | $out.= '</select>'; |
| 440 | - if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 441 | - } |
|
| 442 | - else |
|
| 462 | + if ($user->admin) { |
|
| 463 | + $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 464 | + } |
|
| 465 | + } else |
|
| 443 | 466 | { |
| 444 | 467 | dol_print_error($this->db); |
| 445 | 468 | } |
@@ -489,8 +512,12 @@ discard block |
||
| 489 | 512 | $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c"; |
| 490 | 513 | $sql .= " WHERE f.fk_pays=c.rowid"; |
| 491 | 514 | $sql .= " AND f.active = 1 AND c.active = 1"; |
| 492 | - if ($country_codeid) $sql .= " AND c.code = '".$country_codeid."'"; |
|
| 493 | - if ($filter) $sql .= " ".$filter; |
|
| 515 | + if ($country_codeid) { |
|
| 516 | + $sql .= " AND c.code = '".$country_codeid."'"; |
|
| 517 | + } |
|
| 518 | + if ($filter) { |
|
| 519 | + $sql .= " ".$filter; |
|
| 520 | + } |
|
| 494 | 521 | $sql .= " ORDER BY c.code"; |
| 495 | 522 | |
| 496 | 523 | dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG); |
@@ -499,7 +526,10 @@ discard block |
||
| 499 | 526 | { |
| 500 | 527 | $out.= '<div id="particulier2" class="visible">'; |
| 501 | 528 | $out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">'; |
| 502 | - if ($country_codeid) $out.= '<option value="0"> </option>'; // When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select. |
|
| 529 | + if ($country_codeid) { |
|
| 530 | + $out.= '<option value="0"> </option>'; |
|
| 531 | + } |
|
| 532 | + // When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select. |
|
| 503 | 533 | |
| 504 | 534 | $num = $this->db->num_rows($resql); |
| 505 | 535 | if ($num) |
@@ -510,9 +540,11 @@ discard block |
||
| 510 | 540 | { |
| 511 | 541 | $obj = $this->db->fetch_object($resql); |
| 512 | 542 | |
| 513 | - if ($obj->code) // We exclude empty line, we will add it later |
|
| 543 | + if ($obj->code) { |
|
| 544 | + // We exclude empty line, we will add it later |
|
| 514 | 545 | { |
| 515 | 546 | $labelcountry=(($langs->trans("Country".$obj->country_code)!="Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country); |
| 547 | + } |
|
| 516 | 548 | $labeljs=(($langs->trans("JuridicalStatus".$obj->code)!="JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label!='-'?$obj->label:'')); // $obj->label is already in output charset (converted by database driver) |
| 517 | 549 | $arraydata[$obj->code]=array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry); |
| 518 | 550 | } |
@@ -520,10 +552,12 @@ discard block |
||
| 520 | 552 | } |
| 521 | 553 | |
| 522 | 554 | $arraydata=dol_sort_array($arraydata, 'label_sort', 'ASC'); |
| 523 | - if (empty($country_codeid)) // Introduce empty value (if $country_codeid not empty, empty value was already added) |
|
| 555 | + if (empty($country_codeid)) { |
|
| 556 | + // Introduce empty value (if $country_codeid not empty, empty value was already added) |
|
| 524 | 557 | { |
| 525 | 558 | $arraydata[0]=array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>''); |
| 526 | 559 | } |
| 560 | + } |
|
| 527 | 561 | |
| 528 | 562 | foreach($arraydata as $key => $val) |
| 529 | 563 | { |
@@ -540,8 +574,7 @@ discard block |
||
| 540 | 574 | if ($selected > 0 && $selected == $val['code']) |
| 541 | 575 | { |
| 542 | 576 | $out.= '<option value="'.$val['code'].'" selected>'; |
| 543 | - } |
|
| 544 | - else |
|
| 577 | + } else |
|
| 545 | 578 | { |
| 546 | 579 | $out.= '<option value="'.$val['code'].'">'; |
| 547 | 580 | } |
@@ -551,15 +584,16 @@ discard block |
||
| 551 | 584 | } |
| 552 | 585 | } |
| 553 | 586 | $out.= '</select>'; |
| 554 | - if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 587 | + if ($user->admin) { |
|
| 588 | + $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 589 | + } |
|
| 555 | 590 | |
| 556 | 591 | // Make select dynamic |
| 557 | 592 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
| 558 | 593 | $out .= ajax_combobox($htmlname); |
| 559 | 594 | |
| 560 | 595 | $out.= '</div>'; |
| 561 | - } |
|
| 562 | - else |
|
| 596 | + } else |
|
| 563 | 597 | { |
| 564 | 598 | dol_print_error($this->db); |
| 565 | 599 | } |
@@ -611,7 +645,8 @@ discard block |
||
| 611 | 645 | // To refresh contacts list on thirdparty list change |
| 612 | 646 | $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); |
| 613 | 647 | |
| 614 | - if (count($events)) // If there is some ajax events to run once selection is done, we add code here to run events |
|
| 648 | + if (count($events)) { |
|
| 649 | + // If there is some ajax events to run once selection is done, we add code here to run events |
|
| 615 | 650 | { |
| 616 | 651 | print '<script type="text/javascript"> |
| 617 | 652 | jQuery(document).ready(function() { |
@@ -662,13 +697,13 @@ discard block |
||
| 662 | 697 | }); |
| 663 | 698 | </script>'; |
| 664 | 699 | } |
| 700 | + } |
|
| 665 | 701 | |
| 666 | 702 | print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n"; |
| 667 | 703 | print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />'; |
| 668 | 704 | print ajax_autocompleter(($socid?$socid:-1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0); |
| 669 | 705 | return $socid; |
| 670 | - } |
|
| 671 | - else |
|
| 706 | + } else |
|
| 672 | 707 | { |
| 673 | 708 | // Search to list thirdparties |
| 674 | 709 | $sql = "SELECT s.rowid, s.nom as name FROM"; |
@@ -698,20 +733,27 @@ discard block |
||
| 698 | 733 | while ($i < $num) |
| 699 | 734 | { |
| 700 | 735 | $obj = $this->db->fetch_object($resql); |
| 701 | - if ($i == 0) $firstCompany = $obj->rowid; |
|
| 736 | + if ($i == 0) { |
|
| 737 | + $firstCompany = $obj->rowid; |
|
| 738 | + } |
|
| 702 | 739 | $disabled=0; |
| 703 | - if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1; |
|
| 740 | + if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) { |
|
| 741 | + $disabled=1; |
|
| 742 | + } |
|
| 704 | 743 | if ($selected > 0 && $selected == $obj->rowid) |
| 705 | 744 | { |
| 706 | 745 | print '<option value="'.$obj->rowid.'"'; |
| 707 | - if ($disabled) print ' disabled'; |
|
| 746 | + if ($disabled) { |
|
| 747 | + print ' disabled'; |
|
| 748 | + } |
|
| 708 | 749 | print ' selected>'.dol_trunc($obj->name,24).'</option>'; |
| 709 | 750 | $firstCompany = $obj->rowid; |
| 710 | - } |
|
| 711 | - else |
|
| 751 | + } else |
|
| 712 | 752 | { |
| 713 | 753 | print '<option value="'.$obj->rowid.'"'; |
| 714 | - if ($disabled) print ' disabled'; |
|
| 754 | + if ($disabled) { |
|
| 755 | + print ' disabled'; |
|
| 756 | + } |
|
| 715 | 757 | print '>'.dol_trunc($obj->name,24).'</option>'; |
| 716 | 758 | } |
| 717 | 759 | $i ++; |
@@ -719,8 +761,7 @@ discard block |
||
| 719 | 761 | } |
| 720 | 762 | print "</select>\n"; |
| 721 | 763 | return $firstCompany; |
| 722 | - } |
|
| 723 | - else |
|
| 764 | + } else |
|
| 724 | 765 | { |
| 725 | 766 | dol_print_error($this->db); |
| 726 | 767 | print 'Error sql'; |
@@ -748,15 +789,21 @@ discard block |
||
| 748 | 789 | { |
| 749 | 790 | $lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1); |
| 750 | 791 | print '<select class="flat valignmiddle'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">'; |
| 751 | - if ($showempty) print '<option value="0"></option>'; |
|
| 792 | + if ($showempty) { |
|
| 793 | + print '<option value="0"></option>'; |
|
| 794 | + } |
|
| 752 | 795 | foreach($lesTypes as $key=>$value) |
| 753 | 796 | { |
| 754 | 797 | print '<option value="'.$key.'"'; |
| 755 | - if ($key == $selected) print ' selected'; |
|
| 798 | + if ($key == $selected) { |
|
| 799 | + print ' selected'; |
|
| 800 | + } |
|
| 756 | 801 | print '>'.$value.'</option>'; |
| 757 | 802 | } |
| 758 | 803 | print "</select>"; |
| 759 | - if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 804 | + if ($user->admin) { |
|
| 805 | + print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); |
|
| 806 | + } |
|
| 760 | 807 | print "\n"; |
| 761 | 808 | } |
| 762 | 809 | } |
@@ -782,7 +829,9 @@ discard block |
||
| 782 | 829 | $out=''; |
| 783 | 830 | |
| 784 | 831 | $size=''; |
| 785 | - if (!empty($fieldsize)) $size='size="'.$fieldsize.'"'; |
|
| 832 | + if (!empty($fieldsize)) { |
|
| 833 | + $size='size="'.$fieldsize.'"'; |
|
| 834 | + } |
|
| 786 | 835 | |
| 787 | 836 | if ($conf->use_javascript_ajax && empty($disableautocomplete)) |
| 788 | 837 | { |
@@ -815,27 +864,51 @@ discard block |
||
| 815 | 864 | if ($country_code == 'FR') |
| 816 | 865 | { |
| 817 | 866 | if (isset($idprof)) { |
| 818 | - if ($idprof==1) $formlength=9; |
|
| 819 | - else if ($idprof==2) $formlength=14; |
|
| 820 | - else if ($idprof==3) $formlength=5; // 4 chiffres et 1 lettre depuis janvier |
|
| 821 | - else if ($idprof==4) $formlength=32; // No maximum as we need to include a town name in this id |
|
| 867 | + if ($idprof==1) { |
|
| 868 | + $formlength=9; |
|
| 869 | + } else if ($idprof==2) { |
|
| 870 | + $formlength=14; |
|
| 871 | + } else if ($idprof==3) { |
|
| 872 | + $formlength=5; |
|
| 873 | + } |
|
| 874 | + // 4 chiffres et 1 lettre depuis janvier |
|
| 875 | + else if ($idprof==4) { |
|
| 876 | + $formlength=32; |
|
| 877 | + } |
|
| 878 | + // No maximum as we need to include a town name in this id |
|
| 822 | 879 | } |
| 823 | - } |
|
| 824 | - else if ($country_code == 'ES') |
|
| 880 | + } else if ($country_code == 'ES') |
|
| 825 | 881 | { |
| 826 | - if ($idprof==1) $formlength=9; //CIF/NIF/NIE 9 digits |
|
| 827 | - if ($idprof==2) $formlength=12; //NASS 12 digits without / |
|
| 828 | - if ($idprof==3) $formlength=5; //CNAE 5 digits |
|
| 829 | - if ($idprof==4) $formlength=32; //depend of college |
|
| 882 | + if ($idprof==1) { |
|
| 883 | + $formlength=9; |
|
| 884 | + } |
|
| 885 | + //CIF/NIF/NIE 9 digits |
|
| 886 | + if ($idprof==2) { |
|
| 887 | + $formlength=12; |
|
| 888 | + } |
|
| 889 | + //NASS 12 digits without / |
|
| 890 | + if ($idprof==3) { |
|
| 891 | + $formlength=5; |
|
| 892 | + } |
|
| 893 | + //CNAE 5 digits |
|
| 894 | + if ($idprof==4) { |
|
| 895 | + $formlength=32; |
|
| 896 | + } |
|
| 897 | + //depend of college |
|
| 830 | 898 | } |
| 831 | 899 | } |
| 832 | 900 | |
| 833 | 901 | $selected=$preselected; |
| 834 | 902 | if (! $selected && isset($idprof)) { |
| 835 | - if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1; |
|
| 836 | - else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2; |
|
| 837 | - else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3; |
|
| 838 | - else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4; |
|
| 903 | + if ($idprof==1 && ! empty($this->idprof1)) { |
|
| 904 | + $selected=$this->idprof1; |
|
| 905 | + } else if ($idprof==2 && ! empty($this->idprof2)) { |
|
| 906 | + $selected=$this->idprof2; |
|
| 907 | + } else if ($idprof==3 && ! empty($this->idprof3)) { |
|
| 908 | + $selected=$this->idprof3; |
|
| 909 | + } else if ($idprof==4 && ! empty($this->idprof4)) { |
|
| 910 | + $selected=$this->idprof4; |
|
| 911 | + } |
|
| 839 | 912 | } |
| 840 | 913 | |
| 841 | 914 | $maxlength=$formlength; |
@@ -875,8 +948,7 @@ discard block |
||
| 875 | 948 | if ($selected == $valors[$i]) |
| 876 | 949 | { |
| 877 | 950 | print '<option value="'.$valors[$i].'" selected>'; |
| 878 | - } |
|
| 879 | - else |
|
| 951 | + } else |
|
| 880 | 952 | { |
| 881 | 953 | print '<option value="'.$valors[$i].'">'; |
| 882 | 954 | } |
@@ -300,8 +300,9 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | function setErrorsTo($_strErrorsTo) |
| 302 | 302 | { |
| 303 | - if ( $_strErrorsTo ) |
|
| 304 | - $this->_errorsTo = $this->_strip_email($_strErrorsTo); |
|
| 303 | + if ( $_strErrorsTo ) { |
|
| 304 | + $this->_errorsTo = $this->_strip_email($_strErrorsTo); |
|
| 305 | + } |
|
| 305 | 306 | } |
| 306 | 307 | |
| 307 | 308 | /** |
@@ -314,10 +315,11 @@ discard block |
||
| 314 | 315 | { |
| 315 | 316 | $_retValue = ''; |
| 316 | 317 | |
| 317 | - if ( $_part === true ) |
|
| 318 | - $_retValue = $this->_errorsTo; |
|
| 319 | - else |
|
| 320 | - $_retValue = $this->_errorsTo[$_part]; |
|
| 318 | + if ( $_part === true ) { |
|
| 319 | + $_retValue = $this->_errorsTo; |
|
| 320 | + } else { |
|
| 321 | + $_retValue = $this->_errorsTo[$_part]; |
|
| 322 | + } |
|
| 321 | 323 | |
| 322 | 324 | return $_retValue; |
| 323 | 325 | } |
@@ -373,8 +375,7 @@ discard block |
||
| 373 | 375 | { |
| 374 | 376 | $this->_setErr(99, $host . ' is either offline or is an invalid host name.'); |
| 375 | 377 | $_retVal = false; |
| 376 | - } |
|
| 377 | - else |
|
| 378 | + } else |
|
| 378 | 379 | { |
| 379 | 380 | //See if we can connect to the SMTP server |
| 380 | 381 | if ($this->socket = @fsockopen( |
@@ -383,23 +384,28 @@ discard block |
||
| 383 | 384 | $this->errno, // actual system level error |
| 384 | 385 | $this->errstr, // and any text that goes with the error |
| 385 | 386 | $this->_smtpTimeout |
| 386 | - )) // timeout for reading/writing data over the socket |
|
| 387 | + )) { |
|
| 388 | + // timeout for reading/writing data over the socket |
|
| 387 | 389 | { |
| 388 | 390 | // Fix from PHP SMTP class by 'Chris Ryan' |
| 389 | 391 | // Sometimes the SMTP server takes a little longer to respond |
| 390 | 392 | // so we will give it a longer timeout for the first read |
| 391 | 393 | // Windows still does not have support for this timeout function |
| 392 | 394 | if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0); |
| 395 | + } |
|
| 393 | 396 | |
| 394 | 397 | // Check response from Server |
| 395 | - if ( $_retVal = $this->server_parse($this->socket, "220") ) |
|
| 396 | - $_retVal = $this->socket; |
|
| 398 | + if ( $_retVal = $this->server_parse($this->socket, "220") ) { |
|
| 399 | + $_retVal = $this->socket; |
|
| 400 | + } |
|
| 397 | 401 | } |
| 398 | 402 | // This connection attempt failed. |
| 399 | 403 | else |
| 400 | 404 | { |
| 401 | 405 | // @CHANGE LDR |
| 402 | - if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort(); |
|
| 406 | + if (empty($this->errstr)) { |
|
| 407 | + $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort(); |
|
| 408 | + } |
|
| 403 | 409 | $this->_setErr($this->errno, $this->errstr); |
| 404 | 410 | $_retVal = false; |
| 405 | 411 | } |
@@ -429,7 +435,9 @@ discard block |
||
| 429 | 435 | $host=preg_replace('@ssl://@i','',$host); // Remove prefix |
| 430 | 436 | $host=preg_replace('@tls://@i','',$host); // Remove prefix |
| 431 | 437 | |
| 432 | - if ($usetls) $host='tls://'.$host; |
|
| 438 | + if ($usetls) { |
|
| 439 | + $host='tls://'.$host; |
|
| 440 | + } |
|
| 433 | 441 | |
| 434 | 442 | $hosth = $host; |
| 435 | 443 | |
@@ -506,10 +514,10 @@ discard block |
||
| 506 | 514 | |
| 507 | 515 | // The error here just means the ID/password combo doesn't work. |
| 508 | 516 | // There is not a method to determine which is the problem, ID or password |
| 509 | - if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') ) |
|
| 510 | - $this->_setErr(130, 'Invalid Authentication Credentials.'); |
|
| 511 | - } |
|
| 512 | - else |
|
| 517 | + if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') ) { |
|
| 518 | + $this->_setErr(130, 'Invalid Authentication Credentials.'); |
|
| 519 | + } |
|
| 520 | + } else |
|
| 513 | 521 | { |
| 514 | 522 | $this->_setErr(126, '"' . $host . '" does not support authenticated connections.'); |
| 515 | 523 | } |
@@ -672,14 +680,17 @@ discard block |
||
| 672 | 680 | { |
| 673 | 681 | // Set these properties ONLY if they are set in the php.ini file. |
| 674 | 682 | // Otherwise the default values will be used. |
| 675 | - if ( $_host = ini_get('SMTPs') ) |
|
| 676 | - $this->setHost($_host); |
|
| 683 | + if ( $_host = ini_get('SMTPs') ) { |
|
| 684 | + $this->setHost($_host); |
|
| 685 | + } |
|
| 677 | 686 | |
| 678 | - if ( $_port = ini_get('smtp_port') ) |
|
| 679 | - $this->setPort($_port); |
|
| 687 | + if ( $_port = ini_get('smtp_port') ) { |
|
| 688 | + $this->setPort($_port); |
|
| 689 | + } |
|
| 680 | 690 | |
| 681 | - if ( $_from = ini_get('sendmail_from') ) |
|
| 682 | - $this->setFrom($_from); |
|
| 691 | + if ( $_from = ini_get('sendmail_from') ) { |
|
| 692 | + $this->setFrom($_from); |
|
| 693 | + } |
|
| 683 | 694 | } |
| 684 | 695 | |
| 685 | 696 | // Send back what we have |
@@ -698,8 +709,9 @@ discard block |
||
| 698 | 709 | function setTransportType($_type = 0) |
| 699 | 710 | { |
| 700 | 711 | if ( ( is_numeric($_type) ) && |
| 701 | - ( ( $_type >= 0 ) && ( $_type <= 3 ) ) ) |
|
| 702 | - $this->_transportType = $_type; |
|
| 712 | + ( ( $_type >= 0 ) && ( $_type <= 3 ) ) ) { |
|
| 713 | + $this->_transportType = $_type; |
|
| 714 | + } |
|
| 703 | 715 | } |
| 704 | 716 | |
| 705 | 717 | /** |
@@ -740,8 +752,9 @@ discard block |
||
| 740 | 752 | */ |
| 741 | 753 | function setHost($_strHost) |
| 742 | 754 | { |
| 743 | - if ( $_strHost ) |
|
| 744 | - $this->_smtpsHost = $_strHost; |
|
| 755 | + if ( $_strHost ) { |
|
| 756 | + $this->_smtpsHost = $_strHost; |
|
| 757 | + } |
|
| 745 | 758 | } |
| 746 | 759 | |
| 747 | 760 | /** |
@@ -766,8 +779,9 @@ discard block |
||
| 766 | 779 | function setPort($_intPort) |
| 767 | 780 | { |
| 768 | 781 | if ( ( is_numeric($_intPort) ) && |
| 769 | - ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) ) |
|
| 770 | - $this->_smtpsPort = $_intPort; |
|
| 782 | + ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) ) { |
|
| 783 | + $this->_smtpsPort = $_intPort; |
|
| 784 | + } |
|
| 771 | 785 | } |
| 772 | 786 | |
| 773 | 787 | /** |
@@ -832,8 +846,9 @@ discard block |
||
| 832 | 846 | */ |
| 833 | 847 | function setCharSet($_strCharSet) |
| 834 | 848 | { |
| 835 | - if ( $_strCharSet ) |
|
| 836 | - $this->_smtpsCharSet = $_strCharSet; |
|
| 849 | + if ( $_strCharSet ) { |
|
| 850 | + $this->_smtpsCharSet = $_strCharSet; |
|
| 851 | + } |
|
| 837 | 852 | } |
| 838 | 853 | |
| 839 | 854 | /** |
@@ -863,8 +878,9 @@ discard block |
||
| 863 | 878 | */ |
| 864 | 879 | function setTransEncode($_strTransEncode) |
| 865 | 880 | { |
| 866 | - if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) |
|
| 867 | - $this->_smtpsTransEncode = $_strTransEncode; |
|
| 881 | + if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) { |
|
| 882 | + $this->_smtpsTransEncode = $_strTransEncode; |
|
| 883 | + } |
|
| 868 | 884 | } |
| 869 | 885 | |
| 870 | 886 | /** |
@@ -895,8 +911,9 @@ discard block |
||
| 895 | 911 | */ |
| 896 | 912 | function setTransEncodeType($_strTransEncodeType) |
| 897 | 913 | { |
| 898 | - if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) |
|
| 899 | - $this->_smtpsTransEncodeType = $_strTransEncodeType; |
|
| 914 | + if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) { |
|
| 915 | + $this->_smtpsTransEncodeType = $_strTransEncodeType; |
|
| 916 | + } |
|
| 900 | 917 | } |
| 901 | 918 | |
| 902 | 919 | /** |
@@ -920,8 +937,9 @@ discard block |
||
| 920 | 937 | */ |
| 921 | 938 | function setFrom($_strFrom) |
| 922 | 939 | { |
| 923 | - if ( $_strFrom ) |
|
| 924 | - $this->_msgFrom = $this->_strip_email($_strFrom); |
|
| 940 | + if ( $_strFrom ) { |
|
| 941 | + $this->_msgFrom = $this->_strip_email($_strFrom); |
|
| 942 | + } |
|
| 925 | 943 | } |
| 926 | 944 | |
| 927 | 945 | /** |
@@ -934,10 +952,11 @@ discard block |
||
| 934 | 952 | { |
| 935 | 953 | $_retValue = ''; |
| 936 | 954 | |
| 937 | - if ( $_part === true ) |
|
| 938 | - $_retValue = $this->_msgFrom; |
|
| 939 | - else |
|
| 940 | - $_retValue = $this->_msgFrom[$_part]; |
|
| 955 | + if ( $_part === true ) { |
|
| 956 | + $_retValue = $this->_msgFrom; |
|
| 957 | + } else { |
|
| 958 | + $_retValue = $this->_msgFrom[$_part]; |
|
| 959 | + } |
|
| 941 | 960 | |
| 942 | 961 | return $_retValue; |
| 943 | 962 | } |
@@ -950,8 +969,9 @@ discard block |
||
| 950 | 969 | */ |
| 951 | 970 | function setReplyTo($_strReplyTo) |
| 952 | 971 | { |
| 953 | - if ( $_strReplyTo ) |
|
| 954 | - $this->_msgReplyTo = $this->_strip_email($_strReplyTo); |
|
| 972 | + if ( $_strReplyTo ) { |
|
| 973 | + $this->_msgReplyTo = $this->_strip_email($_strReplyTo); |
|
| 974 | + } |
|
| 955 | 975 | } |
| 956 | 976 | |
| 957 | 977 | /** |
@@ -964,10 +984,11 @@ discard block |
||
| 964 | 984 | { |
| 965 | 985 | $_retValue = ''; |
| 966 | 986 | |
| 967 | - if ( $_part === true ) |
|
| 968 | - $_retValue = $this->_msgReplyTo; |
|
| 969 | - else |
|
| 970 | - $_retValue = $this->_msgReplyTo[$_part]; |
|
| 987 | + if ( $_part === true ) { |
|
| 988 | + $_retValue = $this->_msgReplyTo; |
|
| 989 | + } else { |
|
| 990 | + $_retValue = $this->_msgReplyTo[$_part]; |
|
| 991 | + } |
|
| 971 | 992 | |
| 972 | 993 | return $_retValue; |
| 973 | 994 | } |
@@ -996,13 +1017,15 @@ discard block |
||
| 996 | 1017 | if ( is_string($_addrList) ) |
| 997 | 1018 | { |
| 998 | 1019 | // This could be a COMMA delimited string |
| 999 | - if ( strstr($_addrList, ',') ) |
|
| 1000 | - // "explode "list" into an array |
|
| 1020 | + if ( strstr($_addrList, ',') ) { |
|
| 1021 | + // "explode "list" into an array |
|
| 1001 | 1022 | $_addrList = explode(',', $_addrList); |
| 1023 | + } |
|
| 1002 | 1024 | |
| 1003 | 1025 | // Stick it in an array |
| 1004 | - else |
|
| 1005 | - $_addrList = array($_addrList); |
|
| 1026 | + else { |
|
| 1027 | + $_addrList = array($_addrList); |
|
| 1028 | + } |
|
| 1006 | 1029 | } |
| 1007 | 1030 | |
| 1008 | 1031 | // take the array of addresses and split them further |
@@ -1076,13 +1099,14 @@ discard block |
||
| 1076 | 1099 | if ( count($_tmpAry) == 2 ) |
| 1077 | 1100 | { |
| 1078 | 1101 | // We may not really have a "Real Name" |
| 1079 | - if ( $_tmpAry[0]) |
|
| 1080 | - $_aryEmail['real'] = trim($_tmpAry[0], ' ">'); |
|
| 1102 | + if ( $_tmpAry[0]) { |
|
| 1103 | + $_aryEmail['real'] = trim($_tmpAry[0], ' ">'); |
|
| 1104 | + } |
|
| 1081 | 1105 | |
| 1082 | 1106 | $_aryEmail['addr'] = $_tmpAry[1]; |
| 1107 | + } else { |
|
| 1108 | + $_aryEmail['addr'] = $_tmpAry[0]; |
|
| 1083 | 1109 | } |
| 1084 | - else |
|
| 1085 | - $_aryEmail['addr'] = $_tmpAry[0]; |
|
| 1086 | 1110 | |
| 1087 | 1111 | // Pull User Name and Host.tld apart |
| 1088 | 1112 | list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']); |
@@ -1149,12 +1173,13 @@ discard block |
||
| 1149 | 1173 | { |
| 1150 | 1174 | foreach ( $this->_msgRecipients[$_host][$_which] as $_addr => $_realName ) |
| 1151 | 1175 | { |
| 1152 | - if ( $_realName ) // @CHANGE LDR |
|
| 1176 | + if ( $_realName ) { |
|
| 1177 | + // @CHANGE LDR |
|
| 1153 | 1178 | { |
| 1154 | 1179 | $_realName = '"' . $_realName . '"'; |
| 1155 | - $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>'; |
|
| 1156 | 1180 | } |
| 1157 | - else |
|
| 1181 | + $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>'; |
|
| 1182 | + } else |
|
| 1158 | 1183 | { |
| 1159 | 1184 | $_RCPT_list[] = $_addr . '@' . $_host; |
| 1160 | 1185 | } |
@@ -1163,14 +1188,12 @@ discard block |
||
| 1163 | 1188 | } |
| 1164 | 1189 | |
| 1165 | 1190 | return implode(', ', $_RCPT_list); |
| 1166 | - } |
|
| 1167 | - else |
|
| 1191 | + } else |
|
| 1168 | 1192 | { |
| 1169 | 1193 | $this->_setErr(101, 'No eMail Address for message to be sent to.'); |
| 1170 | 1194 | return false; |
| 1171 | 1195 | } |
| 1172 | - } |
|
| 1173 | - else |
|
| 1196 | + } else |
|
| 1174 | 1197 | { |
| 1175 | 1198 | $this->_setErr(102, 'eMail type not defined.'); |
| 1176 | 1199 | return false; |
@@ -1185,8 +1208,9 @@ discard block |
||
| 1185 | 1208 | */ |
| 1186 | 1209 | function setTO($_addrTo) |
| 1187 | 1210 | { |
| 1188 | - if ( $_addrTo ) |
|
| 1189 | - $this->_buildAddrList('to', $_addrTo); |
|
| 1211 | + if ( $_addrTo ) { |
|
| 1212 | + $this->_buildAddrList('to', $_addrTo); |
|
| 1213 | + } |
|
| 1190 | 1214 | } |
| 1191 | 1215 | |
| 1192 | 1216 | /** |
@@ -1207,8 +1231,9 @@ discard block |
||
| 1207 | 1231 | */ |
| 1208 | 1232 | function setCC($_strCC) |
| 1209 | 1233 | { |
| 1210 | - if ( $_strCC ) |
|
| 1211 | - $this->_buildAddrList('cc', $_strCC); |
|
| 1234 | + if ( $_strCC ) { |
|
| 1235 | + $this->_buildAddrList('cc', $_strCC); |
|
| 1236 | + } |
|
| 1212 | 1237 | } |
| 1213 | 1238 | |
| 1214 | 1239 | /** |
@@ -1229,8 +1254,9 @@ discard block |
||
| 1229 | 1254 | */ |
| 1230 | 1255 | function setBCC($_strBCC) |
| 1231 | 1256 | { |
| 1232 | - if ( $_strBCC ) |
|
| 1233 | - $this->_buildAddrList('bcc', $_strBCC); |
|
| 1257 | + if ( $_strBCC ) { |
|
| 1258 | + $this->_buildAddrList('bcc', $_strBCC); |
|
| 1259 | + } |
|
| 1234 | 1260 | } |
| 1235 | 1261 | |
| 1236 | 1262 | /** |
@@ -1251,8 +1277,9 @@ discard block |
||
| 1251 | 1277 | */ |
| 1252 | 1278 | function setSubject($_strSubject = '') |
| 1253 | 1279 | { |
| 1254 | - if ( $_strSubject ) |
|
| 1255 | - $this->_msgSubject = $_strSubject; |
|
| 1280 | + if ( $_strSubject ) { |
|
| 1281 | + $this->_msgSubject = $_strSubject; |
|
| 1282 | + } |
|
| 1256 | 1283 | } |
| 1257 | 1284 | |
| 1258 | 1285 | /** |
@@ -1277,8 +1304,9 @@ discard block |
||
| 1277 | 1304 | $_header = 'From: ' . $this->getFrom('org') . "\r\n" |
| 1278 | 1305 | . 'To: ' . $this->getTO() . "\r\n"; |
| 1279 | 1306 | |
| 1280 | - if ( $this->getCC() ) |
|
| 1281 | - $_header .= 'Cc: ' . $this->getCC() . "\r\n"; |
|
| 1307 | + if ( $this->getCC() ) { |
|
| 1308 | + $_header .= 'Cc: ' . $this->getCC() . "\r\n"; |
|
| 1309 | + } |
|
| 1282 | 1310 | |
| 1283 | 1311 | /* Note: |
| 1284 | 1312 | * BCC email addresses must be listed in the RCPT TO command list, |
@@ -1311,33 +1339,41 @@ discard block |
||
| 1311 | 1339 | $_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; |
| 1312 | 1340 | $_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; |
| 1313 | 1341 | $_header .= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host . "\r\n"; |
| 1314 | - } |
|
| 1315 | - else |
|
| 1342 | + } else |
|
| 1316 | 1343 | { |
| 1317 | 1344 | $_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n"; |
| 1318 | 1345 | } |
| 1319 | - if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n"; |
|
| 1320 | - if ( $this->getMoreInHeader() ) |
|
| 1321 | - $_header .= $this->getMoreInHeader(); // Value must include the "\r\n"; |
|
| 1346 | + if (! empty($_SERVER['REMOTE_ADDR'])) { |
|
| 1347 | + $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n"; |
|
| 1348 | + } |
|
| 1349 | + if ( $this->getMoreInHeader() ) { |
|
| 1350 | + $_header .= $this->getMoreInHeader(); |
|
| 1351 | + } |
|
| 1352 | + // Value must include the "\r\n"; |
|
| 1322 | 1353 | |
| 1323 | 1354 | //$_header .= |
| 1324 | 1355 | // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n" |
| 1325 | 1356 | // 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"; |
| 1326 | 1357 | |
| 1327 | - if ( $this->getSensitivity() ) |
|
| 1328 | - $_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n"; |
|
| 1358 | + if ( $this->getSensitivity() ) { |
|
| 1359 | + $_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n"; |
|
| 1360 | + } |
|
| 1329 | 1361 | |
| 1330 | - if ( $this->_msgPriority != 3 ) |
|
| 1331 | - $_header .= $this->getPriority(); |
|
| 1362 | + if ( $this->_msgPriority != 3 ) { |
|
| 1363 | + $_header .= $this->getPriority(); |
|
| 1364 | + } |
|
| 1332 | 1365 | |
| 1333 | 1366 | |
| 1334 | 1367 | // @CHANGE LDR |
| 1335 | - if ( $this->getDeliveryReceipt() ) |
|
| 1336 | - $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; |
|
| 1337 | - if ( $this->getErrorsTo() ) |
|
| 1338 | - $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; |
|
| 1339 | - if ( $this->getReplyTo() ) |
|
| 1340 | - $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; |
|
| 1368 | + if ( $this->getDeliveryReceipt() ) { |
|
| 1369 | + $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; |
|
| 1370 | + } |
|
| 1371 | + if ( $this->getErrorsTo() ) { |
|
| 1372 | + $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; |
|
| 1373 | + } |
|
| 1374 | + if ( $this->getReplyTo() ) { |
|
| 1375 | + $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; |
|
| 1376 | + } |
|
| 1341 | 1377 | |
| 1342 | 1378 | $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n"; |
| 1343 | 1379 | $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n"; |
@@ -1358,10 +1394,11 @@ discard block |
||
| 1358 | 1394 | { |
| 1359 | 1395 | //if ( $strContent ) |
| 1360 | 1396 | //{ |
| 1361 | - if ( $strType == 'html' ) |
|
| 1362 | - $strMimeType = 'text/html'; |
|
| 1363 | - else |
|
| 1364 | - $strMimeType = 'text/plain'; |
|
| 1397 | + if ( $strType == 'html' ) { |
|
| 1398 | + $strMimeType = 'text/html'; |
|
| 1399 | + } else { |
|
| 1400 | + $strMimeType = 'text/plain'; |
|
| 1401 | + } |
|
| 1365 | 1402 | |
| 1366 | 1403 | // Make RFC821 Compliant, replace bare linefeeds |
| 1367 | 1404 | $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent); |
@@ -1385,8 +1422,9 @@ discard block |
||
| 1385 | 1422 | $this->_msgContent[$strType]['data'] = $strContent; |
| 1386 | 1423 | $this->_msgContent[$strType]['dataText'] = $strContentAltText; |
| 1387 | 1424 | |
| 1388 | - if ( $this->getMD5flag() ) |
|
| 1389 | - $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3); |
|
| 1425 | + if ( $this->getMD5flag() ) { |
|
| 1426 | + $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3); |
|
| 1427 | + } |
|
| 1390 | 1428 | //} |
| 1391 | 1429 | } |
| 1392 | 1430 | |
@@ -1409,8 +1447,9 @@ discard block |
||
| 1409 | 1447 | $keyCount = count($_types); |
| 1410 | 1448 | |
| 1411 | 1449 | // If we have ZERO, we have a problem |
| 1412 | - if( $keyCount === 0 ) |
|
| 1413 | - die ("Sorry, no content"); |
|
| 1450 | + if( $keyCount === 0 ) { |
|
| 1451 | + die ("Sorry, no content"); |
|
| 1452 | + } |
|
| 1414 | 1453 | |
| 1415 | 1454 | // If we have ONE, we can use the simple format |
| 1416 | 1455 | else if( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) |
@@ -1423,8 +1462,9 @@ discard block |
||
| 1423 | 1462 | . 'Content-Disposition: inline' . "\r\n" |
| 1424 | 1463 | . 'Content-Description: Message' . "\r\n"; |
| 1425 | 1464 | |
| 1426 | - if ( $this->getMD5flag() ) |
|
| 1427 | - $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n"; |
|
| 1465 | + if ( $this->getMD5flag() ) { |
|
| 1466 | + $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n"; |
|
| 1467 | + } |
|
| 1428 | 1468 | |
| 1429 | 1469 | $content .= "\r\n" |
| 1430 | 1470 | . $_msgData['data'] . "\r\n"; |
@@ -1447,9 +1487,11 @@ discard block |
||
| 1447 | 1487 | |
| 1448 | 1488 | $content .= "--" . $this->_getBoundary('mixed') . "\r\n"; |
| 1449 | 1489 | |
| 1450 | - if (key_exists('image', $this->_msgContent)) // If inline image found |
|
| 1490 | + if (key_exists('image', $this->_msgContent)) { |
|
| 1491 | + // If inline image found |
|
| 1451 | 1492 | { |
| 1452 | 1493 | $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; |
| 1494 | + } |
|
| 1453 | 1495 | $content .= "\r\n"; |
| 1454 | 1496 | $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; |
| 1455 | 1497 | } |
@@ -1472,8 +1514,9 @@ discard block |
||
| 1472 | 1514 | . 'Content-Transfer-Encoding: base64' . "\r\n" |
| 1473 | 1515 | . 'Content-Description: ' . $_data['fileName'] ."\r\n"; |
| 1474 | 1516 | |
| 1475 | - if ( $this->getMD5flag() ) |
|
| 1476 | - $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
| 1517 | + if ( $this->getMD5flag() ) { |
|
| 1518 | + $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
| 1519 | + } |
|
| 1477 | 1520 | |
| 1478 | 1521 | $content .= "\r\n" . $_data['data'] . "\r\n\r\n"; |
| 1479 | 1522 | } |
@@ -1491,8 +1534,9 @@ discard block |
||
| 1491 | 1534 | . 'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n" |
| 1492 | 1535 | . 'Content-ID: <' . $_data['cid'] . '> ' . "\r\n"; |
| 1493 | 1536 | |
| 1494 | - if ( $this->getMD5flag() ) |
|
| 1495 | - $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
| 1537 | + if ( $this->getMD5flag() ) { |
|
| 1538 | + $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; |
|
| 1539 | + } |
|
| 1496 | 1540 | |
| 1497 | 1541 | $content .= "\r\n" |
| 1498 | 1542 | . $_data['data'] . "\r\n"; |
@@ -1502,8 +1546,7 @@ discard block |
||
| 1502 | 1546 | $content.= "--" . $this->_getBoundary('related') . "--" . "\r\n"; |
| 1503 | 1547 | $content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n"; |
| 1504 | 1548 | $content.= "\r\n"; |
| 1505 | - } |
|
| 1506 | - else |
|
| 1549 | + } else |
|
| 1507 | 1550 | { |
| 1508 | 1551 | if (key_exists('image', $this->_msgContent)) |
| 1509 | 1552 | { |
@@ -1515,9 +1558,11 @@ discard block |
||
| 1515 | 1558 | $content.= "--" . $this->_getBoundary('related') . "\r\n"; |
| 1516 | 1559 | } |
| 1517 | 1560 | |
| 1518 | - if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
| 1561 | + if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { |
|
| 1562 | + // Add plain text message part before html part |
|
| 1519 | 1563 | { |
| 1520 | 1564 | $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; |
| 1565 | + } |
|
| 1521 | 1566 | $content .= "\r\n"; |
| 1522 | 1567 | $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; |
| 1523 | 1568 | |
@@ -1538,15 +1583,18 @@ discard block |
||
| 1538 | 1583 | // . 'Content-Disposition: inline' . "\r\n" |
| 1539 | 1584 | // . 'Content-Description: ' . $type . ' message' . "\r\n"; |
| 1540 | 1585 | |
| 1541 | - if ( $this->getMD5flag() ) |
|
| 1542 | - $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n"; |
|
| 1586 | + if ( $this->getMD5flag() ) { |
|
| 1587 | + $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n"; |
|
| 1588 | + } |
|
| 1543 | 1589 | |
| 1544 | 1590 | $content .= "\r\n" . $_content['data'] . "\r\n"; |
| 1545 | 1591 | |
| 1546 | - if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
| 1592 | + if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { |
|
| 1593 | + // Add plain text message part after html part |
|
| 1547 | 1594 | { |
| 1548 | 1595 | $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n"; |
| 1549 | 1596 | } |
| 1597 | + } |
|
| 1550 | 1598 | |
| 1551 | 1599 | $content .= "\r\n"; |
| 1552 | 1600 | } |
@@ -1579,8 +1627,9 @@ discard block |
||
| 1579 | 1627 | $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName; |
| 1580 | 1628 | $this->_msgContent['attachment'][$strFileName]['data'] = $strContent; |
| 1581 | 1629 | |
| 1582 | - if ( $this->getMD5flag() ) |
|
| 1583 | - $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3); |
|
| 1630 | + if ( $this->getMD5flag() ) { |
|
| 1631 | + $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3); |
|
| 1632 | + } |
|
| 1584 | 1633 | } |
| 1585 | 1634 | } |
| 1586 | 1635 | |
@@ -1606,8 +1655,9 @@ discard block |
||
| 1606 | 1655 | $this->_msgContent['image'][$strImageName]['cid'] = $strImageCid; |
| 1607 | 1656 | $this->_msgContent['image'][$strImageName]['data'] = $strContent; |
| 1608 | 1657 | |
| 1609 | - if ( $this->getMD5flag() ) |
|
| 1610 | - $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3); |
|
| 1658 | + if ( $this->getMD5flag() ) { |
|
| 1659 | + $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3); |
|
| 1660 | + } |
|
| 1611 | 1661 | } |
| 1612 | 1662 | } |
| 1613 | 1663 | // END @CHANGE LDR |
@@ -1627,8 +1677,9 @@ discard block |
||
| 1627 | 1677 | function setSensitivity($_value = 0) |
| 1628 | 1678 | { |
| 1629 | 1679 | if ( ( is_numeric($_value) ) && |
| 1630 | - ( ( $_value >= 0 ) && ( $_value <= 3 ) ) ) |
|
| 1631 | - $this->_msgSensitivity = $_value; |
|
| 1680 | + ( ( $_value >= 0 ) && ( $_value <= 3 ) ) ) { |
|
| 1681 | + $this->_msgSensitivity = $_value; |
|
| 1682 | + } |
|
| 1632 | 1683 | } |
| 1633 | 1684 | |
| 1634 | 1685 | /** |
@@ -1662,8 +1713,9 @@ discard block |
||
| 1662 | 1713 | function setPriority( $_value = 3 ) |
| 1663 | 1714 | { |
| 1664 | 1715 | if ( ( is_numeric($_value) ) && |
| 1665 | - ( ( $_value >= 0 ) && ( $_value <= 5 ) ) ) |
|
| 1666 | - $this->_msgPriority = $_value; |
|
| 1716 | + ( ( $_value >= 0 ) && ( $_value <= 5 ) ) ) { |
|
| 1717 | + $this->_msgPriority = $_value; |
|
| 1718 | + } |
|
| 1667 | 1719 | } |
| 1668 | 1720 | |
| 1669 | 1721 | /** |
@@ -1716,8 +1768,9 @@ discard block |
||
| 1716 | 1768 | */ |
| 1717 | 1769 | function setXheader($strXdata) |
| 1718 | 1770 | { |
| 1719 | - if ( $strXdata ) |
|
| 1720 | - $this->_msgXheader[] = $strXdata; |
|
| 1771 | + if ( $strXdata ) { |
|
| 1772 | + $this->_msgXheader[] = $strXdata; |
|
| 1773 | + } |
|
| 1721 | 1774 | } |
| 1722 | 1775 | |
| 1723 | 1776 | /** |
@@ -1750,9 +1803,13 @@ discard block |
||
| 1750 | 1803 | */ |
| 1751 | 1804 | function _getBoundary($type='mixed') |
| 1752 | 1805 | { |
| 1753 | - if ($type == 'mixed') return $this->_smtpsBoundary; |
|
| 1754 | - else if ($type == 'related') return $this->_smtpsRelatedBoundary; |
|
| 1755 | - else if ($type == 'alternative') return $this->_smtpsAlternativeBoundary; |
|
| 1806 | + if ($type == 'mixed') { |
|
| 1807 | + return $this->_smtpsBoundary; |
|
| 1808 | + } else if ($type == 'related') { |
|
| 1809 | + return $this->_smtpsRelatedBoundary; |
|
| 1810 | + } else if ($type == 'alternative') { |
|
| 1811 | + return $this->_smtpsAlternativeBoundary; |
|
| 1812 | + } |
|
| 1756 | 1813 | } |
| 1757 | 1814 | |
| 1758 | 1815 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -1810,12 +1867,18 @@ discard block |
||
| 1810 | 1867 | function socket_send_str( $_strSend, $_returnCode = null, $CRLF = "\r\n" ) |
| 1811 | 1868 | { |
| 1812 | 1869 | // phpcs:enable |
| 1813 | - if ($this->_debug) $this->log.=$_strSend; // @CHANGE LDR for log |
|
| 1870 | + if ($this->_debug) { |
|
| 1871 | + $this->log.=$_strSend; |
|
| 1872 | + } |
|
| 1873 | + // @CHANGE LDR for log |
|
| 1814 | 1874 | fputs($this->socket, $_strSend . $CRLF); |
| 1815 | - if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF; |
|
| 1875 | + if ($this->_debug) { |
|
| 1876 | + $this->log.=' ('.$_returnCode.')' . $CRLF; |
|
| 1877 | + } |
|
| 1816 | 1878 | |
| 1817 | - if ( $_returnCode ) |
|
| 1818 | - return $this->server_parse($this->socket, $_returnCode); |
|
| 1879 | + if ( $_returnCode ) { |
|
| 1880 | + return $this->server_parse($this->socket, $_returnCode); |
|
| 1881 | + } |
|
| 1819 | 1882 | } |
| 1820 | 1883 | |
| 1821 | 1884 | // ============================================================= |
@@ -82,8 +82,7 @@ |
||
| 82 | 82 | $label = $res[$label_type]; |
| 83 | 83 | $this->db->free($resql); |
| 84 | 84 | return $label; |
| 85 | - } |
|
| 86 | - else |
|
| 85 | + } else |
|
| 87 | 86 | { |
| 88 | 87 | $this->error=$this->db->error().' sql='.$sql; |
| 89 | 88 | dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR); |
@@ -83,11 +83,21 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | // Clean parameters |
| 85 | 85 | |
| 86 | - if (isset($this->id)) $this->id=trim($this->id); |
|
| 87 | - if (isset($this->code)) $this->code=trim($this->code); |
|
| 88 | - if (isset($this->libelle)) $this->libelle=trim($this->libelle); |
|
| 89 | - if (isset($this->active)) $this->active=trim($this->active); |
|
| 90 | - if (isset($this->module)) $this->module=trim($this->module); |
|
| 86 | + if (isset($this->id)) { |
|
| 87 | + $this->id=trim($this->id); |
|
| 88 | + } |
|
| 89 | + if (isset($this->code)) { |
|
| 90 | + $this->code=trim($this->code); |
|
| 91 | + } |
|
| 92 | + if (isset($this->libelle)) { |
|
| 93 | + $this->libelle=trim($this->libelle); |
|
| 94 | + } |
|
| 95 | + if (isset($this->active)) { |
|
| 96 | + $this->active=trim($this->active); |
|
| 97 | + } |
|
| 98 | + if (isset($this->module)) { |
|
| 99 | + $this->module=trim($this->module); |
|
| 100 | + } |
|
| 91 | 101 | |
| 92 | 102 | |
| 93 | 103 | |
@@ -149,8 +159,7 @@ discard block |
||
| 149 | 159 | } |
| 150 | 160 | $this->db->rollback(); |
| 151 | 161 | return -1*$error; |
| 152 | - } |
|
| 153 | - else |
|
| 162 | + } else |
|
| 154 | 163 | { |
| 155 | 164 | $this->db->commit(); |
| 156 | 165 | return $this->id; |
@@ -177,9 +186,13 @@ discard block |
||
| 177 | 186 | $sql.= " t.active,"; |
| 178 | 187 | $sql.= " t.module"; |
| 179 | 188 | $sql.= " FROM ".MAIN_DB_PREFIX."c_typent as t"; |
| 180 | - if ($id) $sql.= " WHERE t.id = ".$id; |
|
| 181 | - elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 182 | - elseif ($label) $sql.= " WHERE t.libelle = '".$this->db->escape($label)."'"; |
|
| 189 | + if ($id) { |
|
| 190 | + $sql.= " WHERE t.id = ".$id; |
|
| 191 | + } elseif ($code) { |
|
| 192 | + $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 193 | + } elseif ($label) { |
|
| 194 | + $sql.= " WHERE t.libelle = '".$this->db->escape($label)."'"; |
|
| 195 | + } |
|
| 183 | 196 | |
| 184 | 197 | $resql=$this->db->query($sql); |
| 185 | 198 | if ($resql) |
@@ -198,8 +211,7 @@ discard block |
||
| 198 | 211 | $this->db->free($resql); |
| 199 | 212 | |
| 200 | 213 | return 1; |
| 201 | - } |
|
| 202 | - else |
|
| 214 | + } else |
|
| 203 | 215 | { |
| 204 | 216 | $this->error="Error ".$this->db->lasterror(); |
| 205 | 217 | return -1; |
@@ -220,10 +232,18 @@ discard block |
||
| 220 | 232 | $error=0; |
| 221 | 233 | |
| 222 | 234 | // Clean parameters |
| 223 | - if (isset($this->code)) $this->code=trim($this->code); |
|
| 224 | - if (isset($this->libelle)) $this->libelle=trim($this->libelle); |
|
| 225 | - if (isset($this->active)) $this->active=trim($this->active); |
|
| 226 | - if (isset($this->module)) $this->module=trim($this->module); |
|
| 235 | + if (isset($this->code)) { |
|
| 236 | + $this->code=trim($this->code); |
|
| 237 | + } |
|
| 238 | + if (isset($this->libelle)) { |
|
| 239 | + $this->libelle=trim($this->libelle); |
|
| 240 | + } |
|
| 241 | + if (isset($this->active)) { |
|
| 242 | + $this->active=trim($this->active); |
|
| 243 | + } |
|
| 244 | + if (isset($this->module)) { |
|
| 245 | + $this->module=trim($this->module); |
|
| 246 | + } |
|
| 227 | 247 | |
| 228 | 248 | |
| 229 | 249 | // Check parameters |
@@ -269,8 +289,7 @@ discard block |
||
| 269 | 289 | } |
| 270 | 290 | $this->db->rollback(); |
| 271 | 291 | return -1*$error; |
| 272 | - } |
|
| 273 | - else |
|
| 292 | + } else |
|
| 274 | 293 | { |
| 275 | 294 | $this->db->commit(); |
| 276 | 295 | return 1; |
@@ -325,8 +344,7 @@ discard block |
||
| 325 | 344 | } |
| 326 | 345 | $this->db->rollback(); |
| 327 | 346 | return -1*$error; |
| 328 | - } |
|
| 329 | - else |
|
| 347 | + } else |
|
| 330 | 348 | { |
| 331 | 349 | $this->db->commit(); |
| 332 | 350 | return 1; |
@@ -129,15 +129,19 @@ discard block |
||
| 129 | 129 | dol_syslog("AntiVir::dol_avscan_file Result return_var=".$return_var." output=".join(',',$output)); |
| 130 | 130 | |
| 131 | 131 | $returncodevirus=1; |
| 132 | - if ($return_var == $returncodevirus) // Virus found |
|
| 132 | + if ($return_var == $returncodevirus) { |
|
| 133 | + // Virus found |
|
| 133 | 134 | { |
| 134 | 135 | $this->errors=$output; |
| 136 | + } |
|
| 135 | 137 | return -99; |
| 136 | 138 | } |
| 137 | 139 | |
| 138 | - if ($return_var > 0) // If other error |
|
| 140 | + if ($return_var > 0) { |
|
| 141 | + // If other error |
|
| 139 | 142 | { |
| 140 | 143 | $this->errors=$output; |
| 144 | + } |
|
| 141 | 145 | return -98; |
| 142 | 146 | } |
| 143 | 147 | |
@@ -173,10 +177,14 @@ discard block |
||
| 173 | 177 | $param=preg_replace('/%maxfilesize/',$maxfilesize,$param); |
| 174 | 178 | $param=preg_replace('/%file/',trim($file),$param); |
| 175 | 179 | |
| 176 | - if (! preg_match('/%file/',$conf->global->MAIN_ANTIVIRUS_PARAM)) |
|
| 177 | - $param=$param." ".escapeshellarg(trim($file)); |
|
| 180 | + if (! preg_match('/%file/',$conf->global->MAIN_ANTIVIRUS_PARAM)) { |
|
| 181 | + $param=$param." ".escapeshellarg(trim($file)); |
|
| 182 | + } |
|
| 178 | 183 | |
| 179 | - if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command. Using escapeshellcmd fails. |
|
| 184 | + if (preg_match("/\s/",$command)) { |
|
| 185 | + $command=escapeshellarg($command); |
|
| 186 | + } |
|
| 187 | + // Use quotes on command. Using escapeshellcmd fails. |
|
| 180 | 188 | |
| 181 | 189 | $ret=$command.' '.$param; |
| 182 | 190 | //$ret=$command.' '.$param.' 2>&1'; |
@@ -426,23 +426,31 @@ discard block |
||
| 426 | 426 | $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
| 427 | 427 | $sql.= " WHERE entity IN (".getEntity($element).")" ; |
| 428 | 428 | |
| 429 | - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
| 430 | - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 431 | - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 432 | - else { |
|
| 429 | + if ($id > 0) { |
|
| 430 | + $sql.= " AND rowid = ".$db->escape($id); |
|
| 431 | + } else if ($ref) { |
|
| 432 | + $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 433 | + } else if ($ref_ext) { |
|
| 434 | + $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 435 | + } else { |
|
| 433 | 436 | $error='ErrorWrongParameters'; |
| 434 | 437 | dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
| 435 | 438 | return -1; |
| 436 | 439 | } |
| 437 | - if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
| 440 | + if ($ref || $ref_ext) { |
|
| 441 | + $sql.= " AND entity = ".$conf->entity; |
|
| 442 | + } |
|
| 438 | 443 | |
| 439 | 444 | dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
| 440 | 445 | $resql = $db->query($sql); |
| 441 | 446 | if ($resql) |
| 442 | 447 | { |
| 443 | 448 | $num=$db->num_rows($resql); |
| 444 | - if ($num > 0) return 1; |
|
| 445 | - else return 0; |
|
| 449 | + if ($num > 0) { |
|
| 450 | + return 1; |
|
| 451 | + } else { |
|
| 452 | + return 0; |
|
| 453 | + } |
|
| 446 | 454 | } |
| 447 | 455 | return -1; |
| 448 | 456 | } |
@@ -471,13 +479,18 @@ discard block |
||
| 471 | 479 | //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
| 472 | 480 | $lastname=$this->lastname; |
| 473 | 481 | $firstname=$this->firstname; |
| 474 | - if (empty($lastname)) $lastname=(isset($this->lastname)?$this->lastname:(isset($this->name)?$this->name:(isset($this->nom)?$this->nom:(isset($this->societe)?$this->societe:(isset($this->company)?$this->company:''))))); |
|
| 482 | + if (empty($lastname)) { |
|
| 483 | + $lastname=(isset($this->lastname)?$this->lastname:(isset($this->name)?$this->name:(isset($this->nom)?$this->nom:(isset($this->societe)?$this->societe:(isset($this->company)?$this->company:''))))); |
|
| 484 | + } |
|
| 475 | 485 | |
| 476 | 486 | $ret=''; |
| 477 | 487 | if ($option && $this->civility_id) |
| 478 | 488 | { |
| 479 | - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
| 480 | - else $ret.=$this->civility_id.' '; |
|
| 489 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) { |
|
| 490 | + $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
| 491 | + } else { |
|
| 492 | + $ret.=$this->civility_id.' '; |
|
| 493 | + } |
|
| 481 | 494 | } |
| 482 | 495 | |
| 483 | 496 | $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
@@ -570,14 +583,15 @@ discard block |
||
| 570 | 583 | { |
| 571 | 584 | if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) { |
| 572 | 585 | $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
| 573 | - } |
|
| 574 | - else { |
|
| 586 | + } else { |
|
| 575 | 587 | $out.=($outdone?' - ':'').$this->state; |
| 576 | 588 | } |
| 577 | 589 | $outdone++; |
| 578 | 590 | } |
| 579 | 591 | |
| 580 | - if (! empty($this->phone) || ! empty($this->phone_pro) || ! empty($this->phone_mobile) || ! empty($this->phone_perso) || ! empty($this->fax) || ! empty($this->office_phone) || ! empty($this->user_mobile) || ! empty($this->office_fax)) $out.=($outdone?'<br>':''); |
|
| 592 | + if (! empty($this->phone) || ! empty($this->phone_pro) || ! empty($this->phone_mobile) || ! empty($this->phone_perso) || ! empty($this->fax) || ! empty($this->office_phone) || ! empty($this->user_mobile) || ! empty($this->office_fax)) { |
|
| 593 | + $out.=($outdone?'<br>':''); |
|
| 594 | + } |
|
| 581 | 595 | if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
| 582 | 596 | $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
| 583 | 597 | } |
@@ -618,13 +632,21 @@ discard block |
||
| 618 | 632 | $out.='<div style="clear: both;">'; |
| 619 | 633 | if (! empty($conf->socialnetworks->enabled)) |
| 620 | 634 | { |
| 621 | - if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 635 | + if ($this->skype) { |
|
| 636 | + $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 637 | + } |
|
| 622 | 638 | $outdone++; |
| 623 | - if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 639 | + if ($this->jabberid) { |
|
| 640 | + $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 641 | + } |
|
| 624 | 642 | $outdone++; |
| 625 | - if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 643 | + if ($this->twitter) { |
|
| 644 | + $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 645 | + } |
|
| 626 | 646 | $outdone++; |
| 627 | - if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 647 | + if ($this->facebook) { |
|
| 648 | + $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 649 | + } |
|
| 628 | 650 | $outdone++; |
| 629 | 651 | } |
| 630 | 652 | $out.='</div>'; |
@@ -684,10 +706,10 @@ discard block |
||
| 684 | 706 | $this->errors = $ecmfile->errors; |
| 685 | 707 | } |
| 686 | 708 | */ |
| 709 | + } else { |
|
| 710 | + return ''; |
|
| 687 | 711 | } |
| 688 | - else return ''; |
|
| 689 | - } |
|
| 690 | - elseif (empty($ecmfile->share)) |
|
| 712 | + } elseif (empty($ecmfile->share)) |
|
| 691 | 713 | { |
| 692 | 714 | // Add entry into index |
| 693 | 715 | if ($initsharekey) |
@@ -695,8 +717,9 @@ discard block |
||
| 695 | 717 | require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
| 696 | 718 | $ecmfile->share = getRandomPassword(true); |
| 697 | 719 | $ecmfile->update($user); |
| 720 | + } else { |
|
| 721 | + return ''; |
|
| 698 | 722 | } |
| 699 | - else return ''; |
|
| 700 | 723 | } |
| 701 | 724 | |
| 702 | 725 | // Define $urlwithroot |
@@ -710,14 +733,18 @@ discard block |
||
| 710 | 733 | //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
| 711 | 734 | //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
| 712 | 735 | //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
| 713 | - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
| 714 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 736 | + if (! empty($ecmfile->share)) { |
|
| 737 | + $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; |
|
| 738 | + } |
|
| 739 | + // Hash for public share |
|
| 740 | + if ($forcedownload) { |
|
| 741 | + $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 742 | + } |
|
| 715 | 743 | |
| 716 | 744 | if ($relativelink) |
| 717 | 745 | { |
| 718 | 746 | $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
| 719 | - } |
|
| 720 | - else |
|
| 747 | + } else |
|
| 721 | 748 | { |
| 722 | 749 | $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
| 723 | 750 | } |
@@ -765,8 +792,7 @@ discard block |
||
| 765 | 792 | if (is_numeric($type_contact)) |
| 766 | 793 | { |
| 767 | 794 | $id_type_contact=$type_contact; |
| 768 | - } |
|
| 769 | - else |
|
| 795 | + } else |
|
| 770 | 796 | { |
| 771 | 797 | // We look for id type_contact |
| 772 | 798 | $sql = "SELECT tc.rowid"; |
@@ -779,7 +805,9 @@ discard block |
||
| 779 | 805 | if ($resql) |
| 780 | 806 | { |
| 781 | 807 | $obj = $this->db->fetch_object($resql); |
| 782 | - if ($obj) $id_type_contact=$obj->rowid; |
|
| 808 | + if ($obj) { |
|
| 809 | + $id_type_contact=$obj->rowid; |
|
| 810 | + } |
|
| 783 | 811 | } |
| 784 | 812 | } |
| 785 | 813 | |
@@ -831,8 +859,7 @@ discard block |
||
| 831 | 859 | |
| 832 | 860 | $this->db->commit(); |
| 833 | 861 | return 1; |
| 834 | - } |
|
| 835 | - else |
|
| 862 | + } else |
|
| 836 | 863 | { |
| 837 | 864 | if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
| 838 | 865 | { |
@@ -840,15 +867,16 @@ discard block |
||
| 840 | 867 | $this->db->rollback(); |
| 841 | 868 | echo 'err rollback'; |
| 842 | 869 | return -2; |
| 843 | - } |
|
| 844 | - else |
|
| 870 | + } else |
|
| 845 | 871 | { |
| 846 | 872 | $this->error=$this->db->error(); |
| 847 | 873 | $this->db->rollback(); |
| 848 | 874 | return -1; |
| 849 | 875 | } |
| 850 | 876 | } |
| 851 | - } else return 0; |
|
| 877 | + } else { |
|
| 878 | + return 0; |
|
| 879 | + } |
|
| 852 | 880 | } |
| 853 | 881 | |
| 854 | 882 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -890,15 +918,18 @@ discard block |
||
| 890 | 918 | // Insert into database |
| 891 | 919 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
| 892 | 920 | $sql.= " statut = ".$statut; |
| 893 | - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 894 | - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 921 | + if ($type_contact_id) { |
|
| 922 | + $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 923 | + } |
|
| 924 | + if ($fk_socpeople) { |
|
| 925 | + $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 926 | + } |
|
| 895 | 927 | $sql.= " where rowid = ".$rowid; |
| 896 | 928 | $resql=$this->db->query($sql); |
| 897 | 929 | if ($resql) |
| 898 | 930 | { |
| 899 | 931 | return 0; |
| 900 | - } |
|
| 901 | - else |
|
| 932 | + } else |
|
| 902 | 933 | { |
| 903 | 934 | $this->error=$this->db->lasterror(); |
| 904 | 935 | return -1; |
@@ -935,8 +966,7 @@ discard block |
||
| 935 | 966 | |
| 936 | 967 | $this->db->commit(); |
| 937 | 968 | return 1; |
| 938 | - } |
|
| 939 | - else |
|
| 969 | + } else |
|
| 940 | 970 | { |
| 941 | 971 | $this->error=$this->db->lasterror(); |
| 942 | 972 | $this->db->rollback(); |
@@ -966,15 +996,15 @@ discard block |
||
| 966 | 996 | |
| 967 | 997 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
| 968 | 998 | $sql.= " WHERE element_id = ".$this->id; |
| 969 | - if ($listId) |
|
| 970 | - $sql.= " AND fk_c_type_contact IN (".$listId.")"; |
|
| 999 | + if ($listId) { |
|
| 1000 | + $sql.= " AND fk_c_type_contact IN (".$listId.")"; |
|
| 1001 | + } |
|
| 971 | 1002 | |
| 972 | 1003 | dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
| 973 | 1004 | if ($this->db->query($sql)) |
| 974 | 1005 | { |
| 975 | 1006 | return 1; |
| 976 | - } |
|
| 977 | - else |
|
| 1007 | + } else |
|
| 978 | 1008 | { |
| 979 | 1009 | $this->error=$this->db->lasterror(); |
| 980 | 1010 | return -1; |
@@ -999,22 +1029,38 @@ discard block |
||
| 999 | 1029 | $tab=array(); |
| 1000 | 1030 | |
| 1001 | 1031 | $sql = "SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact"; // This field contains id of llx_socpeople or id of llx_user |
| 1002 | - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 1003 | - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 1032 | + if ($source == 'internal') { |
|
| 1033 | + $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 1034 | + } |
|
| 1035 | + if ($source == 'external' || $source == 'thirdparty') { |
|
| 1036 | + $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 1037 | + } |
|
| 1004 | 1038 | $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
| 1005 | 1039 | $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
| 1006 | 1040 | $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
| 1007 | 1041 | $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
| 1008 | - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 1009 | - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 1042 | + if ($source == 'internal') { |
|
| 1043 | + $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 1044 | + } |
|
| 1045 | + if ($source == 'external'|| $source == 'thirdparty') { |
|
| 1046 | + $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 1047 | + } |
|
| 1010 | 1048 | $sql.= " WHERE ec.element_id =".$this->id; |
| 1011 | 1049 | $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
| 1012 | 1050 | $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
| 1013 | - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 1014 | - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
| 1015 | - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
| 1051 | + if ($code) { |
|
| 1052 | + $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 1053 | + } |
|
| 1054 | + if ($source == 'internal') { |
|
| 1055 | + $sql.= " AND tc.source = 'internal'"; |
|
| 1056 | + } |
|
| 1057 | + if ($source == 'external' || $source == 'thirdparty') { |
|
| 1058 | + $sql.= " AND tc.source = 'external'"; |
|
| 1059 | + } |
|
| 1016 | 1060 | $sql.= " AND tc.active=1"; |
| 1017 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 1061 | + if ($statut >= 0) { |
|
| 1062 | + $sql.= " AND ec.statut = '".$statut."'"; |
|
| 1063 | + } |
|
| 1018 | 1064 | $sql.=" ORDER BY t.lastname ASC"; |
| 1019 | 1065 | |
| 1020 | 1066 | dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
@@ -1035,8 +1081,7 @@ discard block |
||
| 1035 | 1081 | 'nom'=>$obj->lastname, // For backward compatibility |
| 1036 | 1082 | 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
| 1037 | 1083 | 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
| 1038 | - } |
|
| 1039 | - else |
|
| 1084 | + } else |
|
| 1040 | 1085 | { |
| 1041 | 1086 | $tab[$i]=$obj->id; |
| 1042 | 1087 | } |
@@ -1045,8 +1090,7 @@ discard block |
||
| 1045 | 1090 | } |
| 1046 | 1091 | |
| 1047 | 1092 | return $tab; |
| 1048 | - } |
|
| 1049 | - else |
|
| 1093 | + } else |
|
| 1050 | 1094 | { |
| 1051 | 1095 | $this->error=$this->db->lasterror(); |
| 1052 | 1096 | dol_print_error($this->db); |
@@ -1081,8 +1125,7 @@ discard block |
||
| 1081 | 1125 | $result = $this->update_contact($rowid, $newstatut); |
| 1082 | 1126 | $this->db->free($resql); |
| 1083 | 1127 | return $result; |
| 1084 | - } |
|
| 1085 | - else |
|
| 1128 | + } else |
|
| 1086 | 1129 | { |
| 1087 | 1130 | $this->error=$this->db->error(); |
| 1088 | 1131 | dol_print_error($this->db); |
@@ -1106,16 +1149,27 @@ discard block |
||
| 1106 | 1149 | // phpcs:enable |
| 1107 | 1150 | global $langs; |
| 1108 | 1151 | |
| 1109 | - if (empty($order)) $order='position'; |
|
| 1110 | - if ($order == 'position') $order.=',code'; |
|
| 1152 | + if (empty($order)) { |
|
| 1153 | + $order='position'; |
|
| 1154 | + } |
|
| 1155 | + if ($order == 'position') { |
|
| 1156 | + $order.=',code'; |
|
| 1157 | + } |
|
| 1111 | 1158 | |
| 1112 | 1159 | $tab = array(); |
| 1113 | 1160 | $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
| 1114 | 1161 | $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
| 1115 | 1162 | $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
| 1116 | - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
| 1117 | - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1118 | - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1163 | + if ($activeonly == 1) { |
|
| 1164 | + $sql.= " AND tc.active=1"; |
|
| 1165 | + } |
|
| 1166 | + // only the active types |
|
| 1167 | + if (! empty($source) && $source != 'all') { |
|
| 1168 | + $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1169 | + } |
|
| 1170 | + if (! empty($code)) { |
|
| 1171 | + $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1172 | + } |
|
| 1119 | 1173 | $sql.= $this->db->order($order,'ASC'); |
| 1120 | 1174 | |
| 1121 | 1175 | //print "sql=".$sql; |
@@ -1130,13 +1184,15 @@ discard block |
||
| 1130 | 1184 | |
| 1131 | 1185 | $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
| 1132 | 1186 | $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
| 1133 | - if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
| 1134 | - else $tab[$obj->code]=$libelle_type; |
|
| 1187 | + if (empty($option)) { |
|
| 1188 | + $tab[$obj->rowid]=$libelle_type; |
|
| 1189 | + } else { |
|
| 1190 | + $tab[$obj->code]=$libelle_type; |
|
| 1191 | + } |
|
| 1135 | 1192 | $i++; |
| 1136 | 1193 | } |
| 1137 | 1194 | return $tab; |
| 1138 | - } |
|
| 1139 | - else |
|
| 1195 | + } else |
|
| 1140 | 1196 | { |
| 1141 | 1197 | $this->error=$this->db->lasterror(); |
| 1142 | 1198 | //dol_print_error($this->db); |
@@ -1175,19 +1231,29 @@ discard block |
||
| 1175 | 1231 | |
| 1176 | 1232 | $sql = "SELECT ec.fk_socpeople"; |
| 1177 | 1233 | $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
| 1178 | - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1179 | - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1234 | + if ($source == 'internal') { |
|
| 1235 | + $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1236 | + } |
|
| 1237 | + if ($source == 'external') { |
|
| 1238 | + $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1239 | + } |
|
| 1180 | 1240 | $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
| 1181 | 1241 | $sql.= " WHERE ec.element_id = ".$id; |
| 1182 | 1242 | $sql.= " AND ec.fk_socpeople = c.rowid"; |
| 1183 | - if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
| 1184 | - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")"; |
|
| 1243 | + if ($source == 'internal') { |
|
| 1244 | + $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
| 1245 | + } |
|
| 1246 | + if ($source == 'external') { |
|
| 1247 | + $sql.= " AND c.entity IN (".getEntity('societe').")"; |
|
| 1248 | + } |
|
| 1185 | 1249 | $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
| 1186 | 1250 | $sql.= " AND tc.element = '".$element."'"; |
| 1187 | 1251 | $sql.= " AND tc.source = '".$source."'"; |
| 1188 | 1252 | $sql.= " AND tc.code = '".$code."'"; |
| 1189 | 1253 | $sql.= " AND tc.active = 1"; |
| 1190 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1254 | + if ($status) { |
|
| 1255 | + $sql.= " AND ec.statut = ".$status; |
|
| 1256 | + } |
|
| 1191 | 1257 | |
| 1192 | 1258 | dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
| 1193 | 1259 | $resql=$this->db->query($sql); |
@@ -1198,8 +1264,7 @@ discard block |
||
| 1198 | 1264 | $result[$i]=$obj->fk_socpeople; |
| 1199 | 1265 | $i++; |
| 1200 | 1266 | } |
| 1201 | - } |
|
| 1202 | - else |
|
| 1267 | + } else |
|
| 1203 | 1268 | { |
| 1204 | 1269 | $this->error=$this->db->error(); |
| 1205 | 1270 | return null; |
@@ -1218,9 +1283,13 @@ discard block |
||
| 1218 | 1283 | function fetch_contact($contactid=null) |
| 1219 | 1284 | { |
| 1220 | 1285 | // phpcs:enable |
| 1221 | - if (empty($contactid)) $contactid=$this->contactid; |
|
| 1286 | + if (empty($contactid)) { |
|
| 1287 | + $contactid=$this->contactid; |
|
| 1288 | + } |
|
| 1222 | 1289 | |
| 1223 | - if (empty($contactid)) return 0; |
|
| 1290 | + if (empty($contactid)) { |
|
| 1291 | + return 0; |
|
| 1292 | + } |
|
| 1224 | 1293 | |
| 1225 | 1294 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
| 1226 | 1295 | $contact = new Contact($this->db); |
@@ -1241,14 +1310,16 @@ discard block |
||
| 1241 | 1310 | // phpcs:enable |
| 1242 | 1311 | global $conf; |
| 1243 | 1312 | |
| 1244 | - if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
|
| 1245 | - return 0; |
|
| 1313 | + if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) { |
|
| 1314 | + return 0; |
|
| 1315 | + } |
|
| 1246 | 1316 | |
| 1247 | 1317 | require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
| 1248 | 1318 | |
| 1249 | 1319 | $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
| 1250 | - if ($force_thirdparty_id) |
|
| 1251 | - $idtofetch = $force_thirdparty_id; |
|
| 1320 | + if ($force_thirdparty_id) { |
|
| 1321 | + $idtofetch = $force_thirdparty_id; |
|
| 1322 | + } |
|
| 1252 | 1323 | |
| 1253 | 1324 | if ($idtofetch) { |
| 1254 | 1325 | $thirdparty = new Societe($this->db); |
@@ -1261,8 +1332,9 @@ discard block |
||
| 1261 | 1332 | } |
| 1262 | 1333 | |
| 1263 | 1334 | return $result; |
| 1264 | - } else |
|
| 1265 | - return -1; |
|
| 1335 | + } else { |
|
| 1336 | + return -1; |
|
| 1337 | + } |
|
| 1266 | 1338 | } |
| 1267 | 1339 | |
| 1268 | 1340 | |
@@ -1308,18 +1380,24 @@ discard block |
||
| 1308 | 1380 | dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
| 1309 | 1381 | |
| 1310 | 1382 | $idtype=$this->barcode_type; |
| 1311 | - if (empty($idtype) && $idtype != '0') // If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined |
|
| 1383 | + if (empty($idtype) && $idtype != '0') { |
|
| 1384 | + // If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined |
|
| 1312 | 1385 | { |
| 1313 | 1386 | if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
| 1314 | - else if ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1315 | - else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING); |
|
| 1387 | + } else if ($this->element == 'societe') { |
|
| 1388 | + $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1389 | + } else { |
|
| 1390 | + dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING); |
|
| 1391 | + } |
|
| 1316 | 1392 | } |
| 1317 | 1393 | |
| 1318 | 1394 | if ($idtype > 0) |
| 1319 | 1395 | { |
| 1320 | - if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) // If data not already loaded |
|
| 1396 | + if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) { |
|
| 1397 | + // If data not already loaded |
|
| 1321 | 1398 | { |
| 1322 | 1399 | $sql = "SELECT rowid, code, libelle as label, coder"; |
| 1400 | + } |
|
| 1323 | 1401 | $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
| 1324 | 1402 | $sql.= " WHERE rowid = ".$idtype; |
| 1325 | 1403 | dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
@@ -1332,8 +1410,7 @@ discard block |
||
| 1332 | 1410 | $this->barcode_type_label = $obj->label; |
| 1333 | 1411 | $this->barcode_type_coder = $obj->coder; |
| 1334 | 1412 | return 1; |
| 1335 | - } |
|
| 1336 | - else |
|
| 1413 | + } else |
|
| 1337 | 1414 | { |
| 1338 | 1415 | dol_print_error($this->db); |
| 1339 | 1416 | return -1; |
@@ -1354,8 +1431,13 @@ discard block |
||
| 1354 | 1431 | // phpcs:enable |
| 1355 | 1432 | include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
| 1356 | 1433 | |
| 1357 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1358 | - if (empty($this->fk_project)) return 0; |
|
| 1434 | + if (empty($this->fk_project) && ! empty($this->fk_projet)) { |
|
| 1435 | + $this->fk_project = $this->fk_projet; |
|
| 1436 | + } |
|
| 1437 | + // For backward compatibility |
|
| 1438 | + if (empty($this->fk_project)) { |
|
| 1439 | + return 0; |
|
| 1440 | + } |
|
| 1359 | 1441 | |
| 1360 | 1442 | $project = new Project($this->db); |
| 1361 | 1443 | $result = $project->fetch($this->fk_project); |
@@ -1376,7 +1458,9 @@ discard block |
||
| 1376 | 1458 | // phpcs:enable |
| 1377 | 1459 | include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
| 1378 | 1460 | |
| 1379 | - if (empty($this->fk_product)) return 0; |
|
| 1461 | + if (empty($this->fk_product)) { |
|
| 1462 | + return 0; |
|
| 1463 | + } |
|
| 1380 | 1464 | |
| 1381 | 1465 | $product = new Product($this->db); |
| 1382 | 1466 | $result = $product->fetch($this->fk_product); |
@@ -1410,9 +1494,15 @@ discard block |
||
| 1410 | 1494 | function fetch_origin() |
| 1411 | 1495 | { |
| 1412 | 1496 | // phpcs:enable |
| 1413 | - if ($this->origin == 'shipping') $this->origin = 'expedition'; |
|
| 1414 | - if ($this->origin == 'delivery') $this->origin = 'livraison'; |
|
| 1415 | - if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur'; |
|
| 1497 | + if ($this->origin == 'shipping') { |
|
| 1498 | + $this->origin = 'expedition'; |
|
| 1499 | + } |
|
| 1500 | + if ($this->origin == 'delivery') { |
|
| 1501 | + $this->origin = 'livraison'; |
|
| 1502 | + } |
|
| 1503 | + if ($this->origin == 'order_supplier') { |
|
| 1504 | + $this->origin = 'commandeFournisseur'; |
|
| 1505 | + } |
|
| 1416 | 1506 | |
| 1417 | 1507 | $origin = $this->origin; |
| 1418 | 1508 | |
@@ -1504,29 +1594,48 @@ discard block |
||
| 1504 | 1594 | { |
| 1505 | 1595 | global $user,$langs,$conf; |
| 1506 | 1596 | |
| 1507 | - if (empty($table)) $table=$this->table_element; |
|
| 1508 | - if (empty($id)) $id=$this->id; |
|
| 1509 | - if (empty($format)) $format='text'; |
|
| 1510 | - if (empty($id_field)) $id_field='rowid'; |
|
| 1597 | + if (empty($table)) { |
|
| 1598 | + $table=$this->table_element; |
|
| 1599 | + } |
|
| 1600 | + if (empty($id)) { |
|
| 1601 | + $id=$this->id; |
|
| 1602 | + } |
|
| 1603 | + if (empty($format)) { |
|
| 1604 | + $format='text'; |
|
| 1605 | + } |
|
| 1606 | + if (empty($id_field)) { |
|
| 1607 | + $id_field='rowid'; |
|
| 1608 | + } |
|
| 1511 | 1609 | |
| 1512 | 1610 | $error=0; |
| 1513 | 1611 | |
| 1514 | 1612 | $this->db->begin(); |
| 1515 | 1613 | |
| 1516 | 1614 | // Special case |
| 1517 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1518 | - if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod'; |
|
| 1615 | + if ($table == 'product' && $field == 'note_private') { |
|
| 1616 | + $field='note'; |
|
| 1617 | + } |
|
| 1618 | + if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) { |
|
| 1619 | + $fk_user_field = 'fk_user_mod'; |
|
| 1620 | + } |
|
| 1519 | 1621 | |
| 1520 | 1622 | $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
| 1521 | 1623 | |
| 1522 | - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1523 | - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
| 1524 | - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1624 | + if ($format == 'text') { |
|
| 1625 | + $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1626 | + } else if ($format == 'int') { |
|
| 1627 | + $sql.= $field." = ".$this->db->escape($value); |
|
| 1628 | + } else if ($format == 'date') { |
|
| 1629 | + $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1630 | + } |
|
| 1525 | 1631 | |
| 1526 | 1632 | if ($fk_user_field) |
| 1527 | 1633 | { |
| 1528 | - if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1529 | - elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1634 | + if (! empty($fuser) && is_object($fuser)) { |
|
| 1635 | + $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1636 | + } elseif (empty($fuser) || $fuser != 'none') { |
|
| 1637 | + $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1638 | + } |
|
| 1530 | 1639 | } |
| 1531 | 1640 | |
| 1532 | 1641 | $sql.= " WHERE ".$id_field." = ".$id; |
@@ -1541,28 +1650,32 @@ discard block |
||
| 1541 | 1650 | if (empty($this->fields) && method_exists($this, 'fetch')) |
| 1542 | 1651 | { |
| 1543 | 1652 | $result = $this->fetch($id); |
| 1544 | - } |
|
| 1545 | - else |
|
| 1653 | + } else |
|
| 1546 | 1654 | { |
| 1547 | 1655 | $result = $this->fetchCommon($id); |
| 1548 | 1656 | } |
| 1549 | - if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1550 | - if ($result < 0) $error++; |
|
| 1657 | + if ($result >= 0) { |
|
| 1658 | + $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); |
|
| 1659 | + } |
|
| 1660 | + // This may set this->errors |
|
| 1661 | + if ($result < 0) { |
|
| 1662 | + $error++; |
|
| 1663 | + } |
|
| 1551 | 1664 | } |
| 1552 | 1665 | |
| 1553 | 1666 | if (! $error) |
| 1554 | 1667 | { |
| 1555 | - if (property_exists($this, $field)) $this->$field = $value; |
|
| 1668 | + if (property_exists($this, $field)) { |
|
| 1669 | + $this->$field = $value; |
|
| 1670 | + } |
|
| 1556 | 1671 | $this->db->commit(); |
| 1557 | 1672 | return 1; |
| 1558 | - } |
|
| 1559 | - else |
|
| 1673 | + } else |
|
| 1560 | 1674 | { |
| 1561 | 1675 | $this->db->rollback(); |
| 1562 | 1676 | return -2; |
| 1563 | 1677 | } |
| 1564 | - } |
|
| 1565 | - else |
|
| 1678 | + } else |
|
| 1566 | 1679 | { |
| 1567 | 1680 | $this->error=$this->db->lasterror(); |
| 1568 | 1681 | $this->db->rollback(); |
@@ -1589,36 +1702,66 @@ discard block |
||
| 1589 | 1702 | dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
| 1590 | 1703 | return -1; |
| 1591 | 1704 | } |
| 1592 | - if ($fieldid == 'none') return 1; |
|
| 1705 | + if ($fieldid == 'none') { |
|
| 1706 | + return 1; |
|
| 1707 | + } |
|
| 1593 | 1708 | |
| 1594 | 1709 | // Security on socid |
| 1595 | 1710 | $socid = 0; |
| 1596 | - if ($user->societe_id > 0) $socid = $user->societe_id; |
|
| 1711 | + if ($user->societe_id > 0) { |
|
| 1712 | + $socid = $user->societe_id; |
|
| 1713 | + } |
|
| 1597 | 1714 | |
| 1598 | 1715 | // this->ismultientitymanaged contains |
| 1599 | 1716 | // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
| 1600 | 1717 | $alias = 's'; |
| 1601 | - if ($this->element == 'societe') $alias = 'te'; |
|
| 1718 | + if ($this->element == 'societe') { |
|
| 1719 | + $alias = 'te'; |
|
| 1720 | + } |
|
| 1602 | 1721 | |
| 1603 | 1722 | $sql = "SELECT MAX(te.".$fieldid.")"; |
| 1604 | 1723 | $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
| 1605 | 1724 | if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
| 1606 | 1725 | $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
| 1607 | 1726 | } |
| 1608 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity |
|
| 1609 | - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid |
|
| 1610 | - else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid |
|
| 1611 | - if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1727 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1728 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1729 | + } |
|
| 1730 | + // If we need to link to societe to limit select to entity |
|
| 1731 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1732 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1733 | + } |
|
| 1734 | + // If we need to link to societe to limit select to socid |
|
| 1735 | + else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1736 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; |
|
| 1737 | + } |
|
| 1738 | + // If we need to link to societe to limit select to socid |
|
| 1739 | + if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) { |
|
| 1740 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1741 | + } |
|
| 1612 | 1742 | $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
| 1613 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1614 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1743 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1744 | + $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1745 | + } |
|
| 1746 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1747 | + $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1748 | + } |
|
| 1615 | 1749 | if (! empty($filter)) |
| 1616 | 1750 | { |
| 1617 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
| 1751 | + if (! preg_match('/^\s*AND/i', $filter)) { |
|
| 1752 | + $sql.=" AND "; |
|
| 1753 | + } |
|
| 1754 | + // For backward compatibility |
|
| 1618 | 1755 | $sql.=$filter; |
| 1619 | 1756 | } |
| 1620 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity |
|
| 1621 | - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid |
|
| 1757 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1758 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1759 | + } |
|
| 1760 | + // If we need to link to societe to limit select to entity |
|
| 1761 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1762 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1763 | + } |
|
| 1764 | + // If we need to link to societe to limit select to socid |
|
| 1622 | 1765 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
| 1623 | 1766 | if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
| 1624 | 1767 | if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
@@ -1631,9 +1774,15 @@ discard block |
||
| 1631 | 1774 | $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
| 1632 | 1775 | } |
| 1633 | 1776 | } |
| 1634 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1635 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1636 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1777 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') { |
|
| 1778 | + $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1779 | + } |
|
| 1780 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') { |
|
| 1781 | + $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1782 | + } |
|
| 1783 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') { |
|
| 1784 | + $sql.= ' AND te.rowid = ' . $socid; |
|
| 1785 | + } |
|
| 1637 | 1786 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1638 | 1787 | |
| 1639 | 1788 | $result = $this->db->query($sql); |
@@ -1651,20 +1800,44 @@ discard block |
||
| 1651 | 1800 | if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
| 1652 | 1801 | $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
| 1653 | 1802 | } |
| 1654 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity |
|
| 1655 | - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid |
|
| 1656 | - else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid |
|
| 1657 | - if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1803 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1804 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1805 | + } |
|
| 1806 | + // If we need to link to societe to limit select to entity |
|
| 1807 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1808 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1809 | + } |
|
| 1810 | + // If we need to link to societe to limit select to socid |
|
| 1811 | + else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1812 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; |
|
| 1813 | + } |
|
| 1814 | + // If we need to link to societe to limit select to socid |
|
| 1815 | + if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) { |
|
| 1816 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1817 | + } |
|
| 1658 | 1818 | $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
| 1659 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1660 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1819 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1820 | + $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1821 | + } |
|
| 1822 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1823 | + $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1824 | + } |
|
| 1661 | 1825 | if (! empty($filter)) |
| 1662 | 1826 | { |
| 1663 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
| 1827 | + if (! preg_match('/^\s*AND/i', $filter)) { |
|
| 1828 | + $sql.=" AND "; |
|
| 1829 | + } |
|
| 1830 | + // For backward compatibility |
|
| 1664 | 1831 | $sql.=$filter; |
| 1665 | 1832 | } |
| 1666 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity |
|
| 1667 | - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid |
|
| 1833 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1834 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1835 | + } |
|
| 1836 | + // If we need to link to societe to limit select to entity |
|
| 1837 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1838 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1839 | + } |
|
| 1840 | + // If we need to link to societe to limit select to socid |
|
| 1668 | 1841 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
| 1669 | 1842 | if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
| 1670 | 1843 | if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
@@ -1677,9 +1850,15 @@ discard block |
||
| 1677 | 1850 | $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
| 1678 | 1851 | } |
| 1679 | 1852 | } |
| 1680 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1681 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1682 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1853 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') { |
|
| 1854 | + $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1855 | + } |
|
| 1856 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') { |
|
| 1857 | + $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1858 | + } |
|
| 1859 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') { |
|
| 1860 | + $sql.= ' AND te.rowid = ' . $socid; |
|
| 1861 | + } |
|
| 1683 | 1862 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1684 | 1863 | // Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null |
| 1685 | 1864 | |
@@ -1711,8 +1890,11 @@ discard block |
||
| 1711 | 1890 | $i = 0; |
| 1712 | 1891 | while ($i < $num) |
| 1713 | 1892 | { |
| 1714 | - if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1715 | - else $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1893 | + if ($source == 'thirdparty') { |
|
| 1894 | + $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1895 | + } else { |
|
| 1896 | + $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1897 | + } |
|
| 1716 | 1898 | $i++; |
| 1717 | 1899 | } |
| 1718 | 1900 | return $contactAlreadySelected; |
@@ -1736,14 +1918,19 @@ discard block |
||
| 1736 | 1918 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1737 | 1919 | if ($this->table_element == 'actioncomm') |
| 1738 | 1920 | { |
| 1739 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1740 | - else $sql.= ' SET fk_project = NULL'; |
|
| 1921 | + if ($projectid) { |
|
| 1922 | + $sql.= ' SET fk_project = '.$projectid; |
|
| 1923 | + } else { |
|
| 1924 | + $sql.= ' SET fk_project = NULL'; |
|
| 1925 | + } |
|
| 1741 | 1926 | $sql.= ' WHERE id = '.$this->id; |
| 1742 | - } |
|
| 1743 | - else |
|
| 1927 | + } else |
|
| 1744 | 1928 | { |
| 1745 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1746 | - else $sql.= ' SET fk_projet = NULL'; |
|
| 1929 | + if ($projectid) { |
|
| 1930 | + $sql.= ' SET fk_projet = '.$projectid; |
|
| 1931 | + } else { |
|
| 1932 | + $sql.= ' SET fk_projet = NULL'; |
|
| 1933 | + } |
|
| 1747 | 1934 | $sql.= ' WHERE rowid = '.$this->id; |
| 1748 | 1935 | } |
| 1749 | 1936 | |
@@ -1752,8 +1939,7 @@ discard block |
||
| 1752 | 1939 | { |
| 1753 | 1940 | $this->fk_project = $projectid; |
| 1754 | 1941 | return 1; |
| 1755 | - } |
|
| 1756 | - else |
|
| 1942 | + } else |
|
| 1757 | 1943 | { |
| 1758 | 1944 | dol_print_error($this->db); |
| 1759 | 1945 | return -1; |
@@ -1773,8 +1959,12 @@ discard block |
||
| 1773 | 1959 | { |
| 1774 | 1960 | // TODO uniformize field name |
| 1775 | 1961 | $fieldname = 'fk_mode_reglement'; |
| 1776 | - if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
|
| 1777 | - if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
|
| 1962 | + if ($this->element == 'societe') { |
|
| 1963 | + $fieldname = 'mode_reglement'; |
|
| 1964 | + } |
|
| 1965 | + if (get_class($this) == 'Fournisseur') { |
|
| 1966 | + $fieldname = 'mode_reglement_supplier'; |
|
| 1967 | + } |
|
| 1778 | 1968 | |
| 1779 | 1969 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1780 | 1970 | $sql .= ' SET '.$fieldname.' = '.$id; |
@@ -1784,17 +1974,17 @@ discard block |
||
| 1784 | 1974 | { |
| 1785 | 1975 | $this->mode_reglement_id = $id; |
| 1786 | 1976 | // for supplier |
| 1787 | - if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
|
| 1977 | + if (get_class($this) == 'Fournisseur') { |
|
| 1978 | + $this->mode_reglement_supplier_id = $id; |
|
| 1979 | + } |
|
| 1788 | 1980 | return 1; |
| 1789 | - } |
|
| 1790 | - else |
|
| 1981 | + } else |
|
| 1791 | 1982 | { |
| 1792 | 1983 | dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
| 1793 | 1984 | $this->error=$this->db->error(); |
| 1794 | 1985 | return -1; |
| 1795 | 1986 | } |
| 1796 | - } |
|
| 1797 | - else |
|
| 1987 | + } else |
|
| 1798 | 1988 | { |
| 1799 | 1989 | dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
| 1800 | 1990 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1824,18 +2014,18 @@ discard block |
||
| 1824 | 2014 | $this->multicurrency_code = $code; |
| 1825 | 2015 | |
| 1826 | 2016 | list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
| 1827 | - if ($rate) $this->setMulticurrencyRate($rate,2); |
|
| 2017 | + if ($rate) { |
|
| 2018 | + $this->setMulticurrencyRate($rate,2); |
|
| 2019 | + } |
|
| 1828 | 2020 | |
| 1829 | 2021 | return 1; |
| 1830 | - } |
|
| 1831 | - else |
|
| 2022 | + } else |
|
| 1832 | 2023 | { |
| 1833 | 2024 | dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
| 1834 | 2025 | $this->error=$this->db->error(); |
| 1835 | 2026 | return -1; |
| 1836 | 2027 | } |
| 1837 | - } |
|
| 1838 | - else |
|
| 2028 | + } else |
|
| 1839 | 2029 | { |
| 1840 | 2030 | dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
| 1841 | 2031 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1929,15 +2119,13 @@ discard block |
||
| 1929 | 2119 | } |
| 1930 | 2120 | |
| 1931 | 2121 | return 1; |
| 1932 | - } |
|
| 1933 | - else |
|
| 2122 | + } else |
|
| 1934 | 2123 | { |
| 1935 | 2124 | dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
| 1936 | 2125 | $this->error=$this->db->error(); |
| 1937 | 2126 | return -1; |
| 1938 | 2127 | } |
| 1939 | - } |
|
| 1940 | - else |
|
| 2128 | + } else |
|
| 1941 | 2129 | { |
| 1942 | 2130 | dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
| 1943 | 2131 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1958,8 +2146,12 @@ discard block |
||
| 1958 | 2146 | { |
| 1959 | 2147 | // TODO uniformize field name |
| 1960 | 2148 | $fieldname = 'fk_cond_reglement'; |
| 1961 | - if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
|
| 1962 | - if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
|
| 2149 | + if ($this->element == 'societe') { |
|
| 2150 | + $fieldname = 'cond_reglement'; |
|
| 2151 | + } |
|
| 2152 | + if (get_class($this) == 'Fournisseur') { |
|
| 2153 | + $fieldname = 'cond_reglement_supplier'; |
|
| 2154 | + } |
|
| 1963 | 2155 | |
| 1964 | 2156 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1965 | 2157 | $sql .= ' SET '.$fieldname.' = '.$id; |
@@ -1969,18 +2161,18 @@ discard block |
||
| 1969 | 2161 | { |
| 1970 | 2162 | $this->cond_reglement_id = $id; |
| 1971 | 2163 | // for supplier |
| 1972 | - if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
|
| 2164 | + if (get_class($this) == 'Fournisseur') { |
|
| 2165 | + $this->cond_reglement_supplier_id = $id; |
|
| 2166 | + } |
|
| 1973 | 2167 | $this->cond_reglement = $id; // for compatibility |
| 1974 | 2168 | return 1; |
| 1975 | - } |
|
| 1976 | - else |
|
| 2169 | + } else |
|
| 1977 | 2170 | { |
| 1978 | 2171 | dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
| 1979 | 2172 | $this->error=$this->db->error(); |
| 1980 | 2173 | return -1; |
| 1981 | 2174 | } |
| 1982 | - } |
|
| 1983 | - else |
|
| 2175 | + } else |
|
| 1984 | 2176 | { |
| 1985 | 2177 | dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
| 1986 | 2178 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1998,7 +2190,9 @@ discard block |
||
| 1998 | 2190 | function setDeliveryAddress($id) |
| 1999 | 2191 | { |
| 2000 | 2192 | $fieldname = 'fk_delivery_address'; |
| 2001 | - if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
|
| 2193 | + if ($this->element == 'delivery' || $this->element == 'shipping') { |
|
| 2194 | + $fieldname = 'fk_address'; |
|
| 2195 | + } |
|
| 2002 | 2196 | |
| 2003 | 2197 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
| 2004 | 2198 | $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
@@ -2007,8 +2201,7 @@ discard block |
||
| 2007 | 2201 | { |
| 2008 | 2202 | $this->fk_delivery_address = $id; |
| 2009 | 2203 | return 1; |
| 2010 | - } |
|
| 2011 | - else |
|
| 2204 | + } else |
|
| 2012 | 2205 | { |
| 2013 | 2206 | $this->error=$this->db->error(); |
| 2014 | 2207 | dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
@@ -2030,7 +2223,9 @@ discard block |
||
| 2030 | 2223 | { |
| 2031 | 2224 | global $user; |
| 2032 | 2225 | |
| 2033 | - if (empty($userused)) $userused=$user; |
|
| 2226 | + if (empty($userused)) { |
|
| 2227 | + $userused=$user; |
|
| 2228 | + } |
|
| 2034 | 2229 | |
| 2035 | 2230 | $error = 0; |
| 2036 | 2231 | |
@@ -2041,7 +2236,9 @@ discard block |
||
| 2041 | 2236 | |
| 2042 | 2237 | $this->db->begin(); |
| 2043 | 2238 | |
| 2044 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 2239 | + if ($shipping_method_id<0) { |
|
| 2240 | + $shipping_method_id='NULL'; |
|
| 2241 | + } |
|
| 2045 | 2242 | dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); |
| 2046 | 2243 | |
| 2047 | 2244 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
@@ -2058,7 +2255,9 @@ discard block |
||
| 2058 | 2255 | // Call trigger |
| 2059 | 2256 | $this->context=array('shippingmethodupdate'=>1); |
| 2060 | 2257 | $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
| 2061 | - if ($result < 0) $error++; |
|
| 2258 | + if ($result < 0) { |
|
| 2259 | + $error++; |
|
| 2260 | + } |
|
| 2062 | 2261 | // End call trigger |
| 2063 | 2262 | } |
| 2064 | 2263 | } |
@@ -2086,7 +2285,9 @@ discard block |
||
| 2086 | 2285 | dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
| 2087 | 2286 | return -1; |
| 2088 | 2287 | } |
| 2089 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 2288 | + if ($warehouse_id<0) { |
|
| 2289 | + $warehouse_id='NULL'; |
|
| 2290 | + } |
|
| 2090 | 2291 | dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); |
| 2091 | 2292 | |
| 2092 | 2293 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
@@ -2133,8 +2334,7 @@ discard block |
||
| 2133 | 2334 | { |
| 2134 | 2335 | $this->modelpdf=$modelpdf; |
| 2135 | 2336 | return 1; |
| 2136 | - } |
|
| 2137 | - else |
|
| 2337 | + } else |
|
| 2138 | 2338 | { |
| 2139 | 2339 | dol_print_error($this->db); |
| 2140 | 2340 | return 0; |
@@ -2154,7 +2354,9 @@ discard block |
||
| 2154 | 2354 | { |
| 2155 | 2355 | global $user; |
| 2156 | 2356 | |
| 2157 | - if (empty($userused)) $userused=$user; |
|
| 2357 | + if (empty($userused)) { |
|
| 2358 | + $userused=$user; |
|
| 2359 | + } |
|
| 2158 | 2360 | |
| 2159 | 2361 | $error = 0; |
| 2160 | 2362 | |
@@ -2164,7 +2366,9 @@ discard block |
||
| 2164 | 2366 | } |
| 2165 | 2367 | $this->db->begin(); |
| 2166 | 2368 | |
| 2167 | - if ($fk_account<0) $fk_account='NULL'; |
|
| 2369 | + if ($fk_account<0) { |
|
| 2370 | + $fk_account='NULL'; |
|
| 2371 | + } |
|
| 2168 | 2372 | dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); |
| 2169 | 2373 | |
| 2170 | 2374 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
@@ -2177,15 +2381,16 @@ discard block |
||
| 2177 | 2381 | dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
| 2178 | 2382 | $this->error = $this->db->lasterror(); |
| 2179 | 2383 | $error++; |
| 2180 | - } |
|
| 2181 | - else |
|
| 2384 | + } else |
|
| 2182 | 2385 | { |
| 2183 | 2386 | if (!$notrigger) |
| 2184 | 2387 | { |
| 2185 | 2388 | // Call trigger |
| 2186 | 2389 | $this->context=array('bankaccountupdate'=>1); |
| 2187 | 2390 | $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
| 2188 | - if ($result < 0) $error++; |
|
| 2391 | + if ($result < 0) { |
|
| 2392 | + $error++; |
|
| 2393 | + } |
|
| 2189 | 2394 | // End call trigger |
| 2190 | 2395 | } |
| 2191 | 2396 | } |
@@ -2193,8 +2398,7 @@ discard block |
||
| 2193 | 2398 | { |
| 2194 | 2399 | $this->db->rollback(); |
| 2195 | 2400 | return -1; |
| 2196 | - } |
|
| 2197 | - else |
|
| 2401 | + } else |
|
| 2198 | 2402 | { |
| 2199 | 2403 | $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
| 2200 | 2404 | $this->db->commit(); |
@@ -2233,8 +2437,12 @@ discard block |
||
| 2233 | 2437 | $nl=0; |
| 2234 | 2438 | $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2235 | 2439 | $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
| 2236 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2237 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2440 | + if (! $renum) { |
|
| 2441 | + $sql.= ' AND rang = 0'; |
|
| 2442 | + } |
|
| 2443 | + if ($renum) { |
|
| 2444 | + $sql.= ' AND rang <> 0'; |
|
| 2445 | + } |
|
| 2238 | 2446 | |
| 2239 | 2447 | dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
| 2240 | 2448 | $resql = $this->db->query($sql); |
@@ -2242,8 +2450,9 @@ discard block |
||
| 2242 | 2450 | { |
| 2243 | 2451 | $row = $this->db->fetch_row($resql); |
| 2244 | 2452 | $nl = $row[0]; |
| 2453 | + } else { |
|
| 2454 | + dol_print_error($this->db); |
|
| 2245 | 2455 | } |
| 2246 | - else dol_print_error($this->db); |
|
| 2247 | 2456 | if ($nl > 0) |
| 2248 | 2457 | { |
| 2249 | 2458 | // The goal of this part is to reorder all lines, with all children lines sharing the same |
@@ -2253,7 +2462,9 @@ discard block |
||
| 2253 | 2462 | // We first search all lines that are parent lines (for multilevel details lines) |
| 2254 | 2463 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2255 | 2464 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
| 2256 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2465 | + if ($fk_parent_line) { |
|
| 2466 | + $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2467 | + } |
|
| 2257 | 2468 | $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
| 2258 | 2469 | |
| 2259 | 2470 | dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
@@ -2285,8 +2496,7 @@ discard block |
||
| 2285 | 2496 | $this->updateRangOfLine($row, ($key+1)); |
| 2286 | 2497 | } |
| 2287 | 2498 | } |
| 2288 | - } |
|
| 2289 | - else |
|
| 2499 | + } else |
|
| 2290 | 2500 | { |
| 2291 | 2501 | dol_print_error($this->db); |
| 2292 | 2502 | } |
@@ -2379,7 +2589,9 @@ discard block |
||
| 2379 | 2589 | function updateRangOfLine($rowid,$rang) |
| 2380 | 2590 | { |
| 2381 | 2591 | $fieldposition = 'rang'; |
| 2382 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
|
| 2592 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) { |
|
| 2593 | + $fieldposition = 'position'; |
|
| 2594 | + } |
|
| 2383 | 2595 | |
| 2384 | 2596 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2385 | 2597 | $sql.= ' WHERE rowid = '.$rowid; |
@@ -2420,7 +2632,9 @@ discard block |
||
| 2420 | 2632 | if ($rang > 1) |
| 2421 | 2633 | { |
| 2422 | 2634 | $fieldposition = 'rang'; |
| 2423 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
|
| 2635 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) { |
|
| 2636 | + $fieldposition = 'position'; |
|
| 2637 | + } |
|
| 2424 | 2638 | |
| 2425 | 2639 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
| 2426 | 2640 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
@@ -2433,8 +2647,7 @@ discard block |
||
| 2433 | 2647 | { |
| 2434 | 2648 | dol_print_error($this->db); |
| 2435 | 2649 | } |
| 2436 | - } |
|
| 2437 | - else |
|
| 2650 | + } else |
|
| 2438 | 2651 | { |
| 2439 | 2652 | dol_print_error($this->db); |
| 2440 | 2653 | } |
@@ -2454,7 +2667,9 @@ discard block |
||
| 2454 | 2667 | if ($rang < $max) |
| 2455 | 2668 | { |
| 2456 | 2669 | $fieldposition = 'rang'; |
| 2457 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
|
| 2670 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) { |
|
| 2671 | + $fieldposition = 'position'; |
|
| 2672 | + } |
|
| 2458 | 2673 | |
| 2459 | 2674 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2460 | 2675 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
@@ -2467,8 +2682,7 @@ discard block |
||
| 2467 | 2682 | { |
| 2468 | 2683 | dol_print_error($this->db); |
| 2469 | 2684 | } |
| 2470 | - } |
|
| 2471 | - else |
|
| 2685 | + } else |
|
| 2472 | 2686 | { |
| 2473 | 2687 | dol_print_error($this->db); |
| 2474 | 2688 | } |
@@ -2539,8 +2753,7 @@ discard block |
||
| 2539 | 2753 | if (! empty($row[0])) |
| 2540 | 2754 | { |
| 2541 | 2755 | return $row[0]; |
| 2542 | - } |
|
| 2543 | - else |
|
| 2756 | + } else |
|
| 2544 | 2757 | { |
| 2545 | 2758 | return $this->getRangOfLine($fk_parent_line); |
| 2546 | 2759 | } |
@@ -2587,8 +2800,7 @@ discard block |
||
| 2587 | 2800 | { |
| 2588 | 2801 | $this->ref_ext = $ref_ext; |
| 2589 | 2802 | return 1; |
| 2590 | - } |
|
| 2591 | - else |
|
| 2803 | + } else |
|
| 2592 | 2804 | { |
| 2593 | 2805 | $this->error=$this->db->error(); |
| 2594 | 2806 | return -1; |
@@ -2622,7 +2834,9 @@ discard block |
||
| 2622 | 2834 | } |
| 2623 | 2835 | // Special cas |
| 2624 | 2836 | //var_dump($this->table_element);exit; |
| 2625 | - if ($this->table_element == 'product') $suffix=''; |
|
| 2837 | + if ($this->table_element == 'product') { |
|
| 2838 | + $suffix=''; |
|
| 2839 | + } |
|
| 2626 | 2840 | |
| 2627 | 2841 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 2628 | 2842 | $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL"); |
@@ -2632,16 +2846,17 @@ discard block |
||
| 2632 | 2846 | dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
| 2633 | 2847 | if ($this->db->query($sql)) |
| 2634 | 2848 | { |
| 2635 | - if ($suffix == '_public') $this->note_public = $note; |
|
| 2636 | - else if ($suffix == '_private') $this->note_private = $note; |
|
| 2637 | - else |
|
| 2849 | + if ($suffix == '_public') { |
|
| 2850 | + $this->note_public = $note; |
|
| 2851 | + } else if ($suffix == '_private') { |
|
| 2852 | + $this->note_private = $note; |
|
| 2853 | + } else |
|
| 2638 | 2854 | { |
| 2639 | 2855 | $this->note = $note; // deprecated |
| 2640 | 2856 | $this->note_private = $note; |
| 2641 | 2857 | } |
| 2642 | 2858 | return 1; |
| 2643 | - } |
|
| 2644 | - else |
|
| 2859 | + } else |
|
| 2645 | 2860 | { |
| 2646 | 2861 | $this->error=$this->db->lasterror(); |
| 2647 | 2862 | return -1; |
@@ -2681,36 +2896,45 @@ discard block |
||
| 2681 | 2896 | |
| 2682 | 2897 | // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) |
| 2683 | 2898 | $MODULE = ""; |
| 2684 | - if ($this->element == 'propal') |
|
| 2685 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2686 | - elseif ($this->element == 'order') |
|
| 2687 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2688 | - elseif ($this->element == 'facture') |
|
| 2689 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2690 | - elseif ($this->element == 'facture_fourn') |
|
| 2691 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2692 | - elseif ($this->element == 'order_supplier') |
|
| 2693 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2694 | - elseif ($this->element == 'supplier_proposal') |
|
| 2695 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2899 | + if ($this->element == 'propal') { |
|
| 2900 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2901 | + } elseif ($this->element == 'order') { |
|
| 2902 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2903 | + } elseif ($this->element == 'facture') { |
|
| 2904 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2905 | + } elseif ($this->element == 'facture_fourn') { |
|
| 2906 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2907 | + } elseif ($this->element == 'order_supplier') { |
|
| 2908 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2909 | + } elseif ($this->element == 'supplier_proposal') { |
|
| 2910 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2911 | + } |
|
| 2696 | 2912 | |
| 2697 | 2913 | if (! empty($MODULE)) { |
| 2698 | 2914 | if (! empty($conf->global->$MODULE)) { |
| 2699 | 2915 | $modsactivated = explode(',', $conf->global->$MODULE); |
| 2700 | 2916 | foreach ($modsactivated as $mod) { |
| 2701 | - if ($conf->$mod->enabled) |
|
| 2702 | - return 1; // update was disabled by specific setup |
|
| 2917 | + if ($conf->$mod->enabled) { |
|
| 2918 | + return 1; |
|
| 2919 | + } |
|
| 2920 | + // update was disabled by specific setup |
|
| 2703 | 2921 | } |
| 2704 | 2922 | } |
| 2705 | 2923 | } |
| 2706 | 2924 | |
| 2707 | 2925 | include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
| 2708 | 2926 | |
| 2709 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 2927 | + if ($roundingadjust == '-1') { |
|
| 2928 | + $roundingadjust='auto'; |
|
| 2929 | + } |
|
| 2930 | + // For backward compatibility |
|
| 2710 | 2931 | |
| 2711 | 2932 | $forcedroundingmode=$roundingadjust; |
| 2712 | - if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2713 | - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
| 2933 | + if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) { |
|
| 2934 | + $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2935 | + } elseif ($forcedroundingmode == 'auto') { |
|
| 2936 | + $forcedroundingmode='0'; |
|
| 2937 | + } |
|
| 2714 | 2938 | |
| 2715 | 2939 | $error=0; |
| 2716 | 2940 | |
@@ -2733,15 +2957,22 @@ discard block |
||
| 2733 | 2957 | |
| 2734 | 2958 | $sql = 'SELECT rowid, qty, '.$fieldup.' as up, remise_percent, total_ht, '.$fieldtva.' as total_tva, total_ttc, '.$fieldlocaltax1.' as total_localtax1, '.$fieldlocaltax2.' as total_localtax2,'; |
| 2735 | 2959 | $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
| 2736 | - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
| 2960 | + if ($this->table_element_line == 'facturedet') { |
|
| 2961 | + $sql.= ', situation_percent'; |
|
| 2962 | + } |
|
| 2737 | 2963 | $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
| 2738 | 2964 | $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2739 | 2965 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
| 2740 | 2966 | if ($exclspec) |
| 2741 | 2967 | { |
| 2742 | 2968 | $product_field='product_type'; |
| 2743 | - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
| 2744 | - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2969 | + if ($this->table_element_line == 'contratdet') { |
|
| 2970 | + $product_field=''; |
|
| 2971 | + } |
|
| 2972 | + // contratdet table has no product_type field |
|
| 2973 | + if ($product_field) { |
|
| 2974 | + $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2975 | + } |
|
| 2745 | 2976 | } |
| 2746 | 2977 | $sql.= ' ORDER by rowid'; // We want to be sure to always use same order of line to not change lines differently when option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND is used |
| 2747 | 2978 | |
@@ -2771,9 +3002,11 @@ discard block |
||
| 2771 | 3002 | $parameters=array('fk_element' => $obj->rowid); |
| 2772 | 3003 | $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 2773 | 3004 | |
| 2774 | - if (empty($reshook) && $forcedroundingmode == '0') // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' |
|
| 3005 | + if (empty($reshook) && $forcedroundingmode == '0') { |
|
| 3006 | + // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' |
|
| 2775 | 3007 | { |
| 2776 | 3008 | $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
| 3009 | + } |
|
| 2777 | 3010 | $tmpcal=calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->product_type, $seller, $localtax_array, (isset($obj->situation_percent) ? $obj->situation_percent : 100), $multicurrency_tx); |
| 2778 | 3011 | $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
| 2779 | 3012 | if ($diff) |
@@ -2781,7 +3014,9 @@ discard block |
||
| 2781 | 3014 | $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
| 2782 | 3015 | dol_syslog('We found unconsistent data into detailed line (difference of '.$diff.') for line rowid = '.$obj->rowid." (total vat of line calculated=".$tmpcal[1].", database=".$obj->total_tva."). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix); |
| 2783 | 3016 | $resqlfix=$this->db->query($sqlfix); |
| 2784 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 3017 | + if (! $resqlfix) { |
|
| 3018 | + dol_print_error($this->db,'Failed to update line'); |
|
| 3019 | + } |
|
| 2785 | 3020 | $obj->total_tva = $tmpcal[1]; |
| 2786 | 3021 | $obj->total_ttc = $tmpcal[2]; |
| 2787 | 3022 | // |
@@ -2797,16 +3032,24 @@ discard block |
||
| 2797 | 3032 | $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
| 2798 | 3033 | $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
| 2799 | 3034 | |
| 2800 | - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
| 2801 | - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
| 2802 | - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 3035 | + if (! isset($total_ht_by_vats[$obj->vatrate])) { |
|
| 3036 | + $total_ht_by_vats[$obj->vatrate]=0; |
|
| 3037 | + } |
|
| 3038 | + if (! isset($total_tva_by_vats[$obj->vatrate])) { |
|
| 3039 | + $total_tva_by_vats[$obj->vatrate]=0; |
|
| 3040 | + } |
|
| 3041 | + if (! isset($total_ttc_by_vats[$obj->vatrate])) { |
|
| 3042 | + $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 3043 | + } |
|
| 2803 | 3044 | $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
| 2804 | 3045 | $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
| 2805 | 3046 | $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
| 2806 | 3047 | |
| 2807 | - if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 3048 | + if ($forcedroundingmode == '1') { |
|
| 3049 | + // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 2808 | 3050 | { |
| 2809 | 3051 | $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
| 3052 | + } |
|
| 2810 | 3053 | $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
| 2811 | 3054 | //print 'Line '.$i.' rowid='.$obj->rowid.' vat_rate='.$obj->vatrate.' total_ht='.$obj->total_ht.' total_tva='.$obj->total_tva.' total_ttc='.$obj->total_ttc.' total_ht_by_vats='.$total_ht_by_vats[$obj->vatrate].' total_tva_by_vats='.$total_tva_by_vats[$obj->vatrate].' (new calculation = '.$tmpvat.') total_ttc_by_vats='.$total_ttc_by_vats[$obj->vatrate].($diff?" => DIFF":"")."<br>\n"; |
| 2812 | 3055 | if ($diff) |
@@ -2815,7 +3058,9 @@ discard block |
||
| 2815 | 3058 | $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".($obj->total_tva - $diff).", total_ttc = ".($obj->total_ttc - $diff)." WHERE rowid = ".$obj->rowid; |
| 2816 | 3059 | dol_syslog('We found a difference of '.$diff.' for line rowid = '.$obj->rowid.". We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix); |
| 2817 | 3060 | $resqlfix=$this->db->query($sqlfix); |
| 2818 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 3061 | + if (! $resqlfix) { |
|
| 3062 | + dol_print_error($this->db,'Failed to update line'); |
|
| 3063 | + } |
|
| 2819 | 3064 | $this->total_tva -= $diff; |
| 2820 | 3065 | $this->total_ttc -= $diff; |
| 2821 | 3066 | $total_tva_by_vats[$obj->vatrate] -= $diff; |
@@ -2856,11 +3101,21 @@ discard block |
||
| 2856 | 3101 | $fieldlocaltax2='localtax2'; |
| 2857 | 3102 | $fieldttc='total_ttc'; |
| 2858 | 3103 | // Specific code for backward compatibility with old field names |
| 2859 | - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
| 2860 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
| 2861 | - if ($this->element == 'propal') $fieldttc='total'; |
|
| 2862 | - if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
| 2863 | - if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
| 3104 | + if ($this->element == 'facture' || $this->element == 'facturerec') { |
|
| 3105 | + $fieldht='total'; |
|
| 3106 | + } |
|
| 3107 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { |
|
| 3108 | + $fieldtva='total_tva'; |
|
| 3109 | + } |
|
| 3110 | + if ($this->element == 'propal') { |
|
| 3111 | + $fieldttc='total'; |
|
| 3112 | + } |
|
| 3113 | + if ($this->element == 'expensereport') { |
|
| 3114 | + $fieldtva='total_tva'; |
|
| 3115 | + } |
|
| 3116 | + if ($this->element == 'supplier_proposal') { |
|
| 3117 | + $fieldttc='total'; |
|
| 3118 | + } |
|
| 2864 | 3119 | |
| 2865 | 3120 | if (empty($nodatabaseupdate)) |
| 2866 | 3121 | { |
@@ -2889,13 +3144,11 @@ discard block |
||
| 2889 | 3144 | if (! $error) |
| 2890 | 3145 | { |
| 2891 | 3146 | return 1; |
| 2892 | - } |
|
| 2893 | - else |
|
| 3147 | + } else |
|
| 2894 | 3148 | { |
| 2895 | 3149 | return -1; |
| 2896 | 3150 | } |
| 2897 | - } |
|
| 2898 | - else |
|
| 3151 | + } else |
|
| 2899 | 3152 | { |
| 2900 | 3153 | dol_print_error($this->db,'Bad request in update_price'); |
| 2901 | 3154 | return -1; |
@@ -2918,10 +3171,18 @@ discard block |
||
| 2918 | 3171 | $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
| 2919 | 3172 | |
| 2920 | 3173 | // Special case |
| 2921 | - if ($origin == 'order') $origin='commande'; |
|
| 2922 | - if ($origin == 'invoice') $origin='facture'; |
|
| 2923 | - if ($origin == 'invoice_template') $origin='facturerec'; |
|
| 2924 | - if ($origin == 'supplierorder') $origin='order_supplier'; |
|
| 3174 | + if ($origin == 'order') { |
|
| 3175 | + $origin='commande'; |
|
| 3176 | + } |
|
| 3177 | + if ($origin == 'invoice') { |
|
| 3178 | + $origin='facture'; |
|
| 3179 | + } |
|
| 3180 | + if ($origin == 'invoice_template') { |
|
| 3181 | + $origin='facturerec'; |
|
| 3182 | + } |
|
| 3183 | + if ($origin == 'supplierorder') { |
|
| 3184 | + $origin='order_supplier'; |
|
| 3185 | + } |
|
| 2925 | 3186 | $this->db->begin(); |
| 2926 | 3187 | |
| 2927 | 3188 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; |
@@ -2941,8 +3202,7 @@ discard block |
||
| 2941 | 3202 | { |
| 2942 | 3203 | $this->db->commit(); |
| 2943 | 3204 | return 1; |
| 2944 | - } |
|
| 2945 | - else |
|
| 3205 | + } else |
|
| 2946 | 3206 | { |
| 2947 | 3207 | $this->error=$this->db->lasterror(); |
| 2948 | 3208 | $this->db->rollback(); |
@@ -2987,12 +3247,16 @@ discard block |
||
| 2987 | 3247 | if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
| 2988 | 3248 | { |
| 2989 | 3249 | $justsource=true; // the source (id and type) is a search criteria |
| 2990 | - if (! empty($targettype)) $withtargettype=true; |
|
| 3250 | + if (! empty($targettype)) { |
|
| 3251 | + $withtargettype=true; |
|
| 3252 | + } |
|
| 2991 | 3253 | } |
| 2992 | 3254 | if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
| 2993 | 3255 | { |
| 2994 | 3256 | $justtarget=true; // the target (id and type) is a search criteria |
| 2995 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
| 3257 | + if (! empty($sourcetype)) { |
|
| 3258 | + $withsourcetype=true; |
|
| 3259 | + } |
|
| 2996 | 3260 | } |
| 2997 | 3261 | |
| 2998 | 3262 | $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
@@ -3015,15 +3279,17 @@ discard block |
||
| 3015 | 3279 | if ($justsource) |
| 3016 | 3280 | { |
| 3017 | 3281 | $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
| 3018 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 3019 | - } |
|
| 3020 | - else if ($justtarget) |
|
| 3282 | + if ($withtargettype) { |
|
| 3283 | + $sql.= " AND targettype = '".$targettype."'"; |
|
| 3284 | + } |
|
| 3285 | + } else if ($justtarget) |
|
| 3021 | 3286 | { |
| 3022 | 3287 | $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
| 3023 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 3288 | + if ($withsourcetype) { |
|
| 3289 | + $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 3290 | + } |
|
| 3024 | 3291 | } |
| 3025 | - } |
|
| 3026 | - else |
|
| 3292 | + } else |
|
| 3027 | 3293 | { |
| 3028 | 3294 | $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
| 3029 | 3295 | $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
@@ -3044,13 +3310,11 @@ discard block |
||
| 3044 | 3310 | if ($justsource) |
| 3045 | 3311 | { |
| 3046 | 3312 | $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
| 3047 | - } |
|
| 3048 | - else if ($justtarget) |
|
| 3313 | + } else if ($justtarget) |
|
| 3049 | 3314 | { |
| 3050 | 3315 | $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
| 3051 | 3316 | } |
| 3052 | - } |
|
| 3053 | - else |
|
| 3317 | + } else |
|
| 3054 | 3318 | { |
| 3055 | 3319 | if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
| 3056 | 3320 | { |
@@ -3067,10 +3331,12 @@ discard block |
||
| 3067 | 3331 | if (! empty($this->linkedObjectsIds)) |
| 3068 | 3332 | { |
| 3069 | 3333 | $tmparray = $this->linkedObjectsIds; |
| 3070 | - foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) |
|
| 3334 | + foreach($tmparray as $objecttype => $objectids) { |
|
| 3335 | + // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) |
|
| 3071 | 3336 | { |
| 3072 | 3337 | // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
| 3073 | 3338 | $module = $element = $subelement = $objecttype; |
| 3339 | + } |
|
| 3074 | 3340 | if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
| 3075 | 3341 | && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) |
| 3076 | 3342 | { |
@@ -3082,29 +3348,21 @@ discard block |
||
| 3082 | 3348 | // To work with non standard classpath or module name |
| 3083 | 3349 | if ($objecttype == 'facture') { |
| 3084 | 3350 | $classpath = 'compta/facture/class'; |
| 3085 | - } |
|
| 3086 | - else if ($objecttype == 'facturerec') { |
|
| 3351 | + } else if ($objecttype == 'facturerec') { |
|
| 3087 | 3352 | $classpath = 'compta/facture/class'; $module = 'facture'; |
| 3088 | - } |
|
| 3089 | - else if ($objecttype == 'propal') { |
|
| 3353 | + } else if ($objecttype == 'propal') { |
|
| 3090 | 3354 | $classpath = 'comm/propal/class'; |
| 3091 | - } |
|
| 3092 | - else if ($objecttype == 'supplier_proposal') { |
|
| 3355 | + } else if ($objecttype == 'supplier_proposal') { |
|
| 3093 | 3356 | $classpath = 'supplier_proposal/class'; |
| 3094 | - } |
|
| 3095 | - else if ($objecttype == 'shipping') { |
|
| 3357 | + } else if ($objecttype == 'shipping') { |
|
| 3096 | 3358 | $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
| 3097 | - } |
|
| 3098 | - else if ($objecttype == 'delivery') { |
|
| 3359 | + } else if ($objecttype == 'delivery') { |
|
| 3099 | 3360 | $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
| 3100 | - } |
|
| 3101 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
| 3361 | + } else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
| 3102 | 3362 | $classpath = 'fourn/class'; $module = 'fournisseur'; |
| 3103 | - } |
|
| 3104 | - else if ($objecttype == 'fichinter') { |
|
| 3363 | + } else if ($objecttype == 'fichinter') { |
|
| 3105 | 3364 | $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
| 3106 | - } |
|
| 3107 | - else if ($objecttype == 'subscription') { |
|
| 3365 | + } else if ($objecttype == 'subscription') { |
|
| 3108 | 3366 | $classpath = 'adherents/class'; $module = 'adherent'; |
| 3109 | 3367 | } |
| 3110 | 3368 | |
@@ -3113,20 +3371,15 @@ discard block |
||
| 3113 | 3371 | |
| 3114 | 3372 | if ($objecttype == 'order') { |
| 3115 | 3373 | $classfile = 'commande'; $classname = 'Commande'; |
| 3116 | - } |
|
| 3117 | - else if ($objecttype == 'invoice_supplier') { |
|
| 3374 | + } else if ($objecttype == 'invoice_supplier') { |
|
| 3118 | 3375 | $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
| 3119 | - } |
|
| 3120 | - else if ($objecttype == 'order_supplier') { |
|
| 3376 | + } else if ($objecttype == 'order_supplier') { |
|
| 3121 | 3377 | $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
| 3122 | - } |
|
| 3123 | - else if ($objecttype == 'supplier_proposal') { |
|
| 3378 | + } else if ($objecttype == 'supplier_proposal') { |
|
| 3124 | 3379 | $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
| 3125 | - } |
|
| 3126 | - else if ($objecttype == 'facturerec') { |
|
| 3380 | + } else if ($objecttype == 'facturerec') { |
|
| 3127 | 3381 | $classfile = 'facture-rec'; $classname = 'FactureRec'; |
| 3128 | - } |
|
| 3129 | - else if ($objecttype == 'subscription') { |
|
| 3382 | + } else if ($objecttype == 'subscription') { |
|
| 3130 | 3383 | $classfile = 'subscription'; $classname = 'Subscription'; |
| 3131 | 3384 | } |
| 3132 | 3385 | |
@@ -3139,9 +3392,11 @@ discard block |
||
| 3139 | 3392 | //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
| 3140 | 3393 | if (class_exists($classname)) |
| 3141 | 3394 | { |
| 3142 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3395 | + foreach($objectids as $i => $objectid) { |
|
| 3396 | + // $i is rowid into llx_element_element |
|
| 3143 | 3397 | { |
| 3144 | 3398 | $object = new $classname($this->db); |
| 3399 | + } |
|
| 3145 | 3400 | $ret = $object->fetch($objectid); |
| 3146 | 3401 | if ($ret >= 0) |
| 3147 | 3402 | { |
@@ -3150,16 +3405,14 @@ discard block |
||
| 3150 | 3405 | } |
| 3151 | 3406 | } |
| 3152 | 3407 | } |
| 3153 | - } |
|
| 3154 | - else |
|
| 3408 | + } else |
|
| 3155 | 3409 | { |
| 3156 | 3410 | unset($this->linkedObjectsIds[$objecttype]); |
| 3157 | 3411 | } |
| 3158 | 3412 | } |
| 3159 | 3413 | } |
| 3160 | 3414 | return 1; |
| 3161 | - } |
|
| 3162 | - else |
|
| 3415 | + } else |
|
| 3163 | 3416 | { |
| 3164 | 3417 | dol_print_error($this->db); |
| 3165 | 3418 | return -1; |
@@ -3181,8 +3434,11 @@ discard block |
||
| 3181 | 3434 | $updatesource=false; |
| 3182 | 3435 | $updatetarget=false; |
| 3183 | 3436 | |
| 3184 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
| 3185 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
| 3437 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) { |
|
| 3438 | + $updatesource=true; |
|
| 3439 | + } else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) { |
|
| 3440 | + $updatetarget=true; |
|
| 3441 | + } |
|
| 3186 | 3442 | |
| 3187 | 3443 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
| 3188 | 3444 | if ($updatesource) |
@@ -3191,8 +3447,7 @@ discard block |
||
| 3191 | 3447 | $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
| 3192 | 3448 | $sql.= " WHERE fk_target = ".$this->id; |
| 3193 | 3449 | $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
| 3194 | - } |
|
| 3195 | - else if ($updatetarget) |
|
| 3450 | + } else if ($updatetarget) |
|
| 3196 | 3451 | { |
| 3197 | 3452 | $sql.= "fk_target = ".$targetid; |
| 3198 | 3453 | $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
@@ -3204,8 +3459,7 @@ discard block |
||
| 3204 | 3459 | if ($this->db->query($sql)) |
| 3205 | 3460 | { |
| 3206 | 3461 | return 1; |
| 3207 | - } |
|
| 3208 | - else |
|
| 3462 | + } else |
|
| 3209 | 3463 | { |
| 3210 | 3464 | $this->error=$this->db->lasterror(); |
| 3211 | 3465 | return -1; |
@@ -3228,8 +3482,11 @@ discard block |
||
| 3228 | 3482 | $deletesource=false; |
| 3229 | 3483 | $deletetarget=false; |
| 3230 | 3484 | |
| 3231 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
| 3232 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
| 3485 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) { |
|
| 3486 | + $deletesource=true; |
|
| 3487 | + } else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) { |
|
| 3488 | + $deletetarget=true; |
|
| 3489 | + } |
|
| 3233 | 3490 | |
| 3234 | 3491 | $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
| 3235 | 3492 | $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
@@ -3241,20 +3498,17 @@ discard block |
||
| 3241 | 3498 | if ($rowid > 0) |
| 3242 | 3499 | { |
| 3243 | 3500 | $sql.=" rowid = ".$rowid; |
| 3244 | - } |
|
| 3245 | - else |
|
| 3501 | + } else |
|
| 3246 | 3502 | { |
| 3247 | 3503 | if ($deletesource) |
| 3248 | 3504 | { |
| 3249 | 3505 | $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
| 3250 | 3506 | $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
| 3251 | - } |
|
| 3252 | - else if ($deletetarget) |
|
| 3507 | + } else if ($deletetarget) |
|
| 3253 | 3508 | { |
| 3254 | 3509 | $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
| 3255 | 3510 | $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
| 3256 | - } |
|
| 3257 | - else |
|
| 3511 | + } else |
|
| 3258 | 3512 | { |
| 3259 | 3513 | $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
| 3260 | 3514 | $sql.= " OR"; |
@@ -3266,8 +3520,7 @@ discard block |
||
| 3266 | 3520 | if ($this->db->query($sql)) |
| 3267 | 3521 | { |
| 3268 | 3522 | return 1; |
| 3269 | - } |
|
| 3270 | - else |
|
| 3523 | + } else |
|
| 3271 | 3524 | { |
| 3272 | 3525 | $this->error=$this->db->lasterror(); |
| 3273 | 3526 | $this->errors[]=$this->error; |
@@ -3296,17 +3549,31 @@ discard block |
||
| 3296 | 3549 | $this->db->begin(); |
| 3297 | 3550 | |
| 3298 | 3551 | $fieldstatus="fk_statut"; |
| 3299 | - if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
| 3300 | - if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
| 3301 | - if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
| 3302 | - if ($elementTable == 'user') $fieldstatus="statut"; |
|
| 3303 | - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
| 3304 | - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
| 3552 | + if ($elementTable == 'facture_rec') { |
|
| 3553 | + $fieldstatus="suspended"; |
|
| 3554 | + } |
|
| 3555 | + if ($elementTable == 'mailing') { |
|
| 3556 | + $fieldstatus="statut"; |
|
| 3557 | + } |
|
| 3558 | + if ($elementTable == 'cronjob') { |
|
| 3559 | + $fieldstatus="status"; |
|
| 3560 | + } |
|
| 3561 | + if ($elementTable == 'user') { |
|
| 3562 | + $fieldstatus="statut"; |
|
| 3563 | + } |
|
| 3564 | + if ($elementTable == 'expensereport') { |
|
| 3565 | + $fieldstatus="fk_statut"; |
|
| 3566 | + } |
|
| 3567 | + if ($elementTable == 'commande_fournisseur_dispatch') { |
|
| 3568 | + $fieldstatus="status"; |
|
| 3569 | + } |
|
| 3305 | 3570 | |
| 3306 | 3571 | $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
| 3307 | 3572 | $sql.= " SET ".$fieldstatus." = ".$status; |
| 3308 | 3573 | // If status = 1 = validated, update also fk_user_valid |
| 3309 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3574 | + if ($status == 1 && $elementTable == 'expensereport') { |
|
| 3575 | + $sql.=", fk_user_valid = ".$user->id; |
|
| 3576 | + } |
|
| 3310 | 3577 | $sql.= " WHERE rowid=".$elementId; |
| 3311 | 3578 | |
| 3312 | 3579 | dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
@@ -3317,12 +3584,27 @@ discard block |
||
| 3317 | 3584 | // Try autoset of trigkey |
| 3318 | 3585 | if (empty($trigkey)) |
| 3319 | 3586 | { |
| 3320 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3321 | - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3322 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3323 | - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3324 | - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3325 | - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3587 | + if ($this->element == 'supplier_proposal' && $status == 2) { |
|
| 3588 | + $trigkey='SUPPLIER_PROPOSAL_SIGN'; |
|
| 3589 | + } |
|
| 3590 | + // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3591 | + if ($this->element == 'supplier_proposal' && $status == 3) { |
|
| 3592 | + $trigkey='SUPPLIER_PROPOSAL_REFUSE'; |
|
| 3593 | + } |
|
| 3594 | + // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3595 | + if ($this->element == 'supplier_proposal' && $status == 4) { |
|
| 3596 | + $trigkey='SUPPLIER_PROPOSAL_CLOSE'; |
|
| 3597 | + } |
|
| 3598 | + // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3599 | + if ($this->element == 'fichinter' && $status == 3) { |
|
| 3600 | + $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3601 | + } |
|
| 3602 | + if ($this->element == 'fichinter' && $status == 2) { |
|
| 3603 | + $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3604 | + } |
|
| 3605 | + if ($this->element == 'fichinter' && $status == 1) { |
|
| 3606 | + $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3607 | + } |
|
| 3326 | 3608 | } |
| 3327 | 3609 | |
| 3328 | 3610 | if ($trigkey) |
@@ -3341,22 +3623,22 @@ discard block |
||
| 3341 | 3623 | { |
| 3342 | 3624 | $this->db->commit(); |
| 3343 | 3625 | |
| 3344 | - if (empty($savElementId)) // If the element we update was $this (so $elementId is null) |
|
| 3626 | + if (empty($savElementId)) { |
|
| 3627 | + // If the element we update was $this (so $elementId is null) |
|
| 3345 | 3628 | { |
| 3346 | 3629 | $this->statut = $status; |
| 3630 | + } |
|
| 3347 | 3631 | $this->status = $status; |
| 3348 | 3632 | } |
| 3349 | 3633 | |
| 3350 | 3634 | return 1; |
| 3351 | - } |
|
| 3352 | - else |
|
| 3635 | + } else |
|
| 3353 | 3636 | { |
| 3354 | 3637 | $this->db->rollback(); |
| 3355 | 3638 | dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
| 3356 | 3639 | return -1; |
| 3357 | 3640 | } |
| 3358 | - } |
|
| 3359 | - else |
|
| 3641 | + } else |
|
| 3360 | 3642 | { |
| 3361 | 3643 | $this->error=$this->db->lasterror(); |
| 3362 | 3644 | $this->db->rollback(); |
@@ -3376,8 +3658,13 @@ discard block |
||
| 3376 | 3658 | { |
| 3377 | 3659 | global $conf; |
| 3378 | 3660 | |
| 3379 | - if (empty($id) && empty($ref)) return 0; |
|
| 3380 | - if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
| 3661 | + if (empty($id) && empty($ref)) { |
|
| 3662 | + return 0; |
|
| 3663 | + } |
|
| 3664 | + if (! empty($conf->global->MAIN_DISABLE_CANVAS)) { |
|
| 3665 | + return 0; |
|
| 3666 | + } |
|
| 3667 | + // To increase speed. Not enabled by default. |
|
| 3381 | 3668 | |
| 3382 | 3669 | // Clean parameters |
| 3383 | 3670 | $ref = trim($ref); |
@@ -3385,8 +3672,12 @@ discard block |
||
| 3385 | 3672 | $sql = "SELECT rowid, canvas"; |
| 3386 | 3673 | $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
| 3387 | 3674 | $sql.= " WHERE entity IN (".getEntity($this->element).")"; |
| 3388 | - if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
| 3389 | - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3675 | + if (! empty($id)) { |
|
| 3676 | + $sql.= " AND rowid = ".$id; |
|
| 3677 | + } |
|
| 3678 | + if (! empty($ref)) { |
|
| 3679 | + $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3680 | + } |
|
| 3390 | 3681 | |
| 3391 | 3682 | $resql = $this->db->query($sql); |
| 3392 | 3683 | if ($resql) |
@@ -3396,10 +3687,10 @@ discard block |
||
| 3396 | 3687 | { |
| 3397 | 3688 | $this->canvas = $obj->canvas; |
| 3398 | 3689 | return 1; |
| 3690 | + } else { |
|
| 3691 | + return 0; |
|
| 3399 | 3692 | } |
| 3400 | - else return 0; |
|
| 3401 | - } |
|
| 3402 | - else |
|
| 3693 | + } else |
|
| 3403 | 3694 | { |
| 3404 | 3695 | dol_print_error($this->db); |
| 3405 | 3696 | return -1; |
@@ -3436,7 +3727,9 @@ discard block |
||
| 3436 | 3727 | { |
| 3437 | 3728 | global $langs; |
| 3438 | 3729 | |
| 3439 | - if (empty($id)) $id=$this->id; |
|
| 3730 | + if (empty($id)) { |
|
| 3731 | + $id=$this->id; |
|
| 3732 | + } |
|
| 3440 | 3733 | |
| 3441 | 3734 | // Check parameters |
| 3442 | 3735 | if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
@@ -3470,18 +3763,18 @@ discard block |
||
| 3470 | 3763 | $langs->load("errors"); |
| 3471 | 3764 | //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
| 3472 | 3765 | $haschild += $obj->nb; |
| 3473 | - if (is_numeric($elementname)) // old usage |
|
| 3766 | + if (is_numeric($elementname)) { |
|
| 3767 | + // old usage |
|
| 3474 | 3768 | { |
| 3475 | 3769 | $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); |
| 3476 | 3770 | } |
| 3477 | - else // new usage: $elementname=Translation key |
|
| 3771 | + } else // new usage: $elementname=Translation key |
|
| 3478 | 3772 | { |
| 3479 | 3773 | $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
| 3480 | 3774 | } |
| 3481 | 3775 | break; // We found at least one, we stop here |
| 3482 | 3776 | } |
| 3483 | - } |
|
| 3484 | - else |
|
| 3777 | + } else |
|
| 3485 | 3778 | { |
| 3486 | 3779 | $this->errors[]=$this->db->lasterror(); |
| 3487 | 3780 | return -1; |
@@ -3491,8 +3784,9 @@ discard block |
||
| 3491 | 3784 | { |
| 3492 | 3785 | $this->errors[]="ErrorRecordHasChildren"; |
| 3493 | 3786 | return $haschild; |
| 3787 | + } else { |
|
| 3788 | + return 0; |
|
| 3494 | 3789 | } |
| 3495 | - else return 0; |
|
| 3496 | 3790 | } |
| 3497 | 3791 | |
| 3498 | 3792 | /** |
@@ -3508,12 +3802,24 @@ discard block |
||
| 3508 | 3802 | foreach($this->lines as $key => $val) |
| 3509 | 3803 | { |
| 3510 | 3804 | $qualified=0; |
| 3511 | - if ($predefined == -1) $qualified=1; |
|
| 3512 | - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
| 3513 | - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
| 3514 | - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
| 3515 | - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
| 3516 | - if ($qualified) $nb++; |
|
| 3805 | + if ($predefined == -1) { |
|
| 3806 | + $qualified=1; |
|
| 3807 | + } |
|
| 3808 | + if ($predefined == 1 && $val->fk_product > 0) { |
|
| 3809 | + $qualified=1; |
|
| 3810 | + } |
|
| 3811 | + if ($predefined == 0 && $val->fk_product <= 0) { |
|
| 3812 | + $qualified=1; |
|
| 3813 | + } |
|
| 3814 | + if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) { |
|
| 3815 | + $qualified=1; |
|
| 3816 | + } |
|
| 3817 | + if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) { |
|
| 3818 | + $qualified=1; |
|
| 3819 | + } |
|
| 3820 | + if ($qualified) { |
|
| 3821 | + $nb++; |
|
| 3822 | + } |
|
| 3517 | 3823 | } |
| 3518 | 3824 | dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
| 3519 | 3825 | return $nb; |
@@ -3577,16 +3883,24 @@ discard block |
||
| 3577 | 3883 | { |
| 3578 | 3884 | if (isset($line->qty_asked)) |
| 3579 | 3885 | { |
| 3580 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3886 | + if (empty($totalOrdered)) { |
|
| 3887 | + $totalOrdered=0; |
|
| 3888 | + } |
|
| 3889 | + // Avoid warning because $totalOrdered is '' |
|
| 3581 | 3890 | $totalOrdered+=$line->qty_asked; // defined for shipment only |
| 3582 | 3891 | } |
| 3583 | 3892 | if (isset($line->qty_shipped)) |
| 3584 | 3893 | { |
| 3585 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3894 | + if (empty($totalToShip)) { |
|
| 3895 | + $totalToShip=0; |
|
| 3896 | + } |
|
| 3897 | + // Avoid warning because $totalToShip is '' |
|
| 3586 | 3898 | $totalToShip+=$line->qty_shipped; // defined for shipment only |
| 3587 | - }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3899 | + } else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3588 | 3900 | { |
| 3589 | - if (empty($totalToShip)) $totalToShip=0; |
|
| 3901 | + if (empty($totalToShip)) { |
|
| 3902 | + $totalToShip=0; |
|
| 3903 | + } |
|
| 3590 | 3904 | $totalToShip+=$line->qty; // defined for reception only |
| 3591 | 3905 | } |
| 3592 | 3906 | |
@@ -3594,8 +3908,7 @@ discard block |
||
| 3594 | 3908 | if ($this->element == 'shipping') { |
| 3595 | 3909 | // for shipments |
| 3596 | 3910 | $qty = $line->qty_shipped ? $line->qty_shipped : 0; |
| 3597 | - } |
|
| 3598 | - else { |
|
| 3911 | + } else { |
|
| 3599 | 3912 | $qty = $line->qty ? $line->qty : 0; |
| 3600 | 3913 | } |
| 3601 | 3914 | |
@@ -3611,19 +3924,30 @@ discard block |
||
| 3611 | 3924 | |
| 3612 | 3925 | $weightUnit=0; |
| 3613 | 3926 | $volumeUnit=0; |
| 3614 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3615 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3927 | + if (! empty($weight_units)) { |
|
| 3928 | + $weightUnit = $weight_units; |
|
| 3929 | + } |
|
| 3930 | + if (! empty($volume_units)) { |
|
| 3931 | + $volumeUnit = $volume_units; |
|
| 3932 | + } |
|
| 3616 | 3933 | |
| 3617 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3618 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 3934 | + if (empty($totalWeight)) { |
|
| 3935 | + $totalWeight=0; |
|
| 3936 | + } |
|
| 3937 | + // Avoid warning because $totalWeight is '' |
|
| 3938 | + if (empty($totalVolume)) { |
|
| 3939 | + $totalVolume=0; |
|
| 3940 | + } |
|
| 3941 | + // Avoid warning because $totalVolume is '' |
|
| 3619 | 3942 | |
| 3620 | 3943 | //var_dump($line->volume_units); |
| 3621 | - if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3944 | + if ($weight_units < 50) { |
|
| 3945 | + // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3622 | 3946 | { |
| 3623 | 3947 | $trueWeightUnit=pow(10, $weightUnit); |
| 3624 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3625 | 3948 | } |
| 3626 | - else { |
|
| 3949 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3950 | + } else { |
|
| 3627 | 3951 | if ($weight_units == 99) { |
| 3628 | 3952 | // conversion 1 Pound = 0.45359237 KG |
| 3629 | 3953 | $trueWeightUnit = 0.45359237; |
@@ -3632,18 +3956,20 @@ discard block |
||
| 3632 | 3956 | // conversion 1 Ounce = 0.0283495 KG |
| 3633 | 3957 | $trueWeightUnit = 0.0283495; |
| 3634 | 3958 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3959 | + } else { |
|
| 3960 | + $totalWeight += $weight * $qty; |
|
| 3635 | 3961 | } |
| 3636 | - else |
|
| 3637 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3962 | + // This may be wrong if we mix different units |
|
| 3638 | 3963 | } |
| 3639 | - if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3964 | + if ($volume_units < 50) { |
|
| 3965 | + // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3640 | 3966 | { |
| 3641 | 3967 | //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
| 3642 | 3968 | $trueVolumeUnit=pow(10, $volumeUnit); |
| 3969 | + } |
|
| 3643 | 3970 | //print $line->volume; |
| 3644 | 3971 | $totalVolume += $volume * $qty * $trueVolumeUnit; |
| 3645 | - } |
|
| 3646 | - else |
|
| 3972 | + } else |
|
| 3647 | 3973 | { |
| 3648 | 3974 | $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
| 3649 | 3975 | } |
@@ -3675,8 +4001,7 @@ discard block |
||
| 3675 | 4001 | $this->error=$this->db->lasterror(); |
| 3676 | 4002 | $this->db->rollback(); |
| 3677 | 4003 | return -1; |
| 3678 | - } |
|
| 3679 | - else |
|
| 4004 | + } else |
|
| 3680 | 4005 | { |
| 3681 | 4006 | $this->db->commit(); |
| 3682 | 4007 | return 1; |
@@ -3728,13 +4053,11 @@ discard block |
||
| 3728 | 4053 | { |
| 3729 | 4054 | $res = $this->db->fetch_object($resql); |
| 3730 | 4055 | return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
| 3731 | - } |
|
| 3732 | - else |
|
| 4056 | + } else |
|
| 3733 | 4057 | { |
| 3734 | 4058 | return ''; |
| 3735 | 4059 | } |
| 3736 | - } |
|
| 3737 | - else |
|
| 4060 | + } else |
|
| 3738 | 4061 | { |
| 3739 | 4062 | $this->errors[] = $this->db->lasterror(); |
| 3740 | 4063 | return false; |
@@ -3771,14 +4094,14 @@ discard block |
||
| 3771 | 4094 | $this->libelle_incoterms = $obj->libelle; |
| 3772 | 4095 | } |
| 3773 | 4096 | return 1; |
| 3774 | - } |
|
| 3775 | - else |
|
| 4097 | + } else |
|
| 3776 | 4098 | { |
| 3777 | 4099 | $this->errors[] = $this->db->lasterror(); |
| 3778 | 4100 | return -1; |
| 3779 | 4101 | } |
| 4102 | + } else { |
|
| 4103 | + return -1; |
|
| 3780 | 4104 | } |
| 3781 | - else return -1; |
|
| 3782 | 4105 | } |
| 3783 | 4106 | |
| 3784 | 4107 | |
@@ -3817,7 +4140,9 @@ discard block |
||
| 3817 | 4140 | } else { |
| 3818 | 4141 | $res=include $tpl; // for debug |
| 3819 | 4142 | } |
| 3820 | - if ($res) break; |
|
| 4143 | + if ($res) { |
|
| 4144 | + break; |
|
| 4145 | + } |
|
| 3821 | 4146 | } |
| 3822 | 4147 | } |
| 3823 | 4148 | |
@@ -3847,7 +4172,9 @@ discard block |
||
| 3847 | 4172 | |
| 3848 | 4173 | // Define usemargins |
| 3849 | 4174 | $usemargins=0; |
| 3850 | - if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1; |
|
| 4175 | + if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) { |
|
| 4176 | + $usemargins=1; |
|
| 4177 | + } |
|
| 3851 | 4178 | |
| 3852 | 4179 | $num = count($this->lines); |
| 3853 | 4180 | |
@@ -3866,7 +4193,9 @@ discard block |
||
| 3866 | 4193 | print '<tr class="liste_titre nodrag nodrop">'; |
| 3867 | 4194 | |
| 3868 | 4195 | // Adds a line numbering column |
| 3869 | - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 4196 | + if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { |
|
| 4197 | + print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 4198 | + } |
|
| 3870 | 4199 | |
| 3871 | 4200 | // Description |
| 3872 | 4201 | print '<td class="linecoldescription">'.$langs->trans('Description').'</td>'; |
@@ -3883,9 +4212,13 @@ discard block |
||
| 3883 | 4212 | print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>'; |
| 3884 | 4213 | |
| 3885 | 4214 | // Multicurrency |
| 3886 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>'; |
|
| 4215 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { |
|
| 4216 | + print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>'; |
|
| 4217 | + } |
|
| 3887 | 4218 | |
| 3888 | - if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>'; |
|
| 4219 | + if ($inputalsopricewithtax) { |
|
| 4220 | + print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>'; |
|
| 4221 | + } |
|
| 3889 | 4222 | |
| 3890 | 4223 | // Qty |
| 3891 | 4224 | print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>'; |
@@ -3906,25 +4239,32 @@ discard block |
||
| 3906 | 4239 | { |
| 3907 | 4240 | if (!empty($user->rights->margins->creer)) |
| 3908 | 4241 | { |
| 3909 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 3910 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>'; |
|
| 3911 | - else |
|
| 3912 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
|
| 4242 | + if ($conf->global->MARGIN_TYPE == "1") { |
|
| 4243 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>'; |
|
| 4244 | + } else { |
|
| 4245 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
|
| 4246 | + } |
|
| 3913 | 4247 | } |
| 3914 | 4248 | |
| 3915 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3916 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>'; |
|
| 3917 | - if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3918 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
|
| 4249 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) { |
|
| 4250 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>'; |
|
| 4251 | + } |
|
| 4252 | + if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) { |
|
| 4253 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
|
| 4254 | + } |
|
| 3919 | 4255 | } |
| 3920 | 4256 | |
| 3921 | 4257 | // Total HT |
| 3922 | 4258 | print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>'; |
| 3923 | 4259 | |
| 3924 | 4260 | // Multicurrency |
| 3925 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>'; |
|
| 4261 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { |
|
| 4262 | + print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>'; |
|
| 4263 | + } |
|
| 3926 | 4264 | |
| 3927 | - if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
|
| 4265 | + if ($outputalsopricetotalwithtax) { |
|
| 4266 | + print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
|
| 4267 | + } |
|
| 3928 | 4268 | |
| 3929 | 4269 | print '<td class="linecoledit"></td>'; // No width to allow autodim |
| 3930 | 4270 | |
@@ -3954,14 +4294,15 @@ discard block |
||
| 3954 | 4294 | $line->fetch_optionals(); |
| 3955 | 4295 | |
| 3956 | 4296 | //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
| 3957 | - if (is_object($hookmanager)) // Old code is commented on preceding line. |
|
| 4297 | + if (is_object($hookmanager)) { |
|
| 4298 | + // Old code is commented on preceding line. |
|
| 3958 | 4299 | { |
| 3959 | 4300 | if (empty($line->fk_parent_line)) |
| 3960 | 4301 | { |
| 3961 | 4302 | $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
| 4303 | + } |
|
| 3962 | 4304 | $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 3963 | - } |
|
| 3964 | - else |
|
| 4305 | + } else |
|
| 3965 | 4306 | { |
| 3966 | 4307 | $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline, 'fk_parent_line'=>$line->fk_parent_line); |
| 3967 | 4308 | $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
@@ -4008,8 +4349,14 @@ discard block |
||
| 4008 | 4349 | // Show product and description |
| 4009 | 4350 | $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
| 4010 | 4351 | // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
| 4011 | - if (! empty($line->date_start)) $type=1; // deprecated |
|
| 4012 | - if (! empty($line->date_end)) $type=1; // deprecated |
|
| 4352 | + if (! empty($line->date_start)) { |
|
| 4353 | + $type=1; |
|
| 4354 | + } |
|
| 4355 | + // deprecated |
|
| 4356 | + if (! empty($line->date_end)) { |
|
| 4357 | + $type=1; |
|
| 4358 | + } |
|
| 4359 | + // deprecated |
|
| 4013 | 4360 | |
| 4014 | 4361 | // Ligne en mode visu |
| 4015 | 4362 | if ($action != 'editline' || $selected != $line->id) |
@@ -4038,8 +4385,13 @@ discard block |
||
| 4038 | 4385 | |
| 4039 | 4386 | $outputlangs = $langs; |
| 4040 | 4387 | $newlang=''; |
| 4041 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
| 4042 | - if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer |
|
| 4388 | + if (empty($newlang) && GETPOST('lang_id','aZ09')) { |
|
| 4389 | + $newlang=GETPOST('lang_id','aZ09'); |
|
| 4390 | + } |
|
| 4391 | + if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) { |
|
| 4392 | + $newlang=$this->thirdparty->default_lang; |
|
| 4393 | + } |
|
| 4394 | + // For language to language of customer |
|
| 4043 | 4395 | if (! empty($newlang)) |
| 4044 | 4396 | { |
| 4045 | 4397 | $outputlangs = new Translate("",$conf); |
@@ -4047,8 +4399,7 @@ discard block |
||
| 4047 | 4399 | } |
| 4048 | 4400 | |
| 4049 | 4401 | $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
| 4050 | - } |
|
| 4051 | - else |
|
| 4402 | + } else |
|
| 4052 | 4403 | { |
| 4053 | 4404 | $label = $line->product_label; |
| 4054 | 4405 | } |
@@ -4070,7 +4421,9 @@ discard block |
||
| 4070 | 4421 | } else { |
| 4071 | 4422 | $res=include $tpl; // for debug |
| 4072 | 4423 | } |
| 4073 | - if ($res) break; |
|
| 4424 | + if ($res) { |
|
| 4425 | + break; |
|
| 4426 | + } |
|
| 4074 | 4427 | } |
| 4075 | 4428 | } |
| 4076 | 4429 | |
@@ -4093,7 +4446,9 @@ discard block |
||
| 4093 | 4446 | } else { |
| 4094 | 4447 | $res=include $tpl; // for debug |
| 4095 | 4448 | } |
| 4096 | - if ($res) break; |
|
| 4449 | + if ($res) { |
|
| 4450 | + break; |
|
| 4451 | + } |
|
| 4097 | 4452 | } |
| 4098 | 4453 | } |
| 4099 | 4454 | } |
@@ -4120,7 +4475,9 @@ discard block |
||
| 4120 | 4475 | print '<td>'.$langs->trans('Description').'</td>'; |
| 4121 | 4476 | print '<td align="right">'.$langs->trans('VATRate').'</td>'; |
| 4122 | 4477 | print '<td align="right">'.$langs->trans('PriceUHT').'</td>'; |
| 4123 | - if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>'; |
|
| 4478 | + if (!empty($conf->multicurrency->enabled)) { |
|
| 4479 | + print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>'; |
|
| 4480 | + } |
|
| 4124 | 4481 | print '<td align="right">'.$langs->trans('Qty').'</td>'; |
| 4125 | 4482 | if($conf->global->PRODUCT_USE_UNITS) |
| 4126 | 4483 | { |
@@ -4143,8 +4500,7 @@ discard block |
||
| 4143 | 4500 | $action=''; |
| 4144 | 4501 | $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
| 4145 | 4502 | } |
| 4146 | - } |
|
| 4147 | - else |
|
| 4503 | + } else |
|
| 4148 | 4504 | { |
| 4149 | 4505 | $this->printOriginLine($line, $var, $restrictlist); |
| 4150 | 4506 | } |
@@ -4173,32 +4529,37 @@ discard block |
||
| 4173 | 4529 | if (!empty($line->date_start)) |
| 4174 | 4530 | { |
| 4175 | 4531 | $date_start=$line->date_start; |
| 4176 | - } |
|
| 4177 | - else |
|
| 4532 | + } else |
|
| 4178 | 4533 | { |
| 4179 | 4534 | $date_start=$line->date_debut_prevue; |
| 4180 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 4535 | + if ($line->date_debut_reel) { |
|
| 4536 | + $date_start=$line->date_debut_reel; |
|
| 4537 | + } |
|
| 4181 | 4538 | } |
| 4182 | 4539 | if (!empty($line->date_end)) |
| 4183 | 4540 | { |
| 4184 | 4541 | $date_end=$line->date_end; |
| 4185 | - } |
|
| 4186 | - else |
|
| 4542 | + } else |
|
| 4187 | 4543 | { |
| 4188 | 4544 | $date_end=$line->date_fin_prevue; |
| 4189 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 4545 | + if ($line->date_fin_reel) { |
|
| 4546 | + $date_end=$line->date_fin_reel; |
|
| 4547 | + } |
|
| 4190 | 4548 | } |
| 4191 | 4549 | |
| 4192 | 4550 | $this->tpl['label'] = ''; |
| 4193 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow'); |
|
| 4551 | + if (! empty($line->fk_parent_line)) { |
|
| 4552 | + $this->tpl['label'].= img_picto('', 'rightarrow'); |
|
| 4553 | + } |
|
| 4194 | 4554 | |
| 4195 | - if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
|
| 4555 | + if (($line->info_bits & 2) == 2) { |
|
| 4556 | + // TODO Not sure this is used for source object |
|
| 4196 | 4557 | { |
| 4197 | 4558 | $discount=new DiscountAbsolute($this->db); |
| 4559 | + } |
|
| 4198 | 4560 | $discount->fk_soc = $this->socid; |
| 4199 | 4561 | $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
| 4200 | - } |
|
| 4201 | - else if (! empty($line->fk_product)) |
|
| 4562 | + } else if (! empty($line->fk_product)) |
|
| 4202 | 4563 | { |
| 4203 | 4564 | $productstatic = new Product($this->db); |
| 4204 | 4565 | $productstatic->id = $line->fk_product; |
@@ -4216,13 +4577,12 @@ discard block |
||
| 4216 | 4577 | { |
| 4217 | 4578 | $this->tpl['label'].= get_date_range($date_start,$date_end); |
| 4218 | 4579 | } |
| 4219 | - } |
|
| 4220 | - else |
|
| 4580 | + } else |
|
| 4221 | 4581 | { |
| 4222 | 4582 | $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'))); |
| 4223 | 4583 | if (!empty($line->desc)) { |
| 4224 | 4584 | $this->tpl['label'].=$line->desc; |
| 4225 | - }else { |
|
| 4585 | + } else { |
|
| 4226 | 4586 | $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
| 4227 | 4587 | } |
| 4228 | 4588 | |
@@ -4235,36 +4595,35 @@ discard block |
||
| 4235 | 4595 | |
| 4236 | 4596 | if (! empty($line->desc)) |
| 4237 | 4597 | { |
| 4238 | - if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
|
| 4598 | + if ($line->desc == '(CREDIT_NOTE)') { |
|
| 4599 | + // TODO Not sure this is used for source object |
|
| 4239 | 4600 | { |
| 4240 | 4601 | $discount=new DiscountAbsolute($this->db); |
| 4602 | + } |
|
| 4241 | 4603 | $discount->fetch($line->fk_remise_except); |
| 4242 | 4604 | $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); |
| 4243 | - } |
|
| 4244 | - elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
|
| 4605 | + } elseif ($line->desc == '(DEPOSIT)') { |
|
| 4606 | + // TODO Not sure this is used for source object |
|
| 4245 | 4607 | { |
| 4246 | 4608 | $discount=new DiscountAbsolute($this->db); |
| 4609 | + } |
|
| 4247 | 4610 | $discount->fetch($line->fk_remise_except); |
| 4248 | 4611 | $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
| 4249 | - } |
|
| 4250 | - elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4612 | + } elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4251 | 4613 | { |
| 4252 | 4614 | $discount=new DiscountAbsolute($this->db); |
| 4253 | 4615 | $discount->fetch($line->fk_remise_except); |
| 4254 | 4616 | $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
| 4255 | - } |
|
| 4256 | - elseif ($line->desc == '(EXCESS PAID)') |
|
| 4617 | + } elseif ($line->desc == '(EXCESS PAID)') |
|
| 4257 | 4618 | { |
| 4258 | 4619 | $discount=new DiscountAbsolute($this->db); |
| 4259 | 4620 | $discount->fetch($line->fk_remise_except); |
| 4260 | 4621 | $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0)); |
| 4261 | - } |
|
| 4262 | - else |
|
| 4622 | + } else |
|
| 4263 | 4623 | { |
| 4264 | 4624 | $this->tpl['description'] = dol_trunc($line->desc,60); |
| 4265 | 4625 | } |
| 4266 | - } |
|
| 4267 | - else |
|
| 4626 | + } else |
|
| 4268 | 4627 | { |
| 4269 | 4628 | $this->tpl['description'] = ' '; |
| 4270 | 4629 | } |
@@ -4272,17 +4631,23 @@ discard block |
||
| 4272 | 4631 | // VAT Rate |
| 4273 | 4632 | $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
| 4274 | 4633 | $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
| 4275 | - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')'; |
|
| 4634 | + if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) { |
|
| 4635 | + $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')'; |
|
| 4636 | + } |
|
| 4276 | 4637 | |
| 4277 | 4638 | $this->tpl['price'] = price($line->subprice); |
| 4278 | 4639 | $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
| 4279 | 4640 | $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; |
| 4280 | - if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long')); |
|
| 4641 | + if ($conf->global->PRODUCT_USE_UNITS) { |
|
| 4642 | + $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long')); |
|
| 4643 | + } |
|
| 4281 | 4644 | $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
| 4282 | 4645 | |
| 4283 | 4646 | // Is the line strike or not |
| 4284 | 4647 | $this->tpl['strike']=0; |
| 4285 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 4648 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) { |
|
| 4649 | + $this->tpl['strike']=1; |
|
| 4650 | + } |
|
| 4286 | 4651 | |
| 4287 | 4652 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 4288 | 4653 | // Use global variables + $dateSelector + $seller and $buyer |
@@ -4295,7 +4660,9 @@ discard block |
||
| 4295 | 4660 | } else { |
| 4296 | 4661 | $res=include $tpl; // for debug |
| 4297 | 4662 | } |
| 4298 | - if ($res) break; |
|
| 4663 | + if ($res) { |
|
| 4664 | + break; |
|
| 4665 | + } |
|
| 4299 | 4666 | } |
| 4300 | 4667 | } |
| 4301 | 4668 | |
@@ -4337,8 +4704,7 @@ discard block |
||
| 4337 | 4704 | { |
| 4338 | 4705 | $this->db->commit(); |
| 4339 | 4706 | return 1; |
| 4340 | - } |
|
| 4341 | - else |
|
| 4707 | + } else |
|
| 4342 | 4708 | { |
| 4343 | 4709 | $this->error=$this->db->lasterror(); |
| 4344 | 4710 | $this->db->rollback(); |
@@ -4373,8 +4739,7 @@ discard block |
||
| 4373 | 4739 | $this->error=$this->db->lasterror(); |
| 4374 | 4740 | $this->db->rollback(); |
| 4375 | 4741 | return -1; |
| 4376 | - } |
|
| 4377 | - else |
|
| 4742 | + } else |
|
| 4378 | 4743 | { |
| 4379 | 4744 | if (! $notrigger) |
| 4380 | 4745 | { |
@@ -4441,13 +4806,20 @@ discard block |
||
| 4441 | 4806 | // Search template files |
| 4442 | 4807 | $file=''; $classname=''; $filefound=0; |
| 4443 | 4808 | $dirmodels=array('/'); |
| 4444 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
| 4809 | + if (is_array($conf->modules_parts['models'])) { |
|
| 4810 | + $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
| 4811 | + } |
|
| 4445 | 4812 | foreach($dirmodels as $reldir) |
| 4446 | 4813 | { |
| 4447 | 4814 | foreach(array('doc','pdf') as $prefix) |
| 4448 | 4815 | { |
| 4449 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
| 4450 | - else $file = $prefix."_".$modele.".modules.php"; |
|
| 4816 | + if (in_array(get_class($this), array('Adherent'))) { |
|
| 4817 | + $file = $prefix."_".$modele.".class.php"; |
|
| 4818 | + } |
|
| 4819 | + // Member module use prefix_module.class.php |
|
| 4820 | + else { |
|
| 4821 | + $file = $prefix."_".$modele.".modules.php"; |
|
| 4822 | + } |
|
| 4451 | 4823 | |
| 4452 | 4824 | // On verifie l'emplacement du modele |
| 4453 | 4825 | $file=dol_buildpath($reldir.$modelspath.$file,0); |
@@ -4458,7 +4830,9 @@ discard block |
||
| 4458 | 4830 | break; |
| 4459 | 4831 | } |
| 4460 | 4832 | } |
| 4461 | - if ($filefound) break; |
|
| 4833 | + if ($filefound) { |
|
| 4834 | + break; |
|
| 4835 | + } |
|
| 4462 | 4836 | } |
| 4463 | 4837 | |
| 4464 | 4838 | // If generator was found |
@@ -4490,7 +4864,9 @@ discard block |
||
| 4490 | 4864 | if (is_dir($tmpdir)) |
| 4491 | 4865 | { |
| 4492 | 4866 | $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
| 4493 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4867 | + if (count($tmpfiles)) { |
|
| 4868 | + $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4869 | + } |
|
| 4494 | 4870 | } |
| 4495 | 4871 | } |
| 4496 | 4872 | |
@@ -4528,8 +4904,7 @@ discard block |
||
| 4528 | 4904 | { |
| 4529 | 4905 | $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
| 4530 | 4906 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
| 4531 | - } |
|
| 4532 | - else |
|
| 4907 | + } else |
|
| 4533 | 4908 | { |
| 4534 | 4909 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
| 4535 | 4910 | } |
@@ -4551,9 +4926,11 @@ discard block |
||
| 4551 | 4926 | $destfile = basename($destfull); |
| 4552 | 4927 | $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); |
| 4553 | 4928 | |
| 4554 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 4929 | + if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) { |
|
| 4930 | + // If not a tmp dir |
|
| 4555 | 4931 | { |
| 4556 | 4932 | $filename = basename($destfile); |
| 4933 | + } |
|
| 4557 | 4934 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
| 4558 | 4935 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
| 4559 | 4936 | |
@@ -4566,18 +4943,30 @@ discard block |
||
| 4566 | 4943 | if ($this->element == 'propal') |
| 4567 | 4944 | { |
| 4568 | 4945 | $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
| 4569 | - if ($useonlinesignature) $setsharekey=true; |
|
| 4570 | - if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4946 | + if ($useonlinesignature) { |
|
| 4947 | + $setsharekey=true; |
|
| 4948 | + } |
|
| 4949 | + if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4950 | + $setsharekey=true; |
|
| 4951 | + } |
|
| 4952 | + } |
|
| 4953 | + if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4954 | + $setsharekey=true; |
|
| 4955 | + } |
|
| 4956 | + if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4957 | + $setsharekey=true; |
|
| 4958 | + } |
|
| 4959 | + if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4960 | + $setsharekey=true; |
|
| 4571 | 4961 | } |
| 4572 | - if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4573 | - if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4574 | - if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4575 | 4962 | |
| 4576 | 4963 | if ($setsharekey) |
| 4577 | 4964 | { |
| 4578 | - if (empty($ecmfile->share)) // Because object not found or share not set yet |
|
| 4965 | + if (empty($ecmfile->share)) { |
|
| 4966 | + // Because object not found or share not set yet |
|
| 4579 | 4967 | { |
| 4580 | 4968 | require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
| 4969 | + } |
|
| 4581 | 4970 | $ecmfile->share = getRandomPassword(true); |
| 4582 | 4971 | } |
| 4583 | 4972 | } |
@@ -4594,8 +4983,7 @@ discard block |
||
| 4594 | 4983 | { |
| 4595 | 4984 | setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
| 4596 | 4985 | } |
| 4597 | - } |
|
| 4598 | - else |
|
| 4986 | + } else |
|
| 4599 | 4987 | { |
| 4600 | 4988 | $ecmfile->entity = $conf->entity; |
| 4601 | 4989 | $ecmfile->filepath = $rel_dir; |
@@ -4622,17 +5010,20 @@ discard block |
||
| 4622 | 5010 | |
| 4623 | 5011 | // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
| 4624 | 5012 | $update_main_doc_field=0; |
| 4625 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 5013 | + if (! empty($obj->update_main_doc_field)) { |
|
| 5014 | + $update_main_doc_field=1; |
|
| 5015 | + } |
|
| 4626 | 5016 | if ($update_main_doc_field && ! empty($this->table_element)) |
| 4627 | 5017 | { |
| 4628 | 5018 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
| 4629 | 5019 | $sql.= ' WHERE rowid = '.$this->id; |
| 4630 | 5020 | $resql = $this->db->query($sql); |
| 4631 | - if (! $resql) dol_print_error($this->db); |
|
| 5021 | + if (! $resql) { |
|
| 5022 | + dol_print_error($this->db); |
|
| 5023 | + } |
|
| 4632 | 5024 | } |
| 4633 | 5025 | } |
| 4634 | - } |
|
| 4635 | - else |
|
| 5026 | + } else |
|
| 4636 | 5027 | { |
| 4637 | 5028 | dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING); |
| 4638 | 5029 | } |
@@ -4641,15 +5032,13 @@ discard block |
||
| 4641 | 5032 | dol_meta_create($this); |
| 4642 | 5033 | |
| 4643 | 5034 | return 1; |
| 4644 | - } |
|
| 4645 | - else |
|
| 5035 | + } else |
|
| 4646 | 5036 | { |
| 4647 | 5037 | $outputlangs->charset_output=$sav_charset_output; |
| 4648 | 5038 | dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
| 4649 | 5039 | return -1; |
| 4650 | 5040 | } |
| 4651 | - } |
|
| 4652 | - else |
|
| 5041 | + } else |
|
| 4653 | 5042 | { |
| 4654 | 5043 | $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
| 4655 | 5044 | dol_print_error('',$this->error); |
@@ -4705,13 +5094,21 @@ discard block |
||
| 4705 | 5094 | global $conf, $_POST; |
| 4706 | 5095 | |
| 4707 | 5096 | // If param here has been posted, we use this value first. |
| 4708 | - if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); |
|
| 5097 | + if (isset($_POST[$fieldname])) { |
|
| 5098 | + return GETPOST($fieldname, 2); |
|
| 5099 | + } |
|
| 4709 | 5100 | |
| 4710 | - if (isset($alternatevalue)) return $alternatevalue; |
|
| 5101 | + if (isset($alternatevalue)) { |
|
| 5102 | + return $alternatevalue; |
|
| 5103 | + } |
|
| 4711 | 5104 | |
| 4712 | 5105 | $newelement=$this->element; |
| 4713 | - if ($newelement == 'facture') $newelement='invoice'; |
|
| 4714 | - if ($newelement == 'commande') $newelement='order'; |
|
| 5106 | + if ($newelement == 'facture') { |
|
| 5107 | + $newelement='invoice'; |
|
| 5108 | + } |
|
| 5109 | + if ($newelement == 'commande') { |
|
| 5110 | + $newelement='order'; |
|
| 5111 | + } |
|
| 4715 | 5112 | if (empty($newelement)) |
| 4716 | 5113 | { |
| 4717 | 5114 | dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING); |
@@ -4720,7 +5117,9 @@ discard block |
||
| 4720 | 5117 | |
| 4721 | 5118 | $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
| 4722 | 5119 | //var_dump($keyforfieldname); |
| 4723 | - if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
|
| 5120 | + if (isset($conf->global->$keyforfieldname)) { |
|
| 5121 | + return $conf->global->$keyforfieldname; |
|
| 5122 | + } |
|
| 4724 | 5123 | |
| 4725 | 5124 | // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname |
| 4726 | 5125 | } |
@@ -4754,8 +5153,7 @@ discard block |
||
| 4754 | 5153 | if (!empty($this->errors)) |
| 4755 | 5154 | { |
| 4756 | 5155 | $this->errors=array_unique(array_merge($this->errors,$interface->errors)); // We use array_unique because when a trigger call another trigger on same object, this->errors is added twice. |
| 4757 | - } |
|
| 4758 | - else |
|
| 5156 | + } else |
|
| 4759 | 5157 | { |
| 4760 | 5158 | $this->errors=$interface->errors; |
| 4761 | 5159 | } |
@@ -4779,7 +5177,9 @@ discard block |
||
| 4779 | 5177 | function fetch_optionals($rowid=null, $optionsArray=null) |
| 4780 | 5178 | { |
| 4781 | 5179 | // phpcs:enable |
| 4782 | - if (empty($rowid)) $rowid=$this->id; |
|
| 5180 | + if (empty($rowid)) { |
|
| 5181 | + $rowid=$this->id; |
|
| 5182 | + } |
|
| 4783 | 5183 | |
| 4784 | 5184 | // To avoid SQL errors. Probably not the better solution though |
| 4785 | 5185 | if (!$this->table_element) { |
@@ -4805,15 +5205,17 @@ discard block |
||
| 4805 | 5205 | $extrafields->fetch_name_optionals_label($this->table_element); |
| 4806 | 5206 | } |
| 4807 | 5207 | $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
| 4808 | - } |
|
| 4809 | - else |
|
| 5208 | + } else |
|
| 4810 | 5209 | { |
| 4811 | 5210 | global $extrafields; |
| 4812 | 5211 | dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING); |
| 4813 | 5212 | } |
| 4814 | 5213 | |
| 4815 | 5214 | $table_element = $this->table_element; |
| 4816 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5215 | + if ($table_element == 'categorie') { |
|
| 5216 | + $table_element = 'categories'; |
|
| 5217 | + } |
|
| 5218 | + // For compatibility |
|
| 4817 | 5219 | |
| 4818 | 5220 | // Request to get complementary values |
| 4819 | 5221 | if (is_array($optionsArray) && count($optionsArray) > 0) |
@@ -4849,8 +5251,7 @@ discard block |
||
| 4849 | 5251 | { |
| 4850 | 5252 | //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
| 4851 | 5253 | $this->array_options["options_".$key]=$this->db->jdate($value); |
| 4852 | - } |
|
| 4853 | - else |
|
| 5254 | + } else |
|
| 4854 | 5255 | { |
| 4855 | 5256 | $this->array_options["options_".$key]=$value; |
| 4856 | 5257 | } |
@@ -4862,10 +5263,12 @@ discard block |
||
| 4862 | 5263 | |
| 4863 | 5264 | $this->db->free($resql); |
| 4864 | 5265 | |
| 4865 | - if ($numrows) return $numrows; |
|
| 4866 | - else return 0; |
|
| 4867 | - } |
|
| 4868 | - else |
|
| 5266 | + if ($numrows) { |
|
| 5267 | + return $numrows; |
|
| 5268 | + } else { |
|
| 5269 | + return 0; |
|
| 5270 | + } |
|
| 5271 | + } else |
|
| 4869 | 5272 | { |
| 4870 | 5273 | dol_print_error($this->db); |
| 4871 | 5274 | return -1; |
@@ -4884,7 +5287,10 @@ discard block |
||
| 4884 | 5287 | $this->db->begin(); |
| 4885 | 5288 | |
| 4886 | 5289 | $table_element = $this->table_element; |
| 4887 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5290 | + if ($table_element == 'categorie') { |
|
| 5291 | + $table_element = 'categories'; |
|
| 5292 | + } |
|
| 5293 | + // For compatibility |
|
| 4888 | 5294 | |
| 4889 | 5295 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
| 4890 | 5296 | dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
@@ -4894,8 +5300,7 @@ discard block |
||
| 4894 | 5300 | $this->error=$this->db->lasterror(); |
| 4895 | 5301 | $this->db->rollback(); |
| 4896 | 5302 | return -1; |
| 4897 | - } |
|
| 4898 | - else |
|
| 5303 | + } else |
|
| 4899 | 5304 | { |
| 4900 | 5305 | $this->db->commit(); |
| 4901 | 5306 | return 1; |
@@ -4916,11 +5321,16 @@ discard block |
||
| 4916 | 5321 | { |
| 4917 | 5322 | global $conf,$langs,$user; |
| 4918 | 5323 | |
| 4919 | - if (empty($userused)) $userused=$user; |
|
| 5324 | + if (empty($userused)) { |
|
| 5325 | + $userused=$user; |
|
| 5326 | + } |
|
| 4920 | 5327 | |
| 4921 | 5328 | $error=0; |
| 4922 | 5329 | |
| 4923 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5330 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 5331 | + return 0; |
|
| 5332 | + } |
|
| 5333 | + // For avoid conflicts if trigger used |
|
| 4924 | 5334 | |
| 4925 | 5335 | if (! empty($this->array_options)) |
| 4926 | 5336 | { |
@@ -4933,10 +5343,13 @@ discard block |
||
| 4933 | 5343 | //Eliminate copied source object extra_fields that do not exist in target object |
| 4934 | 5344 | $new_array_options=array(); |
| 4935 | 5345 | foreach ($this->array_options as $key => $value) { |
| 4936 | - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 5346 | + if (in_array(substr($key,8), array_keys($target_extrafields))) { |
|
| 5347 | + // We remove the 'options_' from $key for test |
|
| 4937 | 5348 | $new_array_options[$key] = $value; |
| 4938 | - elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
|
| 5349 | + } elseif (in_array($key, array_keys($target_extrafields))) { |
|
| 5350 | + // We test on $key that does not contains the 'options_' prefix |
|
| 4939 | 5351 | $new_array_options['options_'.$key] = $value; |
| 5352 | + } |
|
| 4940 | 5353 | } |
| 4941 | 5354 | |
| 4942 | 5355 | foreach($new_array_options as $key => $value) |
@@ -4950,8 +5363,12 @@ discard block |
||
| 4950 | 5363 | if ($attributeRequired) |
| 4951 | 5364 | { |
| 4952 | 5365 | $mandatorypb=false; |
| 4953 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4954 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 5366 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') { |
|
| 5367 | + $mandatorypb=true; |
|
| 5368 | + } |
|
| 5369 | + if ($this->array_options[$key] === '') { |
|
| 5370 | + $mandatorypb=true; |
|
| 5371 | + } |
|
| 4955 | 5372 | if ($mandatorypb) |
| 4956 | 5373 | { |
| 4957 | 5374 | dol_syslog($this->error); |
@@ -4970,8 +5387,7 @@ discard block |
||
| 4970 | 5387 | { |
| 4971 | 5388 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
| 4972 | 5389 | return -1; |
| 4973 | - } |
|
| 4974 | - elseif ($value=='') |
|
| 5390 | + } elseif ($value=='') |
|
| 4975 | 5391 | { |
| 4976 | 5392 | $new_array_options[$key] = null; |
| 4977 | 5393 | } |
@@ -4983,8 +5399,7 @@ discard block |
||
| 4983 | 5399 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
| 4984 | 5400 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
| 4985 | 5401 | return -1; |
| 4986 | - } |
|
| 4987 | - elseif ($value=='') |
|
| 5402 | + } elseif ($value=='') |
|
| 4988 | 5403 | { |
| 4989 | 5404 | $new_array_options[$key] = null; |
| 4990 | 5405 | } |
@@ -5009,27 +5424,27 @@ discard block |
||
| 5009 | 5424 | //global $action; // $action may be 'create', 'update', 'update_extras'... |
| 5010 | 5425 | //var_dump($action); |
| 5011 | 5426 | //var_dump($this->oldcopy);exit; |
| 5012 | - if (is_object($this->oldcopy)) // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value |
|
| 5427 | + if (is_object($this->oldcopy)) { |
|
| 5428 | + // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value |
|
| 5013 | 5429 | { |
| 5014 | 5430 | //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
| 5015 | 5431 | if ($this->array_options[$key] == $this->oldcopy->array_options[$key]) // If old value crypted in database is same than submited new value, it means we don't change it, so we don't update. |
| 5016 | 5432 | { |
| 5017 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5018 | - } |
|
| 5019 | - else |
|
| 5433 | + $new_array_options[$key] = $this->array_options[$key]; |
|
| 5434 | + } |
|
| 5435 | + // Value is kept |
|
| 5436 | + } else |
|
| 5020 | 5437 | { |
| 5021 | 5438 | // var_dump($algo); |
| 5022 | 5439 | $newvalue = dol_hash($this->array_options[$key], $algo); |
| 5023 | 5440 | $new_array_options[$key] = $newvalue; |
| 5024 | 5441 | } |
| 5025 | - } |
|
| 5026 | - else |
|
| 5442 | + } else |
|
| 5027 | 5443 | { |
| 5028 | 5444 | $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
| 5029 | 5445 | } |
| 5030 | 5446 | } |
| 5031 | - } |
|
| 5032 | - else // Common usage |
|
| 5447 | + } else // Common usage |
|
| 5033 | 5448 | { |
| 5034 | 5449 | $new_array_options[$key] = $this->array_options[$key]; |
| 5035 | 5450 | } |
@@ -5055,26 +5470,30 @@ discard block |
||
| 5055 | 5470 | dol_include_once($InfoFieldList[1]); |
| 5056 | 5471 | if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) |
| 5057 | 5472 | { |
| 5058 | - if ($value == '-1') // -1 is key for no defined in combo list of objects |
|
| 5473 | + if ($value == '-1') { |
|
| 5474 | + // -1 is key for no defined in combo list of objects |
|
| 5059 | 5475 | { |
| 5060 | 5476 | $new_array_options[$key]=''; |
| 5061 | 5477 | } |
| 5062 | - elseif ($value) |
|
| 5478 | + } elseif ($value) |
|
| 5063 | 5479 | { |
| 5064 | 5480 | $object = new $InfoFieldList[0]($this->db); |
| 5065 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
| 5066 | - else $res=$object->fetch('',$value); |
|
| 5481 | + if (is_numeric($value)) { |
|
| 5482 | + $res=$object->fetch($value); |
|
| 5483 | + } else { |
|
| 5484 | + $res=$object->fetch('',$value); |
|
| 5485 | + } |
|
| 5067 | 5486 | |
| 5068 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 5069 | - else |
|
| 5487 | + if ($res > 0) { |
|
| 5488 | + $new_array_options[$key]=$object->id; |
|
| 5489 | + } else |
|
| 5070 | 5490 | { |
| 5071 | 5491 | $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
| 5072 | 5492 | $this->db->rollback(); |
| 5073 | 5493 | return -1; |
| 5074 | 5494 | } |
| 5075 | 5495 | } |
| 5076 | - } |
|
| 5077 | - else |
|
| 5496 | + } else |
|
| 5078 | 5497 | { |
| 5079 | 5498 | dol_syslog('Error bad setup of extrafield', LOG_WARNING); |
| 5080 | 5499 | } |
@@ -5085,7 +5504,10 @@ discard block |
||
| 5085 | 5504 | $this->db->begin(); |
| 5086 | 5505 | |
| 5087 | 5506 | $table_element = $this->table_element; |
| 5088 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5507 | + if ($table_element == 'categorie') { |
|
| 5508 | + $table_element = 'categories'; |
|
| 5509 | + } |
|
| 5510 | + // For compatibility |
|
| 5089 | 5511 | |
| 5090 | 5512 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
| 5091 | 5513 | dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
@@ -5096,8 +5518,10 @@ discard block |
||
| 5096 | 5518 | { |
| 5097 | 5519 | $attributeKey = substr($key,8); // Remove 'options_' prefix |
| 5098 | 5520 | // Add field of attribut |
| 5099 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
|
| 5521 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') { |
|
| 5522 | + // Only for other type than separator |
|
| 5100 | 5523 | $sql.=",".$attributeKey; |
| 5524 | + } |
|
| 5101 | 5525 | } |
| 5102 | 5526 | $sql .= ") VALUES (".$this->id; |
| 5103 | 5527 | |
@@ -5105,13 +5529,14 @@ discard block |
||
| 5105 | 5529 | { |
| 5106 | 5530 | $attributeKey = substr($key,8); // Remove 'options_' prefix |
| 5107 | 5531 | // Add field of attribute |
| 5108 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
|
| 5532 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') { |
|
| 5533 | + // Only for other type than separator) |
|
| 5109 | 5534 | { |
| 5110 | 5535 | if ($new_array_options[$key] != '') |
| 5111 | 5536 | { |
| 5112 | 5537 | $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
| 5113 | - } |
|
| 5114 | - else |
|
| 5538 | + } |
|
| 5539 | + } else |
|
| 5115 | 5540 | { |
| 5116 | 5541 | $sql.=",null"; |
| 5117 | 5542 | } |
@@ -5132,7 +5557,9 @@ discard block |
||
| 5132 | 5557 | // Call trigger |
| 5133 | 5558 | $this->context=array('extrafieldaddupdate'=>1); |
| 5134 | 5559 | $result=$this->call_trigger($trigger, $userused); |
| 5135 | - if ($result < 0) $error++; |
|
| 5560 | + if ($result < 0) { |
|
| 5561 | + $error++; |
|
| 5562 | + } |
|
| 5136 | 5563 | // End call trigger |
| 5137 | 5564 | } |
| 5138 | 5565 | |
@@ -5140,14 +5567,14 @@ discard block |
||
| 5140 | 5567 | { |
| 5141 | 5568 | $this->db->rollback(); |
| 5142 | 5569 | return -1; |
| 5143 | - } |
|
| 5144 | - else |
|
| 5570 | + } else |
|
| 5145 | 5571 | { |
| 5146 | 5572 | $this->db->commit(); |
| 5147 | 5573 | return 1; |
| 5148 | 5574 | } |
| 5575 | + } else { |
|
| 5576 | + return 0; |
|
| 5149 | 5577 | } |
| 5150 | - else return 0; |
|
| 5151 | 5578 | } |
| 5152 | 5579 | |
| 5153 | 5580 | /** |
@@ -5164,11 +5591,16 @@ discard block |
||
| 5164 | 5591 | { |
| 5165 | 5592 | global $conf,$langs,$user; |
| 5166 | 5593 | |
| 5167 | - if (empty($userused)) $userused=$user; |
|
| 5594 | + if (empty($userused)) { |
|
| 5595 | + $userused=$user; |
|
| 5596 | + } |
|
| 5168 | 5597 | |
| 5169 | 5598 | $error=0; |
| 5170 | 5599 | |
| 5171 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5600 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 5601 | + return 0; |
|
| 5602 | + } |
|
| 5603 | + // For avoid conflicts if trigger used |
|
| 5172 | 5604 | |
| 5173 | 5605 | if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
| 5174 | 5606 | { |
@@ -5195,8 +5627,7 @@ discard block |
||
| 5195 | 5627 | { |
| 5196 | 5628 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); |
| 5197 | 5629 | return -1; |
| 5198 | - } |
|
| 5199 | - elseif ($value=='') |
|
| 5630 | + } elseif ($value=='') |
|
| 5200 | 5631 | { |
| 5201 | 5632 | $this->array_options["options_".$key] = null; |
| 5202 | 5633 | } |
@@ -5208,8 +5639,7 @@ discard block |
||
| 5208 | 5639 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
| 5209 | 5640 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
| 5210 | 5641 | return -1; |
| 5211 | - } |
|
| 5212 | - elseif ($value=='') |
|
| 5642 | + } elseif ($value=='') |
|
| 5213 | 5643 | { |
| 5214 | 5644 | $this->array_options["options_".$key] = null; |
| 5215 | 5645 | } |
@@ -5261,7 +5691,9 @@ discard block |
||
| 5261 | 5691 | // Call trigger |
| 5262 | 5692 | $this->context=array('extrafieldupdate'=>1); |
| 5263 | 5693 | $result=$this->call_trigger($trigger, $userused); |
| 5264 | - if ($result < 0) $error++; |
|
| 5694 | + if ($result < 0) { |
|
| 5695 | + $error++; |
|
| 5696 | + } |
|
| 5265 | 5697 | // End call trigger |
| 5266 | 5698 | } |
| 5267 | 5699 | |
@@ -5270,14 +5702,14 @@ discard block |
||
| 5270 | 5702 | dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
| 5271 | 5703 | $this->db->rollback(); |
| 5272 | 5704 | return -1; |
| 5273 | - } |
|
| 5274 | - else |
|
| 5705 | + } else |
|
| 5275 | 5706 | { |
| 5276 | 5707 | $this->db->commit(); |
| 5277 | 5708 | return 1; |
| 5278 | 5709 | } |
| 5710 | + } else { |
|
| 5711 | + return 0; |
|
| 5279 | 5712 | } |
| 5280 | - else return 0; |
|
| 5281 | 5713 | } |
| 5282 | 5714 | |
| 5283 | 5715 | |
@@ -5352,8 +5784,11 @@ discard block |
||
| 5352 | 5784 | |
| 5353 | 5785 | if ($computed) |
| 5354 | 5786 | { |
| 5355 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 5356 | - else return ''; |
|
| 5787 | + if (! preg_match('/^search_/', $keyprefix)) { |
|
| 5788 | + return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 5789 | + } else { |
|
| 5790 | + return ''; |
|
| 5791 | + } |
|
| 5357 | 5792 | } |
| 5358 | 5793 | |
| 5359 | 5794 | |
@@ -5367,33 +5802,27 @@ discard block |
||
| 5367 | 5802 | if ($type == 'date') |
| 5368 | 5803 | { |
| 5369 | 5804 | $morecss = 'minwidth100imp'; |
| 5370 | - } |
|
| 5371 | - elseif ($type == 'datetime') |
|
| 5805 | + } elseif ($type == 'datetime') |
|
| 5372 | 5806 | { |
| 5373 | 5807 | $morecss = 'minwidth200imp'; |
| 5374 | - } |
|
| 5375 | - elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
| 5808 | + } elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
| 5376 | 5809 | { |
| 5377 | 5810 | $morecss = 'maxwidth75'; |
| 5378 | - }elseif ($type == 'url') |
|
| 5811 | + } elseif ($type == 'url') |
|
| 5379 | 5812 | { |
| 5380 | 5813 | $morecss='minwidth400'; |
| 5381 | - } |
|
| 5382 | - elseif ($type == 'boolean') |
|
| 5814 | + } elseif ($type == 'boolean') |
|
| 5383 | 5815 | { |
| 5384 | 5816 | $morecss=''; |
| 5385 | - } |
|
| 5386 | - else |
|
| 5817 | + } else |
|
| 5387 | 5818 | { |
| 5388 | 5819 | if (round($size) < 12) |
| 5389 | 5820 | { |
| 5390 | 5821 | $morecss = 'minwidth100'; |
| 5391 | - } |
|
| 5392 | - else if (round($size) <= 48) |
|
| 5822 | + } else if (round($size) <= 48) |
|
| 5393 | 5823 | { |
| 5394 | 5824 | $morecss = 'minwidth200'; |
| 5395 | - } |
|
| 5396 | - else |
|
| 5825 | + } else |
|
| 5397 | 5826 | { |
| 5398 | 5827 | $morecss = 'minwidth400'; |
| 5399 | 5828 | } |
@@ -5408,52 +5837,50 @@ discard block |
||
| 5408 | 5837 | $showtime = in_array($type,array('datetime')) ? 1 : 0; |
| 5409 | 5838 | |
| 5410 | 5839 | // Do not show current date when field not required (see selectDate() method) |
| 5411 | - if (!$required && $value == '') $value = '-1'; |
|
| 5840 | + if (!$required && $value == '') { |
|
| 5841 | + $value = '-1'; |
|
| 5842 | + } |
|
| 5412 | 5843 | |
| 5413 | 5844 | // TODO Must also support $moreparam |
| 5414 | 5845 | $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
| 5415 | - } |
|
| 5416 | - elseif (in_array($type,array('int','integer'))) |
|
| 5846 | + } elseif (in_array($type,array('int','integer'))) |
|
| 5417 | 5847 | { |
| 5418 | 5848 | $tmp=explode(',',$size); |
| 5419 | 5849 | $newsize=$tmp[0]; |
| 5420 | 5850 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
| 5421 | - } |
|
| 5422 | - elseif (preg_match('/varchar/', $type)) |
|
| 5851 | + } elseif (preg_match('/varchar/', $type)) |
|
| 5423 | 5852 | { |
| 5424 | 5853 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
| 5425 | - } |
|
| 5426 | - elseif (in_array($type, array('mail', 'phone', 'url'))) |
|
| 5854 | + } elseif (in_array($type, array('mail', 'phone', 'url'))) |
|
| 5427 | 5855 | { |
| 5428 | 5856 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 5429 | - } |
|
| 5430 | - elseif ($type == 'text') |
|
| 5857 | + } elseif ($type == 'text') |
|
| 5431 | 5858 | { |
| 5432 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5859 | + if (! preg_match('/search_/', $keyprefix)) { |
|
| 5860 | + // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5433 | 5861 | { |
| 5434 | 5862 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 5863 | + } |
|
| 5435 | 5864 | $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
| 5436 | 5865 | $out=$doleditor->Create(1); |
| 5437 | - } |
|
| 5438 | - else |
|
| 5866 | + } else |
|
| 5439 | 5867 | { |
| 5440 | 5868 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 5441 | 5869 | } |
| 5442 | - } |
|
| 5443 | - elseif ($type == 'html') |
|
| 5870 | + } elseif ($type == 'html') |
|
| 5444 | 5871 | { |
| 5445 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5872 | + if (! preg_match('/search_/', $keyprefix)) { |
|
| 5873 | + // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5446 | 5874 | { |
| 5447 | 5875 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 5876 | + } |
|
| 5448 | 5877 | $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%'); |
| 5449 | 5878 | $out=$doleditor->Create(1); |
| 5450 | - } |
|
| 5451 | - else |
|
| 5879 | + } else |
|
| 5452 | 5880 | { |
| 5453 | 5881 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 5454 | 5882 | } |
| 5455 | - } |
|
| 5456 | - elseif ($type == 'boolean') |
|
| 5883 | + } elseif ($type == 'boolean') |
|
| 5457 | 5884 | { |
| 5458 | 5885 | $checked=''; |
| 5459 | 5886 | if (!empty($value)) { |
@@ -5462,22 +5889,19 @@ discard block |
||
| 5462 | 5889 | $checked=' value="1" '; |
| 5463 | 5890 | } |
| 5464 | 5891 | $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
| 5465 | - } |
|
| 5466 | - elseif ($type == 'price') |
|
| 5892 | + } elseif ($type == 'price') |
|
| 5467 | 5893 | { |
| 5468 | 5894 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 5469 | 5895 | $value=price($value); |
| 5470 | 5896 | } |
| 5471 | 5897 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
| 5472 | - } |
|
| 5473 | - elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
| 5898 | + } elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
| 5474 | 5899 | { |
| 5475 | 5900 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 5476 | 5901 | $value=price($value); |
| 5477 | 5902 | } |
| 5478 | 5903 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
| 5479 | - } |
|
| 5480 | - elseif ($type == 'select') |
|
| 5904 | + } elseif ($type == 'select') |
|
| 5481 | 5905 | { |
| 5482 | 5906 | $out = ''; |
| 5483 | 5907 | if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
@@ -5487,10 +5911,14 @@ discard block |
||
| 5487 | 5911 | } |
| 5488 | 5912 | |
| 5489 | 5913 | $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
| 5490 | - if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
| 5914 | + if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1)) { |
|
| 5915 | + $out.='<option value="0"> </option>'; |
|
| 5916 | + } |
|
| 5491 | 5917 | foreach ($param['options'] as $key => $val) |
| 5492 | 5918 | { |
| 5493 | - if ((string) $key == '') continue; |
|
| 5919 | + if ((string) $key == '') { |
|
| 5920 | + continue; |
|
| 5921 | + } |
|
| 5494 | 5922 | list($val, $parent) = explode('|', $val); |
| 5495 | 5923 | $out.='<option value="'.$key.'"'; |
| 5496 | 5924 | $out.= (((string) $value == (string) $key)?' selected':''); |
@@ -5498,8 +5926,7 @@ discard block |
||
| 5498 | 5926 | $out.='>'.$val.'</option>'; |
| 5499 | 5927 | } |
| 5500 | 5928 | $out.='</select>'; |
| 5501 | - } |
|
| 5502 | - elseif ($type == 'sellist') |
|
| 5929 | + } elseif ($type == 'sellist') |
|
| 5503 | 5930 | { |
| 5504 | 5931 | $out = ''; |
| 5505 | 5932 | if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
@@ -5566,13 +5993,11 @@ discard block |
||
| 5566 | 5993 | { |
| 5567 | 5994 | $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
| 5568 | 5995 | $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
| 5569 | - } |
|
| 5570 | - else |
|
| 5996 | + } else |
|
| 5571 | 5997 | { |
| 5572 | 5998 | $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
| 5573 | 5999 | } |
| 5574 | - } |
|
| 5575 | - else |
|
| 6000 | + } else |
|
| 5576 | 6001 | { |
| 5577 | 6002 | $sqlwhere.= ' WHERE 1=1'; |
| 5578 | 6003 | } |
@@ -5608,8 +6033,7 @@ discard block |
||
| 5608 | 6033 | { |
| 5609 | 6034 | $labeltoshow.= $obj->$field_toshow.' '; |
| 5610 | 6035 | } |
| 5611 | - } |
|
| 5612 | - else |
|
| 6036 | + } else |
|
| 5613 | 6037 | { |
| 5614 | 6038 | $labeltoshow=$obj->{$InfoFieldList[1]}; |
| 5615 | 6039 | } |
@@ -5622,25 +6046,25 @@ discard block |
||
| 5622 | 6046 | $translabel=$langs->trans($obj->$field_toshow); |
| 5623 | 6047 | if ($translabel!=$obj->$field_toshow) { |
| 5624 | 6048 | $labeltoshow=dol_trunc($translabel,18).' '; |
| 5625 | - }else { |
|
| 6049 | + } else { |
|
| 5626 | 6050 | $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
| 5627 | 6051 | } |
| 5628 | 6052 | } |
| 5629 | 6053 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
| 5630 | - } |
|
| 5631 | - else |
|
| 6054 | + } else |
|
| 5632 | 6055 | { |
| 5633 | 6056 | if (! $notrans) |
| 5634 | 6057 | { |
| 5635 | 6058 | $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
| 5636 | 6059 | if ($translabel!=$obj->{$InfoFieldList[1]}) { |
| 5637 | 6060 | $labeltoshow=dol_trunc($translabel,18); |
| 5638 | - } |
|
| 5639 | - else { |
|
| 6061 | + } else { |
|
| 5640 | 6062 | $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18); |
| 5641 | 6063 | } |
| 5642 | 6064 | } |
| 5643 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 6065 | + if (empty($labeltoshow)) { |
|
| 6066 | + $labeltoshow='(not defined)'; |
|
| 6067 | + } |
|
| 5644 | 6068 | if ($value==$obj->rowid) |
| 5645 | 6069 | { |
| 5646 | 6070 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
@@ -5660,19 +6084,16 @@ discard block |
||
| 5660 | 6084 | $i++; |
| 5661 | 6085 | } |
| 5662 | 6086 | $this->db->free($resql); |
| 5663 | - } |
|
| 5664 | - else { |
|
| 6087 | + } else { |
|
| 5665 | 6088 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
| 5666 | 6089 | } |
| 5667 | 6090 | } |
| 5668 | 6091 | $out.='</select>'; |
| 5669 | - } |
|
| 5670 | - elseif ($type == 'checkbox') |
|
| 6092 | + } elseif ($type == 'checkbox') |
|
| 5671 | 6093 | { |
| 5672 | 6094 | $value_arr=explode(',',$value); |
| 5673 | 6095 | $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
| 5674 | - } |
|
| 5675 | - elseif ($type == 'radio') |
|
| 6096 | + } elseif ($type == 'radio') |
|
| 5676 | 6097 | { |
| 5677 | 6098 | $out=''; |
| 5678 | 6099 | foreach ($param['options'] as $keyopt => $val) |
@@ -5683,13 +6104,11 @@ discard block |
||
| 5683 | 6104 | $out.= ($value==$keyopt?'checked':''); |
| 5684 | 6105 | $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
| 5685 | 6106 | } |
| 5686 | - } |
|
| 5687 | - elseif ($type == 'chkbxlst') |
|
| 6107 | + } elseif ($type == 'chkbxlst') |
|
| 5688 | 6108 | { |
| 5689 | 6109 | if (is_array($value)) { |
| 5690 | 6110 | $value_arr = $value; |
| 5691 | - } |
|
| 5692 | - else { |
|
| 6111 | + } else { |
|
| 5693 | 6112 | $value_arr = explode(',', $value); |
| 5694 | 6113 | } |
| 5695 | 6114 | |
@@ -5804,8 +6223,9 @@ discard block |
||
| 5804 | 6223 | $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18); |
| 5805 | 6224 | } |
| 5806 | 6225 | } |
| 5807 | - if (empty($labeltoshow)) |
|
| 5808 | - $labeltoshow = '(not defined)'; |
|
| 6226 | + if (empty($labeltoshow)) { |
|
| 6227 | + $labeltoshow = '(not defined)'; |
|
| 6228 | + } |
|
| 5809 | 6229 | |
| 5810 | 6230 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 5811 | 6231 | $data[$obj->rowid]=$labeltoshow; |
@@ -5827,8 +6247,7 @@ discard block |
||
| 5827 | 6247 | print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
| 5828 | 6248 | } |
| 5829 | 6249 | } |
| 5830 | - } |
|
| 5831 | - elseif ($type == 'link') |
|
| 6250 | + } elseif ($type == 'link') |
|
| 5832 | 6251 | { |
| 5833 | 6252 | $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
| 5834 | 6253 | $showempty=(($required && $default != '')?0:1); |
@@ -5836,18 +6255,19 @@ discard block |
||
| 5836 | 6255 | if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
| 5837 | 6256 | { |
| 5838 | 6257 | list($class,$classfile)=explode(':',$param_list[0]); |
| 5839 | - if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 5840 | - else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 6258 | + if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) { |
|
| 6259 | + $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 6260 | + } else { |
|
| 6261 | + $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 6262 | + } |
|
| 5841 | 6263 | $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
| 5842 | 6264 | // TODO Add Javascript code to add input fields contents to new elements urls |
| 5843 | 6265 | } |
| 5844 | - } |
|
| 5845 | - elseif ($type == 'password') |
|
| 6266 | + } elseif ($type == 'password') |
|
| 5846 | 6267 | { |
| 5847 | 6268 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
| 5848 | 6269 | $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
| 5849 | - } |
|
| 5850 | - elseif ($type == 'array') |
|
| 6270 | + } elseif ($type == 'array') |
|
| 5851 | 6271 | { |
| 5852 | 6272 | $newval = $val; |
| 5853 | 6273 | $newval['type'] = 'varchar(256)'; |
@@ -5925,17 +6345,25 @@ discard block |
||
| 5925 | 6345 | { |
| 5926 | 6346 | $type = 'varchar'; // convert varchar(xx) int varchar |
| 5927 | 6347 | $size = $reg[1]; |
| 6348 | + } elseif (preg_match('/varchar/', $type)) { |
|
| 6349 | + $type = 'varchar'; |
|
| 6350 | + } |
|
| 6351 | + // convert varchar(xx) int varchar |
|
| 6352 | + if (is_array($val['arrayofkeyval'])) { |
|
| 6353 | + $type='select'; |
|
| 6354 | + } |
|
| 6355 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) { |
|
| 6356 | + $type='link'; |
|
| 5928 | 6357 | } |
| 5929 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5930 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 5931 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; |
|
| 5932 | 6358 | |
| 5933 | 6359 | $default=$val['default']; |
| 5934 | 6360 | $computed=$val['computed']; |
| 5935 | 6361 | $unique=$val['unique']; |
| 5936 | 6362 | $required=$val['required']; |
| 5937 | 6363 | $param=$val['param']; |
| 5938 | - if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
|
| 6364 | + if (is_array($val['arrayofkeyval'])) { |
|
| 6365 | + $param['options'] = $val['arrayofkeyval']; |
|
| 6366 | + } |
|
| 5939 | 6367 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) |
| 5940 | 6368 | { |
| 5941 | 6369 | $type='link'; |
@@ -5946,7 +6374,9 @@ discard block |
||
| 5946 | 6374 | $help=$val['help']; |
| 5947 | 6375 | $hidden=(($val['visible'] == 0) ? 1 : 0); // If zero, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
| 5948 | 6376 | |
| 5949 | - if ($hidden) return ''; |
|
| 6377 | + if ($hidden) { |
|
| 6378 | + return ''; |
|
| 6379 | + } |
|
| 5950 | 6380 | |
| 5951 | 6381 | // If field is a computed field, value must become result of compute |
| 5952 | 6382 | if ($computed) |
@@ -5962,36 +6392,29 @@ discard block |
||
| 5962 | 6392 | { |
| 5963 | 6393 | //$showsize=10; |
| 5964 | 6394 | $showsize = 'minwidth100imp'; |
| 5965 | - } |
|
| 5966 | - elseif ($type == 'datetime') |
|
| 6395 | + } elseif ($type == 'datetime') |
|
| 5967 | 6396 | { |
| 5968 | 6397 | //$showsize=19; |
| 5969 | 6398 | $showsize = 'minwidth200imp'; |
| 5970 | - } |
|
| 5971 | - elseif (in_array($type,array('int','double','price'))) |
|
| 6399 | + } elseif (in_array($type,array('int','double','price'))) |
|
| 5972 | 6400 | { |
| 5973 | 6401 | //$showsize=10; |
| 5974 | 6402 | $showsize = 'maxwidth75'; |
| 5975 | - } |
|
| 5976 | - elseif ($type == 'url') |
|
| 6403 | + } elseif ($type == 'url') |
|
| 5977 | 6404 | { |
| 5978 | 6405 | $showsize='minwidth400'; |
| 5979 | - } |
|
| 5980 | - elseif ($type == 'boolean') |
|
| 6406 | + } elseif ($type == 'boolean') |
|
| 5981 | 6407 | { |
| 5982 | 6408 | $showsize=''; |
| 5983 | - } |
|
| 5984 | - else |
|
| 6409 | + } else |
|
| 5985 | 6410 | { |
| 5986 | 6411 | if (round($size) < 12) |
| 5987 | 6412 | { |
| 5988 | 6413 | $showsize = 'minwidth100'; |
| 5989 | - } |
|
| 5990 | - else if (round($size) <= 48) |
|
| 6414 | + } else if (round($size) <= 48) |
|
| 5991 | 6415 | { |
| 5992 | 6416 | $showsize = 'minwidth200'; |
| 5993 | - } |
|
| 5994 | - else |
|
| 6417 | + } else |
|
| 5995 | 6418 | { |
| 5996 | 6419 | //$showsize=48; |
| 5997 | 6420 | $showsize = 'minwidth400'; |
@@ -6000,59 +6423,52 @@ discard block |
||
| 6000 | 6423 | } |
| 6001 | 6424 | |
| 6002 | 6425 | // Format output value differently according to properties of field |
| 6003 | - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 6004 | - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
| 6005 | - elseif ($type == 'date') |
|
| 6426 | + if ($key == 'ref' && method_exists($this, 'getNomUrl')) { |
|
| 6427 | + $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 6428 | + } elseif ($key == 'status' && method_exists($this, 'getLibStatut')) { |
|
| 6429 | + $value=$this->getLibStatut(3); |
|
| 6430 | + } elseif ($type == 'date') |
|
| 6006 | 6431 | { |
| 6007 | 6432 | if(! empty($value)) { |
| 6008 | 6433 | $value=dol_print_date($value,'day'); |
| 6009 | 6434 | } else { |
| 6010 | 6435 | $value=''; |
| 6011 | 6436 | } |
| 6012 | - } |
|
| 6013 | - elseif ($type == 'datetime') |
|
| 6437 | + } elseif ($type == 'datetime') |
|
| 6014 | 6438 | { |
| 6015 | 6439 | if(! empty($value)) { |
| 6016 | 6440 | $value=dol_print_date($value,'dayhour'); |
| 6017 | 6441 | } else { |
| 6018 | 6442 | $value=''; |
| 6019 | 6443 | } |
| 6020 | - } |
|
| 6021 | - elseif ($type == 'double') |
|
| 6444 | + } elseif ($type == 'double') |
|
| 6022 | 6445 | { |
| 6023 | 6446 | if (!empty($value)) { |
| 6024 | 6447 | $value=price($value); |
| 6025 | 6448 | } |
| 6026 | - } |
|
| 6027 | - elseif ($type == 'boolean') |
|
| 6449 | + } elseif ($type == 'boolean') |
|
| 6028 | 6450 | { |
| 6029 | 6451 | $checked=''; |
| 6030 | 6452 | if (!empty($value)) { |
| 6031 | 6453 | $checked=' checked '; |
| 6032 | 6454 | } |
| 6033 | 6455 | $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
| 6034 | - } |
|
| 6035 | - elseif ($type == 'mail') |
|
| 6456 | + } elseif ($type == 'mail') |
|
| 6036 | 6457 | { |
| 6037 | 6458 | $value=dol_print_email($value,0,0,0,64,1,1); |
| 6038 | - } |
|
| 6039 | - elseif ($type == 'url') |
|
| 6459 | + } elseif ($type == 'url') |
|
| 6040 | 6460 | { |
| 6041 | 6461 | $value=dol_print_url($value,'_blank',32,1); |
| 6042 | - } |
|
| 6043 | - elseif ($type == 'phone') |
|
| 6462 | + } elseif ($type == 'phone') |
|
| 6044 | 6463 | { |
| 6045 | 6464 | $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
| 6046 | - } |
|
| 6047 | - elseif ($type == 'price') |
|
| 6465 | + } elseif ($type == 'price') |
|
| 6048 | 6466 | { |
| 6049 | 6467 | $value=price($value,0,$langs,0,0,-1,$conf->currency); |
| 6050 | - } |
|
| 6051 | - elseif ($type == 'select') |
|
| 6468 | + } elseif ($type == 'select') |
|
| 6052 | 6469 | { |
| 6053 | 6470 | $value=$param['options'][$value]; |
| 6054 | - } |
|
| 6055 | - elseif ($type == 'sellist') |
|
| 6471 | + } elseif ($type == 'sellist') |
|
| 6056 | 6472 | { |
| 6057 | 6473 | $param_list=array_keys($param['options']); |
| 6058 | 6474 | $InfoFieldList = explode(":", $param_list[0]); |
@@ -6082,7 +6498,7 @@ discard block |
||
| 6082 | 6498 | $sql.= " WHERE ".$selectkey."=0"; |
| 6083 | 6499 | } elseif ($selectkey=='rowid') { |
| 6084 | 6500 | $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
| 6085 | - }else { |
|
| 6501 | + } else { |
|
| 6086 | 6502 | $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
| 6087 | 6503 | } |
| 6088 | 6504 | |
@@ -6109,12 +6525,11 @@ discard block |
||
| 6109 | 6525 | } |
| 6110 | 6526 | if ($translabel!=$field_toshow) { |
| 6111 | 6527 | $value.=dol_trunc($translabel,18).' '; |
| 6112 | - }else { |
|
| 6528 | + } else { |
|
| 6113 | 6529 | $value.=$obj->$field_toshow.' '; |
| 6114 | 6530 | } |
| 6115 | 6531 | } |
| 6116 | - } |
|
| 6117 | - else |
|
| 6532 | + } else |
|
| 6118 | 6533 | { |
| 6119 | 6534 | $translabel=''; |
| 6120 | 6535 | if (!empty($obj->{$InfoFieldList[1]})) { |
@@ -6122,18 +6537,17 @@ discard block |
||
| 6122 | 6537 | } |
| 6123 | 6538 | if ($translabel!=$obj->{$InfoFieldList[1]}) { |
| 6124 | 6539 | $value=dol_trunc($translabel,18); |
| 6125 | - }else { |
|
| 6540 | + } else { |
|
| 6126 | 6541 | $value=$obj->{$InfoFieldList[1]}; |
| 6127 | 6542 | } |
| 6128 | 6543 | } |
| 6544 | + } else { |
|
| 6545 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6129 | 6546 | } |
| 6130 | - else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6131 | - } |
|
| 6132 | - elseif ($type == 'radio') |
|
| 6547 | + } elseif ($type == 'radio') |
|
| 6133 | 6548 | { |
| 6134 | 6549 | $value=$param['options'][$value]; |
| 6135 | - } |
|
| 6136 | - elseif ($type == 'checkbox') |
|
| 6550 | + } elseif ($type == 'checkbox') |
|
| 6137 | 6551 | { |
| 6138 | 6552 | $value_arr=explode(',',$value); |
| 6139 | 6553 | $value=''; |
@@ -6144,8 +6558,7 @@ discard block |
||
| 6144 | 6558 | } |
| 6145 | 6559 | $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
| 6146 | 6560 | } |
| 6147 | - } |
|
| 6148 | - elseif ($type == 'chkbxlst') |
|
| 6561 | + } elseif ($type == 'chkbxlst') |
|
| 6149 | 6562 | { |
| 6150 | 6563 | $value_arr = explode(',', $value); |
| 6151 | 6564 | |
@@ -6213,8 +6626,7 @@ discard block |
||
| 6213 | 6626 | } else { |
| 6214 | 6627 | dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
| 6215 | 6628 | } |
| 6216 | - } |
|
| 6217 | - elseif ($type == 'link') |
|
| 6629 | + } elseif ($type == 'link') |
|
| 6218 | 6630 | { |
| 6219 | 6631 | $out=''; |
| 6220 | 6632 | |
@@ -6236,24 +6648,21 @@ discard block |
||
| 6236 | 6648 | $object->fetch($value); |
| 6237 | 6649 | $value=$object->getNomUrl($getnomurlparam); |
| 6238 | 6650 | } |
| 6239 | - } |
|
| 6240 | - else |
|
| 6651 | + } else |
|
| 6241 | 6652 | { |
| 6242 | 6653 | dol_syslog('Error bad setup of extrafield', LOG_WARNING); |
| 6243 | 6654 | return 'Error bad setup of extrafield'; |
| 6244 | 6655 | } |
| 6656 | + } else { |
|
| 6657 | + $value=''; |
|
| 6245 | 6658 | } |
| 6246 | - else $value=''; |
|
| 6247 | - } |
|
| 6248 | - elseif ($type == 'text' || $type == 'html') |
|
| 6659 | + } elseif ($type == 'text' || $type == 'html') |
|
| 6249 | 6660 | { |
| 6250 | 6661 | $value=dol_htmlentitiesbr($value); |
| 6251 | - } |
|
| 6252 | - elseif ($type == 'password') |
|
| 6662 | + } elseif ($type == 'password') |
|
| 6253 | 6663 | { |
| 6254 | 6664 | $value=preg_replace('/./i','*',$value); |
| 6255 | - } |
|
| 6256 | - elseif ($type == 'array') |
|
| 6665 | + } elseif ($type == 'array') |
|
| 6257 | 6666 | { |
| 6258 | 6667 | $value = implode('<br>', $value); |
| 6259 | 6668 | } |
@@ -6280,7 +6689,9 @@ discard block |
||
| 6280 | 6689 | { |
| 6281 | 6690 | global $db, $conf, $langs, $action, $form; |
| 6282 | 6691 | |
| 6283 | - if (! is_object($form)) $form=new Form($db); |
|
| 6692 | + if (! is_object($form)) { |
|
| 6693 | + $form=new Form($db); |
|
| 6694 | + } |
|
| 6284 | 6695 | |
| 6285 | 6696 | $out = ''; |
| 6286 | 6697 | |
@@ -6294,7 +6705,9 @@ discard block |
||
| 6294 | 6705 | foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
| 6295 | 6706 | { |
| 6296 | 6707 | // Show only the key field in params |
| 6297 | - if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue; |
|
| 6708 | + if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) { |
|
| 6709 | + continue; |
|
| 6710 | + } |
|
| 6298 | 6711 | |
| 6299 | 6712 | $enabled = 1; |
| 6300 | 6713 | if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
@@ -6308,11 +6721,18 @@ discard block |
||
| 6308 | 6721 | $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
| 6309 | 6722 | } |
| 6310 | 6723 | |
| 6311 | - if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6312 | - if (empty($perms)) continue; |
|
| 6724 | + if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) { |
|
| 6725 | + continue; |
|
| 6726 | + } |
|
| 6727 | + // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6728 | + if (empty($perms)) { |
|
| 6729 | + continue; |
|
| 6730 | + } |
|
| 6313 | 6731 | |
| 6314 | 6732 | // Load language if required |
| 6315 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6733 | + if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) { |
|
| 6734 | + $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6735 | + } |
|
| 6316 | 6736 | |
| 6317 | 6737 | $colspan='3'; |
| 6318 | 6738 | if (is_array($params) && count($params)>0) { |
@@ -6346,8 +6766,7 @@ discard block |
||
| 6346 | 6766 | if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') |
| 6347 | 6767 | { |
| 6348 | 6768 | $out .= $extrafields->showSeparator($key, $this); |
| 6349 | - } |
|
| 6350 | - else |
|
| 6769 | + } else |
|
| 6351 | 6770 | { |
| 6352 | 6771 | $csstyle=''; |
| 6353 | 6772 | $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
@@ -6377,10 +6796,12 @@ discard block |
||
| 6377 | 6796 | if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime'))) |
| 6378 | 6797 | { |
| 6379 | 6798 | $datenotinstring = $this->array_options['options_' . $key]; |
| 6380 | - if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
| 6799 | + if (! is_numeric($this->array_options['options_' . $key])) { |
|
| 6800 | + // For backward compatibility |
|
| 6381 | 6801 | { |
| 6382 | 6802 | $datenotinstring = $this->db->jdate($datenotinstring); |
| 6383 | 6803 | } |
| 6804 | + } |
|
| 6384 | 6805 | $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min",'int',3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year",'int',3)):$datenotinstring; |
| 6385 | 6806 | } |
| 6386 | 6807 | // Convert float submited string into real php numeric (value in memory must be a php numeric) |
@@ -6392,11 +6813,18 @@ discard block |
||
| 6392 | 6813 | $labeltoshow = $langs->trans($label); |
| 6393 | 6814 | |
| 6394 | 6815 | $out .= '<td class="titlefield'; |
| 6395 | - if (GETPOST('action','none') == 'create') $out.='create'; |
|
| 6396 | - if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6816 | + if (GETPOST('action','none') == 'create') { |
|
| 6817 | + $out.='create'; |
|
| 6818 | + } |
|
| 6819 | + if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) { |
|
| 6820 | + $out .= ' fieldrequired'; |
|
| 6821 | + } |
|
| 6397 | 6822 | $out .= '">'; |
| 6398 | - if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6399 | - else $out .= $labeltoshow; |
|
| 6823 | + if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) { |
|
| 6824 | + $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6825 | + } else { |
|
| 6826 | + $out .= $labeltoshow; |
|
| 6827 | + } |
|
| 6400 | 6828 | $out .= '</td>'; |
| 6401 | 6829 | |
| 6402 | 6830 | $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
@@ -6413,8 +6841,11 @@ discard block |
||
| 6413 | 6841 | |
| 6414 | 6842 | $out .= '</td>'; |
| 6415 | 6843 | |
| 6416 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 6417 | - else $out .= '</tr>'; |
|
| 6844 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) { |
|
| 6845 | + $out .= '</tr>'; |
|
| 6846 | + } else { |
|
| 6847 | + $out .= '</tr>'; |
|
| 6848 | + } |
|
| 6418 | 6849 | $e++; |
| 6419 | 6850 | } |
| 6420 | 6851 | } |
@@ -6466,7 +6897,9 @@ discard block |
||
| 6466 | 6897 | global $user; |
| 6467 | 6898 | |
| 6468 | 6899 | $element = $this->element; |
| 6469 | - if ($element == 'facturerec') $element='facture'; |
|
| 6900 | + if ($element == 'facturerec') { |
|
| 6901 | + $element='facture'; |
|
| 6902 | + } |
|
| 6470 | 6903 | |
| 6471 | 6904 | return $user->rights->{$element}; |
| 6472 | 6905 | } |
@@ -6491,7 +6924,10 @@ discard block |
||
| 6491 | 6924 | |
| 6492 | 6925 | if (! $db->query($sql)) |
| 6493 | 6926 | { |
| 6494 | - if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B. |
|
| 6927 | + if ($ignoreerrors) { |
|
| 6928 | + return true; |
|
| 6929 | + } |
|
| 6930 | + // TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B. |
|
| 6495 | 6931 | //$this->errors = $db->lasterror(); |
| 6496 | 6932 | return false; |
| 6497 | 6933 | } |
@@ -6518,11 +6954,12 @@ discard block |
||
| 6518 | 6954 | |
| 6519 | 6955 | $buyPrice = 0; |
| 6520 | 6956 | |
| 6521 | - if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false |
|
| 6957 | + if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { |
|
| 6958 | + // In most cases, test here is false |
|
| 6522 | 6959 | { |
| 6523 | 6960 | $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
| 6524 | 6961 | } |
| 6525 | - else |
|
| 6962 | + } else |
|
| 6526 | 6963 | { |
| 6527 | 6964 | // Get cost price for margin calculation |
| 6528 | 6965 | if (! empty($fk_product)) |
@@ -6540,13 +6977,11 @@ discard block |
||
| 6540 | 6977 | if ($product->cost_price > 0) |
| 6541 | 6978 | { |
| 6542 | 6979 | $buyPrice = $product->cost_price; |
| 6543 | - } |
|
| 6544 | - else if ($product->pmp > 0) |
|
| 6980 | + } else if ($product->pmp > 0) |
|
| 6545 | 6981 | { |
| 6546 | 6982 | $buyPrice = $product->pmp; |
| 6547 | 6983 | } |
| 6548 | - } |
|
| 6549 | - else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') |
|
| 6984 | + } else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') |
|
| 6550 | 6985 | { |
| 6551 | 6986 | require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
| 6552 | 6987 | $product = new Product($this->db); |
@@ -6569,8 +7004,7 @@ discard block |
||
| 6569 | 7004 | if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) |
| 6570 | 7005 | { |
| 6571 | 7006 | $buyPrice = $productFournisseur->fourn_unitprice; |
| 6572 | - } |
|
| 6573 | - else if ($result < 0) |
|
| 7007 | + } else if ($result < 0) |
|
| 6574 | 7008 | { |
| 6575 | 7009 | $this->errors[] = $productFournisseur->error; |
| 6576 | 7010 | return -2; |
@@ -6616,8 +7050,7 @@ discard block |
||
| 6616 | 7050 | { |
| 6617 | 7051 | $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
| 6618 | 7052 | $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
| 6619 | - } |
|
| 6620 | - else |
|
| 7053 | + } else |
|
| 6621 | 7054 | { |
| 6622 | 7055 | $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
| 6623 | 7056 | $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
@@ -6680,19 +7113,26 @@ discard block |
||
| 6680 | 7113 | |
| 6681 | 7114 | // Find name of thumb file |
| 6682 | 7115 | $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
| 6683 | - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
| 7116 | + if (! dol_is_file($dirthumb.$photo_vignette)) { |
|
| 7117 | + $photo_vignette=''; |
|
| 7118 | + } |
|
| 6684 | 7119 | |
| 6685 | 7120 | // Get filesize of original file |
| 6686 | 7121 | $imgarray=dol_getImageSize($dir.$photo); |
| 6687 | 7122 | |
| 6688 | 7123 | if ($nbbyrow > 0) |
| 6689 | 7124 | { |
| 6690 | - if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 7125 | + if ($nbphoto == 1) { |
|
| 7126 | + $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 7127 | + } |
|
| 6691 | 7128 | |
| 6692 | - if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
| 7129 | + if ($nbphoto % $nbbyrow == 1) { |
|
| 7130 | + $return.= '<tr align=center valign=middle border=1>'; |
|
| 7131 | + } |
|
| 6693 | 7132 | $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
| 7133 | + } else if ($nbbyrow < 0) { |
|
| 7134 | + $return .= '<div class="inline-block">'; |
|
| 6694 | 7135 | } |
| 6695 | - else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
|
| 6696 | 7136 | |
| 6697 | 7137 | $return.= "\n"; |
| 6698 | 7138 | |
@@ -6700,15 +7140,20 @@ discard block |
||
| 6700 | 7140 | if (empty($nolink)) |
| 6701 | 7141 | { |
| 6702 | 7142 | $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
| 6703 | - if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
| 6704 | - else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 7143 | + if ($urladvanced) { |
|
| 7144 | + $return.='<a href="'.$urladvanced.'">'; |
|
| 7145 | + } else { |
|
| 7146 | + $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 7147 | + } |
|
| 6705 | 7148 | } |
| 6706 | 7149 | |
| 6707 | 7150 | // Show image (width height=$maxHeight) |
| 6708 | 7151 | // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
| 6709 | 7152 | $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile; |
| 6710 | 7153 | $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; |
| 6711 | - if ($notitle) $alt=''; |
|
| 7154 | + if ($notitle) { |
|
| 7155 | + $alt=''; |
|
| 7156 | + } |
|
| 6712 | 7157 | |
| 6713 | 7158 | if ($usesharelink) |
| 6714 | 7159 | { |
@@ -6718,35 +7163,35 @@ discard block |
||
| 6718 | 7163 | { |
| 6719 | 7164 | $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
| 6720 | 7165 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6721 | - } |
|
| 6722 | - else { |
|
| 7166 | + } else { |
|
| 6723 | 7167 | $return.= '<!-- Show original file -->'; |
| 6724 | 7168 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6725 | 7169 | } |
| 6726 | - } |
|
| 6727 | - else |
|
| 7170 | + } else |
|
| 6728 | 7171 | { |
| 6729 | 7172 | $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
| 6730 | 7173 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
| 6731 | 7174 | } |
| 6732 | - } |
|
| 6733 | - else |
|
| 7175 | + } else |
|
| 6734 | 7176 | { |
| 6735 | 7177 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
| 6736 | 7178 | { |
| 6737 | 7179 | $return.= '<!-- Show thumb -->'; |
| 6738 | 7180 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6739 | - } |
|
| 6740 | - else { |
|
| 7181 | + } else { |
|
| 6741 | 7182 | $return.= '<!-- Show original file -->'; |
| 6742 | 7183 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6743 | 7184 | } |
| 6744 | 7185 | } |
| 6745 | 7186 | |
| 6746 | - if (empty($nolink)) $return.= '</a>'; |
|
| 7187 | + if (empty($nolink)) { |
|
| 7188 | + $return.= '</a>'; |
|
| 7189 | + } |
|
| 6747 | 7190 | $return.="\n"; |
| 6748 | 7191 | |
| 6749 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 7192 | + if ($showfilename) { |
|
| 7193 | + $return.= '<br>'.$viewfilename; |
|
| 7194 | + } |
|
| 6750 | 7195 | if ($showaction) |
| 6751 | 7196 | { |
| 6752 | 7197 | $return.= '<br>'; |
@@ -6771,15 +7216,20 @@ discard block |
||
| 6771 | 7216 | if ($nbbyrow > 0) |
| 6772 | 7217 | { |
| 6773 | 7218 | $return.= '</td>'; |
| 6774 | - if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
| 7219 | + if (($nbphoto % $nbbyrow) == 0) { |
|
| 7220 | + $return.= '</tr>'; |
|
| 7221 | + } |
|
| 7222 | + } else if ($nbbyrow < 0) { |
|
| 7223 | + $return.='</div>'; |
|
| 6775 | 7224 | } |
| 6776 | - else if ($nbbyrow < 0) $return.='</div>'; |
|
| 6777 | 7225 | } |
| 6778 | 7226 | |
| 6779 | 7227 | if (empty($size)) { // Format origine |
| 6780 | 7228 | $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
| 6781 | 7229 | |
| 6782 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 7230 | + if ($showfilename) { |
|
| 7231 | + $return.= '<br>'.$viewfilename; |
|
| 7232 | + } |
|
| 6783 | 7233 | if ($showaction) |
| 6784 | 7234 | { |
| 6785 | 7235 | // Special case for product |
@@ -6796,7 +7246,9 @@ discard block |
||
| 6796 | 7246 | } |
| 6797 | 7247 | |
| 6798 | 7248 | // On continue ou on arrete de boucler ? |
| 6799 | - if ($nbmax && $nbphoto >= $nbmax) break; |
|
| 7249 | + if ($nbmax && $nbphoto >= $nbmax) { |
|
| 7250 | + break; |
|
| 7251 | + } |
|
| 6800 | 7252 | } |
| 6801 | 7253 | } |
| 6802 | 7254 | |
@@ -6811,7 +7263,9 @@ discard block |
||
| 6811 | 7263 | $nbphoto++; |
| 6812 | 7264 | } |
| 6813 | 7265 | |
| 6814 | - if ($nbphoto) $return.= '</table>'; |
|
| 7266 | + if ($nbphoto) { |
|
| 7267 | + $return.= '</table>'; |
|
| 7268 | + } |
|
| 6815 | 7269 | } |
| 6816 | 7270 | } |
| 6817 | 7271 | } |
@@ -6832,10 +7286,14 @@ discard block |
||
| 6832 | 7286 | { |
| 6833 | 7287 | if(is_array($info)) |
| 6834 | 7288 | { |
| 6835 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6836 | - else return false; |
|
| 7289 | + if(isset($info['type']) && $info['type']=='array') { |
|
| 7290 | + return true; |
|
| 7291 | + } else { |
|
| 7292 | + return false; |
|
| 7293 | + } |
|
| 7294 | + } else { |
|
| 7295 | + return false; |
|
| 6837 | 7296 | } |
| 6838 | - else return false; |
|
| 6839 | 7297 | } |
| 6840 | 7298 | |
| 6841 | 7299 | /** |
@@ -6848,10 +7306,14 @@ discard block |
||
| 6848 | 7306 | { |
| 6849 | 7307 | if(is_array($info)) |
| 6850 | 7308 | { |
| 6851 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6852 | - else return false; |
|
| 7309 | + if(isset($info['type']) && $info['type']=='null') { |
|
| 7310 | + return true; |
|
| 7311 | + } else { |
|
| 7312 | + return false; |
|
| 7313 | + } |
|
| 7314 | + } else { |
|
| 7315 | + return false; |
|
| 6853 | 7316 | } |
| 6854 | - else return false; |
|
| 6855 | 7317 | } |
| 6856 | 7318 | |
| 6857 | 7319 | /** |
@@ -6862,8 +7324,11 @@ discard block |
||
| 6862 | 7324 | */ |
| 6863 | 7325 | public function isDate($info) |
| 6864 | 7326 | { |
| 6865 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6866 | - else return false; |
|
| 7327 | + if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) { |
|
| 7328 | + return true; |
|
| 7329 | + } else { |
|
| 7330 | + return false; |
|
| 7331 | + } |
|
| 6867 | 7332 | } |
| 6868 | 7333 | |
| 6869 | 7334 | /** |
@@ -6876,10 +7341,14 @@ discard block |
||
| 6876 | 7341 | { |
| 6877 | 7342 | if(is_array($info)) |
| 6878 | 7343 | { |
| 6879 | - if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true; |
|
| 6880 | - else return false; |
|
| 7344 | + if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) { |
|
| 7345 | + return true; |
|
| 7346 | + } else { |
|
| 7347 | + return false; |
|
| 7348 | + } |
|
| 7349 | + } else { |
|
| 7350 | + return false; |
|
| 6881 | 7351 | } |
| 6882 | - else return false; |
|
| 6883 | 7352 | } |
| 6884 | 7353 | |
| 6885 | 7354 | /** |
@@ -6892,10 +7361,14 @@ discard block |
||
| 6892 | 7361 | { |
| 6893 | 7362 | if(is_array($info)) |
| 6894 | 7363 | { |
| 6895 | - if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true; |
|
| 6896 | - else return false; |
|
| 7364 | + if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) { |
|
| 7365 | + return true; |
|
| 7366 | + } else { |
|
| 7367 | + return false; |
|
| 7368 | + } |
|
| 7369 | + } else { |
|
| 7370 | + return false; |
|
| 6897 | 7371 | } |
| 6898 | - else return false; |
|
| 6899 | 7372 | } |
| 6900 | 7373 | |
| 6901 | 7374 | /** |
@@ -6908,10 +7381,14 @@ discard block |
||
| 6908 | 7381 | { |
| 6909 | 7382 | if(is_array($info)) |
| 6910 | 7383 | { |
| 6911 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6912 | - else return false; |
|
| 7384 | + if(isset($info['type']) && $info['type']=='text') { |
|
| 7385 | + return true; |
|
| 7386 | + } else { |
|
| 7387 | + return false; |
|
| 7388 | + } |
|
| 7389 | + } else { |
|
| 7390 | + return false; |
|
| 6913 | 7391 | } |
| 6914 | - else return false; |
|
| 6915 | 7392 | } |
| 6916 | 7393 | |
| 6917 | 7394 | /** |
@@ -6924,10 +7401,14 @@ discard block |
||
| 6924 | 7401 | { |
| 6925 | 7402 | if(is_array($info)) |
| 6926 | 7403 | { |
| 6927 | - if(isset($info['index']) && $info['index']==true) return true; |
|
| 6928 | - else return false; |
|
| 7404 | + if(isset($info['index']) && $info['index']==true) { |
|
| 7405 | + return true; |
|
| 7406 | + } else { |
|
| 7407 | + return false; |
|
| 7408 | + } |
|
| 7409 | + } else { |
|
| 7410 | + return false; |
|
| 6929 | 7411 | } |
| 6930 | - else return false; |
|
| 6931 | 7412 | } |
| 6932 | 7413 | |
| 6933 | 7414 | /** |
@@ -6941,7 +7422,8 @@ discard block |
||
| 6941 | 7422 | global $conf; |
| 6942 | 7423 | |
| 6943 | 7424 | $queryarray=array(); |
| 6944 | - foreach ($this->fields as $field=>$info) // Loop on definition of fields |
|
| 7425 | + foreach ($this->fields as $field=>$info) { |
|
| 7426 | + // Loop on definition of fields |
|
| 6945 | 7427 | { |
| 6946 | 7428 | // Depending on field type ('datetime', ...) |
| 6947 | 7429 | if($this->isDate($info)) |
@@ -6949,13 +7431,12 @@ discard block |
||
| 6949 | 7431 | if(empty($this->{$field})) |
| 6950 | 7432 | { |
| 6951 | 7433 | $queryarray[$field] = null; |
| 6952 | - } |
|
| 6953 | - else |
|
| 7434 | + } |
|
| 7435 | + } else |
|
| 6954 | 7436 | { |
| 6955 | 7437 | $queryarray[$field] = $this->db->idate($this->{$field}); |
| 6956 | 7438 | } |
| 6957 | - } |
|
| 6958 | - else if($this->isArray($info)) |
|
| 7439 | + } else if($this->isArray($info)) |
|
| 6959 | 7440 | { |
| 6960 | 7441 | if(! empty($this->{$field})) { |
| 6961 | 7442 | if(! is_array($this->{$field})) { |
@@ -6965,28 +7446,35 @@ discard block |
||
| 6965 | 7446 | } else { |
| 6966 | 7447 | $queryarray[$field] = null; |
| 6967 | 7448 | } |
| 6968 | - } |
|
| 6969 | - else if($this->isInt($info)) |
|
| 7449 | + } else if($this->isInt($info)) |
|
| 6970 | 7450 | { |
| 6971 | - if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity; |
|
| 6972 | - else |
|
| 7451 | + if ($field == 'entity' && is_null($this->{$field})) { |
|
| 7452 | + $queryarray[$field]=$conf->entity; |
|
| 7453 | + } else |
|
| 6973 | 7454 | { |
| 6974 | 7455 | $queryarray[$field] = (int) price2num($this->{$field}); |
| 6975 | - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 7456 | + if (empty($queryarray[$field])) { |
|
| 7457 | + $queryarray[$field]=0; |
|
| 7458 | + } |
|
| 7459 | + // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6976 | 7460 | } |
| 6977 | - } |
|
| 6978 | - else if($this->isFloat($info)) |
|
| 7461 | + } else if($this->isFloat($info)) |
|
| 6979 | 7462 | { |
| 6980 | 7463 | $queryarray[$field] = (double) price2num($this->{$field}); |
| 6981 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6982 | - } |
|
| 6983 | - else |
|
| 7464 | + if (empty($queryarray[$field])) { |
|
| 7465 | + $queryarray[$field]=0; |
|
| 7466 | + } |
|
| 7467 | + } else |
|
| 6984 | 7468 | { |
| 6985 | 7469 | $queryarray[$field] = $this->{$field}; |
| 6986 | 7470 | } |
| 6987 | 7471 | |
| 6988 | - if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
|
| 6989 | - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 7472 | + if ($info['type'] == 'timestamp' && empty($queryarray[$field])) { |
|
| 7473 | + unset($queryarray[$field]); |
|
| 7474 | + } |
|
| 7475 | + if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) { |
|
| 7476 | + $queryarray[$field] = null; |
|
| 7477 | + } |
|
| 6990 | 7478 | } |
| 6991 | 7479 | |
| 6992 | 7480 | return $queryarray; |
@@ -7004,42 +7492,47 @@ discard block |
||
| 7004 | 7492 | { |
| 7005 | 7493 | if($this->isDate($info)) |
| 7006 | 7494 | { |
| 7007 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; |
|
| 7008 | - else $this->{$field} = strtotime($obj->{$field}); |
|
| 7009 | - } |
|
| 7010 | - elseif($this->isArray($info)) |
|
| 7495 | + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') { |
|
| 7496 | + $this->{$field} = 0; |
|
| 7497 | + } else { |
|
| 7498 | + $this->{$field} = strtotime($obj->{$field}); |
|
| 7499 | + } |
|
| 7500 | + } elseif($this->isArray($info)) |
|
| 7011 | 7501 | { |
| 7012 | 7502 | if(! empty($obj->{$field})) { |
| 7013 | 7503 | $this->{$field} = @unserialize($obj->{$field}); |
| 7014 | 7504 | // Hack for data not in UTF8 |
| 7015 | - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field})); |
|
| 7505 | + if($this->{$field } === false) { |
|
| 7506 | + @unserialize(utf8_decode($obj->{$field})); |
|
| 7507 | + } |
|
| 7016 | 7508 | } else { |
| 7017 | 7509 | $this->{$field} = array(); |
| 7018 | 7510 | } |
| 7019 | - } |
|
| 7020 | - elseif($this->isInt($info)) |
|
| 7511 | + } elseif($this->isInt($info)) |
|
| 7021 | 7512 | { |
| 7022 | - if ($field == 'rowid') $this->id = (int) $obj->{$field}; |
|
| 7023 | - else $this->{$field} = (int) $obj->{$field}; |
|
| 7024 | - } |
|
| 7025 | - elseif($this->isFloat($info)) |
|
| 7513 | + if ($field == 'rowid') { |
|
| 7514 | + $this->id = (int) $obj->{$field}; |
|
| 7515 | + } else { |
|
| 7516 | + $this->{$field} = (int) $obj->{$field}; |
|
| 7517 | + } |
|
| 7518 | + } elseif($this->isFloat($info)) |
|
| 7026 | 7519 | { |
| 7027 | 7520 | $this->{$field} = (double) $obj->{$field}; |
| 7028 | - } |
|
| 7029 | - elseif($this->isNull($info)) |
|
| 7521 | + } elseif($this->isNull($info)) |
|
| 7030 | 7522 | { |
| 7031 | 7523 | $val = $obj->{$field}; |
| 7032 | 7524 | // zero is not null |
| 7033 | 7525 | $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); |
| 7034 | - } |
|
| 7035 | - else |
|
| 7526 | + } else |
|
| 7036 | 7527 | { |
| 7037 | 7528 | $this->{$field} = $obj->{$field}; |
| 7038 | 7529 | } |
| 7039 | 7530 | } |
| 7040 | 7531 | |
| 7041 | 7532 | // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
| 7042 | - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7533 | + if (! isset($this->fields['ref']) && isset($this->id)) { |
|
| 7534 | + $this->ref = $this->id; |
|
| 7535 | + } |
|
| 7043 | 7536 | } |
| 7044 | 7537 | |
| 7045 | 7538 | /** |
@@ -7062,9 +7555,13 @@ discard block |
||
| 7062 | 7555 | */ |
| 7063 | 7556 | protected function quote($value, $fieldsentry) |
| 7064 | 7557 | { |
| 7065 | - if (is_null($value)) return 'NULL'; |
|
| 7066 | - else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value"); |
|
| 7067 | - else return "'".$this->db->escape($value)."'"; |
|
| 7558 | + if (is_null($value)) { |
|
| 7559 | + return 'NULL'; |
|
| 7560 | + } else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) { |
|
| 7561 | + return $this->db->escape("$value"); |
|
| 7562 | + } else { |
|
| 7563 | + return "'".$this->db->escape($value)."'"; |
|
| 7564 | + } |
|
| 7068 | 7565 | } |
| 7069 | 7566 | |
| 7070 | 7567 | |
@@ -7084,8 +7581,12 @@ discard block |
||
| 7084 | 7581 | $now=dol_now(); |
| 7085 | 7582 | |
| 7086 | 7583 | $fieldvalues = $this->setSaveQuery(); |
| 7087 | - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now); |
|
| 7088 | - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id; |
|
| 7584 | + if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) { |
|
| 7585 | + $fieldvalues['date_creation']=$this->db->idate($now); |
|
| 7586 | + } |
|
| 7587 | + if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) { |
|
| 7588 | + $fieldvalues['fk_user_creat']=$user->id; |
|
| 7589 | + } |
|
| 7089 | 7590 | unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
| 7090 | 7591 | |
| 7091 | 7592 | $keys=array(); |
@@ -7100,8 +7601,12 @@ discard block |
||
| 7100 | 7601 | foreach($keys as $key) |
| 7101 | 7602 | { |
| 7102 | 7603 | // If field is an implicit foreign key field |
| 7103 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; |
|
| 7104 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
| 7604 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') { |
|
| 7605 | + $values[$key]=''; |
|
| 7606 | + } |
|
| 7607 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') { |
|
| 7608 | + $values[$key]=''; |
|
| 7609 | + } |
|
| 7105 | 7610 | |
| 7106 | 7611 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7107 | 7612 | if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
@@ -7111,11 +7616,17 @@ discard block |
||
| 7111 | 7616 | } |
| 7112 | 7617 | |
| 7113 | 7618 | // If field is an implicit foreign key field |
| 7114 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null'; |
|
| 7115 | - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
| 7619 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) { |
|
| 7620 | + $values[$key]='null'; |
|
| 7621 | + } |
|
| 7622 | + if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) { |
|
| 7623 | + $values[$key]='null'; |
|
| 7624 | + } |
|
| 7116 | 7625 | } |
| 7117 | 7626 | |
| 7118 | - if ($error) return -1; |
|
| 7627 | + if ($error) { |
|
| 7628 | + return -1; |
|
| 7629 | + } |
|
| 7119 | 7630 | |
| 7120 | 7631 | $this->db->begin(); |
| 7121 | 7632 | |
@@ -7141,7 +7652,9 @@ discard block |
||
| 7141 | 7652 | if (! $error) |
| 7142 | 7653 | { |
| 7143 | 7654 | $result=$this->insertExtraFields(); |
| 7144 | - if ($result < 0) $error++; |
|
| 7655 | + if ($result < 0) { |
|
| 7656 | + $error++; |
|
| 7657 | + } |
|
| 7145 | 7658 | } |
| 7146 | 7659 | |
| 7147 | 7660 | // Triggers |
@@ -7174,15 +7687,24 @@ discard block |
||
| 7174 | 7687 | */ |
| 7175 | 7688 | public function fetchCommon($id, $ref = null, $morewhere = '') |
| 7176 | 7689 | { |
| 7177 | - if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
|
| 7690 | + if (empty($id) && empty($ref) && empty($morewhere)) { |
|
| 7691 | + return -1; |
|
| 7692 | + } |
|
| 7178 | 7693 | |
| 7179 | 7694 | $sql = 'SELECT '.$this->getFieldList(); |
| 7180 | 7695 | $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
| 7181 | 7696 | |
| 7182 | - if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
| 7183 | - elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7184 | - else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
| 7185 | - if ($morewhere) $sql.= $morewhere; |
|
| 7697 | + if (!empty($id)) { |
|
| 7698 | + $sql.= ' WHERE rowid = '.$id; |
|
| 7699 | + } elseif (!empty($ref)) { |
|
| 7700 | + $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7701 | + } else { |
|
| 7702 | + $sql.=' WHERE 1 = 1'; |
|
| 7703 | + } |
|
| 7704 | + // usage with empty id and empty ref is very rare |
|
| 7705 | + if ($morewhere) { |
|
| 7706 | + $sql.= $morewhere; |
|
| 7707 | + } |
|
| 7186 | 7708 | $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
| 7187 | 7709 | |
| 7188 | 7710 | $res = $this->db->query($sql); |
@@ -7193,13 +7715,11 @@ discard block |
||
| 7193 | 7715 | { |
| 7194 | 7716 | $this->setVarsFromFetchObj($obj); |
| 7195 | 7717 | return $this->id; |
| 7196 | - } |
|
| 7197 | - else |
|
| 7718 | + } else |
|
| 7198 | 7719 | { |
| 7199 | 7720 | return 0; |
| 7200 | 7721 | } |
| 7201 | - } |
|
| 7202 | - else |
|
| 7722 | + } else |
|
| 7203 | 7723 | { |
| 7204 | 7724 | $this->error = $this->db->lasterror(); |
| 7205 | 7725 | $this->errors[] = $this->error; |
@@ -7223,8 +7743,12 @@ discard block |
||
| 7223 | 7743 | $now=dol_now(); |
| 7224 | 7744 | |
| 7225 | 7745 | $fieldvalues = $this->setSaveQuery(); |
| 7226 | - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now); |
|
| 7227 | - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id; |
|
| 7746 | + if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) { |
|
| 7747 | + $fieldvalues['date_modification']=$this->db->idate($now); |
|
| 7748 | + } |
|
| 7749 | + if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) { |
|
| 7750 | + $fieldvalues['fk_user_modif']=$user->id; |
|
| 7751 | + } |
|
| 7228 | 7752 | unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
| 7229 | 7753 | |
| 7230 | 7754 | $keys=array(); |
@@ -7239,8 +7763,14 @@ discard block |
||
| 7239 | 7763 | // Clean and check mandatory |
| 7240 | 7764 | foreach($keys as $key) |
| 7241 | 7765 | { |
| 7242 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field |
|
| 7243 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
| 7766 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') { |
|
| 7767 | + $values[$key]=''; |
|
| 7768 | + } |
|
| 7769 | + // This is an implicit foreign key field |
|
| 7770 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') { |
|
| 7771 | + $values[$key]=''; |
|
| 7772 | + } |
|
| 7773 | + // This is an explicit foreign key field |
|
| 7244 | 7774 | |
| 7245 | 7775 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7246 | 7776 | /* |
@@ -7321,10 +7851,11 @@ discard block |
||
| 7321 | 7851 | return -1; |
| 7322 | 7852 | } |
| 7323 | 7853 | } |
| 7324 | - } |
|
| 7325 | - elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7854 | + } elseif (! empty($this->fk_element) && ! empty($this->childtables)) { |
|
| 7855 | + // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7326 | 7856 | { |
| 7327 | 7857 | $objectisused = $this->isObjectUsed($this->id); |
| 7858 | + } |
|
| 7328 | 7859 | if (! empty($objectisused)) |
| 7329 | 7860 | { |
| 7330 | 7861 | dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
@@ -7431,7 +7962,9 @@ discard block |
||
| 7431 | 7962 | */ |
| 7432 | 7963 | public function trimParameters($parameters) |
| 7433 | 7964 | { |
| 7434 | - if (!is_array($parameters)) return; |
|
| 7965 | + if (!is_array($parameters)) { |
|
| 7966 | + return; |
|
| 7967 | + } |
|
| 7435 | 7968 | foreach ($parameters as $parameter) { |
| 7436 | 7969 | if (isset($this->$parameter)) { |
| 7437 | 7970 | $this->$parameter = trim($this->$parameter); |
@@ -172,9 +172,13 @@ |
||
| 172 | 172 | |
| 173 | 173 | |
| 174 | 174 | $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
| 175 | - if ($id) $sql.= " WHERE t.id = ".$id; |
|
| 176 | - elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 177 | - elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
| 175 | + if ($id) { |
|
| 176 | + $sql.= " WHERE t.id = ".$id; |
|
| 177 | + } elseif ($code) { |
|
| 178 | + $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 179 | + } elseif ($label) { |
|
| 180 | + $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
| 181 | + } |
|
| 178 | 182 | |
| 179 | 183 | |
| 180 | 184 | $resql = $this->db->query($sql); |
@@ -105,7 +105,9 @@ discard block |
||
| 105 | 105 | // phpcs:enable |
| 106 | 106 | global $conf, $langs, $user, $form; |
| 107 | 107 | |
| 108 | - if (! is_object($form)) $form=new Form($this->db); |
|
| 108 | + if (! is_object($form)) { |
|
| 109 | + $form=new Form($this->db); |
|
| 110 | + } |
|
| 109 | 111 | |
| 110 | 112 | // Load translation files required by the page |
| 111 | 113 | $langs->loadLangs(array('other', 'mails', 'sms')); |
@@ -131,7 +133,9 @@ discard block |
||
| 131 | 133 | } |
| 132 | 134 | </script>'; |
| 133 | 135 | |
| 134 | - if ($showform) print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n"; |
|
| 136 | + if ($showform) { |
|
| 137 | + print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n"; |
|
| 138 | + } |
|
| 135 | 139 | |
| 136 | 140 | print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
| 137 | 141 | foreach ($this->param as $key=>$value) |
@@ -141,9 +145,11 @@ discard block |
||
| 141 | 145 | print "<table class=\"border centpercent\">\n"; |
| 142 | 146 | |
| 143 | 147 | // Substitution array |
| 144 | - if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this. |
|
| 148 | + if (! empty($this->withsubstit)) { |
|
| 149 | + // Unset or set ->withsubstit=0 to disable this. |
|
| 145 | 150 | { |
| 146 | 151 | print "<tr><td colspan=\"2\">"; |
| 152 | + } |
|
| 147 | 153 | $help=""; |
| 148 | 154 | foreach($this->substit as $key => $val) |
| 149 | 155 | { |
@@ -172,8 +178,7 @@ discard block |
||
| 172 | 178 | if ($this->fromsms) |
| 173 | 179 | { |
| 174 | 180 | print $this->fromsms; |
| 175 | - } |
|
| 176 | - else |
|
| 181 | + } else |
|
| 177 | 182 | { |
| 178 | 183 | if ($this->fromtype) |
| 179 | 184 | { |
@@ -183,34 +188,34 @@ discard block |
||
| 183 | 188 | } |
| 184 | 189 | print "</td></tr>\n"; |
| 185 | 190 | print "</td></tr>\n"; |
| 186 | - } |
|
| 187 | - else |
|
| 191 | + } else |
|
| 188 | 192 | { |
| 189 | 193 | print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>"; |
| 190 | 194 | //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">'; |
| 191 | - if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // For backward compatibility @deprecated |
|
| 195 | + if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') { |
|
| 196 | + // For backward compatibility @deprecated |
|
| 192 | 197 | { |
| 193 | 198 | dol_include_once('/ovh/class/ovhsms.class.php'); |
| 199 | + } |
|
| 194 | 200 | try |
| 195 | 201 | { |
| 196 | 202 | $sms = new OvhSms($this->db); |
| 197 | 203 | if (empty($conf->global->OVHSMS_ACCOUNT)) |
| 198 | 204 | { |
| 199 | 205 | $resultsender = 'ErrorOVHSMS_ACCOUNT not defined'; |
| 200 | - } |
|
| 201 | - else |
|
| 206 | + } else |
|
| 202 | 207 | { |
| 203 | 208 | $resultsender = $sms->SmsSenderList(); |
| 204 | 209 | } |
| 205 | - } |
|
| 206 | - catch(Exception $e) |
|
| 210 | + } catch(Exception $e) |
|
| 207 | 211 | { |
| 208 | 212 | dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
| 209 | 213 | } |
| 210 | - } |
|
| 211 | - else if (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module' |
|
| 214 | + } else if (!empty($conf->global->MAIN_SMS_SENDMODE)) { |
|
| 215 | + // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module' |
|
| 212 | 216 | { |
| 213 | 217 | $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE); |
| 218 | + } |
|
| 214 | 219 | $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]); |
| 215 | 220 | dol_include_once('/'.$module.'/class/'.$classfile.'.class.php'); |
| 216 | 221 | try |
@@ -220,20 +225,17 @@ discard block |
||
| 220 | 225 | { |
| 221 | 226 | $sms = new $classname($this->db); |
| 222 | 227 | $resultsender = $sms->SmsSenderList(); |
| 223 | - } |
|
| 224 | - else |
|
| 228 | + } else |
|
| 225 | 229 | { |
| 226 | 230 | $sms = new stdClass(); |
| 227 | 231 | $sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found'; |
| 228 | 232 | } |
| 229 | - } |
|
| 230 | - catch(Exception $e) |
|
| 233 | + } catch(Exception $e) |
|
| 231 | 234 | { |
| 232 | 235 | dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
| 233 | 236 | exit; |
| 234 | 237 | } |
| 235 | - } |
|
| 236 | - else |
|
| 238 | + } else |
|
| 237 | 239 | { |
| 238 | 240 | dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING); |
| 239 | 241 | $resultsender=array(); |
@@ -248,11 +250,12 @@ discard block |
||
| 248 | 250 | print '<option value="'.$obj->number.'">'.$obj->number.'</option>'; |
| 249 | 251 | } |
| 250 | 252 | print '</select>'; |
| 251 | - } |
|
| 252 | - else |
|
| 253 | + } else |
|
| 253 | 254 | { |
| 254 | 255 | print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound"); |
| 255 | - if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error; |
|
| 256 | + if (is_object($sms) && ! empty($sms->error)) { |
|
| 257 | + print ' '.$sms->error; |
|
| 258 | + } |
|
| 256 | 259 | print '</span>'; |
| 257 | 260 | } |
| 258 | 261 | print '</td>'; |
@@ -271,8 +274,7 @@ discard block |
||
| 271 | 274 | if ($this->withtoreadonly) |
| 272 | 275 | { |
| 273 | 276 | print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; |
| 274 | - } |
|
| 275 | - else |
|
| 277 | + } else |
|
| 276 | 278 | { |
| 277 | 279 | print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?GETPOST("sendto"):$this->withto):"+")."\">"; |
| 278 | 280 | if (! empty($this->withtosocid) && $this->withtosocid > 0) |
@@ -300,7 +302,9 @@ discard block |
||
| 300 | 302 | $defaultmessage=$this->withbody; |
| 301 | 303 | } |
| 302 | 304 | $defaultmessage=make_substitutions($defaultmessage,$this->substit); |
| 303 | - if (isset($_POST["message"])) $defaultmessage=$_POST["message"]; |
|
| 305 | + if (isset($_POST["message"])) { |
|
| 306 | + $defaultmessage=$_POST["message"]; |
|
| 307 | + } |
|
| 304 | 308 | $defaultmessage=str_replace('\n',"\n",$defaultmessage); |
| 305 | 309 | |
| 306 | 310 | print "<tr>"; |
@@ -310,8 +314,7 @@ discard block |
||
| 310 | 314 | { |
| 311 | 315 | print nl2br($defaultmessage); |
| 312 | 316 | print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">'; |
| 313 | - } |
|
| 314 | - else |
|
| 317 | + } else |
|
| 315 | 318 | { |
| 316 | 319 | print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>'; |
| 317 | 320 | print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>'; |
@@ -125,7 +125,9 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | $this->sendcontext = $sendcontext; |
| 127 | 127 | |
| 128 | - if (empty($replyto)) $replyto=$from; |
|
| 128 | + if (empty($replyto)) { |
|
| 129 | + $replyto=$from; |
|
| 130 | + } |
|
| 129 | 131 | |
| 130 | 132 | // Define this->sendmode |
| 131 | 133 | $this->sendmode = ''; |
@@ -133,8 +135,12 @@ discard block |
||
| 133 | 135 | { |
| 134 | 136 | $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE_EMAILING; |
| 135 | 137 | } |
| 136 | - if (empty($this->sendmode)) $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE; |
|
| 137 | - if (empty($this->sendmode)) $this->sendmode='mail'; |
|
| 138 | + if (empty($this->sendmode)) { |
|
| 139 | + $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE; |
|
| 140 | + } |
|
| 141 | + if (empty($this->sendmode)) { |
|
| 142 | + $this->sendmode='mail'; |
|
| 143 | + } |
|
| 138 | 144 | |
| 139 | 145 | // We define end of line (RFC 821). |
| 140 | 146 | $this->eol="\r\n"; |
@@ -175,9 +181,10 @@ discard block |
||
| 175 | 181 | if ($msgishtml == -1) |
| 176 | 182 | { |
| 177 | 183 | $this->msgishtml = 0; |
| 178 | - if (dol_textishtml($msg)) $this->msgishtml = 1; |
|
| 179 | - } |
|
| 180 | - else |
|
| 184 | + if (dol_textishtml($msg)) { |
|
| 185 | + $this->msgishtml = 1; |
|
| 186 | + } |
|
| 187 | + } else |
|
| 181 | 188 | { |
| 182 | 189 | $this->msgishtml = $msgishtml; |
| 183 | 190 | } |
@@ -192,7 +199,10 @@ discard block |
||
| 192 | 199 | // Replace relative /viewimage to absolute path |
| 193 | 200 | $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep); |
| 194 | 201 | |
| 195 | - if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml=1; // To force to send everything with content type html. |
|
| 202 | + if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) { |
|
| 203 | + $this->msgishtml=1; |
|
| 204 | + } |
|
| 205 | + // To force to send everything with content type html. |
|
| 196 | 206 | |
| 197 | 207 | // Detect images |
| 198 | 208 | if ($this->msgishtml) |
@@ -232,7 +242,9 @@ discard block |
||
| 232 | 242 | } |
| 233 | 243 | |
| 234 | 244 | // Add autocopy to (Note: Adding bcc for specific modules are also done from pages) |
| 235 | - if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
| 245 | + if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) { |
|
| 246 | + $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
| 247 | + } |
|
| 236 | 248 | |
| 237 | 249 | // Action according to choosed sending method |
| 238 | 250 | if ($this->sendmode == 'mail') |
@@ -257,7 +269,10 @@ discard block |
||
| 257 | 269 | $this->trackid = $trackid; |
| 258 | 270 | |
| 259 | 271 | $smtp_headers = $this->write_smtpheaders(); |
| 260 | - if (! empty($moreinheader)) $smtp_headers.=$moreinheader; // $moreinheader contains the \r\n |
|
| 272 | + if (! empty($moreinheader)) { |
|
| 273 | + $smtp_headers.=$moreinheader; |
|
| 274 | + } |
|
| 275 | + // $moreinheader contains the \r\n |
|
| 261 | 276 | |
| 262 | 277 | // Define mime_headers |
| 263 | 278 | $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); |
@@ -293,8 +308,7 @@ discard block |
||
| 293 | 308 | $this->message = 'This is a message with multiple parts in MIME format.'.$this->eol; |
| 294 | 309 | $this->message.= $text_body . $files_encoded; |
| 295 | 310 | $this->message.= "--" . $this->mixed_boundary . "--" . $this->eol; |
| 296 | - } |
|
| 297 | - else if ($this->sendmode == 'smtps') |
|
| 311 | + } else if ($this->sendmode == 'smtps') |
|
| 298 | 312 | { |
| 299 | 313 | // Use SMTPS library |
| 300 | 314 | // ------------------------------------------ |
@@ -309,7 +323,9 @@ discard block |
||
| 309 | 323 | $smtps->setTrackId($trackid); |
| 310 | 324 | $smtps->setReplyTo($this->getValidAddress($replyto,0,1)); |
| 311 | 325 | |
| 312 | - if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader); |
|
| 326 | + if (! empty($moreinheader)) { |
|
| 327 | + $smtps->setMoreInHeader($moreinheader); |
|
| 328 | + } |
|
| 313 | 329 | |
| 314 | 330 | if (! empty($this->html)) |
| 315 | 331 | { |
@@ -322,8 +338,11 @@ discard block |
||
| 322 | 338 | $msg = $this->checkIfHTML($msg); |
| 323 | 339 | } |
| 324 | 340 | |
| 325 | - if ($this->msgishtml) $smtps->setBodyContent($msg,'html'); |
|
| 326 | - else $smtps->setBodyContent($msg,'plain'); |
|
| 341 | + if ($this->msgishtml) { |
|
| 342 | + $smtps->setBodyContent($msg,'html'); |
|
| 343 | + } else { |
|
| 344 | + $smtps->setBodyContent($msg,'plain'); |
|
| 345 | + } |
|
| 327 | 346 | |
| 328 | 347 | if ($this->atleastoneimage) |
| 329 | 348 | { |
@@ -348,8 +367,7 @@ discard block |
||
| 348 | 367 | $smtps->setDeliveryReceipt($deliveryreceipt); |
| 349 | 368 | |
| 350 | 369 | $this->smtps=$smtps; |
| 351 | - } |
|
| 352 | - else if ($this->sendmode == 'swiftmailer') |
|
| 370 | + } else if ($this->sendmode == 'swiftmailer') |
|
| 353 | 371 | { |
| 354 | 372 | // Use Swift Mailer library |
| 355 | 373 | // ------------------------------------------ |
@@ -474,12 +492,17 @@ discard block |
||
| 474 | 492 | } |
| 475 | 493 | } |
| 476 | 494 | |
| 477 | - if (! empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc)); |
|
| 478 | - if (! empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc)); |
|
| 495 | + if (! empty($addr_cc)) { |
|
| 496 | + $this->message->setCc($this->getArrayAddress($addr_cc)); |
|
| 497 | + } |
|
| 498 | + if (! empty($addr_bcc)) { |
|
| 499 | + $this->message->setBcc($this->getArrayAddress($addr_bcc)); |
|
| 500 | + } |
|
| 479 | 501 | //if (! empty($errors_to)) $this->message->setErrorsTo($this->getArrayAddress($errors_to); |
| 480 | - if (isset($deliveryreceipt) && $deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($from)); |
|
| 481 | - } |
|
| 482 | - else |
|
| 502 | + if (isset($deliveryreceipt) && $deliveryreceipt == 1) { |
|
| 503 | + $this->message->setReadReceiptTo($this->getArrayAddress($from)); |
|
| 504 | + } |
|
| 505 | + } else |
|
| 483 | 506 | { |
| 484 | 507 | // Send mail method not correctly defined |
| 485 | 508 | // -------------------------------------- |
@@ -517,13 +540,17 @@ discard block |
||
| 517 | 540 | |
| 518 | 541 | return $reshook; |
| 519 | 542 | } |
| 520 | - if ($reshook == 1) // Hook replace standard code |
|
| 543 | + if ($reshook == 1) { |
|
| 544 | + // Hook replace standard code |
|
| 521 | 545 | { |
| 522 | 546 | return true; |
| 523 | 547 | } |
| 548 | + } |
|
| 524 | 549 | |
| 525 | 550 | // Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL |
| 526 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10; |
|
| 551 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) { |
|
| 552 | + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10; |
|
| 553 | + } |
|
| 527 | 554 | $tmparray1 = explode(',', $this->addr_to); |
| 528 | 555 | if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL) |
| 529 | 556 | { |
@@ -531,7 +558,9 @@ discard block |
||
| 531 | 558 | dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
| 532 | 559 | return false; |
| 533 | 560 | } |
| 534 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10; |
|
| 561 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) { |
|
| 562 | + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10; |
|
| 563 | + } |
|
| 535 | 564 | $tmparray2 = explode(',', $this->addr_cc); |
| 536 | 565 | if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL) |
| 537 | 566 | { |
@@ -539,7 +568,9 @@ discard block |
||
| 539 | 568 | dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
| 540 | 569 | return false; |
| 541 | 570 | } |
| 542 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10; |
|
| 571 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) { |
|
| 572 | + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10; |
|
| 573 | + } |
|
| 543 | 574 | $tmparray3 = explode(',', $this->addr_bcc); |
| 544 | 575 | if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL) |
| 545 | 576 | { |
@@ -547,7 +578,9 @@ discard block |
||
| 547 | 578 | dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
| 548 | 579 | return false; |
| 549 | 580 | } |
| 550 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10; |
|
| 581 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) { |
|
| 582 | + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10; |
|
| 583 | + } |
|
| 551 | 584 | if ((count($tmparray1)+count($tmparray2)+count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL) |
| 552 | 585 | { |
| 553 | 586 | $this->error = 'Too much recipients in to:, cc:, bcc:'; |
@@ -590,13 +623,19 @@ discard block |
||
| 590 | 623 | // If Windows, sendmail_from must be defined |
| 591 | 624 | if (isset($_SERVER["WINDIR"])) |
| 592 | 625 | { |
| 593 | - if (empty($this->addr_from)) $this->addr_from = '[email protected]'; |
|
| 626 | + if (empty($this->addr_from)) { |
|
| 627 | + $this->addr_from = '[email protected]'; |
|
| 628 | + } |
|
| 594 | 629 | @ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2)); |
| 595 | 630 | } |
| 596 | 631 | |
| 597 | 632 | // Force parameters |
| 598 | - if (! empty($conf->global->$keyforsmtpserver)) ini_set('SMTP',$conf->global->$keyforsmtpserver); |
|
| 599 | - if (! empty($conf->global->$keyforsmtpport)) ini_set('smtp_port',$conf->global->$keyforsmtpport); |
|
| 633 | + if (! empty($conf->global->$keyforsmtpserver)) { |
|
| 634 | + ini_set('SMTP',$conf->global->$keyforsmtpserver); |
|
| 635 | + } |
|
| 636 | + if (! empty($conf->global->$keyforsmtpport)) { |
|
| 637 | + ini_set('smtp_port',$conf->global->$keyforsmtpport); |
|
| 638 | + } |
|
| 600 | 639 | |
| 601 | 640 | $res=true; |
| 602 | 641 | if ($res && ! $this->subject) |
@@ -624,29 +663,43 @@ discard block |
||
| 624 | 663 | // Having this variable not defined may create problems with some other sendmail (option -f required) |
| 625 | 664 | $additionnalparam .= ($additionnalparam?' ':'').(! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f' . $this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO,2) : ($this->addr_from != '' ? '-f' . $this->getValidAddress($this->addr_from,2) : '') ); |
| 626 | 665 | } |
| 627 | - if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender |
|
| 666 | + if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) { |
|
| 667 | + // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender |
|
| 628 | 668 | { |
| 629 | 669 | $additionnalparam .= ($additionnalparam?' ':'').'-ba'; |
| 630 | 670 | } |
| 671 | + } |
|
| 631 | 672 | |
| 632 | - if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; // Use -U to add additionnal params |
|
| 673 | + if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) { |
|
| 674 | + $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; |
|
| 675 | + } |
|
| 676 | + // Use -U to add additionnal params |
|
| 633 | 677 | |
| 634 | 678 | dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", additionnal_parameters=".$additionnalparam, LOG_DEBUG); |
| 635 | 679 | |
| 636 | 680 | $this->message=stripslashes($this->message); |
| 637 | 681 | |
| 638 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 682 | + if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 683 | + $this->dump_mail(); |
|
| 684 | + } |
|
| 639 | 685 | |
| 640 | - if (! empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam); |
|
| 641 | - else $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers); |
|
| 686 | + if (! empty($additionnalparam)) { |
|
| 687 | + $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam); |
|
| 688 | + } else { |
|
| 689 | + $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers); |
|
| 690 | + } |
|
| 642 | 691 | |
| 643 | 692 | if (! $res) |
| 644 | 693 | { |
| 645 | 694 | $langs->load("errors"); |
| 646 | 695 | $this->error="Failed to send mail with php mail"; |
| 647 | 696 | $linuxlike=1; |
| 648 | - if (preg_match('/^win/i',PHP_OS)) $linuxlike=0; |
|
| 649 | - if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0; |
|
| 697 | + if (preg_match('/^win/i',PHP_OS)) { |
|
| 698 | + $linuxlike=0; |
|
| 699 | + } |
|
| 700 | + if (preg_match('/^mac/i',PHP_OS)) { |
|
| 701 | + $linuxlike=0; |
|
| 702 | + } |
|
| 650 | 703 | if (! $linuxlike) |
| 651 | 704 | { |
| 652 | 705 | $this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'); // This values are value used only for non linuxlike systems |
@@ -654,8 +707,7 @@ discard block |
||
| 654 | 707 | $this->error.=".<br>"; |
| 655 | 708 | $this->error.=$langs->trans("ErrorPhpMailDelivery"); |
| 656 | 709 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 657 | - } |
|
| 658 | - else |
|
| 710 | + } else |
|
| 659 | 711 | { |
| 660 | 712 | dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); |
| 661 | 713 | } |
@@ -667,10 +719,13 @@ discard block |
||
| 667 | 719 | } |
| 668 | 720 | |
| 669 | 721 | // Restore parameters |
| 670 | - if (! empty($conf->global->$keyforsmtpserver)) ini_restore('SMTP'); |
|
| 671 | - if (! empty($conf->global->$keyforsmtpport)) ini_restore('smtp_port'); |
|
| 672 | - } |
|
| 673 | - else if ($this->sendmode == 'smtps') |
|
| 722 | + if (! empty($conf->global->$keyforsmtpserver)) { |
|
| 723 | + ini_restore('SMTP'); |
|
| 724 | + } |
|
| 725 | + if (! empty($conf->global->$keyforsmtpport)) { |
|
| 726 | + ini_restore('smtp_port'); |
|
| 727 | + } |
|
| 728 | + } else if ($this->sendmode == 'smtps') |
|
| 674 | 729 | { |
| 675 | 730 | if (! is_object($this->smtps)) |
| 676 | 731 | { |
@@ -684,14 +739,22 @@ discard block |
||
| 684 | 739 | $this->smtps->setTransportType(0); // Only this method is coded in SMTPs library |
| 685 | 740 | |
| 686 | 741 | // Clean parameters |
| 687 | - if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 688 | - if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 742 | + if (empty($conf->global->$keyforsmtpserver)) { |
|
| 743 | + $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 744 | + } |
|
| 745 | + if (empty($conf->global->$keyforsmtpport)) { |
|
| 746 | + $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 747 | + } |
|
| 689 | 748 | |
| 690 | 749 | // If we use SSL/TLS |
| 691 | 750 | $server=$conf->global->$keyforsmtpserver; |
| 692 | 751 | $secure=''; |
| 693 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl'; |
|
| 694 | - if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls'; |
|
| 752 | + if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) { |
|
| 753 | + $secure='ssl'; |
|
| 754 | + } |
|
| 755 | + if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) { |
|
| 756 | + $secure='tls'; |
|
| 757 | + } |
|
| 695 | 758 | $server=($secure?$secure.'://':'').$server; |
| 696 | 759 | |
| 697 | 760 | $port=$conf->global->$keyforsmtpport; |
@@ -729,47 +792,63 @@ discard block |
||
| 729 | 792 | |
| 730 | 793 | if ($res) |
| 731 | 794 | { |
| 732 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true); |
|
| 795 | + if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 796 | + $this->smtps->setDebug(true); |
|
| 797 | + } |
|
| 733 | 798 | |
| 734 | 799 | $result=$this->smtps->sendMsg(); |
| 735 | 800 | //print $result; |
| 736 | 801 | |
| 737 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 802 | + if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 803 | + $this->dump_mail(); |
|
| 804 | + } |
|
| 738 | 805 | |
| 739 | 806 | $result=$this->smtps->getErrors(); |
| 740 | 807 | if (empty($this->error) && empty($result)) |
| 741 | 808 | { |
| 742 | 809 | dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); |
| 743 | 810 | $res=true; |
| 744 | - } |
|
| 745 | - else |
|
| 811 | + } else |
|
| 746 | 812 | { |
| 747 | - if (empty($this->error)) $this->error=$result; |
|
| 813 | + if (empty($this->error)) { |
|
| 814 | + $this->error=$result; |
|
| 815 | + } |
|
| 748 | 816 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 749 | 817 | $res=false; |
| 750 | 818 | } |
| 751 | 819 | } |
| 752 | - } |
|
| 753 | - else if ($this->sendmode == 'swiftmailer') |
|
| 820 | + } else if ($this->sendmode == 'swiftmailer') |
|
| 754 | 821 | { |
| 755 | 822 | // Use Swift Mailer library |
| 756 | 823 | // ------------------------------------------ |
| 757 | 824 | require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php'; |
| 758 | 825 | |
| 759 | 826 | // Clean parameters |
| 760 | - if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 761 | - if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 827 | + if (empty($conf->global->$keyforsmtpserver)) { |
|
| 828 | + $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 829 | + } |
|
| 830 | + if (empty($conf->global->$keyforsmtpport)) { |
|
| 831 | + $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 832 | + } |
|
| 762 | 833 | |
| 763 | 834 | // If we use SSL/TLS |
| 764 | 835 | $server = $conf->global->$keyforsmtpserver; |
| 765 | 836 | $secure = ''; |
| 766 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl'; |
|
| 767 | - if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls'; |
|
| 837 | + if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) { |
|
| 838 | + $secure='ssl'; |
|
| 839 | + } |
|
| 840 | + if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) { |
|
| 841 | + $secure='tls'; |
|
| 842 | + } |
|
| 768 | 843 | |
| 769 | 844 | $this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure); |
| 770 | 845 | |
| 771 | - if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid); |
|
| 772 | - if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw); |
|
| 846 | + if (! empty($conf->global->$keyforsmtpid)) { |
|
| 847 | + $this->transport->setUsername($conf->global->$keyforsmtpid); |
|
| 848 | + } |
|
| 849 | + if (! empty($conf->global->$keyforsmtppw)) { |
|
| 850 | + $this->transport->setPassword($conf->global->$keyforsmtppw); |
|
| 851 | + } |
|
| 773 | 852 | //$smtps->_msgReplyTo = '[email protected]'; |
| 774 | 853 | |
| 775 | 854 | // Create the Mailer using your created Transport |
@@ -797,19 +876,19 @@ discard block |
||
| 797 | 876 | } catch (Exception $e) { |
| 798 | 877 | $this->error = $e->getMessage(); |
| 799 | 878 | } |
| 800 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 879 | + if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 880 | + $this->dump_mail(); |
|
| 881 | + } |
|
| 801 | 882 | |
| 802 | 883 | $res = true; |
| 803 | 884 | if (! empty($this->error) || ! $result) { |
| 804 | 885 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 805 | 886 | $res=false; |
| 806 | - } |
|
| 807 | - else |
|
| 887 | + } else |
|
| 808 | 888 | { |
| 809 | 889 | dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); |
| 810 | 890 | } |
| 811 | - } |
|
| 812 | - else |
|
| 891 | + } else |
|
| 813 | 892 | { |
| 814 | 893 | // Send mail method not correctly defined |
| 815 | 894 | // -------------------------------------- |
@@ -826,8 +905,7 @@ discard block |
||
| 826 | 905 | |
| 827 | 906 | return $reshook; |
| 828 | 907 | } |
| 829 | - } |
|
| 830 | - else |
|
| 908 | + } else |
|
| 831 | 909 | { |
| 832 | 910 | $this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; |
| 833 | 911 | dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING); |
@@ -867,8 +945,7 @@ discard block |
||
| 867 | 945 | $contents = file_get_contents($newsourcefile); // Need PHP 4.3 |
| 868 | 946 | $encoded = chunk_split(base64_encode($contents), 76, $this->eol); // 76 max is defined into http://tools.ietf.org/html/rfc2047 |
| 869 | 947 | return $encoded; |
| 870 | - } |
|
| 871 | - else |
|
| 948 | + } else |
|
| 872 | 949 | { |
| 873 | 950 | $this->error="Error: Can't read file '".$sourcefile."' into _encode_file"; |
| 874 | 951 | dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR); |
@@ -890,9 +967,11 @@ discard block |
||
| 890 | 967 | // phpcs:enable |
| 891 | 968 | global $conf,$dolibarr_main_data_root; |
| 892 | 969 | |
| 893 | - if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir |
|
| 970 | + if (@is_writeable($dolibarr_main_data_root)) { |
|
| 971 | + // Avoid fatal error on fopen with open_basedir |
|
| 894 | 972 | { |
| 895 | 973 | $outputfile=$dolibarr_main_data_root."/dolibarr_mail.log"; |
| 974 | + } |
|
| 896 | 975 | $fp = fopen($outputfile,"w"); |
| 897 | 976 | |
| 898 | 977 | if ($this->sendmode == 'mail') |
@@ -900,19 +979,18 @@ discard block |
||
| 900 | 979 | fputs($fp, $this->headers); |
| 901 | 980 | fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log |
| 902 | 981 | fputs($fp, $this->message); |
| 903 | - } |
|
| 904 | - elseif ($this->sendmode == 'smtps') |
|
| 982 | + } elseif ($this->sendmode == 'smtps') |
|
| 905 | 983 | { |
| 906 | 984 | fputs($fp, $this->smtps->log); // this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on |
| 907 | - } |
|
| 908 | - elseif ($this->sendmode == 'swiftmailer') |
|
| 985 | + } elseif ($this->sendmode == 'swiftmailer') |
|
| 909 | 986 | { |
| 910 | 987 | fputs($fp, $this->logger->dump()); // this->logger is filled only if MAIN_MAIL_DEBUG was set to on |
| 911 | 988 | } |
| 912 | 989 | |
| 913 | 990 | fclose($fp); |
| 914 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 915 | - @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 991 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 992 | + @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 993 | + } |
|
| 916 | 994 | } |
| 917 | 995 | } |
| 918 | 996 | |
@@ -928,14 +1006,17 @@ discard block |
||
| 928 | 1006 | if (!preg_match('/^[\s\t]*<html/i',$msg)) |
| 929 | 1007 | { |
| 930 | 1008 | $out = "<html><head><title></title>"; |
| 931 | - if (!empty($this->styleCSS)) $out.= $this->styleCSS; |
|
| 1009 | + if (!empty($this->styleCSS)) { |
|
| 1010 | + $out.= $this->styleCSS; |
|
| 1011 | + } |
|
| 932 | 1012 | $out.= "</head><body"; |
| 933 | - if (!empty($this->bodyCSS)) $out.= $this->bodyCSS; |
|
| 1013 | + if (!empty($this->bodyCSS)) { |
|
| 1014 | + $out.= $this->bodyCSS; |
|
| 1015 | + } |
|
| 934 | 1016 | $out.= ">"; |
| 935 | 1017 | $out.= $msg; |
| 936 | 1018 | $out.= "</body></html>"; |
| 937 | - } |
|
| 938 | - else |
|
| 1019 | + } else |
|
| 939 | 1020 | { |
| 940 | 1021 | $out = $msg; |
| 941 | 1022 | } |
@@ -995,15 +1076,26 @@ discard block |
||
| 995 | 1076 | } |
| 996 | 1077 | // Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that. |
| 997 | 1078 | $out.= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol2; |
| 998 | - if (isset($this->reply_to) && $this->reply_to) $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2; |
|
| 999 | - if (isset($this->errors_to) && $this->errors_to) $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2; |
|
| 1079 | + if (isset($this->reply_to) && $this->reply_to) { |
|
| 1080 | + $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2; |
|
| 1081 | + } |
|
| 1082 | + if (isset($this->errors_to) && $this->errors_to) { |
|
| 1083 | + $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2; |
|
| 1084 | + } |
|
| 1000 | 1085 | |
| 1001 | 1086 | // Receiver |
| 1002 | - if (isset($this->addr_cc) && $this->addr_cc) $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2; |
|
| 1003 | - if (isset($this->addr_bcc) && $this->addr_bcc) $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2; // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ? |
|
| 1087 | + if (isset($this->addr_cc) && $this->addr_cc) { |
|
| 1088 | + $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2; |
|
| 1089 | + } |
|
| 1090 | + if (isset($this->addr_bcc) && $this->addr_bcc) { |
|
| 1091 | + $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2; |
|
| 1092 | + } |
|
| 1093 | + // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ? |
|
| 1004 | 1094 | |
| 1005 | 1095 | // Delivery receipt |
| 1006 | - if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2; |
|
| 1096 | + if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) { |
|
| 1097 | + $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2; |
|
| 1098 | + } |
|
| 1007 | 1099 | |
| 1008 | 1100 | //$out.= "X-Priority: 3".$this->eol2; |
| 1009 | 1101 | |
@@ -1016,13 +1108,14 @@ discard block |
||
| 1016 | 1108 | $out.= 'Message-ID: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2; // Uppercase seems replaced by phpmail |
| 1017 | 1109 | $out.= 'References: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2; |
| 1018 | 1110 | $out.= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host. $this->eol2; |
| 1019 | - } |
|
| 1020 | - else |
|
| 1111 | + } else |
|
| 1021 | 1112 | { |
| 1022 | 1113 | $out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2; |
| 1023 | 1114 | } |
| 1024 | 1115 | |
| 1025 | - if (! empty($_SERVER['REMOTE_ADDR'])) $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2; |
|
| 1116 | + if (! empty($_SERVER['REMOTE_ADDR'])) { |
|
| 1117 | + $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2; |
|
| 1118 | + } |
|
| 1026 | 1119 | $out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2; |
| 1027 | 1120 | $out.= "Mime-Version: 1.0".$this->eol2; |
| 1028 | 1121 | |
@@ -1057,7 +1150,9 @@ discard block |
||
| 1057 | 1150 | { |
| 1058 | 1151 | if ($filename_list[$i]) |
| 1059 | 1152 | { |
| 1060 | - if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; |
|
| 1153 | + if ($mimefilename_list[$i]) { |
|
| 1154 | + $filename_list[$i] = $mimefilename_list[$i]; |
|
| 1155 | + } |
|
| 1061 | 1156 | $out.= "X-attachments: $filename_list[$i]".$this->eol2; |
| 1062 | 1157 | } |
| 1063 | 1158 | } |
@@ -1127,9 +1222,11 @@ discard block |
||
| 1127 | 1222 | $out.= "--" . $this->related_boundary . $this->eol; |
| 1128 | 1223 | } |
| 1129 | 1224 | |
| 1130 | - if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
| 1225 | + if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { |
|
| 1226 | + // Add plain text message part before html part |
|
| 1131 | 1227 | { |
| 1132 | 1228 | $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
| 1229 | + } |
|
| 1133 | 1230 | $out.= $this->eol; |
| 1134 | 1231 | $out.= "--" . $this->alternative_boundary . $this->eol; |
| 1135 | 1232 | $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
@@ -1142,12 +1239,13 @@ discard block |
||
| 1142 | 1239 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; // TODO Use base64 |
| 1143 | 1240 | $out.= $this->eol.$strContent.$this->eol; |
| 1144 | 1241 | |
| 1145 | - if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
| 1242 | + if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { |
|
| 1243 | + // Add plain text message part after html part |
|
| 1146 | 1244 | { |
| 1147 | 1245 | $out.= "--" . $this->alternative_boundary . "--". $this->eol; |
| 1148 | 1246 | } |
| 1149 | - } |
|
| 1150 | - else |
|
| 1247 | + } |
|
| 1248 | + } else |
|
| 1151 | 1249 | { |
| 1152 | 1250 | $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
| 1153 | 1251 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; |
@@ -1192,7 +1290,9 @@ discard block |
||
| 1192 | 1290 | $encoded = $this->_encode_file($filename_list[$i]); |
| 1193 | 1291 | if ($encoded >= 0) |
| 1194 | 1292 | { |
| 1195 | - if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; |
|
| 1293 | + if ($mimefilename_list[$i]) { |
|
| 1294 | + $filename_list[$i] = $mimefilename_list[$i]; |
|
| 1295 | + } |
|
| 1196 | 1296 | if (! $mimetype_list[$i]) { |
| 1197 | 1297 | $mimetype_list[$i] = "application/octet-stream"; |
| 1198 | 1298 | } |
@@ -1206,8 +1306,7 @@ discard block |
||
| 1206 | 1306 | $out.= $encoded; |
| 1207 | 1307 | $out.= $this->eol; |
| 1208 | 1308 | //$out.= $this->eol; |
| 1209 | - } |
|
| 1210 | - else |
|
| 1309 | + } else |
|
| 1211 | 1310 | { |
| 1212 | 1311 | return $encoded; |
| 1213 | 1312 | } |
@@ -1286,7 +1385,9 @@ discard block |
||
| 1286 | 1385 | } |
| 1287 | 1386 | |
| 1288 | 1387 | // If we use SSL/TLS |
| 1289 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host='ssl://'.$host; |
|
| 1388 | + if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) { |
|
| 1389 | + $host='ssl://'.$host; |
|
| 1390 | + } |
|
| 1290 | 1391 | // tls smtp start with no encryption |
| 1291 | 1392 | //if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host; |
| 1292 | 1393 | |
@@ -1298,17 +1399,20 @@ discard block |
||
| 1298 | 1399 | $errno, // actual system level error |
| 1299 | 1400 | $errstr, // and any text that goes with the error |
| 1300 | 1401 | $timeout |
| 1301 | - )) // timeout for reading/writing data over the socket |
|
| 1402 | + )) { |
|
| 1403 | + // timeout for reading/writing data over the socket |
|
| 1302 | 1404 | { |
| 1303 | 1405 | // Windows still does not have support for this timeout function |
| 1304 | 1406 | if (function_exists('stream_set_timeout')) stream_set_timeout($socket, $timeout, 0); |
| 1407 | + } |
|
| 1305 | 1408 | |
| 1306 | 1409 | dol_syslog("Now we wait for answer 220"); |
| 1307 | 1410 | |
| 1308 | 1411 | // Check response from Server |
| 1309 | - if ( $_retVal = $this->server_parse($socket, "220") ) $_retVal = $socket; |
|
| 1310 | - } |
|
| 1311 | - else |
|
| 1412 | + if ( $_retVal = $this->server_parse($socket, "220") ) { |
|
| 1413 | + $_retVal = $socket; |
|
| 1414 | + } |
|
| 1415 | + } else |
|
| 1312 | 1416 | { |
| 1313 | 1417 | $this->error = utf8_check('Error '.$errno.' - '.$errstr)?'Error '.$errno.' - '.$errstr:utf8_encode('Error '.$errno.' - '.$errstr); |
| 1314 | 1418 | } |
@@ -1369,9 +1473,11 @@ discard block |
||
| 1369 | 1473 | foreach ($matches[1] as $full) |
| 1370 | 1474 | { |
| 1371 | 1475 | |
| 1372 | - if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs)) // If xxx is 'file=aaa' |
|
| 1476 | + if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs)) { |
|
| 1477 | + // If xxx is 'file=aaa' |
|
| 1373 | 1478 | { |
| 1374 | 1479 | $img = $regs[1]; |
| 1480 | + } |
|
| 1375 | 1481 | |
| 1376 | 1482 | if (file_exists($images_dir.'/'.$img)) |
| 1377 | 1483 | { |
@@ -1430,15 +1536,13 @@ discard block |
||
| 1430 | 1536 | } |
| 1431 | 1537 | $i++; |
| 1432 | 1538 | } |
| 1433 | - } |
|
| 1434 | - else |
|
| 1539 | + } else |
|
| 1435 | 1540 | { |
| 1436 | 1541 | return -1; |
| 1437 | 1542 | } |
| 1438 | 1543 | |
| 1439 | 1544 | return 1; |
| 1440 | - } |
|
| 1441 | - else |
|
| 1545 | + } else |
|
| 1442 | 1546 | { |
| 1443 | 1547 | return 0; |
| 1444 | 1548 | } |
@@ -1473,8 +1577,7 @@ discard block |
||
| 1473 | 1577 | { |
| 1474 | 1578 | $name = trim($regs[1]); |
| 1475 | 1579 | $email = trim($regs[2]); |
| 1476 | - } |
|
| 1477 | - else |
|
| 1580 | + } else |
|
| 1478 | 1581 | { |
| 1479 | 1582 | $name = ''; |
| 1480 | 1583 | $email = trim($val); |
@@ -1499,9 +1602,13 @@ discard block |
||
| 1499 | 1602 | } |
| 1500 | 1603 | if ($format == 0 || $format == 3) |
| 1501 | 1604 | { |
| 1502 | - if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail='<'.$email.'>'; |
|
| 1503 | - elseif (! $name) $newemail='<'.$email.'>'; |
|
| 1504 | - else $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>'; |
|
| 1605 | + if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) { |
|
| 1606 | + $newemail='<'.$email.'>'; |
|
| 1607 | + } elseif (! $name) { |
|
| 1608 | + $newemail='<'.$email.'>'; |
|
| 1609 | + } else { |
|
| 1610 | + $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>'; |
|
| 1611 | + } |
|
| 1505 | 1612 | } |
| 1506 | 1613 | |
| 1507 | 1614 | $ret=($ret ? $ret.',' : '').$newemail; |
@@ -1509,7 +1616,9 @@ discard block |
||
| 1509 | 1616 | // Stop if we have too much records |
| 1510 | 1617 | if ($maxnumberofemail && $i >= $maxnumberofemail) |
| 1511 | 1618 | { |
| 1512 | - if (count($arrayaddress) > $maxnumberofemail) $ret.='...'; |
|
| 1619 | + if (count($arrayaddress) > $maxnumberofemail) { |
|
| 1620 | + $ret.='...'; |
|
| 1621 | + } |
|
| 1513 | 1622 | break; |
| 1514 | 1623 | } |
| 1515 | 1624 | } |
@@ -1539,8 +1648,7 @@ discard block |
||
| 1539 | 1648 | { |
| 1540 | 1649 | $name = trim($regs[1]); |
| 1541 | 1650 | $email = trim($regs[2]); |
| 1542 | - } |
|
| 1543 | - else |
|
| 1651 | + } else |
|
| 1544 | 1652 | { |
| 1545 | 1653 | $name = null; |
| 1546 | 1654 | $email = trim($val); |