92f133ee96716791aa0cad3fd268fafdc9c507dc
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

1) <?php
2) 
3) require_once("inc/debug.php");
4) require_once("inc/db_connect.php");
5) 
6) require_role(ROLE_CUSTOMER);
7) 
8) 
9) function customer_may_have_useraccounts()
10) {
11)   $customerno = (int) $_SESSION['customerinfo']['customerno'];
12)   $result = db_query("SELECT COUNT(*) FROM system.useraccounts WHERE kunde={$customerno}");
13)   return (mysql_num_rows($result) > 0);
14) }
15) 
bernd nicht mehr der user mit der...

bernd authored 16 years ago

16) function customer_useraccount($uid) {
17)   $uid = (int) $uid;
18)   $customerno = (int) $_SESSION['customerinfo']['customerno'];
19)   $result = db_query("SELECT 1 FROM system.useraccounts WHERE kunde={$customerno} AND uid={$uid} AND kundenaccount=1");
20)   return mysql_num_rows($result) > 0;
21) }
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

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

bernd authored 16 years ago

23) function primary_useraccount()
24) {
25)   if (! ($_SESSION['role'] & ROLE_SYSTEMUSER))
26)     return NULL;
27)   $customerno = (int) $_SESSION['customerinfo']['customerno'];
28)   $result = db_query("SELECT MIN(uid) AS uid FROM system.useraccounts WHERE kunde={$customerno}");
29)   $uid = mysql_fetch_object($result)->uid;
30)   DEBUG("primary useraccount: {$uid}");
31)   return $uid;
32) }
33) 
34) 
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

35) function available_shells()
36) {
37)   $result = db_query("SELECT path, name FROM system.shells WHERE usable=1");
38)   $ret = array();
39)   while ($s = mysql_fetch_assoc($result))
40)   {
41)     $ret[$s['path']] = $s['name'];
42)   }
43)   DEBUG($ret);
44)   return $ret;
45) }
46) 
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

47) 
48) function list_useraccounts()
49) {
50)   $customerno = (int) $_SESSION['customerinfo']['customerno'];
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

51)   $result = db_query("SELECT uid,username,name,erstellungsdatum,quota,shell FROM system.useraccounts WHERE kunde={$customerno}");
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

52)   $ret = array();
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

53)   while ($item = mysql_fetch_assoc($result))
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

54)   {
55)     array_push($ret, $item);
56)   }
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

57)   DEBUG($ret);
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

58)   return $ret;
59) }
60) 
61) 
62) function get_account_details($uid)
63) {
64)   $uid = (int) $uid;
65)   $customerno = (int) $_SESSION['customerinfo']['customerno'];
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

66)   $result = db_query("SELECT uid,username,name,shell,quota FROM system.useraccounts WHERE kunde={$customerno} AND uid={$uid}");
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

67)   if (mysql_num_rows($result) == 0)
68)     system_failure("Cannot find the requestes useraccount (for this customer).");
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

69)   return mysql_fetch_assoc($result);
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

70) }
71) 
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

72) function get_used_quota($uid)
73) {
74)   $uid = (int) $uid;
75)   $result = db_query("SELECT s.hostname AS server, used, COALESCE(us.quota, u.quota) AS quota FROM system.usedquota AS uq LEFT JOIN system.useraccounts AS u USING (uid) LEFT JOIN system.servers AS s ON (s.id=uq.server) LEFT JOIN system.user_server AS us ON (us.uid=uq.uid AND us.server=uq.server) WHERE uq.uid='{$uid}'");
76)   $ret = array();
77)   while ($line = mysql_fetch_assoc($result))
78)     $ret[] = $line;
79)   DEBUG($ret);
80)   return $ret;
81) }
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

82) 
83) 
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

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

bernd authored 16 years ago

85) {
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

86)   $uid = (int) $account['uid'];
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

87)   $customerno = (int) $_SESSION['customerinfo']['customerno'];
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

88)   $fullname = maybe_null(mysql_real_escape_string(filter_input_general($account['name'])));
89)   $shell = mysql_real_escape_string(filter_input_general($account['shell']));
90)   $quota = (int) $account['quota'];
bernd Systemuser-Modul hinzugefügt

bernd authored 16 years ago

91) 
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

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

bernd authored 16 years ago

94) 
95) }
96) 
bernd Überarbeitetes Systemuser-M...

bernd authored 14 years ago

97) function get_customer_quota()
98) {
99)   $cid = (int) $_SESSION['customerinfo']['customerno'];
100)   $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={$cid}");
101)   $ret = mysql_fetch_assoc($result);
102)   DEBUG($ret);
103)   return $ret;
104) }
105)