Copyright (c) 2006-2015 osTicket.com.de http://www.osticket.com.de Released under the GNU General Public License WITHOUT ANY WARRANTY. See LICENSE.TXT for details. vim: expandtab sw=4 ts=4 sts=4: **********************************************************************/ class TS { var $version; var $latestVersion = 'ts1.10-2'; function __construct() { global $cfg, $errors, $msg; $this->version = $cfg->getTimesheetVersion(); // prüfen, ob timesheet installiert ist... if(!$this->version) { $install = self::install(); if($install !== TRUE) $errors['err'] = $install; else $msg .= sprintf(__('Timesheet module installed successfully. Current Version is: %s'), $this->version); } // prüfen, ob die installierte Version aktuell ist... if($this->version != $this->latestVersion) { $update = self::update(); if($update !== TRUE) $errors['err'] = $update; else $msg .= sprintf(__('Timesheet module updated successfully. Current Version is: %s'), $this->version); } } function getVersion() { return $this->version; } function updateVersion() { $sql = 'UPDATE '.CONFIG_TABLE .' SET `value`='.db_input($this->version) .' WHERE `key`="timesheet_version"'; if(db_query($sql)) return true; else return false; } function install() { $this->version = 'ts1.10-1'; $sql1 = " CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."timesheet` ( `id` int(11) unsigned NOT NULL auto_increment, `thread_id` int(11) unsigned NOT NULL, `object_id` int(11) unsigned NOT NULL, `object_type` char(1) NOT NULL, `thread_entry_id` int(11) unsigned NOT NULL, `staff_id` int(11) unsigned NOT NULL default '0', `processingTime` int(11) unsigned NOT NULL default '0', `processingTime_type_id` int(11) unsigned NOT NULL default '1', `settled` enum('1', '0') NOT NULL DEFAULT '0', `created` datetime NOT NULL, `updated` datetime NOT NULL, PRIMARY KEY (`id`), KEY `thread_entry_id` (`thread_entry_id`) ) DEFAULT CHARSET=utf8; "; if(db_query($sql1)) { $sql2 = 'INSERT INTO '.CONFIG_TABLE .' SET `namespace`="core"' .', `key`="timesheet_version"' .', value='.db_input($this->version); $updateVID = db_query($sql2); if($updateVID) return TRUE; else return sprintf(__('Timesheet module installed successfully - but config table entry couldn\'t updated. Data with key="timesheetInstalled" should be "%s"'), $this->version); } else return __('Can\'t install timesheet module').' - '.$this->version; } function update() { switch($this->version) { case 'ts-v0.1': // ist das Update auf v1.10 schon durchgeführt worden? $sql = 'SELECT * FROM '.THREAD_TABLE.' LIMIT 1'; if(!db_query($sql)) return __('Error: osTicket version is to old for this timesheet module. The upgrade may not have been successful finished. Update pending until osTicket version is 1.10 or newer'); // Update von ts-v0.1 auf ts1.10-1 $sqlNewTable = " CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."timesheet` ( `id` int(11) unsigned NOT NULL auto_increment, `thread_id` int(11) unsigned NOT NULL, `object_id` int(11) unsigned NOT NULL, `object_type` char(1) NOT NULL, `thread_entry_id` int(11) unsigned NOT NULL, `staff_id` int(11) unsigned NOT NULL default '0', `processingTime` int(11) unsigned NOT NULL default '0', `processingTime_type_id` int(11) unsigned NOT NULL default '1', `settled` enum('1', '0') NOT NULL DEFAULT '0', `created` datetime NOT NULL, `updated` datetime NOT NULL, PRIMARY KEY (`id`), KEY `thread_entry_id` (`thread_entry_id`) ) DEFAULT CHARSET=utf8; "; if(db_query($sqlNewTable)) { // Daten umziehen... $sqlOldData = ' SELECT tht.id AS thread_id, tts.id AS id, tts.ticket_id AS object_id, tts.thread_Id AS thread_entry_id, tts.staff_id, tts.processingTime, tts.type_id AS processingTime_type_id, tts.settled, tts.created, tts.updated FROM `'.TABLE_PREFIX.'ticket_timesheet` tts LEFT JOIN '.THREAD_TABLE.' tht ON (tht.object_id = tts.ticket_id AND tht.object_type = \'T\')'; if(($rows=db_query($sqlOldData)) && db_num_rows($rows)) { while ($row = mysqli_fetch_assoc($rows)) { $sqlInsert = 'INSERT INTO '.TIMESHEET_TABLE.' SET ' .' thread_id='.db_input($row['thread_id']) .' ,object_id='.db_input($row['object_id']) .' ,object_type='.db_input('T') .' ,thread_entry_id='.db_input($row['thread_entry_id']) .' ,staff_id='.db_input($row['staff_id']) .' ,processingTime='.db_input($row['processingTime']) .' ,processingTime_type_id='.db_input($row['processingTime_type_id']) .' ,settled='.db_input($row['settled']) .' ,created='.db_input($row['created']) .' ,updated='.db_input($row['updated']) ; if(db_query($sqlInsert)) { $sqlDelete = 'DELETE FROM `'.TABLE_PREFIX.'ticket_timesheet` WHERE id = '.db_input($row['id']); db_query($sqlDelete); } } // Daten sind umgezogen. Alte Tabelle löschen if(($rows=db_query($sqlOldData)) && db_num_rows($rows) == 0) { $rows=db_query('DROP TABLE `'.TABLE_PREFIX.'ticket_timesheet` '); // Update erfolgreich - timesheet-Version aktualisieren db_query('UPDATE '.CONFIG_TABLE.' SET `key` = \'timesheet_version\' WHERE `key` = \'timesheetInstalled\' '); $this->version = 'ts1.10-1'; self::updateVersion(); } else return __('Error: can\'t delete old Table from version ts-v0.1 - it\' not empty. Please reload Page to retry'); } } else return sprintf(__('Error: can\'t create new Table for timesheet module (%s) - Update from version %s'), $this->latestVersion, $this->version); case 'ts1.10-1': // Create new field timeTotal in thread table $sql = 'ALTER TABLE `'.THREAD_TABLE.'` ADD `timeTotal` INT NULL DEFAULT NULL AFTER `object_type` '; if(db_query($sql)) { $this->version = 'ts1.10-2'; self::updateVersion(); // update new Field... $sql = 'SELECT id FROM `'.THREAD_TABLE.'` WHERE timeTotal IS NULL LIMIT 100'; while(($rows=db_query($sql)) && db_num_rows($rows) > 0) { list($thread_id)=db_fetch_row($rows); self::updateTimeTotal($thread_id); } } else return __('Error: can\'t create new Field `timeTotal` in tread table'); case 'ts1.10-2': // nothing to do, we are on latest version break; default: return __('Error: no supported timesheet module version').' - '.$this->version; } // prüfen, ob aktualisierte Version die aktuellste ist if($this->version != $this->latestVersion) self::update(); else return TRUE; } function getPTinputFieldJS() { echo ' '; } private function getPTinputField() { return ' '.__('Timer').': 00:01 ('.__('h/min/sec').')
('.__('h/min').')