@@ -314,12 +314,12 @@ discard block |
||
314 | 314 | public $date_creation; |
315 | 315 | |
316 | 316 | // Dates |
317 | - public $date_validation; // Date creation |
|
318 | - public $date_modification; // Date validation |
|
317 | + public $date_validation; // Date creation |
|
318 | + public $date_modification; // Date validation |
|
319 | 319 | /** |
320 | 320 | * @var string Column name of the ref field. |
321 | 321 | */ |
322 | - protected $table_ref_field = ''; // Date last change (tms field) |
|
322 | + protected $table_ref_field = ''; // Date last change (tms field) |
|
323 | 323 | |
324 | 324 | |
325 | 325 | // No constructor as it is an abstract class |
@@ -339,20 +339,20 @@ discard block |
||
339 | 339 | global $db, $conf; |
340 | 340 | |
341 | 341 | $sql = "SELECT rowid, ref, ref_ext"; |
342 | - $sql .= " FROM " . MAIN_DB_PREFIX . $element; |
|
343 | - $sql .= " WHERE entity IN (" . getEntity($element) . ")"; |
|
342 | + $sql .= " FROM ".MAIN_DB_PREFIX.$element; |
|
343 | + $sql .= " WHERE entity IN (".getEntity($element).")"; |
|
344 | 344 | |
345 | - if ($id > 0) $sql .= " AND rowid = " . $db->escape($id); |
|
346 | - else if ($ref) $sql .= " AND ref = '" . $db->escape($ref) . "'"; |
|
347 | - else if ($ref_ext) $sql .= " AND ref_ext = '" . $db->escape($ref_ext) . "'"; |
|
345 | + if ($id > 0) $sql .= " AND rowid = ".$db->escape($id); |
|
346 | + else if ($ref) $sql .= " AND ref = '".$db->escape($ref)."'"; |
|
347 | + else if ($ref_ext) $sql .= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
348 | 348 | else { |
349 | 349 | $error = 'ErrorWrongParameters'; |
350 | - dol_print_error(get_class() . "::isExistingObject " . $error, LOG_ERR); |
|
350 | + dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
|
351 | 351 | return -1; |
352 | 352 | } |
353 | - if ($ref || $ref_ext) $sql .= " AND entity = " . $conf->entity; |
|
353 | + if ($ref || $ref_ext) $sql .= " AND entity = ".$conf->entity; |
|
354 | 354 | |
355 | - dol_syslog(get_class() . "::isExistingObject", LOG_DEBUG); |
|
355 | + dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
|
356 | 356 | $resql = $db->query($sql); |
357 | 357 | if ($resql) { |
358 | 358 | $num = $db->num_rows($resql); |
@@ -377,10 +377,10 @@ discard block |
||
377 | 377 | public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) |
378 | 378 | { |
379 | 379 | foreach ($tables as $table) { |
380 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $table . ' SET fk_soc = ' . $dest_id . ' WHERE fk_soc = ' . $origin_id; |
|
380 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
|
381 | 381 | |
382 | 382 | if (!$db->query($sql)) { |
383 | - 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. |
|
383 | + 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. |
|
384 | 384 | //$this->errors = $db->lasterror(); |
385 | 385 | return false; |
386 | 386 | } |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | */ |
397 | 397 | function errorsToString() |
398 | 398 | { |
399 | - return $this->error . (is_array($this->errors) ? (($this->error != '' ? ', ' : '') . join(', ', $this->errors)) : ''); |
|
399 | + return $this->error.(is_array($this->errors) ? (($this->error != '' ? ', ' : '').join(', ', $this->errors)) : ''); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | { |
411 | 411 | global $conf, $langs; |
412 | 412 | |
413 | - $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
413 | + $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
414 | 414 | |
415 | 415 | $contactid = 0; |
416 | 416 | $thirdpartyid = 0; |
@@ -432,13 +432,13 @@ discard block |
||
432 | 432 | $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
433 | 433 | if ($coords) { |
434 | 434 | if (!empty($conf->use_javascript_ajax)) { |
435 | - $namecoords = $this->getFullName($langs, 1) . '<br>' . $coords; |
|
435 | + $namecoords = $this->getFullName($langs, 1).'<br>'.$coords; |
|
436 | 436 | // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
437 | - $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\'' . dol_escape_js($namecoords) . '\',\'' . dol_escape_js($langs->trans("HelpCopyToClipboard")) . '\');">'; |
|
437 | + $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">'; |
|
438 | 438 | $out .= img_picto($langs->trans("Address"), 'object_address.png'); |
439 | 439 | $out .= '</a> '; |
440 | 440 | } |
441 | - $out .= dol_print_address($coords, 'address_' . $htmlkey . '_' . $this->id, $this->element, $this->id, 1, ', '); |
|
441 | + $out .= dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); |
|
442 | 442 | $outdone++; |
443 | 443 | $outdone++; |
444 | 444 | } |
@@ -446,9 +446,9 @@ discard block |
||
446 | 446 | 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 |
447 | 447 | && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) { |
448 | 448 | if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) { |
449 | - $out .= ($outdone ? ' - ' : '') . $this->region . ' - ' . $this->state; |
|
449 | + $out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state; |
|
450 | 450 | } else { |
451 | - $out .= ($outdone ? ' - ' : '') . $this->state; |
|
451 | + $out .= ($outdone ? ' - ' : '').$this->state; |
|
452 | 452 | } |
453 | 453 | $outdone++; |
454 | 454 | } |
@@ -526,14 +526,14 @@ discard block |
||
526 | 526 | function getFullAddress($withcountry = 0, $sep = "\n", $withregion = 0) |
527 | 527 | { |
528 | 528 | if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) { |
529 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; |
|
529 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
530 | 530 | $tmparray = getCountry($this->country_id, 'all'); |
531 | 531 | $this->country_code = $tmparray['code']; |
532 | 532 | $this->country = $tmparray['label']; |
533 | 533 | } |
534 | 534 | |
535 | 535 | if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) { |
536 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; |
|
536 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
537 | 537 | $tmparray = getState($this->state_id, 'all', 0, 1); |
538 | 538 | $this->state_code = $tmparray['code']; |
539 | 539 | $this->state = $tmparray['label']; |
@@ -562,8 +562,8 @@ discard block |
||
562 | 562 | |
563 | 563 | $ret = ''; |
564 | 564 | if ($option && $this->civility_id) { |
565 | - if ($langs->transnoentitiesnoconv("Civility" . $this->civility_id) != "Civility" . $this->civility_id) $ret .= $langs->transnoentitiesnoconv("Civility" . $this->civility_id) . ' '; |
|
566 | - else $ret .= $this->civility_id . ' '; |
|
565 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id) != "Civility".$this->civility_id) $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
566 | + else $ret .= $this->civility_id.' '; |
|
567 | 567 | } |
568 | 568 | |
569 | 569 | $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder); |
@@ -587,10 +587,10 @@ discard block |
||
587 | 587 | global $user, $dolibarr_main_url_root; |
588 | 588 | |
589 | 589 | if (empty($this->last_main_doc)) { |
590 | - return ''; // No way to known which document name to use |
|
590 | + return ''; // No way to known which document name to use |
|
591 | 591 | } |
592 | 592 | |
593 | - include_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmfiles.class.php'; |
|
593 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
594 | 594 | $ecmfile = new EcmFiles($this->db); |
595 | 595 | $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
596 | 596 | if ($result < 0) { |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | if (empty($ecmfile->id)) { |
603 | 603 | // Add entry into index |
604 | 604 | if ($initsharekey) { |
605 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; |
|
605 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
606 | 606 | // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first |
607 | 607 | /* |
608 | 608 | $ecmfile->filepath = $rel_dir; |
@@ -624,15 +624,15 @@ discard block |
||
624 | 624 | } elseif (empty($ecmfile->share)) { |
625 | 625 | // Add entry into index |
626 | 626 | if ($initsharekey) { |
627 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; |
|
627 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
628 | 628 | $ecmfile->share = getRandomPassword(true); |
629 | 629 | $ecmfile->update($user); |
630 | 630 | } else return ''; |
631 | 631 | } |
632 | 632 | |
633 | 633 | // Define $urlwithroot |
634 | - $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root)); |
|
635 | - $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT; // This is to use external domain name found into config file |
|
634 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
635 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
636 | 636 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
637 | 637 | |
638 | 638 | $forcedownload = 0; |
@@ -641,13 +641,13 @@ discard block |
||
641 | 641 | //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
642 | 642 | //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
643 | 643 | //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
644 | - if (!empty($ecmfile->share)) $paramlink .= ($paramlink ? '&' : '') . 'hashp=' . $ecmfile->share; // Hash for public share |
|
645 | - if ($forcedownload) $paramlink .= ($paramlink ? '&' : '') . 'attachment=1'; |
|
644 | + if (!empty($ecmfile->share)) $paramlink .= ($paramlink ? '&' : '').'hashp='.$ecmfile->share; // Hash for public share |
|
645 | + if ($forcedownload) $paramlink .= ($paramlink ? '&' : '').'attachment=1'; |
|
646 | 646 | |
647 | 647 | if ($relativelink) { |
648 | - $linktoreturn = 'document.php' . ($paramlink ? '?' . $paramlink : ''); |
|
648 | + $linktoreturn = 'document.php'.($paramlink ? '?'.$paramlink : ''); |
|
649 | 649 | } else { |
650 | - $linktoreturn = $urlwithroot . '/document.php' . ($paramlink ? '?' . $paramlink : ''); |
|
650 | + $linktoreturn = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : ''); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | // Here $ecmfile->share is defined |
@@ -693,19 +693,19 @@ discard block |
||
693 | 693 | global $user, $langs; |
694 | 694 | |
695 | 695 | |
696 | - dol_syslog(get_class($this) . "::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
|
696 | + dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
|
697 | 697 | |
698 | 698 | // Check parameters |
699 | 699 | if ($fk_socpeople <= 0) { |
700 | 700 | $langs->load("errors"); |
701 | 701 | $this->error = $langs->trans("ErrorWrongValueForParameterX", "1"); |
702 | - dol_syslog(get_class($this) . "::add_contact " . $this->error, LOG_ERR); |
|
702 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
703 | 703 | return -1; |
704 | 704 | } |
705 | 705 | if (!$type_contact) { |
706 | 706 | $langs->load("errors"); |
707 | 707 | $this->error = $langs->trans("ErrorWrongValueForParameterX", "2"); |
708 | - dol_syslog(get_class($this) . "::add_contact " . $this->error, LOG_ERR); |
|
708 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
709 | 709 | return -2; |
710 | 710 | } |
711 | 711 | |
@@ -715,10 +715,10 @@ discard block |
||
715 | 715 | } else { |
716 | 716 | // We look for id type_contact |
717 | 717 | $sql = "SELECT tc.rowid"; |
718 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_type_contact as tc"; |
|
719 | - $sql .= " WHERE tc.element='" . $this->db->escape($this->element) . "'"; |
|
720 | - $sql .= " AND tc.source='" . $this->db->escape($source) . "'"; |
|
721 | - $sql .= " AND tc.code='" . $this->db->escape($type_contact) . "' AND tc.active=1"; |
|
718 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
719 | + $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
720 | + $sql .= " AND tc.source='".$this->db->escape($source)."'"; |
|
721 | + $sql .= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
722 | 722 | //print $sql; |
723 | 723 | $resql = $this->db->query($sql); |
724 | 724 | if ($resql) { |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | |
730 | 730 | if ($id_type_contact == 0) { |
731 | 731 | $this->error = 'CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
732 | - 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"); |
|
732 | + 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"); |
|
733 | 733 | return -3; |
734 | 734 | } |
735 | 735 | |
@@ -752,17 +752,17 @@ discard block |
||
752 | 752 | $this->db->begin(); |
753 | 753 | |
754 | 754 | // Insert into database |
755 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_contact"; |
|
755 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
|
756 | 756 | $sql .= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
757 | - $sql .= " VALUES (" . $this->id . ", " . $fk_socpeople . " , "; |
|
758 | - $sql .= "'" . $this->db->idate($datecreate) . "'"; |
|
759 | - $sql .= ", 4, " . $id_type_contact; |
|
757 | + $sql .= " VALUES (".$this->id.", ".$fk_socpeople." , "; |
|
758 | + $sql .= "'".$this->db->idate($datecreate)."'"; |
|
759 | + $sql .= ", 4, ".$id_type_contact; |
|
760 | 760 | $sql .= ")"; |
761 | 761 | |
762 | 762 | $resql = $this->db->query($sql); |
763 | 763 | if ($resql) { |
764 | 764 | if (!$notrigger) { |
765 | - $result = $this->call_trigger(strtoupper($this->element) . '_ADD_CONTACT', $user); |
|
765 | + $result = $this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
766 | 766 | if ($result < 0) { |
767 | 767 | $this->db->rollback(); |
768 | 768 | return -1; |
@@ -804,26 +804,26 @@ discard block |
||
804 | 804 | |
805 | 805 | $tab = array(); |
806 | 806 | |
807 | - $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 |
|
807 | + $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 |
|
808 | 808 | if ($source == 'internal') $sql .= ", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
809 | 809 | if ($source == 'external' || $source == 'thirdparty') $sql .= ", t.fk_soc as socid, t.statut as statuscontact"; |
810 | 810 | $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
811 | 811 | $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; |
812 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_type_contact tc"; |
|
813 | - $sql .= ", " . MAIN_DB_PREFIX . "element_contact ec"; |
|
814 | - if ($source == 'internal') $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user t on ec.fk_socpeople = t.rowid"; |
|
815 | - if ($source == 'external' || $source == 'thirdparty') $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople t on ec.fk_socpeople = t.rowid"; |
|
816 | - $sql .= " WHERE ec.element_id =" . $this->id; |
|
812 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
813 | + $sql .= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
814 | + if ($source == 'internal') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
815 | + if ($source == 'external' || $source == 'thirdparty') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
816 | + $sql .= " WHERE ec.element_id =".$this->id; |
|
817 | 817 | $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
818 | - $sql .= " AND tc.element='" . $this->db->escape($this->element) . "'"; |
|
819 | - if ($code) $sql .= " AND tc.code = '" . $this->db->escape($code) . "'"; |
|
818 | + $sql .= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
819 | + if ($code) $sql .= " AND tc.code = '".$this->db->escape($code)."'"; |
|
820 | 820 | if ($source == 'internal') $sql .= " AND tc.source = 'internal'"; |
821 | 821 | if ($source == 'external' || $source == 'thirdparty') $sql .= " AND tc.source = 'external'"; |
822 | 822 | $sql .= " AND tc.active=1"; |
823 | - if ($statut >= 0) $sql .= " AND ec.statut = '" . $statut . "'"; |
|
823 | + if ($statut >= 0) $sql .= " AND ec.statut = '".$statut."'"; |
|
824 | 824 | $sql .= " ORDER BY t.lastname ASC"; |
825 | 825 | |
826 | - dol_syslog(get_class($this) . "::liste_contact", LOG_DEBUG); |
|
826 | + dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
|
827 | 827 | $resql = $this->db->query($sql); |
828 | 828 | if ($resql) { |
829 | 829 | $num = $this->db->num_rows($resql); |
@@ -832,10 +832,10 @@ discard block |
||
832 | 832 | $obj = $this->db->fetch_object($resql); |
833 | 833 | |
834 | 834 | if (!$list) { |
835 | - $transkey = "TypeContact_" . $obj->element . "_" . $obj->source . "_" . $obj->code; |
|
835 | + $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
836 | 836 | $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); |
837 | 837 | $tab[$i] = array('source' => $obj->source, 'socid' => $obj->socid, 'id' => $obj->id, |
838 | - 'nom' => $obj->lastname, // For backward compatibility |
|
838 | + 'nom' => $obj->lastname, // For backward compatibility |
|
839 | 839 | 'civility' => $obj->civility, 'lastname' => $obj->lastname, 'firstname' => $obj->firstname, 'email' => $obj->email, 'login' => $obj->login, 'photo' => $obj->photo, 'statuscontact' => $obj->statuscontact, |
840 | 840 | 'rowid' => $obj->rowid, 'code' => $obj->code, 'libelle' => $libelle_type, 'status' => $obj->statuslink, 'fk_c_type_contact' => $obj->fk_c_type_contact); |
841 | 841 | } else { |
@@ -870,13 +870,13 @@ discard block |
||
870 | 870 | // phpcs:enable |
871 | 871 | global $langs, $conf; |
872 | 872 | |
873 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
873 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
874 | 874 | $interface = new Interfaces($this->db); |
875 | 875 | $result = $interface->run_triggers($trigger_name, $this, $user, $langs, $conf); |
876 | 876 | |
877 | 877 | if ($result < 0) { |
878 | 878 | if (!empty($this->errors)) { |
879 | - $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. |
|
879 | + $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. |
|
880 | 880 | } else { |
881 | 881 | $this->errors = $interface->errors; |
882 | 882 | } |
@@ -901,13 +901,13 @@ discard block |
||
901 | 901 | |
902 | 902 | $this->db->begin(); |
903 | 903 | |
904 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_contact"; |
|
905 | - $sql .= " WHERE rowid =" . $rowid; |
|
904 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
905 | + $sql .= " WHERE rowid =".$rowid; |
|
906 | 906 | |
907 | - dol_syslog(get_class($this) . "::delete_contact", LOG_DEBUG); |
|
907 | + dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
|
908 | 908 | if ($this->db->query($sql)) { |
909 | 909 | if (!$notrigger) { |
910 | - $result = $this->call_trigger(strtoupper($this->element) . '_DELETE_CONTACT', $user); |
|
910 | + $result = $this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
911 | 911 | if ($result < 0) { |
912 | 912 | $this->db->rollback(); |
913 | 913 | return -1; |
@@ -941,12 +941,12 @@ discard block |
||
941 | 941 | } |
942 | 942 | $listId = implode(",", $temp); |
943 | 943 | |
944 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_contact"; |
|
945 | - $sql .= " WHERE element_id = " . $this->id; |
|
944 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
945 | + $sql .= " WHERE element_id = ".$this->id; |
|
946 | 946 | if ($listId) |
947 | - $sql .= " AND fk_c_type_contact IN (" . $listId . ")"; |
|
947 | + $sql .= " AND fk_c_type_contact IN (".$listId.")"; |
|
948 | 948 | |
949 | - dol_syslog(get_class($this) . "::delete_linked_contact", LOG_DEBUG); |
|
949 | + dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
|
950 | 950 | if ($this->db->query($sql)) { |
951 | 951 | return 1; |
952 | 952 | } else { |
@@ -977,11 +977,11 @@ discard block |
||
977 | 977 | |
978 | 978 | $tab = array(); |
979 | 979 | $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
980 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_type_contact as tc"; |
|
981 | - $sql .= " WHERE tc.element='" . $this->db->escape($this->element) . "'"; |
|
980 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
981 | + $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
982 | 982 | if ($activeonly == 1) $sql .= " AND tc.active=1"; // only the active types |
983 | - if (!empty($source) && $source != 'all') $sql .= " AND tc.source='" . $this->db->escape($source) . "'"; |
|
984 | - if (!empty($code)) $sql .= " AND tc.code='" . $this->db->escape($code) . "'"; |
|
983 | + if (!empty($source) && $source != 'all') $sql .= " AND tc.source='".$this->db->escape($source)."'"; |
|
984 | + if (!empty($code)) $sql .= " AND tc.code='".$this->db->escape($code)."'"; |
|
985 | 985 | $sql .= $this->db->order($order, 'ASC'); |
986 | 986 | |
987 | 987 | //print "sql=".$sql; |
@@ -992,7 +992,7 @@ discard block |
||
992 | 992 | while ($i < $num) { |
993 | 993 | $obj = $this->db->fetch_object($resql); |
994 | 994 | |
995 | - $transkey = "TypeContact_" . $this->element . "_" . $source . "_" . $obj->code; |
|
995 | + $transkey = "TypeContact_".$this->element."_".$source."_".$obj->code; |
|
996 | 996 | $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); |
997 | 997 | if (empty($option)) $tab[$obj->rowid] = $libelle_type; |
998 | 998 | else $tab[$obj->code] = $libelle_type; |
@@ -1017,13 +1017,13 @@ discard block |
||
1017 | 1017 | $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
1018 | 1018 | $sql .= " tc.code, tc.libelle"; |
1019 | 1019 | //$sql.= ", s.fk_soc"; |
1020 | - $sql .= " FROM (" . MAIN_DB_PREFIX . "element_contact as ec, " . MAIN_DB_PREFIX . "c_type_contact as tc)"; |
|
1020 | + $sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; |
|
1021 | 1021 | //$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 |
1022 | - $sql .= " WHERE ec.rowid =" . $rowid; |
|
1022 | + $sql .= " WHERE ec.rowid =".$rowid; |
|
1023 | 1023 | $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
1024 | - $sql .= " AND tc.element = '" . $this->db->escape($this->element) . "'"; |
|
1024 | + $sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
1025 | 1025 | |
1026 | - dol_syslog(get_class($this) . "::swapContactStatus", LOG_DEBUG); |
|
1026 | + dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
|
1027 | 1027 | $resql = $this->db->query($sql); |
1028 | 1028 | if ($resql) { |
1029 | 1029 | $obj = $this->db->fetch_object($resql); |
@@ -1053,11 +1053,11 @@ discard block |
||
1053 | 1053 | { |
1054 | 1054 | // phpcs:enable |
1055 | 1055 | // Insert into database |
1056 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "element_contact set"; |
|
1057 | - $sql .= " statut = " . $statut; |
|
1058 | - if ($type_contact_id) $sql .= ", fk_c_type_contact = '" . $type_contact_id . "'"; |
|
1059 | - if ($fk_socpeople) $sql .= ", fk_socpeople = '" . $fk_socpeople . "'"; |
|
1060 | - $sql .= " where rowid = " . $rowid; |
|
1056 | + $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
|
1057 | + $sql .= " statut = ".$statut; |
|
1058 | + if ($type_contact_id) $sql .= ", fk_c_type_contact = '".$type_contact_id."'"; |
|
1059 | + if ($fk_socpeople) $sql .= ", fk_socpeople = '".$fk_socpeople."'"; |
|
1060 | + $sql .= " where rowid = ".$rowid; |
|
1061 | 1061 | $resql = $this->db->query($sql); |
1062 | 1062 | if ($resql) { |
1063 | 1063 | return 0; |
@@ -1099,22 +1099,22 @@ discard block |
||
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | $sql = "SELECT ec.fk_socpeople"; |
1102 | - $sql .= " FROM " . MAIN_DB_PREFIX . "element_contact as ec,"; |
|
1103 | - if ($source == 'internal') $sql .= " " . MAIN_DB_PREFIX . "user as c,"; |
|
1104 | - if ($source == 'external') $sql .= " " . MAIN_DB_PREFIX . "socpeople as c,"; |
|
1105 | - $sql .= " " . MAIN_DB_PREFIX . "c_type_contact as tc"; |
|
1106 | - $sql .= " WHERE ec.element_id = " . $id; |
|
1102 | + $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
1103 | + if ($source == 'internal') $sql .= " ".MAIN_DB_PREFIX."user as c,"; |
|
1104 | + if ($source == 'external') $sql .= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
1105 | + $sql .= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
1106 | + $sql .= " WHERE ec.element_id = ".$id; |
|
1107 | 1107 | $sql .= " AND ec.fk_socpeople = c.rowid"; |
1108 | - if ($source == 'internal') $sql .= " AND c.entity IN (" . getEntity('user') . ")"; |
|
1109 | - if ($source == 'external') $sql .= " AND c.entity IN (" . getEntity('societe') . ")"; |
|
1108 | + if ($source == 'internal') $sql .= " AND c.entity IN (".getEntity('user').")"; |
|
1109 | + if ($source == 'external') $sql .= " AND c.entity IN (".getEntity('societe').")"; |
|
1110 | 1110 | $sql .= " AND ec.fk_c_type_contact = tc.rowid"; |
1111 | - $sql .= " AND tc.element = '" . $element . "'"; |
|
1112 | - $sql .= " AND tc.source = '" . $source . "'"; |
|
1113 | - $sql .= " AND tc.code = '" . $code . "'"; |
|
1111 | + $sql .= " AND tc.element = '".$element."'"; |
|
1112 | + $sql .= " AND tc.source = '".$source."'"; |
|
1113 | + $sql .= " AND tc.code = '".$code."'"; |
|
1114 | 1114 | $sql .= " AND tc.active = 1"; |
1115 | - if ($status) $sql .= " AND ec.statut = " . $status; |
|
1115 | + if ($status) $sql .= " AND ec.statut = ".$status; |
|
1116 | 1116 | |
1117 | - dol_syslog(get_class($this) . "::getIdContact", LOG_DEBUG); |
|
1117 | + dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
|
1118 | 1118 | $resql = $this->db->query($sql); |
1119 | 1119 | if ($resql) { |
1120 | 1120 | while ($obj = $this->db->fetch_object($resql)) { |
@@ -1142,7 +1142,7 @@ discard block |
||
1142 | 1142 | |
1143 | 1143 | if (empty($contactid)) return 0; |
1144 | 1144 | |
1145 | - require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; |
|
1145 | + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
1146 | 1146 | $contact = new Contact($this->db); |
1147 | 1147 | $result = $contact->fetch($contactid); |
1148 | 1148 | $this->contact = $contact; |
@@ -1165,7 +1165,7 @@ discard block |
||
1165 | 1165 | if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
1166 | 1166 | return 0; |
1167 | 1167 | |
1168 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
1168 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
1169 | 1169 | |
1170 | 1170 | $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
1171 | 1171 | if ($force_thirdparty_id) |
@@ -1201,7 +1201,7 @@ discard block |
||
1201 | 1201 | return 0; |
1202 | 1202 | } |
1203 | 1203 | |
1204 | - $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . $this->table_element . ' WHERE ' . $this->table_ref_field . ' LIKE "' . $this->db->escape($ref) . '" LIMIT 1'; |
|
1204 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE '.$this->table_ref_field.' LIKE "'.$this->db->escape($ref).'" LIMIT 1'; |
|
1205 | 1205 | |
1206 | 1206 | $query = $this->db->query($sql); |
1207 | 1207 | |
@@ -1228,7 +1228,7 @@ discard block |
||
1228 | 1228 | // phpcs:enable |
1229 | 1229 | global $conf; |
1230 | 1230 | |
1231 | - dol_syslog(get_class($this) . '::fetch_barcode this->element=' . $this->element . ' this->barcode_type=' . $this->barcode_type); |
|
1231 | + dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
|
1232 | 1232 | |
1233 | 1233 | $idtype = $this->barcode_type; |
1234 | 1234 | 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 |
@@ -1242,9 +1242,9 @@ discard block |
||
1242 | 1242 | 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 |
1243 | 1243 | { |
1244 | 1244 | $sql = "SELECT rowid, code, libelle as label, coder"; |
1245 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_barcode_type"; |
|
1246 | - $sql .= " WHERE rowid = " . $idtype; |
|
1247 | - dol_syslog(get_class($this) . '::fetch_barcode', LOG_DEBUG); |
|
1245 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
1246 | + $sql .= " WHERE rowid = ".$idtype; |
|
1247 | + dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
|
1248 | 1248 | $resql = $this->db->query($sql); |
1249 | 1249 | if ($resql) { |
1250 | 1250 | $obj = $this->db->fetch_object($resql); |
@@ -1272,15 +1272,15 @@ discard block |
||
1272 | 1272 | function fetch_projet() |
1273 | 1273 | { |
1274 | 1274 | // phpcs:enable |
1275 | - include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; |
|
1275 | + include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
1276 | 1276 | |
1277 | - if (empty($this->fk_project) && !empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
1277 | + if (empty($this->fk_project) && !empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
1278 | 1278 | if (empty($this->fk_project)) return 0; |
1279 | 1279 | |
1280 | 1280 | $project = new Project($this->db); |
1281 | 1281 | $result = $project->fetch($this->fk_project); |
1282 | 1282 | |
1283 | - $this->projet = $project; // deprecated |
|
1283 | + $this->projet = $project; // deprecated |
|
1284 | 1284 | $this->project = $project; |
1285 | 1285 | return $result; |
1286 | 1286 | } |
@@ -1295,7 +1295,7 @@ discard block |
||
1295 | 1295 | function fetch_product() |
1296 | 1296 | { |
1297 | 1297 | // phpcs:enable |
1298 | - include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; |
|
1298 | + include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
1299 | 1299 | |
1300 | 1300 | if (empty($this->fk_product)) return 0; |
1301 | 1301 | |
@@ -1355,15 +1355,15 @@ discard block |
||
1355 | 1355 | |
1356 | 1356 | $result = false; |
1357 | 1357 | |
1358 | - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . $table; |
|
1359 | - $sql .= " WHERE " . $field . " = '" . $key . "'"; |
|
1358 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
|
1359 | + $sql .= " WHERE ".$field." = '".$key."'"; |
|
1360 | 1360 | if (!empty($element)) { |
1361 | - $sql .= " AND entity IN (" . getEntity($element) . ")"; |
|
1361 | + $sql .= " AND entity IN (".getEntity($element).")"; |
|
1362 | 1362 | } else { |
1363 | - $sql .= " AND entity = " . $conf->entity; |
|
1363 | + $sql .= " AND entity = ".$conf->entity; |
|
1364 | 1364 | } |
1365 | 1365 | |
1366 | - dol_syslog(get_class($this) . '::fetchObjectFrom', LOG_DEBUG); |
|
1366 | + dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
|
1367 | 1367 | $resql = $this->db->query($sql); |
1368 | 1368 | if ($resql) { |
1369 | 1369 | $row = $this->db->fetch_row($resql); |
@@ -1390,10 +1390,10 @@ discard block |
||
1390 | 1390 | { |
1391 | 1391 | $result = false; |
1392 | 1392 | if (!empty($id) && !empty($field) && !empty($table)) { |
1393 | - $sql = "SELECT " . $field . " FROM " . MAIN_DB_PREFIX . $table; |
|
1394 | - $sql .= " WHERE rowid = " . $id; |
|
1393 | + $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
|
1394 | + $sql .= " WHERE rowid = ".$id; |
|
1395 | 1395 | |
1396 | - dol_syslog(get_class($this) . '::getValueFrom', LOG_DEBUG); |
|
1396 | + dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
|
1397 | 1397 | $resql = $this->db->query($sql); |
1398 | 1398 | if ($resql) { |
1399 | 1399 | $row = $this->db->fetch_row($resql); |
@@ -1436,20 +1436,20 @@ discard block |
||
1436 | 1436 | if ($table == 'product' && $field == 'note_private') $field = 'note'; |
1437 | 1437 | if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod'; |
1438 | 1438 | |
1439 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $table . " SET "; |
|
1439 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
|
1440 | 1440 | |
1441 | - if ($format == 'text') $sql .= $field . " = '" . $this->db->escape($value) . "'"; |
|
1442 | - else if ($format == 'int') $sql .= $field . " = " . $this->db->escape($value); |
|
1443 | - else if ($format == 'date') $sql .= $field . " = " . ($value ? "'" . $this->db->idate($value) . "'" : "null"); |
|
1441 | + if ($format == 'text') $sql .= $field." = '".$this->db->escape($value)."'"; |
|
1442 | + else if ($format == 'int') $sql .= $field." = ".$this->db->escape($value); |
|
1443 | + else if ($format == 'date') $sql .= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
1444 | 1444 | |
1445 | 1445 | if ($fk_user_field) { |
1446 | - if (!empty($fuser) && is_object($fuser)) $sql .= ", " . $fk_user_field . " = " . $fuser->id; |
|
1447 | - elseif (empty($fuser) || $fuser != 'none') $sql .= ", " . $fk_user_field . " = " . $user->id; |
|
1446 | + if (!empty($fuser) && is_object($fuser)) $sql .= ", ".$fk_user_field." = ".$fuser->id; |
|
1447 | + elseif (empty($fuser) || $fuser != 'none') $sql .= ", ".$fk_user_field." = ".$user->id; |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | - $sql .= " WHERE " . $id_field . " = " . $id; |
|
1450 | + $sql .= " WHERE ".$id_field." = ".$id; |
|
1451 | 1451 | |
1452 | - dol_syslog(get_class($this) . "::" . __FUNCTION__ . "", LOG_DEBUG); |
|
1452 | + dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
|
1453 | 1453 | $resql = $this->db->query($sql); |
1454 | 1454 | if ($resql) { |
1455 | 1455 | if ($trigkey) { |
@@ -1459,7 +1459,7 @@ discard block |
||
1459 | 1459 | } else { |
1460 | 1460 | $result = $this->fetchCommon($id); |
1461 | 1461 | } |
1462 | - if ($result >= 0) $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
1462 | + if ($result >= 0) $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
1463 | 1463 | if ($result < 0) $error++; |
1464 | 1464 | } |
1465 | 1465 | |
@@ -1490,14 +1490,14 @@ discard block |
||
1490 | 1490 | { |
1491 | 1491 | if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
1492 | 1492 | |
1493 | - $sql = 'SELECT ' . $this->getFieldList(); |
|
1494 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element; |
|
1493 | + $sql = 'SELECT '.$this->getFieldList(); |
|
1494 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
1495 | 1495 | |
1496 | - if (!empty($id)) $sql .= ' WHERE rowid = ' . $id; |
|
1497 | - elseif (!empty($ref)) $sql .= " WHERE ref = " . $this->quote($ref, $this->fields['ref']); |
|
1498 | - else $sql .= ' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
1496 | + if (!empty($id)) $sql .= ' WHERE rowid = '.$id; |
|
1497 | + elseif (!empty($ref)) $sql .= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
1498 | + else $sql .= ' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
1499 | 1499 | if ($morewhere) $sql .= $morewhere; |
1500 | - $sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
1500 | + $sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
1501 | 1501 | |
1502 | 1502 | $res = $this->db->query($sql); |
1503 | 1503 | if ($res) { |
@@ -1537,7 +1537,7 @@ discard block |
||
1537 | 1537 | { |
1538 | 1538 | if (is_null($value)) return 'NULL'; |
1539 | 1539 | else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value"); |
1540 | - else return "'" . $this->db->escape($value) . "'"; |
|
1540 | + else return "'".$this->db->escape($value)."'"; |
|
1541 | 1541 | } |
1542 | 1542 | |
1543 | 1543 | /** |
@@ -1561,10 +1561,10 @@ discard block |
||
1561 | 1561 | $this->{$field} = array(); |
1562 | 1562 | } |
1563 | 1563 | } elseif ($this->isInt($info)) { |
1564 | - if ($field == 'rowid') $this->id = (int)$obj->{$field}; |
|
1565 | - else $this->{$field} = (int)$obj->{$field}; |
|
1564 | + if ($field == 'rowid') $this->id = (int) $obj->{$field}; |
|
1565 | + else $this->{$field} = (int) $obj->{$field}; |
|
1566 | 1566 | } elseif ($this->isFloat($info)) { |
1567 | - $this->{$field} = (double)$obj->{$field}; |
|
1567 | + $this->{$field} = (double) $obj->{$field}; |
|
1568 | 1568 | } elseif ($this->isNull($info)) { |
1569 | 1569 | $val = $obj->{$field}; |
1570 | 1570 | // zero is not null |
@@ -1660,7 +1660,7 @@ discard block |
||
1660 | 1660 | global $conf, $user; |
1661 | 1661 | |
1662 | 1662 | if (!$this->table_element) { |
1663 | - dol_print_error('', get_class($this) . "::load_previous_next_ref was called on objet with property table_element not defined"); |
|
1663 | + dol_print_error('', get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
|
1664 | 1664 | return -1; |
1665 | 1665 | } |
1666 | 1666 | if ($fieldid == 'none') return 1; |
@@ -1674,39 +1674,39 @@ discard block |
||
1674 | 1674 | $alias = 's'; |
1675 | 1675 | if ($this->element == 'societe') $alias = 'te'; |
1676 | 1676 | |
1677 | - $sql = "SELECT MAX(te." . $fieldid . ")"; |
|
1678 | - $sql .= " FROM " . (empty($nodbprefix) ? MAIN_DB_PREFIX : '') . $this->table_element . " as te"; |
|
1677 | + $sql = "SELECT MAX(te.".$fieldid.")"; |
|
1678 | + $sql .= " FROM ".(empty($nodbprefix) ? MAIN_DB_PREFIX : '').$this->table_element." as te"; |
|
1679 | 1679 | if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
1680 | - $sql .= "," . MAIN_DB_PREFIX . "usergroup_user as ug"; |
|
1681 | - } |
|
1682 | - 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 |
|
1683 | - 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 |
|
1684 | - 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 |
|
1685 | - 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"; |
|
1686 | - $sql .= " WHERE te." . $fieldid . " < '" . $this->db->escape($this->ref) . "'"; // ->ref must always be defined (set to id if field does not exists) |
|
1687 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = " . $user->id; |
|
1688 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = " . $user->id . ' OR te.fk_soc IS NULL)'; |
|
1680 | + $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1681 | + } |
|
1682 | + 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 |
|
1683 | + 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 |
|
1684 | + 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 |
|
1685 | + 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"; |
|
1686 | + $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1687 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id; |
|
1688 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)'; |
|
1689 | 1689 | if (!empty($filter)) { |
1690 | - if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
1690 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
1691 | 1691 | $sql .= $filter; |
1692 | 1692 | } |
1693 | - 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 |
|
1694 | - 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 |
|
1693 | + 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 |
|
1694 | + 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 |
|
1695 | 1695 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
1696 | 1696 | if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
1697 | 1697 | if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
1698 | 1698 | $sql .= " AND te.entity IS NOT NULL"; // Show all users |
1699 | 1699 | } else { |
1700 | 1700 | $sql .= " AND ug.fk_user = te.rowid"; |
1701 | - $sql .= " AND ug.entity IN (" . getEntity($this->element) . ")"; |
|
1701 | + $sql .= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1702 | 1702 | } |
1703 | 1703 | } else { |
1704 | - $sql .= ' AND te.entity IN (' . getEntity($this->element) . ')'; |
|
1704 | + $sql .= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1705 | 1705 | } |
1706 | 1706 | } |
1707 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = ' . $socid; |
|
1708 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = ' . $socid . ' OR te.fk_soc IS NULL)'; |
|
1709 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = ' . $socid; |
|
1707 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid; |
|
1708 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)'; |
|
1709 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid; |
|
1710 | 1710 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
1711 | 1711 | |
1712 | 1712 | $result = $this->db->query($sql); |
@@ -1718,39 +1718,39 @@ discard block |
||
1718 | 1718 | $this->ref_previous = $row[0]; |
1719 | 1719 | |
1720 | 1720 | |
1721 | - $sql = "SELECT MIN(te." . $fieldid . ")"; |
|
1722 | - $sql .= " FROM " . (empty($nodbprefix) ? MAIN_DB_PREFIX : '') . $this->table_element . " as te"; |
|
1721 | + $sql = "SELECT MIN(te.".$fieldid.")"; |
|
1722 | + $sql .= " FROM ".(empty($nodbprefix) ? MAIN_DB_PREFIX : '').$this->table_element." as te"; |
|
1723 | 1723 | if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
1724 | - $sql .= "," . MAIN_DB_PREFIX . "usergroup_user as ug"; |
|
1725 | - } |
|
1726 | - 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 |
|
1727 | - 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 |
|
1728 | - 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 |
|
1729 | - 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"; |
|
1730 | - $sql .= " WHERE te." . $fieldid . " > '" . $this->db->escape($this->ref) . "'"; // ->ref must always be defined (set to id if field does not exists) |
|
1731 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = " . $user->id; |
|
1732 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = " . $user->id . ' OR te.fk_soc IS NULL)'; |
|
1724 | + $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1725 | + } |
|
1726 | + 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 |
|
1727 | + 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 |
|
1728 | + 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 |
|
1729 | + 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"; |
|
1730 | + $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1731 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id; |
|
1732 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)'; |
|
1733 | 1733 | if (!empty($filter)) { |
1734 | - if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
1734 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
1735 | 1735 | $sql .= $filter; |
1736 | 1736 | } |
1737 | - 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 |
|
1738 | - 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 |
|
1737 | + 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 |
|
1738 | + 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 |
|
1739 | 1739 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
1740 | 1740 | if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
1741 | 1741 | if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
1742 | 1742 | $sql .= " AND te.entity IS NOT NULL"; // Show all users |
1743 | 1743 | } else { |
1744 | 1744 | $sql .= " AND ug.fk_user = te.rowid"; |
1745 | - $sql .= " AND ug.entity IN (" . getEntity($this->element) . ")"; |
|
1745 | + $sql .= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1746 | 1746 | } |
1747 | 1747 | } else { |
1748 | - $sql .= ' AND te.entity IN (' . getEntity($this->element) . ')'; |
|
1748 | + $sql .= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1749 | 1749 | } |
1750 | 1750 | } |
1751 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = ' . $socid; |
|
1752 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = ' . $socid . ' OR te.fk_soc IS NULL)'; |
|
1753 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = ' . $socid; |
|
1751 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid; |
|
1752 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)'; |
|
1753 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid; |
|
1754 | 1754 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
1755 | 1755 | // 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 |
1756 | 1756 | |
@@ -1800,22 +1800,22 @@ discard block |
||
1800 | 1800 | function setProject($projectid) |
1801 | 1801 | { |
1802 | 1802 | if (!$this->table_element) { |
1803 | - dol_syslog(get_class($this) . "::setProject was called on objet with property table_element not defined", LOG_ERR); |
|
1803 | + dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined", LOG_ERR); |
|
1804 | 1804 | return -1; |
1805 | 1805 | } |
1806 | 1806 | |
1807 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element; |
|
1807 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1808 | 1808 | if ($this->table_element == 'actioncomm') { |
1809 | - if ($projectid) $sql .= ' SET fk_project = ' . $projectid; |
|
1809 | + if ($projectid) $sql .= ' SET fk_project = '.$projectid; |
|
1810 | 1810 | else $sql .= ' SET fk_project = NULL'; |
1811 | - $sql .= ' WHERE id = ' . $this->id; |
|
1811 | + $sql .= ' WHERE id = '.$this->id; |
|
1812 | 1812 | } else { |
1813 | - if ($projectid) $sql .= ' SET fk_projet = ' . $projectid; |
|
1813 | + if ($projectid) $sql .= ' SET fk_projet = '.$projectid; |
|
1814 | 1814 | else $sql .= ' SET fk_projet = NULL'; |
1815 | - $sql .= ' WHERE rowid = ' . $this->id; |
|
1815 | + $sql .= ' WHERE rowid = '.$this->id; |
|
1816 | 1816 | } |
1817 | 1817 | |
1818 | - dol_syslog(get_class($this) . "::setProject", LOG_DEBUG); |
|
1818 | + dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
|
1819 | 1819 | if ($this->db->query($sql)) { |
1820 | 1820 | $this->fk_project = $projectid; |
1821 | 1821 | return 1; |
@@ -1835,16 +1835,16 @@ discard block |
||
1835 | 1835 | */ |
1836 | 1836 | function setPaymentMethods($id) |
1837 | 1837 | { |
1838 | - dol_syslog(get_class($this) . '::setPaymentMethods(' . $id . ')'); |
|
1838 | + dol_syslog(get_class($this).'::setPaymentMethods('.$id.')'); |
|
1839 | 1839 | if ($this->statut >= 0 || $this->element == 'societe') { |
1840 | 1840 | // TODO uniformize field name |
1841 | 1841 | $fieldname = 'fk_mode_reglement'; |
1842 | 1842 | if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
1843 | 1843 | if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
1844 | 1844 | |
1845 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element; |
|
1846 | - $sql .= ' SET ' . $fieldname . ' = ' . $id; |
|
1847 | - $sql .= ' WHERE rowid=' . $this->id; |
|
1845 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1846 | + $sql .= ' SET '.$fieldname.' = '.$id; |
|
1847 | + $sql .= ' WHERE rowid='.$this->id; |
|
1848 | 1848 | |
1849 | 1849 | if ($this->db->query($sql)) { |
1850 | 1850 | $this->mode_reglement_id = $id; |
@@ -1852,13 +1852,13 @@ discard block |
||
1852 | 1852 | if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
1853 | 1853 | return 1; |
1854 | 1854 | } else { |
1855 | - dol_syslog(get_class($this) . '::setPaymentMethods Erreur ' . $sql . ' - ' . $this->db->error()); |
|
1855 | + dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
|
1856 | 1856 | $this->error = $this->db->error(); |
1857 | 1857 | return -1; |
1858 | 1858 | } |
1859 | 1859 | } else { |
1860 | - dol_syslog(get_class($this) . '::setPaymentMethods, status of the object is incompatible'); |
|
1861 | - $this->error = 'Status of the object is incompatible ' . $this->statut; |
|
1860 | + dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
|
1861 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
1862 | 1862 | return -2; |
1863 | 1863 | } |
1864 | 1864 | } |
@@ -1873,13 +1873,13 @@ discard block |
||
1873 | 1873 | */ |
1874 | 1874 | function setMulticurrencyCode($code) |
1875 | 1875 | { |
1876 | - dol_syslog(get_class($this) . '::setMulticurrencyCode(' . $id . ')'); |
|
1876 | + dol_syslog(get_class($this).'::setMulticurrencyCode('.$id.')'); |
|
1877 | 1877 | if ($this->statut >= 0 || $this->element == 'societe') { |
1878 | 1878 | $fieldname = 'multicurrency_code'; |
1879 | 1879 | |
1880 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element; |
|
1881 | - $sql .= ' SET ' . $fieldname . " = '" . $this->db->escape($code) . "'"; |
|
1882 | - $sql .= ' WHERE rowid=' . $this->id; |
|
1880 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1881 | + $sql .= ' SET '.$fieldname." = '".$this->db->escape($code)."'"; |
|
1882 | + $sql .= ' WHERE rowid='.$this->id; |
|
1883 | 1883 | |
1884 | 1884 | if ($this->db->query($sql)) { |
1885 | 1885 | $this->multicurrency_code = $code; |
@@ -1889,13 +1889,13 @@ discard block |
||
1889 | 1889 | |
1890 | 1890 | return 1; |
1891 | 1891 | } else { |
1892 | - dol_syslog(get_class($this) . '::setMulticurrencyCode Erreur ' . $sql . ' - ' . $this->db->error()); |
|
1892 | + dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
|
1893 | 1893 | $this->error = $this->db->error(); |
1894 | 1894 | return -1; |
1895 | 1895 | } |
1896 | 1896 | } else { |
1897 | - dol_syslog(get_class($this) . '::setMulticurrencyCode, status of the object is incompatible'); |
|
1898 | - $this->error = 'Status of the object is incompatible ' . $this->statut; |
|
1897 | + dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
|
1898 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
1899 | 1899 | return -2; |
1900 | 1900 | } |
1901 | 1901 | } |
@@ -1909,13 +1909,13 @@ discard block |
||
1909 | 1909 | */ |
1910 | 1910 | function setMulticurrencyRate($rate, $mode = 1) |
1911 | 1911 | { |
1912 | - dol_syslog(get_class($this) . '::setMulticurrencyRate(' . $id . ')'); |
|
1912 | + dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')'); |
|
1913 | 1913 | if ($this->statut >= 0 || $this->element == 'societe') { |
1914 | 1914 | $fieldname = 'multicurrency_tx'; |
1915 | 1915 | |
1916 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element; |
|
1917 | - $sql .= ' SET ' . $fieldname . ' = ' . $rate; |
|
1918 | - $sql .= ' WHERE rowid=' . $this->id; |
|
1916 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1917 | + $sql .= ' SET '.$fieldname.' = '.$rate; |
|
1918 | + $sql .= ' WHERE rowid='.$this->id; |
|
1919 | 1919 | |
1920 | 1920 | if ($this->db->query($sql)) { |
1921 | 1921 | $this->multicurrency_tx = $rate; |
@@ -1975,7 +1975,7 @@ discard block |
||
1975 | 1975 | ); |
1976 | 1976 | break; |
1977 | 1977 | default: |
1978 | - dol_syslog(get_class($this) . '::setMulticurrencyRate no updateline defined', LOG_DEBUG); |
|
1978 | + dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); |
|
1979 | 1979 | break; |
1980 | 1980 | } |
1981 | 1981 | } |
@@ -1983,13 +1983,13 @@ discard block |
||
1983 | 1983 | |
1984 | 1984 | return 1; |
1985 | 1985 | } else { |
1986 | - dol_syslog(get_class($this) . '::setMulticurrencyRate Erreur ' . $sql . ' - ' . $this->db->error()); |
|
1986 | + dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
|
1987 | 1987 | $this->error = $this->db->error(); |
1988 | 1988 | return -1; |
1989 | 1989 | } |
1990 | 1990 | } else { |
1991 | - dol_syslog(get_class($this) . '::setMulticurrencyRate, status of the object is incompatible'); |
|
1992 | - $this->error = 'Status of the object is incompatible ' . $this->statut; |
|
1991 | + dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
|
1992 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
1993 | 1993 | return -2; |
1994 | 1994 | } |
1995 | 1995 | } |
@@ -2004,31 +2004,31 @@ discard block |
||
2004 | 2004 | */ |
2005 | 2005 | function setPaymentTerms($id) |
2006 | 2006 | { |
2007 | - dol_syslog(get_class($this) . '::setPaymentTerms(' . $id . ')'); |
|
2007 | + dol_syslog(get_class($this).'::setPaymentTerms('.$id.')'); |
|
2008 | 2008 | if ($this->statut >= 0 || $this->element == 'societe') { |
2009 | 2009 | // TODO uniformize field name |
2010 | 2010 | $fieldname = 'fk_cond_reglement'; |
2011 | 2011 | if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
2012 | 2012 | if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
2013 | 2013 | |
2014 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element; |
|
2015 | - $sql .= ' SET ' . $fieldname . ' = ' . $id; |
|
2016 | - $sql .= ' WHERE rowid=' . $this->id; |
|
2014 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
2015 | + $sql .= ' SET '.$fieldname.' = '.$id; |
|
2016 | + $sql .= ' WHERE rowid='.$this->id; |
|
2017 | 2017 | |
2018 | 2018 | if ($this->db->query($sql)) { |
2019 | 2019 | $this->cond_reglement_id = $id; |
2020 | 2020 | // for supplier |
2021 | 2021 | if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
2022 | - $this->cond_reglement = $id; // for compatibility |
|
2022 | + $this->cond_reglement = $id; // for compatibility |
|
2023 | 2023 | return 1; |
2024 | 2024 | } else { |
2025 | - dol_syslog(get_class($this) . '::setPaymentTerms Erreur ' . $sql . ' - ' . $this->db->error()); |
|
2025 | + dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
|
2026 | 2026 | $this->error = $this->db->error(); |
2027 | 2027 | return -1; |
2028 | 2028 | } |
2029 | 2029 | } else { |
2030 | - dol_syslog(get_class($this) . '::setPaymentTerms, status of the object is incompatible'); |
|
2031 | - $this->error = 'Status of the object is incompatible ' . $this->statut; |
|
2030 | + dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
|
2031 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
2032 | 2032 | return -2; |
2033 | 2033 | } |
2034 | 2034 | } |
@@ -2045,15 +2045,15 @@ discard block |
||
2045 | 2045 | $fieldname = 'fk_delivery_address'; |
2046 | 2046 | if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
2047 | 2047 | |
2048 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element . " SET " . $fieldname . " = " . $id; |
|
2049 | - $sql .= " WHERE rowid = " . $this->id . " AND fk_statut = 0"; |
|
2048 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
|
2049 | + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
2050 | 2050 | |
2051 | 2051 | if ($this->db->query($sql)) { |
2052 | 2052 | $this->fk_delivery_address = $id; |
2053 | 2053 | return 1; |
2054 | 2054 | } else { |
2055 | 2055 | $this->error = $this->db->error(); |
2056 | - dol_syslog(get_class($this) . '::setDeliveryAddress Erreur ' . $sql . ' - ' . $this->error); |
|
2056 | + dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
|
2057 | 2057 | return -1; |
2058 | 2058 | } |
2059 | 2059 | } |
@@ -2076,28 +2076,28 @@ discard block |
||
2076 | 2076 | $error = 0; |
2077 | 2077 | |
2078 | 2078 | if (!$this->table_element) { |
2079 | - dol_syslog(get_class($this) . "::setShippingMethod was called on objet with property table_element not defined", LOG_ERR); |
|
2079 | + dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined", LOG_ERR); |
|
2080 | 2080 | return -1; |
2081 | 2081 | } |
2082 | 2082 | |
2083 | 2083 | $this->db->begin(); |
2084 | 2084 | |
2085 | 2085 | if ($shipping_method_id < 0) $shipping_method_id = 'NULL'; |
2086 | - dol_syslog(get_class($this) . '::setShippingMethod(' . $shipping_method_id . ')'); |
|
2086 | + dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); |
|
2087 | 2087 | |
2088 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element; |
|
2089 | - $sql .= " SET fk_shipping_method = " . $shipping_method_id; |
|
2090 | - $sql .= " WHERE rowid=" . $this->id; |
|
2088 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2089 | + $sql .= " SET fk_shipping_method = ".$shipping_method_id; |
|
2090 | + $sql .= " WHERE rowid=".$this->id; |
|
2091 | 2091 | $resql = $this->db->query($sql); |
2092 | 2092 | if (!$resql) { |
2093 | - dol_syslog(get_class($this) . '::setShippingMethod Error ', LOG_DEBUG); |
|
2093 | + dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
|
2094 | 2094 | $this->error = $this->db->lasterror(); |
2095 | 2095 | $error++; |
2096 | 2096 | } else { |
2097 | 2097 | if (!$notrigger) { |
2098 | 2098 | // Call trigger |
2099 | 2099 | $this->context = array('shippingmethodupdate' => 1); |
2100 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
2100 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
2101 | 2101 | if ($result < 0) $error++; |
2102 | 2102 | // End call trigger |
2103 | 2103 | } |
@@ -2121,21 +2121,21 @@ discard block |
||
2121 | 2121 | function setWarehouse($warehouse_id) |
2122 | 2122 | { |
2123 | 2123 | if (!$this->table_element) { |
2124 | - dol_syslog(get_class($this) . "::setWarehouse was called on objet with property table_element not defined", LOG_ERR); |
|
2124 | + dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined", LOG_ERR); |
|
2125 | 2125 | return -1; |
2126 | 2126 | } |
2127 | 2127 | if ($warehouse_id < 0) $warehouse_id = 'NULL'; |
2128 | - dol_syslog(get_class($this) . '::setWarehouse(' . $warehouse_id . ')'); |
|
2128 | + dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); |
|
2129 | 2129 | |
2130 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element; |
|
2131 | - $sql .= " SET fk_warehouse = " . $warehouse_id; |
|
2132 | - $sql .= " WHERE rowid=" . $this->id; |
|
2130 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2131 | + $sql .= " SET fk_warehouse = ".$warehouse_id; |
|
2132 | + $sql .= " WHERE rowid=".$this->id; |
|
2133 | 2133 | |
2134 | 2134 | if ($this->db->query($sql)) { |
2135 | 2135 | $this->warehouse_id = ($warehouse_id == 'NULL') ? null : $warehouse_id; |
2136 | 2136 | return 1; |
2137 | 2137 | } else { |
2138 | - dol_syslog(get_class($this) . '::setWarehouse Error ', LOG_DEBUG); |
|
2138 | + dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
|
2139 | 2139 | $this->error = $this->db->error(); |
2140 | 2140 | return 0; |
2141 | 2141 | } |
@@ -2151,19 +2151,19 @@ discard block |
||
2151 | 2151 | function setDocModel($user, $modelpdf) |
2152 | 2152 | { |
2153 | 2153 | if (!$this->table_element) { |
2154 | - dol_syslog(get_class($this) . "::setDocModel was called on objet with property table_element not defined", LOG_ERR); |
|
2154 | + dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined", LOG_ERR); |
|
2155 | 2155 | return -1; |
2156 | 2156 | } |
2157 | 2157 | |
2158 | 2158 | $newmodelpdf = dol_trunc($modelpdf, 255); |
2159 | 2159 | |
2160 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element; |
|
2161 | - $sql .= " SET model_pdf = '" . $this->db->escape($newmodelpdf) . "'"; |
|
2162 | - $sql .= " WHERE rowid = " . $this->id; |
|
2160 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2161 | + $sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
2162 | + $sql .= " WHERE rowid = ".$this->id; |
|
2163 | 2163 | // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
2164 | 2164 | // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
2165 | 2165 | |
2166 | - dol_syslog(get_class($this) . "::setDocModel", LOG_DEBUG); |
|
2166 | + dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
|
2167 | 2167 | $resql = $this->db->query($sql); |
2168 | 2168 | if ($resql) { |
2169 | 2169 | $this->modelpdf = $modelpdf; |
@@ -2193,28 +2193,28 @@ discard block |
||
2193 | 2193 | $error = 0; |
2194 | 2194 | |
2195 | 2195 | if (!$this->table_element) { |
2196 | - dol_syslog(get_class($this) . "::setBankAccount was called on objet with property table_element not defined", LOG_ERR); |
|
2196 | + dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined", LOG_ERR); |
|
2197 | 2197 | return -1; |
2198 | 2198 | } |
2199 | 2199 | $this->db->begin(); |
2200 | 2200 | |
2201 | 2201 | if ($fk_account < 0) $fk_account = 'NULL'; |
2202 | - dol_syslog(get_class($this) . '::setBankAccount(' . $fk_account . ')'); |
|
2202 | + dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); |
|
2203 | 2203 | |
2204 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element; |
|
2205 | - $sql .= " SET fk_account = " . $fk_account; |
|
2206 | - $sql .= " WHERE rowid=" . $this->id; |
|
2204 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2205 | + $sql .= " SET fk_account = ".$fk_account; |
|
2206 | + $sql .= " WHERE rowid=".$this->id; |
|
2207 | 2207 | |
2208 | 2208 | $resql = $this->db->query($sql); |
2209 | 2209 | if (!$resql) { |
2210 | - dol_syslog(get_class($this) . '::setBankAccount Error ' . $sql . ' - ' . $this->db->error()); |
|
2210 | + dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
|
2211 | 2211 | $this->error = $this->db->lasterror(); |
2212 | 2212 | $error++; |
2213 | 2213 | } else { |
2214 | 2214 | if (!$notrigger) { |
2215 | 2215 | // Call trigger |
2216 | 2216 | $this->context = array('bankaccountupdate' => 1); |
2217 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
2217 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
2218 | 2218 | if ($result < 0) $error++; |
2219 | 2219 | // End call trigger |
2220 | 2220 | } |
@@ -2265,22 +2265,22 @@ discard block |
||
2265 | 2265 | { |
2266 | 2266 | // phpcs:enable |
2267 | 2267 | if (!$this->table_element_line) { |
2268 | - dol_syslog(get_class($this) . "::line_order was called on objet with property table_element_line not defined", LOG_ERR); |
|
2268 | + dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined", LOG_ERR); |
|
2269 | 2269 | return -1; |
2270 | 2270 | } |
2271 | 2271 | if (!$this->fk_element) { |
2272 | - dol_syslog(get_class($this) . "::line_order was called on objet with property fk_element not defined", LOG_ERR); |
|
2272 | + dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined", LOG_ERR); |
|
2273 | 2273 | return -1; |
2274 | 2274 | } |
2275 | 2275 | |
2276 | 2276 | // Count number of lines to reorder (according to choice $renum) |
2277 | 2277 | $nl = 0; |
2278 | - $sql = 'SELECT count(rowid) FROM ' . MAIN_DB_PREFIX . $this->table_element_line; |
|
2279 | - $sql .= ' WHERE ' . $this->fk_element . '=' . $this->id; |
|
2278 | + $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2279 | + $sql .= ' WHERE '.$this->fk_element.'='.$this->id; |
|
2280 | 2280 | if (!$renum) $sql .= ' AND rang = 0'; |
2281 | 2281 | if ($renum) $sql .= ' AND rang <> 0'; |
2282 | 2282 | |
2283 | - dol_syslog(get_class($this) . "::line_order", LOG_DEBUG); |
|
2283 | + dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
|
2284 | 2284 | $resql = $this->db->query($sql); |
2285 | 2285 | if ($resql) { |
2286 | 2286 | $row = $this->db->fetch_row($resql); |
@@ -2292,19 +2292,19 @@ discard block |
||
2292 | 2292 | $rows = array(); |
2293 | 2293 | |
2294 | 2294 | // We first search all lines that are parent lines (for multilevel details lines) |
2295 | - $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . $this->table_element_line; |
|
2296 | - $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id; |
|
2295 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2296 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2297 | 2297 | if ($fk_parent_line) $sql .= ' AND fk_parent_line IS NULL'; |
2298 | - $sql .= ' ORDER BY rang ASC, rowid ' . $rowidorder; |
|
2298 | + $sql .= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
2299 | 2299 | |
2300 | - dol_syslog(get_class($this) . "::line_order search all parent lines", LOG_DEBUG); |
|
2300 | + dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
|
2301 | 2301 | $resql = $this->db->query($sql); |
2302 | 2302 | if ($resql) { |
2303 | 2303 | $i = 0; |
2304 | 2304 | $num = $this->db->num_rows($resql); |
2305 | 2305 | while ($i < $num) { |
2306 | 2306 | $row = $this->db->fetch_row($resql); |
2307 | - $rows[] = $row[0]; // Add parent line into array rows |
|
2307 | + $rows[] = $row[0]; // Add parent line into array rows |
|
2308 | 2308 | $childrens = $this->getChildrenOfLine($row[0]); |
2309 | 2309 | if (!empty($childrens)) { |
2310 | 2310 | foreach ($childrens as $child) { |
@@ -2339,12 +2339,12 @@ discard block |
||
2339 | 2339 | { |
2340 | 2340 | $rows = array(); |
2341 | 2341 | |
2342 | - $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . $this->table_element_line; |
|
2343 | - $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id; |
|
2344 | - $sql .= ' AND fk_parent_line = ' . $id; |
|
2342 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2343 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2344 | + $sql .= ' AND fk_parent_line = '.$id; |
|
2345 | 2345 | $sql .= ' ORDER BY rang ASC'; |
2346 | 2346 | |
2347 | - dol_syslog(get_class($this) . "::getChildrenOfLine search children lines for line " . $id . "", LOG_DEBUG); |
|
2347 | + dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
|
2348 | 2348 | $resql = $this->db->query($sql); |
2349 | 2349 | if ($resql) { |
2350 | 2350 | $i = 0; |
@@ -2373,10 +2373,10 @@ discard block |
||
2373 | 2373 | $fieldposition = 'rang'; |
2374 | 2374 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
2375 | 2375 | |
2376 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element_line . ' SET ' . $fieldposition . ' = ' . $rang; |
|
2377 | - $sql .= ' WHERE rowid = ' . $rowid; |
|
2376 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
2377 | + $sql .= ' WHERE rowid = '.$rowid; |
|
2378 | 2378 | |
2379 | - dol_syslog(get_class($this) . "::updateRangOfLine", LOG_DEBUG); |
|
2379 | + dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
|
2380 | 2380 | if (!$this->db->query($sql)) { |
2381 | 2381 | dol_print_error($this->db); |
2382 | 2382 | } |
@@ -2392,10 +2392,10 @@ discard block |
||
2392 | 2392 | */ |
2393 | 2393 | function getRangOfLine($rowid) |
2394 | 2394 | { |
2395 | - $sql = 'SELECT rang FROM ' . MAIN_DB_PREFIX . $this->table_element_line; |
|
2396 | - $sql .= ' WHERE rowid =' . $rowid; |
|
2395 | + $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2396 | + $sql .= ' WHERE rowid ='.$rowid; |
|
2397 | 2397 | |
2398 | - dol_syslog(get_class($this) . "::getRangOfLine", LOG_DEBUG); |
|
2398 | + dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
|
2399 | 2399 | $resql = $this->db->query($sql); |
2400 | 2400 | if ($resql) { |
2401 | 2401 | $row = $this->db->fetch_row($resql); |
@@ -2416,12 +2416,12 @@ discard block |
||
2416 | 2416 | $fieldposition = 'rang'; |
2417 | 2417 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
2418 | 2418 | |
2419 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element_line . ' SET ' . $fieldposition . ' = ' . $rang; |
|
2420 | - $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id; |
|
2421 | - $sql .= ' AND rang = ' . ($rang - 1); |
|
2419 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
2420 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2421 | + $sql .= ' AND rang = '.($rang - 1); |
|
2422 | 2422 | if ($this->db->query($sql)) { |
2423 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element_line . ' SET ' . $fieldposition . ' = ' . ($rang - 1); |
|
2424 | - $sql .= ' WHERE rowid = ' . $rowid; |
|
2423 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
|
2424 | + $sql .= ' WHERE rowid = '.$rowid; |
|
2425 | 2425 | if (!$this->db->query($sql)) { |
2426 | 2426 | dol_print_error($this->db); |
2427 | 2427 | } |
@@ -2464,11 +2464,11 @@ discard block |
||
2464 | 2464 | // phpcs:enable |
2465 | 2465 | // Search the last rang with fk_parent_line |
2466 | 2466 | if ($fk_parent_line) { |
2467 | - $sql = 'SELECT max(rang) FROM ' . MAIN_DB_PREFIX . $this->table_element_line; |
|
2468 | - $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id; |
|
2469 | - $sql .= ' AND fk_parent_line = ' . $fk_parent_line; |
|
2467 | + $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2468 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2469 | + $sql .= ' AND fk_parent_line = '.$fk_parent_line; |
|
2470 | 2470 | |
2471 | - dol_syslog(get_class($this) . "::line_max", LOG_DEBUG); |
|
2471 | + dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
2472 | 2472 | $resql = $this->db->query($sql); |
2473 | 2473 | if ($resql) { |
2474 | 2474 | $row = $this->db->fetch_row($resql); |
@@ -2480,10 +2480,10 @@ discard block |
||
2480 | 2480 | } |
2481 | 2481 | } // If not, search the last rang of element |
2482 | 2482 | else { |
2483 | - $sql = 'SELECT max(rang) FROM ' . MAIN_DB_PREFIX . $this->table_element_line; |
|
2484 | - $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id; |
|
2483 | + $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2484 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2485 | 2485 | |
2486 | - dol_syslog(get_class($this) . "::line_max", LOG_DEBUG); |
|
2486 | + dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
2487 | 2487 | $resql = $this->db->query($sql); |
2488 | 2488 | if ($resql) { |
2489 | 2489 | $row = $this->db->fetch_row($resql); |
@@ -2506,12 +2506,12 @@ discard block |
||
2506 | 2506 | $fieldposition = 'rang'; |
2507 | 2507 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
2508 | 2508 | |
2509 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element_line . ' SET ' . $fieldposition . ' = ' . $rang; |
|
2510 | - $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id; |
|
2511 | - $sql .= ' AND rang = ' . ($rang + 1); |
|
2509 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
2510 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2511 | + $sql .= ' AND rang = '.($rang + 1); |
|
2512 | 2512 | if ($this->db->query($sql)) { |
2513 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element_line . ' SET ' . $fieldposition . ' = ' . ($rang + 1); |
|
2514 | - $sql .= ' WHERE rowid = ' . $rowid; |
|
2513 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang + 1); |
|
2514 | + $sql .= ' WHERE rowid = '.$rowid; |
|
2515 | 2515 | if (!$this->db->query($sql)) { |
2516 | 2516 | dol_print_error($this->db); |
2517 | 2517 | } |
@@ -2544,9 +2544,9 @@ discard block |
||
2544 | 2544 | */ |
2545 | 2545 | function getIdOfLine($rang) |
2546 | 2546 | { |
2547 | - $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . $this->table_element_line; |
|
2548 | - $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id; |
|
2549 | - $sql .= ' AND rang = ' . $rang; |
|
2547 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2548 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2549 | + $sql .= ' AND rang = '.$rang; |
|
2550 | 2550 | $resql = $this->db->query($sql); |
2551 | 2551 | if ($resql) { |
2552 | 2552 | $row = $this->db->fetch_row($resql); |
@@ -2564,15 +2564,15 @@ discard block |
||
2564 | 2564 | { |
2565 | 2565 | // phpcs:enable |
2566 | 2566 | if (!$this->table_element) { |
2567 | - dol_syslog(get_class($this) . "::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
|
2567 | + dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
|
2568 | 2568 | return -1; |
2569 | 2569 | } |
2570 | 2570 | |
2571 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element; |
|
2572 | - $sql .= " SET ref_ext = '" . $this->db->escape($ref_ext) . "'"; |
|
2573 | - $sql .= " WHERE " . (isset($this->table_rowid) ? $this->table_rowid : 'rowid') . " = " . $this->id; |
|
2571 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
2572 | + $sql .= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
2573 | + $sql .= " WHERE ".(isset($this->table_rowid) ? $this->table_rowid : 'rowid')." = ".$this->id; |
|
2574 | 2574 | |
2575 | - dol_syslog(get_class($this) . "::update_ref_ext", LOG_DEBUG); |
|
2575 | + dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
|
2576 | 2576 | if ($this->db->query($sql)) { |
2577 | 2577 | $this->ref_ext = $ref_ext; |
2578 | 2578 | return 1; |
@@ -2610,29 +2610,29 @@ discard block |
||
2610 | 2610 | |
2611 | 2611 | if (!$this->table_element) { |
2612 | 2612 | $this->error = 'update_note was called on objet with property table_element not defined'; |
2613 | - dol_syslog(get_class($this) . "::update_note was called on objet with property table_element not defined", LOG_ERR); |
|
2613 | + dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
|
2614 | 2614 | return -1; |
2615 | 2615 | } |
2616 | 2616 | if (!in_array($suffix, array('', '_public', '_private'))) { |
2617 | 2617 | $this->error = 'update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
2618 | - dol_syslog(get_class($this) . "::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
|
2618 | + dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
|
2619 | 2619 | return -2; |
2620 | 2620 | } |
2621 | 2621 | // Special cas |
2622 | 2622 | //var_dump($this->table_element);exit; |
2623 | 2623 | if ($this->table_element == 'product') $suffix = ''; |
2624 | 2624 | |
2625 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element; |
|
2626 | - $sql .= " SET note" . $suffix . " = " . (!empty($note) ? ("'" . $this->db->escape($note) . "'") : "NULL"); |
|
2627 | - $sql .= " ," . (in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment')) ? "fk_user_mod" : "fk_user_modif") . " = " . $user->id; |
|
2628 | - $sql .= " WHERE rowid =" . $this->id; |
|
2625 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
2626 | + $sql .= " SET note".$suffix." = ".(!empty($note) ? ("'".$this->db->escape($note)."'") : "NULL"); |
|
2627 | + $sql .= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment')) ? "fk_user_mod" : "fk_user_modif")." = ".$user->id; |
|
2628 | + $sql .= " WHERE rowid =".$this->id; |
|
2629 | 2629 | |
2630 | - dol_syslog(get_class($this) . "::update_note", LOG_DEBUG); |
|
2630 | + dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
|
2631 | 2631 | if ($this->db->query($sql)) { |
2632 | 2632 | if ($suffix == '_public') $this->note_public = $note; |
2633 | 2633 | else if ($suffix == '_private') $this->note_private = $note; |
2634 | 2634 | else { |
2635 | - $this->note = $note; // deprecated |
|
2635 | + $this->note = $note; // deprecated |
|
2636 | 2636 | $this->note_private = $note; |
2637 | 2637 | } |
2638 | 2638 | return 1; |
@@ -2682,9 +2682,9 @@ discard block |
||
2682 | 2682 | } |
2683 | 2683 | } |
2684 | 2684 | |
2685 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php'; |
|
2685 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
|
2686 | 2686 | |
2687 | - if ($roundingadjust == '-1') $roundingadjust = 'auto'; // For backward compatibility |
|
2687 | + if ($roundingadjust == '-1') $roundingadjust = 'auto'; // For backward compatibility |
|
2688 | 2688 | |
2689 | 2689 | $forcedroundingmode = $roundingadjust; |
2690 | 2690 | if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode = $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
@@ -2707,20 +2707,20 @@ discard block |
||
2707 | 2707 | $fieldup = 'value_unit'; |
2708 | 2708 | } |
2709 | 2709 | |
2710 | - $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,'; |
|
2710 | + $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,'; |
|
2711 | 2711 | $sql .= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
2712 | 2712 | if ($this->table_element_line == 'facturedet') $sql .= ', situation_percent'; |
2713 | 2713 | $sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
2714 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element_line; |
|
2715 | - $sql .= ' WHERE ' . $this->fk_element . ' = ' . $this->id; |
|
2714 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2715 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2716 | 2716 | if ($exclspec) { |
2717 | 2717 | $product_field = 'product_type'; |
2718 | - if ($this->table_element_line == 'contratdet') $product_field = ''; // contratdet table has no product_type field |
|
2719 | - if ($product_field) $sql .= ' AND ' . $product_field . ' <> 9'; |
|
2718 | + if ($this->table_element_line == 'contratdet') $product_field = ''; // contratdet table has no product_type field |
|
2719 | + if ($product_field) $sql .= ' AND '.$product_field.' <> 9'; |
|
2720 | 2720 | } |
2721 | - $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 |
|
2721 | + $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 |
|
2722 | 2722 | |
2723 | - dol_syslog(get_class($this) . "::update_price", LOG_DEBUG); |
|
2723 | + dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
2724 | 2724 | $resql = $this->db->query($sql); |
2725 | 2725 | if ($resql) { |
2726 | 2726 | $this->total_ht = 0; |
@@ -2750,8 +2750,8 @@ discard block |
||
2750 | 2750 | $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); |
2751 | 2751 | $diff = price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
2752 | 2752 | if ($diff) { |
2753 | - $sqlfix = "UPDATE " . MAIN_DB_PREFIX . $this->table_element_line . " SET " . $fieldtva . " = " . $tmpcal[1] . ", total_ttc = " . $tmpcal[2] . " WHERE rowid = " . $obj->rowid; |
|
2754 | - 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); |
|
2753 | + $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
2754 | + 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); |
|
2755 | 2755 | $resqlfix = $this->db->query($sqlfix); |
2756 | 2756 | if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
2757 | 2757 | $obj->total_tva = $tmpcal[1]; |
@@ -2760,12 +2760,12 @@ discard block |
||
2760 | 2760 | } |
2761 | 2761 | } |
2762 | 2762 | |
2763 | - $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
2763 | + $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
2764 | 2764 | $this->total_tva += $obj->total_tva; |
2765 | 2765 | $this->total_localtax1 += $obj->total_localtax1; |
2766 | 2766 | $this->total_localtax2 += $obj->total_localtax2; |
2767 | 2767 | $this->total_ttc += $obj->total_ttc; |
2768 | - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
2768 | + $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
2769 | 2769 | $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
2770 | 2770 | $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
2771 | 2771 | |
@@ -2786,8 +2786,8 @@ discard block |
||
2786 | 2786 | dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); |
2787 | 2787 | exit; |
2788 | 2788 | } |
2789 | - $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; |
|
2790 | - 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); |
|
2789 | + $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; |
|
2790 | + 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); |
|
2791 | 2791 | $resqlfix = $this->db->query($sqlfix); |
2792 | 2792 | if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
2793 | 2793 | $this->total_tva -= $diff; |
@@ -2836,19 +2836,19 @@ discard block |
||
2836 | 2836 | if ($this->element == 'supplier_proposal') $fieldttc = 'total'; |
2837 | 2837 | |
2838 | 2838 | if (empty($nodatabaseupdate)) { |
2839 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; |
|
2840 | - $sql .= " " . $fieldht . "='" . price2num($this->total_ht) . "',"; |
|
2841 | - $sql .= " " . $fieldtva . "='" . price2num($this->total_tva) . "',"; |
|
2842 | - $sql .= " " . $fieldlocaltax1 . "='" . price2num($this->total_localtax1) . "',"; |
|
2843 | - $sql .= " " . $fieldlocaltax2 . "='" . price2num($this->total_localtax2) . "',"; |
|
2844 | - $sql .= " " . $fieldttc . "='" . price2num($this->total_ttc) . "'"; |
|
2845 | - $sql .= ", multicurrency_total_ht='" . price2num($this->multicurrency_total_ht, 'MT', 1) . "'"; |
|
2846 | - $sql .= ", multicurrency_total_tva='" . price2num($this->multicurrency_total_tva, 'MT', 1) . "'"; |
|
2847 | - $sql .= ", multicurrency_total_ttc='" . price2num($this->multicurrency_total_ttc, 'MT', 1) . "'"; |
|
2848 | - $sql .= ' WHERE rowid = ' . $this->id; |
|
2849 | - |
|
2850 | - |
|
2851 | - dol_syslog(get_class($this) . "::update_price", LOG_DEBUG); |
|
2839 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
2840 | + $sql .= " ".$fieldht."='".price2num($this->total_ht)."',"; |
|
2841 | + $sql .= " ".$fieldtva."='".price2num($this->total_tva)."',"; |
|
2842 | + $sql .= " ".$fieldlocaltax1."='".price2num($this->total_localtax1)."',"; |
|
2843 | + $sql .= " ".$fieldlocaltax2."='".price2num($this->total_localtax2)."',"; |
|
2844 | + $sql .= " ".$fieldttc."='".price2num($this->total_ttc)."'"; |
|
2845 | + $sql .= ", multicurrency_total_ht='".price2num($this->multicurrency_total_ht, 'MT', 1)."'"; |
|
2846 | + $sql .= ", multicurrency_total_tva='".price2num($this->multicurrency_total_tva, 'MT', 1)."'"; |
|
2847 | + $sql .= ", multicurrency_total_ttc='".price2num($this->multicurrency_total_ttc, 'MT', 1)."'"; |
|
2848 | + $sql .= ' WHERE rowid = '.$this->id; |
|
2849 | + |
|
2850 | + |
|
2851 | + dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
2852 | 2852 | $resql = $this->db->query($sql); |
2853 | 2853 | if (!$resql) { |
2854 | 2854 | $error++; |
@@ -2889,19 +2889,19 @@ discard block |
||
2889 | 2889 | if ($origin == 'supplierorder') $origin = 'order_supplier'; |
2890 | 2890 | $this->db->begin(); |
2891 | 2891 | |
2892 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_element ("; |
|
2892 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; |
|
2893 | 2893 | $sql .= "fk_source"; |
2894 | 2894 | $sql .= ", sourcetype"; |
2895 | 2895 | $sql .= ", fk_target"; |
2896 | 2896 | $sql .= ", targettype"; |
2897 | 2897 | $sql .= ") VALUES ("; |
2898 | 2898 | $sql .= $origin_id; |
2899 | - $sql .= ", '" . $this->db->escape($origin) . "'"; |
|
2900 | - $sql .= ", " . $this->id; |
|
2901 | - $sql .= ", '" . $this->db->escape($this->element) . "'"; |
|
2899 | + $sql .= ", '".$this->db->escape($origin)."'"; |
|
2900 | + $sql .= ", ".$this->id; |
|
2901 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
2902 | 2902 | $sql .= ")"; |
2903 | 2903 | |
2904 | - dol_syslog(get_class($this) . "::add_object_linked", LOG_DEBUG); |
|
2904 | + dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
|
2905 | 2905 | if ($this->db->query($sql)) { |
2906 | 2906 | $this->db->commit(); |
2907 | 2907 | return 1; |
@@ -2950,11 +2950,11 @@ discard block |
||
2950 | 2950 | $withsourcetype = false; |
2951 | 2951 | |
2952 | 2952 | if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) { |
2953 | - $justsource = true; // the source (id and type) is a search criteria |
|
2953 | + $justsource = true; // the source (id and type) is a search criteria |
|
2954 | 2954 | if (!empty($targettype)) $withtargettype = true; |
2955 | 2955 | } |
2956 | 2956 | if (!empty($targetid) && !empty($targettype) && empty($sourceid)) { |
2957 | - $justtarget = true; // the target (id and type) is a search criteria |
|
2957 | + $justtarget = true; // the target (id and type) is a search criteria |
|
2958 | 2958 | if (!empty($sourcetype)) $withsourcetype = true; |
2959 | 2959 | } |
2960 | 2960 | |
@@ -2971,23 +2971,23 @@ discard block |
||
2971 | 2971 | |
2972 | 2972 | // Links between objects are stored in table element_element |
2973 | 2973 | $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
2974 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . 'element_element'; |
|
2974 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
2975 | 2975 | $sql .= " WHERE "; |
2976 | 2976 | if ($justsource || $justtarget) { |
2977 | 2977 | if ($justsource) { |
2978 | - $sql .= "fk_source = " . $sourceid . " AND sourcetype = '" . $sourcetype . "'"; |
|
2979 | - if ($withtargettype) $sql .= " AND targettype = '" . $targettype . "'"; |
|
2978 | + $sql .= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
2979 | + if ($withtargettype) $sql .= " AND targettype = '".$targettype."'"; |
|
2980 | 2980 | } else if ($justtarget) { |
2981 | - $sql .= "fk_target = " . $targetid . " AND targettype = '" . $targettype . "'"; |
|
2982 | - if ($withsourcetype) $sql .= " AND sourcetype = '" . $sourcetype . "'"; |
|
2981 | + $sql .= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
2982 | + if ($withsourcetype) $sql .= " AND sourcetype = '".$sourcetype."'"; |
|
2983 | 2983 | } |
2984 | 2984 | } else { |
2985 | - $sql .= "(fk_source = " . $sourceid . " AND sourcetype = '" . $sourcetype . "')"; |
|
2986 | - $sql .= " " . $clause . " (fk_target = " . $targetid . " AND targettype = '" . $targettype . "')"; |
|
2985 | + $sql .= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
2986 | + $sql .= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
2987 | 2987 | } |
2988 | - $sql .= ' ORDER BY ' . $orderby; |
|
2988 | + $sql .= ' ORDER BY '.$orderby; |
|
2989 | 2989 | |
2990 | - dol_syslog(get_class($this) . "::fetchObjectLink", LOG_DEBUG); |
|
2990 | + dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); |
|
2991 | 2991 | $resql = $this->db->query($sql); |
2992 | 2992 | if ($resql) { |
2993 | 2993 | $num = $this->db->num_rows($resql); |
@@ -3023,7 +3023,7 @@ discard block |
||
3023 | 3023 | $subelement = $regs[2]; |
3024 | 3024 | } |
3025 | 3025 | |
3026 | - $classpath = $element . '/class'; |
|
3026 | + $classpath = $element.'/class'; |
|
3027 | 3027 | // To work with non standard classpath or module name |
3028 | 3028 | if ($objecttype == 'facture') { |
3029 | 3029 | $classpath = 'compta/facture/class'; |
@@ -3081,7 +3081,7 @@ discard block |
||
3081 | 3081 | // Here $module, $classfile and $classname are set |
3082 | 3082 | if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) { |
3083 | 3083 | if ($loadalsoobjects) { |
3084 | - dol_include_once('/' . $classpath . '/' . $classfile . '.class.php'); |
|
3084 | + dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); |
|
3085 | 3085 | //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
3086 | 3086 | if (class_exists($classname)) { |
3087 | 3087 | foreach ($objectids as $i => $objectid) // $i is rowid into llx_element_element |
@@ -3124,20 +3124,20 @@ discard block |
||
3124 | 3124 | if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource = true; |
3125 | 3125 | else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $updatetarget = true; |
3126 | 3126 | |
3127 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "element_element SET "; |
|
3127 | + $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
|
3128 | 3128 | if ($updatesource) { |
3129 | - $sql .= "fk_source = " . $sourceid; |
|
3130 | - $sql .= ", sourcetype = '" . $this->db->escape($sourcetype) . "'"; |
|
3131 | - $sql .= " WHERE fk_target = " . $this->id; |
|
3132 | - $sql .= " AND targettype = '" . $this->db->escape($this->element) . "'"; |
|
3129 | + $sql .= "fk_source = ".$sourceid; |
|
3130 | + $sql .= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3131 | + $sql .= " WHERE fk_target = ".$this->id; |
|
3132 | + $sql .= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
3133 | 3133 | } else if ($updatetarget) { |
3134 | - $sql .= "fk_target = " . $targetid; |
|
3135 | - $sql .= ", targettype = '" . $this->db->escape($targettype) . "'"; |
|
3136 | - $sql .= " WHERE fk_source = " . $this->id; |
|
3137 | - $sql .= " AND sourcetype = '" . $this->db->escape($this->element) . "'"; |
|
3134 | + $sql .= "fk_target = ".$targetid; |
|
3135 | + $sql .= ", targettype = '".$this->db->escape($targettype)."'"; |
|
3136 | + $sql .= " WHERE fk_source = ".$this->id; |
|
3137 | + $sql .= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3138 | 3138 | } |
3139 | 3139 | |
3140 | - dol_syslog(get_class($this) . "::updateObjectLinked", LOG_DEBUG); |
|
3140 | + dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
|
3141 | 3141 | if ($this->db->query($sql)) { |
3142 | 3142 | return 1; |
3143 | 3143 | } else { |
@@ -3170,25 +3170,25 @@ discard block |
||
3170 | 3170 | $targetid = (!empty($targetid) ? $targetid : $this->id); |
3171 | 3171 | $targettype = (!empty($targettype) ? $targettype : $this->element); |
3172 | 3172 | |
3173 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_element"; |
|
3173 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
|
3174 | 3174 | $sql .= " WHERE"; |
3175 | 3175 | if ($rowid > 0) { |
3176 | - $sql .= " rowid = " . $rowid; |
|
3176 | + $sql .= " rowid = ".$rowid; |
|
3177 | 3177 | } else { |
3178 | 3178 | if ($deletesource) { |
3179 | - $sql .= " fk_source = " . $sourceid . " AND sourcetype = '" . $this->db->escape($sourcetype) . "'"; |
|
3180 | - $sql .= " AND fk_target = " . $this->id . " AND targettype = '" . $this->db->escape($this->element) . "'"; |
|
3179 | + $sql .= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3180 | + $sql .= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
3181 | 3181 | } else if ($deletetarget) { |
3182 | - $sql .= " fk_target = " . $targetid . " AND targettype = '" . $this->db->escape($targettype) . "'"; |
|
3183 | - $sql .= " AND fk_source = " . $this->id . " AND sourcetype = '" . $this->db->escape($this->element) . "'"; |
|
3182 | + $sql .= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
3183 | + $sql .= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3184 | 3184 | } else { |
3185 | - $sql .= " (fk_source = " . $this->id . " AND sourcetype = '" . $this->db->escape($this->element) . "')"; |
|
3185 | + $sql .= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
3186 | 3186 | $sql .= " OR"; |
3187 | - $sql .= " (fk_target = " . $this->id . " AND targettype = '" . $this->db->escape($this->element) . "')"; |
|
3187 | + $sql .= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
3188 | 3188 | } |
3189 | 3189 | } |
3190 | 3190 | |
3191 | - dol_syslog(get_class($this) . "::deleteObjectLinked", LOG_DEBUG); |
|
3191 | + dol_syslog(get_class($this)."::deleteObjectLinked", LOG_DEBUG); |
|
3192 | 3192 | if ($this->db->query($sql)) { |
3193 | 3193 | return 1; |
3194 | 3194 | } else { |
@@ -3218,7 +3218,7 @@ discard block |
||
3218 | 3218 | { |
3219 | 3219 | global $user, $langs, $conf; |
3220 | 3220 | |
3221 | - $savElementId = $elementId; // To be used later to know if we were using the method using the id of this or not. |
|
3221 | + $savElementId = $elementId; // To be used later to know if we were using the method using the id of this or not. |
|
3222 | 3222 | |
3223 | 3223 | $elementId = (!empty($elementId) ? $elementId : $this->id); |
3224 | 3224 | $elementTable = (!empty($elementType) ? $elementType : $this->table_element); |
@@ -3233,21 +3233,21 @@ discard block |
||
3233 | 3233 | if ($elementTable == 'expensereport') $fieldstatus = "fk_statut"; |
3234 | 3234 | if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus = "status"; |
3235 | 3235 | |
3236 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $elementTable; |
|
3237 | - $sql .= " SET " . $fieldstatus . " = " . $status; |
|
3236 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
|
3237 | + $sql .= " SET ".$fieldstatus." = ".$status; |
|
3238 | 3238 | // If status = 1 = validated, update also fk_user_valid |
3239 | - if ($status == 1 && $elementTable == 'expensereport') $sql .= ", fk_user_valid = " . $user->id; |
|
3240 | - $sql .= " WHERE rowid=" . $elementId; |
|
3239 | + if ($status == 1 && $elementTable == 'expensereport') $sql .= ", fk_user_valid = ".$user->id; |
|
3240 | + $sql .= " WHERE rowid=".$elementId; |
|
3241 | 3241 | |
3242 | - dol_syslog(get_class($this) . "::setStatut", LOG_DEBUG); |
|
3242 | + dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
|
3243 | 3243 | if ($this->db->query($sql)) { |
3244 | 3244 | $error = 0; |
3245 | 3245 | |
3246 | 3246 | // Try autoset of trigkey |
3247 | 3247 | if (empty($trigkey)) { |
3248 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
3248 | + if ($this->element == 'supplier_proposal' && $status == 2) $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
3249 | 3249 | if ($this->element == 'supplier_proposal' && $status == 3) $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
3250 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
3250 | + if ($this->element == 'supplier_proposal' && $status == 4) $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
3251 | 3251 | if ($this->element == 'fichinter' && $status == 3) $trigkey = 'FICHINTER_CLASSIFY_DONE'; |
3252 | 3252 | if ($this->element == 'fichinter' && $status == 2) $trigkey = 'FICHINTER_CLASSIFY_BILLED'; |
3253 | 3253 | if ($this->element == 'fichinter' && $status == 1) $trigkey = 'FICHINTER_CLASSIFY_UNBILLED'; |
@@ -3255,7 +3255,7 @@ discard block |
||
3255 | 3255 | |
3256 | 3256 | if ($trigkey) { |
3257 | 3257 | // Appel des triggers |
3258 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
3258 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
3259 | 3259 | $interface = new Interfaces($this->db); |
3260 | 3260 | $result = $interface->run_triggers($trigkey, $this, $user, $langs, $conf); |
3261 | 3261 | if ($result < 0) { |
@@ -3277,7 +3277,7 @@ discard block |
||
3277 | 3277 | return 1; |
3278 | 3278 | } else { |
3279 | 3279 | $this->db->rollback(); |
3280 | - dol_syslog(get_class($this) . "::setStatus " . $this->error, LOG_ERR); |
|
3280 | + dol_syslog(get_class($this)."::setStatus ".$this->error, LOG_ERR); |
|
3281 | 3281 | return -1; |
3282 | 3282 | } |
3283 | 3283 | } else { |
@@ -3303,16 +3303,16 @@ discard block |
||
3303 | 3303 | global $conf; |
3304 | 3304 | |
3305 | 3305 | if (empty($id) && empty($ref)) return 0; |
3306 | - if (!empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
3306 | + if (!empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
3307 | 3307 | |
3308 | 3308 | // Clean parameters |
3309 | 3309 | $ref = trim($ref); |
3310 | 3310 | |
3311 | 3311 | $sql = "SELECT rowid, canvas"; |
3312 | - $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; |
|
3313 | - $sql .= " WHERE entity IN (" . getEntity($this->element) . ")"; |
|
3314 | - if (!empty($id)) $sql .= " AND rowid = " . $id; |
|
3315 | - if (!empty($ref)) $sql .= " AND ref = '" . $this->db->escape($ref) . "'"; |
|
3312 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
3313 | + $sql .= " WHERE entity IN (".getEntity($this->element).")"; |
|
3314 | + if (!empty($id)) $sql .= " AND rowid = ".$id; |
|
3315 | + if (!empty($ref)) $sql .= " AND ref = '".$this->db->escape($ref)."'"; |
|
3316 | 3316 | |
3317 | 3317 | $resql = $this->db->query($sql); |
3318 | 3318 | if ($resql) { |
@@ -3335,8 +3335,8 @@ discard block |
||
3335 | 3335 | */ |
3336 | 3336 | function getSpecialCode($lineid) |
3337 | 3337 | { |
3338 | - $sql = 'SELECT special_code FROM ' . MAIN_DB_PREFIX . $this->table_element_line; |
|
3339 | - $sql .= ' WHERE rowid = ' . $lineid; |
|
3338 | + $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
3339 | + $sql .= ' WHERE rowid = '.$lineid; |
|
3340 | 3340 | $resql = $this->db->query($sql); |
3341 | 3341 | if ($resql) { |
3342 | 3342 | $row = $this->db->fetch_row($resql); |
@@ -3366,7 +3366,7 @@ discard block |
||
3366 | 3366 | if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) $qualified = 1; |
3367 | 3367 | if ($qualified) $nb++; |
3368 | 3368 | } |
3369 | - dol_syslog(get_class($this) . '::hasProductsOrServices we found ' . $nb . ' qualified lines of products/servcies'); |
|
3369 | + dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
|
3370 | 3370 | return $nb; |
3371 | 3371 | } |
3372 | 3372 | |
@@ -3380,10 +3380,10 @@ discard block |
||
3380 | 3380 | $total_discount = 0.00; |
3381 | 3381 | |
3382 | 3382 | $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
3383 | - $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element . "det"; |
|
3384 | - $sql .= " WHERE " . $this->fk_element . " = " . $this->id; |
|
3383 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
3384 | + $sql .= " WHERE ".$this->fk_element." = ".$this->id; |
|
3385 | 3385 | |
3386 | - dol_syslog(get_class($this) . '::getTotalDiscount', LOG_DEBUG); |
|
3386 | + dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
|
3387 | 3387 | $resql = $this->db->query($sql); |
3388 | 3388 | if ($resql) { |
3389 | 3389 | $num = $this->db->num_rows($resql); |
@@ -3426,15 +3426,15 @@ discard block |
||
3426 | 3426 | |
3427 | 3427 | foreach ($this->lines as $line) { |
3428 | 3428 | if (isset($line->qty_asked)) { |
3429 | - if (empty($totalOrdered)) $totalOrdered = 0; // Avoid warning because $totalOrdered is '' |
|
3430 | - $totalOrdered += $line->qty_asked; // defined for shipment only |
|
3429 | + if (empty($totalOrdered)) $totalOrdered = 0; // Avoid warning because $totalOrdered is '' |
|
3430 | + $totalOrdered += $line->qty_asked; // defined for shipment only |
|
3431 | 3431 | } |
3432 | 3432 | if (isset($line->qty_shipped)) { |
3433 | - if (empty($totalToShip)) $totalToShip = 0; // Avoid warning because $totalToShip is '' |
|
3434 | - $totalToShip += $line->qty_shipped; // defined for shipment only |
|
3433 | + if (empty($totalToShip)) $totalToShip = 0; // Avoid warning because $totalToShip is '' |
|
3434 | + $totalToShip += $line->qty_shipped; // defined for shipment only |
|
3435 | 3435 | } else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) { |
3436 | 3436 | if (empty($totalToShip)) $totalToShip = 0; |
3437 | - $totalToShip += $line->qty; // defined for reception only |
|
3437 | + $totalToShip += $line->qty; // defined for reception only |
|
3438 | 3438 | } |
3439 | 3439 | |
3440 | 3440 | // Define qty, weight, volume, weight_units, volume_units |
@@ -3460,8 +3460,8 @@ discard block |
||
3460 | 3460 | if (!empty($weight_units)) $weightUnit = $weight_units; |
3461 | 3461 | if (!empty($volume_units)) $volumeUnit = $volume_units; |
3462 | 3462 | |
3463 | - if (empty($totalWeight)) $totalWeight = 0; // Avoid warning because $totalWeight is '' |
|
3464 | - if (empty($totalVolume)) $totalVolume = 0; // Avoid warning because $totalVolume is '' |
|
3463 | + if (empty($totalWeight)) $totalWeight = 0; // Avoid warning because $totalWeight is '' |
|
3464 | + if (empty($totalVolume)) $totalVolume = 0; // Avoid warning because $totalVolume is '' |
|
3465 | 3465 | |
3466 | 3466 | //var_dump($line->volume_units); |
3467 | 3467 | if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
@@ -3478,7 +3478,7 @@ discard block |
||
3478 | 3478 | $trueWeightUnit = 0.0283495; |
3479 | 3479 | $totalWeight += $weight * $qty * $trueWeightUnit; |
3480 | 3480 | } else |
3481 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
3481 | + $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
3482 | 3482 | } |
3483 | 3483 | if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
3484 | 3484 | { |
@@ -3487,7 +3487,7 @@ discard block |
||
3487 | 3487 | //print $line->volume; |
3488 | 3488 | $totalVolume += $volume * $qty * $trueVolumeUnit; |
3489 | 3489 | } else { |
3490 | - $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
3490 | + $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
3491 | 3491 | } |
3492 | 3492 | } |
3493 | 3493 | |
@@ -3507,11 +3507,11 @@ discard block |
||
3507 | 3507 | |
3508 | 3508 | $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) : null); |
3509 | 3509 | |
3510 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element; |
|
3511 | - $sql .= " SET extraparams = " . (!empty($extraparams) ? "'" . $this->db->escape($extraparams) . "'" : "null"); |
|
3512 | - $sql .= " WHERE rowid = " . $this->id; |
|
3510 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
3511 | + $sql .= " SET extraparams = ".(!empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
3512 | + $sql .= " WHERE rowid = ".$this->id; |
|
3513 | 3513 | |
3514 | - dol_syslog(get_class($this) . "::setExtraParameters", LOG_DEBUG); |
|
3514 | + dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
|
3515 | 3515 | $resql = $this->db->query($sql); |
3516 | 3516 | if (!$resql) { |
3517 | 3517 | $this->error = $this->db->lasterror(); |
@@ -3535,7 +3535,7 @@ discard block |
||
3535 | 3535 | $out = ''; |
3536 | 3536 | $this->libelle_incoterms = ''; |
3537 | 3537 | if (!empty($this->fk_incoterms)) { |
3538 | - $sql = 'SELECT code FROM ' . MAIN_DB_PREFIX . 'c_incoterms WHERE rowid = ' . (int)$this->fk_incoterms; |
|
3538 | + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
3539 | 3539 | $result = $this->db->query($sql); |
3540 | 3540 | if ($result) { |
3541 | 3541 | $res = $this->db->fetch_object($result); |
@@ -3543,7 +3543,7 @@ discard block |
||
3543 | 3543 | } |
3544 | 3544 | } |
3545 | 3545 | |
3546 | - $out .= (($res->code && $this->location_incoterms) ? ' - ' : '') . $this->location_incoterms; |
|
3546 | + $out .= (($res->code && $this->location_incoterms) ? ' - ' : '').$this->location_incoterms; |
|
3547 | 3547 | |
3548 | 3548 | return $out; |
3549 | 3549 | } |
@@ -3555,13 +3555,13 @@ discard block |
||
3555 | 3555 | */ |
3556 | 3556 | function getIncotermsForPDF() |
3557 | 3557 | { |
3558 | - $sql = 'SELECT code FROM ' . MAIN_DB_PREFIX . 'c_incoterms WHERE rowid = ' . (int)$this->fk_incoterms; |
|
3558 | + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
3559 | 3559 | $resql = $this->db->query($sql); |
3560 | 3560 | if ($resql) { |
3561 | 3561 | $num = $this->db->num_rows($resql); |
3562 | 3562 | if ($num > 0) { |
3563 | 3563 | $res = $this->db->fetch_object($resql); |
3564 | - return 'Incoterm : ' . $res->code . ' - ' . $this->location_incoterms; |
|
3564 | + return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
|
3565 | 3565 | } else { |
3566 | 3566 | return ''; |
3567 | 3567 | } |
@@ -3581,17 +3581,17 @@ discard block |
||
3581 | 3581 | function setIncoterms($id_incoterm, $location) |
3582 | 3582 | { |
3583 | 3583 | if ($this->id && $this->table_element) { |
3584 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element; |
|
3585 | - $sql .= " SET fk_incoterms = " . ($id_incoterm > 0 ? $id_incoterm : "null"); |
|
3586 | - $sql .= ", location_incoterms = " . ($id_incoterm > 0 ? "'" . $this->db->escape($location) . "'" : "null"); |
|
3587 | - $sql .= " WHERE rowid = " . $this->id; |
|
3588 | - dol_syslog(get_class($this) . '::setIncoterms', LOG_DEBUG); |
|
3584 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
3585 | + $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
3586 | + $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
3587 | + $sql .= " WHERE rowid = ".$this->id; |
|
3588 | + dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
|
3589 | 3589 | $resql = $this->db->query($sql); |
3590 | 3590 | if ($resql) { |
3591 | 3591 | $this->fk_incoterms = $id_incoterm; |
3592 | 3592 | $this->location_incoterms = $location; |
3593 | 3593 | |
3594 | - $sql = 'SELECT libelle FROM ' . MAIN_DB_PREFIX . 'c_incoterms WHERE rowid = ' . (int)$this->fk_incoterms; |
|
3594 | + $sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
3595 | 3595 | $res = $this->db->query($sql); |
3596 | 3596 | if ($res) { |
3597 | 3597 | $obj = $this->db->fetch_object($res); |
@@ -3624,7 +3624,7 @@ discard block |
||
3624 | 3624 | global $form, $bcnd, $var; |
3625 | 3625 | |
3626 | 3626 | // Line extrafield |
3627 | - require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
3627 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
3628 | 3628 | $extrafieldsline = new ExtraFields($this->db); |
3629 | 3629 | $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
3630 | 3630 | |
@@ -3632,7 +3632,7 @@ discard block |
||
3632 | 3632 | // Use global variables + $dateSelector + $seller and $buyer |
3633 | 3633 | $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
3634 | 3634 | foreach ($dirtpls as $reldir) { |
3635 | - $tpl = dol_buildpath($reldir . '/objectline_create.tpl.php'); |
|
3635 | + $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
|
3636 | 3636 | if (empty($conf->file->strict_mode)) { |
3637 | 3637 | $res = @include $tpl; |
3638 | 3638 | } else { |
@@ -3674,7 +3674,7 @@ discard block |
||
3674 | 3674 | $num = count($this->lines); |
3675 | 3675 | |
3676 | 3676 | // Line extrafield |
3677 | - require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
3677 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
3678 | 3678 | $extrafieldsline = new ExtraFields($this->db); |
3679 | 3679 | $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
3680 | 3680 | |
@@ -3690,60 +3690,60 @@ discard block |
||
3690 | 3690 | if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
3691 | 3691 | |
3692 | 3692 | // Description |
3693 | - print '<td class="linecoldescription">' . $langs->trans('Description') . '</td>'; |
|
3693 | + print '<td class="linecoldescription">'.$langs->trans('Description').'</td>'; |
|
3694 | 3694 | |
3695 | 3695 | if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') { |
3696 | - print '<td class="linerefsupplier"><span id="title_fourn_ref">' . $langs->trans("SupplierRef") . '</span></td>'; |
|
3696 | + print '<td class="linerefsupplier"><span id="title_fourn_ref">'.$langs->trans("SupplierRef").'</span></td>'; |
|
3697 | 3697 | } |
3698 | 3698 | |
3699 | 3699 | // VAT |
3700 | - print '<td class="linecolvat" align="right" width="80">' . $langs->trans('VAT') . '</td>'; |
|
3700 | + print '<td class="linecolvat" align="right" width="80">'.$langs->trans('VAT').'</td>'; |
|
3701 | 3701 | |
3702 | 3702 | // Price HT |
3703 | - print '<td class="linecoluht" align="right" width="80">' . $langs->trans('PriceUHT') . '</td>'; |
|
3703 | + print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>'; |
|
3704 | 3704 | |
3705 | 3705 | // Multicurrency |
3706 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoluht_currency" align="right" width="80">' . $langs->trans('PriceUHTCurrency', $this->multicurrency_code) . '</td>'; |
|
3706 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>'; |
|
3707 | 3707 | |
3708 | - if ($inputalsopricewithtax) print '<td align="right" width="80">' . $langs->trans('PriceUTTC') . '</td>'; |
|
3708 | + if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>'; |
|
3709 | 3709 | |
3710 | 3710 | // Qty |
3711 | - print '<td class="linecolqty" align="right">' . $langs->trans('Qty') . '</td>'; |
|
3711 | + print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>'; |
|
3712 | 3712 | |
3713 | 3713 | if ($conf->global->PRODUCT_USE_UNITS) { |
3714 | - print '<td class="linecoluseunit" align="left">' . $langs->trans('Unit') . '</td>'; |
|
3714 | + print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>'; |
|
3715 | 3715 | } |
3716 | 3716 | |
3717 | 3717 | // Reduction short |
3718 | - print '<td class="linecoldiscount" align="right">' . $langs->trans('ReductionShort') . '</td>'; |
|
3718 | + print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>'; |
|
3719 | 3719 | |
3720 | 3720 | if ($this->situation_cycle_ref) { |
3721 | - print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>'; |
|
3721 | + print '<td class="linecolcycleref" align="right">'.$langs->trans('Progress').'</td>'; |
|
3722 | 3722 | } |
3723 | 3723 | |
3724 | 3724 | if ($usemargins && !empty($conf->margin->enabled) && empty($user->societe_id)) { |
3725 | 3725 | if (!empty($user->rights->margins->creer)) { |
3726 | 3726 | if ($conf->global->MARGIN_TYPE == "1") |
3727 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">' . $langs->trans('BuyingPrice') . '</td>'; |
|
3727 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>'; |
|
3728 | 3728 | else |
3729 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">' . $langs->trans('CostPrice') . '</td>'; |
|
3729 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
|
3730 | 3730 | } |
3731 | 3731 | |
3732 | 3732 | if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
3733 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">' . $langs->trans('MarginRate') . '</td>'; |
|
3733 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>'; |
|
3734 | 3734 | if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
3735 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">' . $langs->trans('MarkRate') . '</td>'; |
|
3735 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
|
3736 | 3736 | } |
3737 | 3737 | |
3738 | 3738 | // Total HT |
3739 | - print '<td class="linecolht" align="right">' . $langs->trans('TotalHTShort') . '</td>'; |
|
3739 | + print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>'; |
|
3740 | 3740 | |
3741 | 3741 | // Multicurrency |
3742 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">' . $langs->trans('TotalHTShortCurrency', $this->multicurrency_code) . '</td>'; |
|
3742 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>'; |
|
3743 | 3743 | |
3744 | - if ($outputalsopricetotalwithtax) print '<td align="right" width="80">' . $langs->trans('TotalTTCShort') . '</td>'; |
|
3744 | + if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
|
3745 | 3745 | |
3746 | - print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
3746 | + print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
3747 | 3747 | |
3748 | 3748 | print '<td class="linecoldelete" width="10"></td>'; |
3749 | 3749 | |
@@ -3773,10 +3773,10 @@ discard block |
||
3773 | 3773 | { |
3774 | 3774 | if (empty($line->fk_parent_line)) { |
3775 | 3775 | $parameters = array('line' => $line, 'var' => $var, 'num' => $num, 'i' => $i, 'dateSelector' => $dateSelector, 'seller' => $seller, 'buyer' => $buyer, 'selected' => $selected, 'extrafieldsline' => $extrafieldsline); |
3776 | - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3776 | + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3777 | 3777 | } else { |
3778 | 3778 | $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); |
3779 | - $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3779 | + $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3780 | 3780 | } |
3781 | 3781 | } |
3782 | 3782 | if (empty($reshook)) { |
@@ -3814,7 +3814,7 @@ discard block |
||
3814 | 3814 | { |
3815 | 3815 | global $conf, $langs, $user, $object, $hookmanager; |
3816 | 3816 | global $form, $bc, $bcdd; |
3817 | - global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
3817 | + global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
3818 | 3818 | |
3819 | 3819 | $object_rights = $this->getRights(); |
3820 | 3820 | |
@@ -3854,7 +3854,7 @@ discard block |
||
3854 | 3854 | $outputlangs = $langs; |
3855 | 3855 | $newlang = ''; |
3856 | 3856 | if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); |
3857 | - if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang = $this->thirdparty->default_lang; // For language to language of customer |
|
3857 | + if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang = $this->thirdparty->default_lang; // For language to language of customer |
|
3858 | 3858 | if (!empty($newlang)) { |
3859 | 3859 | $outputlangs = new Translate("", $conf); |
3860 | 3860 | $outputlangs->setDefaultLang($newlang); |
@@ -3865,8 +3865,8 @@ discard block |
||
3865 | 3865 | $label = $line->product_label; |
3866 | 3866 | } |
3867 | 3867 | |
3868 | - $text .= ' - ' . (!empty($line->label) ? $line->label : $label); |
|
3869 | - $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. |
|
3868 | + $text .= ' - '.(!empty($line->label) ? $line->label : $label); |
|
3869 | + $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. |
|
3870 | 3870 | } |
3871 | 3871 | |
3872 | 3872 | $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
@@ -3875,7 +3875,7 @@ discard block |
||
3875 | 3875 | // Use global variables + $dateSelector + $seller and $buyer |
3876 | 3876 | $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
3877 | 3877 | foreach ($dirtpls as $reldir) { |
3878 | - $tpl = dol_buildpath($reldir . '/objectline_view.tpl.php'); |
|
3878 | + $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
|
3879 | 3879 | if (empty($conf->file->strict_mode)) { |
3880 | 3880 | $res = @include $tpl; |
3881 | 3881 | } else { |
@@ -3888,7 +3888,7 @@ discard block |
||
3888 | 3888 | // Ligne en mode update |
3889 | 3889 | if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) { |
3890 | 3890 | $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
3891 | - $placeholder = ' placeholder="' . $langs->trans("Label") . '"'; |
|
3891 | + $placeholder = ' placeholder="'.$langs->trans("Label").'"'; |
|
3892 | 3892 | |
3893 | 3893 | $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
3894 | 3894 | |
@@ -3896,7 +3896,7 @@ discard block |
||
3896 | 3896 | // Use global variables + $dateSelector + $seller and $buyer |
3897 | 3897 | $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
3898 | 3898 | foreach ($dirtpls as $reldir) { |
3899 | - $tpl = dol_buildpath($reldir . '/objectline_edit.tpl.php'); |
|
3899 | + $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
|
3900 | 3900 | if (empty($conf->file->strict_mode)) { |
3901 | 3901 | $res = @include $tpl; |
3902 | 3902 | } else { |
@@ -3935,16 +3935,16 @@ discard block |
||
3935 | 3935 | global $langs, $hookmanager, $conf; |
3936 | 3936 | |
3937 | 3937 | print '<tr class="liste_titre">'; |
3938 | - print '<td>' . $langs->trans('Ref') . '</td>'; |
|
3939 | - print '<td>' . $langs->trans('Description') . '</td>'; |
|
3940 | - print '<td align="right">' . $langs->trans('VATRate') . '</td>'; |
|
3941 | - print '<td align="right">' . $langs->trans('PriceUHT') . '</td>'; |
|
3942 | - if (!empty($conf->multicurrency->enabled)) print '<td align="right">' . $langs->trans('PriceUHTCurrency') . '</td>'; |
|
3943 | - print '<td align="right">' . $langs->trans('Qty') . '</td>'; |
|
3938 | + print '<td>'.$langs->trans('Ref').'</td>'; |
|
3939 | + print '<td>'.$langs->trans('Description').'</td>'; |
|
3940 | + print '<td align="right">'.$langs->trans('VATRate').'</td>'; |
|
3941 | + print '<td align="right">'.$langs->trans('PriceUHT').'</td>'; |
|
3942 | + if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>'; |
|
3943 | + print '<td align="right">'.$langs->trans('Qty').'</td>'; |
|
3944 | 3944 | if ($conf->global->PRODUCT_USE_UNITS) { |
3945 | - print '<td align="left">' . $langs->trans('Unit') . '</td>'; |
|
3945 | + print '<td align="left">'.$langs->trans('Unit').'</td>'; |
|
3946 | 3946 | } |
3947 | - print '<td align="right">' . $langs->trans('ReductionShort') . '</td></tr>'; |
|
3947 | + print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>'; |
|
3948 | 3948 | |
3949 | 3949 | $var = true; |
3950 | 3950 | $i = 0; |
@@ -3955,7 +3955,7 @@ discard block |
||
3955 | 3955 | if (empty($line->fk_parent_line)) { |
3956 | 3956 | $parameters = array('line' => $line, 'var' => $var, 'i' => $i); |
3957 | 3957 | $action = ''; |
3958 | - $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3958 | + $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3959 | 3959 | } |
3960 | 3960 | } else { |
3961 | 3961 | $this->printOriginLine($line, $var, $restrictlist); |
@@ -4014,7 +4014,7 @@ discard block |
||
4014 | 4014 | } |
4015 | 4015 | |
4016 | 4016 | $this->tpl['label'] .= $productstatic->getNomUrl(1); |
4017 | - $this->tpl['label'] .= ' - ' . (!empty($line->label) ? $line->label : $line->product_label); |
|
4017 | + $this->tpl['label'] .= ' - '.(!empty($line->label) ? $line->label : $line->product_label); |
|
4018 | 4018 | // Dates |
4019 | 4019 | if ($line->product_type == 1 && ($date_start || $date_end)) { |
4020 | 4020 | $this->tpl['label'] .= get_date_range($date_start, $date_end); |
@@ -4024,7 +4024,7 @@ discard block |
||
4024 | 4024 | if (!empty($line->desc)) { |
4025 | 4025 | $this->tpl['label'] .= $line->desc; |
4026 | 4026 | } else { |
4027 | - $this->tpl['label'] .= ($line->label ? ' ' . $line->label : ''); |
|
4027 | + $this->tpl['label'] .= ($line->label ? ' '.$line->label : ''); |
|
4028 | 4028 | } |
4029 | 4029 | |
4030 | 4030 | // Dates |
@@ -4062,7 +4062,7 @@ discard block |
||
4062 | 4062 | // VAT Rate |
4063 | 4063 | $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
4064 | 4064 | $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
4065 | - if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'] .= ' (' . $line->vat_src_code . ')'; |
|
4065 | + if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'] .= ' ('.$line->vat_src_code.')'; |
|
4066 | 4066 | |
4067 | 4067 | $this->tpl['price'] = price($line->subprice); |
4068 | 4068 | $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
@@ -4078,7 +4078,7 @@ discard block |
||
4078 | 4078 | // Use global variables + $dateSelector + $seller and $buyer |
4079 | 4079 | $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
4080 | 4080 | foreach ($dirtpls as $reldir) { |
4081 | - $tpl = dol_buildpath($reldir . '/originproductline.tpl.php'); |
|
4081 | + $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
|
4082 | 4082 | if (empty($conf->file->strict_mode)) { |
4083 | 4083 | $res = @include $tpl; |
4084 | 4084 | } else { |
@@ -4103,7 +4103,7 @@ discard block |
||
4103 | 4103 | // phpcs:enable |
4104 | 4104 | $this->db->begin(); |
4105 | 4105 | |
4106 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_resources ("; |
|
4106 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; |
|
4107 | 4107 | $sql .= "resource_id"; |
4108 | 4108 | $sql .= ", resource_type"; |
4109 | 4109 | $sql .= ", element_id"; |
@@ -4112,14 +4112,14 @@ discard block |
||
4112 | 4112 | $sql .= ", mandatory"; |
4113 | 4113 | $sql .= ") VALUES ("; |
4114 | 4114 | $sql .= $resource_id; |
4115 | - $sql .= ", '" . $this->db->escape($resource_type) . "'"; |
|
4116 | - $sql .= ", '" . $this->db->escape($this->id) . "'"; |
|
4117 | - $sql .= ", '" . $this->db->escape($this->element) . "'"; |
|
4118 | - $sql .= ", '" . $this->db->escape($busy) . "'"; |
|
4119 | - $sql .= ", '" . $this->db->escape($mandatory) . "'"; |
|
4115 | + $sql .= ", '".$this->db->escape($resource_type)."'"; |
|
4116 | + $sql .= ", '".$this->db->escape($this->id)."'"; |
|
4117 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
4118 | + $sql .= ", '".$this->db->escape($busy)."'"; |
|
4119 | + $sql .= ", '".$this->db->escape($mandatory)."'"; |
|
4120 | 4120 | $sql .= ")"; |
4121 | 4121 | |
4122 | - dol_syslog(get_class($this) . "::add_element_resource", LOG_DEBUG); |
|
4122 | + dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
|
4123 | 4123 | if ($this->db->query($sql)) { |
4124 | 4124 | $this->db->commit(); |
4125 | 4125 | return 1; |
@@ -4145,10 +4145,10 @@ discard block |
||
4145 | 4145 | |
4146 | 4146 | $this->db->begin(); |
4147 | 4147 | |
4148 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_resources"; |
|
4149 | - $sql .= " WHERE rowid=" . $rowid; |
|
4148 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
|
4149 | + $sql .= " WHERE rowid=".$rowid; |
|
4150 | 4150 | |
4151 | - dol_syslog(get_class($this) . "::delete_resource", LOG_DEBUG); |
|
4151 | + dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
|
4152 | 4152 | |
4153 | 4153 | $resql = $this->db->query($sql); |
4154 | 4154 | if (!$resql) { |
@@ -4157,7 +4157,7 @@ discard block |
||
4157 | 4157 | return -1; |
4158 | 4158 | } else { |
4159 | 4159 | if (!$notrigger) { |
4160 | - $result = $this->call_trigger(strtoupper($element) . '_DELETE_RESOURCE', $user); |
|
4160 | + $result = $this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
4161 | 4161 | if ($result < 0) { |
4162 | 4162 | $this->db->rollback(); |
4163 | 4163 | return -1; |
@@ -4195,7 +4195,7 @@ discard block |
||
4195 | 4195 | { |
4196 | 4196 | global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
4197 | 4197 | |
4198 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
4198 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
4199 | 4199 | |
4200 | 4200 | $file_osencoded = dol_osencode($file); |
4201 | 4201 | if (file_exists($file_osencoded)) { |
@@ -4238,7 +4238,7 @@ discard block |
||
4238 | 4238 | return ''; |
4239 | 4239 | } |
4240 | 4240 | |
4241 | - $keyforfieldname = strtoupper($newelement . '_DEFAULT_' . $fieldname); |
|
4241 | + $keyforfieldname = strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
4242 | 4242 | //var_dump($keyforfieldname); |
4243 | 4243 | if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
4244 | 4244 | |
@@ -4271,7 +4271,7 @@ discard block |
||
4271 | 4271 | // global $extrafields; |
4272 | 4272 | //if (! is_object($extrafields)) |
4273 | 4273 | //{ |
4274 | - require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
4274 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
4275 | 4275 | $extrafields = new ExtraFields($this->db); |
4276 | 4276 | //} |
4277 | 4277 | |
@@ -4293,11 +4293,11 @@ discard block |
||
4293 | 4293 | $sql = "SELECT rowid"; |
4294 | 4294 | foreach ($optionsArray as $name => $label) { |
4295 | 4295 | if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') { |
4296 | - $sql .= ", " . $name; |
|
4296 | + $sql .= ", ".$name; |
|
4297 | 4297 | } |
4298 | 4298 | } |
4299 | - $sql .= " FROM " . MAIN_DB_PREFIX . $table_element . "_extrafields"; |
|
4300 | - $sql .= " WHERE fk_object = " . $rowid; |
|
4299 | + $sql .= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
4300 | + $sql .= " WHERE fk_object = ".$rowid; |
|
4301 | 4301 | |
4302 | 4302 | //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
4303 | 4303 | $resql = $this->db->query($sql); |
@@ -4313,9 +4313,9 @@ discard block |
||
4313 | 4313 | // we can add this attribute to object |
4314 | 4314 | if (!empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime'))) { |
4315 | 4315 | //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
4316 | - $this->array_options["options_" . $key] = $this->db->jdate($value); |
|
4316 | + $this->array_options["options_".$key] = $this->db->jdate($value); |
|
4317 | 4317 | } else { |
4318 | - $this->array_options["options_" . $key] = $value; |
|
4318 | + $this->array_options["options_".$key] = $value; |
|
4319 | 4319 | } |
4320 | 4320 | |
4321 | 4321 | //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]); |
@@ -4349,8 +4349,8 @@ discard block |
||
4349 | 4349 | $table_element = $this->table_element; |
4350 | 4350 | if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
4351 | 4351 | |
4352 | - $sql_del = "DELETE FROM " . MAIN_DB_PREFIX . $table_element . "_extrafields WHERE fk_object = " . $this->id; |
|
4353 | - dol_syslog(get_class($this) . "::deleteExtraFields delete", LOG_DEBUG); |
|
4352 | + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
4353 | + dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
|
4354 | 4354 | $resql = $this->db->query($sql_del); |
4355 | 4355 | if (!$resql) { |
4356 | 4356 | $this->error = $this->db->lasterror(); |
@@ -4380,16 +4380,16 @@ discard block |
||
4380 | 4380 | |
4381 | 4381 | $error = 0; |
4382 | 4382 | |
4383 | - if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
4383 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
4384 | 4384 | |
4385 | - if (!empty($this->array_options) && isset($this->array_options["options_" . $key])) { |
|
4385 | + if (!empty($this->array_options) && isset($this->array_options["options_".$key])) { |
|
4386 | 4386 | // Check parameters |
4387 | 4387 | $langs->load('admin'); |
4388 | - require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
4388 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
4389 | 4389 | $extrafields = new ExtraFields($this->db); |
4390 | 4390 | $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
4391 | 4391 | |
4392 | - $value = $this->array_options["options_" . $key]; |
|
4392 | + $value = $this->array_options["options_".$key]; |
|
4393 | 4393 | |
4394 | 4394 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
4395 | 4395 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
@@ -4405,20 +4405,20 @@ discard block |
||
4405 | 4405 | $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
4406 | 4406 | return -1; |
4407 | 4407 | } elseif ($value == '') { |
4408 | - $this->array_options["options_" . $key] = null; |
|
4408 | + $this->array_options["options_".$key] = null; |
|
4409 | 4409 | } |
4410 | 4410 | break; |
4411 | 4411 | case 'double': |
4412 | 4412 | $value = price2num($value); |
4413 | 4413 | if (!is_numeric($value) && $value != '') { |
4414 | - dol_syslog($langs->trans("ExtraFieldHasWrongValue") . " sur " . $attributeLabel . "(" . $value . "is not '" . $attributeType . "')", LOG_DEBUG); |
|
4414 | + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
|
4415 | 4415 | $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
4416 | 4416 | return -1; |
4417 | 4417 | } elseif ($value == '') { |
4418 | - $this->array_options["options_" . $key] = null; |
|
4418 | + $this->array_options["options_".$key] = null; |
|
4419 | 4419 | } |
4420 | 4420 | //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG); |
4421 | - $this->array_options["options_" . $key] = $value; |
|
4421 | + $this->array_options["options_".$key] = $value; |
|
4422 | 4422 | break; |
4423 | 4423 | /*case 'select': // Not required, we chosed value='0' for undefined values |
4424 | 4424 | if ($value=='-1') |
@@ -4427,13 +4427,13 @@ discard block |
||
4427 | 4427 | } |
4428 | 4428 | break;*/ |
4429 | 4429 | case 'price': |
4430 | - $this->array_options["options_" . $key] = price2num($this->array_options["options_" . $key]); |
|
4430 | + $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
|
4431 | 4431 | break; |
4432 | 4432 | case 'date': |
4433 | - $this->array_options["options_" . $key] = $this->db->idate($this->array_options["options_" . $key]); |
|
4433 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
4434 | 4434 | break; |
4435 | 4435 | case 'datetime': |
4436 | - $this->array_options["options_" . $key] = $this->db->idate($this->array_options["options_" . $key]); |
|
4436 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
4437 | 4437 | break; |
4438 | 4438 | case 'link': |
4439 | 4439 | $param_list = array_keys($attributeParam['options']); |
@@ -4444,14 +4444,14 @@ discard block |
||
4444 | 4444 | if ($value) { |
4445 | 4445 | $object = new $InfoFieldList[0]($this->db); |
4446 | 4446 | $object->fetch(0, $value); |
4447 | - $this->array_options["options_" . $key] = $object->id; |
|
4447 | + $this->array_options["options_".$key] = $object->id; |
|
4448 | 4448 | } |
4449 | 4449 | break; |
4450 | 4450 | } |
4451 | 4451 | |
4452 | 4452 | $this->db->begin(); |
4453 | - $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element . "_extrafields SET " . $key . "='" . $this->db->escape($this->array_options["options_" . $key]) . "'"; |
|
4454 | - $sql .= " WHERE fk_object = " . $this->id; |
|
4453 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
|
4454 | + $sql .= " WHERE fk_object = ".$this->id; |
|
4455 | 4455 | $resql = $this->db->query($sql); |
4456 | 4456 | if (!$resql) { |
4457 | 4457 | $error++; |
@@ -4467,7 +4467,7 @@ discard block |
||
4467 | 4467 | } |
4468 | 4468 | |
4469 | 4469 | if ($error) { |
4470 | - dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); |
|
4470 | + dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR); |
|
4471 | 4471 | $this->db->rollback(); |
4472 | 4472 | return -1; |
4473 | 4473 | } else { |
@@ -4495,7 +4495,7 @@ discard block |
||
4495 | 4495 | global $conf, $langs, $form; |
4496 | 4496 | |
4497 | 4497 | if (!is_object($form)) { |
4498 | - require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'; |
|
4498 | + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
4499 | 4499 | $form = new Form($this->db); |
4500 | 4500 | } |
4501 | 4501 | |
@@ -4508,13 +4508,13 @@ discard block |
||
4508 | 4508 | $size = $this->fields[$key]['size']; |
4509 | 4509 | // Because we work on extrafields |
4510 | 4510 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) { |
4511 | - $param['options'] = array($reg[1] . ':' . $reg[2] => 'N'); |
|
4511 | + $param['options'] = array($reg[1].':'.$reg[2] => 'N'); |
|
4512 | 4512 | $type = 'link'; |
4513 | 4513 | } elseif (preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) { |
4514 | - $param['options'] = array($reg[1] . ':' . $reg[2] => 'N'); |
|
4514 | + $param['options'] = array($reg[1].':'.$reg[2] => 'N'); |
|
4515 | 4515 | $type = 'link'; |
4516 | 4516 | } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) { |
4517 | - $param['options'] = array($reg[1] . ':' . $reg[2] . ':' . $reg[3] . ':' . $reg[4] => 'N'); |
|
4517 | + $param['options'] = array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4] => 'N'); |
|
4518 | 4518 | $type = 'sellist'; |
4519 | 4519 | } elseif (preg_match('/varchar\((\d+)\)/', $val['type'], $reg)) { |
4520 | 4520 | $param['options'] = array(); |
@@ -4546,7 +4546,7 @@ discard block |
||
4546 | 4546 | |
4547 | 4547 | |
4548 | 4548 | if ($computed) { |
4549 | - if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">' . $langs->trans("AutomaticallyCalculated") . '</span>'; |
|
4549 | + if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
4550 | 4550 | else return ''; |
4551 | 4551 | } |
4552 | 4552 | |
@@ -4587,32 +4587,32 @@ discard block |
||
4587 | 4587 | if (!$required && $value == '') $value = '-1'; |
4588 | 4588 | |
4589 | 4589 | // TODO Must also support $moreparam |
4590 | - $out = $form->selectDate($value, $keyprefix . $key . $keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
|
4590 | + $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
|
4591 | 4591 | } elseif (in_array($type, array('int', 'integer'))) { |
4592 | 4592 | $tmp = explode(',', $size); |
4593 | 4593 | $newsize = $tmp[0]; |
4594 | - $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 : '') . '>'; |
|
4594 | + $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 : '').'>'; |
|
4595 | 4595 | } elseif (preg_match('/varchar/', $type)) { |
4596 | - $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 : '') . '>'; |
|
4596 | + $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 : '').'>'; |
|
4597 | 4597 | } elseif (in_array($type, array('mail', 'phone', 'url'))) { |
4598 | - $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . dol_escape_htmltag($value) . '" ' . ($moreparam ? $moreparam : '') . '>'; |
|
4598 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
4599 | 4599 | } elseif ($type == 'text') { |
4600 | 4600 | if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
4601 | 4601 | { |
4602 | - require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; |
|
4603 | - $doleditor = new DolEditor($keyprefix . $key . $keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); |
|
4602 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
4603 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); |
|
4604 | 4604 | $out = $doleditor->Create(1); |
4605 | 4605 | } else { |
4606 | - $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . dol_escape_htmltag($value) . '" ' . ($moreparam ? $moreparam : '') . '>'; |
|
4606 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
4607 | 4607 | } |
4608 | 4608 | } elseif ($type == 'html') { |
4609 | 4609 | if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
4610 | 4610 | { |
4611 | - require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; |
|
4612 | - $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%'); |
|
4611 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
4612 | + $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%'); |
|
4613 | 4613 | $out = $doleditor->Create(1); |
4614 | 4614 | } else { |
4615 | - $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . dol_escape_htmltag($value) . '" ' . ($moreparam ? $moreparam : '') . '>'; |
|
4615 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
4616 | 4616 | } |
4617 | 4617 | } elseif ($type == 'boolean') { |
4618 | 4618 | $checked = ''; |
@@ -4621,43 +4621,43 @@ discard block |
||
4621 | 4621 | } else { |
4622 | 4622 | $checked = ' value="1" '; |
4623 | 4623 | } |
4624 | - $out = '<input type="checkbox" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . $checked . ' ' . ($moreparam ? $moreparam : '') . '>'; |
|
4624 | + $out = '<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>'; |
|
4625 | 4625 | } elseif ($type == 'price') { |
4626 | 4626 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
4627 | 4627 | $value = price($value); |
4628 | 4628 | } |
4629 | - $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ($moreparam ? $moreparam : '') . '> ' . $langs->getCurrencySymbol($conf->currency); |
|
4629 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '.$langs->getCurrencySymbol($conf->currency); |
|
4630 | 4630 | } elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type)) { |
4631 | 4631 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
4632 | 4632 | $value = price($value); |
4633 | 4633 | } |
4634 | - $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ($moreparam ? $moreparam : '') . '> '; |
|
4634 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '; |
|
4635 | 4635 | } elseif ($type == 'select') { |
4636 | 4636 | $out = ''; |
4637 | 4637 | if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) { |
4638 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
4639 | - $out .= ajax_combobox($keyprefix . $key . $keysuffix, array(), 0); |
|
4638 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
4639 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
4640 | 4640 | } |
4641 | 4641 | |
4642 | - $out .= '<select class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . ($moreparam ? $moreparam : '') . '>'; |
|
4642 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
4643 | 4643 | if ((!isset($this->fields[$key]['default'])) || ($this->fields[$key]['notnull'] != 1)) $out .= '<option value="0"> </option>'; |
4644 | 4644 | foreach ($param['options'] as $key => $val) { |
4645 | - if ((string)$key == '') continue; |
|
4645 | + if ((string) $key == '') continue; |
|
4646 | 4646 | list($val, $parent) = explode('|', $val); |
4647 | - $out .= '<option value="' . $key . '"'; |
|
4648 | - $out .= (((string)$value == (string)$key) ? ' selected' : ''); |
|
4649 | - $out .= (!empty($parent) ? ' parent="' . $parent . '"' : ''); |
|
4650 | - $out .= '>' . $val . '</option>'; |
|
4647 | + $out .= '<option value="'.$key.'"'; |
|
4648 | + $out .= (((string) $value == (string) $key) ? ' selected' : ''); |
|
4649 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
4650 | + $out .= '>'.$val.'</option>'; |
|
4651 | 4651 | } |
4652 | 4652 | $out .= '</select>'; |
4653 | 4653 | } elseif ($type == 'sellist') { |
4654 | 4654 | $out = ''; |
4655 | 4655 | if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) { |
4656 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
4657 | - $out .= ajax_combobox($keyprefix . $key . $keysuffix, array(), 0); |
|
4656 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
4657 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
4658 | 4658 | } |
4659 | 4659 | |
4660 | - $out .= '<select class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . ($moreparam ? $moreparam : '') . '>'; |
|
4660 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
4661 | 4661 | if (is_array($param['options'])) { |
4662 | 4662 | $param_list = array_keys($param['options']); |
4663 | 4663 | $InfoFieldList = explode(":", $param_list[0]); |
@@ -4668,19 +4668,19 @@ discard block |
||
4668 | 4668 | // 2 : key fields name (if differ of rowid) |
4669 | 4669 | // 3 : key field parent (for dependent lists) |
4670 | 4670 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
4671 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
4671 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
4672 | 4672 | |
4673 | 4673 | |
4674 | 4674 | if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { |
4675 | 4675 | if (strpos($InfoFieldList[4], 'extra.') !== false) { |
4676 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
4676 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
4677 | 4677 | } else { |
4678 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
4678 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
4679 | 4679 | } |
4680 | 4680 | } |
4681 | 4681 | if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { |
4682 | 4682 | list($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
4683 | - $keyList .= ', ' . $parentField; |
|
4683 | + $keyList .= ', '.$parentField; |
|
4684 | 4684 | } |
4685 | 4685 | |
4686 | 4686 | $fields_label = explode('|', $InfoFieldList[1]); |
@@ -4690,8 +4690,8 @@ discard block |
||
4690 | 4690 | } |
4691 | 4691 | |
4692 | 4692 | $sqlwhere = ''; |
4693 | - $sql = 'SELECT ' . $keyList; |
|
4694 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
4693 | + $sql = 'SELECT '.$keyList; |
|
4694 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
4695 | 4695 | if (!empty($InfoFieldList[4])) { |
4696 | 4696 | // can use SELECT request |
4697 | 4697 | if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
@@ -4706,24 +4706,24 @@ discard block |
||
4706 | 4706 | } |
4707 | 4707 | //We have to join on extrafield table |
4708 | 4708 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
4709 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
4710 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
4709 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
4710 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
4711 | 4711 | } else { |
4712 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
4712 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
4713 | 4713 | } |
4714 | 4714 | } else { |
4715 | 4715 | $sqlwhere .= ' WHERE 1=1'; |
4716 | 4716 | } |
4717 | 4717 | // Some tables may have field, some other not. For the moment we disable it. |
4718 | 4718 | if (in_array($InfoFieldList[0], array('tablewithentity'))) { |
4719 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
4719 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
4720 | 4720 | } |
4721 | 4721 | $sql .= $sqlwhere; |
4722 | 4722 | //print $sql; |
4723 | 4723 | |
4724 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label); |
|
4724 | + $sql .= ' ORDER BY '.implode(', ', $fields_label); |
|
4725 | 4725 | |
4726 | - dol_syslog(get_class($this) . '::showInputField type=sellist', LOG_DEBUG); |
|
4726 | + dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
|
4727 | 4727 | $resql = $this->db->query($sql); |
4728 | 4728 | if ($resql) { |
4729 | 4729 | $out .= '<option value="0"> </option>'; |
@@ -4739,7 +4739,7 @@ discard block |
||
4739 | 4739 | if (is_array($fields_label)) { |
4740 | 4740 | $notrans = true; |
4741 | 4741 | foreach ($fields_label as $field_toshow) { |
4742 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
4742 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
4743 | 4743 | } |
4744 | 4744 | } else { |
4745 | 4745 | $labeltoshow = $obj->{$InfoFieldList[1]}; |
@@ -4750,12 +4750,12 @@ discard block |
||
4750 | 4750 | foreach ($fields_label as $field_toshow) { |
4751 | 4751 | $translabel = $langs->trans($obj->$field_toshow); |
4752 | 4752 | if ($translabel != $obj->$field_toshow) { |
4753 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
4753 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
4754 | 4754 | } else { |
4755 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
4755 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
4756 | 4756 | } |
4757 | 4757 | } |
4758 | - $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>'; |
|
4758 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
4759 | 4759 | } else { |
4760 | 4760 | if (!$notrans) { |
4761 | 4761 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
@@ -4767,38 +4767,38 @@ discard block |
||
4767 | 4767 | } |
4768 | 4768 | if (empty($labeltoshow)) $labeltoshow = '(not defined)'; |
4769 | 4769 | if ($value == $obj->rowid) { |
4770 | - $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>'; |
|
4770 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
4771 | 4771 | } |
4772 | 4772 | |
4773 | 4773 | if (!empty($InfoFieldList[3]) && $parentField) { |
4774 | - $parent = $parentName . ':' . $obj->{$parentField}; |
|
4774 | + $parent = $parentName.':'.$obj->{$parentField}; |
|
4775 | 4775 | } |
4776 | 4776 | |
4777 | - $out .= '<option value="' . $obj->rowid . '"'; |
|
4777 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
4778 | 4778 | $out .= ($value == $obj->rowid ? ' selected' : ''); |
4779 | - $out .= (!empty($parent) ? ' parent="' . $parent . '"' : ''); |
|
4780 | - $out .= '>' . $labeltoshow . '</option>'; |
|
4779 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
4780 | + $out .= '>'.$labeltoshow.'</option>'; |
|
4781 | 4781 | } |
4782 | 4782 | |
4783 | 4783 | $i++; |
4784 | 4784 | } |
4785 | 4785 | $this->db->free($resql); |
4786 | 4786 | } else { |
4787 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
4787 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
4788 | 4788 | } |
4789 | 4789 | } |
4790 | 4790 | $out .= '</select>'; |
4791 | 4791 | } elseif ($type == 'checkbox') { |
4792 | 4792 | $value_arr = explode(',', $value); |
4793 | - $out = $form->multiselectarray($keyprefix . $key . $keysuffix, (empty($param['options']) ? null : $param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
4793 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ? null : $param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
4794 | 4794 | } elseif ($type == 'radio') { |
4795 | 4795 | $out = ''; |
4796 | 4796 | foreach ($param['options'] as $keyopt => $val) { |
4797 | - $out .= '<input class="flat ' . $morecss . '" type="radio" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . ($moreparam ? $moreparam : ''); |
|
4798 | - $out .= ' value="' . $keyopt . '"'; |
|
4799 | - $out .= ' id="' . $keyprefix . $key . $keysuffix . '_' . $keyopt . '"'; |
|
4797 | + $out .= '<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : ''); |
|
4798 | + $out .= ' value="'.$keyopt.'"'; |
|
4799 | + $out .= ' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
4800 | 4800 | $out .= ($value == $keyopt ? 'checked' : ''); |
4801 | - $out .= '/><label for="' . $keyprefix . $key . $keysuffix . '_' . $keyopt . '">' . $val . '</label><br>'; |
|
4801 | + $out .= '/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
4802 | 4802 | } |
4803 | 4803 | } elseif ($type == 'chkbxlst') { |
4804 | 4804 | if (is_array($value)) { |
@@ -4817,17 +4817,17 @@ discard block |
||
4817 | 4817 | // 2 : key fields name (if differ of rowid) |
4818 | 4818 | // 3 : key field parent (for dependent lists) |
4819 | 4819 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
4820 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
4820 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
4821 | 4821 | |
4822 | 4822 | if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { |
4823 | 4823 | list ($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
4824 | - $keyList .= ', ' . $parentField; |
|
4824 | + $keyList .= ', '.$parentField; |
|
4825 | 4825 | } |
4826 | 4826 | if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { |
4827 | 4827 | if (strpos($InfoFieldList[4], 'extra.') !== false) { |
4828 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
4828 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
4829 | 4829 | } else { |
4830 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
4830 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
4831 | 4831 | } |
4832 | 4832 | } |
4833 | 4833 | |
@@ -4838,8 +4838,8 @@ discard block |
||
4838 | 4838 | } |
4839 | 4839 | |
4840 | 4840 | $sqlwhere = ''; |
4841 | - $sql = 'SELECT ' . $keyList; |
|
4842 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
4841 | + $sql = 'SELECT '.$keyList; |
|
4842 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
4843 | 4843 | if (!empty($InfoFieldList[4])) { |
4844 | 4844 | |
4845 | 4845 | // can use SELECT request |
@@ -4856,23 +4856,23 @@ discard block |
||
4856 | 4856 | |
4857 | 4857 | // We have to join on extrafield table |
4858 | 4858 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
4859 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
4860 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
4859 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
4860 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
4861 | 4861 | } else { |
4862 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
4862 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
4863 | 4863 | } |
4864 | 4864 | } else { |
4865 | 4865 | $sqlwhere .= ' WHERE 1=1'; |
4866 | 4866 | } |
4867 | 4867 | // Some tables may have field, some other not. For the moment we disable it. |
4868 | 4868 | if (in_array($InfoFieldList[0], array('tablewithentity'))) { |
4869 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
4869 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
4870 | 4870 | } |
4871 | 4871 | // $sql.=preg_replace('/^ AND /','',$sqlwhere); |
4872 | 4872 | // print $sql; |
4873 | 4873 | |
4874 | 4874 | $sql .= $sqlwhere; |
4875 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst', LOG_DEBUG); |
|
4875 | + dol_syslog(get_class($this).'::showInputField type=chkbxlst', LOG_DEBUG); |
|
4876 | 4876 | $resql = $this->db->query($sql); |
4877 | 4877 | if ($resql) { |
4878 | 4878 | $num = $this->db->num_rows($resql); |
@@ -4890,7 +4890,7 @@ discard block |
||
4890 | 4890 | if (is_array($fields_label)) { |
4891 | 4891 | $notrans = true; |
4892 | 4892 | foreach ($fields_label as $field_toshow) { |
4893 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
4893 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
4894 | 4894 | } |
4895 | 4895 | } else { |
4896 | 4896 | $labeltoshow = $obj->{$InfoFieldList[1]}; |
@@ -4901,9 +4901,9 @@ discard block |
||
4901 | 4901 | foreach ($fields_label as $field_toshow) { |
4902 | 4902 | $translabel = $langs->trans($obj->$field_toshow); |
4903 | 4903 | if ($translabel != $obj->$field_toshow) { |
4904 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
4904 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
4905 | 4905 | } else { |
4906 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
4906 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
4907 | 4907 | } |
4908 | 4908 | } |
4909 | 4909 | |
@@ -4925,7 +4925,7 @@ discard block |
||
4925 | 4925 | } |
4926 | 4926 | |
4927 | 4927 | if (!empty($InfoFieldList[3]) && $parentField) { |
4928 | - $parent = $parentName . ':' . $obj->{$parentField}; |
|
4928 | + $parent = $parentName.':'.$obj->{$parentField}; |
|
4929 | 4929 | } |
4930 | 4930 | |
4931 | 4931 | $data[$obj->rowid] = $labeltoshow; |
@@ -4935,25 +4935,25 @@ discard block |
||
4935 | 4935 | } |
4936 | 4936 | $this->db->free($resql); |
4937 | 4937 | |
4938 | - $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
4938 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
4939 | 4939 | } else { |
4940 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
4940 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
4941 | 4941 | } |
4942 | 4942 | } |
4943 | 4943 | } elseif ($type == 'link') { |
4944 | - $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
4944 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
4945 | 4945 | $showempty = (($required && $default != '') ? 0 : 1); |
4946 | - $out = $form->selectForForms($param_list[0], $keyprefix . $key . $keysuffix, $value, $showempty); |
|
4946 | + $out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
4947 | 4947 | if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { |
4948 | 4948 | list($class, $classfile) = explode(':', $param_list[0]); |
4949 | - if (file_exists(dol_buildpath(dirname(dirname($classfile)) . '/card.php'))) $url_path = dol_buildpath(dirname(dirname($classfile)) . '/card.php', 1); |
|
4950 | - else $url_path = dol_buildpath(dirname(dirname($classfile)) . '/' . $class . '_card.php', 1); |
|
4951 | - $out .= '<a class="butActionNew" href="' . $url_path . '?action=create&backtopage=' . $_SERVER['PHP_SELF'] . '"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
4949 | + if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path = dol_buildpath(dirname(dirname($classfile)).'/card.php', 1); |
|
4950 | + else $url_path = dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php', 1); |
|
4951 | + $out .= '<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
4952 | 4952 | // TODO Add Javascript code to add input fields contents to new elements urls |
4953 | 4953 | } |
4954 | 4954 | } elseif ($type == 'password') { |
4955 | 4955 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
4956 | - $out = '<input type="' . ($keyprefix == 'search_' ? 'text' : 'password') . '" class="flat ' . $morecss . '" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ($moreparam ? $moreparam : '') . '>'; |
|
4956 | + $out = '<input type="'.($keyprefix == 'search_' ? 'text' : 'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>'; |
|
4957 | 4957 | } elseif ($type == 'array') { |
4958 | 4958 | $newval = $val; |
4959 | 4959 | $newval['type'] = 'varchar(256)'; |
@@ -4963,25 +4963,25 @@ discard block |
||
4963 | 4963 | $inputs = array(); |
4964 | 4964 | if (!empty($value)) { |
4965 | 4965 | foreach ($value as $option) { |
4966 | - $out .= '<span><a class="' . dol_escape_htmltag($keyprefix . $key . $keysuffix) . '_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
4967 | - $out .= $this->showInputField($newval, $keyprefix . $key . $keysuffix . '[]', $option, $moreparam, '', '', $showsize) . '<br></span>'; |
|
4966 | + $out .= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
4967 | + $out .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
4968 | 4968 | } |
4969 | 4969 | } |
4970 | 4970 | |
4971 | - $out .= '<a id="' . dol_escape_htmltag($keyprefix . $key . $keysuffix) . '_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
4971 | + $out .= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
4972 | 4972 | |
4973 | - $newInput = '<span><a class="' . dol_escape_htmltag($keyprefix . $key . $keysuffix) . '_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
4974 | - $newInput .= $this->showInputField($newval, $keyprefix . $key . $keysuffix . '[]', '', $moreparam, '', '', $showsize) . '<br></span>'; |
|
4973 | + $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
4974 | + $newInput .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
4975 | 4975 | |
4976 | 4976 | if (!empty($conf->use_javascript_ajax)) { |
4977 | 4977 | $out .= ' |
4978 | 4978 | <script type="text/javascript"> |
4979 | 4979 | $(document).ready(function() { |
4980 | - $("a#' . dol_escape_js($keyprefix . $key . $keysuffix) . '_add").click(function() { |
|
4981 | - $("' . dol_escape_js($newInput) . '").insertBefore(this); |
|
4980 | + $("a#' . dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() { |
|
4981 | + $("' . dol_escape_js($newInput).'").insertBefore(this); |
|
4982 | 4982 | }); |
4983 | 4983 | |
4984 | - $(document).on("click", "a.' . dol_escape_js($keyprefix . $key . $keysuffix) . '_del", function() { |
|
4984 | + $(document).on("click", "a.' . dol_escape_js($keyprefix.$key.$keysuffix).'_del", function() { |
|
4985 | 4985 | $(this).parent().remove(); |
4986 | 4986 | }); |
4987 | 4987 | }); |
@@ -4989,7 +4989,7 @@ discard block |
||
4989 | 4989 | } |
4990 | 4990 | } |
4991 | 4991 | if (!empty($hidden)) { |
4992 | - $out = '<input type="hidden" value="' . $value . '" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '"/>'; |
|
4992 | + $out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
4993 | 4993 | } |
4994 | 4994 | /* Add comments |
4995 | 4995 | if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
@@ -5016,7 +5016,7 @@ discard block |
||
5016 | 5016 | global $conf, $langs, $form; |
5017 | 5017 | |
5018 | 5018 | if (!is_object($form)) { |
5019 | - require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php'; |
|
5019 | + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
5020 | 5020 | $form = new Form($this->db); |
5021 | 5021 | } |
5022 | 5022 | |
@@ -5027,9 +5027,9 @@ discard block |
||
5027 | 5027 | |
5028 | 5028 | // Convert var to be able to share same code than showOutputField of extrafields |
5029 | 5029 | if (preg_match('/varchar\((\d+)\)/', $type, $reg)) { |
5030 | - $type = 'varchar'; // convert varchar(xx) int varchar |
|
5030 | + $type = 'varchar'; // convert varchar(xx) int varchar |
|
5031 | 5031 | $size = $reg[1]; |
5032 | - } elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
5032 | + } elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
5033 | 5033 | if (is_array($val['arrayofkeyval'])) $type = 'select'; |
5034 | 5034 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type = 'link'; |
5035 | 5035 | |
@@ -5041,12 +5041,12 @@ discard block |
||
5041 | 5041 | if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
5042 | 5042 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) { |
5043 | 5043 | $type = 'link'; |
5044 | - $param['options'] = array($reg[1] . ':' . $reg[2] => $reg[1] . ':' . $reg[2]); |
|
5044 | + $param['options'] = array($reg[1].':'.$reg[2] => $reg[1].':'.$reg[2]); |
|
5045 | 5045 | } |
5046 | 5046 | $langfile = $val['langfile']; |
5047 | 5047 | $list = $val['list']; |
5048 | 5048 | $help = $val['help']; |
5049 | - $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) |
|
5049 | + $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) |
|
5050 | 5050 | |
5051 | 5051 | if ($hidden) return ''; |
5052 | 5052 | |
@@ -5107,7 +5107,7 @@ discard block |
||
5107 | 5107 | if (!empty($value)) { |
5108 | 5108 | $checked = ' checked '; |
5109 | 5109 | } |
5110 | - $value = '<input type="checkbox" ' . $checked . ' ' . ($moreparam ? $moreparam : '') . ' readonly disabled>'; |
|
5110 | + $value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>'; |
|
5111 | 5111 | } elseif ($type == 'mail') { |
5112 | 5112 | $value = dol_print_email($value, 0, 0, 0, 64, 1, 1); |
5113 | 5113 | } elseif ($type == 'url') { |
@@ -5127,7 +5127,7 @@ discard block |
||
5127 | 5127 | |
5128 | 5128 | if (count($InfoFieldList) >= 3) { |
5129 | 5129 | $selectkey = $InfoFieldList[2]; |
5130 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
5130 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
5131 | 5131 | } |
5132 | 5132 | |
5133 | 5133 | $fields_label = explode('|', $InfoFieldList[1]); |
@@ -5136,25 +5136,25 @@ discard block |
||
5136 | 5136 | $keyList .= implode(', ', $fields_label); |
5137 | 5137 | } |
5138 | 5138 | |
5139 | - $sql = 'SELECT ' . $keyList; |
|
5140 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
5139 | + $sql = 'SELECT '.$keyList; |
|
5140 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
5141 | 5141 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
5142 | 5142 | $sql .= ' as main'; |
5143 | 5143 | } |
5144 | 5144 | if ($selectkey == 'rowid' && empty($value)) { |
5145 | - $sql .= " WHERE " . $selectkey . "=0"; |
|
5145 | + $sql .= " WHERE ".$selectkey."=0"; |
|
5146 | 5146 | } elseif ($selectkey == 'rowid') { |
5147 | - $sql .= " WHERE " . $selectkey . "=" . $this->db->escape($value); |
|
5147 | + $sql .= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
5148 | 5148 | } else { |
5149 | - $sql .= " WHERE " . $selectkey . "='" . $this->db->escape($value) . "'"; |
|
5149 | + $sql .= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
5150 | 5150 | } |
5151 | 5151 | |
5152 | 5152 | //$sql.= ' AND entity = '.$conf->entity; |
5153 | 5153 | |
5154 | - dol_syslog(get_class($this) . ':showOutputField:$type=sellist', LOG_DEBUG); |
|
5154 | + dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); |
|
5155 | 5155 | $resql = $this->db->query($sql); |
5156 | 5156 | if ($resql) { |
5157 | - $value = ''; // value was used, so now we reste it to use it to build final output |
|
5157 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
5158 | 5158 | |
5159 | 5159 | $obj = $this->db->fetch_object($resql); |
5160 | 5160 | |
@@ -5168,9 +5168,9 @@ discard block |
||
5168 | 5168 | $translabel = $langs->trans($obj->$field_toshow); |
5169 | 5169 | } |
5170 | 5170 | if ($translabel != $field_toshow) { |
5171 | - $value .= dol_trunc($translabel, 18) . ' '; |
|
5171 | + $value .= dol_trunc($translabel, 18).' '; |
|
5172 | 5172 | } else { |
5173 | - $value .= $obj->$field_toshow . ' '; |
|
5173 | + $value .= $obj->$field_toshow.' '; |
|
5174 | 5174 | } |
5175 | 5175 | } |
5176 | 5176 | } else { |
@@ -5184,7 +5184,7 @@ discard block |
||
5184 | 5184 | $value = $obj->{$InfoFieldList[1]}; |
5185 | 5185 | } |
5186 | 5186 | } |
5187 | - } else dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
5187 | + } else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
5188 | 5188 | } elseif ($type == 'radio') { |
5189 | 5189 | $value = $param['options'][$value]; |
5190 | 5190 | } elseif ($type == 'checkbox') { |
@@ -5192,9 +5192,9 @@ discard block |
||
5192 | 5192 | $value = ''; |
5193 | 5193 | if (is_array($value_arr) && count($value_arr) > 0) { |
5194 | 5194 | foreach ($value_arr as $keyval => $valueval) { |
5195 | - $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">' . $param['options'][$valueval] . '</li>'; |
|
5195 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
5196 | 5196 | } |
5197 | - $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>'; |
|
5197 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
5198 | 5198 | } |
5199 | 5199 | } elseif ($type == 'chkbxlst') { |
5200 | 5200 | $value_arr = explode(',', $value); |
@@ -5207,7 +5207,7 @@ discard block |
||
5207 | 5207 | |
5208 | 5208 | if (count($InfoFieldList) >= 3) { |
5209 | 5209 | $selectkey = $InfoFieldList[2]; |
5210 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
5210 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
5211 | 5211 | } |
5212 | 5212 | |
5213 | 5213 | $fields_label = explode('|', $InfoFieldList[1]); |
@@ -5216,15 +5216,15 @@ discard block |
||
5216 | 5216 | $keyList .= implode(', ', $fields_label); |
5217 | 5217 | } |
5218 | 5218 | |
5219 | - $sql = 'SELECT ' . $keyList; |
|
5220 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
5219 | + $sql = 'SELECT '.$keyList; |
|
5220 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
5221 | 5221 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
5222 | 5222 | $sql .= ' as main'; |
5223 | 5223 | } |
5224 | 5224 | // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
5225 | 5225 | // $sql.= ' AND entity = '.$conf->entity; |
5226 | 5226 | |
5227 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst', LOG_DEBUG); |
|
5227 | + dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); |
|
5228 | 5228 | $resql = $this->db->query($sql); |
5229 | 5229 | if ($resql) { |
5230 | 5230 | $value = ''; // value was used, so now we reste it to use it to build final output |
@@ -5241,9 +5241,9 @@ discard block |
||
5241 | 5241 | $translabel = $langs->trans($obj->$field_toshow); |
5242 | 5242 | } |
5243 | 5243 | if ($translabel != $field_toshow) { |
5244 | - $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">' . dol_trunc($translabel, 18) . '</li>'; |
|
5244 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
5245 | 5245 | } else { |
5246 | - $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">' . $obj->$field_toshow . '</li>'; |
|
5246 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
5247 | 5247 | } |
5248 | 5248 | } |
5249 | 5249 | } else { |
@@ -5252,23 +5252,23 @@ discard block |
||
5252 | 5252 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
5253 | 5253 | } |
5254 | 5254 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
5255 | - $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">' . dol_trunc($translabel, 18) . '</li>'; |
|
5255 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
5256 | 5256 | } else { |
5257 | - $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">' . $obj->{$InfoFieldList[1]} . '</li>'; |
|
5257 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
5258 | 5258 | } |
5259 | 5259 | } |
5260 | 5260 | } |
5261 | 5261 | } |
5262 | - $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>'; |
|
5262 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
5263 | 5263 | } else { |
5264 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
5264 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
5265 | 5265 | } |
5266 | 5266 | } elseif ($type == 'link') { |
5267 | 5267 | $out = ''; |
5268 | 5268 | |
5269 | 5269 | // only if something to display (perf) |
5270 | 5270 | if ($value) { |
5271 | - $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
5271 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
5272 | 5272 | |
5273 | 5273 | $InfoFieldList = explode(":", $param_list[0]); |
5274 | 5274 | $classname = $InfoFieldList[0]; |
@@ -5339,7 +5339,7 @@ discard block |
||
5339 | 5339 | $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
5340 | 5340 | } |
5341 | 5341 | |
5342 | - if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
5342 | + if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
5343 | 5343 | if (empty($perms)) continue; |
5344 | 5344 | |
5345 | 5345 | // Load language if required |
@@ -5354,12 +5354,12 @@ discard block |
||
5354 | 5354 | |
5355 | 5355 | switch ($mode) { |
5356 | 5356 | case "view": |
5357 | - $value = $this->array_options["options_" . $key . $keysuffix]; |
|
5357 | + $value = $this->array_options["options_".$key.$keysuffix]; |
|
5358 | 5358 | break; |
5359 | 5359 | case "edit": |
5360 | - $getposttemp = GETPOST($keyprefix . 'options_' . $key . $keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
5360 | + $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
5361 | 5361 | // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc') |
5362 | - if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix)) { |
|
5362 | + if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) { |
|
5363 | 5363 | if (is_array($getposttemp)) { |
5364 | 5364 | // $getposttemp is an array but following code expects a comma separated string |
5365 | 5365 | $value = implode(",", $getposttemp); |
@@ -5367,7 +5367,7 @@ discard block |
||
5367 | 5367 | $value = $getposttemp; |
5368 | 5368 | } |
5369 | 5369 | } else { |
5370 | - $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
5370 | + $value = $this->array_options["options_".$key]; // No GET, no POST, no default value, so we take value of object. |
|
5371 | 5371 | } |
5372 | 5372 | //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
5373 | 5373 | break; |
@@ -5386,12 +5386,12 @@ discard block |
||
5386 | 5386 | |
5387 | 5387 | // add html5 elements |
5388 | 5388 | $domData = ' data-element="extrafield"'; |
5389 | - $domData .= ' data-targetelement="' . $this->element . '"'; |
|
5390 | - $domData .= ' data-targetid="' . $this->id . '"'; |
|
5389 | + $domData .= ' data-targetelement="'.$this->element.'"'; |
|
5390 | + $domData .= ' data-targetid="'.$this->id.'"'; |
|
5391 | 5391 | |
5392 | - $html_id = !empty($this->id) ? 'extrarow-' . $this->element . '_' . $key . '_' . $this->id : ''; |
|
5392 | + $html_id = !empty($this->id) ? 'extrarow-'.$this->element.'_'.$key.'_'.$this->id : ''; |
|
5393 | 5393 | |
5394 | - $out .= '<tr id="' . $html_id . '" ' . $csstyle . ' class="' . $class . $this->element . '_extras_' . $key . '" ' . $domData . ' >'; |
|
5394 | + $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
|
5395 | 5395 | |
5396 | 5396 | if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { |
5397 | 5397 | if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { |
@@ -5405,16 +5405,16 @@ discard block |
||
5405 | 5405 | |
5406 | 5406 | // Convert date into timestamp format (value in memory must be a timestamp) |
5407 | 5407 | if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime'))) { |
5408 | - $datenotinstring = $this->array_options['options_' . $key]; |
|
5409 | - if (!is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
5408 | + $datenotinstring = $this->array_options['options_'.$key]; |
|
5409 | + if (!is_numeric($this->array_options['options_'.$key])) // For backward compatibility |
|
5410 | 5410 | { |
5411 | 5411 | $datenotinstring = $this->db->jdate($datenotinstring); |
5412 | 5412 | } |
5413 | - $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; |
|
5413 | + $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; |
|
5414 | 5414 | } |
5415 | 5415 | // Convert float submited string into real php numeric (value in memory must be a php numeric) |
5416 | 5416 | if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double'))) { |
5417 | - $value = GETPOSTISSET($keyprefix . 'options_' . $key . $keysuffix) ? price2num(GETPOST($keyprefix . 'options_' . $key . $keysuffix, 'alpha', 3)) : $this->array_options['options_' . $key]; |
|
5417 | + $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ? price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)) : $this->array_options['options_'.$key]; |
|
5418 | 5418 | } |
5419 | 5419 | |
5420 | 5420 | $labeltoshow = $langs->trans($label); |
@@ -5427,8 +5427,8 @@ discard block |
||
5427 | 5427 | else $out .= $labeltoshow; |
5428 | 5428 | $out .= '</td>'; |
5429 | 5429 | |
5430 | - $html_id = !empty($this->id) ? $this->element . '_extras_' . $key . '_' . $this->id : ''; |
|
5431 | - $out .= '<td id="' . $html_id . '" class="' . $this->element . '_extras_' . $key . '" ' . ($colspan ? ' colspan="' . $colspan . '"' : '') . '>'; |
|
5430 | + $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
|
5431 | + $out .= '<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan ? ' colspan="'.$colspan.'"' : '').'>'; |
|
5432 | 5432 | |
5433 | 5433 | switch ($mode) { |
5434 | 5434 | case "view": |
@@ -5478,7 +5478,7 @@ discard block |
||
5478 | 5478 | setListDependencies(); |
5479 | 5479 | }); |
5480 | 5480 | </script>' . "\n"; |
5481 | - $out .= '<!-- /showOptionalsInput --> ' . "\n"; |
|
5481 | + $out .= '<!-- /showOptionalsInput --> '."\n"; |
|
5482 | 5482 | } |
5483 | 5483 | } |
5484 | 5484 | return $out; |
@@ -5509,7 +5509,7 @@ discard block |
||
5509 | 5509 | // Get cost price for margin calculation |
5510 | 5510 | if (!empty($fk_product)) { |
5511 | 5511 | if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') { |
5512 | - require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; |
|
5512 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
5513 | 5513 | $product = new Product($this->db); |
5514 | 5514 | $result = $product->fetch($fk_product); |
5515 | 5515 | if ($result <= 0) { |
@@ -5522,7 +5522,7 @@ discard block |
||
5522 | 5522 | $buyPrice = $product->pmp; |
5523 | 5523 | } |
5524 | 5524 | } else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') { |
5525 | - require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; |
|
5525 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
5526 | 5526 | $product = new Product($this->db); |
5527 | 5527 | $result = $product->fetch($fk_product); |
5528 | 5528 | if ($result <= 0) { |
@@ -5535,7 +5535,7 @@ discard block |
||
5535 | 5535 | } |
5536 | 5536 | |
5537 | 5537 | if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1', 'pmp', 'costprice'))) { |
5538 | - require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php'; |
|
5538 | + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
5539 | 5539 | $productFournisseur = new ProductFournisseur($this->db); |
5540 | 5540 | if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) { |
5541 | 5541 | $buyPrice = $productFournisseur->fourn_unitprice; |
@@ -5571,40 +5571,40 @@ discard block |
||
5571 | 5571 | // phpcs:enable |
5572 | 5572 | global $conf, $user, $langs; |
5573 | 5573 | |
5574 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
|
5575 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php'; |
|
5574 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
5575 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
5576 | 5576 | |
5577 | 5577 | $sortfield = 'position_name'; |
5578 | 5578 | $sortorder = 'asc'; |
5579 | 5579 | |
5580 | - $dir = $sdir . '/'; |
|
5580 | + $dir = $sdir.'/'; |
|
5581 | 5581 | $pdir = '/'; |
5582 | 5582 | if ($modulepart == 'ticket') { |
5583 | - $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart) . $this->track_id . '/'; |
|
5584 | - $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart) . $this->track_id . '/'; |
|
5583 | + $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
5584 | + $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
5585 | 5585 | } else { |
5586 | - $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart) . $this->ref . '/'; |
|
5587 | - $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart) . $this->ref . '/'; |
|
5586 | + $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
5587 | + $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
5588 | 5588 | } |
5589 | 5589 | |
5590 | 5590 | // For backward compatibility |
5591 | 5591 | if ($modulepart == 'product' && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) { |
5592 | - $dir = $sdir . '/' . get_exdir($this->id, 2, 0, 0, $this, $modulepart) . $this->id . "/photos/"; |
|
5593 | - $pdir = '/' . get_exdir($this->id, 2, 0, 0, $this, $modulepart) . $this->id . "/photos/"; |
|
5592 | + $dir = $sdir.'/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; |
|
5593 | + $pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; |
|
5594 | 5594 | } |
5595 | 5595 | |
5596 | 5596 | // Defined relative dir to DOL_DATA_ROOT |
5597 | 5597 | $relativedir = ''; |
5598 | 5598 | if ($dir) { |
5599 | - $relativedir = preg_replace('/^' . preg_quote(DOL_DATA_ROOT, '/') . '/', '', $dir); |
|
5599 | + $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir); |
|
5600 | 5600 | $relativedir = preg_replace('/^[\\/]/', '', $relativedir); |
5601 | 5601 | $relativedir = preg_replace('/[\\/]$/', '', $relativedir); |
5602 | 5602 | } |
5603 | 5603 | |
5604 | - $dirthumb = $dir . 'thumbs/'; |
|
5605 | - $pdirthumb = $pdir . 'thumbs/'; |
|
5604 | + $dirthumb = $dir.'thumbs/'; |
|
5605 | + $pdirthumb = $pdir.'thumbs/'; |
|
5606 | 5606 | |
5607 | - $return = '<!-- Photo -->' . "\n"; |
|
5607 | + $return = '<!-- Photo -->'."\n"; |
|
5608 | 5608 | $nbphoto = 0; |
5609 | 5609 | |
5610 | 5610 | $filearray = dol_dir_list($dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1); |
@@ -5637,75 +5637,75 @@ discard block |
||
5637 | 5637 | if ($size == 1 || $size == 'small') { // Format vignette |
5638 | 5638 | |
5639 | 5639 | // Find name of thumb file |
5640 | - $photo_vignette = basename(getImageFileNameForSize($dir . $file, '_small')); |
|
5641 | - if (!dol_is_file($dirthumb . $photo_vignette)) $photo_vignette = ''; |
|
5640 | + $photo_vignette = basename(getImageFileNameForSize($dir.$file, '_small')); |
|
5641 | + if (!dol_is_file($dirthumb.$photo_vignette)) $photo_vignette = ''; |
|
5642 | 5642 | |
5643 | 5643 | // Get filesize of original file |
5644 | - $imgarray = dol_getImageSize($dir . $photo); |
|
5644 | + $imgarray = dol_getImageSize($dir.$photo); |
|
5645 | 5645 | |
5646 | 5646 | if ($nbbyrow > 0) { |
5647 | 5647 | if ($nbphoto == 1) $return .= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
5648 | 5648 | |
5649 | 5649 | if ($nbphoto % $nbbyrow == 1) $return .= '<tr align=center valign=middle border=1>'; |
5650 | - $return .= '<td width="' . ceil(100 / $nbbyrow) . '%" class="photo">'; |
|
5650 | + $return .= '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">'; |
|
5651 | 5651 | } else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
5652 | 5652 | |
5653 | 5653 | $return .= "\n"; |
5654 | 5654 | |
5655 | - $relativefile = preg_replace('/^\//', '', $pdir . $photo); |
|
5655 | + $relativefile = preg_replace('/^\//', '', $pdir.$photo); |
|
5656 | 5656 | if (empty($nolink)) { |
5657 | - $urladvanced = getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity=' . $this->entity); |
|
5658 | - if ($urladvanced) $return .= '<a href="' . $urladvanced . '">'; |
|
5659 | - else $return .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $this->entity . '&file=' . urlencode($pdir . $photo) . '" class="aphoto" target="_blank">'; |
|
5657 | + $urladvanced = getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
5658 | + if ($urladvanced) $return .= '<a href="'.$urladvanced.'">'; |
|
5659 | + else $return .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
5660 | 5660 | } |
5661 | 5661 | |
5662 | 5662 | // Show image (width height=$maxHeight) |
5663 | 5663 | // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
5664 | - $alt = $langs->transnoentitiesnoconv('File') . ': ' . $relativefile; |
|
5665 | - $alt .= ' - ' . $langs->transnoentitiesnoconv('Size') . ': ' . $imgarray['width'] . 'x' . $imgarray['height']; |
|
5664 | + $alt = $langs->transnoentitiesnoconv('File').': '.$relativefile; |
|
5665 | + $alt .= ' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; |
|
5666 | 5666 | if ($notitle) $alt = ''; |
5667 | 5667 | |
5668 | 5668 | if ($usesharelink) { |
5669 | 5669 | if ($val['share']) { |
5670 | 5670 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) { |
5671 | 5671 | $return .= '<!-- Show original file (thumb not yet available with shared links) -->'; |
5672 | - $return .= '<img class="photo photowithmargin" border="0" height="' . $maxHeight . '" src="' . DOL_URL_ROOT . '/viewimage.php?hashp=' . urlencode($val['share']) . '" title="' . dol_escape_htmltag($alt) . '">'; |
|
5672 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
5673 | 5673 | } else { |
5674 | 5674 | $return .= '<!-- Show original file -->'; |
5675 | - $return .= '<img class="photo photowithmargin" border="0" height="' . $maxHeight . '" src="' . DOL_URL_ROOT . '/viewimage.php?hashp=' . urlencode($val['share']) . '" title="' . dol_escape_htmltag($alt) . '">'; |
|
5675 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
5676 | 5676 | } |
5677 | 5677 | } else { |
5678 | 5678 | $return .= '<!-- Show nophoto file (because file is not shared) -->'; |
5679 | - $return .= '<img class="photo photowithmargin" border="0" height="' . $maxHeight . '" src="' . DOL_URL_ROOT . '/public/theme/common/nophoto.png" title="' . dol_escape_htmltag($alt) . '">'; |
|
5679 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
5680 | 5680 | } |
5681 | 5681 | } else { |
5682 | 5682 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) { |
5683 | 5683 | $return .= '<!-- Show thumb -->'; |
5684 | - $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) . '">'; |
|
5684 | + $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).'">'; |
|
5685 | 5685 | } else { |
5686 | 5686 | $return .= '<!-- Show original file -->'; |
5687 | - $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) . '">'; |
|
5687 | + $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).'">'; |
|
5688 | 5688 | } |
5689 | 5689 | } |
5690 | 5690 | |
5691 | 5691 | if (empty($nolink)) $return .= '</a>'; |
5692 | 5692 | $return .= "\n"; |
5693 | 5693 | |
5694 | - if ($showfilename) $return .= '<br>' . $viewfilename; |
|
5694 | + if ($showfilename) $return .= '<br>'.$viewfilename; |
|
5695 | 5695 | if ($showaction) { |
5696 | 5696 | $return .= '<br>'; |
5697 | 5697 | // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
5698 | 5698 | if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) { |
5699 | - $return .= '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $this->id . '&action=addthumb&file=' . urlencode($pdir . $viewfilename) . '">' . img_picto($langs->trans('GenerateThumb'), 'refresh') . ' </a>'; |
|
5699 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').' </a>'; |
|
5700 | 5700 | } |
5701 | 5701 | // Special cas for product |
5702 | 5702 | if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) { |
5703 | 5703 | // Link to resize |
5704 | - $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> '; |
|
5704 | + $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> '; |
|
5705 | 5705 | |
5706 | 5706 | // Link to delete |
5707 | - $return .= '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $this->id . '&action=delete&file=' . urlencode($pdir . $viewfilename) . '">'; |
|
5708 | - $return .= img_delete() . '</a>'; |
|
5707 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
5708 | + $return .= img_delete().'</a>'; |
|
5709 | 5709 | } |
5710 | 5710 | } |
5711 | 5711 | $return .= "\n"; |
@@ -5717,18 +5717,18 @@ discard block |
||
5717 | 5717 | } |
5718 | 5718 | |
5719 | 5719 | if (empty($size)) { // Format origine |
5720 | - $return .= '<img class="photo photowithmargin" border="0" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $this->entity . '&file=' . urlencode($pdir . $photo) . '">'; |
|
5720 | + $return .= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
5721 | 5721 | |
5722 | - if ($showfilename) $return .= '<br>' . $viewfilename; |
|
5722 | + if ($showfilename) $return .= '<br>'.$viewfilename; |
|
5723 | 5723 | if ($showaction) { |
5724 | 5724 | // Special case for product |
5725 | 5725 | if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) { |
5726 | 5726 | // Link to resize |
5727 | - $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> '; |
|
5727 | + $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> '; |
|
5728 | 5728 | |
5729 | 5729 | // Link to delete |
5730 | - $return .= '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $this->id . '&action=delete&file=' . urlencode($pdir . $viewfilename) . '">'; |
|
5731 | - $return .= img_delete() . '</a>'; |
|
5730 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
5731 | + $return .= img_delete().'</a>'; |
|
5732 | 5732 | } |
5733 | 5733 | } |
5734 | 5734 | } |
@@ -5742,7 +5742,7 @@ discard block |
||
5742 | 5742 | if ($nbbyrow > 0) { |
5743 | 5743 | // Ferme tableau |
5744 | 5744 | while ($nbphoto % $nbbyrow) { |
5745 | - $return .= '<td width="' . ceil(100 / $nbbyrow) . '%"> </td>'; |
|
5745 | + $return .= '<td width="'.ceil(100 / $nbbyrow).'%"> </td>'; |
|
5746 | 5746 | $nbphoto++; |
5747 | 5747 | } |
5748 | 5748 | |
@@ -5788,7 +5788,7 @@ discard block |
||
5788 | 5788 | $fieldvalues = $this->setSaveQuery(); |
5789 | 5789 | if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation'] = $this->db->idate($now); |
5790 | 5790 | if (array_key_exists('fk_user_creat', $fieldvalues) && !($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat'] = $user->id; |
5791 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
5791 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
5792 | 5792 | |
5793 | 5793 | $keys = array(); |
5794 | 5794 | $values = array(); |
@@ -5820,9 +5820,9 @@ discard block |
||
5820 | 5820 | $this->db->begin(); |
5821 | 5821 | |
5822 | 5822 | if (!$error) { |
5823 | - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element; |
|
5824 | - $sql .= ' (' . implode(", ", $keys) . ')'; |
|
5825 | - $sql .= ' VALUES (' . implode(", ", $values) . ')'; |
|
5823 | + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
|
5824 | + $sql .= ' ('.implode(", ", $keys).')'; |
|
5825 | + $sql .= ' VALUES ('.implode(", ", $values).')'; |
|
5826 | 5826 | |
5827 | 5827 | $res = $this->db->query($sql); |
5828 | 5828 | if ($res === false) { |
@@ -5832,7 +5832,7 @@ discard block |
||
5832 | 5832 | } |
5833 | 5833 | |
5834 | 5834 | if (!$error) { |
5835 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
5835 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
5836 | 5836 | } |
5837 | 5837 | |
5838 | 5838 | // Create extrafields |
@@ -5844,7 +5844,7 @@ discard block |
||
5844 | 5844 | // Triggers |
5845 | 5845 | if (!$error && !$notrigger) { |
5846 | 5846 | // Call triggers |
5847 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_CREATE', $user); |
|
5847 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_CREATE', $user); |
|
5848 | 5848 | if ($result < 0) { |
5849 | 5849 | $error++; |
5850 | 5850 | } |
@@ -5893,11 +5893,11 @@ discard block |
||
5893 | 5893 | } else if ($this->isInt($info)) { |
5894 | 5894 | if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field] = $conf->entity; |
5895 | 5895 | else { |
5896 | - $queryarray[$field] = (int)price2num($this->{$field}); |
|
5897 | - if (empty($queryarray[$field])) $queryarray[$field] = 0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
5896 | + $queryarray[$field] = (int) price2num($this->{$field}); |
|
5897 | + if (empty($queryarray[$field])) $queryarray[$field] = 0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
5898 | 5898 | } |
5899 | 5899 | } else if ($this->isFloat($info)) { |
5900 | - $queryarray[$field] = (double)price2num($this->{$field}); |
|
5900 | + $queryarray[$field] = (double) price2num($this->{$field}); |
|
5901 | 5901 | if (empty($queryarray[$field])) $queryarray[$field] = 0; |
5902 | 5902 | } else { |
5903 | 5903 | $queryarray[$field] = $this->{$field}; |
@@ -5928,12 +5928,12 @@ discard block |
||
5928 | 5928 | |
5929 | 5929 | $error = 0; |
5930 | 5930 | |
5931 | - if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
5931 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
5932 | 5932 | |
5933 | 5933 | if (!empty($this->array_options)) { |
5934 | 5934 | // Check parameters |
5935 | 5935 | $langs->load('admin'); |
5936 | - require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
5936 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
5937 | 5937 | $extrafields = new ExtraFields($this->db); |
5938 | 5938 | $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
5939 | 5939 | |
@@ -5943,11 +5943,11 @@ discard block |
||
5943 | 5943 | if (in_array(substr($key, 8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
5944 | 5944 | $new_array_options[$key] = $value; |
5945 | 5945 | elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
5946 | - $new_array_options['options_' . $key] = $value; |
|
5946 | + $new_array_options['options_'.$key] = $value; |
|
5947 | 5947 | } |
5948 | 5948 | |
5949 | 5949 | foreach ($new_array_options as $key => $value) { |
5950 | - $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
5950 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
5951 | 5951 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
5952 | 5952 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
5953 | 5953 | $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
@@ -5979,7 +5979,7 @@ discard block |
||
5979 | 5979 | case 'double': |
5980 | 5980 | $value = price2num($value); |
5981 | 5981 | if (!is_numeric($value) && $value != '') { |
5982 | - dol_syslog($langs->trans("ExtraFieldHasWrongValue") . " sur " . $attributeLabel . "(" . $value . "is not '" . $attributeType . "')", LOG_DEBUG); |
|
5982 | + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
|
5983 | 5983 | $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
5984 | 5984 | return -1; |
5985 | 5985 | } elseif ($value == '') { |
@@ -6009,14 +6009,14 @@ discard block |
||
6009 | 6009 | //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
6010 | 6010 | 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. |
6011 | 6011 | { |
6012 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
6012 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
6013 | 6013 | } else { |
6014 | 6014 | // var_dump($algo); |
6015 | 6015 | $newvalue = dol_hash($this->array_options[$key], $algo); |
6016 | 6016 | $new_array_options[$key] = $newvalue; |
6017 | 6017 | } |
6018 | 6018 | } else { |
6019 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
6019 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
6020 | 6020 | } |
6021 | 6021 | } |
6022 | 6022 | } else // Common usage |
@@ -6054,7 +6054,7 @@ discard block |
||
6054 | 6054 | |
6055 | 6055 | if ($res > 0) $new_array_options[$key] = $object->id; |
6056 | 6056 | else { |
6057 | - $this->error = "Id/Ref '" . $value . "' for object '" . $object->element . "' not found"; |
|
6057 | + $this->error = "Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
6058 | 6058 | $this->db->rollback(); |
6059 | 6059 | return -1; |
6060 | 6060 | } |
@@ -6071,26 +6071,26 @@ discard block |
||
6071 | 6071 | $table_element = $this->table_element; |
6072 | 6072 | if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
6073 | 6073 | |
6074 | - $sql_del = "DELETE FROM " . MAIN_DB_PREFIX . $table_element . "_extrafields WHERE fk_object = " . $this->id; |
|
6075 | - dol_syslog(get_class($this) . "::insertExtraFields delete", LOG_DEBUG); |
|
6074 | + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
6075 | + dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
|
6076 | 6076 | $this->db->query($sql_del); |
6077 | 6077 | |
6078 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . $table_element . "_extrafields (fk_object"; |
|
6078 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
|
6079 | 6079 | foreach ($new_array_options as $key => $value) { |
6080 | - $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
6080 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
6081 | 6081 | // Add field of attribut |
6082 | 6082 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
6083 | - $sql .= "," . $attributeKey; |
|
6083 | + $sql .= ",".$attributeKey; |
|
6084 | 6084 | } |
6085 | - $sql .= ") VALUES (" . $this->id; |
|
6085 | + $sql .= ") VALUES (".$this->id; |
|
6086 | 6086 | |
6087 | 6087 | foreach ($new_array_options as $key => $value) { |
6088 | - $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
6088 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
6089 | 6089 | // Add field of attribute |
6090 | 6090 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
6091 | 6091 | { |
6092 | 6092 | if ($new_array_options[$key] != '') { |
6093 | - $sql .= ",'" . $this->db->escape($new_array_options[$key]) . "'"; |
|
6093 | + $sql .= ",'".$this->db->escape($new_array_options[$key])."'"; |
|
6094 | 6094 | } else { |
6095 | 6095 | $sql .= ",null"; |
6096 | 6096 | } |
@@ -6098,7 +6098,7 @@ discard block |
||
6098 | 6098 | } |
6099 | 6099 | $sql .= ")"; |
6100 | 6100 | |
6101 | - dol_syslog(get_class($this) . "::insertExtraFields insert", LOG_DEBUG); |
|
6101 | + dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
|
6102 | 6102 | $resql = $this->db->query($sql); |
6103 | 6103 | if (!$resql) { |
6104 | 6104 | $this->error = $this->db->lasterror(); |
@@ -6141,7 +6141,7 @@ discard block |
||
6141 | 6141 | $fieldvalues = $this->setSaveQuery(); |
6142 | 6142 | if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification'] = $this->db->idate($now); |
6143 | 6143 | if (array_key_exists('fk_user_modif', $fieldvalues) && !($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif'] = $user->id; |
6144 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
6144 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
6145 | 6145 | |
6146 | 6146 | $keys = array(); |
6147 | 6147 | $values = array(); |
@@ -6149,13 +6149,13 @@ discard block |
||
6149 | 6149 | $keys[$k] = $k; |
6150 | 6150 | $value = $this->fields[$k]; |
6151 | 6151 | $values[$k] = $this->quote($v, $value); |
6152 | - $tmp[] = $k . '=' . $this->quote($v, $this->fields[$k]); |
|
6152 | + $tmp[] = $k.'='.$this->quote($v, $this->fields[$k]); |
|
6153 | 6153 | } |
6154 | 6154 | |
6155 | 6155 | // Clean and check mandatory |
6156 | 6156 | foreach ($keys as $key) { |
6157 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; // This is an implicit foreign key field |
|
6158 | - if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = ''; // This is an explicit foreign key field |
|
6157 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; // This is an implicit foreign key field |
|
6158 | + if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = ''; // This is an explicit foreign key field |
|
6159 | 6159 | |
6160 | 6160 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
6161 | 6161 | /* |
@@ -6166,7 +6166,7 @@ discard block |
||
6166 | 6166 | }*/ |
6167 | 6167 | } |
6168 | 6168 | |
6169 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET ' . implode(',', $tmp) . ' WHERE rowid=' . $this->id; |
|
6169 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode(',', $tmp).' WHERE rowid='.$this->id; |
|
6170 | 6170 | |
6171 | 6171 | $this->db->begin(); |
6172 | 6172 | if (!$error) { |
@@ -6188,7 +6188,7 @@ discard block |
||
6188 | 6188 | // Triggers |
6189 | 6189 | if (!$error && !$notrigger) { |
6190 | 6190 | // Call triggers |
6191 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $user); |
|
6191 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $user); |
|
6192 | 6192 | if ($result < 0) { |
6193 | 6193 | $error++; |
6194 | 6194 | } //Do also here what you must do to rollback action if trigger fail |
@@ -6221,7 +6221,7 @@ discard block |
||
6221 | 6221 | |
6222 | 6222 | if ($forcechilddeletion) { |
6223 | 6223 | foreach ($this->childtables as $table) { |
6224 | - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $table . ' WHERE ' . $this->fk_element . ' = ' . $this->id; |
|
6224 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
|
6225 | 6225 | $resql = $this->db->query($sql); |
6226 | 6226 | if (!$resql) { |
6227 | 6227 | $this->error = $this->db->lasterror(); |
@@ -6234,7 +6234,7 @@ discard block |
||
6234 | 6234 | { |
6235 | 6235 | $objectisused = $this->isObjectUsed($this->id); |
6236 | 6236 | if (!empty($objectisused)) { |
6237 | - dol_syslog(get_class($this) . "::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
|
6237 | + dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
|
6238 | 6238 | $this->error = 'ErrorRecordHasChildren'; |
6239 | 6239 | $this->errors[] = $this->error; |
6240 | 6240 | $this->db->rollback(); |
@@ -6245,7 +6245,7 @@ discard block |
||
6245 | 6245 | if (!$error) { |
6246 | 6246 | if (!$notrigger) { |
6247 | 6247 | // Call triggers |
6248 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_DELETE', $user); |
|
6248 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
6249 | 6249 | if ($result < 0) { |
6250 | 6250 | $error++; |
6251 | 6251 | } // Do also here what you must do to rollback action if trigger fail |
@@ -6254,8 +6254,8 @@ discard block |
||
6254 | 6254 | } |
6255 | 6255 | |
6256 | 6256 | if (!$error && !empty($this->isextrafieldmanaged)) { |
6257 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element . "_extrafields"; |
|
6258 | - $sql .= " WHERE fk_object=" . $this->id; |
|
6257 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; |
|
6258 | + $sql .= " WHERE fk_object=".$this->id; |
|
6259 | 6259 | |
6260 | 6260 | $resql = $this->db->query($sql); |
6261 | 6261 | if (!$resql) { |
@@ -6265,7 +6265,7 @@ discard block |
||
6265 | 6265 | } |
6266 | 6266 | |
6267 | 6267 | if (!$error) { |
6268 | - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . ' WHERE rowid=' . $this->id; |
|
6268 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
|
6269 | 6269 | |
6270 | 6270 | $res = $this->db->query($sql); |
6271 | 6271 | if ($res === false) { |
@@ -6315,8 +6315,8 @@ discard block |
||
6315 | 6315 | foreach ($arraytoscan as $table => $elementname) { |
6316 | 6316 | //print $id.'-'.$table.'-'.$elementname.'<br>'; |
6317 | 6317 | // Check if third party can be deleted |
6318 | - $sql = "SELECT COUNT(*) as nb from " . MAIN_DB_PREFIX . $table; |
|
6319 | - $sql .= " WHERE " . $this->fk_element . " = " . $id; |
|
6318 | + $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
|
6319 | + $sql .= " WHERE ".$this->fk_element." = ".$id; |
|
6320 | 6320 | $resql = $this->db->query($sql); |
6321 | 6321 | if ($resql) { |
6322 | 6322 | $obj = $this->db->fetch_object($resql); |
@@ -6331,7 +6331,7 @@ discard block |
||
6331 | 6331 | { |
6332 | 6332 | $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
6333 | 6333 | } |
6334 | - break; // We found at least one, we stop here |
|
6334 | + break; // We found at least one, we stop here |
|
6335 | 6335 | } |
6336 | 6336 | } else { |
6337 | 6337 | $this->errors[] = $this->db->lasterror(); |
@@ -6363,7 +6363,7 @@ discard block |
||
6363 | 6363 | */ |
6364 | 6364 | public function fetchComments() |
6365 | 6365 | { |
6366 | - require_once DOL_DOCUMENT_ROOT . '/core/class/comment.class.php'; |
|
6366 | + require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
|
6367 | 6367 | |
6368 | 6368 | $comment = new Comment($this->db); |
6369 | 6369 | $result = $comment->fetchAllFor($this->element, $this->id); |
@@ -6445,14 +6445,14 @@ discard block |
||
6445 | 6445 | if (is_array($conf->modules_parts['models'])) $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); |
6446 | 6446 | foreach ($dirmodels as $reldir) { |
6447 | 6447 | foreach (array('doc', 'pdf') as $prefix) { |
6448 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix . "_" . $modele . ".class.php"; // Member module use prefix_module.class.php |
|
6449 | - else $file = $prefix . "_" . $modele . ".modules.php"; |
|
6448 | + if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
6449 | + else $file = $prefix."_".$modele.".modules.php"; |
|
6450 | 6450 | |
6451 | 6451 | // On verifie l'emplacement du modele |
6452 | - $file = dol_buildpath($reldir . $modelspath . $file, 0); |
|
6452 | + $file = dol_buildpath($reldir.$modelspath.$file, 0); |
|
6453 | 6453 | if (file_exists($file)) { |
6454 | 6454 | $filefound = 1; |
6455 | - $classname = $prefix . '_' . $modele; |
|
6455 | + $classname = $prefix.'_'.$modele; |
|
6456 | 6456 | break; |
6457 | 6457 | } |
6458 | 6458 | } |
@@ -6461,7 +6461,7 @@ discard block |
||
6461 | 6461 | |
6462 | 6462 | // If generator was found |
6463 | 6463 | if ($filefound) { |
6464 | - global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
6464 | + global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
6465 | 6465 | |
6466 | 6466 | require_once $file; |
6467 | 6467 | |
@@ -6516,7 +6516,7 @@ discard block |
||
6516 | 6516 | $sav_charset_output = $outputlangs->charset_output; |
6517 | 6517 | |
6518 | 6518 | if (in_array(get_class($this), array('Adherent'))) { |
6519 | - $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
6519 | + $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
6520 | 6520 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
6521 | 6521 | } else { |
6522 | 6522 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
@@ -6527,7 +6527,7 @@ discard block |
||
6527 | 6527 | $outputlangs->charset_output = $sav_charset_output; |
6528 | 6528 | |
6529 | 6529 | // We delete old preview |
6530 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
|
6530 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
6531 | 6531 | dol_delete_preview($this); |
6532 | 6532 | |
6533 | 6533 | // Index file in database |
@@ -6535,7 +6535,7 @@ discard block |
||
6535 | 6535 | $destfull = $obj->result['fullpath']; |
6536 | 6536 | $upload_dir = dirname($destfull); |
6537 | 6537 | $destfile = basename($destfull); |
6538 | - $rel_dir = preg_replace('/^' . preg_quote(DOL_DATA_ROOT, '/') . '/', '', $upload_dir); |
|
6538 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir); |
|
6539 | 6539 | |
6540 | 6540 | if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
6541 | 6541 | { |
@@ -6543,14 +6543,14 @@ discard block |
||
6543 | 6543 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
6544 | 6544 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
6545 | 6545 | |
6546 | - include_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmfiles.class.php'; |
|
6546 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
6547 | 6547 | $ecmfile = new EcmFiles($this->db); |
6548 | - $result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir . '/' : '') . $filename); |
|
6548 | + $result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir.'/' : '').$filename); |
|
6549 | 6549 | |
6550 | 6550 | // Set the public "share" key |
6551 | 6551 | $setsharekey = false; |
6552 | 6552 | if ($this->element == 'propal') { |
6553 | - $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
6553 | + $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
6554 | 6554 | if ($useonlinesignature) $setsharekey = true; |
6555 | 6555 | if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
6556 | 6556 | } |
@@ -6561,17 +6561,17 @@ discard block |
||
6561 | 6561 | if ($setsharekey) { |
6562 | 6562 | if (empty($ecmfile->share)) // Because object not found or share not set yet |
6563 | 6563 | { |
6564 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; |
|
6564 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
6565 | 6565 | $ecmfile->share = getRandomPassword(true); |
6566 | 6566 | } |
6567 | 6567 | } |
6568 | 6568 | |
6569 | 6569 | if ($result > 0) { |
6570 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
6570 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
6571 | 6571 | $ecmfile->fullpath_orig = ''; |
6572 | 6572 | $ecmfile->gen_or_uploaded = 'generated'; |
6573 | - $ecmfile->description = ''; // indexed content |
|
6574 | - $ecmfile->keyword = ''; // keyword content |
|
6573 | + $ecmfile->description = ''; // indexed content |
|
6574 | + $ecmfile->keyword = ''; // keyword content |
|
6575 | 6575 | $result = $ecmfile->update($user); |
6576 | 6576 | if ($result < 0) { |
6577 | 6577 | setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
@@ -6580,11 +6580,11 @@ discard block |
||
6580 | 6580 | $ecmfile->entity = $conf->entity; |
6581 | 6581 | $ecmfile->filepath = $rel_dir; |
6582 | 6582 | $ecmfile->filename = $filename; |
6583 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
6583 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
6584 | 6584 | $ecmfile->fullpath_orig = ''; |
6585 | 6585 | $ecmfile->gen_or_uploaded = 'generated'; |
6586 | - $ecmfile->description = ''; // indexed content |
|
6587 | - $ecmfile->keyword = ''; // keyword content |
|
6586 | + $ecmfile->description = ''; // indexed content |
|
6587 | + $ecmfile->keyword = ''; // keyword content |
|
6588 | 6588 | $ecmfile->src_object_type = $this->table_element; |
6589 | 6589 | $ecmfile->src_object_id = $this->id; |
6590 | 6590 | |
@@ -6603,14 +6603,14 @@ discard block |
||
6603 | 6603 | $update_main_doc_field = 0; |
6604 | 6604 | if (!empty($obj->update_main_doc_field)) $update_main_doc_field = 1; |
6605 | 6605 | if ($update_main_doc_field && !empty($this->table_element)) { |
6606 | - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . " SET last_main_doc = '" . ($ecmfile->filepath . '/' . $ecmfile->filename) . "'"; |
|
6607 | - $sql .= ' WHERE rowid = ' . $this->id; |
|
6606 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
|
6607 | + $sql .= ' WHERE rowid = '.$this->id; |
|
6608 | 6608 | $resql = $this->db->query($sql); |
6609 | 6609 | if (!$resql) dol_print_error($this->db); |
6610 | 6610 | } |
6611 | 6611 | } |
6612 | 6612 | } else { |
6613 | - dol_syslog('Method ->write_file was called on object ' . get_class($obj) . ' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING); |
|
6613 | + dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING); |
|
6614 | 6614 | } |
6615 | 6615 | |
6616 | 6616 | // Success in building document. We build meta file. |
@@ -6619,11 +6619,11 @@ discard block |
||
6619 | 6619 | return 1; |
6620 | 6620 | } else { |
6621 | 6621 | $outputlangs->charset_output = $sav_charset_output; |
6622 | - dol_print_error($this->db, "Error generating document for " . __CLASS__ . ". Error: " . $obj->error, $obj->errors); |
|
6622 | + dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
|
6623 | 6623 | return -1; |
6624 | 6624 | } |
6625 | 6625 | } else { |
6626 | - $this->error = $langs->trans("Error") . " " . $langs->trans("ErrorFileDoesNotExists", $file); |
|
6626 | + $this->error = $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file); |
|
6627 | 6627 | dol_print_error('', $this->error); |
6628 | 6628 | return -1; |
6629 | 6629 | } |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | class Translate |
12 | 12 | { |
13 | 13 | |
14 | - public $dir; // Directories that contains /langs subdirectory |
|
15 | - public $defaultlang; // Current language for current user |
|
16 | - public $charset_output = 'UTF-8'; // Codage used by "trans" method outputs |
|
17 | - public $tab_translate = array(); // Array of all translations key=>value |
|
18 | - public $cache_labels = array(); // Array to store result after loading each language file |
|
19 | - public $cache_currencies = array(); // Cache for labels return by getLabelFromKey method |
|
20 | - private $_tab_loaded = array(); // Cache to store currency symbols |
|
14 | + public $dir; // Directories that contains /langs subdirectory |
|
15 | + public $defaultlang; // Current language for current user |
|
16 | + public $charset_output = 'UTF-8'; // Codage used by "trans" method outputs |
|
17 | + public $tab_translate = array(); // Array of all translations key=>value |
|
18 | + public $cache_labels = array(); // Array to store result after loading each language file |
|
19 | + public $cache_currencies = array(); // Cache for labels return by getLabelFromKey method |
|
20 | + private $_tab_loaded = array(); // Cache to store currency symbols |
|
21 | 21 | private $cache_currencies_all_loaded = false; |
22 | 22 | |
23 | 23 | /** |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | $more = array(); |
70 | 70 | $i = 0; |
71 | 71 | foreach ($conf->file->dol_document_root as $dir) { |
72 | - $newdir = $dir . $conf->global->MAIN_FORCELANGDIR; // For example $conf->global->MAIN_FORCELANGDIR is '/mymodule' meaning we search files into '/mymodule/langs/xx_XX' |
|
72 | + $newdir = $dir.$conf->global->MAIN_FORCELANGDIR; // For example $conf->global->MAIN_FORCELANGDIR is '/mymodule' meaning we search files into '/mymodule/langs/xx_XX' |
|
73 | 73 | if (!in_array($newdir, $this->dir)) { |
74 | - $more['module_' . $i] = $newdir; |
|
75 | - $i++; // We add the forced dir into the array $more. Just after, we add entries into $more to list of lang dir $this->dir. |
|
74 | + $more['module_'.$i] = $newdir; |
|
75 | + $i++; // We add the forced dir into the array $more. Just after, we add entries into $more to list of lang dir $this->dir. |
|
76 | 76 | } |
77 | 77 | } |
78 | - $this->dir = array_merge($more, $this->dir); // Forced dir ($more) are before standard dirs ($this->dir) |
|
78 | + $this->dir = array_merge($more, $this->dir); // Forced dir ($more) are before standard dirs ($this->dir) |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | $this->origlang = $srclang; |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep)) |
100 | 100 | $srclang = $longforshort[strtolower($langpart[0])]; |
101 | 101 | else if (!is_numeric($langpart[1])) { // Second part YY may be a numeric with some Chrome browser |
102 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[1]); |
|
102 | + $srclang = strtolower($langpart[0])."_".strtoupper($langpart[1]); |
|
103 | 103 | $longforlong = array('no_nb' => 'nb_NO'); |
104 | 104 | if (isset($longforlong[strtolower($srclang)])) |
105 | 105 | $srclang = $longforlong[strtolower($srclang)]; |
106 | 106 | } else |
107 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
107 | + $srclang = strtolower($langpart[0])."_".strtoupper($langpart[0]); |
|
108 | 108 | } else { // If it's for a codetouse that is a short code xx |
109 | 109 | // Array to convert short lang code into long code. |
110 | 110 | $longforshort = array('ar' => 'ar_SA', 'el' => 'el_GR', 'ca' => 'ca_ES', 'en' => 'en_US', 'nb' => 'nb_NO', 'no' => 'nb_NO'); |
111 | 111 | if (isset($longforshort[strtolower($langpart[0])])) |
112 | 112 | $srclang = $longforshort[strtolower($langpart[0])]; |
113 | 113 | else if (!empty($langpart[0])) |
114 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
114 | + $srclang = strtolower($langpart[0])."_".strtoupper($langpart[0]); |
|
115 | 115 | else |
116 | 116 | $srclang = 'en_US'; |
117 | 117 | } |
@@ -160,16 +160,16 @@ discard block |
||
160 | 160 | //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang); |
161 | 161 | // Check parameters |
162 | 162 | if (empty($domain)) { |
163 | - dol_print_error('', get_class($this) . "::Load ErrorWrongParameters"); |
|
163 | + dol_print_error('', get_class($this)."::Load ErrorWrongParameters"); |
|
164 | 164 | return -1; |
165 | 165 | } |
166 | 166 | if ($this->defaultlang == 'none_NONE') |
167 | - return 0; // Special language code to not translate keys |
|
167 | + return 0; // Special language code to not translate keys |
|
168 | 168 | |
169 | 169 | |
170 | 170 | // Load $this->tab_translate[] from database |
171 | 171 | if (empty($loadfromfileonly) && count($this->tab_translate) == 0) |
172 | - $this->loadFromDatabase($db); // No translation was never loaded yet, so we load database. |
|
172 | + $this->loadFromDatabase($db); // No translation was never loaded yet, so we load database. |
|
173 | 173 | |
174 | 174 | |
175 | 175 | $newdomain = $domain; |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | $alt = 2; |
199 | 199 | |
200 | 200 | if (empty($langofdir)) { // This may occurs when load is called without setting the language and without providing a value for forcelangdir |
201 | - dol_syslog("Error: " . get_class($this) . "::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING); |
|
201 | + dol_syslog("Error: ".get_class($this)."::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING); |
|
202 | 202 | return -1; |
203 | 203 | } |
204 | 204 | |
205 | 205 | foreach ($this->dir as $keydir => $searchdir) { |
206 | 206 | // Directory of translation files |
207 | - $file_lang = $searchdir . ($modulename ? '/' . $modulename : '') . "/langs/" . $langofdir . "/" . $newdomain . ".lang"; |
|
207 | + $file_lang = $searchdir.($modulename ? '/'.$modulename : '')."/langs/".$langofdir."/".$newdomain.".lang"; |
|
208 | 208 | $file_lang_osencoded = AlDolUtils::dol_osencode($file_lang); |
209 | 209 | |
210 | 210 | $filelangexists = is_file($file_lang_osencoded); |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | $usecachekey = ''; |
221 | 221 | // Using a memcached server |
222 | 222 | if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) { |
223 | - $usecachekey = $newdomain . '_' . $langofdir . '_' . md5($file_lang); // Should not contains special chars |
|
223 | + $usecachekey = $newdomain.'_'.$langofdir.'_'.md5($file_lang); // Should not contains special chars |
|
224 | 224 | } // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) |
225 | 225 | else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { |
226 | 226 | $usecachekey = $newdomain; |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | //dol_syslog('Translate::Load we will cache result into usecachekey '.$usecachekey); |
231 | 231 | //global $aaa; $aaa+=1; |
232 | 232 | //print $aaa." ".$usecachekey."\n"; |
233 | - require_once DOL_BASE_PATH . '/core/lib/memory.lib.php'; |
|
233 | + require_once DOL_BASE_PATH.'/core/lib/memory.lib.php'; |
|
234 | 234 | $tmparray = dol_getcache($usecachekey); |
235 | 235 | if (is_array($tmparray) && count($tmparray)) { |
236 | 236 | $this->tab_translate += $tmparray; // Faster than array_merge($tmparray,$this->tab_translate). Note: If a value already exists into tab_translate, value into tmparaay is not added. |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | //var_dump($this->tab_translate); |
239 | 239 | if ($alt == 2) |
240 | 240 | $fileread = 1; |
241 | - $found = true; // Found in dolibarr PHP cache |
|
241 | + $found = true; // Found in dolibarr PHP cache |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
@@ -288,13 +288,13 @@ discard block |
||
288 | 288 | if ($usecachekey && count($tabtranslatedomain)) { |
289 | 289 | $ressetcache = dol_setcache($usecachekey, $tabtranslatedomain); |
290 | 290 | if ($ressetcache < 0) { |
291 | - $error = 'Failed to set cache for usecachekey=' . $usecachekey . ' result=' . $ressetcache; |
|
291 | + $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; |
|
292 | 292 | dol_syslog($error, LOG_ERR); |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | 296 | if (empty($conf->global->MAIN_FORCELANGDIR)) |
297 | - break; // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
297 | + break; // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
298 | 298 | } |
299 | 299 | } |
300 | 300 | } |
@@ -304,11 +304,11 @@ discard block |
||
304 | 304 | if ($alt == 0) { |
305 | 305 | // This function MUST NOT contains call to syslog |
306 | 306 | //dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG); |
307 | - $langofdir = strtolower($langarray[0]) . '_' . strtoupper($langarray[0]); |
|
307 | + $langofdir = strtolower($langarray[0]).'_'.strtoupper($langarray[0]); |
|
308 | 308 | if ($langofdir == 'el_EL') |
309 | - $langofdir = 'el_GR'; // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
309 | + $langofdir = 'el_GR'; // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
310 | 310 | if ($langofdir == 'ar_AR') |
311 | - $langofdir = 'ar_SA'; // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
311 | + $langofdir = 'ar_SA'; // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
312 | 312 | $this->load($domain, $alt + 1, $stopafterdirection, $langofdir); |
313 | 313 | } |
314 | 314 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | // We are in the pass of the reference file. No more files to scan to complete. |
324 | 324 | if ($alt == 2) { |
325 | 325 | if ($fileread) |
326 | - $this->_tab_loaded[$newdomain] = 1; // Set domain file as found so loaded |
|
326 | + $this->_tab_loaded[$newdomain] = 1; // Set domain file as found so loaded |
|
327 | 327 | |
328 | 328 | if (empty($this->_tab_loaded[$newdomain])) |
329 | 329 | $this->_tab_loaded[$newdomain] = 2; // Set this file as not found |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | // This part is deprecated and replaced with table llx_overwrite_trans |
333 | 333 | // Kept for backward compatibility. |
334 | 334 | if (empty($loadfromfileonly)) { |
335 | - $overwritekey = 'MAIN_OVERWRITE_TRANS_' . $this->defaultlang; |
|
335 | + $overwritekey = 'MAIN_OVERWRITE_TRANS_'.$this->defaultlang; |
|
336 | 336 | if (!empty($conf->global->$overwritekey)) { // Overwrite translation with key1:newstring1,key2:newstring2 |
337 | 337 | // Overwrite translation with param MAIN_OVERWRITE_TRANS_xx_XX |
338 | 338 | $tmparray = explode(',', $conf->global->$overwritekey); |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | |
372 | 372 | // Check parameters |
373 | 373 | if (empty($db)) |
374 | - return 0; // Database handler can't be used |
|
374 | + return 0; // Database handler can't be used |
|
375 | 375 | |
376 | 376 | |
377 | 377 | //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang); |
@@ -384,13 +384,13 @@ discard block |
||
384 | 384 | return 0; |
385 | 385 | } |
386 | 386 | |
387 | - $this->_tab_loaded[$newdomain] = 1; // We want to be sure this function is called once only for domain 'database' |
|
387 | + $this->_tab_loaded[$newdomain] = 1; // We want to be sure this function is called once only for domain 'database' |
|
388 | 388 | |
389 | 389 | $fileread = 0; |
390 | 390 | $langofdir = $this->defaultlang; |
391 | 391 | |
392 | 392 | if (empty($langofdir)) { // This may occurs when load is called without setting the language and without providing a value for forcelangdir |
393 | - dol_syslog("Error: " . get_class($this) . "::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING); |
|
393 | + dol_syslog("Error: ".get_class($this)."::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING); |
|
394 | 394 | return -1; |
395 | 395 | } |
396 | 396 | |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | $usecachekey = ''; |
402 | 402 | // Using a memcached server |
403 | 403 | if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) { |
404 | - $usecachekey = $newdomain . '_' . $langofdir; // Should not contains special chars |
|
404 | + $usecachekey = $newdomain.'_'.$langofdir; // Should not contains special chars |
|
405 | 405 | } // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) |
406 | 406 | else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { |
407 | 407 | $usecachekey = $newdomain; |
@@ -411,20 +411,20 @@ discard block |
||
411 | 411 | //dol_syslog('Translate::Load we will cache result into usecachekey '.$usecachekey); |
412 | 412 | //global $aaa; $aaa+=1; |
413 | 413 | //print $aaa." ".$usecachekey."\n"; |
414 | - require_once DOL_BASE_PATH . '/core/lib/memory.lib.php'; |
|
414 | + require_once DOL_BASE_PATH.'/core/lib/memory.lib.php'; |
|
415 | 415 | $tmparray = dol_getcache($usecachekey); |
416 | 416 | if (is_array($tmparray) && count($tmparray)) { |
417 | 417 | $this->tab_translate += $tmparray; // Faster than array_merge($tmparray,$this->tab_translate). Note: If a valuer already exists into tab_translate, value into tmparaay is not added. |
418 | 418 | //print $newdomain."\n"; |
419 | 419 | //var_dump($this->tab_translate); |
420 | 420 | $fileread = 1; |
421 | - $found = true; // Found in dolibarr PHP cache |
|
421 | + $found = true; // Found in dolibarr PHP cache |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | 425 | if (!$found && !empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) { |
426 | 426 | // Overwrite translation with database read |
427 | - $sql = "SELECT transkey, transvalue FROM " . MAIN_DB_PREFIX . "overwrite_trans where lang='" . $db->escape($this->defaultlang) . "'"; |
|
427 | + $sql = "SELECT transkey, transvalue FROM ".MAIN_DB_PREFIX."overwrite_trans where lang='".$db->escape($this->defaultlang)."'"; |
|
428 | 428 | $resql = $db->query($sql); |
429 | 429 | |
430 | 430 | if ($resql) { |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | if ($usecachekey && count($tabtranslatedomain)) { |
460 | 460 | $ressetcache = dol_setcache($usecachekey, $tabtranslatedomain); |
461 | 461 | if ($ressetcache < 0) { |
462 | - $error = 'Failed to set cache for usecachekey=' . $usecachekey . ' result=' . $ressetcache; |
|
462 | + $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; |
|
463 | 463 | dol_syslog($error, LOG_ERR); |
464 | 464 | } |
465 | 465 | } |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | $this->_tab_loaded[$newdomain] = 1; // Set domain file as loaded |
474 | 474 | |
475 | 475 | if (empty($this->_tab_loaded[$newdomain])) |
476 | - $this->_tab_loaded[$newdomain] = 2; // Marque ce cas comme non trouve (no lines found for language) |
|
476 | + $this->_tab_loaded[$newdomain] = 2; // Marque ce cas comme non trouve (no lines found for language) |
|
477 | 477 | |
478 | 478 | return 1; |
479 | 479 | } |
@@ -515,12 +515,12 @@ discard block |
||
515 | 515 | $str = $this->tab_translate[$key]; |
516 | 516 | |
517 | 517 | // Make some string replacement after translation |
518 | - $replacekey = 'MAIN_REPLACE_TRANS_' . $this->defaultlang; |
|
518 | + $replacekey = 'MAIN_REPLACE_TRANS_'.$this->defaultlang; |
|
519 | 519 | if (!empty($conf->global->$replacekey)) { // Replacement translation variable with string1:newstring1;string2:newstring2 |
520 | 520 | $tmparray = explode(';', $conf->global->$replacekey); |
521 | 521 | foreach ($tmparray as $tmp) { |
522 | 522 | $tmparray2 = explode(':', $tmp); |
523 | - $str = preg_replace('/' . preg_quote($tmparray2[0]) . '/', $tmparray2[1], $str); |
|
523 | + $str = preg_replace('/'.preg_quote($tmparray2[0]).'/', $tmparray2[1], $str); |
|
524 | 524 | } |
525 | 525 | } |
526 | 526 | |
@@ -615,20 +615,20 @@ discard block |
||
615 | 615 | // Check if a translation is available (this can call getTradFromKey) |
616 | 616 | $tmp = $this->transnoentitiesnoconv($key); |
617 | 617 | if ($tmp != $key && $tmp != 'ErrorBadValueForParamNotAString') { |
618 | - return $tmp; // Found in language array |
|
618 | + return $tmp; // Found in language array |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | // Check in cache |
622 | 622 | if (isset($this->cache_labels[$tablename][$key])) { // Can be defined to 0 or '' |
623 | - return $this->cache_labels[$tablename][$key]; // Found in cache |
|
623 | + return $this->cache_labels[$tablename][$key]; // Found in cache |
|
624 | 624 | } |
625 | 625 | |
626 | - $sql = "SELECT " . $fieldlabel . " as label"; |
|
627 | - $sql .= " FROM " . MAIN_DB_PREFIX . $tablename; |
|
628 | - $sql .= " WHERE " . $fieldkey . " = '" . $db->escape($keyforselect ? $keyforselect : $key) . "'"; |
|
626 | + $sql = "SELECT ".$fieldlabel." as label"; |
|
627 | + $sql .= " FROM ".MAIN_DB_PREFIX.$tablename; |
|
628 | + $sql .= " WHERE ".$fieldkey." = '".$db->escape($keyforselect ? $keyforselect : $key)."'"; |
|
629 | 629 | if ($filteronentity) |
630 | - $sql .= " AND entity IN (" . getEntity($tablename) . ')'; |
|
631 | - dol_syslog(get_class($this) . '::getLabelFromKey', LOG_DEBUG); |
|
630 | + $sql .= " AND entity IN (".getEntity($tablename).')'; |
|
631 | + dol_syslog(get_class($this).'::getLabelFromKey', LOG_DEBUG); |
|
632 | 632 | $resql = $db->query($sql); |
633 | 633 | if ($resql) { |
634 | 634 | $obj = $db->fetch_object($resql); |
@@ -668,12 +668,12 @@ discard block |
||
668 | 668 | $str = $this->tab_translate[$key]; |
669 | 669 | |
670 | 670 | // Make some string replacement after translation |
671 | - $replacekey = 'MAIN_REPLACE_TRANS_' . $this->defaultlang; |
|
671 | + $replacekey = 'MAIN_REPLACE_TRANS_'.$this->defaultlang; |
|
672 | 672 | if (!empty($conf->global->$replacekey)) { // Replacement translation variable with string1:newstring1;string2:newstring2 |
673 | 673 | $tmparray = explode(';', $conf->global->$replacekey); |
674 | 674 | foreach ($tmparray as $tmp) { |
675 | 675 | $tmparray2 = explode(':', $tmp); |
676 | - $str = preg_replace('/' . preg_quote($tmparray2[0]) . '/', $tmparray2[1], $str); |
|
676 | + $str = preg_replace('/'.preg_quote($tmparray2[0]).'/', $tmparray2[1], $str); |
|
677 | 677 | } |
678 | 678 | } |
679 | 679 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | } |
764 | 764 | |
765 | 765 | // We scan directory langs to detect available languages |
766 | - $handle = opendir($langdir . "/langs"); |
|
766 | + $handle = opendir($langdir."/langs"); |
|
767 | 767 | $langs_available = array(); |
768 | 768 | while ($dir = trim(readdir($handle))) { |
769 | 769 | if (preg_match('/^[a-z]+_[A-Z]+/i', $dir)) { |
@@ -773,9 +773,9 @@ discard block |
||
773 | 773 | $langs_available[$dir] = $dir; |
774 | 774 | } |
775 | 775 | if ($usecode == 1 || !empty($conf->global->MAIN_SHOW_LANGUAGE_CODE)) { |
776 | - $langs_available[$dir] = $dir . ': ' . dol_trunc($this->trans('Language_' . $dir), $maxlength); |
|
776 | + $langs_available[$dir] = $dir.': '.dol_trunc($this->trans('Language_'.$dir), $maxlength); |
|
777 | 777 | } else { |
778 | - $langs_available[$dir] = $this->trans('Language_' . $dir); |
|
778 | + $langs_available[$dir] = $this->trans('Language_'.$dir); |
|
779 | 779 | } |
780 | 780 | } |
781 | 781 | } |
@@ -794,13 +794,13 @@ discard block |
||
794 | 794 | // phpcs:enable |
795 | 795 | // Test si fichier dans repertoire de la langue |
796 | 796 | foreach ($this->dir as $searchdir) { |
797 | - if (is_readable(dol_osencode($searchdir . "/langs/" . $this->defaultlang . "/" . $filename))) |
|
797 | + if (is_readable(dol_osencode($searchdir."/langs/".$this->defaultlang."/".$filename))) |
|
798 | 798 | return true; |
799 | 799 | |
800 | 800 | if ($searchalt) { |
801 | 801 | // Test si fichier dans repertoire de la langue alternative |
802 | 802 | if ($this->defaultlang != "en_US") |
803 | - $filenamealt = $searchdir . "/langs/en_US/" . $filename; |
|
803 | + $filenamealt = $searchdir."/langs/en_US/".$filename; |
|
804 | 804 | //else $filenamealt = $searchdir."/langs/fr_FR/".$filename; |
805 | 805 | if (is_readable(dol_osencode($filenamealt))) |
806 | 806 | return true; |
@@ -837,8 +837,8 @@ discard block |
||
837 | 837 | continue; // We must not use dol_is_dir here, function may not be loaded |
838 | 838 | |
839 | 839 | $fonc = 'numberwords'; |
840 | - if (file_exists($newdir . '/functions_' . $fonc . '.lib.php')) { |
|
841 | - include_once $newdir . '/functions_' . $fonc . '.lib.php'; |
|
840 | + if (file_exists($newdir.'/functions_'.$fonc.'.lib.php')) { |
|
841 | + include_once $newdir.'/functions_'.$fonc.'.lib.php'; |
|
842 | 842 | $newnumber = numberwords_getLabelFromNumber($this, $number, $isamount); |
843 | 843 | break; |
844 | 844 | } |
@@ -861,9 +861,9 @@ discard block |
||
861 | 861 | $symbol = $this->getCurrencySymbol($currency_code); |
862 | 862 | |
863 | 863 | if (in_array($currency_code, array('USD'))) |
864 | - return $symbol . $amount; |
|
864 | + return $symbol.$amount; |
|
865 | 865 | else |
866 | - return $amount . $symbol; |
|
866 | + return $amount.$symbol; |
|
867 | 867 | } |
868 | 868 | |
869 | 869 | /** |
@@ -902,18 +902,18 @@ discard block |
||
902 | 902 | global $db; |
903 | 903 | |
904 | 904 | if ($this->cache_currencies_all_loaded) |
905 | - return 0; // Cache already loaded for all |
|
905 | + return 0; // Cache already loaded for all |
|
906 | 906 | if (!empty($currency_code) && isset($this->cache_currencies[$currency_code])) |
907 | - return 0; // Cache already loaded for the currency |
|
907 | + return 0; // Cache already loaded for the currency |
|
908 | 908 | |
909 | 909 | $sql = "SELECT code_iso, label, unicode"; |
910 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_currencies"; |
|
910 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies"; |
|
911 | 911 | $sql .= " WHERE active = 1"; |
912 | 912 | if (!empty($currency_code)) |
913 | - $sql .= " AND code_iso = '" . $db->escape($currency_code) . "'"; |
|
913 | + $sql .= " AND code_iso = '".$db->escape($currency_code)."'"; |
|
914 | 914 | //$sql.= " ORDER BY code_iso ASC"; // Not required, a sort is done later |
915 | 915 | |
916 | - dol_syslog(get_class($this) . '::loadCacheCurrencies', LOG_DEBUG); |
|
916 | + dol_syslog(get_class($this).'::loadCacheCurrencies', LOG_DEBUG); |
|
917 | 917 | $resql = $db->query($sql); |
918 | 918 | if ($resql) { |
919 | 919 | $this->load("dict"); |
@@ -928,8 +928,8 @@ discard block |
||
928 | 928 | $obj = $db->fetch_object($resql); |
929 | 929 | |
930 | 930 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
931 | - $this->cache_currencies[$obj->code_iso]['label'] = ($obj->code_iso && $this->trans("Currency" . $obj->code_iso) != "Currency" . $obj->code_iso ? $this->trans("Currency" . $obj->code_iso) : ($obj->label != '-' ? $obj->label : '')); |
|
932 | - $this->cache_currencies[$obj->code_iso]['unicode'] = (array)json_decode($obj->unicode, true); |
|
931 | + $this->cache_currencies[$obj->code_iso]['label'] = ($obj->code_iso && $this->trans("Currency".$obj->code_iso) != "Currency".$obj->code_iso ? $this->trans("Currency".$obj->code_iso) : ($obj->label != '-' ? $obj->label : '')); |
|
932 | + $this->cache_currencies[$obj->code_iso]['unicode'] = (array) json_decode($obj->unicode, true); |
|
933 | 933 | $label[$obj->code_iso] = $this->cache_currencies[$obj->code_iso]['label']; |
934 | 934 | $i++; |
935 | 935 | } |
@@ -960,8 +960,8 @@ discard block |
||
960 | 960 | $substitutionarray = array(); |
961 | 961 | |
962 | 962 | foreach ($this->tab_translate as $code => $label) { |
963 | - $substitutionarray['lang_' . $code] = $label; |
|
964 | - $substitutionarray['__(' . $code . ')__'] = $label; |
|
963 | + $substitutionarray['lang_'.$code] = $label; |
|
964 | + $substitutionarray['__('.$code.')__'] = $label; |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | return $substitutionarray; |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | if ($action == 'create' || filter_input(INPUT_POST, "addcat") == 'addcat') { |
72 | 72 | AlDolUtils::dol_set_focus('#label'); |
73 | 73 | |
74 | - print '<form action="' . $_SERVER['PHP_SELF'] . '?type=' . $type . '" method="POST">'; |
|
75 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
76 | - print '<input type="hidden" name="urlfrom" value="' . $urlfrom . '">'; |
|
74 | + print '<form action="'.$_SERVER['PHP_SELF'].'?type='.$type.'" method="POST">'; |
|
75 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
76 | + print '<input type="hidden" name="urlfrom" value="'.$urlfrom.'">'; |
|
77 | 77 | print '<input type="hidden" name="action" value="add">'; |
78 | 78 | print '<input type="hidden" name="addcat" value="addcat">'; |
79 | - print '<input type="hidden" name="id" value="' . AlDolUtils::GETPOST('origin', 'alpha') . '">'; |
|
80 | - print '<input type="hidden" name="type" value="' . $type . '">'; |
|
81 | - print '<input type="hidden" name="backtopage" value="' . $backtopage . '">'; |
|
79 | + print '<input type="hidden" name="id" value="'.AlDolUtils::GETPOST('origin', 'alpha').'">'; |
|
80 | + print '<input type="hidden" name="type" value="'.$type.'">'; |
|
81 | + print '<input type="hidden" name="backtopage" value="'.$backtopage.'">'; |
|
82 | 82 | if ($origin) { |
83 | - print '<input type="hidden" name="origin" value="' . $origin . '">'; |
|
83 | + print '<input type="hidden" name="origin" value="'.$origin.'">'; |
|
84 | 84 | } |
85 | 85 | if ($catorigin) { |
86 | - print '<input type="hidden" name="catorigin" value="' . $catorigin . '">'; |
|
86 | + print '<input type="hidden" name="catorigin" value="'.$catorigin.'">'; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | print load_fiche_titre($langs->trans("CreateCat")); |
@@ -94,29 +94,29 @@ discard block |
||
94 | 94 | |
95 | 95 | // Ref |
96 | 96 | print '<tr>'; |
97 | - print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("Ref") . '</td><td><input id="label" class="minwidth100" name="label" value="' . $label . '">'; |
|
97 | + print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td><input id="label" class="minwidth100" name="label" value="'.$label.'">'; |
|
98 | 98 | print'</td></tr>'; |
99 | 99 | |
100 | 100 | // Description |
101 | - print '<tr><td class="tdtop">' . $langs->trans("Description") . '</td><td>'; |
|
101 | + print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>'; |
|
102 | 102 | //require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; |
103 | 103 | $doleditor = new DolEditor('description', $description, '', 200, 'dolibarr_notes', '', false, true, Globals::$conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, ROWS_6, '90%'); |
104 | 104 | $doleditor->Create(); |
105 | 105 | print '</td></tr>'; |
106 | 106 | |
107 | 107 | // Color |
108 | - print '<tr><td>' . $langs->trans("Color") . '</td><td>'; |
|
108 | + print '<tr><td>'.$langs->trans("Color").'</td><td>'; |
|
109 | 109 | print $formother->selectColor($color, 'color'); |
110 | 110 | print '</td></tr>'; |
111 | 111 | |
112 | 112 | // Parent category |
113 | - print '<tr><td>' . $langs->trans("AddIn") . '</td><td>'; |
|
113 | + print '<tr><td>'.$langs->trans("AddIn").'</td><td>'; |
|
114 | 114 | print $form->select_all_categories($type, $catorigin, 'parent'); |
115 | 115 | print ajax_combobox('parent'); |
116 | 116 | print '</td></tr>'; |
117 | 117 | |
118 | 118 | $parameters = array(); |
119 | - $reshook = Globals::$hookManager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook |
|
119 | + $reshook = Globals::$hookManager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook |
|
120 | 120 | print Globals::$hookManager->resPrint; |
121 | 121 | if (empty($reshook)) { |
122 | 122 | print $object->showOptionals($extrafields, 'edit'); |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | AlDolUtils::dol_fiche_end(''); |
128 | 128 | |
129 | 129 | print '<div class="center">'; |
130 | - print '<input type="submit" class="button" value="' . $langs->trans("CreateThisCat") . '" name="creation" />'; |
|
130 | + print '<input type="submit" class="button" value="'.$langs->trans("CreateThisCat").'" name="creation" />'; |
|
131 | 131 | print ' '; |
132 | - print '<input type="submit" class="button" value="' . $langs->trans("Cancel") . '" name="cancel" />'; |
|
132 | + print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel" />'; |
|
133 | 133 | print '</div>'; |
134 | 134 | |
135 | 135 | print '</form>'; |
@@ -169,7258 +169,7258 @@ |
||
169 | 169 | public $user; |
170 | 170 | |
171 | 171 | /** |
172 | - * @var int The id of originating object |
|
173 | - * @see fetch_origin() |
|
174 | - */ |
|
175 | - public $origin_id; |
|
176 | - |
|
177 | - /** |
|
178 | - * @var string The object's reference |
|
179 | - */ |
|
180 | - public $ref; |
|
181 | - |
|
182 | - /** |
|
183 | - * @var string The object's previous reference |
|
184 | - */ |
|
185 | - public $ref_previous; |
|
186 | - |
|
187 | - /** |
|
188 | - * @var string The object's next reference |
|
189 | - */ |
|
190 | - public $ref_next; |
|
191 | - |
|
192 | - /** |
|
193 | - * @var string An external reference for the object |
|
194 | - */ |
|
195 | - public $ref_ext; |
|
196 | - |
|
197 | - /** |
|
198 | - * @var int The object's status |
|
199 | - * @see setStatut() |
|
200 | - */ |
|
201 | - public $statut; |
|
202 | - |
|
203 | - /** |
|
204 | - * @var string |
|
205 | - * @see getFullAddress() |
|
206 | - */ |
|
207 | - public $country; |
|
208 | - |
|
209 | - /** |
|
210 | - * @var int |
|
211 | - * @see getFullAddress(), country |
|
212 | - */ |
|
213 | - public $country_id; |
|
214 | - |
|
215 | - /** |
|
216 | - * @var string |
|
217 | - * @see getFullAddress(), isInEEC(), country |
|
218 | - */ |
|
219 | - public $country_code; |
|
172 | + * @var int The id of originating object |
|
173 | + * @see fetch_origin() |
|
174 | + */ |
|
175 | + public $origin_id; |
|
220 | 176 | |
221 | 177 | /** |
222 | - * @var string |
|
223 | - * @see getFullAddress() |
|
224 | - */ |
|
225 | - public $state; |
|
178 | + * @var string The object's reference |
|
179 | + */ |
|
180 | + public $ref; |
|
226 | 181 | |
227 | - /** |
|
228 | - * @var int |
|
229 | - * @see getFullAddress(), state |
|
230 | - */ |
|
231 | - public $state_id; |
|
182 | + /** |
|
183 | + * @var string The object's previous reference |
|
184 | + */ |
|
185 | + public $ref_previous; |
|
232 | 186 | |
233 | - /** |
|
234 | - * @var string |
|
235 | - * @see getFullAddress(), state |
|
236 | - */ |
|
237 | - public $state_code; |
|
187 | + /** |
|
188 | + * @var string The object's next reference |
|
189 | + */ |
|
190 | + public $ref_next; |
|
238 | 191 | |
239 | 192 | /** |
240 | - * @var string |
|
241 | - * @see getFullAddress(), region |
|
242 | - */ |
|
243 | - public $region; |
|
193 | + * @var string An external reference for the object |
|
194 | + */ |
|
195 | + public $ref_ext; |
|
244 | 196 | |
245 | - /** |
|
246 | - * @var string |
|
247 | - * @see getFullAddress(), region |
|
248 | - */ |
|
249 | - public $region_code; |
|
197 | + /** |
|
198 | + * @var int The object's status |
|
199 | + * @see setStatut() |
|
200 | + */ |
|
201 | + public $statut; |
|
250 | 202 | |
251 | - /** |
|
252 | - * @var int |
|
253 | - * @see fetch_barcode() |
|
254 | - */ |
|
255 | - public $barcode_type; |
|
256 | - |
|
257 | - /** |
|
258 | - * @var string |
|
259 | - * @see fetch_barcode(), barcode_type |
|
260 | - */ |
|
261 | - public $barcode_type_code; |
|
262 | - |
|
263 | - /** |
|
264 | - * @var string |
|
265 | - * @see fetch_barcode(), barcode_type |
|
266 | - */ |
|
267 | - public $barcode_type_label; |
|
268 | - |
|
269 | - /** |
|
270 | - * @var string |
|
271 | - * @see fetch_barcode(), barcode_type |
|
272 | - */ |
|
273 | - public $barcode_type_coder; |
|
274 | - |
|
275 | - /** |
|
276 | - * @var int Payment method ID (cheque, cash, ...) |
|
277 | - * @see setPaymentMethods() |
|
278 | - */ |
|
279 | - public $mode_reglement_id; |
|
280 | - |
|
281 | - /** |
|
282 | - * @var int Payment terms ID |
|
283 | - * @see setPaymentTerms() |
|
284 | - */ |
|
285 | - public $cond_reglement_id; |
|
286 | - |
|
287 | - /** |
|
288 | - * @var int Payment terms ID |
|
289 | - * @deprecated Kept for compatibility |
|
290 | - * @see cond_reglement_id; |
|
291 | - */ |
|
292 | - public $cond_reglement; |
|
293 | - |
|
294 | - /** |
|
295 | - * @var int Delivery address ID |
|
296 | - * @deprecated |
|
297 | - * @see setDeliveryAddress() |
|
298 | - */ |
|
299 | - public $fk_delivery_address; |
|
300 | - |
|
301 | - /** |
|
302 | - * @var int Shipping method ID |
|
303 | - * @see setShippingMethod() |
|
304 | - */ |
|
305 | - public $shipping_method_id; |
|
306 | - |
|
307 | - /** |
|
308 | - * @var string |
|
309 | - * @see SetDocModel() |
|
310 | - */ |
|
311 | - public $modelpdf; |
|
312 | - |
|
313 | - /** |
|
314 | - * @var int Bank account ID |
|
315 | - * @see SetBankAccount() |
|
316 | - */ |
|
317 | - public $fk_account; |
|
318 | - |
|
319 | - /** |
|
320 | - * @var string Public note |
|
321 | - * @see update_note() |
|
322 | - */ |
|
323 | - public $note_public; |
|
324 | - |
|
325 | - /** |
|
326 | - * @var string Private note |
|
327 | - * @see update_note() |
|
328 | - */ |
|
329 | - public $note_private; |
|
330 | - |
|
331 | - /** |
|
332 | - * @deprecated |
|
333 | - * @see note_public |
|
334 | - */ |
|
335 | - public $note; |
|
336 | - |
|
337 | - /** |
|
338 | - * @var float Total amount before taxes |
|
339 | - * @see update_price() |
|
340 | - */ |
|
341 | - public $total_ht; |
|
342 | - |
|
343 | - /** |
|
344 | - * @var float Total VAT amount |
|
345 | - * @see update_price() |
|
346 | - */ |
|
347 | - public $total_tva; |
|
348 | - |
|
349 | - /** |
|
350 | - * @var float Total local tax 1 amount |
|
351 | - * @see update_price() |
|
352 | - */ |
|
353 | - public $total_localtax1; |
|
354 | - |
|
355 | - /** |
|
356 | - * @var float Total local tax 2 amount |
|
357 | - * @see update_price() |
|
358 | - */ |
|
359 | - public $total_localtax2; |
|
360 | - |
|
361 | - /** |
|
362 | - * @var float Total amount with taxes |
|
363 | - * @see update_price() |
|
364 | - */ |
|
365 | - public $total_ttc; |
|
366 | - |
|
367 | - /** |
|
368 | - * @var CommonObjectLine[] |
|
369 | - */ |
|
370 | - public $lines; |
|
371 | - |
|
372 | - /** |
|
373 | - * @var mixed Contains comments |
|
374 | - * @see fetchComments() |
|
375 | - */ |
|
376 | - public $comments=array(); |
|
377 | - |
|
378 | - /** |
|
379 | - * @var int |
|
380 | - * @see setIncoterms() |
|
381 | - */ |
|
382 | - public $fk_incoterms; |
|
383 | - |
|
384 | - /** |
|
385 | - * @var string |
|
386 | - * @see SetIncoterms() |
|
387 | - */ |
|
388 | - public $libelle_incoterms; |
|
389 | - |
|
390 | - /** |
|
391 | - * @var string |
|
392 | - * @see display_incoterms() |
|
393 | - */ |
|
394 | - public $location_incoterms; |
|
395 | - |
|
396 | - public $name; |
|
397 | - public $lastname; |
|
398 | - public $firstname; |
|
399 | - public $civility_id; |
|
400 | - |
|
401 | - // Dates |
|
402 | - public $date_creation; // Date creation |
|
403 | - public $date_validation; // Date validation |
|
404 | - public $date_modification; // Date last change (tms field) |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - // No constructor as it is an abstract class |
|
409 | - |
|
410 | - /** |
|
411 | - * Check an object id/ref exists |
|
412 | - * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch |
|
413 | - * |
|
414 | - * @param string $element String of element ('product', 'facture', ...) |
|
415 | - * @param int $id Id of object |
|
416 | - * @param string $ref Ref of object to check |
|
417 | - * @param string $ref_ext Ref ext of object to check |
|
418 | - * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
|
419 | - */ |
|
420 | - static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
421 | - { |
|
422 | - global $db,$conf; |
|
423 | - |
|
424 | - $sql = "SELECT rowid, ref, ref_ext"; |
|
425 | - $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
426 | - $sql.= " WHERE entity IN (".getEntity($element).")" ; |
|
427 | - |
|
428 | - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
429 | - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
430 | - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
431 | - else { |
|
432 | - $error='ErrorWrongParameters'; |
|
433 | - dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
|
434 | - return -1; |
|
435 | - } |
|
436 | - if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
437 | - |
|
438 | - dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
|
439 | - $resql = $db->query($sql); |
|
440 | - if ($resql) |
|
441 | - { |
|
442 | - $num=$db->num_rows($resql); |
|
443 | - if ($num > 0) return 1; |
|
444 | - else return 0; |
|
445 | - } |
|
446 | - return -1; |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * Method to output saved errors |
|
451 | - * |
|
452 | - * @return string String with errors |
|
453 | - */ |
|
454 | - function errorsToString() |
|
455 | - { |
|
456 | - return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):''); |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Return full name (civility+' '+name+' '+lastname) |
|
461 | - * |
|
462 | - * @param Translate $langs Language object for translation of civility (used only if option is 1) |
|
463 | - * @param int $option 0=No option, 1=Add civility |
|
464 | - * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname |
|
465 | - * @param int $maxlen Maximum length |
|
466 | - * @return string String with full name |
|
467 | - */ |
|
468 | - function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
469 | - { |
|
470 | - //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
|
471 | - $lastname=$this->lastname; |
|
472 | - $firstname=$this->firstname; |
|
473 | - 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:''))))); |
|
474 | - |
|
475 | - $ret=''; |
|
476 | - if ($option && $this->civility_id) |
|
477 | - { |
|
478 | - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
479 | - else $ret.=$this->civility_id.' '; |
|
480 | - } |
|
481 | - |
|
482 | - $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
483 | - |
|
484 | - return dol_trunc($ret,$maxlen); |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Return full address of contact |
|
489 | - * |
|
490 | - * @param int $withcountry 1=Add country into address string |
|
491 | - * @param string $sep Separator to use to build string |
|
492 | - * @param int $withregion 1=Add region into address string |
|
493 | - * @return string Full address string |
|
494 | - */ |
|
495 | - function getFullAddress($withcountry=0, $sep="\n", $withregion=0) |
|
496 | - { |
|
497 | - if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
|
498 | - { |
|
499 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
500 | - $tmparray=getCountry($this->country_id,'all'); |
|
501 | - $this->country_code=$tmparray['code']; |
|
502 | - $this->country =$tmparray['label']; |
|
503 | - } |
|
203 | + /** |
|
204 | + * @var string |
|
205 | + * @see getFullAddress() |
|
206 | + */ |
|
207 | + public $country; |
|
504 | 208 | |
505 | - if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) |
|
506 | - { |
|
507 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
508 | - $tmparray=getState($this->state_id,'all',0,1); |
|
509 | - $this->state_code =$tmparray['code']; |
|
510 | - $this->state =$tmparray['label']; |
|
511 | - $this->region_code =$tmparray['region_code']; |
|
512 | - $this->region =$tmparray['region']; |
|
513 | - } |
|
514 | - |
|
515 | - return dol_format_address($this, $withcountry, $sep); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * Return full address for banner |
|
521 | - * |
|
522 | - * @param string $htmlkey HTML id to make banner content unique |
|
523 | - * @param Object $object Object (thirdparty, thirdparty of contact for contact, null for a member) |
|
524 | - * @return string Full address string |
|
525 | - */ |
|
526 | - function getBannerAddress($htmlkey, $object) |
|
527 | - { |
|
528 | - global $conf, $langs; |
|
529 | - |
|
530 | - $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
531 | - |
|
532 | - $contactid=0; |
|
533 | - $thirdpartyid=0; |
|
534 | - if ($this->element == 'societe') |
|
535 | - { |
|
536 | - $thirdpartyid=$this->id; |
|
537 | - } |
|
538 | - if ($this->element == 'contact') |
|
539 | - { |
|
540 | - $contactid=$this->id; |
|
541 | - $thirdpartyid=$object->fk_soc; |
|
542 | - } |
|
543 | - if ($this->element == 'user') |
|
544 | - { |
|
545 | - $contactid=$this->contact_id; |
|
546 | - $thirdpartyid=$object->fk_soc; |
|
547 | - } |
|
548 | - |
|
549 | - $out='<!-- BEGIN part to show address block -->'; |
|
550 | - |
|
551 | - $outdone=0; |
|
552 | - $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
553 | - if ($coords) |
|
554 | - { |
|
555 | - if (! empty($conf->use_javascript_ajax)) |
|
556 | - { |
|
557 | - $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
558 | - // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
|
559 | - $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">'; |
|
560 | - $out.=img_picto($langs->trans("Address"), 'object_address.png'); |
|
561 | - $out.='</a> '; |
|
562 | - } |
|
563 | - $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
564 | - $outdone++; |
|
565 | - } |
|
566 | - |
|
567 | - 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 | - && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) |
|
569 | - { |
|
570 | - if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) { |
|
571 | - $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
|
572 | - } |
|
573 | - else { |
|
574 | - $out.=($outdone?' - ':'').$this->state; |
|
575 | - } |
|
576 | - $outdone++; |
|
577 | - } |
|
578 | - |
|
579 | - 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>':''); |
|
580 | - if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
|
581 | - $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
582 | - } |
|
583 | - if (! empty($this->phone_pro)) { |
|
584 | - $out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
585 | - } |
|
586 | - if (! empty($this->phone_mobile)) { |
|
587 | - $out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
588 | - } |
|
589 | - if (! empty($this->phone_perso)) { |
|
590 | - $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++; |
|
591 | - } |
|
592 | - if (! empty($this->office_phone)) { |
|
593 | - $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
594 | - } |
|
595 | - if (! empty($this->user_mobile)) { |
|
596 | - $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
597 | - } |
|
598 | - if (! empty($this->fax)) { |
|
599 | - $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
600 | - } |
|
601 | - if (! empty($this->office_fax)) { |
|
602 | - $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
603 | - } |
|
604 | - |
|
605 | - $out.='<div style="clear: both;"></div>'; |
|
606 | - $outdone=0; |
|
607 | - if (! empty($this->email)) |
|
608 | - { |
|
609 | - $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); |
|
610 | - $outdone++; |
|
611 | - } |
|
612 | - if (! empty($this->url)) |
|
613 | - { |
|
614 | - $out.=dol_print_url($this->url,'_goout',0,1); |
|
615 | - $outdone++; |
|
616 | - } |
|
617 | - $out.='<div style="clear: both;">'; |
|
618 | - if (! empty($conf->socialnetworks->enabled)) |
|
619 | - { |
|
620 | - if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
621 | - $outdone++; |
|
622 | - if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
623 | - $outdone++; |
|
624 | - if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
625 | - $outdone++; |
|
626 | - if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
627 | - $outdone++; |
|
628 | - } |
|
629 | - $out.='</div>'; |
|
630 | - |
|
631 | - $out.='<!-- END Part to show address block -->'; |
|
632 | - |
|
633 | - return $out; |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Return the link of last main doc file for direct public download. |
|
638 | - * |
|
639 | - * @param string $modulepart Module related to document |
|
640 | - * @param int $initsharekey Init the share key if it was not yet defined |
|
641 | - * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
|
642 | - * @return string Link or empty string if there is no download link |
|
643 | - */ |
|
644 | - function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
645 | - { |
|
646 | - global $user, $dolibarr_main_url_root; |
|
647 | - |
|
648 | - if (empty($this->last_main_doc)) |
|
649 | - { |
|
650 | - return ''; // No way to known which document name to use |
|
651 | - } |
|
652 | - |
|
653 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
654 | - $ecmfile=new EcmFiles($this->db); |
|
655 | - $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
|
656 | - if ($result < 0) |
|
657 | - { |
|
658 | - $this->error = $ecmfile->error; |
|
659 | - $this->errors = $ecmfile->errors; |
|
660 | - return -1; |
|
661 | - } |
|
662 | - |
|
663 | - if (empty($ecmfile->id)) |
|
664 | - { |
|
665 | - // Add entry into index |
|
666 | - if ($initsharekey) |
|
667 | - { |
|
668 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
669 | - // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first |
|
670 | - /* |
|
671 | - $ecmfile->filepath = $rel_dir; |
|
672 | - $ecmfile->filename = $filename; |
|
673 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
674 | - $ecmfile->fullpath_orig = ''; |
|
675 | - $ecmfile->gen_or_uploaded = 'generated'; |
|
676 | - $ecmfile->description = ''; // indexed content |
|
677 | - $ecmfile->keyword = ''; // keyword content |
|
678 | - $ecmfile->share = getRandomPassword(true); |
|
679 | - $result = $ecmfile->create($user); |
|
680 | - if ($result < 0) |
|
681 | - { |
|
682 | - $this->error = $ecmfile->error; |
|
683 | - $this->errors = $ecmfile->errors; |
|
684 | - } |
|
685 | - */ |
|
686 | - } |
|
687 | - else return ''; |
|
688 | - } |
|
689 | - elseif (empty($ecmfile->share)) |
|
690 | - { |
|
691 | - // Add entry into index |
|
692 | - if ($initsharekey) |
|
693 | - { |
|
694 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
695 | - $ecmfile->share = getRandomPassword(true); |
|
696 | - $ecmfile->update($user); |
|
697 | - } |
|
698 | - else return ''; |
|
699 | - } |
|
700 | - |
|
701 | - // Define $urlwithroot |
|
702 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
703 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
704 | - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
705 | - |
|
706 | - $forcedownload=0; |
|
707 | - |
|
708 | - $paramlink=''; |
|
709 | - //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
|
710 | - //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
|
711 | - //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
|
712 | - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
713 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
714 | - |
|
715 | - if ($relativelink) |
|
716 | - { |
|
717 | - $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
718 | - } |
|
719 | - else |
|
720 | - { |
|
721 | - $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
722 | - } |
|
723 | - |
|
724 | - // Here $ecmfile->share is defined |
|
725 | - return $linktoreturn; |
|
726 | - } |
|
209 | + /** |
|
210 | + * @var int |
|
211 | + * @see getFullAddress(), country |
|
212 | + */ |
|
213 | + public $country_id; |
|
727 | 214 | |
215 | + /** |
|
216 | + * @var string |
|
217 | + * @see getFullAddress(), isInEEC(), country |
|
218 | + */ |
|
219 | + public $country_code; |
|
728 | 220 | |
729 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
730 | - /** |
|
731 | - * Add a link between element $this->element and a contact |
|
732 | - * |
|
733 | - * @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link |
|
734 | - * @param int $type_contact Type of contact (code or id). Must be id or code found into table llx_c_type_contact. For example: SALESREPFOLL |
|
735 | - * @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) |
|
736 | - * @param int $notrigger Disable all triggers |
|
737 | - * @return int <0 if KO, >0 if OK |
|
738 | - */ |
|
739 | - function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
740 | - { |
|
741 | - // phpcs:enable |
|
742 | - global $user,$langs; |
|
743 | - |
|
744 | - |
|
745 | - dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
|
746 | - |
|
747 | - // Check parameters |
|
748 | - if ($fk_socpeople <= 0) |
|
749 | - { |
|
750 | - $langs->load("errors"); |
|
751 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","1"); |
|
752 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
753 | - return -1; |
|
754 | - } |
|
755 | - if (! $type_contact) |
|
756 | - { |
|
757 | - $langs->load("errors"); |
|
758 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","2"); |
|
759 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
760 | - return -2; |
|
761 | - } |
|
762 | - |
|
763 | - $id_type_contact=0; |
|
764 | - if (is_numeric($type_contact)) |
|
765 | - { |
|
766 | - $id_type_contact=$type_contact; |
|
767 | - } |
|
768 | - else |
|
769 | - { |
|
770 | - // We look for id type_contact |
|
771 | - $sql = "SELECT tc.rowid"; |
|
772 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
773 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
774 | - $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
775 | - $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
776 | - //print $sql; |
|
777 | - $resql=$this->db->query($sql); |
|
778 | - if ($resql) |
|
779 | - { |
|
780 | - $obj = $this->db->fetch_object($resql); |
|
781 | - if ($obj) $id_type_contact=$obj->rowid; |
|
782 | - } |
|
783 | - } |
|
784 | - |
|
785 | - if ($id_type_contact == 0) |
|
786 | - { |
|
787 | - $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
788 | - 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"); |
|
789 | - return -3; |
|
790 | - } |
|
791 | - |
|
792 | - $datecreate = dol_now(); |
|
793 | - |
|
794 | - // Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
|
795 | - $TListeContacts=$this->liste_contact(-1, $source); |
|
796 | - $already_added=false; |
|
797 | - if(!empty($TListeContacts)) { |
|
798 | - foreach($TListeContacts as $array_contact) { |
|
799 | - if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { |
|
800 | - $already_added=true; |
|
801 | - break; |
|
802 | - } |
|
803 | - } |
|
804 | - } |
|
221 | + /** |
|
222 | + * @var string |
|
223 | + * @see getFullAddress() |
|
224 | + */ |
|
225 | + public $state; |
|
805 | 226 | |
806 | - if(!$already_added) { |
|
227 | + /** |
|
228 | + * @var int |
|
229 | + * @see getFullAddress(), state |
|
230 | + */ |
|
231 | + public $state_id; |
|
807 | 232 | |
808 | - $this->db->begin(); |
|
233 | + /** |
|
234 | + * @var string |
|
235 | + * @see getFullAddress(), state |
|
236 | + */ |
|
237 | + public $state_code; |
|
809 | 238 | |
810 | - // Insert into database |
|
811 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
|
812 | - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
813 | - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; |
|
814 | - $sql.= "'".$this->db->idate($datecreate)."'"; |
|
815 | - $sql.= ", 4, ". $id_type_contact; |
|
816 | - $sql.= ")"; |
|
239 | + /** |
|
240 | + * @var string |
|
241 | + * @see getFullAddress(), region |
|
242 | + */ |
|
243 | + public $region; |
|
817 | 244 | |
818 | - $resql=$this->db->query($sql); |
|
819 | - if ($resql) |
|
820 | - { |
|
821 | - if (! $notrigger) |
|
822 | - { |
|
823 | - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
824 | - if ($result < 0) |
|
825 | - { |
|
826 | - $this->db->rollback(); |
|
827 | - return -1; |
|
828 | - } |
|
829 | - } |
|
245 | + /** |
|
246 | + * @var string |
|
247 | + * @see getFullAddress(), region |
|
248 | + */ |
|
249 | + public $region_code; |
|
830 | 250 | |
831 | - $this->db->commit(); |
|
832 | - return 1; |
|
833 | - } |
|
834 | - else |
|
835 | - { |
|
836 | - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
837 | - { |
|
838 | - $this->error=$this->db->errno(); |
|
839 | - $this->db->rollback(); |
|
840 | - echo 'err rollback'; |
|
841 | - return -2; |
|
842 | - } |
|
843 | - else |
|
844 | - { |
|
845 | - $this->error=$this->db->error(); |
|
846 | - $this->db->rollback(); |
|
847 | - return -1; |
|
848 | - } |
|
849 | - } |
|
850 | - } else return 0; |
|
851 | - } |
|
251 | + /** |
|
252 | + * @var int |
|
253 | + * @see fetch_barcode() |
|
254 | + */ |
|
255 | + public $barcode_type; |
|
852 | 256 | |
853 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
854 | - /** |
|
855 | - * Copy contact from one element to current |
|
856 | - * |
|
857 | - * @param CommonObject $objFrom Source element |
|
858 | - * @param string $source Nature of contact ('internal' or 'external') |
|
859 | - * @return int >0 if OK, <0 if KO |
|
860 | - */ |
|
861 | - function copy_linked_contact($objFrom, $source='internal') |
|
862 | - { |
|
863 | - // phpcs:enable |
|
864 | - $contacts = $objFrom->liste_contact(-1, $source); |
|
865 | - foreach($contacts as $contact) |
|
866 | - { |
|
867 | - if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
|
868 | - { |
|
869 | - $this->error=$this->db->lasterror(); |
|
870 | - return -1; |
|
871 | - } |
|
872 | - } |
|
873 | - return 1; |
|
874 | - } |
|
257 | + /** |
|
258 | + * @var string |
|
259 | + * @see fetch_barcode(), barcode_type |
|
260 | + */ |
|
261 | + public $barcode_type_code; |
|
875 | 262 | |
876 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
877 | - /** |
|
878 | - * Update a link to contact line |
|
879 | - * |
|
880 | - * @param int $rowid Id of line contact-element |
|
881 | - * @param int $statut New status of link |
|
882 | - * @param int $type_contact_id Id of contact type (not modified if 0) |
|
883 | - * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
|
884 | - * @return int <0 if KO, >= 0 if OK |
|
885 | - */ |
|
886 | - function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
887 | - { |
|
888 | - // phpcs:enable |
|
889 | - // Insert into database |
|
890 | - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
|
891 | - $sql.= " statut = ".$statut; |
|
892 | - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
893 | - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
894 | - $sql.= " where rowid = ".$rowid; |
|
895 | - $resql=$this->db->query($sql); |
|
896 | - if ($resql) |
|
897 | - { |
|
898 | - return 0; |
|
899 | - } |
|
900 | - else |
|
901 | - { |
|
902 | - $this->error=$this->db->lasterror(); |
|
903 | - return -1; |
|
904 | - } |
|
905 | - } |
|
263 | + /** |
|
264 | + * @var string |
|
265 | + * @see fetch_barcode(), barcode_type |
|
266 | + */ |
|
267 | + public $barcode_type_label; |
|
906 | 268 | |
907 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
908 | - /** |
|
909 | - * Delete a link to contact line |
|
910 | - * |
|
911 | - * @param int $rowid Id of contact link line to delete |
|
912 | - * @param int $notrigger Disable all triggers |
|
913 | - * @return int >0 if OK, <0 if KO |
|
914 | - */ |
|
915 | - function delete_contact($rowid, $notrigger=0) |
|
916 | - { |
|
917 | - // phpcs:enable |
|
918 | - global $user; |
|
269 | + /** |
|
270 | + * @var string |
|
271 | + * @see fetch_barcode(), barcode_type |
|
272 | + */ |
|
273 | + public $barcode_type_coder; |
|
919 | 274 | |
275 | + /** |
|
276 | + * @var int Payment method ID (cheque, cash, ...) |
|
277 | + * @see setPaymentMethods() |
|
278 | + */ |
|
279 | + public $mode_reglement_id; |
|
920 | 280 | |
921 | - $this->db->begin(); |
|
281 | + /** |
|
282 | + * @var int Payment terms ID |
|
283 | + * @see setPaymentTerms() |
|
284 | + */ |
|
285 | + public $cond_reglement_id; |
|
922 | 286 | |
923 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
924 | - $sql.= " WHERE rowid =".$rowid; |
|
287 | + /** |
|
288 | + * @var int Payment terms ID |
|
289 | + * @deprecated Kept for compatibility |
|
290 | + * @see cond_reglement_id; |
|
291 | + */ |
|
292 | + public $cond_reglement; |
|
925 | 293 | |
926 | - dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
|
927 | - if ($this->db->query($sql)) |
|
928 | - { |
|
929 | - if (! $notrigger) |
|
930 | - { |
|
931 | - $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
932 | - if ($result < 0) { $this->db->rollback(); return -1; } |
|
933 | - } |
|
934 | - |
|
935 | - $this->db->commit(); |
|
936 | - return 1; |
|
937 | - } |
|
938 | - else |
|
939 | - { |
|
940 | - $this->error=$this->db->lasterror(); |
|
941 | - $this->db->rollback(); |
|
942 | - return -1; |
|
943 | - } |
|
944 | - } |
|
294 | + /** |
|
295 | + * @var int Delivery address ID |
|
296 | + * @deprecated |
|
297 | + * @see setDeliveryAddress() |
|
298 | + */ |
|
299 | + public $fk_delivery_address; |
|
945 | 300 | |
946 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
947 | - /** |
|
948 | - * Delete all links between an object $this and all its contacts |
|
949 | - * |
|
950 | - * @param string $source '' or 'internal' or 'external' |
|
951 | - * @param string $code Type of contact (code or id) |
|
952 | - * @return int >0 if OK, <0 if KO |
|
953 | - */ |
|
954 | - function delete_linked_contact($source='',$code='') |
|
955 | - { |
|
956 | - // phpcs:enable |
|
957 | - $temp = array(); |
|
958 | - $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
959 | - |
|
960 | - foreach($typeContact as $key => $value) |
|
961 | - { |
|
962 | - array_push($temp,$key); |
|
963 | - } |
|
964 | - $listId = implode(",", $temp); |
|
965 | - |
|
966 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
967 | - $sql.= " WHERE element_id = ".$this->id; |
|
968 | - if ($listId) |
|
969 | - $sql.= " AND fk_c_type_contact IN (".$listId.")"; |
|
970 | - |
|
971 | - dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
|
972 | - if ($this->db->query($sql)) |
|
973 | - { |
|
974 | - return 1; |
|
975 | - } |
|
976 | - else |
|
977 | - { |
|
978 | - $this->error=$this->db->lasterror(); |
|
979 | - return -1; |
|
980 | - } |
|
981 | - } |
|
301 | + /** |
|
302 | + * @var int Shipping method ID |
|
303 | + * @see setShippingMethod() |
|
304 | + */ |
|
305 | + public $shipping_method_id; |
|
982 | 306 | |
983 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
984 | - /** |
|
985 | - * Get array of all contacts for an object |
|
986 | - * |
|
987 | - * @param int $statut Status of links to get (-1=all) |
|
988 | - * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) |
|
989 | - * @param int $list 0:Return array contains all properties, 1:Return array contains just id |
|
990 | - * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) |
|
991 | - * @return array|int Array of contacts, -1 if error |
|
992 | - */ |
|
993 | - function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
994 | - { |
|
995 | - // phpcs:enable |
|
996 | - global $langs; |
|
997 | - |
|
998 | - $tab=array(); |
|
999 | - |
|
1000 | - $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 |
|
1001 | - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
1002 | - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
1003 | - $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
1004 | - $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
1005 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
1006 | - $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
1007 | - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
1008 | - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
1009 | - $sql.= " WHERE ec.element_id =".$this->id; |
|
1010 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
1011 | - $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
1012 | - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
1013 | - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
1014 | - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
1015 | - $sql.= " AND tc.active=1"; |
|
1016 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
1017 | - $sql.=" ORDER BY t.lastname ASC"; |
|
1018 | - |
|
1019 | - dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
|
1020 | - $resql=$this->db->query($sql); |
|
1021 | - if ($resql) |
|
1022 | - { |
|
1023 | - $num=$this->db->num_rows($resql); |
|
1024 | - $i=0; |
|
1025 | - while ($i < $num) |
|
1026 | - { |
|
1027 | - $obj = $this->db->fetch_object($resql); |
|
307 | + /** |
|
308 | + * @var string |
|
309 | + * @see SetDocModel() |
|
310 | + */ |
|
311 | + public $modelpdf; |
|
1028 | 312 | |
1029 | - if (! $list) |
|
1030 | - { |
|
1031 | - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
1032 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
1033 | - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id, |
|
1034 | - 'nom'=>$obj->lastname, // For backward compatibility |
|
1035 | - 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
|
1036 | - 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
|
1037 | - } |
|
1038 | - else |
|
1039 | - { |
|
1040 | - $tab[$i]=$obj->id; |
|
1041 | - } |
|
313 | + /** |
|
314 | + * @var int Bank account ID |
|
315 | + * @see SetBankAccount() |
|
316 | + */ |
|
317 | + public $fk_account; |
|
1042 | 318 | |
1043 | - $i++; |
|
1044 | - } |
|
1045 | - |
|
1046 | - return $tab; |
|
1047 | - } |
|
1048 | - else |
|
1049 | - { |
|
1050 | - $this->error=$this->db->lasterror(); |
|
1051 | - dol_print_error($this->db); |
|
1052 | - return -1; |
|
1053 | - } |
|
1054 | - } |
|
1055 | - |
|
1056 | - |
|
1057 | - /** |
|
1058 | - * Update status of a contact linked to object |
|
1059 | - * |
|
1060 | - * @param int $rowid Id of link between object and contact |
|
1061 | - * @return int <0 if KO, >=0 if OK |
|
1062 | - */ |
|
1063 | - function swapContactStatus($rowid) |
|
1064 | - { |
|
1065 | - $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
|
1066 | - $sql.= " tc.code, tc.libelle"; |
|
1067 | - //$sql.= ", s.fk_soc"; |
|
1068 | - $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; |
|
1069 | - //$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 |
|
1070 | - $sql.= " WHERE ec.rowid =".$rowid; |
|
1071 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
1072 | - $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
1073 | - |
|
1074 | - dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
|
1075 | - $resql=$this->db->query($sql); |
|
1076 | - if ($resql) |
|
1077 | - { |
|
1078 | - $obj = $this->db->fetch_object($resql); |
|
1079 | - $newstatut = ($obj->statut == 4) ? 5 : 4; |
|
1080 | - $result = $this->update_contact($rowid, $newstatut); |
|
1081 | - $this->db->free($resql); |
|
1082 | - return $result; |
|
1083 | - } |
|
1084 | - else |
|
1085 | - { |
|
1086 | - $this->error=$this->db->error(); |
|
1087 | - dol_print_error($this->db); |
|
1088 | - return -1; |
|
1089 | - } |
|
1090 | - } |
|
319 | + /** |
|
320 | + * @var string Public note |
|
321 | + * @see update_note() |
|
322 | + */ |
|
323 | + public $note_public; |
|
1091 | 324 | |
1092 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1093 | - /** |
|
1094 | - * Return array with list of possible values for type of contacts |
|
1095 | - * |
|
1096 | - * @param string $source 'internal', 'external' or 'all' |
|
1097 | - * @param string $order Sort order by : 'position', 'code', 'rowid'... |
|
1098 | - * @param int $option 0=Return array id->label, 1=Return array code->label |
|
1099 | - * @param int $activeonly 0=all status of contact, 1=only the active |
|
1100 | - * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
|
1101 | - * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
|
1102 | - */ |
|
1103 | - function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
1104 | - { |
|
1105 | - // phpcs:enable |
|
1106 | - global $langs; |
|
1107 | - |
|
1108 | - if (empty($order)) $order='position'; |
|
1109 | - if ($order == 'position') $order.=',code'; |
|
1110 | - |
|
1111 | - $tab = array(); |
|
1112 | - $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
|
1113 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
1114 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
1115 | - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
1116 | - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
1117 | - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
1118 | - $sql.= $this->db->order($order,'ASC'); |
|
1119 | - |
|
1120 | - //print "sql=".$sql; |
|
1121 | - $resql=$this->db->query($sql); |
|
1122 | - if ($resql) |
|
1123 | - { |
|
1124 | - $num=$this->db->num_rows($resql); |
|
1125 | - $i=0; |
|
1126 | - while ($i < $num) |
|
1127 | - { |
|
1128 | - $obj = $this->db->fetch_object($resql); |
|
1129 | - |
|
1130 | - $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
1131 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
1132 | - if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
1133 | - else $tab[$obj->code]=$libelle_type; |
|
1134 | - $i++; |
|
1135 | - } |
|
1136 | - return $tab; |
|
1137 | - } |
|
1138 | - else |
|
1139 | - { |
|
1140 | - $this->error=$this->db->lasterror(); |
|
1141 | - //dol_print_error($this->db); |
|
1142 | - return null; |
|
1143 | - } |
|
1144 | - } |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * Return id of contacts for a source and a contact code. |
|
1148 | - * Example: contact client de facturation ('external', 'BILLING') |
|
1149 | - * Example: contact client de livraison ('external', 'SHIPPING') |
|
1150 | - * Example: contact interne suivi paiement ('internal', 'SALESREPFOLL') |
|
1151 | - * |
|
1152 | - * @param string $source 'external' or 'internal' |
|
1153 | - * @param string $code 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... |
|
1154 | - * @param int $status limited to a certain status |
|
1155 | - * @return array List of id for such contacts |
|
1156 | - */ |
|
1157 | - function getIdContact($source,$code,$status=0) |
|
1158 | - { |
|
1159 | - global $conf; |
|
1160 | - |
|
1161 | - $result=array(); |
|
1162 | - $i=0; |
|
1163 | - //cas particulier pour les expeditions |
|
1164 | - if($this->element=='shipping' && $this->origin_id != 0) { |
|
1165 | - $id=$this->origin_id; |
|
1166 | - $element='commande'; |
|
1167 | - } else if($this->element=='reception' && $this->origin_id != 0) { |
|
1168 | - $id=$this->origin_id; |
|
1169 | - $element='order_supplier'; |
|
1170 | - } else { |
|
1171 | - $id=$this->id; |
|
1172 | - $element=$this->element; |
|
1173 | - } |
|
1174 | - |
|
1175 | - $sql = "SELECT ec.fk_socpeople"; |
|
1176 | - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
1177 | - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
1178 | - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
1179 | - $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
1180 | - $sql.= " WHERE ec.element_id = ".$id; |
|
1181 | - $sql.= " AND ec.fk_socpeople = c.rowid"; |
|
1182 | - if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
1183 | - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")"; |
|
1184 | - $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
1185 | - $sql.= " AND tc.element = '".$element."'"; |
|
1186 | - $sql.= " AND tc.source = '".$source."'"; |
|
1187 | - $sql.= " AND tc.code = '".$code."'"; |
|
1188 | - $sql.= " AND tc.active = 1"; |
|
1189 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
1190 | - |
|
1191 | - dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
|
1192 | - $resql=$this->db->query($sql); |
|
1193 | - if ($resql) |
|
1194 | - { |
|
1195 | - while ($obj = $this->db->fetch_object($resql)) |
|
1196 | - { |
|
1197 | - $result[$i]=$obj->fk_socpeople; |
|
1198 | - $i++; |
|
1199 | - } |
|
1200 | - } |
|
1201 | - else |
|
1202 | - { |
|
1203 | - $this->error=$this->db->error(); |
|
1204 | - return null; |
|
1205 | - } |
|
1206 | - |
|
1207 | - return $result; |
|
1208 | - } |
|
325 | + /** |
|
326 | + * @var string Private note |
|
327 | + * @see update_note() |
|
328 | + */ |
|
329 | + public $note_private; |
|
1209 | 330 | |
1210 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1211 | - /** |
|
1212 | - * Load object contact with id=$this->contactid into $this->contact |
|
1213 | - * |
|
1214 | - * @param int $contactid Id du contact. Use this->contactid if empty. |
|
1215 | - * @return int <0 if KO, >0 if OK |
|
1216 | - */ |
|
1217 | - function fetch_contact($contactid=null) |
|
1218 | - { |
|
1219 | - // phpcs:enable |
|
1220 | - if (empty($contactid)) $contactid=$this->contactid; |
|
331 | + /** |
|
332 | + * @deprecated |
|
333 | + * @see note_public |
|
334 | + */ |
|
335 | + public $note; |
|
1221 | 336 | |
1222 | - if (empty($contactid)) return 0; |
|
337 | + /** |
|
338 | + * @var float Total amount before taxes |
|
339 | + * @see update_price() |
|
340 | + */ |
|
341 | + public $total_ht; |
|
1223 | 342 | |
1224 | - require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
1225 | - $contact = new Contact($this->db); |
|
1226 | - $result=$contact->fetch($contactid); |
|
1227 | - $this->contact = $contact; |
|
1228 | - return $result; |
|
1229 | - } |
|
343 | + /** |
|
344 | + * @var float Total VAT amount |
|
345 | + * @see update_price() |
|
346 | + */ |
|
347 | + public $total_tva; |
|
1230 | 348 | |
1231 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1232 | - /** |
|
1233 | - * Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty |
|
1234 | - * |
|
1235 | - * @param int $force_thirdparty_id Force thirdparty id |
|
1236 | - * @return int <0 if KO, >0 if OK |
|
1237 | - */ |
|
1238 | - function fetch_thirdparty($force_thirdparty_id=0) |
|
1239 | - { |
|
1240 | - // phpcs:enable |
|
1241 | - global $conf; |
|
349 | + /** |
|
350 | + * @var float Total local tax 1 amount |
|
351 | + * @see update_price() |
|
352 | + */ |
|
353 | + public $total_localtax1; |
|
1242 | 354 | |
1243 | - if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
|
1244 | - return 0; |
|
355 | + /** |
|
356 | + * @var float Total local tax 2 amount |
|
357 | + * @see update_price() |
|
358 | + */ |
|
359 | + public $total_localtax2; |
|
1245 | 360 | |
1246 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
361 | + /** |
|
362 | + * @var float Total amount with taxes |
|
363 | + * @see update_price() |
|
364 | + */ |
|
365 | + public $total_ttc; |
|
1247 | 366 | |
1248 | - $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
|
1249 | - if ($force_thirdparty_id) |
|
1250 | - $idtofetch = $force_thirdparty_id; |
|
367 | + /** |
|
368 | + * @var CommonObjectLine[] |
|
369 | + */ |
|
370 | + public $lines; |
|
1251 | 371 | |
1252 | - if ($idtofetch) { |
|
1253 | - $thirdparty = new Societe($this->db); |
|
1254 | - $result = $thirdparty->fetch($idtofetch); |
|
1255 | - $this->thirdparty = $thirdparty; |
|
372 | + /** |
|
373 | + * @var mixed Contains comments |
|
374 | + * @see fetchComments() |
|
375 | + */ |
|
376 | + public $comments=array(); |
|
1256 | 377 | |
1257 | - // Use first price level if level not defined for third party |
|
1258 | - if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) { |
|
1259 | - $this->thirdparty->price_level = 1; |
|
1260 | - } |
|
378 | + /** |
|
379 | + * @var int |
|
380 | + * @see setIncoterms() |
|
381 | + */ |
|
382 | + public $fk_incoterms; |
|
1261 | 383 | |
1262 | - return $result; |
|
1263 | - } else |
|
1264 | - return -1; |
|
1265 | - } |
|
384 | + /** |
|
385 | + * @var string |
|
386 | + * @see SetIncoterms() |
|
387 | + */ |
|
388 | + public $libelle_incoterms; |
|
1266 | 389 | |
390 | + /** |
|
391 | + * @var string |
|
392 | + * @see display_incoterms() |
|
393 | + */ |
|
394 | + public $location_incoterms; |
|
1267 | 395 | |
1268 | - /** |
|
1269 | - * Looks for an object with ref matching the wildcard provided |
|
1270 | - * It does only work when $this->table_ref_field is set |
|
1271 | - * |
|
1272 | - * @param string $ref Wildcard |
|
1273 | - * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO |
|
1274 | - */ |
|
1275 | - public function fetchOneLike($ref) |
|
1276 | - { |
|
1277 | - if (!$this->table_ref_field) { |
|
1278 | - return 0; |
|
1279 | - } |
|
396 | + public $name; |
|
397 | + public $lastname; |
|
398 | + public $firstname; |
|
399 | + public $civility_id; |
|
1280 | 400 | |
1281 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE '.$this->table_ref_field.' LIKE "'.$this->db->escape($ref).'" LIMIT 1'; |
|
401 | + // Dates |
|
402 | + public $date_creation; // Date creation |
|
403 | + public $date_validation; // Date validation |
|
404 | + public $date_modification; // Date last change (tms field) |
|
1282 | 405 | |
1283 | - $query = $this->db->query($sql); |
|
1284 | 406 | |
1285 | - if (!$this->db->num_rows($query)) { |
|
1286 | - return 0; |
|
1287 | - } |
|
1288 | 407 | |
1289 | - $result = $this->db->fetch_object($query); |
|
408 | + // No constructor as it is an abstract class |
|
1290 | 409 | |
1291 | - return $this->fetch($result->rowid); |
|
1292 | - } |
|
410 | + /** |
|
411 | + * Check an object id/ref exists |
|
412 | + * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch |
|
413 | + * |
|
414 | + * @param string $element String of element ('product', 'facture', ...) |
|
415 | + * @param int $id Id of object |
|
416 | + * @param string $ref Ref of object to check |
|
417 | + * @param string $ref_ext Ref ext of object to check |
|
418 | + * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
|
419 | + */ |
|
420 | + static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
421 | + { |
|
422 | + global $db,$conf; |
|
423 | + |
|
424 | + $sql = "SELECT rowid, ref, ref_ext"; |
|
425 | + $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
426 | + $sql.= " WHERE entity IN (".getEntity($element).")" ; |
|
427 | + |
|
428 | + if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
429 | + else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
430 | + else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
431 | + else { |
|
432 | + $error='ErrorWrongParameters'; |
|
433 | + dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
|
434 | + return -1; |
|
435 | + } |
|
436 | + if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
1293 | 437 | |
1294 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1295 | - /** |
|
1296 | - * Load data for barcode into properties ->barcode_type* |
|
1297 | - * Properties ->barcode_type that is id of barcode. Type is used to find other properties, but |
|
1298 | - * if it is not defined, ->element must be defined to know default barcode type. |
|
1299 | - * |
|
1300 | - * @return int <0 if KO, 0 if can't guess type of barcode (ISBN, EAN13...), >0 if OK (all barcode properties loaded) |
|
1301 | - */ |
|
1302 | - function fetch_barcode() |
|
1303 | - { |
|
1304 | - // phpcs:enable |
|
1305 | - global $conf; |
|
438 | + dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
|
439 | + $resql = $db->query($sql); |
|
440 | + if ($resql) |
|
441 | + { |
|
442 | + $num=$db->num_rows($resql); |
|
443 | + if ($num > 0) return 1; |
|
444 | + else return 0; |
|
445 | + } |
|
446 | + return -1; |
|
447 | + } |
|
1306 | 448 | |
1307 | - dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
|
449 | + /** |
|
450 | + * Method to output saved errors |
|
451 | + * |
|
452 | + * @return string String with errors |
|
453 | + */ |
|
454 | + function errorsToString() |
|
455 | + { |
|
456 | + return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):''); |
|
457 | + } |
|
1308 | 458 | |
1309 | - $idtype=$this->barcode_type; |
|
1310 | - 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 |
|
1311 | - { |
|
1312 | - if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
1313 | - else if ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
1314 | - else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING); |
|
1315 | - } |
|
459 | + /** |
|
460 | + * Return full name (civility+' '+name+' '+lastname) |
|
461 | + * |
|
462 | + * @param Translate $langs Language object for translation of civility (used only if option is 1) |
|
463 | + * @param int $option 0=No option, 1=Add civility |
|
464 | + * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname |
|
465 | + * @param int $maxlen Maximum length |
|
466 | + * @return string String with full name |
|
467 | + */ |
|
468 | + function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
469 | + { |
|
470 | + //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
|
471 | + $lastname=$this->lastname; |
|
472 | + $firstname=$this->firstname; |
|
473 | + 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:''))))); |
|
1316 | 474 | |
1317 | - if ($idtype > 0) |
|
1318 | - { |
|
1319 | - 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 |
|
1320 | - { |
|
1321 | - $sql = "SELECT rowid, code, libelle as label, coder"; |
|
1322 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
1323 | - $sql.= " WHERE rowid = ".$idtype; |
|
1324 | - dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
|
1325 | - $resql = $this->db->query($sql); |
|
1326 | - if ($resql) |
|
1327 | - { |
|
1328 | - $obj = $this->db->fetch_object($resql); |
|
1329 | - $this->barcode_type = $obj->rowid; |
|
1330 | - $this->barcode_type_code = $obj->code; |
|
1331 | - $this->barcode_type_label = $obj->label; |
|
1332 | - $this->barcode_type_coder = $obj->coder; |
|
1333 | - return 1; |
|
1334 | - } |
|
1335 | - else |
|
1336 | - { |
|
1337 | - dol_print_error($this->db); |
|
1338 | - return -1; |
|
1339 | - } |
|
1340 | - } |
|
1341 | - } |
|
1342 | - return 0; |
|
1343 | - } |
|
475 | + $ret=''; |
|
476 | + if ($option && $this->civility_id) |
|
477 | + { |
|
478 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
479 | + else $ret.=$this->civility_id.' '; |
|
480 | + } |
|
1344 | 481 | |
1345 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1346 | - /** |
|
1347 | - * Load the project with id $this->fk_project into this->project |
|
1348 | - * |
|
1349 | - * @return int <0 if KO, >=0 if OK |
|
1350 | - */ |
|
1351 | - function fetch_projet() |
|
1352 | - { |
|
1353 | - // phpcs:enable |
|
1354 | - include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
482 | + $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
1355 | 483 | |
1356 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
1357 | - if (empty($this->fk_project)) return 0; |
|
484 | + return dol_trunc($ret,$maxlen); |
|
485 | + } |
|
1358 | 486 | |
1359 | - $project = new Project($this->db); |
|
1360 | - $result = $project->fetch($this->fk_project); |
|
487 | + /** |
|
488 | + * Return full address of contact |
|
489 | + * |
|
490 | + * @param int $withcountry 1=Add country into address string |
|
491 | + * @param string $sep Separator to use to build string |
|
492 | + * @param int $withregion 1=Add region into address string |
|
493 | + * @return string Full address string |
|
494 | + */ |
|
495 | + function getFullAddress($withcountry=0, $sep="\n", $withregion=0) |
|
496 | + { |
|
497 | + if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
|
498 | + { |
|
499 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
500 | + $tmparray=getCountry($this->country_id,'all'); |
|
501 | + $this->country_code=$tmparray['code']; |
|
502 | + $this->country =$tmparray['label']; |
|
503 | + } |
|
1361 | 504 | |
1362 | - $this->projet = $project; // deprecated |
|
1363 | - $this->project = $project; |
|
1364 | - return $result; |
|
1365 | - } |
|
505 | + if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) |
|
506 | + { |
|
507 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
508 | + $tmparray=getState($this->state_id,'all',0,1); |
|
509 | + $this->state_code =$tmparray['code']; |
|
510 | + $this->state =$tmparray['label']; |
|
511 | + $this->region_code =$tmparray['region_code']; |
|
512 | + $this->region =$tmparray['region']; |
|
513 | + } |
|
1366 | 514 | |
1367 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1368 | - /** |
|
1369 | - * Load the product with id $this->fk_product into this->product |
|
1370 | - * |
|
1371 | - * @return int <0 if KO, >=0 if OK |
|
1372 | - */ |
|
1373 | - function fetch_product() |
|
1374 | - { |
|
1375 | - // phpcs:enable |
|
1376 | - include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
515 | + return dol_format_address($this, $withcountry, $sep); |
|
516 | + } |
|
1377 | 517 | |
1378 | - if (empty($this->fk_product)) return 0; |
|
1379 | 518 | |
1380 | - $product = new Product($this->db); |
|
1381 | - $result = $product->fetch($this->fk_product); |
|
519 | + /** |
|
520 | + * Return full address for banner |
|
521 | + * |
|
522 | + * @param string $htmlkey HTML id to make banner content unique |
|
523 | + * @param Object $object Object (thirdparty, thirdparty of contact for contact, null for a member) |
|
524 | + * @return string Full address string |
|
525 | + */ |
|
526 | + function getBannerAddress($htmlkey, $object) |
|
527 | + { |
|
528 | + global $conf, $langs; |
|
1382 | 529 | |
1383 | - $this->product = $product; |
|
1384 | - return $result; |
|
1385 | - } |
|
530 | + $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
1386 | 531 | |
1387 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1388 | - /** |
|
1389 | - * Load the user with id $userid into this->user |
|
1390 | - * |
|
1391 | - * @param int $userid Id du contact |
|
1392 | - * @return int <0 if KO, >0 if OK |
|
1393 | - */ |
|
1394 | - function fetch_user($userid) |
|
1395 | - { |
|
1396 | - // phpcs:enable |
|
1397 | - $user = new User($this->db); |
|
1398 | - $result=$user->fetch($userid); |
|
1399 | - $this->user = $user; |
|
1400 | - return $result; |
|
1401 | - } |
|
532 | + $contactid=0; |
|
533 | + $thirdpartyid=0; |
|
534 | + if ($this->element == 'societe') |
|
535 | + { |
|
536 | + $thirdpartyid=$this->id; |
|
537 | + } |
|
538 | + if ($this->element == 'contact') |
|
539 | + { |
|
540 | + $contactid=$this->id; |
|
541 | + $thirdpartyid=$object->fk_soc; |
|
542 | + } |
|
543 | + if ($this->element == 'user') |
|
544 | + { |
|
545 | + $contactid=$this->contact_id; |
|
546 | + $thirdpartyid=$object->fk_soc; |
|
547 | + } |
|
1402 | 548 | |
1403 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1404 | - /** |
|
1405 | - * Read linked origin object |
|
1406 | - * |
|
1407 | - * @return void |
|
1408 | - */ |
|
1409 | - function fetch_origin() |
|
1410 | - { |
|
1411 | - // phpcs:enable |
|
1412 | - if ($this->origin == 'shipping') $this->origin = 'expedition'; |
|
1413 | - if ($this->origin == 'delivery') $this->origin = 'livraison'; |
|
1414 | - if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur'; |
|
549 | + $out='<!-- BEGIN part to show address block -->'; |
|
1415 | 550 | |
1416 | - $origin = $this->origin; |
|
551 | + $outdone=0; |
|
552 | + $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
553 | + if ($coords) |
|
554 | + { |
|
555 | + if (! empty($conf->use_javascript_ajax)) |
|
556 | + { |
|
557 | + $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
558 | + // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
|
559 | + $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">'; |
|
560 | + $out.=img_picto($langs->trans("Address"), 'object_address.png'); |
|
561 | + $out.='</a> '; |
|
562 | + } |
|
563 | + $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
564 | + $outdone++; |
|
565 | + } |
|
1417 | 566 | |
1418 | - $classname = ucfirst($origin); |
|
1419 | - $this->$origin = new $classname($this->db); |
|
1420 | - $this->$origin->fetch($this->origin_id); |
|
1421 | - } |
|
567 | + 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 | + && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) |
|
569 | + { |
|
570 | + if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) { |
|
571 | + $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
|
572 | + } |
|
573 | + else { |
|
574 | + $out.=($outdone?' - ':'').$this->state; |
|
575 | + } |
|
576 | + $outdone++; |
|
577 | + } |
|
1422 | 578 | |
1423 | - /** |
|
1424 | - * Load object from specific field |
|
1425 | - * |
|
1426 | - * @param string $table Table element or element line |
|
1427 | - * @param string $field Field selected |
|
1428 | - * @param string $key Import key |
|
1429 | - * @param string $element Element name |
|
1430 | - * @return int <0 if KO, >0 if OK |
|
1431 | - */ |
|
1432 | - function fetchObjectFrom($table, $field, $key, $element = null) |
|
1433 | - { |
|
1434 | - global $conf; |
|
1435 | - |
|
1436 | - $result=false; |
|
1437 | - |
|
1438 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
|
1439 | - $sql.= " WHERE ".$field." = '".$key."'"; |
|
1440 | - if (! empty($element)) { |
|
1441 | - $sql.= " AND entity IN (".getEntity($element).")"; |
|
1442 | - } else { |
|
1443 | - $sql.= " AND entity = ".$conf->entity; |
|
1444 | - } |
|
1445 | - |
|
1446 | - dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
|
1447 | - $resql = $this->db->query($sql); |
|
1448 | - if ($resql) |
|
1449 | - { |
|
1450 | - $row = $this->db->fetch_row($resql); |
|
1451 | - // Test for avoid error -1 |
|
1452 | - if ($row[0] > 0) { |
|
1453 | - $result = $this->fetch($row[0]); |
|
1454 | - } |
|
1455 | - } |
|
1456 | - |
|
1457 | - return $result; |
|
1458 | - } |
|
1459 | - |
|
1460 | - /** |
|
1461 | - * Getter generic. Load value from a specific field |
|
1462 | - * |
|
1463 | - * @param string $table Table of element or element line |
|
1464 | - * @param int $id Element id |
|
1465 | - * @param string $field Field selected |
|
1466 | - * @return int <0 if KO, >0 if OK |
|
1467 | - */ |
|
1468 | - function getValueFrom($table, $id, $field) |
|
1469 | - { |
|
1470 | - $result=false; |
|
1471 | - if (!empty($id) && !empty($field) && !empty($table)) { |
|
1472 | - $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
|
1473 | - $sql.= " WHERE rowid = ".$id; |
|
1474 | - |
|
1475 | - dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
|
1476 | - $resql = $this->db->query($sql); |
|
1477 | - if ($resql) |
|
1478 | - { |
|
1479 | - $row = $this->db->fetch_row($resql); |
|
1480 | - $result = $row[0]; |
|
1481 | - } |
|
1482 | - } |
|
1483 | - return $result; |
|
1484 | - } |
|
1485 | - |
|
1486 | - /** |
|
1487 | - * Setter generic. Update a specific field into database. |
|
1488 | - * Warning: Trigger is run only if param trigkey is provided. |
|
1489 | - * |
|
1490 | - * @param string $field Field to update |
|
1491 | - * @param mixed $value New value |
|
1492 | - * @param string $table To force other table element or element line (should not be used) |
|
1493 | - * @param int $id To force other object id (should not be used) |
|
1494 | - * @param string $format Data format ('text', 'date'). 'text' is used if not defined |
|
1495 | - * @param string $id_field To force rowid field name. 'rowid' is used if not defined |
|
1496 | - * @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none' |
|
1497 | - * @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY') |
|
1498 | - * @param string $fk_user_field Name of field to save user id making change |
|
1499 | - * @return int <0 if KO, >0 if OK |
|
1500 | - * @see updateExtraField |
|
1501 | - */ |
|
1502 | - function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif') |
|
1503 | - { |
|
1504 | - global $user,$langs,$conf; |
|
1505 | - |
|
1506 | - if (empty($table)) $table=$this->table_element; |
|
1507 | - if (empty($id)) $id=$this->id; |
|
1508 | - if (empty($format)) $format='text'; |
|
1509 | - if (empty($id_field)) $id_field='rowid'; |
|
1510 | - |
|
1511 | - $error=0; |
|
1512 | - |
|
1513 | - $this->db->begin(); |
|
1514 | - |
|
1515 | - // Special case |
|
1516 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
1517 | - if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod'; |
|
1518 | - |
|
1519 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
|
1520 | - |
|
1521 | - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
1522 | - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
1523 | - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
1524 | - |
|
1525 | - if ($fk_user_field) |
|
1526 | - { |
|
1527 | - if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
1528 | - elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
1529 | - } |
|
1530 | - |
|
1531 | - $sql.= " WHERE ".$id_field." = ".$id; |
|
1532 | - |
|
1533 | - dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
|
1534 | - $resql = $this->db->query($sql); |
|
1535 | - if ($resql) |
|
1536 | - { |
|
1537 | - if ($trigkey) |
|
1538 | - { |
|
1539 | - // call trigger with updated object values |
|
1540 | - if (empty($this->fields) && method_exists($this, 'fetch')) |
|
1541 | - { |
|
1542 | - $result = $this->fetch($id); |
|
1543 | - } |
|
1544 | - else |
|
1545 | - { |
|
1546 | - $result = $this->fetchCommon($id); |
|
1547 | - } |
|
1548 | - if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
1549 | - if ($result < 0) $error++; |
|
1550 | - } |
|
579 | + 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>':''); |
|
580 | + if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
|
581 | + $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
582 | + } |
|
583 | + if (! empty($this->phone_pro)) { |
|
584 | + $out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
585 | + } |
|
586 | + if (! empty($this->phone_mobile)) { |
|
587 | + $out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
588 | + } |
|
589 | + if (! empty($this->phone_perso)) { |
|
590 | + $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++; |
|
591 | + } |
|
592 | + if (! empty($this->office_phone)) { |
|
593 | + $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
594 | + } |
|
595 | + if (! empty($this->user_mobile)) { |
|
596 | + $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
597 | + } |
|
598 | + if (! empty($this->fax)) { |
|
599 | + $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
600 | + } |
|
601 | + if (! empty($this->office_fax)) { |
|
602 | + $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
603 | + } |
|
1551 | 604 | |
1552 | - if (! $error) |
|
1553 | - { |
|
1554 | - if (property_exists($this, $field)) $this->$field = $value; |
|
1555 | - $this->db->commit(); |
|
1556 | - return 1; |
|
1557 | - } |
|
1558 | - else |
|
1559 | - { |
|
1560 | - $this->db->rollback(); |
|
1561 | - return -2; |
|
1562 | - } |
|
1563 | - } |
|
1564 | - else |
|
1565 | - { |
|
1566 | - $this->error=$this->db->lasterror(); |
|
1567 | - $this->db->rollback(); |
|
1568 | - return -1; |
|
1569 | - } |
|
1570 | - } |
|
605 | + $out.='<div style="clear: both;"></div>'; |
|
606 | + $outdone=0; |
|
607 | + if (! empty($this->email)) |
|
608 | + { |
|
609 | + $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); |
|
610 | + $outdone++; |
|
611 | + } |
|
612 | + if (! empty($this->url)) |
|
613 | + { |
|
614 | + $out.=dol_print_url($this->url,'_goout',0,1); |
|
615 | + $outdone++; |
|
616 | + } |
|
617 | + $out.='<div style="clear: both;">'; |
|
618 | + if (! empty($conf->socialnetworks->enabled)) |
|
619 | + { |
|
620 | + if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
621 | + $outdone++; |
|
622 | + if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
623 | + $outdone++; |
|
624 | + if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
625 | + $outdone++; |
|
626 | + if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
627 | + $outdone++; |
|
628 | + } |
|
629 | + $out.='</div>'; |
|
1571 | 630 | |
1572 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1573 | - /** |
|
1574 | - * Load properties id_previous and id_next by comparing $fieldid with $this->ref |
|
1575 | - * |
|
1576 | - * @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')" |
|
1577 | - * @param string $fieldid Name of field to use for the select MAX and MIN |
|
1578 | - * @param int $nodbprefix Do not include DB prefix to forge table name |
|
1579 | - * @return int <0 if KO, >0 if OK |
|
1580 | - */ |
|
1581 | - function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
1582 | - { |
|
1583 | - // phpcs:enable |
|
1584 | - global $conf, $user; |
|
1585 | - |
|
1586 | - if (! $this->table_element) |
|
1587 | - { |
|
1588 | - dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
|
1589 | - return -1; |
|
1590 | - } |
|
1591 | - if ($fieldid == 'none') return 1; |
|
1592 | - |
|
1593 | - // Security on socid |
|
1594 | - $socid = 0; |
|
1595 | - if ($user->societe_id > 0) $socid = $user->societe_id; |
|
1596 | - |
|
1597 | - // this->ismultientitymanaged contains |
|
1598 | - // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
1599 | - $alias = 's'; |
|
1600 | - if ($this->element == 'societe') $alias = 'te'; |
|
1601 | - |
|
1602 | - $sql = "SELECT MAX(te.".$fieldid.")"; |
|
1603 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
1604 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1605 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1606 | - } |
|
1607 | - 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 |
|
1608 | - 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 |
|
1609 | - 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 |
|
1610 | - 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"; |
|
1611 | - $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1612 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
1613 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
1614 | - if (! empty($filter)) |
|
1615 | - { |
|
1616 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
1617 | - $sql.=$filter; |
|
1618 | - } |
|
1619 | - 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 |
|
1620 | - 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 |
|
1621 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
|
1622 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1623 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
1624 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
1625 | - } else { |
|
1626 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
1627 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1628 | - } |
|
1629 | - } else { |
|
1630 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1631 | - } |
|
1632 | - } |
|
1633 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
1634 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
1635 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
1636 | - //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
1637 | - |
|
1638 | - $result = $this->db->query($sql); |
|
1639 | - if (! $result) |
|
1640 | - { |
|
1641 | - $this->error=$this->db->lasterror(); |
|
1642 | - return -1; |
|
1643 | - } |
|
1644 | - $row = $this->db->fetch_row($result); |
|
1645 | - $this->ref_previous = $row[0]; |
|
1646 | - |
|
1647 | - |
|
1648 | - $sql = "SELECT MIN(te.".$fieldid.")"; |
|
1649 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
1650 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1651 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1652 | - } |
|
1653 | - 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 |
|
1654 | - 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 |
|
1655 | - 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 |
|
1656 | - 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"; |
|
1657 | - $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1658 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
1659 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
1660 | - if (! empty($filter)) |
|
1661 | - { |
|
1662 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
1663 | - $sql.=$filter; |
|
1664 | - } |
|
1665 | - 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 |
|
1666 | - 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 |
|
1667 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
|
1668 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1669 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
1670 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
1671 | - } else { |
|
1672 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
1673 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1674 | - } |
|
1675 | - } else { |
|
1676 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1677 | - } |
|
1678 | - } |
|
1679 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
1680 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
1681 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
1682 | - //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
1683 | - // 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 |
|
1684 | - |
|
1685 | - $result = $this->db->query($sql); |
|
1686 | - if (! $result) |
|
1687 | - { |
|
1688 | - $this->error=$this->db->lasterror(); |
|
1689 | - return -2; |
|
1690 | - } |
|
1691 | - $row = $this->db->fetch_row($result); |
|
1692 | - $this->ref_next = $row[0]; |
|
1693 | - |
|
1694 | - return 1; |
|
1695 | - } |
|
1696 | - |
|
1697 | - |
|
1698 | - /** |
|
1699 | - * Return list of id of contacts of object |
|
1700 | - * |
|
1701 | - * @param string $source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe) |
|
1702 | - * @return array Array of id of contacts (if source=external or internal) |
|
1703 | - * Array of id of third parties with at least one contact on object (if source=thirdparty) |
|
1704 | - */ |
|
1705 | - function getListContactId($source='external') |
|
1706 | - { |
|
1707 | - $contactAlreadySelected = array(); |
|
1708 | - $tab = $this->liste_contact(-1,$source); |
|
1709 | - $num=count($tab); |
|
1710 | - $i = 0; |
|
1711 | - while ($i < $num) |
|
1712 | - { |
|
1713 | - if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
1714 | - else $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
1715 | - $i++; |
|
1716 | - } |
|
1717 | - return $contactAlreadySelected; |
|
1718 | - } |
|
1719 | - |
|
1720 | - |
|
1721 | - /** |
|
1722 | - * Link element with a project |
|
1723 | - * |
|
1724 | - * @param int $projectid Project id to link element to |
|
1725 | - * @return int <0 if KO, >0 if OK |
|
1726 | - */ |
|
1727 | - function setProject($projectid) |
|
1728 | - { |
|
1729 | - if (! $this->table_element) |
|
1730 | - { |
|
1731 | - dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
1732 | - return -1; |
|
1733 | - } |
|
1734 | - |
|
1735 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1736 | - if ($this->table_element == 'actioncomm') |
|
1737 | - { |
|
1738 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
1739 | - else $sql.= ' SET fk_project = NULL'; |
|
1740 | - $sql.= ' WHERE id = '.$this->id; |
|
1741 | - } |
|
1742 | - else |
|
1743 | - { |
|
1744 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
1745 | - else $sql.= ' SET fk_projet = NULL'; |
|
1746 | - $sql.= ' WHERE rowid = '.$this->id; |
|
1747 | - } |
|
1748 | - |
|
1749 | - dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
|
1750 | - if ($this->db->query($sql)) |
|
1751 | - { |
|
1752 | - $this->fk_project = $projectid; |
|
1753 | - return 1; |
|
1754 | - } |
|
1755 | - else |
|
1756 | - { |
|
1757 | - dol_print_error($this->db); |
|
1758 | - return -1; |
|
1759 | - } |
|
1760 | - } |
|
1761 | - |
|
1762 | - /** |
|
1763 | - * Change the payments methods |
|
1764 | - * |
|
1765 | - * @param int $id Id of new payment method |
|
1766 | - * @return int >0 if OK, <0 if KO |
|
1767 | - */ |
|
1768 | - function setPaymentMethods($id) |
|
1769 | - { |
|
1770 | - dol_syslog(get_class($this).'::setPaymentMethods('.$id.')'); |
|
1771 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
1772 | - { |
|
1773 | - // TODO uniformize field name |
|
1774 | - $fieldname = 'fk_mode_reglement'; |
|
1775 | - if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
|
1776 | - if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
|
1777 | - |
|
1778 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1779 | - $sql .= ' SET '.$fieldname.' = '.$id; |
|
1780 | - $sql .= ' WHERE rowid='.$this->id; |
|
1781 | - |
|
1782 | - if ($this->db->query($sql)) |
|
1783 | - { |
|
1784 | - $this->mode_reglement_id = $id; |
|
1785 | - // for supplier |
|
1786 | - if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
|
1787 | - return 1; |
|
1788 | - } |
|
1789 | - else |
|
1790 | - { |
|
1791 | - dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
|
1792 | - $this->error=$this->db->error(); |
|
1793 | - return -1; |
|
1794 | - } |
|
1795 | - } |
|
1796 | - else |
|
1797 | - { |
|
1798 | - dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
|
1799 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
1800 | - return -2; |
|
1801 | - } |
|
1802 | - } |
|
1803 | - |
|
1804 | - /** |
|
1805 | - * Change the multicurrency code |
|
1806 | - * |
|
1807 | - * @param string $code multicurrency code |
|
1808 | - * @return int >0 if OK, <0 if KO |
|
1809 | - */ |
|
1810 | - function setMulticurrencyCode($code) |
|
1811 | - { |
|
1812 | - dol_syslog(get_class($this).'::setMulticurrencyCode('.$id.')'); |
|
1813 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
1814 | - { |
|
1815 | - $fieldname = 'multicurrency_code'; |
|
1816 | - |
|
1817 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1818 | - $sql .= ' SET '.$fieldname." = '".$this->db->escape($code)."'"; |
|
1819 | - $sql .= ' WHERE rowid='.$this->id; |
|
1820 | - |
|
1821 | - if ($this->db->query($sql)) |
|
1822 | - { |
|
1823 | - $this->multicurrency_code = $code; |
|
631 | + $out.='<!-- END Part to show address block -->'; |
|
1824 | 632 | |
1825 | - list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
|
1826 | - if ($rate) $this->setMulticurrencyRate($rate,2); |
|
633 | + return $out; |
|
634 | + } |
|
1827 | 635 | |
1828 | - return 1; |
|
1829 | - } |
|
1830 | - else |
|
1831 | - { |
|
1832 | - dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
|
1833 | - $this->error=$this->db->error(); |
|
1834 | - return -1; |
|
1835 | - } |
|
1836 | - } |
|
1837 | - else |
|
1838 | - { |
|
1839 | - dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
|
1840 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
1841 | - return -2; |
|
1842 | - } |
|
1843 | - } |
|
1844 | - |
|
1845 | - /** |
|
1846 | - * Change the multicurrency rate |
|
1847 | - * |
|
1848 | - * @param double $rate multicurrency rate |
|
1849 | - * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
|
1850 | - * @return int >0 if OK, <0 if KO |
|
1851 | - */ |
|
1852 | - function setMulticurrencyRate($rate, $mode=1) |
|
1853 | - { |
|
1854 | - dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')'); |
|
1855 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
1856 | - { |
|
1857 | - $fieldname = 'multicurrency_tx'; |
|
1858 | - |
|
1859 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1860 | - $sql .= ' SET '.$fieldname.' = '.$rate; |
|
1861 | - $sql .= ' WHERE rowid='.$this->id; |
|
1862 | - |
|
1863 | - if ($this->db->query($sql)) |
|
1864 | - { |
|
1865 | - $this->multicurrency_tx = $rate; |
|
1866 | - |
|
1867 | - // Update line price |
|
1868 | - if (!empty($this->lines)) |
|
1869 | - { |
|
1870 | - foreach ($this->lines as &$line) |
|
1871 | - { |
|
1872 | - if($mode == 1) { |
|
1873 | - $line->subprice = 0; |
|
1874 | - } |
|
1875 | - |
|
1876 | - switch ($this->element) { |
|
1877 | - case 'propal': |
|
1878 | - $this->updateline( |
|
1879 | - $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
1880 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
1881 | - $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, |
|
1882 | - $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
1883 | - ); |
|
1884 | - break; |
|
1885 | - case 'commande': |
|
1886 | - $this->updateline( |
|
1887 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1888 | - $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, |
|
1889 | - $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
1890 | - $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
1891 | - ); |
|
1892 | - break; |
|
1893 | - case 'facture': |
|
1894 | - $this->updateline( |
|
1895 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1896 | - $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, |
|
1897 | - $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
1898 | - $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice |
|
1899 | - ); |
|
1900 | - break; |
|
1901 | - case 'supplier_proposal': |
|
1902 | - $this->updateline( |
|
1903 | - $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
1904 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
1905 | - $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, |
|
1906 | - $line->ref_fourn, $line->multicurrency_subprice |
|
1907 | - ); |
|
1908 | - break; |
|
1909 | - case 'order_supplier': |
|
1910 | - $this->updateline( |
|
1911 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1912 | - $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, |
|
1913 | - $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
1914 | - ); |
|
1915 | - break; |
|
1916 | - case 'invoice_supplier': |
|
1917 | - $this->updateline( |
|
1918 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
1919 | - $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, |
|
1920 | - $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
1921 | - ); |
|
1922 | - break; |
|
1923 | - default: |
|
1924 | - dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); |
|
1925 | - break; |
|
1926 | - } |
|
1927 | - } |
|
1928 | - } |
|
636 | + /** |
|
637 | + * Return the link of last main doc file for direct public download. |
|
638 | + * |
|
639 | + * @param string $modulepart Module related to document |
|
640 | + * @param int $initsharekey Init the share key if it was not yet defined |
|
641 | + * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
|
642 | + * @return string Link or empty string if there is no download link |
|
643 | + */ |
|
644 | + function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
645 | + { |
|
646 | + global $user, $dolibarr_main_url_root; |
|
1929 | 647 | |
1930 | - return 1; |
|
1931 | - } |
|
1932 | - else |
|
1933 | - { |
|
1934 | - dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
|
1935 | - $this->error=$this->db->error(); |
|
1936 | - return -1; |
|
1937 | - } |
|
1938 | - } |
|
1939 | - else |
|
1940 | - { |
|
1941 | - dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
|
1942 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
1943 | - return -2; |
|
1944 | - } |
|
1945 | - } |
|
1946 | - |
|
1947 | - /** |
|
1948 | - * Change the payments terms |
|
1949 | - * |
|
1950 | - * @param int $id Id of new payment terms |
|
1951 | - * @return int >0 if OK, <0 if KO |
|
1952 | - */ |
|
1953 | - function setPaymentTerms($id) |
|
1954 | - { |
|
1955 | - dol_syslog(get_class($this).'::setPaymentTerms('.$id.')'); |
|
1956 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
1957 | - { |
|
1958 | - // TODO uniformize field name |
|
1959 | - $fieldname = 'fk_cond_reglement'; |
|
1960 | - if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
|
1961 | - if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
|
1962 | - |
|
1963 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1964 | - $sql .= ' SET '.$fieldname.' = '.$id; |
|
1965 | - $sql .= ' WHERE rowid='.$this->id; |
|
1966 | - |
|
1967 | - if ($this->db->query($sql)) |
|
1968 | - { |
|
1969 | - $this->cond_reglement_id = $id; |
|
1970 | - // for supplier |
|
1971 | - if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
|
1972 | - $this->cond_reglement = $id; // for compatibility |
|
1973 | - return 1; |
|
1974 | - } |
|
1975 | - else |
|
1976 | - { |
|
1977 | - dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
|
1978 | - $this->error=$this->db->error(); |
|
1979 | - return -1; |
|
1980 | - } |
|
1981 | - } |
|
1982 | - else |
|
1983 | - { |
|
1984 | - dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
|
1985 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
1986 | - return -2; |
|
1987 | - } |
|
1988 | - } |
|
1989 | - |
|
1990 | - /** |
|
1991 | - * Define delivery address |
|
1992 | - * @deprecated |
|
1993 | - * |
|
1994 | - * @param int $id Address id |
|
1995 | - * @return int <0 si ko, >0 si ok |
|
1996 | - */ |
|
1997 | - function setDeliveryAddress($id) |
|
1998 | - { |
|
1999 | - $fieldname = 'fk_delivery_address'; |
|
2000 | - if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
|
2001 | - |
|
2002 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
|
2003 | - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
2004 | - |
|
2005 | - if ($this->db->query($sql)) |
|
2006 | - { |
|
2007 | - $this->fk_delivery_address = $id; |
|
2008 | - return 1; |
|
2009 | - } |
|
2010 | - else |
|
2011 | - { |
|
2012 | - $this->error=$this->db->error(); |
|
2013 | - dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
|
2014 | - return -1; |
|
2015 | - } |
|
2016 | - } |
|
2017 | - |
|
2018 | - |
|
2019 | - /** |
|
2020 | - * Change the shipping method |
|
2021 | - * |
|
2022 | - * @param int $shipping_method_id Id of shipping method |
|
2023 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
2024 | - * @param User $userused Object user |
|
2025 | - * |
|
2026 | - * @return int 1 if OK, 0 if KO |
|
2027 | - */ |
|
2028 | - function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
2029 | - { |
|
2030 | - global $user; |
|
648 | + if (empty($this->last_main_doc)) |
|
649 | + { |
|
650 | + return ''; // No way to known which document name to use |
|
651 | + } |
|
2031 | 652 | |
2032 | - if (empty($userused)) $userused=$user; |
|
653 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
654 | + $ecmfile=new EcmFiles($this->db); |
|
655 | + $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
|
656 | + if ($result < 0) |
|
657 | + { |
|
658 | + $this->error = $ecmfile->error; |
|
659 | + $this->errors = $ecmfile->errors; |
|
660 | + return -1; |
|
661 | + } |
|
2033 | 662 | |
2034 | - $error = 0; |
|
663 | + if (empty($ecmfile->id)) |
|
664 | + { |
|
665 | + // Add entry into index |
|
666 | + if ($initsharekey) |
|
667 | + { |
|
668 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
669 | + // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first |
|
670 | + /* |
|
671 | + $ecmfile->filepath = $rel_dir; |
|
672 | + $ecmfile->filename = $filename; |
|
673 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
674 | + $ecmfile->fullpath_orig = ''; |
|
675 | + $ecmfile->gen_or_uploaded = 'generated'; |
|
676 | + $ecmfile->description = ''; // indexed content |
|
677 | + $ecmfile->keyword = ''; // keyword content |
|
678 | + $ecmfile->share = getRandomPassword(true); |
|
679 | + $result = $ecmfile->create($user); |
|
680 | + if ($result < 0) |
|
681 | + { |
|
682 | + $this->error = $ecmfile->error; |
|
683 | + $this->errors = $ecmfile->errors; |
|
684 | + } |
|
685 | + */ |
|
686 | + } |
|
687 | + else return ''; |
|
688 | + } |
|
689 | + elseif (empty($ecmfile->share)) |
|
690 | + { |
|
691 | + // Add entry into index |
|
692 | + if ($initsharekey) |
|
693 | + { |
|
694 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
695 | + $ecmfile->share = getRandomPassword(true); |
|
696 | + $ecmfile->update($user); |
|
697 | + } |
|
698 | + else return ''; |
|
699 | + } |
|
2035 | 700 | |
2036 | - if (! $this->table_element) { |
|
2037 | - dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
2038 | - return -1; |
|
2039 | - } |
|
701 | + // Define $urlwithroot |
|
702 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
703 | + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
704 | + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
2040 | 705 | |
2041 | - $this->db->begin(); |
|
706 | + $forcedownload=0; |
|
2042 | 707 | |
2043 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
2044 | - dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); |
|
708 | + $paramlink=''; |
|
709 | + //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
|
710 | + //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
|
711 | + //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
|
712 | + if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
713 | + if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
2045 | 714 | |
2046 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2047 | - $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
2048 | - $sql.= " WHERE rowid=".$this->id; |
|
2049 | - $resql = $this->db->query($sql); |
|
2050 | - if (! $resql) { |
|
2051 | - dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
|
2052 | - $this->error = $this->db->lasterror(); |
|
2053 | - $error++; |
|
2054 | - } else { |
|
2055 | - if (!$notrigger) |
|
2056 | - { |
|
2057 | - // Call trigger |
|
2058 | - $this->context=array('shippingmethodupdate'=>1); |
|
2059 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
2060 | - if ($result < 0) $error++; |
|
2061 | - // End call trigger |
|
2062 | - } |
|
715 | + if ($relativelink) |
|
716 | + { |
|
717 | + $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
2063 | 718 | } |
2064 | - if ($error) |
|
719 | + else |
|
2065 | 720 | { |
2066 | - $this->db->rollback(); |
|
2067 | - return -1; |
|
2068 | - } else { |
|
2069 | - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
2070 | - $this->db->commit(); |
|
2071 | - return 1; |
|
721 | + $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
2072 | 722 | } |
2073 | - } |
|
2074 | - |
|
2075 | - |
|
2076 | - /** |
|
2077 | - * Change the warehouse |
|
2078 | - * |
|
2079 | - * @param int $warehouse_id Id of warehouse |
|
2080 | - * @return int 1 if OK, 0 if KO |
|
2081 | - */ |
|
2082 | - function setWarehouse($warehouse_id) |
|
2083 | - { |
|
2084 | - if (! $this->table_element) { |
|
2085 | - dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
2086 | - return -1; |
|
2087 | - } |
|
2088 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
2089 | - dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); |
|
2090 | - |
|
2091 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2092 | - $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
2093 | - $sql.= " WHERE rowid=".$this->id; |
|
2094 | - |
|
2095 | - if ($this->db->query($sql)) { |
|
2096 | - $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
2097 | - return 1; |
|
2098 | - } else { |
|
2099 | - dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
|
2100 | - $this->error=$this->db->error(); |
|
2101 | - return 0; |
|
2102 | - } |
|
2103 | - } |
|
2104 | - |
|
2105 | - |
|
2106 | - /** |
|
2107 | - * Set last model used by doc generator |
|
2108 | - * |
|
2109 | - * @param User $user User object that make change |
|
2110 | - * @param string $modelpdf Modele name |
|
2111 | - * @return int <0 if KO, >0 if OK |
|
2112 | - */ |
|
2113 | - function setDocModel($user, $modelpdf) |
|
2114 | - { |
|
2115 | - if (! $this->table_element) |
|
2116 | - { |
|
2117 | - dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
2118 | - return -1; |
|
2119 | - } |
|
2120 | - |
|
2121 | - $newmodelpdf=dol_trunc($modelpdf,255); |
|
2122 | - |
|
2123 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2124 | - $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
2125 | - $sql.= " WHERE rowid = ".$this->id; |
|
2126 | - // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
|
2127 | - // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
|
2128 | - |
|
2129 | - dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
|
2130 | - $resql=$this->db->query($sql); |
|
2131 | - if ($resql) |
|
2132 | - { |
|
2133 | - $this->modelpdf=$modelpdf; |
|
2134 | - return 1; |
|
2135 | - } |
|
2136 | - else |
|
2137 | - { |
|
2138 | - dol_print_error($this->db); |
|
2139 | - return 0; |
|
2140 | - } |
|
2141 | - } |
|
2142 | - |
|
2143 | - |
|
2144 | - /** |
|
2145 | - * Change the bank account |
|
2146 | - * |
|
2147 | - * @param int $fk_account Id of bank account |
|
2148 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
2149 | - * @param User $userused Object user |
|
2150 | - * @return int 1 if OK, 0 if KO |
|
2151 | - */ |
|
2152 | - function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
2153 | - { |
|
2154 | - global $user; |
|
2155 | 723 | |
2156 | - if (empty($userused)) $userused=$user; |
|
724 | + // Here $ecmfile->share is defined |
|
725 | + return $linktoreturn; |
|
726 | + } |
|
2157 | 727 | |
2158 | - $error = 0; |
|
2159 | 728 | |
2160 | - if (! $this->table_element) { |
|
2161 | - dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
2162 | - return -1; |
|
2163 | - } |
|
2164 | - $this->db->begin(); |
|
729 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
730 | + /** |
|
731 | + * Add a link between element $this->element and a contact |
|
732 | + * |
|
733 | + * @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link |
|
734 | + * @param int $type_contact Type of contact (code or id). Must be id or code found into table llx_c_type_contact. For example: SALESREPFOLL |
|
735 | + * @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) |
|
736 | + * @param int $notrigger Disable all triggers |
|
737 | + * @return int <0 if KO, >0 if OK |
|
738 | + */ |
|
739 | + function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
740 | + { |
|
741 | + // phpcs:enable |
|
742 | + global $user,$langs; |
|
2165 | 743 | |
2166 | - if ($fk_account<0) $fk_account='NULL'; |
|
2167 | - dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); |
|
2168 | 744 | |
2169 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2170 | - $sql.= " SET fk_account = ".$fk_account; |
|
2171 | - $sql.= " WHERE rowid=".$this->id; |
|
745 | + dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
|
2172 | 746 | |
2173 | - $resql = $this->db->query($sql); |
|
2174 | - if (! $resql) |
|
747 | + // Check parameters |
|
748 | + if ($fk_socpeople <= 0) |
|
2175 | 749 | { |
2176 | - dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
|
2177 | - $this->error = $this->db->lasterror(); |
|
2178 | - $error++; |
|
750 | + $langs->load("errors"); |
|
751 | + $this->error=$langs->trans("ErrorWrongValueForParameterX","1"); |
|
752 | + dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
753 | + return -1; |
|
2179 | 754 | } |
2180 | - else |
|
755 | + if (! $type_contact) |
|
2181 | 756 | { |
2182 | - if (!$notrigger) |
|
2183 | - { |
|
2184 | - // Call trigger |
|
2185 | - $this->context=array('bankaccountupdate'=>1); |
|
2186 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
2187 | - if ($result < 0) $error++; |
|
2188 | - // End call trigger |
|
2189 | - } |
|
757 | + $langs->load("errors"); |
|
758 | + $this->error=$langs->trans("ErrorWrongValueForParameterX","2"); |
|
759 | + dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
760 | + return -2; |
|
2190 | 761 | } |
2191 | - if ($error) |
|
762 | + |
|
763 | + $id_type_contact=0; |
|
764 | + if (is_numeric($type_contact)) |
|
2192 | 765 | { |
2193 | - $this->db->rollback(); |
|
2194 | - return -1; |
|
766 | + $id_type_contact=$type_contact; |
|
2195 | 767 | } |
2196 | 768 | else |
2197 | 769 | { |
2198 | - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
2199 | - $this->db->commit(); |
|
2200 | - return 1; |
|
770 | + // We look for id type_contact |
|
771 | + $sql = "SELECT tc.rowid"; |
|
772 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
773 | + $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
774 | + $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
775 | + $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
776 | + //print $sql; |
|
777 | + $resql=$this->db->query($sql); |
|
778 | + if ($resql) |
|
779 | + { |
|
780 | + $obj = $this->db->fetch_object($resql); |
|
781 | + if ($obj) $id_type_contact=$obj->rowid; |
|
782 | + } |
|
2201 | 783 | } |
2202 | - } |
|
2203 | - |
|
2204 | 784 | |
2205 | - // TODO: Move line related operations to CommonObjectLine? |
|
2206 | - |
|
2207 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2208 | - /** |
|
2209 | - * Save a new position (field rang) for details lines. |
|
2210 | - * You can choose to set position for lines with already a position or lines without any position defined. |
|
2211 | - * |
|
2212 | - * @param boolean $renum True to renum all already ordered lines, false to renum only not already ordered lines. |
|
2213 | - * @param string $rowidorder ASC or DESC |
|
2214 | - * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
2215 | - * @return int <0 if KO, >0 if OK |
|
2216 | - */ |
|
2217 | - function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
2218 | - { |
|
2219 | - // phpcs:enable |
|
2220 | - if (! $this->table_element_line) |
|
2221 | - { |
|
2222 | - dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
2223 | - return -1; |
|
2224 | - } |
|
2225 | - if (! $this->fk_element) |
|
2226 | - { |
|
2227 | - dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
2228 | - return -1; |
|
2229 | - } |
|
2230 | - |
|
2231 | - // Count number of lines to reorder (according to choice $renum) |
|
2232 | - $nl=0; |
|
2233 | - $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2234 | - $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
2235 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
2236 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
2237 | - |
|
2238 | - dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
|
2239 | - $resql = $this->db->query($sql); |
|
2240 | - if ($resql) |
|
2241 | - { |
|
2242 | - $row = $this->db->fetch_row($resql); |
|
2243 | - $nl = $row[0]; |
|
2244 | - } |
|
2245 | - else dol_print_error($this->db); |
|
2246 | - if ($nl > 0) |
|
2247 | - { |
|
2248 | - // The goal of this part is to reorder all lines, with all children lines sharing the same |
|
2249 | - // counter that parents. |
|
2250 | - $rows=array(); |
|
2251 | - |
|
2252 | - // We first search all lines that are parent lines (for multilevel details lines) |
|
2253 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2254 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2255 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
2256 | - $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
2257 | - |
|
2258 | - dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
|
2259 | - $resql = $this->db->query($sql); |
|
2260 | - if ($resql) |
|
2261 | - { |
|
2262 | - $i=0; |
|
2263 | - $num = $this->db->num_rows($resql); |
|
2264 | - while ($i < $num) |
|
2265 | - { |
|
2266 | - $row = $this->db->fetch_row($resql); |
|
2267 | - $rows[] = $row[0]; // Add parent line into array rows |
|
2268 | - $childrens = $this->getChildrenOfLine($row[0]); |
|
2269 | - if (! empty($childrens)) |
|
2270 | - { |
|
2271 | - foreach($childrens as $child) |
|
2272 | - { |
|
2273 | - array_push($rows, $child); |
|
2274 | - } |
|
2275 | - } |
|
2276 | - $i++; |
|
2277 | - } |
|
785 | + if ($id_type_contact == 0) |
|
786 | + { |
|
787 | + $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
788 | + 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"); |
|
789 | + return -3; |
|
790 | + } |
|
2278 | 791 | |
2279 | - // Now we set a new number for each lines (parent and children with children included into parent tree) |
|
2280 | - if (! empty($rows)) |
|
2281 | - { |
|
2282 | - foreach($rows as $key => $row) |
|
2283 | - { |
|
2284 | - $this->updateRangOfLine($row, ($key+1)); |
|
2285 | - } |
|
2286 | - } |
|
2287 | - } |
|
2288 | - else |
|
2289 | - { |
|
2290 | - dol_print_error($this->db); |
|
2291 | - } |
|
2292 | - } |
|
2293 | - return 1; |
|
2294 | - } |
|
2295 | - |
|
2296 | - /** |
|
2297 | - * Get children of line |
|
2298 | - * |
|
2299 | - * @param int $id Id of parent line |
|
2300 | - * @return array Array with list of children lines id |
|
2301 | - */ |
|
2302 | - function getChildrenOfLine($id) |
|
2303 | - { |
|
2304 | - $rows=array(); |
|
2305 | - |
|
2306 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2307 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2308 | - $sql.= ' AND fk_parent_line = '.$id; |
|
2309 | - $sql.= ' ORDER BY rang ASC'; |
|
2310 | - |
|
2311 | - dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
|
2312 | - $resql = $this->db->query($sql); |
|
2313 | - if ($resql) |
|
2314 | - { |
|
2315 | - $i=0; |
|
2316 | - $num = $this->db->num_rows($resql); |
|
2317 | - while ($i < $num) |
|
2318 | - { |
|
2319 | - $row = $this->db->fetch_row($resql); |
|
2320 | - $rows[$i] = $row[0]; |
|
2321 | - $i++; |
|
2322 | - } |
|
2323 | - } |
|
792 | + $datecreate = dol_now(); |
|
793 | + |
|
794 | + // Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
|
795 | + $TListeContacts=$this->liste_contact(-1, $source); |
|
796 | + $already_added=false; |
|
797 | + if(!empty($TListeContacts)) { |
|
798 | + foreach($TListeContacts as $array_contact) { |
|
799 | + if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { |
|
800 | + $already_added=true; |
|
801 | + break; |
|
802 | + } |
|
803 | + } |
|
804 | + } |
|
2324 | 805 | |
2325 | - return $rows; |
|
2326 | - } |
|
806 | + if(!$already_added) { |
|
2327 | 807 | |
2328 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2329 | - /** |
|
2330 | - * Update a line to have a lower rank |
|
2331 | - * |
|
2332 | - * @param int $rowid Id of line |
|
2333 | - * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
2334 | - * @return void |
|
2335 | - */ |
|
2336 | - function line_up($rowid, $fk_parent_line=true) |
|
2337 | - { |
|
2338 | - // phpcs:enable |
|
2339 | - $this->line_order(false, 'ASC', $fk_parent_line); |
|
808 | + $this->db->begin(); |
|
2340 | 809 | |
2341 | - // Get rang of line |
|
2342 | - $rang = $this->getRangOfLine($rowid); |
|
810 | + // Insert into database |
|
811 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
|
812 | + $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
813 | + $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; |
|
814 | + $sql.= "'".$this->db->idate($datecreate)."'"; |
|
815 | + $sql.= ", 4, ". $id_type_contact; |
|
816 | + $sql.= ")"; |
|
2343 | 817 | |
2344 | - // Update position of line |
|
2345 | - $this->updateLineUp($rowid, $rang); |
|
2346 | - } |
|
818 | + $resql=$this->db->query($sql); |
|
819 | + if ($resql) |
|
820 | + { |
|
821 | + if (! $notrigger) |
|
822 | + { |
|
823 | + $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
824 | + if ($result < 0) |
|
825 | + { |
|
826 | + $this->db->rollback(); |
|
827 | + return -1; |
|
828 | + } |
|
829 | + } |
|
830 | + |
|
831 | + $this->db->commit(); |
|
832 | + return 1; |
|
833 | + } |
|
834 | + else |
|
835 | + { |
|
836 | + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
837 | + { |
|
838 | + $this->error=$this->db->errno(); |
|
839 | + $this->db->rollback(); |
|
840 | + echo 'err rollback'; |
|
841 | + return -2; |
|
842 | + } |
|
843 | + else |
|
844 | + { |
|
845 | + $this->error=$this->db->error(); |
|
846 | + $this->db->rollback(); |
|
847 | + return -1; |
|
848 | + } |
|
849 | + } |
|
850 | + } else return 0; |
|
851 | + } |
|
2347 | 852 | |
2348 | 853 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
2349 | - /** |
|
2350 | - * Update a line to have a higher rank |
|
2351 | - * |
|
2352 | - * @param int $rowid Id of line |
|
2353 | - * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
2354 | - * @return void |
|
2355 | - */ |
|
2356 | - function line_down($rowid, $fk_parent_line=true) |
|
2357 | - { |
|
854 | + /** |
|
855 | + * Copy contact from one element to current |
|
856 | + * |
|
857 | + * @param CommonObject $objFrom Source element |
|
858 | + * @param string $source Nature of contact ('internal' or 'external') |
|
859 | + * @return int >0 if OK, <0 if KO |
|
860 | + */ |
|
861 | + function copy_linked_contact($objFrom, $source='internal') |
|
862 | + { |
|
2358 | 863 | // phpcs:enable |
2359 | - $this->line_order(false, 'ASC', $fk_parent_line); |
|
2360 | - |
|
2361 | - // Get rang of line |
|
2362 | - $rang = $this->getRangOfLine($rowid); |
|
2363 | - |
|
2364 | - // Get max value for rang |
|
2365 | - $max = $this->line_max(); |
|
2366 | - |
|
2367 | - // Update position of line |
|
2368 | - $this->updateLineDown($rowid, $rang, $max); |
|
2369 | - } |
|
2370 | - |
|
2371 | - /** |
|
2372 | - * Update position of line (rang) |
|
2373 | - * |
|
2374 | - * @param int $rowid Id of line |
|
2375 | - * @param int $rang Position |
|
2376 | - * @return void |
|
2377 | - */ |
|
2378 | - function updateRangOfLine($rowid,$rang) |
|
2379 | - { |
|
2380 | - $fieldposition = 'rang'; |
|
2381 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
|
2382 | - |
|
2383 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
2384 | - $sql.= ' WHERE rowid = '.$rowid; |
|
2385 | - |
|
2386 | - dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
|
2387 | - if (! $this->db->query($sql)) |
|
2388 | - { |
|
2389 | - dol_print_error($this->db); |
|
2390 | - } |
|
2391 | - } |
|
864 | + $contacts = $objFrom->liste_contact(-1, $source); |
|
865 | + foreach($contacts as $contact) |
|
866 | + { |
|
867 | + if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
|
868 | + { |
|
869 | + $this->error=$this->db->lasterror(); |
|
870 | + return -1; |
|
871 | + } |
|
872 | + } |
|
873 | + return 1; |
|
874 | + } |
|
2392 | 875 | |
2393 | 876 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
2394 | - /** |
|
2395 | - * Update position of line with ajax (rang) |
|
2396 | - * |
|
2397 | - * @param array $rows Array of rows |
|
2398 | - * @return void |
|
2399 | - */ |
|
2400 | - function line_ajaxorder($rows) |
|
2401 | - { |
|
877 | + /** |
|
878 | + * Update a link to contact line |
|
879 | + * |
|
880 | + * @param int $rowid Id of line contact-element |
|
881 | + * @param int $statut New status of link |
|
882 | + * @param int $type_contact_id Id of contact type (not modified if 0) |
|
883 | + * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
|
884 | + * @return int <0 if KO, >= 0 if OK |
|
885 | + */ |
|
886 | + function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
887 | + { |
|
2402 | 888 | // phpcs:enable |
2403 | - $num = count($rows); |
|
2404 | - for ($i = 0 ; $i < $num ; $i++) |
|
2405 | - { |
|
2406 | - $this->updateRangOfLine($rows[$i], ($i+1)); |
|
2407 | - } |
|
2408 | - } |
|
2409 | - |
|
2410 | - /** |
|
2411 | - * Update position of line up (rang) |
|
2412 | - * |
|
2413 | - * @param int $rowid Id of line |
|
2414 | - * @param int $rang Position |
|
2415 | - * @return void |
|
2416 | - */ |
|
2417 | - function updateLineUp($rowid,$rang) |
|
2418 | - { |
|
2419 | - if ($rang > 1) |
|
2420 | - { |
|
2421 | - $fieldposition = 'rang'; |
|
2422 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
|
2423 | - |
|
2424 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
|
2425 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2426 | - $sql.= ' AND rang = '.($rang - 1); |
|
2427 | - if ($this->db->query($sql) ) |
|
2428 | - { |
|
2429 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
|
2430 | - $sql.= ' WHERE rowid = '.$rowid; |
|
2431 | - if (! $this->db->query($sql) ) |
|
2432 | - { |
|
2433 | - dol_print_error($this->db); |
|
2434 | - } |
|
2435 | - } |
|
2436 | - else |
|
2437 | - { |
|
2438 | - dol_print_error($this->db); |
|
2439 | - } |
|
2440 | - } |
|
2441 | - } |
|
2442 | - |
|
2443 | - /** |
|
2444 | - * Update position of line down (rang) |
|
2445 | - * |
|
2446 | - * @param int $rowid Id of line |
|
2447 | - * @param int $rang Position |
|
2448 | - * @param int $max Max |
|
2449 | - * @return void |
|
2450 | - */ |
|
2451 | - function updateLineDown($rowid,$rang,$max) |
|
2452 | - { |
|
2453 | - if ($rang < $max) |
|
2454 | - { |
|
2455 | - $fieldposition = 'rang'; |
|
2456 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
|
2457 | - |
|
2458 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
2459 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2460 | - $sql.= ' AND rang = '.($rang+1); |
|
2461 | - if ($this->db->query($sql) ) |
|
2462 | - { |
|
2463 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang+1); |
|
2464 | - $sql.= ' WHERE rowid = '.$rowid; |
|
2465 | - if (! $this->db->query($sql) ) |
|
2466 | - { |
|
2467 | - dol_print_error($this->db); |
|
2468 | - } |
|
2469 | - } |
|
2470 | - else |
|
2471 | - { |
|
2472 | - dol_print_error($this->db); |
|
2473 | - } |
|
2474 | - } |
|
2475 | - } |
|
2476 | - |
|
2477 | - /** |
|
2478 | - * Get position of line (rang) |
|
2479 | - * |
|
2480 | - * @param int $rowid Id of line |
|
2481 | - * @return int Value of rang in table of lines |
|
2482 | - */ |
|
2483 | - function getRangOfLine($rowid) |
|
2484 | - { |
|
2485 | - $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2486 | - $sql.= ' WHERE rowid ='.$rowid; |
|
2487 | - |
|
2488 | - dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
|
2489 | - $resql = $this->db->query($sql); |
|
2490 | - if ($resql) |
|
2491 | - { |
|
2492 | - $row = $this->db->fetch_row($resql); |
|
2493 | - return $row[0]; |
|
2494 | - } |
|
2495 | - } |
|
2496 | - |
|
2497 | - /** |
|
2498 | - * Get rowid of the line relative to its position |
|
2499 | - * |
|
2500 | - * @param int $rang Rang value |
|
2501 | - * @return int Rowid of the line |
|
2502 | - */ |
|
2503 | - function getIdOfLine($rang) |
|
2504 | - { |
|
2505 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2506 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2507 | - $sql.= ' AND rang = '.$rang; |
|
2508 | - $resql = $this->db->query($sql); |
|
2509 | - if ($resql) |
|
2510 | - { |
|
2511 | - $row = $this->db->fetch_row($resql); |
|
2512 | - return $row[0]; |
|
2513 | - } |
|
2514 | - } |
|
889 | + // Insert into database |
|
890 | + $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
|
891 | + $sql.= " statut = ".$statut; |
|
892 | + if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
893 | + if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
894 | + $sql.= " where rowid = ".$rowid; |
|
895 | + $resql=$this->db->query($sql); |
|
896 | + if ($resql) |
|
897 | + { |
|
898 | + return 0; |
|
899 | + } |
|
900 | + else |
|
901 | + { |
|
902 | + $this->error=$this->db->lasterror(); |
|
903 | + return -1; |
|
904 | + } |
|
905 | + } |
|
2515 | 906 | |
2516 | 907 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
2517 | - /** |
|
2518 | - * Get max value used for position of line (rang) |
|
2519 | - * |
|
2520 | - * @param int $fk_parent_line Parent line id |
|
2521 | - * @return int Max value of rang in table of lines |
|
2522 | - */ |
|
2523 | - function line_max($fk_parent_line=0) |
|
2524 | - { |
|
908 | + /** |
|
909 | + * Delete a link to contact line |
|
910 | + * |
|
911 | + * @param int $rowid Id of contact link line to delete |
|
912 | + * @param int $notrigger Disable all triggers |
|
913 | + * @return int >0 if OK, <0 if KO |
|
914 | + */ |
|
915 | + function delete_contact($rowid, $notrigger=0) |
|
916 | + { |
|
2525 | 917 | // phpcs:enable |
2526 | - // Search the last rang with fk_parent_line |
|
2527 | - if ($fk_parent_line) |
|
2528 | - { |
|
2529 | - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2530 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2531 | - $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
2532 | - |
|
2533 | - dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
2534 | - $resql = $this->db->query($sql); |
|
2535 | - if ($resql) |
|
2536 | - { |
|
2537 | - $row = $this->db->fetch_row($resql); |
|
2538 | - if (! empty($row[0])) |
|
2539 | - { |
|
2540 | - return $row[0]; |
|
2541 | - } |
|
2542 | - else |
|
2543 | - { |
|
2544 | - return $this->getRangOfLine($fk_parent_line); |
|
2545 | - } |
|
2546 | - } |
|
2547 | - } |
|
2548 | - // If not, search the last rang of element |
|
2549 | - else |
|
2550 | - { |
|
2551 | - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2552 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2553 | - |
|
2554 | - dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
2555 | - $resql = $this->db->query($sql); |
|
2556 | - if ($resql) |
|
2557 | - { |
|
2558 | - $row = $this->db->fetch_row($resql); |
|
2559 | - return $row[0]; |
|
2560 | - } |
|
2561 | - } |
|
2562 | - } |
|
918 | + global $user; |
|
2563 | 919 | |
2564 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2565 | - /** |
|
2566 | - * Update external ref of element |
|
2567 | - * |
|
2568 | - * @param string $ref_ext Update field ref_ext |
|
2569 | - * @return int <0 if KO, >0 if OK |
|
2570 | - */ |
|
2571 | - function update_ref_ext($ref_ext) |
|
2572 | - { |
|
2573 | - // phpcs:enable |
|
2574 | - if (! $this->table_element) |
|
2575 | - { |
|
2576 | - dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
|
2577 | - return -1; |
|
2578 | - } |
|
2579 | - |
|
2580 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
2581 | - $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
2582 | - $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
2583 | - |
|
2584 | - dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
|
2585 | - if ($this->db->query($sql)) |
|
2586 | - { |
|
2587 | - $this->ref_ext = $ref_ext; |
|
2588 | - return 1; |
|
2589 | - } |
|
2590 | - else |
|
2591 | - { |
|
2592 | - $this->error=$this->db->error(); |
|
2593 | - return -1; |
|
2594 | - } |
|
2595 | - } |
|
2596 | 920 | |
2597 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2598 | - /** |
|
2599 | - * Update note of element |
|
2600 | - * |
|
2601 | - * @param string $note New value for note |
|
2602 | - * @param string $suffix '', '_public' or '_private' |
|
2603 | - * @return int <0 if KO, >0 if OK |
|
2604 | - */ |
|
2605 | - function update_note($note, $suffix='') |
|
2606 | - { |
|
2607 | - // phpcs:enable |
|
2608 | - global $user; |
|
2609 | - |
|
2610 | - if (! $this->table_element) |
|
2611 | - { |
|
2612 | - $this->error='update_note was called on objet with property table_element not defined'; |
|
2613 | - dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
|
2614 | - return -1; |
|
2615 | - } |
|
2616 | - if (! in_array($suffix,array('','_public','_private'))) |
|
2617 | - { |
|
2618 | - $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
2619 | - dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
|
2620 | - return -2; |
|
2621 | - } |
|
2622 | - // Special cas |
|
2623 | - //var_dump($this->table_element);exit; |
|
2624 | - if ($this->table_element == 'product') $suffix=''; |
|
2625 | - |
|
2626 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
2627 | - $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL"); |
|
2628 | - $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id; |
|
2629 | - $sql.= " WHERE rowid =". $this->id; |
|
2630 | - |
|
2631 | - dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
|
2632 | - if ($this->db->query($sql)) |
|
2633 | - { |
|
2634 | - if ($suffix == '_public') $this->note_public = $note; |
|
2635 | - else if ($suffix == '_private') $this->note_private = $note; |
|
2636 | - else |
|
2637 | - { |
|
2638 | - $this->note = $note; // deprecated |
|
2639 | - $this->note_private = $note; |
|
2640 | - } |
|
2641 | - return 1; |
|
2642 | - } |
|
2643 | - else |
|
2644 | - { |
|
2645 | - $this->error=$this->db->lasterror(); |
|
2646 | - return -1; |
|
2647 | - } |
|
2648 | - } |
|
921 | + $this->db->begin(); |
|
2649 | 922 | |
2650 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2651 | - /** |
|
2652 | - * Update public note (kept for backward compatibility) |
|
2653 | - * |
|
2654 | - * @param string $note New value for note |
|
2655 | - * @return int <0 if KO, >0 if OK |
|
2656 | - * @deprecated |
|
2657 | - * @see update_note() |
|
2658 | - */ |
|
2659 | - function update_note_public($note) |
|
2660 | - { |
|
2661 | - // phpcs:enable |
|
2662 | - return $this->update_note($note,'_public'); |
|
2663 | - } |
|
923 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
924 | + $sql.= " WHERE rowid =".$rowid; |
|
925 | + |
|
926 | + dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
|
927 | + if ($this->db->query($sql)) |
|
928 | + { |
|
929 | + if (! $notrigger) |
|
930 | + { |
|
931 | + $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
932 | + if ($result < 0) { $this->db->rollback(); return -1; } |
|
933 | + } |
|
934 | + |
|
935 | + $this->db->commit(); |
|
936 | + return 1; |
|
937 | + } |
|
938 | + else |
|
939 | + { |
|
940 | + $this->error=$this->db->lasterror(); |
|
941 | + $this->db->rollback(); |
|
942 | + return -1; |
|
943 | + } |
|
944 | + } |
|
2664 | 945 | |
2665 | 946 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
2666 | - /** |
|
2667 | - * Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines). |
|
2668 | - * Must be called at end of methods addline or updateline. |
|
2669 | - * |
|
2670 | - * @param int $exclspec >0 = Exclude special product (product_type=9) |
|
2671 | - * @param string $roundingadjust 'none'=Do nothing, 'auto'=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND if defined, or '0'), '0'=Force mode total of rounding, '1'=Force mode rounding of total |
|
2672 | - * @param int $nodatabaseupdate 1=Do not update database. Update only properties of object. |
|
2673 | - * @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. |
|
2674 | - * @return int <0 if KO, >0 if OK |
|
2675 | - */ |
|
2676 | - function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
2677 | - { |
|
947 | + /** |
|
948 | + * Delete all links between an object $this and all its contacts |
|
949 | + * |
|
950 | + * @param string $source '' or 'internal' or 'external' |
|
951 | + * @param string $code Type of contact (code or id) |
|
952 | + * @return int >0 if OK, <0 if KO |
|
953 | + */ |
|
954 | + function delete_linked_contact($source='',$code='') |
|
955 | + { |
|
2678 | 956 | // phpcs:enable |
2679 | - global $conf, $hookmanager, $action; |
|
2680 | - |
|
2681 | - // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) |
|
2682 | - $MODULE = ""; |
|
2683 | - if ($this->element == 'propal') |
|
2684 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
2685 | - elseif ($this->element == 'order') |
|
2686 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
2687 | - elseif ($this->element == 'facture') |
|
2688 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
2689 | - elseif ($this->element == 'facture_fourn') |
|
2690 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
2691 | - elseif ($this->element == 'order_supplier') |
|
2692 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
2693 | - elseif ($this->element == 'supplier_proposal') |
|
2694 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
2695 | - |
|
2696 | - if (! empty($MODULE)) { |
|
2697 | - if (! empty($conf->global->$MODULE)) { |
|
2698 | - $modsactivated = explode(',', $conf->global->$MODULE); |
|
2699 | - foreach ($modsactivated as $mod) { |
|
2700 | - if ($conf->$mod->enabled) |
|
2701 | - return 1; // update was disabled by specific setup |
|
2702 | - } |
|
2703 | - } |
|
2704 | - } |
|
2705 | - |
|
2706 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
|
2707 | - |
|
2708 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
2709 | - |
|
2710 | - $forcedroundingmode=$roundingadjust; |
|
2711 | - if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
2712 | - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
2713 | - |
|
2714 | - $error=0; |
|
2715 | - |
|
2716 | - $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
|
2717 | - |
|
2718 | - // Define constants to find lines to sum |
|
2719 | - $fieldtva='total_tva'; |
|
2720 | - $fieldlocaltax1='total_localtax1'; |
|
2721 | - $fieldlocaltax2='total_localtax2'; |
|
2722 | - $fieldup='subprice'; |
|
2723 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
2724 | - { |
|
2725 | - $fieldtva='tva'; |
|
2726 | - $fieldup='pu_ht'; |
|
2727 | - } |
|
2728 | - if ($this->element == 'expensereport') |
|
2729 | - { |
|
2730 | - $fieldup='value_unit'; |
|
2731 | - } |
|
2732 | - |
|
2733 | - $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,'; |
|
2734 | - $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
2735 | - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
2736 | - $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
2737 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2738 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2739 | - if ($exclspec) |
|
2740 | - { |
|
2741 | - $product_field='product_type'; |
|
2742 | - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
2743 | - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
2744 | - } |
|
2745 | - $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 | - |
|
2747 | - dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
2748 | - $resql = $this->db->query($sql); |
|
2749 | - if ($resql) |
|
2750 | - { |
|
2751 | - $this->total_ht = 0; |
|
2752 | - $this->total_tva = 0; |
|
2753 | - $this->total_localtax1 = 0; |
|
2754 | - $this->total_localtax2 = 0; |
|
2755 | - $this->total_ttc = 0; |
|
2756 | - $total_ht_by_vats = array(); |
|
2757 | - $total_tva_by_vats = array(); |
|
2758 | - $total_ttc_by_vats = array(); |
|
2759 | - $this->multicurrency_total_ht = 0; |
|
2760 | - $this->multicurrency_total_tva = 0; |
|
2761 | - $this->multicurrency_total_ttc = 0; |
|
2762 | - |
|
2763 | - $num = $this->db->num_rows($resql); |
|
2764 | - $i = 0; |
|
2765 | - while ($i < $num) |
|
2766 | - { |
|
2767 | - $obj = $this->db->fetch_object($resql); |
|
957 | + $temp = array(); |
|
958 | + $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
2768 | 959 | |
2769 | - // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
|
2770 | - $parameters=array('fk_element' => $obj->rowid); |
|
2771 | - $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
960 | + foreach($typeContact as $key => $value) |
|
961 | + { |
|
962 | + array_push($temp,$key); |
|
963 | + } |
|
964 | + $listId = implode(",", $temp); |
|
2772 | 965 | |
2773 | - 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' |
|
2774 | - { |
|
2775 | - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
2776 | - $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); |
|
2777 | - $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
2778 | - if ($diff) |
|
2779 | - { |
|
2780 | - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
2781 | - 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); |
|
2782 | - $resqlfix=$this->db->query($sqlfix); |
|
2783 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
2784 | - $obj->total_tva = $tmpcal[1]; |
|
2785 | - $obj->total_ttc = $tmpcal[2]; |
|
2786 | - // |
|
2787 | - } |
|
2788 | - } |
|
966 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
967 | + $sql.= " WHERE element_id = ".$this->id; |
|
968 | + if ($listId) |
|
969 | + $sql.= " AND fk_c_type_contact IN (".$listId.")"; |
|
2789 | 970 | |
2790 | - $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
2791 | - $this->total_tva += $obj->total_tva; |
|
2792 | - $this->total_localtax1 += $obj->total_localtax1; |
|
2793 | - $this->total_localtax2 += $obj->total_localtax2; |
|
2794 | - $this->total_ttc += $obj->total_ttc; |
|
2795 | - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
2796 | - $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
|
2797 | - $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
|
2798 | - |
|
2799 | - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
2800 | - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
2801 | - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
2802 | - $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
|
2803 | - $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
|
2804 | - $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
|
2805 | - |
|
2806 | - if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
2807 | - { |
|
2808 | - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
2809 | - $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
2810 | - //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"; |
|
2811 | - if ($diff) |
|
2812 | - { |
|
2813 | - if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; } |
|
2814 | - $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 | - 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); |
|
2816 | - $resqlfix=$this->db->query($sqlfix); |
|
2817 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
2818 | - $this->total_tva -= $diff; |
|
2819 | - $this->total_ttc -= $diff; |
|
2820 | - $total_tva_by_vats[$obj->vatrate] -= $diff; |
|
2821 | - $total_ttc_by_vats[$obj->vatrate] -= $diff; |
|
2822 | - } |
|
2823 | - } |
|
971 | + dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
|
972 | + if ($this->db->query($sql)) |
|
973 | + { |
|
974 | + return 1; |
|
975 | + } |
|
976 | + else |
|
977 | + { |
|
978 | + $this->error=$this->db->lasterror(); |
|
979 | + return -1; |
|
980 | + } |
|
981 | + } |
|
2824 | 982 | |
2825 | - $i++; |
|
2826 | - } |
|
983 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
984 | + /** |
|
985 | + * Get array of all contacts for an object |
|
986 | + * |
|
987 | + * @param int $statut Status of links to get (-1=all) |
|
988 | + * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) |
|
989 | + * @param int $list 0:Return array contains all properties, 1:Return array contains just id |
|
990 | + * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) |
|
991 | + * @return array|int Array of contacts, -1 if error |
|
992 | + */ |
|
993 | + function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
994 | + { |
|
995 | + // phpcs:enable |
|
996 | + global $langs; |
|
997 | + |
|
998 | + $tab=array(); |
|
999 | + |
|
1000 | + $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 |
|
1001 | + if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
1002 | + if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
1003 | + $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
1004 | + $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
1005 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
1006 | + $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
1007 | + if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
1008 | + if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
1009 | + $sql.= " WHERE ec.element_id =".$this->id; |
|
1010 | + $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
1011 | + $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
1012 | + if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
1013 | + if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
1014 | + if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
1015 | + $sql.= " AND tc.active=1"; |
|
1016 | + if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
1017 | + $sql.=" ORDER BY t.lastname ASC"; |
|
1018 | + |
|
1019 | + dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
|
1020 | + $resql=$this->db->query($sql); |
|
1021 | + if ($resql) |
|
1022 | + { |
|
1023 | + $num=$this->db->num_rows($resql); |
|
1024 | + $i=0; |
|
1025 | + while ($i < $num) |
|
1026 | + { |
|
1027 | + $obj = $this->db->fetch_object($resql); |
|
1028 | + |
|
1029 | + if (! $list) |
|
1030 | + { |
|
1031 | + $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
1032 | + $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
1033 | + $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id, |
|
1034 | + 'nom'=>$obj->lastname, // For backward compatibility |
|
1035 | + 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
|
1036 | + 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
|
1037 | + } |
|
1038 | + else |
|
1039 | + { |
|
1040 | + $tab[$i]=$obj->id; |
|
1041 | + } |
|
1042 | + |
|
1043 | + $i++; |
|
1044 | + } |
|
2827 | 1045 | |
2828 | - // Add revenue stamp to total |
|
2829 | - $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
2830 | - $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
1046 | + return $tab; |
|
1047 | + } |
|
1048 | + else |
|
1049 | + { |
|
1050 | + $this->error=$this->db->lasterror(); |
|
1051 | + dol_print_error($this->db); |
|
1052 | + return -1; |
|
1053 | + } |
|
1054 | + } |
|
2831 | 1055 | |
2832 | - // Situations totals |
|
2833 | - if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE ) |
|
2834 | - { |
|
2835 | - $prev_sits = $this->get_prev_sits(); |
|
2836 | - |
|
2837 | - foreach ($prev_sits as $sit) { // $sit is an object Facture loaded with a fetch. |
|
2838 | - $this->total_ht -= $sit->total_ht; |
|
2839 | - $this->total_tva -= $sit->total_tva; |
|
2840 | - $this->total_localtax1 -= $sit->total_localtax1; |
|
2841 | - $this->total_localtax2 -= $sit->total_localtax2; |
|
2842 | - $this->total_ttc -= $sit->total_ttc; |
|
2843 | - $this->multicurrency_total_ht -= $sit->multicurrency_total_ht; |
|
2844 | - $this->multicurrency_total_tva -= $sit->multicurrency_total_tva; |
|
2845 | - $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc; |
|
2846 | - } |
|
2847 | - } |
|
2848 | - |
|
2849 | - $this->db->free($resql); |
|
2850 | - |
|
2851 | - // Now update global field total_ht, total_ttc and tva |
|
2852 | - $fieldht='total_ht'; |
|
2853 | - $fieldtva='tva'; |
|
2854 | - $fieldlocaltax1='localtax1'; |
|
2855 | - $fieldlocaltax2='localtax2'; |
|
2856 | - $fieldttc='total_ttc'; |
|
2857 | - // Specific code for backward compatibility with old field names |
|
2858 | - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
2859 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
2860 | - if ($this->element == 'propal') $fieldttc='total'; |
|
2861 | - if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
2862 | - if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
2863 | - |
|
2864 | - if (empty($nodatabaseupdate)) |
|
2865 | - { |
|
2866 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
2867 | - $sql .= " ".$fieldht."='".price2num($this->total_ht)."',"; |
|
2868 | - $sql .= " ".$fieldtva."='".price2num($this->total_tva)."',"; |
|
2869 | - $sql .= " ".$fieldlocaltax1."='".price2num($this->total_localtax1)."',"; |
|
2870 | - $sql .= " ".$fieldlocaltax2."='".price2num($this->total_localtax2)."',"; |
|
2871 | - $sql .= " ".$fieldttc."='".price2num($this->total_ttc)."'"; |
|
2872 | - $sql .= ", multicurrency_total_ht='".price2num($this->multicurrency_total_ht, 'MT', 1)."'"; |
|
2873 | - $sql .= ", multicurrency_total_tva='".price2num($this->multicurrency_total_tva, 'MT', 1)."'"; |
|
2874 | - $sql .= ", multicurrency_total_ttc='".price2num($this->multicurrency_total_ttc, 'MT', 1)."'"; |
|
2875 | - $sql .= ' WHERE rowid = '.$this->id; |
|
2876 | - |
|
2877 | - |
|
2878 | - dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
2879 | - $resql=$this->db->query($sql); |
|
2880 | - if (! $resql) |
|
2881 | - { |
|
2882 | - $error++; |
|
2883 | - $this->error=$this->db->lasterror(); |
|
2884 | - $this->errors[]=$this->db->lasterror(); |
|
2885 | - } |
|
2886 | - } |
|
2887 | 1056 | |
2888 | - if (! $error) |
|
2889 | - { |
|
2890 | - return 1; |
|
2891 | - } |
|
2892 | - else |
|
2893 | - { |
|
2894 | - return -1; |
|
2895 | - } |
|
2896 | - } |
|
2897 | - else |
|
2898 | - { |
|
2899 | - dol_print_error($this->db,'Bad request in update_price'); |
|
2900 | - return -1; |
|
2901 | - } |
|
2902 | - } |
|
1057 | + /** |
|
1058 | + * Update status of a contact linked to object |
|
1059 | + * |
|
1060 | + * @param int $rowid Id of link between object and contact |
|
1061 | + * @return int <0 if KO, >=0 if OK |
|
1062 | + */ |
|
1063 | + function swapContactStatus($rowid) |
|
1064 | + { |
|
1065 | + $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
|
1066 | + $sql.= " tc.code, tc.libelle"; |
|
1067 | + //$sql.= ", s.fk_soc"; |
|
1068 | + $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; |
|
1069 | + //$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 |
|
1070 | + $sql.= " WHERE ec.rowid =".$rowid; |
|
1071 | + $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
1072 | + $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
1073 | + |
|
1074 | + dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
|
1075 | + $resql=$this->db->query($sql); |
|
1076 | + if ($resql) |
|
1077 | + { |
|
1078 | + $obj = $this->db->fetch_object($resql); |
|
1079 | + $newstatut = ($obj->statut == 4) ? 5 : 4; |
|
1080 | + $result = $this->update_contact($rowid, $newstatut); |
|
1081 | + $this->db->free($resql); |
|
1082 | + return $result; |
|
1083 | + } |
|
1084 | + else |
|
1085 | + { |
|
1086 | + $this->error=$this->db->error(); |
|
1087 | + dol_print_error($this->db); |
|
1088 | + return -1; |
|
1089 | + } |
|
1090 | + } |
|
2903 | 1091 | |
2904 | 1092 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
2905 | - /** |
|
2906 | - * Add objects linked in llx_element_element. |
|
2907 | - * |
|
2908 | - * @param string $origin Linked element type |
|
2909 | - * @param int $origin_id Linked element id |
|
2910 | - * @return int <=0 if KO, >0 if OK |
|
2911 | - * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
|
2912 | - */ |
|
2913 | - function add_object_linked($origin=null, $origin_id=null) |
|
2914 | - { |
|
1093 | + /** |
|
1094 | + * Return array with list of possible values for type of contacts |
|
1095 | + * |
|
1096 | + * @param string $source 'internal', 'external' or 'all' |
|
1097 | + * @param string $order Sort order by : 'position', 'code', 'rowid'... |
|
1098 | + * @param int $option 0=Return array id->label, 1=Return array code->label |
|
1099 | + * @param int $activeonly 0=all status of contact, 1=only the active |
|
1100 | + * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
|
1101 | + * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
|
1102 | + */ |
|
1103 | + function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
1104 | + { |
|
2915 | 1105 | // phpcs:enable |
2916 | - $origin = (! empty($origin) ? $origin : $this->origin); |
|
2917 | - $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
2918 | - |
|
2919 | - // Special case |
|
2920 | - if ($origin == 'order') $origin='commande'; |
|
2921 | - if ($origin == 'invoice') $origin='facture'; |
|
2922 | - if ($origin == 'invoice_template') $origin='facturerec'; |
|
2923 | - if ($origin == 'supplierorder') $origin='order_supplier'; |
|
2924 | - $this->db->begin(); |
|
2925 | - |
|
2926 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; |
|
2927 | - $sql.= "fk_source"; |
|
2928 | - $sql.= ", sourcetype"; |
|
2929 | - $sql.= ", fk_target"; |
|
2930 | - $sql.= ", targettype"; |
|
2931 | - $sql.= ") VALUES ("; |
|
2932 | - $sql.= $origin_id; |
|
2933 | - $sql.= ", '".$this->db->escape($origin)."'"; |
|
2934 | - $sql.= ", ".$this->id; |
|
2935 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
2936 | - $sql.= ")"; |
|
2937 | - |
|
2938 | - dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
|
2939 | - if ($this->db->query($sql)) |
|
2940 | - { |
|
2941 | - $this->db->commit(); |
|
2942 | - return 1; |
|
2943 | - } |
|
2944 | - else |
|
2945 | - { |
|
2946 | - $this->error=$this->db->lasterror(); |
|
2947 | - $this->db->rollback(); |
|
2948 | - return 0; |
|
2949 | - } |
|
2950 | - } |
|
2951 | - |
|
2952 | - /** |
|
2953 | - * Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into |
|
2954 | - * this->linkedObjectsIds array and |
|
2955 | - * this->linkedObjects array if $loadalsoobjects = 1 |
|
2956 | - * Possible usage for parameters: |
|
2957 | - * - all parameters empty -> we look all link to current object (current object can be source or target) |
|
2958 | - * - source id+type -> will get target list linked to source |
|
2959 | - * - target id+type -> will get source list linked to target |
|
2960 | - * - source id+type + target type -> will get target list of the type |
|
2961 | - * - target id+type + target source -> will get source list of the type |
|
2962 | - * |
|
2963 | - * @param int $sourceid Object source id (if not defined, id of object) |
|
2964 | - * @param string $sourcetype Object source type (if not defined, element name of object) |
|
2965 | - * @param int $targetid Object target id (if not defined, id of object) |
|
2966 | - * @param string $targettype Object target type (if not defined, elemennt name of object) |
|
2967 | - * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided |
|
2968 | - * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. |
|
2969 | - * @param string $orderby SQL 'ORDER BY' clause |
|
2970 | - * @param int $loadalsoobjects Load also array this->linkedObjects (Use 0 to increase performances) |
|
2971 | - * @return int <0 if KO, >0 if OK |
|
2972 | - * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
|
2973 | - */ |
|
2974 | - function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype',$loadalsoobjects=1) |
|
2975 | - { |
|
2976 | - global $conf; |
|
2977 | - |
|
2978 | - $this->linkedObjectsIds=array(); |
|
2979 | - $this->linkedObjects=array(); |
|
2980 | - |
|
2981 | - $justsource=false; |
|
2982 | - $justtarget=false; |
|
2983 | - $withtargettype=false; |
|
2984 | - $withsourcetype=false; |
|
2985 | - |
|
2986 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
2987 | - { |
|
2988 | - $justsource=true; // the source (id and type) is a search criteria |
|
2989 | - if (! empty($targettype)) $withtargettype=true; |
|
2990 | - } |
|
2991 | - if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
2992 | - { |
|
2993 | - $justtarget=true; // the target (id and type) is a search criteria |
|
2994 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
2995 | - } |
|
2996 | - |
|
2997 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
2998 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
2999 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
3000 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
3001 | - |
|
3002 | - /*if (empty($sourceid) && empty($targetid)) |
|
3003 | - { |
|
3004 | - dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERR); |
|
3005 | - return -1; |
|
3006 | - }*/ |
|
1106 | + global $langs; |
|
1107 | + |
|
1108 | + if (empty($order)) $order='position'; |
|
1109 | + if ($order == 'position') $order.=',code'; |
|
1110 | + |
|
1111 | + $tab = array(); |
|
1112 | + $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
|
1113 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
1114 | + $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
1115 | + if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
1116 | + if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
1117 | + if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
1118 | + $sql.= $this->db->order($order,'ASC'); |
|
1119 | + |
|
1120 | + //print "sql=".$sql; |
|
1121 | + $resql=$this->db->query($sql); |
|
1122 | + if ($resql) |
|
1123 | + { |
|
1124 | + $num=$this->db->num_rows($resql); |
|
1125 | + $i=0; |
|
1126 | + while ($i < $num) |
|
1127 | + { |
|
1128 | + $obj = $this->db->fetch_object($resql); |
|
3007 | 1129 | |
3008 | - // Links between objects are stored in table element_element |
|
3009 | - $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
|
3010 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
3011 | - $sql.= " WHERE "; |
|
3012 | - if ($justsource || $justtarget) |
|
3013 | - { |
|
3014 | - if ($justsource) |
|
3015 | - { |
|
3016 | - $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
3017 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
3018 | - } |
|
3019 | - else if ($justtarget) |
|
3020 | - { |
|
3021 | - $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
3022 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
3023 | - } |
|
3024 | - } |
|
3025 | - else |
|
3026 | - { |
|
3027 | - $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
3028 | - $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
3029 | - } |
|
3030 | - $sql .= ' ORDER BY '.$orderby; |
|
3031 | - |
|
3032 | - dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); |
|
3033 | - $resql = $this->db->query($sql); |
|
3034 | - if ($resql) |
|
3035 | - { |
|
3036 | - $num = $this->db->num_rows($resql); |
|
3037 | - $i = 0; |
|
3038 | - while ($i < $num) |
|
3039 | - { |
|
3040 | - $obj = $this->db->fetch_object($resql); |
|
3041 | - if ($justsource || $justtarget) |
|
3042 | - { |
|
3043 | - if ($justsource) |
|
3044 | - { |
|
3045 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
3046 | - } |
|
3047 | - else if ($justtarget) |
|
3048 | - { |
|
3049 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
3050 | - } |
|
3051 | - } |
|
3052 | - else |
|
3053 | - { |
|
3054 | - if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
|
3055 | - { |
|
3056 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
3057 | - } |
|
3058 | - if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
|
3059 | - { |
|
3060 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
3061 | - } |
|
3062 | - } |
|
3063 | - $i++; |
|
3064 | - } |
|
3065 | - |
|
3066 | - if (! empty($this->linkedObjectsIds)) |
|
3067 | - { |
|
3068 | - $tmparray = $this->linkedObjectsIds; |
|
3069 | - foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) |
|
3070 | - { |
|
3071 | - // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
|
3072 | - $module = $element = $subelement = $objecttype; |
|
3073 | - if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
|
3074 | - && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) |
|
3075 | - { |
|
3076 | - $module = $element = $regs[1]; |
|
3077 | - $subelement = $regs[2]; |
|
3078 | - } |
|
3079 | - |
|
3080 | - $classpath = $element.'/class'; |
|
3081 | - // To work with non standard classpath or module name |
|
3082 | - if ($objecttype == 'facture') { |
|
3083 | - $classpath = 'compta/facture/class'; |
|
3084 | - } |
|
3085 | - else if ($objecttype == 'facturerec') { |
|
3086 | - $classpath = 'compta/facture/class'; $module = 'facture'; |
|
3087 | - } |
|
3088 | - else if ($objecttype == 'propal') { |
|
3089 | - $classpath = 'comm/propal/class'; |
|
3090 | - } |
|
3091 | - else if ($objecttype == 'supplier_proposal') { |
|
3092 | - $classpath = 'supplier_proposal/class'; |
|
3093 | - } |
|
3094 | - else if ($objecttype == 'shipping') { |
|
3095 | - $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
|
3096 | - } |
|
3097 | - else if ($objecttype == 'delivery') { |
|
3098 | - $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
|
3099 | - } |
|
3100 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
3101 | - $classpath = 'fourn/class'; $module = 'fournisseur'; |
|
3102 | - } |
|
3103 | - else if ($objecttype == 'fichinter') { |
|
3104 | - $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
|
3105 | - } |
|
3106 | - else if ($objecttype == 'subscription') { |
|
3107 | - $classpath = 'adherents/class'; $module = 'adherent'; |
|
3108 | - } |
|
3109 | - |
|
3110 | - // Set classfile |
|
3111 | - $classfile = strtolower($subelement); $classname = ucfirst($subelement); |
|
3112 | - |
|
3113 | - if ($objecttype == 'order') { |
|
3114 | - $classfile = 'commande'; $classname = 'Commande'; |
|
3115 | - } |
|
3116 | - else if ($objecttype == 'invoice_supplier') { |
|
3117 | - $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
|
3118 | - } |
|
3119 | - else if ($objecttype == 'order_supplier') { |
|
3120 | - $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
|
3121 | - } |
|
3122 | - else if ($objecttype == 'supplier_proposal') { |
|
3123 | - $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
|
3124 | - } |
|
3125 | - else if ($objecttype == 'facturerec') { |
|
3126 | - $classfile = 'facture-rec'; $classname = 'FactureRec'; |
|
3127 | - } |
|
3128 | - else if ($objecttype == 'subscription') { |
|
3129 | - $classfile = 'subscription'; $classname = 'Subscription'; |
|
3130 | - } |
|
3131 | - |
|
3132 | - // Here $module, $classfile and $classname are set |
|
3133 | - if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) |
|
3134 | - { |
|
3135 | - if ($loadalsoobjects) |
|
3136 | - { |
|
3137 | - dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); |
|
3138 | - //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
|
3139 | - if (class_exists($classname)) |
|
3140 | - { |
|
3141 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
3142 | - { |
|
3143 | - $object = new $classname($this->db); |
|
3144 | - $ret = $object->fetch($objectid); |
|
3145 | - if ($ret >= 0) |
|
3146 | - { |
|
3147 | - $this->linkedObjects[$objecttype][$i] = $object; |
|
3148 | - } |
|
3149 | - } |
|
3150 | - } |
|
3151 | - } |
|
3152 | - } |
|
3153 | - else |
|
3154 | - { |
|
3155 | - unset($this->linkedObjectsIds[$objecttype]); |
|
3156 | - } |
|
3157 | - } |
|
3158 | - } |
|
3159 | - return 1; |
|
3160 | - } |
|
3161 | - else |
|
3162 | - { |
|
3163 | - dol_print_error($this->db); |
|
3164 | - return -1; |
|
3165 | - } |
|
3166 | - } |
|
3167 | - |
|
3168 | - /** |
|
3169 | - * Update object linked of a current object |
|
3170 | - * |
|
3171 | - * @param int $sourceid Object source id |
|
3172 | - * @param string $sourcetype Object source type |
|
3173 | - * @param int $targetid Object target id |
|
3174 | - * @param string $targettype Object target type |
|
3175 | - * @return int >0 if OK, <0 if KO |
|
3176 | - * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
|
3177 | - */ |
|
3178 | - function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
3179 | - { |
|
3180 | - $updatesource=false; |
|
3181 | - $updatetarget=false; |
|
3182 | - |
|
3183 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
3184 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
3185 | - |
|
3186 | - $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
|
3187 | - if ($updatesource) |
|
3188 | - { |
|
3189 | - $sql.= "fk_source = ".$sourceid; |
|
3190 | - $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3191 | - $sql.= " WHERE fk_target = ".$this->id; |
|
3192 | - $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
3193 | - } |
|
3194 | - else if ($updatetarget) |
|
3195 | - { |
|
3196 | - $sql.= "fk_target = ".$targetid; |
|
3197 | - $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
3198 | - $sql.= " WHERE fk_source = ".$this->id; |
|
3199 | - $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3200 | - } |
|
3201 | - |
|
3202 | - dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
|
3203 | - if ($this->db->query($sql)) |
|
3204 | - { |
|
3205 | - return 1; |
|
3206 | - } |
|
3207 | - else |
|
3208 | - { |
|
3209 | - $this->error=$this->db->lasterror(); |
|
3210 | - return -1; |
|
3211 | - } |
|
3212 | - } |
|
3213 | - |
|
3214 | - /** |
|
3215 | - * Delete all links between an object $this |
|
3216 | - * |
|
3217 | - * @param int $sourceid Object source id |
|
3218 | - * @param string $sourcetype Object source type |
|
3219 | - * @param int $targetid Object target id |
|
3220 | - * @param string $targettype Object target type |
|
3221 | - * @param int $rowid Row id of line to delete. If defined, other parameters are not used. |
|
3222 | - * @return int >0 if OK, <0 if KO |
|
3223 | - * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
|
3224 | - */ |
|
3225 | - function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
3226 | - { |
|
3227 | - $deletesource=false; |
|
3228 | - $deletetarget=false; |
|
3229 | - |
|
3230 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
3231 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
3232 | - |
|
3233 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
3234 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
3235 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
3236 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
3237 | - |
|
3238 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
|
3239 | - $sql.= " WHERE"; |
|
3240 | - if ($rowid > 0) |
|
3241 | - { |
|
3242 | - $sql.=" rowid = ".$rowid; |
|
3243 | - } |
|
3244 | - else |
|
3245 | - { |
|
3246 | - if ($deletesource) |
|
3247 | - { |
|
3248 | - $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3249 | - $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
3250 | - } |
|
3251 | - else if ($deletetarget) |
|
3252 | - { |
|
3253 | - $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
3254 | - $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3255 | - } |
|
3256 | - else |
|
3257 | - { |
|
3258 | - $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
3259 | - $sql.= " OR"; |
|
3260 | - $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
3261 | - } |
|
3262 | - } |
|
3263 | - |
|
3264 | - dol_syslog(get_class($this)."::deleteObjectLinked", LOG_DEBUG); |
|
3265 | - if ($this->db->query($sql)) |
|
3266 | - { |
|
3267 | - return 1; |
|
3268 | - } |
|
3269 | - else |
|
3270 | - { |
|
3271 | - $this->error=$this->db->lasterror(); |
|
3272 | - $this->errors[]=$this->error; |
|
3273 | - return -1; |
|
3274 | - } |
|
3275 | - } |
|
3276 | - |
|
3277 | - /** |
|
3278 | - * Set status of an object |
|
3279 | - * |
|
3280 | - * @param int $status Status to set |
|
3281 | - * @param int $elementId Id of element to force (use this->id by default) |
|
3282 | - * @param string $elementType Type of element to force (use this->table_element by default) |
|
3283 | - * @param string $trigkey Trigger key to use for trigger |
|
3284 | - * @return int <0 if KO, >0 if OK |
|
3285 | - */ |
|
3286 | - function setStatut($status, $elementId=null, $elementType='', $trigkey='') |
|
3287 | - { |
|
3288 | - global $user,$langs,$conf; |
|
3289 | - |
|
3290 | - $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
3291 | - |
|
3292 | - $elementId = (!empty($elementId)?$elementId:$this->id); |
|
3293 | - $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
3294 | - |
|
3295 | - $this->db->begin(); |
|
3296 | - |
|
3297 | - $fieldstatus="fk_statut"; |
|
3298 | - if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
3299 | - if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
3300 | - if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
3301 | - if ($elementTable == 'user') $fieldstatus="statut"; |
|
3302 | - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
3303 | - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
3304 | - |
|
3305 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
|
3306 | - $sql.= " SET ".$fieldstatus." = ".$status; |
|
3307 | - // If status = 1 = validated, update also fk_user_valid |
|
3308 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
3309 | - $sql.= " WHERE rowid=".$elementId; |
|
3310 | - |
|
3311 | - dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
|
3312 | - if ($this->db->query($sql)) |
|
3313 | - { |
|
3314 | - $error = 0; |
|
3315 | - |
|
3316 | - // Try autoset of trigkey |
|
3317 | - if (empty($trigkey)) |
|
3318 | - { |
|
3319 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
3320 | - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
3321 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
3322 | - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
3323 | - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
3324 | - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
3325 | - } |
|
3326 | - |
|
3327 | - if ($trigkey) |
|
3328 | - { |
|
3329 | - // Appel des triggers |
|
3330 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
3331 | - $interface=new Interfaces($this->db); |
|
3332 | - $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
3333 | - if ($result < 0) { |
|
3334 | - $error++; $this->errors=$interface->errors; |
|
3335 | - } |
|
3336 | - // Fin appel triggers |
|
3337 | - } |
|
1130 | + $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
1131 | + $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
1132 | + if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
1133 | + else $tab[$obj->code]=$libelle_type; |
|
1134 | + $i++; |
|
1135 | + } |
|
1136 | + return $tab; |
|
1137 | + } |
|
1138 | + else |
|
1139 | + { |
|
1140 | + $this->error=$this->db->lasterror(); |
|
1141 | + //dol_print_error($this->db); |
|
1142 | + return null; |
|
1143 | + } |
|
1144 | + } |
|
3338 | 1145 | |
3339 | - if (! $error) |
|
3340 | - { |
|
3341 | - $this->db->commit(); |
|
1146 | + /** |
|
1147 | + * Return id of contacts for a source and a contact code. |
|
1148 | + * Example: contact client de facturation ('external', 'BILLING') |
|
1149 | + * Example: contact client de livraison ('external', 'SHIPPING') |
|
1150 | + * Example: contact interne suivi paiement ('internal', 'SALESREPFOLL') |
|
1151 | + * |
|
1152 | + * @param string $source 'external' or 'internal' |
|
1153 | + * @param string $code 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... |
|
1154 | + * @param int $status limited to a certain status |
|
1155 | + * @return array List of id for such contacts |
|
1156 | + */ |
|
1157 | + function getIdContact($source,$code,$status=0) |
|
1158 | + { |
|
1159 | + global $conf; |
|
3342 | 1160 | |
3343 | - if (empty($savElementId)) // If the element we update was $this (so $elementId is null) |
|
3344 | - { |
|
3345 | - $this->statut = $status; |
|
3346 | - $this->status = $status; |
|
3347 | - } |
|
1161 | + $result=array(); |
|
1162 | + $i=0; |
|
1163 | + //cas particulier pour les expeditions |
|
1164 | + if($this->element=='shipping' && $this->origin_id != 0) { |
|
1165 | + $id=$this->origin_id; |
|
1166 | + $element='commande'; |
|
1167 | + } else if($this->element=='reception' && $this->origin_id != 0) { |
|
1168 | + $id=$this->origin_id; |
|
1169 | + $element='order_supplier'; |
|
1170 | + } else { |
|
1171 | + $id=$this->id; |
|
1172 | + $element=$this->element; |
|
1173 | + } |
|
3348 | 1174 | |
3349 | - return 1; |
|
3350 | - } |
|
3351 | - else |
|
3352 | - { |
|
3353 | - $this->db->rollback(); |
|
3354 | - dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
3355 | - return -1; |
|
3356 | - } |
|
3357 | - } |
|
3358 | - else |
|
3359 | - { |
|
3360 | - $this->error=$this->db->lasterror(); |
|
3361 | - $this->db->rollback(); |
|
3362 | - return -1; |
|
3363 | - } |
|
3364 | - } |
|
3365 | - |
|
3366 | - |
|
3367 | - /** |
|
3368 | - * Load type of canvas of an object if it exists |
|
3369 | - * |
|
3370 | - * @param int $id Record id |
|
3371 | - * @param string $ref Record ref |
|
3372 | - * @return int <0 if KO, 0 if nothing done, >0 if OK |
|
3373 | - */ |
|
3374 | - function getCanvas($id=0,$ref='') |
|
3375 | - { |
|
3376 | - global $conf; |
|
3377 | - |
|
3378 | - if (empty($id) && empty($ref)) return 0; |
|
3379 | - if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
3380 | - |
|
3381 | - // Clean parameters |
|
3382 | - $ref = trim($ref); |
|
3383 | - |
|
3384 | - $sql = "SELECT rowid, canvas"; |
|
3385 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
3386 | - $sql.= " WHERE entity IN (".getEntity($this->element).")"; |
|
3387 | - if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
3388 | - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
3389 | - |
|
3390 | - $resql = $this->db->query($sql); |
|
3391 | - if ($resql) |
|
3392 | - { |
|
3393 | - $obj = $this->db->fetch_object($resql); |
|
3394 | - if ($obj) |
|
3395 | - { |
|
3396 | - $this->canvas = $obj->canvas; |
|
3397 | - return 1; |
|
3398 | - } |
|
3399 | - else return 0; |
|
3400 | - } |
|
3401 | - else |
|
3402 | - { |
|
3403 | - dol_print_error($this->db); |
|
3404 | - return -1; |
|
3405 | - } |
|
3406 | - } |
|
3407 | - |
|
3408 | - |
|
3409 | - /** |
|
3410 | - * Get special code of a line |
|
3411 | - * |
|
3412 | - * @param int $lineid Id of line |
|
3413 | - * @return int Special code |
|
3414 | - */ |
|
3415 | - function getSpecialCode($lineid) |
|
3416 | - { |
|
3417 | - $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
3418 | - $sql.= ' WHERE rowid = '.$lineid; |
|
3419 | - $resql = $this->db->query($sql); |
|
3420 | - if ($resql) |
|
3421 | - { |
|
3422 | - $row = $this->db->fetch_row($resql); |
|
3423 | - return $row[0]; |
|
3424 | - } |
|
3425 | - } |
|
3426 | - |
|
3427 | - /** |
|
3428 | - * Function to check if an object is used by others. |
|
3429 | - * Check is done into this->childtables. There is no check into llx_element_element. |
|
3430 | - * |
|
3431 | - * @param int $id Force id of object |
|
3432 | - * @return int <0 if KO, 0 if not used, >0 if already used |
|
3433 | - */ |
|
3434 | - function isObjectUsed($id=0) |
|
3435 | - { |
|
3436 | - global $langs; |
|
3437 | - |
|
3438 | - if (empty($id)) $id=$this->id; |
|
3439 | - |
|
3440 | - // Check parameters |
|
3441 | - if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
3442 | - { |
|
3443 | - dol_print_error('Called isObjectUsed on a class with property this->childtables not defined'); |
|
3444 | - return -1; |
|
3445 | - } |
|
3446 | - |
|
3447 | - $arraytoscan = $this->childtables; |
|
3448 | - // For backward compatibility, we check if array is old format array('table1', 'table2', ...) |
|
3449 | - $tmparray=array_keys($this->childtables); |
|
3450 | - if (is_numeric($tmparray[0])) |
|
3451 | - { |
|
3452 | - $arraytoscan = array_flip($this->childtables); |
|
3453 | - } |
|
3454 | - |
|
3455 | - // Test if child exists |
|
3456 | - $haschild=0; |
|
3457 | - foreach($arraytoscan as $table => $elementname) |
|
3458 | - { |
|
3459 | - //print $id.'-'.$table.'-'.$elementname.'<br>'; |
|
3460 | - // Check if third party can be deleted |
|
3461 | - $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
|
3462 | - $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
3463 | - $resql=$this->db->query($sql); |
|
3464 | - if ($resql) |
|
3465 | - { |
|
3466 | - $obj=$this->db->fetch_object($resql); |
|
3467 | - if ($obj->nb > 0) |
|
3468 | - { |
|
3469 | - $langs->load("errors"); |
|
3470 | - //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
|
3471 | - $haschild += $obj->nb; |
|
3472 | - if (is_numeric($elementname)) // old usage |
|
3473 | - { |
|
3474 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); |
|
3475 | - } |
|
3476 | - else // new usage: $elementname=Translation key |
|
3477 | - { |
|
3478 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
|
3479 | - } |
|
3480 | - break; // We found at least one, we stop here |
|
3481 | - } |
|
3482 | - } |
|
3483 | - else |
|
3484 | - { |
|
3485 | - $this->errors[]=$this->db->lasterror(); |
|
3486 | - return -1; |
|
3487 | - } |
|
3488 | - } |
|
3489 | - if ($haschild > 0) |
|
3490 | - { |
|
3491 | - $this->errors[]="ErrorRecordHasChildren"; |
|
3492 | - return $haschild; |
|
3493 | - } |
|
3494 | - else return 0; |
|
3495 | - } |
|
3496 | - |
|
3497 | - /** |
|
3498 | - * Function to say how many lines object contains |
|
3499 | - * |
|
3500 | - * @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 |
|
3501 | - * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
|
3502 | - */ |
|
3503 | - function hasProductsOrServices($predefined=-1) |
|
3504 | - { |
|
3505 | - $nb=0; |
|
3506 | - |
|
3507 | - foreach($this->lines as $key => $val) |
|
3508 | - { |
|
3509 | - $qualified=0; |
|
3510 | - if ($predefined == -1) $qualified=1; |
|
3511 | - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
3512 | - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
3513 | - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
3514 | - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
3515 | - if ($qualified) $nb++; |
|
3516 | - } |
|
3517 | - dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
|
3518 | - return $nb; |
|
3519 | - } |
|
3520 | - |
|
3521 | - /** |
|
3522 | - * Function that returns the total amount HT of discounts applied for all lines. |
|
3523 | - * |
|
3524 | - * @return float |
|
3525 | - */ |
|
3526 | - function getTotalDiscount() |
|
3527 | - { |
|
3528 | - $total_discount=0.00; |
|
3529 | - |
|
3530 | - $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
|
3531 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
3532 | - $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
3533 | - |
|
3534 | - dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
|
3535 | - $resql = $this->db->query($sql); |
|
3536 | - if ($resql) |
|
3537 | - { |
|
3538 | - $num=$this->db->num_rows($resql); |
|
3539 | - $i=0; |
|
3540 | - while ($i < $num) |
|
3541 | - { |
|
3542 | - $obj = $this->db->fetch_object($resql); |
|
3543 | - |
|
3544 | - $pu_ht = $obj->pu_ht; |
|
3545 | - $qty= $obj->qty; |
|
3546 | - $total_ht = $obj->total_ht; |
|
3547 | - |
|
3548 | - $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
|
3549 | - $total_discount += $total_discount_line; |
|
3550 | - |
|
3551 | - $i++; |
|
3552 | - } |
|
3553 | - } |
|
3554 | - |
|
3555 | - //print $total_discount; exit; |
|
3556 | - return price2num($total_discount); |
|
3557 | - } |
|
3558 | - |
|
3559 | - |
|
3560 | - /** |
|
3561 | - * Return into unit=0, the calculated total of weight and volume of all lines * qty |
|
3562 | - * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. |
|
3563 | - * |
|
3564 | - * @return array array('weight'=>...,'volume'=>...) |
|
3565 | - */ |
|
3566 | - function getTotalWeightVolume() |
|
3567 | - { |
|
3568 | - $totalWeight = 0; |
|
3569 | - $totalVolume = 0; |
|
3570 | - // defined for shipment only |
|
3571 | - $totalOrdered = ''; |
|
3572 | - // defined for shipment only |
|
3573 | - $totalToShip = ''; |
|
3574 | - |
|
3575 | - foreach ($this->lines as $line) |
|
3576 | - { |
|
3577 | - if (isset($line->qty_asked)) |
|
3578 | - { |
|
3579 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
3580 | - $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
3581 | - } |
|
3582 | - if (isset($line->qty_shipped)) |
|
3583 | - { |
|
3584 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
3585 | - $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
3586 | - }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
1175 | + $sql = "SELECT ec.fk_socpeople"; |
|
1176 | + $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
1177 | + if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
1178 | + if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
1179 | + $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
1180 | + $sql.= " WHERE ec.element_id = ".$id; |
|
1181 | + $sql.= " AND ec.fk_socpeople = c.rowid"; |
|
1182 | + if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
1183 | + if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")"; |
|
1184 | + $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
1185 | + $sql.= " AND tc.element = '".$element."'"; |
|
1186 | + $sql.= " AND tc.source = '".$source."'"; |
|
1187 | + $sql.= " AND tc.code = '".$code."'"; |
|
1188 | + $sql.= " AND tc.active = 1"; |
|
1189 | + if ($status) $sql.= " AND ec.statut = ".$status; |
|
1190 | + |
|
1191 | + dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
|
1192 | + $resql=$this->db->query($sql); |
|
1193 | + if ($resql) |
|
1194 | + { |
|
1195 | + while ($obj = $this->db->fetch_object($resql)) |
|
3587 | 1196 | { |
3588 | - if (empty($totalToShip)) $totalToShip=0; |
|
3589 | - $totalToShip+=$line->qty; // defined for reception only |
|
3590 | - } |
|
3591 | - |
|
3592 | - // Define qty, weight, volume, weight_units, volume_units |
|
3593 | - if ($this->element == 'shipping') { |
|
3594 | - // for shipments |
|
3595 | - $qty = $line->qty_shipped ? $line->qty_shipped : 0; |
|
3596 | - } |
|
3597 | - else { |
|
3598 | - $qty = $line->qty ? $line->qty : 0; |
|
3599 | - } |
|
3600 | - |
|
3601 | - $weight = $line->weight ? $line->weight : 0; |
|
3602 | - ($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0; |
|
3603 | - $volume = $line->volume ? $line->volume : 0; |
|
3604 | - ($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0; |
|
3605 | - |
|
3606 | - $weight_units=$line->weight_units; |
|
3607 | - ($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0; |
|
3608 | - $volume_units=$line->volume_units; |
|
3609 | - ($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0; |
|
3610 | - |
|
3611 | - $weightUnit=0; |
|
3612 | - $volumeUnit=0; |
|
3613 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
3614 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
3615 | - |
|
3616 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
3617 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
3618 | - |
|
3619 | - //var_dump($line->volume_units); |
|
3620 | - if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
3621 | - { |
|
3622 | - $trueWeightUnit=pow(10, $weightUnit); |
|
3623 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
3624 | - } |
|
3625 | - else { |
|
3626 | - if ($weight_units == 99) { |
|
3627 | - // conversion 1 Pound = 0.45359237 KG |
|
3628 | - $trueWeightUnit = 0.45359237; |
|
3629 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
3630 | - } elseif ($weight_units == 98) { |
|
3631 | - // conversion 1 Ounce = 0.0283495 KG |
|
3632 | - $trueWeightUnit = 0.0283495; |
|
3633 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
3634 | - } |
|
3635 | - else |
|
3636 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
3637 | - } |
|
3638 | - if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
3639 | - { |
|
3640 | - //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
|
3641 | - $trueVolumeUnit=pow(10, $volumeUnit); |
|
3642 | - //print $line->volume; |
|
3643 | - $totalVolume += $volume * $qty * $trueVolumeUnit; |
|
3644 | - } |
|
3645 | - else |
|
3646 | - { |
|
3647 | - $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
3648 | - } |
|
3649 | - } |
|
3650 | - |
|
3651 | - return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip); |
|
3652 | - } |
|
3653 | - |
|
3654 | - |
|
3655 | - /** |
|
3656 | - * Set extra parameters |
|
3657 | - * |
|
3658 | - * @return int <0 if KO, >0 if OK |
|
3659 | - */ |
|
3660 | - function setExtraParameters() |
|
3661 | - { |
|
3662 | - $this->db->begin(); |
|
3663 | - |
|
3664 | - $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
3665 | - |
|
3666 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
3667 | - $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
3668 | - $sql.= " WHERE rowid = ".$this->id; |
|
3669 | - |
|
3670 | - dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
|
3671 | - $resql = $this->db->query($sql); |
|
3672 | - if (! $resql) |
|
3673 | - { |
|
3674 | - $this->error=$this->db->lasterror(); |
|
3675 | - $this->db->rollback(); |
|
3676 | - return -1; |
|
3677 | - } |
|
3678 | - else |
|
3679 | - { |
|
3680 | - $this->db->commit(); |
|
3681 | - return 1; |
|
3682 | - } |
|
3683 | - } |
|
1197 | + $result[$i]=$obj->fk_socpeople; |
|
1198 | + $i++; |
|
1199 | + } |
|
1200 | + } |
|
1201 | + else |
|
1202 | + { |
|
1203 | + $this->error=$this->db->error(); |
|
1204 | + return null; |
|
1205 | + } |
|
3684 | 1206 | |
1207 | + return $result; |
|
1208 | + } |
|
3685 | 1209 | |
3686 | 1210 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
3687 | - /** |
|
3688 | - * Return incoterms informations |
|
3689 | - * TODO Use a cache for label get |
|
3690 | - * |
|
3691 | - * @return string incoterms info |
|
3692 | - */ |
|
3693 | - function display_incoterms() |
|
3694 | - { |
|
1211 | + /** |
|
1212 | + * Load object contact with id=$this->contactid into $this->contact |
|
1213 | + * |
|
1214 | + * @param int $contactid Id du contact. Use this->contactid if empty. |
|
1215 | + * @return int <0 if KO, >0 if OK |
|
1216 | + */ |
|
1217 | + function fetch_contact($contactid=null) |
|
1218 | + { |
|
3695 | 1219 | // phpcs:enable |
3696 | - $out = ''; |
|
3697 | - $this->libelle_incoterms = ''; |
|
3698 | - if (!empty($this->fk_incoterms)) |
|
3699 | - { |
|
3700 | - $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
3701 | - $result = $this->db->query($sql); |
|
3702 | - if ($result) |
|
3703 | - { |
|
3704 | - $res = $this->db->fetch_object($result); |
|
3705 | - $out .= $res->code; |
|
3706 | - } |
|
3707 | - } |
|
3708 | - |
|
3709 | - $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
3710 | - |
|
3711 | - return $out; |
|
3712 | - } |
|
3713 | - |
|
3714 | - /** |
|
3715 | - * Return incoterms informations for pdf display |
|
3716 | - * |
|
3717 | - * @return string incoterms info |
|
3718 | - */ |
|
3719 | - function getIncotermsForPDF() |
|
3720 | - { |
|
3721 | - $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
3722 | - $resql = $this->db->query($sql); |
|
3723 | - if ($resql) |
|
3724 | - { |
|
3725 | - $num = $this->db->num_rows($resql); |
|
3726 | - if ($num > 0) |
|
3727 | - { |
|
3728 | - $res = $this->db->fetch_object($resql); |
|
3729 | - return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
|
3730 | - } |
|
3731 | - else |
|
3732 | - { |
|
3733 | - return ''; |
|
3734 | - } |
|
3735 | - } |
|
3736 | - else |
|
3737 | - { |
|
3738 | - $this->errors[] = $this->db->lasterror(); |
|
3739 | - return false; |
|
3740 | - } |
|
3741 | - } |
|
3742 | - |
|
3743 | - /** |
|
3744 | - * Define incoterms values of current object |
|
3745 | - * |
|
3746 | - * @param int $id_incoterm Id of incoterm to set or '' to remove |
|
3747 | - * @param string $location location of incoterm |
|
3748 | - * @return int <0 if KO, >0 if OK |
|
3749 | - */ |
|
3750 | - function setIncoterms($id_incoterm, $location) |
|
3751 | - { |
|
3752 | - if ($this->id && $this->table_element) |
|
3753 | - { |
|
3754 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
3755 | - $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
3756 | - $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
3757 | - $sql.= " WHERE rowid = " . $this->id; |
|
3758 | - dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
|
3759 | - $resql=$this->db->query($sql); |
|
3760 | - if ($resql) |
|
3761 | - { |
|
3762 | - $this->fk_incoterms = $id_incoterm; |
|
3763 | - $this->location_incoterms = $location; |
|
1220 | + if (empty($contactid)) $contactid=$this->contactid; |
|
3764 | 1221 | |
3765 | - $sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
3766 | - $res = $this->db->query($sql); |
|
3767 | - if ($res) |
|
3768 | - { |
|
3769 | - $obj = $this->db->fetch_object($res); |
|
3770 | - $this->libelle_incoterms = $obj->libelle; |
|
3771 | - } |
|
3772 | - return 1; |
|
3773 | - } |
|
3774 | - else |
|
3775 | - { |
|
3776 | - $this->errors[] = $this->db->lasterror(); |
|
3777 | - return -1; |
|
3778 | - } |
|
3779 | - } |
|
3780 | - else return -1; |
|
3781 | - } |
|
3782 | - |
|
3783 | - |
|
3784 | - // -------------------- |
|
3785 | - // TODO: All functions here must be redesigned and moved as they are not business functions but output functions |
|
3786 | - // -------------------- |
|
3787 | - |
|
3788 | - /* This is to show add lines */ |
|
3789 | - |
|
3790 | - /** |
|
3791 | - * Show add free and predefined products/services form |
|
3792 | - * |
|
3793 | - * @param int $dateSelector 1=Show also date range input fields |
|
3794 | - * @param Societe $seller Object thirdparty who sell |
|
3795 | - * @param Societe $buyer Object thirdparty who buy |
|
3796 | - * @return void |
|
3797 | - */ |
|
3798 | - function formAddObjectLine($dateSelector, $seller, $buyer) |
|
3799 | - { |
|
3800 | - global $conf,$user,$langs,$object,$hookmanager; |
|
3801 | - global $form,$bcnd,$var; |
|
3802 | - |
|
3803 | - // Line extrafield |
|
3804 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
3805 | - $extrafieldsline = new ExtraFields($this->db); |
|
3806 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
3807 | - |
|
3808 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
3809 | - // Use global variables + $dateSelector + $seller and $buyer |
|
3810 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
3811 | - foreach($dirtpls as $reldir) |
|
3812 | - { |
|
3813 | - $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
|
3814 | - if (empty($conf->file->strict_mode)) { |
|
3815 | - $res=@include $tpl; |
|
3816 | - } else { |
|
3817 | - $res=include $tpl; // for debug |
|
3818 | - } |
|
3819 | - if ($res) break; |
|
3820 | - } |
|
3821 | - } |
|
3822 | - |
|
3823 | - |
|
3824 | - |
|
3825 | - /* This is to show array of line of details */ |
|
3826 | - |
|
3827 | - |
|
3828 | - /** |
|
3829 | - * Return HTML table for object lines |
|
3830 | - * TODO Move this into an output class file (htmlline.class.php) |
|
3831 | - * If lines are into a template, title must also be into a template |
|
3832 | - * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
3833 | - * |
|
3834 | - * @param string $action Action code |
|
3835 | - * @param string $seller Object of seller third party |
|
3836 | - * @param string $buyer Object of buyer third party |
|
3837 | - * @param int $selected Object line selected |
|
3838 | - * @param int $dateSelector 1=Show also date range input fields |
|
3839 | - * @return void |
|
3840 | - */ |
|
3841 | - function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
3842 | - { |
|
3843 | - global $conf, $hookmanager, $langs, $user; |
|
3844 | - // TODO We should not use global var for this ! |
|
3845 | - global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
|
3846 | - |
|
3847 | - // Define usemargins |
|
3848 | - $usemargins=0; |
|
3849 | - if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1; |
|
3850 | - |
|
3851 | - $num = count($this->lines); |
|
3852 | - |
|
3853 | - // Line extrafield |
|
3854 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
3855 | - $extrafieldsline = new ExtraFields($this->db); |
|
3856 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
3857 | - |
|
3858 | - $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
3859 | - $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3860 | - if (empty($reshook)) |
|
3861 | - { |
|
3862 | - // Title line |
|
3863 | - print "<thead>\n"; |
|
3864 | - |
|
3865 | - print '<tr class="liste_titre nodrag nodrop">'; |
|
3866 | - |
|
3867 | - // Adds a line numbering column |
|
3868 | - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
3869 | - |
|
3870 | - // Description |
|
3871 | - print '<td class="linecoldescription">'.$langs->trans('Description').'</td>'; |
|
3872 | - |
|
3873 | - if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') |
|
3874 | - { |
|
3875 | - print '<td class="linerefsupplier"><span id="title_fourn_ref">'.$langs->trans("SupplierRef").'</span></td>'; |
|
3876 | - } |
|
1222 | + if (empty($contactid)) return 0; |
|
3877 | 1223 | |
3878 | - // VAT |
|
3879 | - print '<td class="linecolvat" align="right" width="80">'.$langs->trans('VAT').'</td>'; |
|
1224 | + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
1225 | + $contact = new Contact($this->db); |
|
1226 | + $result=$contact->fetch($contactid); |
|
1227 | + $this->contact = $contact; |
|
1228 | + return $result; |
|
1229 | + } |
|
3880 | 1230 | |
3881 | - // Price HT |
|
3882 | - print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>'; |
|
1231 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1232 | + /** |
|
1233 | + * Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty |
|
1234 | + * |
|
1235 | + * @param int $force_thirdparty_id Force thirdparty id |
|
1236 | + * @return int <0 if KO, >0 if OK |
|
1237 | + */ |
|
1238 | + function fetch_thirdparty($force_thirdparty_id=0) |
|
1239 | + { |
|
1240 | + // phpcs:enable |
|
1241 | + global $conf; |
|
3883 | 1242 | |
3884 | - // Multicurrency |
|
3885 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>'; |
|
1243 | + if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
|
1244 | + return 0; |
|
3886 | 1245 | |
3887 | - if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>'; |
|
1246 | + require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
3888 | 1247 | |
3889 | - // Qty |
|
3890 | - print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>'; |
|
1248 | + $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
|
1249 | + if ($force_thirdparty_id) |
|
1250 | + $idtofetch = $force_thirdparty_id; |
|
3891 | 1251 | |
3892 | - if($conf->global->PRODUCT_USE_UNITS) |
|
3893 | - { |
|
3894 | - print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>'; |
|
3895 | - } |
|
1252 | + if ($idtofetch) { |
|
1253 | + $thirdparty = new Societe($this->db); |
|
1254 | + $result = $thirdparty->fetch($idtofetch); |
|
1255 | + $this->thirdparty = $thirdparty; |
|
3896 | 1256 | |
3897 | - // Reduction short |
|
3898 | - print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>'; |
|
1257 | + // Use first price level if level not defined for third party |
|
1258 | + if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) { |
|
1259 | + $this->thirdparty->price_level = 1; |
|
1260 | + } |
|
3899 | 1261 | |
3900 | - if ($this->situation_cycle_ref) { |
|
3901 | - print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>'; |
|
3902 | - } |
|
1262 | + return $result; |
|
1263 | + } else |
|
1264 | + return -1; |
|
1265 | + } |
|
3903 | 1266 | |
3904 | - if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) |
|
3905 | - { |
|
3906 | - if (!empty($user->rights->margins->creer)) |
|
3907 | - { |
|
3908 | - if ($conf->global->MARGIN_TYPE == "1") |
|
3909 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>'; |
|
3910 | - else |
|
3911 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
|
3912 | - } |
|
3913 | 1267 | |
3914 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
3915 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>'; |
|
3916 | - if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
3917 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
|
3918 | - } |
|
1268 | + /** |
|
1269 | + * Looks for an object with ref matching the wildcard provided |
|
1270 | + * It does only work when $this->table_ref_field is set |
|
1271 | + * |
|
1272 | + * @param string $ref Wildcard |
|
1273 | + * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO |
|
1274 | + */ |
|
1275 | + public function fetchOneLike($ref) |
|
1276 | + { |
|
1277 | + if (!$this->table_ref_field) { |
|
1278 | + return 0; |
|
1279 | + } |
|
3919 | 1280 | |
3920 | - // Total HT |
|
3921 | - print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>'; |
|
1281 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE '.$this->table_ref_field.' LIKE "'.$this->db->escape($ref).'" LIMIT 1'; |
|
3922 | 1282 | |
3923 | - // Multicurrency |
|
3924 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>'; |
|
1283 | + $query = $this->db->query($sql); |
|
3925 | 1284 | |
3926 | - if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
|
1285 | + if (!$this->db->num_rows($query)) { |
|
1286 | + return 0; |
|
1287 | + } |
|
3927 | 1288 | |
3928 | - print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
1289 | + $result = $this->db->fetch_object($query); |
|
3929 | 1290 | |
3930 | - print '<td class="linecoldelete" width="10"></td>'; |
|
1291 | + return $this->fetch($result->rowid); |
|
1292 | + } |
|
3931 | 1293 | |
3932 | - print '<td class="linecolmove" width="10"></td>'; |
|
1294 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1295 | + /** |
|
1296 | + * Load data for barcode into properties ->barcode_type* |
|
1297 | + * Properties ->barcode_type that is id of barcode. Type is used to find other properties, but |
|
1298 | + * if it is not defined, ->element must be defined to know default barcode type. |
|
1299 | + * |
|
1300 | + * @return int <0 if KO, 0 if can't guess type of barcode (ISBN, EAN13...), >0 if OK (all barcode properties loaded) |
|
1301 | + */ |
|
1302 | + function fetch_barcode() |
|
1303 | + { |
|
1304 | + // phpcs:enable |
|
1305 | + global $conf; |
|
3933 | 1306 | |
3934 | - if($action == 'selectlines') |
|
3935 | - { |
|
3936 | - print '<td class="linecolcheckall" align="center">'; |
|
3937 | - print '<input type="checkbox" class="linecheckboxtoggle" />'; |
|
3938 | - print '<script type="text/javascript">$(document).ready(function() {$(".linecheckboxtoggle").click(function() {var checkBoxes = $(".linecheckbox");checkBoxes.prop("checked", this.checked);})});</script>'; |
|
3939 | - print '</td>'; |
|
3940 | - } |
|
3941 | - |
|
3942 | - print "</tr>\n"; |
|
3943 | - print "</thead>\n"; |
|
3944 | - } |
|
3945 | - |
|
3946 | - $var = true; |
|
3947 | - $i = 0; |
|
3948 | - |
|
3949 | - print "<tbody>\n"; |
|
3950 | - foreach ($this->lines as $line) |
|
3951 | - { |
|
3952 | - //Line extrafield |
|
3953 | - $line->fetch_optionals(); |
|
3954 | - |
|
3955 | - //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
3956 | - if (is_object($hookmanager)) // Old code is commented on preceding line. |
|
3957 | - { |
|
3958 | - if (empty($line->fk_parent_line)) |
|
3959 | - { |
|
3960 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
3961 | - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3962 | - } |
|
3963 | - else |
|
3964 | - { |
|
3965 | - $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); |
|
3966 | - $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3967 | - } |
|
3968 | - } |
|
3969 | - if (empty($reshook)) |
|
3970 | - { |
|
3971 | - $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
3972 | - } |
|
3973 | - |
|
3974 | - $i++; |
|
3975 | - } |
|
3976 | - print "</tbody>\n"; |
|
3977 | - } |
|
3978 | - |
|
3979 | - /** |
|
3980 | - * Return HTML content of a detail line |
|
3981 | - * TODO Move this into an output class file (htmlline.class.php) |
|
3982 | - * |
|
3983 | - * @param string $action GET/POST action |
|
3984 | - * @param CommonObjectLine $line Selected object line to output |
|
3985 | - * @param string $var Is it a an odd line (true) |
|
3986 | - * @param int $num Number of line (0) |
|
3987 | - * @param int $i I |
|
3988 | - * @param int $dateSelector 1=Show also date range input fields |
|
3989 | - * @param string $seller Object of seller third party |
|
3990 | - * @param string $buyer Object of buyer third party |
|
3991 | - * @param int $selected Object line selected |
|
3992 | - * @param int $extrafieldsline Object of extrafield line attribute |
|
3993 | - * @return void |
|
3994 | - */ |
|
3995 | - function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
3996 | - { |
|
3997 | - global $conf,$langs,$user,$object,$hookmanager; |
|
3998 | - global $form,$bc,$bcdd; |
|
3999 | - global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
4000 | - |
|
4001 | - $object_rights = $this->getRights(); |
|
4002 | - |
|
4003 | - $element=$this->element; |
|
4004 | - |
|
4005 | - $text=''; $description=''; $type=0; |
|
4006 | - |
|
4007 | - // Show product and description |
|
4008 | - $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
4009 | - // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
|
4010 | - if (! empty($line->date_start)) $type=1; // deprecated |
|
4011 | - if (! empty($line->date_end)) $type=1; // deprecated |
|
4012 | - |
|
4013 | - // Ligne en mode visu |
|
4014 | - if ($action != 'editline' || $selected != $line->id) |
|
4015 | - { |
|
4016 | - // Product |
|
4017 | - if ($line->fk_product > 0) |
|
4018 | - { |
|
4019 | - $product_static = new Product($this->db); |
|
4020 | - $product_static->fetch($line->fk_product); |
|
1307 | + dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
|
4021 | 1308 | |
4022 | - $product_static->ref = $line->ref; //can change ref in hook |
|
4023 | - $product_static->label = $line->label; //can change label in hook |
|
4024 | - $text=$product_static->getNomUrl(1); |
|
1309 | + $idtype=$this->barcode_type; |
|
1310 | + 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 |
|
1311 | + { |
|
1312 | + if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
1313 | + else if ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
1314 | + else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING); |
|
1315 | + } |
|
4025 | 1316 | |
4026 | - // Define output language and label |
|
4027 | - if (! empty($conf->global->MAIN_MULTILANGS)) |
|
4028 | - { |
|
4029 | - if (! is_object($this->thirdparty)) |
|
4030 | - { |
|
4031 | - dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); |
|
4032 | - return; |
|
4033 | - } |
|
4034 | - |
|
4035 | - $prod = new Product($this->db); |
|
4036 | - $prod->fetch($line->fk_product); |
|
4037 | - |
|
4038 | - $outputlangs = $langs; |
|
4039 | - $newlang=''; |
|
4040 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
4041 | - if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer |
|
4042 | - if (! empty($newlang)) |
|
4043 | - { |
|
4044 | - $outputlangs = new Translate("",$conf); |
|
4045 | - $outputlangs->setDefaultLang($newlang); |
|
4046 | - } |
|
4047 | - |
|
4048 | - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
4049 | - } |
|
4050 | - else |
|
4051 | - { |
|
4052 | - $label = $line->product_label; |
|
4053 | - } |
|
1317 | + if ($idtype > 0) |
|
1318 | + { |
|
1319 | + 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 |
|
1320 | + { |
|
1321 | + $sql = "SELECT rowid, code, libelle as label, coder"; |
|
1322 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
1323 | + $sql.= " WHERE rowid = ".$idtype; |
|
1324 | + dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
|
1325 | + $resql = $this->db->query($sql); |
|
1326 | + if ($resql) |
|
1327 | + { |
|
1328 | + $obj = $this->db->fetch_object($resql); |
|
1329 | + $this->barcode_type = $obj->rowid; |
|
1330 | + $this->barcode_type_code = $obj->code; |
|
1331 | + $this->barcode_type_label = $obj->label; |
|
1332 | + $this->barcode_type_coder = $obj->coder; |
|
1333 | + return 1; |
|
1334 | + } |
|
1335 | + else |
|
1336 | + { |
|
1337 | + dol_print_error($this->db); |
|
1338 | + return -1; |
|
1339 | + } |
|
1340 | + } |
|
1341 | + } |
|
1342 | + return 0; |
|
1343 | + } |
|
4054 | 1344 | |
4055 | - $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
4056 | - $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. |
|
4057 | - } |
|
1345 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1346 | + /** |
|
1347 | + * Load the project with id $this->fk_project into this->project |
|
1348 | + * |
|
1349 | + * @return int <0 if KO, >=0 if OK |
|
1350 | + */ |
|
1351 | + function fetch_projet() |
|
1352 | + { |
|
1353 | + // phpcs:enable |
|
1354 | + include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
4058 | 1355 | |
4059 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
1356 | + if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
1357 | + if (empty($this->fk_project)) return 0; |
|
4060 | 1358 | |
4061 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
4062 | - // Use global variables + $dateSelector + $seller and $buyer |
|
4063 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
4064 | - foreach($dirtpls as $reldir) |
|
4065 | - { |
|
4066 | - $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
|
4067 | - if (empty($conf->file->strict_mode)) { |
|
4068 | - $res=@include $tpl; |
|
4069 | - } else { |
|
4070 | - $res=include $tpl; // for debug |
|
4071 | - } |
|
4072 | - if ($res) break; |
|
4073 | - } |
|
4074 | - } |
|
4075 | - |
|
4076 | - // Ligne en mode update |
|
4077 | - if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
|
4078 | - { |
|
4079 | - $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
4080 | - $placeholder=' placeholder="'.$langs->trans("Label").'"'; |
|
4081 | - |
|
4082 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
4083 | - |
|
4084 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
4085 | - // Use global variables + $dateSelector + $seller and $buyer |
|
4086 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
4087 | - foreach($dirtpls as $reldir) |
|
4088 | - { |
|
4089 | - $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
|
4090 | - if (empty($conf->file->strict_mode)) { |
|
4091 | - $res=@include $tpl; |
|
4092 | - } else { |
|
4093 | - $res=include $tpl; // for debug |
|
4094 | - } |
|
4095 | - if ($res) break; |
|
4096 | - } |
|
4097 | - } |
|
4098 | - } |
|
4099 | - |
|
4100 | - |
|
4101 | - /* This is to show array of line of details of source object */ |
|
4102 | - |
|
4103 | - |
|
4104 | - /** |
|
4105 | - * Return HTML table table of source object lines |
|
4106 | - * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
4107 | - * If lines are into a template, title must also be into a template |
|
4108 | - * But for the moment we don't know if it's possible, so we keep the method available on overloaded objects. |
|
4109 | - * |
|
4110 | - * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
|
4111 | - * @return void |
|
4112 | - */ |
|
4113 | - function printOriginLinesList($restrictlist='') |
|
4114 | - { |
|
4115 | - global $langs, $hookmanager, $conf; |
|
4116 | - |
|
4117 | - print '<tr class="liste_titre">'; |
|
4118 | - print '<td>'.$langs->trans('Ref').'</td>'; |
|
4119 | - print '<td>'.$langs->trans('Description').'</td>'; |
|
4120 | - print '<td align="right">'.$langs->trans('VATRate').'</td>'; |
|
4121 | - print '<td align="right">'.$langs->trans('PriceUHT').'</td>'; |
|
4122 | - if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>'; |
|
4123 | - print '<td align="right">'.$langs->trans('Qty').'</td>'; |
|
4124 | - if($conf->global->PRODUCT_USE_UNITS) |
|
4125 | - { |
|
4126 | - print '<td align="left">'.$langs->trans('Unit').'</td>'; |
|
4127 | - } |
|
4128 | - print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>'; |
|
4129 | - |
|
4130 | - $var = true; |
|
4131 | - $i = 0; |
|
4132 | - |
|
4133 | - if (! empty($this->lines)) |
|
4134 | - { |
|
4135 | - foreach ($this->lines as $line) |
|
4136 | - { |
|
4137 | - if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
4138 | - { |
|
4139 | - if (empty($line->fk_parent_line)) |
|
4140 | - { |
|
4141 | - $parameters=array('line'=>$line,'var'=>$var,'i'=>$i); |
|
4142 | - $action=''; |
|
4143 | - $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
4144 | - } |
|
4145 | - } |
|
4146 | - else |
|
4147 | - { |
|
4148 | - $this->printOriginLine($line, $var, $restrictlist); |
|
4149 | - } |
|
1359 | + $project = new Project($this->db); |
|
1360 | + $result = $project->fetch($this->fk_project); |
|
4150 | 1361 | |
4151 | - $i++; |
|
4152 | - } |
|
4153 | - } |
|
4154 | - } |
|
4155 | - |
|
4156 | - /** |
|
4157 | - * Return HTML with a line of table array of source object lines |
|
4158 | - * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
4159 | - * If lines are into a template, title must also be into a template |
|
4160 | - * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
4161 | - * |
|
4162 | - * @param CommonObjectLine $line Line |
|
4163 | - * @param string $var Var |
|
4164 | - * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
|
4165 | - * @return void |
|
4166 | - */ |
|
4167 | - function printOriginLine($line, $var, $restrictlist='') |
|
4168 | - { |
|
4169 | - global $langs, $conf; |
|
4170 | - |
|
4171 | - //var_dump($line); |
|
4172 | - if (!empty($line->date_start)) |
|
4173 | - { |
|
4174 | - $date_start=$line->date_start; |
|
4175 | - } |
|
4176 | - else |
|
4177 | - { |
|
4178 | - $date_start=$line->date_debut_prevue; |
|
4179 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
4180 | - } |
|
4181 | - if (!empty($line->date_end)) |
|
4182 | - { |
|
4183 | - $date_end=$line->date_end; |
|
4184 | - } |
|
4185 | - else |
|
4186 | - { |
|
4187 | - $date_end=$line->date_fin_prevue; |
|
4188 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
4189 | - } |
|
4190 | - |
|
4191 | - $this->tpl['label'] = ''; |
|
4192 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow'); |
|
4193 | - |
|
4194 | - if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
|
4195 | - { |
|
4196 | - $discount=new DiscountAbsolute($this->db); |
|
4197 | - $discount->fk_soc = $this->socid; |
|
4198 | - $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
4199 | - } |
|
4200 | - else if (! empty($line->fk_product)) |
|
4201 | - { |
|
4202 | - $productstatic = new Product($this->db); |
|
4203 | - $productstatic->id = $line->fk_product; |
|
4204 | - $productstatic->ref = $line->ref; |
|
4205 | - $productstatic->type = $line->fk_product_type; |
|
4206 | - if(empty($productstatic->ref)){ |
|
4207 | - $line->fetch_product(); |
|
4208 | - $productstatic = $line->product; |
|
4209 | - } |
|
4210 | - |
|
4211 | - $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
4212 | - $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
4213 | - // Dates |
|
4214 | - if ($line->product_type == 1 && ($date_start || $date_end)) |
|
4215 | - { |
|
4216 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
4217 | - } |
|
4218 | - } |
|
4219 | - else |
|
4220 | - { |
|
4221 | - $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'))); |
|
4222 | - if (!empty($line->desc)) { |
|
4223 | - $this->tpl['label'].=$line->desc; |
|
4224 | - }else { |
|
4225 | - $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
4226 | - } |
|
4227 | - |
|
4228 | - // Dates |
|
4229 | - if ($line->product_type == 1 && ($date_start || $date_end)) |
|
4230 | - { |
|
4231 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
4232 | - } |
|
4233 | - } |
|
1362 | + $this->projet = $project; // deprecated |
|
1363 | + $this->project = $project; |
|
1364 | + return $result; |
|
1365 | + } |
|
4234 | 1366 | |
4235 | - if (! empty($line->desc)) |
|
4236 | - { |
|
4237 | - if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
|
4238 | - { |
|
4239 | - $discount=new DiscountAbsolute($this->db); |
|
4240 | - $discount->fetch($line->fk_remise_except); |
|
4241 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); |
|
4242 | - } |
|
4243 | - elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
|
4244 | - { |
|
4245 | - $discount=new DiscountAbsolute($this->db); |
|
4246 | - $discount->fetch($line->fk_remise_except); |
|
4247 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
|
4248 | - } |
|
4249 | - elseif ($line->desc == '(EXCESS RECEIVED)') |
|
4250 | - { |
|
4251 | - $discount=new DiscountAbsolute($this->db); |
|
4252 | - $discount->fetch($line->fk_remise_except); |
|
4253 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
|
4254 | - } |
|
4255 | - elseif ($line->desc == '(EXCESS PAID)') |
|
4256 | - { |
|
4257 | - $discount=new DiscountAbsolute($this->db); |
|
4258 | - $discount->fetch($line->fk_remise_except); |
|
4259 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0)); |
|
4260 | - } |
|
4261 | - else |
|
4262 | - { |
|
4263 | - $this->tpl['description'] = dol_trunc($line->desc,60); |
|
4264 | - } |
|
4265 | - } |
|
4266 | - else |
|
4267 | - { |
|
4268 | - $this->tpl['description'] = ' '; |
|
4269 | - } |
|
1367 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
1368 | + /** |
|
1369 | + * Load the product with id $this->fk_product into this->product |
|
1370 | + * |
|
1371 | + * @return int <0 if KO, >=0 if OK |
|
1372 | + */ |
|
1373 | + function fetch_product() |
|
1374 | + { |
|
1375 | + // phpcs:enable |
|
1376 | + include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
4270 | 1377 | |
4271 | - // VAT Rate |
|
4272 | - $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
|
4273 | - $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
|
4274 | - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')'; |
|
1378 | + if (empty($this->fk_product)) return 0; |
|
4275 | 1379 | |
4276 | - $this->tpl['price'] = price($line->subprice); |
|
4277 | - $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
|
4278 | - $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; |
|
4279 | - if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long')); |
|
4280 | - $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
|
4281 | - |
|
4282 | - // Is the line strike or not |
|
4283 | - $this->tpl['strike']=0; |
|
4284 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
4285 | - |
|
4286 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
4287 | - // Use global variables + $dateSelector + $seller and $buyer |
|
4288 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
4289 | - foreach($dirtpls as $reldir) |
|
4290 | - { |
|
4291 | - $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
|
4292 | - if (empty($conf->file->strict_mode)) { |
|
4293 | - $res=@include $tpl; |
|
4294 | - } else { |
|
4295 | - $res=include $tpl; // for debug |
|
4296 | - } |
|
4297 | - if ($res) break; |
|
4298 | - } |
|
4299 | - } |
|
1380 | + $product = new Product($this->db); |
|
1381 | + $result = $product->fetch($this->fk_product); |
|
4300 | 1382 | |
1383 | + $this->product = $product; |
|
1384 | + return $result; |
|
1385 | + } |
|
4301 | 1386 | |
4302 | 1387 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
4303 | - /** |
|
4304 | - * Add resources to the current object : add entry into llx_element_resources |
|
4305 | - * Need $this->element & $this->id |
|
4306 | - * |
|
4307 | - * @param int $resource_id Resource id |
|
4308 | - * @param string $resource_type 'resource' |
|
4309 | - * @param int $busy Busy or not |
|
4310 | - * @param int $mandatory Mandatory or not |
|
4311 | - * @return int <=0 if KO, >0 if OK |
|
4312 | - */ |
|
4313 | - function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
4314 | - { |
|
1388 | + /** |
|
1389 | + * Load the user with id $userid into this->user |
|
1390 | + * |
|
1391 | + * @param int $userid Id du contact |
|
1392 | + * @return int <0 if KO, >0 if OK |
|
1393 | + */ |
|
1394 | + function fetch_user($userid) |
|
1395 | + { |
|
4315 | 1396 | // phpcs:enable |
4316 | - $this->db->begin(); |
|
4317 | - |
|
4318 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; |
|
4319 | - $sql.= "resource_id"; |
|
4320 | - $sql.= ", resource_type"; |
|
4321 | - $sql.= ", element_id"; |
|
4322 | - $sql.= ", element_type"; |
|
4323 | - $sql.= ", busy"; |
|
4324 | - $sql.= ", mandatory"; |
|
4325 | - $sql.= ") VALUES ("; |
|
4326 | - $sql.= $resource_id; |
|
4327 | - $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
4328 | - $sql.= ", '".$this->db->escape($this->id)."'"; |
|
4329 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
4330 | - $sql.= ", '".$this->db->escape($busy)."'"; |
|
4331 | - $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
4332 | - $sql.= ")"; |
|
4333 | - |
|
4334 | - dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
|
4335 | - if ($this->db->query($sql)) |
|
4336 | - { |
|
4337 | - $this->db->commit(); |
|
4338 | - return 1; |
|
4339 | - } |
|
4340 | - else |
|
4341 | - { |
|
4342 | - $this->error=$this->db->lasterror(); |
|
4343 | - $this->db->rollback(); |
|
4344 | - return 0; |
|
4345 | - } |
|
4346 | - } |
|
1397 | + $user = new User($this->db); |
|
1398 | + $result=$user->fetch($userid); |
|
1399 | + $this->user = $user; |
|
1400 | + return $result; |
|
1401 | + } |
|
4347 | 1402 | |
4348 | 1403 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
4349 | - /** |
|
4350 | - * Delete a link to resource line |
|
4351 | - * |
|
4352 | - * @param int $rowid Id of resource line to delete |
|
4353 | - * @param int $element element name (for trigger) TODO: use $this->element into commonobject class |
|
4354 | - * @param int $notrigger Disable all triggers |
|
4355 | - * @return int >0 if OK, <0 if KO |
|
4356 | - */ |
|
4357 | - function delete_resource($rowid, $element, $notrigger=0) |
|
4358 | - { |
|
1404 | + /** |
|
1405 | + * Read linked origin object |
|
1406 | + * |
|
1407 | + * @return void |
|
1408 | + */ |
|
1409 | + function fetch_origin() |
|
1410 | + { |
|
4359 | 1411 | // phpcs:enable |
4360 | - global $user; |
|
4361 | - |
|
4362 | - $this->db->begin(); |
|
4363 | - |
|
4364 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
|
4365 | - $sql.= " WHERE rowid=".$rowid; |
|
1412 | + if ($this->origin == 'shipping') $this->origin = 'expedition'; |
|
1413 | + if ($this->origin == 'delivery') $this->origin = 'livraison'; |
|
1414 | + if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur'; |
|
4366 | 1415 | |
4367 | - dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
|
1416 | + $origin = $this->origin; |
|
4368 | 1417 | |
4369 | - $resql=$this->db->query($sql); |
|
4370 | - if (! $resql) |
|
4371 | - { |
|
4372 | - $this->error=$this->db->lasterror(); |
|
4373 | - $this->db->rollback(); |
|
4374 | - return -1; |
|
4375 | - } |
|
4376 | - else |
|
4377 | - { |
|
4378 | - if (! $notrigger) |
|
4379 | - { |
|
4380 | - $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
4381 | - if ($result < 0) { $this->db->rollback(); return -1; } |
|
4382 | - } |
|
4383 | - $this->db->commit(); |
|
4384 | - return 1; |
|
4385 | - } |
|
4386 | - } |
|
4387 | - |
|
4388 | - |
|
4389 | - /** |
|
4390 | - * Overwrite magic function to solve problem of cloning object that are kept as references |
|
4391 | - * |
|
4392 | - * @return void |
|
4393 | - */ |
|
4394 | - function __clone() |
|
4395 | - { |
|
4396 | - // Force a copy of this->lines, otherwise it will point to same object. |
|
4397 | - if (isset($this->lines) && is_array($this->lines)) |
|
4398 | - { |
|
4399 | - $nboflines=count($this->lines); |
|
4400 | - for($i=0; $i < $nboflines; $i++) |
|
4401 | - { |
|
4402 | - $this->lines[$i] = clone $this->lines[$i]; |
|
4403 | - } |
|
4404 | - } |
|
4405 | - } |
|
4406 | - |
|
4407 | - /** |
|
4408 | - * Common function for all objects extending CommonObject for generating documents |
|
4409 | - * |
|
4410 | - * @param string $modelspath Relative folder where generators are placed |
|
4411 | - * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example. |
|
4412 | - * @param Translate $outputlangs Output language to use |
|
4413 | - * @param int $hidedetails 1 to hide details. 0 by default |
|
4414 | - * @param int $hidedesc 1 to hide product description. 0 by default |
|
4415 | - * @param int $hideref 1 to hide product reference. 0 by default |
|
4416 | - * @param null|array $moreparams Array to provide more information |
|
4417 | - * @return int >0 if OK, <0 if KO |
|
4418 | - * @see addFileIntoDatabaseIndex |
|
4419 | - */ |
|
4420 | - protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
4421 | - { |
|
4422 | - global $conf, $langs, $user; |
|
4423 | - |
|
4424 | - $srctemplatepath=''; |
|
4425 | - |
|
4426 | - // Increase limit for PDF build |
|
4427 | - $err=error_reporting(); |
|
4428 | - error_reporting(0); |
|
4429 | - @set_time_limit(120); |
|
4430 | - error_reporting($err); |
|
4431 | - |
|
4432 | - // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
|
4433 | - $tmp=explode(':',$modele,2); |
|
4434 | - if (! empty($tmp[1])) |
|
4435 | - { |
|
4436 | - $modele=$tmp[0]; |
|
4437 | - $srctemplatepath=$tmp[1]; |
|
4438 | - } |
|
4439 | - |
|
4440 | - // Search template files |
|
4441 | - $file=''; $classname=''; $filefound=0; |
|
4442 | - $dirmodels=array('/'); |
|
4443 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
4444 | - foreach($dirmodels as $reldir) |
|
4445 | - { |
|
4446 | - foreach(array('doc','pdf') as $prefix) |
|
4447 | - { |
|
4448 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
4449 | - else $file = $prefix."_".$modele.".modules.php"; |
|
1418 | + $classname = ucfirst($origin); |
|
1419 | + $this->$origin = new $classname($this->db); |
|
1420 | + $this->$origin->fetch($this->origin_id); |
|
1421 | + } |
|
4450 | 1422 | |
4451 | - // On verifie l'emplacement du modele |
|
4452 | - $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
4453 | - if (file_exists($file)) |
|
4454 | - { |
|
4455 | - $filefound=1; |
|
4456 | - $classname=$prefix.'_'.$modele; |
|
4457 | - break; |
|
4458 | - } |
|
4459 | - } |
|
4460 | - if ($filefound) break; |
|
4461 | - } |
|
1423 | + /** |
|
1424 | + * Load object from specific field |
|
1425 | + * |
|
1426 | + * @param string $table Table element or element line |
|
1427 | + * @param string $field Field selected |
|
1428 | + * @param string $key Import key |
|
1429 | + * @param string $element Element name |
|
1430 | + * @return int <0 if KO, >0 if OK |
|
1431 | + */ |
|
1432 | + function fetchObjectFrom($table, $field, $key, $element = null) |
|
1433 | + { |
|
1434 | + global $conf; |
|
4462 | 1435 | |
4463 | - // If generator was found |
|
4464 | - if ($filefound) |
|
4465 | - { |
|
4466 | - global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
1436 | + $result=false; |
|
4467 | 1437 | |
4468 | - require_once $file; |
|
1438 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
|
1439 | + $sql.= " WHERE ".$field." = '".$key."'"; |
|
1440 | + if (! empty($element)) { |
|
1441 | + $sql.= " AND entity IN (".getEntity($element).")"; |
|
1442 | + } else { |
|
1443 | + $sql.= " AND entity = ".$conf->entity; |
|
1444 | + } |
|
4469 | 1445 | |
4470 | - $obj = new $classname($this->db); |
|
1446 | + dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
|
1447 | + $resql = $this->db->query($sql); |
|
1448 | + if ($resql) |
|
1449 | + { |
|
1450 | + $row = $this->db->fetch_row($resql); |
|
1451 | + // Test for avoid error -1 |
|
1452 | + if ($row[0] > 0) { |
|
1453 | + $result = $this->fetch($row[0]); |
|
1454 | + } |
|
1455 | + } |
|
4471 | 1456 | |
4472 | - // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
|
4473 | - if ($obj->type == 'odt' && empty($srctemplatepath)) |
|
4474 | - { |
|
4475 | - $varfortemplatedir=$obj->scandir; |
|
4476 | - if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) |
|
4477 | - { |
|
4478 | - $dirtoscan=$conf->global->$varfortemplatedir; |
|
4479 | - |
|
4480 | - $listoffiles=array(); |
|
4481 | - |
|
4482 | - // Now we add first model found in directories scanned |
|
4483 | - $listofdir=explode(',',$dirtoscan); |
|
4484 | - foreach($listofdir as $key => $tmpdir) |
|
4485 | - { |
|
4486 | - $tmpdir=trim($tmpdir); |
|
4487 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
4488 | - if (! $tmpdir) { unset($listofdir[$key]); continue; } |
|
4489 | - if (is_dir($tmpdir)) |
|
4490 | - { |
|
4491 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
4492 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
4493 | - } |
|
4494 | - } |
|
4495 | - |
|
4496 | - if (count($listoffiles)) |
|
4497 | - { |
|
4498 | - foreach($listoffiles as $record) |
|
4499 | - { |
|
4500 | - $srctemplatepath=$record['fullname']; |
|
4501 | - break; |
|
4502 | - } |
|
4503 | - } |
|
4504 | - } |
|
1457 | + return $result; |
|
1458 | + } |
|
4505 | 1459 | |
4506 | - if (empty($srctemplatepath)) |
|
4507 | - { |
|
4508 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
4509 | - return -1; |
|
4510 | - } |
|
4511 | - } |
|
1460 | + /** |
|
1461 | + * Getter generic. Load value from a specific field |
|
1462 | + * |
|
1463 | + * @param string $table Table of element or element line |
|
1464 | + * @param int $id Element id |
|
1465 | + * @param string $field Field selected |
|
1466 | + * @return int <0 if KO, >0 if OK |
|
1467 | + */ |
|
1468 | + function getValueFrom($table, $id, $field) |
|
1469 | + { |
|
1470 | + $result=false; |
|
1471 | + if (!empty($id) && !empty($field) && !empty($table)) { |
|
1472 | + $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
|
1473 | + $sql.= " WHERE rowid = ".$id; |
|
1474 | + |
|
1475 | + dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
|
1476 | + $resql = $this->db->query($sql); |
|
1477 | + if ($resql) |
|
1478 | + { |
|
1479 | + $row = $this->db->fetch_row($resql); |
|
1480 | + $result = $row[0]; |
|
1481 | + } |
|
1482 | + } |
|
1483 | + return $result; |
|
1484 | + } |
|
4512 | 1485 | |
4513 | - if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
4514 | - { |
|
4515 | - if (! dol_is_file($srctemplatepath)) |
|
4516 | - { |
|
4517 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
4518 | - return -1; |
|
4519 | - } |
|
4520 | - } |
|
1486 | + /** |
|
1487 | + * Setter generic. Update a specific field into database. |
|
1488 | + * Warning: Trigger is run only if param trigkey is provided. |
|
1489 | + * |
|
1490 | + * @param string $field Field to update |
|
1491 | + * @param mixed $value New value |
|
1492 | + * @param string $table To force other table element or element line (should not be used) |
|
1493 | + * @param int $id To force other object id (should not be used) |
|
1494 | + * @param string $format Data format ('text', 'date'). 'text' is used if not defined |
|
1495 | + * @param string $id_field To force rowid field name. 'rowid' is used if not defined |
|
1496 | + * @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none' |
|
1497 | + * @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY') |
|
1498 | + * @param string $fk_user_field Name of field to save user id making change |
|
1499 | + * @return int <0 if KO, >0 if OK |
|
1500 | + * @see updateExtraField |
|
1501 | + */ |
|
1502 | + function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif') |
|
1503 | + { |
|
1504 | + global $user,$langs,$conf; |
|
4521 | 1505 | |
4522 | - // We save charset_output to restore it because write_file can change it if needed for |
|
4523 | - // output format that does not support UTF8. |
|
4524 | - $sav_charset_output=$outputlangs->charset_output; |
|
1506 | + if (empty($table)) $table=$this->table_element; |
|
1507 | + if (empty($id)) $id=$this->id; |
|
1508 | + if (empty($format)) $format='text'; |
|
1509 | + if (empty($id_field)) $id_field='rowid'; |
|
4525 | 1510 | |
4526 | - if (in_array(get_class($this), array('Adherent'))) |
|
4527 | - { |
|
4528 | - $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
4529 | - $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
|
4530 | - } |
|
4531 | - else |
|
4532 | - { |
|
4533 | - $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
4534 | - } |
|
4535 | - // After call of write_file $obj->result['fullpath'] is set with generated file. It will be used to update the ECM database index. |
|
1511 | + $error=0; |
|
4536 | 1512 | |
4537 | - if ($resultwritefile > 0) |
|
4538 | - { |
|
4539 | - $outputlangs->charset_output=$sav_charset_output; |
|
1513 | + $this->db->begin(); |
|
4540 | 1514 | |
4541 | - // We delete old preview |
|
4542 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
4543 | - dol_delete_preview($this); |
|
1515 | + // Special case |
|
1516 | + if ($table == 'product' && $field == 'note_private') $field='note'; |
|
1517 | + if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod'; |
|
4544 | 1518 | |
4545 | - // Index file in database |
|
4546 | - if (! empty($obj->result['fullpath'])) |
|
4547 | - { |
|
4548 | - $destfull = $obj->result['fullpath']; |
|
4549 | - $upload_dir = dirname($destfull); |
|
4550 | - $destfile = basename($destfull); |
|
4551 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); |
|
4552 | - |
|
4553 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
4554 | - { |
|
4555 | - $filename = basename($destfile); |
|
4556 | - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
4557 | - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
4558 | - |
|
4559 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
4560 | - $ecmfile=new EcmFiles($this->db); |
|
4561 | - $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
4562 | - |
|
4563 | - // Set the public "share" key |
|
4564 | - $setsharekey = false; |
|
4565 | - if ($this->element == 'propal') |
|
4566 | - { |
|
4567 | - $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
4568 | - if ($useonlinesignature) $setsharekey=true; |
|
4569 | - if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4570 | - } |
|
4571 | - if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4572 | - if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4573 | - if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4574 | - |
|
4575 | - if ($setsharekey) |
|
4576 | - { |
|
4577 | - if (empty($ecmfile->share)) // Because object not found or share not set yet |
|
4578 | - { |
|
4579 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
4580 | - $ecmfile->share = getRandomPassword(true); |
|
4581 | - } |
|
4582 | - } |
|
1519 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
|
4583 | 1520 | |
4584 | - if ($result > 0) |
|
4585 | - { |
|
4586 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
4587 | - $ecmfile->fullpath_orig = ''; |
|
4588 | - $ecmfile->gen_or_uploaded = 'generated'; |
|
4589 | - $ecmfile->description = ''; // indexed content |
|
4590 | - $ecmfile->keyword = ''; // keyword content |
|
4591 | - $result = $ecmfile->update($user); |
|
4592 | - if ($result < 0) |
|
4593 | - { |
|
4594 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
4595 | - } |
|
4596 | - } |
|
4597 | - else |
|
4598 | - { |
|
4599 | - $ecmfile->entity = $conf->entity; |
|
4600 | - $ecmfile->filepath = $rel_dir; |
|
4601 | - $ecmfile->filename = $filename; |
|
4602 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
4603 | - $ecmfile->fullpath_orig = ''; |
|
4604 | - $ecmfile->gen_or_uploaded = 'generated'; |
|
4605 | - $ecmfile->description = ''; // indexed content |
|
4606 | - $ecmfile->keyword = ''; // keyword content |
|
4607 | - $ecmfile->src_object_type = $this->table_element; |
|
4608 | - $ecmfile->src_object_id = $this->id; |
|
4609 | - |
|
4610 | - $result = $ecmfile->create($user); |
|
4611 | - if ($result < 0) |
|
4612 | - { |
|
4613 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
4614 | - } |
|
4615 | - } |
|
1521 | + if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
1522 | + else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
1523 | + else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
4616 | 1524 | |
4617 | - /*$this->result['fullname']=$destfull; |
|
4618 | - $this->result['filepath']=$ecmfile->filepath; |
|
4619 | - $this->result['filename']=$ecmfile->filename;*/ |
|
4620 | - //var_dump($obj->update_main_doc_field);exit; |
|
4621 | - |
|
4622 | - // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
|
4623 | - $update_main_doc_field=0; |
|
4624 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
4625 | - if ($update_main_doc_field && ! empty($this->table_element)) |
|
4626 | - { |
|
4627 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
|
4628 | - $sql.= ' WHERE rowid = '.$this->id; |
|
4629 | - $resql = $this->db->query($sql); |
|
4630 | - if (! $resql) dol_print_error($this->db); |
|
4631 | - } |
|
4632 | - } |
|
4633 | - } |
|
4634 | - else |
|
4635 | - { |
|
4636 | - dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING); |
|
4637 | - } |
|
1525 | + if ($fk_user_field) |
|
1526 | + { |
|
1527 | + if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
1528 | + elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
1529 | + } |
|
4638 | 1530 | |
4639 | - // Success in building document. We build meta file. |
|
4640 | - dol_meta_create($this); |
|
1531 | + $sql.= " WHERE ".$id_field." = ".$id; |
|
4641 | 1532 | |
4642 | - return 1; |
|
4643 | - } |
|
4644 | - else |
|
4645 | - { |
|
4646 | - $outputlangs->charset_output=$sav_charset_output; |
|
4647 | - dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
|
4648 | - return -1; |
|
4649 | - } |
|
4650 | - } |
|
4651 | - else |
|
4652 | - { |
|
4653 | - $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
|
4654 | - dol_print_error('',$this->error); |
|
4655 | - return -1; |
|
4656 | - } |
|
4657 | - } |
|
4658 | - |
|
4659 | - /** |
|
4660 | - * Build thumb |
|
4661 | - * @TODO Move this into files.lib.php |
|
4662 | - * |
|
4663 | - * @param string $file Path file in UTF8 to original file to create thumbs from. |
|
4664 | - * @return void |
|
4665 | - */ |
|
4666 | - function addThumbs($file) |
|
4667 | - { |
|
4668 | - global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
|
4669 | - |
|
4670 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
4671 | - |
|
4672 | - $file_osencoded=dol_osencode($file); |
|
4673 | - if (file_exists($file_osencoded)) |
|
4674 | - { |
|
4675 | - // Create small thumbs for company (Ratio is near 16/9) |
|
4676 | - // Used on logon for example |
|
4677 | - vignette($file_osencoded, $maxwidthsmall, $maxheightsmall, '_small', $quality); |
|
4678 | - |
|
4679 | - // Create mini thumbs for company (Ratio is near 16/9) |
|
4680 | - // Used on menu or for setup page for example |
|
4681 | - vignette($file_osencoded, $maxwidthmini, $maxheightmini, '_mini', $quality); |
|
4682 | - } |
|
4683 | - } |
|
4684 | - |
|
4685 | - |
|
4686 | - /* Functions common to commonobject and commonobjectline */ |
|
4687 | - |
|
4688 | - /* For default values */ |
|
4689 | - |
|
4690 | - /** |
|
4691 | - * Return the default value to use for a field when showing the create form of object. |
|
4692 | - * Return values in this order: |
|
4693 | - * 1) If parameter is available into POST, we return it first. |
|
4694 | - * 2) If not but an alternate value was provided as parameter of function, we return it. |
|
4695 | - * 3) If not but a constant $conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table). |
|
4696 | - * 4) Return value found into database (TODO No yet implemented) |
|
4697 | - * |
|
4698 | - * @param string $fieldname Name of field |
|
4699 | - * @param string $alternatevalue Alternate value to use |
|
4700 | - * @return string|string[] Default value (can be an array if the GETPOST return an array) |
|
4701 | - **/ |
|
4702 | - function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
4703 | - { |
|
4704 | - global $conf, $_POST; |
|
4705 | - |
|
4706 | - // If param here has been posted, we use this value first. |
|
4707 | - if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); |
|
4708 | - |
|
4709 | - if (isset($alternatevalue)) return $alternatevalue; |
|
4710 | - |
|
4711 | - $newelement=$this->element; |
|
4712 | - if ($newelement == 'facture') $newelement='invoice'; |
|
4713 | - if ($newelement == 'commande') $newelement='order'; |
|
4714 | - if (empty($newelement)) |
|
4715 | - { |
|
4716 | - dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING); |
|
4717 | - return ''; |
|
4718 | - } |
|
4719 | - |
|
4720 | - $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
4721 | - //var_dump($keyforfieldname); |
|
4722 | - if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
|
4723 | - |
|
4724 | - // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname |
|
4725 | - } |
|
4726 | - |
|
4727 | - |
|
4728 | - /* For triggers */ |
|
1533 | + dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
|
1534 | + $resql = $this->db->query($sql); |
|
1535 | + if ($resql) |
|
1536 | + { |
|
1537 | + if ($trigkey) |
|
1538 | + { |
|
1539 | + // call trigger with updated object values |
|
1540 | + if (empty($this->fields) && method_exists($this, 'fetch')) |
|
1541 | + { |
|
1542 | + $result = $this->fetch($id); |
|
1543 | + } |
|
1544 | + else |
|
1545 | + { |
|
1546 | + $result = $this->fetchCommon($id); |
|
1547 | + } |
|
1548 | + if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
1549 | + if ($result < 0) $error++; |
|
1550 | + } |
|
4729 | 1551 | |
1552 | + if (! $error) |
|
1553 | + { |
|
1554 | + if (property_exists($this, $field)) $this->$field = $value; |
|
1555 | + $this->db->commit(); |
|
1556 | + return 1; |
|
1557 | + } |
|
1558 | + else |
|
1559 | + { |
|
1560 | + $this->db->rollback(); |
|
1561 | + return -2; |
|
1562 | + } |
|
1563 | + } |
|
1564 | + else |
|
1565 | + { |
|
1566 | + $this->error=$this->db->lasterror(); |
|
1567 | + $this->db->rollback(); |
|
1568 | + return -1; |
|
1569 | + } |
|
1570 | + } |
|
4730 | 1571 | |
4731 | 1572 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
4732 | - /** |
|
4733 | - * Call trigger based on this instance. |
|
4734 | - * Some context information may also be provided into array property this->context. |
|
4735 | - * NB: Error from trigger are stacked in interface->errors |
|
4736 | - * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. |
|
4737 | - * |
|
4738 | - * @param string $trigger_name trigger's name to execute |
|
4739 | - * @param User $user Object user |
|
4740 | - * @return int Result of run_triggers |
|
4741 | - */ |
|
4742 | - function call_trigger($trigger_name, $user) |
|
4743 | - { |
|
1573 | + /** |
|
1574 | + * Load properties id_previous and id_next by comparing $fieldid with $this->ref |
|
1575 | + * |
|
1576 | + * @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')" |
|
1577 | + * @param string $fieldid Name of field to use for the select MAX and MIN |
|
1578 | + * @param int $nodbprefix Do not include DB prefix to forge table name |
|
1579 | + * @return int <0 if KO, >0 if OK |
|
1580 | + */ |
|
1581 | + function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
1582 | + { |
|
4744 | 1583 | // phpcs:enable |
4745 | - global $langs,$conf; |
|
1584 | + global $conf, $user; |
|
4746 | 1585 | |
4747 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
4748 | - $interface=new Interfaces($this->db); |
|
4749 | - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
1586 | + if (! $this->table_element) |
|
1587 | + { |
|
1588 | + dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
|
1589 | + return -1; |
|
1590 | + } |
|
1591 | + if ($fieldid == 'none') return 1; |
|
4750 | 1592 | |
4751 | - if ($result < 0) |
|
4752 | - { |
|
4753 | - if (!empty($this->errors)) |
|
4754 | - { |
|
4755 | - $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 | - } |
|
4757 | - else |
|
4758 | - { |
|
4759 | - $this->errors=$interface->errors; |
|
4760 | - } |
|
4761 | - } |
|
4762 | - return $result; |
|
4763 | - } |
|
1593 | + // Security on socid |
|
1594 | + $socid = 0; |
|
1595 | + if ($user->societe_id > 0) $socid = $user->societe_id; |
|
4764 | 1596 | |
1597 | + // this->ismultientitymanaged contains |
|
1598 | + // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
1599 | + $alias = 's'; |
|
1600 | + if ($this->element == 'societe') $alias = 'te'; |
|
4765 | 1601 | |
4766 | - /* Functions for extrafields */ |
|
1602 | + $sql = "SELECT MAX(te.".$fieldid.")"; |
|
1603 | + $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
1604 | + if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1605 | + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1606 | + } |
|
1607 | + 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 |
|
1608 | + 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 |
|
1609 | + 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 |
|
1610 | + 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"; |
|
1611 | + $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1612 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
1613 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
1614 | + if (! empty($filter)) |
|
1615 | + { |
|
1616 | + if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
1617 | + $sql.=$filter; |
|
1618 | + } |
|
1619 | + 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 |
|
1620 | + 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 |
|
1621 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
|
1622 | + if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1623 | + if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
1624 | + $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
1625 | + } else { |
|
1626 | + $sql.= " AND ug.fk_user = te.rowid"; |
|
1627 | + $sql.= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1628 | + } |
|
1629 | + } else { |
|
1630 | + $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1631 | + } |
|
1632 | + } |
|
1633 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
1634 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
1635 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
1636 | + //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
4767 | 1637 | |
1638 | + $result = $this->db->query($sql); |
|
1639 | + if (! $result) |
|
1640 | + { |
|
1641 | + $this->error=$this->db->lasterror(); |
|
1642 | + return -1; |
|
1643 | + } |
|
1644 | + $row = $this->db->fetch_row($result); |
|
1645 | + $this->ref_previous = $row[0]; |
|
4768 | 1646 | |
4769 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
4770 | - /** |
|
4771 | - * Function to get extra fields of an object into $this->array_options |
|
4772 | - * This method is in most cases called by method fetch of objects but you can call it separately. |
|
4773 | - * |
|
4774 | - * @param int $rowid Id of line. Use the id of object if not defined. Deprecated. Function must be called without parameters. |
|
4775 | - * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
|
4776 | - * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
|
4777 | - */ |
|
4778 | - function fetch_optionals($rowid=null, $optionsArray=null) |
|
4779 | - { |
|
4780 | - // phpcs:enable |
|
4781 | - if (empty($rowid)) $rowid=$this->id; |
|
4782 | - |
|
4783 | - // To avoid SQL errors. Probably not the better solution though |
|
4784 | - if (!$this->table_element) { |
|
4785 | - return 0; |
|
4786 | - } |
|
4787 | - |
|
4788 | - $this->array_options=array(); |
|
4789 | - |
|
4790 | - if (! is_array($optionsArray)) |
|
4791 | - { |
|
4792 | - // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
|
4793 | - // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
|
4794 | - // global $extrafields; |
|
4795 | - //if (! is_object($extrafields)) |
|
4796 | - //{ |
|
4797 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
4798 | - $extrafields = new ExtraFields($this->db); |
|
4799 | - //} |
|
4800 | - |
|
4801 | - // Load array of extrafields for elementype = $this->table_element |
|
4802 | - if (empty($extrafields->attributes[$this->table_element]['loaded'])) |
|
4803 | - { |
|
4804 | - $extrafields->fetch_name_optionals_label($this->table_element); |
|
4805 | - } |
|
4806 | - $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
|
4807 | - } |
|
4808 | - else |
|
4809 | - { |
|
4810 | - global $extrafields; |
|
4811 | - dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING); |
|
4812 | - } |
|
4813 | - |
|
4814 | - $table_element = $this->table_element; |
|
4815 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
4816 | - |
|
4817 | - // Request to get complementary values |
|
4818 | - if (is_array($optionsArray) && count($optionsArray) > 0) |
|
4819 | - { |
|
4820 | - $sql = "SELECT rowid"; |
|
4821 | - foreach ($optionsArray as $name => $label) |
|
4822 | - { |
|
4823 | - if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
|
4824 | - { |
|
4825 | - $sql.= ", ".$name; |
|
4826 | - } |
|
4827 | - } |
|
4828 | - $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
4829 | - $sql.= " WHERE fk_object = ".$rowid; |
|
4830 | 1647 | |
4831 | - //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
|
4832 | - $resql=$this->db->query($sql); |
|
4833 | - if ($resql) |
|
4834 | - { |
|
4835 | - $this->array_options = array(); |
|
4836 | - $numrows=$this->db->num_rows($resql); |
|
4837 | - if ($numrows) |
|
4838 | - { |
|
4839 | - $tab = $this->db->fetch_array($resql); |
|
4840 | - |
|
4841 | - foreach ($tab as $key => $value) |
|
4842 | - { |
|
4843 | - // 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) |
|
4844 | - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
4845 | - { |
|
4846 | - // we can add this attribute to object |
|
4847 | - if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime'))) |
|
4848 | - { |
|
4849 | - //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
|
4850 | - $this->array_options["options_".$key]=$this->db->jdate($value); |
|
4851 | - } |
|
4852 | - else |
|
4853 | - { |
|
4854 | - $this->array_options["options_".$key]=$value; |
|
4855 | - } |
|
1648 | + $sql = "SELECT MIN(te.".$fieldid.")"; |
|
1649 | + $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
1650 | + if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1651 | + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1652 | + } |
|
1653 | + 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 |
|
1654 | + 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 |
|
1655 | + 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 |
|
1656 | + 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"; |
|
1657 | + $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1658 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
1659 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
1660 | + if (! empty($filter)) |
|
1661 | + { |
|
1662 | + if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
1663 | + $sql.=$filter; |
|
1664 | + } |
|
1665 | + 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 |
|
1666 | + 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 |
|
1667 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
|
1668 | + if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1669 | + if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
1670 | + $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
1671 | + } else { |
|
1672 | + $sql.= " AND ug.fk_user = te.rowid"; |
|
1673 | + $sql.= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1674 | + } |
|
1675 | + } else { |
|
1676 | + $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1677 | + } |
|
1678 | + } |
|
1679 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
1680 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
1681 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
1682 | + //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
1683 | + // 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 |
|
1684 | + |
|
1685 | + $result = $this->db->query($sql); |
|
1686 | + if (! $result) |
|
1687 | + { |
|
1688 | + $this->error=$this->db->lasterror(); |
|
1689 | + return -2; |
|
1690 | + } |
|
1691 | + $row = $this->db->fetch_row($result); |
|
1692 | + $this->ref_next = $row[0]; |
|
4856 | 1693 | |
4857 | - //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]); |
|
4858 | - } |
|
4859 | - } |
|
4860 | - } |
|
1694 | + return 1; |
|
1695 | + } |
|
4861 | 1696 | |
4862 | - $this->db->free($resql); |
|
4863 | 1697 | |
4864 | - if ($numrows) return $numrows; |
|
4865 | - else return 0; |
|
4866 | - } |
|
4867 | - else |
|
4868 | - { |
|
4869 | - dol_print_error($this->db); |
|
4870 | - return -1; |
|
4871 | - } |
|
4872 | - } |
|
4873 | - return 0; |
|
4874 | - } |
|
4875 | - |
|
4876 | - /** |
|
4877 | - * Delete all extra fields values for the current object. |
|
4878 | - * |
|
4879 | - * @return int <0 if KO, >0 if OK |
|
4880 | - */ |
|
4881 | - function deleteExtraFields() |
|
4882 | - { |
|
4883 | - $this->db->begin(); |
|
4884 | - |
|
4885 | - $table_element = $this->table_element; |
|
4886 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
4887 | - |
|
4888 | - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
4889 | - dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
|
4890 | - $resql=$this->db->query($sql_del); |
|
4891 | - if (! $resql) |
|
4892 | - { |
|
4893 | - $this->error=$this->db->lasterror(); |
|
4894 | - $this->db->rollback(); |
|
4895 | - return -1; |
|
4896 | - } |
|
4897 | - else |
|
4898 | - { |
|
4899 | - $this->db->commit(); |
|
4900 | - return 1; |
|
4901 | - } |
|
4902 | - } |
|
4903 | - |
|
4904 | - /** |
|
4905 | - * Add/Update all extra fields values for the current object. |
|
4906 | - * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) |
|
4907 | - * This function delete record with all extrafields and insert them again from the array $this->array_options. |
|
4908 | - * |
|
4909 | - * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
4910 | - * @param User $userused Object user |
|
4911 | - * @return int -1=error, O=did nothing, 1=OK |
|
4912 | - * @see updateExtraField, setValueFrom |
|
4913 | - */ |
|
4914 | - function insertExtraFields($trigger='', $userused=null) |
|
4915 | - { |
|
4916 | - global $conf,$langs,$user; |
|
4917 | - |
|
4918 | - if (empty($userused)) $userused=$user; |
|
4919 | - |
|
4920 | - $error=0; |
|
4921 | - |
|
4922 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
4923 | - |
|
4924 | - if (! empty($this->array_options)) |
|
4925 | - { |
|
4926 | - // Check parameters |
|
4927 | - $langs->load('admin'); |
|
4928 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
4929 | - $extrafields = new ExtraFields($this->db); |
|
4930 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
4931 | - |
|
4932 | - //Eliminate copied source object extra_fields that do not exist in target object |
|
4933 | - $new_array_options=array(); |
|
4934 | - foreach ($this->array_options as $key => $value) { |
|
4935 | - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
4936 | - $new_array_options[$key] = $value; |
|
4937 | - elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
|
4938 | - $new_array_options['options_'.$key] = $value; |
|
4939 | - } |
|
4940 | - |
|
4941 | - foreach($new_array_options as $key => $value) |
|
4942 | - { |
|
4943 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
4944 | - $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
|
4945 | - $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
|
4946 | - $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
|
4947 | - $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey]; |
|
4948 | - |
|
4949 | - if ($attributeRequired) |
|
4950 | - { |
|
4951 | - $mandatorypb=false; |
|
4952 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
4953 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
4954 | - if ($mandatorypb) |
|
4955 | - { |
|
4956 | - dol_syslog($this->error); |
|
4957 | - $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel); |
|
4958 | - return -1; |
|
4959 | - } |
|
4960 | - } |
|
4961 | - |
|
4962 | - //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); |
|
4963 | - //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); |
|
4964 | - |
|
4965 | - switch ($attributeType) |
|
4966 | - { |
|
4967 | - case 'int': |
|
4968 | - if (!is_numeric($value) && $value!='') |
|
4969 | - { |
|
4970 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
4971 | - return -1; |
|
4972 | - } |
|
4973 | - elseif ($value=='') |
|
4974 | - { |
|
4975 | - $new_array_options[$key] = null; |
|
4976 | - } |
|
4977 | - break; |
|
4978 | - case 'double': |
|
4979 | - $value = price2num($value); |
|
4980 | - if (!is_numeric($value) && $value!='') |
|
4981 | - { |
|
4982 | - dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
|
4983 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
4984 | - return -1; |
|
4985 | - } |
|
4986 | - elseif ($value=='') |
|
4987 | - { |
|
4988 | - $new_array_options[$key] = null; |
|
4989 | - } |
|
4990 | - //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG); |
|
4991 | - $new_array_options[$key] = $value; |
|
4992 | - break; |
|
4993 | - /*case 'select': // Not required, we chosed value='0' for undefined values |
|
4994 | - if ($value=='-1') |
|
4995 | - { |
|
4996 | - $this->array_options[$key] = null; |
|
4997 | - } |
|
4998 | - break;*/ |
|
4999 | - case 'password': |
|
5000 | - $algo=''; |
|
5001 | - if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
|
5002 | - { |
|
5003 | - // If there is an encryption choice, we use it to crypt data before insert |
|
5004 | - $tmparrays = array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options']); |
|
5005 | - $algo=reset($tmparrays); |
|
5006 | - if ($algo != '') |
|
5007 | - { |
|
5008 | - //global $action; // $action may be 'create', 'update', 'update_extras'... |
|
5009 | - //var_dump($action); |
|
5010 | - //var_dump($this->oldcopy);exit; |
|
5011 | - if (is_object($this->oldcopy)) // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value |
|
5012 | - { |
|
5013 | - //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
|
5014 | - 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. |
|
5015 | - { |
|
5016 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
5017 | - } |
|
5018 | - else |
|
5019 | - { |
|
5020 | - // var_dump($algo); |
|
5021 | - $newvalue = dol_hash($this->array_options[$key], $algo); |
|
5022 | - $new_array_options[$key] = $newvalue; |
|
5023 | - } |
|
5024 | - } |
|
5025 | - else |
|
5026 | - { |
|
5027 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
5028 | - } |
|
5029 | - } |
|
5030 | - } |
|
5031 | - else // Common usage |
|
5032 | - { |
|
5033 | - $new_array_options[$key] = $this->array_options[$key]; |
|
5034 | - } |
|
5035 | - break; |
|
5036 | - case 'price': |
|
5037 | - $new_array_options[$key] = price2num($this->array_options[$key]); |
|
5038 | - break; |
|
5039 | - case 'date': |
|
5040 | - $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
5041 | - break; |
|
5042 | - case 'datetime': |
|
5043 | - // If data is a string instead of a timestamp, we convert it |
|
5044 | - if (! is_int($this->array_options[$key])) { |
|
5045 | - $this->array_options[$key] = strtotime($this->array_options[$key]); |
|
5046 | - } |
|
5047 | - $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
5048 | - break; |
|
5049 | - case 'link': |
|
5050 | - $param_list=array_keys($attributeParam['options']); |
|
5051 | - // 0 : ObjectName |
|
5052 | - // 1 : classPath |
|
5053 | - $InfoFieldList = explode(":", $param_list[0]); |
|
5054 | - dol_include_once($InfoFieldList[1]); |
|
5055 | - if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) |
|
5056 | - { |
|
5057 | - if ($value == '-1') // -1 is key for no defined in combo list of objects |
|
5058 | - { |
|
5059 | - $new_array_options[$key]=''; |
|
5060 | - } |
|
5061 | - elseif ($value) |
|
5062 | - { |
|
5063 | - $object = new $InfoFieldList[0]($this->db); |
|
5064 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
5065 | - else $res=$object->fetch('',$value); |
|
5066 | - |
|
5067 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
5068 | - else |
|
5069 | - { |
|
5070 | - $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
5071 | - $this->db->rollback(); |
|
5072 | - return -1; |
|
5073 | - } |
|
5074 | - } |
|
5075 | - } |
|
5076 | - else |
|
5077 | - { |
|
5078 | - dol_syslog('Error bad setup of extrafield', LOG_WARNING); |
|
5079 | - } |
|
5080 | - break; |
|
5081 | - } |
|
5082 | - } |
|
1698 | + /** |
|
1699 | + * Return list of id of contacts of object |
|
1700 | + * |
|
1701 | + * @param string $source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe) |
|
1702 | + * @return array Array of id of contacts (if source=external or internal) |
|
1703 | + * Array of id of third parties with at least one contact on object (if source=thirdparty) |
|
1704 | + */ |
|
1705 | + function getListContactId($source='external') |
|
1706 | + { |
|
1707 | + $contactAlreadySelected = array(); |
|
1708 | + $tab = $this->liste_contact(-1,$source); |
|
1709 | + $num=count($tab); |
|
1710 | + $i = 0; |
|
1711 | + while ($i < $num) |
|
1712 | + { |
|
1713 | + if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
1714 | + else $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
1715 | + $i++; |
|
1716 | + } |
|
1717 | + return $contactAlreadySelected; |
|
1718 | + } |
|
5083 | 1719 | |
5084 | - $this->db->begin(); |
|
5085 | 1720 | |
5086 | - $table_element = $this->table_element; |
|
5087 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
1721 | + /** |
|
1722 | + * Link element with a project |
|
1723 | + * |
|
1724 | + * @param int $projectid Project id to link element to |
|
1725 | + * @return int <0 if KO, >0 if OK |
|
1726 | + */ |
|
1727 | + function setProject($projectid) |
|
1728 | + { |
|
1729 | + if (! $this->table_element) |
|
1730 | + { |
|
1731 | + dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
1732 | + return -1; |
|
1733 | + } |
|
5088 | 1734 | |
5089 | - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
5090 | - dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
|
5091 | - $this->db->query($sql_del); |
|
1735 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1736 | + if ($this->table_element == 'actioncomm') |
|
1737 | + { |
|
1738 | + if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
1739 | + else $sql.= ' SET fk_project = NULL'; |
|
1740 | + $sql.= ' WHERE id = '.$this->id; |
|
1741 | + } |
|
1742 | + else |
|
1743 | + { |
|
1744 | + if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
1745 | + else $sql.= ' SET fk_projet = NULL'; |
|
1746 | + $sql.= ' WHERE rowid = '.$this->id; |
|
1747 | + } |
|
5092 | 1748 | |
5093 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
|
5094 | - foreach($new_array_options as $key => $value) |
|
5095 | - { |
|
5096 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
5097 | - // Add field of attribut |
|
5098 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
|
5099 | - $sql.=",".$attributeKey; |
|
5100 | - } |
|
5101 | - $sql .= ") VALUES (".$this->id; |
|
5102 | - |
|
5103 | - foreach($new_array_options as $key => $value) |
|
5104 | - { |
|
5105 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
5106 | - // Add field of attribute |
|
5107 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
|
5108 | - { |
|
5109 | - if ($new_array_options[$key] != '') |
|
5110 | - { |
|
5111 | - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
5112 | - } |
|
5113 | - else |
|
5114 | - { |
|
5115 | - $sql.=",null"; |
|
5116 | - } |
|
5117 | - } |
|
5118 | - } |
|
5119 | - $sql.=")"; |
|
1749 | + dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
|
1750 | + if ($this->db->query($sql)) |
|
1751 | + { |
|
1752 | + $this->fk_project = $projectid; |
|
1753 | + return 1; |
|
1754 | + } |
|
1755 | + else |
|
1756 | + { |
|
1757 | + dol_print_error($this->db); |
|
1758 | + return -1; |
|
1759 | + } |
|
1760 | + } |
|
5120 | 1761 | |
5121 | - dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
|
5122 | - $resql = $this->db->query($sql); |
|
5123 | - if (! $resql) |
|
5124 | - { |
|
5125 | - $this->error=$this->db->lasterror(); |
|
5126 | - $error++; |
|
5127 | - } |
|
1762 | + /** |
|
1763 | + * Change the payments methods |
|
1764 | + * |
|
1765 | + * @param int $id Id of new payment method |
|
1766 | + * @return int >0 if OK, <0 if KO |
|
1767 | + */ |
|
1768 | + function setPaymentMethods($id) |
|
1769 | + { |
|
1770 | + dol_syslog(get_class($this).'::setPaymentMethods('.$id.')'); |
|
1771 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
1772 | + { |
|
1773 | + // TODO uniformize field name |
|
1774 | + $fieldname = 'fk_mode_reglement'; |
|
1775 | + if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
|
1776 | + if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
|
5128 | 1777 | |
5129 | - if (! $error && $trigger) |
|
5130 | - { |
|
5131 | - // Call trigger |
|
5132 | - $this->context=array('extrafieldaddupdate'=>1); |
|
5133 | - $result=$this->call_trigger($trigger, $userused); |
|
5134 | - if ($result < 0) $error++; |
|
5135 | - // End call trigger |
|
5136 | - } |
|
5137 | - |
|
5138 | - if ($error) |
|
5139 | - { |
|
5140 | - $this->db->rollback(); |
|
5141 | - return -1; |
|
5142 | - } |
|
5143 | - else |
|
5144 | - { |
|
5145 | - $this->db->commit(); |
|
5146 | - return 1; |
|
5147 | - } |
|
5148 | - } |
|
5149 | - else return 0; |
|
5150 | - } |
|
5151 | - |
|
5152 | - /** |
|
5153 | - * Update an extra field value for the current object. |
|
5154 | - * Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) |
|
5155 | - * |
|
5156 | - * @param string $key Key of the extrafield (without starting 'options_') |
|
5157 | - * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
5158 | - * @param User $userused Object user |
|
5159 | - * @return int -1=error, O=did nothing, 1=OK |
|
5160 | - * @see setValueFrom, insertExtraFields |
|
5161 | - */ |
|
5162 | - function updateExtraField($key, $trigger=null, $userused=null) |
|
5163 | - { |
|
5164 | - global $conf,$langs,$user; |
|
5165 | - |
|
5166 | - if (empty($userused)) $userused=$user; |
|
5167 | - |
|
5168 | - $error=0; |
|
5169 | - |
|
5170 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
5171 | - |
|
5172 | - if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
5173 | - { |
|
5174 | - // Check parameters |
|
5175 | - $langs->load('admin'); |
|
5176 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
5177 | - $extrafields = new ExtraFields($this->db); |
|
5178 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
5179 | - |
|
5180 | - $value=$this->array_options["options_".$key]; |
|
5181 | - |
|
5182 | - $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
|
5183 | - $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
|
5184 | - $attributeParam = $extrafields->attributes[$this->table_element]['param'][$key]; |
|
5185 | - $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$key]; |
|
5186 | - |
|
5187 | - //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); |
|
5188 | - //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); |
|
5189 | - |
|
5190 | - switch ($attributeType) |
|
5191 | - { |
|
5192 | - case 'int': |
|
5193 | - if (!is_numeric($value) && $value!='') |
|
5194 | - { |
|
5195 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); |
|
5196 | - return -1; |
|
5197 | - } |
|
5198 | - elseif ($value=='') |
|
5199 | - { |
|
5200 | - $this->array_options["options_".$key] = null; |
|
5201 | - } |
|
5202 | - break; |
|
5203 | - case 'double': |
|
5204 | - $value = price2num($value); |
|
5205 | - if (!is_numeric($value) && $value!='') |
|
5206 | - { |
|
5207 | - dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
|
5208 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
5209 | - return -1; |
|
5210 | - } |
|
5211 | - elseif ($value=='') |
|
5212 | - { |
|
5213 | - $this->array_options["options_".$key] = null; |
|
5214 | - } |
|
5215 | - //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG); |
|
5216 | - $this->array_options["options_".$key] = $value; |
|
5217 | - break; |
|
5218 | - /*case 'select': // Not required, we chosed value='0' for undefined values |
|
5219 | - if ($value=='-1') |
|
5220 | - { |
|
5221 | - $this->array_options[$key] = null; |
|
5222 | - } |
|
5223 | - break;*/ |
|
5224 | - case 'price': |
|
5225 | - $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
|
5226 | - break; |
|
5227 | - case 'date': |
|
5228 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
5229 | - break; |
|
5230 | - case 'datetime': |
|
5231 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
5232 | - break; |
|
5233 | - case 'link': |
|
5234 | - $param_list=array_keys($attributeParam['options']); |
|
5235 | - // 0 : ObjectName |
|
5236 | - // 1 : classPath |
|
5237 | - $InfoFieldList = explode(":", $param_list[0]); |
|
5238 | - dol_include_once($InfoFieldList[1]); |
|
5239 | - if ($value) |
|
5240 | - { |
|
5241 | - $object = new $InfoFieldList[0]($this->db); |
|
5242 | - $object->fetch(0,$value); |
|
5243 | - $this->array_options["options_".$key]=$object->id; |
|
5244 | - } |
|
5245 | - break; |
|
5246 | - } |
|
5247 | - |
|
5248 | - $this->db->begin(); |
|
5249 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
|
5250 | - $sql .= " WHERE fk_object = ".$this->id; |
|
5251 | - $resql = $this->db->query($sql); |
|
5252 | - if (! $resql) |
|
5253 | - { |
|
5254 | - $error++; |
|
5255 | - $this->error=$this->db->lasterror(); |
|
5256 | - } |
|
1778 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1779 | + $sql .= ' SET '.$fieldname.' = '.$id; |
|
1780 | + $sql .= ' WHERE rowid='.$this->id; |
|
5257 | 1781 | |
5258 | - if (! $error && $trigger) |
|
5259 | - { |
|
5260 | - // Call trigger |
|
5261 | - $this->context=array('extrafieldupdate'=>1); |
|
5262 | - $result=$this->call_trigger($trigger, $userused); |
|
5263 | - if ($result < 0) $error++; |
|
5264 | - // End call trigger |
|
5265 | - } |
|
5266 | - |
|
5267 | - if ($error) |
|
5268 | - { |
|
5269 | - dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
|
5270 | - $this->db->rollback(); |
|
5271 | - return -1; |
|
5272 | - } |
|
5273 | - else |
|
5274 | - { |
|
5275 | - $this->db->commit(); |
|
5276 | - return 1; |
|
5277 | - } |
|
5278 | - } |
|
5279 | - else return 0; |
|
5280 | - } |
|
5281 | - |
|
5282 | - |
|
5283 | - /** |
|
5284 | - * Return HTML string to put an input field into a page |
|
5285 | - * Code very similar with showInputField of extra fields |
|
5286 | - * |
|
5287 | - * @param array $val Array of properties for field to show |
|
5288 | - * @param string $key Key of attribute |
|
5289 | - * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) |
|
5290 | - * @param string $moreparam To add more parameters on html input tag |
|
5291 | - * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
5292 | - * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
5293 | - * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. |
|
5294 | - * @return string |
|
5295 | - */ |
|
5296 | - function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0) |
|
5297 | - { |
|
5298 | - global $conf,$langs,$form; |
|
5299 | - |
|
5300 | - if (! is_object($form)) |
|
5301 | - { |
|
5302 | - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
5303 | - $form=new Form($this->db); |
|
5304 | - } |
|
5305 | - |
|
5306 | - $val=$this->fields[$key]; |
|
5307 | - |
|
5308 | - $out=''; |
|
5309 | - $type=''; |
|
5310 | - $param = array(); |
|
5311 | - $param['options']=array(); |
|
5312 | - $size =$this->fields[$key]['size']; |
|
5313 | - // Because we work on extrafields |
|
5314 | - if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){ |
|
5315 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
5316 | - $type ='link'; |
|
5317 | - } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) { |
|
5318 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
5319 | - $type ='link'; |
|
5320 | - } elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) { |
|
5321 | - $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
5322 | - $type ='sellist'; |
|
5323 | - } elseif(preg_match('/varchar\((\d+)\)/', $val['type'],$reg)) { |
|
5324 | - $param['options']=array(); |
|
5325 | - $type ='varchar'; |
|
5326 | - $size=$reg[1]; |
|
5327 | - } elseif(preg_match('/varchar/', $val['type'])) { |
|
5328 | - $param['options']=array(); |
|
5329 | - $type ='varchar'; |
|
5330 | - } elseif(is_array($this->fields[$key]['arrayofkeyval'])) { |
|
5331 | - $param['options']=$this->fields[$key]['arrayofkeyval']; |
|
5332 | - $type ='select'; |
|
5333 | - } else { |
|
5334 | - $param['options']=array(); |
|
5335 | - $type =$this->fields[$key]['type']; |
|
1782 | + if ($this->db->query($sql)) |
|
1783 | + { |
|
1784 | + $this->mode_reglement_id = $id; |
|
1785 | + // for supplier |
|
1786 | + if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
|
1787 | + return 1; |
|
1788 | + } |
|
1789 | + else |
|
1790 | + { |
|
1791 | + dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
|
1792 | + $this->error=$this->db->error(); |
|
1793 | + return -1; |
|
1794 | + } |
|
1795 | + } |
|
1796 | + else |
|
1797 | + { |
|
1798 | + dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
|
1799 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
1800 | + return -2; |
|
5336 | 1801 | } |
1802 | + } |
|
5337 | 1803 | |
5338 | - $label=$this->fields[$key]['label']; |
|
5339 | - //$elementtype=$this->fields[$key]['elementtype']; // Seems not used |
|
5340 | - $default=$this->fields[$key]['default']; |
|
5341 | - $computed=$this->fields[$key]['computed']; |
|
5342 | - $unique=$this->fields[$key]['unique']; |
|
5343 | - $required=$this->fields[$key]['required']; |
|
1804 | + /** |
|
1805 | + * Change the multicurrency code |
|
1806 | + * |
|
1807 | + * @param string $code multicurrency code |
|
1808 | + * @return int >0 if OK, <0 if KO |
|
1809 | + */ |
|
1810 | + function setMulticurrencyCode($code) |
|
1811 | + { |
|
1812 | + dol_syslog(get_class($this).'::setMulticurrencyCode('.$id.')'); |
|
1813 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
1814 | + { |
|
1815 | + $fieldname = 'multicurrency_code'; |
|
5344 | 1816 | |
5345 | - $langfile=$this->fields[$key]['langfile']; |
|
5346 | - $list=$this->fields[$key]['list']; |
|
5347 | - $hidden=abs($this->fields[$key]['visible'])!=1?1:0; |
|
1817 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1818 | + $sql .= ' SET '.$fieldname." = '".$this->db->escape($code)."'"; |
|
1819 | + $sql .= ' WHERE rowid='.$this->id; |
|
5348 | 1820 | |
5349 | - $objectid = $this->id; |
|
1821 | + if ($this->db->query($sql)) |
|
1822 | + { |
|
1823 | + $this->multicurrency_code = $code; |
|
5350 | 1824 | |
1825 | + list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
|
1826 | + if ($rate) $this->setMulticurrencyRate($rate,2); |
|
5351 | 1827 | |
5352 | - if ($computed) |
|
5353 | - { |
|
5354 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
5355 | - else return ''; |
|
5356 | - } |
|
1828 | + return 1; |
|
1829 | + } |
|
1830 | + else |
|
1831 | + { |
|
1832 | + dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
|
1833 | + $this->error=$this->db->error(); |
|
1834 | + return -1; |
|
1835 | + } |
|
1836 | + } |
|
1837 | + else |
|
1838 | + { |
|
1839 | + dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
|
1840 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
1841 | + return -2; |
|
1842 | + } |
|
1843 | + } |
|
5357 | 1844 | |
1845 | + /** |
|
1846 | + * Change the multicurrency rate |
|
1847 | + * |
|
1848 | + * @param double $rate multicurrency rate |
|
1849 | + * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
|
1850 | + * @return int >0 if OK, <0 if KO |
|
1851 | + */ |
|
1852 | + function setMulticurrencyRate($rate, $mode=1) |
|
1853 | + { |
|
1854 | + dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')'); |
|
1855 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
1856 | + { |
|
1857 | + $fieldname = 'multicurrency_tx'; |
|
5358 | 1858 | |
5359 | - // Use in priority showsize from parameters, then $val['css'] then autodefine |
|
5360 | - if (empty($morecss) && ! empty($val['css'])) |
|
5361 | - { |
|
5362 | - $showsize = $val['css']; |
|
5363 | - } |
|
5364 | - if (empty($morecss)) |
|
5365 | - { |
|
5366 | - if ($type == 'date') |
|
5367 | - { |
|
5368 | - $morecss = 'minwidth100imp'; |
|
5369 | - } |
|
5370 | - elseif ($type == 'datetime') |
|
5371 | - { |
|
5372 | - $morecss = 'minwidth200imp'; |
|
5373 | - } |
|
5374 | - elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
5375 | - { |
|
5376 | - $morecss = 'maxwidth75'; |
|
5377 | - }elseif ($type == 'url') |
|
5378 | - { |
|
5379 | - $morecss='minwidth400'; |
|
5380 | - } |
|
5381 | - elseif ($type == 'boolean') |
|
5382 | - { |
|
5383 | - $morecss=''; |
|
5384 | - } |
|
5385 | - else |
|
5386 | - { |
|
5387 | - if (round($size) < 12) |
|
5388 | - { |
|
5389 | - $morecss = 'minwidth100'; |
|
5390 | - } |
|
5391 | - else if (round($size) <= 48) |
|
5392 | - { |
|
5393 | - $morecss = 'minwidth200'; |
|
5394 | - } |
|
5395 | - else |
|
5396 | - { |
|
5397 | - $morecss = 'minwidth400'; |
|
5398 | - } |
|
5399 | - } |
|
5400 | - } |
|
5401 | - |
|
5402 | - if (in_array($type,array('date','datetime'))) |
|
5403 | - { |
|
5404 | - $tmp=explode(',',$size); |
|
5405 | - $newsize=$tmp[0]; |
|
5406 | - |
|
5407 | - $showtime = in_array($type,array('datetime')) ? 1 : 0; |
|
5408 | - |
|
5409 | - // Do not show current date when field not required (see selectDate() method) |
|
5410 | - if (!$required && $value == '') $value = '-1'; |
|
5411 | - |
|
5412 | - // TODO Must also support $moreparam |
|
5413 | - $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
|
5414 | - } |
|
5415 | - elseif (in_array($type,array('int','integer'))) |
|
5416 | - { |
|
5417 | - $tmp=explode(',',$size); |
|
5418 | - $newsize=$tmp[0]; |
|
5419 | - $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:'').'>'; |
|
5420 | - } |
|
5421 | - elseif (preg_match('/varchar/', $type)) |
|
5422 | - { |
|
5423 | - $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 | - } |
|
5425 | - elseif (in_array($type, array('mail', 'phone', 'url'))) |
|
5426 | - { |
|
5427 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
5428 | - } |
|
5429 | - elseif ($type == 'text') |
|
5430 | - { |
|
5431 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
5432 | - { |
|
5433 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
5434 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
5435 | - $out=$doleditor->Create(1); |
|
5436 | - } |
|
5437 | - else |
|
5438 | - { |
|
5439 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
5440 | - } |
|
5441 | - } |
|
5442 | - elseif ($type == 'html') |
|
5443 | - { |
|
5444 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
5445 | - { |
|
5446 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
5447 | - $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%'); |
|
5448 | - $out=$doleditor->Create(1); |
|
5449 | - } |
|
5450 | - else |
|
5451 | - { |
|
5452 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
5453 | - } |
|
5454 | - } |
|
5455 | - elseif ($type == 'boolean') |
|
5456 | - { |
|
5457 | - $checked=''; |
|
5458 | - if (!empty($value)) { |
|
5459 | - $checked=' checked value="1" '; |
|
5460 | - } else { |
|
5461 | - $checked=' value="1" '; |
|
5462 | - } |
|
5463 | - $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
5464 | - } |
|
5465 | - elseif ($type == 'price') |
|
5466 | - { |
|
5467 | - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
|
5468 | - $value=price($value); |
|
5469 | - } |
|
5470 | - $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 | - } |
|
5472 | - elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
5473 | - { |
|
5474 | - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
|
5475 | - $value=price($value); |
|
5476 | - } |
|
5477 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
5478 | - } |
|
5479 | - elseif ($type == 'select') |
|
5480 | - { |
|
5481 | - $out = ''; |
|
5482 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
5483 | - { |
|
5484 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
5485 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
5486 | - } |
|
1859 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1860 | + $sql .= ' SET '.$fieldname.' = '.$rate; |
|
1861 | + $sql .= ' WHERE rowid='.$this->id; |
|
5487 | 1862 | |
5488 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
5489 | - if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
5490 | - foreach ($param['options'] as $key => $val) |
|
5491 | - { |
|
5492 | - if ((string) $key == '') continue; |
|
5493 | - list($val, $parent) = explode('|', $val); |
|
5494 | - $out.='<option value="'.$key.'"'; |
|
5495 | - $out.= (((string) $value == (string) $key)?' selected':''); |
|
5496 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
5497 | - $out.='>'.$val.'</option>'; |
|
5498 | - } |
|
5499 | - $out.='</select>'; |
|
5500 | - } |
|
5501 | - elseif ($type == 'sellist') |
|
5502 | - { |
|
5503 | - $out = ''; |
|
5504 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
5505 | - { |
|
5506 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
5507 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
5508 | - } |
|
1863 | + if ($this->db->query($sql)) |
|
1864 | + { |
|
1865 | + $this->multicurrency_tx = $rate; |
|
1866 | + |
|
1867 | + // Update line price |
|
1868 | + if (!empty($this->lines)) |
|
1869 | + { |
|
1870 | + foreach ($this->lines as &$line) |
|
1871 | + { |
|
1872 | + if($mode == 1) { |
|
1873 | + $line->subprice = 0; |
|
1874 | + } |
|
1875 | + |
|
1876 | + switch ($this->element) { |
|
1877 | + case 'propal': |
|
1878 | + $this->updateline( |
|
1879 | + $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
1880 | + ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
1881 | + $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, |
|
1882 | + $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
1883 | + ); |
|
1884 | + break; |
|
1885 | + case 'commande': |
|
1886 | + $this->updateline( |
|
1887 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1888 | + $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, |
|
1889 | + $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
1890 | + $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
1891 | + ); |
|
1892 | + break; |
|
1893 | + case 'facture': |
|
1894 | + $this->updateline( |
|
1895 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1896 | + $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, |
|
1897 | + $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
1898 | + $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice |
|
1899 | + ); |
|
1900 | + break; |
|
1901 | + case 'supplier_proposal': |
|
1902 | + $this->updateline( |
|
1903 | + $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
1904 | + ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
1905 | + $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, |
|
1906 | + $line->ref_fourn, $line->multicurrency_subprice |
|
1907 | + ); |
|
1908 | + break; |
|
1909 | + case 'order_supplier': |
|
1910 | + $this->updateline( |
|
1911 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1912 | + $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, |
|
1913 | + $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
1914 | + ); |
|
1915 | + break; |
|
1916 | + case 'invoice_supplier': |
|
1917 | + $this->updateline( |
|
1918 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
1919 | + $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, |
|
1920 | + $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
1921 | + ); |
|
1922 | + break; |
|
1923 | + default: |
|
1924 | + dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); |
|
1925 | + break; |
|
1926 | + } |
|
1927 | + } |
|
1928 | + } |
|
1929 | + |
|
1930 | + return 1; |
|
1931 | + } |
|
1932 | + else |
|
1933 | + { |
|
1934 | + dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
|
1935 | + $this->error=$this->db->error(); |
|
1936 | + return -1; |
|
1937 | + } |
|
1938 | + } |
|
1939 | + else |
|
1940 | + { |
|
1941 | + dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
|
1942 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
1943 | + return -2; |
|
1944 | + } |
|
1945 | + } |
|
5509 | 1946 | |
5510 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
5511 | - if (is_array($param['options'])) |
|
5512 | - { |
|
5513 | - $param_list=array_keys($param['options']); |
|
5514 | - $InfoFieldList = explode(":", $param_list[0]); |
|
5515 | - $parentName=''; |
|
5516 | - $parentField=''; |
|
5517 | - // 0 : tableName |
|
5518 | - // 1 : label field name |
|
5519 | - // 2 : key fields name (if differ of rowid) |
|
5520 | - // 3 : key field parent (for dependent lists) |
|
5521 | - // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
5522 | - $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
5523 | - |
|
5524 | - |
|
5525 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
5526 | - { |
|
5527 | - if (strpos($InfoFieldList[4], 'extra.') !== false) |
|
5528 | - { |
|
5529 | - $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
5530 | - } else { |
|
5531 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
5532 | - } |
|
5533 | - } |
|
5534 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
5535 | - { |
|
5536 | - list($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
|
5537 | - $keyList.= ', '.$parentField; |
|
5538 | - } |
|
1947 | + /** |
|
1948 | + * Change the payments terms |
|
1949 | + * |
|
1950 | + * @param int $id Id of new payment terms |
|
1951 | + * @return int >0 if OK, <0 if KO |
|
1952 | + */ |
|
1953 | + function setPaymentTerms($id) |
|
1954 | + { |
|
1955 | + dol_syslog(get_class($this).'::setPaymentTerms('.$id.')'); |
|
1956 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
1957 | + { |
|
1958 | + // TODO uniformize field name |
|
1959 | + $fieldname = 'fk_cond_reglement'; |
|
1960 | + if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
|
1961 | + if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
|
5539 | 1962 | |
5540 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
5541 | - if (is_array($fields_label)) |
|
5542 | - { |
|
5543 | - $keyList .=', '; |
|
5544 | - $keyList .= implode(', ', $fields_label); |
|
5545 | - } |
|
1963 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
1964 | + $sql .= ' SET '.$fieldname.' = '.$id; |
|
1965 | + $sql .= ' WHERE rowid='.$this->id; |
|
5546 | 1966 | |
5547 | - $sqlwhere=''; |
|
5548 | - $sql = 'SELECT '.$keyList; |
|
5549 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
5550 | - if (!empty($InfoFieldList[4])) |
|
5551 | - { |
|
5552 | - // can use SELECT request |
|
5553 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
5554 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
5555 | - } |
|
5556 | - |
|
5557 | - // current object id can be use into filter |
|
5558 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
5559 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
5560 | - } else { |
|
5561 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
5562 | - } |
|
5563 | - //We have to join on extrafield table |
|
5564 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
5565 | - { |
|
5566 | - $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
5567 | - $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
5568 | - } |
|
5569 | - else |
|
5570 | - { |
|
5571 | - $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
5572 | - } |
|
5573 | - } |
|
5574 | - else |
|
5575 | - { |
|
5576 | - $sqlwhere.= ' WHERE 1=1'; |
|
5577 | - } |
|
5578 | - // Some tables may have field, some other not. For the moment we disable it. |
|
5579 | - if (in_array($InfoFieldList[0],array('tablewithentity'))) |
|
5580 | - { |
|
5581 | - $sqlwhere.= ' AND entity = '.$conf->entity; |
|
5582 | - } |
|
5583 | - $sql.=$sqlwhere; |
|
5584 | - //print $sql; |
|
1967 | + if ($this->db->query($sql)) |
|
1968 | + { |
|
1969 | + $this->cond_reglement_id = $id; |
|
1970 | + // for supplier |
|
1971 | + if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
|
1972 | + $this->cond_reglement = $id; // for compatibility |
|
1973 | + return 1; |
|
1974 | + } |
|
1975 | + else |
|
1976 | + { |
|
1977 | + dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
|
1978 | + $this->error=$this->db->error(); |
|
1979 | + return -1; |
|
1980 | + } |
|
1981 | + } |
|
1982 | + else |
|
1983 | + { |
|
1984 | + dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
|
1985 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
1986 | + return -2; |
|
1987 | + } |
|
1988 | + } |
|
5585 | 1989 | |
5586 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label); |
|
1990 | + /** |
|
1991 | + * Define delivery address |
|
1992 | + * @deprecated |
|
1993 | + * |
|
1994 | + * @param int $id Address id |
|
1995 | + * @return int <0 si ko, >0 si ok |
|
1996 | + */ |
|
1997 | + function setDeliveryAddress($id) |
|
1998 | + { |
|
1999 | + $fieldname = 'fk_delivery_address'; |
|
2000 | + if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
|
5587 | 2001 | |
5588 | - dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
|
5589 | - $resql = $this->db->query($sql); |
|
5590 | - if ($resql) |
|
5591 | - { |
|
5592 | - $out.='<option value="0"> </option>'; |
|
5593 | - $num = $this->db->num_rows($resql); |
|
5594 | - $i = 0; |
|
5595 | - while ($i < $num) |
|
5596 | - { |
|
5597 | - $labeltoshow=''; |
|
5598 | - $obj = $this->db->fetch_object($resql); |
|
5599 | - |
|
5600 | - // Several field into label (eq table:code|libelle:rowid) |
|
5601 | - $notrans = false; |
|
5602 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
5603 | - if (is_array($fields_label)) |
|
5604 | - { |
|
5605 | - $notrans = true; |
|
5606 | - foreach ($fields_label as $field_toshow) |
|
5607 | - { |
|
5608 | - $labeltoshow.= $obj->$field_toshow.' '; |
|
5609 | - } |
|
5610 | - } |
|
5611 | - else |
|
5612 | - { |
|
5613 | - $labeltoshow=$obj->{$InfoFieldList[1]}; |
|
5614 | - } |
|
5615 | - $labeltoshow=dol_trunc($labeltoshow,45); |
|
5616 | - |
|
5617 | - if ($value == $obj->rowid) |
|
5618 | - { |
|
5619 | - foreach ($fields_label as $field_toshow) |
|
5620 | - { |
|
5621 | - $translabel=$langs->trans($obj->$field_toshow); |
|
5622 | - if ($translabel!=$obj->$field_toshow) { |
|
5623 | - $labeltoshow=dol_trunc($translabel,18).' '; |
|
5624 | - }else { |
|
5625 | - $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
5626 | - } |
|
5627 | - } |
|
5628 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
5629 | - } |
|
5630 | - else |
|
5631 | - { |
|
5632 | - if (! $notrans) |
|
5633 | - { |
|
5634 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
5635 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
5636 | - $labeltoshow=dol_trunc($translabel,18); |
|
5637 | - } |
|
5638 | - else { |
|
5639 | - $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18); |
|
5640 | - } |
|
5641 | - } |
|
5642 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
5643 | - if ($value==$obj->rowid) |
|
5644 | - { |
|
5645 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
5646 | - } |
|
2002 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
|
2003 | + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
5647 | 2004 | |
5648 | - if (!empty($InfoFieldList[3]) && $parentField) |
|
5649 | - { |
|
5650 | - $parent = $parentName.':'.$obj->{$parentField}; |
|
5651 | - } |
|
2005 | + if ($this->db->query($sql)) |
|
2006 | + { |
|
2007 | + $this->fk_delivery_address = $id; |
|
2008 | + return 1; |
|
2009 | + } |
|
2010 | + else |
|
2011 | + { |
|
2012 | + $this->error=$this->db->error(); |
|
2013 | + dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
|
2014 | + return -1; |
|
2015 | + } |
|
2016 | + } |
|
5652 | 2017 | |
5653 | - $out.='<option value="'.$obj->rowid.'"'; |
|
5654 | - $out.= ($value==$obj->rowid?' selected':''); |
|
5655 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
5656 | - $out.='>'.$labeltoshow.'</option>'; |
|
5657 | - } |
|
5658 | 2018 | |
5659 | - $i++; |
|
5660 | - } |
|
5661 | - $this->db->free($resql); |
|
5662 | - } |
|
5663 | - else { |
|
5664 | - print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
5665 | - } |
|
5666 | - } |
|
5667 | - $out.='</select>'; |
|
5668 | - } |
|
5669 | - elseif ($type == 'checkbox') |
|
5670 | - { |
|
5671 | - $value_arr=explode(',',$value); |
|
5672 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
5673 | - } |
|
5674 | - elseif ($type == 'radio') |
|
5675 | - { |
|
5676 | - $out=''; |
|
5677 | - foreach ($param['options'] as $keyopt => $val) |
|
5678 | - { |
|
5679 | - $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
5680 | - $out.=' value="'.$keyopt.'"'; |
|
5681 | - $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
5682 | - $out.= ($value==$keyopt?'checked':''); |
|
5683 | - $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
5684 | - } |
|
5685 | - } |
|
5686 | - elseif ($type == 'chkbxlst') |
|
5687 | - { |
|
5688 | - if (is_array($value)) { |
|
5689 | - $value_arr = $value; |
|
5690 | - } |
|
5691 | - else { |
|
5692 | - $value_arr = explode(',', $value); |
|
5693 | - } |
|
5694 | - |
|
5695 | - if (is_array($param['options'])) { |
|
5696 | - $param_list = array_keys($param['options']); |
|
5697 | - $InfoFieldList = explode(":", $param_list[0]); |
|
5698 | - $parentName=''; |
|
5699 | - $parentField=''; |
|
5700 | - // 0 : tableName |
|
5701 | - // 1 : label field name |
|
5702 | - // 2 : key fields name (if differ of rowid) |
|
5703 | - // 3 : key field parent (for dependent lists) |
|
5704 | - // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
5705 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
5706 | - |
|
5707 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) { |
|
5708 | - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]); |
|
5709 | - $keyList .= ', ' . $parentField; |
|
5710 | - } |
|
5711 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) { |
|
5712 | - if (strpos($InfoFieldList[4], 'extra.') !== false) { |
|
5713 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
5714 | - } else { |
|
5715 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
5716 | - } |
|
5717 | - } |
|
2019 | + /** |
|
2020 | + * Change the shipping method |
|
2021 | + * |
|
2022 | + * @param int $shipping_method_id Id of shipping method |
|
2023 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
2024 | + * @param User $userused Object user |
|
2025 | + * |
|
2026 | + * @return int 1 if OK, 0 if KO |
|
2027 | + */ |
|
2028 | + function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
2029 | + { |
|
2030 | + global $user; |
|
5718 | 2031 | |
5719 | - $fields_label = explode('|', $InfoFieldList[1]); |
|
5720 | - if (is_array($fields_label)) { |
|
5721 | - $keyList .= ', '; |
|
5722 | - $keyList .= implode(', ', $fields_label); |
|
5723 | - } |
|
2032 | + if (empty($userused)) $userused=$user; |
|
5724 | 2033 | |
5725 | - $sqlwhere = ''; |
|
5726 | - $sql = 'SELECT ' . $keyList; |
|
5727 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
5728 | - if (! empty($InfoFieldList[4])) { |
|
5729 | - |
|
5730 | - // can use SELECT request |
|
5731 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
5732 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
5733 | - } |
|
5734 | - |
|
5735 | - // current object id can be use into filter |
|
5736 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
5737 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
5738 | - } else { |
|
5739 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
5740 | - } |
|
5741 | - |
|
5742 | - // We have to join on extrafield table |
|
5743 | - if (strpos($InfoFieldList[4], 'extra') !== false) { |
|
5744 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
5745 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
5746 | - } else { |
|
5747 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
5748 | - } |
|
5749 | - } else { |
|
5750 | - $sqlwhere .= ' WHERE 1=1'; |
|
5751 | - } |
|
5752 | - // Some tables may have field, some other not. For the moment we disable it. |
|
5753 | - if (in_array($InfoFieldList[0], array ('tablewithentity'))) |
|
5754 | - { |
|
5755 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
5756 | - } |
|
5757 | - // $sql.=preg_replace('/^ AND /','',$sqlwhere); |
|
5758 | - // print $sql; |
|
5759 | - |
|
5760 | - $sql .= $sqlwhere; |
|
5761 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
5762 | - $resql = $this->db->query($sql); |
|
5763 | - if ($resql) { |
|
5764 | - $num = $this->db->num_rows($resql); |
|
5765 | - $i = 0; |
|
5766 | - |
|
5767 | - $data=array(); |
|
5768 | - |
|
5769 | - while ( $i < $num ) { |
|
5770 | - $labeltoshow = ''; |
|
5771 | - $obj = $this->db->fetch_object($resql); |
|
5772 | - |
|
5773 | - $notrans = false; |
|
5774 | - // Several field into label (eq table:code|libelle:rowid) |
|
5775 | - $fields_label = explode('|', $InfoFieldList[1]); |
|
5776 | - if (is_array($fields_label)) { |
|
5777 | - $notrans = true; |
|
5778 | - foreach ( $fields_label as $field_toshow ) { |
|
5779 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
5780 | - } |
|
5781 | - } else { |
|
5782 | - $labeltoshow = $obj->{$InfoFieldList[1]}; |
|
5783 | - } |
|
5784 | - $labeltoshow = dol_trunc($labeltoshow, 45); |
|
5785 | - |
|
5786 | - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
|
5787 | - foreach ( $fields_label as $field_toshow ) { |
|
5788 | - $translabel = $langs->trans($obj->$field_toshow); |
|
5789 | - if ($translabel != $obj->$field_toshow) { |
|
5790 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
5791 | - } else { |
|
5792 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
5793 | - } |
|
5794 | - } |
|
2034 | + $error = 0; |
|
5795 | 2035 | |
5796 | - $data[$obj->rowid]=$labeltoshow; |
|
5797 | - } else { |
|
5798 | - if (! $notrans) { |
|
5799 | - $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
5800 | - if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
5801 | - $labeltoshow = dol_trunc($translabel, 18); |
|
5802 | - } else { |
|
5803 | - $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18); |
|
5804 | - } |
|
5805 | - } |
|
5806 | - if (empty($labeltoshow)) |
|
5807 | - $labeltoshow = '(not defined)'; |
|
2036 | + if (! $this->table_element) { |
|
2037 | + dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
2038 | + return -1; |
|
2039 | + } |
|
5808 | 2040 | |
5809 | - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
|
5810 | - $data[$obj->rowid]=$labeltoshow; |
|
5811 | - } |
|
2041 | + $this->db->begin(); |
|
5812 | 2042 | |
5813 | - if (! empty($InfoFieldList[3]) && $parentField) { |
|
5814 | - $parent = $parentName . ':' . $obj->{$parentField}; |
|
5815 | - } |
|
2043 | + if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
2044 | + dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); |
|
5816 | 2045 | |
5817 | - $data[$obj->rowid]=$labeltoshow; |
|
5818 | - } |
|
2046 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2047 | + $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
2048 | + $sql.= " WHERE rowid=".$this->id; |
|
2049 | + $resql = $this->db->query($sql); |
|
2050 | + if (! $resql) { |
|
2051 | + dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
|
2052 | + $this->error = $this->db->lasterror(); |
|
2053 | + $error++; |
|
2054 | + } else { |
|
2055 | + if (!$notrigger) |
|
2056 | + { |
|
2057 | + // Call trigger |
|
2058 | + $this->context=array('shippingmethodupdate'=>1); |
|
2059 | + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
2060 | + if ($result < 0) $error++; |
|
2061 | + // End call trigger |
|
2062 | + } |
|
2063 | + } |
|
2064 | + if ($error) |
|
2065 | + { |
|
2066 | + $this->db->rollback(); |
|
2067 | + return -1; |
|
2068 | + } else { |
|
2069 | + $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
2070 | + $this->db->commit(); |
|
2071 | + return 1; |
|
2072 | + } |
|
2073 | + } |
|
2074 | + |
|
2075 | + |
|
2076 | + /** |
|
2077 | + * Change the warehouse |
|
2078 | + * |
|
2079 | + * @param int $warehouse_id Id of warehouse |
|
2080 | + * @return int 1 if OK, 0 if KO |
|
2081 | + */ |
|
2082 | + function setWarehouse($warehouse_id) |
|
2083 | + { |
|
2084 | + if (! $this->table_element) { |
|
2085 | + dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
2086 | + return -1; |
|
2087 | + } |
|
2088 | + if ($warehouse_id<0) $warehouse_id='NULL'; |
|
2089 | + dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); |
|
2090 | + |
|
2091 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2092 | + $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
2093 | + $sql.= " WHERE rowid=".$this->id; |
|
2094 | + |
|
2095 | + if ($this->db->query($sql)) { |
|
2096 | + $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
2097 | + return 1; |
|
2098 | + } else { |
|
2099 | + dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
|
2100 | + $this->error=$this->db->error(); |
|
2101 | + return 0; |
|
2102 | + } |
|
2103 | + } |
|
2104 | + |
|
2105 | + |
|
2106 | + /** |
|
2107 | + * Set last model used by doc generator |
|
2108 | + * |
|
2109 | + * @param User $user User object that make change |
|
2110 | + * @param string $modelpdf Modele name |
|
2111 | + * @return int <0 if KO, >0 if OK |
|
2112 | + */ |
|
2113 | + function setDocModel($user, $modelpdf) |
|
2114 | + { |
|
2115 | + if (! $this->table_element) |
|
2116 | + { |
|
2117 | + dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
2118 | + return -1; |
|
2119 | + } |
|
2120 | + |
|
2121 | + $newmodelpdf=dol_trunc($modelpdf,255); |
|
2122 | + |
|
2123 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2124 | + $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
2125 | + $sql.= " WHERE rowid = ".$this->id; |
|
2126 | + // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
|
2127 | + // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
|
2128 | + |
|
2129 | + dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
|
2130 | + $resql=$this->db->query($sql); |
|
2131 | + if ($resql) |
|
2132 | + { |
|
2133 | + $this->modelpdf=$modelpdf; |
|
2134 | + return 1; |
|
2135 | + } |
|
2136 | + else |
|
2137 | + { |
|
2138 | + dol_print_error($this->db); |
|
2139 | + return 0; |
|
2140 | + } |
|
2141 | + } |
|
2142 | + |
|
2143 | + |
|
2144 | + /** |
|
2145 | + * Change the bank account |
|
2146 | + * |
|
2147 | + * @param int $fk_account Id of bank account |
|
2148 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
2149 | + * @param User $userused Object user |
|
2150 | + * @return int 1 if OK, 0 if KO |
|
2151 | + */ |
|
2152 | + function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
2153 | + { |
|
2154 | + global $user; |
|
2155 | + |
|
2156 | + if (empty($userused)) $userused=$user; |
|
2157 | + |
|
2158 | + $error = 0; |
|
2159 | + |
|
2160 | + if (! $this->table_element) { |
|
2161 | + dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
2162 | + return -1; |
|
2163 | + } |
|
2164 | + $this->db->begin(); |
|
2165 | + |
|
2166 | + if ($fk_account<0) $fk_account='NULL'; |
|
2167 | + dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); |
|
2168 | + |
|
2169 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
2170 | + $sql.= " SET fk_account = ".$fk_account; |
|
2171 | + $sql.= " WHERE rowid=".$this->id; |
|
2172 | + |
|
2173 | + $resql = $this->db->query($sql); |
|
2174 | + if (! $resql) |
|
2175 | + { |
|
2176 | + dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
|
2177 | + $this->error = $this->db->lasterror(); |
|
2178 | + $error++; |
|
2179 | + } |
|
2180 | + else |
|
2181 | + { |
|
2182 | + if (!$notrigger) |
|
2183 | + { |
|
2184 | + // Call trigger |
|
2185 | + $this->context=array('bankaccountupdate'=>1); |
|
2186 | + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
2187 | + if ($result < 0) $error++; |
|
2188 | + // End call trigger |
|
2189 | + } |
|
2190 | + } |
|
2191 | + if ($error) |
|
2192 | + { |
|
2193 | + $this->db->rollback(); |
|
2194 | + return -1; |
|
2195 | + } |
|
2196 | + else |
|
2197 | + { |
|
2198 | + $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
2199 | + $this->db->commit(); |
|
2200 | + return 1; |
|
2201 | + } |
|
2202 | + } |
|
2203 | + |
|
2204 | + |
|
2205 | + // TODO: Move line related operations to CommonObjectLine? |
|
2206 | + |
|
2207 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2208 | + /** |
|
2209 | + * Save a new position (field rang) for details lines. |
|
2210 | + * You can choose to set position for lines with already a position or lines without any position defined. |
|
2211 | + * |
|
2212 | + * @param boolean $renum True to renum all already ordered lines, false to renum only not already ordered lines. |
|
2213 | + * @param string $rowidorder ASC or DESC |
|
2214 | + * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
2215 | + * @return int <0 if KO, >0 if OK |
|
2216 | + */ |
|
2217 | + function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
2218 | + { |
|
2219 | + // phpcs:enable |
|
2220 | + if (! $this->table_element_line) |
|
2221 | + { |
|
2222 | + dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
2223 | + return -1; |
|
2224 | + } |
|
2225 | + if (! $this->fk_element) |
|
2226 | + { |
|
2227 | + dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
2228 | + return -1; |
|
2229 | + } |
|
2230 | + |
|
2231 | + // Count number of lines to reorder (according to choice $renum) |
|
2232 | + $nl=0; |
|
2233 | + $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2234 | + $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
2235 | + if (! $renum) $sql.= ' AND rang = 0'; |
|
2236 | + if ($renum) $sql.= ' AND rang <> 0'; |
|
2237 | + |
|
2238 | + dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
|
2239 | + $resql = $this->db->query($sql); |
|
2240 | + if ($resql) |
|
2241 | + { |
|
2242 | + $row = $this->db->fetch_row($resql); |
|
2243 | + $nl = $row[0]; |
|
2244 | + } |
|
2245 | + else dol_print_error($this->db); |
|
2246 | + if ($nl > 0) |
|
2247 | + { |
|
2248 | + // The goal of this part is to reorder all lines, with all children lines sharing the same |
|
2249 | + // counter that parents. |
|
2250 | + $rows=array(); |
|
2251 | + |
|
2252 | + // We first search all lines that are parent lines (for multilevel details lines) |
|
2253 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2254 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2255 | + if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
2256 | + $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
2257 | + |
|
2258 | + dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
|
2259 | + $resql = $this->db->query($sql); |
|
2260 | + if ($resql) |
|
2261 | + { |
|
2262 | + $i=0; |
|
2263 | + $num = $this->db->num_rows($resql); |
|
2264 | + while ($i < $num) |
|
2265 | + { |
|
2266 | + $row = $this->db->fetch_row($resql); |
|
2267 | + $rows[] = $row[0]; // Add parent line into array rows |
|
2268 | + $childrens = $this->getChildrenOfLine($row[0]); |
|
2269 | + if (! empty($childrens)) |
|
2270 | + { |
|
2271 | + foreach($childrens as $child) |
|
2272 | + { |
|
2273 | + array_push($rows, $child); |
|
2274 | + } |
|
2275 | + } |
|
2276 | + $i++; |
|
2277 | + } |
|
2278 | + |
|
2279 | + // Now we set a new number for each lines (parent and children with children included into parent tree) |
|
2280 | + if (! empty($rows)) |
|
2281 | + { |
|
2282 | + foreach($rows as $key => $row) |
|
2283 | + { |
|
2284 | + $this->updateRangOfLine($row, ($key+1)); |
|
2285 | + } |
|
2286 | + } |
|
2287 | + } |
|
2288 | + else |
|
2289 | + { |
|
2290 | + dol_print_error($this->db); |
|
2291 | + } |
|
2292 | + } |
|
2293 | + return 1; |
|
2294 | + } |
|
2295 | + |
|
2296 | + /** |
|
2297 | + * Get children of line |
|
2298 | + * |
|
2299 | + * @param int $id Id of parent line |
|
2300 | + * @return array Array with list of children lines id |
|
2301 | + */ |
|
2302 | + function getChildrenOfLine($id) |
|
2303 | + { |
|
2304 | + $rows=array(); |
|
2305 | + |
|
2306 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2307 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2308 | + $sql.= ' AND fk_parent_line = '.$id; |
|
2309 | + $sql.= ' ORDER BY rang ASC'; |
|
2310 | + |
|
2311 | + dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
|
2312 | + $resql = $this->db->query($sql); |
|
2313 | + if ($resql) |
|
2314 | + { |
|
2315 | + $i=0; |
|
2316 | + $num = $this->db->num_rows($resql); |
|
2317 | + while ($i < $num) |
|
2318 | + { |
|
2319 | + $row = $this->db->fetch_row($resql); |
|
2320 | + $rows[$i] = $row[0]; |
|
2321 | + $i++; |
|
2322 | + } |
|
2323 | + } |
|
2324 | + |
|
2325 | + return $rows; |
|
2326 | + } |
|
2327 | + |
|
2328 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2329 | + /** |
|
2330 | + * Update a line to have a lower rank |
|
2331 | + * |
|
2332 | + * @param int $rowid Id of line |
|
2333 | + * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
2334 | + * @return void |
|
2335 | + */ |
|
2336 | + function line_up($rowid, $fk_parent_line=true) |
|
2337 | + { |
|
2338 | + // phpcs:enable |
|
2339 | + $this->line_order(false, 'ASC', $fk_parent_line); |
|
2340 | + |
|
2341 | + // Get rang of line |
|
2342 | + $rang = $this->getRangOfLine($rowid); |
|
2343 | + |
|
2344 | + // Update position of line |
|
2345 | + $this->updateLineUp($rowid, $rang); |
|
2346 | + } |
|
2347 | + |
|
2348 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2349 | + /** |
|
2350 | + * Update a line to have a higher rank |
|
2351 | + * |
|
2352 | + * @param int $rowid Id of line |
|
2353 | + * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
2354 | + * @return void |
|
2355 | + */ |
|
2356 | + function line_down($rowid, $fk_parent_line=true) |
|
2357 | + { |
|
2358 | + // phpcs:enable |
|
2359 | + $this->line_order(false, 'ASC', $fk_parent_line); |
|
2360 | + |
|
2361 | + // Get rang of line |
|
2362 | + $rang = $this->getRangOfLine($rowid); |
|
2363 | + |
|
2364 | + // Get max value for rang |
|
2365 | + $max = $this->line_max(); |
|
2366 | + |
|
2367 | + // Update position of line |
|
2368 | + $this->updateLineDown($rowid, $rang, $max); |
|
2369 | + } |
|
2370 | + |
|
2371 | + /** |
|
2372 | + * Update position of line (rang) |
|
2373 | + * |
|
2374 | + * @param int $rowid Id of line |
|
2375 | + * @param int $rang Position |
|
2376 | + * @return void |
|
2377 | + */ |
|
2378 | + function updateRangOfLine($rowid,$rang) |
|
2379 | + { |
|
2380 | + $fieldposition = 'rang'; |
|
2381 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
|
2382 | + |
|
2383 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
2384 | + $sql.= ' WHERE rowid = '.$rowid; |
|
2385 | + |
|
2386 | + dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
|
2387 | + if (! $this->db->query($sql)) |
|
2388 | + { |
|
2389 | + dol_print_error($this->db); |
|
2390 | + } |
|
2391 | + } |
|
2392 | + |
|
2393 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2394 | + /** |
|
2395 | + * Update position of line with ajax (rang) |
|
2396 | + * |
|
2397 | + * @param array $rows Array of rows |
|
2398 | + * @return void |
|
2399 | + */ |
|
2400 | + function line_ajaxorder($rows) |
|
2401 | + { |
|
2402 | + // phpcs:enable |
|
2403 | + $num = count($rows); |
|
2404 | + for ($i = 0 ; $i < $num ; $i++) |
|
2405 | + { |
|
2406 | + $this->updateRangOfLine($rows[$i], ($i+1)); |
|
2407 | + } |
|
2408 | + } |
|
2409 | + |
|
2410 | + /** |
|
2411 | + * Update position of line up (rang) |
|
2412 | + * |
|
2413 | + * @param int $rowid Id of line |
|
2414 | + * @param int $rang Position |
|
2415 | + * @return void |
|
2416 | + */ |
|
2417 | + function updateLineUp($rowid,$rang) |
|
2418 | + { |
|
2419 | + if ($rang > 1) |
|
2420 | + { |
|
2421 | + $fieldposition = 'rang'; |
|
2422 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
|
2423 | + |
|
2424 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
|
2425 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2426 | + $sql.= ' AND rang = '.($rang - 1); |
|
2427 | + if ($this->db->query($sql) ) |
|
2428 | + { |
|
2429 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
|
2430 | + $sql.= ' WHERE rowid = '.$rowid; |
|
2431 | + if (! $this->db->query($sql) ) |
|
2432 | + { |
|
2433 | + dol_print_error($this->db); |
|
2434 | + } |
|
2435 | + } |
|
2436 | + else |
|
2437 | + { |
|
2438 | + dol_print_error($this->db); |
|
2439 | + } |
|
2440 | + } |
|
2441 | + } |
|
2442 | + |
|
2443 | + /** |
|
2444 | + * Update position of line down (rang) |
|
2445 | + * |
|
2446 | + * @param int $rowid Id of line |
|
2447 | + * @param int $rang Position |
|
2448 | + * @param int $max Max |
|
2449 | + * @return void |
|
2450 | + */ |
|
2451 | + function updateLineDown($rowid,$rang,$max) |
|
2452 | + { |
|
2453 | + if ($rang < $max) |
|
2454 | + { |
|
2455 | + $fieldposition = 'rang'; |
|
2456 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
|
2457 | + |
|
2458 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
2459 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2460 | + $sql.= ' AND rang = '.($rang+1); |
|
2461 | + if ($this->db->query($sql) ) |
|
2462 | + { |
|
2463 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang+1); |
|
2464 | + $sql.= ' WHERE rowid = '.$rowid; |
|
2465 | + if (! $this->db->query($sql) ) |
|
2466 | + { |
|
2467 | + dol_print_error($this->db); |
|
2468 | + } |
|
2469 | + } |
|
2470 | + else |
|
2471 | + { |
|
2472 | + dol_print_error($this->db); |
|
2473 | + } |
|
2474 | + } |
|
2475 | + } |
|
2476 | + |
|
2477 | + /** |
|
2478 | + * Get position of line (rang) |
|
2479 | + * |
|
2480 | + * @param int $rowid Id of line |
|
2481 | + * @return int Value of rang in table of lines |
|
2482 | + */ |
|
2483 | + function getRangOfLine($rowid) |
|
2484 | + { |
|
2485 | + $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2486 | + $sql.= ' WHERE rowid ='.$rowid; |
|
2487 | + |
|
2488 | + dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
|
2489 | + $resql = $this->db->query($sql); |
|
2490 | + if ($resql) |
|
2491 | + { |
|
2492 | + $row = $this->db->fetch_row($resql); |
|
2493 | + return $row[0]; |
|
2494 | + } |
|
2495 | + } |
|
2496 | + |
|
2497 | + /** |
|
2498 | + * Get rowid of the line relative to its position |
|
2499 | + * |
|
2500 | + * @param int $rang Rang value |
|
2501 | + * @return int Rowid of the line |
|
2502 | + */ |
|
2503 | + function getIdOfLine($rang) |
|
2504 | + { |
|
2505 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2506 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2507 | + $sql.= ' AND rang = '.$rang; |
|
2508 | + $resql = $this->db->query($sql); |
|
2509 | + if ($resql) |
|
2510 | + { |
|
2511 | + $row = $this->db->fetch_row($resql); |
|
2512 | + return $row[0]; |
|
2513 | + } |
|
2514 | + } |
|
2515 | + |
|
2516 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2517 | + /** |
|
2518 | + * Get max value used for position of line (rang) |
|
2519 | + * |
|
2520 | + * @param int $fk_parent_line Parent line id |
|
2521 | + * @return int Max value of rang in table of lines |
|
2522 | + */ |
|
2523 | + function line_max($fk_parent_line=0) |
|
2524 | + { |
|
2525 | + // phpcs:enable |
|
2526 | + // Search the last rang with fk_parent_line |
|
2527 | + if ($fk_parent_line) |
|
2528 | + { |
|
2529 | + $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2530 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2531 | + $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
2532 | + |
|
2533 | + dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
2534 | + $resql = $this->db->query($sql); |
|
2535 | + if ($resql) |
|
2536 | + { |
|
2537 | + $row = $this->db->fetch_row($resql); |
|
2538 | + if (! empty($row[0])) |
|
2539 | + { |
|
2540 | + return $row[0]; |
|
2541 | + } |
|
2542 | + else |
|
2543 | + { |
|
2544 | + return $this->getRangOfLine($fk_parent_line); |
|
2545 | + } |
|
2546 | + } |
|
2547 | + } |
|
2548 | + // If not, search the last rang of element |
|
2549 | + else |
|
2550 | + { |
|
2551 | + $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2552 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2553 | + |
|
2554 | + dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
2555 | + $resql = $this->db->query($sql); |
|
2556 | + if ($resql) |
|
2557 | + { |
|
2558 | + $row = $this->db->fetch_row($resql); |
|
2559 | + return $row[0]; |
|
2560 | + } |
|
2561 | + } |
|
2562 | + } |
|
2563 | + |
|
2564 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2565 | + /** |
|
2566 | + * Update external ref of element |
|
2567 | + * |
|
2568 | + * @param string $ref_ext Update field ref_ext |
|
2569 | + * @return int <0 if KO, >0 if OK |
|
2570 | + */ |
|
2571 | + function update_ref_ext($ref_ext) |
|
2572 | + { |
|
2573 | + // phpcs:enable |
|
2574 | + if (! $this->table_element) |
|
2575 | + { |
|
2576 | + dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
|
2577 | + return -1; |
|
2578 | + } |
|
2579 | + |
|
2580 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
2581 | + $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
2582 | + $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
2583 | + |
|
2584 | + dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
|
2585 | + if ($this->db->query($sql)) |
|
2586 | + { |
|
2587 | + $this->ref_ext = $ref_ext; |
|
2588 | + return 1; |
|
2589 | + } |
|
2590 | + else |
|
2591 | + { |
|
2592 | + $this->error=$this->db->error(); |
|
2593 | + return -1; |
|
2594 | + } |
|
2595 | + } |
|
2596 | + |
|
2597 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2598 | + /** |
|
2599 | + * Update note of element |
|
2600 | + * |
|
2601 | + * @param string $note New value for note |
|
2602 | + * @param string $suffix '', '_public' or '_private' |
|
2603 | + * @return int <0 if KO, >0 if OK |
|
2604 | + */ |
|
2605 | + function update_note($note, $suffix='') |
|
2606 | + { |
|
2607 | + // phpcs:enable |
|
2608 | + global $user; |
|
2609 | + |
|
2610 | + if (! $this->table_element) |
|
2611 | + { |
|
2612 | + $this->error='update_note was called on objet with property table_element not defined'; |
|
2613 | + dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
|
2614 | + return -1; |
|
2615 | + } |
|
2616 | + if (! in_array($suffix,array('','_public','_private'))) |
|
2617 | + { |
|
2618 | + $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
2619 | + dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
|
2620 | + return -2; |
|
2621 | + } |
|
2622 | + // Special cas |
|
2623 | + //var_dump($this->table_element);exit; |
|
2624 | + if ($this->table_element == 'product') $suffix=''; |
|
2625 | + |
|
2626 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
2627 | + $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL"); |
|
2628 | + $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id; |
|
2629 | + $sql.= " WHERE rowid =". $this->id; |
|
2630 | + |
|
2631 | + dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
|
2632 | + if ($this->db->query($sql)) |
|
2633 | + { |
|
2634 | + if ($suffix == '_public') $this->note_public = $note; |
|
2635 | + else if ($suffix == '_private') $this->note_private = $note; |
|
2636 | + else |
|
2637 | + { |
|
2638 | + $this->note = $note; // deprecated |
|
2639 | + $this->note_private = $note; |
|
2640 | + } |
|
2641 | + return 1; |
|
2642 | + } |
|
2643 | + else |
|
2644 | + { |
|
2645 | + $this->error=$this->db->lasterror(); |
|
2646 | + return -1; |
|
2647 | + } |
|
2648 | + } |
|
2649 | + |
|
2650 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2651 | + /** |
|
2652 | + * Update public note (kept for backward compatibility) |
|
2653 | + * |
|
2654 | + * @param string $note New value for note |
|
2655 | + * @return int <0 if KO, >0 if OK |
|
2656 | + * @deprecated |
|
2657 | + * @see update_note() |
|
2658 | + */ |
|
2659 | + function update_note_public($note) |
|
2660 | + { |
|
2661 | + // phpcs:enable |
|
2662 | + return $this->update_note($note,'_public'); |
|
2663 | + } |
|
2664 | + |
|
2665 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2666 | + /** |
|
2667 | + * Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines). |
|
2668 | + * Must be called at end of methods addline or updateline. |
|
2669 | + * |
|
2670 | + * @param int $exclspec >0 = Exclude special product (product_type=9) |
|
2671 | + * @param string $roundingadjust 'none'=Do nothing, 'auto'=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND if defined, or '0'), '0'=Force mode total of rounding, '1'=Force mode rounding of total |
|
2672 | + * @param int $nodatabaseupdate 1=Do not update database. Update only properties of object. |
|
2673 | + * @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. |
|
2674 | + * @return int <0 if KO, >0 if OK |
|
2675 | + */ |
|
2676 | + function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
2677 | + { |
|
2678 | + // phpcs:enable |
|
2679 | + global $conf, $hookmanager, $action; |
|
2680 | + |
|
2681 | + // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) |
|
2682 | + $MODULE = ""; |
|
2683 | + if ($this->element == 'propal') |
|
2684 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
2685 | + elseif ($this->element == 'order') |
|
2686 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
2687 | + elseif ($this->element == 'facture') |
|
2688 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
2689 | + elseif ($this->element == 'facture_fourn') |
|
2690 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
2691 | + elseif ($this->element == 'order_supplier') |
|
2692 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
2693 | + elseif ($this->element == 'supplier_proposal') |
|
2694 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
2695 | + |
|
2696 | + if (! empty($MODULE)) { |
|
2697 | + if (! empty($conf->global->$MODULE)) { |
|
2698 | + $modsactivated = explode(',', $conf->global->$MODULE); |
|
2699 | + foreach ($modsactivated as $mod) { |
|
2700 | + if ($conf->$mod->enabled) |
|
2701 | + return 1; // update was disabled by specific setup |
|
2702 | + } |
|
2703 | + } |
|
2704 | + } |
|
2705 | + |
|
2706 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
|
2707 | + |
|
2708 | + if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
2709 | + |
|
2710 | + $forcedroundingmode=$roundingadjust; |
|
2711 | + if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
2712 | + elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
2713 | + |
|
2714 | + $error=0; |
|
2715 | + |
|
2716 | + $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
|
2717 | + |
|
2718 | + // Define constants to find lines to sum |
|
2719 | + $fieldtva='total_tva'; |
|
2720 | + $fieldlocaltax1='total_localtax1'; |
|
2721 | + $fieldlocaltax2='total_localtax2'; |
|
2722 | + $fieldup='subprice'; |
|
2723 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
2724 | + { |
|
2725 | + $fieldtva='tva'; |
|
2726 | + $fieldup='pu_ht'; |
|
2727 | + } |
|
2728 | + if ($this->element == 'expensereport') |
|
2729 | + { |
|
2730 | + $fieldup='value_unit'; |
|
2731 | + } |
|
2732 | + |
|
2733 | + $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,'; |
|
2734 | + $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
2735 | + if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
2736 | + $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
2737 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2738 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2739 | + if ($exclspec) |
|
2740 | + { |
|
2741 | + $product_field='product_type'; |
|
2742 | + if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
2743 | + if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
2744 | + } |
|
2745 | + $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 | + |
|
2747 | + dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
2748 | + $resql = $this->db->query($sql); |
|
2749 | + if ($resql) |
|
2750 | + { |
|
2751 | + $this->total_ht = 0; |
|
2752 | + $this->total_tva = 0; |
|
2753 | + $this->total_localtax1 = 0; |
|
2754 | + $this->total_localtax2 = 0; |
|
2755 | + $this->total_ttc = 0; |
|
2756 | + $total_ht_by_vats = array(); |
|
2757 | + $total_tva_by_vats = array(); |
|
2758 | + $total_ttc_by_vats = array(); |
|
2759 | + $this->multicurrency_total_ht = 0; |
|
2760 | + $this->multicurrency_total_tva = 0; |
|
2761 | + $this->multicurrency_total_ttc = 0; |
|
2762 | + |
|
2763 | + $num = $this->db->num_rows($resql); |
|
2764 | + $i = 0; |
|
2765 | + while ($i < $num) |
|
2766 | + { |
|
2767 | + $obj = $this->db->fetch_object($resql); |
|
2768 | + |
|
2769 | + // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
|
2770 | + $parameters=array('fk_element' => $obj->rowid); |
|
2771 | + $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
2772 | + |
|
2773 | + 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' |
|
2774 | + { |
|
2775 | + $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
2776 | + $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); |
|
2777 | + $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
2778 | + if ($diff) |
|
2779 | + { |
|
2780 | + $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
2781 | + 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); |
|
2782 | + $resqlfix=$this->db->query($sqlfix); |
|
2783 | + if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
2784 | + $obj->total_tva = $tmpcal[1]; |
|
2785 | + $obj->total_ttc = $tmpcal[2]; |
|
2786 | + // |
|
2787 | + } |
|
2788 | + } |
|
2789 | + |
|
2790 | + $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
2791 | + $this->total_tva += $obj->total_tva; |
|
2792 | + $this->total_localtax1 += $obj->total_localtax1; |
|
2793 | + $this->total_localtax2 += $obj->total_localtax2; |
|
2794 | + $this->total_ttc += $obj->total_ttc; |
|
2795 | + $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
2796 | + $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
|
2797 | + $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
|
2798 | + |
|
2799 | + if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
2800 | + if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
2801 | + if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
2802 | + $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
|
2803 | + $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
|
2804 | + $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
|
2805 | + |
|
2806 | + if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
2807 | + { |
|
2808 | + $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
2809 | + $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
2810 | + //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"; |
|
2811 | + if ($diff) |
|
2812 | + { |
|
2813 | + if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; } |
|
2814 | + $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 | + 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); |
|
2816 | + $resqlfix=$this->db->query($sqlfix); |
|
2817 | + if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
2818 | + $this->total_tva -= $diff; |
|
2819 | + $this->total_ttc -= $diff; |
|
2820 | + $total_tva_by_vats[$obj->vatrate] -= $diff; |
|
2821 | + $total_ttc_by_vats[$obj->vatrate] -= $diff; |
|
2822 | + } |
|
2823 | + } |
|
2824 | + |
|
2825 | + $i++; |
|
2826 | + } |
|
2827 | + |
|
2828 | + // Add revenue stamp to total |
|
2829 | + $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
2830 | + $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
2831 | + |
|
2832 | + // Situations totals |
|
2833 | + if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE ) |
|
2834 | + { |
|
2835 | + $prev_sits = $this->get_prev_sits(); |
|
2836 | + |
|
2837 | + foreach ($prev_sits as $sit) { // $sit is an object Facture loaded with a fetch. |
|
2838 | + $this->total_ht -= $sit->total_ht; |
|
2839 | + $this->total_tva -= $sit->total_tva; |
|
2840 | + $this->total_localtax1 -= $sit->total_localtax1; |
|
2841 | + $this->total_localtax2 -= $sit->total_localtax2; |
|
2842 | + $this->total_ttc -= $sit->total_ttc; |
|
2843 | + $this->multicurrency_total_ht -= $sit->multicurrency_total_ht; |
|
2844 | + $this->multicurrency_total_tva -= $sit->multicurrency_total_tva; |
|
2845 | + $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc; |
|
2846 | + } |
|
2847 | + } |
|
2848 | + |
|
2849 | + $this->db->free($resql); |
|
2850 | + |
|
2851 | + // Now update global field total_ht, total_ttc and tva |
|
2852 | + $fieldht='total_ht'; |
|
2853 | + $fieldtva='tva'; |
|
2854 | + $fieldlocaltax1='localtax1'; |
|
2855 | + $fieldlocaltax2='localtax2'; |
|
2856 | + $fieldttc='total_ttc'; |
|
2857 | + // Specific code for backward compatibility with old field names |
|
2858 | + if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
2859 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
2860 | + if ($this->element == 'propal') $fieldttc='total'; |
|
2861 | + if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
2862 | + if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
2863 | + |
|
2864 | + if (empty($nodatabaseupdate)) |
|
2865 | + { |
|
2866 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
2867 | + $sql .= " ".$fieldht."='".price2num($this->total_ht)."',"; |
|
2868 | + $sql .= " ".$fieldtva."='".price2num($this->total_tva)."',"; |
|
2869 | + $sql .= " ".$fieldlocaltax1."='".price2num($this->total_localtax1)."',"; |
|
2870 | + $sql .= " ".$fieldlocaltax2."='".price2num($this->total_localtax2)."',"; |
|
2871 | + $sql .= " ".$fieldttc."='".price2num($this->total_ttc)."'"; |
|
2872 | + $sql .= ", multicurrency_total_ht='".price2num($this->multicurrency_total_ht, 'MT', 1)."'"; |
|
2873 | + $sql .= ", multicurrency_total_tva='".price2num($this->multicurrency_total_tva, 'MT', 1)."'"; |
|
2874 | + $sql .= ", multicurrency_total_ttc='".price2num($this->multicurrency_total_ttc, 'MT', 1)."'"; |
|
2875 | + $sql .= ' WHERE rowid = '.$this->id; |
|
2876 | + |
|
2877 | + |
|
2878 | + dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
2879 | + $resql=$this->db->query($sql); |
|
2880 | + if (! $resql) |
|
2881 | + { |
|
2882 | + $error++; |
|
2883 | + $this->error=$this->db->lasterror(); |
|
2884 | + $this->errors[]=$this->db->lasterror(); |
|
2885 | + } |
|
2886 | + } |
|
2887 | + |
|
2888 | + if (! $error) |
|
2889 | + { |
|
2890 | + return 1; |
|
2891 | + } |
|
2892 | + else |
|
2893 | + { |
|
2894 | + return -1; |
|
2895 | + } |
|
2896 | + } |
|
2897 | + else |
|
2898 | + { |
|
2899 | + dol_print_error($this->db,'Bad request in update_price'); |
|
2900 | + return -1; |
|
2901 | + } |
|
2902 | + } |
|
2903 | + |
|
2904 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
2905 | + /** |
|
2906 | + * Add objects linked in llx_element_element. |
|
2907 | + * |
|
2908 | + * @param string $origin Linked element type |
|
2909 | + * @param int $origin_id Linked element id |
|
2910 | + * @return int <=0 if KO, >0 if OK |
|
2911 | + * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
|
2912 | + */ |
|
2913 | + function add_object_linked($origin=null, $origin_id=null) |
|
2914 | + { |
|
2915 | + // phpcs:enable |
|
2916 | + $origin = (! empty($origin) ? $origin : $this->origin); |
|
2917 | + $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
2918 | + |
|
2919 | + // Special case |
|
2920 | + if ($origin == 'order') $origin='commande'; |
|
2921 | + if ($origin == 'invoice') $origin='facture'; |
|
2922 | + if ($origin == 'invoice_template') $origin='facturerec'; |
|
2923 | + if ($origin == 'supplierorder') $origin='order_supplier'; |
|
2924 | + $this->db->begin(); |
|
2925 | + |
|
2926 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; |
|
2927 | + $sql.= "fk_source"; |
|
2928 | + $sql.= ", sourcetype"; |
|
2929 | + $sql.= ", fk_target"; |
|
2930 | + $sql.= ", targettype"; |
|
2931 | + $sql.= ") VALUES ("; |
|
2932 | + $sql.= $origin_id; |
|
2933 | + $sql.= ", '".$this->db->escape($origin)."'"; |
|
2934 | + $sql.= ", ".$this->id; |
|
2935 | + $sql.= ", '".$this->db->escape($this->element)."'"; |
|
2936 | + $sql.= ")"; |
|
2937 | + |
|
2938 | + dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
|
2939 | + if ($this->db->query($sql)) |
|
2940 | + { |
|
2941 | + $this->db->commit(); |
|
2942 | + return 1; |
|
2943 | + } |
|
2944 | + else |
|
2945 | + { |
|
2946 | + $this->error=$this->db->lasterror(); |
|
2947 | + $this->db->rollback(); |
|
2948 | + return 0; |
|
2949 | + } |
|
2950 | + } |
|
2951 | + |
|
2952 | + /** |
|
2953 | + * Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into |
|
2954 | + * this->linkedObjectsIds array and |
|
2955 | + * this->linkedObjects array if $loadalsoobjects = 1 |
|
2956 | + * Possible usage for parameters: |
|
2957 | + * - all parameters empty -> we look all link to current object (current object can be source or target) |
|
2958 | + * - source id+type -> will get target list linked to source |
|
2959 | + * - target id+type -> will get source list linked to target |
|
2960 | + * - source id+type + target type -> will get target list of the type |
|
2961 | + * - target id+type + target source -> will get source list of the type |
|
2962 | + * |
|
2963 | + * @param int $sourceid Object source id (if not defined, id of object) |
|
2964 | + * @param string $sourcetype Object source type (if not defined, element name of object) |
|
2965 | + * @param int $targetid Object target id (if not defined, id of object) |
|
2966 | + * @param string $targettype Object target type (if not defined, elemennt name of object) |
|
2967 | + * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided |
|
2968 | + * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. |
|
2969 | + * @param string $orderby SQL 'ORDER BY' clause |
|
2970 | + * @param int $loadalsoobjects Load also array this->linkedObjects (Use 0 to increase performances) |
|
2971 | + * @return int <0 if KO, >0 if OK |
|
2972 | + * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
|
2973 | + */ |
|
2974 | + function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype',$loadalsoobjects=1) |
|
2975 | + { |
|
2976 | + global $conf; |
|
2977 | + |
|
2978 | + $this->linkedObjectsIds=array(); |
|
2979 | + $this->linkedObjects=array(); |
|
2980 | + |
|
2981 | + $justsource=false; |
|
2982 | + $justtarget=false; |
|
2983 | + $withtargettype=false; |
|
2984 | + $withsourcetype=false; |
|
2985 | + |
|
2986 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
2987 | + { |
|
2988 | + $justsource=true; // the source (id and type) is a search criteria |
|
2989 | + if (! empty($targettype)) $withtargettype=true; |
|
2990 | + } |
|
2991 | + if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
2992 | + { |
|
2993 | + $justtarget=true; // the target (id and type) is a search criteria |
|
2994 | + if (! empty($sourcetype)) $withsourcetype=true; |
|
2995 | + } |
|
2996 | + |
|
2997 | + $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
2998 | + $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
2999 | + $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
3000 | + $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
3001 | + |
|
3002 | + /*if (empty($sourceid) && empty($targetid)) |
|
3003 | + { |
|
3004 | + dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERR); |
|
3005 | + return -1; |
|
3006 | + }*/ |
|
3007 | + |
|
3008 | + // Links between objects are stored in table element_element |
|
3009 | + $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
|
3010 | + $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
3011 | + $sql.= " WHERE "; |
|
3012 | + if ($justsource || $justtarget) |
|
3013 | + { |
|
3014 | + if ($justsource) |
|
3015 | + { |
|
3016 | + $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
3017 | + if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
3018 | + } |
|
3019 | + else if ($justtarget) |
|
3020 | + { |
|
3021 | + $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
3022 | + if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
3023 | + } |
|
3024 | + } |
|
3025 | + else |
|
3026 | + { |
|
3027 | + $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
3028 | + $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
3029 | + } |
|
3030 | + $sql .= ' ORDER BY '.$orderby; |
|
3031 | + |
|
3032 | + dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); |
|
3033 | + $resql = $this->db->query($sql); |
|
3034 | + if ($resql) |
|
3035 | + { |
|
3036 | + $num = $this->db->num_rows($resql); |
|
3037 | + $i = 0; |
|
3038 | + while ($i < $num) |
|
3039 | + { |
|
3040 | + $obj = $this->db->fetch_object($resql); |
|
3041 | + if ($justsource || $justtarget) |
|
3042 | + { |
|
3043 | + if ($justsource) |
|
3044 | + { |
|
3045 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
3046 | + } |
|
3047 | + else if ($justtarget) |
|
3048 | + { |
|
3049 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
3050 | + } |
|
3051 | + } |
|
3052 | + else |
|
3053 | + { |
|
3054 | + if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
|
3055 | + { |
|
3056 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
3057 | + } |
|
3058 | + if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
|
3059 | + { |
|
3060 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
3061 | + } |
|
3062 | + } |
|
3063 | + $i++; |
|
3064 | + } |
|
3065 | + |
|
3066 | + if (! empty($this->linkedObjectsIds)) |
|
3067 | + { |
|
3068 | + $tmparray = $this->linkedObjectsIds; |
|
3069 | + foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) |
|
3070 | + { |
|
3071 | + // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
|
3072 | + $module = $element = $subelement = $objecttype; |
|
3073 | + if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
|
3074 | + && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) |
|
3075 | + { |
|
3076 | + $module = $element = $regs[1]; |
|
3077 | + $subelement = $regs[2]; |
|
3078 | + } |
|
3079 | + |
|
3080 | + $classpath = $element.'/class'; |
|
3081 | + // To work with non standard classpath or module name |
|
3082 | + if ($objecttype == 'facture') { |
|
3083 | + $classpath = 'compta/facture/class'; |
|
3084 | + } |
|
3085 | + else if ($objecttype == 'facturerec') { |
|
3086 | + $classpath = 'compta/facture/class'; $module = 'facture'; |
|
3087 | + } |
|
3088 | + else if ($objecttype == 'propal') { |
|
3089 | + $classpath = 'comm/propal/class'; |
|
3090 | + } |
|
3091 | + else if ($objecttype == 'supplier_proposal') { |
|
3092 | + $classpath = 'supplier_proposal/class'; |
|
3093 | + } |
|
3094 | + else if ($objecttype == 'shipping') { |
|
3095 | + $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
|
3096 | + } |
|
3097 | + else if ($objecttype == 'delivery') { |
|
3098 | + $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
|
3099 | + } |
|
3100 | + else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
3101 | + $classpath = 'fourn/class'; $module = 'fournisseur'; |
|
3102 | + } |
|
3103 | + else if ($objecttype == 'fichinter') { |
|
3104 | + $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
|
3105 | + } |
|
3106 | + else if ($objecttype == 'subscription') { |
|
3107 | + $classpath = 'adherents/class'; $module = 'adherent'; |
|
3108 | + } |
|
3109 | + |
|
3110 | + // Set classfile |
|
3111 | + $classfile = strtolower($subelement); $classname = ucfirst($subelement); |
|
3112 | + |
|
3113 | + if ($objecttype == 'order') { |
|
3114 | + $classfile = 'commande'; $classname = 'Commande'; |
|
3115 | + } |
|
3116 | + else if ($objecttype == 'invoice_supplier') { |
|
3117 | + $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
|
3118 | + } |
|
3119 | + else if ($objecttype == 'order_supplier') { |
|
3120 | + $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
|
3121 | + } |
|
3122 | + else if ($objecttype == 'supplier_proposal') { |
|
3123 | + $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
|
3124 | + } |
|
3125 | + else if ($objecttype == 'facturerec') { |
|
3126 | + $classfile = 'facture-rec'; $classname = 'FactureRec'; |
|
3127 | + } |
|
3128 | + else if ($objecttype == 'subscription') { |
|
3129 | + $classfile = 'subscription'; $classname = 'Subscription'; |
|
3130 | + } |
|
3131 | + |
|
3132 | + // Here $module, $classfile and $classname are set |
|
3133 | + if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) |
|
3134 | + { |
|
3135 | + if ($loadalsoobjects) |
|
3136 | + { |
|
3137 | + dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); |
|
3138 | + //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
|
3139 | + if (class_exists($classname)) |
|
3140 | + { |
|
3141 | + foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
3142 | + { |
|
3143 | + $object = new $classname($this->db); |
|
3144 | + $ret = $object->fetch($objectid); |
|
3145 | + if ($ret >= 0) |
|
3146 | + { |
|
3147 | + $this->linkedObjects[$objecttype][$i] = $object; |
|
3148 | + } |
|
3149 | + } |
|
3150 | + } |
|
3151 | + } |
|
3152 | + } |
|
3153 | + else |
|
3154 | + { |
|
3155 | + unset($this->linkedObjectsIds[$objecttype]); |
|
3156 | + } |
|
3157 | + } |
|
3158 | + } |
|
3159 | + return 1; |
|
3160 | + } |
|
3161 | + else |
|
3162 | + { |
|
3163 | + dol_print_error($this->db); |
|
3164 | + return -1; |
|
3165 | + } |
|
3166 | + } |
|
3167 | + |
|
3168 | + /** |
|
3169 | + * Update object linked of a current object |
|
3170 | + * |
|
3171 | + * @param int $sourceid Object source id |
|
3172 | + * @param string $sourcetype Object source type |
|
3173 | + * @param int $targetid Object target id |
|
3174 | + * @param string $targettype Object target type |
|
3175 | + * @return int >0 if OK, <0 if KO |
|
3176 | + * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
|
3177 | + */ |
|
3178 | + function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
3179 | + { |
|
3180 | + $updatesource=false; |
|
3181 | + $updatetarget=false; |
|
3182 | + |
|
3183 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
3184 | + else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
3185 | + |
|
3186 | + $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
|
3187 | + if ($updatesource) |
|
3188 | + { |
|
3189 | + $sql.= "fk_source = ".$sourceid; |
|
3190 | + $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3191 | + $sql.= " WHERE fk_target = ".$this->id; |
|
3192 | + $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
3193 | + } |
|
3194 | + else if ($updatetarget) |
|
3195 | + { |
|
3196 | + $sql.= "fk_target = ".$targetid; |
|
3197 | + $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
3198 | + $sql.= " WHERE fk_source = ".$this->id; |
|
3199 | + $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3200 | + } |
|
3201 | + |
|
3202 | + dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
|
3203 | + if ($this->db->query($sql)) |
|
3204 | + { |
|
3205 | + return 1; |
|
3206 | + } |
|
3207 | + else |
|
3208 | + { |
|
3209 | + $this->error=$this->db->lasterror(); |
|
3210 | + return -1; |
|
3211 | + } |
|
3212 | + } |
|
3213 | + |
|
3214 | + /** |
|
3215 | + * Delete all links between an object $this |
|
3216 | + * |
|
3217 | + * @param int $sourceid Object source id |
|
3218 | + * @param string $sourcetype Object source type |
|
3219 | + * @param int $targetid Object target id |
|
3220 | + * @param string $targettype Object target type |
|
3221 | + * @param int $rowid Row id of line to delete. If defined, other parameters are not used. |
|
3222 | + * @return int >0 if OK, <0 if KO |
|
3223 | + * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
|
3224 | + */ |
|
3225 | + function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
3226 | + { |
|
3227 | + $deletesource=false; |
|
3228 | + $deletetarget=false; |
|
3229 | + |
|
3230 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
3231 | + else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
3232 | + |
|
3233 | + $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
3234 | + $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
3235 | + $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
3236 | + $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
3237 | + |
|
3238 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
|
3239 | + $sql.= " WHERE"; |
|
3240 | + if ($rowid > 0) |
|
3241 | + { |
|
3242 | + $sql.=" rowid = ".$rowid; |
|
3243 | + } |
|
3244 | + else |
|
3245 | + { |
|
3246 | + if ($deletesource) |
|
3247 | + { |
|
3248 | + $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3249 | + $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
3250 | + } |
|
3251 | + else if ($deletetarget) |
|
3252 | + { |
|
3253 | + $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
3254 | + $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3255 | + } |
|
3256 | + else |
|
3257 | + { |
|
3258 | + $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
3259 | + $sql.= " OR"; |
|
3260 | + $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
3261 | + } |
|
3262 | + } |
|
3263 | + |
|
3264 | + dol_syslog(get_class($this)."::deleteObjectLinked", LOG_DEBUG); |
|
3265 | + if ($this->db->query($sql)) |
|
3266 | + { |
|
3267 | + return 1; |
|
3268 | + } |
|
3269 | + else |
|
3270 | + { |
|
3271 | + $this->error=$this->db->lasterror(); |
|
3272 | + $this->errors[]=$this->error; |
|
3273 | + return -1; |
|
3274 | + } |
|
3275 | + } |
|
3276 | + |
|
3277 | + /** |
|
3278 | + * Set status of an object |
|
3279 | + * |
|
3280 | + * @param int $status Status to set |
|
3281 | + * @param int $elementId Id of element to force (use this->id by default) |
|
3282 | + * @param string $elementType Type of element to force (use this->table_element by default) |
|
3283 | + * @param string $trigkey Trigger key to use for trigger |
|
3284 | + * @return int <0 if KO, >0 if OK |
|
3285 | + */ |
|
3286 | + function setStatut($status, $elementId=null, $elementType='', $trigkey='') |
|
3287 | + { |
|
3288 | + global $user,$langs,$conf; |
|
3289 | + |
|
3290 | + $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
3291 | + |
|
3292 | + $elementId = (!empty($elementId)?$elementId:$this->id); |
|
3293 | + $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
3294 | + |
|
3295 | + $this->db->begin(); |
|
3296 | + |
|
3297 | + $fieldstatus="fk_statut"; |
|
3298 | + if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
3299 | + if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
3300 | + if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
3301 | + if ($elementTable == 'user') $fieldstatus="statut"; |
|
3302 | + if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
3303 | + if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
3304 | + |
|
3305 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
|
3306 | + $sql.= " SET ".$fieldstatus." = ".$status; |
|
3307 | + // If status = 1 = validated, update also fk_user_valid |
|
3308 | + if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
3309 | + $sql.= " WHERE rowid=".$elementId; |
|
3310 | + |
|
3311 | + dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
|
3312 | + if ($this->db->query($sql)) |
|
3313 | + { |
|
3314 | + $error = 0; |
|
3315 | + |
|
3316 | + // Try autoset of trigkey |
|
3317 | + if (empty($trigkey)) |
|
3318 | + { |
|
3319 | + if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
3320 | + if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
3321 | + if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
3322 | + if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
3323 | + if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
3324 | + if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
3325 | + } |
|
3326 | + |
|
3327 | + if ($trigkey) |
|
3328 | + { |
|
3329 | + // Appel des triggers |
|
3330 | + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
3331 | + $interface=new Interfaces($this->db); |
|
3332 | + $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
3333 | + if ($result < 0) { |
|
3334 | + $error++; $this->errors=$interface->errors; |
|
3335 | + } |
|
3336 | + // Fin appel triggers |
|
3337 | + } |
|
3338 | + |
|
3339 | + if (! $error) |
|
3340 | + { |
|
3341 | + $this->db->commit(); |
|
3342 | + |
|
3343 | + if (empty($savElementId)) // If the element we update was $this (so $elementId is null) |
|
3344 | + { |
|
3345 | + $this->statut = $status; |
|
3346 | + $this->status = $status; |
|
3347 | + } |
|
3348 | + |
|
3349 | + return 1; |
|
3350 | + } |
|
3351 | + else |
|
3352 | + { |
|
3353 | + $this->db->rollback(); |
|
3354 | + dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
3355 | + return -1; |
|
3356 | + } |
|
3357 | + } |
|
3358 | + else |
|
3359 | + { |
|
3360 | + $this->error=$this->db->lasterror(); |
|
3361 | + $this->db->rollback(); |
|
3362 | + return -1; |
|
3363 | + } |
|
3364 | + } |
|
3365 | + |
|
3366 | + |
|
3367 | + /** |
|
3368 | + * Load type of canvas of an object if it exists |
|
3369 | + * |
|
3370 | + * @param int $id Record id |
|
3371 | + * @param string $ref Record ref |
|
3372 | + * @return int <0 if KO, 0 if nothing done, >0 if OK |
|
3373 | + */ |
|
3374 | + function getCanvas($id=0,$ref='') |
|
3375 | + { |
|
3376 | + global $conf; |
|
3377 | + |
|
3378 | + if (empty($id) && empty($ref)) return 0; |
|
3379 | + if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
3380 | + |
|
3381 | + // Clean parameters |
|
3382 | + $ref = trim($ref); |
|
3383 | + |
|
3384 | + $sql = "SELECT rowid, canvas"; |
|
3385 | + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
3386 | + $sql.= " WHERE entity IN (".getEntity($this->element).")"; |
|
3387 | + if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
3388 | + if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
3389 | + |
|
3390 | + $resql = $this->db->query($sql); |
|
3391 | + if ($resql) |
|
3392 | + { |
|
3393 | + $obj = $this->db->fetch_object($resql); |
|
3394 | + if ($obj) |
|
3395 | + { |
|
3396 | + $this->canvas = $obj->canvas; |
|
3397 | + return 1; |
|
3398 | + } |
|
3399 | + else return 0; |
|
3400 | + } |
|
3401 | + else |
|
3402 | + { |
|
3403 | + dol_print_error($this->db); |
|
3404 | + return -1; |
|
3405 | + } |
|
3406 | + } |
|
3407 | + |
|
3408 | + |
|
3409 | + /** |
|
3410 | + * Get special code of a line |
|
3411 | + * |
|
3412 | + * @param int $lineid Id of line |
|
3413 | + * @return int Special code |
|
3414 | + */ |
|
3415 | + function getSpecialCode($lineid) |
|
3416 | + { |
|
3417 | + $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
3418 | + $sql.= ' WHERE rowid = '.$lineid; |
|
3419 | + $resql = $this->db->query($sql); |
|
3420 | + if ($resql) |
|
3421 | + { |
|
3422 | + $row = $this->db->fetch_row($resql); |
|
3423 | + return $row[0]; |
|
3424 | + } |
|
3425 | + } |
|
3426 | + |
|
3427 | + /** |
|
3428 | + * Function to check if an object is used by others. |
|
3429 | + * Check is done into this->childtables. There is no check into llx_element_element. |
|
3430 | + * |
|
3431 | + * @param int $id Force id of object |
|
3432 | + * @return int <0 if KO, 0 if not used, >0 if already used |
|
3433 | + */ |
|
3434 | + function isObjectUsed($id=0) |
|
3435 | + { |
|
3436 | + global $langs; |
|
3437 | + |
|
3438 | + if (empty($id)) $id=$this->id; |
|
3439 | + |
|
3440 | + // Check parameters |
|
3441 | + if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
3442 | + { |
|
3443 | + dol_print_error('Called isObjectUsed on a class with property this->childtables not defined'); |
|
3444 | + return -1; |
|
3445 | + } |
|
3446 | + |
|
3447 | + $arraytoscan = $this->childtables; |
|
3448 | + // For backward compatibility, we check if array is old format array('table1', 'table2', ...) |
|
3449 | + $tmparray=array_keys($this->childtables); |
|
3450 | + if (is_numeric($tmparray[0])) |
|
3451 | + { |
|
3452 | + $arraytoscan = array_flip($this->childtables); |
|
3453 | + } |
|
3454 | + |
|
3455 | + // Test if child exists |
|
3456 | + $haschild=0; |
|
3457 | + foreach($arraytoscan as $table => $elementname) |
|
3458 | + { |
|
3459 | + //print $id.'-'.$table.'-'.$elementname.'<br>'; |
|
3460 | + // Check if third party can be deleted |
|
3461 | + $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
|
3462 | + $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
3463 | + $resql=$this->db->query($sql); |
|
3464 | + if ($resql) |
|
3465 | + { |
|
3466 | + $obj=$this->db->fetch_object($resql); |
|
3467 | + if ($obj->nb > 0) |
|
3468 | + { |
|
3469 | + $langs->load("errors"); |
|
3470 | + //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
|
3471 | + $haschild += $obj->nb; |
|
3472 | + if (is_numeric($elementname)) // old usage |
|
3473 | + { |
|
3474 | + $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); |
|
3475 | + } |
|
3476 | + else // new usage: $elementname=Translation key |
|
3477 | + { |
|
3478 | + $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
|
3479 | + } |
|
3480 | + break; // We found at least one, we stop here |
|
3481 | + } |
|
3482 | + } |
|
3483 | + else |
|
3484 | + { |
|
3485 | + $this->errors[]=$this->db->lasterror(); |
|
3486 | + return -1; |
|
3487 | + } |
|
3488 | + } |
|
3489 | + if ($haschild > 0) |
|
3490 | + { |
|
3491 | + $this->errors[]="ErrorRecordHasChildren"; |
|
3492 | + return $haschild; |
|
3493 | + } |
|
3494 | + else return 0; |
|
3495 | + } |
|
3496 | + |
|
3497 | + /** |
|
3498 | + * Function to say how many lines object contains |
|
3499 | + * |
|
3500 | + * @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 |
|
3501 | + * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
|
3502 | + */ |
|
3503 | + function hasProductsOrServices($predefined=-1) |
|
3504 | + { |
|
3505 | + $nb=0; |
|
3506 | + |
|
3507 | + foreach($this->lines as $key => $val) |
|
3508 | + { |
|
3509 | + $qualified=0; |
|
3510 | + if ($predefined == -1) $qualified=1; |
|
3511 | + if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
3512 | + if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
3513 | + if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
3514 | + if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
3515 | + if ($qualified) $nb++; |
|
3516 | + } |
|
3517 | + dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
|
3518 | + return $nb; |
|
3519 | + } |
|
3520 | + |
|
3521 | + /** |
|
3522 | + * Function that returns the total amount HT of discounts applied for all lines. |
|
3523 | + * |
|
3524 | + * @return float |
|
3525 | + */ |
|
3526 | + function getTotalDiscount() |
|
3527 | + { |
|
3528 | + $total_discount=0.00; |
|
3529 | + |
|
3530 | + $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
|
3531 | + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
3532 | + $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
3533 | + |
|
3534 | + dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
|
3535 | + $resql = $this->db->query($sql); |
|
3536 | + if ($resql) |
|
3537 | + { |
|
3538 | + $num=$this->db->num_rows($resql); |
|
3539 | + $i=0; |
|
3540 | + while ($i < $num) |
|
3541 | + { |
|
3542 | + $obj = $this->db->fetch_object($resql); |
|
3543 | + |
|
3544 | + $pu_ht = $obj->pu_ht; |
|
3545 | + $qty= $obj->qty; |
|
3546 | + $total_ht = $obj->total_ht; |
|
3547 | + |
|
3548 | + $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
|
3549 | + $total_discount += $total_discount_line; |
|
3550 | + |
|
3551 | + $i++; |
|
3552 | + } |
|
3553 | + } |
|
3554 | + |
|
3555 | + //print $total_discount; exit; |
|
3556 | + return price2num($total_discount); |
|
3557 | + } |
|
3558 | + |
|
3559 | + |
|
3560 | + /** |
|
3561 | + * Return into unit=0, the calculated total of weight and volume of all lines * qty |
|
3562 | + * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. |
|
3563 | + * |
|
3564 | + * @return array array('weight'=>...,'volume'=>...) |
|
3565 | + */ |
|
3566 | + function getTotalWeightVolume() |
|
3567 | + { |
|
3568 | + $totalWeight = 0; |
|
3569 | + $totalVolume = 0; |
|
3570 | + // defined for shipment only |
|
3571 | + $totalOrdered = ''; |
|
3572 | + // defined for shipment only |
|
3573 | + $totalToShip = ''; |
|
3574 | + |
|
3575 | + foreach ($this->lines as $line) |
|
3576 | + { |
|
3577 | + if (isset($line->qty_asked)) |
|
3578 | + { |
|
3579 | + if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
3580 | + $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
3581 | + } |
|
3582 | + if (isset($line->qty_shipped)) |
|
3583 | + { |
|
3584 | + if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
3585 | + $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
3586 | + }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
3587 | + { |
|
3588 | + if (empty($totalToShip)) $totalToShip=0; |
|
3589 | + $totalToShip+=$line->qty; // defined for reception only |
|
3590 | + } |
|
3591 | + |
|
3592 | + // Define qty, weight, volume, weight_units, volume_units |
|
3593 | + if ($this->element == 'shipping') { |
|
3594 | + // for shipments |
|
3595 | + $qty = $line->qty_shipped ? $line->qty_shipped : 0; |
|
3596 | + } |
|
3597 | + else { |
|
3598 | + $qty = $line->qty ? $line->qty : 0; |
|
3599 | + } |
|
3600 | + |
|
3601 | + $weight = $line->weight ? $line->weight : 0; |
|
3602 | + ($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0; |
|
3603 | + $volume = $line->volume ? $line->volume : 0; |
|
3604 | + ($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0; |
|
3605 | + |
|
3606 | + $weight_units=$line->weight_units; |
|
3607 | + ($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0; |
|
3608 | + $volume_units=$line->volume_units; |
|
3609 | + ($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0; |
|
3610 | + |
|
3611 | + $weightUnit=0; |
|
3612 | + $volumeUnit=0; |
|
3613 | + if (! empty($weight_units)) $weightUnit = $weight_units; |
|
3614 | + if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
3615 | + |
|
3616 | + if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
3617 | + if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
3618 | + |
|
3619 | + //var_dump($line->volume_units); |
|
3620 | + if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
3621 | + { |
|
3622 | + $trueWeightUnit=pow(10, $weightUnit); |
|
3623 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
3624 | + } |
|
3625 | + else { |
|
3626 | + if ($weight_units == 99) { |
|
3627 | + // conversion 1 Pound = 0.45359237 KG |
|
3628 | + $trueWeightUnit = 0.45359237; |
|
3629 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
3630 | + } elseif ($weight_units == 98) { |
|
3631 | + // conversion 1 Ounce = 0.0283495 KG |
|
3632 | + $trueWeightUnit = 0.0283495; |
|
3633 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
3634 | + } |
|
3635 | + else |
|
3636 | + $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
3637 | + } |
|
3638 | + if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
3639 | + { |
|
3640 | + //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
|
3641 | + $trueVolumeUnit=pow(10, $volumeUnit); |
|
3642 | + //print $line->volume; |
|
3643 | + $totalVolume += $volume * $qty * $trueVolumeUnit; |
|
3644 | + } |
|
3645 | + else |
|
3646 | + { |
|
3647 | + $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
3648 | + } |
|
3649 | + } |
|
3650 | + |
|
3651 | + return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip); |
|
3652 | + } |
|
3653 | + |
|
3654 | + |
|
3655 | + /** |
|
3656 | + * Set extra parameters |
|
3657 | + * |
|
3658 | + * @return int <0 if KO, >0 if OK |
|
3659 | + */ |
|
3660 | + function setExtraParameters() |
|
3661 | + { |
|
3662 | + $this->db->begin(); |
|
3663 | + |
|
3664 | + $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
3665 | + |
|
3666 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
3667 | + $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
3668 | + $sql.= " WHERE rowid = ".$this->id; |
|
3669 | + |
|
3670 | + dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
|
3671 | + $resql = $this->db->query($sql); |
|
3672 | + if (! $resql) |
|
3673 | + { |
|
3674 | + $this->error=$this->db->lasterror(); |
|
3675 | + $this->db->rollback(); |
|
3676 | + return -1; |
|
3677 | + } |
|
3678 | + else |
|
3679 | + { |
|
3680 | + $this->db->commit(); |
|
3681 | + return 1; |
|
3682 | + } |
|
3683 | + } |
|
3684 | + |
|
3685 | + |
|
3686 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
3687 | + /** |
|
3688 | + * Return incoterms informations |
|
3689 | + * TODO Use a cache for label get |
|
3690 | + * |
|
3691 | + * @return string incoterms info |
|
3692 | + */ |
|
3693 | + function display_incoterms() |
|
3694 | + { |
|
3695 | + // phpcs:enable |
|
3696 | + $out = ''; |
|
3697 | + $this->libelle_incoterms = ''; |
|
3698 | + if (!empty($this->fk_incoterms)) |
|
3699 | + { |
|
3700 | + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
3701 | + $result = $this->db->query($sql); |
|
3702 | + if ($result) |
|
3703 | + { |
|
3704 | + $res = $this->db->fetch_object($result); |
|
3705 | + $out .= $res->code; |
|
3706 | + } |
|
3707 | + } |
|
3708 | + |
|
3709 | + $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
3710 | + |
|
3711 | + return $out; |
|
3712 | + } |
|
3713 | + |
|
3714 | + /** |
|
3715 | + * Return incoterms informations for pdf display |
|
3716 | + * |
|
3717 | + * @return string incoterms info |
|
3718 | + */ |
|
3719 | + function getIncotermsForPDF() |
|
3720 | + { |
|
3721 | + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
3722 | + $resql = $this->db->query($sql); |
|
3723 | + if ($resql) |
|
3724 | + { |
|
3725 | + $num = $this->db->num_rows($resql); |
|
3726 | + if ($num > 0) |
|
3727 | + { |
|
3728 | + $res = $this->db->fetch_object($resql); |
|
3729 | + return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
|
3730 | + } |
|
3731 | + else |
|
3732 | + { |
|
3733 | + return ''; |
|
3734 | + } |
|
3735 | + } |
|
3736 | + else |
|
3737 | + { |
|
3738 | + $this->errors[] = $this->db->lasterror(); |
|
3739 | + return false; |
|
3740 | + } |
|
3741 | + } |
|
3742 | + |
|
3743 | + /** |
|
3744 | + * Define incoterms values of current object |
|
3745 | + * |
|
3746 | + * @param int $id_incoterm Id of incoterm to set or '' to remove |
|
3747 | + * @param string $location location of incoterm |
|
3748 | + * @return int <0 if KO, >0 if OK |
|
3749 | + */ |
|
3750 | + function setIncoterms($id_incoterm, $location) |
|
3751 | + { |
|
3752 | + if ($this->id && $this->table_element) |
|
3753 | + { |
|
3754 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
3755 | + $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
3756 | + $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
3757 | + $sql.= " WHERE rowid = " . $this->id; |
|
3758 | + dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
|
3759 | + $resql=$this->db->query($sql); |
|
3760 | + if ($resql) |
|
3761 | + { |
|
3762 | + $this->fk_incoterms = $id_incoterm; |
|
3763 | + $this->location_incoterms = $location; |
|
3764 | + |
|
3765 | + $sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
3766 | + $res = $this->db->query($sql); |
|
3767 | + if ($res) |
|
3768 | + { |
|
3769 | + $obj = $this->db->fetch_object($res); |
|
3770 | + $this->libelle_incoterms = $obj->libelle; |
|
3771 | + } |
|
3772 | + return 1; |
|
3773 | + } |
|
3774 | + else |
|
3775 | + { |
|
3776 | + $this->errors[] = $this->db->lasterror(); |
|
3777 | + return -1; |
|
3778 | + } |
|
3779 | + } |
|
3780 | + else return -1; |
|
3781 | + } |
|
3782 | + |
|
3783 | + |
|
3784 | + // -------------------- |
|
3785 | + // TODO: All functions here must be redesigned and moved as they are not business functions but output functions |
|
3786 | + // -------------------- |
|
3787 | + |
|
3788 | + /* This is to show add lines */ |
|
3789 | + |
|
3790 | + /** |
|
3791 | + * Show add free and predefined products/services form |
|
3792 | + * |
|
3793 | + * @param int $dateSelector 1=Show also date range input fields |
|
3794 | + * @param Societe $seller Object thirdparty who sell |
|
3795 | + * @param Societe $buyer Object thirdparty who buy |
|
3796 | + * @return void |
|
3797 | + */ |
|
3798 | + function formAddObjectLine($dateSelector, $seller, $buyer) |
|
3799 | + { |
|
3800 | + global $conf,$user,$langs,$object,$hookmanager; |
|
3801 | + global $form,$bcnd,$var; |
|
3802 | + |
|
3803 | + // Line extrafield |
|
3804 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
3805 | + $extrafieldsline = new ExtraFields($this->db); |
|
3806 | + $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
3807 | + |
|
3808 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
3809 | + // Use global variables + $dateSelector + $seller and $buyer |
|
3810 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
3811 | + foreach($dirtpls as $reldir) |
|
3812 | + { |
|
3813 | + $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
|
3814 | + if (empty($conf->file->strict_mode)) { |
|
3815 | + $res=@include $tpl; |
|
3816 | + } else { |
|
3817 | + $res=include $tpl; // for debug |
|
3818 | + } |
|
3819 | + if ($res) break; |
|
3820 | + } |
|
3821 | + } |
|
3822 | + |
|
3823 | + |
|
3824 | + |
|
3825 | + /* This is to show array of line of details */ |
|
3826 | + |
|
3827 | + |
|
3828 | + /** |
|
3829 | + * Return HTML table for object lines |
|
3830 | + * TODO Move this into an output class file (htmlline.class.php) |
|
3831 | + * If lines are into a template, title must also be into a template |
|
3832 | + * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
3833 | + * |
|
3834 | + * @param string $action Action code |
|
3835 | + * @param string $seller Object of seller third party |
|
3836 | + * @param string $buyer Object of buyer third party |
|
3837 | + * @param int $selected Object line selected |
|
3838 | + * @param int $dateSelector 1=Show also date range input fields |
|
3839 | + * @return void |
|
3840 | + */ |
|
3841 | + function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
3842 | + { |
|
3843 | + global $conf, $hookmanager, $langs, $user; |
|
3844 | + // TODO We should not use global var for this ! |
|
3845 | + global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
|
3846 | + |
|
3847 | + // Define usemargins |
|
3848 | + $usemargins=0; |
|
3849 | + if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1; |
|
3850 | + |
|
3851 | + $num = count($this->lines); |
|
3852 | + |
|
3853 | + // Line extrafield |
|
3854 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
3855 | + $extrafieldsline = new ExtraFields($this->db); |
|
3856 | + $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
3857 | + |
|
3858 | + $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
3859 | + $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3860 | + if (empty($reshook)) |
|
3861 | + { |
|
3862 | + // Title line |
|
3863 | + print "<thead>\n"; |
|
3864 | + |
|
3865 | + print '<tr class="liste_titre nodrag nodrop">'; |
|
3866 | + |
|
3867 | + // Adds a line numbering column |
|
3868 | + if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
3869 | + |
|
3870 | + // Description |
|
3871 | + print '<td class="linecoldescription">'.$langs->trans('Description').'</td>'; |
|
3872 | + |
|
3873 | + if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') |
|
3874 | + { |
|
3875 | + print '<td class="linerefsupplier"><span id="title_fourn_ref">'.$langs->trans("SupplierRef").'</span></td>'; |
|
3876 | + } |
|
3877 | + |
|
3878 | + // VAT |
|
3879 | + print '<td class="linecolvat" align="right" width="80">'.$langs->trans('VAT').'</td>'; |
|
3880 | + |
|
3881 | + // Price HT |
|
3882 | + print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>'; |
|
3883 | + |
|
3884 | + // Multicurrency |
|
3885 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>'; |
|
3886 | + |
|
3887 | + if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>'; |
|
3888 | + |
|
3889 | + // Qty |
|
3890 | + print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>'; |
|
3891 | + |
|
3892 | + if($conf->global->PRODUCT_USE_UNITS) |
|
3893 | + { |
|
3894 | + print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>'; |
|
3895 | + } |
|
3896 | + |
|
3897 | + // Reduction short |
|
3898 | + print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>'; |
|
3899 | + |
|
3900 | + if ($this->situation_cycle_ref) { |
|
3901 | + print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>'; |
|
3902 | + } |
|
3903 | + |
|
3904 | + if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) |
|
3905 | + { |
|
3906 | + if (!empty($user->rights->margins->creer)) |
|
3907 | + { |
|
3908 | + if ($conf->global->MARGIN_TYPE == "1") |
|
3909 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>'; |
|
3910 | + else |
|
3911 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
|
3912 | + } |
|
3913 | + |
|
3914 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
3915 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>'; |
|
3916 | + if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
3917 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
|
3918 | + } |
|
3919 | + |
|
3920 | + // Total HT |
|
3921 | + print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>'; |
|
3922 | + |
|
3923 | + // Multicurrency |
|
3924 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>'; |
|
3925 | + |
|
3926 | + if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
|
3927 | + |
|
3928 | + print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
3929 | + |
|
3930 | + print '<td class="linecoldelete" width="10"></td>'; |
|
3931 | + |
|
3932 | + print '<td class="linecolmove" width="10"></td>'; |
|
3933 | + |
|
3934 | + if($action == 'selectlines') |
|
3935 | + { |
|
3936 | + print '<td class="linecolcheckall" align="center">'; |
|
3937 | + print '<input type="checkbox" class="linecheckboxtoggle" />'; |
|
3938 | + print '<script type="text/javascript">$(document).ready(function() {$(".linecheckboxtoggle").click(function() {var checkBoxes = $(".linecheckbox");checkBoxes.prop("checked", this.checked);})});</script>'; |
|
3939 | + print '</td>'; |
|
3940 | + } |
|
3941 | + |
|
3942 | + print "</tr>\n"; |
|
3943 | + print "</thead>\n"; |
|
3944 | + } |
|
3945 | + |
|
3946 | + $var = true; |
|
3947 | + $i = 0; |
|
3948 | + |
|
3949 | + print "<tbody>\n"; |
|
3950 | + foreach ($this->lines as $line) |
|
3951 | + { |
|
3952 | + //Line extrafield |
|
3953 | + $line->fetch_optionals(); |
|
3954 | + |
|
3955 | + //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
3956 | + if (is_object($hookmanager)) // Old code is commented on preceding line. |
|
3957 | + { |
|
3958 | + if (empty($line->fk_parent_line)) |
|
3959 | + { |
|
3960 | + $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
3961 | + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3962 | + } |
|
3963 | + else |
|
3964 | + { |
|
3965 | + $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); |
|
3966 | + $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3967 | + } |
|
3968 | + } |
|
3969 | + if (empty($reshook)) |
|
3970 | + { |
|
3971 | + $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
3972 | + } |
|
3973 | + |
|
3974 | + $i++; |
|
3975 | + } |
|
3976 | + print "</tbody>\n"; |
|
3977 | + } |
|
3978 | + |
|
3979 | + /** |
|
3980 | + * Return HTML content of a detail line |
|
3981 | + * TODO Move this into an output class file (htmlline.class.php) |
|
3982 | + * |
|
3983 | + * @param string $action GET/POST action |
|
3984 | + * @param CommonObjectLine $line Selected object line to output |
|
3985 | + * @param string $var Is it a an odd line (true) |
|
3986 | + * @param int $num Number of line (0) |
|
3987 | + * @param int $i I |
|
3988 | + * @param int $dateSelector 1=Show also date range input fields |
|
3989 | + * @param string $seller Object of seller third party |
|
3990 | + * @param string $buyer Object of buyer third party |
|
3991 | + * @param int $selected Object line selected |
|
3992 | + * @param int $extrafieldsline Object of extrafield line attribute |
|
3993 | + * @return void |
|
3994 | + */ |
|
3995 | + function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
3996 | + { |
|
3997 | + global $conf,$langs,$user,$object,$hookmanager; |
|
3998 | + global $form,$bc,$bcdd; |
|
3999 | + global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
4000 | + |
|
4001 | + $object_rights = $this->getRights(); |
|
4002 | + |
|
4003 | + $element=$this->element; |
|
4004 | + |
|
4005 | + $text=''; $description=''; $type=0; |
|
4006 | + |
|
4007 | + // Show product and description |
|
4008 | + $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
4009 | + // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
|
4010 | + if (! empty($line->date_start)) $type=1; // deprecated |
|
4011 | + if (! empty($line->date_end)) $type=1; // deprecated |
|
4012 | + |
|
4013 | + // Ligne en mode visu |
|
4014 | + if ($action != 'editline' || $selected != $line->id) |
|
4015 | + { |
|
4016 | + // Product |
|
4017 | + if ($line->fk_product > 0) |
|
4018 | + { |
|
4019 | + $product_static = new Product($this->db); |
|
4020 | + $product_static->fetch($line->fk_product); |
|
4021 | + |
|
4022 | + $product_static->ref = $line->ref; //can change ref in hook |
|
4023 | + $product_static->label = $line->label; //can change label in hook |
|
4024 | + $text=$product_static->getNomUrl(1); |
|
4025 | + |
|
4026 | + // Define output language and label |
|
4027 | + if (! empty($conf->global->MAIN_MULTILANGS)) |
|
4028 | + { |
|
4029 | + if (! is_object($this->thirdparty)) |
|
4030 | + { |
|
4031 | + dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); |
|
4032 | + return; |
|
4033 | + } |
|
4034 | + |
|
4035 | + $prod = new Product($this->db); |
|
4036 | + $prod->fetch($line->fk_product); |
|
4037 | + |
|
4038 | + $outputlangs = $langs; |
|
4039 | + $newlang=''; |
|
4040 | + if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
4041 | + if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer |
|
4042 | + if (! empty($newlang)) |
|
4043 | + { |
|
4044 | + $outputlangs = new Translate("",$conf); |
|
4045 | + $outputlangs->setDefaultLang($newlang); |
|
4046 | + } |
|
4047 | + |
|
4048 | + $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
4049 | + } |
|
4050 | + else |
|
4051 | + { |
|
4052 | + $label = $line->product_label; |
|
4053 | + } |
|
4054 | + |
|
4055 | + $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
4056 | + $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. |
|
4057 | + } |
|
4058 | + |
|
4059 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
4060 | + |
|
4061 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
4062 | + // Use global variables + $dateSelector + $seller and $buyer |
|
4063 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
4064 | + foreach($dirtpls as $reldir) |
|
4065 | + { |
|
4066 | + $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
|
4067 | + if (empty($conf->file->strict_mode)) { |
|
4068 | + $res=@include $tpl; |
|
4069 | + } else { |
|
4070 | + $res=include $tpl; // for debug |
|
4071 | + } |
|
4072 | + if ($res) break; |
|
4073 | + } |
|
4074 | + } |
|
4075 | + |
|
4076 | + // Ligne en mode update |
|
4077 | + if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
|
4078 | + { |
|
4079 | + $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
4080 | + $placeholder=' placeholder="'.$langs->trans("Label").'"'; |
|
4081 | + |
|
4082 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
4083 | + |
|
4084 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
4085 | + // Use global variables + $dateSelector + $seller and $buyer |
|
4086 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
4087 | + foreach($dirtpls as $reldir) |
|
4088 | + { |
|
4089 | + $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
|
4090 | + if (empty($conf->file->strict_mode)) { |
|
4091 | + $res=@include $tpl; |
|
4092 | + } else { |
|
4093 | + $res=include $tpl; // for debug |
|
4094 | + } |
|
4095 | + if ($res) break; |
|
4096 | + } |
|
4097 | + } |
|
4098 | + } |
|
4099 | + |
|
4100 | + |
|
4101 | + /* This is to show array of line of details of source object */ |
|
4102 | + |
|
4103 | + |
|
4104 | + /** |
|
4105 | + * Return HTML table table of source object lines |
|
4106 | + * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
4107 | + * If lines are into a template, title must also be into a template |
|
4108 | + * But for the moment we don't know if it's possible, so we keep the method available on overloaded objects. |
|
4109 | + * |
|
4110 | + * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
|
4111 | + * @return void |
|
4112 | + */ |
|
4113 | + function printOriginLinesList($restrictlist='') |
|
4114 | + { |
|
4115 | + global $langs, $hookmanager, $conf; |
|
4116 | + |
|
4117 | + print '<tr class="liste_titre">'; |
|
4118 | + print '<td>'.$langs->trans('Ref').'</td>'; |
|
4119 | + print '<td>'.$langs->trans('Description').'</td>'; |
|
4120 | + print '<td align="right">'.$langs->trans('VATRate').'</td>'; |
|
4121 | + print '<td align="right">'.$langs->trans('PriceUHT').'</td>'; |
|
4122 | + if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>'; |
|
4123 | + print '<td align="right">'.$langs->trans('Qty').'</td>'; |
|
4124 | + if($conf->global->PRODUCT_USE_UNITS) |
|
4125 | + { |
|
4126 | + print '<td align="left">'.$langs->trans('Unit').'</td>'; |
|
4127 | + } |
|
4128 | + print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>'; |
|
4129 | + |
|
4130 | + $var = true; |
|
4131 | + $i = 0; |
|
4132 | + |
|
4133 | + if (! empty($this->lines)) |
|
4134 | + { |
|
4135 | + foreach ($this->lines as $line) |
|
4136 | + { |
|
4137 | + if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
4138 | + { |
|
4139 | + if (empty($line->fk_parent_line)) |
|
4140 | + { |
|
4141 | + $parameters=array('line'=>$line,'var'=>$var,'i'=>$i); |
|
4142 | + $action=''; |
|
4143 | + $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
4144 | + } |
|
4145 | + } |
|
4146 | + else |
|
4147 | + { |
|
4148 | + $this->printOriginLine($line, $var, $restrictlist); |
|
4149 | + } |
|
4150 | + |
|
4151 | + $i++; |
|
4152 | + } |
|
4153 | + } |
|
4154 | + } |
|
4155 | + |
|
4156 | + /** |
|
4157 | + * Return HTML with a line of table array of source object lines |
|
4158 | + * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
4159 | + * If lines are into a template, title must also be into a template |
|
4160 | + * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
4161 | + * |
|
4162 | + * @param CommonObjectLine $line Line |
|
4163 | + * @param string $var Var |
|
4164 | + * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
|
4165 | + * @return void |
|
4166 | + */ |
|
4167 | + function printOriginLine($line, $var, $restrictlist='') |
|
4168 | + { |
|
4169 | + global $langs, $conf; |
|
4170 | + |
|
4171 | + //var_dump($line); |
|
4172 | + if (!empty($line->date_start)) |
|
4173 | + { |
|
4174 | + $date_start=$line->date_start; |
|
4175 | + } |
|
4176 | + else |
|
4177 | + { |
|
4178 | + $date_start=$line->date_debut_prevue; |
|
4179 | + if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
4180 | + } |
|
4181 | + if (!empty($line->date_end)) |
|
4182 | + { |
|
4183 | + $date_end=$line->date_end; |
|
4184 | + } |
|
4185 | + else |
|
4186 | + { |
|
4187 | + $date_end=$line->date_fin_prevue; |
|
4188 | + if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
4189 | + } |
|
4190 | + |
|
4191 | + $this->tpl['label'] = ''; |
|
4192 | + if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow'); |
|
4193 | + |
|
4194 | + if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
|
4195 | + { |
|
4196 | + $discount=new DiscountAbsolute($this->db); |
|
4197 | + $discount->fk_soc = $this->socid; |
|
4198 | + $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
4199 | + } |
|
4200 | + else if (! empty($line->fk_product)) |
|
4201 | + { |
|
4202 | + $productstatic = new Product($this->db); |
|
4203 | + $productstatic->id = $line->fk_product; |
|
4204 | + $productstatic->ref = $line->ref; |
|
4205 | + $productstatic->type = $line->fk_product_type; |
|
4206 | + if(empty($productstatic->ref)){ |
|
4207 | + $line->fetch_product(); |
|
4208 | + $productstatic = $line->product; |
|
4209 | + } |
|
4210 | + |
|
4211 | + $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
4212 | + $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
4213 | + // Dates |
|
4214 | + if ($line->product_type == 1 && ($date_start || $date_end)) |
|
4215 | + { |
|
4216 | + $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
4217 | + } |
|
4218 | + } |
|
4219 | + else |
|
4220 | + { |
|
4221 | + $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'))); |
|
4222 | + if (!empty($line->desc)) { |
|
4223 | + $this->tpl['label'].=$line->desc; |
|
4224 | + }else { |
|
4225 | + $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
4226 | + } |
|
4227 | + |
|
4228 | + // Dates |
|
4229 | + if ($line->product_type == 1 && ($date_start || $date_end)) |
|
4230 | + { |
|
4231 | + $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
4232 | + } |
|
4233 | + } |
|
4234 | + |
|
4235 | + if (! empty($line->desc)) |
|
4236 | + { |
|
4237 | + if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
|
4238 | + { |
|
4239 | + $discount=new DiscountAbsolute($this->db); |
|
4240 | + $discount->fetch($line->fk_remise_except); |
|
4241 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); |
|
4242 | + } |
|
4243 | + elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
|
4244 | + { |
|
4245 | + $discount=new DiscountAbsolute($this->db); |
|
4246 | + $discount->fetch($line->fk_remise_except); |
|
4247 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
|
4248 | + } |
|
4249 | + elseif ($line->desc == '(EXCESS RECEIVED)') |
|
4250 | + { |
|
4251 | + $discount=new DiscountAbsolute($this->db); |
|
4252 | + $discount->fetch($line->fk_remise_except); |
|
4253 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
|
4254 | + } |
|
4255 | + elseif ($line->desc == '(EXCESS PAID)') |
|
4256 | + { |
|
4257 | + $discount=new DiscountAbsolute($this->db); |
|
4258 | + $discount->fetch($line->fk_remise_except); |
|
4259 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0)); |
|
4260 | + } |
|
4261 | + else |
|
4262 | + { |
|
4263 | + $this->tpl['description'] = dol_trunc($line->desc,60); |
|
4264 | + } |
|
4265 | + } |
|
4266 | + else |
|
4267 | + { |
|
4268 | + $this->tpl['description'] = ' '; |
|
4269 | + } |
|
4270 | + |
|
4271 | + // VAT Rate |
|
4272 | + $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
|
4273 | + $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
|
4274 | + if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')'; |
|
4275 | + |
|
4276 | + $this->tpl['price'] = price($line->subprice); |
|
4277 | + $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
|
4278 | + $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; |
|
4279 | + if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long')); |
|
4280 | + $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
|
4281 | + |
|
4282 | + // Is the line strike or not |
|
4283 | + $this->tpl['strike']=0; |
|
4284 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
4285 | + |
|
4286 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
4287 | + // Use global variables + $dateSelector + $seller and $buyer |
|
4288 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
4289 | + foreach($dirtpls as $reldir) |
|
4290 | + { |
|
4291 | + $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
|
4292 | + if (empty($conf->file->strict_mode)) { |
|
4293 | + $res=@include $tpl; |
|
4294 | + } else { |
|
4295 | + $res=include $tpl; // for debug |
|
4296 | + } |
|
4297 | + if ($res) break; |
|
4298 | + } |
|
4299 | + } |
|
4300 | + |
|
4301 | + |
|
4302 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
4303 | + /** |
|
4304 | + * Add resources to the current object : add entry into llx_element_resources |
|
4305 | + * Need $this->element & $this->id |
|
4306 | + * |
|
4307 | + * @param int $resource_id Resource id |
|
4308 | + * @param string $resource_type 'resource' |
|
4309 | + * @param int $busy Busy or not |
|
4310 | + * @param int $mandatory Mandatory or not |
|
4311 | + * @return int <=0 if KO, >0 if OK |
|
4312 | + */ |
|
4313 | + function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
4314 | + { |
|
4315 | + // phpcs:enable |
|
4316 | + $this->db->begin(); |
|
4317 | + |
|
4318 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; |
|
4319 | + $sql.= "resource_id"; |
|
4320 | + $sql.= ", resource_type"; |
|
4321 | + $sql.= ", element_id"; |
|
4322 | + $sql.= ", element_type"; |
|
4323 | + $sql.= ", busy"; |
|
4324 | + $sql.= ", mandatory"; |
|
4325 | + $sql.= ") VALUES ("; |
|
4326 | + $sql.= $resource_id; |
|
4327 | + $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
4328 | + $sql.= ", '".$this->db->escape($this->id)."'"; |
|
4329 | + $sql.= ", '".$this->db->escape($this->element)."'"; |
|
4330 | + $sql.= ", '".$this->db->escape($busy)."'"; |
|
4331 | + $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
4332 | + $sql.= ")"; |
|
4333 | + |
|
4334 | + dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
|
4335 | + if ($this->db->query($sql)) |
|
4336 | + { |
|
4337 | + $this->db->commit(); |
|
4338 | + return 1; |
|
4339 | + } |
|
4340 | + else |
|
4341 | + { |
|
4342 | + $this->error=$this->db->lasterror(); |
|
4343 | + $this->db->rollback(); |
|
4344 | + return 0; |
|
4345 | + } |
|
4346 | + } |
|
4347 | + |
|
4348 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
4349 | + /** |
|
4350 | + * Delete a link to resource line |
|
4351 | + * |
|
4352 | + * @param int $rowid Id of resource line to delete |
|
4353 | + * @param int $element element name (for trigger) TODO: use $this->element into commonobject class |
|
4354 | + * @param int $notrigger Disable all triggers |
|
4355 | + * @return int >0 if OK, <0 if KO |
|
4356 | + */ |
|
4357 | + function delete_resource($rowid, $element, $notrigger=0) |
|
4358 | + { |
|
4359 | + // phpcs:enable |
|
4360 | + global $user; |
|
4361 | + |
|
4362 | + $this->db->begin(); |
|
4363 | + |
|
4364 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
|
4365 | + $sql.= " WHERE rowid=".$rowid; |
|
4366 | + |
|
4367 | + dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
|
4368 | + |
|
4369 | + $resql=$this->db->query($sql); |
|
4370 | + if (! $resql) |
|
4371 | + { |
|
4372 | + $this->error=$this->db->lasterror(); |
|
4373 | + $this->db->rollback(); |
|
4374 | + return -1; |
|
4375 | + } |
|
4376 | + else |
|
4377 | + { |
|
4378 | + if (! $notrigger) |
|
4379 | + { |
|
4380 | + $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
4381 | + if ($result < 0) { $this->db->rollback(); return -1; } |
|
4382 | + } |
|
4383 | + $this->db->commit(); |
|
4384 | + return 1; |
|
4385 | + } |
|
4386 | + } |
|
4387 | + |
|
4388 | + |
|
4389 | + /** |
|
4390 | + * Overwrite magic function to solve problem of cloning object that are kept as references |
|
4391 | + * |
|
4392 | + * @return void |
|
4393 | + */ |
|
4394 | + function __clone() |
|
4395 | + { |
|
4396 | + // Force a copy of this->lines, otherwise it will point to same object. |
|
4397 | + if (isset($this->lines) && is_array($this->lines)) |
|
4398 | + { |
|
4399 | + $nboflines=count($this->lines); |
|
4400 | + for($i=0; $i < $nboflines; $i++) |
|
4401 | + { |
|
4402 | + $this->lines[$i] = clone $this->lines[$i]; |
|
4403 | + } |
|
4404 | + } |
|
4405 | + } |
|
4406 | + |
|
4407 | + /** |
|
4408 | + * Common function for all objects extending CommonObject for generating documents |
|
4409 | + * |
|
4410 | + * @param string $modelspath Relative folder where generators are placed |
|
4411 | + * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example. |
|
4412 | + * @param Translate $outputlangs Output language to use |
|
4413 | + * @param int $hidedetails 1 to hide details. 0 by default |
|
4414 | + * @param int $hidedesc 1 to hide product description. 0 by default |
|
4415 | + * @param int $hideref 1 to hide product reference. 0 by default |
|
4416 | + * @param null|array $moreparams Array to provide more information |
|
4417 | + * @return int >0 if OK, <0 if KO |
|
4418 | + * @see addFileIntoDatabaseIndex |
|
4419 | + */ |
|
4420 | + protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
4421 | + { |
|
4422 | + global $conf, $langs, $user; |
|
4423 | + |
|
4424 | + $srctemplatepath=''; |
|
4425 | + |
|
4426 | + // Increase limit for PDF build |
|
4427 | + $err=error_reporting(); |
|
4428 | + error_reporting(0); |
|
4429 | + @set_time_limit(120); |
|
4430 | + error_reporting($err); |
|
4431 | + |
|
4432 | + // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
|
4433 | + $tmp=explode(':',$modele,2); |
|
4434 | + if (! empty($tmp[1])) |
|
4435 | + { |
|
4436 | + $modele=$tmp[0]; |
|
4437 | + $srctemplatepath=$tmp[1]; |
|
4438 | + } |
|
4439 | + |
|
4440 | + // Search template files |
|
4441 | + $file=''; $classname=''; $filefound=0; |
|
4442 | + $dirmodels=array('/'); |
|
4443 | + if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
4444 | + foreach($dirmodels as $reldir) |
|
4445 | + { |
|
4446 | + foreach(array('doc','pdf') as $prefix) |
|
4447 | + { |
|
4448 | + if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
4449 | + else $file = $prefix."_".$modele.".modules.php"; |
|
4450 | + |
|
4451 | + // On verifie l'emplacement du modele |
|
4452 | + $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
4453 | + if (file_exists($file)) |
|
4454 | + { |
|
4455 | + $filefound=1; |
|
4456 | + $classname=$prefix.'_'.$modele; |
|
4457 | + break; |
|
4458 | + } |
|
4459 | + } |
|
4460 | + if ($filefound) break; |
|
4461 | + } |
|
4462 | + |
|
4463 | + // If generator was found |
|
4464 | + if ($filefound) |
|
4465 | + { |
|
4466 | + global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
4467 | + |
|
4468 | + require_once $file; |
|
4469 | + |
|
4470 | + $obj = new $classname($this->db); |
|
4471 | + |
|
4472 | + // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
|
4473 | + if ($obj->type == 'odt' && empty($srctemplatepath)) |
|
4474 | + { |
|
4475 | + $varfortemplatedir=$obj->scandir; |
|
4476 | + if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) |
|
4477 | + { |
|
4478 | + $dirtoscan=$conf->global->$varfortemplatedir; |
|
4479 | + |
|
4480 | + $listoffiles=array(); |
|
4481 | + |
|
4482 | + // Now we add first model found in directories scanned |
|
4483 | + $listofdir=explode(',',$dirtoscan); |
|
4484 | + foreach($listofdir as $key => $tmpdir) |
|
4485 | + { |
|
4486 | + $tmpdir=trim($tmpdir); |
|
4487 | + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
4488 | + if (! $tmpdir) { unset($listofdir[$key]); continue; } |
|
4489 | + if (is_dir($tmpdir)) |
|
4490 | + { |
|
4491 | + $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
4492 | + if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
4493 | + } |
|
4494 | + } |
|
4495 | + |
|
4496 | + if (count($listoffiles)) |
|
4497 | + { |
|
4498 | + foreach($listoffiles as $record) |
|
4499 | + { |
|
4500 | + $srctemplatepath=$record['fullname']; |
|
4501 | + break; |
|
4502 | + } |
|
4503 | + } |
|
4504 | + } |
|
4505 | + |
|
4506 | + if (empty($srctemplatepath)) |
|
4507 | + { |
|
4508 | + $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
4509 | + return -1; |
|
4510 | + } |
|
4511 | + } |
|
4512 | + |
|
4513 | + if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
4514 | + { |
|
4515 | + if (! dol_is_file($srctemplatepath)) |
|
4516 | + { |
|
4517 | + $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
4518 | + return -1; |
|
4519 | + } |
|
4520 | + } |
|
4521 | + |
|
4522 | + // We save charset_output to restore it because write_file can change it if needed for |
|
4523 | + // output format that does not support UTF8. |
|
4524 | + $sav_charset_output=$outputlangs->charset_output; |
|
4525 | + |
|
4526 | + if (in_array(get_class($this), array('Adherent'))) |
|
4527 | + { |
|
4528 | + $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
4529 | + $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
|
4530 | + } |
|
4531 | + else |
|
4532 | + { |
|
4533 | + $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
4534 | + } |
|
4535 | + // After call of write_file $obj->result['fullpath'] is set with generated file. It will be used to update the ECM database index. |
|
4536 | + |
|
4537 | + if ($resultwritefile > 0) |
|
4538 | + { |
|
4539 | + $outputlangs->charset_output=$sav_charset_output; |
|
4540 | + |
|
4541 | + // We delete old preview |
|
4542 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
4543 | + dol_delete_preview($this); |
|
4544 | + |
|
4545 | + // Index file in database |
|
4546 | + if (! empty($obj->result['fullpath'])) |
|
4547 | + { |
|
4548 | + $destfull = $obj->result['fullpath']; |
|
4549 | + $upload_dir = dirname($destfull); |
|
4550 | + $destfile = basename($destfull); |
|
4551 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); |
|
4552 | + |
|
4553 | + if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
4554 | + { |
|
4555 | + $filename = basename($destfile); |
|
4556 | + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
|
4557 | + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
|
4558 | + |
|
4559 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
4560 | + $ecmfile=new EcmFiles($this->db); |
|
4561 | + $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
4562 | + |
|
4563 | + // Set the public "share" key |
|
4564 | + $setsharekey = false; |
|
4565 | + if ($this->element == 'propal') |
|
4566 | + { |
|
4567 | + $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
4568 | + if ($useonlinesignature) $setsharekey=true; |
|
4569 | + if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4570 | + } |
|
4571 | + if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4572 | + if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4573 | + if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4574 | + |
|
4575 | + if ($setsharekey) |
|
4576 | + { |
|
4577 | + if (empty($ecmfile->share)) // Because object not found or share not set yet |
|
4578 | + { |
|
4579 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
4580 | + $ecmfile->share = getRandomPassword(true); |
|
4581 | + } |
|
4582 | + } |
|
4583 | + |
|
4584 | + if ($result > 0) |
|
4585 | + { |
|
4586 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
4587 | + $ecmfile->fullpath_orig = ''; |
|
4588 | + $ecmfile->gen_or_uploaded = 'generated'; |
|
4589 | + $ecmfile->description = ''; // indexed content |
|
4590 | + $ecmfile->keyword = ''; // keyword content |
|
4591 | + $result = $ecmfile->update($user); |
|
4592 | + if ($result < 0) |
|
4593 | + { |
|
4594 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
4595 | + } |
|
4596 | + } |
|
4597 | + else |
|
4598 | + { |
|
4599 | + $ecmfile->entity = $conf->entity; |
|
4600 | + $ecmfile->filepath = $rel_dir; |
|
4601 | + $ecmfile->filename = $filename; |
|
4602 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
4603 | + $ecmfile->fullpath_orig = ''; |
|
4604 | + $ecmfile->gen_or_uploaded = 'generated'; |
|
4605 | + $ecmfile->description = ''; // indexed content |
|
4606 | + $ecmfile->keyword = ''; // keyword content |
|
4607 | + $ecmfile->src_object_type = $this->table_element; |
|
4608 | + $ecmfile->src_object_id = $this->id; |
|
4609 | + |
|
4610 | + $result = $ecmfile->create($user); |
|
4611 | + if ($result < 0) |
|
4612 | + { |
|
4613 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
4614 | + } |
|
4615 | + } |
|
4616 | + |
|
4617 | + /*$this->result['fullname']=$destfull; |
|
4618 | + $this->result['filepath']=$ecmfile->filepath; |
|
4619 | + $this->result['filename']=$ecmfile->filename;*/ |
|
4620 | + //var_dump($obj->update_main_doc_field);exit; |
|
4621 | + |
|
4622 | + // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
|
4623 | + $update_main_doc_field=0; |
|
4624 | + if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
4625 | + if ($update_main_doc_field && ! empty($this->table_element)) |
|
4626 | + { |
|
4627 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
|
4628 | + $sql.= ' WHERE rowid = '.$this->id; |
|
4629 | + $resql = $this->db->query($sql); |
|
4630 | + if (! $resql) dol_print_error($this->db); |
|
4631 | + } |
|
4632 | + } |
|
4633 | + } |
|
4634 | + else |
|
4635 | + { |
|
4636 | + dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING); |
|
4637 | + } |
|
4638 | + |
|
4639 | + // Success in building document. We build meta file. |
|
4640 | + dol_meta_create($this); |
|
4641 | + |
|
4642 | + return 1; |
|
4643 | + } |
|
4644 | + else |
|
4645 | + { |
|
4646 | + $outputlangs->charset_output=$sav_charset_output; |
|
4647 | + dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
|
4648 | + return -1; |
|
4649 | + } |
|
4650 | + } |
|
4651 | + else |
|
4652 | + { |
|
4653 | + $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
|
4654 | + dol_print_error('',$this->error); |
|
4655 | + return -1; |
|
4656 | + } |
|
4657 | + } |
|
4658 | + |
|
4659 | + /** |
|
4660 | + * Build thumb |
|
4661 | + * @TODO Move this into files.lib.php |
|
4662 | + * |
|
4663 | + * @param string $file Path file in UTF8 to original file to create thumbs from. |
|
4664 | + * @return void |
|
4665 | + */ |
|
4666 | + function addThumbs($file) |
|
4667 | + { |
|
4668 | + global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
|
4669 | + |
|
4670 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
4671 | + |
|
4672 | + $file_osencoded=dol_osencode($file); |
|
4673 | + if (file_exists($file_osencoded)) |
|
4674 | + { |
|
4675 | + // Create small thumbs for company (Ratio is near 16/9) |
|
4676 | + // Used on logon for example |
|
4677 | + vignette($file_osencoded, $maxwidthsmall, $maxheightsmall, '_small', $quality); |
|
4678 | + |
|
4679 | + // Create mini thumbs for company (Ratio is near 16/9) |
|
4680 | + // Used on menu or for setup page for example |
|
4681 | + vignette($file_osencoded, $maxwidthmini, $maxheightmini, '_mini', $quality); |
|
4682 | + } |
|
4683 | + } |
|
4684 | + |
|
4685 | + |
|
4686 | + /* Functions common to commonobject and commonobjectline */ |
|
4687 | + |
|
4688 | + /* For default values */ |
|
4689 | + |
|
4690 | + /** |
|
4691 | + * Return the default value to use for a field when showing the create form of object. |
|
4692 | + * Return values in this order: |
|
4693 | + * 1) If parameter is available into POST, we return it first. |
|
4694 | + * 2) If not but an alternate value was provided as parameter of function, we return it. |
|
4695 | + * 3) If not but a constant $conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table). |
|
4696 | + * 4) Return value found into database (TODO No yet implemented) |
|
4697 | + * |
|
4698 | + * @param string $fieldname Name of field |
|
4699 | + * @param string $alternatevalue Alternate value to use |
|
4700 | + * @return string|string[] Default value (can be an array if the GETPOST return an array) |
|
4701 | + **/ |
|
4702 | + function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
4703 | + { |
|
4704 | + global $conf, $_POST; |
|
4705 | + |
|
4706 | + // If param here has been posted, we use this value first. |
|
4707 | + if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); |
|
4708 | + |
|
4709 | + if (isset($alternatevalue)) return $alternatevalue; |
|
4710 | + |
|
4711 | + $newelement=$this->element; |
|
4712 | + if ($newelement == 'facture') $newelement='invoice'; |
|
4713 | + if ($newelement == 'commande') $newelement='order'; |
|
4714 | + if (empty($newelement)) |
|
4715 | + { |
|
4716 | + dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING); |
|
4717 | + return ''; |
|
4718 | + } |
|
4719 | + |
|
4720 | + $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
4721 | + //var_dump($keyforfieldname); |
|
4722 | + if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
|
4723 | + |
|
4724 | + // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname |
|
4725 | + } |
|
4726 | + |
|
4727 | + |
|
4728 | + /* For triggers */ |
|
4729 | + |
|
4730 | + |
|
4731 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
4732 | + /** |
|
4733 | + * Call trigger based on this instance. |
|
4734 | + * Some context information may also be provided into array property this->context. |
|
4735 | + * NB: Error from trigger are stacked in interface->errors |
|
4736 | + * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. |
|
4737 | + * |
|
4738 | + * @param string $trigger_name trigger's name to execute |
|
4739 | + * @param User $user Object user |
|
4740 | + * @return int Result of run_triggers |
|
4741 | + */ |
|
4742 | + function call_trigger($trigger_name, $user) |
|
4743 | + { |
|
4744 | + // phpcs:enable |
|
4745 | + global $langs,$conf; |
|
4746 | + |
|
4747 | + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
4748 | + $interface=new Interfaces($this->db); |
|
4749 | + $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
4750 | + |
|
4751 | + if ($result < 0) |
|
4752 | + { |
|
4753 | + if (!empty($this->errors)) |
|
4754 | + { |
|
4755 | + $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 | + } |
|
4757 | + else |
|
4758 | + { |
|
4759 | + $this->errors=$interface->errors; |
|
4760 | + } |
|
4761 | + } |
|
4762 | + return $result; |
|
4763 | + } |
|
4764 | + |
|
4765 | + |
|
4766 | + /* Functions for extrafields */ |
|
4767 | + |
|
4768 | + |
|
4769 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
4770 | + /** |
|
4771 | + * Function to get extra fields of an object into $this->array_options |
|
4772 | + * This method is in most cases called by method fetch of objects but you can call it separately. |
|
4773 | + * |
|
4774 | + * @param int $rowid Id of line. Use the id of object if not defined. Deprecated. Function must be called without parameters. |
|
4775 | + * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
|
4776 | + * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
|
4777 | + */ |
|
4778 | + function fetch_optionals($rowid=null, $optionsArray=null) |
|
4779 | + { |
|
4780 | + // phpcs:enable |
|
4781 | + if (empty($rowid)) $rowid=$this->id; |
|
4782 | + |
|
4783 | + // To avoid SQL errors. Probably not the better solution though |
|
4784 | + if (!$this->table_element) { |
|
4785 | + return 0; |
|
4786 | + } |
|
4787 | + |
|
4788 | + $this->array_options=array(); |
|
4789 | + |
|
4790 | + if (! is_array($optionsArray)) |
|
4791 | + { |
|
4792 | + // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
|
4793 | + // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
|
4794 | + // global $extrafields; |
|
4795 | + //if (! is_object($extrafields)) |
|
4796 | + //{ |
|
4797 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
4798 | + $extrafields = new ExtraFields($this->db); |
|
4799 | + //} |
|
4800 | + |
|
4801 | + // Load array of extrafields for elementype = $this->table_element |
|
4802 | + if (empty($extrafields->attributes[$this->table_element]['loaded'])) |
|
4803 | + { |
|
4804 | + $extrafields->fetch_name_optionals_label($this->table_element); |
|
4805 | + } |
|
4806 | + $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
|
4807 | + } |
|
4808 | + else |
|
4809 | + { |
|
4810 | + global $extrafields; |
|
4811 | + dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING); |
|
4812 | + } |
|
4813 | + |
|
4814 | + $table_element = $this->table_element; |
|
4815 | + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
4816 | + |
|
4817 | + // Request to get complementary values |
|
4818 | + if (is_array($optionsArray) && count($optionsArray) > 0) |
|
4819 | + { |
|
4820 | + $sql = "SELECT rowid"; |
|
4821 | + foreach ($optionsArray as $name => $label) |
|
4822 | + { |
|
4823 | + if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
|
4824 | + { |
|
4825 | + $sql.= ", ".$name; |
|
4826 | + } |
|
4827 | + } |
|
4828 | + $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
4829 | + $sql.= " WHERE fk_object = ".$rowid; |
|
4830 | + |
|
4831 | + //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
|
4832 | + $resql=$this->db->query($sql); |
|
4833 | + if ($resql) |
|
4834 | + { |
|
4835 | + $this->array_options = array(); |
|
4836 | + $numrows=$this->db->num_rows($resql); |
|
4837 | + if ($numrows) |
|
4838 | + { |
|
4839 | + $tab = $this->db->fetch_array($resql); |
|
4840 | + |
|
4841 | + foreach ($tab as $key => $value) |
|
4842 | + { |
|
4843 | + // 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) |
|
4844 | + if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
4845 | + { |
|
4846 | + // we can add this attribute to object |
|
4847 | + if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime'))) |
|
4848 | + { |
|
4849 | + //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
|
4850 | + $this->array_options["options_".$key]=$this->db->jdate($value); |
|
4851 | + } |
|
4852 | + else |
|
4853 | + { |
|
4854 | + $this->array_options["options_".$key]=$value; |
|
4855 | + } |
|
4856 | + |
|
4857 | + //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]); |
|
4858 | + } |
|
4859 | + } |
|
4860 | + } |
|
4861 | + |
|
4862 | + $this->db->free($resql); |
|
4863 | + |
|
4864 | + if ($numrows) return $numrows; |
|
4865 | + else return 0; |
|
4866 | + } |
|
4867 | + else |
|
4868 | + { |
|
4869 | + dol_print_error($this->db); |
|
4870 | + return -1; |
|
4871 | + } |
|
4872 | + } |
|
4873 | + return 0; |
|
4874 | + } |
|
4875 | + |
|
4876 | + /** |
|
4877 | + * Delete all extra fields values for the current object. |
|
4878 | + * |
|
4879 | + * @return int <0 if KO, >0 if OK |
|
4880 | + */ |
|
4881 | + function deleteExtraFields() |
|
4882 | + { |
|
4883 | + $this->db->begin(); |
|
4884 | + |
|
4885 | + $table_element = $this->table_element; |
|
4886 | + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
4887 | + |
|
4888 | + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
4889 | + dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
|
4890 | + $resql=$this->db->query($sql_del); |
|
4891 | + if (! $resql) |
|
4892 | + { |
|
4893 | + $this->error=$this->db->lasterror(); |
|
4894 | + $this->db->rollback(); |
|
4895 | + return -1; |
|
4896 | + } |
|
4897 | + else |
|
4898 | + { |
|
4899 | + $this->db->commit(); |
|
4900 | + return 1; |
|
4901 | + } |
|
4902 | + } |
|
4903 | + |
|
4904 | + /** |
|
4905 | + * Add/Update all extra fields values for the current object. |
|
4906 | + * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) |
|
4907 | + * This function delete record with all extrafields and insert them again from the array $this->array_options. |
|
4908 | + * |
|
4909 | + * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
4910 | + * @param User $userused Object user |
|
4911 | + * @return int -1=error, O=did nothing, 1=OK |
|
4912 | + * @see updateExtraField, setValueFrom |
|
4913 | + */ |
|
4914 | + function insertExtraFields($trigger='', $userused=null) |
|
4915 | + { |
|
4916 | + global $conf,$langs,$user; |
|
4917 | + |
|
4918 | + if (empty($userused)) $userused=$user; |
|
4919 | + |
|
4920 | + $error=0; |
|
4921 | + |
|
4922 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
4923 | + |
|
4924 | + if (! empty($this->array_options)) |
|
4925 | + { |
|
4926 | + // Check parameters |
|
4927 | + $langs->load('admin'); |
|
4928 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
4929 | + $extrafields = new ExtraFields($this->db); |
|
4930 | + $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
4931 | + |
|
4932 | + //Eliminate copied source object extra_fields that do not exist in target object |
|
4933 | + $new_array_options=array(); |
|
4934 | + foreach ($this->array_options as $key => $value) { |
|
4935 | + if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
4936 | + $new_array_options[$key] = $value; |
|
4937 | + elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
|
4938 | + $new_array_options['options_'.$key] = $value; |
|
4939 | + } |
|
4940 | + |
|
4941 | + foreach($new_array_options as $key => $value) |
|
4942 | + { |
|
4943 | + $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
4944 | + $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
|
4945 | + $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
|
4946 | + $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
|
4947 | + $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey]; |
|
4948 | + |
|
4949 | + if ($attributeRequired) |
|
4950 | + { |
|
4951 | + $mandatorypb=false; |
|
4952 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
4953 | + if ($this->array_options[$key] === '') $mandatorypb=true; |
|
4954 | + if ($mandatorypb) |
|
4955 | + { |
|
4956 | + dol_syslog($this->error); |
|
4957 | + $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel); |
|
4958 | + return -1; |
|
4959 | + } |
|
4960 | + } |
|
4961 | + |
|
4962 | + //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); |
|
4963 | + //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); |
|
4964 | + |
|
4965 | + switch ($attributeType) |
|
4966 | + { |
|
4967 | + case 'int': |
|
4968 | + if (!is_numeric($value) && $value!='') |
|
4969 | + { |
|
4970 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
4971 | + return -1; |
|
4972 | + } |
|
4973 | + elseif ($value=='') |
|
4974 | + { |
|
4975 | + $new_array_options[$key] = null; |
|
4976 | + } |
|
4977 | + break; |
|
4978 | + case 'double': |
|
4979 | + $value = price2num($value); |
|
4980 | + if (!is_numeric($value) && $value!='') |
|
4981 | + { |
|
4982 | + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
|
4983 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
4984 | + return -1; |
|
4985 | + } |
|
4986 | + elseif ($value=='') |
|
4987 | + { |
|
4988 | + $new_array_options[$key] = null; |
|
4989 | + } |
|
4990 | + //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG); |
|
4991 | + $new_array_options[$key] = $value; |
|
4992 | + break; |
|
4993 | + /*case 'select': // Not required, we chosed value='0' for undefined values |
|
4994 | + if ($value=='-1') |
|
4995 | + { |
|
4996 | + $this->array_options[$key] = null; |
|
4997 | + } |
|
4998 | + break;*/ |
|
4999 | + case 'password': |
|
5000 | + $algo=''; |
|
5001 | + if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
|
5002 | + { |
|
5003 | + // If there is an encryption choice, we use it to crypt data before insert |
|
5004 | + $tmparrays = array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options']); |
|
5005 | + $algo=reset($tmparrays); |
|
5006 | + if ($algo != '') |
|
5007 | + { |
|
5008 | + //global $action; // $action may be 'create', 'update', 'update_extras'... |
|
5009 | + //var_dump($action); |
|
5010 | + //var_dump($this->oldcopy);exit; |
|
5011 | + if (is_object($this->oldcopy)) // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value |
|
5012 | + { |
|
5013 | + //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
|
5014 | + 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. |
|
5015 | + { |
|
5016 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
5017 | + } |
|
5018 | + else |
|
5019 | + { |
|
5020 | + // var_dump($algo); |
|
5021 | + $newvalue = dol_hash($this->array_options[$key], $algo); |
|
5022 | + $new_array_options[$key] = $newvalue; |
|
5023 | + } |
|
5024 | + } |
|
5025 | + else |
|
5026 | + { |
|
5027 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
5028 | + } |
|
5029 | + } |
|
5030 | + } |
|
5031 | + else // Common usage |
|
5032 | + { |
|
5033 | + $new_array_options[$key] = $this->array_options[$key]; |
|
5034 | + } |
|
5035 | + break; |
|
5036 | + case 'price': |
|
5037 | + $new_array_options[$key] = price2num($this->array_options[$key]); |
|
5038 | + break; |
|
5039 | + case 'date': |
|
5040 | + $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
5041 | + break; |
|
5042 | + case 'datetime': |
|
5043 | + // If data is a string instead of a timestamp, we convert it |
|
5044 | + if (! is_int($this->array_options[$key])) { |
|
5045 | + $this->array_options[$key] = strtotime($this->array_options[$key]); |
|
5046 | + } |
|
5047 | + $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
5048 | + break; |
|
5049 | + case 'link': |
|
5050 | + $param_list=array_keys($attributeParam['options']); |
|
5051 | + // 0 : ObjectName |
|
5052 | + // 1 : classPath |
|
5053 | + $InfoFieldList = explode(":", $param_list[0]); |
|
5054 | + dol_include_once($InfoFieldList[1]); |
|
5055 | + if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) |
|
5056 | + { |
|
5057 | + if ($value == '-1') // -1 is key for no defined in combo list of objects |
|
5058 | + { |
|
5059 | + $new_array_options[$key]=''; |
|
5060 | + } |
|
5061 | + elseif ($value) |
|
5062 | + { |
|
5063 | + $object = new $InfoFieldList[0]($this->db); |
|
5064 | + if (is_numeric($value)) $res=$object->fetch($value); |
|
5065 | + else $res=$object->fetch('',$value); |
|
5066 | + |
|
5067 | + if ($res > 0) $new_array_options[$key]=$object->id; |
|
5068 | + else |
|
5069 | + { |
|
5070 | + $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
5071 | + $this->db->rollback(); |
|
5072 | + return -1; |
|
5073 | + } |
|
5074 | + } |
|
5075 | + } |
|
5076 | + else |
|
5077 | + { |
|
5078 | + dol_syslog('Error bad setup of extrafield', LOG_WARNING); |
|
5079 | + } |
|
5080 | + break; |
|
5081 | + } |
|
5082 | + } |
|
5083 | + |
|
5084 | + $this->db->begin(); |
|
5085 | + |
|
5086 | + $table_element = $this->table_element; |
|
5087 | + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
5088 | + |
|
5089 | + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
5090 | + dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
|
5091 | + $this->db->query($sql_del); |
|
5092 | + |
|
5093 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
|
5094 | + foreach($new_array_options as $key => $value) |
|
5095 | + { |
|
5096 | + $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
5097 | + // Add field of attribut |
|
5098 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
|
5099 | + $sql.=",".$attributeKey; |
|
5100 | + } |
|
5101 | + $sql .= ") VALUES (".$this->id; |
|
5102 | + |
|
5103 | + foreach($new_array_options as $key => $value) |
|
5104 | + { |
|
5105 | + $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
5106 | + // Add field of attribute |
|
5107 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
|
5108 | + { |
|
5109 | + if ($new_array_options[$key] != '') |
|
5110 | + { |
|
5111 | + $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
5112 | + } |
|
5113 | + else |
|
5114 | + { |
|
5115 | + $sql.=",null"; |
|
5116 | + } |
|
5117 | + } |
|
5118 | + } |
|
5119 | + $sql.=")"; |
|
5120 | + |
|
5121 | + dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
|
5122 | + $resql = $this->db->query($sql); |
|
5123 | + if (! $resql) |
|
5124 | + { |
|
5125 | + $this->error=$this->db->lasterror(); |
|
5126 | + $error++; |
|
5127 | + } |
|
5128 | + |
|
5129 | + if (! $error && $trigger) |
|
5130 | + { |
|
5131 | + // Call trigger |
|
5132 | + $this->context=array('extrafieldaddupdate'=>1); |
|
5133 | + $result=$this->call_trigger($trigger, $userused); |
|
5134 | + if ($result < 0) $error++; |
|
5135 | + // End call trigger |
|
5136 | + } |
|
5137 | + |
|
5138 | + if ($error) |
|
5139 | + { |
|
5140 | + $this->db->rollback(); |
|
5141 | + return -1; |
|
5142 | + } |
|
5143 | + else |
|
5144 | + { |
|
5145 | + $this->db->commit(); |
|
5146 | + return 1; |
|
5147 | + } |
|
5148 | + } |
|
5149 | + else return 0; |
|
5150 | + } |
|
5151 | + |
|
5152 | + /** |
|
5153 | + * Update an extra field value for the current object. |
|
5154 | + * Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) |
|
5155 | + * |
|
5156 | + * @param string $key Key of the extrafield (without starting 'options_') |
|
5157 | + * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
5158 | + * @param User $userused Object user |
|
5159 | + * @return int -1=error, O=did nothing, 1=OK |
|
5160 | + * @see setValueFrom, insertExtraFields |
|
5161 | + */ |
|
5162 | + function updateExtraField($key, $trigger=null, $userused=null) |
|
5163 | + { |
|
5164 | + global $conf,$langs,$user; |
|
5165 | + |
|
5166 | + if (empty($userused)) $userused=$user; |
|
5167 | + |
|
5168 | + $error=0; |
|
5169 | + |
|
5170 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
5171 | + |
|
5172 | + if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
5173 | + { |
|
5174 | + // Check parameters |
|
5175 | + $langs->load('admin'); |
|
5176 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
5177 | + $extrafields = new ExtraFields($this->db); |
|
5178 | + $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
5179 | + |
|
5180 | + $value=$this->array_options["options_".$key]; |
|
5181 | + |
|
5182 | + $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
|
5183 | + $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
|
5184 | + $attributeParam = $extrafields->attributes[$this->table_element]['param'][$key]; |
|
5185 | + $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$key]; |
|
5186 | + |
|
5187 | + //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); |
|
5188 | + //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); |
|
5189 | + |
|
5190 | + switch ($attributeType) |
|
5191 | + { |
|
5192 | + case 'int': |
|
5193 | + if (!is_numeric($value) && $value!='') |
|
5194 | + { |
|
5195 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); |
|
5196 | + return -1; |
|
5197 | + } |
|
5198 | + elseif ($value=='') |
|
5199 | + { |
|
5200 | + $this->array_options["options_".$key] = null; |
|
5201 | + } |
|
5202 | + break; |
|
5203 | + case 'double': |
|
5204 | + $value = price2num($value); |
|
5205 | + if (!is_numeric($value) && $value!='') |
|
5206 | + { |
|
5207 | + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
|
5208 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
5209 | + return -1; |
|
5210 | + } |
|
5211 | + elseif ($value=='') |
|
5212 | + { |
|
5213 | + $this->array_options["options_".$key] = null; |
|
5214 | + } |
|
5215 | + //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG); |
|
5216 | + $this->array_options["options_".$key] = $value; |
|
5217 | + break; |
|
5218 | + /*case 'select': // Not required, we chosed value='0' for undefined values |
|
5219 | + if ($value=='-1') |
|
5220 | + { |
|
5221 | + $this->array_options[$key] = null; |
|
5222 | + } |
|
5223 | + break;*/ |
|
5224 | + case 'price': |
|
5225 | + $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
|
5226 | + break; |
|
5227 | + case 'date': |
|
5228 | + $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
5229 | + break; |
|
5230 | + case 'datetime': |
|
5231 | + $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
5232 | + break; |
|
5233 | + case 'link': |
|
5234 | + $param_list=array_keys($attributeParam['options']); |
|
5235 | + // 0 : ObjectName |
|
5236 | + // 1 : classPath |
|
5237 | + $InfoFieldList = explode(":", $param_list[0]); |
|
5238 | + dol_include_once($InfoFieldList[1]); |
|
5239 | + if ($value) |
|
5240 | + { |
|
5241 | + $object = new $InfoFieldList[0]($this->db); |
|
5242 | + $object->fetch(0,$value); |
|
5243 | + $this->array_options["options_".$key]=$object->id; |
|
5244 | + } |
|
5245 | + break; |
|
5246 | + } |
|
5247 | + |
|
5248 | + $this->db->begin(); |
|
5249 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
|
5250 | + $sql .= " WHERE fk_object = ".$this->id; |
|
5251 | + $resql = $this->db->query($sql); |
|
5252 | + if (! $resql) |
|
5253 | + { |
|
5254 | + $error++; |
|
5255 | + $this->error=$this->db->lasterror(); |
|
5256 | + } |
|
5257 | + |
|
5258 | + if (! $error && $trigger) |
|
5259 | + { |
|
5260 | + // Call trigger |
|
5261 | + $this->context=array('extrafieldupdate'=>1); |
|
5262 | + $result=$this->call_trigger($trigger, $userused); |
|
5263 | + if ($result < 0) $error++; |
|
5264 | + // End call trigger |
|
5265 | + } |
|
5266 | + |
|
5267 | + if ($error) |
|
5268 | + { |
|
5269 | + dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
|
5270 | + $this->db->rollback(); |
|
5271 | + return -1; |
|
5272 | + } |
|
5273 | + else |
|
5274 | + { |
|
5275 | + $this->db->commit(); |
|
5276 | + return 1; |
|
5277 | + } |
|
5278 | + } |
|
5279 | + else return 0; |
|
5280 | + } |
|
5281 | + |
|
5282 | + |
|
5283 | + /** |
|
5284 | + * Return HTML string to put an input field into a page |
|
5285 | + * Code very similar with showInputField of extra fields |
|
5286 | + * |
|
5287 | + * @param array $val Array of properties for field to show |
|
5288 | + * @param string $key Key of attribute |
|
5289 | + * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) |
|
5290 | + * @param string $moreparam To add more parameters on html input tag |
|
5291 | + * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
5292 | + * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
5293 | + * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. |
|
5294 | + * @return string |
|
5295 | + */ |
|
5296 | + function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0) |
|
5297 | + { |
|
5298 | + global $conf,$langs,$form; |
|
5299 | + |
|
5300 | + if (! is_object($form)) |
|
5301 | + { |
|
5302 | + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
5303 | + $form=new Form($this->db); |
|
5304 | + } |
|
5305 | + |
|
5306 | + $val=$this->fields[$key]; |
|
5307 | + |
|
5308 | + $out=''; |
|
5309 | + $type=''; |
|
5310 | + $param = array(); |
|
5311 | + $param['options']=array(); |
|
5312 | + $size =$this->fields[$key]['size']; |
|
5313 | + // Because we work on extrafields |
|
5314 | + if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){ |
|
5315 | + $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
5316 | + $type ='link'; |
|
5317 | + } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) { |
|
5318 | + $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
5319 | + $type ='link'; |
|
5320 | + } elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) { |
|
5321 | + $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
5322 | + $type ='sellist'; |
|
5323 | + } elseif(preg_match('/varchar\((\d+)\)/', $val['type'],$reg)) { |
|
5324 | + $param['options']=array(); |
|
5325 | + $type ='varchar'; |
|
5326 | + $size=$reg[1]; |
|
5327 | + } elseif(preg_match('/varchar/', $val['type'])) { |
|
5328 | + $param['options']=array(); |
|
5329 | + $type ='varchar'; |
|
5330 | + } elseif(is_array($this->fields[$key]['arrayofkeyval'])) { |
|
5331 | + $param['options']=$this->fields[$key]['arrayofkeyval']; |
|
5332 | + $type ='select'; |
|
5333 | + } else { |
|
5334 | + $param['options']=array(); |
|
5335 | + $type =$this->fields[$key]['type']; |
|
5336 | + } |
|
5337 | + |
|
5338 | + $label=$this->fields[$key]['label']; |
|
5339 | + //$elementtype=$this->fields[$key]['elementtype']; // Seems not used |
|
5340 | + $default=$this->fields[$key]['default']; |
|
5341 | + $computed=$this->fields[$key]['computed']; |
|
5342 | + $unique=$this->fields[$key]['unique']; |
|
5343 | + $required=$this->fields[$key]['required']; |
|
5344 | + |
|
5345 | + $langfile=$this->fields[$key]['langfile']; |
|
5346 | + $list=$this->fields[$key]['list']; |
|
5347 | + $hidden=abs($this->fields[$key]['visible'])!=1?1:0; |
|
5348 | + |
|
5349 | + $objectid = $this->id; |
|
5350 | + |
|
5351 | + |
|
5352 | + if ($computed) |
|
5353 | + { |
|
5354 | + if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
5355 | + else return ''; |
|
5356 | + } |
|
5357 | + |
|
5358 | + |
|
5359 | + // Use in priority showsize from parameters, then $val['css'] then autodefine |
|
5360 | + if (empty($morecss) && ! empty($val['css'])) |
|
5361 | + { |
|
5362 | + $showsize = $val['css']; |
|
5363 | + } |
|
5364 | + if (empty($morecss)) |
|
5365 | + { |
|
5366 | + if ($type == 'date') |
|
5367 | + { |
|
5368 | + $morecss = 'minwidth100imp'; |
|
5369 | + } |
|
5370 | + elseif ($type == 'datetime') |
|
5371 | + { |
|
5372 | + $morecss = 'minwidth200imp'; |
|
5373 | + } |
|
5374 | + elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
5375 | + { |
|
5376 | + $morecss = 'maxwidth75'; |
|
5377 | + }elseif ($type == 'url') |
|
5378 | + { |
|
5379 | + $morecss='minwidth400'; |
|
5380 | + } |
|
5381 | + elseif ($type == 'boolean') |
|
5382 | + { |
|
5383 | + $morecss=''; |
|
5384 | + } |
|
5385 | + else |
|
5386 | + { |
|
5387 | + if (round($size) < 12) |
|
5388 | + { |
|
5389 | + $morecss = 'minwidth100'; |
|
5390 | + } |
|
5391 | + else if (round($size) <= 48) |
|
5392 | + { |
|
5393 | + $morecss = 'minwidth200'; |
|
5394 | + } |
|
5395 | + else |
|
5396 | + { |
|
5397 | + $morecss = 'minwidth400'; |
|
5398 | + } |
|
5399 | + } |
|
5400 | + } |
|
5401 | + |
|
5402 | + if (in_array($type,array('date','datetime'))) |
|
5403 | + { |
|
5404 | + $tmp=explode(',',$size); |
|
5405 | + $newsize=$tmp[0]; |
|
5406 | + |
|
5407 | + $showtime = in_array($type,array('datetime')) ? 1 : 0; |
|
5408 | + |
|
5409 | + // Do not show current date when field not required (see selectDate() method) |
|
5410 | + if (!$required && $value == '') $value = '-1'; |
|
5411 | + |
|
5412 | + // TODO Must also support $moreparam |
|
5413 | + $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
|
5414 | + } |
|
5415 | + elseif (in_array($type,array('int','integer'))) |
|
5416 | + { |
|
5417 | + $tmp=explode(',',$size); |
|
5418 | + $newsize=$tmp[0]; |
|
5419 | + $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:'').'>'; |
|
5420 | + } |
|
5421 | + elseif (preg_match('/varchar/', $type)) |
|
5422 | + { |
|
5423 | + $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 | + } |
|
5425 | + elseif (in_array($type, array('mail', 'phone', 'url'))) |
|
5426 | + { |
|
5427 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
5428 | + } |
|
5429 | + elseif ($type == 'text') |
|
5430 | + { |
|
5431 | + if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
5432 | + { |
|
5433 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
5434 | + $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
5435 | + $out=$doleditor->Create(1); |
|
5436 | + } |
|
5437 | + else |
|
5438 | + { |
|
5439 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
5440 | + } |
|
5441 | + } |
|
5442 | + elseif ($type == 'html') |
|
5443 | + { |
|
5444 | + if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
5445 | + { |
|
5446 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
5447 | + $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%'); |
|
5448 | + $out=$doleditor->Create(1); |
|
5449 | + } |
|
5450 | + else |
|
5451 | + { |
|
5452 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
5453 | + } |
|
5454 | + } |
|
5455 | + elseif ($type == 'boolean') |
|
5456 | + { |
|
5457 | + $checked=''; |
|
5458 | + if (!empty($value)) { |
|
5459 | + $checked=' checked value="1" '; |
|
5460 | + } else { |
|
5461 | + $checked=' value="1" '; |
|
5462 | + } |
|
5463 | + $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
5464 | + } |
|
5465 | + elseif ($type == 'price') |
|
5466 | + { |
|
5467 | + if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
|
5468 | + $value=price($value); |
|
5469 | + } |
|
5470 | + $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 | + } |
|
5472 | + elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
5473 | + { |
|
5474 | + if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
|
5475 | + $value=price($value); |
|
5476 | + } |
|
5477 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
5478 | + } |
|
5479 | + elseif ($type == 'select') |
|
5480 | + { |
|
5481 | + $out = ''; |
|
5482 | + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
5483 | + { |
|
5484 | + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
5485 | + $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
5486 | + } |
|
5487 | + |
|
5488 | + $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
5489 | + if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
5490 | + foreach ($param['options'] as $key => $val) |
|
5491 | + { |
|
5492 | + if ((string) $key == '') continue; |
|
5493 | + list($val, $parent) = explode('|', $val); |
|
5494 | + $out.='<option value="'.$key.'"'; |
|
5495 | + $out.= (((string) $value == (string) $key)?' selected':''); |
|
5496 | + $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
5497 | + $out.='>'.$val.'</option>'; |
|
5498 | + } |
|
5499 | + $out.='</select>'; |
|
5500 | + } |
|
5501 | + elseif ($type == 'sellist') |
|
5502 | + { |
|
5503 | + $out = ''; |
|
5504 | + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
5505 | + { |
|
5506 | + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
5507 | + $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
5508 | + } |
|
5509 | + |
|
5510 | + $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
5511 | + if (is_array($param['options'])) |
|
5512 | + { |
|
5513 | + $param_list=array_keys($param['options']); |
|
5514 | + $InfoFieldList = explode(":", $param_list[0]); |
|
5515 | + $parentName=''; |
|
5516 | + $parentField=''; |
|
5517 | + // 0 : tableName |
|
5518 | + // 1 : label field name |
|
5519 | + // 2 : key fields name (if differ of rowid) |
|
5520 | + // 3 : key field parent (for dependent lists) |
|
5521 | + // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
5522 | + $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
5523 | + |
|
5524 | + |
|
5525 | + if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
5526 | + { |
|
5527 | + if (strpos($InfoFieldList[4], 'extra.') !== false) |
|
5528 | + { |
|
5529 | + $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
5530 | + } else { |
|
5531 | + $keyList=$InfoFieldList[2].' as rowid'; |
|
5532 | + } |
|
5533 | + } |
|
5534 | + if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
5535 | + { |
|
5536 | + list($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
|
5537 | + $keyList.= ', '.$parentField; |
|
5538 | + } |
|
5539 | + |
|
5540 | + $fields_label = explode('|',$InfoFieldList[1]); |
|
5541 | + if (is_array($fields_label)) |
|
5542 | + { |
|
5543 | + $keyList .=', '; |
|
5544 | + $keyList .= implode(', ', $fields_label); |
|
5545 | + } |
|
5546 | + |
|
5547 | + $sqlwhere=''; |
|
5548 | + $sql = 'SELECT '.$keyList; |
|
5549 | + $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
5550 | + if (!empty($InfoFieldList[4])) |
|
5551 | + { |
|
5552 | + // can use SELECT request |
|
5553 | + if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
5554 | + $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
5555 | + } |
|
5556 | + |
|
5557 | + // current object id can be use into filter |
|
5558 | + if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
5559 | + $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
5560 | + } else { |
|
5561 | + $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
5562 | + } |
|
5563 | + //We have to join on extrafield table |
|
5564 | + if (strpos($InfoFieldList[4], 'extra')!==false) |
|
5565 | + { |
|
5566 | + $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
5567 | + $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
5568 | + } |
|
5569 | + else |
|
5570 | + { |
|
5571 | + $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
5572 | + } |
|
5573 | + } |
|
5574 | + else |
|
5575 | + { |
|
5576 | + $sqlwhere.= ' WHERE 1=1'; |
|
5577 | + } |
|
5578 | + // Some tables may have field, some other not. For the moment we disable it. |
|
5579 | + if (in_array($InfoFieldList[0],array('tablewithentity'))) |
|
5580 | + { |
|
5581 | + $sqlwhere.= ' AND entity = '.$conf->entity; |
|
5582 | + } |
|
5583 | + $sql.=$sqlwhere; |
|
5584 | + //print $sql; |
|
5585 | + |
|
5586 | + $sql .= ' ORDER BY ' . implode(', ', $fields_label); |
|
5587 | + |
|
5588 | + dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
|
5589 | + $resql = $this->db->query($sql); |
|
5590 | + if ($resql) |
|
5591 | + { |
|
5592 | + $out.='<option value="0"> </option>'; |
|
5593 | + $num = $this->db->num_rows($resql); |
|
5594 | + $i = 0; |
|
5595 | + while ($i < $num) |
|
5596 | + { |
|
5597 | + $labeltoshow=''; |
|
5598 | + $obj = $this->db->fetch_object($resql); |
|
5599 | + |
|
5600 | + // Several field into label (eq table:code|libelle:rowid) |
|
5601 | + $notrans = false; |
|
5602 | + $fields_label = explode('|',$InfoFieldList[1]); |
|
5603 | + if (is_array($fields_label)) |
|
5604 | + { |
|
5605 | + $notrans = true; |
|
5606 | + foreach ($fields_label as $field_toshow) |
|
5607 | + { |
|
5608 | + $labeltoshow.= $obj->$field_toshow.' '; |
|
5609 | + } |
|
5610 | + } |
|
5611 | + else |
|
5612 | + { |
|
5613 | + $labeltoshow=$obj->{$InfoFieldList[1]}; |
|
5614 | + } |
|
5615 | + $labeltoshow=dol_trunc($labeltoshow,45); |
|
5616 | + |
|
5617 | + if ($value == $obj->rowid) |
|
5618 | + { |
|
5619 | + foreach ($fields_label as $field_toshow) |
|
5620 | + { |
|
5621 | + $translabel=$langs->trans($obj->$field_toshow); |
|
5622 | + if ($translabel!=$obj->$field_toshow) { |
|
5623 | + $labeltoshow=dol_trunc($translabel,18).' '; |
|
5624 | + }else { |
|
5625 | + $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
5626 | + } |
|
5627 | + } |
|
5628 | + $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
5629 | + } |
|
5630 | + else |
|
5631 | + { |
|
5632 | + if (! $notrans) |
|
5633 | + { |
|
5634 | + $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
5635 | + if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
5636 | + $labeltoshow=dol_trunc($translabel,18); |
|
5637 | + } |
|
5638 | + else { |
|
5639 | + $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18); |
|
5640 | + } |
|
5641 | + } |
|
5642 | + if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
5643 | + if ($value==$obj->rowid) |
|
5644 | + { |
|
5645 | + $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
5646 | + } |
|
5647 | + |
|
5648 | + if (!empty($InfoFieldList[3]) && $parentField) |
|
5649 | + { |
|
5650 | + $parent = $parentName.':'.$obj->{$parentField}; |
|
5651 | + } |
|
5652 | + |
|
5653 | + $out.='<option value="'.$obj->rowid.'"'; |
|
5654 | + $out.= ($value==$obj->rowid?' selected':''); |
|
5655 | + $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
5656 | + $out.='>'.$labeltoshow.'</option>'; |
|
5657 | + } |
|
5658 | + |
|
5659 | + $i++; |
|
5660 | + } |
|
5661 | + $this->db->free($resql); |
|
5662 | + } |
|
5663 | + else { |
|
5664 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
5665 | + } |
|
5666 | + } |
|
5667 | + $out.='</select>'; |
|
5668 | + } |
|
5669 | + elseif ($type == 'checkbox') |
|
5670 | + { |
|
5671 | + $value_arr=explode(',',$value); |
|
5672 | + $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
5673 | + } |
|
5674 | + elseif ($type == 'radio') |
|
5675 | + { |
|
5676 | + $out=''; |
|
5677 | + foreach ($param['options'] as $keyopt => $val) |
|
5678 | + { |
|
5679 | + $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
5680 | + $out.=' value="'.$keyopt.'"'; |
|
5681 | + $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
5682 | + $out.= ($value==$keyopt?'checked':''); |
|
5683 | + $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
5684 | + } |
|
5685 | + } |
|
5686 | + elseif ($type == 'chkbxlst') |
|
5687 | + { |
|
5688 | + if (is_array($value)) { |
|
5689 | + $value_arr = $value; |
|
5690 | + } |
|
5691 | + else { |
|
5692 | + $value_arr = explode(',', $value); |
|
5693 | + } |
|
5694 | + |
|
5695 | + if (is_array($param['options'])) { |
|
5696 | + $param_list = array_keys($param['options']); |
|
5697 | + $InfoFieldList = explode(":", $param_list[0]); |
|
5698 | + $parentName=''; |
|
5699 | + $parentField=''; |
|
5700 | + // 0 : tableName |
|
5701 | + // 1 : label field name |
|
5702 | + // 2 : key fields name (if differ of rowid) |
|
5703 | + // 3 : key field parent (for dependent lists) |
|
5704 | + // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
5705 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
5706 | + |
|
5707 | + if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) { |
|
5708 | + list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]); |
|
5709 | + $keyList .= ', ' . $parentField; |
|
5710 | + } |
|
5711 | + if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) { |
|
5712 | + if (strpos($InfoFieldList[4], 'extra.') !== false) { |
|
5713 | + $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
5714 | + } else { |
|
5715 | + $keyList = $InfoFieldList[2] . ' as rowid'; |
|
5716 | + } |
|
5717 | + } |
|
5718 | + |
|
5719 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
5720 | + if (is_array($fields_label)) { |
|
5721 | + $keyList .= ', '; |
|
5722 | + $keyList .= implode(', ', $fields_label); |
|
5723 | + } |
|
5724 | + |
|
5725 | + $sqlwhere = ''; |
|
5726 | + $sql = 'SELECT ' . $keyList; |
|
5727 | + $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
5728 | + if (! empty($InfoFieldList[4])) { |
|
5729 | + |
|
5730 | + // can use SELECT request |
|
5731 | + if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
5732 | + $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
5733 | + } |
|
5734 | + |
|
5735 | + // current object id can be use into filter |
|
5736 | + if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
5737 | + $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
5738 | + } else { |
|
5739 | + $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
5740 | + } |
|
5741 | + |
|
5742 | + // We have to join on extrafield table |
|
5743 | + if (strpos($InfoFieldList[4], 'extra') !== false) { |
|
5744 | + $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
5745 | + $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
5746 | + } else { |
|
5747 | + $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
5748 | + } |
|
5749 | + } else { |
|
5750 | + $sqlwhere .= ' WHERE 1=1'; |
|
5751 | + } |
|
5752 | + // Some tables may have field, some other not. For the moment we disable it. |
|
5753 | + if (in_array($InfoFieldList[0], array ('tablewithentity'))) |
|
5754 | + { |
|
5755 | + $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
5756 | + } |
|
5757 | + // $sql.=preg_replace('/^ AND /','',$sqlwhere); |
|
5758 | + // print $sql; |
|
5759 | + |
|
5760 | + $sql .= $sqlwhere; |
|
5761 | + dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
5762 | + $resql = $this->db->query($sql); |
|
5763 | + if ($resql) { |
|
5764 | + $num = $this->db->num_rows($resql); |
|
5765 | + $i = 0; |
|
5766 | + |
|
5767 | + $data=array(); |
|
5768 | + |
|
5769 | + while ( $i < $num ) { |
|
5770 | + $labeltoshow = ''; |
|
5771 | + $obj = $this->db->fetch_object($resql); |
|
5772 | + |
|
5773 | + $notrans = false; |
|
5774 | + // Several field into label (eq table:code|libelle:rowid) |
|
5775 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
5776 | + if (is_array($fields_label)) { |
|
5777 | + $notrans = true; |
|
5778 | + foreach ( $fields_label as $field_toshow ) { |
|
5779 | + $labeltoshow .= $obj->$field_toshow . ' '; |
|
5780 | + } |
|
5781 | + } else { |
|
5782 | + $labeltoshow = $obj->{$InfoFieldList[1]}; |
|
5783 | + } |
|
5784 | + $labeltoshow = dol_trunc($labeltoshow, 45); |
|
5785 | + |
|
5786 | + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
|
5787 | + foreach ( $fields_label as $field_toshow ) { |
|
5788 | + $translabel = $langs->trans($obj->$field_toshow); |
|
5789 | + if ($translabel != $obj->$field_toshow) { |
|
5790 | + $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
5791 | + } else { |
|
5792 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
5793 | + } |
|
5794 | + } |
|
5795 | + |
|
5796 | + $data[$obj->rowid]=$labeltoshow; |
|
5797 | + } else { |
|
5798 | + if (! $notrans) { |
|
5799 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
5800 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
5801 | + $labeltoshow = dol_trunc($translabel, 18); |
|
5802 | + } else { |
|
5803 | + $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18); |
|
5804 | + } |
|
5805 | + } |
|
5806 | + if (empty($labeltoshow)) |
|
5807 | + $labeltoshow = '(not defined)'; |
|
5808 | + |
|
5809 | + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
|
5810 | + $data[$obj->rowid]=$labeltoshow; |
|
5811 | + } |
|
5812 | + |
|
5813 | + if (! empty($InfoFieldList[3]) && $parentField) { |
|
5814 | + $parent = $parentName . ':' . $obj->{$parentField}; |
|
5815 | + } |
|
5816 | + |
|
5817 | + $data[$obj->rowid]=$labeltoshow; |
|
5818 | + } |
|
5819 | + |
|
5820 | + $i ++; |
|
5821 | + } |
|
5822 | + $this->db->free($resql); |
|
5823 | + |
|
5824 | + $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
5825 | + } else { |
|
5826 | + print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
5827 | + } |
|
5828 | + } |
|
5829 | + } |
|
5830 | + elseif ($type == 'link') |
|
5831 | + { |
|
5832 | + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
5833 | + $showempty=(($required && $default != '')?0:1); |
|
5834 | + $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
5835 | + if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
|
5836 | + { |
|
5837 | + list($class,$classfile)=explode(':',$param_list[0]); |
|
5838 | + if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
5839 | + else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
5840 | + $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
5841 | + // TODO Add Javascript code to add input fields contents to new elements urls |
|
5842 | + } |
|
5843 | + } |
|
5844 | + elseif ($type == 'password') |
|
5845 | + { |
|
5846 | + // If prefix is 'search_', field is used as a filter, we use a common text field. |
|
5847 | + $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
5848 | + } |
|
5849 | + elseif ($type == 'array') |
|
5850 | + { |
|
5851 | + $newval = $val; |
|
5852 | + $newval['type'] = 'varchar(256)'; |
|
5853 | + |
|
5854 | + $out=''; |
|
5855 | + |
|
5856 | + $inputs = array(); |
|
5857 | + if(! empty($value)) { |
|
5858 | + foreach($value as $option) { |
|
5859 | + $out.= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
5860 | + $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
5861 | + } |
|
5862 | + } |
|
5863 | + |
|
5864 | + $out.= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
5865 | + |
|
5866 | + $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
5867 | + $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
5868 | + |
|
5869 | + if(! empty($conf->use_javascript_ajax)) { |
|
5870 | + $out.= ' |
|
5871 | + <script type="text/javascript"> |
|
5872 | + $(document).ready(function() { |
|
5873 | + $("a#'.dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() { |
|
5874 | + $("'.dol_escape_js($newInput).'").insertBefore(this); |
|
5875 | + }); |
|
5876 | + |
|
5877 | + $(document).on("click", "a.'.dol_escape_js($keyprefix.$key.$keysuffix).'_del", function() { |
|
5878 | + $(this).parent().remove(); |
|
5879 | + }); |
|
5880 | + }); |
|
5881 | + </script>'; |
|
5882 | + } |
|
5883 | + } |
|
5884 | + if (!empty($hidden)) { |
|
5885 | + $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
5886 | + } |
|
5887 | + /* Add comments |
|
5888 | + if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
|
5889 | + elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; |
|
5890 | + */ |
|
5891 | + return $out; |
|
5892 | + } |
|
5893 | + |
|
5894 | + /** |
|
5895 | + * Return HTML string to show a field into a page |
|
5896 | + * Code very similar with showOutputField of extra fields |
|
5897 | + * |
|
5898 | + * @param array $val Array of properties of field to show |
|
5899 | + * @param string $key Key of attribute |
|
5900 | + * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) |
|
5901 | + * @param string $moreparam To add more parametes on html input tag |
|
5902 | + * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
5903 | + * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
5904 | + * @param mixed $showsize Value for css to define size. May also be a numeric. |
|
5905 | + * @return string |
|
5906 | + */ |
|
5907 | + function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
5908 | + { |
|
5909 | + global $conf,$langs,$form; |
|
5910 | + |
|
5911 | + if (! is_object($form)) |
|
5912 | + { |
|
5913 | + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
5914 | + $form=new Form($this->db); |
|
5915 | + } |
|
5916 | + |
|
5917 | + $objectid = $this->id; |
|
5918 | + $label = $val['label']; |
|
5919 | + $type = $val['type']; |
|
5920 | + $size = $val['css']; |
|
5921 | + |
|
5922 | + // Convert var to be able to share same code than showOutputField of extrafields |
|
5923 | + if (preg_match('/varchar\((\d+)\)/', $type, $reg)) |
|
5924 | + { |
|
5925 | + $type = 'varchar'; // convert varchar(xx) int varchar |
|
5926 | + $size = $reg[1]; |
|
5927 | + } |
|
5928 | + elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
5929 | + if (is_array($val['arrayofkeyval'])) $type='select'; |
|
5930 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; |
|
5931 | + |
|
5932 | + $default=$val['default']; |
|
5933 | + $computed=$val['computed']; |
|
5934 | + $unique=$val['unique']; |
|
5935 | + $required=$val['required']; |
|
5936 | + $param=$val['param']; |
|
5937 | + if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
|
5938 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) |
|
5939 | + { |
|
5940 | + $type='link'; |
|
5941 | + $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
5942 | + } |
|
5943 | + $langfile=$val['langfile']; |
|
5944 | + $list=$val['list']; |
|
5945 | + $help=$val['help']; |
|
5946 | + $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) |
|
5947 | + |
|
5948 | + if ($hidden) return ''; |
|
5949 | + |
|
5950 | + // If field is a computed field, value must become result of compute |
|
5951 | + if ($computed) |
|
5952 | + { |
|
5953 | + // Make the eval of compute string |
|
5954 | + //var_dump($computed); |
|
5955 | + $value = dol_eval($computed, 1, 0); |
|
5956 | + } |
|
5957 | + |
|
5958 | + if (empty($showsize)) |
|
5959 | + { |
|
5960 | + if ($type == 'date') |
|
5961 | + { |
|
5962 | + //$showsize=10; |
|
5963 | + $showsize = 'minwidth100imp'; |
|
5964 | + } |
|
5965 | + elseif ($type == 'datetime') |
|
5966 | + { |
|
5967 | + //$showsize=19; |
|
5968 | + $showsize = 'minwidth200imp'; |
|
5969 | + } |
|
5970 | + elseif (in_array($type,array('int','double','price'))) |
|
5971 | + { |
|
5972 | + //$showsize=10; |
|
5973 | + $showsize = 'maxwidth75'; |
|
5974 | + } |
|
5975 | + elseif ($type == 'url') |
|
5976 | + { |
|
5977 | + $showsize='minwidth400'; |
|
5978 | + } |
|
5979 | + elseif ($type == 'boolean') |
|
5980 | + { |
|
5981 | + $showsize=''; |
|
5982 | + } |
|
5983 | + else |
|
5984 | + { |
|
5985 | + if (round($size) < 12) |
|
5986 | + { |
|
5987 | + $showsize = 'minwidth100'; |
|
5988 | + } |
|
5989 | + else if (round($size) <= 48) |
|
5990 | + { |
|
5991 | + $showsize = 'minwidth200'; |
|
5992 | + } |
|
5993 | + else |
|
5994 | + { |
|
5995 | + //$showsize=48; |
|
5996 | + $showsize = 'minwidth400'; |
|
5997 | + } |
|
5998 | + } |
|
5999 | + } |
|
6000 | + |
|
6001 | + // Format output value differently according to properties of field |
|
6002 | + if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
6003 | + elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
6004 | + elseif ($type == 'date') |
|
6005 | + { |
|
6006 | + if(! empty($value)) { |
|
6007 | + $value=dol_print_date($value,'day'); |
|
6008 | + } else { |
|
6009 | + $value=''; |
|
6010 | + } |
|
6011 | + } |
|
6012 | + elseif ($type == 'datetime') |
|
6013 | + { |
|
6014 | + if(! empty($value)) { |
|
6015 | + $value=dol_print_date($value,'dayhour'); |
|
6016 | + } else { |
|
6017 | + $value=''; |
|
6018 | + } |
|
6019 | + } |
|
6020 | + elseif ($type == 'double') |
|
6021 | + { |
|
6022 | + if (!empty($value)) { |
|
6023 | + $value=price($value); |
|
6024 | + } |
|
6025 | + } |
|
6026 | + elseif ($type == 'boolean') |
|
6027 | + { |
|
6028 | + $checked=''; |
|
6029 | + if (!empty($value)) { |
|
6030 | + $checked=' checked '; |
|
6031 | + } |
|
6032 | + $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
6033 | + } |
|
6034 | + elseif ($type == 'mail') |
|
6035 | + { |
|
6036 | + $value=dol_print_email($value,0,0,0,64,1,1); |
|
6037 | + } |
|
6038 | + elseif ($type == 'url') |
|
6039 | + { |
|
6040 | + $value=dol_print_url($value,'_blank',32,1); |
|
6041 | + } |
|
6042 | + elseif ($type == 'phone') |
|
6043 | + { |
|
6044 | + $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
6045 | + } |
|
6046 | + elseif ($type == 'price') |
|
6047 | + { |
|
6048 | + $value=price($value,0,$langs,0,0,-1,$conf->currency); |
|
6049 | + } |
|
6050 | + elseif ($type == 'select') |
|
6051 | + { |
|
6052 | + $value=$param['options'][$value]; |
|
6053 | + } |
|
6054 | + elseif ($type == 'sellist') |
|
6055 | + { |
|
6056 | + $param_list=array_keys($param['options']); |
|
6057 | + $InfoFieldList = explode(":", $param_list[0]); |
|
6058 | + |
|
6059 | + $selectkey="rowid"; |
|
6060 | + $keyList='rowid'; |
|
6061 | + |
|
6062 | + if (count($InfoFieldList)>=3) |
|
6063 | + { |
|
6064 | + $selectkey = $InfoFieldList[2]; |
|
6065 | + $keyList=$InfoFieldList[2].' as rowid'; |
|
6066 | + } |
|
6067 | + |
|
6068 | + $fields_label = explode('|',$InfoFieldList[1]); |
|
6069 | + if(is_array($fields_label)) { |
|
6070 | + $keyList .=', '; |
|
6071 | + $keyList .= implode(', ', $fields_label); |
|
6072 | + } |
|
6073 | + |
|
6074 | + $sql = 'SELECT '.$keyList; |
|
6075 | + $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
6076 | + if (strpos($InfoFieldList[4], 'extra')!==false) |
|
6077 | + { |
|
6078 | + $sql.= ' as main'; |
|
6079 | + } |
|
6080 | + if ($selectkey=='rowid' && empty($value)) { |
|
6081 | + $sql.= " WHERE ".$selectkey."=0"; |
|
6082 | + } elseif ($selectkey=='rowid') { |
|
6083 | + $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
6084 | + }else { |
|
6085 | + $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
6086 | + } |
|
6087 | + |
|
6088 | + //$sql.= ' AND entity = '.$conf->entity; |
|
6089 | + |
|
6090 | + dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); |
|
6091 | + $resql = $this->db->query($sql); |
|
6092 | + if ($resql) |
|
6093 | + { |
|
6094 | + $value=''; // value was used, so now we reste it to use it to build final output |
|
6095 | + |
|
6096 | + $obj = $this->db->fetch_object($resql); |
|
6097 | + |
|
6098 | + // Several field into label (eq table:code|libelle:rowid) |
|
6099 | + $fields_label = explode('|',$InfoFieldList[1]); |
|
6100 | + |
|
6101 | + if(is_array($fields_label) && count($fields_label)>1) |
|
6102 | + { |
|
6103 | + foreach ($fields_label as $field_toshow) |
|
6104 | + { |
|
6105 | + $translabel=''; |
|
6106 | + if (!empty($obj->$field_toshow)) { |
|
6107 | + $translabel=$langs->trans($obj->$field_toshow); |
|
6108 | + } |
|
6109 | + if ($translabel!=$field_toshow) { |
|
6110 | + $value.=dol_trunc($translabel,18).' '; |
|
6111 | + }else { |
|
6112 | + $value.=$obj->$field_toshow.' '; |
|
6113 | + } |
|
6114 | + } |
|
6115 | + } |
|
6116 | + else |
|
6117 | + { |
|
6118 | + $translabel=''; |
|
6119 | + if (!empty($obj->{$InfoFieldList[1]})) { |
|
6120 | + $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
6121 | + } |
|
6122 | + if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
6123 | + $value=dol_trunc($translabel,18); |
|
6124 | + }else { |
|
6125 | + $value=$obj->{$InfoFieldList[1]}; |
|
6126 | + } |
|
6127 | + } |
|
6128 | + } |
|
6129 | + else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
6130 | + } |
|
6131 | + elseif ($type == 'radio') |
|
6132 | + { |
|
6133 | + $value=$param['options'][$value]; |
|
6134 | + } |
|
6135 | + elseif ($type == 'checkbox') |
|
6136 | + { |
|
6137 | + $value_arr=explode(',',$value); |
|
6138 | + $value=''; |
|
6139 | + if (is_array($value_arr) && count($value_arr)>0) |
|
6140 | + { |
|
6141 | + foreach ($value_arr as $keyval=>$valueval) { |
|
6142 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
6143 | + } |
|
6144 | + $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
6145 | + } |
|
6146 | + } |
|
6147 | + elseif ($type == 'chkbxlst') |
|
6148 | + { |
|
6149 | + $value_arr = explode(',', $value); |
|
6150 | + |
|
6151 | + $param_list = array_keys($param['options']); |
|
6152 | + $InfoFieldList = explode(":", $param_list[0]); |
|
6153 | + |
|
6154 | + $selectkey = "rowid"; |
|
6155 | + $keyList = 'rowid'; |
|
6156 | + |
|
6157 | + if (count($InfoFieldList) >= 3) { |
|
6158 | + $selectkey = $InfoFieldList[2]; |
|
6159 | + $keyList = $InfoFieldList[2] . ' as rowid'; |
|
6160 | + } |
|
6161 | + |
|
6162 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
6163 | + if (is_array($fields_label)) { |
|
6164 | + $keyList .= ', '; |
|
6165 | + $keyList .= implode(', ', $fields_label); |
|
6166 | + } |
|
6167 | + |
|
6168 | + $sql = 'SELECT ' . $keyList; |
|
6169 | + $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
6170 | + if (strpos($InfoFieldList[4], 'extra') !== false) { |
|
6171 | + $sql .= ' as main'; |
|
6172 | + } |
|
6173 | + // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
6174 | + // $sql.= ' AND entity = '.$conf->entity; |
|
6175 | + |
|
6176 | + dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
6177 | + $resql = $this->db->query($sql); |
|
6178 | + if ($resql) { |
|
6179 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
6180 | + $toprint=array(); |
|
6181 | + while ( $obj = $this->db->fetch_object($resql) ) { |
|
6182 | + |
|
6183 | + // Several field into label (eq table:code|libelle:rowid) |
|
6184 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
6185 | + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
|
6186 | + if (is_array($fields_label) && count($fields_label) > 1) { |
|
6187 | + foreach ( $fields_label as $field_toshow ) { |
|
6188 | + $translabel = ''; |
|
6189 | + if (! empty($obj->$field_toshow)) { |
|
6190 | + $translabel = $langs->trans($obj->$field_toshow); |
|
6191 | + } |
|
6192 | + if ($translabel != $field_toshow) { |
|
6193 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
6194 | + } else { |
|
6195 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
6196 | + } |
|
6197 | + } |
|
6198 | + } else { |
|
6199 | + $translabel = ''; |
|
6200 | + if (! empty($obj->{$InfoFieldList[1]})) { |
|
6201 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
6202 | + } |
|
6203 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
6204 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
6205 | + } else { |
|
6206 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
6207 | + } |
|
6208 | + } |
|
6209 | + } |
|
6210 | + } |
|
6211 | + $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
6212 | + } else { |
|
6213 | + dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
6214 | + } |
|
6215 | + } |
|
6216 | + elseif ($type == 'link') |
|
6217 | + { |
|
6218 | + $out=''; |
|
6219 | + |
|
6220 | + // only if something to display (perf) |
|
6221 | + if ($value) |
|
6222 | + { |
|
6223 | + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
6224 | + |
|
6225 | + $InfoFieldList = explode(":", $param_list[0]); |
|
6226 | + $classname=$InfoFieldList[0]; |
|
6227 | + $classpath=$InfoFieldList[1]; |
|
6228 | + $getnomurlparam=(empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
6229 | + if (! empty($classpath)) |
|
6230 | + { |
|
6231 | + dol_include_once($InfoFieldList[1]); |
|
6232 | + if ($classname && class_exists($classname)) |
|
6233 | + { |
|
6234 | + $object = new $classname($this->db); |
|
6235 | + $object->fetch($value); |
|
6236 | + $value=$object->getNomUrl($getnomurlparam); |
|
6237 | + } |
|
6238 | + } |
|
6239 | + else |
|
6240 | + { |
|
6241 | + dol_syslog('Error bad setup of extrafield', LOG_WARNING); |
|
6242 | + return 'Error bad setup of extrafield'; |
|
6243 | + } |
|
6244 | + } |
|
6245 | + else $value=''; |
|
6246 | + } |
|
6247 | + elseif ($type == 'text' || $type == 'html') |
|
6248 | + { |
|
6249 | + $value=dol_htmlentitiesbr($value); |
|
6250 | + } |
|
6251 | + elseif ($type == 'password') |
|
6252 | + { |
|
6253 | + $value=preg_replace('/./i','*',$value); |
|
6254 | + } |
|
6255 | + elseif ($type == 'array') |
|
6256 | + { |
|
6257 | + $value = implode('<br>', $value); |
|
6258 | + } |
|
6259 | + |
|
6260 | + //print $type.'-'.$size; |
|
6261 | + $out=$value; |
|
6262 | + |
|
6263 | + return $out; |
|
6264 | + } |
|
6265 | + |
|
6266 | + |
|
6267 | + /** |
|
6268 | + * Function to show lines of extrafields with output datas |
|
6269 | + * |
|
6270 | + * @param Extrafields $extrafields Extrafield Object |
|
6271 | + * @param string $mode Show output (view) or input (edit) for extrafield |
|
6272 | + * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan) |
|
6273 | + * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) |
|
6274 | + * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) |
|
6275 | + * @param string $onetrtd All fields in same tr td |
|
6276 | + * @return string |
|
6277 | + */ |
|
6278 | + function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) |
|
6279 | + { |
|
6280 | + global $db, $conf, $langs, $action, $form; |
|
6281 | + |
|
6282 | + if (! is_object($form)) $form=new Form($db); |
|
6283 | + |
|
6284 | + $out = ''; |
|
6285 | + |
|
6286 | + if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) |
|
6287 | + { |
|
6288 | + $out .= "\n"; |
|
6289 | + $out .= '<!-- showOptionalsInput --> '; |
|
6290 | + $out .= "\n"; |
|
5819 | 6291 | |
5820 | - $i ++; |
|
5821 | - } |
|
5822 | - $this->db->free($resql); |
|
6292 | + $e = 0; |
|
6293 | + foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
6294 | + { |
|
6295 | + // Show only the key field in params |
|
6296 | + if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue; |
|
6297 | + |
|
6298 | + $enabled = 1; |
|
6299 | + if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
|
6300 | + { |
|
6301 | + $enabled = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1); |
|
6302 | + } |
|
6303 | + |
|
6304 | + $perms = 1; |
|
6305 | + if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) |
|
6306 | + { |
|
6307 | + $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
|
6308 | + } |
|
6309 | + |
|
6310 | + 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 (empty($perms)) continue; |
|
6312 | + |
|
6313 | + // Load language if required |
|
6314 | + if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
6315 | + |
|
6316 | + $colspan='3'; |
|
6317 | + if (is_array($params) && count($params)>0) { |
|
6318 | + if (array_key_exists('colspan',$params)) { |
|
6319 | + $colspan=$params['colspan']; |
|
6320 | + } |
|
6321 | + } |
|
6322 | + |
|
6323 | + switch($mode) { |
|
6324 | + case "view": |
|
6325 | + $value=$this->array_options["options_".$key.$keysuffix]; |
|
6326 | + break; |
|
6327 | + case "edit": |
|
6328 | + $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
6329 | + // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc') |
|
6330 | + if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
|
6331 | + { |
|
6332 | + if (is_array($getposttemp)) { |
|
6333 | + // $getposttemp is an array but following code expects a comma separated string |
|
6334 | + $value = implode(",", $getposttemp); |
|
6335 | + } else { |
|
6336 | + $value = $getposttemp; |
|
6337 | + } |
|
6338 | + } else { |
|
6339 | + $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
6340 | + } |
|
6341 | + //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
|
6342 | + break; |
|
6343 | + } |
|
6344 | + |
|
6345 | + if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') |
|
6346 | + { |
|
6347 | + $out .= $extrafields->showSeparator($key, $this); |
|
6348 | + } |
|
6349 | + else |
|
6350 | + { |
|
6351 | + $csstyle=''; |
|
6352 | + $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
6353 | + if (is_array($params) && count($params)>0) { |
|
6354 | + if (array_key_exists('style',$params)) { |
|
6355 | + $csstyle=$params['style']; |
|
6356 | + } |
|
6357 | + } |
|
6358 | + |
|
6359 | + // add html5 elements |
|
6360 | + $domData = ' data-element="extrafield"'; |
|
6361 | + $domData .= ' data-targetelement="'.$this->element.'"'; |
|
6362 | + $domData .= ' data-targetid="'.$this->id.'"'; |
|
6363 | + |
|
6364 | + $html_id = !empty($this->id) ? 'extrarow-'.$this->element.'_'.$key.'_'.$this->id : ''; |
|
6365 | + |
|
6366 | + $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
|
6367 | + |
|
6368 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
6369 | + { |
|
6370 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; } |
|
6371 | + } |
|
6372 | + |
|
6373 | + if ($action == 'selectlines') { $colspan++; } |
|
6374 | + |
|
6375 | + // Convert date into timestamp format (value in memory must be a timestamp) |
|
6376 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime'))) |
|
6377 | + { |
|
6378 | + $datenotinstring = $this->array_options['options_' . $key]; |
|
6379 | + if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
6380 | + { |
|
6381 | + $datenotinstring = $this->db->jdate($datenotinstring); |
|
6382 | + } |
|
6383 | + $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 | + } |
|
6385 | + // Convert float submited string into real php numeric (value in memory must be a php numeric) |
|
6386 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double'))) |
|
6387 | + { |
|
6388 | + $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)):$this->array_options['options_'.$key]; |
|
6389 | + } |
|
6390 | + |
|
6391 | + $labeltoshow = $langs->trans($label); |
|
6392 | + |
|
6393 | + $out .= '<td class="titlefield'; |
|
6394 | + if (GETPOST('action','none') == 'create') $out.='create'; |
|
6395 | + if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
6396 | + $out .= '">'; |
|
6397 | + if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
6398 | + else $out .= $labeltoshow; |
|
6399 | + $out .= '</td>'; |
|
6400 | + |
|
6401 | + $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
|
6402 | + $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
6403 | + |
|
6404 | + switch($mode) { |
|
6405 | + case "view": |
|
6406 | + $out .= $extrafields->showOutputField($key, $value); |
|
6407 | + break; |
|
6408 | + case "edit": |
|
6409 | + $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id); |
|
6410 | + break; |
|
6411 | + } |
|
6412 | + |
|
6413 | + $out .= '</td>'; |
|
6414 | + |
|
6415 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
6416 | + else $out .= '</tr>'; |
|
6417 | + $e++; |
|
6418 | + } |
|
6419 | + } |
|
6420 | + $out .= "\n"; |
|
6421 | + // Add code to manage list depending on others |
|
6422 | + if (! empty($conf->use_javascript_ajax)) { |
|
6423 | + $out .= ' |
|
6424 | + <script type="text/javascript"> |
|
6425 | + jQuery(document).ready(function() { |
|
6426 | + function showOptions(child_list, parent_list) |
|
6427 | + { |
|
6428 | + var val = $("select[name=\"options_"+parent_list+"\"]").val(); |
|
6429 | + var parentVal = parent_list + ":" + val; |
|
6430 | + if(val > 0) { |
|
6431 | + $("select[name=\""+child_list+"\"] option[parent]").hide(); |
|
6432 | + $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show(); |
|
6433 | + } else { |
|
6434 | + $("select[name=\""+child_list+"\"] option").show(); |
|
6435 | + } |
|
6436 | + } |
|
6437 | + function setListDependencies() { |
|
6438 | + jQuery("select option[parent]").parent().each(function() { |
|
6439 | + var child_list = $(this).attr("name"); |
|
6440 | + var parent = $(this).find("option[parent]:first").attr("parent"); |
|
6441 | + var infos = parent.split(":"); |
|
6442 | + var parent_list = infos[0]; |
|
6443 | + $("select[name=\""+parent_list+"\"]").change(function() { |
|
6444 | + showOptions(child_list, parent_list); |
|
6445 | + }); |
|
6446 | + }); |
|
6447 | + } |
|
5823 | 6448 | |
5824 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
5825 | - } else { |
|
5826 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
5827 | - } |
|
5828 | - } |
|
5829 | - } |
|
5830 | - elseif ($type == 'link') |
|
5831 | - { |
|
5832 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
5833 | - $showempty=(($required && $default != '')?0:1); |
|
5834 | - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
5835 | - if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
|
5836 | - { |
|
5837 | - list($class,$classfile)=explode(':',$param_list[0]); |
|
5838 | - if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
5839 | - else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
5840 | - $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
5841 | - // TODO Add Javascript code to add input fields contents to new elements urls |
|
5842 | - } |
|
5843 | - } |
|
5844 | - elseif ($type == 'password') |
|
5845 | - { |
|
5846 | - // If prefix is 'search_', field is used as a filter, we use a common text field. |
|
5847 | - $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
5848 | - } |
|
5849 | - elseif ($type == 'array') |
|
5850 | - { |
|
5851 | - $newval = $val; |
|
5852 | - $newval['type'] = 'varchar(256)'; |
|
5853 | - |
|
5854 | - $out=''; |
|
5855 | - |
|
5856 | - $inputs = array(); |
|
5857 | - if(! empty($value)) { |
|
5858 | - foreach($value as $option) { |
|
5859 | - $out.= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
5860 | - $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
5861 | - } |
|
5862 | - } |
|
6449 | + setListDependencies(); |
|
6450 | + }); |
|
6451 | + </script>'."\n"; |
|
6452 | + $out .= '<!-- /showOptionalsInput --> '."\n"; |
|
6453 | + } |
|
6454 | + } |
|
6455 | + return $out; |
|
6456 | + } |
|
5863 | 6457 | |
5864 | - $out.= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
5865 | 6458 | |
5866 | - $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
5867 | - $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
6459 | + /** |
|
6460 | + * Returns the rights used for this class |
|
6461 | + * @return stdClass |
|
6462 | + */ |
|
6463 | + public function getRights() |
|
6464 | + { |
|
6465 | + global $user; |
|
5868 | 6466 | |
5869 | - if(! empty($conf->use_javascript_ajax)) { |
|
5870 | - $out.= ' |
|
5871 | - <script type="text/javascript"> |
|
5872 | - $(document).ready(function() { |
|
5873 | - $("a#'.dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() { |
|
5874 | - $("'.dol_escape_js($newInput).'").insertBefore(this); |
|
5875 | - }); |
|
6467 | + $element = $this->element; |
|
6468 | + if ($element == 'facturerec') $element='facture'; |
|
5876 | 6469 | |
5877 | - $(document).on("click", "a.'.dol_escape_js($keyprefix.$key.$keysuffix).'_del", function() { |
|
5878 | - $(this).parent().remove(); |
|
5879 | - }); |
|
5880 | - }); |
|
5881 | - </script>'; |
|
5882 | - } |
|
5883 | - } |
|
5884 | - if (!empty($hidden)) { |
|
5885 | - $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
5886 | - } |
|
5887 | - /* Add comments |
|
5888 | - if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
|
5889 | - elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; |
|
5890 | - */ |
|
5891 | - return $out; |
|
5892 | - } |
|
5893 | - |
|
5894 | - /** |
|
5895 | - * Return HTML string to show a field into a page |
|
5896 | - * Code very similar with showOutputField of extra fields |
|
5897 | - * |
|
5898 | - * @param array $val Array of properties of field to show |
|
5899 | - * @param string $key Key of attribute |
|
5900 | - * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) |
|
5901 | - * @param string $moreparam To add more parametes on html input tag |
|
5902 | - * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
5903 | - * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
5904 | - * @param mixed $showsize Value for css to define size. May also be a numeric. |
|
5905 | - * @return string |
|
5906 | - */ |
|
5907 | - function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
5908 | - { |
|
5909 | - global $conf,$langs,$form; |
|
5910 | - |
|
5911 | - if (! is_object($form)) |
|
5912 | - { |
|
5913 | - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
5914 | - $form=new Form($this->db); |
|
5915 | - } |
|
5916 | - |
|
5917 | - $objectid = $this->id; |
|
5918 | - $label = $val['label']; |
|
5919 | - $type = $val['type']; |
|
5920 | - $size = $val['css']; |
|
5921 | - |
|
5922 | - // Convert var to be able to share same code than showOutputField of extrafields |
|
5923 | - if (preg_match('/varchar\((\d+)\)/', $type, $reg)) |
|
5924 | - { |
|
5925 | - $type = 'varchar'; // convert varchar(xx) int varchar |
|
5926 | - $size = $reg[1]; |
|
5927 | - } |
|
5928 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
5929 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
5930 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; |
|
5931 | - |
|
5932 | - $default=$val['default']; |
|
5933 | - $computed=$val['computed']; |
|
5934 | - $unique=$val['unique']; |
|
5935 | - $required=$val['required']; |
|
5936 | - $param=$val['param']; |
|
5937 | - if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
|
5938 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) |
|
5939 | - { |
|
5940 | - $type='link'; |
|
5941 | - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
5942 | - } |
|
5943 | - $langfile=$val['langfile']; |
|
5944 | - $list=$val['list']; |
|
5945 | - $help=$val['help']; |
|
5946 | - $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) |
|
5947 | - |
|
5948 | - if ($hidden) return ''; |
|
5949 | - |
|
5950 | - // If field is a computed field, value must become result of compute |
|
5951 | - if ($computed) |
|
5952 | - { |
|
5953 | - // Make the eval of compute string |
|
5954 | - //var_dump($computed); |
|
5955 | - $value = dol_eval($computed, 1, 0); |
|
5956 | - } |
|
5957 | - |
|
5958 | - if (empty($showsize)) |
|
5959 | - { |
|
5960 | - if ($type == 'date') |
|
5961 | - { |
|
5962 | - //$showsize=10; |
|
5963 | - $showsize = 'minwidth100imp'; |
|
5964 | - } |
|
5965 | - elseif ($type == 'datetime') |
|
5966 | - { |
|
5967 | - //$showsize=19; |
|
5968 | - $showsize = 'minwidth200imp'; |
|
5969 | - } |
|
5970 | - elseif (in_array($type,array('int','double','price'))) |
|
5971 | - { |
|
5972 | - //$showsize=10; |
|
5973 | - $showsize = 'maxwidth75'; |
|
5974 | - } |
|
5975 | - elseif ($type == 'url') |
|
5976 | - { |
|
5977 | - $showsize='minwidth400'; |
|
5978 | - } |
|
5979 | - elseif ($type == 'boolean') |
|
5980 | - { |
|
5981 | - $showsize=''; |
|
5982 | - } |
|
5983 | - else |
|
5984 | - { |
|
5985 | - if (round($size) < 12) |
|
5986 | - { |
|
5987 | - $showsize = 'minwidth100'; |
|
5988 | - } |
|
5989 | - else if (round($size) <= 48) |
|
5990 | - { |
|
5991 | - $showsize = 'minwidth200'; |
|
5992 | - } |
|
5993 | - else |
|
5994 | - { |
|
5995 | - //$showsize=48; |
|
5996 | - $showsize = 'minwidth400'; |
|
5997 | - } |
|
5998 | - } |
|
5999 | - } |
|
6000 | - |
|
6001 | - // Format output value differently according to properties of field |
|
6002 | - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
6003 | - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
6004 | - elseif ($type == 'date') |
|
6005 | - { |
|
6006 | - if(! empty($value)) { |
|
6007 | - $value=dol_print_date($value,'day'); |
|
6008 | - } else { |
|
6009 | - $value=''; |
|
6010 | - } |
|
6011 | - } |
|
6012 | - elseif ($type == 'datetime') |
|
6013 | - { |
|
6014 | - if(! empty($value)) { |
|
6015 | - $value=dol_print_date($value,'dayhour'); |
|
6016 | - } else { |
|
6017 | - $value=''; |
|
6018 | - } |
|
6019 | - } |
|
6020 | - elseif ($type == 'double') |
|
6021 | - { |
|
6022 | - if (!empty($value)) { |
|
6023 | - $value=price($value); |
|
6024 | - } |
|
6025 | - } |
|
6026 | - elseif ($type == 'boolean') |
|
6027 | - { |
|
6028 | - $checked=''; |
|
6029 | - if (!empty($value)) { |
|
6030 | - $checked=' checked '; |
|
6031 | - } |
|
6032 | - $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
6033 | - } |
|
6034 | - elseif ($type == 'mail') |
|
6035 | - { |
|
6036 | - $value=dol_print_email($value,0,0,0,64,1,1); |
|
6037 | - } |
|
6038 | - elseif ($type == 'url') |
|
6039 | - { |
|
6040 | - $value=dol_print_url($value,'_blank',32,1); |
|
6041 | - } |
|
6042 | - elseif ($type == 'phone') |
|
6043 | - { |
|
6044 | - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
6045 | - } |
|
6046 | - elseif ($type == 'price') |
|
6047 | - { |
|
6048 | - $value=price($value,0,$langs,0,0,-1,$conf->currency); |
|
6049 | - } |
|
6050 | - elseif ($type == 'select') |
|
6051 | - { |
|
6052 | - $value=$param['options'][$value]; |
|
6053 | - } |
|
6054 | - elseif ($type == 'sellist') |
|
6055 | - { |
|
6056 | - $param_list=array_keys($param['options']); |
|
6057 | - $InfoFieldList = explode(":", $param_list[0]); |
|
6058 | - |
|
6059 | - $selectkey="rowid"; |
|
6060 | - $keyList='rowid'; |
|
6061 | - |
|
6062 | - if (count($InfoFieldList)>=3) |
|
6063 | - { |
|
6064 | - $selectkey = $InfoFieldList[2]; |
|
6065 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
6066 | - } |
|
6067 | - |
|
6068 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
6069 | - if(is_array($fields_label)) { |
|
6070 | - $keyList .=', '; |
|
6071 | - $keyList .= implode(', ', $fields_label); |
|
6072 | - } |
|
6073 | - |
|
6074 | - $sql = 'SELECT '.$keyList; |
|
6075 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
6076 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
6077 | - { |
|
6078 | - $sql.= ' as main'; |
|
6079 | - } |
|
6080 | - if ($selectkey=='rowid' && empty($value)) { |
|
6081 | - $sql.= " WHERE ".$selectkey."=0"; |
|
6082 | - } elseif ($selectkey=='rowid') { |
|
6083 | - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
6084 | - }else { |
|
6085 | - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
6086 | - } |
|
6087 | - |
|
6088 | - //$sql.= ' AND entity = '.$conf->entity; |
|
6089 | - |
|
6090 | - dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); |
|
6091 | - $resql = $this->db->query($sql); |
|
6092 | - if ($resql) |
|
6093 | - { |
|
6094 | - $value=''; // value was used, so now we reste it to use it to build final output |
|
6470 | + return $user->rights->{$element}; |
|
6471 | + } |
|
6472 | + |
|
6473 | + /** |
|
6474 | + * Function used to replace a thirdparty id with another one. |
|
6475 | + * This function is meant to be called from replaceThirdparty with the appropiate tables |
|
6476 | + * Column name fk_soc MUST be used to identify thirdparties |
|
6477 | + * |
|
6478 | + * @param DoliDB $db Database handler |
|
6479 | + * @param int $origin_id Old thirdparty id (the thirdparty to delete) |
|
6480 | + * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) |
|
6481 | + * @param string[] $tables Tables that need to be changed |
|
6482 | + * @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) |
|
6483 | + * @return bool True if success, False if error |
|
6484 | + */ |
|
6485 | + public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
6486 | + { |
|
6487 | + foreach ($tables as $table) |
|
6488 | + { |
|
6489 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
|
6490 | + |
|
6491 | + if (! $db->query($sql)) |
|
6492 | + { |
|
6493 | + 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 | + //$this->errors = $db->lasterror(); |
|
6495 | + return false; |
|
6496 | + } |
|
6497 | + } |
|
6498 | + |
|
6499 | + return true; |
|
6500 | + } |
|
6501 | + |
|
6502 | + /** |
|
6503 | + * Get buy price to use for margin calculation. This function is called when buy price is unknown. |
|
6504 | + * Set buy price = sell price if ForceBuyingPriceIfNull configured, |
|
6505 | + * else if calculation MARGIN_TYPE = 'costprice' and costprice is defined, use costprice as buyprice |
|
6506 | + * else if calculation MARGIN_TYPE = 'pmp' and pmp is calculated, use pmp as buyprice |
|
6507 | + * else set min buy price as buy price |
|
6508 | + * |
|
6509 | + * @param float $unitPrice Product unit price |
|
6510 | + * @param float $discountPercent Line discount percent |
|
6511 | + * @param int $fk_product Product id |
|
6512 | + * @return float <0 if KO, buyprice if OK |
|
6513 | + */ |
|
6514 | + public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) |
|
6515 | + { |
|
6516 | + global $conf; |
|
6517 | + |
|
6518 | + $buyPrice = 0; |
|
6519 | + |
|
6520 | + if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false |
|
6521 | + { |
|
6522 | + $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
|
6523 | + } |
|
6524 | + else |
|
6525 | + { |
|
6526 | + // Get cost price for margin calculation |
|
6527 | + if (! empty($fk_product)) |
|
6528 | + { |
|
6529 | + if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') |
|
6530 | + { |
|
6531 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
6532 | + $product = new Product($this->db); |
|
6533 | + $result = $product->fetch($fk_product); |
|
6534 | + if ($result <= 0) |
|
6535 | + { |
|
6536 | + $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
6537 | + return -1; |
|
6538 | + } |
|
6539 | + if ($product->cost_price > 0) |
|
6540 | + { |
|
6541 | + $buyPrice = $product->cost_price; |
|
6542 | + } |
|
6543 | + else if ($product->pmp > 0) |
|
6544 | + { |
|
6545 | + $buyPrice = $product->pmp; |
|
6546 | + } |
|
6547 | + } |
|
6548 | + else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') |
|
6549 | + { |
|
6550 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
6551 | + $product = new Product($this->db); |
|
6552 | + $result = $product->fetch($fk_product); |
|
6553 | + if ($result <= 0) |
|
6554 | + { |
|
6555 | + $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
6556 | + return -1; |
|
6557 | + } |
|
6558 | + if ($product->pmp > 0) |
|
6559 | + { |
|
6560 | + $buyPrice = $product->pmp; |
|
6561 | + } |
|
6562 | + } |
|
6563 | + |
|
6564 | + if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice'))) |
|
6565 | + { |
|
6566 | + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
6567 | + $productFournisseur = new ProductFournisseur($this->db); |
|
6568 | + if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) |
|
6569 | + { |
|
6570 | + $buyPrice = $productFournisseur->fourn_unitprice; |
|
6571 | + } |
|
6572 | + else if ($result < 0) |
|
6573 | + { |
|
6574 | + $this->errors[] = $productFournisseur->error; |
|
6575 | + return -2; |
|
6576 | + } |
|
6577 | + } |
|
6578 | + } |
|
6579 | + } |
|
6580 | + return $buyPrice; |
|
6581 | + } |
|
6582 | + |
|
6583 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
6584 | + /** |
|
6585 | + * Show photos of an object (nbmax maximum), into several columns |
|
6586 | + * |
|
6587 | + * @param string $modulepart 'product', 'ticket', ... |
|
6588 | + * @param string $sdir Directory to scan (full absolute path) |
|
6589 | + * @param int $size 0=original size, 1='small' use thumbnail if possible |
|
6590 | + * @param int $nbmax Nombre maximum de photos (0=pas de max) |
|
6591 | + * @param int $nbbyrow Number of image per line or -1 to use div. Used only if size=1. |
|
6592 | + * @param int $showfilename 1=Show filename |
|
6593 | + * @param int $showaction 1=Show icon with action links (resize, delete) |
|
6594 | + * @param int $maxHeight Max height of original image when size='small' (so we can use original even if small requested). If 0, always use 'small' thumb image. |
|
6595 | + * @param int $maxWidth Max width of original image when size='small' |
|
6596 | + * @param int $nolink Do not add a href link to view enlarged imaged into a new tab |
|
6597 | + * @param int $notitle Do not add title tag on image |
|
6598 | + * @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead) |
|
6599 | + * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto |
|
6600 | + */ |
|
6601 | + 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 | + { |
|
6603 | + // phpcs:enable |
|
6604 | + global $conf,$user,$langs; |
|
6605 | + |
|
6606 | + include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; |
|
6607 | + include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; |
|
6608 | + |
|
6609 | + $sortfield='position_name'; |
|
6610 | + $sortorder='asc'; |
|
6611 | + |
|
6612 | + $dir = $sdir . '/'; |
|
6613 | + $pdir = '/'; |
|
6614 | + if ($modulepart == 'ticket') |
|
6615 | + { |
|
6616 | + $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
6617 | + $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
6618 | + } |
|
6619 | + else |
|
6620 | + { |
|
6621 | + $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
6622 | + $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
6623 | + } |
|
6624 | + |
|
6625 | + // For backward compatibility |
|
6626 | + if ($modulepart == 'product' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
6627 | + { |
|
6628 | + $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
6629 | + $pdir = '/' . get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
6630 | + } |
|
6631 | + |
|
6632 | + // Defined relative dir to DOL_DATA_ROOT |
|
6633 | + $relativedir = ''; |
|
6634 | + if ($dir) |
|
6635 | + { |
|
6636 | + $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
6637 | + $relativedir = preg_replace('/^[\\/]/','',$relativedir); |
|
6638 | + $relativedir = preg_replace('/[\\/]$/','',$relativedir); |
|
6639 | + } |
|
6640 | + |
|
6641 | + $dirthumb = $dir.'thumbs/'; |
|
6642 | + $pdirthumb = $pdir.'thumbs/'; |
|
6643 | + |
|
6644 | + $return ='<!-- Photo -->'."\n"; |
|
6645 | + $nbphoto=0; |
|
6646 | + |
|
6647 | + $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
6648 | + |
|
6649 | + /*if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs |
|
6650 | + { |
|
6651 | + $filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
6652 | + $filearray=array_merge($filearray, $filearrayold); |
|
6653 | + }*/ |
|
6654 | + |
|
6655 | + completeFileArrayWithDatabaseInfo($filearray, $relativedir); |
|
6656 | + |
|
6657 | + if (count($filearray)) |
|
6658 | + { |
|
6659 | + if ($sortfield && $sortorder) |
|
6660 | + { |
|
6661 | + $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
6662 | + } |
|
6663 | + |
|
6664 | + foreach($filearray as $key => $val) |
|
6665 | + { |
|
6666 | + $photo=''; |
|
6667 | + $file = $val['name']; |
|
6668 | + |
|
6669 | + //if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory |
|
6670 | + |
|
6671 | + //if (dol_is_file($dir.$file) && image_format_supported($file) >= 0) |
|
6672 | + if (image_format_supported($file) >= 0) |
|
6673 | + { |
|
6674 | + $nbphoto++; |
|
6675 | + $photo = $file; |
|
6676 | + $viewfilename = $file; |
|
6677 | + |
|
6678 | + if ($size == 1 || $size == 'small') { // Format vignette |
|
6679 | + |
|
6680 | + // Find name of thumb file |
|
6681 | + $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
|
6682 | + if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
6683 | + |
|
6684 | + // Get filesize of original file |
|
6685 | + $imgarray=dol_getImageSize($dir.$photo); |
|
6686 | + |
|
6687 | + if ($nbbyrow > 0) |
|
6688 | + { |
|
6689 | + if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
6690 | + |
|
6691 | + if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
6692 | + $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
|
6693 | + } |
|
6694 | + else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
|
6695 | + |
|
6696 | + $return.= "\n"; |
|
6697 | + |
|
6698 | + $relativefile=preg_replace('/^\//', '', $pdir.$photo); |
|
6699 | + if (empty($nolink)) |
|
6700 | + { |
|
6701 | + $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
6702 | + if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
6703 | + else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
6704 | + } |
|
6705 | + |
|
6706 | + // Show image (width height=$maxHeight) |
|
6707 | + // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
|
6708 | + $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile; |
|
6709 | + $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; |
|
6710 | + if ($notitle) $alt=''; |
|
6711 | + |
|
6712 | + if ($usesharelink) |
|
6713 | + { |
|
6714 | + if ($val['share']) |
|
6715 | + { |
|
6716 | + if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
6717 | + { |
|
6718 | + $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
6719 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
6720 | + } |
|
6721 | + else { |
|
6722 | + $return.= '<!-- Show original file -->'; |
|
6723 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
6724 | + } |
|
6725 | + } |
|
6726 | + else |
|
6727 | + { |
|
6728 | + $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
|
6729 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
6730 | + } |
|
6731 | + } |
|
6732 | + else |
|
6733 | + { |
|
6734 | + if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
6735 | + { |
|
6736 | + $return.= '<!-- Show thumb -->'; |
|
6737 | + $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).'">'; |
|
6738 | + } |
|
6739 | + else { |
|
6740 | + $return.= '<!-- Show original file -->'; |
|
6741 | + $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).'">'; |
|
6742 | + } |
|
6743 | + } |
|
6744 | + |
|
6745 | + if (empty($nolink)) $return.= '</a>'; |
|
6746 | + $return.="\n"; |
|
6747 | + |
|
6748 | + if ($showfilename) $return.= '<br>'.$viewfilename; |
|
6749 | + if ($showaction) |
|
6750 | + { |
|
6751 | + $return.= '<br>'; |
|
6752 | + // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
|
6753 | + if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) |
|
6754 | + { |
|
6755 | + $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' </a>'; |
|
6756 | + } |
|
6757 | + // Special cas for product |
|
6758 | + if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
6759 | + { |
|
6760 | + // Link to resize |
|
6761 | + $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 | + |
|
6763 | + // Link to delete |
|
6764 | + $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
6765 | + $return.= img_delete().'</a>'; |
|
6766 | + } |
|
6767 | + } |
|
6768 | + $return.= "\n"; |
|
6769 | + |
|
6770 | + if ($nbbyrow > 0) |
|
6771 | + { |
|
6772 | + $return.= '</td>'; |
|
6773 | + if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
6774 | + } |
|
6775 | + else if ($nbbyrow < 0) $return.='</div>'; |
|
6776 | + } |
|
6777 | + |
|
6778 | + if (empty($size)) { // Format origine |
|
6779 | + $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
6780 | + |
|
6781 | + if ($showfilename) $return.= '<br>'.$viewfilename; |
|
6782 | + if ($showaction) |
|
6783 | + { |
|
6784 | + // Special case for product |
|
6785 | + if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
6786 | + { |
|
6787 | + // Link to resize |
|
6788 | + $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 | + |
|
6790 | + // Link to delete |
|
6791 | + $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
6792 | + $return.= img_delete().'</a>'; |
|
6793 | + } |
|
6794 | + } |
|
6795 | + } |
|
6796 | + |
|
6797 | + // On continue ou on arrete de boucler ? |
|
6798 | + if ($nbmax && $nbphoto >= $nbmax) break; |
|
6799 | + } |
|
6800 | + } |
|
6801 | + |
|
6802 | + if ($size==1 || $size=='small') |
|
6803 | + { |
|
6804 | + if ($nbbyrow > 0) |
|
6805 | + { |
|
6806 | + // Ferme tableau |
|
6807 | + while ($nbphoto % $nbbyrow) |
|
6808 | + { |
|
6809 | + $return.= '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; |
|
6810 | + $nbphoto++; |
|
6811 | + } |
|
6812 | + |
|
6813 | + if ($nbphoto) $return.= '</table>'; |
|
6814 | + } |
|
6815 | + } |
|
6816 | + } |
|
6817 | + |
|
6818 | + $this->nbphoto = $nbphoto; |
|
6819 | + |
|
6820 | + return $return; |
|
6821 | + } |
|
6822 | + |
|
6823 | + |
|
6824 | + /** |
|
6825 | + * Function test if type is array |
|
6826 | + * |
|
6827 | + * @param array $info content informations of field |
|
6828 | + * @return bool |
|
6829 | + */ |
|
6830 | + protected function isArray($info) |
|
6831 | + { |
|
6832 | + if(is_array($info)) |
|
6833 | + { |
|
6834 | + if(isset($info['type']) && $info['type']=='array') return true; |
|
6835 | + else return false; |
|
6836 | + } |
|
6837 | + else return false; |
|
6838 | + } |
|
6839 | + |
|
6840 | + /** |
|
6841 | + * Function test if type is null |
|
6842 | + * |
|
6843 | + * @param array $info content informations of field |
|
6844 | + * @return bool |
|
6845 | + */ |
|
6846 | + protected function isNull($info) |
|
6847 | + { |
|
6848 | + if(is_array($info)) |
|
6849 | + { |
|
6850 | + if(isset($info['type']) && $info['type']=='null') return true; |
|
6851 | + else return false; |
|
6852 | + } |
|
6853 | + else return false; |
|
6854 | + } |
|
6855 | + |
|
6856 | + /** |
|
6857 | + * Function test if type is date |
|
6858 | + * |
|
6859 | + * @param array $info content informations of field |
|
6860 | + * @return bool |
|
6861 | + */ |
|
6862 | + public function isDate($info) |
|
6863 | + { |
|
6864 | + if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
6865 | + else return false; |
|
6866 | + } |
|
6867 | + |
|
6868 | + /** |
|
6869 | + * Function test if type is integer |
|
6870 | + * |
|
6871 | + * @param array $info content informations of field |
|
6872 | + * @return bool |
|
6873 | + */ |
|
6874 | + public function isInt($info) |
|
6875 | + { |
|
6876 | + if(is_array($info)) |
|
6877 | + { |
|
6878 | + if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true; |
|
6879 | + else return false; |
|
6880 | + } |
|
6881 | + else return false; |
|
6882 | + } |
|
6883 | + |
|
6884 | + /** |
|
6885 | + * Function test if type is float |
|
6886 | + * |
|
6887 | + * @param array $info content informations of field |
|
6888 | + * @return bool |
|
6889 | + */ |
|
6890 | + public function isFloat($info) |
|
6891 | + { |
|
6892 | + if(is_array($info)) |
|
6893 | + { |
|
6894 | + if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true; |
|
6895 | + else return false; |
|
6896 | + } |
|
6897 | + else return false; |
|
6898 | + } |
|
6899 | + |
|
6900 | + /** |
|
6901 | + * Function test if type is text |
|
6902 | + * |
|
6903 | + * @param array $info content informations of field |
|
6904 | + * @return bool |
|
6905 | + */ |
|
6906 | + public function isText($info) |
|
6907 | + { |
|
6908 | + if(is_array($info)) |
|
6909 | + { |
|
6910 | + if(isset($info['type']) && $info['type']=='text') return true; |
|
6911 | + else return false; |
|
6912 | + } |
|
6913 | + else return false; |
|
6914 | + } |
|
6915 | + |
|
6916 | + /** |
|
6917 | + * Function test if is indexed |
|
6918 | + * |
|
6919 | + * @param array $info content informations of field |
|
6920 | + * @return bool |
|
6921 | + */ |
|
6922 | + protected function isIndex($info) |
|
6923 | + { |
|
6924 | + if(is_array($info)) |
|
6925 | + { |
|
6926 | + if(isset($info['index']) && $info['index']==true) return true; |
|
6927 | + else return false; |
|
6928 | + } |
|
6929 | + else return false; |
|
6930 | + } |
|
6931 | + |
|
6932 | + /** |
|
6933 | + * Function to prepare the values to insert. |
|
6934 | + * Note $this->${field} are set by the page that make the createCommon or the updateCommon. |
|
6935 | + * |
|
6936 | + * @return array |
|
6937 | + */ |
|
6938 | + protected function setSaveQuery() |
|
6939 | + { |
|
6940 | + global $conf; |
|
6941 | + |
|
6942 | + $queryarray=array(); |
|
6943 | + foreach ($this->fields as $field=>$info) // Loop on definition of fields |
|
6944 | + { |
|
6945 | + // Depending on field type ('datetime', ...) |
|
6946 | + if($this->isDate($info)) |
|
6947 | + { |
|
6948 | + if(empty($this->{$field})) |
|
6949 | + { |
|
6950 | + $queryarray[$field] = null; |
|
6951 | + } |
|
6952 | + else |
|
6953 | + { |
|
6954 | + $queryarray[$field] = $this->db->idate($this->{$field}); |
|
6955 | + } |
|
6956 | + } |
|
6957 | + else if($this->isArray($info)) |
|
6958 | + { |
|
6959 | + if(! empty($this->{$field})) { |
|
6960 | + if(! is_array($this->{$field})) { |
|
6961 | + $this->{$field} = array($this->{$field}); |
|
6962 | + } |
|
6963 | + $queryarray[$field] = serialize($this->{$field}); |
|
6964 | + } else { |
|
6965 | + $queryarray[$field] = null; |
|
6966 | + } |
|
6967 | + } |
|
6968 | + else if($this->isInt($info)) |
|
6969 | + { |
|
6970 | + if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity; |
|
6971 | + else |
|
6972 | + { |
|
6973 | + $queryarray[$field] = (int) price2num($this->{$field}); |
|
6974 | + if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
6975 | + } |
|
6976 | + } |
|
6977 | + else if($this->isFloat($info)) |
|
6978 | + { |
|
6979 | + $queryarray[$field] = (double) price2num($this->{$field}); |
|
6980 | + if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
6981 | + } |
|
6982 | + else |
|
6983 | + { |
|
6984 | + $queryarray[$field] = $this->{$field}; |
|
6985 | + } |
|
6986 | + |
|
6987 | + if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
|
6988 | + if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
6989 | + } |
|
6990 | + |
|
6991 | + return $queryarray; |
|
6992 | + } |
|
6993 | + |
|
6994 | + /** |
|
6995 | + * Function to load data from a SQL pointer into properties of current object $this |
|
6996 | + * |
|
6997 | + * @param stdClass $obj Contain data of object from database |
|
6998 | + * @return void |
|
6999 | + */ |
|
7000 | + protected function setVarsFromFetchObj(&$obj) |
|
7001 | + { |
|
7002 | + foreach ($this->fields as $field => $info) |
|
7003 | + { |
|
7004 | + if($this->isDate($info)) |
|
7005 | + { |
|
7006 | + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; |
|
7007 | + else $this->{$field} = strtotime($obj->{$field}); |
|
7008 | + } |
|
7009 | + elseif($this->isArray($info)) |
|
7010 | + { |
|
7011 | + if(! empty($obj->{$field})) { |
|
7012 | + $this->{$field} = @unserialize($obj->{$field}); |
|
7013 | + // Hack for data not in UTF8 |
|
7014 | + if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field})); |
|
7015 | + } else { |
|
7016 | + $this->{$field} = array(); |
|
7017 | + } |
|
7018 | + } |
|
7019 | + elseif($this->isInt($info)) |
|
7020 | + { |
|
7021 | + if ($field == 'rowid') $this->id = (int) $obj->{$field}; |
|
7022 | + else $this->{$field} = (int) $obj->{$field}; |
|
7023 | + } |
|
7024 | + elseif($this->isFloat($info)) |
|
7025 | + { |
|
7026 | + $this->{$field} = (double) $obj->{$field}; |
|
7027 | + } |
|
7028 | + elseif($this->isNull($info)) |
|
7029 | + { |
|
7030 | + $val = $obj->{$field}; |
|
7031 | + // zero is not null |
|
7032 | + $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); |
|
7033 | + } |
|
7034 | + else |
|
7035 | + { |
|
7036 | + $this->{$field} = $obj->{$field}; |
|
7037 | + } |
|
7038 | + } |
|
7039 | + |
|
7040 | + // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
|
7041 | + if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
7042 | + } |
|
7043 | + |
|
7044 | + /** |
|
7045 | + * Function to concat keys of fields |
|
7046 | + * |
|
7047 | + * @return string |
|
7048 | + */ |
|
7049 | + protected function getFieldList() |
|
7050 | + { |
|
7051 | + $keys = array_keys($this->fields); |
|
7052 | + return implode(',', $keys); |
|
7053 | + } |
|
7054 | + |
|
7055 | + /** |
|
7056 | + * Add quote to field value if necessary |
|
7057 | + * |
|
7058 | + * @param string|int $value Value to protect |
|
7059 | + * @param array $fieldsentry Properties of field |
|
7060 | + * @return string |
|
7061 | + */ |
|
7062 | + protected function quote($value, $fieldsentry) |
|
7063 | + { |
|
7064 | + if (is_null($value)) return 'NULL'; |
|
7065 | + else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value"); |
|
7066 | + else return "'".$this->db->escape($value)."'"; |
|
7067 | + } |
|
7068 | + |
|
7069 | + |
|
7070 | + /** |
|
7071 | + * Create object into database |
|
7072 | + * |
|
7073 | + * @param User $user User that creates |
|
7074 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
7075 | + * @return int <0 if KO, Id of created object if OK |
|
7076 | + */ |
|
7077 | + public function createCommon(User $user, $notrigger = false) |
|
7078 | + { |
|
7079 | + global $langs; |
|
6095 | 7080 | |
6096 | - $obj = $this->db->fetch_object($resql); |
|
7081 | + $error = 0; |
|
6097 | 7082 | |
6098 | - // Several field into label (eq table:code|libelle:rowid) |
|
6099 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
7083 | + $now=dol_now(); |
|
6100 | 7084 | |
6101 | - if(is_array($fields_label) && count($fields_label)>1) |
|
6102 | - { |
|
6103 | - foreach ($fields_label as $field_toshow) |
|
6104 | - { |
|
6105 | - $translabel=''; |
|
6106 | - if (!empty($obj->$field_toshow)) { |
|
6107 | - $translabel=$langs->trans($obj->$field_toshow); |
|
6108 | - } |
|
6109 | - if ($translabel!=$field_toshow) { |
|
6110 | - $value.=dol_trunc($translabel,18).' '; |
|
6111 | - }else { |
|
6112 | - $value.=$obj->$field_toshow.' '; |
|
6113 | - } |
|
6114 | - } |
|
6115 | - } |
|
6116 | - else |
|
6117 | - { |
|
6118 | - $translabel=''; |
|
6119 | - if (!empty($obj->{$InfoFieldList[1]})) { |
|
6120 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
6121 | - } |
|
6122 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
6123 | - $value=dol_trunc($translabel,18); |
|
6124 | - }else { |
|
6125 | - $value=$obj->{$InfoFieldList[1]}; |
|
6126 | - } |
|
6127 | - } |
|
6128 | - } |
|
6129 | - else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
6130 | - } |
|
6131 | - elseif ($type == 'radio') |
|
6132 | - { |
|
6133 | - $value=$param['options'][$value]; |
|
6134 | - } |
|
6135 | - elseif ($type == 'checkbox') |
|
6136 | - { |
|
6137 | - $value_arr=explode(',',$value); |
|
6138 | - $value=''; |
|
6139 | - if (is_array($value_arr) && count($value_arr)>0) |
|
6140 | - { |
|
6141 | - foreach ($value_arr as $keyval=>$valueval) { |
|
6142 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
6143 | - } |
|
6144 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
6145 | - } |
|
6146 | - } |
|
6147 | - elseif ($type == 'chkbxlst') |
|
6148 | - { |
|
6149 | - $value_arr = explode(',', $value); |
|
6150 | - |
|
6151 | - $param_list = array_keys($param['options']); |
|
6152 | - $InfoFieldList = explode(":", $param_list[0]); |
|
6153 | - |
|
6154 | - $selectkey = "rowid"; |
|
6155 | - $keyList = 'rowid'; |
|
6156 | - |
|
6157 | - if (count($InfoFieldList) >= 3) { |
|
6158 | - $selectkey = $InfoFieldList[2]; |
|
6159 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
6160 | - } |
|
6161 | - |
|
6162 | - $fields_label = explode('|', $InfoFieldList[1]); |
|
6163 | - if (is_array($fields_label)) { |
|
6164 | - $keyList .= ', '; |
|
6165 | - $keyList .= implode(', ', $fields_label); |
|
6166 | - } |
|
6167 | - |
|
6168 | - $sql = 'SELECT ' . $keyList; |
|
6169 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
6170 | - if (strpos($InfoFieldList[4], 'extra') !== false) { |
|
6171 | - $sql .= ' as main'; |
|
6172 | - } |
|
6173 | - // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
6174 | - // $sql.= ' AND entity = '.$conf->entity; |
|
6175 | - |
|
6176 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
6177 | - $resql = $this->db->query($sql); |
|
6178 | - if ($resql) { |
|
6179 | - $value = ''; // value was used, so now we reste it to use it to build final output |
|
6180 | - $toprint=array(); |
|
6181 | - while ( $obj = $this->db->fetch_object($resql) ) { |
|
6182 | - |
|
6183 | - // Several field into label (eq table:code|libelle:rowid) |
|
6184 | - $fields_label = explode('|', $InfoFieldList[1]); |
|
6185 | - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
|
6186 | - if (is_array($fields_label) && count($fields_label) > 1) { |
|
6187 | - foreach ( $fields_label as $field_toshow ) { |
|
6188 | - $translabel = ''; |
|
6189 | - if (! empty($obj->$field_toshow)) { |
|
6190 | - $translabel = $langs->trans($obj->$field_toshow); |
|
6191 | - } |
|
6192 | - if ($translabel != $field_toshow) { |
|
6193 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
6194 | - } else { |
|
6195 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
6196 | - } |
|
6197 | - } |
|
6198 | - } else { |
|
6199 | - $translabel = ''; |
|
6200 | - if (! empty($obj->{$InfoFieldList[1]})) { |
|
6201 | - $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
6202 | - } |
|
6203 | - if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
6204 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
6205 | - } else { |
|
6206 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
6207 | - } |
|
6208 | - } |
|
6209 | - } |
|
6210 | - } |
|
6211 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
6212 | - } else { |
|
6213 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
6214 | - } |
|
6215 | - } |
|
6216 | - elseif ($type == 'link') |
|
6217 | - { |
|
6218 | - $out=''; |
|
6219 | - |
|
6220 | - // only if something to display (perf) |
|
6221 | - if ($value) |
|
6222 | - { |
|
6223 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
7085 | + $fieldvalues = $this->setSaveQuery(); |
|
7086 | + if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now); |
|
7087 | + if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id; |
|
7088 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
6224 | 7089 | |
6225 | - $InfoFieldList = explode(":", $param_list[0]); |
|
6226 | - $classname=$InfoFieldList[0]; |
|
6227 | - $classpath=$InfoFieldList[1]; |
|
6228 | - $getnomurlparam=(empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
6229 | - if (! empty($classpath)) |
|
6230 | - { |
|
6231 | - dol_include_once($InfoFieldList[1]); |
|
6232 | - if ($classname && class_exists($classname)) |
|
6233 | - { |
|
6234 | - $object = new $classname($this->db); |
|
6235 | - $object->fetch($value); |
|
6236 | - $value=$object->getNomUrl($getnomurlparam); |
|
6237 | - } |
|
6238 | - } |
|
6239 | - else |
|
6240 | - { |
|
6241 | - dol_syslog('Error bad setup of extrafield', LOG_WARNING); |
|
6242 | - return 'Error bad setup of extrafield'; |
|
6243 | - } |
|
6244 | - } |
|
6245 | - else $value=''; |
|
6246 | - } |
|
6247 | - elseif ($type == 'text' || $type == 'html') |
|
6248 | - { |
|
6249 | - $value=dol_htmlentitiesbr($value); |
|
6250 | - } |
|
6251 | - elseif ($type == 'password') |
|
6252 | - { |
|
6253 | - $value=preg_replace('/./i','*',$value); |
|
6254 | - } |
|
6255 | - elseif ($type == 'array') |
|
6256 | - { |
|
6257 | - $value = implode('<br>', $value); |
|
6258 | - } |
|
6259 | - |
|
6260 | - //print $type.'-'.$size; |
|
6261 | - $out=$value; |
|
6262 | - |
|
6263 | - return $out; |
|
6264 | - } |
|
6265 | - |
|
6266 | - |
|
6267 | - /** |
|
6268 | - * Function to show lines of extrafields with output datas |
|
6269 | - * |
|
6270 | - * @param Extrafields $extrafields Extrafield Object |
|
6271 | - * @param string $mode Show output (view) or input (edit) for extrafield |
|
6272 | - * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan) |
|
6273 | - * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) |
|
6274 | - * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) |
|
6275 | - * @param string $onetrtd All fields in same tr td |
|
6276 | - * @return string |
|
6277 | - */ |
|
6278 | - function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) |
|
6279 | - { |
|
6280 | - global $db, $conf, $langs, $action, $form; |
|
6281 | - |
|
6282 | - if (! is_object($form)) $form=new Form($db); |
|
6283 | - |
|
6284 | - $out = ''; |
|
6285 | - |
|
6286 | - if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) |
|
6287 | - { |
|
6288 | - $out .= "\n"; |
|
6289 | - $out .= '<!-- showOptionalsInput --> '; |
|
6290 | - $out .= "\n"; |
|
6291 | - |
|
6292 | - $e = 0; |
|
6293 | - foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
6294 | - { |
|
6295 | - // Show only the key field in params |
|
6296 | - if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue; |
|
7090 | + $keys=array(); |
|
7091 | + $values = array(); |
|
7092 | + foreach ($fieldvalues as $k => $v) { |
|
7093 | + $keys[$k] = $k; |
|
7094 | + $value = $this->fields[$k]; |
|
7095 | + $values[$k] = $this->quote($v, $value); |
|
7096 | + } |
|
6297 | 7097 | |
6298 | - $enabled = 1; |
|
6299 | - if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
|
6300 | - { |
|
6301 | - $enabled = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1); |
|
6302 | - } |
|
7098 | + // Clean and check mandatory |
|
7099 | + foreach($keys as $key) |
|
7100 | + { |
|
7101 | + // If field is an implicit foreign key field |
|
7102 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; |
|
7103 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
6303 | 7104 | |
6304 | - $perms = 1; |
|
6305 | - if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) |
|
6306 | - { |
|
6307 | - $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
|
6308 | - } |
|
7105 | + //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
7106 | + if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
|
7107 | + { |
|
7108 | + $error++; |
|
7109 | + $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
7110 | + } |
|
6309 | 7111 | |
6310 | - 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 (empty($perms)) continue; |
|
7112 | + // If field is an implicit foreign key field |
|
7113 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null'; |
|
7114 | + if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
7115 | + } |
|
6312 | 7116 | |
6313 | - // Load language if required |
|
6314 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
7117 | + if ($error) return -1; |
|
6315 | 7118 | |
6316 | - $colspan='3'; |
|
6317 | - if (is_array($params) && count($params)>0) { |
|
6318 | - if (array_key_exists('colspan',$params)) { |
|
6319 | - $colspan=$params['colspan']; |
|
6320 | - } |
|
6321 | - } |
|
7119 | + $this->db->begin(); |
|
6322 | 7120 | |
6323 | - switch($mode) { |
|
6324 | - case "view": |
|
6325 | - $value=$this->array_options["options_".$key.$keysuffix]; |
|
6326 | - break; |
|
6327 | - case "edit": |
|
6328 | - $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
6329 | - // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc') |
|
6330 | - if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
|
6331 | - { |
|
6332 | - if (is_array($getposttemp)) { |
|
6333 | - // $getposttemp is an array but following code expects a comma separated string |
|
6334 | - $value = implode(",", $getposttemp); |
|
6335 | - } else { |
|
6336 | - $value = $getposttemp; |
|
6337 | - } |
|
6338 | - } else { |
|
6339 | - $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
6340 | - } |
|
6341 | - //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
|
6342 | - break; |
|
6343 | - } |
|
7121 | + if (! $error) |
|
7122 | + { |
|
7123 | + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
|
7124 | + $sql.= ' ('.implode( ", ", $keys ).')'; |
|
7125 | + $sql.= ' VALUES ('.implode( ", ", $values ).')'; |
|
7126 | + |
|
7127 | + $res = $this->db->query($sql); |
|
7128 | + if ($res===false) { |
|
7129 | + $error++; |
|
7130 | + $this->errors[] = $this->db->lasterror(); |
|
7131 | + } |
|
7132 | + } |
|
6344 | 7133 | |
6345 | - if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') |
|
6346 | - { |
|
6347 | - $out .= $extrafields->showSeparator($key, $this); |
|
6348 | - } |
|
6349 | - else |
|
6350 | - { |
|
6351 | - $csstyle=''; |
|
6352 | - $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
6353 | - if (is_array($params) && count($params)>0) { |
|
6354 | - if (array_key_exists('style',$params)) { |
|
6355 | - $csstyle=$params['style']; |
|
6356 | - } |
|
6357 | - } |
|
7134 | + if (! $error) |
|
7135 | + { |
|
7136 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
7137 | + } |
|
6358 | 7138 | |
6359 | - // add html5 elements |
|
6360 | - $domData = ' data-element="extrafield"'; |
|
6361 | - $domData .= ' data-targetelement="'.$this->element.'"'; |
|
6362 | - $domData .= ' data-targetid="'.$this->id.'"'; |
|
7139 | + // Create extrafields |
|
7140 | + if (! $error) |
|
7141 | + { |
|
7142 | + $result=$this->insertExtraFields(); |
|
7143 | + if ($result < 0) $error++; |
|
7144 | + } |
|
6363 | 7145 | |
6364 | - $html_id = !empty($this->id) ? 'extrarow-'.$this->element.'_'.$key.'_'.$this->id : ''; |
|
7146 | + // Triggers |
|
7147 | + if (! $error && ! $notrigger) |
|
7148 | + { |
|
7149 | + // Call triggers |
|
7150 | + $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
7151 | + if ($result < 0) { $error++; } |
|
7152 | + // End call triggers |
|
7153 | + } |
|
6365 | 7154 | |
6366 | - $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
|
7155 | + // Commit or rollback |
|
7156 | + if ($error) { |
|
7157 | + $this->db->rollback(); |
|
7158 | + return -1; |
|
7159 | + } else { |
|
7160 | + $this->db->commit(); |
|
7161 | + return $this->id; |
|
7162 | + } |
|
7163 | + } |
|
6367 | 7164 | |
6368 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
6369 | - { |
|
6370 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; } |
|
6371 | - } |
|
6372 | 7165 | |
6373 | - if ($action == 'selectlines') { $colspan++; } |
|
7166 | + /** |
|
7167 | + * Load object in memory from the database |
|
7168 | + * |
|
7169 | + * @param int $id Id object |
|
7170 | + * @param string $ref Ref |
|
7171 | + * @param string $morewhere More SQL filters (' AND ...') |
|
7172 | + * @return int <0 if KO, 0 if not found, >0 if OK |
|
7173 | + */ |
|
7174 | + public function fetchCommon($id, $ref = null, $morewhere = '') |
|
7175 | + { |
|
7176 | + if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
|
6374 | 7177 | |
6375 | - // Convert date into timestamp format (value in memory must be a timestamp) |
|
6376 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime'))) |
|
6377 | - { |
|
6378 | - $datenotinstring = $this->array_options['options_' . $key]; |
|
6379 | - if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
6380 | - { |
|
6381 | - $datenotinstring = $this->db->jdate($datenotinstring); |
|
6382 | - } |
|
6383 | - $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 | - } |
|
6385 | - // Convert float submited string into real php numeric (value in memory must be a php numeric) |
|
6386 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double'))) |
|
6387 | - { |
|
6388 | - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)):$this->array_options['options_'.$key]; |
|
6389 | - } |
|
6390 | - |
|
6391 | - $labeltoshow = $langs->trans($label); |
|
6392 | - |
|
6393 | - $out .= '<td class="titlefield'; |
|
6394 | - if (GETPOST('action','none') == 'create') $out.='create'; |
|
6395 | - if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
6396 | - $out .= '">'; |
|
6397 | - if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
6398 | - else $out .= $labeltoshow; |
|
6399 | - $out .= '</td>'; |
|
6400 | - |
|
6401 | - $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
|
6402 | - $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
6403 | - |
|
6404 | - switch($mode) { |
|
6405 | - case "view": |
|
6406 | - $out .= $extrafields->showOutputField($key, $value); |
|
6407 | - break; |
|
6408 | - case "edit": |
|
6409 | - $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id); |
|
6410 | - break; |
|
6411 | - } |
|
6412 | - |
|
6413 | - $out .= '</td>'; |
|
6414 | - |
|
6415 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
6416 | - else $out .= '</tr>'; |
|
6417 | - $e++; |
|
6418 | - } |
|
6419 | - } |
|
6420 | - $out .= "\n"; |
|
6421 | - // Add code to manage list depending on others |
|
6422 | - if (! empty($conf->use_javascript_ajax)) { |
|
6423 | - $out .= ' |
|
6424 | - <script type="text/javascript"> |
|
6425 | - jQuery(document).ready(function() { |
|
6426 | - function showOptions(child_list, parent_list) |
|
6427 | - { |
|
6428 | - var val = $("select[name=\"options_"+parent_list+"\"]").val(); |
|
6429 | - var parentVal = parent_list + ":" + val; |
|
6430 | - if(val > 0) { |
|
6431 | - $("select[name=\""+child_list+"\"] option[parent]").hide(); |
|
6432 | - $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show(); |
|
6433 | - } else { |
|
6434 | - $("select[name=\""+child_list+"\"] option").show(); |
|
6435 | - } |
|
6436 | - } |
|
6437 | - function setListDependencies() { |
|
6438 | - jQuery("select option[parent]").parent().each(function() { |
|
6439 | - var child_list = $(this).attr("name"); |
|
6440 | - var parent = $(this).find("option[parent]:first").attr("parent"); |
|
6441 | - var infos = parent.split(":"); |
|
6442 | - var parent_list = infos[0]; |
|
6443 | - $("select[name=\""+parent_list+"\"]").change(function() { |
|
6444 | - showOptions(child_list, parent_list); |
|
6445 | - }); |
|
6446 | - }); |
|
6447 | - } |
|
7178 | + $sql = 'SELECT '.$this->getFieldList(); |
|
7179 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
6448 | 7180 | |
6449 | - setListDependencies(); |
|
6450 | - }); |
|
6451 | - </script>'."\n"; |
|
6452 | - $out .= '<!-- /showOptionalsInput --> '."\n"; |
|
6453 | - } |
|
6454 | - } |
|
6455 | - return $out; |
|
6456 | - } |
|
6457 | - |
|
6458 | - |
|
6459 | - /** |
|
6460 | - * Returns the rights used for this class |
|
6461 | - * @return stdClass |
|
6462 | - */ |
|
6463 | - public function getRights() |
|
6464 | - { |
|
6465 | - global $user; |
|
6466 | - |
|
6467 | - $element = $this->element; |
|
6468 | - if ($element == 'facturerec') $element='facture'; |
|
6469 | - |
|
6470 | - return $user->rights->{$element}; |
|
6471 | - } |
|
6472 | - |
|
6473 | - /** |
|
6474 | - * Function used to replace a thirdparty id with another one. |
|
6475 | - * This function is meant to be called from replaceThirdparty with the appropiate tables |
|
6476 | - * Column name fk_soc MUST be used to identify thirdparties |
|
6477 | - * |
|
6478 | - * @param DoliDB $db Database handler |
|
6479 | - * @param int $origin_id Old thirdparty id (the thirdparty to delete) |
|
6480 | - * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) |
|
6481 | - * @param string[] $tables Tables that need to be changed |
|
6482 | - * @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) |
|
6483 | - * @return bool True if success, False if error |
|
6484 | - */ |
|
6485 | - public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
6486 | - { |
|
6487 | - foreach ($tables as $table) |
|
6488 | - { |
|
6489 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
|
6490 | - |
|
6491 | - if (! $db->query($sql)) |
|
6492 | - { |
|
6493 | - 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 | - //$this->errors = $db->lasterror(); |
|
6495 | - return false; |
|
6496 | - } |
|
6497 | - } |
|
6498 | - |
|
6499 | - return true; |
|
6500 | - } |
|
6501 | - |
|
6502 | - /** |
|
6503 | - * Get buy price to use for margin calculation. This function is called when buy price is unknown. |
|
6504 | - * Set buy price = sell price if ForceBuyingPriceIfNull configured, |
|
6505 | - * else if calculation MARGIN_TYPE = 'costprice' and costprice is defined, use costprice as buyprice |
|
6506 | - * else if calculation MARGIN_TYPE = 'pmp' and pmp is calculated, use pmp as buyprice |
|
6507 | - * else set min buy price as buy price |
|
6508 | - * |
|
6509 | - * @param float $unitPrice Product unit price |
|
6510 | - * @param float $discountPercent Line discount percent |
|
6511 | - * @param int $fk_product Product id |
|
6512 | - * @return float <0 if KO, buyprice if OK |
|
6513 | - */ |
|
6514 | - public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) |
|
6515 | - { |
|
6516 | - global $conf; |
|
6517 | - |
|
6518 | - $buyPrice = 0; |
|
6519 | - |
|
6520 | - if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false |
|
6521 | - { |
|
6522 | - $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
|
6523 | - } |
|
6524 | - else |
|
6525 | - { |
|
6526 | - // Get cost price for margin calculation |
|
6527 | - if (! empty($fk_product)) |
|
6528 | - { |
|
6529 | - if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') |
|
6530 | - { |
|
6531 | - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
6532 | - $product = new Product($this->db); |
|
6533 | - $result = $product->fetch($fk_product); |
|
6534 | - if ($result <= 0) |
|
6535 | - { |
|
6536 | - $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
6537 | - return -1; |
|
6538 | - } |
|
6539 | - if ($product->cost_price > 0) |
|
6540 | - { |
|
6541 | - $buyPrice = $product->cost_price; |
|
6542 | - } |
|
6543 | - else if ($product->pmp > 0) |
|
6544 | - { |
|
6545 | - $buyPrice = $product->pmp; |
|
6546 | - } |
|
6547 | - } |
|
6548 | - else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') |
|
6549 | - { |
|
6550 | - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
6551 | - $product = new Product($this->db); |
|
6552 | - $result = $product->fetch($fk_product); |
|
6553 | - if ($result <= 0) |
|
6554 | - { |
|
6555 | - $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
6556 | - return -1; |
|
6557 | - } |
|
6558 | - if ($product->pmp > 0) |
|
6559 | - { |
|
6560 | - $buyPrice = $product->pmp; |
|
6561 | - } |
|
6562 | - } |
|
7181 | + if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
7182 | + elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
7183 | + else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
7184 | + if ($morewhere) $sql.= $morewhere; |
|
7185 | + $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
6563 | 7186 | |
6564 | - if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice'))) |
|
6565 | - { |
|
6566 | - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
6567 | - $productFournisseur = new ProductFournisseur($this->db); |
|
6568 | - if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) |
|
6569 | - { |
|
6570 | - $buyPrice = $productFournisseur->fourn_unitprice; |
|
6571 | - } |
|
6572 | - else if ($result < 0) |
|
6573 | - { |
|
6574 | - $this->errors[] = $productFournisseur->error; |
|
6575 | - return -2; |
|
6576 | - } |
|
6577 | - } |
|
6578 | - } |
|
6579 | - } |
|
6580 | - return $buyPrice; |
|
6581 | - } |
|
7187 | + $res = $this->db->query($sql); |
|
7188 | + if ($res) |
|
7189 | + { |
|
7190 | + $obj = $this->db->fetch_object($res); |
|
7191 | + if ($obj) |
|
7192 | + { |
|
7193 | + $this->setVarsFromFetchObj($obj); |
|
7194 | + return $this->id; |
|
7195 | + } |
|
7196 | + else |
|
7197 | + { |
|
7198 | + return 0; |
|
7199 | + } |
|
7200 | + } |
|
7201 | + else |
|
7202 | + { |
|
7203 | + $this->error = $this->db->lasterror(); |
|
7204 | + $this->errors[] = $this->error; |
|
7205 | + return -1; |
|
7206 | + } |
|
7207 | + } |
|
6582 | 7208 | |
6583 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
6584 | - /** |
|
6585 | - * Show photos of an object (nbmax maximum), into several columns |
|
6586 | - * |
|
6587 | - * @param string $modulepart 'product', 'ticket', ... |
|
6588 | - * @param string $sdir Directory to scan (full absolute path) |
|
6589 | - * @param int $size 0=original size, 1='small' use thumbnail if possible |
|
6590 | - * @param int $nbmax Nombre maximum de photos (0=pas de max) |
|
6591 | - * @param int $nbbyrow Number of image per line or -1 to use div. Used only if size=1. |
|
6592 | - * @param int $showfilename 1=Show filename |
|
6593 | - * @param int $showaction 1=Show icon with action links (resize, delete) |
|
6594 | - * @param int $maxHeight Max height of original image when size='small' (so we can use original even if small requested). If 0, always use 'small' thumb image. |
|
6595 | - * @param int $maxWidth Max width of original image when size='small' |
|
6596 | - * @param int $nolink Do not add a href link to view enlarged imaged into a new tab |
|
6597 | - * @param int $notitle Do not add title tag on image |
|
6598 | - * @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead) |
|
6599 | - * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto |
|
6600 | - */ |
|
6601 | - 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 | - { |
|
6603 | - // phpcs:enable |
|
6604 | - global $conf,$user,$langs; |
|
6605 | - |
|
6606 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; |
|
6607 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; |
|
6608 | - |
|
6609 | - $sortfield='position_name'; |
|
6610 | - $sortorder='asc'; |
|
6611 | - |
|
6612 | - $dir = $sdir . '/'; |
|
6613 | - $pdir = '/'; |
|
6614 | - if ($modulepart == 'ticket') |
|
6615 | - { |
|
6616 | - $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
6617 | - $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
6618 | - } |
|
6619 | - else |
|
6620 | - { |
|
6621 | - $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
6622 | - $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
6623 | - } |
|
6624 | - |
|
6625 | - // For backward compatibility |
|
6626 | - if ($modulepart == 'product' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
6627 | - { |
|
6628 | - $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
6629 | - $pdir = '/' . get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
6630 | - } |
|
6631 | - |
|
6632 | - // Defined relative dir to DOL_DATA_ROOT |
|
6633 | - $relativedir = ''; |
|
6634 | - if ($dir) |
|
6635 | - { |
|
6636 | - $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
6637 | - $relativedir = preg_replace('/^[\\/]/','',$relativedir); |
|
6638 | - $relativedir = preg_replace('/[\\/]$/','',$relativedir); |
|
6639 | - } |
|
6640 | - |
|
6641 | - $dirthumb = $dir.'thumbs/'; |
|
6642 | - $pdirthumb = $pdir.'thumbs/'; |
|
6643 | - |
|
6644 | - $return ='<!-- Photo -->'."\n"; |
|
6645 | - $nbphoto=0; |
|
6646 | - |
|
6647 | - $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
6648 | - |
|
6649 | - /*if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs |
|
6650 | - { |
|
6651 | - $filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
6652 | - $filearray=array_merge($filearray, $filearrayold); |
|
6653 | - }*/ |
|
7209 | + /** |
|
7210 | + * Update object into database |
|
7211 | + * |
|
7212 | + * @param User $user User that modifies |
|
7213 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
7214 | + * @return int <0 if KO, >0 if OK |
|
7215 | + */ |
|
7216 | + public function updateCommon(User $user, $notrigger = false) |
|
7217 | + { |
|
7218 | + global $conf, $langs; |
|
6654 | 7219 | |
6655 | - completeFileArrayWithDatabaseInfo($filearray, $relativedir); |
|
7220 | + $error = 0; |
|
6656 | 7221 | |
6657 | - if (count($filearray)) |
|
6658 | - { |
|
6659 | - if ($sortfield && $sortorder) |
|
6660 | - { |
|
6661 | - $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
6662 | - } |
|
7222 | + $now=dol_now(); |
|
6663 | 7223 | |
6664 | - foreach($filearray as $key => $val) |
|
6665 | - { |
|
6666 | - $photo=''; |
|
6667 | - $file = $val['name']; |
|
7224 | + $fieldvalues = $this->setSaveQuery(); |
|
7225 | + if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now); |
|
7226 | + if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id; |
|
7227 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
6668 | 7228 | |
6669 | - //if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory |
|
7229 | + $keys=array(); |
|
7230 | + $values = array(); |
|
7231 | + foreach ($fieldvalues as $k => $v) { |
|
7232 | + $keys[$k] = $k; |
|
7233 | + $value = $this->fields[$k]; |
|
7234 | + $values[$k] = $this->quote($v, $value); |
|
7235 | + $tmp[] = $k.'='.$this->quote($v, $this->fields[$k]); |
|
7236 | + } |
|
6670 | 7237 | |
6671 | - //if (dol_is_file($dir.$file) && image_format_supported($file) >= 0) |
|
6672 | - if (image_format_supported($file) >= 0) |
|
6673 | - { |
|
6674 | - $nbphoto++; |
|
6675 | - $photo = $file; |
|
6676 | - $viewfilename = $file; |
|
7238 | + // Clean and check mandatory |
|
7239 | + foreach($keys as $key) |
|
7240 | + { |
|
7241 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field |
|
7242 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
7243 | + |
|
7244 | + //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
7245 | + /* |
|
7246 | + if ($this->fields[$key]['notnull'] == 1 && empty($values[$key])) |
|
7247 | + { |
|
7248 | + $error++; |
|
7249 | + $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
7250 | + }*/ |
|
7251 | + } |
|
6677 | 7252 | |
6678 | - if ($size == 1 || $size == 'small') { // Format vignette |
|
7253 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
6679 | 7254 | |
6680 | - // Find name of thumb file |
|
6681 | - $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
|
6682 | - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
7255 | + $this->db->begin(); |
|
7256 | + if (! $error) |
|
7257 | + { |
|
7258 | + $res = $this->db->query($sql); |
|
7259 | + if ($res===false) |
|
7260 | + { |
|
7261 | + $error++; |
|
7262 | + $this->errors[] = $this->db->lasterror(); |
|
7263 | + } |
|
7264 | + } |
|
6683 | 7265 | |
6684 | - // Get filesize of original file |
|
6685 | - $imgarray=dol_getImageSize($dir.$photo); |
|
7266 | + // Update extrafield |
|
7267 | + if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) |
|
7268 | + { |
|
7269 | + $result=$this->insertExtraFields(); |
|
7270 | + if ($result < 0) |
|
7271 | + { |
|
7272 | + $error++; |
|
7273 | + } |
|
7274 | + } |
|
6686 | 7275 | |
6687 | - if ($nbbyrow > 0) |
|
6688 | - { |
|
6689 | - if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
7276 | + // Triggers |
|
7277 | + if (! $error && ! $notrigger) |
|
7278 | + { |
|
7279 | + // Call triggers |
|
7280 | + $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
7281 | + if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail |
|
7282 | + // End call triggers |
|
7283 | + } |
|
6690 | 7284 | |
6691 | - if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
6692 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
|
6693 | - } |
|
6694 | - else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
|
7285 | + // Commit or rollback |
|
7286 | + if ($error) { |
|
7287 | + $this->db->rollback(); |
|
7288 | + return -1; |
|
7289 | + } else { |
|
7290 | + $this->db->commit(); |
|
7291 | + return $this->id; |
|
7292 | + } |
|
7293 | + } |
|
6695 | 7294 | |
6696 | - $return.= "\n"; |
|
7295 | + /** |
|
7296 | + * Delete object in database |
|
7297 | + * |
|
7298 | + * @param User $user User that deletes |
|
7299 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
7300 | + * @param int $forcechilddeletion 0=no, 1=Force deletion of children |
|
7301 | + * @return int <=0 if KO, >0 if OK |
|
7302 | + */ |
|
7303 | + public function deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0) |
|
7304 | + { |
|
7305 | + $error=0; |
|
6697 | 7306 | |
6698 | - $relativefile=preg_replace('/^\//', '', $pdir.$photo); |
|
6699 | - if (empty($nolink)) |
|
6700 | - { |
|
6701 | - $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
6702 | - if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
6703 | - else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
6704 | - } |
|
7307 | + $this->db->begin(); |
|
6705 | 7308 | |
6706 | - // Show image (width height=$maxHeight) |
|
6707 | - // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
|
6708 | - $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile; |
|
6709 | - $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; |
|
6710 | - if ($notitle) $alt=''; |
|
6711 | - |
|
6712 | - if ($usesharelink) |
|
6713 | - { |
|
6714 | - if ($val['share']) |
|
6715 | - { |
|
6716 | - if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
6717 | - { |
|
6718 | - $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
6719 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
6720 | - } |
|
6721 | - else { |
|
6722 | - $return.= '<!-- Show original file -->'; |
|
6723 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
6724 | - } |
|
6725 | - } |
|
6726 | - else |
|
6727 | - { |
|
6728 | - $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
|
6729 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
6730 | - } |
|
6731 | - } |
|
6732 | - else |
|
6733 | - { |
|
6734 | - if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
6735 | - { |
|
6736 | - $return.= '<!-- Show thumb -->'; |
|
6737 | - $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).'">'; |
|
6738 | - } |
|
6739 | - else { |
|
6740 | - $return.= '<!-- Show original file -->'; |
|
6741 | - $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).'">'; |
|
6742 | - } |
|
6743 | - } |
|
7309 | + if ($forcechilddeletion) |
|
7310 | + { |
|
7311 | + foreach($this->childtables as $table) |
|
7312 | + { |
|
7313 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
|
7314 | + $resql = $this->db->query($sql); |
|
7315 | + if (! $resql) |
|
7316 | + { |
|
7317 | + $this->error=$this->db->lasterror(); |
|
7318 | + $this->errors[]=$this->error; |
|
7319 | + $this->db->rollback(); |
|
7320 | + return -1; |
|
7321 | + } |
|
7322 | + } |
|
7323 | + } |
|
7324 | + elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
7325 | + { |
|
7326 | + $objectisused = $this->isObjectUsed($this->id); |
|
7327 | + if (! empty($objectisused)) |
|
7328 | + { |
|
7329 | + dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
|
7330 | + $this->error='ErrorRecordHasChildren'; |
|
7331 | + $this->errors[]=$this->error; |
|
7332 | + $this->db->rollback(); |
|
7333 | + return 0; |
|
7334 | + } |
|
7335 | + } |
|
6744 | 7336 | |
6745 | - if (empty($nolink)) $return.= '</a>'; |
|
6746 | - $return.="\n"; |
|
6747 | - |
|
6748 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
6749 | - if ($showaction) |
|
6750 | - { |
|
6751 | - $return.= '<br>'; |
|
6752 | - // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
|
6753 | - if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) |
|
6754 | - { |
|
6755 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' </a>'; |
|
6756 | - } |
|
6757 | - // Special cas for product |
|
6758 | - if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
6759 | - { |
|
6760 | - // Link to resize |
|
6761 | - $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 | - |
|
6763 | - // Link to delete |
|
6764 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
6765 | - $return.= img_delete().'</a>'; |
|
6766 | - } |
|
6767 | - } |
|
6768 | - $return.= "\n"; |
|
7337 | + if (! $error) { |
|
7338 | + if (! $notrigger) { |
|
7339 | + // Call triggers |
|
7340 | + $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
7341 | + if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail |
|
7342 | + // End call triggers |
|
7343 | + } |
|
7344 | + } |
|
6769 | 7345 | |
6770 | - if ($nbbyrow > 0) |
|
6771 | - { |
|
6772 | - $return.= '</td>'; |
|
6773 | - if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
6774 | - } |
|
6775 | - else if ($nbbyrow < 0) $return.='</div>'; |
|
6776 | - } |
|
6777 | - |
|
6778 | - if (empty($size)) { // Format origine |
|
6779 | - $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
6780 | - |
|
6781 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
6782 | - if ($showaction) |
|
6783 | - { |
|
6784 | - // Special case for product |
|
6785 | - if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
6786 | - { |
|
6787 | - // Link to resize |
|
6788 | - $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 | - |
|
6790 | - // Link to delete |
|
6791 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
6792 | - $return.= img_delete().'</a>'; |
|
6793 | - } |
|
6794 | - } |
|
6795 | - } |
|
7346 | + if (! $error && ! empty($this->isextrafieldmanaged)) |
|
7347 | + { |
|
7348 | + $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
7349 | + $sql.= " WHERE fk_object=" . $this->id; |
|
6796 | 7350 | |
6797 | - // On continue ou on arrete de boucler ? |
|
6798 | - if ($nbmax && $nbphoto >= $nbmax) break; |
|
6799 | - } |
|
6800 | - } |
|
7351 | + $resql = $this->db->query($sql); |
|
7352 | + if (! $resql) |
|
7353 | + { |
|
7354 | + $this->errors[] = $this->db->lasterror(); |
|
7355 | + $error++; |
|
7356 | + } |
|
7357 | + } |
|
6801 | 7358 | |
6802 | - if ($size==1 || $size=='small') |
|
6803 | - { |
|
6804 | - if ($nbbyrow > 0) |
|
6805 | - { |
|
6806 | - // Ferme tableau |
|
6807 | - while ($nbphoto % $nbbyrow) |
|
6808 | - { |
|
6809 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; |
|
6810 | - $nbphoto++; |
|
6811 | - } |
|
6812 | - |
|
6813 | - if ($nbphoto) $return.= '</table>'; |
|
6814 | - } |
|
6815 | - } |
|
6816 | - } |
|
6817 | - |
|
6818 | - $this->nbphoto = $nbphoto; |
|
6819 | - |
|
6820 | - return $return; |
|
6821 | - } |
|
6822 | - |
|
6823 | - |
|
6824 | - /** |
|
6825 | - * Function test if type is array |
|
6826 | - * |
|
6827 | - * @param array $info content informations of field |
|
6828 | - * @return bool |
|
6829 | - */ |
|
6830 | - protected function isArray($info) |
|
6831 | - { |
|
6832 | - if(is_array($info)) |
|
6833 | - { |
|
6834 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
6835 | - else return false; |
|
6836 | - } |
|
6837 | - else return false; |
|
6838 | - } |
|
6839 | - |
|
6840 | - /** |
|
6841 | - * Function test if type is null |
|
6842 | - * |
|
6843 | - * @param array $info content informations of field |
|
6844 | - * @return bool |
|
6845 | - */ |
|
6846 | - protected function isNull($info) |
|
6847 | - { |
|
6848 | - if(is_array($info)) |
|
6849 | - { |
|
6850 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
6851 | - else return false; |
|
6852 | - } |
|
6853 | - else return false; |
|
6854 | - } |
|
6855 | - |
|
6856 | - /** |
|
6857 | - * Function test if type is date |
|
6858 | - * |
|
6859 | - * @param array $info content informations of field |
|
6860 | - * @return bool |
|
6861 | - */ |
|
6862 | - public function isDate($info) |
|
6863 | - { |
|
6864 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
6865 | - else return false; |
|
6866 | - } |
|
6867 | - |
|
6868 | - /** |
|
6869 | - * Function test if type is integer |
|
6870 | - * |
|
6871 | - * @param array $info content informations of field |
|
6872 | - * @return bool |
|
6873 | - */ |
|
6874 | - public function isInt($info) |
|
6875 | - { |
|
6876 | - if(is_array($info)) |
|
6877 | - { |
|
6878 | - if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true; |
|
6879 | - else return false; |
|
6880 | - } |
|
6881 | - else return false; |
|
6882 | - } |
|
6883 | - |
|
6884 | - /** |
|
6885 | - * Function test if type is float |
|
6886 | - * |
|
6887 | - * @param array $info content informations of field |
|
6888 | - * @return bool |
|
6889 | - */ |
|
6890 | - public function isFloat($info) |
|
6891 | - { |
|
6892 | - if(is_array($info)) |
|
6893 | - { |
|
6894 | - if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true; |
|
6895 | - else return false; |
|
6896 | - } |
|
6897 | - else return false; |
|
6898 | - } |
|
6899 | - |
|
6900 | - /** |
|
6901 | - * Function test if type is text |
|
6902 | - * |
|
6903 | - * @param array $info content informations of field |
|
6904 | - * @return bool |
|
6905 | - */ |
|
6906 | - public function isText($info) |
|
6907 | - { |
|
6908 | - if(is_array($info)) |
|
6909 | - { |
|
6910 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
6911 | - else return false; |
|
6912 | - } |
|
6913 | - else return false; |
|
6914 | - } |
|
6915 | - |
|
6916 | - /** |
|
6917 | - * Function test if is indexed |
|
6918 | - * |
|
6919 | - * @param array $info content informations of field |
|
6920 | - * @return bool |
|
6921 | - */ |
|
6922 | - protected function isIndex($info) |
|
6923 | - { |
|
6924 | - if(is_array($info)) |
|
6925 | - { |
|
6926 | - if(isset($info['index']) && $info['index']==true) return true; |
|
6927 | - else return false; |
|
6928 | - } |
|
6929 | - else return false; |
|
6930 | - } |
|
6931 | - |
|
6932 | - /** |
|
6933 | - * Function to prepare the values to insert. |
|
6934 | - * Note $this->${field} are set by the page that make the createCommon or the updateCommon. |
|
6935 | - * |
|
6936 | - * @return array |
|
6937 | - */ |
|
6938 | - protected function setSaveQuery() |
|
6939 | - { |
|
6940 | - global $conf; |
|
6941 | - |
|
6942 | - $queryarray=array(); |
|
6943 | - foreach ($this->fields as $field=>$info) // Loop on definition of fields |
|
6944 | - { |
|
6945 | - // Depending on field type ('datetime', ...) |
|
6946 | - if($this->isDate($info)) |
|
6947 | - { |
|
6948 | - if(empty($this->{$field})) |
|
6949 | - { |
|
6950 | - $queryarray[$field] = null; |
|
6951 | - } |
|
6952 | - else |
|
6953 | - { |
|
6954 | - $queryarray[$field] = $this->db->idate($this->{$field}); |
|
6955 | - } |
|
6956 | - } |
|
6957 | - else if($this->isArray($info)) |
|
6958 | - { |
|
6959 | - if(! empty($this->{$field})) { |
|
6960 | - if(! is_array($this->{$field})) { |
|
6961 | - $this->{$field} = array($this->{$field}); |
|
6962 | - } |
|
6963 | - $queryarray[$field] = serialize($this->{$field}); |
|
6964 | - } else { |
|
6965 | - $queryarray[$field] = null; |
|
6966 | - } |
|
6967 | - } |
|
6968 | - else if($this->isInt($info)) |
|
6969 | - { |
|
6970 | - if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity; |
|
6971 | - else |
|
6972 | - { |
|
6973 | - $queryarray[$field] = (int) price2num($this->{$field}); |
|
6974 | - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
6975 | - } |
|
6976 | - } |
|
6977 | - else if($this->isFloat($info)) |
|
6978 | - { |
|
6979 | - $queryarray[$field] = (double) price2num($this->{$field}); |
|
6980 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
6981 | - } |
|
6982 | - else |
|
6983 | - { |
|
6984 | - $queryarray[$field] = $this->{$field}; |
|
6985 | - } |
|
7359 | + if (! $error) |
|
7360 | + { |
|
7361 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
|
6986 | 7362 | |
6987 | - if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
|
6988 | - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
6989 | - } |
|
7363 | + $res = $this->db->query($sql); |
|
7364 | + if($res===false) { |
|
7365 | + $error++; |
|
7366 | + $this->errors[] = $this->db->lasterror(); |
|
7367 | + } |
|
7368 | + } |
|
6990 | 7369 | |
6991 | - return $queryarray; |
|
6992 | - } |
|
7370 | + // Commit or rollback |
|
7371 | + if ($error) { |
|
7372 | + $this->db->rollback(); |
|
7373 | + return -1; |
|
7374 | + } else { |
|
7375 | + $this->db->commit(); |
|
7376 | + return 1; |
|
7377 | + } |
|
7378 | + } |
|
6993 | 7379 | |
6994 | - /** |
|
6995 | - * Function to load data from a SQL pointer into properties of current object $this |
|
6996 | - * |
|
6997 | - * @param stdClass $obj Contain data of object from database |
|
7380 | + /** |
|
7381 | + * Initialise object with example values |
|
7382 | + * Id must be 0 if object instance is a specimen |
|
7383 | + * |
|
6998 | 7384 | * @return void |
6999 | - */ |
|
7000 | - protected function setVarsFromFetchObj(&$obj) |
|
7001 | - { |
|
7002 | - foreach ($this->fields as $field => $info) |
|
7003 | - { |
|
7004 | - if($this->isDate($info)) |
|
7005 | - { |
|
7006 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; |
|
7007 | - else $this->{$field} = strtotime($obj->{$field}); |
|
7008 | - } |
|
7009 | - elseif($this->isArray($info)) |
|
7010 | - { |
|
7011 | - if(! empty($obj->{$field})) { |
|
7012 | - $this->{$field} = @unserialize($obj->{$field}); |
|
7013 | - // Hack for data not in UTF8 |
|
7014 | - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field})); |
|
7015 | - } else { |
|
7016 | - $this->{$field} = array(); |
|
7017 | - } |
|
7018 | - } |
|
7019 | - elseif($this->isInt($info)) |
|
7020 | - { |
|
7021 | - if ($field == 'rowid') $this->id = (int) $obj->{$field}; |
|
7022 | - else $this->{$field} = (int) $obj->{$field}; |
|
7023 | - } |
|
7024 | - elseif($this->isFloat($info)) |
|
7025 | - { |
|
7026 | - $this->{$field} = (double) $obj->{$field}; |
|
7027 | - } |
|
7028 | - elseif($this->isNull($info)) |
|
7029 | - { |
|
7030 | - $val = $obj->{$field}; |
|
7031 | - // zero is not null |
|
7032 | - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); |
|
7033 | - } |
|
7034 | - else |
|
7035 | - { |
|
7036 | - $this->{$field} = $obj->{$field}; |
|
7037 | - } |
|
7038 | - } |
|
7039 | - |
|
7040 | - // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
|
7041 | - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
7042 | - } |
|
7043 | - |
|
7044 | - /** |
|
7045 | - * Function to concat keys of fields |
|
7046 | - * |
|
7047 | - * @return string |
|
7048 | - */ |
|
7049 | - protected function getFieldList() |
|
7050 | - { |
|
7051 | - $keys = array_keys($this->fields); |
|
7052 | - return implode(',', $keys); |
|
7053 | - } |
|
7054 | - |
|
7055 | - /** |
|
7056 | - * Add quote to field value if necessary |
|
7057 | - * |
|
7058 | - * @param string|int $value Value to protect |
|
7059 | - * @param array $fieldsentry Properties of field |
|
7060 | - * @return string |
|
7061 | - */ |
|
7062 | - protected function quote($value, $fieldsentry) |
|
7385 | + */ |
|
7386 | + public function initAsSpecimenCommon() |
|
7063 | 7387 | { |
7064 | - if (is_null($value)) return 'NULL'; |
|
7065 | - else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value"); |
|
7066 | - else return "'".$this->db->escape($value)."'"; |
|
7067 | - } |
|
7068 | - |
|
7069 | - |
|
7070 | - /** |
|
7071 | - * Create object into database |
|
7072 | - * |
|
7073 | - * @param User $user User that creates |
|
7074 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
7075 | - * @return int <0 if KO, Id of created object if OK |
|
7076 | - */ |
|
7077 | - public function createCommon(User $user, $notrigger = false) |
|
7078 | - { |
|
7079 | - global $langs; |
|
7080 | - |
|
7081 | - $error = 0; |
|
7082 | - |
|
7083 | - $now=dol_now(); |
|
7084 | - |
|
7085 | - $fieldvalues = $this->setSaveQuery(); |
|
7086 | - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now); |
|
7087 | - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id; |
|
7088 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
7089 | - |
|
7090 | - $keys=array(); |
|
7091 | - $values = array(); |
|
7092 | - foreach ($fieldvalues as $k => $v) { |
|
7093 | - $keys[$k] = $k; |
|
7094 | - $value = $this->fields[$k]; |
|
7095 | - $values[$k] = $this->quote($v, $value); |
|
7096 | - } |
|
7097 | - |
|
7098 | - // Clean and check mandatory |
|
7099 | - foreach($keys as $key) |
|
7100 | - { |
|
7101 | - // If field is an implicit foreign key field |
|
7102 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; |
|
7103 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
7104 | - |
|
7105 | - //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
7106 | - if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
|
7107 | - { |
|
7108 | - $error++; |
|
7109 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
7110 | - } |
|
7111 | - |
|
7112 | - // If field is an implicit foreign key field |
|
7113 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null'; |
|
7114 | - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
7115 | - } |
|
7116 | - |
|
7117 | - if ($error) return -1; |
|
7118 | - |
|
7119 | - $this->db->begin(); |
|
7388 | + $this->id = 0; |
|
7120 | 7389 | |
7121 | - if (! $error) |
|
7122 | - { |
|
7123 | - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
|
7124 | - $sql.= ' ('.implode( ", ", $keys ).')'; |
|
7125 | - $sql.= ' VALUES ('.implode( ", ", $values ).')'; |
|
7390 | + // TODO... |
|
7391 | + } |
|
7126 | 7392 | |
7127 | - $res = $this->db->query($sql); |
|
7128 | - if ($res===false) { |
|
7129 | - $error++; |
|
7130 | - $this->errors[] = $this->db->lasterror(); |
|
7131 | - } |
|
7132 | - } |
|
7133 | - |
|
7134 | - if (! $error) |
|
7135 | - { |
|
7136 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
7137 | - } |
|
7138 | - |
|
7139 | - // Create extrafields |
|
7140 | - if (! $error) |
|
7141 | - { |
|
7142 | - $result=$this->insertExtraFields(); |
|
7143 | - if ($result < 0) $error++; |
|
7144 | - } |
|
7145 | - |
|
7146 | - // Triggers |
|
7147 | - if (! $error && ! $notrigger) |
|
7148 | - { |
|
7149 | - // Call triggers |
|
7150 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
7151 | - if ($result < 0) { $error++; } |
|
7152 | - // End call triggers |
|
7153 | - } |
|
7154 | - |
|
7155 | - // Commit or rollback |
|
7156 | - if ($error) { |
|
7157 | - $this->db->rollback(); |
|
7158 | - return -1; |
|
7159 | - } else { |
|
7160 | - $this->db->commit(); |
|
7161 | - return $this->id; |
|
7162 | - } |
|
7163 | - } |
|
7164 | - |
|
7165 | - |
|
7166 | - /** |
|
7167 | - * Load object in memory from the database |
|
7168 | - * |
|
7169 | - * @param int $id Id object |
|
7170 | - * @param string $ref Ref |
|
7171 | - * @param string $morewhere More SQL filters (' AND ...') |
|
7172 | - * @return int <0 if KO, 0 if not found, >0 if OK |
|
7173 | - */ |
|
7174 | - public function fetchCommon($id, $ref = null, $morewhere = '') |
|
7175 | - { |
|
7176 | - if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
|
7177 | - |
|
7178 | - $sql = 'SELECT '.$this->getFieldList(); |
|
7179 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
7180 | - |
|
7181 | - if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
7182 | - elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
7183 | - else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
7184 | - if ($morewhere) $sql.= $morewhere; |
|
7185 | - $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
7186 | - |
|
7187 | - $res = $this->db->query($sql); |
|
7188 | - if ($res) |
|
7189 | - { |
|
7190 | - $obj = $this->db->fetch_object($res); |
|
7191 | - if ($obj) |
|
7192 | - { |
|
7193 | - $this->setVarsFromFetchObj($obj); |
|
7194 | - return $this->id; |
|
7195 | - } |
|
7196 | - else |
|
7197 | - { |
|
7198 | - return 0; |
|
7199 | - } |
|
7200 | - } |
|
7201 | - else |
|
7202 | - { |
|
7203 | - $this->error = $this->db->lasterror(); |
|
7204 | - $this->errors[] = $this->error; |
|
7205 | - return -1; |
|
7206 | - } |
|
7207 | - } |
|
7208 | - |
|
7209 | - /** |
|
7210 | - * Update object into database |
|
7211 | - * |
|
7212 | - * @param User $user User that modifies |
|
7213 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
7214 | - * @return int <0 if KO, >0 if OK |
|
7215 | - */ |
|
7216 | - public function updateCommon(User $user, $notrigger = false) |
|
7217 | - { |
|
7218 | - global $conf, $langs; |
|
7219 | - |
|
7220 | - $error = 0; |
|
7221 | - |
|
7222 | - $now=dol_now(); |
|
7223 | - |
|
7224 | - $fieldvalues = $this->setSaveQuery(); |
|
7225 | - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now); |
|
7226 | - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id; |
|
7227 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
7228 | - |
|
7229 | - $keys=array(); |
|
7230 | - $values = array(); |
|
7231 | - foreach ($fieldvalues as $k => $v) { |
|
7232 | - $keys[$k] = $k; |
|
7233 | - $value = $this->fields[$k]; |
|
7234 | - $values[$k] = $this->quote($v, $value); |
|
7235 | - $tmp[] = $k.'='.$this->quote($v, $this->fields[$k]); |
|
7236 | - } |
|
7237 | - |
|
7238 | - // Clean and check mandatory |
|
7239 | - foreach($keys as $key) |
|
7240 | - { |
|
7241 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field |
|
7242 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
7243 | - |
|
7244 | - //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
7245 | - /* |
|
7246 | - if ($this->fields[$key]['notnull'] == 1 && empty($values[$key])) |
|
7247 | - { |
|
7248 | - $error++; |
|
7249 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
7250 | - }*/ |
|
7251 | - } |
|
7252 | 7393 | |
7253 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
7394 | + /* Part for comments */ |
|
7254 | 7395 | |
7255 | - $this->db->begin(); |
|
7256 | - if (! $error) |
|
7257 | - { |
|
7258 | - $res = $this->db->query($sql); |
|
7259 | - if ($res===false) |
|
7260 | - { |
|
7261 | - $error++; |
|
7262 | - $this->errors[] = $this->db->lasterror(); |
|
7263 | - } |
|
7264 | - } |
|
7265 | - |
|
7266 | - // Update extrafield |
|
7267 | - if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) |
|
7268 | - { |
|
7269 | - $result=$this->insertExtraFields(); |
|
7270 | - if ($result < 0) |
|
7271 | - { |
|
7272 | - $error++; |
|
7273 | - } |
|
7274 | - } |
|
7275 | - |
|
7276 | - // Triggers |
|
7277 | - if (! $error && ! $notrigger) |
|
7278 | - { |
|
7279 | - // Call triggers |
|
7280 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
7281 | - if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail |
|
7282 | - // End call triggers |
|
7283 | - } |
|
7284 | - |
|
7285 | - // Commit or rollback |
|
7286 | - if ($error) { |
|
7287 | - $this->db->rollback(); |
|
7288 | - return -1; |
|
7289 | - } else { |
|
7290 | - $this->db->commit(); |
|
7291 | - return $this->id; |
|
7292 | - } |
|
7293 | - } |
|
7294 | - |
|
7295 | - /** |
|
7296 | - * Delete object in database |
|
7297 | - * |
|
7298 | - * @param User $user User that deletes |
|
7299 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
7300 | - * @param int $forcechilddeletion 0=no, 1=Force deletion of children |
|
7301 | - * @return int <=0 if KO, >0 if OK |
|
7302 | - */ |
|
7303 | - public function deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0) |
|
7304 | - { |
|
7305 | - $error=0; |
|
7306 | - |
|
7307 | - $this->db->begin(); |
|
7308 | - |
|
7309 | - if ($forcechilddeletion) |
|
7310 | - { |
|
7311 | - foreach($this->childtables as $table) |
|
7312 | - { |
|
7313 | - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
|
7314 | - $resql = $this->db->query($sql); |
|
7315 | - if (! $resql) |
|
7316 | - { |
|
7317 | - $this->error=$this->db->lasterror(); |
|
7318 | - $this->errors[]=$this->error; |
|
7319 | - $this->db->rollback(); |
|
7320 | - return -1; |
|
7321 | - } |
|
7322 | - } |
|
7323 | - } |
|
7324 | - elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
7325 | - { |
|
7326 | - $objectisused = $this->isObjectUsed($this->id); |
|
7327 | - if (! empty($objectisused)) |
|
7328 | - { |
|
7329 | - dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
|
7330 | - $this->error='ErrorRecordHasChildren'; |
|
7331 | - $this->errors[]=$this->error; |
|
7332 | - $this->db->rollback(); |
|
7333 | - return 0; |
|
7334 | - } |
|
7335 | - } |
|
7336 | - |
|
7337 | - if (! $error) { |
|
7338 | - if (! $notrigger) { |
|
7339 | - // Call triggers |
|
7340 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
7341 | - if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail |
|
7342 | - // End call triggers |
|
7343 | - } |
|
7344 | - } |
|
7345 | - |
|
7346 | - if (! $error && ! empty($this->isextrafieldmanaged)) |
|
7347 | - { |
|
7348 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
7349 | - $sql.= " WHERE fk_object=" . $this->id; |
|
7350 | - |
|
7351 | - $resql = $this->db->query($sql); |
|
7352 | - if (! $resql) |
|
7353 | - { |
|
7354 | - $this->errors[] = $this->db->lasterror(); |
|
7355 | - $error++; |
|
7356 | - } |
|
7357 | - } |
|
7396 | + /** |
|
7397 | + * Load comments linked with current task |
|
7398 | + * @return boolean 1 if ok |
|
7399 | + */ |
|
7400 | + public function fetchComments() |
|
7401 | + { |
|
7402 | + require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
|
7358 | 7403 | |
7359 | - if (! $error) |
|
7360 | - { |
|
7361 | - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
|
7404 | + $comment = new Comment($this->db); |
|
7405 | + $result=$comment->fetchAllFor($this->element, $this->id); |
|
7406 | + if ($result<0) { |
|
7407 | + $this->errors=array_merge($this->errors, $comment->errors); |
|
7408 | + return -1; |
|
7409 | + } else { |
|
7410 | + $this->comments = $comment->comments; |
|
7411 | + } |
|
7412 | + return count($this->comments); |
|
7413 | + } |
|
7362 | 7414 | |
7363 | - $res = $this->db->query($sql); |
|
7364 | - if($res===false) { |
|
7365 | - $error++; |
|
7366 | - $this->errors[] = $this->db->lasterror(); |
|
7367 | - } |
|
7368 | - } |
|
7369 | - |
|
7370 | - // Commit or rollback |
|
7371 | - if ($error) { |
|
7372 | - $this->db->rollback(); |
|
7373 | - return -1; |
|
7374 | - } else { |
|
7375 | - $this->db->commit(); |
|
7376 | - return 1; |
|
7377 | - } |
|
7378 | - } |
|
7379 | - |
|
7380 | - /** |
|
7381 | - * Initialise object with example values |
|
7382 | - * Id must be 0 if object instance is a specimen |
|
7383 | - * |
|
7384 | - * @return void |
|
7385 | - */ |
|
7386 | - public function initAsSpecimenCommon() |
|
7387 | - { |
|
7388 | - $this->id = 0; |
|
7389 | - |
|
7390 | - // TODO... |
|
7391 | - } |
|
7392 | - |
|
7393 | - |
|
7394 | - /* Part for comments */ |
|
7395 | - |
|
7396 | - /** |
|
7397 | - * Load comments linked with current task |
|
7398 | - * @return boolean 1 if ok |
|
7399 | - */ |
|
7400 | - public function fetchComments() |
|
7401 | - { |
|
7402 | - require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
|
7403 | - |
|
7404 | - $comment = new Comment($this->db); |
|
7405 | - $result=$comment->fetchAllFor($this->element, $this->id); |
|
7406 | - if ($result<0) { |
|
7407 | - $this->errors=array_merge($this->errors, $comment->errors); |
|
7408 | - return -1; |
|
7409 | - } else { |
|
7410 | - $this->comments = $comment->comments; |
|
7411 | - } |
|
7412 | - return count($this->comments); |
|
7413 | - } |
|
7414 | - |
|
7415 | - /** |
|
7416 | - * Return nb comments already posted |
|
7417 | - * |
|
7418 | - * @return int |
|
7419 | - */ |
|
7420 | - public function getNbComments() |
|
7421 | - { |
|
7422 | - return count($this->comments); |
|
7423 | - } |
|
7415 | + /** |
|
7416 | + * Return nb comments already posted |
|
7417 | + * |
|
7418 | + * @return int |
|
7419 | + */ |
|
7420 | + public function getNbComments() |
|
7421 | + { |
|
7422 | + return count($this->comments); |
|
7423 | + } |
|
7424 | 7424 | |
7425 | 7425 | /** |
7426 | 7426 | * Trim object parameters |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * @var mixed Contains comments |
374 | 374 | * @see fetchComments() |
375 | 375 | */ |
376 | - public $comments=array(); |
|
376 | + public $comments = array(); |
|
377 | 377 | |
378 | 378 | /** |
379 | 379 | * @var int |
@@ -399,9 +399,9 @@ discard block |
||
399 | 399 | public $civility_id; |
400 | 400 | |
401 | 401 | // Dates |
402 | - public $date_creation; // Date creation |
|
403 | - public $date_validation; // Date validation |
|
404 | - public $date_modification; // Date last change (tms field) |
|
402 | + public $date_creation; // Date creation |
|
403 | + public $date_validation; // Date validation |
|
404 | + public $date_modification; // Date last change (tms field) |
|
405 | 405 | |
406 | 406 | |
407 | 407 | |
@@ -417,29 +417,29 @@ discard block |
||
417 | 417 | * @param string $ref_ext Ref ext of object to check |
418 | 418 | * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
419 | 419 | */ |
420 | - static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
420 | + static function isExistingObject($element, $id, $ref = '', $ref_ext = '') |
|
421 | 421 | { |
422 | - global $db,$conf; |
|
422 | + global $db, $conf; |
|
423 | 423 | |
424 | 424 | $sql = "SELECT rowid, ref, ref_ext"; |
425 | - $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
426 | - $sql.= " WHERE entity IN (".getEntity($element).")" ; |
|
425 | + $sql .= " FROM ".MAIN_DB_PREFIX.$element; |
|
426 | + $sql .= " WHERE entity IN (".getEntity($element).")"; |
|
427 | 427 | |
428 | - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
429 | - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
430 | - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
428 | + if ($id > 0) $sql .= " AND rowid = ".$db->escape($id); |
|
429 | + else if ($ref) $sql .= " AND ref = '".$db->escape($ref)."'"; |
|
430 | + else if ($ref_ext) $sql .= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
431 | 431 | else { |
432 | - $error='ErrorWrongParameters'; |
|
432 | + $error = 'ErrorWrongParameters'; |
|
433 | 433 | dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
434 | 434 | return -1; |
435 | 435 | } |
436 | - if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
436 | + if ($ref || $ref_ext) $sql .= " AND entity = ".$conf->entity; |
|
437 | 437 | |
438 | 438 | dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
439 | 439 | $resql = $db->query($sql); |
440 | 440 | if ($resql) |
441 | 441 | { |
442 | - $num=$db->num_rows($resql); |
|
442 | + $num = $db->num_rows($resql); |
|
443 | 443 | if ($num > 0) return 1; |
444 | 444 | else return 0; |
445 | 445 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | */ |
454 | 454 | function errorsToString() |
455 | 455 | { |
456 | - return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):''); |
|
456 | + return $this->error.(is_array($this->errors) ? (($this->error != '' ? ', ' : '').join(', ', $this->errors)) : ''); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** |
@@ -465,23 +465,23 @@ discard block |
||
465 | 465 | * @param int $maxlen Maximum length |
466 | 466 | * @return string String with full name |
467 | 467 | */ |
468 | - function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
468 | + function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0) |
|
469 | 469 | { |
470 | 470 | //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
471 | - $lastname=$this->lastname; |
|
472 | - $firstname=$this->firstname; |
|
473 | - 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:''))))); |
|
471 | + $lastname = $this->lastname; |
|
472 | + $firstname = $this->firstname; |
|
473 | + 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 : ''))))); |
|
474 | 474 | |
475 | - $ret=''; |
|
475 | + $ret = ''; |
|
476 | 476 | if ($option && $this->civility_id) |
477 | 477 | { |
478 | - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
479 | - else $ret.=$this->civility_id.' '; |
|
478 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id) != "Civility".$this->civility_id) $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
479 | + else $ret .= $this->civility_id.' '; |
|
480 | 480 | } |
481 | 481 | |
482 | - $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
482 | + $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
483 | 483 | |
484 | - return dol_trunc($ret,$maxlen); |
|
484 | + return dol_trunc($ret, $maxlen); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -492,24 +492,24 @@ discard block |
||
492 | 492 | * @param int $withregion 1=Add region into address string |
493 | 493 | * @return string Full address string |
494 | 494 | */ |
495 | - function getFullAddress($withcountry=0, $sep="\n", $withregion=0) |
|
495 | + function getFullAddress($withcountry = 0, $sep = "\n", $withregion = 0) |
|
496 | 496 | { |
497 | 497 | if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
498 | 498 | { |
499 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
500 | - $tmparray=getCountry($this->country_id,'all'); |
|
501 | - $this->country_code=$tmparray['code']; |
|
502 | - $this->country =$tmparray['label']; |
|
499 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
500 | + $tmparray = getCountry($this->country_id, 'all'); |
|
501 | + $this->country_code = $tmparray['code']; |
|
502 | + $this->country = $tmparray['label']; |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) |
506 | 506 | { |
507 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
508 | - $tmparray=getState($this->state_id,'all',0,1); |
|
509 | - $this->state_code =$tmparray['code']; |
|
510 | - $this->state =$tmparray['label']; |
|
511 | - $this->region_code =$tmparray['region_code']; |
|
512 | - $this->region =$tmparray['region']; |
|
507 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
508 | + $tmparray = getState($this->state_id, 'all', 0, 1); |
|
509 | + $this->state_code = $tmparray['code']; |
|
510 | + $this->state = $tmparray['label']; |
|
511 | + $this->region_code = $tmparray['region_code']; |
|
512 | + $this->region = $tmparray['region']; |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | return dol_format_address($this, $withcountry, $sep); |
@@ -527,108 +527,108 @@ discard block |
||
527 | 527 | { |
528 | 528 | global $conf, $langs; |
529 | 529 | |
530 | - $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
530 | + $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
531 | 531 | |
532 | - $contactid=0; |
|
533 | - $thirdpartyid=0; |
|
532 | + $contactid = 0; |
|
533 | + $thirdpartyid = 0; |
|
534 | 534 | if ($this->element == 'societe') |
535 | 535 | { |
536 | - $thirdpartyid=$this->id; |
|
536 | + $thirdpartyid = $this->id; |
|
537 | 537 | } |
538 | 538 | if ($this->element == 'contact') |
539 | 539 | { |
540 | - $contactid=$this->id; |
|
541 | - $thirdpartyid=$object->fk_soc; |
|
540 | + $contactid = $this->id; |
|
541 | + $thirdpartyid = $object->fk_soc; |
|
542 | 542 | } |
543 | 543 | if ($this->element == 'user') |
544 | 544 | { |
545 | - $contactid=$this->contact_id; |
|
546 | - $thirdpartyid=$object->fk_soc; |
|
545 | + $contactid = $this->contact_id; |
|
546 | + $thirdpartyid = $object->fk_soc; |
|
547 | 547 | } |
548 | 548 | |
549 | - $out='<!-- BEGIN part to show address block -->'; |
|
549 | + $out = '<!-- BEGIN part to show address block -->'; |
|
550 | 550 | |
551 | - $outdone=0; |
|
552 | - $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
551 | + $outdone = 0; |
|
552 | + $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
553 | 553 | if ($coords) |
554 | 554 | { |
555 | - if (! empty($conf->use_javascript_ajax)) |
|
555 | + if (!empty($conf->use_javascript_ajax)) |
|
556 | 556 | { |
557 | - $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
557 | + $namecoords = $this->getFullName($langs, 1).'<br>'.$coords; |
|
558 | 558 | // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
559 | - $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">'; |
|
560 | - $out.=img_picto($langs->trans("Address"), 'object_address.png'); |
|
561 | - $out.='</a> '; |
|
559 | + $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">'; |
|
560 | + $out .= img_picto($langs->trans("Address"), 'object_address.png'); |
|
561 | + $out .= '</a> '; |
|
562 | 562 | } |
563 | - $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
563 | + $out .= dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
564 | 564 | $outdone++; |
565 | 565 | } |
566 | 566 | |
567 | - 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 |
|
567 | + 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 | 568 | && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) |
569 | 569 | { |
570 | 570 | if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) { |
571 | - $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
|
571 | + $out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state; |
|
572 | 572 | } |
573 | 573 | else { |
574 | - $out.=($outdone?' - ':'').$this->state; |
|
574 | + $out .= ($outdone ? ' - ' : '').$this->state; |
|
575 | 575 | } |
576 | 576 | $outdone++; |
577 | 577 | } |
578 | 578 | |
579 | - 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>':''); |
|
580 | - if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
|
581 | - $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
579 | + 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>' : ''); |
|
580 | + if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
|
581 | + $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++; |
|
582 | 582 | } |
583 | - if (! empty($this->phone_pro)) { |
|
584 | - $out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
583 | + if (!empty($this->phone_pro)) { |
|
584 | + $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++; |
|
585 | 585 | } |
586 | - if (! empty($this->phone_mobile)) { |
|
587 | - $out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
586 | + if (!empty($this->phone_mobile)) { |
|
587 | + $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); $outdone++; |
|
588 | 588 | } |
589 | - if (! empty($this->phone_perso)) { |
|
590 | - $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++; |
|
589 | + if (!empty($this->phone_perso)) { |
|
590 | + $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePerso")); $outdone++; |
|
591 | 591 | } |
592 | - if (! empty($this->office_phone)) { |
|
593 | - $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
592 | + if (!empty($this->office_phone)) { |
|
593 | + $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++; |
|
594 | 594 | } |
595 | - if (! empty($this->user_mobile)) { |
|
596 | - $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
595 | + if (!empty($this->user_mobile)) { |
|
596 | + $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); $outdone++; |
|
597 | 597 | } |
598 | - if (! empty($this->fax)) { |
|
599 | - $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
598 | + if (!empty($this->fax)) { |
|
599 | + $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); $outdone++; |
|
600 | 600 | } |
601 | - if (! empty($this->office_fax)) { |
|
602 | - $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
601 | + if (!empty($this->office_fax)) { |
|
602 | + $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); $outdone++; |
|
603 | 603 | } |
604 | 604 | |
605 | - $out.='<div style="clear: both;"></div>'; |
|
606 | - $outdone=0; |
|
607 | - if (! empty($this->email)) |
|
605 | + $out .= '<div style="clear: both;"></div>'; |
|
606 | + $outdone = 0; |
|
607 | + if (!empty($this->email)) |
|
608 | 608 | { |
609 | - $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); |
|
609 | + $out .= dol_print_email($this->email, $this->id, $object->id, 'AC_EMAIL', 0, 0, 1); |
|
610 | 610 | $outdone++; |
611 | 611 | } |
612 | - if (! empty($this->url)) |
|
612 | + if (!empty($this->url)) |
|
613 | 613 | { |
614 | - $out.=dol_print_url($this->url,'_goout',0,1); |
|
614 | + $out .= dol_print_url($this->url, '_goout', 0, 1); |
|
615 | 615 | $outdone++; |
616 | 616 | } |
617 | - $out.='<div style="clear: both;">'; |
|
618 | - if (! empty($conf->socialnetworks->enabled)) |
|
617 | + $out .= '<div style="clear: both;">'; |
|
618 | + if (!empty($conf->socialnetworks->enabled)) |
|
619 | 619 | { |
620 | - if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
620 | + if ($this->skype) $out .= dol_print_socialnetworks($this->skype, $this->id, $object->id, 'skype'); |
|
621 | 621 | $outdone++; |
622 | - if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
622 | + if ($this->jabberid) $out .= dol_print_socialnetworks($this->jabberid, $this->id, $object->id, 'jabber'); |
|
623 | 623 | $outdone++; |
624 | - if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
624 | + if ($this->twitter) $out .= dol_print_socialnetworks($this->twitter, $this->id, $object->id, 'twitter'); |
|
625 | 625 | $outdone++; |
626 | - if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
626 | + if ($this->facebook) $out .= dol_print_socialnetworks($this->facebook, $this->id, $object->id, 'facebook'); |
|
627 | 627 | $outdone++; |
628 | 628 | } |
629 | - $out.='</div>'; |
|
629 | + $out .= '</div>'; |
|
630 | 630 | |
631 | - $out.='<!-- END Part to show address block -->'; |
|
631 | + $out .= '<!-- END Part to show address block -->'; |
|
632 | 632 | |
633 | 633 | return $out; |
634 | 634 | } |
@@ -641,17 +641,17 @@ discard block |
||
641 | 641 | * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
642 | 642 | * @return string Link or empty string if there is no download link |
643 | 643 | */ |
644 | - function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
644 | + function getLastMainDocLink($modulepart, $initsharekey = 0, $relativelink = 0) |
|
645 | 645 | { |
646 | 646 | global $user, $dolibarr_main_url_root; |
647 | 647 | |
648 | 648 | if (empty($this->last_main_doc)) |
649 | 649 | { |
650 | - return ''; // No way to known which document name to use |
|
650 | + return ''; // No way to known which document name to use |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
654 | - $ecmfile=new EcmFiles($this->db); |
|
654 | + $ecmfile = new EcmFiles($this->db); |
|
655 | 655 | $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
656 | 656 | if ($result < 0) |
657 | 657 | { |
@@ -699,26 +699,26 @@ discard block |
||
699 | 699 | } |
700 | 700 | |
701 | 701 | // Define $urlwithroot |
702 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
703 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
702 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
703 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
704 | 704 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
705 | 705 | |
706 | - $forcedownload=0; |
|
706 | + $forcedownload = 0; |
|
707 | 707 | |
708 | - $paramlink=''; |
|
708 | + $paramlink = ''; |
|
709 | 709 | //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
710 | 710 | //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
711 | 711 | //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
712 | - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
713 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
712 | + if (!empty($ecmfile->share)) $paramlink .= ($paramlink ? '&' : '').'hashp='.$ecmfile->share; // Hash for public share |
|
713 | + if ($forcedownload) $paramlink .= ($paramlink ? '&' : '').'attachment=1'; |
|
714 | 714 | |
715 | 715 | if ($relativelink) |
716 | 716 | { |
717 | - $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
717 | + $linktoreturn = 'document.php'.($paramlink ? '?'.$paramlink : ''); |
|
718 | 718 | } |
719 | 719 | else |
720 | 720 | { |
721 | - $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
721 | + $linktoreturn = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : ''); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | // Here $ecmfile->share is defined |
@@ -736,10 +736,10 @@ discard block |
||
736 | 736 | * @param int $notrigger Disable all triggers |
737 | 737 | * @return int <0 if KO, >0 if OK |
738 | 738 | */ |
739 | - function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
739 | + function add_contact($fk_socpeople, $type_contact, $source = 'external', $notrigger = 0) |
|
740 | 740 | { |
741 | 741 | // phpcs:enable |
742 | - global $user,$langs; |
|
742 | + global $user, $langs; |
|
743 | 743 | |
744 | 744 | |
745 | 745 | dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
@@ -748,43 +748,43 @@ discard block |
||
748 | 748 | if ($fk_socpeople <= 0) |
749 | 749 | { |
750 | 750 | $langs->load("errors"); |
751 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","1"); |
|
752 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
751 | + $this->error = $langs->trans("ErrorWrongValueForParameterX", "1"); |
|
752 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
753 | 753 | return -1; |
754 | 754 | } |
755 | - if (! $type_contact) |
|
755 | + if (!$type_contact) |
|
756 | 756 | { |
757 | 757 | $langs->load("errors"); |
758 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","2"); |
|
759 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
758 | + $this->error = $langs->trans("ErrorWrongValueForParameterX", "2"); |
|
759 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
760 | 760 | return -2; |
761 | 761 | } |
762 | 762 | |
763 | - $id_type_contact=0; |
|
763 | + $id_type_contact = 0; |
|
764 | 764 | if (is_numeric($type_contact)) |
765 | 765 | { |
766 | - $id_type_contact=$type_contact; |
|
766 | + $id_type_contact = $type_contact; |
|
767 | 767 | } |
768 | 768 | else |
769 | 769 | { |
770 | 770 | // We look for id type_contact |
771 | 771 | $sql = "SELECT tc.rowid"; |
772 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
773 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
774 | - $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
775 | - $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
772 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
773 | + $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
774 | + $sql .= " AND tc.source='".$this->db->escape($source)."'"; |
|
775 | + $sql .= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
776 | 776 | //print $sql; |
777 | - $resql=$this->db->query($sql); |
|
777 | + $resql = $this->db->query($sql); |
|
778 | 778 | if ($resql) |
779 | 779 | { |
780 | 780 | $obj = $this->db->fetch_object($resql); |
781 | - if ($obj) $id_type_contact=$obj->rowid; |
|
781 | + if ($obj) $id_type_contact = $obj->rowid; |
|
782 | 782 | } |
783 | 783 | } |
784 | 784 | |
785 | 785 | if ($id_type_contact == 0) |
786 | 786 | { |
787 | - $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
787 | + $this->error = 'CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
788 | 788 | 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"); |
789 | 789 | return -3; |
790 | 790 | } |
@@ -792,35 +792,35 @@ discard block |
||
792 | 792 | $datecreate = dol_now(); |
793 | 793 | |
794 | 794 | // Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
795 | - $TListeContacts=$this->liste_contact(-1, $source); |
|
796 | - $already_added=false; |
|
797 | - if(!empty($TListeContacts)) { |
|
798 | - foreach($TListeContacts as $array_contact) { |
|
799 | - if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { |
|
800 | - $already_added=true; |
|
795 | + $TListeContacts = $this->liste_contact(-1, $source); |
|
796 | + $already_added = false; |
|
797 | + if (!empty($TListeContacts)) { |
|
798 | + foreach ($TListeContacts as $array_contact) { |
|
799 | + if ($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { |
|
800 | + $already_added = true; |
|
801 | 801 | break; |
802 | 802 | } |
803 | 803 | } |
804 | 804 | } |
805 | 805 | |
806 | - if(!$already_added) { |
|
806 | + if (!$already_added) { |
|
807 | 807 | |
808 | 808 | $this->db->begin(); |
809 | 809 | |
810 | 810 | // Insert into database |
811 | 811 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
812 | - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
813 | - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; |
|
814 | - $sql.= "'".$this->db->idate($datecreate)."'"; |
|
815 | - $sql.= ", 4, ". $id_type_contact; |
|
816 | - $sql.= ")"; |
|
812 | + $sql .= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
813 | + $sql .= " VALUES (".$this->id.", ".$fk_socpeople." , "; |
|
814 | + $sql .= "'".$this->db->idate($datecreate)."'"; |
|
815 | + $sql .= ", 4, ".$id_type_contact; |
|
816 | + $sql .= ")"; |
|
817 | 817 | |
818 | - $resql=$this->db->query($sql); |
|
818 | + $resql = $this->db->query($sql); |
|
819 | 819 | if ($resql) |
820 | 820 | { |
821 | - if (! $notrigger) |
|
821 | + if (!$notrigger) |
|
822 | 822 | { |
823 | - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
823 | + $result = $this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
824 | 824 | if ($result < 0) |
825 | 825 | { |
826 | 826 | $this->db->rollback(); |
@@ -835,14 +835,14 @@ discard block |
||
835 | 835 | { |
836 | 836 | if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
837 | 837 | { |
838 | - $this->error=$this->db->errno(); |
|
838 | + $this->error = $this->db->errno(); |
|
839 | 839 | $this->db->rollback(); |
840 | 840 | echo 'err rollback'; |
841 | 841 | return -2; |
842 | 842 | } |
843 | 843 | else |
844 | 844 | { |
845 | - $this->error=$this->db->error(); |
|
845 | + $this->error = $this->db->error(); |
|
846 | 846 | $this->db->rollback(); |
847 | 847 | return -1; |
848 | 848 | } |
@@ -858,15 +858,15 @@ discard block |
||
858 | 858 | * @param string $source Nature of contact ('internal' or 'external') |
859 | 859 | * @return int >0 if OK, <0 if KO |
860 | 860 | */ |
861 | - function copy_linked_contact($objFrom, $source='internal') |
|
861 | + function copy_linked_contact($objFrom, $source = 'internal') |
|
862 | 862 | { |
863 | 863 | // phpcs:enable |
864 | 864 | $contacts = $objFrom->liste_contact(-1, $source); |
865 | - foreach($contacts as $contact) |
|
865 | + foreach ($contacts as $contact) |
|
866 | 866 | { |
867 | 867 | if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
868 | 868 | { |
869 | - $this->error=$this->db->lasterror(); |
|
869 | + $this->error = $this->db->lasterror(); |
|
870 | 870 | return -1; |
871 | 871 | } |
872 | 872 | } |
@@ -883,23 +883,23 @@ discard block |
||
883 | 883 | * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
884 | 884 | * @return int <0 if KO, >= 0 if OK |
885 | 885 | */ |
886 | - function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
886 | + function update_contact($rowid, $statut, $type_contact_id = 0, $fk_socpeople = 0) |
|
887 | 887 | { |
888 | 888 | // phpcs:enable |
889 | 889 | // Insert into database |
890 | 890 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
891 | - $sql.= " statut = ".$statut; |
|
892 | - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
893 | - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
894 | - $sql.= " where rowid = ".$rowid; |
|
895 | - $resql=$this->db->query($sql); |
|
891 | + $sql .= " statut = ".$statut; |
|
892 | + if ($type_contact_id) $sql .= ", fk_c_type_contact = '".$type_contact_id."'"; |
|
893 | + if ($fk_socpeople) $sql .= ", fk_socpeople = '".$fk_socpeople."'"; |
|
894 | + $sql .= " where rowid = ".$rowid; |
|
895 | + $resql = $this->db->query($sql); |
|
896 | 896 | if ($resql) |
897 | 897 | { |
898 | 898 | return 0; |
899 | 899 | } |
900 | 900 | else |
901 | 901 | { |
902 | - $this->error=$this->db->lasterror(); |
|
902 | + $this->error = $this->db->lasterror(); |
|
903 | 903 | return -1; |
904 | 904 | } |
905 | 905 | } |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | * @param int $notrigger Disable all triggers |
913 | 913 | * @return int >0 if OK, <0 if KO |
914 | 914 | */ |
915 | - function delete_contact($rowid, $notrigger=0) |
|
915 | + function delete_contact($rowid, $notrigger = 0) |
|
916 | 916 | { |
917 | 917 | // phpcs:enable |
918 | 918 | global $user; |
@@ -921,14 +921,14 @@ discard block |
||
921 | 921 | $this->db->begin(); |
922 | 922 | |
923 | 923 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
924 | - $sql.= " WHERE rowid =".$rowid; |
|
924 | + $sql .= " WHERE rowid =".$rowid; |
|
925 | 925 | |
926 | 926 | dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
927 | 927 | if ($this->db->query($sql)) |
928 | 928 | { |
929 | - if (! $notrigger) |
|
929 | + if (!$notrigger) |
|
930 | 930 | { |
931 | - $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
931 | + $result = $this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
932 | 932 | if ($result < 0) { $this->db->rollback(); return -1; } |
933 | 933 | } |
934 | 934 | |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | } |
938 | 938 | else |
939 | 939 | { |
940 | - $this->error=$this->db->lasterror(); |
|
940 | + $this->error = $this->db->lasterror(); |
|
941 | 941 | $this->db->rollback(); |
942 | 942 | return -1; |
943 | 943 | } |
@@ -951,22 +951,22 @@ discard block |
||
951 | 951 | * @param string $code Type of contact (code or id) |
952 | 952 | * @return int >0 if OK, <0 if KO |
953 | 953 | */ |
954 | - function delete_linked_contact($source='',$code='') |
|
954 | + function delete_linked_contact($source = '', $code = '') |
|
955 | 955 | { |
956 | 956 | // phpcs:enable |
957 | 957 | $temp = array(); |
958 | - $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
958 | + $typeContact = $this->liste_type_contact($source, '', 0, 0, $code); |
|
959 | 959 | |
960 | - foreach($typeContact as $key => $value) |
|
960 | + foreach ($typeContact as $key => $value) |
|
961 | 961 | { |
962 | - array_push($temp,$key); |
|
962 | + array_push($temp, $key); |
|
963 | 963 | } |
964 | 964 | $listId = implode(",", $temp); |
965 | 965 | |
966 | 966 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
967 | - $sql.= " WHERE element_id = ".$this->id; |
|
967 | + $sql .= " WHERE element_id = ".$this->id; |
|
968 | 968 | if ($listId) |
969 | - $sql.= " AND fk_c_type_contact IN (".$listId.")"; |
|
969 | + $sql .= " AND fk_c_type_contact IN (".$listId.")"; |
|
970 | 970 | |
971 | 971 | dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
972 | 972 | if ($this->db->query($sql)) |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | } |
976 | 976 | else |
977 | 977 | { |
978 | - $this->error=$this->db->lasterror(); |
|
978 | + $this->error = $this->db->lasterror(); |
|
979 | 979 | return -1; |
980 | 980 | } |
981 | 981 | } |
@@ -990,54 +990,54 @@ discard block |
||
990 | 990 | * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) |
991 | 991 | * @return array|int Array of contacts, -1 if error |
992 | 992 | */ |
993 | - function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
993 | + function liste_contact($statut = -1, $source = 'external', $list = 0, $code = '') |
|
994 | 994 | { |
995 | 995 | // phpcs:enable |
996 | 996 | global $langs; |
997 | 997 | |
998 | - $tab=array(); |
|
999 | - |
|
1000 | - $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 |
|
1001 | - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
1002 | - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
1003 | - $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
1004 | - $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
1005 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
1006 | - $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
1007 | - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
1008 | - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
1009 | - $sql.= " WHERE ec.element_id =".$this->id; |
|
1010 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
1011 | - $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
1012 | - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
1013 | - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
1014 | - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
1015 | - $sql.= " AND tc.active=1"; |
|
1016 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
1017 | - $sql.=" ORDER BY t.lastname ASC"; |
|
998 | + $tab = array(); |
|
999 | + |
|
1000 | + $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 |
|
1001 | + if ($source == 'internal') $sql .= ", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
1002 | + if ($source == 'external' || $source == 'thirdparty') $sql .= ", t.fk_soc as socid, t.statut as statuscontact"; |
|
1003 | + $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
1004 | + $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
1005 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
1006 | + $sql .= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
1007 | + if ($source == 'internal') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
1008 | + if ($source == 'external' || $source == 'thirdparty') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
1009 | + $sql .= " WHERE ec.element_id =".$this->id; |
|
1010 | + $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
|
1011 | + $sql .= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
1012 | + if ($code) $sql .= " AND tc.code = '".$this->db->escape($code)."'"; |
|
1013 | + if ($source == 'internal') $sql .= " AND tc.source = 'internal'"; |
|
1014 | + if ($source == 'external' || $source == 'thirdparty') $sql .= " AND tc.source = 'external'"; |
|
1015 | + $sql .= " AND tc.active=1"; |
|
1016 | + if ($statut >= 0) $sql .= " AND ec.statut = '".$statut."'"; |
|
1017 | + $sql .= " ORDER BY t.lastname ASC"; |
|
1018 | 1018 | |
1019 | 1019 | dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
1020 | - $resql=$this->db->query($sql); |
|
1020 | + $resql = $this->db->query($sql); |
|
1021 | 1021 | if ($resql) |
1022 | 1022 | { |
1023 | - $num=$this->db->num_rows($resql); |
|
1024 | - $i=0; |
|
1023 | + $num = $this->db->num_rows($resql); |
|
1024 | + $i = 0; |
|
1025 | 1025 | while ($i < $num) |
1026 | 1026 | { |
1027 | 1027 | $obj = $this->db->fetch_object($resql); |
1028 | 1028 | |
1029 | - if (! $list) |
|
1029 | + if (!$list) |
|
1030 | 1030 | { |
1031 | - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
1032 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
1033 | - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id, |
|
1034 | - 'nom'=>$obj->lastname, // For backward compatibility |
|
1031 | + $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
1032 | + $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); |
|
1033 | + $tab[$i] = array('source'=>$obj->source, 'socid'=>$obj->socid, 'id'=>$obj->id, |
|
1034 | + 'nom'=>$obj->lastname, // For backward compatibility |
|
1035 | 1035 | 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
1036 | 1036 | 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
1037 | 1037 | } |
1038 | 1038 | else |
1039 | 1039 | { |
1040 | - $tab[$i]=$obj->id; |
|
1040 | + $tab[$i] = $obj->id; |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | $i++; |
@@ -1047,7 +1047,7 @@ discard block |
||
1047 | 1047 | } |
1048 | 1048 | else |
1049 | 1049 | { |
1050 | - $this->error=$this->db->lasterror(); |
|
1050 | + $this->error = $this->db->lasterror(); |
|
1051 | 1051 | dol_print_error($this->db); |
1052 | 1052 | return -1; |
1053 | 1053 | } |
@@ -1063,16 +1063,16 @@ discard block |
||
1063 | 1063 | function swapContactStatus($rowid) |
1064 | 1064 | { |
1065 | 1065 | $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
1066 | - $sql.= " tc.code, tc.libelle"; |
|
1066 | + $sql .= " tc.code, tc.libelle"; |
|
1067 | 1067 | //$sql.= ", s.fk_soc"; |
1068 | - $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; |
|
1068 | + $sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; |
|
1069 | 1069 | //$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 |
1070 | - $sql.= " WHERE ec.rowid =".$rowid; |
|
1071 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
1072 | - $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
1070 | + $sql .= " WHERE ec.rowid =".$rowid; |
|
1071 | + $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
|
1072 | + $sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
1073 | 1073 | |
1074 | 1074 | dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
1075 | - $resql=$this->db->query($sql); |
|
1075 | + $resql = $this->db->query($sql); |
|
1076 | 1076 | if ($resql) |
1077 | 1077 | { |
1078 | 1078 | $obj = $this->db->fetch_object($resql); |
@@ -1083,7 +1083,7 @@ discard block |
||
1083 | 1083 | } |
1084 | 1084 | else |
1085 | 1085 | { |
1086 | - $this->error=$this->db->error(); |
|
1086 | + $this->error = $this->db->error(); |
|
1087 | 1087 | dol_print_error($this->db); |
1088 | 1088 | return -1; |
1089 | 1089 | } |
@@ -1100,44 +1100,44 @@ discard block |
||
1100 | 1100 | * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
1101 | 1101 | * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
1102 | 1102 | */ |
1103 | - function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
1103 | + function liste_type_contact($source = 'internal', $order = 'position', $option = 0, $activeonly = 0, $code = '') |
|
1104 | 1104 | { |
1105 | 1105 | // phpcs:enable |
1106 | 1106 | global $langs; |
1107 | 1107 | |
1108 | - if (empty($order)) $order='position'; |
|
1109 | - if ($order == 'position') $order.=',code'; |
|
1108 | + if (empty($order)) $order = 'position'; |
|
1109 | + if ($order == 'position') $order .= ',code'; |
|
1110 | 1110 | |
1111 | 1111 | $tab = array(); |
1112 | 1112 | $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
1113 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
1114 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
1115 | - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
1116 | - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
1117 | - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
1118 | - $sql.= $this->db->order($order,'ASC'); |
|
1113 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
1114 | + $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
1115 | + if ($activeonly == 1) $sql .= " AND tc.active=1"; // only the active types |
|
1116 | + if (!empty($source) && $source != 'all') $sql .= " AND tc.source='".$this->db->escape($source)."'"; |
|
1117 | + if (!empty($code)) $sql .= " AND tc.code='".$this->db->escape($code)."'"; |
|
1118 | + $sql .= $this->db->order($order, 'ASC'); |
|
1119 | 1119 | |
1120 | 1120 | //print "sql=".$sql; |
1121 | - $resql=$this->db->query($sql); |
|
1121 | + $resql = $this->db->query($sql); |
|
1122 | 1122 | if ($resql) |
1123 | 1123 | { |
1124 | - $num=$this->db->num_rows($resql); |
|
1125 | - $i=0; |
|
1124 | + $num = $this->db->num_rows($resql); |
|
1125 | + $i = 0; |
|
1126 | 1126 | while ($i < $num) |
1127 | 1127 | { |
1128 | 1128 | $obj = $this->db->fetch_object($resql); |
1129 | 1129 | |
1130 | - $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
1131 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
1132 | - if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
1133 | - else $tab[$obj->code]=$libelle_type; |
|
1130 | + $transkey = "TypeContact_".$this->element."_".$source."_".$obj->code; |
|
1131 | + $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); |
|
1132 | + if (empty($option)) $tab[$obj->rowid] = $libelle_type; |
|
1133 | + else $tab[$obj->code] = $libelle_type; |
|
1134 | 1134 | $i++; |
1135 | 1135 | } |
1136 | 1136 | return $tab; |
1137 | 1137 | } |
1138 | 1138 | else |
1139 | 1139 | { |
1140 | - $this->error=$this->db->lasterror(); |
|
1140 | + $this->error = $this->db->lasterror(); |
|
1141 | 1141 | //dol_print_error($this->db); |
1142 | 1142 | return null; |
1143 | 1143 | } |
@@ -1154,53 +1154,53 @@ discard block |
||
1154 | 1154 | * @param int $status limited to a certain status |
1155 | 1155 | * @return array List of id for such contacts |
1156 | 1156 | */ |
1157 | - function getIdContact($source,$code,$status=0) |
|
1157 | + function getIdContact($source, $code, $status = 0) |
|
1158 | 1158 | { |
1159 | 1159 | global $conf; |
1160 | 1160 | |
1161 | - $result=array(); |
|
1162 | - $i=0; |
|
1161 | + $result = array(); |
|
1162 | + $i = 0; |
|
1163 | 1163 | //cas particulier pour les expeditions |
1164 | - if($this->element=='shipping' && $this->origin_id != 0) { |
|
1165 | - $id=$this->origin_id; |
|
1166 | - $element='commande'; |
|
1167 | - } else if($this->element=='reception' && $this->origin_id != 0) { |
|
1168 | - $id=$this->origin_id; |
|
1169 | - $element='order_supplier'; |
|
1164 | + if ($this->element == 'shipping' && $this->origin_id != 0) { |
|
1165 | + $id = $this->origin_id; |
|
1166 | + $element = 'commande'; |
|
1167 | + } else if ($this->element == 'reception' && $this->origin_id != 0) { |
|
1168 | + $id = $this->origin_id; |
|
1169 | + $element = 'order_supplier'; |
|
1170 | 1170 | } else { |
1171 | - $id=$this->id; |
|
1172 | - $element=$this->element; |
|
1171 | + $id = $this->id; |
|
1172 | + $element = $this->element; |
|
1173 | 1173 | } |
1174 | 1174 | |
1175 | 1175 | $sql = "SELECT ec.fk_socpeople"; |
1176 | - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
1177 | - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
1178 | - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
1179 | - $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
1180 | - $sql.= " WHERE ec.element_id = ".$id; |
|
1181 | - $sql.= " AND ec.fk_socpeople = c.rowid"; |
|
1182 | - if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
1183 | - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")"; |
|
1184 | - $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
1185 | - $sql.= " AND tc.element = '".$element."'"; |
|
1186 | - $sql.= " AND tc.source = '".$source."'"; |
|
1187 | - $sql.= " AND tc.code = '".$code."'"; |
|
1188 | - $sql.= " AND tc.active = 1"; |
|
1189 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
1176 | + $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
1177 | + if ($source == 'internal') $sql .= " ".MAIN_DB_PREFIX."user as c,"; |
|
1178 | + if ($source == 'external') $sql .= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
1179 | + $sql .= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
1180 | + $sql .= " WHERE ec.element_id = ".$id; |
|
1181 | + $sql .= " AND ec.fk_socpeople = c.rowid"; |
|
1182 | + if ($source == 'internal') $sql .= " AND c.entity IN (".getEntity('user').")"; |
|
1183 | + if ($source == 'external') $sql .= " AND c.entity IN (".getEntity('societe').")"; |
|
1184 | + $sql .= " AND ec.fk_c_type_contact = tc.rowid"; |
|
1185 | + $sql .= " AND tc.element = '".$element."'"; |
|
1186 | + $sql .= " AND tc.source = '".$source."'"; |
|
1187 | + $sql .= " AND tc.code = '".$code."'"; |
|
1188 | + $sql .= " AND tc.active = 1"; |
|
1189 | + if ($status) $sql .= " AND ec.statut = ".$status; |
|
1190 | 1190 | |
1191 | 1191 | dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
1192 | - $resql=$this->db->query($sql); |
|
1192 | + $resql = $this->db->query($sql); |
|
1193 | 1193 | if ($resql) |
1194 | 1194 | { |
1195 | 1195 | while ($obj = $this->db->fetch_object($resql)) |
1196 | 1196 | { |
1197 | - $result[$i]=$obj->fk_socpeople; |
|
1197 | + $result[$i] = $obj->fk_socpeople; |
|
1198 | 1198 | $i++; |
1199 | 1199 | } |
1200 | 1200 | } |
1201 | 1201 | else |
1202 | 1202 | { |
1203 | - $this->error=$this->db->error(); |
|
1203 | + $this->error = $this->db->error(); |
|
1204 | 1204 | return null; |
1205 | 1205 | } |
1206 | 1206 | |
@@ -1214,16 +1214,16 @@ discard block |
||
1214 | 1214 | * @param int $contactid Id du contact. Use this->contactid if empty. |
1215 | 1215 | * @return int <0 if KO, >0 if OK |
1216 | 1216 | */ |
1217 | - function fetch_contact($contactid=null) |
|
1217 | + function fetch_contact($contactid = null) |
|
1218 | 1218 | { |
1219 | 1219 | // phpcs:enable |
1220 | - if (empty($contactid)) $contactid=$this->contactid; |
|
1220 | + if (empty($contactid)) $contactid = $this->contactid; |
|
1221 | 1221 | |
1222 | 1222 | if (empty($contactid)) return 0; |
1223 | 1223 | |
1224 | 1224 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
1225 | 1225 | $contact = new Contact($this->db); |
1226 | - $result=$contact->fetch($contactid); |
|
1226 | + $result = $contact->fetch($contactid); |
|
1227 | 1227 | $this->contact = $contact; |
1228 | 1228 | return $result; |
1229 | 1229 | } |
@@ -1235,7 +1235,7 @@ discard block |
||
1235 | 1235 | * @param int $force_thirdparty_id Force thirdparty id |
1236 | 1236 | * @return int <0 if KO, >0 if OK |
1237 | 1237 | */ |
1238 | - function fetch_thirdparty($force_thirdparty_id=0) |
|
1238 | + function fetch_thirdparty($force_thirdparty_id = 0) |
|
1239 | 1239 | { |
1240 | 1240 | // phpcs:enable |
1241 | 1241 | global $conf; |
@@ -1243,7 +1243,7 @@ discard block |
||
1243 | 1243 | if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
1244 | 1244 | return 0; |
1245 | 1245 | |
1246 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
1246 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
1247 | 1247 | |
1248 | 1248 | $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
1249 | 1249 | if ($force_thirdparty_id) |
@@ -1306,7 +1306,7 @@ discard block |
||
1306 | 1306 | |
1307 | 1307 | dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
1308 | 1308 | |
1309 | - $idtype=$this->barcode_type; |
|
1309 | + $idtype = $this->barcode_type; |
|
1310 | 1310 | 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 |
1311 | 1311 | { |
1312 | 1312 | if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
@@ -1319,8 +1319,8 @@ discard block |
||
1319 | 1319 | 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 |
1320 | 1320 | { |
1321 | 1321 | $sql = "SELECT rowid, code, libelle as label, coder"; |
1322 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
1323 | - $sql.= " WHERE rowid = ".$idtype; |
|
1322 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
1323 | + $sql .= " WHERE rowid = ".$idtype; |
|
1324 | 1324 | dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
1325 | 1325 | $resql = $this->db->query($sql); |
1326 | 1326 | if ($resql) |
@@ -1353,13 +1353,13 @@ discard block |
||
1353 | 1353 | // phpcs:enable |
1354 | 1354 | include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
1355 | 1355 | |
1356 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
1356 | + if (empty($this->fk_project) && !empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
1357 | 1357 | if (empty($this->fk_project)) return 0; |
1358 | 1358 | |
1359 | 1359 | $project = new Project($this->db); |
1360 | 1360 | $result = $project->fetch($this->fk_project); |
1361 | 1361 | |
1362 | - $this->projet = $project; // deprecated |
|
1362 | + $this->projet = $project; // deprecated |
|
1363 | 1363 | $this->project = $project; |
1364 | 1364 | return $result; |
1365 | 1365 | } |
@@ -1395,7 +1395,7 @@ discard block |
||
1395 | 1395 | { |
1396 | 1396 | // phpcs:enable |
1397 | 1397 | $user = new User($this->db); |
1398 | - $result=$user->fetch($userid); |
|
1398 | + $result = $user->fetch($userid); |
|
1399 | 1399 | $this->user = $user; |
1400 | 1400 | return $result; |
1401 | 1401 | } |
@@ -1433,14 +1433,14 @@ discard block |
||
1433 | 1433 | { |
1434 | 1434 | global $conf; |
1435 | 1435 | |
1436 | - $result=false; |
|
1436 | + $result = false; |
|
1437 | 1437 | |
1438 | 1438 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
1439 | - $sql.= " WHERE ".$field." = '".$key."'"; |
|
1440 | - if (! empty($element)) { |
|
1441 | - $sql.= " AND entity IN (".getEntity($element).")"; |
|
1439 | + $sql .= " WHERE ".$field." = '".$key."'"; |
|
1440 | + if (!empty($element)) { |
|
1441 | + $sql .= " AND entity IN (".getEntity($element).")"; |
|
1442 | 1442 | } else { |
1443 | - $sql.= " AND entity = ".$conf->entity; |
|
1443 | + $sql .= " AND entity = ".$conf->entity; |
|
1444 | 1444 | } |
1445 | 1445 | |
1446 | 1446 | dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
@@ -1467,10 +1467,10 @@ discard block |
||
1467 | 1467 | */ |
1468 | 1468 | function getValueFrom($table, $id, $field) |
1469 | 1469 | { |
1470 | - $result=false; |
|
1470 | + $result = false; |
|
1471 | 1471 | if (!empty($id) && !empty($field) && !empty($table)) { |
1472 | 1472 | $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
1473 | - $sql.= " WHERE rowid = ".$id; |
|
1473 | + $sql .= " WHERE rowid = ".$id; |
|
1474 | 1474 | |
1475 | 1475 | dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
1476 | 1476 | $resql = $this->db->query($sql); |
@@ -1499,36 +1499,36 @@ discard block |
||
1499 | 1499 | * @return int <0 if KO, >0 if OK |
1500 | 1500 | * @see updateExtraField |
1501 | 1501 | */ |
1502 | - function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif') |
|
1502 | + function setValueFrom($field, $value, $table = '', $id = null, $format = '', $id_field = '', $fuser = null, $trigkey = '', $fk_user_field = 'fk_user_modif') |
|
1503 | 1503 | { |
1504 | - global $user,$langs,$conf; |
|
1504 | + global $user, $langs, $conf; |
|
1505 | 1505 | |
1506 | - if (empty($table)) $table=$this->table_element; |
|
1507 | - if (empty($id)) $id=$this->id; |
|
1508 | - if (empty($format)) $format='text'; |
|
1509 | - if (empty($id_field)) $id_field='rowid'; |
|
1506 | + if (empty($table)) $table = $this->table_element; |
|
1507 | + if (empty($id)) $id = $this->id; |
|
1508 | + if (empty($format)) $format = 'text'; |
|
1509 | + if (empty($id_field)) $id_field = 'rowid'; |
|
1510 | 1510 | |
1511 | - $error=0; |
|
1511 | + $error = 0; |
|
1512 | 1512 | |
1513 | 1513 | $this->db->begin(); |
1514 | 1514 | |
1515 | 1515 | // Special case |
1516 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
1516 | + if ($table == 'product' && $field == 'note_private') $field = 'note'; |
|
1517 | 1517 | if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod'; |
1518 | 1518 | |
1519 | 1519 | $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
1520 | 1520 | |
1521 | - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
1522 | - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
1523 | - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
1521 | + if ($format == 'text') $sql .= $field." = '".$this->db->escape($value)."'"; |
|
1522 | + else if ($format == 'int') $sql .= $field." = ".$this->db->escape($value); |
|
1523 | + else if ($format == 'date') $sql .= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
1524 | 1524 | |
1525 | 1525 | if ($fk_user_field) |
1526 | 1526 | { |
1527 | - if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
1528 | - elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
1527 | + if (!empty($fuser) && is_object($fuser)) $sql .= ", ".$fk_user_field." = ".$fuser->id; |
|
1528 | + elseif (empty($fuser) || $fuser != 'none') $sql .= ", ".$fk_user_field." = ".$user->id; |
|
1529 | 1529 | } |
1530 | 1530 | |
1531 | - $sql.= " WHERE ".$id_field." = ".$id; |
|
1531 | + $sql .= " WHERE ".$id_field." = ".$id; |
|
1532 | 1532 | |
1533 | 1533 | dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
1534 | 1534 | $resql = $this->db->query($sql); |
@@ -1545,11 +1545,11 @@ discard block |
||
1545 | 1545 | { |
1546 | 1546 | $result = $this->fetchCommon($id); |
1547 | 1547 | } |
1548 | - if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
1548 | + if ($result >= 0) $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
1549 | 1549 | if ($result < 0) $error++; |
1550 | 1550 | } |
1551 | 1551 | |
1552 | - if (! $error) |
|
1552 | + if (!$error) |
|
1553 | 1553 | { |
1554 | 1554 | if (property_exists($this, $field)) $this->$field = $value; |
1555 | 1555 | $this->db->commit(); |
@@ -1563,7 +1563,7 @@ discard block |
||
1563 | 1563 | } |
1564 | 1564 | else |
1565 | 1565 | { |
1566 | - $this->error=$this->db->lasterror(); |
|
1566 | + $this->error = $this->db->lasterror(); |
|
1567 | 1567 | $this->db->rollback(); |
1568 | 1568 | return -1; |
1569 | 1569 | } |
@@ -1578,14 +1578,14 @@ discard block |
||
1578 | 1578 | * @param int $nodbprefix Do not include DB prefix to forge table name |
1579 | 1579 | * @return int <0 if KO, >0 if OK |
1580 | 1580 | */ |
1581 | - function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
1581 | + function load_previous_next_ref($filter, $fieldid, $nodbprefix = 0) |
|
1582 | 1582 | { |
1583 | 1583 | // phpcs:enable |
1584 | 1584 | global $conf, $user; |
1585 | 1585 | |
1586 | - if (! $this->table_element) |
|
1586 | + if (!$this->table_element) |
|
1587 | 1587 | { |
1588 | - dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
|
1588 | + dol_print_error('', get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
|
1589 | 1589 | return -1; |
1590 | 1590 | } |
1591 | 1591 | if ($fieldid == 'none') return 1; |
@@ -1600,45 +1600,45 @@ discard block |
||
1600 | 1600 | if ($this->element == 'societe') $alias = 'te'; |
1601 | 1601 | |
1602 | 1602 | $sql = "SELECT MAX(te.".$fieldid.")"; |
1603 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
1604 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1605 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1606 | - } |
|
1607 | - 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 |
|
1608 | - 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 |
|
1609 | - 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 |
|
1610 | - 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"; |
|
1611 | - $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1612 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
1613 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
1614 | - if (! empty($filter)) |
|
1615 | - { |
|
1616 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
1617 | - $sql.=$filter; |
|
1618 | - } |
|
1619 | - 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 |
|
1620 | - 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 |
|
1603 | + $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
1604 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1605 | + $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1606 | + } |
|
1607 | + 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 |
|
1608 | + 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 |
|
1609 | + 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 |
|
1610 | + 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"; |
|
1611 | + $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1612 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id; |
|
1613 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)'; |
|
1614 | + if (!empty($filter)) |
|
1615 | + { |
|
1616 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
1617 | + $sql .= $filter; |
|
1618 | + } |
|
1619 | + 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 |
|
1620 | + 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 |
|
1621 | 1621 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
1622 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1623 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
1624 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
1622 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1623 | + if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
1624 | + $sql .= " AND te.entity IS NOT NULL"; // Show all users |
|
1625 | 1625 | } else { |
1626 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
1627 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1626 | + $sql .= " AND ug.fk_user = te.rowid"; |
|
1627 | + $sql .= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1628 | 1628 | } |
1629 | 1629 | } else { |
1630 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1630 | + $sql .= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1631 | 1631 | } |
1632 | 1632 | } |
1633 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
1634 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
1635 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
1633 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid; |
|
1634 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)'; |
|
1635 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid; |
|
1636 | 1636 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
1637 | 1637 | |
1638 | 1638 | $result = $this->db->query($sql); |
1639 | - if (! $result) |
|
1639 | + if (!$result) |
|
1640 | 1640 | { |
1641 | - $this->error=$this->db->lasterror(); |
|
1641 | + $this->error = $this->db->lasterror(); |
|
1642 | 1642 | return -1; |
1643 | 1643 | } |
1644 | 1644 | $row = $this->db->fetch_row($result); |
@@ -1646,46 +1646,46 @@ discard block |
||
1646 | 1646 | |
1647 | 1647 | |
1648 | 1648 | $sql = "SELECT MIN(te.".$fieldid.")"; |
1649 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
1650 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1651 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1652 | - } |
|
1653 | - 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 |
|
1654 | - 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 |
|
1655 | - 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 |
|
1656 | - 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"; |
|
1657 | - $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1658 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
1659 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
1660 | - if (! empty($filter)) |
|
1661 | - { |
|
1662 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
1663 | - $sql.=$filter; |
|
1664 | - } |
|
1665 | - 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 |
|
1666 | - 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 |
|
1649 | + $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
1650 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1651 | + $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
1652 | + } |
|
1653 | + 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 |
|
1654 | + 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 |
|
1655 | + 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 |
|
1656 | + 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"; |
|
1657 | + $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
1658 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id; |
|
1659 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)'; |
|
1660 | + if (!empty($filter)) |
|
1661 | + { |
|
1662 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
1663 | + $sql .= $filter; |
|
1664 | + } |
|
1665 | + 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 |
|
1666 | + 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 |
|
1667 | 1667 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { |
1668 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1669 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
1670 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
1668 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
|
1669 | + if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) { |
|
1670 | + $sql .= " AND te.entity IS NOT NULL"; // Show all users |
|
1671 | 1671 | } else { |
1672 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
1673 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1672 | + $sql .= " AND ug.fk_user = te.rowid"; |
|
1673 | + $sql .= " AND ug.entity IN (".getEntity($this->element).")"; |
|
1674 | 1674 | } |
1675 | 1675 | } else { |
1676 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1676 | + $sql .= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
1677 | 1677 | } |
1678 | 1678 | } |
1679 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
1680 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
1681 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
1679 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid; |
|
1680 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)'; |
|
1681 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid; |
|
1682 | 1682 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
1683 | 1683 | // 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 |
1684 | 1684 | |
1685 | 1685 | $result = $this->db->query($sql); |
1686 | - if (! $result) |
|
1686 | + if (!$result) |
|
1687 | 1687 | { |
1688 | - $this->error=$this->db->lasterror(); |
|
1688 | + $this->error = $this->db->lasterror(); |
|
1689 | 1689 | return -2; |
1690 | 1690 | } |
1691 | 1691 | $row = $this->db->fetch_row($result); |
@@ -1702,11 +1702,11 @@ discard block |
||
1702 | 1702 | * @return array Array of id of contacts (if source=external or internal) |
1703 | 1703 | * Array of id of third parties with at least one contact on object (if source=thirdparty) |
1704 | 1704 | */ |
1705 | - function getListContactId($source='external') |
|
1705 | + function getListContactId($source = 'external') |
|
1706 | 1706 | { |
1707 | 1707 | $contactAlreadySelected = array(); |
1708 | - $tab = $this->liste_contact(-1,$source); |
|
1709 | - $num=count($tab); |
|
1708 | + $tab = $this->liste_contact(-1, $source); |
|
1709 | + $num = count($tab); |
|
1710 | 1710 | $i = 0; |
1711 | 1711 | while ($i < $num) |
1712 | 1712 | { |
@@ -1726,24 +1726,24 @@ discard block |
||
1726 | 1726 | */ |
1727 | 1727 | function setProject($projectid) |
1728 | 1728 | { |
1729 | - if (! $this->table_element) |
|
1729 | + if (!$this->table_element) |
|
1730 | 1730 | { |
1731 | - dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
1731 | + dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined", LOG_ERR); |
|
1732 | 1732 | return -1; |
1733 | 1733 | } |
1734 | 1734 | |
1735 | 1735 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
1736 | 1736 | if ($this->table_element == 'actioncomm') |
1737 | 1737 | { |
1738 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
1739 | - else $sql.= ' SET fk_project = NULL'; |
|
1740 | - $sql.= ' WHERE id = '.$this->id; |
|
1738 | + if ($projectid) $sql .= ' SET fk_project = '.$projectid; |
|
1739 | + else $sql .= ' SET fk_project = NULL'; |
|
1740 | + $sql .= ' WHERE id = '.$this->id; |
|
1741 | 1741 | } |
1742 | 1742 | else |
1743 | 1743 | { |
1744 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
1745 | - else $sql.= ' SET fk_projet = NULL'; |
|
1746 | - $sql.= ' WHERE rowid = '.$this->id; |
|
1744 | + if ($projectid) $sql .= ' SET fk_projet = '.$projectid; |
|
1745 | + else $sql .= ' SET fk_projet = NULL'; |
|
1746 | + $sql .= ' WHERE rowid = '.$this->id; |
|
1747 | 1747 | } |
1748 | 1748 | |
1749 | 1749 | dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
@@ -1789,14 +1789,14 @@ discard block |
||
1789 | 1789 | else |
1790 | 1790 | { |
1791 | 1791 | dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
1792 | - $this->error=$this->db->error(); |
|
1792 | + $this->error = $this->db->error(); |
|
1793 | 1793 | return -1; |
1794 | 1794 | } |
1795 | 1795 | } |
1796 | 1796 | else |
1797 | 1797 | { |
1798 | 1798 | dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
1799 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
1799 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
1800 | 1800 | return -2; |
1801 | 1801 | } |
1802 | 1802 | } |
@@ -1823,21 +1823,21 @@ discard block |
||
1823 | 1823 | $this->multicurrency_code = $code; |
1824 | 1824 | |
1825 | 1825 | list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
1826 | - if ($rate) $this->setMulticurrencyRate($rate,2); |
|
1826 | + if ($rate) $this->setMulticurrencyRate($rate, 2); |
|
1827 | 1827 | |
1828 | 1828 | return 1; |
1829 | 1829 | } |
1830 | 1830 | else |
1831 | 1831 | { |
1832 | 1832 | dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
1833 | - $this->error=$this->db->error(); |
|
1833 | + $this->error = $this->db->error(); |
|
1834 | 1834 | return -1; |
1835 | 1835 | } |
1836 | 1836 | } |
1837 | 1837 | else |
1838 | 1838 | { |
1839 | 1839 | dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
1840 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
1840 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
1841 | 1841 | return -2; |
1842 | 1842 | } |
1843 | 1843 | } |
@@ -1849,7 +1849,7 @@ discard block |
||
1849 | 1849 | * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
1850 | 1850 | * @return int >0 if OK, <0 if KO |
1851 | 1851 | */ |
1852 | - function setMulticurrencyRate($rate, $mode=1) |
|
1852 | + function setMulticurrencyRate($rate, $mode = 1) |
|
1853 | 1853 | { |
1854 | 1854 | dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')'); |
1855 | 1855 | if ($this->statut >= 0 || $this->element == 'societe') |
@@ -1869,7 +1869,7 @@ discard block |
||
1869 | 1869 | { |
1870 | 1870 | foreach ($this->lines as &$line) |
1871 | 1871 | { |
1872 | - if($mode == 1) { |
|
1872 | + if ($mode == 1) { |
|
1873 | 1873 | $line->subprice = 0; |
1874 | 1874 | } |
1875 | 1875 | |
@@ -1877,14 +1877,14 @@ discard block |
||
1877 | 1877 | case 'propal': |
1878 | 1878 | $this->updateline( |
1879 | 1879 | $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
1880 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
1880 | + ($line->description ? $line->description : $line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
1881 | 1881 | $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, |
1882 | 1882 | $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
1883 | 1883 | ); |
1884 | 1884 | break; |
1885 | 1885 | case 'commande': |
1886 | 1886 | $this->updateline( |
1887 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1887 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1888 | 1888 | $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, |
1889 | 1889 | $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
1890 | 1890 | $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
@@ -1892,7 +1892,7 @@ discard block |
||
1892 | 1892 | break; |
1893 | 1893 | case 'facture': |
1894 | 1894 | $this->updateline( |
1895 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1895 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1896 | 1896 | $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, |
1897 | 1897 | $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
1898 | 1898 | $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice |
@@ -1901,21 +1901,21 @@ discard block |
||
1901 | 1901 | case 'supplier_proposal': |
1902 | 1902 | $this->updateline( |
1903 | 1903 | $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
1904 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
1904 | + ($line->description ? $line->description : $line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
1905 | 1905 | $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, |
1906 | 1906 | $line->ref_fourn, $line->multicurrency_subprice |
1907 | 1907 | ); |
1908 | 1908 | break; |
1909 | 1909 | case 'order_supplier': |
1910 | 1910 | $this->updateline( |
1911 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1911 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
1912 | 1912 | $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, |
1913 | 1913 | $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
1914 | 1914 | ); |
1915 | 1915 | break; |
1916 | 1916 | case 'invoice_supplier': |
1917 | 1917 | $this->updateline( |
1918 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
1918 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
1919 | 1919 | $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, |
1920 | 1920 | $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
1921 | 1921 | ); |
@@ -1932,14 +1932,14 @@ discard block |
||
1932 | 1932 | else |
1933 | 1933 | { |
1934 | 1934 | dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
1935 | - $this->error=$this->db->error(); |
|
1935 | + $this->error = $this->db->error(); |
|
1936 | 1936 | return -1; |
1937 | 1937 | } |
1938 | 1938 | } |
1939 | 1939 | else |
1940 | 1940 | { |
1941 | 1941 | dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
1942 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
1942 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
1943 | 1943 | return -2; |
1944 | 1944 | } |
1945 | 1945 | } |
@@ -1969,20 +1969,20 @@ discard block |
||
1969 | 1969 | $this->cond_reglement_id = $id; |
1970 | 1970 | // for supplier |
1971 | 1971 | if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
1972 | - $this->cond_reglement = $id; // for compatibility |
|
1972 | + $this->cond_reglement = $id; // for compatibility |
|
1973 | 1973 | return 1; |
1974 | 1974 | } |
1975 | 1975 | else |
1976 | 1976 | { |
1977 | 1977 | dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
1978 | - $this->error=$this->db->error(); |
|
1978 | + $this->error = $this->db->error(); |
|
1979 | 1979 | return -1; |
1980 | 1980 | } |
1981 | 1981 | } |
1982 | 1982 | else |
1983 | 1983 | { |
1984 | 1984 | dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
1985 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
1985 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
1986 | 1986 | return -2; |
1987 | 1987 | } |
1988 | 1988 | } |
@@ -2000,7 +2000,7 @@ discard block |
||
2000 | 2000 | if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
2001 | 2001 | |
2002 | 2002 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
2003 | - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
2003 | + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
2004 | 2004 | |
2005 | 2005 | if ($this->db->query($sql)) |
2006 | 2006 | { |
@@ -2009,7 +2009,7 @@ discard block |
||
2009 | 2009 | } |
2010 | 2010 | else |
2011 | 2011 | { |
2012 | - $this->error=$this->db->error(); |
|
2012 | + $this->error = $this->db->error(); |
|
2013 | 2013 | dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
2014 | 2014 | return -1; |
2015 | 2015 | } |
@@ -2025,29 +2025,29 @@ discard block |
||
2025 | 2025 | * |
2026 | 2026 | * @return int 1 if OK, 0 if KO |
2027 | 2027 | */ |
2028 | - function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
2028 | + function setShippingMethod($shipping_method_id, $notrigger = false, $userused = null) |
|
2029 | 2029 | { |
2030 | 2030 | global $user; |
2031 | 2031 | |
2032 | - if (empty($userused)) $userused=$user; |
|
2032 | + if (empty($userused)) $userused = $user; |
|
2033 | 2033 | |
2034 | 2034 | $error = 0; |
2035 | 2035 | |
2036 | - if (! $this->table_element) { |
|
2037 | - dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
2036 | + if (!$this->table_element) { |
|
2037 | + dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined", LOG_ERR); |
|
2038 | 2038 | return -1; |
2039 | 2039 | } |
2040 | 2040 | |
2041 | 2041 | $this->db->begin(); |
2042 | 2042 | |
2043 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
2043 | + if ($shipping_method_id < 0) $shipping_method_id = 'NULL'; |
|
2044 | 2044 | dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); |
2045 | 2045 | |
2046 | 2046 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
2047 | - $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
2048 | - $sql.= " WHERE rowid=".$this->id; |
|
2047 | + $sql .= " SET fk_shipping_method = ".$shipping_method_id; |
|
2048 | + $sql .= " WHERE rowid=".$this->id; |
|
2049 | 2049 | $resql = $this->db->query($sql); |
2050 | - if (! $resql) { |
|
2050 | + if (!$resql) { |
|
2051 | 2051 | dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
2052 | 2052 | $this->error = $this->db->lasterror(); |
2053 | 2053 | $error++; |
@@ -2055,8 +2055,8 @@ discard block |
||
2055 | 2055 | if (!$notrigger) |
2056 | 2056 | { |
2057 | 2057 | // Call trigger |
2058 | - $this->context=array('shippingmethodupdate'=>1); |
|
2059 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
2058 | + $this->context = array('shippingmethodupdate'=>1); |
|
2059 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
2060 | 2060 | if ($result < 0) $error++; |
2061 | 2061 | // End call trigger |
2062 | 2062 | } |
@@ -2066,7 +2066,7 @@ discard block |
||
2066 | 2066 | $this->db->rollback(); |
2067 | 2067 | return -1; |
2068 | 2068 | } else { |
2069 | - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
2069 | + $this->shipping_method_id = ($shipping_method_id == 'NULL') ?null:$shipping_method_id; |
|
2070 | 2070 | $this->db->commit(); |
2071 | 2071 | return 1; |
2072 | 2072 | } |
@@ -2081,23 +2081,23 @@ discard block |
||
2081 | 2081 | */ |
2082 | 2082 | function setWarehouse($warehouse_id) |
2083 | 2083 | { |
2084 | - if (! $this->table_element) { |
|
2085 | - dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
2084 | + if (!$this->table_element) { |
|
2085 | + dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined", LOG_ERR); |
|
2086 | 2086 | return -1; |
2087 | 2087 | } |
2088 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
2088 | + if ($warehouse_id < 0) $warehouse_id = 'NULL'; |
|
2089 | 2089 | dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); |
2090 | 2090 | |
2091 | 2091 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
2092 | - $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
2093 | - $sql.= " WHERE rowid=".$this->id; |
|
2092 | + $sql .= " SET fk_warehouse = ".$warehouse_id; |
|
2093 | + $sql .= " WHERE rowid=".$this->id; |
|
2094 | 2094 | |
2095 | 2095 | if ($this->db->query($sql)) { |
2096 | - $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
2096 | + $this->warehouse_id = ($warehouse_id == 'NULL') ?null:$warehouse_id; |
|
2097 | 2097 | return 1; |
2098 | 2098 | } else { |
2099 | 2099 | dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
2100 | - $this->error=$this->db->error(); |
|
2100 | + $this->error = $this->db->error(); |
|
2101 | 2101 | return 0; |
2102 | 2102 | } |
2103 | 2103 | } |
@@ -2112,25 +2112,25 @@ discard block |
||
2112 | 2112 | */ |
2113 | 2113 | function setDocModel($user, $modelpdf) |
2114 | 2114 | { |
2115 | - if (! $this->table_element) |
|
2115 | + if (!$this->table_element) |
|
2116 | 2116 | { |
2117 | - dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
2117 | + dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined", LOG_ERR); |
|
2118 | 2118 | return -1; |
2119 | 2119 | } |
2120 | 2120 | |
2121 | - $newmodelpdf=dol_trunc($modelpdf,255); |
|
2121 | + $newmodelpdf = dol_trunc($modelpdf, 255); |
|
2122 | 2122 | |
2123 | 2123 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
2124 | - $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
2125 | - $sql.= " WHERE rowid = ".$this->id; |
|
2124 | + $sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
2125 | + $sql .= " WHERE rowid = ".$this->id; |
|
2126 | 2126 | // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
2127 | 2127 | // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
2128 | 2128 | |
2129 | 2129 | dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
2130 | - $resql=$this->db->query($sql); |
|
2130 | + $resql = $this->db->query($sql); |
|
2131 | 2131 | if ($resql) |
2132 | 2132 | { |
2133 | - $this->modelpdf=$modelpdf; |
|
2133 | + $this->modelpdf = $modelpdf; |
|
2134 | 2134 | return 1; |
2135 | 2135 | } |
2136 | 2136 | else |
@@ -2149,29 +2149,29 @@ discard block |
||
2149 | 2149 | * @param User $userused Object user |
2150 | 2150 | * @return int 1 if OK, 0 if KO |
2151 | 2151 | */ |
2152 | - function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
2152 | + function setBankAccount($fk_account, $notrigger = false, $userused = null) |
|
2153 | 2153 | { |
2154 | 2154 | global $user; |
2155 | 2155 | |
2156 | - if (empty($userused)) $userused=$user; |
|
2156 | + if (empty($userused)) $userused = $user; |
|
2157 | 2157 | |
2158 | 2158 | $error = 0; |
2159 | 2159 | |
2160 | - if (! $this->table_element) { |
|
2161 | - dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
2160 | + if (!$this->table_element) { |
|
2161 | + dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined", LOG_ERR); |
|
2162 | 2162 | return -1; |
2163 | 2163 | } |
2164 | 2164 | $this->db->begin(); |
2165 | 2165 | |
2166 | - if ($fk_account<0) $fk_account='NULL'; |
|
2166 | + if ($fk_account < 0) $fk_account = 'NULL'; |
|
2167 | 2167 | dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); |
2168 | 2168 | |
2169 | 2169 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
2170 | - $sql.= " SET fk_account = ".$fk_account; |
|
2171 | - $sql.= " WHERE rowid=".$this->id; |
|
2170 | + $sql .= " SET fk_account = ".$fk_account; |
|
2171 | + $sql .= " WHERE rowid=".$this->id; |
|
2172 | 2172 | |
2173 | 2173 | $resql = $this->db->query($sql); |
2174 | - if (! $resql) |
|
2174 | + if (!$resql) |
|
2175 | 2175 | { |
2176 | 2176 | dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
2177 | 2177 | $this->error = $this->db->lasterror(); |
@@ -2182,8 +2182,8 @@ discard block |
||
2182 | 2182 | if (!$notrigger) |
2183 | 2183 | { |
2184 | 2184 | // Call trigger |
2185 | - $this->context=array('bankaccountupdate'=>1); |
|
2186 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
2185 | + $this->context = array('bankaccountupdate'=>1); |
|
2186 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
2187 | 2187 | if ($result < 0) $error++; |
2188 | 2188 | // End call trigger |
2189 | 2189 | } |
@@ -2195,7 +2195,7 @@ discard block |
||
2195 | 2195 | } |
2196 | 2196 | else |
2197 | 2197 | { |
2198 | - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
2198 | + $this->fk_account = ($fk_account == 'NULL') ?null:$fk_account; |
|
2199 | 2199 | $this->db->commit(); |
2200 | 2200 | return 1; |
2201 | 2201 | } |
@@ -2214,26 +2214,26 @@ discard block |
||
2214 | 2214 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
2215 | 2215 | * @return int <0 if KO, >0 if OK |
2216 | 2216 | */ |
2217 | - function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
2217 | + function line_order($renum = false, $rowidorder = 'ASC', $fk_parent_line = true) |
|
2218 | 2218 | { |
2219 | 2219 | // phpcs:enable |
2220 | - if (! $this->table_element_line) |
|
2220 | + if (!$this->table_element_line) |
|
2221 | 2221 | { |
2222 | - dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
2222 | + dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined", LOG_ERR); |
|
2223 | 2223 | return -1; |
2224 | 2224 | } |
2225 | - if (! $this->fk_element) |
|
2225 | + if (!$this->fk_element) |
|
2226 | 2226 | { |
2227 | - dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
2227 | + dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined", LOG_ERR); |
|
2228 | 2228 | return -1; |
2229 | 2229 | } |
2230 | 2230 | |
2231 | 2231 | // Count number of lines to reorder (according to choice $renum) |
2232 | - $nl=0; |
|
2232 | + $nl = 0; |
|
2233 | 2233 | $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
2234 | - $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
2235 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
2236 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
2234 | + $sql .= ' WHERE '.$this->fk_element.'='.$this->id; |
|
2235 | + if (!$renum) $sql .= ' AND rang = 0'; |
|
2236 | + if ($renum) $sql .= ' AND rang <> 0'; |
|
2237 | 2237 | |
2238 | 2238 | dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
2239 | 2239 | $resql = $this->db->query($sql); |
@@ -2247,28 +2247,28 @@ discard block |
||
2247 | 2247 | { |
2248 | 2248 | // The goal of this part is to reorder all lines, with all children lines sharing the same |
2249 | 2249 | // counter that parents. |
2250 | - $rows=array(); |
|
2250 | + $rows = array(); |
|
2251 | 2251 | |
2252 | 2252 | // We first search all lines that are parent lines (for multilevel details lines) |
2253 | 2253 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
2254 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2255 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
2256 | - $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
2254 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2255 | + if ($fk_parent_line) $sql .= ' AND fk_parent_line IS NULL'; |
|
2256 | + $sql .= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
2257 | 2257 | |
2258 | 2258 | dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
2259 | 2259 | $resql = $this->db->query($sql); |
2260 | 2260 | if ($resql) |
2261 | 2261 | { |
2262 | - $i=0; |
|
2262 | + $i = 0; |
|
2263 | 2263 | $num = $this->db->num_rows($resql); |
2264 | 2264 | while ($i < $num) |
2265 | 2265 | { |
2266 | 2266 | $row = $this->db->fetch_row($resql); |
2267 | - $rows[] = $row[0]; // Add parent line into array rows |
|
2267 | + $rows[] = $row[0]; // Add parent line into array rows |
|
2268 | 2268 | $childrens = $this->getChildrenOfLine($row[0]); |
2269 | - if (! empty($childrens)) |
|
2269 | + if (!empty($childrens)) |
|
2270 | 2270 | { |
2271 | - foreach($childrens as $child) |
|
2271 | + foreach ($childrens as $child) |
|
2272 | 2272 | { |
2273 | 2273 | array_push($rows, $child); |
2274 | 2274 | } |
@@ -2277,11 +2277,11 @@ discard block |
||
2277 | 2277 | } |
2278 | 2278 | |
2279 | 2279 | // Now we set a new number for each lines (parent and children with children included into parent tree) |
2280 | - if (! empty($rows)) |
|
2280 | + if (!empty($rows)) |
|
2281 | 2281 | { |
2282 | - foreach($rows as $key => $row) |
|
2282 | + foreach ($rows as $key => $row) |
|
2283 | 2283 | { |
2284 | - $this->updateRangOfLine($row, ($key+1)); |
|
2284 | + $this->updateRangOfLine($row, ($key + 1)); |
|
2285 | 2285 | } |
2286 | 2286 | } |
2287 | 2287 | } |
@@ -2301,18 +2301,18 @@ discard block |
||
2301 | 2301 | */ |
2302 | 2302 | function getChildrenOfLine($id) |
2303 | 2303 | { |
2304 | - $rows=array(); |
|
2304 | + $rows = array(); |
|
2305 | 2305 | |
2306 | 2306 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
2307 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2308 | - $sql.= ' AND fk_parent_line = '.$id; |
|
2309 | - $sql.= ' ORDER BY rang ASC'; |
|
2307 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2308 | + $sql .= ' AND fk_parent_line = '.$id; |
|
2309 | + $sql .= ' ORDER BY rang ASC'; |
|
2310 | 2310 | |
2311 | 2311 | dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
2312 | 2312 | $resql = $this->db->query($sql); |
2313 | 2313 | if ($resql) |
2314 | 2314 | { |
2315 | - $i=0; |
|
2315 | + $i = 0; |
|
2316 | 2316 | $num = $this->db->num_rows($resql); |
2317 | 2317 | while ($i < $num) |
2318 | 2318 | { |
@@ -2333,7 +2333,7 @@ discard block |
||
2333 | 2333 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
2334 | 2334 | * @return void |
2335 | 2335 | */ |
2336 | - function line_up($rowid, $fk_parent_line=true) |
|
2336 | + function line_up($rowid, $fk_parent_line = true) |
|
2337 | 2337 | { |
2338 | 2338 | // phpcs:enable |
2339 | 2339 | $this->line_order(false, 'ASC', $fk_parent_line); |
@@ -2353,7 +2353,7 @@ discard block |
||
2353 | 2353 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
2354 | 2354 | * @return void |
2355 | 2355 | */ |
2356 | - function line_down($rowid, $fk_parent_line=true) |
|
2356 | + function line_down($rowid, $fk_parent_line = true) |
|
2357 | 2357 | { |
2358 | 2358 | // phpcs:enable |
2359 | 2359 | $this->line_order(false, 'ASC', $fk_parent_line); |
@@ -2375,16 +2375,16 @@ discard block |
||
2375 | 2375 | * @param int $rang Position |
2376 | 2376 | * @return void |
2377 | 2377 | */ |
2378 | - function updateRangOfLine($rowid,$rang) |
|
2378 | + function updateRangOfLine($rowid, $rang) |
|
2379 | 2379 | { |
2380 | 2380 | $fieldposition = 'rang'; |
2381 | 2381 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
2382 | 2382 | |
2383 | 2383 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
2384 | - $sql.= ' WHERE rowid = '.$rowid; |
|
2384 | + $sql .= ' WHERE rowid = '.$rowid; |
|
2385 | 2385 | |
2386 | 2386 | dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
2387 | - if (! $this->db->query($sql)) |
|
2387 | + if (!$this->db->query($sql)) |
|
2388 | 2388 | { |
2389 | 2389 | dol_print_error($this->db); |
2390 | 2390 | } |
@@ -2401,9 +2401,9 @@ discard block |
||
2401 | 2401 | { |
2402 | 2402 | // phpcs:enable |
2403 | 2403 | $num = count($rows); |
2404 | - for ($i = 0 ; $i < $num ; $i++) |
|
2404 | + for ($i = 0; $i < $num; $i++) |
|
2405 | 2405 | { |
2406 | - $this->updateRangOfLine($rows[$i], ($i+1)); |
|
2406 | + $this->updateRangOfLine($rows[$i], ($i + 1)); |
|
2407 | 2407 | } |
2408 | 2408 | } |
2409 | 2409 | |
@@ -2414,21 +2414,21 @@ discard block |
||
2414 | 2414 | * @param int $rang Position |
2415 | 2415 | * @return void |
2416 | 2416 | */ |
2417 | - function updateLineUp($rowid,$rang) |
|
2417 | + function updateLineUp($rowid, $rang) |
|
2418 | 2418 | { |
2419 | 2419 | if ($rang > 1) |
2420 | 2420 | { |
2421 | 2421 | $fieldposition = 'rang'; |
2422 | 2422 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
2423 | 2423 | |
2424 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
|
2425 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2426 | - $sql.= ' AND rang = '.($rang - 1); |
|
2427 | - if ($this->db->query($sql) ) |
|
2424 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
2425 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2426 | + $sql .= ' AND rang = '.($rang - 1); |
|
2427 | + if ($this->db->query($sql)) |
|
2428 | 2428 | { |
2429 | 2429 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
2430 | - $sql.= ' WHERE rowid = '.$rowid; |
|
2431 | - if (! $this->db->query($sql) ) |
|
2430 | + $sql .= ' WHERE rowid = '.$rowid; |
|
2431 | + if (!$this->db->query($sql)) |
|
2432 | 2432 | { |
2433 | 2433 | dol_print_error($this->db); |
2434 | 2434 | } |
@@ -2448,7 +2448,7 @@ discard block |
||
2448 | 2448 | * @param int $max Max |
2449 | 2449 | * @return void |
2450 | 2450 | */ |
2451 | - function updateLineDown($rowid,$rang,$max) |
|
2451 | + function updateLineDown($rowid, $rang, $max) |
|
2452 | 2452 | { |
2453 | 2453 | if ($rang < $max) |
2454 | 2454 | { |
@@ -2456,13 +2456,13 @@ discard block |
||
2456 | 2456 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position'; |
2457 | 2457 | |
2458 | 2458 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
2459 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2460 | - $sql.= ' AND rang = '.($rang+1); |
|
2461 | - if ($this->db->query($sql) ) |
|
2459 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2460 | + $sql .= ' AND rang = '.($rang + 1); |
|
2461 | + if ($this->db->query($sql)) |
|
2462 | 2462 | { |
2463 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang+1); |
|
2464 | - $sql.= ' WHERE rowid = '.$rowid; |
|
2465 | - if (! $this->db->query($sql) ) |
|
2463 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang + 1); |
|
2464 | + $sql .= ' WHERE rowid = '.$rowid; |
|
2465 | + if (!$this->db->query($sql)) |
|
2466 | 2466 | { |
2467 | 2467 | dol_print_error($this->db); |
2468 | 2468 | } |
@@ -2483,7 +2483,7 @@ discard block |
||
2483 | 2483 | function getRangOfLine($rowid) |
2484 | 2484 | { |
2485 | 2485 | $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
2486 | - $sql.= ' WHERE rowid ='.$rowid; |
|
2486 | + $sql .= ' WHERE rowid ='.$rowid; |
|
2487 | 2487 | |
2488 | 2488 | dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
2489 | 2489 | $resql = $this->db->query($sql); |
@@ -2503,8 +2503,8 @@ discard block |
||
2503 | 2503 | function getIdOfLine($rang) |
2504 | 2504 | { |
2505 | 2505 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
2506 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2507 | - $sql.= ' AND rang = '.$rang; |
|
2506 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2507 | + $sql .= ' AND rang = '.$rang; |
|
2508 | 2508 | $resql = $this->db->query($sql); |
2509 | 2509 | if ($resql) |
2510 | 2510 | { |
@@ -2520,22 +2520,22 @@ discard block |
||
2520 | 2520 | * @param int $fk_parent_line Parent line id |
2521 | 2521 | * @return int Max value of rang in table of lines |
2522 | 2522 | */ |
2523 | - function line_max($fk_parent_line=0) |
|
2523 | + function line_max($fk_parent_line = 0) |
|
2524 | 2524 | { |
2525 | 2525 | // phpcs:enable |
2526 | 2526 | // Search the last rang with fk_parent_line |
2527 | 2527 | if ($fk_parent_line) |
2528 | 2528 | { |
2529 | 2529 | $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
2530 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2531 | - $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
2530 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2531 | + $sql .= ' AND fk_parent_line = '.$fk_parent_line; |
|
2532 | 2532 | |
2533 | 2533 | dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
2534 | 2534 | $resql = $this->db->query($sql); |
2535 | 2535 | if ($resql) |
2536 | 2536 | { |
2537 | 2537 | $row = $this->db->fetch_row($resql); |
2538 | - if (! empty($row[0])) |
|
2538 | + if (!empty($row[0])) |
|
2539 | 2539 | { |
2540 | 2540 | return $row[0]; |
2541 | 2541 | } |
@@ -2549,7 +2549,7 @@ discard block |
||
2549 | 2549 | else |
2550 | 2550 | { |
2551 | 2551 | $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
2552 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2552 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2553 | 2553 | |
2554 | 2554 | dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
2555 | 2555 | $resql = $this->db->query($sql); |
@@ -2571,15 +2571,15 @@ discard block |
||
2571 | 2571 | function update_ref_ext($ref_ext) |
2572 | 2572 | { |
2573 | 2573 | // phpcs:enable |
2574 | - if (! $this->table_element) |
|
2574 | + if (!$this->table_element) |
|
2575 | 2575 | { |
2576 | 2576 | dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
2577 | 2577 | return -1; |
2578 | 2578 | } |
2579 | 2579 | |
2580 | 2580 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
2581 | - $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
2582 | - $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
2581 | + $sql .= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
2582 | + $sql .= " WHERE ".(isset($this->table_rowid) ? $this->table_rowid : 'rowid')." = ".$this->id; |
|
2583 | 2583 | |
2584 | 2584 | dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
2585 | 2585 | if ($this->db->query($sql)) |
@@ -2589,7 +2589,7 @@ discard block |
||
2589 | 2589 | } |
2590 | 2590 | else |
2591 | 2591 | { |
2592 | - $this->error=$this->db->error(); |
|
2592 | + $this->error = $this->db->error(); |
|
2593 | 2593 | return -1; |
2594 | 2594 | } |
2595 | 2595 | } |
@@ -2602,31 +2602,31 @@ discard block |
||
2602 | 2602 | * @param string $suffix '', '_public' or '_private' |
2603 | 2603 | * @return int <0 if KO, >0 if OK |
2604 | 2604 | */ |
2605 | - function update_note($note, $suffix='') |
|
2605 | + function update_note($note, $suffix = '') |
|
2606 | 2606 | { |
2607 | 2607 | // phpcs:enable |
2608 | 2608 | global $user; |
2609 | 2609 | |
2610 | - if (! $this->table_element) |
|
2610 | + if (!$this->table_element) |
|
2611 | 2611 | { |
2612 | - $this->error='update_note was called on objet with property table_element not defined'; |
|
2612 | + $this->error = 'update_note was called on objet with property table_element not defined'; |
|
2613 | 2613 | dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
2614 | 2614 | return -1; |
2615 | 2615 | } |
2616 | - if (! in_array($suffix,array('','_public','_private'))) |
|
2616 | + if (!in_array($suffix, array('', '_public', '_private'))) |
|
2617 | 2617 | { |
2618 | - $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
2618 | + $this->error = 'update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
2619 | 2619 | dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
2620 | 2620 | return -2; |
2621 | 2621 | } |
2622 | 2622 | // Special cas |
2623 | 2623 | //var_dump($this->table_element);exit; |
2624 | - if ($this->table_element == 'product') $suffix=''; |
|
2624 | + if ($this->table_element == 'product') $suffix = ''; |
|
2625 | 2625 | |
2626 | 2626 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
2627 | - $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL"); |
|
2628 | - $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id; |
|
2629 | - $sql.= " WHERE rowid =". $this->id; |
|
2627 | + $sql .= " SET note".$suffix." = ".(!empty($note) ? ("'".$this->db->escape($note)."'") : "NULL"); |
|
2628 | + $sql .= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment')) ? "fk_user_mod" : "fk_user_modif")." = ".$user->id; |
|
2629 | + $sql .= " WHERE rowid =".$this->id; |
|
2630 | 2630 | |
2631 | 2631 | dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
2632 | 2632 | if ($this->db->query($sql)) |
@@ -2635,14 +2635,14 @@ discard block |
||
2635 | 2635 | else if ($suffix == '_private') $this->note_private = $note; |
2636 | 2636 | else |
2637 | 2637 | { |
2638 | - $this->note = $note; // deprecated |
|
2638 | + $this->note = $note; // deprecated |
|
2639 | 2639 | $this->note_private = $note; |
2640 | 2640 | } |
2641 | 2641 | return 1; |
2642 | 2642 | } |
2643 | 2643 | else |
2644 | 2644 | { |
2645 | - $this->error=$this->db->lasterror(); |
|
2645 | + $this->error = $this->db->lasterror(); |
|
2646 | 2646 | return -1; |
2647 | 2647 | } |
2648 | 2648 | } |
@@ -2659,7 +2659,7 @@ discard block |
||
2659 | 2659 | function update_note_public($note) |
2660 | 2660 | { |
2661 | 2661 | // phpcs:enable |
2662 | - return $this->update_note($note,'_public'); |
|
2662 | + return $this->update_note($note, '_public'); |
|
2663 | 2663 | } |
2664 | 2664 | |
2665 | 2665 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -2673,7 +2673,7 @@ discard block |
||
2673 | 2673 | * @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. |
2674 | 2674 | * @return int <0 if KO, >0 if OK |
2675 | 2675 | */ |
2676 | - function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
2676 | + function update_price($exclspec = 0, $roundingadjust = 'none', $nodatabaseupdate = 0, $seller = null) |
|
2677 | 2677 | { |
2678 | 2678 | // phpcs:enable |
2679 | 2679 | global $conf, $hookmanager, $action; |
@@ -2693,8 +2693,8 @@ discard block |
||
2693 | 2693 | elseif ($this->element == 'supplier_proposal') |
2694 | 2694 | $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
2695 | 2695 | |
2696 | - if (! empty($MODULE)) { |
|
2697 | - if (! empty($conf->global->$MODULE)) { |
|
2696 | + if (!empty($MODULE)) { |
|
2697 | + if (!empty($conf->global->$MODULE)) { |
|
2698 | 2698 | $modsactivated = explode(',', $conf->global->$MODULE); |
2699 | 2699 | foreach ($modsactivated as $mod) { |
2700 | 2700 | if ($conf->$mod->enabled) |
@@ -2705,44 +2705,44 @@ discard block |
||
2705 | 2705 | |
2706 | 2706 | include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
2707 | 2707 | |
2708 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
2708 | + if ($roundingadjust == '-1') $roundingadjust = 'auto'; // For backward compatibility |
|
2709 | 2709 | |
2710 | - $forcedroundingmode=$roundingadjust; |
|
2711 | - if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
2712 | - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
2710 | + $forcedroundingmode = $roundingadjust; |
|
2711 | + if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode = $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
2712 | + elseif ($forcedroundingmode == 'auto') $forcedroundingmode = '0'; |
|
2713 | 2713 | |
2714 | - $error=0; |
|
2714 | + $error = 0; |
|
2715 | 2715 | |
2716 | 2716 | $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
2717 | 2717 | |
2718 | 2718 | // Define constants to find lines to sum |
2719 | - $fieldtva='total_tva'; |
|
2720 | - $fieldlocaltax1='total_localtax1'; |
|
2721 | - $fieldlocaltax2='total_localtax2'; |
|
2722 | - $fieldup='subprice'; |
|
2719 | + $fieldtva = 'total_tva'; |
|
2720 | + $fieldlocaltax1 = 'total_localtax1'; |
|
2721 | + $fieldlocaltax2 = 'total_localtax2'; |
|
2722 | + $fieldup = 'subprice'; |
|
2723 | 2723 | if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
2724 | 2724 | { |
2725 | - $fieldtva='tva'; |
|
2726 | - $fieldup='pu_ht'; |
|
2725 | + $fieldtva = 'tva'; |
|
2726 | + $fieldup = 'pu_ht'; |
|
2727 | 2727 | } |
2728 | 2728 | if ($this->element == 'expensereport') |
2729 | 2729 | { |
2730 | - $fieldup='value_unit'; |
|
2730 | + $fieldup = 'value_unit'; |
|
2731 | 2731 | } |
2732 | 2732 | |
2733 | 2733 | $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,'; |
2734 | - $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
2735 | - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
2736 | - $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
2737 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2738 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2734 | + $sql .= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
2735 | + if ($this->table_element_line == 'facturedet') $sql .= ', situation_percent'; |
|
2736 | + $sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
2737 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
2738 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
2739 | 2739 | if ($exclspec) |
2740 | 2740 | { |
2741 | - $product_field='product_type'; |
|
2742 | - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
2743 | - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
2741 | + $product_field = 'product_type'; |
|
2742 | + if ($this->table_element_line == 'contratdet') $product_field = ''; // contratdet table has no product_type field |
|
2743 | + if ($product_field) $sql .= ' AND '.$product_field.' <> 9'; |
|
2744 | 2744 | } |
2745 | - $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 |
|
2745 | + $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 | 2746 | |
2747 | 2747 | dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
2748 | 2748 | $resql = $this->db->query($sql); |
@@ -2756,7 +2756,7 @@ discard block |
||
2756 | 2756 | $total_ht_by_vats = array(); |
2757 | 2757 | $total_tva_by_vats = array(); |
2758 | 2758 | $total_ttc_by_vats = array(); |
2759 | - $this->multicurrency_total_ht = 0; |
|
2759 | + $this->multicurrency_total_ht = 0; |
|
2760 | 2760 | $this->multicurrency_total_tva = 0; |
2761 | 2761 | $this->multicurrency_total_ttc = 0; |
2762 | 2762 | |
@@ -2767,54 +2767,54 @@ discard block |
||
2767 | 2767 | $obj = $this->db->fetch_object($resql); |
2768 | 2768 | |
2769 | 2769 | // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
2770 | - $parameters=array('fk_element' => $obj->rowid); |
|
2770 | + $parameters = array('fk_element' => $obj->rowid); |
|
2771 | 2771 | $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
2772 | 2772 | |
2773 | 2773 | 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' |
2774 | 2774 | { |
2775 | - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
2776 | - $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); |
|
2777 | - $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
2775 | + $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx); |
|
2776 | + $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); |
|
2777 | + $diff = price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
2778 | 2778 | if ($diff) |
2779 | 2779 | { |
2780 | - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
2780 | + $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
2781 | 2781 | 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); |
2782 | - $resqlfix=$this->db->query($sqlfix); |
|
2783 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
2782 | + $resqlfix = $this->db->query($sqlfix); |
|
2783 | + if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
|
2784 | 2784 | $obj->total_tva = $tmpcal[1]; |
2785 | 2785 | $obj->total_ttc = $tmpcal[2]; |
2786 | 2786 | // |
2787 | 2787 | } |
2788 | 2788 | } |
2789 | 2789 | |
2790 | - $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
2790 | + $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
2791 | 2791 | $this->total_tva += $obj->total_tva; |
2792 | 2792 | $this->total_localtax1 += $obj->total_localtax1; |
2793 | 2793 | $this->total_localtax2 += $obj->total_localtax2; |
2794 | 2794 | $this->total_ttc += $obj->total_ttc; |
2795 | - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
2795 | + $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
2796 | 2796 | $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
2797 | 2797 | $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
2798 | 2798 | |
2799 | - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
2800 | - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
2801 | - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
2799 | + if (!isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate] = 0; |
|
2800 | + if (!isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate] = 0; |
|
2801 | + if (!isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate] = 0; |
|
2802 | 2802 | $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
2803 | 2803 | $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
2804 | 2804 | $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
2805 | 2805 | |
2806 | 2806 | if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
2807 | 2807 | { |
2808 | - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
2809 | - $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
2808 | + $tmpvat = price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
2809 | + $diff = price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat, 'MT', 1); |
|
2810 | 2810 | //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"; |
2811 | 2811 | if ($diff) |
2812 | 2812 | { |
2813 | 2813 | if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; } |
2814 | - $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; |
|
2814 | + $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 | 2815 | 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); |
2816 | - $resqlfix=$this->db->query($sqlfix); |
|
2817 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
2816 | + $resqlfix = $this->db->query($sqlfix); |
|
2817 | + if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
|
2818 | 2818 | $this->total_tva -= $diff; |
2819 | 2819 | $this->total_ttc -= $diff; |
2820 | 2820 | $total_tva_by_vats[$obj->vatrate] -= $diff; |
@@ -2826,11 +2826,11 @@ discard block |
||
2826 | 2826 | } |
2827 | 2827 | |
2828 | 2828 | // Add revenue stamp to total |
2829 | - $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
2830 | - $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
2829 | + $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0; |
|
2830 | + $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0; |
|
2831 | 2831 | |
2832 | 2832 | // Situations totals |
2833 | - if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE ) |
|
2833 | + if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE) |
|
2834 | 2834 | { |
2835 | 2835 | $prev_sits = $this->get_prev_sits(); |
2836 | 2836 | |
@@ -2849,17 +2849,17 @@ discard block |
||
2849 | 2849 | $this->db->free($resql); |
2850 | 2850 | |
2851 | 2851 | // Now update global field total_ht, total_ttc and tva |
2852 | - $fieldht='total_ht'; |
|
2853 | - $fieldtva='tva'; |
|
2854 | - $fieldlocaltax1='localtax1'; |
|
2855 | - $fieldlocaltax2='localtax2'; |
|
2856 | - $fieldttc='total_ttc'; |
|
2852 | + $fieldht = 'total_ht'; |
|
2853 | + $fieldtva = 'tva'; |
|
2854 | + $fieldlocaltax1 = 'localtax1'; |
|
2855 | + $fieldlocaltax2 = 'localtax2'; |
|
2856 | + $fieldttc = 'total_ttc'; |
|
2857 | 2857 | // Specific code for backward compatibility with old field names |
2858 | - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
2859 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
2860 | - if ($this->element == 'propal') $fieldttc='total'; |
|
2861 | - if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
2862 | - if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
2858 | + if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht = 'total'; |
|
2859 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva = 'total_tva'; |
|
2860 | + if ($this->element == 'propal') $fieldttc = 'total'; |
|
2861 | + if ($this->element == 'expensereport') $fieldtva = 'total_tva'; |
|
2862 | + if ($this->element == 'supplier_proposal') $fieldttc = 'total'; |
|
2863 | 2863 | |
2864 | 2864 | if (empty($nodatabaseupdate)) |
2865 | 2865 | { |
@@ -2876,16 +2876,16 @@ discard block |
||
2876 | 2876 | |
2877 | 2877 | |
2878 | 2878 | dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
2879 | - $resql=$this->db->query($sql); |
|
2880 | - if (! $resql) |
|
2879 | + $resql = $this->db->query($sql); |
|
2880 | + if (!$resql) |
|
2881 | 2881 | { |
2882 | 2882 | $error++; |
2883 | - $this->error=$this->db->lasterror(); |
|
2884 | - $this->errors[]=$this->db->lasterror(); |
|
2883 | + $this->error = $this->db->lasterror(); |
|
2884 | + $this->errors[] = $this->db->lasterror(); |
|
2885 | 2885 | } |
2886 | 2886 | } |
2887 | 2887 | |
2888 | - if (! $error) |
|
2888 | + if (!$error) |
|
2889 | 2889 | { |
2890 | 2890 | return 1; |
2891 | 2891 | } |
@@ -2896,7 +2896,7 @@ discard block |
||
2896 | 2896 | } |
2897 | 2897 | else |
2898 | 2898 | { |
2899 | - dol_print_error($this->db,'Bad request in update_price'); |
|
2899 | + dol_print_error($this->db, 'Bad request in update_price'); |
|
2900 | 2900 | return -1; |
2901 | 2901 | } |
2902 | 2902 | } |
@@ -2910,30 +2910,30 @@ discard block |
||
2910 | 2910 | * @return int <=0 if KO, >0 if OK |
2911 | 2911 | * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
2912 | 2912 | */ |
2913 | - function add_object_linked($origin=null, $origin_id=null) |
|
2913 | + function add_object_linked($origin = null, $origin_id = null) |
|
2914 | 2914 | { |
2915 | 2915 | // phpcs:enable |
2916 | - $origin = (! empty($origin) ? $origin : $this->origin); |
|
2917 | - $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
2916 | + $origin = (!empty($origin) ? $origin : $this->origin); |
|
2917 | + $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id); |
|
2918 | 2918 | |
2919 | 2919 | // Special case |
2920 | - if ($origin == 'order') $origin='commande'; |
|
2921 | - if ($origin == 'invoice') $origin='facture'; |
|
2922 | - if ($origin == 'invoice_template') $origin='facturerec'; |
|
2923 | - if ($origin == 'supplierorder') $origin='order_supplier'; |
|
2920 | + if ($origin == 'order') $origin = 'commande'; |
|
2921 | + if ($origin == 'invoice') $origin = 'facture'; |
|
2922 | + if ($origin == 'invoice_template') $origin = 'facturerec'; |
|
2923 | + if ($origin == 'supplierorder') $origin = 'order_supplier'; |
|
2924 | 2924 | $this->db->begin(); |
2925 | 2925 | |
2926 | 2926 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; |
2927 | - $sql.= "fk_source"; |
|
2928 | - $sql.= ", sourcetype"; |
|
2929 | - $sql.= ", fk_target"; |
|
2930 | - $sql.= ", targettype"; |
|
2931 | - $sql.= ") VALUES ("; |
|
2932 | - $sql.= $origin_id; |
|
2933 | - $sql.= ", '".$this->db->escape($origin)."'"; |
|
2934 | - $sql.= ", ".$this->id; |
|
2935 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
2936 | - $sql.= ")"; |
|
2927 | + $sql .= "fk_source"; |
|
2928 | + $sql .= ", sourcetype"; |
|
2929 | + $sql .= ", fk_target"; |
|
2930 | + $sql .= ", targettype"; |
|
2931 | + $sql .= ") VALUES ("; |
|
2932 | + $sql .= $origin_id; |
|
2933 | + $sql .= ", '".$this->db->escape($origin)."'"; |
|
2934 | + $sql .= ", ".$this->id; |
|
2935 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
2936 | + $sql .= ")"; |
|
2937 | 2937 | |
2938 | 2938 | dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
2939 | 2939 | if ($this->db->query($sql)) |
@@ -2943,7 +2943,7 @@ discard block |
||
2943 | 2943 | } |
2944 | 2944 | else |
2945 | 2945 | { |
2946 | - $this->error=$this->db->lasterror(); |
|
2946 | + $this->error = $this->db->lasterror(); |
|
2947 | 2947 | $this->db->rollback(); |
2948 | 2948 | return 0; |
2949 | 2949 | } |
@@ -2971,33 +2971,33 @@ discard block |
||
2971 | 2971 | * @return int <0 if KO, >0 if OK |
2972 | 2972 | * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
2973 | 2973 | */ |
2974 | - function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype',$loadalsoobjects=1) |
|
2974 | + function fetchObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $clause = 'OR', $alsosametype = 1, $orderby = 'sourcetype', $loadalsoobjects = 1) |
|
2975 | 2975 | { |
2976 | 2976 | global $conf; |
2977 | 2977 | |
2978 | - $this->linkedObjectsIds=array(); |
|
2979 | - $this->linkedObjects=array(); |
|
2978 | + $this->linkedObjectsIds = array(); |
|
2979 | + $this->linkedObjects = array(); |
|
2980 | 2980 | |
2981 | - $justsource=false; |
|
2982 | - $justtarget=false; |
|
2983 | - $withtargettype=false; |
|
2984 | - $withsourcetype=false; |
|
2981 | + $justsource = false; |
|
2982 | + $justtarget = false; |
|
2983 | + $withtargettype = false; |
|
2984 | + $withsourcetype = false; |
|
2985 | 2985 | |
2986 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
2986 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) |
|
2987 | 2987 | { |
2988 | - $justsource=true; // the source (id and type) is a search criteria |
|
2989 | - if (! empty($targettype)) $withtargettype=true; |
|
2988 | + $justsource = true; // the source (id and type) is a search criteria |
|
2989 | + if (!empty($targettype)) $withtargettype = true; |
|
2990 | 2990 | } |
2991 | - if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
2991 | + if (!empty($targetid) && !empty($targettype) && empty($sourceid)) |
|
2992 | 2992 | { |
2993 | - $justtarget=true; // the target (id and type) is a search criteria |
|
2994 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
2993 | + $justtarget = true; // the target (id and type) is a search criteria |
|
2994 | + if (!empty($sourcetype)) $withsourcetype = true; |
|
2995 | 2995 | } |
2996 | 2996 | |
2997 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
2998 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
2999 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
3000 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
2997 | + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); |
|
2998 | + $targetid = (!empty($targetid) ? $targetid : $this->id); |
|
2999 | + $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); |
|
3000 | + $targettype = (!empty($targettype) ? $targettype : $this->element); |
|
3001 | 3001 | |
3002 | 3002 | /*if (empty($sourceid) && empty($targetid)) |
3003 | 3003 | { |
@@ -3007,25 +3007,25 @@ discard block |
||
3007 | 3007 | |
3008 | 3008 | // Links between objects are stored in table element_element |
3009 | 3009 | $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
3010 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
3011 | - $sql.= " WHERE "; |
|
3010 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
3011 | + $sql .= " WHERE "; |
|
3012 | 3012 | if ($justsource || $justtarget) |
3013 | 3013 | { |
3014 | 3014 | if ($justsource) |
3015 | 3015 | { |
3016 | - $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
3017 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
3016 | + $sql .= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
3017 | + if ($withtargettype) $sql .= " AND targettype = '".$targettype."'"; |
|
3018 | 3018 | } |
3019 | 3019 | else if ($justtarget) |
3020 | 3020 | { |
3021 | - $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
3022 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
3021 | + $sql .= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
3022 | + if ($withsourcetype) $sql .= " AND sourcetype = '".$sourcetype."'"; |
|
3023 | 3023 | } |
3024 | 3024 | } |
3025 | 3025 | else |
3026 | 3026 | { |
3027 | - $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
3028 | - $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
3027 | + $sql .= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
3028 | + $sql .= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
3029 | 3029 | } |
3030 | 3030 | $sql .= ' ORDER BY '.$orderby; |
3031 | 3031 | |
@@ -3042,36 +3042,36 @@ discard block |
||
3042 | 3042 | { |
3043 | 3043 | if ($justsource) |
3044 | 3044 | { |
3045 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
3045 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target; |
|
3046 | 3046 | } |
3047 | 3047 | else if ($justtarget) |
3048 | 3048 | { |
3049 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
3049 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source; |
|
3050 | 3050 | } |
3051 | 3051 | } |
3052 | 3052 | else |
3053 | 3053 | { |
3054 | 3054 | if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
3055 | 3055 | { |
3056 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
3056 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target; |
|
3057 | 3057 | } |
3058 | 3058 | if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
3059 | 3059 | { |
3060 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
3060 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source; |
|
3061 | 3061 | } |
3062 | 3062 | } |
3063 | 3063 | $i++; |
3064 | 3064 | } |
3065 | 3065 | |
3066 | - if (! empty($this->linkedObjectsIds)) |
|
3066 | + if (!empty($this->linkedObjectsIds)) |
|
3067 | 3067 | { |
3068 | 3068 | $tmparray = $this->linkedObjectsIds; |
3069 | - foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) |
|
3069 | + foreach ($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) |
|
3070 | 3070 | { |
3071 | 3071 | // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
3072 | 3072 | $module = $element = $subelement = $objecttype; |
3073 | 3073 | if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
3074 | - && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) |
|
3074 | + && preg_match('/^([^_]+)_([^_]+)/i', $objecttype, $regs)) |
|
3075 | 3075 | { |
3076 | 3076 | $module = $element = $regs[1]; |
3077 | 3077 | $subelement = $regs[2]; |
@@ -3079,31 +3079,31 @@ discard block |
||
3079 | 3079 | |
3080 | 3080 | $classpath = $element.'/class'; |
3081 | 3081 | // To work with non standard classpath or module name |
3082 | - if ($objecttype == 'facture') { |
|
3082 | + if ($objecttype == 'facture') { |
|
3083 | 3083 | $classpath = 'compta/facture/class'; |
3084 | 3084 | } |
3085 | - else if ($objecttype == 'facturerec') { |
|
3085 | + else if ($objecttype == 'facturerec') { |
|
3086 | 3086 | $classpath = 'compta/facture/class'; $module = 'facture'; |
3087 | 3087 | } |
3088 | - else if ($objecttype == 'propal') { |
|
3088 | + else if ($objecttype == 'propal') { |
|
3089 | 3089 | $classpath = 'comm/propal/class'; |
3090 | 3090 | } |
3091 | - else if ($objecttype == 'supplier_proposal') { |
|
3091 | + else if ($objecttype == 'supplier_proposal') { |
|
3092 | 3092 | $classpath = 'supplier_proposal/class'; |
3093 | 3093 | } |
3094 | - else if ($objecttype == 'shipping') { |
|
3094 | + else if ($objecttype == 'shipping') { |
|
3095 | 3095 | $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
3096 | 3096 | } |
3097 | - else if ($objecttype == 'delivery') { |
|
3097 | + else if ($objecttype == 'delivery') { |
|
3098 | 3098 | $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
3099 | 3099 | } |
3100 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
3100 | + else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
3101 | 3101 | $classpath = 'fourn/class'; $module = 'fournisseur'; |
3102 | 3102 | } |
3103 | - else if ($objecttype == 'fichinter') { |
|
3103 | + else if ($objecttype == 'fichinter') { |
|
3104 | 3104 | $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
3105 | 3105 | } |
3106 | - else if ($objecttype == 'subscription') { |
|
3106 | + else if ($objecttype == 'subscription') { |
|
3107 | 3107 | $classpath = 'adherents/class'; $module = 'adherent'; |
3108 | 3108 | } |
3109 | 3109 | |
@@ -3116,16 +3116,16 @@ discard block |
||
3116 | 3116 | else if ($objecttype == 'invoice_supplier') { |
3117 | 3117 | $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
3118 | 3118 | } |
3119 | - else if ($objecttype == 'order_supplier') { |
|
3119 | + else if ($objecttype == 'order_supplier') { |
|
3120 | 3120 | $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
3121 | 3121 | } |
3122 | - else if ($objecttype == 'supplier_proposal') { |
|
3122 | + else if ($objecttype == 'supplier_proposal') { |
|
3123 | 3123 | $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
3124 | 3124 | } |
3125 | - else if ($objecttype == 'facturerec') { |
|
3125 | + else if ($objecttype == 'facturerec') { |
|
3126 | 3126 | $classfile = 'facture-rec'; $classname = 'FactureRec'; |
3127 | 3127 | } |
3128 | - else if ($objecttype == 'subscription') { |
|
3128 | + else if ($objecttype == 'subscription') { |
|
3129 | 3129 | $classfile = 'subscription'; $classname = 'Subscription'; |
3130 | 3130 | } |
3131 | 3131 | |
@@ -3138,7 +3138,7 @@ discard block |
||
3138 | 3138 | //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
3139 | 3139 | if (class_exists($classname)) |
3140 | 3140 | { |
3141 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
3141 | + foreach ($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
3142 | 3142 | { |
3143 | 3143 | $object = new $classname($this->db); |
3144 | 3144 | $ret = $object->fetch($objectid); |
@@ -3175,28 +3175,28 @@ discard block |
||
3175 | 3175 | * @return int >0 if OK, <0 if KO |
3176 | 3176 | * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
3177 | 3177 | */ |
3178 | - function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
3178 | + function updateObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '') |
|
3179 | 3179 | { |
3180 | - $updatesource=false; |
|
3181 | - $updatetarget=false; |
|
3180 | + $updatesource = false; |
|
3181 | + $updatetarget = false; |
|
3182 | 3182 | |
3183 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
3184 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
3183 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource = true; |
|
3184 | + else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $updatetarget = true; |
|
3185 | 3185 | |
3186 | 3186 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
3187 | 3187 | if ($updatesource) |
3188 | 3188 | { |
3189 | - $sql.= "fk_source = ".$sourceid; |
|
3190 | - $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3191 | - $sql.= " WHERE fk_target = ".$this->id; |
|
3192 | - $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
3189 | + $sql .= "fk_source = ".$sourceid; |
|
3190 | + $sql .= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3191 | + $sql .= " WHERE fk_target = ".$this->id; |
|
3192 | + $sql .= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
3193 | 3193 | } |
3194 | 3194 | else if ($updatetarget) |
3195 | 3195 | { |
3196 | - $sql.= "fk_target = ".$targetid; |
|
3197 | - $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
3198 | - $sql.= " WHERE fk_source = ".$this->id; |
|
3199 | - $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3196 | + $sql .= "fk_target = ".$targetid; |
|
3197 | + $sql .= ", targettype = '".$this->db->escape($targettype)."'"; |
|
3198 | + $sql .= " WHERE fk_source = ".$this->id; |
|
3199 | + $sql .= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3200 | 3200 | } |
3201 | 3201 | |
3202 | 3202 | dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
@@ -3206,7 +3206,7 @@ discard block |
||
3206 | 3206 | } |
3207 | 3207 | else |
3208 | 3208 | { |
3209 | - $this->error=$this->db->lasterror(); |
|
3209 | + $this->error = $this->db->lasterror(); |
|
3210 | 3210 | return -1; |
3211 | 3211 | } |
3212 | 3212 | } |
@@ -3222,42 +3222,42 @@ discard block |
||
3222 | 3222 | * @return int >0 if OK, <0 if KO |
3223 | 3223 | * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
3224 | 3224 | */ |
3225 | - function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
3225 | + function deleteObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $rowid = '') |
|
3226 | 3226 | { |
3227 | - $deletesource=false; |
|
3228 | - $deletetarget=false; |
|
3227 | + $deletesource = false; |
|
3228 | + $deletetarget = false; |
|
3229 | 3229 | |
3230 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
3231 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
3230 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource = true; |
|
3231 | + else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $deletetarget = true; |
|
3232 | 3232 | |
3233 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
3234 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
3235 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
3236 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
3233 | + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); |
|
3234 | + $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); |
|
3235 | + $targetid = (!empty($targetid) ? $targetid : $this->id); |
|
3236 | + $targettype = (!empty($targettype) ? $targettype : $this->element); |
|
3237 | 3237 | |
3238 | 3238 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
3239 | - $sql.= " WHERE"; |
|
3239 | + $sql .= " WHERE"; |
|
3240 | 3240 | if ($rowid > 0) |
3241 | 3241 | { |
3242 | - $sql.=" rowid = ".$rowid; |
|
3242 | + $sql .= " rowid = ".$rowid; |
|
3243 | 3243 | } |
3244 | 3244 | else |
3245 | 3245 | { |
3246 | 3246 | if ($deletesource) |
3247 | 3247 | { |
3248 | - $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3249 | - $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
3248 | + $sql .= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
3249 | + $sql .= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
3250 | 3250 | } |
3251 | 3251 | else if ($deletetarget) |
3252 | 3252 | { |
3253 | - $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
3254 | - $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3253 | + $sql .= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
3254 | + $sql .= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
3255 | 3255 | } |
3256 | 3256 | else |
3257 | 3257 | { |
3258 | - $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
3259 | - $sql.= " OR"; |
|
3260 | - $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
3258 | + $sql .= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
3259 | + $sql .= " OR"; |
|
3260 | + $sql .= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
3261 | 3261 | } |
3262 | 3262 | } |
3263 | 3263 | |
@@ -3268,8 +3268,8 @@ discard block |
||
3268 | 3268 | } |
3269 | 3269 | else |
3270 | 3270 | { |
3271 | - $this->error=$this->db->lasterror(); |
|
3272 | - $this->errors[]=$this->error; |
|
3271 | + $this->error = $this->db->lasterror(); |
|
3272 | + $this->errors[] = $this->error; |
|
3273 | 3273 | return -1; |
3274 | 3274 | } |
3275 | 3275 | } |
@@ -3283,30 +3283,30 @@ discard block |
||
3283 | 3283 | * @param string $trigkey Trigger key to use for trigger |
3284 | 3284 | * @return int <0 if KO, >0 if OK |
3285 | 3285 | */ |
3286 | - function setStatut($status, $elementId=null, $elementType='', $trigkey='') |
|
3286 | + function setStatut($status, $elementId = null, $elementType = '', $trigkey = '') |
|
3287 | 3287 | { |
3288 | - global $user,$langs,$conf; |
|
3288 | + global $user, $langs, $conf; |
|
3289 | 3289 | |
3290 | - $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
3290 | + $savElementId = $elementId; // To be used later to know if we were using the method using the id of this or not. |
|
3291 | 3291 | |
3292 | - $elementId = (!empty($elementId)?$elementId:$this->id); |
|
3293 | - $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
3292 | + $elementId = (!empty($elementId) ? $elementId : $this->id); |
|
3293 | + $elementTable = (!empty($elementType) ? $elementType : $this->table_element); |
|
3294 | 3294 | |
3295 | 3295 | $this->db->begin(); |
3296 | 3296 | |
3297 | - $fieldstatus="fk_statut"; |
|
3298 | - if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
3299 | - if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
3300 | - if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
3301 | - if ($elementTable == 'user') $fieldstatus="statut"; |
|
3302 | - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
3303 | - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
3297 | + $fieldstatus = "fk_statut"; |
|
3298 | + if ($elementTable == 'facture_rec') $fieldstatus = "suspended"; |
|
3299 | + if ($elementTable == 'mailing') $fieldstatus = "statut"; |
|
3300 | + if ($elementTable == 'cronjob') $fieldstatus = "status"; |
|
3301 | + if ($elementTable == 'user') $fieldstatus = "statut"; |
|
3302 | + if ($elementTable == 'expensereport') $fieldstatus = "fk_statut"; |
|
3303 | + if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus = "status"; |
|
3304 | 3304 | |
3305 | 3305 | $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
3306 | - $sql.= " SET ".$fieldstatus." = ".$status; |
|
3306 | + $sql .= " SET ".$fieldstatus." = ".$status; |
|
3307 | 3307 | // If status = 1 = validated, update also fk_user_valid |
3308 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
3309 | - $sql.= " WHERE rowid=".$elementId; |
|
3308 | + if ($status == 1 && $elementTable == 'expensereport') $sql .= ", fk_user_valid = ".$user->id; |
|
3309 | + $sql .= " WHERE rowid=".$elementId; |
|
3310 | 3310 | |
3311 | 3311 | dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
3312 | 3312 | if ($this->db->query($sql)) |
@@ -3316,27 +3316,27 @@ discard block |
||
3316 | 3316 | // Try autoset of trigkey |
3317 | 3317 | if (empty($trigkey)) |
3318 | 3318 | { |
3319 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
3320 | - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
3321 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
3322 | - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
3323 | - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
3324 | - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
3319 | + if ($this->element == 'supplier_proposal' && $status == 2) $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
3320 | + if ($this->element == 'supplier_proposal' && $status == 3) $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
3321 | + if ($this->element == 'supplier_proposal' && $status == 4) $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
3322 | + if ($this->element == 'fichinter' && $status == 3) $trigkey = 'FICHINTER_CLASSIFY_DONE'; |
|
3323 | + if ($this->element == 'fichinter' && $status == 2) $trigkey = 'FICHINTER_CLASSIFY_BILLED'; |
|
3324 | + if ($this->element == 'fichinter' && $status == 1) $trigkey = 'FICHINTER_CLASSIFY_UNBILLED'; |
|
3325 | 3325 | } |
3326 | 3326 | |
3327 | 3327 | if ($trigkey) |
3328 | 3328 | { |
3329 | 3329 | // Appel des triggers |
3330 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
3331 | - $interface=new Interfaces($this->db); |
|
3332 | - $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
3330 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
3331 | + $interface = new Interfaces($this->db); |
|
3332 | + $result = $interface->run_triggers($trigkey, $this, $user, $langs, $conf); |
|
3333 | 3333 | if ($result < 0) { |
3334 | - $error++; $this->errors=$interface->errors; |
|
3334 | + $error++; $this->errors = $interface->errors; |
|
3335 | 3335 | } |
3336 | 3336 | // Fin appel triggers |
3337 | 3337 | } |
3338 | 3338 | |
3339 | - if (! $error) |
|
3339 | + if (!$error) |
|
3340 | 3340 | { |
3341 | 3341 | $this->db->commit(); |
3342 | 3342 | |
@@ -3351,13 +3351,13 @@ discard block |
||
3351 | 3351 | else |
3352 | 3352 | { |
3353 | 3353 | $this->db->rollback(); |
3354 | - dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
3354 | + dol_syslog(get_class($this)."::setStatus ".$this->error, LOG_ERR); |
|
3355 | 3355 | return -1; |
3356 | 3356 | } |
3357 | 3357 | } |
3358 | 3358 | else |
3359 | 3359 | { |
3360 | - $this->error=$this->db->lasterror(); |
|
3360 | + $this->error = $this->db->lasterror(); |
|
3361 | 3361 | $this->db->rollback(); |
3362 | 3362 | return -1; |
3363 | 3363 | } |
@@ -3371,21 +3371,21 @@ discard block |
||
3371 | 3371 | * @param string $ref Record ref |
3372 | 3372 | * @return int <0 if KO, 0 if nothing done, >0 if OK |
3373 | 3373 | */ |
3374 | - function getCanvas($id=0,$ref='') |
|
3374 | + function getCanvas($id = 0, $ref = '') |
|
3375 | 3375 | { |
3376 | 3376 | global $conf; |
3377 | 3377 | |
3378 | 3378 | if (empty($id) && empty($ref)) return 0; |
3379 | - if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
3379 | + if (!empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
3380 | 3380 | |
3381 | 3381 | // Clean parameters |
3382 | 3382 | $ref = trim($ref); |
3383 | 3383 | |
3384 | 3384 | $sql = "SELECT rowid, canvas"; |
3385 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
3386 | - $sql.= " WHERE entity IN (".getEntity($this->element).")"; |
|
3387 | - if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
3388 | - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
3385 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
3386 | + $sql .= " WHERE entity IN (".getEntity($this->element).")"; |
|
3387 | + if (!empty($id)) $sql .= " AND rowid = ".$id; |
|
3388 | + if (!empty($ref)) $sql .= " AND ref = '".$this->db->escape($ref)."'"; |
|
3389 | 3389 | |
3390 | 3390 | $resql = $this->db->query($sql); |
3391 | 3391 | if ($resql) |
@@ -3393,7 +3393,7 @@ discard block |
||
3393 | 3393 | $obj = $this->db->fetch_object($resql); |
3394 | 3394 | if ($obj) |
3395 | 3395 | { |
3396 | - $this->canvas = $obj->canvas; |
|
3396 | + $this->canvas = $obj->canvas; |
|
3397 | 3397 | return 1; |
3398 | 3398 | } |
3399 | 3399 | else return 0; |
@@ -3415,7 +3415,7 @@ discard block |
||
3415 | 3415 | function getSpecialCode($lineid) |
3416 | 3416 | { |
3417 | 3417 | $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
3418 | - $sql.= ' WHERE rowid = '.$lineid; |
|
3418 | + $sql .= ' WHERE rowid = '.$lineid; |
|
3419 | 3419 | $resql = $this->db->query($sql); |
3420 | 3420 | if ($resql) |
3421 | 3421 | { |
@@ -3431,14 +3431,14 @@ discard block |
||
3431 | 3431 | * @param int $id Force id of object |
3432 | 3432 | * @return int <0 if KO, 0 if not used, >0 if already used |
3433 | 3433 | */ |
3434 | - function isObjectUsed($id=0) |
|
3434 | + function isObjectUsed($id = 0) |
|
3435 | 3435 | { |
3436 | 3436 | global $langs; |
3437 | 3437 | |
3438 | - if (empty($id)) $id=$this->id; |
|
3438 | + if (empty($id)) $id = $this->id; |
|
3439 | 3439 | |
3440 | 3440 | // Check parameters |
3441 | - if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
3441 | + if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) |
|
3442 | 3442 | { |
3443 | 3443 | dol_print_error('Called isObjectUsed on a class with property this->childtables not defined'); |
3444 | 3444 | return -1; |
@@ -3446,24 +3446,24 @@ discard block |
||
3446 | 3446 | |
3447 | 3447 | $arraytoscan = $this->childtables; |
3448 | 3448 | // For backward compatibility, we check if array is old format array('table1', 'table2', ...) |
3449 | - $tmparray=array_keys($this->childtables); |
|
3449 | + $tmparray = array_keys($this->childtables); |
|
3450 | 3450 | if (is_numeric($tmparray[0])) |
3451 | 3451 | { |
3452 | 3452 | $arraytoscan = array_flip($this->childtables); |
3453 | 3453 | } |
3454 | 3454 | |
3455 | 3455 | // Test if child exists |
3456 | - $haschild=0; |
|
3457 | - foreach($arraytoscan as $table => $elementname) |
|
3456 | + $haschild = 0; |
|
3457 | + foreach ($arraytoscan as $table => $elementname) |
|
3458 | 3458 | { |
3459 | 3459 | //print $id.'-'.$table.'-'.$elementname.'<br>'; |
3460 | 3460 | // Check if third party can be deleted |
3461 | 3461 | $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
3462 | - $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
3463 | - $resql=$this->db->query($sql); |
|
3462 | + $sql .= " WHERE ".$this->fk_element." = ".$id; |
|
3463 | + $resql = $this->db->query($sql); |
|
3464 | 3464 | if ($resql) |
3465 | 3465 | { |
3466 | - $obj=$this->db->fetch_object($resql); |
|
3466 | + $obj = $this->db->fetch_object($resql); |
|
3467 | 3467 | if ($obj->nb > 0) |
3468 | 3468 | { |
3469 | 3469 | $langs->load("errors"); |
@@ -3471,24 +3471,24 @@ discard block |
||
3471 | 3471 | $haschild += $obj->nb; |
3472 | 3472 | if (is_numeric($elementname)) // old usage |
3473 | 3473 | { |
3474 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); |
|
3474 | + $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); |
|
3475 | 3475 | } |
3476 | 3476 | else // new usage: $elementname=Translation key |
3477 | 3477 | { |
3478 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
|
3478 | + $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
|
3479 | 3479 | } |
3480 | - break; // We found at least one, we stop here |
|
3480 | + break; // We found at least one, we stop here |
|
3481 | 3481 | } |
3482 | 3482 | } |
3483 | 3483 | else |
3484 | 3484 | { |
3485 | - $this->errors[]=$this->db->lasterror(); |
|
3485 | + $this->errors[] = $this->db->lasterror(); |
|
3486 | 3486 | return -1; |
3487 | 3487 | } |
3488 | 3488 | } |
3489 | 3489 | if ($haschild > 0) |
3490 | 3490 | { |
3491 | - $this->errors[]="ErrorRecordHasChildren"; |
|
3491 | + $this->errors[] = "ErrorRecordHasChildren"; |
|
3492 | 3492 | return $haschild; |
3493 | 3493 | } |
3494 | 3494 | else return 0; |
@@ -3500,18 +3500,18 @@ discard block |
||
3500 | 3500 | * @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 |
3501 | 3501 | * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
3502 | 3502 | */ |
3503 | - function hasProductsOrServices($predefined=-1) |
|
3503 | + function hasProductsOrServices($predefined = -1) |
|
3504 | 3504 | { |
3505 | - $nb=0; |
|
3505 | + $nb = 0; |
|
3506 | 3506 | |
3507 | - foreach($this->lines as $key => $val) |
|
3507 | + foreach ($this->lines as $key => $val) |
|
3508 | 3508 | { |
3509 | - $qualified=0; |
|
3510 | - if ($predefined == -1) $qualified=1; |
|
3511 | - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
3512 | - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
3513 | - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
3514 | - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
3509 | + $qualified = 0; |
|
3510 | + if ($predefined == -1) $qualified = 1; |
|
3511 | + if ($predefined == 1 && $val->fk_product > 0) $qualified = 1; |
|
3512 | + if ($predefined == 0 && $val->fk_product <= 0) $qualified = 1; |
|
3513 | + if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) $qualified = 1; |
|
3514 | + if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) $qualified = 1; |
|
3515 | 3515 | if ($qualified) $nb++; |
3516 | 3516 | } |
3517 | 3517 | dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
@@ -3525,24 +3525,24 @@ discard block |
||
3525 | 3525 | */ |
3526 | 3526 | function getTotalDiscount() |
3527 | 3527 | { |
3528 | - $total_discount=0.00; |
|
3528 | + $total_discount = 0.00; |
|
3529 | 3529 | |
3530 | 3530 | $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
3531 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
3532 | - $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
3531 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
3532 | + $sql .= " WHERE ".$this->fk_element." = ".$this->id; |
|
3533 | 3533 | |
3534 | 3534 | dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
3535 | 3535 | $resql = $this->db->query($sql); |
3536 | 3536 | if ($resql) |
3537 | 3537 | { |
3538 | - $num=$this->db->num_rows($resql); |
|
3539 | - $i=0; |
|
3538 | + $num = $this->db->num_rows($resql); |
|
3539 | + $i = 0; |
|
3540 | 3540 | while ($i < $num) |
3541 | 3541 | { |
3542 | 3542 | $obj = $this->db->fetch_object($resql); |
3543 | 3543 | |
3544 | 3544 | $pu_ht = $obj->pu_ht; |
3545 | - $qty= $obj->qty; |
|
3545 | + $qty = $obj->qty; |
|
3546 | 3546 | $total_ht = $obj->total_ht; |
3547 | 3547 | |
3548 | 3548 | $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
@@ -3576,17 +3576,17 @@ discard block |
||
3576 | 3576 | { |
3577 | 3577 | if (isset($line->qty_asked)) |
3578 | 3578 | { |
3579 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
3580 | - $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
3579 | + if (empty($totalOrdered)) $totalOrdered = 0; // Avoid warning because $totalOrdered is '' |
|
3580 | + $totalOrdered += $line->qty_asked; // defined for shipment only |
|
3581 | 3581 | } |
3582 | 3582 | if (isset($line->qty_shipped)) |
3583 | 3583 | { |
3584 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
3585 | - $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
3586 | - }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
3584 | + if (empty($totalToShip)) $totalToShip = 0; // Avoid warning because $totalToShip is '' |
|
3585 | + $totalToShip += $line->qty_shipped; // defined for shipment only |
|
3586 | + } else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
3587 | 3587 | { |
3588 | - if (empty($totalToShip)) $totalToShip=0; |
|
3589 | - $totalToShip+=$line->qty; // defined for reception only |
|
3588 | + if (empty($totalToShip)) $totalToShip = 0; |
|
3589 | + $totalToShip += $line->qty; // defined for reception only |
|
3590 | 3590 | } |
3591 | 3591 | |
3592 | 3592 | // Define qty, weight, volume, weight_units, volume_units |
@@ -3599,27 +3599,27 @@ discard block |
||
3599 | 3599 | } |
3600 | 3600 | |
3601 | 3601 | $weight = $line->weight ? $line->weight : 0; |
3602 | - ($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0; |
|
3602 | + ($weight == 0 && !empty($line->product->weight)) ? $weight = $line->product->weight : 0; |
|
3603 | 3603 | $volume = $line->volume ? $line->volume : 0; |
3604 | - ($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0; |
|
3604 | + ($volume == 0 && !empty($line->product->volume)) ? $volume = $line->product->volume : 0; |
|
3605 | 3605 | |
3606 | - $weight_units=$line->weight_units; |
|
3607 | - ($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0; |
|
3608 | - $volume_units=$line->volume_units; |
|
3609 | - ($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0; |
|
3606 | + $weight_units = $line->weight_units; |
|
3607 | + ($weight_units == 0 && !empty($line->product->weight_units)) ? $weight_units = $line->product->weight_units : 0; |
|
3608 | + $volume_units = $line->volume_units; |
|
3609 | + ($volume_units == 0 && !empty($line->product->volume_units)) ? $volume_units = $line->product->volume_units : 0; |
|
3610 | 3610 | |
3611 | - $weightUnit=0; |
|
3612 | - $volumeUnit=0; |
|
3613 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
3614 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
3611 | + $weightUnit = 0; |
|
3612 | + $volumeUnit = 0; |
|
3613 | + if (!empty($weight_units)) $weightUnit = $weight_units; |
|
3614 | + if (!empty($volume_units)) $volumeUnit = $volume_units; |
|
3615 | 3615 | |
3616 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
3617 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
3616 | + if (empty($totalWeight)) $totalWeight = 0; // Avoid warning because $totalWeight is '' |
|
3617 | + if (empty($totalVolume)) $totalVolume = 0; // Avoid warning because $totalVolume is '' |
|
3618 | 3618 | |
3619 | 3619 | //var_dump($line->volume_units); |
3620 | 3620 | if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
3621 | 3621 | { |
3622 | - $trueWeightUnit=pow(10, $weightUnit); |
|
3622 | + $trueWeightUnit = pow(10, $weightUnit); |
|
3623 | 3623 | $totalWeight += $weight * $qty * $trueWeightUnit; |
3624 | 3624 | } |
3625 | 3625 | else { |
@@ -3633,18 +3633,18 @@ discard block |
||
3633 | 3633 | $totalWeight += $weight * $qty * $trueWeightUnit; |
3634 | 3634 | } |
3635 | 3635 | else |
3636 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
3636 | + $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
3637 | 3637 | } |
3638 | 3638 | if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
3639 | 3639 | { |
3640 | 3640 | //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
3641 | - $trueVolumeUnit=pow(10, $volumeUnit); |
|
3641 | + $trueVolumeUnit = pow(10, $volumeUnit); |
|
3642 | 3642 | //print $line->volume; |
3643 | 3643 | $totalVolume += $volume * $qty * $trueVolumeUnit; |
3644 | 3644 | } |
3645 | 3645 | else |
3646 | 3646 | { |
3647 | - $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
3647 | + $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
3648 | 3648 | } |
3649 | 3649 | } |
3650 | 3650 | |
@@ -3661,17 +3661,17 @@ discard block |
||
3661 | 3661 | { |
3662 | 3662 | $this->db->begin(); |
3663 | 3663 | |
3664 | - $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
3664 | + $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
3665 | 3665 | |
3666 | 3666 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
3667 | - $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
3668 | - $sql.= " WHERE rowid = ".$this->id; |
|
3667 | + $sql .= " SET extraparams = ".(!empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
3668 | + $sql .= " WHERE rowid = ".$this->id; |
|
3669 | 3669 | |
3670 | 3670 | dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
3671 | 3671 | $resql = $this->db->query($sql); |
3672 | - if (! $resql) |
|
3672 | + if (!$resql) |
|
3673 | 3673 | { |
3674 | - $this->error=$this->db->lasterror(); |
|
3674 | + $this->error = $this->db->lasterror(); |
|
3675 | 3675 | $this->db->rollback(); |
3676 | 3676 | return -1; |
3677 | 3677 | } |
@@ -3706,7 +3706,7 @@ discard block |
||
3706 | 3706 | } |
3707 | 3707 | } |
3708 | 3708 | |
3709 | - $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
3709 | + $out .= (($res->code && $this->location_incoterms) ? ' - ' : '').$this->location_incoterms; |
|
3710 | 3710 | |
3711 | 3711 | return $out; |
3712 | 3712 | } |
@@ -3752,11 +3752,11 @@ discard block |
||
3752 | 3752 | if ($this->id && $this->table_element) |
3753 | 3753 | { |
3754 | 3754 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
3755 | - $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
3756 | - $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
3757 | - $sql.= " WHERE rowid = " . $this->id; |
|
3755 | + $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
3756 | + $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
3757 | + $sql .= " WHERE rowid = ".$this->id; |
|
3758 | 3758 | dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
3759 | - $resql=$this->db->query($sql); |
|
3759 | + $resql = $this->db->query($sql); |
|
3760 | 3760 | if ($resql) |
3761 | 3761 | { |
3762 | 3762 | $this->fk_incoterms = $id_incoterm; |
@@ -3797,24 +3797,24 @@ discard block |
||
3797 | 3797 | */ |
3798 | 3798 | function formAddObjectLine($dateSelector, $seller, $buyer) |
3799 | 3799 | { |
3800 | - global $conf,$user,$langs,$object,$hookmanager; |
|
3801 | - global $form,$bcnd,$var; |
|
3800 | + global $conf, $user, $langs, $object, $hookmanager; |
|
3801 | + global $form, $bcnd, $var; |
|
3802 | 3802 | |
3803 | 3803 | // Line extrafield |
3804 | 3804 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
3805 | 3805 | $extrafieldsline = new ExtraFields($this->db); |
3806 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
3806 | + $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
3807 | 3807 | |
3808 | 3808 | // Output template part (modules that overwrite templates must declare this into descriptor) |
3809 | 3809 | // Use global variables + $dateSelector + $seller and $buyer |
3810 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
3811 | - foreach($dirtpls as $reldir) |
|
3810 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
3811 | + foreach ($dirtpls as $reldir) |
|
3812 | 3812 | { |
3813 | 3813 | $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
3814 | 3814 | if (empty($conf->file->strict_mode)) { |
3815 | - $res=@include $tpl; |
|
3815 | + $res = @include $tpl; |
|
3816 | 3816 | } else { |
3817 | - $res=include $tpl; // for debug |
|
3817 | + $res = include $tpl; // for debug |
|
3818 | 3818 | } |
3819 | 3819 | if ($res) break; |
3820 | 3820 | } |
@@ -3838,24 +3838,24 @@ discard block |
||
3838 | 3838 | * @param int $dateSelector 1=Show also date range input fields |
3839 | 3839 | * @return void |
3840 | 3840 | */ |
3841 | - function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
3841 | + function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0) |
|
3842 | 3842 | { |
3843 | 3843 | global $conf, $hookmanager, $langs, $user; |
3844 | 3844 | // TODO We should not use global var for this ! |
3845 | 3845 | global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
3846 | 3846 | |
3847 | 3847 | // Define usemargins |
3848 | - $usemargins=0; |
|
3849 | - if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1; |
|
3848 | + $usemargins = 0; |
|
3849 | + if (!empty($conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande'))) $usemargins = 1; |
|
3850 | 3850 | |
3851 | 3851 | $num = count($this->lines); |
3852 | 3852 | |
3853 | 3853 | // Line extrafield |
3854 | 3854 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
3855 | 3855 | $extrafieldsline = new ExtraFields($this->db); |
3856 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
3856 | + $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
3857 | 3857 | |
3858 | - $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
3858 | + $parameters = array('num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
3859 | 3859 | $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
3860 | 3860 | if (empty($reshook)) |
3861 | 3861 | { |
@@ -3865,7 +3865,7 @@ discard block |
||
3865 | 3865 | print '<tr class="liste_titre nodrag nodrop">'; |
3866 | 3866 | |
3867 | 3867 | // Adds a line numbering column |
3868 | - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
3868 | + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
3869 | 3869 | |
3870 | 3870 | // Description |
3871 | 3871 | print '<td class="linecoldescription">'.$langs->trans('Description').'</td>'; |
@@ -3889,7 +3889,7 @@ discard block |
||
3889 | 3889 | // Qty |
3890 | 3890 | print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>'; |
3891 | 3891 | |
3892 | - if($conf->global->PRODUCT_USE_UNITS) |
|
3892 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
3893 | 3893 | { |
3894 | 3894 | print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>'; |
3895 | 3895 | } |
@@ -3898,10 +3898,10 @@ discard block |
||
3898 | 3898 | print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>'; |
3899 | 3899 | |
3900 | 3900 | if ($this->situation_cycle_ref) { |
3901 | - print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>'; |
|
3901 | + print '<td class="linecolcycleref" align="right">'.$langs->trans('Progress').'</td>'; |
|
3902 | 3902 | } |
3903 | 3903 | |
3904 | - if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) |
|
3904 | + if ($usemargins && !empty($conf->margin->enabled) && empty($user->societe_id)) |
|
3905 | 3905 | { |
3906 | 3906 | if (!empty($user->rights->margins->creer)) |
3907 | 3907 | { |
@@ -3911,9 +3911,9 @@ discard block |
||
3911 | 3911 | print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
3912 | 3912 | } |
3913 | 3913 | |
3914 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
3914 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
3915 | 3915 | print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>'; |
3916 | - if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
3916 | + if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
3917 | 3917 | print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
3918 | 3918 | } |
3919 | 3919 | |
@@ -3925,13 +3925,13 @@ discard block |
||
3925 | 3925 | |
3926 | 3926 | if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
3927 | 3927 | |
3928 | - print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
3928 | + print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
3929 | 3929 | |
3930 | 3930 | print '<td class="linecoldelete" width="10"></td>'; |
3931 | 3931 | |
3932 | 3932 | print '<td class="linecolmove" width="10"></td>'; |
3933 | 3933 | |
3934 | - if($action == 'selectlines') |
|
3934 | + if ($action == 'selectlines') |
|
3935 | 3935 | { |
3936 | 3936 | print '<td class="linecolcheckall" align="center">'; |
3937 | 3937 | print '<input type="checkbox" class="linecheckboxtoggle" />'; |
@@ -3944,7 +3944,7 @@ discard block |
||
3944 | 3944 | } |
3945 | 3945 | |
3946 | 3946 | $var = true; |
3947 | - $i = 0; |
|
3947 | + $i = 0; |
|
3948 | 3948 | |
3949 | 3949 | print "<tbody>\n"; |
3950 | 3950 | foreach ($this->lines as $line) |
@@ -3957,18 +3957,18 @@ discard block |
||
3957 | 3957 | { |
3958 | 3958 | if (empty($line->fk_parent_line)) |
3959 | 3959 | { |
3960 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
3961 | - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3960 | + $parameters = array('line'=>$line, 'var'=>$var, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
3961 | + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3962 | 3962 | } |
3963 | 3963 | else |
3964 | 3964 | { |
3965 | - $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); |
|
3966 | - $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3965 | + $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); |
|
3966 | + $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
3967 | 3967 | } |
3968 | 3968 | } |
3969 | 3969 | if (empty($reshook)) |
3970 | 3970 | { |
3971 | - $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
3971 | + $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline); |
|
3972 | 3972 | } |
3973 | 3973 | |
3974 | 3974 | $i++; |
@@ -3992,23 +3992,23 @@ discard block |
||
3992 | 3992 | * @param int $extrafieldsline Object of extrafield line attribute |
3993 | 3993 | * @return void |
3994 | 3994 | */ |
3995 | - function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
3995 | + function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0) |
|
3996 | 3996 | { |
3997 | - global $conf,$langs,$user,$object,$hookmanager; |
|
3998 | - global $form,$bc,$bcdd; |
|
3999 | - global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
3997 | + global $conf, $langs, $user, $object, $hookmanager; |
|
3998 | + global $form, $bc, $bcdd; |
|
3999 | + global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
4000 | 4000 | |
4001 | 4001 | $object_rights = $this->getRights(); |
4002 | 4002 | |
4003 | - $element=$this->element; |
|
4003 | + $element = $this->element; |
|
4004 | 4004 | |
4005 | - $text=''; $description=''; $type=0; |
|
4005 | + $text = ''; $description = ''; $type = 0; |
|
4006 | 4006 | |
4007 | 4007 | // Show product and description |
4008 | - $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
4008 | + $type = (!empty($line->product_type) ? $line->product_type : $line->fk_product_type); |
|
4009 | 4009 | // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
4010 | - if (! empty($line->date_start)) $type=1; // deprecated |
|
4011 | - if (! empty($line->date_end)) $type=1; // deprecated |
|
4010 | + if (!empty($line->date_start)) $type = 1; // deprecated |
|
4011 | + if (!empty($line->date_end)) $type = 1; // deprecated |
|
4012 | 4012 | |
4013 | 4013 | // Ligne en mode visu |
4014 | 4014 | if ($action != 'editline' || $selected != $line->id) |
@@ -4021,14 +4021,14 @@ discard block |
||
4021 | 4021 | |
4022 | 4022 | $product_static->ref = $line->ref; //can change ref in hook |
4023 | 4023 | $product_static->label = $line->label; //can change label in hook |
4024 | - $text=$product_static->getNomUrl(1); |
|
4024 | + $text = $product_static->getNomUrl(1); |
|
4025 | 4025 | |
4026 | 4026 | // Define output language and label |
4027 | - if (! empty($conf->global->MAIN_MULTILANGS)) |
|
4027 | + if (!empty($conf->global->MAIN_MULTILANGS)) |
|
4028 | 4028 | { |
4029 | - if (! is_object($this->thirdparty)) |
|
4029 | + if (!is_object($this->thirdparty)) |
|
4030 | 4030 | { |
4031 | - dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); |
|
4031 | + dol_print_error('', 'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); |
|
4032 | 4032 | return; |
4033 | 4033 | } |
4034 | 4034 | |
@@ -4036,38 +4036,38 @@ discard block |
||
4036 | 4036 | $prod->fetch($line->fk_product); |
4037 | 4037 | |
4038 | 4038 | $outputlangs = $langs; |
4039 | - $newlang=''; |
|
4040 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
4041 | - if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer |
|
4042 | - if (! empty($newlang)) |
|
4039 | + $newlang = ''; |
|
4040 | + if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); |
|
4041 | + if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang = $this->thirdparty->default_lang; // For language to language of customer |
|
4042 | + if (!empty($newlang)) |
|
4043 | 4043 | { |
4044 | - $outputlangs = new Translate("",$conf); |
|
4044 | + $outputlangs = new Translate("", $conf); |
|
4045 | 4045 | $outputlangs->setDefaultLang($newlang); |
4046 | 4046 | } |
4047 | 4047 | |
4048 | - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
4048 | + $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
4049 | 4049 | } |
4050 | 4050 | else |
4051 | 4051 | { |
4052 | 4052 | $label = $line->product_label; |
4053 | 4053 | } |
4054 | 4054 | |
4055 | - $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
4056 | - $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. |
|
4055 | + $text .= ' - '.(!empty($line->label) ? $line->label : $label); |
|
4056 | + $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. |
|
4057 | 4057 | } |
4058 | 4058 | |
4059 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
4059 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
|
4060 | 4060 | |
4061 | 4061 | // Output template part (modules that overwrite templates must declare this into descriptor) |
4062 | 4062 | // Use global variables + $dateSelector + $seller and $buyer |
4063 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
4064 | - foreach($dirtpls as $reldir) |
|
4063 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
4064 | + foreach ($dirtpls as $reldir) |
|
4065 | 4065 | { |
4066 | 4066 | $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
4067 | 4067 | if (empty($conf->file->strict_mode)) { |
4068 | - $res=@include $tpl; |
|
4068 | + $res = @include $tpl; |
|
4069 | 4069 | } else { |
4070 | - $res=include $tpl; // for debug |
|
4070 | + $res = include $tpl; // for debug |
|
4071 | 4071 | } |
4072 | 4072 | if ($res) break; |
4073 | 4073 | } |
@@ -4076,21 +4076,21 @@ discard block |
||
4076 | 4076 | // Ligne en mode update |
4077 | 4077 | if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
4078 | 4078 | { |
4079 | - $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
4080 | - $placeholder=' placeholder="'.$langs->trans("Label").'"'; |
|
4079 | + $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
4080 | + $placeholder = ' placeholder="'.$langs->trans("Label").'"'; |
|
4081 | 4081 | |
4082 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
4082 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
|
4083 | 4083 | |
4084 | 4084 | // Output template part (modules that overwrite templates must declare this into descriptor) |
4085 | 4085 | // Use global variables + $dateSelector + $seller and $buyer |
4086 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
4087 | - foreach($dirtpls as $reldir) |
|
4086 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
4087 | + foreach ($dirtpls as $reldir) |
|
4088 | 4088 | { |
4089 | 4089 | $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
4090 | 4090 | if (empty($conf->file->strict_mode)) { |
4091 | - $res=@include $tpl; |
|
4091 | + $res = @include $tpl; |
|
4092 | 4092 | } else { |
4093 | - $res=include $tpl; // for debug |
|
4093 | + $res = include $tpl; // for debug |
|
4094 | 4094 | } |
4095 | 4095 | if ($res) break; |
4096 | 4096 | } |
@@ -4110,7 +4110,7 @@ discard block |
||
4110 | 4110 | * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
4111 | 4111 | * @return void |
4112 | 4112 | */ |
4113 | - function printOriginLinesList($restrictlist='') |
|
4113 | + function printOriginLinesList($restrictlist = '') |
|
4114 | 4114 | { |
4115 | 4115 | global $langs, $hookmanager, $conf; |
4116 | 4116 | |
@@ -4121,26 +4121,26 @@ discard block |
||
4121 | 4121 | print '<td align="right">'.$langs->trans('PriceUHT').'</td>'; |
4122 | 4122 | if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>'; |
4123 | 4123 | print '<td align="right">'.$langs->trans('Qty').'</td>'; |
4124 | - if($conf->global->PRODUCT_USE_UNITS) |
|
4124 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
4125 | 4125 | { |
4126 | 4126 | print '<td align="left">'.$langs->trans('Unit').'</td>'; |
4127 | 4127 | } |
4128 | 4128 | print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>'; |
4129 | 4129 | |
4130 | 4130 | $var = true; |
4131 | - $i = 0; |
|
4131 | + $i = 0; |
|
4132 | 4132 | |
4133 | - if (! empty($this->lines)) |
|
4133 | + if (!empty($this->lines)) |
|
4134 | 4134 | { |
4135 | 4135 | foreach ($this->lines as $line) |
4136 | 4136 | { |
4137 | - if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
4137 | + if (is_object($hookmanager) && (($line->product_type == 9 && !empty($line->special_code)) || !empty($line->fk_parent_line))) |
|
4138 | 4138 | { |
4139 | 4139 | if (empty($line->fk_parent_line)) |
4140 | 4140 | { |
4141 | - $parameters=array('line'=>$line,'var'=>$var,'i'=>$i); |
|
4142 | - $action=''; |
|
4143 | - $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
4141 | + $parameters = array('line'=>$line, 'var'=>$var, 'i'=>$i); |
|
4142 | + $action = ''; |
|
4143 | + $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
4144 | 4144 | } |
4145 | 4145 | } |
4146 | 4146 | else |
@@ -4164,103 +4164,103 @@ discard block |
||
4164 | 4164 | * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
4165 | 4165 | * @return void |
4166 | 4166 | */ |
4167 | - function printOriginLine($line, $var, $restrictlist='') |
|
4167 | + function printOriginLine($line, $var, $restrictlist = '') |
|
4168 | 4168 | { |
4169 | 4169 | global $langs, $conf; |
4170 | 4170 | |
4171 | 4171 | //var_dump($line); |
4172 | 4172 | if (!empty($line->date_start)) |
4173 | 4173 | { |
4174 | - $date_start=$line->date_start; |
|
4174 | + $date_start = $line->date_start; |
|
4175 | 4175 | } |
4176 | 4176 | else |
4177 | 4177 | { |
4178 | - $date_start=$line->date_debut_prevue; |
|
4179 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
4178 | + $date_start = $line->date_debut_prevue; |
|
4179 | + if ($line->date_debut_reel) $date_start = $line->date_debut_reel; |
|
4180 | 4180 | } |
4181 | 4181 | if (!empty($line->date_end)) |
4182 | 4182 | { |
4183 | - $date_end=$line->date_end; |
|
4183 | + $date_end = $line->date_end; |
|
4184 | 4184 | } |
4185 | 4185 | else |
4186 | 4186 | { |
4187 | - $date_end=$line->date_fin_prevue; |
|
4188 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
4187 | + $date_end = $line->date_fin_prevue; |
|
4188 | + if ($line->date_fin_reel) $date_end = $line->date_fin_reel; |
|
4189 | 4189 | } |
4190 | 4190 | |
4191 | 4191 | $this->tpl['label'] = ''; |
4192 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow'); |
|
4192 | + if (!empty($line->fk_parent_line)) $this->tpl['label'] .= img_picto('', 'rightarrow'); |
|
4193 | 4193 | |
4194 | 4194 | if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
4195 | 4195 | { |
4196 | - $discount=new DiscountAbsolute($this->db); |
|
4196 | + $discount = new DiscountAbsolute($this->db); |
|
4197 | 4197 | $discount->fk_soc = $this->socid; |
4198 | - $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
4198 | + $this->tpl['label'] .= $discount->getNomUrl(0, 'discount'); |
|
4199 | 4199 | } |
4200 | - else if (! empty($line->fk_product)) |
|
4200 | + else if (!empty($line->fk_product)) |
|
4201 | 4201 | { |
4202 | 4202 | $productstatic = new Product($this->db); |
4203 | 4203 | $productstatic->id = $line->fk_product; |
4204 | 4204 | $productstatic->ref = $line->ref; |
4205 | 4205 | $productstatic->type = $line->fk_product_type; |
4206 | - if(empty($productstatic->ref)){ |
|
4206 | + if (empty($productstatic->ref)) { |
|
4207 | 4207 | $line->fetch_product(); |
4208 | 4208 | $productstatic = $line->product; |
4209 | 4209 | } |
4210 | 4210 | |
4211 | - $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
4212 | - $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
4211 | + $this->tpl['label'] .= $productstatic->getNomUrl(1); |
|
4212 | + $this->tpl['label'] .= ' - '.(!empty($line->label) ? $line->label : $line->product_label); |
|
4213 | 4213 | // Dates |
4214 | 4214 | if ($line->product_type == 1 && ($date_start || $date_end)) |
4215 | 4215 | { |
4216 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
4216 | + $this->tpl['label'] .= get_date_range($date_start, $date_end); |
|
4217 | 4217 | } |
4218 | 4218 | } |
4219 | 4219 | else |
4220 | 4220 | { |
4221 | - $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'))); |
|
4221 | + $this->tpl['label'] .= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''), 'service') : img_object($langs->trans(''), 'product'))); |
|
4222 | 4222 | if (!empty($line->desc)) { |
4223 | - $this->tpl['label'].=$line->desc; |
|
4224 | - }else { |
|
4225 | - $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
4223 | + $this->tpl['label'] .= $line->desc; |
|
4224 | + } else { |
|
4225 | + $this->tpl['label'] .= ($line->label ? ' '.$line->label : ''); |
|
4226 | 4226 | } |
4227 | 4227 | |
4228 | 4228 | // Dates |
4229 | 4229 | if ($line->product_type == 1 && ($date_start || $date_end)) |
4230 | 4230 | { |
4231 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
4231 | + $this->tpl['label'] .= get_date_range($date_start, $date_end); |
|
4232 | 4232 | } |
4233 | 4233 | } |
4234 | 4234 | |
4235 | - if (! empty($line->desc)) |
|
4235 | + if (!empty($line->desc)) |
|
4236 | 4236 | { |
4237 | 4237 | if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
4238 | 4238 | { |
4239 | - $discount=new DiscountAbsolute($this->db); |
|
4239 | + $discount = new DiscountAbsolute($this->db); |
|
4240 | 4240 | $discount->fetch($line->fk_remise_except); |
4241 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); |
|
4241 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0)); |
|
4242 | 4242 | } |
4243 | 4243 | elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
4244 | 4244 | { |
4245 | - $discount=new DiscountAbsolute($this->db); |
|
4245 | + $discount = new DiscountAbsolute($this->db); |
|
4246 | 4246 | $discount->fetch($line->fk_remise_except); |
4247 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
|
4247 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0)); |
|
4248 | 4248 | } |
4249 | 4249 | elseif ($line->desc == '(EXCESS RECEIVED)') |
4250 | 4250 | { |
4251 | - $discount=new DiscountAbsolute($this->db); |
|
4251 | + $discount = new DiscountAbsolute($this->db); |
|
4252 | 4252 | $discount->fetch($line->fk_remise_except); |
4253 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
|
4253 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0)); |
|
4254 | 4254 | } |
4255 | 4255 | elseif ($line->desc == '(EXCESS PAID)') |
4256 | 4256 | { |
4257 | - $discount=new DiscountAbsolute($this->db); |
|
4257 | + $discount = new DiscountAbsolute($this->db); |
|
4258 | 4258 | $discount->fetch($line->fk_remise_except); |
4259 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0)); |
|
4259 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0)); |
|
4260 | 4260 | } |
4261 | 4261 | else |
4262 | 4262 | { |
4263 | - $this->tpl['description'] = dol_trunc($line->desc,60); |
|
4263 | + $this->tpl['description'] = dol_trunc($line->desc, 60); |
|
4264 | 4264 | } |
4265 | 4265 | } |
4266 | 4266 | else |
@@ -4271,7 +4271,7 @@ discard block |
||
4271 | 4271 | // VAT Rate |
4272 | 4272 | $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
4273 | 4273 | $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
4274 | - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')'; |
|
4274 | + if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'] .= ' ('.$line->vat_src_code.')'; |
|
4275 | 4275 | |
4276 | 4276 | $this->tpl['price'] = price($line->subprice); |
4277 | 4277 | $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
@@ -4280,19 +4280,19 @@ discard block |
||
4280 | 4280 | $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
4281 | 4281 | |
4282 | 4282 | // Is the line strike or not |
4283 | - $this->tpl['strike']=0; |
|
4284 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
4283 | + $this->tpl['strike'] = 0; |
|
4284 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike'] = 1; |
|
4285 | 4285 | |
4286 | 4286 | // Output template part (modules that overwrite templates must declare this into descriptor) |
4287 | 4287 | // Use global variables + $dateSelector + $seller and $buyer |
4288 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
4289 | - foreach($dirtpls as $reldir) |
|
4288 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
4289 | + foreach ($dirtpls as $reldir) |
|
4290 | 4290 | { |
4291 | 4291 | $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
4292 | 4292 | if (empty($conf->file->strict_mode)) { |
4293 | - $res=@include $tpl; |
|
4293 | + $res = @include $tpl; |
|
4294 | 4294 | } else { |
4295 | - $res=include $tpl; // for debug |
|
4295 | + $res = include $tpl; // for debug |
|
4296 | 4296 | } |
4297 | 4297 | if ($res) break; |
4298 | 4298 | } |
@@ -4310,26 +4310,26 @@ discard block |
||
4310 | 4310 | * @param int $mandatory Mandatory or not |
4311 | 4311 | * @return int <=0 if KO, >0 if OK |
4312 | 4312 | */ |
4313 | - function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
4313 | + function add_element_resource($resource_id, $resource_type, $busy = 0, $mandatory = 0) |
|
4314 | 4314 | { |
4315 | 4315 | // phpcs:enable |
4316 | 4316 | $this->db->begin(); |
4317 | 4317 | |
4318 | 4318 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; |
4319 | - $sql.= "resource_id"; |
|
4320 | - $sql.= ", resource_type"; |
|
4321 | - $sql.= ", element_id"; |
|
4322 | - $sql.= ", element_type"; |
|
4323 | - $sql.= ", busy"; |
|
4324 | - $sql.= ", mandatory"; |
|
4325 | - $sql.= ") VALUES ("; |
|
4326 | - $sql.= $resource_id; |
|
4327 | - $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
4328 | - $sql.= ", '".$this->db->escape($this->id)."'"; |
|
4329 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
4330 | - $sql.= ", '".$this->db->escape($busy)."'"; |
|
4331 | - $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
4332 | - $sql.= ")"; |
|
4319 | + $sql .= "resource_id"; |
|
4320 | + $sql .= ", resource_type"; |
|
4321 | + $sql .= ", element_id"; |
|
4322 | + $sql .= ", element_type"; |
|
4323 | + $sql .= ", busy"; |
|
4324 | + $sql .= ", mandatory"; |
|
4325 | + $sql .= ") VALUES ("; |
|
4326 | + $sql .= $resource_id; |
|
4327 | + $sql .= ", '".$this->db->escape($resource_type)."'"; |
|
4328 | + $sql .= ", '".$this->db->escape($this->id)."'"; |
|
4329 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
4330 | + $sql .= ", '".$this->db->escape($busy)."'"; |
|
4331 | + $sql .= ", '".$this->db->escape($mandatory)."'"; |
|
4332 | + $sql .= ")"; |
|
4333 | 4333 | |
4334 | 4334 | dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
4335 | 4335 | if ($this->db->query($sql)) |
@@ -4339,7 +4339,7 @@ discard block |
||
4339 | 4339 | } |
4340 | 4340 | else |
4341 | 4341 | { |
4342 | - $this->error=$this->db->lasterror(); |
|
4342 | + $this->error = $this->db->lasterror(); |
|
4343 | 4343 | $this->db->rollback(); |
4344 | 4344 | return 0; |
4345 | 4345 | } |
@@ -4354,7 +4354,7 @@ discard block |
||
4354 | 4354 | * @param int $notrigger Disable all triggers |
4355 | 4355 | * @return int >0 if OK, <0 if KO |
4356 | 4356 | */ |
4357 | - function delete_resource($rowid, $element, $notrigger=0) |
|
4357 | + function delete_resource($rowid, $element, $notrigger = 0) |
|
4358 | 4358 | { |
4359 | 4359 | // phpcs:enable |
4360 | 4360 | global $user; |
@@ -4362,22 +4362,22 @@ discard block |
||
4362 | 4362 | $this->db->begin(); |
4363 | 4363 | |
4364 | 4364 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
4365 | - $sql.= " WHERE rowid=".$rowid; |
|
4365 | + $sql .= " WHERE rowid=".$rowid; |
|
4366 | 4366 | |
4367 | 4367 | dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
4368 | 4368 | |
4369 | - $resql=$this->db->query($sql); |
|
4370 | - if (! $resql) |
|
4369 | + $resql = $this->db->query($sql); |
|
4370 | + if (!$resql) |
|
4371 | 4371 | { |
4372 | - $this->error=$this->db->lasterror(); |
|
4372 | + $this->error = $this->db->lasterror(); |
|
4373 | 4373 | $this->db->rollback(); |
4374 | 4374 | return -1; |
4375 | 4375 | } |
4376 | 4376 | else |
4377 | 4377 | { |
4378 | - if (! $notrigger) |
|
4378 | + if (!$notrigger) |
|
4379 | 4379 | { |
4380 | - $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
4380 | + $result = $this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
4381 | 4381 | if ($result < 0) { $this->db->rollback(); return -1; } |
4382 | 4382 | } |
4383 | 4383 | $this->db->commit(); |
@@ -4396,8 +4396,8 @@ discard block |
||
4396 | 4396 | // Force a copy of this->lines, otherwise it will point to same object. |
4397 | 4397 | if (isset($this->lines) && is_array($this->lines)) |
4398 | 4398 | { |
4399 | - $nboflines=count($this->lines); |
|
4400 | - for($i=0; $i < $nboflines; $i++) |
|
4399 | + $nboflines = count($this->lines); |
|
4400 | + for ($i = 0; $i < $nboflines; $i++) |
|
4401 | 4401 | { |
4402 | 4402 | $this->lines[$i] = clone $this->lines[$i]; |
4403 | 4403 | } |
@@ -4417,43 +4417,43 @@ discard block |
||
4417 | 4417 | * @return int >0 if OK, <0 if KO |
4418 | 4418 | * @see addFileIntoDatabaseIndex |
4419 | 4419 | */ |
4420 | - protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
4420 | + protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams = null) |
|
4421 | 4421 | { |
4422 | 4422 | global $conf, $langs, $user; |
4423 | 4423 | |
4424 | - $srctemplatepath=''; |
|
4424 | + $srctemplatepath = ''; |
|
4425 | 4425 | |
4426 | 4426 | // Increase limit for PDF build |
4427 | - $err=error_reporting(); |
|
4427 | + $err = error_reporting(); |
|
4428 | 4428 | error_reporting(0); |
4429 | 4429 | @set_time_limit(120); |
4430 | 4430 | error_reporting($err); |
4431 | 4431 | |
4432 | 4432 | // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
4433 | - $tmp=explode(':',$modele,2); |
|
4434 | - if (! empty($tmp[1])) |
|
4433 | + $tmp = explode(':', $modele, 2); |
|
4434 | + if (!empty($tmp[1])) |
|
4435 | 4435 | { |
4436 | - $modele=$tmp[0]; |
|
4437 | - $srctemplatepath=$tmp[1]; |
|
4436 | + $modele = $tmp[0]; |
|
4437 | + $srctemplatepath = $tmp[1]; |
|
4438 | 4438 | } |
4439 | 4439 | |
4440 | 4440 | // Search template files |
4441 | - $file=''; $classname=''; $filefound=0; |
|
4442 | - $dirmodels=array('/'); |
|
4443 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
4444 | - foreach($dirmodels as $reldir) |
|
4441 | + $file = ''; $classname = ''; $filefound = 0; |
|
4442 | + $dirmodels = array('/'); |
|
4443 | + if (is_array($conf->modules_parts['models'])) $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); |
|
4444 | + foreach ($dirmodels as $reldir) |
|
4445 | 4445 | { |
4446 | - foreach(array('doc','pdf') as $prefix) |
|
4446 | + foreach (array('doc', 'pdf') as $prefix) |
|
4447 | 4447 | { |
4448 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
4448 | + if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
4449 | 4449 | else $file = $prefix."_".$modele.".modules.php"; |
4450 | 4450 | |
4451 | 4451 | // On verifie l'emplacement du modele |
4452 | - $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
4452 | + $file = dol_buildpath($reldir.$modelspath.$file, 0); |
|
4453 | 4453 | if (file_exists($file)) |
4454 | 4454 | { |
4455 | - $filefound=1; |
|
4456 | - $classname=$prefix.'_'.$modele; |
|
4455 | + $filefound = 1; |
|
4456 | + $classname = $prefix.'_'.$modele; |
|
4457 | 4457 | break; |
4458 | 4458 | } |
4459 | 4459 | } |
@@ -4463,7 +4463,7 @@ discard block |
||
4463 | 4463 | // If generator was found |
4464 | 4464 | if ($filefound) |
4465 | 4465 | { |
4466 | - global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
4466 | + global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
4467 | 4467 | |
4468 | 4468 | require_once $file; |
4469 | 4469 | |
@@ -4472,32 +4472,32 @@ discard block |
||
4472 | 4472 | // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
4473 | 4473 | if ($obj->type == 'odt' && empty($srctemplatepath)) |
4474 | 4474 | { |
4475 | - $varfortemplatedir=$obj->scandir; |
|
4476 | - if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) |
|
4475 | + $varfortemplatedir = $obj->scandir; |
|
4476 | + if ($varfortemplatedir && !empty($conf->global->$varfortemplatedir)) |
|
4477 | 4477 | { |
4478 | - $dirtoscan=$conf->global->$varfortemplatedir; |
|
4478 | + $dirtoscan = $conf->global->$varfortemplatedir; |
|
4479 | 4479 | |
4480 | - $listoffiles=array(); |
|
4480 | + $listoffiles = array(); |
|
4481 | 4481 | |
4482 | 4482 | // Now we add first model found in directories scanned |
4483 | - $listofdir=explode(',',$dirtoscan); |
|
4484 | - foreach($listofdir as $key => $tmpdir) |
|
4483 | + $listofdir = explode(',', $dirtoscan); |
|
4484 | + foreach ($listofdir as $key => $tmpdir) |
|
4485 | 4485 | { |
4486 | - $tmpdir=trim($tmpdir); |
|
4487 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
4488 | - if (! $tmpdir) { unset($listofdir[$key]); continue; } |
|
4486 | + $tmpdir = trim($tmpdir); |
|
4487 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
4488 | + if (!$tmpdir) { unset($listofdir[$key]); continue; } |
|
4489 | 4489 | if (is_dir($tmpdir)) |
4490 | 4490 | { |
4491 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
4492 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
4491 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.od(s|t)$', '', 'name', SORT_ASC, 0); |
|
4492 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
4493 | 4493 | } |
4494 | 4494 | } |
4495 | 4495 | |
4496 | 4496 | if (count($listoffiles)) |
4497 | 4497 | { |
4498 | - foreach($listoffiles as $record) |
|
4498 | + foreach ($listoffiles as $record) |
|
4499 | 4499 | { |
4500 | - $srctemplatepath=$record['fullname']; |
|
4500 | + $srctemplatepath = $record['fullname']; |
|
4501 | 4501 | break; |
4502 | 4502 | } |
4503 | 4503 | } |
@@ -4505,27 +4505,27 @@ discard block |
||
4505 | 4505 | |
4506 | 4506 | if (empty($srctemplatepath)) |
4507 | 4507 | { |
4508 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
4508 | + $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
4509 | 4509 | return -1; |
4510 | 4510 | } |
4511 | 4511 | } |
4512 | 4512 | |
4513 | - if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
4513 | + if ($obj->type == 'odt' && !empty($srctemplatepath)) |
|
4514 | 4514 | { |
4515 | - if (! dol_is_file($srctemplatepath)) |
|
4515 | + if (!dol_is_file($srctemplatepath)) |
|
4516 | 4516 | { |
4517 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
4517 | + $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
4518 | 4518 | return -1; |
4519 | 4519 | } |
4520 | 4520 | } |
4521 | 4521 | |
4522 | 4522 | // We save charset_output to restore it because write_file can change it if needed for |
4523 | 4523 | // output format that does not support UTF8. |
4524 | - $sav_charset_output=$outputlangs->charset_output; |
|
4524 | + $sav_charset_output = $outputlangs->charset_output; |
|
4525 | 4525 | |
4526 | 4526 | if (in_array(get_class($this), array('Adherent'))) |
4527 | 4527 | { |
4528 | - $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
4528 | + $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
4529 | 4529 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
4530 | 4530 | } |
4531 | 4531 | else |
@@ -4536,41 +4536,41 @@ discard block |
||
4536 | 4536 | |
4537 | 4537 | if ($resultwritefile > 0) |
4538 | 4538 | { |
4539 | - $outputlangs->charset_output=$sav_charset_output; |
|
4539 | + $outputlangs->charset_output = $sav_charset_output; |
|
4540 | 4540 | |
4541 | 4541 | // We delete old preview |
4542 | 4542 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
4543 | 4543 | dol_delete_preview($this); |
4544 | 4544 | |
4545 | 4545 | // Index file in database |
4546 | - if (! empty($obj->result['fullpath'])) |
|
4546 | + if (!empty($obj->result['fullpath'])) |
|
4547 | 4547 | { |
4548 | 4548 | $destfull = $obj->result['fullpath']; |
4549 | 4549 | $upload_dir = dirname($destfull); |
4550 | 4550 | $destfile = basename($destfull); |
4551 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); |
|
4551 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir); |
|
4552 | 4552 | |
4553 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
4553 | + if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
4554 | 4554 | { |
4555 | 4555 | $filename = basename($destfile); |
4556 | 4556 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
4557 | 4557 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
4558 | 4558 | |
4559 | 4559 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
4560 | - $ecmfile=new EcmFiles($this->db); |
|
4561 | - $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
4560 | + $ecmfile = new EcmFiles($this->db); |
|
4561 | + $result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir.'/' : '').$filename); |
|
4562 | 4562 | |
4563 | 4563 | // Set the public "share" key |
4564 | 4564 | $setsharekey = false; |
4565 | 4565 | if ($this->element == 'propal') |
4566 | 4566 | { |
4567 | - $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
4568 | - if ($useonlinesignature) $setsharekey=true; |
|
4569 | - if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4567 | + $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
4568 | + if ($useonlinesignature) $setsharekey = true; |
|
4569 | + if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
4570 | 4570 | } |
4571 | - if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4572 | - if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4573 | - if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
4571 | + if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
4572 | + if ($this->element == 'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
4573 | + if ($this->element == 'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
4574 | 4574 | |
4575 | 4575 | if ($setsharekey) |
4576 | 4576 | { |
@@ -4583,11 +4583,11 @@ discard block |
||
4583 | 4583 | |
4584 | 4584 | if ($result > 0) |
4585 | 4585 | { |
4586 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
4586 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
4587 | 4587 | $ecmfile->fullpath_orig = ''; |
4588 | 4588 | $ecmfile->gen_or_uploaded = 'generated'; |
4589 | - $ecmfile->description = ''; // indexed content |
|
4590 | - $ecmfile->keyword = ''; // keyword content |
|
4589 | + $ecmfile->description = ''; // indexed content |
|
4590 | + $ecmfile->keyword = ''; // keyword content |
|
4591 | 4591 | $result = $ecmfile->update($user); |
4592 | 4592 | if ($result < 0) |
4593 | 4593 | { |
@@ -4599,11 +4599,11 @@ discard block |
||
4599 | 4599 | $ecmfile->entity = $conf->entity; |
4600 | 4600 | $ecmfile->filepath = $rel_dir; |
4601 | 4601 | $ecmfile->filename = $filename; |
4602 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
4602 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
4603 | 4603 | $ecmfile->fullpath_orig = ''; |
4604 | 4604 | $ecmfile->gen_or_uploaded = 'generated'; |
4605 | - $ecmfile->description = ''; // indexed content |
|
4606 | - $ecmfile->keyword = ''; // keyword content |
|
4605 | + $ecmfile->description = ''; // indexed content |
|
4606 | + $ecmfile->keyword = ''; // keyword content |
|
4607 | 4607 | $ecmfile->src_object_type = $this->table_element; |
4608 | 4608 | $ecmfile->src_object_id = $this->id; |
4609 | 4609 | |
@@ -4620,14 +4620,14 @@ discard block |
||
4620 | 4620 | //var_dump($obj->update_main_doc_field);exit; |
4621 | 4621 | |
4622 | 4622 | // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
4623 | - $update_main_doc_field=0; |
|
4624 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
4625 | - if ($update_main_doc_field && ! empty($this->table_element)) |
|
4623 | + $update_main_doc_field = 0; |
|
4624 | + if (!empty($obj->update_main_doc_field)) $update_main_doc_field = 1; |
|
4625 | + if ($update_main_doc_field && !empty($this->table_element)) |
|
4626 | 4626 | { |
4627 | 4627 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
4628 | - $sql.= ' WHERE rowid = '.$this->id; |
|
4628 | + $sql .= ' WHERE rowid = '.$this->id; |
|
4629 | 4629 | $resql = $this->db->query($sql); |
4630 | - if (! $resql) dol_print_error($this->db); |
|
4630 | + if (!$resql) dol_print_error($this->db); |
|
4631 | 4631 | } |
4632 | 4632 | } |
4633 | 4633 | } |
@@ -4643,15 +4643,15 @@ discard block |
||
4643 | 4643 | } |
4644 | 4644 | else |
4645 | 4645 | { |
4646 | - $outputlangs->charset_output=$sav_charset_output; |
|
4646 | + $outputlangs->charset_output = $sav_charset_output; |
|
4647 | 4647 | dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
4648 | 4648 | return -1; |
4649 | 4649 | } |
4650 | 4650 | } |
4651 | 4651 | else |
4652 | 4652 | { |
4653 | - $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
|
4654 | - dol_print_error('',$this->error); |
|
4653 | + $this->error = $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file); |
|
4654 | + dol_print_error('', $this->error); |
|
4655 | 4655 | return -1; |
4656 | 4656 | } |
4657 | 4657 | } |
@@ -4667,9 +4667,9 @@ discard block |
||
4667 | 4667 | { |
4668 | 4668 | global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
4669 | 4669 | |
4670 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
4670 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
4671 | 4671 | |
4672 | - $file_osencoded=dol_osencode($file); |
|
4672 | + $file_osencoded = dol_osencode($file); |
|
4673 | 4673 | if (file_exists($file_osencoded)) |
4674 | 4674 | { |
4675 | 4675 | // Create small thumbs for company (Ratio is near 16/9) |
@@ -4699,7 +4699,7 @@ discard block |
||
4699 | 4699 | * @param string $alternatevalue Alternate value to use |
4700 | 4700 | * @return string|string[] Default value (can be an array if the GETPOST return an array) |
4701 | 4701 | **/ |
4702 | - function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
4702 | + function getDefaultCreateValueFor($fieldname, $alternatevalue = null) |
|
4703 | 4703 | { |
4704 | 4704 | global $conf, $_POST; |
4705 | 4705 | |
@@ -4708,16 +4708,16 @@ discard block |
||
4708 | 4708 | |
4709 | 4709 | if (isset($alternatevalue)) return $alternatevalue; |
4710 | 4710 | |
4711 | - $newelement=$this->element; |
|
4712 | - if ($newelement == 'facture') $newelement='invoice'; |
|
4713 | - if ($newelement == 'commande') $newelement='order'; |
|
4711 | + $newelement = $this->element; |
|
4712 | + if ($newelement == 'facture') $newelement = 'invoice'; |
|
4713 | + if ($newelement == 'commande') $newelement = 'order'; |
|
4714 | 4714 | if (empty($newelement)) |
4715 | 4715 | { |
4716 | 4716 | dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING); |
4717 | 4717 | return ''; |
4718 | 4718 | } |
4719 | 4719 | |
4720 | - $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
4720 | + $keyforfieldname = strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
4721 | 4721 | //var_dump($keyforfieldname); |
4722 | 4722 | if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
4723 | 4723 | |
@@ -4742,21 +4742,21 @@ discard block |
||
4742 | 4742 | function call_trigger($trigger_name, $user) |
4743 | 4743 | { |
4744 | 4744 | // phpcs:enable |
4745 | - global $langs,$conf; |
|
4745 | + global $langs, $conf; |
|
4746 | 4746 | |
4747 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
4748 | - $interface=new Interfaces($this->db); |
|
4749 | - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
4747 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
4748 | + $interface = new Interfaces($this->db); |
|
4749 | + $result = $interface->run_triggers($trigger_name, $this, $user, $langs, $conf); |
|
4750 | 4750 | |
4751 | 4751 | if ($result < 0) |
4752 | 4752 | { |
4753 | 4753 | if (!empty($this->errors)) |
4754 | 4754 | { |
4755 | - $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. |
|
4755 | + $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 | 4756 | } |
4757 | 4757 | else |
4758 | 4758 | { |
4759 | - $this->errors=$interface->errors; |
|
4759 | + $this->errors = $interface->errors; |
|
4760 | 4760 | } |
4761 | 4761 | } |
4762 | 4762 | return $result; |
@@ -4775,19 +4775,19 @@ discard block |
||
4775 | 4775 | * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
4776 | 4776 | * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
4777 | 4777 | */ |
4778 | - function fetch_optionals($rowid=null, $optionsArray=null) |
|
4778 | + function fetch_optionals($rowid = null, $optionsArray = null) |
|
4779 | 4779 | { |
4780 | 4780 | // phpcs:enable |
4781 | - if (empty($rowid)) $rowid=$this->id; |
|
4781 | + if (empty($rowid)) $rowid = $this->id; |
|
4782 | 4782 | |
4783 | 4783 | // To avoid SQL errors. Probably not the better solution though |
4784 | 4784 | if (!$this->table_element) { |
4785 | 4785 | return 0; |
4786 | 4786 | } |
4787 | 4787 | |
4788 | - $this->array_options=array(); |
|
4788 | + $this->array_options = array(); |
|
4789 | 4789 | |
4790 | - if (! is_array($optionsArray)) |
|
4790 | + if (!is_array($optionsArray)) |
|
4791 | 4791 | { |
4792 | 4792 | // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
4793 | 4793 | // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
@@ -4803,7 +4803,7 @@ discard block |
||
4803 | 4803 | { |
4804 | 4804 | $extrafields->fetch_name_optionals_label($this->table_element); |
4805 | 4805 | } |
4806 | - $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
|
4806 | + $optionsArray = (!empty($extrafields->attributes[$this->table_element]['label']) ? $extrafields->attributes[$this->table_element]['label'] : null); |
|
4807 | 4807 | } |
4808 | 4808 | else |
4809 | 4809 | { |
@@ -4822,18 +4822,18 @@ discard block |
||
4822 | 4822 | { |
4823 | 4823 | if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
4824 | 4824 | { |
4825 | - $sql.= ", ".$name; |
|
4825 | + $sql .= ", ".$name; |
|
4826 | 4826 | } |
4827 | 4827 | } |
4828 | - $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
4829 | - $sql.= " WHERE fk_object = ".$rowid; |
|
4828 | + $sql .= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
4829 | + $sql .= " WHERE fk_object = ".$rowid; |
|
4830 | 4830 | |
4831 | 4831 | //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
4832 | - $resql=$this->db->query($sql); |
|
4832 | + $resql = $this->db->query($sql); |
|
4833 | 4833 | if ($resql) |
4834 | 4834 | { |
4835 | 4835 | $this->array_options = array(); |
4836 | - $numrows=$this->db->num_rows($resql); |
|
4836 | + $numrows = $this->db->num_rows($resql); |
|
4837 | 4837 | if ($numrows) |
4838 | 4838 | { |
4839 | 4839 | $tab = $this->db->fetch_array($resql); |
@@ -4841,17 +4841,17 @@ discard block |
||
4841 | 4841 | foreach ($tab as $key => $value) |
4842 | 4842 | { |
4843 | 4843 | // 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) |
4844 | - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
4844 | + if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && !is_int($key)) |
|
4845 | 4845 | { |
4846 | 4846 | // we can add this attribute to object |
4847 | - if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime'))) |
|
4847 | + if (!empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime'))) |
|
4848 | 4848 | { |
4849 | 4849 | //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
4850 | - $this->array_options["options_".$key]=$this->db->jdate($value); |
|
4850 | + $this->array_options["options_".$key] = $this->db->jdate($value); |
|
4851 | 4851 | } |
4852 | 4852 | else |
4853 | 4853 | { |
4854 | - $this->array_options["options_".$key]=$value; |
|
4854 | + $this->array_options["options_".$key] = $value; |
|
4855 | 4855 | } |
4856 | 4856 | |
4857 | 4857 | //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]); |
@@ -4887,10 +4887,10 @@ discard block |
||
4887 | 4887 | |
4888 | 4888 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
4889 | 4889 | dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
4890 | - $resql=$this->db->query($sql_del); |
|
4891 | - if (! $resql) |
|
4890 | + $resql = $this->db->query($sql_del); |
|
4891 | + if (!$resql) |
|
4892 | 4892 | { |
4893 | - $this->error=$this->db->lasterror(); |
|
4893 | + $this->error = $this->db->lasterror(); |
|
4894 | 4894 | $this->db->rollback(); |
4895 | 4895 | return -1; |
4896 | 4896 | } |
@@ -4911,36 +4911,36 @@ discard block |
||
4911 | 4911 | * @return int -1=error, O=did nothing, 1=OK |
4912 | 4912 | * @see updateExtraField, setValueFrom |
4913 | 4913 | */ |
4914 | - function insertExtraFields($trigger='', $userused=null) |
|
4914 | + function insertExtraFields($trigger = '', $userused = null) |
|
4915 | 4915 | { |
4916 | - global $conf,$langs,$user; |
|
4916 | + global $conf, $langs, $user; |
|
4917 | 4917 | |
4918 | - if (empty($userused)) $userused=$user; |
|
4918 | + if (empty($userused)) $userused = $user; |
|
4919 | 4919 | |
4920 | - $error=0; |
|
4920 | + $error = 0; |
|
4921 | 4921 | |
4922 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
4922 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
4923 | 4923 | |
4924 | - if (! empty($this->array_options)) |
|
4924 | + if (!empty($this->array_options)) |
|
4925 | 4925 | { |
4926 | 4926 | // Check parameters |
4927 | 4927 | $langs->load('admin'); |
4928 | 4928 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
4929 | 4929 | $extrafields = new ExtraFields($this->db); |
4930 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
4930 | + $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
|
4931 | 4931 | |
4932 | 4932 | //Eliminate copied source object extra_fields that do not exist in target object |
4933 | - $new_array_options=array(); |
|
4933 | + $new_array_options = array(); |
|
4934 | 4934 | foreach ($this->array_options as $key => $value) { |
4935 | - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
4935 | + if (in_array(substr($key, 8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
4936 | 4936 | $new_array_options[$key] = $value; |
4937 | 4937 | elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
4938 | 4938 | $new_array_options['options_'.$key] = $value; |
4939 | 4939 | } |
4940 | 4940 | |
4941 | - foreach($new_array_options as $key => $value) |
|
4941 | + foreach ($new_array_options as $key => $value) |
|
4942 | 4942 | { |
4943 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
4943 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
4944 | 4944 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
4945 | 4945 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
4946 | 4946 | $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
@@ -4948,13 +4948,13 @@ discard block |
||
4948 | 4948 | |
4949 | 4949 | if ($attributeRequired) |
4950 | 4950 | { |
4951 | - $mandatorypb=false; |
|
4952 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
4953 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
4951 | + $mandatorypb = false; |
|
4952 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb = true; |
|
4953 | + if ($this->array_options[$key] === '') $mandatorypb = true; |
|
4954 | 4954 | if ($mandatorypb) |
4955 | 4955 | { |
4956 | 4956 | dol_syslog($this->error); |
4957 | - $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel); |
|
4957 | + $this->errors[] = $langs->trans('ErrorFieldRequired', $attributeLabel); |
|
4958 | 4958 | return -1; |
4959 | 4959 | } |
4960 | 4960 | } |
@@ -4965,25 +4965,25 @@ discard block |
||
4965 | 4965 | switch ($attributeType) |
4966 | 4966 | { |
4967 | 4967 | case 'int': |
4968 | - if (!is_numeric($value) && $value!='') |
|
4968 | + if (!is_numeric($value) && $value != '') |
|
4969 | 4969 | { |
4970 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
4970 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
4971 | 4971 | return -1; |
4972 | 4972 | } |
4973 | - elseif ($value=='') |
|
4973 | + elseif ($value == '') |
|
4974 | 4974 | { |
4975 | 4975 | $new_array_options[$key] = null; |
4976 | 4976 | } |
4977 | 4977 | break; |
4978 | 4978 | case 'double': |
4979 | 4979 | $value = price2num($value); |
4980 | - if (!is_numeric($value) && $value!='') |
|
4980 | + if (!is_numeric($value) && $value != '') |
|
4981 | 4981 | { |
4982 | 4982 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
4983 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
4983 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
4984 | 4984 | return -1; |
4985 | 4985 | } |
4986 | - elseif ($value=='') |
|
4986 | + elseif ($value == '') |
|
4987 | 4987 | { |
4988 | 4988 | $new_array_options[$key] = null; |
4989 | 4989 | } |
@@ -4997,12 +4997,12 @@ discard block |
||
4997 | 4997 | } |
4998 | 4998 | break;*/ |
4999 | 4999 | case 'password': |
5000 | - $algo=''; |
|
5000 | + $algo = ''; |
|
5001 | 5001 | if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
5002 | 5002 | { |
5003 | 5003 | // If there is an encryption choice, we use it to crypt data before insert |
5004 | 5004 | $tmparrays = array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options']); |
5005 | - $algo=reset($tmparrays); |
|
5005 | + $algo = reset($tmparrays); |
|
5006 | 5006 | if ($algo != '') |
5007 | 5007 | { |
5008 | 5008 | //global $action; // $action may be 'create', 'update', 'update_extras'... |
@@ -5013,7 +5013,7 @@ discard block |
||
5013 | 5013 | //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
5014 | 5014 | 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. |
5015 | 5015 | { |
5016 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
5016 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
5017 | 5017 | } |
5018 | 5018 | else |
5019 | 5019 | { |
@@ -5024,7 +5024,7 @@ discard block |
||
5024 | 5024 | } |
5025 | 5025 | else |
5026 | 5026 | { |
5027 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
5027 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
5028 | 5028 | } |
5029 | 5029 | } |
5030 | 5030 | } |
@@ -5041,13 +5041,13 @@ discard block |
||
5041 | 5041 | break; |
5042 | 5042 | case 'datetime': |
5043 | 5043 | // If data is a string instead of a timestamp, we convert it |
5044 | - if (! is_int($this->array_options[$key])) { |
|
5044 | + if (!is_int($this->array_options[$key])) { |
|
5045 | 5045 | $this->array_options[$key] = strtotime($this->array_options[$key]); |
5046 | 5046 | } |
5047 | 5047 | $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
5048 | 5048 | break; |
5049 | 5049 | case 'link': |
5050 | - $param_list=array_keys($attributeParam['options']); |
|
5050 | + $param_list = array_keys($attributeParam['options']); |
|
5051 | 5051 | // 0 : ObjectName |
5052 | 5052 | // 1 : classPath |
5053 | 5053 | $InfoFieldList = explode(":", $param_list[0]); |
@@ -5056,18 +5056,18 @@ discard block |
||
5056 | 5056 | { |
5057 | 5057 | if ($value == '-1') // -1 is key for no defined in combo list of objects |
5058 | 5058 | { |
5059 | - $new_array_options[$key]=''; |
|
5059 | + $new_array_options[$key] = ''; |
|
5060 | 5060 | } |
5061 | 5061 | elseif ($value) |
5062 | 5062 | { |
5063 | 5063 | $object = new $InfoFieldList[0]($this->db); |
5064 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
5065 | - else $res=$object->fetch('',$value); |
|
5064 | + if (is_numeric($value)) $res = $object->fetch($value); |
|
5065 | + else $res = $object->fetch('', $value); |
|
5066 | 5066 | |
5067 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
5067 | + if ($res > 0) $new_array_options[$key] = $object->id; |
|
5068 | 5068 | else |
5069 | 5069 | { |
5070 | - $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
5070 | + $this->error = "Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
5071 | 5071 | $this->db->rollback(); |
5072 | 5072 | return -1; |
5073 | 5073 | } |
@@ -5091,46 +5091,46 @@ discard block |
||
5091 | 5091 | $this->db->query($sql_del); |
5092 | 5092 | |
5093 | 5093 | $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
5094 | - foreach($new_array_options as $key => $value) |
|
5094 | + foreach ($new_array_options as $key => $value) |
|
5095 | 5095 | { |
5096 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
5096 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
5097 | 5097 | // Add field of attribut |
5098 | 5098 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
5099 | - $sql.=",".$attributeKey; |
|
5099 | + $sql .= ",".$attributeKey; |
|
5100 | 5100 | } |
5101 | 5101 | $sql .= ") VALUES (".$this->id; |
5102 | 5102 | |
5103 | - foreach($new_array_options as $key => $value) |
|
5103 | + foreach ($new_array_options as $key => $value) |
|
5104 | 5104 | { |
5105 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
5105 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
5106 | 5106 | // Add field of attribute |
5107 | 5107 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
5108 | 5108 | { |
5109 | 5109 | if ($new_array_options[$key] != '') |
5110 | 5110 | { |
5111 | - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
5111 | + $sql .= ",'".$this->db->escape($new_array_options[$key])."'"; |
|
5112 | 5112 | } |
5113 | 5113 | else |
5114 | 5114 | { |
5115 | - $sql.=",null"; |
|
5115 | + $sql .= ",null"; |
|
5116 | 5116 | } |
5117 | 5117 | } |
5118 | 5118 | } |
5119 | - $sql.=")"; |
|
5119 | + $sql .= ")"; |
|
5120 | 5120 | |
5121 | 5121 | dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
5122 | 5122 | $resql = $this->db->query($sql); |
5123 | - if (! $resql) |
|
5123 | + if (!$resql) |
|
5124 | 5124 | { |
5125 | - $this->error=$this->db->lasterror(); |
|
5125 | + $this->error = $this->db->lasterror(); |
|
5126 | 5126 | $error++; |
5127 | 5127 | } |
5128 | 5128 | |
5129 | - if (! $error && $trigger) |
|
5129 | + if (!$error && $trigger) |
|
5130 | 5130 | { |
5131 | 5131 | // Call trigger |
5132 | - $this->context=array('extrafieldaddupdate'=>1); |
|
5133 | - $result=$this->call_trigger($trigger, $userused); |
|
5132 | + $this->context = array('extrafieldaddupdate'=>1); |
|
5133 | + $result = $this->call_trigger($trigger, $userused); |
|
5134 | 5134 | if ($result < 0) $error++; |
5135 | 5135 | // End call trigger |
5136 | 5136 | } |
@@ -5159,25 +5159,25 @@ discard block |
||
5159 | 5159 | * @return int -1=error, O=did nothing, 1=OK |
5160 | 5160 | * @see setValueFrom, insertExtraFields |
5161 | 5161 | */ |
5162 | - function updateExtraField($key, $trigger=null, $userused=null) |
|
5162 | + function updateExtraField($key, $trigger = null, $userused = null) |
|
5163 | 5163 | { |
5164 | - global $conf,$langs,$user; |
|
5164 | + global $conf, $langs, $user; |
|
5165 | 5165 | |
5166 | - if (empty($userused)) $userused=$user; |
|
5166 | + if (empty($userused)) $userused = $user; |
|
5167 | 5167 | |
5168 | - $error=0; |
|
5168 | + $error = 0; |
|
5169 | 5169 | |
5170 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
5170 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
5171 | 5171 | |
5172 | - if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
5172 | + if (!empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
5173 | 5173 | { |
5174 | 5174 | // Check parameters |
5175 | 5175 | $langs->load('admin'); |
5176 | 5176 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
5177 | 5177 | $extrafields = new ExtraFields($this->db); |
5178 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
5178 | + $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
|
5179 | 5179 | |
5180 | - $value=$this->array_options["options_".$key]; |
|
5180 | + $value = $this->array_options["options_".$key]; |
|
5181 | 5181 | |
5182 | 5182 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
5183 | 5183 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
@@ -5190,25 +5190,25 @@ discard block |
||
5190 | 5190 | switch ($attributeType) |
5191 | 5191 | { |
5192 | 5192 | case 'int': |
5193 | - if (!is_numeric($value) && $value!='') |
|
5193 | + if (!is_numeric($value) && $value != '') |
|
5194 | 5194 | { |
5195 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); |
|
5195 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
5196 | 5196 | return -1; |
5197 | 5197 | } |
5198 | - elseif ($value=='') |
|
5198 | + elseif ($value == '') |
|
5199 | 5199 | { |
5200 | 5200 | $this->array_options["options_".$key] = null; |
5201 | 5201 | } |
5202 | 5202 | break; |
5203 | 5203 | case 'double': |
5204 | 5204 | $value = price2num($value); |
5205 | - if (!is_numeric($value) && $value!='') |
|
5205 | + if (!is_numeric($value) && $value != '') |
|
5206 | 5206 | { |
5207 | 5207 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); |
5208 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
5208 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
5209 | 5209 | return -1; |
5210 | 5210 | } |
5211 | - elseif ($value=='') |
|
5211 | + elseif ($value == '') |
|
5212 | 5212 | { |
5213 | 5213 | $this->array_options["options_".$key] = null; |
5214 | 5214 | } |
@@ -5225,13 +5225,13 @@ discard block |
||
5225 | 5225 | $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
5226 | 5226 | break; |
5227 | 5227 | case 'date': |
5228 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
5228 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
5229 | 5229 | break; |
5230 | 5230 | case 'datetime': |
5231 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
5231 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
5232 | 5232 | break; |
5233 | 5233 | case 'link': |
5234 | - $param_list=array_keys($attributeParam['options']); |
|
5234 | + $param_list = array_keys($attributeParam['options']); |
|
5235 | 5235 | // 0 : ObjectName |
5236 | 5236 | // 1 : classPath |
5237 | 5237 | $InfoFieldList = explode(":", $param_list[0]); |
@@ -5239,8 +5239,8 @@ discard block |
||
5239 | 5239 | if ($value) |
5240 | 5240 | { |
5241 | 5241 | $object = new $InfoFieldList[0]($this->db); |
5242 | - $object->fetch(0,$value); |
|
5243 | - $this->array_options["options_".$key]=$object->id; |
|
5242 | + $object->fetch(0, $value); |
|
5243 | + $this->array_options["options_".$key] = $object->id; |
|
5244 | 5244 | } |
5245 | 5245 | break; |
5246 | 5246 | } |
@@ -5249,24 +5249,24 @@ discard block |
||
5249 | 5249 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
5250 | 5250 | $sql .= " WHERE fk_object = ".$this->id; |
5251 | 5251 | $resql = $this->db->query($sql); |
5252 | - if (! $resql) |
|
5252 | + if (!$resql) |
|
5253 | 5253 | { |
5254 | 5254 | $error++; |
5255 | - $this->error=$this->db->lasterror(); |
|
5255 | + $this->error = $this->db->lasterror(); |
|
5256 | 5256 | } |
5257 | 5257 | |
5258 | - if (! $error && $trigger) |
|
5258 | + if (!$error && $trigger) |
|
5259 | 5259 | { |
5260 | 5260 | // Call trigger |
5261 | - $this->context=array('extrafieldupdate'=>1); |
|
5262 | - $result=$this->call_trigger($trigger, $userused); |
|
5261 | + $this->context = array('extrafieldupdate'=>1); |
|
5262 | + $result = $this->call_trigger($trigger, $userused); |
|
5263 | 5263 | if ($result < 0) $error++; |
5264 | 5264 | // End call trigger |
5265 | 5265 | } |
5266 | 5266 | |
5267 | 5267 | if ($error) |
5268 | 5268 | { |
5269 | - dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
|
5269 | + dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR); |
|
5270 | 5270 | $this->db->rollback(); |
5271 | 5271 | return -1; |
5272 | 5272 | } |
@@ -5293,71 +5293,71 @@ discard block |
||
5293 | 5293 | * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. |
5294 | 5294 | * @return string |
5295 | 5295 | */ |
5296 | - function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0) |
|
5296 | + function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0) |
|
5297 | 5297 | { |
5298 | - global $conf,$langs,$form; |
|
5298 | + global $conf, $langs, $form; |
|
5299 | 5299 | |
5300 | - if (! is_object($form)) |
|
5300 | + if (!is_object($form)) |
|
5301 | 5301 | { |
5302 | 5302 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
5303 | - $form=new Form($this->db); |
|
5303 | + $form = new Form($this->db); |
|
5304 | 5304 | } |
5305 | 5305 | |
5306 | - $val=$this->fields[$key]; |
|
5306 | + $val = $this->fields[$key]; |
|
5307 | 5307 | |
5308 | - $out=''; |
|
5309 | - $type=''; |
|
5308 | + $out = ''; |
|
5309 | + $type = ''; |
|
5310 | 5310 | $param = array(); |
5311 | - $param['options']=array(); |
|
5312 | - $size =$this->fields[$key]['size']; |
|
5311 | + $param['options'] = array(); |
|
5312 | + $size = $this->fields[$key]['size']; |
|
5313 | 5313 | // Because we work on extrafields |
5314 | - if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){ |
|
5315 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
5316 | - $type ='link'; |
|
5317 | - } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) { |
|
5318 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
5319 | - $type ='link'; |
|
5320 | - } elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) { |
|
5321 | - $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
5322 | - $type ='sellist'; |
|
5323 | - } elseif(preg_match('/varchar\((\d+)\)/', $val['type'],$reg)) { |
|
5324 | - $param['options']=array(); |
|
5325 | - $type ='varchar'; |
|
5326 | - $size=$reg[1]; |
|
5327 | - } elseif(preg_match('/varchar/', $val['type'])) { |
|
5328 | - $param['options']=array(); |
|
5329 | - $type ='varchar'; |
|
5330 | - } elseif(is_array($this->fields[$key]['arrayofkeyval'])) { |
|
5331 | - $param['options']=$this->fields[$key]['arrayofkeyval']; |
|
5332 | - $type ='select'; |
|
5314 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) { |
|
5315 | + $param['options'] = array($reg[1].':'.$reg[2]=>'N'); |
|
5316 | + $type = 'link'; |
|
5317 | + } elseif (preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) { |
|
5318 | + $param['options'] = array($reg[1].':'.$reg[2]=>'N'); |
|
5319 | + $type = 'link'; |
|
5320 | + } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) { |
|
5321 | + $param['options'] = array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
5322 | + $type = 'sellist'; |
|
5323 | + } elseif (preg_match('/varchar\((\d+)\)/', $val['type'], $reg)) { |
|
5324 | + $param['options'] = array(); |
|
5325 | + $type = 'varchar'; |
|
5326 | + $size = $reg[1]; |
|
5327 | + } elseif (preg_match('/varchar/', $val['type'])) { |
|
5328 | + $param['options'] = array(); |
|
5329 | + $type = 'varchar'; |
|
5330 | + } elseif (is_array($this->fields[$key]['arrayofkeyval'])) { |
|
5331 | + $param['options'] = $this->fields[$key]['arrayofkeyval']; |
|
5332 | + $type = 'select'; |
|
5333 | 5333 | } else { |
5334 | - $param['options']=array(); |
|
5335 | - $type =$this->fields[$key]['type']; |
|
5334 | + $param['options'] = array(); |
|
5335 | + $type = $this->fields[$key]['type']; |
|
5336 | 5336 | } |
5337 | 5337 | |
5338 | - $label=$this->fields[$key]['label']; |
|
5338 | + $label = $this->fields[$key]['label']; |
|
5339 | 5339 | //$elementtype=$this->fields[$key]['elementtype']; // Seems not used |
5340 | - $default=$this->fields[$key]['default']; |
|
5341 | - $computed=$this->fields[$key]['computed']; |
|
5342 | - $unique=$this->fields[$key]['unique']; |
|
5343 | - $required=$this->fields[$key]['required']; |
|
5340 | + $default = $this->fields[$key]['default']; |
|
5341 | + $computed = $this->fields[$key]['computed']; |
|
5342 | + $unique = $this->fields[$key]['unique']; |
|
5343 | + $required = $this->fields[$key]['required']; |
|
5344 | 5344 | |
5345 | - $langfile=$this->fields[$key]['langfile']; |
|
5346 | - $list=$this->fields[$key]['list']; |
|
5347 | - $hidden=abs($this->fields[$key]['visible'])!=1?1:0; |
|
5345 | + $langfile = $this->fields[$key]['langfile']; |
|
5346 | + $list = $this->fields[$key]['list']; |
|
5347 | + $hidden = abs($this->fields[$key]['visible']) != 1 ? 1 : 0; |
|
5348 | 5348 | |
5349 | 5349 | $objectid = $this->id; |
5350 | 5350 | |
5351 | 5351 | |
5352 | 5352 | if ($computed) |
5353 | 5353 | { |
5354 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
5354 | + if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
5355 | 5355 | else return ''; |
5356 | 5356 | } |
5357 | 5357 | |
5358 | 5358 | |
5359 | 5359 | // Use in priority showsize from parameters, then $val['css'] then autodefine |
5360 | - if (empty($morecss) && ! empty($val['css'])) |
|
5360 | + if (empty($morecss) && !empty($val['css'])) |
|
5361 | 5361 | { |
5362 | 5362 | $showsize = $val['css']; |
5363 | 5363 | } |
@@ -5371,16 +5371,16 @@ discard block |
||
5371 | 5371 | { |
5372 | 5372 | $morecss = 'minwidth200imp'; |
5373 | 5373 | } |
5374 | - elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
5374 | + elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type)) |
|
5375 | 5375 | { |
5376 | 5376 | $morecss = 'maxwidth75'; |
5377 | 5377 | }elseif ($type == 'url') |
5378 | 5378 | { |
5379 | - $morecss='minwidth400'; |
|
5379 | + $morecss = 'minwidth400'; |
|
5380 | 5380 | } |
5381 | 5381 | elseif ($type == 'boolean') |
5382 | 5382 | { |
5383 | - $morecss=''; |
|
5383 | + $morecss = ''; |
|
5384 | 5384 | } |
5385 | 5385 | else |
5386 | 5386 | { |
@@ -5399,12 +5399,12 @@ discard block |
||
5399 | 5399 | } |
5400 | 5400 | } |
5401 | 5401 | |
5402 | - if (in_array($type,array('date','datetime'))) |
|
5402 | + if (in_array($type, array('date', 'datetime'))) |
|
5403 | 5403 | { |
5404 | - $tmp=explode(',',$size); |
|
5405 | - $newsize=$tmp[0]; |
|
5404 | + $tmp = explode(',', $size); |
|
5405 | + $newsize = $tmp[0]; |
|
5406 | 5406 | |
5407 | - $showtime = in_array($type,array('datetime')) ? 1 : 0; |
|
5407 | + $showtime = in_array($type, array('datetime')) ? 1 : 0; |
|
5408 | 5408 | |
5409 | 5409 | // Do not show current date when field not required (see selectDate() method) |
5410 | 5410 | if (!$required && $value == '') $value = '-1'; |
@@ -5412,237 +5412,237 @@ discard block |
||
5412 | 5412 | // TODO Must also support $moreparam |
5413 | 5413 | $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
5414 | 5414 | } |
5415 | - elseif (in_array($type,array('int','integer'))) |
|
5415 | + elseif (in_array($type, array('int', 'integer'))) |
|
5416 | 5416 | { |
5417 | - $tmp=explode(',',$size); |
|
5418 | - $newsize=$tmp[0]; |
|
5419 | - $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:'').'>'; |
|
5417 | + $tmp = explode(',', $size); |
|
5418 | + $newsize = $tmp[0]; |
|
5419 | + $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 : '').'>'; |
|
5420 | 5420 | } |
5421 | 5421 | elseif (preg_match('/varchar/', $type)) |
5422 | 5422 | { |
5423 | - $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:'').'>'; |
|
5423 | + $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 | 5424 | } |
5425 | 5425 | elseif (in_array($type, array('mail', 'phone', 'url'))) |
5426 | 5426 | { |
5427 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
5427 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
5428 | 5428 | } |
5429 | 5429 | elseif ($type == 'text') |
5430 | 5430 | { |
5431 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
5431 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
5432 | 5432 | { |
5433 | 5433 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
5434 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
5435 | - $out=$doleditor->Create(1); |
|
5434 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); |
|
5435 | + $out = $doleditor->Create(1); |
|
5436 | 5436 | } |
5437 | 5437 | else |
5438 | 5438 | { |
5439 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
5439 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
5440 | 5440 | } |
5441 | 5441 | } |
5442 | 5442 | elseif ($type == 'html') |
5443 | 5443 | { |
5444 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
5444 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
5445 | 5445 | { |
5446 | 5446 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
5447 | - $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%'); |
|
5448 | - $out=$doleditor->Create(1); |
|
5447 | + $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%'); |
|
5448 | + $out = $doleditor->Create(1); |
|
5449 | 5449 | } |
5450 | 5450 | else |
5451 | 5451 | { |
5452 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
5452 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
5453 | 5453 | } |
5454 | 5454 | } |
5455 | 5455 | elseif ($type == 'boolean') |
5456 | 5456 | { |
5457 | - $checked=''; |
|
5457 | + $checked = ''; |
|
5458 | 5458 | if (!empty($value)) { |
5459 | - $checked=' checked value="1" '; |
|
5459 | + $checked = ' checked value="1" '; |
|
5460 | 5460 | } else { |
5461 | - $checked=' value="1" '; |
|
5461 | + $checked = ' value="1" '; |
|
5462 | 5462 | } |
5463 | - $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
5463 | + $out = '<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>'; |
|
5464 | 5464 | } |
5465 | 5465 | elseif ($type == 'price') |
5466 | 5466 | { |
5467 | 5467 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
5468 | - $value=price($value); |
|
5468 | + $value = price($value); |
|
5469 | 5469 | } |
5470 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
|
5470 | + $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 | 5471 | } |
5472 | - elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type)) |
|
5472 | + elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type)) |
|
5473 | 5473 | { |
5474 | 5474 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
5475 | - $value=price($value); |
|
5475 | + $value = price($value); |
|
5476 | 5476 | } |
5477 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
5477 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '; |
|
5478 | 5478 | } |
5479 | 5479 | elseif ($type == 'select') |
5480 | 5480 | { |
5481 | 5481 | $out = ''; |
5482 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
5482 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
5483 | 5483 | { |
5484 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
5485 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
5484 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
5485 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
5486 | 5486 | } |
5487 | 5487 | |
5488 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
5489 | - if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
5488 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
5489 | + if ((!isset($this->fields[$key]['default'])) || ($this->fields[$key]['notnull'] != 1))$out .= '<option value="0"> </option>'; |
|
5490 | 5490 | foreach ($param['options'] as $key => $val) |
5491 | 5491 | { |
5492 | 5492 | if ((string) $key == '') continue; |
5493 | 5493 | list($val, $parent) = explode('|', $val); |
5494 | - $out.='<option value="'.$key.'"'; |
|
5495 | - $out.= (((string) $value == (string) $key)?' selected':''); |
|
5496 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
5497 | - $out.='>'.$val.'</option>'; |
|
5494 | + $out .= '<option value="'.$key.'"'; |
|
5495 | + $out .= (((string) $value == (string) $key) ? ' selected' : ''); |
|
5496 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
5497 | + $out .= '>'.$val.'</option>'; |
|
5498 | 5498 | } |
5499 | - $out.='</select>'; |
|
5499 | + $out .= '</select>'; |
|
5500 | 5500 | } |
5501 | 5501 | elseif ($type == 'sellist') |
5502 | 5502 | { |
5503 | 5503 | $out = ''; |
5504 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
5504 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
5505 | 5505 | { |
5506 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
5507 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
5506 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
5507 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
5508 | 5508 | } |
5509 | 5509 | |
5510 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
5510 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
5511 | 5511 | if (is_array($param['options'])) |
5512 | 5512 | { |
5513 | - $param_list=array_keys($param['options']); |
|
5513 | + $param_list = array_keys($param['options']); |
|
5514 | 5514 | $InfoFieldList = explode(":", $param_list[0]); |
5515 | - $parentName=''; |
|
5516 | - $parentField=''; |
|
5515 | + $parentName = ''; |
|
5516 | + $parentField = ''; |
|
5517 | 5517 | // 0 : tableName |
5518 | 5518 | // 1 : label field name |
5519 | 5519 | // 2 : key fields name (if differ of rowid) |
5520 | 5520 | // 3 : key field parent (for dependent lists) |
5521 | 5521 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
5522 | - $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
5522 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
5523 | 5523 | |
5524 | 5524 | |
5525 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
5525 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) |
|
5526 | 5526 | { |
5527 | 5527 | if (strpos($InfoFieldList[4], 'extra.') !== false) |
5528 | 5528 | { |
5529 | - $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
5529 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
5530 | 5530 | } else { |
5531 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
5531 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
5532 | 5532 | } |
5533 | 5533 | } |
5534 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
5534 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) |
|
5535 | 5535 | { |
5536 | 5536 | list($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
5537 | - $keyList.= ', '.$parentField; |
|
5537 | + $keyList .= ', '.$parentField; |
|
5538 | 5538 | } |
5539 | 5539 | |
5540 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
5540 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
5541 | 5541 | if (is_array($fields_label)) |
5542 | 5542 | { |
5543 | - $keyList .=', '; |
|
5543 | + $keyList .= ', '; |
|
5544 | 5544 | $keyList .= implode(', ', $fields_label); |
5545 | 5545 | } |
5546 | 5546 | |
5547 | - $sqlwhere=''; |
|
5547 | + $sqlwhere = ''; |
|
5548 | 5548 | $sql = 'SELECT '.$keyList; |
5549 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
5549 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
5550 | 5550 | if (!empty($InfoFieldList[4])) |
5551 | 5551 | { |
5552 | 5552 | // can use SELECT request |
5553 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
5554 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
5553 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
5554 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
5555 | 5555 | } |
5556 | 5556 | |
5557 | 5557 | // current object id can be use into filter |
5558 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
5559 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
5558 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
5559 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
5560 | 5560 | } else { |
5561 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
5561 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
5562 | 5562 | } |
5563 | 5563 | //We have to join on extrafield table |
5564 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
5564 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
5565 | 5565 | { |
5566 | - $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
5567 | - $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
5566 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
5567 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
5568 | 5568 | } |
5569 | 5569 | else |
5570 | 5570 | { |
5571 | - $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
5571 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
5572 | 5572 | } |
5573 | 5573 | } |
5574 | 5574 | else |
5575 | 5575 | { |
5576 | - $sqlwhere.= ' WHERE 1=1'; |
|
5576 | + $sqlwhere .= ' WHERE 1=1'; |
|
5577 | 5577 | } |
5578 | 5578 | // Some tables may have field, some other not. For the moment we disable it. |
5579 | - if (in_array($InfoFieldList[0],array('tablewithentity'))) |
|
5579 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
5580 | 5580 | { |
5581 | - $sqlwhere.= ' AND entity = '.$conf->entity; |
|
5581 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
5582 | 5582 | } |
5583 | - $sql.=$sqlwhere; |
|
5583 | + $sql .= $sqlwhere; |
|
5584 | 5584 | //print $sql; |
5585 | 5585 | |
5586 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label); |
|
5586 | + $sql .= ' ORDER BY '.implode(', ', $fields_label); |
|
5587 | 5587 | |
5588 | 5588 | dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
5589 | 5589 | $resql = $this->db->query($sql); |
5590 | 5590 | if ($resql) |
5591 | 5591 | { |
5592 | - $out.='<option value="0"> </option>'; |
|
5592 | + $out .= '<option value="0"> </option>'; |
|
5593 | 5593 | $num = $this->db->num_rows($resql); |
5594 | 5594 | $i = 0; |
5595 | 5595 | while ($i < $num) |
5596 | 5596 | { |
5597 | - $labeltoshow=''; |
|
5597 | + $labeltoshow = ''; |
|
5598 | 5598 | $obj = $this->db->fetch_object($resql); |
5599 | 5599 | |
5600 | 5600 | // Several field into label (eq table:code|libelle:rowid) |
5601 | 5601 | $notrans = false; |
5602 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
5602 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
5603 | 5603 | if (is_array($fields_label)) |
5604 | 5604 | { |
5605 | 5605 | $notrans = true; |
5606 | 5606 | foreach ($fields_label as $field_toshow) |
5607 | 5607 | { |
5608 | - $labeltoshow.= $obj->$field_toshow.' '; |
|
5608 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
5609 | 5609 | } |
5610 | 5610 | } |
5611 | 5611 | else |
5612 | 5612 | { |
5613 | - $labeltoshow=$obj->{$InfoFieldList[1]}; |
|
5613 | + $labeltoshow = $obj->{$InfoFieldList[1]}; |
|
5614 | 5614 | } |
5615 | - $labeltoshow=dol_trunc($labeltoshow,45); |
|
5615 | + $labeltoshow = dol_trunc($labeltoshow, 45); |
|
5616 | 5616 | |
5617 | 5617 | if ($value == $obj->rowid) |
5618 | 5618 | { |
5619 | 5619 | foreach ($fields_label as $field_toshow) |
5620 | 5620 | { |
5621 | - $translabel=$langs->trans($obj->$field_toshow); |
|
5622 | - if ($translabel!=$obj->$field_toshow) { |
|
5623 | - $labeltoshow=dol_trunc($translabel,18).' '; |
|
5624 | - }else { |
|
5625 | - $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
5621 | + $translabel = $langs->trans($obj->$field_toshow); |
|
5622 | + if ($translabel != $obj->$field_toshow) { |
|
5623 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
5624 | + } else { |
|
5625 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
5626 | 5626 | } |
5627 | 5627 | } |
5628 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
5628 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
5629 | 5629 | } |
5630 | 5630 | else |
5631 | 5631 | { |
5632 | - if (! $notrans) |
|
5632 | + if (!$notrans) |
|
5633 | 5633 | { |
5634 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
5635 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
5636 | - $labeltoshow=dol_trunc($translabel,18); |
|
5634 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
5635 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
5636 | + $labeltoshow = dol_trunc($translabel, 18); |
|
5637 | 5637 | } |
5638 | 5638 | else { |
5639 | - $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18); |
|
5639 | + $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]},18); |
|
5640 | 5640 | } |
5641 | 5641 | } |
5642 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
5643 | - if ($value==$obj->rowid) |
|
5642 | + if (empty($labeltoshow)) $labeltoshow = '(not defined)'; |
|
5643 | + if ($value == $obj->rowid) |
|
5644 | 5644 | { |
5645 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
5645 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
5646 | 5646 | } |
5647 | 5647 | |
5648 | 5648 | if (!empty($InfoFieldList[3]) && $parentField) |
@@ -5650,10 +5650,10 @@ discard block |
||
5650 | 5650 | $parent = $parentName.':'.$obj->{$parentField}; |
5651 | 5651 | } |
5652 | 5652 | |
5653 | - $out.='<option value="'.$obj->rowid.'"'; |
|
5654 | - $out.= ($value==$obj->rowid?' selected':''); |
|
5655 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
5656 | - $out.='>'.$labeltoshow.'</option>'; |
|
5653 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
5654 | + $out .= ($value == $obj->rowid ? ' selected' : ''); |
|
5655 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
5656 | + $out .= '>'.$labeltoshow.'</option>'; |
|
5657 | 5657 | } |
5658 | 5658 | |
5659 | 5659 | $i++; |
@@ -5664,23 +5664,23 @@ discard block |
||
5664 | 5664 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
5665 | 5665 | } |
5666 | 5666 | } |
5667 | - $out.='</select>'; |
|
5667 | + $out .= '</select>'; |
|
5668 | 5668 | } |
5669 | 5669 | elseif ($type == 'checkbox') |
5670 | 5670 | { |
5671 | - $value_arr=explode(',',$value); |
|
5672 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
5671 | + $value_arr = explode(',', $value); |
|
5672 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
5673 | 5673 | } |
5674 | 5674 | elseif ($type == 'radio') |
5675 | 5675 | { |
5676 | - $out=''; |
|
5676 | + $out = ''; |
|
5677 | 5677 | foreach ($param['options'] as $keyopt => $val) |
5678 | 5678 | { |
5679 | - $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
5680 | - $out.=' value="'.$keyopt.'"'; |
|
5681 | - $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
5682 | - $out.= ($value==$keyopt?'checked':''); |
|
5683 | - $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
5679 | + $out .= '<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : ''); |
|
5680 | + $out .= ' value="'.$keyopt.'"'; |
|
5681 | + $out .= ' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
5682 | + $out .= ($value == $keyopt ? 'checked' : ''); |
|
5683 | + $out .= '/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
5684 | 5684 | } |
5685 | 5685 | } |
5686 | 5686 | elseif ($type == 'chkbxlst') |
@@ -5695,24 +5695,24 @@ discard block |
||
5695 | 5695 | if (is_array($param['options'])) { |
5696 | 5696 | $param_list = array_keys($param['options']); |
5697 | 5697 | $InfoFieldList = explode(":", $param_list[0]); |
5698 | - $parentName=''; |
|
5699 | - $parentField=''; |
|
5698 | + $parentName = ''; |
|
5699 | + $parentField = ''; |
|
5700 | 5700 | // 0 : tableName |
5701 | 5701 | // 1 : label field name |
5702 | 5702 | // 2 : key fields name (if differ of rowid) |
5703 | 5703 | // 3 : key field parent (for dependent lists) |
5704 | 5704 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
5705 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
5705 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
5706 | 5706 | |
5707 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) { |
|
5708 | - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]); |
|
5709 | - $keyList .= ', ' . $parentField; |
|
5707 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { |
|
5708 | + list ($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
|
5709 | + $keyList .= ', '.$parentField; |
|
5710 | 5710 | } |
5711 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) { |
|
5711 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { |
|
5712 | 5712 | if (strpos($InfoFieldList[4], 'extra.') !== false) { |
5713 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
5713 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
5714 | 5714 | } else { |
5715 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
5715 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
5716 | 5716 | } |
5717 | 5717 | } |
5718 | 5718 | |
@@ -5723,50 +5723,50 @@ discard block |
||
5723 | 5723 | } |
5724 | 5724 | |
5725 | 5725 | $sqlwhere = ''; |
5726 | - $sql = 'SELECT ' . $keyList; |
|
5727 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
5728 | - if (! empty($InfoFieldList[4])) { |
|
5726 | + $sql = 'SELECT '.$keyList; |
|
5727 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
5728 | + if (!empty($InfoFieldList[4])) { |
|
5729 | 5729 | |
5730 | 5730 | // can use SELECT request |
5731 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
5732 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
5731 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
5732 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
5733 | 5733 | } |
5734 | 5734 | |
5735 | 5735 | // current object id can be use into filter |
5736 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
5737 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
5736 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
5737 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
5738 | 5738 | } else { |
5739 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
5739 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
5740 | 5740 | } |
5741 | 5741 | |
5742 | 5742 | // We have to join on extrafield table |
5743 | 5743 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
5744 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
5745 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
5744 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
5745 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
5746 | 5746 | } else { |
5747 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
5747 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
5748 | 5748 | } |
5749 | 5749 | } else { |
5750 | 5750 | $sqlwhere .= ' WHERE 1=1'; |
5751 | 5751 | } |
5752 | 5752 | // Some tables may have field, some other not. For the moment we disable it. |
5753 | - if (in_array($InfoFieldList[0], array ('tablewithentity'))) |
|
5753 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
5754 | 5754 | { |
5755 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
5755 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
5756 | 5756 | } |
5757 | 5757 | // $sql.=preg_replace('/^ AND /','',$sqlwhere); |
5758 | 5758 | // print $sql; |
5759 | 5759 | |
5760 | 5760 | $sql .= $sqlwhere; |
5761 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
5761 | + dol_syslog(get_class($this).'::showInputField type=chkbxlst', LOG_DEBUG); |
|
5762 | 5762 | $resql = $this->db->query($sql); |
5763 | 5763 | if ($resql) { |
5764 | 5764 | $num = $this->db->num_rows($resql); |
5765 | 5765 | $i = 0; |
5766 | 5766 | |
5767 | - $data=array(); |
|
5767 | + $data = array(); |
|
5768 | 5768 | |
5769 | - while ( $i < $num ) { |
|
5769 | + while ($i < $num) { |
|
5770 | 5770 | $labeltoshow = ''; |
5771 | 5771 | $obj = $this->db->fetch_object($resql); |
5772 | 5772 | |
@@ -5775,8 +5775,8 @@ discard block |
||
5775 | 5775 | $fields_label = explode('|', $InfoFieldList[1]); |
5776 | 5776 | if (is_array($fields_label)) { |
5777 | 5777 | $notrans = true; |
5778 | - foreach ( $fields_label as $field_toshow ) { |
|
5779 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
5778 | + foreach ($fields_label as $field_toshow) { |
|
5779 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
5780 | 5780 | } |
5781 | 5781 | } else { |
5782 | 5782 | $labeltoshow = $obj->{$InfoFieldList[1]}; |
@@ -5784,18 +5784,18 @@ discard block |
||
5784 | 5784 | $labeltoshow = dol_trunc($labeltoshow, 45); |
5785 | 5785 | |
5786 | 5786 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
5787 | - foreach ( $fields_label as $field_toshow ) { |
|
5787 | + foreach ($fields_label as $field_toshow) { |
|
5788 | 5788 | $translabel = $langs->trans($obj->$field_toshow); |
5789 | 5789 | if ($translabel != $obj->$field_toshow) { |
5790 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
5790 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
5791 | 5791 | } else { |
5792 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
5792 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
5793 | 5793 | } |
5794 | 5794 | } |
5795 | 5795 | |
5796 | - $data[$obj->rowid]=$labeltoshow; |
|
5796 | + $data[$obj->rowid] = $labeltoshow; |
|
5797 | 5797 | } else { |
5798 | - if (! $notrans) { |
|
5798 | + if (!$notrans) { |
|
5799 | 5799 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
5800 | 5800 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
5801 | 5801 | $labeltoshow = dol_trunc($translabel, 18); |
@@ -5807,67 +5807,67 @@ discard block |
||
5807 | 5807 | $labeltoshow = '(not defined)'; |
5808 | 5808 | |
5809 | 5809 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
5810 | - $data[$obj->rowid]=$labeltoshow; |
|
5810 | + $data[$obj->rowid] = $labeltoshow; |
|
5811 | 5811 | } |
5812 | 5812 | |
5813 | - if (! empty($InfoFieldList[3]) && $parentField) { |
|
5814 | - $parent = $parentName . ':' . $obj->{$parentField}; |
|
5813 | + if (!empty($InfoFieldList[3]) && $parentField) { |
|
5814 | + $parent = $parentName.':'.$obj->{$parentField}; |
|
5815 | 5815 | } |
5816 | 5816 | |
5817 | - $data[$obj->rowid]=$labeltoshow; |
|
5817 | + $data[$obj->rowid] = $labeltoshow; |
|
5818 | 5818 | } |
5819 | 5819 | |
5820 | - $i ++; |
|
5820 | + $i++; |
|
5821 | 5821 | } |
5822 | 5822 | $this->db->free($resql); |
5823 | 5823 | |
5824 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
5824 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
5825 | 5825 | } else { |
5826 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
5826 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
5827 | 5827 | } |
5828 | 5828 | } |
5829 | 5829 | } |
5830 | 5830 | elseif ($type == 'link') |
5831 | 5831 | { |
5832 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
5833 | - $showempty=(($required && $default != '')?0:1); |
|
5834 | - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
5832 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
5833 | + $showempty = (($required && $default != '') ? 0 : 1); |
|
5834 | + $out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
5835 | 5835 | if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
5836 | 5836 | { |
5837 | - list($class,$classfile)=explode(':',$param_list[0]); |
|
5838 | - if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
5839 | - else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
5840 | - $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
5837 | + list($class, $classfile) = explode(':', $param_list[0]); |
|
5838 | + if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path = dol_buildpath(dirname(dirname($classfile)).'/card.php', 1); |
|
5839 | + else $url_path = dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php', 1); |
|
5840 | + $out .= '<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
5841 | 5841 | // TODO Add Javascript code to add input fields contents to new elements urls |
5842 | 5842 | } |
5843 | 5843 | } |
5844 | 5844 | elseif ($type == 'password') |
5845 | 5845 | { |
5846 | 5846 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
5847 | - $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
5847 | + $out = '<input type="'.($keyprefix == 'search_' ? 'text' : 'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>'; |
|
5848 | 5848 | } |
5849 | 5849 | elseif ($type == 'array') |
5850 | 5850 | { |
5851 | 5851 | $newval = $val; |
5852 | 5852 | $newval['type'] = 'varchar(256)'; |
5853 | 5853 | |
5854 | - $out=''; |
|
5854 | + $out = ''; |
|
5855 | 5855 | |
5856 | 5856 | $inputs = array(); |
5857 | - if(! empty($value)) { |
|
5858 | - foreach($value as $option) { |
|
5859 | - $out.= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
5860 | - $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
5857 | + if (!empty($value)) { |
|
5858 | + foreach ($value as $option) { |
|
5859 | + $out .= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
5860 | + $out .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
5861 | 5861 | } |
5862 | 5862 | } |
5863 | 5863 | |
5864 | - $out.= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
5864 | + $out .= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
5865 | 5865 | |
5866 | 5866 | $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
5867 | - $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
5867 | + $newInput .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
5868 | 5868 | |
5869 | - if(! empty($conf->use_javascript_ajax)) { |
|
5870 | - $out.= ' |
|
5869 | + if (!empty($conf->use_javascript_ajax)) { |
|
5870 | + $out .= ' |
|
5871 | 5871 | <script type="text/javascript"> |
5872 | 5872 | $(document).ready(function() { |
5873 | 5873 | $("a#'.dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() { |
@@ -5882,7 +5882,7 @@ discard block |
||
5882 | 5882 | } |
5883 | 5883 | } |
5884 | 5884 | if (!empty($hidden)) { |
5885 | - $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
5885 | + $out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
5886 | 5886 | } |
5887 | 5887 | /* Add comments |
5888 | 5888 | if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
@@ -5904,14 +5904,14 @@ discard block |
||
5904 | 5904 | * @param mixed $showsize Value for css to define size. May also be a numeric. |
5905 | 5905 | * @return string |
5906 | 5906 | */ |
5907 | - function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
5907 | + function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $showsize = 0) |
|
5908 | 5908 | { |
5909 | - global $conf,$langs,$form; |
|
5909 | + global $conf, $langs, $form; |
|
5910 | 5910 | |
5911 | - if (! is_object($form)) |
|
5911 | + if (!is_object($form)) |
|
5912 | 5912 | { |
5913 | 5913 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
5914 | - $form=new Form($this->db); |
|
5914 | + $form = new Form($this->db); |
|
5915 | 5915 | } |
5916 | 5916 | |
5917 | 5917 | $objectid = $this->id; |
@@ -5922,28 +5922,28 @@ discard block |
||
5922 | 5922 | // Convert var to be able to share same code than showOutputField of extrafields |
5923 | 5923 | if (preg_match('/varchar\((\d+)\)/', $type, $reg)) |
5924 | 5924 | { |
5925 | - $type = 'varchar'; // convert varchar(xx) int varchar |
|
5925 | + $type = 'varchar'; // convert varchar(xx) int varchar |
|
5926 | 5926 | $size = $reg[1]; |
5927 | 5927 | } |
5928 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
5929 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
5930 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; |
|
5928 | + elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
5929 | + if (is_array($val['arrayofkeyval'])) $type = 'select'; |
|
5930 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type = 'link'; |
|
5931 | 5931 | |
5932 | - $default=$val['default']; |
|
5933 | - $computed=$val['computed']; |
|
5934 | - $unique=$val['unique']; |
|
5935 | - $required=$val['required']; |
|
5936 | - $param=$val['param']; |
|
5932 | + $default = $val['default']; |
|
5933 | + $computed = $val['computed']; |
|
5934 | + $unique = $val['unique']; |
|
5935 | + $required = $val['required']; |
|
5936 | + $param = $val['param']; |
|
5937 | 5937 | if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
5938 | 5938 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) |
5939 | 5939 | { |
5940 | - $type='link'; |
|
5941 | - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
5940 | + $type = 'link'; |
|
5941 | + $param['options'] = array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
5942 | 5942 | } |
5943 | - $langfile=$val['langfile']; |
|
5944 | - $list=$val['list']; |
|
5945 | - $help=$val['help']; |
|
5946 | - $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) |
|
5943 | + $langfile = $val['langfile']; |
|
5944 | + $list = $val['list']; |
|
5945 | + $help = $val['help']; |
|
5946 | + $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) |
|
5947 | 5947 | |
5948 | 5948 | if ($hidden) return ''; |
5949 | 5949 | |
@@ -5967,18 +5967,18 @@ discard block |
||
5967 | 5967 | //$showsize=19; |
5968 | 5968 | $showsize = 'minwidth200imp'; |
5969 | 5969 | } |
5970 | - elseif (in_array($type,array('int','double','price'))) |
|
5970 | + elseif (in_array($type, array('int', 'double', 'price'))) |
|
5971 | 5971 | { |
5972 | 5972 | //$showsize=10; |
5973 | 5973 | $showsize = 'maxwidth75'; |
5974 | 5974 | } |
5975 | 5975 | elseif ($type == 'url') |
5976 | 5976 | { |
5977 | - $showsize='minwidth400'; |
|
5977 | + $showsize = 'minwidth400'; |
|
5978 | 5978 | } |
5979 | 5979 | elseif ($type == 'boolean') |
5980 | 5980 | { |
5981 | - $showsize=''; |
|
5981 | + $showsize = ''; |
|
5982 | 5982 | } |
5983 | 5983 | else |
5984 | 5984 | { |
@@ -5999,90 +5999,90 @@ discard block |
||
5999 | 5999 | } |
6000 | 6000 | |
6001 | 6001 | // Format output value differently according to properties of field |
6002 | - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
6003 | - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
6002 | + if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value = $this->getNomUrl(1, '', 0, '', 1); |
|
6003 | + elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value = $this->getLibStatut(3); |
|
6004 | 6004 | elseif ($type == 'date') |
6005 | 6005 | { |
6006 | - if(! empty($value)) { |
|
6007 | - $value=dol_print_date($value,'day'); |
|
6006 | + if (!empty($value)) { |
|
6007 | + $value = dol_print_date($value, 'day'); |
|
6008 | 6008 | } else { |
6009 | - $value=''; |
|
6009 | + $value = ''; |
|
6010 | 6010 | } |
6011 | 6011 | } |
6012 | 6012 | elseif ($type == 'datetime') |
6013 | 6013 | { |
6014 | - if(! empty($value)) { |
|
6015 | - $value=dol_print_date($value,'dayhour'); |
|
6014 | + if (!empty($value)) { |
|
6015 | + $value = dol_print_date($value, 'dayhour'); |
|
6016 | 6016 | } else { |
6017 | - $value=''; |
|
6017 | + $value = ''; |
|
6018 | 6018 | } |
6019 | 6019 | } |
6020 | 6020 | elseif ($type == 'double') |
6021 | 6021 | { |
6022 | 6022 | if (!empty($value)) { |
6023 | - $value=price($value); |
|
6023 | + $value = price($value); |
|
6024 | 6024 | } |
6025 | 6025 | } |
6026 | 6026 | elseif ($type == 'boolean') |
6027 | 6027 | { |
6028 | - $checked=''; |
|
6028 | + $checked = ''; |
|
6029 | 6029 | if (!empty($value)) { |
6030 | - $checked=' checked '; |
|
6030 | + $checked = ' checked '; |
|
6031 | 6031 | } |
6032 | - $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
6032 | + $value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>'; |
|
6033 | 6033 | } |
6034 | 6034 | elseif ($type == 'mail') |
6035 | 6035 | { |
6036 | - $value=dol_print_email($value,0,0,0,64,1,1); |
|
6036 | + $value = dol_print_email($value, 0, 0, 0, 64, 1, 1); |
|
6037 | 6037 | } |
6038 | 6038 | elseif ($type == 'url') |
6039 | 6039 | { |
6040 | - $value=dol_print_url($value,'_blank',32,1); |
|
6040 | + $value = dol_print_url($value, '_blank', 32, 1); |
|
6041 | 6041 | } |
6042 | 6042 | elseif ($type == 'phone') |
6043 | 6043 | { |
6044 | - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
6044 | + $value = dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
6045 | 6045 | } |
6046 | 6046 | elseif ($type == 'price') |
6047 | 6047 | { |
6048 | - $value=price($value,0,$langs,0,0,-1,$conf->currency); |
|
6048 | + $value = price($value, 0, $langs, 0, 0, -1, $conf->currency); |
|
6049 | 6049 | } |
6050 | 6050 | elseif ($type == 'select') |
6051 | 6051 | { |
6052 | - $value=$param['options'][$value]; |
|
6052 | + $value = $param['options'][$value]; |
|
6053 | 6053 | } |
6054 | 6054 | elseif ($type == 'sellist') |
6055 | 6055 | { |
6056 | - $param_list=array_keys($param['options']); |
|
6056 | + $param_list = array_keys($param['options']); |
|
6057 | 6057 | $InfoFieldList = explode(":", $param_list[0]); |
6058 | 6058 | |
6059 | - $selectkey="rowid"; |
|
6060 | - $keyList='rowid'; |
|
6059 | + $selectkey = "rowid"; |
|
6060 | + $keyList = 'rowid'; |
|
6061 | 6061 | |
6062 | - if (count($InfoFieldList)>=3) |
|
6062 | + if (count($InfoFieldList) >= 3) |
|
6063 | 6063 | { |
6064 | 6064 | $selectkey = $InfoFieldList[2]; |
6065 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
6065 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
6066 | 6066 | } |
6067 | 6067 | |
6068 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
6069 | - if(is_array($fields_label)) { |
|
6070 | - $keyList .=', '; |
|
6068 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
6069 | + if (is_array($fields_label)) { |
|
6070 | + $keyList .= ', '; |
|
6071 | 6071 | $keyList .= implode(', ', $fields_label); |
6072 | 6072 | } |
6073 | 6073 | |
6074 | 6074 | $sql = 'SELECT '.$keyList; |
6075 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
6076 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
6075 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
6076 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
6077 | 6077 | { |
6078 | - $sql.= ' as main'; |
|
6078 | + $sql .= ' as main'; |
|
6079 | 6079 | } |
6080 | - if ($selectkey=='rowid' && empty($value)) { |
|
6081 | - $sql.= " WHERE ".$selectkey."=0"; |
|
6082 | - } elseif ($selectkey=='rowid') { |
|
6083 | - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
6084 | - }else { |
|
6085 | - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
6080 | + if ($selectkey == 'rowid' && empty($value)) { |
|
6081 | + $sql .= " WHERE ".$selectkey."=0"; |
|
6082 | + } elseif ($selectkey == 'rowid') { |
|
6083 | + $sql .= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
6084 | + } else { |
|
6085 | + $sql .= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
6086 | 6086 | } |
6087 | 6087 | |
6088 | 6088 | //$sql.= ' AND entity = '.$conf->entity; |
@@ -6091,38 +6091,38 @@ discard block |
||
6091 | 6091 | $resql = $this->db->query($sql); |
6092 | 6092 | if ($resql) |
6093 | 6093 | { |
6094 | - $value=''; // value was used, so now we reste it to use it to build final output |
|
6094 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
6095 | 6095 | |
6096 | 6096 | $obj = $this->db->fetch_object($resql); |
6097 | 6097 | |
6098 | 6098 | // Several field into label (eq table:code|libelle:rowid) |
6099 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
6099 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
6100 | 6100 | |
6101 | - if(is_array($fields_label) && count($fields_label)>1) |
|
6101 | + if (is_array($fields_label) && count($fields_label) > 1) |
|
6102 | 6102 | { |
6103 | 6103 | foreach ($fields_label as $field_toshow) |
6104 | 6104 | { |
6105 | - $translabel=''; |
|
6105 | + $translabel = ''; |
|
6106 | 6106 | if (!empty($obj->$field_toshow)) { |
6107 | - $translabel=$langs->trans($obj->$field_toshow); |
|
6107 | + $translabel = $langs->trans($obj->$field_toshow); |
|
6108 | 6108 | } |
6109 | - if ($translabel!=$field_toshow) { |
|
6110 | - $value.=dol_trunc($translabel,18).' '; |
|
6111 | - }else { |
|
6112 | - $value.=$obj->$field_toshow.' '; |
|
6109 | + if ($translabel != $field_toshow) { |
|
6110 | + $value .= dol_trunc($translabel, 18).' '; |
|
6111 | + } else { |
|
6112 | + $value .= $obj->$field_toshow.' '; |
|
6113 | 6113 | } |
6114 | 6114 | } |
6115 | 6115 | } |
6116 | 6116 | else |
6117 | 6117 | { |
6118 | - $translabel=''; |
|
6118 | + $translabel = ''; |
|
6119 | 6119 | if (!empty($obj->{$InfoFieldList[1]})) { |
6120 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
6120 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
6121 | 6121 | } |
6122 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
6123 | - $value=dol_trunc($translabel,18); |
|
6124 | - }else { |
|
6125 | - $value=$obj->{$InfoFieldList[1]}; |
|
6122 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
6123 | + $value = dol_trunc($translabel, 18); |
|
6124 | + } else { |
|
6125 | + $value = $obj->{$InfoFieldList[1]}; |
|
6126 | 6126 | } |
6127 | 6127 | } |
6128 | 6128 | } |
@@ -6130,18 +6130,18 @@ discard block |
||
6130 | 6130 | } |
6131 | 6131 | elseif ($type == 'radio') |
6132 | 6132 | { |
6133 | - $value=$param['options'][$value]; |
|
6133 | + $value = $param['options'][$value]; |
|
6134 | 6134 | } |
6135 | 6135 | elseif ($type == 'checkbox') |
6136 | 6136 | { |
6137 | - $value_arr=explode(',',$value); |
|
6138 | - $value=''; |
|
6139 | - if (is_array($value_arr) && count($value_arr)>0) |
|
6137 | + $value_arr = explode(',', $value); |
|
6138 | + $value = ''; |
|
6139 | + if (is_array($value_arr) && count($value_arr) > 0) |
|
6140 | 6140 | { |
6141 | 6141 | foreach ($value_arr as $keyval=>$valueval) { |
6142 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
6142 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
6143 | 6143 | } |
6144 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
6144 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
6145 | 6145 | } |
6146 | 6146 | } |
6147 | 6147 | elseif ($type == 'chkbxlst') |
@@ -6156,7 +6156,7 @@ discard block |
||
6156 | 6156 | |
6157 | 6157 | if (count($InfoFieldList) >= 3) { |
6158 | 6158 | $selectkey = $InfoFieldList[2]; |
6159 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
6159 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
6160 | 6160 | } |
6161 | 6161 | |
6162 | 6162 | $fields_label = explode('|', $InfoFieldList[1]); |
@@ -6165,75 +6165,75 @@ discard block |
||
6165 | 6165 | $keyList .= implode(', ', $fields_label); |
6166 | 6166 | } |
6167 | 6167 | |
6168 | - $sql = 'SELECT ' . $keyList; |
|
6169 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
6168 | + $sql = 'SELECT '.$keyList; |
|
6169 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
6170 | 6170 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
6171 | 6171 | $sql .= ' as main'; |
6172 | 6172 | } |
6173 | 6173 | // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
6174 | 6174 | // $sql.= ' AND entity = '.$conf->entity; |
6175 | 6175 | |
6176 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
6176 | + dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); |
|
6177 | 6177 | $resql = $this->db->query($sql); |
6178 | 6178 | if ($resql) { |
6179 | 6179 | $value = ''; // value was used, so now we reste it to use it to build final output |
6180 | - $toprint=array(); |
|
6181 | - while ( $obj = $this->db->fetch_object($resql) ) { |
|
6180 | + $toprint = array(); |
|
6181 | + while ($obj = $this->db->fetch_object($resql)) { |
|
6182 | 6182 | |
6183 | 6183 | // Several field into label (eq table:code|libelle:rowid) |
6184 | 6184 | $fields_label = explode('|', $InfoFieldList[1]); |
6185 | 6185 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
6186 | 6186 | if (is_array($fields_label) && count($fields_label) > 1) { |
6187 | - foreach ( $fields_label as $field_toshow ) { |
|
6187 | + foreach ($fields_label as $field_toshow) { |
|
6188 | 6188 | $translabel = ''; |
6189 | - if (! empty($obj->$field_toshow)) { |
|
6189 | + if (!empty($obj->$field_toshow)) { |
|
6190 | 6190 | $translabel = $langs->trans($obj->$field_toshow); |
6191 | 6191 | } |
6192 | 6192 | if ($translabel != $field_toshow) { |
6193 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
6193 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
6194 | 6194 | } else { |
6195 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
6195 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
6196 | 6196 | } |
6197 | 6197 | } |
6198 | 6198 | } else { |
6199 | 6199 | $translabel = ''; |
6200 | - if (! empty($obj->{$InfoFieldList[1]})) { |
|
6200 | + if (!empty($obj->{$InfoFieldList[1]})) { |
|
6201 | 6201 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
6202 | 6202 | } |
6203 | 6203 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
6204 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
6204 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
6205 | 6205 | } else { |
6206 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
6206 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
6207 | 6207 | } |
6208 | 6208 | } |
6209 | 6209 | } |
6210 | 6210 | } |
6211 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
6211 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
6212 | 6212 | } else { |
6213 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
6213 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
6214 | 6214 | } |
6215 | 6215 | } |
6216 | 6216 | elseif ($type == 'link') |
6217 | 6217 | { |
6218 | - $out=''; |
|
6218 | + $out = ''; |
|
6219 | 6219 | |
6220 | 6220 | // only if something to display (perf) |
6221 | 6221 | if ($value) |
6222 | 6222 | { |
6223 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
6223 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
6224 | 6224 | |
6225 | 6225 | $InfoFieldList = explode(":", $param_list[0]); |
6226 | - $classname=$InfoFieldList[0]; |
|
6227 | - $classpath=$InfoFieldList[1]; |
|
6228 | - $getnomurlparam=(empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
6229 | - if (! empty($classpath)) |
|
6226 | + $classname = $InfoFieldList[0]; |
|
6227 | + $classpath = $InfoFieldList[1]; |
|
6228 | + $getnomurlparam = (empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
6229 | + if (!empty($classpath)) |
|
6230 | 6230 | { |
6231 | 6231 | dol_include_once($InfoFieldList[1]); |
6232 | 6232 | if ($classname && class_exists($classname)) |
6233 | 6233 | { |
6234 | 6234 | $object = new $classname($this->db); |
6235 | 6235 | $object->fetch($value); |
6236 | - $value=$object->getNomUrl($getnomurlparam); |
|
6236 | + $value = $object->getNomUrl($getnomurlparam); |
|
6237 | 6237 | } |
6238 | 6238 | } |
6239 | 6239 | else |
@@ -6242,15 +6242,15 @@ discard block |
||
6242 | 6242 | return 'Error bad setup of extrafield'; |
6243 | 6243 | } |
6244 | 6244 | } |
6245 | - else $value=''; |
|
6245 | + else $value = ''; |
|
6246 | 6246 | } |
6247 | 6247 | elseif ($type == 'text' || $type == 'html') |
6248 | 6248 | { |
6249 | - $value=dol_htmlentitiesbr($value); |
|
6249 | + $value = dol_htmlentitiesbr($value); |
|
6250 | 6250 | } |
6251 | 6251 | elseif ($type == 'password') |
6252 | 6252 | { |
6253 | - $value=preg_replace('/./i','*',$value); |
|
6253 | + $value = preg_replace('/./i', '*', $value); |
|
6254 | 6254 | } |
6255 | 6255 | elseif ($type == 'array') |
6256 | 6256 | { |
@@ -6258,7 +6258,7 @@ discard block |
||
6258 | 6258 | } |
6259 | 6259 | |
6260 | 6260 | //print $type.'-'.$size; |
6261 | - $out=$value; |
|
6261 | + $out = $value; |
|
6262 | 6262 | |
6263 | 6263 | return $out; |
6264 | 6264 | } |
@@ -6275,11 +6275,11 @@ discard block |
||
6275 | 6275 | * @param string $onetrtd All fields in same tr td |
6276 | 6276 | * @return string |
6277 | 6277 | */ |
6278 | - function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) |
|
6278 | + function showOptionals($extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0) |
|
6279 | 6279 | { |
6280 | 6280 | global $db, $conf, $langs, $action, $form; |
6281 | 6281 | |
6282 | - if (! is_object($form)) $form=new Form($db); |
|
6282 | + if (!is_object($form)) $form = new Form($db); |
|
6283 | 6283 | |
6284 | 6284 | $out = ''; |
6285 | 6285 | |
@@ -6290,10 +6290,10 @@ discard block |
||
6290 | 6290 | $out .= "\n"; |
6291 | 6291 | |
6292 | 6292 | $e = 0; |
6293 | - foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
6293 | + foreach ($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
6294 | 6294 | { |
6295 | 6295 | // Show only the key field in params |
6296 | - if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue; |
|
6296 | + if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) continue; |
|
6297 | 6297 | |
6298 | 6298 | $enabled = 1; |
6299 | 6299 | if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
@@ -6307,25 +6307,25 @@ discard block |
||
6307 | 6307 | $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
6308 | 6308 | } |
6309 | 6309 | |
6310 | - if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
6310 | + 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 | 6311 | if (empty($perms)) continue; |
6312 | 6312 | |
6313 | 6313 | // Load language if required |
6314 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
6314 | + if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
6315 | 6315 | |
6316 | - $colspan='3'; |
|
6317 | - if (is_array($params) && count($params)>0) { |
|
6318 | - if (array_key_exists('colspan',$params)) { |
|
6319 | - $colspan=$params['colspan']; |
|
6316 | + $colspan = '3'; |
|
6317 | + if (is_array($params) && count($params) > 0) { |
|
6318 | + if (array_key_exists('colspan', $params)) { |
|
6319 | + $colspan = $params['colspan']; |
|
6320 | 6320 | } |
6321 | 6321 | } |
6322 | 6322 | |
6323 | - switch($mode) { |
|
6323 | + switch ($mode) { |
|
6324 | 6324 | case "view": |
6325 | - $value=$this->array_options["options_".$key.$keysuffix]; |
|
6325 | + $value = $this->array_options["options_".$key.$keysuffix]; |
|
6326 | 6326 | break; |
6327 | 6327 | case "edit": |
6328 | - $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
6328 | + $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
6329 | 6329 | // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc') |
6330 | 6330 | if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
6331 | 6331 | { |
@@ -6336,7 +6336,7 @@ discard block |
||
6336 | 6336 | $value = $getposttemp; |
6337 | 6337 | } |
6338 | 6338 | } else { |
6339 | - $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
6339 | + $value = $this->array_options["options_".$key]; // No GET, no POST, no default value, so we take value of object. |
|
6340 | 6340 | } |
6341 | 6341 | //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
6342 | 6342 | break; |
@@ -6348,11 +6348,11 @@ discard block |
||
6348 | 6348 | } |
6349 | 6349 | else |
6350 | 6350 | { |
6351 | - $csstyle=''; |
|
6352 | - $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
6353 | - if (is_array($params) && count($params)>0) { |
|
6354 | - if (array_key_exists('style',$params)) { |
|
6355 | - $csstyle=$params['style']; |
|
6351 | + $csstyle = ''; |
|
6352 | + $class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
6353 | + if (is_array($params) && count($params) > 0) { |
|
6354 | + if (array_key_exists('style', $params)) { |
|
6355 | + $csstyle = $params['style']; |
|
6356 | 6356 | } |
6357 | 6357 | } |
6358 | 6358 | |
@@ -6365,43 +6365,43 @@ discard block |
||
6365 | 6365 | |
6366 | 6366 | $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
6367 | 6367 | |
6368 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
6368 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
6369 | 6369 | { |
6370 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; } |
|
6370 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan = '0'; } |
|
6371 | 6371 | } |
6372 | 6372 | |
6373 | 6373 | if ($action == 'selectlines') { $colspan++; } |
6374 | 6374 | |
6375 | 6375 | // Convert date into timestamp format (value in memory must be a timestamp) |
6376 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime'))) |
|
6376 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime'))) |
|
6377 | 6377 | { |
6378 | - $datenotinstring = $this->array_options['options_' . $key]; |
|
6379 | - if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
6378 | + $datenotinstring = $this->array_options['options_'.$key]; |
|
6379 | + if (!is_numeric($this->array_options['options_'.$key])) // For backward compatibility |
|
6380 | 6380 | { |
6381 | 6381 | $datenotinstring = $this->db->jdate($datenotinstring); |
6382 | 6382 | } |
6383 | - $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; |
|
6383 | + $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 | 6384 | } |
6385 | 6385 | // Convert float submited string into real php numeric (value in memory must be a php numeric) |
6386 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double'))) |
|
6386 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double'))) |
|
6387 | 6387 | { |
6388 | - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)):$this->array_options['options_'.$key]; |
|
6388 | + $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)) : $this->array_options['options_'.$key]; |
|
6389 | 6389 | } |
6390 | 6390 | |
6391 | 6391 | $labeltoshow = $langs->trans($label); |
6392 | 6392 | |
6393 | 6393 | $out .= '<td class="titlefield'; |
6394 | - if (GETPOST('action','none') == 'create') $out.='create'; |
|
6395 | - if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
6394 | + if (GETPOST('action', 'none') == 'create') $out .= 'create'; |
|
6395 | + if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
6396 | 6396 | $out .= '">'; |
6397 | - if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
6397 | + if (!empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
6398 | 6398 | else $out .= $labeltoshow; |
6399 | 6399 | $out .= '</td>'; |
6400 | 6400 | |
6401 | 6401 | $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
6402 | - $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
6402 | + $out .= '<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan ? ' colspan="'.$colspan.'"' : '').'>'; |
|
6403 | 6403 | |
6404 | - switch($mode) { |
|
6404 | + switch ($mode) { |
|
6405 | 6405 | case "view": |
6406 | 6406 | $out .= $extrafields->showOutputField($key, $value); |
6407 | 6407 | break; |
@@ -6412,14 +6412,14 @@ discard block |
||
6412 | 6412 | |
6413 | 6413 | $out .= '</td>'; |
6414 | 6414 | |
6415 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
6415 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
6416 | 6416 | else $out .= '</tr>'; |
6417 | 6417 | $e++; |
6418 | 6418 | } |
6419 | 6419 | } |
6420 | 6420 | $out .= "\n"; |
6421 | 6421 | // Add code to manage list depending on others |
6422 | - if (! empty($conf->use_javascript_ajax)) { |
|
6422 | + if (!empty($conf->use_javascript_ajax)) { |
|
6423 | 6423 | $out .= ' |
6424 | 6424 | <script type="text/javascript"> |
6425 | 6425 | jQuery(document).ready(function() { |
@@ -6465,7 +6465,7 @@ discard block |
||
6465 | 6465 | global $user; |
6466 | 6466 | |
6467 | 6467 | $element = $this->element; |
6468 | - if ($element == 'facturerec') $element='facture'; |
|
6468 | + if ($element == 'facturerec') $element = 'facture'; |
|
6469 | 6469 | |
6470 | 6470 | return $user->rights->{$element}; |
6471 | 6471 | } |
@@ -6482,15 +6482,15 @@ discard block |
||
6482 | 6482 | * @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) |
6483 | 6483 | * @return bool True if success, False if error |
6484 | 6484 | */ |
6485 | - public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
6485 | + public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) |
|
6486 | 6486 | { |
6487 | 6487 | foreach ($tables as $table) |
6488 | 6488 | { |
6489 | 6489 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
6490 | 6490 | |
6491 | - if (! $db->query($sql)) |
|
6491 | + if (!$db->query($sql)) |
|
6492 | 6492 | { |
6493 | - 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. |
|
6493 | + 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 | 6494 | //$this->errors = $db->lasterror(); |
6495 | 6495 | return false; |
6496 | 6496 | } |
@@ -6524,7 +6524,7 @@ discard block |
||
6524 | 6524 | else |
6525 | 6525 | { |
6526 | 6526 | // Get cost price for margin calculation |
6527 | - if (! empty($fk_product)) |
|
6527 | + if (!empty($fk_product)) |
|
6528 | 6528 | { |
6529 | 6529 | if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') |
6530 | 6530 | { |
@@ -6561,7 +6561,7 @@ discard block |
||
6561 | 6561 | } |
6562 | 6562 | } |
6563 | 6563 | |
6564 | - if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice'))) |
|
6564 | + if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1', 'pmp', 'costprice'))) |
|
6565 | 6565 | { |
6566 | 6566 | require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
6567 | 6567 | $productFournisseur = new ProductFournisseur($this->db); |
@@ -6598,18 +6598,18 @@ discard block |
||
6598 | 6598 | * @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead) |
6599 | 6599 | * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto |
6600 | 6600 | */ |
6601 | - 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) |
|
6601 | + 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 | 6602 | { |
6603 | 6603 | // phpcs:enable |
6604 | - global $conf,$user,$langs; |
|
6604 | + global $conf, $user, $langs; |
|
6605 | 6605 | |
6606 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; |
|
6607 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; |
|
6606 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
6607 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
6608 | 6608 | |
6609 | - $sortfield='position_name'; |
|
6610 | - $sortorder='asc'; |
|
6609 | + $sortfield = 'position_name'; |
|
6610 | + $sortorder = 'asc'; |
|
6611 | 6611 | |
6612 | - $dir = $sdir . '/'; |
|
6612 | + $dir = $sdir.'/'; |
|
6613 | 6613 | $pdir = '/'; |
6614 | 6614 | if ($modulepart == 'ticket') |
6615 | 6615 | { |
@@ -6623,28 +6623,28 @@ discard block |
||
6623 | 6623 | } |
6624 | 6624 | |
6625 | 6625 | // For backward compatibility |
6626 | - if ($modulepart == 'product' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
6626 | + if ($modulepart == 'product' && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
6627 | 6627 | { |
6628 | - $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
6629 | - $pdir = '/' . get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
6628 | + $dir = $sdir.'/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; |
|
6629 | + $pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; |
|
6630 | 6630 | } |
6631 | 6631 | |
6632 | 6632 | // Defined relative dir to DOL_DATA_ROOT |
6633 | 6633 | $relativedir = ''; |
6634 | 6634 | if ($dir) |
6635 | 6635 | { |
6636 | - $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir); |
|
6637 | - $relativedir = preg_replace('/^[\\/]/','',$relativedir); |
|
6638 | - $relativedir = preg_replace('/[\\/]$/','',$relativedir); |
|
6636 | + $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir); |
|
6637 | + $relativedir = preg_replace('/^[\\/]/', '', $relativedir); |
|
6638 | + $relativedir = preg_replace('/[\\/]$/', '', $relativedir); |
|
6639 | 6639 | } |
6640 | 6640 | |
6641 | 6641 | $dirthumb = $dir.'thumbs/'; |
6642 | 6642 | $pdirthumb = $pdir.'thumbs/'; |
6643 | 6643 | |
6644 | - $return ='<!-- Photo -->'."\n"; |
|
6645 | - $nbphoto=0; |
|
6644 | + $return = '<!-- Photo -->'."\n"; |
|
6645 | + $nbphoto = 0; |
|
6646 | 6646 | |
6647 | - $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
6647 | + $filearray = dol_dir_list($dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); |
|
6648 | 6648 | |
6649 | 6649 | /*if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs |
6650 | 6650 | { |
@@ -6658,12 +6658,12 @@ discard block |
||
6658 | 6658 | { |
6659 | 6659 | if ($sortfield && $sortorder) |
6660 | 6660 | { |
6661 | - $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
6661 | + $filearray = dol_sort_array($filearray, $sortfield, $sortorder); |
|
6662 | 6662 | } |
6663 | 6663 | |
6664 | - foreach($filearray as $key => $val) |
|
6664 | + foreach ($filearray as $key => $val) |
|
6665 | 6665 | { |
6666 | - $photo=''; |
|
6666 | + $photo = ''; |
|
6667 | 6667 | $file = $val['name']; |
6668 | 6668 | |
6669 | 6669 | //if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory |
@@ -6678,36 +6678,36 @@ discard block |
||
6678 | 6678 | if ($size == 1 || $size == 'small') { // Format vignette |
6679 | 6679 | |
6680 | 6680 | // Find name of thumb file |
6681 | - $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
|
6682 | - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
6681 | + $photo_vignette = basename(getImageFileNameForSize($dir.$file, '_small')); |
|
6682 | + if (!dol_is_file($dirthumb.$photo_vignette)) $photo_vignette = ''; |
|
6683 | 6683 | |
6684 | 6684 | // Get filesize of original file |
6685 | - $imgarray=dol_getImageSize($dir.$photo); |
|
6685 | + $imgarray = dol_getImageSize($dir.$photo); |
|
6686 | 6686 | |
6687 | 6687 | if ($nbbyrow > 0) |
6688 | 6688 | { |
6689 | - if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
6689 | + if ($nbphoto == 1) $return .= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
6690 | 6690 | |
6691 | - if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
6692 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
|
6691 | + if ($nbphoto % $nbbyrow == 1) $return .= '<tr align=center valign=middle border=1>'; |
|
6692 | + $return .= '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">'; |
|
6693 | 6693 | } |
6694 | 6694 | else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
6695 | 6695 | |
6696 | - $return.= "\n"; |
|
6696 | + $return .= "\n"; |
|
6697 | 6697 | |
6698 | - $relativefile=preg_replace('/^\//', '', $pdir.$photo); |
|
6698 | + $relativefile = preg_replace('/^\//', '', $pdir.$photo); |
|
6699 | 6699 | if (empty($nolink)) |
6700 | 6700 | { |
6701 | - $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
6702 | - if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
6703 | - else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
6701 | + $urladvanced = getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
6702 | + if ($urladvanced) $return .= '<a href="'.$urladvanced.'">'; |
|
6703 | + else $return .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
6704 | 6704 | } |
6705 | 6705 | |
6706 | 6706 | // Show image (width height=$maxHeight) |
6707 | 6707 | // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
6708 | - $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile; |
|
6709 | - $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; |
|
6710 | - if ($notitle) $alt=''; |
|
6708 | + $alt = $langs->transnoentitiesnoconv('File').': '.$relativefile; |
|
6709 | + $alt .= ' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; |
|
6710 | + if ($notitle) $alt = ''; |
|
6711 | 6711 | |
6712 | 6712 | if ($usesharelink) |
6713 | 6713 | { |
@@ -6715,81 +6715,81 @@ discard block |
||
6715 | 6715 | { |
6716 | 6716 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
6717 | 6717 | { |
6718 | - $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
6719 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
6718 | + $return .= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
6719 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
6720 | 6720 | } |
6721 | 6721 | else { |
6722 | - $return.= '<!-- Show original file -->'; |
|
6723 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
6722 | + $return .= '<!-- Show original file -->'; |
|
6723 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
6724 | 6724 | } |
6725 | 6725 | } |
6726 | 6726 | else |
6727 | 6727 | { |
6728 | - $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
|
6729 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
6728 | + $return .= '<!-- Show nophoto file (because file is not shared) -->'; |
|
6729 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
6730 | 6730 | } |
6731 | 6731 | } |
6732 | 6732 | else |
6733 | 6733 | { |
6734 | 6734 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
6735 | 6735 | { |
6736 | - $return.= '<!-- Show thumb -->'; |
|
6737 | - $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).'">'; |
|
6736 | + $return .= '<!-- Show thumb -->'; |
|
6737 | + $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).'">'; |
|
6738 | 6738 | } |
6739 | 6739 | else { |
6740 | - $return.= '<!-- Show original file -->'; |
|
6741 | - $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).'">'; |
|
6740 | + $return .= '<!-- Show original file -->'; |
|
6741 | + $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).'">'; |
|
6742 | 6742 | } |
6743 | 6743 | } |
6744 | 6744 | |
6745 | - if (empty($nolink)) $return.= '</a>'; |
|
6746 | - $return.="\n"; |
|
6745 | + if (empty($nolink)) $return .= '</a>'; |
|
6746 | + $return .= "\n"; |
|
6747 | 6747 | |
6748 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
6748 | + if ($showfilename) $return .= '<br>'.$viewfilename; |
|
6749 | 6749 | if ($showaction) |
6750 | 6750 | { |
6751 | - $return.= '<br>'; |
|
6751 | + $return .= '<br>'; |
|
6752 | 6752 | // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
6753 | 6753 | if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) |
6754 | 6754 | { |
6755 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' </a>'; |
|
6755 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').' </a>'; |
|
6756 | 6756 | } |
6757 | 6757 | // Special cas for product |
6758 | 6758 | if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
6759 | 6759 | { |
6760 | 6760 | // Link to resize |
6761 | - $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> '; |
|
6761 | + $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 | 6762 | |
6763 | 6763 | // Link to delete |
6764 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
6765 | - $return.= img_delete().'</a>'; |
|
6764 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
6765 | + $return .= img_delete().'</a>'; |
|
6766 | 6766 | } |
6767 | 6767 | } |
6768 | - $return.= "\n"; |
|
6768 | + $return .= "\n"; |
|
6769 | 6769 | |
6770 | 6770 | if ($nbbyrow > 0) |
6771 | 6771 | { |
6772 | - $return.= '</td>'; |
|
6773 | - if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
6772 | + $return .= '</td>'; |
|
6773 | + if (($nbphoto % $nbbyrow) == 0) $return .= '</tr>'; |
|
6774 | 6774 | } |
6775 | - else if ($nbbyrow < 0) $return.='</div>'; |
|
6775 | + else if ($nbbyrow < 0) $return .= '</div>'; |
|
6776 | 6776 | } |
6777 | 6777 | |
6778 | 6778 | if (empty($size)) { // Format origine |
6779 | - $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
6779 | + $return .= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
6780 | 6780 | |
6781 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
6781 | + if ($showfilename) $return .= '<br>'.$viewfilename; |
|
6782 | 6782 | if ($showaction) |
6783 | 6783 | { |
6784 | 6784 | // Special case for product |
6785 | 6785 | if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
6786 | 6786 | { |
6787 | 6787 | // Link to resize |
6788 | - $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> '; |
|
6788 | + $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 | 6789 | |
6790 | 6790 | // Link to delete |
6791 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
6792 | - $return.= img_delete().'</a>'; |
|
6791 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
6792 | + $return .= img_delete().'</a>'; |
|
6793 | 6793 | } |
6794 | 6794 | } |
6795 | 6795 | } |
@@ -6799,18 +6799,18 @@ discard block |
||
6799 | 6799 | } |
6800 | 6800 | } |
6801 | 6801 | |
6802 | - if ($size==1 || $size=='small') |
|
6802 | + if ($size == 1 || $size == 'small') |
|
6803 | 6803 | { |
6804 | 6804 | if ($nbbyrow > 0) |
6805 | 6805 | { |
6806 | 6806 | // Ferme tableau |
6807 | 6807 | while ($nbphoto % $nbbyrow) |
6808 | 6808 | { |
6809 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; |
|
6809 | + $return .= '<td width="'.ceil(100 / $nbbyrow).'%"> </td>'; |
|
6810 | 6810 | $nbphoto++; |
6811 | 6811 | } |
6812 | 6812 | |
6813 | - if ($nbphoto) $return.= '</table>'; |
|
6813 | + if ($nbphoto) $return .= '</table>'; |
|
6814 | 6814 | } |
6815 | 6815 | } |
6816 | 6816 | } |
@@ -6829,9 +6829,9 @@ discard block |
||
6829 | 6829 | */ |
6830 | 6830 | protected function isArray($info) |
6831 | 6831 | { |
6832 | - if(is_array($info)) |
|
6832 | + if (is_array($info)) |
|
6833 | 6833 | { |
6834 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
6834 | + if (isset($info['type']) && $info['type'] == 'array') return true; |
|
6835 | 6835 | else return false; |
6836 | 6836 | } |
6837 | 6837 | else return false; |
@@ -6845,9 +6845,9 @@ discard block |
||
6845 | 6845 | */ |
6846 | 6846 | protected function isNull($info) |
6847 | 6847 | { |
6848 | - if(is_array($info)) |
|
6848 | + if (is_array($info)) |
|
6849 | 6849 | { |
6850 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
6850 | + if (isset($info['type']) && $info['type'] == 'null') return true; |
|
6851 | 6851 | else return false; |
6852 | 6852 | } |
6853 | 6853 | else return false; |
@@ -6861,7 +6861,7 @@ discard block |
||
6861 | 6861 | */ |
6862 | 6862 | public function isDate($info) |
6863 | 6863 | { |
6864 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
6864 | + if (isset($info['type']) && ($info['type'] == 'date' || $info['type'] == 'datetime' || $info['type'] == 'timestamp')) return true; |
|
6865 | 6865 | else return false; |
6866 | 6866 | } |
6867 | 6867 | |
@@ -6873,9 +6873,9 @@ discard block |
||
6873 | 6873 | */ |
6874 | 6874 | public function isInt($info) |
6875 | 6875 | { |
6876 | - if(is_array($info)) |
|
6876 | + if (is_array($info)) |
|
6877 | 6877 | { |
6878 | - if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true; |
|
6878 | + if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) return true; |
|
6879 | 6879 | else return false; |
6880 | 6880 | } |
6881 | 6881 | else return false; |
@@ -6889,7 +6889,7 @@ discard block |
||
6889 | 6889 | */ |
6890 | 6890 | public function isFloat($info) |
6891 | 6891 | { |
6892 | - if(is_array($info)) |
|
6892 | + if (is_array($info)) |
|
6893 | 6893 | { |
6894 | 6894 | if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true; |
6895 | 6895 | else return false; |
@@ -6905,9 +6905,9 @@ discard block |
||
6905 | 6905 | */ |
6906 | 6906 | public function isText($info) |
6907 | 6907 | { |
6908 | - if(is_array($info)) |
|
6908 | + if (is_array($info)) |
|
6909 | 6909 | { |
6910 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
6910 | + if (isset($info['type']) && $info['type'] == 'text') return true; |
|
6911 | 6911 | else return false; |
6912 | 6912 | } |
6913 | 6913 | else return false; |
@@ -6921,9 +6921,9 @@ discard block |
||
6921 | 6921 | */ |
6922 | 6922 | protected function isIndex($info) |
6923 | 6923 | { |
6924 | - if(is_array($info)) |
|
6924 | + if (is_array($info)) |
|
6925 | 6925 | { |
6926 | - if(isset($info['index']) && $info['index']==true) return true; |
|
6926 | + if (isset($info['index']) && $info['index'] == true) return true; |
|
6927 | 6927 | else return false; |
6928 | 6928 | } |
6929 | 6929 | else return false; |
@@ -6939,13 +6939,13 @@ discard block |
||
6939 | 6939 | { |
6940 | 6940 | global $conf; |
6941 | 6941 | |
6942 | - $queryarray=array(); |
|
6942 | + $queryarray = array(); |
|
6943 | 6943 | foreach ($this->fields as $field=>$info) // Loop on definition of fields |
6944 | 6944 | { |
6945 | 6945 | // Depending on field type ('datetime', ...) |
6946 | - if($this->isDate($info)) |
|
6946 | + if ($this->isDate($info)) |
|
6947 | 6947 | { |
6948 | - if(empty($this->{$field})) |
|
6948 | + if (empty($this->{$field})) |
|
6949 | 6949 | { |
6950 | 6950 | $queryarray[$field] = null; |
6951 | 6951 | } |
@@ -6954,10 +6954,10 @@ discard block |
||
6954 | 6954 | $queryarray[$field] = $this->db->idate($this->{$field}); |
6955 | 6955 | } |
6956 | 6956 | } |
6957 | - else if($this->isArray($info)) |
|
6957 | + else if ($this->isArray($info)) |
|
6958 | 6958 | { |
6959 | - if(! empty($this->{$field})) { |
|
6960 | - if(! is_array($this->{$field})) { |
|
6959 | + if (!empty($this->{$field})) { |
|
6960 | + if (!is_array($this->{$field})) { |
|
6961 | 6961 | $this->{$field} = array($this->{$field}); |
6962 | 6962 | } |
6963 | 6963 | $queryarray[$field] = serialize($this->{$field}); |
@@ -6965,19 +6965,19 @@ discard block |
||
6965 | 6965 | $queryarray[$field] = null; |
6966 | 6966 | } |
6967 | 6967 | } |
6968 | - else if($this->isInt($info)) |
|
6968 | + else if ($this->isInt($info)) |
|
6969 | 6969 | { |
6970 | - if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity; |
|
6970 | + if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field] = $conf->entity; |
|
6971 | 6971 | else |
6972 | 6972 | { |
6973 | 6973 | $queryarray[$field] = (int) price2num($this->{$field}); |
6974 | - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
6974 | + if (empty($queryarray[$field])) $queryarray[$field] = 0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
6975 | 6975 | } |
6976 | 6976 | } |
6977 | - else if($this->isFloat($info)) |
|
6977 | + else if ($this->isFloat($info)) |
|
6978 | 6978 | { |
6979 | 6979 | $queryarray[$field] = (double) price2num($this->{$field}); |
6980 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
6980 | + if (empty($queryarray[$field])) $queryarray[$field] = 0; |
|
6981 | 6981 | } |
6982 | 6982 | else |
6983 | 6983 | { |
@@ -6985,7 +6985,7 @@ discard block |
||
6985 | 6985 | } |
6986 | 6986 | |
6987 | 6987 | if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
6988 | - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
6988 | + if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
6989 | 6989 | } |
6990 | 6990 | |
6991 | 6991 | return $queryarray; |
@@ -7001,35 +7001,35 @@ discard block |
||
7001 | 7001 | { |
7002 | 7002 | foreach ($this->fields as $field => $info) |
7003 | 7003 | { |
7004 | - if($this->isDate($info)) |
|
7004 | + if ($this->isDate($info)) |
|
7005 | 7005 | { |
7006 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; |
|
7006 | + if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; |
|
7007 | 7007 | else $this->{$field} = strtotime($obj->{$field}); |
7008 | 7008 | } |
7009 | - elseif($this->isArray($info)) |
|
7009 | + elseif ($this->isArray($info)) |
|
7010 | 7010 | { |
7011 | - if(! empty($obj->{$field})) { |
|
7011 | + if (!empty($obj->{$field})) { |
|
7012 | 7012 | $this->{$field} = @unserialize($obj->{$field}); |
7013 | 7013 | // Hack for data not in UTF8 |
7014 | - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field})); |
|
7014 | + if ($this->{$field } === false) @unserialize(utf8_decode($obj->{$field})); |
|
7015 | 7015 | } else { |
7016 | 7016 | $this->{$field} = array(); |
7017 | 7017 | } |
7018 | 7018 | } |
7019 | - elseif($this->isInt($info)) |
|
7019 | + elseif ($this->isInt($info)) |
|
7020 | 7020 | { |
7021 | 7021 | if ($field == 'rowid') $this->id = (int) $obj->{$field}; |
7022 | 7022 | else $this->{$field} = (int) $obj->{$field}; |
7023 | 7023 | } |
7024 | - elseif($this->isFloat($info)) |
|
7024 | + elseif ($this->isFloat($info)) |
|
7025 | 7025 | { |
7026 | 7026 | $this->{$field} = (double) $obj->{$field}; |
7027 | 7027 | } |
7028 | - elseif($this->isNull($info)) |
|
7028 | + elseif ($this->isNull($info)) |
|
7029 | 7029 | { |
7030 | 7030 | $val = $obj->{$field}; |
7031 | 7031 | // zero is not null |
7032 | - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); |
|
7032 | + $this->{$field} = (is_null($val) || (empty($val) && $val !== 0 && $val !== '0') ? null : $val); |
|
7033 | 7033 | } |
7034 | 7034 | else |
7035 | 7035 | { |
@@ -7038,7 +7038,7 @@ discard block |
||
7038 | 7038 | } |
7039 | 7039 | |
7040 | 7040 | // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
7041 | - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
7041 | + if (!isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
7042 | 7042 | } |
7043 | 7043 | |
7044 | 7044 | /** |
@@ -7080,14 +7080,14 @@ discard block |
||
7080 | 7080 | |
7081 | 7081 | $error = 0; |
7082 | 7082 | |
7083 | - $now=dol_now(); |
|
7083 | + $now = dol_now(); |
|
7084 | 7084 | |
7085 | 7085 | $fieldvalues = $this->setSaveQuery(); |
7086 | - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now); |
|
7087 | - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id; |
|
7088 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
7086 | + if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation'] = $this->db->idate($now); |
|
7087 | + if (array_key_exists('fk_user_creat', $fieldvalues) && !($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat'] = $user->id; |
|
7088 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
7089 | 7089 | |
7090 | - $keys=array(); |
|
7090 | + $keys = array(); |
|
7091 | 7091 | $values = array(); |
7092 | 7092 | foreach ($fieldvalues as $k => $v) { |
7093 | 7093 | $keys[$k] = $k; |
@@ -7096,58 +7096,58 @@ discard block |
||
7096 | 7096 | } |
7097 | 7097 | |
7098 | 7098 | // Clean and check mandatory |
7099 | - foreach($keys as $key) |
|
7099 | + foreach ($keys as $key) |
|
7100 | 7100 | { |
7101 | 7101 | // If field is an implicit foreign key field |
7102 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; |
|
7103 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
7102 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; |
|
7103 | + if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = ''; |
|
7104 | 7104 | |
7105 | 7105 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
7106 | - if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
|
7106 | + if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && !isset($values[$key]) && is_null($val['default'])) |
|
7107 | 7107 | { |
7108 | 7108 | $error++; |
7109 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
7109 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
7110 | 7110 | } |
7111 | 7111 | |
7112 | 7112 | // If field is an implicit foreign key field |
7113 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null'; |
|
7114 | - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
7113 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key] = 'null'; |
|
7114 | + if (!empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key] = 'null'; |
|
7115 | 7115 | } |
7116 | 7116 | |
7117 | 7117 | if ($error) return -1; |
7118 | 7118 | |
7119 | 7119 | $this->db->begin(); |
7120 | 7120 | |
7121 | - if (! $error) |
|
7121 | + if (!$error) |
|
7122 | 7122 | { |
7123 | 7123 | $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
7124 | - $sql.= ' ('.implode( ", ", $keys ).')'; |
|
7125 | - $sql.= ' VALUES ('.implode( ", ", $values ).')'; |
|
7124 | + $sql .= ' ('.implode(", ", $keys).')'; |
|
7125 | + $sql .= ' VALUES ('.implode(", ", $values).')'; |
|
7126 | 7126 | |
7127 | 7127 | $res = $this->db->query($sql); |
7128 | - if ($res===false) { |
|
7128 | + if ($res === false) { |
|
7129 | 7129 | $error++; |
7130 | 7130 | $this->errors[] = $this->db->lasterror(); |
7131 | 7131 | } |
7132 | 7132 | } |
7133 | 7133 | |
7134 | - if (! $error) |
|
7134 | + if (!$error) |
|
7135 | 7135 | { |
7136 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
7136 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
7137 | 7137 | } |
7138 | 7138 | |
7139 | 7139 | // Create extrafields |
7140 | - if (! $error) |
|
7140 | + if (!$error) |
|
7141 | 7141 | { |
7142 | - $result=$this->insertExtraFields(); |
|
7142 | + $result = $this->insertExtraFields(); |
|
7143 | 7143 | if ($result < 0) $error++; |
7144 | 7144 | } |
7145 | 7145 | |
7146 | 7146 | // Triggers |
7147 | - if (! $error && ! $notrigger) |
|
7147 | + if (!$error && !$notrigger) |
|
7148 | 7148 | { |
7149 | 7149 | // Call triggers |
7150 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
7150 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_CREATE', $user); |
|
7151 | 7151 | if ($result < 0) { $error++; } |
7152 | 7152 | // End call triggers |
7153 | 7153 | } |
@@ -7176,13 +7176,13 @@ discard block |
||
7176 | 7176 | if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
7177 | 7177 | |
7178 | 7178 | $sql = 'SELECT '.$this->getFieldList(); |
7179 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
7179 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
7180 | 7180 | |
7181 | - if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
7182 | - elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
7183 | - else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
7184 | - if ($morewhere) $sql.= $morewhere; |
|
7185 | - $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
7181 | + if (!empty($id)) $sql .= ' WHERE rowid = '.$id; |
|
7182 | + elseif (!empty($ref)) $sql .= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
7183 | + else $sql .= ' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
7184 | + if ($morewhere) $sql .= $morewhere; |
|
7185 | + $sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
7186 | 7186 | |
7187 | 7187 | $res = $this->db->query($sql); |
7188 | 7188 | if ($res) |
@@ -7219,14 +7219,14 @@ discard block |
||
7219 | 7219 | |
7220 | 7220 | $error = 0; |
7221 | 7221 | |
7222 | - $now=dol_now(); |
|
7222 | + $now = dol_now(); |
|
7223 | 7223 | |
7224 | 7224 | $fieldvalues = $this->setSaveQuery(); |
7225 | - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now); |
|
7226 | - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id; |
|
7227 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
7225 | + if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification'] = $this->db->idate($now); |
|
7226 | + if (array_key_exists('fk_user_modif', $fieldvalues) && !($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif'] = $user->id; |
|
7227 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
7228 | 7228 | |
7229 | - $keys=array(); |
|
7229 | + $keys = array(); |
|
7230 | 7230 | $values = array(); |
7231 | 7231 | foreach ($fieldvalues as $k => $v) { |
7232 | 7232 | $keys[$k] = $k; |
@@ -7236,10 +7236,10 @@ discard block |
||
7236 | 7236 | } |
7237 | 7237 | |
7238 | 7238 | // Clean and check mandatory |
7239 | - foreach($keys as $key) |
|
7239 | + foreach ($keys as $key) |
|
7240 | 7240 | { |
7241 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field |
|
7242 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
7241 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; // This is an implicit foreign key field |
|
7242 | + if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = ''; // This is an explicit foreign key field |
|
7243 | 7243 | |
7244 | 7244 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
7245 | 7245 | /* |
@@ -7250,13 +7250,13 @@ discard block |
||
7250 | 7250 | }*/ |
7251 | 7251 | } |
7252 | 7252 | |
7253 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
7253 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode(',', $tmp).' WHERE rowid='.$this->id; |
|
7254 | 7254 | |
7255 | 7255 | $this->db->begin(); |
7256 | - if (! $error) |
|
7256 | + if (!$error) |
|
7257 | 7257 | { |
7258 | 7258 | $res = $this->db->query($sql); |
7259 | - if ($res===false) |
|
7259 | + if ($res === false) |
|
7260 | 7260 | { |
7261 | 7261 | $error++; |
7262 | 7262 | $this->errors[] = $this->db->lasterror(); |
@@ -7264,9 +7264,9 @@ discard block |
||
7264 | 7264 | } |
7265 | 7265 | |
7266 | 7266 | // Update extrafield |
7267 | - if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) |
|
7267 | + if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) |
|
7268 | 7268 | { |
7269 | - $result=$this->insertExtraFields(); |
|
7269 | + $result = $this->insertExtraFields(); |
|
7270 | 7270 | if ($result < 0) |
7271 | 7271 | { |
7272 | 7272 | $error++; |
@@ -7274,10 +7274,10 @@ discard block |
||
7274 | 7274 | } |
7275 | 7275 | |
7276 | 7276 | // Triggers |
7277 | - if (! $error && ! $notrigger) |
|
7277 | + if (!$error && !$notrigger) |
|
7278 | 7278 | { |
7279 | 7279 | // Call triggers |
7280 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
7280 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $user); |
|
7281 | 7281 | if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail |
7282 | 7282 | // End call triggers |
7283 | 7283 | } |
@@ -7300,68 +7300,68 @@ discard block |
||
7300 | 7300 | * @param int $forcechilddeletion 0=no, 1=Force deletion of children |
7301 | 7301 | * @return int <=0 if KO, >0 if OK |
7302 | 7302 | */ |
7303 | - public function deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0) |
|
7303 | + public function deleteCommon(User $user, $notrigger = false, $forcechilddeletion = 0) |
|
7304 | 7304 | { |
7305 | - $error=0; |
|
7305 | + $error = 0; |
|
7306 | 7306 | |
7307 | 7307 | $this->db->begin(); |
7308 | 7308 | |
7309 | 7309 | if ($forcechilddeletion) |
7310 | 7310 | { |
7311 | - foreach($this->childtables as $table) |
|
7311 | + foreach ($this->childtables as $table) |
|
7312 | 7312 | { |
7313 | 7313 | $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
7314 | 7314 | $resql = $this->db->query($sql); |
7315 | - if (! $resql) |
|
7315 | + if (!$resql) |
|
7316 | 7316 | { |
7317 | - $this->error=$this->db->lasterror(); |
|
7318 | - $this->errors[]=$this->error; |
|
7317 | + $this->error = $this->db->lasterror(); |
|
7318 | + $this->errors[] = $this->error; |
|
7319 | 7319 | $this->db->rollback(); |
7320 | 7320 | return -1; |
7321 | 7321 | } |
7322 | 7322 | } |
7323 | 7323 | } |
7324 | - elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
7324 | + elseif (!empty($this->fk_element) && !empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
7325 | 7325 | { |
7326 | 7326 | $objectisused = $this->isObjectUsed($this->id); |
7327 | - if (! empty($objectisused)) |
|
7327 | + if (!empty($objectisused)) |
|
7328 | 7328 | { |
7329 | 7329 | dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
7330 | - $this->error='ErrorRecordHasChildren'; |
|
7331 | - $this->errors[]=$this->error; |
|
7330 | + $this->error = 'ErrorRecordHasChildren'; |
|
7331 | + $this->errors[] = $this->error; |
|
7332 | 7332 | $this->db->rollback(); |
7333 | 7333 | return 0; |
7334 | 7334 | } |
7335 | 7335 | } |
7336 | 7336 | |
7337 | - if (! $error) { |
|
7338 | - if (! $notrigger) { |
|
7337 | + if (!$error) { |
|
7338 | + if (!$notrigger) { |
|
7339 | 7339 | // Call triggers |
7340 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
7340 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
7341 | 7341 | if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail |
7342 | 7342 | // End call triggers |
7343 | 7343 | } |
7344 | 7344 | } |
7345 | 7345 | |
7346 | - if (! $error && ! empty($this->isextrafieldmanaged)) |
|
7346 | + if (!$error && !empty($this->isextrafieldmanaged)) |
|
7347 | 7347 | { |
7348 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
7349 | - $sql.= " WHERE fk_object=" . $this->id; |
|
7348 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; |
|
7349 | + $sql .= " WHERE fk_object=".$this->id; |
|
7350 | 7350 | |
7351 | 7351 | $resql = $this->db->query($sql); |
7352 | - if (! $resql) |
|
7352 | + if (!$resql) |
|
7353 | 7353 | { |
7354 | 7354 | $this->errors[] = $this->db->lasterror(); |
7355 | 7355 | $error++; |
7356 | 7356 | } |
7357 | 7357 | } |
7358 | 7358 | |
7359 | - if (! $error) |
|
7359 | + if (!$error) |
|
7360 | 7360 | { |
7361 | 7361 | $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
7362 | 7362 | |
7363 | 7363 | $res = $this->db->query($sql); |
7364 | - if($res===false) { |
|
7364 | + if ($res === false) { |
|
7365 | 7365 | $error++; |
7366 | 7366 | $this->errors[] = $this->db->lasterror(); |
7367 | 7367 | } |
@@ -7402,9 +7402,9 @@ discard block |
||
7402 | 7402 | require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
7403 | 7403 | |
7404 | 7404 | $comment = new Comment($this->db); |
7405 | - $result=$comment->fetchAllFor($this->element, $this->id); |
|
7406 | - if ($result<0) { |
|
7407 | - $this->errors=array_merge($this->errors, $comment->errors); |
|
7405 | + $result = $comment->fetchAllFor($this->element, $this->id); |
|
7406 | + if ($result < 0) { |
|
7407 | + $this->errors = array_merge($this->errors, $comment->errors); |
|
7408 | 7408 | return -1; |
7409 | 7409 | } else { |
7410 | 7410 | $this->comments = $comment->comments; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | if (!defined('DOL_VERSION')) { |
40 | - define('DOL_VERSION', '10.0.0-alpha'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c |
|
40 | + define('DOL_VERSION', '10.0.0-alpha'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | if (!defined('EURO')) { |
@@ -77,19 +77,19 @@ discard block |
||
77 | 77 | // --- End of part replaced by Dolibarr packager makepack-dolibarr |
78 | 78 | // Include configuration |
79 | 79 | |
80 | -$conffile = DOL_BASE_PATH . '/conf/conf.php'; |
|
80 | +$conffile = DOL_BASE_PATH.'/conf/conf.php'; |
|
81 | 81 | if (!file_exists($conffile)) { |
82 | - die('Configuración no encontrada: ' . $conffile); |
|
82 | + die('Configuración no encontrada: '.$conffile); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | $result = @include_once $conffile; // Keep @ because with some error reporting this break the redirect done when file not found |
86 | 86 | |
87 | 87 | if (!$result && !empty($_SERVER["GATEWAY_INTERFACE"])) { // If install not done and we are in a web session |
88 | - header('Location: ' . BASE_URI . '?controller=install&method=index'); // Changed for Alixar |
|
88 | + header('Location: '.BASE_URI.'?controller=install&method=index'); // Changed for Alixar |
|
89 | 89 | exit; |
90 | 90 | |
91 | 91 | if (!empty($_SERVER["CONTEXT_PREFIX"])) { // CONTEXT_PREFIX and CONTEXT_DOCUMENT_ROOT are not defined on all apache versions |
92 | - $path = $_SERVER["CONTEXT_PREFIX"]; // example '/dolibarr/' when using an apache alias. |
|
92 | + $path = $_SERVER["CONTEXT_PREFIX"]; // example '/dolibarr/' when using an apache alias. |
|
93 | 93 | if (!preg_match('/\/$/', $path)) |
94 | 94 | $path .= '/'; |
95 | 95 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | - header("Location: " . $path . "install/index.php"); |
|
121 | + header("Location: ".$path."install/index.php"); |
|
122 | 122 | exit; |
123 | 123 | } |
124 | 124 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $dolibarr_main_document_root_alt = (empty($dolibarr_main_document_root_alt) ? '' : trim($dolibarr_main_document_root_alt)); |
143 | 143 | |
144 | 144 | if (empty($dolibarr_main_db_port)) { |
145 | - $dolibarr_main_db_port = 3306; // For compatibility with old configs, if not defined, we take 'mysql' type |
|
145 | + $dolibarr_main_db_port = 3306; // For compatibility with old configs, if not defined, we take 'mysql' type |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | if (empty($dolibarr_main_db_type)) { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $dolibarr_main_db_prefix = 'llx_'; |
158 | 158 | } |
159 | 159 | if (empty($dolibarr_main_db_character_set)) { |
160 | - $dolibarr_main_db_character_set = ($dolibarr_main_db_type == 'mysqli' ? 'utf8' : ''); // Old installation |
|
160 | + $dolibarr_main_db_character_set = ($dolibarr_main_db_type == 'mysqli' ? 'utf8' : ''); // Old installation |
|
161 | 161 | } |
162 | 162 | if (empty($dolibarr_main_db_collation)) { |
163 | 163 | $dolibarr_main_db_collation = ($dolibarr_main_db_type == 'mysqli' ? 'utf8_unicode_ci' : ''); // Old installation |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | } |
208 | 208 | |
209 | 209 | if (empty($dolibarr_main_db_host)) { |
210 | - print '<div align="center">Dolibarr setup is not yet complete.<br><br>' . "\n"; |
|
211 | - print '<a href="?controller=install&method=index">Click here to finish Dolibarr install process</a> ...</div>' . "\n"; |
|
210 | + print '<div align="center">Dolibarr setup is not yet complete.<br><br>'."\n"; |
|
211 | + print '<a href="?controller=install&method=index">Click here to finish Dolibarr install process</a> ...</div>'."\n"; |
|
212 | 212 | die; |
213 | 213 | } |
214 | 214 | if (empty($dolibarr_main_url_root)) { |
215 | - print 'Value for parameter \'dolibarr_main_url_root\' is not defined in your \'htdocs\conf\conf.php\' file.<br>' . "\n"; |
|
216 | - print 'You must add this parameter with your full Dolibarr root Url (Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/)' . "\n"; |
|
215 | + print 'Value for parameter \'dolibarr_main_url_root\' is not defined in your \'htdocs\conf\conf.php\' file.<br>'."\n"; |
|
216 | + print 'You must add this parameter with your full Dolibarr root Url (Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/)'."\n"; |
|
217 | 217 | die; |
218 | 218 | } |
219 | 219 | if (empty($dolibarr_main_data_root)) { |
@@ -223,30 +223,30 @@ discard block |
||
223 | 223 | } |
224 | 224 | |
225 | 225 | // Define some constants |
226 | -define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir (defined only for some code that want to be compatible with old versions without this parameter) |
|
227 | -define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem data (documents) |
|
228 | -define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem core php (htdocs) |
|
226 | +define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir (defined only for some code that want to be compatible with old versions without this parameter) |
|
227 | +define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem data (documents) |
|
228 | +define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem core php (htdocs) |
|
229 | 229 | // Try to autodetect DOL_MAIN_URL_ROOT and DOL_URL_ROOT. |
230 | 230 | // Note: autodetect works only in case 1, 2, 3 and 4 of phpunit test CoreTest.php. For case 5, 6, only setting value into conf.php will works. |
231 | 231 | $tmp = ''; |
232 | 232 | $found = 0; |
233 | 233 | $real_dolibarr_main_document_root = str_replace('\\', '/', realpath($dolibarr_main_document_root)); // A) Value found into config file, to say where are store htdocs files. Ex: C:/xxx/dolibarr, C:/xxx/dolibarr/htdocs |
234 | 234 | if (!empty($_SERVER["DOCUMENT_ROOT"])) { |
235 | - $pathroot = $_SERVER["DOCUMENT_ROOT"]; // B) Value reported by web server setup (not defined on CLI mode), to say where is root of web server instance. Ex: C:/xxx/dolibarr, C:/xxx/dolibarr/htdocs |
|
235 | + $pathroot = $_SERVER["DOCUMENT_ROOT"]; // B) Value reported by web server setup (not defined on CLI mode), to say where is root of web server instance. Ex: C:/xxx/dolibarr, C:/xxx/dolibarr/htdocs |
|
236 | 236 | } else { |
237 | 237 | $pathroot = 'NOTDEFINED'; |
238 | 238 | } |
239 | -$paths = explode('/', str_replace('\\', '/', $_SERVER["SCRIPT_NAME"])); // C) Value reported by web server, to say full path on filesystem of a file. Ex: /dolibarr/htdocs/admin/system/phpinfo.php |
|
239 | +$paths = explode('/', str_replace('\\', '/', $_SERVER["SCRIPT_NAME"])); // C) Value reported by web server, to say full path on filesystem of a file. Ex: /dolibarr/htdocs/admin/system/phpinfo.php |
|
240 | 240 | // Try to detect if $_SERVER["DOCUMENT_ROOT"]+start of $_SERVER["SCRIPT_NAME"] is $dolibarr_main_document_root. If yes, relative url to add before dol files is this start part. |
241 | 241 | $concatpath = ''; |
242 | 242 | foreach ($paths as $tmppath) { // We check to find (B+start of C)=A |
243 | 243 | if (empty($tmppath)) { |
244 | 244 | continue; |
245 | 245 | } |
246 | - $concatpath .= '/' . $tmppath; |
|
246 | + $concatpath .= '/'.$tmppath; |
|
247 | 247 | //if ($tmppath) $concatpath.='/'.$tmppath; |
248 | 248 | //print $_SERVER["SCRIPT_NAME"].'-'.$pathroot.'-'.$concatpath.'-'.$real_dolibarr_main_document_root.'-'.realpath($pathroot.$concatpath).'<br>'; |
249 | - if ($real_dolibarr_main_document_root == @realpath($pathroot . $concatpath)) { // @ avoid warning when safe_mode is on. |
|
249 | + if ($real_dolibarr_main_document_root == @realpath($pathroot.$concatpath)) { // @ avoid warning when safe_mode is on. |
|
250 | 250 | //print "Found relative url = ".$concatpath; |
251 | 251 | $tmp3 = $concatpath; |
252 | 252 | $found = 1; |
@@ -258,19 +258,19 @@ discard block |
||
258 | 258 | if (!$found) { |
259 | 259 | $tmp = $dolibarr_main_url_root; // If autodetect fails (Ie: when using apache alias that point outside default DOCUMENT_ROOT). |
260 | 260 | } else { |
261 | - $tmp = 'http' . (((empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on') && (empty($_SERVER["SERVER_PORT"]) || $_SERVER["SERVER_PORT"] != 443)) ? '' : 's') . '://' . $_SERVER["SERVER_NAME"] . ((empty($_SERVER["SERVER_PORT"]) || $_SERVER["SERVER_PORT"] == 80 || $_SERVER["SERVER_PORT"] == 443) ? '' : ':' . $_SERVER["SERVER_PORT"]) . ($tmp3 ? (preg_match('/^\//', $tmp3) ? '' : '/') . $tmp3 : ''); |
|
261 | + $tmp = 'http'.(((empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on') && (empty($_SERVER["SERVER_PORT"]) || $_SERVER["SERVER_PORT"] != 443)) ? '' : 's').'://'.$_SERVER["SERVER_NAME"].((empty($_SERVER["SERVER_PORT"]) || $_SERVER["SERVER_PORT"] == 80 || $_SERVER["SERVER_PORT"] == 443) ? '' : ':'.$_SERVER["SERVER_PORT"]).($tmp3 ? (preg_match('/^\//', $tmp3) ? '' : '/').$tmp3 : ''); |
|
262 | 262 | } |
263 | 263 | //print "tmp1=".$tmp1." tmp2=".$tmp2." tmp3=".$tmp3." tmp=".$tmp."\n"; |
264 | 264 | if (!empty($dolibarr_main_force_https)) { |
265 | 265 | $tmp = preg_replace('/^http:/i', 'https:', $tmp); |
266 | 266 | } |
267 | -define('DOL_MAIN_URL_ROOT', $tmp); // URL absolute root (https://sss/dolibarr, ...) |
|
267 | +define('DOL_MAIN_URL_ROOT', $tmp); // URL absolute root (https://sss/dolibarr, ...) |
|
268 | 268 | $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http* |
269 | -$suburi = strstr($uri, '/'); // $suburi contains url without domain:port |
|
269 | +$suburi = strstr($uri, '/'); // $suburi contains url without domain:port |
|
270 | 270 | if ($suburi == '/') { |
271 | - $suburi = ''; // If $suburi is /, it is now '' |
|
271 | + $suburi = ''; // If $suburi is /, it is now '' |
|
272 | 272 | } |
273 | -define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...) |
|
273 | +define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...) |
|
274 | 274 | //print DOL_MAIN_URL_ROOT.'-'.DOL_URL_ROOT."\n"; |
275 | 275 | // Define prefix MAIN_DB_PREFIX |
276 | 276 | define('MAIN_DB_PREFIX', $dolibarr_main_db_prefix); |
@@ -294,50 +294,50 @@ discard block |
||
294 | 294 | |
295 | 295 | */ |
296 | 296 | if (!defined('ADODB_PATH')) { |
297 | - define('ADODB_PATH', BASE_PATH . '/vendor/adodb/adodb-php'); |
|
297 | + define('ADODB_PATH', BASE_PATH.'/vendor/adodb/adodb-php'); |
|
298 | 298 | } |
299 | 299 | if (!defined('ADODB_DATE_VERSION')) { |
300 | - include_once ADODB_PATH . '/adodb-time.inc.php'; |
|
300 | + include_once ADODB_PATH.'/adodb-time.inc.php'; |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | if (!defined('FPDF_PATH')) { |
304 | - define('FPDF_PATH', (empty($dolibarr_lib_FPDF_PATH)) ? DOL_BASE_PATH . '/includes/fpdf/' : $dolibarr_lib_FPDF_PATH . '/'); |
|
304 | + define('FPDF_PATH', (empty($dolibarr_lib_FPDF_PATH)) ? DOL_BASE_PATH . '/includes/fpdf/' : $dolibarr_lib_FPDF_PATH.'/'); |
|
305 | 305 | } // Used only for package that can't include tcpdf |
306 | 306 | if (!defined('TCPDF_PATH')) { |
307 | - define('TCPDF_PATH', (empty($dolibarr_lib_TCPDF_PATH)) ? DOL_BASE_PATH . '/includes/tecnickcom/tcpdf/' : $dolibarr_lib_TCPDF_PATH . '/'); |
|
307 | + define('TCPDF_PATH', (empty($dolibarr_lib_TCPDF_PATH)) ? DOL_BASE_PATH . '/includes/tecnickcom/tcpdf/' : $dolibarr_lib_TCPDF_PATH.'/'); |
|
308 | 308 | } |
309 | 309 | if (!defined('FPDI_PATH')) { |
310 | - define('FPDI_PATH', (empty($dolibarr_lib_FPDI_PATH)) ? DOL_BASE_PATH . '/includes/fpdfi/' : $dolibarr_lib_FPDI_PATH . '/'); |
|
310 | + define('FPDI_PATH', (empty($dolibarr_lib_FPDI_PATH)) ? DOL_BASE_PATH . '/includes/fpdfi/' : $dolibarr_lib_FPDI_PATH.'/'); |
|
311 | 311 | } |
312 | 312 | if (!defined('TCPDI_PATH')) { |
313 | - define('TCPDI_PATH', (empty($dolibarr_lib_TCPDI_PATH)) ? DOL_BASE_PATH . '/includes/tcpdi/' : $dolibarr_lib_TCPDI_PATH . '/'); |
|
313 | + define('TCPDI_PATH', (empty($dolibarr_lib_TCPDI_PATH)) ? DOL_BASE_PATH . '/includes/tcpdi/' : $dolibarr_lib_TCPDI_PATH.'/'); |
|
314 | 314 | } |
315 | 315 | if (!defined('NUSOAP_PATH')) { |
316 | - define('NUSOAP_PATH', (!isset($dolibarr_lib_NUSOAP_PATH)) ? DOL_BASE_PATH . '/includes/nusoap/lib/' : (empty($dolibarr_lib_NUSOAP_PATH) ? '' : $dolibarr_lib_NUSOAP_PATH . '/')); |
|
316 | + define('NUSOAP_PATH', (!isset($dolibarr_lib_NUSOAP_PATH)) ? DOL_BASE_PATH . '/includes/nusoap/lib/' : (empty($dolibarr_lib_NUSOAP_PATH) ? '' : $dolibarr_lib_NUSOAP_PATH.'/')); |
|
317 | 317 | } |
318 | 318 | if (!defined('PHPEXCEL_PATH')) { |
319 | - define('PHPEXCEL_PATH', (!isset($dolibarr_lib_PHPEXCEL_PATH)) ? DOL_BASE_PATH . '/includes/phpoffice/phpexcel/Classes/' : (empty($dolibarr_lib_PHPEXCEL_PATH) ? '' : $dolibarr_lib_PHPEXCEL_PATH . '/')); |
|
319 | + define('PHPEXCEL_PATH', (!isset($dolibarr_lib_PHPEXCEL_PATH)) ? DOL_BASE_PATH . '/includes/phpoffice/phpexcel/Classes/' : (empty($dolibarr_lib_PHPEXCEL_PATH) ? '' : $dolibarr_lib_PHPEXCEL_PATH.'/')); |
|
320 | 320 | } |
321 | 321 | if (!defined('GEOIP_PATH')) { |
322 | - define('GEOIP_PATH', (!isset($dolibarr_lib_GEOIP_PATH)) ? DOL_BASE_PATH . '/includes/geoip/' : (empty($dolibarr_lib_GEOIP_PATH) ? '' : $dolibarr_lib_GEOIP_PATH . '/')); |
|
322 | + define('GEOIP_PATH', (!isset($dolibarr_lib_GEOIP_PATH)) ? DOL_BASE_PATH . '/includes/geoip/' : (empty($dolibarr_lib_GEOIP_PATH) ? '' : $dolibarr_lib_GEOIP_PATH.'/')); |
|
323 | 323 | } |
324 | 324 | if (!defined('ODTPHP_PATH')) { |
325 | - define('ODTPHP_PATH', (!isset($dolibarr_lib_ODTPHP_PATH)) ? DOL_BASE_PATH . '/includes/odtphp/' : (empty($dolibarr_lib_ODTPHP_PATH) ? '' : $dolibarr_lib_ODTPHP_PATH . '/')); |
|
325 | + define('ODTPHP_PATH', (!isset($dolibarr_lib_ODTPHP_PATH)) ? DOL_BASE_PATH . '/includes/odtphp/' : (empty($dolibarr_lib_ODTPHP_PATH) ? '' : $dolibarr_lib_ODTPHP_PATH.'/')); |
|
326 | 326 | } |
327 | 327 | if (!defined('ODTPHP_PATHTOPCLZIP')) { |
328 | - define('ODTPHP_PATHTOPCLZIP', (!isset($dolibarr_lib_ODTPHP_PATHTOPCLZIP)) ? DOL_BASE_PATH . '/includes/odtphp/zip/pclzip/' : (empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP) ? '' : $dolibarr_lib_ODTPHP_PATHTOPCLZIP . '/')); |
|
328 | + define('ODTPHP_PATHTOPCLZIP', (!isset($dolibarr_lib_ODTPHP_PATHTOPCLZIP)) ? DOL_BASE_PATH . '/includes/odtphp/zip/pclzip/' : (empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP) ? '' : $dolibarr_lib_ODTPHP_PATHTOPCLZIP.'/')); |
|
329 | 329 | } |
330 | 330 | if (!defined('JS_CKEDITOR')) { |
331 | - define('JS_CKEDITOR', (!isset($dolibarr_js_CKEDITOR)) ? '' : (empty($dolibarr_js_CKEDITOR) ? '' : $dolibarr_js_CKEDITOR . '/')); |
|
331 | + define('JS_CKEDITOR', (!isset($dolibarr_js_CKEDITOR)) ? '' : (empty($dolibarr_js_CKEDITOR) ? '' : $dolibarr_js_CKEDITOR.'/')); |
|
332 | 332 | } |
333 | 333 | if (!defined('JS_JQUERY')) { |
334 | - define('JS_JQUERY', (!isset($dolibarr_js_JQUERY)) ? '' : (empty($dolibarr_js_JQUERY) ? '' : $dolibarr_js_JQUERY . '/')); |
|
334 | + define('JS_JQUERY', (!isset($dolibarr_js_JQUERY)) ? '' : (empty($dolibarr_js_JQUERY) ? '' : $dolibarr_js_JQUERY.'/')); |
|
335 | 335 | } |
336 | 336 | if (!defined('JS_JQUERY_UI')) { |
337 | - define('JS_JQUERY_UI', (!isset($dolibarr_js_JQUERY_UI)) ? '' : (empty($dolibarr_js_JQUERY_UI) ? '' : $dolibarr_js_JQUERY_UI . '/')); |
|
337 | + define('JS_JQUERY_UI', (!isset($dolibarr_js_JQUERY_UI)) ? '' : (empty($dolibarr_js_JQUERY_UI) ? '' : $dolibarr_js_JQUERY_UI.'/')); |
|
338 | 338 | } |
339 | 339 | if (!defined('JS_JQUERY_FLOT')) { |
340 | - define('JS_JQUERY_FLOT', (!isset($dolibarr_js_JQUERY_FLOT)) ? '' : (empty($dolibarr_js_JQUERY_FLOT) ? '' : $dolibarr_js_JQUERY_FLOT . '/')); |
|
340 | + define('JS_JQUERY_FLOT', (!isset($dolibarr_js_JQUERY_FLOT)) ? '' : (empty($dolibarr_js_JQUERY_FLOT) ? '' : $dolibarr_js_JQUERY_FLOT.'/')); |
|
341 | 341 | } |
342 | 342 | // Other required path |
343 | 343 | if (!defined('DOL_DEFAULT_TTF')) { |
@@ -351,15 +351,15 @@ discard block |
||
351 | 351 | * Include functions |
352 | 352 | */ |
353 | 353 | |
354 | -if (!file_exists(DOL_BASE_PATH . "/core/lib/functions.lib.php")) { |
|
354 | +if (!file_exists(DOL_BASE_PATH."/core/lib/functions.lib.php")) { |
|
355 | 355 | print "Error: Dolibarr config file content seems to be not correctly defined.<br>\n"; |
356 | 356 | print "Please run dolibarr setup by calling page <b>/install</b>.<br>\n"; |
357 | 357 | exit; |
358 | 358 | } |
359 | 359 | |
360 | 360 | // Included by default |
361 | -include_once DOL_BASE_PATH . '/core/lib/functions.lib.php'; |
|
362 | -include_once DOL_BASE_PATH . '/core/lib/security.lib.php'; |
|
361 | +include_once DOL_BASE_PATH.'/core/lib/functions.lib.php'; |
|
362 | +include_once DOL_BASE_PATH.'/core/lib/security.lib.php'; |
|
363 | 363 | |
364 | 364 | //print memory_get_usage(); |
365 | 365 | // If password is encoded, we decode it |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public $fk_element = 'fk_soc'; |
25 | 25 | public $fieldsforcombobox = 'nom,name_alias'; |
26 | - public $picto = 'company'; // To test if we can delete object |
|
26 | + public $picto = 'company'; // To test if we can delete object |
|
27 | 27 | /** |
28 | 28 | * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
29 | 29 | * @var int |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * @var int ID |
354 | 354 | */ |
355 | 355 | public $fk_multicurrency; |
356 | - public $multicurrency_code; //Used into tooltip |
|
356 | + public $multicurrency_code; //Used into tooltip |
|
357 | 357 | // Multicurrency |
358 | 358 | protected $childtables = array("supplier_proposal" => 'SupplierProposal', "propal" => 'Proposal', "commande" => 'Order', "facture" => 'Invoice', "facture_rec" => 'RecurringInvoiceTemplate', "contrat" => 'Contract', "fichinter" => 'Fichinter', "facture_fourn" => 'SupplierInvoice', "commande_fournisseur" => 'SupplierOrder', "projet" => 'Project', "expedition" => 'Shipment', "prelevement_lignes" => 'DirectDebitRecord'); |
359 | 359 | protected $childtablesoncascade = array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm"); |
@@ -399,16 +399,16 @@ discard block |
||
399 | 399 | * Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some to avoid duplicate. |
400 | 400 | * Because this function is meant to be executed within a transaction, we won't take care of begin/commit. |
401 | 401 | */ |
402 | - $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'societe_commerciaux '; |
|
403 | - $sql .= ' WHERE fk_soc = ' . (int)$dest_id . ' AND fk_user IN ( '; |
|
402 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'societe_commerciaux '; |
|
403 | + $sql .= ' WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( '; |
|
404 | 404 | $sql .= ' SELECT fk_user '; |
405 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe_commerciaux '; |
|
406 | - $sql .= ' WHERE fk_soc = ' . (int)$origin_id . ') '; |
|
405 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux '; |
|
406 | + $sql .= ' WHERE fk_soc = '.(int) $origin_id.') '; |
|
407 | 407 | |
408 | 408 | $query = $db->query($sql); |
409 | 409 | |
410 | 410 | while ($result = $db->fetch_object($query)) { |
411 | - $db->query('DELETE FROM ' . MAIN_DB_PREFIX . 'societe_commerciaux WHERE rowid = ' . $result->rowid); |
|
411 | + $db->query('DELETE FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE rowid = '.$result->rowid); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | /** |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | function create_individual(User $user) |
440 | 440 | { |
441 | 441 | // phpcs:enable |
442 | - require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; |
|
442 | + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
443 | 443 | $contact = new Contact($this->db); |
444 | 444 | |
445 | 445 | $contact->name = $this->name_bis; |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | if ($result < 0) { |
461 | 461 | $this->error = $contact->error; |
462 | 462 | $this->errors = $contact->errors; |
463 | - dol_syslog(get_class($this) . "::create_individual ERROR:" . $this->error, LOG_ERR); |
|
463 | + dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | return $result; |
@@ -516,40 +516,40 @@ discard block |
||
516 | 516 | $sql .= ', st.libelle as stcomm'; |
517 | 517 | $sql .= ', te.code as typent_code'; |
518 | 518 | $sql .= ', i.libelle as libelle_incoterms'; |
519 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s'; |
|
520 | - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_effectif as e ON s.fk_effectif = e.id'; |
|
521 | - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as c ON s.fk_pays = c.rowid'; |
|
522 | - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_stcomm as st ON s.fk_stcomm = st.id'; |
|
523 | - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code'; |
|
524 | - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_departements as d ON s.fk_departement = d.rowid'; |
|
525 | - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_typent as te ON s.fk_typent = te.id'; |
|
526 | - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_incoterms as i ON s.fk_incoterms = i.rowid'; |
|
527 | - |
|
528 | - $sql .= ' WHERE s.entity IN (' . getEntity($this->element) . ')'; |
|
519 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s'; |
|
520 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as e ON s.fk_effectif = e.id'; |
|
521 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid'; |
|
522 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id'; |
|
523 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code'; |
|
524 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; |
|
525 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id'; |
|
526 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid'; |
|
527 | + |
|
528 | + $sql .= ' WHERE s.entity IN ('.getEntity($this->element).')'; |
|
529 | 529 | if ($rowid) |
530 | - $sql .= ' AND s.rowid = ' . $rowid; |
|
530 | + $sql .= ' AND s.rowid = '.$rowid; |
|
531 | 531 | if ($ref) |
532 | - $sql .= " AND s.nom = '" . $this->db->escape($ref) . "'"; |
|
532 | + $sql .= " AND s.nom = '".$this->db->escape($ref)."'"; |
|
533 | 533 | if ($ref_alias) |
534 | - $sql .= " AND s.nom_alias = '" . $this->db->escape($ref_alias) . "'"; |
|
534 | + $sql .= " AND s.nom_alias = '".$this->db->escape($ref_alias)."'"; |
|
535 | 535 | if ($ref_ext) |
536 | - $sql .= " AND s.ref_ext = '" . $this->db->escape($ref_ext) . "'"; |
|
536 | + $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
537 | 537 | if ($ref_int) |
538 | - $sql .= " AND s.ref_int = '" . $this->db->escape($ref_int) . "'"; |
|
538 | + $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'"; |
|
539 | 539 | if ($idprof1) |
540 | - $sql .= " AND s.siren = '" . $this->db->escape($idprof1) . "'"; |
|
540 | + $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'"; |
|
541 | 541 | if ($idprof2) |
542 | - $sql .= " AND s.siret = '" . $this->db->escape($idprof2) . "'"; |
|
542 | + $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'"; |
|
543 | 543 | if ($idprof3) |
544 | - $sql .= " AND s.ape = '" . $this->db->escape($idprof3) . "'"; |
|
544 | + $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'"; |
|
545 | 545 | if ($idprof4) |
546 | - $sql .= " AND s.idprof4 = '" . $this->db->escape($idprof4) . "'"; |
|
546 | + $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'"; |
|
547 | 547 | if ($idprof5) |
548 | - $sql .= " AND s.idprof5 = '" . $this->db->escape($idprof5) . "'"; |
|
548 | + $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'"; |
|
549 | 549 | if ($idprof6) |
550 | - $sql .= " AND s.idprof6 = '" . $this->db->escape($idprof6) . "'"; |
|
550 | + $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'"; |
|
551 | 551 | if ($email) |
552 | - $sql .= " AND s.email = '" . $this->db->escape($email) . "'"; |
|
552 | + $sql .= " AND s.email = '".$this->db->escape($email)."'"; |
|
553 | 553 | |
554 | 554 | $resql = $this->db->query($sql); |
555 | 555 | if ($resql) { |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | |
568 | 568 | $this->ref = $obj->rowid; |
569 | 569 | $this->name = $obj->name; |
570 | - $this->nom = $obj->name; // deprecated |
|
570 | + $this->nom = $obj->name; // deprecated |
|
571 | 571 | $this->name_alias = $obj->name_alias; |
572 | 572 | $this->ref_ext = $obj->ref_ext; |
573 | 573 | $this->ref_int = $obj->ref_int; |
@@ -583,16 +583,16 @@ discard block |
||
583 | 583 | |
584 | 584 | $this->country_id = $obj->country_id; |
585 | 585 | $this->country_code = $obj->country_id ? $obj->country_code : ''; |
586 | - $this->country = $obj->country_id ? ($langs->trans('Country' . $obj->country_code) != 'Country' . $obj->country_code ? $langs->transnoentities('Country' . $obj->country_code) : $obj->country) : ''; |
|
586 | + $this->country = $obj->country_id ? ($langs->trans('Country'.$obj->country_code) != 'Country'.$obj->country_code ? $langs->transnoentities('Country'.$obj->country_code) : $obj->country) : ''; |
|
587 | 587 | |
588 | 588 | $this->state_id = $obj->fk_departement; |
589 | 589 | $this->state_code = $obj->state_code; |
590 | 590 | $this->state = ($obj->state != '-' ? $obj->state : ''); |
591 | 591 | |
592 | - $transcode = $langs->trans('StatusProspect' . $obj->fk_stcomm); |
|
593 | - $libelle = ($transcode != 'StatusProspect' . $obj->fk_stcomm ? $transcode : $obj->stcomm); |
|
594 | - $this->stcomm_id = $obj->fk_stcomm; // id statut commercial |
|
595 | - $this->statut_commercial = $libelle; // libelle statut commercial |
|
592 | + $transcode = $langs->trans('StatusProspect'.$obj->fk_stcomm); |
|
593 | + $libelle = ($transcode != 'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm); |
|
594 | + $this->stcomm_id = $obj->fk_stcomm; // id statut commercial |
|
595 | + $this->statut_commercial = $libelle; // libelle statut commercial |
|
596 | 596 | |
597 | 597 | $this->email = $obj->email; |
598 | 598 | $this->skype = $obj->skype; |
@@ -721,11 +721,11 @@ discard block |
||
721 | 721 | if (empty($fuser)) |
722 | 722 | $fuser = $user; |
723 | 723 | |
724 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
|
724 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
725 | 725 | |
726 | 726 | $entity = isset($this->entity) ? $this->entity : $conf->entity; |
727 | 727 | |
728 | - dol_syslog(get_class($this) . "::delete", LOG_DEBUG); |
|
728 | + dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
729 | 729 | $error = 0; |
730 | 730 | |
731 | 731 | // Test if child exists |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | } |
744 | 744 | |
745 | 745 | if (!$error) { |
746 | - require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; |
|
746 | + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
747 | 747 | $static_cat = new Categorie($this->db); |
748 | 748 | $toute_categs = array(); |
749 | 749 | |
@@ -765,8 +765,8 @@ discard block |
||
765 | 765 | |
766 | 766 | foreach ($this->childtablesoncascade as $tabletodelete) { |
767 | 767 | if (!$error) { |
768 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $tabletodelete; |
|
769 | - $sql .= " WHERE fk_soc = " . $id; |
|
768 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete; |
|
769 | + $sql .= " WHERE fk_soc = ".$id; |
|
770 | 770 | if (!$this->db->query($sql)) { |
771 | 771 | $error++; |
772 | 772 | $this->errors[] = $this->db->lasterror(); |
@@ -779,15 +779,15 @@ discard block |
||
779 | 779 | $result = $this->deleteExtraFields(); |
780 | 780 | if ($result < 0) { |
781 | 781 | $error++; |
782 | - dol_syslog(get_class($this) . "::delete error -3 " . $this->error, LOG_ERR); |
|
782 | + dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); |
|
783 | 783 | } |
784 | 784 | } |
785 | 785 | |
786 | 786 | // Remove links to subsidiaries companies |
787 | 787 | if (!$error) { |
788 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "societe"; |
|
788 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; |
|
789 | 789 | $sql .= " SET parent = NULL"; |
790 | - $sql .= " WHERE parent = " . $id; |
|
790 | + $sql .= " WHERE parent = ".$id; |
|
791 | 791 | if (!$this->db->query($sql)) { |
792 | 792 | $error++; |
793 | 793 | $this->errors[] = $this->db->lasterror(); |
@@ -796,8 +796,8 @@ discard block |
||
796 | 796 | |
797 | 797 | // Remove third party |
798 | 798 | if (!$error) { |
799 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe"; |
|
800 | - $sql .= " WHERE rowid = " . $id; |
|
799 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe"; |
|
800 | + $sql .= " WHERE rowid = ".$id; |
|
801 | 801 | if (!$this->db->query($sql)) { |
802 | 802 | $error++; |
803 | 803 | $this->errors[] = $this->db->lasterror(); |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | |
810 | 810 | // Delete directory |
811 | 811 | if (!empty($conf->societe->multidir_output[$entity])) { |
812 | - $docdir = $conf->societe->multidir_output[$entity] . "/" . $id; |
|
812 | + $docdir = $conf->societe->multidir_output[$entity]."/".$id; |
|
813 | 813 | if (dol_is_dir($docdir)) { |
814 | 814 | dol_delete_dir_recursive($docdir); |
815 | 815 | } |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | return -1; |
823 | 823 | } |
824 | 824 | } else |
825 | - dol_syslog("Can't remove thirdparty with id " . $id . ". There is " . $objectisused . " childs", LOG_WARNING); |
|
825 | + dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING); |
|
826 | 826 | return 0; |
827 | 827 | } |
828 | 828 | |
@@ -838,9 +838,9 @@ discard block |
||
838 | 838 | $newclient = 1; |
839 | 839 | if ($this->client == 2 || $this->client == 3) |
840 | 840 | $newclient = 3; //If prospect, we keep prospect tag |
841 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "societe"; |
|
842 | - $sql .= " SET client = " . $newclient; |
|
843 | - $sql .= " WHERE rowid = " . $this->id; |
|
841 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; |
|
842 | + $sql .= " SET client = ".$newclient; |
|
843 | + $sql .= " WHERE rowid = ".$this->id; |
|
844 | 844 | |
845 | 845 | $resql = $this->db->query($sql); |
846 | 846 | if ($resql) { |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | return -2; |
873 | 873 | } |
874 | 874 | |
875 | - dol_syslog(get_class($this) . "::set_remise_client " . $remise . ", " . $note . ", " . $user->id); |
|
875 | + dol_syslog(get_class($this)."::set_remise_client ".$remise.", ".$note.", ".$user->id); |
|
876 | 876 | |
877 | 877 | if ($this->id) { |
878 | 878 | $this->db->begin(); |
@@ -880,9 +880,9 @@ discard block |
||
880 | 880 | $now = dol_now(); |
881 | 881 | |
882 | 882 | // Positionne remise courante |
883 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "societe "; |
|
884 | - $sql .= " SET remise_client = '" . $this->db->escape($remise) . "'"; |
|
885 | - $sql .= " WHERE rowid = " . $this->id; |
|
883 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; |
|
884 | + $sql .= " SET remise_client = '".$this->db->escape($remise)."'"; |
|
885 | + $sql .= " WHERE rowid = ".$this->id; |
|
886 | 886 | $resql = $this->db->query($sql); |
887 | 887 | if (!$resql) { |
888 | 888 | $this->db->rollback(); |
@@ -891,11 +891,11 @@ discard block |
||
891 | 891 | } |
892 | 892 | |
893 | 893 | // Ecrit trace dans historique des remises |
894 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_remise"; |
|
894 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise"; |
|
895 | 895 | $sql .= " (entity, datec, fk_soc, remise_client, note, fk_user_author)"; |
896 | - $sql .= " VALUES (" . $conf->entity . ", '" . $this->db->idate($now) . "', " . $this->id . ", '" . $this->db->escape($remise) . "',"; |
|
897 | - $sql .= " '" . $this->db->escape($note) . "',"; |
|
898 | - $sql .= " " . $user->id; |
|
896 | + $sql .= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',"; |
|
897 | + $sql .= " '".$this->db->escape($note)."',"; |
|
898 | + $sql .= " ".$user->id; |
|
899 | 899 | $sql .= ")"; |
900 | 900 | |
901 | 901 | $resql = $this->db->query($sql); |
@@ -932,7 +932,7 @@ discard block |
||
932 | 932 | return -2; |
933 | 933 | } |
934 | 934 | |
935 | - dol_syslog(get_class($this) . "::set_remise_supplier " . $remise . ", " . $note . ", " . $user->id); |
|
935 | + dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id); |
|
936 | 936 | |
937 | 937 | if ($this->id) { |
938 | 938 | $this->db->begin(); |
@@ -940,9 +940,9 @@ discard block |
||
940 | 940 | $now = dol_now(); |
941 | 941 | |
942 | 942 | // Positionne remise courante |
943 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "societe "; |
|
944 | - $sql .= " SET remise_supplier = '" . $this->db->escape($remise) . "'"; |
|
945 | - $sql .= " WHERE rowid = " . $this->id; |
|
943 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; |
|
944 | + $sql .= " SET remise_supplier = '".$this->db->escape($remise)."'"; |
|
945 | + $sql .= " WHERE rowid = ".$this->id; |
|
946 | 946 | $resql = $this->db->query($sql); |
947 | 947 | if (!$resql) { |
948 | 948 | $this->db->rollback(); |
@@ -951,11 +951,11 @@ discard block |
||
951 | 951 | } |
952 | 952 | |
953 | 953 | // Ecrit trace dans historique des remises |
954 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_remise_supplier"; |
|
954 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_supplier"; |
|
955 | 955 | $sql .= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)"; |
956 | - $sql .= " VALUES (" . $conf->entity . ", '" . $this->db->idate($now) . "', " . $this->id . ", '" . $this->db->escape($remise) . "',"; |
|
957 | - $sql .= " '" . $this->db->escape($note) . "',"; |
|
958 | - $sql .= " " . $user->id; |
|
956 | + $sql .= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',"; |
|
957 | + $sql .= " '".$this->db->escape($note)."',"; |
|
958 | + $sql .= " ".$user->id; |
|
959 | 959 | $sql .= ")"; |
960 | 960 | |
961 | 961 | $resql = $this->db->query($sql); |
@@ -1002,7 +1002,7 @@ discard block |
||
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | if ($this->id) { |
1005 | - require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php'; |
|
1005 | + require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; |
|
1006 | 1006 | |
1007 | 1007 | $discount = new DiscountAbsolute($this->db); |
1008 | 1008 | $discount->fk_soc = $this->id; |
@@ -1040,7 +1040,7 @@ discard block |
||
1040 | 1040 | */ |
1041 | 1041 | function getAvailableDiscounts($user = '', $filter = '', $maxvalue = 0, $discount_type = 0) |
1042 | 1042 | { |
1043 | - require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php'; |
|
1043 | + require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; |
|
1044 | 1044 | |
1045 | 1045 | $discountstatic = new DiscountAbsolute($this->db); |
1046 | 1046 | $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type); |
@@ -1067,18 +1067,18 @@ discard block |
||
1067 | 1067 | if ($this->id) { |
1068 | 1068 | $now = dol_now(); |
1069 | 1069 | |
1070 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "societe"; |
|
1071 | - $sql .= " SET price_level = '" . $this->db->escape($price_level) . "'"; |
|
1072 | - $sql .= " WHERE rowid = " . $this->id; |
|
1070 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; |
|
1071 | + $sql .= " SET price_level = '".$this->db->escape($price_level)."'"; |
|
1072 | + $sql .= " WHERE rowid = ".$this->id; |
|
1073 | 1073 | |
1074 | 1074 | if (!$this->db->query($sql)) { |
1075 | 1075 | dol_print_error($this->db); |
1076 | 1076 | return -1; |
1077 | 1077 | } |
1078 | 1078 | |
1079 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_prices"; |
|
1079 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices"; |
|
1080 | 1080 | $sql .= " (datec, fk_soc, price_level, fk_user_author)"; |
1081 | - $sql .= " VALUES ('" . $this->db->idate($now) . "', " . $this->id . ", '" . $this->db->escape($price_level) . "', " . $user->id . ")"; |
|
1081 | + $sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")"; |
|
1082 | 1082 | |
1083 | 1083 | if (!$this->db->query($sql)) { |
1084 | 1084 | dol_print_error($this->db); |
@@ -1104,7 +1104,7 @@ discard block |
||
1104 | 1104 | global $conf, $langs, $hookmanager; |
1105 | 1105 | |
1106 | 1106 | if (!empty($conf->dol_no_mouse_hover)) |
1107 | - $notooltip = 1; // Force disable tooltips |
|
1107 | + $notooltip = 1; // Force disable tooltips |
|
1108 | 1108 | |
1109 | 1109 | $name = $this->name ? $this->name : $this->nom; |
1110 | 1110 | |
@@ -1122,24 +1122,24 @@ discard block |
||
1122 | 1122 | if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2 |
1123 | 1123 | ) |
1124 | 1124 | ) { |
1125 | - $code = $this->code_client . ' - '; |
|
1125 | + $code = $this->code_client.' - '; |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | if (($this->fournisseur) && (!empty($this->code_fournisseur)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3 |
1129 | 1129 | ) |
1130 | 1130 | ) { |
1131 | - $code .= $this->code_fournisseur . ' - '; |
|
1131 | + $code .= $this->code_fournisseur.' - '; |
|
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1) { |
1135 | - $name = $code . ' ' . $name; |
|
1135 | + $name = $code.' '.$name; |
|
1136 | 1136 | } else { |
1137 | 1137 | $name = $code; |
1138 | 1138 | } |
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | if (!empty($this->name_alias)) |
1142 | - $name .= ' (' . $this->name_alias . ')'; |
|
1142 | + $name .= ' ('.$this->name_alias.')'; |
|
1143 | 1143 | |
1144 | 1144 | $result = ''; |
1145 | 1145 | $label = ''; |
@@ -1155,83 +1155,83 @@ discard block |
||
1155 | 1155 | $label .= '<div class="centpercent">'; |
1156 | 1156 | |
1157 | 1157 | if ($option == 'customer' || $option == 'compta' || $option == 'category' || $option == 'category_supplier') { |
1158 | - $label .= '<u>' . $langs->trans("ShowCustomer") . '</u>'; |
|
1158 | + $label .= '<u>'.$langs->trans("ShowCustomer").'</u>'; |
|
1159 | 1159 | // $linkstart = '<a href="' . DOL_URL_ROOT . '/comm/card.php?socid=' . $this->id; |
1160 | - $linkstart = '<a href="' . BASE_URI . '?controller=comm&method=card&socid=' . $this->id; |
|
1160 | + $linkstart = '<a href="'.BASE_URI.'?controller=comm&method=card&socid='.$this->id; |
|
1161 | 1161 | } elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) { |
1162 | - $label .= '<u>' . $langs->trans("ShowProspect") . '</u>'; |
|
1162 | + $label .= '<u>'.$langs->trans("ShowProspect").'</u>'; |
|
1163 | 1163 | // $linkstart = '<a href="' . DOL_URL_ROOT . '/comm/card.php?socid=' . $this->id; |
1164 | - $linkstart = '<a href="' . BASE_URI . '?controller=comm&method=card&socid=' . $this->id; |
|
1164 | + $linkstart = '<a href="'.BASE_URI.'?controller=comm&method=card&socid='.$this->id; |
|
1165 | 1165 | } elseif ($option == 'supplier') { |
1166 | - $label .= '<u>' . $langs->trans("ShowSupplier") . '</u>'; |
|
1166 | + $label .= '<u>'.$langs->trans("ShowSupplier").'</u>'; |
|
1167 | 1167 | // $linkstart = '<a href="' . DOL_URL_ROOT . '/fourn/card.php?socid=' . $this->id; |
1168 | - $linkstart = '<a href="' . BASE_URI . '?controller=fourn&method=card&socid=' . $this->id; |
|
1168 | + $linkstart = '<a href="'.BASE_URI.'?controller=fourn&method=card&socid='.$this->id; |
|
1169 | 1169 | } elseif ($option == 'agenda') { |
1170 | - $label .= '<u>' . $langs->trans("ShowAgenda") . '</u>'; |
|
1170 | + $label .= '<u>'.$langs->trans("ShowAgenda").'</u>'; |
|
1171 | 1171 | // $linkstart = '<a href="' . DOL_URL_ROOT . '/societe/agenda.php?socid=' . $this->id; |
1172 | - $linkstart = '<a href="' . BASE_URI . '?controller=societe&method=agenda&socid=' . $this->id; |
|
1172 | + $linkstart = '<a href="'.BASE_URI.'?controller=societe&method=agenda&socid='.$this->id; |
|
1173 | 1173 | } elseif ($option == 'project') { |
1174 | - $label .= '<u>' . $langs->trans("ShowProject") . '</u>'; |
|
1174 | + $label .= '<u>'.$langs->trans("ShowProject").'</u>'; |
|
1175 | 1175 | // $linkstart = '<a href="' . DOL_URL_ROOT . '/societe/project.php?socid=' . $this->id; |
1176 | - $linkstart = '<a href="' . BASE_URI . '?controller=societe&method=project&socid=' . $this->id; |
|
1176 | + $linkstart = '<a href="'.BASE_URI.'?controller=societe&method=project&socid='.$this->id; |
|
1177 | 1177 | } elseif ($option == 'margin') { |
1178 | - $label .= '<u>' . $langs->trans("ShowMargin") . '</u>'; |
|
1178 | + $label .= '<u>'.$langs->trans("ShowMargin").'</u>'; |
|
1179 | 1179 | // $linkstart = '<a href="' . DOL_URL_ROOT . '/margin/tabs/thirdpartyMargins.php?socid=' . $this->id . '&type=1'; |
1180 | - $linkstart = '<a href="' . BASE_URI . '?controller=margin/tabs&method=thirdpartyMargins&socid=' . $this->id . '&type=1'; |
|
1180 | + $linkstart = '<a href="'.BASE_URI.'?controller=margin/tabs&method=thirdpartyMargins&socid='.$this->id.'&type=1'; |
|
1181 | 1181 | } elseif ($option == 'contact') { |
1182 | - $label .= '<u>' . $langs->trans("ShowContacts") . '</u>'; |
|
1182 | + $label .= '<u>'.$langs->trans("ShowContacts").'</u>'; |
|
1183 | 1183 | // $linkstart = '<a href="' . DOL_URL_ROOT . '/societe/contact.php?socid=' . $this->id; |
1184 | - $linkstart = '<a href="' . BASE_URI . '?controller=societe&method=contact&socid=' . $this->id; |
|
1184 | + $linkstart = '<a href="'.BASE_URI.'?controller=societe&method=contact&socid='.$this->id; |
|
1185 | 1185 | } elseif ($option == 'ban') { |
1186 | - $label .= '<u>' . $langs->trans("ShowBan") . '</u>'; |
|
1186 | + $label .= '<u>'.$langs->trans("ShowBan").'</u>'; |
|
1187 | 1187 | // $linkstart = '<a href="' . DOL_URL_ROOT . '/societe/paymentmodes.php?socid=' . $this->id; |
1188 | - $linkstart = '<a href="' . BASE_URI . '?controller=societe&method=paymentmodes&socid=' . $this->id; |
|
1188 | + $linkstart = '<a href="'.BASE_URI.'?controller=societe&method=paymentmodes&socid='.$this->id; |
|
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | // By default |
1192 | 1192 | if (empty($linkstart)) { |
1193 | - $label .= '<u>' . $langs->trans("ShowCompany") . '</u>'; |
|
1193 | + $label .= '<u>'.$langs->trans("ShowCompany").'</u>'; |
|
1194 | 1194 | // $linkstart = '<a href="' . DOL_URL_ROOT . '/societe/card.php?socid=' . $this->id; |
1195 | - $linkstart = '<a href="' . BASE_URI . '?controller=societe&method=card&socid=' . $this->id; |
|
1195 | + $linkstart = '<a href="'.BASE_URI.'?controller=societe&method=card&socid='.$this->id; |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | 1198 | if (!empty($this->name)) { |
1199 | - $label .= '<br><b>' . $langs->trans('Name') . ':</b> ' . $this->name; |
|
1199 | + $label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->name; |
|
1200 | 1200 | if (!empty($this->name_alias)) |
1201 | - $label .= ' (' . $this->name_alias . ')'; |
|
1202 | - $label .= '<br><b>' . $langs->trans('Email') . ':</b> ' . $this->email; |
|
1201 | + $label .= ' ('.$this->name_alias.')'; |
|
1202 | + $label .= '<br><b>'.$langs->trans('Email').':</b> '.$this->email; |
|
1203 | 1203 | } |
1204 | 1204 | if (!empty($this->country_code)) |
1205 | - $label .= '<br><b>' . $langs->trans('Country') . ':</b> ' . $this->country_code; |
|
1205 | + $label .= '<br><b>'.$langs->trans('Country').':</b> '.$this->country_code; |
|
1206 | 1206 | if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false)) |
1207 | - $label .= '<br><b>' . $langs->trans('VATIntra') . ':</b> ' . $this->tva_intra; |
|
1207 | + $label .= '<br><b>'.$langs->trans('VATIntra').':</b> '.$this->tva_intra; |
|
1208 | 1208 | if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP)) { |
1209 | 1209 | if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) |
1210 | - $label .= '<br><b>' . $langs->trans('ProfId1' . $this->country_code) . ':</b> ' . $this->idprof1; |
|
1210 | + $label .= '<br><b>'.$langs->trans('ProfId1'.$this->country_code).':</b> '.$this->idprof1; |
|
1211 | 1211 | if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) |
1212 | - $label .= '<br><b>' . $langs->trans('ProfId2' . $this->country_code) . ':</b> ' . $this->idprof2; |
|
1212 | + $label .= '<br><b>'.$langs->trans('ProfId2'.$this->country_code).':</b> '.$this->idprof2; |
|
1213 | 1213 | if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) |
1214 | - $label .= '<br><b>' . $langs->trans('ProfId3' . $this->country_code) . ':</b> ' . $this->idprof3; |
|
1214 | + $label .= '<br><b>'.$langs->trans('ProfId3'.$this->country_code).':</b> '.$this->idprof3; |
|
1215 | 1215 | if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) |
1216 | - $label .= '<br><b>' . $langs->trans('ProfId4' . $this->country_code) . ':</b> ' . $this->idprof4; |
|
1216 | + $label .= '<br><b>'.$langs->trans('ProfId4'.$this->country_code).':</b> '.$this->idprof4; |
|
1217 | 1217 | if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) |
1218 | - $label .= '<br><b>' . $langs->trans('ProfId5' . $this->country_code) . ':</b> ' . $this->idprof5; |
|
1218 | + $label .= '<br><b>'.$langs->trans('ProfId5'.$this->country_code).':</b> '.$this->idprof5; |
|
1219 | 1219 | if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) |
1220 | - $label .= '<br><b>' . $langs->trans('ProfId6' . $this->country_code) . ':</b> ' . $this->idprof6; |
|
1220 | + $label .= '<br><b>'.$langs->trans('ProfId6'.$this->country_code).':</b> '.$this->idprof6; |
|
1221 | 1221 | } |
1222 | 1222 | if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3)) |
1223 | - $label .= '<br><b>' . $langs->trans('CustomerCode') . ':</b> ' . $this->code_client; |
|
1223 | + $label .= '<br><b>'.$langs->trans('CustomerCode').':</b> '.$this->code_client; |
|
1224 | 1224 | if (!empty($this->code_fournisseur) && $this->fournisseur) |
1225 | - $label .= '<br><b>' . $langs->trans('SupplierCode') . ':</b> ' . $this->code_fournisseur; |
|
1225 | + $label .= '<br><b>'.$langs->trans('SupplierCode').':</b> '.$this->code_fournisseur; |
|
1226 | 1226 | if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) |
1227 | - $label .= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> ' . ($this->code_compta ? $this->code_compta : $this->code_compta_client); |
|
1227 | + $label .= '<br><b>'.$langs->trans('CustomerAccountancyCode').':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client); |
|
1228 | 1228 | if (!empty($conf->accounting->enabled) && $this->fournisseur) |
1229 | - $label .= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> ' . $this->code_compta_fournisseur; |
|
1229 | + $label .= '<br><b>'.$langs->trans('SupplierAccountancyCode').':</b> '.$this->code_compta_fournisseur; |
|
1230 | 1230 | |
1231 | 1231 | $label .= '</div>'; |
1232 | 1232 | |
1233 | 1233 | // Add type of canvas |
1234 | - $linkstart .= (!empty($this->canvas) ? '&canvas=' . $this->canvas : ''); |
|
1234 | + $linkstart .= (!empty($this->canvas) ? '&canvas='.$this->canvas : ''); |
|
1235 | 1235 | // Add param to save lastsearch_values or not |
1236 | 1236 | $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
1237 | 1237 | if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) |
@@ -1244,9 +1244,9 @@ discard block |
||
1244 | 1244 | if (empty($notooltip)) { |
1245 | 1245 | if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { |
1246 | 1246 | $label = $langs->trans("ShowCompany"); |
1247 | - $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"'; |
|
1247 | + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
1248 | 1248 | } |
1249 | - $linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"'; |
|
1249 | + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
1250 | 1250 | $linkclose .= ' class="classfortooltip refurl"'; |
1251 | 1251 | |
1252 | 1252 | /* |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | if ($reshook > 0) $linkclose = $hookmanager->resPrint; |
1257 | 1257 | */ |
1258 | 1258 | } |
1259 | - $linkstart .= $linkclose . '>'; |
|
1259 | + $linkstart .= $linkclose.'>'; |
|
1260 | 1260 | $linkend = '</a>'; |
1261 | 1261 | |
1262 | 1262 | global $user; |
@@ -1267,7 +1267,7 @@ discard block |
||
1267 | 1267 | |
1268 | 1268 | $result .= $linkstart; |
1269 | 1269 | if ($withpicto) |
1270 | - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip valigntextbottom"'), 0, 0, $notooltip ? 0 : 1); |
|
1270 | + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip ? 0 : 1); |
|
1271 | 1271 | if ($withpicto != 2) |
1272 | 1272 | $result .= ($maxlen ? dol_trunc($name, $maxlen) : $name); |
1273 | 1273 | $result .= $linkend; |
@@ -1275,7 +1275,7 @@ discard block |
||
1275 | 1275 | global $action; |
1276 | 1276 | $hookmanager->initHooks(array('thirdpartydao')); |
1277 | 1277 | $parameters = array('id' => $this->id, 'getnomurl' => $result); |
1278 | - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
1278 | + $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
1279 | 1279 | if ($reshook > 0) |
1280 | 1280 | $result = $hookmanager->resPrint; |
1281 | 1281 | else |
@@ -1322,9 +1322,9 @@ discard block |
||
1322 | 1322 | return $langs->trans("InActivity"); |
1323 | 1323 | } elseif ($mode == 2) { |
1324 | 1324 | if ($statut == 0) |
1325 | - return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"') . ' ' . $langs->trans("ActivityCeased"); |
|
1325 | + return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased"); |
|
1326 | 1326 | elseif ($statut == 1) |
1327 | - return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"') . ' ' . $langs->trans("InActivity"); |
|
1327 | + return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity"); |
|
1328 | 1328 | } elseif ($mode == 3) { |
1329 | 1329 | if ($statut == 0) |
1330 | 1330 | return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"'); |
@@ -1332,19 +1332,19 @@ discard block |
||
1332 | 1332 | return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"'); |
1333 | 1333 | } elseif ($mode == 4) { |
1334 | 1334 | if ($statut == 0) |
1335 | - return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"') . ' ' . $langs->trans("ActivityCeased"); |
|
1335 | + return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased"); |
|
1336 | 1336 | elseif ($statut == 1) |
1337 | - return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"') . ' ' . $langs->trans("InActivity"); |
|
1337 | + return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity"); |
|
1338 | 1338 | } elseif ($mode == 5) { |
1339 | 1339 | if ($statut == 0) |
1340 | - return '<span class="hideonsmartphone">' . $langs->trans("ActivityCeased") . '</span> ' . img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"'); |
|
1340 | + return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"'); |
|
1341 | 1341 | elseif ($statut == 1) |
1342 | - return '<span class="hideonsmartphone">' . $langs->trans("InActivity") . '</span> ' . img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"'); |
|
1342 | + return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"'); |
|
1343 | 1343 | } elseif ($mode == 6) { |
1344 | 1344 | if ($statut == 0) |
1345 | - return '<span class="hideonsmartphone">' . $langs->trans("ActivityCeased") . '</span> ' . img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"'); |
|
1345 | + return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"'); |
|
1346 | 1346 | elseif ($statut == 1) |
1347 | - return '<span class="hideonsmartphone">' . $langs->trans("InActivity") . '</span> ' . img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"'); |
|
1347 | + return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"'); |
|
1348 | 1348 | } |
1349 | 1349 | } |
1350 | 1350 | |
@@ -1365,7 +1365,7 @@ discard block |
||
1365 | 1365 | if ($this->email && $addthirdparty) { |
1366 | 1366 | if (empty($this->name)) |
1367 | 1367 | $this->name = $this->nom; |
1368 | - $contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty") . ': ' . dol_trunc($this->name, 16) . " <" . $this->email . ">"; |
|
1368 | + $contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->email.">"; |
|
1369 | 1369 | } |
1370 | 1370 | //var_dump($contact_emails) |
1371 | 1371 | return $contact_emails; |
@@ -1389,8 +1389,8 @@ discard block |
||
1389 | 1389 | |
1390 | 1390 | |
1391 | 1391 | $sql = "SELECT rowid, email, statut, phone_mobile, lastname, poste, firstname"; |
1392 | - $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople"; |
|
1393 | - $sql .= " WHERE fk_soc = " . $this->id; |
|
1392 | + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople"; |
|
1393 | + $sql .= " WHERE fk_soc = ".$this->id; |
|
1394 | 1394 | |
1395 | 1395 | $resql = $this->db->query($sql); |
1396 | 1396 | if ($resql) { |
@@ -1423,9 +1423,9 @@ discard block |
||
1423 | 1423 | } |
1424 | 1424 | |
1425 | 1425 | if (!empty($obj->poste)) { |
1426 | - $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)) . ($obj->poste ? " - " . $obj->poste : "") . (($mode != 'poste' && $property) ? " " . $sepa . $property . $sepb : ''); |
|
1426 | + $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ? " - ".$obj->poste : "").(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : ''); |
|
1427 | 1427 | } else { |
1428 | - $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)) . (($mode != 'poste' && $property) ? " " . $sepa . $property . $sepb : ''); |
|
1428 | + $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : ''); |
|
1429 | 1429 | } |
1430 | 1430 | } |
1431 | 1431 | $i++; |
@@ -1453,7 +1453,7 @@ discard block |
||
1453 | 1453 | if (empty($this->name)) |
1454 | 1454 | $this->name = $this->nom; |
1455 | 1455 | // TODO: Tester si tel non deja present dans tableau contact |
1456 | - $contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty") . ': ' . dol_trunc($this->name, 16) . " <" . $this->phone . ">"; |
|
1456 | + $contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->phone.">"; |
|
1457 | 1457 | } |
1458 | 1458 | return $contact_phone; |
1459 | 1459 | } |
@@ -1468,7 +1468,7 @@ discard block |
||
1468 | 1468 | // phpcs:enable |
1469 | 1469 | $contacts = array(); |
1470 | 1470 | |
1471 | - $sql = "SELECT rowid, lastname, firstname FROM " . MAIN_DB_PREFIX . "socpeople WHERE fk_soc = " . $this->id; |
|
1471 | + $sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id; |
|
1472 | 1472 | $resql = $this->db->query($sql); |
1473 | 1473 | if ($resql) { |
1474 | 1474 | $nump = $this->db->num_rows($resql); |
@@ -1496,10 +1496,10 @@ discard block |
||
1496 | 1496 | function contact_array_objects() |
1497 | 1497 | { |
1498 | 1498 | // phpcs:enable |
1499 | - require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; |
|
1499 | + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
1500 | 1500 | $contacts = array(); |
1501 | 1501 | |
1502 | - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "socpeople WHERE fk_soc = " . $this->id; |
|
1502 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id; |
|
1503 | 1503 | $resql = $this->db->query($sql); |
1504 | 1504 | if ($resql) { |
1505 | 1505 | $nump = $this->db->num_rows($resql); |
@@ -1537,8 +1537,8 @@ discard block |
||
1537 | 1537 | return ''; |
1538 | 1538 | |
1539 | 1539 | $sql = "SELECT rowid, email, phone_mobile, lastname, firstname"; |
1540 | - $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople"; |
|
1541 | - $sql .= " WHERE rowid = '" . $rowid . "'"; |
|
1540 | + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople"; |
|
1541 | + $sql .= " WHERE rowid = '".$rowid."'"; |
|
1542 | 1542 | |
1543 | 1543 | $resql = $this->db->query($sql); |
1544 | 1544 | if ($resql) { |
@@ -1548,7 +1548,7 @@ discard block |
||
1548 | 1548 | $obj = $this->db->fetch_object($resql); |
1549 | 1549 | |
1550 | 1550 | if ($mode == 'email') |
1551 | - $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(",")) . " <" . $obj->email . ">"; |
|
1551 | + $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">"; |
|
1552 | 1552 | else if ($mode == 'mobile') |
1553 | 1553 | $contact_property = $obj->phone_mobile; |
1554 | 1554 | } |
@@ -1569,7 +1569,7 @@ discard block |
||
1569 | 1569 | function display_rib($mode = 'label') |
1570 | 1570 | { |
1571 | 1571 | // phpcs:enable |
1572 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php'; |
|
1572 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; |
|
1573 | 1573 | |
1574 | 1574 | $bac = new CompanyBankAccount($this->db); |
1575 | 1575 | $bac->fetch(0, $this->id); |
@@ -1578,7 +1578,7 @@ discard block |
||
1578 | 1578 | return $bac->getRibLabel(true); |
1579 | 1579 | } elseif ($mode == 'rum') { |
1580 | 1580 | if (empty($bac->rum)) { |
1581 | - require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php'; |
|
1581 | + require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; |
|
1582 | 1582 | $prelevement = new BonPrelevement($this->db); |
1583 | 1583 | $bac->fetch_thirdparty(); |
1584 | 1584 | $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id); |
@@ -1601,8 +1601,8 @@ discard block |
||
1601 | 1601 | function get_all_rib() |
1602 | 1602 | { |
1603 | 1603 | // phpcs:enable |
1604 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php'; |
|
1605 | - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "societe_rib WHERE type='ban' AND fk_soc = " . $this->id; |
|
1604 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; |
|
1605 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE type='ban' AND fk_soc = ".$this->id; |
|
1606 | 1606 | $result = $this->db->query($sql); |
1607 | 1607 | if (!$result) { |
1608 | 1608 | $this->error++; |
@@ -1639,14 +1639,14 @@ discard block |
||
1639 | 1639 | |
1640 | 1640 | $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); |
1641 | 1641 | foreach ($dirsociete as $dirroot) { |
1642 | - $res = dol_include_once($dirroot . $module . '.php'); |
|
1642 | + $res = dol_include_once($dirroot.$module.'.php'); |
|
1643 | 1643 | if ($res) |
1644 | 1644 | break; |
1645 | 1645 | } |
1646 | 1646 | |
1647 | 1647 | $mod = new $module(); |
1648 | 1648 | |
1649 | - dol_syslog(get_class($this) . "::codeclient_modifiable code_client=" . $this->code_client . " module=" . $module); |
|
1649 | + dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module); |
|
1650 | 1650 | if ($mod->code_modifiable_null && !$this->code_client) |
1651 | 1651 | return 1; |
1652 | 1652 | if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) |
@@ -1679,14 +1679,14 @@ discard block |
||
1679 | 1679 | |
1680 | 1680 | $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); |
1681 | 1681 | foreach ($dirsociete as $dirroot) { |
1682 | - $res = dol_include_once($dirroot . $module . '.php'); |
|
1682 | + $res = dol_include_once($dirroot.$module.'.php'); |
|
1683 | 1683 | if ($res) |
1684 | 1684 | break; |
1685 | 1685 | } |
1686 | 1686 | |
1687 | 1687 | $mod = new $module(); |
1688 | 1688 | |
1689 | - dol_syslog(get_class($this) . "::check_codeclient code_client=" . $this->code_client . " module=" . $module); |
|
1689 | + dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module); |
|
1690 | 1690 | $result = $mod->verif($this->db, $this->code_client, $this, 0); |
1691 | 1691 | return $result; |
1692 | 1692 | } else { |
@@ -1710,14 +1710,14 @@ discard block |
||
1710 | 1710 | |
1711 | 1711 | $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); |
1712 | 1712 | foreach ($dirsociete as $dirroot) { |
1713 | - $res = dol_include_once($dirroot . $module . '.php'); |
|
1713 | + $res = dol_include_once($dirroot.$module.'.php'); |
|
1714 | 1714 | if ($res) |
1715 | 1715 | break; |
1716 | 1716 | } |
1717 | 1717 | |
1718 | 1718 | $mod = new $module(); |
1719 | 1719 | |
1720 | - dol_syslog(get_class($this) . "::codefournisseur_modifiable code_founisseur=" . $this->code_fournisseur . " module=" . $module); |
|
1720 | + dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module); |
|
1721 | 1721 | if ($mod->code_modifiable_null && !$this->code_fournisseur) |
1722 | 1722 | return 1; |
1723 | 1723 | if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) |
@@ -1750,14 +1750,14 @@ discard block |
||
1750 | 1750 | |
1751 | 1751 | $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); |
1752 | 1752 | foreach ($dirsociete as $dirroot) { |
1753 | - $res = dol_include_once($dirroot . $module . '.php'); |
|
1753 | + $res = dol_include_once($dirroot.$module.'.php'); |
|
1754 | 1754 | if ($res) |
1755 | 1755 | break; |
1756 | 1756 | } |
1757 | 1757 | |
1758 | 1758 | $mod = new $module(); |
1759 | 1759 | |
1760 | - dol_syslog(get_class($this) . "::check_codefournisseur code_fournisseur=" . $this->code_fournisseur . " module=" . $module); |
|
1760 | + dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module); |
|
1761 | 1761 | $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1); |
1762 | 1762 | return $result; |
1763 | 1763 | } else { |
@@ -1777,10 +1777,10 @@ discard block |
||
1777 | 1777 | { |
1778 | 1778 | // phpcs:enable |
1779 | 1779 | if ($this->id) { |
1780 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "societe"; |
|
1781 | - $sql .= " SET parent = " . ($id > 0 ? $id : "null"); |
|
1782 | - $sql .= " WHERE rowid = " . $this->id; |
|
1783 | - dol_syslog(get_class($this) . '::set_parent', LOG_DEBUG); |
|
1780 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; |
|
1781 | + $sql .= " SET parent = ".($id > 0 ? $id : "null"); |
|
1782 | + $sql .= " WHERE rowid = ".$this->id; |
|
1783 | + dol_syslog(get_class($this).'::set_parent', LOG_DEBUG); |
|
1784 | 1784 | $resql = $this->db->query($sql); |
1785 | 1785 | if ($resql) { |
1786 | 1786 | $this->parent = $id; |
@@ -1828,7 +1828,7 @@ discard block |
||
1828 | 1828 | // on ajoute cette valeur à la somme totale |
1829 | 1829 | |
1830 | 1830 | for ($index = 0; $index < 9; $index++) { |
1831 | - $number = (int)$siren[$index]; |
|
1831 | + $number = (int) $siren[$index]; |
|
1832 | 1832 | if (($index % 2) != 0) { |
1833 | 1833 | if (($number *= 2) > 9) |
1834 | 1834 | $number -= 9; |
@@ -1857,7 +1857,7 @@ discard block |
||
1857 | 1857 | // on ajoute cette valeur à la somme totale |
1858 | 1858 | |
1859 | 1859 | for ($index = 0; $index < 14; $index++) { |
1860 | - $number = (int)$chaine[$index]; |
|
1860 | + $number = (int) $chaine[$index]; |
|
1861 | 1861 | if (($index % 2) == 0) { |
1862 | 1862 | if (($number *= 2) > 9) |
1863 | 1863 | $number -= 9; |
@@ -1970,7 +1970,7 @@ discard block |
||
1970 | 1970 | |
1971 | 1971 | $hookmanager->initHooks(array('idprofurl')); |
1972 | 1972 | $parameters = array('idprof' => $idprof, 'company' => $thirdparty); |
1973 | - $reshook = $hookmanager->executeHooks('getIdProfUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
1973 | + $reshook = $hookmanager->executeHooks('getIdProfUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
1974 | 1974 | if (empty($reshook)) { |
1975 | 1975 | if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) { |
1976 | 1976 | return ''; |
@@ -1979,23 +1979,23 @@ discard block |
||
1979 | 1979 | // TODO Move links to validate professional ID into a dictionary table "country" + "link" |
1980 | 1980 | $strippedIdProf1 = str_replace(' ', '', $thirdparty->idprof1); |
1981 | 1981 | if ($idprof == 1 && $thirdparty->country_code == 'FR') { |
1982 | - $url = 'http://www.societe.com/cgi-bin/search?champs=' . $strippedIdProf1; // See also http://avis-situation-sirene.insee.fr/ |
|
1982 | + $url = 'http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1; // See also http://avis-situation-sirene.insee.fr/ |
|
1983 | 1983 | } |
1984 | 1984 | if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) { |
1985 | - $url = 'https://beta.companieshouse.gov.uk/company/' . $strippedIdProf1; |
|
1985 | + $url = 'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1; |
|
1986 | 1986 | } |
1987 | 1987 | if ($idprof == 1 && $thirdparty->country_code == 'ES') { |
1988 | - $url = 'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/' . $strippedIdProf1; |
|
1988 | + $url = 'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1; |
|
1989 | 1989 | } |
1990 | 1990 | if ($idprof == 1 && $thirdparty->country_code == 'IN') { |
1991 | - $url = 'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber=' . $strippedIdProf1 . ';&searchBy=TIN&backPage=searchByTin_Inter.jsp'; |
|
1991 | + $url = 'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp'; |
|
1992 | 1992 | } |
1993 | 1993 | if ($idprof == 1 && $thirdparty->country_code == 'PT') { |
1994 | - $url = 'http://www.nif.pt/' . $strippedIdProf1; |
|
1994 | + $url = 'http://www.nif.pt/'.$strippedIdProf1; |
|
1995 | 1995 | } |
1996 | 1996 | |
1997 | 1997 | if ($url) { |
1998 | - return '<a target="_blank" href="' . $url . '">' . $langs->trans("Check") . '</a>'; |
|
1998 | + return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>'; |
|
1999 | 1999 | } |
2000 | 2000 | } else { |
2001 | 2001 | return $hookmanager->resPrint; |
@@ -2014,7 +2014,7 @@ discard block |
||
2014 | 2014 | function has_projects() |
2015 | 2015 | { |
2016 | 2016 | // phpcs:enable |
2017 | - $sql = 'SELECT COUNT(*) as numproj FROM ' . MAIN_DB_PREFIX . 'projet WHERE fk_soc = ' . $this->id; |
|
2017 | + $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = '.$this->id; |
|
2018 | 2018 | $resql = $this->db->query($sql); |
2019 | 2019 | if ($resql) { |
2020 | 2020 | $obj = $this->db->fetch_object($resql); |
@@ -2039,8 +2039,8 @@ discard block |
||
2039 | 2039 | { |
2040 | 2040 | $sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,"; |
2041 | 2041 | $sql .= " fk_user_creat, fk_user_modif"; |
2042 | - $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; |
|
2043 | - $sql .= " WHERE s.rowid = " . $id; |
|
2042 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
2043 | + $sql .= " WHERE s.rowid = ".$id; |
|
2044 | 2044 | |
2045 | 2045 | $result = $this->db->query($sql); |
2046 | 2046 | if ($result) { |
@@ -2081,7 +2081,7 @@ discard block |
||
2081 | 2081 | */ |
2082 | 2082 | function isInEEC() |
2083 | 2083 | { |
2084 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; |
|
2084 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
2085 | 2085 | return isInEEC($this); |
2086 | 2086 | } |
2087 | 2087 | |
@@ -2097,8 +2097,8 @@ discard block |
||
2097 | 2097 | // phpcs:enable |
2098 | 2098 | $this->SupplierCategories = array(); |
2099 | 2099 | $sql = "SELECT rowid, label"; |
2100 | - $sql .= " FROM " . MAIN_DB_PREFIX . "categorie"; |
|
2101 | - $sql .= " WHERE type = " . Categorie::TYPE_SUPPLIER; |
|
2100 | + $sql .= " FROM ".MAIN_DB_PREFIX."categorie"; |
|
2101 | + $sql .= " WHERE type = ".Categorie::TYPE_SUPPLIER; |
|
2102 | 2102 | |
2103 | 2103 | $resql = $this->db->query($sql); |
2104 | 2104 | if ($resql) { |
@@ -2123,8 +2123,8 @@ discard block |
||
2123 | 2123 | { |
2124 | 2124 | // phpcs:enable |
2125 | 2125 | if ($categorie_id > 0 && $this->id > 0) { |
2126 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "categorie_fournisseur (fk_categorie, fk_soc) "; |
|
2127 | - $sql .= " VALUES (" . $categorie_id . ", " . $this->id . ")"; |
|
2126 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) "; |
|
2127 | + $sql .= " VALUES (".$categorie_id.", ".$this->id.")"; |
|
2128 | 2128 | |
2129 | 2129 | if ($resql = $this->db->query($sql)) |
2130 | 2130 | return 0; |
@@ -2150,7 +2150,7 @@ discard block |
||
2150 | 2150 | // phpcs:enable |
2151 | 2151 | global $user, $langs; |
2152 | 2152 | |
2153 | - dol_syslog(get_class($this) . "::create_from_member", LOG_DEBUG); |
|
2153 | + dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); |
|
2154 | 2154 | |
2155 | 2155 | $name = $socname ? $socname : $member->societe; |
2156 | 2156 | if (empty($name)) |
@@ -2159,7 +2159,7 @@ discard block |
||
2159 | 2159 | $alias = $socalias ? $socalias : ''; |
2160 | 2160 | |
2161 | 2161 | // Positionne parametres |
2162 | - $this->nom = $name; // TODO deprecated |
|
2162 | + $this->nom = $name; // TODO deprecated |
|
2163 | 2163 | $this->name = $name; |
2164 | 2164 | $this->name_alias = $alias; |
2165 | 2165 | $this->address = $member->address; |
@@ -2167,13 +2167,13 @@ discard block |
||
2167 | 2167 | $this->town = $member->town; |
2168 | 2168 | $this->country_code = $member->country_code; |
2169 | 2169 | $this->country_id = $member->country_id; |
2170 | - $this->phone = $member->phone; // Prof phone |
|
2170 | + $this->phone = $member->phone; // Prof phone |
|
2171 | 2171 | $this->email = $member->email; |
2172 | 2172 | $this->skype = $member->skype; |
2173 | 2173 | $this->twitter = $member->twitter; |
2174 | 2174 | $this->facebook = $member->facebook; |
2175 | 2175 | |
2176 | - $this->client = 1; // A member is a customer by default |
|
2176 | + $this->client = 1; // A member is a customer by default |
|
2177 | 2177 | $this->code_client = ($customercode ? $customercode : -1); |
2178 | 2178 | $this->code_fournisseur = -1; |
2179 | 2179 | |
@@ -2182,9 +2182,9 @@ discard block |
||
2182 | 2182 | // Cree et positionne $this->id |
2183 | 2183 | $result = $this->create($user); |
2184 | 2184 | if ($result >= 0) { |
2185 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "adherent"; |
|
2186 | - $sql .= " SET fk_soc=" . $this->id; |
|
2187 | - $sql .= " WHERE rowid=" . $member->id; |
|
2185 | + $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; |
|
2186 | + $sql .= " SET fk_soc=".$this->id; |
|
2187 | + $sql .= " WHERE rowid=".$member->id; |
|
2188 | 2188 | |
2189 | 2189 | $resql = $this->db->query($sql); |
2190 | 2190 | if ($resql) { |
@@ -2198,7 +2198,7 @@ discard block |
||
2198 | 2198 | } |
2199 | 2199 | } else { |
2200 | 2200 | // $this->error deja positionne |
2201 | - dol_syslog(get_class($this) . "::create_from_member - 2 - " . $this->error . " - " . join(',', $this->errors), LOG_ERR); |
|
2201 | + dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',', $this->errors), LOG_ERR); |
|
2202 | 2202 | |
2203 | 2203 | $this->db->rollback(); |
2204 | 2204 | return $result; |
@@ -2245,7 +2245,7 @@ discard block |
||
2245 | 2245 | $this->fk_multicurrency = 0; |
2246 | 2246 | } |
2247 | 2247 | |
2248 | - dol_syslog(get_class($this) . "::create " . $this->name); |
|
2248 | + dol_syslog(get_class($this)."::create ".$this->name); |
|
2249 | 2249 | |
2250 | 2250 | $now = dol_now(); |
2251 | 2251 | |
@@ -2268,24 +2268,24 @@ discard block |
||
2268 | 2268 | $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); |
2269 | 2269 | } |
2270 | 2270 | |
2271 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)"; |
|
2272 | - $sql .= " VALUES ('" . $this->db->escape($this->name) . "', '" . $this->db->escape($this->name_alias) . "', " . $this->db->escape($this->entity) . ", '" . $this->db->idate($now) . "'"; |
|
2273 | - $sql .= ", " . (!empty($user->id) ? "'" . $user->id . "'" : "null"); |
|
2274 | - $sql .= ", " . (!empty($this->canvas) ? "'" . $this->db->escape($this->canvas) . "'" : "null"); |
|
2275 | - $sql .= ", " . $this->status; |
|
2276 | - $sql .= ", " . (!empty($this->ref_int) ? "'" . $this->db->escape($this->ref_int) . "'" : "null"); |
|
2277 | - $sql .= ", " . (!empty($this->ref_ext) ? "'" . $this->db->escape($this->ref_ext) . "'" : "null"); |
|
2271 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)"; |
|
2272 | + $sql .= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'"; |
|
2273 | + $sql .= ", ".(!empty($user->id) ? "'".$user->id."'" : "null"); |
|
2274 | + $sql .= ", ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null"); |
|
2275 | + $sql .= ", ".$this->status; |
|
2276 | + $sql .= ", ".(!empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'" : "null"); |
|
2277 | + $sql .= ", ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null"); |
|
2278 | 2278 | $sql .= ", 0"; |
2279 | - $sql .= ", " . (int)$this->fk_incoterms; |
|
2280 | - $sql .= ", '" . $this->db->escape($this->location_incoterms) . "'"; |
|
2281 | - $sql .= ", " . (!empty($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null"); |
|
2282 | - $sql .= ", " . (int)$this->fk_multicurrency; |
|
2283 | - $sql .= ", '" . $this->db->escape($this->multicurrency_code) . "')"; |
|
2279 | + $sql .= ", ".(int) $this->fk_incoterms; |
|
2280 | + $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; |
|
2281 | + $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); |
|
2282 | + $sql .= ", ".(int) $this->fk_multicurrency; |
|
2283 | + $sql .= ", '".$this->db->escape($this->multicurrency_code)."')"; |
|
2284 | 2284 | |
2285 | - dol_syslog(get_class($this) . "::create", LOG_DEBUG); |
|
2285 | + dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
2286 | 2286 | $result = $this->db->query($sql); |
2287 | 2287 | if ($result) { |
2288 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "societe"); |
|
2288 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe"); |
|
2289 | 2289 | |
2290 | 2290 | $ret = $this->update($this->id, $user, 0, 1, 1, 'add'); |
2291 | 2291 | |
@@ -2307,17 +2307,17 @@ discard block |
||
2307 | 2307 | $error++; |
2308 | 2308 | |
2309 | 2309 | if (!$error) { |
2310 | - dol_syslog(get_class($this) . "::Create success id=" . $this->id); |
|
2310 | + dol_syslog(get_class($this)."::Create success id=".$this->id); |
|
2311 | 2311 | $this->db->commit(); |
2312 | 2312 | return $this->id; |
2313 | 2313 | } else { |
2314 | - dol_syslog(get_class($this) . "::Create echec update " . $this->error . " " . join(',', $this->errors), LOG_ERR); |
|
2314 | + dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',', $this->errors), LOG_ERR); |
|
2315 | 2315 | $this->db->rollback(); |
2316 | 2316 | return -4; |
2317 | 2317 | } |
2318 | 2318 | } else { |
2319 | 2319 | if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { |
2320 | - $this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); // duplicate on a field (code or profid or ...) |
|
2320 | + $this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); // duplicate on a field (code or profid or ...) |
|
2321 | 2321 | $result = -1; |
2322 | 2322 | } else { |
2323 | 2323 | $this->error = $this->db->lasterror(); |
@@ -2328,7 +2328,7 @@ discard block |
||
2328 | 2328 | } |
2329 | 2329 | } else { |
2330 | 2330 | $this->db->rollback(); |
2331 | - dol_syslog(get_class($this) . "::Create fails verify " . join(',', $this->errors), LOG_WARNING); |
|
2331 | + dol_syslog(get_class($this)."::Create fails verify ".join(',', $this->errors), LOG_WARNING); |
|
2332 | 2332 | return -3; |
2333 | 2333 | } |
2334 | 2334 | } |
@@ -2352,7 +2352,7 @@ discard block |
||
2352 | 2352 | |
2353 | 2353 | $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); |
2354 | 2354 | foreach ($dirsociete as $dirroot) { |
2355 | - $res = dol_include_once($dirroot . $module . '.php'); |
|
2355 | + $res = dol_include_once($dirroot.$module.'.php'); |
|
2356 | 2356 | if ($res) |
2357 | 2357 | break; |
2358 | 2358 | } |
@@ -2361,7 +2361,7 @@ discard block |
||
2361 | 2361 | $this->code_client = $mod->getNextValue($objsoc, $type); |
2362 | 2362 | $this->prefixCustomerIsRequired = $mod->prefixIsRequired; |
2363 | 2363 | |
2364 | - dol_syslog(get_class($this) . "::get_codeclient code_client=" . $this->code_client . " module=" . $module); |
|
2364 | + dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$module); |
|
2365 | 2365 | } |
2366 | 2366 | } |
2367 | 2367 | |
@@ -2384,7 +2384,7 @@ discard block |
||
2384 | 2384 | |
2385 | 2385 | $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); |
2386 | 2386 | foreach ($dirsociete as $dirroot) { |
2387 | - $res = dol_include_once($dirroot . $module . '.php'); |
|
2387 | + $res = dol_include_once($dirroot.$module.'.php'); |
|
2388 | 2388 | if ($res) |
2389 | 2389 | break; |
2390 | 2390 | } |
@@ -2392,7 +2392,7 @@ discard block |
||
2392 | 2392 | |
2393 | 2393 | $this->code_fournisseur = $mod->getNextValue($objsoc, $type); |
2394 | 2394 | |
2395 | - dol_syslog(get_class($this) . "::get_codefournisseur code_fournisseur=" . $this->code_fournisseur . " module=" . $module); |
|
2395 | + dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module); |
|
2396 | 2396 | } |
2397 | 2397 | } |
2398 | 2398 | |
@@ -2456,7 +2456,7 @@ discard block |
||
2456 | 2456 | $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL'); |
2457 | 2457 | foreach ($array_to_check as $key) { |
2458 | 2458 | $keymin = strtolower($key); |
2459 | - $i = (int)preg_replace('/[^0-9]/', '', $key); |
|
2459 | + $i = (int) preg_replace('/[^0-9]/', '', $key); |
|
2460 | 2460 | $vallabel = $this->$keymin; |
2461 | 2461 | |
2462 | 2462 | if ($i > 0) { |
@@ -2466,17 +2466,17 @@ discard block |
||
2466 | 2466 | if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { |
2467 | 2467 | $langs->load("errors"); |
2468 | 2468 | $error++; |
2469 | - $this->errors[] = $langs->transcountry('ProfId' . $i, $this->country_code) . " " . $langs->trans("ErrorProdIdAlreadyExist", $vallabel) . ' (' . $langs->trans("ForbiddenBySetupRules") . ')'; |
|
2469 | + $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; |
|
2470 | 2470 | } |
2471 | 2471 | } |
2472 | 2472 | |
2473 | 2473 | // Check for mandatory prof id (but only if country is other than ours) |
2474 | 2474 | if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) { |
2475 | - $idprof_mandatory = 'SOCIETE_' . $key . '_MANDATORY'; |
|
2475 | + $idprof_mandatory = 'SOCIETE_'.$key.'_MANDATORY'; |
|
2476 | 2476 | if (!$vallabel && !empty($conf->global->$idprof_mandatory)) { |
2477 | 2477 | $langs->load("errors"); |
2478 | 2478 | $error++; |
2479 | - $this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId' . $i, $this->country_code)) . ' (' . $langs->trans("ForbiddenBySetupRules") . ')'; |
|
2479 | + $this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')'; |
|
2480 | 2480 | } |
2481 | 2481 | } |
2482 | 2482 | } |
@@ -2489,7 +2489,7 @@ discard block |
||
2489 | 2489 | if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { |
2490 | 2490 | $langs->load("errors"); |
2491 | 2491 | $error++; |
2492 | - $this->errors[] = $langs->trans('Email') . " " . $langs->trans("ErrorProdIdAlreadyExist", $vallabel) . ' (' . $langs->trans("ForbiddenBySetupRules") . ')'; |
|
2492 | + $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; |
|
2493 | 2493 | } |
2494 | 2494 | } |
2495 | 2495 | |
@@ -2497,7 +2497,7 @@ discard block |
||
2497 | 2497 | if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) { |
2498 | 2498 | $langs->load("errors"); |
2499 | 2499 | $error++; |
2500 | - $this->errors[] = $langs->trans("ErrorBadEMail", $this->email) . ' (' . $langs->trans("ForbiddenBySetupRules") . ')'; |
|
2500 | + $this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')'; |
|
2501 | 2501 | } |
2502 | 2502 | } |
2503 | 2503 | } |
@@ -2611,9 +2611,9 @@ discard block |
||
2611 | 2611 | } |
2612 | 2612 | |
2613 | 2613 | //Verify duplicate entries |
2614 | - $sql = "SELECT COUNT(*) as idprof FROM " . MAIN_DB_PREFIX . "societe WHERE " . $field . " = '" . $value . "' AND entity IN (" . getEntity('societe') . ")"; |
|
2614 | + $sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")"; |
|
2615 | 2615 | if ($socid) |
2616 | - $sql .= " AND rowid <> " . $socid; |
|
2616 | + $sql .= " AND rowid <> ".$socid; |
|
2617 | 2617 | $resql = $this->db->query($sql); |
2618 | 2618 | if ($resql) { |
2619 | 2619 | $obj = $this->db->fetch_object($resql); |
@@ -2646,14 +2646,14 @@ discard block |
||
2646 | 2646 | { |
2647 | 2647 | global $langs, $conf, $hookmanager; |
2648 | 2648 | |
2649 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; |
|
2649 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
2650 | 2650 | |
2651 | 2651 | if (empty($id)) |
2652 | 2652 | $id = $this->id; |
2653 | 2653 | |
2654 | 2654 | $error = 0; |
2655 | 2655 | |
2656 | - dol_syslog(get_class($this) . "::Update id=" . $id . " call_trigger=" . $call_trigger . " allowmodcodeclient=" . $allowmodcodeclient . " allowmodcodefournisseur=" . $allowmodcodefournisseur); |
|
2656 | + dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur); |
|
2657 | 2657 | |
2658 | 2658 | $now = dol_now(); |
2659 | 2659 | |
@@ -2715,7 +2715,7 @@ discard block |
||
2715 | 2715 | if ($this->capital != '') |
2716 | 2716 | $this->capital = price2num(trim($this->capital)); |
2717 | 2717 | if (!is_numeric($this->capital)) |
2718 | - $this->capital = ''; // '' = undef |
|
2718 | + $this->capital = ''; // '' = undef |
|
2719 | 2719 | |
2720 | 2720 | $this->effectif_id = trim($this->effectif_id); |
2721 | 2721 | $this->forme_juridique_code = trim($this->forme_juridique_code); |
@@ -2768,7 +2768,7 @@ discard block |
||
2768 | 2768 | $this->webservices_key = trim($this->webservices_key); |
2769 | 2769 | |
2770 | 2770 | //Incoterms |
2771 | - $this->fk_incoterms = (int)$this->fk_incoterms; |
|
2771 | + $this->fk_incoterms = (int) $this->fk_incoterms; |
|
2772 | 2772 | $this->location_incoterms = trim($this->location_incoterms); |
2773 | 2773 | |
2774 | 2774 | $this->db->begin(); |
@@ -2799,51 +2799,51 @@ discard block |
||
2799 | 2799 | } |
2800 | 2800 | |
2801 | 2801 | if ($result >= 0) { |
2802 | - dol_syslog(get_class($this) . "::update verify ok or not done"); |
|
2802 | + dol_syslog(get_class($this)."::update verify ok or not done"); |
|
2803 | 2803 | |
2804 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "societe SET "; |
|
2805 | - $sql .= "entity = " . $this->db->escape($this->entity); |
|
2806 | - $sql .= ",nom = '" . $this->db->escape($this->name) . "'"; // Required |
|
2807 | - $sql .= ",name_alias = '" . $this->db->escape($this->name_alias) . "'"; |
|
2808 | - $sql .= ",ref_ext = " . (!empty($this->ref_ext) ? "'" . $this->db->escape($this->ref_ext) . "'" : "null"); |
|
2809 | - $sql .= ",address = '" . $this->db->escape($this->address) . "'"; |
|
2804 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET "; |
|
2805 | + $sql .= "entity = ".$this->db->escape($this->entity); |
|
2806 | + $sql .= ",nom = '".$this->db->escape($this->name)."'"; // Required |
|
2807 | + $sql .= ",name_alias = '".$this->db->escape($this->name_alias)."'"; |
|
2808 | + $sql .= ",ref_ext = ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null"); |
|
2809 | + $sql .= ",address = '".$this->db->escape($this->address)."'"; |
|
2810 | 2810 | |
2811 | - $sql .= ",zip = " . (!empty($this->zip) ? "'" . $this->db->escape($this->zip) . "'" : "null"); |
|
2812 | - $sql .= ",town = " . (!empty($this->town) ? "'" . $this->db->escape($this->town) . "'" : "null"); |
|
2811 | + $sql .= ",zip = ".(!empty($this->zip) ? "'".$this->db->escape($this->zip)."'" : "null"); |
|
2812 | + $sql .= ",town = ".(!empty($this->town) ? "'".$this->db->escape($this->town)."'" : "null"); |
|
2813 | 2813 | |
2814 | - $sql .= ",fk_departement = '" . (!empty($this->state_id) ? $this->state_id : '0') . "'"; |
|
2815 | - $sql .= ",fk_pays = '" . (!empty($this->country_id) ? $this->country_id : '0') . "'"; |
|
2814 | + $sql .= ",fk_departement = '".(!empty($this->state_id) ? $this->state_id : '0')."'"; |
|
2815 | + $sql .= ",fk_pays = '".(!empty($this->country_id) ? $this->country_id : '0')."'"; |
|
2816 | 2816 | |
2817 | - $sql .= ",phone = " . (!empty($this->phone) ? "'" . $this->db->escape($this->phone) . "'" : "null"); |
|
2818 | - $sql .= ",fax = " . (!empty($this->fax) ? "'" . $this->db->escape($this->fax) . "'" : "null"); |
|
2819 | - $sql .= ",email = " . (!empty($this->email) ? "'" . $this->db->escape($this->email) . "'" : "null"); |
|
2820 | - $sql .= ",skype = " . (!empty($this->skype) ? "'" . $this->db->escape($this->skype) . "'" : "null"); |
|
2821 | - $sql .= ",twitter = " . (!empty($this->twitter) ? "'" . $this->db->escape($this->twitter) . "'" : "null"); |
|
2822 | - $sql .= ",facebook = " . (!empty($this->facebook) ? "'" . $this->db->escape($this->facebook) . "'" : "null"); |
|
2823 | - $sql .= ",url = " . (!empty($this->url) ? "'" . $this->db->escape($this->url) . "'" : "null"); |
|
2817 | + $sql .= ",phone = ".(!empty($this->phone) ? "'".$this->db->escape($this->phone)."'" : "null"); |
|
2818 | + $sql .= ",fax = ".(!empty($this->fax) ? "'".$this->db->escape($this->fax)."'" : "null"); |
|
2819 | + $sql .= ",email = ".(!empty($this->email) ? "'".$this->db->escape($this->email)."'" : "null"); |
|
2820 | + $sql .= ",skype = ".(!empty($this->skype) ? "'".$this->db->escape($this->skype)."'" : "null"); |
|
2821 | + $sql .= ",twitter = ".(!empty($this->twitter) ? "'".$this->db->escape($this->twitter)."'" : "null"); |
|
2822 | + $sql .= ",facebook = ".(!empty($this->facebook) ? "'".$this->db->escape($this->facebook)."'" : "null"); |
|
2823 | + $sql .= ",url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null"); |
|
2824 | 2824 | |
2825 | - $sql .= ",parent = " . ($this->parent > 0 ? $this->parent : "null"); |
|
2825 | + $sql .= ",parent = ".($this->parent > 0 ? $this->parent : "null"); |
|
2826 | 2826 | |
2827 | - $sql .= ",note_private = " . (!empty($this->note_private) ? "'" . $this->db->escape($this->note_private) . "'" : "null"); |
|
2828 | - $sql .= ",note_public = " . (!empty($this->note_public) ? "'" . $this->db->escape($this->note_public) . "'" : "null"); |
|
2827 | + $sql .= ",note_private = ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null"); |
|
2828 | + $sql .= ",note_public = ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null"); |
|
2829 | 2829 | |
2830 | - $sql .= ",siren = '" . $this->db->escape($this->idprof1) . "'"; |
|
2831 | - $sql .= ",siret = '" . $this->db->escape($this->idprof2) . "'"; |
|
2832 | - $sql .= ",ape = '" . $this->db->escape($this->idprof3) . "'"; |
|
2833 | - $sql .= ",idprof4 = '" . $this->db->escape($this->idprof4) . "'"; |
|
2834 | - $sql .= ",idprof5 = '" . $this->db->escape($this->idprof5) . "'"; |
|
2835 | - $sql .= ",idprof6 = '" . $this->db->escape($this->idprof6) . "'"; |
|
2830 | + $sql .= ",siren = '".$this->db->escape($this->idprof1)."'"; |
|
2831 | + $sql .= ",siret = '".$this->db->escape($this->idprof2)."'"; |
|
2832 | + $sql .= ",ape = '".$this->db->escape($this->idprof3)."'"; |
|
2833 | + $sql .= ",idprof4 = '".$this->db->escape($this->idprof4)."'"; |
|
2834 | + $sql .= ",idprof5 = '".$this->db->escape($this->idprof5)."'"; |
|
2835 | + $sql .= ",idprof6 = '".$this->db->escape($this->idprof6)."'"; |
|
2836 | 2836 | |
2837 | - $sql .= ",tva_assuj = " . ($this->tva_assuj != '' ? "'" . $this->db->escape($this->tva_assuj) . "'" : "null"); |
|
2838 | - $sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) . "'"; |
|
2839 | - $sql .= ",status = " . $this->status; |
|
2837 | + $sql .= ",tva_assuj = ".($this->tva_assuj != '' ? "'".$this->db->escape($this->tva_assuj)."'" : "null"); |
|
2838 | + $sql .= ",tva_intra = '".$this->db->escape($this->tva_intra)."'"; |
|
2839 | + $sql .= ",status = ".$this->status; |
|
2840 | 2840 | |
2841 | 2841 | // Local taxes |
2842 | - $sql .= ",localtax1_assuj = " . ($this->localtax1_assuj != '' ? "'" . $this->db->escape($this->localtax1_assuj) . "'" : "null"); |
|
2843 | - $sql .= ",localtax2_assuj = " . ($this->localtax2_assuj != '' ? "'" . $this->db->escape($this->localtax2_assuj) . "'" : "null"); |
|
2842 | + $sql .= ",localtax1_assuj = ".($this->localtax1_assuj != '' ? "'".$this->db->escape($this->localtax1_assuj)."'" : "null"); |
|
2843 | + $sql .= ",localtax2_assuj = ".($this->localtax2_assuj != '' ? "'".$this->db->escape($this->localtax2_assuj)."'" : "null"); |
|
2844 | 2844 | if ($this->localtax1_assuj == 1) { |
2845 | 2845 | if ($this->localtax1_value != '') { |
2846 | - $sql .= ",localtax1_value =" . $this->localtax1_value; |
|
2846 | + $sql .= ",localtax1_value =".$this->localtax1_value; |
|
2847 | 2847 | } else |
2848 | 2848 | $sql .= ",localtax1_value =0.000"; |
2849 | 2849 | } else |
@@ -2851,60 +2851,60 @@ discard block |
||
2851 | 2851 | |
2852 | 2852 | if ($this->localtax2_assuj == 1) { |
2853 | 2853 | if ($this->localtax2_value != '') { |
2854 | - $sql .= ",localtax2_value =" . $this->localtax2_value; |
|
2854 | + $sql .= ",localtax2_value =".$this->localtax2_value; |
|
2855 | 2855 | } else |
2856 | 2856 | $sql .= ",localtax2_value =0.000"; |
2857 | 2857 | } else |
2858 | 2858 | $sql .= ",localtax2_value =0.000"; |
2859 | 2859 | |
2860 | - $sql .= ",capital = " . ($this->capital == '' ? "null" : $this->capital); |
|
2860 | + $sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital); |
|
2861 | 2861 | |
2862 | - $sql .= ",prefix_comm = " . (!empty($this->prefix_comm) ? "'" . $this->db->escape($this->prefix_comm) . "'" : "null"); |
|
2862 | + $sql .= ",prefix_comm = ".(!empty($this->prefix_comm) ? "'".$this->db->escape($this->prefix_comm)."'" : "null"); |
|
2863 | 2863 | |
2864 | - $sql .= ",fk_effectif = " . (!empty($this->effectif_id) ? "'" . $this->db->escape($this->effectif_id) . "'" : "null"); |
|
2864 | + $sql .= ",fk_effectif = ".(!empty($this->effectif_id) ? "'".$this->db->escape($this->effectif_id)."'" : "null"); |
|
2865 | 2865 | if (isset($this->stcomm_id)) { |
2866 | - $sql .= ",fk_stcomm=" . (!empty($this->stcomm_id) ? $this->stcomm_id : "0"); |
|
2866 | + $sql .= ",fk_stcomm=".(!empty($this->stcomm_id) ? $this->stcomm_id : "0"); |
|
2867 | 2867 | } |
2868 | - $sql .= ",fk_typent = " . (!empty($this->typent_id) ? "'" . $this->db->escape($this->typent_id) . "'" : "0"); |
|
2868 | + $sql .= ",fk_typent = ".(!empty($this->typent_id) ? "'".$this->db->escape($this->typent_id)."'" : "0"); |
|
2869 | 2869 | |
2870 | - $sql .= ",fk_forme_juridique = " . (!empty($this->forme_juridique_code) ? "'" . $this->db->escape($this->forme_juridique_code) . "'" : "null"); |
|
2870 | + $sql .= ",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ? "'".$this->db->escape($this->forme_juridique_code)."'" : "null"); |
|
2871 | 2871 | |
2872 | - $sql .= ",mode_reglement = " . (!empty($this->mode_reglement_id) ? "'" . $this->db->escape($this->mode_reglement_id) . "'" : "null"); |
|
2873 | - $sql .= ",cond_reglement = " . (!empty($this->cond_reglement_id) ? "'" . $this->db->escape($this->cond_reglement_id) . "'" : "null"); |
|
2874 | - $sql .= ",mode_reglement_supplier = " . (!empty($this->mode_reglement_supplier_id) ? "'" . $this->db->escape($this->mode_reglement_supplier_id) . "'" : "null"); |
|
2875 | - $sql .= ",cond_reglement_supplier = " . (!empty($this->cond_reglement_supplier_id) ? "'" . $this->db->escape($this->cond_reglement_supplier_id) . "'" : "null"); |
|
2876 | - $sql .= ",fk_shipping_method = " . (!empty($this->shipping_method_id) ? "'" . $this->db->escape($this->shipping_method_id) . "'" : "null"); |
|
2872 | + $sql .= ",mode_reglement = ".(!empty($this->mode_reglement_id) ? "'".$this->db->escape($this->mode_reglement_id)."'" : "null"); |
|
2873 | + $sql .= ",cond_reglement = ".(!empty($this->cond_reglement_id) ? "'".$this->db->escape($this->cond_reglement_id)."'" : "null"); |
|
2874 | + $sql .= ",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ? "'".$this->db->escape($this->mode_reglement_supplier_id)."'" : "null"); |
|
2875 | + $sql .= ",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ? "'".$this->db->escape($this->cond_reglement_supplier_id)."'" : "null"); |
|
2876 | + $sql .= ",fk_shipping_method = ".(!empty($this->shipping_method_id) ? "'".$this->db->escape($this->shipping_method_id)."'" : "null"); |
|
2877 | 2877 | |
2878 | - $sql .= ",client = " . (!empty($this->client) ? $this->client : 0); |
|
2879 | - $sql .= ",fournisseur = " . (!empty($this->fournisseur) ? $this->fournisseur : 0); |
|
2880 | - $sql .= ",barcode = " . (!empty($this->barcode) ? "'" . $this->db->escape($this->barcode) . "'" : "null"); |
|
2881 | - $sql .= ",default_lang = " . (!empty($this->default_lang) ? "'" . $this->db->escape($this->default_lang) . "'" : "null"); |
|
2882 | - $sql .= ",logo = " . (!empty($this->logo) ? "'" . $this->db->escape($this->logo) . "'" : "null"); |
|
2883 | - $sql .= ",outstanding_limit= " . ($this->outstanding_limit != '' ? $this->outstanding_limit : 'null'); |
|
2884 | - $sql .= ",order_min_amount= " . ($this->order_min_amount != '' ? $this->order_min_amount : 'null'); |
|
2885 | - $sql .= ",supplier_order_min_amount= " . ($this->supplier_order_min_amount != '' ? $this->supplier_order_min_amount : 'null'); |
|
2886 | - $sql .= ",fk_prospectlevel='" . $this->db->escape($this->fk_prospectlevel) . "'"; |
|
2878 | + $sql .= ",client = ".(!empty($this->client) ? $this->client : 0); |
|
2879 | + $sql .= ",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0); |
|
2880 | + $sql .= ",barcode = ".(!empty($this->barcode) ? "'".$this->db->escape($this->barcode)."'" : "null"); |
|
2881 | + $sql .= ",default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null"); |
|
2882 | + $sql .= ",logo = ".(!empty($this->logo) ? "'".$this->db->escape($this->logo)."'" : "null"); |
|
2883 | + $sql .= ",outstanding_limit= ".($this->outstanding_limit != '' ? $this->outstanding_limit : 'null'); |
|
2884 | + $sql .= ",order_min_amount= ".($this->order_min_amount != '' ? $this->order_min_amount : 'null'); |
|
2885 | + $sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount != '' ? $this->supplier_order_min_amount : 'null'); |
|
2886 | + $sql .= ",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel)."'"; |
|
2887 | 2887 | |
2888 | - $sql .= ",webservices_url = " . (!empty($this->webservices_url) ? "'" . $this->db->escape($this->webservices_url) . "'" : "null"); |
|
2889 | - $sql .= ",webservices_key = " . (!empty($this->webservices_key) ? "'" . $this->db->escape($this->webservices_key) . "'" : "null"); |
|
2888 | + $sql .= ",webservices_url = ".(!empty($this->webservices_url) ? "'".$this->db->escape($this->webservices_url)."'" : "null"); |
|
2889 | + $sql .= ",webservices_key = ".(!empty($this->webservices_key) ? "'".$this->db->escape($this->webservices_key)."'" : "null"); |
|
2890 | 2890 | |
2891 | 2891 | //Incoterms |
2892 | - $sql .= ", fk_incoterms = " . $this->fk_incoterms; |
|
2893 | - $sql .= ", location_incoterms = " . (!empty($this->location_incoterms) ? "'" . $this->db->escape($this->location_incoterms) . "'" : "null"); |
|
2892 | + $sql .= ", fk_incoterms = ".$this->fk_incoterms; |
|
2893 | + $sql .= ", location_incoterms = ".(!empty($this->location_incoterms) ? "'".$this->db->escape($this->location_incoterms)."'" : "null"); |
|
2894 | 2894 | |
2895 | 2895 | if ($customer) { |
2896 | - $sql .= ", code_client = " . (!empty($this->code_client) ? "'" . $this->db->escape($this->code_client) . "'" : "null"); |
|
2897 | - $sql .= ", code_compta = " . (!empty($this->code_compta) ? "'" . $this->db->escape($this->code_compta) . "'" : "null"); |
|
2896 | + $sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null"); |
|
2897 | + $sql .= ", code_compta = ".(!empty($this->code_compta) ? "'".$this->db->escape($this->code_compta)."'" : "null"); |
|
2898 | 2898 | } |
2899 | 2899 | |
2900 | 2900 | if ($supplier) { |
2901 | - $sql .= ", code_fournisseur = " . (!empty($this->code_fournisseur) ? "'" . $this->db->escape($this->code_fournisseur) . "'" : "null"); |
|
2902 | - $sql .= ", code_compta_fournisseur = " . (!empty($this->code_compta_fournisseur) ? "'" . $this->db->escape($this->code_compta_fournisseur) . "'" : "null"); |
|
2901 | + $sql .= ", code_fournisseur = ".(!empty($this->code_fournisseur) ? "'".$this->db->escape($this->code_fournisseur)."'" : "null"); |
|
2902 | + $sql .= ", code_compta_fournisseur = ".(!empty($this->code_compta_fournisseur) ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null"); |
|
2903 | 2903 | } |
2904 | - $sql .= ", fk_user_modif = " . ($user->id > 0 ? $user->id : "null"); |
|
2905 | - $sql .= ", fk_multicurrency = " . (int)$this->fk_multicurrency; |
|
2906 | - $sql .= ", multicurrency_code = '" . $this->db->escape($this->multicurrency_code) . "'"; |
|
2907 | - $sql .= " WHERE rowid = " . (int)$id; |
|
2904 | + $sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id : "null"); |
|
2905 | + $sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency; |
|
2906 | + $sql .= ", multicurrency_code = '".$this->db->escape($this->multicurrency_code)."'"; |
|
2907 | + $sql .= " WHERE rowid = ".(int) $id; |
|
2908 | 2908 | |
2909 | 2909 | $resql = $this->db->query($sql); |
2910 | 2910 | if ($resql) { |
@@ -2929,9 +2929,9 @@ discard block |
||
2929 | 2929 | if (!$error && $nbrowsaffected) { |
2930 | 2930 | // Update information on linked member if it is an update |
2931 | 2931 | if (!$nosyncmember && !empty($conf->adherent->enabled)) { |
2932 | - require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; |
|
2932 | + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; |
|
2933 | 2933 | |
2934 | - dol_syslog(get_class($this) . "::update update linked member"); |
|
2934 | + dol_syslog(get_class($this)."::update update linked member"); |
|
2935 | 2935 | |
2936 | 2936 | $lmember = new Adherent($this->db); |
2937 | 2937 | $result = $lmember->fetch(0, 0, $this->id); |
@@ -2950,7 +2950,7 @@ discard block |
||
2950 | 2950 | $result = $lmember->update($user, 0, 1, 1, 1); // Use nosync to 1 to avoid cyclic updates |
2951 | 2951 | if ($result < 0) { |
2952 | 2952 | $this->error = $lmember->error; |
2953 | - dol_syslog(get_class($this) . "::update " . $this->error, LOG_ERR); |
|
2953 | + dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR); |
|
2954 | 2954 | $error++; |
2955 | 2955 | } |
2956 | 2956 | } elseif ($result < 0) { |
@@ -2979,7 +2979,7 @@ discard block |
||
2979 | 2979 | } |
2980 | 2980 | |
2981 | 2981 | if (!$error) { |
2982 | - dol_syslog(get_class($this) . "::Update success"); |
|
2982 | + dol_syslog(get_class($this)."::Update success"); |
|
2983 | 2983 | $this->db->commit(); |
2984 | 2984 | return 1; |
2985 | 2985 | } else { |
@@ -3000,7 +3000,7 @@ discard block |
||
3000 | 3000 | } |
3001 | 3001 | } else { |
3002 | 3002 | $this->db->rollback(); |
3003 | - dol_syslog(get_class($this) . "::Update fails verify " . join(',', $this->errors), LOG_WARNING); |
|
3003 | + dol_syslog(get_class($this)."::Update fails verify ".join(',', $this->errors), LOG_WARNING); |
|
3004 | 3004 | return -3; |
3005 | 3005 | } |
3006 | 3006 | } |
@@ -3024,7 +3024,7 @@ discard block |
||
3024 | 3024 | $res = false; |
3025 | 3025 | $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); |
3026 | 3026 | foreach ($dirsociete as $dirroot) { |
3027 | - $res = dol_include_once($dirroot . $conf->global->SOCIETE_CODECOMPTA_ADDON . '.php'); |
|
3027 | + $res = dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php'); |
|
3028 | 3028 | if ($res) |
3029 | 3029 | break; |
3030 | 3030 | } |
@@ -3072,17 +3072,17 @@ discard block |
||
3072 | 3072 | |
3073 | 3073 | |
3074 | 3074 | if ($this->id > 0 && $commid > 0) { |
3075 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_commerciaux"; |
|
3076 | - $sql .= " WHERE fk_soc = " . $this->id . " AND fk_user =" . $commid; |
|
3075 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux"; |
|
3076 | + $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid; |
|
3077 | 3077 | |
3078 | 3078 | $this->db->query($sql); |
3079 | 3079 | |
3080 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_commerciaux"; |
|
3080 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux"; |
|
3081 | 3081 | $sql .= " ( fk_soc, fk_user )"; |
3082 | - $sql .= " VALUES (" . $this->id . "," . $commid . ")"; |
|
3082 | + $sql .= " VALUES (".$this->id.",".$commid.")"; |
|
3083 | 3083 | |
3084 | 3084 | if (!$this->db->query($sql)) { |
3085 | - dol_syslog(get_class($this) . "::add_commercial Erreur"); |
|
3085 | + dol_syslog(get_class($this)."::add_commercial Erreur"); |
|
3086 | 3086 | } else { |
3087 | 3087 | $this->context = array('commercial_modified' => $commid); |
3088 | 3088 | |
@@ -3116,7 +3116,7 @@ discard block |
||
3116 | 3116 | |
3117 | 3117 | $this->note_private = empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOTE; |
3118 | 3118 | |
3119 | - $this->nom = $this->name; // deprecated |
|
3119 | + $this->nom = $this->name; // deprecated |
|
3120 | 3120 | // We define country_id, country_code and country |
3121 | 3121 | $country_id = $country_code = $country_label = ''; |
3122 | 3122 | if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) { |
@@ -3127,16 +3127,16 @@ discard block |
||
3127 | 3127 | $country_label = $tmp[2]; |
3128 | 3128 | } else { // For backward compatibility |
3129 | 3129 | dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR); |
3130 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; |
|
3131 | - $country_code = getCountry($country_id, 2, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore |
|
3132 | - $country_label = getCountry($country_id, 0, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore |
|
3130 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
3131 | + $country_code = getCountry($country_id, 2, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore |
|
3132 | + $country_label = getCountry($country_id, 0, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore |
|
3133 | 3133 | } |
3134 | 3134 | } |
3135 | 3135 | $this->country_id = $country_id; |
3136 | 3136 | $this->country_code = $country_code; |
3137 | 3137 | $this->country = $country_label; |
3138 | 3138 | if (is_object($langs)) |
3139 | - $this->country = ($langs->trans('Country' . $country_code) != 'Country' . $country_code) ? $langs->trans('Country' . $country_code) : $country_label; |
|
3139 | + $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label; |
|
3140 | 3140 | |
3141 | 3141 | $this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ? '' : $conf->global->MAIN_INFO_SOCIETE_TEL; |
3142 | 3142 | $this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ? '' : $conf->global->MAIN_INFO_SOCIETE_FAX; |
@@ -3178,8 +3178,8 @@ discard block |
||
3178 | 3178 | |
3179 | 3179 | // Initialize parameters |
3180 | 3180 | $this->id = 0; |
3181 | - $this->name = 'THIRDPARTY SPECIMEN ' . dol_print_date($now, 'dayhourlog'); |
|
3182 | - $this->nom = $this->name; // For backward compatibility |
|
3181 | + $this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now, 'dayhourlog'); |
|
3182 | + $this->nom = $this->name; // For backward compatibility |
|
3183 | 3183 | $this->ref_ext = 'Ref ext'; |
3184 | 3184 | $this->specimen = 1; |
3185 | 3185 | $this->address = '21 jump street'; |
@@ -3199,8 +3199,8 @@ discard block |
||
3199 | 3199 | $this->phone = '0909090901'; |
3200 | 3200 | $this->fax = '0909090909'; |
3201 | 3201 | |
3202 | - $this->code_client = 'CC-' . dol_print_date($now, 'dayhourlog'); |
|
3203 | - $this->code_fournisseur = 'SC-' . dol_print_date($now, 'dayhourlog'); |
|
3202 | + $this->code_client = 'CC-'.dol_print_date($now, 'dayhourlog'); |
|
3203 | + $this->code_fournisseur = 'SC-'.dol_print_date($now, 'dayhourlog'); |
|
3204 | 3204 | $this->capital = 10000; |
3205 | 3205 | $this->client = 1; |
3206 | 3206 | $this->prospect = 1; |
@@ -3227,8 +3227,8 @@ discard block |
||
3227 | 3227 | function useLocalTax($localTaxNum = 0) |
3228 | 3228 | { |
3229 | 3229 | $sql = "SELECT t.localtax1, t.localtax2"; |
3230 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t, " . MAIN_DB_PREFIX . "c_country as c"; |
|
3231 | - $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $this->db->escape($this->country_code) . "'"; |
|
3230 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; |
|
3231 | + $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'"; |
|
3232 | 3232 | $sql .= " AND t.active = 1"; |
3233 | 3233 | if (empty($localTaxNum)) |
3234 | 3234 | $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')"; |
@@ -3253,8 +3253,8 @@ discard block |
||
3253 | 3253 | function useNPR() |
3254 | 3254 | { |
3255 | 3255 | $sql = "SELECT t.rowid"; |
3256 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t, " . MAIN_DB_PREFIX . "c_country as c"; |
|
3257 | - $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '" . $this->db->escape($this->country_code) . "'"; |
|
3256 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; |
|
3257 | + $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'"; |
|
3258 | 3258 | $sql .= " AND t.active = 1 AND t.recuperableonly = 1"; |
3259 | 3259 | |
3260 | 3260 | dol_syslog("useNPR", LOG_DEBUG); |
@@ -3273,8 +3273,8 @@ discard block |
||
3273 | 3273 | function useRevenueStamp() |
3274 | 3274 | { |
3275 | 3275 | $sql = "SELECT COUNT(*) as nb"; |
3276 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_revenuestamp as r, " . MAIN_DB_PREFIX . "c_country as c"; |
|
3277 | - $sql .= " WHERE r.fk_pays = c.rowid AND c.code = '" . $this->db->escape($this->country_code) . "'"; |
|
3276 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r, ".MAIN_DB_PREFIX."c_country as c"; |
|
3277 | + $sql .= " WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'"; |
|
3278 | 3278 | $sql .= " AND r.active = 1"; |
3279 | 3279 | |
3280 | 3280 | dol_syslog("useRevenueStamp", LOG_DEBUG); |
@@ -3309,9 +3309,9 @@ discard block |
||
3309 | 3309 | // phpcs:enable |
3310 | 3310 | global $langs; |
3311 | 3311 | |
3312 | - $lib = $langs->trans("ProspectLevel" . $fk_prospectlevel); |
|
3312 | + $lib = $langs->trans("ProspectLevel".$fk_prospectlevel); |
|
3313 | 3313 | // If lib not found in language file, we get label from cache/databse |
3314 | - if ($lib == $langs->trans("ProspectLevel" . $fk_prospectlevel)) { |
|
3314 | + if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) { |
|
3315 | 3315 | $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label'); |
3316 | 3316 | } |
3317 | 3317 | return $lib; |
@@ -3362,17 +3362,17 @@ discard block |
||
3362 | 3362 | |
3363 | 3363 | if ($mode == 2) { |
3364 | 3364 | if ($statut == '-1' || $statut == 'ST_NO') |
3365 | - return img_action($langs->trans("StatusProspect-1"), -1) . ' ' . $langs->trans("StatusProspect-1"); |
|
3365 | + return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1"); |
|
3366 | 3366 | elseif ($statut == '0' || $statut == 'ST_NEVER') |
3367 | - return img_action($langs->trans("StatusProspect0"), 0) . ' ' . $langs->trans("StatusProspect0"); |
|
3367 | + return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0"); |
|
3368 | 3368 | elseif ($statut == '1' || $statut == 'ST_TODO') |
3369 | - return img_action($langs->trans("StatusProspect1"), 1) . ' ' . $langs->trans("StatusProspect1"); |
|
3369 | + return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1"); |
|
3370 | 3370 | elseif ($statut == '2' || $statut == 'ST_PEND') |
3371 | - return img_action($langs->trans("StatusProspect2"), 2) . ' ' . $langs->trans("StatusProspect2"); |
|
3371 | + return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2"); |
|
3372 | 3372 | elseif ($statut == '3' || $statut == 'ST_DONE') |
3373 | - return img_action($langs->trans("StatusProspect3"), 3) . ' ' . $langs->trans("StatusProspect3"); |
|
3373 | + return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3"); |
|
3374 | 3374 | else { |
3375 | - return img_action(($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label, 0) . ' ' . (($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label); |
|
3375 | + return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label); |
|
3376 | 3376 | } |
3377 | 3377 | } |
3378 | 3378 | if ($mode == 3) { |
@@ -3387,22 +3387,22 @@ discard block |
||
3387 | 3387 | elseif ($statut == '3' || $statut == 'ST_DONE') |
3388 | 3388 | return img_action($langs->trans("StatusProspect3"), 3); |
3389 | 3389 | else { |
3390 | - return img_action(($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label, 0); |
|
3390 | + return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0); |
|
3391 | 3391 | } |
3392 | 3392 | } |
3393 | 3393 | if ($mode == 4) { |
3394 | 3394 | if ($statut == '-1' || $statut == 'ST_NO') |
3395 | - return img_action($langs->trans("StatusProspect-1"), -1) . ' ' . $langs->trans("StatusProspect-1"); |
|
3395 | + return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1"); |
|
3396 | 3396 | elseif ($statut == '0' || $statut == 'ST_NEVER') |
3397 | - return img_action($langs->trans("StatusProspect0"), 0) . ' ' . $langs->trans("StatusProspect0"); |
|
3397 | + return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0"); |
|
3398 | 3398 | elseif ($statut == '1' || $statut == 'ST_TODO') |
3399 | - return img_action($langs->trans("StatusProspect1"), 1) . ' ' . $langs->trans("StatusProspect1"); |
|
3399 | + return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1"); |
|
3400 | 3400 | elseif ($statut == '2' || $statut == 'ST_PEND') |
3401 | - return img_action($langs->trans("StatusProspect2"), 2) . ' ' . $langs->trans("StatusProspect2"); |
|
3401 | + return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2"); |
|
3402 | 3402 | elseif ($statut == '3' || $statut == 'ST_DONE') |
3403 | - return img_action($langs->trans("StatusProspect3"), 3) . ' ' . $langs->trans("StatusProspect3"); |
|
3403 | + return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3"); |
|
3404 | 3404 | else { |
3405 | - return img_action(($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label, 0) . ' ' . (($langs->trans("StatusProspect" . $statut) != "StatusProspect" . $statut) ? $langs->trans("StatusProspect" . $statut) : $label); |
|
3405 | + return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label); |
|
3406 | 3406 | } |
3407 | 3407 | } |
3408 | 3408 | |
@@ -3438,12 +3438,12 @@ discard block |
||
3438 | 3438 | if ($mode == 'supplier') |
3439 | 3439 | $table = 'supplier_proposal'; |
3440 | 3440 | |
3441 | - $sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM " . MAIN_DB_PREFIX . $table . " as f"; |
|
3442 | - $sql .= " WHERE fk_soc = " . $this->id; |
|
3441 | + $sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f"; |
|
3442 | + $sql .= " WHERE fk_soc = ".$this->id; |
|
3443 | 3443 | if ($mode == 'supplier') { |
3444 | - $sql .= " AND entity IN (" . getEntity('supplier_proposal') . ")"; |
|
3444 | + $sql .= " AND entity IN (".getEntity('supplier_proposal').")"; |
|
3445 | 3445 | } else { |
3446 | - $sql .= " AND entity IN (" . getEntity('propal') . ")"; |
|
3446 | + $sql .= " AND entity IN (".getEntity('propal').")"; |
|
3447 | 3447 | } |
3448 | 3448 | |
3449 | 3449 | dol_syslog("getOutstandingProposals", LOG_DEBUG); |
@@ -3476,12 +3476,12 @@ discard block |
||
3476 | 3476 | if ($mode == 'supplier') |
3477 | 3477 | $table = 'commande_fournisseur'; |
3478 | 3478 | |
3479 | - $sql = "SELECT rowid, total_ht, total_ttc, fk_statut FROM " . MAIN_DB_PREFIX . $table . " as f"; |
|
3480 | - $sql .= " WHERE fk_soc = " . $this->id; |
|
3479 | + $sql = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f"; |
|
3480 | + $sql .= " WHERE fk_soc = ".$this->id; |
|
3481 | 3481 | if ($mode == 'supplier') { |
3482 | - $sql .= " AND entity IN (" . getEntity('supplier_order') . ")"; |
|
3482 | + $sql .= " AND entity IN (".getEntity('supplier_order').")"; |
|
3483 | 3483 | } else { |
3484 | - $sql .= " AND entity IN (" . getEntity('commande') . ")"; |
|
3484 | + $sql .= " AND entity IN (".getEntity('commande').")"; |
|
3485 | 3485 | } |
3486 | 3486 | |
3487 | 3487 | dol_syslog("getOutstandingOrders", LOG_DEBUG); |
@@ -3522,14 +3522,14 @@ discard block |
||
3522 | 3522 | $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); |
3523 | 3523 | */ |
3524 | 3524 | if ($mode == 'supplier') |
3525 | - $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM " . MAIN_DB_PREFIX . $table . " as f"; |
|
3525 | + $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; |
|
3526 | 3526 | else |
3527 | - $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM " . MAIN_DB_PREFIX . $table . " as f"; |
|
3528 | - $sql .= " WHERE fk_soc = " . $this->id; |
|
3527 | + $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; |
|
3528 | + $sql .= " WHERE fk_soc = ".$this->id; |
|
3529 | 3529 | if ($mode == 'supplier') { |
3530 | - $sql .= " AND entity IN (" . getEntity('facture_fourn') . ")"; |
|
3530 | + $sql .= " AND entity IN (".getEntity('facture_fourn').")"; |
|
3531 | 3531 | } else { |
3532 | - $sql .= " AND entity IN (" . getEntity('invoice') . ")"; |
|
3532 | + $sql .= " AND entity IN (".getEntity('invoice').")"; |
|
3533 | 3533 | } |
3534 | 3534 | |
3535 | 3535 | dol_syslog("getOutstandingBills", LOG_DEBUG); |
@@ -3539,10 +3539,10 @@ discard block |
||
3539 | 3539 | $outstandingTotal = 0; |
3540 | 3540 | $outstandingTotalIncTax = 0; |
3541 | 3541 | if ($mode == 'supplier') { |
3542 | - require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; |
|
3542 | + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
|
3543 | 3543 | $tmpobject = new FactureFournisseur($this->db); |
3544 | 3544 | } else { |
3545 | - require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; |
|
3545 | + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
3546 | 3546 | $tmpobject = new Facture($this->db); |
3547 | 3547 | } |
3548 | 3548 | while ($obj = $this->db->fetch_object($resql)) { |
@@ -3586,19 +3586,19 @@ discard block |
||
3586 | 3586 | $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); |
3587 | 3587 | $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); |
3588 | 3588 | */ |
3589 | - $sql = "SELECT rowid, total_ttc FROM " . MAIN_DB_PREFIX . "facture as f"; |
|
3590 | - $sql .= " WHERE fk_soc = " . $this->id; |
|
3589 | + $sql = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f"; |
|
3590 | + $sql .= " WHERE fk_soc = ".$this->id; |
|
3591 | 3591 | $sql .= " AND paye = 0"; |
3592 | 3592 | $sql .= " AND fk_statut <> 0"; // Not a draft |
3593 | 3593 | //$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason |
3594 | - $sql .= " AND fk_statut <> 3"; // Not abandonned |
|
3595 | - $sql .= " AND fk_statut <> 2"; // Not clasified as paid |
|
3594 | + $sql .= " AND fk_statut <> 3"; // Not abandonned |
|
3595 | + $sql .= " AND fk_statut <> 2"; // Not clasified as paid |
|
3596 | 3596 | |
3597 | 3597 | dol_syslog("get_OutstandingBill", LOG_DEBUG); |
3598 | 3598 | $resql = $this->db->query($sql); |
3599 | 3599 | if ($resql) { |
3600 | 3600 | $outstandingAmount = 0; |
3601 | - require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; |
|
3601 | + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
3602 | 3602 | $tmpobject = new Facture($this->db); |
3603 | 3603 | while ($obj = $this->db->fetch_object($resql)) { |
3604 | 3604 | $tmpobject->id = $obj->rowid; |
@@ -3666,7 +3666,7 @@ discard block |
||
3666 | 3666 | if (!empty($moreparams) && !empty($moreparams['use_companybankid'])) { |
3667 | 3667 | $modelpath = "core/modules/bank/doc/"; |
3668 | 3668 | |
3669 | - include_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php'; |
|
3669 | + include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; |
|
3670 | 3670 | $companybankaccount = new CompanyBankAccount($this->db); |
3671 | 3671 | $result = $companybankaccount->fetch($moreparams['use_companybankid']); |
3672 | 3672 | if (!$result) |
@@ -3678,7 +3678,7 @@ discard block |
||
3678 | 3678 | if (!empty($conf->global->COMPANY_ADDON_PDF)) { |
3679 | 3679 | $modele = $conf->global->COMPANY_ADDON_PDF; |
3680 | 3680 | } else { |
3681 | - print $langs->trans("Error") . " " . $langs->trans("Error_COMPANY_ADDON_PDF_NotDefined"); |
|
3681 | + print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined"); |
|
3682 | 3682 | return 0; |
3683 | 3683 | } |
3684 | 3684 | } |
@@ -3704,7 +3704,7 @@ discard block |
||
3704 | 3704 | */ |
3705 | 3705 | public function setCategories($categories, $type) |
3706 | 3706 | { |
3707 | - require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; |
|
3707 | + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
3708 | 3708 | |
3709 | 3709 | // Decode type |
3710 | 3710 | if ($type == 'customer') { |
@@ -3714,7 +3714,7 @@ discard block |
||
3714 | 3714 | $type_id = Categorie::TYPE_SUPPLIER; |
3715 | 3715 | $type_text = 'supplier'; |
3716 | 3716 | } else { |
3717 | - dol_syslog(__METHOD__ . ': Type ' . $type . 'is an unknown company category type. Done nothing.', LOG_ERR); |
|
3717 | + dol_syslog(__METHOD__.': Type '.$type.'is an unknown company category type. Done nothing.', LOG_ERR); |
|
3718 | 3718 | return -1; |
3719 | 3719 | } |
3720 | 3720 | |
@@ -3819,16 +3819,16 @@ discard block |
||
3819 | 3819 | $reparray = array(); |
3820 | 3820 | |
3821 | 3821 | $sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo"; |
3822 | - $sql .= " FROM " . MAIN_DB_PREFIX . "societe_commerciaux as sc, " . MAIN_DB_PREFIX . "user as u"; |
|
3822 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u"; |
|
3823 | 3823 | if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { |
3824 | - $sql .= ", " . MAIN_DB_PREFIX . "usergroup_user as ug"; |
|
3824 | + $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
3825 | 3825 | $sql .= " WHERE ((ug.fk_user = sc.fk_user"; |
3826 | - $sql .= " AND ug.entity = " . $conf->entity . ")"; |
|
3826 | + $sql .= " AND ug.entity = ".$conf->entity.")"; |
|
3827 | 3827 | $sql .= " OR u.admin = 1)"; |
3828 | 3828 | } else |
3829 | - $sql .= " WHERE entity in (0, " . $conf->entity . ")"; |
|
3829 | + $sql .= " WHERE entity in (0, ".$conf->entity.")"; |
|
3830 | 3830 | |
3831 | - $sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = " . $this->id; |
|
3831 | + $sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id; |
|
3832 | 3832 | |
3833 | 3833 | $resql = $this->db->query($sql); |
3834 | 3834 | if ($resql) { |
@@ -3876,11 +3876,11 @@ discard block |
||
3876 | 3876 | $error++; |
3877 | 3877 | |
3878 | 3878 | if ($this->id > 0 && $commid > 0) { |
3879 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_commerciaux "; |
|
3880 | - $sql .= " WHERE fk_soc = " . $this->id . " AND fk_user =" . $commid; |
|
3879 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux "; |
|
3880 | + $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid; |
|
3881 | 3881 | |
3882 | 3882 | if (!$this->db->query($sql)) { |
3883 | - dol_syslog(get_class($this) . "::del_commercial Erreur"); |
|
3883 | + dol_syslog(get_class($this)."::del_commercial Erreur"); |
|
3884 | 3884 | } |
3885 | 3885 | } |
3886 | 3886 | } |
@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | define('BASE_PATH', __DIR__); |
10 | 10 | define('DEBUG', true); |
11 | 11 | |
12 | -require_once BASE_PATH . '/vendor/autoload.php'; |
|
13 | -require_once BASE_PATH . '/alxarafe/vendor/autoload.php'; |
|
12 | +require_once BASE_PATH.'/vendor/autoload.php'; |
|
13 | +require_once BASE_PATH.'/alxarafe/vendor/autoload.php'; |
|
14 | 14 | |
15 | 15 | use Alixar\Helpers\AlixarDispatcher; |
16 | 16 | |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | $className = $controller; |
28 | 28 | $method = filter_input(INPUT_GET, 'method') ?: 'main'; |
29 | 29 | foreach ($dispatcher->searchDir as $nameSpace => $path) { |
30 | - $className = $nameSpace . '\\Controllers\\' . $controller; |
|
31 | - $controllerPath = $path . '/Controllers/' . $controller . '.php'; |
|
30 | + $className = $nameSpace.'\\Controllers\\'.$controller; |
|
31 | + $controllerPath = $path.'/Controllers/'.$controller.'.php'; |
|
32 | 32 | if (file_exists($controllerPath)) { |
33 | 33 | //require_once $controllerPath; |
34 | 34 | $class = new $className; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | $controller = filter_input(INPUT_GET, 'controller') ?: 'home'; |
49 | 49 | $method = filter_input(INPUT_GET, 'next') ?: filter_input(INPUT_GET, 'method') ?: 'home'; |
50 | 50 | |
51 | -$path = BASE_PATH . "/dolibarr/htdocs/$controller/$method.php"; |
|
51 | +$path = BASE_PATH."/dolibarr/htdocs/$controller/$method.php"; |
|
52 | 52 | include($path); |
53 | 53 | die('End'); |
54 | 54 |
@@ -118,34 +118,34 @@ discard block |
||
118 | 118 | // Action ajout d'une categorie |
119 | 119 | if ($this->cancel) { |
120 | 120 | if ($this->urlfrom) { |
121 | - header("Location: " . $urlfrom); |
|
121 | + header("Location: ".$urlfrom); |
|
122 | 122 | exit; |
123 | 123 | } |
124 | 124 | if ($idProdOrigin) { |
125 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idProdOrigin . '&type=' . $this->type); |
|
125 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$this->type); |
|
126 | 126 | exit; |
127 | 127 | } |
128 | 128 | if ($idCompanyOrigin) { |
129 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idCompanyOrigin . '&type=' . $this->type); |
|
129 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$this->type); |
|
130 | 130 | exit; |
131 | 131 | } |
132 | 132 | if ($idSupplierOrigin) { |
133 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idSupplierOrigin . '&type=' . $this->type); |
|
133 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$this->type); |
|
134 | 134 | exit; |
135 | 135 | } |
136 | 136 | if ($idMemberOrigin) { |
137 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idMemberOrigin . '&type=' . $this->type); |
|
137 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$this->type); |
|
138 | 138 | exit; |
139 | 139 | } |
140 | 140 | if ($idContactOrigin) { |
141 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idContactOrigin . '&type=' . $this->type); |
|
141 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$this->type); |
|
142 | 142 | exit; |
143 | 143 | } |
144 | 144 | if ($idProjectOrigin) { |
145 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idProjectOrigin . '&type=' . $this->type); |
|
145 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$this->type); |
|
146 | 146 | exit; |
147 | 147 | } |
148 | - header("Location: " . DOL_URL_ROOT . '/categories/index.php?leftmenu=cat&type=' . $this->type); |
|
148 | + header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$this->type); |
|
149 | 149 | exit; |
150 | 150 | } |
151 | 151 | |
@@ -188,39 +188,39 @@ discard block |
||
188 | 188 | // Action confirmation de creation categorie |
189 | 189 | if ($this->action == 'confirmed') { |
190 | 190 | if ($urlfrom) { |
191 | - header("Location: " . $urlfrom); |
|
191 | + header("Location: ".$urlfrom); |
|
192 | 192 | exit; |
193 | 193 | } |
194 | 194 | if ($backtopage) { |
195 | - header("Location: " . $backtopage); |
|
195 | + header("Location: ".$backtopage); |
|
196 | 196 | exit; |
197 | 197 | } |
198 | 198 | if ($idProdOrigin) { |
199 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idProdOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated"))); |
|
199 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProdOrigin.'&type='.$this->type.'&mesg='.urlencode(Globals::$langs->trans("CatCreated"))); |
|
200 | 200 | exit; |
201 | 201 | } |
202 | 202 | if ($idCompanyOrigin) { |
203 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idCompanyOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated"))); |
|
203 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCompanyOrigin.'&type='.$this->type.'&mesg='.urlencode(Globals::$langs->trans("CatCreated"))); |
|
204 | 204 | exit; |
205 | 205 | } |
206 | 206 | if ($idSupplierOrigin) { |
207 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idSupplierOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated"))); |
|
207 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idSupplierOrigin.'&type='.$this->type.'&mesg='.urlencode(Globals::$langs->trans("CatCreated"))); |
|
208 | 208 | exit; |
209 | 209 | } |
210 | 210 | if ($idMemberOrigin) { |
211 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idMemberOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated"))); |
|
211 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idMemberOrigin.'&type='.$this->type.'&mesg='.urlencode(Globals::$langs->trans("CatCreated"))); |
|
212 | 212 | exit; |
213 | 213 | } |
214 | 214 | if ($idContactOrigin) { |
215 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idContactOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated"))); |
|
215 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$this->type.'&mesg='.urlencode(Globals::$langs->trans("CatCreated"))); |
|
216 | 216 | exit; |
217 | 217 | } |
218 | 218 | if ($idProjectOrigin) { |
219 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idProjectOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated"))); |
|
219 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idProjectOrigin.'&type='.$this->type.'&mesg='.urlencode(Globals::$langs->trans("CatCreated"))); |
|
220 | 220 | exit; |
221 | 221 | } |
222 | 222 | |
223 | - header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $result . '&type=' . $this->type); |
|
223 | + header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$this->type); |
|
224 | 224 | exit; |
225 | 225 | } |
226 | 226 | } |
@@ -58,15 +58,15 @@ discard block |
||
58 | 58 | |
59 | 59 | if (count($listofsearchfields)) { |
60 | 60 | // print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">'; |
61 | - print '<form method="post" action="' . BASE_URI . '?controller=core&method=search">'; |
|
62 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
61 | + print '<form method="post" action="'.BASE_URI.'?controller=core&method=search">'; |
|
62 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
63 | 63 | print '<table class="noborder nohover centpercent">'; |
64 | 64 | $i = 0; |
65 | 65 | foreach ($listofsearchfields as $key => $value) { |
66 | - if ($i == 0) print '<tr class="liste_titre"><th colspan="3">' . $langs->trans("Search") . '</th></tr>'; |
|
67 | - print '<tr ' . $bc[false] . '>'; |
|
68 | - print '<td class="nowrap"><label for="' . $key . '">' . $langs->trans($value["text"]) . '</label></td><td><input type="text" class="flat inputsearch" name="' . $key . '" id="' . $key . '" size="18"></td>'; |
|
69 | - if ($i == 0) print '<td rowspan="' . count($listofsearchfields) . '"><input type="submit" value="' . $langs->trans("Search") . '" class="button"></td>'; |
|
66 | + if ($i == 0) print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("Search").'</th></tr>'; |
|
67 | + print '<tr '.$bc[false].'>'; |
|
68 | + print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>'; |
|
69 | + if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>'; |
|
70 | 70 | print '</tr>'; |
71 | 71 | $i++; |
72 | 72 | } |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | $total = 0; |
91 | 91 | |
92 | 92 | $sql = "SELECT s.rowid, s.client, s.fournisseur"; |
93 | - $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; |
|
94 | - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
95 | - $sql .= ' WHERE s.entity IN (' . getEntity('societe') . ')'; |
|
96 | - if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
97 | - if ($socid) $sql .= " AND s.rowid = " . $socid; |
|
98 | - if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible |
|
93 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
94 | + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
95 | + $sql .= ' WHERE s.entity IN ('.getEntity('societe').')'; |
|
96 | + if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; |
|
97 | + if ($socid) $sql .= " AND s.rowid = ".$socid; |
|
98 | + if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible |
|
99 | 99 | //print $sql; |
100 | 100 | $result = $db->query($sql); |
101 | 101 | if ($result) { |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | } else dol_print_error($db); |
123 | 123 | |
124 | 124 | print '<div class="div-table-responsive-no-min">'; |
125 | - print '<table class="noborder nohover" width="100%">' . "\n"; |
|
126 | - print '<tr class="liste_titre"><th colspan="2">' . $langs->trans("Statistics") . '</th></tr>'; |
|
125 | + print '<table class="noborder nohover" width="100%">'."\n"; |
|
126 | + print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>'; |
|
127 | 127 | if (!empty($conf->use_javascript_ajax) && ((round($third['prospect']) ? 1 : 0) + (round($third['customer']) ? 1 : 0) + (round($third['supplier']) ? 1 : 0) + (round($third['other']) ? 1 : 0) >= 2)) { |
128 | 128 | print '<tr><td align="center" colspan="2">'; |
129 | 129 | $dataseries = array(); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[] = array($langs->trans("Customers"), round($third['customer'])); |
132 | 132 | if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[] = array($langs->trans("Suppliers"), round($third['supplier'])); |
133 | 133 | if (!empty($conf->societe->enabled)) $dataseries[] = array($langs->trans("Others"), round($third['other'])); |
134 | - include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php'; |
|
134 | + include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; |
|
135 | 135 | $dolgraph = new DolGraph(); |
136 | 136 | $dolgraph->SetData($dataseries); |
137 | 137 | $dolgraph->setShowLegend(1); |
@@ -140,51 +140,51 @@ discard block |
||
140 | 140 | $dolgraph->setWidth('100%'); |
141 | 141 | $dolgraph->draw('idgraphthirdparties'); |
142 | 142 | print $dolgraph->show(); |
143 | - print '</td></tr>' . "\n"; |
|
143 | + print '</td></tr>'."\n"; |
|
144 | 144 | } else { |
145 | 145 | if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) { |
146 | 146 | $statstring = "<tr>"; |
147 | 147 | //$statstring.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td align="right">'.round($third['prospect']).'</td>'; |
148 | - $statstring .= '<td><a href="' . BASE_URI . '?controller=societe&method=list&type=p">' . $langs->trans("Prospects") . '</a></td><td align="right">' . round($third['prospect']) . '</td>'; |
|
148 | + $statstring .= '<td><a href="'.BASE_URI.'?controller=societe&method=list&type=p">'.$langs->trans("Prospects").'</a></td><td align="right">'.round($third['prospect']).'</td>'; |
|
149 | 149 | $statstring .= "</tr>"; |
150 | 150 | } |
151 | 151 | if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) { |
152 | 152 | $statstring .= "<tr>"; |
153 | 153 | //$statstring.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td align="right">'.round($third['customer']).'</td>'; |
154 | - $statstring .= '<td><a href="' . BASE_URI . '?controller=societe&method=list&type=c">' . $langs->trans("Customers") . '</a></td><td align="right">' . round($third['customer']) . '</td>'; |
|
154 | + $statstring .= '<td><a href="'.BASE_URI.'?controller=societe&method=list&type=c">'.$langs->trans("Customers").'</a></td><td align="right">'.round($third['customer']).'</td>'; |
|
155 | 155 | $statstring .= "</tr>"; |
156 | 156 | } |
157 | 157 | if (!empty($conf->fournisseur->enabled) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $user->rights->fournisseur->lire) { |
158 | 158 | $statstring2 = "<tr>"; |
159 | 159 | //$statstring2.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td align="right">'.round($third['supplier']).'</td>'; |
160 | - $statstring2 .= '<td><a href="' . BASE_URI . '?controller=societe&method=list&typef">' . $langs->trans("Suppliers") . '</a></td><td align="right">' . round($third['supplier']) . '</td>'; |
|
160 | + $statstring2 .= '<td><a href="'.BASE_URI.'?controller=societe&method=list&typef">'.$langs->trans("Suppliers").'</a></td><td align="right">'.round($third['supplier']).'</td>'; |
|
161 | 161 | $statstring2 .= "</tr>"; |
162 | 162 | } |
163 | 163 | print $statstring; |
164 | 164 | print $statstring2; |
165 | 165 | } |
166 | - print '<tr class="liste_total"><td>' . $langs->trans("UniqueThirdParties") . '</td><td align="right">'; |
|
166 | + print '<tr class="liste_total"><td>'.$langs->trans("UniqueThirdParties").'</td><td align="right">'; |
|
167 | 167 | print $total; |
168 | 168 | print '</td></tr>'; |
169 | 169 | print '</table>'; |
170 | 170 | print '</div>'; |
171 | 171 | |
172 | 172 | if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) { |
173 | - require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; |
|
173 | + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
174 | 174 | $elementtype = 'societe'; |
175 | 175 | |
176 | 176 | print '<br>'; |
177 | 177 | |
178 | 178 | print '<div class="div-table-responsive-no-min">'; |
179 | 179 | print '<table class="noborder nohover" width="100%">'; |
180 | - print '<tr class="liste_titre"><th colspan="2">' . $langs->trans("Categories") . '</th></tr>'; |
|
181 | - print '<tr ' . $bc[0] . '><td align="center" colspan="2">'; |
|
180 | + print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>'; |
|
181 | + print '<tr '.$bc[0].'><td align="center" colspan="2">'; |
|
182 | 182 | $sql = "SELECT c.label, count(*) as nb"; |
183 | - $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_societe as cs"; |
|
184 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "categorie as c ON cs.fk_categorie = c.rowid"; |
|
183 | + $sql .= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs"; |
|
184 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid"; |
|
185 | 185 | $sql .= " WHERE c.type = 2"; |
186 | - if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) $sql .= " AND c.label like '" . $db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES) . "'"; |
|
187 | - $sql .= " AND c.entity IN (" . getEntity('category') . ")"; |
|
186 | + if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) $sql .= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'"; |
|
187 | + $sql .= " AND c.entity IN (".getEntity('category').")"; |
|
188 | 188 | $sql .= " GROUP BY c.label"; |
189 | 189 | $total = 0; |
190 | 190 | $result = $db->query($sql); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | if ($i > $nbmax) { |
210 | 210 | $dataseries[] = array($langs->trans("Other"), round($rest)); |
211 | 211 | } |
212 | - include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php'; |
|
212 | + include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; |
|
213 | 213 | $dolgraph = new DolGraph(); |
214 | 214 | $dolgraph->SetData($dataseries); |
215 | 215 | $dolgraph->setShowLegend(1); |
@@ -222,14 +222,14 @@ discard block |
||
222 | 222 | while ($i < $num) { |
223 | 223 | $obj = $db->fetch_object($result); |
224 | 224 | |
225 | - print '<tr class="oddeven"><td>' . $obj->label . '</td><td>' . $obj->nb . '</td></tr>'; |
|
225 | + print '<tr class="oddeven"><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>'; |
|
226 | 226 | $total += $obj->nb; |
227 | 227 | $i++; |
228 | 228 | } |
229 | 229 | } |
230 | 230 | } |
231 | 231 | print '</td></tr>'; |
232 | - print '<tr class="liste_total"><td>' . $langs->trans("Total") . '</td><td align="right">'; |
|
232 | + print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'; |
|
233 | 233 | print $total; |
234 | 234 | print '</td></tr>'; |
235 | 235 | print '</table>'; |
@@ -249,11 +249,11 @@ discard block |
||
249 | 249 | $sql .= ", s.code_fournisseur"; |
250 | 250 | $sql .= ", s.logo"; |
251 | 251 | $sql .= ", s.canvas, s.tms as datem, s.status as status"; |
252 | - $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; |
|
253 | - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
254 | - $sql .= ' WHERE s.entity IN (' . getEntity('societe') . ')'; |
|
255 | - if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
256 | - if ($socid) $sql .= " AND s.rowid = " . $socid; |
|
252 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
253 | + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
254 | + $sql .= ' WHERE s.entity IN ('.getEntity('societe').')'; |
|
255 | + if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; |
|
256 | + if ($socid) $sql .= " AND s.rowid = ".$socid; |
|
257 | 257 | if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur != 1 OR s.client != 0)"; |
258 | 258 | $sql .= $db->order("s.tms", "DESC"); |
259 | 259 | $sql .= $db->plimit($max, 0); |
@@ -272,11 +272,11 @@ discard block |
||
272 | 272 | print '<div class="div-table-responsive-no-min">'; |
273 | 273 | print '<table class="noborder" width="100%">'; |
274 | 274 | |
275 | - print '<tr class="liste_titre"><th colspan="2">' . $transRecordedType . '</th>'; |
|
275 | + print '<tr class="liste_titre"><th colspan="2">'.$transRecordedType.'</th>'; |
|
276 | 276 | print '<th> </th>'; |
277 | 277 | //print '<th class="right"><a href="'.DOL_URL_ROOT.'/societe/list.php?sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>'; |
278 | - print '<th class="right"><a href="' . BASE_URI . '?controller=societe&method=list&sortfield=s.tms&sortorder=DESC">' . $langs->trans("FullList") . '</th>'; |
|
279 | - print '</tr>' . "\n"; |
|
278 | + print '<th class="right"><a href="'.BASE_URI.'?controller=societe&method=list&sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>'; |
|
279 | + print '</tr>'."\n"; |
|
280 | 280 | |
281 | 281 | while ($i < $num) { |
282 | 282 | $objp = $db->fetch_object($result); |