From eea9a76589c6138dea1e06c8774d7c6a1522cfd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 18 Sep 2014 15:09:03 +0200 Subject: [PATCH] FIX: Variable might not be traversable --- htdocs/accountancy/journal/bankjournal.php | 144 +++++++++++---------- htdocs/accountancy/journal/cashjournal.php | 107 +++++++-------- htdocs/comm/action/peruser.php | 77 ++++++----- htdocs/compta/bank/class/account.class.php | 8 +- htdocs/core/class/html.form.class.php | 19 +-- htdocs/core/lib/json.lib.php | 2 +- htdocs/user/class/usergroup.class.php | 2 +- 7 files changed, 192 insertions(+), 167 deletions(-) diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index ef39e5668a0..ca862098bd3 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -170,83 +170,87 @@ if ($result) { } $links = $object->get_url($obj->rowid); - foreach ( $links as $key => $val ) { + // get_url may return -1 which is not traversable + if (is_array($links)) { - $tabtype[$obj->rowid] = $links[$key]['type']; + foreach ( $links as $key => $val ) { - 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']; + $tabtype[$obj->rowid] = $links[$key]['type']; - $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 + if ($links[$key]['type'] == 'payment') { - $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) + $paymentstatic->id = $links[$key]['url_id']; + $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2); + } + else if ($links[$key]['type'] == 'payment_supplier') { - $objmid = $db->fetch_object($resultmid); - $tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount; + $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/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; diff --git a/htdocs/accountancy/journal/cashjournal.php b/htdocs/accountancy/journal/cashjournal.php index 33b1e4359c1..e2994ce57e6 100644 --- a/htdocs/accountancy/journal/cashjournal.php +++ b/htdocs/accountancy/journal/cashjournal.php @@ -157,64 +157,67 @@ if ($result) { } $links = $object->get_url($obj->rowid); - foreach ( $links as $key => $val ) { + // get_url may return -1 which is not traversable + if (is_array($links)) { + foreach ($links as $key => $val) { - $tabtype[$obj->rowid] = $links[$key]['type']; + $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') { + 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') { + $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']; + $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']; + $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; } - $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 { + $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(); \ No newline at end of file +$db->close(); diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 8bcd1c7289b..ccb544ac4bb 100644 --- a/htdocs/comm/action/peruser.php +++ b/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 ""; - echo '' . $username->getNomUrl(1). ''; - $tmpday = $sav; - $i = 0; - for ($iter_day = 0; $iter_day < 7; $iter_day++) - { - if (($i + 1) < $begin_d || ($i + 1) > $end_d) - { +// listUsersForGroup may return -1 which is not traversable +if (is_array($usernames)) { + foreach ($usernames as $username) { + echo ""; + echo '' . $username->getNomUrl(1) . ''; + $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']; + + $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++; - 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']; - - $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++; + echo "\n"; + $showheader = false; } - echo "\n"; - $showheader = false; } echo "\n"; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 4ca6175d785..cd428f927b2 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/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='') { diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 937f904c512..6b0e9b4d895 100644 --- a/htdocs/core/class/html.form.class.php +++ b/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.='
'; - 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.='
'; - } + // 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.='
'; + } + } //$out.=''; return $out; diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index 69dbb4eba1a..00d5970d77e 100644 --- a/htdocs/core/lib/json.lib.php +++ b/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) { diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index b801c2660aa..9bd0d64fe4c 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/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) {