tbrehm
2007-05-26 b565bf69e857600508468f93f62207d464429068
commit | author | age
22e7f9 1 <?php
T 2 /*
3 Copyright (c) 2005, Till Brehm, projektfarm Gmbh
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
8
9     * Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright notice,
12       this list of conditions and the following disclaimer in the documentation
13       and/or other materials provided with the distribution.
14     * Neither the name of ISPConfig nor the names of its contributors
15       may be used to endorse or promote products derived from this software without
16       specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30
31 /******************************************
32 * Begin Form configuration
33 ******************************************/
34
35 $tform_def_file = "form/mail_domain.tform.php";
36
37 /******************************************
38 * End Form configuration
39 ******************************************/
40
41 require_once('../../lib/config.inc.php');
42 require_once('../../lib/app.inc.php');
43
44 // Checking module permissions
45 if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) {
46     header("Location: ../index.php");
47     exit;
48 }
49
50 // Loading classes
51 $app->uses('tpl,tform,tform_actions');
52 $app->load('tform_actions');
53
54 class page_action extends tform_actions {
965795 55     
T 56     function onShowNew() {
57         global $app, $conf;
58         
59         // we will check only users, not admins
60         if($_SESSION["s"]["user"]["typ"] == 'user') {
61             
62             // Get the limits of the client
63             $client_group_id = $_SESSION["s"]["user"]["default_group"];
64             $client = $app->db->queryOneRecord("SELECT limit_maildomain FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
65             
66             // Check if the user may add another maildomain.
67             if($client["limit_maildomain"] >= 0) {
68                 $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM mail_domain WHERE sys_groupid = $client_group_id");
69                 if($tmp["number"] >= $client["limit_maildomain"]) {
70                     $app->error($app->tform->wordbook["limit_maildomain_txt"]);
71                 }
72             }
73         }
74         
75         parent::onShowNew();
76     }
77     
22e7f9 78     function onShowEnd() {
T 79         global $app, $conf;
80         
81         if($_SESSION["s"]["user"]["typ"] == 'admin') {
82             // Getting Domains of the user
83             $sql = "SELECT groupid, name FROM sys_group WHERE client_id > 0";
84             $clients = $app->db->queryAllRecords($sql);
85             $client_select = "<option value='0'></option>";
86             if(is_array($clients)) {
87                 foreach( $clients as $client) {
88                     $selected = ($client["groupid"] == $this->dataRecord["sys_groupid"])?'SELECTED':'';
89                     $client_select .= "<option value='$client[groupid]' $selected>$client[name]</option>\r\n";
90                 }
91             }
92         $app->tpl->setVar("client_group_id",$client_select);
93         }
94         
95         parent::onShowEnd();
96     }
97     
98     function onSubmit() {
965795 99         global $app, $conf;
T 100         if($_SESSION["s"]["user"]["typ"] != 'admin') {
101             
102             // Get the limits of the client
103             $client_group_id = $_SESSION["s"]["user"]["default_group"];
104             $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");
105             
106             // When the record is updated
107             if($this->id > 0) {
108                 // restore the server ID if the user is not admin and record is edited
109                 $tmp = $app->db->queryOneRecord("SELECT server_id FROM mail_domain WHERE domain_id = ".intval($this->id));
110                 $this->dataRecord["server_id"] = $tmp["server_id"];
111                 unset($tmp);
112             // When the record is inserted
113             } else {
114                 // set the server ID to the default mailserver of the client
115                 $this->dataRecord["server_id"] = $client["default_mailserver"];
116                 
117                 // Check if the user may add another mail_domain
118                 if($client["limit_maildomain"] >= 0) {
119                     $tmp = $app->db->queryOneRecord("SELECT count(domain_id) as number FROM mail_domain WHERE sys_groupid = $client_group_id");
120                     if($tmp["number"] >= $client["limit_maildomain"]) {
121                         $app->error($app->tform->wordbook["limit_maildomain_txt"]);
122                     }
123                 }
124             }
125             
126             // Clients may not set the client_group_id, so we unset them if user is not a admin
127             unset($this->dataRecord["client_group_id"]);
128         }
22e7f9 129         parent::onSubmit();
T 130     }
131     
132     function onAfterInsert() {
133         global $app, $conf;
134         
965795 135         // make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
b565bf 136         // also make sure that the user can not delete domain created by a admin
22e7f9 137         if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
T 138             $client_group_id = intval($this->dataRecord["client_group_id"]);
b565bf 139             $app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id);
22e7f9 140         }
T 141     }
142     
143     function onAfterUpdate() {
144         global $app, $conf;
145         
b565bf 146         // make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
T 147         // also make sure that the user can not delete domain created by a admin
22e7f9 148         if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) {
T 149             $client_group_id = intval($this->dataRecord["client_group_id"]);
b565bf 150             $app->db->query("UPDATE mail_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id);
22e7f9 151         }
T 152     }
153     
154 }
155
156 $page = new page_action;
157 $page->onLoad();
158
83b0d0 159 ?>