root/modules/branches/2.4/timeconditions/functions.inc.php

Revision 5284, 7.9 kB (checked in by p_lindheimer, 5 years ago)

added timeconditions_getdest() and timeconditions_getdestinfo() and feedback on destination usage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id */
2
3 // returns a associative arrays with keys 'destination' and 'description'
4 function timeconditions_destinations() {
5     //get the list of meetmes
6     $results = timeconditions_list();
7
8     // return an associative array with destination and description
9     if (isset($results)) {
10         foreach($results as $result){
11                 $extens[] = array('destination' => 'timeconditions,'.$result['timeconditions_id'].',1', 'description' => $result['displayname']);
12         }
13         return $extens;
14     } else {
15         return null;
16     }
17 }
18
19 function timeconditions_getdest($exten) {
20     return array('timeconditions,'.$exten.',1');
21 }
22
23 function timeconditions_getdestinfo($dest) {
24     global $active_modules;
25
26     if (substr(trim($dest),0,15) == 'timeconditions,') {
27         $exten = explode(',',$dest);
28         $exten = $exten[1];
29         $thisexten = timeconditions_get($exten);
30         if (empty($thisexten)) {
31             return array();
32         } else {
33             //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
34             return array('description' => 'Time Conditon : '.$thisexten['displayname'],
35                          'edit_url' => 'config.php?display=timeconditions&itemid='.urlencode($exten),
36                                   );
37         }
38     } else {
39         return false;
40     }
41 }
42
43
44 /*     Generates dialplan for conferences
45     We call this with retrieve_conf
46 */
47 function timeconditions_get_config($engine) {
48     global $ext// is this the best way to pass this?
49     global $conferences_conf;
50     switch($engine) {
51         case "asterisk":
52             $timelist = timeconditions_list();
53             if(is_array($timelist)) {
54                 foreach($timelist as $item) {
55                     $thisitem = timeconditions_get(ltrim($item['timeconditions_id']));
56                     // add dialplan
57                     $ext->add('timeconditions', $item['timeconditions_id'], '', new ext_gotoiftime($item['time'],$item['truegoto']));
58                     $ext->add('timeconditions', $item['timeconditions_id'], '', new ext_goto($item['falsegoto']));
59                 }
60             }
61         break;
62     }
63 }
64
65 function timeconditions_check_destinations($dest=true) {
66     global $active_modules;
67
68     $destlist = array();
69     if (is_array($dest) && empty($dest)) {
70         return $destlist;
71     }
72     $sql = "SELECT timeconditions_id, displayname, truegoto, falsegoto FROM timeconditions ";
73     if ($dest !== true) {
74         $sql .= "WHERE (truegoto in ('".implode("','",$dest)."') ) OR (falsegoto in ('".implode("','",$dest)."') )";
75     }
76     $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
77
78     $type = isset($active_modules['timeconditions']['type'])?$active_modules['timeconditions']['type']:'setup';
79
80     foreach ($results as $result) {
81         $thisdest    = $result['truegoto'];
82         $thisid      = $result['timeconditions_id'];
83         $description = 'Timecondition: '.$result['displayname'];
84         $thisurl     = 'config.php?display=timeconditions&itemid='.urlencode($thisid);
85         if ($dest === true || $dest = $thisdest) {
86             $destlist[] = array(
87                 'dest' => $thisdest,
88                 'description' => $description,
89                 'edit_url' => $thisurl,
90             );
91         }
92         $thisdest = $result['falsegoto'];
93         if ($dest === true || $dest = $thisdest) {
94             $destlist[] = array(
95                 'dest' => $thisdest,
96                 'description' => $description,
97                 'edit_url' => $thisurl,
98             );
99         }
100     }
101     return $destlist;
102 }
103
104 //get the existing meetme extensions
105 function timeconditions_list() {
106     $results = sql("SELECT * FROM timeconditions","getAll",DB_FETCHMODE_ASSOC);
107     if(is_array($results)){
108         foreach($results as $result){
109             // check to see if we have a dept match for the current AMP User.
110             if (checkDept($result['deptname'])){
111                 // return this item's dialplan destination, and the description
112                 $allowed[] = $result;
113             }
114         }
115     }
116     if (isset($allowed)) {
117         return $allowed;
118     } else {
119         return null;
120     }
121 }
122
123 function timeconditions_get($id){
124     //get all the variables for the meetme
125     $results = sql("SELECT * FROM timeconditions WHERE timeconditions_id = '$id'","getRow",DB_FETCHMODE_ASSOC);
126     return $results;
127 }
128
129 function timeconditions_del($id){
130     $results = sql("DELETE FROM timeconditions WHERE timeconditions_id = \"$id\"","query");
131 }
132
133 function timeconditions_get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish) {
134
135         //----- Time Hour Interval proccess ----
136         if ($minute_start == '-') {
137             $time_minute_start = "*";
138          } else {
139             $time_minute_start = sprintf("%02d",$minute_start);
140          }
141          if ($minute_finish == '-') {
142             $time_minute_finish = "*";
143          } else {
144              $time_minute_finish = sprintf("%02d",$minute_finish);
145          }
146          if ($hour_start == '-') {
147              $time_hour_start = '*';
148           } else {
149              $time_hour_start = sprintf("%02d",$hour_start) . ':' . $time_minute_start;
150           }
151           if ($hour_finish == '-') {
152              $time_hour_finish = '*';
153           } else {
154              $time_hour_finish = sprintf("%02d",$hour_finish) . ':' . $time_minute_finish;
155           }
156           if ($time_hour_start == $time_hour_finish) {
157               $time_hour = $time_hour_start;
158           } else {
159               $time_hour = $time_hour_start . '-' . $time_hour_finish;
160           }
161           //----- Time Week Day Interval proccess -----
162           if ($wday_start == '-') {
163               $time_wday_start = '*';
164            } else {
165               $time_wday_start = $wday_start;
166            }
167            if ($wday_finish == '-') {
168               $time_wday_finish = '*';
169            } else {
170               $time_wday_finish = $wday_finish;
171            }
172            if ($time_wday_start == $time_wday_finish) {
173                $time_wday = $time_wday_start;
174             } else {
175                $time_wday = $time_wday_start . '-' . $time_wday_finish;
176             }
177             //----- Time Month Day Interval proccess -----
178             if ($mday_start == '-') {
179                $time_mday_start = '*';
180             } else {
181                 $time_mday_start = $mday_start;
182             }
183             if ($mday_finish == '-') {
184                 $time_mday_finish = '*';
185             } else {
186                 $time_mday_finish = $mday_finish;
187             }
188             if ($time_mday_start == $time_mday_finish) {
189                 $time_mday = $time_mday_start;
190             } else {
191                 $time_mday = $time_mday_start . '-' . $time_mday_finish;
192             }
193             //----- Time Month Interval proccess -----
194             if ($month_start == '-') {
195                 $time_month_start = '*';
196             } else {
197                 $time_month_start = $month_start;
198             }
199             if ($month_finish == '-') {
200                 $time_month_finish = '*';
201             } else {
202                 $time_month_finish = $month_finish;
203             }
204             if ($time_month_start == $time_month_finish) {
205                 $time_month = $time_month_start;
206             } else {
207                 $time_month = $time_month_start . '-' . $time_month_finish;
208             }
209         $time = $time_hour . '|' . $time_wday . '|' . $time_mday . '|' . $time_month;
210         return $time;
211 }
212
213 function timeconditions_add($post){
214     if(!timeconditions_chk($post))
215         return false;
216     extract($post);
217
218         $time = timeconditions_get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish);
219
220     if(empty($displayname)) $displayname = "unnamed";
221     $results = sql("INSERT INTO timeconditions (displayname,time,truegoto,falsegoto,deptname) values (\"$displayname\",\"$time\",\"${$goto0.'0'}\",\"${$goto1.'1'}\",\"$deptname\")");
222 }
223
224 function timeconditions_edit($id,$post){
225     if(!timeconditions_chk($post))
226         return false;
227     extract($post);
228
229         $time = timeconditions_get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish);
230     
231     if(empty($displayname)) $displayname = "unnamed";
232     $results = sql("UPDATE timeconditions SET displayname = \"$displayname\", time = \"$time\", truegoto = \"${$goto0.'0'}\", falsegoto = \"${$goto1.'1'}\", deptname = \"$deptname\" WHERE timeconditions_id = \"$id\"");
233 }
234
235 // ensures post vars is valid
236 function timeconditions_chk($post){
237     return true;
238 }
239 ?>
240
Note: See TracBrowser for help on using the browser.