diff --git a/htdocs/admin/bank_extrafields.php b/htdocs/admin/bank_extrafields.php index 75fd269abc9..940e0a7313e 100644 --- a/htdocs/admin/bank_extrafields.php +++ b/htdocs/admin/bank_extrafields.php @@ -37,13 +37,13 @@ $extrafields = new ExtraFields($db); $form = new Form($db); // List of supported format -$tmptype2label=ExtraFields::$type2label; -$type2label=array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val); +$tmptype2label = ExtraFields::$type2label; +$type2label = array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); -$action=GETPOST('action', 'alpha'); -$attrname=GETPOST('attrname', 'alpha'); -$elementtype='bank_account'; //Must be the $element of the class that manage extrafield +$action = GETPOST('action', 'alpha'); +$attrname = GETPOST('attrname', 'alpha'); +$elementtype = 'bank_account'; //Must be the $element of the class that manage extrafield if (!$user->admin) accessforbidden(); @@ -65,7 +65,7 @@ $textobject = $langs->transnoentitiesnoconv("Bank"); llxHeader('', $langs->trans("BankSetupModule"), $help_url); -$linkback=''.$langs->trans("BackToModuleList").''; +$linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("BankSetupModule"), $linkback, 'title_setup'); @@ -101,7 +101,7 @@ if ($action == 'create') /* * Edition of an optional field */ -if ($action == 'edit' && ! empty($attrname)) +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/admin/system/filecheck.php b/htdocs/admin/system/filecheck.php index 9bae083ea0d..9a530262b6e 100644 --- a/htdocs/admin/system/filecheck.php +++ b/htdocs/admin/system/filecheck.php @@ -215,7 +215,7 @@ if (!$error && $xml) // Defined qualified files (must be same than into generate_filelist_xml.php) $regextoinclude = '\.(php|php3|php4|php5|phtml|phps|phar|inc|css|scss|html|xml|js|json|tpl|jpg|jpeg|png|gif|ico|sql|lang|txt|yml|md|mp3|mp4|wav|mkv|z|gz|zip|rar|tar|less|svg|eot|woff|woff2|ttf|manifest)$'; - $regextoexclude = '('.($includecustom ? '' : 'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs + $regextoexclude = '('.($includecustom ? '' : 'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude); // Fill file_list with files in signature, new files, modified files diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 553c30e0ec8..a42888aad27 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -67,21 +67,21 @@ class Setup extends DolibarrApi $list = array(); $sql = "SELECT rowid, code, libelle as label, module"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_input_method as t"; - $sql.= " WHERE t.active = ".$active; + $sql .= " FROM ".MAIN_DB_PREFIX."c_input_method as t"; + $sql .= " WHERE t.active = ".$active; // Add sql filters if ($sqlfilters) { - if (! DolibarrApi::_checkFilters($sqlfilters)) + if (!DolibarrApi::_checkFilters($sqlfilters)) { throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters); } - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - $sql.= $this->db->order($sortfield, $sortorder); + $sql .= $this->db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) { @@ -453,21 +453,21 @@ class Setup extends DolibarrApi { $list = array(); $sql = "SELECT t.rowid, t.code, t.libelle, t.description, t.tracking"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t"; - $sql.= " WHERE t.active = ".$active; + $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t"; + $sql .= " WHERE t.active = ".$active; // Add sql filters if ($sqlfilters) { - if (! DolibarrApi::_checkFilters($sqlfilters)) + if (!DolibarrApi::_checkFilters($sqlfilters)) { throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); } - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - $sql.= $this->db->order($sortfield, $sortorder); + $sql .= $this->db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) { @@ -1104,22 +1104,22 @@ class Setup extends DolibarrApi $list = array(); //TODO link with multicurrency module $sql = "SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_socialnetworks as t"; - $sql.= " WHERE t.entity IN (".getEntity('c_socialnetworks').")"; - $sql.= " AND t.active = ".$active; + $sql .= " FROM ".MAIN_DB_PREFIX."c_socialnetworks as t"; + $sql .= " WHERE t.entity IN (".getEntity('c_socialnetworks').")"; + $sql .= " AND t.active = ".$active; // Add sql filters if ($sqlfilters) { - if (! DolibarrApi::_checkFilters($sqlfilters)) + if (!DolibarrApi::_checkFilters($sqlfilters)) { throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); } - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - $sql.= $this->db->order($sortfield, $sortorder); + $sql .= $this->db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) { @@ -1474,7 +1474,7 @@ class Setup extends DolibarrApi // Defined qualified files (must be same than into generate_filelist_xml.php) $regextoinclude = '\.(php|php3|php4|php5|phtml|phps|phar|inc|css|scss|html|xml|js|json|tpl|jpg|jpeg|png|gif|ico|sql|lang|txt|yml|bak|md|mp3|mp4|wav|mkv|z|gz|zip|rar|tar|less|svg|eot|woff|woff2|ttf|manifest)$'; - $regextoexclude = '('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs + $regextoexclude = '('.($includecustom ? '' : 'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude); // Fill file_list with files in signature, new files, modified files diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 562982dfc47..a6696bc629d 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -36,89 +36,89 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php'; -if (! empty($conf->projet->enabled)) { +if (!empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; } -if (! isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW=3; +if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3; -if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB=5; -$MAXAGENDA=$conf->global->AGENDA_EXT_NB; +if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB = 5; +$MAXAGENDA = $conf->global->AGENDA_EXT_NB; -$filter = GETPOST("search_filter", 'alpha', 3)?GETPOST("search_filter", 'alpha', 3):GETPOST("filter", 'alpha', 3); -$filtert = GETPOST("search_filtert", "int", 3)?GETPOST("search_filtert", "int", 3):GETPOST("filtert", "int", 3); -$usergroup = GETPOST("search_usergroup", "int", 3)?GETPOST("search_usergroup", "int", 3):GETPOST("usergroup", "int", 3); -$showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday", "int"):1; +$filter = GETPOST("search_filter", 'alpha', 3) ?GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3); +$filtert = GETPOST("search_filtert", "int", 3) ?GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3); +$usergroup = GETPOST("search_usergroup", "int", 3) ?GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3); +$showbirthday = empty($conf->use_javascript_ajax) ?GETPOST("showbirthday", "int") : 1; // If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) { - $filtert=$user->id; + $filtert = $user->id; } $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOST("page", "int"); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 -$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; -if (! $sortorder) $sortorder="ASC"; -if (! $sortfield) $sortfield="a.datec"; +if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) $sortfield = "a.datec"; // Security check -$socid = GETPOST("search_socid", "int")?GETPOST("search_socid", "int"):GETPOST("socid", "int"); -if ($user->socid) $socid=$user->socid; +$socid = GETPOST("search_socid", "int") ?GETPOST("search_socid", "int") : GETPOST("socid", "int"); +if ($user->socid) $socid = $user->socid; $result = restrictedArea($user, 'agenda', 0, '', 'myactions'); -if ($socid < 0) $socid=''; +if ($socid < 0) $socid = ''; -$canedit=1; -if (! $user->rights->agenda->myactions->read) accessforbidden(); -if (! $user->rights->agenda->allactions->read) $canedit=0; -if (! $user->rights->agenda->allactions->read || $filter =='mine') // If no permission to see all, we show only affected to me +$canedit = 1; +if (!$user->rights->agenda->myactions->read) accessforbidden(); +if (!$user->rights->agenda->allactions->read) $canedit = 0; +if (!$user->rights->agenda->allactions->read || $filter == 'mine') // If no permission to see all, we show only affected to me { - $filtert=$user->id; + $filtert = $user->id; } -$action=GETPOST('action', 'alpha'); -$resourceid=GETPOST("search_resourceid", "int"); -$year=GETPOST("year", "int")?GETPOST("year", "int"):date("Y"); -$month=GETPOST("month", "int")?GETPOST("month", "int"):date("m"); -$week=GETPOST("week", "int")?GETPOST("week", "int"):date("W"); -$day=GETPOST("day", "int")?GETPOST("day", "int"):date("d"); -$pid=GETPOST("search_projectid", "int", 3)?GETPOST("search_projectid", "int", 3):GETPOST("projectid", "int", 3); -$status=GETPOST("search_status", 'aZ09')?GETPOST("search_status", 'aZ09'):GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo' -$type=GETPOST("search_type", 'aZ09')?GETPOST("search_type", 'aZ09'):GETPOST("type", 'aZ09'); -$maxprint=(isset($_GET["maxprint"])?GETPOST("maxprint"):$conf->global->AGENDA_MAX_EVENTS_DAY_VIEW); -$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') +$action = GETPOST('action', 'alpha'); +$resourceid = GETPOST("search_resourceid", "int"); +$year = GETPOST("year", "int") ?GETPOST("year", "int") : date("Y"); +$month = GETPOST("month", "int") ?GETPOST("month", "int") : date("m"); +$week = GETPOST("week", "int") ?GETPOST("week", "int") : date("W"); +$day = GETPOST("day", "int") ?GETPOST("day", "int") : date("d"); +$pid = GETPOST("search_projectid", "int", 3) ?GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3); +$status = GETPOST("search_status", 'aZ09') ?GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo' +$type = GETPOST("search_type", 'aZ09') ?GETPOST("search_type", 'aZ09') : GETPOST("type", 'aZ09'); +$maxprint = (isset($_GET["maxprint"]) ?GETPOST("maxprint") : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW); +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index) if (GETPOST('search_actioncode', 'array')) { - $actioncode=GETPOST('search_actioncode', 'array', 3); - if (! count($actioncode)) $actioncode='0'; + $actioncode = GETPOST('search_actioncode', 'array', 3); + if (!count($actioncode)) $actioncode = '0'; } else { - $actioncode=GETPOST("search_actioncode", "alpha", 3)?GETPOST("search_actioncode", "alpha", 3):(GETPOST("search_actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE)); + $actioncode = GETPOST("search_actioncode", "alpha", 3) ?GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE)); } -if ($actioncode == '' && empty($actioncodearray)) $actioncode=(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE); +if ($actioncode == '' && empty($actioncodearray)) $actioncode = (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE); -if ($status == '' && ! GETPOSTISSET('search_status')) $status=(empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS)?'':$conf->global->AGENDA_DEFAULT_FILTER_STATUS); +if ($status == '' && !GETPOSTISSET('search_status')) $status = (empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS); $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW); $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW); -if (empty($action) && ! GETPOSTISSET('action')) $action=$defaultview; +if (empty($action) && !GETPOSTISSET('action')) $action = $defaultview; if ($action == 'default') // When action is default, we want a calendar view and not the list { $action = (($defaultview != 'show_list') ? $defaultview : 'show_month'); } -if (GETPOST('viewcal', 'none') && GETPOST('action', 'alpha') != 'show_day' && GETPOST('action', 'alpha') != 'show_week') { - $action='show_month'; $day=''; +if (GETPOST('viewcal', 'none') && GETPOST('action', 'alpha') != 'show_day' && GETPOST('action', 'alpha') != 'show_week') { + $action = 'show_month'; $day = ''; } // View by month if (GETPOST('viewweek', 'none') || GETPOST('action', 'alpha') == 'show_week') { - $action='show_week'; $week=($week?$week:date("W")); $day=($day?$day:date("d")); + $action = 'show_week'; $week = ($week ? $week : date("W")); $day = ($day ? $day : date("d")); } // View by week -if (GETPOST('viewday', 'none') || GETPOST('action', 'alpha') == 'show_day') { - $action='show_day'; $day=($day?$day:date("d")); +if (GETPOST('viewday', 'none') || GETPOST('action', 'alpha') == 'show_day') { + $action = 'show_day'; $day = ($day ? $day : date("d")); } // View by day // Load translation files required by the page @@ -1482,7 +1482,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa //var_dump($event->userassigned); //var_dump($event->transparency); print ''.img_picto("all", "1downarrow_selected.png").' ...'; - print ' +'.(count($eventarray[$daykey])-$maxprint); + print ' +'.(count($eventarray[$daykey]) - $maxprint); print ''; break; //$ok=false; // To avoid to show twice the link diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 48256d75b8c..947d0a9d2f8 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -51,93 +51,93 @@ $showbirthday = 0; // If not choice done on calendar owner, we filter on user. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) { - $filtert=$user->id; + $filtert = $user->id; } $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOST("page", "int"); if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 -$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; -if (! $sortorder) $sortorder="ASC"; -if (! $sortfield) $sortfield="a.datec"; +if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) $sortfield = "a.datec"; // Security check -$socid = GETPOST("search_socid", "int")?GETPOST("search_socid", "int"):GETPOST("socid", "int"); -if ($user->socid) $socid=$user->socid; +$socid = GETPOST("search_socid", "int") ?GETPOST("search_socid", "int") : GETPOST("socid", "int"); +if ($user->socid) $socid = $user->socid; $result = restrictedArea($user, 'agenda', 0, '', 'myactions'); -if ($socid < 0) $socid=''; +if ($socid < 0) $socid = ''; -$canedit=1; -if (! $user->rights->agenda->myactions->read) accessforbidden(); -if (! $user->rights->agenda->allactions->read) $canedit=0; -if (! $user->rights->agenda->allactions->read || $filter =='mine') // If no permission to see all, we show only affected to me +$canedit = 1; +if (!$user->rights->agenda->myactions->read) accessforbidden(); +if (!$user->rights->agenda->allactions->read) $canedit = 0; +if (!$user->rights->agenda->allactions->read || $filter == 'mine') // If no permission to see all, we show only affected to me { - $filtert=$user->id; + $filtert = $user->id; } //$action=GETPOST('action','alpha'); -$action='show_peruser'; //We use 'show_week' mode -$resourceid=GETPOST("search_resourceid", "int")?GETPOST("search_resourceid", "int"):GETPOST("resourceid", "int"); -$year=GETPOST("year", "int")?GETPOST("year", "int"):date("Y"); -$month=GETPOST("month", "int")?GETPOST("month", "int"):date("m"); -$week=GETPOST("week", "int")?GETPOST("week", "int"):date("W"); -$day=GETPOST("day", "int")?GETPOST("day", "int"):date("d"); -$pid=GETPOST("search_projectid", "int", 3)?GETPOST("search_projectid", "int", 3):GETPOST("projectid", "int", 3); -$status=GETPOST("search_status", 'alpha')?GETPOST("search_status", 'alpha'):GETPOST("status", 'alpha'); -$type=GETPOST("search_type", 'alpha')?GETPOST("search_type", 'alpha'):GETPOST("type", 'alpha'); -$maxprint=((GETPOST("maxprint", 'int')!='')?GETPOST("maxprint", 'int'):$conf->global->AGENDA_MAX_EVENTS_DAY_VIEW); -$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') +$action = 'show_peruser'; //We use 'show_week' mode +$resourceid = GETPOST("search_resourceid", "int") ?GETPOST("search_resourceid", "int") : GETPOST("resourceid", "int"); +$year = GETPOST("year", "int") ?GETPOST("year", "int") : date("Y"); +$month = GETPOST("month", "int") ?GETPOST("month", "int") : date("m"); +$week = GETPOST("week", "int") ?GETPOST("week", "int") : date("W"); +$day = GETPOST("day", "int") ?GETPOST("day", "int") : date("d"); +$pid = GETPOST("search_projectid", "int", 3) ?GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3); +$status = GETPOST("search_status", 'alpha') ?GETPOST("search_status", 'alpha') : GETPOST("status", 'alpha'); +$type = GETPOST("search_type", 'alpha') ?GETPOST("search_type", 'alpha') : GETPOST("type", 'alpha'); +$maxprint = ((GETPOST("maxprint", 'int') != '') ?GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW); +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index) if (GETPOST('search_actioncode', 'array')) { - $actioncode=GETPOST('search_actioncode', 'array', 3); - if (! count($actioncode)) $actioncode='0'; + $actioncode = GETPOST('search_actioncode', 'array', 3); + if (!count($actioncode)) $actioncode = '0'; } else { - $actioncode=GETPOST("search_actioncode", "alpha", 3)?GETPOST("search_actioncode", "alpha", 3):(GETPOST("search_actioncode", "alpha")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE)); + $actioncode = GETPOST("search_actioncode", "alpha", 3) ?GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode", "alpha") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE)); } -if ($actioncode == '' && empty($actioncodearray)) $actioncode=(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE); +if ($actioncode == '' && empty($actioncodearray)) $actioncode = (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE); -$dateselect=dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int')); +$dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int')); if ($dateselect > 0) { - $day=GETPOST('dateselectday', 'int'); - $month=GETPOST('dateselectmonth', 'int'); - $year=GETPOST('dateselectyear', 'int'); + $day = GETPOST('dateselectday', 'int'); + $month = GETPOST('dateselectmonth', 'int'); + $year = GETPOST('dateselectyear', 'int'); } -$tmp=empty($conf->global->MAIN_DEFAULT_WORKING_HOURS)?'9-18':$conf->global->MAIN_DEFAULT_WORKING_HOURS; -$tmp=str_replace(' ', '', $tmp); // FIX 7533 -$tmparray=explode('-', $tmp); -$begin_h = GETPOST('begin_h', 'int')!=''?GETPOST('begin_h', 'int'):($tmparray[0] != '' ? $tmparray[0] : 9); -$end_h = GETPOST('end_h', 'int')?GETPOST('end_h', 'int'):($tmparray[1] != '' ? $tmparray[1] : 18); +$tmp = empty($conf->global->MAIN_DEFAULT_WORKING_HOURS) ? '9-18' : $conf->global->MAIN_DEFAULT_WORKING_HOURS; +$tmp = str_replace(' ', '', $tmp); // FIX 7533 +$tmparray = explode('-', $tmp); +$begin_h = GETPOST('begin_h', 'int') != '' ?GETPOST('begin_h', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 9); +$end_h = GETPOST('end_h', 'int') ?GETPOST('end_h', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 18); if ($begin_h < 0 || $begin_h > 23) $begin_h = 9; if ($end_h < 1 || $end_h > 24) $end_h = 18; if ($end_h <= $begin_h) $end_h = $begin_h + 1; -$tmp=empty($conf->global->MAIN_DEFAULT_WORKING_DAYS)?'1-5':$conf->global->MAIN_DEFAULT_WORKING_DAYS; -$tmp=str_replace(' ', '', $tmp); // FIX 7533 -$tmparray=explode('-', $tmp); -$begin_d = GETPOST('begin_d', 'int')?GETPOST('begin_d', 'int'):($tmparray[0] != '' ? $tmparray[0] : 1); -$end_d = GETPOST('end_d', 'int')?GETPOST('end_d', 'int'):($tmparray[1] != '' ? $tmparray[1] : 5); +$tmp = empty($conf->global->MAIN_DEFAULT_WORKING_DAYS) ? '1-5' : $conf->global->MAIN_DEFAULT_WORKING_DAYS; +$tmp = str_replace(' ', '', $tmp); // FIX 7533 +$tmparray = explode('-', $tmp); +$begin_d = GETPOST('begin_d', 'int') ?GETPOST('begin_d', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 1); +$end_d = GETPOST('end_d', 'int') ?GETPOST('end_d', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 5); if ($begin_d < 1 || $begin_d > 7) $begin_d = 1; if ($end_d < 1 || $end_d > 7) $end_d = 7; if ($end_d < $begin_d) $end_d = $begin_d + 1; -if ($status == '' && ! isset($_GET['status']) && ! isset($_POST['status'])) $status=(empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS)?'':$conf->global->AGENDA_DEFAULT_FILTER_STATUS); -if (empty($action) && ! isset($_GET['action']) && ! isset($_POST['action'])) $action=(empty($conf->global->AGENDA_DEFAULT_VIEW)?'show_month':$conf->global->AGENDA_DEFAULT_VIEW); +if ($status == '' && !isset($_GET['status']) && !isset($_POST['status'])) $status = (empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS); +if (empty($action) && !isset($_GET['action']) && !isset($_POST['action'])) $action = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW); -if (GETPOST('viewcal', 'alpha') && $action != 'show_day' && $action != 'show_week' && $action != 'show_peruser') { - $action='show_month'; $day=''; +if (GETPOST('viewcal', 'alpha') && $action != 'show_day' && $action != 'show_week' && $action != 'show_peruser') { + $action = 'show_month'; $day = ''; } // View by month if (GETPOST('viewweek', 'alpha') || $action == 'show_week') { - $action='show_week'; $week=($week?$week:date("W")); $day=($day?$day:date("d")); + $action = 'show_week'; $week = ($week ? $week : date("W")); $day = ($day ? $day : date("d")); } // View by week -if (GETPOST('viewday', 'alpha') || $action == 'show_day') { - $action='show_day'; $day=($day?$day:date("d")); +if (GETPOST('viewday', 'alpha') || $action == 'show_day') { + $action = 'show_day'; $day = ($day ? $day : date("d")); } // View by day // Load translation files required by the page @@ -385,189 +385,189 @@ if ($conf->use_javascript_ajax) } -$newcardbutton=''; +$newcardbutton = ''; if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) { - $tmpforcreatebutton=dol_getdate(dol_now(), true); + $tmpforcreatebutton = dol_getdate(dol_now(), true); - $newparam.='&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year']; + $newparam .= '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year']; //$param='month='.$monthshown.'&year='.$year; - $hourminsec='100000'; - $newcardbutton.= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d", $tmpforcreatebutton['year'], $tmpforcreatebutton['mon'], $tmpforcreatebutton['mday']).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam?'?'.$newparam:''))); + $hourminsec = '100000'; + $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d", $tmpforcreatebutton['year'], $tmpforcreatebutton['mon'], $tmpforcreatebutton['mday']).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''))); } -$link=''; +$link = ''; print load_fiche_titre($s, $link.'     '.$nav.' '.$newcardbutton, ''); // Get event in an array -$eventarray=array(); +$eventarray = array(); $sql = 'SELECT'; -if ($usergroup > 0) $sql.=" DISTINCT"; -$sql.= ' a.id, a.label,'; -$sql.= ' a.datep,'; -$sql.= ' a.datep2,'; -$sql.= ' a.percent,'; -$sql.= ' a.fk_user_author,a.fk_user_action,'; -$sql.= ' a.transparency, a.priority, a.fulldayevent, a.location,'; -$sql.= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,'; -$sql.= ' ca.code, ca.color'; -$sql.= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a"; -if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; +if ($usergroup > 0) $sql .= " DISTINCT"; +$sql .= ' a.id, a.label,'; +$sql .= ' a.datep,'; +$sql .= ' a.datep2,'; +$sql .= ' a.percent,'; +$sql .= ' a.fk_user_author,a.fk_user_action,'; +$sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,'; +$sql .= ' a.fk_soc, a.fk_contact, a.fk_element, a.elementtype, a.fk_project,'; +$sql .= ' ca.code, ca.color'; +$sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a"; +if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; // We must filter on resource table -if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r"; +if ($resourceid > 0) $sql .= ", ".MAIN_DB_PREFIX."element_resources as r"; // We must filter on assignement table -if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; -if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; -$sql.= ' WHERE a.fk_action = ca.id'; -$sql.= ' AND a.entity IN ('.getEntity('agenda').')'; +if ($filtert > 0 || $usergroup > 0) $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; +if ($usergroup > 0) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; +$sql .= ' WHERE a.fk_action = ca.id'; +$sql .= ' AND a.entity IN ('.getEntity('agenda').')'; // Condition on actioncode -if (! empty($actioncode)) +if (!empty($actioncode)) { if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) { - if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'"; - elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'"; + if ($actioncode == 'AC_NON_AUTO') $sql .= " AND ca.type != 'systemauto'"; + elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND ca.type = 'systemauto'"; else { - if ($actioncode == 'AC_OTH') $sql.= " AND ca.type != 'systemauto'"; - if ($actioncode == 'AC_OTH_AUTO') $sql.= " AND ca.type = 'systemauto'"; + if ($actioncode == 'AC_OTH') $sql .= " AND ca.type != 'systemauto'"; + if ($actioncode == 'AC_OTH_AUTO') $sql .= " AND ca.type = 'systemauto'"; } } else { - if ($actioncode == 'AC_NON_AUTO') $sql.= " AND ca.type != 'systemauto'"; - elseif ($actioncode == 'AC_ALL_AUTO') $sql.= " AND ca.type = 'systemauto'"; + if ($actioncode == 'AC_NON_AUTO') $sql .= " AND ca.type != 'systemauto'"; + elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND ca.type = 'systemauto'"; else { if (is_array($actioncode)) { - $sql.=" AND ca.code IN ('".implode("','", $actioncode)."')"; + $sql .= " AND ca.code IN ('".implode("','", $actioncode)."')"; } else { - $sql.=" AND ca.code IN ('".implode("','", explode(',', $actioncode))."')"; + $sql .= " AND ca.code IN ('".implode("','", explode(',', $actioncode))."')"; } } } } -if ($resourceid > 0) $sql.=" AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid); -if ($pid) $sql.=" AND a.fk_project=".$db->escape($pid); -if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")"; -if ($socid > 0) $sql.= ' AND a.fk_soc = '.$socid; +if ($resourceid > 0) $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".$db->escape($resourceid); +if ($pid) $sql .= " AND a.fk_project=".$db->escape($pid); +if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".$user->id.")"; +if ($socid > 0) $sql .= ' AND a.fk_soc = '.$socid; // We must filter on assignement table -if ($filtert > 0 || $usergroup > 0) $sql.= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'"; +if ($filtert > 0 || $usergroup > 0) $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'"; if ($action == 'show_day') { - $sql.= " AND ("; - $sql.= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."'"; - $sql.= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."')"; - $sql.= " OR "; - $sql.= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."'"; - $sql.= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."')"; - $sql.= " OR "; - $sql.= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."'"; - $sql.= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."')"; - $sql.= ')'; + $sql .= " AND ("; + $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."'"; + $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."')"; + $sql .= " OR "; + $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."'"; + $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."')"; + $sql .= " OR "; + $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."'"; + $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."')"; + $sql .= ')'; } else { // To limit array - $sql.= " AND ("; - $sql.= " (a.datep BETWEEN '".$db->idate($firstdaytoshow-(60*60*24*2))."'"; // Start 2 day before $firstdaytoshow - $sql.= " AND '".$db->idate($lastdaytoshow+(60*60*24*2))."')"; // End 2 day after $lastdaytoshow - $sql.= " OR "; - $sql.= " (a.datep2 BETWEEN '".$db->idate($firstdaytoshow-(60*60*24*2))."'"; - $sql.= " AND '".$db->idate($lastdaytoshow+(60*60*24*2))."')"; - $sql.= " OR "; - $sql.= " (a.datep < '".$db->idate($firstdaytoshow-(60*60*24*2))."'"; - $sql.= " AND a.datep2 > '".$db->idate($lastdaytoshow+(60*60*24*2))."')"; - $sql.= ')'; + $sql .= " AND ("; + $sql .= " (a.datep BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'"; // Start 2 day before $firstdaytoshow + $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')"; // End 2 day after $lastdaytoshow + $sql .= " OR "; + $sql .= " (a.datep2 BETWEEN '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'"; + $sql .= " AND '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')"; + $sql .= " OR "; + $sql .= " (a.datep < '".$db->idate($firstdaytoshow - (60 * 60 * 24 * 2))."'"; + $sql .= " AND a.datep2 > '".$db->idate($lastdaytoshow + (60 * 60 * 24 * 2))."')"; + $sql .= ')'; } -if ($type) $sql.= " AND ca.id = ".$type; -if ($status == '0') { $sql.= " AND a.percent = 0"; } -if ($status == '-1') { $sql.= " AND a.percent = -1"; } // Not applicable -if ($status == '50') { $sql.= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started -if ($status == 'done' || $status == '100') { $sql.= " AND (a.percent = 100)"; } -if ($status == 'todo') { $sql.= " AND (a.percent >= 0 AND a.percent < 100)"; } +if ($type) $sql .= " AND ca.id = ".$type; +if ($status == '0') { $sql .= " AND a.percent = 0"; } +if ($status == '-1') { $sql .= " AND a.percent = -1"; } // Not applicable +if ($status == '50') { $sql .= " AND (a.percent > 0 AND a.percent < 100)"; } // Running already started +if ($status == 'done' || $status == '100') { $sql .= " AND (a.percent = 100)"; } +if ($status == 'todo') { $sql .= " AND (a.percent >= 0 AND a.percent < 100)"; } // We must filter on assignement table if ($filtert > 0 || $usergroup > 0) { - $sql.= " AND ("; - if ($filtert > 0) $sql.= "ar.fk_element = ".$filtert; - if ($usergroup > 0) $sql.= ($filtert>0?" OR ":"")." ugu.fk_usergroup = ".$usergroup; - $sql.= ")"; + $sql .= " AND ("; + if ($filtert > 0) $sql .= "ar.fk_element = ".$filtert; + if ($usergroup > 0) $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".$usergroup; + $sql .= ")"; } // Sort on date -$sql.= ' ORDER BY fk_user_action, datep'; //fk_user_action +$sql .= ' ORDER BY fk_user_action, datep'; //fk_user_action dol_syslog("comm/action/peruser.php", LOG_DEBUG); -$resql=$db->query($sql); +$resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); - $i=0; + $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); // Discard auto action if option is on - if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code == 'AC_OTH_AUTO') + if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->code == 'AC_OTH_AUTO') { $i++; continue; } - $datep=$db->jdate($obj->datep); - $datep2=$db->jdate($obj->datep2); + $datep = $db->jdate($obj->datep); + $datep2 = $db->jdate($obj->datep2); // Create a new object action - $event=new ActionComm($db); - $event->id=$obj->id; - $event->datep=$datep; // datep and datef are GMT date - $event->datef=$datep2; - $event->type_code=$obj->code; - $event->type_color=$obj->color; - $event->label=$obj->label; - $event->percentage=$obj->percent; - $event->authorid=$obj->fk_user_author; // user id of creator - $event->userownerid=$obj->fk_user_action; // user id of owner - $event->priority=$obj->priority; - $event->fulldayevent=$obj->fulldayevent; - $event->location=$obj->location; - $event->transparency=$obj->transparency; + $event = new ActionComm($db); + $event->id = $obj->id; + $event->datep = $datep; // datep and datef are GMT date + $event->datef = $datep2; + $event->type_code = $obj->code; + $event->type_color = $obj->color; + $event->label = $obj->label; + $event->percentage = $obj->percent; + $event->authorid = $obj->fk_user_author; // user id of creator + $event->userownerid = $obj->fk_user_action; // user id of owner + $event->priority = $obj->priority; + $event->fulldayevent = $obj->fulldayevent; + $event->location = $obj->location; + $event->transparency = $obj->transparency; - $event->fk_project=$obj->fk_project; + $event->fk_project = $obj->fk_project; - $event->socid=$obj->fk_soc; - $event->contactid=$obj->fk_contact; + $event->socid = $obj->fk_soc; + $event->contactid = $obj->fk_contact; - $event->fk_element=$obj->fk_element; - $event->elementtype=$obj->elementtype; + $event->fk_element = $obj->fk_element; + $event->elementtype = $obj->elementtype; // Defined date_start_in_calendar and date_end_in_calendar property // They are date start and end of action but modified to not be outside calendar view. if ($event->percentage <= 0) { - $event->date_start_in_calendar=$datep; - if ($datep2 != '' && $datep2 >= $datep) $event->date_end_in_calendar=$datep2; - else $event->date_end_in_calendar=$datep; + $event->date_start_in_calendar = $datep; + if ($datep2 != '' && $datep2 >= $datep) $event->date_end_in_calendar = $datep2; + else $event->date_end_in_calendar = $datep; } else { - $event->date_start_in_calendar=$datep; - if ($datep2 != '' && $datep2 >= $datep) $event->date_end_in_calendar=$datep2; - else $event->date_end_in_calendar=$datep; + $event->date_start_in_calendar = $datep; + if ($datep2 != '' && $datep2 >= $datep) $event->date_end_in_calendar = $datep2; + else $event->date_end_in_calendar = $datep; } // Define ponctual property if ($event->date_start_in_calendar == $event->date_end_in_calendar) { - $event->ponctuel=1; + $event->ponctuel = 1; } // Check values @@ -655,12 +655,12 @@ echo ''; $currentdaytoshow = $firstdaytoshow; echo '
'; -while($currentdaytoshow<$lastdaytoshow) { +while ($currentdaytoshow < $lastdaytoshow) { echo '
'; echo ''; echo ''; - $i=0; // 0 = sunday, + $i = 0; // 0 = sunday, while ($i < 7) { if (($i + 1) < $begin_d || ($i + 1) > $end_d) @@ -712,10 +712,10 @@ while($currentdaytoshow<$lastdaytoshow) { foreach ($eventarray[$daykey] as $index => $event) { $event->fetch_userassigned(); - $listofuserid=$event->userassigned; - foreach($listofuserid as $userid => $tmp) + $listofuserid = $event->userassigned; + foreach ($listofuserid as $userid => $tmp) { - if (! in_array($userid, $usernamesid)) $usernamesid[$userid] = $userid; + if (!in_array($userid, $usernamesid)) $usernamesid[$userid] = $userid; } } } @@ -775,26 +775,26 @@ while($currentdaytoshow<$lastdaytoshow) { }*/ // Load array of colors by type - $colorsbytype=array(); - $labelbytype=array(); - $sql="SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position"; - $resql=$db->query($sql); + $colorsbytype = array(); + $labelbytype = array(); + $sql = "SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position"; + $resql = $db->query($sql); while ($obj = $db->fetch_object($resql)) { - $colorsbytype[$obj->code]=$obj->color; - $labelbytype[$obj->code]=$obj->label; + $colorsbytype[$obj->code] = $obj->color; + $labelbytype[$obj->code] = $obj->label; } // Loop on each user to show calendar - $todayarray=dol_getdate($now, 'fast'); + $todayarray = dol_getdate($now, 'fast'); $sav = $tmpday; $showheader = true; $var = false; foreach ($usernames as $username) { - $var = ! $var; + $var = !$var; echo ""; - echo ''; $tmpday = $sav; @@ -1059,210 +1059,210 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & { $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, false, 0); $b = dol_mktime((int) $h, 30, 0, $month, $day, $year, false, 0); - $c = dol_mktime((int) $h+1, 0, 0, $month, $day, $year, false, 0); + $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, false, 0); - $dateendtouse=$event->date_end_in_calendar; - if ($dateendtouse==$event->date_start_in_calendar) $dateendtouse++; + $dateendtouse = $event->date_end_in_calendar; + if ($dateendtouse == $event->date_start_in_calendar) $dateendtouse++; //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'
'; if ($event->date_start_in_calendar < $b && $dateendtouse > $a) { - $busy=$event->transparency; - $cases1[$h][$event->id]['busy']=$busy; - $cases1[$h][$event->id]['string']=dol_print_date($event->date_start_in_calendar, 'dayhour'); + $busy = $event->transparency; + $cases1[$h][$event->id]['busy'] = $busy; + $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour'); if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) { - $tmpa=dol_getdate($event->date_start_in_calendar, true); - $tmpb=dol_getdate($event->date_end_in_calendar, true); - if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $cases1[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar, 'hour'); - else $cases1[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar, 'dayhour'); + $tmpa = dol_getdate($event->date_start_in_calendar, true); + $tmpb = dol_getdate($event->date_end_in_calendar, true); + if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour'); + else $cases1[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour'); } - if ($event->label) $cases1[$h][$event->id]['string'].=' - '.$event->label; - $cases1[$h][$event->id]['typecode']=$event->type_code; - $cases1[$h][$event->id]['color']=$color; + if ($event->label) $cases1[$h][$event->id]['string'] .= ' - '.$event->label; + $cases1[$h][$event->id]['typecode'] = $event->type_code; + $cases1[$h][$event->id]['color'] = $color; if ($event->fk_project > 0) { if (empty($cacheprojects[$event->fk_project])) { - $tmpproj=new Project($db); + $tmpproj = new Project($db); $tmpproj->fetch($event->fk_project); - $cacheprojects[$event->fk_project]=$tmpproj; + $cacheprojects[$event->fk_project] = $tmpproj; } - $cases1[$h][$event->id]['string'].=', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title; + $cases1[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title; } if ($event->socid > 0) { if (empty($cachethirdparties[$event->socid])) { - $tmpthirdparty=new Societe($db); + $tmpthirdparty = new Societe($db); $tmpthirdparty->fetch($event->socid); - $cachethirdparties[$event->socid]=$tmpthirdparty; + $cachethirdparties[$event->socid] = $tmpthirdparty; } - $cases1[$h][$event->id]['string'].=', '.$cachethirdparties[$event->socid]->name; + $cases1[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name; } if ($event->contactid > 0) { if (empty($cachecontacts[$event->contactid])) { - $tmpcontact=new Contact($db); + $tmpcontact = new Contact($db); $tmpcontact->fetch($event->contactid); - $cachecontacts[$event->contactid]=$tmpcontact; + $cachecontacts[$event->contactid] = $tmpcontact; } - $cases1[$h][$event->id]['string'].=', '.$cachecontacts[$event->contactid]->getFullName($langs); + $cases1[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contactid]->getFullName($langs); } } if ($event->date_start_in_calendar < $c && $dateendtouse > $b) { - $busy=$event->transparency; - $cases2[$h][$event->id]['busy']=$busy; - $cases2[$h][$event->id]['string']=dol_print_date($event->date_start_in_calendar, 'dayhour'); + $busy = $event->transparency; + $cases2[$h][$event->id]['busy'] = $busy; + $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour'); if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) { - $tmpa=dol_getdate($event->date_start_in_calendar, true); - $tmpb=dol_getdate($event->date_end_in_calendar, true); - if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $cases2[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar, 'hour'); - else $cases2[$h][$event->id]['string'].='-'.dol_print_date($event->date_end_in_calendar, 'dayhour'); + $tmpa = dol_getdate($event->date_start_in_calendar, true); + $tmpb = dol_getdate($event->date_end_in_calendar, true); + if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'hour'); + else $cases2[$h][$event->id]['string'] .= '-'.dol_print_date($event->date_end_in_calendar, 'dayhour'); } - if ($event->label) $cases2[$h][$event->id]['string'].=' - '.$event->label; - $cases2[$h][$event->id]['typecode']=$event->type_code; - $cases2[$h][$event->id]['color']=$color; + if ($event->label) $cases2[$h][$event->id]['string'] .= ' - '.$event->label; + $cases2[$h][$event->id]['typecode'] = $event->type_code; + $cases2[$h][$event->id]['color'] = $color; if ($event->fk_project > 0) { if (empty($cacheprojects[$event->fk_project])) { - $tmpproj=new Project($db); + $tmpproj = new Project($db); $tmpproj->fetch($event->fk_project); - $cacheprojects[$event->fk_project]=$tmpproj; + $cacheprojects[$event->fk_project] = $tmpproj; } - $cases2[$h][$event->id]['string'].=', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title; + $cases2[$h][$event->id]['string'] .= ', '.$langs->trans("Project").': '.$cacheprojects[$event->fk_project]->ref.' - '.$cacheprojects[$event->fk_project]->title; } if ($event->socid > 0) { if (empty($cachethirdparties[$event->socid])) { - $tmpthirdparty=new Societe($db); + $tmpthirdparty = new Societe($db); $tmpthirdparty->fetch($event->socid); - $cachethirdparties[$event->socid]=$tmpthirdparty; + $cachethirdparties[$event->socid] = $tmpthirdparty; } - $cases2[$h][$event->id]['string'].=', '.$cachethirdparties[$event->socid]->name; + $cases2[$h][$event->id]['string'] .= ', '.$cachethirdparties[$event->socid]->name; } if ($event->contactid > 0) { if (empty($cachecontacts[$event->contactid])) { - $tmpcontact=new Contact($db); + $tmpcontact = new Contact($db); $tmpcontact->fetch($event->contactid); - $cachecontacts[$event->contactid]=$tmpcontact; + $cachecontacts[$event->contactid] = $tmpcontact; } - $cases2[$h][$event->id]['string'].=', '.$cachecontacts[$event->contactid]->getFullName($langs); + $cases2[$h][$event->id]['string'] .= ', '.$cachecontacts[$event->contactid]->getFullName($langs); } } } else { - $busy=$event->transparency; - $cases1[$h][$event->id]['busy']=$busy; - $cases2[$h][$event->id]['busy']=$busy; - $cases1[$h][$event->id]['string']=$event->label; - $cases2[$h][$event->id]['string']=$event->label; - $cases1[$h][$event->id]['typecode']=$event->type_code; - $cases2[$h][$event->id]['typecode']=$event->type_code; - $cases1[$h][$event->id]['color']=$color; - $cases2[$h][$event->id]['color']=$color; + $busy = $event->transparency; + $cases1[$h][$event->id]['busy'] = $busy; + $cases2[$h][$event->id]['busy'] = $busy; + $cases1[$h][$event->id]['string'] = $event->label; + $cases2[$h][$event->id]['string'] = $event->label; + $cases1[$h][$event->id]['typecode'] = $event->type_code; + $cases2[$h][$event->id]['typecode'] = $event->type_code; + $cases1[$h][$event->id]['color'] = $color; + $cases2[$h][$event->id]['color'] = $color; } } $i++; } - break; // We found the date we were looking for. No need to search anymore. + break; // We found the date we were looking for. No need to search anymore. } } // Now output $casesX for ($h = $begin_h; $h < $end_h; $h++) { - $color1='';$color2=''; - $style1='';$style2=''; - $string1=' ';$string2=' '; - $title1='';$title2=''; + $color1 = ''; $color2 = ''; + $style1 = ''; $style2 = ''; + $string1 = ' '; $string2 = ' '; + $title1 = ''; $title2 = ''; if (isset($cases1[$h]) && $cases1[$h] != '') { //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events")); - if (count($cases1[$h]) > 1) $title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events")); - $string1=' '; - if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style1='peruser_notbusy'; - else $style1='peruser_busy'; - foreach($cases1[$h] as $id => $ev) + if (count($cases1[$h]) > 1) $title1 .= count($cases1[$h]).' '.(count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events")); + $string1 = ' '; + if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style1 = 'peruser_notbusy'; + else $style1 = 'peruser_busy'; + foreach ($cases1[$h] as $id => $ev) { - if ($ev['busy']) $style1='peruser_busy'; + if ($ev['busy']) $style1 = 'peruser_busy'; } } if (isset($cases2[$h]) && $cases2[$h] != '') { //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events")); - if (count($cases2[$h]) > 1) $title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events")); - $string2=' '; - if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style2='peruser_notbusy'; - else $style2='peruser_busy'; - foreach($cases2[$h] as $id => $ev) + if (count($cases2[$h]) > 1) $title2 .= count($cases2[$h]).' '.(count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events")); + $string2 = ' '; + if (empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) $style2 = 'peruser_notbusy'; + else $style2 = 'peruser_busy'; + foreach ($cases2[$h] as $id => $ev) { - if ($ev['busy']) $style2='peruser_busy'; + if ($ev['busy']) $style2 = 'peruser_busy'; } } - $ids1=''; - $ids2=''; - if (is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) $ids1=join(',', array_keys($cases1[$h])); - if (is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) $ids2=join(',', array_keys($cases2[$h])); + $ids1 = ''; + $ids2 = ''; + if (is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) $ids1 = join(',', array_keys($cases1[$h])); + if (is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) $ids2 = join(',', array_keys($cases2[$h])); - if ($h == $begin_h) echo ''; // Payment type (VIR, LIQ, ...) -$labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->type_label; +$labeltype = $langs->trans("PaymentType".$object->type_code) != ("PaymentType".$object->type_code) ? $langs->trans("PaymentType".$object->type_code) : $object->type_label; print ''; // Amount @@ -230,9 +230,9 @@ print ''; print ''; print ''; @@ -275,7 +275,7 @@ print ''; */ // Bank account -if (! empty($conf->banque->enabled)) +if (!empty($conf->banque->enabled)) { if ($object->fk_account > 0) { @@ -319,12 +319,12 @@ dol_fiche_end(); */ $sql = 'SELECT f.rowid as facid, f.ref, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, s.nom as name, s.rowid as socid'; -$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s'; -$sql.= ' WHERE pf.fk_facture = f.rowid'; -$sql.= ' AND f.fk_soc = s.rowid'; -$sql.= ' AND f.entity IN ('.getEntity('invoice').')'; -$sql.= ' AND pf.fk_paiement = '.$object->id; -$resql=$db->query($sql); +$sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s'; +$sql .= ' WHERE pf.fk_facture = f.rowid'; +$sql .= ' AND f.fk_soc = s.rowid'; +$sql .= ' AND f.entity IN ('.getEntity('invoice').')'; +$sql .= ' AND pf.fk_paiement = '.$object->id; +$resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -332,7 +332,7 @@ if ($resql) $i = 0; $total = 0; - $moreforfilter=''; + $moreforfilter = ''; print '
'; @@ -342,7 +342,7 @@ if ($resql) print ''; print ''; print ''; - if($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED )print ''; + if ($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED)print ''; print ''; print ''; print ''; @@ -357,14 +357,14 @@ if ($resql) $thirdpartystatic->fetch($objp->socid); - $invoice=new Facture($db); + $invoice = new Facture($db); $invoice->fetch($objp->facid); $paiement = $invoice->getSommePaiement(); - $creditnotes=$invoice->getSumCreditNotesUsed(); - $deposits=$invoice->getSumDepositsUsed(); - $alreadypayed=price2num($paiement + $creditnotes + $deposits, 'MT'); - $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT'); + $creditnotes = $invoice->getSumCreditNotesUsed(); + $deposits = $invoice->getSumDepositsUsed(); + $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT'); + $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT'); print ''; @@ -379,7 +379,7 @@ if ($resql) print ''; // Expected to pay - if($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED ){ + if ($conf->global->MULTICOMPANY_INVOICE_SHARING_ENABLED) { print '
'; + echo ''; print $username->getNomUrl(-1, '', 0, 0, 20, 1, ''); print ''; - else echo ''; + if ($h == $begin_h) echo ''; + else echo ''; if (is_array($cases1[$h]) && count($cases1[$h]) == 1) // only 1 event { $output = array_slice($cases1[$h], 0, 1); - $title1=$langs->trans("Ref").' '.$ids1.($title1?' - '.$title1:''); - if ($output[0]['string']) $title1.=($title1?' - ':'').$output[0]['string']; + $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : ''); + if ($output[0]['string']) $title1 .= ($title1 ? ' - ' : '').$output[0]['string']; if ($output[0]['color']) $color1 = $output[0]['color']; } elseif (is_array($cases1[$h]) && count($cases1[$h]) > 1) { - $title1=$langs->trans("Ref").' '.$ids1.($title1?' - '.$title1:''); - $color1='222222'; + $title1 = $langs->trans("Ref").' '.$ids1.($title1 ? ' - '.$title1 : ''); + $color1 = '222222'; } if (is_array($cases2[$h]) && count($cases2[$h]) == 1) // only 1 event { $output = array_slice($cases2[$h], 0, 1); - $title2=$langs->trans("Ref").' '.$ids2.($title2?' - '.$title2:''); - if ($output[0]['string']) $title2.=($title2?' - ':'').$output[0]['string']; + $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : ''); + if ($output[0]['string']) $title2 .= ($title2 ? ' - ' : '').$output[0]['string']; if ($output[0]['color']) $color2 = $output[0]['color']; } elseif (is_array($cases2[$h]) && count($cases2[$h]) > 1) { - $title2=$langs->trans("Ref").' '.$ids2.($title2?' - '.$title2:''); - $color2='222222'; + $title2 = $langs->trans("Ref").' '.$ids2.($title2 ? ' - '.$title2 : ''); + $color2 = '222222'; } print ''; print ''; print '
'; + print ($style1 ? $style1.' ' : ''); + print 'onclickopenref'.($title1 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_00_'.($ids1 ? $ids1 : 'none').'"'.($title1 ? ' title="'.$title1.'"' : '').'>'; print $string1; print ''; + print ($style2 ? $style2.' ' : ''); + print 'onclickopenref'.($title1 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_30_'.($ids2 ? $ids2 : 'none').'"'.($title2 ? ' title="'.$title2.'"' : '').'>'; print $string2; print '
'; diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 4e0cfa2f2dc..3ce6d2f00fa 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -37,33 +37,33 @@ require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; -if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; -if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; -if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; -if (! empty($conf->expedition->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; -if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; -if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; -if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; +if (!empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +if (!empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; +if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; +if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; +if (!empty($conf->expedition->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; +if (!empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; +if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; +if (!empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; // Load translation files required by the page $langs->loadLangs(array('companies', 'banks')); -if (! empty($conf->contrat->enabled)) $langs->load("contracts"); -if (! empty($conf->commande->enabled)) $langs->load("orders"); -if (! empty($conf->expedition->enabled)) $langs->load("sendings"); -if (! empty($conf->facture->enabled)) $langs->load("bills"); -if (! empty($conf->projet->enabled)) $langs->load("projects"); -if (! empty($conf->ficheinter->enabled)) $langs->load("interventions"); -if (! empty($conf->notification->enabled)) $langs->load("mails"); +if (!empty($conf->contrat->enabled)) $langs->load("contracts"); +if (!empty($conf->commande->enabled)) $langs->load("orders"); +if (!empty($conf->expedition->enabled)) $langs->load("sendings"); +if (!empty($conf->facture->enabled)) $langs->load("bills"); +if (!empty($conf->projet->enabled)) $langs->load("projects"); +if (!empty($conf->ficheinter->enabled)) $langs->load("interventions"); +if (!empty($conf->notification->enabled)) $langs->load("mails"); // Security check $id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int')); -if ($user->socid > 0) $id=$user->socid; +if ($user->socid > 0) $id = $user->socid; $result = restrictedArea($user, 'societe', $id, '&societe'); -$action = GETPOST('action', 'aZ09'); -$mode = GETPOST("mode"); +$action = GETPOST('action', 'aZ09'); +$mode = GETPOST("mode"); $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); @@ -240,7 +240,7 @@ if ($object->id > 0) $linkback = ''.$langs->trans("BackToList").''; - dol_banner_tab($object, 'socid', $linkback, ($user->socid?0:1), 'rowid', 'nom'); + dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); print '
'; @@ -1293,11 +1293,11 @@ if ($object->id > 0) $langs->load("bills"); $langs->load("orders"); - if (! empty($conf->commande->enabled)) + if (!empty($conf->commande->enabled)) { if ($object->client != 0 && $object->client != 2) { - if (! empty($orders2invoice) && $orders2invoice > 0) print ''; + if (!empty($orders2invoice) && $orders2invoice > 0) print ''; else print ''; } else print ''; diff --git a/htdocs/comm/mailing/info.php b/htdocs/comm/mailing/info.php index 2291f04d0fb..3dfe0c4264c 100644 --- a/htdocs/comm/mailing/info.php +++ b/htdocs/comm/mailing/info.php @@ -23,17 +23,17 @@ */ require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT .'/comm/mailing/class/mailing.class.php'; +require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php'; -$id=GETPOST('id'); +$id = GETPOST('id'); // Load translation files required by the page $langs->load("mails"); // Security check -if (! $user->rights->mailing->lire || $user->socid > 0) +if (!$user->rights->mailing->lire || $user->socid > 0) accessforbidden(); @@ -56,16 +56,16 @@ if ($object->fetch($id) >= 0) $linkback = ''.$langs->trans("BackToList").''; - $morehtmlright=''; + $morehtmlright = ''; $nbtry = $nbok = 0; if ($object->statut == 2 || $object->statut == 3) { $nbtry = $object->countNbOfTargets('alreadysent'); $nbko = $object->countNbOfTargets('alreadysentko'); - $morehtmlright.=' ('.$nbtry.'/'.$object->nbemail; - if ($nbko) $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error"); - $morehtmlright.=')   '; + $morehtmlright .= ' ('.$nbtry.'/'.$object->nbemail; + if ($nbko) $morehtmlright .= ' - '.$nbko.' '.$langs->trans("Error"); + $morehtmlright .= ')   '; } dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright); @@ -73,10 +73,10 @@ if ($object->fetch($id) >= 0) print '

'; //print '
'; - $object->user_creation=$object->user_creat; - $object->date_creation=$object->date_creat; - $object->user_validation=$object->user_valid; - $object->date_validation=$object->date_valid; + $object->user_creation = $object->user_creat; + $object->date_creation = $object->date_creat; + $object->user_validation = $object->user_valid; + $object->date_validation = $object->date_valid; dol_print_object_info($object, 0); //print '
'; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index d421e7bc344..c249a6a7b5f 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -772,8 +772,8 @@ class Propal extends CommonObject $this->line->rang = $rangmax + 1; } - $this->line->id = $rowid; - $this->line->label = $label; + $this->line->id = $rowid; + $this->line->label = $label; $this->line->desc = $desc; $this->line->qty = $qty; $this->line->product_type = $type; @@ -1544,7 +1544,7 @@ class Propal extends CommonObject if (isset($this->note_public)) $this->note_public = trim($this->note_public); if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf); if (isset($this->import_key)) $this->import_key = trim($this->import_key); - if (! empty($this->duree_validite)) $this->fin_validite=$this->date + ($this->duree_validite * 24 * 3600); + if (!empty($this->duree_validite)) $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600); // Check parameters // Put here code to add control on parameters values @@ -1557,7 +1557,7 @@ class Propal extends CommonObject $sql .= " ref_ext=".(isset($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").","; $sql .= " fk_soc=".(isset($this->socid) ? $this->socid : "null").","; $sql .= " datep=".(strval($this->date) != '' ? "'".$this->db->idate($this->date)."'" : 'null').","; - if (! empty($this->fin_validite)) $sql .= " fin_validite=".(strval($this->fin_validite)!='' ? "'".$this->db->idate($this->fin_validite)."'" : 'null').","; + if (!empty($this->fin_validite)) $sql .= " fin_validite=".(strval($this->fin_validite) != '' ? "'".$this->db->idate($this->fin_validite)."'" : 'null').","; $sql .= " date_valid=".(strval($this->date_validation) != '' ? "'".$this->db->idate($this->date_validation)."'" : 'null').","; $sql .= " tva=".(isset($this->total_tva) ? $this->total_tva : "null").","; $sql .= " localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 : "null").","; @@ -1700,25 +1700,25 @@ class Propal extends CommonObject $line->fk_product = $objp->fk_product; - $line->ref = $objp->product_ref; // deprecated - $line->product_ref = $objp->product_ref; - $line->libelle = $objp->product_label; // deprecated - $line->product_label = $objp->product_label; - $line->product_desc = $objp->product_desc; // Description produit + $line->ref = $objp->product_ref; // deprecated + $line->product_ref = $objp->product_ref; + $line->libelle = $objp->product_label; // deprecated + $line->product_label = $objp->product_label; + $line->product_desc = $objp->product_desc; // Description produit $line->product_tobatch = $objp->product_tobatch; - $line->fk_product_type = $objp->fk_product_type; // deprecated + $line->fk_product_type = $objp->fk_product_type; // deprecated $line->fk_unit = $objp->fk_unit; $line->weight = $objp->weight; $line->weight_units = $objp->weight_units; $line->volume = $objp->volume; $line->volume_units = $objp->volume_units; - $line->date_start = $this->db->jdate($objp->date_start); - $line->date_end = $this->db->jdate($objp->date_end); + $line->date_start = $this->db->jdate($objp->date_start); + $line->date_end = $this->db->jdate($objp->date_end); // Multicurrency - $line->fk_multicurrency = $objp->fk_multicurrency; - $line->multicurrency_code = $objp->multicurrency_code; + $line->fk_multicurrency = $objp->fk_multicurrency; + $line->multicurrency_code = $objp->multicurrency_code; $line->multicurrency_subprice = $objp->multicurrency_subprice; $line->multicurrency_total_ht = $objp->multicurrency_total_ht; $line->multicurrency_total_tva = $objp->multicurrency_total_tva; @@ -3228,24 +3228,24 @@ class Propal extends CommonObject { global $langs; $langs->load("propal"); - $this->labelStatus[0]=$langs->trans("PropalStatusDraft"); - $this->labelStatus[1]=$langs->trans("PropalStatusValidated"); - $this->labelStatus[2]=$langs->trans("PropalStatusSigned"); - $this->labelStatus[3]=$langs->trans("PropalStatusNotSigned"); - $this->labelStatus[4]=$langs->trans("PropalStatusBilled"); - $this->labelStatusShort[0]=$langs->trans("PropalStatusDraftShort"); - $this->labelStatusShort[1]=$langs->trans("PropalStatusValidatedShort"); - $this->labelStatusShort[2]=$langs->trans("PropalStatusSignedShort"); - $this->labelStatusShort[3]=$langs->trans("PropalStatusNotSignedShort"); - $this->labelStatusShort[4]=$langs->trans("PropalStatusBilledShort"); + $this->labelStatus[0] = $langs->trans("PropalStatusDraft"); + $this->labelStatus[1] = $langs->trans("PropalStatusValidated"); + $this->labelStatus[2] = $langs->trans("PropalStatusSigned"); + $this->labelStatus[3] = $langs->trans("PropalStatusNotSigned"); + $this->labelStatus[4] = $langs->trans("PropalStatusBilled"); + $this->labelStatusShort[0] = $langs->trans("PropalStatusDraftShort"); + $this->labelStatusShort[1] = $langs->trans("PropalStatusValidatedShort"); + $this->labelStatusShort[2] = $langs->trans("PropalStatusSignedShort"); + $this->labelStatusShort[3] = $langs->trans("PropalStatusNotSignedShort"); + $this->labelStatusShort[4] = $langs->trans("PropalStatusBilledShort"); } - $statusType=''; - if ($status==self::STATUS_DRAFT) $statusType='status0'; - elseif ($status==self::STATUS_VALIDATED) $statusType='status1'; - elseif ($status==self::STATUS_SIGNED) $statusType='status3'; - elseif ($status==self::STATUS_NOTSIGNED) $statusType='status5'; - elseif ($status==self::STATUS_BILLED) $statusType='status6'; + $statusType = ''; + if ($status == self::STATUS_DRAFT) $statusType = 'status0'; + elseif ($status == self::STATUS_VALIDATED) $statusType = 'status1'; + elseif ($status == self::STATUS_SIGNED) $statusType = 'status3'; + elseif ($status == self::STATUS_NOTSIGNED) $statusType = 'status5'; + elseif ($status == self::STATUS_BILLED) $statusType = 'status6'; return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); } @@ -3267,42 +3267,42 @@ class Propal extends CommonObject $clause = " WHERE"; $sql = "SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin, p.total_ht"; - $sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$user->socid) { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc"; - $sql.= " WHERE sc.fk_user = " .$user->id; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc"; + $sql .= " WHERE sc.fk_user = ".$user->id; $clause = " AND"; } - $sql.= $clause." p.entity IN (".getEntity('propal').")"; - if ($mode == 'opened') $sql.= " AND p.fk_statut = ".self::STATUS_VALIDATED; - if ($mode == 'signed') $sql.= " AND p.fk_statut = ".self::STATUS_SIGNED; - if ($user->socid) $sql.= " AND p.fk_soc = ".$user->socid; + $sql .= $clause." p.entity IN (".getEntity('propal').")"; + if ($mode == 'opened') $sql .= " AND p.fk_statut = ".self::STATUS_VALIDATED; + if ($mode == 'signed') $sql .= " AND p.fk_statut = ".self::STATUS_SIGNED; + if ($user->socid) $sql .= " AND p.fk_soc = ".$user->socid; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $langs->load("propal"); - $now=dol_now(); + $now = dol_now(); $delay_warning = 0; $status = 0; $label = $labelShort = ''; if ($mode == 'opened') { - $delay_warning=$conf->propal->cloture->warning_delay; + $delay_warning = $conf->propal->cloture->warning_delay; $status = self::STATUS_VALIDATED; $label = $langs->trans("PropalsToClose"); $labelShort = $langs->trans("ToAcceptRefuse"); } if ($mode == 'signed') { - $delay_warning=$conf->propal->facturation->warning_delay; + $delay_warning = $conf->propal->facturation->warning_delay; $status = self::STATUS_SIGNED; - $label = $langs->trans("PropalsToBill"); // We set here bill but may be billed or ordered + $label = $langs->trans("PropalsToBill"); // We set here bill but may be billed or ordered $labelShort = $langs->trans("ToBill"); } $response = new WorkboardResponse(); - $response->warning_delay = $delay_warning/60/60/24; + $response->warning_delay = $delay_warning / 60 / 60 / 24; $response->label = $label; $response->labelShort = $labelShort; $response->url = DOL_URL_ROOT.'/comm/propal/list.php?viewstatut='.$status.'&mainmenu=commercial&leftmenu=propals'; @@ -3441,27 +3441,27 @@ class Propal extends CommonObject // phpcs:enable global $user; - $this->nb=array(); + $this->nb = array(); $clause = "WHERE"; $sql = "SELECT count(p.rowid) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid"; if (!$user->rights->societe->client->voir && !$user->socid) { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; - $sql.= " WHERE sc.fk_user = " .$user->id; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; + $sql .= " WHERE sc.fk_user = ".$user->id; $clause = "AND"; } - $sql.= " ".$clause." p.entity IN (".getEntity('propal').")"; + $sql .= " ".$clause." p.entity IN (".getEntity('propal').")"; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { // This assignment in condition is not a bug. It allows walking the results. - while ($obj=$this->db->fetch_object($resql)) + while ($obj = $this->db->fetch_object($resql)) { - $this->nb["proposals"]=$obj->nb; + $this->nb["proposals"] = $obj->nb; } $this->db->free($resql); return 1; diff --git a/htdocs/compta/facture/admin/facture_cust_extrafields.php b/htdocs/compta/facture/admin/facture_cust_extrafields.php index c9d4d906280..55d4141fc07 100644 --- a/htdocs/compta/facture/admin/facture_cust_extrafields.php +++ b/htdocs/compta/facture/admin/facture_cust_extrafields.php @@ -36,13 +36,13 @@ $extrafields = new ExtraFields($db); $form = new Form($db); // List of supported format -$tmptype2label=ExtraFields::$type2label; -$type2label=array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val); +$tmptype2label = ExtraFields::$type2label; +$type2label = array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); -$action=GETPOST('action', 'alpha'); -$attrname=GETPOST('attrname', 'alpha'); -$elementtype='facture'; //Must be the $table_element of the class that manage extrafield +$action = GETPOST('action', 'alpha'); +$attrname = GETPOST('attrname', 'alpha'); +$elementtype = 'facture'; //Must be the $table_element of the class that manage extrafield if (!$user->admin) accessforbidden(); @@ -59,11 +59,11 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; * View */ -$textobject=strtolower($langs->transnoentitiesnoconv("BillsCustomers")); +$textobject = strtolower($langs->transnoentitiesnoconv("BillsCustomers")); llxHeader('', $langs->trans("BillsSetup")); -$linkback=''.$langs->trans("BackToModuleList").''; +$linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup'); @@ -104,7 +104,7 @@ if ($action == 'create') * Edition of an optional field * */ -if ($action == 'edit' && ! empty($attrname)) +if ($action == 'edit' && !empty($attrname)) { $langs->load("members"); diff --git a/htdocs/compta/facture/admin/facture_rec_cust_extrafields.php b/htdocs/compta/facture/admin/facture_rec_cust_extrafields.php index 08a2280ff1c..feeca2046d6 100644 --- a/htdocs/compta/facture/admin/facture_rec_cust_extrafields.php +++ b/htdocs/compta/facture/admin/facture_rec_cust_extrafields.php @@ -37,13 +37,13 @@ $extrafields = new ExtraFields($db); $form = new Form($db); // List of supported format -$tmptype2label=ExtraFields::$type2label; -$type2label=array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val); +$tmptype2label = ExtraFields::$type2label; +$type2label = array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); -$action=GETPOST('action', 'alpha'); -$attrname=GETPOST('attrname', 'alpha'); -$elementtype='facture_rec'; //Must be the $table_element of the class that manage extrafield +$action = GETPOST('action', 'alpha'); +$attrname = GETPOST('attrname', 'alpha'); +$elementtype = 'facture_rec'; //Must be the $table_element of the class that manage extrafield if (!$user->admin) accessforbidden(); @@ -60,11 +60,11 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; * View */ -$textobject=strtolower($langs->transnoentitiesnoconv("BillsCustomers")); +$textobject = strtolower($langs->transnoentitiesnoconv("BillsCustomers")); llxHeader('', $langs->trans("BillsSetup")); -$linkback=''.$langs->trans("BackToModuleList").''; +$linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup'); @@ -105,7 +105,7 @@ if ($action == 'create') * Edition of an optional field * */ -if ($action == 'edit' && ! empty($attrname)) +if ($action == 'edit' && !empty($attrname)) { $langs->load("members"); diff --git a/htdocs/compta/facture/admin/facturedet_cust_extrafields.php b/htdocs/compta/facture/admin/facturedet_cust_extrafields.php index fad5ec0e7a2..87467f0dba6 100644 --- a/htdocs/compta/facture/admin/facturedet_cust_extrafields.php +++ b/htdocs/compta/facture/admin/facturedet_cust_extrafields.php @@ -37,13 +37,13 @@ $extrafields = new ExtraFields($db); $form = new Form($db); // List of supported format -$tmptype2label=ExtraFields::$type2label; -$type2label=array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val); +$tmptype2label = ExtraFields::$type2label; +$type2label = array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); -$action=GETPOST('action', 'alpha'); -$attrname=GETPOST('attrname', 'alpha'); -$elementtype='facturedet'; //Must be the $table_element of the class that manage extrafield +$action = GETPOST('action', 'alpha'); +$attrname = GETPOST('attrname', 'alpha'); +$elementtype = 'facturedet'; //Must be the $table_element of the class that manage extrafield if (!$user->admin) accessforbidden(); @@ -60,11 +60,11 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; * View */ -$textobject=strtolower($langs->transnoentitiesnoconv("BillsCustomers")); +$textobject = strtolower($langs->transnoentitiesnoconv("BillsCustomers")); llxHeader('', $langs->trans("BillsSetup")); -$linkback=''.$langs->trans("BackToModuleList").''; +$linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup'); @@ -105,7 +105,7 @@ if ($action == 'create') * Edition d'un champ optionnel * */ -if ($action == 'edit' && ! empty($attrname)) +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/compta/facture/admin/facturedet_rec_cust_extrafields.php b/htdocs/compta/facture/admin/facturedet_rec_cust_extrafields.php index 133102fc282..32a7a8cb75a 100644 --- a/htdocs/compta/facture/admin/facturedet_rec_cust_extrafields.php +++ b/htdocs/compta/facture/admin/facturedet_rec_cust_extrafields.php @@ -37,13 +37,13 @@ $extrafields = new ExtraFields($db); $form = new Form($db); // List of supported format -$tmptype2label=ExtraFields::$type2label; -$type2label=array(''); -foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val); +$tmptype2label = ExtraFields::$type2label; +$type2label = array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); -$action=GETPOST('action', 'alpha'); -$attrname=GETPOST('attrname', 'alpha'); -$elementtype='facturedet_rec'; //Must be the $table_element of the class that manage extrafield +$action = GETPOST('action', 'alpha'); +$attrname = GETPOST('attrname', 'alpha'); +$elementtype = 'facturedet_rec'; //Must be the $table_element of the class that manage extrafield if (!$user->admin) accessforbidden(); @@ -60,11 +60,11 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; * View */ -$textobject=strtolower($langs->transnoentitiesnoconv("BillsCustomers")); +$textobject = strtolower($langs->transnoentitiesnoconv("BillsCustomers")); llxHeader('', $langs->trans("BillsSetup")); -$linkback=''.$langs->trans("BackToModuleList").''; +$linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup'); @@ -105,7 +105,7 @@ if ($action == 'create') * Edition d'un champ optionnel * */ -if ($action == 'edit' && ! empty($attrname)) +if ($action == 'edit' && !empty($attrname)) { print "
"; print load_fiche_titre($langs->trans("FieldEdition", $attrname)); diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index b5db78e8154..7e1faa00e60 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -1989,7 +1989,7 @@ if (empty($reshook)) if (empty($price2num_remise_percent)) $price2num_remise_percent = 0; if (empty($price2num_price_min)) $price2num_price_min = 0; - if ($usercanproductignorepricemin && (! empty($price_min) && ($price2num_pu_ht * (1 - $price2num_remise_percent / 100) < $price2num_price_min))) { + if ($usercanproductignorepricemin && (!empty($price_min) && ($price2num_pu_ht * (1 - $price2num_remise_percent / 100) < $price2num_price_min))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); setEventMessages($mesg, null, 'errors'); } else { diff --git a/htdocs/compta/paiement/card.php b/htdocs/compta/paiement/card.php index ffdb2bb90ea..edc76de0698 100644 --- a/htdocs/compta/paiement/card.php +++ b/htdocs/compta/paiement/card.php @@ -30,21 +30,21 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; -require_once DOL_DOCUMENT_ROOT .'/core/modules/facture/modules_facture.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; -if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Load translation files required by the page -$langs->loadLangs(array('bills','banks','companies')); +$langs->loadLangs(array('bills', 'banks', 'companies')); -$id=GETPOST('id', 'int'); -$ref=GETPOST('ref', 'alpha'); -$action=GETPOST('action', 'alpha'); -$confirm=GETPOST('confirm', 'alpha'); -$backtopage=GETPOST('backtopage', 'alpha'); +$id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'alpha'); +$confirm = GETPOST('confirm', 'alpha'); +$backtopage = GETPOST('backtopage', 'alpha'); // Security check -if ($user->socid) $socid=$user->socid; +if ($user->socid) $socid = $user->socid; // TODO ajouter regle pour restreindre acces paiement //$result = restrictedArea($user, 'facture', $id,''); @@ -64,7 +64,7 @@ if ($action == 'setnote' && $user->rights->facture->paiement) if ($result > 0) { $db->commit(); - $action=''; + $action = ''; } else { @@ -112,14 +112,14 @@ if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->facture-> $db->commit(); // Loop on each invoice linked to this payment to rebuild PDF - $factures=array(); - foreach($factures as $id) + $factures = array(); + foreach ($factures as $id) { $fac = new Facture($db); $fac->fetch($id); $outputlangs = $langs; - if (! empty($_REQUEST['lang_id'])) + if (!empty($_REQUEST['lang_id'])) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); @@ -140,7 +140,7 @@ if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->facture-> } } -if ($action == 'setnum_paiement' && ! empty($_POST['num_paiement'])) +if ($action == 'setnum_paiement' && !empty($_POST['num_paiement'])) { $object->fetch($id); $res = $object->update_num($_POST['num_paiement']); @@ -154,7 +154,7 @@ if ($action == 'setnum_paiement' && ! empty($_POST['num_paiement'])) } } -if ($action == 'setdatep' && ! empty($_POST['datepday'])) +if ($action == 'setdatep' && !empty($_POST['datepday'])) { $object->fetch($id); $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int')); @@ -176,9 +176,9 @@ if ($action == 'setdatep' && ! empty($_POST['datepday'])) llxHeader('', $langs->trans("Payment")); -$thirdpartystatic=new Societe($db); +$thirdpartystatic = new Societe($db); -$result=$object->fetch($id, $ref); +$result = $object->fetch($id, $ref); if ($result <= 0) { dol_print_error($db, 'Payement '.$id.' not found in database'); @@ -204,7 +204,7 @@ if ($action == 'valide') print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide', '', 0, 2); } -$linkback = '' . $langs->trans("BackToList") . ''; +$linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', ''); @@ -220,9 +220,9 @@ print $form->editfieldval("Date", 'datep', $object->date, $object, $user->rights print '
'.$langs->trans('PaymentMode').''.$labeltype; -print $object->num_paiement?' - '.$object->num_paiement:''; +print $object->num_paiement ? ' - '.$object->num_paiement : ''; print '
'.$langs->trans('Amount').''.price($object->amount, '', $disable_delete = 0; // Bank account -if (! empty($conf->banque->enabled)) +if (!empty($conf->banque->enabled)) { - $bankline=new AccountLine($db); + $bankline = new AccountLine($db); if ($object->fk_account > 0) { @@ -246,7 +246,7 @@ if (! empty($conf->banque->enabled)) print '
'.$langs->trans('BankAccount').''; - $accountstatic=new Account($db); + $accountstatic = new Account($db); $accountstatic->fetch($bankline->fk_account); print $accountstatic->getNomUrl(1); print '
'.$langs->trans('Bill').''.$langs->trans('Company').''.$langs->trans('Entity').''.$langs->trans('Entity').''.$langs->trans('ExpectedToPay').''.$langs->trans('PayedByThisPayment').''.$langs->trans('RemainderToPay').'
'; $mc->getInfo($objp->entity); print $mc->label; @@ -427,7 +427,7 @@ else print '
'; -if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) +if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) { if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '') { @@ -442,7 +442,7 @@ if ($user->socid == 0 && $action == '') { if ($user->rights->facture->paiement) { - if (! $disable_delete) + if (!$disable_delete) { print ''.$langs->trans('Delete').''; } diff --git a/htdocs/compta/paiement/info.php b/htdocs/compta/paiement/info.php index 691707cf188..3da6a95a1e8 100644 --- a/htdocs/compta/paiement/info.php +++ b/htdocs/compta/paiement/info.php @@ -31,10 +31,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; // Load translation files required by the page $langs->loadLangs(array('bills', 'companies')); -$id=GETPOST('id'); -$ref=GETPOST('ref', 'alpha'); -$action=GETPOST('action', 'alpha'); -$confirm=GETPOST('confirm', 'alpha'); +$id = GETPOST('id'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'alpha'); +$confirm = GETPOST('confirm', 'alpha'); /* * Actions @@ -58,7 +58,7 @@ $head = payment_prepare_head($object); dol_fiche_head($head, 'info', $langs->trans("PaymentCustomerInvoice"), -1, 'payment'); -$linkback = '' . $langs->trans("BackToList") . ''; +$linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', ''); diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 88faf188d17..128e43b335a 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -32,19 +32,19 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; // Load translation files required by the page -$langs->loadLangs(array('compta','bills','donation','salaries')); +$langs->loadLangs(array('compta', 'bills', 'donation', 'salaries')); -$date_startmonth=GETPOST('date_startmonth', 'int'); -$date_startday=GETPOST('date_startday', 'int'); -$date_startyear=GETPOST('date_startyear', 'int'); -$date_endmonth=GETPOST('date_endmonth', 'int'); -$date_endday=GETPOST('date_endday', 'int'); -$date_endyear=GETPOST('date_endyear', 'int'); +$date_startmonth = GETPOST('date_startmonth', 'int'); +$date_startday = GETPOST('date_startday', 'int'); +$date_startyear = GETPOST('date_startyear', 'int'); +$date_endmonth = GETPOST('date_endmonth', 'int'); +$date_endday = GETPOST('date_endday', 'int'); +$date_endyear = GETPOST('date_endyear', 'int'); -$nbofyear=4; +$nbofyear = 4; // Date range -$year=GETPOST('year', 'int'); +$year = GETPOST('year', 'int'); if (empty($year)) { $year_current = strftime("%Y", dol_now()); @@ -55,42 +55,42 @@ if (empty($year)) $month_current = strftime("%m", dol_now()); $year_start = $year - ($nbofyear - 1); } -$date_start=dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); -$date_end=dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); +$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); +$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); // We define date_start and date_end if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - $q=GETPOST("q")?GETPOST("q"):0; - if ($q==0) + $q = GETPOST("q") ?GETPOST("q") : 0; + if ($q == 0) { // We define date_start and date_end - $year_end=$year_start + ($nbofyear - 1); - $month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); - if (! GETPOST('month')) + $year_end = $year_start + ($nbofyear - 1); + $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); + if (!GETPOST('month')) { - if (! GETPOST("year") && $month_start > $month_current) + if (!GETPOST("year") && $month_start > $month_current) { $year_start--; $year_end--; } - $month_end=$month_start-1; - if ($month_end < 1) $month_end=12; + $month_end = $month_start - 1; + if ($month_end < 1) $month_end = 12; else $year_end++; } - else $month_end=$month_start; - $date_start=dol_get_first_day($year_start, $month_start, false); $date_end=dol_get_last_day($year_end, $month_end, false); + else $month_end = $month_start; + $date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false); } - if ($q==1) { $date_start=dol_get_first_day($year_start, 1, false); $date_end=dol_get_last_day($year_start, 3, false); } - if ($q==2) { $date_start=dol_get_first_day($year_start, 4, false); $date_end=dol_get_last_day($year_start, 6, false); } - if ($q==3) { $date_start=dol_get_first_day($year_start, 7, false); $date_end=dol_get_last_day($year_start, 9, false); } - if ($q==4) { $date_start=dol_get_first_day($year_start, 10, false); $date_end=dol_get_last_day($year_start, 12, false); } + if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); } + if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); } + if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); } + if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); } } // $date_start and $date_end are defined. We force $year_start and $nbofyear -$tmps=dol_getdate($date_start); +$tmps = dol_getdate($date_start); $year_start = $tmps['year']; -$tmpe=dol_getdate($date_end); +$tmpe = dol_getdate($date_end); $year_end = $tmpe['year']; $nbofyear = ($year_end - $year_start) + 1; //var_dump("year_start=".$year_start." year_end=".$year_end." nbofyear=".$nbofyear." date_start=".dol_print_date($date_start, 'dayhour')." date_end=".dol_print_date($date_end, 'dayhour')); @@ -99,13 +99,13 @@ $nbofyear = ($year_end - $year_start) + 1; // Security check $socid = GETPOST('socid', 'int'); if ($user->socid > 0) $socid = $user->socid; -if (! empty($conf->comptabilite->enabled)) $result=restrictedArea($user, 'compta', '', '', 'resultat'); -if (! empty($conf->accounting->enabled)) $result=restrictedArea($user, 'accounting', '', '', 'comptarapport'); +if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat'); +if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING') $modecompta = $conf->global->ACCOUNTING_MODE; -if (! empty($conf->accounting->enabled)) $modecompta='BOOKKEEPING'; -if (GETPOST("modecompta", 'alpha')) $modecompta=GETPOST("modecompta", 'alpha'); +if (!empty($conf->accounting->enabled)) $modecompta = 'BOOKKEEPING'; +if (GETPOST("modecompta", 'alpha')) $modecompta = GETPOST("modecompta", 'alpha'); /* @@ -114,57 +114,57 @@ if (GETPOST("modecompta", 'alpha')) $modecompta=GETPOST("modecompta", 'alpha'); llxHeader(); -$form=new Form($db); +$form = new Form($db); -$exportlink=''; +$exportlink = ''; // Affiche en-tete du rapport if ($modecompta == 'CREANCES-DETTES') { $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear"); - $calcmode=$langs->trans("CalcModeDebt"); - $calcmode.='
('.$langs->trans("SeeReportInInputOutputMode", '', '').')'; - if (! empty($conf->accounting->enabled)) $calcmode.='
('.$langs->trans("SeeReportInBookkeepingMode", '', '').')'; - $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); - $periodlink=($year_start?"".img_previous()." ".img_next()."":""); - $description=$langs->trans("RulesAmountWithTaxIncluded"); - $description.='
'.$langs->trans("RulesResultDue"); - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.="
".$langs->trans("DepositsAreNotIncluded"); - else $description.="
".$langs->trans("DepositsAreIncluded"); - $builddate=dol_now(); + $calcmode = $langs->trans("CalcModeDebt"); + $calcmode .= '
('.$langs->trans("SeeReportInInputOutputMode", '', '').')'; + if (!empty($conf->accounting->enabled)) $calcmode .= '
('.$langs->trans("SeeReportInBookkeepingMode", '', '').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); + $periodlink = ($year_start ? "".img_previous()." ".img_next()."" : ""); + $description = $langs->trans("RulesAmountWithTaxIncluded"); + $description .= '
'.$langs->trans("RulesResultDue"); + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= "
".$langs->trans("DepositsAreNotIncluded"); + else $description .= "
".$langs->trans("DepositsAreIncluded"); + $builddate = dol_now(); //$exportlink=$langs->trans("NotYetAvailable"); } -elseif ($modecompta=="RECETTES-DEPENSES") { +elseif ($modecompta == "RECETTES-DEPENSES") { $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear"); - $calcmode=$langs->trans("CalcModeEngagement"); - $calcmode.='
('.$langs->trans("SeeReportInDueDebtMode", '', '').')'; - if (! empty($conf->accounting->enabled)) $calcmode.='
('.$langs->trans("SeeReportInBookkeepingMode", '', '').')'; - $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); - $periodlink=($year_start?"".img_previous()." ".img_next()."":""); - $description=$langs->trans("RulesAmountWithTaxIncluded"); - $description.='
'.$langs->trans("RulesResultInOut"); - $builddate=dol_now(); + $calcmode = $langs->trans("CalcModeEngagement"); + $calcmode .= '
('.$langs->trans("SeeReportInDueDebtMode", '', '').')'; + if (!empty($conf->accounting->enabled)) $calcmode .= '
('.$langs->trans("SeeReportInBookkeepingMode", '', '').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); + $periodlink = ($year_start ? "".img_previous()." ".img_next()."" : ""); + $description = $langs->trans("RulesAmountWithTaxIncluded"); + $description .= '
'.$langs->trans("RulesResultInOut"); + $builddate = dol_now(); //$exportlink=$langs->trans("NotYetAvailable"); } -elseif ($modecompta=="BOOKKEEPING") +elseif ($modecompta == "BOOKKEEPING") { $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear"); - $calcmode=$langs->trans("CalcModeBookkeeping"); - $calcmode.='
('.$langs->trans("SeeReportInInputOutputMode", '', '').')'; - $calcmode.='
('.$langs->trans("SeeReportInDueDebtMode", '', '').')'; - $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); - $periodlink=($year_start?"".img_previous()." ".img_next()."":""); - $description=$langs->trans("RulesAmountOnInOutBookkeepingRecord"); - $description.=' ('.$langs->trans("SeePageForSetup", DOL_URL_ROOT.'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->trans("Chartofaccounts")).')'; - $builddate=dol_now(); + $calcmode = $langs->trans("CalcModeBookkeeping"); + $calcmode .= '
('.$langs->trans("SeeReportInInputOutputMode", '', '').')'; + $calcmode .= '
('.$langs->trans("SeeReportInDueDebtMode", '', '').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); + $periodlink = ($year_start ? "".img_previous()." ".img_next()."" : ""); + $description = $langs->trans("RulesAmountOnInOutBookkeepingRecord"); + $description .= ' ('.$langs->trans("SeePageForSetup", DOL_URL_ROOT.'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->trans("Chartofaccounts")).')'; + $builddate = dol_now(); //$exportlink=$langs->trans("NotYetAvailable"); } -$hselected='report'; +$hselected = 'report'; report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array('modecompta'=>$modecompta), $calcmode); -if (! empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') { print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); } @@ -177,44 +177,44 @@ if (! empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') $subtotal_ht = 0; $subtotal_ttc = 0; -if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES")) +if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ", ".MAIN_DB_PREFIX."facture as f"; - $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND f.fk_statut IN (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; - else $sql.= " AND f.type IN (0,1,2,3,5)"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $sql = "SELECT sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql .= ", ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.fk_soc = s.rowid"; + $sql .= " AND f.fk_statut IN (1,2)"; + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)"; + else $sql .= " AND f.type IN (0,1,2,3,5)"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } - elseif ($modecompta=="RECETTES-DEPENSES") + elseif ($modecompta == "RECETTES-DEPENSES") { /* * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) */ - $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; - $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; - $sql.= " WHERE p.rowid = pf.fk_paiement"; - $sql.= " AND pf.fk_facture = f.rowid"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql .= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " WHERE p.rowid = pf.fk_paiement"; + $sql .= " AND pf.fk_facture = f.rowid"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } - $sql.= " AND f.entity IN (".getEntity('invoice').")"; - if ($socid) $sql.= " AND f.fk_soc = $socid"; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm"; + $sql .= " AND f.entity IN (".getEntity('invoice').")"; + if ($socid) $sql .= " AND f.fk_soc = $socid"; + $sql .= " GROUP BY dm"; + $sql .= " ORDER BY dm"; //print $sql; dol_syslog("get customers invoices", LOG_DEBUG); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -222,7 +222,7 @@ if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mo while ($i < $num) { $row = $db->fetch_object($result); - $encaiss[$row->dm] = (isset($row->amount_ht)?$row->amount_ht:0); + $encaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0); $encaiss_ttc[$row->dm] = $row->amount_ttc; $i++; } @@ -232,29 +232,29 @@ if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mo dol_print_error($db); } } -elseif ($modecompta=="BOOKKEEPING") +elseif ($modecompta == "BOOKKEEPING") { // Nothing from this table } -if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES")) +if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { // On ajoute les paiements clients anciennes version, non lies par paiement_facture if ($modecompta != 'CREANCES-DETTES') { $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; - $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; - $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; - $sql.= " WHERE pf.rowid IS NULL"; - $sql.= " AND p.fk_bank = b.rowid"; - $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql .= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql .= " WHERE pf.rowid IS NULL"; + $sql .= " AND p.fk_bank = b.rowid"; + $sql .= " AND b.fk_account = ba.rowid"; + $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= " GROUP BY dm"; + $sql .= " ORDER BY dm"; dol_syslog("get old customers payments not linked to invoices", LOG_DEBUG); $result = $db->query($sql); @@ -265,10 +265,10 @@ if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mo { $row = $db->fetch_object($result); - if (! isset($encaiss[$row->dm])) $encaiss[$row->dm]=0; - $encaiss[$row->dm] += (isset($row->amount_ht)?$row->amount_ht:0); + if (!isset($encaiss[$row->dm])) $encaiss[$row->dm] = 0; + $encaiss[$row->dm] += (isset($row->amount_ht) ? $row->amount_ht : 0); - if (! isset($encaiss_ttc[$row->dm])) $encaiss_ttc[$row->dm]=0; + if (!isset($encaiss_ttc[$row->dm])) $encaiss_ttc[$row->dm] = 0; $encaiss_ttc[$row->dm] += $row->amount_ttc; $i++; @@ -278,12 +278,12 @@ if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mo dol_print_error($db); } } - elseif ($modecompta=="RECETTES-DEPENSES") + elseif ($modecompta == "RECETTES-DEPENSES") { // Nothing from this table } } -elseif ($modecompta=="BOOKKEEPING") +elseif ($modecompta == "BOOKKEEPING") { // Nothing from this table } @@ -295,36 +295,36 @@ elseif ($modecompta=="BOOKKEEPING") $subtotal_ht = 0; $subtotal_ttc = 0; -if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES")) +if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql.= " WHERE f.fk_statut IN (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)"; - else $sql.= " AND f.type IN (0,1,2,3)"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql .= " WHERE f.fk_statut IN (1,2)"; + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2)"; + else $sql .= " AND f.type IN (0,1,2,3)"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } - elseif ($modecompta=="RECETTES-DEPENSES") + elseif ($modecompta == "RECETTES-DEPENSES") { $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm"; - $sql.= " FROM ".MAIN_DB_PREFIX."paiementfourn as p"; - $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql.= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf"; - $sql.= " WHERE f.rowid = pf.fk_facturefourn"; - $sql.= " AND p.rowid = pf.fk_paiementfourn"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p"; + $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf"; + $sql .= " WHERE f.rowid = pf.fk_facturefourn"; + $sql .= " AND p.rowid = pf.fk_paiementfourn"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } - $sql.= " AND f.entity = ".$conf->entity; - if ($socid) $sql.= " AND f.fk_soc = ".$socid; - $sql.= " GROUP BY dm"; + $sql .= " AND f.entity = ".$conf->entity; + if ($socid) $sql .= " AND f.fk_soc = ".$socid; + $sql .= " GROUP BY dm"; dol_syslog("get suppliers invoices", LOG_DEBUG); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -333,10 +333,10 @@ if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mo { $row = $db->fetch_object($result); - if (! isset($decaiss[$row->dm])) $decaiss[$row->dm]=0; - $decaiss[$row->dm] = (isset($row->amount_ht)?$row->amount_ht:0); + if (!isset($decaiss[$row->dm])) $decaiss[$row->dm] = 0; + $decaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0); - if (! isset($decaiss_ttc[$row->dm])) $decaiss_ttc[$row->dm]=0; + if (!isset($decaiss_ttc[$row->dm])) $decaiss_ttc[$row->dm] = 0; $decaiss_ttc[$row->dm] = $row->amount_ttc; $i++; @@ -347,7 +347,7 @@ if (! empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mo dol_print_error($db); } } -elseif ($modecompta=="BOOKKEEPING") +elseif ($modecompta == "BOOKKEEPING") { // Nothing from this table } @@ -360,23 +360,23 @@ elseif ($modecompta=="BOOKKEEPING") $subtotal_ht = 0; $subtotal_ttc = 0; -if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES")) +if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { if ($modecompta == 'CREANCES-DETTES') { // TVA a payer $sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql.= " WHERE f.fk_statut IN (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; - else $sql.= " AND f.type IN (0,1,2,3,5)"; - $sql.= " AND f.entity IN (".getEntity('invoice').")"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; - $sql.= " GROUP BY dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.fk_statut IN (1,2)"; + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)"; + else $sql .= " AND f.type IN (0,1,2,3,5)"; + $sql .= " AND f.entity IN (".getEntity('invoice').")"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $sql .= " GROUP BY dm"; dol_syslog("get vat to pay", LOG_DEBUG); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; @@ -384,10 +384,10 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco while ($i < $num) { $obj = $db->fetch_object($result); - if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; + if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0; $decaiss[$obj->dm] += $obj->amount; - if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; + if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0; $decaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -398,17 +398,17 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco } // TVA a recuperer $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql.= " WHERE f.fk_statut IN (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2)"; - else $sql.= " AND f.type IN (0,1,2,3)"; - $sql.= " AND f.entity = ".$conf->entity; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; - $sql.= " GROUP BY dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql .= " WHERE f.fk_statut IN (1,2)"; + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2)"; + else $sql .= " AND f.type IN (0,1,2,3)"; + $sql .= " AND f.entity = ".$conf->entity; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $sql .= " GROUP BY dm"; dol_syslog("get vat to receive back", LOG_DEBUG); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; @@ -416,10 +416,10 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco while ($i < $num) { $obj = $db->fetch_object($result); - if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0; + if (!isset($encaiss[$obj->dm])) $encaiss[$obj->dm] = 0; $encaiss[$obj->dm] += $obj->amount; - if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0; + if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0; $encaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -429,19 +429,19 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco dol_print_error($db); } } - elseif ($modecompta=="RECETTES-DEPENSES") + elseif ($modecompta == "RECETTES-DEPENSES") { // TVA reellement deja payee $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; - $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; - $sql.= " WHERE amount > 0"; - $sql.= " AND t.entity = ".$conf->entity; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; - $sql.= " GROUP BY dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql .= " WHERE amount > 0"; + $sql .= " AND t.entity = ".$conf->entity; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; + $sql .= " GROUP BY dm"; dol_syslog("get vat really paid", LOG_DEBUG); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; @@ -449,10 +449,10 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco while ($i < $num) { $obj = $db->fetch_object($result); - if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; + if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0; $decaiss[$obj->dm] += $obj->amount; - if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; + if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0; $decaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -463,15 +463,15 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco } // TVA recuperee $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; - $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; - $sql.= " WHERE amount < 0"; - $sql.= " AND t.entity = ".$conf->entity; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; - $sql.= " GROUP BY dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql .= " WHERE amount < 0"; + $sql .= " AND t.entity = ".$conf->entity; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; + $sql .= " GROUP BY dm"; dol_syslog("get vat really received back", LOG_DEBUG); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; @@ -479,10 +479,10 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco while ($i < $num) { $obj = $db->fetch_object($result); - if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0; + if (!isset($encaiss[$obj->dm])) $encaiss[$obj->dm] = 0; $encaiss[$obj->dm] += -$obj->amount; - if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0; + if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0; $encaiss_ttc[$obj->dm] += -$obj->amount; $i++; @@ -493,7 +493,7 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco } } } -elseif ($modecompta=="BOOKKEEPING") +elseif ($modecompta == "BOOKKEEPING") { // Nothing from this table } @@ -504,36 +504,36 @@ elseif ($modecompta=="BOOKKEEPING") $subtotal_ht = 0; $subtotal_ttc = 0; -if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES")) +if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; - $sql.= " WHERE cs.fk_type = c.id"; - $sql.= " AND c.deductible = 0"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql .= " WHERE cs.fk_type = c.id"; + $sql .= " AND c.deductible = 0"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; } - elseif ($modecompta=="RECETTES-DEPENSES") + elseif ($modecompta == "RECETTES-DEPENSES") { $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; - $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql.= " WHERE p.fk_charge = cs.rowid"; - $sql.= " AND cs.fk_type = c.id"; - $sql.= " AND c.deductible = 0"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p"; + $sql .= " WHERE p.fk_charge = cs.rowid"; + $sql .= " AND cs.fk_type = c.id"; + $sql .= " AND c.deductible = 0"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } - $sql.= " AND cs.entity = ".$conf->entity; - $sql.= " GROUP BY c.libelle, dm"; + $sql .= " AND cs.entity = ".$conf->entity; + $sql .= " GROUP BY c.libelle, dm"; dol_syslog("get social contributions deductible=0 ", LOG_DEBUG); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; @@ -541,10 +541,10 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco while ($i < $num) { $obj = $db->fetch_object($result); - if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; + if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0; $decaiss[$obj->dm] += $obj->amount; - if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; + if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0; $decaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -554,7 +554,7 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco dol_print_error($db); } } -elseif ($modecompta=="BOOKKEEPING") +elseif ($modecompta == "BOOKKEEPING") { // Nothing from this table } @@ -566,36 +566,36 @@ elseif ($modecompta=="BOOKKEEPING") $subtotal_ht = 0; $subtotal_ttc = 0; -if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES")) +if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; - $sql.= " WHERE cs.fk_type = c.id"; - $sql.= " AND c.deductible = 1"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql .= " WHERE cs.fk_type = c.id"; + $sql .= " AND c.deductible = 1"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; } - elseif ($modecompta=="RECETTES-DEPENSES") + elseif ($modecompta == "RECETTES-DEPENSES") { $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as cs"; - $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql.= " WHERE p.fk_charge = cs.rowid"; - $sql.= " AND cs.fk_type = c.id"; - $sql.= " AND c.deductible = 1"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p"; + $sql .= " WHERE p.fk_charge = cs.rowid"; + $sql .= " AND cs.fk_type = c.id"; + $sql .= " AND c.deductible = 1"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } - $sql.= " AND cs.entity = ".$conf->entity; - $sql.= " GROUP BY c.libelle, dm"; + $sql .= " AND cs.entity = ".$conf->entity; + $sql .= " GROUP BY c.libelle, dm"; dol_syslog("get social contributions paid deductible=1", LOG_DEBUG); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; @@ -603,10 +603,10 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco while ($i < $num) { $obj = $db->fetch_object($result); - if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; + if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0; $decaiss[$obj->dm] += $obj->amount; - if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; + if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0; $decaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -616,7 +616,7 @@ if (! empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco dol_print_error($db); } } -elseif ($modecompta=="BOOKKEEPING") +elseif ($modecompta == "BOOKKEEPING") { // Nothing from this table } @@ -626,7 +626,7 @@ elseif ($modecompta=="BOOKKEEPING") * Salaries */ -if (! empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES")) +if (!empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { if ($modecompta == 'CREANCES-DETTES') $column = 'p.datev'; if ($modecompta == "RECETTES-DEPENSES") $column = 'p.datep'; @@ -634,10 +634,10 @@ if (! empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $m $subtotal_ht = 0; $subtotal_ttc = 0; $sql = "SELECT p.label as nom, date_format(".$column.",'%Y-%m') as dm, sum(p.amount) as amount"; - $sql .= " FROM " . MAIN_DB_PREFIX . "payment_salary as p"; + $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p"; $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'"; $sql .= " GROUP BY p.label, dm"; dol_syslog("get social salaries payments"); @@ -649,15 +649,15 @@ if (! empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $m while ($i < $num) { $obj = $db->fetch_object($result); - if (! isset($decaiss[$obj->dm])) + if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0; $decaiss[$obj->dm] += $obj->amount; - if (! isset($decaiss_ttc[$obj->dm])) + if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0; $decaiss_ttc[$obj->dm] += $obj->amount; - $i ++; + $i++; } } } else { @@ -674,38 +674,38 @@ elseif ($modecompta == "BOOKKEEPING") * Expense reports */ -if (! empty($conf->expensereport->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES")) +if (!empty($conf->expensereport->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { $langs->load('trips'); if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; - $sql.= " WHERE p.entity IN (".getEntity('expensereport').")"; - $sql.= " AND p.fk_statut>=5"; + $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; + $sql .= " WHERE p.entity IN (".getEntity('expensereport').")"; + $sql .= " AND p.fk_statut>=5"; - $column='p.date_valid'; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'"; + $column = 'p.date_valid'; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'"; } elseif ($modecompta == 'RECETTES-DEPENSES') { $sql = "SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; - $sql.= " WHERE p.entity IN (".getEntity('expensereport').")"; - $sql.= " AND p.fk_statut>=5"; + $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; + $sql .= " WHERE p.entity IN (".getEntity('expensereport').")"; + $sql .= " AND p.fk_statut>=5"; - $column='pe.datep'; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'"; + $column = 'pe.datep'; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'"; } - $sql.= " GROUP BY dm"; + $sql .= " GROUP BY dm"; dol_syslog("get expense report outcome"); - $result=$db->query($sql); + $result = $db->query($sql); $subtotal_ht = 0; $subtotal_ttc = 0; if ($result) @@ -715,10 +715,10 @@ if (! empty($conf->expensereport->enabled) && ($modecompta == 'CREANCES-DETTES' { while ($obj = $db->fetch_object($result)) { - if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; + if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0; $decaiss[$obj->dm] += $obj->amount_ht; - if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; + if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0; $decaiss_ttc[$obj->dm] += $obj->amount_ttc; } } @@ -737,34 +737,34 @@ elseif ($modecompta == 'BOOKKEEPING') { * Donation get dunning paiement */ -if (! empty($conf->don->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta=="RECETTES-DEPENSES")) +if (!empty($conf->don->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { $subtotal_ht = 0; $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; - $sql.= " WHERE p.entity IN (".getEntity('donation').")"; - $sql.= " AND fk_statut in (1,2)"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'"; + $sql .= " FROM ".MAIN_DB_PREFIX."don as p"; + $sql .= " WHERE p.entity IN (".getEntity('donation').")"; + $sql .= " AND fk_statut in (1,2)"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'"; } elseif ($modecompta == 'RECETTES-DEPENSES') { $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; - $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; - $sql.= " WHERE p.entity IN (".getEntity('donation').")"; - $sql.= " AND fk_statut >= 2"; - if (! empty($date_start) && ! empty($date_end)) { - $sql.= " AND pe.datep >= '".$db->idate($date_start)."' AND pe.datep <= '".$db->idate($date_end)."'"; + $sql .= " FROM ".MAIN_DB_PREFIX."don as p"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; + $sql .= " WHERE p.entity IN (".getEntity('donation').")"; + $sql .= " AND fk_statut >= 2"; + if (!empty($date_start) && !empty($date_end)) { + $sql .= " AND pe.datep >= '".$db->idate($date_start)."' AND pe.datep <= '".$db->idate($date_end)."'"; } } - $sql.= " GROUP BY p.societe, p.firstname, p.lastname, dm"; + $sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm"; dol_syslog("get donation payments"); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -775,10 +775,10 @@ if (! empty($conf->don->enabled) && ($modecompta == 'CREANCES-DETTES' || $modeco { $obj = $db->fetch_object($result); - if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0; + if (!isset($encaiss[$obj->dm])) $encaiss[$obj->dm] = 0; $encaiss[$obj->dm] += $obj->amount; - if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0; + if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0; $encaiss_ttc[$obj->dm] += $obj->amount; $i++; @@ -800,36 +800,36 @@ elseif ($modecompta == 'BOOKKEEPING') { * Request in mode BOOKKEEPING */ -if (! empty($conf->accounting->enabled) && ($modecompta == 'BOOKKEEPING')) +if (!empty($conf->accounting->enabled) && ($modecompta == 'BOOKKEEPING')) { $predefinedgroupwhere = "("; //$predefinedgroupwhere.= " (pcg_type = 'EXPENSE' and pcg_subtype in ('PRODUCT','SERVICE'))"; - $predefinedgroupwhere.= " (pcg_type = 'EXPENSE')"; - $predefinedgroupwhere.= " OR "; + $predefinedgroupwhere .= " (pcg_type = 'EXPENSE')"; + $predefinedgroupwhere .= " OR "; //$predefinedgroupwhere.= " (pcg_type = 'INCOME' and pcg_subtype in ('PRODUCT','SERVICE'))"; - $predefinedgroupwhere.= " (pcg_type = 'INCOME')"; - $predefinedgroupwhere.= ")"; + $predefinedgroupwhere .= " (pcg_type = 'INCOME')"; + $predefinedgroupwhere .= ")"; $charofaccountstring = $conf->global->CHARTOFACCOUNTS; - $charofaccountstring=dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version'); + $charofaccountstring = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version'); $sql = "SELECT b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, date_format(b.doc_date,'%Y-%m') as dm, sum(b.debit) as debit, sum(b.credit) as credit, sum(b.montant) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_account as aa"; - $sql.= " WHERE b.entity = ".$conf->entity; - $sql.= " AND aa.entity = ".$conf->entity; - $sql.= " AND b.numero_compte = aa.account_number"; - $sql.= " AND ".$predefinedgroupwhere; - $sql.= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'"; - if (! empty($date_start) && ! empty($date_end)) - $sql.= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'"; - $sql.= " GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_account as aa"; + $sql .= " WHERE b.entity = ".$conf->entity; + $sql .= " AND aa.entity = ".$conf->entity; + $sql .= " AND b.numero_compte = aa.account_number"; + $sql .= " AND ".$predefinedgroupwhere; + $sql .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'"; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'"; + $sql .= " GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm"; //print $sql; $subtotal_ht = 0; $subtotal_ttc = 0; dol_syslog("get bookkeeping record"); - $result=$db->query($sql); + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -840,12 +840,12 @@ if (! empty($conf->accounting->enabled) && ($modecompta == 'BOOKKEEPING')) { $obj = $db->fetch_object($result); - if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0; - if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; + if (!isset($encaiss[$obj->dm])) $encaiss[$obj->dm] = 0; + if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0; $encaiss[$obj->dm] += $obj->credit; $decaiss[$obj->dm] += $obj->debit; - if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0; - if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; + if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0; + if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0; $encaiss_ttc[$obj->dm] += 0; $decaiss_ttc[$obj->dm] += 0; @@ -866,7 +866,7 @@ $object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc); $parameters["mode"] = $modecompta; // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('externalbalance')); -$reshook=$hookmanager->executeHooks('addReportInfo', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +$reshook = $hookmanager->executeHooks('addReportInfo', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks @@ -874,34 +874,34 @@ $reshook=$hookmanager->executeHooks('addReportInfo', $parameters, $object, $acti * Show result array */ -$totentrees=array(); -$totsorties=array(); +$totentrees = array(); +$totsorties = array(); print '
'; print ''."\n"; print ''; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) +for ($annee = $year_start; $annee <= $year_end; $annee++) { print ''; } print ''; print ''; // Loop on each year to ouput -for ($annee = $year_start ; $annee <= $year_end ; $annee++) +for ($annee = $year_start; $annee <= $year_end; $annee++) { print ''; print ''; @@ -910,18 +910,18 @@ print ''; // Loop on each month -$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START-1):0; -for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) +$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0; +for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) { $mois_modulo = $mois; - if($mois>12) {$mois_modulo = $mois-12;} + if ($mois > 12) {$mois_modulo = $mois - 12; } print ''; print ""; - for ($annee = $year_start ; $annee <= $year_end ; $annee++) + for ($annee = $year_start; $annee <= $year_end; $annee++) { - $annee_decalage=$annee; - if($mois>12) {$annee_decalage=$annee+1;} + $annee_decalage = $annee; + if ($mois > 12) {$annee_decalage = $annee + 1; } $case = strftime("%Y-%m", dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage)); print '"; @@ -950,18 +950,18 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) { if (isset($encaiss[$case])) { - print ''.price(price2num($encaiss[$case], 'MT')).''; - if (! isset($totentrees[$annee])) $totentrees[$annee]=0; - $totentrees[$annee]+=$encaiss[$case]; + print ''.price(price2num($encaiss[$case], 'MT')).''; + if (!isset($totentrees[$annee])) $totentrees[$annee] = 0; + $totentrees[$annee] += $encaiss[$case]; } } else { if (isset($encaiss_ttc[$case])) { - print ''.price(price2num($encaiss_ttc[$case], 'MT')).''; - if (! isset($totentrees[$annee])) $totentrees[$annee]=0; - $totentrees[$annee]+=$encaiss_ttc[$case]; + print ''.price(price2num($encaiss_ttc[$case], 'MT')).''; + if (!isset($totentrees[$annee])) $totentrees[$annee] = 0; + $totentrees[$annee] += $encaiss_ttc[$case]; } } print ""; @@ -972,16 +972,16 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) // Total -$nbcols=0; +$nbcols = 0; print ''; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) +for ($annee = $year_start; $annee <= $year_end; $annee++) { - $nbcols+=2; - print ''; - print ''; + $nbcols += 2; + print ''; + print ''; } print "\n"; @@ -993,14 +993,14 @@ print "\n"; // Balance print ''; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) +for ($annee = $year_start; $annee <= $year_end; $annee++) { print ''; + $in = (isset($totentrees[$annee]) ?price2num($totentrees[$annee], 'MT') : 0); + $out = (isset($totsorties[$annee]) ?price2num($totsorties[$annee], 'MT') : 0); + print price(price2num($in - $out, 'MT')).''; // print ''; } } diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index fe0668aa9b2..684ef337fcd 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -29,19 +29,19 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; // Load translation files required by the page -$langs->loadLangs(array('compta','bills','donation','salaries')); +$langs->loadLangs(array('compta', 'bills', 'donation', 'salaries')); -$date_startmonth=GETPOST('date_startmonth'); -$date_startday=GETPOST('date_startday'); -$date_startyear=GETPOST('date_startyear'); -$date_endmonth=GETPOST('date_endmonth'); -$date_endday=GETPOST('date_endday'); -$date_endyear=GETPOST('date_endyear'); +$date_startmonth = GETPOST('date_startmonth'); +$date_startday = GETPOST('date_startday'); +$date_startyear = GETPOST('date_startyear'); +$date_endmonth = GETPOST('date_endmonth'); +$date_endday = GETPOST('date_endday'); +$date_endyear = GETPOST('date_endyear'); -$nbofyear=4; +$nbofyear = 4; // Date range -$year=GETPOST('year', 'int'); +$year = GETPOST('year', 'int'); if (empty($year)) { $year_current = strftime("%Y", dol_now()); @@ -52,55 +52,55 @@ if (empty($year)) $month_current = strftime("%m", dol_now()); $year_start = $year - ($nbofyear - 1); } -$date_start=dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); -$date_end=dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); +$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); +$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); // We define date_start and date_end if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - $q=GETPOST("q")?GETPOST("q"):0; - if ($q==0) + $q = GETPOST("q") ?GETPOST("q") : 0; + if ($q == 0) { // We define date_start and date_end - $year_end=$year_start + ($nbofyear - 1); - $month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); - if (! GETPOST('month')) + $year_end = $year_start + ($nbofyear - 1); + $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); + if (!GETPOST('month')) { - if (! GETPOST("year") && $month_start > $month_current) + if (!GETPOST("year") && $month_start > $month_current) { $year_start--; $year_end--; } - $month_end=$month_start-1; - if ($month_end < 1) $month_end=12; + $month_end = $month_start - 1; + if ($month_end < 1) $month_end = 12; } - else $month_end=$month_start; - $date_start=dol_get_first_day($year_start, $month_start, false); $date_end=dol_get_last_day($year_end, $month_end, false); + else $month_end = $month_start; + $date_start = dol_get_first_day($year_start, $month_start, false); $date_end = dol_get_last_day($year_end, $month_end, false); } - if ($q==1) { $date_start=dol_get_first_day($year_start, 1, false); $date_end=dol_get_last_day($year_start, 3, false); } - if ($q==2) { $date_start=dol_get_first_day($year_start, 4, false); $date_end=dol_get_last_day($year_start, 6, false); } - if ($q==3) { $date_start=dol_get_first_day($year_start, 7, false); $date_end=dol_get_last_day($year_start, 9, false); } - if ($q==4) { $date_start=dol_get_first_day($year_start, 10, false); $date_end=dol_get_last_day($year_start, 12, false); } + if ($q == 1) { $date_start = dol_get_first_day($year_start, 1, false); $date_end = dol_get_last_day($year_start, 3, false); } + if ($q == 2) { $date_start = dol_get_first_day($year_start, 4, false); $date_end = dol_get_last_day($year_start, 6, false); } + if ($q == 3) { $date_start = dol_get_first_day($year_start, 7, false); $date_end = dol_get_last_day($year_start, 9, false); } + if ($q == 4) { $date_start = dol_get_first_day($year_start, 10, false); $date_end = dol_get_last_day($year_start, 12, false); } } -$userid=GETPOST('userid', 'int'); +$userid = GETPOST('userid', 'int'); $socid = GETPOST('socid', 'int'); -$tmps=dol_getdate($date_start); +$tmps = dol_getdate($date_start); $year_start = $tmps['year']; -$tmpe=dol_getdate($date_end); +$tmpe = dol_getdate($date_end); $year_end = $tmpe['year']; $nbofyear = ($year_end - $year_start) + 1; // Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING') $modecompta = $conf->global->ACCOUNTING_MODE; -if (! empty($conf->accounting->enabled)) $modecompta='BOOKKEEPING'; -if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta", 'alpha'); +if (!empty($conf->accounting->enabled)) $modecompta = 'BOOKKEEPING'; +if (GETPOST("modecompta")) $modecompta = GETPOST("modecompta", 'alpha'); // Security check if ($user->socid > 0) $socid = $user->socid; -if (! empty($conf->comptabilite->enabled)) $result=restrictedArea($user, 'compta', '', '', 'resultat'); -if (! empty($conf->accounting->enabled)) $result=restrictedArea($user, 'accounting', '', '', 'comptarapport'); +if (!empty($conf->comptabilite->enabled)) $result = restrictedArea($user, 'compta', '', '', 'resultat'); +if (!empty($conf->accounting->enabled)) $result = restrictedArea($user, 'accounting', '', '', 'comptarapport'); @@ -111,54 +111,54 @@ if (! empty($conf->accounting->enabled)) $result=restrictedArea($user, 'accounti llxHeader(); -$form=new Form($db); +$form = new Form($db); // Affiche en-tete du rapport -if ($modecompta=="CREANCES-DETTES") +if ($modecompta == "CREANCES-DETTES") { - $name=$langs->trans("Turnover"); - $calcmode=$langs->trans("CalcModeDebt"); + $name = $langs->trans("Turnover"); + $calcmode = $langs->trans("CalcModeDebt"); //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; - $calcmode.='
('.$langs->trans("SeeReportInBookkeepingMode", '', '').')'; - $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); - $periodlink=($year_start?"".img_previous()."".img_next()."":""); - $description=$langs->trans("RulesCADue"); - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.= $langs->trans("DepositsAreNotIncluded"); - else $description.= $langs->trans("DepositsAreIncluded"); - $builddate=dol_now(); + $calcmode .= '
('.$langs->trans("SeeReportInBookkeepingMode", '', '').')'; + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); + $periodlink = ($year_start ? "".img_previous()."".img_next()."" : ""); + $description = $langs->trans("RulesCADue"); + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans("DepositsAreNotIncluded"); + else $description .= $langs->trans("DepositsAreIncluded"); + $builddate = dol_now(); //$exportlink=$langs->trans("NotYetAvailable"); } -elseif ($modecompta=="RECETTES-DEPENSES") +elseif ($modecompta == "RECETTES-DEPENSES") { - $name=$langs->trans("TurnoverCollected"); - $calcmode=$langs->trans("CalcModeEngagement"); + $name = $langs->trans("TurnoverCollected"); + $calcmode = $langs->trans("CalcModeEngagement"); //$calcmode.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; //$calcmode.='
('.$langs->trans("SeeReportInBookkeepingMode",'','').')'; - $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); - $periodlink=($year_start?"".img_previous()."".img_next()."":""); - $description=$langs->trans("RulesCAIn"); - $description.= $langs->trans("DepositsAreIncluded"); - $builddate=dol_now(); + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); + $periodlink = ($year_start ? "".img_previous()."".img_next()."" : ""); + $description = $langs->trans("RulesCAIn"); + $description .= $langs->trans("DepositsAreIncluded"); + $builddate = dol_now(); //$exportlink=$langs->trans("NotYetAvailable"); } -elseif ($modecompta=="BOOKKEEPING") +elseif ($modecompta == "BOOKKEEPING") { - $name=$langs->trans("Turnover"); - $calcmode=$langs->trans("CalcModeBookkeeping"); - $calcmode.='
('.$langs->trans("SeeReportInDueDebtMode", '', '').')'; + $name = $langs->trans("Turnover"); + $calcmode = $langs->trans("CalcModeBookkeeping"); + $calcmode .= '
('.$langs->trans("SeeReportInDueDebtMode", '', '').')'; //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; - $period=$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); - $periodlink=($year_start?"".img_previous()."".img_next()."":""); - $description=$langs->trans("RulesCATotalSaleJournal"); - $builddate=dol_now(); + $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); + $periodlink = ($year_start ? "".img_previous()."".img_next()."" : ""); + $description = $langs->trans("RulesCATotalSaleJournal"); + $builddate = dol_now(); //$exportlink=$langs->trans("NotYetAvailable"); } -$moreparam=array(); -if (! empty($modecompta)) $moreparam['modecompta']=$modecompta; +$moreparam = array(); +if (!empty($modecompta)) $moreparam['modecompta'] = $modecompta; report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode); -if (! empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') +if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') { print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); } @@ -166,40 +166,40 @@ if (! empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql.= " WHERE f.fk_statut in (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)"; - else $sql.= " AND f.type IN (0,1,2,3,5)"; - $sql.= " AND f.entity IN (".getEntity('invoice').")"; - if ($socid) $sql.= " AND f.fk_soc = ".$socid; + $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.fk_statut in (1,2)"; + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)"; + else $sql .= " AND f.type IN (0,1,2,3,5)"; + $sql .= " AND f.entity IN (".getEntity('invoice').")"; + if ($socid) $sql .= " AND f.fk_soc = ".$socid; } -elseif ($modecompta=="RECETTES-DEPENSES") +elseif ($modecompta == "RECETTES-DEPENSES") { /* * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) */ - $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; - $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; - $sql.= " WHERE p.rowid = pf.fk_paiement"; - $sql.= " AND pf.fk_facture = f.rowid"; - $sql.= " AND f.entity IN (".getEntity('invoice').")"; - if ($socid) $sql.= " AND f.fk_soc = ".$socid; + $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql .= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " WHERE p.rowid = pf.fk_paiement"; + $sql .= " AND pf.fk_facture = f.rowid"; + $sql .= " AND f.entity IN (".getEntity('invoice').")"; + if ($socid) $sql .= " AND f.fk_soc = ".$socid; } -elseif ($modecompta=="BOOKKEEPING") +elseif ($modecompta == "BOOKKEEPING") { - $sql = "SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.credit) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_journal as aj"; - $sql.= " WHERE b.entity = ".$conf->entity; - $sql.= " AND aj.entity = ".$conf->entity; - $sql.= " AND b.code_journal = aj.code AND aj.nature = 2" ; // @todo currently count amount in sale journal, but we need to define a category group for turnover + $sql = "SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.credit) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_journal as aj"; + $sql .= " WHERE b.entity = ".$conf->entity; + $sql .= " AND aj.entity = ".$conf->entity; + $sql .= " AND b.code_journal = aj.code AND aj.nature = 2"; // @todo currently count amount in sale journal, but we need to define a category group for turnover } -$sql.= " GROUP BY dm"; -$sql.= " ORDER BY dm"; +$sql .= " GROUP BY dm"; +$sql .= " ORDER BY dm"; //print $sql; $result = $db->query($sql); @@ -214,8 +214,8 @@ if ($result) $cum[$obj->dm] = $obj->amount_ttc; if ($obj->amount_ttc) { - $minyearmonth=($minyearmonth?min($minyearmonth, $obj->dm):$obj->dm); - $maxyearmonth=max($maxyearmonth, $obj->dm); + $minyearmonth = ($minyearmonth ?min($minyearmonth, $obj->dm) : $obj->dm); + $maxyearmonth = max($maxyearmonth, $obj->dm); } $i++; } @@ -229,16 +229,16 @@ else { if ($modecompta == 'RECETTES-DEPENSES') { $sql = "SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; - $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; - $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; - $sql.= " WHERE pf.rowid IS NULL"; - $sql.= " AND p.fk_bank = b.rowid"; - $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql .= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql .= " WHERE pf.rowid IS NULL"; + $sql .= " AND p.fk_bank = b.rowid"; + $sql .= " AND b.fk_account = ba.rowid"; + $sql .= " AND ba.entity IN (".getEntity('bank_account').")"; + $sql .= " GROUP BY dm"; + $sql .= " ORDER BY dm"; $result = $db->query($sql); if ($result) @@ -251,8 +251,8 @@ if ($modecompta == 'RECETTES-DEPENSES') $cum[$obj->dm] += $obj->amount_ttc; if ($obj->amount_ttc) { - $minyearmonth=($minyearmonth?min($minyearmonth, $obj->dm):$obj->dm); - $maxyearmonth=max($maxyearmonth, $obj->dm); + $minyearmonth = ($minyearmonth ?min($minyearmonth, $obj->dm) : $obj->dm); + $maxyearmonth = max($maxyearmonth, $obj->dm); } $i++; } @@ -263,20 +263,20 @@ if ($modecompta == 'RECETTES-DEPENSES') } } -$moreforfilter=''; +$moreforfilter = ''; print '
'; -print '
 '; print ''; print $annee; - if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee+1); + if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee + 1); print '
'.$langs->trans("Month").''; - $htmlhelp=''; + $htmlhelp = ''; // if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("PurchasesPlusVATEarnedAndDue"); print $form->textwithpicto($langs->trans("Outcome"), $htmlhelp); print ''; - $htmlhelp=''; + $htmlhelp = ''; // if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("SalesPlusVATToRetreive"); print $form->textwithpicto($langs->trans("Income"), $htmlhelp); print '
".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, $annee), "%B")." '; @@ -929,18 +929,18 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) { if (isset($decaiss[$case]) && $decaiss[$case] != 0) { - print ''.price(price2num($decaiss[$case], 'MT')).''; - if (! isset($totsorties[$annee])) $totsorties[$annee]=0; - $totsorties[$annee]+=$decaiss[$case]; + print ''.price(price2num($decaiss[$case], 'MT')).''; + if (!isset($totsorties[$annee])) $totsorties[$annee] = 0; + $totsorties[$annee] += $decaiss[$case]; } } else { if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) { - print ''.price(price2num($decaiss_ttc[$case], 'MT')).''; - if (! isset($totsorties[$annee])) $totsorties[$annee]=0; - $totsorties[$annee]+=$decaiss_ttc[$case]; + print ''.price(price2num($decaiss_ttc[$case], 'MT')).''; + if (!isset($totsorties[$annee])) $totsorties[$annee] = 0; + $totsorties[$annee] += $decaiss_ttc[$case]; } } print "
'; if ($modecompta == 'BOOKKEEPING') print $langs->trans("Total"); else print $langs->trans("TotalTTC"); print ''.(isset($totsorties[$annee])?price(price2num($totsorties[$annee], 'MT')):' ').''.(isset($totentrees[$annee])?price(price2num($totentrees[$annee], 'MT')):' ').''.(isset($totsorties[$annee]) ?price(price2num($totsorties[$annee], 'MT')) : ' ').''.(isset($totentrees[$annee]) ?price(price2num($totentrees[$annee], 'MT')) : ' ').'
'.$langs->trans("AccountingResult").' '; if (isset($totentrees[$annee]) || isset($totsorties[$annee])) { - $in=(isset($totentrees[$annee])?price2num($totentrees[$annee], 'MT'):0); - $out=(isset($totsorties[$annee])?price2num($totsorties[$annee], 'MT'):0); - print price(price2num($in-$out, 'MT')).' 
'."\n"; +print '
'."\n"; print ''; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) +for ($annee = $year_start; $annee <= $year_end; $annee++) { if ($modecompta == 'CREANCES-DETTES') print ''; if ($annee != $year_end) print ''; @@ -284,7 +284,7 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) print ''; print ''; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) +for ($annee = $year_start; $annee <= $year_end; $annee++) { if ($modecompta == 'CREANCES-DETTES') print ''; print ''; @@ -293,31 +293,31 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) } print ''; -$now_show_delta=0; -$minyear=substr($minyearmonth, 0, 4); -$maxyear=substr($maxyearmonth, 0, 4); -$nowyear=strftime("%Y", dol_now()); -$nowyearmonth=strftime("%Y-%m", dol_now()); -$maxyearmonth=max($maxyearmonth, $nowyearmonth); -$now=dol_now(); +$now_show_delta = 0; +$minyear = substr($minyearmonth, 0, 4); +$maxyear = substr($maxyearmonth, 0, 4); +$nowyear = strftime("%Y", dol_now()); +$nowyearmonth = strftime("%Y-%m", dol_now()); +$maxyearmonth = max($maxyearmonth, $nowyearmonth); +$now = dol_now(); $casenow = dol_print_date($now, "%Y-%m"); // Loop on each month -$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START-1):0; -for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) +$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0; +for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) { - $mois_modulo = $mois;// ajout - if($mois>12){$mois_modulo = $mois-12;} // ajout + $mois_modulo = $mois; // ajout + if ($mois > 12) {$mois_modulo = $mois - 12; } // ajout print ''; print ""; - for ($annee = $year_start -1 ; $annee <= $year_end ; $annee++) // We start one year before to have data to be able to make delta + for ($annee = $year_start - 1; $annee <= $year_end; $annee++) // We start one year before to have data to be able to make delta { - $annee_decalage=$annee; - if ($mois>12) {$annee_decalage=$annee+1;} + $annee_decalage = $annee; + if ($mois > 12) {$annee_decalage = $annee + 1; } $case = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage), "%Y-%m"); - $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage-1), "%Y-%m"); + $caseprev = dol_print_date(dol_mktime(1, 1, 1, $mois_modulo, 1, $annee_decalage - 1), "%Y-%m"); if ($annee >= $year_start) // We ignore $annee < $year_start, we loop on it to be able to make delta, nothing is output. { @@ -326,8 +326,8 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) print ''; + print ''; } - if ($cum[$caseprev] && ! $cum[$case]) + if ($cum[$caseprev] && !$cum[$case]) { print ''; } - if (! $cum[$caseprev] && $cum[$case]) + if (!$cum[$caseprev] && $cum[$case]) { //print ''; print ''; } - if (isset($cum[$caseprev]) && ! $cum[$caseprev] && ! $cum[$case]) + if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case]) { print ''; } - if (! isset($cum[$caseprev]) && ! $cum[$case]) + if (!isset($cum[$caseprev]) && !$cum[$case]) { print ''; } @@ -391,7 +391,7 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) print ''; } - $total_ht[$annee] += ((! empty($cum_ht[$case])) ? $cum_ht[$case] : 0); + $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0); $total[$annee] += $cum[$case]; } @@ -465,13 +465,13 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) // Affiche total print ''; -for ($annee = $year_start ; $annee <= $year_end ; $annee++) +for ($annee = $year_start; $annee <= $year_end; $annee++) { if ($modecompta == 'CREANCES-DETTES') { // Montant total HT if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { - print '"; + print '"; } else { @@ -482,7 +482,7 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) // Montant total if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) { - print '"; + print '"; } else { @@ -492,19 +492,19 @@ for ($annee = $year_start ; $annee <= $year_end ; $annee++) // Pourcentage total if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) { - if ($total[$annee-1] && $total[$annee]) { - $percent=(round(($total[$annee]-$total[$annee-1])/$total[$annee-1], 4)*100); - print ''; + if ($total[$annee - 1] && $total[$annee]) { + $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100); + print ''; } - if ($total[$annee-1] && ! $total[$annee]) + if ($total[$annee - 1] && !$total[$annee]) { print ''; } - if (! $total[$annee-1] && $total[$annee]) + if (!$total[$annee - 1] && $total[$annee]) { print ''; } - if (! $total[$annee-1] && ! $total[$annee]) + if (!$total[$annee - 1] && !$total[$annee]) { print ''; } diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 3f13eec2b34..2cd713a5654 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -40,30 +40,30 @@ if (GETPOST('addfile', 'alpha')) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Set tmp user directory - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path + $vardir = $conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path dol_add_file_process($upload_dir_tmp, 1, 0, 'addedfile', '', null, $trackid, 0); - $action='presend'; + $action = 'presend'; } /* * Remove file in email form */ -if (! empty($_POST['removedfile']) && empty($_POST['removAll'])) +if (!empty($_POST['removedfile']) && empty($_POST['removAll'])) { $trackid = GETPOST('trackid', 'aZ09'); require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Set tmp user directory - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path + $vardir = $conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path // TODO Delete only files that was uploaded from email form. This can be addressed by adding the trackid into the temp path then changing donotdeletefile to 2 instead of 1 to say "delete only if into temp dir" // GETPOST('removedfile','alpha') is position of file into $_SESSION["listofpaths"...] array. - dol_remove_file_process(GETPOST('removedfile', 'alpha'), 0, 1, $trackid); // We do not delete because if file is the official PDF of doc, we don't want to remove it physically - $action='presend'; + dol_remove_file_process(GETPOST('removedfile', 'alpha'), 0, 1, $trackid); // We do not delete because if file is the official PDF of doc, we don't want to remove it physically + $action = 'presend'; } /* @@ -73,19 +73,19 @@ if (GETPOST('removAll', 'alpha')) { $trackid = GETPOST('trackid', 'aZ09'); - $listofpaths=array(); - $listofnames=array(); - $listofmimes=array(); - $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; - if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); - if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';', $_SESSION["listofnames".$keytoavoidconflict]); - if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); + $listofpaths = array(); + $listofnames = array(); + $listofmimes = array(); + $keytoavoidconflict = empty($trackid) ? '' : '-'.$trackid; + if (!empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths = explode(';', $_SESSION["listofpaths".$keytoavoidconflict]); + if (!empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames = explode(';', $_SESSION["listofnames".$keytoavoidconflict]); + if (!empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes = explode(';', $_SESSION["listofmimes".$keytoavoidconflict]); include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); $formmail->trackid = $trackid; - foreach($listofpaths as $key => $value) + foreach ($listofpaths as $key => $value) { $pathtodelete = $value; $filetodelete = $listofnames[$key]; @@ -101,84 +101,84 @@ if (GETPOST('removAll', 'alpha')) /* * Send mail */ -if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removAll'] && ! $_POST['removedfile'] && ! $_POST['cancel'] && !$_POST['modelselected']) +if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST['removAll'] && !$_POST['removedfile'] && !$_POST['cancel'] && !$_POST['modelselected']) { if (empty($trackid)) $trackid = GETPOST('trackid', 'aZ09'); - $subject='';$actionmsg='';$actionmsg2=''; + $subject = ''; $actionmsg = ''; $actionmsg2 = ''; $langs->load('mails'); if (is_object($object)) { - $result=$object->fetch($id); + $result = $object->fetch($id); - $sendtosocid=0; // Id of related thirdparty - if (method_exists($object, "fetch_thirdparty") && ! in_array($object->element, array('societe', 'member', 'user', 'expensereport', 'contact'))) + $sendtosocid = 0; // Id of related thirdparty + if (method_exists($object, "fetch_thirdparty") && !in_array($object->element, array('societe', 'member', 'user', 'expensereport', 'contact'))) { - $result=$object->fetch_thirdparty(); - if ($object->element == 'user' && $result == 0) $result=1; // Even if not found, we consider ok - $thirdparty=$object->thirdparty; - $sendtosocid=$thirdparty->id; + $result = $object->fetch_thirdparty(); + if ($object->element == 'user' && $result == 0) $result = 1; // Even if not found, we consider ok + $thirdparty = $object->thirdparty; + $sendtosocid = $thirdparty->id; } elseif ($object->element == 'member' || $object->element == 'user') { - $thirdparty=$object; - if ($object->socid > 0) $sendtosocid=$object->socid; + $thirdparty = $object; + if ($object->socid > 0) $sendtosocid = $object->socid; } elseif ($object->element == 'expensereport') { - $tmpuser=new User($db); + $tmpuser = new User($db); $tmpuser->fetch($object->fk_user_author); - $thirdparty=$tmpuser; - if ($object->socid > 0) $sendtosocid=$object->socid; + $thirdparty = $tmpuser; + if ($object->socid > 0) $sendtosocid = $object->socid; } elseif ($object->element == 'societe') { - $thirdparty=$object; - if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id; + $thirdparty = $object; + if ($thirdparty->id > 0) $sendtosocid = $thirdparty->id; } elseif ($object->element == 'contact') { - $contact=$object; - if ($contact->id > 0) $sendtosocid=$contact->fetch_thirdparty()->id; + $contact = $object; + if ($contact->id > 0) $sendtosocid = $contact->fetch_thirdparty()->id; } else dol_print_error('', "Use actions_sendmails.in.php for an element/object '".$object->element."' that is not supported"); if (is_object($hookmanager)) { - $parameters=array(); - $reshook=$hookmanager->executeHooks('initSendToSocid', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('initSendToSocid', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks } } else $thirdparty = $mysoc; if ($result > 0) { - $sendto=''; - $sendtocc=''; - $sendtobcc=''; + $sendto = ''; + $sendtocc = ''; + $sendtobcc = ''; $sendtoid = array(); - $sendtouserid=array(); - $sendtoccuserid=array(); + $sendtouserid = array(); + $sendtoccuserid = array(); // Define $sendto - $receiver=$_POST['receiver']; - if (! is_array($receiver)) + $receiver = $_POST['receiver']; + if (!is_array($receiver)) { - if ($receiver == '-1') $receiver=array(); - else $receiver=array($receiver); + if ($receiver == '-1') $receiver = array(); + else $receiver = array($receiver); } - $tmparray=array(); + $tmparray = array(); if (trim($_POST['sendto'])) { // Recipients are provided into free text $tmparray[] = trim($_POST['sendto']); } - if (count($receiver)>0) + if (count($receiver) > 0) { - foreach($receiver as $key=>$val) + foreach ($receiver as $key=>$val) { // Recipient was provided from combo list if ($val == 'thirdparty') // Key selected means currentthird party (may be usd for current member or current user too) @@ -200,11 +200,11 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { - $receiveruser=$_POST['receiveruser']; - if (is_array($receiveruser) && count($receiveruser)>0) + $receiveruser = $_POST['receiveruser']; + if (is_array($receiveruser) && count($receiveruser) > 0) { $fuserdest = new User($db); - foreach($receiveruser as $key=>$val) + foreach ($receiveruser as $key=>$val) { $tmparray[] = $fuserdest->user_get_property($val, 'email'); $sendtouserid[] = $val; @@ -212,23 +212,23 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } } - $sendto=implode(',', $tmparray); + $sendto = implode(',', $tmparray); // Define $sendtocc - $receivercc=$_POST['receivercc']; - if (! is_array($receivercc)) + $receivercc = $_POST['receivercc']; + if (!is_array($receivercc)) { - if ($receivercc == '-1') $receivercc=array(); - else $receivercc=array($receivercc); + if ($receivercc == '-1') $receivercc = array(); + else $receivercc = array($receivercc); } - $tmparray=array(); + $tmparray = array(); if (trim($_POST['sendtocc'])) { $tmparray[] = trim($_POST['sendtocc']); } if (count($receivercc) > 0) { - foreach($receivercc as $key=>$val) + foreach ($receivercc as $key=>$val) { // Recipient was provided from combo list if ($val == 'thirdparty') // Key selected means currentthird party (may be usd for current member or current user too) @@ -248,25 +248,25 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } } if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { - $receiverccuser=$_POST['receiverccuser']; + $receiverccuser = $_POST['receiverccuser']; - if (is_array($receiverccuser) && count($receiverccuser)>0) + if (is_array($receiverccuser) && count($receiverccuser) > 0) { $fuserdest = new User($db); - foreach($receiverccuser as $key=>$val) + foreach ($receiverccuser as $key=>$val) { $tmparray[] = $fuserdest->user_get_property($val, 'email'); $sendtoccuserid[] = $val; } } } - $sendtocc=implode(',', $tmparray); + $sendtocc = implode(',', $tmparray); if (dol_strlen($sendto)) { // Define $urlwithroot - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; @@ -275,24 +275,24 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $fromtype = GETPOST('fromtype', 'alpha'); if ($fromtype === 'robot') { - $from = dol_string_nospecial($conf->global->MAIN_MAIL_EMAIL_FROM, ' ', array(",")) .' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.'>'; + $from = dol_string_nospecial($conf->global->MAIN_MAIL_EMAIL_FROM, ' ', array(",")).' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.'>'; } elseif ($fromtype === 'user') { - $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")) .' <'.$user->email.'>'; + $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")).' <'.$user->email.'>'; } elseif ($fromtype === 'company') { - $from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")) .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; + $from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")).' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; } elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { - $tmp=explode(',', $user->email_aliases); + $tmp = explode(',', $user->email_aliases); $from = trim($tmp[($reg[1] - 1)]); } elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { - $tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); + $tmp = explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); $from = trim($tmp[($reg[1] - 1)]); } elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { - $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1]; + $sql = 'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1]; $resql = $db->query($sql); $obj = $db->fetch_object($resql); if ($obj) @@ -301,10 +301,10 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } } else { - $from = dol_string_nospecial($_POST['fromname'], ' ', array(",")) . ' <' . $_POST['frommail'] .'>'; + $from = dol_string_nospecial($_POST['fromname'], ' ', array(",")).' <'.$_POST['frommail'].'>'; } - $replyto = dol_string_nospecial($_POST['replytoname'], ' ', array(",")). ' <' . $_POST['replytomail'].'>'; + $replyto = dol_string_nospecial($_POST['replytoname'], ' ', array(",")).' <'.$_POST['replytomail'].'>'; $message = GETPOST('message', 'none'); $subject = GETPOST('subject', 'none'); @@ -312,28 +312,28 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO // // become // - $message=preg_replace('/()/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message); + $message = preg_replace('/()/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message); - $sendtobcc= GETPOST('sendtoccc'); + $sendtobcc = GETPOST('sendtoccc'); // Autocomplete the $sendtobcc // $autocopy can be MAIN_MAIL_AUTOCOPY_PROPOSAL_TO, MAIN_MAIL_AUTOCOPY_ORDER_TO, MAIN_MAIL_AUTOCOPY_INVOICE_TO, MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO... - if (! empty($autocopy)) + if (!empty($autocopy)) { - $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc?", ":"").$conf->global->$autocopy)); + $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc ? ", " : "").$conf->global->$autocopy)); } $deliveryreceipt = $_POST['deliveryreceipt']; if ($action == 'send' || $action == 'relance') { - $actionmsg2=$langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1); + $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1); if ($message) { - $actionmsg=$langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from); - $actionmsg=dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto)); - if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . dol_escape_htmltag($sendtocc)); - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject); - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":"); + $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from); + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto)); + if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc)); + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject); + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":"); $actionmsg = dol_concatdesc($actionmsg, $message); } } @@ -341,9 +341,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO // Create form object include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); - $formmail->trackid = $trackid; // $trackid must be defined + $formmail->trackid = $trackid; // $trackid must be defined - $attachedfiles=$formmail->get_attached_files(); + $attachedfiles = $formmail->get_attached_files(); $filepath = $attachedfiles['paths']; $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; @@ -393,15 +393,15 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO */ // Make substitution in email content - $substitutionarray=getCommonSubstitutionArray($langs, 0, null, $object); + $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $object); $substitutionarray['__EMAIL__'] = $sendto; - $substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty))?'':''; + $substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty)) ? '' : ''; - $parameters=array('mode'=>'formemail'); + $parameters = array('mode'=>'formemail'); complete_substitutions_array($substitutionarray, $langs, $object, $parameters); - $subject=make_substitutions($subject, $substitutionarray); - $message=make_substitutions($message, $substitutionarray); + $subject = make_substitutions($subject, $substitutionarray); + $message = make_substitutions($message, $substitutionarray); if (method_exists($object, 'makeSubstitution')) { @@ -416,35 +416,35 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO if ($mailfile->error) { setEventMessages($mailfile->error, $mailfile->errors, 'errors'); - $action='presend'; + $action = 'presend'; } else { - $result=$mailfile->sendfile(); + $result = $mailfile->sendfile(); if ($result) { // Initialisation of datas of object to call trigger if (is_object($object)) { - if (empty($actiontypecode)) $actiontypecode='AC_OTH_AUTO'; // Event insert into agenda automatically + if (empty($actiontypecode)) $actiontypecode = 'AC_OTH_AUTO'; // Event insert into agenda automatically - $object->socid = $sendtosocid; // To link to a company - $object->sendtoid = $sendtoid; // To link to contact addresses. This is an array. - $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) - $object->actionmsg = $actionmsg; // Long text (@todo Replace this with $message, we already have details of email in dedicated properties) - $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...); + $object->socid = $sendtosocid; // To link to a company + $object->sendtoid = $sendtoid; // To link to contact addresses. This is an array. + $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) + $object->actionmsg = $actionmsg; // Long text (@todo Replace this with $message, we already have details of email in dedicated properties) + $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...); - $object->trackid = $trackid; + $object->trackid = $trackid; $object->fk_element = $object->id; $object->elementtype = $object->element; - if (is_array($attachedfiles) && count($attachedfiles)>0) { - $object->attachedfiles = $attachedfiles; + if (is_array($attachedfiles) && count($attachedfiles) > 0) { + $object->attachedfiles = $attachedfiles; } - if (is_array($sendtouserid) && count($sendtouserid)>0 && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { - $object->sendtouserid = $sendtouserid; + if (is_array($sendtouserid) && count($sendtouserid) > 0 && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { + $object->sendtouserid = $sendtouserid; } - $object->email_msgid = $mailfile->msgid; // @todo Set msgid into $mailfile after sending + $object->email_msgid = $mailfile->msgid; // @todo Set msgid into $mailfile after sending $object->email_from = $from; $object->email_subject = $subject; $object->email_to = $sendto; @@ -454,11 +454,11 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $object->email_msgid = $mailfile->msgid; // Call of triggers (you should have set $triggersendname to execute trigger. $trigger_name is deprcated) - if (! empty($triggersendname) || ! empty($trigger_name)) + if (!empty($triggersendname) || !empty($trigger_name)) { - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($db); - $result=$interface->run_triggers(empty($triggersendname)?$trigger_name:$triggersendname, $object, $user, $langs, $conf); + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; + $interface = new Interfaces($db); + $result = $interface->run_triggers(empty($triggersendname) ? $trigger_name : $triggersendname, $object, $user, $langs, $conf); if ($result < 0) { setEventMessages($interface->error, $interface->errors, 'errors'); } @@ -467,28 +467,28 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO // Redirect here // This avoid sending mail twice if going out and then back to page - $mesg=$langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2)); + $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2)); setEventMessages($mesg, null, 'mesgs'); - $moreparam=''; - if (isset($paramname2) || isset($paramval2)) $moreparam.= '&'.($paramname2?$paramname2:'mid').'='.$paramval2; - header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'').$moreparam); + $moreparam = ''; + if (isset($paramname2) || isset($paramval2)) $moreparam .= '&'.($paramname2 ? $paramname2 : 'mid').'='.$paramval2; + header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname ? $paramname : 'id').'='.(is_object($object) ? $object->id : '').$moreparam); exit; } else { $langs->load("other"); - $mesg='
'; + $mesg = '
'; if ($mailfile->error) { - $mesg.=$langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto)); - $mesg.='
'.$mailfile->error; + $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($from), dol_escape_htmltag($sendto)); + $mesg .= '
'.$mailfile->error; } else { - $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + $mesg .= 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; } - $mesg.='
'; + $mesg .= '
'; setEventMessages($mesg, null, 'warnings'); $action = 'presend'; diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index cab3b4b4336..36d471408ee 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -32,8 +32,8 @@ class Utils */ public $db; - public $output; // Used by Cron method to return message - public $result; // Used by Cron method to return data + public $output; // Used by Cron method to return message + public $result; // Used by Cron method to return data /** * Constructor @@ -62,84 +62,84 @@ class Utils require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $filesarray=array(); - if (empty($choice)) $choice='tempfilesold'; + $filesarray = array(); + if (empty($choice)) $choice = 'tempfilesold'; dol_syslog("Utils::purgeFiles choice=".$choice, LOG_DEBUG); - if ($choice=='tempfiles' || $choice=='tempfilesold') + if ($choice == 'tempfiles' || $choice == 'tempfilesold') { // Delete temporary files if ($dolibarr_main_data_root) { - $filesarray=dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', 'name', SORT_ASC, 2, 0, '', 1); // Do not follow symlinks + $filesarray = dol_dir_list($dolibarr_main_data_root, "directories", 1, '^temp$', '', 'name', SORT_ASC, 2, 0, '', 1); // Do not follow symlinks if ($choice == 'tempfilesold') { $now = dol_now(); - foreach($filesarray as $key => $val) + foreach ($filesarray as $key => $val) { - if ($val['date'] > ($now - ($nbsecondsold))) unset($filesarray[$key]); // Discard temp dir not older than $nbsecondsold + if ($val['date'] > ($now - ($nbsecondsold))) unset($filesarray[$key]); // Discard temp dir not older than $nbsecondsold } } } } - if ($choice=='allfiles') + if ($choice == 'allfiles') { // Delete all files (except install.lock, do not follow symbolic links) if ($dolibarr_main_data_root) { - $filesarray=dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); + $filesarray = dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); } } - if ($choice=='logfile') + if ($choice == 'logfile') { // Define files log if ($dolibarr_main_data_root) { - $filesarray=dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*(\.gz)?$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); + $filesarray = dol_dir_list($dolibarr_main_data_root, "files", 0, '.*\.log[\.0-9]*(\.gz)?$', 'install\.lock$', 'name', SORT_ASC, 0, 0, '', 1); } - $filelog=''; - if (! empty($conf->syslog->enabled)) + $filelog = ''; + if (!empty($conf->syslog->enabled)) { - $filelog=$conf->global->SYSLOG_FILE; - $filelog=preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog); + $filelog = $conf->global->SYSLOG_FILE; + $filelog = preg_replace('/DOL_DATA_ROOT/i', DOL_DATA_ROOT, $filelog); - $alreadyincluded=false; + $alreadyincluded = false; foreach ($filesarray as $tmpcursor) { - if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded=true; } + if ($tmpcursor['fullname'] == $filelog) { $alreadyincluded = true; } } - if (! $alreadyincluded) $filesarray[]=array('fullname'=>$filelog,'type'=>'file'); + if (!$alreadyincluded) $filesarray[] = array('fullname'=>$filelog, 'type'=>'file'); } } - $count=0; - $countdeleted=0; - $counterror=0; + $count = 0; + $countdeleted = 0; + $counterror = 0; if (count($filesarray)) { - foreach($filesarray as $key => $value) + foreach ($filesarray as $key => $value) { //print "x ".$filesarray[$key]['fullname']."-".$filesarray[$key]['type']."
\n"; if ($filesarray[$key]['type'] == 'dir') { - $startcount=0; - $tmpcountdeleted=0; + $startcount = 0; + $tmpcountdeleted = 0; - $result=dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted); - $count+=$result; - $countdeleted+=$tmpcountdeleted; + $result = dol_delete_dir_recursive($filesarray[$key]['fullname'], $startcount, 1, 0, $tmpcountdeleted); + $count += $result; + $countdeleted += $tmpcountdeleted; } elseif ($filesarray[$key]['type'] == 'file') { // If (file that is not logfile) or (if mode is logfile) - if ($filesarray[$key]['fullname'] != $filelog || $choice=='logfile') + if ($filesarray[$key]['fullname'] != $filelog || $choice == 'logfile') { - $result=dol_delete_file($filesarray[$key]['fullname'], 1, 1); + $result = dol_delete_file($filesarray[$key]['fullname'], 1, 1); if ($result) { $count++; @@ -154,7 +154,7 @@ class Utils } // Update cachenbofdoc - if (! empty($conf->ecm->enabled) && $choice=='allfiles') + if (!empty($conf->ecm->enabled) && $choice == 'allfiles') { require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php'; $ecmdirstatic = new EcmDirectory($this->db); @@ -164,20 +164,20 @@ class Utils if ($count > 0) { - $this->output=$langs->trans("PurgeNDirectoriesDeleted", $countdeleted); - if ($count > $countdeleted) $this->output.='
'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted)); + $this->output = $langs->trans("PurgeNDirectoriesDeleted", $countdeleted); + if ($count > $countdeleted) $this->output .= '
'.$langs->trans("PurgeNDirectoriesFailed", ($count - $countdeleted)); } - else $this->output=$langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)':''); + else $this->output = $langs->trans("PurgeNothingToDelete").($choice == 'tempfilesold' ? ' (older than 24h)' : ''); // Recreate temp dir that are not automatically recreated by core code for performance purpose, we need them - if (! empty($conf->api->enabled)) + if (!empty($conf->api->enabled)) { dol_mkdir($conf->api->dir_temp); } dol_mkdir($conf->user->dir_temp); //return $count; - return 0; // This function can be called by cron so must return 0 if OK + return 0; // This function can be called by cron so must return 0 if OK } @@ -204,114 +204,114 @@ class Utils require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Check compression parameter - if (! in_array($compression, array('none', 'gz', 'bz', 'zip'))) + if (!in_array($compression, array('none', 'gz', 'bz', 'zip'))) { $langs->load("errors"); - $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression"); + $this->error = $langs->transnoentitiesnoconv("ErrorBadValueForParameter", $compression, "Compression"); return -1; } // Check type parameter if ($type == 'auto') $type = $db->type; - if (! in_array($type, array('postgresql', 'pgsql', 'mysql', 'mysqli', 'mysqlnobin'))) + if (!in_array($type, array('postgresql', 'pgsql', 'mysql', 'mysqli', 'mysqlnobin'))) { $langs->load("errors"); - $this->error=$langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype"); + $this->error = $langs->transnoentitiesnoconv("ErrorBadValueForParameter", $type, "Basetype"); return -1; } // Check file parameter if ($file == 'auto') { - $prefix='dump'; - $ext='sql'; - if (in_array($type, array('mysql', 'mysqli'))) { $prefix='mysqldump'; $ext='sql'; } + $prefix = 'dump'; + $ext = 'sql'; + if (in_array($type, array('mysql', 'mysqli'))) { $prefix = 'mysqldump'; $ext = 'sql'; } //if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='dump'; } - if (in_array($type, array('pgsql'))) { $prefix='pg_dump'; $ext='sql'; } - $file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext; + if (in_array($type, array('pgsql'))) { $prefix = 'pg_dump'; $ext = 'sql'; } + $file = $prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext; } - $outputdir = $conf->admin->dir_output.'/backup'; - $result=dol_mkdir($outputdir); + $outputdir = $conf->admin->dir_output.'/backup'; + $result = dol_mkdir($outputdir); // MYSQL if ($type == 'mysql' || $type == 'mysqli') { - $cmddump=$conf->global->SYSTEMTOOLS_MYSQLDUMP; + $cmddump = $conf->global->SYSTEMTOOLS_MYSQLDUMP; $outputfile = $outputdir.'/'.$file; // for compression format, we add extension - $compression=$compression ? $compression : 'none'; - if ($compression == 'gz') $outputfile.='.gz'; - if ($compression == 'bz') $outputfile.='.bz2'; + $compression = $compression ? $compression : 'none'; + if ($compression == 'gz') $outputfile .= '.gz'; + if ($compression == 'bz') $outputfile .= '.bz2'; $outputerror = $outputfile.'.err'; dol_mkdir($conf->admin->dir_output.'/backup'); // Parameteres execution $command = $cmddump; - $command = preg_replace('/(\$|%)/', '', $command); // We removed chars that can be used to inject vars that contains space inside path of command without seeing there is a space to bypass the escapeshellarg. - if (preg_match("/\s/", $command)) $command=escapeshellarg($command); // If there is spaces, we add quotes on command to be sure $command is only a program and not a program+parameters + $command = preg_replace('/(\$|%)/', '', $command); // We removed chars that can be used to inject vars that contains space inside path of command without seeing there is a space to bypass the escapeshellarg. + if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // If there is spaces, we add quotes on command to be sure $command is only a program and not a program+parameters //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass); - $param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host; - $param.=" -u ".$dolibarr_main_db_user; - if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port; - if (! GETPOST("use_transaction", "alpha")) $param.=" -l --single-transaction"; - if (GETPOST("disable_fk", "alpha") || $usedefault) $param.=" -K"; - if (GETPOST("sql_compat", "alpha") && GETPOST("sql_compat", "alpha") != 'NONE') $param.=" --compatible=".escapeshellarg(GETPOST("sql_compat", "alpha")); - if (GETPOST("drop_database", "alpha")) $param.=" --add-drop-database"; - if (GETPOST("use_mysql_quick_param", "alpha"))$param.=" --quick"; + $param = $dolibarr_main_db_name." -h ".$dolibarr_main_db_host; + $param .= " -u ".$dolibarr_main_db_user; + if (!empty($dolibarr_main_db_port)) $param .= " -P ".$dolibarr_main_db_port; + if (!GETPOST("use_transaction", "alpha")) $param .= " -l --single-transaction"; + if (GETPOST("disable_fk", "alpha") || $usedefault) $param .= " -K"; + if (GETPOST("sql_compat", "alpha") && GETPOST("sql_compat", "alpha") != 'NONE') $param .= " --compatible=".escapeshellarg(GETPOST("sql_compat", "alpha")); + if (GETPOST("drop_database", "alpha")) $param .= " --add-drop-database"; + if (GETPOST("use_mysql_quick_param", "alpha"))$param .= " --quick"; if (GETPOST("sql_structure", "alpha") || $usedefault) { - if (GETPOST("drop", "alpha") || $usedefault) $param.=" --add-drop-table=TRUE"; - else $param.=" --add-drop-table=FALSE"; + if (GETPOST("drop", "alpha") || $usedefault) $param .= " --add-drop-table=TRUE"; + else $param .= " --add-drop-table=FALSE"; } else { - $param.=" -t"; + $param .= " -t"; } - if (GETPOST("disable-add-locks", "alpha")) $param.=" --add-locks=FALSE"; + if (GETPOST("disable-add-locks", "alpha")) $param .= " --add-locks=FALSE"; if (GETPOST("sql_data", "alpha") || $usedefault) { - $param.=" --tables"; - if (GETPOST("showcolumns", "alpha") || $usedefault) $param.=" -c"; - if (GETPOST("extended_ins", "alpha") || $usedefault) $param.=" -e"; - else $param.=" --skip-extended-insert"; - if (GETPOST("delayed", "alpha")) $param.=" --delayed-insert"; - if (GETPOST("sql_ignore", "alpha")) $param.=" --insert-ignore"; - if (GETPOST("hexforbinary", "alpha") || $usedefault) $param.=" --hex-blob"; + $param .= " --tables"; + if (GETPOST("showcolumns", "alpha") || $usedefault) $param .= " -c"; + if (GETPOST("extended_ins", "alpha") || $usedefault) $param .= " -e"; + else $param .= " --skip-extended-insert"; + if (GETPOST("delayed", "alpha")) $param .= " --delayed-insert"; + if (GETPOST("sql_ignore", "alpha")) $param .= " --insert-ignore"; + if (GETPOST("hexforbinary", "alpha") || $usedefault) $param .= " --hex-blob"; } else { - $param.=" -d"; // No row information (no data) + $param .= " -d"; // No row information (no data) } - $param.=" --default-character-set=utf8"; // We always save output into utf8 charset - $paramcrypted=$param; - $paramclear=$param; - if (! empty($dolibarr_main_db_pass)) + $param .= " --default-character-set=utf8"; // We always save output into utf8 charset + $paramcrypted = $param; + $paramclear = $param; + if (!empty($dolibarr_main_db_pass)) { - $paramcrypted.=' -p"'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'"'; - $paramclear.=' -p"'.str_replace(array('"','`'), array('\"','\`'), $dolibarr_main_db_pass).'"'; + $paramcrypted .= ' -p"'.preg_replace('/./i', '*', $dolibarr_main_db_pass).'"'; + $paramclear .= ' -p"'.str_replace(array('"', '`'), array('\"', '\`'), $dolibarr_main_db_pass).'"'; } - $errormsg=''; + $errormsg = ''; $handle = ''; // Start call method to execute dump - $fullcommandcrypted=$command." ".$paramcrypted." 2>&1"; - $fullcommandclear=$command." ".$paramclear." 2>&1"; + $fullcommandcrypted = $command." ".$paramcrypted." 2>&1"; + $fullcommandclear = $command." ".$paramclear." 2>&1"; if ($compression == 'none') $handle = fopen($outputfile, 'w'); if ($compression == 'gz') $handle = gzopen($outputfile, 'w'); if ($compression == 'bz') $handle = bzopen($outputfile, 'w'); if ($handle) { - if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN; - if (empty($execmethod)) $execmethod=1; + if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod = $conf->global->MAIN_EXEC_USE_POPEN; + if (empty($execmethod)) $execmethod = 1; - $ok=0; + $ok = 0; dol_syslog("Utils::dumpDatabase execmethod=".$execmethod." command:".$fullcommandcrypted, LOG_DEBUG); // TODO Replace with executeCLI function @@ -325,20 +325,20 @@ class Utils $langs->load("errors"); dol_syslog("Datadump retval after exec=".$retval, LOG_ERR); $errormsg = 'Error '.$retval; - $ok=0; + $ok = 0; } else { - $i=0; + $i = 0; if (!empty($output_arr)) { - foreach($output_arr as $key => $read) + foreach ($output_arr as $key => $read) { - $i++; // output line number + $i++; // output line number if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue; fwrite($handle, $read.($execmethod == 2 ? '' : "\n")); - if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok=1; - elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok=1; + if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok = 1; + elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok = 1; } } } @@ -346,16 +346,16 @@ class Utils if ($execmethod == 2) // With this method, there is no way to get the return code, only output { $handlein = popen($fullcommandclear, 'r'); - $i=0; + $i = 0; while (!feof($handlein)) { - $i++; // output line number + $i++; // output line number $read = fgets($handlein); // Exclude warning line we don't want if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) continue; fwrite($handle, $read); - if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok=1; - elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok=1; + if (preg_match('/'.preg_quote('-- Dump completed').'/i', $read)) $ok = 1; + elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES').'/i', $read)) $ok = 1; } pclose($handlein); } @@ -365,14 +365,14 @@ class Utils if ($compression == 'gz') gzclose($handle); if ($compression == 'bz') bzclose($handle); - if (! empty($conf->global->MAIN_UMASK)) + if (!empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); } else { $langs->load("errors"); dol_syslog("Failed to open file ".$outputfile, LOG_ERR); - $errormsg=$langs->trans("ErrorFailedToWriteInDir"); + $errormsg = $langs->trans("ErrorFailedToWriteInDir"); } // Get errorstring @@ -387,7 +387,7 @@ class Utils if ($compression == 'none') fclose($handle); if ($compression == 'gz') gzclose($handle); if ($compression == 'bz') bzclose($handle); - if ($ok && preg_match('/^-- MySql/i', $errormsg)) $errormsg=''; // Pas erreur + if ($ok && preg_match('/^-- MySql/i', $errormsg)) $errormsg = ''; // Pas erreur else { // Renommer fichier sortie en fichier erreur @@ -395,10 +395,10 @@ class Utils @dol_delete_file($outputerror, 1, 0, 0, null, false, 0); @rename($outputfile, $outputerror); // Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide - if (! $errormsg) + if (!$errormsg) { $langs->load("errors"); - $errormsg=$langs->trans("ErrorFailedToRunExternalCommand"); + $errormsg = $langs->trans("ErrorFailedToRunExternalCommand"); } } } @@ -416,9 +416,9 @@ class Utils $outputfile = $outputdir.'/'.$file; $outputfiletemp = $outputfile.'-TMP.sql'; // for compression format, we add extension - $compression=$compression ? $compression : 'none'; - if ($compression == 'gz') $outputfile.='.gz'; - if ($compression == 'bz') $outputfile.='.bz2'; + $compression = $compression ? $compression : 'none'; + if ($compression == 'gz') $outputfile .= '.gz'; + if ($compression == 'bz') $outputfile .= '.bz2'; $outputerror = $outputfile.'.err'; dol_mkdir($conf->admin->dir_output.'/backup'); @@ -440,52 +440,52 @@ class Utils // POSTGRESQL if ($type == 'postgresql' || $type == 'pgsql') { - $cmddump=$conf->global->SYSTEMTOOLS_POSTGRESQLDUMP; + $cmddump = $conf->global->SYSTEMTOOLS_POSTGRESQLDUMP; $outputfile = $outputdir.'/'.$file; // for compression format, we add extension - $compression=$compression ? $compression : 'none'; - if ($compression == 'gz') $outputfile.='.gz'; - if ($compression == 'bz') $outputfile.='.bz2'; + $compression = $compression ? $compression : 'none'; + if ($compression == 'gz') $outputfile .= '.gz'; + if ($compression == 'bz') $outputfile .= '.bz2'; $outputerror = $outputfile.'.err'; dol_mkdir($conf->admin->dir_output.'/backup'); // Parameteres execution $command = $cmddump; - $command = preg_replace('/(\$|%)/', '', $command); // We removed chars that can be used to inject vars that contains space inside path of command without seeing there is a space to bypass the escapeshellarg. - if (preg_match("/\s/", $command)) $command=escapeshellarg($command); // If there is spaces, we add quotes on command to be sure $command is only a program and not a program+parameters + $command = preg_replace('/(\$|%)/', '', $command); // We removed chars that can be used to inject vars that contains space inside path of command without seeing there is a space to bypass the escapeshellarg. + if (preg_match("/\s/", $command)) $command = escapeshellarg($command); // If there is spaces, we add quotes on command to be sure $command is only a program and not a program+parameters //$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass); //$param="-F c"; - $param="-F p"; - $param.=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host; - $param.=" -U ".$dolibarr_main_db_user; - if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port; - if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.=" --disable-dollar-quoting"; - if (GETPOST("drop_database")) $param.=" -c -C"; + $param = "-F p"; + $param .= " --no-tablespaces --inserts -h ".$dolibarr_main_db_host; + $param .= " -U ".$dolibarr_main_db_user; + if (!empty($dolibarr_main_db_port)) $param .= " -p ".$dolibarr_main_db_port; + if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param .= " --disable-dollar-quoting"; + if (GETPOST("drop_database")) $param .= " -c -C"; if (GETPOST("sql_structure")) { - if (GETPOST("drop")) $param.=" --add-drop-table"; - if (! GETPOST("sql_data")) $param.=" -s"; + if (GETPOST("drop")) $param .= " --add-drop-table"; + if (!GETPOST("sql_data")) $param .= " -s"; } if (GETPOST("sql_data")) { - if (! GETPOST("sql_structure")) $param.=" -a"; - if (GETPOST("showcolumns")) $param.=" -c"; + if (!GETPOST("sql_structure")) $param .= " -a"; + if (GETPOST("showcolumns")) $param .= " -c"; } - $param.=' -f "'.$outputfile.'"'; + $param .= ' -f "'.$outputfile.'"'; //if ($compression == 'none') - if ($compression == 'gz') $param.=' -Z 9'; + if ($compression == 'gz') $param .= ' -Z 9'; //if ($compression == 'bz') - $paramcrypted=$param; - $paramclear=$param; + $paramcrypted = $param; + $paramclear = $param; /*if (! empty($dolibarr_main_db_pass)) { $paramcrypted.=" -W".preg_replace('/./i','*',$dolibarr_main_db_pass); $paramclear.=" -W".$dolibarr_main_db_pass; }*/ - $paramcrypted.=" -w ".$dolibarr_main_db_name; - $paramclear.=" -w ".$dolibarr_main_db_name; + $paramcrypted .= " -w ".$dolibarr_main_db_name; + $paramclear .= " -w ".$dolibarr_main_db_name; $this->output = ""; $this->result = array("commandbackuplastdone" => "", "commandbackuptorun" => $command." ".$paramcrypted); @@ -495,8 +495,8 @@ class Utils if ($keeplastnfiles > 0) { $tmpfiles = dol_dir_list($conf->admin->dir_output.'/backup', 'files', 0, '', '(\.err|\.old|\.sav)$', 'date', SORT_DESC); - $i=0; - foreach($tmpfiles as $key => $val) + $i = 0; + foreach ($tmpfiles as $key => $val) { $i++; if ($i <= $keeplastnfiles) continue; @@ -525,15 +525,15 @@ class Utils $output = ''; $error = ''; - $command=escapeshellcmd($command); - $command.=" 2>&1"; + $command = escapeshellcmd($command); + $command .= " 2>&1"; - if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN; - if (empty($execmethod)) $execmethod=1; + if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod = $conf->global->MAIN_EXEC_USE_POPEN; + if (empty($execmethod)) $execmethod = 1; //$execmethod=1; dol_syslog("Utils::executeCLI execmethod=".$execmethod." system:".$command, LOG_DEBUG); - $output_arr=array(); + $output_arr = array(); if ($execmethod == 1) { @@ -558,20 +558,20 @@ class Utils { $read = fgets($handlein); fwrite($handle, $read); - $output_arr[]=$read; + $output_arr[] = $read; } pclose($handlein); fclose($handle); } - if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); + if (!empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); } // Update with result - if (is_array($output_arr) && count($output_arr)>0) + if (is_array($output_arr) && count($output_arr) > 0) { - foreach($output_arr as $val) + foreach ($output_arr as $val) { - $output.=$val.($execmethod == 2 ? '' : "\n"); + $output .= $val.($execmethod == 2 ? '' : "\n"); } } @@ -593,24 +593,24 @@ class Utils $error = 0; - $modulelowercase=strtolower($module); - $now=dol_now(); + $modulelowercase = strtolower($module); + $now = dol_now(); // Dir for module $dir = $dirins.'/'.$modulelowercase; // Zip file to build - $FILENAMEDOC=''; + $FILENAMEDOC = ''; // Load module dol_include_once($modulelowercase.'/core/modules/mod'.$module.'.class.php'); - $class='mod'.$module; + $class = 'mod'.$module; if (class_exists($class)) { try { $moduleobj = new $class($this->db); } - catch(Exception $e) + catch (Exception $e) { $error++; dol_print_error($e->getMessage()); @@ -624,12 +624,12 @@ class Utils exit; } - $arrayversion=explode('.', $moduleobj->version, 3); + $arrayversion = explode('.', $moduleobj->version, 3); if (count($arrayversion)) { - $FILENAMEASCII=strtolower($module).'.asciidoc'; - $FILENAMEDOC=strtolower($module).'.html'; - $FILENAMEDOCPDF=strtolower($module).'.pdf'; + $FILENAMEASCII = strtolower($module).'.asciidoc'; + $FILENAMEDOC = strtolower($module).'.html'; + $FILENAMEDOCPDF = strtolower($module).'.pdf'; $dirofmodule = dol_buildpath(strtolower($module), 0); $dirofmoduledoc = dol_buildpath(strtolower($module), 0).'/doc'; @@ -637,9 +637,9 @@ class Utils $outputfiledoc = $dirofmoduledoc.'/'.$FILENAMEDOC; if ($dirofmoduledoc) { - if (! dol_is_dir($dirofmoduledoc)) dol_mkdir($dirofmoduledoc); - if (! dol_is_dir($dirofmoduletmp)) dol_mkdir($dirofmoduletmp); - if (! is_writable($dirofmoduletmp)) + if (!dol_is_dir($dirofmoduledoc)) dol_mkdir($dirofmoduledoc); + if (!dol_is_dir($dirofmoduletmp)) dol_mkdir($dirofmoduletmp); + if (!is_writable($dirofmoduletmp)) { $this->error = 'Dir '.$dirofmoduletmp.' does not exists or is not writable'; return -1; @@ -656,31 +656,31 @@ class Utils dol_copy($dirofmodule.'/ChangeLog.md', $dirofmoduletmp.'/ChangeLog.md', 0, 1); // Replace into README.md and ChangeLog.md (in case they are included into documentation with tag __README__ or __CHANGELOG__) - $arrayreplacement=array(); - $arrayreplacement['/^#\s.*/m']=''; // Remove first level of title into .md files - $arrayreplacement['/^#/m']='##'; // Add on # to increase level + $arrayreplacement = array(); + $arrayreplacement['/^#\s.*/m'] = ''; // Remove first level of title into .md files + $arrayreplacement['/^#/m'] = '##'; // Add on # to increase level dolReplaceInFile($dirofmoduletmp.'/README.md', $arrayreplacement, '', 0, 0, 1); dolReplaceInFile($dirofmoduletmp.'/ChangeLog.md', $arrayreplacement, '', 0, 0, 1); - $destfile=$dirofmoduletmp.'/'.$FILENAMEASCII; + $destfile = $dirofmoduletmp.'/'.$FILENAMEASCII; $fhandle = fopen($destfile, 'w+'); if ($fhandle) { - $specs=dol_dir_list(dol_buildpath(strtolower($module).'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/')); + $specs = dol_dir_list(dol_buildpath(strtolower($module).'/doc', 0), 'files', 1, '(\.md|\.asciidoc)$', array('\/temp\/')); $i = 0; foreach ($specs as $spec) { - if (preg_match('/notindoc/', $spec['relativename'])) continue; // Discard file - if (preg_match('/example/', $spec['relativename'])) continue; // Discard file - if (preg_match('/disabled/', $spec['relativename'])) continue; // Discard file + if (preg_match('/notindoc/', $spec['relativename'])) continue; // Discard file + if (preg_match('/example/', $spec['relativename'])) continue; // Discard file + if (preg_match('/disabled/', $spec['relativename'])) continue; // Discard file $pathtofile = strtolower($module).'/doc/'.$spec['relativename']; - $format='asciidoc'; - if (preg_match('/\.md$/i', $spec['name'])) $format='markdown'; + $format = 'asciidoc'; + if (preg_match('/\.md$/i', $spec['name'])) $format = 'markdown'; $filecursor = @file_get_contents($spec['fullname']); if ($filecursor) @@ -698,13 +698,13 @@ class Utils fclose($fhandle); - $contentreadme=file_get_contents($dirofmoduletmp.'/README.md'); - $contentchangelog=file_get_contents($dirofmoduletmp.'/ChangeLog.md'); + $contentreadme = file_get_contents($dirofmoduletmp.'/README.md'); + $contentchangelog = file_get_contents($dirofmoduletmp.'/ChangeLog.md'); include DOL_DOCUMENT_ROOT.'/core/lib/parsemd.lib.php'; //var_dump($phpfileval['fullname']); - $arrayreplacement=array( + $arrayreplacement = array( 'mymodule'=>strtolower($module), 'MyModule'=>$module, 'MYMODULE'=>strtoupper($module), @@ -718,7 +718,7 @@ class Utils '__USER_FULLNAME__'=>$user->getFullName($langs), '__USER_EMAIL__'=>$user->email, '__YYYY-MM-DD__'=>dol_print_date($now, 'dayrfc'), - '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email?' <'.$user->email.'>':''), + '---Put here your own copyright and developer email---'=>dol_print_date($now, 'dayrfc').' '.$user->getFullName($langs).($user->email ? ' <'.$user->email.'>' : ''), '__DATA_SPECIFICATION__'=>'Not yet available', '__README__'=>dolMd2Asciidoc($contentreadme), '__CHANGELOG__'=>dolMd2Asciidoc($contentchangelog), @@ -735,8 +735,8 @@ class Utils $utils = new Utils($this->db); // Build HTML doc - $command=$conf->global->MODULEBUILDER_ASCIIDOCTOR.' '.$destfile.' -n -o '.$dirofmoduledoc.'/'.$FILENAMEDOC; - $outfile=$dirofmoduletmp.'/out.tmp'; + $command = $conf->global->MODULEBUILDER_ASCIIDOCTOR.' '.$destfile.' -n -o '.$dirofmoduledoc.'/'.$FILENAMEDOC; + $outfile = $dirofmoduletmp.'/out.tmp'; $resarray = $utils->executeCLI($command, $outfile); if ($resarray['result'] != '0') @@ -746,8 +746,8 @@ class Utils $result = ($resarray['result'] == 0) ? 1 : 0; // Build PDF doc - $command=$conf->global->MODULEBUILDER_ASCIIDOCTORPDF.' '.$destfile.' -n -o '.$dirofmoduledoc.'/'.$FILENAMEDOCPDF; - $outfile=$dirofmoduletmp.'/outpdf.tmp'; + $command = $conf->global->MODULEBUILDER_ASCIIDOCTORPDF.' '.$destfile.' -n -o '.$dirofmoduledoc.'/'.$FILENAMEDOCPDF; + $outfile = $dirofmoduletmp.'/outpdf.tmp'; $resarray = $utils->executeCLI($command, $outfile); if ($resarray['result'] != '0') { @@ -794,11 +794,11 @@ class Utils { global $conf; - if(empty($conf->loghandlers['mod_syslog_file'])) { // File Syslog disabled + if (empty($conf->loghandlers['mod_syslog_file'])) { // File Syslog disabled return 0; } - if(! function_exists('gzopen')) { + if (!function_exists('gzopen')) { $this->error = 'Support for gzopen not available in this PHP'; return -1; } @@ -819,7 +819,7 @@ class Utils $tabfiles = dol_dir_list(DOL_DATA_ROOT, 'files', 0, '^(dolibarr_.+|odt2pdf)\.log$'); // Also handle other log files like dolibarr_install.log $tabfiles[] = array('name' => $mainlog, 'path' => $mainlogdir); - foreach($tabfiles as $file) { + foreach ($tabfiles as $file) { $logname = $file['name']; $logpath = $file['path']; @@ -832,7 +832,7 @@ class Utils $gzfilestmp = dol_dir_list($logpath, 'files', 0, $filter); $gzfiles = array(); - foreach($gzfilestmp as $gzfile) { + foreach ($gzfilestmp as $gzfile) { $tabmatches = array(); preg_match('/'.$filter.'/i', $gzfile['name'], $tabmatches); @@ -843,15 +843,15 @@ class Utils krsort($gzfiles, SORT_NUMERIC); - foreach($gzfiles as $numsave => $dummy) { - if (dol_is_file($logpath.'/'.$logname.'.'.($numsave+1).'.gz')) { + foreach ($gzfiles as $numsave => $dummy) { + if (dol_is_file($logpath.'/'.$logname.'.'.($numsave + 1).'.gz')) { return -2; } - if($numsave >= $nbSaves) { + if ($numsave >= $nbSaves) { dol_delete_file($logpath.'/'.$logname.'.'.$numsave.'.gz', 0, 0, 0, null, false, 0); } else { - dol_move($logpath.'/'.$logname.'.'.$numsave.'.gz', $logpath.'/'.$logname.'.'.($numsave+1).'.gz', 0, 1, 0, 0); + dol_move($logpath.'/'.$logname.'.'.$numsave.'.gz', $logpath.'/'.$logname.'.'.($numsave + 1).'.gz', 0, 1, 0, 0); } } @@ -872,14 +872,14 @@ class Utils return -4; } - while(! feof($sourcehandle)) { + while (!feof($sourcehandle)) { gzwrite($gzfilehandle, fread($sourcehandle, 512 * 1024)); // Read 512 kB at a time } fclose($sourcehandle); gzclose($gzfilehandle); - @chmod($logpath.'/'.$logname.'.1.gz', octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK)); + @chmod($logpath.'/'.$logname.'.1.gz', octdec(empty($conf->global->MAIN_UMASK) ? '0664' : $conf->global->MAIN_UMASK)); } dol_delete_file($logpath.'/'.$logname, 0, 0, 0, null, false, 0); @@ -889,7 +889,7 @@ class Utils fclose($newlog); //var_dump($logpath.'/'.$logname." - ".octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK)); - @chmod($logpath.'/'.$logname, octdec(empty($conf->global->MAIN_UMASK)?'0664':$conf->global->MAIN_UMASK)); + @chmod($logpath.'/'.$logname, octdec(empty($conf->global->MAIN_UMASK) ? '0664' : $conf->global->MAIN_UMASK)); } } @@ -927,7 +927,7 @@ class Utils { $tables = array(); $result = $db->query('SHOW FULL TABLES WHERE Table_type = \'BASE TABLE\''); - while($row = $db->fetch_row($result)) + while ($row = $db->fetch_row($result)) { $tables[] = $row[0]; } @@ -943,7 +943,7 @@ class Utils { $langs->load("errors"); dol_syslog("Failed to open file ".$outputfile, LOG_ERR); - $errormsg=$langs->trans("ErrorFailedToWriteInDir"); + $errormsg = $langs->trans("ErrorFailedToWriteInDir"); return -1; } @@ -980,7 +980,7 @@ class Utils if (GETPOST("nobin_delayed")) $delayed = 'DELAYED '; // Process each table and print their definition + their datas - foreach($tables as $table) + foreach ($tables as $table) { // Saving the table structure fwrite($handle, "\n--\n-- Table structure for table `".$table."`\n--\n"); @@ -988,7 +988,7 @@ class Utils if (GETPOST("nobin_drop")) fwrite($handle, "DROP TABLE IF EXISTS `".$table."`;\n"); // Dropping table if exists prior to re create it fwrite($handle, "/*!40101 SET @saved_cs_client = @@character_set_client */;\n"); fwrite($handle, "/*!40101 SET character_set_client = utf8 */;\n"); - $resqldrop=$db->query('SHOW CREATE TABLE '.$table); + $resqldrop = $db->query('SHOW CREATE TABLE '.$table); $row2 = $db->fetch_row($resqldrop); if (empty($row2[1])) { @@ -1005,22 +1005,22 @@ class Utils if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` DISABLE KEYS;\n"); else fwrite($handle, "/*!40000 ALTER TABLE `".$table."` DISABLE KEYS */;\n"); - $sql='SELECT * FROM '.$table; // Here SELECT * is allowed because we don't have definition of columns to take + $sql = 'SELECT * FROM '.$table; // Here SELECT * is allowed because we don't have definition of columns to take $result = $db->query($sql); - while($row = $db->fetch_row($result)) + while ($row = $db->fetch_row($result)) { // For each row of data we print a line of INSERT fwrite($handle, 'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES ('); $columns = count($row); - for($j=0; $j<$columns; $j++) { + for ($j = 0; $j < $columns; $j++) { // Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier) if ($row[$j] == null && !is_string($row[$j])) { // IMPORTANT: if the field is NULL we set it NULL $row[$j] = 'NULL'; - } elseif(is_string($row[$j]) && $row[$j] == '') { + } elseif (is_string($row[$j]) && $row[$j] == '') { // if it's an empty string, we set it as an empty string $row[$j] = "''"; - } elseif(is_numeric($row[$j]) && !strcmp($row[$j], $row[$j]+0) ) { // test if it's a numeric type and the numeric version ($nb+0) == string version (eg: if we have 01, it's probably not a number but rather a string, else it would not have any leading 0) + } elseif (is_numeric($row[$j]) && !strcmp($row[$j], $row[$j] + 0)) { // test if it's a numeric type and the numeric version ($nb+0) == string version (eg: if we have 01, it's probably not a number but rather a string, else it would not have any leading 0) // if it's a number, we return it as-is // $row[$j] = $row[$j]; } else { // else for all other cases we escape the value and put quotes around @@ -1057,10 +1057,10 @@ class Utils /* Backup Procedure structure*/ // Write the footer (restore the previous database settings) - $sqlfooter="\n\n"; + $sqlfooter = "\n\n"; if (GETPOST("nobin_use_transaction")) $sqlfooter .= "COMMIT;\n"; if (GETPOST("nobin_disable_fk")) $sqlfooter .= "SET FOREIGN_KEY_CHECKS=1;\n"; - $sqlfooter.="\n\n-- Dump completed on ".date('Y-m-d G-i-s'); + $sqlfooter .= "\n\n-- Dump completed on ".date('Y-m-d G-i-s'); fwrite($handle, $sqlfooter); fclose($handle); diff --git a/htdocs/core/modules/export/export_excel2007new.modules.php b/htdocs/core/modules/export/export_excel2007new.modules.php index 3d27f78b39d..779f2240155 100644 --- a/htdocs/core/modules/export/export_excel2007new.modules.php +++ b/htdocs/core/modules/export/export_excel2007new.modules.php @@ -55,15 +55,15 @@ class ExportExcel2007new extends ModeleExports public $version_lib; - public $workbook; // Handle file + public $workbook; // Handle file - public $worksheet; // Handle sheet + public $worksheet; // Handle sheet public $row; public $col; - public $file; // To save filename + public $file; // To save filename /** @@ -76,15 +76,15 @@ class ExportExcel2007new extends ModeleExports global $conf, $langs; $this->db = $db; - $this->id='excel2007new'; // Same value then xxx in file name export_xxx.modules.php - $this->label='Excel 2007'; // Label of driver + $this->id = 'excel2007new'; // Same value then xxx in file name export_xxx.modules.php + $this->label = 'Excel 2007'; // Label of driver $this->desc = $langs->trans('Excel2007FormatDesc'); - $this->extension='xlsx'; // Extension for generated file by this driver - $this->picto='mime/xls'; // Picto - $this->version='1.30'; // Driver version - $this->phpmin = array(5,6); // Minimum version of PHP required by module + $this->extension = 'xlsx'; // Extension for generated file by this driver + $this->picto = 'mime/xls'; // Picto + $this->version = '1.30'; // Driver version + $this->phpmin = array(5, 6); // Minimum version of PHP required by module - $this->disabled = (in_array(constant('PHPEXCEL_PATH'), array('disabled','disabled/'))?1:0); // A condition to disable module (used for native debian packages) + $this->disabled = (in_array(constant('PHPEXCEL_PATH'), array('disabled', 'disabled/')) ? 1 : 0); // A condition to disable module (used for native debian packages) if (empty($this->disabled)) { @@ -92,11 +92,11 @@ class ExportExcel2007new extends ModeleExports //require_once PHPEXCEL_PATH.'PHPExcel/Style/Alignment.php'; //$this->label_lib='PhpExcel'; require_once PHPEXCELNEW_PATH.'Spreadsheet.php'; - $this->label_lib='PhpSpreadSheet'; - $this->version_lib='1.6.0'; // No way to get info from library + $this->label_lib = 'PhpSpreadSheet'; + $this->version_lib = '1.6.0'; // No way to get info from library } - $this->row=0; + $this->row = 0; } /** @@ -181,17 +181,17 @@ class ExportExcel2007new extends ModeleExports public function open_file($file, $outputlangs) { // phpcs:enable - global $user,$conf,$langs; + global $user, $conf, $langs; - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) + if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) { - $outputlangs->charset_output='ISO-8859-1'; // Because Excel 5 format is ISO + $outputlangs->charset_output = 'ISO-8859-1'; // Because Excel 5 format is ISO } dol_syslog(get_class($this)."::open_file file=".$file); - $this->file=$file; + $this->file = $file; - $ret=1; + $ret = 1; $outputlangs->load("exports"); @@ -203,10 +203,10 @@ class ExportExcel2007new extends ModeleExports if ($this->id == 'excel2007new') { - if (! class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive + if (!class_exists('ZipArchive')) // For Excel2007, PHPExcel need ZipArchive { $langs->load("errors"); - $this->error=$langs->trans('ErrorPHPNeedModule', 'zip'); + $this->error = $langs->trans('ErrorPHPNeedModule', 'zip'); return -1; } } @@ -261,23 +261,23 @@ class ExportExcel2007new extends ModeleExports $this->workbook->getActiveSheet()->getStyle('1')->getFont()->setBold(true); $this->workbook->getActiveSheet()->getStyle('1')->getAlignment()->setHorizontal(PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT); - $this->col=1; - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) { - $this->col=0; + $this->col = 1; + if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) { + $this->col = 0; } - foreach($array_selected_sorted as $code => $value) + foreach ($array_selected_sorted as $code => $value) { - $alias=$array_export_fields_label[$code]; + $alias = $array_export_fields_label[$code]; //print "dd".$alias; if (empty($alias)) dol_print_error('', 'Bad value for field with code='.$code.'. Try to redefine export.'); - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) + if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) { $this->worksheet->write($this->row, $this->col, $outputlangs->transnoentities($alias), $formatheader); } else { - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $outputlangs->transnoentities($alias)); - if (! empty($array_types[$code]) && in_array($array_types[$code], array('Date','Numeric','TextAuto'))) // Set autowidth for some types + $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, $outputlangs->transnoentities($alias)); + if (!empty($array_types[$code]) && in_array($array_types[$code], array('Date', 'Numeric', 'TextAuto'))) // Set autowidth for some types { $this->workbook->getActiveSheet()->getColumnDimension($this->column2Letter($this->col + 1))->setAutoSize(true); } @@ -304,22 +304,22 @@ class ExportExcel2007new extends ModeleExports global $conf; // Define first row - $this->col=1; - if (! empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) { - $this->col=0; + $this->col = 1; + if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) { + $this->col = 0; } - $reg=array(); + $reg = array(); - foreach($array_selected_sorted as $code => $value) + foreach ($array_selected_sorted as $code => $value) { - if (strpos($code, ' as ') == 0) $alias=str_replace(array('.','-','(',')'), '_', $code); - else $alias=substr($code, strpos($code, ' as ') + 4); + if (strpos($code, ' as ') == 0) $alias = str_replace(array('.', '-', '(', ')'), '_', $code); + else $alias = substr($code, strpos($code, ' as ') + 4); if (empty($alias)) dol_print_error('', 'Bad value for field with code='.$code.'. Try to redefine export.'); - $newvalue=$objp->$alias; + $newvalue = $objp->$alias; - $newvalue=$this->excel_clean($newvalue); - $typefield=isset($array_types[$code])?$array_types[$code]:''; + $newvalue = $this->excel_clean($newvalue); + $typefield = isset($array_types[$code]) ? $array_types[$code] : ''; if (preg_match('/^Select:/i', $typefield, $reg) && $typefield = substr($typefield, 7)) { @@ -331,25 +331,25 @@ class ExportExcel2007new extends ModeleExports // Traduction newvalue if (preg_match('/^\((.*)\)$/i', $newvalue, $reg)) { - $newvalue=$outputlangs->transnoentities($reg[1]); + $newvalue = $outputlangs->transnoentities($reg[1]); } else { - $newvalue=$outputlangs->convToOutputCharset($newvalue); + $newvalue = $outputlangs->convToOutputCharset($newvalue); } if (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/i', $newvalue)) { - $newvalue=dol_stringtotime($newvalue); - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($newvalue)); - $coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate(); + $newvalue = dol_stringtotime($newvalue); + $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($newvalue)); + $coord = $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row + 1)->getCoordinate(); $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd'); } elseif (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]$/i', $newvalue)) { - $newvalue=dol_stringtotime($newvalue); - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($newvalue)); - $coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate(); + $newvalue = dol_stringtotime($newvalue); + $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($newvalue)); + $coord = $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row + 1)->getCoordinate(); $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd h:mm:ss'); } else @@ -357,14 +357,14 @@ class ExportExcel2007new extends ModeleExports if ($typefield == 'Text' || $typefield == 'TextAuto') { //$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->setValueExplicit($newvalue, PHPExcel_Cell_DataType::TYPE_STRING); - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, (string) $newvalue); - $coord=$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->getCoordinate(); + $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, (string) $newvalue); + $coord = $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row + 1)->getCoordinate(); $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('@'); $this->workbook->getActiveSheet()->getStyle($coord)->getAlignment()->setHorizontal(PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT); } else { - $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row+1, $newvalue); + $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, $newvalue); } } $this->col++; @@ -419,7 +419,7 @@ class ExportExcel2007new extends ModeleExports { // phpcs:enable // Rule Dolibarr: No HTML - $newvalue=dol_string_nohtmltag($newvalue); + $newvalue = dol_string_nohtmltag($newvalue); return $newvalue; } @@ -440,7 +440,7 @@ class ExportExcel2007new extends ModeleExports while ($c != 0) { $p = ($c - 1) % 26; $c = intval(($c - $p) / 26); - $letter = chr(65 + $p) . $letter; + $letter = chr(65 + $p).$letter; } return $letter; diff --git a/htdocs/core/modules/fichinter/mod_arctic.php b/htdocs/core/modules/fichinter/mod_arctic.php index 3087864b38a..eb01e36f652 100644 --- a/htdocs/core/modules/fichinter/mod_arctic.php +++ b/htdocs/core/modules/fichinter/mod_arctic.php @@ -25,7 +25,7 @@ * \ingroup fiche intervention * \brief File with Arctic numbering module for interventions */ -require_once DOL_DOCUMENT_ROOT .'/core/modules/fichinter/modules_fichinter.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php'; /** * Class to manage numbering of intervention cards with rule Artic. @@ -36,7 +36,7 @@ class mod_arctic extends ModeleNumRefFicheinter * Dolibarr version of the loaded document * @var string */ - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' /** * @var string Error message @@ -48,12 +48,12 @@ class mod_arctic extends ModeleNumRefFicheinter * @deprecated * @see name */ - public $nom='arctic'; + public $nom = 'arctic'; /** * @var string model name */ - public $name='arctic'; + public $name = 'arctic'; /** @@ -70,28 +70,28 @@ class mod_arctic extends ModeleNumRefFicheinter $form = new Form($db); $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; - $texte.= '
'; - $texte.= ''; - $texte.= ''; - $texte.= ''; - $texte.= '
 '; else print ''; if ($modecompta != 'BOOKKEEPING') print ''; print $annee; - if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee+1); + if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print '-'.($annee + 1); if ($modecompta != 'BOOKKEEPING') print ''; print ' 
'.$langs->trans("Month").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").'
".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, 2000), "%B")."'; if ($cum_ht[$case]) { - $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre. - print ''.price($cum_ht[$case], 1).''; + $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. + print ''.price($cum_ht[$case], 1).''; } else { @@ -341,8 +341,8 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) print ''; if ($cum[$case]) { - $now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre. - if ($modecompta != 'BOOKKEEPING') print ''; + $now_show_delta = 1; // On a trouve le premier mois de la premiere annee generant du chiffre. + if ($modecompta != 'BOOKKEEPING') print ''; print price($cum[$case], 1); if ($modecompta != 'BOOKKEEPING') print ''; } @@ -358,24 +358,24 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) { if ($cum[$caseprev] && $cum[$case]) { - $percent=(round(($cum[$case]-$cum[$caseprev])/$cum[$caseprev], 4)*100); + $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100); //print "X $cum[$case] - $cum[$caseprev] - $cum[$caseprev] - $percent X"; - print ''.($percent>=0?"+$percent":"$percent").'%'.($percent >= 0 ? "+$percent" : "$percent").'%-100%+Inf%-+0%- 
'.$langs->trans("Total").''.($total_ht[$annee]?price($total_ht[$annee]):"0")."'.($total_ht[$annee] ?price($total_ht[$annee]) : "0")."'.($total[$annee]?price($total[$annee]):"0")."'.($total[$annee] ?price($total[$annee]) : "0")."'.($percent>=0?"+$percent":"$percent").'%'.($percent >= 0 ? "+$percent" : "$percent").'%-100%+'.$langs->trans('Inf').'%+0%
'; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= ''; + $texte .= '
'; - $tooltip=$langs->trans("GenericMaskCodes", $langs->transnoentities("InterventionCard"), $langs->transnoentities("InterventionCard")); - $tooltip.=$langs->trans("GenericMaskCodes2"); - $tooltip.=$langs->trans("GenericMaskCodes3"); - $tooltip.=$langs->trans("GenericMaskCodes4a", $langs->transnoentities("InterventionCard"), $langs->transnoentities("InterventionCard")); - $tooltip.=$langs->trans("GenericMaskCodes5"); + $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("InterventionCard"), $langs->transnoentities("InterventionCard")); + $tooltip .= $langs->trans("GenericMaskCodes2"); + $tooltip .= $langs->trans("GenericMaskCodes3"); + $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("InterventionCard"), $langs->transnoentities("InterventionCard")); + $tooltip .= $langs->trans("GenericMaskCodes5"); // Setting the prefix - $texte.= ''; - $texte.= ''; + $texte .= ''; + $texte .= ''; - $texte.= ''; + $texte .= ''; - $texte.= ''; + $texte .= ''; - $texte.= '
'.$langs->trans("Mask").':'.$form->textwithpicto('', $tooltip, 1, 1).'
'.$langs->trans("Mask").':'.$form->textwithpicto('', $tooltip, 1, 1).'   
'; - $texte.= ''; + $texte .= '
'; + $texte .= ''; return $texte; } @@ -103,14 +103,14 @@ class mod_arctic extends ModeleNumRefFicheinter */ public function getExample() { - global $conf,$langs,$mysoc; + global $conf, $langs, $mysoc; - $old_code_client=$mysoc->code_client; - $mysoc->code_client='CCCCCCCCCC'; + $old_code_client = $mysoc->code_client; + $mysoc->code_client = 'CCCCCCCCCC'; $numExample = $this->getNextValue($mysoc, ''); - $mysoc->code_client=$old_code_client; + $mysoc->code_client = $old_code_client; - if (! $numExample) + if (!$numExample) { $numExample = $langs->trans('NotConfigured'); } @@ -126,20 +126,20 @@ class mod_arctic extends ModeleNumRefFicheinter */ public function getNextValue($objsoc = 0, $object = '') { - global $db,$conf; + global $db, $conf; - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; // We define the search criteria of the counter - $mask=$conf->global->FICHINTER_ARTIC_MASK; + $mask = $conf->global->FICHINTER_ARTIC_MASK; - if (! $mask) + if (!$mask) { - $this->error='NotConfigured'; + $this->error = 'NotConfigured'; return 0; } - $numFinal=get_next_value($db, $mask, 'fichinter', 'ref', '', $objsoc, $object->datec); + $numFinal = get_next_value($db, $mask, 'fichinter', 'ref', '', $objsoc, $object->datec); return $numFinal; } diff --git a/htdocs/core/modules/modEmailCollector.class.php b/htdocs/core/modules/modEmailCollector.class.php index 370c2ac2cec..cba555391d7 100644 --- a/htdocs/core/modules/modEmailCollector.class.php +++ b/htdocs/core/modules/modEmailCollector.class.php @@ -23,7 +23,7 @@ * \ingroup emailcollector * \brief Description and activation file for module emailcollector */ -include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; +include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; /** @@ -38,7 +38,7 @@ class modEmailCollector extends DolibarrModules */ public function __construct($db) { - global $langs,$conf; + global $langs, $conf; $this->db = $db; @@ -70,7 +70,7 @@ class modEmailCollector extends DolibarrModules // Name of image file used for this module. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' - $this->picto='email'; + $this->picto = 'email'; // Defined all module parts (triggers, login, substitutions, menus, css, etc...) // for default path (eg: /dav/core/xxxxx) (0=disable, 1=enable) @@ -86,15 +86,15 @@ class modEmailCollector extends DolibarrModules $this->config_page_url = array("emailcollector_list.php"); // Dependencies - $this->hidden = false; // A condition to hide module - $this->depends = array('always'=>'modCron'); // List of module class names as string that must be enabled if this module is enabled - $this->requiredby = array(); // List of module ids to disable if this one is disabled - $this->conflictwith = array(); // List of module class names as string this module is in conflict with + $this->hidden = false; // A condition to hide module + $this->depends = array('always'=>'modCron'); // List of module class names as string that must be enabled if this module is enabled + $this->requiredby = array(); // List of module ids to disable if this one is disabled + $this->conflictwith = array(); // List of module class names as string this module is in conflict with $this->langfiles = array("admin"); - $this->phpmin = array(5,4); // Minimum version of PHP required by module - $this->need_dolibarr_version = array(7,0); // Minimum version of Dolibarr required by module - $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) - $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) + $this->phpmin = array(5, 4); // Minimum version of PHP required by module + $this->need_dolibarr_version = array(7, 0); // Minimum version of Dolibarr required by module + $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) + $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) //$this->automatic_activation = array('FR'=>'davWasAutomaticallyActivatedBecauseOfYourCountryChoice'); //$this->always_enabled = true; // If true, can't be disabled @@ -108,10 +108,10 @@ class modEmailCollector extends DolibarrModules ); - if (! isset($conf->emailcollector) || ! isset($conf->emailcollector->enabled)) + if (!isset($conf->emailcollector) || !isset($conf->emailcollector->enabled)) { - $conf->emailcollector=new stdClass(); - $conf->emailcollector->enabled=0; + $conf->emailcollector = new stdClass(); + $conf->emailcollector->enabled = 0; } @@ -145,7 +145,7 @@ class modEmailCollector extends DolibarrModules // Dictionaries - $this->dictionaries=array(); + $this->dictionaries = array(); /* Example: $this->dictionaries=array( 'langs'=>'mylangfile@dav', @@ -179,7 +179,7 @@ class modEmailCollector extends DolibarrModules // Permissions - $this->rights = array(); // Permission array used by this module + $this->rights = array(); // Permission array used by this module /* $r=0; @@ -205,8 +205,8 @@ class modEmailCollector extends DolibarrModules */ // Main menu entries - $this->menu = array(); // List of menus to add - $r=0; + $this->menu = array(); // List of menus to add + $r = 0; // Add here entries to declare new menus diff --git a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php index 490727f9521..760a2101087 100644 --- a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php +++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php @@ -45,7 +45,7 @@ class InterfaceNotification extends DolibarrTriggers public $picto = 'email'; // @todo Defined also into notify.class.php) - public $listofmanagedevents=array( + public $listofmanagedevents = array( 'BILL_VALIDATE', 'BILL_PAYED', 'ORDER_VALIDATE', @@ -76,12 +76,12 @@ class InterfaceNotification extends DolibarrTriggers */ public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) { - if (empty($conf->notification->enabled)) return 0; // Module not active, we do nothing + if (empty($conf->notification->enabled)) return 0; // Module not active, we do nothing - require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; $notify = new Notify($this->db); - if (! in_array($action, $notify->arrayofnotifsupported)) return 0; + if (!in_array($action, $notify->arrayofnotifsupported)) return 0; dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); @@ -100,42 +100,42 @@ class InterfaceNotification extends DolibarrTriggers { global $conf; - $ret=array(); + $ret = array(); $sql = "SELECT rowid, code, label, description, elementtype"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger"; - $sql.= $this->db->order("rang, elementtype, code"); + $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger"; + $sql .= $this->db->order("rang, elementtype, code"); dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $num=$this->db->num_rows($resql); - $i=0; + $num = $this->db->num_rows($resql); + $i = 0; while ($i < $num) { - $obj=$this->db->fetch_object($resql); + $obj = $this->db->fetch_object($resql); - $qualified=0; + $qualified = 0; // Check is this event is supported by notification module - if (in_array($obj->code, $this->listofmanagedevents)) $qualified=1; + if (in_array($obj->code, $this->listofmanagedevents)) $qualified = 1; // Check if module for this event is active if ($qualified) { //print 'xx'.$obj->code; - $element=$obj->elementtype; + $element = $obj->elementtype; // Exclude events if related module is disabled - if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) $qualified=0; - elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) $qualified=0; - elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) $qualified=0; - elseif ($element == 'shipping' && empty($conf->expedition->enabled)) $qualified=0; - elseif ($element == 'member' && empty($conf->adherent->enabled)) $qualified=0; - elseif (! in_array($element, array('order_supplier','invoice_supplier','withdraw','shipping','member','expensereport')) && empty($conf->$element->enabled)) $qualified=0; + if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) $qualified = 0; + elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) $qualified = 0; + elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) $qualified = 0; + elseif ($element == 'shipping' && empty($conf->expedition->enabled)) $qualified = 0; + elseif ($element == 'member' && empty($conf->adherent->enabled)) $qualified = 0; + elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member', 'expensereport')) && empty($conf->$element->enabled)) $qualified = 0; } if ($qualified) { - $ret[]=array('rowid'=>$obj->rowid,'code'=>$obj->code,'label'=>$obj->label,'description'=>$obj->description,'elementtype'=>$obj->elementtype); + $ret[] = array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$obj->label, 'description'=>$obj->description, 'elementtype'=>$obj->elementtype); } $i++; diff --git a/htdocs/don/admin/donation.php b/htdocs/don/admin/donation.php index b5c775207ba..4809dfc4253 100644 --- a/htdocs/don/admin/donation.php +++ b/htdocs/don/admin/donation.php @@ -26,11 +26,11 @@ * \brief Page to setup the donation module */ require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; -require_once DOL_DOCUMENT_ROOT . '/core/lib/donation.lib.php'; -require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php'; -require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; -if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; +if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; // Load translation files required by the page $langs->loadLangs(array('admin', 'donations', 'accountancy', 'other')); @@ -42,7 +42,7 @@ $value = GETPOST('value'); $label = GETPOST('label', 'alpha'); $scandir = GETPOST('scan_dir', 'alpha'); -$type='donation'; +$type = 'donation'; /* @@ -51,13 +51,13 @@ $type='donation'; if ($action == 'specimen') { - $modele=GETPOST('module', 'alpha'); + $modele = GETPOST('module', 'alpha'); $don = new Don($db); $don->initAsSpecimen(); // Search template files - $dir = DOL_DOCUMENT_ROOT . "/core/modules/dons/"; + $dir = DOL_DOCUMENT_ROOT."/core/modules/dons/"; $file = $modele.".modules.php"; if (file_exists($dir.$file)) { @@ -124,9 +124,9 @@ if ($action == 'set_DONATION_ACCOUNTINGACCOUNT') $res = dolibarr_set_const($db, "DONATION_ACCOUNTINGACCOUNT", $account, 'chaine', 0, '', $conf->entity); - if (! $res > 0) $error++; + if (!$res > 0) $error++; - if (! $error) + if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } @@ -138,13 +138,13 @@ if ($action == 'set_DONATION_ACCOUNTINGACCOUNT') if ($action == 'set_DONATION_MESSAGE') { - $freemessage = GETPOST('DONATION_MESSAGE', 'none'); // No alpha here, we want exact string + $freemessage = GETPOST('DONATION_MESSAGE', 'none'); // No alpha here, we want exact string $res = dolibarr_set_const($db, "DONATION_MESSAGE", $freemessage, 'chaine', 0, '', $conf->entity); - if (! $res > 0) $error++; + if (!$res > 0) $error++; - if (! $error) + if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } @@ -159,7 +159,7 @@ if ($action == 'set_DONATION_MESSAGE') */ if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) { - $code=$reg[1]; + $code = $reg[1]; if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) { header("Location: ".$_SERVER["PHP_SELF"]); @@ -173,7 +173,7 @@ if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) { - $code=$reg[1]; + $code = $reg[1]; if (dolibarr_del_const($db, $code, $conf->entity) > 0) { header("Location: ".$_SERVER["PHP_SELF"]); @@ -190,11 +190,11 @@ if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) */ $dir = "../../core/modules/dons/"; -$form=new Form($db); -if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); +$form = new Form($db); +if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); llxHeader('', $langs->trans("DonationsSetup"), 'DonConfiguration'); -$linkback=''.$langs->trans("BackToModuleList").''; +$linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("DonationsSetup"), $linkback, 'title_setup'); $head = donation_admin_prepare_head(); @@ -206,16 +206,16 @@ dol_fiche_head($head, 'general', $langs->trans("Donations"), -1, 'payment'); print load_fiche_titre($langs->trans("DonationsModels"), '', ''); // Defined the template definition table -$type='donation'; +$type = 'donation'; $def = array(); $sql = "SELECT nom"; -$sql.= " FROM ".MAIN_DB_PREFIX."document_model"; -$sql.= " WHERE type = '".$type."'"; -$resql=$db->query($sql); +$sql .= " FROM ".MAIN_DB_PREFIX."document_model"; +$sql .= " WHERE type = '".$type."'"; +$resql = $db->query($sql); if ($resql) { $i = 0; - $num_rows=$db->num_rows($resql); + $num_rows = $db->num_rows($resql); while ($i < $num_rows) { $array = $db->fetch_array($resql); @@ -240,22 +240,22 @@ print "\n"; clearstatcache(); -$handle=opendir($dir); +$handle = opendir($dir); if (is_resource($handle)) { - while (($file = readdir($handle))!==false) + while (($file = readdir($handle)) !== false) { if (preg_match('/\.modules\.php$/i', $file)) { - $name = substr($file, 0, dol_strlen($file) -12); - $classname = substr($file, 0, dol_strlen($file) -12); + $name = substr($file, 0, dol_strlen($file) - 12); + $classname = substr($file, 0, dol_strlen($file) - 12); require_once $dir.'/'.$file; - $module=new $classname($db); + $module = new $classname($db); // Show modules according to features level - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; if ($module->isEnabled()) @@ -305,15 +305,15 @@ if (is_resource($handle)) } // Info - $htmltooltip = ''.$langs->trans("Name").': '.$module->name; - $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); + $htmltooltip = ''.$langs->trans("Name").': '.$module->name; + $htmltooltip .= '
'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown")); if ($module->type == 'pdf') { - $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + $htmltooltip .= '
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; } - $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1); - $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1); + $htmltooltip .= '

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip .= '
'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1); + $htmltooltip .= '
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1); print ''; print $form->textwithpicto('', $htmltooltip, -1, 0); print ''; @@ -365,15 +365,15 @@ print "\n"; print ''; print ''; $label = $langs->trans("AccountAccounting"); -print ''; +print ''; print ''; -if (! empty($conf->accounting->enabled)) +if (!empty($conf->accounting->enabled)) { print $formaccounting->select_account($conf->global->DONATION_ACCOUNTINGACCOUNT, 'DONATION_ACCOUNTINGACCOUNT', 1, '', 1, 1); } else { - print ''; + print ''; } print ''; print ''; @@ -409,7 +409,7 @@ if (preg_match('/fr/i', $conf->global->MAIN_INFO_SOCIETE_COUNTRY)) print "\n"; print ''; - print '' . $langs->trans("DONATION_ART200") . ''; + print ''.$langs->trans("DONATION_ART200").''; print ''; if ($conf->use_javascript_ajax) { print ajax_constantonoff('DONATION_ART200'); @@ -420,7 +420,7 @@ if (preg_match('/fr/i', $conf->global->MAIN_INFO_SOCIETE_COUNTRY)) print ''; print ''; - print '' . $langs->trans("DONATION_ART238") . ''; + print ''.$langs->trans("DONATION_ART238").''; print ''; if ($conf->use_javascript_ajax) { print ajax_constantonoff('DONATION_ART238'); @@ -431,7 +431,7 @@ if (preg_match('/fr/i', $conf->global->MAIN_INFO_SOCIETE_COUNTRY)) print ''; print ''; - print '' . $langs->trans("DONATION_ART885") . ''; + print ''.$langs->trans("DONATION_ART885").''; print ''; if ($conf->use_javascript_ajax) { print ajax_constantonoff('DONATION_ART885'); diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index bd3e3a8ada9..baa362085c1 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -25,9 +25,9 @@ * \ingroup expensereport * \brief File to manage Expense Reports */ -require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; -require_once DOL_DOCUMENT_ROOT .'/expensereport/class/expensereport_ik.class.php'; -require_once DOL_DOCUMENT_ROOT .'/expensereport/class/expensereport_rule.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_rule.class.php'; /** * Class to manage Trips and Expenses @@ -37,12 +37,12 @@ class ExpenseReport extends CommonObject /** * @var string ID to identify managed object */ - public $element='expensereport'; + public $element = 'expensereport'; /** * @var string Name of table without prefix where object is stored */ - public $table_element='expensereport'; + public $table_element = 'expensereport'; public $table_element_line = 'expensereport_det'; public $fk_element = 'fk_expensereport'; @@ -52,14 +52,14 @@ class ExpenseReport extends CommonObject */ public $picto = 'trip'; - public $lines=array(); + public $lines = array(); public $date_debut; public $date_fin; public $status; - public $fk_statut; // -- 0=draft, 2=validated (attente approb), 4=canceled, 5=approved, 6=payed, 99=denied + public $fk_statut; // -- 0=draft, 2=validated (attente approb), 4=canceled, 5=approved, 6=payed, 99=denied public $fk_c_paiement; public $paid; @@ -75,7 +75,7 @@ class ExpenseReport extends CommonObject // Create public $date_create; - public $fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. + public $fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. // Update public $date_modif; @@ -91,16 +91,16 @@ class ExpenseReport extends CommonObject public $detail_cancel; public $fk_user_cancel; - public $fk_user_validator; // User that is defined to approve + public $fk_user_validator; // User that is defined to approve // Validation - public $date_valid; // User making validation + public $date_valid; // User making validation public $fk_user_valid; public $user_valid_infos; // Approve public $date_approve; - public $fk_user_approve; // User that has approved + public $fk_user_approve; // User that has approved // Paiement public $user_paid_infos; @@ -137,7 +137,7 @@ class ExpenseReport extends CommonObject const STATUS_CLOSED = 6; - public $fields=array( + public $fields = array( 'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10), 'ref' =>array('type'=>'varchar(50)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'showoncombobox'=>1, 'position'=>15), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>20), @@ -220,77 +220,77 @@ class ExpenseReport extends CommonObject // Check parameters if (empty($this->date_debut) || empty($this->date_fin)) { - $this->error=$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Date')); + $this->error = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Date')); return -1; } - $fuserid = $this->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. + $fuserid = $this->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. if (empty($fuserid)) $fuserid = $user->id; $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; - $sql.= "ref"; - $sql.= ",total_ht"; - $sql.= ",total_ttc"; - $sql.= ",total_tva"; - $sql.= ",date_debut"; - $sql.= ",date_fin"; - $sql.= ",date_create"; - $sql.= ",fk_user_author"; - $sql.= ",fk_user_validator"; - $sql.= ",fk_user_approve"; - $sql.= ",fk_user_modif"; - $sql.= ",fk_statut"; - $sql.= ",fk_c_paiement"; - $sql.= ",paid"; - $sql.= ",note_public"; - $sql.= ",note_private"; - $sql.= ",entity"; - $sql.= ") VALUES("; - $sql.= "'(PROV)'"; - $sql.= ", ".$this->total_ht; - $sql.= ", ".$this->total_ttc; - $sql.= ", ".$this->total_tva; - $sql.= ", '".$this->db->idate($this->date_debut)."'"; - $sql.= ", '".$this->db->idate($this->date_fin)."'"; - $sql.= ", '".$this->db->idate($now)."'"; - $sql.= ", ".$fuserid; - $sql.= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null"); - $sql.= ", ".($this->fk_user_approve > 0 ? $this->fk_user_approve:"null"); - $sql.= ", ".($this->fk_user_modif > 0 ? $this->fk_user_modif:"null"); - $sql.= ", ".($this->fk_statut > 1 ? $this->fk_statut:0); - $sql.= ", ".($this->modepaymentid?$this->modepaymentid:"null"); - $sql.= ", 0"; - $sql.= ", ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); - $sql.= ", ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); - $sql.= ", ".$conf->entity; - $sql.= ")"; + $sql .= "ref"; + $sql .= ",total_ht"; + $sql .= ",total_ttc"; + $sql .= ",total_tva"; + $sql .= ",date_debut"; + $sql .= ",date_fin"; + $sql .= ",date_create"; + $sql .= ",fk_user_author"; + $sql .= ",fk_user_validator"; + $sql .= ",fk_user_approve"; + $sql .= ",fk_user_modif"; + $sql .= ",fk_statut"; + $sql .= ",fk_c_paiement"; + $sql .= ",paid"; + $sql .= ",note_public"; + $sql .= ",note_private"; + $sql .= ",entity"; + $sql .= ") VALUES("; + $sql .= "'(PROV)'"; + $sql .= ", ".$this->total_ht; + $sql .= ", ".$this->total_ttc; + $sql .= ", ".$this->total_tva; + $sql .= ", '".$this->db->idate($this->date_debut)."'"; + $sql .= ", '".$this->db->idate($this->date_fin)."'"; + $sql .= ", '".$this->db->idate($now)."'"; + $sql .= ", ".$fuserid; + $sql .= ", ".($this->fk_user_validator > 0 ? $this->fk_user_validator : "null"); + $sql .= ", ".($this->fk_user_approve > 0 ? $this->fk_user_approve : "null"); + $sql .= ", ".($this->fk_user_modif > 0 ? $this->fk_user_modif : "null"); + $sql .= ", ".($this->fk_statut > 1 ? $this->fk_statut : 0); + $sql .= ", ".($this->modepaymentid ? $this->modepaymentid : "null"); + $sql .= ", 0"; + $sql .= ", ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null"); + $sql .= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null"); + $sql .= ", ".$conf->entity; + $sql .= ")"; $result = $this->db->query($sql); if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); - $this->ref='(PROV'.$this->id.')'; + $this->ref = '(PROV'.$this->id.')'; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); $error++; } - if (! $error) + if (!$error) { - if (is_array($this->lines) && count($this->lines)>0) + if (is_array($this->lines) && count($this->lines) > 0) { foreach ($this->lines as $i => $val) { //$newndfline=new ExpenseReportLine($this->db); - $newndfline=$this->lines[$i]; - $newndfline->fk_expensereport=$this->id; - $result=$newndfline->insert(); + $newndfline = $this->lines[$i]; + $newndfline->fk_expensereport = $this->id; + $result = $newndfline->insert(); if ($result < 0) { $this->error = $newndfline->error; @@ -301,21 +301,21 @@ class ExpenseReport extends CommonObject } } - if (! $error) + if (!$error) { - $result=$this->insertExtraFields(); + $result = $this->insertExtraFields(); if ($result < 0) $error++; } - if (! $error) + if (!$error) { - $result=$this->update_price(); + $result = $this->update_price(); if ($result > 0) { if (!$notrigger) { // Call trigger - $result=$this->call_trigger('EXPENSE_REPORT_CREATE', $user); + $result = $this->call_trigger('EXPENSE_REPORT_CREATE', $user); if ($result < 0) { $error++; @@ -349,7 +349,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->db->lasterror()." sql=".$sql; + $this->error = $this->db->lasterror()." sql=".$sql; $this->db->rollback(); return -1; } @@ -367,7 +367,7 @@ class ExpenseReport extends CommonObject { global $hookmanager; - $error=0; + $error = 0; if (empty($fk_user_author)) $fk_user_author = $user->id; @@ -380,31 +380,31 @@ class ExpenseReport extends CommonObject // Load source object $objFrom = clone $this; - $this->id=0; + $this->id = 0; $this->ref = ''; - $this->status=0; - $this->fk_statut=0; + $this->status = 0; + $this->fk_statut = 0; // Clear fields - $this->fk_user_author = $fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. + $this->fk_user_author = $fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. $this->fk_user_valid = ''; - $this->date_create = ''; + $this->date_create = ''; $this->date_creation = ''; $this->date_validation = ''; // Create clone $this->context['createfromclone'] = 'createfromclone'; - $result=$this->create($user); + $result = $this->create($user); if ($result < 0) $error++; - if (! $error) + if (!$error) { // Hook of thirdparty module if (is_object($hookmanager)) { - $parameters=array('objFrom'=>$objFrom); - $action=''; - $reshook=$hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $parameters = array('objFrom'=>$objFrom); + $action = ''; + $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) $error++; } } @@ -412,7 +412,7 @@ class ExpenseReport extends CommonObject unset($this->context['createfromclone']); // End - if (! $error) + if (!$error) { $this->db->commit(); return $this->id; @@ -441,25 +441,25 @@ class ExpenseReport extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql.= " total_ht = ".$this->total_ht; - $sql.= " , total_ttc = ".$this->total_ttc; - $sql.= " , total_tva = ".$this->total_tva; - $sql.= " , date_debut = '".$this->db->idate($this->date_debut)."'"; - $sql.= " , date_fin = '".$this->db->idate($this->date_fin)."'"; + $sql .= " total_ht = ".$this->total_ht; + $sql .= " , total_ttc = ".$this->total_ttc; + $sql .= " , total_tva = ".$this->total_tva; + $sql .= " , date_debut = '".$this->db->idate($this->date_debut)."'"; + $sql .= " , date_fin = '".$this->db->idate($this->date_fin)."'"; if ($userofexpensereport && is_object($userofexpensereport)) { - $sql.= " , fk_user_author = ".($userofexpensereport->id > 0 ? "'".$userofexpensereport->id."'":"null"); // Note fk_user_author is not the 'author' but the guy the expense report is for. + $sql .= " , fk_user_author = ".($userofexpensereport->id > 0 ? "'".$userofexpensereport->id."'" : "null"); // Note fk_user_author is not the 'author' but the guy the expense report is for. } - $sql.= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null"); - $sql.= " , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid:"null"); - $sql.= " , fk_user_approve = ".($this->fk_user_approve > 0 ? $this->fk_user_approve:"null"); - $sql.= " , fk_user_modif = ".$user->id; - $sql.= " , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut:'0'); - $sql.= " , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null"); - $sql.= " , note_public = ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"''"); - $sql.= " , note_private = ".(!empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"''"); - $sql.= " , detail_refuse = ".(!empty($this->detail_refuse)?"'".$this->db->escape($this->detail_refuse)."'":"''"); - $sql.= " WHERE rowid = ".$this->id; + $sql .= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator : "null"); + $sql .= " , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid : "null"); + $sql .= " , fk_user_approve = ".($this->fk_user_approve > 0 ? $this->fk_user_approve : "null"); + $sql .= " , fk_user_modif = ".$user->id; + $sql .= " , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut : '0'); + $sql .= " , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement : "null"); + $sql .= " , note_public = ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "''"); + $sql .= " , note_private = ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "''"); + $sql .= " , detail_refuse = ".(!empty($this->detail_refuse) ? "'".$this->db->escape($this->detail_refuse)."'" : "''"); + $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql); @@ -468,7 +468,7 @@ class ExpenseReport extends CommonObject if (!$notrigger) { // Call trigger - $result=$this->call_trigger('EXPENSE_REPORT_UPDATE', $user); + $result = $this->call_trigger('EXPENSE_REPORT_UPDATE', $user); if ($result < 0) { $error++; @@ -484,14 +484,14 @@ class ExpenseReport extends CommonObject else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -2; } } else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -507,23 +507,23 @@ class ExpenseReport extends CommonObject { global $conf; - $sql = "SELECT d.rowid, d.ref, d.note_public, d.note_private,"; // DEFAULT - $sql.= " d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,"; // ACTIONS - $sql.= " d.date_refuse, d.date_cancel,"; // ACTIONS - $sql.= " d.total_ht, d.total_ttc, d.total_tva,"; // TOTAUX (int) - $sql.= " d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve,"; // DATES (datetime) - $sql.= " d.fk_user_author, d.fk_user_modif, d.fk_user_validator,"; - $sql.= " d.fk_user_valid, d.fk_user_approve,"; - $sql.= " d.fk_statut as status, d.fk_c_paiement, d.paid,"; - $sql.= " dp.libelle as label_payment, dp.code as code_paiement"; // INNER JOIN paiement - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id"; - if ($ref) $sql.= " WHERE d.ref = '".$this->db->escape($ref)."'"; - else $sql.= " WHERE d.rowid = ".$id; + $sql = "SELECT d.rowid, d.ref, d.note_public, d.note_private,"; // DEFAULT + $sql .= " d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,"; // ACTIONS + $sql .= " d.date_refuse, d.date_cancel,"; // ACTIONS + $sql .= " d.total_ht, d.total_ttc, d.total_tva,"; // TOTAUX (int) + $sql .= " d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve,"; // DATES (datetime) + $sql .= " d.fk_user_author, d.fk_user_modif, d.fk_user_validator,"; + $sql .= " d.fk_user_valid, d.fk_user_approve,"; + $sql .= " d.fk_statut as status, d.fk_c_paiement, d.paid,"; + $sql .= " dp.libelle as label_payment, dp.code as code_paiement"; // INNER JOIN paiement + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id"; + if ($ref) $sql .= " WHERE d.ref = '".$this->db->escape($ref)."'"; + else $sql .= " WHERE d.rowid = ".$id; //$sql.= $restrict; dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); - $resql = $this->db->query($sql) ; + $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); @@ -548,7 +548,7 @@ class ExpenseReport extends CommonObject $this->date_refuse = $this->db->jdate($obj->date_refuse); $this->date_cancel = $this->db->jdate($obj->date_cancel); - $this->fk_user_author = $obj->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. + $this->fk_user_author = $obj->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. $this->fk_user_modif = $obj->fk_user_modif; $this->fk_user_validator = $obj->fk_user_validator; $this->fk_user_valid = $obj->fk_user_valid; @@ -563,7 +563,7 @@ class ExpenseReport extends CommonObject $user_approver = new User($this->db); if ($this->fk_user_approve > 0) $user_approver->fetch($this->fk_user_approve); - elseif ($this->fk_user_validator > 0) $user_approver->fetch($this->fk_user_validator); // For backward compatibility + elseif ($this->fk_user_validator > 0) $user_approver->fetch($this->fk_user_validator); // For backward compatibility $this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname); $this->fk_statut = $obj->status; @@ -583,7 +583,7 @@ class ExpenseReport extends CommonObject $this->lines = array(); - $result=$this->fetch_lines(); + $result = $this->fetch_lines(); return $result; } @@ -594,7 +594,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -615,11 +615,11 @@ class ExpenseReport extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport"; - $sql.= " SET fk_statut = ".self::STATUS_CLOSED.", paid=1"; - $sql.= " WHERE rowid = ".$id." AND fk_statut = ".self::STATUS_APPROVED; + $sql .= " SET fk_statut = ".self::STATUS_CLOSED.", paid=1"; + $sql .= " WHERE rowid = ".$id." AND fk_statut = ".self::STATUS_APPROVED; dol_syslog(get_class($this)."::set_paid sql=".$sql, LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { if ($this->db->affected_rows($resql)) @@ -627,7 +627,7 @@ class ExpenseReport extends CommonObject if (!$notrigger) { // Call trigger - $result=$this->call_trigger('EXPENSE_REPORT_PAID', $fuser); + $result = $this->call_trigger('EXPENSE_REPORT_PAID', $fuser); if ($result < 0) { $error++; @@ -643,7 +643,7 @@ class ExpenseReport extends CommonObject else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -2; } } @@ -705,17 +705,17 @@ class ExpenseReport extends CommonObject global $conf; $sql = "SELECT f.rowid,"; - $sql.= " f.date_create as datec,"; - $sql.= " f.tms as date_modification,"; - $sql.= " f.date_valid as datev,"; - $sql.= " f.date_approve as datea,"; + $sql .= " f.date_create as datec,"; + $sql .= " f.tms as date_modification,"; + $sql .= " f.date_valid as datev,"; + $sql .= " f.date_approve as datea,"; //$sql.= " f.fk_user_author as fk_user_creation,"; // This is not user of creation but user the expense is for. - $sql.= " f.fk_user_modif as fk_user_modification,"; - $sql.= " f.fk_user_valid,"; - $sql.= " f.fk_user_approve"; - $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as f"; - $sql.= " WHERE f.rowid = ".$id; - $sql.= " AND f.entity = ".$conf->entity; + $sql .= " f.fk_user_modif as fk_user_modification,"; + $sql .= " f.fk_user_valid,"; + $sql .= " f.fk_user_approve"; + $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as f"; + $sql .= " WHERE f.rowid = ".$id; + $sql .= " AND f.entity = ".$conf->entity; $resql = $this->db->query($sql); if ($resql) @@ -739,25 +739,25 @@ class ExpenseReport extends CommonObject { $cuser = new User($this->db); $cuser->fetch($obj->fk_user_creation); - $this->user_creation = $cuser; + $this->user_creation = $cuser; } if ($obj->fk_user_valid) { $vuser = new User($this->db); $vuser->fetch($obj->fk_user_valid); - $this->user_validation = $vuser; + $this->user_validation = $vuser; } if ($obj->fk_user_modification) { $muser = new User($this->db); $muser->fetch($obj->fk_user_modification); - $this->user_modification = $muser; + $this->user_modification = $muser; } if ($obj->fk_user_approve) { $auser = new User($this->db); $auser->fetch($obj->fk_user_approve); - $this->user_approve = $auser; + $this->user_approve = $auser; } } $this->db->free($resql); @@ -779,21 +779,21 @@ class ExpenseReport extends CommonObject */ public function initAsSpecimen() { - global $user,$langs,$conf; + global $user, $langs, $conf; - $now=dol_now(); + $now = dol_now(); // Initialise parametres - $this->id=0; + $this->id = 0; $this->ref = 'SPECIMEN'; - $this->specimen=1; + $this->specimen = 1; $this->date_create = $now; $this->date_debut = $now; $this->date_fin = $now; $this->date_valid = $now; $this->date_approve = $now; - $type_fees_id = 2; // TF_TRIP + $type_fees_id = 2; // TF_TRIP $this->status = 5; $this->fk_statut = 5; @@ -803,32 +803,32 @@ class ExpenseReport extends CommonObject $this->fk_user_valid = $user->id; $this->fk_user_approve = $user->id; - $this->note_private='Private note'; - $this->note_public='SPECIMEN'; + $this->note_private = 'Private note'; + $this->note_public = 'SPECIMEN'; $nbp = 5; $xnbp = 0; while ($xnbp < $nbp) { - $line=new ExpenseReportLine($this->db); - $line->comments=$langs->trans("Comment")." ".$xnbp; - $line->date=($now-3600*(1+$xnbp)); - $line->total_ht=100; - $line->total_tva=20; - $line->total_ttc=120; - $line->qty=1; - $line->vatrate=20; - $line->value_unit=120; - $line->fk_expensereport=0; - $line->type_fees_code='TRA'; - $line->fk_c_type_fees=$type_fees_id; + $line = new ExpenseReportLine($this->db); + $line->comments = $langs->trans("Comment")." ".$xnbp; + $line->date = ($now - 3600 * (1 + $xnbp)); + $line->total_ht = 100; + $line->total_tva = 20; + $line->total_ttc = 120; + $line->qty = 1; + $line->vatrate = 20; + $line->value_unit = 120; + $line->fk_expensereport = 0; + $line->type_fees_code = 'TRA'; + $line->fk_c_type_fees = $type_fees_id; $line->projet_ref = 'ABC'; - $this->lines[$xnbp]=$line; + $this->lines[$xnbp] = $line; $xnbp++; - $this->total_ht+=$line->total_ht; - $this->total_tva+=$line->total_tva; - $this->total_ttc+=$line->total_ttc; + $this->total_ht += $line->total_ht; + $this->total_tva += $line->total_tva; + $this->total_ttc += $line->total_ttc; } } @@ -843,17 +843,17 @@ class ExpenseReport extends CommonObject public function fetch_line_by_project($projectid, $user = '') { // phpcs:enable - global $conf,$db,$langs; + global $conf, $db, $langs; $langs->load('trips'); if ($user->rights->expensereport->lire) { $sql = "SELECT de.fk_expensereport, de.date, de.comments, de.total_ht, de.total_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."expensereport_det as de"; - $sql.= " WHERE de.fk_projet = ".$projectid; + $sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as de"; + $sql .= " WHERE de.fk_projet = ".$projectid; dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); - $result = $db->query($sql) ; + $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); @@ -866,8 +866,8 @@ class ExpenseReport extends CommonObject $objp = $db->fetch_object($result); $sql2 = "SELECT d.rowid, d.fk_user_author, d.ref, d.fk_statut"; - $sql2.= " FROM ".MAIN_DB_PREFIX."expensereport as d"; - $sql2.= " WHERE d.rowid = '".$objp->fk_expensereport."'"; + $sql2 .= " FROM ".MAIN_DB_PREFIX."expensereport as d"; + $sql2 .= " WHERE d.rowid = '".$objp->fk_expensereport."'"; $result2 = $db->query($sql2); $obj = $db->fetch_object($result2); @@ -891,7 +891,7 @@ class ExpenseReport extends CommonObject print ''.price($objp->total_ttc).''; print ''; - switch($objp->fk_c_expensereport_status) { + switch ($objp->fk_c_expensereport_status) { case 4: print img_picto($langs->trans('StatusOrderCanceled'), 'statut5'); break; @@ -930,7 +930,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$db->lasterror(); + $this->error = $db->lasterror(); return -1; } } @@ -946,42 +946,42 @@ class ExpenseReport extends CommonObject public function recalculer($id) { $sql = 'SELECT tt.total_ht, tt.total_ttc, tt.total_tva'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as tt'; - $sql.= ' WHERE tt.'.$this->fk_element.' = '.$id; + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as tt'; + $sql .= ' WHERE tt.'.$this->fk_element.' = '.$id; $total_ht = 0; $total_tva = 0; $total_ttc = 0; $result = $this->db->query($sql); - if($result) + if ($result) { $num = $this->db->num_rows($result); $i = 0; while ($i < $num): $objp = $this->db->fetch_object($result); - $total_ht+=$objp->total_ht; - $total_tva+=$objp->total_tva; + $total_ht += $objp->total_ht; + $total_tva += $objp->total_tva; $i++; endwhile; $total_ttc = $total_ht + $total_tva; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql.= " total_ht = ".$total_ht; - $sql.= " , total_ttc = ".$total_ttc; - $sql.= " , total_tva = ".$total_tva; - $sql.= " WHERE rowid = ".$id; + $sql .= " total_ht = ".$total_ht; + $sql .= " , total_ttc = ".$total_ttc; + $sql .= " , total_tva = ".$total_tva; + $sql .= " WHERE rowid = ".$id; $result = $this->db->query($sql); if ($result): $this->db->free($result); return 1; else: - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); dol_syslog(get_class($this)."::recalculer: Error ".$this->error, LOG_ERR); return -3; endif; } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); dol_syslog(get_class($this)."::recalculer: Error ".$this->error, LOG_ERR); return -3; } @@ -996,24 +996,24 @@ class ExpenseReport extends CommonObject public function fetch_lines() { // phpcs:enable - $this->lines=array(); + $this->lines = array(); $sql = ' SELECT de.rowid, de.comments, de.qty, de.value_unit, de.date, de.rang,'; - $sql.= ' de.'.$this->fk_element.', de.fk_c_type_fees, de.fk_c_exp_tax_cat, de.fk_projet as fk_project, de.tva_tx, de.fk_ecm_files,'; - $sql.= ' de.total_ht, de.total_tva, de.total_ttc,'; - $sql.= ' ctf.code as code_type_fees, ctf.label as libelle_type_fees,'; - $sql.= ' p.ref as ref_projet, p.title as title_projet'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as de'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as p ON de.fk_projet = p.rowid'; - $sql.= ' WHERE de.'.$this->fk_element.' = '.$this->id; - if (! empty($conf->global->EXPENSEREPORT_LINES_SORTED_BY_ROWID)) + $sql .= ' de.'.$this->fk_element.', de.fk_c_type_fees, de.fk_c_exp_tax_cat, de.fk_projet as fk_project, de.tva_tx, de.fk_ecm_files,'; + $sql .= ' de.total_ht, de.total_tva, de.total_ttc,'; + $sql .= ' ctf.code as code_type_fees, ctf.label as libelle_type_fees,'; + $sql .= ' p.ref as ref_projet, p.title as title_projet'; + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as de'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as p ON de.fk_projet = p.rowid'; + $sql .= ' WHERE de.'.$this->fk_element.' = '.$this->id; + if (!empty($conf->global->EXPENSEREPORT_LINES_SORTED_BY_ROWID)) { - $sql.= ' ORDER BY de.rang ASC, de.rowid ASC'; + $sql .= ' ORDER BY de.rang ASC, de.rowid ASC'; } else { - $sql.= ' ORDER BY de.rang ASC, de.date ASC'; + $sql .= ' ORDER BY de.rang ASC, de.date ASC'; } $resql = $this->db->query($sql); @@ -1038,7 +1038,7 @@ class ExpenseReport extends CommonObject $deplig->fk_expensereport = $objp->fk_expensereport; $deplig->fk_c_type_fees = $objp->fk_c_type_fees; $deplig->fk_c_exp_tax_cat = $objp->fk_c_exp_tax_cat; - $deplig->fk_projet = $objp->fk_project; // deprecated + $deplig->fk_projet = $objp->fk_project; // deprecated $deplig->fk_project = $objp->fk_project; $deplig->fk_ecm_files = $objp->fk_ecm_files; @@ -1046,9 +1046,9 @@ class ExpenseReport extends CommonObject $deplig->total_tva = $objp->total_tva; $deplig->total_ttc = $objp->total_ttc; - $deplig->type_fees_code = empty($objp->code_type_fees)?'TF_OTHER':$objp->code_type_fees; + $deplig->type_fees_code = empty($objp->code_type_fees) ? 'TF_OTHER' : $objp->code_type_fees; $deplig->type_fees_libelle = $objp->libelle_type_fees; - $deplig->tva_tx = $objp->tva_tx; + $deplig->tva_tx = $objp->tva_tx; $deplig->vatrate = $objp->tva_tx; $deplig->projet_ref = $objp->ref_projet; $deplig->projet_title = $objp->title_projet; @@ -1064,7 +1064,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); dol_syslog(get_class($this)."::fetch_lines: Error ".$this->error, LOG_ERR); return -3; } @@ -1079,15 +1079,15 @@ class ExpenseReport extends CommonObject */ public function delete(User $fuser = null) { - global $user,$langs,$conf; + global $user, $langs, $conf; - if (! $rowid) $rowid=$this->id; + if (!$rowid) $rowid = $this->id; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line.' WHERE '.$this->fk_element.' = '.$rowid; if ($this->db->query($sql)) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid = '.$rowid; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $this->db->commit(); @@ -1095,7 +1095,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->db->error()." sql=".$sql; + $this->error = $this->db->error()." sql=".$sql; dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); $this->db->rollback(); return -6; @@ -1103,7 +1103,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->db->error()." sql=".$sql; + $this->error = $this->db->error()." sql=".$sql; dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); $this->db->rollback(); return -4; @@ -1119,7 +1119,7 @@ class ExpenseReport extends CommonObject */ public function setValidate($fuser, $notrigger = 0) { - global $conf,$langs,$user; + global $conf, $langs, $user; $error = 0; $now = dol_now(); @@ -1131,10 +1131,10 @@ class ExpenseReport extends CommonObject return 0; } - $this->date_valid = $now; // Required for the getNextNum later. + $this->date_valid = $now; // Required for the getNextNum later. // Define new ref - if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life + if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life { $num = $this->getNextNumRef(); } @@ -1150,26 +1150,26 @@ class ExpenseReport extends CommonObject // Validate $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET ref = '".$num."',"; - $sql.= " fk_statut = ".self::STATUS_VALIDATED.","; - $sql.= " date_valid='".$this->db->idate($this->date_valid)."',"; - $sql.= " fk_user_valid = ".$user->id; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET ref = '".$num."',"; + $sql .= " fk_statut = ".self::STATUS_VALIDATED.","; + $sql .= " date_valid='".$this->db->idate($this->date_valid)."',"; + $sql .= " fk_user_valid = ".$user->id; + $sql .= " WHERE rowid = ".$this->id; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('EXPENSE_REPORT_VALIDATE', $fuser); + $result = $this->call_trigger('EXPENSE_REPORT_VALIDATE', $fuser); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $this->oldref = $this->ref; @@ -1179,17 +1179,17 @@ class ExpenseReport extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Now we rename also files into index - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'expensereport/".$this->db->escape($this->newref)."'"; - $sql.= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expensereport/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'expensereport/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expensereport/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + if (!$resql) { $error++; $this->error = $this->db->lasterror(); } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->expensereport->dir_output.'/'.$oldref; $dirdest = $conf->expensereport->dir_output.'/'.$newref; - if (! $error && file_exists($dirsource)) + if (!$error && file_exists($dirsource)) { dol_syslog(get_class($this)."::setValidate() rename dir ".$dirsource." into ".$dirdest); @@ -1197,13 +1197,13 @@ class ExpenseReport extends CommonObject { dol_syslog("Rename ok"); // Rename docs starting with $oldref with $newref - $listoffiles=dol_dir_list($conf->expensereport->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach($listoffiles as $fileentry) + $listoffiles = dol_dir_list($conf->expensereport->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); + foreach ($listoffiles as $fileentry) { - $dirsource=$fileentry['name']; - $dirdest=preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); - $dirsource=$fileentry['path'].'/'.$dirsource; - $dirdest=$fileentry['path'].'/'.$dirdest; + $dirsource = $fileentry['name']; + $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); + $dirsource = $fileentry['path'].'/'.$dirsource; + $dirdest = $fileentry['path'].'/'.$dirdest; @rename($dirsource, $dirdest); } } @@ -1212,7 +1212,7 @@ class ExpenseReport extends CommonObject } // Set new ref and current status - if (! $error) + if (!$error) { $this->ref = $num; $this->statut = self::STATUS_VALIDATED; @@ -1226,14 +1226,14 @@ class ExpenseReport extends CommonObject else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -2; } } else { $this->db->rollback(); - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -1248,12 +1248,12 @@ class ExpenseReport extends CommonObject public function set_save_from_refuse($fuser) { // phpcs:enable - global $conf,$langs; + global $conf, $langs; // Sélection de la date de début de la NDF $sql = 'SELECT date_debut'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; - $sql.= ' WHERE rowid = '.$this->id; + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql .= ' WHERE rowid = '.$this->id; $result = $this->db->query($sql); @@ -1264,8 +1264,8 @@ class ExpenseReport extends CommonObject if ($this->fk_statut != self::STATUS_VALIDATED) { $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_statut = ".self::STATUS_VALIDATED; - $sql.= ' WHERE rowid = '.$this->id; + $sql .= " SET fk_statut = ".self::STATUS_VALIDATED; + $sql .= ' WHERE rowid = '.$this->id; dol_syslog(get_class($this)."::set_save_from_refuse sql=".$sql, LOG_DEBUG); @@ -1275,7 +1275,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -1294,7 +1294,7 @@ class ExpenseReport extends CommonObject */ public function setApproved($fuser, $notrigger = 0) { - $now=dol_now(); + $now = dol_now(); $error = 0; // date approval @@ -1304,15 +1304,15 @@ class ExpenseReport extends CommonObject $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = ".self::STATUS_APPROVED.", fk_user_approve = ".$fuser->id.","; - $sql.= " date_approve='".$this->db->idate($this->date_approve)."'"; - $sql.= ' WHERE rowid = '.$this->id; + $sql .= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = ".self::STATUS_APPROVED.", fk_user_approve = ".$fuser->id.","; + $sql .= " date_approve='".$this->db->idate($this->date_approve)."'"; + $sql .= ' WHERE rowid = '.$this->id; if ($this->db->query($sql)) { if (!$notrigger) { // Call trigger - $result=$this->call_trigger('EXPENSE_REPORT_APPROVE', $fuser); + $result = $this->call_trigger('EXPENSE_REPORT_APPROVE', $fuser); if ($result < 0) { $error++; @@ -1328,14 +1328,14 @@ class ExpenseReport extends CommonObject else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -2; } } else { $this->db->rollback(); - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -1364,11 +1364,11 @@ class ExpenseReport extends CommonObject if ($this->fk_statut != self::STATUS_REFUSED) { $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = ".self::STATUS_REFUSED.", fk_user_refuse = ".$fuser->id.","; - $sql.= " date_refuse='".$this->db->idate($now)."',"; - $sql.= " detail_refuse='".$this->db->escape($details)."',"; - $sql.= " fk_user_approve = NULL"; - $sql.= ' WHERE rowid = '.$this->id; + $sql .= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = ".self::STATUS_REFUSED.", fk_user_refuse = ".$fuser->id.","; + $sql .= " date_refuse='".$this->db->idate($now)."',"; + $sql .= " detail_refuse='".$this->db->escape($details)."',"; + $sql .= " fk_user_approve = NULL"; + $sql .= ' WHERE rowid = '.$this->id; if ($this->db->query($sql)) { $this->fk_statut = 99; @@ -1379,7 +1379,7 @@ class ExpenseReport extends CommonObject if (!$notrigger) { // Call trigger - $result=$this->call_trigger('EXPENSE_REPORT_DENY', $fuser); + $result = $this->call_trigger('EXPENSE_REPORT_DENY', $fuser); if ($result < 0) { $error++; @@ -1395,14 +1395,14 @@ class ExpenseReport extends CommonObject else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -2; } } else { $this->db->rollback(); - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -1430,8 +1430,8 @@ class ExpenseReport extends CommonObject $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET paid = 0, fk_statut = ".self::STATUS_APPROVED; - $sql.= ' WHERE rowid = '.$this->id; + $sql .= " SET paid = 0, fk_statut = ".self::STATUS_APPROVED; + $sql .= ' WHERE rowid = '.$this->id; dol_syslog(get_class($this)."::set_unpaid sql=".$sql, LOG_DEBUG); @@ -1440,7 +1440,7 @@ class ExpenseReport extends CommonObject if (!$notrigger) { // Call trigger - $result=$this->call_trigger('EXPENSE_REPORT_UNPAID', $fuser); + $result = $this->call_trigger('EXPENSE_REPORT_UNPAID', $fuser); if ($result < 0) { $error++; @@ -1456,14 +1456,14 @@ class ExpenseReport extends CommonObject else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -2; } } else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -1492,10 +1492,10 @@ class ExpenseReport extends CommonObject $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_statut = ".self::STATUS_CANCELED.", fk_user_cancel = ".$fuser->id; - $sql.= ", date_cancel='".$this->db->idate($this->date_cancel)."'"; - $sql.= " ,detail_cancel='".$this->db->escape($detail)."'"; - $sql.= ' WHERE rowid = '.$this->id; + $sql .= " SET fk_statut = ".self::STATUS_CANCELED.", fk_user_cancel = ".$fuser->id; + $sql .= ", date_cancel='".$this->db->idate($this->date_cancel)."'"; + $sql .= " ,detail_cancel='".$this->db->escape($detail)."'"; + $sql .= ' WHERE rowid = '.$this->id; dol_syslog(get_class($this)."::set_cancel sql=".$sql, LOG_DEBUG); @@ -1504,7 +1504,7 @@ class ExpenseReport extends CommonObject if (!$notrigger) { // Call trigger - $result=$this->call_trigger('EXPENSE_REPORT_CANCEL', $fuser); + $result = $this->call_trigger('EXPENSE_REPORT_CANCEL', $fuser); if ($result < 0) { $error++; @@ -1520,14 +1520,14 @@ class ExpenseReport extends CommonObject else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -2; } } else { $this->db->rollback(); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -1547,21 +1547,21 @@ class ExpenseReport extends CommonObject global $langs, $conf; $langs->load("trips"); - if (! empty($conf->global->EXPENSEREPORT_ADDON)) + if (!empty($conf->global->EXPENSEREPORT_ADDON)) { - $mybool=false; + $mybool = false; $file = $conf->global->EXPENSEREPORT_ADDON.".php"; $classname = $conf->global->EXPENSEREPORT_ADDON; // Include file with class - $dirmodels=array_merge(array('/'), (array) $conf->modules_parts['models']); + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); foreach ($dirmodels as $reldir) { $dir = dol_buildpath($reldir."core/modules/expensereport/"); // Load file with numbering class (if found) - $mybool|=@include_once $dir.$file; + $mybool |= @include_once $dir.$file; } if ($mybool === false) { @@ -1578,8 +1578,8 @@ class ExpenseReport extends CommonObject } else { - $this->error=$obj->error; - $this->errors=$obj->errors; + $this->error = $obj->error; + $this->errors = $obj->errors; //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); return -1; } @@ -1606,53 +1606,53 @@ class ExpenseReport extends CommonObject { global $langs, $conf; - $result=''; + $result = ''; $url = DOL_URL_ROOT.'/expensereport/card.php?id='.$this->id; if ($short) return $url; - $label = '' . $langs->trans("ShowExpenseReport") . ''; - if (! empty($this->ref)) - $label .= '
' . $langs->trans('Ref') . ': ' . $this->ref; - if (! empty($this->total_ht)) - $label.= '
' . $langs->trans('AmountHT') . ': ' . price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); - if (! empty($this->total_tva)) - $label.= '
' . $langs->trans('VAT') . ': ' . price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); - if (! empty($this->total_ttc)) - $label.= '
' . $langs->trans('AmountTTC') . ': ' . price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); - if ($moretitle) $label.=' - '.$moretitle; + $label = ''.$langs->trans("ShowExpenseReport").''; + if (!empty($this->ref)) + $label .= '
'.$langs->trans('Ref').': '.$this->ref; + if (!empty($this->total_ht)) + $label .= '
'.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); + if (!empty($this->total_tva)) + $label .= '
'.$langs->trans('VAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); + if (!empty($this->total_ttc)) + $label .= '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); + if ($moretitle) $label .= ' - '.$moretitle; //if ($option != 'nolink') //{ // Add param to save lastsearch_values or not - $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; - if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; //} - $ref=$this->ref; - if (empty($ref)) $ref=$this->id; + $ref = $this->ref; + if (empty($ref)) $ref = $this->id; - $linkclose=''; + $linkclose = ''; if (empty($notooltip)) { - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $label=$langs->trans("ShowExpenseReport"); - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + $label = $langs->trans("ShowExpenseReport"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } - $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose.=' class="classfortooltip"'; + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; } $linkstart = ''; - $linkend=''; + $linkstart .= $linkclose.'>'; + $linkend = ''; $result .= $linkstart; - if ($withpicto) $result.=img_object(($notooltip?'':$label), $this->picto, ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1); - if ($withpicto != 2) $result.=($max?dol_trunc($ref, $max):$ref); + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= ($max ?dol_trunc($ref, $max) : $ref); $result .= $linkend; return $result; @@ -1674,16 +1674,16 @@ class ExpenseReport extends CommonObject $this->total_ttc = $this->total_ht + $this->total_tva; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql.= " total_ht = ".$this->total_ht; - $sql.= " , total_ttc = ".$this->total_ttc; - $sql.= " , total_tva = ".$this->total_tva; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " total_ht = ".$this->total_ht; + $sql .= " , total_ttc = ".$this->total_ttc; + $sql .= " , total_tva = ".$this->total_tva; + $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); if ($result): return 1; else: - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; endif; } @@ -1704,16 +1704,16 @@ class ExpenseReport extends CommonObject $this->total_ttc = $this->total_ht + $this->total_tva; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql.= " total_ht = ".$this->total_ht; - $sql.= " , total_ttc = ".$this->total_ttc; - $sql.= " , total_tva = ".$this->total_tva; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " total_ht = ".$this->total_ht; + $sql .= " , total_ttc = ".$this->total_ttc; + $sql .= " , total_tva = ".$this->total_tva; + $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); if ($result): return 1; else: - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; endif; } @@ -1749,8 +1749,8 @@ class ExpenseReport extends CommonObject if (empty($fk_project)) $fk_project = 0; $qty = price2num($qty); - if (! preg_match('/\s*\((.*)\)/', $vatrate)) { - $vatrate = price2num($vatrate); // $txtva can have format '5.0 (XXX)' or '5' + if (!preg_match('/\s*\((.*)\)/', $vatrate)) { + $vatrate = price2num($vatrate); // $txtva can have format '5.0 (XXX)' or '5' } $up = price2num($up); @@ -1758,17 +1758,17 @@ class ExpenseReport extends CommonObject $this->line = new ExpenseReportLine($this->db); - $localtaxes_type=getLocalTaxesFromRate($vatrate, 0, $mysoc, $this->thirdparty); + $localtaxes_type = getLocalTaxesFromRate($vatrate, 0, $mysoc, $this->thirdparty); $vat_src_code = ''; if (preg_match('/\s*\((.*)\)/', $vatrate, $reg)) { $vat_src_code = $reg[1]; - $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. + $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. } $vatrate = preg_replace('/\*/', '', $vatrate); - $seller = ''; // seller is unknown + $seller = ''; // seller is unknown $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type); @@ -1785,7 +1785,7 @@ class ExpenseReport extends CommonObject $this->line->fk_c_type_fees = $fk_c_type_fees; $this->line->fk_c_exp_tax_cat = $fk_c_exp_tax_cat; $this->line->comments = $comments; - $this->line->fk_projet = $fk_project; // deprecated + $this->line->fk_projet = $fk_project; // deprecated $this->line->fk_project = $fk_project; $this->line->fk_ecm_files = $fk_ecm_files; @@ -1793,10 +1793,10 @@ class ExpenseReport extends CommonObject $this->applyOffset(); $this->checkRules($type, $seller); - $result=$this->line->insert(0, true); + $result = $this->line->insert(0, true); if ($result > 0) { - $result=$this->update_price(); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + $result = $this->update_price(); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. if ($result > 0) { $this->db->commit(); @@ -1810,7 +1810,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->line->error; + $this->error = $this->line->error; dol_syslog(get_class($this)."::addline error=".$this->error, LOG_ERR); $this->db->rollback(); return -2; @@ -1833,7 +1833,7 @@ class ExpenseReport extends CommonObject */ public function checkRules($type = 0, $seller = '') { - global $user,$conf,$db,$langs; + global $user, $conf, $db, $langs; $langs->load('trips'); @@ -1883,7 +1883,7 @@ class ExpenseReport extends CommonObject if ($violation > 0) { - $tmp = calcul_price_total($this->line->qty, $new_current_total_ttc/$this->line->qty, 0, $this->line->vatrate, 0, 0, 0, 'TTC', 0, $type, $seller); + $tmp = calcul_price_total($this->line->qty, $new_current_total_ttc / $this->line->qty, 0, $this->line->vatrate, 0, 0, 0, 'TTC', 0, $type, $seller); $this->line->value_unit = $tmp[5]; $this->line->total_ttc = $tmp[2]; @@ -1951,11 +1951,11 @@ class ExpenseReport extends CommonObject public function offsetAlreadyGiven() { $sql = 'SELECT e.rowid FROM '.MAIN_DB_PREFIX.'expensereport e'; - $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'expensereport_det d ON (e.rowid = d.fk_expensereport)'; - $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees f ON (d.fk_c_type_fees = f.id AND f.code = "EX_KME")'; - $sql.= ' WHERE e.fk_user_author = '.(int) $this->fk_user_author; - $sql.= ' AND YEAR(d.date) = "'.dol_print_date($this->line->date, '%Y').'" AND MONTH(d.date) = "'.dol_print_date($this->line->date, '%m').'"'; - if (!empty($this->line->id)) $sql.= ' AND d.rowid <> '.$this->line->id; + $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'expensereport_det d ON (e.rowid = d.fk_expensereport)'; + $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees f ON (d.fk_c_type_fees = f.id AND f.code = "EX_KME")'; + $sql .= ' WHERE e.fk_user_author = '.(int) $this->fk_user_author; + $sql .= ' AND YEAR(d.date) = "'.dol_print_date($this->line->date, '%Y').'" AND MONTH(d.date) = "'.dol_print_date($this->line->date, '%m').'"'; + if (!empty($this->line->id)) $sql .= ' AND d.rowid <> '.$this->line->id; dol_syslog(get_class($this)."::offsetAlreadyGiven sql=".$sql); $resql = $this->db->query($sql); @@ -1992,24 +1992,24 @@ class ExpenseReport extends CommonObject { global $user, $mysoc; - if ($this->fk_statut==0 || $this->fk_statut==99) + if ($this->fk_statut == 0 || $this->fk_statut == 99) { $this->db->begin(); - $type = 0; // TODO What if type is service ? + $type = 0; // TODO What if type is service ? // We don't know seller and buyer for expense reports $seller = $mysoc; $buyer = new Societe($this->db); - $localtaxes_type=getLocalTaxesFromRate($vatrate, 0, $buyer, $seller); + $localtaxes_type = getLocalTaxesFromRate($vatrate, 0, $buyer, $seller); // Clean vat code - $vat_src_code=''; + $vat_src_code = ''; if (preg_match('/\((.*)\)/', $vatrate, $reg)) { $vat_src_code = $reg[1]; - $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. + $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. } $vatrate = preg_replace('/\*/', '', $vatrate); @@ -2020,7 +2020,7 @@ class ExpenseReport extends CommonObject $tx_tva = $vatrate / 100; $tx_tva = $tx_tva + 1; - $total_ht = price2num($total_ttc/$tx_tva, 'MT'); + $total_ht = price2num($total_ttc / $tx_tva, 'MT'); $total_tva = price2num($total_ttc - $total_ht, 'MT'); // fin calculs @@ -2031,10 +2031,10 @@ class ExpenseReport extends CommonObject $this->line->value_unit = $value_unit; $this->line->date = $date; - $this->line->fk_expensereport= $expensereport_id; + $this->line->fk_expensereport = $expensereport_id; $this->line->fk_c_type_fees = $type_fees_id; - $this->line->fk_c_exp_tax_cat = $fk_c_exp_tax_cat; - $this->line->fk_projet = $projet_id; // deprecated + $this->line->fk_c_exp_tax_cat = $fk_c_exp_tax_cat; + $this->line->fk_projet = $projet_id; // deprecated $this->line->fk_project = $projet_id; $this->line->vat_src_code = $vat_src_code; @@ -2049,12 +2049,12 @@ class ExpenseReport extends CommonObject $this->line->fk_ecm_files = $fk_ecm_files; - $this->line->id = $rowid; + $this->line->id = $rowid; // Select des infos sur le type fees $sql = "SELECT c.code as code_type_fees, c.label as libelle_type_fees"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; - $sql.= " WHERE c.id = ".$type_fees_id; + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; + $sql .= " WHERE c.id = ".$type_fees_id; $resql = $this->db->query($sql); if ($resql) { @@ -2066,8 +2066,8 @@ class ExpenseReport extends CommonObject // Select des informations du projet $sql = "SELECT p.ref as ref_projet, p.title as title_projet"; - $sql.= " FROM ".MAIN_DB_PREFIX."projet as p"; - $sql.= " WHERE p.rowid = ".$projet_id; + $sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; + $sql .= " WHERE p.rowid = ".$projet_id; $resql = $this->db->query($sql); if ($resql) { $objp_projet = $this->db->fetch_object($resql); @@ -2087,8 +2087,8 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->line->error; - $this->errors=$this->line->errors; + $this->error = $this->line->error; + $this->errors = $this->line->errors; $this->db->rollback(); return -2; } @@ -2107,13 +2107,13 @@ class ExpenseReport extends CommonObject $this->db->begin(); $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line; - $sql.= ' WHERE rowid = '.$rowid; + $sql .= ' WHERE rowid = '.$rowid; dol_syslog(get_class($this)."::deleteline sql=".$sql); $result = $this->db->query($sql); if (!$result) { - $this->error=$this->db->error(); + $this->error = $this->db->error(); dol_syslog(get_class($this)."::deleteline Error ".$this->error, LOG_ERR); $this->db->rollback(); return -1; @@ -2137,8 +2137,8 @@ class ExpenseReport extends CommonObject { // phpcs:enable $sql = "SELECT rowid, date_debut, date_fin"; - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " WHERE fk_user_author = '{$fuser->id}'"; + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " WHERE fk_user_author = '{$fuser->id}'"; dol_syslog(get_class($this)."::periode_existe sql=".$sql); $result = $this->db->query($sql); @@ -2157,14 +2157,14 @@ class ExpenseReport extends CommonObject $objp = $this->db->fetch_object($result); $date_d_req = $this->db->jdate($objp->date_debut); // 3 - $date_f_req = $this->db->jdate($objp->date_fin); // 4 + $date_f_req = $this->db->jdate($objp->date_fin); // 4 if (!($date_f_form < $date_d_req || $date_d_form > $date_f_req)) $existe = true; $i++; } - if($existe) return 1; + if ($existe) return 1; else return 0; } else @@ -2174,7 +2174,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); dol_syslog(get_class($this)."::periode_existe Error ".$this->error, LOG_ERR); return -1; } @@ -2191,20 +2191,20 @@ class ExpenseReport extends CommonObject public function fetch_users_approver_expensereport() { // phpcs:enable - $users_validator=array(); + $users_validator = array(); $sql = "SELECT DISTINCT ur.fk_user"; - $sql.= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd"; - $sql.= " WHERE ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'"; // Permission 'Approve'; - $sql.= "UNION"; - $sql.= " SELECT DISTINCT ugu.fk_user"; - $sql.= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd"; - $sql.= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'"; // Permission 'Approve'; + $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd"; + $sql .= " WHERE ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'"; // Permission 'Approve'; + $sql .= "UNION"; + $sql .= " SELECT DISTINCT ugu.fk_user"; + $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd"; + $sql .= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'"; // Permission 'Approve'; //print $sql; dol_syslog(get_class($this)."::fetch_users_approver_expensereport sql=".$sql); $result = $this->db->query($sql); - if($result) + if ($result) { $num_rows = $this->db->num_rows($result); $i = 0; while ($i < $num_rows) @@ -2217,7 +2217,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); dol_syslog(get_class($this)."::fetch_users_approver_expensereport Error ".$this->error, LOG_ERR); return -1; } @@ -2236,16 +2236,16 @@ class ExpenseReport extends CommonObject */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) { - global $conf,$langs; + global $conf, $langs; $langs->load("trips"); - if (! dol_strlen($modele)) { + if (!dol_strlen($modele)) { $modele = 'standard'; if ($this->modelpdf) { $modele = $this->modelpdf; - } elseif (! empty($conf->global->EXPENSEREPORT_ADDON_PDF)) { + } elseif (!empty($conf->global->EXPENSEREPORT_ADDON_PDF)) { $modele = $conf->global->EXPENSEREPORT_ADDON_PDF; } } @@ -2264,20 +2264,20 @@ class ExpenseReport extends CommonObject public function listOfTypes($active = 1) { global $langs; - $ret=array(); + $ret = array(); $sql = "SELECT id, code, label"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees"; - $sql.= " WHERE active = ".$active; + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees"; + $sql .= " WHERE active = ".$active; dol_syslog(get_class($this)."::listOfTypes", LOG_DEBUG); $result = $this->db->query($sql); - if ( $result ) + if ($result) { $num = $this->db->num_rows($result); - $i=0; + $i = 0; while ($i < $num) { $obj = $this->db->fetch_object($result); - $ret[$obj->code]=(($langs->trans($obj->code)!=$obj->code)?$langs->trans($obj->code):$obj->label); + $ret[$obj->code] = (($langs->trans($obj->code) != $obj->code) ? $langs->trans($obj->code) : $obj->label); $i++; } } @@ -2299,17 +2299,17 @@ class ExpenseReport extends CommonObject // phpcs:enable global $conf; - $this->nb=array(); + $this->nb = array(); $sql = "SELECT count(ex.rowid) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as ex"; - $sql.= " WHERE ex.fk_statut > 0"; - $sql.= " AND ex.entity IN (".getEntity('expensereport').")"; + $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as ex"; + $sql .= " WHERE ex.fk_statut > 0"; + $sql .= " AND ex.entity IN (".getEntity('expensereport').")"; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - while ($obj=$this->db->fetch_object($resql)) { - $this->nb["expensereports"]=$obj->nb; + while ($obj = $this->db->fetch_object($resql)) { + $this->nb["expensereports"] = $obj->nb; } $this->db->free($resql); return 1; @@ -2317,7 +2317,7 @@ class ExpenseReport extends CommonObject else { dol_print_error($this->db); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -2335,21 +2335,21 @@ class ExpenseReport extends CommonObject // phpcs:enable global $conf, $langs; - if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe + if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe - $now=dol_now(); + $now = dol_now(); $userchildids = $user->getAllChildIds(1); $sql = "SELECT ex.rowid, ex.date_valid"; - $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as ex"; - if ($option == 'toapprove') $sql.= " WHERE ex.fk_statut = 2"; - else $sql.= " WHERE ex.fk_statut = 5"; - $sql.= " AND ex.entity IN (".getEntity('expensereport').")"; - $sql.= " AND (ex.fk_user_author IN (".join(',', $userchildids).")"; - $sql.= " OR ex.fk_user_validator IN (".join(',', $userchildids)."))"; + $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as ex"; + if ($option == 'toapprove') $sql .= " WHERE ex.fk_statut = 2"; + else $sql .= " WHERE ex.fk_statut = 5"; + $sql .= " AND ex.entity IN (".getEntity('expensereport').")"; + $sql .= " AND (ex.fk_user_author IN (".join(',', $userchildids).")"; + $sql .= " OR ex.fk_user_validator IN (".join(',', $userchildids)."))"; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $langs->load("trips"); @@ -2357,21 +2357,21 @@ class ExpenseReport extends CommonObject $response = new WorkboardResponse(); if ($option == 'toapprove') { - $response->warning_delay=$conf->expensereport->approve->warning_delay/60/60/24; - $response->label=$langs->trans("ExpenseReportsToApprove"); - $response->labelShort=$langs->trans("ToApprove"); - $response->url=DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm&statut=2'; + $response->warning_delay = $conf->expensereport->approve->warning_delay / 60 / 60 / 24; + $response->label = $langs->trans("ExpenseReportsToApprove"); + $response->labelShort = $langs->trans("ToApprove"); + $response->url = DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm&statut=2'; } else { - $response->warning_delay=$conf->expensereport->payment->warning_delay/60/60/24; - $response->label=$langs->trans("ExpenseReportsToPay"); - $response->labelShort=$langs->trans("StatusToPay"); - $response->url=DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm&statut=5'; + $response->warning_delay = $conf->expensereport->payment->warning_delay / 60 / 60 / 24; + $response->label = $langs->trans("ExpenseReportsToPay"); + $response->labelShort = $langs->trans("StatusToPay"); + $response->url = DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm&statut=5'; } - $response->img=img_object('', "trip"); + $response->img = img_object('', "trip"); - while ($obj=$this->db->fetch_object($resql)) + while ($obj = $this->db->fetch_object($resql)) { $response->nbtodo++; @@ -2394,7 +2394,7 @@ class ExpenseReport extends CommonObject else { dol_print_error($this->db); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -2416,10 +2416,10 @@ class ExpenseReport extends CommonObject $now = dol_now(); if ($option == 'toapprove') { - return ($this->datevalid?$this->datevalid:$this->date_valid) < ($now - $conf->expensereport->approve->warning_delay); + return ($this->datevalid ? $this->datevalid : $this->date_valid) < ($now - $conf->expensereport->approve->warning_delay); } else - return ($this->datevalid?$this->datevalid:$this->date_valid) < ($now - $conf->expensereport->payment->warning_delay); + return ($this->datevalid ? $this->datevalid : $this->date_valid) < ($now - $conf->expensereport->payment->warning_delay); } /** @@ -2463,15 +2463,15 @@ class ExpenseReport extends CommonObject */ public function getSumPayments() { - $table='payment_expensereport'; - $field='fk_expensereport'; + $table = 'payment_expensereport'; + $field = 'fk_expensereport'; $sql = 'SELECT sum(amount) as amount'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$table; - $sql.= ' WHERE '.$field.' = '.$this->id; + $sql .= ' FROM '.MAIN_DB_PREFIX.$table; + $sql .= ' WHERE '.$field.' = '.$this->id; dol_syslog(get_class($this)."::getSumPayments", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); @@ -2480,7 +2480,7 @@ class ExpenseReport extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -2500,7 +2500,7 @@ class ExpenseReportLine /** * @var string Error code (or message) */ - public $error=''; + public $error = ''; /** * @var int ID @@ -2556,7 +2556,7 @@ class ExpenseReportLine */ public function __construct($db) { - $this->db= $db; + $this->db = $db; } /** @@ -2568,17 +2568,17 @@ class ExpenseReportLine public function fetch($rowid) { $sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_c_exp_tax_cat, fde.fk_projet as fk_project, fde.date,'; - $sql.= ' fde.tva_tx as vatrate, fde.vat_src_code, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc, fde.fk_ecm_files,'; - $sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,'; - $sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id'; // Sometimes type of expense report has been removed, so we use a left join here. - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pjt ON fde.fk_projet=pjt.rowid'; - $sql.= ' WHERE fde.rowid = '.$rowid; + $sql .= ' fde.tva_tx as vatrate, fde.vat_src_code, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc, fde.fk_ecm_files,'; + $sql .= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,'; + $sql .= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id'; // Sometimes type of expense report has been removed, so we use a left join here. + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pjt ON fde.fk_projet=pjt.rowid'; + $sql .= ' WHERE fde.rowid = '.$rowid; $result = $this->db->query($sql); - if($result) + if ($result) { $objp = $this->db->fetch_object($result); @@ -2593,7 +2593,7 @@ class ExpenseReportLine $this->value_unit = $objp->value_unit; $this->fk_c_type_fees = $objp->fk_c_type_fees; $this->fk_c_exp_tax_cat = $objp->fk_c_exp_tax_cat; - $this->fk_projet = $objp->fk_project; // deprecated + $this->fk_projet = $objp->fk_project; // deprecated $this->fk_project = $objp->fk_project; $this->type_fees_code = $objp->type_fees_code; $this->type_fees_libelle = $objp->type_fees_libelle; @@ -2623,13 +2623,13 @@ class ExpenseReportLine { global $langs, $user, $conf; - $error=0; + $error = 0; dol_syslog("ExpenseReportLine::Insert rang=".$this->rang, LOG_DEBUG); // Clean parameters - $this->comments=trim($this->comments); - if (!$this->value_unit_HT) $this->value_unit_HT=0; + $this->comments = trim($this->comments); + if (!$this->value_unit_HT) $this->value_unit_HT = 0; $this->qty = price2num($this->qty); $this->vatrate = price2num($this->vatrate); if (empty($this->fk_c_exp_tax_cat)) $this->fk_c_exp_tax_cat = 0; @@ -2637,33 +2637,33 @@ class ExpenseReportLine $this->db->begin(); $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'expensereport_det'; - $sql.= ' (fk_expensereport, fk_c_type_fees, fk_projet,'; - $sql.= ' tva_tx, vat_src_code, comments, qty, value_unit, total_ht, total_tva, total_ttc, date, rule_warning_message, fk_c_exp_tax_cat, fk_ecm_files)'; - $sql.= " VALUES (".$this->db->escape($this->fk_expensereport).","; - $sql.= " ".$this->db->escape($this->fk_c_type_fees).","; - $sql.= " ".$this->db->escape($this->fk_project>0?$this->fk_project:($this->fk_projet>0?$this->fk_projet:'null')).","; - $sql.= " ".$this->db->escape($this->vatrate).","; - $sql.= " '".$this->db->escape($this->vat_src_code)."',"; - $sql.= " '".$this->db->escape($this->comments)."',"; - $sql.= " ".$this->db->escape($this->qty).","; - $sql.= " ".$this->db->escape($this->value_unit).","; - $sql.= " ".$this->db->escape($this->total_ht).","; - $sql.= " ".$this->db->escape($this->total_tva).","; - $sql.= " ".$this->db->escape($this->total_ttc).","; - $sql.= "'".$this->db->idate($this->date)."',"; - $sql.= " '".$this->db->escape($this->rule_warning_message)."',"; - $sql.= " ".$this->db->escape($this->fk_c_exp_tax_cat).","; - $sql.= " ".($this->fk_ecm_files > 0 ? $this->fk_ecm_files : 'null'); - $sql.= ")"; + $sql .= ' (fk_expensereport, fk_c_type_fees, fk_projet,'; + $sql .= ' tva_tx, vat_src_code, comments, qty, value_unit, total_ht, total_tva, total_ttc, date, rule_warning_message, fk_c_exp_tax_cat, fk_ecm_files)'; + $sql .= " VALUES (".$this->db->escape($this->fk_expensereport).","; + $sql .= " ".$this->db->escape($this->fk_c_type_fees).","; + $sql .= " ".$this->db->escape($this->fk_project > 0 ? $this->fk_project : ($this->fk_projet > 0 ? $this->fk_projet : 'null')).","; + $sql .= " ".$this->db->escape($this->vatrate).","; + $sql .= " '".$this->db->escape($this->vat_src_code)."',"; + $sql .= " '".$this->db->escape($this->comments)."',"; + $sql .= " ".$this->db->escape($this->qty).","; + $sql .= " ".$this->db->escape($this->value_unit).","; + $sql .= " ".$this->db->escape($this->total_ht).","; + $sql .= " ".$this->db->escape($this->total_tva).","; + $sql .= " ".$this->db->escape($this->total_ttc).","; + $sql .= "'".$this->db->idate($this->date)."',"; + $sql .= " '".$this->db->escape($this->rule_warning_message)."',"; + $sql .= " ".$this->db->escape($this->fk_c_exp_tax_cat).","; + $sql .= " ".($this->fk_ecm_files > 0 ? $this->fk_ecm_files : 'null'); + $sql .= ")"; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'expensereport_det'); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'expensereport_det'); - if (! $fromaddline) + if (!$fromaddline) { - $tmpparent=new ExpenseReport($this->db); + $tmpparent = new ExpenseReport($this->db); $tmpparent->fetch($this->fk_expensereport); $result = $tmpparent->update_price(); if ($result < 0) @@ -2679,14 +2679,14 @@ class ExpenseReportLine $error++; } - if (! $error) + if (!$error) { $this->db->commit(); return $this->rowid; } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); dol_syslog("ExpenseReportLine::insert Error ".$this->error, LOG_ERR); $this->db->rollback(); return -2; @@ -2709,11 +2709,11 @@ class ExpenseReportLine $sql .= ' FROM '.MAIN_DB_PREFIX.'expensereport_det d'; $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'expensereport e ON (d.fk_expensereport = e.rowid)'; $sql .= ' WHERE e.fk_user_author = '.$fk_user; - if (!empty($this->id)) $sql.= ' AND d.rowid <> '.$this->id; + if (!empty($this->id)) $sql .= ' AND d.rowid <> '.$this->id; $sql .= ' AND d.fk_c_type_fees = '.$rule->fk_c_type_fees; if ($mode == 'day' || $mode == 'EX_DAY') $sql .= ' AND d.date = \''.dol_print_date($this->date, '%Y-%m-%d').'\''; - elseif ($mode == 'mon' || $mode == 'EX_MON') $sql .= ' AND DATE_FORMAT(d.date, \'%Y-%m\') = \''.dol_print_date($this->date, '%Y-%m').'\''; // @todo DATE_FORMAT is forbidden - elseif ($mode == 'year' || $mode == 'EX_YEA') $sql .= ' AND DATE_FORMAT(d.date, \'%Y\') = \''.dol_print_date($this->date, '%Y').'\''; // @todo DATE_FORMAT is forbidden + elseif ($mode == 'mon' || $mode == 'EX_MON') $sql .= ' AND DATE_FORMAT(d.date, \'%Y-%m\') = \''.dol_print_date($this->date, '%Y-%m').'\''; // @todo DATE_FORMAT is forbidden + elseif ($mode == 'year' || $mode == 'EX_YEA') $sql .= ' AND DATE_FORMAT(d.date, \'%Y\') = \''.dol_print_date($this->date, '%Y').'\''; // @todo DATE_FORMAT is forbidden dol_syslog('ExpenseReportLine::getExpAmount'); @@ -2743,12 +2743,12 @@ class ExpenseReportLine */ public function update(User $user) { - global $langs,$conf; + global $langs, $conf; - $error=0; + $error = 0; // Clean parameters - $this->comments=trim($this->comments); + $this->comments = trim($this->comments); $this->vatrate = price2num($this->vatrate); $this->value_unit = price2num($this->value_unit); if (empty($this->fk_c_exp_tax_cat)) $this->fk_c_exp_tax_cat = 0; @@ -2757,30 +2757,30 @@ class ExpenseReportLine // Update line in database $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport_det SET"; - $sql.= " comments='".$this->db->escape($this->comments)."'"; - $sql.= ",value_unit=".$this->db->escape($this->value_unit); - $sql.= ",qty=".$this->db->escape($this->qty); - $sql.= ",date='".$this->db->idate($this->date)."'"; - $sql.= ",total_ht=".$this->db->escape($this->total_ht).""; - $sql.= ",total_tva=".$this->db->escape($this->total_tva).""; - $sql.= ",total_ttc=".$this->db->escape($this->total_ttc).""; - $sql.= ",tva_tx=".$this->db->escape($this->vatrate); - $sql.= ",vat_src_code='".$this->db->escape($this->vat_src_code)."'"; - $sql.= ",rule_warning_message='".$this->db->escape($this->rule_warning_message)."'"; - $sql.= ",fk_c_exp_tax_cat=".$this->db->escape($this->fk_c_exp_tax_cat); - $sql.= ",fk_ecm_files=".($this->fk_ecm_files > 0 ? $this->fk_ecm_files : 'null'); - if ($this->fk_c_type_fees) $sql.= ",fk_c_type_fees=".$this->db->escape($this->fk_c_type_fees); - else $sql.= ",fk_c_type_fees=null"; - if ($this->fk_project > 0) $sql.= ",fk_projet=".$this->db->escape($this->fk_project); - else $sql.= ",fk_projet=null"; - $sql.= " WHERE rowid = ".$this->db->escape($this->rowid); + $sql .= " comments='".$this->db->escape($this->comments)."'"; + $sql .= ",value_unit=".$this->db->escape($this->value_unit); + $sql .= ",qty=".$this->db->escape($this->qty); + $sql .= ",date='".$this->db->idate($this->date)."'"; + $sql .= ",total_ht=".$this->db->escape($this->total_ht).""; + $sql .= ",total_tva=".$this->db->escape($this->total_tva).""; + $sql .= ",total_ttc=".$this->db->escape($this->total_ttc).""; + $sql .= ",tva_tx=".$this->db->escape($this->vatrate); + $sql .= ",vat_src_code='".$this->db->escape($this->vat_src_code)."'"; + $sql .= ",rule_warning_message='".$this->db->escape($this->rule_warning_message)."'"; + $sql .= ",fk_c_exp_tax_cat=".$this->db->escape($this->fk_c_exp_tax_cat); + $sql .= ",fk_ecm_files=".($this->fk_ecm_files > 0 ? $this->fk_ecm_files : 'null'); + if ($this->fk_c_type_fees) $sql .= ",fk_c_type_fees=".$this->db->escape($this->fk_c_type_fees); + else $sql .= ",fk_c_type_fees=null"; + if ($this->fk_project > 0) $sql .= ",fk_projet=".$this->db->escape($this->fk_project); + else $sql .= ",fk_projet=null"; + $sql .= " WHERE rowid = ".$this->db->escape($this->rowid); dol_syslog("ExpenseReportLine::update sql=".$sql); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $tmpparent=new ExpenseReport($this->db); + $tmpparent = new ExpenseReport($this->db); $result = $tmpparent->fetch($this->fk_expensereport); if ($result > 0) { @@ -2805,14 +2805,14 @@ class ExpenseReportLine dol_print_error($this->db); } - if (! $error) + if (!$error) { $this->db->commit(); return 1; } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); dol_syslog("ExpenseReportLine::update Error ".$this->error, LOG_ERR); $this->db->rollback(); return -2; @@ -2835,12 +2835,12 @@ function select_expensereport_statut($selected = '', $htmlname = 'fk_statut', $u { global $db, $langs; - $tmpep=new ExpenseReport($db); + $tmpep = new ExpenseReport($db); print ''; @@ -2880,9 +2880,9 @@ function select_type_fees_id($selected = '', $htmlname = 'type', $showempty = 0, } $sql = "SELECT c.id, c.code, c.label as type FROM ".MAIN_DB_PREFIX."c_type_fees as c"; - if ($active >= 0) $sql.= " WHERE c.active = ".$active; - $sql.= " ORDER BY c.label ASC"; - $resql=$db->query($sql); + if ($active >= 0) $sql .= " WHERE c.active = ".$active; + $sql .= " ORDER BY c.label ASC"; + $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 9ca729aedfc..9f180fc24b0 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -27,8 +27,8 @@ * \ingroup ficheinter * \brief Fichier de la classe des gestion des fiches interventions */ -require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; -require_once DOL_DOCUMENT_ROOT .'/core/class/commonobjectline.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php'; /** @@ -39,22 +39,22 @@ class Fichinter extends CommonObject /** * @var string ID to identify managed object */ - public $element='fichinter'; + public $element = 'fichinter'; /** * @var string Name of table without prefix where object is stored */ - public $table_element='fichinter'; + public $table_element = 'fichinter'; /** * @var int Field with ID of parent key if this field has a parent */ - public $fk_element='fk_fichinter'; + public $fk_element = 'fk_fichinter'; /** * @var int Name of subtable line */ - public $table_element_line='fichinterdet'; + public $table_element_line = 'fichinterdet'; /** * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png @@ -66,7 +66,7 @@ class Fichinter extends CommonObject */ protected $table_ref_field = 'ref'; - public $socid; // Id client + public $socid; // Id client public $author; @@ -90,7 +90,7 @@ class Fichinter extends CommonObject public $datem; public $duration; - public $statut = 0; // 0=draft, 1=validated, 2=invoiced, 3=Terminate + public $statut = 0; // 0=draft, 1=validated, 2=invoiced, 3=Terminate /** * @var string description @@ -107,7 +107,7 @@ class Fichinter extends CommonObject */ public $fk_project = 0; - public $extraparams=array(); + public $extraparams = array(); public $lines = array(); @@ -154,26 +154,26 @@ class Fichinter extends CommonObject // phpcs:enable global $user; - $this->nb=array(); + $this->nb = array(); $clause = "WHERE"; $sql = "SELECT count(fi.rowid) as nb"; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as fi"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON fi.fk_soc = s.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as fi"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON fi.fk_soc = s.rowid"; if (!$user->rights->societe->client->voir && !$user->socid) { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; - $sql.= " WHERE sc.fk_user = " .$user->id; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; + $sql .= " WHERE sc.fk_user = ".$user->id; $clause = "AND"; } - $sql.= " ".$clause." fi.entity IN (".getEntity('intervention').")"; + $sql .= " ".$clause." fi.entity IN (".getEntity('intervention').")"; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - while ($obj=$this->db->fetch_object($resql)) + while ($obj = $this->db->fetch_object($resql)) { - $this->nb["fichinters"]=$obj->nb; + $this->nb["fichinters"] = $obj->nb; } $this->db->free($resql); return 1; @@ -181,7 +181,7 @@ class Fichinter extends CommonObject else { dol_print_error($this->db); - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -202,83 +202,83 @@ class Fichinter extends CommonObject dol_syslog(get_class($this)."::create ref=".$this->ref); // Check parameters - if (! empty($this->ref)) // We check that ref is not already used + if (!empty($this->ref)) // We check that ref is not already used { - $result=self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used + $result = self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used if ($result > 0) { - $this->error='ErrorRefAlreadyExists'; + $this->error = 'ErrorRefAlreadyExists'; dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING); $this->db->rollback(); return -1; } } - if (! is_numeric($this->duration)) $this->duration = 0; + if (!is_numeric($this->duration)) $this->duration = 0; if ($this->socid <= 0) { - $this->error='ErrorBadParameterForFunc'; + $this->error = 'ErrorBadParameterForFunc'; dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); return -1; } $soc = new Societe($this->db); - $result=$soc->fetch($this->socid); + $result = $soc->fetch($this->socid); - $now=dol_now(); + $now = dol_now(); $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter ("; - $sql.= "fk_soc"; - $sql.= ", datec"; - $sql.= ", ref"; - $sql.= ", entity"; - $sql.= ", fk_user_author"; - $sql.= ", fk_user_modif"; - $sql.= ", description"; - $sql.= ", model_pdf"; - $sql.= ", fk_projet"; - $sql.= ", fk_contrat"; - $sql.= ", fk_statut"; - $sql.= ", note_private"; - $sql.= ", note_public"; - $sql.= ") "; - $sql.= " VALUES ("; - $sql.= $this->socid; - $sql.= ", '".$this->db->idate($now)."'"; - $sql.= ", '".$this->db->escape($this->ref)."'"; - $sql.= ", ".$conf->entity; - $sql.= ", ".$user->id; - $sql.= ", ".$user->id; - $sql.= ", ".($this->description?"'".$this->db->escape($this->description)."'":"null"); - $sql.= ", '".$this->db->escape($this->modelpdf)."'"; - $sql.= ", ".($this->fk_project ? $this->fk_project : 0); - $sql.= ", ".($this->fk_contrat ? $this->fk_contrat : 0); - $sql.= ", ".$this->statut; - $sql.= ", ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); - $sql.= ", ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); - $sql.= ")"; + $sql .= "fk_soc"; + $sql .= ", datec"; + $sql .= ", ref"; + $sql .= ", entity"; + $sql .= ", fk_user_author"; + $sql .= ", fk_user_modif"; + $sql .= ", description"; + $sql .= ", model_pdf"; + $sql .= ", fk_projet"; + $sql .= ", fk_contrat"; + $sql .= ", fk_statut"; + $sql .= ", note_private"; + $sql .= ", note_public"; + $sql .= ") "; + $sql .= " VALUES ("; + $sql .= $this->socid; + $sql .= ", '".$this->db->idate($now)."'"; + $sql .= ", '".$this->db->escape($this->ref)."'"; + $sql .= ", ".$conf->entity; + $sql .= ", ".$user->id; + $sql .= ", ".$user->id; + $sql .= ", ".($this->description ? "'".$this->db->escape($this->description)."'" : "null"); + $sql .= ", '".$this->db->escape($this->modelpdf)."'"; + $sql .= ", ".($this->fk_project ? $this->fk_project : 0); + $sql .= ", ".($this->fk_contrat ? $this->fk_contrat : 0); + $sql .= ", ".$this->statut; + $sql .= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null"); + $sql .= ", ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null"); + $sql .= ")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); - $result=$this->db->query($sql); + $result = $this->db->query($sql); if ($result) { - $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."fichinter"); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."fichinter"); if ($this->id) { - $this->ref='(PROV'.$this->id.')'; + $this->ref = '(PROV'.$this->id.')'; $sql = 'UPDATE '.MAIN_DB_PREFIX."fichinter SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id; dol_syslog(get_class($this)."::create", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) $error++; + $resql = $this->db->query($sql); + if (!$resql) $error++; } - if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) + if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { - $result=$this->insertExtraFields(); + $result = $this->insertExtraFields(); if ($result < 0) { $error++; @@ -286,22 +286,22 @@ class Fichinter extends CommonObject } // Add linked object - if (! $error && $this->origin && $this->origin_id) + if (!$error && $this->origin && $this->origin_id) { $ret = $this->add_object_linked(); - if (! $ret) dol_print_error($this->db); + if (!$ret) dol_print_error($this->db); } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('FICHINTER_CREATE', $user); + $result = $this->call_trigger('FICHINTER_CREATE', $user); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return $this->id; @@ -309,14 +309,14 @@ class Fichinter extends CommonObject else { $this->db->rollback(); - $this->error=join(',', $this->errors); + $this->error = join(',', $this->errors); dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); return -1; } } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); $this->db->rollback(); return -1; } @@ -333,10 +333,10 @@ class Fichinter extends CommonObject { global $conf; - if (! is_numeric($this->duration)) { + if (!is_numeric($this->duration)) { $this->duration = 0; } - if (! dol_strlen($this->fk_project)) { + if (!dol_strlen($this->fk_project)) { $this->fk_project = 0; } @@ -345,30 +345,30 @@ class Fichinter extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; - $sql.= "description = '".$this->db->escape($this->description)."'"; - $sql.= ", duree = ".$this->duration; - $sql.= ", fk_projet = ".$this->fk_project; - $sql.= ", note_private = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null"); - $sql.= ", note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null"); - $sql.= ", fk_user_modif = ".$user->id; - $sql.= " WHERE rowid = ".$this->id; + $sql .= "description = '".$this->db->escape($this->description)."'"; + $sql .= ", duree = ".$this->duration; + $sql .= ", fk_projet = ".$this->fk_project; + $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null"); + $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null"); + $sql .= ", fk_user_modif = ".$user->id; + $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); if ($this->db->query($sql)) { - if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $result=$this->insertExtraFields(); + $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('FICHINTER_MODIFY', $user); + $result = $this->call_trigger('FICHINTER_MODIFY', $user); if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers } @@ -378,7 +378,7 @@ class Fichinter extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); $this->db->rollback(); return -1; } @@ -394,19 +394,19 @@ class Fichinter extends CommonObject public function fetch($rowid, $ref = '') { $sql = "SELECT f.rowid, f.ref, f.description, f.fk_soc, f.fk_statut,"; - $sql.= " f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,"; - $sql.= " f.date_valid as datev,"; - $sql.= " f.tms as datem,"; - $sql.= " f.duree, f.fk_projet as fk_project, f.note_public, f.note_private, f.model_pdf, f.extraparams, fk_contrat"; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; + $sql .= " f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,"; + $sql .= " f.date_valid as datev,"; + $sql .= " f.tms as datem,"; + $sql .= " f.duree, f.fk_projet as fk_project, f.note_public, f.note_private, f.model_pdf, f.extraparams, fk_contrat"; + $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f"; if ($ref) { - $sql.= " WHERE f.entity IN (".getEntity('intervention').")"; - $sql.= " AND f.ref='".$this->db->escape($ref)."'"; + $sql .= " WHERE f.entity IN (".getEntity('intervention').")"; + $sql .= " AND f.ref='".$this->db->escape($ref)."'"; } - else $sql.= " WHERE f.rowid=".$rowid; + else $sql .= " WHERE f.rowid=".$rowid; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { if ($this->db->num_rows($resql)) @@ -443,7 +443,7 @@ class Fichinter extends CommonObject /* * Lines */ - $result=$this->fetch_lines(); + $result = $this->fetch_lines(); if ($result < 0) { return -3; @@ -454,7 +454,7 @@ class Fichinter extends CommonObject } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -469,7 +469,7 @@ class Fichinter extends CommonObject { global $langs, $conf; - $error=0; + $error = 0; // Protection if ($this->statut <= self::STATUS_DRAFT) @@ -482,10 +482,10 @@ class Fichinter extends CommonObject $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; - $sql.= " SET fk_statut = ".self::STATUS_DRAFT; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET fk_statut = ".self::STATUS_DRAFT; + $sql .= " WHERE rowid = ".$this->id; - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { if (!$error) { @@ -494,12 +494,12 @@ class Fichinter extends CommonObject if (!$error) { // Call trigger - $result=$this->call_trigger('FICHINTER_UNVALIDATE', $user); + $result = $this->call_trigger('FICHINTER_UNVALIDATE', $user); if ($result < 0) $error++; } if (!$error) { - $this->statut=self::STATUS_DRAFT; + $this->statut = self::STATUS_DRAFT; $this->db->commit(); return 1; } else { @@ -510,7 +510,7 @@ class Fichinter extends CommonObject else { $this->db->rollback(); - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); return -1; } } @@ -527,16 +527,16 @@ class Fichinter extends CommonObject global $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $error=0; + $error = 0; if ($this->statut != 1) { $this->db->begin(); - $now=dol_now(); + $now = dol_now(); // Define new ref - if (! $error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life + if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life { $num = $this->getNextNumRef($this->thirdparty); } @@ -547,31 +547,31 @@ class Fichinter extends CommonObject $this->newref = $num; $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; - $sql.= " SET fk_statut = 1"; - $sql.= ", ref = '".$num."'"; - $sql.= ", date_valid = '".$this->db->idate($now)."'"; - $sql.= ", fk_user_valid = ".$user->id; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND entity = ".$conf->entity; - $sql.= " AND fk_statut = 0"; + $sql .= " SET fk_statut = 1"; + $sql .= ", ref = '".$num."'"; + $sql .= ", date_valid = '".$this->db->idate($now)."'"; + $sql .= ", fk_user_valid = ".$user->id; + $sql .= " WHERE rowid = ".$this->id; + $sql .= " AND entity = ".$conf->entity; + $sql .= " AND fk_statut = 0"; dol_syslog(get_class($this)."::setValid", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) + $resql = $this->db->query($sql); + if (!$resql) { dol_print_error($this->db); $error++; } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('FICHINTER_VALIDATE', $user); + $result = $this->call_trigger('FICHINTER_VALIDATE', $user); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $this->oldref = $this->ref; @@ -581,17 +581,17 @@ class Fichinter extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Now we rename also files into index - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref)+1).")), filepath = 'ficheinter/".$this->db->escape($this->newref)."'"; - $sql.= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'ficheinter/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; + $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'ficheinter/".$this->db->escape($this->newref)."'"; + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'ficheinter/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->error = $this->db->lasterror(); } + if (!$resql) { $error++; $this->error = $this->db->lasterror(); } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->ficheinter->dir_output.'/'.$oldref; $dirdest = $conf->ficheinter->dir_output.'/'.$newref; - if (! $error && file_exists($dirsource)) + if (!$error && file_exists($dirsource)) { dol_syslog(get_class($this)."::setValid rename dir ".$dirsource." into ".$dirdest); @@ -599,13 +599,13 @@ class Fichinter extends CommonObject { dol_syslog("Rename ok"); // Rename docs starting with $oldref with $newref - $listoffiles=dol_dir_list($conf->ficheinter->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach($listoffiles as $fileentry) + $listoffiles = dol_dir_list($conf->ficheinter->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); + foreach ($listoffiles as $fileentry) { - $dirsource=$fileentry['name']; - $dirdest=preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); - $dirsource=$fileentry['path'].'/'.$dirsource; - $dirdest=$fileentry['path'].'/'.$dirdest; + $dirsource = $fileentry['name']; + $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); + $dirsource = $fileentry['path'].'/'.$dirsource; + $dirdest = $fileentry['path'].'/'.$dirdest; @rename($dirsource, $dirdest); } } @@ -614,15 +614,15 @@ class Fichinter extends CommonObject } // Set new ref and define current statut - if (! $error) + if (!$error) { $this->ref = $num; - $this->statut=1; - $this->brouillon=0; - $this->date_validation=$now; + $this->statut = 1; + $this->brouillon = 0; + $this->date_validation = $now; } - if (! $error) + if (!$error) { $this->db->commit(); return 1; @@ -652,7 +652,7 @@ class Fichinter extends CommonObject $thm = $this->author->thm; - foreach($this->lines as $line) { + foreach ($this->lines as $line) { $amount += ($line->duration / 60 / 60 * $thm); } @@ -673,16 +673,16 @@ class Fichinter extends CommonObject */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) { - global $conf,$langs; + global $conf, $langs; $langs->load("interventions"); - if (! dol_strlen($modele)) { + if (!dol_strlen($modele)) { $modele = 'soleil'; if ($this->modelpdf) { $modele = $this->modelpdf; - } elseif (! empty($conf->global->FICHEINTER_ADDON_PDF)) { + } elseif (!empty($conf->global->FICHEINTER_ADDON_PDF)) { $modele = $conf->global->FICHEINTER_ADDON_PDF; } } @@ -720,18 +720,18 @@ class Fichinter extends CommonObject global $langs; $langs->load("fichinter"); - $this->statuts[self::STATUS_DRAFT]=$langs->trans('Draft'); - $this->statuts[self::STATUS_VALIDATED]=$langs->trans('Validated'); - $this->statuts[self::STATUS_BILLED]=$langs->trans('StatusInterInvoiced'); - $this->statuts[self::STATUS_CLOSED]=$langs->trans('Done'); - $this->statuts_short[self::STATUS_DRAFT]=$langs->trans('Draft'); - $this->statuts_short[self::STATUS_VALIDATED]=$langs->trans('Validated'); - $this->statuts_short[self::STATUS_BILLED]=$langs->trans('StatusInterInvoiced'); - $this->statuts_short[self::STATUS_CLOSED]=$langs->trans('Done'); - $this->statuts_logo[self::STATUS_DRAFT]='status0'; - $this->statuts_logo[self::STATUS_VALIDATED]='status1'; - $this->statuts_logo[self::STATUS_BILLED]='status6'; - $this->statuts_logo[self::STATUS_CLOSED]='status6'; + $this->statuts[self::STATUS_DRAFT] = $langs->trans('Draft'); + $this->statuts[self::STATUS_VALIDATED] = $langs->trans('Validated'); + $this->statuts[self::STATUS_BILLED] = $langs->trans('StatusInterInvoiced'); + $this->statuts[self::STATUS_CLOSED] = $langs->trans('Done'); + $this->statuts_short[self::STATUS_DRAFT] = $langs->trans('Draft'); + $this->statuts_short[self::STATUS_VALIDATED] = $langs->trans('Validated'); + $this->statuts_short[self::STATUS_BILLED] = $langs->trans('StatusInterInvoiced'); + $this->statuts_short[self::STATUS_CLOSED] = $langs->trans('Done'); + $this->statuts_logo[self::STATUS_DRAFT] = 'status0'; + $this->statuts_logo[self::STATUS_VALIDATED] = 'status1'; + $this->statuts_logo[self::STATUS_BILLED] = 'status6'; + $this->statuts_logo[self::STATUS_CLOSED] = 'status6'; } return dolGetStatus($this->statuts[$status], $this->statuts_short[$status], '', $this->statuts_logo[$status], $mode); @@ -750,32 +750,32 @@ class Fichinter extends CommonObject { global $conf, $langs, $hookmanager; - $result=''; + $result = ''; - $label = '' . $langs->trans("ShowIntervention") . ''; - if (! empty($this->ref)) - $label .= '
' . $langs->trans('Ref') . ': '.$this->ref; + $label = ''.$langs->trans("ShowIntervention").''; + if (!empty($this->ref)) + $label .= '
'.$langs->trans('Ref').': '.$this->ref; $url = DOL_URL_ROOT.'/fichinter/card.php?id='.$this->id; if ($option !== 'nolink') { // Add param to save lastsearch_values or not - $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; - if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; } - $linkclose=''; + $linkclose = ''; if (empty($notooltip)) { - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $label=$langs->trans("ShowIntervention"); - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + $label = $langs->trans("ShowIntervention"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } - $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose.=' class="classfortooltip"'; + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; /* $hookmanager->initHooks(array('fichinterdao')); @@ -786,18 +786,18 @@ class Fichinter extends CommonObject } $linkstart = ''; - $linkend=''; + $linkstart .= $linkclose.'>'; + $linkend = ''; $result .= $linkstart; - if ($withpicto) $result.=img_object(($notooltip?'':$label), $this->picto, ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1); - if ($withpicto != 2) $result.= $this->ref; + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= $this->ref; $result .= $linkend; global $action; $hookmanager->initHooks(array('intervnetiondao')); - $parameters=array('id'=>$this->id, 'getnomurl'=>$result); - $reshook=$hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $parameters = array('id'=>$this->id, 'getnomurl'=>$result); + $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; @@ -817,7 +817,7 @@ class Fichinter extends CommonObject global $conf, $db, $langs; $langs->load("interventions"); - if (! empty($conf->global->FICHEINTER_ADDON)) + if (!empty($conf->global->FICHEINTER_ADDON)) { $mybool = false; @@ -831,7 +831,7 @@ class Fichinter extends CommonObject $dir = dol_buildpath($reldir."core/modules/fichinter/"); // Load file with numbering class (if found) - $mybool|=@include_once $dir.$file; + $mybool |= @include_once $dir.$file; } if ($mybool === false) { @@ -843,7 +843,7 @@ class Fichinter extends CommonObject $numref = ""; $numref = $obj->getNextValue($soc, $this); - if ( $numref != "") + if ($numref != "") { return $numref; } @@ -872,14 +872,14 @@ class Fichinter extends CommonObject global $conf; $sql = "SELECT f.rowid,"; - $sql.= " f.datec,"; - $sql.= " f.tms as date_modification,"; - $sql.= " f.date_valid as datev,"; - $sql.= " f.fk_user_author,"; - $sql.= " f.fk_user_modif as fk_user_modification,"; - $sql.= " f.fk_user_valid"; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f"; - $sql.= " WHERE f.rowid = ".$id; + $sql .= " f.datec,"; + $sql .= " f.tms as date_modification,"; + $sql .= " f.date_valid as datev,"; + $sql .= " f.fk_user_author,"; + $sql .= " f.fk_user_modif as fk_user_modification,"; + $sql .= " f.fk_user_valid"; + $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f"; + $sql .= " WHERE f.rowid = ".$id; $resql = $this->db->query($sql); if ($resql) @@ -896,19 +896,19 @@ class Fichinter extends CommonObject $cuser = new User($this->db); $cuser->fetch($obj->fk_user_author); - $this->user_creation = $cuser; + $this->user_creation = $cuser; if ($obj->fk_user_valid) { $vuser = new User($this->db); $vuser->fetch($obj->fk_user_valid); - $this->user_validation = $vuser; + $this->user_validation = $vuser; } if ($obj->fk_user_modification) { $muser = new User($this->db); $muser->fetch($obj->fk_user_modification); - $this->user_modification = $muser; + $this->user_modification = $muser; } } $this->db->free($resql); @@ -928,98 +928,98 @@ class Fichinter extends CommonObject */ public function delete($user, $notrigger = 0) { - global $conf,$langs; + global $conf, $langs; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $error=0; + $error = 0; $this->db->begin(); - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('FICHINTER_DELETE', $user); + $result = $this->call_trigger('FICHINTER_DELETE', $user); if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers } // Delete linked object - if (! $error) + if (!$error) { $res = $this->deleteObjectLinked(); if ($res < 0) $error++; } // Delete linked contacts - if (! $error) + if (!$error) { $res = $this->delete_linked_contact(); if ($res < 0) { - $this->error='ErrorFailToDeleteLinkedContact'; + $this->error = 'ErrorFailToDeleteLinkedContact'; $error++; } } - if (! $error) + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet"; - $sql.= " WHERE fk_fichinter = ".$this->id; + $sql .= " WHERE fk_fichinter = ".$this->id; $resql = $this->db->query($sql); - if (! $resql) $error++; + if (!$resql) $error++; } - if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used + if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { // Remove extrafields $res = $this->deleteExtraFields(); if ($res < 0) $error++; } - if (! $error) + if (!$error) { // Delete object $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter"; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " WHERE rowid = ".$this->id; dol_syslog("Fichinter::delete", LOG_DEBUG); $resql = $this->db->query($sql); - if (! $resql) $error++; + if (!$resql) $error++; } - if (! $error) + if (!$error) { // Remove directory with files $fichinterref = dol_sanitizeFileName($this->ref); if ($conf->ficheinter->dir_output) { - $dir = $conf->ficheinter->dir_output . "/" . $fichinterref ; - $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf"; + $dir = $conf->ficheinter->dir_output."/".$fichinterref; + $file = $conf->ficheinter->dir_output."/".$fichinterref."/".$fichinterref.".pdf"; if (file_exists($file)) { dol_delete_preview($this); - if (! dol_delete_file($file, 0, 0, 0, $this)) // For triggers + if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers { $langs->load("errors"); - $this->error=$langs->trans("ErrorFailToDeleteFile", $file); + $this->error = $langs->trans("ErrorFailToDeleteFile", $file); return 0; } } if (file_exists($dir)) { - if (! dol_delete_dir_recursive($dir)) + if (!dol_delete_dir_recursive($dir)) { $langs->load("errors"); - $this->error=$langs->trans("ErrorFailToDeleteDir", $dir); + $this->error = $langs->trans("ErrorFailToDeleteDir", $dir); return 0; } } } } - if (! $error) + if (!$error) { $this->db->commit(); return 1; @@ -1047,9 +1047,9 @@ class Fichinter extends CommonObject if ($user->rights->ficheinter->creer) { $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; - $sql.= " SET datei = '".$this->db->idate($date_delivery)."'"; - $sql.= " WHERE rowid = ".$this->id; - $sql.= " AND fk_statut = 0"; + $sql .= " SET datei = '".$this->db->idate($date_delivery)."'"; + $sql .= " WHERE rowid = ".$this->id; + $sql .= " AND fk_statut = 0"; if ($this->db->query($sql)) { @@ -1058,7 +1058,7 @@ class Fichinter extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); dol_syslog("Fichinter::set_date_delivery Erreur SQL"); return -1; } @@ -1081,9 +1081,9 @@ class Fichinter extends CommonObject if ($user->rights->ficheinter->creer) { $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; - $sql.= " SET description = '".$this->db->escape($description)."',"; - $sql.= " fk_user_modif = ".$user->id; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET description = '".$this->db->escape($description)."',"; + $sql .= " fk_user_modif = ".$user->id; + $sql .= " WHERE rowid = ".$this->id; if ($this->db->query($sql)) { @@ -1092,7 +1092,7 @@ class Fichinter extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); dol_syslog("Fichinter::set_description Erreur SQL"); return -1; } @@ -1116,8 +1116,8 @@ class Fichinter extends CommonObject if ($user->rights->ficheinter->creer) { $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter "; - $sql.= " SET fk_contrat = '".$contractid."'"; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " SET fk_contrat = '".$contractid."'"; + $sql .= " WHERE rowid = ".$this->id; if ($this->db->query($sql)) { @@ -1126,7 +1126,7 @@ class Fichinter extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -1146,37 +1146,37 @@ class Fichinter extends CommonObject { global $hookmanager; - $error=0; + $error = 0; $this->db->begin(); // get extrafields so they will be clone - foreach($this->lines as $line) + foreach ($this->lines as $line) $line->fetch_optionals($line->rowid); // Load source object $objFrom = clone $this; // Change socid if needed - if (! empty($socid) && $socid != $this->socid) + if (!empty($socid) && $socid != $this->socid) { $objsoc = new Societe($this->db); - if ($objsoc->fetch($socid)>0) + if ($objsoc->fetch($socid) > 0) { - $this->socid = $objsoc->id; + $this->socid = $objsoc->id; //$this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); //$this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); - $this->fk_project = ''; - $this->fk_delivery_address = ''; + $this->fk_project = ''; + $this->fk_delivery_address = ''; } // TODO Change product price if multi-prices } - $this->id=0; + $this->id = 0; $this->ref = ''; - $this->statut=0; + $this->statut = 0; // Clear fields $this->user_author_id = $user->id; @@ -1187,10 +1187,10 @@ class Fichinter extends CommonObject // Create clone $this->context['createfromclone'] = 'createfromclone'; - $result=$this->create($user); + $result = $this->create($user); if ($result < 0) $error++; - if (! $error) + if (!$error) { // Add lines because it is not included into create function foreach ($this->lines as $line) @@ -1201,9 +1201,9 @@ class Fichinter extends CommonObject // Hook of thirdparty module if (is_object($hookmanager)) { - $parameters=array('objFrom'=>$objFrom); - $action=''; - $reshook=$hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $parameters = array('objFrom'=>$objFrom); + $action = ''; + $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) $error++; } } @@ -1211,7 +1211,7 @@ class Fichinter extends CommonObject unset($this->context['createfromclone']); // End - if (! $error) + if (!$error) { $this->db->commit(); return $this->id; @@ -1244,18 +1244,18 @@ class Fichinter extends CommonObject $this->db->begin(); // Insertion ligne - $line=new FichinterLigne($this->db); + $line = new FichinterLigne($this->db); $line->fk_fichinter = $fichinterid; $line->desc = $desc; $line->datei = $date_intervention; $line->duration = $duration; - if (is_array($array_options) && count($array_options)>0) { - $line->array_options=$array_options; + if (is_array($array_options) && count($array_options) > 0) { + $line->array_options = $array_options; } - $result=$line->insert($user); + $result = $line->insert($user); if ($result >= 0) { @@ -1264,7 +1264,7 @@ class Fichinter extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); $this->db->rollback(); return -1; } @@ -1281,32 +1281,32 @@ class Fichinter extends CommonObject */ public function initAsSpecimen() { - global $user,$langs,$conf; + global $user, $langs, $conf; - $now=dol_now(); + $now = dol_now(); // Initialise parametres - $this->id=0; + $this->id = 0; $this->ref = 'SPECIMEN'; - $this->specimen=1; + $this->specimen = 1; $this->socid = 1; $this->datec = $now; - $this->note_private='Private note'; - $this->note_public='SPECIMEN'; + $this->note_private = 'Private note'; + $this->note_public = 'SPECIMEN'; $this->duration = 0; $nbp = 25; $xnbp = 0; while ($xnbp < $nbp) { - $line=new FichinterLigne($this->db); - $line->desc=$langs->trans("Description")." ".$xnbp; - $line->datei=($now-3600*(1+$xnbp)); - $line->duration=600; - $line->fk_fichinter=0; - $this->lines[$xnbp]=$line; + $line = new FichinterLigne($this->db); + $line->desc = $langs->trans("Description")." ".$xnbp; + $line->datei = ($now - 3600 * (1 + $xnbp)); + $line->duration = 600; + $line->fk_fichinter = 0; + $this->lines[$xnbp] = $line; $xnbp++; - $this->duration+=$line->duration; + $this->duration += $line->duration; } } @@ -1322,11 +1322,11 @@ class Fichinter extends CommonObject $this->lines = array(); $sql = 'SELECT rowid, fk_fichinter, description, duree, date, rang'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet'; - $sql.=' WHERE fk_fichinter = '.$this->id .' ORDER BY rang ASC, date ASC' ; + $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet'; + $sql .= ' WHERE fk_fichinter = '.$this->id.' ORDER BY rang ASC, date ASC'; dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -1341,7 +1341,7 @@ class Fichinter extends CommonObject $line->desc = $objp->description; $line->duration = $objp->duree; //For invoicing we calculing hours - $line->qty = round($objp->duree/3600, 2); + $line->qty = round($objp->duree / 3600, 2); $line->date = $this->db->jdate($objp->date); $line->datei = $this->db->jdate($objp->date); $line->rang = $objp->rang; @@ -1357,7 +1357,7 @@ class Fichinter extends CommonObject } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); return -1; } } @@ -1393,7 +1393,7 @@ class FichinterLigne extends CommonObjectLine /** * @var string Error code (or message) */ - public $error=''; + public $error = ''; // From llx_fichinterdet /** @@ -1401,25 +1401,25 @@ class FichinterLigne extends CommonObjectLine */ public $fk_fichinter; - public $desc; // Description ligne - public $datei; // Date intervention - public $duration; // Duree de l'intervention + public $desc; // Description ligne + public $datei; // Date intervention + public $duration; // Duree de l'intervention public $rang = 0; /** * @var string ID to identify managed object */ - public $element='fichinterdet'; + public $element = 'fichinterdet'; /** * @var string Name of table without prefix where object is stored */ - public $table_element='fichinterdet'; + public $table_element = 'fichinterdet'; /** * @var int Field with ID of parent key if this field has a parent */ - public $fk_element='fk_fichinter'; + public $fk_element = 'fk_fichinter'; /** * Constructor @@ -1440,9 +1440,9 @@ class FichinterLigne extends CommonObjectLine public function fetch($rowid) { $sql = 'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang,'; - $sql.= ' ft.date as datei'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft'; - $sql.= ' WHERE ft.rowid = '.$rowid; + $sql .= ' ft.date as datei'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft'; + $sql .= ' WHERE ft.rowid = '.$rowid; dol_syslog("FichinterLigne::fetch", LOG_DEBUG); $result = $this->db->query($sql); @@ -1450,9 +1450,9 @@ class FichinterLigne extends CommonObjectLine { $objp = $this->db->fetch_object($result); $this->rowid = $objp->rowid; - $this->id = $objp->rowid; + $this->id = $objp->rowid; $this->fk_fichinter = $objp->fk_fichinter; - $this->datei = $this->db->jdate($objp->datei); + $this->datei = $this->db->jdate($objp->datei); $this->desc = $objp->description; $this->duration = $objp->duree; $this->rang = $objp->rang; @@ -1462,7 +1462,7 @@ class FichinterLigne extends CommonObjectLine } else { - $this->error=$this->db->error().' sql='.$sql; + $this->error = $this->db->error().' sql='.$sql; return -1; } } @@ -1476,7 +1476,7 @@ class FichinterLigne extends CommonObjectLine */ public function insert($user, $notrigger = 0) { - global $langs,$conf; + global $langs, $conf; $error = 0; @@ -1484,12 +1484,12 @@ class FichinterLigne extends CommonObjectLine $this->db->begin(); - $rangToUse=$this->rang; + $rangToUse = $this->rang; if ($rangToUse == -1) { // Recupere rang max de la ligne d'intervention dans $rangmax $sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'fichinterdet'; - $sql.= ' WHERE fk_fichinter ='.$this->fk_fichinter; + $sql .= ' WHERE fk_fichinter ='.$this->fk_fichinter; $resql = $this->db->query($sql); if ($resql) { @@ -1506,24 +1506,24 @@ class FichinterLigne extends CommonObjectLine // Insertion dans base de la ligne $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'fichinterdet'; - $sql.= ' (fk_fichinter, description, date, duree, rang)'; - $sql.= " VALUES (".$this->fk_fichinter.","; - $sql.= " '".$this->db->escape($this->desc)."',"; - $sql.= " '".$this->db->idate($this->datei)."',"; - $sql.= " ".$this->duration.","; - $sql.= ' '.$rangToUse; - $sql.= ')'; + $sql .= ' (fk_fichinter, description, date, duree, rang)'; + $sql .= " VALUES (".$this->fk_fichinter.","; + $sql .= " '".$this->db->escape($this->desc)."',"; + $sql .= " '".$this->db->idate($this->datei)."',"; + $sql .= " ".$this->duration.","; + $sql .= ' '.$rangToUse; + $sql .= ')'; dol_syslog("FichinterLigne::insert", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'fichinterdet'); - $this->rowid=$this->id; + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'fichinterdet'); + $this->rowid = $this->id; if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $result=$this->insertExtraFields(); + $result = $this->insertExtraFields(); if ($result < 0) { $error++; @@ -1531,16 +1531,16 @@ class FichinterLigne extends CommonObjectLine } - $result=$this->update_total(); + $result = $this->update_total(); if ($result > 0) { - $this->rang=$rangToUse; + $this->rang = $rangToUse; - if (! $notrigger) + if (!$notrigger) { // Call trigger - $result=$this->call_trigger('LINEFICHINTER_CREATE', $user); + $result = $this->call_trigger('LINEFICHINTER_CREATE', $user); if ($result < 0) { $error++; } // End call triggers } @@ -1558,7 +1558,7 @@ class FichinterLigne extends CommonObjectLine } else { - $this->error=$this->db->error()." sql=".$sql; + $this->error = $this->db->error()." sql=".$sql; $this->db->rollback(); return -1; } @@ -1574,7 +1574,7 @@ class FichinterLigne extends CommonObjectLine */ public function update($user, $notrigger = 0) { - global $langs,$conf; + global $langs, $conf; $error = 0; @@ -1582,32 +1582,32 @@ class FichinterLigne extends CommonObjectLine // Mise a jour ligne en base $sql = "UPDATE ".MAIN_DB_PREFIX."fichinterdet SET"; - $sql.= " description='".$this->db->escape($this->desc)."'"; - $sql.= ",date='".$this->db->idate($this->datei)."'"; - $sql.= ",duree=".$this->duration; - $sql.= ",rang='".$this->db->escape($this->rang)."'"; - $sql.= " WHERE rowid = ".$this->id; + $sql .= " description='".$this->db->escape($this->desc)."'"; + $sql .= ",date='".$this->db->idate($this->datei)."'"; + $sql .= ",duree=".$this->duration; + $sql .= ",rang='".$this->db->escape($this->rang)."'"; + $sql .= " WHERE rowid = ".$this->id; dol_syslog("FichinterLigne::update", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $result=$this->insertExtraFields(); + $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } - $result=$this->update_total(); + $result = $this->update_total(); if ($result > 0) { - if (! $notrigger) + if (!$notrigger) { // Call trigger - $result=$this->call_trigger('LINEFICHINTER_UPDATE', $user); + $result = $this->call_trigger('LINEFICHINTER_UPDATE', $user); if ($result < 0) { $error++; } // End call triggers } @@ -1620,14 +1620,14 @@ class FichinterLigne extends CommonObjectLine } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } } else { - $this->error=$this->db->lasterror(); + $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } @@ -1647,25 +1647,25 @@ class FichinterLigne extends CommonObjectLine $this->db->begin(); $sql = "SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee "; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinterdet"; - $sql.= " WHERE fk_fichinter=".$this->fk_fichinter; + $sql .= " FROM ".MAIN_DB_PREFIX."fichinterdet"; + $sql .= " WHERE fk_fichinter=".$this->fk_fichinter; dol_syslog("FichinterLigne::update_total", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $obj=$this->db->fetch_object($resql); - $total_duration=0; + $obj = $this->db->fetch_object($resql); + $total_duration = 0; if (!empty($obj->total_duration)) $total_duration = $obj->total_duration; $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; - $sql.= " SET duree = ".$total_duration; - $sql.= " , dateo = ".(! empty($obj->dateo)?"'".$this->db->idate($obj->dateo)."'":"null"); - $sql.= " , datee = ".(! empty($obj->datee)?"'".$this->db->idate($obj->datee)."'":"null"); - $sql.= " WHERE rowid = ".$this->fk_fichinter; + $sql .= " SET duree = ".$total_duration; + $sql .= " , dateo = ".(!empty($obj->dateo) ? "'".$this->db->idate($obj->dateo)."'" : "null"); + $sql .= " , datee = ".(!empty($obj->datee) ? "'".$this->db->idate($obj->datee)."'" : "null"); + $sql .= " WHERE rowid = ".$this->fk_fichinter; dol_syslog("FichinterLigne::update_total", LOG_DEBUG); - $resql=$this->db->query($sql); + $resql = $this->db->query($sql); if ($resql) { $this->db->commit(); @@ -1673,14 +1673,14 @@ class FichinterLigne extends CommonObjectLine } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); $this->db->rollback(); return -2; } } else { - $this->error=$this->db->error(); + $this->error = $this->db->error(); $this->db->rollback(); return -1; } @@ -1695,9 +1695,9 @@ class FichinterLigne extends CommonObjectLine */ public function deleteline($user, $notrigger = 0) { - global $langs,$conf; + global $langs, $conf; - $error=0; + $error = 0; if ($this->statut == 0) { @@ -1712,10 +1712,10 @@ class FichinterLigne extends CommonObjectLine $result = $this->update_total(); if ($result > 0) { - if (! $notrigger) + if (!$notrigger) { // Call trigger - $result=$this->call_trigger('LINEFICHINTER_DELETE', $user); + $result = $this->call_trigger('LINEFICHINTER_DELETE', $user); if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers } @@ -1731,7 +1731,7 @@ class FichinterLigne extends CommonObjectLine } else { - $this->error=$this->db->error()." sql=".$sql; + $this->error = $this->db->error()." sql=".$sql; $this->db->rollback(); return -1; } diff --git a/htdocs/margin/agentMargins.php b/htdocs/margin/agentMargins.php index f65acb2eeda..c2ca9da8bbd 100644 --- a/htdocs/margin/agentMargins.php +++ b/htdocs/margin/agentMargins.php @@ -35,7 +35,7 @@ $langs->loadLangs(array('companies', 'bills', 'products', 'margins')); $mesg = ''; // Load variable for pagination -$limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page', 'int'); @@ -43,16 +43,16 @@ if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortorder) $sortorder="ASC"; -if (! $sortfield) +if (!$sortorder) $sortorder = "ASC"; +if (!$sortfield) { if ($agentid > 0) - $sortfield="s.nom"; + $sortfield = "s.nom"; else - $sortfield="u.lastname"; + $sortfield = "u.lastname"; } -$startdate=$enddate=''; +$startdate = $enddate = ''; $startdateday = GETPOST('startdateday', 'int'); $startdatemonth = GETPOST('startdatemonth', 'int'); @@ -64,7 +64,7 @@ $enddateyear = GETPOST('enddateyear', 'int'); if (!empty($startdatemonth)) $startdate = dol_mktime(0, 0, 0, $startdatemonth, $startdateday, $startdateyear); if (!empty($enddatemonth)) - $enddate = dol_mktime(23, 59, 59, $enddatemonth, $enddateday, $enddateyear); + $enddate = dol_mktime(23, 59, 59, $enddatemonth, $enddateday, $enddateyear); // Security check if ($user->rights->margins->read->all) { @@ -72,7 +72,7 @@ if ($user->rights->margins->read->all) { } else { $agentid = $user->id; } -$result=restrictedArea($user, 'margins'); +$result = restrictedArea($user, 'margins'); /* @@ -89,19 +89,19 @@ $result=restrictedArea($user, 'margins'); $userstatic = new User($db); $companystatic = new Societe($db); -$invoicestatic=new Facture($db); +$invoicestatic = new Facture($db); $form = new Form($db); llxHeader('', $langs->trans("Margins").' - '.$langs->trans("Agents")); -$text=$langs->trans("Margins"); +$text = $langs->trans("Margins"); //print load_fiche_titre($text); // Show tabs -$head=marges_prepare_head($user); -$titre=$langs->trans("Margins"); -$picto='margin'; +$head = marges_prepare_head($user); +$titre = $langs->trans("Margins"); +$picto = 'margin'; print '
'; @@ -135,45 +135,45 @@ print '
'; $invoice_status_except_list = array(Facture::STATUS_DRAFT, Facture::STATUS_ABANDONED); $sql = "SELECT"; -$sql.= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; -$sql.= " u.rowid as agent, u.login, u.lastname, u.firstname,"; -$sql.= " sum(d.total_ht) as selling_price,"; +$sql .= " s.rowid as socid, s.nom as name, s.code_client, s.client,"; +$sql .= " u.rowid as agent, u.login, u.lastname, u.firstname,"; +$sql .= " sum(d.total_ht) as selling_price,"; // Note: qty and buy_price_ht is always positive (if not your database may be corrupted, you can update this) -$sql.= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,"; -$sql.= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge" ; -$sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; -$sql.= ", ".MAIN_DB_PREFIX."facture as f"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE)?-1:$conf->global->AGENT_CONTACT_TYPE); -$sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; -$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -$sql.= ", ".MAIN_DB_PREFIX."user as u"; -$sql.= " WHERE f.fk_soc = s.rowid"; -$sql.= ' AND f.entity IN ('.getEntity('invoice').')'; -$sql.= " AND sc.fk_soc = f.fk_soc"; -$sql.= " AND (d.product_type = 0 OR d.product_type = 1)"; -if (! empty($conf->global->AGENT_CONTACT_TYPE)) - $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; +$sql .= " sum(".$db->ifsql('d.total_ht < 0', 'd.qty * d.buy_price_ht * -1', 'd.qty * d.buy_price_ht').") as buying_price,"; +$sql .= " sum(".$db->ifsql('d.total_ht < 0', '-1 * (abs(d.total_ht) - (d.buy_price_ht * d.qty))', 'd.total_ht - (d.buy_price_ht * d.qty)').") as marge"; +$sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; +$sql .= ", ".MAIN_DB_PREFIX."facture as f"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact e ON e.element_id = f.rowid and e.statut = 4 and e.fk_c_type_contact = ".(empty($conf->global->AGENT_CONTACT_TYPE) ?-1 : $conf->global->AGENT_CONTACT_TYPE); +$sql .= ", ".MAIN_DB_PREFIX."facturedet as d"; +$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +$sql .= ", ".MAIN_DB_PREFIX."user as u"; +$sql .= " WHERE f.fk_soc = s.rowid"; +$sql .= ' AND f.entity IN ('.getEntity('invoice').')'; +$sql .= " AND sc.fk_soc = f.fk_soc"; +$sql .= " AND (d.product_type = 0 OR d.product_type = 1)"; +if (!empty($conf->global->AGENT_CONTACT_TYPE)) + $sql .= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; else $sql .= " AND sc.fk_user = u.rowid"; -$sql.= " AND f.fk_statut NOT IN (" . implode(', ', $invoice_status_except_list) . ")"; -$sql.= ' AND s.entity IN ('.getEntity('societe').')'; -$sql.= " AND d.fk_facture = f.rowid"; +$sql .= " AND f.fk_statut NOT IN (".implode(', ', $invoice_status_except_list).")"; +$sql .= ' AND s.entity IN ('.getEntity('societe').')'; +$sql .= " AND d.fk_facture = f.rowid"; if ($agentid > 0) { - if (! empty($conf->global->AGENT_CONTACT_TYPE)) - $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; + if (!empty($conf->global->AGENT_CONTACT_TYPE)) + $sql .= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; else $sql .= " AND sc.fk_user = ".$agentid; } if (!empty($startdate)) - $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; + $sql .= " AND f.datef >= '".$db->idate($startdate)."'"; if (!empty($enddate)) - $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; + $sql .= " AND f.datef <= '".$db->idate($enddate)."'"; $sql .= " AND d.buy_price_ht IS NOT NULL"; if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; //if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; //else $sql.= " GROUP BY u.rowid, u.login, u.lastname, u.firstname"; -$sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; -$sql.=$db->order($sortfield, $sortorder); +$sql .= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; +$sql .= $db->order($sortfield, $sortorder); // TODO: calculate total to display then restore pagination //$sql.= $db->plimit($conf->liste_limit +1, $offset); @@ -181,7 +181,7 @@ $sql.=$db->order($sortfield, $sortorder); print '
'; print img_info('').' '.$langs->trans("MarginPerSaleRepresentativeWarning").'
'; -$param=''; +$param = ''; if (!empty($agentid)) $param .= "&agentid=".urlencode($agentid); if (!empty($startdateday)) $param .= "&startdateday=".urlencode($startdateday); if (!empty($startdatemonth)) $param .= "&startdatemonth=".urlencode($startdatemonth); @@ -201,9 +201,9 @@ if ($result) print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); if ($conf->global->MARGIN_TYPE == "1") - $labelcostprice='BuyingPrice'; + $labelcostprice = 'BuyingPrice'; else // value is 'costprice' or 'pmp' - $labelcostprice='CostPrice'; + $labelcostprice = 'CostPrice'; $i = 0; print ""; @@ -217,9 +217,9 @@ if ($result) print_liste_field_titre("SellingPrice", $_SERVER["PHP_SELF"], "selling_price", "", $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre($labelcostprice, $_SERVER["PHP_SELF"], "buying_price", "", $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre("Margin", $_SERVER["PHP_SELF"], "marge", "", $param, '', $sortfield, $sortorder, 'right '); - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) print_liste_field_titre("MarginRate", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); - if (! empty($conf->global->DISPLAY_MARK_RATES)) + if (!empty($conf->global->DISPLAY_MARK_RATES)) print_liste_field_titre("MarkRate", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right '); print "\n"; @@ -252,8 +252,8 @@ if ($result) if ($objp->socid > 0) { // sql nb sellers $sql_seller = "SELECT COUNT(sc.rowid) as nb"; - $sql_seller .= " FROM " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; - $sql_seller .= " WHERE sc.fk_soc = " . $objp->socid; + $sql_seller .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql_seller .= " WHERE sc.fk_soc = ".$objp->socid; $sql_seller .= " LIMIT 1"; $resql_seller = $db->query($sql_seller); @@ -284,18 +284,18 @@ if ($result) $pv = $group_array['selling_price']; $marge = $group_array['marge']; - $marginRate = ($pa != 0)?(100 * $marge / $pa):''; - $markRate = ($pv != 0)?(100 * $marge / $pv):''; + $marginRate = ($pa != 0) ? (100 * $marge / $pa) : ''; + $markRate = ($pv != 0) ? (100 * $marge / $pv) : ''; print ''; print "\n"; print "\n"; print "\n"; print "\n"; - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) - print "\n"; - if (! empty($conf->global->DISPLAY_MARK_RATES)) - print "\n"; + if (!empty($conf->global->DISPLAY_MARGIN_RATES)) + print "\n"; + if (!empty($conf->global->DISPLAY_MARK_RATES)) + print "\n"; print "\n"; } } diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index ea5b6d45bc1..8b9dd15f038 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -373,12 +373,12 @@ else // Warehouse card $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref='
'; - $morehtmlref.=$langs->trans("LocationSummary").' : '.$object->lieu; - $morehtmlref.='
'; + $morehtmlref = '
'; + $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu; + $morehtmlref .= '
'; $shownav = 1; - if ($user->socid && ! in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; + if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); @@ -390,7 +390,7 @@ else // Parent entrepot $parentwarehouse = new Entrepot($db); - if(!empty($object->fk_parent) && $parentwarehouse->fetch($object->fk_parent) > 0) { + if (!empty($object->fk_parent) && $parentwarehouse->fetch($object->fk_parent) > 0) { print ''; @@ -430,8 +430,8 @@ else // Last movement if (!empty($user->rights->stock->mouvement->lire)) { $sql = "SELECT max(m.datem) as datem"; - $sql .= " FROM " . MAIN_DB_PREFIX . "stock_mouvement as m"; - $sql .= " WHERE m.fk_entrepot = '" . $object->id . "'"; + $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; + $sql .= " WHERE m.fk_entrepot = '".$object->id."'"; $resqlbis = $db->query($sql); if ($resqlbis) { $obj = $db->fetch_object($resqlbis); @@ -439,10 +439,10 @@ else } else { dol_print_error($db); } - print '\n"; - $arrayofuniqueproduct=array(); + $arrayofuniqueproduct = array(); while ($i < min($num, $limit)) { $objp = $db->fetch_object($resql); - $userstatic->id=$objp->fk_user_author; - $userstatic->login=$objp->login; - $userstatic->lastname=$objp->lastname; - $userstatic->firstname=$objp->firstname; - $userstatic->photo=$objp->photo; + $userstatic->id = $objp->fk_user_author; + $userstatic->login = $objp->login; + $userstatic->lastname = $objp->lastname; + $userstatic->firstname = $objp->firstname; + $userstatic->photo = $objp->photo; - $productstatic->id=$objp->rowid; - $productstatic->ref=$objp->product_ref; - $productstatic->label=$objp->produit; - $productstatic->type=$objp->type; - $productstatic->entity=$objp->entity; - $productstatic->status_batch=$objp->tobatch; + $productstatic->id = $objp->rowid; + $productstatic->ref = $objp->product_ref; + $productstatic->label = $objp->produit; + $productstatic->type = $objp->type; + $productstatic->entity = $objp->entity; + $productstatic->status_batch = $objp->tobatch; $productlot->id = $objp->lotid; - $productlot->batch= $objp->batch; - $productlot->eatby= $objp->eatby; - $productlot->sellby= $objp->sellby; + $productlot->batch = $objp->batch; + $productlot->eatby = $objp->eatby; + $productlot->sellby = $objp->sellby; - $warehousestatic->id=$objp->entrepot_id; - $warehousestatic->ref=$objp->warehouse_ref; - $warehousestatic->libelle=$objp->warehouse_ref; // deprecated - $warehousestatic->label=$objp->warehouse_ref; - $warehousestatic->lieu=$objp->lieu; + $warehousestatic->id = $objp->entrepot_id; + $warehousestatic->ref = $objp->warehouse_ref; + $warehousestatic->libelle = $objp->warehouse_ref; // deprecated + $warehousestatic->label = $objp->warehouse_ref; + $warehousestatic->lieu = $objp->lieu; $warehousestatic->fk_parent = $objp->fk_parent; $warehousestatic->statut = $objp->statut; - $arrayofuniqueproduct[$objp->rowid]=$objp->produit; - if(!empty($objp->fk_origin)) { + $arrayofuniqueproduct[$objp->rowid] = $objp->produit; + if (!empty($objp->fk_origin)) { $origin = $movement->get_origin($objp->fk_origin, $objp->origintype); } else { $origin = ''; diff --git a/htdocs/reception/note.php b/htdocs/reception/note.php index 82b5724908e..ee6200bd8a2 100644 --- a/htdocs/reception/note.php +++ b/htdocs/reception/note.php @@ -42,17 +42,17 @@ $langs->load('stocks'); $langs->load('other'); $langs->load('propal'); -$id=(GETPOST('id', 'int')?GETPOST('id', 'int'):GETPOST('facid', 'int')); // For backward compatibility -$ref=GETPOST('ref', 'alpha'); -$action=GETPOST('action', 'alpha'); +$id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'alpha'); // Security check -$socid=''; -if ($user->socid) $socid=$user->socid; -$result=restrictedArea($user, $origin, $origin_id); +$socid = ''; +if ($user->socid) $socid = $user->socid; +$result = restrictedArea($user, $origin, $origin_id); $object = new Reception($db); -if ($id > 0 || ! empty($ref)) +if ($id > 0 || !empty($ref)) { $object->fetch($id, $ref); $object->fetch_thirdparty(); @@ -95,48 +95,48 @@ llxHeader('', 'Reception'); $form = new Form($db); -if ($id > 0 || ! empty($ref)) +if ($id > 0 || !empty($ref)) { - $head=reception_prepare_head($object); + $head = reception_prepare_head($object); dol_fiche_head($head, 'note', $langs->trans("Reception"), -1, 'sending'); // Reception card $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref='
'; + $morehtmlref = '
'; // Ref customer reception - $morehtmlref.=$form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1); - $morehtmlref.=$form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1); + $morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1); // Thirdparty - $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); + $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); // Project - if (! empty($conf->projet->enabled)) { + if (!empty($conf->projet->enabled)) { $langs->load("projects"); - $morehtmlref .= '
' . $langs->trans('Project') . ' '; + $morehtmlref .= '
'.$langs->trans('Project').' '; if (0) { // Do not change on reception if ($action != 'classify') { - $morehtmlref .= '' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; } if ($action == 'classify') { // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref .= '
'; + $morehtmlref .= ''; $morehtmlref .= ''; - $morehtmlref .= ''; + $morehtmlref .= ''; $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref .= ''; + $morehtmlref .= ''; $morehtmlref .= ''; } else { - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); } } else { // We don't have project on reception, so we will use the project or source object instead // TODO Add project on reception $morehtmlref .= ' : '; - if (! empty($objectsrc->fk_project)) { + if (!empty($objectsrc->fk_project)) { $proj = new Project($db); $proj->fetch($objectsrc->fk_project); - $morehtmlref .= ''; + $morehtmlref .= ''; $morehtmlref .= $proj->ref; $morehtmlref .= ''; } else { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 3160a701f64..cb595ce8410 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -673,7 +673,7 @@ class Societe extends CommonObject if (empty($this->status)) $this->status = 0; $this->name = $this->name ?trim($this->name) : trim($this->nom); if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name=strtoupper($this->name); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = strtoupper($this->name); $this->nom = $this->name; // For backward compatibility if (empty($this->client)) $this->client = 0; if (empty($this->fournisseur)) $this->fournisseur = 0; @@ -990,7 +990,7 @@ class Societe extends CommonObject $now = dol_now(); if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name); - if (! empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name=strtoupper($this->name); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = strtoupper($this->name); // Clean parameters $this->id = $id; $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); @@ -1538,7 +1538,7 @@ class Societe extends CommonObject $this->effectif = $obj->effectif_id ? $obj->effectif : ''; $this->forme_juridique_code = $obj->forme_juridique_code; - $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique : ''; + $this->forme_juridique = $obj->forme_juridique_code ? $obj->forme_juridique : ''; $this->fk_prospectlevel = $obj->fk_prospectlevel; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 387d227d6b4..7b89c21972b 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -278,76 +278,76 @@ class User extends CommonObject global $conf, $user; // Clean parameters - $login=trim($login); + $login = trim($login); // Get user $sql = "SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.birth, u.email, u.personal_email, u.job,"; - $sql.= " u.socialnetworks,"; - $sql.= " u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,"; - $sql.= " u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,"; - $sql.= " u.admin, u.login, u.note as note_private, u.note_public,"; - $sql.= " u.pass, u.pass_crypted, u.pass_temp, u.api_key,"; - $sql.= " u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid, u.fk_user_expense_validator, u.fk_user_holiday_validator,"; - $sql.= " u.statut, u.lang, u.entity,"; - $sql.= " u.datec as datec,"; - $sql.= " u.tms as datem,"; - $sql.= " u.datelastlogin as datel,"; - $sql.= " u.datepreviouslogin as datep,"; - $sql.= " u.photo as photo,"; - $sql.= " u.openid as openid,"; - $sql.= " u.accountancy_code,"; - $sql.= " u.thm,"; - $sql.= " u.tjm,"; - $sql.= " u.salary,"; - $sql.= " u.salaryextra,"; - $sql.= " u.weeklyhours,"; - $sql.= " u.color,"; - $sql.= " u.dateemployment, u.dateemploymentend,"; - $sql.= " u.fk_warehouse,"; - $sql.= " u.ref_int, u.ref_ext,"; - $sql.= " u.default_range, u.default_c_exp_tax_cat,"; // Expense report default mode - $sql.= " c.code as country_code, c.label as country,"; - $sql.= " d.code_departement as state_code, d.nom as state"; - $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON u.fk_country = c.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON u.fk_state = d.rowid"; + $sql .= " u.socialnetworks,"; + $sql .= " u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,"; + $sql .= " u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,"; + $sql .= " u.admin, u.login, u.note as note_private, u.note_public,"; + $sql .= " u.pass, u.pass_crypted, u.pass_temp, u.api_key,"; + $sql .= " u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid, u.fk_user_expense_validator, u.fk_user_holiday_validator,"; + $sql .= " u.statut, u.lang, u.entity,"; + $sql .= " u.datec as datec,"; + $sql .= " u.tms as datem,"; + $sql .= " u.datelastlogin as datel,"; + $sql .= " u.datepreviouslogin as datep,"; + $sql .= " u.photo as photo,"; + $sql .= " u.openid as openid,"; + $sql .= " u.accountancy_code,"; + $sql .= " u.thm,"; + $sql .= " u.tjm,"; + $sql .= " u.salary,"; + $sql .= " u.salaryextra,"; + $sql .= " u.weeklyhours,"; + $sql .= " u.color,"; + $sql .= " u.dateemployment, u.dateemploymentend,"; + $sql .= " u.fk_warehouse,"; + $sql .= " u.ref_int, u.ref_ext,"; + $sql .= " u.default_range, u.default_c_exp_tax_cat,"; // Expense report default mode + $sql .= " c.code as country_code, c.label as country,"; + $sql .= " d.code_departement as state_code, d.nom as state"; + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON u.fk_country = c.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON u.fk_state = d.rowid"; if ($entity < 0) { - if ((empty($conf->multicompany->enabled) || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (! empty($user->entity))) + if ((empty($conf->multicompany->enabled) || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) { - $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; + $sql .= " WHERE u.entity IN (0,".$conf->entity.")"; } else { - $sql.= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database + $sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database } } else // The fetch was forced on an entity { if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) - $sql.= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database + $sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database else - $sql.= " WHERE u.entity IN (0, ".(($entity!='' && $entity >= 0)?$entity:$conf->entity).")"; // search in entity provided in parameter + $sql .= " WHERE u.entity IN (0, ".(($entity != '' && $entity >= 0) ? $entity : $conf->entity).")"; // search in entity provided in parameter } if ($sid) // permet une recherche du user par son SID ActiveDirectory ou Samba { - $sql.= " AND (u.ldap_sid = '".$this->db->escape($sid)."' OR u.login = '".$this->db->escape($login)."') LIMIT 1"; + $sql .= " AND (u.ldap_sid = '".$this->db->escape($sid)."' OR u.login = '".$this->db->escape($login)."') LIMIT 1"; } elseif ($login) { - $sql.= " AND u.login = '".$this->db->escape($login)."'"; + $sql .= " AND u.login = '".$this->db->escape($login)."'"; } elseif ($email) { - $sql.= " AND u.email = '".$this->db->escape($email)."'"; + $sql .= " AND u.email = '".$this->db->escape($email)."'"; } else { - $sql.= " AND u.rowid = ".$id; + $sql .= " AND u.rowid = ".$id; } - $sql.= " ORDER BY u.entity ASC"; // Avoid random result when there is 2 login in 2 different entities + $sql .= " ORDER BY u.entity ASC"; // Avoid random result when there is 2 login in 2 different entities $result = $this->db->query($sql); if ($result) @@ -392,14 +392,14 @@ class User extends CommonObject $this->office_fax = $obj->office_fax; $this->user_mobile = $obj->user_mobile; $this->personal_mobile = $obj->personal_mobile; - $this->email = $obj->email; + $this->email = $obj->email; $this->personal_email = $obj->personal_email; $this->socialnetworks = (array) json_decode($obj->socialnetworks, true); - $this->job = $obj->job; - $this->signature = $obj->signature; + $this->job = $obj->job; + $this->signature = $obj->signature; $this->admin = $obj->admin; - $this->note_public = $obj->note_public; - $this->note_private = $obj->note_private; + $this->note_public = $obj->note_public; + $this->note_private = $obj->note_private; $this->note = $obj->note_private; $this->statut = $obj->statut; $this->photo = $obj->photo; @@ -1177,9 +1177,9 @@ class User extends CommonObject // Clean parameters - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname=strtoupper($this->lastname); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); $this->login = trim($this->login); if (!isset($this->entity)) $this->entity = $conf->entity; // If not defined, we use default value @@ -1256,7 +1256,7 @@ class User extends CommonObject $langs->load("stocks"); $entrepot = new Entrepot($this->db); $entrepot->label = $langs->trans("PersonalStock", $this->getFullName($langs)); - $entrepot->libelle = $entrepot->label; // For backward compatibility + $entrepot->libelle = $entrepot->label; // For backward compatibility $entrepot->description = $langs->trans("ThisWarehouseIsPersonalStock", $this->getFullName($langs)); $entrepot->statut = 1; $entrepot->country_id = $mysoc->country_id; @@ -1334,28 +1334,28 @@ class User extends CommonObject $this->country_id = $contact->country_id; $this->employee = 0; - if (empty($login)) $login=strtolower(substr($contact->firstname, 0, 4)) . strtolower(substr($contact->lastname, 0, 4)); + if (empty($login)) $login = strtolower(substr($contact->firstname, 0, 4)).strtolower(substr($contact->lastname, 0, 4)); $this->login = $login; $this->db->begin(); // Create user and set $this->id. Trigger is disabled because executed later. - $result=$this->create($user, 1); + $result = $this->create($user, 1); if ($result > 0) { $sql = "UPDATE ".MAIN_DB_PREFIX."user"; - $sql.= " SET fk_socpeople=".$contact->id; - if ($contact->socid) $sql.=", fk_soc=".$contact->socid; - $sql.= " WHERE rowid=".$this->id; - $resql=$this->db->query($sql); + $sql .= " SET fk_socpeople=".$contact->id; + if ($contact->socid) $sql .= ", fk_soc=".$contact->socid; + $sql .= " WHERE rowid=".$this->id; + $resql = $this->db->query($sql); dol_syslog(get_class($this)."::create_from_contact", LOG_DEBUG); if ($resql) { - $this->context['createfromcontact']='createfromcontact'; + $this->context['createfromcontact'] = 'createfromcontact'; // Call trigger - $result=$this->call_trigger('USER_CREATE', $user); + $result = $this->call_trigger('USER_CREATE', $user); if ($result < 0) { $error++; $this->db->rollback(); return -1; } // End call triggers @@ -1520,9 +1520,9 @@ class User extends CommonObject // Clean parameters - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname=strtoupper($this->lastname); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); $this->lastname = trim($this->lastname); $this->firstname = trim($this->firstname); @@ -1544,23 +1544,23 @@ class User extends CommonObject $this->email = trim($this->email); $this->personal_email = trim($this->personal_email); - $this->job = trim($this->job); + $this->job = trim($this->job); $this->signature = trim($this->signature); $this->note_public = trim($this->note_public); $this->note_private = trim($this->note_private); - $this->openid = trim(empty($this->openid)?'':$this->openid); // Avoid warning - $this->admin = $this->admin?$this->admin:0; - $this->address = empty($this->address)?'':$this->address; - $this->zip = empty($this->zip)?'':$this->zip; - $this->town = empty($this->town)?'':$this->town; + $this->openid = trim(empty($this->openid) ? '' : $this->openid); // Avoid warning + $this->admin = $this->admin ? $this->admin : 0; + $this->address = empty($this->address) ? '' : $this->address; + $this->zip = empty($this->zip) ? '' : $this->zip; + $this->town = empty($this->town) ? '' : $this->town; $this->accountancy_code = trim($this->accountancy_code); - $this->color = empty($this->color)?'':$this->color; - $this->dateemployment = empty($this->dateemployment)?'':$this->dateemployment; - $this->dateemploymentend = empty($this->dateemploymentend)?'':$this->dateemploymentend; - $this->fk_warehouse = trim(empty($this->fk_warehouse)?'':$this->fk_warehouse); + $this->color = empty($this->color) ? '' : $this->color; + $this->dateemployment = empty($this->dateemployment) ? '' : $this->dateemployment; + $this->dateemploymentend = empty($this->dateemploymentend) ? '' : $this->dateemploymentend; + $this->fk_warehouse = trim(empty($this->fk_warehouse) ? '' : $this->fk_warehouse); // Check parameters - if (! empty($conf->global->USER_MAIL_REQUIRED) && ! isValidEMail($this->email)) + if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) { $langs->load("errors"); $this->error = $langs->trans("ErrorBadEMail", $this->email); @@ -1577,56 +1577,56 @@ class User extends CommonObject // Update datas $sql = "UPDATE ".MAIN_DB_PREFIX."user SET"; - $sql.= " lastname = '".$this->db->escape($this->lastname)."'"; - $sql.= ", firstname = '".$this->db->escape($this->firstname)."'"; - $sql.= ", employee = ".(int) $this->employee; - $sql.= ", login = '".$this->db->escape($this->login)."'"; - $sql.= ", api_key = ".($this->api_key ? "'".$this->db->escape($this->api_key)."'" : "null"); - $sql.= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman' - $sql.= ", birth=".(strval($this->birth)!='' ? "'".$this->db->idate($this->birth)."'" : 'null'); - if (! empty($user->admin)) $sql.= ", admin = ".(int) $this->admin; // admin flag can be set/unset only by an admin user - $sql.= ", address = '".$this->db->escape($this->address)."'"; - $sql.= ", zip = '".$this->db->escape($this->zip)."'"; - $sql.= ", town = '".$this->db->escape($this->town)."'"; - $sql.= ", fk_state = ".((! empty($this->state_id) && $this->state_id > 0)?"'".$this->db->escape($this->state_id)."'":"null"); - $sql.= ", fk_country = ".((! empty($this->country_id) && $this->country_id > 0)?"'".$this->db->escape($this->country_id)."'":"null"); - $sql.= ", office_phone = '".$this->db->escape($this->office_phone)."'"; - $sql.= ", office_fax = '".$this->db->escape($this->office_fax)."'"; - $sql.= ", user_mobile = '".$this->db->escape($this->user_mobile)."'"; - $sql.= ", personal_mobile = '".$this->db->escape($this->personal_mobile)."'"; - $sql.= ", email = '".$this->db->escape($this->email)."'"; - $sql.= ", personal_email = '".$this->db->escape($this->personal_email)."'"; - $sql.= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; - $sql.= ", job = '".$this->db->escape($this->job)."'"; - $sql.= ", signature = '".$this->db->escape($this->signature)."'"; - $sql.= ", accountancy_code = '".$this->db->escape($this->accountancy_code)."'"; - $sql.= ", color = '".$this->db->escape($this->color)."'"; - $sql.= ", dateemployment=".(strval($this->dateemployment)!='' ? "'".$this->db->idate($this->dateemployment)."'" : 'null'); - $sql.= ", dateemploymentend=".(strval($this->dateemploymentend)!='' ? "'".$this->db->idate($this->dateemploymentend)."'" : 'null'); - $sql.= ", note = '".$this->db->escape($this->note_private)."'"; - $sql.= ", note_public = '".$this->db->escape($this->note_public)."'"; - $sql.= ", photo = ".($this->photo?"'".$this->db->escape($this->photo)."'":"null"); - $sql.= ", openid = ".($this->openid?"'".$this->db->escape($this->openid)."'":"null"); - $sql.= ", fk_user = ".($this->fk_user > 0?"'".$this->db->escape($this->fk_user)."'":"null"); - $sql.= ", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0?"'".$this->db->escape($this->fk_user_expense_validator)."'":"null"); - $sql.= ", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0?"'".$this->db->escape($this->fk_user_holiday_validator)."'":"null"); - if (isset($this->thm) || $this->thm != '') $sql.= ", thm= ".($this->thm != ''?"'".$this->db->escape($this->thm)."'":"null"); - if (isset($this->tjm) || $this->tjm != '') $sql.= ", tjm= ".($this->tjm != ''?"'".$this->db->escape($this->tjm)."'":"null"); - if (isset($this->salary) || $this->salary != '') $sql.= ", salary= ".($this->salary != ''?"'".$this->db->escape($this->salary)."'":"null"); - if (isset($this->salaryextra) || $this->salaryextra != '') $sql.= ", salaryextra= ".($this->salaryextra != ''?"'".$this->db->escape($this->salaryextra)."'":"null"); - $sql.= ", weeklyhours= ".($this->weeklyhours != ''?"'".$this->db->escape($this->weeklyhours)."'":"null"); - $sql.= ", entity = '".$this->db->escape($this->entity)."'"; - $sql.= ", default_range = ".($this->default_range > 0 ? $this->default_range : 'null'); - $sql.= ", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat : 'null'); - $sql.= ", fk_warehouse = ".($this->fk_warehouse?"'".$this->db->escape($this->fk_warehouse)."'":"null"); + $sql .= " lastname = '".$this->db->escape($this->lastname)."'"; + $sql .= ", firstname = '".$this->db->escape($this->firstname)."'"; + $sql .= ", employee = ".(int) $this->employee; + $sql .= ", login = '".$this->db->escape($this->login)."'"; + $sql .= ", api_key = ".($this->api_key ? "'".$this->db->escape($this->api_key)."'" : "null"); + $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman' + $sql .= ", birth=".(strval($this->birth) != '' ? "'".$this->db->idate($this->birth)."'" : 'null'); + if (!empty($user->admin)) $sql .= ", admin = ".(int) $this->admin; // admin flag can be set/unset only by an admin user + $sql .= ", address = '".$this->db->escape($this->address)."'"; + $sql .= ", zip = '".$this->db->escape($this->zip)."'"; + $sql .= ", town = '".$this->db->escape($this->town)."'"; + $sql .= ", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ? "'".$this->db->escape($this->state_id)."'" : "null"); + $sql .= ", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ? "'".$this->db->escape($this->country_id)."'" : "null"); + $sql .= ", office_phone = '".$this->db->escape($this->office_phone)."'"; + $sql .= ", office_fax = '".$this->db->escape($this->office_fax)."'"; + $sql .= ", user_mobile = '".$this->db->escape($this->user_mobile)."'"; + $sql .= ", personal_mobile = '".$this->db->escape($this->personal_mobile)."'"; + $sql .= ", email = '".$this->db->escape($this->email)."'"; + $sql .= ", personal_email = '".$this->db->escape($this->personal_email)."'"; + $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; + $sql .= ", job = '".$this->db->escape($this->job)."'"; + $sql .= ", signature = '".$this->db->escape($this->signature)."'"; + $sql .= ", accountancy_code = '".$this->db->escape($this->accountancy_code)."'"; + $sql .= ", color = '".$this->db->escape($this->color)."'"; + $sql .= ", dateemployment=".(strval($this->dateemployment) != '' ? "'".$this->db->idate($this->dateemployment)."'" : 'null'); + $sql .= ", dateemploymentend=".(strval($this->dateemploymentend) != '' ? "'".$this->db->idate($this->dateemploymentend)."'" : 'null'); + $sql .= ", note = '".$this->db->escape($this->note_private)."'"; + $sql .= ", note_public = '".$this->db->escape($this->note_public)."'"; + $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null"); + $sql .= ", openid = ".($this->openid ? "'".$this->db->escape($this->openid)."'" : "null"); + $sql .= ", fk_user = ".($this->fk_user > 0 ? "'".$this->db->escape($this->fk_user)."'" : "null"); + $sql .= ", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? "'".$this->db->escape($this->fk_user_expense_validator)."'" : "null"); + $sql .= ", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? "'".$this->db->escape($this->fk_user_holiday_validator)."'" : "null"); + if (isset($this->thm) || $this->thm != '') $sql .= ", thm= ".($this->thm != '' ? "'".$this->db->escape($this->thm)."'" : "null"); + if (isset($this->tjm) || $this->tjm != '') $sql .= ", tjm= ".($this->tjm != '' ? "'".$this->db->escape($this->tjm)."'" : "null"); + if (isset($this->salary) || $this->salary != '') $sql .= ", salary= ".($this->salary != '' ? "'".$this->db->escape($this->salary)."'" : "null"); + if (isset($this->salaryextra) || $this->salaryextra != '') $sql .= ", salaryextra= ".($this->salaryextra != '' ? "'".$this->db->escape($this->salaryextra)."'" : "null"); + $sql .= ", weeklyhours= ".($this->weeklyhours != '' ? "'".$this->db->escape($this->weeklyhours)."'" : "null"); + $sql .= ", entity = '".$this->db->escape($this->entity)."'"; + $sql .= ", default_range = ".($this->default_range > 0 ? $this->default_range : 'null'); + $sql .= ", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat : 'null'); + $sql .= ", fk_warehouse = ".($this->fk_warehouse ? "'".$this->db->escape($this->fk_warehouse)."'" : "null"); - $sql.= " WHERE rowid = ".$this->id; + $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $nbrowsaffected+=$this->db->affected_rows($resql); + $nbrowsaffected += $this->db->affected_rows($resql); // Update password if (!empty($this->pass)) @@ -1663,55 +1663,55 @@ class User extends CommonObject // This user is linked with a member, so we also update member information // if this is an update. - $adh=new Adherent($this->db); - $result=$adh->fetch($this->fk_member); + $adh = new Adherent($this->db); + $result = $adh->fetch($this->fk_member); if ($result > 0) { - $adh->firstname=$this->firstname; - $adh->lastname=$this->lastname; - $adh->login=$this->login; - $adh->gender=$this->gender; - $adh->birth=$this->birth; + $adh->firstname = $this->firstname; + $adh->lastname = $this->lastname; + $adh->login = $this->login; + $adh->gender = $this->gender; + $adh->birth = $this->birth; - $adh->pass=$this->pass; + $adh->pass = $this->pass; - $adh->societe=(empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe); + $adh->societe = (empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe); - $adh->address=$this->address; - $adh->town=$this->town; - $adh->zip=$this->zip; - $adh->state_id=$this->state_id; - $adh->country_id=$this->country_id; + $adh->address = $this->address; + $adh->town = $this->town; + $adh->zip = $this->zip; + $adh->state_id = $this->state_id; + $adh->country_id = $this->country_id; - $adh->email=$this->email; + $adh->email = $this->email; - $adh->socialnetworks=$this->socialnetworks; + $adh->socialnetworks = $this->socialnetworks; - $adh->phone=$this->office_phone; - $adh->phone_mobile=$this->user_mobile; + $adh->phone = $this->office_phone; + $adh->phone_mobile = $this->user_mobile; - $adh->user_id=$this->id; - $adh->user_login=$this->login; + $adh->user_id = $this->id; + $adh->user_login = $this->login; - $result=$adh->update($user, 0, 1, 0); + $result = $adh->update($user, 0, 1, 0); if ($result < 0) { - $this->error=$adh->error; - $this->errors=$adh->errors; + $this->error = $adh->error; + $this->errors = $adh->errors; dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR); $error++; } } elseif ($result < 0) { - $this->error=$adh->error; - $this->errors=$adh->errors; + $this->error = $adh->error; + $this->errors = $adh->errors; $error++; } } - if ($this->contact_id > 0 && ! $nosynccontact) + if ($this->contact_id > 0 && !$nosynccontact) { dol_syslog(get_class($this)."::update user is linked with a contact. We try to update contact too.", LOG_DEBUG); @@ -1719,77 +1719,77 @@ class User extends CommonObject // This user is linked with a contact, so we also update contact information // if this is an update. - $tmpobj=new Contact($this->db); - $result=$tmpobj->fetch($this->contact_id); + $tmpobj = new Contact($this->db); + $result = $tmpobj->fetch($this->contact_id); if ($result >= 0) { - $tmpobj->firstname=$this->firstname; - $tmpobj->lastname=$this->lastname; - $tmpobj->login=$this->login; - $tmpobj->gender=$this->gender; - $tmpobj->birth=$this->birth; + $tmpobj->firstname = $this->firstname; + $tmpobj->lastname = $this->lastname; + $tmpobj->login = $this->login; + $tmpobj->gender = $this->gender; + $tmpobj->birth = $this->birth; //$tmpobj->pass=$this->pass; //$tmpobj->societe=(empty($tmpobj->societe) && $this->societe_id ? $this->societe_id : $tmpobj->societe); - $tmpobj->email=$this->email; + $tmpobj->email = $this->email; - $tmpobj->socialnetworks=$this->socialnetworks; + $tmpobj->socialnetworks = $this->socialnetworks; - $tmpobj->phone_pro=$this->office_phone; - $tmpobj->phone_mobile=$this->user_mobile; - $tmpobj->fax=$this->office_fax; + $tmpobj->phone_pro = $this->office_phone; + $tmpobj->phone_mobile = $this->user_mobile; + $tmpobj->fax = $this->office_fax; - $tmpobj->address=$this->address; - $tmpobj->town=$this->town; - $tmpobj->zip=$this->zip; - $tmpobj->state_id=$this->state_id; - $tmpobj->country_id=$this->country_id; + $tmpobj->address = $this->address; + $tmpobj->town = $this->town; + $tmpobj->zip = $this->zip; + $tmpobj->state_id = $this->state_id; + $tmpobj->country_id = $this->country_id; - $tmpobj->user_id=$this->id; - $tmpobj->user_login=$this->login; + $tmpobj->user_id = $this->id; + $tmpobj->user_login = $this->login; - $result=$tmpobj->update($tmpobj->id, $user, 0, 'update', 1); + $result = $tmpobj->update($tmpobj->id, $user, 0, 'update', 1); if ($result < 0) { - $this->error=$tmpobj->error; - $this->errors=$tmpobj->errors; + $this->error = $tmpobj->error; + $this->errors = $tmpobj->errors; dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR); $error++; } } else { - $this->error=$tmpobj->error; - $this->errors=$tmpobj->errors; + $this->error = $tmpobj->error; + $this->errors = $tmpobj->errors; $error++; } } } - $action='update'; + $action = 'update'; // Actions on extra fields - if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) + if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { - $result=$this->insertExtraFields(); + $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } - if (! $error && ! $notrigger) + if (!$error && !$notrigger) { // Call trigger - $result=$this->call_trigger('USER_MODIFY', $user); + $result = $this->call_trigger('USER_MODIFY', $user); if ($result < 0) { $error++; } // End call triggers } - if (! $error) + if (!$error) { $this->db->commit(); return $nbrowsaffected; @@ -2332,60 +2332,60 @@ class User extends CommonObject global $dolibarr_main_authentication, $dolibarr_main_demo; global $menumanager; - if(!$user->rights->user->user->lire && $user->id !=$this->id) $option='nolink'; + if (!$user->rights->user->user->lire && $user->id != $this->id) $option = 'nolink'; - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg=0; + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg = 0; - $result=''; $label=''; + $result = ''; $label = ''; - if (! empty($this->photo)) + if (!empty($this->photo)) { - $label.= '
'; - $label.= Form::showphoto('userphoto', $this, 0, 60, 0, 'photowithmargin photologintooltip', 'small', 0, 1); // Force height to 60 so we total height of tooltip can be calculated and collision can be managed - $label.= '
'; + $label .= '
'; + $label .= Form::showphoto('userphoto', $this, 0, 60, 0, 'photowithmargin photologintooltip', 'small', 0, 1); // Force height to 60 so we total height of tooltip can be calculated and collision can be managed + $label .= '
'; } // Info Login - $label.= '
'; - $label.= '' . $langs->trans("User") . '
'; - $label.= '' . $langs->trans('Name') . ': ' . $this->getFullName($langs, ''); - if (! empty($this->login)) $label.= '
' . $langs->trans('Login') . ': ' . $this->login; - if (! empty($this->job)) $label.= '
' . $langs->trans("Job").': '.$this->job; - $label.= '
' . $langs->trans("Email").': '.$this->email; - if (! empty($this->phone)) $label.= '
' . $langs->trans("Phone").': '.$this->phone; - if (! empty($this->admin)) - $label.= '
' . $langs->trans("Administrator").': '.yn($this->admin); - if (! empty($this->socid) ) // Add thirdparty for external users + $label .= '
'; + $label .= ''.$langs->trans("User").'
'; + $label .= ''.$langs->trans('Name').': '.$this->getFullName($langs, ''); + if (!empty($this->login)) $label .= '
'.$langs->trans('Login').': '.$this->login; + if (!empty($this->job)) $label .= '
'.$langs->trans("Job").': '.$this->job; + $label .= '
'.$langs->trans("Email").': '.$this->email; + if (!empty($this->phone)) $label .= '
'.$langs->trans("Phone").': '.$this->phone; + if (!empty($this->admin)) + $label .= '
'.$langs->trans("Administrator").': '.yn($this->admin); + if (!empty($this->socid)) // Add thirdparty for external users { $thirdpartystatic = new Societe($db); $thirdpartystatic->fetch($this->socid); - if (empty($hidethirdpartylogo)) $companylink = ' '.$thirdpartystatic->getNomUrl(2, (($option == 'nolink')?'nolink':'')); // picto only of company - $company=' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')'; + if (empty($hidethirdpartylogo)) $companylink = ' '.$thirdpartystatic->getNomUrl(2, (($option == 'nolink') ? 'nolink' : '')); // picto only of company + $company = ' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')'; } - $type=($this->socid?$langs->trans("External").$company:$langs->trans("Internal")); - $label.= '
' . $langs->trans("Type") . ': ' . $type; - $label.= '
' . $langs->trans("Status").': '.$this->getLibStatut(0); - $label.='
'; + $type = ($this->socid ? $langs->trans("External").$company : $langs->trans("Internal")); + $label .= '
'.$langs->trans("Type").': '.$type; + $label .= '
'.$langs->trans("Status").': '.$this->getLibStatut(0); + $label .= '
'; if ($infologin > 0) { - $label.= '
'; - $label.= '
'.$langs->trans("Session").''; - $label.= '
'.$langs->trans("IPAddress").': '.$_SERVER["REMOTE_ADDR"]; - if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $label.= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$this->entity.')'; - $label.= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo)?'':' (demo)'); - $label.= '
'.$langs->trans("ConnectedSince").': '.dol_print_date($this->datelastlogin, "dayhour", 'tzuser'); - $label.= '
'.$langs->trans("PreviousConnexion").': '.dol_print_date($this->datepreviouslogin, "dayhour", 'tzuser'); - $label.= '
'.$langs->trans("CurrentTheme").': '.$conf->theme; - $label.= '
'.$langs->trans("CurrentMenuManager").': '.$menumanager->name; - $s=picto_from_langcode($langs->getDefaultLang()); - $label.= '
'.$langs->trans("CurrentUserLanguage").': '.($s?$s.' ':'').$langs->getDefaultLang(); - $label.= '
'.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version?' '.$conf->browser->version:'').' ('.$_SERVER['HTTP_USER_AGENT'].')'; - $label.= '
'.$langs->trans("Layout").': '.$conf->browser->layout; - $label.= '
'.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']; - if ($conf->browser->layout == 'phone') $label.= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); - if (! empty($_SESSION["disablemodules"])) $label.= '
'.$langs->trans("DisabledModules").':
'.join(', ', explode(',', $_SESSION["disablemodules"])); + $label .= '
'; + $label .= '
'.$langs->trans("Session").''; + $label .= '
'.$langs->trans("IPAddress").': '.$_SERVER["REMOTE_ADDR"]; + if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $label .= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$this->entity.')'; + $label .= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)'); + $label .= '
'.$langs->trans("ConnectedSince").': '.dol_print_date($this->datelastlogin, "dayhour", 'tzuser'); + $label .= '
'.$langs->trans("PreviousConnexion").': '.dol_print_date($this->datepreviouslogin, "dayhour", 'tzuser'); + $label .= '
'.$langs->trans("CurrentTheme").': '.$conf->theme; + $label .= '
'.$langs->trans("CurrentMenuManager").': '.$menumanager->name; + $s = picto_from_langcode($langs->getDefaultLang()); + $label .= '
'.$langs->trans("CurrentUserLanguage").': '.($s ? $s.' ' : '').$langs->getDefaultLang(); + $label .= '
'.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version ? ' '.$conf->browser->version : '').' ('.$_SERVER['HTTP_USER_AGENT'].')'; + $label .= '
'.$langs->trans("Layout").': '.$conf->browser->layout; + $label .= '
'.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']; + if ($conf->browser->layout == 'phone') $label .= '
'.$langs->trans("Phone").': '.$langs->trans("Yes"); + if (!empty($_SESSION["disablemodules"])) $label .= '
'.$langs->trans("DisabledModules").':
'.join(', ', explode(',', $_SESSION["disablemodules"])); } - if ($infologin < 0) $label=''; + if ($infologin < 0) $label = ''; $url = DOL_URL_ROOT.'/user/card.php?id='.$this->id; if ($option == 'leave') $url = DOL_URL_ROOT.'/holiday/list.php?id='.$this->id; @@ -2703,43 +2703,43 @@ class User extends CommonObject */ public function initAsSpecimen() { - global $user,$langs; + global $user, $langs; - $now=dol_now(); + $now = dol_now(); // Initialise parametres - $this->id=0; + $this->id = 0; $this->ref = 'SPECIMEN'; - $this->specimen=1; + $this->specimen = 1; - $this->lastname='DOLIBARR'; - $this->firstname='SPECIMEN'; - $this->gender='man'; - $this->note_public='This is a note public'; - $this->note_private='This is a note private'; - $this->email='email@specimen.com'; - $this->personal_email='personalemail@specimen.com'; + $this->lastname = 'DOLIBARR'; + $this->firstname = 'SPECIMEN'; + $this->gender = 'man'; + $this->note_public = 'This is a note public'; + $this->note_private = 'This is a note private'; + $this->email = 'email@specimen.com'; + $this->personal_email = 'personalemail@specimen.com'; $this->socialnetworks = array( 'skype' => 'skypepseudo', 'twitter' => 'twitterpseudo', 'facebook' => 'facebookpseudo', 'linkedin' => 'linkedinpseudo', ); - $this->office_phone='0999999999'; - $this->office_fax='0999999998'; - $this->user_mobile='0999999997'; - $this->personal_mobile='0999999996'; - $this->admin=0; - $this->login='dolibspec'; - $this->pass='dolibspec'; + $this->office_phone = '0999999999'; + $this->office_fax = '0999999998'; + $this->user_mobile = '0999999997'; + $this->personal_mobile = '0999999996'; + $this->admin = 0; + $this->login = 'dolibspec'; + $this->pass = 'dolibspec'; //$this->pass_indatabase='dolibspec'; Set after a fetch //$this->pass_indatabase_crypted='e80ca5a88c892b0aaaf7e154853bccab'; Set after a fetch - $this->datec=$now; - $this->datem=$now; + $this->datec = $now; + $this->datem = $now; - $this->datelastlogin=$now; - $this->datepreviouslogin=$now; - $this->statut=1; + $this->datelastlogin = $now; + $this->datepreviouslogin = $now; + $this->statut = 1; //$this->societe_id = 1; For external users //$this->contact_id = 1; For external users diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index 04c9e70c447..679c1777297 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -288,23 +288,23 @@ if ($action === 'confirm_deletecombination') { $form = new Form($db); -if (! empty($id) || ! empty($ref)) +if (!empty($id) || !empty($ref)) { llxHeader("", "", $langs->trans("CardProduct".$object->type)); - $showbarcode=empty($conf->barcode->enabled)?0:1; - if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0; + $showbarcode = empty($conf->barcode->enabled) ? 0 : 1; + if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode = 0; - $head=product_prepare_head($object); - $titre=$langs->trans("CardProduct".$object->type); - $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); + $head = product_prepare_head($object); + $titre = $langs->trans("CardProduct".$object->type); + $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product'); dol_fiche_head($head, 'combinations', $titre, -1, $picto); $linkback = ''.$langs->trans("BackToList").''; - $object->next_prev_filter=" fk_product_type = ".$object->type; + $object->next_prev_filter = " fk_product_type = ".$object->type; - dol_banner_tab($object, 'ref', $linkback, ($user->socid?0:1), 'ref', '', '', '', 0, '', '', 1); + dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', '', '', '', 0, '', '', 1); print '
'; @@ -494,9 +494,9 @@ if (! empty($id) || ! empty($ref)) print '
'."\n"; print ''; print ''."\n"; - print ''."\n"; + print ''."\n"; if ($valueid > 0) { - print ''."\n"; + print ''."\n"; } dol_fiche_head(); @@ -518,7 +518,7 @@ if (! empty($id) || ! empty($ref)) print ''; } - $htmltext=$langs->trans("GoOnMenuToCreateVairants", $langs->transnoentities("Product"), $langs->transnoentities("VariantAttributes")); + $htmltext = $langs->trans("GoOnMenuToCreateVairants", $langs->transnoentities("Product"), $langs->transnoentities("VariantAttributes")); print $form->textwithpicto('', $htmltext); /*print '     id).'">'; print $langs->trans("Create"); @@ -780,9 +780,9 @@ if (! empty($id) || ! empty($ref)) print '
'; print '';
".$group_array['htmlname']."".price(price2num($pv, 'MT'))."".price(price2num($pa, 'MT'))."".price(price2num($marge, 'MT'))."".(($marginRate === '')?'n/a':price(price2num($marginRate, 'MT'))."%")."".(($markRate === '')?'n/a':price(price2num($markRate, 'MT'))."%")."".(($marginRate === '') ? 'n/a' : price(price2num($marginRate, 'MT'))."%")."".(($markRate === '') ? 'n/a' : price(price2num($markRate, 'MT'))."%")."
'.$langs->trans("ParentWarehouse").''; print $parentwarehouse->getNomUrl(3); print '
' . $langs->trans("LastMovement") . ''; + print '
'.$langs->trans("LastMovement").''; if ($lastmovementdate) { - print dol_print_date($lastmovementdate, 'dayhour') . ' '; - print '(' . $langs->trans("FullList") . ')'; + print dol_print_date($lastmovementdate, 'dayhour').' '; + print '('.$langs->trans("FullList").')'; } else { print $langs->trans("None"); } diff --git a/htdocs/product/stock/info.php b/htdocs/product/stock/info.php index 463e39a49d1..cb27f37afb6 100644 --- a/htdocs/product/stock/info.php +++ b/htdocs/product/stock/info.php @@ -34,14 +34,14 @@ $ref = GETPOST('ref', 'alpha'); // Security check //$result=restrictedArea($user,'stock', $id, 'entrepot&stock'); -$result=restrictedArea($user, 'stock'); +$result = restrictedArea($user, 'stock'); /* * View */ -$help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; +$help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; llxHeader("", $langs->trans("Stocks"), $help_url); $object = new Entrepot($db); @@ -55,12 +55,12 @@ dol_fiche_head($head, 'info', $langs->trans("Warehouse"), -1, 'stock'); $linkback = ''.$langs->trans("BackToList").''; -$morehtmlref='
'; -$morehtmlref.=$langs->trans("LocationSummary").' : '.$object->lieu; -$morehtmlref.='
'; +$morehtmlref = '
'; +$morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu; +$morehtmlref .= '
'; $shownav = 1; -if ($user->socid && ! in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; +if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php index e6742cdc78b..ce44f28effe 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -195,14 +195,14 @@ if ($action == "correct_stock") if ($product->hasbatch()) { - $batch=GETPOST('batch_number'); + $batch = GETPOST('batch_number'); //$eatby=GETPOST('eatby'); //$sellby=GETPOST('sellby'); - $eatby=dol_mktime(0, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear')); - $sellby=dol_mktime(0, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear')); + $eatby = dol_mktime(0, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear')); + $sellby = dol_mktime(0, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear')); - $result=$product->correct_stock_batch( + $result = $product->correct_stock_batch( $user, $id, GETPOST("nbpiece", 'int'), @@ -213,11 +213,11 @@ if ($action == "correct_stock") GETPOST('inventorycode'), $origin_element, $origin_id - ); // We do not change value of stock for a correction + ); // We do not change value of stock for a correction } else { - $result=$product->correct_stock( + $result = $product->correct_stock( $user, $id, GETPOST("nbpiece", 'int'), @@ -414,63 +414,63 @@ if ($action == "transfert_stock" && !$cancel) * View */ -$productlot=new ProductLot($db); -$productstatic=new Product($db); -$warehousestatic=new Entrepot($db); -$movement=new MouvementStock($db); -$userstatic=new User($db); -$form=new Form($db); -$formother=new FormOther($db); -$formproduct=new FormProduct($db); -if (!empty($conf->projet->enabled)) $formproject=new FormProjets($db); +$productlot = new ProductLot($db); +$productstatic = new Product($db); +$warehousestatic = new Entrepot($db); +$movement = new MouvementStock($db); +$userstatic = new User($db); +$form = new Form($db); +$formother = new FormOther($db); +$formproduct = new FormProduct($db); +if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.entity,"; -$sql.= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu, e.fk_parent, e.statut,"; -$sql.= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,"; -$sql.= " m.batch, m.price,"; -$sql.= " m.type_mouvement,"; -$sql.= " m.fk_projet as fk_project,"; -$sql.= " pl.rowid as lotid, pl.eatby, pl.sellby,"; -$sql.= " u.login, u.photo, u.lastname, u.firstname"; +$sql .= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu, e.fk_parent, e.statut,"; +$sql .= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,"; +$sql .= " m.batch, m.price,"; +$sql .= " m.type_mouvement,"; +$sql .= " m.fk_projet as fk_project,"; +$sql .= " pl.rowid as lotid, pl.eatby, pl.sellby,"; +$sql .= " u.login, u.photo, u.lastname, u.firstname"; // Add fields from extrafields -if (! empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); +if (!empty($extrafields->attributes[$object->table_element]['label'])) { + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); } // Add fields from hooks -$parameters=array(); -$reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook -$sql.=$hookmanager->resPrint; -$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e,"; -$sql.= " ".MAIN_DB_PREFIX."product as p,"; -$sql.= " ".MAIN_DB_PREFIX."stock_mouvement as m"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid"; -$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product"; -$sql.= " WHERE m.fk_product = p.rowid"; +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; +$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,"; +$sql .= " ".MAIN_DB_PREFIX."product as p,"; +$sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product"; +$sql .= " WHERE m.fk_product = p.rowid"; if ($msid > 0) $sql .= " AND m.rowid = ".$msid; -$sql.= " AND m.fk_entrepot = e.rowid"; -$sql.= " AND e.entity IN (".getEntity('stock').")"; -if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND p.fk_product_type = 0"; -if ($id > 0) $sql.= " AND e.rowid ='".$id."'"; -$sql.= dolSqlDateFilter('m.datem', 0, $month, $year); -if ($idproduct > 0) $sql.= " AND p.rowid = '".$idproduct."'"; -if (! empty($search_ref)) $sql.= natural_search('m.rowid', $search_ref, 1); -if (! empty($search_movement)) $sql.= natural_search('m.label', $search_movement); -if (! empty($search_inventorycode)) $sql.= natural_search('m.inventorycode', $search_inventorycode); -if (! empty($search_product_ref)) $sql.= natural_search('p.ref', $search_product_ref); -if (! empty($search_product)) $sql.= natural_search('p.label', $search_product); -if ($search_warehouse != '' && $search_warehouse != '-1') $sql.= natural_search('e.rowid', $search_warehouse, 2); -if (! empty($search_user)) $sql.= natural_search('u.login', $search_user); -if (! empty($search_batch)) $sql.= natural_search('m.batch', $search_batch); -if ($search_qty != '') $sql.= natural_search('m.value', $search_qty, 1); -if ($search_type_mouvement != '' && $search_type_mouvement != '-1') $sql.= natural_search('m.type_mouvement', $search_type_mouvement, 2); +$sql .= " AND m.fk_entrepot = e.rowid"; +$sql .= " AND e.entity IN (".getEntity('stock').")"; +if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= " AND p.fk_product_type = 0"; +if ($id > 0) $sql .= " AND e.rowid ='".$id."'"; +$sql .= dolSqlDateFilter('m.datem', 0, $month, $year); +if ($idproduct > 0) $sql .= " AND p.rowid = '".$idproduct."'"; +if (!empty($search_ref)) $sql .= natural_search('m.rowid', $search_ref, 1); +if (!empty($search_movement)) $sql .= natural_search('m.label', $search_movement); +if (!empty($search_inventorycode)) $sql .= natural_search('m.inventorycode', $search_inventorycode); +if (!empty($search_product_ref)) $sql .= natural_search('p.ref', $search_product_ref); +if (!empty($search_product)) $sql .= natural_search('p.label', $search_product); +if ($search_warehouse != '' && $search_warehouse != '-1') $sql .= natural_search('e.rowid', $search_warehouse, 2); +if (!empty($search_user)) $sql .= natural_search('u.login', $search_user); +if (!empty($search_batch)) $sql .= natural_search('m.batch', $search_batch); +if ($search_qty != '') $sql .= natural_search('m.value', $search_qty, 1); +if ($search_type_mouvement != '' && $search_type_mouvement != '-1') $sql .= natural_search('m.type_mouvement', $search_type_mouvement, 2); // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks -$parameters=array(); -$reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook -$sql.=$hookmanager->resPrint; -$sql.= $db->order($sortfield, $sortorder); +$parameters = array(); +$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook +$sql .= $hookmanager->resPrint; +$sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) @@ -544,12 +544,12 @@ if ($resql) $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref='
'; - $morehtmlref.=$langs->trans("LocationSummary").' : '.$object->lieu; - $morehtmlref.='
'; + $morehtmlref = '
'; + $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu; + $morehtmlref .= '
'; $shownav = 1; - if ($user->socid && ! in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav=0; + if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0; dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); @@ -947,53 +947,53 @@ if ($resql) include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; // Hook fields - $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder); - $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook + $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); + $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (! empty($arrayfields['m.datec']['checked'])) { + if (!empty($arrayfields['m.datec']['checked'])) { print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); } - if (! empty($arrayfields['m.tms']['checked'])) { + if (!empty($arrayfields['m.tms']['checked'])) { print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); } print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print "
'; if ($productCombinations || $massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined { - $selected=0; - if (in_array($prodstatic->id, $arrayofselected)) $selected=1; - print ''; + $selected = 0; + if (in_array($prodstatic->id, $arrayofselected)) $selected = 1; + print ''; } print '