2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
40 global $app_list_strings;
43 global $currentModule;
49 if ($db->dbType == 'oci8') {
51 echo "<p>".$mod_strings['ERR_NOT_FOR_ORACLE']."</p>";
55 if ($db->dbType == 'mssql') {
57 echo "<p>".$mod_strings['ERR_NOT_FOR_MSSQL']."</p>";
67 $db = DBManagerFactory::getInstance();
70 // check if this fix has been applied already
71 $qDone = "SELECT * FROM versions WHERE name = 'DST Fix'";
72 $rDone = $db->query($qDone);
73 $rowsDone = $db->getRowCount($rDone);
81 $disabled = 'DISABLED';
85 if(!empty($_REQUEST['confirmed']) && $_REQUEST['confirmed'] == true) {
86 // blowaway vCal server cache
87 $qvCal = "TRUNCATE vcals";
88 $rvCal = $db->query($qvCal);
90 // disable refresh double-ups
91 $rDblCheck = $db->query($qDone);
92 $rowsDblCheck = $db->getRowCount($rDblCheck);
93 if($rowsDblCheck < 1) {
95 // majed's sql generation
98 'date_start'=>'time_start',
101 'date_start'=>'time_start',
104 'date_due'=>'time_due',
106 'project_task'=>array(
107 'date_due'=>'time_due',
109 'email_marketing'=>array(
110 'date_start'=>'time_start',
113 'send_date_time'=>'datetime',
117 $zone = $_REQUEST['server_timezone'];
118 $td = new TimeDate();
121 $date_modified = gmdate($GLOBALS['timedate']->get_db_date_time_format());
124 foreach($tables as $table_name =>$table) {
126 //$display .= '<B>'. $table_name . '</b><BR>';
129 for($year = $startyear; $year <= $maxyear; $year++) {
130 $range = $td->getDSTRange($year,$timezones[$zone]);
131 $startDateTime = explode(' ',$range['start']);
132 $endDateTime = explode(' ',$range['end']);
135 if( strtotime($range['start']) < strtotime($range['end'])) {
136 foreach($table as $date=>$time) {
137 $interval='PLUSMINUS INTERVAL 3600 second';
138 if($time != 'datetime'){
139 if ( ( $db->dbType == 'mysql' ) or ( $db->dbType == 'oci8' ) )
141 $field = "CONCAT($table_name.$date,' ', $table_name.$time)";
143 if ( $db->dbType == 'mssql' )
145 $field = "$table_name.$date + ' ' + $table_name.$time";
147 $updateBase= "UPDATE $table_name SET date_modified='$date_modified', $table_name.$date=LEFT($field $interval,10),";
148 $updateBase .= " $table_name.$time=RIGHT($field $interval,8)";
151 $field = "$table_name.$date";
152 $updateBase = "UPDATE $table_name SET date_modified='$date_modified', $table_name.$date = $table_name.$date $interval";
154 //BEGIN DATE MODIFIED IN DST WITH DATE OUT DST
155 $update = str_replace('PLUSMINUS', '+', $updateBase);
156 $queryInDST = $update ."
158 $table_name.date_modified >= '{$range['start']}' AND $table_name.date_modified < '{$range['end']}'
159 AND ( $field < '{$range['start']}' OR $field >= '{$range['end']}' )";
161 $result = $db->query($queryInDST);
162 $count = $db->getAffectedRowCount();
163 //$display .= "$year - Records updated with date modified in DST with date out of DST: $count <br>";
164 //BEGIN DATE MODIFIED OUT DST WITH DATE IN DST
165 $update = str_replace('PLUSMINUS', '-', $updateBase);
166 $queryOutDST = $update ."
168 ( $table_name.date_modified < '{$range['start']}' OR $table_name.date_modified >= '{$range['end']}' )
169 AND $field >= '{$range['start']}' AND $field < '{$range['end']}' ";
171 $result = $db->query($queryOutDST);
172 $count = $db->getAffectedRowCount();
173 //$display .= "$year - Records updated with date modified out of DST with date in DST: $count <br>";
177 foreach($table as $date=>$time){
178 $interval='PLUSMINUS INTERVAL 3600 second';
179 if($time != 'datetime'){
181 if ( ( $this->db->dbType == 'mysql' ) or ( $this->db->dbType == 'oci8' ) )
183 $field = "CONCAT($table_name.$date,' ', $table_name.$time)";
185 if ( $this->db->dbType == 'mssql' )
187 $field = "$table_name.$date + ' ' + $table_name.$time";
189 $updateBase= "UPDATE $table_name SET $table_name.$date=LEFT($field $interval,10),";
190 $updateBase .= " $table_name.$time=RIGHT($field $interval,8)";
193 $field = "$table_name.$date";
194 $updateBase = "UPDATE $table_name SET $table_name.$date = $table_name.$date $interval";
198 //BEGIN DATE MODIFIED IN DST WITH DATE OUT OF DST
199 $update = str_replace('PLUSMINUS', '+', $updateBase);
200 $queryInDST = $update ."
202 ($table_name.date_modified >= '{$range['start']}' OR $table_name.date_modified < '{$range['end']}' )
203 AND $field < '{$range['start']}' AND $field >= '{$range['end']}'";
205 $result = $db->query($queryInDST);
206 $count = $db->getAffectedRowCount();
207 //$display .= "$year - Records updated with date modified in DST with date out of DST: $count <br>";
209 //BEGIN DATE MODIFIED OUT DST WITH DATE IN DST
210 $update = str_replace('PLUSMINUS', '-', $updateBase);
211 $queryOutDST = $update ."
213 ($table_name.date_modified < '{$range['start']}' AND $table_name.date_modified >= '{$range['end']}' )
215 ($field >= '{$range['start']}' OR $field < '{$range['end']}' )";
221 $result = $db->query($queryOutDST);
222 $count = $db->getAffectedRowCount();
223 //$display .= "$year - Records updated with date modified out of DST with date in DST: $count <br>";
226 } // end outer forloop
231 $display .= "<br><b>".$mod_strings['LBL_DST_FIX_DONE_DESC']."</b>";
232 } elseif(!$done) { // show primary screen
235 if(empty($timedate)) {
237 $timedate = new TimeDate();
240 require_once('include/timezone/timezones.php');
242 $timezoneOptions = '';
244 if(!isset($defaultServerZone)){
245 $defaultServerZone = lookupTimezone(0);
247 foreach($timezones as $key => $value) {
248 if(!empty($value['dstOffset'])) {
253 if($key == $defaultServerZone){
254 $selected = 'selected';
258 $gmtOffset = ($value['gmtOffset'] / 60);
259 if(!strstr($gmtOffset,'-')) {
260 $gmtOffset = "+".$gmtOffset;
262 $timezoneOptions .= "<option value='$key'".$selected.">".str_replace(array('_','North'), array(' ', 'N.'),$key). " (GMT".$gmtOffset.") ".$dst."</option>";
265 // descriptions and assumptions
269 <td width=\"20%\" class=\"tabDetailViewDL2\" nowrap align='right'><slot>
270 ".$mod_strings['LBL_DST_FIX_TARGET']."
272 <td class=\"tabDetailViewDF2\"><slot>
273 ".$mod_strings['LBL_APPLY_DST_FIX_DESC']."
277 <td width=\"20%\" class=\"tabDetailViewDL2\" nowrap align='right'><slot>
278 ".$mod_strings['LBL_DST_BEFORE']."
280 <td class=\"tabDetailViewDF2\"><slot>
281 ".$mod_strings['LBL_DST_BEFORE_DESC']."
285 <td width=\"20%\" class=\"tabDetailViewDL2\" nowrap align='right'><slot>
286 ".$mod_strings['LBL_DST_FIX_CONFIRM']."
288 <td class=\"tabDetailViewDF2\"><slot>
289 ".$mod_strings['LBL_DST_FIX_CONFIRM_DESC']."
293 <td width=\"20%\" class=\"tabDetailViewDL2\" nowrap align='right'><slot>
296 <td class=\"tabDetailViewDF2\"><slot>
297 <table cellpadding='0' cellspacing='0' border='0'>
299 <td class=\"tabDetailViewDF2\"><slot>
300 <b>".$mod_strings['LBL_DST_CURRENT_SERVER_TIME']."</b>
302 <td class=\"tabDetailViewDF2\"><slot>
303 ".$timedate->to_display_time(date($GLOBALS['timedate']->get_db_date_time_format(), strtotime('now')), true, false)."
307 <td class=\"tabDetailViewDF2\"><slot>
308 <b>".$mod_strings['LBL_DST_CURRENT_SERVER_TIME_ZONE']."</b>
310 <td class=\"tabDetailViewDF2\"><slot>
315 <td class=\"tabDetailViewDF2\"><slot>
316 <b>".$mod_strings['LBL_DST_CURRENT_SERVER_TIME_ZONE_LOCALE']."</b>
318 <td class=\"tabDetailViewDF2\"><slot>
319 <select name='server_timezone'>".$timezoneOptions."</select><br>
325 } else { // fix has been applied - don't want to allow a 2nd pass
326 $display = $mod_strings['LBL_DST_FIX_DONE_DESC'];
327 $disabled = 'DISABLED';
328 $confirmed = 'false';
331 if(!empty($_POST['upgrade'])){
332 // enter row in versions table
333 $qDst = "INSERT INTO versions VALUES ('".create_guid()."', 0, '".gmdate($GLOBALS['timedate']->get_db_date_time_format(), strtotime('now'))."', '".gmdate($GLOBALS['timedate']->get_db_date_time_format(), strtotime('now'))."', '".$current_user->id."', '".$current_user->id."', 'DST Fix', '3.5.1b', '3.5.1b')";
334 $qRes = $db->query($qDst);
335 // record server's time zone locale for future upgrades
336 $qSTZ = "INSERT INTO config VALUES ('Update', 'server_timezone', '".$_REQUEST['server_timezone']."')";
337 $rSTZ = $db->query($qSTZ);
338 if(empty($_REQUEST['confirmed']) || $_REQUEST['confirmed'] == 'false') {
339 $display = $mod_strings['LBL_DST_FIX_DONE_DESC'];
340 $disabled = 'DISABLED';
341 $confirmed = 'false';
343 unset($_SESSION['GMTO']);
348 echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_APPLY_DST_FIX'], true);
350 if(empty($disabled)){
353 <table cellspacing="<?php echo $gridline;?>" class="other view">
355 <td scope="row" width="20%">
356 <slot><?php echo $mod_strings['LBL_DST_FIX_USER']; ?></slot>
360 <?php echo $mod_strings['LBL_DST_FIX_USER_TZ']; ?><br>
361 <input type='button' class='button' value='<?php echo $mod_strings['LBL_DST_SET_USER_TZ']; ?>' onclick='document.location.href="index.php?module=Administration&action=updateTimezonePrefs"'>
368 <form name='DstFix' action='index.php' method='POST'>
369 <input type='hidden' name='module' value='Administration'>
370 <input type='hidden' name='action' value='DstFix'>
372 if(empty($disabled)){
373 echo "<h2>Step 2:</h2>";
376 <table cellspacing="<?php echo $gridline;?>" class="other view">
379 if(empty($disabled)){
382 <td scope="row" width="20%">
383 <slot><?php echo $mod_strings['LBL_DST_UPGRADE']; ?></slot>
387 <input type='checkbox' name='confirmed' value='true' checked="checked" />
388 <?php echo $mod_strings['LBL_DST_APPLY_FIX']; ?>
394 <td scope="row" width="20%"></td>
398 if(empty($disabled)){
399 echo "<input ".$disabled." title='".$mod_strings['LBL_APPLY_DST_FIX']."' accessKey='".$app_strings['LBL_SAVE_BUTTON_KEY']."' class=\"button\" onclick=\"this.form.action.value='DstFix';\" type=\"submit\" name=\"upgrade\" value='".$mod_strings['LBL_APPLY_DST_FIX']."' >";
401 echo "<input title='".$app_strings['LBL_DONE_BUTTON_TITLE']."' accessKey='".$app_strings['LBL_DONE_BUTTON_KEY']."' class=\"button\" onclick=\"this.form.action.value='Upgrade'; this.form.module.value='Administration';\" type=\"submit\" name=\"done\" value='".$app_strings['LBL_DONE_BUTTON_LABEL']."'>";