Changeset 2109

Show
Ignore:
Timestamp:
06/28/06 07:35:05 (7 years ago)
Author:
diego_iastrubni
Message:

indentation and cleanups

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/htdocs/admin/modules/core/functions.inc.php

    r2101 r2109  
    1616      foreach ($vmcontexts as $vmcontext) { 
    1717        if(isset($uservm[$vmcontext][$extnum])){ 
    18         // $vmname = $uservm[$vmcontext][$extnum]['name']; 
    19         // $vmboxes[$extnum] = array($extnum, '"' . $vmname . '" <' . $extnum . '>'); 
    20         $vmboxes[$extnum] = true; 
     18        //$vmname = $uservm[$vmcontext][$extnum]['name']; 
     19        //$vmboxes[$extnum] = array($extnum, '"' . $vmname . '" <' . $extnum . '>'); 
     20        $vmboxes[$extnum] = true; 
    2121        } 
    2222      } 
     
    2727  // core provides both users and voicemail boxes as destinations 
    2828  if (isset($results)) { 
    29     foreach($results as $result)
    30       $extens[] = array('destination' => 'ext-local,'.$result['0'].',1', 'description' => $result['1'].' <'.$result['0'].'>'); 
    31       if(isset($vmboxes[$result['0']])) { 
    32         $extens[] = array('destination' => 'ext-local,${VM_PREFIX}'.$result['0'].',1', 'description' => 'voicemail box '.$result['0']); 
    33      
     29    foreach($results as $result)
     30      $extens[] = array('destination' => 'ext-local,'.$result['0'].',1', 'description' => $result['1'].' <'.$result['0'].'>'); 
     31      if(isset($vmboxes[$result['0']])) { 
     32        $extens[] = array('destination' => 'ext-local,${VM_PREFIX}'.$result['0'].',1', 'description' => 'voicemail box '.$result['0']); 
     33     
    3434    } 
    3535  } 
     
    516516    else  
    517517      $vmcontext = $thisUser['voicemail']; 
     518     
    518519    //voicemail symlink 
    519520    exec("rm -f /var/spool/asterisk/voicemail/device/".$id); 
     
    550551    $deviceuser = $astman->database_get("DEVICE",$account."/user"); 
    551552    if (isset($deviceuser) && $deviceuser != "none") { 
    552         // Remove the device record from the user's device list 
    553         $userdevices = $astman->database_get("AMPUSER",$deviceuser."/device"); 
    554         /*$userdevices = str_replace($account."&", "", $userdevices."&"); 
    555         // If there was more than one device, remove the extra "&" at the end. 
    556         if (substr($userdevices, -1, 1) == "&") { 
    557           $userdevices = substr($userdevices, 0, -1); 
    558         }*/ 
    559                                 $userdevicesarr = explode("&", $userdevices); 
    560                                 array_splice($userdevicesarr, array_search($account, $userdevicesarr), 1); 
    561                                 $userdevices = implode("&", $userdevicesarr); 
    562         if (empty($userdevices)) { 
    563             $astman->database_del("AMPUSER",$deviceuser."/device"); 
    564         } else { 
    565             $astman->database_put("AMPUSER",$deviceuser."/device",$userdevices); 
    566         } 
     553      // Remove the device record from the user's device list 
     554      $userdevices = $astman->database_get("AMPUSER",$deviceuser."/device"); 
     555      /*$userdevices = str_replace($account."&", "", $userdevices."&"); 
     556       
     557      // If there was more than one device, remove the extra "&" at the end. 
     558      if (substr($userdevices, -1, 1) == "&") { 
     559        $userdevices = substr($userdevices, 0, -1); 
     560      }*/ 
     561      $userdevicesarr = explode("&", $userdevices); 
     562      array_splice($userdevicesarr, array_search($account, $userdevicesarr), 1); 
     563      $userdevices = implode("&", $userdevicesarr); 
     564       
     565      if (empty($userdevices)) { 
     566          $astman->database_del("AMPUSER",$deviceuser."/device"); 
     567      } else { 
     568          $astman->database_put("AMPUSER",$deviceuser."/device",$userdevices); 
     569      } 
    567570    } 
    568571    $astman->database_del("DEVICE",$account."/dial"); 
     
    596599  //take care of sip/iax/zap config 
    597600  $funct = "core_devices_get".strtolower($results['tech']); 
    598   if(!empty($results['tech']) && function_exists($funct))
     601  if (!empty($results['tech']) && function_exists($funct))
    599602    $devtech = $funct($account); 
    600603    if (is_array($devtech)){ 
     
    617620  //add details to astdb 
    618621  $astman = new AGI_AsteriskManager(); 
    619   if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {  
     622  if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) { 
    620623    $astman->database_deltree("DEVICE"); 
    621624    foreach($devresults as $dev) { 
     
    711714    die($result->getDebugInfo()."<br><br>".'error adding to SIP table');   
    712715  } 
    713         
    714  
    715   //script to write sip conf file from mysql 
    716   //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_sip_conf_from_mysql.pl'; 
    717   //exec($wScript); 
    718  
    719716} 
    720717 
     
    722719  global $db; 
    723720  global $currentFile; 
    724     $sql = "DELETE FROM sip WHERE id = '$account'"; 
    725     $result = $db->query($sql); 
    726     if(DB::IsError($result)) { 
    727         die($result->getMessage().$sql); 
    728   } 
    729  
    730   //script to write sip conf file from mysql 
    731   //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_sip_conf_from_mysql.pl'; 
    732   //exec($wScript); 
    733   //script to write op_server.cfg file from mysql  
    734   //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 
    735   //exec($wOpScript); 
     721   
     722  $sql = "DELETE FROM sip WHERE id = '$account'"; 
     723  $result = $db->query($sql); 
     724   
     725  if(DB::IsError($result)) { 
     726    die($result->getMessage().$sql); 
     727  } 
    736728} 
    737729 
     
    743735    $results = null; 
    744736  } 
     737   
    745738  return $results; 
    746739} 
     
    750743  global $db; 
    751744  global $currentFile; 
     745   
    752746  $iaxfields = array(array($account,'account',$account), 
    753747  array($account,'secret',($_REQUEST['secret'])?$_REQUEST['secret']:''), 
     
    771765  if(DB::IsError($result)) { 
    772766    die($result->getMessage()."<br><br>error adding to IAX table");  
    773   }  
    774  
    775  
    776   //script to write iax2 conf file from mysql 
    777   //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_iax_conf_from_mysql.pl'; 
    778   //exec($wScript); 
    779   //script to write op_server.cfg file from mysql  
    780   //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 
    781   //exec($wOpScript); 
     767  } 
    782768} 
    783769 
     
    785771  global $db; 
    786772  global $currentFile; 
    787     $sql = "DELETE FROM iax WHERE id = '$account'"; 
    788     $result = $db->query($sql); 
    789     if(DB::IsError($result)) { 
    790         die($result->getMessage().$sql); 
    791   } 
    792    
    793   //script to write iax2 conf file from mysql 
    794   //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_iax_conf_from_mysql.pl'; 
    795   //exec($wScript); 
    796   //script to write op_server.cfg file from mysql  
    797   //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 
    798   //exec($wOpScript); 
     773   
     774  $sql = "DELETE FROM iax WHERE id = '$account'"; 
     775  $result = $db->query($sql); 
     776   
     777  if(DB::IsError($result)) { 
     778    die($result->getMessage().$sql); 
     779  } 
    799780} 
    800781 
     
    806787    $results = null; 
    807788  } 
     789   
    808790  return $results; 
    809791} 
     
    812794  global $db; 
    813795  global $currentFile; 
     796   
    814797  $zapfields = array( 
    815798  array($account,'account',$account), 
     
    833816  if(DB::IsError($result)) { 
    834817    die($result->getMessage()."<br><br>error adding to ZAP table");  
    835   }  
    836  
    837  
    838   //script to write zap conf file from mysql 
    839   //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_zap_conf_from_mysql.pl'; 
    840   //exec($wScript); 
    841   //script to write op_server.cfg file from mysql  
    842   //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 
    843   //exec($wOpScript); 
     818  } 
    844819} 
    845820 
     
    847822  global $db; 
    848823  global $currentFile; 
    849     $sql = "DELETE FROM zap WHERE id = '$account'"; 
    850     $result = $db->query($sql); 
    851     if(DB::IsError($result)) { 
    852         die($result->getMessage().$sql); 
    853   } 
    854    
    855   //script to write zap conf file from mysql 
    856   //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_zap_conf_from_mysql.pl'; 
    857   //exec($wScript); 
    858   //script to write op_server.cfg file from mysql  
    859   //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 
    860   //exec($wOpScript); 
     824   
     825  $sql = "DELETE FROM zap WHERE id = '$account'"; 
     826  $result = $db->query($sql); 
     827  if(DB::IsError($result)) { 
     828    die($result->getMessage().$sql); 
     829  } 
    861830} 
    862831 
     
    917886    } 
    918887  } 
     888   
    919889  if (isset($extens)) { 
    920890    sort($extens); 
     
    10441014    $vmoption = explode("=",$delete); 
    10451015      $vmoptions[$vmoption[0]] = $vmoption[1]; 
     1016       
    10461017    $uservm[$vmcontext][$extension] = array( 
    1047                   'mailbox' => $extension,  
    1048                   'pwd' => $vmpwd, 
    1049                   'name' => $name, 
    1050                   'email' => $email, 
    1051                   'pager' => $pager, 
    1052                   'options' => $vmoptions); 
     1018      'mailbox' => $extension,  
     1019      'pwd' => $vmpwd, 
     1020      'name' => $name, 
     1021      'email' => $email, 
     1022      'pager' => $pager, 
     1023      'options' => $vmoptions 
     1024    ); 
    10531025  } 
    10541026  saveVoicemail($uservm); 
     
    10611033  $results = $db->getRow($sql,DB_FETCHMODE_ASSOC); 
    10621034  if(DB::IsError($results)) { 
    1063         die($results->getMessage().$sql); 
    1064   } 
     1035    die($results->getMessage().$sql); 
     1036  } 
     1037   
    10651038  //explode recording vars 
    10661039  $recording = explode("|",$results['recording']); 
     
    10811054  $results = $db->query($sql); 
    10821055  if(DB::IsError($results)) { 
    1083         die($results->getMessage().$sql); 
     1056   die($results->getMessage().$sql); 
    10841057  } 
    10851058 
     
    11031076  unset($uservm[$incontext][$extension]); 
    11041077  saveVoicemail($uservm); 
     1078   
    11051079  /*   
    11061080  //delete the extension info from extensions table 
     
    13161290  { 
    13171291    // TODO: sqlite work arround - diego  
     1292    // need to reorder the trunks in PHP code 
    13181293    $unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable","getAll");  
    13191294  } 
     
    16731648  $routepriority = array_values($routepriority); // resequence our numbers 
    16741649  $counter=0; 
    1675   foreach ($routepriority as $tresult)  
    1676   { 
     1650  foreach ($routepriority as $tresult) { 
    16771651    $order=core_routing_setroutepriorityvalue($counter++); 
    16781652    $sql = sprintf("Update extensions set context='outrt-%s-%s' WHERE context='outrt-%s'",$order,substr($tresult[0],4), $tresult[0]); 
     
    16821656    } 
    16831657  } 
     1658   
    16841659  // Delete and readd the outbound-allroutes entries 
    16851660  $sql = "delete from  extensions WHERE context='outbound-allroutes'"; 
     
    16881663          die($result->getMessage().$sql); 
    16891664  } 
     1665   
    16901666  $sql = "SELECT DISTINCT context FROM extensions WHERE context like 'outrt-%' ORDER BY context"; 
    16911667  $results = $db->getAll($sql); 
     
    17111687    } 
    17121688  } 
     1689   
    17131690  $sql = "SELECT DISTINCT SUBSTRING(context,7) FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context "; 
    17141691        // we SUBSTRING() to remove "outrt-" 
    17151692        $routepriority = $db->getAll($sql); 
    1716         if(DB::IsError($routepriority)) 
    1717         { 
     1693        if(DB::IsError($routepriority)) { 
    17181694                die($routepriority->getMessage()); 
    17191695        } 
     
    17511727  } 
    17521728   
    1753   if ($method=="new") 
    1754   {  
    1755             $sql="select DISTINCT context FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context"; 
    1756             $routepriority = $db->getAll($sql); 
    1757             if(DB::IsError($result)) { 
    1758                     die($result->getMessage()); 
    1759             } 
    1760             $order=core_routing_setroutepriorityvalue(count($routepriority)); 
    1761     $name = sprintf ("%s-%s",$order,$name); 
     1729  if ($method=="new") {  
     1730    $sql="select DISTINCT context FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context"; 
     1731    $routepriority = $db->getAll($sql); 
     1732    if(DB::IsError($result)) { 
     1733      die($result->getMessage()); 
     1734    } 
     1735    $order=core_routing_setroutepriorityvalue(count($routepriority)); 
     1736    $name = sprintf ("%s-%s",$order,$name); 
    17621737  } 
    17631738  $trunks = array_values($trunks); // probably already done, but it's important for our dialplan 
     
    17651740   
    17661741  foreach ($patterns as $pattern) { 
    1767      
    17681742    if (false !== ($pos = strpos($pattern,"|"))) { 
    17691743      // we have a | meaning to not pass the digits on 
     
    17861760    // 1st priority is emergency dialing variable (if set) 
    17871761    if(!empty($emergency)) { 
    1788          $startpriority = 1; 
    1789          $sql = "INSERT INTO extensions (context, extension, priority, application, args, descr) VALUES "; 
    1790          $sql .= "('outrt-".$name."', "; 
    1791          $sql .= "'".$pattern."', "; 
    1792          $sql .= "'".$startpriority."', "; 
    1793          $sql .= "'SetVar', "; 
    1794          $sql .= "'EMERGENCYROUTE=YES', "; 
    1795          $sql .= "'Use Emergency CID for device')"; 
    1796          $result = $db->query($sql); 
    1797       if(DB::IsError($result)) { 
    1798             die($result->getMessage()); 
    1799      
     1762      $startpriority = 1; 
     1763      $sql = "INSERT INTO extensions (context, extension, priority, application, args, descr) VALUES "; 
     1764      $sql .= "('outrt-".$name."', "; 
     1765      $sql .= "'".$pattern."', "; 
     1766      $sql .= "'".$startpriority."', "; 
     1767      $sql .= "'SetVar', "; 
     1768      $sql .= "'EMERGENCYROUTE=YES', "; 
     1769      $sql .= "'Use Emergency CID for device')"; 
     1770      $result = $db->query($sql); 
     1771      if(DB::IsError($result)) { 
     1772        die($result->getMessage()); 
     1773     
    18001774    } else { 
    1801          $startpriority = 0; 
     1775      $startpriority = 0; 
    18021776    } 
    18031777 
     
    20001974    $password = ""; 
    20011975  } 
     1976   
    20021977  return $password; 
    2003    
    20041978} 
    20051979 
    20061980//get emergency state for this route 
    20071981function core_routing_getrouteemergency($route) { 
    2008        global $db; 
    2009        $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'EMERGENCYROUTE%') "; 
    2010        $results = $db->getOne($sql); 
    2011        if(DB::IsError($results)) { 
    2012                die($results->getMessage()); 
    2013        } 
    2014        if (preg_match('/^.*=(.*)/', $results, $matches)) { 
    2015                $emergency = $matches[1]; 
    2016        } else { 
    2017                $emergency = ""; 
    2018        } 
    2019        return $emergency; 
     1982  global $db; 
     1983  $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'EMERGENCYROUTE%') "; 
     1984  $results = $db->getOne($sql); 
     1985  if(DB::IsError($results)) { 
     1986    die($results->getMessage()); 
     1987  } 
     1988  if (preg_match('/^.*=(.*)/', $results, $matches)) { 
     1989    $emergency = $matches[1]; 
     1990  } else { 
     1991    $emergency = ""; 
     1992  } 
     1993   
     1994  return $emergency; 
    20201995} 
    20211996