diff --git a/trunk/module/search/control.php b/trunk/module/search/control.php index 05d5a12afe..a03ba529f0 100644 --- a/trunk/module/search/control.php +++ b/trunk/module/search/control.php @@ -23,7 +23,7 @@ */ class search extends control { - public function buildForm($module, $searchFields, $fieldParams, $actionURL) + public function buildForm($module, $searchFields, $fieldParams, $actionURL, $queryID = 0) { $this->search->initSession($module, $searchFields, $fieldParams); @@ -32,6 +32,8 @@ class search extends control $this->view->searchFields = $searchFields; $this->view->actionURL = $actionURL; $this->view->fieldParams = $this->search->setDefaultParams($searchFields, $fieldParams); + $this->view->queries = $this->search->getQueryPairs($module); + $this->view->queryID = $queryID; $this->display(); } @@ -40,4 +42,17 @@ class search extends control $this->search->buildQuery(); die(js::locate($this->post->actionURL, 'parent')); } + + public function saveQuery() + { + $this->search->saveQuery(); + if(dao::isError()) die(js::error(dao::getError())); + die('success'); + } + + public function deleteQuery($queryID) + { + $this->dao->delete()->from(TABLE_USERQUERY)->where('id')->eq($queryID)->andWhere('account')->eq($this->app->user->account)->exec(); + die(js::reload('parent')); + } } diff --git a/trunk/module/search/lang/zh-cn.php b/trunk/module/search/lang/zh-cn.php index 0521adb665..59dbf38f90 100644 --- a/trunk/module/search/lang/zh-cn.php +++ b/trunk/module/search/lang/zh-cn.php @@ -22,7 +22,7 @@ * @link http://www.zentaoms.com */ $lang->search->common = '搜索'; -$lang->search->reset = '重填'; +$lang->search->reset = '重置'; $lang->search->more = '更多'; $lang->search->lite = '简洁'; $lang->search->saveQuery = '保存'; @@ -31,16 +31,23 @@ $lang->search->group1 = '第一组'; $lang->search->group2 = '第二组'; $lang->search->buildForm = '搜索表单'; $lang->search->buildQuery= '执行搜索'; +$lang->search->saveQuery = '保存'; +$lang->search->setQueryTitle = '请输入查询标题(保存之前请先查询):'; -$lang->search->operators['='] = '等于'; -$lang->search->operators['!='] = '不等于'; -$lang->search->operators['>'] = '大于'; -$lang->search->operators['>='] = '大于等于'; -$lang->search->operators['<'] = '小于'; -$lang->search->operators['<='] = '小于等于'; +$lang->search->operators['='] = '='; +$lang->search->operators['!='] = '!='; +$lang->search->operators['>'] = '>'; +$lang->search->operators['>='] = '>='; +$lang->search->operators['<'] = '<'; +$lang->search->operators['<='] = '<='; $lang->search->operators['include'] = '包含'; $lang->search->andor['and'] = '并且'; $lang->search->andor['or'] = '或者'; $lang->search->null = '空'; + +$lang->userquery->title = '查询标题'; +$lang->userquery->myQueries = '我的查询'; +$lang->userquery->execut = '执行'; +$lang->userquery->delete = '删除'; diff --git a/trunk/module/search/model.php b/trunk/module/search/model.php index 02cb76acc4..9a4d20c266 100644 --- a/trunk/module/search/model.php +++ b/trunk/module/search/model.php @@ -125,4 +125,47 @@ class searchModel extends model } return $params; } + + /* 获得某一个查询。*/ + public function getQuery($queryID) + { + $query = $this->dao->findByID($queryID)->from(TABLE_USERQUERY)->fetch(); + if(!$query) return false; + $query->form = unserialize($query->form); + return $query; + } + + /* 保存查询。*/ + public function saveQuery() + { + $sqlVar = $this->post->module . 'Query'; + $formVar = $this->post->module . 'Form'; + $query = fixer::input('post') + ->specialChars('title') + ->add('account', $this->app->user->account) + ->add('form', serialize($this->session->$formVar)) + ->add('sql', $this->session->$sqlVar) + ->get(); + $this->dao->insert(TABLE_USERQUERY)->data($query)->autoCheck()->check('title', 'notempty')->exec(); + } + + /* 获得用户查询对。*/ + public function getQueryPairs($module) + { + $queries = $this->dao->select('id, title') + ->from(TABLE_USERQUERY) + ->where('account')->eq($this->app->user->account) + ->andWhere('module')->eq($module) + ->orderBy('id_asc') + ->fetchPairs(); + if(!$queries) return array('' => $this->lang->search->myQuery); + $i = ord('A'); + foreach($queries as $key => $value) + { + $queries[$key] = chr($i) . ': ' . $value; + $i ++; + } + $queries = array('' => $this->lang->search->myQuery) + $queries; + return $queries; + } } diff --git a/trunk/module/search/view/buildform.html.php b/trunk/module/search/view/buildform.html.php index f5d8e2f2ad..8229d6c2de 100644 --- a/trunk/module/search/view/buildform.html.php +++ b/trunk/module/search/view/buildform.html.php @@ -22,10 +22,18 @@ * @link http://www.zentaoms.com */ ?> - +
| search->common;?> | -+ |
" . html::select("andOr$fieldNO", $lang->search->andor, $formSession["andOr$fieldNO"]); /* 打印字段。*/ @@ -126,8 +169,8 @@ foreach($fieldParams as $fieldName => $param) ?> |
- + |
" . html::select("andOr$fieldNO", $lang->search->andor, $formSession["andOr$fieldNO"]); /* 打印字段。*/ @@ -168,22 +211,25 @@ foreach($fieldParams as $fieldName => $param) echo html::hidden('actionURL', $actionURL); echo html::hidden('groupItems', $groupItems); echo html::submitButton($lang->search->common); - echo html::resetButton($lang->search->reset); - //echo html::submitButton($lang->search->saveQuery); + echo html::commonButton($lang->search->reset, 'onclick=resetForm();'); + echo html::commonButton($lang->search->saveQuery, 'onclick=saveQuery()'); ?> |
+ + + | search->more;?> search->lite;?> - + | -
|---|