Permalink
Browse files

Adds a feature to mark multiple records as verified at once in Admin_…

…MonitoringUserAgentChecker module.
  • Loading branch information...
JB Lebrun
JB Lebrun committed Nov 21, 2018
1 parent 79e3ff6 commit 578a00aa97b872f40f08f90f3345333170571a56
@@ -5,7 +5,7 @@
* @details Plugin, Module Engine
* @file plugin/module/Admin_MonitoringUserAgentChecker/Admin_MonitoringUserAgentChecker.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.1
* @version 1.0.2
* @date Creation: Dec 2014
* @date Modification: Nov 2018
* @copyright 2014 - 2018 CaMykS Team
@@ -97,12 +97,57 @@ final class Admin_MonitoringUserAgentChecker extends Module {
public function get_rights() {
global $camyks;
$this->rights[0] = array(
'name' =>'read',
'name' => 'read',
'title' => $camyks->get_translation('read'),
'default' =>false,
'default' => false,
);
}
/**
* Register a menu in admin interface.
* @return array
*/
function get_adminEngineSpecificMenus() {
/* Load mode from header */
$this->mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : 'main';
/* Return menus */
if ($this->mode == 'main') {
return array(
array(
'name' => 'useragentchecker',
'title' => $this->get_translation('title'),
),
);
}
/* Return default result */
return array();
}
/**
* Register menu items in admin interface.
* @return array
*/
function get_adminEngineSpecificMenuItems() {
global $camyks;
/* Return menu items */
if ($this->mode == 'main') {
return array(
array(
'name' => 'markselected',
'title' => $this->get_translation('markitemsasverified'),
'icon' => $this->theme->get_pictURL('valid', 12, 'std'),
'menu' => 'useragentchecker',
'url' => 'javascript:UARecordList.mark_recordsAsVerified();',
),
);
}
return array();
}
/**
* Update description in control panel.
* @return void
@@ -162,26 +207,6 @@ final class Admin_MonitoringUserAgentChecker extends Module {
/* get informations */
$this->mode = isset ($_REQUEST['mode']) ? $_REQUEST['mode'] : 'main';
/* build form */
$this->addform = new HTMLForm(
'edit_record',
$this->get_adminlink(array('mode'=>'save_record')),
'POST'
);
$this->addform->add_hidden('record_id', 0);
/* build popup buttons */
$this->popupbuttons = array(
array(
'title' => $camyks->get_translation('close'),
'link' => 'javascript:adminengine_modalPopupClose(\'admin_genericuseragentmanager_addpopup\')',
),
array(
'title' => $camyks->get_translation('add'),
'link' => $this->addform->get_HTMLSubmitLink(),
),
);
switch ($this->mode) {
case 'view_record':
/* mode == view_record */
@@ -207,6 +232,10 @@ final class Admin_MonitoringUserAgentChecker extends Module {
/* mode == mark_recordAsVerified */
$this->init_admin_mark_recordAsVerified();
break;
case 'mark_recordsAsVerified':
/* mode == mark_recordsAsVerified */
$this->init_admin_mark_recordsAsVerified();
break;
case 'main':
default:
/* mode == main */
@@ -257,11 +286,38 @@ final class Admin_MonitoringUserAgentChecker extends Module {
/* initialise tabs */
$this->tabBuilder->initialise(array('default'=>'Records'));
/* build multi selection form */
$this->selectionForm = new HTMLForm('recordSelection', $this->get_adminLink(), 'POST');
$this->selectionForm->add_hidden('mode', 'main');
$this->selectionForm->add_hidden('ids', '');
/* add scripts */
$this->add_JSFIle('UARecordList.js');
$this->add_JSLoadScript('UARecordList.set_param("form", "'.$this->selectionForm->name.'");');
$this->add_JSLoadScript('UARecordList.set_locale("confirm_message", "'.string_html2Text($this->get_translation('validaterecordsmessage')).'");');
$this->add_JSLoadScript('UARecordList.initialise();');
/* get buttons */
$this->buttons = array(array(
'link' => $camyks->get_adminLink(),
'title' => $camyks->get_translation('back'),
));
/* build record insertion form */
$this->addform = new HTMLForm('edit_record', $this->get_adminlink(array('mode'=>'save_record')), 'POST');
$this->addform->add_hidden('record_id', 0);
/* build popup buttons */
$this->popupbuttons = array(
array(
'title' => $camyks->get_translation('close'),
'link' => 'javascript:adminengine_modalPopupClose(\'admin_genericuseragentmanager_addpopup\')',
),
array(
'title' => $camyks->get_translation('add'),
'link' => $this->addform->get_HTMLSubmitLink(),
),
);
}
/**
@@ -442,10 +498,6 @@ final class Admin_MonitoringUserAgentChecker extends Module {
private function init_admin_delete_record() {
global $camyks;
/* check user rights */
if ($this->check_right(2) === false)
return $this->init_admin_actionNotAllowed() ;
/* check record id */
if (!isset($_REQUEST['record_id']))
return $this->init_admin_main();
@@ -472,10 +524,6 @@ final class Admin_MonitoringUserAgentChecker extends Module {
private function init_admin_update_recordType() {
global $camyks;
/* check user rights */
if ($this->check_right(2) === false)
return $this->init_admin_actionNotAllowed();
/* check record id */
if (!isset($_REQUEST['record_id']))
return $this->init_admin_main();
@@ -502,10 +550,6 @@ final class Admin_MonitoringUserAgentChecker extends Module {
private function init_admin_mark_recordAsVerified() {
global $camyks;
/* check user rights */
if ($this->check_right(2) === false)
return $this->init_admin_actionNotAllowed();
/* check record id */
if (!isset($_REQUEST['record_id']))
return $this->init_admin_main();
@@ -525,6 +569,28 @@ final class Admin_MonitoringUserAgentChecker extends Module {
$this->set_redirect($this->get_adminLink(array('mode'=>'view_record', 'record_id'=>$this->recordItem->id)));
}
/**
* Initialise module object in admin/mark_recordsAsVerified mode.
* @return void
*/
private function init_admin_mark_recordsAsVerified() {
global $camyks;
/* disable admin menu */
$this->disable_adminEngineMenus();
/* load and update record */
$list = $this->get_selectedItems();
if ($this->recordItem->mark_recordsAsVerified($list))
$this->text = $this->get_translation('records_updated');
else
$this->text = $this->get_translation('records_notupdated');
/* update layout */
$this->set_selectedLayout('admin_message.html.inc', 'camyks');
$this->set_redirect($this->get_adminLink());
}
/* specific tool methods */
/**
@@ -553,6 +619,25 @@ final class Admin_MonitoringUserAgentChecker extends Module {
return $this->recordItem->save();
}
/**
* Return selected item list.
* @return array
*/
private function get_selecteditems() {
$list = array();
$ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : '';
if ($ids == '')
return $list;
$list = explode(',', $ids);
foreach ($list as $id)
$id = (int)$id;
return $list;
}
/**
* Return records platform type list.
* @return array
@@ -4,7 +4,7 @@
* @details Plugin / Module layout
* @file plugin/module/Admin_MonitoringUserAgentChecker/html/admin.html.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.1
* @version 1.0.2
* @date Creation: Dec 2014
* @date Modification: Nov 2018
* @copyright 2014 - 2018 CaMykS Team
@@ -14,6 +14,10 @@
*/
global $camyks;
?>
<?= $this->selectionForm->display_header(); ?>
<?= $this->selectionForm->display_hiddens(); ?>
<?= $this->selectionForm->display_footer(); ?>

<?= $this->theme->get_boxHeader(array('class'=>'adminEditorModule')); ?>
<?= $this->theme->get_boxTitleBar($this->title) ?>
<?= $this->theme->get_boxTabsBar($this->tabBuilder->tabs, $this->tabBuilder->jsParams); ?>
@@ -0,0 +1,96 @@
/**
* @brief Admin_MonitoringUserAgentChecker module record list scripts
* @details Plugin / Module Scripts
* @file plugin/module/Admin_MonitoringUserAgentChecker/js/UARecordList.js
* @author CaMykS Team
* @version 1.0
* @date Creation: Nov 2018
* @date Modification: Nov 2018
* @copyright 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

var UARecordList = {
params: {},
locales: {},
loaded: false,

/**
* Add parameter
* @param string name
* @param mixed value
* @return void
*/
set_param: function(param, value, subvalue) {
if (subvalue != undefined && this.params[param])
this.params[param][value] = subvalue;
else
this.params[param] = value;
},

/**
* Return param value from name
* @param mixed param
* @return mixed
*/
get_param: function(param, value) {
if (value != undefined && (this.params[param][value] || this.params[param][value] === 0))
return this.params[param][value];
if (this.params[param] || this.params[param] === 0)
return this.params[param]
return false;
},

/**
* Set locale value
* @param string name
* @param string value
* @return void
*/
set_locale: function(name, value) {
this.locales[name.toLowerCase()] = value;
},

/**
* Return locale value
* @param string name
* @return void
*/
get_locale: function(name) {
if (this.locales[name.toLowerCase()])
return this.locales[name.toLowerCase()];
return name;
},

/**
* Initialise object
* @return void
*/
initialise: function() {
/* set form */
this.set_param('form', document.getElementById(this.get_param('form')));

/* finalise initialisation */
this.loaded = true;
},

/* Action methods */

/**
* check selected 404 Fallback value
* @return void
*/
mark_recordsAsVerified: function() {
if (!this.loaded)
return false;

if (!confirm(this.get_locale('confirm_message')))
return;

ids = recordList.get_checkedBoxes('selection');
this.get_param('form').mode.value = 'mark_recordsAsVerified';
this.get_param('form').ids.value = ids.join(',');
this.get_param('form').submit();
},
}
@@ -4,7 +4,7 @@
* @details Plugin, Module Library
* @file plugin/module/Admin_MonitoringUserAgentChecker/lib/Admin_MonitoringUserAgentCheckerRecord.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.1
* @version 1.0.2
* @date Creation: Dec 2014
* @date Modification: Nov 2018
* @copyright 2014 - 2018 CaMykS Team
@@ -252,6 +252,28 @@ final class Admin_MonitoringUserAgentCheckerRecord extends ModuleLibrary {
return $this->update_databaseSpecificItems(array('status'));
}
/**
* Mark records as verified.
* @param array $ids
* @return boolean success
*/
public function mark_recordsAsVerified($ids) {
/* Check ids count */
if (count($ids) == 0)
return true;
/* build SQL query */
$sql = 'update '.$this->_libSQLTable;
$sql .= ' set status = 1';
if (count($ids) == 1)
$sql .= ' where id = '. $ids[0];
else
$sql .= ' where id in ('.implode(',', $ids).')';
/* execute sql query */
return ($this->execute_DBQuery($sql, __LINE__));
}
/**
* Update visit count.
* @return boolean success
Oops, something went wrong.

0 comments on commit 578a00a

Please sign in to comment.