ElixirVault/www/system-brs-core/sys/sysActionLog/inc/sysActionLogController.php

395 lines
12 KiB
PHP

<?php
namespace BRSystems\Core\Sys\sysActionLog\inc;
use BRSystems\Core\Library\cCore\cCore;
use BRSystems\Core\Library\cJSON\cJSON;
/**
* sysActionLog Controller
*
* @category sysActionLog Controller
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @since Version 2.0
*/
class sysActionLogController extends cCore
{
public $dir;
public $name;
public $module;
/**
* Class constructor
*/
public function __construct($uriData, $dir, $name) {
$this->dir = $dir;
$this->name = $name;
parent :: __construct($uriData);
$this->module = new sysActionLogModule();
$this->oView->setTemplateDir($this->dir . "/tmpl/");
if(!$this->oView->cacheUsed()){
$this->oView->setJs(getCurrentFolder($this->dir) . '/js/' . $this->name . '.js');
$this->oView->setCss(getCurrentFolder($this->dir) . '/css/' . $this->name . '.css');
}
// Set JS module init title
$this->oView->setAsJSON(cCore::JS_MOD, ucfirst($name));
}
/**
* Function to show main form in the module
*
* @category sysActionLog Controller
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @returns bool true
*/
public function run($initEditMode = false){
$this->oView->TABLE = true;
$this->oView->setAsJSON('initEdit', $initEditMode);
$this->oView->setAsJSON('baseUrl', $this->gL());
$this->oView->setAsJSON('gM', $this->getTranslations());
$this->oView->setAsJSON('vcfg', $this->getValCfg());
$this->oView->display();
}
/**
* Function to create cms table & return for direct & ajax input
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @param int $page - page to display
* @param string $filter_json - (optional) filter json string
* @param bool $headers - flag whether to send header data or not
* @return array of data
* @version 1.1
*/
public function createCmsTable($page = 1, $filter_json = '', $headers = false) {
$pages = 0;
$filter = array();
if($filter_json){
$filter = cJSON::decode($filter_json, true);
}
$this->oView->MODULE_TITLE = $this->gM("Sys Action Log");
if(!!$filter && is_array($filter))
$this->oView->DEFAULT_SEARCH_VALUES = prepForDisplayHtml($filter);
$this->oView->LIST_BTN = true;
$this->oView->LIST_HEADER = reOrderTableFields($this->getTableFields(), $this->oUser->oCfg->getTableProperty($this->name));
$this->oView->LIST_DATA = $this->getModuleData($page, $filter, $pages);
$this->oView->LIST_ACTIONS = $this->getTableActions();
$data = array(
'data' => $this->oView->genHelperView('cmsc/table/data-table'),
'pcount' => $pages,
'rlimit' => $this->cmsTableRecordsPerPage
);
// Send data to client
if($headers)
$data['header'] = $this->oView->genHelperView('cmsc/table/data-table-search');
return $data;
}
/**
* Function to get module data
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @param int $page
* @param array $filter
* @param int $pages
* @return array of data
* @version 1.1
*/
public function getModuleData($page = 1, $filter = array(), &$pages) {
$where = "AND 1";
$sort = "ll.id DESC";
$offset = (($page?$page:1)-1) * $this->cmsTableRecordsPerPage;
$tFields = $this->getTableFields();
// Create sort by
if(getP('sortBy'))
$sort = $this->module->db->genOrderByQuery(getP('sortBy'), getP('sortWay'), $tFields);
// Create where clause
if(count($filter))
$where = $this->module->db->genSearchFieldQuery($filter, $tFields);
$subWhere = "";
/* if(o){
$filter['field_search'] = $this->module->db->prepData($filter['field_search']);
$subWhere = "
AND (
ll.action like '%{$filter['field_search']}%'
OR ll.value like '%{$filter['field_search']}%'
)";
unset($filter['field_search']);
}*/
$data = $this->module->getModuleRecords($where . $subWhere, $sort, $offset, $this->cmsTableRecordsPerPage);
if($data && count($data)){
//$now = time();
foreach($data as &$v){
/*if($v['expires'] > $now)
$v['sclass'] = 'bggreen';*/
if(date($this->CMSDateFormat, $v['time']) == date($this->CMSDateFormat)){
$v['time'] = date(" H:i", $v['time']);
}else{
$v['time'] = date($this->CMSDateFormat . " H:i", $v['time']);
}
}
unset($v);
}
$this->oView->ROWS = $rows = $this->module->db->getSelectedRecordsCount();
$pages = floor($rows / $this->cmsTableRecordsPerPage) + ($rows%$this->cmsTableRecordsPerPage?1:0);
return $data;
}
/**
* Function to delete records marked in table
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @param string $rows - passed user ids in JSON string
* @return array of data
*/
public function delete($rows) {
if($rows = cJSON::decode($rows, true)){
$rows = $this->module->db->prepData($rows);
if($this->module->deleteRecords($rows)){
return true;
}else{
cJSON::sendError();
}
}
return false;
}
/**
* Function to delete all records in table & clear all APC cache
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @return array of data
*/
public function deleteAll() {
$this->oApc->clearCache();
$this->module->deleteAllRecords();
}
/**
* Function to get table record data for edit mode
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @param int $id - record id
* @return array of data
*/
public function editCmsTableRecord($id) {
}
/**
* Function to save Record data
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @param int $recordId - record id
* @param string $fields - param JSON string
* @return array of data
*/
public function saveRecordData($recordId, $fields) {
}
/**
* Function to create table headers + search
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @return array of data
* @version 1.1
*/
public function getTableFields() {
if(!$this->chkP('SYS_ACTION_LOG_MANAGEMENT_SHOW')){
return false;
}
$tFields = array(
"checkbox" => array(
'sort' => false,
'title' => '',
'class' => 'w4 center rchk'
),
"id" => array(
'sort' => true,
'search' => true,
'title' => $this->gM("ID"),
'class' => 'w8 center sortDesc sort',
'db_field' => 'll.id',
'type' => 'input',
),
"action" => array(
'sort' => true,
'search' => true,
'title' => $this->gM("Action key"),
'class' => 'w18',
'db_field' => 'll.action',
'type' => 'input',
),
"value" => array(
'sort' => false,
'search' => true,
'title' => $this->gM("Value"),
'class' => 'w32',
'db_field' => 'll.value',
'type' => 'input',
),
"time" => array(
'sort' => true,
'search' => false,
'db_field' => 'll.time',
'title' => $this->gM("Inserted"),
'class' => 'w14 center'
),
/*"status" => array(
'sort' => false,
'field' => 'blocked',
'title' => $this->gM("Blocked"),
'class' => 'w7 center'
),*/
"buttons" => array(
'sort' => false,
'class' => 'w20',
'title' => $this->gM("Actions"),
'btnset' => array(
/*'ledit' => array(
'edit' => true,
'title' => $this->gM("Edit"),
), */
'ldelete' => array(
'title' => $this->gM("Delete"),
)
)
)
);
if(!$this->chkP('SYS_SHOW_TABLE_IDS'))
unset($tFields['id']);
return $tFields;
}
/**
* Function to get js translations for view
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @return array of data
*/
public function getTranslations(){
return array(
'yes' => $this->gM('Yes'),
'no' => $this->gM('No'),
'delTitle' => $this->gM('Delete Log record?'),
'delMessage' => $this->gM('Selected Log records will be permanently deleted and cannot be recovered. Confirm delete?'),
'buttonYes' => $this->gM('Delete selected records'),
'buttonCancel' => $this->gM('Cancel operation'),
'clearTitle' => $this->gM('Clear Action Log table'),
'clearMessage' => $this->gM('Whole Action Log table will be permanently cleared and cannot be recovered. Confirm clear?'),
'clearYes' => $this->gM('Clear all'),
'clearCancel' => $this->gM('Cancel'),
);
}
/**
* Function to get table actions
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @return array of data
*/
public function getTableActions(){
$actions = array(
/*'inew' => array(
'lbl' => $this->gM("Add new"),
'icon' => 'ico-addnew',
),
'istatus' => array(
'lbl' => $this->gM("Change item status"),
'sepline' => true,
),*/
'idelete' => array(
'lbl' => $this->gM("Delete selected"),
'icon' => 'nico-delete'
),
'icleartable' => array(
'lbl' => $this->gM("Delete All table entries"),
'icon' => 'nico-delete-all'
),
);
if(!$this->chkP('SYS_ACTION_LOG_OVERVIEW_DELETE_ALL'))
unset($actions['icleartable']);
// Reformat drop down
reformatDropDown($actions, false);
return $actions;
}
/**
* Function to get js validator cfg
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @return array of data
*/
public function getValCfg(){
$data = array();
return $data;
}
/**
* Function to get form buttons
*
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
* @category sysActionLog Controller
* @return array of data
*/
public function getFormButtons(){
return array(
/*1 => array(
'id' => 'fsave',
'lbl' => $this->gM('Save')
),*/
2 => array(
'id' => 'fcancel',
'lbl' => $this->gM('Cancel')
)
);
}
}