~budgester/irm/trunk

« back to all changes in this revision

Viewing changes to include/setup-templates.class.php

  • Committer: budgester at budgester
  • Date: 2008-03-05 23:14:13 UTC
  • Revision ID: budgester@budgester.com-20080305231413-k5vqfuckfo09ju42
Initial import of IRM codebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
#    IRM - The Information Resource Manager
 
3
#    Copyright (C) 2006 Martin Stevens
 
4
#
 
5
#    This program is free software; you can redistribute it and/or modify
 
6
#    it under the terms of the GNU General Public License as published by
 
7
#    the Free Software Foundation; either version 2 of the License, or
 
8
#    (at your option) any later version.
 
9
#
 
10
#    This program is distributed in the hope that it will be useful,
 
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#    GNU General Public License (in file COPYING) for more details.
 
14
#
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with this program; if not, write to the Free Software
 
17
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
#
 
19
################################################################################
 
20
 
 
21
class setupTemplates{
 
22
 
 
23
        function setupTemplates()
 
24
        {
 
25
                $this->ID = $_REQUEST['ID'];
 
26
 
 
27
                switch($_REQUEST['action']){
 
28
                case 'add':
 
29
                        $this->add();
 
30
                        break;          
 
31
                case 'addform':
 
32
                        $this->addForm();
 
33
                        break;
 
34
                case 'edit':
 
35
                        $this->edit();
 
36
                        break;
 
37
                case 'update':
 
38
                        $this->update();
 
39
                        break;
 
40
                case 'delete':
 
41
                        $this->delete();
 
42
                        break;
 
43
                default:
 
44
                        $this->main();
 
45
                        break;
 
46
                }
 
47
        }
 
48
        
 
49
        function setVals(){
 
50
                $this->vals = array(
 
51
                        'templname' => $_REQUEST['templname'],
 
52
                        'name' => $_REQUEST['name'],
 
53
                        'type' => $_REQUEST['type'],
 
54
                        'flags_server' => $_REQUEST['flags_server'],
 
55
                        'os' => $_REQUEST['os'],
 
56
                        'osver' => $_REQUEST['osver'],
 
57
                        'processor' => $_REQUEST['processor'],
 
58
                        'processor_speed' => $_REQUEST['processor_speed'],
 
59
                        'location' => $_REQUEST['location'],
 
60
                        'serial' => $_REQUEST['serial'],
 
61
                        'otherserial' => $_REQUEST['otherserial'],
 
62
                        'ramtype' => $_REQUEST['ramtype'],
 
63
                        'ram' => $_REQUEST['ram'],
 
64
                        'network' => $_REQUEST['network'],
 
65
                        'ip' => $_REQUEST['ip'],
 
66
                        'mac' => $_REQUEST['mac'],
 
67
                        'hdspace' => $_REQUEST['hdspace'],
 
68
                        'contact' => $_REQUEST['contact'],
 
69
                        'contact_num' => $_REQUEST['contact_num'],
 
70
                        'comments' => $_REQUEST['comments'],
 
71
                        'iface' => $_REQUEST['iface'],
 
72
                        'flags_surplus' => $_REQUEST['flags_surplus']
 
73
                        );
 
74
        }
 
75
 
 
76
        function update(){
 
77
                AuthCheck("tech");
 
78
 
 
79
                $flags_server = Computer::Flags(@$flags_server);
 
80
                $flags_surplus = Computer::Flags(@$flags_surplus);
 
81
 
 
82
                $this->setVals();
 
83
 
 
84
                $DB = Config::Database();
 
85
                $ID = $DB->getTextValue($ID);
 
86
                $DB->UpdateQuery('templates', $this->vals, "ID=$this->ID");
 
87
                $this->main();
 
88
        }
 
89
 
 
90
        function edit(){
 
91
                AuthCheck("tech");
 
92
 
 
93
                commonHeader(_("Setup") . " - " . _("Templates Editor"));
 
94
 
 
95
                $DB = Config::Database();
 
96
                $qID = $DB->getTextValue($this->ID);
 
97
                $query = "SELECT * FROM templates WHERE (ID = $qID)";
 
98
                $DB = Config::Database();
 
99
                $result = $DB->getRow($query);
 
100
                $ID = $result["ID"];
 
101
                $templname = $result["templname"];
 
102
                $name = $result["name"];
 
103
                $type = $result["type"];
 
104
                $os = $result["os"];
 
105
                $osver = $result["osver"];
 
106
                $processor = $result["processor"];
 
107
                $processor_speed = $result["processor_speed"];
 
108
                $location = $result["location"];
 
109
                $serial = $result["serial"];
 
110
                $otherserial = $result["otherserial"];
 
111
                $ramtype = $result["ramtype"];
 
112
                $ram = $result["ram"];
 
113
                $network = $result["network"];
 
114
                $ip = $result["ip"];
 
115
                $mac = $result["mac"];
 
116
                $hdspace = $result["hdspace"];
 
117
                $contact = $result["contact"];
 
118
                $contact_num = $result["contact_num"];
 
119
                $comments = $result["comments"];
 
120
                $flags_server = $result["flags_server"];
 
121
                $flags_surplus = $result["flags_surplus"];
 
122
                $new_date = date("Y-m-d H:i:s");
 
123
                $iface = $result["iface"];
 
124
 
 
125
                $vals = array(
 
126
                        'ID' => $ID,
 
127
                        'name' => $name,
 
128
                        'type' => $type,
 
129
                        'flags_server' => $flags_server,
 
130
                        'flags_surplus' => $flags_surplus,
 
131
                        'os' => $os,
 
132
                        'osver' => $osver,
 
133
                        'processor' => $processor,
 
134
                        'processor_speed' => $processor_speed,
 
135
                        'location' => $location,
 
136
                        'serial' => $serial,
 
137
                        'otherserial' => $otherserial,
 
138
                        'ramtype' => $ramtype,
 
139
                        'ram' => $ram,
 
140
                        'network' => $network,
 
141
                        'ip' => $ip,
 
142
                        'mac' => $mac,
 
143
                        'hdspace' => $hdspace,
 
144
                        'contact' => $contact,
 
145
                        'contact_num' => $contact_num,
 
146
                        'comments' => $comments,
 
147
                        'date_mod' => $date_mod
 
148
                        );
 
149
 
 
150
                $new_date = date("Y-m-d H:i:s");
 
151
 
 
152
                if (!@$contact)
 
153
                {
 
154
                        $contact = '';
 
155
                }
 
156
                if (!@$contact_num)
 
157
                {
 
158
                        $contact_num = '';
 
159
                }
 
160
 
 
161
                printf(_('Use this form to edit template "%s".'), $templname);
 
162
                PRINT '<a href="'.Config::AbsLoc('users/setup-templates-index.php').'">'._("Back to Templates").'</a><br>';
 
163
                PRINT "<table>";
 
164
                PRINT '<form method=post action="'.Config::AbsLoc('users/setup-templates-index.php').'">';
 
165
                PRINT '<input type="hidden" name="action" value="update">';
 
166
                PRINT '<tr class="setupheader">';
 
167
                PRINT '<th colspan=2>';
 
168
                PRINT _("Editing Template");
 
169
                PRINT "<input type=hidden name=ID value=\"$ID\">";
 
170
                PRINT "<input type=text name=templname value=\"$templname\" size=40>";
 
171
                PRINT "</th>";
 
172
                PRINT "</tr>";
 
173
 
 
174
                PRINT '<tr class="setupdetail">';
 
175
                #PRINT "<td>"._("Name:")."<br><input type=text name=name value=\"$name\" size=24></td>";
 
176
                #PRINT "<td>"._("Type").":<br>";
 
177
                #PRINT Dropdown_value("dropdown_type", "type", $type);
 
178
                #PRINT "</td>";
 
179
                PRINT "</tr>";
 
180
 
 
181
                Computer::computerForm($vals);
 
182
 
 
183
                PRINT '<tr class="setupupdate">';
 
184
                PRINT "<td><input type=submit value=\""._("Update")."\"></td>";
 
185
                PRINT "<td><input type=Reset value=\""._("Reset")."\"></form></td>";
 
186
                PRINT "</tr>";
 
187
                PRINT "</table>";
 
188
                PRINT "<br>";
 
189
                templcompsoftShow($ID);
 
190
                PRINT "<br>";   
 
191
        }
 
192
        
 
193
        function add(){
 
194
                AuthCheck("tech");
 
195
 
 
196
                # $flags_server = serverFlags(@$flags_server);
 
197
                # $flags_surplus = surplusFlags(@$flags_surplus);
 
198
                if ($flags_server = "")
 
199
                {
 
200
                        $flags_server = "0";
 
201
                }
 
202
 
 
203
                $this->setVals();
 
204
 
 
205
                
 
206
                $DB = Config::Database();
 
207
                $DB->InsertQuery('templates', $this->vals);
 
208
                $this->main();
 
209
        }
 
210
 
 
211
        function delete(){
 
212
                AuthCheck("tech");
 
213
                $DB = Config::Database();
 
214
                $ID = $DB->getTextValue($this->ID);
 
215
                $query = "DELETE FROM templates WHERE (ID = $ID)";
 
216
                $DB->query($query);
 
217
                $query = "DELETE FROM templ_inst_software WHERE (cID = $ID)";
 
218
                $DB->query($query);
 
219
                $this->main();
 
220
        }
 
221
        
 
222
        function main(){
 
223
                AuthCheck("admin");
 
224
                commonHeader(_("Setup - Computer Templates"));
 
225
                $this->templatesList();
 
226
                commonFooter();
 
227
        }
 
228
 
 
229
        function addForm(){
 
230
                AuthCheck("tech");
 
231
 
 
232
                commonHeader(_("Setup") . " - " . _("Templates Add Form"));
 
233
 
 
234
                if ($add == 1) 
 
235
                {
 
236
                  PRINT "<h3>";
 
237
                  __("Template Added Successfuly");
 
238
                  PRINT "</h3>";
 
239
                  PRINT "<hr noshade>";
 
240
                }
 
241
 
 
242
                $new_date = date("Y-m-d H:i:s");
 
243
 
 
244
                __("Use this form to add a template.");
 
245
                PRINT '<a href="'.Config::AbsLoc('users/setup-templates-index.php').'">' . _("Back to Templates") . '</a>';
 
246
                PRINT '<br>';
 
247
                PRINT '<table>';
 
248
                PRINT '<form method=post action="'.Config::AbsLoc('users/setup-templates-index.php').'">';
 
249
                PRINT '<input type="hidden" name="action" value="add">';
 
250
                PRINT '<tr class="computerheader">';
 
251
                PRINT '<td colspan=2>';
 
252
                PRINT "<strong>";
 
253
                __("Add Template");
 
254
                PRINT "<input type=text name=templname value=\"$templname\" size=40></strong>";
 
255
                PRINT "</td>";
 
256
                PRINT "</tr>";
 
257
 
 
258
                PRINT '<tr class="setupdetail">';
 
259
                #PRINT "<td>" ._("Name:") . "<br><input type=text name=name value=\"$name\" size=24></td>";
 
260
                #PRINT "<td>" . _("Type") . ":<br>";
 
261
                #PRINT Dropdown_value("dropdown_type", "type", $type);
 
262
                #PRINT "</td>";
 
263
                PRINT "</tr>";
 
264
 
 
265
                Computer::computerForm("");
 
266
 
 
267
                PRINT '<tr class="setupdetail">';
 
268
                PRINT "<td><input type=submit value=Add></td>";
 
269
                PRINT "<td><input type=Reset value=Reset></form></td>";
 
270
                PRINT "</tr>";
 
271
                PRINT "</table>";
 
272
                __("If you wish to add software to this template, you must do so by editing it.");
 
273
 
 
274
                commonFooter();
 
275
        }
 
276
        
 
277
        function templatesList()
 
278
        {
 
279
                printf(_("Please select a template below to edit, delete, or <a href=\"%s\">add one</a>."),Config::AbsLoc('users/setup-templates-index.php?action=addform'));
 
280
 
 
281
                $query = "SELECT * FROM templates";
 
282
                $DB = Config::Database();
 
283
                $data = $DB->getAll($query);
 
284
 
 
285
                $data = orderTemplateList($data);
 
286
 
 
287
                PRINT "<table>";
 
288
                PRINT "<tr>";
 
289
                PRINT "<th colspan=2>" . _("Computer Templates") . "</th>";
 
290
                PRINT "</tr>\n";
 
291
 
 
292
                foreach ($data as $result)
 
293
                {
 
294
                        $ID = $result["ID"];
 
295
                        $name = $result["templname"];
 
296
                        PRINT '<tr class="setupdetail">';
 
297
                        PRINT '<td><a href="' . Config::AbsLoc("users/setup-templates-index.php?action=edit&ID=$ID")    . "\">$name</a></td>";
 
298
                        PRINT '<td><a href="' . Config::AbsLoc("users/setup-templates-index.php?action=delete&ID=$ID") . '">['. _("Delete"). ']</a></td>';
 
299
                        PRINT '</tr>';
 
300
                }
 
301
                PRINT "</table>";
 
302
        }
 
303
 
 
304
 
 
305
 
 
306
}
 
307
?>