Code

Added ogroups acls
[gosa.git] / plugins / admin / ogroups / class_phonequeue.inc
index 506984d55659a2be4381a61c9966893f4da9ee96..d20ad03dc719f015b9d0d352aece44d9a7f08ad0 100644 (file)
@@ -34,11 +34,15 @@ class phonequeue extends plugin
   var $goFonDialOption          ="";
   var $goFonQueueRetry          =5;
 
+  var $goFonQueueStrategyOptions=array();
+  var $goFonQueueStrategyOptionsR=array();
+  
+
   var $old_phone_numbers        =array();
 
   /* 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");
@@ -71,11 +75,33 @@ class phonequeue extends plugin
       $this->goFonQueueAnnounceHoldtime=false;
     }
     $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];
+  
+
   }
 
 
   function execute()
   {
+       /* Call parent execute */
+       plugin::execute();
+
     /* Do we need to flip is_account state? */
     if (isset($_POST['modify_state'])){
       $this->is_account= !$this->is_account;
@@ -87,7 +113,8 @@ class phonequeue extends plugin
         $display= $this->show_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_header(_("Create phone queue"), _("For this group the phone queues are disabled. You can enable them by clicking below."));
+        $display= $this->show_header(_("Create phone queue"), 
+                  _("For this group the phone queues are disabled. You can enable them by clicking below."));
         return ($display);
       }
     }
@@ -132,18 +159,10 @@ class phonequeue extends plugin
       }
     }
 
-
     $smarty= get_smarty();
 
-    $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German'),'ur'=>_('Uruguai')));
-    $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);
+    $smarty->assign("goFonQueueLanguageOptions",array('de'=>_('German')));
+    $smarty->assign("goFonQueueStrategyOptions", $this->goFonQueueStrategyOptions);
 
     foreach($this->attributes as $key => $val){
       $smarty->assign($val,$this->$val);  
@@ -167,16 +186,15 @@ class phonequeue extends plugin
   /* Check formular input */
   function check()
   {
-    $message= array();
-  #fixme workaround : Tab is not initialised correct
-         if(!$this->is_account) return($message);
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     if($this->is_number_used()){
       $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)))){
@@ -200,11 +218,15 @@ 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. Your settings can't be saved."));
+    }
+
     // Get Configuration for Mysql database Server
     $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
     $s_parameter  ="";
@@ -215,7 +237,7 @@ class phonequeue extends plugin
     // 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."),
+      return (sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
           $a_SETUP['SERVER'],$a_SETUP['LOGIN']));
     }
 
@@ -232,21 +254,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){
@@ -256,15 +282,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; 
+          }
         }
       }
 
@@ -284,18 +314,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
@@ -303,12 +337,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';
@@ -410,7 +447,7 @@ class phonequeue extends plugin
         $queue["name"]                  = $this->attrs['cn'][0];  
         $queue["timeout"]               = $this->goFonTimeOut; 
         $queue["maxlen"]                = $this->goFonMaxLen;
-        $queue["strategy" ]             = $this->goFonQueueStrategy;
+        $queue["strategy" ]             = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
         $queue["queue_thankyou"]        = $this->goFonQueueThankYou;   
         $queue["queue_reporthold"]      = $this->goFonQueueReportHold; 
         $queue["announce_frequency"]    = $this->goFonAnnounceFrequency;
@@ -460,6 +497,7 @@ class phonequeue extends plugin
       }
 
     }
+    @mysql_close($r_con);
     return(false);
   }
 
@@ -471,7 +509,7 @@ class phonequeue extends plugin
   {
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(goFonConference))", 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){
@@ -523,13 +561,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" ){
@@ -537,12 +576,15 @@ class phonequeue extends plugin
     }else{
       $this->attrs['goFonQueueAnnounceHoldtime'] = "no";
     }
+
+    $this->attrs['goFonQueueStrategy'] = $this->goFonQueueStrategyOptionsR[$this->goFonQueueStrategy];
+
     /* Save data to LDAP */
     $ldap->cd($this->dn);
-    $ldap->modify($this->attrs);
+    $this->cleanup();
+    $ldap->modify ($this->attrs); 
 
-    show_ldap_error($ldap->get_error());
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of object group/phone queue with dn '%s' failed."),$this->dn));
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){
@@ -583,8 +625,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]);
@@ -635,10 +678,72 @@ class phonequeue extends plugin
     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
         $this->attributes, "Save");
     $ldap->cd($this->dn);
-    $ldap->modify($this->attrs);
-    show_ldap_error($ldap->get_error());
+    $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));
+  }
+
+  
+  function getCopyDialog()
+  {
+    $str  = "";
+    $str .= _("Phone number");
+    $str .= "&nbsp;<input type='text' name='telephoneNumber' value='".$this->telephoneNumber."'>";
+    return($str);
+  }
+
+
+  function saveCopyDialog()
+  {
+    if(isset($_POST['telephoneNumber'])){
+      $this->telephoneNumber = $_POST['telephoneNumber'];
+    }
   }
 
+
+    function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Phone"),
+          "plDescription" => _("Phone group"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 0,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("ogroups"), 
+          "plProvidedAcls"=> array(
+
+            "goFonTimeOut"              => _("Timeout"),
+            "goFonMaxLen"               => _("Max queue lenght"),
+            "goFonAnnounceFrequency"    => _(" Announce frequency"),
+            "goFonDialOption_t"         => _("Allow the called user to transfer his call"),
+            "goFonDialOption_T"         => _("Allows calling user to transfer call"),
+            "goFonDialOption_h"         => _("Allow the called to hangup by pressing *"),
+            "goFonDialOption_r"         => _("Ring instead of playing background music"),
+            "goFonDialOption_H"         => _("Allows calling to hangup by pressing *"),
+
+            "goFonMusiconHold"          => _("Music on hold"),
+            "goFonWelcomeMusic"         => _("Welcome music"),
+            "goFonQueueReportHold"      => _("Report hold time"),
+            "goFonQueueYouAreNext"      => _("'You are next' sound"),
+            "goFonQueueThereAre"        => _("'There are' sound"),
+            "goFonQueueCallsWaiting"    => _("'Call waiting' sound"),
+            "goFonQueueThankYou"        => _("'Thank you' sound"),
+            "goFonQueueMinutes"         => _("'Minutes' sound"),
+            "goFonQueueSeconds"         => _("'Second' sound"),
+            "goFonQueueLessThan"        => _("'Less than' sound"),
+            "telephoneNumber"           => _("Queue phone number"),
+            "goFonQueueLanguage"        => _("Language"),
+            "goFonQueueStrategy"        => _("Method"),
+            "goFonQueueAnnounceHoldtime"=> _("Announce holdtime"),
+            "goFonQueueAnnounce"        => _("Announce"),
+            "goFonQueueRetry"           => _("Retry"))
+              ));
+  }
+
+
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: