root/contributed_modules/modules/bulkextensions/page.bulkextensions.php

Revision 10599, 39.4 kB (checked in by mickecarlsson, 2 years ago)

Re #4649 updated bulkextensions for FreePBX 2.9

Line 
1 <?php
2 //This file is part of FreePBX.
3 //
4 //    FreePBX is free software: you can redistribute it and/or modify
5 //    it under the terms of the GNU General Public License as published by
6 //    the Free Software Foundation, either version 2 of the License, or
7 //    (at your option) any later version.
8 //
9 //    FreePBX is distributed in the hope that it will be useful,
10 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //    GNU General Public License for more details.
13 //
14 //    You should have received a copy of the GNU General Public License
15 //    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>.
16 //
17 //    Copyright 2006 Seth Sargent, Steven Ward
18 //    Portions Copyright 2009, 2010 Mikael Carlsson, mickecamino@gmail.com
19 //
20 // This is a long running process, so extend time limit for execution.
21 // Typical PHP default is 30 seconds, but this only allows 100 to 200
22 // extensions to be processed. Setting time limit to 3000 seconds allows
23 // 10000 to 20000 extensions to be processed.
24 set_time_limit(3000);
25 // $change is used as a flag whether or not a reload is needed. If no changes
26 // are made, no reload will be prompted.
27 $change = false;
28 $output = "";
29 $action = isset($_REQUEST["csv_type"])?$_REQUEST["csv_type"]:'';
30
31 if ($action == "output") {
32   exportextensions_allusers();
33 } elseif ($action == "input") {
34   // Set email notification variables
35   if (isset($_REQUEST["default_email"])) {
36     $default_email = $_REQUEST["default_email"];
37   } else {
38     $default_email = "";
39   }
40   if (isset($_REQUEST["override_email"])) {
41     $override_email = $_REQUEST["override_email"];
42   } else {
43     $override_email = "";
44   }
45   if (isset($_REQUEST["email_from"])) {
46     $email_from = $_REQUEST["email_from"];
47   } else {
48     $email_from = "";
49   }
50   if (isset($_REQUEST["email_replyto"])) {
51     $email_replyto = $_REQUEST["email_replyto"];
52   } else {
53     $email_replyto = "";
54   }
55   if (isset($_REQUEST["email_subject"])) {
56     $email_subject = $_REQUEST["email_subject"];
57   } else {
58     $email_subject = "";
59   }
60   if (isset($_REQUEST["email_body_open"])) {
61     $email_body_open = $_REQUEST["email_body_open"];
62   } else {
63     $email_body_open = "";
64   }
65   if (isset($_REQUEST["email_body_close"])) {
66     $email_body_close = $_REQUEST["email_body_close"];
67   } else {
68     $email_body_close = "";
69   }
70   $line_end = "\n";
71
72     $aFields = array (
73       "action" => array(false, -1),
74       "extension" => array(false, -1),
75       "name" => array(false, -1),
76       "cid_masquerade" => array(false, -1),
77       "sipname" => array(false, -1),
78       "outboundcid" => array(false, -1),
79       "ringtimer" => array(false, -1),
80       "callwaiting" => array(false, -1),
81       "call_screen" => array(false, -1),
82       "pinless" => array(false, -1),
83       "password" => array(false, -1),
84       "noanswer_dest" => array(false, -1),
85       "noanswer_cid" => array(false, -1),
86       "busy_dest" => array(false, -1),
87       "busy_cid" => array(false, -1),
88       "chanunavail_dest" => array(false, -1),
89       "chanunavail_cid" => array(false, -1),
90       "emergency_cid" => array(false, -1),
91       "tech" => array(false, -1),
92       "hardware" => array(false, -1),
93       "devinfo_channel" => array(false, -1),    // for zap devices
94       "devinfo_secret" => array(false, -1),
95       "devinfo_notransfer" => array(false, -1),   // for iax2 devices
96       "devinfo_dtmfmode" => array(false, -1),     // used in core\core_devices_add<sip|zap|iax2>()
97       "devinfo_canreinvite" => array(false, -1),  // used in core\core_devices_add<sip|zap|iax2>()
98       "devinfo_context" => array(false, -1),
99       "devinfo_immediate" => array(false, -1),    // for zap devices
100       "devinfo_signalling" => array(false, -1),   // for zap devices
101       "devinfo_echocancel" => array(false, -1),   // for zap devices
102       "devinfo_echocancelwhenbridged" => array(false, -1),  // for zap devices
103       "devinfo_echotraining" => array(false, -1), // for zap devices
104       "devinfo_busydetect" => array(false, -1),   // for zap devices
105       "devinfo_busycount" => array(false, -1),    // for zap devices
106       "devinfo_callprogress" => array(false, -1),
107       "devinfo_host" => array(false, -1),
108       "devinfo_type" => array(false, -1),
109       "devinfo_nat" => array(false, -1),
110       "devinfo_port" => array(false, -1),
111       "devinfo_qualify" => array(false, -1),
112       "devinfo_callgroup" => array(false, -1),
113       "devinfo_pickupgroup" => array(false, -1),
114       "devinfo_disallow" => array(false, -1),
115       "devinfo_allow" => array(false, -1),
116       "devinfo_dial" => array(false, -1),
117       "devinfo_accountcode" => array(false, -1),
118       "devinfo_mailbox" => array(false, -1),
119       "devinfo_deny" => array(false, -1),
120       "devinfo_permit" => array(false, -1),
121       "devicetype" => array(false, -1),
122       "deviceid" => array(false, -1),
123       "deviceuser" => array(false, -1),
124       "description" => array(false, -1),
125       "dictenabled" => array(false, -1),
126       "dictformat" => array(false, -1),
127       "dictemail" => array(false, -1),
128       "langcode" => array(false, -1),
129       "record_in" => array(false, -1),
130       "record_out" => array(false, -1),
131       "vm" => array(false, -1),
132       "vmpwd" => array(false, -1),
133       "email" => array(false, -1),
134       "pager" => array(false, -1),
135       "attach" => array(false, -1),
136       "saycid" => array(false, -1),
137       "envelope" => array(false, -1),
138       "delete" => array(false, -1),
139       "options" => array(false, -1),
140       "vmcontext" => array(false, -1),
141       "vmx_state" => array(false, -1),
142       "vmx_unavail_enabled" => array(false, -1),
143       "vmx_busy_enabled" => array(false, -1),
144       "vmx_play_instructions" => array(false, -1),
145       "vmx_option_0_system_default" => array(false, -1),
146       "vmx_option_0_number" => array(false, -1),
147       "vmx_option_1_system_default" => array(false, -1),
148       "vmx_option_1_number" => array(false, -1),
149       "vmx_option_2_number" => array(false, -1),
150       "account" => array(false, -1),
151       "ddial" => array(false, -1),
152       "pre_ring" => array(false, -1),
153       "strategy" => array(false, -1),
154       "grptime" => array(false, -1),
155       "grplist" => array(false, -1),
156       "annmsg_id" => array(false, -1),
157       "ringing" => array(false, -1),
158       "grppre" => array(false, -1),
159       "dring" => array(false, -1),
160       "needsconf" => array(false, -1),
161       "remotealert_id" => array(false, -1),
162       "toolate_id" => array(false, -1),
163       "postdest" => array(false, -1),
164       "faxenabled" => array(false, -1),
165       "faxemail" => array(false, -1),
166       );
167
168       $fh = fopen($_FILES["csvFile"]["tmp_name"], "r");
169       if ($fh == NULL) {
170         $file_ok = FALSE;
171       } else {
172         $file_ok = TRUE;
173       }
174
175       $k = 0;
176
177       while ($file_ok && (($aInfo = fgetcsv($fh, 2000, ",", "\"")) !== FALSE)) {
178               $k++;
179         if (empty($aInfo[0])) {
180           continue;
181         }
182
183         // If this is the first row then we need to check each field listed (these are the headings)
184         if ($i==0) {
185           for ($j=0; $j<count($aInfo); $j++) {
186             $aKeys = array_keys($aFields);
187             foreach ($aKeys as $sKey) {
188               if ($aInfo[$j] == $sKey) {
189                 $aFields[$sKey][0] = true;
190                 $aFields[$sKey][1] = $j;
191               }
192             }
193           }
194           $i++;
195           $output .= "<BR><BR>Row $k: Headers parsed. <BR>";
196           continue;
197         }
198
199         if ($aFields["action"][0]) {
200           $vars["action"] = trim($aInfo[$aFields["action"][1]]);
201         }
202
203         if ($aFields["extension"][0]) {
204           $vars["extension"]  = trim($aInfo[$aFields["extension"][1]]);
205           $vars["extdisplay"] = trim($aInfo[$aFields["extension"][1]]);
206         }
207
208         if ($aFields["name"][0]) {
209           $vars["name"] = trim($aInfo[$aFields["name"][1]]);
210         }
211
212         if ($aFields["cid_masquerade"][0]) {
213           $vars["cid_masquerade"] = trim($aInfo[$aFields["cid_masquerade"][1]]);
214         }
215
216         if ($aFields["sipname"][0]) {
217           $vars["sipname"] = trim($aInfo[$aFields["sipname"][1]]);
218       }
219
220         if ($aFields["outboundcid"][0]) {
221           $vars["outboundcid"] = trim($aInfo[$aFields["outboundcid"][1]]);
222       }
223
224         if ($aFields["ringtimer"][0]) {
225           $vars["ringtimer"] = trim($aInfo[$aFields["ringtimer"][1]]);
226       }
227
228         if ($aFields["callwaiting"][0]) {
229           $vars["callwaiting"] = trim($aInfo[$aFields["callwaiting"][1]]);
230       }
231
232         if ($aFields["call_screen"][0]) {
233           $vars["call_screen"] = trim($aInfo[$aFields["call_screen"][1]]);
234       }
235
236         if ($aFields["pinless"][0]) {
237           $vars["pinless"] = trim($aInfo[$aFields["pinless"][1]]);
238       }
239
240         if ($aFields["password"][0]) {
241           $vars["password"] = trim($aInfo[$aFields["password"][1]]);
242       }
243
244         if ($aFields["noanswer_dest"][0]) {
245           $vars["noanswer_dest"] = trim($aInfo[$aFields["noanswer_dest"][1]]);
246       }
247
248         if ($aFields["noanswer_cid"][0]) {
249           $vars["noanswer_cid"] = trim($aInfo[$aFields["noanswer_cid"][1]]);
250       }
251
252         if ($aFields["busy_dest"][0]) {
253           $vars["busy_dest"] = trim($aInfo[$aFields["busy_dest"][1]]);
254       }
255
256         if ($aFields["busy_cid"][0]) {
257           $vars["busy_cid"] = trim($aInfo[$aFields["busy_cid"][1]]);
258       }
259
260         if ($aFields["chanunavail_dest"][0]) {
261           $vars["chanunavail_dest"] = trim($aInfo[$aFields["chanunavail_dest"][1]]);
262       }
263
264         if ($aFields["chanunavail_cid"][0]) {
265           $vars["chanunavail_cid"] = trim($aInfo[$aFields["chanunavail_cid"][1]]);
266       }   
267      
268         if ($aFields["emergency_cid"][0]) {
269           $vars["emergency_cid"] = trim($aInfo[$aFields["emergency_cid"][1]]);
270         }
271
272         if ($aFields["tech"][0]) {
273           $vars["tech"] = trim($aInfo[$aFields["tech"][1]]);
274         }
275
276               if ($aFields["hardware"][0]) {
277           $vars["hardware"] = trim($aInfo[$aFields["hardware"][1]]);
278         }
279
280         if ($aFields["devinfo_channel"][0]) {
281               if (!isset($aInfo[$aFields["devinfo_channel"][1]]) || ($aInfo[$aFields["devinfo_channel"][1]] == "")){
282                 unset($vars["devinfo_channel"]);
283             }
284               else {
285             $vars["devinfo_channel"] = trim($aInfo[$aFields["devinfo_channel"][1]]);
286             }
287         }
288
289         if ($aFields["devinfo_secret"][0]) {
290           $vars["devinfo_secret"] = trim($aInfo[$aFields["devinfo_secret"][1]]);
291         }
292
293         if ($aFields["devinfo_notransfer"][0]) {
294             if (!isset($aInfo[$aFields["devinfo_notransfer"][1]]) || ($aInfo[$aFields["devinfo_notransfer"][1]] == "")){
295                 unset($vars["devinfo_notransfer"]);
296             }
297               else {
298             $vars["devinfo_notransfer"] = trim($aInfo[$aFields["devinfo_notransfer"][1]]);
299             }
300         }
301
302         if ($aFields["devinfo_dtmfmode"][0]) {
303           $vars["devinfo_dtmfmode"] = trim($aInfo[$aFields["devinfo_dtmfmode"][1]]);
304         }
305
306         if ($aFields["devinfo_canreinvite"][0]) {
307           $vars["devinfo_canreinvite"] = trim($aInfo[$aFields["devinfo_canreinvite"][1]]);
308         }
309
310         if ($aFields["devinfo_context"][0]) {
311           $vars["devinfo_context"] = trim($aInfo[$aFields["devinfo_context"][1]]);
312         }
313
314         if ($aFields["devinfo_immediate"][0]) {
315             if (!isset($aInfo[$aFields["devinfo_immediate"][1]]) || ($aInfo[$aFields["devinfo_immediate"][1]] == "")){
316                 unset($vars["devinfo_immediate"]);
317             }
318               else {
319             $vars["devinfo_immediate"] = trim($aInfo[$aFields["devinfo_immediate"][1]]);
320             }
321         }
322
323         if ($aFields["devinfo_signalling"][0]) {
324             if (!isset($aInfo[$aFields["devinfo_signalling"][1]]) || ($aInfo[$aFields["devinfo_signalling"][1]] == "")){
325                 unset($vars["devinfo_signalling"]);
326             }
327               else {
328             $vars["devinfo_signalling"] = trim($aInfo[$aFields["devinfo_signalling"][1]]);
329             }
330         }
331
332         if ($aFields["devinfo_echocancel"][0]) {
333             if (!isset($aInfo[$aFields["devinfo_echocancel"][1]]) || ($aInfo[$aFields["devinfo_echocancel"][1]] == "")){
334                 unset($vars["devinfo_echocancel"]);
335             }
336               else {
337             $vars["devinfo_echocancel"] = trim($aInfo[$aFields["devinfo_echocancel"][1]]);
338             }
339         }
340
341         if ($aFields["devinfo_echocancelwhenbridged"][0]) {
342             if (!isset($aInfo[$aFields["devinfo_echocancelwhenbridged"][1]]) || ($aInfo[$aFields["devinfo_echocancelwhenbridged"][1]] == "")){
343                 unset($vars["devinfo_echocancelwhenbridged"]);
344             }
345               else {
346             $vars["devinfo_echocancelwhenbridged"] = trim($aInfo[$aFields["devinfo_echocancelwhenbridged"][1]]);
347             }
348         }
349
350         if ($aFields["devinfo_echotraining"][0]) {
351             if (!isset($aInfo[$aFields["devinfo_echotraining"][1]]) || ($aInfo[$aFields["devinfo_echotraining"][1]] == "")){
352                 unset($vars["devinfo_echotraining"]);
353             }
354               else {
355             $vars["devinfo_echotraining"] = trim($aInfo[$aFields["devinfo_echotraining"][1]]);
356             }
357         }
358
359         if ($aFields["devinfo_busydetect"][0]) {
360             if (!isset($aInfo[$aFields["devinfo_busydetect"][1]]) || ($aInfo[$aFields["devinfo_busydetect"][1]] == "")){
361                 unset($vars["devinfo_busydetect"]);
362             }
363               else {
364             $vars["devinfo_busydetect"] = trim($aInfo[$aFields["devinfo_busydetect"][1]]);
365             }
366         }
367
368         if ($aFields["devinfo_busycount"][0]) {
369             if (!isset($aInfo[$aFields["devinfo_busycount"][1]]) || ($aInfo[$aFields["devinfo_busycount"][1]] == "")){
370                 unset($vars["devinfo_busycount"]);
371             }
372               else {
373             $vars["devinfo_busycount"] = trim($aInfo[$aFields["devinfo_busycount"][1]]);
374             }
375         }
376
377         if ($aFields["devinfo_callprogress"][0]) {
378             if (!isset($aInfo[$aFields["devinfo_callprogress"][1]]) || ($aInfo[$aFields["devinfo_callprogress"][1]] == "")){
379                 unset($vars["devinfo_callprogress"]);
380             }
381               else {
382             $vars["devinfo_callprogress"] = trim($aInfo[$aFields["devinfo_callprogress"][1]]);
383             }
384         }
385
386         if ($aFields["devinfo_host"][0]) {
387           $vars["devinfo_host"] = trim($aInfo[$aFields["devinfo_host"][1]]);
388         }
389
390         if ($aFields["devinfo_type"][0]) {
391           $vars["devinfo_type"] = trim($aInfo[$aFields["devinfo_type"][1]]);
392         }
393
394         if ($aFields["devinfo_nat"][0]) {
395           $vars["devinfo_nat"] = trim($aInfo[$aFields["devinfo_nat"][1]]);
396         }
397
398         if ($aFields["devinfo_port"][0]) {
399           $vars["devinfo_port"] = trim($aInfo[$aFields["devinfo_port"][1]]);
400         }
401
402         if ($aFields["devinfo_qualify"][0]) {
403           $vars["devinfo_qualify"] = trim($aInfo[$aFields["devinfo_qualify"][1]]);
404         }
405
406         if ($aFields["devinfo_callgroup"][0]) {
407               if (!isset($aInfo[$aFields["devinfo_callgroup"][1]]) || ($aInfo[$aFields["devinfo_callgroup"][1]] == "")){
408                 unset($vars["devinfo_callgroup"]);
409             }
410               else {
411             $vars["devinfo_callgroup"] = trim($aInfo[$aFields["devinfo_callgroup"][1]]);
412             }
413         }
414
415         if ($aFields["devinfo_pickupgroup"][0]) {
416               if (!isset($aInfo[$aFields["devinfo_pickupgroup"][1]]) || ($aInfo[$aFields["devinfo_pickupgroup"][1]] == "")){
417               unset($vars["devinfo_pickupgroup"]);
418               }
419               else {
420                    $vars["devinfo_pickupgroup"] = trim($aInfo[$aFields["devinfo_pickupgroup"][1]]);
421                    }
422         }
423
424         if ($aFields["devinfo_disallow"][0]) {
425               if (!isset($aInfo[$aFields["devinfo_disallow"][1]]) || ($aInfo[$aFields["devinfo_disallow"][1]] == "")){
426               unset($vars["devinfo_disallow"]);
427               }
428               else {
429                    $vars["devinfo_disallow"] = trim($aInfo[$aFields["devinfo_disallow"][1]]);
430                    }
431         }
432
433         if ($aFields["devinfo_allow"][0]) {
434               if (!isset($aInfo[$aFields["devinfo_allow"][1]]) || ($aInfo[$aFields["devinfo_allow"][1]] == "")){
435               unset($vars["devinfo_allow"]);
436               }
437               else {
438                    $vars["devinfo_allow"] = trim($aInfo[$aFields["devinfo_allow"][1]]);
439                    }
440         }
441
442         if ($aFields["devinfo_dial"][0]) {
443           $vars["devinfo_dial"] = trim($aInfo[$aFields["devinfo_dial"][1]]);
444         }
445
446         if ($aFields["devinfo_accountcode"][0]) {
447               if (!isset($aInfo[$aFields["devinfo_accountcode"][1]]) || ($aInfo[$aFields["devinfo_accountcode"][1]] == "")){
448                 unset($vars["devinfo_accountcode"]);
449             }
450               else {
451             $vars["devinfo_accountcode"] = trim($aInfo[$aFields["devinfo_accountcode"][1]]);
452             }
453         }
454
455         if ($aFields["devinfo_mailbox"][0]) {
456           $vars["devinfo_mailbox"] = trim($aInfo[$aFields["devinfo_mailbox"][1]]);
457         }
458
459               if ($aFields["devinfo_deny"][0]) {
460         // If field is empty fill in default 0.0.0.0/0.0.0.0
461                 if (!isset($aInfo[$aFields["devinfo_deny"][1]]) || ($aInfo[$aFields["devinfo_deny"][1]] == "")){
462           $vars["devinfo_deny"] = "0.0.0.0/0.0.0.0";  // default value
463           }
464           else {
465               $vars["devinfo_deny"] = trim($aInfo[$aFields["devinfo_deny"][1]]);
466             }
467         }
468
469               if ($aFields["devinfo_permit"][0]) {
470         // If field is empty fill in default 0.0.0.0/0.0.0.0             
471               if (!isset($aInfo[$aFields["devinfo_deny"][1]]) || ($aInfo[$aFields["devinfo_permit"][1]] == "")){
472           $vars["devinfo_permit"] = "0.0.0.0/0.0.0.0"; // default value
473           }
474           else {
475               $vars["devinfo_permit"] = trim($aInfo[$aFields["devinfo_permit"][1]]);
476               }
477         }
478
479         if ($aFields["devicetype"][0]) {
480           $vars["devicetype"] = trim($aInfo[$aFields["devicetype"][1]]);
481         }
482
483         if ($aFields["deviceid"][0]) {
484           $vars["deviceid"] = trim($aInfo[$aFields["deviceid"][1]]);
485         }
486
487               if ($aFields["deviceuser"][0]) {
488           $vars["deviceuser"] = trim($aInfo[$aFields["deviceuser"][1]]);
489         }
490
491         if ($aFields["description"][0]) {
492           $vars["description"] = trim($aInfo[$aFields["description"][1]]);
493         }
494
495         if ($aFields["dictenabled"][0]) {
496           $vars["dictenabled"] = trim($aInfo[$aFields["dictenabled"][1]]);
497         }
498
499         if ($aFields["dictformat"][0]) {
500           $vars["dictformat"] = trim($aInfo[$aFields["dictformat"][1]]);
501         }
502
503         if ($aFields["dictemail"][0]) {
504           $vars["dictemail"] = trim($aInfo[$aFields["dictemail"][1]]);
505         }
506
507         if ($aFields["langcode"][0]) {
508           $vars["langcode"] = trim($aInfo[$aFields["langcode"][1]]);
509         }
510
511         if ($aFields["record_in"][0]) {
512           $vars["record_in"] = trim($aInfo[$aFields["record_in"][1]]);
513         }
514
515         if ($aFields["record_out"][0]) {
516           $vars["record_out"] = trim($aInfo[$aFields["record_out"][1]]);
517         }
518
519         if ($aFields["vm"][0]) {
520           $vars["vm"] = trim($aInfo[$aFields["vm"][1]]);
521         }
522
523         if ($aFields["vmpwd"][0]) {
524           $vars["vmpwd"] = trim($aInfo[$aFields["vmpwd"][1]]);
525         }
526
527         if ($aFields["email"][0]) {
528           $vars["email"] = trim($aInfo[$aFields["email"][1]]);
529         }
530
531         if ($aFields["pager"][0]) {
532           $vars["pager"] = trim($aInfo[$aFields["pager"][1]]);
533         }
534
535         if ($aFields["attach"][0]) {
536           $vars["attach"] = trim($aInfo[$aFields["attach"][1]]);
537         }
538
539         if ($aFields["saycid"][0]) {
540           $vars["saycid"] = trim($aInfo[$aFields["saycid"][1]]);
541         }
542
543         if ($aFields["envelope"][0]) {
544           $vars["envelope"] = trim($aInfo[$aFields["envelope"][1]]);
545         }
546
547         if ($aFields["delete"][0]) {
548           $vars["delete"] = trim($aInfo[$aFields["delete"][1]]);
549         }
550
551         if ($aFields["options"][0]) {
552           $vars["options"] = trim($aInfo[$aFields["options"][1]]);
553         }
554
555         if ($aFields["vmcontext"][0]) {
556           $vars["vmcontext"] = trim($aInfo[$aFields["vmcontext"][1]]);
557         }
558
559         if ($aFields["vmx_state"][0]) {
560           $vars["vmx_state"] = trim($aInfo[$aFields["vmx_state"][1]]);
561         }
562
563         if ($aFields["vmx_unavail_enabled"][0]) {
564           $vars["vmx_unavail_enabled"] = trim($aInfo[$aFields["vmx_unavail_enabled"][1]]);
565         }
566
567         if ($aFields["vmx_busy_enabled"][0]) {
568           $vars["vmx_busy_enabled"] = trim($aInfo[$aFields["vmx_busy_enabled"][1]]);
569         }
570
571         if ($aFields["vmx_play_instructions"][0]) {
572           $vars["vmx_play_instructions"] = trim($aInfo[$aFields["vmx_play_instructions"][1]]);
573         }
574
575         if ($aFields["vmx_option_0_system_default"][0]) {
576           $vars["vmx_option_0_system_default"] = trim($aInfo[$aFields["vmx_option_0_system_default"][1]]);
577         }
578
579         if ($aFields["vmx_option_0_number"][0]) {
580           $vars["vmx_option_0_number"] = trim($aInfo[$aFields["vmx_option_0_number"][1]]);
581         }
582
583         if ($aFields["vmx_option_1_system_default"][0]) {
584           $vars["vmx_option_1_system_default"] = trim($aInfo[$aFields["vmx_option_1_system_default"][1]]);
585         }
586
587         if ($aFields["vmx_option_1_number"][0]) {
588           $vars["vmx_option_1_number"] = trim($aInfo[$aFields["vmx_option_1_number"][1]]);
589         }
590
591         if ($aFields["vmx_option_2_number"][0]) {
592           $vars["vmx_option_2_number"] = trim($aInfo[$aFields["vmx_option_2_number"][1]]);
593         }
594        
595         if ($aFields["account"][0]) {
596           $vars["account"] = trim($aInfo[$aFields["account"][1]]);
597           if ($vars["account"] == $vars["extension"]) {
598             $followme_set = TRUE;   /* indicate we have follow me settings to set */
599           } else {
600             $followme_set = FALSE;
601           }
602         }
603        
604         if ($aFields["ddial"][0]) {
605           $vars["ddial"] = trim($aInfo[$aFields["ddial"][1]]);
606         }
607
608               if ($aFields["pre_ring"][0]) {
609           $vars["pre_ring"] = trim($aInfo[$aFields["pre_ring"][1]]);
610         }
611
612               if ($aFields["strategy"][0]) {
613           $vars["strategy"] = trim($aInfo[$aFields["strategy"][1]]);
614         }
615
616               if ($aFields["grptime"][0]) {
617           $vars["grptime"] = trim($aInfo[$aFields["grptime"][1]]);
618         }
619
620               if ($aFields["grplist"][0]) {
621           $vars["grplist"] = trim($aInfo[$aFields["grplist"][1]]);
622         }
623
624               if ($aFields["annmsg_id"][0]) {
625           $vars["annmsg_id"] = trim($aInfo[$aFields["annmsg_id"][1]]);
626         }
627
628               if ($aFields["ringing"][0]) {
629           $vars["ringing"] = trim($aInfo[$aFields["ringing"][1]]);
630         }
631
632               if ($aFields["grppre"][0]) {
633           $vars["grppre"] = trim($aInfo[$aFields["grppre"][1]]);
634         }
635
636               if ($aFields["dring"][0]) {
637           $vars["dring"] = trim($aInfo[$aFields["dring"][1]]);
638         }
639
640               if ($aFields["needsconf"][0]) {
641           $vars["needsconf"] = trim($aInfo[$aFields["needsconf"][1]]);
642         }
643
644               if ($aFields["remotealert_id"][0]) {
645           $vars["remotealert_id"] = trim($aInfo[$aFields["remotealert_id"][1]]);
646         }
647
648               if ($aFields["toolate_id"][0]) {
649           $vars["toolate_id"] = trim($aInfo[$aFields["toolate_id"][1]]);
650         }
651
652               if ($aFields["postdest"][0]) {
653           $vars["postdest"] = trim($aInfo[$aFields["postdest"][1]]);
654         }
655         if ($aFields["faxenabled"][0]) {
656         if (!isset($aInfo[$aFields["faxenabled"][1]]) || ($aInfo[$aFields["faxenabled"][1]] == "")){
657         unset($vars["faxenabled"]);
658         } else {
659       $vars["faxenabled"] = trim($aInfo[$aFields["faxenabled"][1]]);
660       }
661         }
662         if ($aFields["faxemail"][0]) {
663         if (!isset($aInfo[$aFields["faxemail"][1]]) || ($aInfo[$aFields["faxemail"][1]] == "")){
664         unset($vars["faxemail"]);
665         } else {
666       $vars["faxemail"] = trim($aInfo[$aFields["faxemail"][1]]);
667       }
668         }
669         /* Needed fields for creating a Follow Me are account (aka grpnum), strategy, grptime, */
670         /* grplist and pre_ring.                     */
671         if ($followme_set) {
672           if (!isset($vars["strategy"]) || ($vars["strategy"] == "")) {
673             $vars["strategy"] = "ringallv2";    // default value
674           }
675          
676           if(!isset($vars["grptime"]) || ($vars["grptime"] == "")) {
677             $vars["grptime"] = "20";      // default value
678           }
679          
680           if(!isset($vars["grplist"]) || ($vars["grplist"] == "")) {
681             $vars["grplist"] = $vars["extension"];  // default value
682           }
683          
684           if(!isset($vars["pre_ring"]) || ($vars["pre_ring"] == "")) {
685             $vars["pre_ring"] = "0";      // default value
686           }
687         }
688
689         if (!(isset($amp_conf["AMPEXTENSIONS"]) && ($amp_conf["AMPEXTENSIONS"] == "deviceanduser"))) {
690           $vars["devicetype"]   = "fixed";
691           $vars["deviceid"] = $vars["deviceuser"] = $vars["extension"];
692           $vars["description"]  = $vars["name"];
693         } else {
694           /* deviceid is required; if freepbx is in devicesandusers mode, deviceid cannot be left blank. */
695           if ($vars["deviceid"] == "") {
696             $vars["deviceid"] = $vars["extension"];
697           }
698         }
699
700         $vars["display"]  = "bulkextensions";
701         $vars["type"] = "tool";
702
703         $_REQUEST = $vars;
704
705         if (checkRange($vars["extension"])) {
706
707           switch ($vars["action"]) {
708             case "add":
709         // Only add if no voicemail, no user and no device entry already
710         // exist for the extension we're trying to add.
711         // Check the list of voicemail entries.
712         // user_vmexists == false means add  new voicemail entry.
713         $user_vmexists = FALSE;
714         if ($vm_exists) {
715           $uservm = voicemail_getVoicemail();
716           $vmcontexts = array_keys($uservm);
717           foreach ($vmcontexts as $vmcontext) {
718             if (isset($uservm[$vmcontext][$vars["extension"]])) {
719               $user_vmexists = TRUE;    // DO NOT add.
720             }
721           }
722         }
723         if ($user_vmexists || core_users_get($vars["extension"]) || core_devices_get($vars["extension"])) {
724           $output .= "Row $k: Extension " . $vars["extension"] . " already exists" . "<BR>";
725         } else {
726           if ($vm_exists) {
727             voicemail_mailbox_add($vars["extension"], $vars);
728           }
729           core_users_add($vars);
730           core_devices_add($vars["deviceid"],$vars["tech"],$vars["devinfo_dial"],$vars["devicetype"],$vars["deviceuser"],$vars["description"],$vars["emergency_cid"]);
731          
732           if ($lang_exists) {
733             languages_user_update($vars["extension"], $vars["langcode"]);
734           }
735           if ($dict_exists) {
736             dictate_update($vars["extension"], $vars["dictenabled"], $vars["dictformat"], $vars["dictemail"]);
737           }
738           if ($findme_exists && $followme_set) {
739             findmefollow_add($vars["account"], $vars["strategy"], $vars["grptime"], $vars["grplist"], $vars["postdest"], $vars["grppre"], $vars["annmsg_id"], $vars["dring"], $vars["needsconf"], $vars["remotealert_id"], $vars["toolate_id"], $vars["ringing"], $vars["pre_ring"], $vars["ddial"]);
740           }
741           if ($fax_exists) {
742             fax_save_user($vars["extension"], $vars["faxenabled"], $vars["faxemail"]);
743           }
744
745           // begin status output for this row
746           $output .= "Row $k: Added: " . $vars["extension"];
747           // send notification email for new voicemail account
748           $email_to = "";
749           // first use user email defined for voicemail account
750           if (isset($vars["email"])) {
751             $email_to = $vars["email"];
752           }
753           // if no user email specified, use default email
754           if (isset($default_email) && ($email_to == "")) {
755             $email_to = $default_email;
756           }
757           // if an override email is specified, use it
758           // if "noemail" is set for override email
759           // set email_to = "" so that an email will not be sent
760           if (isset($override_email) && ($override_email != "")) {
761             if ($override_email == "noemail") {
762               $email_to = "";
763             } else {
764               $email_to = $override_email;
765             }
766           }
767           if ($email_to != "") {
768
769             // SUBJECT - set default subject if not set by user
770             if (!isset($email_subject) || $email_subject == "") {
771               $email_subject = _("Voicemail Account Activated");
772             }
773
774             // FROM - if specified, use that, otherwise leave blank
775             if (isset($email_from) && $email_from != "") {
776               $email_from_header = "From: " . $email_from . $line_end;
777             } else {
778               $email_from_header = "";
779             }
780
781             // REPLY-TO - if specified, use that, otherwise leave blank
782             if (isset($email_replyto) && $email_replyto != "") {
783               $email_replyto_header = "Reply-To: " . $email_replyto . $line_end;
784             } else {
785               $email_replyto_header = "";
786             }
787
788             // HEADERS
789             $email_headers = $email_from_header . $email_replyto_header;
790
791             // BODY
792             if (!isset($email_body_open) || $email_body_open == "") {
793               $email_body = _("Login information for your voicemail account is as follows:"). "\n\n";
794             } else {
795               $email_body = $email_body_open . "\n\n";
796             }
797             $email_body .= "\t" . _("Account Name: ") . $vars["name"] . $line_end;
798             $email_body .= "\t" . _("Extension: ") . $vars["extension"] . $line_end;
799             $email_body .= "\t" . _("Voicemail Password: ") . $vars["vmpwd"] . $line_end;
800             if (isset($email_body_close) && $email_body_close != "") {
801               $email_body .= "\n\n" . $email_body_close . $line_end;
802             }
803            
804             // Mail it!
805             if (mail($email_to, $email_subject, $email_body, $email_headers)) {
806               $output .= ", notification sent to: " . $email_to;
807             } else {
808               $output .= ", notification failed to: " . $email_to;
809             }
810           }
811           // close status output for this row with line break
812           $output .= "<br />";
813           $change = true;
814         }
815         break;
816       case "edit":
817         // Functions core_devices_del and core_users_del
818         // do not check that the device or user actually
819         // exists.
820         // We check that the device or user exists before
821                           // deleting by looking them up by the extension.
822         // Only if the device or user exists do we call
823         // core_devices_del or core_users_del.
824         if (core_devices_get($vars["extension"])) {
825           core_devices_del($vars["extension"]);
826           $change = true;
827         }
828         if (core_users_get($vars["extension"])) {
829           core_users_del($vars["extension"]);
830           core_users_cleanastdb($vars["extension"]);
831           if ($findme_exists) {
832             findmefollow_del($vars["extension"]);
833           }
834           if ($dict_exists) {
835             dictate_del($vars["extension"]);
836           }
837           if ($lang_exists) {
838             languages_user_del($vars["extension"]);
839           }
840           $change = true;
841         }
842         // The voicemail functions have their own internal
843         // checking.
844         // If the voicemail box in question does not exist,
845         // the functions simply return.  No harm done.
846         //
847         // When editting an existing extension do not call
848         // voicemail_mailbox_remove, it will delete existing
849         // voicemail messages, which is undesirable.
850         if ($vm_exists) {
851           voicemail_mailbox_del($vars["extension"]);
852         }
853         // Only add if no voicemail, no user and no device entry already
854         // exist for the extension we're trying to add.
855         // Check the list of voicemail entries.
856         // user_vmexists == false means add new voicemail entry.
857         $user_vmexists = FALSE;
858         if ($vm_exists) {
859           $uservm = voicemail_getVoicemail();
860           $vmcontexts = array_keys($uservm);
861           foreach ($vmcontexts as $vmcontext) {
862             if (isset($uservm[$vmcontext][$vars["extension"]])) {
863               $user_vmexists = TRUE;    // DO NOT add.
864             }
865           }
866         }
867         if ($user_vmexists || core_users_get($vars["extension"]) || core_devices_get($vars["extension"])) {
868           $output .= "Row $k: Extension " . $vars["extension"] . " already exists" . "<BR>";
869         } else {
870           if ($vm_exists) {
871             voicemail_mailbox_add($vars["extension"], $vars);
872           }
873           core_users_add($vars);
874           core_devices_add($vars["deviceid"],$vars["tech"],$vars["devinfo_dial"],$vars["devicetype"],$vars["deviceuser"],$vars["description"],$vars["emergency_cid"]);
875           if ($lang_exists) {
876             languages_user_update($vars["extension"], $vars["langcode"]);
877           }
878           if ($dict_exists) {
879             dictate_update($vars["extension"], $vars["dictenabled"], $vars["dictformat"], $vars["dictemail"]);
880           }
881           if ($findme_exists && $followme_set) {
882             findmefollow_add($vars["account"], $vars["strategy"], $vars["grptime"], $vars["grplist"], $vars["postdest"], $vars["grppre"], $vars["annmsg_id"], $vars["dring"], $vars["needsconf"], $vars["remotealert_id"], $vars["toolate_id"], $vars["ringing"], $vars["pre_ring"], $vars["ddial"]);
883           }
884           $change = true;
885         }
886                                 if ($fax_exists) {
887                                 // If there is no entry in faxenabled, then delete the user in the fax table
888                                     if (!isset($aInfo[$aFields["faxenabled"][1]]) || ($aInfo[$aFields["faxenabled"][1]] == "")){
889                                         fax_delete_user($vars["extension"]);
890                                         } else {
891                                             fax_save_user($vars["extension"], $vars["faxenabled"], $vars["faxemail"]);
892                                             }
893                                     }
894
895         $output .= "Row $k: Edited: " . $vars["extension"] . "<BR>";
896         break;
897       case "del":
898         // Functions core_devices_del and core_users_del
899         // do not check that the device or user actually
900         // exists.
901         // We check that the device or user exists before
902                           // deleting by looking them up by the extension.
903         // Only if the device or user exists do we call
904         // core_devices_del or core_users_del.
905         if (core_devices_get($vars["extension"])) {
906           core_devices_del($vars["extension"]);
907           $change = true;
908         }
909         if (core_users_get($vars["extension"])) {
910           core_users_del($vars["extension"]);
911           core_users_cleanastdb($vars["extension"]);
912           if ($findme_exists) {
913             findmefollow_del($vars["extension"]);
914           }
915           if ($dict_exists) {
916             dictate_del($vars["extension"]);
917           }
918           if ($lang_exists) {
919             languages_user_del($vars["extension"]);
920           }
921           $change = true;
922         }
923         // The voicemail functions have their own internal
924         // checking.
925         // If the voicemail box in question does not exist,
926         // the functions simply return.  No harm done.
927         //
928         // call remove BEFORE del
929         if ($vm_exists) {
930           voicemail_mailbox_remove($vars["extension"]);
931           voicemail_mailbox_del($vars["extension"]);
932         }
933                                 // Fax settings
934                                 if ($fax_exists) {
935                                         fax_delete_user($vars["extension"]);
936                                 }
937         $output .= "Row $k: Deleted: " . $vars["extension"] . "<BR>";
938         break;
939       default:
940         $output .= "Row $k: Unrecognized action: the only actions recognized are add, edit, del.\n";
941         break;
942           }
943  
944           if ($change) {
945         needreload();
946           }
947         } else {
948           $output .= "Row $k: Access denied to extension " . $vars["extension"] . ".  No action performed.<BR>";
949         }
950       } // while loop
951
952        print $output;
953
954 } else
955 {
956   $table_output = "";
957   $table_rows = generate_table_rows();
958   if ($table_rows === NULL) {
959     $table_output = "Table unavailable";
960   } else {
961     $table_output .=  "<table cellspacing='0' cellpadding='4' rules='rows'>";
962     $table_output .=  "<tr valign='top'>
963             <th align='left' valign='top'>#</th>
964             <th align='left' valign='top'>Name</th>
965             <th align='left' valign='top'>Default</th>
966             <th align='left' valign='top'>Allowed</th>
967             <th align='left' valign='top'>On Extensions page</th>
968             <th align='left' valign='top'>Details</th>
969           </tr>";
970     $i = 1;
971     foreach ($table_rows as $row) {
972       $table_output .= "<tr>";
973       $table_output .= "<td valign='top'>" . $i . "</td>";
974       $i++;
975       foreach ($row as $col) {
976         $table_output .= "<td valign='top'>" . $col . "</td>";
977       }
978       $table_output .= "</tr>";
979     }
980     $table_output .= "</table>";
981   }
982
983
984 echo "<h1>"._("Bulk Extensions")."</h1>";
985 echo "<h2>"._("Manage Extensions in bulk using CSV files.")."</h2>";
986 echo "<p>";
987
988 echo sprintf(_("Start by downloading the %s Template CSV file %s (right-click > save as) or clicking the Export Extensions button."), "<a href=\"modules/bulkextensions/template.csv\">", "</a>");
989
990 echo "<p>";
991
992 echo _("Modify the CSV file to add, edit, or delete Extensions as desired. Then load the CSV file. After the CSV file is processed, the action taken for each row will be displayed.");
993 echo "<p>";
994 echo "<b>"._("Bulk extension changes can take a long time to complete. It can take 30-60 seconds to add 100 extensions on a small system. However, on a system with 2000 extensions it can take about 5 minutes to add 100 new extensions.")."</b>";
995 ?>
996 <form action="<?php $_SERVER["PHP_SELF"] ?>" name="uploadcsv" method="post" enctype="multipart/form-data">
997 <input id="csv_type" name="csv_type" type="hidden" value="none" />
998 <input type="submit" onclick="document.getElementById('csv_type').value='output';" value="<?php echo _("Export Extensions")?>" />
999 &nbsp;&nbsp;<?php echo _("CSV File to Load")?>: <input name="csvFile" type="file" />
1000 <input type="submit" onclick="document.getElementById('csv_type').value='input';" value="<?php echo _("Load File")?>" />
1001 <hr />
1002
1003 <?php
1004 echo "<h3>"._("Email Notification for New Accounts")."</h3>";
1005 echo "<p>";
1006 echo _("By default, a notification email will be sent to the voicemail email address set for each account added.")."<br>";
1007 echo _(" The settings below can be used to control the content and destination of the notification emails.");
1008 ?>
1009 <table>
1010   <tr>
1011     <td>
1012       <a href="#" class="info">
1013       <?php echo _("Default Address:")?>
1014       <span><?php echo _("If a Default Address is specified, notification emails for new accounts without a voicemail email address will be sent to the Default Address.")?>
1015       </span>
1016       </a>
1017     </td>
1018     <td>
1019       <input name="default_email" id="default_email" type="text" size="60" value="" />
1020     </td>
1021   </tr>
1022   <tr>
1023     <td>
1024       <a href="#" class="info">
1025       <?php echo _("Override Address:")?>
1026       <span><?php echo _("If an Override Address is specified, all notification emails will be sent to the Override Address only. Type \"noemail\" (without the quotes) as the Override Address to stop notification emails from being sent.")?>
1027       </span>
1028       </a>
1029     </td>
1030     <td>
1031       <input name="override_email" id="override_email" type="text" size="60" value="" />
1032     </td>
1033   </tr>
1034   <tr>
1035     <td>
1036       <a href="#" class="info">
1037       <?php echo _("Email From:")?>
1038       <span>
1039       <?php echo _("The Email From header may be specified. If left blank, the system default will be used.")?>
1040       </span>
1041       </a>
1042     </td>
1043     <td>
1044       <input name="email_from" id="email_from" type="text" size="60" value="" />
1045     </td>
1046   </tr>
1047   <tr>
1048     <td>
1049       <a href="#" class="info">
1050       <?php echo _("Email Reply-To:")?>
1051       <span>
1052       <?php echo _("The Email Reply-To header may be specified. If left blank, the system default will be used.")?>
1053       </span>
1054       </a>
1055     </td>
1056     <td>
1057       <input name="email_replyto" id="email-replyto" type="text" size="60" value="" />
1058     </td>
1059   </tr>
1060   <tr>
1061     <td>
1062       <a href="#" class="info">
1063       <?php echo _("Email Subject:")?>
1064       <span>
1065       <?php echo _("The Email Subject may be specified. If left blank, the default subject, \"Voicemail Account Activated\", will be used.")?>
1066       </span>
1067       </a>
1068     </td>
1069     <td>
1070       <input name="email_subject" id="email_subject" type="text" size="60" value="" />
1071     </td>
1072   </tr>
1073   <tr>
1074     <td>
1075       <a href="#" class="info">
1076       <?php echo _("Email Opening:")?>
1077       <span>
1078       <?php echo _("The Email Opening may be specified. If left blank, the default opening, \"Login information for your voicemail account is as follows:\", will be used.")?>
1079       <?php echo _(" The account name, extension, and voicemail password will automatically be inserted after the opening.")?>
1080       </span>
1081       </a>
1082     </td>
1083     <td>
1084       <textarea name="email_body_open" id="email_body_open" rows="2" cols="60"></textarea>
1085     </td>
1086   </tr>
1087   <tr>
1088     <td>
1089       <a href="#" class="info">
1090       <?php echo _("Email Closing:")?>
1091       <span>
1092       <?php echo _("The Email Closing may be specified. If any text is entered, it will be inserted at the end of the email.")?>
1093       </span>
1094       </a>
1095     </td>
1096     <td>
1097       <textarea name="email_body_close" id="email_body_close" rows="2" cols="60"></textarea>
1098     </td>
1099   </tr>
1100 </table>
1101 </form>
1102 <hr />
1103 <?php 
1104 echo "<h3>"._("Bulk Extensions CSV File Columns")."</h3><p>";
1105 echo _("The table below explains each column in the CSV file. You can change the column order of the CSV file as you like, however, the column names must be preserved.")."<p>";
1106   print $table_output;
1107 }
1108 ?>
Note: See TracBrowser for help on using the browser.