Browse Source

FIX: Variable might not be traversable

Raphaël Doursenaud 10 years ago
parent
commit
eea9a76589

+ 75 - 71
htdocs/accountancy/journal/bankjournal.php

@@ -170,83 +170,87 @@ if ($result) {
 		}
 		$links = $object->get_url($obj->rowid);
 
-		foreach ( $links as $key => $val ) {
-
-			$tabtype[$obj->rowid] = $links[$key]['type'];
-
-			if ($links[$key]['type'] == 'payment')
-			{
-				$paymentstatic->id = $links[$key]['url_id'];
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2);
-			} 
-			else if ($links[$key]['type'] == 'payment_supplier')
-			{
-				$paymentsupplierstatic->id = $links[$key]['url_id'];
-				$paymentsupplierstatic->ref = $links[$key]['url_id'];
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2);
-			}
-			else if ($links[$key]['type'] == 'company')
-			{
-				$societestatic->id = $links[$key]['url_id'];
-				$societestatic->nom = $links[$key]['label'];
-				$tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
-				$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
-			}
-			else if ($links[$key]['type'] == 'sc')
-			{
-				$chargestatic->id = $links[$key]['url_id'];
-				$chargestatic->ref = $links[$key]['url_id'];
-
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
-				if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
-					if ($reg[1] == 'socialcontribution')
-						$reg[1] = 'SocialContribution';
-					$chargestatic->lib = $langs->trans($reg[1]);
+		// get_url may return -1 which is not traversable
+		if (is_array($links)) {
+
+			foreach ( $links as $key => $val ) {
+
+				$tabtype[$obj->rowid] = $links[$key]['type'];
+
+				if ($links[$key]['type'] == 'payment')
+				{
+					$paymentstatic->id = $links[$key]['url_id'];
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2);
+				} 
+				else if ($links[$key]['type'] == 'payment_supplier')
+				{
+					$paymentsupplierstatic->id = $links[$key]['url_id'];
+					$paymentsupplierstatic->ref = $links[$key]['url_id'];
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2);
 				}
-				else
+				else if ($links[$key]['type'] == 'company')
 				{
-					$chargestatic->lib = $links[$key]['label'];
+					$societestatic->id = $links[$key]['url_id'];
+					$societestatic->nom = $links[$key]['label'];
+					$tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
+					$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
 				}
-				$chargestatic->ref = $chargestatic->lib;
-				$tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
-
-				$sqlmid = 'SELECT cchgsoc.accountancy_code';
-				$sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc ";
-				$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON  chgsoc.fk_type=cchgsoc.id";
-				$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON  paycharg.fk_charge=chgsoc.rowid";
-				$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON  bkurl.url_id=paycharg.rowid";
-				$sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid;
-
-				dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
-				$resultmid = $db->query($sqlmid);
-				if ($resultmid)
+				else if ($links[$key]['type'] == 'sc')
 				{
-					$objmid = $db->fetch_object($resultmid);
-					$tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount;
+					$chargestatic->id = $links[$key]['url_id'];
+					$chargestatic->ref = $links[$key]['url_id'];
+
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
+					if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
+						if ($reg[1] == 'socialcontribution')
+							$reg[1] = 'SocialContribution';
+						$chargestatic->lib = $langs->trans($reg[1]);
+					}
+					else
+					{
+						$chargestatic->lib = $links[$key]['label'];
+					}
+					$chargestatic->ref = $chargestatic->lib;
+					$tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
+
+					$sqlmid = 'SELECT cchgsoc.accountancy_code';
+					$sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc ";
+					$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON  chgsoc.fk_type=cchgsoc.id";
+					$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON  paycharg.fk_charge=chgsoc.rowid";
+					$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON  bkurl.url_id=paycharg.rowid";
+					$sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid;
+
+					dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
+					$resultmid = $db->query($sqlmid);
+					if ($resultmid)
+					{
+						$objmid = $db->fetch_object($resultmid);
+						$tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount;
+					}
 				}
+				else if ($links[$key]['type'] == 'payment_vat')
+				{
+					$paymentvatstatic->id = $links[$key]['url_id'];
+					$paymentvatstatic->ref = $links[$key]['url_id'];
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
+					$tabtp[$obj->rowid][$cpttva] += $obj->amount;
+				}
+				else if ($links[$key]['type'] == 'payment_salary')
+				{	
+					$paymentsalstatic->id = $links[$key]['url_id'];
+					$paymentsalstatic->ref = $links[$key]['url_id'];
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2);
+					$tabtp[$obj->rowid][$accountancy_account_salary] += $obj->amount;
+				}
+				else if ($links[$key]['type'] == 'banktransfert')
+				{
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
+					$tabtp[$obj->rowid][$cpttva] += $obj->amount;
+				}
+				/*else {
+					$tabtp [$obj->rowid] [$accountancy_account_salary] += $obj->amount;
+				}*/
 			}
-			else if ($links[$key]['type'] == 'payment_vat')
-			{
-				$paymentvatstatic->id = $links[$key]['url_id'];
-				$paymentvatstatic->ref = $links[$key]['url_id'];
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
-				$tabtp[$obj->rowid][$cpttva] += $obj->amount;
-			}
-			else if ($links[$key]['type'] == 'payment_salary')
-			{	
-				$paymentsalstatic->id = $links[$key]['url_id'];
-				$paymentsalstatic->ref = $links[$key]['url_id'];
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2);
-				$tabtp[$obj->rowid][$accountancy_account_salary] += $obj->amount;
-			}
-			else if ($links[$key]['type'] == 'banktransfert')
-			{
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
-				$tabtp[$obj->rowid][$cpttva] += $obj->amount;
-			}
-			/*else {
-				$tabtp [$obj->rowid] [$accountancy_account_salary] += $obj->amount;
-			}*/
 		}
 		$tabbq[$obj->rowid][$compta_bank] += $obj->amount;
 

+ 60 - 57
htdocs/accountancy/journal/cashjournal.php

@@ -157,64 +157,67 @@ if ($result) {
 		}
 		$links = $object->get_url($obj->rowid);
 
-		foreach ( $links as $key => $val ) {
-
-			$tabtype[$obj->rowid] = $links[$key]['type'];
-
-			if ($links[$key]['type'] == 'payment') {
-				$paymentstatic->id = $links[$key]['url_id'];
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2);
-			} else if ($links[$key]['type'] == 'payment_supplier') {
-				$paymentsupplierstatic->id = $links[$key]['url_id'];
-				$paymentsupplierstatic->ref = $links[$key]['url_id'];
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2);
-			} else if ($links[$key]['type'] == 'company') {
-
-				$societestatic->id = $links[$key]['url_id'];
-				$societestatic->nom = $links[$key]['label'];
-				$tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
-				$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
-			} else if ($links[$key]['type'] == 'sc') {
-
-				$chargestatic->id = $links[$key]['url_id'];
-				$chargestatic->ref = $links[$key]['url_id'];
-
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
-				if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
-					if ($reg[1] == 'socialcontribution')
-						$reg[1] = 'SocialContribution';
-					$chargestatic->lib = $langs->trans($reg[1]);
-				} else {
-					$chargestatic->lib = $links[$key]['label'];
-				}
-				$chargestatic->ref = $chargestatic->lib;
-				$tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
-
-				$sqlmid = 'SELECT cchgsoc.accountancy_code';
-				$sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc ";
-				$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON  chgsoc.fk_type=cchgsoc.id";
-				$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON  paycharg.fk_charge=chgsoc.rowid";
-				$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON  bkurl.url_id=paycharg.rowid";
-				$sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid;
-				dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
-				$resultmid = $db->query($sqlmid);
-				if ($resultmid) {
-					$objmid = $db->fetch_object($resultmid);
-					$tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount;
+		// get_url may return -1 which is not traversable
+		if (is_array($links)) {
+			foreach ($links as $key => $val) {
+
+				$tabtype[$obj->rowid] = $links[$key]['type'];
+
+				if ($links[$key]['type'] == 'payment') {
+					$paymentstatic->id = $links[$key]['url_id'];
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2);
+				} else if ($links[$key]['type'] == 'payment_supplier') {
+					$paymentsupplierstatic->id = $links[$key]['url_id'];
+					$paymentsupplierstatic->ref = $links[$key]['url_id'];
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2);
+				} else if ($links[$key]['type'] == 'company') {
+
+					$societestatic->id = $links[$key]['url_id'];
+					$societestatic->nom = $links[$key]['label'];
+					$tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30);
+					$tabtp[$obj->rowid][$compta_soc] += $obj->amount;
+				} else if ($links[$key]['type'] == 'sc') {
+
+					$chargestatic->id = $links[$key]['url_id'];
+					$chargestatic->ref = $links[$key]['url_id'];
+
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2);
+					if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) {
+						if ($reg[1] == 'socialcontribution')
+							$reg[1] = 'SocialContribution';
+						$chargestatic->lib = $langs->trans($reg[1]);
+					} else {
+						$chargestatic->lib = $links[$key]['label'];
+					}
+					$chargestatic->ref = $chargestatic->lib;
+					$tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30);
+
+					$sqlmid = 'SELECT cchgsoc.accountancy_code';
+					$sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc ";
+					$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON  chgsoc.fk_type=cchgsoc.id";
+					$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON  paycharg.fk_charge=chgsoc.rowid";
+					$sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON  bkurl.url_id=paycharg.rowid";
+					$sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid;
+					dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG);
+					$resultmid = $db->query($sqlmid);
+					if ($resultmid) {
+						$objmid = $db->fetch_object($resultmid);
+						$tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount;
+					}
+				} else if ($links[$key]['type'] == 'payment_vat') {
+
+					$paymentvatstatic->id = $links[$key]['url_id'];
+					$paymentvatstatic->ref = $links[$key]['url_id'];
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
+					$tabtp[$obj->rowid][$cpttva] += $obj->amount;
+				} else if ($links[$key]['type'] == 'banktransfert') {
+					$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
+					$tabtp[$obj->rowid][$cpttva] += $obj->amount;
 				}
-			} else if ($links[$key]['type'] == 'payment_vat') {
-
-				$paymentvatstatic->id = $links[$key]['url_id'];
-				$paymentvatstatic->ref = $links[$key]['url_id'];
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
-				$tabtp[$obj->rowid][$cpttva] += $obj->amount;
-			} else if ($links[$key]['type'] == 'banktransfert') {
-				$tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2);
-				$tabtp[$obj->rowid][$cpttva] += $obj->amount;
+				/*else {
+					$tabtp [$obj->rowid] [$cptsociale] += $obj->amount;
+				}*/
 			}
-			/*else {
-				$tabtp [$obj->rowid] [$cptsociale] += $obj->amount;
-			}*/
 		}
 		$tabbq[$obj->rowid][$compta_bank] += $obj->amount;
 
@@ -530,4 +533,4 @@ if ($action == 'export_csv') {
 	// End of page
 	llxFooter();
 }
-$db->close();
+$db->close();

+ 45 - 30
htdocs/comm/action/peruser.php

@@ -600,41 +600,56 @@ else
 // Loop on each user to show calendar
 $sav = $tmpday;
 $showheader = true;
-foreach ($usernames as $username)
-{
-	echo "<tr>";
-	echo '<td class="cal_current_month">' . $username->getNomUrl(1). '</td>';
-	$tmpday = $sav;
-
-	$i = 0;
-	for ($iter_day = 0; $iter_day < 7; $iter_day++)
-	{
-		if (($i + 1) < $begin_d || ($i + 1) > $end_d)
-		{
-			$i++;
-			continue;
-		}
 
-        // Show days of the current week
-		$curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
-		$tmparray = dol_getdate($curtime,'fast');
-		$tmpday = $tmparray['mday'];
-		$tmpmonth = $tmparray['mon'];
-		$tmpyear = $tmparray['year'];
+// listUsersForGroup may return -1 which is not traversable
+if (is_array($usernames)) {
+	foreach ($usernames as $username) {
+		echo "<tr>";
+		echo '<td class="cal_current_month">' . $username->getNomUrl(1) . '</td>';
+		$tmpday = $sav;
 
-		$style='cal_current_month';
-		if ($iter_day == 6) $style.=' cal_other_month';
-		$today=0;
-		$todayarray=dol_getdate($now,'fast');
-		if ($todayarray['mday']==$tmpday && $todayarray['mon']==$month && $todayarray['year']==$year) $today=1;
-		if ($today) $style='cal_today_peruser';
+		$i = 0;
+		for ($iter_day = 0; $iter_day < 7; $iter_day++) {
+			if (($i + 1) < $begin_d || ($i + 1) > $end_d) {
+				$i++;
+				continue;
+			}
 
-		show_day_events2($username, $tmpday, $month, $year, $monthshown, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, $showheader);
+			// Show days of the current week
+			$curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd');
+			$tmparray = dol_getdate($curtime, 'fast');
+			$tmpday = $tmparray['mday'];
+			$tmpmonth = $tmparray['mon'];
+			$tmpyear = $tmparray['year'];
+
+			$style = 'cal_current_month';
+			if ($iter_day == 6) $style .= ' cal_other_month';
+			$today = 0;
+			$todayarray = dol_getdate($now, 'fast');
+			if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) $today = 1;
+			if ($today) $style = 'cal_today_peruser';
+
+			show_day_events2(
+				$username,
+				$tmpday,
+				$month,
+				$year,
+				$monthshown,
+				$style,
+				$eventarray,
+				0,
+				$maxnbofchar,
+				$newparam,
+				1,
+				300,
+				$showheader
+			);
 
-		$i++;
+			$i++;
+		}
+		echo "</tr>\n";
+		$showheader = false;
 	}
-	echo "</tr>\n";
-	$showheader = false;
 }
 
 echo "</table>\n";

+ 4 - 4
htdocs/compta/bank/class/account.class.php

@@ -164,10 +164,10 @@ class Account extends CommonObject
      * 		TODO Move this into AccountLine
      *      Return array with links from llx_bank_url
      *
-     *      @param	int		$fk_bank        To search using bank transaction id
-     *      @param	int		$url_id         To search using link to
-     *      @param  string	$type           To search using type
-     *      @return array           		Array of links
+     *      @param  int         $fk_bank    To search using bank transaction id
+     *      @param  int         $url_id     To search using link to
+     *      @param  string      $type       To search using type
+     *      @return array|-1                Array of links or -1 on error
      */
     function get_url($fk_bank='', $url_id='', $type='')
     {

+ 11 - 8
htdocs/core/class/html.form.class.php

@@ -1302,14 +1302,17 @@ class Form
 		$assignedtouser=array();
 		if (!empty($_SESSION['assignedtouser'])) $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true);
 		if (count($assignedtouser)) $out.='<br>';
-		foreach($assignedtouser as $key => $value)
-		{
-			$userstatic->fetch($key);
-			$out.=$userstatic->getNomUrl(1);
-			//$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional"));
-			//$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy"));
-			$out.='<br>';
-		}
+		// dol_json_decode may return false on error which is not traversable
+		if (is_array($assignedtouser)) {
+			foreach($assignedtouser as $key => $value)
+			{
+				$userstatic->fetch($key);
+				$out.=$userstatic->getNomUrl(1);
+				//$out.=' '.($value['mandatory']?$langs->trans("Mandatory"):$langs->trans("Optional"));
+				//$out.=' '.($value['transparency']?$langs->trans("Busy"):$langs->trans("NotBusy"));
+				$out.='<br>';
+			}
+	    }
 
 		//$out.='</form>';
         return $out;

+ 1 - 1
htdocs/core/lib/json.lib.php

@@ -218,7 +218,7 @@ if (! function_exists('json_decode'))
  *
  * @param	string	$json		Json encoded to PHP Object or Array
  * @param	bool	$assoc		False return an object, true return an array. Try to always use it with true !
- * @return 	mixed				Object or Array
+ * @return 	mixed				Object or Array or false on error
  */
 function dol_json_decode($json, $assoc=false)
 {

+ 1 - 1
htdocs/user/class/usergroup.class.php

@@ -178,7 +178,7 @@ class UserGroup extends CommonObject
 	 *
 	 * 	@param	string	$excludefilter		Filter to exclude
 	 *  @param	int		$mode				0=Return array of user instance, 1=Return array of users id only
-	 * 	@return	array 						Array of users
+	 * 	@return	array|-1					Array of users or -1 on error
 	 */
 	function listUsersForGroup($excludefilter='', $mode=0)
 	{