tbrehm
2012-05-18 8677124afa9ddf23e34540565200d82ae1502bad
commit | author | age
cfa9da 1 <?php
T 2 /*
3 Copyright (c) 2008, 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
cc2156 30 function replacePrefix($name, $dataRecord) {
T 31     // No input -> no possible output -> go out!
32     if ($name=="") return "";
cfa9da 33
cc2156 34     // Array containing keys to search
e8a4ba 35     $keywordlist=array('CLIENTNAME','CLIENTID','DOMAINID');
cc2156 36
T 37     // Try to match the key within the string
38     foreach ($keywordlist as $keyword) {
39         if (substr_count($name, '['.$keyword.']') > 0) {
40             switch ($keyword) {
41                 case 'CLIENTNAME':
42                     $name=str_replace('['.$keyword.']', getClientName($dataRecord),$name);
43                 break;
44                 case 'CLIENTID':
45                     $name=str_replace('['.$keyword.']', getClientID($dataRecord),$name);
46                 break;
e8a4ba 47                 case 'DOMAINID':
O 48                     $name=str_replace('['.$keyword.']', $dataRecord['parent_domain_id'],$name);
49                 break;
cc2156 50             }
T 51         }
52     }
53     return $name;
cfa9da 54 }
T 55
56 function getClientName($dataRecord) {
57     global $app, $conf;
867712 58     if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
T 59         // Get the group-id of the user if the logged in user is neither admin nor reseller
cfa9da 60         $client_group_id = $_SESSION["s"]["user"]["default_group"];
T 61     } else {
62         // Get the group-id from the data itself
63         if(isset($dataRecord['client_group_id'])) {
64             $client_group_id = $dataRecord['client_group_id'];
e6e445 65         } elseif (isset($dataRecord['parent_domain_id'])) {
T 66             $tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']);
67             $client_group_id = $tmp['sys_groupid'];
cfa9da 68           } else {
T 69             $client_group_id = $dataRecord['sys_groupid'];
70           }
71     }
07bdbd 72     
cfa9da 73     /* get the name of the client */
T 74     $tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id);
75     $clientName = $tmp['name'];
76     if ($clientName == "") $clientName = 'default';
77     $clientName = convertClientName($clientName);
78     return $clientName;
79 }
80
81 function getClientID($dataRecord) {
82     global $app, $conf;
83
867712 84     if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
cfa9da 85         // Get the group-id of the user
T 86         $client_group_id = $_SESSION["s"]["user"]["default_group"];
87     } else {
88         // Get the group-id from the data itself
89         if(isset($dataRecord['client_group_id'])) {
90             $client_group_id = $dataRecord['client_group_id'];
e6e445 91           } elseif (isset($dataRecord['parent_domain_id'])) {
T 92             $tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']);
93             $client_group_id = $tmp['sys_groupid'];
94         } else {
cfa9da 95             $client_group_id = $dataRecord['sys_groupid'];
T 96           }
97     }
98     /* get the name of the client */
99     $tmp = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = " . $client_group_id);
100     $clientID = $tmp['client_id'];
101     if ($clientID == '') $clientID = '0';
102     return $clientID;
103 }
104
105 function convertClientName($name){
106     /**
9f56bd 107      *  only allow 'a'..'z', '_', '0'..'9'
cfa9da 108      */
9f56bd 109     $allowed = 'abcdefghijklmnopqrstuvwxyz0123456789_';
cfa9da 110     $res = '';
T 111     $name = strtolower(trim($name));
112     for ($i=0; $i < strlen($name); $i++){
113         if ($name[$i] == ' ') continue;
114         if (strpos($allowed, $name[$i]) !== false){
115             $res .= $name[$i];
116         }
117         else {
118             $res .= '_';
119         }
120     }
121     return $res;
122 }
123
124
125 ?>