| | |
| | | /* |
| | | * The admin can select ALL domains, the user only the domains assigned to him |
| | | */ |
| | | $sql = "SELECT domain FROM domain "; |
| | | $sql = "SELECT domain_id, domain FROM domain "; |
| | | if ($_SESSION["s"]["user"]["typ"] != 'admin') { |
| | | $sql .= "WHERE sys_groupid =" . $client_group_id; |
| | | } |
| | |
| | | if(is_array($domains) && sizeof($domains) > 0) { |
| | | /* We have domains in the list, so create the drop-down-list */ |
| | | foreach( $domains as $domain) { |
| | | $domain_select .= "<option value=" . $domain['domain'] ; |
| | | $domain_select .= "<option value=" . $domain['domain_id'] ; |
| | | if ($domain['domain'] == $this->dataRecord["domain"]) { |
| | | $domain_select .= " selected"; |
| | | } |
| | | $domain_select .= ">" . $domain['domain'] . "</option>\r\n"; |
| | | $domain_select .= ">" . $app->functions->idn_decode($domain['domain']) . "</option>\r\n"; |
| | | } |
| | | } |
| | | else { |
| | |
| | | |
| | | function onSubmit() { |
| | | global $app, $conf; |
| | | if($_SESSION["s"]["user"]["typ"] != 'admin') { |
| | | |
| | | /* check if the domain module is used - and check if the selected domain can be used! */ |
| | | $app->uses('ini_parser,getconf'); |
| | | $settings = $app->getconf->get_global_config('domains'); |
| | | if ($settings['use_domain_module'] == 'y') { |
| | | $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); |
| | | |
| | | $sql = "SELECT domain_id, domain FROM domain WHERE domain_id = " . $app->functions->intval($this->dataRecord['domain']); |
| | | if ($_SESSION["s"]["user"]["typ"] != 'admin') { |
| | | $sql .= " AND sys_groupid =" . $client_group_id; |
| | | } |
| | | $domain_check = $app->db->queryOneRecord($sql); |
| | | if(!$domain_check) { |
| | | // invalid domain selected |
| | | $app->tform->errorMessage .= $app->tform->lng("domain_error_empty")."<br />"; |
| | | } else { |
| | | $this->dataRecord['domain'] = $domain_check['domain']; |
| | | } |
| | | } |
| | | |
| | | if($_SESSION["s"]["user"]["typ"] != 'admin') { |
| | | |
| | | // Get the limits of the client |
| | | $client_group_id = $_SESSION["s"]["user"]["default_group"]; |
| | |
| | | // When the record is updated |
| | | if($this->id > 0) { |
| | | // restore the server ID if the user is not admin and record is edited |
| | | $tmp = $app->db->queryOneRecord("SELECT server_id FROM mail_domain WHERE domain_id = ".intval($this->id)); |
| | | $tmp = $app->db->queryOneRecord("SELECT server_id FROM mail_domain WHERE domain_id = ".$app->functions->intval($this->id)); |
| | | $this->dataRecord["server_id"] = $tmp["server_id"]; |
| | | unset($tmp); |
| | | // When the record is inserted |
| | |
| | | // make sure that the record belongs to the client group and not the admin group when a dmin inserts it |
| | | // also make sure that the user can not delete domain created by a admin |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) { |
| | | $client_group_id = intval($this->dataRecord["client_group_id"]); |
| | | $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]); |
| | | $app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id); |
| | | } |
| | | if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) { |
| | | $client_group_id = intval($this->dataRecord["client_group_id"]); |
| | | $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]); |
| | | $app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$this->id); |
| | | } |
| | | |
| | | // Spamfilter policy |
| | | $policy_id = intval($this->dataRecord["policy"]); |
| | | $policy_id = $app->functions->intval($this->dataRecord["policy"]); |
| | | if($policy_id > 0) { |
| | | $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".$app->db->quote($this->dataRecord["domain"])."'"); |
| | | if($tmp_user["id"] > 0) { |
| | |
| | | $tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ".$this->id); |
| | | // We create a new record |
| | | $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`) |
| | | VALUES (".$_SESSION["s"]["user"]["userid"].", ".$tmp_domain["sys_groupid"].", 'riud', 'riud', '', ".$this->dataRecord["server_id"].", 5, ".$policy_id.", '@".mysql_real_escape_string($this->dataRecord["domain"])."', '@".mysql_real_escape_string($this->dataRecord["domain"])."', 'Y')"; |
| | | VALUES (".$_SESSION["s"]["user"]["userid"].", ".$tmp_domain["sys_groupid"].", 'riud', 'riud', '', ".$this->dataRecord["server_id"].", 5, ".$policy_id.", '@".$app->db->quote($this->dataRecord["domain"])."', '@".$app->db->quote($this->dataRecord["domain"])."', 'Y')"; |
| | | $app->db->datalogInsert('spamfilter_users', $insert_data, 'id'); |
| | | unset($tmp_domain); |
| | | } |
| | |
| | | // make sure that the record belongs to the client group and not the admin group when admin inserts it |
| | | // also make sure that the user can not delete domain created by a admin |
| | | if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) { |
| | | $client_group_id = intval($this->dataRecord["client_group_id"]); |
| | | $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]); |
| | | $tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $client_group_id"); |
| | | $client_user_id = ($tmp['userid'] > 0)?$tmp['userid']:1; |
| | | $app->db->query("UPDATE mail_domain SET sys_userid = $client_user_id, sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id); |
| | | } |
| | | if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) { |
| | | $client_group_id = intval($this->dataRecord["client_group_id"]); |
| | | $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]); |
| | | $tmp = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE default_group = $client_group_id"); |
| | | $client_user_id = ($tmp['userid'] > 0)?$tmp['userid']:1; |
| | | $app->db->query("UPDATE mail_domain SET sys_userid = $client_user_id, sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$this->id); |
| | | } |
| | | |
| | | // Spamfilter policy |
| | | $policy_id = intval($this->dataRecord["policy"]); |
| | | $policy_id = $app->functions->intval($this->dataRecord["policy"]); |
| | | $tmp_user = $app->db->queryOneRecord("SELECT id FROM spamfilter_users WHERE email = '@".$app->db->quote($this->dataRecord["domain"])."'"); |
| | | if($policy_id > 0) { |
| | | if($tmp_user["id"] > 0) { |
| | |
| | | $tmp_domain = $app->db->queryOneRecord("SELECT sys_groupid FROM mail_domain WHERE domain_id = ".$this->id); |
| | | // We create a new record |
| | | $insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `priority`, `policy_id`, `email`, `fullname`, `local`) |
| | | VALUES (".$_SESSION["s"]["user"]["userid"].", ".$tmp_domain["sys_groupid"].", 'riud', 'riud', '', ".$this->dataRecord["server_id"].", 5, ".$policy_id.", '@".mysql_real_escape_string($this->dataRecord["domain"])."', '@".mysql_real_escape_string($this->dataRecord["domain"])."', 'Y')"; |
| | | VALUES (".$_SESSION["s"]["user"]["userid"].", ".$tmp_domain["sys_groupid"].", 'riud', 'riud', '', ".$this->dataRecord["server_id"].", 5, ".$policy_id.", '@".$app->db->quote($this->dataRecord["domain"])."', '@".$app->db->quote($this->dataRecord["domain"])."', 'Y')"; |
| | | $app->db->datalogInsert('spamfilter_users', $insert_data, 'id'); |
| | | unset($tmp_domain); |
| | | } |
| | |
| | | } |
| | | |
| | | //* Update the aliases |
| | | $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source like '%@".$app->db->quote($this->oldDataRecord['domain'])."' OR destination like '%@".mysql_real_escape_string($this->oldDataRecord['domain'])."'"); |
| | | $forwardings = $app->db->queryAllRecords("SELECT * FROM mail_forwarding WHERE source like '%@".$app->db->quote($this->oldDataRecord['domain'])."' OR destination like '%@".$app->db->quote($this->oldDataRecord['domain'])."'"); |
| | | if(is_array($forwardings)) { |
| | | foreach($forwardings as $rec) { |
| | | $destination = $app->db->quote(str_replace($this->oldDataRecord['domain'],$this->dataRecord['domain'],$rec['destination'])); |