From 2117cf7a6a2febc03e04dba287b7ed58345836f4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Mar 2012 14:34:53 +0100 Subject: [PATCH 1/6] Fix: use $context for key to avoid data corrupt Fix: remove dao instantiation --- htdocs/core/class/hookmanager.class.php | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index fe9ad22e071..2fe08fc5488 100755 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -77,7 +77,6 @@ class HookManager $this->contextarray=array_merge($arraycontext,$this->contextarray); // All contexts are concatenated - $i=0; foreach($conf->hooks_modules as $module => $hooks) { if ($conf->$module->enabled) @@ -93,29 +92,14 @@ class HookManager $actionfile = 'actions_'.$module.'.class.php'; $pathroot = ''; - $this->hooks[$i]['type']=$context; - // Include actions class overwriting hooks $resaction=dol_include_once($path.$actionfile); if ($resaction) { $controlclassname = 'Actions'.ucfirst($module); $actionInstance = new $controlclassname($this->db); - $this->hooks[$i]['modules'][$module] = $actionInstance; + $this->hooks[$context]['modules'][$module] = $actionInstance; } - - // Include dataservice class (model) - // TODO storing dao is useless here. It's goal of controller to known which dao to manage - $daofile = 'dao_'.$module.'.class.php'; - $resdao=dol_include_once($path.$daofile); - if ($resdao) - { - // Instantiate dataservice class (model) - $daoInstance = 'Dao'.ucfirst($module); - $this->hooks[$i]['modules'][$module]->object = new $daoInstance($this->db); - } - - $i++; } } } From ca468c2f843ed068a63db16e0d9941ec828b0fcd Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Mar 2012 14:48:56 +0100 Subject: [PATCH 2/6] Fix: hook object more simple --- htdocs/core/class/hookmanager.class.php | 8 ++++---- htdocs/core/lib/pdf.lib.php | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 2fe08fc5488..eaac3eabf07 100755 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -98,7 +98,7 @@ class HookManager { $controlclassname = 'Actions'.ucfirst($module); $actionInstance = new $controlclassname($this->db); - $this->hooks[$context]['modules'][$module] = $actionInstance; + $this->hooks[$context][$module] = $actionInstance; } } } @@ -129,11 +129,11 @@ class HookManager // Loop on each hook $resaction=0; $resprint=''; - foreach($this->hooks as $hook) + foreach($this->hooks as $modules) { - if (! empty($hook['modules'])) + if (! empty($modules)) { - foreach($hook['modules'] as $module => $actioninstance) + foreach($modules as $actioninstance) { $var=!$var; diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 8148f6e91d1..30137ca7963 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1005,13 +1005,13 @@ function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0,$hookmanage */ function pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails=0) { - if (! empty($object->hooks) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) ) + if (! empty($object->hooks) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) { $special_code = $object->lines[$i]->special_code; if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); - foreach($object->hooks as $hook) + foreach($object->hooks as $modules) { - if (method_exists($hook['modules'][$special_code],'pdf_getlineupwithtax')) return $hook['modules'][$special_code]->pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails); + if (method_exists($modules[$special_code],'pdf_getlineupwithtax')) return $modules[$special_code]->pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails); } } else @@ -1222,13 +1222,13 @@ function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0) } else { - if (! empty($object->hooks) && ( ($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) ) + if (! empty($object->hooks) && (($object->lines[$i]->product_type == 9 && ! empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) { $special_code = $object->lines[$i]->special_code; if (! empty($object->lines[$i]->fk_parent_line)) $special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line); - foreach($object->hooks as $hook) + foreach($object->hooks as $modules) { - if (method_exists($hook['modules'][$special_code],'pdf_getlinetotalwithtax')) return $hook['modules'][$special_code]->pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails); + if (method_exists($modules[$special_code],'pdf_getlinetotalwithtax')) return $modules[$special_code]->pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails); } } else From 2e9ef6f49a7feacc588ee32fbae806204f43bcfa Mon Sep 17 00:00:00 2001 From: simnandez Date: Fri, 9 Mar 2012 17:21:53 +0100 Subject: [PATCH 3/6] Fix: Missing translation --- htdocs/projet/element.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 136014cf0e6..468ffcee2c4 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -2,6 +2,7 @@ /* Copyright (C) 2001-2004 Rodolphe Quiedeville * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2012 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,9 +41,10 @@ if ($conf->agenda->enabled) require_once(DOL_DOCUMENT_ROOT."/comm/action/cl $langs->load("projects"); $langs->load("companies"); $langs->load("suppliers"); -if ($conf->facture->enabled) $langs->load("bills"); -if ($conf->commande->enabled) $langs->load("orders"); -if ($conf->propal->enabled) $langs->load("propal"); +if ($conf->facture->enabled) $langs->load("bills"); +if ($conf->commande->enabled) $langs->load("orders"); +if ($conf->propal->enabled) $langs->load("propal"); +if ($conf->ficheinter->enabled) $langs->load("interventions"); $projectid=''; $ref=''; From 96a5eadcfdcefb38ff0208bb45ce7d9ae2432d6e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Mar 2012 18:03:32 +0100 Subject: [PATCH 4/6] Fix: missing extension --- htdocs/core/tpl/login.tpl.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 55a5f6f608d..2e31abbc569 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -35,6 +35,8 @@ print ''."\n"; if (constant('JS_JQUERY_UI')) print ''."\n"; // JQuery else print ''."\n"; // JQuery // JQuery. Must be before other includes +$ext='.js'; +if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x01)) $ext='.jgz'; print ''."\n"; if (constant('JS_JQUERY')) print ''."\n"; else print ''."\n"; From 616698889ceb77e4c27cab406000763dea8160b2 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Mar 2012 18:21:11 +0100 Subject: [PATCH 5/6] Fix: move script to js core file --- htdocs/core/js/dst.js | 156 ++++++++++++++++++++++++++++++++++ htdocs/core/tpl/login.tpl.php | 136 +---------------------------- 2 files changed, 159 insertions(+), 133 deletions(-) create mode 100644 htdocs/core/js/dst.js diff --git a/htdocs/core/js/dst.js b/htdocs/core/js/dst.js new file mode 100644 index 00000000000..b28c500e2c4 --- /dev/null +++ b/htdocs/core/js/dst.js @@ -0,0 +1,156 @@ +// Copyright (C) 2011-2012 Laurent Destailleur +// Copyright (C) 2011-2012 Regis Houssin +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// or see http://www.gnu.org/ +// + +// +// \file htdocs/core/js/dst.js +// \brief File that include javascript functions for detect user tz, dst_observed, dst_first, dst_second +// + +$(document).ready(function () { + // Detect and save TZ and DST + var rightNow = new Date(); + var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0); + var temp = jan1.toGMTString(); + var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1)); + var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60); + var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); + temp = june1.toGMTString(); + var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1)); + var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60); + var dst; + if (std_time_offset == daylight_time_offset) { + dst = "0"; // daylight savings time is NOT observed + } else { + dst = "1"; // daylight savings time is observed + } + var dst_first=DisplayDstSwitchDates('first'); + var dst_second=DisplayDstSwitchDates('second'); + //alert(dst); + $('#tz').val(std_time_offset); // returns TZ + $('#dst_observed').val(dst); // returns if DST is observed on summer + $('#dst_first').val(dst_first); // returns DST first switch in year + $('#dst_second').val(dst_second); // returns DST second switch in year + // Detect and save screen resolution + $('#screenwidth').val($(window).width()); // returns width of browser viewport + $('#screenheight').val($(window).height()); // returns width of browser viewport +}); + +function DisplayDstSwitchDates(firstsecond) +{ + var year = new Date().getYear(); + if (year < 1000) year += 1900; + + var firstSwitch = 0; + var secondSwitch = 0; + var lastOffset = 99; + + // Loop through every month of the current year + for (i = 0; i < 12; i++) + { + // Fetch the timezone value for the month + var newDate = new Date(Date.UTC(year, i, 0, 0, 0, 0, 0)); + var tz = -1 * newDate.getTimezoneOffset() / 60; + + // Capture when a timzezone change occurs + if (tz > lastOffset) + firstSwitch = i-1; + else if (tz < lastOffset) + secondSwitch = i-1; + + lastOffset = tz; + } + + // Go figure out date/time occurences a minute before + // a DST adjustment occurs + var secondDstDate = FindDstSwitchDate(year, secondSwitch); + var firstDstDate = FindDstSwitchDate(year, firstSwitch); + + if (firstsecond == 'first') return firstDstDate; + if (firstsecond == 'second') return secondDstDate; + + if (firstDstDate == null && secondDstDate == null) + return 'Daylight Savings is not observed in your timezone.'; + else + return 'Last minute before DST change occurs in ' + + year + ': ' + firstDstDate + ' and ' + secondDstDate; +} + +function FindDstSwitchDate(year, month) +{ + // Set the starting date + var baseDate = new Date(Date.UTC(year, month, 0, 0, 0, 0, 0)); + var changeDay = 0; + var changeMinute = -1; + var baseOffset = -1 * baseDate.getTimezoneOffset() / 60; + var dstDate; + + // Loop to find the exact day a timezone adjust occurs + for (day = 0; day < 50; day++) + { + var tmpDate = new Date(Date.UTC(year, month, day, 0, 0, 0, 0)); + var tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60; + + // Check if the timezone changed from one day to the next + if (tmpOffset != baseOffset) + { + var minutes = 0; + changeDay = day; + + // Back-up one day and grap the offset + tmpDate = new Date(Date.UTC(year, month, day-1, 0, 0, 0, 0)); + tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60; + + // Count the minutes until a timezone chnage occurs + while (changeMinute == -1) + { + tmpDate = new Date(Date.UTC(year, month, day-1, 0, minutes, 0, 0)); + tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60; + + // Determine the exact minute a timezone change + // occurs + if (tmpOffset != baseOffset) + { + // Back-up a minute to get the date/time just + // before a timezone change occurs + tmpOffset = new Date(Date.UTC(year, month, + day-1, 0, minutes-1, 0, 0)); + changeMinute = minutes; + break; + } + else + minutes++; + } + + // Add a month (for display) since JavaScript counts + // months from 0 to 11 + dstDate = tmpOffset.getMonth() + 1; + + // Pad the month as needed + if (dstDate < 10) dstDate = "0" + dstDate; + + // Add the day and year + dstDate = year + '-' + dstDate + '-' + tmpOffset.getDate() + 'T'; + + // Capture the time stamp + tmpDate = new Date(Date.UTC(year, month, + day-1, 0, minutes-1, 0, 0)); + dstDate += tmpDate.toTimeString().split(' ')[0] + 'Z'; + return dstDate; + } + } +} diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 2e31abbc569..72de98269af 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -40,6 +40,7 @@ if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_S print ''."\n"; if (constant('JS_JQUERY')) print ''."\n"; else print ''."\n"; +print ''."\n"; print '