root/modules/branches/2.3/customerdb/page.customerdb.php

Revision 3204, 10.4 kB (checked in by gregmac, 6 years ago)

Updated for changes in r3203: only pass identifying variable on edit, and explicitly pass extdisplay if needed (as it is no longer included by default)

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 <?php
2 //CustomerDB 1.00 written by Keith Dowell 2006-04-07
3 //Copyright (C) 2006 Keith Dowell (snowolfex@yahoo.com)
4 //
5 //This program is free software; you can redistribute it and/or
6 //modify it under the terms of the GNU General Public License
7 //as published by the Free Software Foundation; either version 2
8 //of the License, or (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 for more details.
14
15 //Set all the vars so there arent a ton of errors in the httpd error_log
16
17 $display = isset($_REQUEST['display'])?$_REQUEST['display']:'customerdb';
18 $type = isset($_REQUEST['type'])?$_REQUEST['type']:'tool';
19
20 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
21 $name = isset($_REQUEST['name'])?$_REQUEST['name']:'';
22 $addr1 = isset($_REQUEST['addr1'])?$_REQUEST['addr1']:'';
23 $addr2 = isset($_REQUEST['addr2'])?$_REQUEST['addr2']:'';
24 $city = isset($_REQUEST['city'])?$_REQUEST['city']:'';
25 $state = isset($_REQUEST['state'])?$_REQUEST['state']:'LA';
26 $zip = isset($_REQUEST['zip'])?$_REQUEST['zip']:'';
27 $sip = isset($_REQUEST['sip'])?$_REQUEST['sip']:'';
28 $did = isset($_REQUEST['did'])?$_REQUEST['did']:'';
29 $device = isset($_REQUEST['device'])?$_REQUEST['device']:'';
30 $ip = isset($_REQUEST['ip'])?$_REQUEST['ip']:'';
31 $serial = isset($_REQUEST['serial'])?$_REQUEST['serial']:'';
32 $account = isset($_REQUEST['account'])?$_REQUEST['account']:'';
33 $email = isset($_REQUEST['email'])?$_REQUEST['email']:'';
34 $username = isset($_REQUEST['username'])?$_REQUEST['username']:'';
35 $password = isset($_REQUEST['password'])?$_REQUEST['password']:'';
36
37 extract($_REQUEST);
38
39 $dispnum='customerdb';
40
41 if(!isset($action))
42   $action='';
43 switch($action) {
44   case "add":
45     customerdb_add($name, $addr1, $addr2, $city, $state, $zip, $sip, $did, $device, $ip, $serial, $account, $email, $username, $password);
46     $name='';
47     $addr1='';
48     $addr2='';
49     $city='';
50     $state='';
51     $zip='';
52     $sip='';
53     $did='';
54     $ip='';
55     $serial='';
56     $account='';
57     $email='';
58     $device='';
59     $username='';
60     $password='';
61     //needreload();
62     //right now... not writing config files... don't need to reload
63     redirect_standard();
64   break;
65   case "del":
66     customerdb_del($extdisplay);
67     //needreload();
68     redirect_standard();
69   break;
70   case "edit":
71     customerdb_edit($extdisplay, $name, $addr1, $addr2, $city, $state, $zip, $sip, $did, $device, $ip, $serial, $account, $email, $username, $password);
72     //needreload();
73     redirect_standard('extdisplay');
74   break;
75  
76 }
77 ?>
78 </div>
79 <div class="rnav">
80 <?php
81 $customers=customerdb_list();
82 drawListMenu($customers, $skip, $type, $dispnum, $extdisplay, _("Customer"));
83 ?>
84 </div>
85
86
87 <div class="content">
88 <?php
89 if($action=='del'){
90   echo "<br><h3>ID ".$extdisplay." "._("deleted")."!</h3><br><Br><br><br><br><br><br>";
91 }
92 else if(!isset($extdisplay)) {
93
94    
95   echo "<h2>Add a user</h2>";
96 //  echo "<li><a href=\"".$_SERVER['PHP_SELF']."?$action=add\";>Add</a><br>";
97
98 }
99 else {
100   $delURL = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."&action=del&extdisplay=$extdisplay";
101
102   //If we have some data, load it up... this means we are editing.
103   if($extdisplay!=""){
104     $customerInfo=customerdb_get($extdisplay);
105     $name=$customerInfo['name'];
106     $addr1=$customerInfo['addr1'];
107     $addr2=$customerInfo['addr2'];
108     $city=$customerInfo['city'];
109     $state=$customerInfo['state'];
110     $zip=$customerInfo['zip'];
111     $sip=$customerInfo['sip'];
112     $did=$customerInfo['did'];
113     $device=$customerInfo['device'];
114     $serial=$customerInfo['serial'];
115     $ip=$customerInfo['ip'];
116     $account=$customerInfo['account'];
117     $email=$customerInfo['email'];
118     $username=$customerInfo['username'];
119     $password=$customerInfo['password'];
120   }
121    
122  
123   if(isset($customerInfo) && is_array($customerInfo)){
124     $action="edit";
125     echo "<h2> ".$extdisplay." ".$name."</h2>";
126     echo "<p><a href=\"".$delURL."\">Delete Customer</a></p>";
127   }
128   else {
129     echo "<h2>Add Customer</h2>";
130   }
131
132 }
133
134 echo "<form name=\"addNew\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" onsubmit=\"return addNew_onsubmit();\">";
135 echo "<input type=hidden name=type value='tool'>\n";
136 echo "<input type=hidden name=extdisplay value=$extdisplay>\n";
137 echo "<input type=hidden name=action value=\"";
138 echo ($action=="" ? "add" : $action);
139 echo "\">\n";
140 echo "<input type=hidden name=display value=\"customerdb\">";
141
142 echo "<table>";
143  
144 echo "<tr><td colspan=2><h5>";
145 echo ($extdisplay ? _('Edit Customer') : _('Add Customer'));
146 echo "</h5></td></tr>\n";
147
148 //Name
149 echo "<tr ";
150 echo ($extdisplay ? '' : '');
151 echo "><td>";
152 echo "<a href=\"#\" class=\"info\">Name\n";
153 echo "<span>Name of business or person (REQUIRED)</span></a>\n";
154 echo "</td>";
155 echo "<td>";
156 echo "<input type=text name=\"name\" value=\"$name\">\n";
157 echo "</td></tr>\n";
158
159 //Address Line 1
160 echo "<tr><td>\n";
161 echo "<a href=\"#\" class=\"info\">Address 1\n";
162 echo "<span>Address Line 1 (REQUIRED)</span></a>\n";
163 echo "</td><td>\n";
164 echo "<input type=text name=\"addr1\" value=\"$addr1\"\n";
165 echo "</td></tr>\n";
166
167 //Address Line 2
168 echo "<tr><td>\n";
169 echo "<a href=\"#\" class=\"info\">Address 2\n";
170 echo "<span>Address Line 2</span></a>\n";
171 echo "</td><td>\n";
172 echo "<input type=text name=\"addr2\" value=\"$addr2\">\n";
173 echo "</td><tr>\n";
174
175 //City
176 echo "<tr><td>\n";
177 echo "<a href=\"#\" class=\"info\">City\n";
178 echo "<span>City (REQUIRED)</span></a>\n";
179 echo "</td><td>\n";
180 echo "<input type=text name=\"city\" value=\"$city\">\n";
181 echo "</td></tr>\n";
182
183 //State
184 echo "<tr><td>\n";
185 echo "<a href=\"#\" class=\"info\">State\n";
186 echo "<span>State (REQUIRED)</span></a>\n";
187 echo "</td><td>\n";
188 $state=($extdisplay ? $state : "LA");
189 $states = array('AL', 'AK', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA', 'HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA', 'MA','MD', 'ME', 'MI', 'MN', 'MO', 'MS', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM', 'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'PR', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VA', 'VT', 'WA', 'WV', 'WI', 'WY', 'TAS', 'VIC', 'NSW', 'ACT', 'QLD', 'NT', 'SA');
190 echo "&nbsp;&nbsp;<select name=\"state\">\n";
191 foreach ($states as $s){
192   echo "<option value=\"$s\"";
193   if($state==$s) echo " SELECTED";
194   echo ">$s</option>\n";
195 }
196 echo "</select>\n";
197 echo "</td></tr>\n";
198
199 //Zip
200 echo "<tr><td>\n";
201 echo "<a href=\"#\" class=\"info\">Zip/Post Code\n";
202 echo "<span>Zip (REQUIRED)</span></a>\n";
203 echo "</td><td>\n";
204 echo "<input type=text name=\"zip\" value=\"$zip\">\n";
205 echo "</td></tr>\n";
206
207 //Sip
208 echo "<tr><td align=left>\n";
209 echo "<input type=radio checked name=\"sipbtn\" onclick=\"switchit_sip();return true;\"><a
210 href=\"#\" class=\"info\">Sip Account\n";
211 echo "<span>Sip Account <font size=-1>(must have this or a did tied to the account)</font></span></a>\n";
212 echo "</td><td>\n";
213 $sips=customerdb_getsip();
214 echo "&nbsp;&nbsp;<select name=\"sip\" onchange=\"switchit_sip(); return true;\">\n";
215 echo "<option value=\"\">";
216 foreach ($sips as $sipid){
217   echo "<option value=\"$sipid[0]\"";
218   if($sip==$sipid[0]) echo " SELECTED";
219   echo ">$sipid[0]</option>\n";
220 }
221 echo "</select>\n";
222 echo "</td></tr>\n";
223
224 //Did
225 echo "<tr><td>\n";
226 echo "<input type=radio name=\"didbtn\" onclick=\"switchit_did();return true;\"><a href=\"#\" class=\"info\">DID
227 Number\n";
228 echo "<span>DID Number <font size=-1>(must have this or sip tied to the account)</font></span></a>\n";
229 echo "</td><td>\n";
230 $dids=customerdb_getdid();
231 echo "&nbsp;&nbsp;<select name=\"did\" onchange=\"switchit_did(); return true;\">\n";
232 echo "<option value=\"\">";
233 foreach ($dids as $didnum){
234   echo "<option value=\"$didnum[0]\"";
235   if($did==$didnum[0]) echo " SELECTED";
236   echo ">$didnum[0]</option>\n";
237 }
238 echo "</select>\n";
239 echo "</td></tr>\n";
240
241 //Device
242 echo "<tr><td>\n";
243 echo "<a href=\"#\" class=\"info\">Device\n";
244 echo "<span>Device <font size=-1>(example... Linksys PAP-2, Sipura)</font></span></a>\n";
245 echo "</td><td>\n";
246 echo "<input type=text name=\"device\" value=\"$device\">\n";
247 echo "</td></tr>\n";
248
249 //Serial
250 echo "<tr><td>\n";
251 echo "<a href=\"#\" class=\"info\">Serial\n";
252 echo "<span>Serial Number</span></a>\n";
253 echo "</td><td>\n";
254 echo "<input name=\"serial\" value=\"$serial\">\n";
255 echo "</td></tr>\n";
256
257 //IP
258 echo "<tr><td>\n";
259 echo "<a href=\"#\" class=\"info\">IP Address\n";
260 echo "<span>IP Address </font></span></a>\n";
261 echo "</td><td>\n";
262 echo "<input type=text name=\"ip\" value=\"$ip\">\n";
263 echo "</td></tr>\n";
264
265 //Account
266 echo "<tr><td>\n";
267 echo "<a href=\"#\" class=\"info\">Account\n";
268 echo "<span>Account Number (internal use)</span></a>\n";
269 echo "</td><td>\n";
270 echo "<input name=\"account\" value=\"$account\">\n";
271 echo "</td></tr>\n";
272
273 //Email
274 echo "<tr><td>\n";
275 echo "<a href=\"#\" class=\"info\">Email\n";
276 echo "<span>Email Address</span></a>\n";
277 echo "</td><td>\n";
278 echo "<input name=\"email\" value=\"$email\">\n";
279 echo "</td></tr>\n";
280
281 //Username
282 echo "<tr><td>\n";
283 echo "<a href=\"#\" class=\"info\">Username\n";
284 echo "<span>Username for the device</span></a>\n";
285 echo "</td><td>\n";
286 echo "<input name=\"username\" value=\"$username\">\n";
287 echo "</td></tr>\n";
288
289 //Password
290 echo "<tr><td>\n";
291 echo "<a href=\"#\" class=\"info\">Password\n";
292 echo "<span>Password for device</span></a>\n";
293 echo "</td><td>\n";
294 echo "<input name=\"password\" value=\"$password\">\n";
295 echo "</td></tr>\n";
296
297 ?>
298 <tr><td></td><td><input type=submit Value="Submit Changes"></td></tr></table>
299
300 <script language="javascript">
301 var cform = document.addNew;
302 if(cform.name.value == ""){
303   cform.name.focus();
304 }
305
306 if(cform.did.selectedIndex>0){
307   cform.sipbtn.checked=false;
308   cform.didbtn.checked=true;
309 }
310 else{
311   if(cform.sip.selectedIndex>0){
312     cform.sipbtn.checked=true;
313     cform.didbtn.checked=false;
314   }
315   else{
316     cform.sipbtn.checked=false;
317     cform.didbtn.selected=false;
318   }
319 }
320
321
322 function addNew_onsubmit() {
323   if(isEmpty(cform.name.value)){
324     return warnInvalid(cform.name, "Please enter a name for this customer");
325   }
326   if(isEmpty(cform.addr1.value)){
327     return warnInvalid(cform.addr1, "Please enter an address for this customer");
328   }
329   if(isEmpty(cform.city.value)){
330     return warnInvalid(cform.city, "Pleast enter a city for this customer");
331   }
332   if(isEmpty(cform.zip.value)){
333     return warnInvalid(cform.zip, "Please enter a zip for this customer");
334   }
335   if(cform.sip.selectedIndex==0 && cform.did.selectedIndex==0){
336     return warnInvalid(cform.sipbtn, "You must choose either a sip or did number for this customer.");
337   }
338 }
339
340 function switchit_sip() {
341   cform.sipbtn.checked=true;
342   cform.didbtn.checked=false;
343   cform.did[0].selected=true;
344 }
345
346 function switchit_did() {
347   cform.sipbtn.checked=false;
348   cform.didbtn.checked=true;
349   cform.sip[0].selected=true;
350 }
351
352 </script>
353
354
355
356 </form>
Note: See TracBrowser for help on using the browser.