493 lines
16 KiB
PHP
493 lines
16 KiB
PHP
<?php
|
|
|
|
namespace BRSystems\Core\Sys\sysApcOverview\inc;
|
|
|
|
use BRSystems\Core\Library\cCore\cCore;
|
|
use BRSystems\Core\Library\cJSON\cJSON;
|
|
|
|
/**
|
|
* sysApcOverview Controller
|
|
*
|
|
* @category sysApcOverview Controller
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @since Version 2.0
|
|
*/
|
|
class sysApcOverviewController 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 sysApcOverviewModule($this->oApc);
|
|
|
|
$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 sysApcOverview 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 sysApcOverview 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("APC Overview") . " <span class='status'>(<span class='red'>" . ($this->oApc->installed?($this->oApc->enabled?$this->gM("Enabled"):$this->gM("Disabled")):$this->gM("Not Installed - check PHP settings!")) . "</span>)</span>";
|
|
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 sysApcOverview 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 = "sc.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(0){
|
|
$filter['field_search'] = $this->module->db->prepData($filter['field_search']);
|
|
$subWhere = "
|
|
AND (
|
|
sc.key 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';
|
|
|
|
$v['inserted'] = date($this->CMSDateFormat . " H:i", $v['inserted']);
|
|
$v['expires'] = date($this->CMSDateFormat . " H:i", $v['expires']);
|
|
|
|
}
|
|
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 sysApcOverview 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 sysApcOverview Controller
|
|
* @return array of data
|
|
*/
|
|
public function deleteAll() {
|
|
|
|
$this->oApc->clearCache();
|
|
$this->module->deleteAllRecords();
|
|
|
|
}
|
|
/**
|
|
* Function to call apc disable
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category sysApcOverview Controller
|
|
* @param bool $enable - status
|
|
* @return array of data
|
|
*/
|
|
public function changeApcStatus($enable = true) {
|
|
|
|
$this->oApc->enabled($enable);
|
|
if($enable)
|
|
return array('lbl' => $this->gM('Enabled'));
|
|
else
|
|
return array('lbl' => $this->gM('Disabled'));
|
|
}
|
|
|
|
/**
|
|
* Function to get table record data for edit mode
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category sysApcOverview Controller
|
|
* @param int $id - record id
|
|
* @return array of data
|
|
*/
|
|
public function editCmsTableRecord($id) {
|
|
|
|
$keysToFields = array(
|
|
'key' => array('key', 'info'),
|
|
|
|
'num_hits' => array('num_hits', 'nhits'),
|
|
'creation_time' => array('creation_time', 'ctime'),
|
|
'access_time' => array('access_time', 'atime'),
|
|
'deletion_time' => array('deletion_time', 'dtime'),
|
|
'mtime' => array('mtime'),
|
|
);
|
|
|
|
|
|
if($id){
|
|
$data = $this->module->getRecordDataById($id);
|
|
|
|
// Load cache data for display
|
|
if($dd = $this->oApc->check(str_replace($this->oApc->prefix, '', $data['key']), true)){
|
|
|
|
// Get cache info
|
|
$cache = $this->oApc->getUserCacheData();
|
|
$v = false;
|
|
foreach($cache['cache_list'] as $vv){
|
|
foreach($keysToFields['key'] as $key){
|
|
if(isset($vv[$key]) && $vv[$key] == $data['key']){
|
|
$v = $vv;
|
|
|
|
// Set all values
|
|
foreach($keysToFields as $baseKey=>$keyVars){
|
|
if(!!$keyVars){
|
|
foreach($keyVars as $subKey){
|
|
if(isset($vv[$subKey])){
|
|
unset($v[$subKey]);
|
|
$v[$baseKey] = $vv[$subKey];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if(!!$v)
|
|
break;
|
|
}
|
|
|
|
|
|
if(!!$v) {
|
|
if (isset($v["num_hits"]))
|
|
$v["num_hits"] = sprintf("%s (%.2f%%)", $v["num_hits"], $v["num_hits"] * 100 / $cache["num_hits"]);
|
|
if (isset($v["creation_time"]) && $v["creation_time"])
|
|
$v["creation_time"] = date($this->CMSDateFormat . " H:i", $v["creation_time"]);
|
|
if (isset($v["access_time"]) && $v["access_time"])
|
|
$v["access_time"] = date($this->CMSDateFormat . " H:i", $v["access_time"]);
|
|
if (isset($v["deletion_time"]) && $v["deletion_time"])
|
|
$v["deletion_time"] = date($this->CMSDateFormat . " H:i", $v["deletion_time"]);
|
|
if (isset($v["mtime"]) && $v["mtime"])
|
|
$v["mtime"] = date($this->CMSDateFormat . " H:i", $v["mtime"]);
|
|
}
|
|
|
|
//$sItems = explode("\n", pRr($dd));
|
|
//$v['data'] = str_replace(array("] => ", "\n"), array("] => <p>", "</p>"), pRr($dd));
|
|
$v['data'] = pRr($dd);
|
|
$data['data'] = $v;
|
|
$this->oView->C = $data;
|
|
}else{
|
|
$this->oApc->setExpired($data['key']);
|
|
}
|
|
}
|
|
|
|
return array(
|
|
'show' => array('buttons_top' => false, 'buttons_bottom' => true),
|
|
'btn' => $this->getFormButtons(),
|
|
'html' => $this->oView->genTemplate('apcEdit'),
|
|
);
|
|
|
|
}
|
|
|
|
/**
|
|
* Function to save Record data
|
|
*
|
|
* @author Mareks Keišs <mareks.keiss@brsystems.lv>
|
|
* @category sysApcOverview 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 sysApcOverview Controller
|
|
* @return array of data
|
|
* @version 1.1
|
|
*/
|
|
public function getTableFields() {
|
|
|
|
if(!$this->chkP('SYS_APC_OVERVIEW_SHOW_OVERVIEW')){
|
|
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' => 'sc.id',
|
|
'type' => 'input',
|
|
),
|
|
"key" => array(
|
|
'sort' => true,
|
|
'search' => true,
|
|
'title' => $this->gM("APC key"),
|
|
'class' => 'w32',
|
|
'db_field' => 'sc.key',
|
|
'type' => 'input',
|
|
),
|
|
"inserted" => array(
|
|
'sort' => false,
|
|
'search' => false,
|
|
'title' => $this->gM("Inserted"),
|
|
'class' => 'w14',
|
|
'db_field' => 'sc.inserted',
|
|
'type' => 'input',
|
|
),
|
|
"expires" => array(
|
|
'sort' => false,
|
|
'search' => false,
|
|
'title' => $this->gM("Expires"),
|
|
'class' => 'w14',
|
|
'db_field' => 'sc.expires',
|
|
'type' => 'input',
|
|
),
|
|
"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 sysApcOverview Controller
|
|
* @return array of data
|
|
*/
|
|
public function getTranslations(){
|
|
return array(
|
|
'yes' => $this->gM('Yes'),
|
|
'no' => $this->gM('No'),
|
|
'delTitle' => $this->gM('Delete apc cache?'),
|
|
'delMessage' => $this->gM('Selected keys will be permanently deleted and cannot be recovered. Confirm delete?'),
|
|
'buttonYes' => $this->gM('Delete selected keys'),
|
|
'buttonCancel' => $this->gM('Cancel operation'),
|
|
'clearTitle' => $this->gM('Clear whole APC cache table'),
|
|
'clearMessage' => $this->gM('Whole APC cache 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 sysApcOverview 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 whole cache table"),
|
|
'icon' => 'nico-delete-all'
|
|
),
|
|
'sepline',
|
|
'idisable' => array(
|
|
'lbl' => $this->gM("Disable APC"),
|
|
),
|
|
'ienable' => array(
|
|
'lbl' => $this->gM("Enable APC"),
|
|
),
|
|
);
|
|
|
|
if($this->oApc->enabled)
|
|
unset($actions['ienable']);
|
|
else
|
|
unset($actions['idisable']);
|
|
|
|
if(!$this->oApc->installed || !$this->chkP('SYS_APC_OVERVIEW_DISABLE'))
|
|
unset($actions['ienable'], $actions['idisable']);
|
|
if(!$this->chkP('SYS_APC_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 sysApcOverview 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 sysApcOverview 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')
|
|
)
|
|
);
|
|
|
|
}
|
|
}
|