diff --git a/include/class.config.php b/include/class.config.php index cc9b497682097d0e622dbbd410b0a4f5b0fae601..f7eafc4a47074c856872754fd954811b36376ef3 100644 --- a/include/class.config.php +++ b/include/class.config.php @@ -18,9 +18,8 @@ require_once(INCLUDE_DIR.'class.email.php'); class Config { - var $id=0; - var $mysqltzoffset=0; - var $config=array(); + var $id = 0; + var $config = array(); var $defaultDept; //Default Department var $defaultSLA; //Default SLA @@ -33,18 +32,35 @@ class Config { } function load($id=0) { + if(!$id && !($id=$this->getId())) return false; $sql='SELECT * FROM '.CONFIG_TABLE .' WHERE id='.db_input($id); + if(!($res=db_query($sql)) || !db_num_rows($res)) return false; - $this->config=db_fetch_array($res); - $this->id=$this->config['id']; - $this->setMysqlTZ(db_timezone()); + $this->config = db_fetch_array($res); + $this->id = $this->config['id']; + //Figure out DB timezone + if(($dbtz=db_timezone())) { + if($dbtz=='SYSTEM') + $this->config['dbtz_offset'] = preg_replace('/([+-]\d{2})(\d{2})/', '\1', date('O')); + else + $this->config['dbtz_offset'] = preg_replace('/([+-]\d{2})(:)(\d{2})/', '\1', $dbtz); + } else { + $this->config['dbtz_offset'] = 0; + } + + //Get the default time zone + // We can't JOIN timezone table above due to upgrade support. + if($this->config['default_timezone_id']) + $this->config['tz_offset'] = Timezone::getOffsetById($this->config['default_timezone_id']); + else + $this->config['tz_offset'] = 0; return true; } @@ -92,17 +108,9 @@ class Config { return null; } - - function setMysqlTZ($tz) { - //TODO: Combine the 2 replace regex - if($tz=='SYSTEM') - $this->mysqltzoffset=preg_replace('/([+-]\d{2})(\d{2})/','\1',date('O')); - else - $this->mysqltzoffset=preg_replace('/([+-]\d{2})(:)(\d{2})/','\1',$tz); - } - function getMysqlTZoffset() { - return $this->mysqltzoffset; + function getDBTZoffset() { + return $this->config['dbtz_offset']; } /* Date & Time Formats */ @@ -149,7 +157,7 @@ class Config { } function getTZOffset() { - return $this->config['timezone_offset']; + return $this->config['tz_offset']; } function getPageSize() { diff --git a/include/class.misc.php b/include/class.misc.php index 9fd6744ba8913061a5e34c2b10bf705216d286fa..8149a1fce37ea3a26106f6bb217d1c92cc17395e 100644 --- a/include/class.misc.php +++ b/include/class.misc.php @@ -35,7 +35,7 @@ class Misc { if(!$var) return; $dbtime=is_int($var)?$var:strtotime($var); - return $dbtime-($cfg->getMysqlTZoffset()*3600); + return $dbtime-($cfg->getDBTZoffset()*3600); } //Take user time or gmtime and return db (mysql) time. @@ -50,7 +50,7 @@ class Misc { $time=$time-($offset*3600); } //gm to db time - return $time+($cfg->getMysqlTZoffset()*3600); + return $time+($cfg->getDBTZoffset()*3600); } /*Helper get GM time based on timezone offset*/ diff --git a/include/staff/settings-dates.inc.php b/include/staff/settings-dates.inc.php index f8085cfc3193342bf1bd6c66df87b48d9dcf5edd..9aa493a7573f535b2d49e087158625c8173b0af7 100644 --- a/include/staff/settings-dates.inc.php +++ b/include/staff/settings-dates.inc.php @@ -1,5 +1,6 @@ <?php $gmtime=Misc::gmtime(); + ?> <form action="settings.php?t=dates" method="post" id="save"> <?php csrf_token(); ?> @@ -18,24 +19,24 @@ $gmtime=Misc::gmtime(); <td> <input type="text" name="time_format" value="<?php echo $config['time_format']; ?>"> <font class="error">* <?php echo $errors['time_format']; ?></font> - <em><?php echo Format::date($config['time_format'],$gmtime,$config['timezone_offset'],$config['enable_daylight_saving']); ?></em></td> + <em><?php echo Format::date($config['time_format'],$gmtime,$config['tz_offset'],$config['enable_daylight_saving']); ?></em></td> </tr> <tr><td width="220" class="required">Date Format:</td> <td><input type="text" name="date_format" value="<?php echo $config['date_format']; ?>"> <font class="error">* <?php echo $errors['date_format']; ?></font> - <em><?php echo Format::date($config['date_format'],$gmtime,$config['timezone_offset'],$config['enable_daylight_saving']); ?></em> + <em><?php echo Format::date($config['date_format'],$gmtime,$config['tz_offset'],$config['enable_daylight_saving']); ?></em> </td> </tr> <tr><td width="220" class="required">Date & Time Format:</td> <td><input type="text" name="datetime_format" value="<?php echo $config['datetime_format']; ?>"> <font class="error">* <?php echo $errors['datetime_format']; ?></font> - <em><?php echo Format::date($config['datetime_format'],$gmtime,$config['timezone_offset'],$config['enable_daylight_saving']); ?></em> + <em><?php echo Format::date($config['datetime_format'],$gmtime,$config['tz_offset'],$config['enable_daylight_saving']); ?></em> </td> </tr> <tr><td width="220" class="required">Day, Date & Time Format:</td> <td><input type="text" name="daydatetime_format" value="<?php echo $config['daydatetime_format']; ?>"> <font class="error">* <?php echo $errors['daydatetime_format']; ?></font> - <em><?php echo Format::date($config['daydatetime_format'],$gmtime,$config['timezone_offset'],$config['enable_daylight_saving']); ?></em> + <em><?php echo Format::date($config['daydatetime_format'],$gmtime,$config['tz_offset'],$config['enable_daylight_saving']); ?></em> </td> </tr> <tr><td width="220" class="required">Default Time Zone:</td>