Changeset 9823

Show
Ignore:
Timestamp:
06/13/10 11:47:05 (3 years ago)
Author:
p_lindheimer
Message:

revert back the 2.8 changes that were moved to do final pre 2.8 publish

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • contributed_modules/modules/customcontexts/functions.inc.php

    r9821 r9823  
    55function customcontexts_getmodulevalue($id) { 
    66global $db; 
    7  
    8 switch ($id) { 
    9   case 'moduledisplayname': 
    10     $module_info = module_getinfo('customcontexts'); 
    11     return($module_info['customcontexts']['name']); 
    12     break; 
    13  
    14   case 'moduleversion': 
    15     $module_info = module_getinfo('customcontexts'); 
    16     return($module_info['customcontexts']['version']); 
    17     break; 
    18  
    19   default: 
    20   $sql = "select value from customcontexts_module where id = '$id'"; 
    21   $results = $db->getAll($sql); 
    22   if(DB::IsError($results))  
    23     $results = null; 
    24   return isset($results)?$results[0][0]:null; 
    25   } 
     7  switch ($id) { 
     8    case 'moduledisplayname': 
     9      $module_info = module_getinfo('customcontexts'); 
     10      return($module_info['customcontexts']['name']); 
     11      break; 
     12    case 'moduleversion': 
     13      $module_info = module_getinfo('customcontexts'); 
     14      return($module_info['customcontexts']['version']); 
     15      break; 
     16    default: 
     17    $sql = "select value from customcontexts_module where id = '$id'"; 
     18    $results = $db->getAll($sql); 
     19    if(DB::IsError($results)) { 
     20      $results = null; 
     21    } 
     22    return isset($results)?$results[0][0]:null; 
     23  } 
    2624} 
    2725 
     
    3937  switch($engine) { 
    4038    case 'asterisk': 
    41       $sql = "update customcontexts_includes_list set missing = 1 where context not in (select context from customcontexts_contexts_list where locked = 1)"; 
     39      $sql = 'UPDATE customcontexts_includes_list SET missing = 1 WHERE context  
     40              NOT IN (SELECT context FROM customcontexts_contexts_list WHERE locked = 1)'; 
    4241      $db->query($sql); 
    43       $sql = "select context from customcontexts_contexts_list"
    44       $results = $db->getAll($sql); 
     42      $sql = 'SELECT context FROM customcontexts_contexts_list'
     43      $sections = $db->getAll($sql); 
    4544      if(DB::IsError($results)) { 
    4645        $results = null; 
    4746      } 
    48       foreach ($results as $val) { 
    49         $section = $val[0]; 
     47      foreach ($sections as $section) { 
     48        $section = $section[0]; 
     49        $i = 0; 
    5050        if (isset($ext->_includes[$section])) { 
    51                 $i = 0; 
    5251          foreach ($ext->_includes[$section] as $include) { 
     52            $i = $i + 1; 
    5353            if ($section == 'outbound-allroutes') { 
    54               $i = $i + 1; 
    55               $sql = "update customcontexts_includes_list  set missing = 0, sort = $i where context = '$section' and include = '$include'"; 
    56               $db->query($sql); 
    57 //fix prioritized contexts       , description = '$include' 
    58               $sql = "update customcontexts_includes_list  set include = '$include', description = '$include', missing = 0, sort = $i where missing = 1 and context = '$section' and substring(include,1,6) = 'outrt-' and substring(include,10) = substring('$include',10)"; 
    59               $db->query($sql); 
    60 //fix allowed prioritized contexts  (i did not do , sort = $i, maybe i should)    context = '$section' and 
    61               $sql = "update customcontexts_includes set include = '$include' where substr(include,1,6) = 'outrt-' and substr(include,10) = substr('$include',10)"; 
     54              $sql = 'INSERT INTO customcontexts_includes_list  
     55                      (context, include, description, missing, sort) 
     56                      VALUES ("'.$section.'", "'.$include['include'].'", 
     57                      "'.$include['comment'].'", "0", "'.$i.'")  
     58                      ON DUPLICATE KEY UPDATE sort = "'.$i.'", missing = "0"'; 
    6259              $db->query($sql); 
    6360            } else { 
    64               $sql = "update customcontexts_includes_list  set missing = 0, sort = $i where context = '$section' and include = '$include'"; 
     61              $sql = 'UPDATE customcontexts_includes_list SET missing = "0", sort = "'.$i.'"  
     62                      WHERE context = "'.$section.'" and include = "'.$include['include'].'"'; 
    6563              $db->query($sql); 
    66                         } 
    67             $sql = "INSERT IGNORE INTO customcontexts_includes_list (context, include, description, sort) VALUES ('$section', '$include', '$include', $i)"; 
     64            } 
     65            $sql = 'INSERT IGNORE INTO customcontexts_includes_list  
     66                    (context, include, description, sort)  
     67                    VALUES ("'.$section.'", "'.$include['include'].'",  
     68                    "'.$include['include'].'", "'.$i.'")'; 
    6869            $db->query($sql); 
    6970          } 
     
    8182    // only provide display for outbound routing 
    8283    case 'routing': 
    83 /* 
    84       $route = substr($viewing_itemid,4); 
    85       $hookhtml = ''; 
    86             return $hookhtml; 
    87 */ 
     84      /*$route = substr($viewing_itemid,4);$hookhtml = '';return $hookhtml;*/ 
    8885      return ''; 
    8986    break; 
     
    9491} 
    9592 
    96 //this is to catch any rename reorder or delete route, so i can fix custom contexts 
    97 function customcontexts_hookProcess_core($viewing_itemid, $request) { 
    98   switch ($request['display']) { 
    99         case 'routing': 
    100       if(isset($request['Submit'])) { 
    101 //        $route = substr($viewing_itemid,4); 
    102 //        $priority = (int)(substr($viewing_itemid,0,3)); 
    103       }  
    104       switch ($request['action']) { 
    105         case 'delroute': 
    106 //          $route = substr($viewing_itemid,4); 
    107           $priority = (int)(substr($viewing_itemid,0,3)); 
    108           customcontexts_routing_prioritize($request['action'],$priority); 
    109         break; 
    110         case 'prioritizeroute': 
    111           $fullroute = $viewing_itemid; 
    112           if (isset($request['reporoutekey'])) { 
    113                     $outbound_routes = core_routing_getroutenames(); 
    114             $fullroute = $outbound_routes[(int)$request['reporoutekey']][0]; 
    115                 } 
    116 //          $route = substr($fullroute,4); 
    117           $priority = (int)(substr($fullroute,0,3)); 
    118           $direction = $request['reporoutedirection']; 
    119           customcontexts_routing_prioritize($request['action'],$priority,$direction); 
    120         break; 
    121         case 'renameroute'; 
    122           $newname = $request['newroutename']; 
    123           $route = $viewing_itemid; 
    124           $priority = (substr($viewing_itemid,0,3)); 
    125                     $fullnewname = 'outrt-'.$priority.'-'.$newname; 
    126                     $fullroutename = 'outrt-'.$route; 
    127           customcontexts_routing_editname($fullroutename,$fullnewname); 
    128         break; 
    129         default: 
    130      
    131         break; 
    132       } 
    133     break; 
    134   } 
    135 } 
    136  
    13793function customcontexts_routing_editname($route,$newname) { 
    13894  global $db; 
    139 //fix renamed contexts       , description = '$include' 
     95 //fix renamed contexts, description = '$include' 
    14096  $sql = "update customcontexts_includes_list  set include = '$newname', description = '$newname', missing = 0 where context = 'outbound-allroutes' and include = '$route'"; 
    14197  $db->query($sql); 
    142 //fix allowed renamed contexts  (i did not do , sort = $i, maybe i should)   context = 'outbound-allroutes' and 
     98 //fix allowed renamed contexts  (i did not do , sort = $i, maybe i should)   context = 'outbound-allroutes' and 
    14399  $sql = "update customcontexts_includes set include = '$newname' where include = '$route'"; 
    144100  $db->query($sql); 
     
    146102 
    147103function customcontexts_routing_prioritize($action,$priority,$direction=null) { 
    148     global $db; 
     104  global $db; 
    149105  $outbound_routes = core_routing_getroutenames(); 
    150106  foreach ($outbound_routes as $route) { 
     
    162118        } 
    163119        if (isset($newroute)) { 
    164 //fix prioritized contexts    , description = '$newroute' 
     120         //fix prioritized contexts , description = '$newroute' 
    165121          $sql = "update customcontexts_includes_list  set include = '$newroute', description = '$newroute', missing = 0, sort = $newpriority where context = 'outbound-allroutes' and include= 'outrt-$routename'"; 
    166 //echo $sql; 
     122         //echo $sql; 
    167123          $db->query($sql); 
    168 //fix allowed prioritized contexts  (i did not do , sort = $i, maybe i should)    context = 'outbound-allroutes' and 
     124         //fix allowed prioritized contexts  (i did not do , sort = $i, maybe i should)    context = 'outbound-allroutes' and 
    169125          $sql = "update customcontexts_includes set include = '$newroute' where include = 'outrt-$routename'"; 
    170 //echo $sql; 
     126         //echo $sql; 
    171127          $db->query($sql); 
    172128        } 
     
    175131            case 'delroute'; 
    176132              if ($routepriority > $priority) { 
    177           $newpriority = str_pad($routepriority - 1, 3, "0", STR_PAD_LEFT); 
    178                     $newroute = 'outrt-'.$newpriority.'-'.substr($routename,4); 
    179 //fix prioritized contexts   , description = '$newroute' 
    180           $sql = "update customcontexts_includes_list  set include = '$newroute', description = '$newroute', missing = 0, sort = $newpriority where context = 'outbound-allroutes' and include= 'outrt-$routename'"; 
    181 //echo $sql; 
    182           $db->query($sql); 
    183 //fix allowed prioritized contexts  (i did not do , sort = $i, maybe i should)   context = 'outbound-allroutes' and 
    184           $sql = "update customcontexts_includes set include = '$newroute' where include = 'outrt-$routename'"; 
    185 //echo $sql; 
    186           $db->query($sql); 
    187        
    188         unset($newroute); 
    189             break; 
     133               $newpriority = str_pad($routepriority - 1, 3, "0", STR_PAD_LEFT); 
     134               $newroute = 'outrt-'.$newpriority.'-'.substr($routename,4); 
     135               //fix prioritized contexts   , description = '$newroute' 
     136               $sql = "update customcontexts_includes_list  set include = '$newroute', description = '$newroute', missing = 0, sort = $newpriority where context = 'outbound-allroutes' and include= 'outrt-$routename'"; 
     137               //echo $sql; 
     138               $db->query($sql); 
     139               //fix allowed prioritized contexts  (i did not do , sort = $i, maybe i should)   context = 'outbound-allroutes' and 
     140               $sql = "update customcontexts_includes set include = '$newroute' where include = 'outrt-$routename'"; 
     141               //echo $sql; 
     142               $db->query($sql); 
     143             
     144             unset($newroute); 
     145            break; 
    190146    }             
    191147  } 
     
    199155  global $db; 
    200156//  $sql = "select include, description from customcontexts_includes_list where context = '".$context."' order by description"; 
    201   $sql = "select include, customcontexts_includes_list.description, count(customcontexts_contexts_list.context) as preemptcount  from customcontexts_includes_list left outer join customcontexts_contexts_list on include = customcontexts_contexts_list.context where customcontexts_includes_list.context = '$context' group by include, customcontexts_includes_list.description order by customcontexts_includes_list.description"; 
     157  $sql = "SELECT include, customcontexts_includes_list.description,  
     158          COUNT(customcontexts_contexts_list.context) AS preemptcount   
     159          FROM customcontexts_includes_list  
     160          LEFT OUTER JOIN customcontexts_contexts_list  
     161          ON include = customcontexts_contexts_list.context  
     162          WHERE customcontexts_includes_list.context = '$context'  
     163          GROUP BY include, customcontexts_includes_list.description  
     164          ORDER BY customcontexts_includes_list.sort, 
     165          customcontexts_includes_list.description"; 
    202166  $results = $db->getAll($sql); 
    203   if(DB::IsError($results))  
     167  if(DB::IsError($results)) { 
    204168    $results = null; 
    205   foreach ($results as $val) 
     169  } 
     170  foreach ($results as $val) { 
    206171    $tmparray[] = array($val[0], $val[1], $val[2]); 
     172  } 
    207173  return $tmparray; 
    208174} 
     
    213179  $sql = "select context, description from customcontexts_contexts_list order by description"; 
    214180  $results = $db->getAll($sql); 
    215   if(DB::IsError($results))  
     181  if(DB::IsError($results)) { 
    216182    $results = null; 
    217   foreach ($results as $val) 
     183  } 
     184  foreach ($results as $val) { 
    218185    $tmparray[] = array($val[0], $val[1]); 
     186  } 
    219187  return $tmparray; 
    220188} 
     
    224192  global $db; 
    225193//  $sql = "select customcontexts_contexts_list.context, customcontexts_contexts_list.description as contextdescription, customcontexts_includes_list.include, customcontexts_includes_list.description, if(saved.include is null, 'no', if(saved.timegroupid is null, 'yes', saved.timegroupid)) as allow, saved.sort from customcontexts_contexts_list inner join customcontexts_includes_list on customcontexts_contexts_list.context = customcontexts_includes_list.context left outer join (select * from customcontexts_includes where context = '$context') saved on customcontexts_includes_list.include = saved.include order by customcontexts_contexts_list.description, customcontexts_includes_list.description"; 
    226   $sql = "select customcontexts_contexts_list.context, customcontexts_contexts_list.description as contextdescription, customcontexts_includes_list.include, customcontexts_includes_list.description, if(saved.include is null, 'no', if(saved.timegroupid is null, if(saved.userules is null, 'yes', saved.userules), saved.timegroupid)) as allow, if(saved.sort is null,customcontexts_includes_list.sort,saved.sort) as sort, count(preemptcheck.context) as preemptcount from customcontexts_contexts_list inner join customcontexts_includes_list on customcontexts_contexts_list.context = customcontexts_includes_list.context left outer join (select * from customcontexts_includes where context = '$context           ') saved on customcontexts_includes_list.include = saved.include left outer join customcontexts_contexts_list  preemptcheck on customcontexts_includes_list.include = preemptcheck.context group by customcontexts_contexts_list.context, customcontexts_contexts_list.description, customcontexts_includes_list.include, customcontexts_includes_list.description, if(saved.include is null, 'no', if(saved.timegroupid is null, 'yes', saved.timegroupid)), saved.sort order by customcontexts_contexts_list.description, if(saved.sort is null,101,saved.sort), customcontexts_includes_list.description;"; 
     194  $sql = "SELECT customcontexts_contexts_list.context,  
     195          customcontexts_contexts_list.description AS contextdescription,  
     196          customcontexts_includes_list.include,  
     197          customcontexts_includes_list.description,  
     198          IF(saved.include is null, 'no',  
     199            IF(saved.timegroupid is null, IF(saved.userules is null, 'yes', saved.userules), 
     200          saved.timegroupid)) AS allow,  
     201          IF(saved.sort is null,customcontexts_includes_list.sort,saved.sort) AS sort,  
     202          COUNT(preemptcheck.context) AS preemptcount FROM customcontexts_contexts_list  
     203          INNER JOIN customcontexts_includes_list  
     204          ON customcontexts_contexts_list.context = customcontexts_includes_list.context  
     205          LEFT OUTER JOIN (SELECT * from customcontexts_includes WHERE context = '$context')  AS saved  
     206          ON customcontexts_includes_list.include = saved.include  
     207          LEFT OUTER JOIN customcontexts_contexts_list preemptcheck  
     208          ON customcontexts_includes_list.include = preemptcheck.context  
     209          GROUP BY customcontexts_contexts_list.context,  
     210          customcontexts_contexts_list.description,  
     211          customcontexts_includes_list.include,  
     212          customcontexts_includes_list.description,  
     213          IF(saved.include is null, 'no',  
     214            IF(saved.timegroupid is null, 'yes', saved.timegroupid)),  
     215          saved.sort,   
     216          customcontexts_contexts_list.description 
     217          ORDER BY customcontexts_contexts_list.description,  
     218          IF(saved.sort is null,101,saved.sort),  
     219          customcontexts_includes_list.description"; 
    227220  $results = $db->getAll($sql); 
    228   if(DB::IsError($results))  
     221  if(DB::IsError($results)) { 
    229222    $results = null; 
    230   foreach ($results as $val) 
     223  } 
     224  foreach ($results as $val){ 
    231225    $tmparray[] = array($val[0], $val[1], $val[2], $val[3], $val[4], $val[5], $val[6]); 
    232 //    0-context      1-contextdescription      2-include     3-description     4-allow     5-sort 6-preemptcount 
     226  } 
     227  //0-context 1-contextdescription  2-include  3-description 4-allow 5-sort 6-preemptcount 
    233228  return $tmparray; 
    234229} 
     
    279274} 
    280275 
    281 //allow reload to get our config 
    282 //we add all user custom contexts ad include his selected includes 
    283 //also maybe allow the user to specify invalid destination 
     276/*  
     277 * allow reload to get our config 
     278 * we add all user custom contexts ad include his selected includes 
     279 * also maybe allow the user to specify invalid destination 
     280 */  
    284281function customcontexts_get_config($engine) { 
    285282  global $ext; 
     
    287284    case 'asterisk': 
    288285  global $db; 
    289   $sql = "select context, dialrules, faildestination, featurefaildestination, failpin, featurefailpin from customcontexts_contexts"; 
     286  $sql = "SELECT context, dialrules, faildestination, featurefaildestination,  
     287          failpin, featurefailpin FROM customcontexts_contexts"; 
    290288  $results = $db->getAll($sql); 
    291   if(DB::IsError($results))  
     289  if(DB::IsError($results)) {  
    292290    $results = null; 
     291  } 
    293292  foreach ($results as $val) { 
    294293    $context = $val[0]; 
    295 //   $ext->_exts[$context][] = null; 
    296 //partially stolen from outbound routing 
     294   //$ext->_exts[$context][] = null; 
     295   //partially stolen from outbound routing 
    297296    $dialpattern = explode("\n",$val[1]); 
    298297    if (!$dialpattern) { 
     
    304303       
    305304      // remove blanks 
    306       if ($dialpattern[$key] == "") unset($dialpattern[$key]); 
     305      if ($dialpattern[$key] == "") { 
     306        unset($dialpattern[$key]); 
     307      } 
    307308       
    308309      // remove leading underscores (we do that on backend) 
    309       if ($dialpattern[$key][0] == "_") $dialpattern[$key] = substr($dialpattern[$key],1); 
     310      if ($dialpattern[$key][0] == "_") { 
     311        $dialpattern[$key] = substr($dialpattern[$key],1); 
     312      } 
    310313    } 
    311314    // check for duplicates, and re-sequence 
     
    333336      } 
    334337    } 
    335 //switch to first line to deny all access when time group deleted 
    336 //    $sql = "select include, time from customcontexts_includes left outer join customcontexts_timegroups_detail on  customcontexts_includes.timegroupid = customcontexts_timegroups_detail.timegroupid where context = '".$context."' and (customcontexts_includes.timegroupid is null or customcontexts_timegroups_detail.timegroupid is not null) order by sort"; 
    337     $sql = "select include, time, userules from customcontexts_includes left outer join customcontexts_timegroups_detail on  customcontexts_includes.timegroupid = customcontexts_timegroups_detail.timegroupid where context = '".$context."' order by sort"; 
     338    //switch to first line to deny all access when time group deleted 
     339    //$sql = "select include, time from customcontexts_includes left outer join customcontexts_timegroups_detail on  customcontexts_includes.timegroupid = customcontexts_timegroups_detail.timegroupid where context = '".$context."' and (customcontexts_includes.timegroupid is null or customcontexts_timegroups_detail.timegroupid is not null) order by sort"; 
     340    $sql  = "SELECT include, time, userules, seq FROM customcontexts_includes  
     341            LEFT OUTER JOIN customcontexts_timegroups_detail  
     342            ON  customcontexts_includes.timegroupid = customcontexts_timegroups_detail.timegroupid  
     343            LEFT OUTER JOIN  outbound_route_sequence  
     344            ON REPLACE(include,'outrt-','') = outbound_route_sequence.route_id 
     345            WHERE context = '$context' ORDER BY sort, seq"; 
    338346    $results2 = $db->getAll($sql); 
    339     if(DB::IsError($results2))  
     347    if(DB::IsError($results2)) { 
    340348      $results2 = null; 
     349    } 
    341350    foreach ($results2 as $inc) { 
     351    dbug('$results2',$inc); 
    342352      $time = isset($inc[1])?'|'.$inc[1]:''; 
    343353      switch ($inc[2]) { 
     
    358368      } 
    359369    } 
    360 //these go in funny "exten => s,1,Macro(hangupcall,)" 
    361 //i'd rather use the base extension class to type it normally, but there is a bug in the class see ticket http://www.freepbx.org/trac/ticket/1453 
     370   //these go in funny "exten => s,1,Macro(hangupcall,)" 
     371   //i'd rather use the base extension class to type it normally, but there is a bug in the class see ticket http://www.freepbx.org/trac/ticket/1453 
    362372    $ext->add($context,'s', '', new ext_macro('hangupcall'));  
    363373    $ext->add($context,'h', '', new ext_macro('hangupcall')); 
     
    439449function customcontexts_devices_configpageload() { 
    440450global $currentcomponent; 
    441 //should get current context if possible 
     451 //should get current context if possible 
    442452  $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; 
    443453  $query="SELECT `data` FROM `sip` WHERE `keyword`='context' AND `id`='".$extdisplay."'"; 
     
    449459function customcontexts_extensions_configpageload() { 
    450460global $currentcomponent; 
    451 //should get current context if possible 
     461 //should get current context if possible 
    452462  $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; 
    453463  $query="SELECT `data` FROM `sip` WHERE `keyword`='context' AND `id`='".$extdisplay."'"; 
     
    456466} 
    457467 
    458 //admin page helper 
    459 //we are using gui styles so there is very little on the page 
    460 //the admin page is used to list _existing_ contexts for us to parse for includes 
    461 //these contexts/includes can be tagged with a description for the user to select on the custom contexts page 
     468/* 
     469 * admin page helper 
     470 * we are using gui styles so there is very little on the page 
     471 * the admin page is used to list _existing_ contexts for us to parse for includes 
     472 * these contexts/includes can be tagged with a description for the user to select on the custom contexts page 
     473 */  
    462474function customcontexts_customcontextsadmin_configpageinit($dispnum) { 
    463475global $currentcomponent; 
     
    479491  if ($action == 'del') { 
    480492    $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Context").": $extdisplay"." deleted!", false), 0); 
    481   } 
    482   else 
    483   { 
    484 //need to get module name/type dynamically 
     493  } else { 
     494    //need to get module name/type dynamically 
    485495    $query = ($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:'type=tool&display=customcontextsadmin&extdisplay='.$extdisplay; 
    486496    $delURL = $_SERVER['PHP_SELF'].'?'.$query.'&action=del'; 
    487497    $info = 'The context which contains includes which you would like to make available to '.customcontexts_getmodulevalue('moduledisplayname').'. Any context you enter here will be parsed for includes and you can then include them in your own '.customcontexts_getmodulevalue('moduledisplayname').'. Removing them here does NOT delete the context, rather makes them unavailable to your '.customcontexts_getmodulevalue('moduledisplayname').'.'; 
    488          $currentcomponent->addguielem('_top', new gui_hidden('action', ($extdisplay ? 'edit' : 'add'))); 
     498    $currentcomponent->addguielem('_top', new gui_hidden('action', ($extdisplay ? 'edit' : 'add'))); 
    489499    $currentcomponent->addguielem('_bottom', new gui_link('help', _(customcontexts_getmodulevalue('moduledisplayname')." v".customcontexts_getmodulevalue('moduleversion')), 'http://www.freepbx.org/support/documentation/module-documentation/third-party-unsupported-modules/customcontexts', true, false), 0); 
     500    $currentcomponent->addguielem('_bottom', new gui_link('bounty', 'Module Going END OF LIFE - Click For Details', 'http://www.freepbx.org/bounties/custom-context', true, false), 0); 
    490501    if (!$extdisplay) { 
    491502      $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Context"), false), 0); 
    492503      $currentcomponent->addguielem('Context', new gui_textbox('extdisplay', '', 'Context', $info, 'isWhitespace() || !isFilename()', $contexterr, false), 3); 
    493504      $currentcomponent->addguielem('Context', new gui_textbox('description', '', 'Description', 'This will display as a heading for the available includes on the '.customcontexts_getmodulevalue('moduledisplayname').' page.', '!isAlphanumeric() || isWhitespace()', $descerr, false), 3); 
    494     } 
    495     else 
    496     { 
     505    } else { 
    497506      $savedcontext = customcontexts_customcontextsadmin_get($extdisplay); 
    498507      $context = $savedcontext[0]; 
     
    512521      foreach ($inclist as $val) { 
    513522        if ($val[2] > 0) { 
    514 //$gui1 = new gui_textbox('includes['.$val[0].']', $val[1], '<font color="red"><strong>'.$val[0].'</strong></font>', 'This will display as the name of the include on the '.customcontexts_getmodulevalue('moduledisplayname').' page.<BR><font color="red"><strong>NOTE: This include should have a description denoting the fact that allowing it may allow another ENTIRE context!</strong></font>', '!isAlphanumeric() || isWhitespace()', $descerr, false); 
    515 //$inchtml = $gui1->generatehtml(); 
    516 //$inchtml = '<tr><td colspan="2"><table><tr><td colspan="2">'.$inchtml.'</td></tr></table></td></tr>'.$inchtml; 
    517 //$currentcomponent->addguielem('Includes Descriptions', new guielement('$val[0]',$inchtml,''),3); 
    518523          $currentcomponent->addguielem('Includes Descriptions', new gui_textbox('includes['.$val[0].']', $val[1], '<font color="red"><strong>'.$val[0].'</strong></font>', 'This will display as the name of the include on the '.customcontexts_getmodulevalue('moduledisplayname').' page.<BR><font color="red"><strong>NOTE: This include should have a description denoting the fact that allowing it may allow another ENTIRE context!</strong></font>', '!isAlphanumeric() || isWhitespace()', $descerr, false), 3); 
    519524        } else { 
     
    601606//--------------------------------------------- 
    602607 
    603 //custom contexts page helper 
    604 //we are using gui styles so there is very little on the page 
    605 //the custom contexts page is used to create _new_ contexts for use in the dialplan 
    606 //these contexts can include any includes which were made available from admin 
     608/* custom contexts page helper 
     609 * we are using gui styles so there is very little on the page 
     610 * the custom contexts page is used to create _new_ contexts for use in the dialplan 
     611 * these contexts can include any includes which were made available from admin 
     612 */  
    607613function customcontexts_customcontexts_configpageinit($dispnum) { 
    608614global $currentcomponent; 
     
    640646  if ($action == 'del') { 
    641647    $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Context").": $extdisplay"." deleted!", false), 0); 
    642   } 
    643   else 
    644   { 
    645 //need to get page name/type dynamically 
    646 //caused trouble on dup or del after dup or rename 
    647 //    $query = ($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:'type=setup&display=customcontexts&extdisplay='.$extdisplay; 
     648  } else { 
     649    //need to get page name/type dynamically 
     650    //caused trouble on dup or del after dup or rename 
     651    //$query = ($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:'type=setup&display=customcontexts&extdisplay='.$extdisplay; 
    648652    $query = 'type=setup&display=customcontexts&extdisplay='.$extdisplay; 
    649653    $delURL = $_SERVER['PHP_SELF'].'?'.$query.'&action=del'; 
     
    651655    $info = 'The custom context to make will be available in your dialplan. These contexts can be used as a context for a device/extension to allow them limited access to your dialplan.'; 
    652656    $currentcomponent->addguielem('_bottom', new gui_link('ver', _(customcontexts_getmodulevalue('moduledisplayname')." v".customcontexts_getmodulevalue('moduleversion')), 'http://www.freepbx.org/support/documentation/module-documentation/third-party-unsupported-modules/customcontexts', true, false), 0); 
     657    $currentcomponent->addguielem('_bottom', new gui_link('bounty', 'Module Going END OF LIFE - Click For Details', 'http://www.freepbx.org/bounties/custom-context', true, false), 0); 
    653658    if (!$extdisplay) { 
    654659      $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Context"), false), 0); 
    655660      $currentcomponent->addguielem('Context', new gui_textbox('extdisplay', '', 'Context', $info, 'isWhitespace() || !isFilename()', $contexterr, false), 3); 
    656661      $currentcomponent->addguielem('Context', new gui_textbox('description', '', 'Description', 'This will display as the name of this custom context.', '!isAlphanumeric() || isWhitespace()', $descerr, false), 3); 
    657     } 
    658     else 
    659     { 
     662    } else { 
    660663      $savedcontext = customcontexts_customcontexts_get($extdisplay); 
    661664      $context = $savedcontext[0]; 
     
    668671      $currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay)); 
    669672      $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Edit Context").": $description", false), 0); 
    670 //     $currentcomponent->addguielem('_top', new gui_link('del', _("Delete Context")." $context", $delURL, true, false), 0); 
     673     //$currentcomponent->addguielem('_top', new gui_link('del', _("Delete Context")." $context", $delURL, true, false), 0); 
    671674      $currentcomponent->addguielem('_top', new guielement('del', '<tr><td colspan ="2"><a href="'.$delURL.'" onclick="return confirm(\'Are you sure you want to delete '.$context.'?\')">Delete Context '.$context.'</a></td></tr>', ''),3); 
    672675      $currentcomponent->addguielem('_top', new gui_link('dup', _("Duplicate Context")." $context", $dupURL, true, false), 3); 
    673676      $showsort = customcontexts_getmodulevalue('displaysortforincludes'); 
    674677      if ($showsort == 1) { 
    675 //       $sortURL = $_SERVER['PHP_SELF'].'?'.$query.'&showsort=0'; 
    676 //       $currentcomponent->addguielem('_top', new gui_link('showsort', "Hide Sort Option", $sortURL, true, false), 0); 
     678     //$sortURL = $_SERVER['PHP_SELF'].'?'.$query.'&showsort=0'; 
     679     //$currentcomponent->addguielem('_top', new gui_link('showsort', "Hide Sort Option", $sortURL, true, false), 0); 
    677680      } else { 
    678681        $sortURL = $_SERVER['PHP_SELF'].'?'.$query.'&showsort=1'; 
     
    684687      $ruleshtml = '<tr><td valign="top"><a href="#" class="info">Dial Rules<span>'.$ruledesc.'</span></a></td><td><textarea cols="20" rows="5" id="dialpattern" name="dialpattern">'.$rulestext.'</textarea></td></tr>'; 
    685688      $currentcomponent->addguielem('Context', new guielement('rulesbox',$ruleshtml,''), 3); 
    686 //      !isDialpattern 
     689 
    687690      $currentcomponent->addguielem('Failover Destination', new gui_textbox('failpin', $failpin, 'PIN', 'Enter a numeric PIN to require authentication before continuing to destination.', '!isPINList()', 'PIN must be numeric!', true), 4); 
    688       $selhtml = drawselects($faildest ,0); 
    689       $currentcomponent->addguielem('Failover Destination', new guielement('dest0', $selhtml, ''),4); 
    690691      $currentcomponent->addguielem('Feature Code Failover Destination', new gui_textbox('featurefailpin', $featurefailpin, 'PIN', 'Enter a numeric PIN to require authentication before continuing to destination.', '!isPINList()', 'PIN must be numeric!', true), 4); 
    691       $selhtml = drawselects($featurefaildest ,1); 
    692       $currentcomponent->addguielem('Feature Code Failover Destination', new guielement('dest1', $selhtml, ''),4); 
     692      $currentcomponent->addguielem('Failover Destination', new gui_drawselects('dest0', 0, $faildest, 'Failover Destination')); 
     693      $currentcomponent->addguielem('Feature Code Failover Destination', new gui_drawselects('dest1', 1, $featurefaildest, 'Failover Destination')); 
    693694      $currentcomponent->addguielem('Set All', new gui_selectbox('setall', $currentcomponent->getoptlist('includeyn'), '', 'Set All To:', 'Choose allow to allow access to all includes, choose deny to deny access.',true,'javascript:for (i=0;i<document.forms[\'frm_customcontexts\'].length;i++) {if(document.forms[\'frm_customcontexts\'][i].type==\'select-one\' && document.forms[\'frm_customcontexts\'][i].name.indexOf(\'[allow]\') >= 0 ) {document.forms[\'frm_customcontexts\'][i].selectedIndex = document.forms[\'frm_customcontexts\'][\'setall\'].selectedIndex-1;}}'),2); 
    694695      $inclist = customcontexts_getincludes($extdisplay); 
    695696      foreach ($inclist as $val) { 
    696697        if ($showsort == 1) { 
    697 //$gui1 = new gui_textbox('includes['.$val[0].']', $val[1], '<font color="red"><strong>'.$val[0].'</strong></font>', 'This will display as the name of the include on the '.customcontexts_getmodulevalue('moduledisplayname').' page.<BR><font color="red"><strong>NOTE: This include should have a description denoting the fact that allowing it may allow another ENTIRE context!</strong></font>', '!isAlphanumeric() || isWhitespace()', $descerr, false); 
    698 //$inchtml = $gui1->generatehtml(); 
    699 //$inchtml = '<tr><td colspan="2"><table><tr><td colspan="2">'.$inchtml.'</td></tr></table></td></tr>'.$inchtml; 
    700 //$currentcomponent->addguielem('Includes Descriptions', new guielement('$val[0]',$inchtml,''),3); 
    701698          if ($val[6] > 0) { 
    702 //            $currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][allow]', $currentcomponent->getoptlist('includeyn'), $val[4], '<font color="red"><strong>'.$val[3].'</strong></font>', $val[2].': Choose allow to allow access to this include, choose deny to deny access.<BR><font color="red"><strong>NOTE: Allowing this include may automatically allow another ENTIRE context!</strong></font>',false)); 
    703             $gui1 = new gui_selectbox('includes['.$val[2].'][allow]', $currentcomponent->getoptlist('includeyn'), $val[4], '<font color="red"><strong>'.$val[3].'</strong></font>', $val[2].': Choose allow to allow access to this include, choose deny to deny access.<BR><font color="red"><strong>NOTE: Allowing this include may automatically allow another ENTIRE context!</strong></font>',false); 
     699            //$currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][allow]', $currentcomponent->getoptlist('includeyn'), $val[4], '<font color="red"><strong>'.$val[3].'</strong></font>', $val[2].': Choose allow to allow access to this include, choose deny to deny access.<BR><font color="red"><strong>NOTE: Allowing this include may automatically allow another ENTIRE context!</strong></font>',false)); 
     700            $gui1 = new gui_selectbox('includes['.$val[2].'][allow]',  
     701                        $currentcomponent->getoptlist('includeyn'), $val[4],  
     702                        '<font color="red"><strong>'.$val[3].'</strong></font>',  
     703                        $val[2].': Choose allow to allow access to this include, choose deny to deny access.<BR><font color="red"><strong>NOTE: Allowing this include may automatically allow another ENTIRE context!</strong></font>',false); 
    704704          } else { 
    705 //            $currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][allow]', $currentcomponent->getoptlist('includeyn'), $val[4], $val[3], $val[2].': Choose allow to allow access to this include, choose deny to deny access.',false)); 
    706             $gui1 = new gui_selectbox('includes['.$val[2].'][allow]', $currentcomponent->getoptlist('includeyn'), $val[4], $val[3], $val[2].': Choose allow to allow access to this include, choose deny to deny access.',false); 
     705            //$currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][allow]', $currentcomponent->getoptlist('includeyn'), $val[4], $val[3], $val[2].': Choose allow to allow access to this include, choose deny to deny access.',false)); 
     706            $gui1 = new gui_selectbox('includes['.$val[2].'][allow]',  
     707                    $currentcomponent->getoptlist('includeyn'), $val[4], $val[3],  
     708                    $val[2].': Choose allow to allow access to this include, choose deny to deny access.',false); 
    707709          } 
    708 //         $currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][sort]', $currentcomponent->getoptlist('includesort'), $val[5], '<div align="right">Priority</div>', 'Choose a priority with which to sort this option. Lower numbers have a higher priority.',false)); 
     710         //$currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][sort]', $currentcomponent->getoptlist('includesort'), $val[5], '<div align="right">Priority</div>', 'Choose a priority with which to sort this option. Lower numbers have a higher priority.',false)); 
    709711          $guisort = new gui_selectbox('includes['.$val[2].'][sort]', $currentcomponent->getoptlist('includesort'), $val[5], '<div align="right">Priority</div>', 'Choose a priority with which to sort this option. Lower numbers have a higher priority.',false); 
    710712          $inchtml = '<tr><td colspan="2"><table width="100%"><tr><td></td><td width="50"></td></tr>'.$gui1->generatehtml().'</table></td><td><table>'.$guisort->generatehtml().'</table></td></tr>'; 
     
    712714        } else { 
    713715          if ($val[6] > 0) { 
    714             $currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][allow]', $currentcomponent->getoptlist('includeyn'), $val[4], '<font color="red"><strong>'.$val[3].'</strong></font>', $val[2].': Choose allow to allow access to this include, choose deny to deny access.<BR><font color="red"><strong>NOTE: Allowing this include may automatically allow another ENTIRE context!</strong></font>',false)); 
     716            $currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][allow]',  
     717                              $currentcomponent->getoptlist('includeyn'), $val[4],  
     718                              '<font color="red"><strong>'.$val[3].'</strong></font>', $val[2].': Choose allow to allow access to this include, choose deny to deny access.<BR><font color="red"><strong>NOTE: Allowing this include may automatically allow another ENTIRE context!</strong></font>',false)); 
    715719          } else { 
    716             $currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][allow]', $currentcomponent->getoptlist('includeyn'), $val[4], $val[3], $val[2].': Choose allow to allow access to this include, choose deny to deny access.',false)); 
     720            $currentcomponent->addguielem($val[1], new gui_selectbox('includes['.$val[2].'][allow]',  
     721                              $currentcomponent->getoptlist('includeyn'), $val[4],  
     722                              $val[3], $val[2].': Choose allow to allow access to this include, choose deny to deny access.',false)); 
    717723          } 
    718724        } 
     
    874880//--------------------------------------------- 
    875881 
    876 //custom contexts timegroups page helper 
    877 //we are using gui styles so there is very little on the page 
    878 //the custom contexts timegroups page is used to create time conditions  
    879 //to allow the user to limit when to include each context on the custom contexts page 
     882/*custom contexts timegroups page helper 
     883 * we are using gui styles so there is very little on the page 
     884 * the custom contexts timegroups page is used to create time conditions  
     885 * to allow the user to limit when to include each context on the custom contexts page 
     886 */  
    880887function customcontexts_customcontextstimes_configpageinit($dispnum) { 
    881888global $currentcomponent; 
     
    896903  if ($action == 'del') { 
    897904    $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Time Group").": $extdisplay"." deleted!", false), 0); 
    898   } 
    899   else 
    900   { 
    901 //need to get page name/type dynamically 
     905  } else { 
     906    //need to get page name/type dynamically 
    902907    $query = ($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:'type=setup&display=customcontextstimes&extdisplay='.$extdisplay; 
    903908    $delURL = $_SERVER['PHP_SELF'].'?'.$query.'&action=del'; 
    904909    $info = ''; 
    905910    $currentcomponent->addguielem('_bottom', new gui_link('ver', _(customcontexts_getmodulevalue('moduledisplayname')." v".customcontexts_getmodulevalue('moduleversion')), 'http://www.freepbx.org/support/documentation/module-documentation/third-party-unsupported-modules/customcontexts', true, false), 0); 
     911    $currentcomponent->addguielem('_bottom', new gui_link('bounty', 'Module Going END OF LIFE - Click For Details', 'http://www.freepbx.org/bounties/custom-context', true, false), 0); 
    906912    if (!$extdisplay) { 
    907913      $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Add Time Group"), false), 0); 
    908914      $currentcomponent->addguielem('Time Group', new gui_textbox('description', '', 'Description', 'This will display as the name of this Time Group.', '!isAlphanumeric() || isWhitespace()', $descerr, false), 3); 
    909     } 
    910     else 
    911     { 
     915    } else{ 
    912916      $savedtimegroup= customcontexts_customcontextstimes_get($extdisplay); 
    913917      $timegroup = $savedtimegroup[0]; 
     
    916920      $currentcomponent->addguielem('_top', new gui_pageheading('title', _("Edit Time Group").": $description", false), 0); 
    917921      $currentcomponent->addguielem('_top', new gui_link('del', _("Delete Time Group")." $timegroup", $delURL, true, false), 0); 
    918 //     $currentcomponent->addguielem('_top', new gui_subheading('subtitle', "Time Group", false), 0); 
     922     //$currentcomponent->addguielem('_top', new gui_subheading('subtitle', "Time Group", false), 0); 
    919923      $currentcomponent->addguielem('Time Group', new gui_textbox('description', $description, 'Description', 'This will display as the name of this Time Group.', '', '', false), 3); 
    920924      $timelist = customcontexts_gettimes($extdisplay); 
    921925      foreach ($timelist as $val) { 
    922 //add gui here 
    923       $timehtml = drawtimeselects('times['.$val[0].']',$val[1]); 
    924       $timehtml = '<tr><td colspan="2"><table>'.$timehtml.'</table></td></tr>'; 
    925       $currentcomponent->addguielem($val[1], new guielement('dest0', $timehtml, ''),5); 
     926       //add gui here 
     927      $timehtml = drawtimeselects('times['.$val[0].']',$val[1]); 
     928      $timehtml = '<tr><td colspan="2"><table>'.$timehtml.'</table></td></tr>'; 
     929      $currentcomponent->addguielem($val[1], new guielement('dest0', $timehtml, ''),5); 
    926930      } 
    927931    $timehtml = drawtimeselects('times[new]',null); 
     
    938942  $timegroup= isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null; 
    939943  $description= isset($_REQUEST['description'])?$_REQUEST['description']:null; 
    940 //addslashes   
     944 //addslashes  
    941945  switch ($action) { 
    942946  case 'add': 
     
    13441348 
    13451349function customcontexts_customcontextstimes_buildtime( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish) { 
    1346  
    1347         //----- Time Hour Interval proccess ---- 
    1348         if ($minute_start == '-') { 
    1349             $time_minute_start = "00"; 
    1350          } else { 
    1351             $time_minute_start = sprintf("%02d",$minute_start); 
    1352          } 
    1353          if ($minute_finish == '-') { 
    1354             $time_minute_finish = "00"; 
    1355          } else { 
    1356              $time_minute_finish = sprintf("%02d",$minute_finish); 
    1357          } 
    1358          if ($hour_start == '-') { 
    1359              $time_hour_start = '*'; 
    1360           } else { 
    1361              $time_hour_start = sprintf("%02d",$hour_start) . ':' . $time_minute_start; 
    1362           } 
    1363           if ($hour_finish == '-') { 
    1364              $time_hour_finish = '*'; 
    1365           } else { 
    1366              $time_hour_finish = sprintf("%02d",$hour_finish) . ':' . $time_minute_finish; 
    1367           } 
    1368           if ($time_hour_start === '*') {$time_hour_start = $time_hour_finish;} 
    1369           if ($time_hour_finish === '*') {$time_hour_finish = $time_hour_start;} 
    1370           if ($time_hour_start == $time_hour_finish) { 
    1371               $time_hour = $time_hour_start; 
    1372           } else { 
    1373               $time_hour = $time_hour_start . '-' . $time_hour_finish; 
    1374           } 
    1375           //----- Time Week Day Interval proccess ----- 
    1376           if ($wday_start == '-') { 
    1377               $time_wday_start = '*'; 
    1378            } else { 
    1379               $time_wday_start = $wday_start; 
    1380            } 
    1381            if ($wday_finish == '-') { 
    1382               $time_wday_finish = '*'; 
    1383            } else { 
    1384               $time_wday_finish = $wday_finish; 
    1385            } 
    1386            if ($time_wday_start === '*') {$time_wday_start = $time_wday_finish;} 
    1387            if ($time_wday_finish === '*') {$time_wday_finish = $time_wday_start;} 
    1388            if ($time_wday_start == $time_wday_finish) { 
    1389                $time_wday = $time_wday_start; 
    1390             } else { 
    1391                $time_wday = $time_wday_start . '-' . $time_wday_finish; 
    1392             } 
    1393             //----- Time Month Day Interval proccess ----- 
    1394             if ($mday_start == '-') { 
    1395                $time_mday_start = '*'; 
    1396             } else { 
    1397                 $time_mday_start = $mday_start; 
    1398             } 
    1399             if ($mday_finish == '-') { 
    1400                 $time_mday_finish = '*'; 
    1401             } else { 
    1402                 $time_mday_finish = $mday_finish; 
    1403             } 
    1404             if ($time_mday_start === '*') {$time_mday_start = $time_mday_finish;} 
    1405             if ($time_mday_finish === '*') {$time_mday_finish = $time_mday_start;} 
    1406             if ($time_mday_start == $time_mday_finish) { 
    1407                 $time_mday = $time_mday_start; 
    1408             } else { 
    1409                 $time_mday = $time_mday_start . '-' . $time_mday_finish; 
    1410             } 
    1411             //----- Time Month Interval proccess ----- 
    1412             if ($month_start == '-') { 
    1413                 $time_month_start = '*'; 
    1414             } else { 
    1415                 $time_month_start = $month_start; 
    1416             } 
    1417             if ($month_finish == '-') { 
    1418                 $time_month_finish = '*'; 
    1419             } else { 
    1420                 $time_month_finish = $month_finish; 
    1421             } 
    1422             if ($time_month_start === '*') {$time_month_start = $time_month_finish;} 
    1423             if ($time_month_finish === '*') {$time_month_finish = $time_month_start;} 
    1424             if ($time_month_start == $time_month_finish) { 
    1425                 $time_month = $time_month_start; 
    1426             } else { 
    1427                 $time_month = $time_month_start . '-' . $time_month_finish; 
    1428             } 
    1429       $time = $time_hour . '|' . $time_wday . '|' . $time_mday . '|' . $time_month; 
    1430       return $time; 
    1431 
    1432  
    1433  
     1350  //----- Time Hour Interval proccess ---- 
     1351  if ($minute_start == '-') { 
     1352      $time_minute_start = "00"; 
     1353   } else { 
     1354      $time_minute_start = sprintf("%02d",$minute_start); 
     1355   } 
     1356   if ($minute_finish == '-') { 
     1357      $time_minute_finish = "00"; 
     1358   } else { 
     1359       $time_minute_finish = sprintf("%02d",$minute_finish); 
     1360   } 
     1361   if ($hour_start == '-') { 
     1362       $time_hour_start = '*'; 
     1363    } else { 
     1364       $time_hour_start = sprintf("%02d",$hour_start) . ':' . $time_minute_start; 
     1365    } 
     1366    if ($hour_finish == '-') { 
     1367       $time_hour_finish = '*'; 
     1368    } else { 
     1369       $time_hour_finish = sprintf("%02d",$hour_finish) . ':' . $time_minute_finish; 
     1370    } 
     1371    if ($time_hour_start === '*') {$time_hour_start = $time_hour_finish;} 
     1372    if ($time_hour_finish === '*') {$time_hour_finish = $time_hour_start;} 
     1373    if ($time_hour_start == $time_hour_finish) { 
     1374        $time_hour = $time_hour_start; 
     1375    } else { 
     1376        $time_hour = $time_hour_start . '-' . $time_hour_finish; 
     1377    } 
     1378    //----- Time Week Day Interval proccess ----- 
     1379    if ($wday_start == '-') { 
     1380        $time_wday_start = '*'; 
     1381     } else { 
     1382        $time_wday_start = $wday_start; 
     1383     } 
     1384     if ($wday_finish == '-') { 
     1385        $time_wday_finish = '*'; 
     1386     } else { 
     1387        $time_wday_finish = $wday_finish; 
     1388     } 
     1389     if ($time_wday_start === '*') {$time_wday_start = $time_wday_finish;} 
     1390     if ($time_wday_finish === '*') {$time_wday_finish = $time_wday_start;} 
     1391     if ($time_wday_start == $time_wday_finish) { 
     1392         $time_wday = $time_wday_start; 
     1393      } else { 
     1394         $time_wday = $time_wday_start . '-' . $time_wday_finish; 
     1395      } 
     1396      //----- Time Month Day Interval proccess ----- 
     1397      if ($mday_start == '-') { 
     1398         $time_mday_start = '*'; 
     1399      } else { 
     1400          $time_mday_start = $mday_start; 
     1401      } 
     1402      if ($mday_finish == '-') { 
     1403          $time_mday_finish = '*'; 
     1404      } else { 
     1405          $time_mday_finish = $mday_finish; 
     1406      } 
     1407      if ($time_mday_start === '*') {$time_mday_start = $time_mday_finish;} 
     1408      if ($time_mday_finish === '*') {$time_mday_finish = $time_mday_start;} 
     1409      if ($time_mday_start == $time_mday_finish) { 
     1410          $time_mday = $time_mday_start; 
     1411      } else { 
     1412          $time_mday = $time_mday_start . '-' . $time_mday_finish; 
     1413      } 
     1414      //----- Time Month Interval proccess ----- 
     1415      if ($month_start == '-') { 
     1416          $time_month_start = '*'; 
     1417      } else { 
     1418          $time_month_start = $month_start; 
     1419      } 
     1420      if ($month_finish == '-') { 
     1421          $time_month_finish = '*'; 
     1422      } else { 
     1423          $time_month_finish = $month_finish; 
     1424      } 
     1425      if ($time_month_start === '*') {$time_month_start = $time_month_finish;} 
     1426      if ($time_month_finish === '*') {$time_month_finish = $time_month_start;} 
     1427      if ($time_month_start == $time_month_finish) { 
     1428          $time_month = $time_month_start; 
     1429      } else { 
     1430          $time_month = $time_month_start . '-' . $time_month_finish; 
     1431      } 
     1432$time = $time_hour . '|' . $time_wday . '|' . $time_mday . '|' . $time_month; 
     1433return $time; 
     1434
    14341435 
    14351436//---------------------------end stolen from timeconditions------------------------------------- 
  • contributed_modules/modules/customcontexts/install.php

    r9821 r9823  
    1616--> 
    1717<?php 
     18 
     19global $db; 
     20global $amp_conf; 
     21 
     22if (! function_exists("out")) { 
     23  function out($text) { 
     24    echo $text."<br />"; 
     25  } 
     26} 
     27 
     28if (! function_exists("outn")) { 
     29  function outn($text) { 
     30    echo $text; 
     31  } 
     32} 
     33 
     34 
     35$sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_contexts` ( 
     36        `context` varchar(100) NOT NULL default '', 
     37        `description` varchar(100) NOT NULL default '', 
     38        PRIMARY KEY  (`context`), 
     39        UNIQUE KEY `description` (`description`) 
     40      )"; 
     41 
     42 
     43$sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_contexts_list` ( 
     44        `context` varchar(100) NOT NULL default '', 
     45        `description` varchar(100) NOT NULL default '', 
     46        `locked` tinyint(1) NOT NULL default '0', 
     47        PRIMARY KEY  (`context`), 
     48        UNIQUE KEY `description` (`description`) 
     49        )"; 
     50 
     51$sql[] ="INSERT IGNORE INTO `customcontexts_contexts_list`  
     52        (`context`, `description`, `locked`)  
     53        VALUES ('from-internal', 'Default Internal Context', 1), 
     54        ('from-internal-additional', 'Internal Dialplan', 0),('outbound-allroutes', 'Outbound Routes', 0)"; 
     55 
     56$sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_includes` ( 
     57  `context` varchar(100) NOT NULL default '', 
     58  `include` varchar(100) NOT NULL default '', 
     59  `timegroupid` int(11) default NULL, 
     60  `sort` int(11) NOT NULL default '0', 
     61  PRIMARY KEY  (`context`,`include`), 
     62  KEY `sort` (`sort`) 
     63)"; 
     64 
     65$sql[] ="ALTER IGNORE TABLE `customcontexts_includes` ADD `timegroupid` INT NULL AFTER `include`"; 
     66 
     67$sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_includes_list` ( 
     68  `context` varchar(100) NOT NULL default '', 
     69  `include` varchar(100) NOT NULL default '', 
     70  `description` varchar(100) NOT NULL default '', 
     71  PRIMARY KEY  (`context`,`include`) 
     72)"; 
     73 
     74$sql[] ="ALTER IGNORE TABLE `customcontexts_includes_list` ADD `missing` BOOL NOT NULL DEFAULT '0'"; 
     75 
     76 
     77$sql[] ="INSERT IGNORE INTO `customcontexts_includes_list` (`context`, `include`, `description`) VALUES ('from-internal', 'parkedcalls', 'Call Parking'), 
     78('from-internal', 'from-internal-custom', 'Custom Internal Dialplan'), 
     79('from-internal', 'ext-fax', 'Fax')"; 
     80 
     81$sql[] ="INSERT IGNORE INTO `customcontexts_includes_list` (`context`, `include`, `description`) VALUES ('from-internal-additional', 'outbound-allroutes', 'ALL OUTBOUND ROUTES'), 
     82('from-internal', 'from-internal-additional', 'ENTIRE Basic Internal Dialplan')"; 
     83 
     84$sql[] ="UPDATE `customcontexts_includes_list` SET `description` = 'ALL OUTBOUND ROUTES' WHERE  `context` = 'from-internal-additional' AND `include` = 'outbound-allroutes'"; 
     85 
     86$sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_module` ( 
     87  `id` varchar(50) NOT NULL default '', 
     88  `value` varchar(100) NOT NULL default '', 
     89  PRIMARY KEY  (`id`) 
     90)"; 
     91 
     92$sql[] ="INSERT IGNORE INTO `customcontexts_module` (`id`, `value`) VALUES ('modulerawname', 'customcontexts'), 
     93        ('moduledisplayname', 'Custom Contexts'), 
     94        ('moduleversion', '0.3.2'), 
     95        ('displaysortforincludes', 1)"; 
     96 
     97$sql[] ="UPDATE `customcontexts_module` set `value` = '0.3.2' where `id` = 'moduleversion';"; 
     98 
     99$sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_timegroups` ( 
     100  `id` int(11) NOT NULL auto_increment, 
     101  `description` varchar(50) NOT NULL default '', 
     102  PRIMARY KEY  (`id`), 
     103  UNIQUE KEY `display` (`description`) 
     104) AUTO_INCREMENT=4 "; 
     105 
     106$sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_timegroups_detail` ( 
     107  `id` int(11) NOT NULL auto_increment, 
     108  `timegroupid` int(11) NOT NULL default '0', 
     109  `time` varchar(100) NOT NULL default '', 
     110  PRIMARY KEY  (`id`) 
     111) AUTO_INCREMENT=20"; 
     112 
     113foreach ($sql as $q){ 
     114  $db->query($sql); 
     115} 
     116 
    18117customcontexts_updatedb(); 
    19118 
     
    38137  $db->query($sql); 
    39138} 
     139 
     140outn(_("checking if migration required...")); 
     141$modinfo = module_getinfo('customcontexts'); 
     142if (is_array($modinfo)) { 
     143  $ver = $modinfo['customcontexts']['dbversion']; 
     144  if (version_compare($ver,'0.3.6','le')) { 
     145      outn(_("migrating..")); 
     146      /* We need to now migrate from from the old format of dispname_id where the only supported dispname 
     147         so far has been "routing" and the "id" used was the imperfect nnn-name. As it truns out, it was 
     148         possible to have the same route name perfiously so we will try to detect that. This was really ugly 
     149         so if we can't find stuff we will simply report errors and let the user go back and fix things. 
     150       */ 
     151      $sql = "SELECT * FROM customcontexts_includes_list WHERE context = 'outbound-allroutes'"; 
     152      $includes = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     153      if(DB::IsError($result) || !isset($includes)) {  
     154        out(_("Unknown error fetching table data or no data to migrate")); 
     155        out(_("Migration aborted")); 
     156      } else { 
     157        /* If there are any rows then lets get our route information. We will force this module to depend on 
     158         * the new core, so we can count on the APIs being available. If there are indentical names, then 
     159         * oh well... 
     160         */ 
     161        $routes = core_routing_list(); 
     162        $newincludes = array(); 
     163        foreach ($includes as $myinclude) { 
     164          $include = explode('-',$myinclude['include'],3); 
     165          $include[1] = (int)$include[1]; 
     166           
     167          foreach ($routes as $route) { 
     168            //if we have a trunk with the same name or the same number mathc it and take it out of the list 
     169            if ($include[2] == $route['name'] || $include[1] == $route['route_id']){ 
     170              $newincludes[] = array('new' => 'outrt-'.$route['route_id'],  
     171                                  'sort' => $route['seq'], 'old' => $include); 
     172              unset($includes[$myinclude]); 
     173            }  
     174          }  
     175        } 
     176 
     177        //alert user of unmigrated routes 
     178        foreach ($includes as $include) { 
     179          out(_('FAILED to migrating route '.$include['description'].'. NO MATCH FOUND')); 
     180          outn(_("continuing...")); 
     181        } 
     182 
     183        // We new have all the indices, so lets save them 
     184        // 
     185        $sql = $db->prepare('UPDATE customcontexts_includes_list SET include = ?, sort = ? WHERE include = ?'); 
     186        //$result = $db->executeMultiple($sql,$newincludes); 
     187        if(DB::IsError($result)) { 
     188          out("FATAL: ".$result->getDebugInfo()."\n".'error updating customcontexts_includes_list table. Aborting!');  
     189        } else { 
     190          //now update the next table 
     191          foreach ($newincludes as $newinclude){  
     192            unset($newincludes[$newinclude]['sort']); 
     193          } 
     194          $sql = $db->prepare('UPDATE customcontexts_includes SET include = ?, WHERE include = ?'); 
     195          //$result = $db->executeMultiple($sql,$newincludes); 
     196          if(DB::IsError($result)) { 
     197            out("FATAL: ".$result->getDebugInfo()."\n".'error updating customcontexts_includes table. Aborting!');   
     198          } else { 
     199          out(_("done"));          
     200        } 
     201      } 
     202    } 
     203  } 
     204} 
     205 
     206 
    40207?> 
  • contributed_modules/modules/customcontexts/module.xml

    r9822 r9823  
    22  <rawname>customcontexts</rawname> 
    33  <name>Custom Contexts</name> 
    4   <version>0.3.7</version> 
     4  <version>2.8.0beta1.0</version> 
    55  <type>setup</type> 
    66  <category>Third Party Addon</category> 
    77  <description> 
    8     Creates custom contexts which can be used to allow limited access to dialplan applications. 
    9     Allows for time restrictions on any dialplan access. 
    10     Allows for pattern matching to allow/deny. 
    11     Allows for failover destinations, and PIN protected failover. 
    12     This can be very useful for multi-tennant systems. 
    13     Inbound routing can be done using DID or zap channel routing, this module allows for selective outbound routing. 
    14     House/public phones can be placed in a restricted context allowing them only internal calls. 
     8    Creates custom contexts which can be used to allow limited access to dialplan applications. Allows for time restrictions on any dialplan access. Allows for pattern matching to allow/deny. Allows for failover destinations, and PIN protected failover. This can be very useful for multi-tennant systems. Inbound routing can be done using DID or zap channel routing,  this module allows for selective outbound routing. House/public phones can be placed in a restricted context allowing them only internal calls. 
    159  </description> 
    1610  <menuitems> 
     
    2014  </menuitems> 
    2115        <depends> 
    22           <version>lt 2.8.0alpha1</version> 
     16          <version> 2.8.0alpha1</version> 
    2317          <module>core</module> 
    2418        </depends> 
    2519        <changelog> 
    26                 *0.3.7* remove EOL warnings 
    27                 *0.3.6* fix version, End of Life warning, dependency requirement 
    28                 *0.3.5* #3994 current context on extension page not sticking 
    29                 *0.3.4* see http://freepbx.org/forum/freepbx/users/custom-contexts-broken-in-freepbx-2-3-1-3 
    30                 *0.3.3* Added Set All option to quickly allow/deny all. 
    31                         Fixed bug which caused routes to be denied after rename/sort/or delete other route. 
    32                 *0.3.2* Optional PIN to protect failover destination. 
    33                         Contexts can now be used as destinations. An IVR menu, Time Condition, etc. can now send a caller into a custom context. 
    34                         (This last feature requires a bugfix in 2.2 after rc1. bug #1549) 
    35                 *0.3.1* Now prompts on delete. After duplicate you are editing new context. Allows rename context. 
    36                 *0.3.0* New Features: 
    37                         Allow or Deny based on pattern matching. 
    38                         Failover Destination (one for regular extension, one for failed feature codes) 
    39                         Bugfixes: 
    40                         Adjusted Gui, Duplicate context, now duplicates the description too. 
    41                 *0.2.2* Bugfix: Duplicate Context now copies the priority also. 
    42                 *0.2.1* Added Duplicate Context option to easily copy an entire set of rules. 
    43                 *0.2.0* Added priority feature to allow the user to control in what order the allowed contexts are included. 
    44                 *0.1.3* Made it obvious when allowing one include may allow another entire context. 
    45                 *0.1.2* Bugfixes- deleted routes, etc. now are removed. 
    46                         Context tests for spaces and illegal chars. 
    47                         Moved admin to tools to reduce confusion. 
    48                         Added option to allow entire internal dialplan. (Usefull for time limit on everything) 
    49                         Made description for outbound-allroutes clearer that allowing overrides to allow all routes. 
    50                 *0.1.1* Still Beta, added time groups and bugfixes 
    51                 *0.0.1* Beta release 
     20          *2.8.0beta1.0* migration and changes to support 2.8 
     21          *0.3.7* remove EOL warnings 
     22          *0.3.6* fix version, End of Life warning, dependency requirement 
     23          *0.3.5* #3994 current context on extension page not sticking 
     24          *0.3.4* see http://freepbx.org/forum/freepbx/users/custom-contexts-broken-in-freepbx-2-3-1-3 
     25          *0.3.3* Added Set All option to quickly allow/deny all. Fixed bug which caused routes to be denied after rename/sort/or delete other route. 
     26          *0.3.2* Optional PIN to protect failover destination. Contexts can now be used as destinations. An IVR menu, Time Condition, etc. can now send a caller into a custom context. (This last feature requires a bugfix in 2.2 after rc1. bug #1549) 
     27          *0.3.1* Now prompts on delete. After duplicate you are editing new context. Allows rename context. 
     28          *0.3.0* New Features: Allow or Deny based on pattern matching. Failover Destination (one for regular extension, one for failed feature codes) Bugfixes: Adjusted Gui, Duplicate context, now duplicates the description too. 
     29          *0.2.2* Bugfix: Duplicate Context now copies the priority also. 
     30          *0.2.1* Added Duplicate Context option to easily copy an entire set of rules. 
     31          *0.2.0* Added priority feature to allow the user to control in what order the allowed contexts are included. 
     32          *0.1.3* Made it obvious when allowing one include may allow another entire context. 
     33          *0.1.2* Bugfixes- deleted routes, etc. now are removed. Context tests for spaces and illegal chars. Moved admin to tools to reduce confusion. Added option to allow entire internal dialplan. (Usefull for time limit on everything) Made description for outbound-allroutes clearer that allowing overrides to allow all routes. 
     34          *0.1.1* Still Beta, added time groups and bugfixes 
     35          *0.0.1* Beta release 
    5236        </changelog> 
    5337  <attention> 
     
    5741    REMEMBER! Any device placed in a restricted context will have no access to the dialplan if this module is disabled until it is placed in a normal context! 
    5842  </attention> 
    59   <location>contributed_modules/release/customcontexts-0.3.7.tgz</location> 
    60   <md5sum>f4fd5fd77afb3a9c41d56efb34577d29</md5sum> 
     43  <location>contributed_modules/release/customcontexts-0.3.5.tgz</location> 
     44  <md5sum>69192c610cb8985dc3baee543ffe9ef0</md5sum> 
    6145</module> 
  • contributed_modules/modules/customcontexts/page.customcontexts.php

    r9821 r9823  
    1212 
    1313$dispnum = 'customcontexts'; //used for switch on config.php 
    14  
    1514?> 
    1615 
  • contributed_modules/modules/customcontexts/uninstall.php

    r9821 r9823  
    1010//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1111//GNU General Public License for more details. 
     12 
     13$sql[] = "DROP TABLE IF EXISTS `customcontexts_contexts`"; 
     14$sql[] = "DROP TABLE IF EXISTS `customcontexts_contexts_list`"; 
     15$sql[] = "DROP TABLE IF EXISTS `customcontexts_includes`"; 
     16$sql[] = "DROP TABLE IF EXISTS `customcontexts_includes_list`"; 
     17$sql[] = "DROP TABLE IF EXISTS `customcontexts_module`"; 
     18$sql[] = "DROP TABLE IF EXISTS `customcontexts_timegroups`"; 
     19$sql[] = "DROP TABLE IF EXISTS `customcontexts_timegroups_detail`"; 
     20foreach ($sql as $q){ 
     21  $db->query($sql); 
     22} 
    1223?> 
    1324<font color="red"><strong>You have uninstalled the Custom Contexts Module!<BR>