diff --git a/.gitignore b/.gitignore index 0ead00db35..29ffc02c56 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ config/my.php www/data/ tools/* release/* +tmp/* tmp/extensions/* tmp/log/* tmp/model/* diff --git a/module/api/control.php b/module/api/control.php index b2d41da0eb..c5e73773da 100644 --- a/module/api/control.php +++ b/module/api/control.php @@ -91,14 +91,14 @@ class api extends control /** * Query sql; * - * @param string $sql this sql is base64 encode. + * @param string $keyField * @access public * @return void */ - public function query($sql) + public function sql($keyField = '') { - $sql = base64_decode($sql); - $this->view->results = $this->api->query($sql); + $sql = isset($_POST['sql']) ? $this->post->sql : ''; + $this->view->results = $this->api->sql($sql, $keyField); die($this->display()); } } diff --git a/module/api/lang/en.php b/module/api/lang/en.php index b962cd27cb..ee08f8936b 100644 --- a/module/api/lang/en.php +++ b/module/api/lang/en.php @@ -12,7 +12,7 @@ $lang->api = new stdclass(); $lang->api->common = 'API'; $lang->api->getModel = 'Super Model API'; -$lang->api->query = 'SQL Query API'; +$lang->api->sql = 'SQL Query API'; $lang->api->position = 'Position'; $lang->api->startLine = "%s, line %s"; diff --git a/module/api/lang/zh-cn.php b/module/api/lang/zh-cn.php index d0db3ddb83..54c2381342 100644 --- a/module/api/lang/zh-cn.php +++ b/module/api/lang/zh-cn.php @@ -12,7 +12,7 @@ $lang->api = new stdclass(); $lang->api->common = 'API接口'; $lang->api->getModel = '超级model调用接口'; -$lang->api->query = 'SQL查询接口'; +$lang->api->sql = 'SQL查询接口'; $lang->api->position = '位置'; $lang->api->startLine = "%s,%s行"; diff --git a/module/api/model.php b/module/api/model.php index 56e02db85e..537bf05944 100644 --- a/module/api/model.php +++ b/module/api/model.php @@ -88,40 +88,35 @@ class apiModel extends model * Query sql. * * @param string $sql + * @param string $keyField * @access public * @return array */ - public function query($sql) + public function sql($sql, $keyField = '') { $sql = trim($sql); - $sqls = explode(';', $sql); + if(strpos($sql, ';') !== false) $sql = substr($sql, 0, strpos($sql, ';')); + a($sql); + if(empty($sql)) return ''; - $results = array(); - foreach($sqls as $sql) + if(stripos($sql, 'select ') !== 0) { - $sql = trim($sql); - if(empty($sql)) continue; - - $result = new stdclass(); - $result->sql = $sql; - $result->result = ''; - if(stripos($sql, 'select ') !== 0) + return $this->lang->api->error->onlySelect; + } + else + { + try { - $result->result = $this->lang->api->error->onlySelect; + $stmt = $this->dao->query($sql); + if(empty($keyField)) return $stmt->fetchAll(); + $rows = array(); + while($row = $stmt->fetch()) $rows[$row->$keyField] = $row; + return $rows; } - else + catch(PDOException $e) { - try - { - $result->result = $this->dao->query($sql)->fetchAll(); - } - catch(PDOException $e) - { - $result->result = $e->getMessage(); - } + return $e->getMessage(); } - $results[] = $result; } - return $results; } } diff --git a/module/backup/control.php b/module/backup/control.php index cb5769e988..bc127c9d5f 100644 --- a/module/backup/control.php +++ b/module/backup/control.php @@ -11,11 +11,17 @@ */ class backup extends control { + /** + * __construct + * + * @access public + * @return void + */ public function __construct() { parent::__construct(); - $this->backupPath = $this->app->getCacheRoot() . 'backup/'; + $this->backupPath = $this->app->getTmpRoot() . 'backup/'; if(!is_dir($this->backupPath)) { if(!mkdir($this->backupPath, 0777, true)) $this->view->error = sprintf($this->lang->backup->error->noWritable, dirname($this->backupPath)); @@ -26,6 +32,12 @@ class backup extends control } } + /** + * Index + * + * @access public + * @return void + */ public function index() { $backups = array(); @@ -37,9 +49,9 @@ class backup extends control $backupFile->time = filemtime($file); $backupFile->name = str_replace('.sql.php', '', basename($file)); $backupFile->files[$file] = filesize($file); - if(file_exists($this->backupPath . $backupFile->name . '.file.zip')) + if(file_exists($this->backupPath . $backupFile->name . '.file.zip.php')) { - $backupFile->files[$this->backupPath . $backupFile->name . '.file.zip'] = filesize($this->backupPath . $backupFile->name . '.file.zip'); + $backupFile->files[$this->backupPath . $backupFile->name . '.file.zip.php'] = filesize($this->backupPath . $backupFile->name . '.file.zip.php'); } $backups[$backupFile->name] = $backupFile; @@ -53,6 +65,12 @@ class backup extends control $this->display(); } + /** + * Backup + * + * @access public + * @return void + */ public function backup() { set_time_limit(0); @@ -66,26 +84,34 @@ class backup extends control $fp = fopen($this->backupPath . $fileName . '.sql.php', 'r'); $tmp = fopen($this->backupPath . $fileName . '.sql.php.tmp', 'w'); - fwrite($tmp, "\n"); + fwrite($tmp, "#;\n"); while(($buffer = fgets($fp)) !== false) fwrite($tmp, $buffer); - fclose($tmp); fclose($fp); + fclose($tmp); rename($this->backupPath . $fileName . '.sql.php.tmp', $this->backupPath . $fileName . '.sql.php'); - if(extension_loaded('zlib')) - { - $result = $this->backup->backFile($this->backupPath . $fileName . '.file.zip'); - if(!$result->result) - { - echo js::alert(sprintf($this->lang->backup->error->backupFile, $result->error)); - die(js::reload('parent')); - } - } + if(extension_loaded('zlib')) + { + $result = $this->backup->backFile($this->backupPath . $fileName . '.file.zip.php'); + if(!$result->result) + { + echo js::alert(sprintf($this->lang->backup->error->backupFile, $result->error)); + die(js::reload('parent')); + } + } echo js::alert($this->lang->backup->success->backup); die(js::reload('parent')); } + /** + * Restore + * + * @param string $fileName + * @param string $confirm + * @access public + * @return void + */ public function restore($fileName, $confirm = 'no') { if($confirm == 'no') @@ -94,28 +120,19 @@ class backup extends control } set_time_limit(0); - $fp = fopen($this->backupPath . $fileName . '.sql.php', 'r'); - $tmp = fopen($this->backupPath . $fileName . '.sql', 'w'); - $line = 0; - while(($buffer = fgets($fp)) !== false) - { - $line++; - if($line == 1) continue; - fwrite($tmp, $buffer); - } - fclose($tmp); - fclose($fp); - $result = $this->backup->restoreSQL($this->backupPath . $fileName . '.sql'); - unlink($this->backupPath . $fileName . '.sql'); + + /* Restore database. */ + $result = $this->backup->restoreSQL($this->backupPath . $fileName . '.sql.php'); if(!$result->result) { echo js::alert(sprintf($this->lang->backup->error->restoreSQL, $result->error)); die(js::reload('parent')); } - if(file_exists($this->backupPath . $fileName . '.file.zip')) + /* Restore attatchments. */ + if(file_exists($this->backupPath . $fileName . '.file.zip.php')) { - $result = $this->backup->restoreFile($this->backupPath . $fileName . '.file.zip'); + $result = $this->backup->restoreFile($this->backupPath . $fileName . '.file.zip.php'); if(!$result->result) { echo js::alert(sprintf($this->lang->backup->error->restoreFile, $result->error)); @@ -126,19 +143,28 @@ class backup extends control die(js::reload('parent')); } + /** + * Delete + * + * @param string $fileName + * @param string $confirm + * @access public + * @return void + */ public function delete($fileName, $confirm = 'no') { - if($confirm == 'no') - { - die(js::confirm($this->lang->backup->confirmDelete, inlink('delete', "fileName=$fileName&confirm=yes"))); - } + if($confirm == 'no') die(js::confirm($this->lang->backup->confirmDelete, inlink('delete', "fileName=$fileName&confirm=yes"))); + + /* Delete database file. */ if(file_exists($this->backupPath . $fileName . '.sql.php') and !unlink($this->backupPath . $fileName . '.sql.php')) { die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.sql.php'))); } - if(file_exists($this->backupPath . $fileName . '.file.zip') and !unlink($this->backupPath . $fileName . '.file.zip')) + + /* Delete attatchments file. */ + if(file_exists($this->backupPath . $fileName . '.file.zip.php') and !unlink($this->backupPath . $fileName . '.file.zip.php')) { - die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.file.zip'))); + die(js::alert(sprintf($this->lang->backup->error->noDelete, $this->backupPath . $fileName . '.file.zip.php'))); } die(js::reload('parent')); diff --git a/module/backup/lang/en.php b/module/backup/lang/en.php index 50e77955ed..696369b997 100644 --- a/module/backup/lang/en.php +++ b/module/backup/lang/en.php @@ -1,5 +1,5 @@ backup->common = 'Backup and restore'; +$lang->backup->common = 'Backup'; $lang->backup->index = 'Index'; $lang->backup->history = 'History'; $lang->backup->delete = 'Delete'; diff --git a/module/backup/lang/zh-cn.php b/module/backup/lang/zh-cn.php index 692687958a..eeb7802946 100644 --- a/module/backup/lang/zh-cn.php +++ b/module/backup/lang/zh-cn.php @@ -1,6 +1,6 @@ backup->common = '备份还原'; -$lang->backup->index = '备份还原首页'; +$lang->backup->common = '备份'; +$lang->backup->index = '备份首页'; $lang->backup->history = '备份历史'; $lang->backup->delete = '删除备份'; $lang->backup->backup = '备份'; diff --git a/module/backup/model.php b/module/backup/model.php index 0a1ebfff35..1de5e795fd 100644 --- a/module/backup/model.php +++ b/module/backup/model.php @@ -11,12 +11,26 @@ */ class backupModel extends model { + /** + * Backup SQL + * + * @param string $backupFile + * @access public + * @return object + */ public function backSQL($backupFile) { $zdb = $this->app->loadClass('zdb'); return $zdb->dump($backupFile); } + /** + * Backup file. + * + * @param string $backupFile + * @access public + * @return object + */ public function backFile($backupFile) { $return = new stdclass(); @@ -35,12 +49,26 @@ class backupModel extends model return $return; } + /** + * Restore SQL + * + * @param string $backupFile + * @access public + * @return object + */ public function restoreSQL($backupFile) { $zdb = $this->app->loadClass('zdb'); return $zdb->import($backupFile); } + /** + * Restore File + * + * @param string $backupFile + * @access public + * @return object + */ public function restoreFile($backupFile) { $return = new stdclass(); diff --git a/module/backup/view/index.html.php b/module/backup/view/index.html.php index 162083b88c..9377204277 100644 --- a/module/backup/view/index.html.php +++ b/module/backup/view/index.html.php @@ -28,7 +28,6 @@ backup->time?> - backup->name?> backup->files?> backup->size?> actions?> @@ -42,7 +41,6 @@ 1) echo "rowspan='$rowspan'"?>>time);?> - 1) echo "rowspan='$rowspan'"?>>name;?> = 1024 ? round($size / 1024 / 1024, 2) . 'MB' : round($size / 1024, 2) . 'KB';?> diff --git a/module/common/lang/en.php b/module/common/lang/en.php index e624d8d195..d78cd935a5 100644 --- a/module/common/lang/en.php +++ b/module/common/lang/en.php @@ -281,8 +281,8 @@ $lang->admin->menu->extension = array('link' => 'Extension|extension|browse', 's $lang->admin->menu->custom = array('link' => 'Custom|custom|index', 'subModule' => 'custom'); $lang->admin->menu->mail = array('link' => 'Email|mail|index', 'subModule' => 'mail'); $lang->admin->menu->convert = array('link' => 'Import|convert|index', 'subModule' => 'convert'); +$lang->admin->menu->backup = array('link' => 'Backup|backup|index', 'subModule' => 'backup'); $lang->admin->menu->trashes = array('link' => 'Trash|action|trash', 'subModule' => 'action'); -$lang->admin->menu->backup = array('link' => 'Backup and restore|backup|index', 'subModule' => 'backup'); $lang->convert = new stdclass(); $lang->upgrade = new stdclass(); diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index e5acfefbb1..dda2df0c07 100644 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -281,8 +281,8 @@ $lang->admin->menu->extension = array('link' => '扩展|extension|browse', 'subM $lang->admin->menu->custom = array('link' => '自定义|custom|index', 'subModule' => 'custom'); $lang->admin->menu->mail = array('link' => '发信|mail|index', 'subModule' => 'mail'); $lang->admin->menu->convert = array('link' => '导入|convert|index', 'subModule' => 'convert'); +$lang->admin->menu->backup = array('link' => '备份|backup|index', 'subModule' => 'backup'); $lang->admin->menu->trashes = array('link' => '回收站|action|trash', 'subModule' => 'action'); -$lang->admin->menu->backup = array('link' => '备份还原|backup|index', 'subModule' => 'backup'); $lang->convert = new stdclass(); $lang->upgrade = new stdclass(); diff --git a/module/dept/control.php b/module/dept/control.php index f4dffef793..b5de6a8af8 100644 --- a/module/dept/control.php +++ b/module/dept/control.php @@ -86,20 +86,16 @@ class dept extends control if(!empty($_POST)) { $this->dept->update($deptID); - echo js::alert($this->lang->dept->successSave); - die(js::reload('parent')); + die(js::alert($this->lang->dept->successSave) . js::reload('parent')); } $dept = $this->dept->getById($deptID); - $users = $this->dept->getUsers('0' . $dept->path); - - $userPairs = array(); - foreach($users as $user) $userPairs[$user->account] = empty($user->realname) ? $user->account : $user->realname; + $users = $this->loadModel('user')->getPairs('nodeleted|noletter|noclosed'); $this->view->optionMenu = $this->dept->getOptionMenu(); $this->view->dept = $dept; - $this->view->users = $userPairs; + $this->view->users = $users; /* Remove self and childs from the $optionMenu. Because it's parent can't be self or childs. */ $childs = $this->dept->getAllChildId($deptID); diff --git a/module/release/lang/zh-cn.php b/module/release/lang/zh-cn.php index c6664c17a2..f6a6ddbe8d 100644 --- a/module/release/lang/zh-cn.php +++ b/module/release/lang/zh-cn.php @@ -39,9 +39,9 @@ $lang->release->linkStories = '相关需求'; $lang->release->unlinkStory = '移除需求'; $lang->release->linkBugs = '相关Bug'; $lang->release->unlinkBug = '移除Bug'; -$lang->release->stories = '已完成的需求'; -$lang->release->bugs = '已解决的Bug'; -$lang->release->generatedBugs = '遗留的Bug'; +$lang->release->stories = '已完成需求'; +$lang->release->bugs = '已解决Bug'; +$lang->release->generatedBugs = '遗留Bug'; $lang->release->finishStories = '本次共完成 %s 个需求'; $lang->release->resolvedBugs = '本次共解决 %s 个Bug'; $lang->release->createdBugs = '本次共遗留 %s 个Bug';