root/modules/branches/2.9/phonebook/page.phonebook.php

Revision 10528, 8.6 kB (checked in by mbrevda, 3 years ago)

downstream alignments

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 <?php /* $Id */
2 //Copyright (C) 2006 WeBRainstorm S.r.l. (ask@webrainstorm.it)
3 //
4 //This program is free software; you can redistribute it and/or
5 //modify it under the terms of the GNU General Public License
6 //as published by the Free Software Foundation; either version 2
7 //of the License, or (at your option) any later version.
8 //
9 //This program 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 isset($_REQUEST['action'])?$action = $_REQUEST['action']:$action='';
15 isset($_REQUEST['number'])?$number = $_REQUEST['number']:$number='';
16 isset($_REQUEST['name'])?$name = $_REQUEST['name']:$name='';
17 isset($_REQUEST['speeddial'])?$speeddial = $_REQUEST['speeddial']:$speeddial='';
18 isset($_REQUEST['gensd'])?$gensd = $_REQUEST['gensd']:$gensd='';
19
20 isset($_REQUEST['editnumber'])?$editnumber = $_REQUEST['editnumber']:$editnumber='';
21
22 $dispnum = "phonebook"; //used for switch on config.php
23
24 //if submitting form, update database
25
26 if(isset($_REQUEST['action'])) {
27   switch ($action) {
28     case "add":
29       phonebook_add($number, $name, $speeddial, $gensd);
30       redirect_standard();
31     exit;
32     break;
33     case "delete":
34       $numbers = phonebook_list();
35       phonebook_del($number, $numbers[$number]['speeddial']);
36       redirect_standard();
37     break;
38     case "edit":
39       $numbers = phonebook_list();
40       phonebook_del($editnumber, $numbers[$editnumber]['speeddial']);
41       phonebook_add($number, $name, $speeddial, $gensd);
42       redirect_standard();
43     break;
44     case "empty":
45       phonebook_empty();
46     break;
47     case "import":
48       $i = 0; // imported lines
49       if(is_uploaded_file($_FILES['csv']['tmp_name'])) {
50         $lines = file($_FILES['csv']['tmp_name']);
51         if (is_array($lines)) {
52           $n = count($lines); // total lines
53           foreach($lines as $line) {
54             $fields = phonebook_fgetcsvfromline($line, 3);
55             $fields = array_map('trim', $fields);
56             if (is_array($fields) && count($fields) == 3 && is_numeric($fields[2]) &&  ($fields[3] == '' || is_numeric($fields[3]))) {
57               phonebook_del($fields[2], $numbers[$fields[2]]['speeddial']);
58               phonebook_add(htmlentities($fields[2],ENT_QUOTES), addslashes(htmlentities($fields[1],ENT_QUOTES)), htmlentities($fields[3],ENT_QUOTES));
59               $i++;
60             }
61           }
62           redirect_standard();
63         }
64       } else
65         $n = 0; // total lines if no file
66     break;
67     case "export":
68       header('Content-Type: text/csv');
69       header('Content-disposition: attachment; filename=phonebook.csv');
70       $numbers = phonebook_list();
71       foreach ($numbers as $number => $values)
72         printf("\"%s\";%s;%s\n", $values['name'], $number, $values['speeddial']);
73       die_freepbx();
74     break;
75   }
76 }
77
78 $numbers = phonebook_list();
79
80 ?>
81
82 </div>
83
84 <!-- NO rnav in this module -->
85
86
87 <div class="content">
88 <?php
89 if ($action == 'delete')
90   echo '<h3>'._("Phonebook entry").' '.$itemid.' '._("deleted").' !</h3>';
91 elseif ($action == 'import')
92   echo '<h3>'._("Imported").' '.$i.' '._("lines of").' '.$n.' '.'!</h3>';
93 elseif ($action == 'empty')
94   echo '<h3>'._("Phonebook emptied").' !</h3>';
95  
96 if (is_array($numbers)) {
97
98 ?>
99
100 <form autocomplete="off" name="delete" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return confirm('<?php echo _("Are you sure you want to empty your phonebook ?")?>');">
101 <input type="hidden" name="action" value="empty">
102 <table cellpadding="5" width="100%">
103
104 <?php//onsubmit="return edit_onsubmit();"?>
105 <tr><td colspan="4"<h2>Phone Book</h2></td></tr>
106 <tr><td colspan="4">Use this module to create system wide speed dial numbers that can be dialed from any phone.<br><br></td></tr>
107
108   <tr>
109     <td colspan="5"><h5><?php echo _("Phonebook entries") ?></h5><hr></td>
110   </tr>
111
112   <tr>
113     <td><b><?php _("Number")?></b></td>
114     <td><b><?php _("Name")?></b></td>
115     <td><b><?php _("Speed dial")?></b></td>
116     <td>&nbsp;</td>
117     <td>&nbsp;</td>
118   </tr>
119
120 <?php
121 // Why should I specify type=tool ???
122
123   foreach ($numbers as $num => $values) {
124     print('<tr>');
125     printf('<td>%s</td><td>%s</td><td>%s</td>', $num, $values['name'], $values['speeddial']);
126     printf('<td><a href="%s?type=tool&display=%s&number=%s&action=delete" onclick="return confirm(\'%s\')">%s</a></td>',
127       $_SERVER['PHP_SELF'], urlencode($dispnum), urlencode($num), _("Are you sure you want to delete this entry ?"), _("Delete"));
128     printf('<td><a href="#" 
129     onClick="theForm.number.value = \'%s\'; theForm.name.value = \'%s\' ; theForm.speeddial.value = \'%s\' ;
130     if (theForm.name.value && theForm.number.value && !theForm.speeddial.value) { theForm.gensd.checked = false } else { theForm.gensd.checked = true };
131     theForm.editnumber.value = \'%s\' ; theForm.action.value = \'edit\' ; ">%s</a></td>',
132       $num,  addslashes($values['name']), $values['speeddial'], $num, _("Edit"));
133     print('</tr>');
134   }
135
136 ?>
137
138   <tr>
139     <td colspan="3"><br><h6><a href="<?php echo $_SERVER['PHP_SELF'] ?>?type=tool&display=phonebook&action=export&quietmode=1"><?php echo _("Export in CSV") ?></a></h6></td><td colspan="2" align="center"><input name="submit" type="submit" value="<?php echo _("Empty Phonebook")?>"></td>   
140   </tr>
141 </table>
142 </form>
143
144 <?php
145 }
146 ?>
147
148 <form autocomplete="off" name="edit" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return edit_onsubmit();">
149 <input type="hidden" name="display" value="<?php echo $dispnum?>">
150 <input type="hidden" name="action" value="add">
151 <input type="hidden" name="editnumber" value="">
152 <table cellpadding="5" width="100%">
153   <tr><td colspan="4"<h2>Phone Book</h2></td></tr>
154     <tr><td colspan="4">Use this module to create system wide speed dial numbers that can be dialed from any phone.<br><br></td></tr>
155
156   <tr><td colspan="4"><h5><?php echo _("Add or replace entry") ?><hr></h5></td></tr>
157
158   <tr>
159     <td><a href="#" class="info"><?php echo _("Name:")?><span><?php echo _("Enter the name")?></span></a></td>
160     <td><input type="text" name="name" tabindex="<?php echo ++$tabindex;?>"></td>
161   </tr>
162  
163   <tr>
164     <td><a href="#" class="info"><?php echo _("Number:")?>
165     <span><?php echo _("Enter the number (For caller ID lookup to work it should match the caller ID received from network)")?></span></a></td>
166     <td><input type="text" name="number" tabindex="<?php echo ++$tabindex;?>"></td>
167   </tr>
168
169   <tr>
170     <td><a href="#" class="info"><?php echo _("Speed dial code:")?><span><?php echo _("Enter a speed dial code<br/>Speeddial module is required to use speeddial codes")?></span></a></td>
171     <td><input type="text" name="speeddial" tabindex="<?php echo ++$tabindex;?>"></td>
172   </tr>
173
174   <tr>
175     <td><a href="#" class="info"><?php echo _("Set Speed Dial?"); ?><span><?php echo _("Check to have a speed dial created automatically for this number"); ?></span></a></td>
176     <td><input type="checkbox" name="gensd" value="yes" CHECKED tabindex="<?php echo ++$tabindex;?>"></td>
177
178   <tr>
179     <td colspan="2"><br><h6><input name="submit" type="submit" value="<?php echo _("Submit Changes")?>" tabindex="<?php echo ++$tabindex;?>"></h6></td>   
180
181   </tr>
182 </table>
183 </form>
184
185 <form autocomplete="off" enctype="multipart/form-data" name="import" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
186 <input type="hidden" name="MAX_FILE_SIZE" value="30000">
187 <input type="hidden" name="display" value="<?php echo $dispnum?>">
188 <input type="hidden" name="action" value="import">
189
190 <table cellpadding="5" width="100%">
191
192   <tr><td colspan="4"><h5><?php echo _("Import from CSV") ?><hr></h5></td></tr>
193
194         <tr>
195                 <td><a href="#" class="info"><?php echo _("File:")?>
196                 <span><?php echo _("Import a CSV File formatted as follows:<br/>\"Name\";Number;Speeddial<br /> Names should be enclosed by '\"' and fields separated by ';' <br /><br /> Example:<br/>\"John Doe\";12345678;123")?></span></a></td>
197                 <td><input type="file" name="csv" tabindex="<?php echo ++$tabindex;?>"></td>
198         </tr>
199
200   <tr>
201     <td colspan="2"><br><h6><input name="submit" type="submit" value="<?php echo _("Upload")?>" tabindex="<?php echo ++$tabindex;?>"></h6></td>   
202   </tr>
203 </table>
204 </form>
205 <script language="javascript">
206 <!--
207
208 var theForm = document.edit;
209 theForm.name.focus();
210
211 function edit_onsubmit() {
212   var msgInvalidNumber = "<?php echo _("Please enter a valid Number"); ?>";
213   var msgInvalidName = "<?php echo _("Please enter a valid Name"); ?>";
214   var msgInvalidCode = "<?php echo _("Please enter a valid Speeddial code or leave it empty"); ?>";
215   defaultEmptyOK = false;
216   if (!isInteger(theForm.number.value))
217     return warnInvalid(theForm.number, msgInvalidNumber);
218   if (!isAlphanumeric(theForm.name.value))
219     return warnInvalid(theForm.name, msgInvalidName);
220  
221   defaultEmptyOK = true;
222   if (!isInteger(theForm.speeddial.value))
223     return warnInvalid(theForm.speeddial, msgInvalidCode);
224    
225   return true;
226 }
227
228
229 -->
230 </script>
Note: See TracBrowser for help on using the browser.