Code

Added acl check for conferences
[gosa.git] / plugins / admin / ogroups / class_phonequeue.inc
index 90480d9a5a0a6351aae8862b3696b688785a95e5..96fbdf170027e37f002438fe51641631b04d50f2 100644 (file)
@@ -7,37 +7,40 @@ class phonequeue extends plugin
   var $cn= "";
 
 
-  var $goFonTimeOut             ="5"; 
-  var $goFonMaxLen              ="20";
-  var $goFonAnnounceFrequency   ="60";
-  var $goFonDialOption_t        ="t";
-  var $goFonDialOption_T        ="T";
-  var $goFonDialOption_h        ="h";
-  var $goFonQueueAnnounce            ="gonicus-berlin-welcome";
-  var $goFonDialOption_H        ="H";
+  var $goFonTimeOut             ="20"; 
+  var $goFonMaxLen              ="20"; // 
+  var $goFonAnnounceFrequency   ="60"; // Annouce Frequency in seconds
+  var $goFonDialOption_t        ="";
+  var $goFonDialOption_T        ="";
+  var $goFonDialOption_h        ="";
+  var $goFonDialOption_r        ="";
+  var $goFonQueueAnnounce       ="gonicus-berlin-welcome";
+  var $goFonDialOption_H        ="";
   var $goFonMusiconHold         ="default";
   var $goFonWelcomeMusic        ="gonicus-berlin-welcome";
-  var $goFonQueueReportHold     ="";
+  var $goFonQueueReportHold     ="yes";
   var $goFonQueueYouAreNext     ="queue-youarenext";
-  var $goFonQueueThereAre       ="queue-therare";
+  var $goFonQueueThereAre       ="queue-thereare";
   var $goFonQueueCallsWaiting   ="queue-callswaiting";
   var $goFonQueueThankYou       ="queue-thankyou";
   var $goFonQueueMinutes        ="queue-minutes"; 
   var $goFonQueueSeconds        ="queue-seconds";
-  var $goFonQueueLanguage            ="queue-holdtime";
-  var $goFonQueueStrategy            ="rrmemory";
-  var $goFonQueueAnnounceHoldtime    ="yes";
+  var $goFonQueueLessThan       ="queue-lessthan";
+  var $goFonQueueLanguage       ="queue-holdtime";
+  var $goFonQueueStrategy       ="ringall";
+  var $goFonQueueAnnounceHoldtime="yes";
   var $telephoneNumber          =array();
   var $goFonQueueMember         =array(); 
-  var $goFonDialOption          ="tThH";
+  var $goFonDialOption          ="";
   var $goFonQueueRetry          =5;
 
   var $old_phone_numbers        =array();
 
   /* attribute list for save action */
-  var $attributes= array( "goFonTimeOut","goFonMaxLen","goFonAnnounceFrequency","goFonDialOption_t","goFonDialOption_T","goFonDialOption_h",
+  var $attributes= array( "goFonTimeOut","goFonMaxLen","goFonAnnounceFrequency","goFonDialOption_t","goFonDialOption_T",
+      "goFonDialOption_h","goFonDialOption_r",
       "goFonDialOption_H","goFonMusiconHold","goFonWelcomeMusic","goFonQueueReportHold","goFonQueueYouAreNext",
-      "goFonQueueThereAre","goFonQueueCallsWaiting","goFonQueueThankYou","goFonQueueMinutes","goFonQueueSeconds",
+      "goFonQueueThereAre","goFonQueueCallsWaiting","goFonQueueThankYou","goFonQueueMinutes","goFonQueueSeconds","goFonQueueLessThan",
       "telephoneNumber","goFonQueueLanguage","goFonQueueStrategy","goFonQueueAnnounceHoldtime","goFonQueueAnnounce","goFonDialOption","goFonQueueRetry");
   /* ObjectClass */
   var $objectclasses= array("goFonQueue");
@@ -64,6 +67,9 @@ class phonequeue extends plugin
       }
     }
 
+    if($this->goFonQueueAnnounceHoldtime == "no"){
+      $this->goFonQueueAnnounceHoldtime=false;
+    }
     $this->old_phone_numbers = $this->telephoneNumber;
   }
 
@@ -130,13 +136,14 @@ class phonequeue extends plugin
     $smarty= get_smarty();
 
     $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German'),'ur'=>_('Uruguai')));
-    $smarty->assign("goFonQueueAnnounceHoldtimeOptions",array('no'=>_("No"),'yes'=>_('Yes')));
-    $smarty->assign("goFonQueueStrategyOptions",array('ringall'    =>_("ring all available channels until one answers"),
-          'roundrobin' =>_("take turns ringing each available interface"),
-          'leastrecent'=>_("ring interface which was least recently called by this queue"),
-          'fewestcalls'=>_("ring the one with fewest completed calls from this queue"),
-          'random'     =>_("ring random interface"),
-          'rrmemory'   =>_("round robin with memory, remember where we left off last ring pass")));
+    $types= array('ringall'    =>_("ring all"),
+          'roundrobin' =>_("round robin"),
+          'leastrecent'=>_("least recently called"),
+          'fewestcalls'=>_("fewest completed calls"),
+          'random'     =>_("random"),
+          'rrmemory'   =>_("round robin with memory"));
+    sort($types);
+    $smarty->assign("goFonQueueStrategyOptions", $types);
 
     foreach($this->attributes as $key => $val){
       $smarty->assign($val,$this->$val);  
@@ -161,6 +168,7 @@ class phonequeue extends plugin
   function check()
   {
     $message= array();
+  #fixme workaround : Tab is not initialised correct
          if(!$this->is_account) return($message);
 
     if($this->is_number_used()){
@@ -278,77 +286,122 @@ 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++;
+        }
+      }
+
+
       $i = 0;
       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
         
-        $prio --;
         $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 ++ ; 
-        $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 ++ ; 
-        $a_ext[$i]['context']  = 'GOsa';
-        $a_ext[$i]['exten']    = $num;
-        $a_ext[$i]['priority'] = 2;
-        $a_ext[$i]['app']      = "Set";
-        $a_ext[$i]['appdata']  = "LANGUAGE|".$this->goFonQueueLanguage;
-        $i ++ ; 
-        $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 ++ ; 
-        $a_ext[$i]['context']  = 'GOsa';
-        $a_ext[$i]['exten']    = $num;
-        $a_ext[$i]['priority'] = 4;
-        $a_ext[$i]['app']      = "SetCIDName";
-        $a_ext[$i]['appdata']  = $this->parent->by_object['ogroup']->description;
-        $i ++ ; 
-        $a_ext[$i]['context']  = 'GOsa';
-        $a_ext[$i]['exten']    = $num;
-        $a_ext[$i]['priority'] = 5;
-        $a_ext[$i]['app']      = "Queue";
-        $a_ext[$i]['appdata']  =  $this->attrs['cn'][0].
-          "|".
-          $this->goFonDialOption_t.
-          $this->goFonDialOption_T.
-          $this->goFonDialOption_h.
-          $this->goFonDialOption_H.
-          "|".  // Optionalurl egal
-          "|".  // announceoverride
-          "|";  // Timeout
-
-//        $i ++ ; 
-//        $a_ext[$i]['context']  = 'GOsa';
-//        $a_ext[$i]['exten']    = $num;
-//        $a_ext[$i]['priority'] = 6;
-//        $a_ext[$i]['app']      = "SetVar";
-//        $a_ext[$i]['appdata']  = "Queue_Prio=".$prio;
-        $i ++ ;
+    
+        if($queueusers == 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;
+          $a_ext[$i]['app']      = "Goto";
+          $a_ext[$i]['appdata']  = "default";
+          $i ++ ; 
+        }else{
+          $prio --;
+          $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 ++ ; 
+          $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 ++ ; 
+          $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 ++ ; 
+          $a_ext[$i]['context']  = 'GOsa';
+          $a_ext[$i]['exten']    = $num;
+          $a_ext[$i]['priority'] = 4;
+          $a_ext[$i]['app']      = "SetCIDName";
+          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;
+          }
+          $i ++ ; 
+          $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 ++ ; 
+          $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].
+            "|".
+            $this->goFonDialOption_t.
+            $this->goFonDialOption_T.
+            $this->goFonDialOption_h.
+            $this->goFonDialOption_H.
+            $this->goFonDialOption_r;
+        }
+
+        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"]        = "";   
+        $queue["queue_lessthan"]        = $this->goFonQueueLessThan;   
         $queue["announce_round_seconds"]= "";   
         $queue["retry"]                 = $this->goFonQueueRetry;
         $queue["wrapuptime"]            = "";
         $queue["servicelevel"]          = "";
-        $queue["joinempty"]             = "";
-        $queue["leavewhenempty"]        = "";   
+        $queue["joinempty"]             = "no";
+        $queue["leavewhenempty"]        = "yes";   
         $queue["eventmemberstatus"]     = "";
         $queue["eventwhencalled"]       = "";
-        $queue["reportholdtime"]        = "";
+        $queue["reportholdtime"]        = "yes";
         $queue["memberdelay"]           = "";
         $queue["weight"]                = "";
         $queue["timeoutrestart"]        = "";
@@ -418,7 +471,7 @@ class phonequeue extends plugin
   {
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue))", array("telephoneNumber","cn","uid"));
+    $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
     while($attrs = $ldap->fetch()) {
       unset($attrs['telephoneNumber']['count']);
       foreach($attrs['telephoneNumber'] as $tele){
@@ -447,31 +500,44 @@ class phonequeue extends plugin
   {
     plugin::save_object();  
     if(isset($_POST['phonenumber'])){
-      foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_H","goFonMusiconHold") as $val){
+      foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_r","goFonDialOption_H","goFonMusiconHold") as $val){
         if(isset($_POST[$val])){
           $this->$val = $_POST[$val];
         }else{
           $this->$val = false;
         }
       }
+      if(isset($_POST['goFonQueueAnnounceHoldtime'])){
+        $this->goFonQueueAnnounceHoldtime = "yes";
+      }else{
+        $this->goFonQueueAnnounceHoldtime = false;
+      }
+      
     }
 
   }
 
   function save()
   {
+  #fixme workaround : Tab is not initialised correct
        if(!$this->is_account) return;
     $ldap= $this->config->get_ldap_link();
 
     plugin::save();
     $this->attrs['goFonDialOption'] = "";
-    foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_H") as $val){
+    foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H") 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" ){
+      $this->attrs['goFonQueueAnnounceHoldtime'] = "yes";
+    }else{
+      $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
+    }
     /* Save data to LDAP */
     $ldap->cd($this->dn);
     $ldap->modify($this->attrs);
@@ -518,7 +584,7 @@ class phonequeue extends plugin
     }
 
     $tmp = array_flip($this->attributes);
-    foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_h","goFonDialOption_H") as $val){
+    foreach(array("goFonDialOption_t","goFonDialOption_T","goFonDialOption_r","goFonDialOption_h","goFonDialOption_H") as $val){
       unset($this->$val);
       unset($this->attrs[$val]);
       unset($tmp[$val]);