Passed
Push — master ( 284492...2c3033 )
by Alxarafe
27:10
created
Base/AlixarModel.php 2 patches
Spacing   +719 added lines, -719 removed lines patch added patch discarded remove patch
@@ -314,12 +314,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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