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

Revision 4767, 5.8 kB (checked in by gregmac, 5 years ago)

Change all freepbx die() calls to die_freepbx()

  • 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 function parking_destinations() {
4 }
5
6 /*  Generates dialplan for parkinglot
7   We call this with retrieve_conf
8 */
9 function parking_get_config($engine) {
10   global $db;
11   global $ext;  // is this the best way to pass this?
12   global $asterisk_conf;
13   switch($engine) {
14     case "asterisk":
15
16     $contextname = 'park-dial';
17
18     $parkinglot_id = 1; // only 1 parking lot, but prepare for future
19     $results = parking_getconfig($parkinglot_id);
20
21     // Got the array, let's go work out the required variables
22     //
23     $parkingenabled = isset($results['parkingenabled'])?$results['parkingenabled']:'';
24     $parkext  = isset($results['parkext'])?$results['parkext']:70;
25     $numslots   = isset($results['numslots'])?$results['numslots']:8;
26     $parkingtime  = isset($results['parkingtime'])?$results['parkingtime']:'';
27     $parkingcontext = isset($results['parkingcontext'])?$results['parkingcontext']:'parkedcalls';
28     $parkalertinfo  = isset($results['parkalertinfo'])?$results['parkalertinfo']:'';
29     $parkcid  = isset($results['parkcid'])?$results['parkcid']:'';
30     $parkingannmsg  = isset($results['parkingannmsg'])?$results['parkingannmsg']:'';
31     $goto   = isset($results['goto'])?$results['goto']:'from-pstn,s,1';
32
33     $parkpos1 = $parkext + 1;
34     $parkpos2 = $parkpos1 + $numslots;
35
36     //open the file and truncate. If diabled, file will be deleted this way
37     //AND GET THE ENV VARIABLES TO CALL THIS BY
38
39     $filename = isset($asterisk_conf["astetcdir"]) && $asterisk_conf["astetcdir"] != '' ? rtrim($asterisk_conf["astetcdir"],DIRECTORY_SEPARATOR) : "/etc/asterisk";
40     $filename .= "/parking_additional.inc";
41     $fh = fopen($filename, "w+");
42     fwrite($fh, ";*** WARNING: DO NOT HAND EDIT THIS FILE IT IS AUTO-GENERATD ***\n;\n");
43
44     if ($parkingenabled) {
45       // TODO: lookup ampportal.conf variables for this, don't hard code
46       // first write features_additional.inc include file
47       //
48       fwrite($fh, "parkext => ".$parkext."\n");
49       fwrite($fh, "parkpos => ".$parkpos1."-".$parkpos2."\n");
50       fwrite($fh, "context => ".$parkingcontext."\n");
51       if ($parkingtime) {
52         fwrite($fh, "parkingtime => ".$parkingtime."\n");
53       }
54
55       // Now generate dialplan
56       $ext->add($contextname, "t", '', new ext_noop('Parked Call Timed Out and Got Orphaned'));
57       if ($parkalertinfo) {
58         $ext->add($contextname, "t", '', new ext_setvar('__ALERT_INFO',str_replace(';', '\;', $parkalertinfo)));
59       }
60       if ($parkcid) {
61         $ext->add($contextname, "t", '', new ext_setvar('CALLERID(name)', $parkcid.'${CALLERID(name)}'));
62       }
63       if ($parkingannmsg) {
64         $ext->add($contextname, "t", '', new ext_playback($parkingannmsg));
65       }
66       // goto the destination here
67       //
68       $ext->add($contextname, "t", '', new ext_goto($goto));
69     } else {
70     fwrite($fh, ";***              PARKING LOT HAS BEEN DISABLED              ***\n");
71     }
72     fclose($fh);
73     chmod($filename, 0660);
74     break;
75   }
76 }
77
78 function parking_add($parkingenabled, $parkext, $numslots, $parkingtime, $parkingcontext, $parkalertinfo, $parkcid, $parkingannmsg, $goto) {
79   global $db;
80
81   $parkinglot_id  = 1; // only 1 parkinglot but prepare for future
82
83   // in future will do in a parking_del but not needed for now
84   //
85   $sql = "DELETE FROM parkinglot WHERE id = '$parkinglot_id'";
86   $result = $db->query($sql);
87   if(DB::IsError($result)) {
88     die_freepbx($result->getMessage().$sql);
89   }
90
91   // Check for interger only inputs and set to default if not
92   //  and set goto to default if not set for some reason
93   //
94   $parkext  = ctype_digit($parkext)   ? $parkext  : 70;
95   $numslots   = ctype_digit($numslots)    ? $numslots : 8;
96   $parkingtime  = ctype_digit($parkingtime) ? $parkingtime  : '';
97   $goto   = ($goto)       ? $goto   : 'from-pstn,s,1';
98
99   $parkfields = array(array($parkinglot_id, 'parkingenabled', "$parkingenabled"),
100       array($parkinglot_id, 'parkext', "$parkext"),
101       array($parkinglot_id, 'numslots', "$numslots"),
102       array($parkinglot_id, 'parkingtime', "$parkingtime"),
103       array($parkinglot_id, 'parkingcontext', trim("$parkingcontext")),
104       array($parkinglot_id, 'parkalertinfo', trim("$parkalertinfo")),
105       array($parkinglot_id, 'parkcid', trim("$parkcid")),
106       array($parkinglot_id, 'parkingannmsg', "$parkingannmsg"),
107       array($parkinglot_id, 'goto', "$goto"));
108
109   $compiled = $db->prepare('INSERT INTO parkinglot (id, keyword, data) values (?,?,?)');
110
111   $result = $db->executeMultiple($compiled,$parkfields);
112   if(DB::IsError($result)) {
113     die_freepbx($result->getDebugInfo()."<br><br>".'error adding to PARKING table');
114   }
115 }
116
117
118 function parking_getconfig($parkinglot_id=1) {
119   global $db;
120   $sql = "SELECT keyword,data FROM parkinglot WHERE id = '$parkinglot_id'";
121   $results = $db->getAssoc($sql);
122   if(DB::IsError($results)) {
123     $results = null;
124   }
125   return $results;
126 }
127
128 // 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
129 //
130 function parking_timeString($seconds, $full = false) {
131         if ($seconds == 0) {
132                 return "0 ".($full ? "seconds" : "s");
133         }
134
135         $minutes = floor($seconds / 60);
136         $seconds = $seconds % 60;
137
138         $hours = floor($minutes / 60);
139         $minutes = $minutes % 60;
140
141         $days = floor($hours / 24);
142         $hours = $hours % 24;
143
144         if ($full) {
145                 return substr(
146                                 ($days ? $days." day".(($days == 1) ? "" : "s").", " : "").
147                                 ($hours ? $hours." hour".(($hours == 1) ? "" : "s").", " : "").
148                                 ($minutes ? $minutes." minute".(($minutes == 1) ? "" : "s").", " : "").
149                                 ($seconds ? $seconds." second".(($seconds == 1) ? "" : "s").", " : ""),
150                                0, -2);
151         } else {
152                 return substr(($days ? $days."d, " : "").($hours ? $hours."h, " : "").($minutes ? $minutes."m, " : "").($seconds ? $seconds."s, " : ""), 0, -2);
153         }
154 }
155
156 ?>
Note: See TracBrowser for help on using the browser.