Code

Added asterisl multi server to ogroup queue
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 10 Jan 2007 11:13:21 +0000 (11:13 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 10 Jan 2007 11:13:21 +0000 (11:13 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@5512 594d385d-05f5-0310-b6e9-bd551577e9d8

plugins/admin/ogroups/class_phonequeue.inc
plugins/admin/ogroups/phonequeue.tpl
plugins/admin/ogroups/tabs_ogroups.inc

index 013407a3838b37f2f9f566714d0ceebf95836276..6355f05b7d771996d20c55c19ff707cbefea4762 100644 (file)
@@ -5,17 +5,17 @@ class phonequeue extends plugin
   /* plugin specific values */
   var $mail= "";
   var $cn= "";
-
+  var $old_cn ="";
 
   var $goFonTimeOut             ="20"; 
   var $goFonMaxLen              ="20"; // 
   var $goFonAnnounceFrequency   ="60"; // Annouce Frequency in seconds
-  var $goFonDialOptiont        ="";
-  var $goFonDialOptionT        ="";
-  var $goFonDialOptionh        ="";
-  var $goFonDialOptionr        ="";
+  var $goFonDialOptiont         ="";
+  var $goFonDialOptionT         ="";
+  var $goFonDialOptionh         ="";
+  var $goFonDialOptionr         ="";
+  var $goFonDialOptionH         ="";
   var $goFonQueueAnnounce       ="gonicus-berlin-welcome";
-  var $goFonDialOptionH        ="";
   var $goFonMusiconHold         ="default";
   var $goFonWelcomeMusic        ="gonicus-berlin-welcome";
   var $goFonQueueReportHold     ="yes";
@@ -37,72 +37,163 @@ class phonequeue extends plugin
   var $goFonQueueStrategyOptions=array();
   var $goFonQueueStrategyOptionsR=array();
   
-
   var $old_phone_numbers        =array();
 
+  var $goFonHomeServer  = "0";
+  var $init_HomeServer  = "0";
+  var $goFonHomeServers = array();
+
   /* attribute list for save action */
   var $attributes= array( "goFonTimeOut","goFonMaxLen","goFonAnnounceFrequency","goFonDialOptiont","goFonDialOptionT",
-      "goFonDialOptionh","goFonDialOptionr","cn",
+      "goFonDialOptionh","goFonDialOptionr","cn","goFonHomeServer",
       "goFonDialOptionH","goFonMusiconHold","goFonWelcomeMusic","goFonQueueReportHold","goFonQueueYouAreNext",
       "goFonQueueThereAre","goFonQueueCallsWaiting","goFonQueueThankYou","goFonQueueMinutes","goFonQueueSeconds","goFonQueueLessThan",
       "telephoneNumber","goFonQueueLanguage","goFonQueueStrategy","goFonQueueAnnounceHoldtime","goFonQueueAnnounce","goFonDialOption","goFonQueueRetry");
+
   /* ObjectClass */
   var $objectclasses= array("goFonQueue");
 
+
+
+  /* Pluigin initialization 
+   * - Check currently selected and available home server.
+   * - Set default home server if necessary
+   * - Parse phone options flags
+   * - Get phone numbers 
+   */
   function phonequeue ($config, $dn= NULL)
   {
     plugin::plugin($config, $dn);
 
-    /* Include config object */
-    $this->config= $config;
+    /* Check server configurations
+     * Load all server configuration in $this->goFonHomeServers if available
+     *  and use first server as default if necessary.
+     */
+    if(array_key_exists('config',$_SESSION) &&
+        array_key_exists('SERVERS',$_SESSION['config']->data) &&
+        array_key_exists('FON',$_SESSION['config']->data['SERVERS']) &&
+        count($_SESSION['config']->data['SERVERS']['FON']) &&
+        is_callable("mysql_connect")
+      ) {
+
+      /* Set available server */
+      $this->goFonHomeServers = $_SESSION['config']->data['SERVERS']['FON'];
+
+      /* Set default server */
+      if($this->dn == "new"){
+        $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
+      }
+
+      /* Remember inital home server, to be able to remove old entries */
+      $this->init_HomeServer = $this->goFonHomeServer;
+
+      /* get config */
+      if(!isset($this->goFonHomeServers[$this->goFonHomeServer])){
+        print_red(sprintf(_("The specified home server '%s' is not available in GOsa server configuration. Saving this account will create a new entry on the server '%s'. Use cancel if you do not want to create a new entry while ignoring old accounts."), preg_replace("/,/",", ",$this->goFonHomeServer), preg_replace("/,/",", ",$this->goFonHomeServers[0]['DN'])));
+        $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
+        $this->init_HomeServer = $this->goFonHomeServers[0]['DN'];
+      }
+      $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer];
+    }
 
-    /* Save initial account state */
-    $this->initially_was_account= $this->is_account;
 
+    /* Variable init  
+     *  Load phone nubmers and parse dial options 
+     */
     if($this->is_account){
       if(isset($this->attrs['telephoneNumber'])){
         $this->telephoneNumber=$this->attrs['telephoneNumber'];
         unset($this->telephoneNumber['count']); 
       }
-
       for($i = 0; $i < strlen($this->goFonDialOption); $i++){
         $name = "goFonDialOption".$this->goFonDialOption[$i];
         $this->$name=$this->goFonDialOption[$i];
       }
     }
 
-    if($this->goFonQueueAnnounceHoldtime == "no"){
+    /* Set Queue announce hold time to true/false */
+    if(preg_match("/no/i",$this->goFonQueueAnnounceHoldtime)){
       $this->goFonQueueAnnounceHoldtime=false;
+    }else{
+      $this->goFonQueueAnnounceHoldtime=true;
     }
+
+    /* Define all available ringdown types */
+    $types= array('ringall'    =>_("ring all"),
+        'roundrobin' =>_("round robin"),
+        'leastrecent'=>_("least recently called"),
+        'fewestcalls'=>_("fewest completed calls"),
+        'random'     =>_("random"),
+        'rrmemory'   =>_("round robin with memory"));
+    $i = 0;
+    foreach($types as $type => $name){
+      $i++;
+      $this->goFonQueueStrategyOptions[$i]    =$name;
+      $this->goFonQueueStrategyOptionsR[$i]   =$type;
+      $tmp[$type] = $i; 
+    }
+    $this->goFonQueueStrategy= $tmp[$this->goFonQueueStrategy];
+    $this->old_cn = $this->cn;
     $this->old_phone_numbers = $this->telephoneNumber;
+  }
 
-   $types= array('ringall'    =>_("ring all"),
-          'roundrobin' =>_("round robin"),
-          'leastrecent'=>_("least recently called"),
-          'fewestcalls'=>_("fewest completed calls"),
-          'random'     =>_("random"),
-          'rrmemory'   =>_("round robin with memory"));
-
-   $i = 0;
-   foreach($types as $type => $name){
-     $i++;
-     $this->goFonQueueStrategyOptions[$i]    =$name;
-     $this->goFonQueueStrategyOptionsR[$i]   =$type;
-     $tmp[$type] = $i; 
-   }
-  
-  $this->goFonQueueStrategy= $tmp[$this->goFonQueueStrategy];
-  
 
+  /* This function ensures that the selected home server 
+   * and the initially selected home server are reachable and accessible  
+   */
+  function check_database_accessibility()
+  {
+    /* Check if mysql extension is available */
+    if(!is_callable("mysql_pconnect")){
+      return(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup."));
+    }
+
+    /********************
+     * Check currently selected home server
+     ********************/
+
+    $cfg_Current  = $this->goFonHomeServers[$this->goFonHomeServer];
+    $r_current    =  @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
+    if(!$r_current){
+      gosa_log(@mysql_error($r_current));
+      return(sprintf(_("The MySQL home server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
+            $cfg_Current['SERVER'],$cfg_Current['LOGIN']));
+    }
+    $db_current  =  @mysql_select_db($cfg_Current['DB'],$r_current);
+    if(!$db_current){
+      gosa_log(@mysql_error($r_current));
+      mysql_close($r_current);
+      return( sprintf(_("Can't select database '%s' on home server '%s'."),$cfg_Current['DB'],$cfg_Current['SERVER']));
+    }
+
+    /********************
+     * Check init home server
+     ********************/
+
+    if($this->initially_was_account){
+      $cfg_Init  = $this->goFonHomeServers[$this->init_HomeServer] ;
+      $r_init    =  @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
+      if(!$r_init){
+        gosa_log(@mysql_error($r_init));
+        return(sprintf(_("The MySQL initial home server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
+              $cfg_Init['SERVER'],$cfg_Init['LOGIN']));
+      }
+      $db_init  =  @mysql_select_db($cfg_Init['DB'],$r_init);
+      if(!$db_init){
+        gosa_log(@mysql_error($r_init));
+        mysql_close($r_init);
+        return( sprintf(_("Can't select database '%s' on initial home server '%s'."),$cfg_Init['DB'],$cfg_Init['SERVER']));
+      }
+    }
   }
 
-
+  
+  /* Display plugin ui */
   function execute()
   {
     /* Call parent execute */
     plugin::execute();
 
-    /* Do we need to flip is_account state? */
     if(isset($_POST['modify_state'])){
       if($this->is_account && $this->acl_is_removeable()){
         $this->is_account= FALSE;
@@ -117,59 +208,60 @@ class phonequeue extends plugin
         $display= $this->show_disable_header(_("Remove the phone queue from this Account"),
             _("Phone queue is enabled for this group. You can disable it by clicking below."));
       } else {
-        $display= $this->show_enable_header(_("Create phone queue"), 
-                  _("For this group the phone queues are disabled. You can enable them by clicking below."));
+        $display= $this->show_enable_header(_("Create phone queue"),
+            _("For this group the phone queues are disabled. You can enable them by clicking below."));
         return ($display);
       }
     }
 
-    /* Add queue number */ 
     if($this->acl_is_writeable("telephoneNumber")){
+
+      /* Add queue number */ 
       if(isset($_POST['add_phonenumber'])&&(isset($_POST['phonenumber']))&&(!empty($_POST['phonenumber']))){
         if((!in_array($_POST['phonenumber'],$this->telephoneNumber))&&(is_numeric($_POST['phonenumber']))){
           $this->telephoneNumber[]=$_POST['phonenumber'];
         }
       }
-    }
 
-    /* Delete queue number */ 
-    if($this->acl_is_writeable("telephoneNumber")){
+      /* Delete queue number */ 
       if(isset($_POST['delete_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
         unset($this->telephoneNumber[$_POST['goFonQueueNumber_List']]);
       }
-    }
-  
-    $tmp = array();
-    foreach($this->telephoneNumber as $val){
-      if(!empty($val)){
-        $tmp[]= $val;
-      }
-    }  
-    $this->telephoneNumber=$tmp;
 
-    /* queue number up */ 
-    if($this->acl_is_writeable("telephoneNumber")){
+      /* queue number up */ 
       if(isset($_POST['up_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
         if($_POST['goFonQueueNumber_List']>0){
           $up   = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
           $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1];
-          $this->telephoneNumber[$_POST['goFonQueueNumber_List']]    = $down; 
+          $this->telephoneNumber[$_POST['goFonQueueNumber_List']]    = $down;
           $this->telephoneNumber[$_POST['goFonQueueNumber_List']-1]  = $up;
         }
       }
 
-      /* Queuenumber down */ 
+      /* Queuenumber down */
       if(isset($_POST['down_phonenumber'])&&(isset($_POST['goFonQueueNumber_List']))){
         if(isset($this->telephoneNumber[($_POST['goFonQueueNumber_List']+1)])){
           $up   = $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1];
           $down = $this->telephoneNumber[$_POST['goFonQueueNumber_List']];
-          $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1]    = $down; 
+          $this->telephoneNumber[$_POST['goFonQueueNumber_List']+1]    = $down;
           $this->telephoneNumber[$_POST['goFonQueueNumber_List']]  = $up;
         }
+        $this->telephoneNumber[$_POST['goFonQueueNumber_List']]  = $up;
       }
     }
 
+    $tmp = array();
+    foreach($this->telephoneNumber as $val){
+      if(!empty($val)){
+        $tmp[]= $val;
+      }
+    }  
+    $this->telephoneNumber=$tmp;
+
+    /* Assign samrty variables */
     $smarty= get_smarty();
+    $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German')));
+    $smarty->assign("goFonQueueStrategyOptions", $this->goFonQueueStrategyOptions);
 
     /* Set acls */
     $tmp = $this->plInfo();
@@ -177,18 +269,24 @@ class phonequeue extends plugin
       $smarty->assign($name."ACL",$this->getacl($name));
     }
 
-    $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German')));
-    $smarty->assign("goFonQueueStrategyOptions", $this->goFonQueueStrategyOptions);
-
     foreach($this->attributes as $key => $val){
       $smarty->assign($val,$this->$val);  
-
       if($this->$val == false){
         $smarty->assign($val."CHK","");
       }else{
         $smarty->assign($val."CHK"," checked ");
       }
     }
+    
+    /* Create array with goFonHomeServer */
+    $tmp = array();
+    foreach($this->goFonHomeServers as $dn => $val){
+      if(!is_numeric($dn)){
+        $tmp[$dn]  = $val['SERVER'];
+      }
+    }
+    $smarty->assign("goFonHomeServers",$tmp);
+
     return ($display.$smarty->fetch (get_template_path('phonequeue.tpl', TRUE)));
   }
 
@@ -198,15 +296,15 @@ class phonequeue extends plugin
   {
     /* Call common method to give check the hook */
     $message= plugin::check();
-
+    if(!count($this->goFonHomeServers)){
+      $message[] = _("There must be at least one server with an asterisk database to create a phone queue.");
+    }
+    if(empty($this->goFonHomeServer)){
+      $message[] = _("Please select a valid goFonHomeServer.");
+    }
     if($this->is_number_used()){
       $message[] = $this->is_number_used();
     }
-
-    if($this->generate_mysql_table_entries()){
-      $message[] = $this->generate_mysql_table_entries();
-    }
-
     if(!((is_numeric($this->goFonTimeOut))||(empty($this->goFonTimeOut)))){
       $message[] = _("Timeout must be numeric");
     }
@@ -223,86 +321,242 @@ class phonequeue extends plugin
       $message[] = _("There must be least one queue number defined.");
     }
 
+    /* check if add to database could be successfull  */
+    $str = $this->add_to_database();
+    if(!empty($str)){
+      $message[] = $str;
+    }
     return $message;
   }
 
 
-
-  function generate_mysql_table_entries($save = false)
+  /* This function removes the old database entries. 
+   * If this entry should be removed or the home server has changed
+   *  this function is called to ensure that all old entries will be deleted.
+   */
+  function remove_from_database($save = false)
   {
+    /* Check if we must remove old entries */
+    if($this->initially_was_account){
 
-    $SQL = array();
+      /* Check if there is at least on server configuration */
+      if(!count($this->goFonHomeServers)){
+        return( _("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."));
+      }
 
-    if(!isset($_SESSION['config']->data['SERVERS']['FON'][0])){
-      return(_("There is currently no asterisk server defined. Your settings can't be saved."));
-    }
+      /********************
+       * Get configuration and check it
+       ********************/
+
+      /* Check if databases are reachable, returns an error string if anything fails  */
+      $error_str = $this->check_database_accessibility();
+      if($error_str){
+        return($error_str);
+      }
 
-    // Get Configuration for Mysql database Server
-    $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'][0];
-    $s_parameter  ="";
+      /* Connect to current database to be able to add new entries */
+      $cfg_Current  = $this->goFonHomeServers[$this->init_HomeServer] ;
+      $res_cur      =  @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
+      $db_cur       =  @mysql_select_db($cfg_Current['DB'],$res_cur);
+
+      /* Create sql entries */
+      $delete[]=    "DELETE FROM ".$cfg_Current['EXT_TABLE']."    WHERE exten='".$this->old_cn."';\n";
+      $delete[]=    "DELETE FROM ".$cfg_Current['QUEUE_TABLE']."  WHERE name='".$this->old_cn."'; \n";
+      $delete[]=    "DELETE FROM ".$cfg_Current['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$this->old_cn."';\n";
+      foreach($this->old_phone_numbers as $number){
+        $delete[]=    "DELETE FROM ".$cfg_Current['EXT_TABLE']."    WHERE exten='".$number."';\n";
+      }
+
+      /* Execute the queries */  
+      if($save){
+        foreach($delete as $sql){
+          $res = @mysql_query($sql,$res_cur);
+          if(!$res){
+            gosa_log(@mysql_error($res_cur));
+            return(_("Error while removing old queue entries from database.").
+                "&nbsp;"._("Please have a look a the gosa logfiles."));
+          }
+        }
+      }
+    }
+  }
 
-    // Connect to DB server
-    $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
 
-    // Check if we are  connected correctly
-    if(!$r_con){
-      gosa_log(mysql_error());
-      return (sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
-          $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
+  /* This function handles the database entries for this 
+   *  queue. 
+   * Existing entries will be updated if possible.
+   */
+  function add_to_database($save = false)
+  {
+    /* Check if there is at least on server configuration */
+    if(!count($this->goFonHomeServers)){
+      return( _("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."));
     }
 
-    // Select database for Extensions
-    $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
+    /********************
+     * Get configuration and check it
+     ********************/
 
-    // Test if we have the database selected correctly
-    if(!$db){
-      gosa_log(mysql_error());
-      return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
+    /* Check if databases are reachable, returns an error string if anything fails  */
+    $error_str = $this->check_database_accessibility();
+    if($error_str){
+      return($error_str);
     }
 
-    if($save){
-      $i = 0;
-      $prio = 11; 
+    /* Connect to current database to be able to add new entries */
+    $cfg_Current  = $this->goFonHomeServers[$this->goFonHomeServer] ;
+    $res_cur      =  @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
+    $db_cur       =  @mysql_select_db($cfg_Current['DB'],$res_cur);
 
-      $delete = array();
-      if(!empty($this->parent->by_object['ogroup'])){
-        $new_cn = $this->parent->by_object['ogroup']->cn;
+    /* Connect to old home server and remove old entries if necessary */
+    if(($this->initially_was_account) && ($this->init_HomeServer != $this->goFonHomeServer)){
+      $str = $this->remove_from_database($save); 
+      if(!empty($str)){
+        return($str);;
       }
-      $old_cn = $this->cn;
+    }
 
-      $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$new_cn."';\n";
-      $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']."  WHERE name='".$new_cn."'; \n";
-      $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$new_cn."';\n";
-      $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$old_cn."';\n";
-      $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']."  WHERE name='".$old_cn."'; \n";
-      $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$old_cn."';\n";
+    /* Ensure that we have the new cn in $this->cn and the old cn in $this->old_cn */
+    $this->cn = $this->parent->by_object['ogroup']->cn;
 
-      // Delete old Entries 
-      if(is_array($this->old_phone_numbers)){
-        foreach($this->old_phone_numbers as $phone){
-          $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
-        }
+    if($save){
+  
+      /*****************
+       * Create queue table entry 
+       *****************/
+      /* Check if QUEUE_TABLE entry exists.
+       * If this entry is missing - create it 
+       *  else update the entry with new values.
+       */
+      $query = "SELECT * FROM ".$cfg_Current['QUEUE_TABLE']."  WHERE name='".$this->old_cn."';";
+      $res   = mysql_query($query,$res_cur);
+      if(!$res){
+        gosa_log(@mysql_error($res_cur));
+        return(_("Could not detect old queue entry, query failed.")."&nbsp;"._("Please have a look a the gosa logfiles."));
       }
+      $cnt = mysql_affected_rows($res_cur);
+
+
+      /* Create queue table entry 
+       * Leave unused options empty. 
+       */
+      $queue["announce"]              = "";
+      $queue["monitor_join"]          = "";
+      $queue["monitor_format"]        = "";
+      $queue["announce_round_seconds"]= "";   
+      $queue["wrapuptime"]            = "";
+      $queue["servicelevel"]          = "";
+      $queue["eventmemberstatus"]     = "";
+      $queue["eventwhencalled"]       = "";
+      $queue["memberdelay"]           = "";
+      $queue["weight"]                = "";
+      $queue["timeoutrestart"]        = "";
+
+      $queue["queue_holdtime"]        = $this->goFonQueueAnnounce;
+      $queue["queue_lessthan"]        = $this->goFonQueueLessThan;   
+      $queue["retry"]                 = $this->goFonQueueRetry;
+      $queue["reportholdtime"]        = "1";
+      $queue["joinempty"]             = "no";
+      $queue["leavewhenempty"]        = "yes";   
+
+      $queue["context"]               = "default";
+      $queue["name"]                  = $this->cn;  
+      $queue["timeout"]               = $this->goFonTimeOut; 
+      $queue["maxlen"]                = $this->goFonMaxLen;
+      $queue["strategy" ]             = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
+      $queue["queue_thankyou"]        = $this->goFonQueueThankYou;   
+      $queue["queue_reporthold"]      = $this->goFonQueueReportHold; 
+      $queue["announce_frequency"]    = $this->goFonAnnounceFrequency;
+      $queue["queue_youarenext"]      = $this->goFonQueueYouAreNext;   
+      $queue["queue_thereare"]        = $this->goFonQueueThereAre;   
+      $queue["queue_callswaiting"]    = $this->goFonQueueCallsWaiting;
+      $queue["queue_minutes"]         = $this->goFonQueueMinutes;
+      $queue["queue_seconds"]         = $this->goFonQueueSeconds;   
+      $queue["announce_holdtime"]     = $this->goFonQueueAnnounceHoldtime;   
+      $queue["musiconhold"]           = $this->goFonMusiconHold;
+
+
+      /* Check if we must create a new queue entry 
+       *  or if we can update an existing entry 
+       *  $cnt contains the number of entries matching this cn
+       */
+
+      /* Create new queue table entry 
+       */
+      if($cnt == 0){
+
+        /* Parse and Add Queue */
+        $entries = "";
+        $values  = "";
+        foreach($queue as $attr=>$val){
+          if($val == "") continue;
+          $entries.= "`".$attr."`,";
+          $values .= "'".$val."',";
+        }
+        $values  = preg_replace("/,$/","",$values);
+        $entries = preg_replace("/,$/","",$entries );
+        $SQL[]="INSERT INTO ".$cfg_Current['QUEUE_TABLE']." (".$entries.") VALUES (".$values.");";
+      }elseif($cnt == 1){
+
+        /* Update queue table entry 
+         */
+        $queue_old = @mysql_fetch_assoc($res);
+        foreach($queue_old as $name => $value){
+          if(isset($queue[$name]) && $queue[$name] == $value){
+            unset($queue[$name]);
+          }
+        }
 
-      /* Perform queries to delte old entries */
-      foreach($delete as $query){
-        if(!mysql_query($query)){
-          gosa_log(mysql_error());
-          return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
+        /* Parse and Add Queue */
+        if(count($queue)){
+          $query = "UPDATE ".$cfg_Current['QUEUE_TABLE']." SET ";
+          foreach($queue as $key => $val){
+            $query.= "".$key."='".$val."',";
+          }
+          $query = preg_replace("/,$/","",$query);
+          $query.= " WHERE name='".$this->old_cn."';";
+          $SQL[] = $query;
         }
+      }else{
+        return(sprintf(_("More than one entry in queue table found, that uses the name ('%s'). Please fix this issue manually first."),$this->cn));
       }
 
-      $this->attrs['cn'][0] = $new_cn;
 
+      /*****************
+       * Create queue member entries
+       *****************/
+      
+      /* Add the queue member entries 
+       * First we must remove all old user entries. 
+       * to be able to add a clean set of members.
+       */ 
+      $SQL[]= "DELETE FROM ".$cfg_Current['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$this->cn."';";
+      $SQL[]= "DELETE FROM ".$cfg_Current['QUEUE_MEMBER_TABLE']." WHERE queue_name='".$this->old_cn."';";
+      
       /* Append new Member for this queue */ 
-      $i = 0;
       $queueuser =array();
-      foreach($this->parent->by_object['ogroup']->memberList as $member){
-        if(isset($member['objectClass'])){
-          if(in_array("goFonAccount",$member['objectClass'])){
+      $i = 0;
+      $parent = $this->parent->by_object['ogroup'];
+
+      
+      $ldap = $this->config->get_ldap_link();
+      foreach($parent->memberList as $member => $mem_data){
+        $ldap->cat($member,array("goFonHomeServer","objectClass","dn","uid"));
+        if($ldap->count()){
+
+          $obj = $ldap->fetch();
+
+          /* Calculate server and account dependencies */
+          $is_acc = in_array("goFonAccount",$obj['objectClass']);
+          $is_home= isset($obj['goFonHomeServer'][0]) && $obj['goFonHomeServer'][0] == $this->goFonHomeServer; 
+
+          /* Append user to list of queue member,
+           *  only if user has phoneAccount extension && is on same home server */
+          if($is_acc && $is_home){
             $i ++ ;
-            $queueuser[$i]['queue_name']  = $this->attrs['cn'][0]
-            $queueuser[$i]['interface']   = "SIP/".$member['uid'][0]; 
+            $queueuser[$i]['queue_name']  = $this->cn
+            $queueuser[$i]['interface']   = "SIP/".$obj['uid'][0]; 
             $queueuser[$i]['penalty']     = 1; 
           }
         }
@@ -320,58 +574,69 @@ class phonequeue extends plugin
           $values  = preg_replace("/,$/","",$values);
           $entries = preg_replace("/,$/","",$entries );
 
-          $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_MEMBER_TABLE']." (".$entries.") VALUES (".$values.")"; 
+          $SQL[]="INSERT INTO ".$cfg_Current['QUEUE_MEMBER_TABLE']." (".$entries.") VALUES (".$values.")"; 
         }
       }
       
-      /* generate Extension entries, with priority  */
 
-      $queueusers=0;
-      foreach($this->parent->by_object['ogroup']->memberList as $member){
-        if(isset($member['objectClass'])){
-          if(in_array("goFonAccount",$member['objectClass'])){
-            $queueusers++;
-          }
+      /*****************
+       * Create extension entries
+       *****************/
+      
+      /* Add the extension entries 
+       * First we must remove all old entensions. 
+       */ 
+      $SQL[]=  "DELETE FROM ".$cfg_Current['EXT_TABLE']."  WHERE exten='".$this->cn."';\n";
+      $SQL[]=  "DELETE FROM ".$cfg_Current['EXT_TABLE']."  WHERE exten='".$this->old_cn."';\n";
+
+      /* Delete old enxtension entries for the old telephone nubmer  */
+      if(is_array($this->old_phone_numbers)){
+        foreach($this->old_phone_numbers as $phone){
+          $SQL[]= "DELETE FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$phone."';\n";
+        }
+      }
+      
+      /* Delete enxtension entries for telephone numbers  */
+      if(is_array($this->telephoneNumber)){
+        foreach($this->telephoneNumber as $phone){
+          $SQL[]= "DELETE FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$phone."';\n";
         }
       }
 
-
-      $i = 0;
-
+      /* Create a extension entry fpr each telephoneNumber */
       $i_insert_only_once = false;
-      
+      $prio = 11;   // This represents the priority for each telephoneNumber 
       foreach($this->telephoneNumber as $num){
-       
-        // If there are no member in a Queue
-        // Play sound an quit
 
-        // A Queue is not deleted directly, it is stored until the o group is deleted
-        
+        /* The naming refrences */
         if($i_insert_only_once == false){
           $i_insert_only_once = true;
           $a_ext[$i]['context']  = 'GOsa';
-          $a_ext[$i]['exten']    = $this->attrs['cn'][0];
+          $a_ext[$i]['exten']    = $this->cn;
           $a_ext[$i]['priority'] = 1;
           $a_ext[$i]['app']      = "Goto";
           $a_ext[$i]['appdata']  = $num."|1";
           $i ++ ; 
         }
-    
-        if($queueusers == 0){
+
+        /* If there is currently no user for this queue 
+         * Play no service sound file and return to default context.  
+         */
+        if(count($queueuser)==0){
           $a_ext[$i]['context']  = 'GOsa';
           $a_ext[$i]['exten']    = $num;
           $a_ext[$i]['priority'] = 1;
           $a_ext[$i]['app']      = "SetLanguage";
           $a_ext[$i]['appdata']  = "de";
           $i ++ ; 
-          
+
           $a_ext[$i]['context']  = 'GOsa';
           $a_ext[$i]['exten']    = $num;
           $a_ext[$i]['priority'] = 2;
           $a_ext[$i]['app']      = "Playback";
           $a_ext[$i]['appdata']  = "ss-noservice";
           $i ++ ; 
-          
+
           $a_ext[$i]['context']  = 'GOsa';
           $a_ext[$i]['exten']    = $num;
           $a_ext[$i]['priority'] = 3;
@@ -379,25 +644,35 @@ class phonequeue extends plugin
           $a_ext[$i]['appdata']  = "default";
           $i ++ ; 
         }else{
+
+          /* Dcrement priority to avoid using same priority twice */
           $prio --;
+
+          /* Wait for 2 seconds */
           $a_ext[$i]['context']  = 'GOsa';
           $a_ext[$i]['exten']    = $num;
           $a_ext[$i]['priority'] = 1;
           $a_ext[$i]['app']      = "Wait";
           $a_ext[$i]['appdata']  = "2";
           $i ++ ; 
+    
+          /* Set language to queue language */
           $a_ext[$i]['context']  = 'GOsa';
           $a_ext[$i]['exten']    = $num;
           $a_ext[$i]['priority'] = 2;
           $a_ext[$i]['app']      = "SetLanguage";
           $a_ext[$i]['appdata']  = $this->goFonQueueLanguage;
           $i ++ ; 
+  
+          /* Play welcome sound file */
           $a_ext[$i]['context']  = 'GOsa';
           $a_ext[$i]['exten']    = $num;
           $a_ext[$i]['priority'] = 3;
           $a_ext[$i]['app']      = "Playback";
           $a_ext[$i]['appdata']  = $this->goFonWelcomeMusic;
           $i ++ ; 
+
+          /* Set CID name */
           $a_ext[$i]['context']  = 'GOsa';
           $a_ext[$i]['exten']    = $num;
           $a_ext[$i]['priority'] = 4;
@@ -405,20 +680,24 @@ class phonequeue extends plugin
           if(!empty($this->parent->by_object['ogroup']->description)){
             $a_ext[$i]['appdata']  = $this->parent->by_object['ogroup']->description;
           }else{
-            $a_ext[$i]['appdata']  = $this->attrs['cn'][0]." - ".$num;
+            $a_ext[$i]['appdata']  = $this->cn." - ".$num;
           }
           $i ++ ; 
+
+          /* Set queue priority */
           $a_ext[$i]['context']  = 'GOsa';
           $a_ext[$i]['exten']    = $num;
           $a_ext[$i]['priority'] = 5;
           $a_ext[$i]['app']      = "SetVar";
           $a_ext[$i]['appdata']  = "QUEUE_PRIO=".$prio;
           $i ++ ; 
+
+          /* Open queue */
           $a_ext[$i]['context']  = 'GOsa';
           $a_ext[$i]['exten']    = $num;
           $a_ext[$i]['priority'] = 6;
           $a_ext[$i]['app']      = "Queue";
-          $a_ext[$i]['appdata']  =  $this->attrs['cn'][0].
+          $a_ext[$i]['appdata']  =  $this->cn;
             "|".
             $this->goFonDialOptiont.
             $this->goFonDialOptionT.
@@ -427,48 +706,6 @@ class phonequeue extends plugin
             $this->goFonDialOptionr;
         }
 
-        if($this->goFonQueueAnnounceHoldtime != false) {
-          $this->goFonQueueAnnounceHoldtime = "yes";
-        }else{
-          $this->goFonQueueAnnounceHoldtime = "no";
-        }
-
-
-        /* Generate Priority Entry */
-        $queue["announce"]              = "";
-        $queue["monitor_join"]          = "";
-        $queue["monitor_format"]        = "";
-        $queue["queue_holdtime"]        = $this->goFonQueueAnnounce;
-        $queue["queue_lessthan"]        = $this->goFonQueueLessThan;   
-        $queue["announce_round_seconds"]= "";   
-        $queue["retry"]                 = $this->goFonQueueRetry;
-        $queue["wrapuptime"]            = "";
-        $queue["servicelevel"]          = "";
-        $queue["joinempty"]             = "no";
-        $queue["leavewhenempty"]        = "yes";   
-        $queue["eventmemberstatus"]     = "";
-        $queue["eventwhencalled"]       = "";
-        $queue["reportholdtime"]        = "yes";
-        $queue["memberdelay"]           = "";
-        $queue["weight"]                = "";
-        $queue["timeoutrestart"]        = "";
-
-        $queue["context"]               = "default";
-        $queue["name"]                  = $this->attrs['cn'][0];  
-        $queue["timeout"]               = $this->goFonTimeOut; 
-        $queue["maxlen"]                = $this->goFonMaxLen;
-        $queue["strategy" ]             = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
-        $queue["queue_thankyou"]        = $this->goFonQueueThankYou;   
-        $queue["queue_reporthold"]      = $this->goFonQueueReportHold; 
-        $queue["announce_frequency"]    = $this->goFonAnnounceFrequency;
-        $queue["queue_youarenext"]      = $this->goFonQueueYouAreNext;   
-        $queue["queue_thereare"]        = $this->goFonQueueThereAre;   
-        $queue["queue_callswaiting"]    = $this->goFonQueueCallsWaiting;
-        $queue["queue_minutes"]         = $this->goFonQueueMinutes;
-        $queue["queue_seconds"]         = $this->goFonQueueSeconds;   
-        $queue["announce_holdtime"]     = $this->goFonQueueAnnounceHoldtime;   
-        $queue["musiconhold"]           = $this->goFonMusiconHold;
-
         $i++;
       }
 
@@ -482,44 +719,35 @@ class phonequeue extends plugin
         }
         $values  = preg_replace("/,$/","",$values);
         $entries = preg_replace("/,$/","",$entries );
-        $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
+        $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$entries.") VALUES (".$values.")";
       }
 
-
-      /* Parse and Add Queue */
-      $entries = "";
-      $values  = "";
-      foreach($queue as $attr=>$val){
-        if($val == "") continue;
-        $entries.= "`".$attr."`,";
-        $values .= "'".$val."',";
+      /* Do all collected mysql queries 
+       */
+      foreach($SQL as $query)
+      $res   = mysql_query($query,$res_cur);
+      if(!$res){
+        gosa_log(@mysql_error($res_cur));
+        return(_("Mysql query failed.")."&nbsp;"._("Please have a look a the gosa logfiles."));
       }
-      $values  = preg_replace("/,$/","",$values);
-      $entries = preg_replace("/,$/","",$entries );
-      $SQL[]="INSERT INTO ".$a_SETUP['QUEUE_TABLE']." (".$entries.") VALUES (".$values.")";
-
-      foreach($SQL as $query){
-         if(!mysql_query($query)){
-          gosa_log(mysql_error());
-          print_red(mysql_error());
-          return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
-        }
-      }
-
     }
     @mysql_close($r_con);
     return(false);
   }
 
 
-
- /* This function checks if the given phonenumbers are available or already in use*/
-
+  /* This function checks if the given phonenumbers 
+   *  are available or already in use
+   */
   function is_number_used()
   {
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
+    $ldap->search("(&(& (!(uid=".$this->cn."))
+                        (!(cn=".$this->cn.")))
+                     (| (objectClass=goFonAccount)
+                        (objectClass=goFonQueue)
+                        (objectClass=goFonConference)))", array("telephoneNumber","cn","uid"));
     while($attrs = $ldap->fetch()) {
       unset($attrs['telephoneNumber']['count']);
       foreach($attrs['telephoneNumber'] as $tele){
@@ -541,9 +769,7 @@ class phonequeue extends plugin
   }
 
 
-
-
-
+  /* Get posted attributes */
   function save_object()
   {
     plugin::save_object();  
@@ -560,41 +786,48 @@ class phonequeue extends plugin
       }else{
         $this->goFonQueueAnnounceHoldtime = false;
       }
-      
     }
-
   }
 
+
   function save()
   {
-  #fixme workaround : Tab is not initialised correct
-       if(!$this->is_account) return;
     $ldap= $this->config->get_ldap_link();
 
-    $this->generate_mysql_table_entries(true);
-
     plugin::save();
+
+    /* Create dial option attribute */
     $this->attrs['goFonDialOption'] = "";
     foreach(array("goFonDialOptiont","goFonDialOptionT","goFonDialOptionr","goFonDialOptionh","goFonDialOptionH","cn") as $val){
       $this->attrs['goFonDialOption'].=$this->$val; 
       unset($this->attrs[$val]); 
     }
-    if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
-  
+    if(empty($this->attrs['goFonDialOption'])) {
+      $this->attrs['goFonDialOption']=array();
+    }
+
+    /* Set announce hold time to yes no .. */
     if($this->goFonQueueAnnounceHoldtime != "no" ){
       $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
     }else{
       $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
     }
 
+    /* Set strategy */
     $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
 
+    /* Add database entry, display error and abort if this fails */
+    $str = $this->add_to_database(true);
+    if(!empty($str)){
+      print_red($str);
+    }
+
     /* Save data to LDAP */
     $ldap->cd($this->dn);
     $this->cleanup();
     $ldap->modify ($this->attrs); 
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of object group/phone queue with dn '%s' failed."),$this->dn));
+    show_ldap_error($ldap->get_error(), _("Saving phone queue failed"));
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){
@@ -610,31 +843,20 @@ class phonequeue extends plugin
   /* remove object from parent */
   function remove_from_parent()
   {
-    $SQL = array();
-
-    // Get Configuration for Mysql database Server
-    $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'][0];
-    $s_parameter  ="";
-
-    // Connect to DB server
-    $r_con =  @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
-
-    // Check if we are  connected correctly
-    if(!$r_con){
-      gosa_log(mysql_error());
-      return (sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
-            $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
+    /* Cancel if nothing is to do here */
+    if (!$this->initially_was_account){
+      return;
     }
 
-    // Select database for Extensions
-    $db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
-
-    // Test if we have the database selected correctly
-    if(!$db){
-      gosa_log(mysql_error());
-      return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
+    /* Remove database entries, 
+     *  if fails display errors and abort
+     */
+    $str = $this->remove_from_database(true);
+    if(!empty($str)){
+      print_red($str);
+      return false;
     }
-
+  
     /* Remove all temporary attributes */
     $tmp = array_flip($this->attributes);
     foreach(array("goFonDialOptiont","goFonDialOptionT","goFonDialOptionr","goFonDialOptionh","goFonDialOptionH","cn") as $val){
@@ -647,51 +869,17 @@ class phonequeue extends plugin
     } 
     $this->attributes = $tmp2;
 
-    $i = 0;
-    $prio = 11;
-
-    if(empty($this->cn)){
-      $this->cn = $this->parent->by_object['ogroup']->cn;
-      $this->attrs['cn'][0] = $this->parent->by_object['ogroup']->cn;
-    }
-
-    // Delete old Entries
-    $delete = array();
-    foreach($this->old_phone_numbers as $phone){
-      $delete[]= "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$phone."';\n";
-    }
-    $delete[]=    "DELETE FROM ".$a_SETUP['EXT_TABLE']."    WHERE exten='".$this->attrs['cn'][0]."';\n";
-    $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_TABLE']." WHERE name=\"".$this->attrs['cn'][0]."\"; \n";
-    $delete[]=    "DELETE FROM ".$a_SETUP['QUEUE_MEMBER_TABLE']." WHERE queue_name=\"".$this->attrs['cn'][0]."\";\n";
-
-    /* Perform queries to delte old entries */
-    foreach($delete as $query){
-      if(!mysql_query($query)){
-        gosa_log(mysql_error());
-        return(mysql_error(). sprintf(_("Can't delete in Database %s, on Server %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
-      }
-    }
-
-
-
-    /* Cancel if there's nothing to do here */
-    if (!$this->initially_was_account){
-      return;
-    }
-
     /* include global link_info */
     $ldap= $this->config->get_ldap_link();
 
     /* Remove and write to LDAP */
     plugin::remove_from_parent();
 
-    @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
-        $this->attributes, "Save");
+    @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
     $ldap->cd($this->dn);
     $this->cleanup();
     $ldap->modify ($this->attrs); 
-
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of object group/phone queue with dn '%s' failed."),$this->dn));
+    show_ldap_error($ldap->get_error(), _("Removing phone queue failed"));
   }
 
   
@@ -712,7 +900,7 @@ class phonequeue extends plugin
   }
 
 
-    function plInfo()
+  function plInfo()
   {
     return (array(
           "plShortName"   => _("Phone"),
@@ -721,17 +909,18 @@ class phonequeue extends plugin
           "plDepends"     => array(),
           "plPriority"    => 3,
           "plSection"     => array("administration"),
-          "plCategory"    => array("ogroups"), 
+          "plCategory"    => array("ogroups"),
           "plProvidedAcls"=> array(
 
             "goFonTimeOut"              => _("Timeout"),
             "goFonMaxLen"               => _("Max queue length"),
+            "goFonHomeServer"           => _("Home server"),
             "goFonAnnounceFrequency"    => _("Announce frequency"),
-            "goFonDialOptiont"         => _("Allow the called user to transfer his call"),
-            "goFonDialOptionT"         => _("Allows calling user to transfer call"),
-            "goFonDialOptionh"         => _("Allow the called to hangup by pressing *"),
-            "goFonDialOptionr"         => _("Ring instead of playing background music"),
-            "goFonDialOptionH"         => _("Allows calling to hangup by pressing *"),
+            "goFonDialOptiont"          => _("Allow the called user to transfer his call"),
+            "goFonDialOptionT"          => _("Allows calling user to transfer call"),
+            "goFonDialOptionh"          => _("Allow the called to hangup by pressing *"),
+            "goFonDialOptionr"          => _("Ring instead of playing background music"),
+            "goFonDialOptionH"          => _("Allows calling to hangup by pressing *"),
 
             "goFonMusiconHold"          => _("Music on hold"),
             "goFonWelcomeMusic"         => _("Welcome music"),
@@ -752,8 +941,6 @@ class phonequeue extends plugin
               ));
   }
 
-
-
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
index 9a2ea4046e900515ec2ca6671fa042befb999a34..53fbb20edf02f7cdf006a3899c39b440701b9f1f 100644 (file)
                <tr>
                  <td colspan=2><h2><img class="center" alt="" src="images/select_ogroup.png" align="middle">&nbsp;{t}Options{/t}</h2></td>
                </tr>
+                <tr>
+                <td><LABEL for="goFonHomeServer">{t}Home server{/t}</LABEL>{$must}</td>
+                <td>
+{render acl=$goFonHomeServerACL}
+                        <select name='goFonHomeServer'>
+                         {html_options options=$goFonHomeServers selected=$goFonHomeServer}
+                        </select>
+{/render}
+                </td>
+                </tr>
+
                <tr>
                <td>
                        {t}Language{/t} 
index 6664bce7e02a2d61f80f24bc4a44433841573735..1e2c75fb50e87bcba273027849ead9c4112d5362 100644 (file)
@@ -13,8 +13,10 @@ class ogrouptabs extends tabs
      */
     $usePhoneTab = false;
     foreach($this->by_object['ogroup']->memberList as $dn => $val){
-      if(isset($val['objectClass'])){
-        if(in_array("goFonAccount",$val['objectClass'])){
+
+      $obj = $this->by_object['ogroup']->objcache[$dn];
+      if(isset($obj['objectClass'])){
+        if(in_array("goFonAccount",$obj['objectClass'])){
           $usePhoneTab = true;
         }
       }
@@ -56,12 +58,16 @@ class ogrouptabs extends tabs
      */
     if(!isset($this->by_object['phonequeue'])){
       foreach($this->by_object['ogroup']->memberList as $dn => $val){
-        if(isset($val['objectClass'])){
-          if(in_array("goFonAccount",$val['objectClass'])){
+
+        $obj = $this->by_object['ogroup']->objcache[$dn];
+  
+        if(isset($obj['objectClass'])){
+          if(in_array("goFonAccount",$obj['objectClass'])){
             require_once("class_phonequeue.inc");
             $this->by_name['phonequeue']= _("Phone queue");
             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
             $this->by_object['phonequeue']->parent= &$this;
+            break;
           }
         }
       }
@@ -145,7 +151,7 @@ class ogrouptabs extends tabs
     /* Insert extra tabs for several object types - if present */
 
     $objects= preg_replace('/[\[\]]/', '', $this->by_object['ogroup']->gosaGroupObjects);
-    
+   
     for ($n= 0; $n<strlen($objects); $n++){
       switch ($objects[$n]){
         case "T":
@@ -161,8 +167,11 @@ class ogrouptabs extends tabs
             /* Append a PhoneQueue, if objectClass = goFonAccount */
             $use = false;
           foreach($this->by_object['ogroup']->memberList as $dn => $val){
-            if(isset($val['objectClass'])){
-              if(in_array("goFonAccount",$val['objectClass'])){
+
+            $obj = $this->by_object['ogroup']->objcache[$dn];
+            
+            if(isset($obj['objectClass'])){
+              if(in_array("goFonAccount",$obj['objectClass'])){
                 $use = true; 
               }
             }
@@ -174,7 +183,6 @@ class ogrouptabs extends tabs
             $this->by_name['phonequeue']= _("Phone queue");
             $this->by_object['phonequeue']= new phonequeue($this->config, $this->dn);
             $this->by_object['phonequeue']->parent= &$this;
-
           } 
  
           /* Add a user tab used for mail distribution lists */