diff --git a/SECURITY.md b/SECURITY.md index 6dc6e0f33b5..08ca64e4a4c 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -55,8 +55,7 @@ ONLY vulnerabilities discovered, when the following setup on test platform is us * $dolibarr_nocsrfcheck must be kept to the value 0 into conf.php (this is the default value) * $dolibarr_main_force_https must be set to something else than 0. * The constant MAIN_SECURITY_CSRF_WITH_TOKEN must be set to 1 into backoffice menu Home - Setup - Other (this protection should be set to 1 soon by default) -* The module DebugBar must NOT be enabled (by default, this module is not enabled. This is a developer tool) -* The module ModuleBuilder must NOT be enabled (by default, this module is not enabled. This is a developer tool) +* The module DebugBar and ModuleBuilder must NOT be enabled (by default, this module is not enabled. This is a developer tool) * ONLY security reports on modules provided by default and with the "stable" status are valid (troubles into "experimental", "developement" or external modules are not valid vulnerabilities). * The root of web server must link to htdocs and the documents directory must be outside of the web server root (this is the default when using the default installer but may differs with external installer). * The web server setup must be done so only the documents directory is in write mode. The root directory called htdocs must be readonly. diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index ebd768de1dc..54d6b66dd56 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -467,7 +467,7 @@ if (!empty($sortfield)) { // Export into a file with format defined into setup (FEC, CSV, ...) // Must be after definition of $sql -if ($action == 'export_file' && $user->rights->accounting->mouvements->export) { +if ($action == 'export_fileconfirm' && $user->rights->accounting->mouvements->export) { // TODO Replace the fetchAll + ->export later that consume too much memory on large export with the query($sql) and loop on each line to export them. $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter, 'AND', $conf->global->ACCOUNTING_REEXPORT); @@ -495,6 +495,7 @@ if ($action == 'export_file' && $user->rights->accounting->mouvements->export) { $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping"; $sql .= " SET date_export = '".$db->idate($now)."'"; + $sql .= " , date_validated = '".$db->idate($now)."'"; $sql .= " WHERE rowid = ".$movement->id; dol_syslog("/accountancy/bookeeping/list.php Function export_file Specify movements as exported sql=".$sql, LOG_DEBUG); @@ -566,7 +567,25 @@ if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) llxHeader('', $title_page); +if ($action == 'export_file') { + $form_question = array(); + $form_question['notifiedexportdate'] = array( + 'name' => 'notifiedexportdate', + 'type' => 'checkbox', + 'label' => $langs->trans('NotifiedExportDate'), + 'value' => (!empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_EXPORT_DATE) ? 'false' : 'true'), + ); + $form_question['notifiedvalidationdate'] = array( + 'name' => 'notifiedvalidationdate', + 'type' => 'checkbox', // We don't use select here, the journal_array is already a select html component + 'label' => $langs->trans('NotifiedValidationDate'), + 'value' => (!empty($conf->global->ACCOUNTING_DEFAULT_NOT_NOTIFIED_VALIDATION_DATE) ? 'false' : 'true'), + ); + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?'.$param, $langs->trans("ExportFilteredList").' ('.$listofformat[$formatexportset].')', $langs->trans('ConfirmExportFile'), 'export_fileconfirm', $form_question, '', 1, 300); + print $formconfirm; +} if ($action == 'delmouv') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?mvt_num='.GETPOST('mvt_num').$param, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvtPartial'), 'delmouvconfirm', '', 0, 1); print $formconfirm; diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 1bcc4129821..201e3cac95a 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -840,17 +840,19 @@ class AccountancyExport print "DateLet".$separator; print "ValidDate".$separator; print "Montantdevise".$separator; - print "Idevise"; + print "Idevise".$separator; + print "DateLimitReglmt"; print $end_line; foreach ($objectLines as $line) { - if ($line->debit == 0 && $line->credit == 0) { + if ($line->debit == 0 && $line->credit == 0) { unset($array[$line]); } else { - $date_creation = dol_print_date($line->date_creation, '%Y%m%d'); - $date_document = dol_print_date($line->doc_date, '%Y%m%d'); - $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d'); - $date_validation = dol_print_date($line->date_validated, '%Y%m%d'); + $date_creation = dol_print_date($line->date_creation, '%Y%m%d'); + $date_document = dol_print_date($line->doc_date, '%Y%m%d'); + $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d'); + $date_validation = dol_print_date($line->date_validated, '%Y%m%d'); + $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d'); // FEC:JournalCode print $line->code_journal.$separator; @@ -865,13 +867,13 @@ class AccountancyExport print $date_document.$separator; // FEC:CompteNum - print $line->numero_compte.$separator; + print length_accountg($line->numero_compte).$separator; // FEC:CompteLib print dol_string_unaccent($line->label_compte).$separator; // FEC:CompAuxNum - print $line->subledger_account.$separator; + print length_accounta($line->subledger_account).$separator; // FEC:CompAuxLib print dol_string_unaccent($line->subledger_label).$separator; @@ -880,7 +882,7 @@ class AccountancyExport print $line->doc_ref.$separator; // FEC:PieceDate - print dol_string_unaccent($date_creation).$separator; + print $date_creation.$separator; // FEC:EcritureLib print dol_string_unaccent($line->label_operation).$separator; @@ -904,7 +906,10 @@ class AccountancyExport print $line->multicurrency_amount.$separator; // FEC:Idevise - print $line->multicurrency_code; + print $line->multicurrency_code.$separator; + + // FEC_suppl:DateLimitReglmt + print $date_limit_payment; print $end_line; } @@ -939,7 +944,8 @@ class AccountancyExport print "DateLet".$separator; print "ValidDate".$separator; print "Montantdevise".$separator; - print "Idevise"; + print "Idevise".$separator; + print "DateLimitReglmt"; print $end_line; foreach ($objectLines as $line) { @@ -950,6 +956,7 @@ class AccountancyExport $date_document = dol_print_date($line->doc_date, '%Y%m%d'); $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d'); $date_validation = dol_print_date($line->date_validated, '%Y%m%d'); + $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d'); // FEC:JournalCode print $line->code_journal . $separator; @@ -964,13 +971,13 @@ class AccountancyExport print $date_creation . $separator; // FEC:CompteNum - print $line->numero_compte . $separator; + print length_accountg($line->numero_compte) . $separator; // FEC:CompteLib print dol_string_unaccent($line->label_compte) . $separator; // FEC:CompAuxNum - print $line->subledger_account . $separator; + print length_accounta($line->subledger_account) . $separator; // FEC:CompAuxLib print dol_string_unaccent($line->subledger_label) . $separator; @@ -1003,7 +1010,10 @@ class AccountancyExport print $line->multicurrency_amount . $separator; // FEC:Idevise - print $line->multicurrency_code; + print $line->multicurrency_code . $separator; + + // FEC_suppl:DateLimitReglmt + print $date_limit_payment; print $end_line; } diff --git a/htdocs/admin/agenda_reminder.php b/htdocs/admin/agenda_reminder.php index 27c6bbeed73..36f0c572de4 100644 --- a/htdocs/admin/agenda_reminder.php +++ b/htdocs/admin/agenda_reminder.php @@ -187,14 +187,14 @@ print ' '."\n"; print ''."\n"; if (empty($conf->global->AGENDA_REMINDER_BROWSER)) { - if (! getIsHTTPS()) { + if (!isHTTPS()) { $langs->load("errors"); print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' '; } print ''.img_picto($langs->trans('Disabled'), 'switch_off').''; print ''."\n"; } else { - if (! getIsHTTPS()) { + if (!isHTTPS()) { $langs->load("errors"); print img_warning($langs->trans("WarningAvailableOnlyForHTTPSServers"), '', 'valignmiddle size15x').' '; } diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 4fc07fa1172..b5e92bb2961 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -475,24 +475,22 @@ print load_fiche_titre($langs->trans("ModulesSetup"), '', 'title_setup'); if ($mode == 'common' || $mode == 'commonkanban') { $desc = $langs->trans("ModulesDesc", '{picto}'); $desc = str_replace('{picto}', img_picto('', 'switch_off'), $desc); - print ''.$desc."
\n"; + print ''.$desc."

\n"; } if ($mode == 'marketplace') { - print ''.$langs->trans("ModulesMarketPlaceDesc")."
\n"; + print ''.$langs->trans("ModulesMarketPlaceDesc")."

\n"; } if ($mode == 'deploy') { - print ''.$langs->trans("ModulesDeployDesc", $langs->transnoentitiesnoconv("AvailableModules"))."
\n"; + print ''.$langs->trans("ModulesDeployDesc", $langs->transnoentitiesnoconv("AvailableModules"))."

\n"; } if ($mode == 'develop') { - print ''.$langs->trans("ModulesDevelopDesc")."
\n"; + print ''.$langs->trans("ModulesDevelopDesc")."

\n"; } + $head = modules_prepare_head(); -print "
\n"; - - if ($mode == 'common' || $mode == 'commonkanban') { dol_set_focus('#search_keyword'); diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 8e2f07ec4fc..7f8e415e4b1 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1146,6 +1146,8 @@ class Categorie extends CommonObject // First build full array $motherof //$this->load_motherof(); // Disabled because already done by caller of build_path_from_id_categ + // $this->cats[$id_categ] is supposed to be already an array. We just want to complete it with property fullpath and fulllabel + // Define fullpath and fulllabel $this->cats[$id_categ]['fullpath'] = '_'.$id_categ; $this->cats[$id_categ]['fulllabel'] = $this->cats[$id_categ]['label']; diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 81f64ef6016..bcf1e9c1e3b 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -131,8 +131,8 @@ if (GETPOST('exportcsv', 'int')) header('Content-Disposition: attachment;filename='.$completefilename); // List of selected targets - $sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.tms,"; - $sql .= " mc.source_url, mc.source_id, mc.source_type, mc.error_text"; + $sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut as status, mc.date_envoi, mc.tms,"; + $sql .= " mc.source_id, mc.source_type, mc.error_text"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; $sql .= " WHERE mc.fk_mailing=".$object->id; $sql .= $db->order($sortfield, $sortorder); @@ -146,16 +146,16 @@ if (GETPOST('exportcsv', 'int')) while ($obj = $db->fetch_object($resql)) { print $obj->rowid.$sep; - print $obj->lastname.$sep; - print $obj->firstname.$sep; + print '"'.$obj->lastname.'"'.$sep; + print '"'.$obj->firstname.'"'.$sep; print $obj->email.$sep; print $obj->other.$sep; - print $obj->date_envoi.$sep; print $obj->tms.$sep; - print $obj->source_url.$sep; - print $obj->source_id.$sep; print $obj->source_type.$sep; - print $obj->error_text.$sep; + print $obj->source_id.$sep; + print $obj->date_envoi.$sep; + print $obj->status.$sep; + print '"'.$obj->error_text.'"'.$sep; print "\n"; } @@ -499,7 +499,7 @@ if ($object->fetch($id) >= 0) // Fix/update nbemail on emailing record if it differs (may happen if user edit lines from database directly) if (empty($asearchcriteriahasbeenset)) { - if ($nbtotalofrecords != $object->email) { + if ($nbtotalofrecords != $object->nbemail) { dol_syslog("We found a difference in nb of record in target table and the property ->nbemail, we fix ->nbemail"); //print "nbemail=".$object->nbemail." nbtotalofrecords=".$nbtotalofrecords; $resultrefresh = $object->refreshNbOfTargets(); diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index 2961218f148..56670da17cd 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -619,12 +619,15 @@ class Mailing extends CommonObject if (! $resqlupdate) { $this->error = $this->db->lasterror(); return -1; + } else { + $this->nbemail = (int) $nbforupdate; } } } else { $this->error = $this->db->lasterror(); return -1; } + return 1; } diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index c61bfdf6819..a1bde7e4f3d 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -1584,6 +1584,8 @@ if ($resql) { print ''.price($marginInfo['total_margin']).''; if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'total_margin'; + $totalarray['val']['total_margin'] += $marginInfo['total_margin']; } // Total margin rate if (!empty($arrayfields['total_margin_rate']['checked'])) diff --git a/htdocs/core/boxes/box_scheduled_jobs.php b/htdocs/core/boxes/box_scheduled_jobs.php index 2ac81c80d16..04ba2944c75 100644 --- a/htdocs/core/boxes/box_scheduled_jobs.php +++ b/htdocs/core/boxes/box_scheduled_jobs.php @@ -42,6 +42,9 @@ class box_scheduled_jobs extends ModeleBoxes */ public $db; + /** + * @var string params + */ public $param; public $info_box_head = array(); @@ -101,9 +104,11 @@ class box_scheduled_jobs extends ModeleBoxes if (dol_eval($objp->test, 1, 1)) { $nextrun = $this->db->jdate($objp->datenextrun); - if (empty($nextrun)) $nextrun = $this->db->jdate($objp->datestart); + if (empty($nextrun)) { + $nextrun = $this->db->jdate($objp->datestart); + } - if ($line == 0 || ($nextrun < $cronstatic->datenextrun && (empty($objp->nbrun) || empty($objp->maxrun) || $objp->nbrun < $obj->maxrun))) { + if ($line == 0 || ($nextrun < $cronstatic->datenextrun && (empty($objp->nbrun) || empty($objp->maxrun) || $objp->nbrun < $objp->maxrun))) { $cronstatic->id = $objp->rowid; $cronstatic->ref = $objp->rowid; $cronstatic->label = $langs->trans($objp->label); diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index f9f1c3b99ef..7cd38233eb3 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -129,7 +129,7 @@ class Notify if (is_array($listofnotiftodo)) { $i = 0; - foreach ($listofnotiftodo as $key => $val) { + foreach ($listofnotiftodo as $val) { if ($i) { $texte .= ', '; } else { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 884d8eac496..a156f35292e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2909,7 +2909,7 @@ function getUserRemoteIP() * * @return boolean True if user is using HTTPS */ -function getIsHTTPS() +function isHTTPS() { $isSecure = false; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { @@ -3032,7 +3032,7 @@ function dol_print_address($address, $htmlid, $element, $id, $noprint = 0, $char /** * Return true if email syntax is ok. * - * @param string $address email (Ex: "toto@examle.com", "John Do ") + * @param string $address email (Ex: "toto@examle.com". Long form "John Do " will be false) * @param int $acceptsupervisorkey If 1, the special string '__SUPERVISOREMAIL__' is also accepted as valid * @return boolean true if email syntax is OK, false if KO or empty string * @see isValidMXRecord() @@ -7123,9 +7123,9 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen foreach (array_keys($array) as $key) { if (is_object($array[$key])) { - $temp[$key] = $array[$key]->$index; + $temp[$key] = empty($array[$key]->$index) ? 0 : $array[$key]->$index; } else { - $temp[$key] = $array[$key][$index]; + $temp[$key] = empty($array[$key][$index]) ? 0 : $array[$key][$index]; } } diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 8391c6aab06..a77f38f8f66 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1252,7 +1252,7 @@ function check_value($mask, $value) //print "masktri=".$masktri." maskcounter=".$maskcounter." maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode." maskraz=".$maskraz." maskoffset=".$maskoffset."
\n"; if (function_exists('mb_strrpos')) { - $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 'UTF-8'); + $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0, 'UTF-8'); } else { $posnumstart = strrpos($maskwithnocode, $maskcounter); diff --git a/htdocs/core/lib/ws.lib.php b/htdocs/core/lib/ws.lib.php index faf1b5bc871..2545c8e5973 100644 --- a/htdocs/core/lib/ws.lib.php +++ b/htdocs/core/lib/ws.lib.php @@ -29,7 +29,7 @@ * @param array $authentication Array with authentication informations ('login'=>,'password'=>,'entity'=>,'dolibarrkey'=>) * @param int $error Number of errors * @param string $errorcode Error string code - * @param string $errorlabel Error string label + * @param string $errorlabel Error string label * @return User Return user object identified by login/pass/entity into authentication array */ function check_authentication($authentication, &$error, &$errorcode, &$errorlabel) diff --git a/htdocs/core/modules/mailings/xinputfile.modules.php b/htdocs/core/modules/mailings/xinputfile.modules.php index afc691f3e2e..a31d1c41483 100644 --- a/htdocs/core/modules/mailings/xinputfile.modules.php +++ b/htdocs/core/modules/mailings/xinputfile.modules.php @@ -162,7 +162,6 @@ class mailing_xinputfile extends MailingTargets if (!empty($buffer)) { //print 'xx'.dol_strlen($buffer).empty($buffer)."
\n"; - $id = $cpt; if (isValidEMail($email)) { if ($old <> $email) diff --git a/htdocs/core/modules/societe/mod_codeclient_elephant.php b/htdocs/core/modules/societe/mod_codeclient_elephant.php index 9b870bd5dd2..18947732b16 100644 --- a/htdocs/core/modules/societe/mod_codeclient_elephant.php +++ b/htdocs/core/modules/societe/mod_codeclient_elephant.php @@ -212,8 +212,8 @@ class mod_codeclient_elephant extends ModeleThirdPartyCode // Get Mask value $mask = ''; - if ($type == 0) $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; - if ($type == 1) $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; + if ($type == 0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER) ? '' : $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; + if ($type == 1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER) ? '' : $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; if (!$mask) { $this->error = 'NotConfigured'; diff --git a/htdocs/core/modules/societe/mod_codecompta_digitaria.php b/htdocs/core/modules/societe/mod_codecompta_digitaria.php index 961fa1a4e73..ea25a480d45 100644 --- a/htdocs/core/modules/societe/mod_codecompta_digitaria.php +++ b/htdocs/core/modules/societe/mod_codecompta_digitaria.php @@ -157,6 +157,8 @@ class mod_codecompta_digitaria extends ModeleAccountancyCode $i = 0; $this->code = ''; + $disponibility = 0; + if (is_object($societe)) { dol_syslog("mod_codecompta_digitaria::get_code search code for type=".$type." & company=".(!empty($societe->name) ? $societe->name : '')); @@ -216,8 +218,7 @@ class mod_codecompta_digitaria extends ModeleAccountancyCode } } - if ($disponibility == 0) - { + if ($disponibility == 0) { return 0; // return ok } else { return -1; // return ko diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php index ca2b9fec473..4c4a3fc3412 100644 --- a/htdocs/ecm/class/ecmdirectory.class.php +++ b/htdocs/ecm/class/ecmdirectory.class.php @@ -345,7 +345,7 @@ class EcmDirectory extends CommonObject $sql .= " t.date_c as date_c,"; $sql .= " t.tms as date_m"; $sql .= " FROM ".MAIN_DB_PREFIX."ecm_directories as t"; - $sql .= " WHERE t.rowid = ".$id; + $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/ecm/dir_card.php b/htdocs/ecm/dir_card.php index 9dc6977f1e4..8b86f99d2c7 100644 --- a/htdocs/ecm/dir_card.php +++ b/htdocs/ecm/dir_card.php @@ -54,7 +54,7 @@ $pagenext = $page + 1; if (!$sortorder) $sortorder = "ASC"; if (!$sortfield) $sortfield = "name"; -$section = GETPOST("section", 'alpha') ?GETPOST("section", 'alpha') : GETPOST("relativedir", 'alpha'); +$section = GETPOST("section", 'alpha') ? GETPOST("section", 'alpha') : GETPOST("relativedir", 'alpha'); if (!$section) { dol_print_error('', "ErrorSectionParamNotDefined"); @@ -66,15 +66,15 @@ $ecmdir = new EcmDirectory($db); if ($module == 'ecm') { + // $section should be an int except if it is dir not yet created into EcmDirectory $result = $ecmdir->fetch($section); - if (!$result > 0) - { - dol_print_error($db, $ecmdir->error); - exit; + if ($result > 0) { + $relativepath = $ecmdir->getRelativePath(); + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; + } else { + $relativepath = $section; + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; } - - $relativepath = $ecmdir->getRelativePath(); - $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; } else // For example $module == 'medias' { $relativepath = $section; @@ -143,28 +143,23 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') } // Remove dir -if ($action == 'confirm_deletedir' && $confirm == 'yes') -{ +if ($action == 'confirm_deletedir' && $confirm == 'yes') { $backtourl = DOL_URL_ROOT."/ecm/index.php"; - if ($module == 'medias') - { + if ($module == 'medias') { $backtourl = DOL_URL_ROOT."/website/index.php?file_manager=1"; } $deletedirrecursive = (GETPOST('deletedirrecursive', 'alpha') == 'on' ? 1 : 0); - if ($module == 'ecm') - { + if ($module == 'ecm' && $ecmdir->id > 0) { // If manual ECM and directory is indexed into database // Fetch was already done $result = $ecmdir->delete($user, 'all', $deletedirrecursive); - if ($result <= 0) - { + if ($result <= 0) { $langs->load('errors'); setEventMessages($langs->trans($ecmdir->error, $ecmdir->label), null, 'errors'); } } else { - if ($deletedirrecursive) - { + if ($deletedirrecursive) { $resbool = dol_delete_dir_recursive($upload_dir, 0, 1); } else { $resbool = dol_delete_dir($upload_dir, 1); @@ -176,8 +171,7 @@ if ($action == 'confirm_deletedir' && $confirm == 'yes') $result = 0; } } - if ($result > 0) - { + if ($result > 0) { header("Location: ".$backtourl); exit; } @@ -269,10 +263,9 @@ if ($action == 'update' && !GETPOST('cancel', 'alpha')) } - -/******************************************************************* -* View -********************************************************************/ +/* + * View + */ $form = new Form($db); @@ -281,9 +274,7 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); - -if ($module == 'ecm') -{ +if ($module == 'ecm' && $ecmdir->id > 0) { $object->fetch($ecmdir->id); } @@ -323,24 +314,27 @@ if ($module == 'ecm') $result = 1; $i = 0; $tmpecmdir = new EcmDirectory($db); // Need to create a new one - $tmpecmdir->fetch($ecmdir->id); - while ($tmpecmdir && $result > 0) - { - $tmpecmdir->ref = $tmpecmdir->label; - if ($i == 0 && $action == 'edit') + if ($ecmdir->id > 0) { + $tmpecmdir->fetch($ecmdir->id); + while ($tmpecmdir && $result > 0) { - $s = ''; - } else $s = $tmpecmdir->getNomUrl(1).$s; - if ($tmpecmdir->fk_parent) - { - $s = ' -> '.$s; - $result = $tmpecmdir->fetch($tmpecmdir->fk_parent); - } else { - $tmpecmdir = 0; + $tmpecmdir->ref = $tmpecmdir->label; + if ($i == 0 && $action == 'edit') + { + $s = ''; + } else $s = $tmpecmdir->getNomUrl(1).$s; + if ($tmpecmdir->fk_parent) + { + $s = ' -> '.$s; + $result = $tmpecmdir->fetch($tmpecmdir->fk_parent); + } else { + $tmpecmdir = 0; + } + $i++; } - $i++; + } else { + $s .= join(' -> ', explode('/', $section)); } - $morehtmlref = ''.$langs->trans("ECMRoot").' -> '.$s; } if ($module == 'medias') @@ -393,9 +387,11 @@ if ($module == 'ecm') print ''; print ''.$langs->trans("ECMCreationUser").''; - $userecm = new User($db); - $userecm->fetch($ecmdir->fk_user_c); - print $userecm->getNomUrl(1); + if ($ecmdir->fk_user_c > 0) { + $userecm = new User($db); + $userecm->fetch($ecmdir->fk_user_c); + print $userecm->getNomUrl(1); + } print ''; } print ''.$langs->trans("ECMCreationDate").''; diff --git a/htdocs/includes/nusoap/lib/nusoap.php b/htdocs/includes/nusoap/lib/nusoap.php index 459f4aeb7b6..7e0ebd94da4 100644 --- a/htdocs/includes/nusoap/lib/nusoap.php +++ b/htdocs/includes/nusoap/lib/nusoap.php @@ -6125,7 +6125,7 @@ class wsdl extends nusoap_base { $rows = sizeof($value); $contents = ''; foreach($value as $k => $v) { - $this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]"); + $this->debug("serializing array element: $k of type: ".$typeDef['arrayType']); //if (strpos($typeDef['arrayType'], ':') ) { if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) { $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use); diff --git a/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql b/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql index 23e7d489e09..3a612623298 100644 --- a/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql +++ b/htdocs/install/mysql/tables/llx_accounting_bookkeeping.sql @@ -41,7 +41,7 @@ CREATE TABLE llx_accounting_bookkeeping multicurrency_code varchar(255), -- FEC:Idevise lettering_code varchar(255), -- FEC:EcritureLet date_lettering datetime, -- FEC:DateLet - date_lim_reglement datetime DEFAULT NULL, -- | date limite de reglement + date_lim_reglement datetime DEFAULT NULL, -- FEC_suppl:DateLimitReglmt | payment deadline fk_user_author integer NOT NULL, -- | user creating fk_user_modif integer, -- | user making last change date_creation datetime, -- FEC:EcritureDate | creation date diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 1c2eb2327d2..63e0fea2b36 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2395,7 +2395,7 @@ class Product extends CommonObject public function load_stats_mo($socid = 0) { // phpcs:enable - global $user, $hookmanager; + global $user, $hookmanager, $action; $error = 0; @@ -2408,7 +2408,7 @@ class Product extends CommonObject $sql .= " SUM(mp.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."mrp_production as mp ON mp.fk_mo=c.rowid"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= "INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".$user->id; } $sql .= " WHERE "; @@ -2527,14 +2527,14 @@ class Product extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd"; $sql .= ", ".MAIN_DB_PREFIX."propal as p"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = pd.fk_propal"; $sql .= " AND p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('propal').")"; $sql .= " AND pd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND pr.fk_statut != 0"; @@ -2593,23 +2593,26 @@ class Product extends CommonObject public function load_stats_proposal_supplier($socid = 0) { // phpcs:enable - global $conf, $user, $hookmanager; + global $conf, $user, $hookmanager, $action; $sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_suppliers, COUNT(DISTINCT p.rowid) as nb,"; $sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as pd"; $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = pd.fk_supplier_proposal"; $sql .= " AND p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")"; $sql .= " AND pd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND pr.fk_statut != 0"; - if ($socid > 0) { $sql .= " AND p.fk_soc = ".$socid; + if ($socid > 0) { + $sql .= " AND p.fk_soc = ".$socid; } $result = $this->db->query($sql); @@ -2665,7 +2668,7 @@ class Product extends CommonObject $sql .= " AND c.fk_soc = ".$socid; } if ($filtrestatut <> '') { - $sql .= " AND c.fk_statut in (".$filtrestatut.")"; + $sql .= " AND c.fk_statut in (".$this->db->sanitize($filtrestatut).")"; } $result = $this->db->query($sql); @@ -2744,28 +2747,28 @@ class Product extends CommonObject public function load_stats_commande_fournisseur($socid = 0, $filtrestatut = '', $forVirtualStock = 0) { // phpcs:enable - global $conf, $user, $hookmanager; + global $conf, $user, $hookmanager, $action; $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_commande"; $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")"; $sql .= " AND cd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { $sql .= " AND c.fk_soc = ".$socid; } if ($filtrestatut != '') { - $sql .= " AND c.fk_statut in (".$filtrestatut.")"; // Peut valoir 0 + $sql .= " AND c.fk_statut in (".$this->db->sanitize($filtrestatut).")"; // Peut valoir 0 } $result = $this->db->query($sql); @@ -2809,7 +2812,7 @@ class Product extends CommonObject $sql .= ", ".MAIN_DB_PREFIX."commande as c"; $sql .= ", ".MAIN_DB_PREFIX."expedition as e"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE e.rowid = ed.fk_expedition"; @@ -2818,16 +2821,16 @@ class Product extends CommonObject $sql .= " AND e.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'expedition').")"; $sql .= " AND ed.fk_origin_line = cd.rowid"; $sql .= " AND cd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= " AND e.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { $sql .= " AND e.fk_soc = ".$socid; } if ($filtrestatut <> '') { - $sql .= " AND c.fk_statut in (".$filtrestatut.")"; + $sql .= " AND c.fk_statut IN (".$this->db->sanitize($filtrestatut).")"; } - if (!empty($filterShipmentStatus)) $sql .= " AND e.fk_statut IN (".$filterShipmentStatus.")"; + if (!empty($filterShipmentStatus)) $sql .= " AND e.fk_statut IN (".$this->db->sanitize($filterShipmentStatus).")"; $result = $this->db->query($sql); if ($result) { @@ -2881,24 +2884,28 @@ class Product extends CommonObject public function load_stats_reception($socid = 0, $filtrestatut = '', $forVirtualStock = 0) { // phpcs:enable - global $conf, $user, $hookmanager; + global $conf, $user, $hookmanager, $action; $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_suppliers, COUNT(DISTINCT cf.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd"; $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE cf.rowid = fd.fk_commande"; $sql .= " AND cf.fk_soc = s.rowid"; $sql .= " AND cf.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'supplier_order').")"; $sql .= " AND fd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { + $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } - if ($socid > 0) { $sql .= " AND cf.fk_soc = ".$socid; + if ($socid > 0) { + $sql .= " AND cf.fk_soc = ".$socid; } - if ($filtrestatut <> '') { $sql .= " AND cf.fk_statut in (".$filtrestatut.")"; + if ($filtrestatut <> '') { + $sql .= " AND cf.fk_statut IN (".$this->db->sanitize($filtrestatut).")"; } $result = $this->db->query($sql); @@ -2939,20 +2946,20 @@ class Product extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."mrp_production as mp"; $sql .= ", ".MAIN_DB_PREFIX."mrp_mo as m"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = m.fk_soc"; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE m.rowid = mp.fk_mo"; $sql .= " AND m.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mrp').")"; $sql .= " AND mp.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid && !$forVirtualStock) { + if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { $sql .= " AND m.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { $sql .= " AND m.fk_soc = ".$socid; } if ($filtrestatut <> '') { - $sql .= " AND m.status in (".$filtrestatut.")"; + $sql .= " AND m.status IN (".$this->db->sanitize($filtrestatut).")"; } $sql .= " GROUP BY role"; @@ -3026,14 +3033,14 @@ class Product extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; $sql .= ", ".MAIN_DB_PREFIX."contrat as c"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_contrat"; $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('contract').")"; $sql .= " AND cd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND c.statut != 0"; @@ -3098,14 +3105,14 @@ class Product extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd"; $sql .= ", ".MAIN_DB_PREFIX."facture as f"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = fd.fk_facture"; $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; $sql .= " AND fd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND f.fk_statut != 0"; @@ -3163,21 +3170,21 @@ class Product extends CommonObject public function load_stats_facture_fournisseur($socid = 0) { // phpcs:enable - global $conf, $user, $hookmanager; + global $conf, $user, $hookmanager, $action; $sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_suppliers, COUNT(DISTINCT f.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as fd"; $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = fd.fk_facture_fourn"; $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('facture_fourn').")"; $sql .= " AND fd.fk_product = ".$this->id; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } //$sql.= " AND f.fk_statut != 0"; @@ -3302,7 +3309,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = d.fk_facture"; @@ -3312,11 +3319,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3355,7 +3362,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = d.fk_facture_fourn"; @@ -3365,11 +3372,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND f.fk_soc = s.rowid"; $sql .= " AND f.entity IN (".getEntity('facture_fourn').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3406,7 +3413,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as prod"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = d.fk_propal"; @@ -3416,11 +3423,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND prod.rowid = d.fk_product AND prod.fk_product_type =".$filteronproducttype; + $sql .= " AND prod.rowid = d.fk_product AND prod.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('propal').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3458,7 +3465,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as prod"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = d.fk_supplier_proposal"; @@ -3468,11 +3475,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND prod.rowid = d.fk_product AND prod.fk_product_type =".$filteronproducttype; + $sql .= " AND prod.rowid = d.fk_product AND prod.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND p.fk_soc = s.rowid"; $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3509,7 +3516,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = d.fk_commande"; @@ -3519,11 +3526,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('commande').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3560,7 +3567,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = d.fk_commande"; @@ -3570,11 +3577,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('supplier_order').")"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3611,7 +3618,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } @@ -3624,11 +3631,11 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } $sql .= " AND c.fk_soc = s.rowid"; - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { @@ -3665,7 +3672,7 @@ class Product extends CommonObject if ($filteronproducttype >= 0) { $sql .= ", ".MAIN_DB_PREFIX."product as p"; } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } @@ -3678,10 +3685,10 @@ class Product extends CommonObject $sql .= " AND d.fk_product > 0"; } if ($filteronproducttype >= 0) { - $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type =".$filteronproducttype; + $sql .= " AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype); } - if (!$user->rights->societe->client->voir && !$socid) { + if (empty($user->rights->societe->client->voir) && !$socid) { $sql .= " AND d.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; } if ($socid > 0) { diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 648ce4840fe..a624daf8afb 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -533,9 +533,6 @@ if ($resql) //'builddoc'=>$langs->trans("PDFMerge"), //'presend'=>$langs->trans("SendByMail"), ); - - $rightskey = 'produit'; - if ($type == Product::TYPE_SERVICE) $rightskey = 'service'; if ($user->rights->{$rightskey}->supprimer) $arrayofmassactions['predelete'] = "".$langs->trans("Delete"); if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); $massactionbutton = $form->selectMassAction('', $arrayofmassactions); diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 0fc33232c5d..7fccdf994b9 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -109,7 +109,7 @@ if ($object->id > 0) { $permissiontoread = $user->rights->societe->lire; $permissiontoadd = $user->rights->societe->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php -$permissiontodelete = $user->rights->societe->delete || ($permissiontoadd && isset($object->status) && $object->status == 0); +$permissiontodelete = $user->rights->societe->supprimer || ($permissiontoadd && isset($object->status) && $object->status == 0); $permissionnote = $user->rights->societe->creer; // Used by the include of actions_setnotes.inc.php $permissiondellink = $user->rights->societe->creer; // Used by the include of actions_dellink.inc.php $upload_dir = $conf->societe->multidir_output[isset($object->entity) ? $object->entity : 1]; @@ -1355,7 +1355,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print 'browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_phoning_fax').' '; // Email / Web - print ''.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', $conf->global->SOCIETE_EMAIL_MANDATORY).''; + print ''.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', empty($conf->global->SOCIETE_EMAIL_MANDATORY) ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY).''; print ''.img_picto('', 'object_email').' '; print ''.$form->editfieldkey('Web', 'url', '', $object, 0).''; print ''.img_picto('', 'globe').' '; @@ -1366,7 +1366,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; } elseif (!empty($object->socialnetworks[$key])) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 0aeb64aa427..4c25a002a8f 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -784,17 +784,24 @@ class Societe extends CommonObject $error = 0; // Clean parameters - if (empty($this->status)) $this->status = 0; + if (empty($this->status)) { + $this->status = 0; + } $this->name = $this->name ?trim($this->name) : trim($this->nom); $this->setUpperOrLowerCase(); $this->nom = $this->name; // For backward compatibility - if (empty($this->client)) $this->client = 0; - if (empty($this->fournisseur)) $this->fournisseur = 0; + if (empty($this->client)) { + $this->client = 0; + } + if (empty($this->fournisseur)) { + $this->fournisseur = 0; + } $this->import_key = trim($this->import_key); - if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); - if (empty($this->fk_multicurrency)) - { + if (!empty($this->multicurrency_code)) { + $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + } + if (empty($this->fk_multicurrency)) { $this->multicurrency_code = ''; $this->fk_multicurrency = 0; } @@ -806,15 +813,18 @@ class Societe extends CommonObject $this->db->begin(); // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) - if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this, 0); - if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1); + if ($this->code_client == -1 || $this->code_client === 'auto') { + $this->get_codeclient($this, 0); + } + if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') { + $this->get_codefournisseur($this, 1); + } // Check more parameters (including mandatory setup // If error, this->errors[] is filled $result = $this->verify(); - if ($result >= 0) - { + if ($result >= 0) { $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)"; @@ -832,44 +842,42 @@ class Societe extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe"); $ret = $this->update($this->id, $user, 0, 1, 1, 'add'); // Ajout du commercial affecte - if ($this->commercial_id != '' && $this->commercial_id != -1) - { + if ($this->commercial_id != '' && $this->commercial_id != -1) { $this->add_commercial($user, $this->commercial_id); } // si un commercial cree un client il lui est affecte automatiquement - elseif (empty($user->rights->societe->client->voir)) - { + elseif (empty($user->rights->societe->client->voir)) { $this->add_commercial($user, $user->id); } - if ($ret >= 0) - { + if ($ret >= 0) { // Call trigger $result = $this->call_trigger('COMPANY_CREATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers - } else $error++; + } else { + $error++; + } - if (!$error) - { + if (!$error) { dol_syslog(get_class($this)."::Create success id=".$this->id); $this->db->commit(); return $this->id; } else { - dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',', $this->errors), LOG_ERR); + dol_syslog(get_class($this)."::Create echec update ".$this->error.(empty($this->errors) ? '' : ' '.join(',', $this->errors)), LOG_ERR); $this->db->rollback(); return -4; } } else { - if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); // duplicate on a field (code or profid or ...) $result = -1; } else { @@ -916,8 +924,7 @@ class Societe extends CommonObject $contact->phone_pro = $this->phone; $result = $contact->create($user); - if ($result < 0) - { + if ($result < 0) { $this->error = $contact->error; $this->errors = $contact->errors; dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR); @@ -943,28 +950,21 @@ class Societe extends CommonObject $this->name = trim($this->name); $this->nom = $this->name; // For backward compatibility - if (!$this->name) - { + if (!$this->name) { $this->errors[] = 'ErrorBadThirdPartyName'; $result = -2; } - if ($this->client) - { + if ($this->client) { $rescode = $this->check_codeclient(); - if ($rescode <> 0) - { - if ($rescode == -1) - { + if ($rescode != 0 && $rescode != -5) { + if ($rescode == -1) { $this->errors[] = 'ErrorBadCustomerCodeSyntax'; - } elseif ($rescode == -2) - { + } elseif ($rescode == -2) { $this->errors[] = 'ErrorCustomerCodeRequired'; - } elseif ($rescode == -3) - { + } elseif ($rescode == -3) { $this->errors[] = 'ErrorCustomerCodeAlreadyUsed'; - } elseif ($rescode == -4) - { + } elseif ($rescode == -4) { $this->errors[] = 'ErrorPrefixRequired'; } else { $this->errors[] = 'ErrorUnknownOnCustomerCodeCheck'; @@ -974,22 +974,16 @@ class Societe extends CommonObject } } - if ($this->fournisseur) - { + if ($this->fournisseur) { $rescode = $this->check_codefournisseur(); - if ($rescode <> 0) - { - if ($rescode == -1) - { + if ($rescode != 0 && $rescode != -5) { + if ($rescode == -1) { $this->errors[] = 'ErrorBadSupplierCodeSyntax'; - } elseif ($rescode == -2) - { + } elseif ($rescode == -2) { $this->errors[] = 'ErrorSupplierCodeRequired'; - } elseif ($rescode == -3) - { + } elseif ($rescode == -3) { $this->errors[] = 'ErrorSupplierCodeAlreadyUsed'; - } elseif ($rescode == -4) - { + } elseif ($rescode == -4) { $this->errors[] = 'ErrorPrefixRequired'; } else { $this->errors[] = 'ErrorUnknownOnSupplierCodeCheck'; @@ -1000,22 +994,17 @@ class Societe extends CommonObject // Check for duplicate or mandatory fields defined into setup $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL'); - foreach ($array_to_check as $key) - { + foreach ($array_to_check as $key) { $keymin = strtolower($key); $i = (int) preg_replace('/[^0-9]/', '', $key); $vallabel = $this->$keymin; - if ($i > 0) - { - if ($this->isACompany()) - { + if ($i > 0) { + if ($this->isACompany()) { // Check for mandatory prof id (but only if country is same than ours) - if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) - { + if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id) { $idprof_mandatory = 'SOCIETE_'.$key.'_MANDATORY'; - if (!$vallabel && !empty($conf->global->$idprof_mandatory)) - { + if (!$vallabel && !empty($conf->global->$idprof_mandatory)) { $langs->load("errors"); $error++; $this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')'; @@ -1024,10 +1013,8 @@ class Societe extends CommonObject } // Check for unicity on profid - if (!$error && $vallabel && $this->id_prof_verifiable($i)) - { - if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) - { + if (!$error && $vallabel && $this->id_prof_verifiable($i)) { + if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { $langs->load("errors"); $error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; @@ -1036,21 +1023,17 @@ class Societe extends CommonObject } else { //var_dump($conf->global->SOCIETE_EMAIL_UNIQUE); //var_dump($conf->global->SOCIETE_EMAIL_MANDATORY); - if ($key == 'EMAIL') - { + if ($key == 'EMAIL') { // Check for mandatory - if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) - { + if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email)) { $langs->load("errors"); $error++; $this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')'; } // Check for unicity - if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) - { - if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) - { + if (!$error && $vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE)) { + if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0))) { $langs->load("errors"); $error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')'; } @@ -1059,7 +1042,9 @@ class Societe extends CommonObject } } - if ($error) $result = -4; + if ($error) { + $result = -4; + } return $result; } @@ -1082,7 +1067,9 @@ class Societe extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - if (empty($id)) $id = $this->id; + if (empty($id)) { + $id = $this->id; + } $error = 0; @@ -1126,11 +1113,14 @@ class Societe extends CommonObject $this->tva_assuj = trim($this->tva_assuj); $this->tva_intra = dol_sanitizeFileName($this->tva_intra, ''); - if (empty($this->status)) $this->status = 0; + if (empty($this->status)) { + $this->status = 0; + } - if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); - if (empty($this->fk_multicurrency)) - { + if (!empty($this->multicurrency_code)) { + $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + } + if (empty($this->fk_multicurrency)) { $this->multicurrency_code = ''; $this->fk_multicurrency = 0; } @@ -1142,8 +1132,12 @@ class Societe extends CommonObject $this->localtax1_value = trim($this->localtax1_value); $this->localtax2_value = trim($this->localtax2_value); - if ($this->capital != '') $this->capital = price2num(trim($this->capital)); - if (!is_numeric($this->capital)) $this->capital = ''; // '' = undef + if ($this->capital != '') { + $this->capital = price2num(trim($this->capital)); + } + if (!is_numeric($this->capital)) { + $this->capital = ''; // '' = undef + } $this->effectif_id = trim($this->effectif_id); $this->forme_juridique_code = trim($this->forme_juridique_code); @@ -1152,41 +1146,44 @@ class Societe extends CommonObject $this->barcode = trim($this->barcode); // For automatic creation - if ($this->code_client == -1 || $this->code_client === 'auto') $this->get_codeclient($this, 0); - if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1); + if ($this->code_client == -1 || $this->code_client === 'auto') { + $this->get_codeclient($this, 0); + } + if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') { + $this->get_codefournisseur($this, 1); + } $this->code_compta = trim($this->code_compta); $this->code_compta_fournisseur = trim($this->code_compta_fournisseur); // Check parameters. More tests are done later in the ->verify() - if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) - { + if (!is_numeric($this->client) && !is_numeric($this->fournisseur)) { $langs->load("errors"); $this->error = $langs->trans("BadValueForParameterClientOrSupplier"); return -1; } $customer = false; - if (!empty($allowmodcodeclient) && !empty($this->client)) - { + if (!empty($allowmodcodeclient) && !empty($this->client)) { // Attention get_codecompta peut modifier le code suivant le module utilise - if (empty($this->code_compta)) - { + if (empty($this->code_compta)) { $ret = $this->get_codecompta('customer'); - if ($ret < 0) return -1; + if ($ret < 0) { + return -1; + } } $customer = true; } $supplier = false; - if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) - { + if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) { // Attention get_codecompta peut modifier le code suivant le module utilise - if ($this->code_compta_fournisseur == "") - { + if ($this->code_compta_fournisseur == "") { $ret = $this->get_codecompta('supplier'); - if ($ret < 0) return -1; + if ($ret < 0) { + return -1; + } } $supplier = true; @@ -1205,33 +1202,31 @@ class Societe extends CommonObject // Check name is required and codes are ok or unique. // If error, this->errors[] is filled $result = 0; - if ($action != 'add' && $action != 'merge') - { + if ($action != 'add' && $action != 'merge') { // We don't check when update called during a create because verify was already done. // For a merge, we suppose source data is clean and a customer code of a deleted thirdparty must be accepted into a target thirdparty with empty code without duplicate error $result = $this->verify(); // If there is only one error and error is ErrorBadCustomerCodeSyntax and we don't change customer code, we allow the update // So we can update record that were using and old numbering rule. - if (is_array($this->errors)) - { - if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) - { - if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message + if (is_array($this->errors)) { + if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client) { + if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) { + unset($this->errors[$key]); // Remove error message + } } - if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) - { - if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message + if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur) { + if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) { + unset($this->errors[$key]); // Remove error message + } } - if (empty($this->errors)) // If there is no more error, we can make like if there is no error at all - { + if (empty($this->errors)) { // If there is no more error, we can make like if there is no error at all $result = 0; } } } - if ($result >= 0) - { + if ($result >= 0) { dol_syslog(get_class($this)."::update verify ok or not done"); $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET "; @@ -1272,29 +1267,32 @@ class Societe extends CommonObject // Local taxes $sql .= ",localtax1_assuj = ".($this->localtax1_assuj != '' ? "'".$this->db->escape($this->localtax1_assuj)."'" : "null"); $sql .= ",localtax2_assuj = ".($this->localtax2_assuj != '' ? "'".$this->db->escape($this->localtax2_assuj)."'" : "null"); - if ($this->localtax1_assuj == 1) - { - if ($this->localtax1_value != '') - { + if ($this->localtax1_assuj == 1) { + if ($this->localtax1_value != '') { $sql .= ",localtax1_value =".$this->localtax1_value; - } else $sql .= ",localtax1_value =0.000"; - } else $sql .= ",localtax1_value =0.000"; + } else { + $sql .= ",localtax1_value =0.000"; + } + } else { + $sql .= ",localtax1_value =0.000"; + } - if ($this->localtax2_assuj == 1) - { - if ($this->localtax2_value != '') - { + if ($this->localtax2_assuj == 1) { + if ($this->localtax2_value != '') { $sql .= ",localtax2_value =".$this->localtax2_value; - } else $sql .= ",localtax2_value =0.000"; - } else $sql .= ",localtax2_value =0.000"; + } else { + $sql .= ",localtax2_value =0.000"; + } + } else { + $sql .= ",localtax2_value =0.000"; + } $sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital); $sql .= ",prefix_comm = ".(!empty($this->prefix_comm) ? "'".$this->db->escape($this->prefix_comm)."'" : "null"); $sql .= ",fk_effectif = ".(!empty($this->effectif_id) ? "'".$this->db->escape($this->effectif_id)."'" : "null"); - if (isset($this->stcomm_id)) - { + if (isset($this->stcomm_id)) { $sql .= ",fk_stcomm=".(!empty($this->stcomm_id) ? $this->stcomm_id : "0"); } $sql .= ",fk_typent = ".(!empty($this->typent_id) ? "'".$this->db->escape($this->typent_id)."'" : "0"); @@ -1327,14 +1325,12 @@ class Societe extends CommonObject $sql .= ", fk_incoterms = ".$this->fk_incoterms; $sql .= ", location_incoterms = ".(!empty($this->location_incoterms) ? "'".$this->db->escape($this->location_incoterms)."'" : "null"); - if ($customer) - { + if ($customer) { $sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null"); $sql .= ", code_compta = ".(!empty($this->code_compta) ? "'".$this->db->escape($this->code_compta)."'" : "null"); } - if ($supplier) - { + if ($supplier) { $sql .= ", code_fournisseur = ".(!empty($this->code_fournisseur) ? "'".$this->db->escape($this->code_fournisseur)."'" : "null"); $sql .= ", code_compta_fournisseur = ".(($this->code_compta_fournisseur != "") ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null"); } @@ -1345,17 +1341,13 @@ class Societe extends CommonObject $sql .= " WHERE rowid = ".(int) $id; $resql = $this->db->query($sql); - if ($resql) - { - if (is_object($this->oldcopy)) // If we have information on old values - { - if ($this->oldcopy->country_id != $this->country_id) - { + if ($resql) { + if (is_object($this->oldcopy)) { // If we have information on old values + if ($this->oldcopy->country_id != $this->country_id) { unset($this->country_code); unset($this->country); } - if ($this->oldcopy->state_id != $this->state_id) - { + if ($this->oldcopy->state_id != $this->state_id) { unset($this->state_code); unset($this->state); } @@ -1368,11 +1360,9 @@ class Societe extends CommonObject $nbrowsaffected = $this->db->affected_rows($resql); - if (!$error && $nbrowsaffected) - { + if (!$error && $nbrowsaffected) { // Update information on linked member if it is an update - if (!$nosyncmember && !empty($conf->adherent->enabled)) - { + if (!$nosyncmember && !empty($conf->adherent->enabled)) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; dol_syslog(get_class($this)."::update update linked member"); @@ -1380,8 +1370,7 @@ class Societe extends CommonObject $lmember = new Adherent($this->db); $result = $lmember->fetch(0, 0, $this->id); - if ($result > 0) - { + if ($result > 0) { $lmember->company = $this->name; //$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname; // We keep firstname and lastname of member unchanged //$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname; // We keep firstname and lastname of member unchanged @@ -1395,15 +1384,13 @@ class Societe extends CommonObject $lmember->country_id = $this->country_id; $result = $lmember->update($user, 0, 1, 1, 1); // Use nosync to 1 to avoid cyclic updates - if ($result < 0) - { + if ($result < 0) { $this->error = $lmember->error; $this->errors = array_merge($this->errors, $lmember->errors); dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR); $error++; } - } elseif ($result < 0) - { + } elseif ($result < 0) { $this->error = $lmember->error; $error++; } @@ -1413,34 +1400,30 @@ class Societe extends CommonObject $action = 'update'; // Actions on extra fields - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } // Actions on extra languages - if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) // For avoid conflicts if trigger used - { + if (!$error && empty($conf->global->MAIN_EXTRALANGUAGES_DISABLED)) { // For avoid conflicts if trigger used $result = $this->insertExtraLanguages(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error && $call_trigger) - { + if (!$error && $call_trigger) { // Call trigger $result = $this->call_trigger('COMPANY_MODIFY', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { dol_syslog(get_class($this)."::Update success"); $this->db->commit(); return 1; @@ -1449,8 +1432,7 @@ class Societe extends CommonObject return -1; } } else { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { // Doublon $this->error = $langs->trans("ErrorDuplicateField"); $result = -1; @@ -1490,7 +1472,9 @@ class Societe extends CommonObject global $langs; global $conf; - if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1; + if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($barcode) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) { + return -1; + } $sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.address, s.datec as date_creation, s.prefix_comm'; $sql .= ', s.status'; @@ -1533,30 +1517,51 @@ class Societe extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_remise as sr ON sr.rowid = (SELECT MAX(rowid) FROM '.MAIN_DB_PREFIX.'societe_remise WHERE fk_soc = s.rowid AND entity IN ('.getEntity('discount').'))'; $sql .= ' WHERE s.entity IN ('.getEntity($this->element).')'; - if ($rowid) $sql .= ' AND s.rowid = '.$rowid; - if ($ref) $sql .= " AND s.nom = '".$this->db->escape($ref)."'"; - if ($ref_alias) $sql .= " AND s.name_alias = '".$this->db->escape($ref_alias)."'"; - if ($ref_ext) $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'"; - if ($barcode) $sql .= " AND s.barcode = '".$this->db->escape($barcode)."'"; - if ($idprof1) $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'"; - if ($idprof2) $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'"; - if ($idprof3) $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'"; - if ($idprof4) $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'"; - if ($idprof5) $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'"; - if ($idprof6) $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'"; - if ($email) $sql .= " AND s.email = '".$this->db->escape($email)."'"; + if ($rowid) { + $sql .= ' AND s.rowid = '.$rowid; + } + if ($ref) { + $sql .= " AND s.nom = '".$this->db->escape($ref)."'"; + } + if ($ref_alias) { + $sql .= " AND s.name_alias = '".$this->db->escape($ref_alias)."'"; + } + if ($ref_ext) { + $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'"; + } + if ($barcode) { + $sql .= " AND s.barcode = '".$this->db->escape($barcode)."'"; + } + if ($idprof1) { + $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'"; + } + if ($idprof2) { + $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'"; + } + if ($idprof3) { + $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'"; + } + if ($idprof4) { + $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'"; + } + if ($idprof5) { + $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'"; + } + if ($idprof6) { + $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'"; + } + if ($email) { + $sql .= " AND s.email = '".$this->db->escape($email)."'"; + } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); - if ($num > 1) - { + if ($num > 1) { $this->error = 'Fetch found several records. Rename one of thirdparties to avoid duplicate.'; dol_syslog($this->error, LOG_ERR); $result = -2; - } elseif ($num) // $num = 1 - { + } elseif ($num) { // $num = 1 $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -1642,7 +1647,7 @@ class Societe extends CommonObject $this->prefix_comm = $obj->prefix_comm; - $this->remise_percent = price2num($obj->remise_client); // 0.000000 must be 0 + $this->remise_percent = $obj->remise_client ? price2num($obj->remise_client) : 0; // 0.000000 must be 0 $this->remise_supplier_percent = $obj->remise_supplier; $this->mode_reglement_id = $obj->mode_reglement; $this->cond_reglement_id = $obj->cond_reglement; @@ -1702,7 +1707,9 @@ class Societe extends CommonObject } // Use first price level if level not defined for third party - if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) $this->price_level = 1; + if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($this->price_level)) { + $this->price_level = 1; + } return $result; } @@ -1719,7 +1726,9 @@ class Societe extends CommonObject { global $langs, $conf, $user; - if (empty($fuser)) $fuser = $user; + if (empty($fuser)) { + $fuser = $user; + } require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1730,49 +1739,42 @@ class Societe extends CommonObject // Test if child exists $objectisused = $this->isObjectUsed($id); - if (empty($objectisused)) - { + if (empty($objectisused)) { $this->db->begin(); // User is mandatory for trigger call - if (!$error && $call_trigger) - { + if (!$error && $call_trigger) { // Call trigger $result = $this->call_trigger('COMPANY_DELETE', $fuser); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $static_cat = new Categorie($this->db); $toute_categs = array(); // Fill $toute_categs array with an array of (type => array of ("Categorie" instance)) - if ($this->client || $this->prospect) - { + if ($this->client || $this->prospect) { $toute_categs['customer'] = $static_cat->containing($this->id, Categorie::TYPE_CUSTOMER); } - if ($this->fournisseur) - { + if ($this->fournisseur) { $toute_categs['supplier'] = $static_cat->containing($this->id, Categorie::TYPE_SUPPLIER); } // Remove each "Categorie" - foreach ($toute_categs as $type => $categs_type) - { - foreach ($categs_type as $cat) - { + foreach ($toute_categs as $type => $categs_type) { + foreach ($categs_type as $cat) { $cat->del_type($this, $type); } } } - if (!$error) - { - foreach ($this->childtablesoncascade as $tabletodelete) - { + if (!$error) { + foreach ($this->childtablesoncascade as $tabletodelete) { $deleteFromObject = explode(':', $tabletodelete); if (count($deleteFromObject) >= 2) { $className = str_replace('@', '', $deleteFromObject[0]); @@ -1804,51 +1806,42 @@ class Societe extends CommonObject } // Removed extrafields - if (!$error) - { + if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR); } } // Remove links to subsidiaries companies - if (!$error) - { + if (!$error) { $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET parent = NULL"; $sql .= " WHERE parent = ".$id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $error++; $this->errors[] = $this->db->lasterror(); } } // Remove third party - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe"; $sql .= " WHERE rowid = ".$id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $error++; $this->errors[] = $this->db->lasterror(); } } - if (!$error) - { + if (!$error) { $this->db->commit(); // Delete directory - if (!empty($conf->societe->multidir_output[$entity])) - { + if (!empty($conf->societe->multidir_output[$entity])) { $docdir = $conf->societe->multidir_output[$entity]."/".$id; - if (dol_is_dir($docdir)) - { + if (dol_is_dir($docdir)) { dol_delete_dir_recursive($docdir); } } @@ -1859,7 +1852,9 @@ class Societe extends CommonObject $this->db->rollback(); return -1; } - } else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING); + } else { + dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING); + } return 0; } @@ -1872,20 +1867,22 @@ class Societe extends CommonObject public function set_as_client() { // phpcs:enable - if ($this->id) - { + if ($this->id) { $newclient = 1; - if ($this->client == 2 || $this->client == 3) $newclient = 3; //If prospect, we keep prospect tag + if ($this->client == 2 || $this->client == 3) { + $newclient = 3; //If prospect, we keep prospect tag + } $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET client = ".$newclient; $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->client = $newclient; return 1; - } else return -1; + } else { + return -1; + } } return 0; } @@ -1906,16 +1903,14 @@ class Societe extends CommonObject // Parameter cleaning $note = trim($note); - if (!$note) - { + if (!$note) { $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NoteReason")); return -2; } dol_syslog(get_class($this)."::set_remise_client ".$remise.", ".$note.", ".$user->id); - if ($this->id) - { + if ($this->id) { $this->db->begin(); $now = dol_now(); @@ -1925,8 +1920,7 @@ class Societe extends CommonObject $sql .= " SET remise_client = '".$this->db->escape($remise)."'"; $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->db->rollback(); $this->error = $this->db->error(); return -1; @@ -1941,8 +1935,7 @@ class Societe extends CommonObject $sql .= ")"; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->db->rollback(); $this->error = $this->db->lasterror(); return -1; @@ -1969,16 +1962,14 @@ class Societe extends CommonObject // Parameter cleaning $note = trim($note); - if (!$note) - { + if (!$note) { $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NoteReason")); return -2; } dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id); - if ($this->id) - { + if ($this->id) { $this->db->begin(); $now = dol_now(); @@ -1988,8 +1979,7 @@ class Societe extends CommonObject $sql .= " SET remise_supplier = '".$this->db->escape($remise)."'"; $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->db->rollback(); $this->error = $this->db->error(); return -1; @@ -2004,8 +1994,7 @@ class Societe extends CommonObject $sql .= ")"; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->db->rollback(); $this->error = $this->db->lasterror(); return -1; @@ -2037,24 +2026,20 @@ class Societe extends CommonObject $desc = trim($desc); // Check parameters - if (!$remise > 0) - { + if (!$remise > 0) { $this->error = $langs->trans("ErrorWrongValueForParameter", "1"); return -1; } - if (!$desc) - { + if (!$desc) { $this->error = $langs->trans("ErrorWrongValueForParameter", "3"); return -2; } - if ($this->id > 0) - { + if ($this->id > 0) { // Clean vat code $reg = array(); $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $vatrate, $reg)) - { + if (preg_match('/\((.*)\)/', $vatrate, $reg)) { $vat_src_code = $reg[1]; $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. } @@ -2076,14 +2061,15 @@ class Societe extends CommonObject $discount->description = $desc; $result = $discount->create($user); - if ($result > 0) - { + if ($result > 0) { return $result; } else { $this->error = $discount->error; return -3; } - } else return 0; + } else { + return 0; + } } /** @@ -2101,8 +2087,7 @@ class Societe extends CommonObject $discountstatic = new DiscountAbsolute($this->db); $result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type); - if ($result >= 0) - { + if ($result >= 0) { return $result; } else { $this->error = $discountstatic->error; @@ -2127,13 +2112,14 @@ class Societe extends CommonObject $sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.office_phone, u.job, u.email, u.statut as status, u.entity, u.photo"; $sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u"; - if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) - { + if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql .= " WHERE ((ug.fk_user = sc.fk_user"; $sql .= " AND ug.entity = ".$conf->entity.")"; $sql .= " OR u.admin = 1)"; - } else $sql .= " WHERE entity in (0, ".$conf->entity.")"; + } else { + $sql .= " WHERE entity in (0, ".$conf->entity.")"; + } $sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id; if (empty($sortfield) && empty($sortorder)) { @@ -2143,16 +2129,13 @@ class Societe extends CommonObject $sql .= $this->db->order($sortfield, $sortorder); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($resql); - if (empty($mode)) - { + if (empty($mode)) { $reparray[$i]['id'] = $obj->rowid; $reparray[$i]['lastname'] = $obj->lastname; $reparray[$i]['firstname'] = $obj->firstname; @@ -2187,16 +2170,14 @@ class Societe extends CommonObject public function set_price_level($price_level, User $user) { // phpcs:enable - if ($this->id) - { + if ($this->id) { $now = dol_now(); $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET price_level = '".$this->db->escape($price_level)."'"; $sql .= " WHERE rowid = ".$this->id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { dol_print_error($this->db); return -1; } @@ -2205,8 +2186,7 @@ class Societe extends CommonObject $sql .= " (datec, fk_soc, price_level, fk_user_author)"; $sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")"; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { dol_print_error($this->db); return -1; } @@ -2228,50 +2208,42 @@ class Societe extends CommonObject // phpcs:enable $error = 0; - if ($this->id > 0 && $commid > 0) - { + if ($this->id > 0 && $commid > 0) { $this->db->begin(); - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux"; $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); $error++; } } - if (!$error) - { + if (!$error) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux"; $sql .= " (fk_soc, fk_user)"; $sql .= " VALUES (".$this->id.", ".$commid.")"; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { dol_syslog(get_class($this)."::add_commercial Error ".$this->db->lasterror()); $error++; } } - if (!$error) - { + if (!$error) { $this->context = array('commercial_modified'=>$commid); $result = $this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE', $user); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -2298,15 +2270,15 @@ class Societe extends CommonObject $this->context = array('commercial_modified'=>$commid); $result = $this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } - if ($this->id > 0 && $commid > 0) - { + if ($this->id > 0 && $commid > 0) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_commerciaux "; $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { dol_syslog(get_class($this)."::del_commercial Erreur"); } } @@ -2327,17 +2299,22 @@ class Societe extends CommonObject { global $conf, $langs, $hookmanager; - if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + if (!empty($conf->dol_no_mouse_hover)) { + $notooltip = 1; // Force disable tooltips + } $name = $this->name ? $this->name : $this->nom; if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) { - if (empty($option) && $this->client > 0) $option = 'customer'; - if (empty($option) && $this->fournisseur > 0) $option = 'supplier'; + if (empty($option) && $this->client > 0) { + $option = 'customer'; + } + if (empty($option) && $this->fournisseur > 0) { + $option = 'supplier'; + } } - if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) - { + if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto))) { $code = ''; if (($this->client) && (!empty($this->code_client)) && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1 || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2)) { $code = $this->code_client.' - '; @@ -2356,18 +2333,18 @@ class Societe extends CommonObject } } - if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')'; + if (!empty($this->name_alias)) { + $name .= ' ('.$this->name_alias.')'; + } $result = ''; $label = ''; $linkstart = ''; $linkend = ''; - if (!empty($this->logo) && class_exists('Form')) - { + if (!empty($this->logo) && class_exists('Form')) { $label .= '
'; $label .= Form::showphoto('societe', $this, 0, 40, 0, '', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. $label .= '
'; - } elseif (!empty($this->logo_squarred) && class_exists('Form')) - { + } elseif (!empty($this->logo_squarred) && class_exists('Form')) { /*$label.= '
'; $label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. $label.= '
';*/ @@ -2375,43 +2352,34 @@ class Societe extends CommonObject $label .= '
'; - if ($option == 'customer' || $option == 'compta' || $option == 'category') - { + if ($option == 'customer' || $option == 'compta' || $option == 'category') { $label .= img_picto('', $this->picto).' '.$langs->trans("Customer").''; $linkstart = ''.$langs->trans("Prospect").''; $linkstart = ''.$langs->trans("Supplier").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = ''.$langs->trans("ThirdParty").''; $linkstart = 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowCompany"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose .= ' class="classfortooltip refurl"'; - /* + /* $hookmanager->initHooks(array('thirdpartydao')); $parameters=array('id'=>$this->id); $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks @@ -2478,15 +2466,18 @@ class Societe extends CommonObject $linkend = ''; global $user; - if (!$user->rights->societe->client->voir && $user->socid > 0 && $this->id != $user->socid) - { + if (!$user->rights->societe->client->voir && $user->socid > 0 && $this->id != $user->socid) { $linkstart = ''; $linkend = ''; } $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name); + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name); + } $result .= $linkend; global $action; @@ -2501,8 +2492,11 @@ class Societe extends CommonObject 'save_lastsearch_value'=> $save_lastsearch_value ); $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) $result = $hookmanager->resPrint; - else $result .= $hookmanager->resPrint; + if ($reshook > 0) { + $result = $hookmanager->resPrint; + } else { + $result .= $hookmanager->resPrint; + } return $result; } @@ -2533,10 +2527,11 @@ class Societe extends CommonObject $langs->load('companies'); $statusType = 'status4'; - if ($status == 0) $statusType = 'status6'; + if ($status == 0) { + $statusType = 'status6'; + } - if (empty($this->labelStatus) || empty($this->labelStatusShort)) - { + if (empty($this->labelStatus) || empty($this->labelStatusShort)) { $this->labelStatus[0] = $langs->trans("ActivityCeased"); $this->labelStatus[1] = $langs->trans("InActivity"); $this->labelStatusShort[0] = $langs->trans("ActivityCeased"); @@ -2559,9 +2554,10 @@ class Societe extends CommonObject global $langs; $contact_emails = $this->contact_property_array('email', 1); - if ($this->email && $addthirdparty) - { - if (empty($this->name)) $this->name = $this->nom; + if ($this->email && $addthirdparty) { + if (empty($this->name)) { + $this->name = $this->nom; + } $contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->email.">"; } //var_dump($contact_emails) @@ -2581,9 +2577,10 @@ class Societe extends CommonObject $contact_phone = $this->contact_property_array('mobile'); - if (!empty($this->phone)) // If a phone of thirdparty is defined, we add it ot mobile of contacts - { - if (empty($this->name)) $this->name = $this->nom; + if (!empty($this->phone)) { // If a phone of thirdparty is defined, we add it ot mobile of contacts + if (empty($this->name)) { + $this->name = $this->nom; + } // TODO: Tester si tel non deja present dans tableau contact $contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->phone.">"; } @@ -2612,36 +2609,36 @@ class Societe extends CommonObject $sql .= " ORDER BY lastname, firstname"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $nump = $this->db->num_rows($resql); - if ($nump) - { + if ($nump) { $sepa = "("; $sepb = ")"; - if ($mode == 'email') - { + if ($mode == 'email') { //$sepa="<"; $sepb=">"; $sepa = "<"; $sepb = ">"; } $i = 0; - while ($i < $nump) - { + while ($i < $nump) { $obj = $this->db->fetch_object($resql); - if ($mode == 'email') $property = $obj->email; - elseif ($mode == 'mobile') $property = $obj->phone_mobile; - else $property = $obj->$mode; + if ($mode == 'email') { + $property = $obj->email; + } elseif ($mode == 'mobile') { + $property = $obj->phone_mobile; + } else { + $property = $obj->$mode; + } // Show all contact. If hidedisabled is 1, showonly contacts with status = 1 - if ($obj->status == 1 || empty($hidedisabled)) - { - if (empty($property)) - { - if ($mode == 'email') $property = $langs->transnoentitiesnoconv("NoEMail"); - elseif ($mode == 'mobile') $property = $langs->transnoentitiesnoconv("NoMobilePhone"); + if ($obj->status == 1 || empty($hidedisabled)) { + if (empty($property)) { + if ($mode == 'email') { + $property = $langs->transnoentitiesnoconv("NoEMail"); + } elseif ($mode == 'mobile') { + $property = $langs->transnoentitiesnoconv("NoMobilePhone"); + } } - if (!empty($obj->poste)) - { + if (!empty($obj->poste)) { $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ? " - ".$obj->poste : "").(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : ''); } else { $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : ''); @@ -2670,14 +2667,11 @@ class Societe extends CommonObject $sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $nump = $this->db->num_rows($resql); - if ($nump) - { + if ($nump) { $i = 0; - while ($i < $nump) - { + while ($i < $nump) { $obj = $this->db->fetch_object($resql); $contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname, $obj->lastname); $i++; @@ -2703,14 +2697,11 @@ class Societe extends CommonObject $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $nump = $this->db->num_rows($resql); - if ($nump) - { + if ($nump) { $i = 0; - while ($i < $nump) - { + while ($i < $nump) { $obj = $this->db->fetch_object($resql); $contact = new Contact($this->db); $contact->fetch($obj->rowid); @@ -2737,23 +2728,26 @@ class Societe extends CommonObject // phpcs:enable $contact_property = ''; - if (empty($rowid)) return ''; + if (empty($rowid)) { + return ''; + } $sql = "SELECT rowid, email, phone_mobile, lastname, firstname"; $sql .= " FROM ".MAIN_DB_PREFIX."socpeople"; $sql .= " WHERE rowid = ".((int) $rowid); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $nump = $this->db->num_rows($resql); - if ($nump) - { + if ($nump) { $obj = $this->db->fetch_object($resql); - if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">"; - elseif ($mode == 'mobile') $contact_property = $obj->phone_mobile; + if ($mode == 'email') { + $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">"; + } elseif ($mode == 'mobile') { + $contact_property = $obj->phone_mobile; + } } return $contact_property; } else { @@ -2841,15 +2835,15 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); @@ -2873,15 +2867,15 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); @@ -2902,23 +2896,29 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module); - if ($mod->code_modifiable_null && !$this->code_client) return 1; - if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1; - if ($mod->code_modifiable) return 1; // A mettre en dernier + if ($mod->code_modifiable_null && !$this->code_client) { + return 1; + } + if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) { + return 1; + } + if ($mod->code_modifiable) { + return 1; // A mettre en dernier + } return 0; } else { return 0; @@ -2936,23 +2936,29 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module); - if ($mod->code_modifiable_null && !$this->code_fournisseur) return 1; - if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1; - if ($mod->code_modifiable) return 1; // A mettre en dernier + if ($mod->code_modifiable_null && !$this->code_fournisseur) { + return 1; + } + if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) { + return 1; + } + if ($mod->code_modifiable) { + return 1; // A mettre en dernier + } return 0; } else { return 0; @@ -2976,25 +2982,25 @@ class Societe extends CommonObject { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); - dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module); - $result = $mod->verif($this->db, $this->code_client, $this, 0); - if ($result) { // If error - $this->error = $mod->error; - $this->errors = $mod->errors; - } + dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module); + $result = $mod->verif($this->db, $this->code_client, $this, 0); + if ($result) { // If error + $this->error = $mod->error; + $this->errors = $mod->errors; + } return $result; } else { return 0; @@ -3010,20 +3016,22 @@ class Societe extends CommonObject * -2 ErrorCustomerCodeRequired * -3 ErrorCustomerCodeAlreadyUsed * -4 ErrorPrefixRequired + * -5 NotConfigured - Setup empty so any value may be ok or not + * -6 Other (see this->error) */ public function check_codefournisseur() { // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON)) { $module = $conf->global->SOCIETE_CODECLIENT_ADDON; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$module.'.php'); - if ($res) break; + if ($res) { + break; + } } $mod = new $module(); @@ -3054,26 +3062,28 @@ class Societe extends CommonObject // phpcs:enable global $conf; - if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) - { + if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON)) { $res = false; $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']); - foreach ($dirsociete as $dirroot) - { + foreach ($dirsociete as $dirroot) { $res = dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php'); - if ($res) break; + if ($res) { + break; + } } - if ($res) - { + if ($res) { $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON; $mod = new $classname; // Set code count in $mod->code $result = $mod->get_code($this->db, $this, $type); - if ($type == 'customer') $this->code_compta = $mod->code; - elseif ($type == 'supplier') $this->code_compta_fournisseur = $mod->code; + if ($type == 'customer') { + $this->code_compta = $mod->code; + } elseif ($type == 'supplier') { + $this->code_compta_fournisseur = $mod->code; + } return $result; } else { @@ -3081,8 +3091,11 @@ class Societe extends CommonObject return -1; } } else { - if ($type == 'customer') $this->code_compta = ''; - elseif ($type == 'supplier') $this->code_compta_fournisseur = ''; + if ($type == 'customer') { + $this->code_compta = ''; + } elseif ($type == 'supplier') { + $this->code_compta_fournisseur = ''; + } return 0; } @@ -3098,21 +3111,21 @@ class Societe extends CommonObject public function set_parent($id) { // phpcs:enable - if ($this->id) - { + if ($this->id) { $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET parent = ".($id > 0 ? $id : "null"); $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this).'::set_parent', LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->parent = $id; return 1; } else { return -1; } - } else return -1; + } else { + return -1; + } } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3127,8 +3140,7 @@ class Societe extends CommonObject // phpcs:enable global $conf; - switch ($idprof) - { + switch ($idprof) { case 1: $ret = (empty($conf->global->SOCIETE_IDPROF1_UNIQUE) ? false : true); break; @@ -3168,8 +3180,7 @@ class Societe extends CommonObject // phpcs:enable $field = $idprof; - switch ($idprof) // For backward compatibility - { + switch ($idprof) { // For backward compatibility case '1': case 'idprof1': $field = "siren"; @@ -3192,14 +3203,15 @@ class Societe extends CommonObject case '6': $field = "idprof6"; break; - } + } //Verify duplicate entries $sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$this->db->escape($value)."' AND entity IN (".getEntity('societe').")"; - if ($socid) $sql .= " AND rowid <> ".$socid; + if ($socid) { + $sql .= " AND rowid <> ".$socid; + } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); $count = $obj->idprof; } else { @@ -3208,8 +3220,11 @@ class Societe extends CommonObject } $this->db->free($resql); - if ($count > 0) return true; - else return false; + if ($count > 0) { + return true; + } else { + return false; + } } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3228,111 +3243,144 @@ class Societe extends CommonObject $ok = 1; - if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1; + if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) { + return 1; + } // Check SIREN if country FR - if ($idprof == 1 && $soc->country_code == 'FR') - { + if ($idprof == 1 && $soc->country_code == 'FR') { $chaine = trim($this->idprof1); $chaine = preg_replace('/(\s)/', '', $chaine); - if (!is_numeric($chaine)) return -1; - if (dol_strlen($chaine) != 9) return -1; + if (!is_numeric($chaine)) { + return -1; + } + if (dol_strlen($chaine) != 9) { + return -1; + } // on prend chaque chiffre un par un // si son index (position dans la chaîne en commence à 0 au premier caractère) est impair // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9 // on ajoute cette valeur à la somme totale $sum = 0; - for ($index = 0; $index < 9; $index++) - { + for ($index = 0; $index < 9; $index++) { $number = (int) $chaine[$index]; - if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; } + if (($index % 2) != 0) { + if (($number *= 2) > 9) { + $number -= 9; + } + } $sum += $number; } // le numéro est valide si la somme des chiffres est multiple de 10 - if (($sum % 10) != 0) return -1; + if (($sum % 10) != 0) { + return -1; + } } // Verifie SIRET si pays FR - if ($idprof == 2 && $soc->country_code == 'FR') - { + if ($idprof == 2 && $soc->country_code == 'FR') { $chaine = trim($this->idprof2); $chaine = preg_replace('/(\s)/', '', $chaine); - if (!is_numeric($chaine)) return -1; - if (dol_strlen($chaine) != 14) return -1; + if (!is_numeric($chaine)) { + return -1; + } + if (dol_strlen($chaine) != 14) { + return -1; + } // on prend chaque chiffre un par un // si son index (position dans la chaîne en commence à 0 au premier caractère) est pair // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9 // on ajoute cette valeur à la somme totale $sum = 0; - for ($index = 0; $index < 14; $index++) - { + for ($index = 0; $index < 14; $index++) { $number = (int) $chaine[$index]; - if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; } + if (($index % 2) == 0) { + if (($number *= 2) > 9) { + $number -= 9; + } + } $sum += $number; } // le numéro est valide si la somme des chiffres est multiple de 10 - if (($sum % 10) != 0) return -1; + if (($sum % 10) != 0) { + return -1; + } } //Verify CIF/NIF/NIE if pays ES //Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad - if ($idprof == 1 && $soc->country_code == 'ES') - { + if ($idprof == 1 && $soc->country_code == 'ES') { $string = trim($this->idprof1); $string = preg_replace('/(\s)/', '', $string); $string = strtoupper($string); //Check format - if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) - return 0; + if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) { + return 0; + } $num = array(); - for ($i = 0; $i < 9; $i++) - { + for ($i = 0; $i < 9; $i++) { $num[$i] = substr($string, $i, 1); } //Check NIF - if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) - if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) + if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) { + if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1)) { return 1; - else return -1; + } else { + return -1; + } + } //algorithm checking type code CIF $sum = $num[2] + $num[4] + $num[6]; - for ($i = 1; $i < 8; $i += 2) - $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1)); + for ($i = 1; $i < 8; $i += 2) { + $sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1)); + } $n = 10 - substr($sum, strlen($sum) - 1, 1); //Chek special NIF - if (preg_match('/^[KLM]{1}/', $string)) - if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) + if (preg_match('/^[KLM]{1}/', $string)) { + if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1)) { return 1; - else return -1; + } else { + return -1; + } + } //Check CIF - if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) - if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) + if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) { + if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1)) { return 2; - else return -2; + } else { + return -2; + } + } //Check NIE T - if (preg_match('/^[T]{1}/', $string)) - if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string)) + if (preg_match('/^[T]{1}/', $string)) { + if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string)) { return 3; - else return -3; + } else { + return -3; + } + } //Check NIE XYZ - if (preg_match('/^[XYZ]{1}/', $string)) - if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1)) + if (preg_match('/^[XYZ]{1}/', $string)) { + if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1)) { return 3; - else return -3; + } else { + return -3; + } + } //Can not be verified return -4; @@ -3340,8 +3388,7 @@ class Societe extends CommonObject //Verify NIF if country is PT //Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad - if ($idprof == 1 && $soc->country_code == 'PT') - { + if ($idprof == 1 && $soc->country_code == 'PT') { $string = trim($this->idprof1); $string = preg_replace('/(\s)/', '', $string); @@ -3420,8 +3467,7 @@ class Societe extends CommonObject // phpcs:enable $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = '.$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); $count = $obj->numproj; } else { @@ -3447,10 +3493,8 @@ class Societe extends CommonObject $sql .= " WHERE s.rowid = ".$id; $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { + if ($result) { + if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; @@ -3493,11 +3537,13 @@ class Societe extends CommonObject $isacompany = 1; } elseif (!empty($this->idprof1) || !empty($this->idprof2) || !empty($this->idprof3) || !empty($this->idprof4) || !empty($this->idprof5) || !empty($this->idprof6)) { $isacompany = 1; - } elseif (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN') - { + } elseif (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN') { // TODO Add a field is_a_company into dictionary - if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany = 0; - else $isacompany = 1; + if (preg_match('/^TE_PRIVATE/', $this->typent_code)) { + $isacompany = 0; + } else { + $isacompany = 1; + } } return $isacompany; @@ -3529,10 +3575,8 @@ class Societe extends CommonObject $sql .= " WHERE type = ".Categorie::TYPE_SUPPLIER; $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $this->SupplierCategories[$obj->rowid] = $obj->label; } return 0; @@ -3551,12 +3595,13 @@ class Societe extends CommonObject public function AddFournisseurInCategory($categorie_id) { // phpcs:enable - if ($categorie_id > 0 && $this->id > 0) - { + if ($categorie_id > 0 && $this->id > 0) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) "; $sql .= " VALUES (".$categorie_id.", ".$this->id.")"; - if ($resql = $this->db->query($sql)) return 0; + if ($resql = $this->db->query($sql)) { + return 0; + } } else { return 0; } @@ -3582,7 +3627,9 @@ class Societe extends CommonObject dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); $name = $socname ? $socname : $member->societe; - if (empty($name)) $name = $member->getFullName($langs); + if (empty($name)) { + $name = $member->getFullName($langs); + } $alias = $socalias ? $socalias : ''; @@ -3608,15 +3655,13 @@ class Societe extends CommonObject // Cree et positionne $this->id $result = $this->create($user); - if ($result >= 0) - { + if ($result >= 0) { $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; $sql .= " SET fk_soc=".$this->id; $sql .= " WHERE rowid=".$member->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->db->commit(); return $this->id; } else { @@ -3658,12 +3703,10 @@ class Societe extends CommonObject // We define country_id, country_code and country $country_id = $country_code = $country_label = ''; - if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) - { + if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) { $tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY); $country_id = $tmp[0]; - if (!empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label" - { + if (!empty($tmp[1])) { // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label" $country_code = $tmp[1]; $country_label = $tmp[2]; } else // For backward compatibility @@ -3677,17 +3720,17 @@ class Societe extends CommonObject $this->country_id = $country_id; $this->country_code = $country_code; $this->country = $country_label; - if (is_object($langs)) $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label; + if (is_object($langs)) { + $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label; + } //TODO This could be replicated for region but function `getRegion` didn't exist, so I didn't added it. // We define state_id, state_code and state $state_id = 0; $state_code = $state_label = ''; - if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) - { + if (!empty($conf->global->MAIN_INFO_SOCIETE_STATE)) { $tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_STATE); $state_id = $tmp[0]; - if (!empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" - { + if (!empty($tmp[1])) { // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" $state_code = $tmp[1]; $state_label = $tmp[2]; } else // For backward compatibility @@ -3701,7 +3744,9 @@ class Societe extends CommonObject $this->state_id = $state_id; $this->state_code = $state_code; $this->state = $state_label; - if (is_object($langs)) $this->state = ($langs->trans('State'.$state_code) != 'State'.$state_code) ? $langs->trans('State'.$state_code) : $state_label; + if (is_object($langs)) { + $this->state = ($langs->trans('State'.$state_code) != 'State'.$state_code) ? $langs->trans('State'.$state_code) : $state_label; + } $this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ? '' : $conf->global->MAIN_INFO_SOCIETE_TEL; $this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ? '' : $conf->global->MAIN_INFO_SOCIETE_FAX; @@ -3715,12 +3760,24 @@ class Societe extends CommonObject $this->youtube_url = empty($conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_YOUTUBE_URL; $this->github_url = empty($conf->global->MAIN_INFO_SOCIETE_GITHUB_URL) ? '' : $conf->global->MAIN_INFO_SOCIETE_GITHUB_URL; $this->socialnetworks = array(); - if (!empty($this->facebook_url)) $this->socialnetworks['facebook'] = $this->facebook_url; - if (!empty($this->twitter_url)) $this->socialnetworks['twitter'] = $this->twitter_url; - if (!empty($this->linkedin_url)) $this->socialnetworks['linkedin'] = $this->linkedin_url; - if (!empty($this->instagram_url)) $this->socialnetworks['instagram'] = $this->instagram_url; - if (!empty($this->youtube_url)) $this->socialnetworks['youtube'] = $this->youtube_url; - if (!empty($this->github_url)) $this->socialnetworks['github'] = $this->github_url; + if (!empty($this->facebook_url)) { + $this->socialnetworks['facebook'] = $this->facebook_url; + } + if (!empty($this->twitter_url)) { + $this->socialnetworks['twitter'] = $this->twitter_url; + } + if (!empty($this->linkedin_url)) { + $this->socialnetworks['linkedin'] = $this->linkedin_url; + } + if (!empty($this->instagram_url)) { + $this->socialnetworks['instagram'] = $this->instagram_url; + } + if (!empty($this->youtube_url)) { + $this->socialnetworks['youtube'] = $this->youtube_url; + } + if (!empty($this->github_url)) { + $this->socialnetworks['github'] = $this->github_url; + } // Id prof generiques $this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ? '' : $conf->global->MAIN_INFO_SIREN; @@ -3820,15 +3877,20 @@ class Societe extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'"; $sql .= " AND t.active = 1"; - if (empty($localTaxNum)) $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')"; - elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'"; - elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'"; + if (empty($localTaxNum)) { + $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')"; + } elseif ($localTaxNum == 1) { + $sql .= " AND t.localtax1_type <> '0'"; + } elseif ($localTaxNum == 2) { + $sql .= " AND t.localtax2_type <> '0'"; + } $resql = $this->db->query($sql); - if ($resql) - { - return ($this->db->num_rows($resql) > 0); - } else return false; + if ($resql) { + return ($this->db->num_rows($resql) > 0); + } else { + return false; + } } /** @@ -3845,10 +3907,11 @@ class Societe extends CommonObject dol_syslog("useNPR", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { return ($this->db->num_rows($resql) > 0); - } else return false; + } else { + return false; + } } /** @@ -3866,10 +3929,9 @@ class Societe extends CommonObject dol_syslog("useRevenueStamp", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - return (($obj->nb > 0) ?true:false); + return (($obj->nb > 0) ?true:false); } else { $this->error = $this->db->lasterror(); return false; @@ -3900,8 +3962,7 @@ class Societe extends CommonObject $lib = $langs->trans("ProspectLevel".$fk_prospectlevel); // If lib not found in language file, we get label from cache/databse - if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) - { + if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) { $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label'); } return $lib; @@ -3955,30 +4016,45 @@ class Societe extends CommonObject $langs->load('customers'); if ($mode == 2) { - if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); - elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); - elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); - elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); - elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); - else { + if ($status == '-1' || $status == 'ST_NO') { + return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); + } elseif ($status == '0' || $status == 'ST_NEVER') { + return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); + } elseif ($status == '1' || $status == 'ST_TODO') { + return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); + } elseif ($status == '2' || $status == 'ST_PEND') { + return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); + } elseif ($status == '3' || $status == 'ST_DONE') { + return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); + } else { return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label); } } elseif ($mode == 3) { - if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto); - elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto); - elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto); - elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto); - elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto); - else { + if ($status == '-1' || $status == 'ST_NO') { + return img_action($langs->trans("StatusProspect-1"), -1, $picto); + } elseif ($status == '0' || $status == 'ST_NEVER') { + return img_action($langs->trans("StatusProspect0"), 0, $picto); + } elseif ($status == '1' || $status == 'ST_TODO') { + return img_action($langs->trans("StatusProspect1"), 1, $picto); + } elseif ($status == '2' || $status == 'ST_PEND') { + return img_action($langs->trans("StatusProspect2"), 2, $picto); + } elseif ($status == '3' || $status == 'ST_DONE') { + return img_action($langs->trans("StatusProspect3"), 3, $picto); + } else { return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto); } } elseif ($mode == 4) { - if ($status == '-1' || $status == 'ST_NO') return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); - elseif ($status == '0' || $status == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); - elseif ($status == '1' || $status == 'ST_TODO') return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); - elseif ($status == '2' || $status == 'ST_PEND') return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); - elseif ($status == '3' || $status == 'ST_DONE') return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); - else { + if ($status == '-1' || $status == 'ST_NO') { + return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1"); + } elseif ($status == '0' || $status == 'ST_NEVER') { + return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0"); + } elseif ($status == '1' || $status == 'ST_TODO') { + return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1"); + } elseif ($status == '2' || $status == 'ST_PEND') { + return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2"); + } elseif ($status == '3' || $status == 'ST_DONE') { + return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3"); + } else { return img_action(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$status) != "StatusProspect".$status) ? $langs->trans("StatusProspect".$status) : $label); } } @@ -4009,7 +4085,9 @@ class Societe extends CommonObject public function getOutstandingProposals($mode = 'customer') { $table = 'propal'; - if ($mode == 'supplier') $table = 'supplier_proposal'; + if ($mode == 'supplier') { + $table = 'supplier_proposal'; + } $sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; $sql .= " WHERE fk_soc = ".$this->id; @@ -4021,21 +4099,22 @@ class Societe extends CommonObject dol_syslog("getOutstandingProposals", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; while ($obj = $this->db->fetch_object($resql)) { $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; - if ($obj->status != 0) // Not a draft - { + if ($obj->status != 0) { + // Not a draft $outstandingOpened += $obj->total_ttc; } } return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' - } else return array(); + } else { + return array(); + } } /** @@ -4047,7 +4126,9 @@ class Societe extends CommonObject public function getOutstandingOrders($mode = 'customer') { $table = 'commande'; - if ($mode == 'supplier') $table = 'commande_fournisseur'; + if ($mode == 'supplier') { + $table = 'commande_fournisseur'; + } $sql = "SELECT rowid, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; $sql .= " WHERE fk_soc = ".$this->id; @@ -4059,21 +4140,22 @@ class Societe extends CommonObject dol_syslog("getOutstandingOrders", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; while ($obj = $this->db->fetch_object($resql)) { $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; - if ($obj->status != 0) // Not a draft - { + if ($obj->status != 0) { + // Not a draft $outstandingOpened += $obj->total_ttc; } } return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' - } else return array(); + } else { + return array(); + } } /** @@ -4086,7 +4168,9 @@ class Societe extends CommonObject public function getOutstandingBills($mode = 'customer', $late = 0) { $table = 'facture'; - if ($mode == 'supplier') $table = 'facture_fourn'; + if ($mode == 'supplier') { + $table = 'facture_fourn'; + } /* Accurate value of remain to pay is to sum remaintopay for each invoice $paiement = $invoice->getSommePaiement(); @@ -4095,8 +4179,11 @@ class Societe extends CommonObject $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); */ - if ($mode == 'supplier') $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; - else $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + if ($mode == 'supplier') { + $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + } else { + $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + } $sql .= " WHERE fk_soc = ".$this->id; if (!empty($late)) { $sql .= " AND date_lim_reglement < '".$this->db->idate(dol_now())."'"; @@ -4109,13 +4196,11 @@ class Societe extends CommonObject dol_syslog("getOutstandingBills", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; - if ($mode == 'supplier') - { + if ($mode == 'supplier') { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; $tmpobject = new FactureFournisseur($this->db); } else { @@ -4127,17 +4212,15 @@ class Societe extends CommonObject if ($obj->status != $tmpobject::STATUS_DRAFT // Not a draft && !($obj->status == $tmpobject::STATUS_ABANDONED && $obj->close_code == 'replaced') // Not a replaced invoice - ) - { + ) { $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; } if ($obj->paye == 0 && $obj->status != $tmpobject::STATUS_DRAFT // Not a draft && $obj->status != $tmpobject::STATUS_ABANDONED // Not abandonned - && $obj->status != $tmpobject::STATUS_CLOSED) // Not classified as paid - //$sql .= " AND (status <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason - { + && $obj->status != $tmpobject::STATUS_CLOSED) { // Not classified as paid + //$sql .= " AND (status <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason $paiement = $tmpobject->getSommePaiement(); $creditnotes = $tmpobject->getSumCreditNotesUsed(); $deposits = $tmpobject->getSumDepositsUsed(); @@ -4147,8 +4230,7 @@ class Societe extends CommonObject //if credit note is converted but not used // TODO Do this also for customer ? - if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed()) - { + if ($mode == 'supplier' && $obj->type == FactureFournisseur::TYPE_CREDIT_NOTE && $tmpobject->isCreditNoteUsed()) { $outstandingOpened -= $tmpobject->getSumFromThisCreditNotesNotUsed(); } } @@ -4181,10 +4263,15 @@ class Societe extends CommonObject global $langs; $langs->load('companies'); - if ($status == 0) return $langs->trans("NorProspectNorCustomer"); - elseif ($status == 1) return $langs->trans("Customer"); - elseif ($status == 2) return $langs->trans("Prospect"); - elseif ($status == 3) return $langs->trans("ProspectCustomer"); + if ($status == 0) { + return $langs->trans("NorProspectNorCustomer"); + } elseif ($status == 1) { + return $langs->trans("Customer"); + } elseif ($status == 2) { + return $langs->trans("Prospect"); + } elseif ($status == 3) { + return $langs->trans("ProspectCustomer"); + } } @@ -4203,21 +4290,20 @@ class Societe extends CommonObject { global $conf, $user, $langs; - if (!empty($moreparams) && !empty($moreparams['use_companybankid'])) - { + if (!empty($moreparams) && !empty($moreparams['use_companybankid'])) { $modelpath = "core/modules/bank/doc/"; include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; $companybankaccount = new CompanyBankAccount($this->db); $result = $companybankaccount->fetch($moreparams['use_companybankid']); - if (!$result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors); + if (!$result) { + dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors); + } $result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } else { // Positionne le modele sur le nom du modele a utiliser - if (!dol_strlen($modele)) - { - if (!empty($conf->global->COMPANY_ADDON_PDF)) - { + if (!dol_strlen($modele)) { + if (!empty($conf->global->COMPANY_ADDON_PDF)) { $modele = $conf->global->COMPANY_ADDON_PDF; } else { print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined"); @@ -4293,11 +4379,9 @@ class Societe extends CommonObject } } foreach ($to_add as $add) { - if ($c->fetch($add) > 0) - { + if ($c->fetch($add) > 0) { $result = $c->add_type($this, $type_categ); - if ($result < 0) - { + if ($result < 0) { $error++; $this->error = $c->error; $this->errors = $c->errors; @@ -4325,7 +4409,6 @@ class Societe extends CommonObject $salesrep = array($salesrep); } - $to_del = array(); // Nothing to delete $to_add = $salesrep; if ($onlyAdd === false) { @@ -4347,8 +4430,7 @@ class Societe extends CommonObject } foreach ($to_add as $add) { $result = $this->add_commercial($user, $add); - if ($result < 0) - { + if ($result < 0) { $error++; break; } @@ -4365,22 +4447,22 @@ class Societe extends CommonObject */ public function setThirdpartyType($typent_id) { - if ($this->id) - { + if ($this->id) { $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql .= " SET fk_typent = ".($typent_id > 0 ? $typent_id : "null"); $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this).'::setThirdpartyType', LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->typent_id = $typent_id; - $this->typent_code = dol_getIdFromCode($db, $this->$typent_id, 'c_typent', 'id', 'code'); + $this->typent_code = dol_getIdFromCode($this->db, $this->$typent_id, 'c_typent', 'id', 'code'); return 1; } else { return -1; } - } else return -1; + } else { + return -1; + } } /** @@ -4394,8 +4476,7 @@ class Societe extends CommonObject */ public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) { - if ($origin_id == $dest_id) - { + if ($origin_id == $dest_id) { dol_syslog('Error: Try to merge a thirdparty into itself'); return false; } diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index e6991388ad0..1c807b7b2b1 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -35,7 +35,7 @@ --oddevencolor: #202020; --colorboxstatsborder: #e0e0e0; --dolgraphbg: rgba(255,255,255,0); - --fieldrequiredcolor: #804000; + --fieldrequiredcolor: #700040; --colortextbacktab: #; --colorboxiconbg: #eee; --refidnocolor:#444; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index eb92bd51eb9..98e70cf66b7 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2418,6 +2418,7 @@ class User extends CommonObject } $result = ''; $label = ''; + $companylink = ''; if (!empty($this->photo)) { $label .= '
'; diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 5a8e6fb241c..7397b8ca2a6 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -288,7 +288,7 @@ $server->register( */ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getInvoice login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -363,7 +363,7 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '') 'note_private' => $invoice->note_private ? $invoice->note_private : '', 'note_public' => $invoice->note_public ? $invoice->note_public : '', 'status' => $invoice->statut, - 'project_id' => $invoic->fk_project, + 'project_id' => $invoice->fk_project, 'close_code' => $invoice->close_code ? $invoice->close_code : '', 'close_note' => $invoice->close_note ? $invoice->close_note : '', 'payment_mode_id' => $invoice->mode_reglement_id ? $invoice->mode_reglement_id : '', @@ -399,7 +399,7 @@ function getInvoice($authentication, $id = '', $ref = '', $ref_ext = '') */ function getInvoicesForThirdParty($authentication, $idthirdparty) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getInvoicesForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty); @@ -482,7 +482,7 @@ function getInvoicesForThirdParty($authentication, $idthirdparty) 'fk_user_valid' => $invoice->user_valid ? $invoice->user_valid : '', 'date' => $invoice->date ?dol_print_date($invoice->date, 'dayrfc') : '', 'date_due' => $invoice->date_lim_reglement ?dol_print_date($invoice->date_lim_reglement, 'dayrfc') : '', - 'date_creation' => $invoice->date_creation ?dol_print_date($invoice->date_creation, 'dayhourrfc') : '', + 'date_creation' => $invoice->date_creation ?dol_print_date($invoice->date_creation, 'dayhourrfc') : '', 'date_validation' => $invoice->date_validation ?dol_print_date($invoice->date_creation, 'dayhourrfc') : '', 'date_modification' => $invoice->datem ?dol_print_date($invoice->datem, 'dayhourrfc') : '', 'type' => $invoice->type, @@ -492,7 +492,7 @@ function getInvoicesForThirdParty($authentication, $idthirdparty) 'note_private' => $invoice->note_private ? $invoice->note_private : '', 'note_public' => $invoice->note_public ? $invoice->note_public : '', 'status'=> $invoice->statut, - 'project_id' => $invoic->fk_project, + 'project_id' => $invoice->fk_project, 'close_code' => $invoice->close_code ? $invoice->close_code : '', 'close_note' => $invoice->close_note ? $invoice->close_note : '', 'payment_mode_id' => $invoice->mode_reglement_id ? $invoice->mode_reglement_id : '', @@ -528,17 +528,16 @@ function getInvoicesForThirdParty($authentication, $idthirdparty) * Create an invoice * * @param array $authentication Array of authentication information - * @param Facture $invoice Invoice + * @param array $invoice Invoice * @return array Array result */ function createInvoice($authentication, $invoice) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); - dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice->id. - ", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext); + dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice['id'].", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']); if ($authentication['entity']) $conf->entity = $authentication['entity']; @@ -580,22 +579,22 @@ function createInvoice($authentication, $invoice) if (isset($invoice['lines']['line'][0])) $arrayoflines = $invoice['lines']['line']; else $arrayoflines = $invoice['lines']; - foreach ($arrayoflines as $key => $line) + foreach ($arrayoflines as $line) { // $key can be 'line' or '0','1',... $newline = new FactureLigne($db); $newline->product_type = $line['type']; $newline->desc = $line['desc']; - $newline->fk_product = $line['fk_product']; - $newline->tva_tx = $line['vat_rate']; + $newline->fk_product = $line['product_id']; + $newline->tva_tx = isset($line['vat_rate']) ? $line['vat_rate'] : 0; $newline->qty = $line['qty']; - $newline->subprice = $line['unitprice']; + $newline->subprice = isset($line['unitprice']) ? $line['unitprice'] : null; $newline->total_ht = $line['total_net']; $newline->total_tva = $line['total_vat']; $newline->total_ttc = $line['total']; $newline->date_start = dol_stringtotime($line['date_start']); $newline->date_end = dol_stringtotime($line['date_end']); - $newline->fk_product = $line['product_id']; + $new_invoice->lines[] = $newline; } //var_dump($newobject->date_lim_reglement); exit; @@ -654,10 +653,7 @@ function createInvoiceFromOrder($authentication, $id_order = '', $ref_order = '' { global $db, $conf; - $now = dol_now(); - - dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order. - ", ref=".$ref_order.", ref_ext=".$ref_ext_order); + dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order.", ref=".$ref_order.", ref_ext=".$ref_ext_order); if ($authentication['entity']) $conf->entity = $authentication['entity']; @@ -781,12 +777,11 @@ function updateInvoice($authentication, $invoice) $object->generateDocument($object->model_pdf, $outputlangs); } } - if ($invoice['status'] == Facture::STATUS_CLOSED) - { - $result = $object->set_paid($fuser, $invoice->close_code, $invoice->close_note); + if ($invoice['status'] == Facture::STATUS_CLOSED) { + $result = $object->set_paid($fuser, $invoice['close_code'], $invoice['close_note']); } if ($invoice['status'] == Facture::STATUS_ABANDONED) - $result = $object->set_canceled($fuser, $invoice->close_code, $invoice->close_note); + $result = $object->set_canceled($fuser, $invoice['close_code'], $invoice['close_note']); } } diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 30c105d7192..361b2a08f4a 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -354,7 +354,7 @@ $server->register( */ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getOrder login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -504,7 +504,7 @@ function getOrder($authentication, $id = '', $ref = '', $ref_ext = '') */ function getOrdersForThirdParty($authentication, $idthirdparty) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getOrdersForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty); @@ -707,7 +707,7 @@ function createOrder($authentication, $order) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $order[$key]; @@ -813,7 +813,7 @@ function validOrder($authentication, $id = '', $id_warehouse = 0) { global $db, $conf, $langs; - dol_syslog("Function: validOrder login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + dol_syslog("Function: validOrder login=".$authentication['login']." id=".$id." id_warehouse=".$id_warehouse); // Init and check authentication $objectresp = array(); @@ -830,7 +830,7 @@ function validOrder($authentication, $id = '', $id_warehouse = 0) if ($fuser->rights->commande->lire) { $order = new Commande($db); - $result = $order->fetch($id, $ref, $ref_ext); + $result = $order->fetch($id); $order->fetch_thirdparty(); $db->begin(); @@ -889,8 +889,6 @@ function updateOrder($authentication, $order) { global $db, $conf, $langs; - $now = dol_now(); - dol_syslog("Function: updateOrder login=".$authentication['login']); if ($authentication['entity']) $conf->entity = $authentication['entity']; @@ -950,7 +948,7 @@ function updateOrder($authentication, $order) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; if (isset($order[$key])) diff --git a/htdocs/webservices/server_other.php b/htdocs/webservices/server_other.php index 71ee78d3c4d..61f53f7e275 100644 --- a/htdocs/webservices/server_other.php +++ b/htdocs/webservices/server_other.php @@ -145,7 +145,7 @@ $server->register( */ function getVersions($authentication) { - global $db, $conf, $langs; + global $conf; dol_syslog("Function: getVersions login=".$authentication['login']); @@ -188,7 +188,7 @@ function getVersions($authentication) */ function getDocument($authentication, $modulepart, $file, $refname = '') { - global $db, $conf, $langs, $mysoc; + global $db, $conf; dol_syslog("Function: getDocument login=".$authentication['login'].' - modulepart='.$modulepart.' - file='.$file); @@ -283,10 +283,7 @@ function getDocument($authentication, $modulepart, $file, $refname = '') { if (file_exists($original_file)) { - dol_syslog("Function: getDocument $original_file $filename content-type=$type"); - - $file = $fileparams['fullname']; - $filename = basename($file); + dol_syslog("Function: getDocument $original_file content-type=$type"); $f = fopen($original_file, 'r'); $content_file = fread($f, filesize($original_file)); diff --git a/htdocs/webservices/server_payment.php b/htdocs/webservices/server_payment.php index 8a9b19d76d6..3fd3868a36a 100644 --- a/htdocs/webservices/server_payment.php +++ b/htdocs/webservices/server_payment.php @@ -45,6 +45,7 @@ $langs->load("main"); if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) { $langs->load("admin"); + dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled"); print $langs->trans("WarningModuleNotActive", 'WebServices').'.

'; print $langs->trans("ToActivateModule"); @@ -139,7 +140,7 @@ $server->register( */ function createPayment($authentication, $payment) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); @@ -165,7 +166,7 @@ function createPayment($authentication, $payment) if (!$error) { $soc = new Societe($db); - $res = $soc->fetch($payment['thirdparty_id']); + $soc->fetch($payment['thirdparty_id']); $new_payment = new Paiement($db); $new_payment->amount = doubleval($payment['amount']); diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index bb068167b74..4368386c41e 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -1,6 +1,7 @@ * Copyright (C) 2012 JF FERRY + * Copyright (C) 2020 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +24,9 @@ * \brief File that is entry point to call Dolibarr WebServices */ -if (!defined("NOCSRFCHECK")) define("NOCSRFCHECK", '1'); +if (!defined("NOCSRFCHECK")) { + define("NOCSRFCHECK", '1'); +} require '../master.inc.php'; require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP @@ -42,8 +45,7 @@ dol_syslog("Call Dolibarr webservices interfaces"); $langs->load("main"); // Enable and test if module web services is enabled -if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) -{ +if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) { $langs->load("admin"); dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled"); print $langs->trans("WarningModuleNotActive", 'WebServices').'.

'; @@ -142,19 +144,22 @@ $extrafield_array = null; if (is_array($extrafields) && count($extrafields) > 0) { $extrafield_array = array(); } -if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) -{ - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) - { +if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $type = $extrafields->attributes[$elementtype]['type'][$key]; - if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; } - else {$type = 'xsd:string'; } + if ($type == 'date' || $type == 'datetime') { + $type = 'xsd:dateTime'; + } else { + $type = 'xsd:string'; + } $extrafield_array['options_'.$key] = array('name'=>'options_'.$key, 'type'=>$type); } } -if (is_array($extrafield_array)) $productorservice_fields = array_merge($productorservice_fields, $extrafield_array); +if (is_array($extrafield_array)) { + $productorservice_fields = array_merge($productorservice_fields, $extrafield_array); +} // Define other specific objects $server->wsdl->addComplexType( @@ -236,7 +241,6 @@ $server->wsdl->addComplexType( ); - // 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped // Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model. // http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/ @@ -349,44 +353,49 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = '' $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT)); $langs->setDefaultLang($langcode); - if ($authentication['entity']) $conf->entity = $authentication['entity']; + if ($authentication['entity']) { + $conf->entity = $authentication['entity']; + } // Init and check authentication $objectresp = array(); - $errorcode = ''; $errorlabel = ''; + $errorcode = ''; + $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); // Check parameters - if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) - { + if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) { $error++; $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; } - if (!$error) - { + if (!$error) { $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT)); $langs->setDefaultLang($langcode); $fuser->getrights(); $nbmax = 10; - if ($fuser->rights->produit->lire || $fuser->rights->service->lire) - { + if ($fuser->rights->produit->lire || $fuser->rights->service->lire) { $product = new Product($db); $result = $product->fetch($id, $ref, $ref_ext); - if ($result > 0) - { + if ($result > 0) { $product->load_stock(); $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output); $pdir = get_exdir($product->id, 2, 0, 0, $product, 'product').$product->ref."/"; $dir = $dir.'/'.$pdir; - if (!empty($product->multilangs[$langs->defaultlang]["label"])) $product->label = $product->multilangs[$langs->defaultlang]["label"]; - if (!empty($product->multilangs[$langs->defaultlang]["description"])) $product->description = $product->multilangs[$langs->defaultlang]["description"]; - if (!empty($product->multilangs[$langs->defaultlang]["note"])) $product->note = $product->multilangs[$langs->defaultlang]["note"]; + if (!empty($product->multilangs[$langs->defaultlang]["label"])) { + $product->label = $product->multilangs[$langs->defaultlang]["label"]; + } + if (!empty($product->multilangs[$langs->defaultlang]["description"])) { + $product->description = $product->multilangs[$langs->defaultlang]["description"]; + } + if (!empty($product->multilangs[$langs->defaultlang]["note"])) { + $product->note = $product->multilangs[$langs->defaultlang]["note"]; + } $productorservice_result_fields = array( 'id' => $product->id, @@ -436,10 +445,8 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = '' //Get extrafield values $product->fetch_optionals(); - if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) - { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) - { + if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $productorservice_result_fields = array_merge($productorservice_result_fields, array('options_'.$key => $product->array_options['options_'.$key])); } } @@ -449,20 +456,17 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = '' 'result'=>array('result_code'=>'OK', 'result_label'=>''), 'product'=>$productorservice_result_fields ); - } - else { + } else { $error++; $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; } - } - else { + } else { $error++; $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; } } - if ($error) - { + if ($error) { $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); } //var_dump($objectresp);exit; @@ -479,37 +483,41 @@ function getProductOrService($authentication, $id = '', $ref = '', $ref_ext = '' */ function createProductOrService($authentication, $product) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); dol_syslog("Function: createProductOrService login=".$authentication['login']); - if ($authentication['entity']) $conf->entity = $authentication['entity']; + if ($authentication['entity']) { + $conf->entity = $authentication['entity']; + } // Init and check authentication $objectresp = array(); - $errorcode = ''; $errorlabel = ''; + $errorcode = ''; + $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); // Check parameters if (empty($product['price_base_type'])) { - if (isset($product['price_net']) && $product['price_net'] > 0) $product['price_base_type'] = 'HT'; - if (isset($product['price']) && $product['price'] > 0) $product['price_base_type'] = 'TTC'; + if (isset($product['price_net']) && $product['price_net'] > 0) { + $product['price_base_type'] = 'HT'; + } + if (isset($product['price']) && $product['price'] > 0) { + $product['price_base_type'] = 'TTC'; + } } - if (isset($product['price_net']) && $product['price_net'] > 0 && isset($product['price']) && $product['price'] > 0) - { + if (isset($product['price_net']) && $product['price_net'] > 0 && isset($product['price']) && $product['price'] > 0) { $error++; $errorcode = 'KO'; $errorlabel = "You must choose between price or price_net to provide price."; } - if (!empty($product['barcode']) && empty($product['barcode_type'])) - { + if (!empty($product['barcode']) && empty($product['barcode_type'])) { $error++; $errorcode = 'KO'; $errorlabel = "You must set a barcode type when setting a barcode."; } - if (!$error) - { + if (!$error) { include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $newobject = new Product($db); @@ -528,34 +536,35 @@ function createProductOrService($authentication, $product) $newobject->price_base_type = $product['price_base_type']; $newobject->date_creation = $now; - if (!empty($product['barcode'])) - { + if (!empty($product['barcode'])) { $newobject->barcode = $product['barcode']; $newobject->barcode_type = $product['barcode_type']; } $newobject->stock_reel = isset($product['stock_real']) ? $product['stock_real'] : null; $newobject->pmp = isset($product['pmp']) ? $product['pmp'] : null; - $newobject->seuil_stock_alert = isset($product['stock_alert']) ? $product['stock_alert'] : null; + $newobject->seuil_stock_alerte = isset($product['stock_alert']) ? $product['stock_alert'] : null; $newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0; - if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3); + if (!empty($product['country_code'])) { + $newobject->country_id = getCountry($product['country_code'], 3); + } $newobject->customcode = isset($product['customcode']) ? $product['customcode'] : ''; $newobject->canvas = isset($product['canvas']) ? $product['canvas'] : ''; /*foreach($product['lines'] as $line) - { - $newline=new FactureLigne($db); - $newline->type=$line['type']; - $newline->desc=$line['desc']; - $newline->fk_product=$line['fk_product']; - $newline->total_ht=$line['total_net']; - $newline->total_vat=$line['total_vat']; - $newline->total_ttc=$line['total']; - $newline->vat=$line['vat_rate']; - $newline->qty=$line['qty']; - $newline->fk_product=$line['product_id']; - }*/ + { + $newline=new FactureLigne($db); + $newline->type=$line['type']; + $newline->desc=$line['desc']; + $newline->fk_product=$line['fk_product']; + $newline->total_ht=$line['total_net']; + $newline->total_vat=$line['total_vat']; + $newline->total_ttc=$line['total']; + $newline->vat=$line['vat_rate']; + $newline->qty=$line['qty']; + $newline->fk_product=$line['product_id']; + }*/ //var_dump($product['ref_ext']); //var_dump($product['lines'][0]['type']); @@ -563,10 +572,8 @@ function createProductOrService($authentication, $product) $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) - { - foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) - { + if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $product[$key]; } @@ -575,43 +582,34 @@ function createProductOrService($authentication, $product) $db->begin(); $result = $newobject->create($fuser, 0); - if ($result <= 0) - { + if ($result <= 0) { $error++; } - if (!$error) - { + if (!$error) { // Update stock if stock count is provided and differs from database after creation or update - if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) - { + if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) { include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $savstockreal = $newobject->stock_reel; $newobject->load_stock('novirtual,nobatch'); // This overwrite ->stock_reel, surely 0 because we have just created product $getstockreal = $newobject->stock_reel; - if ($savstockreal != $getstockreal) - { + if ($savstockreal != $getstockreal) { $warehouse = new Entrepot($db); $warehouse->fetch(0, $product['warehouse_ref']); - if ($warehouse->id > 0) - { - if (($savstockreal - $getstockreal) > 0) - { + if ($warehouse->id > 0) { + if (($savstockreal - $getstockreal) > 0) { $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog')); } - if (($savstockreal - $getstockreal) > 0) - { + if (($savstockreal - $getstockreal) > 0) { $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog')); } - if ($result <= 0) - { + if ($result <= 0) { $error++; $newobject->error = 'You set a different value for stock, but correction of stock count (before='.$getstockreal.', after='.$savstockreal.') fails with error '.$newobject->error; } - } - else { + } else { $error++; $newobject->error = 'You set a different value for stock but we failed to find warehouse '.$product['warehouse_ref'].' to make correction.'; } @@ -619,12 +617,10 @@ function createProductOrService($authentication, $product) } } - if (!$error) - { + if (!$error) { $db->commit(); $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref); - } - else { + } else { $db->rollback(); $error++; $errorcode = 'KO'; @@ -632,8 +628,7 @@ function createProductOrService($authentication, $product) } } - if ($error) - { + if ($error) { $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); } @@ -650,43 +645,51 @@ function createProductOrService($authentication, $product) */ function updateProductOrService($authentication, $product) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); dol_syslog("Function: updateProductOrService login=".$authentication['login']); - if ($authentication['entity']) $conf->entity = $authentication['entity']; + if ($authentication['entity']) { + $conf->entity = $authentication['entity']; + } // Init and check authentication $objectresp = array(); - $errorcode = ''; $errorlabel = ''; + $errorcode = ''; + $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); // Check parameters - if ($product['price_net'] > 0) $product['price_base_type'] = 'HT'; - if ($product['price'] > 0) $product['price_base_type'] = 'TTC'; + if ($product['price_net'] > 0) { + $product['price_base_type'] = 'HT'; + } + if ($product['price'] > 0) { + $product['price_base_type'] = 'TTC'; + } - if ($product['price_net'] > 0 && $product['price'] > 0) - { + if ($product['price_net'] > 0 && $product['price'] > 0) { $error++; $errorcode = 'KO'; $errorlabel = "You must choose between price or price_net to provide price."; } - if ($product['barcode'] && !$product['barcode_type']) - { + if ($product['barcode'] && !$product['barcode_type']) { $error++; $errorcode = 'KO'; $errorlabel = "You must set a barcode type when setting a barcode."; } - if (!$error) - { + if (!$error) { include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $newobject = new Product($db); $newobject->fetch($product['id']); - if (isset($product['ref'])) $newobject->ref = $product['ref']; - if (isset($product['ref_ext'])) $newobject->ref_ext = $product['ref_ext']; + if (isset($product['ref'])) { + $newobject->ref = $product['ref']; + } + if (isset($product['ref_ext'])) { + $newobject->ref_ext = $product['ref_ext']; + } $newobject->type = $product['type']; $newobject->label = $product['label']; $newobject->description = $product['description']; @@ -699,30 +702,27 @@ function updateProductOrService($authentication, $product) $newobject->price_base_type = $product['price_base_type']; $newobject->date_creation = $now; - if ($product['barcode']) - { + if ($product['barcode']) { $newobject->barcode = $product['barcode']; $newobject->barcode_type = $product['barcode_type']; } - $newobject->stock_reel = $product['stock_real']; - $newobject->pmp = $product['pmp']; - $newobject->seuil_stock_alert = $product['stock_alert']; + $newobject->stock_reel = isset($product['stock_real']) ? $product['stock_real'] : null; + $newobject->pmp = isset($product['pmp']) ? $product['pmp'] : null; + $newobject->seuil_stock_alerte = isset($product['stock_alert']) ? $product['stock_alert'] : null; - $newobject->country_id = $product['country_id']; - if ($product['country_code']) $newobject->country_id = getCountry($product['country_code'], 3); - $newobject->customcode = $product['customcode']; + $newobject->country_id = isset($product['country_id']) ? $product['country_id'] : 0; + if (!empty($product['country_code'])) $newobject->country_id = getCountry($product['country_code'], 3); + $newobject->customcode = isset($product['customcode']) ? $product['customcode'] : ''; - $newobject->canvas = $product['canvas']; + $newobject->canvas = isset($product['canvas']) ? $product['canvas'] : ''; $elementtype = 'product'; $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($elementtype, true); - if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) - { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) - { + if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $product[$key]; } @@ -731,41 +731,32 @@ function updateProductOrService($authentication, $product) $db->begin(); $result = $newobject->update($newobject->id, $fuser); - if ($result <= 0) - { + if ($result <= 0) { $error++; - } - else { + } else { // Update stock if stock count is provided and differs from database after creation or update - if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) - { + if (isset($product['stock_real']) && $product['stock_real'] != '' && !empty($conf->global->stock->enabled)) { include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $savstockreal = $newobject->stock_reel; $newobject->load_stock('novirtual,nobatch'); // This overwrite ->stock_reel $getstockreal = $newobject->stock_reel; - if ($savstockreal != $getstockreal) - { + if ($savstockreal != $getstockreal) { $warehouse = new Entrepot($db); $warehouse->fetch(0, $product['warehouse_ref']); - if ($warehouse->id > 0) - { - if (($savstockreal - $getstockreal) > 0) - { + if ($warehouse->id > 0) { + if (($savstockreal - $getstockreal) > 0) { $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 0, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog')); } - if (($savstockreal - $getstockreal) > 0) - { + if (($savstockreal - $getstockreal) > 0) { $result = $newobject->correct_stock($fuser, $warehouse->id, ($savstockreal - $getstockreal), 1, 'Correction from external call (Web Service)', 0, 'WS'.dol_print_date($now, 'dayhourlog')); } - if ($result <= 0) - { + if ($result <= 0) { $error++; $newobject->error = 'You set a different value for stock, but correction of stock count (before='.$getstockreal.', after='.$savstockreal.') fails with error '.$newobject->error; } - } - else { + } else { $error++; $newobject->error = 'You set a different value for stock but we failed to find warehouse '.$product['warehouse_ref'].' to make correction.'; } @@ -773,32 +764,24 @@ function updateProductOrService($authentication, $product) } } - if (!$error) - { - if ($newobject->price_base_type == 'HT') - { + if (!$error) { + if ($newobject->price_base_type == 'HT') { $result = $newobject->updatePrice($newobject->price, $newobject->price_base_type, $fuser); - if ($result <= 0) - { + if ($result <= 0) { $error++; } - } - elseif ($newobject->price_base_type == 'TTC') - { - $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type); - if ($result <= 0) - { + } elseif ($newobject->price_base_type == 'TTC') { + $result = $newobject->updatePrice($newobject->price_ttc, $newobject->price_base_type, $fuser); + if ($result <= 0) { $error++; } } } - if (!$error) - { + if (!$error) { $db->commit(); $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref); - } - else { + } else { $db->rollback(); $error++; $errorcode = 'KO'; @@ -806,8 +789,7 @@ function updateProductOrService($authentication, $product) } } - if ($error) - { + if ($error) { $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); } @@ -824,15 +806,18 @@ function updateProductOrService($authentication, $product) */ function deleteProductOrService($authentication, $listofidstring) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: deleteProductOrService login=".$authentication['login']); - if ($authentication['entity']) $conf->entity = $authentication['entity']; + if ($authentication['entity']) { + $conf->entity = $authentication['entity']; + } // Init and check authentication $objectresp = array(); - $errorcode = ''; $errorlabel = ''; + $errorcode = ''; + $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); @@ -844,32 +829,26 @@ function deleteProductOrService($authentication, $listofidstring) $listofiddeleted = array(); // Check parameters - if (count($listofid) == 0 || empty($listofid[0])) - { + if (count($listofid) == 0 || empty($listofid[0])) { $error++; $errorcode = 'KO'; $errorlabel = "List of Id of products or services to delete are required."; } - if (!$error) - { + if (!$error) { $firsterror = ''; $db->begin(); - foreach ($listofid as $key => $id) - { + foreach ($listofid as $id) { $newobject = new Product($db); $result = $newobject->fetch($id); - if ($result == 0) - { + if ($result == 0) { $error++; $firsterror = 'Product or service with id '.$id.' not found'; break; - } - else { + } else { $result = $newobject->delete($user); - if ($result <= 0) - { + if ($result <= 0) { $error++; $firsterror = $newobject->error; break; @@ -879,13 +858,11 @@ function deleteProductOrService($authentication, $listofidstring) } } - if (!$error) - { + if (!$error) { $db->commit(); //$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'listofid'=>$listofiddeleted); $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'nbdeleted'=>count($listofiddeleted)); - } - else { + } else { $db->rollback(); $error++; $errorcode = 'KO'; @@ -893,15 +870,12 @@ function deleteProductOrService($authentication, $listofidstring) } } - if ($error) - { + if ($error) { //$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'listofid'=>$listofiddeleted); $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'nbdeleted'=>0); - } - elseif (count($listofiddeleted) == 0) - { - //$objectresp=array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',',$listofid).' found'), 'listofid'=>$listofiddeleted); - $objectresp = array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',', $listofid).' found'), 'nbdeleted'=>0); + } elseif (count($listofiddeleted) == 0) { + //$objectresp=array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',',$listofid).' found'), 'listofid'=>$listofiddeleted); + $objectresp = array('result'=>array('result_code'=>'NOT_FOUND', 'result_label'=>'No product or service with id '.join(',', $listofid).' found'), 'nbdeleted'=>0); } return $objectresp; @@ -917,53 +891,56 @@ function deleteProductOrService($authentication, $listofidstring) */ function getListOfProductsOrServices($authentication, $filterproduct) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getListOfProductsOrServices login=".$authentication['login']); - if ($authentication['entity']) $conf->entity = $authentication['entity']; + if ($authentication['entity']) { + $conf->entity = $authentication['entity']; + } // Init and check authentication $objectresp = array(); $arrayproducts = array(); - $errorcode = ''; $errorlabel = ''; + $errorcode = ''; + $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); // Check parameters - if (!$error) - { + if (!$error) { $sql = "SELECT rowid, ref, ref_ext"; $sql .= " FROM ".MAIN_DB_PREFIX."product"; $sql .= " WHERE entity=".$conf->entity; - foreach ($filterproduct as $key => $val) - { - if ($key == 'type' && $val >= 0) $sql .= " AND fk_product_type = ".$db->escape($val); - if ($key == 'status_tosell') $sql .= " AND tosell = ".$db->escape($val); - if ($key == 'status_tobuy') $sql .= " AND tobuy = ".$db->escape($val); + foreach ($filterproduct as $key => $val) { + if ($key == 'type' && $val >= 0) { + $sql .= " AND fk_product_type = ".$db->escape($val); + } + if ($key == 'status_tosell') { + $sql .= " AND tosell = ".$db->escape($val); + } + if ($key == 'status_tobuy') { + $sql .= " AND tobuy = ".$db->escape($val); + } } $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); + if ($resql) { + $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - $arrayproducts[] = array('id'=>$obj->rowid, 'ref'=>$obj->ref, 'ref_ext'=>$obj->ref_ext); - $i++; - } - } - else { + $i = 0; + while ($i < $num) { + $obj = $db->fetch_object($resql); + $arrayproducts[] = array('id'=>$obj->rowid, 'ref'=>$obj->ref, 'ref_ext'=>$obj->ref_ext); + $i++; + } + } else { $error++; $errorcode = $db->lasterrno(); $errorlabel = $db->lasterror(); } } - if ($error) - { + if ($error) { $objectresp = array( 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel), 'products'=>$arrayproducts @@ -996,7 +973,9 @@ function getProductsForCategory($authentication, $id, $lang = '') dol_syslog("Function: getProductsForCategory login=".$authentication['login']." id=".$id); - if ($authentication['entity']) $conf->entity = $authentication['entity']; + if ($authentication['entity']) { + $conf->entity = $authentication['entity']; + } $objectresp = array(); $errorcode = ''; $errorlabel = ''; @@ -1005,27 +984,23 @@ function getProductsForCategory($authentication, $id, $lang = '') $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); - if (!$error && !$id) - { + if (!$error && !$id) { $error++; $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter id must be provided."; } - if (!$error) - { + if (!$error) { $langcode = ($lang ? $lang : (empty($conf->global->MAIN_LANG_DEFAULT) ? 'auto' : $conf->global->MAIN_LANG_DEFAULT)); $langs->setDefaultLang($langcode); $fuser->getrights(); $nbmax = 10; - if ($fuser->rights->produit->lire) - { + if ($fuser->rights->produit->lire) { $categorie = new Categorie($db); $result = $categorie->fetch($id); - if ($result > 0) - { + if ($result > 0) { $table = "product"; $field = "product"; $sql = "SELECT fk_".$field." FROM ".MAIN_DB_PREFIX."categorie_".$table; @@ -1035,24 +1010,21 @@ function getProductsForCategory($authentication, $id, $lang = '') dol_syslog("getProductsForCategory get id of product into category", LOG_DEBUG); $res = $db->query($sql); - if ($res) - { + if ($res) { $iProduct = 0; $tmpproduct = new Product($db); $products = array(); - while ($rec = $db->fetch_array($res)) - { + while ($rec = $db->fetch_array($res)) { $tmpproduct->fetch($rec['fk_'.$field]); - if ($tmpproduct->status > 0) - { + if ($tmpproduct->status > 0) { $dir = (!empty($conf->product->dir_output) ? $conf->product->dir_output : $conf->service->dir_output); $pdir = get_exdir($tmpproduct->id, 2, 0, 0, $tmpproduct, 'product').$tmpproduct->id."/photos/"; $dir = $dir.'/'.$pdir; $products[] = array( 'id' => $tmpproduct->id, - 'ref' => $tmpproduct->ref, - 'ref_ext' => $tmpproduct->ref_ext, + 'ref' => $tmpproduct->ref, + 'ref_ext' => $tmpproduct->ref_ext, 'label' => !empty($tmpproduct->multilangs[$langs->defaultlang]["label"]) ? $tmpproduct->multilangs[$langs->defaultlang]["label"] : $tmpproduct->label, 'description' => !empty($tmpproduct->multilangs[$langs->defaultlang]["description"]) ? $tmpproduct->multilangs[$langs->defaultlang]["description"] : $tmpproduct->description, 'date_creation' => dol_print_date($tmpproduct->date_creation, 'dayhourrfc'), @@ -1090,10 +1062,8 @@ function getProductsForCategory($authentication, $id, $lang = '') //Get extrafield values $tmpproduct->fetch_optionals(); - if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) - { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) - { + if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $products[$iProduct] = array_merge($products[$iProduct], array('options_'.$key => $tmpproduct->array_options['options_'.$key])); } } @@ -1107,26 +1077,22 @@ function getProductsForCategory($authentication, $id, $lang = '') 'result'=>array('result_code'=>'OK', 'result_label'=>''), 'products'=> $products ); - } - else { + } else { $errorcode = 'NORECORDS_FOR_ASSOCIATION'; $errorlabel = 'No products associated'.$sql; $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); dol_syslog("getProductsForCategory:: ".$errorcode, LOG_DEBUG); } - } - else { + } else { $error++; $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id; } - } - else { + } else { $error++; $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; } } - if ($error) - { + if ($error) { $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); } diff --git a/htdocs/webservices/server_project.php b/htdocs/webservices/server_project.php index 0817332c09f..8d76786df71 100644 --- a/htdocs/webservices/server_project.php +++ b/htdocs/webservices/server_project.php @@ -131,7 +131,7 @@ $server->wsdl->addComplexType( ); $project_elements = array(); -foreach ($listofreferent as $key => $_) +foreach ($listofreferent as $key => $label) { $project_elements[$key] = array('name'=>$key, 'type'=>'tns:elementsArray'); } @@ -279,7 +279,7 @@ function createProject($authentication, $project) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $project[$key]; @@ -338,7 +338,7 @@ function createProject($authentication, $project) */ function getProject($authentication, $id = '', $ref = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getProject login=".$authentication['login']." id=".$id." ref=".$ref); @@ -389,7 +389,7 @@ function getProject($authentication, $id = '', $ref = '') if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { $project->fetch_optionals(); - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $project_result_fields = array_merge($project_result_fields, array('options_'.$key => $project->array_options['options_'.$key])); } diff --git a/htdocs/webservices/server_supplier_invoice.php b/htdocs/webservices/server_supplier_invoice.php index be90b60c36f..507095ac78b 100644 --- a/htdocs/webservices/server_supplier_invoice.php +++ b/htdocs/webservices/server_supplier_invoice.php @@ -225,7 +225,7 @@ $server->register( */ function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getSupplierInvoice login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -333,7 +333,7 @@ function getSupplierInvoice($authentication, $id = '', $ref = '', $ref_ext = '') */ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty) { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getSupplierInvoicesForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty); @@ -344,6 +344,7 @@ function getSupplierInvoicesForThirdParty($authentication, $idthirdparty) $errorcode = ''; $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); + // Check parameters if (!$error && empty($idthirdparty)) { diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index 5bde94cc0d5..12b2d3315c8 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -132,7 +132,7 @@ if (is_array($extrafields) && count($extrafields) > 0) { } if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { //$value=$object->array_options["options_".$key]; $type = $extrafields->attributes[$elementtype]['type'][$key]; @@ -290,7 +290,7 @@ $server->register( */ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -367,7 +367,7 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $thirdparty_result_fields = array_merge($thirdparty_result_fields, array('options_'.$key => $thirdparty->array_options['options_'.$key])); } @@ -408,7 +408,7 @@ function getThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') */ function createThirdParty($authentication, $thirdparty) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); @@ -483,7 +483,7 @@ function createThirdParty($authentication, $thirdparty) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $newobject->array_options[$key] = $thirdparty[$key]; @@ -538,7 +538,7 @@ function createThirdParty($authentication, $thirdparty) */ function updateThirdParty($authentication, $thirdparty) { - global $db, $conf, $langs; + global $db, $conf; $now = dol_now(); @@ -617,7 +617,7 @@ function updateThirdParty($authentication, $thirdparty) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'options_'.$key; $object->array_options[$key] = $thirdparty[$key]; @@ -672,9 +672,7 @@ function updateThirdParty($authentication, $thirdparty) */ function getListOfThirdParties($authentication, $filterthirdparty) { - global $db, $conf, $langs; - - $now = dol_now(); + global $db, $conf; dol_syslog("Function: getListOfThirdParties login=".$authentication['login']); @@ -725,7 +723,7 @@ function getListOfThirdParties($authentication, $filterthirdparty) if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $extrafieldsOptions['options_'.$key] = $obj->{$key}; } @@ -782,7 +780,7 @@ function getListOfThirdParties($authentication, $filterthirdparty) */ function deleteThirdParty($authentication, $id = '', $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: deleteThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php index 25cb2324412..8619a952ea1 100644 --- a/htdocs/webservices/server_user.php +++ b/htdocs/webservices/server_user.php @@ -195,7 +195,7 @@ if (is_array($extrafields) && count($extrafields) > 0) { } if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $type = $extrafields->attributes[$elementtype]['type'][$key]; if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; } @@ -308,7 +308,7 @@ $server->register( */ function getUser($authentication, $id, $ref = '', $ref_ext = '') { - global $db, $conf, $langs; + global $db, $conf; dol_syslog("Function: getUser login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); @@ -399,9 +399,7 @@ function getUser($authentication, $id, $ref = '', $ref_ext = '') */ function getListOfGroups($authentication) { - global $db, $conf, $langs; - - $now = dol_now(); + global $db, $conf; dol_syslog("Function: getListOfGroups login=".$authentication['login']); @@ -477,7 +475,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) { global $db, $conf, $langs; - dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']); if ($authentication['entity']) $conf->entity = $authentication['entity']; @@ -601,7 +599,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) $extrafields->fetch_name_optionals_label($elementtype, true); if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) { - foreach ($extrafields->attributes[$elementtype]['label'] as $key=>$label) + foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) { $key = 'contact_options_'.$key; $key = substr($key, 8); // Remove 'contact_' prefix @@ -644,7 +642,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) } } else { $error++; - $errors = ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors); + $errorcode = join(', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors)); } } } else { @@ -662,7 +660,7 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) { $db->rollback(); $objectresp = array( - 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel) + 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel) ); } @@ -680,9 +678,9 @@ function createUserFromThirdparty($authentication, $thirdpartywithuser) function setUserPassword($authentication, $shortuser) { - global $db, $conf, $langs; + global $db, $conf; - dol_syslog("Function: setUserPassword login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + dol_syslog("Function: setUserPassword login=".$authentication['login']); if ($authentication['entity']) $conf->entity = $authentication['entity']; @@ -715,7 +713,6 @@ function setUserPassword($authentication, $shortuser) { $objectresp = array( 'result'=>array('result_code' => 'OK', 'result_label' => ''), - 'groups'=>$arraygroups ); } else { diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 7cbb6af5955..8dc903642e0 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -131,6 +131,35 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; } + /** + * testIsValidEmail + * + * @return void + */ + public function testIsValidEmail() + { + // Nb of line is same than entry text + + $input="bidon@bademail"; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertFalse($result, 'Check isValidEmail '.$input); + + $input="test@yahoo.com"; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'Check isValidEmail '.$input); + + $input="The name of sender "; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertFalse($result, 'Check isValidEmail '.$input); + + $input="1234.abcdefg@domainame.com.br"; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'Check isValidEmail '.$input); + } /** * testIsValidMXRecord diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 650e391587b..6bedda43fa4 100644 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -61,6 +61,9 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase protected $ns = 'http://www.dolibarr.org/ns/'; + protected $pass = 'admin'; + + /** * Constructor * We save global variables into local variables @@ -102,6 +105,8 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase { global $conf,$user,$langs,$db; + $now = dol_now(); + // create a third_party, needed to create an invoice // // The third party is created in setUpBeforeClass() and not in the @@ -246,7 +251,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, 'sourceapplication'=>'DEMO', 'login'=>'admin', - 'password'=>'admin', + 'password'=>$this->pass, 'entity'=>''); // Test URL @@ -270,7 +275,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase print "\n"; } - print __METHOD__." result=".$result['result']['result_code']."\n"; + print __METHOD__." result=".$result['result']['result_code']." ".$result['result']['result_label']."\n"; $this->assertEquals('OK', $result['result']['result_code']); $this->assertEquals('ref-phpunit-2', $result['ref_ext']); @@ -302,7 +307,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, 'sourceapplication'=>'DEMO', 'login'=>'admin', - 'password'=>'admin', + 'password'=>$this->pass, 'entity'=>''); // Test URL @@ -401,7 +406,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, 'sourceapplication'=>'DEMO', 'login'=>'admin', - 'password'=>'admin', + 'password'=>$this->pass, 'entity'=>''); // Test URL