commit | author | age
|
596f0b
|
1 |
<?php |
SC |
2 |
/** |
|
3 |
* dns_dns_slave_plugin plugin |
|
4 |
* |
|
5 |
* @author Sergio Cambra <sergio@programatica.es> 2014 |
|
6 |
*/ |
|
7 |
|
|
8 |
|
|
9 |
class dns_dns_slave_plugin { |
|
10 |
|
|
11 |
var $plugin_name = 'dns_dns_slave_plugin'; |
|
12 |
var $class_name = 'dns_dns_slave_plugin'; |
|
13 |
|
|
14 |
/* |
|
15 |
This function is called when the plugin is loaded |
|
16 |
*/ |
|
17 |
function onLoad() { |
|
18 |
global $app; |
|
19 |
//Register for the events |
|
20 |
$app->plugin->registerEvent('dns:dns_slave:on_after_insert', 'dns_dns_slave_plugin', 'dns_dns_slave_edit'); |
|
21 |
$app->plugin->registerEvent('dns:dns_slave:on_after_update', 'dns_dns_slave_plugin', 'dns_dns_slave_edit'); |
|
22 |
} |
|
23 |
|
|
24 |
/* |
|
25 |
Function to change dns slave owner |
|
26 |
*/ |
|
27 |
function dns_dns_slave_edit($event_name, $page_form) { |
|
28 |
global $app, $conf; |
|
29 |
|
|
30 |
// make sure that the record belongs to the client group and not the admin group when a dmin inserts it |
|
31 |
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) { |
|
32 |
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]); |
cc7a82
|
33 |
$app->db->query("UPDATE dns_slave SET sys_groupid = ? WHERE id = ?", $client_group_id, $page_form->id); |
596f0b
|
34 |
} |
SC |
35 |
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) { |
|
36 |
$client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]); |
cc7a82
|
37 |
$app->db->query("UPDATE dns_slave SET sys_groupid = ? WHERE id = ?", $client_group_id, $page_form->id); |
596f0b
|
38 |
} |
SC |
39 |
|
|
40 |
//** When the client group has changed, change also the owner of the record if the owner is not the admin user |
|
41 |
if($page_form->oldDataRecord && $page_form->oldDataRecord["client_group_id"] != $page_form->dataRecord["client_group_id"] && $page_form->dataRecord["sys_userid"] != 1) { |
|
42 |
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]); |
cc7a82
|
43 |
$tmp = $app->db->queryOneREcord("SELECT userid FROM sys_user WHERE default_group = ?", $client_group_id); |
596f0b
|
44 |
if($tmp["userid"] > 0) { |
cc7a82
|
45 |
$app->db->query("UPDATE dns_slave SET sys_userid = ? WHERE id = ?", $tmp["userid"], $page_form->id); |
596f0b
|
46 |
} |
SC |
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
} |