From 0b9a3087eacbd965f0ef43f72f1a7ead501df1c3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 Nov 2017 12:11:02 +0100 Subject: [PATCH] Fix bug reported by scrutinizer --- htdocs/accountancy/class/lettering.class.php | 39 ++++++++++--------- htdocs/bookmarks/bookmarks.lib.php | 6 +-- htdocs/categories/class/categorie.class.php | 2 +- .../action/class/api_agendaevents.class.php | 9 +++-- htdocs/comm/action/index.php | 4 +- htdocs/comm/action/pertype.php | 38 +++++++++--------- htdocs/contrat/class/contrat.class.php | 10 +++-- htdocs/core/class/commonobject.class.php | 6 +-- htdocs/core/lib/functions.lib.php | 10 +++-- 9 files changed, 64 insertions(+), 60 deletions(-) diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index 81e0ad5e20e..b30c0bdf9da 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -20,7 +20,7 @@ /** * \file accountancy/class/bookkeeping.class.php * \ingroup Advanced accountancy - * \brief File of class for lettering + * \brief File of class for lettering */ include_once DOL_DOCUMENT_ROOT . "/accountancy/class/bookkeeping.class.php"; include_once DOL_DOCUMENT_ROOT . "/societe/class/societe.class.php"; @@ -37,8 +37,9 @@ class lettering extends BookKeeping * @param int $socid Thirdparty id * @return void */ - public function lettrageTiers($socid) { - $db = $this->db; + public function lettrageTiers($socid) + { + $error = 0; $object = new Societe($this->db); $object->id = $socid; @@ -70,20 +71,20 @@ class lettering extends BookKeeping $sql .= " ) AND (bk.date_lettering ='' OR bk.date_lettering IS NULL) "; $sql .= " AND (bk.lettering_code != '' OR bk.lettering_code IS NULL) "; - $sql .= $db->order('bk.doc_date', 'DESC'); + $sql .= $this->db->order('bk.doc_date', 'DESC'); // echo $sql; // - $resql = $db->query($sql); + $resql = $this->db->query($sql); if ($resql) { - $num = $db->num_rows($resql); + $num = $this->db->num_rows($resql); - while ( $obj = $db->fetch_object($resql) ) { + while ($obj = $this->db->fetch_object($resql) ) { $ids = array(); $ids_fact = array(); - if ($obj->type == 'payment_supplier') { - + if ($obj->type == 'payment_supplier') + { $sql = 'SELECT DISTINCT bk.rowid, facf.ref, facf.ref_supplier, payf.fk_bank, facf.rowid as fact_id'; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; @@ -103,9 +104,9 @@ class lettering extends BookKeeping } $sql .= " ) "; - $resql2 = $db->query($sql); + $resql2 = $this->db->query($sql); if ($resql2) { - while ( $obj2 = $db->fetch_object($resql2) ) { + while ( $obj2 = $this->db->fetch_object($resql2) ) { $ids[$obj2->rowid] = $obj2->rowid; $ids_fact[] = $obj2->fact_id; } @@ -130,9 +131,9 @@ class lettering extends BookKeeping } $sql .= " ) "; - $resql2 = $db->query($sql); + $resql2 = $this->db->query($sql); if ($resql2) { - while ( $obj2 = $db->fetch_object($resql2) ) { + while ( $obj2 = $this->db->fetch_object($resql2) ) { $ids[$obj2->rowid] = $obj2->rowid; } } else { @@ -161,9 +162,9 @@ class lettering extends BookKeeping } $sql .= " ) "; - $resql2 = $db->query($sql); + $resql2 = $this->db->query($sql); if ($resql2) { - while ( $obj2 = $db->fetch_object($resql2) ) { + while ( $obj2 = $this->db->fetch_object($resql2) ) { $ids[$obj2->rowid] = $obj2->rowid; $ids_fact[] = $obj2->fact_id; } @@ -188,9 +189,9 @@ class lettering extends BookKeeping } $sql .= " ) "; - $resql2 = $db->query($sql); + $resql2 = $this->db->query($sql); if ($resql2) { - while ( $obj2 = $db->fetch_object($resql2) ) { + while ( $obj2 = $this->db->fetch_object($resql2) ) { $ids[$obj2->rowid] = $obj2->rowid; } } else { @@ -220,8 +221,8 @@ class lettering extends BookKeeping * * @param array $ids ids array * @param boolean $notrigger no trigger - * @return number - */ + * @return number + */ public function updateLettrage($ids = array(), $notrigger = false) { $error = 0; diff --git a/htdocs/bookmarks/bookmarks.lib.php b/htdocs/bookmarks/bookmarks.lib.php index dc91b259018..9754b0aeeb8 100644 --- a/htdocs/bookmarks/bookmarks.lib.php +++ b/htdocs/bookmarks/bookmarks.lib.php @@ -35,7 +35,7 @@ function printBookmarksList($aDb, $aLangs) $db = $aDb; $langs = $aLangs; - $ret.= ''."\n"; + $ret = ''."\n"; if (! empty($conf->use_javascript_ajax)) { // Bookmark autosubmit can't work when javascript is off. @@ -67,10 +67,8 @@ function printBookmarksList($aDb, $aLangs) $url.=($tmpurl?'?'.$tmpurl:''); } - $ret = ''; - // Menu bookmark - $ret.= ''."\n"; + $ret = ''."\n"; $ret.= ''."\n"; $ret.= '
'; diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 2e69626c1aa..87594b2031f 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -392,7 +392,7 @@ class Categorie extends CommonObject * -1 : SQL error * -2 : invalid category */ - function update($user='') + function update(User $user) { global $conf, $langs,$hookmanager; diff --git a/htdocs/comm/action/class/api_agendaevents.class.php b/htdocs/comm/action/class/api_agendaevents.class.php index 252d2915050..58deec46f5e 100644 --- a/htdocs/comm/action/class/api_agendaevents.class.php +++ b/htdocs/comm/action/class/api_agendaevents.class.php @@ -36,7 +36,7 @@ class AgendaEvents extends DolibarrApi ); /** - * @var Event $actioncomm {@type ActionComm} + * @var ActionComm $actioncomm {@type ActionComm} */ public $actioncomm; @@ -115,11 +115,11 @@ class AgendaEvents extends DolibarrApi if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id; $sql = "SELECT t.id as rowid"; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as t"; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale $sql.= ' WHERE t.entity IN ('.getEntity('agenda').')'; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc"; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc"; if ($user_ids) $sql.=" AND t.fk_user_action IN (".$user_ids.")"; if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid; // Insert sale filter @@ -153,6 +153,7 @@ class AgendaEvents extends DolibarrApi if ($result) { + $i=0; $num = $db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); while ($i < $min) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index cfa4fd18508..2d475e07ed5 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -703,7 +703,7 @@ if ($showbirthday) $event->type_code='BIRTHDAY'; $event->libelle=$langs->trans("Birthday").' '.dolGetFirstLastname($obj->firstname,$obj->lastname); $event->percentage=100; - $event->fulldayevent=true; + $event->fulldayevent=1; $event->date_start_in_calendar=$event->datep; $event->date_end_in_calendar=$event->datef; @@ -876,7 +876,7 @@ if (count($listofextcals)) $dateend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1; // We remove one second to get last second of day //print 'x'.$datestart.'-'.$dateend;exit; //print dol_print_date($dateend,'dayhour','gmt'); - $event->fulldayevent=true; + $event->fulldayevent=1; $addevent=true; } elseif (!is_array($icalevent['DTSTART'])) // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch) diff --git a/htdocs/comm/action/pertype.php b/htdocs/comm/action/pertype.php index 8a68ba1bd86..cc3688a4793 100644 --- a/htdocs/comm/action/pertype.php +++ b/htdocs/comm/action/pertype.php @@ -772,7 +772,7 @@ function show_day_events_pertype($username, $day, $month, $year, $monthshown, $s global $user, $conf, $langs, $hookmanager, $action; global $filter, $filtert, $status, $actioncode; // Filters used into search form global $theme_datacolor; // Array with a list of different we can use (come from theme) - global $cachethirdparties, $cachecontacts, $colorindexused; + global $cachethirdparties, $cachecontacts, $cacheprojects, $colorindexused; global $begin_h, $end_h; $cases1 = array(); // Color first half hour @@ -894,33 +894,33 @@ function show_day_events_pertype($username, $day, $month, $year, $monthshown, $s $cases1[$h][$event->id]['color']=$color; if ($event->fk_project > 0) { - if (empty($cache_project[$event->fk_project])) + if (empty($cacheprojects[$event->fk_project])) { $tmpproj=new Project($db); $tmpproj->fetch($event->fk_project); - $cache_project[$event->fk_project]=$tmpproj; + $cacheprojects[$event->fk_project]=$tmpproj; } - $cases1[$h][$event->id]['string'].=', '.$langs->trans("Project").': '.$cache_project[$event->fk_project]->ref.' - '.$cache_project[$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($cache_thirdparty[$event->socid])) + if (empty($cachethirdparties[$event->socid])) { $tmpthirdparty=new Societe($db); $tmpthirdparty->fetch($event->socid); - $cache_thirdparty[$event->socid]=$tmpthirdparty; + $cachethirdparties[$event->socid]=$tmpthirdparty; } - $cases1[$h][$event->id]['string'].=', '.$cache_thirdparty[$event->socid]->name; + $cases1[$h][$event->id]['string'].=', '.$cachethirdparties[$event->socid]->name; } if ($event->contactid > 0) { - if (empty($cache_contact[$event->contactid])) + if (empty($cachecontacts[$event->contactid])) { $tmpcontact=new Contact($db); $tmpcontact->fetch($event->contactid); - $cache_contact[$event->contactid]=$tmpcontact; + $cachecontacts[$event->contactid]=$tmpcontact; } - $cases1[$h][$event->id]['string'].=', '.$cache_contact[$event->contactid]->getFullName($langs); + $cases1[$h][$event->id]['string'].=', '.$cachecontacts[$event->contactid]->getFullName($langs); } } if ($event->date_start_in_calendar < $c && $dateendtouse > $b) @@ -940,33 +940,33 @@ function show_day_events_pertype($username, $day, $month, $year, $monthshown, $s $cases2[$h][$event->id]['color']=$color; if ($event->fk_project > 0) { - if (empty($cache_project[$event->fk_project])) + if (empty($cacheprojects[$event->fk_project])) { $tmpproj=new Project($db); $tmpproj->fetch($event->fk_project); - $cache_project[$event->fk_project]=$tmpproj; + $cacheprojects[$event->fk_project]=$tmpproj; } - $cases2[$h][$event->id]['string'].=', '.$langs->trans("Project").': '.$cache_project[$event->fk_project]->ref.' - '.$cache_project[$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($cache_thirdparty[$event->socid])) + if (empty($cachethirdparties[$event->socid])) { $tmpthirdparty=new Societe($db); $tmpthirdparty->fetch($event->socid); - $cache_thirdparty[$event->socid]=$tmpthirdparty; + $cachethirdparties[$event->socid]=$tmpthirdparty; } - $cases2[$h][$event->id]['string'].=', '.$cache_thirdparty[$event->socid]->name; + $cases2[$h][$event->id]['string'].=', '.$cachethirdparties[$event->socid]->name; } if ($event->contactid > 0) { - if (empty($cache_contact[$event->contactid])) + if (empty($cachecontacts[$event->contactid])) { $tmpcontact=new Contact($db); $tmpcontact->fetch($event->contactid); - $cache_contact[$event->contactid]=$tmpcontact; + $cachecontacts[$event->contactid]=$tmpcontact; } - $cases2[$h][$event->id]['string'].=', '.$cache_contact[$event->contactid]->getFullName($langs); + $cases2[$h][$event->id]['string'].=', '.$cachecontacts[$event->contactid]->getFullName($langs); } } } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index c1d8839dd57..2a8f2a6b505 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -311,13 +311,15 @@ class Contrat extends CommonObject // Load lines $this->fetch_lines(); + $now = dol_now(); + $ok=true; foreach($this->lines as $contratline) { // Close lines not already closed if ($contratline->statut != 5) { - $contratline->date_cloture=dol_now(); + $contratline->date_cloture=$now; $contratline->fk_user_cloture=$user->id; $contratline->statut='5'; $result=$contratline->update($user); @@ -448,9 +450,9 @@ class Contrat extends CommonObject 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; } } else diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 23315ef2778..f1bef8c9271 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -149,13 +149,13 @@ abstract class CommonObject public $user; /** - * @var CommonObject An originating object? + * @var string The type of originating object ('commande', 'facture', ...) * @see fetch_origin() */ public $origin; /** - * @var int The originating object? - * @see fetch_origin(), origin + * @var int The id of originating object + * @see fetch_origin() */ public $origin_id; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 435ae68fa94..a4b569aae87 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1949,7 +1949,7 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) /** - * Return date for now. In mot cases, we use this function without parameters (that means GMT time). + * Return date for now. In most cases, we use this function without parameters (that means GMT time). * * @param string $mode 'gmt' => we return GMT timestamp, * 'tzserver' => we add the PHP server timezone @@ -1959,7 +1959,8 @@ function dol_mktime($hour,$minute,$second,$month,$day,$year,$gm=false,$check=1) */ function dol_now($mode='gmt') { - $ret=''; + $ret=0; + // Note that gmmktime and mktime return same value (GMT) when used without parameters //if ($mode == 'gmt') $ret=gmmktime(); // Strict Standards: gmmktime(): You should be using the time() function instead if ($mode == 'gmt') $ret=time(); // Time for now at greenwich. @@ -1967,7 +1968,7 @@ function dol_now($mode='gmt') { require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $tzsecond=getServerTimeZoneInt('now'); // Contains tz+dayling saving time - $ret=dol_now('gmt')+($tzsecond*3600); + $ret=(int) dol_now('gmt')+($tzsecond*3600); } /*else if ($mode == 'tzref') // Time for now with parent company timezone is added { @@ -1980,8 +1981,9 @@ function dol_now($mode='gmt') //print 'eeee'.time().'-'.mktime().'-'.gmmktime(); $offsettz=(empty($_SESSION['dol_tz'])?0:$_SESSION['dol_tz'])*60*60; $offsetdst=(empty($_SESSION['dol_dst'])?0:$_SESSION['dol_dst'])*60*60; - $ret=dol_now('gmt')+($offsettz+$offsetdst); + $ret=(int) dol_now('gmt')+($offsettz+$offsetdst); } + return $ret; }