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

Revision 13091, 8.7 kB (checked in by p_lindheimer, 2 years ago)

adds FREEPBX_IS_AUTH checking to most module files re #5478

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