Sergio Cambra
2014-06-25 e9bb05d44d4672f7dc29a78cc7bb98cebc96abc6
interface/web/mail/mail_domain_edit.php
@@ -71,7 +71,7 @@
      if($_SESSION["s"]["user"]["typ"] == 'admin') {
         // Getting Clients of the user
         $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY sys_group.name";
         $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name";
         $clients = $app->db->queryAllRecords($sql);
         $client_select = '';
@@ -97,7 +97,7 @@
         unset($tmp);
         // Fill the client select field
         $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$app->functions->intval($client['client_id'])." ORDER BY sys_group.name";
         $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ".$app->functions->intval($client['client_id'])." ORDER BY client.company_name, client.contact_name, sys_group.name";
         $clients = $app->db->queryAllRecords($sql);
         $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($client['client_id']));
         $client_select = '<option value="'.$tmp['groupid'].'">'.$client['contactname'].'</option>';
@@ -109,6 +109,34 @@
            }
         }
         $app->tpl->setVar("client_group_id", $client_select);
      }
      if($_SESSION["s"]["user"]["typ"] != 'admin')
      {
         $client_group_id = $_SESSION["s"]["user"]["default_group"];
         $client_mail = $app->db->queryOneRecord("SELECT mail_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
         $client_mail['mail_servers_ids'] = explode(',', $client_mail['mail_servers']);
         $only_one_server = count($client_mail['mail_servers_ids']) === 1;
         $app->tpl->setVar('only_one_server', $only_one_server);
         if ($only_one_server) {
            $app->tpl->setVar('server_id_value', $client_mail['mail_servers_ids'][0]);
         }
         $sql = "SELECT server_id, server_name FROM server WHERE server_id IN (" . $client_mail['mail_servers'] . ");";
         $mail_servers = $app->db->queryAllRecords($sql);
         $options_mail_servers = "";
         foreach ($mail_servers as $mail_server) {
            $options_mail_servers .= "<option value='$mail_server[server_id]'>$mail_server[server_name]</option>";
         }
         $app->tpl->setVar("client_server_id", $options_mail_servers);
         unset($options_mail_servers);
      }
@@ -148,7 +176,7 @@
      // Get the spamfilter policys for the user
      $tmp_user = $app->db->queryOneRecord("SELECT policy_id FROM spamfilter_users WHERE email = '@".$app->db->quote($this->dataRecord["domain"])."'");
      $sql = "SELECT id, policy_name FROM spamfilter_policy WHERE ".$app->tform->getAuthSQL('r');
      $sql = "SELECT id, policy_name FROM spamfilter_policy WHERE ".$app->tform->getAuthSQL('r')." ORDER BY policy_name";
      $policys = $app->db->queryAllRecords($sql);
      $policy_select = "<option value='0'>".$app->tform->wordbook["no_policy"]."</option>";
      if(is_array($policys)) {
@@ -190,11 +218,9 @@
      }
      if($_SESSION["s"]["user"]["typ"] != 'admin') {
         // Get the limits of the client
         $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
         $client = $app->db->queryOneRecord("SELECT limit_maildomain, default_mailserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
         // When the record is updated
         if($this->id > 0) {
            // restore the server ID if the user is not admin and record is edited
@@ -203,10 +229,13 @@
            unset($tmp);
            // When the record is inserted
         } else {
            // set the server ID to the default mailserver of the client
            $this->dataRecord["server_id"] = $client["default_mailserver"];
            $client['mail_servers_ids'] = explode(',', $client['mail_servers']);
            // Check if the user may add another mail_domain
            // Check if chosen server is in authorized servers for this client
            if (!(is_array($client['mail_servers_ids']) && in_array($this->dataRecord["server_id"], $client['mail_servers_ids']))) {
               $app->error($app->tform->wordbook['error_not_allowed_server_id']);
            }
            if($client["limit_maildomain"] >= 0) {
               $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM mail_domain WHERE sys_groupid = $client_group_id");
               if($tmp["number"] >= $client["limit_maildomain"]) {