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

Revision 5276, 4.3 kB (checked in by p_lindheimer, 5 years ago)

remove miscapps_check_extensions() because featurecode_admin handles it

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