* adjust code.

This commit is contained in:
wangyidong
2014-12-19 01:05:41 +00:00
parent 532d22eb5e
commit 0c0f8d85a9
14 changed files with 125 additions and 81 deletions
+1
View File
@@ -2,6 +2,7 @@ config/my.php
www/data/
tools/*
release/*
tmp/*
tmp/extensions/*
tmp/log/*
tmp/model/*
+4 -4
View File
@@ -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());
}
}
+1 -1
View File
@@ -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";
+1 -1
View File
@@ -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行";
+18 -23
View File
@@ -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;
}
}
+61 -35
View File
@@ -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, "<?php die();?>\n");
fwrite($tmp, "#<?php die()?>;\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'));
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
$lang->backup->common = 'Backup and restore';
$lang->backup->common = 'Backup';
$lang->backup->index = 'Index';
$lang->backup->history = 'History';
$lang->backup->delete = 'Delete';
+2 -2
View File
@@ -1,6 +1,6 @@
<?php
$lang->backup->common = '备份还原';
$lang->backup->index = '备份还原首页';
$lang->backup->common = '备份';
$lang->backup->index = '备份首页';
$lang->backup->history = '备份历史';
$lang->backup->delete = '删除备份';
$lang->backup->backup = '备份';
+28
View File
@@ -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();
-2
View File
@@ -28,7 +28,6 @@
<thead>
<tr>
<th class='w-150px'><?php echo $lang->backup->time?></th>
<th class='w-200px'><?php echo $lang->backup->name?></th>
<th><?php echo $lang->backup->files?></th>
<th class='w-150px'><?php echo $lang->backup->size?></th>
<th class='w-80px'><?php echo $lang->actions?></th>
@@ -42,7 +41,6 @@
<tr>
<?php if($i == 0):?>
<td <?php if($rowspan > 1) echo "rowspan='$rowspan'"?>><?php echo date(DT_DATETIME1, $backupFile->time);?></td>
<td <?php if($rowspan > 1) echo "rowspan='$rowspan'"?>><?php echo $backupFile->name;?></td>
<?php endif;?>
<td class='text-left'><?php echo $file;?></td>
<td><?php echo $size / 1024 >= 1024 ? round($size / 1024 / 1024, 2) . 'MB' : round($size / 1024, 2) . 'KB';?></td>
+1 -1
View File
@@ -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();
+1 -1
View File
@@ -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();
+3 -7
View File
@@ -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);
+3 -3
View File
@@ -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';