Code

msgPool
[gosa.git] / gosa-plugins / gofax / gofax / faxaccount / class_gofaxAccount.inc
index eca2228577a9cc7591826a1803e03327489faafd..c8835201944aaf70c9856a4070ae7b0908ef8121 100644 (file)
@@ -6,12 +6,6 @@ class gofaxAccount extends plugin
   var $plHeadline= "FAX";
   var $plDescription= "This does something";
 
-  /* CLI vars */
-  var $cli_summary= "Manage users fax account";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
-
   /* Department list shown in the divSelectList*/
   var $departments;
 
@@ -50,6 +44,9 @@ class gofaxAccount extends plugin
 
   var $objectclasses= array("goFaxAccount");
 
+  /* Enable multiple edit support */
+  var $multiple_support = TRUE;
+
   function gofaxAccount (&$config, $dn= NULL)
   {
     /* General initialization */
@@ -63,8 +60,10 @@ class gofaxAccount extends plugin
     /* Hickert : 11.11.05
      * Added to be able to handle department selection in divSelelect
      */
-    if(!isset($_SESSION["Fax_Filter"])){
-      $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
+    if(!session::is_set("Fax_Filter")){
+      $Fax_Filter = array();
+      $Fax_Filter['depselect'] = $this->config->current['BASE'];
+      session::set('Fax_Filter',$Fax_Filter);
     }
 
     if ($dn != "new"){
@@ -86,10 +85,7 @@ class gofaxAccount extends plugin
     }
 
     /* Load printer list */
-    if (isset($this->config->data['SERVERS']['CUPS'])){
-      $this->printerList= get_printer_list ($this->config->data['SERVERS']['CUPS']);
-      asort ($this->printerList);
-    }
+    $this->printerList=get_printer_list();
 
     /* Check if the currently selected printer is still available. 
        If not, append current printer to list of available.
@@ -99,13 +95,13 @@ class gofaxAccount extends plugin
     }
 
     /* Get global filter config */
-    if (!is_global("faxfilter")){
+    if (!session::is_set("faxfilter")){
       $ui= get_userinfo();
       $base= get_base_from_people($ui->dn);
       $faxfilter= array( "depselect"       => $base,
           "fuser"            => "*",
           "regex"           => "");
-      register_global("faxfilter", $faxfilter);
+      session::set("faxfilter", $faxfilter);
     }
   }
 
@@ -125,15 +121,17 @@ class gofaxAccount extends plugin
      */
     if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
 
+      $Fax_Filter = session::get('Fax_Filter');
       if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
-        $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
+        $Fax_Filter['depselect']= base64_decode($_GET['dep_id']);
       }else{
-        $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
+        $Fax_Filter['depselect']= $this->config->current['BASE'];
       }
+      session::set('Fax_Filter',$Fax_Filter);
     }
 
     /* Edit mode specifies if we are editing from my accout */
-    $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
+    $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
 
     /* Load smarty stuff */
     $smarty= get_smarty();
@@ -151,30 +149,35 @@ class gofaxAccount extends plugin
       $smarty->assign("has_mailaccount", "true");
     }
 
-    /* Do we need to flip is_account state? */
-    if (isset($_POST['modify_state'])){
-      $this->is_account= !$this->is_account;
-    }
 
-    /* Do we represent a valid account? */
-    if (!$this->is_account && $this->parent === NULL){
-      $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
-        _("This account has no fax extensions.")."</b>";
-      $display.= back_to_main();
-      return ($display);
-    }
+    $display = "";
+    if(!$this->multiple_support_active){    
 
-    /* Show tab dialog headers */
-    $display= "";
-    if ($this->parent !== NULL){
-      if ($this->is_account){
-        $display= $this->show_disable_header(_("Remove fax account"),
-            _("This account has fax features enabled. You can disable them by clicking below."));
-      } else {
-        $display= $this->show_enable_header(_("Create fax account"),
-            _("This account has fax features disabled. You can enable them by clicking below."));
+      /* Do we need to flip is_account state? */
+      if (isset($_POST['modify_state'])){
+        $this->is_account= !$this->is_account;
+      }
+
+      /* Do we represent a valid account? */
+      if (!$this->is_account && $this->parent === NULL){
+        $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
+          msgPool::noValidExtension(_("GOfax"))."</b>";
+        $display.= back_to_main();
         return ($display);
       }
+
+      /* Show tab dialog headers */
+      $display= "";
+      if ($this->parent !== NULL){
+        if ($this->is_account){
+          $display= $this->show_disable_header(_("Remove fax account"),
+              msgPool::featuresEnabled(_("GOfax")));
+        } else {
+          $display= $this->show_enable_header(_("Create fax account"),
+              msgPool::featuresDisabled(_("GOfax")));
+          return ($display);
+        }
+      }
     }
 
     /* Trigger Add local fax alternatives dialog */
@@ -196,7 +199,7 @@ class gofaxAccount extends plugin
     }
 
     /* Add alternatives */
-    if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && is_phone_nr($_POST['forward_address'])){ 
+    if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && tests::is_phone_nr($_POST['forward_address'])){ 
       if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
         $this->addAlternate($_POST['forward_address']);
       }
@@ -234,8 +237,8 @@ class gofaxAccount extends plugin
 
     /* Add number to blocklist (dialog) */
     if (isset($_POST['add_blocklist_number']) && $_POST['block_number'] != ""){
-      if (!is_phone_nr($_POST['block_number'])){
-        print_red (_("You're trying to add an invalid phone number."));
+      if (!tests::is_phone_nr($_POST['block_number'])){
+        msg_dialog::display(_("Error"), msgPool::invalid(_("Phone number")), ERROR_DIALOG);
       } else {
         array_push($this->current_blocklist, $_POST['block_number']);
         $this->current_blocklist= array_unique($this->current_blocklist);
@@ -290,7 +293,7 @@ class gofaxAccount extends plugin
         $this->goFaxRBlockgroups = array();
 
         foreach ($this->current_blocklist as $val){
-          if (is_phone_nr($val)){
+          if (tests::is_phone_nr($val)){
             $this->goFaxRBlocklist[]=$val;
           } else {
             $this->goFaxRBlockgroups[]= $val;
@@ -302,7 +305,7 @@ class gofaxAccount extends plugin
 
         /* Transfer values to ourself */
         foreach ($this->current_blocklist as $val){
-          if (is_phone_nr($val)){
+          if (tests::is_phone_nr($val)){
             $this->goFaxSBlocklist[]=$val;
           } else {
             $this->goFaxSBlockgroups[]= $val;
@@ -339,7 +342,7 @@ class gofaxAccount extends plugin
     if ($this->locals_dialog){
 
       /* Save data */
-      $faxfilter= get_global("faxfilter");
+      $faxfilter= session::get("faxfilter");
       foreach( array("depselect", "fuser", "regex") as $type){
         if (isset($_POST[$type])){
           $faxfilter[$type]= $_POST[$type];
@@ -408,7 +411,8 @@ class gofaxAccount extends plugin
       /* The base specifies the current position in the ldap tree 
        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
        */
-      $base = $_SESSION['Fax_Filter']['depselect'];
+      $Fax_Filter = session::get('Fax_Filter');
+      $base = $Fax_Filter['depselect'];
       $ldap->cd($base);
 
       /* Ge all Blocklists */
@@ -436,7 +440,8 @@ class gofaxAccount extends plugin
       $this->departments= array();
    
       /* Get all departments within the current department */ 
-      $base = $_SESSION['Fax_Filter']['depselect'];
+      $Fax_Filter = session::get('Fax_Filter');
+      $base = $Fax_Filter['depselect'];
       $ldap->ls("(objectClass=gosaDepartment)",$base);
 
       /* Base back is used to go one department up in our ldap tree */
@@ -496,7 +501,8 @@ class gofaxAccount extends plugin
       /* The base specifies the current position in the ldap tree
        * The current base was specified by $_GET['dep_id'] before. Or contains the default value.
        */
-      $base = $_SESSION['Fax_Filter']['depselect'];
+      $Fax_Filter = session::get('Fax_Filter');
+      $base = $Fax_Filter['depselect'];
       $ldap->cd($base);
 
       /* Ge all Blocklists */ 
@@ -607,7 +613,22 @@ class gofaxAccount extends plugin
       $smarty->assign("faxtoprinter", "");
     }
 
-
+    foreach($this->attributes as $attr){
+      if(in_array($attr,$this->multi_boxes)) {
+        $smarty->assign("use_".$attr,TRUE);
+      }else{
+        $smarty->assign("use_".$attr,FALSE);
+      }
+    }
+    foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
+      if(in_array($attr,$this->multi_boxes)) {
+        $smarty->assign("use_".$attr,TRUE);
+      }else{
+        $smarty->assign("use_".$attr,FALSE);
+      }
+    }
+  
+    $smarty->assign("multiple_support",$this->multiple_support_active);
     $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
     return ($display);
   }
@@ -633,7 +654,9 @@ class gofaxAccount extends plugin
 
     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/fax account with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+    }
 
     /* Optionally execute a command after we're done */
     $this->handle_post_events('remove',array("uid"=> $this->uid));
@@ -648,11 +671,11 @@ class gofaxAccount extends plugin
 
     /* must: facsimileTelephoneNumber */
     if ($this->facsimileTelephoneNumber == ""){
-      $message[]= _("The required field 'Fax' is not set.");
+      $message[]= msgPool::required(_("Faxi number"));
     }
 
-    if (!is_phone_nr($this->facsimileTelephoneNumber)){
-      $message[]= _("Please enter a valid telephone number in the 'Fax' field.");
+    if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
+      $message[]= msgPool::invalid(_("Fax number"),$this->facsimileTelephoneNumber,"/[0-9]/");
     }
 
     /* IF mail is specified (which is only the case if there's no mail account
@@ -660,15 +683,15 @@ class gofaxAccount extends plugin
     if (@isset($this->parent->by_object['mailAccount']) &&
         $this->goFaxDeliveryMode & 32){
       if ($this->mail == ""){
-        $message[]= _("Mail delivery is checked, but no address has been specified.");
-      } elseif (!is_email($this->mail)){
-        $message[]= _("The mail address you've entered is invalid.");
+        $message[]= _("Mail delivery is requested without target address!");
+      } elseif (!tests::is_email($this->mail)){
+        $message[]= msgPool::invalid(_("Mail address"),"","",_("your-name@your-domain.com"));
       }
     }
 
     // IE Fix, IE lets you choose disabled option, stupid browser ... 
     if((empty($this->goFaxPrinter))&&($this->goFaxDeliveryMode & 64)){
-      $message[]= _("Deliver fax to printer, is only possible if valid printer is given. Please correct your choice.");
+      $message[]= _("Printing is requested without a target printer!");
     }
 
     return ($message);
@@ -677,7 +700,7 @@ class gofaxAccount extends plugin
   /* Save data to object */
   function save_object()
   {
-    $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
+    $edit_mode = (!is_object($this->parent) && !session::is_set('edit'));
     if (isset($_POST['faxTab'])){
       plugin::save_object();
 
@@ -760,7 +783,9 @@ class gofaxAccount extends plugin
       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     }
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/fax account with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+    }
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){
@@ -851,6 +876,103 @@ class gofaxAccount extends plugin
             "goFaxLanguage"                     => _("Language"))
           ));
   }
+
+  /* Multiple edit support 
+   */
+  
+  /* Execute */
+  function multiple_execute()
+  {
+    return($this->execute());
+  }
+
+  function multiple_save_object()
+  {
+    if (isset($_POST['faxTab'])){
+      plugin::multiple_save_object();
+      foreach(array("goFaxIsEnabled","edit_outgoing","edit_incoming","faxtomail","faxtoprinter") as $attr){
+        if(isset($_POST["use_".$attr])){
+          $this->multi_boxes[] = $attr;
+        }
+      }
+
+      $tmp = 0+$this->goFaxDeliveryMode;
+      if(in_array("faxtomail",$this->multi_boxes)){
+        if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){
+          $tmp |= 32;
+        }elseif($tmp & 32){
+          $tmp &= (!32);
+        }
+      }
+      if(in_array("faxtoprinter",$this->multi_boxes)){
+        if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){
+          $tmp |= 64;
+        }elseif($tmp & 64){
+          $tmp &= !64;
+        }
+      }
+      $this->goFaxDeliveryMode = $tmp;
+
+        if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
+          $this->goFaxIsEnabled= "0";
+        } else {
+          $this->goFaxIsEnabled= "1";
+        }
+      if (isset($_POST['mail']) && in_array("mail",$this->multi_boxes)){
+        $this->mail= $_POST['mail'];
+      }
+    }
+  }
+
+  function get_multi_edit_values()
+  {
+    $ret = plugin::get_multi_edit_values();
+    if(in_array("goFaxIsEnabled",$this->multi_boxes)){
+      $ret['goFaxIsEnabled'] = $this->goFaxIsEnabled;
+    }
+    if(in_array("faxtoprinter",$this->multi_boxes)){
+      $ret['faxtoprinter'] = $this->goFaxDeliveryMode & 64;
+    }
+    if(in_array("faxtomail",$this->multi_boxes)){
+      $ret['faxtomail'] = $this->goFaxDeliveryMode & 32;
+    }
+
+    if(in_array("edit_incoming",$this->multi_boxes)){
+      $ret['goFaxRBlocklist'] = $this->goFaxRBlocklist;
+      $ret['goFaxRBlockgroups'] = $this->goFaxRBlockgroups;
+    }
+    if(in_array("edit_outgoing",$this->multi_boxes)){
+      $ret['goFaxSBlocklist'] = $this->goFaxSBlocklist;
+      $ret['goFaxSBlockgroups'] = $this->goFaxSBlockgroups;
+    }
+    return($ret);
+  }
+
+  function multiple_check()
+  {
+    $message = plugin::multiple_check();
+    return($message);
+  }
+
+  function set_multi_edit_values($values)
+  {
+    plugin::set_multi_edit_values($values);
+
+    if(isset($values['faxtoprinter'])){
+      if($values['faxtoprinter']){
+        $this->goFaxDeliveryMode |= 64;
+      }else{
+        $this->goFaxDeliveryMode &= !64;
+      }
+    }
+    if(isset($values['faxtomail'])){
+      if($values['faxtomail']){
+        $this->goFaxDeliveryMode |= 32;
+      }else{
+        $this->goFaxDeliveryMode &= !32;
+      }
+    }
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: