Overview

Packages

  • None
  • Shout

Classes

  • AccountDetailsForm
  • ConferenceDetailsForm
  • DeviceDetailsForm
  • ExtensionDetailsForm
  • MenuForm
  • NumberDetailsForm
  • RecordingDetailsForm
  • Shout
  • Shout_Ajax_Application
  • Shout_Driver
  • Shout_Driver_Ldap
  • Shout_Driver_Sql
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Defines the AJAX interface for Shout.
  4:  *
  5:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Michael Slusarz <slusarz@horde.org>
 11:  * @author  Ben Klang <ben@alkaloid.net>
 12:  * @package Shout
 13:  */
 14: class Shout_Ajax_Application extends Horde_Core_Ajax_Application
 15: {
 16:     public function saveExtension()
 17:     {
 18:         try {
 19:             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
 20:             $curaccount = $GLOBALS['session']->get('shout', 'curaccount_code');
 21:             require_once SHOUT_BASE . '/lib/Forms/ExtensionForm.php';
 22:             $this->_vars->set('account', $curaccount);
 23:             $Form = new ExtensionDetailsForm($this->_vars);
 24:             $Form->setSubmitted();
 25:             if ($Form->isValid()) {
 26:                 $Form->execute();
 27:                 return true;
 28:             }
 29:         } catch (Exception $e) {
 30:             //FIXME: Create a way to notify the user of the failure.
 31:             Horde::logMessage($e, 'ERR');
 32:             return false;
 33:         }
 34:     }
 35: 
 36:     /**
 37:      * TODO
 38:      */
 39:     public function addDestination()
 40:     {
 41:         $vars = $this->_vars;
 42:         $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
 43:         $account = $GLOBALS['session']->get('shout', 'curaccount_code');
 44:         try {
 45:             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
 46:             $shout->extensions->addDestination($account, $vars->extension, $vars->type, $vars->destination);
 47: 
 48:             return $shout->extensions->getExtensions($account);
 49:         } catch (Exception $e) {
 50:             //FIXME: Create a way to notify the user of the failure.
 51:             Horde::logMessage($e, 'ERR');
 52:             return false;
 53:         }
 54:     }
 55: 
 56:     /**
 57:      * TODO
 58:      */
 59:     public function deleteDestination()
 60:     {
 61:         $vars = $this->_vars;
 62:         $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
 63:         $account = $GLOBALS['session']->get('shout', 'curaccount_code');
 64:         try {
 65:             // FIXME: Use Form?
 66:             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
 67:             $shout->extensions->deleteDestination($account, $vars->extension, $vars->type, $vars->destination);
 68: 
 69:             return $this->getDestinations();
 70:         } catch (Exception $e) {
 71:             //FIXME: Create a way to notify the user of the failure.
 72:             Horde::logMessage($e, 'ERR');
 73:             return false;
 74:         }
 75:     }
 76: 
 77:     /**
 78:      * TODO
 79:      */
 80:     public function getDestinations()
 81:     {
 82:         try {
 83:             $vars = $this->_vars;
 84:             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
 85:             $account = $GLOBALS['session']->get('shout', 'curaccount_code');
 86:             return $shout->extensions->getExtensions($account);
 87:         } catch (Exception $e) {
 88:             //FIXME: Create a way to notify the user of the failure.
 89:             Horde::logMessage($e, 'ERR');
 90:             return false;
 91:         }
 92:     }
 93: 
 94:     public function getDevices()
 95:     {
 96:         try {
 97:             $vars = $this->_vars;
 98:             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
 99:             $account = $GLOBALS['session']->get('shout', 'curaccount_code');
100:             $devices = $shout->devices->getDevices($account);
101:             if (empty($devices)) {
102:                 return false;
103:             } else {
104:                 return $devices;
105:             }
106:         } catch (Exception $e) {
107:             //FIXME: Create a way to notify the user of the failure.
108:             Horde::logMessage($e, 'ERR');
109:             return false;
110:         }
111:     }
112: 
113:     /**
114:      * TODO
115:      */
116:     public function getMenus()
117:     {
118:         try {
119:             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
120:             $account = $GLOBALS['session']->get('shout', 'curaccount_code');
121:             $menus = $shout->storage->getMenus($account);
122:             if (empty($menus)) {
123:                 return false;
124:             }
125:             foreach ($menus as $menu => $info) {
126:                 // Fill in the actions for each menu
127:                 $menus[$menu]['actions'] = $shout->dialplan->getMenuActions($account, $menu);
128:             }
129:             return $menus;
130:         } catch (Exception $e) {
131:             //FIXME: Create a way to notify the user of the failure.
132:             Horde::logMessage($e, 'ERR');
133:             return false;
134:         }
135:     }
136: 
137:     public function deleteMenu()
138:     {
139:         try {
140:             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
141:             $account = $GLOBALS['session']->get('shout', 'curaccount_code');
142:             $menu = $this->_vars->get('menu');
143:             if (empty($menu)) {
144:                 throw new Shout_Exception('Must specify a menu to delete.');
145:             }
146:             $shout->dialplan->deleteMenu($account, $menu);
147:             return true;
148:         } catch (Exception $e) {
149:             //FIXME: Create a way to notify the user of the failure.
150:             Horde::logMessage($e, 'ERR');
151:             return false;
152:         }
153:     }
154: 
155:     public function getConferences()
156:     {
157:         try {
158:             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
159:             $account = $GLOBALS['session']->get('shout', 'curaccount_code');
160:             return $shout->storage->getConferences($account);
161:         } catch (Exception $e) {
162:             //FIXME: Create a way to notify the user of the failure.
163:             Horde::logMessage($e, 'ERR');
164:             return false;
165:         }
166:     }
167: 
168:     public function saveMenuInfo()
169:     {
170:         try {
171:             $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
172:             $account = $GLOBALS['session']->get('shout', 'curaccount_code');
173:             $vars = &$this->_vars;
174:             $info = array(
175:                 'name' => $vars->get('name'),
176:                 'oldname' => $vars->get('oldname'),
177:                 'description' => $vars->get('description'),
178:                 'recording_id' => $vars->get('recording_id')
179:             );
180:             return $shout->storage->saveMenuInfo($account, $info);
181:         } catch (Exception $e) {
182:             //FIXME: Create a way to notify the user of the failure.
183:             Horde::logMessage($e, 'ERR');
184:             return false;
185:         }
186:     }
187: 
188:     public function saveAction()
189:     {
190:         try {
191:             $shout = $GLOBALS['shout'] = Horde_Registry::appInit('shout');
192:             $vars = $this->_vars;
193:             if (!($action = $vars->get('action'))) {
194:                 throw new Shout_Exception("Invalid action requested.");
195:             }
196:             $account = $GLOBALS['session']->get('shout', 'curaccount_code');
197:             $digit = $vars->get('digit');
198:             $menu = $vars->get('menu');
199:             $action = $vars->get('action');
200: 
201:             if ($action == 'none') {
202:                 // Remove the menu action and return
203:                 $shout->dialplan->deleteMenuAction($account, $menu, $digit);
204:                 return true;
205:             }
206: 
207:             $actions = Shout::getMenuActions();
208:             if (!isset($actions[$action])) {
209:                 throw new Shout_Exception('Invalid action requested.');
210:             }
211:             $args = array();
212:             foreach ($actions[$action]['args'] as $name => $info) {
213:                 $args[$name] = $vars->get($name);
214:             }
215:             $shout->dialplan->saveMenuAction($account, $menu, $digit, $action, $args);
216:             return true;
217:         } catch (Exception $e) {
218:             //FIXME: Create a way to notify the user of the failure.
219:             Horde::logMessage($e, 'ERR');
220:             return false;
221:         }
222:     }
223: 
224:     public function logException()
225:     {
226:         $vars = &$this->_vars;
227:         $filename = $vars->get('fileName');
228:         $message = $vars->get('message');
229:         $stack = $vars->get('stack');
230:         $log = sprintf('Client side error in %s: %s.  Stacktrace follows:\n%s',
231:                        $filename, $message, $stack);
232:         Horde::logMessage($log, 'ERR');
233:         return true;
234:     }
235: 
236: }
237: 
API documentation generated by ApiGen