@@ -37,7 +37,7 @@ |
||
| 37 | 37 | /** |
| 38 | 38 | * @var string Error code (or message) |
| 39 | 39 | */ |
| 40 | - public $error=''; |
|
| 40 | + public $error = ''; |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | /** |
| 34 | 34 | * @var string Error code (or message) |
| 35 | 35 | */ |
| 36 | - public $error=''; |
|
| 36 | + public $error = ''; |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * @var string[] Error codes (or messages) |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | function __construct($db) |
| 59 | 59 | { |
| 60 | - $this->db=$db; |
|
| 60 | + $this->db = $db; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -82,17 +82,17 @@ discard block |
||
| 82 | 82 | return -97; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - $fullcommand=$this->getCliCommand($file); |
|
| 85 | + $fullcommand = $this->getCliCommand($file); |
|
| 86 | 86 | //$fullcommand='"c:\Program Files (x86)\ClamWin\bin\clamscan.exe" --database="C:\Program Files (x86)\ClamWin\lib" "c:\temp\aaa.txt"'; |
| 87 | - $fullcommand.=' 2>&1'; // This is to get error output |
|
| 87 | + $fullcommand .= ' 2>&1'; // This is to get error output |
|
| 88 | 88 | |
| 89 | - $output=array(); |
|
| 90 | - $return_var=0; |
|
| 91 | - $safemode=ini_get("safe_mode"); |
|
| 89 | + $output = array(); |
|
| 90 | + $return_var = 0; |
|
| 91 | + $safemode = ini_get("safe_mode"); |
|
| 92 | 92 | // Create a clean fullcommand |
| 93 | - dol_syslog("AntiVir::dol_avscan_file Run command=".$fullcommand." with safe_mode ".($safemode?"on":"off")); |
|
| 93 | + dol_syslog("AntiVir::dol_avscan_file Run command=".$fullcommand." with safe_mode ".($safemode ? "on" : "off")); |
|
| 94 | 94 | // Run CLI command. If run of Windows, you can get return with echo %ERRORLEVEL% |
| 95 | - $lastline=exec($fullcommand, $output, $return_var); |
|
| 95 | + $lastline = exec($fullcommand, $output, $return_var); |
|
| 96 | 96 | |
| 97 | 97 | //print "x".$lastline." - ".join(',',$output)." - ".$return_var."y";exit; |
| 98 | 98 | |
@@ -126,18 +126,18 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | */ |
| 128 | 128 | |
| 129 | - dol_syslog("AntiVir::dol_avscan_file Result return_var=".$return_var." output=".join(',',$output)); |
|
| 129 | + dol_syslog("AntiVir::dol_avscan_file Result return_var=".$return_var." output=".join(',', $output)); |
|
| 130 | 130 | |
| 131 | - $returncodevirus=1; |
|
| 131 | + $returncodevirus = 1; |
|
| 132 | 132 | if ($return_var == $returncodevirus) // Virus found |
| 133 | 133 | { |
| 134 | - $this->errors=$output; |
|
| 134 | + $this->errors = $output; |
|
| 135 | 135 | return -99; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if ($return_var > 0) // If other error |
| 139 | 139 | { |
| 140 | - $this->errors=$output; |
|
| 140 | + $this->errors = $output; |
|
| 141 | 141 | return -98; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -157,28 +157,28 @@ discard block |
||
| 157 | 157 | { |
| 158 | 158 | global $conf; |
| 159 | 159 | |
| 160 | - $maxreclevel = 5 ; // maximal recursion level |
|
| 161 | - $maxfiles = 1000; // maximal number of files to be scanned within archive |
|
| 162 | - $maxratio = 200; // maximal compression ratio |
|
| 163 | - $bz2archivememlim = 0; // limit memory usage for bzip2 (0/1) |
|
| 164 | - $maxfilesize = 10485760; // archived files larger than this value (in bytes) will not be scanned |
|
| 160 | + $maxreclevel = 5; // maximal recursion level |
|
| 161 | + $maxfiles = 1000; // maximal number of files to be scanned within archive |
|
| 162 | + $maxratio = 200; // maximal compression ratio |
|
| 163 | + $bz2archivememlim = 0; // limit memory usage for bzip2 (0/1) |
|
| 164 | + $maxfilesize = 10485760; // archived files larger than this value (in bytes) will not be scanned |
|
| 165 | 165 | |
| 166 | - $command=$conf->global->MAIN_ANTIVIRUS_COMMAND; |
|
| 167 | - $param=$conf->global->MAIN_ANTIVIRUS_PARAM; |
|
| 166 | + $command = $conf->global->MAIN_ANTIVIRUS_COMMAND; |
|
| 167 | + $param = $conf->global->MAIN_ANTIVIRUS_PARAM; |
|
| 168 | 168 | |
| 169 | - $param=preg_replace('/%maxreclevel/',$maxreclevel,$param); |
|
| 170 | - $param=preg_replace('/%maxfiles/',$maxfiles,$param); |
|
| 171 | - $param=preg_replace('/%maxratio/',$maxratio,$param); |
|
| 172 | - $param=preg_replace('/%bz2archivememlim/',$bz2archivememlim,$param); |
|
| 173 | - $param=preg_replace('/%maxfilesize/',$maxfilesize,$param); |
|
| 174 | - $param=preg_replace('/%file/',trim($file),$param); |
|
| 169 | + $param = preg_replace('/%maxreclevel/', $maxreclevel, $param); |
|
| 170 | + $param = preg_replace('/%maxfiles/', $maxfiles, $param); |
|
| 171 | + $param = preg_replace('/%maxratio/', $maxratio, $param); |
|
| 172 | + $param = preg_replace('/%bz2archivememlim/', $bz2archivememlim, $param); |
|
| 173 | + $param = preg_replace('/%maxfilesize/', $maxfilesize, $param); |
|
| 174 | + $param = preg_replace('/%file/', trim($file), $param); |
|
| 175 | 175 | |
| 176 | - if (! preg_match('/%file/',$conf->global->MAIN_ANTIVIRUS_PARAM)) |
|
| 177 | - $param=$param." ".escapeshellarg(trim($file)); |
|
| 176 | + if (!preg_match('/%file/', $conf->global->MAIN_ANTIVIRUS_PARAM)) |
|
| 177 | + $param = $param." ".escapeshellarg(trim($file)); |
|
| 178 | 178 | |
| 179 | - if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command. Using escapeshellcmd fails. |
|
| 179 | + if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // Use quotes on command. Using escapeshellcmd fails. |
|
| 180 | 180 | |
| 181 | - $ret=$command.' '.$param; |
|
| 181 | + $ret = $command.' '.$param; |
|
| 182 | 182 | //$ret=$command.' '.$param.' 2>&1'; |
| 183 | 183 | //print "xx".$ret."xx";exit; |
| 184 | 184 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * @var string[] Array of error strings |
| 62 | 62 | */ |
| 63 | - public $errors=array(); |
|
| 63 | + public $errors = array(); |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * @var string ID to identify managed object |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | /** |
| 76 | 76 | * @var int Name of subtable line |
| 77 | 77 | */ |
| 78 | - public $table_element_line=''; |
|
| 78 | + public $table_element_line = ''; |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * @var string Key value used to track if data is coming from import wizard |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | /** |
| 86 | 86 | * @var mixed Contains data to manage extrafields |
| 87 | 87 | */ |
| 88 | - public $array_options=array(); |
|
| 88 | + public $array_options = array(); |
|
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | /** |
| 115 | 115 | * @var array<string,mixed> Can be used to pass information when only object is provided to method |
| 116 | 116 | */ |
| 117 | - public $context=array(); |
|
| 117 | + public $context = array(); |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * @var string Contains canvas name if record is an alternative canvas record |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * @var mixed Contains comments |
| 375 | 375 | * @see fetchComments() |
| 376 | 376 | */ |
| 377 | - public $comments=array(); |
|
| 377 | + public $comments = array(); |
|
| 378 | 378 | |
| 379 | 379 | /** |
| 380 | 380 | * @var int |
@@ -400,9 +400,9 @@ discard block |
||
| 400 | 400 | public $civility_id; |
| 401 | 401 | |
| 402 | 402 | // Dates |
| 403 | - public $date_creation; // Date creation |
|
| 404 | - public $date_validation; // Date validation |
|
| 405 | - public $date_modification; // Date last change (tms field) |
|
| 403 | + public $date_creation; // Date creation |
|
| 404 | + public $date_validation; // Date validation |
|
| 405 | + public $date_modification; // Date last change (tms field) |
|
| 406 | 406 | |
| 407 | 407 | |
| 408 | 408 | |
@@ -418,29 +418,29 @@ discard block |
||
| 418 | 418 | * @param string $ref_ext Ref ext of object to check |
| 419 | 419 | * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
| 420 | 420 | */ |
| 421 | - static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
| 421 | + static function isExistingObject($element, $id, $ref = '', $ref_ext = '') |
|
| 422 | 422 | { |
| 423 | - global $db,$conf; |
|
| 423 | + global $db, $conf; |
|
| 424 | 424 | |
| 425 | 425 | $sql = "SELECT rowid, ref, ref_ext"; |
| 426 | - $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 427 | - $sql.= " WHERE entity IN (".getEntity($element).")" ; |
|
| 426 | + $sql .= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 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)."'"; |
|
| 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 | 432 | else { |
| 433 | - $error='ErrorWrongParameters'; |
|
| 433 | + $error = 'ErrorWrongParameters'; |
|
| 434 | 434 | dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
| 435 | 435 | return -1; |
| 436 | 436 | } |
| 437 | - if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
| 437 | + if ($ref || $ref_ext) $sql .= " AND entity = ".$conf->entity; |
|
| 438 | 438 | |
| 439 | 439 | dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
| 440 | 440 | $resql = $db->query($sql); |
| 441 | 441 | if ($resql) |
| 442 | 442 | { |
| 443 | - $num=$db->num_rows($resql); |
|
| 443 | + $num = $db->num_rows($resql); |
|
| 444 | 444 | if ($num > 0) return 1; |
| 445 | 445 | else return 0; |
| 446 | 446 | } |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | */ |
| 455 | 455 | function errorsToString() |
| 456 | 456 | { |
| 457 | - return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):''); |
|
| 457 | + return $this->error.(is_array($this->errors) ? (($this->error != '' ? ', ' : '').join(', ', $this->errors)) : ''); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -466,23 +466,23 @@ discard block |
||
| 466 | 466 | * @param int $maxlen Maximum length |
| 467 | 467 | * @return string String with full name |
| 468 | 468 | */ |
| 469 | - function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
| 469 | + function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0) |
|
| 470 | 470 | { |
| 471 | 471 | //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
| 472 | - $lastname=$this->lastname; |
|
| 473 | - $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:''))))); |
|
| 472 | + $lastname = $this->lastname; |
|
| 473 | + $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 : ''))))); |
|
| 475 | 475 | |
| 476 | - $ret=''; |
|
| 476 | + $ret = ''; |
|
| 477 | 477 | if ($option && $this->civility_id) |
| 478 | 478 | { |
| 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.' '; |
|
| 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.' '; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 483 | + $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 484 | 484 | |
| 485 | - return dol_trunc($ret,$maxlen); |
|
| 485 | + return dol_trunc($ret, $maxlen); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | /** |
@@ -493,24 +493,24 @@ discard block |
||
| 493 | 493 | * @param int $withregion 1=Add region into address string |
| 494 | 494 | * @return string Full address string |
| 495 | 495 | */ |
| 496 | - function getFullAddress($withcountry=0, $sep="\n", $withregion=0) |
|
| 496 | + function getFullAddress($withcountry = 0, $sep = "\n", $withregion = 0) |
|
| 497 | 497 | { |
| 498 | 498 | if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
| 499 | 499 | { |
| 500 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 501 | - $tmparray=getCountry($this->country_id,'all'); |
|
| 502 | - $this->country_code=$tmparray['code']; |
|
| 503 | - $this->country =$tmparray['label']; |
|
| 500 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
| 501 | + $tmparray = getCountry($this->country_id, 'all'); |
|
| 502 | + $this->country_code = $tmparray['code']; |
|
| 503 | + $this->country = $tmparray['label']; |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) |
| 507 | 507 | { |
| 508 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 509 | - $tmparray=getState($this->state_id,'all',0,1); |
|
| 510 | - $this->state_code =$tmparray['code']; |
|
| 511 | - $this->state =$tmparray['label']; |
|
| 512 | - $this->region_code =$tmparray['region_code']; |
|
| 513 | - $this->region =$tmparray['region']; |
|
| 508 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
| 509 | + $tmparray = getState($this->state_id, 'all', 0, 1); |
|
| 510 | + $this->state_code = $tmparray['code']; |
|
| 511 | + $this->state = $tmparray['label']; |
|
| 512 | + $this->region_code = $tmparray['region_code']; |
|
| 513 | + $this->region = $tmparray['region']; |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | return dol_format_address($this, $withcountry, $sep); |
@@ -528,108 +528,108 @@ discard block |
||
| 528 | 528 | { |
| 529 | 529 | global $conf, $langs; |
| 530 | 530 | |
| 531 | - $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
| 531 | + $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
| 532 | 532 | |
| 533 | - $contactid=0; |
|
| 534 | - $thirdpartyid=0; |
|
| 533 | + $contactid = 0; |
|
| 534 | + $thirdpartyid = 0; |
|
| 535 | 535 | if ($this->element == 'societe') |
| 536 | 536 | { |
| 537 | - $thirdpartyid=$this->id; |
|
| 537 | + $thirdpartyid = $this->id; |
|
| 538 | 538 | } |
| 539 | 539 | if ($this->element == 'contact') |
| 540 | 540 | { |
| 541 | - $contactid=$this->id; |
|
| 542 | - $thirdpartyid=$object->fk_soc; |
|
| 541 | + $contactid = $this->id; |
|
| 542 | + $thirdpartyid = $object->fk_soc; |
|
| 543 | 543 | } |
| 544 | 544 | if ($this->element == 'user') |
| 545 | 545 | { |
| 546 | - $contactid=$this->contact_id; |
|
| 547 | - $thirdpartyid=$object->fk_soc; |
|
| 546 | + $contactid = $this->contact_id; |
|
| 547 | + $thirdpartyid = $object->fk_soc; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - $out='<!-- BEGIN part to show address block -->'; |
|
| 550 | + $out = '<!-- BEGIN part to show address block -->'; |
|
| 551 | 551 | |
| 552 | - $outdone=0; |
|
| 553 | - $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
| 552 | + $outdone = 0; |
|
| 553 | + $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
| 554 | 554 | if ($coords) |
| 555 | 555 | { |
| 556 | - if (! empty($conf->use_javascript_ajax)) |
|
| 556 | + if (!empty($conf->use_javascript_ajax)) |
|
| 557 | 557 | { |
| 558 | - $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
| 558 | + $namecoords = $this->getFullName($langs, 1).'<br>'.$coords; |
|
| 559 | 559 | // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
| 560 | - $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">'; |
|
| 561 | - $out.=img_picto($langs->trans("Address"), 'object_address.png'); |
|
| 562 | - $out.='</a> '; |
|
| 560 | + $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">'; |
|
| 561 | + $out .= img_picto($langs->trans("Address"), 'object_address.png'); |
|
| 562 | + $out .= '</a> '; |
|
| 563 | 563 | } |
| 564 | - $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 564 | + $out .= dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 565 | 565 | $outdone++; |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - if (! in_array($this->country_code,$countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress |
|
| 568 | + if (!in_array($this->country_code, $countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress |
|
| 569 | 569 | && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) |
| 570 | 570 | { |
| 571 | 571 | if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) { |
| 572 | - $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
|
| 572 | + $out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state; |
|
| 573 | 573 | } |
| 574 | 574 | else { |
| 575 | - $out.=($outdone?' - ':'').$this->state; |
|
| 575 | + $out .= ($outdone ? ' - ' : '').$this->state; |
|
| 576 | 576 | } |
| 577 | 577 | $outdone++; |
| 578 | 578 | } |
| 579 | 579 | |
| 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>':''); |
|
| 581 | - if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
|
| 582 | - $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
| 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>' : ''); |
|
| 581 | + if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
|
| 582 | + $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++; |
|
| 583 | 583 | } |
| 584 | - if (! empty($this->phone_pro)) { |
|
| 585 | - $out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
| 584 | + if (!empty($this->phone_pro)) { |
|
| 585 | + $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++; |
|
| 586 | 586 | } |
| 587 | - if (! empty($this->phone_mobile)) { |
|
| 588 | - $out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
| 587 | + if (!empty($this->phone_mobile)) { |
|
| 588 | + $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); $outdone++; |
|
| 589 | 589 | } |
| 590 | - if (! empty($this->phone_perso)) { |
|
| 591 | - $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++; |
|
| 590 | + if (!empty($this->phone_perso)) { |
|
| 591 | + $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePerso")); $outdone++; |
|
| 592 | 592 | } |
| 593 | - if (! empty($this->office_phone)) { |
|
| 594 | - $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
| 593 | + if (!empty($this->office_phone)) { |
|
| 594 | + $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++; |
|
| 595 | 595 | } |
| 596 | - if (! empty($this->user_mobile)) { |
|
| 597 | - $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
| 596 | + if (!empty($this->user_mobile)) { |
|
| 597 | + $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); $outdone++; |
|
| 598 | 598 | } |
| 599 | - if (! empty($this->fax)) { |
|
| 600 | - $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
| 599 | + if (!empty($this->fax)) { |
|
| 600 | + $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); $outdone++; |
|
| 601 | 601 | } |
| 602 | - if (! empty($this->office_fax)) { |
|
| 603 | - $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
| 602 | + if (!empty($this->office_fax)) { |
|
| 603 | + $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); $outdone++; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | - $out.='<div style="clear: both;"></div>'; |
|
| 607 | - $outdone=0; |
|
| 608 | - if (! empty($this->email)) |
|
| 606 | + $out .= '<div style="clear: both;"></div>'; |
|
| 607 | + $outdone = 0; |
|
| 608 | + if (!empty($this->email)) |
|
| 609 | 609 | { |
| 610 | - $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); |
|
| 610 | + $out .= dol_print_email($this->email, $this->id, $object->id, 'AC_EMAIL', 0, 0, 1); |
|
| 611 | 611 | $outdone++; |
| 612 | 612 | } |
| 613 | - if (! empty($this->url)) |
|
| 613 | + if (!empty($this->url)) |
|
| 614 | 614 | { |
| 615 | - $out.=dol_print_url($this->url,'_goout',0,1); |
|
| 615 | + $out .= dol_print_url($this->url, '_goout', 0, 1); |
|
| 616 | 616 | $outdone++; |
| 617 | 617 | } |
| 618 | - $out.='<div style="clear: both;">'; |
|
| 619 | - if (! empty($conf->socialnetworks->enabled)) |
|
| 618 | + $out .= '<div style="clear: both;">'; |
|
| 619 | + if (!empty($conf->socialnetworks->enabled)) |
|
| 620 | 620 | { |
| 621 | - if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 621 | + if ($this->skype) $out .= dol_print_socialnetworks($this->skype, $this->id, $object->id, 'skype'); |
|
| 622 | 622 | $outdone++; |
| 623 | - if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 623 | + if ($this->jabberid) $out .= dol_print_socialnetworks($this->jabberid, $this->id, $object->id, 'jabber'); |
|
| 624 | 624 | $outdone++; |
| 625 | - if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 625 | + if ($this->twitter) $out .= dol_print_socialnetworks($this->twitter, $this->id, $object->id, 'twitter'); |
|
| 626 | 626 | $outdone++; |
| 627 | - if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 627 | + if ($this->facebook) $out .= dol_print_socialnetworks($this->facebook, $this->id, $object->id, 'facebook'); |
|
| 628 | 628 | $outdone++; |
| 629 | 629 | } |
| 630 | - $out.='</div>'; |
|
| 630 | + $out .= '</div>'; |
|
| 631 | 631 | |
| 632 | - $out.='<!-- END Part to show address block -->'; |
|
| 632 | + $out .= '<!-- END Part to show address block -->'; |
|
| 633 | 633 | |
| 634 | 634 | return $out; |
| 635 | 635 | } |
@@ -642,17 +642,17 @@ discard block |
||
| 642 | 642 | * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
| 643 | 643 | * @return string Link or empty string if there is no download link |
| 644 | 644 | */ |
| 645 | - function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
| 645 | + function getLastMainDocLink($modulepart, $initsharekey = 0, $relativelink = 0) |
|
| 646 | 646 | { |
| 647 | 647 | global $user, $dolibarr_main_url_root; |
| 648 | 648 | |
| 649 | 649 | if (empty($this->last_main_doc)) |
| 650 | 650 | { |
| 651 | - return ''; // No way to known which document name to use |
|
| 651 | + return ''; // No way to known which document name to use |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 655 | - $ecmfile=new EcmFiles($this->db); |
|
| 655 | + $ecmfile = new EcmFiles($this->db); |
|
| 656 | 656 | $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
| 657 | 657 | if ($result < 0) |
| 658 | 658 | { |
@@ -700,26 +700,26 @@ discard block |
||
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | // Define $urlwithroot |
| 703 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 704 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 703 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
| 704 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 705 | 705 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
| 706 | 706 | |
| 707 | - $forcedownload=0; |
|
| 707 | + $forcedownload = 0; |
|
| 708 | 708 | |
| 709 | - $paramlink=''; |
|
| 709 | + $paramlink = ''; |
|
| 710 | 710 | //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
| 711 | 711 | //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
| 712 | 712 | //$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'; |
|
| 713 | + if (!empty($ecmfile->share)) $paramlink .= ($paramlink ? '&' : '').'hashp='.$ecmfile->share; // Hash for public share |
|
| 714 | + if ($forcedownload) $paramlink .= ($paramlink ? '&' : '').'attachment=1'; |
|
| 715 | 715 | |
| 716 | 716 | if ($relativelink) |
| 717 | 717 | { |
| 718 | - $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
| 718 | + $linktoreturn = 'document.php'.($paramlink ? '?'.$paramlink : ''); |
|
| 719 | 719 | } |
| 720 | 720 | else |
| 721 | 721 | { |
| 722 | - $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
| 722 | + $linktoreturn = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : ''); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | // Here $ecmfile->share is defined |
@@ -737,10 +737,10 @@ discard block |
||
| 737 | 737 | * @param int $notrigger Disable all triggers |
| 738 | 738 | * @return int <0 if KO, >0 if OK |
| 739 | 739 | */ |
| 740 | - function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
| 740 | + function add_contact($fk_socpeople, $type_contact, $source = 'external', $notrigger = 0) |
|
| 741 | 741 | { |
| 742 | 742 | // phpcs:enable |
| 743 | - global $user,$langs; |
|
| 743 | + global $user, $langs; |
|
| 744 | 744 | |
| 745 | 745 | |
| 746 | 746 | dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
@@ -749,43 +749,43 @@ discard block |
||
| 749 | 749 | if ($fk_socpeople <= 0) |
| 750 | 750 | { |
| 751 | 751 | $langs->load("errors"); |
| 752 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","1"); |
|
| 753 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 752 | + $this->error = $langs->trans("ErrorWrongValueForParameterX", "1"); |
|
| 753 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
| 754 | 754 | return -1; |
| 755 | 755 | } |
| 756 | - if (! $type_contact) |
|
| 756 | + if (!$type_contact) |
|
| 757 | 757 | { |
| 758 | 758 | $langs->load("errors"); |
| 759 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","2"); |
|
| 760 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 759 | + $this->error = $langs->trans("ErrorWrongValueForParameterX", "2"); |
|
| 760 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
| 761 | 761 | return -2; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - $id_type_contact=0; |
|
| 764 | + $id_type_contact = 0; |
|
| 765 | 765 | if (is_numeric($type_contact)) |
| 766 | 766 | { |
| 767 | - $id_type_contact=$type_contact; |
|
| 767 | + $id_type_contact = $type_contact; |
|
| 768 | 768 | } |
| 769 | 769 | else |
| 770 | 770 | { |
| 771 | 771 | // We look for id type_contact |
| 772 | 772 | $sql = "SELECT tc.rowid"; |
| 773 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 774 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 775 | - $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 776 | - $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 773 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 774 | + $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 775 | + $sql .= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 776 | + $sql .= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 777 | 777 | //print $sql; |
| 778 | - $resql=$this->db->query($sql); |
|
| 778 | + $resql = $this->db->query($sql); |
|
| 779 | 779 | if ($resql) |
| 780 | 780 | { |
| 781 | 781 | $obj = $this->db->fetch_object($resql); |
| 782 | - if ($obj) $id_type_contact=$obj->rowid; |
|
| 782 | + if ($obj) $id_type_contact = $obj->rowid; |
|
| 783 | 783 | } |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | if ($id_type_contact == 0) |
| 787 | 787 | { |
| 788 | - $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 788 | + $this->error = 'CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 789 | 789 | dol_syslog("CODE_NOT_VALID_FOR_THIS_ELEMENT: Code type of contact '".$type_contact."' does not exists or is not active for element ".$this->element.", we can ignore it"); |
| 790 | 790 | return -3; |
| 791 | 791 | } |
@@ -793,35 +793,35 @@ discard block |
||
| 793 | 793 | $datecreate = dol_now(); |
| 794 | 794 | |
| 795 | 795 | // Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
| 796 | - $TListeContacts=$this->liste_contact(-1, $source); |
|
| 797 | - $already_added=false; |
|
| 798 | - if(!empty($TListeContacts)) { |
|
| 799 | - foreach($TListeContacts as $array_contact) { |
|
| 800 | - if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { |
|
| 801 | - $already_added=true; |
|
| 796 | + $TListeContacts = $this->liste_contact(-1, $source); |
|
| 797 | + $already_added = false; |
|
| 798 | + if (!empty($TListeContacts)) { |
|
| 799 | + foreach ($TListeContacts as $array_contact) { |
|
| 800 | + if ($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { |
|
| 801 | + $already_added = true; |
|
| 802 | 802 | break; |
| 803 | 803 | } |
| 804 | 804 | } |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | - if(!$already_added) { |
|
| 807 | + if (!$already_added) { |
|
| 808 | 808 | |
| 809 | 809 | $this->db->begin(); |
| 810 | 810 | |
| 811 | 811 | // Insert into database |
| 812 | 812 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
| 813 | - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 814 | - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; |
|
| 815 | - $sql.= "'".$this->db->idate($datecreate)."'"; |
|
| 816 | - $sql.= ", 4, ". $id_type_contact; |
|
| 817 | - $sql.= ")"; |
|
| 813 | + $sql .= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 814 | + $sql .= " VALUES (".$this->id.", ".$fk_socpeople." , "; |
|
| 815 | + $sql .= "'".$this->db->idate($datecreate)."'"; |
|
| 816 | + $sql .= ", 4, ".$id_type_contact; |
|
| 817 | + $sql .= ")"; |
|
| 818 | 818 | |
| 819 | - $resql=$this->db->query($sql); |
|
| 819 | + $resql = $this->db->query($sql); |
|
| 820 | 820 | if ($resql) |
| 821 | 821 | { |
| 822 | - if (! $notrigger) |
|
| 822 | + if (!$notrigger) |
|
| 823 | 823 | { |
| 824 | - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 824 | + $result = $this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 825 | 825 | if ($result < 0) |
| 826 | 826 | { |
| 827 | 827 | $this->db->rollback(); |
@@ -836,14 +836,14 @@ discard block |
||
| 836 | 836 | { |
| 837 | 837 | if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
| 838 | 838 | { |
| 839 | - $this->error=$this->db->errno(); |
|
| 839 | + $this->error = $this->db->errno(); |
|
| 840 | 840 | $this->db->rollback(); |
| 841 | 841 | echo 'err rollback'; |
| 842 | 842 | return -2; |
| 843 | 843 | } |
| 844 | 844 | else |
| 845 | 845 | { |
| 846 | - $this->error=$this->db->error(); |
|
| 846 | + $this->error = $this->db->error(); |
|
| 847 | 847 | $this->db->rollback(); |
| 848 | 848 | return -1; |
| 849 | 849 | } |
@@ -859,15 +859,15 @@ discard block |
||
| 859 | 859 | * @param string $source Nature of contact ('internal' or 'external') |
| 860 | 860 | * @return int >0 if OK, <0 if KO |
| 861 | 861 | */ |
| 862 | - function copy_linked_contact($objFrom, $source='internal') |
|
| 862 | + function copy_linked_contact($objFrom, $source = 'internal') |
|
| 863 | 863 | { |
| 864 | 864 | // phpcs:enable |
| 865 | 865 | $contacts = $objFrom->liste_contact(-1, $source); |
| 866 | - foreach($contacts as $contact) |
|
| 866 | + foreach ($contacts as $contact) |
|
| 867 | 867 | { |
| 868 | 868 | if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
| 869 | 869 | { |
| 870 | - $this->error=$this->db->lasterror(); |
|
| 870 | + $this->error = $this->db->lasterror(); |
|
| 871 | 871 | return -1; |
| 872 | 872 | } |
| 873 | 873 | } |
@@ -884,23 +884,23 @@ discard block |
||
| 884 | 884 | * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
| 885 | 885 | * @return int <0 if KO, >= 0 if OK |
| 886 | 886 | */ |
| 887 | - function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
| 887 | + function update_contact($rowid, $statut, $type_contact_id = 0, $fk_socpeople = 0) |
|
| 888 | 888 | { |
| 889 | 889 | // phpcs:enable |
| 890 | 890 | // Insert into database |
| 891 | 891 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
| 892 | - $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 ."'"; |
|
| 895 | - $sql.= " where rowid = ".$rowid; |
|
| 896 | - $resql=$this->db->query($sql); |
|
| 892 | + $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."'"; |
|
| 895 | + $sql .= " where rowid = ".$rowid; |
|
| 896 | + $resql = $this->db->query($sql); |
|
| 897 | 897 | if ($resql) |
| 898 | 898 | { |
| 899 | 899 | return 0; |
| 900 | 900 | } |
| 901 | 901 | else |
| 902 | 902 | { |
| 903 | - $this->error=$this->db->lasterror(); |
|
| 903 | + $this->error = $this->db->lasterror(); |
|
| 904 | 904 | return -1; |
| 905 | 905 | } |
| 906 | 906 | } |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | * @param int $notrigger Disable all triggers |
| 914 | 914 | * @return int >0 if OK, <0 if KO |
| 915 | 915 | */ |
| 916 | - function delete_contact($rowid, $notrigger=0) |
|
| 916 | + function delete_contact($rowid, $notrigger = 0) |
|
| 917 | 917 | { |
| 918 | 918 | // phpcs:enable |
| 919 | 919 | global $user; |
@@ -922,14 +922,14 @@ discard block |
||
| 922 | 922 | $this->db->begin(); |
| 923 | 923 | |
| 924 | 924 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
| 925 | - $sql.= " WHERE rowid =".$rowid; |
|
| 925 | + $sql .= " WHERE rowid =".$rowid; |
|
| 926 | 926 | |
| 927 | 927 | dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
| 928 | 928 | if ($this->db->query($sql)) |
| 929 | 929 | { |
| 930 | - if (! $notrigger) |
|
| 930 | + if (!$notrigger) |
|
| 931 | 931 | { |
| 932 | - $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 932 | + $result = $this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 933 | 933 | if ($result < 0) { $this->db->rollback(); return -1; } |
| 934 | 934 | } |
| 935 | 935 | |
@@ -938,7 +938,7 @@ discard block |
||
| 938 | 938 | } |
| 939 | 939 | else |
| 940 | 940 | { |
| 941 | - $this->error=$this->db->lasterror(); |
|
| 941 | + $this->error = $this->db->lasterror(); |
|
| 942 | 942 | $this->db->rollback(); |
| 943 | 943 | return -1; |
| 944 | 944 | } |
@@ -952,22 +952,22 @@ discard block |
||
| 952 | 952 | * @param string $code Type of contact (code or id) |
| 953 | 953 | * @return int >0 if OK, <0 if KO |
| 954 | 954 | */ |
| 955 | - function delete_linked_contact($source='',$code='') |
|
| 955 | + function delete_linked_contact($source = '', $code = '') |
|
| 956 | 956 | { |
| 957 | 957 | // phpcs:enable |
| 958 | 958 | $temp = array(); |
| 959 | - $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
| 959 | + $typeContact = $this->liste_type_contact($source, '', 0, 0, $code); |
|
| 960 | 960 | |
| 961 | - foreach($typeContact as $key => $value) |
|
| 961 | + foreach ($typeContact as $key => $value) |
|
| 962 | 962 | { |
| 963 | - array_push($temp,$key); |
|
| 963 | + array_push($temp, $key); |
|
| 964 | 964 | } |
| 965 | 965 | $listId = implode(",", $temp); |
| 966 | 966 | |
| 967 | 967 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
| 968 | - $sql.= " WHERE element_id = ".$this->id; |
|
| 968 | + $sql .= " WHERE element_id = ".$this->id; |
|
| 969 | 969 | if ($listId) |
| 970 | - $sql.= " AND fk_c_type_contact IN (".$listId.")"; |
|
| 970 | + $sql .= " AND fk_c_type_contact IN (".$listId.")"; |
|
| 971 | 971 | |
| 972 | 972 | dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
| 973 | 973 | if ($this->db->query($sql)) |
@@ -976,7 +976,7 @@ discard block |
||
| 976 | 976 | } |
| 977 | 977 | else |
| 978 | 978 | { |
| 979 | - $this->error=$this->db->lasterror(); |
|
| 979 | + $this->error = $this->db->lasterror(); |
|
| 980 | 980 | return -1; |
| 981 | 981 | } |
| 982 | 982 | } |
@@ -991,54 +991,54 @@ discard block |
||
| 991 | 991 | * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) |
| 992 | 992 | * @return array|int Array of contacts, -1 if error |
| 993 | 993 | */ |
| 994 | - function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
| 994 | + function liste_contact($statut = -1, $source = 'external', $list = 0, $code = '') |
|
| 995 | 995 | { |
| 996 | 996 | // phpcs:enable |
| 997 | 997 | global $langs; |
| 998 | 998 | |
| 999 | - $tab=array(); |
|
| 1000 | - |
|
| 1001 | - $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"; |
|
| 1004 | - $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 1005 | - $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 1006 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 1007 | - $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"; |
|
| 1010 | - $sql.= " WHERE ec.element_id =".$this->id; |
|
| 1011 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1012 | - $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'"; |
|
| 1016 | - $sql.= " AND tc.active=1"; |
|
| 1017 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 1018 | - $sql.=" ORDER BY t.lastname ASC"; |
|
| 999 | + $tab = array(); |
|
| 1000 | + |
|
| 1001 | + $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"; |
|
| 1004 | + $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 1005 | + $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 1006 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 1007 | + $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"; |
|
| 1010 | + $sql .= " WHERE ec.element_id =".$this->id; |
|
| 1011 | + $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1012 | + $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'"; |
|
| 1016 | + $sql .= " AND tc.active=1"; |
|
| 1017 | + if ($statut >= 0) $sql .= " AND ec.statut = '".$statut."'"; |
|
| 1018 | + $sql .= " ORDER BY t.lastname ASC"; |
|
| 1019 | 1019 | |
| 1020 | 1020 | dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
| 1021 | - $resql=$this->db->query($sql); |
|
| 1021 | + $resql = $this->db->query($sql); |
|
| 1022 | 1022 | if ($resql) |
| 1023 | 1023 | { |
| 1024 | - $num=$this->db->num_rows($resql); |
|
| 1025 | - $i=0; |
|
| 1024 | + $num = $this->db->num_rows($resql); |
|
| 1025 | + $i = 0; |
|
| 1026 | 1026 | while ($i < $num) |
| 1027 | 1027 | { |
| 1028 | 1028 | $obj = $this->db->fetch_object($resql); |
| 1029 | 1029 | |
| 1030 | - if (! $list) |
|
| 1030 | + if (!$list) |
|
| 1031 | 1031 | { |
| 1032 | - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 1033 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1034 | - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id, |
|
| 1035 | - 'nom'=>$obj->lastname, // For backward compatibility |
|
| 1032 | + $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 1033 | + $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1034 | + $tab[$i] = array('source'=>$obj->source, 'socid'=>$obj->socid, 'id'=>$obj->id, |
|
| 1035 | + 'nom'=>$obj->lastname, // For backward compatibility |
|
| 1036 | 1036 | 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
| 1037 | 1037 | 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
| 1038 | 1038 | } |
| 1039 | 1039 | else |
| 1040 | 1040 | { |
| 1041 | - $tab[$i]=$obj->id; |
|
| 1041 | + $tab[$i] = $obj->id; |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | $i++; |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | } |
| 1049 | 1049 | else |
| 1050 | 1050 | { |
| 1051 | - $this->error=$this->db->lasterror(); |
|
| 1051 | + $this->error = $this->db->lasterror(); |
|
| 1052 | 1052 | dol_print_error($this->db); |
| 1053 | 1053 | return -1; |
| 1054 | 1054 | } |
@@ -1064,16 +1064,16 @@ discard block |
||
| 1064 | 1064 | function swapContactStatus($rowid) |
| 1065 | 1065 | { |
| 1066 | 1066 | $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
| 1067 | - $sql.= " tc.code, tc.libelle"; |
|
| 1067 | + $sql .= " tc.code, tc.libelle"; |
|
| 1068 | 1068 | //$sql.= ", s.fk_soc"; |
| 1069 | - $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; |
|
| 1069 | + $sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; |
|
| 1070 | 1070 | //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.rowid"; // Si contact de type external, alors il est lie a une societe |
| 1071 | - $sql.= " WHERE ec.rowid =".$rowid; |
|
| 1072 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1073 | - $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 1071 | + $sql .= " WHERE ec.rowid =".$rowid; |
|
| 1072 | + $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1073 | + $sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 1074 | 1074 | |
| 1075 | 1075 | dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
| 1076 | - $resql=$this->db->query($sql); |
|
| 1076 | + $resql = $this->db->query($sql); |
|
| 1077 | 1077 | if ($resql) |
| 1078 | 1078 | { |
| 1079 | 1079 | $obj = $this->db->fetch_object($resql); |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | } |
| 1085 | 1085 | else |
| 1086 | 1086 | { |
| 1087 | - $this->error=$this->db->error(); |
|
| 1087 | + $this->error = $this->db->error(); |
|
| 1088 | 1088 | dol_print_error($this->db); |
| 1089 | 1089 | return -1; |
| 1090 | 1090 | } |
@@ -1101,44 +1101,44 @@ discard block |
||
| 1101 | 1101 | * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
| 1102 | 1102 | * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
| 1103 | 1103 | */ |
| 1104 | - function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
| 1104 | + function liste_type_contact($source = 'internal', $order = 'position', $option = 0, $activeonly = 0, $code = '') |
|
| 1105 | 1105 | { |
| 1106 | 1106 | // phpcs:enable |
| 1107 | 1107 | global $langs; |
| 1108 | 1108 | |
| 1109 | - if (empty($order)) $order='position'; |
|
| 1110 | - if ($order == 'position') $order.=',code'; |
|
| 1109 | + if (empty($order)) $order = 'position'; |
|
| 1110 | + if ($order == 'position') $order .= ',code'; |
|
| 1111 | 1111 | |
| 1112 | 1112 | $tab = array(); |
| 1113 | 1113 | $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
| 1114 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1115 | - $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)."'"; |
|
| 1119 | - $sql.= $this->db->order($order,'ASC'); |
|
| 1114 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1115 | + $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)."'"; |
|
| 1119 | + $sql .= $this->db->order($order, 'ASC'); |
|
| 1120 | 1120 | |
| 1121 | 1121 | //print "sql=".$sql; |
| 1122 | - $resql=$this->db->query($sql); |
|
| 1122 | + $resql = $this->db->query($sql); |
|
| 1123 | 1123 | if ($resql) |
| 1124 | 1124 | { |
| 1125 | - $num=$this->db->num_rows($resql); |
|
| 1126 | - $i=0; |
|
| 1125 | + $num = $this->db->num_rows($resql); |
|
| 1126 | + $i = 0; |
|
| 1127 | 1127 | while ($i < $num) |
| 1128 | 1128 | { |
| 1129 | 1129 | $obj = $this->db->fetch_object($resql); |
| 1130 | 1130 | |
| 1131 | - $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1132 | - $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; |
|
| 1131 | + $transkey = "TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1132 | + $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; |
|
| 1135 | 1135 | $i++; |
| 1136 | 1136 | } |
| 1137 | 1137 | return $tab; |
| 1138 | 1138 | } |
| 1139 | 1139 | else |
| 1140 | 1140 | { |
| 1141 | - $this->error=$this->db->lasterror(); |
|
| 1141 | + $this->error = $this->db->lasterror(); |
|
| 1142 | 1142 | //dol_print_error($this->db); |
| 1143 | 1143 | return null; |
| 1144 | 1144 | } |
@@ -1155,53 +1155,53 @@ discard block |
||
| 1155 | 1155 | * @param int $status limited to a certain status |
| 1156 | 1156 | * @return array List of id for such contacts |
| 1157 | 1157 | */ |
| 1158 | - function getIdContact($source,$code,$status=0) |
|
| 1158 | + function getIdContact($source, $code, $status = 0) |
|
| 1159 | 1159 | { |
| 1160 | 1160 | global $conf; |
| 1161 | 1161 | |
| 1162 | - $result=array(); |
|
| 1163 | - $i=0; |
|
| 1162 | + $result = array(); |
|
| 1163 | + $i = 0; |
|
| 1164 | 1164 | //cas particulier pour les expeditions |
| 1165 | - if($this->element=='shipping' && $this->origin_id != 0) { |
|
| 1166 | - $id=$this->origin_id; |
|
| 1167 | - $element='commande'; |
|
| 1168 | - } else if($this->element=='reception' && $this->origin_id != 0) { |
|
| 1169 | - $id=$this->origin_id; |
|
| 1170 | - $element='order_supplier'; |
|
| 1165 | + if ($this->element == 'shipping' && $this->origin_id != 0) { |
|
| 1166 | + $id = $this->origin_id; |
|
| 1167 | + $element = 'commande'; |
|
| 1168 | + } else if ($this->element == 'reception' && $this->origin_id != 0) { |
|
| 1169 | + $id = $this->origin_id; |
|
| 1170 | + $element = 'order_supplier'; |
|
| 1171 | 1171 | } else { |
| 1172 | - $id=$this->id; |
|
| 1173 | - $element=$this->element; |
|
| 1172 | + $id = $this->id; |
|
| 1173 | + $element = $this->element; |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | $sql = "SELECT ec.fk_socpeople"; |
| 1177 | - $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,"; |
|
| 1180 | - $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1181 | - $sql.= " WHERE ec.element_id = ".$id; |
|
| 1182 | - $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').")"; |
|
| 1185 | - $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1186 | - $sql.= " AND tc.element = '".$element."'"; |
|
| 1187 | - $sql.= " AND tc.source = '".$source."'"; |
|
| 1188 | - $sql.= " AND tc.code = '".$code."'"; |
|
| 1189 | - $sql.= " AND tc.active = 1"; |
|
| 1190 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1177 | + $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,"; |
|
| 1180 | + $sql .= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1181 | + $sql .= " WHERE ec.element_id = ".$id; |
|
| 1182 | + $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').")"; |
|
| 1185 | + $sql .= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1186 | + $sql .= " AND tc.element = '".$element."'"; |
|
| 1187 | + $sql .= " AND tc.source = '".$source."'"; |
|
| 1188 | + $sql .= " AND tc.code = '".$code."'"; |
|
| 1189 | + $sql .= " AND tc.active = 1"; |
|
| 1190 | + if ($status) $sql .= " AND ec.statut = ".$status; |
|
| 1191 | 1191 | |
| 1192 | 1192 | dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
| 1193 | - $resql=$this->db->query($sql); |
|
| 1193 | + $resql = $this->db->query($sql); |
|
| 1194 | 1194 | if ($resql) |
| 1195 | 1195 | { |
| 1196 | 1196 | while ($obj = $this->db->fetch_object($resql)) |
| 1197 | 1197 | { |
| 1198 | - $result[$i]=$obj->fk_socpeople; |
|
| 1198 | + $result[$i] = $obj->fk_socpeople; |
|
| 1199 | 1199 | $i++; |
| 1200 | 1200 | } |
| 1201 | 1201 | } |
| 1202 | 1202 | else |
| 1203 | 1203 | { |
| 1204 | - $this->error=$this->db->error(); |
|
| 1204 | + $this->error = $this->db->error(); |
|
| 1205 | 1205 | return null; |
| 1206 | 1206 | } |
| 1207 | 1207 | |
@@ -1215,16 +1215,16 @@ discard block |
||
| 1215 | 1215 | * @param int $contactid Id du contact. Use this->contactid if empty. |
| 1216 | 1216 | * @return int <0 if KO, >0 if OK |
| 1217 | 1217 | */ |
| 1218 | - function fetch_contact($contactid=null) |
|
| 1218 | + function fetch_contact($contactid = null) |
|
| 1219 | 1219 | { |
| 1220 | 1220 | // phpcs:enable |
| 1221 | - if (empty($contactid)) $contactid=$this->contactid; |
|
| 1221 | + if (empty($contactid)) $contactid = $this->contactid; |
|
| 1222 | 1222 | |
| 1223 | 1223 | if (empty($contactid)) return 0; |
| 1224 | 1224 | |
| 1225 | 1225 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
| 1226 | 1226 | $contact = new Contact($this->db); |
| 1227 | - $result=$contact->fetch($contactid); |
|
| 1227 | + $result = $contact->fetch($contactid); |
|
| 1228 | 1228 | $this->contact = $contact; |
| 1229 | 1229 | return $result; |
| 1230 | 1230 | } |
@@ -1236,7 +1236,7 @@ discard block |
||
| 1236 | 1236 | * @param int $force_thirdparty_id Force thirdparty id |
| 1237 | 1237 | * @return int <0 if KO, >0 if OK |
| 1238 | 1238 | */ |
| 1239 | - function fetch_thirdparty($force_thirdparty_id=0) |
|
| 1239 | + function fetch_thirdparty($force_thirdparty_id = 0) |
|
| 1240 | 1240 | { |
| 1241 | 1241 | // phpcs:enable |
| 1242 | 1242 | global $conf; |
@@ -1244,7 +1244,7 @@ discard block |
||
| 1244 | 1244 | if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
| 1245 | 1245 | return 0; |
| 1246 | 1246 | |
| 1247 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
| 1247 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
| 1248 | 1248 | |
| 1249 | 1249 | $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
| 1250 | 1250 | if ($force_thirdparty_id) |
@@ -1307,7 +1307,7 @@ discard block |
||
| 1307 | 1307 | |
| 1308 | 1308 | dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
| 1309 | 1309 | |
| 1310 | - $idtype=$this->barcode_type; |
|
| 1310 | + $idtype = $this->barcode_type; |
|
| 1311 | 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 |
| 1312 | 1312 | { |
| 1313 | 1313 | if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
@@ -1320,8 +1320,8 @@ discard block |
||
| 1320 | 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 |
| 1321 | 1321 | { |
| 1322 | 1322 | $sql = "SELECT rowid, code, libelle as label, coder"; |
| 1323 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1324 | - $sql.= " WHERE rowid = ".$idtype; |
|
| 1323 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1324 | + $sql .= " WHERE rowid = ".$idtype; |
|
| 1325 | 1325 | dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
| 1326 | 1326 | $resql = $this->db->query($sql); |
| 1327 | 1327 | if ($resql) |
@@ -1354,13 +1354,13 @@ discard block |
||
| 1354 | 1354 | // phpcs:enable |
| 1355 | 1355 | include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
| 1356 | 1356 | |
| 1357 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1357 | + if (empty($this->fk_project) && !empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1358 | 1358 | if (empty($this->fk_project)) return 0; |
| 1359 | 1359 | |
| 1360 | 1360 | $project = new Project($this->db); |
| 1361 | 1361 | $result = $project->fetch($this->fk_project); |
| 1362 | 1362 | |
| 1363 | - $this->projet = $project; // deprecated |
|
| 1363 | + $this->projet = $project; // deprecated |
|
| 1364 | 1364 | $this->project = $project; |
| 1365 | 1365 | return $result; |
| 1366 | 1366 | } |
@@ -1396,7 +1396,7 @@ discard block |
||
| 1396 | 1396 | { |
| 1397 | 1397 | // phpcs:enable |
| 1398 | 1398 | $user = new User($this->db); |
| 1399 | - $result=$user->fetch($userid); |
|
| 1399 | + $result = $user->fetch($userid); |
|
| 1400 | 1400 | $this->user = $user; |
| 1401 | 1401 | return $result; |
| 1402 | 1402 | } |
@@ -1434,14 +1434,14 @@ discard block |
||
| 1434 | 1434 | { |
| 1435 | 1435 | global $conf; |
| 1436 | 1436 | |
| 1437 | - $result=false; |
|
| 1437 | + $result = false; |
|
| 1438 | 1438 | |
| 1439 | 1439 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
| 1440 | - $sql.= " WHERE ".$field." = '".$key."'"; |
|
| 1441 | - if (! empty($element)) { |
|
| 1442 | - $sql.= " AND entity IN (".getEntity($element).")"; |
|
| 1440 | + $sql .= " WHERE ".$field." = '".$key."'"; |
|
| 1441 | + if (!empty($element)) { |
|
| 1442 | + $sql .= " AND entity IN (".getEntity($element).")"; |
|
| 1443 | 1443 | } else { |
| 1444 | - $sql.= " AND entity = ".$conf->entity; |
|
| 1444 | + $sql .= " AND entity = ".$conf->entity; |
|
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | 1447 | dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
@@ -1468,10 +1468,10 @@ discard block |
||
| 1468 | 1468 | */ |
| 1469 | 1469 | function getValueFrom($table, $id, $field) |
| 1470 | 1470 | { |
| 1471 | - $result=false; |
|
| 1471 | + $result = false; |
|
| 1472 | 1472 | if (!empty($id) && !empty($field) && !empty($table)) { |
| 1473 | 1473 | $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
| 1474 | - $sql.= " WHERE rowid = ".$id; |
|
| 1474 | + $sql .= " WHERE rowid = ".$id; |
|
| 1475 | 1475 | |
| 1476 | 1476 | dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
| 1477 | 1477 | $resql = $this->db->query($sql); |
@@ -1500,36 +1500,36 @@ discard block |
||
| 1500 | 1500 | * @return int <0 if KO, >0 if OK |
| 1501 | 1501 | * @see updateExtraField |
| 1502 | 1502 | */ |
| 1503 | - function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif') |
|
| 1503 | + function setValueFrom($field, $value, $table = '', $id = null, $format = '', $id_field = '', $fuser = null, $trigkey = '', $fk_user_field = 'fk_user_modif') |
|
| 1504 | 1504 | { |
| 1505 | - global $user,$langs,$conf; |
|
| 1505 | + global $user, $langs, $conf; |
|
| 1506 | 1506 | |
| 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'; |
|
| 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'; |
|
| 1511 | 1511 | |
| 1512 | - $error=0; |
|
| 1512 | + $error = 0; |
|
| 1513 | 1513 | |
| 1514 | 1514 | $this->db->begin(); |
| 1515 | 1515 | |
| 1516 | 1516 | // Special case |
| 1517 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1517 | + if ($table == 'product' && $field == 'note_private') $field = 'note'; |
|
| 1518 | 1518 | if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod'; |
| 1519 | 1519 | |
| 1520 | 1520 | $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
| 1521 | 1521 | |
| 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"); |
|
| 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"); |
|
| 1525 | 1525 | |
| 1526 | 1526 | if ($fk_user_field) |
| 1527 | 1527 | { |
| 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; |
|
| 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; |
|
| 1530 | 1530 | } |
| 1531 | 1531 | |
| 1532 | - $sql.= " WHERE ".$id_field." = ".$id; |
|
| 1532 | + $sql .= " WHERE ".$id_field." = ".$id; |
|
| 1533 | 1533 | |
| 1534 | 1534 | dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
| 1535 | 1535 | $resql = $this->db->query($sql); |
@@ -1546,11 +1546,11 @@ discard block |
||
| 1546 | 1546 | { |
| 1547 | 1547 | $result = $this->fetchCommon($id); |
| 1548 | 1548 | } |
| 1549 | - if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1549 | + if ($result >= 0) $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1550 | 1550 | if ($result < 0) $error++; |
| 1551 | 1551 | } |
| 1552 | 1552 | |
| 1553 | - if (! $error) |
|
| 1553 | + if (!$error) |
|
| 1554 | 1554 | { |
| 1555 | 1555 | if (property_exists($this, $field)) $this->$field = $value; |
| 1556 | 1556 | $this->db->commit(); |
@@ -1564,7 +1564,7 @@ discard block |
||
| 1564 | 1564 | } |
| 1565 | 1565 | else |
| 1566 | 1566 | { |
| 1567 | - $this->error=$this->db->lasterror(); |
|
| 1567 | + $this->error = $this->db->lasterror(); |
|
| 1568 | 1568 | $this->db->rollback(); |
| 1569 | 1569 | return -1; |
| 1570 | 1570 | } |
@@ -1579,14 +1579,14 @@ discard block |
||
| 1579 | 1579 | * @param int $nodbprefix Do not include DB prefix to forge table name |
| 1580 | 1580 | * @return int <0 if KO, >0 if OK |
| 1581 | 1581 | */ |
| 1582 | - function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
| 1582 | + function load_previous_next_ref($filter, $fieldid, $nodbprefix = 0) |
|
| 1583 | 1583 | { |
| 1584 | 1584 | // phpcs:enable |
| 1585 | 1585 | global $conf, $user; |
| 1586 | 1586 | |
| 1587 | - if (! $this->table_element) |
|
| 1587 | + if (!$this->table_element) |
|
| 1588 | 1588 | { |
| 1589 | - dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
|
| 1589 | + dol_print_error('', get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
|
| 1590 | 1590 | return -1; |
| 1591 | 1591 | } |
| 1592 | 1592 | if ($fieldid == 'none') return 1; |
@@ -1601,45 +1601,45 @@ discard block |
||
| 1601 | 1601 | if ($this->element == 'societe') $alias = 'te'; |
| 1602 | 1602 | |
| 1603 | 1603 | $sql = "SELECT MAX(te.".$fieldid.")"; |
| 1604 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1605 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
| 1606 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1607 | - } |
|
| 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"; |
|
| 1612 | - $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)'; |
|
| 1615 | - if (! empty($filter)) |
|
| 1616 | - { |
|
| 1617 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
| 1618 | - $sql.=$filter; |
|
| 1619 | - } |
|
| 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 |
|
| 1604 | + $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1605 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
| 1606 | + $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1607 | + } |
|
| 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"; |
|
| 1612 | + $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)'; |
|
| 1615 | + if (!empty($filter)) |
|
| 1616 | + { |
|
| 1617 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
| 1618 | + $sql .= $filter; |
|
| 1619 | + } |
|
| 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 |
|
| 1622 | 1622 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
| 1623 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
| 1624 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
| 1625 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1623 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
| 1624 | + if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
| 1625 | + $sql .= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1626 | 1626 | } else { |
| 1627 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1628 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")"; |
|
| 1627 | + $sql .= " AND ug.fk_user = te.rowid"; |
|
| 1628 | + $sql .= " AND ug.entity IN (".getEntity($this->element).")"; |
|
| 1629 | 1629 | } |
| 1630 | 1630 | } else { |
| 1631 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
| 1631 | + $sql .= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
| 1632 | 1632 | } |
| 1633 | 1633 | } |
| 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; |
|
| 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; |
|
| 1637 | 1637 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1638 | 1638 | |
| 1639 | 1639 | $result = $this->db->query($sql); |
| 1640 | - if (! $result) |
|
| 1640 | + if (!$result) |
|
| 1641 | 1641 | { |
| 1642 | - $this->error=$this->db->lasterror(); |
|
| 1642 | + $this->error = $this->db->lasterror(); |
|
| 1643 | 1643 | return -1; |
| 1644 | 1644 | } |
| 1645 | 1645 | $row = $this->db->fetch_row($result); |
@@ -1647,46 +1647,46 @@ discard block |
||
| 1647 | 1647 | |
| 1648 | 1648 | |
| 1649 | 1649 | $sql = "SELECT MIN(te.".$fieldid.")"; |
| 1650 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1651 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
| 1652 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1653 | - } |
|
| 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"; |
|
| 1658 | - $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)'; |
|
| 1661 | - if (! empty($filter)) |
|
| 1662 | - { |
|
| 1663 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
| 1664 | - $sql.=$filter; |
|
| 1665 | - } |
|
| 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 |
|
| 1650 | + $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1651 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
| 1652 | + $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1653 | + } |
|
| 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"; |
|
| 1658 | + $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)'; |
|
| 1661 | + if (!empty($filter)) |
|
| 1662 | + { |
|
| 1663 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
| 1664 | + $sql .= $filter; |
|
| 1665 | + } |
|
| 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 |
|
| 1668 | 1668 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
| 1669 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
| 1670 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
| 1671 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1669 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
| 1670 | + if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
| 1671 | + $sql .= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1672 | 1672 | } else { |
| 1673 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1674 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")"; |
|
| 1673 | + $sql .= " AND ug.fk_user = te.rowid"; |
|
| 1674 | + $sql .= " AND ug.entity IN (".getEntity($this->element).")"; |
|
| 1675 | 1675 | } |
| 1676 | 1676 | } else { |
| 1677 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
| 1677 | + $sql .= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
| 1678 | 1678 | } |
| 1679 | 1679 | } |
| 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; |
|
| 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; |
|
| 1683 | 1683 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1684 | 1684 | // 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 | 1685 | |
| 1686 | 1686 | $result = $this->db->query($sql); |
| 1687 | - if (! $result) |
|
| 1687 | + if (!$result) |
|
| 1688 | 1688 | { |
| 1689 | - $this->error=$this->db->lasterror(); |
|
| 1689 | + $this->error = $this->db->lasterror(); |
|
| 1690 | 1690 | return -2; |
| 1691 | 1691 | } |
| 1692 | 1692 | $row = $this->db->fetch_row($result); |
@@ -1703,11 +1703,11 @@ discard block |
||
| 1703 | 1703 | * @return array Array of id of contacts (if source=external or internal) |
| 1704 | 1704 | * Array of id of third parties with at least one contact on object (if source=thirdparty) |
| 1705 | 1705 | */ |
| 1706 | - function getListContactId($source='external') |
|
| 1706 | + function getListContactId($source = 'external') |
|
| 1707 | 1707 | { |
| 1708 | 1708 | $contactAlreadySelected = array(); |
| 1709 | - $tab = $this->liste_contact(-1,$source); |
|
| 1710 | - $num=count($tab); |
|
| 1709 | + $tab = $this->liste_contact(-1, $source); |
|
| 1710 | + $num = count($tab); |
|
| 1711 | 1711 | $i = 0; |
| 1712 | 1712 | while ($i < $num) |
| 1713 | 1713 | { |
@@ -1727,24 +1727,24 @@ discard block |
||
| 1727 | 1727 | */ |
| 1728 | 1728 | function setProject($projectid) |
| 1729 | 1729 | { |
| 1730 | - if (! $this->table_element) |
|
| 1730 | + if (!$this->table_element) |
|
| 1731 | 1731 | { |
| 1732 | - dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
| 1732 | + dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined", LOG_ERR); |
|
| 1733 | 1733 | return -1; |
| 1734 | 1734 | } |
| 1735 | 1735 | |
| 1736 | 1736 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1737 | 1737 | if ($this->table_element == 'actioncomm') |
| 1738 | 1738 | { |
| 1739 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1740 | - else $sql.= ' SET fk_project = NULL'; |
|
| 1741 | - $sql.= ' WHERE id = '.$this->id; |
|
| 1739 | + if ($projectid) $sql .= ' SET fk_project = '.$projectid; |
|
| 1740 | + else $sql .= ' SET fk_project = NULL'; |
|
| 1741 | + $sql .= ' WHERE id = '.$this->id; |
|
| 1742 | 1742 | } |
| 1743 | 1743 | else |
| 1744 | 1744 | { |
| 1745 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1746 | - else $sql.= ' SET fk_projet = NULL'; |
|
| 1747 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 1745 | + if ($projectid) $sql .= ' SET fk_projet = '.$projectid; |
|
| 1746 | + else $sql .= ' SET fk_projet = NULL'; |
|
| 1747 | + $sql .= ' WHERE rowid = '.$this->id; |
|
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | 1750 | dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
@@ -1790,14 +1790,14 @@ discard block |
||
| 1790 | 1790 | else |
| 1791 | 1791 | { |
| 1792 | 1792 | dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
| 1793 | - $this->error=$this->db->error(); |
|
| 1793 | + $this->error = $this->db->error(); |
|
| 1794 | 1794 | return -1; |
| 1795 | 1795 | } |
| 1796 | 1796 | } |
| 1797 | 1797 | else |
| 1798 | 1798 | { |
| 1799 | 1799 | dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
| 1800 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1800 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1801 | 1801 | return -2; |
| 1802 | 1802 | } |
| 1803 | 1803 | } |
@@ -1824,21 +1824,21 @@ discard block |
||
| 1824 | 1824 | $this->multicurrency_code = $code; |
| 1825 | 1825 | |
| 1826 | 1826 | list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
| 1827 | - if ($rate) $this->setMulticurrencyRate($rate,2); |
|
| 1827 | + if ($rate) $this->setMulticurrencyRate($rate, 2); |
|
| 1828 | 1828 | |
| 1829 | 1829 | return 1; |
| 1830 | 1830 | } |
| 1831 | 1831 | else |
| 1832 | 1832 | { |
| 1833 | 1833 | dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
| 1834 | - $this->error=$this->db->error(); |
|
| 1834 | + $this->error = $this->db->error(); |
|
| 1835 | 1835 | return -1; |
| 1836 | 1836 | } |
| 1837 | 1837 | } |
| 1838 | 1838 | else |
| 1839 | 1839 | { |
| 1840 | 1840 | dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
| 1841 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1841 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1842 | 1842 | return -2; |
| 1843 | 1843 | } |
| 1844 | 1844 | } |
@@ -1850,7 +1850,7 @@ discard block |
||
| 1850 | 1850 | * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
| 1851 | 1851 | * @return int >0 if OK, <0 if KO |
| 1852 | 1852 | */ |
| 1853 | - function setMulticurrencyRate($rate, $mode=1) |
|
| 1853 | + function setMulticurrencyRate($rate, $mode = 1) |
|
| 1854 | 1854 | { |
| 1855 | 1855 | dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')'); |
| 1856 | 1856 | if ($this->statut >= 0 || $this->element == 'societe') |
@@ -1870,7 +1870,7 @@ discard block |
||
| 1870 | 1870 | { |
| 1871 | 1871 | foreach ($this->lines as &$line) |
| 1872 | 1872 | { |
| 1873 | - if($mode == 1) { |
|
| 1873 | + if ($mode == 1) { |
|
| 1874 | 1874 | $line->subprice = 0; |
| 1875 | 1875 | } |
| 1876 | 1876 | |
@@ -1878,14 +1878,14 @@ discard block |
||
| 1878 | 1878 | case 'propal': |
| 1879 | 1879 | $this->updateline( |
| 1880 | 1880 | $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
| 1881 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1881 | + ($line->description ? $line->description : $line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1882 | 1882 | $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, |
| 1883 | 1883 | $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
| 1884 | 1884 | ); |
| 1885 | 1885 | break; |
| 1886 | 1886 | case 'commande': |
| 1887 | 1887 | $this->updateline( |
| 1888 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1888 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1889 | 1889 | $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, |
| 1890 | 1890 | $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
| 1891 | 1891 | $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
@@ -1893,7 +1893,7 @@ discard block |
||
| 1893 | 1893 | break; |
| 1894 | 1894 | case 'facture': |
| 1895 | 1895 | $this->updateline( |
| 1896 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1896 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1897 | 1897 | $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, |
| 1898 | 1898 | $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
| 1899 | 1899 | $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice |
@@ -1902,21 +1902,21 @@ discard block |
||
| 1902 | 1902 | case 'supplier_proposal': |
| 1903 | 1903 | $this->updateline( |
| 1904 | 1904 | $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
| 1905 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1905 | + ($line->description ? $line->description : $line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1906 | 1906 | $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, |
| 1907 | 1907 | $line->ref_fourn, $line->multicurrency_subprice |
| 1908 | 1908 | ); |
| 1909 | 1909 | break; |
| 1910 | 1910 | case 'order_supplier': |
| 1911 | 1911 | $this->updateline( |
| 1912 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1912 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1913 | 1913 | $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, |
| 1914 | 1914 | $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
| 1915 | 1915 | ); |
| 1916 | 1916 | break; |
| 1917 | 1917 | case 'invoice_supplier': |
| 1918 | 1918 | $this->updateline( |
| 1919 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
| 1919 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
| 1920 | 1920 | $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, |
| 1921 | 1921 | $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
| 1922 | 1922 | ); |
@@ -1933,14 +1933,14 @@ discard block |
||
| 1933 | 1933 | else |
| 1934 | 1934 | { |
| 1935 | 1935 | dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
| 1936 | - $this->error=$this->db->error(); |
|
| 1936 | + $this->error = $this->db->error(); |
|
| 1937 | 1937 | return -1; |
| 1938 | 1938 | } |
| 1939 | 1939 | } |
| 1940 | 1940 | else |
| 1941 | 1941 | { |
| 1942 | 1942 | dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
| 1943 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1943 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1944 | 1944 | return -2; |
| 1945 | 1945 | } |
| 1946 | 1946 | } |
@@ -1970,20 +1970,20 @@ discard block |
||
| 1970 | 1970 | $this->cond_reglement_id = $id; |
| 1971 | 1971 | // for supplier |
| 1972 | 1972 | if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
| 1973 | - $this->cond_reglement = $id; // for compatibility |
|
| 1973 | + $this->cond_reglement = $id; // for compatibility |
|
| 1974 | 1974 | return 1; |
| 1975 | 1975 | } |
| 1976 | 1976 | else |
| 1977 | 1977 | { |
| 1978 | 1978 | dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
| 1979 | - $this->error=$this->db->error(); |
|
| 1979 | + $this->error = $this->db->error(); |
|
| 1980 | 1980 | return -1; |
| 1981 | 1981 | } |
| 1982 | 1982 | } |
| 1983 | 1983 | else |
| 1984 | 1984 | { |
| 1985 | 1985 | dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
| 1986 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1986 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1987 | 1987 | return -2; |
| 1988 | 1988 | } |
| 1989 | 1989 | } |
@@ -2001,7 +2001,7 @@ discard block |
||
| 2001 | 2001 | if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
| 2002 | 2002 | |
| 2003 | 2003 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
| 2004 | - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 2004 | + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 2005 | 2005 | |
| 2006 | 2006 | if ($this->db->query($sql)) |
| 2007 | 2007 | { |
@@ -2010,7 +2010,7 @@ discard block |
||
| 2010 | 2010 | } |
| 2011 | 2011 | else |
| 2012 | 2012 | { |
| 2013 | - $this->error=$this->db->error(); |
|
| 2013 | + $this->error = $this->db->error(); |
|
| 2014 | 2014 | dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
| 2015 | 2015 | return -1; |
| 2016 | 2016 | } |
@@ -2026,29 +2026,29 @@ discard block |
||
| 2026 | 2026 | * |
| 2027 | 2027 | * @return int 1 if OK, 0 if KO |
| 2028 | 2028 | */ |
| 2029 | - function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
| 2029 | + function setShippingMethod($shipping_method_id, $notrigger = false, $userused = null) |
|
| 2030 | 2030 | { |
| 2031 | 2031 | global $user; |
| 2032 | 2032 | |
| 2033 | - if (empty($userused)) $userused=$user; |
|
| 2033 | + if (empty($userused)) $userused = $user; |
|
| 2034 | 2034 | |
| 2035 | 2035 | $error = 0; |
| 2036 | 2036 | |
| 2037 | - if (! $this->table_element) { |
|
| 2038 | - dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
| 2037 | + if (!$this->table_element) { |
|
| 2038 | + dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined", LOG_ERR); |
|
| 2039 | 2039 | return -1; |
| 2040 | 2040 | } |
| 2041 | 2041 | |
| 2042 | 2042 | $this->db->begin(); |
| 2043 | 2043 | |
| 2044 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 2044 | + if ($shipping_method_id < 0) $shipping_method_id = 'NULL'; |
|
| 2045 | 2045 | dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); |
| 2046 | 2046 | |
| 2047 | 2047 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 2048 | - $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 2049 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2048 | + $sql .= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 2049 | + $sql .= " WHERE rowid=".$this->id; |
|
| 2050 | 2050 | $resql = $this->db->query($sql); |
| 2051 | - if (! $resql) { |
|
| 2051 | + if (!$resql) { |
|
| 2052 | 2052 | dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
| 2053 | 2053 | $this->error = $this->db->lasterror(); |
| 2054 | 2054 | $error++; |
@@ -2056,8 +2056,8 @@ discard block |
||
| 2056 | 2056 | if (!$notrigger) |
| 2057 | 2057 | { |
| 2058 | 2058 | // Call trigger |
| 2059 | - $this->context=array('shippingmethodupdate'=>1); |
|
| 2060 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2059 | + $this->context = array('shippingmethodupdate'=>1); |
|
| 2060 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
| 2061 | 2061 | if ($result < 0) $error++; |
| 2062 | 2062 | // End call trigger |
| 2063 | 2063 | } |
@@ -2067,7 +2067,7 @@ discard block |
||
| 2067 | 2067 | $this->db->rollback(); |
| 2068 | 2068 | return -1; |
| 2069 | 2069 | } else { |
| 2070 | - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
| 2070 | + $this->shipping_method_id = ($shipping_method_id == 'NULL') ?null:$shipping_method_id; |
|
| 2071 | 2071 | $this->db->commit(); |
| 2072 | 2072 | return 1; |
| 2073 | 2073 | } |
@@ -2082,23 +2082,23 @@ discard block |
||
| 2082 | 2082 | */ |
| 2083 | 2083 | function setWarehouse($warehouse_id) |
| 2084 | 2084 | { |
| 2085 | - if (! $this->table_element) { |
|
| 2086 | - dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
| 2085 | + if (!$this->table_element) { |
|
| 2086 | + dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined", LOG_ERR); |
|
| 2087 | 2087 | return -1; |
| 2088 | 2088 | } |
| 2089 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 2089 | + if ($warehouse_id < 0) $warehouse_id = 'NULL'; |
|
| 2090 | 2090 | dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); |
| 2091 | 2091 | |
| 2092 | 2092 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 2093 | - $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
| 2094 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2093 | + $sql .= " SET fk_warehouse = ".$warehouse_id; |
|
| 2094 | + $sql .= " WHERE rowid=".$this->id; |
|
| 2095 | 2095 | |
| 2096 | 2096 | if ($this->db->query($sql)) { |
| 2097 | - $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
| 2097 | + $this->warehouse_id = ($warehouse_id == 'NULL') ?null:$warehouse_id; |
|
| 2098 | 2098 | return 1; |
| 2099 | 2099 | } else { |
| 2100 | 2100 | dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
| 2101 | - $this->error=$this->db->error(); |
|
| 2101 | + $this->error = $this->db->error(); |
|
| 2102 | 2102 | return 0; |
| 2103 | 2103 | } |
| 2104 | 2104 | } |
@@ -2113,25 +2113,25 @@ discard block |
||
| 2113 | 2113 | */ |
| 2114 | 2114 | function setDocModel($user, $modelpdf) |
| 2115 | 2115 | { |
| 2116 | - if (! $this->table_element) |
|
| 2116 | + if (!$this->table_element) |
|
| 2117 | 2117 | { |
| 2118 | - dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
| 2118 | + dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined", LOG_ERR); |
|
| 2119 | 2119 | return -1; |
| 2120 | 2120 | } |
| 2121 | 2121 | |
| 2122 | - $newmodelpdf=dol_trunc($modelpdf,255); |
|
| 2122 | + $newmodelpdf = dol_trunc($modelpdf, 255); |
|
| 2123 | 2123 | |
| 2124 | 2124 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 2125 | - $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 2126 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 2125 | + $sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 2126 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 2127 | 2127 | // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
| 2128 | 2128 | // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
| 2129 | 2129 | |
| 2130 | 2130 | dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
| 2131 | - $resql=$this->db->query($sql); |
|
| 2131 | + $resql = $this->db->query($sql); |
|
| 2132 | 2132 | if ($resql) |
| 2133 | 2133 | { |
| 2134 | - $this->modelpdf=$modelpdf; |
|
| 2134 | + $this->modelpdf = $modelpdf; |
|
| 2135 | 2135 | return 1; |
| 2136 | 2136 | } |
| 2137 | 2137 | else |
@@ -2150,29 +2150,29 @@ discard block |
||
| 2150 | 2150 | * @param User $userused Object user |
| 2151 | 2151 | * @return int 1 if OK, 0 if KO |
| 2152 | 2152 | */ |
| 2153 | - function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
| 2153 | + function setBankAccount($fk_account, $notrigger = false, $userused = null) |
|
| 2154 | 2154 | { |
| 2155 | 2155 | global $user; |
| 2156 | 2156 | |
| 2157 | - if (empty($userused)) $userused=$user; |
|
| 2157 | + if (empty($userused)) $userused = $user; |
|
| 2158 | 2158 | |
| 2159 | 2159 | $error = 0; |
| 2160 | 2160 | |
| 2161 | - if (! $this->table_element) { |
|
| 2162 | - dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
| 2161 | + if (!$this->table_element) { |
|
| 2162 | + dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined", LOG_ERR); |
|
| 2163 | 2163 | return -1; |
| 2164 | 2164 | } |
| 2165 | 2165 | $this->db->begin(); |
| 2166 | 2166 | |
| 2167 | - if ($fk_account<0) $fk_account='NULL'; |
|
| 2167 | + if ($fk_account < 0) $fk_account = 'NULL'; |
|
| 2168 | 2168 | dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); |
| 2169 | 2169 | |
| 2170 | 2170 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 2171 | - $sql.= " SET fk_account = ".$fk_account; |
|
| 2172 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2171 | + $sql .= " SET fk_account = ".$fk_account; |
|
| 2172 | + $sql .= " WHERE rowid=".$this->id; |
|
| 2173 | 2173 | |
| 2174 | 2174 | $resql = $this->db->query($sql); |
| 2175 | - if (! $resql) |
|
| 2175 | + if (!$resql) |
|
| 2176 | 2176 | { |
| 2177 | 2177 | dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
| 2178 | 2178 | $this->error = $this->db->lasterror(); |
@@ -2183,8 +2183,8 @@ discard block |
||
| 2183 | 2183 | if (!$notrigger) |
| 2184 | 2184 | { |
| 2185 | 2185 | // Call trigger |
| 2186 | - $this->context=array('bankaccountupdate'=>1); |
|
| 2187 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2186 | + $this->context = array('bankaccountupdate'=>1); |
|
| 2187 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
| 2188 | 2188 | if ($result < 0) $error++; |
| 2189 | 2189 | // End call trigger |
| 2190 | 2190 | } |
@@ -2196,7 +2196,7 @@ discard block |
||
| 2196 | 2196 | } |
| 2197 | 2197 | else |
| 2198 | 2198 | { |
| 2199 | - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
| 2199 | + $this->fk_account = ($fk_account == 'NULL') ?null:$fk_account; |
|
| 2200 | 2200 | $this->db->commit(); |
| 2201 | 2201 | return 1; |
| 2202 | 2202 | } |
@@ -2215,26 +2215,26 @@ discard block |
||
| 2215 | 2215 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
| 2216 | 2216 | * @return int <0 if KO, >0 if OK |
| 2217 | 2217 | */ |
| 2218 | - function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
| 2218 | + function line_order($renum = false, $rowidorder = 'ASC', $fk_parent_line = true) |
|
| 2219 | 2219 | { |
| 2220 | 2220 | // phpcs:enable |
| 2221 | - if (! $this->table_element_line) |
|
| 2221 | + if (!$this->table_element_line) |
|
| 2222 | 2222 | { |
| 2223 | - dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
| 2223 | + dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined", LOG_ERR); |
|
| 2224 | 2224 | return -1; |
| 2225 | 2225 | } |
| 2226 | - if (! $this->fk_element) |
|
| 2226 | + if (!$this->fk_element) |
|
| 2227 | 2227 | { |
| 2228 | - dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
| 2228 | + dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined", LOG_ERR); |
|
| 2229 | 2229 | return -1; |
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | 2232 | // Count number of lines to reorder (according to choice $renum) |
| 2233 | - $nl=0; |
|
| 2233 | + $nl = 0; |
|
| 2234 | 2234 | $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2235 | - $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2236 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2237 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2235 | + $sql .= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2236 | + if (!$renum) $sql .= ' AND rang = 0'; |
|
| 2237 | + if ($renum) $sql .= ' AND rang <> 0'; |
|
| 2238 | 2238 | |
| 2239 | 2239 | dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
| 2240 | 2240 | $resql = $this->db->query($sql); |
@@ -2248,28 +2248,28 @@ discard block |
||
| 2248 | 2248 | { |
| 2249 | 2249 | // The goal of this part is to reorder all lines, with all children lines sharing the same |
| 2250 | 2250 | // counter that parents. |
| 2251 | - $rows=array(); |
|
| 2251 | + $rows = array(); |
|
| 2252 | 2252 | |
| 2253 | 2253 | // We first search all lines that are parent lines (for multilevel details lines) |
| 2254 | 2254 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2255 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2256 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2257 | - $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2255 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2256 | + if ($fk_parent_line) $sql .= ' AND fk_parent_line IS NULL'; |
|
| 2257 | + $sql .= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2258 | 2258 | |
| 2259 | 2259 | dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
| 2260 | 2260 | $resql = $this->db->query($sql); |
| 2261 | 2261 | if ($resql) |
| 2262 | 2262 | { |
| 2263 | - $i=0; |
|
| 2263 | + $i = 0; |
|
| 2264 | 2264 | $num = $this->db->num_rows($resql); |
| 2265 | 2265 | while ($i < $num) |
| 2266 | 2266 | { |
| 2267 | 2267 | $row = $this->db->fetch_row($resql); |
| 2268 | - $rows[] = $row[0]; // Add parent line into array rows |
|
| 2268 | + $rows[] = $row[0]; // Add parent line into array rows |
|
| 2269 | 2269 | $childrens = $this->getChildrenOfLine($row[0]); |
| 2270 | - if (! empty($childrens)) |
|
| 2270 | + if (!empty($childrens)) |
|
| 2271 | 2271 | { |
| 2272 | - foreach($childrens as $child) |
|
| 2272 | + foreach ($childrens as $child) |
|
| 2273 | 2273 | { |
| 2274 | 2274 | array_push($rows, $child); |
| 2275 | 2275 | } |
@@ -2278,11 +2278,11 @@ discard block |
||
| 2278 | 2278 | } |
| 2279 | 2279 | |
| 2280 | 2280 | // Now we set a new number for each lines (parent and children with children included into parent tree) |
| 2281 | - if (! empty($rows)) |
|
| 2281 | + if (!empty($rows)) |
|
| 2282 | 2282 | { |
| 2283 | - foreach($rows as $key => $row) |
|
| 2283 | + foreach ($rows as $key => $row) |
|
| 2284 | 2284 | { |
| 2285 | - $this->updateRangOfLine($row, ($key+1)); |
|
| 2285 | + $this->updateRangOfLine($row, ($key + 1)); |
|
| 2286 | 2286 | } |
| 2287 | 2287 | } |
| 2288 | 2288 | } |
@@ -2302,18 +2302,18 @@ discard block |
||
| 2302 | 2302 | */ |
| 2303 | 2303 | function getChildrenOfLine($id) |
| 2304 | 2304 | { |
| 2305 | - $rows=array(); |
|
| 2305 | + $rows = array(); |
|
| 2306 | 2306 | |
| 2307 | 2307 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2308 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2309 | - $sql.= ' AND fk_parent_line = '.$id; |
|
| 2310 | - $sql.= ' ORDER BY rang ASC'; |
|
| 2308 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2309 | + $sql .= ' AND fk_parent_line = '.$id; |
|
| 2310 | + $sql .= ' ORDER BY rang ASC'; |
|
| 2311 | 2311 | |
| 2312 | 2312 | dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
| 2313 | 2313 | $resql = $this->db->query($sql); |
| 2314 | 2314 | if ($resql) |
| 2315 | 2315 | { |
| 2316 | - $i=0; |
|
| 2316 | + $i = 0; |
|
| 2317 | 2317 | $num = $this->db->num_rows($resql); |
| 2318 | 2318 | while ($i < $num) |
| 2319 | 2319 | { |
@@ -2334,7 +2334,7 @@ discard block |
||
| 2334 | 2334 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
| 2335 | 2335 | * @return void |
| 2336 | 2336 | */ |
| 2337 | - function line_up($rowid, $fk_parent_line=true) |
|
| 2337 | + function line_up($rowid, $fk_parent_line = true) |
|
| 2338 | 2338 | { |
| 2339 | 2339 | // phpcs:enable |
| 2340 | 2340 | $this->line_order(false, 'ASC', $fk_parent_line); |
@@ -2354,7 +2354,7 @@ discard block |
||
| 2354 | 2354 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
| 2355 | 2355 | * @return void |
| 2356 | 2356 | */ |
| 2357 | - function line_down($rowid, $fk_parent_line=true) |
|
| 2357 | + function line_down($rowid, $fk_parent_line = true) |
|
| 2358 | 2358 | { |
| 2359 | 2359 | // phpcs:enable |
| 2360 | 2360 | $this->line_order(false, 'ASC', $fk_parent_line); |
@@ -2376,16 +2376,16 @@ discard block |
||
| 2376 | 2376 | * @param int $rang Position |
| 2377 | 2377 | * @return void |
| 2378 | 2378 | */ |
| 2379 | - function updateRangOfLine($rowid,$rang) |
|
| 2379 | + function updateRangOfLine($rowid, $rang) |
|
| 2380 | 2380 | { |
| 2381 | 2381 | $fieldposition = 'rang'; |
| 2382 | 2382 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
| 2383 | 2383 | |
| 2384 | 2384 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2385 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2385 | + $sql .= ' WHERE rowid = '.$rowid; |
|
| 2386 | 2386 | |
| 2387 | 2387 | dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
| 2388 | - if (! $this->db->query($sql)) |
|
| 2388 | + if (!$this->db->query($sql)) |
|
| 2389 | 2389 | { |
| 2390 | 2390 | dol_print_error($this->db); |
| 2391 | 2391 | } |
@@ -2402,9 +2402,9 @@ discard block |
||
| 2402 | 2402 | { |
| 2403 | 2403 | // phpcs:enable |
| 2404 | 2404 | $num = count($rows); |
| 2405 | - for ($i = 0 ; $i < $num ; $i++) |
|
| 2405 | + for ($i = 0; $i < $num; $i++) |
|
| 2406 | 2406 | { |
| 2407 | - $this->updateRangOfLine($rows[$i], ($i+1)); |
|
| 2407 | + $this->updateRangOfLine($rows[$i], ($i + 1)); |
|
| 2408 | 2408 | } |
| 2409 | 2409 | } |
| 2410 | 2410 | |
@@ -2415,21 +2415,21 @@ discard block |
||
| 2415 | 2415 | * @param int $rang Position |
| 2416 | 2416 | * @return void |
| 2417 | 2417 | */ |
| 2418 | - function updateLineUp($rowid,$rang) |
|
| 2418 | + function updateLineUp($rowid, $rang) |
|
| 2419 | 2419 | { |
| 2420 | 2420 | if ($rang > 1) |
| 2421 | 2421 | { |
| 2422 | 2422 | $fieldposition = 'rang'; |
| 2423 | 2423 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
| 2424 | 2424 | |
| 2425 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
|
| 2426 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2427 | - $sql.= ' AND rang = '.($rang - 1); |
|
| 2428 | - if ($this->db->query($sql) ) |
|
| 2425 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2426 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2427 | + $sql .= ' AND rang = '.($rang - 1); |
|
| 2428 | + if ($this->db->query($sql)) |
|
| 2429 | 2429 | { |
| 2430 | 2430 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
| 2431 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2432 | - if (! $this->db->query($sql) ) |
|
| 2431 | + $sql .= ' WHERE rowid = '.$rowid; |
|
| 2432 | + if (!$this->db->query($sql)) |
|
| 2433 | 2433 | { |
| 2434 | 2434 | dol_print_error($this->db); |
| 2435 | 2435 | } |
@@ -2449,7 +2449,7 @@ discard block |
||
| 2449 | 2449 | * @param int $max Max |
| 2450 | 2450 | * @return void |
| 2451 | 2451 | */ |
| 2452 | - function updateLineDown($rowid,$rang,$max) |
|
| 2452 | + function updateLineDown($rowid, $rang, $max) |
|
| 2453 | 2453 | { |
| 2454 | 2454 | if ($rang < $max) |
| 2455 | 2455 | { |
@@ -2457,13 +2457,13 @@ discard block |
||
| 2457 | 2457 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
| 2458 | 2458 | |
| 2459 | 2459 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2460 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2461 | - $sql.= ' AND rang = '.($rang+1); |
|
| 2462 | - if ($this->db->query($sql) ) |
|
| 2460 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2461 | + $sql .= ' AND rang = '.($rang + 1); |
|
| 2462 | + if ($this->db->query($sql)) |
|
| 2463 | 2463 | { |
| 2464 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang+1); |
|
| 2465 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2466 | - if (! $this->db->query($sql) ) |
|
| 2464 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang + 1); |
|
| 2465 | + $sql .= ' WHERE rowid = '.$rowid; |
|
| 2466 | + if (!$this->db->query($sql)) |
|
| 2467 | 2467 | { |
| 2468 | 2468 | dol_print_error($this->db); |
| 2469 | 2469 | } |
@@ -2484,7 +2484,7 @@ discard block |
||
| 2484 | 2484 | function getRangOfLine($rowid) |
| 2485 | 2485 | { |
| 2486 | 2486 | $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2487 | - $sql.= ' WHERE rowid ='.$rowid; |
|
| 2487 | + $sql .= ' WHERE rowid ='.$rowid; |
|
| 2488 | 2488 | |
| 2489 | 2489 | dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
| 2490 | 2490 | $resql = $this->db->query($sql); |
@@ -2504,8 +2504,8 @@ discard block |
||
| 2504 | 2504 | function getIdOfLine($rang) |
| 2505 | 2505 | { |
| 2506 | 2506 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2507 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2508 | - $sql.= ' AND rang = '.$rang; |
|
| 2507 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2508 | + $sql .= ' AND rang = '.$rang; |
|
| 2509 | 2509 | $resql = $this->db->query($sql); |
| 2510 | 2510 | if ($resql) |
| 2511 | 2511 | { |
@@ -2521,22 +2521,22 @@ discard block |
||
| 2521 | 2521 | * @param int $fk_parent_line Parent line id |
| 2522 | 2522 | * @return int Max value of rang in table of lines |
| 2523 | 2523 | */ |
| 2524 | - function line_max($fk_parent_line=0) |
|
| 2524 | + function line_max($fk_parent_line = 0) |
|
| 2525 | 2525 | { |
| 2526 | 2526 | // phpcs:enable |
| 2527 | 2527 | // Search the last rang with fk_parent_line |
| 2528 | 2528 | if ($fk_parent_line) |
| 2529 | 2529 | { |
| 2530 | 2530 | $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2531 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2532 | - $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2531 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2532 | + $sql .= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2533 | 2533 | |
| 2534 | 2534 | dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
| 2535 | 2535 | $resql = $this->db->query($sql); |
| 2536 | 2536 | if ($resql) |
| 2537 | 2537 | { |
| 2538 | 2538 | $row = $this->db->fetch_row($resql); |
| 2539 | - if (! empty($row[0])) |
|
| 2539 | + if (!empty($row[0])) |
|
| 2540 | 2540 | { |
| 2541 | 2541 | return $row[0]; |
| 2542 | 2542 | } |
@@ -2550,7 +2550,7 @@ discard block |
||
| 2550 | 2550 | else |
| 2551 | 2551 | { |
| 2552 | 2552 | $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2553 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2553 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2554 | 2554 | |
| 2555 | 2555 | dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
| 2556 | 2556 | $resql = $this->db->query($sql); |
@@ -2572,15 +2572,15 @@ discard block |
||
| 2572 | 2572 | function update_ref_ext($ref_ext) |
| 2573 | 2573 | { |
| 2574 | 2574 | // phpcs:enable |
| 2575 | - if (! $this->table_element) |
|
| 2575 | + if (!$this->table_element) |
|
| 2576 | 2576 | { |
| 2577 | 2577 | dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
| 2578 | 2578 | return -1; |
| 2579 | 2579 | } |
| 2580 | 2580 | |
| 2581 | 2581 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 2582 | - $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2583 | - $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
| 2582 | + $sql .= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2583 | + $sql .= " WHERE ".(isset($this->table_rowid) ? $this->table_rowid : 'rowid')." = ".$this->id; |
|
| 2584 | 2584 | |
| 2585 | 2585 | dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
| 2586 | 2586 | if ($this->db->query($sql)) |
@@ -2590,7 +2590,7 @@ discard block |
||
| 2590 | 2590 | } |
| 2591 | 2591 | else |
| 2592 | 2592 | { |
| 2593 | - $this->error=$this->db->error(); |
|
| 2593 | + $this->error = $this->db->error(); |
|
| 2594 | 2594 | return -1; |
| 2595 | 2595 | } |
| 2596 | 2596 | } |
@@ -2603,31 +2603,31 @@ discard block |
||
| 2603 | 2603 | * @param string $suffix '', '_public' or '_private' |
| 2604 | 2604 | * @return int <0 if KO, >0 if OK |
| 2605 | 2605 | */ |
| 2606 | - function update_note($note, $suffix='') |
|
| 2606 | + function update_note($note, $suffix = '') |
|
| 2607 | 2607 | { |
| 2608 | 2608 | // phpcs:enable |
| 2609 | 2609 | global $user; |
| 2610 | 2610 | |
| 2611 | - if (! $this->table_element) |
|
| 2611 | + if (!$this->table_element) |
|
| 2612 | 2612 | { |
| 2613 | - $this->error='update_note was called on objet with property table_element not defined'; |
|
| 2613 | + $this->error = 'update_note was called on objet with property table_element not defined'; |
|
| 2614 | 2614 | dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
| 2615 | 2615 | return -1; |
| 2616 | 2616 | } |
| 2617 | - if (! in_array($suffix,array('','_public','_private'))) |
|
| 2617 | + if (!in_array($suffix, array('', '_public', '_private'))) |
|
| 2618 | 2618 | { |
| 2619 | - $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
| 2619 | + $this->error = 'update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
| 2620 | 2620 | dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
| 2621 | 2621 | return -2; |
| 2622 | 2622 | } |
| 2623 | 2623 | // Special cas |
| 2624 | 2624 | //var_dump($this->table_element);exit; |
| 2625 | - if ($this->table_element == 'product') $suffix=''; |
|
| 2625 | + if ($this->table_element == 'product') $suffix = ''; |
|
| 2626 | 2626 | |
| 2627 | 2627 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 2628 | - $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL"); |
|
| 2629 | - $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id; |
|
| 2630 | - $sql.= " WHERE rowid =". $this->id; |
|
| 2628 | + $sql .= " SET note".$suffix." = ".(!empty($note) ? ("'".$this->db->escape($note)."'") : "NULL"); |
|
| 2629 | + $sql .= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment')) ? "fk_user_mod" : "fk_user_modif")." = ".$user->id; |
|
| 2630 | + $sql .= " WHERE rowid =".$this->id; |
|
| 2631 | 2631 | |
| 2632 | 2632 | dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
| 2633 | 2633 | if ($this->db->query($sql)) |
@@ -2636,14 +2636,14 @@ discard block |
||
| 2636 | 2636 | else if ($suffix == '_private') $this->note_private = $note; |
| 2637 | 2637 | else |
| 2638 | 2638 | { |
| 2639 | - $this->note = $note; // deprecated |
|
| 2639 | + $this->note = $note; // deprecated |
|
| 2640 | 2640 | $this->note_private = $note; |
| 2641 | 2641 | } |
| 2642 | 2642 | return 1; |
| 2643 | 2643 | } |
| 2644 | 2644 | else |
| 2645 | 2645 | { |
| 2646 | - $this->error=$this->db->lasterror(); |
|
| 2646 | + $this->error = $this->db->lasterror(); |
|
| 2647 | 2647 | return -1; |
| 2648 | 2648 | } |
| 2649 | 2649 | } |
@@ -2660,7 +2660,7 @@ discard block |
||
| 2660 | 2660 | function update_note_public($note) |
| 2661 | 2661 | { |
| 2662 | 2662 | // phpcs:enable |
| 2663 | - return $this->update_note($note,'_public'); |
|
| 2663 | + return $this->update_note($note, '_public'); |
|
| 2664 | 2664 | } |
| 2665 | 2665 | |
| 2666 | 2666 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -2674,7 +2674,7 @@ discard block |
||
| 2674 | 2674 | * @param Societe $seller If roundingadjust is '0' or '1' or maybe 'auto', it means we recalculate total for lines before calculating total for object and for this, we need seller object. |
| 2675 | 2675 | * @return int <0 if KO, >0 if OK |
| 2676 | 2676 | */ |
| 2677 | - function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
| 2677 | + function update_price($exclspec = 0, $roundingadjust = 'none', $nodatabaseupdate = 0, $seller = null) |
|
| 2678 | 2678 | { |
| 2679 | 2679 | // phpcs:enable |
| 2680 | 2680 | global $conf, $hookmanager, $action; |
@@ -2694,8 +2694,8 @@ discard block |
||
| 2694 | 2694 | elseif ($this->element == 'supplier_proposal') |
| 2695 | 2695 | $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
| 2696 | 2696 | |
| 2697 | - if (! empty($MODULE)) { |
|
| 2698 | - if (! empty($conf->global->$MODULE)) { |
|
| 2697 | + if (!empty($MODULE)) { |
|
| 2698 | + if (!empty($conf->global->$MODULE)) { |
|
| 2699 | 2699 | $modsactivated = explode(',', $conf->global->$MODULE); |
| 2700 | 2700 | foreach ($modsactivated as $mod) { |
| 2701 | 2701 | if ($conf->$mod->enabled) |
@@ -2706,44 +2706,44 @@ discard block |
||
| 2706 | 2706 | |
| 2707 | 2707 | include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
| 2708 | 2708 | |
| 2709 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 2709 | + if ($roundingadjust == '-1') $roundingadjust = 'auto'; // For backward compatibility |
|
| 2710 | 2710 | |
| 2711 | - $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'; |
|
| 2711 | + $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'; |
|
| 2714 | 2714 | |
| 2715 | - $error=0; |
|
| 2715 | + $error = 0; |
|
| 2716 | 2716 | |
| 2717 | 2717 | $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
| 2718 | 2718 | |
| 2719 | 2719 | // Define constants to find lines to sum |
| 2720 | - $fieldtva='total_tva'; |
|
| 2721 | - $fieldlocaltax1='total_localtax1'; |
|
| 2722 | - $fieldlocaltax2='total_localtax2'; |
|
| 2723 | - $fieldup='subprice'; |
|
| 2720 | + $fieldtva = 'total_tva'; |
|
| 2721 | + $fieldlocaltax1 = 'total_localtax1'; |
|
| 2722 | + $fieldlocaltax2 = 'total_localtax2'; |
|
| 2723 | + $fieldup = 'subprice'; |
|
| 2724 | 2724 | if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
| 2725 | 2725 | { |
| 2726 | - $fieldtva='tva'; |
|
| 2727 | - $fieldup='pu_ht'; |
|
| 2726 | + $fieldtva = 'tva'; |
|
| 2727 | + $fieldup = 'pu_ht'; |
|
| 2728 | 2728 | } |
| 2729 | 2729 | if ($this->element == 'expensereport') |
| 2730 | 2730 | { |
| 2731 | - $fieldup='value_unit'; |
|
| 2731 | + $fieldup = 'value_unit'; |
|
| 2732 | 2732 | } |
| 2733 | 2733 | |
| 2734 | 2734 | $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 | - $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'; |
|
| 2737 | - $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2738 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2739 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2735 | + $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'; |
|
| 2737 | + $sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2738 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2739 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2740 | 2740 | if ($exclspec) |
| 2741 | 2741 | { |
| 2742 | - $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'; |
|
| 2742 | + $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'; |
|
| 2745 | 2745 | } |
| 2746 | - $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 |
|
| 2746 | + $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 | 2747 | |
| 2748 | 2748 | dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
| 2749 | 2749 | $resql = $this->db->query($sql); |
@@ -2757,7 +2757,7 @@ discard block |
||
| 2757 | 2757 | $total_ht_by_vats = array(); |
| 2758 | 2758 | $total_tva_by_vats = array(); |
| 2759 | 2759 | $total_ttc_by_vats = array(); |
| 2760 | - $this->multicurrency_total_ht = 0; |
|
| 2760 | + $this->multicurrency_total_ht = 0; |
|
| 2761 | 2761 | $this->multicurrency_total_tva = 0; |
| 2762 | 2762 | $this->multicurrency_total_ttc = 0; |
| 2763 | 2763 | |
@@ -2768,54 +2768,54 @@ discard block |
||
| 2768 | 2768 | $obj = $this->db->fetch_object($resql); |
| 2769 | 2769 | |
| 2770 | 2770 | // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
| 2771 | - $parameters=array('fk_element' => $obj->rowid); |
|
| 2771 | + $parameters = array('fk_element' => $obj->rowid); |
|
| 2772 | 2772 | $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 2773 | 2773 | |
| 2774 | 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' |
| 2775 | 2775 | { |
| 2776 | - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2777 | - $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 | - $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2776 | + $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx); |
|
| 2777 | + $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 | + $diff = price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2779 | 2779 | if ($diff) |
| 2780 | 2780 | { |
| 2781 | - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2781 | + $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2782 | 2782 | 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 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2784 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2783 | + $resqlfix = $this->db->query($sqlfix); |
|
| 2784 | + if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
|
| 2785 | 2785 | $obj->total_tva = $tmpcal[1]; |
| 2786 | 2786 | $obj->total_ttc = $tmpcal[2]; |
| 2787 | 2787 | // |
| 2788 | 2788 | } |
| 2789 | 2789 | } |
| 2790 | 2790 | |
| 2791 | - $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2791 | + $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2792 | 2792 | $this->total_tva += $obj->total_tva; |
| 2793 | 2793 | $this->total_localtax1 += $obj->total_localtax1; |
| 2794 | 2794 | $this->total_localtax2 += $obj->total_localtax2; |
| 2795 | 2795 | $this->total_ttc += $obj->total_ttc; |
| 2796 | - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2796 | + $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2797 | 2797 | $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
| 2798 | 2798 | $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
| 2799 | 2799 | |
| 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; |
|
| 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; |
|
| 2803 | 2803 | $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
| 2804 | 2804 | $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
| 2805 | 2805 | $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
| 2806 | 2806 | |
| 2807 | 2807 | if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
| 2808 | 2808 | { |
| 2809 | - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2810 | - $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
| 2809 | + $tmpvat = price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2810 | + $diff = price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat, 'MT', 1); |
|
| 2811 | 2811 | //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 | 2812 | if ($diff) |
| 2813 | 2813 | { |
| 2814 | 2814 | if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; } |
| 2815 | - $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; |
|
| 2815 | + $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 | 2816 | 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 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2818 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2817 | + $resqlfix = $this->db->query($sqlfix); |
|
| 2818 | + if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
|
| 2819 | 2819 | $this->total_tva -= $diff; |
| 2820 | 2820 | $this->total_ttc -= $diff; |
| 2821 | 2821 | $total_tva_by_vats[$obj->vatrate] -= $diff; |
@@ -2827,11 +2827,11 @@ discard block |
||
| 2827 | 2827 | } |
| 2828 | 2828 | |
| 2829 | 2829 | // Add revenue stamp to total |
| 2830 | - $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
| 2831 | - $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
| 2830 | + $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0; |
|
| 2831 | + $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0; |
|
| 2832 | 2832 | |
| 2833 | 2833 | // Situations totals |
| 2834 | - if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE ) |
|
| 2834 | + if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE) |
|
| 2835 | 2835 | { |
| 2836 | 2836 | $prev_sits = $this->get_prev_sits(); |
| 2837 | 2837 | |
@@ -2850,17 +2850,17 @@ discard block |
||
| 2850 | 2850 | $this->db->free($resql); |
| 2851 | 2851 | |
| 2852 | 2852 | // Now update global field total_ht, total_ttc and tva |
| 2853 | - $fieldht='total_ht'; |
|
| 2854 | - $fieldtva='tva'; |
|
| 2855 | - $fieldlocaltax1='localtax1'; |
|
| 2856 | - $fieldlocaltax2='localtax2'; |
|
| 2857 | - $fieldttc='total_ttc'; |
|
| 2853 | + $fieldht = 'total_ht'; |
|
| 2854 | + $fieldtva = 'tva'; |
|
| 2855 | + $fieldlocaltax1 = 'localtax1'; |
|
| 2856 | + $fieldlocaltax2 = 'localtax2'; |
|
| 2857 | + $fieldttc = 'total_ttc'; |
|
| 2858 | 2858 | // 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'; |
|
| 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'; |
|
| 2864 | 2864 | |
| 2865 | 2865 | if (empty($nodatabaseupdate)) |
| 2866 | 2866 | { |
@@ -2877,16 +2877,16 @@ discard block |
||
| 2877 | 2877 | |
| 2878 | 2878 | |
| 2879 | 2879 | dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
| 2880 | - $resql=$this->db->query($sql); |
|
| 2881 | - if (! $resql) |
|
| 2880 | + $resql = $this->db->query($sql); |
|
| 2881 | + if (!$resql) |
|
| 2882 | 2882 | { |
| 2883 | 2883 | $error++; |
| 2884 | - $this->error=$this->db->lasterror(); |
|
| 2885 | - $this->errors[]=$this->db->lasterror(); |
|
| 2884 | + $this->error = $this->db->lasterror(); |
|
| 2885 | + $this->errors[] = $this->db->lasterror(); |
|
| 2886 | 2886 | } |
| 2887 | 2887 | } |
| 2888 | 2888 | |
| 2889 | - if (! $error) |
|
| 2889 | + if (!$error) |
|
| 2890 | 2890 | { |
| 2891 | 2891 | return 1; |
| 2892 | 2892 | } |
@@ -2897,7 +2897,7 @@ discard block |
||
| 2897 | 2897 | } |
| 2898 | 2898 | else |
| 2899 | 2899 | { |
| 2900 | - dol_print_error($this->db,'Bad request in update_price'); |
|
| 2900 | + dol_print_error($this->db, 'Bad request in update_price'); |
|
| 2901 | 2901 | return -1; |
| 2902 | 2902 | } |
| 2903 | 2903 | } |
@@ -2911,30 +2911,30 @@ discard block |
||
| 2911 | 2911 | * @return int <=0 if KO, >0 if OK |
| 2912 | 2912 | * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
| 2913 | 2913 | */ |
| 2914 | - function add_object_linked($origin=null, $origin_id=null) |
|
| 2914 | + function add_object_linked($origin = null, $origin_id = null) |
|
| 2915 | 2915 | { |
| 2916 | 2916 | // phpcs:enable |
| 2917 | - $origin = (! empty($origin) ? $origin : $this->origin); |
|
| 2918 | - $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2917 | + $origin = (!empty($origin) ? $origin : $this->origin); |
|
| 2918 | + $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2919 | 2919 | |
| 2920 | 2920 | // 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'; |
|
| 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'; |
|
| 2925 | 2925 | $this->db->begin(); |
| 2926 | 2926 | |
| 2927 | 2927 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; |
| 2928 | - $sql.= "fk_source"; |
|
| 2929 | - $sql.= ", sourcetype"; |
|
| 2930 | - $sql.= ", fk_target"; |
|
| 2931 | - $sql.= ", targettype"; |
|
| 2932 | - $sql.= ") VALUES ("; |
|
| 2933 | - $sql.= $origin_id; |
|
| 2934 | - $sql.= ", '".$this->db->escape($origin)."'"; |
|
| 2935 | - $sql.= ", ".$this->id; |
|
| 2936 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 2937 | - $sql.= ")"; |
|
| 2928 | + $sql .= "fk_source"; |
|
| 2929 | + $sql .= ", sourcetype"; |
|
| 2930 | + $sql .= ", fk_target"; |
|
| 2931 | + $sql .= ", targettype"; |
|
| 2932 | + $sql .= ") VALUES ("; |
|
| 2933 | + $sql .= $origin_id; |
|
| 2934 | + $sql .= ", '".$this->db->escape($origin)."'"; |
|
| 2935 | + $sql .= ", ".$this->id; |
|
| 2936 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
| 2937 | + $sql .= ")"; |
|
| 2938 | 2938 | |
| 2939 | 2939 | dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
| 2940 | 2940 | if ($this->db->query($sql)) |
@@ -2944,7 +2944,7 @@ discard block |
||
| 2944 | 2944 | } |
| 2945 | 2945 | else |
| 2946 | 2946 | { |
| 2947 | - $this->error=$this->db->lasterror(); |
|
| 2947 | + $this->error = $this->db->lasterror(); |
|
| 2948 | 2948 | $this->db->rollback(); |
| 2949 | 2949 | return 0; |
| 2950 | 2950 | } |
@@ -2972,33 +2972,33 @@ discard block |
||
| 2972 | 2972 | * @return int <0 if KO, >0 if OK |
| 2973 | 2973 | * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
| 2974 | 2974 | */ |
| 2975 | - function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype',$loadalsoobjects=1) |
|
| 2975 | + function fetchObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $clause = 'OR', $alsosametype = 1, $orderby = 'sourcetype', $loadalsoobjects = 1) |
|
| 2976 | 2976 | { |
| 2977 | 2977 | global $conf; |
| 2978 | 2978 | |
| 2979 | - $this->linkedObjectsIds=array(); |
|
| 2980 | - $this->linkedObjects=array(); |
|
| 2979 | + $this->linkedObjectsIds = array(); |
|
| 2980 | + $this->linkedObjects = array(); |
|
| 2981 | 2981 | |
| 2982 | - $justsource=false; |
|
| 2983 | - $justtarget=false; |
|
| 2984 | - $withtargettype=false; |
|
| 2985 | - $withsourcetype=false; |
|
| 2982 | + $justsource = false; |
|
| 2983 | + $justtarget = false; |
|
| 2984 | + $withtargettype = false; |
|
| 2985 | + $withsourcetype = false; |
|
| 2986 | 2986 | |
| 2987 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
| 2987 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) |
|
| 2988 | 2988 | { |
| 2989 | - $justsource=true; // the source (id and type) is a search criteria |
|
| 2990 | - if (! empty($targettype)) $withtargettype=true; |
|
| 2989 | + $justsource = true; // the source (id and type) is a search criteria |
|
| 2990 | + if (!empty($targettype)) $withtargettype = true; |
|
| 2991 | 2991 | } |
| 2992 | - if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
| 2992 | + if (!empty($targetid) && !empty($targettype) && empty($sourceid)) |
|
| 2993 | 2993 | { |
| 2994 | - $justtarget=true; // the target (id and type) is a search criteria |
|
| 2995 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
| 2994 | + $justtarget = true; // the target (id and type) is a search criteria |
|
| 2995 | + if (!empty($sourcetype)) $withsourcetype = true; |
|
| 2996 | 2996 | } |
| 2997 | 2997 | |
| 2998 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 2999 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 3000 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3001 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 2998 | + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); |
|
| 2999 | + $targetid = (!empty($targetid) ? $targetid : $this->id); |
|
| 3000 | + $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3001 | + $targettype = (!empty($targettype) ? $targettype : $this->element); |
|
| 3002 | 3002 | |
| 3003 | 3003 | /*if (empty($sourceid) && empty($targetid)) |
| 3004 | 3004 | { |
@@ -3008,25 +3008,25 @@ discard block |
||
| 3008 | 3008 | |
| 3009 | 3009 | // Links between objects are stored in table element_element |
| 3010 | 3010 | $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
| 3011 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 3012 | - $sql.= " WHERE "; |
|
| 3011 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 3012 | + $sql .= " WHERE "; |
|
| 3013 | 3013 | if ($justsource || $justtarget) |
| 3014 | 3014 | { |
| 3015 | 3015 | if ($justsource) |
| 3016 | 3016 | { |
| 3017 | - $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 3018 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 3017 | + $sql .= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 3018 | + if ($withtargettype) $sql .= " AND targettype = '".$targettype."'"; |
|
| 3019 | 3019 | } |
| 3020 | 3020 | else if ($justtarget) |
| 3021 | 3021 | { |
| 3022 | - $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 3023 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 3022 | + $sql .= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 3023 | + if ($withsourcetype) $sql .= " AND sourcetype = '".$sourcetype."'"; |
|
| 3024 | 3024 | } |
| 3025 | 3025 | } |
| 3026 | 3026 | else |
| 3027 | 3027 | { |
| 3028 | - $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 3029 | - $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 3028 | + $sql .= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 3029 | + $sql .= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 3030 | 3030 | } |
| 3031 | 3031 | $sql .= ' ORDER BY '.$orderby; |
| 3032 | 3032 | |
@@ -3043,36 +3043,36 @@ discard block |
||
| 3043 | 3043 | { |
| 3044 | 3044 | if ($justsource) |
| 3045 | 3045 | { |
| 3046 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3046 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target; |
|
| 3047 | 3047 | } |
| 3048 | 3048 | else if ($justtarget) |
| 3049 | 3049 | { |
| 3050 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3050 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source; |
|
| 3051 | 3051 | } |
| 3052 | 3052 | } |
| 3053 | 3053 | else |
| 3054 | 3054 | { |
| 3055 | 3055 | if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
| 3056 | 3056 | { |
| 3057 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3057 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target; |
|
| 3058 | 3058 | } |
| 3059 | 3059 | if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
| 3060 | 3060 | { |
| 3061 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3061 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source; |
|
| 3062 | 3062 | } |
| 3063 | 3063 | } |
| 3064 | 3064 | $i++; |
| 3065 | 3065 | } |
| 3066 | 3066 | |
| 3067 | - if (! empty($this->linkedObjectsIds)) |
|
| 3067 | + if (!empty($this->linkedObjectsIds)) |
|
| 3068 | 3068 | { |
| 3069 | 3069 | $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', ...) |
|
| 3070 | + foreach ($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) |
|
| 3071 | 3071 | { |
| 3072 | 3072 | // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
| 3073 | 3073 | $module = $element = $subelement = $objecttype; |
| 3074 | 3074 | if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
| 3075 | - && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) |
|
| 3075 | + && preg_match('/^([^_]+)_([^_]+)/i', $objecttype, $regs)) |
|
| 3076 | 3076 | { |
| 3077 | 3077 | $module = $element = $regs[1]; |
| 3078 | 3078 | $subelement = $regs[2]; |
@@ -3080,31 +3080,31 @@ discard block |
||
| 3080 | 3080 | |
| 3081 | 3081 | $classpath = $element.'/class'; |
| 3082 | 3082 | // To work with non standard classpath or module name |
| 3083 | - if ($objecttype == 'facture') { |
|
| 3083 | + if ($objecttype == 'facture') { |
|
| 3084 | 3084 | $classpath = 'compta/facture/class'; |
| 3085 | 3085 | } |
| 3086 | - else if ($objecttype == 'facturerec') { |
|
| 3086 | + else if ($objecttype == 'facturerec') { |
|
| 3087 | 3087 | $classpath = 'compta/facture/class'; $module = 'facture'; |
| 3088 | 3088 | } |
| 3089 | - else if ($objecttype == 'propal') { |
|
| 3089 | + else if ($objecttype == 'propal') { |
|
| 3090 | 3090 | $classpath = 'comm/propal/class'; |
| 3091 | 3091 | } |
| 3092 | - else if ($objecttype == 'supplier_proposal') { |
|
| 3092 | + else if ($objecttype == 'supplier_proposal') { |
|
| 3093 | 3093 | $classpath = 'supplier_proposal/class'; |
| 3094 | 3094 | } |
| 3095 | - else if ($objecttype == 'shipping') { |
|
| 3095 | + else if ($objecttype == 'shipping') { |
|
| 3096 | 3096 | $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
| 3097 | 3097 | } |
| 3098 | - else if ($objecttype == 'delivery') { |
|
| 3098 | + else if ($objecttype == 'delivery') { |
|
| 3099 | 3099 | $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
| 3100 | 3100 | } |
| 3101 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
| 3101 | + else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
| 3102 | 3102 | $classpath = 'fourn/class'; $module = 'fournisseur'; |
| 3103 | 3103 | } |
| 3104 | - else if ($objecttype == 'fichinter') { |
|
| 3104 | + else if ($objecttype == 'fichinter') { |
|
| 3105 | 3105 | $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
| 3106 | 3106 | } |
| 3107 | - else if ($objecttype == 'subscription') { |
|
| 3107 | + else if ($objecttype == 'subscription') { |
|
| 3108 | 3108 | $classpath = 'adherents/class'; $module = 'adherent'; |
| 3109 | 3109 | } |
| 3110 | 3110 | |
@@ -3117,16 +3117,16 @@ discard block |
||
| 3117 | 3117 | else if ($objecttype == 'invoice_supplier') { |
| 3118 | 3118 | $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
| 3119 | 3119 | } |
| 3120 | - else if ($objecttype == 'order_supplier') { |
|
| 3120 | + else if ($objecttype == 'order_supplier') { |
|
| 3121 | 3121 | $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
| 3122 | 3122 | } |
| 3123 | - else if ($objecttype == 'supplier_proposal') { |
|
| 3123 | + else if ($objecttype == 'supplier_proposal') { |
|
| 3124 | 3124 | $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
| 3125 | 3125 | } |
| 3126 | - else if ($objecttype == 'facturerec') { |
|
| 3126 | + else if ($objecttype == 'facturerec') { |
|
| 3127 | 3127 | $classfile = 'facture-rec'; $classname = 'FactureRec'; |
| 3128 | 3128 | } |
| 3129 | - else if ($objecttype == 'subscription') { |
|
| 3129 | + else if ($objecttype == 'subscription') { |
|
| 3130 | 3130 | $classfile = 'subscription'; $classname = 'Subscription'; |
| 3131 | 3131 | } |
| 3132 | 3132 | |
@@ -3139,7 +3139,7 @@ discard block |
||
| 3139 | 3139 | //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
| 3140 | 3140 | if (class_exists($classname)) |
| 3141 | 3141 | { |
| 3142 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3142 | + foreach ($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3143 | 3143 | { |
| 3144 | 3144 | $object = new $classname($this->db); |
| 3145 | 3145 | $ret = $object->fetch($objectid); |
@@ -3176,28 +3176,28 @@ discard block |
||
| 3176 | 3176 | * @return int >0 if OK, <0 if KO |
| 3177 | 3177 | * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
| 3178 | 3178 | */ |
| 3179 | - function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
| 3179 | + function updateObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '') |
|
| 3180 | 3180 | { |
| 3181 | - $updatesource=false; |
|
| 3182 | - $updatetarget=false; |
|
| 3181 | + $updatesource = false; |
|
| 3182 | + $updatetarget = false; |
|
| 3183 | 3183 | |
| 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; |
|
| 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; |
|
| 3186 | 3186 | |
| 3187 | 3187 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
| 3188 | 3188 | if ($updatesource) |
| 3189 | 3189 | { |
| 3190 | - $sql.= "fk_source = ".$sourceid; |
|
| 3191 | - $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3192 | - $sql.= " WHERE fk_target = ".$this->id; |
|
| 3193 | - $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3190 | + $sql .= "fk_source = ".$sourceid; |
|
| 3191 | + $sql .= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3192 | + $sql .= " WHERE fk_target = ".$this->id; |
|
| 3193 | + $sql .= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3194 | 3194 | } |
| 3195 | 3195 | else if ($updatetarget) |
| 3196 | 3196 | { |
| 3197 | - $sql.= "fk_target = ".$targetid; |
|
| 3198 | - $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 3199 | - $sql.= " WHERE fk_source = ".$this->id; |
|
| 3200 | - $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3197 | + $sql .= "fk_target = ".$targetid; |
|
| 3198 | + $sql .= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 3199 | + $sql .= " WHERE fk_source = ".$this->id; |
|
| 3200 | + $sql .= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3201 | 3201 | } |
| 3202 | 3202 | |
| 3203 | 3203 | dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
@@ -3207,7 +3207,7 @@ discard block |
||
| 3207 | 3207 | } |
| 3208 | 3208 | else |
| 3209 | 3209 | { |
| 3210 | - $this->error=$this->db->lasterror(); |
|
| 3210 | + $this->error = $this->db->lasterror(); |
|
| 3211 | 3211 | return -1; |
| 3212 | 3212 | } |
| 3213 | 3213 | } |
@@ -3223,42 +3223,42 @@ discard block |
||
| 3223 | 3223 | * @return int >0 if OK, <0 if KO |
| 3224 | 3224 | * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
| 3225 | 3225 | */ |
| 3226 | - function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
| 3226 | + function deleteObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $rowid = '') |
|
| 3227 | 3227 | { |
| 3228 | - $deletesource=false; |
|
| 3229 | - $deletetarget=false; |
|
| 3228 | + $deletesource = false; |
|
| 3229 | + $deletetarget = false; |
|
| 3230 | 3230 | |
| 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; |
|
| 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; |
|
| 3233 | 3233 | |
| 3234 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 3235 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3236 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 3237 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 3234 | + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); |
|
| 3235 | + $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3236 | + $targetid = (!empty($targetid) ? $targetid : $this->id); |
|
| 3237 | + $targettype = (!empty($targettype) ? $targettype : $this->element); |
|
| 3238 | 3238 | |
| 3239 | 3239 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
| 3240 | - $sql.= " WHERE"; |
|
| 3240 | + $sql .= " WHERE"; |
|
| 3241 | 3241 | if ($rowid > 0) |
| 3242 | 3242 | { |
| 3243 | - $sql.=" rowid = ".$rowid; |
|
| 3243 | + $sql .= " rowid = ".$rowid; |
|
| 3244 | 3244 | } |
| 3245 | 3245 | else |
| 3246 | 3246 | { |
| 3247 | 3247 | if ($deletesource) |
| 3248 | 3248 | { |
| 3249 | - $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3250 | - $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3249 | + $sql .= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3250 | + $sql .= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3251 | 3251 | } |
| 3252 | 3252 | else if ($deletetarget) |
| 3253 | 3253 | { |
| 3254 | - $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 3255 | - $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3254 | + $sql .= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 3255 | + $sql .= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3256 | 3256 | } |
| 3257 | 3257 | else |
| 3258 | 3258 | { |
| 3259 | - $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3260 | - $sql.= " OR"; |
|
| 3261 | - $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3259 | + $sql .= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3260 | + $sql .= " OR"; |
|
| 3261 | + $sql .= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3262 | 3262 | } |
| 3263 | 3263 | } |
| 3264 | 3264 | |
@@ -3269,8 +3269,8 @@ discard block |
||
| 3269 | 3269 | } |
| 3270 | 3270 | else |
| 3271 | 3271 | { |
| 3272 | - $this->error=$this->db->lasterror(); |
|
| 3273 | - $this->errors[]=$this->error; |
|
| 3272 | + $this->error = $this->db->lasterror(); |
|
| 3273 | + $this->errors[] = $this->error; |
|
| 3274 | 3274 | return -1; |
| 3275 | 3275 | } |
| 3276 | 3276 | } |
@@ -3284,30 +3284,30 @@ discard block |
||
| 3284 | 3284 | * @param string $trigkey Trigger key to use for trigger |
| 3285 | 3285 | * @return int <0 if KO, >0 if OK |
| 3286 | 3286 | */ |
| 3287 | - function setStatut($status, $elementId=null, $elementType='', $trigkey='') |
|
| 3287 | + function setStatut($status, $elementId = null, $elementType = '', $trigkey = '') |
|
| 3288 | 3288 | { |
| 3289 | - global $user,$langs,$conf; |
|
| 3289 | + global $user, $langs, $conf; |
|
| 3290 | 3290 | |
| 3291 | - $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3291 | + $savElementId = $elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3292 | 3292 | |
| 3293 | - $elementId = (!empty($elementId)?$elementId:$this->id); |
|
| 3294 | - $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
| 3293 | + $elementId = (!empty($elementId) ? $elementId : $this->id); |
|
| 3294 | + $elementTable = (!empty($elementType) ? $elementType : $this->table_element); |
|
| 3295 | 3295 | |
| 3296 | 3296 | $this->db->begin(); |
| 3297 | 3297 | |
| 3298 | - $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"; |
|
| 3298 | + $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"; |
|
| 3305 | 3305 | |
| 3306 | 3306 | $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
| 3307 | - $sql.= " SET ".$fieldstatus." = ".$status; |
|
| 3307 | + $sql .= " SET ".$fieldstatus." = ".$status; |
|
| 3308 | 3308 | // If status = 1 = validated, update also fk_user_valid |
| 3309 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3310 | - $sql.= " WHERE rowid=".$elementId; |
|
| 3309 | + if ($status == 1 && $elementTable == 'expensereport') $sql .= ", fk_user_valid = ".$user->id; |
|
| 3310 | + $sql .= " WHERE rowid=".$elementId; |
|
| 3311 | 3311 | |
| 3312 | 3312 | dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
| 3313 | 3313 | if ($this->db->query($sql)) |
@@ -3317,27 +3317,27 @@ discard block |
||
| 3317 | 3317 | // Try autoset of trigkey |
| 3318 | 3318 | if (empty($trigkey)) |
| 3319 | 3319 | { |
| 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'; |
|
| 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'; |
|
| 3326 | 3326 | } |
| 3327 | 3327 | |
| 3328 | 3328 | if ($trigkey) |
| 3329 | 3329 | { |
| 3330 | 3330 | // Appel des triggers |
| 3331 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 3332 | - $interface=new Interfaces($this->db); |
|
| 3333 | - $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
| 3331 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
| 3332 | + $interface = new Interfaces($this->db); |
|
| 3333 | + $result = $interface->run_triggers($trigkey, $this, $user, $langs, $conf); |
|
| 3334 | 3334 | if ($result < 0) { |
| 3335 | - $error++; $this->errors=$interface->errors; |
|
| 3335 | + $error++; $this->errors = $interface->errors; |
|
| 3336 | 3336 | } |
| 3337 | 3337 | // Fin appel triggers |
| 3338 | 3338 | } |
| 3339 | 3339 | |
| 3340 | - if (! $error) |
|
| 3340 | + if (!$error) |
|
| 3341 | 3341 | { |
| 3342 | 3342 | $this->db->commit(); |
| 3343 | 3343 | |
@@ -3352,13 +3352,13 @@ discard block |
||
| 3352 | 3352 | else |
| 3353 | 3353 | { |
| 3354 | 3354 | $this->db->rollback(); |
| 3355 | - dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
| 3355 | + dol_syslog(get_class($this)."::setStatus ".$this->error, LOG_ERR); |
|
| 3356 | 3356 | return -1; |
| 3357 | 3357 | } |
| 3358 | 3358 | } |
| 3359 | 3359 | else |
| 3360 | 3360 | { |
| 3361 | - $this->error=$this->db->lasterror(); |
|
| 3361 | + $this->error = $this->db->lasterror(); |
|
| 3362 | 3362 | $this->db->rollback(); |
| 3363 | 3363 | return -1; |
| 3364 | 3364 | } |
@@ -3372,21 +3372,21 @@ discard block |
||
| 3372 | 3372 | * @param string $ref Record ref |
| 3373 | 3373 | * @return int <0 if KO, 0 if nothing done, >0 if OK |
| 3374 | 3374 | */ |
| 3375 | - function getCanvas($id=0,$ref='') |
|
| 3375 | + function getCanvas($id = 0, $ref = '') |
|
| 3376 | 3376 | { |
| 3377 | 3377 | global $conf; |
| 3378 | 3378 | |
| 3379 | 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. |
|
| 3380 | + if (!empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
| 3381 | 3381 | |
| 3382 | 3382 | // Clean parameters |
| 3383 | 3383 | $ref = trim($ref); |
| 3384 | 3384 | |
| 3385 | 3385 | $sql = "SELECT rowid, canvas"; |
| 3386 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3387 | - $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)."'"; |
|
| 3386 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3387 | + $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)."'"; |
|
| 3390 | 3390 | |
| 3391 | 3391 | $resql = $this->db->query($sql); |
| 3392 | 3392 | if ($resql) |
@@ -3394,7 +3394,7 @@ discard block |
||
| 3394 | 3394 | $obj = $this->db->fetch_object($resql); |
| 3395 | 3395 | if ($obj) |
| 3396 | 3396 | { |
| 3397 | - $this->canvas = $obj->canvas; |
|
| 3397 | + $this->canvas = $obj->canvas; |
|
| 3398 | 3398 | return 1; |
| 3399 | 3399 | } |
| 3400 | 3400 | else return 0; |
@@ -3416,7 +3416,7 @@ discard block |
||
| 3416 | 3416 | function getSpecialCode($lineid) |
| 3417 | 3417 | { |
| 3418 | 3418 | $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 3419 | - $sql.= ' WHERE rowid = '.$lineid; |
|
| 3419 | + $sql .= ' WHERE rowid = '.$lineid; |
|
| 3420 | 3420 | $resql = $this->db->query($sql); |
| 3421 | 3421 | if ($resql) |
| 3422 | 3422 | { |
@@ -3432,14 +3432,14 @@ discard block |
||
| 3432 | 3432 | * @param int $id Force id of object |
| 3433 | 3433 | * @return int <0 if KO, 0 if not used, >0 if already used |
| 3434 | 3434 | */ |
| 3435 | - function isObjectUsed($id=0) |
|
| 3435 | + function isObjectUsed($id = 0) |
|
| 3436 | 3436 | { |
| 3437 | 3437 | global $langs; |
| 3438 | 3438 | |
| 3439 | - if (empty($id)) $id=$this->id; |
|
| 3439 | + if (empty($id)) $id = $this->id; |
|
| 3440 | 3440 | |
| 3441 | 3441 | // Check parameters |
| 3442 | - if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3442 | + if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3443 | 3443 | { |
| 3444 | 3444 | dol_print_error('Called isObjectUsed on a class with property this->childtables not defined'); |
| 3445 | 3445 | return -1; |
@@ -3447,24 +3447,24 @@ discard block |
||
| 3447 | 3447 | |
| 3448 | 3448 | $arraytoscan = $this->childtables; |
| 3449 | 3449 | // For backward compatibility, we check if array is old format array('table1', 'table2', ...) |
| 3450 | - $tmparray=array_keys($this->childtables); |
|
| 3450 | + $tmparray = array_keys($this->childtables); |
|
| 3451 | 3451 | if (is_numeric($tmparray[0])) |
| 3452 | 3452 | { |
| 3453 | 3453 | $arraytoscan = array_flip($this->childtables); |
| 3454 | 3454 | } |
| 3455 | 3455 | |
| 3456 | 3456 | // Test if child exists |
| 3457 | - $haschild=0; |
|
| 3458 | - foreach($arraytoscan as $table => $elementname) |
|
| 3457 | + $haschild = 0; |
|
| 3458 | + foreach ($arraytoscan as $table => $elementname) |
|
| 3459 | 3459 | { |
| 3460 | 3460 | //print $id.'-'.$table.'-'.$elementname.'<br>'; |
| 3461 | 3461 | // Check if third party can be deleted |
| 3462 | 3462 | $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
| 3463 | - $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
| 3464 | - $resql=$this->db->query($sql); |
|
| 3463 | + $sql .= " WHERE ".$this->fk_element." = ".$id; |
|
| 3464 | + $resql = $this->db->query($sql); |
|
| 3465 | 3465 | if ($resql) |
| 3466 | 3466 | { |
| 3467 | - $obj=$this->db->fetch_object($resql); |
|
| 3467 | + $obj = $this->db->fetch_object($resql); |
|
| 3468 | 3468 | if ($obj->nb > 0) |
| 3469 | 3469 | { |
| 3470 | 3470 | $langs->load("errors"); |
@@ -3472,24 +3472,24 @@ discard block |
||
| 3472 | 3472 | $haschild += $obj->nb; |
| 3473 | 3473 | if (is_numeric($elementname)) // old usage |
| 3474 | 3474 | { |
| 3475 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); |
|
| 3475 | + $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); |
|
| 3476 | 3476 | } |
| 3477 | 3477 | else // new usage: $elementname=Translation key |
| 3478 | 3478 | { |
| 3479 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
|
| 3479 | + $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
|
| 3480 | 3480 | } |
| 3481 | - break; // We found at least one, we stop here |
|
| 3481 | + break; // We found at least one, we stop here |
|
| 3482 | 3482 | } |
| 3483 | 3483 | } |
| 3484 | 3484 | else |
| 3485 | 3485 | { |
| 3486 | - $this->errors[]=$this->db->lasterror(); |
|
| 3486 | + $this->errors[] = $this->db->lasterror(); |
|
| 3487 | 3487 | return -1; |
| 3488 | 3488 | } |
| 3489 | 3489 | } |
| 3490 | 3490 | if ($haschild > 0) |
| 3491 | 3491 | { |
| 3492 | - $this->errors[]="ErrorRecordHasChildren"; |
|
| 3492 | + $this->errors[] = "ErrorRecordHasChildren"; |
|
| 3493 | 3493 | return $haschild; |
| 3494 | 3494 | } |
| 3495 | 3495 | else return 0; |
@@ -3501,18 +3501,18 @@ discard block |
||
| 3501 | 3501 | * @param int $predefined -1=All, 0=Count free product/service only, 1=Count predefined product/service only, 2=Count predefined product, 3=Count predefined service |
| 3502 | 3502 | * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
| 3503 | 3503 | */ |
| 3504 | - function hasProductsOrServices($predefined=-1) |
|
| 3504 | + function hasProductsOrServices($predefined = -1) |
|
| 3505 | 3505 | { |
| 3506 | - $nb=0; |
|
| 3506 | + $nb = 0; |
|
| 3507 | 3507 | |
| 3508 | - foreach($this->lines as $key => $val) |
|
| 3508 | + foreach ($this->lines as $key => $val) |
|
| 3509 | 3509 | { |
| 3510 | - $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; |
|
| 3510 | + $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 | 3516 | if ($qualified) $nb++; |
| 3517 | 3517 | } |
| 3518 | 3518 | dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
@@ -3526,24 +3526,24 @@ discard block |
||
| 3526 | 3526 | */ |
| 3527 | 3527 | function getTotalDiscount() |
| 3528 | 3528 | { |
| 3529 | - $total_discount=0.00; |
|
| 3529 | + $total_discount = 0.00; |
|
| 3530 | 3530 | |
| 3531 | 3531 | $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
| 3532 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3533 | - $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3532 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3533 | + $sql .= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3534 | 3534 | |
| 3535 | 3535 | dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
| 3536 | 3536 | $resql = $this->db->query($sql); |
| 3537 | 3537 | if ($resql) |
| 3538 | 3538 | { |
| 3539 | - $num=$this->db->num_rows($resql); |
|
| 3540 | - $i=0; |
|
| 3539 | + $num = $this->db->num_rows($resql); |
|
| 3540 | + $i = 0; |
|
| 3541 | 3541 | while ($i < $num) |
| 3542 | 3542 | { |
| 3543 | 3543 | $obj = $this->db->fetch_object($resql); |
| 3544 | 3544 | |
| 3545 | 3545 | $pu_ht = $obj->pu_ht; |
| 3546 | - $qty= $obj->qty; |
|
| 3546 | + $qty = $obj->qty; |
|
| 3547 | 3547 | $total_ht = $obj->total_ht; |
| 3548 | 3548 | |
| 3549 | 3549 | $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
@@ -3577,17 +3577,17 @@ discard block |
||
| 3577 | 3577 | { |
| 3578 | 3578 | if (isset($line->qty_asked)) |
| 3579 | 3579 | { |
| 3580 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3581 | - $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
| 3580 | + if (empty($totalOrdered)) $totalOrdered = 0; // Avoid warning because $totalOrdered is '' |
|
| 3581 | + $totalOrdered += $line->qty_asked; // defined for shipment only |
|
| 3582 | 3582 | } |
| 3583 | 3583 | if (isset($line->qty_shipped)) |
| 3584 | 3584 | { |
| 3585 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3586 | - $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
| 3587 | - }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3585 | + if (empty($totalToShip)) $totalToShip = 0; // Avoid warning because $totalToShip is '' |
|
| 3586 | + $totalToShip += $line->qty_shipped; // defined for shipment only |
|
| 3587 | + } else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3588 | 3588 | { |
| 3589 | - if (empty($totalToShip)) $totalToShip=0; |
|
| 3590 | - $totalToShip+=$line->qty; // defined for reception only |
|
| 3589 | + if (empty($totalToShip)) $totalToShip = 0; |
|
| 3590 | + $totalToShip += $line->qty; // defined for reception only |
|
| 3591 | 3591 | } |
| 3592 | 3592 | |
| 3593 | 3593 | // Define qty, weight, volume, weight_units, volume_units |
@@ -3600,27 +3600,27 @@ discard block |
||
| 3600 | 3600 | } |
| 3601 | 3601 | |
| 3602 | 3602 | $weight = $line->weight ? $line->weight : 0; |
| 3603 | - ($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0; |
|
| 3603 | + ($weight == 0 && !empty($line->product->weight)) ? $weight = $line->product->weight : 0; |
|
| 3604 | 3604 | $volume = $line->volume ? $line->volume : 0; |
| 3605 | - ($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0; |
|
| 3605 | + ($volume == 0 && !empty($line->product->volume)) ? $volume = $line->product->volume : 0; |
|
| 3606 | 3606 | |
| 3607 | - $weight_units=$line->weight_units; |
|
| 3608 | - ($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0; |
|
| 3609 | - $volume_units=$line->volume_units; |
|
| 3610 | - ($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0; |
|
| 3607 | + $weight_units = $line->weight_units; |
|
| 3608 | + ($weight_units == 0 && !empty($line->product->weight_units)) ? $weight_units = $line->product->weight_units : 0; |
|
| 3609 | + $volume_units = $line->volume_units; |
|
| 3610 | + ($volume_units == 0 && !empty($line->product->volume_units)) ? $volume_units = $line->product->volume_units : 0; |
|
| 3611 | 3611 | |
| 3612 | - $weightUnit=0; |
|
| 3613 | - $volumeUnit=0; |
|
| 3614 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3615 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3612 | + $weightUnit = 0; |
|
| 3613 | + $volumeUnit = 0; |
|
| 3614 | + if (!empty($weight_units)) $weightUnit = $weight_units; |
|
| 3615 | + if (!empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3616 | 3616 | |
| 3617 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3618 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 3617 | + if (empty($totalWeight)) $totalWeight = 0; // Avoid warning because $totalWeight is '' |
|
| 3618 | + if (empty($totalVolume)) $totalVolume = 0; // Avoid warning because $totalVolume is '' |
|
| 3619 | 3619 | |
| 3620 | 3620 | //var_dump($line->volume_units); |
| 3621 | 3621 | if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
| 3622 | 3622 | { |
| 3623 | - $trueWeightUnit=pow(10, $weightUnit); |
|
| 3623 | + $trueWeightUnit = pow(10, $weightUnit); |
|
| 3624 | 3624 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3625 | 3625 | } |
| 3626 | 3626 | else { |
@@ -3634,18 +3634,18 @@ discard block |
||
| 3634 | 3634 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3635 | 3635 | } |
| 3636 | 3636 | else |
| 3637 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3637 | + $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3638 | 3638 | } |
| 3639 | 3639 | if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
| 3640 | 3640 | { |
| 3641 | 3641 | //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
| 3642 | - $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3642 | + $trueVolumeUnit = pow(10, $volumeUnit); |
|
| 3643 | 3643 | //print $line->volume; |
| 3644 | 3644 | $totalVolume += $volume * $qty * $trueVolumeUnit; |
| 3645 | 3645 | } |
| 3646 | 3646 | else |
| 3647 | 3647 | { |
| 3648 | - $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3648 | + $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3649 | 3649 | } |
| 3650 | 3650 | } |
| 3651 | 3651 | |
@@ -3662,17 +3662,17 @@ discard block |
||
| 3662 | 3662 | { |
| 3663 | 3663 | $this->db->begin(); |
| 3664 | 3664 | |
| 3665 | - $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3665 | + $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3666 | 3666 | |
| 3667 | 3667 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 3668 | - $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3669 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 3668 | + $sql .= " SET extraparams = ".(!empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3669 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 3670 | 3670 | |
| 3671 | 3671 | dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
| 3672 | 3672 | $resql = $this->db->query($sql); |
| 3673 | - if (! $resql) |
|
| 3673 | + if (!$resql) |
|
| 3674 | 3674 | { |
| 3675 | - $this->error=$this->db->lasterror(); |
|
| 3675 | + $this->error = $this->db->lasterror(); |
|
| 3676 | 3676 | $this->db->rollback(); |
| 3677 | 3677 | return -1; |
| 3678 | 3678 | } |
@@ -3707,7 +3707,7 @@ discard block |
||
| 3707 | 3707 | } |
| 3708 | 3708 | } |
| 3709 | 3709 | |
| 3710 | - $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
| 3710 | + $out .= (($res->code && $this->location_incoterms) ? ' - ' : '').$this->location_incoterms; |
|
| 3711 | 3711 | |
| 3712 | 3712 | return $out; |
| 3713 | 3713 | } |
@@ -3753,11 +3753,11 @@ discard block |
||
| 3753 | 3753 | if ($this->id && $this->table_element) |
| 3754 | 3754 | { |
| 3755 | 3755 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 3756 | - $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3757 | - $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3758 | - $sql.= " WHERE rowid = " . $this->id; |
|
| 3756 | + $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3757 | + $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3758 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 3759 | 3759 | dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
| 3760 | - $resql=$this->db->query($sql); |
|
| 3760 | + $resql = $this->db->query($sql); |
|
| 3761 | 3761 | if ($resql) |
| 3762 | 3762 | { |
| 3763 | 3763 | $this->fk_incoterms = $id_incoterm; |
@@ -3798,24 +3798,24 @@ discard block |
||
| 3798 | 3798 | */ |
| 3799 | 3799 | function formAddObjectLine($dateSelector, $seller, $buyer) |
| 3800 | 3800 | { |
| 3801 | - global $conf,$user,$langs,$object,$hookmanager; |
|
| 3802 | - global $form,$bcnd,$var; |
|
| 3801 | + global $conf, $user, $langs, $object, $hookmanager; |
|
| 3802 | + global $form, $bcnd, $var; |
|
| 3803 | 3803 | |
| 3804 | 3804 | // Line extrafield |
| 3805 | 3805 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 3806 | 3806 | $extrafieldsline = new ExtraFields($this->db); |
| 3807 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3807 | + $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3808 | 3808 | |
| 3809 | 3809 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 3810 | 3810 | // Use global variables + $dateSelector + $seller and $buyer |
| 3811 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
| 3812 | - foreach($dirtpls as $reldir) |
|
| 3811 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
| 3812 | + foreach ($dirtpls as $reldir) |
|
| 3813 | 3813 | { |
| 3814 | 3814 | $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
| 3815 | 3815 | if (empty($conf->file->strict_mode)) { |
| 3816 | - $res=@include $tpl; |
|
| 3816 | + $res = @include $tpl; |
|
| 3817 | 3817 | } else { |
| 3818 | - $res=include $tpl; // for debug |
|
| 3818 | + $res = include $tpl; // for debug |
|
| 3819 | 3819 | } |
| 3820 | 3820 | if ($res) break; |
| 3821 | 3821 | } |
@@ -3839,24 +3839,24 @@ discard block |
||
| 3839 | 3839 | * @param int $dateSelector 1=Show also date range input fields |
| 3840 | 3840 | * @return void |
| 3841 | 3841 | */ |
| 3842 | - function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
| 3842 | + function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0) |
|
| 3843 | 3843 | { |
| 3844 | 3844 | global $conf, $hookmanager, $langs, $user; |
| 3845 | 3845 | // TODO We should not use global var for this ! |
| 3846 | 3846 | global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
| 3847 | 3847 | |
| 3848 | 3848 | // Define usemargins |
| 3849 | - $usemargins=0; |
|
| 3850 | - if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1; |
|
| 3849 | + $usemargins = 0; |
|
| 3850 | + if (!empty($conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande'))) $usemargins = 1; |
|
| 3851 | 3851 | |
| 3852 | 3852 | $num = count($this->lines); |
| 3853 | 3853 | |
| 3854 | 3854 | // Line extrafield |
| 3855 | 3855 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 3856 | 3856 | $extrafieldsline = new ExtraFields($this->db); |
| 3857 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3857 | + $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3858 | 3858 | |
| 3859 | - $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 3859 | + $parameters = array('num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 3860 | 3860 | $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 3861 | 3861 | if (empty($reshook)) |
| 3862 | 3862 | { |
@@ -3866,7 +3866,7 @@ discard block |
||
| 3866 | 3866 | print '<tr class="liste_titre nodrag nodrop">'; |
| 3867 | 3867 | |
| 3868 | 3868 | // Adds a line numbering column |
| 3869 | - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 3869 | + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 3870 | 3870 | |
| 3871 | 3871 | // Description |
| 3872 | 3872 | print '<td class="linecoldescription">'.$langs->trans('Description').'</td>'; |
@@ -3890,7 +3890,7 @@ discard block |
||
| 3890 | 3890 | // Qty |
| 3891 | 3891 | print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>'; |
| 3892 | 3892 | |
| 3893 | - if($conf->global->PRODUCT_USE_UNITS) |
|
| 3893 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
| 3894 | 3894 | { |
| 3895 | 3895 | print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>'; |
| 3896 | 3896 | } |
@@ -3899,10 +3899,10 @@ discard block |
||
| 3899 | 3899 | print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>'; |
| 3900 | 3900 | |
| 3901 | 3901 | if ($this->situation_cycle_ref) { |
| 3902 | - print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>'; |
|
| 3902 | + print '<td class="linecolcycleref" align="right">'.$langs->trans('Progress').'</td>'; |
|
| 3903 | 3903 | } |
| 3904 | 3904 | |
| 3905 | - if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) |
|
| 3905 | + if ($usemargins && !empty($conf->margin->enabled) && empty($user->societe_id)) |
|
| 3906 | 3906 | { |
| 3907 | 3907 | if (!empty($user->rights->margins->creer)) |
| 3908 | 3908 | { |
@@ -3912,9 +3912,9 @@ discard block |
||
| 3912 | 3912 | print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
| 3913 | 3913 | } |
| 3914 | 3914 | |
| 3915 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3915 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3916 | 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) |
|
| 3917 | + if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3918 | 3918 | print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
| 3919 | 3919 | } |
| 3920 | 3920 | |
@@ -3926,13 +3926,13 @@ discard block |
||
| 3926 | 3926 | |
| 3927 | 3927 | if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
| 3928 | 3928 | |
| 3929 | - print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 3929 | + print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 3930 | 3930 | |
| 3931 | 3931 | print '<td class="linecoldelete" width="10"></td>'; |
| 3932 | 3932 | |
| 3933 | 3933 | print '<td class="linecolmove" width="10"></td>'; |
| 3934 | 3934 | |
| 3935 | - if($action == 'selectlines') |
|
| 3935 | + if ($action == 'selectlines') |
|
| 3936 | 3936 | { |
| 3937 | 3937 | print '<td class="linecolcheckall" align="center">'; |
| 3938 | 3938 | print '<input type="checkbox" class="linecheckboxtoggle" />'; |
@@ -3945,7 +3945,7 @@ discard block |
||
| 3945 | 3945 | } |
| 3946 | 3946 | |
| 3947 | 3947 | $var = true; |
| 3948 | - $i = 0; |
|
| 3948 | + $i = 0; |
|
| 3949 | 3949 | |
| 3950 | 3950 | print "<tbody>\n"; |
| 3951 | 3951 | foreach ($this->lines as $line) |
@@ -3958,18 +3958,18 @@ discard block |
||
| 3958 | 3958 | { |
| 3959 | 3959 | if (empty($line->fk_parent_line)) |
| 3960 | 3960 | { |
| 3961 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 3962 | - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 3961 | + $parameters = array('line'=>$line, 'var'=>$var, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 3962 | + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 3963 | 3963 | } |
| 3964 | 3964 | else |
| 3965 | 3965 | { |
| 3966 | - $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 | - $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 3966 | + $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 | + $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 3968 | 3968 | } |
| 3969 | 3969 | } |
| 3970 | 3970 | if (empty($reshook)) |
| 3971 | 3971 | { |
| 3972 | - $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
| 3972 | + $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline); |
|
| 3973 | 3973 | } |
| 3974 | 3974 | |
| 3975 | 3975 | $i++; |
@@ -3993,23 +3993,23 @@ discard block |
||
| 3993 | 3993 | * @param int $extrafieldsline Object of extrafield line attribute |
| 3994 | 3994 | * @return void |
| 3995 | 3995 | */ |
| 3996 | - function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
| 3996 | + function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0) |
|
| 3997 | 3997 | { |
| 3998 | - global $conf,$langs,$user,$object,$hookmanager; |
|
| 3999 | - global $form,$bc,$bcdd; |
|
| 4000 | - global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
| 3998 | + global $conf, $langs, $user, $object, $hookmanager; |
|
| 3999 | + global $form, $bc, $bcdd; |
|
| 4000 | + global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
| 4001 | 4001 | |
| 4002 | 4002 | $object_rights = $this->getRights(); |
| 4003 | 4003 | |
| 4004 | - $element=$this->element; |
|
| 4004 | + $element = $this->element; |
|
| 4005 | 4005 | |
| 4006 | - $text=''; $description=''; $type=0; |
|
| 4006 | + $text = ''; $description = ''; $type = 0; |
|
| 4007 | 4007 | |
| 4008 | 4008 | // Show product and description |
| 4009 | - $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
| 4009 | + $type = (!empty($line->product_type) ? $line->product_type : $line->fk_product_type); |
|
| 4010 | 4010 | // 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 |
|
| 4011 | + if (!empty($line->date_start)) $type = 1; // deprecated |
|
| 4012 | + if (!empty($line->date_end)) $type = 1; // deprecated |
|
| 4013 | 4013 | |
| 4014 | 4014 | // Ligne en mode visu |
| 4015 | 4015 | if ($action != 'editline' || $selected != $line->id) |
@@ -4022,14 +4022,14 @@ discard block |
||
| 4022 | 4022 | |
| 4023 | 4023 | $product_static->ref = $line->ref; //can change ref in hook |
| 4024 | 4024 | $product_static->label = $line->label; //can change label in hook |
| 4025 | - $text=$product_static->getNomUrl(1); |
|
| 4025 | + $text = $product_static->getNomUrl(1); |
|
| 4026 | 4026 | |
| 4027 | 4027 | // Define output language and label |
| 4028 | - if (! empty($conf->global->MAIN_MULTILANGS)) |
|
| 4028 | + if (!empty($conf->global->MAIN_MULTILANGS)) |
|
| 4029 | 4029 | { |
| 4030 | - if (! is_object($this->thirdparty)) |
|
| 4030 | + if (!is_object($this->thirdparty)) |
|
| 4031 | 4031 | { |
| 4032 | - dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); |
|
| 4032 | + dol_print_error('', 'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); |
|
| 4033 | 4033 | return; |
| 4034 | 4034 | } |
| 4035 | 4035 | |
@@ -4037,38 +4037,38 @@ discard block |
||
| 4037 | 4037 | $prod->fetch($line->fk_product); |
| 4038 | 4038 | |
| 4039 | 4039 | $outputlangs = $langs; |
| 4040 | - $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 |
|
| 4043 | - if (! empty($newlang)) |
|
| 4040 | + $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 |
|
| 4043 | + if (!empty($newlang)) |
|
| 4044 | 4044 | { |
| 4045 | - $outputlangs = new Translate("",$conf); |
|
| 4045 | + $outputlangs = new Translate("", $conf); |
|
| 4046 | 4046 | $outputlangs->setDefaultLang($newlang); |
| 4047 | 4047 | } |
| 4048 | 4048 | |
| 4049 | - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 4049 | + $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 4050 | 4050 | } |
| 4051 | 4051 | else |
| 4052 | 4052 | { |
| 4053 | 4053 | $label = $line->product_label; |
| 4054 | 4054 | } |
| 4055 | 4055 | |
| 4056 | - $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
| 4057 | - $description.=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($line->description)); // Description is what to show on popup. We shown nothing if already into desc. |
|
| 4056 | + $text .= ' - '.(!empty($line->label) ? $line->label : $label); |
|
| 4057 | + $description .= (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($line->description)); // Description is what to show on popup. We shown nothing if already into desc. |
|
| 4058 | 4058 | } |
| 4059 | 4059 | |
| 4060 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4060 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
|
| 4061 | 4061 | |
| 4062 | 4062 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 4063 | 4063 | // Use global variables + $dateSelector + $seller and $buyer |
| 4064 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
| 4065 | - foreach($dirtpls as $reldir) |
|
| 4064 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
| 4065 | + foreach ($dirtpls as $reldir) |
|
| 4066 | 4066 | { |
| 4067 | 4067 | $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
| 4068 | 4068 | if (empty($conf->file->strict_mode)) { |
| 4069 | - $res=@include $tpl; |
|
| 4069 | + $res = @include $tpl; |
|
| 4070 | 4070 | } else { |
| 4071 | - $res=include $tpl; // for debug |
|
| 4071 | + $res = include $tpl; // for debug |
|
| 4072 | 4072 | } |
| 4073 | 4073 | if ($res) break; |
| 4074 | 4074 | } |
@@ -4077,21 +4077,21 @@ discard block |
||
| 4077 | 4077 | // Ligne en mode update |
| 4078 | 4078 | if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
| 4079 | 4079 | { |
| 4080 | - $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 4081 | - $placeholder=' placeholder="'.$langs->trans("Label").'"'; |
|
| 4080 | + $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 4081 | + $placeholder = ' placeholder="'.$langs->trans("Label").'"'; |
|
| 4082 | 4082 | |
| 4083 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4083 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
|
| 4084 | 4084 | |
| 4085 | 4085 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 4086 | 4086 | // Use global variables + $dateSelector + $seller and $buyer |
| 4087 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
| 4088 | - foreach($dirtpls as $reldir) |
|
| 4087 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
| 4088 | + foreach ($dirtpls as $reldir) |
|
| 4089 | 4089 | { |
| 4090 | 4090 | $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
| 4091 | 4091 | if (empty($conf->file->strict_mode)) { |
| 4092 | - $res=@include $tpl; |
|
| 4092 | + $res = @include $tpl; |
|
| 4093 | 4093 | } else { |
| 4094 | - $res=include $tpl; // for debug |
|
| 4094 | + $res = include $tpl; // for debug |
|
| 4095 | 4095 | } |
| 4096 | 4096 | if ($res) break; |
| 4097 | 4097 | } |
@@ -4111,7 +4111,7 @@ discard block |
||
| 4111 | 4111 | * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
| 4112 | 4112 | * @return void |
| 4113 | 4113 | */ |
| 4114 | - function printOriginLinesList($restrictlist='') |
|
| 4114 | + function printOriginLinesList($restrictlist = '') |
|
| 4115 | 4115 | { |
| 4116 | 4116 | global $langs, $hookmanager, $conf; |
| 4117 | 4117 | |
@@ -4122,26 +4122,26 @@ discard block |
||
| 4122 | 4122 | print '<td align="right">'.$langs->trans('PriceUHT').'</td>'; |
| 4123 | 4123 | if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>'; |
| 4124 | 4124 | print '<td align="right">'.$langs->trans('Qty').'</td>'; |
| 4125 | - if($conf->global->PRODUCT_USE_UNITS) |
|
| 4125 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
| 4126 | 4126 | { |
| 4127 | 4127 | print '<td align="left">'.$langs->trans('Unit').'</td>'; |
| 4128 | 4128 | } |
| 4129 | 4129 | print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>'; |
| 4130 | 4130 | |
| 4131 | 4131 | $var = true; |
| 4132 | - $i = 0; |
|
| 4132 | + $i = 0; |
|
| 4133 | 4133 | |
| 4134 | - if (! empty($this->lines)) |
|
| 4134 | + if (!empty($this->lines)) |
|
| 4135 | 4135 | { |
| 4136 | 4136 | foreach ($this->lines as $line) |
| 4137 | 4137 | { |
| 4138 | - if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 4138 | + if (is_object($hookmanager) && (($line->product_type == 9 && !empty($line->special_code)) || !empty($line->fk_parent_line))) |
|
| 4139 | 4139 | { |
| 4140 | 4140 | if (empty($line->fk_parent_line)) |
| 4141 | 4141 | { |
| 4142 | - $parameters=array('line'=>$line,'var'=>$var,'i'=>$i); |
|
| 4143 | - $action=''; |
|
| 4144 | - $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 4142 | + $parameters = array('line'=>$line, 'var'=>$var, 'i'=>$i); |
|
| 4143 | + $action = ''; |
|
| 4144 | + $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 4145 | 4145 | } |
| 4146 | 4146 | } |
| 4147 | 4147 | else |
@@ -4165,103 +4165,103 @@ discard block |
||
| 4165 | 4165 | * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
| 4166 | 4166 | * @return void |
| 4167 | 4167 | */ |
| 4168 | - function printOriginLine($line, $var, $restrictlist='') |
|
| 4168 | + function printOriginLine($line, $var, $restrictlist = '') |
|
| 4169 | 4169 | { |
| 4170 | 4170 | global $langs, $conf; |
| 4171 | 4171 | |
| 4172 | 4172 | //var_dump($line); |
| 4173 | 4173 | if (!empty($line->date_start)) |
| 4174 | 4174 | { |
| 4175 | - $date_start=$line->date_start; |
|
| 4175 | + $date_start = $line->date_start; |
|
| 4176 | 4176 | } |
| 4177 | 4177 | else |
| 4178 | 4178 | { |
| 4179 | - $date_start=$line->date_debut_prevue; |
|
| 4180 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 4179 | + $date_start = $line->date_debut_prevue; |
|
| 4180 | + if ($line->date_debut_reel) $date_start = $line->date_debut_reel; |
|
| 4181 | 4181 | } |
| 4182 | 4182 | if (!empty($line->date_end)) |
| 4183 | 4183 | { |
| 4184 | - $date_end=$line->date_end; |
|
| 4184 | + $date_end = $line->date_end; |
|
| 4185 | 4185 | } |
| 4186 | 4186 | else |
| 4187 | 4187 | { |
| 4188 | - $date_end=$line->date_fin_prevue; |
|
| 4189 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 4188 | + $date_end = $line->date_fin_prevue; |
|
| 4189 | + if ($line->date_fin_reel) $date_end = $line->date_fin_reel; |
|
| 4190 | 4190 | } |
| 4191 | 4191 | |
| 4192 | 4192 | $this->tpl['label'] = ''; |
| 4193 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow'); |
|
| 4193 | + if (!empty($line->fk_parent_line)) $this->tpl['label'] .= img_picto('', 'rightarrow'); |
|
| 4194 | 4194 | |
| 4195 | 4195 | if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
| 4196 | 4196 | { |
| 4197 | - $discount=new DiscountAbsolute($this->db); |
|
| 4197 | + $discount = new DiscountAbsolute($this->db); |
|
| 4198 | 4198 | $discount->fk_soc = $this->socid; |
| 4199 | - $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
| 4199 | + $this->tpl['label'] .= $discount->getNomUrl(0, 'discount'); |
|
| 4200 | 4200 | } |
| 4201 | - else if (! empty($line->fk_product)) |
|
| 4201 | + else if (!empty($line->fk_product)) |
|
| 4202 | 4202 | { |
| 4203 | 4203 | $productstatic = new Product($this->db); |
| 4204 | 4204 | $productstatic->id = $line->fk_product; |
| 4205 | 4205 | $productstatic->ref = $line->ref; |
| 4206 | 4206 | $productstatic->type = $line->fk_product_type; |
| 4207 | - if(empty($productstatic->ref)){ |
|
| 4207 | + if (empty($productstatic->ref)) { |
|
| 4208 | 4208 | $line->fetch_product(); |
| 4209 | 4209 | $productstatic = $line->product; |
| 4210 | 4210 | } |
| 4211 | 4211 | |
| 4212 | - $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
| 4213 | - $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
| 4212 | + $this->tpl['label'] .= $productstatic->getNomUrl(1); |
|
| 4213 | + $this->tpl['label'] .= ' - '.(!empty($line->label) ? $line->label : $line->product_label); |
|
| 4214 | 4214 | // Dates |
| 4215 | 4215 | if ($line->product_type == 1 && ($date_start || $date_end)) |
| 4216 | 4216 | { |
| 4217 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4217 | + $this->tpl['label'] .= get_date_range($date_start, $date_end); |
|
| 4218 | 4218 | } |
| 4219 | 4219 | } |
| 4220 | 4220 | else |
| 4221 | 4221 | { |
| 4222 | - $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'))); |
|
| 4222 | + $this->tpl['label'] .= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''), 'service') : img_object($langs->trans(''), 'product'))); |
|
| 4223 | 4223 | if (!empty($line->desc)) { |
| 4224 | - $this->tpl['label'].=$line->desc; |
|
| 4225 | - }else { |
|
| 4226 | - $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
| 4224 | + $this->tpl['label'] .= $line->desc; |
|
| 4225 | + } else { |
|
| 4226 | + $this->tpl['label'] .= ($line->label ? ' '.$line->label : ''); |
|
| 4227 | 4227 | } |
| 4228 | 4228 | |
| 4229 | 4229 | // Dates |
| 4230 | 4230 | if ($line->product_type == 1 && ($date_start || $date_end)) |
| 4231 | 4231 | { |
| 4232 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4232 | + $this->tpl['label'] .= get_date_range($date_start, $date_end); |
|
| 4233 | 4233 | } |
| 4234 | 4234 | } |
| 4235 | 4235 | |
| 4236 | - if (! empty($line->desc)) |
|
| 4236 | + if (!empty($line->desc)) |
|
| 4237 | 4237 | { |
| 4238 | 4238 | if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
| 4239 | 4239 | { |
| 4240 | - $discount=new DiscountAbsolute($this->db); |
|
| 4240 | + $discount = new DiscountAbsolute($this->db); |
|
| 4241 | 4241 | $discount->fetch($line->fk_remise_except); |
| 4242 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); |
|
| 4242 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0)); |
|
| 4243 | 4243 | } |
| 4244 | 4244 | elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
| 4245 | 4245 | { |
| 4246 | - $discount=new DiscountAbsolute($this->db); |
|
| 4246 | + $discount = new DiscountAbsolute($this->db); |
|
| 4247 | 4247 | $discount->fetch($line->fk_remise_except); |
| 4248 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
|
| 4248 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0)); |
|
| 4249 | 4249 | } |
| 4250 | 4250 | elseif ($line->desc == '(EXCESS RECEIVED)') |
| 4251 | 4251 | { |
| 4252 | - $discount=new DiscountAbsolute($this->db); |
|
| 4252 | + $discount = new DiscountAbsolute($this->db); |
|
| 4253 | 4253 | $discount->fetch($line->fk_remise_except); |
| 4254 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
|
| 4254 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0)); |
|
| 4255 | 4255 | } |
| 4256 | 4256 | elseif ($line->desc == '(EXCESS PAID)') |
| 4257 | 4257 | { |
| 4258 | - $discount=new DiscountAbsolute($this->db); |
|
| 4258 | + $discount = new DiscountAbsolute($this->db); |
|
| 4259 | 4259 | $discount->fetch($line->fk_remise_except); |
| 4260 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0)); |
|
| 4260 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0)); |
|
| 4261 | 4261 | } |
| 4262 | 4262 | else |
| 4263 | 4263 | { |
| 4264 | - $this->tpl['description'] = dol_trunc($line->desc,60); |
|
| 4264 | + $this->tpl['description'] = dol_trunc($line->desc, 60); |
|
| 4265 | 4265 | } |
| 4266 | 4266 | } |
| 4267 | 4267 | else |
@@ -4272,7 +4272,7 @@ discard block |
||
| 4272 | 4272 | // VAT Rate |
| 4273 | 4273 | $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
| 4274 | 4274 | $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.')'; |
|
| 4275 | + if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'] .= ' ('.$line->vat_src_code.')'; |
|
| 4276 | 4276 | |
| 4277 | 4277 | $this->tpl['price'] = price($line->subprice); |
| 4278 | 4278 | $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
@@ -4281,19 +4281,19 @@ discard block |
||
| 4281 | 4281 | $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
| 4282 | 4282 | |
| 4283 | 4283 | // Is the line strike or not |
| 4284 | - $this->tpl['strike']=0; |
|
| 4285 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 4284 | + $this->tpl['strike'] = 0; |
|
| 4285 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike'] = 1; |
|
| 4286 | 4286 | |
| 4287 | 4287 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 4288 | 4288 | // Use global variables + $dateSelector + $seller and $buyer |
| 4289 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
| 4290 | - foreach($dirtpls as $reldir) |
|
| 4289 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
| 4290 | + foreach ($dirtpls as $reldir) |
|
| 4291 | 4291 | { |
| 4292 | 4292 | $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
| 4293 | 4293 | if (empty($conf->file->strict_mode)) { |
| 4294 | - $res=@include $tpl; |
|
| 4294 | + $res = @include $tpl; |
|
| 4295 | 4295 | } else { |
| 4296 | - $res=include $tpl; // for debug |
|
| 4296 | + $res = include $tpl; // for debug |
|
| 4297 | 4297 | } |
| 4298 | 4298 | if ($res) break; |
| 4299 | 4299 | } |
@@ -4311,26 +4311,26 @@ discard block |
||
| 4311 | 4311 | * @param int $mandatory Mandatory or not |
| 4312 | 4312 | * @return int <=0 if KO, >0 if OK |
| 4313 | 4313 | */ |
| 4314 | - function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
| 4314 | + function add_element_resource($resource_id, $resource_type, $busy = 0, $mandatory = 0) |
|
| 4315 | 4315 | { |
| 4316 | 4316 | // phpcs:enable |
| 4317 | 4317 | $this->db->begin(); |
| 4318 | 4318 | |
| 4319 | 4319 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; |
| 4320 | - $sql.= "resource_id"; |
|
| 4321 | - $sql.= ", resource_type"; |
|
| 4322 | - $sql.= ", element_id"; |
|
| 4323 | - $sql.= ", element_type"; |
|
| 4324 | - $sql.= ", busy"; |
|
| 4325 | - $sql.= ", mandatory"; |
|
| 4326 | - $sql.= ") VALUES ("; |
|
| 4327 | - $sql.= $resource_id; |
|
| 4328 | - $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
| 4329 | - $sql.= ", '".$this->db->escape($this->id)."'"; |
|
| 4330 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 4331 | - $sql.= ", '".$this->db->escape($busy)."'"; |
|
| 4332 | - $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
| 4333 | - $sql.= ")"; |
|
| 4320 | + $sql .= "resource_id"; |
|
| 4321 | + $sql .= ", resource_type"; |
|
| 4322 | + $sql .= ", element_id"; |
|
| 4323 | + $sql .= ", element_type"; |
|
| 4324 | + $sql .= ", busy"; |
|
| 4325 | + $sql .= ", mandatory"; |
|
| 4326 | + $sql .= ") VALUES ("; |
|
| 4327 | + $sql .= $resource_id; |
|
| 4328 | + $sql .= ", '".$this->db->escape($resource_type)."'"; |
|
| 4329 | + $sql .= ", '".$this->db->escape($this->id)."'"; |
|
| 4330 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
| 4331 | + $sql .= ", '".$this->db->escape($busy)."'"; |
|
| 4332 | + $sql .= ", '".$this->db->escape($mandatory)."'"; |
|
| 4333 | + $sql .= ")"; |
|
| 4334 | 4334 | |
| 4335 | 4335 | dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
| 4336 | 4336 | if ($this->db->query($sql)) |
@@ -4340,7 +4340,7 @@ discard block |
||
| 4340 | 4340 | } |
| 4341 | 4341 | else |
| 4342 | 4342 | { |
| 4343 | - $this->error=$this->db->lasterror(); |
|
| 4343 | + $this->error = $this->db->lasterror(); |
|
| 4344 | 4344 | $this->db->rollback(); |
| 4345 | 4345 | return 0; |
| 4346 | 4346 | } |
@@ -4355,7 +4355,7 @@ discard block |
||
| 4355 | 4355 | * @param int $notrigger Disable all triggers |
| 4356 | 4356 | * @return int >0 if OK, <0 if KO |
| 4357 | 4357 | */ |
| 4358 | - function delete_resource($rowid, $element, $notrigger=0) |
|
| 4358 | + function delete_resource($rowid, $element, $notrigger = 0) |
|
| 4359 | 4359 | { |
| 4360 | 4360 | // phpcs:enable |
| 4361 | 4361 | global $user; |
@@ -4363,22 +4363,22 @@ discard block |
||
| 4363 | 4363 | $this->db->begin(); |
| 4364 | 4364 | |
| 4365 | 4365 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
| 4366 | - $sql.= " WHERE rowid=".$rowid; |
|
| 4366 | + $sql .= " WHERE rowid=".$rowid; |
|
| 4367 | 4367 | |
| 4368 | 4368 | dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
| 4369 | 4369 | |
| 4370 | - $resql=$this->db->query($sql); |
|
| 4371 | - if (! $resql) |
|
| 4370 | + $resql = $this->db->query($sql); |
|
| 4371 | + if (!$resql) |
|
| 4372 | 4372 | { |
| 4373 | - $this->error=$this->db->lasterror(); |
|
| 4373 | + $this->error = $this->db->lasterror(); |
|
| 4374 | 4374 | $this->db->rollback(); |
| 4375 | 4375 | return -1; |
| 4376 | 4376 | } |
| 4377 | 4377 | else |
| 4378 | 4378 | { |
| 4379 | - if (! $notrigger) |
|
| 4379 | + if (!$notrigger) |
|
| 4380 | 4380 | { |
| 4381 | - $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4381 | + $result = $this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4382 | 4382 | if ($result < 0) { $this->db->rollback(); return -1; } |
| 4383 | 4383 | } |
| 4384 | 4384 | $this->db->commit(); |
@@ -4397,8 +4397,8 @@ discard block |
||
| 4397 | 4397 | // Force a copy of this->lines, otherwise it will point to same object. |
| 4398 | 4398 | if (isset($this->lines) && is_array($this->lines)) |
| 4399 | 4399 | { |
| 4400 | - $nboflines=count($this->lines); |
|
| 4401 | - for($i=0; $i < $nboflines; $i++) |
|
| 4400 | + $nboflines = count($this->lines); |
|
| 4401 | + for ($i = 0; $i < $nboflines; $i++) |
|
| 4402 | 4402 | { |
| 4403 | 4403 | $this->lines[$i] = clone $this->lines[$i]; |
| 4404 | 4404 | } |
@@ -4418,43 +4418,43 @@ discard block |
||
| 4418 | 4418 | * @return int >0 if OK, <0 if KO |
| 4419 | 4419 | * @see addFileIntoDatabaseIndex |
| 4420 | 4420 | */ |
| 4421 | - protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
| 4421 | + protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams = null) |
|
| 4422 | 4422 | { |
| 4423 | 4423 | global $conf, $langs, $user; |
| 4424 | 4424 | |
| 4425 | - $srctemplatepath=''; |
|
| 4425 | + $srctemplatepath = ''; |
|
| 4426 | 4426 | |
| 4427 | 4427 | // Increase limit for PDF build |
| 4428 | - $err=error_reporting(); |
|
| 4428 | + $err = error_reporting(); |
|
| 4429 | 4429 | error_reporting(0); |
| 4430 | 4430 | @set_time_limit(120); |
| 4431 | 4431 | error_reporting($err); |
| 4432 | 4432 | |
| 4433 | 4433 | // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
| 4434 | - $tmp=explode(':',$modele,2); |
|
| 4435 | - if (! empty($tmp[1])) |
|
| 4434 | + $tmp = explode(':', $modele, 2); |
|
| 4435 | + if (!empty($tmp[1])) |
|
| 4436 | 4436 | { |
| 4437 | - $modele=$tmp[0]; |
|
| 4438 | - $srctemplatepath=$tmp[1]; |
|
| 4437 | + $modele = $tmp[0]; |
|
| 4438 | + $srctemplatepath = $tmp[1]; |
|
| 4439 | 4439 | } |
| 4440 | 4440 | |
| 4441 | 4441 | // Search template files |
| 4442 | - $file=''; $classname=''; $filefound=0; |
|
| 4443 | - $dirmodels=array('/'); |
|
| 4444 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
| 4445 | - foreach($dirmodels as $reldir) |
|
| 4442 | + $file = ''; $classname = ''; $filefound = 0; |
|
| 4443 | + $dirmodels = array('/'); |
|
| 4444 | + if (is_array($conf->modules_parts['models'])) $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); |
|
| 4445 | + foreach ($dirmodels as $reldir) |
|
| 4446 | 4446 | { |
| 4447 | - foreach(array('doc','pdf') as $prefix) |
|
| 4447 | + foreach (array('doc', 'pdf') as $prefix) |
|
| 4448 | 4448 | { |
| 4449 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
| 4449 | + if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
| 4450 | 4450 | else $file = $prefix."_".$modele.".modules.php"; |
| 4451 | 4451 | |
| 4452 | 4452 | // On verifie l'emplacement du modele |
| 4453 | - $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
| 4453 | + $file = dol_buildpath($reldir.$modelspath.$file, 0); |
|
| 4454 | 4454 | if (file_exists($file)) |
| 4455 | 4455 | { |
| 4456 | - $filefound=1; |
|
| 4457 | - $classname=$prefix.'_'.$modele; |
|
| 4456 | + $filefound = 1; |
|
| 4457 | + $classname = $prefix.'_'.$modele; |
|
| 4458 | 4458 | break; |
| 4459 | 4459 | } |
| 4460 | 4460 | } |
@@ -4464,7 +4464,7 @@ discard block |
||
| 4464 | 4464 | // If generator was found |
| 4465 | 4465 | if ($filefound) |
| 4466 | 4466 | { |
| 4467 | - global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 4467 | + global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 4468 | 4468 | |
| 4469 | 4469 | require_once $file; |
| 4470 | 4470 | |
@@ -4473,32 +4473,32 @@ discard block |
||
| 4473 | 4473 | // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
| 4474 | 4474 | if ($obj->type == 'odt' && empty($srctemplatepath)) |
| 4475 | 4475 | { |
| 4476 | - $varfortemplatedir=$obj->scandir; |
|
| 4477 | - if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) |
|
| 4476 | + $varfortemplatedir = $obj->scandir; |
|
| 4477 | + if ($varfortemplatedir && !empty($conf->global->$varfortemplatedir)) |
|
| 4478 | 4478 | { |
| 4479 | - $dirtoscan=$conf->global->$varfortemplatedir; |
|
| 4479 | + $dirtoscan = $conf->global->$varfortemplatedir; |
|
| 4480 | 4480 | |
| 4481 | - $listoffiles=array(); |
|
| 4481 | + $listoffiles = array(); |
|
| 4482 | 4482 | |
| 4483 | 4483 | // Now we add first model found in directories scanned |
| 4484 | - $listofdir=explode(',',$dirtoscan); |
|
| 4485 | - foreach($listofdir as $key => $tmpdir) |
|
| 4484 | + $listofdir = explode(',', $dirtoscan); |
|
| 4485 | + foreach ($listofdir as $key => $tmpdir) |
|
| 4486 | 4486 | { |
| 4487 | - $tmpdir=trim($tmpdir); |
|
| 4488 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
| 4489 | - if (! $tmpdir) { unset($listofdir[$key]); continue; } |
|
| 4487 | + $tmpdir = trim($tmpdir); |
|
| 4488 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
| 4489 | + if (!$tmpdir) { unset($listofdir[$key]); continue; } |
|
| 4490 | 4490 | if (is_dir($tmpdir)) |
| 4491 | 4491 | { |
| 4492 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
| 4493 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4492 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.od(s|t)$', '', 'name', SORT_ASC, 0); |
|
| 4493 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
| 4494 | 4494 | } |
| 4495 | 4495 | } |
| 4496 | 4496 | |
| 4497 | 4497 | if (count($listoffiles)) |
| 4498 | 4498 | { |
| 4499 | - foreach($listoffiles as $record) |
|
| 4499 | + foreach ($listoffiles as $record) |
|
| 4500 | 4500 | { |
| 4501 | - $srctemplatepath=$record['fullname']; |
|
| 4501 | + $srctemplatepath = $record['fullname']; |
|
| 4502 | 4502 | break; |
| 4503 | 4503 | } |
| 4504 | 4504 | } |
@@ -4506,27 +4506,27 @@ discard block |
||
| 4506 | 4506 | |
| 4507 | 4507 | if (empty($srctemplatepath)) |
| 4508 | 4508 | { |
| 4509 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4509 | + $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4510 | 4510 | return -1; |
| 4511 | 4511 | } |
| 4512 | 4512 | } |
| 4513 | 4513 | |
| 4514 | - if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
| 4514 | + if ($obj->type == 'odt' && !empty($srctemplatepath)) |
|
| 4515 | 4515 | { |
| 4516 | - if (! dol_is_file($srctemplatepath)) |
|
| 4516 | + if (!dol_is_file($srctemplatepath)) |
|
| 4517 | 4517 | { |
| 4518 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4518 | + $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4519 | 4519 | return -1; |
| 4520 | 4520 | } |
| 4521 | 4521 | } |
| 4522 | 4522 | |
| 4523 | 4523 | // We save charset_output to restore it because write_file can change it if needed for |
| 4524 | 4524 | // output format that does not support UTF8. |
| 4525 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 4525 | + $sav_charset_output = $outputlangs->charset_output; |
|
| 4526 | 4526 | |
| 4527 | 4527 | if (in_array(get_class($this), array('Adherent'))) |
| 4528 | 4528 | { |
| 4529 | - $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4529 | + $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4530 | 4530 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
| 4531 | 4531 | } |
| 4532 | 4532 | else |
@@ -4537,41 +4537,41 @@ discard block |
||
| 4537 | 4537 | |
| 4538 | 4538 | if ($resultwritefile > 0) |
| 4539 | 4539 | { |
| 4540 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 4540 | + $outputlangs->charset_output = $sav_charset_output; |
|
| 4541 | 4541 | |
| 4542 | 4542 | // We delete old preview |
| 4543 | 4543 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 4544 | 4544 | dol_delete_preview($this); |
| 4545 | 4545 | |
| 4546 | 4546 | // Index file in database |
| 4547 | - if (! empty($obj->result['fullpath'])) |
|
| 4547 | + if (!empty($obj->result['fullpath'])) |
|
| 4548 | 4548 | { |
| 4549 | 4549 | $destfull = $obj->result['fullpath']; |
| 4550 | 4550 | $upload_dir = dirname($destfull); |
| 4551 | 4551 | $destfile = basename($destfull); |
| 4552 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); |
|
| 4552 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir); |
|
| 4553 | 4553 | |
| 4554 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 4554 | + if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 4555 | 4555 | { |
| 4556 | 4556 | $filename = basename($destfile); |
| 4557 | 4557 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
| 4558 | 4558 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
| 4559 | 4559 | |
| 4560 | 4560 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 4561 | - $ecmfile=new EcmFiles($this->db); |
|
| 4562 | - $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
| 4561 | + $ecmfile = new EcmFiles($this->db); |
|
| 4562 | + $result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir.'/' : '').$filename); |
|
| 4563 | 4563 | |
| 4564 | 4564 | // Set the public "share" key |
| 4565 | 4565 | $setsharekey = false; |
| 4566 | 4566 | if ($this->element == 'propal') |
| 4567 | 4567 | { |
| 4568 | - $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; |
|
| 4568 | + $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; |
|
| 4571 | 4571 | } |
| 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; |
|
| 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 | 4575 | |
| 4576 | 4576 | if ($setsharekey) |
| 4577 | 4577 | { |
@@ -4584,11 +4584,11 @@ discard block |
||
| 4584 | 4584 | |
| 4585 | 4585 | if ($result > 0) |
| 4586 | 4586 | { |
| 4587 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4587 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4588 | 4588 | $ecmfile->fullpath_orig = ''; |
| 4589 | 4589 | $ecmfile->gen_or_uploaded = 'generated'; |
| 4590 | - $ecmfile->description = ''; // indexed content |
|
| 4591 | - $ecmfile->keyword = ''; // keyword content |
|
| 4590 | + $ecmfile->description = ''; // indexed content |
|
| 4591 | + $ecmfile->keyword = ''; // keyword content |
|
| 4592 | 4592 | $result = $ecmfile->update($user); |
| 4593 | 4593 | if ($result < 0) |
| 4594 | 4594 | { |
@@ -4600,11 +4600,11 @@ discard block |
||
| 4600 | 4600 | $ecmfile->entity = $conf->entity; |
| 4601 | 4601 | $ecmfile->filepath = $rel_dir; |
| 4602 | 4602 | $ecmfile->filename = $filename; |
| 4603 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4603 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4604 | 4604 | $ecmfile->fullpath_orig = ''; |
| 4605 | 4605 | $ecmfile->gen_or_uploaded = 'generated'; |
| 4606 | - $ecmfile->description = ''; // indexed content |
|
| 4607 | - $ecmfile->keyword = ''; // keyword content |
|
| 4606 | + $ecmfile->description = ''; // indexed content |
|
| 4607 | + $ecmfile->keyword = ''; // keyword content |
|
| 4608 | 4608 | $ecmfile->src_object_type = $this->table_element; |
| 4609 | 4609 | $ecmfile->src_object_id = $this->id; |
| 4610 | 4610 | |
@@ -4621,14 +4621,14 @@ discard block |
||
| 4621 | 4621 | //var_dump($obj->update_main_doc_field);exit; |
| 4622 | 4622 | |
| 4623 | 4623 | // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
| 4624 | - $update_main_doc_field=0; |
|
| 4625 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 4626 | - if ($update_main_doc_field && ! empty($this->table_element)) |
|
| 4624 | + $update_main_doc_field = 0; |
|
| 4625 | + if (!empty($obj->update_main_doc_field)) $update_main_doc_field = 1; |
|
| 4626 | + if ($update_main_doc_field && !empty($this->table_element)) |
|
| 4627 | 4627 | { |
| 4628 | 4628 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
| 4629 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 4629 | + $sql .= ' WHERE rowid = '.$this->id; |
|
| 4630 | 4630 | $resql = $this->db->query($sql); |
| 4631 | - if (! $resql) dol_print_error($this->db); |
|
| 4631 | + if (!$resql) dol_print_error($this->db); |
|
| 4632 | 4632 | } |
| 4633 | 4633 | } |
| 4634 | 4634 | } |
@@ -4644,15 +4644,15 @@ discard block |
||
| 4644 | 4644 | } |
| 4645 | 4645 | else |
| 4646 | 4646 | { |
| 4647 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 4647 | + $outputlangs->charset_output = $sav_charset_output; |
|
| 4648 | 4648 | dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
| 4649 | 4649 | return -1; |
| 4650 | 4650 | } |
| 4651 | 4651 | } |
| 4652 | 4652 | else |
| 4653 | 4653 | { |
| 4654 | - $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
|
| 4655 | - dol_print_error('',$this->error); |
|
| 4654 | + $this->error = $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file); |
|
| 4655 | + dol_print_error('', $this->error); |
|
| 4656 | 4656 | return -1; |
| 4657 | 4657 | } |
| 4658 | 4658 | } |
@@ -4668,9 +4668,9 @@ discard block |
||
| 4668 | 4668 | { |
| 4669 | 4669 | global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
| 4670 | 4670 | |
| 4671 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4671 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4672 | 4672 | |
| 4673 | - $file_osencoded=dol_osencode($file); |
|
| 4673 | + $file_osencoded = dol_osencode($file); |
|
| 4674 | 4674 | if (file_exists($file_osencoded)) |
| 4675 | 4675 | { |
| 4676 | 4676 | // Create small thumbs for company (Ratio is near 16/9) |
@@ -4700,7 +4700,7 @@ discard block |
||
| 4700 | 4700 | * @param string $alternatevalue Alternate value to use |
| 4701 | 4701 | * @return string|string[] Default value (can be an array if the GETPOST return an array) |
| 4702 | 4702 | **/ |
| 4703 | - function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
| 4703 | + function getDefaultCreateValueFor($fieldname, $alternatevalue = null) |
|
| 4704 | 4704 | { |
| 4705 | 4705 | global $conf, $_POST; |
| 4706 | 4706 | |
@@ -4709,16 +4709,16 @@ discard block |
||
| 4709 | 4709 | |
| 4710 | 4710 | if (isset($alternatevalue)) return $alternatevalue; |
| 4711 | 4711 | |
| 4712 | - $newelement=$this->element; |
|
| 4713 | - if ($newelement == 'facture') $newelement='invoice'; |
|
| 4714 | - if ($newelement == 'commande') $newelement='order'; |
|
| 4712 | + $newelement = $this->element; |
|
| 4713 | + if ($newelement == 'facture') $newelement = 'invoice'; |
|
| 4714 | + if ($newelement == 'commande') $newelement = 'order'; |
|
| 4715 | 4715 | if (empty($newelement)) |
| 4716 | 4716 | { |
| 4717 | 4717 | dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING); |
| 4718 | 4718 | return ''; |
| 4719 | 4719 | } |
| 4720 | 4720 | |
| 4721 | - $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4721 | + $keyforfieldname = strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4722 | 4722 | //var_dump($keyforfieldname); |
| 4723 | 4723 | if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
| 4724 | 4724 | |
@@ -4743,21 +4743,21 @@ discard block |
||
| 4743 | 4743 | function call_trigger($trigger_name, $user) |
| 4744 | 4744 | { |
| 4745 | 4745 | // phpcs:enable |
| 4746 | - global $langs,$conf; |
|
| 4746 | + global $langs, $conf; |
|
| 4747 | 4747 | |
| 4748 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 4749 | - $interface=new Interfaces($this->db); |
|
| 4750 | - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
| 4748 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
| 4749 | + $interface = new Interfaces($this->db); |
|
| 4750 | + $result = $interface->run_triggers($trigger_name, $this, $user, $langs, $conf); |
|
| 4751 | 4751 | |
| 4752 | 4752 | if ($result < 0) |
| 4753 | 4753 | { |
| 4754 | 4754 | if (!empty($this->errors)) |
| 4755 | 4755 | { |
| 4756 | - $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. |
|
| 4756 | + $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 | 4757 | } |
| 4758 | 4758 | else |
| 4759 | 4759 | { |
| 4760 | - $this->errors=$interface->errors; |
|
| 4760 | + $this->errors = $interface->errors; |
|
| 4761 | 4761 | } |
| 4762 | 4762 | } |
| 4763 | 4763 | return $result; |
@@ -4776,19 +4776,19 @@ discard block |
||
| 4776 | 4776 | * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
| 4777 | 4777 | * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
| 4778 | 4778 | */ |
| 4779 | - function fetch_optionals($rowid=null, $optionsArray=null) |
|
| 4779 | + function fetch_optionals($rowid = null, $optionsArray = null) |
|
| 4780 | 4780 | { |
| 4781 | 4781 | // phpcs:enable |
| 4782 | - if (empty($rowid)) $rowid=$this->id; |
|
| 4782 | + if (empty($rowid)) $rowid = $this->id; |
|
| 4783 | 4783 | |
| 4784 | 4784 | // To avoid SQL errors. Probably not the better solution though |
| 4785 | 4785 | if (!$this->table_element) { |
| 4786 | 4786 | return 0; |
| 4787 | 4787 | } |
| 4788 | 4788 | |
| 4789 | - $this->array_options=array(); |
|
| 4789 | + $this->array_options = array(); |
|
| 4790 | 4790 | |
| 4791 | - if (! is_array($optionsArray)) |
|
| 4791 | + if (!is_array($optionsArray)) |
|
| 4792 | 4792 | { |
| 4793 | 4793 | // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
| 4794 | 4794 | // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
@@ -4804,7 +4804,7 @@ discard block |
||
| 4804 | 4804 | { |
| 4805 | 4805 | $extrafields->fetch_name_optionals_label($this->table_element); |
| 4806 | 4806 | } |
| 4807 | - $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
|
| 4807 | + $optionsArray = (!empty($extrafields->attributes[$this->table_element]['label']) ? $extrafields->attributes[$this->table_element]['label'] : null); |
|
| 4808 | 4808 | } |
| 4809 | 4809 | else |
| 4810 | 4810 | { |
@@ -4823,18 +4823,18 @@ discard block |
||
| 4823 | 4823 | { |
| 4824 | 4824 | if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
| 4825 | 4825 | { |
| 4826 | - $sql.= ", ".$name; |
|
| 4826 | + $sql .= ", ".$name; |
|
| 4827 | 4827 | } |
| 4828 | 4828 | } |
| 4829 | - $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4830 | - $sql.= " WHERE fk_object = ".$rowid; |
|
| 4829 | + $sql .= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4830 | + $sql .= " WHERE fk_object = ".$rowid; |
|
| 4831 | 4831 | |
| 4832 | 4832 | //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
| 4833 | - $resql=$this->db->query($sql); |
|
| 4833 | + $resql = $this->db->query($sql); |
|
| 4834 | 4834 | if ($resql) |
| 4835 | 4835 | { |
| 4836 | 4836 | $this->array_options = array(); |
| 4837 | - $numrows=$this->db->num_rows($resql); |
|
| 4837 | + $numrows = $this->db->num_rows($resql); |
|
| 4838 | 4838 | if ($numrows) |
| 4839 | 4839 | { |
| 4840 | 4840 | $tab = $this->db->fetch_array($resql); |
@@ -4842,17 +4842,17 @@ discard block |
||
| 4842 | 4842 | foreach ($tab as $key => $value) |
| 4843 | 4843 | { |
| 4844 | 4844 | // Test fetch_array ! is_int($key) because fetch_array result is a mix table with Key as alpha and Key as int (depend db engine) |
| 4845 | - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
| 4845 | + if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && !is_int($key)) |
|
| 4846 | 4846 | { |
| 4847 | 4847 | // we can add this attribute to object |
| 4848 | - if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime'))) |
|
| 4848 | + if (!empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime'))) |
|
| 4849 | 4849 | { |
| 4850 | 4850 | //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
| 4851 | - $this->array_options["options_".$key]=$this->db->jdate($value); |
|
| 4851 | + $this->array_options["options_".$key] = $this->db->jdate($value); |
|
| 4852 | 4852 | } |
| 4853 | 4853 | else |
| 4854 | 4854 | { |
| 4855 | - $this->array_options["options_".$key]=$value; |
|
| 4855 | + $this->array_options["options_".$key] = $value; |
|
| 4856 | 4856 | } |
| 4857 | 4857 | |
| 4858 | 4858 | //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]); |
@@ -4888,10 +4888,10 @@ discard block |
||
| 4888 | 4888 | |
| 4889 | 4889 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
| 4890 | 4890 | dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
| 4891 | - $resql=$this->db->query($sql_del); |
|
| 4892 | - if (! $resql) |
|
| 4891 | + $resql = $this->db->query($sql_del); |
|
| 4892 | + if (!$resql) |
|
| 4893 | 4893 | { |
| 4894 | - $this->error=$this->db->lasterror(); |
|
| 4894 | + $this->error = $this->db->lasterror(); |
|
| 4895 | 4895 | $this->db->rollback(); |
| 4896 | 4896 | return -1; |
| 4897 | 4897 | } |
@@ -4912,36 +4912,36 @@ discard block |
||
| 4912 | 4912 | * @return int -1=error, O=did nothing, 1=OK |
| 4913 | 4913 | * @see updateExtraField, setValueFrom |
| 4914 | 4914 | */ |
| 4915 | - function insertExtraFields($trigger='', $userused=null) |
|
| 4915 | + function insertExtraFields($trigger = '', $userused = null) |
|
| 4916 | 4916 | { |
| 4917 | - global $conf,$langs,$user; |
|
| 4917 | + global $conf, $langs, $user; |
|
| 4918 | 4918 | |
| 4919 | - if (empty($userused)) $userused=$user; |
|
| 4919 | + if (empty($userused)) $userused = $user; |
|
| 4920 | 4920 | |
| 4921 | - $error=0; |
|
| 4921 | + $error = 0; |
|
| 4922 | 4922 | |
| 4923 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4923 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4924 | 4924 | |
| 4925 | - if (! empty($this->array_options)) |
|
| 4925 | + if (!empty($this->array_options)) |
|
| 4926 | 4926 | { |
| 4927 | 4927 | // Check parameters |
| 4928 | 4928 | $langs->load('admin'); |
| 4929 | 4929 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 4930 | 4930 | $extrafields = new ExtraFields($this->db); |
| 4931 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4931 | + $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4932 | 4932 | |
| 4933 | 4933 | //Eliminate copied source object extra_fields that do not exist in target object |
| 4934 | - $new_array_options=array(); |
|
| 4934 | + $new_array_options = array(); |
|
| 4935 | 4935 | 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 |
|
| 4936 | + if (in_array(substr($key, 8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4937 | 4937 | $new_array_options[$key] = $value; |
| 4938 | 4938 | elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
| 4939 | 4939 | $new_array_options['options_'.$key] = $value; |
| 4940 | 4940 | } |
| 4941 | 4941 | |
| 4942 | - foreach($new_array_options as $key => $value) |
|
| 4942 | + foreach ($new_array_options as $key => $value) |
|
| 4943 | 4943 | { |
| 4944 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 4944 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
| 4945 | 4945 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
| 4946 | 4946 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
| 4947 | 4947 | $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
@@ -4949,13 +4949,13 @@ discard block |
||
| 4949 | 4949 | |
| 4950 | 4950 | if ($attributeRequired) |
| 4951 | 4951 | { |
| 4952 | - $mandatorypb=false; |
|
| 4953 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4954 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 4952 | + $mandatorypb = false; |
|
| 4953 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb = true; |
|
| 4954 | + if ($this->array_options[$key] === '') $mandatorypb = true; |
|
| 4955 | 4955 | if ($mandatorypb) |
| 4956 | 4956 | { |
| 4957 | 4957 | dol_syslog($this->error); |
| 4958 | - $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel); |
|
| 4958 | + $this->errors[] = $langs->trans('ErrorFieldRequired', $attributeLabel); |
|
| 4959 | 4959 | return -1; |
| 4960 | 4960 | } |
| 4961 | 4961 | } |
@@ -4966,25 +4966,25 @@ discard block |
||
| 4966 | 4966 | switch ($attributeType) |
| 4967 | 4967 | { |
| 4968 | 4968 | case 'int': |
| 4969 | - if (!is_numeric($value) && $value!='') |
|
| 4969 | + if (!is_numeric($value) && $value != '') |
|
| 4970 | 4970 | { |
| 4971 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 4971 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 4972 | 4972 | return -1; |
| 4973 | 4973 | } |
| 4974 | - elseif ($value=='') |
|
| 4974 | + elseif ($value == '') |
|
| 4975 | 4975 | { |
| 4976 | 4976 | $new_array_options[$key] = null; |
| 4977 | 4977 | } |
| 4978 | 4978 | break; |
| 4979 | 4979 | case 'double': |
| 4980 | 4980 | $value = price2num($value); |
| 4981 | - if (!is_numeric($value) && $value!='') |
|
| 4981 | + if (!is_numeric($value) && $value != '') |
|
| 4982 | 4982 | { |
| 4983 | 4983 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
| 4984 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 4984 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 4985 | 4985 | return -1; |
| 4986 | 4986 | } |
| 4987 | - elseif ($value=='') |
|
| 4987 | + elseif ($value == '') |
|
| 4988 | 4988 | { |
| 4989 | 4989 | $new_array_options[$key] = null; |
| 4990 | 4990 | } |
@@ -4998,12 +4998,12 @@ discard block |
||
| 4998 | 4998 | } |
| 4999 | 4999 | break;*/ |
| 5000 | 5000 | case 'password': |
| 5001 | - $algo=''; |
|
| 5001 | + $algo = ''; |
|
| 5002 | 5002 | if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
| 5003 | 5003 | { |
| 5004 | 5004 | // If there is an encryption choice, we use it to crypt data before insert |
| 5005 | 5005 | $tmparrays = array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options']); |
| 5006 | - $algo=reset($tmparrays); |
|
| 5006 | + $algo = reset($tmparrays); |
|
| 5007 | 5007 | if ($algo != '') |
| 5008 | 5008 | { |
| 5009 | 5009 | //global $action; // $action may be 'create', 'update', 'update_extras'... |
@@ -5014,7 +5014,7 @@ discard block |
||
| 5014 | 5014 | //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
| 5015 | 5015 | 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 | 5016 | { |
| 5017 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5017 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5018 | 5018 | } |
| 5019 | 5019 | else |
| 5020 | 5020 | { |
@@ -5025,7 +5025,7 @@ discard block |
||
| 5025 | 5025 | } |
| 5026 | 5026 | else |
| 5027 | 5027 | { |
| 5028 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5028 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5029 | 5029 | } |
| 5030 | 5030 | } |
| 5031 | 5031 | } |
@@ -5042,13 +5042,13 @@ discard block |
||
| 5042 | 5042 | break; |
| 5043 | 5043 | case 'datetime': |
| 5044 | 5044 | // If data is a string instead of a timestamp, we convert it |
| 5045 | - if (! is_int($this->array_options[$key])) { |
|
| 5045 | + if (!is_int($this->array_options[$key])) { |
|
| 5046 | 5046 | $this->array_options[$key] = strtotime($this->array_options[$key]); |
| 5047 | 5047 | } |
| 5048 | 5048 | $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
| 5049 | 5049 | break; |
| 5050 | 5050 | case 'link': |
| 5051 | - $param_list=array_keys($attributeParam['options']); |
|
| 5051 | + $param_list = array_keys($attributeParam['options']); |
|
| 5052 | 5052 | // 0 : ObjectName |
| 5053 | 5053 | // 1 : classPath |
| 5054 | 5054 | $InfoFieldList = explode(":", $param_list[0]); |
@@ -5057,18 +5057,18 @@ discard block |
||
| 5057 | 5057 | { |
| 5058 | 5058 | if ($value == '-1') // -1 is key for no defined in combo list of objects |
| 5059 | 5059 | { |
| 5060 | - $new_array_options[$key]=''; |
|
| 5060 | + $new_array_options[$key] = ''; |
|
| 5061 | 5061 | } |
| 5062 | 5062 | elseif ($value) |
| 5063 | 5063 | { |
| 5064 | 5064 | $object = new $InfoFieldList[0]($this->db); |
| 5065 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
| 5066 | - else $res=$object->fetch('',$value); |
|
| 5065 | + if (is_numeric($value)) $res = $object->fetch($value); |
|
| 5066 | + else $res = $object->fetch('', $value); |
|
| 5067 | 5067 | |
| 5068 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 5068 | + if ($res > 0) $new_array_options[$key] = $object->id; |
|
| 5069 | 5069 | else |
| 5070 | 5070 | { |
| 5071 | - $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 5071 | + $this->error = "Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 5072 | 5072 | $this->db->rollback(); |
| 5073 | 5073 | return -1; |
| 5074 | 5074 | } |
@@ -5092,46 +5092,46 @@ discard block |
||
| 5092 | 5092 | $this->db->query($sql_del); |
| 5093 | 5093 | |
| 5094 | 5094 | $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
| 5095 | - foreach($new_array_options as $key => $value) |
|
| 5095 | + foreach ($new_array_options as $key => $value) |
|
| 5096 | 5096 | { |
| 5097 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5097 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
| 5098 | 5098 | // Add field of attribut |
| 5099 | 5099 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
| 5100 | - $sql.=",".$attributeKey; |
|
| 5100 | + $sql .= ",".$attributeKey; |
|
| 5101 | 5101 | } |
| 5102 | 5102 | $sql .= ") VALUES (".$this->id; |
| 5103 | 5103 | |
| 5104 | - foreach($new_array_options as $key => $value) |
|
| 5104 | + foreach ($new_array_options as $key => $value) |
|
| 5105 | 5105 | { |
| 5106 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5106 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
| 5107 | 5107 | // Add field of attribute |
| 5108 | 5108 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
| 5109 | 5109 | { |
| 5110 | 5110 | if ($new_array_options[$key] != '') |
| 5111 | 5111 | { |
| 5112 | - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5112 | + $sql .= ",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5113 | 5113 | } |
| 5114 | 5114 | else |
| 5115 | 5115 | { |
| 5116 | - $sql.=",null"; |
|
| 5116 | + $sql .= ",null"; |
|
| 5117 | 5117 | } |
| 5118 | 5118 | } |
| 5119 | 5119 | } |
| 5120 | - $sql.=")"; |
|
| 5120 | + $sql .= ")"; |
|
| 5121 | 5121 | |
| 5122 | 5122 | dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
| 5123 | 5123 | $resql = $this->db->query($sql); |
| 5124 | - if (! $resql) |
|
| 5124 | + if (!$resql) |
|
| 5125 | 5125 | { |
| 5126 | - $this->error=$this->db->lasterror(); |
|
| 5126 | + $this->error = $this->db->lasterror(); |
|
| 5127 | 5127 | $error++; |
| 5128 | 5128 | } |
| 5129 | 5129 | |
| 5130 | - if (! $error && $trigger) |
|
| 5130 | + if (!$error && $trigger) |
|
| 5131 | 5131 | { |
| 5132 | 5132 | // Call trigger |
| 5133 | - $this->context=array('extrafieldaddupdate'=>1); |
|
| 5134 | - $result=$this->call_trigger($trigger, $userused); |
|
| 5133 | + $this->context = array('extrafieldaddupdate'=>1); |
|
| 5134 | + $result = $this->call_trigger($trigger, $userused); |
|
| 5135 | 5135 | if ($result < 0) $error++; |
| 5136 | 5136 | // End call trigger |
| 5137 | 5137 | } |
@@ -5160,25 +5160,25 @@ discard block |
||
| 5160 | 5160 | * @return int -1=error, O=did nothing, 1=OK |
| 5161 | 5161 | * @see setValueFrom, insertExtraFields |
| 5162 | 5162 | */ |
| 5163 | - function updateExtraField($key, $trigger=null, $userused=null) |
|
| 5163 | + function updateExtraField($key, $trigger = null, $userused = null) |
|
| 5164 | 5164 | { |
| 5165 | - global $conf,$langs,$user; |
|
| 5165 | + global $conf, $langs, $user; |
|
| 5166 | 5166 | |
| 5167 | - if (empty($userused)) $userused=$user; |
|
| 5167 | + if (empty($userused)) $userused = $user; |
|
| 5168 | 5168 | |
| 5169 | - $error=0; |
|
| 5169 | + $error = 0; |
|
| 5170 | 5170 | |
| 5171 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5171 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5172 | 5172 | |
| 5173 | - if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 5173 | + if (!empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 5174 | 5174 | { |
| 5175 | 5175 | // Check parameters |
| 5176 | 5176 | $langs->load('admin'); |
| 5177 | 5177 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 5178 | 5178 | $extrafields = new ExtraFields($this->db); |
| 5179 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 5179 | + $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 5180 | 5180 | |
| 5181 | - $value=$this->array_options["options_".$key]; |
|
| 5181 | + $value = $this->array_options["options_".$key]; |
|
| 5182 | 5182 | |
| 5183 | 5183 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
| 5184 | 5184 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
@@ -5191,25 +5191,25 @@ discard block |
||
| 5191 | 5191 | switch ($attributeType) |
| 5192 | 5192 | { |
| 5193 | 5193 | case 'int': |
| 5194 | - if (!is_numeric($value) && $value!='') |
|
| 5194 | + if (!is_numeric($value) && $value != '') |
|
| 5195 | 5195 | { |
| 5196 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); |
|
| 5196 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 5197 | 5197 | return -1; |
| 5198 | 5198 | } |
| 5199 | - elseif ($value=='') |
|
| 5199 | + elseif ($value == '') |
|
| 5200 | 5200 | { |
| 5201 | 5201 | $this->array_options["options_".$key] = null; |
| 5202 | 5202 | } |
| 5203 | 5203 | break; |
| 5204 | 5204 | case 'double': |
| 5205 | 5205 | $value = price2num($value); |
| 5206 | - if (!is_numeric($value) && $value!='') |
|
| 5206 | + if (!is_numeric($value) && $value != '') |
|
| 5207 | 5207 | { |
| 5208 | 5208 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
| 5209 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 5209 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 5210 | 5210 | return -1; |
| 5211 | 5211 | } |
| 5212 | - elseif ($value=='') |
|
| 5212 | + elseif ($value == '') |
|
| 5213 | 5213 | { |
| 5214 | 5214 | $this->array_options["options_".$key] = null; |
| 5215 | 5215 | } |
@@ -5226,13 +5226,13 @@ discard block |
||
| 5226 | 5226 | $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
| 5227 | 5227 | break; |
| 5228 | 5228 | case 'date': |
| 5229 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5229 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
| 5230 | 5230 | break; |
| 5231 | 5231 | case 'datetime': |
| 5232 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5232 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
| 5233 | 5233 | break; |
| 5234 | 5234 | case 'link': |
| 5235 | - $param_list=array_keys($attributeParam['options']); |
|
| 5235 | + $param_list = array_keys($attributeParam['options']); |
|
| 5236 | 5236 | // 0 : ObjectName |
| 5237 | 5237 | // 1 : classPath |
| 5238 | 5238 | $InfoFieldList = explode(":", $param_list[0]); |
@@ -5240,8 +5240,8 @@ discard block |
||
| 5240 | 5240 | if ($value) |
| 5241 | 5241 | { |
| 5242 | 5242 | $object = new $InfoFieldList[0]($this->db); |
| 5243 | - $object->fetch(0,$value); |
|
| 5244 | - $this->array_options["options_".$key]=$object->id; |
|
| 5243 | + $object->fetch(0, $value); |
|
| 5244 | + $this->array_options["options_".$key] = $object->id; |
|
| 5245 | 5245 | } |
| 5246 | 5246 | break; |
| 5247 | 5247 | } |
@@ -5250,24 +5250,24 @@ discard block |
||
| 5250 | 5250 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
| 5251 | 5251 | $sql .= " WHERE fk_object = ".$this->id; |
| 5252 | 5252 | $resql = $this->db->query($sql); |
| 5253 | - if (! $resql) |
|
| 5253 | + if (!$resql) |
|
| 5254 | 5254 | { |
| 5255 | 5255 | $error++; |
| 5256 | - $this->error=$this->db->lasterror(); |
|
| 5256 | + $this->error = $this->db->lasterror(); |
|
| 5257 | 5257 | } |
| 5258 | 5258 | |
| 5259 | - if (! $error && $trigger) |
|
| 5259 | + if (!$error && $trigger) |
|
| 5260 | 5260 | { |
| 5261 | 5261 | // Call trigger |
| 5262 | - $this->context=array('extrafieldupdate'=>1); |
|
| 5263 | - $result=$this->call_trigger($trigger, $userused); |
|
| 5262 | + $this->context = array('extrafieldupdate'=>1); |
|
| 5263 | + $result = $this->call_trigger($trigger, $userused); |
|
| 5264 | 5264 | if ($result < 0) $error++; |
| 5265 | 5265 | // End call trigger |
| 5266 | 5266 | } |
| 5267 | 5267 | |
| 5268 | 5268 | if ($error) |
| 5269 | 5269 | { |
| 5270 | - dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
|
| 5270 | + dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR); |
|
| 5271 | 5271 | $this->db->rollback(); |
| 5272 | 5272 | return -1; |
| 5273 | 5273 | } |
@@ -5294,71 +5294,71 @@ discard block |
||
| 5294 | 5294 | * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. |
| 5295 | 5295 | * @return string |
| 5296 | 5296 | */ |
| 5297 | - function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0) |
|
| 5297 | + function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0) |
|
| 5298 | 5298 | { |
| 5299 | - global $conf,$langs,$form; |
|
| 5299 | + global $conf, $langs, $form; |
|
| 5300 | 5300 | |
| 5301 | - if (! is_object($form)) |
|
| 5301 | + if (!is_object($form)) |
|
| 5302 | 5302 | { |
| 5303 | 5303 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
| 5304 | - $form=new Form($this->db); |
|
| 5304 | + $form = new Form($this->db); |
|
| 5305 | 5305 | } |
| 5306 | 5306 | |
| 5307 | - $val=$this->fields[$key]; |
|
| 5307 | + $val = $this->fields[$key]; |
|
| 5308 | 5308 | |
| 5309 | - $out=''; |
|
| 5310 | - $type=''; |
|
| 5309 | + $out = ''; |
|
| 5310 | + $type = ''; |
|
| 5311 | 5311 | $param = array(); |
| 5312 | - $param['options']=array(); |
|
| 5313 | - $size =$this->fields[$key]['size']; |
|
| 5312 | + $param['options'] = array(); |
|
| 5313 | + $size = $this->fields[$key]['size']; |
|
| 5314 | 5314 | // Because we work on extrafields |
| 5315 | - if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){ |
|
| 5316 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5317 | - $type ='link'; |
|
| 5318 | - } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) { |
|
| 5319 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5320 | - $type ='link'; |
|
| 5321 | - } elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) { |
|
| 5322 | - $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
| 5323 | - $type ='sellist'; |
|
| 5324 | - } elseif(preg_match('/varchar\((\d+)\)/', $val['type'],$reg)) { |
|
| 5325 | - $param['options']=array(); |
|
| 5326 | - $type ='varchar'; |
|
| 5327 | - $size=$reg[1]; |
|
| 5328 | - } elseif(preg_match('/varchar/', $val['type'])) { |
|
| 5329 | - $param['options']=array(); |
|
| 5330 | - $type ='varchar'; |
|
| 5331 | - } elseif(is_array($this->fields[$key]['arrayofkeyval'])) { |
|
| 5332 | - $param['options']=$this->fields[$key]['arrayofkeyval']; |
|
| 5333 | - $type ='select'; |
|
| 5315 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) { |
|
| 5316 | + $param['options'] = array($reg[1].':'.$reg[2]=>'N'); |
|
| 5317 | + $type = 'link'; |
|
| 5318 | + } elseif (preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) { |
|
| 5319 | + $param['options'] = array($reg[1].':'.$reg[2]=>'N'); |
|
| 5320 | + $type = 'link'; |
|
| 5321 | + } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) { |
|
| 5322 | + $param['options'] = array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
| 5323 | + $type = 'sellist'; |
|
| 5324 | + } elseif (preg_match('/varchar\((\d+)\)/', $val['type'], $reg)) { |
|
| 5325 | + $param['options'] = array(); |
|
| 5326 | + $type = 'varchar'; |
|
| 5327 | + $size = $reg[1]; |
|
| 5328 | + } elseif (preg_match('/varchar/', $val['type'])) { |
|
| 5329 | + $param['options'] = array(); |
|
| 5330 | + $type = 'varchar'; |
|
| 5331 | + } elseif (is_array($this->fields[$key]['arrayofkeyval'])) { |
|
| 5332 | + $param['options'] = $this->fields[$key]['arrayofkeyval']; |
|
| 5333 | + $type = 'select'; |
|
| 5334 | 5334 | } else { |
| 5335 | - $param['options']=array(); |
|
| 5336 | - $type =$this->fields[$key]['type']; |
|
| 5335 | + $param['options'] = array(); |
|
| 5336 | + $type = $this->fields[$key]['type']; |
|
| 5337 | 5337 | } |
| 5338 | 5338 | |
| 5339 | - $label=$this->fields[$key]['label']; |
|
| 5339 | + $label = $this->fields[$key]['label']; |
|
| 5340 | 5340 | //$elementtype=$this->fields[$key]['elementtype']; // Seems not used |
| 5341 | - $default=$this->fields[$key]['default']; |
|
| 5342 | - $computed=$this->fields[$key]['computed']; |
|
| 5343 | - $unique=$this->fields[$key]['unique']; |
|
| 5344 | - $required=$this->fields[$key]['required']; |
|
| 5341 | + $default = $this->fields[$key]['default']; |
|
| 5342 | + $computed = $this->fields[$key]['computed']; |
|
| 5343 | + $unique = $this->fields[$key]['unique']; |
|
| 5344 | + $required = $this->fields[$key]['required']; |
|
| 5345 | 5345 | |
| 5346 | - $langfile=$this->fields[$key]['langfile']; |
|
| 5347 | - $list=$this->fields[$key]['list']; |
|
| 5348 | - $hidden=abs($this->fields[$key]['visible'])!=1?1:0; |
|
| 5346 | + $langfile = $this->fields[$key]['langfile']; |
|
| 5347 | + $list = $this->fields[$key]['list']; |
|
| 5348 | + $hidden = abs($this->fields[$key]['visible']) != 1 ? 1 : 0; |
|
| 5349 | 5349 | |
| 5350 | 5350 | $objectid = $this->id; |
| 5351 | 5351 | |
| 5352 | 5352 | |
| 5353 | 5353 | if ($computed) |
| 5354 | 5354 | { |
| 5355 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 5355 | + if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 5356 | 5356 | else return ''; |
| 5357 | 5357 | } |
| 5358 | 5358 | |
| 5359 | 5359 | |
| 5360 | 5360 | // Use in priority showsize from parameters, then $val['css'] then autodefine |
| 5361 | - if (empty($morecss) && ! empty($val['css'])) |
|
| 5361 | + if (empty($morecss) && !empty($val['css'])) |
|
| 5362 | 5362 | { |
| 5363 | 5363 | $showsize = $val['css']; |
| 5364 | 5364 | } |
@@ -5372,16 +5372,16 @@ discard block |
||
| 5372 | 5372 | { |
| 5373 | 5373 | $morecss = 'minwidth200imp'; |
| 5374 | 5374 | } |
| 5375 | - elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
| 5375 | + elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type)) |
|
| 5376 | 5376 | { |
| 5377 | 5377 | $morecss = 'maxwidth75'; |
| 5378 | 5378 | }elseif ($type == 'url') |
| 5379 | 5379 | { |
| 5380 | - $morecss='minwidth400'; |
|
| 5380 | + $morecss = 'minwidth400'; |
|
| 5381 | 5381 | } |
| 5382 | 5382 | elseif ($type == 'boolean') |
| 5383 | 5383 | { |
| 5384 | - $morecss=''; |
|
| 5384 | + $morecss = ''; |
|
| 5385 | 5385 | } |
| 5386 | 5386 | else |
| 5387 | 5387 | { |
@@ -5400,12 +5400,12 @@ discard block |
||
| 5400 | 5400 | } |
| 5401 | 5401 | } |
| 5402 | 5402 | |
| 5403 | - if (in_array($type,array('date','datetime'))) |
|
| 5403 | + if (in_array($type, array('date', 'datetime'))) |
|
| 5404 | 5404 | { |
| 5405 | - $tmp=explode(',',$size); |
|
| 5406 | - $newsize=$tmp[0]; |
|
| 5405 | + $tmp = explode(',', $size); |
|
| 5406 | + $newsize = $tmp[0]; |
|
| 5407 | 5407 | |
| 5408 | - $showtime = in_array($type,array('datetime')) ? 1 : 0; |
|
| 5408 | + $showtime = in_array($type, array('datetime')) ? 1 : 0; |
|
| 5409 | 5409 | |
| 5410 | 5410 | // Do not show current date when field not required (see selectDate() method) |
| 5411 | 5411 | if (!$required && $value == '') $value = '-1'; |
@@ -5413,237 +5413,237 @@ discard block |
||
| 5413 | 5413 | // TODO Must also support $moreparam |
| 5414 | 5414 | $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
| 5415 | 5415 | } |
| 5416 | - elseif (in_array($type,array('int','integer'))) |
|
| 5416 | + elseif (in_array($type, array('int', 'integer'))) |
|
| 5417 | 5417 | { |
| 5418 | - $tmp=explode(',',$size); |
|
| 5419 | - $newsize=$tmp[0]; |
|
| 5420 | - $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:'').'>'; |
|
| 5418 | + $tmp = explode(',', $size); |
|
| 5419 | + $newsize = $tmp[0]; |
|
| 5420 | + $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 | 5421 | } |
| 5422 | 5422 | elseif (preg_match('/varchar/', $type)) |
| 5423 | 5423 | { |
| 5424 | - $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:'').'>'; |
|
| 5424 | + $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 | 5425 | } |
| 5426 | 5426 | elseif (in_array($type, array('mail', 'phone', 'url'))) |
| 5427 | 5427 | { |
| 5428 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5428 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5429 | 5429 | } |
| 5430 | 5430 | elseif ($type == 'text') |
| 5431 | 5431 | { |
| 5432 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5432 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5433 | 5433 | { |
| 5434 | 5434 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 5435 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
| 5436 | - $out=$doleditor->Create(1); |
|
| 5435 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); |
|
| 5436 | + $out = $doleditor->Create(1); |
|
| 5437 | 5437 | } |
| 5438 | 5438 | else |
| 5439 | 5439 | { |
| 5440 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5440 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5441 | 5441 | } |
| 5442 | 5442 | } |
| 5443 | 5443 | elseif ($type == 'html') |
| 5444 | 5444 | { |
| 5445 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5445 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5446 | 5446 | { |
| 5447 | 5447 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 5448 | - $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 | - $out=$doleditor->Create(1); |
|
| 5448 | + $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 | + $out = $doleditor->Create(1); |
|
| 5450 | 5450 | } |
| 5451 | 5451 | else |
| 5452 | 5452 | { |
| 5453 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5453 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5454 | 5454 | } |
| 5455 | 5455 | } |
| 5456 | 5456 | elseif ($type == 'boolean') |
| 5457 | 5457 | { |
| 5458 | - $checked=''; |
|
| 5458 | + $checked = ''; |
|
| 5459 | 5459 | if (!empty($value)) { |
| 5460 | - $checked=' checked value="1" '; |
|
| 5460 | + $checked = ' checked value="1" '; |
|
| 5461 | 5461 | } else { |
| 5462 | - $checked=' value="1" '; |
|
| 5462 | + $checked = ' value="1" '; |
|
| 5463 | 5463 | } |
| 5464 | - $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
| 5464 | + $out = '<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>'; |
|
| 5465 | 5465 | } |
| 5466 | 5466 | elseif ($type == 'price') |
| 5467 | 5467 | { |
| 5468 | 5468 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 5469 | - $value=price($value); |
|
| 5469 | + $value = price($value); |
|
| 5470 | 5470 | } |
| 5471 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
|
| 5471 | + $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 | 5472 | } |
| 5473 | - elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
| 5473 | + elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type)) |
|
| 5474 | 5474 | { |
| 5475 | 5475 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 5476 | - $value=price($value); |
|
| 5476 | + $value = price($value); |
|
| 5477 | 5477 | } |
| 5478 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
| 5478 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '; |
|
| 5479 | 5479 | } |
| 5480 | 5480 | elseif ($type == 'select') |
| 5481 | 5481 | { |
| 5482 | 5482 | $out = ''; |
| 5483 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5483 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5484 | 5484 | { |
| 5485 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5486 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5485 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 5486 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5487 | 5487 | } |
| 5488 | 5488 | |
| 5489 | - $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>'; |
|
| 5489 | + $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>'; |
|
| 5491 | 5491 | foreach ($param['options'] as $key => $val) |
| 5492 | 5492 | { |
| 5493 | 5493 | if ((string) $key == '') continue; |
| 5494 | 5494 | list($val, $parent) = explode('|', $val); |
| 5495 | - $out.='<option value="'.$key.'"'; |
|
| 5496 | - $out.= (((string) $value == (string) $key)?' selected':''); |
|
| 5497 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5498 | - $out.='>'.$val.'</option>'; |
|
| 5495 | + $out .= '<option value="'.$key.'"'; |
|
| 5496 | + $out .= (((string) $value == (string) $key) ? ' selected' : ''); |
|
| 5497 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
| 5498 | + $out .= '>'.$val.'</option>'; |
|
| 5499 | 5499 | } |
| 5500 | - $out.='</select>'; |
|
| 5500 | + $out .= '</select>'; |
|
| 5501 | 5501 | } |
| 5502 | 5502 | elseif ($type == 'sellist') |
| 5503 | 5503 | { |
| 5504 | 5504 | $out = ''; |
| 5505 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5505 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5506 | 5506 | { |
| 5507 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5508 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5507 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 5508 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5509 | 5509 | } |
| 5510 | 5510 | |
| 5511 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5511 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5512 | 5512 | if (is_array($param['options'])) |
| 5513 | 5513 | { |
| 5514 | - $param_list=array_keys($param['options']); |
|
| 5514 | + $param_list = array_keys($param['options']); |
|
| 5515 | 5515 | $InfoFieldList = explode(":", $param_list[0]); |
| 5516 | - $parentName=''; |
|
| 5517 | - $parentField=''; |
|
| 5516 | + $parentName = ''; |
|
| 5517 | + $parentField = ''; |
|
| 5518 | 5518 | // 0 : tableName |
| 5519 | 5519 | // 1 : label field name |
| 5520 | 5520 | // 2 : key fields name (if differ of rowid) |
| 5521 | 5521 | // 3 : key field parent (for dependent lists) |
| 5522 | 5522 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
| 5523 | - $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
| 5523 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
| 5524 | 5524 | |
| 5525 | 5525 | |
| 5526 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
| 5526 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) |
|
| 5527 | 5527 | { |
| 5528 | 5528 | if (strpos($InfoFieldList[4], 'extra.') !== false) |
| 5529 | 5529 | { |
| 5530 | - $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
| 5530 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
| 5531 | 5531 | } else { |
| 5532 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 5532 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 5533 | 5533 | } |
| 5534 | 5534 | } |
| 5535 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
| 5535 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) |
|
| 5536 | 5536 | { |
| 5537 | 5537 | list($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
| 5538 | - $keyList.= ', '.$parentField; |
|
| 5538 | + $keyList .= ', '.$parentField; |
|
| 5539 | 5539 | } |
| 5540 | 5540 | |
| 5541 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 5541 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 5542 | 5542 | if (is_array($fields_label)) |
| 5543 | 5543 | { |
| 5544 | - $keyList .=', '; |
|
| 5544 | + $keyList .= ', '; |
|
| 5545 | 5545 | $keyList .= implode(', ', $fields_label); |
| 5546 | 5546 | } |
| 5547 | 5547 | |
| 5548 | - $sqlwhere=''; |
|
| 5548 | + $sqlwhere = ''; |
|
| 5549 | 5549 | $sql = 'SELECT '.$keyList; |
| 5550 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 5550 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 5551 | 5551 | if (!empty($InfoFieldList[4])) |
| 5552 | 5552 | { |
| 5553 | 5553 | // can use SELECT request |
| 5554 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
| 5555 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
| 5554 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
| 5555 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
| 5556 | 5556 | } |
| 5557 | 5557 | |
| 5558 | 5558 | // current object id can be use into filter |
| 5559 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
| 5560 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
| 5559 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
| 5560 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
| 5561 | 5561 | } else { |
| 5562 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
| 5562 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
| 5563 | 5563 | } |
| 5564 | 5564 | //We have to join on extrafield table |
| 5565 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 5565 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
| 5566 | 5566 | { |
| 5567 | - $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
| 5568 | - $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
| 5567 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
| 5568 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
| 5569 | 5569 | } |
| 5570 | 5570 | else |
| 5571 | 5571 | { |
| 5572 | - $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
| 5572 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
| 5573 | 5573 | } |
| 5574 | 5574 | } |
| 5575 | 5575 | else |
| 5576 | 5576 | { |
| 5577 | - $sqlwhere.= ' WHERE 1=1'; |
|
| 5577 | + $sqlwhere .= ' WHERE 1=1'; |
|
| 5578 | 5578 | } |
| 5579 | 5579 | // Some tables may have field, some other not. For the moment we disable it. |
| 5580 | - if (in_array($InfoFieldList[0],array('tablewithentity'))) |
|
| 5580 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
| 5581 | 5581 | { |
| 5582 | - $sqlwhere.= ' AND entity = '.$conf->entity; |
|
| 5582 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
| 5583 | 5583 | } |
| 5584 | - $sql.=$sqlwhere; |
|
| 5584 | + $sql .= $sqlwhere; |
|
| 5585 | 5585 | //print $sql; |
| 5586 | 5586 | |
| 5587 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label); |
|
| 5587 | + $sql .= ' ORDER BY '.implode(', ', $fields_label); |
|
| 5588 | 5588 | |
| 5589 | 5589 | dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
| 5590 | 5590 | $resql = $this->db->query($sql); |
| 5591 | 5591 | if ($resql) |
| 5592 | 5592 | { |
| 5593 | - $out.='<option value="0"> </option>'; |
|
| 5593 | + $out .= '<option value="0"> </option>'; |
|
| 5594 | 5594 | $num = $this->db->num_rows($resql); |
| 5595 | 5595 | $i = 0; |
| 5596 | 5596 | while ($i < $num) |
| 5597 | 5597 | { |
| 5598 | - $labeltoshow=''; |
|
| 5598 | + $labeltoshow = ''; |
|
| 5599 | 5599 | $obj = $this->db->fetch_object($resql); |
| 5600 | 5600 | |
| 5601 | 5601 | // Several field into label (eq table:code|libelle:rowid) |
| 5602 | 5602 | $notrans = false; |
| 5603 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 5603 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 5604 | 5604 | if (is_array($fields_label)) |
| 5605 | 5605 | { |
| 5606 | 5606 | $notrans = true; |
| 5607 | 5607 | foreach ($fields_label as $field_toshow) |
| 5608 | 5608 | { |
| 5609 | - $labeltoshow.= $obj->$field_toshow.' '; |
|
| 5609 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
| 5610 | 5610 | } |
| 5611 | 5611 | } |
| 5612 | 5612 | else |
| 5613 | 5613 | { |
| 5614 | - $labeltoshow=$obj->{$InfoFieldList[1]}; |
|
| 5614 | + $labeltoshow = $obj->{$InfoFieldList[1]}; |
|
| 5615 | 5615 | } |
| 5616 | - $labeltoshow=dol_trunc($labeltoshow,45); |
|
| 5616 | + $labeltoshow = dol_trunc($labeltoshow, 45); |
|
| 5617 | 5617 | |
| 5618 | 5618 | if ($value == $obj->rowid) |
| 5619 | 5619 | { |
| 5620 | 5620 | foreach ($fields_label as $field_toshow) |
| 5621 | 5621 | { |
| 5622 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 5623 | - if ($translabel!=$obj->$field_toshow) { |
|
| 5624 | - $labeltoshow=dol_trunc($translabel,18).' '; |
|
| 5625 | - }else { |
|
| 5626 | - $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
| 5622 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 5623 | + if ($translabel != $obj->$field_toshow) { |
|
| 5624 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
| 5625 | + } else { |
|
| 5626 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
| 5627 | 5627 | } |
| 5628 | 5628 | } |
| 5629 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5629 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5630 | 5630 | } |
| 5631 | 5631 | else |
| 5632 | 5632 | { |
| 5633 | - if (! $notrans) |
|
| 5633 | + if (!$notrans) |
|
| 5634 | 5634 | { |
| 5635 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
| 5636 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
| 5637 | - $labeltoshow=dol_trunc($translabel,18); |
|
| 5635 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
| 5636 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
| 5637 | + $labeltoshow = dol_trunc($translabel, 18); |
|
| 5638 | 5638 | } |
| 5639 | 5639 | else { |
| 5640 | - $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18); |
|
| 5640 | + $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]},18); |
|
| 5641 | 5641 | } |
| 5642 | 5642 | } |
| 5643 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 5644 | - if ($value==$obj->rowid) |
|
| 5643 | + if (empty($labeltoshow)) $labeltoshow = '(not defined)'; |
|
| 5644 | + if ($value == $obj->rowid) |
|
| 5645 | 5645 | { |
| 5646 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5646 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5647 | 5647 | } |
| 5648 | 5648 | |
| 5649 | 5649 | if (!empty($InfoFieldList[3]) && $parentField) |
@@ -5651,10 +5651,10 @@ discard block |
||
| 5651 | 5651 | $parent = $parentName.':'.$obj->{$parentField}; |
| 5652 | 5652 | } |
| 5653 | 5653 | |
| 5654 | - $out.='<option value="'.$obj->rowid.'"'; |
|
| 5655 | - $out.= ($value==$obj->rowid?' selected':''); |
|
| 5656 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5657 | - $out.='>'.$labeltoshow.'</option>'; |
|
| 5654 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
| 5655 | + $out .= ($value == $obj->rowid ? ' selected' : ''); |
|
| 5656 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
| 5657 | + $out .= '>'.$labeltoshow.'</option>'; |
|
| 5658 | 5658 | } |
| 5659 | 5659 | |
| 5660 | 5660 | $i++; |
@@ -5665,23 +5665,23 @@ discard block |
||
| 5665 | 5665 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
| 5666 | 5666 | } |
| 5667 | 5667 | } |
| 5668 | - $out.='</select>'; |
|
| 5668 | + $out .= '</select>'; |
|
| 5669 | 5669 | } |
| 5670 | 5670 | elseif ($type == 'checkbox') |
| 5671 | 5671 | { |
| 5672 | - $value_arr=explode(',',$value); |
|
| 5673 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5672 | + $value_arr = explode(',', $value); |
|
| 5673 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5674 | 5674 | } |
| 5675 | 5675 | elseif ($type == 'radio') |
| 5676 | 5676 | { |
| 5677 | - $out=''; |
|
| 5677 | + $out = ''; |
|
| 5678 | 5678 | foreach ($param['options'] as $keyopt => $val) |
| 5679 | 5679 | { |
| 5680 | - $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
| 5681 | - $out.=' value="'.$keyopt.'"'; |
|
| 5682 | - $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5683 | - $out.= ($value==$keyopt?'checked':''); |
|
| 5684 | - $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5680 | + $out .= '<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : ''); |
|
| 5681 | + $out .= ' value="'.$keyopt.'"'; |
|
| 5682 | + $out .= ' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5683 | + $out .= ($value == $keyopt ? 'checked' : ''); |
|
| 5684 | + $out .= '/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5685 | 5685 | } |
| 5686 | 5686 | } |
| 5687 | 5687 | elseif ($type == 'chkbxlst') |
@@ -5696,24 +5696,24 @@ discard block |
||
| 5696 | 5696 | if (is_array($param['options'])) { |
| 5697 | 5697 | $param_list = array_keys($param['options']); |
| 5698 | 5698 | $InfoFieldList = explode(":", $param_list[0]); |
| 5699 | - $parentName=''; |
|
| 5700 | - $parentField=''; |
|
| 5699 | + $parentName = ''; |
|
| 5700 | + $parentField = ''; |
|
| 5701 | 5701 | // 0 : tableName |
| 5702 | 5702 | // 1 : label field name |
| 5703 | 5703 | // 2 : key fields name (if differ of rowid) |
| 5704 | 5704 | // 3 : key field parent (for dependent lists) |
| 5705 | 5705 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
| 5706 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
| 5706 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
| 5707 | 5707 | |
| 5708 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) { |
|
| 5709 | - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]); |
|
| 5710 | - $keyList .= ', ' . $parentField; |
|
| 5708 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { |
|
| 5709 | + list ($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
|
| 5710 | + $keyList .= ', '.$parentField; |
|
| 5711 | 5711 | } |
| 5712 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) { |
|
| 5712 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { |
|
| 5713 | 5713 | if (strpos($InfoFieldList[4], 'extra.') !== false) { |
| 5714 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
| 5714 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
| 5715 | 5715 | } else { |
| 5716 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 5716 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 5717 | 5717 | } |
| 5718 | 5718 | } |
| 5719 | 5719 | |
@@ -5724,50 +5724,50 @@ discard block |
||
| 5724 | 5724 | } |
| 5725 | 5725 | |
| 5726 | 5726 | $sqlwhere = ''; |
| 5727 | - $sql = 'SELECT ' . $keyList; |
|
| 5728 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 5729 | - if (! empty($InfoFieldList[4])) { |
|
| 5727 | + $sql = 'SELECT '.$keyList; |
|
| 5728 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 5729 | + if (!empty($InfoFieldList[4])) { |
|
| 5730 | 5730 | |
| 5731 | 5731 | // can use SELECT request |
| 5732 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
| 5733 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
| 5732 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
| 5733 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
| 5734 | 5734 | } |
| 5735 | 5735 | |
| 5736 | 5736 | // current object id can be use into filter |
| 5737 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
| 5738 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
| 5737 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
| 5738 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
| 5739 | 5739 | } else { |
| 5740 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
| 5740 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
| 5741 | 5741 | } |
| 5742 | 5742 | |
| 5743 | 5743 | // We have to join on extrafield table |
| 5744 | 5744 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
| 5745 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
| 5746 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
| 5745 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
| 5746 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
| 5747 | 5747 | } else { |
| 5748 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
| 5748 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
| 5749 | 5749 | } |
| 5750 | 5750 | } else { |
| 5751 | 5751 | $sqlwhere .= ' WHERE 1=1'; |
| 5752 | 5752 | } |
| 5753 | 5753 | // Some tables may have field, some other not. For the moment we disable it. |
| 5754 | - if (in_array($InfoFieldList[0], array ('tablewithentity'))) |
|
| 5754 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
| 5755 | 5755 | { |
| 5756 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
| 5756 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
| 5757 | 5757 | } |
| 5758 | 5758 | // $sql.=preg_replace('/^ AND /','',$sqlwhere); |
| 5759 | 5759 | // print $sql; |
| 5760 | 5760 | |
| 5761 | 5761 | $sql .= $sqlwhere; |
| 5762 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
| 5762 | + dol_syslog(get_class($this).'::showInputField type=chkbxlst', LOG_DEBUG); |
|
| 5763 | 5763 | $resql = $this->db->query($sql); |
| 5764 | 5764 | if ($resql) { |
| 5765 | 5765 | $num = $this->db->num_rows($resql); |
| 5766 | 5766 | $i = 0; |
| 5767 | 5767 | |
| 5768 | - $data=array(); |
|
| 5768 | + $data = array(); |
|
| 5769 | 5769 | |
| 5770 | - while ( $i < $num ) { |
|
| 5770 | + while ($i < $num) { |
|
| 5771 | 5771 | $labeltoshow = ''; |
| 5772 | 5772 | $obj = $this->db->fetch_object($resql); |
| 5773 | 5773 | |
@@ -5776,8 +5776,8 @@ discard block |
||
| 5776 | 5776 | $fields_label = explode('|', $InfoFieldList[1]); |
| 5777 | 5777 | if (is_array($fields_label)) { |
| 5778 | 5778 | $notrans = true; |
| 5779 | - foreach ( $fields_label as $field_toshow ) { |
|
| 5780 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
| 5779 | + foreach ($fields_label as $field_toshow) { |
|
| 5780 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
| 5781 | 5781 | } |
| 5782 | 5782 | } else { |
| 5783 | 5783 | $labeltoshow = $obj->{$InfoFieldList[1]}; |
@@ -5785,18 +5785,18 @@ discard block |
||
| 5785 | 5785 | $labeltoshow = dol_trunc($labeltoshow, 45); |
| 5786 | 5786 | |
| 5787 | 5787 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 5788 | - foreach ( $fields_label as $field_toshow ) { |
|
| 5788 | + foreach ($fields_label as $field_toshow) { |
|
| 5789 | 5789 | $translabel = $langs->trans($obj->$field_toshow); |
| 5790 | 5790 | if ($translabel != $obj->$field_toshow) { |
| 5791 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
| 5791 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
| 5792 | 5792 | } else { |
| 5793 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
| 5793 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
| 5794 | 5794 | } |
| 5795 | 5795 | } |
| 5796 | 5796 | |
| 5797 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5797 | + $data[$obj->rowid] = $labeltoshow; |
|
| 5798 | 5798 | } else { |
| 5799 | - if (! $notrans) { |
|
| 5799 | + if (!$notrans) { |
|
| 5800 | 5800 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
| 5801 | 5801 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
| 5802 | 5802 | $labeltoshow = dol_trunc($translabel, 18); |
@@ -5808,67 +5808,67 @@ discard block |
||
| 5808 | 5808 | $labeltoshow = '(not defined)'; |
| 5809 | 5809 | |
| 5810 | 5810 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 5811 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5811 | + $data[$obj->rowid] = $labeltoshow; |
|
| 5812 | 5812 | } |
| 5813 | 5813 | |
| 5814 | - if (! empty($InfoFieldList[3]) && $parentField) { |
|
| 5815 | - $parent = $parentName . ':' . $obj->{$parentField}; |
|
| 5814 | + if (!empty($InfoFieldList[3]) && $parentField) { |
|
| 5815 | + $parent = $parentName.':'.$obj->{$parentField}; |
|
| 5816 | 5816 | } |
| 5817 | 5817 | |
| 5818 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5818 | + $data[$obj->rowid] = $labeltoshow; |
|
| 5819 | 5819 | } |
| 5820 | 5820 | |
| 5821 | - $i ++; |
|
| 5821 | + $i++; |
|
| 5822 | 5822 | } |
| 5823 | 5823 | $this->db->free($resql); |
| 5824 | 5824 | |
| 5825 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5825 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5826 | 5826 | } else { |
| 5827 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
| 5827 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
| 5828 | 5828 | } |
| 5829 | 5829 | } |
| 5830 | 5830 | } |
| 5831 | 5831 | elseif ($type == 'link') |
| 5832 | 5832 | { |
| 5833 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5834 | - $showempty=(($required && $default != '')?0:1); |
|
| 5835 | - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5833 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5834 | + $showempty = (($required && $default != '') ? 0 : 1); |
|
| 5835 | + $out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5836 | 5836 | if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
| 5837 | 5837 | { |
| 5838 | - 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); |
|
| 5841 | - $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5838 | + 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); |
|
| 5841 | + $out .= '<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5842 | 5842 | // TODO Add Javascript code to add input fields contents to new elements urls |
| 5843 | 5843 | } |
| 5844 | 5844 | } |
| 5845 | 5845 | elseif ($type == 'password') |
| 5846 | 5846 | { |
| 5847 | 5847 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
| 5848 | - $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5848 | + $out = '<input type="'.($keyprefix == 'search_' ? 'text' : 'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5849 | 5849 | } |
| 5850 | 5850 | elseif ($type == 'array') |
| 5851 | 5851 | { |
| 5852 | 5852 | $newval = $val; |
| 5853 | 5853 | $newval['type'] = 'varchar(256)'; |
| 5854 | 5854 | |
| 5855 | - $out=''; |
|
| 5855 | + $out = ''; |
|
| 5856 | 5856 | |
| 5857 | 5857 | $inputs = array(); |
| 5858 | - if(! empty($value)) { |
|
| 5859 | - foreach($value as $option) { |
|
| 5860 | - $out.= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5861 | - $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5858 | + if (!empty($value)) { |
|
| 5859 | + foreach ($value as $option) { |
|
| 5860 | + $out .= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5861 | + $out .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5862 | 5862 | } |
| 5863 | 5863 | } |
| 5864 | 5864 | |
| 5865 | - $out.= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5865 | + $out .= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5866 | 5866 | |
| 5867 | 5867 | $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
| 5868 | - $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5868 | + $newInput .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5869 | 5869 | |
| 5870 | - if(! empty($conf->use_javascript_ajax)) { |
|
| 5871 | - $out.= ' |
|
| 5870 | + if (!empty($conf->use_javascript_ajax)) { |
|
| 5871 | + $out .= ' |
|
| 5872 | 5872 | <script type="text/javascript"> |
| 5873 | 5873 | $(document).ready(function() { |
| 5874 | 5874 | $("a#'.dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() { |
@@ -5883,7 +5883,7 @@ discard block |
||
| 5883 | 5883 | } |
| 5884 | 5884 | } |
| 5885 | 5885 | if (!empty($hidden)) { |
| 5886 | - $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5886 | + $out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5887 | 5887 | } |
| 5888 | 5888 | /* Add comments |
| 5889 | 5889 | if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
@@ -5905,14 +5905,14 @@ discard block |
||
| 5905 | 5905 | * @param mixed $showsize Value for css to define size. May also be a numeric. |
| 5906 | 5906 | * @return string |
| 5907 | 5907 | */ |
| 5908 | - function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
| 5908 | + function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $showsize = 0) |
|
| 5909 | 5909 | { |
| 5910 | - global $conf,$langs,$form; |
|
| 5910 | + global $conf, $langs, $form; |
|
| 5911 | 5911 | |
| 5912 | - if (! is_object($form)) |
|
| 5912 | + if (!is_object($form)) |
|
| 5913 | 5913 | { |
| 5914 | 5914 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
| 5915 | - $form=new Form($this->db); |
|
| 5915 | + $form = new Form($this->db); |
|
| 5916 | 5916 | } |
| 5917 | 5917 | |
| 5918 | 5918 | $objectid = $this->id; |
@@ -5923,28 +5923,28 @@ discard block |
||
| 5923 | 5923 | // Convert var to be able to share same code than showOutputField of extrafields |
| 5924 | 5924 | if (preg_match('/varchar\((\d+)\)/', $type, $reg)) |
| 5925 | 5925 | { |
| 5926 | - $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5926 | + $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5927 | 5927 | $size = $reg[1]; |
| 5928 | 5928 | } |
| 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'; |
|
| 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 | 5932 | |
| 5933 | - $default=$val['default']; |
|
| 5934 | - $computed=$val['computed']; |
|
| 5935 | - $unique=$val['unique']; |
|
| 5936 | - $required=$val['required']; |
|
| 5937 | - $param=$val['param']; |
|
| 5933 | + $default = $val['default']; |
|
| 5934 | + $computed = $val['computed']; |
|
| 5935 | + $unique = $val['unique']; |
|
| 5936 | + $required = $val['required']; |
|
| 5937 | + $param = $val['param']; |
|
| 5938 | 5938 | if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
| 5939 | 5939 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) |
| 5940 | 5940 | { |
| 5941 | - $type='link'; |
|
| 5942 | - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5941 | + $type = 'link'; |
|
| 5942 | + $param['options'] = array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5943 | 5943 | } |
| 5944 | - $langfile=$val['langfile']; |
|
| 5945 | - $list=$val['list']; |
|
| 5946 | - $help=$val['help']; |
|
| 5947 | - $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) |
|
| 5944 | + $langfile = $val['langfile']; |
|
| 5945 | + $list = $val['list']; |
|
| 5946 | + $help = $val['help']; |
|
| 5947 | + $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 | 5948 | |
| 5949 | 5949 | if ($hidden) return ''; |
| 5950 | 5950 | |
@@ -5968,18 +5968,18 @@ discard block |
||
| 5968 | 5968 | //$showsize=19; |
| 5969 | 5969 | $showsize = 'minwidth200imp'; |
| 5970 | 5970 | } |
| 5971 | - elseif (in_array($type,array('int','double','price'))) |
|
| 5971 | + elseif (in_array($type, array('int', 'double', 'price'))) |
|
| 5972 | 5972 | { |
| 5973 | 5973 | //$showsize=10; |
| 5974 | 5974 | $showsize = 'maxwidth75'; |
| 5975 | 5975 | } |
| 5976 | 5976 | elseif ($type == 'url') |
| 5977 | 5977 | { |
| 5978 | - $showsize='minwidth400'; |
|
| 5978 | + $showsize = 'minwidth400'; |
|
| 5979 | 5979 | } |
| 5980 | 5980 | elseif ($type == 'boolean') |
| 5981 | 5981 | { |
| 5982 | - $showsize=''; |
|
| 5982 | + $showsize = ''; |
|
| 5983 | 5983 | } |
| 5984 | 5984 | else |
| 5985 | 5985 | { |
@@ -6000,90 +6000,90 @@ discard block |
||
| 6000 | 6000 | } |
| 6001 | 6001 | |
| 6002 | 6002 | // 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); |
|
| 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 | 6005 | elseif ($type == 'date') |
| 6006 | 6006 | { |
| 6007 | - if(! empty($value)) { |
|
| 6008 | - $value=dol_print_date($value,'day'); |
|
| 6007 | + if (!empty($value)) { |
|
| 6008 | + $value = dol_print_date($value, 'day'); |
|
| 6009 | 6009 | } else { |
| 6010 | - $value=''; |
|
| 6010 | + $value = ''; |
|
| 6011 | 6011 | } |
| 6012 | 6012 | } |
| 6013 | 6013 | elseif ($type == 'datetime') |
| 6014 | 6014 | { |
| 6015 | - if(! empty($value)) { |
|
| 6016 | - $value=dol_print_date($value,'dayhour'); |
|
| 6015 | + if (!empty($value)) { |
|
| 6016 | + $value = dol_print_date($value, 'dayhour'); |
|
| 6017 | 6017 | } else { |
| 6018 | - $value=''; |
|
| 6018 | + $value = ''; |
|
| 6019 | 6019 | } |
| 6020 | 6020 | } |
| 6021 | 6021 | elseif ($type == 'double') |
| 6022 | 6022 | { |
| 6023 | 6023 | if (!empty($value)) { |
| 6024 | - $value=price($value); |
|
| 6024 | + $value = price($value); |
|
| 6025 | 6025 | } |
| 6026 | 6026 | } |
| 6027 | 6027 | elseif ($type == 'boolean') |
| 6028 | 6028 | { |
| 6029 | - $checked=''; |
|
| 6029 | + $checked = ''; |
|
| 6030 | 6030 | if (!empty($value)) { |
| 6031 | - $checked=' checked '; |
|
| 6031 | + $checked = ' checked '; |
|
| 6032 | 6032 | } |
| 6033 | - $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
| 6033 | + $value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>'; |
|
| 6034 | 6034 | } |
| 6035 | 6035 | elseif ($type == 'mail') |
| 6036 | 6036 | { |
| 6037 | - $value=dol_print_email($value,0,0,0,64,1,1); |
|
| 6037 | + $value = dol_print_email($value, 0, 0, 0, 64, 1, 1); |
|
| 6038 | 6038 | } |
| 6039 | 6039 | elseif ($type == 'url') |
| 6040 | 6040 | { |
| 6041 | - $value=dol_print_url($value,'_blank',32,1); |
|
| 6041 | + $value = dol_print_url($value, '_blank', 32, 1); |
|
| 6042 | 6042 | } |
| 6043 | 6043 | elseif ($type == 'phone') |
| 6044 | 6044 | { |
| 6045 | - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 6045 | + $value = dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 6046 | 6046 | } |
| 6047 | 6047 | elseif ($type == 'price') |
| 6048 | 6048 | { |
| 6049 | - $value=price($value,0,$langs,0,0,-1,$conf->currency); |
|
| 6049 | + $value = price($value, 0, $langs, 0, 0, -1, $conf->currency); |
|
| 6050 | 6050 | } |
| 6051 | 6051 | elseif ($type == 'select') |
| 6052 | 6052 | { |
| 6053 | - $value=$param['options'][$value]; |
|
| 6053 | + $value = $param['options'][$value]; |
|
| 6054 | 6054 | } |
| 6055 | 6055 | elseif ($type == 'sellist') |
| 6056 | 6056 | { |
| 6057 | - $param_list=array_keys($param['options']); |
|
| 6057 | + $param_list = array_keys($param['options']); |
|
| 6058 | 6058 | $InfoFieldList = explode(":", $param_list[0]); |
| 6059 | 6059 | |
| 6060 | - $selectkey="rowid"; |
|
| 6061 | - $keyList='rowid'; |
|
| 6060 | + $selectkey = "rowid"; |
|
| 6061 | + $keyList = 'rowid'; |
|
| 6062 | 6062 | |
| 6063 | - if (count($InfoFieldList)>=3) |
|
| 6063 | + if (count($InfoFieldList) >= 3) |
|
| 6064 | 6064 | { |
| 6065 | 6065 | $selectkey = $InfoFieldList[2]; |
| 6066 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 6066 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 6067 | 6067 | } |
| 6068 | 6068 | |
| 6069 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 6070 | - if(is_array($fields_label)) { |
|
| 6071 | - $keyList .=', '; |
|
| 6069 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 6070 | + if (is_array($fields_label)) { |
|
| 6071 | + $keyList .= ', '; |
|
| 6072 | 6072 | $keyList .= implode(', ', $fields_label); |
| 6073 | 6073 | } |
| 6074 | 6074 | |
| 6075 | 6075 | $sql = 'SELECT '.$keyList; |
| 6076 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 6077 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 6076 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 6077 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
| 6078 | 6078 | { |
| 6079 | - $sql.= ' as main'; |
|
| 6079 | + $sql .= ' as main'; |
|
| 6080 | 6080 | } |
| 6081 | - if ($selectkey=='rowid' && empty($value)) { |
|
| 6082 | - $sql.= " WHERE ".$selectkey."=0"; |
|
| 6083 | - } elseif ($selectkey=='rowid') { |
|
| 6084 | - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 6085 | - }else { |
|
| 6086 | - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6081 | + if ($selectkey == 'rowid' && empty($value)) { |
|
| 6082 | + $sql .= " WHERE ".$selectkey."=0"; |
|
| 6083 | + } elseif ($selectkey == 'rowid') { |
|
| 6084 | + $sql .= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 6085 | + } else { |
|
| 6086 | + $sql .= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6087 | 6087 | } |
| 6088 | 6088 | |
| 6089 | 6089 | //$sql.= ' AND entity = '.$conf->entity; |
@@ -6092,38 +6092,38 @@ discard block |
||
| 6092 | 6092 | $resql = $this->db->query($sql); |
| 6093 | 6093 | if ($resql) |
| 6094 | 6094 | { |
| 6095 | - $value=''; // value was used, so now we reste it to use it to build final output |
|
| 6095 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
| 6096 | 6096 | |
| 6097 | 6097 | $obj = $this->db->fetch_object($resql); |
| 6098 | 6098 | |
| 6099 | 6099 | // Several field into label (eq table:code|libelle:rowid) |
| 6100 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 6100 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 6101 | 6101 | |
| 6102 | - if(is_array($fields_label) && count($fields_label)>1) |
|
| 6102 | + if (is_array($fields_label) && count($fields_label) > 1) |
|
| 6103 | 6103 | { |
| 6104 | 6104 | foreach ($fields_label as $field_toshow) |
| 6105 | 6105 | { |
| 6106 | - $translabel=''; |
|
| 6106 | + $translabel = ''; |
|
| 6107 | 6107 | if (!empty($obj->$field_toshow)) { |
| 6108 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 6108 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 6109 | 6109 | } |
| 6110 | - if ($translabel!=$field_toshow) { |
|
| 6111 | - $value.=dol_trunc($translabel,18).' '; |
|
| 6112 | - }else { |
|
| 6113 | - $value.=$obj->$field_toshow.' '; |
|
| 6110 | + if ($translabel != $field_toshow) { |
|
| 6111 | + $value .= dol_trunc($translabel, 18).' '; |
|
| 6112 | + } else { |
|
| 6113 | + $value .= $obj->$field_toshow.' '; |
|
| 6114 | 6114 | } |
| 6115 | 6115 | } |
| 6116 | 6116 | } |
| 6117 | 6117 | else |
| 6118 | 6118 | { |
| 6119 | - $translabel=''; |
|
| 6119 | + $translabel = ''; |
|
| 6120 | 6120 | if (!empty($obj->{$InfoFieldList[1]})) { |
| 6121 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
| 6121 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
| 6122 | 6122 | } |
| 6123 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
| 6124 | - $value=dol_trunc($translabel,18); |
|
| 6125 | - }else { |
|
| 6126 | - $value=$obj->{$InfoFieldList[1]}; |
|
| 6123 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
| 6124 | + $value = dol_trunc($translabel, 18); |
|
| 6125 | + } else { |
|
| 6126 | + $value = $obj->{$InfoFieldList[1]}; |
|
| 6127 | 6127 | } |
| 6128 | 6128 | } |
| 6129 | 6129 | } |
@@ -6131,18 +6131,18 @@ discard block |
||
| 6131 | 6131 | } |
| 6132 | 6132 | elseif ($type == 'radio') |
| 6133 | 6133 | { |
| 6134 | - $value=$param['options'][$value]; |
|
| 6134 | + $value = $param['options'][$value]; |
|
| 6135 | 6135 | } |
| 6136 | 6136 | elseif ($type == 'checkbox') |
| 6137 | 6137 | { |
| 6138 | - $value_arr=explode(',',$value); |
|
| 6139 | - $value=''; |
|
| 6140 | - if (is_array($value_arr) && count($value_arr)>0) |
|
| 6138 | + $value_arr = explode(',', $value); |
|
| 6139 | + $value = ''; |
|
| 6140 | + if (is_array($value_arr) && count($value_arr) > 0) |
|
| 6141 | 6141 | { |
| 6142 | 6142 | foreach ($value_arr as $keyval=>$valueval) { |
| 6143 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 6143 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 6144 | 6144 | } |
| 6145 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 6145 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 6146 | 6146 | } |
| 6147 | 6147 | } |
| 6148 | 6148 | elseif ($type == 'chkbxlst') |
@@ -6157,7 +6157,7 @@ discard block |
||
| 6157 | 6157 | |
| 6158 | 6158 | if (count($InfoFieldList) >= 3) { |
| 6159 | 6159 | $selectkey = $InfoFieldList[2]; |
| 6160 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 6160 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 6161 | 6161 | } |
| 6162 | 6162 | |
| 6163 | 6163 | $fields_label = explode('|', $InfoFieldList[1]); |
@@ -6166,75 +6166,75 @@ discard block |
||
| 6166 | 6166 | $keyList .= implode(', ', $fields_label); |
| 6167 | 6167 | } |
| 6168 | 6168 | |
| 6169 | - $sql = 'SELECT ' . $keyList; |
|
| 6170 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 6169 | + $sql = 'SELECT '.$keyList; |
|
| 6170 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 6171 | 6171 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
| 6172 | 6172 | $sql .= ' as main'; |
| 6173 | 6173 | } |
| 6174 | 6174 | // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
| 6175 | 6175 | // $sql.= ' AND entity = '.$conf->entity; |
| 6176 | 6176 | |
| 6177 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
| 6177 | + dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); |
|
| 6178 | 6178 | $resql = $this->db->query($sql); |
| 6179 | 6179 | if ($resql) { |
| 6180 | 6180 | $value = ''; // value was used, so now we reste it to use it to build final output |
| 6181 | - $toprint=array(); |
|
| 6182 | - while ( $obj = $this->db->fetch_object($resql) ) { |
|
| 6181 | + $toprint = array(); |
|
| 6182 | + while ($obj = $this->db->fetch_object($resql)) { |
|
| 6183 | 6183 | |
| 6184 | 6184 | // Several field into label (eq table:code|libelle:rowid) |
| 6185 | 6185 | $fields_label = explode('|', $InfoFieldList[1]); |
| 6186 | 6186 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 6187 | 6187 | if (is_array($fields_label) && count($fields_label) > 1) { |
| 6188 | - foreach ( $fields_label as $field_toshow ) { |
|
| 6188 | + foreach ($fields_label as $field_toshow) { |
|
| 6189 | 6189 | $translabel = ''; |
| 6190 | - if (! empty($obj->$field_toshow)) { |
|
| 6190 | + if (!empty($obj->$field_toshow)) { |
|
| 6191 | 6191 | $translabel = $langs->trans($obj->$field_toshow); |
| 6192 | 6192 | } |
| 6193 | 6193 | if ($translabel != $field_toshow) { |
| 6194 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6194 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6195 | 6195 | } else { |
| 6196 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 6196 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 6197 | 6197 | } |
| 6198 | 6198 | } |
| 6199 | 6199 | } else { |
| 6200 | 6200 | $translabel = ''; |
| 6201 | - if (! empty($obj->{$InfoFieldList[1]})) { |
|
| 6201 | + if (!empty($obj->{$InfoFieldList[1]})) { |
|
| 6202 | 6202 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
| 6203 | 6203 | } |
| 6204 | 6204 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
| 6205 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6205 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6206 | 6206 | } else { |
| 6207 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
| 6207 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
| 6208 | 6208 | } |
| 6209 | 6209 | } |
| 6210 | 6210 | } |
| 6211 | 6211 | } |
| 6212 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 6212 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 6213 | 6213 | } else { |
| 6214 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
| 6214 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6215 | 6215 | } |
| 6216 | 6216 | } |
| 6217 | 6217 | elseif ($type == 'link') |
| 6218 | 6218 | { |
| 6219 | - $out=''; |
|
| 6219 | + $out = ''; |
|
| 6220 | 6220 | |
| 6221 | 6221 | // only if something to display (perf) |
| 6222 | 6222 | if ($value) |
| 6223 | 6223 | { |
| 6224 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 6224 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 6225 | 6225 | |
| 6226 | 6226 | $InfoFieldList = explode(":", $param_list[0]); |
| 6227 | - $classname=$InfoFieldList[0]; |
|
| 6228 | - $classpath=$InfoFieldList[1]; |
|
| 6229 | - $getnomurlparam=(empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
| 6230 | - if (! empty($classpath)) |
|
| 6227 | + $classname = $InfoFieldList[0]; |
|
| 6228 | + $classpath = $InfoFieldList[1]; |
|
| 6229 | + $getnomurlparam = (empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
| 6230 | + if (!empty($classpath)) |
|
| 6231 | 6231 | { |
| 6232 | 6232 | dol_include_once($InfoFieldList[1]); |
| 6233 | 6233 | if ($classname && class_exists($classname)) |
| 6234 | 6234 | { |
| 6235 | 6235 | $object = new $classname($this->db); |
| 6236 | 6236 | $object->fetch($value); |
| 6237 | - $value=$object->getNomUrl($getnomurlparam); |
|
| 6237 | + $value = $object->getNomUrl($getnomurlparam); |
|
| 6238 | 6238 | } |
| 6239 | 6239 | } |
| 6240 | 6240 | else |
@@ -6243,15 +6243,15 @@ discard block |
||
| 6243 | 6243 | return 'Error bad setup of extrafield'; |
| 6244 | 6244 | } |
| 6245 | 6245 | } |
| 6246 | - else $value=''; |
|
| 6246 | + else $value = ''; |
|
| 6247 | 6247 | } |
| 6248 | 6248 | elseif ($type == 'text' || $type == 'html') |
| 6249 | 6249 | { |
| 6250 | - $value=dol_htmlentitiesbr($value); |
|
| 6250 | + $value = dol_htmlentitiesbr($value); |
|
| 6251 | 6251 | } |
| 6252 | 6252 | elseif ($type == 'password') |
| 6253 | 6253 | { |
| 6254 | - $value=preg_replace('/./i','*',$value); |
|
| 6254 | + $value = preg_replace('/./i', '*', $value); |
|
| 6255 | 6255 | } |
| 6256 | 6256 | elseif ($type == 'array') |
| 6257 | 6257 | { |
@@ -6259,7 +6259,7 @@ discard block |
||
| 6259 | 6259 | } |
| 6260 | 6260 | |
| 6261 | 6261 | //print $type.'-'.$size; |
| 6262 | - $out=$value; |
|
| 6262 | + $out = $value; |
|
| 6263 | 6263 | |
| 6264 | 6264 | return $out; |
| 6265 | 6265 | } |
@@ -6276,11 +6276,11 @@ discard block |
||
| 6276 | 6276 | * @param string $onetrtd All fields in same tr td |
| 6277 | 6277 | * @return string |
| 6278 | 6278 | */ |
| 6279 | - function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) |
|
| 6279 | + function showOptionals($extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0) |
|
| 6280 | 6280 | { |
| 6281 | 6281 | global $db, $conf, $langs, $action, $form; |
| 6282 | 6282 | |
| 6283 | - if (! is_object($form)) $form=new Form($db); |
|
| 6283 | + if (!is_object($form)) $form = new Form($db); |
|
| 6284 | 6284 | |
| 6285 | 6285 | $out = ''; |
| 6286 | 6286 | |
@@ -6291,10 +6291,10 @@ discard block |
||
| 6291 | 6291 | $out .= "\n"; |
| 6292 | 6292 | |
| 6293 | 6293 | $e = 0; |
| 6294 | - foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
| 6294 | + foreach ($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
| 6295 | 6295 | { |
| 6296 | 6296 | // Show only the key field in params |
| 6297 | - if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue; |
|
| 6297 | + if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) continue; |
|
| 6298 | 6298 | |
| 6299 | 6299 | $enabled = 1; |
| 6300 | 6300 | if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
@@ -6308,25 +6308,25 @@ discard block |
||
| 6308 | 6308 | $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
| 6309 | 6309 | } |
| 6310 | 6310 | |
| 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 |
|
| 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 | 6312 | if (empty($perms)) continue; |
| 6313 | 6313 | |
| 6314 | 6314 | // Load language if required |
| 6315 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6315 | + if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6316 | 6316 | |
| 6317 | - $colspan='3'; |
|
| 6318 | - if (is_array($params) && count($params)>0) { |
|
| 6319 | - if (array_key_exists('colspan',$params)) { |
|
| 6320 | - $colspan=$params['colspan']; |
|
| 6317 | + $colspan = '3'; |
|
| 6318 | + if (is_array($params) && count($params) > 0) { |
|
| 6319 | + if (array_key_exists('colspan', $params)) { |
|
| 6320 | + $colspan = $params['colspan']; |
|
| 6321 | 6321 | } |
| 6322 | 6322 | } |
| 6323 | 6323 | |
| 6324 | - switch($mode) { |
|
| 6324 | + switch ($mode) { |
|
| 6325 | 6325 | case "view": |
| 6326 | - $value=$this->array_options["options_".$key.$keysuffix]; |
|
| 6326 | + $value = $this->array_options["options_".$key.$keysuffix]; |
|
| 6327 | 6327 | break; |
| 6328 | 6328 | case "edit": |
| 6329 | - $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 6329 | + $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 6330 | 6330 | // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc') |
| 6331 | 6331 | if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
| 6332 | 6332 | { |
@@ -6337,7 +6337,7 @@ discard block |
||
| 6337 | 6337 | $value = $getposttemp; |
| 6338 | 6338 | } |
| 6339 | 6339 | } else { |
| 6340 | - $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
| 6340 | + $value = $this->array_options["options_".$key]; // No GET, no POST, no default value, so we take value of object. |
|
| 6341 | 6341 | } |
| 6342 | 6342 | //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
| 6343 | 6343 | break; |
@@ -6349,11 +6349,11 @@ discard block |
||
| 6349 | 6349 | } |
| 6350 | 6350 | else |
| 6351 | 6351 | { |
| 6352 | - $csstyle=''; |
|
| 6353 | - $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
| 6354 | - if (is_array($params) && count($params)>0) { |
|
| 6355 | - if (array_key_exists('style',$params)) { |
|
| 6356 | - $csstyle=$params['style']; |
|
| 6352 | + $csstyle = ''; |
|
| 6353 | + $class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
| 6354 | + if (is_array($params) && count($params) > 0) { |
|
| 6355 | + if (array_key_exists('style', $params)) { |
|
| 6356 | + $csstyle = $params['style']; |
|
| 6357 | 6357 | } |
| 6358 | 6358 | } |
| 6359 | 6359 | |
@@ -6366,43 +6366,43 @@ discard block |
||
| 6366 | 6366 | |
| 6367 | 6367 | $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
| 6368 | 6368 | |
| 6369 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
| 6369 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
| 6370 | 6370 | { |
| 6371 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; } |
|
| 6371 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan = '0'; } |
|
| 6372 | 6372 | } |
| 6373 | 6373 | |
| 6374 | 6374 | if ($action == 'selectlines') { $colspan++; } |
| 6375 | 6375 | |
| 6376 | 6376 | // Convert date into timestamp format (value in memory must be a timestamp) |
| 6377 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime'))) |
|
| 6377 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime'))) |
|
| 6378 | 6378 | { |
| 6379 | - $datenotinstring = $this->array_options['options_' . $key]; |
|
| 6380 | - if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
| 6379 | + $datenotinstring = $this->array_options['options_'.$key]; |
|
| 6380 | + if (!is_numeric($this->array_options['options_'.$key])) // For backward compatibility |
|
| 6381 | 6381 | { |
| 6382 | 6382 | $datenotinstring = $this->db->jdate($datenotinstring); |
| 6383 | 6383 | } |
| 6384 | - $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; |
|
| 6384 | + $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 | 6385 | } |
| 6386 | 6386 | // Convert float submited string into real php numeric (value in memory must be a php numeric) |
| 6387 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double'))) |
|
| 6387 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double'))) |
|
| 6388 | 6388 | { |
| 6389 | - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)):$this->array_options['options_'.$key]; |
|
| 6389 | + $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)) : $this->array_options['options_'.$key]; |
|
| 6390 | 6390 | } |
| 6391 | 6391 | |
| 6392 | 6392 | $labeltoshow = $langs->trans($label); |
| 6393 | 6393 | |
| 6394 | 6394 | $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'; |
|
| 6395 | + if (GETPOST('action', 'none') == 'create') $out .= 'create'; |
|
| 6396 | + if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6397 | 6397 | $out .= '">'; |
| 6398 | - if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6398 | + if (!empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6399 | 6399 | else $out .= $labeltoshow; |
| 6400 | 6400 | $out .= '</td>'; |
| 6401 | 6401 | |
| 6402 | 6402 | $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
| 6403 | - $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
| 6403 | + $out .= '<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan ? ' colspan="'.$colspan.'"' : '').'>'; |
|
| 6404 | 6404 | |
| 6405 | - switch($mode) { |
|
| 6405 | + switch ($mode) { |
|
| 6406 | 6406 | case "view": |
| 6407 | 6407 | $out .= $extrafields->showOutputField($key, $value); |
| 6408 | 6408 | break; |
@@ -6413,14 +6413,14 @@ discard block |
||
| 6413 | 6413 | |
| 6414 | 6414 | $out .= '</td>'; |
| 6415 | 6415 | |
| 6416 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 6416 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 6417 | 6417 | else $out .= '</tr>'; |
| 6418 | 6418 | $e++; |
| 6419 | 6419 | } |
| 6420 | 6420 | } |
| 6421 | 6421 | $out .= "\n"; |
| 6422 | 6422 | // Add code to manage list depending on others |
| 6423 | - if (! empty($conf->use_javascript_ajax)) { |
|
| 6423 | + if (!empty($conf->use_javascript_ajax)) { |
|
| 6424 | 6424 | $out .= ' |
| 6425 | 6425 | <script type="text/javascript"> |
| 6426 | 6426 | jQuery(document).ready(function() { |
@@ -6466,7 +6466,7 @@ discard block |
||
| 6466 | 6466 | global $user; |
| 6467 | 6467 | |
| 6468 | 6468 | $element = $this->element; |
| 6469 | - if ($element == 'facturerec') $element='facture'; |
|
| 6469 | + if ($element == 'facturerec') $element = 'facture'; |
|
| 6470 | 6470 | |
| 6471 | 6471 | return $user->rights->{$element}; |
| 6472 | 6472 | } |
@@ -6483,15 +6483,15 @@ discard block |
||
| 6483 | 6483 | * @param int $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old thirdparty may already exists on new one) |
| 6484 | 6484 | * @return bool True if success, False if error |
| 6485 | 6485 | */ |
| 6486 | - public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
| 6486 | + public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) |
|
| 6487 | 6487 | { |
| 6488 | 6488 | foreach ($tables as $table) |
| 6489 | 6489 | { |
| 6490 | 6490 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
| 6491 | 6491 | |
| 6492 | - if (! $db->query($sql)) |
|
| 6492 | + if (!$db->query($sql)) |
|
| 6493 | 6493 | { |
| 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. |
|
| 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. |
|
| 6495 | 6495 | //$this->errors = $db->lasterror(); |
| 6496 | 6496 | return false; |
| 6497 | 6497 | } |
@@ -6525,7 +6525,7 @@ discard block |
||
| 6525 | 6525 | else |
| 6526 | 6526 | { |
| 6527 | 6527 | // Get cost price for margin calculation |
| 6528 | - if (! empty($fk_product)) |
|
| 6528 | + if (!empty($fk_product)) |
|
| 6529 | 6529 | { |
| 6530 | 6530 | if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') |
| 6531 | 6531 | { |
@@ -6562,7 +6562,7 @@ discard block |
||
| 6562 | 6562 | } |
| 6563 | 6563 | } |
| 6564 | 6564 | |
| 6565 | - if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice'))) |
|
| 6565 | + if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1', 'pmp', 'costprice'))) |
|
| 6566 | 6566 | { |
| 6567 | 6567 | require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
| 6568 | 6568 | $productFournisseur = new ProductFournisseur($this->db); |
@@ -6599,18 +6599,18 @@ discard block |
||
| 6599 | 6599 | * @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead) |
| 6600 | 6600 | * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto |
| 6601 | 6601 | */ |
| 6602 | - function show_photos($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $notitle=0, $usesharelink=0) |
|
| 6602 | + function show_photos($modulepart, $sdir, $size = 0, $nbmax = 0, $nbbyrow = 5, $showfilename = 0, $showaction = 0, $maxHeight = 120, $maxWidth = 160, $nolink = 0, $notitle = 0, $usesharelink = 0) |
|
| 6603 | 6603 | { |
| 6604 | 6604 | // phpcs:enable |
| 6605 | - global $conf,$user,$langs; |
|
| 6605 | + global $conf, $user, $langs; |
|
| 6606 | 6606 | |
| 6607 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; |
|
| 6608 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; |
|
| 6607 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 6608 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
| 6609 | 6609 | |
| 6610 | - $sortfield='position_name'; |
|
| 6611 | - $sortorder='asc'; |
|
| 6610 | + $sortfield = 'position_name'; |
|
| 6611 | + $sortorder = 'asc'; |
|
| 6612 | 6612 | |
| 6613 | - $dir = $sdir . '/'; |
|
| 6613 | + $dir = $sdir.'/'; |
|
| 6614 | 6614 | $pdir = '/'; |
| 6615 | 6615 | if ($modulepart == 'ticket') |
| 6616 | 6616 | { |
@@ -6624,28 +6624,28 @@ discard block |
||
| 6624 | 6624 | } |
| 6625 | 6625 | |
| 6626 | 6626 | // For backward compatibility |
| 6627 | - if ($modulepart == 'product' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
| 6627 | + if ($modulepart == 'product' && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
| 6628 | 6628 | { |
| 6629 | - $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6630 | - $pdir = '/' . get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6629 | + $dir = $sdir.'/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; |
|
| 6630 | + $pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; |
|
| 6631 | 6631 | } |
| 6632 | 6632 | |
| 6633 | 6633 | // Defined relative dir to DOL_DATA_ROOT |
| 6634 | 6634 | $relativedir = ''; |
| 6635 | 6635 | if ($dir) |
| 6636 | 6636 | { |
| 6637 | - $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
| 6638 | - $relativedir = preg_replace('/^[\\/]/','',$relativedir); |
|
| 6639 | - $relativedir = preg_replace('/[\\/]$/','',$relativedir); |
|
| 6637 | + $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir); |
|
| 6638 | + $relativedir = preg_replace('/^[\\/]/', '', $relativedir); |
|
| 6639 | + $relativedir = preg_replace('/[\\/]$/', '', $relativedir); |
|
| 6640 | 6640 | } |
| 6641 | 6641 | |
| 6642 | 6642 | $dirthumb = $dir.'thumbs/'; |
| 6643 | 6643 | $pdirthumb = $pdir.'thumbs/'; |
| 6644 | 6644 | |
| 6645 | - $return ='<!-- Photo -->'."\n"; |
|
| 6646 | - $nbphoto=0; |
|
| 6645 | + $return = '<!-- Photo -->'."\n"; |
|
| 6646 | + $nbphoto = 0; |
|
| 6647 | 6647 | |
| 6648 | - $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6648 | + $filearray = dol_dir_list($dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); |
|
| 6649 | 6649 | |
| 6650 | 6650 | /*if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs |
| 6651 | 6651 | { |
@@ -6659,12 +6659,12 @@ discard block |
||
| 6659 | 6659 | { |
| 6660 | 6660 | if ($sortfield && $sortorder) |
| 6661 | 6661 | { |
| 6662 | - $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 6662 | + $filearray = dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 6663 | 6663 | } |
| 6664 | 6664 | |
| 6665 | - foreach($filearray as $key => $val) |
|
| 6665 | + foreach ($filearray as $key => $val) |
|
| 6666 | 6666 | { |
| 6667 | - $photo=''; |
|
| 6667 | + $photo = ''; |
|
| 6668 | 6668 | $file = $val['name']; |
| 6669 | 6669 | |
| 6670 | 6670 | //if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory |
@@ -6679,36 +6679,36 @@ discard block |
||
| 6679 | 6679 | if ($size == 1 || $size == 'small') { // Format vignette |
| 6680 | 6680 | |
| 6681 | 6681 | // Find name of thumb file |
| 6682 | - $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
|
| 6683 | - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
| 6682 | + $photo_vignette = basename(getImageFileNameForSize($dir.$file, '_small')); |
|
| 6683 | + if (!dol_is_file($dirthumb.$photo_vignette)) $photo_vignette = ''; |
|
| 6684 | 6684 | |
| 6685 | 6685 | // Get filesize of original file |
| 6686 | - $imgarray=dol_getImageSize($dir.$photo); |
|
| 6686 | + $imgarray = dol_getImageSize($dir.$photo); |
|
| 6687 | 6687 | |
| 6688 | 6688 | if ($nbbyrow > 0) |
| 6689 | 6689 | { |
| 6690 | - if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 6690 | + if ($nbphoto == 1) $return .= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 6691 | 6691 | |
| 6692 | - if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
| 6693 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
|
| 6692 | + if ($nbphoto % $nbbyrow == 1) $return .= '<tr align=center valign=middle border=1>'; |
|
| 6693 | + $return .= '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">'; |
|
| 6694 | 6694 | } |
| 6695 | 6695 | else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
| 6696 | 6696 | |
| 6697 | - $return.= "\n"; |
|
| 6697 | + $return .= "\n"; |
|
| 6698 | 6698 | |
| 6699 | - $relativefile=preg_replace('/^\//', '', $pdir.$photo); |
|
| 6699 | + $relativefile = preg_replace('/^\//', '', $pdir.$photo); |
|
| 6700 | 6700 | if (empty($nolink)) |
| 6701 | 6701 | { |
| 6702 | - $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">'; |
|
| 6702 | + $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">'; |
|
| 6705 | 6705 | } |
| 6706 | 6706 | |
| 6707 | 6707 | // Show image (width height=$maxHeight) |
| 6708 | 6708 | // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
| 6709 | - $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile; |
|
| 6710 | - $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; |
|
| 6711 | - if ($notitle) $alt=''; |
|
| 6709 | + $alt = $langs->transnoentitiesnoconv('File').': '.$relativefile; |
|
| 6710 | + $alt .= ' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; |
|
| 6711 | + if ($notitle) $alt = ''; |
|
| 6712 | 6712 | |
| 6713 | 6713 | if ($usesharelink) |
| 6714 | 6714 | { |
@@ -6716,81 +6716,81 @@ discard block |
||
| 6716 | 6716 | { |
| 6717 | 6717 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
| 6718 | 6718 | { |
| 6719 | - $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
| 6720 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6719 | + $return .= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
| 6720 | + $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 | 6721 | } |
| 6722 | 6722 | else { |
| 6723 | - $return.= '<!-- Show original file -->'; |
|
| 6724 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6723 | + $return .= '<!-- Show original file -->'; |
|
| 6724 | + $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 | 6725 | } |
| 6726 | 6726 | } |
| 6727 | 6727 | else |
| 6728 | 6728 | { |
| 6729 | - $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
|
| 6730 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6729 | + $return .= '<!-- Show nophoto file (because file is not shared) -->'; |
|
| 6730 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6731 | 6731 | } |
| 6732 | 6732 | } |
| 6733 | 6733 | else |
| 6734 | 6734 | { |
| 6735 | 6735 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
| 6736 | 6736 | { |
| 6737 | - $return.= '<!-- Show thumb -->'; |
|
| 6738 | - $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).'">'; |
|
| 6737 | + $return .= '<!-- Show thumb -->'; |
|
| 6738 | + $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 | 6739 | } |
| 6740 | 6740 | else { |
| 6741 | - $return.= '<!-- Show original file -->'; |
|
| 6742 | - $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).'">'; |
|
| 6741 | + $return .= '<!-- Show original file -->'; |
|
| 6742 | + $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 | 6743 | } |
| 6744 | 6744 | } |
| 6745 | 6745 | |
| 6746 | - if (empty($nolink)) $return.= '</a>'; |
|
| 6747 | - $return.="\n"; |
|
| 6746 | + if (empty($nolink)) $return .= '</a>'; |
|
| 6747 | + $return .= "\n"; |
|
| 6748 | 6748 | |
| 6749 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6749 | + if ($showfilename) $return .= '<br>'.$viewfilename; |
|
| 6750 | 6750 | if ($showaction) |
| 6751 | 6751 | { |
| 6752 | - $return.= '<br>'; |
|
| 6752 | + $return .= '<br>'; |
|
| 6753 | 6753 | // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
| 6754 | 6754 | if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) |
| 6755 | 6755 | { |
| 6756 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' </a>'; |
|
| 6756 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').' </a>'; |
|
| 6757 | 6757 | } |
| 6758 | 6758 | // Special cas for product |
| 6759 | 6759 | if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
| 6760 | 6760 | { |
| 6761 | 6761 | // Link to resize |
| 6762 | - $return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> '; |
|
| 6762 | + $return .= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> '; |
|
| 6763 | 6763 | |
| 6764 | 6764 | // Link to delete |
| 6765 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6766 | - $return.= img_delete().'</a>'; |
|
| 6765 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6766 | + $return .= img_delete().'</a>'; |
|
| 6767 | 6767 | } |
| 6768 | 6768 | } |
| 6769 | - $return.= "\n"; |
|
| 6769 | + $return .= "\n"; |
|
| 6770 | 6770 | |
| 6771 | 6771 | if ($nbbyrow > 0) |
| 6772 | 6772 | { |
| 6773 | - $return.= '</td>'; |
|
| 6774 | - if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
| 6773 | + $return .= '</td>'; |
|
| 6774 | + if (($nbphoto % $nbbyrow) == 0) $return .= '</tr>'; |
|
| 6775 | 6775 | } |
| 6776 | - else if ($nbbyrow < 0) $return.='</div>'; |
|
| 6776 | + else if ($nbbyrow < 0) $return .= '</div>'; |
|
| 6777 | 6777 | } |
| 6778 | 6778 | |
| 6779 | 6779 | if (empty($size)) { // Format origine |
| 6780 | - $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
| 6780 | + $return .= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
| 6781 | 6781 | |
| 6782 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6782 | + if ($showfilename) $return .= '<br>'.$viewfilename; |
|
| 6783 | 6783 | if ($showaction) |
| 6784 | 6784 | { |
| 6785 | 6785 | // Special case for product |
| 6786 | 6786 | if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
| 6787 | 6787 | { |
| 6788 | 6788 | // Link to resize |
| 6789 | - $return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> '; |
|
| 6789 | + $return .= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> '; |
|
| 6790 | 6790 | |
| 6791 | 6791 | // Link to delete |
| 6792 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6793 | - $return.= img_delete().'</a>'; |
|
| 6792 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6793 | + $return .= img_delete().'</a>'; |
|
| 6794 | 6794 | } |
| 6795 | 6795 | } |
| 6796 | 6796 | } |
@@ -6800,18 +6800,18 @@ discard block |
||
| 6800 | 6800 | } |
| 6801 | 6801 | } |
| 6802 | 6802 | |
| 6803 | - if ($size==1 || $size=='small') |
|
| 6803 | + if ($size == 1 || $size == 'small') |
|
| 6804 | 6804 | { |
| 6805 | 6805 | if ($nbbyrow > 0) |
| 6806 | 6806 | { |
| 6807 | 6807 | // Ferme tableau |
| 6808 | 6808 | while ($nbphoto % $nbbyrow) |
| 6809 | 6809 | { |
| 6810 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; |
|
| 6810 | + $return .= '<td width="'.ceil(100 / $nbbyrow).'%"> </td>'; |
|
| 6811 | 6811 | $nbphoto++; |
| 6812 | 6812 | } |
| 6813 | 6813 | |
| 6814 | - if ($nbphoto) $return.= '</table>'; |
|
| 6814 | + if ($nbphoto) $return .= '</table>'; |
|
| 6815 | 6815 | } |
| 6816 | 6816 | } |
| 6817 | 6817 | } |
@@ -6830,9 +6830,9 @@ discard block |
||
| 6830 | 6830 | */ |
| 6831 | 6831 | protected function isArray($info) |
| 6832 | 6832 | { |
| 6833 | - if(is_array($info)) |
|
| 6833 | + if (is_array($info)) |
|
| 6834 | 6834 | { |
| 6835 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6835 | + if (isset($info['type']) && $info['type'] == 'array') return true; |
|
| 6836 | 6836 | else return false; |
| 6837 | 6837 | } |
| 6838 | 6838 | else return false; |
@@ -6846,9 +6846,9 @@ discard block |
||
| 6846 | 6846 | */ |
| 6847 | 6847 | protected function isNull($info) |
| 6848 | 6848 | { |
| 6849 | - if(is_array($info)) |
|
| 6849 | + if (is_array($info)) |
|
| 6850 | 6850 | { |
| 6851 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6851 | + if (isset($info['type']) && $info['type'] == 'null') return true; |
|
| 6852 | 6852 | else return false; |
| 6853 | 6853 | } |
| 6854 | 6854 | else return false; |
@@ -6862,7 +6862,7 @@ discard block |
||
| 6862 | 6862 | */ |
| 6863 | 6863 | public function isDate($info) |
| 6864 | 6864 | { |
| 6865 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6865 | + if (isset($info['type']) && ($info['type'] == 'date' || $info['type'] == 'datetime' || $info['type'] == 'timestamp')) return true; |
|
| 6866 | 6866 | else return false; |
| 6867 | 6867 | } |
| 6868 | 6868 | |
@@ -6874,9 +6874,9 @@ discard block |
||
| 6874 | 6874 | */ |
| 6875 | 6875 | public function isInt($info) |
| 6876 | 6876 | { |
| 6877 | - if(is_array($info)) |
|
| 6877 | + if (is_array($info)) |
|
| 6878 | 6878 | { |
| 6879 | - if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true; |
|
| 6879 | + if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) return true; |
|
| 6880 | 6880 | else return false; |
| 6881 | 6881 | } |
| 6882 | 6882 | else return false; |
@@ -6890,7 +6890,7 @@ discard block |
||
| 6890 | 6890 | */ |
| 6891 | 6891 | public function isFloat($info) |
| 6892 | 6892 | { |
| 6893 | - if(is_array($info)) |
|
| 6893 | + if (is_array($info)) |
|
| 6894 | 6894 | { |
| 6895 | 6895 | if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true; |
| 6896 | 6896 | else return false; |
@@ -6906,9 +6906,9 @@ discard block |
||
| 6906 | 6906 | */ |
| 6907 | 6907 | public function isText($info) |
| 6908 | 6908 | { |
| 6909 | - if(is_array($info)) |
|
| 6909 | + if (is_array($info)) |
|
| 6910 | 6910 | { |
| 6911 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6911 | + if (isset($info['type']) && $info['type'] == 'text') return true; |
|
| 6912 | 6912 | else return false; |
| 6913 | 6913 | } |
| 6914 | 6914 | else return false; |
@@ -6922,9 +6922,9 @@ discard block |
||
| 6922 | 6922 | */ |
| 6923 | 6923 | protected function isIndex($info) |
| 6924 | 6924 | { |
| 6925 | - if(is_array($info)) |
|
| 6925 | + if (is_array($info)) |
|
| 6926 | 6926 | { |
| 6927 | - if(isset($info['index']) && $info['index']==true) return true; |
|
| 6927 | + if (isset($info['index']) && $info['index'] == true) return true; |
|
| 6928 | 6928 | else return false; |
| 6929 | 6929 | } |
| 6930 | 6930 | else return false; |
@@ -6940,13 +6940,13 @@ discard block |
||
| 6940 | 6940 | { |
| 6941 | 6941 | global $conf; |
| 6942 | 6942 | |
| 6943 | - $queryarray=array(); |
|
| 6943 | + $queryarray = array(); |
|
| 6944 | 6944 | foreach ($this->fields as $field=>$info) // Loop on definition of fields |
| 6945 | 6945 | { |
| 6946 | 6946 | // Depending on field type ('datetime', ...) |
| 6947 | - if($this->isDate($info)) |
|
| 6947 | + if ($this->isDate($info)) |
|
| 6948 | 6948 | { |
| 6949 | - if(empty($this->{$field})) |
|
| 6949 | + if (empty($this->{$field})) |
|
| 6950 | 6950 | { |
| 6951 | 6951 | $queryarray[$field] = null; |
| 6952 | 6952 | } |
@@ -6955,10 +6955,10 @@ discard block |
||
| 6955 | 6955 | $queryarray[$field] = $this->db->idate($this->{$field}); |
| 6956 | 6956 | } |
| 6957 | 6957 | } |
| 6958 | - else if($this->isArray($info)) |
|
| 6958 | + else if ($this->isArray($info)) |
|
| 6959 | 6959 | { |
| 6960 | - if(! empty($this->{$field})) { |
|
| 6961 | - if(! is_array($this->{$field})) { |
|
| 6960 | + if (!empty($this->{$field})) { |
|
| 6961 | + if (!is_array($this->{$field})) { |
|
| 6962 | 6962 | $this->{$field} = array($this->{$field}); |
| 6963 | 6963 | } |
| 6964 | 6964 | $queryarray[$field] = serialize($this->{$field}); |
@@ -6966,19 +6966,19 @@ discard block |
||
| 6966 | 6966 | $queryarray[$field] = null; |
| 6967 | 6967 | } |
| 6968 | 6968 | } |
| 6969 | - else if($this->isInt($info)) |
|
| 6969 | + else if ($this->isInt($info)) |
|
| 6970 | 6970 | { |
| 6971 | - if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity; |
|
| 6971 | + if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field] = $conf->entity; |
|
| 6972 | 6972 | else |
| 6973 | 6973 | { |
| 6974 | 6974 | $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. |
|
| 6975 | + if (empty($queryarray[$field])) $queryarray[$field] = 0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6976 | 6976 | } |
| 6977 | 6977 | } |
| 6978 | - else if($this->isFloat($info)) |
|
| 6978 | + else if ($this->isFloat($info)) |
|
| 6979 | 6979 | { |
| 6980 | 6980 | $queryarray[$field] = (double) price2num($this->{$field}); |
| 6981 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6981 | + if (empty($queryarray[$field])) $queryarray[$field] = 0; |
|
| 6982 | 6982 | } |
| 6983 | 6983 | else |
| 6984 | 6984 | { |
@@ -6986,7 +6986,7 @@ discard block |
||
| 6986 | 6986 | } |
| 6987 | 6987 | |
| 6988 | 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; |
|
| 6989 | + if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 6990 | 6990 | } |
| 6991 | 6991 | |
| 6992 | 6992 | return $queryarray; |
@@ -7002,35 +7002,35 @@ discard block |
||
| 7002 | 7002 | { |
| 7003 | 7003 | foreach ($this->fields as $field => $info) |
| 7004 | 7004 | { |
| 7005 | - if($this->isDate($info)) |
|
| 7005 | + if ($this->isDate($info)) |
|
| 7006 | 7006 | { |
| 7007 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; |
|
| 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 | 7008 | else $this->{$field} = strtotime($obj->{$field}); |
| 7009 | 7009 | } |
| 7010 | - elseif($this->isArray($info)) |
|
| 7010 | + elseif ($this->isArray($info)) |
|
| 7011 | 7011 | { |
| 7012 | - if(! empty($obj->{$field})) { |
|
| 7012 | + if (!empty($obj->{$field})) { |
|
| 7013 | 7013 | $this->{$field} = @unserialize($obj->{$field}); |
| 7014 | 7014 | // Hack for data not in UTF8 |
| 7015 | - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field})); |
|
| 7015 | + if ($this->{$field } === false) @unserialize(utf8_decode($obj->{$field})); |
|
| 7016 | 7016 | } else { |
| 7017 | 7017 | $this->{$field} = array(); |
| 7018 | 7018 | } |
| 7019 | 7019 | } |
| 7020 | - elseif($this->isInt($info)) |
|
| 7020 | + elseif ($this->isInt($info)) |
|
| 7021 | 7021 | { |
| 7022 | 7022 | if ($field == 'rowid') $this->id = (int) $obj->{$field}; |
| 7023 | 7023 | else $this->{$field} = (int) $obj->{$field}; |
| 7024 | 7024 | } |
| 7025 | - elseif($this->isFloat($info)) |
|
| 7025 | + elseif ($this->isFloat($info)) |
|
| 7026 | 7026 | { |
| 7027 | 7027 | $this->{$field} = (double) $obj->{$field}; |
| 7028 | 7028 | } |
| 7029 | - elseif($this->isNull($info)) |
|
| 7029 | + elseif ($this->isNull($info)) |
|
| 7030 | 7030 | { |
| 7031 | 7031 | $val = $obj->{$field}; |
| 7032 | 7032 | // zero is not null |
| 7033 | - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); |
|
| 7033 | + $this->{$field} = (is_null($val) || (empty($val) && $val !== 0 && $val !== '0') ? null : $val); |
|
| 7034 | 7034 | } |
| 7035 | 7035 | else |
| 7036 | 7036 | { |
@@ -7039,7 +7039,7 @@ discard block |
||
| 7039 | 7039 | } |
| 7040 | 7040 | |
| 7041 | 7041 | // 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; |
|
| 7042 | + if (!isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7043 | 7043 | } |
| 7044 | 7044 | |
| 7045 | 7045 | /** |
@@ -7081,14 +7081,14 @@ discard block |
||
| 7081 | 7081 | |
| 7082 | 7082 | $error = 0; |
| 7083 | 7083 | |
| 7084 | - $now=dol_now(); |
|
| 7084 | + $now = dol_now(); |
|
| 7085 | 7085 | |
| 7086 | 7086 | $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; |
|
| 7089 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 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; |
|
| 7089 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 7090 | 7090 | |
| 7091 | - $keys=array(); |
|
| 7091 | + $keys = array(); |
|
| 7092 | 7092 | $values = array(); |
| 7093 | 7093 | foreach ($fieldvalues as $k => $v) { |
| 7094 | 7094 | $keys[$k] = $k; |
@@ -7097,58 +7097,58 @@ discard block |
||
| 7097 | 7097 | } |
| 7098 | 7098 | |
| 7099 | 7099 | // Clean and check mandatory |
| 7100 | - foreach($keys as $key) |
|
| 7100 | + foreach ($keys as $key) |
|
| 7101 | 7101 | { |
| 7102 | 7102 | // 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]=''; |
|
| 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] = ''; |
|
| 7105 | 7105 | |
| 7106 | 7106 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7107 | - if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
|
| 7107 | + if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && !isset($values[$key]) && is_null($val['default'])) |
|
| 7108 | 7108 | { |
| 7109 | 7109 | $error++; |
| 7110 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
| 7110 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
| 7111 | 7111 | } |
| 7112 | 7112 | |
| 7113 | 7113 | // 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'; |
|
| 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'; |
|
| 7116 | 7116 | } |
| 7117 | 7117 | |
| 7118 | 7118 | if ($error) return -1; |
| 7119 | 7119 | |
| 7120 | 7120 | $this->db->begin(); |
| 7121 | 7121 | |
| 7122 | - if (! $error) |
|
| 7122 | + if (!$error) |
|
| 7123 | 7123 | { |
| 7124 | 7124 | $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
| 7125 | - $sql.= ' ('.implode( ", ", $keys ).')'; |
|
| 7126 | - $sql.= ' VALUES ('.implode( ", ", $values ).')'; |
|
| 7125 | + $sql .= ' ('.implode(", ", $keys).')'; |
|
| 7126 | + $sql .= ' VALUES ('.implode(", ", $values).')'; |
|
| 7127 | 7127 | |
| 7128 | 7128 | $res = $this->db->query($sql); |
| 7129 | - if ($res===false) { |
|
| 7129 | + if ($res === false) { |
|
| 7130 | 7130 | $error++; |
| 7131 | 7131 | $this->errors[] = $this->db->lasterror(); |
| 7132 | 7132 | } |
| 7133 | 7133 | } |
| 7134 | 7134 | |
| 7135 | - if (! $error) |
|
| 7135 | + if (!$error) |
|
| 7136 | 7136 | { |
| 7137 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
| 7137 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
| 7138 | 7138 | } |
| 7139 | 7139 | |
| 7140 | 7140 | // Create extrafields |
| 7141 | - if (! $error) |
|
| 7141 | + if (!$error) |
|
| 7142 | 7142 | { |
| 7143 | - $result=$this->insertExtraFields(); |
|
| 7143 | + $result = $this->insertExtraFields(); |
|
| 7144 | 7144 | if ($result < 0) $error++; |
| 7145 | 7145 | } |
| 7146 | 7146 | |
| 7147 | 7147 | // Triggers |
| 7148 | - if (! $error && ! $notrigger) |
|
| 7148 | + if (!$error && !$notrigger) |
|
| 7149 | 7149 | { |
| 7150 | 7150 | // Call triggers |
| 7151 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
| 7151 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_CREATE', $user); |
|
| 7152 | 7152 | if ($result < 0) { $error++; } |
| 7153 | 7153 | // End call triggers |
| 7154 | 7154 | } |
@@ -7177,13 +7177,13 @@ discard block |
||
| 7177 | 7177 | if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
| 7178 | 7178 | |
| 7179 | 7179 | $sql = 'SELECT '.$this->getFieldList(); |
| 7180 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7180 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7181 | 7181 | |
| 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; |
|
| 7186 | - $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
| 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; |
|
| 7186 | + $sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
| 7187 | 7187 | |
| 7188 | 7188 | $res = $this->db->query($sql); |
| 7189 | 7189 | if ($res) |
@@ -7220,14 +7220,14 @@ discard block |
||
| 7220 | 7220 | |
| 7221 | 7221 | $error = 0; |
| 7222 | 7222 | |
| 7223 | - $now=dol_now(); |
|
| 7223 | + $now = dol_now(); |
|
| 7224 | 7224 | |
| 7225 | 7225 | $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; |
|
| 7228 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 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; |
|
| 7228 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 7229 | 7229 | |
| 7230 | - $keys=array(); |
|
| 7230 | + $keys = array(); |
|
| 7231 | 7231 | $values = array(); |
| 7232 | 7232 | foreach ($fieldvalues as $k => $v) { |
| 7233 | 7233 | $keys[$k] = $k; |
@@ -7237,10 +7237,10 @@ discard block |
||
| 7237 | 7237 | } |
| 7238 | 7238 | |
| 7239 | 7239 | // Clean and check mandatory |
| 7240 | - foreach($keys as $key) |
|
| 7240 | + foreach ($keys as $key) |
|
| 7241 | 7241 | { |
| 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 |
|
| 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 |
|
| 7244 | 7244 | |
| 7245 | 7245 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7246 | 7246 | /* |
@@ -7251,13 +7251,13 @@ discard block |
||
| 7251 | 7251 | }*/ |
| 7252 | 7252 | } |
| 7253 | 7253 | |
| 7254 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
| 7254 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode(',', $tmp).' WHERE rowid='.$this->id; |
|
| 7255 | 7255 | |
| 7256 | 7256 | $this->db->begin(); |
| 7257 | - if (! $error) |
|
| 7257 | + if (!$error) |
|
| 7258 | 7258 | { |
| 7259 | 7259 | $res = $this->db->query($sql); |
| 7260 | - if ($res===false) |
|
| 7260 | + if ($res === false) |
|
| 7261 | 7261 | { |
| 7262 | 7262 | $error++; |
| 7263 | 7263 | $this->errors[] = $this->db->lasterror(); |
@@ -7265,9 +7265,9 @@ discard block |
||
| 7265 | 7265 | } |
| 7266 | 7266 | |
| 7267 | 7267 | // Update extrafield |
| 7268 | - if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) |
|
| 7268 | + if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) |
|
| 7269 | 7269 | { |
| 7270 | - $result=$this->insertExtraFields(); |
|
| 7270 | + $result = $this->insertExtraFields(); |
|
| 7271 | 7271 | if ($result < 0) |
| 7272 | 7272 | { |
| 7273 | 7273 | $error++; |
@@ -7275,10 +7275,10 @@ discard block |
||
| 7275 | 7275 | } |
| 7276 | 7276 | |
| 7277 | 7277 | // Triggers |
| 7278 | - if (! $error && ! $notrigger) |
|
| 7278 | + if (!$error && !$notrigger) |
|
| 7279 | 7279 | { |
| 7280 | 7280 | // Call triggers |
| 7281 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
| 7281 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $user); |
|
| 7282 | 7282 | if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail |
| 7283 | 7283 | // End call triggers |
| 7284 | 7284 | } |
@@ -7301,68 +7301,68 @@ discard block |
||
| 7301 | 7301 | * @param int $forcechilddeletion 0=no, 1=Force deletion of children |
| 7302 | 7302 | * @return int <=0 if KO, >0 if OK |
| 7303 | 7303 | */ |
| 7304 | - public function deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0) |
|
| 7304 | + public function deleteCommon(User $user, $notrigger = false, $forcechilddeletion = 0) |
|
| 7305 | 7305 | { |
| 7306 | - $error=0; |
|
| 7306 | + $error = 0; |
|
| 7307 | 7307 | |
| 7308 | 7308 | $this->db->begin(); |
| 7309 | 7309 | |
| 7310 | 7310 | if ($forcechilddeletion) |
| 7311 | 7311 | { |
| 7312 | - foreach($this->childtables as $table) |
|
| 7312 | + foreach ($this->childtables as $table) |
|
| 7313 | 7313 | { |
| 7314 | 7314 | $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
| 7315 | 7315 | $resql = $this->db->query($sql); |
| 7316 | - if (! $resql) |
|
| 7316 | + if (!$resql) |
|
| 7317 | 7317 | { |
| 7318 | - $this->error=$this->db->lasterror(); |
|
| 7319 | - $this->errors[]=$this->error; |
|
| 7318 | + $this->error = $this->db->lasterror(); |
|
| 7319 | + $this->errors[] = $this->error; |
|
| 7320 | 7320 | $this->db->rollback(); |
| 7321 | 7321 | return -1; |
| 7322 | 7322 | } |
| 7323 | 7323 | } |
| 7324 | 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. |
|
| 7325 | + elseif (!empty($this->fk_element) && !empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7326 | 7326 | { |
| 7327 | 7327 | $objectisused = $this->isObjectUsed($this->id); |
| 7328 | - if (! empty($objectisused)) |
|
| 7328 | + if (!empty($objectisused)) |
|
| 7329 | 7329 | { |
| 7330 | 7330 | dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
| 7331 | - $this->error='ErrorRecordHasChildren'; |
|
| 7332 | - $this->errors[]=$this->error; |
|
| 7331 | + $this->error = 'ErrorRecordHasChildren'; |
|
| 7332 | + $this->errors[] = $this->error; |
|
| 7333 | 7333 | $this->db->rollback(); |
| 7334 | 7334 | return 0; |
| 7335 | 7335 | } |
| 7336 | 7336 | } |
| 7337 | 7337 | |
| 7338 | - if (! $error) { |
|
| 7339 | - if (! $notrigger) { |
|
| 7338 | + if (!$error) { |
|
| 7339 | + if (!$notrigger) { |
|
| 7340 | 7340 | // Call triggers |
| 7341 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 7341 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 7342 | 7342 | if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail |
| 7343 | 7343 | // End call triggers |
| 7344 | 7344 | } |
| 7345 | 7345 | } |
| 7346 | 7346 | |
| 7347 | - if (! $error && ! empty($this->isextrafieldmanaged)) |
|
| 7347 | + if (!$error && !empty($this->isextrafieldmanaged)) |
|
| 7348 | 7348 | { |
| 7349 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
| 7350 | - $sql.= " WHERE fk_object=" . $this->id; |
|
| 7349 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; |
|
| 7350 | + $sql .= " WHERE fk_object=".$this->id; |
|
| 7351 | 7351 | |
| 7352 | 7352 | $resql = $this->db->query($sql); |
| 7353 | - if (! $resql) |
|
| 7353 | + if (!$resql) |
|
| 7354 | 7354 | { |
| 7355 | 7355 | $this->errors[] = $this->db->lasterror(); |
| 7356 | 7356 | $error++; |
| 7357 | 7357 | } |
| 7358 | 7358 | } |
| 7359 | 7359 | |
| 7360 | - if (! $error) |
|
| 7360 | + if (!$error) |
|
| 7361 | 7361 | { |
| 7362 | 7362 | $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
| 7363 | 7363 | |
| 7364 | 7364 | $res = $this->db->query($sql); |
| 7365 | - if($res===false) { |
|
| 7365 | + if ($res === false) { |
|
| 7366 | 7366 | $error++; |
| 7367 | 7367 | $this->errors[] = $this->db->lasterror(); |
| 7368 | 7368 | } |
@@ -7403,9 +7403,9 @@ discard block |
||
| 7403 | 7403 | require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
| 7404 | 7404 | |
| 7405 | 7405 | $comment = new Comment($this->db); |
| 7406 | - $result=$comment->fetchAllFor($this->element, $this->id); |
|
| 7407 | - if ($result<0) { |
|
| 7408 | - $this->errors=array_merge($this->errors, $comment->errors); |
|
| 7406 | + $result = $comment->fetchAllFor($this->element, $this->id); |
|
| 7407 | + if ($result < 0) { |
|
| 7408 | + $this->errors = array_merge($this->errors, $comment->errors); |
|
| 7409 | 7409 | return -1; |
| 7410 | 7410 | } else { |
| 7411 | 7411 | $this->comments = $comment->comments; |
@@ -99,18 +99,18 @@ discard block |
||
| 99 | 99 | // Put here code to add control on parameters values |
| 100 | 100 | |
| 101 | 101 | // Insert request |
| 102 | - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; |
|
| 102 | + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; |
|
| 103 | 103 | |
| 104 | - $sql.= 'code,'; |
|
| 105 | - $sql.= 'label'; |
|
| 106 | - $sql.= 'active'; |
|
| 104 | + $sql .= 'code,'; |
|
| 105 | + $sql .= 'label'; |
|
| 106 | + $sql .= 'active'; |
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | 109 | $sql .= ') VALUES ('; |
| 110 | 110 | |
| 111 | - $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").','; |
|
| 112 | - $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; |
|
| 113 | - $sql .= ' '.(! isset($this->active)?'NULL':$this->active); |
|
| 111 | + $sql .= ' '.(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").','; |
|
| 112 | + $sql .= ' '.(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").','; |
|
| 113 | + $sql .= ' '.(!isset($this->active) ? 'NULL' : $this->active); |
|
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | $sql .= ')'; |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | $resql = $this->db->query($sql); |
| 121 | 121 | if (!$resql) { |
| 122 | - $error ++; |
|
| 123 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 124 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 122 | + $error++; |
|
| 123 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 124 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (!$error) { |
| 128 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
| 128 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
| 129 | 129 | |
| 130 | 130 | // Uncomment this and change MYOBJECT to your own tag if you |
| 131 | 131 | // want this action to call a trigger. |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if ($error) { |
| 143 | 143 | $this->db->rollback(); |
| 144 | 144 | |
| 145 | - return - 1 * $error; |
|
| 145 | + return -1 * $error; |
|
| 146 | 146 | } else { |
| 147 | 147 | $this->db->commit(); |
| 148 | 148 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @return int <0 if KO, 0 if not found, >0 if OK |
| 161 | 161 | */ |
| 162 | - public function fetch($id,$code='',$label='') |
|
| 162 | + public function fetch($id, $code = '', $label = '') |
|
| 163 | 163 | { |
| 164 | 164 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 165 | 165 | |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | $sql .= " t.active"; |
| 172 | 172 | |
| 173 | 173 | |
| 174 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
|
| 175 | - if ($id) $sql.= " WHERE t.id = ".$id; |
|
| 176 | - elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 177 | - elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
| 174 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
|
| 175 | + if ($id) $sql .= " WHERE t.id = ".$id; |
|
| 176 | + elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 177 | + elseif ($label) $sql .= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | $resql = $this->db->query($sql); |
@@ -204,10 +204,10 @@ discard block |
||
| 204 | 204 | return 0; |
| 205 | 205 | } |
| 206 | 206 | } else { |
| 207 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 208 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 207 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 208 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 209 | 209 | |
| 210 | - return - 1; |
|
| 210 | + return -1; |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @return int <0 if KO, >0 if OK |
| 225 | 225 | */ |
| 226 | - public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') |
|
| 226 | + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') |
|
| 227 | 227 | { |
| 228 | 228 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 229 | 229 | |
@@ -235,24 +235,24 @@ discard block |
||
| 235 | 235 | $sql .= " t.active"; |
| 236 | 236 | |
| 237 | 237 | |
| 238 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; |
|
| 238 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
|
| 239 | 239 | |
| 240 | 240 | // Manage filter |
| 241 | 241 | $sqlwhere = array(); |
| 242 | 242 | if (count($filter) > 0) { |
| 243 | 243 | foreach ($filter as $key => $value) { |
| 244 | - $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; |
|
| 244 | + $sqlwhere [] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; |
|
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | if (count($sqlwhere) > 0) { |
| 249 | - $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); |
|
| 249 | + $sql .= ' WHERE '.implode(' '.$filtermode.' ', $sqlwhere); |
|
| 250 | 250 | } |
| 251 | 251 | if (!empty($sortfield)) { |
| 252 | - $sql .= $this->db->order($sortfield,$sortorder); |
|
| 252 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
| 253 | 253 | } |
| 254 | 254 | if (!empty($limit)) { |
| 255 | - $sql .= ' ' . $this->db->plimit($limit, $offset); |
|
| 255 | + $sql .= ' '.$this->db->plimit($limit, $offset); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | $resql = $this->db->query($sql); |
@@ -272,10 +272,10 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | return $num; |
| 274 | 274 | } else { |
| 275 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 276 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 275 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 276 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 277 | 277 | |
| 278 | - return - 1; |
|
| 278 | + return -1; |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | |
@@ -309,22 +309,22 @@ discard block |
||
| 309 | 309 | // Put here code to add a control on parameters values |
| 310 | 310 | |
| 311 | 311 | // Update request |
| 312 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; |
|
| 312 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
| 313 | 313 | |
| 314 | - $sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").','; |
|
| 315 | - $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").','; |
|
| 316 | - $sql .= ' active = '.(isset($this->active)?$this->active:"null"); |
|
| 314 | + $sql .= ' code = '.(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").','; |
|
| 315 | + $sql .= ' label = '.(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").','; |
|
| 316 | + $sql .= ' active = '.(isset($this->active) ? $this->active : "null"); |
|
| 317 | 317 | |
| 318 | 318 | |
| 319 | - $sql .= ' WHERE rowid=' . $this->id; |
|
| 319 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 320 | 320 | |
| 321 | 321 | $this->db->begin(); |
| 322 | 322 | |
| 323 | 323 | $resql = $this->db->query($sql); |
| 324 | 324 | if (!$resql) { |
| 325 | - $error ++; |
|
| 326 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 327 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 325 | + $error++; |
|
| 326 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 327 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | // Uncomment this and change MYOBJECT to your own tag if you |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | if ($error) { |
| 342 | 342 | $this->db->rollback(); |
| 343 | 343 | |
| 344 | - return - 1 * $error; |
|
| 344 | + return -1 * $error; |
|
| 345 | 345 | } else { |
| 346 | 346 | $this->db->commit(); |
| 347 | 347 | |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | // If you need to delete child tables to, you can insert them here |
| 379 | 379 | |
| 380 | 380 | if (!$error) { |
| 381 | - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; |
|
| 382 | - $sql .= ' WHERE rowid=' . $this->id; |
|
| 381 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 382 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 383 | 383 | |
| 384 | 384 | $resql = $this->db->query($sql); |
| 385 | 385 | if (!$resql) { |
| 386 | - $error ++; |
|
| 387 | - $this->errors[] = 'Error ' . $this->db->lasterror(); |
|
| 388 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 386 | + $error++; |
|
| 387 | + $this->errors[] = 'Error '.$this->db->lasterror(); |
|
| 388 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | 391 | |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | if ($error) { |
| 394 | 394 | $this->db->rollback(); |
| 395 | 395 | |
| 396 | - return - 1 * $error; |
|
| 396 | + return -1 * $error; |
|
| 397 | 397 | } else { |
| 398 | 398 | $this->db->commit(); |
| 399 | 399 | |
@@ -431,9 +431,9 @@ discard block |
||
| 431 | 431 | |
| 432 | 432 | // Other options |
| 433 | 433 | if ($result < 0) { |
| 434 | - $error ++; |
|
| 434 | + $error++; |
|
| 435 | 435 | $this->errors = $object->errors; |
| 436 | - dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); |
|
| 436 | + dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // End |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | } else { |
| 445 | 445 | $this->db->rollback(); |
| 446 | 446 | |
| 447 | - return - 1; |
|
| 447 | + return -1; |
|
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * \ingroup core |
| 23 | 23 | * \brief Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire |
| 24 | 24 | */ |
| 25 | -require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php'; |
|
| 25 | +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public $toname; |
| 46 | 46 | public $tomail; |
| 47 | 47 | |
| 48 | - public $withsubstit; // Show substitution array |
|
| 48 | + public $withsubstit; // Show substitution array |
|
| 49 | 49 | public $withfrom; |
| 50 | 50 | public $withto; |
| 51 | 51 | public $withtopic; |
@@ -57,18 +57,18 @@ discard block |
||
| 57 | 57 | public $withtopicreadonly; |
| 58 | 58 | public $withcancel; |
| 59 | 59 | |
| 60 | - public $substit=array(); |
|
| 61 | - public $param=array(); |
|
| 60 | + public $substit = array(); |
|
| 61 | + public $param = array(); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @var string Error code (or message) |
| 65 | 65 | */ |
| 66 | - public $error=''; |
|
| 66 | + public $error = ''; |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @var string[] Array of error strings |
| 70 | 70 | */ |
| 71 | - public $errors=array(); |
|
| 71 | + public $errors = array(); |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -80,16 +80,16 @@ discard block |
||
| 80 | 80 | { |
| 81 | 81 | $this->db = $db; |
| 82 | 82 | |
| 83 | - $this->withfrom=1; |
|
| 84 | - $this->withto=1; |
|
| 85 | - $this->withtopic=1; |
|
| 86 | - $this->withbody=1; |
|
| 83 | + $this->withfrom = 1; |
|
| 84 | + $this->withto = 1; |
|
| 85 | + $this->withtopic = 1; |
|
| 86 | + $this->withbody = 1; |
|
| 87 | 87 | |
| 88 | - $this->withfromreadonly=1; |
|
| 89 | - $this->withreplytoreadonly=1; |
|
| 90 | - $this->withtoreadonly=0; |
|
| 91 | - $this->withtopicreadonly=0; |
|
| 92 | - $this->withbodyreadonly=0; |
|
| 88 | + $this->withfromreadonly = 1; |
|
| 89 | + $this->withreplytoreadonly = 1; |
|
| 90 | + $this->withtoreadonly = 0; |
|
| 91 | + $this->withtopicreadonly = 0; |
|
| 92 | + $this->withbodyreadonly = 0; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -100,17 +100,17 @@ discard block |
||
| 100 | 100 | * @param int $showform Show form tags and submit button (recommanded is to use with value 0) |
| 101 | 101 | * @return void |
| 102 | 102 | */ |
| 103 | - function show_form($morecss='titlefield', $showform=1) |
|
| 103 | + function show_form($morecss = 'titlefield', $showform = 1) |
|
| 104 | 104 | { |
| 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)) $form = new Form($this->db); |
|
| 109 | 109 | |
| 110 | 110 | // Load translation files required by the page |
| 111 | 111 | $langs->loadLangs(array('other', 'mails', 'sms')); |
| 112 | 112 | |
| 113 | - $soc=new Societe($this->db); |
|
| 113 | + $soc = new Societe($this->db); |
|
| 114 | 114 | if (!empty($this->withtosocid) && $this->withtosocid > 0) |
| 115 | 115 | { |
| 116 | 116 | $soc->fetch($this->withtosocid); |
@@ -141,15 +141,15 @@ discard block |
||
| 141 | 141 | print "<table class=\"border centpercent\">\n"; |
| 142 | 142 | |
| 143 | 143 | // Substitution array |
| 144 | - if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this. |
|
| 144 | + if (!empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this. |
|
| 145 | 145 | { |
| 146 | 146 | print "<tr><td colspan=\"2\">"; |
| 147 | - $help=""; |
|
| 148 | - foreach($this->substit as $key => $val) |
|
| 147 | + $help = ""; |
|
| 148 | + foreach ($this->substit as $key => $val) |
|
| 149 | 149 | { |
| 150 | - $help.=$key.' -> '.$langs->trans($val).'<br>'; |
|
| 150 | + $help .= $key.' -> '.$langs->trans($val).'<br>'; |
|
| 151 | 151 | } |
| 152 | - print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"),$help); |
|
| 152 | + print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"), $help); |
|
| 153 | 153 | print "</td></tr>\n"; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | if ($this->fromtype == 'user') |
| 165 | 165 | { |
| 166 | 166 | $langs->load("users"); |
| 167 | - $fuser=new User($this->db); |
|
| 167 | + $fuser = new User($this->db); |
|
| 168 | 168 | $fuser->fetch($this->fromid); |
| 169 | 169 | print $fuser->getNomUrl(1); |
| 170 | 170 | print ' '; |
@@ -203,19 +203,19 @@ discard block |
||
| 203 | 203 | $resultsender = $sms->SmsSenderList(); |
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | - catch(Exception $e) |
|
| 206 | + catch (Exception $e) |
|
| 207 | 207 | { |
| 208 | - dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
|
| 208 | + dol_print_error('', 'Error to get list of senders: '.$e->getMessage()); |
|
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | else if (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module' |
| 212 | 212 | { |
| 213 | - $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE); |
|
| 214 | - $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]); |
|
| 213 | + $tmp = explode('@', $conf->global->MAIN_SMS_SENDMODE); |
|
| 214 | + $classfile = $tmp[0]; $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]); |
|
| 215 | 215 | dol_include_once('/'.$module.'/class/'.$classfile.'.class.php'); |
| 216 | 216 | try |
| 217 | 217 | { |
| 218 | - $classname=ucfirst($classfile); |
|
| 218 | + $classname = ucfirst($classfile); |
|
| 219 | 219 | if (class_exists($classname)) |
| 220 | 220 | { |
| 221 | 221 | $sms = new $classname($this->db); |
@@ -224,26 +224,26 @@ discard block |
||
| 224 | 224 | else |
| 225 | 225 | { |
| 226 | 226 | $sms = new stdClass(); |
| 227 | - $sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found'; |
|
| 227 | + $sms->error = 'The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found'; |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | - catch(Exception $e) |
|
| 230 | + catch (Exception $e) |
|
| 231 | 231 | { |
| 232 | - dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
|
| 232 | + dol_print_error('', 'Error to get list of senders: '.$e->getMessage()); |
|
| 233 | 233 | exit; |
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | else |
| 237 | 237 | { |
| 238 | 238 | dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING); |
| 239 | - $resultsender=array(); |
|
| 240 | - $resultsender[0]->number=$this->fromsms; |
|
| 239 | + $resultsender = array(); |
|
| 240 | + $resultsender[0]->number = $this->fromsms; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | if (is_array($resultsender) && count($resultsender) > 0) |
| 244 | 244 | { |
| 245 | 245 | print '<select name="fromsms" id="fromsms" class="flat">'; |
| 246 | - foreach($resultsender as $obj) |
|
| 246 | + foreach ($resultsender as $obj) |
|
| 247 | 247 | { |
| 248 | 248 | print '<option value="'.$obj->number.'">'.$obj->number.'</option>'; |
| 249 | 249 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | else |
| 253 | 253 | { |
| 254 | 254 | print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound"); |
| 255 | - if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error; |
|
| 255 | + if (is_object($sms) && !empty($sms->error)) print ' '.$sms->error; |
|
| 256 | 256 | print '</span>'; |
| 257 | 257 | } |
| 258 | 258 | print '</td>'; |
@@ -265,22 +265,22 @@ discard block |
||
| 265 | 265 | { |
| 266 | 266 | print '<tr><td>'; |
| 267 | 267 | //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients"); |
| 268 | - $moretext=''; |
|
| 269 | - print $form->textwithpicto($langs->trans("SmsTo"),$moretext); |
|
| 268 | + $moretext = ''; |
|
| 269 | + print $form->textwithpicto($langs->trans("SmsTo"), $moretext); |
|
| 270 | 270 | print '</td><td>'; |
| 271 | 271 | if ($this->withtoreadonly) |
| 272 | 272 | { |
| 273 | - print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; |
|
| 273 | + print (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : ""; |
|
| 274 | 274 | } |
| 275 | 275 | else |
| 276 | 276 | { |
| 277 | - 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 | - if (! empty($this->withtosocid) && $this->withtosocid > 0) |
|
| 277 | + 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 | + if (!empty($this->withtosocid) && $this->withtosocid > 0) |
|
| 279 | 279 | { |
| 280 | - $liste=array(); |
|
| 280 | + $liste = array(); |
|
| 281 | 281 | foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value) |
| 282 | 282 | { |
| 283 | - $liste[$key]=$value; |
|
| 283 | + $liste[$key] = $value; |
|
| 284 | 284 | } |
| 285 | 285 | print " ".$langs->trans("or")." "; |
| 286 | 286 | //var_dump($_REQUEST);exit; |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | // Message |
| 295 | 295 | if ($this->withbody) |
| 296 | 296 | { |
| 297 | - $defaultmessage=''; |
|
| 298 | - if ($this->param["models"]=='body') |
|
| 297 | + $defaultmessage = ''; |
|
| 298 | + if ($this->param["models"] == 'body') |
|
| 299 | 299 | { |
| 300 | - $defaultmessage=$this->withbody; |
|
| 300 | + $defaultmessage = $this->withbody; |
|
| 301 | 301 | } |
| 302 | - $defaultmessage=make_substitutions($defaultmessage,$this->substit); |
|
| 303 | - if (isset($_POST["message"])) $defaultmessage=$_POST["message"]; |
|
| 304 | - $defaultmessage=str_replace('\n',"\n",$defaultmessage); |
|
| 302 | + $defaultmessage = make_substitutions($defaultmessage, $this->substit); |
|
| 303 | + if (isset($_POST["message"])) $defaultmessage = $_POST["message"]; |
|
| 304 | + $defaultmessage = str_replace('\n', "\n", $defaultmessage); |
|
| 305 | 305 | |
| 306 | 306 | print "<tr>"; |
| 307 | 307 | print '<td class="tdtop">'.$langs->trans("SmsText")."</td>"; |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | else |
| 315 | 315 | { |
| 316 | 316 | print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>'; |
| 317 | - print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>'; |
|
| 317 | + print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160 - dol_strlen($defaultmessage)).'</span></div></td>'; |
|
| 318 | 318 | } |
| 319 | 319 | print "</td></tr>\n"; |
| 320 | 320 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * \ingroup core |
| 21 | 21 | * \brief File of class of generic business class |
| 22 | 22 | */ |
| 23 | -require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; |
|
| 23 | +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -36,6 +36,6 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | function __construct($db) |
| 38 | 38 | { |
| 39 | - $this->db=$db; |
|
| 39 | + $this->db = $db; |
|
| 40 | 40 | } |
| 41 | 41 | } |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | public $sendmode; |
| 41 | 41 | public $sendsetup; |
| 42 | 42 | |
| 43 | - var $subject; // Topic: Subject of email |
|
| 44 | - var $addr_from; // From: Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to). |
|
| 43 | + var $subject; // Topic: Subject of email |
|
| 44 | + var $addr_from; // From: Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to). |
|
| 45 | 45 | // Sender: Who send the email ("Sender" has sent emails on behalf of "From"). |
| 46 | 46 | // Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, add Sender field with an email of the protected domain. |
| 47 | 47 | // Return-Path: Email where to send bounds. |
| 48 | - var $reply_to; // Reply-To: Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined) |
|
| 49 | - var $errors_to; // Errors-To: Email where to send errors. |
|
| 48 | + var $reply_to; // Reply-To: Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined) |
|
| 49 | + var $errors_to; // Errors-To: Email where to send errors. |
|
| 50 | 50 | var $addr_to; |
| 51 | 51 | var $addr_cc; |
| 52 | 52 | var $addr_bcc; |
@@ -63,10 +63,10 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * @var string Error code (or message) |
| 65 | 65 | */ |
| 66 | - public $error=''; |
|
| 66 | + public $error = ''; |
|
| 67 | 67 | |
| 68 | - var $smtps; // Contains SMTPs object (if this method is used) |
|
| 69 | - var $phpmailer; // Contains PHPMailer object (if this method is used) |
|
| 68 | + var $smtps; // Contains SMTPs object (if this method is used) |
|
| 69 | + var $phpmailer; // Contains PHPMailer object (if this method is used) |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @var string CSS |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | // Image |
| 84 | 84 | var $html; |
| 85 | 85 | var $image_boundary; |
| 86 | - var $atleastoneimage=0; // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used). |
|
| 87 | - var $html_images=array(); |
|
| 88 | - var $images_encoded=array(); |
|
| 86 | + var $atleastoneimage = 0; // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used). |
|
| 87 | + var $html_images = array(); |
|
| 88 | + var $images_encoded = array(); |
|
| 89 | 89 | var $image_types = array( |
| 90 | 90 | 'gif' => 'image/gif', |
| 91 | 91 | 'jpg' => 'image/jpeg', |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | * @param string $sendcontext 'standard', 'emailing', ... (used to define with sending mode and parameters to use) |
| 120 | 120 | * @param string $replyto Reply-to email (will be set to same value than From by default if not provided) |
| 121 | 121 | */ |
| 122 | - function __construct($subject, $to, $from, $msg, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=0, $errors_to='', $css='', $trackid='', $moreinheader='', $sendcontext='standard', $replyto='') |
|
| 122 | + function __construct($subject, $to, $from, $msg, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = 0, $errors_to = '', $css = '', $trackid = '', $moreinheader = '', $sendcontext = 'standard', $replyto = '') |
|
| 123 | 123 | { |
| 124 | 124 | global $conf, $dolibarr_main_data_root; |
| 125 | 125 | |
| 126 | 126 | $this->sendcontext = $sendcontext; |
| 127 | 127 | |
| 128 | - if (empty($replyto)) $replyto=$from; |
|
| 128 | + if (empty($replyto)) $replyto = $from; |
|
| 129 | 129 | |
| 130 | 130 | // Define this->sendmode |
| 131 | 131 | $this->sendmode = ''; |
@@ -133,28 +133,28 @@ discard block |
||
| 133 | 133 | { |
| 134 | 134 | $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE_EMAILING; |
| 135 | 135 | } |
| 136 | - if (empty($this->sendmode)) $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE; |
|
| 137 | - if (empty($this->sendmode)) $this->sendmode='mail'; |
|
| 136 | + if (empty($this->sendmode)) $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE; |
|
| 137 | + if (empty($this->sendmode)) $this->sendmode = 'mail'; |
|
| 138 | 138 | |
| 139 | 139 | // We define end of line (RFC 821). |
| 140 | - $this->eol="\r\n"; |
|
| 140 | + $this->eol = "\r\n"; |
|
| 141 | 141 | // We define end of line for header fields (RFC 822bis section 2.3 says header must contains \r\n). |
| 142 | - $this->eol2="\r\n"; |
|
| 143 | - if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) |
|
| 142 | + $this->eol2 = "\r\n"; |
|
| 143 | + if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) |
|
| 144 | 144 | { |
| 145 | - $this->eol="\n"; |
|
| 146 | - $this->eol2="\n"; |
|
| 147 | - $moreinheader = str_replace("\r\n","\n",$moreinheader); |
|
| 145 | + $this->eol = "\n"; |
|
| 146 | + $this->eol2 = "\n"; |
|
| 147 | + $moreinheader = str_replace("\r\n", "\n", $moreinheader); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | // On defini mixed_boundary |
| 151 | - $this->mixed_boundary = "multipart_x." . time() . ".x_boundary"; |
|
| 151 | + $this->mixed_boundary = "multipart_x.".time().".x_boundary"; |
|
| 152 | 152 | |
| 153 | 153 | // On defini related_boundary |
| 154 | - $this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3); // Force md5 hash (does not contains special chars) |
|
| 154 | + $this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3); // Force md5 hash (does not contains special chars) |
|
| 155 | 155 | |
| 156 | 156 | // On defini alternative_boundary |
| 157 | - $this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3); // Force md5 hash (does not contains special chars) |
|
| 157 | + $this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3); // Force md5 hash (does not contains special chars) |
|
| 158 | 158 | |
| 159 | 159 | dol_syslog("CMailFile::CMailfile: sendmode=".$this->sendmode." charset=".$conf->file->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to, trackid=$trackid sendcontext=$sendcontext", LOG_DEBUG); |
| 160 | 160 | dol_syslog("CMailFile::CMailfile: subject=".$subject.", deliveryreceipt=".$deliveryreceipt.", msgishtml=".$msgishtml, LOG_DEBUG); |
@@ -162,13 +162,13 @@ discard block |
||
| 162 | 162 | if (empty($subject)) |
| 163 | 163 | { |
| 164 | 164 | dol_syslog("CMailFile::CMailfile: Try to send an email with empty subject"); |
| 165 | - $this->error='ErrorSubjectIsRequired'; |
|
| 165 | + $this->error = 'ErrorSubjectIsRequired'; |
|
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | 168 | if (empty($msg)) |
| 169 | 169 | { |
| 170 | 170 | dol_syslog("CMailFile::CMailfile: Try to send an email with empty body"); |
| 171 | - $msg='.'; // Avoid empty message (with empty message conten show a multipart structure) |
|
| 171 | + $msg = '.'; // Avoid empty message (with empty message conten show a multipart structure) |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // Detect if message is HTML (use fast method) |
@@ -185,21 +185,21 @@ discard block |
||
| 185 | 185 | global $dolibarr_main_url_root; |
| 186 | 186 | |
| 187 | 187 | // Define $urlwithroot |
| 188 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 189 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 188 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
| 189 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 190 | 190 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
| 191 | 191 | |
| 192 | 192 | // Replace relative /viewimage to absolute path |
| 193 | - $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep); |
|
| 193 | + $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep); |
|
| 194 | 194 | |
| 195 | - if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml=1; // To force to send everything with content type html. |
|
| 195 | + if (!empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml = 1; // To force to send everything with content type html. |
|
| 196 | 196 | |
| 197 | 197 | // Detect images |
| 198 | 198 | if ($this->msgishtml) |
| 199 | 199 | { |
| 200 | 200 | $this->html = $msg; |
| 201 | 201 | |
| 202 | - if (! empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS)) |
|
| 202 | + if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS)) |
|
| 203 | 203 | { |
| 204 | 204 | $findimg = $this->findHtmlImages($dolibarr_main_data_root.'/medias'); |
| 205 | 205 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | { |
| 212 | 212 | if ($this->html_images[$i]) |
| 213 | 213 | { |
| 214 | - $this->atleastoneimage=1; |
|
| 214 | + $this->atleastoneimage = 1; |
|
| 215 | 215 | dol_syslog("CMailFile::CMailfile: html_images[$i]['name']=".$this->html_images[$i]['name'], LOG_DEBUG); |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -225,14 +225,14 @@ discard block |
||
| 225 | 225 | { |
| 226 | 226 | if ($filename_list[$i]) |
| 227 | 227 | { |
| 228 | - $this->atleastonefile=1; |
|
| 228 | + $this->atleastonefile = 1; |
|
| 229 | 229 | dol_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG); |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | // 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; |
|
| 235 | + if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
| 236 | 236 | |
| 237 | 237 | // Action according to choosed sending method |
| 238 | 238 | if ($this->sendmode == 'mail') |
@@ -257,17 +257,17 @@ discard block |
||
| 257 | 257 | $this->trackid = $trackid; |
| 258 | 258 | |
| 259 | 259 | $smtp_headers = $this->write_smtpheaders(); |
| 260 | - if (! empty($moreinheader)) $smtp_headers.=$moreinheader; // $moreinheader contains the \r\n |
|
| 260 | + if (!empty($moreinheader)) $smtp_headers .= $moreinheader; // $moreinheader contains the \r\n |
|
| 261 | 261 | |
| 262 | 262 | // Define mime_headers |
| 263 | 263 | $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); |
| 264 | 264 | |
| 265 | - if (! empty($this->html)) |
|
| 265 | + if (!empty($this->html)) |
|
| 266 | 266 | { |
| 267 | 267 | if (!empty($css)) |
| 268 | 268 | { |
| 269 | 269 | $this->css = $css; |
| 270 | - $this->buildCSS(); // Build a css style (mode = all) into this->styleCSS and this->bodyCSS |
|
| 270 | + $this->buildCSS(); // Build a css style (mode = all) into this->styleCSS and this->bodyCSS |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | $msg = $this->html; |
@@ -279,20 +279,20 @@ discard block |
||
| 279 | 279 | // Add attachments to text_encoded |
| 280 | 280 | if ($this->atleastonefile) |
| 281 | 281 | { |
| 282 | - $files_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list); |
|
| 282 | + $files_encoded = $this->write_files($filename_list, $mimetype_list, $mimefilename_list); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // We now define $this->headers and $this->message |
| 286 | - $this->headers = $smtp_headers . $mime_headers; |
|
| 286 | + $this->headers = $smtp_headers.$mime_headers; |
|
| 287 | 287 | // On nettoie le header pour qu'il ne se termine pas par un retour chariot. |
| 288 | 288 | // Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees |
| 289 | 289 | // comme des injections mail par les serveurs de messagerie. |
| 290 | - $this->headers = preg_replace("/([\r\n]+)$/i","",$this->headers); |
|
| 290 | + $this->headers = preg_replace("/([\r\n]+)$/i", "", $this->headers); |
|
| 291 | 291 | |
| 292 | 292 | //$this->message = $this->eol.'This is a message with multiple parts in MIME format.'.$this->eol; |
| 293 | 293 | $this->message = 'This is a message with multiple parts in MIME format.'.$this->eol; |
| 294 | - $this->message.= $text_body . $files_encoded; |
|
| 295 | - $this->message.= "--" . $this->mixed_boundary . "--" . $this->eol; |
|
| 294 | + $this->message .= $text_body.$files_encoded; |
|
| 295 | + $this->message .= "--".$this->mixed_boundary."--".$this->eol; |
|
| 296 | 296 | } |
| 297 | 297 | else if ($this->sendmode == 'smtps') |
| 298 | 298 | { |
@@ -304,14 +304,14 @@ discard block |
||
| 304 | 304 | $smtps->setCharSet($conf->file->character_set_client); |
| 305 | 305 | |
| 306 | 306 | $smtps->setSubject($this->encodetorfc2822($subject)); |
| 307 | - $smtps->setTO($this->getValidAddress($to,0,1)); |
|
| 308 | - $smtps->setFrom($this->getValidAddress($from,0,1)); |
|
| 307 | + $smtps->setTO($this->getValidAddress($to, 0, 1)); |
|
| 308 | + $smtps->setFrom($this->getValidAddress($from, 0, 1)); |
|
| 309 | 309 | $smtps->setTrackId($trackid); |
| 310 | - $smtps->setReplyTo($this->getValidAddress($replyto,0,1)); |
|
| 310 | + $smtps->setReplyTo($this->getValidAddress($replyto, 0, 1)); |
|
| 311 | 311 | |
| 312 | - if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader); |
|
| 312 | + if (!empty($moreinheader)) $smtps->setMoreInHeader($moreinheader); |
|
| 313 | 313 | |
| 314 | - if (! empty($this->html)) |
|
| 314 | + if (!empty($this->html)) |
|
| 315 | 315 | { |
| 316 | 316 | if (!empty($css)) |
| 317 | 317 | { |
@@ -322,14 +322,14 @@ discard block |
||
| 322 | 322 | $msg = $this->checkIfHTML($msg); |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - if ($this->msgishtml) $smtps->setBodyContent($msg,'html'); |
|
| 326 | - else $smtps->setBodyContent($msg,'plain'); |
|
| 325 | + if ($this->msgishtml) $smtps->setBodyContent($msg, 'html'); |
|
| 326 | + else $smtps->setBodyContent($msg, 'plain'); |
|
| 327 | 327 | |
| 328 | 328 | if ($this->atleastoneimage) |
| 329 | 329 | { |
| 330 | 330 | foreach ($this->images_encoded as $img) |
| 331 | 331 | { |
| 332 | - $smtps->setImageInline($img['image_encoded'],$img['name'],$img['content_type'],$img['cid']); |
|
| 332 | + $smtps->setImageInline($img['image_encoded'], $img['name'], $img['content_type'], $img['cid']); |
|
| 333 | 333 | } |
| 334 | 334 | } |
| 335 | 335 | |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | { |
| 338 | 338 | foreach ($filename_list as $i => $val) |
| 339 | 339 | { |
| 340 | - $content=file_get_contents($filename_list[$i]); |
|
| 341 | - $smtps->setAttachment($content,$mimefilename_list[$i],$mimetype_list[$i]); |
|
| 340 | + $content = file_get_contents($filename_list[$i]); |
|
| 341 | + $smtps->setAttachment($content, $mimefilename_list[$i], $mimetype_list[$i]); |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | $smtps->setErrorsTo($errors_to); |
| 348 | 348 | $smtps->setDeliveryReceipt($deliveryreceipt); |
| 349 | 349 | |
| 350 | - $this->smtps=$smtps; |
|
| 350 | + $this->smtps = $smtps; |
|
| 351 | 351 | } |
| 352 | 352 | else if ($this->sendmode == 'swiftmailer') |
| 353 | 353 | { |
@@ -383,8 +383,8 @@ discard block |
||
| 383 | 383 | //$this->message = new Swift_SignedMessage(); |
| 384 | 384 | // Adding a trackid header to a message |
| 385 | 385 | $headers = $this->message->getHeaders(); |
| 386 | - $headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host); |
|
| 387 | - $headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host; |
|
| 386 | + $headers->addTextHeader('X-Dolibarr-TRACKID', $trackid.'@'.$host); |
|
| 387 | + $headerID = time().'.swiftmailer-dolibarr-'.$trackid.'@'.$host; |
|
| 388 | 388 | $msgid = $headers->get('Message-ID'); |
| 389 | 389 | $msgid->setId($headerID); |
| 390 | 390 | $headers->addIdHeader('References', $headerID); |
@@ -394,12 +394,12 @@ discard block |
||
| 394 | 394 | try { |
| 395 | 395 | $result = $this->message->setSubject($subject); |
| 396 | 396 | } catch (Exception $e) { |
| 397 | - $this->errors[] = $e->getMessage(); |
|
| 397 | + $this->errors[] = $e->getMessage(); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | // Set the From address with an associative array |
| 401 | 401 | //$this->message->setFrom(array('[email protected]' => 'John Doe')); |
| 402 | - if (! empty($from)) { |
|
| 402 | + if (!empty($from)) { |
|
| 403 | 403 | try { |
| 404 | 404 | $result = $this->message->setFrom($this->getArrayAddress($from)); |
| 405 | 405 | } catch (Exception $e) { |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | // Set the To addresses with an associative array |
| 411 | - if (! empty($to)) { |
|
| 411 | + if (!empty($to)) { |
|
| 412 | 412 | try { |
| 413 | 413 | $result = $this->message->setTo($this->getArrayAddress($to)); |
| 414 | 414 | } catch (Exception $e) { |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - if (! empty($replyto)) { |
|
| 419 | + if (!empty($replyto)) { |
|
| 420 | 420 | try { |
| 421 | 421 | $result = $this->message->SetReplyTo($this->getArrayAddress($replyto)); |
| 422 | 422 | } catch (Exception $e) { |
@@ -427,10 +427,10 @@ discard block |
||
| 427 | 427 | try { |
| 428 | 428 | $result = $this->message->setCharSet($conf->file->character_set_client); |
| 429 | 429 | } catch (Exception $e) { |
| 430 | - $this->errors[] = $e->getMessage(); |
|
| 430 | + $this->errors[] = $e->getMessage(); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if (! empty($this->html)) |
|
| 433 | + if (!empty($this->html)) |
|
| 434 | 434 | { |
| 435 | 435 | if (!empty($css)) |
| 436 | 436 | { |
@@ -455,11 +455,11 @@ discard block |
||
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | if ($this->msgishtml) { |
| 458 | - $this->message->setBody($msg,'text/html'); |
|
| 458 | + $this->message->setBody($msg, 'text/html'); |
|
| 459 | 459 | // And optionally an alternative body |
| 460 | 460 | $this->message->addPart(html_entity_decode(strip_tags($msg)), 'text/plain'); |
| 461 | 461 | } else { |
| 462 | - $this->message->setBody($msg,'text/plain'); |
|
| 462 | + $this->message->setBody($msg, 'text/plain'); |
|
| 463 | 463 | // And optionally an alternative body |
| 464 | 464 | $this->message->addPart($msg, 'text/html'); |
| 465 | 465 | } |
@@ -469,13 +469,13 @@ discard block |
||
| 469 | 469 | foreach ($filename_list as $i => $val) |
| 470 | 470 | { |
| 471 | 471 | //$this->message->attach(Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i])); |
| 472 | - $attachment = Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]); |
|
| 472 | + $attachment = Swift_Attachment::fromPath($filename_list[$i], $mimetype_list[$i]); |
|
| 473 | 473 | $this->message->attach($attachment); |
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - if (! empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc)); |
|
| 478 | - if (! empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc)); |
|
| 477 | + if (!empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc)); |
|
| 478 | + if (!empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc)); |
|
| 479 | 479 | //if (! empty($errors_to)) $this->message->setErrorsTo($this->getArrayAddress($errors_to); |
| 480 | 480 | if (isset($deliveryreceipt) && $deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($from)); |
| 481 | 481 | } |
@@ -495,25 +495,25 @@ discard block |
||
| 495 | 495 | */ |
| 496 | 496 | function sendfile() |
| 497 | 497 | { |
| 498 | - global $conf,$db,$langs; |
|
| 498 | + global $conf, $db, $langs; |
|
| 499 | 499 | |
| 500 | - $errorlevel=error_reporting(); |
|
| 500 | + $errorlevel = error_reporting(); |
|
| 501 | 501 | //error_reporting($errorlevel ^ E_WARNING); // Desactive warnings |
| 502 | 502 | |
| 503 | - $res=false; |
|
| 503 | + $res = false; |
|
| 504 | 504 | |
| 505 | 505 | if (empty($conf->global->MAIN_DISABLE_ALL_MAILS) || !empty($conf->global->MAIN_MAIL_FORCE_SENDTO)) |
| 506 | 506 | { |
| 507 | - require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; |
|
| 507 | + require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
| 508 | 508 | $hookmanager = new HookManager($db); |
| 509 | 509 | $hookmanager->initHooks(array('mail')); |
| 510 | 510 | |
| 511 | - $parameters=array(); $action=''; |
|
| 511 | + $parameters = array(); $action = ''; |
|
| 512 | 512 | $reshook = $hookmanager->executeHooks('sendMail', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 513 | 513 | if ($reshook < 0) |
| 514 | 514 | { |
| 515 | - $this->error = "Error in hook maildao sendMail " . $reshook; |
|
| 516 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR); |
|
| 515 | + $this->error = "Error in hook maildao sendMail ".$reshook; |
|
| 516 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
|
| 517 | 517 | |
| 518 | 518 | return $reshook; |
| 519 | 519 | } |
@@ -523,52 +523,52 @@ discard block |
||
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | // 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; |
|
| 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; |
|
| 527 | 527 | $tmparray1 = explode(',', $this->addr_to); |
| 528 | 528 | if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL) |
| 529 | 529 | { |
| 530 | 530 | $this->error = 'Too much recipients in to:'; |
| 531 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
|
| 531 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); |
|
| 532 | 532 | return false; |
| 533 | 533 | } |
| 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; |
|
| 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; |
|
| 535 | 535 | $tmparray2 = explode(',', $this->addr_cc); |
| 536 | 536 | if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL) |
| 537 | 537 | { |
| 538 | 538 | $this->error = 'Too much recipients in cc:'; |
| 539 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
|
| 539 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); |
|
| 540 | 540 | return false; |
| 541 | 541 | } |
| 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; |
|
| 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; |
|
| 543 | 543 | $tmparray3 = explode(',', $this->addr_bcc); |
| 544 | 544 | if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL) |
| 545 | 545 | { |
| 546 | 546 | $this->error = 'Too much recipients in bcc:'; |
| 547 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
|
| 547 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); |
|
| 548 | 548 | return false; |
| 549 | 549 | } |
| 550 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10; |
|
| 551 | - if ((count($tmparray1)+count($tmparray2)+count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL) |
|
| 550 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL = 10; |
|
| 551 | + if ((count($tmparray1) + count($tmparray2) + count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL) |
|
| 552 | 552 | { |
| 553 | 553 | $this->error = 'Too much recipients in to:, cc:, bcc:'; |
| 554 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
|
| 554 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING); |
|
| 555 | 555 | return false; |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER'; |
|
| 559 | - $keyforsmtpport ='MAIN_MAIL_SMTP_PORT'; |
|
| 560 | - $keyforsmtpid ='MAIN_MAIL_SMTPS_ID'; |
|
| 561 | - $keyforsmtppw ='MAIN_MAIL_SMTPS_PW'; |
|
| 562 | - $keyfortls ='MAIN_MAIL_EMAIL_TLS'; |
|
| 563 | - $keyforstarttls ='MAIN_MAIL_EMAIL_STARTTLS'; |
|
| 558 | + $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER'; |
|
| 559 | + $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT'; |
|
| 560 | + $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID'; |
|
| 561 | + $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW'; |
|
| 562 | + $keyfortls = 'MAIN_MAIL_EMAIL_TLS'; |
|
| 563 | + $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS'; |
|
| 564 | 564 | if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') |
| 565 | 565 | { |
| 566 | - $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING'; |
|
| 567 | - $keyforsmtpport ='MAIN_MAIL_SMTP_PORT_EMAILING'; |
|
| 568 | - $keyforsmtpid ='MAIN_MAIL_SMTPS_ID_EMAILING'; |
|
| 569 | - $keyforsmtppw ='MAIN_MAIL_SMTPS_PW_EMAILING'; |
|
| 570 | - $keyfortls ='MAIN_MAIL_EMAIL_TLS_EMAILING'; |
|
| 571 | - $keyforstarttls ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING'; |
|
| 566 | + $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING'; |
|
| 567 | + $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT_EMAILING'; |
|
| 568 | + $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID_EMAILING'; |
|
| 569 | + $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW_EMAILING'; |
|
| 570 | + $keyfortls = 'MAIN_MAIL_EMAIL_TLS_EMAILING'; |
|
| 571 | + $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS_EMAILING'; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO)) |
@@ -591,68 +591,68 @@ discard block |
||
| 591 | 591 | if (isset($_SERVER["WINDIR"])) |
| 592 | 592 | { |
| 593 | 593 | if (empty($this->addr_from)) $this->addr_from = '[email protected]'; |
| 594 | - @ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2)); |
|
| 594 | + @ini_set('sendmail_from', $this->getValidAddress($this->addr_from, 2)); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | // 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); |
|
| 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); |
|
| 600 | 600 | |
| 601 | - $res=true; |
|
| 602 | - if ($res && ! $this->subject) |
|
| 601 | + $res = true; |
|
| 602 | + if ($res && !$this->subject) |
|
| 603 | 603 | { |
| 604 | - $this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty"; |
|
| 604 | + $this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty"; |
|
| 605 | 605 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 606 | - $res=false; |
|
| 606 | + $res = false; |
|
| 607 | 607 | } |
| 608 | - $dest=$this->getValidAddress($this->addr_to,2); |
|
| 609 | - if ($res && ! $dest) |
|
| 608 | + $dest = $this->getValidAddress($this->addr_to, 2); |
|
| 609 | + if ($res && !$dest) |
|
| 610 | 610 | { |
| 611 | - $this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid"; |
|
| 611 | + $this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid"; |
|
| 612 | 612 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 613 | - $res=false; |
|
| 613 | + $res = false; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | if ($res) |
| 617 | 617 | { |
| 618 | - $additionnalparam = ''; // By default |
|
| 619 | - if (! empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F)) |
|
| 618 | + $additionnalparam = ''; // By default |
|
| 619 | + if (!empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F)) |
|
| 620 | 620 | { |
| 621 | 621 | // le "Return-Path" (retour des messages bounced) dans les header ne fonctionne pas avec tous les MTA |
| 622 | 622 | // Le forcage de la valeur grace à l'option -f de sendmail est donc possible si la constante MAIN_MAIL_ALLOW_SENDMAIL_F est definie. |
| 623 | 623 | // Having this variable defined may create problems with some sendmail (option -f refused) |
| 624 | 624 | // Having this variable not defined may create problems with some other sendmail (option -f required) |
| 625 | - $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) : '') ); |
|
| 625 | + $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 | 626 | } |
| 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 |
|
| 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 |
|
| 628 | 628 | { |
| 629 | - $additionnalparam .= ($additionnalparam?' ':'').'-ba'; |
|
| 629 | + $additionnalparam .= ($additionnalparam ? ' ' : '').'-ba'; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; // Use -U to add additionnal params |
|
| 632 | + if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam ? ' ' : '').'-U '.$additionnalparam; // Use -U to add additionnal params |
|
| 633 | 633 | |
| 634 | 634 | dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", additionnal_parameters=".$additionnalparam, LOG_DEBUG); |
| 635 | 635 | |
| 636 | - $this->message=stripslashes($this->message); |
|
| 636 | + $this->message = stripslashes($this->message); |
|
| 637 | 637 | |
| 638 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 638 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 639 | 639 | |
| 640 | - if (! empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam); |
|
| 640 | + if (!empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam); |
|
| 641 | 641 | else $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers); |
| 642 | 642 | |
| 643 | - if (! $res) |
|
| 643 | + if (!$res) |
|
| 644 | 644 | { |
| 645 | 645 | $langs->load("errors"); |
| 646 | - $this->error="Failed to send mail with php mail"; |
|
| 647 | - $linuxlike=1; |
|
| 648 | - if (preg_match('/^win/i',PHP_OS)) $linuxlike=0; |
|
| 649 | - if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0; |
|
| 650 | - if (! $linuxlike) |
|
| 646 | + $this->error = "Failed to send mail with php mail"; |
|
| 647 | + $linuxlike = 1; |
|
| 648 | + if (preg_match('/^win/i', PHP_OS)) $linuxlike = 0; |
|
| 649 | + if (preg_match('/^mac/i', PHP_OS)) $linuxlike = 0; |
|
| 650 | + if (!$linuxlike) |
|
| 651 | 651 | { |
| 652 | - $this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'); // This values are value used only for non linuxlike systems |
|
| 652 | + $this->error .= " to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'); // This values are value used only for non linuxlike systems |
|
| 653 | 653 | } |
| 654 | - $this->error.=".<br>"; |
|
| 655 | - $this->error.=$langs->trans("ErrorPhpMailDelivery"); |
|
| 654 | + $this->error .= ".<br>"; |
|
| 655 | + $this->error .= $langs->trans("ErrorPhpMailDelivery"); |
|
| 656 | 656 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 657 | 657 | } |
| 658 | 658 | else |
@@ -667,86 +667,86 @@ discard block |
||
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | // Restore parameters |
| 670 | - if (! empty($conf->global->$keyforsmtpserver)) ini_restore('SMTP'); |
|
| 671 | - if (! empty($conf->global->$keyforsmtpport)) ini_restore('smtp_port'); |
|
| 670 | + if (!empty($conf->global->$keyforsmtpserver)) ini_restore('SMTP'); |
|
| 671 | + if (!empty($conf->global->$keyforsmtpport)) ini_restore('smtp_port'); |
|
| 672 | 672 | } |
| 673 | 673 | else if ($this->sendmode == 'smtps') |
| 674 | 674 | { |
| 675 | - if (! is_object($this->smtps)) |
|
| 675 | + if (!is_object($this->smtps)) |
|
| 676 | 676 | { |
| 677 | - $this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors."; |
|
| 677 | + $this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors."; |
|
| 678 | 678 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 679 | 679 | return false; |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | // Use SMTPS library |
| 683 | 683 | // ------------------------------------------ |
| 684 | - $this->smtps->setTransportType(0); // Only this method is coded in SMTPs library |
|
| 684 | + $this->smtps->setTransportType(0); // Only this method is coded in SMTPs library |
|
| 685 | 685 | |
| 686 | 686 | // 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'); |
|
| 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'); |
|
| 689 | 689 | |
| 690 | 690 | // If we use SSL/TLS |
| 691 | - $server=$conf->global->$keyforsmtpserver; |
|
| 692 | - $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'; |
|
| 695 | - $server=($secure?$secure.'://':'').$server; |
|
| 691 | + $server = $conf->global->$keyforsmtpserver; |
|
| 692 | + $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'; |
|
| 695 | + $server = ($secure ? $secure.'://' : '').$server; |
|
| 696 | 696 | |
| 697 | - $port=$conf->global->$keyforsmtpport; |
|
| 697 | + $port = $conf->global->$keyforsmtpport; |
|
| 698 | 698 | |
| 699 | 699 | $this->smtps->setHost($server); |
| 700 | 700 | $this->smtps->setPort($port); // 25, 465...; |
| 701 | 701 | |
| 702 | - $loginid=''; $loginpass=''; |
|
| 703 | - if (! empty($conf->global->$keyforsmtpid)) |
|
| 702 | + $loginid = ''; $loginpass = ''; |
|
| 703 | + if (!empty($conf->global->$keyforsmtpid)) |
|
| 704 | 704 | { |
| 705 | 705 | $loginid = $conf->global->$keyforsmtpid; |
| 706 | 706 | $this->smtps->setID($loginid); |
| 707 | 707 | } |
| 708 | - if (! empty($conf->global->$keyforsmtppw)) |
|
| 708 | + if (!empty($conf->global->$keyforsmtppw)) |
|
| 709 | 709 | { |
| 710 | 710 | $loginpass = $conf->global->$keyforsmtppw; |
| 711 | 711 | $this->smtps->setPW($loginpass); |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - $res=true; |
|
| 715 | - $from=$this->smtps->getFrom('org'); |
|
| 716 | - if ($res && ! $from) |
|
| 714 | + $res = true; |
|
| 715 | + $from = $this->smtps->getFrom('org'); |
|
| 716 | + if ($res && !$from) |
|
| 717 | 717 | { |
| 718 | - $this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid"; |
|
| 718 | + $this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid"; |
|
| 719 | 719 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 720 | - $res=false; |
|
| 720 | + $res = false; |
|
| 721 | 721 | } |
| 722 | - $dest=$this->smtps->getTo(); |
|
| 723 | - if ($res && ! $dest) |
|
| 722 | + $dest = $this->smtps->getTo(); |
|
| 723 | + if ($res && !$dest) |
|
| 724 | 724 | { |
| 725 | - $this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid"; |
|
| 725 | + $this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid"; |
|
| 726 | 726 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 727 | - $res=false; |
|
| 727 | + $res = false; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | if ($res) |
| 731 | 731 | { |
| 732 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true); |
|
| 732 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true); |
|
| 733 | 733 | |
| 734 | - $result=$this->smtps->sendMsg(); |
|
| 734 | + $result = $this->smtps->sendMsg(); |
|
| 735 | 735 | //print $result; |
| 736 | 736 | |
| 737 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 737 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 738 | 738 | |
| 739 | - $result=$this->smtps->getErrors(); |
|
| 739 | + $result = $this->smtps->getErrors(); |
|
| 740 | 740 | if (empty($this->error) && empty($result)) |
| 741 | 741 | { |
| 742 | 742 | dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); |
| 743 | - $res=true; |
|
| 743 | + $res = true; |
|
| 744 | 744 | } |
| 745 | 745 | else |
| 746 | 746 | { |
| 747 | - if (empty($this->error)) $this->error=$result; |
|
| 747 | + if (empty($this->error)) $this->error = $result; |
|
| 748 | 748 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 749 | - $res=false; |
|
| 749 | + $res = false; |
|
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | } |
@@ -757,19 +757,19 @@ discard block |
||
| 757 | 757 | require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php'; |
| 758 | 758 | |
| 759 | 759 | // 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'); |
|
| 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'); |
|
| 762 | 762 | |
| 763 | 763 | // If we use SSL/TLS |
| 764 | 764 | $server = $conf->global->$keyforsmtpserver; |
| 765 | 765 | $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'; |
|
| 766 | + if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure = 'ssl'; |
|
| 767 | + if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure = 'tls'; |
|
| 768 | 768 | |
| 769 | 769 | $this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure); |
| 770 | 770 | |
| 771 | - if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid); |
|
| 772 | - if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw); |
|
| 771 | + if (!empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid); |
|
| 772 | + if (!empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw); |
|
| 773 | 773 | //$smtps->_msgReplyTo = '[email protected]'; |
| 774 | 774 | |
| 775 | 775 | // Create the Mailer using your created Transport |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | $this->message->attachSigner($signer->ignoreHeader('Return-Path')); |
| 785 | 785 | } |
| 786 | 786 | |
| 787 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 787 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 788 | 788 | // To use the ArrayLogger |
| 789 | 789 | $this->logger = new Swift_Plugins_Loggers_ArrayLogger(); |
| 790 | 790 | // Or to use the Echo Logger |
@@ -795,14 +795,14 @@ discard block |
||
| 795 | 795 | try { |
| 796 | 796 | $result = $this->mailer->send($this->message); |
| 797 | 797 | } catch (Exception $e) { |
| 798 | - $this->error = $e->getMessage(); |
|
| 798 | + $this->error = $e->getMessage(); |
|
| 799 | 799 | } |
| 800 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 800 | + if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 801 | 801 | |
| 802 | 802 | $res = true; |
| 803 | - if (! empty($this->error) || ! $result) { |
|
| 803 | + if (!empty($this->error) || !$result) { |
|
| 804 | 804 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 805 | - $res=false; |
|
| 805 | + $res = false; |
|
| 806 | 806 | } |
| 807 | 807 | else |
| 808 | 808 | { |
@@ -817,23 +817,23 @@ discard block |
||
| 817 | 817 | return 'Bad value for sendmode'; |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | - $parameters=array(); $action=''; |
|
| 820 | + $parameters = array(); $action = ''; |
|
| 821 | 821 | $reshook = $hookmanager->executeHooks('sendMailAfter', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 822 | 822 | if ($reshook < 0) |
| 823 | 823 | { |
| 824 | - $this->error = "Error in hook maildao sendMailAfter " . $reshook; |
|
| 825 | - dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR); |
|
| 824 | + $this->error = "Error in hook maildao sendMailAfter ".$reshook; |
|
| 825 | + dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
|
| 826 | 826 | |
| 827 | 827 | return $reshook; |
| 828 | 828 | } |
| 829 | 829 | } |
| 830 | 830 | else |
| 831 | 831 | { |
| 832 | - $this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; |
|
| 832 | + $this->error = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; |
|
| 833 | 833 | dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING); |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | - error_reporting($errorlevel); // Reactive niveau erreur origine |
|
| 836 | + error_reporting($errorlevel); // Reactive niveau erreur origine |
|
| 837 | 837 | |
| 838 | 838 | return $res; |
| 839 | 839 | } |
@@ -860,17 +860,17 @@ discard block |
||
| 860 | 860 | function _encode_file($sourcefile) |
| 861 | 861 | { |
| 862 | 862 | // phpcs:enable |
| 863 | - $newsourcefile=dol_osencode($sourcefile); |
|
| 863 | + $newsourcefile = dol_osencode($sourcefile); |
|
| 864 | 864 | |
| 865 | 865 | if (is_readable($newsourcefile)) |
| 866 | 866 | { |
| 867 | - $contents = file_get_contents($newsourcefile); // Need PHP 4.3 |
|
| 868 | - $encoded = chunk_split(base64_encode($contents), 76, $this->eol); // 76 max is defined into http://tools.ietf.org/html/rfc2047 |
|
| 867 | + $contents = file_get_contents($newsourcefile); // Need PHP 4.3 |
|
| 868 | + $encoded = chunk_split(base64_encode($contents), 76, $this->eol); // 76 max is defined into http://tools.ietf.org/html/rfc2047 |
|
| 869 | 869 | return $encoded; |
| 870 | 870 | } |
| 871 | 871 | else |
| 872 | 872 | { |
| 873 | - $this->error="Error: Can't read file '".$sourcefile."' into _encode_file"; |
|
| 873 | + $this->error = "Error: Can't read file '".$sourcefile."' into _encode_file"; |
|
| 874 | 874 | dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR); |
| 875 | 875 | return -1; |
| 876 | 876 | } |
@@ -888,30 +888,30 @@ discard block |
||
| 888 | 888 | function dump_mail() |
| 889 | 889 | { |
| 890 | 890 | // phpcs:enable |
| 891 | - global $conf,$dolibarr_main_data_root; |
|
| 891 | + global $conf, $dolibarr_main_data_root; |
|
| 892 | 892 | |
| 893 | 893 | if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir |
| 894 | 894 | { |
| 895 | - $outputfile=$dolibarr_main_data_root."/dolibarr_mail.log"; |
|
| 896 | - $fp = fopen($outputfile,"w"); |
|
| 895 | + $outputfile = $dolibarr_main_data_root."/dolibarr_mail.log"; |
|
| 896 | + $fp = fopen($outputfile, "w"); |
|
| 897 | 897 | |
| 898 | 898 | if ($this->sendmode == 'mail') |
| 899 | 899 | { |
| 900 | 900 | fputs($fp, $this->headers); |
| 901 | - fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log |
|
| 901 | + fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log |
|
| 902 | 902 | fputs($fp, $this->message); |
| 903 | 903 | } |
| 904 | 904 | elseif ($this->sendmode == 'smtps') |
| 905 | 905 | { |
| 906 | - fputs($fp, $this->smtps->log); // this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on |
|
| 906 | + fputs($fp, $this->smtps->log); // this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on |
|
| 907 | 907 | } |
| 908 | 908 | elseif ($this->sendmode == 'swiftmailer') |
| 909 | 909 | { |
| 910 | - fputs($fp, $this->logger->dump()); // this->logger is filled only if MAIN_MAIL_DEBUG was set to on |
|
| 910 | + fputs($fp, $this->logger->dump()); // this->logger is filled only if MAIN_MAIL_DEBUG was set to on |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | fclose($fp); |
| 914 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 914 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 915 | 915 | @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
| 916 | 916 | } |
| 917 | 917 | } |
@@ -925,15 +925,15 @@ discard block |
||
| 925 | 925 | */ |
| 926 | 926 | function checkIfHTML($msg) |
| 927 | 927 | { |
| 928 | - if (!preg_match('/^[\s\t]*<html/i',$msg)) |
|
| 928 | + if (!preg_match('/^[\s\t]*<html/i', $msg)) |
|
| 929 | 929 | { |
| 930 | 930 | $out = "<html><head><title></title>"; |
| 931 | - if (!empty($this->styleCSS)) $out.= $this->styleCSS; |
|
| 932 | - $out.= "</head><body"; |
|
| 933 | - if (!empty($this->bodyCSS)) $out.= $this->bodyCSS; |
|
| 934 | - $out.= ">"; |
|
| 935 | - $out.= $msg; |
|
| 936 | - $out.= "</body></html>"; |
|
| 931 | + if (!empty($this->styleCSS)) $out .= $this->styleCSS; |
|
| 932 | + $out .= "</head><body"; |
|
| 933 | + if (!empty($this->bodyCSS)) $out .= $this->bodyCSS; |
|
| 934 | + $out .= ">"; |
|
| 935 | + $out .= $msg; |
|
| 936 | + $out .= "</body></html>"; |
|
| 937 | 937 | } |
| 938 | 938 | else |
| 939 | 939 | { |
@@ -950,24 +950,24 @@ discard block |
||
| 950 | 950 | */ |
| 951 | 951 | function buildCSS() |
| 952 | 952 | { |
| 953 | - if (! empty($this->css)) |
|
| 953 | + if (!empty($this->css)) |
|
| 954 | 954 | { |
| 955 | 955 | // Style CSS |
| 956 | 956 | $this->styleCSS = '<style type="text/css">'; |
| 957 | - $this->styleCSS.= 'body {'; |
|
| 957 | + $this->styleCSS .= 'body {'; |
|
| 958 | 958 | |
| 959 | 959 | if ($this->css['bgcolor']) |
| 960 | 960 | { |
| 961 | - $this->styleCSS.= ' background-color: '.$this->css['bgcolor'].';'; |
|
| 962 | - $this->bodyCSS.= ' bgcolor="'.$this->css['bgcolor'].'"'; |
|
| 961 | + $this->styleCSS .= ' background-color: '.$this->css['bgcolor'].';'; |
|
| 962 | + $this->bodyCSS .= ' bgcolor="'.$this->css['bgcolor'].'"'; |
|
| 963 | 963 | } |
| 964 | 964 | if ($this->css['bgimage']) |
| 965 | 965 | { |
| 966 | 966 | // TODO recuperer cid |
| 967 | - $this->styleCSS.= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");'; |
|
| 967 | + $this->styleCSS .= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");'; |
|
| 968 | 968 | } |
| 969 | - $this->styleCSS.= '}'; |
|
| 970 | - $this->styleCSS.= '</style>'; |
|
| 969 | + $this->styleCSS .= '}'; |
|
| 970 | + $this->styleCSS .= '</style>'; |
|
| 971 | 971 | } |
| 972 | 972 | } |
| 973 | 973 | |
@@ -988,48 +988,48 @@ discard block |
||
| 988 | 988 | |
| 989 | 989 | // Sender |
| 990 | 990 | //$out.= "Sender: ".getValidAddress($this->addr_from,2)).$this->eol2; |
| 991 | - $out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol2; |
|
| 992 | - if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) |
|
| 991 | + $out .= "From: ".$this->getValidAddress($this->addr_from, 3, 1).$this->eol2; |
|
| 992 | + if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) |
|
| 993 | 993 | { |
| 994 | - $out.= "To: ".$this->getValidAddress($this->addr_to,0,1).$this->eol2; |
|
| 994 | + $out .= "To: ".$this->getValidAddress($this->addr_to, 0, 1).$this->eol2; |
|
| 995 | 995 | } |
| 996 | 996 | // 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 | - $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; |
|
| 997 | + $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; |
|
| 1000 | 1000 | |
| 1001 | 1001 | // 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 ? |
|
| 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 ? |
|
| 1004 | 1004 | |
| 1005 | 1005 | // Delivery receipt |
| 1006 | - if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2; |
|
| 1006 | + if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from, 2).$this->eol2; |
|
| 1007 | 1007 | |
| 1008 | 1008 | //$out.= "X-Priority: 3".$this->eol2; |
| 1009 | 1009 | |
| 1010 | - $out.= 'Date: ' . date("r") . $this->eol2; |
|
| 1010 | + $out .= 'Date: '.date("r").$this->eol2; |
|
| 1011 | 1011 | |
| 1012 | 1012 | $trackid = $this->trackid; |
| 1013 | 1013 | if ($trackid) |
| 1014 | 1014 | { |
| 1015 | 1015 | // References is kept in response and Message-ID is returned into In-Reply-To: |
| 1016 | - $out.= 'Message-ID: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2; // Uppercase seems replaced by phpmail |
|
| 1017 | - $out.= 'References: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2; |
|
| 1018 | - $out.= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host. $this->eol2; |
|
| 1016 | + $out .= 'Message-ID: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2; // Uppercase seems replaced by phpmail |
|
| 1017 | + $out .= 'References: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2; |
|
| 1018 | + $out .= 'X-Dolibarr-TRACKID: '.$trackid.'@'.$host.$this->eol2; |
|
| 1019 | 1019 | } |
| 1020 | 1020 | else |
| 1021 | 1021 | { |
| 1022 | - $out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2; |
|
| 1022 | + $out .= 'Message-ID: <'.time().'.phpmail@'.$host.">".$this->eol2; |
|
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | - if (! empty($_SERVER['REMOTE_ADDR'])) $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2; |
|
| 1026 | - $out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2; |
|
| 1027 | - $out.= "Mime-Version: 1.0".$this->eol2; |
|
| 1025 | + if (!empty($_SERVER['REMOTE_ADDR'])) $out .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR'].$this->eol2; |
|
| 1026 | + $out .= "X-Mailer: Dolibarr version ".DOL_VERSION." (using php mail)".$this->eol2; |
|
| 1027 | + $out .= "Mime-Version: 1.0".$this->eol2; |
|
| 1028 | 1028 | |
| 1029 | 1029 | //$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol; |
| 1030 | 1030 | |
| 1031 | - $out.= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2; |
|
| 1032 | - $out.= "Content-Transfer-Encoding: 8bit".$this->eol2; // TODO Seems to be ignored. Header is 7bit once received. |
|
| 1031 | + $out .= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2; |
|
| 1032 | + $out .= "Content-Transfer-Encoding: 8bit".$this->eol2; // TODO Seems to be ignored. Header is 7bit once received. |
|
| 1033 | 1033 | |
| 1034 | 1034 | dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out); |
| 1035 | 1035 | return $out; |
@@ -1047,18 +1047,18 @@ discard block |
||
| 1047 | 1047 | function write_mimeheaders($filename_list, $mimefilename_list) |
| 1048 | 1048 | { |
| 1049 | 1049 | // phpcs:enable |
| 1050 | - $mimedone=0; |
|
| 1050 | + $mimedone = 0; |
|
| 1051 | 1051 | $out = ""; |
| 1052 | 1052 | |
| 1053 | 1053 | if (is_array($filename_list)) |
| 1054 | 1054 | { |
| 1055 | - $filename_list_size=count($filename_list); |
|
| 1056 | - for($i=0;$i < $filename_list_size;$i++) |
|
| 1055 | + $filename_list_size = count($filename_list); |
|
| 1056 | + for ($i = 0; $i < $filename_list_size; $i++) |
|
| 1057 | 1057 | { |
| 1058 | 1058 | if ($filename_list[$i]) |
| 1059 | 1059 | { |
| 1060 | 1060 | if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; |
| 1061 | - $out.= "X-attachments: $filename_list[$i]".$this->eol2; |
|
| 1061 | + $out .= "X-attachments: $filename_list[$i]".$this->eol2; |
|
| 1062 | 1062 | } |
| 1063 | 1063 | } |
| 1064 | 1064 | } |
@@ -1079,31 +1079,31 @@ discard block |
||
| 1079 | 1079 | // phpcs:enable |
| 1080 | 1080 | global $conf; |
| 1081 | 1081 | |
| 1082 | - $out=''; |
|
| 1082 | + $out = ''; |
|
| 1083 | 1083 | |
| 1084 | - $out.= "--" . $this->mixed_boundary . $this->eol; |
|
| 1084 | + $out .= "--".$this->mixed_boundary.$this->eol; |
|
| 1085 | 1085 | |
| 1086 | 1086 | if ($this->atleastoneimage) |
| 1087 | 1087 | { |
| 1088 | - $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
|
| 1089 | - $out.= $this->eol; |
|
| 1090 | - $out.= "--" . $this->alternative_boundary . $this->eol; |
|
| 1088 | + $out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
|
| 1089 | + $out .= $this->eol; |
|
| 1090 | + $out .= "--".$this->alternative_boundary.$this->eol; |
|
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | // Make RFC821 Compliant, replace bare linefeeds |
| 1094 | - $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext); // PCRE modifier /s means new lines are common chars |
|
| 1095 | - if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) |
|
| 1094 | + $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext); // PCRE modifier /s means new lines are common chars |
|
| 1095 | + if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)) |
|
| 1096 | 1096 | { |
| 1097 | - $strContent = preg_replace("/\r\n/si", "\n", $strContent); // PCRE modifier /s means new lines are common chars |
|
| 1097 | + $strContent = preg_replace("/\r\n/si", "\n", $strContent); // PCRE modifier /s means new lines are common chars |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | $strContentAltText = ''; |
| 1101 | 1101 | if ($this->msgishtml) |
| 1102 | 1102 | { |
| 1103 | 1103 | // Similar code to forge a text from html is also in CMailFile.class.php |
| 1104 | - $strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent); |
|
| 1104 | + $strContentAltText = preg_replace("/<br\s*[^>]*>/", " ", $strContent); |
|
| 1105 | 1105 | $strContentAltText = html_entity_decode(strip_tags($strContentAltText)); |
| 1106 | - $strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n")); |
|
| 1106 | + $strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ? "\r\n" : "\n")); |
|
| 1107 | 1107 | |
| 1108 | 1108 | // Check if html header already in message, if not complete the message |
| 1109 | 1109 | $strContent = $this->checkIfHTML($strContent); |
@@ -1112,57 +1112,57 @@ discard block |
||
| 1112 | 1112 | // Make RFC2045 Compliant, split lines |
| 1113 | 1113 | //$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content |
| 1114 | 1114 | // TODO Encode main content into base64 and use the chunk_split, or quoted-printable |
| 1115 | - $strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n")); // TODO Using this method creates unexpected line break on text/plain content. |
|
| 1115 | + $strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ? "\r\n" : "\n")); // TODO Using this method creates unexpected line break on text/plain content. |
|
| 1116 | 1116 | |
| 1117 | 1117 | if ($this->msgishtml) |
| 1118 | 1118 | { |
| 1119 | 1119 | if ($this->atleastoneimage) |
| 1120 | 1120 | { |
| 1121 | - $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1121 | + $out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1122 | 1122 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; |
| 1123 | - $out.= $this->eol.($strContentAltText?$strContentAltText:strip_tags($strContent)).$this->eol; // Add plain text message |
|
| 1124 | - $out.= "--" . $this->alternative_boundary . $this->eol; |
|
| 1125 | - $out.= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol; |
|
| 1126 | - $out.= $this->eol; |
|
| 1127 | - $out.= "--" . $this->related_boundary . $this->eol; |
|
| 1123 | + $out .= $this->eol.($strContentAltText ? $strContentAltText : strip_tags($strContent)).$this->eol; // Add plain text message |
|
| 1124 | + $out .= "--".$this->alternative_boundary.$this->eol; |
|
| 1125 | + $out .= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol; |
|
| 1126 | + $out .= $this->eol; |
|
| 1127 | + $out .= "--".$this->related_boundary.$this->eol; |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | - if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
| 1130 | + if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
| 1131 | 1131 | { |
| 1132 | - $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
|
| 1133 | - $out.= $this->eol; |
|
| 1134 | - $out.= "--" . $this->alternative_boundary . $this->eol; |
|
| 1135 | - $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1132 | + $out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
|
| 1133 | + $out .= $this->eol; |
|
| 1134 | + $out .= "--".$this->alternative_boundary.$this->eol; |
|
| 1135 | + $out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1136 | 1136 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; |
| 1137 | - $out.= $this->eol.$strContentAltText.$this->eol; |
|
| 1138 | - $out.= "--" . $this->alternative_boundary . $this->eol; |
|
| 1137 | + $out .= $this->eol.$strContentAltText.$this->eol; |
|
| 1138 | + $out .= "--".$this->alternative_boundary.$this->eol; |
|
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | - $out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1141 | + $out .= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1142 | 1142 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; // TODO Use base64 |
| 1143 | - $out.= $this->eol.$strContent.$this->eol; |
|
| 1143 | + $out .= $this->eol.$strContent.$this->eol; |
|
| 1144 | 1144 | |
| 1145 | - if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
| 1145 | + if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
| 1146 | 1146 | { |
| 1147 | - $out.= "--" . $this->alternative_boundary . "--". $this->eol; |
|
| 1147 | + $out .= "--".$this->alternative_boundary."--".$this->eol; |
|
| 1148 | 1148 | } |
| 1149 | 1149 | } |
| 1150 | 1150 | else |
| 1151 | 1151 | { |
| 1152 | - $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1152 | + $out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
|
| 1153 | 1153 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; |
| 1154 | - $out.= $this->eol.$strContent.$this->eol; |
|
| 1154 | + $out .= $this->eol.$strContent.$this->eol; |
|
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - $out.= $this->eol; |
|
| 1157 | + $out .= $this->eol; |
|
| 1158 | 1158 | |
| 1159 | 1159 | // Encode images |
| 1160 | 1160 | if ($this->atleastoneimage) |
| 1161 | 1161 | { |
| 1162 | 1162 | $out .= $this->write_images($this->images_encoded); |
| 1163 | 1163 | // always end related and end alternative after inline images |
| 1164 | - $out .= "--" . $this->related_boundary . "--" . $this->eol; |
|
| 1165 | - $out .= $this->eol . "--" . $this->alternative_boundary . "--" . $this->eol; |
|
| 1164 | + $out .= "--".$this->related_boundary."--".$this->eol; |
|
| 1165 | + $out .= $this->eol."--".$this->alternative_boundary."--".$this->eol; |
|
| 1166 | 1166 | $out .= $this->eol; |
| 1167 | 1167 | } |
| 1168 | 1168 | |
@@ -1178,13 +1178,13 @@ discard block |
||
| 1178 | 1178 | * @param array $mimefilename_list Tableau |
| 1179 | 1179 | * @return string Chaine fichiers encodes |
| 1180 | 1180 | */ |
| 1181 | - function write_files($filename_list,$mimetype_list,$mimefilename_list) |
|
| 1181 | + function write_files($filename_list, $mimetype_list, $mimefilename_list) |
|
| 1182 | 1182 | { |
| 1183 | 1183 | // phpcs:enable |
| 1184 | 1184 | $out = ''; |
| 1185 | 1185 | |
| 1186 | - $filename_list_size=count($filename_list); |
|
| 1187 | - for($i=0;$i < $filename_list_size;$i++) |
|
| 1186 | + $filename_list_size = count($filename_list); |
|
| 1187 | + for ($i = 0; $i < $filename_list_size; $i++) |
|
| 1188 | 1188 | { |
| 1189 | 1189 | if ($filename_list[$i]) |
| 1190 | 1190 | { |
@@ -1193,18 +1193,18 @@ discard block |
||
| 1193 | 1193 | if ($encoded >= 0) |
| 1194 | 1194 | { |
| 1195 | 1195 | if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; |
| 1196 | - if (! $mimetype_list[$i]) { |
|
| 1196 | + if (!$mimetype_list[$i]) { |
|
| 1197 | 1197 | $mimetype_list[$i] = "application/octet-stream"; |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | - $out.= "--" . $this->mixed_boundary . $this->eol; |
|
| 1201 | - $out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol; |
|
| 1202 | - $out.= "Content-Type: " . $mimetype_list[$i] . "; name=\"".$filename_list[$i]."\"".$this->eol; |
|
| 1203 | - $out.= "Content-Transfer-Encoding: base64".$this->eol; |
|
| 1204 | - $out.= "Content-Description: ".$filename_list[$i].$this->eol; |
|
| 1205 | - $out.= $this->eol; |
|
| 1206 | - $out.= $encoded; |
|
| 1207 | - $out.= $this->eol; |
|
| 1200 | + $out .= "--".$this->mixed_boundary.$this->eol; |
|
| 1201 | + $out .= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol; |
|
| 1202 | + $out .= "Content-Type: ".$mimetype_list[$i]."; name=\"".$filename_list[$i]."\"".$this->eol; |
|
| 1203 | + $out .= "Content-Transfer-Encoding: base64".$this->eol; |
|
| 1204 | + $out .= "Content-Description: ".$filename_list[$i].$this->eol; |
|
| 1205 | + $out .= $this->eol; |
|
| 1206 | + $out .= $encoded; |
|
| 1207 | + $out .= $this->eol; |
|
| 1208 | 1208 | //$out.= $this->eol; |
| 1209 | 1209 | } |
| 1210 | 1210 | else |
@@ -1236,14 +1236,14 @@ discard block |
||
| 1236 | 1236 | { |
| 1237 | 1237 | dol_syslog("CMailFile::write_images: ".$img["name"]); |
| 1238 | 1238 | |
| 1239 | - $out.= "--" . $this->related_boundary . $this->eol; // always related for an inline image |
|
| 1240 | - $out.= "Content-Type: " . $img["content_type"] . "; name=\"".$img["name"]."\"".$this->eol; |
|
| 1241 | - $out.= "Content-Transfer-Encoding: base64".$this->eol; |
|
| 1242 | - $out.= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol; |
|
| 1243 | - $out.= "Content-ID: <".$img["cid"].">".$this->eol; |
|
| 1244 | - $out.= $this->eol; |
|
| 1245 | - $out.= $img["image_encoded"]; |
|
| 1246 | - $out.= $this->eol; |
|
| 1239 | + $out .= "--".$this->related_boundary.$this->eol; // always related for an inline image |
|
| 1240 | + $out .= "Content-Type: ".$img["content_type"]."; name=\"".$img["name"]."\"".$this->eol; |
|
| 1241 | + $out .= "Content-Transfer-Encoding: base64".$this->eol; |
|
| 1242 | + $out .= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol; |
|
| 1243 | + $out .= "Content-ID: <".$img["cid"].">".$this->eol; |
|
| 1244 | + $out .= $this->eol; |
|
| 1245 | + $out .= $img["image_encoded"]; |
|
| 1246 | + $out .= $this->eol; |
|
| 1247 | 1247 | } |
| 1248 | 1248 | } |
| 1249 | 1249 | |
@@ -1259,44 +1259,44 @@ discard block |
||
| 1259 | 1259 | * @param int $port Example: 25, 465 |
| 1260 | 1260 | * @return int Socket id if ok, 0 if KO |
| 1261 | 1261 | */ |
| 1262 | - function check_server_port($host,$port) |
|
| 1262 | + function check_server_port($host, $port) |
|
| 1263 | 1263 | { |
| 1264 | 1264 | // phpcs:enable |
| 1265 | 1265 | global $conf; |
| 1266 | 1266 | |
| 1267 | - $_retVal=0; |
|
| 1268 | - $timeout=5; // Timeout in seconds |
|
| 1267 | + $_retVal = 0; |
|
| 1268 | + $timeout = 5; // Timeout in seconds |
|
| 1269 | 1269 | |
| 1270 | 1270 | if (function_exists('fsockopen')) |
| 1271 | 1271 | { |
| 1272 | - $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER'; |
|
| 1273 | - $keyforsmtpport ='MAIN_MAIL_SMTP_PORT'; |
|
| 1274 | - $keyforsmtpid ='MAIN_MAIL_SMTPS_ID'; |
|
| 1275 | - $keyforsmtppw ='MAIN_MAIL_SMTPS_PW'; |
|
| 1276 | - $keyfortls ='MAIN_MAIL_EMAIL_TLS'; |
|
| 1277 | - $keyforstarttls ='MAIN_MAIL_EMAIL_STARTTLS'; |
|
| 1272 | + $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER'; |
|
| 1273 | + $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT'; |
|
| 1274 | + $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID'; |
|
| 1275 | + $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW'; |
|
| 1276 | + $keyfortls = 'MAIN_MAIL_EMAIL_TLS'; |
|
| 1277 | + $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS'; |
|
| 1278 | 1278 | if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default') |
| 1279 | 1279 | { |
| 1280 | - $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING'; |
|
| 1281 | - $keyforsmtpport ='MAIN_MAIL_SMTP_PORT_EMAILING'; |
|
| 1282 | - $keyforsmtpid ='MAIN_MAIL_SMTPS_ID_EMAILING'; |
|
| 1283 | - $keyforsmtppw ='MAIN_MAIL_SMTPS_PW_EMAILING'; |
|
| 1284 | - $keyfortls ='MAIN_MAIL_EMAIL_TLS_EMAILING'; |
|
| 1285 | - $keyforstarttls ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING'; |
|
| 1280 | + $keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING'; |
|
| 1281 | + $keyforsmtpport = 'MAIN_MAIL_SMTP_PORT_EMAILING'; |
|
| 1282 | + $keyforsmtpid = 'MAIN_MAIL_SMTPS_ID_EMAILING'; |
|
| 1283 | + $keyforsmtppw = 'MAIN_MAIL_SMTPS_PW_EMAILING'; |
|
| 1284 | + $keyfortls = 'MAIN_MAIL_EMAIL_TLS_EMAILING'; |
|
| 1285 | + $keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS_EMAILING'; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | // If we use SSL/TLS |
| 1289 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host='ssl://'.$host; |
|
| 1289 | + if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host = 'ssl://'.$host; |
|
| 1290 | 1290 | // tls smtp start with no encryption |
| 1291 | 1291 | //if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host; |
| 1292 | 1292 | |
| 1293 | 1293 | dol_syslog("Try socket connection to host=".$host." port=".$port); |
| 1294 | 1294 | //See if we can connect to the SMTP server |
| 1295 | 1295 | if ($socket = @fsockopen( |
| 1296 | - $host, // Host to test, IP or domain. Add ssl:// for SSL/TLS. |
|
| 1297 | - $port, // which Port number to use |
|
| 1298 | - $errno, // actual system level error |
|
| 1299 | - $errstr, // and any text that goes with the error |
|
| 1296 | + $host, // Host to test, IP or domain. Add ssl:// for SSL/TLS. |
|
| 1297 | + $port, // which Port number to use |
|
| 1298 | + $errno, // actual system level error |
|
| 1299 | + $errstr, // and any text that goes with the error |
|
| 1300 | 1300 | $timeout |
| 1301 | 1301 | )) // timeout for reading/writing data over the socket |
| 1302 | 1302 | { |
@@ -1306,11 +1306,11 @@ discard block |
||
| 1306 | 1306 | dol_syslog("Now we wait for answer 220"); |
| 1307 | 1307 | |
| 1308 | 1308 | // Check response from Server |
| 1309 | - if ( $_retVal = $this->server_parse($socket, "220") ) $_retVal = $socket; |
|
| 1309 | + if ($_retVal = $this->server_parse($socket, "220")) $_retVal = $socket; |
|
| 1310 | 1310 | } |
| 1311 | 1311 | else |
| 1312 | 1312 | { |
| 1313 | - $this->error = utf8_check('Error '.$errno.' - '.$errstr)?'Error '.$errno.' - '.$errstr:utf8_encode('Error '.$errno.' - '.$errstr); |
|
| 1313 | + $this->error = utf8_check('Error '.$errno.' - '.$errstr) ? 'Error '.$errno.' - '.$errstr : utf8_encode('Error '.$errno.' - '.$errstr); |
|
| 1314 | 1314 | } |
| 1315 | 1315 | } |
| 1316 | 1316 | return $_retVal; |
@@ -1328,21 +1328,21 @@ discard block |
||
| 1328 | 1328 | function server_parse($socket, $response) |
| 1329 | 1329 | { |
| 1330 | 1330 | // phpcs:enable |
| 1331 | - $_retVal = true; // Indicates if Object was created or not |
|
| 1331 | + $_retVal = true; // Indicates if Object was created or not |
|
| 1332 | 1332 | $server_response = ''; |
| 1333 | 1333 | |
| 1334 | - while (substr($server_response,3,1) != ' ') |
|
| 1334 | + while (substr($server_response, 3, 1) != ' ') |
|
| 1335 | 1335 | { |
| 1336 | - if (! ($server_response = fgets($socket, 256)) ) |
|
| 1336 | + if (!($server_response = fgets($socket, 256))) |
|
| 1337 | 1337 | { |
| 1338 | - $this->error="Couldn't get mail server response codes"; |
|
| 1338 | + $this->error = "Couldn't get mail server response codes"; |
|
| 1339 | 1339 | return false; |
| 1340 | 1340 | } |
| 1341 | 1341 | } |
| 1342 | 1342 | |
| 1343 | - if( !( substr($server_response, 0, 3) == $response ) ) |
|
| 1343 | + if (!(substr($server_response, 0, 3) == $response)) |
|
| 1344 | 1344 | { |
| 1345 | - $this->error="Ran into problems sending Mail.\r\nResponse: $server_response"; |
|
| 1345 | + $this->error = "Ran into problems sending Mail.\r\nResponse: $server_response"; |
|
| 1346 | 1346 | $_retVal = false; |
| 1347 | 1347 | } |
| 1348 | 1348 | |
@@ -1361,22 +1361,22 @@ discard block |
||
| 1361 | 1361 | $extensions = array_keys($this->image_types); |
| 1362 | 1362 | |
| 1363 | 1363 | $matches = array(); |
| 1364 | - preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches); // If "xxx.ext" or 'xxx.ext' found |
|
| 1364 | + preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches); // If "xxx.ext" or 'xxx.ext' found |
|
| 1365 | 1365 | |
| 1366 | - if (! empty($matches)) |
|
| 1366 | + if (!empty($matches)) |
|
| 1367 | 1367 | { |
| 1368 | - $i=0; |
|
| 1368 | + $i = 0; |
|
| 1369 | 1369 | foreach ($matches[1] as $full) |
| 1370 | 1370 | { |
| 1371 | 1371 | |
| 1372 | - if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs)) // If xxx is 'file=aaa' |
|
| 1372 | + if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i', $full, $regs)) // If xxx is 'file=aaa' |
|
| 1373 | 1373 | { |
| 1374 | 1374 | $img = $regs[1]; |
| 1375 | 1375 | |
| 1376 | 1376 | if (file_exists($images_dir.'/'.$img)) |
| 1377 | 1377 | { |
| 1378 | 1378 | // Image path in src |
| 1379 | - $src = preg_quote($full,'/'); |
|
| 1379 | + $src = preg_quote($full, '/'); |
|
| 1380 | 1380 | |
| 1381 | 1381 | // Image full path |
| 1382 | 1382 | $this->html_images[$i]["fullpath"] = $images_dir.'/'.$img; |
@@ -1387,12 +1387,12 @@ discard block |
||
| 1387 | 1387 | // Content type |
| 1388 | 1388 | if (preg_match('/^.+\.(\w{3,4})$/', $img, $reg)) |
| 1389 | 1389 | { |
| 1390 | - $ext=strtolower($reg[1]); |
|
| 1390 | + $ext = strtolower($reg[1]); |
|
| 1391 | 1391 | $this->html_images[$i]["content_type"] = $this->image_types[$ext]; |
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | // cid |
| 1395 | - $this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3); // Force md5 hash (does not contains special chars) |
|
| 1395 | + $this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3); // Force md5 hash (does not contains special chars) |
|
| 1396 | 1396 | $this->html = preg_replace("/src=\"$src\"|src='$src'/i", "src=\"cid:".$this->html_images[$i]["cid"]."\"", $this->html); |
| 1397 | 1397 | } |
| 1398 | 1398 | $i++; |
@@ -1403,20 +1403,20 @@ discard block |
||
| 1403 | 1403 | { |
| 1404 | 1404 | $inline = array(); |
| 1405 | 1405 | |
| 1406 | - $i=0; |
|
| 1406 | + $i = 0; |
|
| 1407 | 1407 | |
| 1408 | 1408 | foreach ($this->html_images as $img) |
| 1409 | 1409 | { |
| 1410 | 1410 | $fullpath = $images_dir.'/'.$img["name"]; |
| 1411 | 1411 | |
| 1412 | 1412 | // If duplicate images are embedded, they may show up as attachments, so remove them. |
| 1413 | - if (!in_array($fullpath,$inline)) |
|
| 1413 | + if (!in_array($fullpath, $inline)) |
|
| 1414 | 1414 | { |
| 1415 | 1415 | // Read image file |
| 1416 | 1416 | if ($image = file_get_contents($fullpath)) |
| 1417 | 1417 | { |
| 1418 | 1418 | // On garde que le nom de l'image |
| 1419 | - preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i',$img["name"],$regs); |
|
| 1419 | + preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i', $img["name"], $regs); |
|
| 1420 | 1420 | $imgName = $regs[1]; |
| 1421 | 1421 | |
| 1422 | 1422 | $this->images_encoded[$i]['name'] = $imgName; |
@@ -1457,19 +1457,19 @@ discard block |
||
| 1457 | 1457 | * If format 3: '<[email protected]>' or '"John Doe" <[email protected]>' or '"=?UTF-8?B?Sm9obiBEb2U=?=" <[email protected]>' |
| 1458 | 1458 | * If format 4: 'John Doe' or '[email protected]' if no label exists |
| 1459 | 1459 | */ |
| 1460 | - static function getValidAddress($address,$format,$encode=0,$maxnumberofemail=0) |
|
| 1460 | + static function getValidAddress($address, $format, $encode = 0, $maxnumberofemail = 0) |
|
| 1461 | 1461 | { |
| 1462 | 1462 | global $conf; |
| 1463 | 1463 | |
| 1464 | - $ret=''; |
|
| 1464 | + $ret = ''; |
|
| 1465 | 1465 | |
| 1466 | - $arrayaddress=explode(',',$address); |
|
| 1466 | + $arrayaddress = explode(',', $address); |
|
| 1467 | 1467 | |
| 1468 | 1468 | // Boucle sur chaque composant de l'adresse |
| 1469 | - $i=0; |
|
| 1470 | - foreach($arrayaddress as $val) |
|
| 1469 | + $i = 0; |
|
| 1470 | + foreach ($arrayaddress as $val) |
|
| 1471 | 1471 | { |
| 1472 | - if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs)) |
|
| 1472 | + if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs)) |
|
| 1473 | 1473 | { |
| 1474 | 1474 | $name = trim($regs[1]); |
| 1475 | 1475 | $email = trim($regs[2]); |
@@ -1484,32 +1484,32 @@ discard block |
||
| 1484 | 1484 | { |
| 1485 | 1485 | $i++; |
| 1486 | 1486 | |
| 1487 | - $newemail=''; |
|
| 1487 | + $newemail = ''; |
|
| 1488 | 1488 | if ($format == 4) |
| 1489 | 1489 | { |
| 1490 | - $newemail = $name?$name:$email; |
|
| 1490 | + $newemail = $name ? $name : $email; |
|
| 1491 | 1491 | } |
| 1492 | 1492 | if ($format == 2) |
| 1493 | 1493 | { |
| 1494 | - $newemail=$email; |
|
| 1494 | + $newemail = $email; |
|
| 1495 | 1495 | } |
| 1496 | 1496 | if ($format == 1 || $format == 3) |
| 1497 | 1497 | { |
| 1498 | - $newemail='<'.$email.'>'; |
|
| 1498 | + $newemail = '<'.$email.'>'; |
|
| 1499 | 1499 | } |
| 1500 | 1500 | if ($format == 0 || $format == 3) |
| 1501 | 1501 | { |
| 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.'>'; |
|
| 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.'>'; |
|
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | - $ret=($ret ? $ret.',' : '').$newemail; |
|
| 1507 | + $ret = ($ret ? $ret.',' : '').$newemail; |
|
| 1508 | 1508 | |
| 1509 | 1509 | // Stop if we have too much records |
| 1510 | 1510 | if ($maxnumberofemail && $i >= $maxnumberofemail) |
| 1511 | 1511 | { |
| 1512 | - if (count($arrayaddress) > $maxnumberofemail) $ret.='...'; |
|
| 1512 | + if (count($arrayaddress) > $maxnumberofemail) $ret .= '...'; |
|
| 1513 | 1513 | break; |
| 1514 | 1514 | } |
| 1515 | 1515 | } |
@@ -1528,14 +1528,14 @@ discard block |
||
| 1528 | 1528 | { |
| 1529 | 1529 | global $conf; |
| 1530 | 1530 | |
| 1531 | - $ret=array(); |
|
| 1531 | + $ret = array(); |
|
| 1532 | 1532 | |
| 1533 | - $arrayaddress=explode(',',$address); |
|
| 1533 | + $arrayaddress = explode(',', $address); |
|
| 1534 | 1534 | |
| 1535 | 1535 | // Boucle sur chaque composant de l'adresse |
| 1536 | - foreach($arrayaddress as $val) |
|
| 1536 | + foreach ($arrayaddress as $val) |
|
| 1537 | 1537 | { |
| 1538 | - if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs)) |
|
| 1538 | + if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs)) |
|
| 1539 | 1539 | { |
| 1540 | 1540 | $name = trim($regs[1]); |
| 1541 | 1541 | $email = trim($regs[2]); |
@@ -1546,7 +1546,7 @@ discard block |
||
| 1546 | 1546 | $email = trim($val); |
| 1547 | 1547 | } |
| 1548 | 1548 | |
| 1549 | - $ret[$email]=empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)?$name:null; |
|
| 1549 | + $ret[$email] = empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL) ? $name : null; |
|
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | 1552 | return $ret; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @var string Error code (or message) |
| 39 | 39 | */ |
| 40 | - public $error=''; |
|
| 40 | + public $error = ''; |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param int $idForm Id du formulaire |
| 61 | 61 | * @return string HTML select string |
| 62 | 62 | */ |
| 63 | - function setBarcodeEncoder($selected,$barcodelist,$code_id,$idForm='formbarcode') |
|
| 63 | + function setBarcodeEncoder($selected, $barcodelist, $code_id, $idForm = 'formbarcode') |
|
| 64 | 64 | { |
| 65 | 65 | global $conf, $langs; |
| 66 | 66 | |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // We check if barcode is already selected by default |
| 84 | - if (((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) || |
|
| 85 | - (! empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id)) |
|
| 84 | + if (((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) || |
|
| 85 | + (!empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id)) |
|
| 86 | 86 | { |
| 87 | 87 | $disable = 'disabled'; |
| 88 | 88 | } |
@@ -90,24 +90,24 @@ discard block |
||
| 90 | 90 | if (!empty($conf->use_javascript_ajax)) |
| 91 | 91 | { |
| 92 | 92 | $select_encoder = '<form action="'.DOL_URL_ROOT.'/admin/barcode.php" method="POST" id="form'.$idForm.'">'; |
| 93 | - $select_encoder.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 94 | - $select_encoder.= '<input type="hidden" name="action" value="update">'; |
|
| 95 | - $select_encoder.= '<input type="hidden" name="code_id" value="'.$code_id.'">'; |
|
| 93 | + $select_encoder .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 94 | + $select_encoder .= '<input type="hidden" name="action" value="update">'; |
|
| 95 | + $select_encoder .= '<input type="hidden" name="code_id" value="'.$code_id.'">'; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $selectname=(!empty($conf->use_javascript_ajax)?'coder':'coder'.$code_id); |
|
| 99 | - $select_encoder.= '<select id="select'.$idForm.'" class="flat" name="'.$selectname.'">'; |
|
| 100 | - $select_encoder.= '<option value="0"'.($selected==0?' selected':'').' '.$disable.'>'.$langs->trans('Disable').'</option>'; |
|
| 101 | - $select_encoder.= '<option value="-1" disabled>--------------------</option>'; |
|
| 102 | - foreach($barcodelist as $key => $value) |
|
| 98 | + $selectname = (!empty($conf->use_javascript_ajax) ? 'coder' : 'coder'.$code_id); |
|
| 99 | + $select_encoder .= '<select id="select'.$idForm.'" class="flat" name="'.$selectname.'">'; |
|
| 100 | + $select_encoder .= '<option value="0"'.($selected == 0 ? ' selected' : '').' '.$disable.'>'.$langs->trans('Disable').'</option>'; |
|
| 101 | + $select_encoder .= '<option value="-1" disabled>--------------------</option>'; |
|
| 102 | + foreach ($barcodelist as $key => $value) |
|
| 103 | 103 | { |
| 104 | - $select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected':'').'>'.$value.'</option>'; |
|
| 104 | + $select_encoder .= '<option value="'.$key.'"'.($selected == $key ? ' selected' : '').'>'.$value.'</option>'; |
|
| 105 | 105 | } |
| 106 | - $select_encoder.= '</select>'; |
|
| 106 | + $select_encoder .= '</select>'; |
|
| 107 | 107 | |
| 108 | 108 | if (!empty($conf->use_javascript_ajax)) |
| 109 | 109 | { |
| 110 | - $select_encoder.= '</form>'; |
|
| 110 | + $select_encoder .= '</form>'; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return $select_encoder; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @return void |
| 124 | 124 | * @deprecated |
| 125 | 125 | */ |
| 126 | - function select_barcode_type($selected='', $htmlname='barcodetype_id', $useempty=0) |
|
| 126 | + function select_barcode_type($selected = '', $htmlname = 'barcodetype_id', $useempty = 0) |
|
| 127 | 127 | { |
| 128 | 128 | // phpcs:enable |
| 129 | 129 | print $this->selectBarcodeType($selected, $htmlname, $useempty); |
@@ -137,17 +137,17 @@ discard block |
||
| 137 | 137 | * @param int $useempty Display empty value in select |
| 138 | 138 | * @return string |
| 139 | 139 | */ |
| 140 | - function selectBarcodeType($selected='', $htmlname='barcodetype_id', $useempty=0) |
|
| 140 | + function selectBarcodeType($selected = '', $htmlname = 'barcodetype_id', $useempty = 0) |
|
| 141 | 141 | { |
| 142 | 142 | global $langs, $conf; |
| 143 | 143 | |
| 144 | 144 | $out = ''; |
| 145 | 145 | |
| 146 | 146 | $sql = "SELECT rowid, code, libelle"; |
| 147 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 148 | - $sql.= " WHERE coder <> '0'"; |
|
| 149 | - $sql.= " AND entity = ".$conf->entity; |
|
| 150 | - $sql.= " ORDER BY code"; |
|
| 147 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 148 | + $sql .= " WHERE coder <> '0'"; |
|
| 149 | + $sql .= " AND entity = ".$conf->entity; |
|
| 150 | + $sql .= " ORDER BY code"; |
|
| 151 | 151 | |
| 152 | 152 | $result = $this->db->query($sql); |
| 153 | 153 | if ($result) { |
@@ -155,20 +155,20 @@ discard block |
||
| 155 | 155 | $i = 0; |
| 156 | 156 | |
| 157 | 157 | if ($useempty && $num > 0) { |
| 158 | - $out .= '<select class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">'; |
|
| 158 | + $out .= '<select class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
|
| 159 | 159 | $out .= '<option value="0"> </option>'; |
| 160 | 160 | } else { |
| 161 | 161 | $langs->load("errors"); |
| 162 | - $out .= '<select disabled class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">'; |
|
| 163 | - $out .= '<option value="0" selected>' . $langs->trans('ErrorNoActivatedBarcode') . '</option>'; |
|
| 162 | + $out .= '<select disabled class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
|
| 163 | + $out .= '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>'; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | while ($i < $num) { |
| 167 | 167 | $obj = $this->db->fetch_object($result); |
| 168 | 168 | if ($selected == $obj->rowid) { |
| 169 | - $out .= '<option value="' . $obj->rowid . '" selected>'; |
|
| 169 | + $out .= '<option value="'.$obj->rowid.'" selected>'; |
|
| 170 | 170 | } else { |
| 171 | - $out .= '<option value="' . $obj->rowid . '">'; |
|
| 171 | + $out .= '<option value="'.$obj->rowid.'">'; |
|
| 172 | 172 | } |
| 173 | 173 | $out .= $obj->libelle; |
| 174 | 174 | $out .= '</option>'; |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * @return void |
| 194 | 194 | * @deprecated |
| 195 | 195 | */ |
| 196 | - function form_barcode_type($page, $selected='', $htmlname='barcodetype_id') |
|
| 196 | + function form_barcode_type($page, $selected = '', $htmlname = 'barcodetype_id') |
|
| 197 | 197 | { |
| 198 | 198 | // phpcs:enable |
| 199 | 199 | print $this->formBarcodeType($page, $selected, $htmlname); |
@@ -207,19 +207,19 @@ discard block |
||
| 207 | 207 | * @param string $htmlname Nom du formulaire select |
| 208 | 208 | * @return string |
| 209 | 209 | */ |
| 210 | - function formBarcodeType($page, $selected='', $htmlname='barcodetype_id') |
|
| 210 | + function formBarcodeType($page, $selected = '', $htmlname = 'barcodetype_id') |
|
| 211 | 211 | { |
| 212 | 212 | global $langs, $conf; |
| 213 | 213 | $out = ''; |
| 214 | 214 | if ($htmlname != "none") { |
| 215 | - $out .= '<form method="post" action="' . $page . '">'; |
|
| 216 | - $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 215 | + $out .= '<form method="post" action="'.$page.'">'; |
|
| 216 | + $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 217 | 217 | $out .= '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
| 218 | 218 | $out .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; |
| 219 | 219 | $out .= '<tr><td>'; |
| 220 | 220 | $out .= $this->selectBarcodeType($selected, $htmlname, 1); |
| 221 | 221 | $out .= '</td>'; |
| 222 | - $out .= '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '">'; |
|
| 222 | + $out .= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">'; |
|
| 223 | 223 | $out .= '</td></tr></table></form>'; |
| 224 | 224 | } |
| 225 | 225 | return $out; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * @var string Error code (or message) |
| 39 | 39 | */ |
| 40 | - public $error=''; |
|
| 40 | + public $error = ''; |
|
| 41 | 41 | |
| 42 | 42 | public $addr_from; |
| 43 | 43 | public $addr_to; |
@@ -59,19 +59,19 @@ discard block |
||
| 59 | 59 | * @param int $priority Priority |
| 60 | 60 | * @param int $class Class |
| 61 | 61 | */ |
| 62 | - function __construct($to,$from,$msg,$deliveryreceipt=0,$deferred=0,$priority=3,$class=1) |
|
| 62 | + function __construct($to, $from, $msg, $deliveryreceipt = 0, $deferred = 0, $priority = 3, $class = 1) |
|
| 63 | 63 | { |
| 64 | 64 | global $conf; |
| 65 | 65 | |
| 66 | 66 | // On definit fin de ligne |
| 67 | - $this->eol="\n"; |
|
| 68 | - if (preg_match('/^win/i',PHP_OS)) $this->eol="\r\n"; |
|
| 69 | - if (preg_match('/^mac/i',PHP_OS)) $this->eol="\r"; |
|
| 67 | + $this->eol = "\n"; |
|
| 68 | + if (preg_match('/^win/i', PHP_OS)) $this->eol = "\r\n"; |
|
| 69 | + if (preg_match('/^mac/i', PHP_OS)) $this->eol = "\r"; |
|
| 70 | 70 | |
| 71 | 71 | // If ending method not defined |
| 72 | 72 | if (empty($conf->global->MAIN_SMS_SENDMODE)) |
| 73 | 73 | { |
| 74 | - $this->error='No SMS Engine defined'; |
|
| 74 | + $this->error = 'No SMS Engine defined'; |
|
| 75 | 75 | return -1; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | dol_syslog("CSMSFile::CSMSFile: deferred=".$deferred." priority=".$priority." class=".$class, LOG_DEBUG); |
| 80 | 80 | |
| 81 | 81 | // Action according to choosed sending method |
| 82 | - $this->addr_from=$from; |
|
| 83 | - $this->addr_to=$to; |
|
| 84 | - $this->deferred=$deferred; |
|
| 85 | - $this->priority=$priority; |
|
| 86 | - $this->class=$class; |
|
| 87 | - $this->message=$msg; |
|
| 88 | - $this->nostop=false; |
|
| 82 | + $this->addr_from = $from; |
|
| 83 | + $this->addr_to = $to; |
|
| 84 | + $this->deferred = $deferred; |
|
| 85 | + $this->priority = $priority; |
|
| 86 | + $this->class = $class; |
|
| 87 | + $this->message = $msg; |
|
| 88 | + $this->nostop = false; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
@@ -98,17 +98,17 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | global $conf; |
| 100 | 100 | |
| 101 | - $errorlevel=error_reporting(); |
|
| 102 | - error_reporting($errorlevel ^ E_WARNING); // Desactive warnings |
|
| 101 | + $errorlevel = error_reporting(); |
|
| 102 | + error_reporting($errorlevel ^ E_WARNING); // Desactive warnings |
|
| 103 | 103 | |
| 104 | - $res=false; |
|
| 104 | + $res = false; |
|
| 105 | 105 | |
| 106 | 106 | dol_syslog("CSMSFile::sendfile addr_to=".$this->addr_to, LOG_DEBUG); |
| 107 | 107 | dol_syslog("CSMSFile::sendfile message=\n".$this->message); |
| 108 | 108 | |
| 109 | - $this->message=stripslashes($this->message); |
|
| 109 | + $this->message = stripslashes($this->message); |
|
| 110 | 110 | |
| 111 | - if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms(); |
|
| 111 | + if (!empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms(); |
|
| 112 | 112 | |
| 113 | 113 | if (empty($conf->global->MAIN_DISABLE_ALL_SMS)) |
| 114 | 114 | { |
@@ -117,46 +117,46 @@ discard block |
||
| 117 | 117 | if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // Backward compatibility @deprecated |
| 118 | 118 | { |
| 119 | 119 | dol_include_once('/ovh/class/ovhsms.class.php'); |
| 120 | - $sms=new OvhSms($this->db); |
|
| 121 | - $sms->expe=$this->addr_from; |
|
| 122 | - $sms->dest=$this->addr_to; |
|
| 123 | - $sms->message=$this->message; |
|
| 124 | - $sms->deferred=$this->deferred; |
|
| 125 | - $sms->priority=$this->priority; |
|
| 126 | - $sms->class=$this->class; |
|
| 127 | - $sms->nostop=$this->nostop; |
|
| 128 | - |
|
| 129 | - $res=$sms->SmsSend(); |
|
| 120 | + $sms = new OvhSms($this->db); |
|
| 121 | + $sms->expe = $this->addr_from; |
|
| 122 | + $sms->dest = $this->addr_to; |
|
| 123 | + $sms->message = $this->message; |
|
| 124 | + $sms->deferred = $this->deferred; |
|
| 125 | + $sms->priority = $this->priority; |
|
| 126 | + $sms->class = $this->class; |
|
| 127 | + $sms->nostop = $this->nostop; |
|
| 128 | + |
|
| 129 | + $res = $sms->SmsSend(); |
|
| 130 | 130 | if ($res <= 0) |
| 131 | 131 | { |
| 132 | - $this->error=$sms->error; |
|
| 132 | + $this->error = $sms->error; |
|
| 133 | 133 | dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR); |
| 134 | 134 | } |
| 135 | 135 | else |
| 136 | 136 | { |
| 137 | 137 | dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG); |
| 138 | 138 | //var_dump($res); // 1973128 |
| 139 | - if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res); |
|
| 139 | + if (!empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | - else if (! empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module' |
|
| 142 | + else if (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module' |
|
| 143 | 143 | { |
| 144 | - $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE); |
|
| 145 | - $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]); |
|
| 144 | + $tmp = explode('@', $conf->global->MAIN_SMS_SENDMODE); |
|
| 145 | + $classfile = $tmp[0]; $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]); |
|
| 146 | 146 | dol_include_once('/'.$module.'/class/'.$classfile.'.class.php'); |
| 147 | 147 | try |
| 148 | 148 | { |
| 149 | - $classname=ucfirst($classfile); |
|
| 149 | + $classname = ucfirst($classfile); |
|
| 150 | 150 | $sms = new $classname($this->db); |
| 151 | - $sms->expe=$this->addr_from; |
|
| 152 | - $sms->dest=$this->addr_to; |
|
| 153 | - $sms->deferred=$this->deferred; |
|
| 154 | - $sms->priority=$this->priority; |
|
| 155 | - $sms->class=$this->class; |
|
| 156 | - $sms->message=$this->message; |
|
| 157 | - $sms->nostop=$this->nostop; |
|
| 158 | - |
|
| 159 | - $res=$sms->SmsSend(); |
|
| 151 | + $sms->expe = $this->addr_from; |
|
| 152 | + $sms->dest = $this->addr_to; |
|
| 153 | + $sms->deferred = $this->deferred; |
|
| 154 | + $sms->priority = $this->priority; |
|
| 155 | + $sms->class = $this->class; |
|
| 156 | + $sms->message = $this->message; |
|
| 157 | + $sms->nostop = $this->nostop; |
|
| 158 | + |
|
| 159 | + $res = $sms->SmsSend(); |
|
| 160 | 160 | $this->error = $sms->error; |
| 161 | 161 | $this->errors = $sms->errors; |
| 162 | 162 | if ($res <= 0) |
@@ -167,12 +167,12 @@ discard block |
||
| 167 | 167 | { |
| 168 | 168 | dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG); |
| 169 | 169 | //var_dump($res); // 1973128 |
| 170 | - if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res); |
|
| 170 | + if (!empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | - catch(Exception $e) |
|
| 173 | + catch (Exception $e) |
|
| 174 | 174 | { |
| 175 | - dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
|
| 175 | + dol_print_error('', 'Error to get list of senders: '.$e->getMessage()); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | else |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | } |
| 186 | 186 | else |
| 187 | 187 | { |
| 188 | - $this->error='No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS'; |
|
| 188 | + $this->error = 'No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS'; |
|
| 189 | 189 | dol_syslog("CSMSFile::sendfile: ".$this->error, LOG_WARNING); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - error_reporting($errorlevel); // Reactive niveau erreur origine |
|
| 192 | + error_reporting($errorlevel); // Reactive niveau erreur origine |
|
| 193 | 193 | |
| 194 | 194 | return $res; |
| 195 | 195 | } |
@@ -205,12 +205,12 @@ discard block |
||
| 205 | 205 | function dump_sms() |
| 206 | 206 | { |
| 207 | 207 | // phpcs:enable |
| 208 | - global $conf,$dolibarr_main_data_root; |
|
| 208 | + global $conf, $dolibarr_main_data_root; |
|
| 209 | 209 | |
| 210 | 210 | if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir |
| 211 | 211 | { |
| 212 | - $outputfile=$dolibarr_main_data_root."/dolibarr_sms.log"; |
|
| 213 | - $fp = fopen($outputfile,"w"); |
|
| 212 | + $outputfile = $dolibarr_main_data_root."/dolibarr_sms.log"; |
|
| 213 | + $fp = fopen($outputfile, "w"); |
|
| 214 | 214 | |
| 215 | 215 | fputs($fp, "From: ".$this->addr_from."\n"); |
| 216 | 216 | fputs($fp, "To: ".$this->addr_to."\n"); |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | fputs($fp, "Message:\n".$this->message); |
| 222 | 222 | |
| 223 | 223 | fclose($fp); |
| 224 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 224 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 225 | 225 | @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
| 226 | 226 | } |
| 227 | 227 | } |
@@ -237,17 +237,17 @@ discard block |
||
| 237 | 237 | function dump_sms_result($result) |
| 238 | 238 | { |
| 239 | 239 | // phpcs:enable |
| 240 | - global $conf,$dolibarr_main_data_root; |
|
| 240 | + global $conf, $dolibarr_main_data_root; |
|
| 241 | 241 | |
| 242 | 242 | if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir |
| 243 | 243 | { |
| 244 | - $outputfile=$dolibarr_main_data_root."/dolibarr_sms.log"; |
|
| 245 | - $fp = fopen($outputfile,"a+"); |
|
| 244 | + $outputfile = $dolibarr_main_data_root."/dolibarr_sms.log"; |
|
| 245 | + $fp = fopen($outputfile, "a+"); |
|
| 246 | 246 | |
| 247 | 247 | fputs($fp, "\nResult id=".$result); |
| 248 | 248 | |
| 249 | 249 | fclose($fp); |
| 250 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 250 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 251 | 251 | @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
| 252 | 252 | } |
| 253 | 253 | } |