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 |
|
|
30 |
function replacePrefix($name, $dataRecord){ |
|
31 |
$keywordlist=array('CLIENTNAME','CLIENTID'); |
|
32 |
|
|
33 |
if ($name != '') { |
|
34 |
foreach ($keywordlist as $keyword) { |
|
35 |
if (substr_count($name, '['.$keyword.']') > 0) { |
|
36 |
switch ($keyword) { |
|
37 |
case 'CLIENTNAME': |
|
38 |
$res=str_replace('['.$keyword.']', getClientName($dataRecord), $name); |
|
39 |
break; |
|
40 |
case 'CLIENTID': |
|
41 |
$res=str_replace('['.$keyword.']', getClientID($dataRecord), $name); |
|
42 |
break; |
|
43 |
} |
|
44 |
} |
|
45 |
} |
|
46 |
} else { |
|
47 |
$res=''; |
|
48 |
} |
|
49 |
|
|
50 |
return $res; |
|
51 |
} |
|
52 |
|
|
53 |
function getClientName($dataRecord) { |
|
54 |
global $app, $conf; |
|
55 |
|
542146
|
56 |
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
cfa9da
|
57 |
// Get the group-id of the user |
T |
58 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
59 |
} else { |
|
60 |
// Get the group-id from the data itself |
|
61 |
if(isset($dataRecord['client_group_id'])) { |
|
62 |
$client_group_id = $dataRecord['client_group_id']; |
958241
|
63 |
} elseif (isset($dataRecord['parent_domain_id'])) { |
T |
64 |
$tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']); |
|
65 |
$client_group_id = $tmp['sys_groupid']; |
cfa9da
|
66 |
} else { |
T |
67 |
$client_group_id = $dataRecord['sys_groupid']; |
|
68 |
} |
|
69 |
} |
69944a
|
70 |
|
cfa9da
|
71 |
/* get the name of the client */ |
T |
72 |
$tmp = $app->db->queryOneRecord("SELECT name FROM sys_group WHERE groupid = " . $client_group_id); |
|
73 |
$clientName = $tmp['name']; |
|
74 |
if ($clientName == "") $clientName = 'default'; |
|
75 |
$clientName = convertClientName($clientName); |
|
76 |
return $clientName; |
|
77 |
} |
|
78 |
|
|
79 |
function getClientID($dataRecord) { |
|
80 |
global $app, $conf; |
|
81 |
|
542146
|
82 |
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { |
cfa9da
|
83 |
// Get the group-id of the user |
T |
84 |
$client_group_id = $_SESSION["s"]["user"]["default_group"]; |
|
85 |
} else { |
|
86 |
// Get the group-id from the data itself |
|
87 |
if(isset($dataRecord['client_group_id'])) { |
|
88 |
$client_group_id = $dataRecord['client_group_id']; |
958241
|
89 |
} elseif (isset($dataRecord['parent_domain_id'])) { |
T |
90 |
$tmp = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = " . $dataRecord['parent_domain_id']); |
|
91 |
$client_group_id = $tmp['sys_groupid']; |
|
92 |
} else { |
cfa9da
|
93 |
$client_group_id = $dataRecord['sys_groupid']; |
T |
94 |
} |
|
95 |
} |
|
96 |
/* get the name of the client */ |
|
97 |
$tmp = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE groupid = " . $client_group_id); |
|
98 |
$clientID = $tmp['client_id']; |
|
99 |
if ($clientID == '') $clientID = '0'; |
|
100 |
return $clientID; |
|
101 |
} |
|
102 |
|
|
103 |
function convertClientName($name){ |
|
104 |
/** |
|
105 |
* only allow 'a'..'z', '_', '0'..'9' |
|
106 |
*/ |
|
107 |
$allowed = 'abcdefghijklmnopqrstuvwxyz0123456789_'; |
|
108 |
$res = ''; |
|
109 |
$name = strtolower(trim($name)); |
|
110 |
for ($i=0; $i < strlen($name); $i++){ |
|
111 |
if ($name[$i] == ' ') continue; |
|
112 |
if (strpos($allowed, $name[$i]) !== false){ |
|
113 |
$res .= $name[$i]; |
|
114 |
} |
|
115 |
else { |
|
116 |
$res .= '_'; |
|
117 |
} |
|
118 |
} |
|
119 |
return $res; |
|
120 |
} |
|
121 |
|
|
122 |
|
|
123 |
?> |