root/modules/branches/2.9/parking/functions.inc.php

Revision 10920, 8.2 kB (checked in by p_lindheimer, 2 years ago)

adds _change_destination callback to missed modules re #4655

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php /* $Id: functions.inc.php 2188 2006-07-27 02:21:52Z p_lindheimer $ */
2
3 /*  Generates dialplan for parkinglot
4   We call this with retrieve_conf
5 */
6
7 function parking_get_config($engine) {
8   global $db;
9   global $amp_conf;
10   global $ext;  // is this the best way to pass this?
11   global $asterisk_conf;
12   global $core_conf;
13   global $version;
14
15   switch($engine) {
16     case "asterisk":
17
18     $contextname = 'park-dial';
19
20     $parkinglot_id = 1; // only 1 parking lot, but prepare for future
21     $results = parking_getconfig($parkinglot_id);
22
23     // Got the array, let's go work out the required variables
24     //
25     $parkingenabled = isset($results['parkingenabled'])?$results['parkingenabled']:'';
26     $parkext  = isset($results['parkext'])?$results['parkext']:70;
27     $numslots   = isset($results['numslots'])?$results['numslots']:8;
28     $parkingtime  = isset($results['parkingtime'])?$results['parkingtime']:'';
29     $parkingcontext = isset($results['parkingcontext'])?$results['parkingcontext']:'parkedcalls';
30     $parkalertinfo  = isset($results['parkalertinfo'])?$results['parkalertinfo']:'';
31     $parkcid  = isset($results['parkcid'])?$results['parkcid']:'';
32     $parkingannmsg_id   = isset($results['parkingannmsg_id'])?$results['parkingannmsg_id']:'';
33     $goto   = isset($results['goto'])?$results['goto']:'from-pstn,s,1';
34
35     $parkpos1 = $parkext + 1;
36     $parkpos2 = $parkpos1 + $numslots -1;
37
38     if ($parkingenabled) {
39       // TODO: lookup ampportal.conf variables for this, don't hard code
40       // first write features_additional.inc include file
41       //
42       $core_conf->addFeatureGeneral('parkext',$parkext);
43       $core_conf->addFeatureGeneral('parkpos',$parkpos1."-".$parkpos2);
44       $core_conf->addFeatureGeneral('context',$parkingcontext);
45
46       if ($parkingtime) {
47         $core_conf->addFeatureGeneral('parkingtime',$parkingtime);
48       }
49
50       // Now generate dialplan
51       $ext->add($contextname, "t", '', new ext_noop('Parked Call Timed Out and Got Orphaned'));
52       $ext->add($contextname, "_[0-9a-zA-Z*#].", '', new ext_noop('Parked Call Timed Out and Got Orphaned'));
53
54       // If we have an appropriate Asterisk patch, set paraemters for Asterisk
55       //
56       if (isset($amp_conf["PARKINGPATCH"]) && strtolower($amp_conf["PARKINGPATCH"]) == 'true') {
57         if ($parkalertinfo) {
58           $core_conf->addFeatureGeneral('parkreturnalertinfo',$parkalertinfo);
59         }
60         if ($parkcid) {
61           $core_conf->addFeatureGeneral('parkreturncidprefix',$parkcid);
62         }
63       // No patch, do the default for orphaned calls
64       } else {
65         if ($parkalertinfo) {
66           $ext->add($contextname, "t", '', new ext_setvar('__ALERT_INFO',str_replace(';', '\;', $parkalertinfo)));
67           $ext->add($contextname, "_[0-9a-zA-Z*#].", '', new ext_setvar('__ALERT_INFO',str_replace(';', '\;', $parkalertinfo)));
68         }
69         if ($parkcid) {
70           $ext->add($contextname, "t", '', new ext_setvar('CALLERID(name)', $parkcid.'${CALLERID(name)}'));
71           $ext->add($contextname, "_[0-9a-zA-Z*#].", '', new ext_setvar('CALLERID(name)', $parkcid.'${CALLERID(name)}'));
72         }
73       }
74
75       if ($parkingannmsg_id != '') {
76         $parkingannmsg = recordings_get_file($parkingannmsg_id);
77         $ext->add($contextname, "t", '', new ext_playback($parkingannmsg));
78         $ext->add($contextname, "_[0-9a-zA-Z*#].", '', new ext_playback($parkingannmsg));
79       }
80       // goto the destination here
81       //
82       $ext->add($contextname, "t", '', new ext_goto($goto));
83       $ext->add($contextname, "_[0-9a-zA-Z*#].", '', new ext_goto($goto));
84
85       // Asterisk 1.4 requires hints to be generated for parking
86       //
87       if (version_compare($version, "1.4", "ge")) {
88         $parkhints = 'park-hints';
89         $ext->addInclude('from-internal-additional', $parkhints); // Add the include from from-internal
90         for ($slot = $parkpos1; $slot <= $parkpos2; $slot++) {
91           $ext->addHint($parkhints, $slot, "park:$slot@$parkingcontext");
92           $ext->add($parkhints, $slot, '', new ext_parkedcall($slot));
93         }
94       }
95     }
96     break;
97   }
98 }
99
100 function parking_add($parkingenabled, $parkext, $numslots, $parkingtime, $parkingcontext, $parkalertinfo, $parkcid, $parkingannmsg_id, $goto) {
101   global $db;
102
103   $parkinglot_id  = 1; // only 1 parkinglot but prepare for future
104
105   // in future will do in a parking_del but not needed for now
106   //
107   $sql = "DELETE FROM parkinglot WHERE id = '$parkinglot_id'";
108   $result = $db->query($sql);
109   if(DB::IsError($result)) {
110     die_freepbx($result->getMessage().$sql);
111   }
112
113   // Check for interger only inputs and set to default if not
114   //  and set goto to default if not set for some reason
115   //
116   $parkext  = ctype_digit($parkext)   ? $parkext  : 70;
117   $numslots   = ctype_digit($numslots)    ? $numslots : 8;
118   $parkingtime  = ctype_digit($parkingtime) ? $parkingtime  : '';
119   $goto   = ($goto)       ? $goto   : 'from-pstn,s,1';
120
121   $parkfields = array(array($parkinglot_id, 'parkingenabled', "$parkingenabled"),
122       array($parkinglot_id, 'parkext', "$parkext"),
123       array($parkinglot_id, 'numslots', "$numslots"),
124       array($parkinglot_id, 'parkingtime', "$parkingtime"),
125       array($parkinglot_id, 'parkingcontext', trim("$parkingcontext")),
126       array($parkinglot_id, 'parkalertinfo', trim("$parkalertinfo")),
127       array($parkinglot_id, 'parkcid', trim("$parkcid")),
128       array($parkinglot_id, 'parkingannmsg_id', "$parkingannmsg_id"),
129       array($parkinglot_id, 'goto', "$goto"));
130
131   $compiled = $db->prepare('INSERT INTO parkinglot (id, keyword, data) values (?,?,?)');
132
133   $result = $db->executeMultiple($compiled,$parkfields);
134   if(DB::IsError($result)) {
135     die_freepbx($result->getDebugInfo()."<br><br>".'error adding to PARKING table');
136   }
137 }
138
139
140 function parking_getconfig($parkinglot_id=1) {
141   global $db;
142   $sql = "SELECT keyword,data FROM parkinglot WHERE id = '$parkinglot_id'";
143   $results = $db->getAssoc($sql);
144   if(DB::IsError($results)) {
145     $results = null;
146   }
147   return $results;
148 }
149
150 function parking_check_destinations($dest=true) {
151   global $active_modules;
152
153   $destlist = array();
154   if (is_array($dest) && empty($dest)) {
155     return $destlist;
156   }
157   $sql = "SELECT keyword, data FROM parkinglot WHERE keyword = 'goto' ";
158   if ($dest !== true) {
159     $sql .= "AND data in ('".implode("','",$dest)."')";
160   }
161   $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
162
163   $type = isset($active_modules['parking']['type'])?$active_modules['parking']['type']:'setup';
164
165   foreach ($results as $result) {
166     $thisdest = $result['data'];
167     $destlist[] = array(
168       'dest' => $thisdest,
169       'description' => _('Parking Lot'),
170       'edit_url' => 'config.php?type='.$type.'&display=parking',
171     );
172   }
173   return $destlist;
174 }
175
176 function parking_change_destination($old_dest, $new_dest) {
177   $sql = 'UPDATE parkinglot SET data = "' . $new_dest . '" WHERE data = "' . $old_dest . '" AND keyword = "goto"';
178   sql($sql, "query");
179 }
180
181 function parking_recordings_usage($recording_id) {
182   global $active_modules;
183
184   $my_id = sql("SELECT `data` FROM `parkinglot` WHERE `id` = '1' AND `keyword` = 'parkingannmsg_id' AND `data` = '$recording_id'","getOne");
185   if (!isset($my_id) || $my_id == '') {
186     return array();
187   } else {
188     $type = isset($active_modules['parking']['type'])?$active_modules['parking']['type']:'setup';
189     $usage_arr[] = array(
190       'url_query' => 'config.php?type='.$type.'&display=parking',
191       'description' => _("Parking Lot"),
192     );
193     return $usage_arr;
194   }
195 }
196
197 // Duly stolen from the queues module (since I can't count on it being there, but would not be bad to stuff back in the common include
198 //
199 function parking_timeString($seconds, $full = false) {
200         if ($seconds == 0) {
201                 return "0 ".($full ? "seconds" : "s");
202         }
203
204         $minutes = floor($seconds / 60);
205         $seconds = $seconds % 60;
206
207         $hours = floor($minutes / 60);
208         $minutes = $minutes % 60;
209
210         $days = floor($hours / 24);
211         $hours = $hours % 24;
212
213         if ($full) {
214                 return substr(
215         ($days ? $days." "._("day").(($days == 1) ? "" : "s").", " : "").
216                                 ($hours ? $hours." ".(($hours == 1) ? _("hour") : _("hours")).", " : "").
217                                 ($minutes ? $minutes." ".(($minutes == 1) ? _("minute") : _("minutes")).", " : "").
218                                 ($seconds ? $seconds." ".(($seconds == 1) ? _("second") : _("seconds")).", " : ""),
219                                 0, -2);
220         } else {
221                 return substr(($days ? $days."d, " : "").($hours ? $hours."h, " : "").($minutes ? $minutes."m, " : "").($seconds ? $seconds."s, " : ""), 0, -2);
222         }
223 }
224
225 ?>
Note: See TracBrowser for help on using the browser.