/[scire]/scire/.lib/DB_functions.php
Gentoo

Contents of /scire/.lib/DB_functions.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 99 - (show annotations) (download)
Wed Jun 14 01:52:27 2006 UTC (11 years, 6 months ago) by codeman
File size: 5767 byte(s)
 various updates around the board.  mainly focusing on client and user
 pages.  some DB updates and asthetic changes.
 preparing for user sessions


1 <?php
2
3 function get_scire_modules() {
4 global $db;
5 $result = $db->select('*', 'modules');
6 if ($result && count($result) > 0) {
7 return $result;
8 } else {
9 return array();
10 }
11 }
12
13 function get_scire_module_list() {
14 global $db;
15 $result = $db->select(array('main_content', 'name'), 'modules');
16 if ($result && count($result) > 0) {
17 return $result;
18 } else {
19 return array();
20 }
21 }
22
23 function get_profile_list() {
24 global $db;
25 $result = $db->select('profile_name', 'GLI_profiles');
26 if ($result && count($result) > 0) {
27 return $result;
28 } else {
29 return array();
30 }
31 }
32
33 function get_group_clients($group) {
34 global $db;
35 $result = $db->select('*', 'clients', '`gli_profile` = \'' . $group . '\'');
36 if ($result && count($result) > 0) {
37 return $result;
38 } else {
39 return array();
40 }
41 }
42
43 function get_scire_clients($orderby, $direction) {
44 global $db;
45 if ($orderby) {
46 $where = "ORDER BY `$orderby` $direction";
47 } else {
48 $where = '';
49 }
50 $result = $db->select('SELECT c.clientid, c.assetid, c.digest, c.hostname, c.mac, c.ip, c.status,
51 p.profile_name, o.osname, u.username, c.installtime
52 FROM clients c, os o, GLI_profiles p, users u
53 WHERE c.gli_profile=p.profileid
54 AND c.osid=o.osid
55 AND c.contact=u.userid '.$where);
56 $result = $db->select('SELECT c.clientid, c.assetid, c.digest, c.hostname, c.mac, c.ip, c.status, c.installtime, p.profile_name, o.osname, u.username FROM clients AS c LEFT JOIN GLI_profiles AS p ON (c.gli_profile=p.profileid) LEFT JOIN os AS o ON (c.osid=o.osid) LEFT JOIN users AS u ON (c.contact=u.userid) '.$where);
57 if ($result && count($result) > 0) {
58 return $result;
59 } else {
60 return array();
61 }
62 }
63
64 function get_scire_client($clientid) {
65 global $db;
66 $result = $db->select('*', 'clients', '`clientid` = \'' . $clientid . '\'');
67 if ($result && count($result) > 0) {
68 return $result[0];
69 } else {
70 return false;
71 }
72 }
73
74 function scire_add_client($digest, $hostname, $mac, $ip, $profileid, $osid, $contact, $status, $installtime, $assetid) {
75 #clientid, assetid, digest, cert, hostname, mac, ip, gli_profile, osid, status, contact, installtime
76 if (!$installtime) {$installtime = "NOW()"; }
77 global $db;
78 $result = $db->insert('clients', array('digest' => $digest, 'hostname' => $hostname, 'mac' => $mac, 'ip' => $ip, 'gli_profile' => $profileid, 'osid' => $osid, 'contact' => $contact, 'status' => $status, 'installtime' => $installtime, 'assetid' => $assetid));
79 if ($result) {
80 return true;
81 } else {
82 return $db->error;
83 }
84 }
85
86 function scire_edit_client($clientid, $fields) {
87 global $db;
88 $result = $db->update('clients', $fields, '`clientid` = \'' . $clientid . '\'');
89 if ($result) {
90 return true;
91 } else {
92 return $db->error;
93 }
94 }
95
96 function scire_del_client($client_id) {
97 global $db;
98 $result = $db->delete('clients', '`client_id` = \'' . $client_id . '\'');
99 if ($result) {
100 return true;
101 } else {
102 return $db->error;
103 }
104 }
105
106 function get_scire_users($orderby, $direction) {
107 #we don't want to store the password for security reasons. <- ???
108 global $db;
109 if ($orderby) {
110 $where = "1 ORDER BY `$orderby` $direction";
111 } else {
112 $where = '1';
113 }
114 $result = $db->select(array('userid', 'username', 'comment', 'real_name'), 'users', $where);
115 if ($result && count($result) > 0) {
116 return $result;
117 } else {
118 return array();
119 }
120 }
121
122 function get_scire_user($userid) {
123 global $db;
124 $result = $db->select('*', 'users', '`userid` = ' . $userid . '');
125 if ($result && count($result) > 0) {
126 return $result[0];
127 } else {
128 return false;
129 }
130 }
131
132 function scire_add_user($username, $password, $real_name, $comment, $email, $phone, $pager) {
133 global $db;
134 $result = $db->insert('users', array('username' => $username, 'password' => crypt($password, 447470567), 'comment' => $comment, 'real_name' => $real_name, 'email' => $email, 'phone' => $phone, 'pager' => $pager));
135 if ($result) {
136 return true;
137 } else {
138 return $db->error;
139 }
140 }
141
142 function scire_edit_user($userid, $fields) {
143 global $db;
144 $result = $db->update('users', $fields, '`userid` = \'' . $userid . '\'');
145 if ($result) {
146 return true;
147 } else {
148 return $db->error;
149 }
150 }
151
152 function scire_del_user($userid) {
153 global $db;
154 $result = $db->delete('users', '`userid` = \'' . $userid . '\'');
155 if ($result) {
156 return true;
157 } else {
158 return $db->error;
159 }
160 }
161
162 function scire_add_permission($perm_name, $desc, $created_by) {
163 global $db;
164 $result = $db->insert('permissions', array('perm_name' => $perm_name, 'description' => $desc, 'creator' => $created_by));
165 if ($result) {
166 return true;
167 } else {
168 return $db->error;
169 }
170 }
171
172 function scire_edit_permission($perm_name, $desc) {
173 global $db;
174 $result = $db->update('permissions', array('description' => $desc), '`perm_name` = \'' . $perm_name . '\'');
175 if ($result) {
176 return true;
177 } else {
178 return $db->error;
179 }
180 }
181
182 function scire_del_permission($perm_name) {
183 global $db;
184 $result = $db->delete('permissions', '`perm_name` = \'' . $perm_name . '\'');
185 if ($result) {
186 return true;
187 } else {
188 return $db->error;
189 }
190 }
191
192 function get_scire_permissions() {
193 global $db;
194 $result = $db->select('*', 'permissions');
195 if ($result && count($result) > 0) {
196 return $result;
197 } else {
198 return array();
199 }
200 }
201
202 function get_scire_gli_profiles() {
203 global $db;
204 $result = $db->select(array('profile_name','profileid'), 'GLI_profiles');
205 if ($result && count($result) > 0) {
206 return $result;
207 } else {
208 return array();
209 }
210 }
211
212 function get_scire_oss() {
213 global $db;
214 $result = $db->select(array('osname','osid'), 'os');
215 if ($result && count($result) > 0) {
216 return $result;
217 } else {
218 return array();
219 }
220 }
221
222 ?>

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20