| Information | |
|---|---|
| min. EQDKP-PLUS Version | 0.7.0.0
|
Contents |
At the Admin-Page you want to create you extend your class by admin_generic.
class myadmin_page extends page_generic {
In the constructor you set the vars you need at the admin page.
By Default you can use $this->simple_head. It reads from $in->get('simple_head') (which has to be true for simple, otherwise its full);
public function __construct() { parent::__construct($pre_check, $handler=false, $pdh_call=array(), $params=null, $cb_name='', $url_id=''); //here you can set up your own code. Everything after $this->process(); wont be executed!! $this->process(); }
This is the minimum how it has to be used. The different params are explained below.
As $pre_check you can pass false or a string. If you pass a string it should be something like "a_item_". If you pass false, you must check the permission on your own.
global $user; $user->check_auth('a_config_man'); parent::__construct([...]);
For example like here.
An important note about passing pre-check:
If you pass the pre-check and dont define a 'check' key in your handler for each element, it will check for $pre_check.{key_of_handler}.
Example (you may want to read the paragraph about handler first):
public function __construct() { $handler = array( 'my_edit' => array('process' => 'edit_me'), 'my_save' => array('process' => 'save_me', 'check' => 'my_save_perm') ); parent::__construct('pre_check_', $handler); }
When the 'my_edit' handler is called, he would check for a permission named pre_check_my_edit. While for the 'my_save' handler he checks for a permission named my_save_perm, but only if the pre_check val is NOT false.
With $handler you set which functions shall be called if specific $_POST or $_GET variables are set or a formular is submitted. $handler has to be an array. Example follows:
$handler = array( 'save' => array('process' => 'save', 'session_key' => true), 'mode' => array( array('process' => 'create', 'value' => 'create', 'check' => 'a_page_add'), array('process' => 'icon_update', 'value' => 'icon_upd', 'check' => 'a_page_upd')) ); parent::__construct('a_page_', $handler);
If a $handler like this is passed the following happens:
If $_GET['save'] or $_POST['save'] is set, it will check for the permission a_page_save and call the function $this->save().
If $_GET['mode'] is set and the value of $_GET['mode'] is "create" and the user has the permission a_page_add the function $this->create() is called.
sessoin_key is used to prevent CSRF. If you have set it to true, which you should do for all handlers where a form is submitted, the script will automatically check if session_key has been passed with the form. To guarantee functionality, its necessary that you start your form like in this example:
<form method="post" name="{ACTION}" class= [...] </form>In the Admin-Generic class ACTION is assigned as follows:
$tpl->assign_var('ACTION', $_SERVER['PHP_SELF'].$SID.'&session_key='.$user->data['session_key']);
If you need another action param you should use the latter part &session_key='.$user->data['session_key'].
By default there are four handlers set:
private $handler = array( 'del' => array('process' => 'delete', seesion_key => true), 'add' => array('process' => 'add'), 'upd' => array('process' => 'update'), 'edit' => array('process' => 'edit') );
If he does not find any fitting handler he defaults back to $this->display(). You -must- have defined a function named display in your admin-class! Be careful to verify that only one handler is triggered. If you theoretically trigger to handlers only the one he finds first is triggered!
If you like to use $this->url_id in your admin-class you have to pass the name (e.g. "n") of the param.
With the new admin_generic class it is very easy to realise confirm-delete windows. To use them you have to do just a few things:
<input type="button" name="del" value="{L_sowieso}" class="mainoption bi_delete" onclick="delete_warning();" />If you have a mass-deletion and the ids come from checkboxes you further have to add (if "del" is your handler for the delete-function)
<input type="hidden" name="del" value="1" disabled="disabled" id="mass_del_submit" />after the button.
If you have a mass-deletion confirm-window and want to display e.g. the names of what shall be deleted, then you can set here which pdh-modul and tag shall be called to get the names.
$pdh_call has then to be an array like this: array($module_name, $tag_name);
If you want to display the plain ids, pass "plain" for $pdh_call. (If your ids are names for example).
If the specified pdh_modul expects extra parameters except the ID you can set them here.
$params = array('%id%', 'another_param', 'another_param');
By Default $params has only set the %id% param, which is replaced with the id.
As Checkbox-Name you pass the exact name of the checkbox the user has to check to select the entries which shall be deleted (only necessary for mass-deletion).
If you use a hptt with checkboxes you have to pass "selected_ids[]".
It is possible to pass "_class_" for $cb_name. Then you have to add class="cb_select_class" to your input-checkbox-tag. This helps if it is necessary to have a specified key in the brackets, e.g. "ids[{row.KEY}]".
Its possible to initialize the hptt, see hptt for more information
$this->get_hptt(....)