Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
ecb6b3 1 <?php
M 2 /**
3  * sites_web_database_user_plugin plugin
b1a6a5 4  *
ecb6b3 5  * @author Marius Cramer <m.cramer@pixcept.de> pixcept KG 2012
M 6  */
b1a6a5 7
MC 8
ecb6b3 9 class sites_web_database_user_plugin {
M 10
11     var $plugin_name        = 'sites_web_database_user_plugin';
12     var $class_name         = 'sites_web_database_user_plugin';
b1a6a5 13
MC 14     /*
ecb6b3 15             This function is called when the plugin is loaded
M 16     */
b1a6a5 17     function onLoad() {
MC 18         global $app;
19         //Register for the events
20         $app->plugin->registerEvent('sites:web_database_user:on_after_update', 'sites_web_database_user_plugin', 'sites_web_database_user_edit');
21         $app->plugin->registerEvent('sites:web_database_user:on_after_insert', 'sites_web_database_user_plugin', 'sites_web_database_user_edit');
ecb6b3 22     }
b1a6a5 23
MC 24     /*
25         Function to create the sites_web_database_user rule and insert it into the custom rules
26     */
27     function sites_web_database_user_edit($event_name, $page_form) {
28         global $app, $conf;
29
30         // make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
31         // also make sure that the user can not delete entry created by an admin
32         if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) {
33             $client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
cc7a82 34             $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'ru' WHERE database_user_id = ?", $client_group_id, $page_form->id);
b1a6a5 35         }
MC 36         if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($page_form->dataRecord["client_group_id"])) {
37             $client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
cc7a82 38             $app->db->query("UPDATE web_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_group_id, $page_form->id);
b1a6a5 39         }
MC 40     }
41
42 }