Changeset 4446

Show
Ignore:
Timestamp:
07/19/07 02:26:10 (6 years ago)
Author:
gregmac
Message:

Add support for 'display' menuitem attribute,
Rework config.php to use 'display' to select current page, instead of menuitem key
Some optimizations to config.php processing (at least two nested foreach loops removed)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.3/amp_conf/htdocs/admin/config.php

    r4442 r4446  
    9191// initialize menu with module admin 
    9292$fpbx_menu = array( 
    93   'modules1' => array('type'=>'tool', 'category' => 'Admin', 'name' => 'Module Admin', 'sort' => -9), 
    94   'modules2' => array('type'=>'setup', 'category' => 'Admin', 'name' => 'Module Admin', 'sort' => -9), 
    95   'dashboard1' => array('type'=>'setup', 'category' => 'Admin', 'name' => 'Status Dashboard', 'sort' => -10), 
    96   'dashboard2' => array('type'=>'tool', 'category' => 'Admin', 'name' => 'Status Dashboard', 'sort' => -10), 
     93  'modules1' => array('display'=>'modules', 'type'=>'tool', 'category' => 'Admin', 'name' => 'Module Admin', 'sort' => -9), 
     94  'modules2' => array('display'=>'modules', 'type'=>'setup', 'category' => 'Admin', 'name' => 'Module Admin', 'sort' => -9), 
    9795); 
     96 
     97// pointer to current item in $fpbx_menu, if applicable 
     98$cur_menuitem = null; 
     99 
     100// handler just to check hardcoded fpbx_menu items to see whats being displayed 
     101//   For non-hardcoded modules we check this below while looping through $active_modules. 
     102//   These are separate to avoid looping through $active_modules and then $fpbX_menu 
     103foreach ($fpbx_menu as $itemKey => $item) { 
     104  if ($item['display'] == $display) { 
     105    $cur_menuitem =& $fpbx_menu[$itemKey]; 
     106  } 
     107} 
    98108 
    99109// include any module global functions 
     
    106116      require_once("modules/{$key}/functions.inc.php"); 
    107117    } 
     118     
     119    // check access 
     120    // TODO : do we always include functions.inc (like it is now), or do we put this check first? 
     121    if (!$_SESSION["AMP_user"]->checkSection($itemKey)) { 
     122      // no access, skip to the next  
     123      continue; 
     124    } 
     125     
     126    // if the module has it's own translations, use them for displaying menu item 
     127    if (extension_loaded('gettext')) { 
     128      if (is_dir("modules/{$key}/i18n")) { 
     129        bindtextdomain($key,"modules/{$key}/i18n"); 
     130        bind_textdomain_codeset($key, 'utf8'); 
     131        textdomain($key); 
     132      } else { 
     133        bindtextdomain('amp','./i18n'); 
     134        textdomain('amp'); 
     135      } 
     136    } 
     137     
    108138    //create an array of module sections to display 
    109     // only of the type we are displaying though 
    110      
    111139    // stored as [items][$type][$category][$name] = $displayvalue 
    112140    if (isset($module['items']) && is_array($module['items'])) { 
     
    116144          $types[] = $item['type']; 
    117145        } 
    118         // item is an assoc array, with at least array(name=>, category=>, type=>) 
     146         
     147        if (!isset($item['display'])) { 
     148          $item['display'] = $itemKey; 
     149        } 
     150         
     151        // reference to the actual module 
     152        $item['module'] =& $active_modules[$key]; 
     153         
     154        // item is an assoc array, with at least array(module=> name=>, category=>, type=>, display=>) 
    119155        $fpbx_menu[$itemKey] = $item; 
    120156         
    121157        // allow a module to replace our main index page 
    122         if (($itemKey == 'index') && ($display == '')) { 
    123           $display = $itemKey; 
     158        if (($item['display'] == 'index') && ($display == '')) { 
     159          $display = 'index'; 
     160        } 
     161         
     162        // check current item 
     163        if ($display == $item['display']) { 
     164          // found current menuitem, make a reference to it  
     165          $cur_menuitem =& $fpbx_menu[$itemKey]; 
    124166        } 
    125167      } 
     
    149191} 
    150192 
    151  
    152193// extensions vs device/users ... this is a bad design, but hey, it works 
    153194if (isset($amp_conf["AMPEXTENSIONS"]) && ($amp_conf["AMPEXTENSIONS"] == "deviceanduser")) { 
     
    158199} 
    159200 
    160 if (is_array($fpbx_menu)) { 
    161   foreach ($fpbx_menu as $key => $value) { 
    162     // check access 
    163     if ($_SESSION["AMP_user"]->checkSection($key)) { 
    164       // if the module has it's own translations, use them for displaying menu item 
    165       if (extension_loaded('gettext')) { 
    166         if (is_dir("modules/{$key}/i18n")) { 
    167           bindtextdomain($key,"modules/{$key}/i18n"); 
    168           bind_textdomain_codeset($key, 'utf8'); 
    169           textdomain($key); 
    170         } else { 
    171           bindtextdomain('amp','./i18n'); 
    172           textdomain('amp'); 
    173         } 
    174       } 
    175     } else { 
    176       // they don't have access to this, remove it completely 
    177       unset($fpbx_menu[$key]); 
    178     } 
    179   } 
    180 } 
    181  
    182  
    183  
    184201// check access 
    185 if ( ($display != '') && !isset($fpbx_menu[$display]) ) { 
     202if (!is_array($cur_menuitem)) { 
    186203  showview("noaccess"); 
    187204  exit; 
     
    208225// This may change in the future, with proper returns, but for now, it's a simple  
    209226// way to support the old page.item.php include module format. 
     227 
    210228ob_start(); 
    211229 
     
    214232  default: 
    215233    //display the appropriate module page 
    216     if (!isset($active_modules) || (isset($active_modules) && !is_array($active_modules))) { 
    217       break; 
    218     } 
    219      
    220     foreach ($active_modules as $modkey => $module) { 
    221       if (!isset($module['items']) || (isset($module['items']) && !is_array($module['items']))){ 
    222         continue; 
    223       } 
    224        
    225       foreach (array_keys($module['items']) as $item){ 
    226         if ($display != $item)  { 
    227           continue; 
    228         } 
    229          
    230         // set the active modules  
    231         $module_name = $modkey; 
    232         $module_page = $item; 
    233          
    234         // modules can use their own translation files 
    235         if (extension_loaded('gettext')) { 
    236           if(is_dir("./modules/{$modkey}/i18n")) { 
    237             bindtextdomain($modkey,"./modules/{$modkey}/i18n"); 
    238             bind_textdomain_codeset($modkey, 'utf8'); 
    239             textdomain($modkey); 
    240           } 
    241         } 
    242          
    243         //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 :-( 
    244         $possibilites = array( 
    245           'userdisplay', 
    246           'extdisplay', 
    247           'id', 
    248           'itemid', 
    249           'category', 
    250           'selection' 
    251         ); 
    252         $itemid = ''; 
    253         foreach($possibilites as $possibility) { 
    254           if ( isset($_REQUEST[$possibility]) && $_REQUEST[$possibility] != '' )  
    255             $itemid = $_REQUEST[$possibility]; 
    256         } 
    257  
    258         // create a module_hook object for this module's page 
    259         $module_hook = new moduleHook; 
    260          
    261         // populate object variables 
    262         $module_hook->install_hooks($itemid,$modkey,$item); 
    263  
    264         // let hooking modules process the $_REQUEST 
    265         $module_hook->process_hooks($itemid,$modkey,$item,$_REQUEST); 
    266          
    267         // include the module page 
    268         include "modules/{$modkey}/page.{$item}.php"; 
    269          
    270         // global component 
    271         if ( isset($currentcomponent) ) { 
    272           echo $currentcomponent->generateconfigpage(); 
    273         } 
    274  
    275       } 
    276     } 
     234    $module_name = $cur_menuitem['module']['rawname']; 
     235    $module_page = $cur_menuitem['display']; 
     236     
     237    $module_file = 'modules/'.$module_name.'/page.'.$module_page.'.php'; 
     238     
     239     
     240    //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 :-( 
     241    $possibilites = array( 
     242      'userdisplay', 
     243      'extdisplay', 
     244      'id', 
     245      'itemid', 
     246      'category', 
     247      'selection' 
     248    ); 
     249    $itemid = ''; 
     250    foreach($possibilites as $possibility) { 
     251      if ( isset($_REQUEST[$possibility]) && $_REQUEST[$possibility] != '' )  
     252        $itemid = $_REQUEST[$possibility]; 
     253    } 
     254 
     255    // create a module_hook object for this module's page 
     256    $module_hook = new moduleHook; 
     257     
     258    // populate object variables 
     259    $module_hook->install_hooks($itemid,$modkey,$item); 
     260 
     261    // let hooking modules process the $_REQUEST 
     262    $module_hook->process_hooks($itemid,$modkey,$item,$_REQUEST); 
     263     
     264     
     265     
     266    // include the module page 
     267    if (file_exists($module_file)) { 
     268      include($module_file); 
     269    } else { 
     270      echo "404 Not found"; 
     271    } 
     272     
     273    // global component 
     274    if ( isset($currentcomponent) ) { 
     275      echo $currentcomponent->generateconfigpage(); 
     276    } 
     277 
    277278  break; 
    278279  case 'modules': 
  • freepbx/branches/2.3/amp_conf/htdocs/admin/functions.inc.php

    r4430 r4446  
    26732673           
    26742674          // add optional values: 
    2675            
    2676           // custom href 
    2677           if (isset($parser->attributes[$path]['href'])) { 
    2678             $xmlarray['module']['items'][$item]['href'] = $parser->attributes[$path]['href']; 
    2679           } 
    2680            
    2681           // custom target 
    2682           if (isset($parser->attributes[$path]['target'])) { 
    2683             $xmlarray['module']['items'][$item]['target'] = $parser->attributes[$path]['target']; 
     2675          $optional_attribs = array( 
     2676          'href', // custom href 
     2677          'target', // custom target frame 
     2678            'display', // display= override 
     2679          ); 
     2680          foreach ($optional_attribs as $attrib) { 
     2681          if (isset($parser->attributes[$path][ $attrib ])) { 
     2682             $xmlarray['module']['items'][$item][ $attrib ] = $parser->attributes[$path][ $attrib ]; 
     2683            } 
    26842684          } 
    26852685           
  • freepbx/branches/2.3/amp_conf/htdocs/admin/views/freepbx_admin.php

    r4444 r4446  
    6565  $started_div = false; 
    6666  foreach ($fpbx_menu as $key => $row) { 
    67     // don't show the "index" item in the menu. 
    68     if ($key == "index") continue; 
    69      
    7067    if ($prev_type != $row['type']) { 
    7168      if ($started_div) { 
     
    8279    } 
    8380     
    84     $href = isset($row['href']) ? $row['href'] : "config.php?type=".$row['type']."&display=".$key
     81    $href = isset($row['href']) ? $row['href'] : "config.php?type=".$row['type']."&display=".$row['display']
    8582    $extra_attributes = ''; 
    8683    if (isset($row['target'])) { 
     
    8986     
    9087    echo "\t<li" . 
    91       (($display==$key) ? ' class="current"':'') . 
     88      (($display==$row['display']) ? ' class="current"':'') . 
    9289      '><a href="'.$href.'" '.$extra_attributes.' >'._($row['name'])."</a></li>\n"; 
    9390