Code

Invalid repository settings fixed.
[gosa.git] / plugins / admin / ogroups / class_phonequeue.inc
index 7e2c822a11ba5afd86a8a7bd037687ca43787fdc..c7f61c946901f3b32fd880e1f93226eba7fe698c 100644 (file)
@@ -42,7 +42,7 @@ class phonequeue extends plugin
 
   /* attribute list for save action */
   var $attributes= array( "goFonTimeOut","goFonMaxLen","goFonAnnounceFrequency","goFonDialOption_t","goFonDialOption_T",
-      "goFonDialOption_h","goFonDialOption_r",
+      "goFonDialOption_h","goFonDialOption_r","cn",
       "goFonDialOption_H","goFonMusiconHold","goFonWelcomeMusic","goFonQueueReportHold","goFonQueueYouAreNext",
       "goFonQueueThereAre","goFonQueueCallsWaiting","goFonQueueThankYou","goFonQueueMinutes","goFonQueueSeconds","goFonQueueLessThan",
       "telephoneNumber","goFonQueueLanguage","goFonQueueStrategy","goFonQueueAnnounceHoldtime","goFonQueueAnnounce","goFonDialOption","goFonQueueRetry");
@@ -190,8 +190,8 @@ class phonequeue extends plugin
       $message[] = $this->is_number_used();
     }
 
-    if($this->generate_mysql_entension_entries()){
-      $message[] = $this->generate_mysql_entension_entries();
+    if($this->generate_mysql_table_entries()){
+      $message[] = $this->generate_mysql_table_entries();
     }
 
     if(!((is_numeric($this->goFonTimeOut))||(empty($this->goFonTimeOut)))){
@@ -215,11 +215,16 @@ class phonequeue extends plugin
 
 
 
-  function generate_mysql_entension_entries($save = false)
+  function generate_mysql_table_entries($save = false)
   {
 
     $SQL = array();
+
+    if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
+      return(_("There is currently no asterisk server defined. Possibly you are missing a server that handles the asterisk management (goFonServer).\nYour Settings can't be saved to asterisk Database."));
+      return(false);
+    }
+
     // Get Configuration for Mysql database Server
     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
     $s_parameter  ="";
@@ -247,21 +252,25 @@ class phonequeue extends plugin
       $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 = array();
+      if(!empty($this->parent->by_object['ogroup'])){
+        $new_cn = $this->parent->by_object['ogroup']->cn;
       }
+      $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";
 
       // Delete old Entries 
-      $delete = array();
       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";
         }
       }
-      $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){
@@ -271,15 +280,19 @@ class phonequeue extends plugin
         }
       }
 
+      $this->attrs['cn'][0] = $new_cn;
+
       /* Append new Member for this queue */ 
       $i = 0;
       $queueuser =array();
       foreach($this->parent->by_object['ogroup']->memberList as $member){
-        if(in_array("goFonAccount",$member['objectClass'])){
-          $i ++ ;
-          $queueuser[$i]['queue_name']  = $this->attrs['cn'][0]; 
-          $queueuser[$i]['interface']   = "SIP/".$member['uid'][0]; 
-          $queueuser[$i]['penalty']     = 1; 
+        if(isset($member['objectClass'])){
+          if(in_array("goFonAccount",$member['objectClass'])){
+            $i ++ ;
+            $queueuser[$i]['queue_name']  = $this->attrs['cn'][0]; 
+            $queueuser[$i]['interface']   = "SIP/".$member['uid'][0]; 
+            $queueuser[$i]['penalty']     = 1; 
+          }
         }
       }
 
@@ -299,18 +312,22 @@ class phonequeue extends plugin
         }
       }
       
-
       /* generate Extension entries, with priority  */
 
       $queueusers=0;
       foreach($this->parent->by_object['ogroup']->memberList as $member){
-        if(in_array("goFonAccount",$member['objectClass'])){
-          $queueusers++;
+        if(isset($member['objectClass'])){
+          if(in_array("goFonAccount",$member['objectClass'])){
+            $queueusers++;
+          }
         }
       }
 
 
       $i = 0;
+
+      $i_insert_only_once = false;
+      
       foreach($this->telephoneNumber as $num){
        
         // If there are no member in a Queue
@@ -318,12 +335,15 @@ class phonequeue extends plugin
 
         // A Queue is not deleted directly, it is stored until the o group is deleted
         
-        $a_ext[$i]['context']  = 'GOsa';
-        $a_ext[$i]['exten']    = $this->attrs['cn'][0];
-        $a_ext[$i]['priority'] = 1;
-        $a_ext[$i]['app']      = "Goto";
-        $a_ext[$i]['appdata']  = $num."|1";
-        $i ++ ; 
+        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]['priority'] = 1;
+          $a_ext[$i]['app']      = "Goto";
+          $a_ext[$i]['appdata']  = $num."|1";
+          $i ++ ; 
+        }
     
         if($queueusers == 0){
           $a_ext[$i]['context']  = 'GOsa';
@@ -475,6 +495,7 @@ class phonequeue extends plugin
       }
 
     }
+    @mysql_close($r_con);
     return(false);
   }
 
@@ -538,13 +559,14 @@ class phonequeue extends plugin
        if(!$this->is_account) return;
     $ldap= $this->config->get_ldap_link();
 
+    $this->generate_mysql_table_entries(true);
+
     plugin::save();
     $this->attrs['goFonDialOption'] = "";
-    foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H") as $val){
+    foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
       $this->attrs['goFonDialOption'].=$this->$val; 
       unset($this->attrs[$val]); 
     }
-    $this->generate_mysql_entension_entries(true);
     if($this->attrs['goFonDialOption']=="") $this->attrs['goFonDialOption']=array();
   
     if($this->goFonQueueAnnounceHoldtime != "no" ){
@@ -600,8 +622,9 @@ class phonequeue extends plugin
       return( sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']));
     }
 
+    /* Remove all temporary attributes */
     $tmp = array_flip($this->attributes);
-    foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H") as $val){
+    foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H","cn") as $val){
       unset($this->$val);
       unset($this->attrs[$val]);
       unset($tmp[$val]);