Browse Source

Fix bug reported by scrutinizer

Laurent Destailleur 7 years ago
parent
commit
0b9a3087ea

+ 20 - 19
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;
 

+ 2 - 4
htdocs/bookmarks/bookmarks.lib.php

@@ -35,7 +35,7 @@ function printBookmarksList($aDb, $aLangs)
 	$db = $aDb;
 	$langs = $aLangs;
 
-	$ret.= '<div class="menu_top"></div>'."\n";
+	$ret = '<div class="menu_top"></div>'."\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.= '<div class="menu_top"></div>'."\n";
+		$ret = '<div class="menu_top"></div>'."\n";
 
 		$ret.= '<!-- form with POST method by default, will be replaced with GET for external link by js -->'."\n";
 		$ret.= '<form id="actionbookmark" name="actionbookmark" method="POST" action="">';

+ 1 - 1
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;
 

+ 5 - 4
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)

+ 2 - 2
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)

+ 19 - 19
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);
 							}
 						}
 					}

+ 6 - 4
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

+ 3 - 3
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;
 

+ 6 - 4
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;
 }