Overview

Packages

  • None
  • Shout

Classes

  • AccountDeleteForm
  • ConferenceDeleteForm
  • DeviceDeleteForm
  • DeviceMenuForm
  • ExtensionDeleteForm
  • NumberDeleteForm
  • Shout_Application
  • Shout_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Shout application interface.
  4:  *
  5:  * This file defines Horde's core API interface. Other core Horde libraries
  6:  * can interact with Shout through this API.
  7:  *
  8:  * Copyright 2006-2010 Alkaloid Networks (http://projects.alkaloid.net/)
  9:  *
 10:  * See the enclosed file LICENSE for license information (BSD). If you did not
 11:  * did not receive this file, see
 12:  * http://www.opensource.org/licenses/bsd-license.html.
 13:  *
 14:  * @author  Ben Klang <ben@alkaloid.net>
 15:  * @package Shout
 16:  */
 17: 
 18: if (!defined('SHOUT_BASE')) {
 19:     define('SHOUT_BASE', dirname(__FILE__). '/..');
 20: }
 21: 
 22: if (!defined('HORDE_BASE')) {
 23:     /* If horde does not live directly under the app directory, the HORDE_BASE
 24:      * constant should be defined in config/horde.local.php. */
 25:     if (file_exists(SHOUT_BASE. '/config/horde.local.php')) {
 26:         include SHOUT_BASE . '/config/horde.local.php';
 27:     } else {
 28:         define('HORDE_BASE', SHOUT_BASE . '/..');
 29:     }
 30: }
 31: 
 32: /* Load the Horde Framework core (needed to autoload
 33:  * Horde_Registry_Application::). */
 34: require_once HORDE_BASE . '/lib/core.php';
 35: 
 36: class Shout_Application extends Horde_Registry_Application
 37: {
 38:     /**
 39:      */
 40:     public $version = 'H4 (1.0-git)';
 41: 
 42:     /**
 43:      * TODO
 44:      */
 45:     public $storage = null;
 46: 
 47:     /**
 48:      * TODO
 49:      */
 50:     public $extensions = null;
 51: 
 52:     /**
 53:      * TODO
 54:      */
 55:     public $devices = null;
 56: 
 57:     /**
 58:      * TODO
 59:      */
 60:     public $dialplan = null;
 61: 
 62:     /**
 63:      * TODO
 64:      */
 65:     public $vfs = null;
 66: 
 67:     /**
 68:      */
 69:     protected function _init()
 70:     {
 71:         try {
 72:             $this->storage = Shout_Driver::factory('storage');
 73:             $this->extensions = Shout_Driver::factory('extensions');
 74:             $this->devices = Shout_Driver::factory('devices');
 75:             $this->dialplan = Shout_Driver::factory('dialplan');
 76:             $conf = $GLOBALS['conf'];
 77:             $this->vfs = Horde_Vfs::factory($conf['ivr']['driver'], $conf['ivr']['params']);
 78: 
 79:             $accounts = $this->storage->getAccounts();
 80:         } catch (Shout_Exception $e) {
 81:             $GLOBALS['notification']->push($e);
 82:             $accounts = false;
 83:             return false;
 84:         }
 85: 
 86:         $account = Horde_Util::getFormData('account');
 87:         if (empty($account)) {
 88:             $account = $GLOBALS['session']->get('shout', 'curaccount_code');
 89:         }
 90: 
 91:         if (!empty($account) && !in_array($account, array_keys($accounts))) {
 92:             // Requested account not available
 93:             $GLOBALS['notification']->push(_("You do not have permission to access that account."), 'horde.error');
 94:             $account = false;
 95:         }
 96: 
 97:         if (empty($account)) {
 98:             if (count($accounts)) {
 99:                 // Default to the user's first account
100:                 $account = reset(array_keys($accounts));
101:             } else {
102:                 // No account requested and/or no accounts available anyway
103:                 $GLOBALS['notification']->push("Please select a account to continue.", 'horde.info');
104:                 $account = false;
105:             }
106:         }
107: 
108:         $session->set('shout', 'curaccount_code', $accounts[$account]['code']);
109:         $session->set('shout', 'curaccount_name', $accounts[$account]['name']);
110:     }
111: 
112:     /**
113:      */
114:     public function perms()
115:     {
116:         $perms = array(
117:             'accounts' => array(
118:                 'title' => _("Accounts")
119:             ),
120:             'superadmin' => array(
121:                 'title' => _("Super Administrator")
122:             )
123:         );
124: 
125:         $accounts = $this->storage->getAccounts();
126: 
127:         // Run through every contact source.
128:         foreach ($accounts as $code => $info) {
129:             $perms['account:' . $code] = array(
130:                 'title' => $info['name']
131:             );
132: 
133:             foreach(
134:                 array(
135:                     'extensions' => 'Extensions',
136:                     'devices' => 'Devices',
137:                     'conferences' => 'Conference Rooms',
138:                 )
139:                 as $module => $modname) {
140:                 $perms['accounts:' . $code . ':' . $module] = array(
141:                     'title' => $modname
142:                 );
143:             }
144:         }
145: 
146:         return $perms;
147:     }
148: 
149: 
150:     public function getRecordings()
151:     {
152:         $account = $GLOBALS['session']->get('shout', 'curaccount_code');
153:         $rlist = $this->vfs->listFolder($account);
154: 
155:         // In Asterisk, filenames the same basename and different extension are
156:         // functionally equivalent.  Asterisk chooses the file based on the least cost
157:         // to transcode.  For that reason, we will drop the filename extension when
158:         // handling files.
159:         $recordings = array();
160:         foreach ($rlist as $name => $info) {
161:             $name = substr($name, 0, strrpos($name, '.'));
162:             $info['name'] = $name;
163:             $recordings[$name] = $info;
164:         }
165: 
166:         return $recordings;
167:     }
168: 
169: }
170: 
API documentation generated by ApiGen