vogelor
2008-12-16 12ae7f4b1e0544a02a299ec5ef7ac998c8c800d0
commit | author | age
0c702b 1 <?php
V 2 /*
3 Copyright (c) 2007-2008, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
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 function applyClientTemplates($clientId){
31     global $app;
32     /*
33      * Get the master-template for the client
34      */
12ae7f 35     $sql = "SELECT template_master, template_additional FROM client WHERE client_id = " . intval($clientId);
0c702b 36     $record = $app->db->queryOneRecord($sql);
V 37     $masterTemplateId = $record['template_master'];
12ae7f 38     $additionalTemplateStr = $record['template_additional'];
0c702b 39
V 40     /*
41      * if the master-Template is custom there is NO changing
42      */
43     if ($masterTemplateId > 0){
44         $sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId);
45         $limits = $app->db->queryOneRecord($sql);
12ae7f 46     } else {
V 47         $limits = $this->dataRecord;
0c702b 48     }
V 49
50     /*
12ae7f 51      * Process the additional tempaltes here (add them to the limits
0c702b 52      * if != -1)
V 53      */
12ae7f 54     $addTpl = explode('/', $additionalTemplateStr);
V 55     foreach ($addTpl as $item){
56         if (trim($item) != ''){
57             $sql = "SELECT * FROM client_template WHERE template_id = " . intval($item);
58             $addLimits = $app->db->queryOneRecord($sql);
59             /* maybe the template is deleted in the meantime */
60             if (is_array($addLimits)){
61                 foreach($addLimits as $k => $v){
62                     if ($limits[$k] > -1){
63                         if ($v == -1) {
64                             $limits[$k] = -1;
65                         }
66                         else {
67                             $limits[$k] += $v;
68                         }
69                     }
70                 }
71             }
72         }
73     }
0c702b 74
V 75     /*
76      * Write all back to the database
77      */
78     $update = '';
79     foreach($limits as $k => $v){
80         if (strpos($k, 'limit') !== false){
81             if ($update != '') $update .= ', ';
82             $update .= '`' . $k . "`='" . $v . "'";
83         }
84     }
85     $sql = 'UPDATE client SET ' . $update . " WHERE client_id = " . intval($clientId);
86     $app->db->query($sql);
87 }
88 ?>