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

Revision 4644, 6.8 kB (checked in by p_lindheimer, 5 years ago)

added xml attribute needsenginedb, fixed some undefined vars

Line 
1 <?php 
2 /* $Id: page.ivr.php 3790 2007-02-16 18:52:53Z p_lindheimer $ */
3 //Copyright (C) 2007 Atengo LLC (info@atengo.net)
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 $dispnum = "daynight"; //used for switch on config.php
16
17 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
18 $password = isset($_REQUEST['password'])?$_REQUEST['password']:'';
19 $fc_description = isset($_REQUEST['fc_description'])?$_REQUEST['fc_description']:'';
20
21 isset($_REQUEST['itemid'])?$itemid=mysql_real_escape_string($_REQUEST['itemid']):$itemid='';
22
23
24 $fcc = new featurecode('daynight', 'toggle-mode');
25 $fc = $fcc->getCodeActive();
26 unset($fcc);
27
28 $daynightcodes = daynight_list();
29 ?>
30
31 </div> <!-- end content div so we can display rnav properly-->
32
33 <!-- right side menu -->
34 <div class="rnav"><ul>
35     <li><a id="<?php echo ($itemid=='' ? 'current':'') ?>" href="config.php?display=<?php echo urlencode($dispnum)?>&action=add"><?php echo _("Add Day/Night Code")?></a></li>
36 <?php
37 if (isset($daynightcodes)) {
38   foreach ($daynightcodes as $code) {
39     $dnobj = daynight_get_obj($code['ext']);
40     $color = $dnobj['state'] == 'DAY' ? "style='color:green'" : "style='color:red'";
41     echo "<li><a $color id=\"".($itemid==$code['ext'] ? 'current':'')."\" href=\"config.php?display=".urlencode($dispnum)."&itemid=".urlencode($code['ext'])."&action=edit\">($fc{$code['ext']}) {$code['dest']}</a></li>";
42   }
43 }
44 ?>
45 </ul></div>
46 <?php
47
48 switch ($action) {
49   case "add":
50     daynight_show_edit($_POST,'add');
51     break;
52   case "edit":
53     daynight_show_edit($_POST);
54     break;
55   case "edited":
56       daynight_edit($_POST,$itemid);
57       redirect_standard('itemid');
58       break;
59   case "delete":
60       daynight_del($itemid);
61       redirect_standard();
62       break;
63   default:
64     daynight_show_edit($_POST,'add');
65     break;
66 }
67
68 function daynight_show_edit($post, $add="") {
69   global $db;
70   global $itemid;
71
72   $fcc = new featurecode('daynight', 'toggle-mode');
73   $code = $fcc->getCodeActive().$itemid;
74   unset($fcc);
75
76   $dests = daynight_get_obj($itemid);
77   $password = isset($dests['password'])?$dests['password']:'';
78   $fc_description = isset($dests['fc_description'])?$dests['fc_description']:'';
79   $state = isset($dests['state'])?$dests['state']:'DAY';
80 ?>
81   <div class="content">
82   <h2><?php echo _("Day / Night Mode Control"); ?></h2>
83
84 <?php
85   $delURL = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&action=delete';
86 ?>
87 <?php   if ($itemid != ""){ ?>
88   <p><a href="<?php echo $delURL ?>"><?php echo _("Delete Day/Night Feature Code:")?> <?php echo $code; ?></a></p>
89 <?php   } ?>
90
91   <form name="prompt" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return prompt_onsubmit();">
92   <input type="hidden" name="action" value="edited" />
93   <input type="hidden" name="display" value="daynight" />
94   <input name="Submit" type="submit" style="display:none;" value="save" />
95   <table>
96   <tr>
97     <td colspan=2><hr />
98     </td>
99   </tr>
100   <tr>
101     <td colspan="2"> 
102     <input name="Submit" type="submit" value="<?php echo _("Save")?>">
103     <?php if ($itemid != '') echo "&nbsp ".sprintf(_("Use feature code: %s to toggle DAY/NIGHT mode"),"<strong>".$code."</strong>")?>
104     </td>
105   </tr>
106   <tr>
107     <td colspan=2>
108     <hr />
109     </td>
110   </tr>
111   <tr>
112     <td><a href="#" class="info"><?php echo _("Day/Night Feature Code Index:")?>
113     <span><?php echo _("There are a total of 10 Feature code objects, 0-9, each can control a call flow and be toggled using the day/night feature code plus the index.")?>
114     </span></a>
115     </td>
116     <td>
117 <?php
118       if ($add == "add" && $itemid =="") {
119 ?>
120       <select name="itemid"/>
121       <?php
122         $ids = daynight_get_avail();
123         foreach ($ids as $id) {
124           echo '<option value="'.$id.'" >'.$id.'</option>';
125         }
126       ?>
127       </select>
128 <?php
129       } else {
130 ?>
131     <input readonly="yes" size="1" type="text" name="itemid" value="<?php  echo $itemid ?>">
132 <?php
133     }
134 ?>
135     </td>
136   </tr>
137   <tr>
138     <td><a href="#" class="info"><?php echo _("Description")?>:<span><?php echo _('Description for this Day/Night Control')?></span></a></td>
139     <td><input size="40" type="text" name="fc_description" value="<?php  echo $fc_description ?>">
140     </td>
141   </tr>
142   <tr>
143     <td><a href="#" class="info"><?php echo _("Current Mode:")?>
144     <span><?php echo _("This will change the current state for this Day/Night Mode Control, or set the intial state when creating a new one.")?>
145     </span></a>
146     </td>
147     <td>
148       <select name="state"/>
149         <option value="DAY" <?php echo ($state == 'DAY' ? 'SELECTED':'') ?> >Day</option>
150         <option value="NIGHT" <?php echo ($state == 'NIGHT' ? 'SELECTED':'') ?> >Night</option>
151       </select>
152     </td>
153   </tr>
154   <tr>
155     <td><a href="#" class="info"><?php echo _("Optional Password")?>:<span><?php echo _('You can optionally include a password to authenticate before toggling the day/night mode. If left blank anyone can use the feature code will be un-protected')?></span></a></td>
156     <td><input size="12" type="text" name="password" value="<?php  echo $password ?>">
157     </td>
158   </tr>
159   <tr>
160     <td colspan=2>
161     <hr />
162     </td>
163   </tr>
164 <?php
165   // Draw the destinations
166   // returns an array, $dest['day'], $dest['night']
167   // and puts null if nothing set
168
169   drawdestinations(0, _("DAY"),   isset($dests['day'])?$dests['day']:'');
170   drawdestinations(1, _("NIGHT"), isset($dests['night'])?$dests['night']:'');
171
172   //TODO: Check to make sure a destination radio button was checked, and if custom, that it was not blank
173   //
174 ?>
175   <tr>
176     <td colspan=2> 
177     <input name="Submit" type="submit" value="<?php echo _("Save")?>">
178     <?php if ($itemid != '') echo "&nbsp ".sprintf(_("Use feature code: %s to toggle DAY/NIGHT mode"),"<strong>".$code."</strong>")?>
179     </td>
180   </tr>
181   <tr>
182     <td colspan=2>
183     <hr />
184     </td>
185   </tr>
186   </table>
187
188   <script language="javascript">
189   <!--
190   var theForm = document.prompt;
191
192   function prompt_onsubmit() {
193     var msgInvalidPassword = "<?php echo _('Please enter a valid numeric password, only numbers are allowed'); ?>";
194
195     defaultEmptyOK = true;
196     if (!isInteger(theForm.password.value))
197       return warnInvalid(theForm.password, msgInvalidPassword);
198     return true;
199   }
200   //-->
201   </script>
202
203   </form>
204   </div>
205 <?php
206 } //daynight function
207
208
209 // count is for the unique identifier
210 // dest is the target
211 //
212 function drawdestinations($count, $mode, $dest) { ?>
213   <tr>
214     <td style="text-align:right;">
215     <a href="#" class="info"><strong><?php echo _("$mode")?></strong><span><?php echo _("Destination to use when set to $mode mode")?></span></a>
216     </td>
217     <td>
218       <table> <?php echo drawselects($dest,$count); ?>
219       </table>
220     </td>
221   </tr>
222   <tr><td colspan=2><hr /></td></tr>
223 <?php
224 }
225 ?>
Note: See TracBrowser for help on using the browser.