| 1 |
<?php /* $Id: config.php 2115 2006-06-28 23:30:39Z mheydon1973 $ */ |
|---|
| 2 |
//Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca) |
|---|
| 3 |
// |
|---|
| 4 |
//This program is free software; you can redistribute it and/or |
|---|
| 5 |
//modify it under the terms of the GNU General Public License |
|---|
| 6 |
//as published by the Free Software Foundation; either version 2 |
|---|
| 7 |
//of the License, or (at your option) any later version. |
|---|
| 8 |
// |
|---|
| 9 |
//This program is distributed in the hope that it will be useful, |
|---|
| 10 |
//but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 |
//GNU General Public License for more details. |
|---|
| 13 |
|
|---|
| 14 |
$title="freePBX administration"; |
|---|
| 15 |
|
|---|
| 16 |
// determine module type to show, default to 'setup' |
|---|
| 17 |
if(isset($_REQUEST['type']) && $_REQUEST['type'] == "tool") { |
|---|
| 18 |
$message="Tools"; |
|---|
| 19 |
} else { |
|---|
| 20 |
$message="Setup"; |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
$quietmode = isset($_REQUEST['quietmode'])?$_REQUEST['quietmode']:''; |
|---|
| 24 |
require_once('functions.inc.php'); |
|---|
| 25 |
|
|---|
| 26 |
// get settings |
|---|
| 27 |
$amp_conf = parse_amportal_conf("/etc/amportal.conf"); |
|---|
| 28 |
$asterisk_conf = parse_asterisk_conf("/etc/asterisk/asterisk.conf"); |
|---|
| 29 |
|
|---|
| 30 |
include 'header_auth.php'; |
|---|
| 31 |
|
|---|
| 32 |
if (isset($_REQUEST['display'])) { |
|---|
| 33 |
$display=$_REQUEST['display']; |
|---|
| 34 |
} else { |
|---|
| 35 |
$display=''; |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
// if we are looking at tools, then show module admin |
|---|
| 39 |
if ($_REQUEST['type'] == "tool") { |
|---|
| 40 |
$amp_sections = array( |
|---|
| 41 |
'modules'=>_("Module Admin") |
|---|
| 42 |
); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
/* |
|---|
| 46 |
// only show AMP Users if they have authtype set approiately |
|---|
| 47 |
if (isset($amp_conf["AUTHTYPE"]) && ($amp_conf["AUTHTYPE"] != "none")) { |
|---|
| 48 |
$amp_sections[10] = _("AMP Users"); |
|---|
| 49 |
}*/ |
|---|
| 50 |
|
|---|
| 51 |
// determine module type to show, default to 'setup' |
|---|
| 52 |
if(isset($_REQUEST['type']) && $_REQUEST['type'] == "tool") { |
|---|
| 53 |
$type='tool'; |
|---|
| 54 |
} else { |
|---|
| 55 |
$type='setup'; |
|---|
| 56 |
} |
|---|
| 57 |
// get all enabled modules |
|---|
| 58 |
// active_modules array used below and in drawselects function and genConf function |
|---|
| 59 |
$active_modules = find_modules(2); |
|---|
| 60 |
|
|---|
| 61 |
// include any module global functions |
|---|
| 62 |
// add module sections to $amp_sections |
|---|
| 63 |
if(is_array($active_modules)){ |
|---|
| 64 |
foreach($active_modules as $key => $module) { |
|---|
| 65 |
//include module functions |
|---|
| 66 |
if (is_file("modules/{$key}/functions.inc.php")) { |
|---|
| 67 |
require_once("modules/{$key}/functions.inc.php"); |
|---|
| 68 |
} |
|---|
| 69 |
//create an array of module sections to display |
|---|
| 70 |
// only of the type we are displaying though |
|---|
| 71 |
if ($module['type'] == $type) { |
|---|
| 72 |
if (is_array($module['items'])) { |
|---|
| 73 |
foreach($module['items'] as $itemKey => $itemName) { |
|---|
| 74 |
$amp_sections[$itemKey] = $itemName; |
|---|
| 75 |
|
|---|
| 76 |
//list of potential _configpageinit functions |
|---|
| 77 |
$initfuncname = $key . '_' . $itemKey . '_configpageinit'; |
|---|
| 78 |
if ( function_exists($initfuncname) ) { |
|---|
| 79 |
$configpageinits[] = $initfuncname; |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
//check for module level (rather than item as above) _configpageinit function |
|---|
| 84 |
$initfuncname = $key . '_configpageinit'; |
|---|
| 85 |
if ( function_exists($initfuncname) ) { |
|---|
| 86 |
$configpageinits[] = $initfuncname; |
|---|
| 87 |
} |
|---|
| 88 |
} |
|---|
| 89 |
//sort it? probably not right but was getting in a mess to be honest |
|---|
| 90 |
//so something better than nothing |
|---|
| 91 |
if (is_array($amp_sections)) |
|---|
| 92 |
asort($amp_sections); |
|---|
| 93 |
} |
|---|
| 94 |
} |
|---|
| 95 |
if (!$quietmode) { |
|---|
| 96 |
echo "<table width=\"100%\" cellspacing='0' cellpadding='0'><tr><td>"; |
|---|
| 97 |
// show menu |
|---|
| 98 |
echo "<div class=\"nav\">\n"; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
// extensions vs device/users ... this is a bad design, but hey, it works |
|---|
| 102 |
if (isset($amp_conf["AMPEXTENSIONS"]) && ($amp_conf["AMPEXTENSIONS"] == "deviceanduser")) { |
|---|
| 103 |
unset($amp_sections["extensions"]); |
|---|
| 104 |
} else { |
|---|
| 105 |
unset($amp_sections["devices"]); |
|---|
| 106 |
unset($amp_sections["users"]); |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
// add the APPLY Changes bar as a section, so it shows in the Administrators module |
|---|
| 111 |
$amp_sections[99] = _("Apply Changes Bar"); |
|---|
| 112 |
|
|---|
| 113 |
foreach ($amp_sections as $key=>$value) { |
|---|
| 114 |
// check access |
|---|
| 115 |
if ($_SESSION["AMP_user"]->checkSection($key)) { |
|---|
| 116 |
if ($key != 99) { |
|---|
| 117 |
// if the module has it's own translations, use them for displaying menu item |
|---|
| 118 |
if (extension_loaded('gettext')) { |
|---|
| 119 |
if(is_dir("modules/{$key}/i18n")) { |
|---|
| 120 |
bindtextdomain($key,"modules/{$key}/i18n"); |
|---|
| 121 |
textdomain($key); |
|---|
| 122 |
} else { |
|---|
| 123 |
bindtextdomain('amp','./i18n'); |
|---|
| 124 |
textdomain('amp'); |
|---|
| 125 |
} |
|---|
| 126 |
} |
|---|
| 127 |
if (!$quietmode) { |
|---|
| 128 |
if(preg_match("/^(<a.+>)(.+)(<\/a>)/",$value,$matches)) |
|---|
| 129 |
echo "<li>".$matches[1]._($matches[2]).$matches[3]."</li>\n"; |
|---|
| 130 |
else |
|---|
| 131 |
echo "<li><a id=\"".(($display==$key) ? 'current':'')."\" href=\"config.php?".(isset($_REQUEST['type'])?"type={$_REQUEST['type']}&":"")."display=".$key."\">"._($value)."</a></li>\n"; |
|---|
| 132 |
} |
|---|
| 133 |
} |
|---|
| 134 |
} else { |
|---|
| 135 |
// they don't have access to this, remove it completely |
|---|
| 136 |
unset($amp_sections[$key]); |
|---|
| 137 |
} |
|---|
| 138 |
} |
|---|
| 139 |
if (!$quietmode) { |
|---|
| 140 |
echo "</div>\n<div class=\"content\">\n"; |
|---|
| 141 |
} |
|---|
| 142 |
// check access |
|---|
| 143 |
if ( ($display != '') && !isset($amp_sections[$display]) ) { |
|---|
| 144 |
$display = "noaccess"; |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
// load the component from the loaded modules |
|---|
| 148 |
if ( $display != '' && is_array($configpageinits) ) { |
|---|
| 149 |
$currentcomponent = new component($display); |
|---|
| 150 |
|
|---|
| 151 |
// call every modules _configpageinit function which should just |
|---|
| 152 |
// register the gui and process functions for each module, if relevent |
|---|
| 153 |
// for this $display |
|---|
| 154 |
foreach ($configpageinits as $func) { |
|---|
| 155 |
$func($display); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
// now run each 'process' function and 'gui' function |
|---|
| 159 |
$currentcomponent->processconfigpage(); |
|---|
| 160 |
$currentcomponent->buildconfigpage(); |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
// show the approiate page |
|---|
| 164 |
switch($display) { |
|---|
| 165 |
default: |
|---|
| 166 |
//display the appropriate module page |
|---|
| 167 |
if (!is_array($active_modules)) { |
|---|
| 168 |
break; |
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
foreach ($active_modules as $modkey => $module) { |
|---|
| 172 |
if (!is_array($module['items'])){ |
|---|
| 173 |
continue; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
foreach (array_keys($module['items']) as $item){ |
|---|
| 177 |
if ($display != $item) { |
|---|
| 178 |
continue; |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
// modules can use their own translation files |
|---|
| 182 |
if (extension_loaded('gettext')) { |
|---|
| 183 |
if(is_dir("./modules/{$modkey}/i18n")) { |
|---|
| 184 |
bindtextdomain($modkey,"./modules/{$modkey}/i18n"); |
|---|
| 185 |
textdomain($modkey); |
|---|
| 186 |
} |
|---|
| 187 |
} |
|---|
| 188 |
|
|---|
| 189 |
//TODO Determine which item is this module displaying. Currently this is over the place, we should standarize on a "itemid" request var for now, we'll just cover all possibilities :-( |
|---|
| 190 |
$possibilites = array( |
|---|
| 191 |
'userdisplay', |
|---|
| 192 |
'extdisplay', |
|---|
| 193 |
'id', |
|---|
| 194 |
'itemid', |
|---|
| 195 |
'category', |
|---|
| 196 |
'selection' |
|---|
| 197 |
); |
|---|
| 198 |
$itemid = ''; |
|---|
| 199 |
foreach($possibilites as $possibility) { |
|---|
| 200 |
if ( isset($_REQUEST[$possibility]) && $_REQUEST[$possibility] != '' ) |
|---|
| 201 |
$itemid = $_REQUEST[$possibility]; |
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
// create a module_hook object for this module's page |
|---|
| 205 |
$module_hook = new moduleHook; |
|---|
| 206 |
|
|---|
| 207 |
// populate object variables |
|---|
| 208 |
$module_hook->install_hooks($itemid,$modkey,$item); |
|---|
| 209 |
|
|---|
| 210 |
// include the module page |
|---|
| 211 |
include "modules/{$modkey}/page.{$item}.php"; |
|---|
| 212 |
|
|---|
| 213 |
// global component |
|---|
| 214 |
if ( isset($currentcomponent) ) { |
|---|
| 215 |
echo $currentcomponent->generateconfigpage(); |
|---|
| 216 |
} |
|---|
| 217 |
|
|---|
| 218 |
// let hooking modules process the $_REQUEST |
|---|
| 219 |
$module_hook->process_hooks($itemid,$modkey,$item,$_REQUEST); |
|---|
| 220 |
} |
|---|
| 221 |
} |
|---|
| 222 |
break; |
|---|
| 223 |
case 'noaccess': |
|---|
| 224 |
echo "<h2>"._("Not found")."</h2>"; |
|---|
| 225 |
echo "<p>"._("The section you requested does not exist or you do not have access to it.")."</p>"; |
|---|
| 226 |
break; |
|---|
| 227 |
case 'modules': |
|---|
| 228 |
include 'page.modules.php'; |
|---|
| 229 |
break; |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
//use main translation file for footer |
|---|
| 233 |
if (extension_loaded('gettext')) { |
|---|
| 234 |
bindtextdomain('amp','./i18n'); |
|---|
| 235 |
textdomain('amp'); |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
?> |
|---|
| 239 |
</div> |
|---|
| 240 |
</td></tr></table> |
|---|
| 241 |
<?php include 'footer.php' ?> |
|---|