Code

First Multi server asterisk update
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 21 Dec 2006 03:51:06 +0000 (03:51 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 21 Dec 2006 03:51:06 +0000 (03:51 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@5451 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_config.inc
plugins/gofon/phoneaccount/class_phoneAccount.inc
plugins/gofon/phoneaccount/generic.tpl

index 938f9a07177a01f630752285a0f9c57f3a4104fe..7a3a5bfd3bb4d2d79a26451dbb77ccb2e260a521 100644 (file)
@@ -379,16 +379,34 @@ class config  {
     $this->data['SERVERS']['FON']= array(); 
     if ($ldap->count()){
       while ($attrs= $ldap->fetch()){
-        $this->data['SERVERS']['FON'][]= array( 
-            'SERVER'   => $attrs['cn'][0],
-            'LOGIN'    => $attrs['goFonAdmin'][0],
-            'PASSWORD'         => $attrs['goFonPassword'][0],
-            'DB'               => "gophone",
-            'SIP_TABLE'                => "sip_users",
-            'EXT_TABLE'        => "extensions",
-            'VOICE_TABLE'      => "voicemail_users",
-            'QUEUE_TABLE'      => "queues",
-            'QUEUE_MEMBER_TABLE'       => "queue_members");
+
+        /* Add 0 entry for development */
+        if(count($this->data['SERVERS']['FON']) == 0){
+          $this->data['SERVERS']['FON'][0]= array(
+              'DN'      => $attrs['dn'],
+              'SERVER'         => $attrs['cn'][0],
+              'LOGIN'  => $attrs['goFonAdmin'][0],
+              'PASSWORD'       => $attrs['goFonPassword'][0],
+              'DB'             => "gophone",
+              'SIP_TABLE'              => "sip_users",
+              'EXT_TABLE'      => "extensions",
+              'VOICE_TABLE'    => "voicemail_users",
+              'QUEUE_TABLE'    => "queues",
+              'QUEUE_MEMBER_TABLE'     => "queue_members");
+        }
+
+        /* Add entry with 'dn' as index */
+        $this->data['SERVERS']['FON'][$attrs['dn']]= array(
+            'DN'      => $attrs['dn'],
+            'SERVER'  => $attrs['cn'][0],
+            'LOGIN'   => $attrs['goFonAdmin'][0],
+            'PASSWORD'  => $attrs['goFonPassword'][0],
+            'DB'    => "gophone",
+            'SIP_TABLE'   => "sip_users",
+            'EXT_TABLE'   => "extensions",
+            'VOICE_TABLE' => "voicemail_users",
+            'QUEUE_TABLE' => "queues",
+            'QUEUE_MEMBER_TABLE'  => "queue_members");
       }
     }
 
index 87985ba3e1b793d0960ffead3648e18bcc915ffd..10f792748b0256184bb493aca2d5b604a5cf913d 100644 (file)
@@ -27,6 +27,9 @@ class phoneAccount extends plugin
   var $generate_error         = "";
   var $a_old_telenums         = array();
   var $goFonPINVoice          = "";
+  var $goFonHomeServer        = "0";            // Contains the dn of the server that manage this account 
+  var $goFonHomeServers       = array();        // Contains all available server configurations 
+    
 
   /* CLI vars */
   var $cli_summary            = "Manage users phone account";
@@ -37,7 +40,7 @@ class phoneAccount extends plugin
   var $CopyPasteVars          = array("phoneNumbers","macroarray","macrostillavailable"/*"phoneNumbers" -Reset- */,
                                       "hardware_list","used_hardware");
 
-  var $attributes             = array("goFonDeliveryMode", "goFonFormat","uid","cn",
+  var $attributes             = array("goFonDeliveryMode", "goFonFormat","uid","cn","goFonHomeServer",
       "goFonHardware","goFonPIN","goFonVoicemailPIN","telephoneNumber", "goFonMacro","macro");
   var $objectclasses= array("goFonAccount");
 
@@ -78,17 +81,29 @@ class phoneAccount extends plugin
        array_key_exists('FON',$_SESSION['config']->data['SERVERS']) &&
        is_callable("mysql_connect")
        ) {
-      $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'][0];
-      $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
+
+      /* Set available server */
+      $this->goFonHomeServers = $_SESSION['config']->data['SERVERS']['FON'];
+
+      /* Set default server */
+      if($this->dn == "new"){
+        $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
+      }
+
+      /* get config */
+      $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer];
+     
+
+      $r_con =  @mysql_pconnect($cur_cfg['SERVER'],$cur_cfg['LOGIN'],$cur_cfg['PASSWORD']);
       if(!$r_con){
         $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
-          $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
+          $cur_cfg['SERVER'],$cur_cfg['LOGIN']);
         gosa_log(mysql_error());
         return false;
       }
-      $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
+      $db  =  @mysql_select_db($cur_cfg['DB'],$r_con);
       if(!$db){
-        $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
+        $this->generate_error = sprintf(_("Can't select database %s on %s."),$cur_cfg['DB'],$cur_cfg['SERVER']);
         gosa_log(mysql_error());
         return false;
       }
@@ -228,11 +243,11 @@ class phoneAccount extends plugin
      * This means, the PIN in the DB is up to date
      */
     // Connect to DB server
-    if((is_callable("mysql_pconnect"))&&(isset($a_SETUP))&&(isset($a_SETUP['SERVER']))&&(isset($a_SETUP['LOGIN']))&&(isset($a_SETUP['PASSWORD']))){
-      $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
+    if((is_callable("mysql_pconnect"))&&(isset($cur_cfg))&&(isset($cur_cfg['SERVER']))&&(isset($cur_cfg['LOGIN']))&&(isset($cur_cfg['PASSWORD']))){
+      $r_con =  @mysql_pconnect($cur_cfg['SERVER'],$cur_cfg['LOGIN'],$cur_cfg['PASSWORD']);
       if($r_con){
-        $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
-        $vp = mysql_fetch_row(mysql_query("SELECT ".$a_SETUP['VOICE_TABLE'].".password FROM  ".$a_SETUP['VOICE_TABLE'].", ".$a_SETUP['SIP_TABLE']."  WHERE customer_id = sip_users.mailbox AND name='".$this->uid."'"));
+        $r_db  =  @mysql_select_db($cur_cfg['DB'],$r_con);
+        $vp = mysql_fetch_row(mysql_query("SELECT ".$cur_cfg['VOICE_TABLE'].".password FROM  ".$cur_cfg['VOICE_TABLE'].", ".$cur_cfg['SIP_TABLE']."  WHERE customer_id = sip_users.mailbox AND name='".$this->uid."'"));
 
         if((isset($vp[0]))&&(!empty($vp[0]))){
           $this->goFonPINVoice = $vp[0];
@@ -248,14 +263,19 @@ class phoneAccount extends plugin
 
 
   // Generate MySQL Syntax
-  function generate_mysql_entension_entries($save = false){
-
-    if(!isset($_SESSION['config']->data['SERVERS']['FON'][0])){
-      if($save)
-      print_red(_("There is currently no asterisk server defined. Possibly you are missing a server that handles the asterisk management (goFonServer). Your settings can't be saved to asterisk database."));
+  function generate_mysql_entension_entries($save = false)
+  {
+    /* Check if there is at least one server available 
+       If not, return and tell the user that saving failed 
+     */
+    if(!count($this->goFonHomeServers)){
+      if($save){
+        print_red(_("There is currently no asterisk server defined. Possibly you are missing a server that handles the asterisk management (goFonServer). Your settings can't be saved to asterisk database."));
+      }
       return(true);
     }
 
+    /* Check if Mysql extension is available */
     if(!is_callable("mysql_pconnect")){
       if($save)
       print_red(_("Can't save any changes to asterisk database, there is no mysql extension available."));
@@ -263,7 +283,7 @@ class phoneAccount extends plugin
     }
   
     // Get Configuration for Mysql database Server
-    $a_SETUP        = $_SESSION['config']->data['SERVERS']['FON'][0];  // DB Configuration
+    $a_SETUP        = $this->goFonHomeServers[$this->goFonHomeServer];  // DB Configuration
     $s_parameter    = "";                                           // Contains paramter for selected Macro 
     $r_con          = false;                                        // DB connection
     $r_db           = false;                                        // Selected DB
@@ -574,8 +594,8 @@ class phoneAccount extends plugin
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* Call parent execute */
+    plugin::execute();
 
     $display = "";
 
@@ -646,7 +666,7 @@ class phoneAccount extends plugin
     $smarty->assign("macro", $this->macro);   
 
     /* check if there is a FON server created */
-    if(!isset($_SESSION['config']->data['SERVERS']['FON'][0])){
+    if(!count($this->goFonHomeServer)){
       print_red(_("There is currently no asterisk server defined. Possibly you are missing a server that handles the asterisk management (goFonServer). Your settings can't be saved to asterisk database."));
     }
 
@@ -795,6 +815,15 @@ class phoneAccount extends plugin
       }
     }
 
+    /* Create home server array */
+    $tmp = array();
+    foreach($this->goFonHomeServers as $dn => $attrs){
+      if(!is_numeric($dn)){
+        $tmp[$dn] = $attrs['SERVER'];
+      }
+    }
+    $smarty->assign("goFonHomeServers",$tmp);
+
     /* Fill arrays */
     $smarty->assign ("goFonHardware", $this->goFonHardware);
     if (!count($this->phoneNumbers)){
@@ -1026,12 +1055,10 @@ class phoneAccount extends plugin
         unset($this->$val);
       }
     }
-    if(array_key_exists('config', $_SESSION) &&
-       array_key_exists('SERVERS', $_SESSION['config']->data) &&
-       array_key_exists('FON', $_SESSION['config']->data['SERVERS']) &&
-        is_callable("mysql_pconnect")) {
+    if(count($this->goFonHomeServers) && !empty($this->goFonHomeServer) && is_callable("mysql_pconnect")){
+
       // Get Configuration for Mysql database Server
-      $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'][0];
+      $a_SETUP = $this->goFonHomeServers[$this->goFonHomeServer];
       $s_parameter  ="";
 
       // Connect to DB server
index e61865f2d270aca0d9208f84010e679722288a32..48414e80e79eb08c91c37e7c1e10cb14c0202774 100644 (file)
     <tr>
      <td>{t}Telephone{/t}</td>
      <td>{$hardware_list}</td>
+    </tr>
+    <tr>
+     <td>{t}Home server{/t}
+     </td>
+     <td>
+      <select name='goFonHomeServer' title='{t}Select the accounts home server{/t}'> 
+       {html_options options=$goFonHomeServers selected=$goFonHomeServer}
+      </select>        
+     </td>
     </tr>
                        <tr>
                                <td>