Changeset 12802

Show
Ignore:
Timestamp:
10/14/11 16:59:32 (2 years ago)
Author:
p_lindheimer
Message:

remove FOP from framework and convert to real module

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.10/amp_conf/bin/retrieve_conf

    r12757 r12802  
    829829} 
    830830 
    831 // script to write op_server.cfg file from mysql  
    832 // 
    833 if(!$amp_conf['FOPDISABLE'])  { 
    834   if (!@include("retrieve_op_conf_from_mysql.php")) { 
    835     error(_("error running retrieve_op_conf_from_mysql.php")); 
    836   } 
    837   /* 
    838   $script = $amp_conf['AMPBIN'].'/retrieve_op_conf_from_mysql.php'; 
    839   if (is_executable($script)) { 
    840     $script .= ' '.$amportalconf.' '.rtrim($asterisk_conf['astetcdir'],DIRECTORY_SEPARATOR); 
    841     $output = array(); 
    842     exec($script, $output, $ret); 
    843     if ($ret) { 
    844       error(sprintf(_("retrieve_op_conf_from_mysql.php returned with an error code %s"),$ret)); 
    845     } 
    846   } else { 
    847     error(_("retrieve_op_conf_from_mysql.php does not exist or is not executable")); 
    848   } 
    849   */ 
    850 } 
    851 // generate configuration files 
    852 // 
    853 // Leave the legacy scripts in for a little while to help with odd-ball upgrade scenarios if they haven't gotten 
    854 // a module upgraded yet. In particular Queues 
    855 // 
    856 if (!isset($core_conf) || !is_a($core_conf, "core_conf")) { 
    857   include_once("libfreepbx.confgen.php"); 
    858   generate_configurations_sip($version); 
    859   generate_configurations_iax($version); 
    860   generate_configurations_zap($version); 
    861 } 
    862 if (isset($modules['queues']['status']) && $modules['queues']['status'] == MODULE_STATUS_ENABLED && (!isset($queues_conf) || !is_a($queues_conf, "queues_conf"))) { 
    863   include_once("libfreepbx.confgen.php"); 
    864   generate_configurations_queues($version); 
    865 } 
    866    
    867831// Check and install the freepbx-cron-scheduler.php manager 
    868832// 
  • freepbx/branches/2.10/amp_conf/htdocs/admin/functions.inc.php

    r12522 r12802  
    373373  $return['message'] = _('Successfully reloaded'); 
    374374   
    375   if ($amp_conf['FOPRUN'] && !$amp_conf['FOPDISABLE']) { 
    376     unset($output); 
    377     exec('killall -HUP op_server.pl 2>&1', $output, $exit_val); 
    378     if ($exit_val != 0) { 
    379       $desc = _('Could not reload the FOP operator panel server using killall -HUP op_server.pl. Configuration changes may not be reflected in the panel display.'); 
    380       $notify->add_error('freepbx','reload_fop', _('Could not reload FOP server'), $desc); 
    381       // send the error output to dbug log if enabled. 
    382       dbug($output); 
    383        
    384       $return['num_errors']++; 
    385     } else { 
    386       $notify->delete('freepbx','reload_fop'); 
    387     } 
    388   } 
    389    
    390375  //store asterisk reloaded status 
    391376  $sql = "UPDATE admin SET value = 'false' WHERE variable = 'need_reload'";  
  • freepbx/branches/2.10/libfreepbx.install.php

    r12777 r12802  
    256256       
    257257      // configurable in amportal.conf 
    258       if (strpos($destination,"htdocs_panel")) { 
    259         $destination=str_replace("/htdocs_panel",trim($amp_conf["FOPWEBROOT"]),$destination); 
    260       } else { 
    261         $destination=str_replace("/htdocs",trim($amp_conf["AMPWEBROOT"]),$destination); 
    262       } 
    263       $destination=str_replace("/htdocs_panel",trim($amp_conf["FOPWEBROOT"]),$destination); 
    264 //      $destination=str_replace("/cgi-bin",trim($amp_conf["AMPCGIBIN"]),$destination); 
    265258      if(strpos($dirsource, 'modules') === false) $destination=str_replace("/bin",trim($amp_conf["AMPBIN"]),$destination); 
    266259      $destination=str_replace("/sbin",trim($amp_conf["AMPSBIN"]),$destination); 
     
    14761469  $set['level'] = 0; 
    14771470 
    1478   // FOPSORT 
    1479   $set['value'] = 'extension'; 
    1480   $set['options'] = 'extension,lastname'; 
    1481   $set['name'] = 'FOP Sort Mode'; 
    1482   $set['description'] = 'How FOP sort extensions. By Last Name [lastname] or by Extension [extension].'; 
    1483   $set['emptyok'] = 0; 
    1484   $set['readonly'] = 0; 
    1485   $set['type'] = CONF_TYPE_SELECT; 
    1486   $freepbx_conf->define_conf_setting('FOPSORT',$set); 
    1487  
     1471  // FOPWEBROOT also used by FOP2 and iSymphony modules 
    14881472  // FOPWEBROOT 
    1489   $set['value'] = '/var/www/html/panel'; 
     1473  $set['value'] = ''; 
    14901474  $set['options'] = ''; 
    14911475  $set['name'] = 'FOP Web Root Dir'; 
    1492   $set['description'] = 'Path to the Flash Operator Panel webroot (leave off trailing slash).'; 
    1493   $set['emptyok'] = 0; 
    1494   $set['readonly'] = 1; 
     1476  $set['description'] = 'Path to the Flash Operator Panel webroot or other modules providing such functionality (leave off trailing slash).'; 
     1477  $set['emptyok'] = 1; 
     1478  $set['readonly'] = 1; 
     1479  $set['hidden'] = 1; 
    14951480  $set['type'] = CONF_TYPE_DIR; 
    14961481  $set['level'] = 4; 
    14971482  $freepbx_conf->define_conf_setting('FOPWEBROOT',$set); 
    14981483  $set['level'] = 0; 
    1499  
    1500   // FOPPASSWORD 
    1501   $set['value'] = 'passw0rd'; 
    1502   $set['options'] = ''; 
    1503   $set['name'] = 'FOP Password'; 
    1504   $set['description'] = 'Password for performing transfers and hangups in the Flash Operator Panel (FOP).'; 
    1505   $set['emptyok'] = 0; 
    1506   $set['readonly'] = 0; 
    1507   $set['type'] = CONF_TYPE_TEXT; 
    1508   $freepbx_conf->define_conf_setting('FOPPASSWORD',$set); 
    1509  
    1510   // FOPDISABLE 
    1511   $set['value'] = false; 
    1512   $set['options'] = ''; 
    1513   $set['name'] = 'Disable FOP'; 
    1514   $set['description'] = 'Set to true to disable FOP in interface and retrieve_conf.  Useful for sqlite3 or if you do not want FOP.'; 
    1515   $set['emptyok'] = 0; 
    1516   $set['readonly'] = 0; 
    1517   $set['type'] = CONF_TYPE_BOOL; 
    1518   $freepbx_conf->define_conf_setting('FOPDISABLE',$set); 
    1519  
    1520   // FOPRUN 
    1521   $set['value'] = true; 
    1522   $set['options'] = ''; 
    1523   $set['name'] = 'Start FOP with amportal'; 
    1524   $set['description'] = 'Set to true if you want FOP started by freepbx_engine (amportal_start), false otherwise.'; 
    1525   $set['emptyok'] = 0; 
    1526   $set['readonly'] = 0; 
    1527   $set['type'] = CONF_TYPE_BOOL; 
    1528   $freepbx_conf->define_conf_setting('FOPRUN',$set); 
    15291484 
    15301485 
  • modules/branches/2.10/fw_fop/functions.inc.php

    r12167 r12802  
    11<?php 
    2  
    3 # Retrieves the sip user/peer entries from the database for the flash operator panel 
    4  
    5 ################### BEGIN OF CONFIGURATION #################### 
     2// TODO: ugliness! 
     3// This whole file is an "ugly" portr of retrieve_op_conf_from_mysql.php, if it persists 
     4// it would be nice to write properly. 
     5// 
     6// Use hookGet_config to get this to exectue as late as possible for now minimizing any relics 
     7// with changes not yet done. 
     8// 
     9function fw_fop_hookGet_config($engine) { 
     10  $modulename = 'fw_fop'; 
     11   
     12  // This generates the dialplan 
     13  global $ext;   
     14  global $amp_conf;   
     15  global $version; 
     16  global $nt; 
     17  switch($engine) { 
     18    case "asterisk": 
     19      fw_fop_retrieve_op_conf_from_mysql(); 
     20 
     21      // TODO: This used to be done in the POST_RELOAD space after reload was successful and there was likely 
     22      //       a good reason for it as in config changes where made to Asterisk and are not visible thus can line 
     23      //       up with the configuration file. Moving it here may break things but we'll try for now and 
     24      //       see what happens. 
     25      // 
     26      unset($output); 
     27      exec('killall -HUP op_server.pl 2>&1', $output, $exit_val); 
     28      if ($exit_val != 0) { 
     29        $desc = _('Could not reload the FOP operator panel server using killall -HUP op_server.pl. Configuration changes may not be reflected in the panel display.'); 
     30        $nt->add_error('freepbx','reload_fop', _('Could not reload FOP server'), $desc); 
     31        // send the error output to dbug log if enabled. 
     32      } else { 
     33        $nt->delete('freepbx','reload_fop'); 
     34      } 
     35    break; 
     36  } 
     37
     38 
     39 
     40/** 
     41 * function fw_fop_retrieve_op_conf_from_mysql 
     42 * straight port from retrieve_op_conf_from_mysql.php 
     43 * 
     44 * TODO: this should be updated some day so that it is 
     45 * properly written vs. a port of the standalone code 
     46 * 
     47 */ 
     48function fw_fop_retrieve_op_conf_from_mysql() { 
     49 
     50// Retrieves the sip user/peer entries from the database for the flash operator panel 
     51 
     52//################# BEGIN OF CONFIGURATION #################### 
    653 
    754global $zapataconfdir; 
     
    1966} 
    2067 
    21 ######## LAYOUT INFO ######### 
    22  
    23 # NOTE - These values may be overwritten by values in a table in the freepbx database named "panel" 
    24 # NOTE = Currently only one layout is supported. This layout is applied to all panel contexts (amp users). 
    25 # TODO - add support in this code and in "panel" database for a layout for each panel context (amp user) 
    26  
    27 # structure is - ID, Legend, startpos, stoppos, color1, color2 
     68//###### LAYOUT INFO ######### 
     69 
     70// NOTE - These values may be overwritten by values in a table in the freepbx database named "panel" 
     71// NOTE = Currently only one layout is supported. This layout is applied to all panel contexts (amp users). 
     72// TODO - add support in this code and in "panel" database for a layout for each panel context (amp user) 
     73 
     74// structure is - ID, Legend, startpos, stoppos, color1, color2 
    2875$rectangle1 = array("trunk","Trunks", 53, 80, "10ff10", "009900"); 
    2976$rectangle2 = array("extension","Extensions", 1, 40, "1010ff", "99cccc"); 
     
    3885$legendoffsety = 1; 
    3986 
    40 # $layoutbuttonsonly = 0 : allow display of buttons even if no corresponding layout info 
    41 # $layoutbuttonsonly = 1 : suppress display of buttons if no corresponding layout info 
     87// $layoutbuttonsonly = 0 : allow display of buttons even if no corresponding layout info 
     88// $layoutbuttonsonly = 1 : suppress display of buttons if no corresponding layout info 
    4289$layoutbuttonsonly = 1; 
    4390 
    44 ######## BUTTON INFO ######### 
     91//###### BUTTON INFO ######### 
    4592$buttonsizex = 246; # 1+244+1 from information in op_style.cfg 
    4693$buttonsizey = 28; # 1+26+1 from information in op_style.cfg 
     
    5198 
    5299 
    53 ######## STYLE INFO ######### 
    54  
    55 # NOTE - These values may be overwritten by the syleinfo function with values generated from the layout info 
     100//###### STYLE INFO ######### 
     101 
     102// NOTE - These values may be overwritten by the syleinfo function with values generated from the layout info 
    56103 
    57104$extenpos="2-40"; 
     
    63110 
    64111 
    65 # Remove or add Zap trunks as needed 
    66 # Note: ZAP/* will match any ZAP channel that *is not referenced* in another button (ie: extensions) 
     112// Remove or add Zap trunks as needed 
     113// Note: ZAP/* will match any ZAP channel that *is not referenced* in another button (ie: extensions) 
    67114$zaplines=array(); # zap channel, description 
    68115#array_push($zaplines,array( "Zap/*","PSTN" )); 
     
    73120 
    74121if (file_exists($zapataconf)) { 
    75   parse_zapata($zaplines,$zapataconf); 
     122  fw_fop_parse_zapata($zaplines,$zapataconf); 
    76123} 
    77124// Now no need to parse other files as include declarations are followed 
    78125//if (file_exists($zapataautoconf)) { 
    79 //  parse_zapata($zaplines,$zapataautoconf); 
     126//  fw_fop_parse_zapata($zaplines,$zapataautoconf); 
    80127//} 
    81128 
    82 function parse_zapata(&$zaplines,$conffile) { 
    83   # LETS PARSE zapata.conf 
    84   # Allowed format options 
    85   # %c Zap Channel number 
    86   # %n Line number 
    87   # %N Line number, but restart counter 
    88   # Example: 
    89   # ;AMPLABEL:Channel %c - Button %n 
     129 
     130 
     131# Conference Rooms not yet implemented in AMP config 
     132$conferences=array();   #### ext#, description 
     133#array_push($conferences,array( "810","Conf.10" )); 
     134#array_push($conferences,array( "811","Conf.11" )); 
     135 
     136# cool hack by Julien BLACHE <jblache@debian.org> 
     137# WARNING: this file will be substituted by the output of this program 
     138$op_conf = $amp_conf["AMPWEBROOT"]."/panel/op_buttons_additional.cfg"; 
     139# username to connect to the database 
     140$username = $amp_conf["AMPDBUSER"]; 
     141# password to connect to the database 
     142$password = $amp_conf["AMPDBPASS"]; 
     143# the name of the box the MySQL database is running on 
     144$hostname = $amp_conf["AMPDBHOST"]; 
     145# the name of the database our tables are kept 
     146$database = $amp_conf["AMPDBNAME"]; 
     147#sort option: extension or lastname 
     148$sortoption = $amp_conf["FOPSORT"]; 
     149 
     150################### END OF CONFIGURATION ####################### 
     151 
     152$warning_banner = 
     153"; do not edit this file, this is an auto-generated file by freepbx 
     154; all modifications must be done from the web gui 
     155"; 
     156 
     157# Get layout-info from a "panel" table in the freepbx database 
     158if (fw_fop_table_exists($db,"panel")) { 
     159 
     160  $statement = "SELECT id, legend, startpos, stoppos, color1, color2 from panel"; 
     161  $results = $db->getAll($statement); 
     162  if(DB::IsError($results)) { 
     163     die($results->getMessage()); 
     164  } 
     165  if (count($results) < 1) { 
     166    print "Notice: no panel defined\n"; 
     167  } 
     168  $rectangles = $results; 
     169
     170 
     171// pass layout info to function explicitly rather than via globals 
     172$layoutinfo = array('rectangles'=>$rectangles,'numbuttonsx'=>$numbuttonsx,'numbuttonsy'=>$numbuttonsy); 
     173 
     174# Automated generation of style-info from layout-info 
     175$autoextenpos=fw_fop_get_style_info("extension",$layoutinfo); 
     176$autotrunkpos=fw_fop_get_style_info("trunk",$layoutinfo); 
     177$autoparkingpos=fw_fop_get_style_info("parking",$layoutinfo); 
     178$autoconfepos=fw_fop_get_style_info("conference",$layoutinfo); 
     179$autoqueuepos=fw_fop_get_style_info("queue",$layoutinfo); 
     180 
     181if ($layoutbuttonsonly == 1) {$extenpos = ""; $trunkpos = ""; $parkingpos = ""; $confepos = ""; $queuepos = "";} 
     182 
     183if (isset($autoextenpos)) {$extenpos = $autoextenpos;} 
     184if (isset($autotrunkpos)) {$trunkpos = $autotrunkpos;} 
     185if (isset($autoparkingpos)) {$parkingpos = $autoparkingpos;} 
     186if (isset($autoconfepos)) {$confepos = $autoconfepos;} 
     187if (isset($autoqueuepos)) {$queuepos = $autoqueuepos;} 
     188 
     189 
     190$fhandle = fopen($op_conf,"w" ); 
     191if ($fhandle === false) {die("Cannot create/overwrite config file: $op_conf \n");} 
     192fwrite($fhandle, $warning_banner); 
     193 
     194#First, populate extensions 
     195 
     196$extensionlist=array(); 
     197 
     198if (fw_fop_table_exists($db,"devices")) { 
     199  $statement = "SELECT description,id,dial,tech from devices"; 
     200  $results = $db->getAll($statement); 
     201  if(DB::IsError($results)) { 
     202     die($results->getMessage()); 
     203  } 
     204  if (count($results) < 1) { 
     205    print "Notice: no Devices defined\n"; 
     206  } 
     207  $extensionlist = $results; 
     208
     209else { print "Table does not exist: devices\n"; } 
     210 
     211# sort the extensions 
     212foreach ($extensionlist as $key=>$extension) { 
     213  $temparray = explode(" ",$extension[0]); 
     214  $lastname[$key] = end($temparray); 
     215  $extnum[$key] = $extension[1]; 
     216
     217 
     218if  (isset($sortoption) && ($sortoption == "lastname")) { 
     219  array_multisort($lastname,$extensionlist); 
     220} else { 
     221  array_multisort($extnum,SORT_STRING,$extensionlist); 
     222
     223 
     224#Next, populate queues 
     225$queues=array(); 
     226if (fw_fop_table_exists($db,"queues_config")) { 
     227  $statement = "SELECT extension,descr from queues_config order by extension"; 
     228  $results = $db->getAll($statement); 
     229  if(DB::IsError($results)) { 
     230     die($results->getMessage()); 
     231  } 
     232  if (count($results) < 1) { 
     233    print "Notice: no Queues defined\n"; 
     234  } 
     235  $queues = $results; 
     236
     237else { print "Table does not exist: queues_config\n"; } 
     238 
     239 
     240## SME server chnges 
     241 
     242#Next, populate conferences 
     243$conferences=array(); 
     244if(fw_fop_table_exists($db,"meetme")) { 
     245  $statement = "SELECT exten,description FROM meetme ORDER BY exten"; 
     246  $results = $db->getAll($statement); 
     247  if(DB::IsError($results)) { 
     248     die($results->getMessage()); 
     249  } 
     250  if (count($results) < 1) { 
     251    print "Notice: no Conferences defined\n"; 
     252  } 
     253  $conferences = $results; 
     254
     255else { print "Table does not exist: meetme\n"; } 
     256 
     257 
     258#Next, populate parkings 
     259$parkings=array(); 
     260if(fw_fop_table_exists($db,"parkinglot")) { 
     261  $statement = "SELECT keyword,data FROM parkinglot"; 
     262  $results = $db->getAll($statement); 
     263  if(DB::IsError($results)) { 
     264     die($results->getMessage()); 
     265  } 
     266  if (count($results) < 1) { 
     267    print "Notice: no Parking Lots defined\n"; 
     268  } 
     269  $parkings = $results; 
     270
     271else { print "Table does not exist: parkinglot\n"; } 
     272 
     273## End of changes 
     274#Next, populate trunks (sip and iax) 
     275$trunklist=array(); 
     276$tables = array("sip","iax"); 
     277foreach ($tables as $table) { 
     278  if (fw_fop_table_exists($db,$table)) { 
     279    $statement = "SELECT data,id,'$table' from $table where keyword='account' and flags <> 1 and id LIKE 'tr-%' group by data order by id"; 
     280    $results = $db->getAll($statement); 
     281    if(DB::IsError($results)) { 
     282       die($results->getMessage()); 
     283    } 
     284    if (count($results) < 1) { 
     285      print "Notice: no $table trunks defined\n"; 
     286    } 
     287    $trunklist = array_merge($trunklist,$results); 
     288
     289else { print "Table does not exist: $table \n"; } 
     290
     291 
     292#Determine AMP Users 
     293$ampusers=array(); 
     294if (fw_fop_table_exists($db,"ampusers")) { 
     295  $statement = 'SELECT deptname,extension_low,extension_high from ampusers WHERE NOT extension_low = "" AND NOT extension_high = ""'; 
     296    $results = $db->getAll($statement); 
     297    if(DB::IsError($results)) { 
     298       die($results->getMessage()); 
     299    } 
     300    if (count($results) < 1) { 
     301      print "Notice: no AMP Users defined\n"; 
     302    } 
     303    else { 
     304      $ampusers = $results; 
     305    } 
     306
     307else { print "Table does not exist: ampusers\n"; } 
     308array_push($ampusers,array("default","0","0")); //add a default panelcontext that can see all extensions 
     309 
     310#Write a separate panel context from each AMP User department 
     311foreach ($ampusers as $pcontext) { 
     312  $exten_low = $pcontext[1]; 
     313  $exten_high = $pcontext[2]; 
     314  $panelcontext = $pcontext[0]; 
     315  if ($panelcontext == "") { $panelcontext = $exten_low."to".$exten_high; } 
     316 
     317fwrite($fhandle, "\n\n; Panel Context: " . $panelcontext . "\n"); 
     318 
     319  # WRITE EXTENSIONS 
     320 
     321  $btn=0; 
     322  if ($exten_low != 0 && $exten_high != 0) {  #display only allowed range of extensions for panel_contexts 
     323    $extensionrange = array(); 
     324    foreach ($extensionlist as $value) { 
     325      if (!is_numeric($value[1])) {array_push($extensionrange,$value);} 
     326      if (($value[1] >= $exten_low) && ($value[1] <= $exten_high))  {array_push($extensionrange,$value);} 
     327    } 
     328  } else { 
     329    $extensionrange = $extensionlist; 
     330  } 
     331 
     332  foreach ( $extensionrange as $row ) { 
     333    $description = $row[0]; 
     334    $id = $row[1]; 
     335    $dial = $row[2]; 
     336 
     337 
     338    # Support for real mailbox settings - 
     339    $tech = $row[3]; 
     340    # some sensible defaults for voicemail ext and context 
     341    $vmext = $row[1]; 
     342    $vmcontext = "default"; 
     343    # the device tech table should also have a dial context - if not assume from-internal 
     344    $context = "from-internal"; 
     345    # database table name for iax2 is just iax but sip and zap are ok 
     346    if ($tech == "iax2") {$tech = "iax";} 
     347    # get mailbox setting from relevant tech table and split into ext and content 
     348    if (fw_fop_table_exists($db,$tech)) { 
     349      $statement = "SELECT data from $tech WHERE id = '$id' AND keyword = 'mailbox' "; 
     350      $results = $db->getAll($statement); 
     351      if(DB::IsError($results)) { 
     352         die($results->getMessage()); 
     353      } 
     354      if (count($results) < 1) { 
     355        print "Notice: no Mailboxes defined\n"; 
     356      } 
     357      else { 
     358      $mailbox = $results[0][0]; 
     359      $values = @explode('@', $mailbox,2); 
     360      if (strlen($values[0]) > 0) {$vmext = $values[0];} 
     361      if (strlen($values[1]) > 0) {$vmcontext = $values[1];} 
     362      } 
     363      #while in this table lets get the dial context as well 
     364      $statement = "SELECT data from $tech WHERE id = '$id' AND keyword = 'context' "; 
     365      $results = $db->getAll($statement); 
     366      if(DB::IsError($results)) { 
     367         die($results->getMessage()); 
     368      } 
     369      if (count($results) < 1) { 
     370        print "Notice: no Context defined\n"; 
     371      } 
     372      else { 
     373      $context = $results[0][0]; 
     374      } 
     375    } else { print "Table does not exist: $tech\n"; } 
     376    # - Support for real mailbox settings 
     377 
     378 
     379    # Support for real VM_PREFIX - 
     380    $vmprefix = "*"; 
     381    if (fw_fop_table_exists($db,"globals")) { 
     382      $statement = "SELECT value from globals WHERE variable = 'VM_PREFIX' "; 
     383      $results = $db->getAll($statement); 
     384      if(DB::IsError($results)) { 
     385         die($results->getMessage()); 
     386      } 
     387      if (count($results) < 1) { 
     388        print "Notice: no VM Prefix defined\n"; 
     389      } 
     390      else { 
     391      $vmprefix = $results[0][0]; 
     392      } 
     393    } else { print "Table does not exist: global\n"; } 
     394    # - Support for real VM_PREFIX 
     395 
     396    $btn=fw_fop_get_next_btn($extenpos,$btn); 
     397    $icon='4'; 
     398    fwrite($fhandle, "\n[$dial]\nPosition=$btn\nLabel=\"$id : $description\"\nExtension=$id\nContext=$context\nIcon=$icon\nVoicemail_Context=$vmcontext\nVoiceMailExt=$vmprefix$vmext@$context\nPanel_Context=$panelcontext\nAstdbkey=$id\n"); 
     399  } 
     400 
     401 
     402  ### NOW WRITE TRUNKS.. WE START WITH ZAP TRUNKS DEFINED ABOVE 
     403 
     404 
     405 
     406 
     407  $btn=0; 
     408 
     409  foreach ($zaplines as $row) { 
     410    $zapdef=$row[0]; 
     411    $zapdesc=$row[1]; 
     412    $icon='3'; 
     413    # zaplines and trunklist share the trunk positions so need to store previous btn on overflow from zaplines 
     414    $previousbtn = $btn; 
     415    $btn=fw_fop_get_next_btn($trunkpos,$btn); 
     416    if ($btn == 0) {$btn = $previousbtn; break;} 
     417    if ($zapdef == "Zap/*") { 
     418      $numbuttons=$row[2]-1; 
     419      fwrite($fhandle, "\n[$zapdef]\nLabel=\"$zapdesc\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\nPosition=".$btn); 
     420      while($numbuttons-->0) { 
     421        $btn=fw_fop_get_next_btn($trunkpos,$btn); 
     422        fwrite($fhandle, ",".$btn); 
     423      } 
     424 
     425      fwrite($fhandle, "\n"); 
     426    } else { 
     427      fwrite($fhandle, "\n[$zapdef]\nPosition=$btn\nLabel=\"$zapdesc\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
     428    } 
     429  } 
     430 
     431 
     432  foreach ($trunklist as $row) { 
     433    $account = $row[0]; 
     434    $id = $row[1]; 
     435    $table = $row[2]; 
     436    if ($account == "") {continue;}; 
     437    $btn=fw_fop_get_next_btn($trunkpos,$btn); 
     438    if ($btn == 0) {break;} 
     439    if (fw_fop_table_exists($db,$table)) { 
     440    $statement = "SELECT keyword,data from $table where id='$id' and keyword <> 'account' and flags <> 1 order by keyword"; 
     441      $results = $db->getAll($statement); 
     442      if(DB::IsError($results)) { 
     443         die($results->getMessage()); 
     444      } 
     445      if (count($results) < 1) { 
     446        print "Notice: no Trunks defined\n"; 
     447      } 
     448    } else { print "Table does not exist: $table \n"; } 
     449 
     450    if ($table == "sip") {$tech="SIP";} 
     451    if ($table == "iax") {$tech="IAX2";} 
     452    #if ($table == "zap") {$tech="ZAP";} #no zap trunks in db 
     453 
     454    $callerid = $account;  #default callerid to account 
     455 
     456    foreach ($results as $drow) { 
     457      if ( $drow[0] == "callerid" ) { 
     458        $callerid = $drow[1]; 
     459        $fields = explode("<",$callerid); 
     460        $callerid=$fields[1] ." ". $fields[0]; 
     461        $callerid = str_replace("\t","",$callerid); 
     462        $callerid = str_replace("\"","",$callerid); 
     463        $callerid = str_replace("<","",$callerid); 
     464        $callerid = str_replace(">","",$callerid); 
     465      } 
     466    } 
     467    $icon='3'; 
     468    fwrite($fhandle, "\n[$tech/$account]\nPosition=$btn\nLabel=\"$callerid\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
     469  } 
     470 
     471 
     472  ## SME server changes 
     473 
     474 
     475 
     476        ### Write Parkings lots 
     477  $btn=0; 
     478  $parken="" ; 
     479  $extpark ; 
     480  $parkcontext ; 
     481  $numberlots ; 
     482  $maxparkingslots ; 
     483 
     484  foreach ($parkings as $row) { 
     485    if ($row[0] == "parkingenabled") { 
     486      $parken = $row[1] ; 
     487    } 
     488    if ($row[0] == "parkext") { 
     489      $extpark = $row[1] ; 
     490    } 
     491    if ($row[0] == "parkingcontext") { 
     492      $parkcontext = $row[1] ; 
     493    } 
     494    if ($row[0] == "numslots") { 
     495      $numberlots = $row[1] ; 
     496    } 
     497  } 
     498  if ($parken == "s") { 
     499    for ($i = 1 ; $i <= $numberlots ; $i++ ) { 
     500      $btn=fw_fop_get_next_btn($parkingpos,$btn); 
     501      if ($btn == 0) {break;} 
     502      $parknum = $extpark + $i ; 
     503      $icon='1'; 
     504      fwrite($fhandle, "\n[PARK$parknum]\nPosition=$btn\nLabel=\"Parked ($parknum)\"\nExtension=$parknum\nContext=$parkcontext\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
     505    } 
     506  } 
     507 
     508  ## End of chagnes 
     509  ### Write conferences (meetme) 
     510 
     511  $btn=0; 
     512  if ($exten_low != 0 && $exten_high != 0) {  #display only allowed range of extensions for panel_contexts 
     513    $confrange = array(); 
     514    foreach ($conferences as $value) { 
     515      if (!is_numeric($value)) {array_push($confrange,$value);} 
     516      if (($value >= $exten_low) && ($value <= $exten_high))  {array_push($confrange,$value);} 
     517    } 
     518  } else { 
     519    $confrange = $conferences; 
     520  } 
     521  foreach ($confrange as $row) { 
     522    $btn=fw_fop_get_next_btn($confepos,$btn); 
     523    if ($btn == 0) {break;} 
     524    $confenum=$row[0]; 
     525    $confedesc=$row[1]; 
     526    $icon='6'; 
     527    fwrite($fhandle, "\n[$confenum]\nPosition=$btn\nLabel=\"$confedesc\"\nExtension=$confenum\nContext=from-internal\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
     528  } 
     529 
     530  ### Write Queues 
     531 
     532  $btn=0; 
     533  if ($exten_low != 0 && $exten_high != 0) {  #display only allowed range of extensions for panel_contexts 
     534    $queuerange = array(); 
     535    foreach ($queues as $value) { 
     536      if (!is_numeric($value)) {array_push($queuerange,$value);} 
     537      if (($value >= $exten_low) && ($value <= $exten_high))  {array_push($queuerange,$value);} 
     538    } 
     539  } else { 
     540    $queuerange = $queues; 
     541  } 
     542  foreach ($queuerange as $row) { 
     543    $btn=fw_fop_get_next_btn($queuepos,$btn); 
     544    if ($btn == 0) {break;} 
     545    $queuename=$row[0]; 
     546    $queuedesc=$row[1]; 
     547    $icon='5'; 
     548    fwrite($fhandle, "\n[QUEUE/$queuename]\nPosition=$btn\nLabel=\"$queuedesc\"\nExtension=-1\nContext=from-internal\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
     549  } 
     550 
     551  ### Write rectangles 
     552 
     553  foreach ($rectangles as $rect) { 
     554    $comment = $rect[0]; 
     555    $color1 = $rect[4]; 
     556    $color2 = $rect[5]; 
     557    $start = $rect[2]; 
     558    $stop = $rect[3]; 
     559 
     560    $xposition = $buttonsoriginx + $buttonsizex * floor(($start-1)/$numbuttonsy); 
     561    $yposition = $buttonsoriginy + $buttonsizey * (($start-1)%$numbuttonsy); 
     562    $xsize = $buttonsizex * (1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy)); 
     563    $ysize = $buttonsizey * (1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy)); 
     564 
     565    if (($xsize <= 0) || ($ysize <= 0)) {continue;} 
     566 
     567    $xposition += $rectmarginx; 
     568    $yposition += $rectmarginy; 
     569    $xsize -= 2 * $rectmarginx; 
     570    $ysize -= 2 * $rectmarginy; 
     571 
     572    fwrite($fhandle, "\n; $comment\n[rectangle]\nx=$xposition\ny=$yposition\nwidth=$xsize\nheight=$ysize\nline_width=0\nline_color=$color1\nfade_color1=$color1\nfade_color2=$color2\nrnd_border=2\nalpha=20\nlayer=bottom\nPanel_Context=$panelcontext\n"); 
     573  } 
     574 
     575  ### Write legends 
     576 
     577  foreach ($rectangles as $legend) { 
     578    $text = $legend[1]; 
     579    $start = $legend[2]; 
     580    $stop = $legend[3]; 
     581 
     582    $xposition = $buttonsoriginx + $buttonsizex * floor(($start-1)/$numbuttonsy); 
     583    $yposition = $buttonsoriginy + $buttonsizey * (($start-1)%$numbuttonsy); 
     584    $xsize = $buttonsizex * (1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy)); 
     585    $ysize = $buttonsizey * (1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy)); 
     586 
     587    if (($xsize <= 0) || ($ysize <= 0)) {continue;} 
     588 
     589    $xposition += $legendoffsetx; 
     590    $yposition += $legendoffsety; 
     591 
     592    fwrite($fhandle, "\n[LEGEND]\nx=$xposition\ny=$yposition\ntext=$text\nfont_size=18\nfont_family=Arial\nuse_embed_fonts=1\nPanel_Context=$panelcontext\n"); 
     593  } 
     594 
     595
     596 
     597} // function fw_fop_retrieve_op_conf_from_mysql() 
     598 
     599 
     600function fw_fop_get_next_btn($data,$last) { 
     601  $rangelist=explode(",",$data); 
     602  foreach ($rangelist as $range) { 
     603    $rangeval=explode("-",$range,2); 
     604    if ($last < $rangeval[0]) {return $rangeval[0] ;} 
     605    if (isset($rangeval[1]) && ($last < $rangeval[1])) {return $last+1;} 
     606    #Need to try another range def... 
     607  } 
     608  #If we get here, we ran out of positions :( 
     609  return 0; #????? 
     610
     611 
     612#this sub checks for the existance of a table 
     613function fw_fop_table_exists($db,$table) { 
     614  $result = mysql_query("SHOW TABLES LIKE '" . $table . "'"); 
     615  if(mysql_fetch_row($result) === false) {return(false);} 
     616  return(true); 
     617
     618 
     619function fw_fop_get_style_info($id,$layoutinfo) { 
     620// do not use globals - instead pass layout info into function explicitly 
     621//  global $rectangles; 
     622//  global $numbuttonsx; 
     623//  global $numbuttonsy; 
     624$rectangles = $layoutinfo['rectangles']; 
     625$numbuttonsx = $layoutinfo['numbuttonsx']; 
     626$numbuttonsy = $layoutinfo['numbuttonsy']; 
     627 
     628 
     629  foreach ($rectangles as $rect) { 
     630    if ($id == $rect[0]) { 
     631 
     632      $start = $rect[2]; 
     633      $stop = $rect[3]; 
     634 
     635      $xposition = floor(($start-1)/$numbuttonsy); 
     636      $yposition = (($start-1)%$numbuttonsy); 
     637      $xsize = 1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy); 
     638      $ysize = 1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy); 
     639 
     640      if (($xsize <= 0) || ($ysize <= 0)) {print "Warning: rectange '$id' has negative area\n"; break;} 
     641      $styleinfo = ""; 
     642      if ($ysize > 2) { 
     643        $styleinfo .= ($start + 1) . "-" . ($start + $ysize - 1) . ","; 
     644      } 
     645      elseif ($ysize == 2) { 
     646        $styleinfo .= ($start + 1) . ","; 
     647      } 
     648 
     649      for ($i = 1 ; $i < $xsize ; $i++ ) { 
     650        if ($ysize > 1) { 
     651          $styleinfo .= (($i + $xposition) * $numbuttonsy + $yposition + 1) . "-" . (($i + $xposition) * $numbuttonsy + $yposition + $ysize) . ","; 
     652        } 
     653        else { 
     654          $styleinfo .= (($i + $xposition) * $numbuttonsy + $yposition + 1) . ","; 
     655        } 
     656      } 
     657      $retval = $styleinfo; 
     658      break; 
     659    } 
     660  } 
     661  return $retval; 
     662
     663 
     664function fw_fop_parse_zapata(&$zaplines,$conffile) { 
     665  // LETS PARSE zapata.conf 
     666  // Allowed format options 
     667  // %c Zap Channel number 
     668  // %n Line number 
     669  // %N Line number, but restart counter 
     670  // Example: 
     671  // ;AMPLABEL:Channel %c - Button %n 
    90672 
    91673  global $zapataconfdir; 
     
    129711    } 
    130712 
    131     # remove comments 
     713    // remove comments 
    132714    $line_arr = explode(";",$line,2); 
    133715    $line = trim($line_arr[0]); 
    134716    if ($line == "") {continue;} 
    135717 
    136     #normalize whitespace 
     718    //normalize whitespace 
    137719    $line = str_replace("\t"," ",$line); 
    138720    $line = preg_replace("/(\040)+/", " ", $line); 
     
    146728        } 
    147729 
    148     #normalize assignment operator 
     730    //normalize assignment operator 
    149731    $line = str_replace("=>","=",$line); 
    150732    $line = str_replace(" ","",$line); 
     
    152734    //echo "Debug: " . $line . "\n"; 
    153735 
    154         # check if trunk or extension 
     736        // check if trunk or extension 
    155737        //note that some versions of php do not support !== but only === 
    156738        if (!(strpos($line,"context=from-pstn") === false)) { 
     
    182764          $newlabel=str_replace("%N",$lastlabelnum,$newlabel); 
    183765 
    184           # only add if A) this is a trunk 
    185           # and B) we have not already defined any zaplines at the top of the file 
    186           # (I use this to customize it so instead of saying "Zap 1" it will 
    187           # say something more useful -- like the phone # of the line) 
     766          // only add if A) this is a trunk 
     767          // and B) we have not already defined any zaplines at the top of the file 
     768          // (I use this to customize it so instead of saying "Zap 1" it will 
     769          // say something more useful -- like the phone # of the line) 
    188770 
    189771          if($istrunk == 1) { 
     
    209791  return $zaplines; 
    210792} 
    211 #Finished parsing zapata.conf 
    212  
    213  
    214 # Conference Rooms not yet implemented in AMP config 
    215 $conferences=array();   #### ext#, description 
    216 #array_push($conferences,array( "810","Conf.10" )); 
    217 #array_push($conferences,array( "811","Conf.11" )); 
    218  
    219 # cool hack by Julien BLACHE <jblache@debian.org> 
    220 # WARNING: this file will be substituted by the output of this program 
    221 $op_conf = $amp_conf["AMPWEBROOT"]."/panel/op_buttons_additional.cfg"; 
    222 # username to connect to the database 
    223 $username = $amp_conf["AMPDBUSER"]; 
    224 # password to connect to the database 
    225 $password = $amp_conf["AMPDBPASS"]; 
    226 # the name of the box the MySQL database is running on 
    227 $hostname = $amp_conf["AMPDBHOST"]; 
    228 # the name of the database our tables are kept 
    229 $database = $amp_conf["AMPDBNAME"]; 
    230 #sort option: extension or lastname 
    231 $sortoption = $amp_conf["FOPSORT"]; 
    232  
    233 ################### END OF CONFIGURATION ####################### 
    234  
    235 $warning_banner = 
    236 "; do not edit this file, this is an auto-generated file by freepbx 
    237 ; all modifications must be done from the web gui 
    238 "; 
    239  
    240 # Get layout-info from a "panel" table in the freepbx database 
    241 if (table_exists($db,"panel")) { 
    242  
    243   $statement = "SELECT id, legend, startpos, stoppos, color1, color2 from panel"; 
    244   $results = $db->getAll($statement); 
    245   if(DB::IsError($results)) { 
    246      die($results->getMessage()); 
    247   } 
    248   if (count($results) < 1) { 
    249     print "Notice: no panel defined\n"; 
    250   } 
    251   $rectangles = $results; 
    252 
    253  
    254 // pass layout info to function explicitly rather than via globals 
    255 $layoutinfo = array('rectangles'=>$rectangles,'numbuttonsx'=>$numbuttonsx,'numbuttonsy'=>$numbuttonsy); 
    256  
    257 # Automated generation of style-info from layout-info 
    258 $autoextenpos=get_styleinfo("extension",$layoutinfo); 
    259 $autotrunkpos=get_styleinfo("trunk",$layoutinfo); 
    260 $autoparkingpos=get_styleinfo("parking",$layoutinfo); 
    261 $autoconfepos=get_styleinfo("conference",$layoutinfo); 
    262 $autoqueuepos=get_styleinfo("queue",$layoutinfo); 
    263  
    264 if ($layoutbuttonsonly == 1) {$extenpos = ""; $trunkpos = ""; $parkingpos = ""; $confepos = ""; $queuepos = "";} 
    265  
    266 if (isset($autoextenpos)) {$extenpos = $autoextenpos;} 
    267 if (isset($autotrunkpos)) {$trunkpos = $autotrunkpos;} 
    268 if (isset($autoparkingpos)) {$parkingpos = $autoparkingpos;} 
    269 if (isset($autoconfepos)) {$confepos = $autoconfepos;} 
    270 if (isset($autoqueuepos)) {$queuepos = $autoqueuepos;} 
    271  
    272  
    273 $fhandle = fopen($op_conf,"w" ); 
    274 if ($fhandle === false) {die("Cannot create/overwrite config file: $op_conf \n");} 
    275 fwrite($fhandle, $warning_banner); 
    276  
    277 #First, populate extensions 
    278  
    279 $extensionlist=array(); 
    280  
    281 if (table_exists($db,"devices")) { 
    282   $statement = "SELECT description,id,dial,tech from devices"; 
    283   $results = $db->getAll($statement); 
    284   if(DB::IsError($results)) { 
    285      die($results->getMessage()); 
    286   } 
    287   if (count($results) < 1) { 
    288     print "Notice: no Devices defined\n"; 
    289   } 
    290   $extensionlist = $results; 
    291 
    292 else { print "Table does not exist: devices\n"; } 
    293  
    294 # sort the extensions 
    295 foreach ($extensionlist as $key=>$extension) { 
    296   $temparray = explode(" ",$extension[0]); 
    297   $lastname[$key] = end($temparray); 
    298   $extnum[$key] = $extension[1]; 
    299 
    300  
    301 if  (isset($sortoption) && ($sortoption == "lastname")) { 
    302   array_multisort($lastname,$extensionlist); 
    303 } else { 
    304   array_multisort($extnum,SORT_STRING,$extensionlist); 
    305 
    306  
    307 #Next, populate queues 
    308 $queues=array(); 
    309 if (table_exists($db,"queues_config")) { 
    310   $statement = "SELECT extension,descr from queues_config order by extension"; 
    311   $results = $db->getAll($statement); 
    312   if(DB::IsError($results)) { 
    313      die($results->getMessage()); 
    314   } 
    315   if (count($results) < 1) { 
    316     print "Notice: no Queues defined\n"; 
    317   } 
    318   $queues = $results; 
    319 
    320 else { print "Table does not exist: queues_config\n"; } 
    321  
    322  
    323 ## SME server chnges 
    324  
    325 #Next, populate conferences 
    326 $conferences=array(); 
    327 if(table_exists($db,"meetme")) { 
    328   $statement = "SELECT exten,description FROM meetme ORDER BY exten"; 
    329   $results = $db->getAll($statement); 
    330   if(DB::IsError($results)) { 
    331      die($results->getMessage()); 
    332   } 
    333   if (count($results) < 1) { 
    334     print "Notice: no Conferences defined\n"; 
    335   } 
    336   $conferences = $results; 
    337 
    338 else { print "Table does not exist: meetme\n"; } 
    339  
    340  
    341 #Next, populate parkings 
    342 $parkings=array(); 
    343 if(table_exists($db,"parkinglot")) { 
    344   $statement = "SELECT keyword,data FROM parkinglot"; 
    345   $results = $db->getAll($statement); 
    346   if(DB::IsError($results)) { 
    347      die($results->getMessage()); 
    348   } 
    349   if (count($results) < 1) { 
    350     print "Notice: no Parking Lots defined\n"; 
    351   } 
    352   $parkings = $results; 
    353 
    354 else { print "Table does not exist: parkinglot\n"; } 
    355  
    356 ## End of changes 
    357 #Next, populate trunks (sip and iax) 
    358 $trunklist=array(); 
    359 $tables = array("sip","iax"); 
    360 foreach ($tables as $table) { 
    361   if (table_exists($db,$table)) { 
    362     $statement = "SELECT data,id,'$table' from $table where keyword='account' and flags <> 1 and id LIKE 'tr-%' group by data order by id"; 
    363     $results = $db->getAll($statement); 
    364     if(DB::IsError($results)) { 
    365        die($results->getMessage()); 
    366     } 
    367     if (count($results) < 1) { 
    368       print "Notice: no $table trunks defined\n"; 
    369     } 
    370     $trunklist = array_merge($trunklist,$results); 
    371 
    372 else { print "Table does not exist: $table \n"; } 
    373 
    374  
    375 #Determine AMP Users 
    376 $ampusers=array(); 
    377 if (table_exists($db,"ampusers")) { 
    378   $statement = 'SELECT deptname,extension_low,extension_high from ampusers WHERE NOT extension_low = "" AND NOT extension_high = ""'; 
    379     $results = $db->getAll($statement); 
    380     if(DB::IsError($results)) { 
    381        die($results->getMessage()); 
    382     } 
    383     if (count($results) < 1) { 
    384       print "Notice: no AMP Users defined\n"; 
    385     } 
    386     else { 
    387       $ampusers = $results; 
    388     } 
    389 
    390 else { print "Table does not exist: ampusers\n"; } 
    391 array_push($ampusers,array("default","0","0")); //add a default panelcontext that can see all extensions 
    392  
    393 #Write a separate panel context from each AMP User department 
    394 foreach ($ampusers as $pcontext) { 
    395   $exten_low = $pcontext[1]; 
    396   $exten_high = $pcontext[2]; 
    397   $panelcontext = $pcontext[0]; 
    398   if ($panelcontext == "") { $panelcontext = $exten_low."to".$exten_high; } 
    399  
    400 fwrite($fhandle, "\n\n; Panel Context: " . $panelcontext . "\n"); 
    401  
    402   # WRITE EXTENSIONS 
    403  
    404   $btn=0; 
    405   if ($exten_low != 0 && $exten_high != 0) {  #display only allowed range of extensions for panel_contexts 
    406     $extensionrange = array(); 
    407     foreach ($extensionlist as $value) { 
    408       if (!is_numeric($value[1])) {array_push($extensionrange,$value);} 
    409       if (($value[1] >= $exten_low) && ($value[1] <= $exten_high))  {array_push($extensionrange,$value);} 
    410     } 
    411   } else { 
    412     $extensionrange = $extensionlist; 
    413   } 
    414  
    415   foreach ( $extensionrange as $row ) { 
    416     $description = $row[0]; 
    417     $id = $row[1]; 
    418     $dial = $row[2]; 
    419  
    420  
    421     # Support for real mailbox settings - 
    422     $tech = $row[3]; 
    423     # some sensible defaults for voicemail ext and context 
    424     $vmext = $row[1]; 
    425     $vmcontext = "default"; 
    426     # the device tech table should also have a dial context - if not assume from-internal 
    427     $context = "from-internal"; 
    428     # database table name for iax2 is just iax but sip and zap are ok 
    429     if ($tech == "iax2") {$tech = "iax";} 
    430     # get mailbox setting from relevant tech table and split into ext and content 
    431     if (table_exists($db,$tech)) { 
    432       $statement = "SELECT data from $tech WHERE id = '$id' AND keyword = 'mailbox' "; 
    433       $results = $db->getAll($statement); 
    434       if(DB::IsError($results)) { 
    435          die($results->getMessage()); 
    436       } 
    437       if (count($results) < 1) { 
    438         print "Notice: no Mailboxes defined\n"; 
    439       } 
    440       else { 
    441       $mailbox = $results[0][0]; 
    442       $values = @explode('@', $mailbox,2); 
    443       if (strlen($values[0]) > 0) {$vmext = $values[0];} 
    444       if (strlen($values[1]) > 0) {$vmcontext = $values[1];} 
    445       } 
    446       #while in this table lets get the dial context as well 
    447       $statement = "SELECT data from $tech WHERE id = '$id' AND keyword = 'context' "; 
    448       $results = $db->getAll($statement); 
    449       if(DB::IsError($results)) { 
    450          die($results->getMessage()); 
    451       } 
    452       if (count($results) < 1) { 
    453         print "Notice: no Context defined\n"; 
    454       } 
    455       else { 
    456       $context = $results[0][0]; 
    457       } 
    458     } else { print "Table does not exist: $tech\n"; } 
    459     # - Support for real mailbox settings 
    460  
    461  
    462     # Support for real VM_PREFIX - 
    463     $vmprefix = "*"; 
    464     if (table_exists($db,"globals")) { 
    465       $statement = "SELECT value from globals WHERE variable = 'VM_PREFIX' "; 
    466       $results = $db->getAll($statement); 
    467       if(DB::IsError($results)) { 
    468          die($results->getMessage()); 
    469       } 
    470       if (count($results) < 1) { 
    471         print "Notice: no VM Prefix defined\n"; 
    472       } 
    473       else { 
    474       $vmprefix = $results[0][0]; 
    475       } 
    476     } else { print "Table does not exist: global\n"; } 
    477     # - Support for real VM_PREFIX 
    478  
    479     $btn=get_next_btn($extenpos,$btn); 
    480     $icon='4'; 
    481     fwrite($fhandle, "\n[$dial]\nPosition=$btn\nLabel=\"$id : $description\"\nExtension=$id\nContext=$context\nIcon=$icon\nVoicemail_Context=$vmcontext\nVoiceMailExt=$vmprefix$vmext@$context\nPanel_Context=$panelcontext\nAstdbkey=$id\n"); 
    482   } 
    483  
    484  
    485   ### NOW WRITE TRUNKS.. WE START WITH ZAP TRUNKS DEFINED ABOVE 
    486  
    487  
    488  
    489  
    490   $btn=0; 
    491  
    492   foreach ($zaplines as $row) { 
    493     $zapdef=$row[0]; 
    494     $zapdesc=$row[1]; 
    495     $icon='3'; 
    496     # zaplines and trunklist share the trunk positions so need to store previous btn on overflow from zaplines 
    497     $previousbtn = $btn; 
    498     $btn=get_next_btn($trunkpos,$btn); 
    499     if ($btn == 0) {$btn = $previousbtn; break;} 
    500     if ($zapdef == "Zap/*") { 
    501       $numbuttons=$row[2]-1; 
    502       fwrite($fhandle, "\n[$zapdef]\nLabel=\"$zapdesc\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\nPosition=".$btn); 
    503       while($numbuttons-->0) { 
    504         $btn=get_next_btn($trunkpos,$btn); 
    505         fwrite($fhandle, ",".$btn); 
    506       } 
    507  
    508       fwrite($fhandle, "\n"); 
    509     } else { 
    510       fwrite($fhandle, "\n[$zapdef]\nPosition=$btn\nLabel=\"$zapdesc\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
    511     } 
    512   } 
    513  
    514  
    515   foreach ($trunklist as $row) { 
    516     $account = $row[0]; 
    517     $id = $row[1]; 
    518     $table = $row[2]; 
    519     if ($account == "") {continue;}; 
    520     $btn=get_next_btn($trunkpos,$btn); 
    521     if ($btn == 0) {break;} 
    522     if (table_exists($db,$table)) { 
    523     $statement = "SELECT keyword,data from $table where id='$id' and keyword <> 'account' and flags <> 1 order by keyword"; 
    524       $results = $db->getAll($statement); 
    525       if(DB::IsError($results)) { 
    526          die($results->getMessage()); 
    527       } 
    528       if (count($results) < 1) { 
    529         print "Notice: no Trunks defined\n"; 
    530       } 
    531     } else { print "Table does not exist: $table \n"; } 
    532  
    533     if ($table == "sip") {$tech="SIP";} 
    534     if ($table == "iax") {$tech="IAX2";} 
    535     #if ($table == "zap") {$tech="ZAP";} #no zap trunks in db 
    536  
    537     $callerid = $account;  #default callerid to account 
    538  
    539     foreach ($results as $drow) { 
    540       if ( $drow[0] == "callerid" ) { 
    541         $callerid = $drow[1]; 
    542         $fields = explode("<",$callerid); 
    543         $callerid=$fields[1] ." ". $fields[0]; 
    544         $callerid = str_replace("\t","",$callerid); 
    545         $callerid = str_replace("\"","",$callerid); 
    546         $callerid = str_replace("<","",$callerid); 
    547         $callerid = str_replace(">","",$callerid); 
    548       } 
    549     } 
    550     $icon='3'; 
    551     fwrite($fhandle, "\n[$tech/$account]\nPosition=$btn\nLabel=\"$callerid\"\nExtension=-1\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
    552   } 
    553  
    554  
    555   ## SME server changes 
    556  
    557  
    558  
    559         ### Write Parkings lots 
    560   $btn=0; 
    561   $parken="" ; 
    562   $extpark ; 
    563   $parkcontext ; 
    564   $numberlots ; 
    565   $maxparkingslots ; 
    566  
    567   foreach ($parkings as $row) { 
    568     if ($row[0] == "parkingenabled") { 
    569       $parken = $row[1] ; 
    570     } 
    571     if ($row[0] == "parkext") { 
    572       $extpark = $row[1] ; 
    573     } 
    574     if ($row[0] == "parkingcontext") { 
    575       $parkcontext = $row[1] ; 
    576     } 
    577     if ($row[0] == "numslots") { 
    578       $numberlots = $row[1] ; 
    579     } 
    580   } 
    581   if ($parken == "s") { 
    582     for ($i = 1 ; $i <= $numberlots ; $i++ ) { 
    583       $btn=get_next_btn($parkingpos,$btn); 
    584       if ($btn == 0) {break;} 
    585       $parknum = $extpark + $i ; 
    586       $icon='1'; 
    587       fwrite($fhandle, "\n[PARK$parknum]\nPosition=$btn\nLabel=\"Parked ($parknum)\"\nExtension=$parknum\nContext=$parkcontext\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
    588     } 
    589   } 
    590  
    591   ## End of chagnes 
    592   ### Write conferences (meetme) 
    593  
    594   $btn=0; 
    595   if ($exten_low != 0 && $exten_high != 0) {  #display only allowed range of extensions for panel_contexts 
    596     $confrange = array(); 
    597     foreach ($conferences as $value) { 
    598       if (!is_numeric($value)) {array_push($confrange,$value);} 
    599       if (($value >= $exten_low) && ($value <= $exten_high))  {array_push($confrange,$value);} 
    600     } 
    601   } else { 
    602     $confrange = $conferences; 
    603   } 
    604   foreach ($confrange as $row) { 
    605     $btn=get_next_btn($confepos,$btn); 
    606     if ($btn == 0) {break;} 
    607     $confenum=$row[0]; 
    608     $confedesc=$row[1]; 
    609     $icon='6'; 
    610     fwrite($fhandle, "\n[$confenum]\nPosition=$btn\nLabel=\"$confedesc\"\nExtension=$confenum\nContext=from-internal\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
    611   } 
    612  
    613   ### Write Queues 
    614  
    615   $btn=0; 
    616   if ($exten_low != 0 && $exten_high != 0) {  #display only allowed range of extensions for panel_contexts 
    617     $queuerange = array(); 
    618     foreach ($queues as $value) { 
    619       if (!is_numeric($value)) {array_push($queuerange,$value);} 
    620       if (($value >= $exten_low) && ($value <= $exten_high))  {array_push($queuerange,$value);} 
    621     } 
    622   } else { 
    623     $queuerange = $queues; 
    624   } 
    625   foreach ($queuerange as $row) { 
    626     $btn=get_next_btn($queuepos,$btn); 
    627     if ($btn == 0) {break;} 
    628     $queuename=$row[0]; 
    629     $queuedesc=$row[1]; 
    630     $icon='5'; 
    631     fwrite($fhandle, "\n[QUEUE/$queuename]\nPosition=$btn\nLabel=\"$queuedesc\"\nExtension=-1\nContext=from-internal\nIcon=$icon\nPanel_Context=$panelcontext\n"); 
    632   } 
    633  
    634   ### Write rectangles 
    635  
    636   foreach ($rectangles as $rect) { 
    637     $comment = $rect[0]; 
    638     $color1 = $rect[4]; 
    639     $color2 = $rect[5]; 
    640     $start = $rect[2]; 
    641     $stop = $rect[3]; 
    642  
    643     $xposition = $buttonsoriginx + $buttonsizex * floor(($start-1)/$numbuttonsy); 
    644     $yposition = $buttonsoriginy + $buttonsizey * (($start-1)%$numbuttonsy); 
    645     $xsize = $buttonsizex * (1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy)); 
    646     $ysize = $buttonsizey * (1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy)); 
    647  
    648     if (($xsize <= 0) || ($ysize <= 0)) {continue;} 
    649  
    650     $xposition += $rectmarginx; 
    651     $yposition += $rectmarginy; 
    652     $xsize -= 2 * $rectmarginx; 
    653     $ysize -= 2 * $rectmarginy; 
    654  
    655     fwrite($fhandle, "\n; $comment\n[rectangle]\nx=$xposition\ny=$yposition\nwidth=$xsize\nheight=$ysize\nline_width=0\nline_color=$color1\nfade_color1=$color1\nfade_color2=$color2\nrnd_border=2\nalpha=20\nlayer=bottom\nPanel_Context=$panelcontext\n"); 
    656   } 
    657  
    658   ### Write legends 
    659  
    660   foreach ($rectangles as $legend) { 
    661     $text = $legend[1]; 
    662     $start = $legend[2]; 
    663     $stop = $legend[3]; 
    664  
    665     $xposition = $buttonsoriginx + $buttonsizex * floor(($start-1)/$numbuttonsy); 
    666     $yposition = $buttonsoriginy + $buttonsizey * (($start-1)%$numbuttonsy); 
    667     $xsize = $buttonsizex * (1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy)); 
    668     $ysize = $buttonsizey * (1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy)); 
    669  
    670     if (($xsize <= 0) || ($ysize <= 0)) {continue;} 
    671  
    672     $xposition += $legendoffsetx; 
    673     $yposition += $legendoffsety; 
    674  
    675     fwrite($fhandle, "\n[LEGEND]\nx=$xposition\ny=$yposition\ntext=$text\nfont_size=18\nfont_family=Arial\nuse_embed_fonts=1\nPanel_Context=$panelcontext\n"); 
    676   } 
    677  
    678 
    679  
    680 function get_next_btn($data,$last) { 
    681   $rangelist=explode(",",$data); 
    682   foreach ($rangelist as $range) { 
    683     $rangeval=explode("-",$range,2); 
    684     if ($last < $rangeval[0]) {return $rangeval[0] ;} 
    685     if (isset($rangeval[1]) && ($last < $rangeval[1])) {return $last+1;} 
    686     #Need to try another range def... 
    687   } 
    688   #If we get here, we ran out of positions :( 
    689   return 0; #????? 
    690 
    691 #this sub checks for the existance of a table 
    692 function table_exists($db,$table) { 
    693          $result = mysql_query("SHOW TABLES LIKE '" . $table . "'"); 
    694          if(mysql_fetch_row($result) === false) {return(false);} 
    695          return(true); 
    696          } 
    697  
    698 function get_styleinfo($id,$layoutinfo) { 
    699 // do not use globals - instead pass layout info into function explicitly 
    700 //  global $rectangles; 
    701 //  global $numbuttonsx; 
    702 //  global $numbuttonsy; 
    703 $rectangles = $layoutinfo['rectangles']; 
    704 $numbuttonsx = $layoutinfo['numbuttonsx']; 
    705 $numbuttonsy = $layoutinfo['numbuttonsy']; 
    706  
    707  
    708   foreach ($rectangles as $rect) { 
    709     if ($id == $rect[0]) { 
    710  
    711       $start = $rect[2]; 
    712       $stop = $rect[3]; 
    713  
    714       $xposition = floor(($start-1)/$numbuttonsy); 
    715       $yposition = (($start-1)%$numbuttonsy); 
    716       $xsize = 1 + floor(($stop-1)/$numbuttonsy) - floor(($start-1)/$numbuttonsy); 
    717       $ysize = 1 + (($stop-1)%$numbuttonsy) - (($start-1)%$numbuttonsy); 
    718  
    719       if (($xsize <= 0) || ($ysize <= 0)) {print "Warning: rectange '$id' has negative area\n"; break;} 
    720       $styleinfo = ""; 
    721       if ($ysize > 2) { 
    722         $styleinfo .= ($start + 1) . "-" . ($start + $ysize - 1) . ","; 
    723       } 
    724       elseif ($ysize == 2) { 
    725         $styleinfo .= ($start + 1) . ","; 
    726       } 
    727  
    728       for ($i = 1 ; $i < $xsize ; $i++ ) { 
    729         if ($ysize > 1) { 
    730           $styleinfo .= (($i + $xposition) * $numbuttonsy + $yposition + 1) . "-" . (($i + $xposition) * $numbuttonsy + $yposition + $ysize) . ","; 
    731         } 
    732         else { 
    733           $styleinfo .= (($i + $xposition) * $numbuttonsy + $yposition + 1) . ","; 
    734         } 
    735       } 
    736       $retval = $styleinfo; 
    737       break; 
    738     } 
    739   } 
    740   return $retval; 
    741 
     793//Finished parsing zapata.conf 
    742794?> 
  • modules/branches/2.10/fw_fop/index.php

    r10122 r12802  
    11<?php 
    22 
    3 function parse_amportal_conf($filename) { 
    4   $file = file($filename); 
    5   foreach ($file as $line) { 
    6     if (preg_match("/^\s*([a-zA-Z0-9_]+)=([a-zA-Z0-9 .&-@=_!<>\"\']+)\s*$/",$line,$matches)) { 
    7       $conf[ $matches[1] ] = $matches[2]; 
    8     } 
    9   } 
    10   return $conf
     3$bootstrap_settings['freepbx_auth'] = false; 
     4// don't include any of the functions.inc.php files from modules, this CLI version of 
     5// module_admin is somtimes the only way to recover from a bad module being loaded into 
     6// a system. 
     7// 
     8$restrict_mods = true; 
     9if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) { 
     10  include_once('/etc/asterisk/freepbx.conf')
    1111} 
    12  
    13 $amp_conf = parse_amportal_conf("/etc/amportal.conf"); 
    1412 
    1513if ($amp_conf["AMPWEBADDRESS"] == "") 
  • modules/branches/2.10/fw_fop/install.php

    r11109 r12802  
    1717//   Copyright 2006 FreePBX 
    1818// 
    19 // HELPER FUNCTIONS: 
    20  
    21 function fw_fop_print_errors($src, $dst, $errors) { 
    22   echo "error copying fw_fop files:<br />'cp -rf' from src: '$src' to dst: '$dst'...details follow<br />"; 
    23   foreach ($errors as $error) { 
    24     echo "$error<br />"; 
    25   } 
    26 } 
    2719 
    2820global $amp_conf; 
    2921global $asterisk_conf; 
    3022 
    31 $debug = false; 
    32 $dryrun = false; 
     23$freepbx_conf =& freepbx_conf::create(); 
    3324 
    34 /** verison_compare that works with freePBX version numbers 
    35  *  included here because there are some older versions of functions.inc.php that do not have 
    36  *  it included as it was added during 2.3.0beta1 
    37  */ 
    38 if (!function_exists('version_compare_freepbx')) { 
    39   function version_compare_freepbx($version1, $version2, $op = null) { 
    40     $version1 = str_replace("rc","RC", strtolower($version1)); 
    41     $version2 = str_replace("rc","RC", strtolower($version2)); 
    42     if (!is_null($op)) { 
    43       return version_compare($version1, $version2, $op); 
    44     } else { 
    45       return version_compare($version1, $version2); 
    46     } 
    47   } 
    48 
     25// 
     26// CATEGORY: Flash Operator Panel 
     27// 
     28$set['category'] = 'Flash Operator Panel'; 
     29$set['level'] = 0; 
     30$set['module'] = 'fw_fop'; 
    4931 
    50 /* 
    51  * fw_fop install script 
    52  */ 
    53   $bin_source = dirname(__FILE__)."/bin/*"; 
    54   $bin_dest = $amp_conf['AMPBIN']; 
     32// FOPSORT 
     33$set['value'] = 'extension'; 
     34$set['defaultval'] =& $set['value']; 
     35$set['options'] = 'extension,lastname'; 
     36$set['readonly'] = 0; 
     37$set['hidden'] = 0; 
     38$set['emptyok'] = 0; 
     39$set['name'] = 'FOP Sort Mode'; 
     40$set['description'] = 'How FOP sort extensions. By Last Name [lastname] or by Extension [extension].'; 
     41$set['type'] = CONF_TYPE_SELECT; 
     42$freepbx_conf->define_conf_setting('FOPSORT',$set); 
    5543 
    56   $htdocs_panel_source = dirname(__FILE__)."/htdocs_panel/*"; 
     44// FOPPASSWORD 
     45$set['value'] = 'passw0rd'; 
     46$set['defaultval'] =& $set['value']; 
     47$set['options'] = ''; 
     48$set['readonly'] = 0; 
     49$set['hidden'] = 0; 
     50$set['emptyok'] = 0; 
     51$set['name'] = 'FOP Password'; 
     52$set['description'] = 'Password for performing transfers and hangups in the Flash Operator Panel (FOP).'; 
     53$set['type'] = CONF_TYPE_TEXT; 
     54$freepbx_conf->define_conf_setting('FOPPASSWORD',$set); 
    5755 
    58   if (!file_exists(dirname($htdocs_panel_source))) { 
    59     out(sprintf(_("No directory %s, install script not needed"),dirname($htdocs_panel_source))); 
    60     return true; 
    61   } 
     56$fopwebroot = dirname(__FILE__); 
     57$freepbx_conf->set_conf_values(array('FOPWEBROOT',$fopwebroot), true, true); 
    6258 
    63   // There was a past bug where FOPWEBROOT was pointing to AMPWEBROOT so if that is the case then hardcode 
    64   // and force to panel here. 
    65   // 
    66   $htdocs_panel_dest = $amp_conf['FOPWEBROOT']; 
    67   if ($htdocs_panel_dest == $amp_conf['AMPWEBROOT']) { 
    68     $htdocs_panel_dest .= "/panel"; 
    69   } 
    70  
    71   exec("cp -rf $htdocs_panel_source $htdocs_panel_dest 2>&1",$out,$ret); 
    72   if ($ret != 0) { 
    73     fw_fop_print_errors($htdocs_panel_source, $htdocs_panel_dest, $out); 
    74   } 
    75  
    76   exec("cp -rf $bin_source $bin_dest 2>&1",$out,$ret); 
    77   if ($ret != 0) { 
    78     fw_fop_print_errors($htdocs_panel_source, $bin_dest, $out); 
    79   } 
    80  
     59// remove deprecated settings 
     60$freepbx_conf->remove_conf_settings(array('FOPRUN','FOPDISABLE')); 
    8161?> 
  • modules/branches/2.10/fw_fop/module.xml

    r12622 r12802  
    11<module> 
    22  <rawname>fw_fop</rawname> 
    3   <modtype>framework</modtype> 
    4   <repo>standard</repo> 
     3  <repo>unsupported</repo> 
    54  <name>FreePBX FOP Framework</name> 
    65  <version>2.10.0.beta1.0</version> 
    76  <publisher>FreePBX</publisher> 
    87  <license>GPLv2+</license> 
    9   <candisable>no</candisable> 
    10   <canuninstall>no</canuninstall> 
     8  <menuitems> 
     9    <fw_fop category="Op Panel" href="modules/fw_fop/" target="_fop" access="all">FOP Panel</fw_fop> 
     10  </menuitems> 
    1111  <changelog> 
    1212    *2.10.0beta1.0* beta1 release, see svn log