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

Revision 4923, 3.8 kB (checked in by p_lindheimer, 5 years ago)

oops left debug statement in

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2 /*
3 function miscapp_destinations() {
4   // return an associative array with destination and description
5   foreach (announcement_list() as $row) {
6     $extens[] = array('destination' => 'app-announcement,ann-'.$row[0].',1', 'description' => $row[1]);
7   }
8   return $extens;
9 }
10 */
11
12 function miscapps_contexts() {
13   // return an associative array with context and description
14   foreach (miscapps_list() as $row) {
15     $contexts[] = array(
16       'context' => 'app-miscapps-'.$row['miscapps_id'],
17       'description'=> 'Misc Application: '.$row['description'],
18       'source' => 'Misc Applications',
19     );
20   }
21   return $contexts;
22 }
23
24 function miscapps_get_config($engine) {
25   global $ext;
26   switch ($engine) {
27     case 'asterisk':
28       foreach (miscapps_list(true) as $row) {
29         if ($row['enabled']) {
30           $ext->add('app-miscapps-'.$row['miscapps_id'], $row['ext'], '', new ext_noop('Running miscapp '.$row['miscapps_id'].': '.$row['description']));
31           $ext->add('app-miscapps-'.$row['miscapps_id'], $row['ext'], '', new ext_goto($row['dest']));
32          
33           $ext->addInclude('from-internal-additional', 'app-miscapps-'.$row['miscapps_id']);
34         }
35       }
36     break;
37   }
38 }
39
40
41 /**  Get a list of all miscapps
42  * Optional parameter is get_ext. Potentially slow, because each row is extracted from the featurecodes table
43  * one-by-one
44  */
45 function miscapps_list($get_ext = false) {
46   global $db;
47   $sql = "SELECT miscapps_id, description, dest FROM miscapps ORDER BY description ";
48   $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
49   if(DB::IsError($results)) {
50     die_freepbx($results->getMessage()."<br><br>Error selecting from miscapps"); 
51   }
52  
53   if ($get_ext) {
54     foreach (array_keys($results) as $idx) {
55       $fc = new featurecode('miscapps', 'miscapp_'.$results[$idx]['miscapps_id']);
56       $results[$idx]['ext'] = $fc->getDefault();
57       $results[$idx]['enabled'] = $fc->isEnabled();
58     }
59   }
60  
61   return $results;
62 }
63
64 function miscapps_get($miscapps_id) {
65   global $db;
66   $sql = "SELECT miscapps_id, description, ext, dest FROM miscapps WHERE miscapps_id = ".addslashes($miscapps_id);
67   $row = $db->getRow($sql, DB_FETCHMODE_ASSOC);
68   if(DB::IsError($row)) {
69     die_freepbx($row->getMessage()."<br><br>Error selecting row from miscapps"); 
70   }
71  
72   // we want to get the ext from featurecodes
73   $fc = new featurecode('miscapps', 'miscapp_'.$row['miscapps_id']);
74   $row['ext'] = $fc->getDefault();
75   $row['enabled'] = $fc->isEnabled();
76
77   return $row;
78 }
79
80 function miscapps_add($description, $ext, $dest) {
81   global $db;
82   $sql = "INSERT INTO miscapps (description, ext, dest) VALUES (".
83     "'".addslashes($description)."', ".
84     "'".addslashes($ext)."', ".
85     "'".addslashes($dest)."')";
86   $result = $db->query($sql);
87   if(DB::IsError($result)) {
88     die_freepbx($result->getMessage().$sql);
89   }
90   //get id..
91   $miscapps_id = $db->getOne('SELECT LAST_INSERT_ID()');
92   if (DB::IsError($miscapps_id)) {
93     //TODO -- handle this
94   }
95  
96   $fc = new featurecode('miscapps', 'miscapp_'.$miscapps_id);
97   $fc->setDescription($description);
98   $fc->setDefault($ext, true);
99   $fc->update();
100 }
101
102 function miscapps_delete($miscapps_id) {
103   global $db;
104   $sql = "DELETE FROM miscapps WHERE miscapps_id = ".addslashes($miscapps_id);
105   $result = $db->query($sql);
106   if(DB::IsError($result)) {
107     die_freepbx($result->getMessage().$sql);
108   }
109  
110   $fc = new featurecode('miscapps', 'miscapp_'.$miscapps_id);
111   $fc->delete();
112 }
113
114 function miscapps_edit($miscapps_id, $description, $ext, $dest, $enabled=true) {
115   global $db;
116   $sql = "UPDATE miscapps SET ".
117     "description = '".addslashes($description)."', ".
118     "ext = '".addslashes($ext)."', ".
119     "dest = '".addslashes($dest)."' ".
120     "WHERE miscapps_id = ".addslashes($miscapps_id);
121   $result = $db->query($sql);
122   if(DB::IsError($result)) {
123     die_freepbx($result->getMessage().$sql);
124   }
125  
126   $fc = new featurecode('miscapps', 'miscapp_'.$miscapps_id);
127   $fc->setDescription($description);
128   $fc->setDefault($ext, true);
129   $fc->setEnabled($enabled);
130   $fc->update();
131 }
132
133 ?>
Note: See TracBrowser for help on using the browser.