* [MOD] Search filters stored as an object in session

* [FIX] Minor bugfixes
This commit is contained in:
nuxsmin
2015-06-21 22:45:53 +02:00
parent a3c6e4885d
commit f17e010dde
8 changed files with 356 additions and 192 deletions

View File

@@ -340,7 +340,7 @@ class AccountHistory extends AccountBase implements AccountInterface
$queryRes = DB::getResults($query, __FUNCTION__, $data);
if ($queryRes === false) {
throw new Exception(_('No se pudieron obtener los datos de la cuenta'));
throw new \Exception(_('No se pudieron obtener los datos de la cuenta'));
}
$this->setAccountUserId($queryRes->account_userId);

View File

@@ -32,41 +32,194 @@ defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'
*/
class AccountSearch
{
/**
* Constantes de ordenación
*/
const SORT_NAME = 1;
const SORT_CATEGORY = 2;
const SORT_LOGIN = 3;
const SORT_URL = 4;
const SORT_CUSTOMER = 5;
/**
* @var int El número de registros de la última consulta
*/
public static $queryNumRows;
private $_globalSearch = false;
private $_txtSearch = '';
private $_customerId = 0;
private $_categoryId = 0;
private $_sortOrder = 0;
private $_sortKey = 0;
private $_limitStart = 0;
private $_limitCount = 12;
/**
* Constructor
*/
function __construct()
{
$this->setLimitCount(Config::getValue('account_count'));
}
/**
* @return boolean
*/
public function isGlobalSearch()
{
return $this->_globalSearch;
}
/**
* @param boolean $globalSearch
*/
public function setGlobalSearch($globalSearch)
{
$this->_globalSearch = $globalSearch;
}
/**
* @return string
*/
public function getTxtSearch()
{
return $this->_txtSearch;
}
/**
* @param string $txtSearch
*/
public function setTxtSearch($txtSearch)
{
$this->_txtSearch = $txtSearch;
}
/**
* @return int
*/
public function getCustomerId()
{
return $this->_customerId;
}
/**
* @param int $customerId
*/
public function setCustomerId($customerId)
{
$this->_customerId = $customerId;
}
/**
* @return int
*/
public function getCategoryId()
{
return $this->_categoryId;
}
/**
* @param int $categoryId
*/
public function setCategoryId($categoryId)
{
$this->_categoryId = $categoryId;
}
/**
* @return int
*/
public function getSortOrder()
{
return $this->_sortOrder;
}
/**
* @param int $sortOrder
*/
public function setSortOrder($sortOrder)
{
$this->_sortOrder = $sortOrder;
}
/**
* @return int
*/
public function getSortKey()
{
return $this->_sortKey;
}
/**
* @param int $sortKey
*/
public function setSortKey($sortKey)
{
$this->_sortKey = $sortKey;
}
/**
* @return int
*/
public function getLimitStart()
{
return $this->_limitStart;
}
/**
* @param int $limitStart
*/
public function setLimitStart($limitStart)
{
$this->_limitStart = $limitStart;
}
/**
* @return int
*/
public function getLimitCount()
{
return $this->_limitCount;
}
/**
* @param int $limitCount
*/
public function setLimitCount($limitCount)
{
$this->_limitCount = $limitCount;
}
/**
* Obtener las cuentas de una búsqueda.
*
* @param array $searchFilter Filtros de búsqueda
* @return bool Resultado de la consulta
*/
public static function getAccounts($searchFilter)
public function getAccounts()
{
$isAdmin = ($_SESSION['uisadminapp'] || $_SESSION['uisadminacc']);
$globalSearch = ($searchFilter['globalSearch'] === 1 && Config::getValue('globalsearch', 0));
$isAdmin = (Session::getUserIsAdminApp() || Session::getUserIsAdminAcc());
$globalSearch = ($this->isGlobalSearch() && Config::getValue('globalsearch', 0));
$arrFilterCommon = array();
$arrFilterSelect = array();
$arrFilterUser = array();
$arrQueryWhere = array();
switch ($searchFilter['keyId']) {
case 1:
switch ($this->getSortKey()) {
case self::SORT_NAME:
$orderKey = 'account_name';
break;
case 2:
case self::SORT_CATEGORY:
$orderKey = 'category_name';
break;
case 3:
case self::SORT_LOGIN:
$orderKey = 'account_login';
break;
case 4:
case self::SORT_URL:
$orderKey = 'account_url';
break;
case 5:
case self::SORT_CUSTOMER:
$orderKey = 'customer_name';
break;
default :
@@ -95,27 +248,27 @@ class AccountSearch
. 'LEFT JOIN accUsers ON accuser_accountId = account_id '
. 'LEFT JOIN accGroups ON accgroup_accountId = account_id';
if ($searchFilter['txtSearch']) {
if ($this->getTxtSearch()) {
$arrFilterCommon[] = 'account_name LIKE :name';
$arrFilterCommon[] = 'account_login LIKE :login';
$arrFilterCommon[] = 'account_url LIKE :url';
$arrFilterCommon[] = 'account_notes LIKE :notes';
$data['name'] = '%' . $searchFilter['txtSearch'] . '%';
$data['login'] = '%' . $searchFilter['txtSearch'] . '%';
$data['url'] = '%' . $searchFilter['txtSearch'] . '%';
$data['notes'] = '%' . $searchFilter['txtSearch'] . '%';
$data['name'] = '%' . $this->getTxtSearch() . '%';
$data['login'] = '%' . $this->getTxtSearch() . '%';
$data['url'] = '%' . $this->getTxtSearch() . '%';
$data['notes'] = '%' . $this->getTxtSearch() . '%';
}
if ($searchFilter['categoryId'] != 0) {
if ($this->getCategoryId() !== 0) {
$arrFilterSelect[] = 'category_id = :categoryId';
$data['categoryId'] = $searchFilter['categoryId'];
$data['categoryId'] = $this->getCategoryId();
}
if ($searchFilter['customerId'] != 0) {
if ($this->getCustomerId() !== 0) {
$arrFilterSelect[] = 'account_customerId = :customerId';
$data['customerId'] = $searchFilter['customerId'];
$data['customerId'] = $this->getCustomerId();
}
if (count($arrFilterCommon) > 0) {
@@ -132,23 +285,25 @@ class AccountSearch
$arrFilterUser[] = 'accgroup_groupId = :accgroup_groupId';
$arrFilterUser[] = 'accuser_userId = :accuser_userId';
$data['userGroupId'] = $searchFilter['groupId'];
$data['userId'] = $searchFilter['userId'];
$data['accgroup_groupId'] = $searchFilter['groupId'];
$data['accuser_userId'] = $searchFilter['userId'];
// Usuario/Grupo principal de la cuenta
$data['userId'] = Session::getUserId();
$data['accuser_userId'] = Session::getUserId();
// Usuario/Grupo secundario de la cuenta
$data['userGroupId'] = Session::getUserGroupId();
$data['accgroup_groupId'] = Session::getUserGroupId();
//$arrQueryWhere[] = '(' . implode(' OR ', $arrFilterUser) . ')';
$arrQueryWhere[] = implode(' OR ', $arrFilterUser);
}
$orderDir = ($searchFilter["txtOrder"] == 0) ? 'ASC' : 'DESC';
$orderDir = ($this->getSortOrder() === 0) ? 'ASC' : 'DESC';
$queryOrder = 'ORDER BY ' . $orderKey . ' ' . $orderDir;
if ($searchFilter['limitCount'] != 99) {
if ($this->getLimitCount() != 99) {
$queryLimit = 'LIMIT :limitStart,:limitCount';
$data['limitStart'] = $searchFilter['limitStart'];
$data['limitCount'] = $searchFilter['limitCount'];
$data['limitStart'] = $this->getLimitStart();
$data['limitCount'] = $this->getLimitCount();
}
if (count($arrQueryWhere) === 1) {
@@ -177,14 +332,8 @@ class AccountSearch
// Obtenemos el número de registros totales de la consulta sin contar el LIMIT
self::$queryNumRows = DB::$last_num_rows;
$_SESSION["accountSearchTxt"] = $searchFilter["txtSearch"];
$_SESSION["accountSearchCustomer"] = $searchFilter["customerId"];
$_SESSION["accountSearchCategory"] = $searchFilter["categoryId"];
$_SESSION["accountSearchOrder"] = $searchFilter["txtOrder"];
$_SESSION["accountSearchKey"] = $searchFilter["keyId"];
$_SESSION["accountSearchStart"] = $searchFilter["limitStart"];
$_SESSION["accountSearchLimit"] = $searchFilter["limitCount"];
$_SESSION["accountGlobalSearch"] = $searchFilter["globalSearch"];
// Establecer el filtro de búsqueda en la sesión como un objeto
Session::setSearchFilters($this);
return $queryRes;
}

View File

@@ -251,4 +251,39 @@ class Session
{
$_SESSION["usrprofile"] = $profile;
}
/**
* @return \SP\AccountSearch
*/
public static function getSearchFilters()
{
return $_SESSION["search"];
}
/**
* @param \SP\AccountSearch $search
*/
public static function setSearchFilters(\SP\AccountSearch $search)
{
$_SESSION["search"] = $search;
}
/**
* Establece la cuenta primaria para el histórico
*
* @param $id int El id de la cuenta
*/
public static function setAccountParentId($id){
$_SESSION["accParentId"] = (int) $id;
}
/**
* Devuelve la cuenta primaria para el histórico
*
* @return int
*/
public static function getAccountParentId()
{
return $_SESSION["accParentId"];
}
}

View File

@@ -1,12 +1,12 @@
<div id="title" class="midroundup <?php echo $title['class']; ?>"><?php echo $title['name']; ?></div>
<?php if ($showform): ?>
<form method="post" name="frmaccount" id="frmAccount">
<?php endif; ?>
<?php if ($gotData && $accountIsHistory): ?>
<table class="data round tblIcon">
<?php else: ?>
<table class="data round">
<form method="post" name="frmaccount" id="frmAccount">
<?php endif; ?>
<?php if ($gotData && $accountIsHistory): ?>
<table class="data round tblIcon">
<?php else: ?>
<table class="data round">
<?php endif; ?>
<tr>
<td class="descField"><?php echo _('Nombre'); ?></td>
<td class="valField">
@@ -15,7 +15,7 @@
maxlength="50"
value="<?php echo ($gotData) ? $accountData->account_name : ''; ?>">
<?php else: ?>
<?php echo $accountData->account_name; ?>
<?php echo $accountData->account_name; ?>
<?php endif; ?>
</td>
</tr>
@@ -23,12 +23,18 @@
<td class="descField"><?php echo _('Cliente'); ?></td>
<td class="valField">
<?php if ($showform): ?>
<?php \SP\Html::printSelect(\SP\DB::getValuesForSelect('customers', 'customer_id', 'customer_name'), $customersSelProp);?>
<select id="selCustomer" name="customerId" class="select-box">
<option value="0"></option>
<?php foreach ($customers as $id => $name): ?>
<option
value="<?php echo $id; ?>" <?php echo ($gotData && $id == $accountData->account_customerId) ? 'selected' : ''; ?>><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
<br><br>
<input type="text" name="customer_new" maxlength="50"
placeholder="<?php echo _('Buscar en desplegable o introducir'); ?>"/>
<?php else: ?>
<?php echo $accountData->customer_name; ?>
<?php echo $accountData->customer_name; ?>
<?php endif; ?>
</td>
</tr>
@@ -36,9 +42,15 @@
<td class="descField"><?php echo _('Categoría'); ?></td>
<td class="valField">
<?php if ($showform): ?>
<?php \SP\Html::printSelect($accountCategories, $categoriesSelProp); ?>
<select id="selCategory" name="categoryId" class="select-box">
<option value="0"></option>
<?php foreach ($categories as $id => $name): ?>
<option
value="<?php echo $id; ?>" <?php echo ($gotData && $id == $accountData->account_categoryId) ? 'selected' : ''; ?>><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
<?php echo $accountData->category_name; ?>
<?php echo $accountData->category_name; ?>
<?php endif; ?>
</td>
</tr>
@@ -50,7 +62,7 @@
maxlength="255"
value="<?php echo ($gotData) ? $accountData->account_url : ''; ?>">
<?php else: ?>
<?php echo $accountData->account_url; ?>
<?php echo $accountData->account_url; ?>
<?php endif; ?>
</td>
</tr>
@@ -62,7 +74,7 @@
maxlength="50"
value="<?php echo ($gotData) ? $accountData->account_login : ''; ?>">
<?php else: ?>
<?php echo $accountData->account_login; ?>
<?php echo $accountData->account_login; ?>
<?php endif; ?>
</td>
</tr>
@@ -165,17 +177,17 @@
</tr>
<?php endif; ?>
<?php if ($showform): ?>
<input type="hidden" name="hash" value="<?php echo $changesHash; ?>">
<input type="hidden" name="next" value="<?php echo $nextaction; ?>">
<input type="hidden" name="actionId" value="<?php echo $actionId; ?>">
<?php if ($showform): ?>
<input type="hidden" name="hash" value="<?php echo $changesHash; ?>">
<input type="hidden" name="next" value="<?php echo $nextaction; ?>">
<input type="hidden" name="actionId" value="<?php echo $actionId; ?>">
<?php if ($gotData): ?>
<input type="hidden" name="accountid" value="<?php echo $accountId; ?>"/>
<?php endif; ?>
<input type="hidden" name="sk" value="<?php echo $sk; ?>">
<input type="hidden" name="isAjax" value="1">
</form>
<?php endif; ?>
<input type="hidden" name="sk" value="<?php echo $sk; ?>">
<input type="hidden" name="isAjax" value="1">
</form>
<?php endif; ?>
<!--Files boxes-->
<?php if ($showFiles): ?>
@@ -207,11 +219,26 @@
<tr>
<td class="descField"><?php echo _('Historial'); ?></td>
<td class="valField">
<?php SP\Html::printSelect($historyData, $historySelProp); ?>
<script>$("#sel-history").chosen({
<select id="selHistory" name="historyId" class="select-box">
<option value="0"></option>
<?php foreach ($historyData as $id => $name): ?>
<option
value="<?php echo $id; ?>" <?php echo ($gotData && $id === $accountId) ? 'selected' : ''; ?>><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
<script>
$('#selHistory').on('change', function (e) {
var historyId = $('#selHistory').val();
if (historyId > 0)
doAction(<?php echo \SP\Controller\ActionsInterface::ACTION_ACC_VIEW_HISTORY; ?>,<?php echo \SP\Controller\ActionsInterface::ACTION_ACC_VIEW; ?>, historyId);
});
$('#selHistory').chosen({
disable_search: true,
placeholder_text_single: "<?php echo _('Seleccionar fecha'); ?>"
});</script>
});
</script>
</td>
</tr>
<?php endif; ?>
@@ -300,7 +327,8 @@
<?php if ($gotData && $accountIsHistory): ?>
<form method="post" name="frmaccount" id="frmAccount">
<input type="hidden" name="hash" value="<?php echo $changesHash; ?>">
<input type="hidden" name="actionId" value="<?php echo \SP\Controller\ActionsInterface::ACTION_ACC_EDIT_RESTORE; ?>">
<input type="hidden" name="actionId"
value="<?php echo \SP\Controller\ActionsInterface::ACTION_ACC_EDIT_RESTORE; ?>">
<input type="hidden" name="accountid" value="<?php echo $accountId; ?>"/>
<input type="hidden" name="sk" value="<?php echo $sk; ?>">
<input type="hidden" name="isAjax" value="1">

View File

@@ -2,24 +2,29 @@
<table id="tblTools" class="round shadow">
<tr>
<td id="toolsLeft">
<img src="imgs/clear.png" title="<?php use SP\Html;
echo _('Limpiar'); ?>" class="inputImg" id="btnClear" onClick="clearSearch(); accSearch(0);" />
<input type="text" name="search" id="txtSearch" onKeyUp="accSearch(1,event)" value="<?php echo $searchTxt; ?>" placeholder="<?php echo _('Texto a buscar'); ?>"/>
<img src="imgs/clear.png" title="<?php echo _('Limpiar'); ?>" class="inputImg" id="btnClear" />
<input type="text" name="search" id="txtSearch" value="<?php echo $searchTxt; ?>" placeholder="<?php echo _('Texto a buscar'); ?>"/>
<?php if ( $globalSearch && ! $isAdmin ): ?>
<input type="checkbox" name="gsearch" id="gsearch" class="checkbox" <?php echo ($searchGlobal) ? 'checked="checked"' : ''; ?>/>
<label for="gsearch" title="<?php echo _('Búsqueda global');?>"><?php echo ($searchGlobal) ? 'ON' : 'OFF'; ?></label>
<?php endif; ?>
<label for="gsearch" title="<?php echo _('Búsqueda global');?>"><?php echo ($searchGlobal) ? 'ON' : 'OFF'; ?></label>
<input type="checkbox" name="gsearch" id="gsearch" class="checkbox" <?php echo ($searchGlobal) ? 'checked="checked"' : ''; ?>/>
<?php endif; ?>
<input type="hidden" name="start" value="<?php echo $limitStart; ?>">
<input type="hidden" name="skey" value="<?php echo $searchKey; ?>" />
<input type="hidden" name="sorder" value="<?php echo $searchOrder; ?>" />
<input type="hidden" name="sk" value="<?php echo $sk; ?>">
<input type="hidden" name="isAjax" value="1">
<?php
\SP\Html::printSelect(\SP\DB::getValuesForSelect('customers', 'customer_id', 'customer_name'), $customersSelProp);
\SP\Html::printSelect(\SP\DB::getValuesForSelect('categories', 'category_id', 'category_name'), $categoriesSelProp);
?>
<br>
<select id="selCustomer" name="customer" class="select-box">
<option value="0"></option>
<?php foreach ($customers as $id => $name): ?>
<option value="<?php echo $id; ?>" <?php echo ($id === $searchCustomer) ? 'selected' : ''; ?>><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
<select id="selCategory" name="category" class="select-box">
<option value="0"></option>
<?php foreach ($categories as $id => $name): ?>
<option value="<?php echo $id; ?>" <?php echo ($id === $searchCategory) ? 'selected' : ''; ?>><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
</td>
<td id="toolsRight">
<input type="text" name="rpp" id="rpp" placeholder="<?php echo _('CPP'); ?>" title="<?php echo _('Cuentas por página'); ?>" value="<?php echo $limitCount; ?>"/>
@@ -30,13 +35,15 @@
<script>
mkChosen({id: 'selCustomer', placeholder: '<?php echo _('Seleccionar Cliente'); ?>', noresults: '<?php echo _('Sin resultados'); ?>' });
mkChosen({id: 'selCategory', placeholder: '<?php echo _('Seleccionar Categoría'); ?>', noresults: '<?php echo _('Sin resultados'); ?>' });
$('#frmSearch select').on('change', function(e){clearSearch(1); accSearch(0)});
$("#rpp").spinner({step: 3, max: 50, min: 6, numberFormat: "n", stop: function(event, ui) {
accSearch(0);
}});
<?php if ( $globalSearch ): ?>
$('#tblTools').find('.checkbox').button();
$('#gsearch').click(function(){
$('#frmSearch #gsearch').click(function(){
if ( $(this).next('label').hasClass('ui-state-active') ){
$(this).next('label').children('span').html('OFF');
} else{
@@ -45,5 +52,7 @@
accSearch(0);
});
<?php endif; ?>
$('input:text:visible:first').focus();
$('#frmSearch input:text:visible:first').focus();
$('#frmSearch #txtSearch').keyup(function(e){accSearch(1,e)});
$('#frmSearch #btnClear').click(function(e){clearSearch(); accSearch(0);})
</script>

View File

@@ -153,12 +153,8 @@ function clearSearch(clearStart) {
}
document.frmSearch.search.value = "";
document.frmSearch.customer.selectedIndex = 0;
document.frmSearch.category.selectedIndex = 0;
$('#frmSearch').find('input[name="start"]').val(0);
$('#frmSearch').find('input[name="skey"]').val(0);
$('#frmSearch').find('input[name="sorder"]').val(0);
$(".select-box").val('').trigger("chosen:updated");
$('#frmSearch').find('select').prop('selectedIndex', 0).trigger("chosen:updated");
$('#frmSearch').find('input[name="start"], input[name="skey"], input[name="sorder"]').val(0);
order.key = 0;
order.dir = 0;
}
@@ -185,12 +181,14 @@ function accSearch(continous, event) {
return;
}
if (lenTxtSearch < 3 && continous === 1 && lenTxtSearch > window.lastlen && event.keyCode != 13) {
if (lenTxtSearch < 3 && continous === 1 && lenTxtSearch > window.lastlen && event.keyCode !== 13) {
return;
}
window.lastlen = lenTxtSearch;
$('#frmSearch').find('input[name="start"]').val(0);
doSearch();
}

View File

@@ -174,9 +174,6 @@ class AccountC extends Controller implements ActionsInterface
if ($this->isGotData()) {
$this->view->assign('accountParentId', $this->getAccount()->getAccountParentId());
$this->view->assign('accountIsHistory', $this->getAccount()->getAccountIsHistory());
$this->view->assign('accountCategories', \SP\DB::getValuesForSelect('categories', 'category_id', 'category_name'));
$this->view->assign('otherUsers', \SP\DB::getValuesForSelect('usrData', 'user_id', 'user_name'));
$this->view->assign('otherGroups', \SP\DB::getValuesForSelect('usrGroups', 'usergroup_id', 'usergroup_name'));
$this->view->assign('accountOtherUsers', $this->getAccount()->getAccountUsersId());
$this->view->assign('accountOtherUsersName', \SP\Users::getUsersNameForAccount($this->getId()));
$this->view->assign('accountOtherGroups', $this->getAccount()->getAccountUserGroupsId());
@@ -184,46 +181,17 @@ class AccountC extends Controller implements ActionsInterface
$this->view->assign('changesHash', $this->getAccount()->calcChangesHash());
$this->view->assign('chkUserEdit', ($this->view->accountData->account_otherUserEdit) ? 'checked' : '');
$this->view->assign('chkGroupEdit', ($this->view->accountData->account_otherGroupEdit) ? 'checked' : '');
$this->view->assign('historyData', \SP\AccountHistory::getAccountList($this->getAccount()->getAccountParentId()));
$this->view->assign('isModified', ($this->view->accountData->account_dateEdit && $this->view->accountData->account_dateEdit <> '0000-00-00 00:00:00'));
$this->view->assign('maxFileSize', round(\SP\Config::getValue('files_allowed_size') / 1024, 1));
$this->view->assign('filesAllowedExts', \SP\Config::getValue('files_allowed_exts'));
$this->view->assign('filesDelete', ($this->_action == Acl::ACTION_ACC_EDIT) ? 1 : 0);
}
$this->view->assign('customersSelProp', array("name" => "customerId",
"id" => "selCustomer",
"class" => "",
"size" => 1,
"label" => "",
"selected" => ($this->_gotData) ? $this->view->accountData->account_customerId : '',
"default" => "",
"js" => "",
"attribs" => ""
));
$this->view->assign('categoriesSelProp', array("name" => "categoryId",
"id" => "selCategory",
"class" => "",
"size" => 1,
"label" => "",
"selected" => ($this->_gotData) ? $this->view->accountData->account_categoryId : '',
"default" => "",
"js" => "",
"attribs" => ""
));
$this->view->assign('historySelProp', array("name" => "historyId",
"id" => "sel-history",
"class" => "",
"size" => 1,
"label" => "",
"selected" => ($this->_gotData && $this->_account->getAccountIsHistory()) ? $this->getId() : '',
"default" => "",
"js" => "OnChange=\"if ( $('#sel-history').val() > 0 ) doAction(" . self::ACTION_ACC_VIEW_HISTORY . "," . self::ACTION_ACC_VIEW . ", $('#sel-history').val());\"",
"attribs" => ''
));
$this->view->assign('isModified', ($this->_gotData && $this->view->accountData->account_dateEdit && $this->view->accountData->account_dateEdit <> '0000-00-00 00:00:00'));
$this->view->assign('filesDelete', ($this->_action == Acl::ACTION_ACC_EDIT) ? 1 : 0);
$this->view->assign('maxFileSize', round(\SP\Config::getValue('files_allowed_size') / 1024, 1));
$this->view->assign('historyData', \SP\AccountHistory::getAccountList($this->getId()));
$this->view->assign('filesAllowedExts', \SP\Config::getValue('files_allowed_exts'));
$this->view->assign('categories', \SP\DB::getValuesForSelect('categories', 'category_id', 'category_name'));
$this->view->assign('customers', \SP\DB::getValuesForSelect('customers', 'customer_id', 'customer_name'));
$this->view->assign('otherUsers', \SP\DB::getValuesForSelect('usrData', 'user_id', 'user_name'));
$this->view->assign('otherGroups', \SP\DB::getValuesForSelect('usrGroups', 'usergroup_id', 'usergroup_name'));
}
/**
@@ -291,7 +259,7 @@ class AccountC extends Controller implements ActionsInterface
try {
$this->setAccount(new Account());
$this->_account->setAccountId($this->getId());
$this->_account->setAccountParentId(Common::parseParams('s', 'accParentId', 0));
$this->_account->setAccountParentId(\SP\Session::getAccountParentId());
$this->view->assign('accountId', $this->getId());
$this->view->assign('accountData', $this->getAccount()->getAccountData());
@@ -377,7 +345,7 @@ class AccountC extends Controller implements ActionsInterface
$this->view->assign('title', array('class' => 'titleNormal', 'name' => _('Detalles de Cuenta')));
$this->view->assign('showform', false);
$_SESSION["accParentId"] = $this->getId();
\SP\Session::setAccountParentId($this->getId());
$this->_account->incrementViewCounter();
$this->setCommonData();
@@ -418,7 +386,7 @@ class AccountC extends Controller implements ActionsInterface
try {
$this->setAccount(new AccountHistory());
$this->_account->setAccountId($this->getId());
$this->_account->setAccountParentId(Common::parseParams('s', 'accParentId', 0));
$this->_account->setAccountParentId(\SP\Session::getAccountParentId());
$this->view->assign('accountId', $this->getId());
$this->view->assign('accountData', $this->getAccount()->getAccountData());

View File

@@ -26,6 +26,7 @@
namespace SP\Controller;
use SP\AccountSearch;
use SP\Session;
defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
@@ -36,15 +37,6 @@ defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'
*/
class SearchC extends Controller implements ActionsInterface
{
/**
* Constantes de ordenación
*/
const SORT_NAME = 1;
const SORT_CATEGORY = 2;
const SORT_USER = 3;
const SORT_URL = 4;
const SORT_CUSTOMER = 5;
/**
* Constructor
*
@@ -63,18 +55,26 @@ class SearchC extends Controller implements ActionsInterface
*/
private function setVars()
{
$this->view->assign('isAdmin', ($_SESSION["uisadminapp"] || $_SESSION["uisadminacc"]));
$this->view->assign('isAdmin', (\SP\Session::getUserIsAdminApp() || \SP\Session::getUserIsAdminAcc()));
$this->view->assign('globalSearch', \SP\Config::getValue('globalsearch', 0));
// Comprobar si está creado el objeto de búsqueda en la sesión
if (!is_object(Session::getSearchFilters())) {
Session::setSearchFilters(new AccountSearch());
}
// Obtener el filtro de búsqueda desde la sesión
$filters = Session::getSearchFilters();
// Valores POST
$this->view->assign('searchKey', \SP\Common::parseParams('p', 'skey', \SP\Common::parseParams('s', 'accountSearchKey', 0)));
$this->view->assign('searchOrder', \SP\Common::parseParams('p', 'sorder', \SP\Common::parseParams('s', 'accountSearchOrder', 0)));
$this->view->assign('searchCustomer', \SP\Common::parseParams('p', 'customer', \SP\Common::parseParams('s', 'accountSearchCustomer', 0)));
$this->view->assign('searchCategory', \SP\Common::parseParams('p', 'category', \SP\Common::parseParams('s', 'accountSearchCategory', 0)));
$this->view->assign('searchTxt', \SP\Common::parseParams('p', 'search', \SP\Common::parseParams('s', 'accountSearchTxt')));
$this->view->assign('searchGlobal', \SP\Common::parseParams('p', 'gsearch', \SP\Common::parseParams('s', 'accountGlobalSearch', 0), false, 1));
$this->view->assign('limitStart', \SP\Common::parseParams('p', 'start', \SP\Common::parseParams('s', 'accountSearchStart', 0)));
$this->view->assign('limitCount', \SP\Common::parseParams('p', 'rpp', \SP\Common::parseParams('s', 'accountSearchLimit', \SP\Config::getValue('account_count', 10))));
$this->view->assign('searchKey', \SP\Common::parseParams('p', 'skey', $filters->getSortKey()));
$this->view->assign('searchOrder', \SP\Common::parseParams('p', 'sorder', $filters->getSortOrder()));
$this->view->assign('searchCustomer', \SP\Common::parseParams('p', 'customer', $filters->getCustomerId()));
$this->view->assign('searchCategory', \SP\Common::parseParams('p', 'category', $filters->getCategoryId()));
$this->view->assign('searchTxt', \SP\Common::parseParams('p', 'search', $filters->getTxtSearch()));
$this->view->assign('searchGlobal', \SP\Common::parseParams('p', 'gsearch', $filters->isGlobalSearch(), false, 1));
$this->view->assign('limitStart', \SP\Common::parseParams('p', 'start', $filters->getLimitStart()));
$this->view->assign('limitCount', \SP\Common::parseParams('p', 'rpp', $filters->getLimitCount()));
}
/**
@@ -84,29 +84,8 @@ class SearchC extends Controller implements ActionsInterface
{
$this->view->addTemplate('searchbox');
$this->view->assign('customersSelProp',
array("name" => "customer",
"id" => "selCustomer",
"class" => "select-box",
"size" => 1,
"label" => "",
"selected" => $this->view->searchCustomer,
"default" => "",
"js" => 'OnChange="clearSearch(1); accSearch(0)"',
"attribs" => "")
);
$this->view->assign('categoriesSelProp',
array("name" => "category",
"id" => "selCategory",
"class" => "select-box",
"size" => 1,
"label" => "",
"selected" => $this->view->searchCategory,
"default" => "",
"js" => 'OnChange="clearSearch(1); accSearch(0)"',
"attribs" => "")
);
$this->view->assign('customers', \SP\DB::getValuesForSelect('customers', 'customer_id', 'customer_name'));
$this->view->assign('categories', \SP\DB::getValuesForSelect('categories', 'category_id', 'category_name'));
}
public function getSearch()
@@ -115,20 +94,18 @@ class SearchC extends Controller implements ActionsInterface
$this->view->assign('queryTimeStart', microtime());
$searchFilter = array(
'txtSearch' => $this->view->searchTxt,
'userId' => \SP\Common::parseParams('s', 'uid', 0),
'groupId' => \SP\Common::parseParams('s', 'ugroup', 0),
'categoryId' => $this->view->searchCategory,
'customerId' => $this->view->searchCustomer,
'keyId' => $this->view->searchKey,
'txtOrder' => $this->view->searchOrder,
'limitStart' => $this->view->limitStart,
'limitCount' => $this->view->limitCount,
'globalSearch' => $this->view->globalSearch
);
$search = new AccountSearch();
$resQuery = AccountSearch::getAccounts($searchFilter);
$search->setGlobalSearch($this->view->globalSearch);
$search->setTxtSearch($this->view->searchTxt);
$search->setCategoryId($this->view->searchCategory);
$search->setCustomerId($this->view->searchCustomer);
$search->setSortKey($this->view->searchKey);
$search->setSortOrder($this->view->searchOrder);
$search->setLimitStart($this->view->limitStart);
$search->setLimitCount($this->view->limitCount);
$resQuery = $search->getAccounts();
if (!$resQuery) {
$this->view->assign('accounts', false);
@@ -282,34 +259,34 @@ class SearchC extends Controller implements ActionsInterface
{
$this->view->assign('sortFields', array(
array(
'key' => self::SORT_CUSTOMER,
'key' => AccountSearch::SORT_CUSTOMER,
'title' => _('Ordenar por Cliente'),
'name' => _('Cliente'),
'function' => 'searchSort(' . self::SORT_CUSTOMER . ',' . $this->view->limitStart . ')'
'function' => 'searchSort(' . AccountSearch::SORT_CUSTOMER . ',' . $this->view->limitStart . ')'
),
array(
'key' => self::SORT_NAME,
'key' => AccountSearch::SORT_NAME,
'title' => _('Ordenar por Nombre'),
'name' => _('Nombre'),
'function' => 'searchSort(' . self::SORT_NAME . ',' . $this->view->limitStart . ')'
'function' => 'searchSort(' . AccountSearch::SORT_NAME . ',' . $this->view->limitStart . ')'
),
array(
'key' => self::SORT_CATEGORY,
'key' => AccountSearch::SORT_CATEGORY,
'title' => _('Ordenar por Categoría'),
'name' => _('Categoría'),
'function' => 'searchSort(' . self::SORT_CATEGORY . ',' . $this->view->limitStart . ')'
'function' => 'searchSort(' . AccountSearch::SORT_CATEGORY . ',' . $this->view->limitStart . ')'
),
array(
'key' => self::SORT_USER,
'key' => AccountSearch::SORT_LOGIN,
'title' => _('Ordenar por Usuario'),
'name' => _('Usuario'),
'function' => 'searchSort(' . self::SORT_USER . ',' . $this->view->limitStart . ')'
'function' => 'searchSort(' . AccountSearch::SORT_LOGIN . ',' . $this->view->limitStart . ')'
),
array(
'key' => self::SORT_URL,
'key' => AccountSearch::SORT_URL,
'title' => _('Ordenar por URL / IP'),
'name' => _('URL / IP'),
'function' => 'searchSort(' . self::SORT_URL . ',' . $this->view->limitStart . ')'
'function' => 'searchSort(' . AccountSearch::SORT_URL . ',' . $this->view->limitStart . ')'
)
));
}