2626dd47daad110c63a82c0560b134e2364eeac3
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Bernd Wurst Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15) */
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

16) 
17) require_once("inc/debug.php");
18) 
19) 
20) 
21) function customer_may_have_useraccounts()
22) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

23)     $customerno = (int) $_SESSION['customerinfo']['customerno'];
24)     $result = db_query("SELECT COUNT(*) FROM system.useraccounts WHERE kunde=?", array($customerno));
25)     return ($result->rowCount() > 0);
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

26) }
27) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

28) function customer_useraccount($uid)
29) {
30)     $args = array(":uid" => $uid, ":customerno" => $_SESSION['customerinfo']['customerno']);
31)     $result = db_query("SELECT 1 FROM system.useraccounts WHERE kunde=:customerno AND uid=:uid AND kundenaccount=1", $args);
32)     return $result->rowCount() > 0;
bernd nicht mehr der user mit der...

bernd authored 17 years ago

33) }
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

34) 
bernd Primärer Useraccount kann d...

bernd authored 17 years ago

35) function primary_useraccount()
36) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

37)     if (! ($_SESSION['role'] & ROLE_SYSTEMUSER)) {
38)         return null;
39)     }
40)     $customerno = (int) $_SESSION['customerinfo']['customerno'];
41)     $result = db_query("SELECT MIN(uid) AS uid FROM system.useraccounts WHERE kunde=?", array($customerno));
42)     $uid = $result->fetch(PDO::FETCH_OBJ)->uid;
43)     DEBUG("primary useraccount: {$uid}");
44)     return $uid;
bernd Primärer Useraccount kann d...

bernd authored 17 years ago

45) }
46) 
47) 
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

48) function available_shells()
49) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

50)     $result = db_query("SELECT path, name FROM system.shells WHERE usable=?", array(1));
51)     $ret = array();
52)     while ($s = $result->fetch()) {
53)         $ret[$s['path']] = $s['name'];
54)     }
55)     DEBUG($ret);
56)     return $ret;
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

57) }
58) 
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

59) 
60) function list_useraccounts()
61) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

62)     $customerno = (int) $_SESSION['customerinfo']['customerno'];
63)     $result = db_query("SELECT uid,username,name,erstellungsdatum,quota,shell FROM system.useraccounts WHERE kunde=?", array($customerno));
64)     $ret = array();
65)     while ($item = $result->fetch()) {
66)         array_push($ret, $item);
67)     }
68)     #DEBUG($ret);
69)     return $ret;
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

70) }
71) 
72) 
bernd Erlaube Änderung von Name u...

bernd authored 14 years ago

73) function get_account_details($uid, $customerno=0)
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

74) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

75)     $uid = (int) $uid;
76)     $customerno = (int) $customerno;
77)     if ($customerno == 0) {
78)         $customerno = $_SESSION['customerinfo']['customerno'];
79)     }
80)     $args = array(":uid" => $uid, ":customerno" => $customerno);
81)     $result = db_query("SELECT uid,username,name,shell,server,quota,erstellungsdatum FROM system.useraccounts WHERE kunde=:customerno AND uid=:uid", $args);
82)     if ($result->rowCount() == 0) {
83)         system_failure("Cannot find the requestes useraccount (for this customer).");
84)     }
85)     return $result->fetch();
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

86) }
87) 
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

88) function get_used_quota($uid)
89) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

90)     $uid = (int) $uid;
91)     $result = db_query("SELECT s.hostname AS server, systemquota, systemquota_used, mailquota, mailquota_used FROM system.v_quota AS q LEFT JOIN system.servers AS s ON (s.id=q.server) WHERE uid=?", array($uid));
92)     $ret = array();
93)     while ($line = $result->fetch()) {
94)         $ret[] = $line;
95)     }
96)     #DEBUG($ret);
97)     return $ret;
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

98) }
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

99) 
100) 
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

101) function set_account_details($account)
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

102) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

103)     $customerno = null;
104)     if ($_SESSION['role'] & ROLE_CUSTOMER) {
105)         $customerno = (int) $_SESSION['customerinfo']['customerno'];
106)     } else {
107)         $customerno = (int) $_SESSION['userinfo']['customerno'];
108)     }
109) 
110)     if ($account['name'] == '') {
111)         $account['name'] = null;
112)     }
113)     $args = array(":fullname" => filter_input_general($account['name']),
Bernd Wurst Weitere Prepared-Statements

Bernd Wurst authored 10 years ago

114)                 ":shell" => filter_input_general($account['shell']),
115)                 ":quota" => $account['quota'],
116)                 ":uid" => $account['uid'],
117)                 ":customerno" => $customerno);
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

118) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

119)     db_query("UPDATE system.useraccounts SET name=:fullname, quota=:quota, shell=:shell WHERE kunde=:customerno AND uid=:uid", $args);
120)     logger(LOG_INFO, "modules/systemuser/include/useraccounts", "systemuser", "updated details for uid {$args[":uid"]}");
bernd Systemuser-Modul hinzugefügt

bernd authored 17 years ago

121) }
122) 
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

123) function get_customer_quota()
124) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

125)     $cid = (int) $_SESSION['customerinfo']['customerno'];
126)     $result = db_query("SELECT SUM(u.quota) AS assigned, cq.quota AS max FROM system.customerquota AS cq INNER JOIN system.useraccounts AS u ON (u.kunde=cq.cid) WHERE cq.cid=?", array($cid));
127)     $ret = $result->fetch();
128)     DEBUG($ret);
129)     return $ret;