+ add the feature of save query.
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = '删除';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,18 @@
|
||||
* @link http://www.zentaoms.com
|
||||
*/
|
||||
?>
|
||||
<style>.helplink{display:none}</style>
|
||||
<style>
|
||||
.helplink {display:none}
|
||||
.button-s, .button-r, .button-c {padding:3px}
|
||||
.select-1 {width:80%}
|
||||
</style>
|
||||
<script language='Javascript'>
|
||||
var params = <?php echo json_encode($fieldParams);?>;
|
||||
var groupItems = <?php echo $config->search->groupItems;?>;
|
||||
|
||||
var params = <?php echo json_encode($fieldParams);?>;
|
||||
var groupItems = <?php echo $config->search->groupItems;?>;
|
||||
var setQueryTitle = '<?php echo $lang->search->setQueryTitle;?>';
|
||||
var module = '<?php echo $module;?>';
|
||||
var actionURL = '<?php echo $actionURL;?>';
|
||||
|
||||
/* 根据字段的参数,重新设置它对应的操作符和值。*/
|
||||
function setField(fieldName, fieldNO)
|
||||
@@ -35,6 +43,15 @@ function setField(fieldName, fieldNO)
|
||||
$('#valueBox' + fieldNO).html(htmlString);
|
||||
}
|
||||
|
||||
/* 重置表单。*/
|
||||
function resetForm()
|
||||
{
|
||||
for(i = 1; i <= groupItems * 2; i ++)
|
||||
{
|
||||
$('#value' + i).val('');
|
||||
}
|
||||
}
|
||||
|
||||
/* 显示更多的搜索选项。*/
|
||||
function showmore()
|
||||
{
|
||||
@@ -48,9 +65,7 @@ function showmore()
|
||||
|
||||
$('#searchmore').addClass('hidden');
|
||||
$('#searchlite').removeClass('hidden');
|
||||
$('#searchgroup1').removeClass('hidden');
|
||||
$('#searchgroup2').removeClass('hidden');
|
||||
$('#searchType').val('more');
|
||||
$('#formType').val('more');
|
||||
}
|
||||
|
||||
/* 显示简洁的搜索选项。*/
|
||||
@@ -66,10 +81,38 @@ function showlite()
|
||||
}
|
||||
$('#searchmore').removeClass('hidden');
|
||||
$('#searchlite').addClass('hidden');
|
||||
$('#searchgroup1').addClass('hidden');
|
||||
$('#searchgroup2').addClass('hidden');
|
||||
$('#searchType').val('lite');
|
||||
$('#formType').val('lite');
|
||||
}
|
||||
|
||||
/* 保存用户设定的查询条件。*/
|
||||
function saveQuery()
|
||||
{
|
||||
jPrompt(setQueryTitle, '', '', function(r)
|
||||
{
|
||||
if(!r) return;
|
||||
saveQueryLink = createLink('search', 'saveQuery');
|
||||
$.post(saveQueryLink, {title: r, module: module}, function(data)
|
||||
{
|
||||
if(data == 'success') location.reload();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/* 执行用户选中的query。*/
|
||||
function executeQuery(queryID)
|
||||
{
|
||||
if(!queryID) return;
|
||||
location.href = actionURL.replace('queryID', queryID);
|
||||
}
|
||||
|
||||
/* 删除Query。*/
|
||||
function deleteQuery()
|
||||
{
|
||||
queryID = $('#queryID').val();
|
||||
if(!queryID) return;
|
||||
hiddenwin.location.href = createLink('search', 'deleteQuery', 'queryID=' + queryID);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<div class='hidden'>
|
||||
@@ -88,7 +131,7 @@ foreach($fieldParams as $fieldName => $param)
|
||||
<table class='table-1'>
|
||||
<tr valign='middle'>
|
||||
<th width='10' class='bg-gray'><?php echo $lang->search->common;?></th>
|
||||
<td class='a-right' width='200px'>
|
||||
<td class='a-right'>
|
||||
<nobr>
|
||||
<?php
|
||||
$formSessionName = $module . 'Form';
|
||||
@@ -105,7 +148,7 @@ foreach($fieldParams as $fieldName => $param)
|
||||
$param = $fieldParams[$currentField];
|
||||
|
||||
/* 打印and or。*/
|
||||
if($i == 1) echo "<span id='searchgroup1' class='hidden'><strong>{$lang->search->group1}</strong></span>" . html::hidden("andOr$fieldNO", 'AND');
|
||||
if($i == 1) echo "<span id='searchgroup1'><strong>{$lang->search->group1}</strong></span>" . html::hidden("andOr$fieldNO", 'AND');
|
||||
if($i > 1) echo "<br />" . html::select("andOr$fieldNO", $lang->search->andor, $formSession["andOr$fieldNO"]);
|
||||
|
||||
/* 打印字段。*/
|
||||
@@ -126,8 +169,8 @@ foreach($fieldParams as $fieldName => $param)
|
||||
?>
|
||||
</nobr>
|
||||
</td>
|
||||
<td class='a-center' width='20'><nobr><?php echo html::select('groupAndOr', $lang->search->andor, $formSession['groupAndOr'])?></nobr></td>
|
||||
<td class='a-right' width='200'>
|
||||
<td class='a-center' width='60'><nobr><?php echo html::select('groupAndOr', $lang->search->andor, $formSession['groupAndOr'])?></nobr></td>
|
||||
<td class='a-right'>
|
||||
<nobr>
|
||||
<?php
|
||||
for($i = 1; $i <= $groupItems; $i ++)
|
||||
@@ -140,7 +183,7 @@ foreach($fieldParams as $fieldName => $param)
|
||||
$param = $fieldParams[$currentField];
|
||||
|
||||
/* 打印and or。*/
|
||||
if($i == 1) echo "<span id='searchgroup2' class='hidden'><strong>{$lang->search->group2}</strong></span>" . html::hidden("andOr$fieldNO", 'AND');
|
||||
if($i == 1) echo "<span id='searchgroup2'><strong>{$lang->search->group2}</strong></span>" . html::hidden("andOr$fieldNO", 'AND');
|
||||
if($i > 1) echo "<br />" . 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()');
|
||||
?>
|
||||
</nobr>
|
||||
</td>
|
||||
<td width='250' class='a-center'>
|
||||
<?php
|
||||
echo html::select('queryID', $queries, $queryID, 'class=select-1 onchange=executeQuery(this.value)');
|
||||
if(common::hasPriv('search', 'deleteQuery')) echo html::commonButton(' x ', 'onclick=deleteQuery();');
|
||||
?>
|
||||
</td>
|
||||
<th width='10' class='bg-gray' style='cursor:pointer; padding:0'>
|
||||
<span id='searchmore' onclick='showmore()' style='width:100%; height:100%'><?php echo $lang->search->more;?></span>
|
||||
<span id='searchlite' onclick='showlite()' style='width:100%; height:100%' class='hidden'><?php echo $lang->search->lite;?></span>
|
||||
<?php echo html::hidden('searchType', 'lite');?>
|
||||
<?php echo html::hidden('formType', 'lite');?>
|
||||
</th>
|
||||
<!--<td><?php echo $lang->search->myQuery; ?></td>-->
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<script language='Javascript'>
|
||||
<?php
|
||||
if(isset($formSession['searchType'])) echo "show{$formSession['searchType']}()";
|
||||
?>
|
||||
<?php if(isset($formSession['formType'])) echo "show{$formSession['formType']}()";?>
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user