Code

Fixed a couple of static/non-static error messages
[gosa.git] / plugins / gofax / faxaccount / class_gofaxAccount.inc
index a8658b2ed137f02b386157d6c180be8df2cd0642..eca2228577a9cc7591826a1803e03327489faafd 100644 (file)
@@ -29,6 +29,7 @@ class gofaxAccount extends plugin
   var $goFaxSBlockgroups= array();
   var $mail= "";
   var $facsimileAlternateTelephoneNumber= array();
+  var $fax_formats = array("pdf","ps","png","mtiff","tiff");  
 
   /* Internal variables */
   var $printerList= array();
@@ -37,17 +38,27 @@ class gofaxAccount extends plugin
   var $in_blocklist_dialog= FALSE;
   var $out_blocklist_dialog= FALSE;
   var $current_blocklist= array();
+  var $view_logged = FALSE;
+
+  /* Copy & paste variables */
+  var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
 
   /* attribute list for save action */
-  var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled",
-      "goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail");
+  var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","facsimileAlternateTelephoneNumber","goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups","goFaxPrinter", "goFaxDivertNumber", "goFaxLanguage", "goFaxFormat", "mail","facsimileTelephoneNumber");
+
+  var $uid ="";
+
   var $objectclasses= array("goFaxAccount");
 
-  function gofaxAccount ($config, $dn= NULL)
+  function gofaxAccount (&$config, $dn= NULL)
   {
     /* General initialization */
     plugin::plugin ($config, $dn);
 
+    /* Set uid, it is used in handle_post_events */
+    if(isset($this->attrs['uid'])){
+      $this->uid = $this->attrs['uid'][0];
+    }
 
     /* Hickert : 11.11.05
      * Added to be able to handle department selection in divSelelect
@@ -60,7 +71,7 @@ class gofaxAccount extends plugin
       /* Get arrays */
       foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
             "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
-
+        $this->$val =array();
         if (isset($this->attrs["$val"]["count"])){
           for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
             array_push($this->$val, $this->attrs["$val"][$i]);
@@ -72,9 +83,6 @@ class gofaxAccount extends plugin
       if (in_array("gosaMailAccount", $this->attrs['objectClass'])){
         $this->has_mailAccount= TRUE;
       }
-      if (isset($this->attrs["facsimileTelephoneNumber"][0])){
-        $this->facsimileTelephoneNumber= $this->attrs["facsimileTelephoneNumber"][0];
-      }
     }
 
     /* Load printer list */
@@ -83,6 +91,13 @@ class gofaxAccount extends plugin
       asort ($this->printerList);
     }
 
+    /* Check if the currently selected printer is still available. 
+       If not, append current printer to list of available.
+       It could be possible, that we are not allowed to view printers and so the list is empty ...  */
+    if(!empty($this->goFaxPrinter) && !isset($this->printerList[$this->goFaxPrinter])) {
+      $this->printerList[$this->goFaxPrinter] = "[".$this->goFaxPrinter."]";
+    }
+
     /* Get global filter config */
     if (!is_global("faxfilter")){
       $ui= get_userinfo();
@@ -98,6 +113,13 @@ class gofaxAccount extends plugin
   {
     /* Call parent execute */
     plugin::execute();
+
+    /* Log view */
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","users/".get_class($this),$this->dn);
+    }
+
     /* Hickert : 11.11.05
      * Added to be able to handle department selection in divSelelect
      */
@@ -110,6 +132,9 @@ class gofaxAccount extends plugin
       }
     }
 
+    /* Edit mode specifies if we are editing from my accout */
+    $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
+
     /* Load smarty stuff */
     $smarty= get_smarty();
 
@@ -132,7 +157,7 @@ class gofaxAccount extends plugin
     }
 
     /* Do we represent a valid account? */
-    if (!$this->is_account && $this->parent == NULL){
+    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();
@@ -141,12 +166,12 @@ class gofaxAccount extends plugin
 
     /* Show tab dialog headers */
     $display= "";
-    if ($this->parent != NULL){
+    if ($this->parent !== NULL){
       if ($this->is_account){
-        $display= $this->show_header(_("Remove fax 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_header(_("Create fax account"),
+        $display= $this->show_enable_header(_("Create fax account"),
             _("This account has fax features disabled. You can enable them by clicking below."));
         return ($display);
       }
@@ -154,15 +179,15 @@ class gofaxAccount extends plugin
 
     /* Trigger Add local fax alternatives dialog */
     if (isset($_POST['add_local_alternate'])){
-      $this->locals_dialog= TRUE;      
-      $this->dialog= TRUE;     
+      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
+        $this->locals_dialog= TRUE;    
+        $this->dialog= TRUE;   
+      }
     }
 
     /* Add alternatives from dialog */
-    if (isset($_POST['add_locals_finish'])){
-      if (isset($_POST['local_list']) &&
-          chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
-
+    if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
+      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
         foreach ($_POST['local_list'] as $val){
           $this->addAlternate($val);
           $this->is_modified= TRUE;
@@ -171,20 +196,15 @@ class gofaxAccount extends plugin
     }
 
     /* Add alternatives */
-    if (isset($_POST['add_alternate'])){
-      if ($_POST['forward_address'] != "" &&
-          is_phone_nr($_POST['forward_address']) &&
-          chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
-
+    if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && is_phone_nr($_POST['forward_address'])){ 
+      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
         $this->addAlternate($_POST['forward_address']);
       }
     }
 
     /* Delete alternate fax number */
-    if (isset($_POST['delete_alternate'])){
-      if (isset($_POST['alternate_list']) && count($_POST['alternate_list']) &&
-          chkacl ($this->acl, "facsimileAlternateTelephoneNumber") == ""){
-
+    if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){ 
+      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
         $this->delAlternate ($_POST['alternate_list']);
       }
     }
@@ -192,19 +212,19 @@ class gofaxAccount extends plugin
 
     /* Edit incoming blocklists */
     if (isset($_POST['edit_incoming'])){
-      $this->current_blocklist= array_merge($this->goFaxRBlocklist,
-          $this->goFaxRBlockgroups);
-      sort($this->current_blocklist);
-      reset($this->current_blocklist);
+      if($this->acl_is_writeable("goFaxRBlocklist",$edit_mode))  {
+        $this->current_blocklist= array_merge($this->goFaxRBlocklist,$this->goFaxRBlockgroups);
+        sort($this->current_blocklist);
+        reset($this->current_blocklist);
 
-      $this->in_blocklist_dialog= TRUE;
-      $this->dialog= TRUE;
+        $this->in_blocklist_dialog= TRUE;
+        $this->dialog= TRUE;
+      }
     }
 
     /* Edit outgoing blocklists */
     if (isset($_POST['edit_outgoing'])){
-      $this->current_blocklist= array_merge($this->goFaxSBlocklist,
-          $this->goFaxSBlockgroups);
+      $this->current_blocklist= array_merge($this->goFaxSBlocklist,$this->goFaxSBlockgroups);
       sort($this->current_blocklist);
       reset($this->current_blocklist);
 
@@ -294,10 +314,8 @@ class gofaxAccount extends plugin
 
 
     /* Set departments */
-    if ($this->locals_dialog ||
-        $this->in_blocklist_dialog ||
-        $this->out_blocklist_dialog){
-
+    if ($this->locals_dialog || $this->in_blocklist_dialog || $this->out_blocklist_dialog){
+      
       $list= array ();
       $ldap= $this->config->get_ldap_link();
       if (isset ($_POST['department'])){
@@ -334,7 +352,6 @@ class gofaxAccount extends plugin
         }
         $faxfilter['fuser']= $s;
       }
-      register_global("faxfilter", $faxfilter);
 
       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
         $regex= $faxfilter['regex'];
@@ -348,9 +365,8 @@ class gofaxAccount extends plugin
       }
 
       $base= $faxfilter['depselect'];
-      $acl= array($this->config->current['BASE'] => ":all");
-      print "(&(objectClass=goFaxAccount)$filter)";
-      $res= get_list($acl, "(&(objectClass=goFaxAccount)$filter)", TRUE, $base, array("sn", "givenName", "facsimileTelephoneNumber"), TRUE);
+      $res= get_list("(&(objectClass=goFaxAccount)$filter)", "gofax", $base, 
+                     array("sn", "givenName", "facsimileTelephoneNumber"), GL_SIZELIMIT | GL_SUBSEARCH);
 
       foreach ($res as $attrs){
         $list[$attrs['facsimileTelephoneNumber'][0]]=
@@ -434,7 +450,7 @@ class gofaxAccount extends plugin
       /* Fetch all returned departments an add them to our divlist */
       while($value = $ldap->fetch()){
         if($value["description"][0]!=".."){
-          $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
+          $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
         }else{
           $this->departments[$value['dn']]=$value["description"][0];
         }
@@ -465,7 +481,6 @@ class gofaxAccount extends plugin
 
       /* Show dialog */
       $smarty->assign("cblocklist", $this->current_blocklist);
-      $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
       $smarty->assign("departments", $this->config->idepartments);
       $smarty->assign("divSelectPredefined", $divSel->DrawList());
       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
@@ -516,7 +531,7 @@ class gofaxAccount extends plugin
       /* Get all departments */
       while($value = $ldap->fetch()){
         if(isset($value["description"][0])){
-          $this->departments[$value['dn']]=convert_department_dn($value['dn'])." - [".$value["description"][0]."]";
+          $this->departments[$value['dn']]=@LDAP::fix(convert_department_dn($value['dn'])." - [".$value["description"][0]."]");
         }else{
           $this->departments[$value['dn']]=$value["description"][0];
         }
@@ -548,7 +563,6 @@ class gofaxAccount extends plugin
 
       /* Show dialog */
       $smarty->assign("cblocklist", $this->current_blocklist);
-      $smarty->assign("goFaxBlockListACL", chkacl($this->acl, "goFaxBlockList"));
       $smarty->assign("departments", $this->config->idepartments);
       $smarty->assign("divSelectPredefined", $divSel->DrawList());
       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
@@ -557,8 +571,9 @@ class gofaxAccount extends plugin
 
 
     /* Show main page */
-    $smarty->assign("languages", $this->config->data['MAIN']['LANGUAGES']);
-    $smarty->assign("formats", $this->config->data['MAIN']['FAXFORMATS']);
+    $smarty->assign("languages", get_languages(TRUE));
+
+    $smarty->assign("formats",  $this->fax_formats);
     $smarty->assign("printers", $this->printerList);
 
     /* Load attributes */
@@ -567,10 +582,12 @@ class gofaxAccount extends plugin
           "facsimileAlternateTelephoneNumber", "mail") as $val){
 
       $smarty->assign("$val", $this->$val);
-      $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
     }
-    $smarty->assign("goFaxRBlockgroupsACL", chkacl($this->acl, "goFaxRBlockgroups"));
-    $smarty->assign("goFaxSBlockgroupsACL", chkacl($this->acl, "goFaxSBlockgroups"));
+
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $acl => $desc){
+      $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
+    }
 
     /* Load checkboxes */
     if ($this->goFaxIsEnabled == "1"){
@@ -580,14 +597,14 @@ class gofaxAccount extends plugin
     }
     /* goFaxAccount has "mail" as must! Block if no mailaddress is specified... */
     if ($this->goFaxDeliveryMode & 32) {
-      $smarty->assign("fax_to_mail", "checked");
+      $smarty->assign("faxtomail", "checked");
     } else {
-      $smarty->assign("fax_to_mail", "");
+      $smarty->assign("faxtomail", "");
     }
     if ($this->goFaxDeliveryMode & 64) {
-      $smarty->assign("fax_to_printer", "checked");
+      $smarty->assign("faxtoprinter", "checked");
     } else {
-      $smarty->assign("fax_to_printer", "");
+      $smarty->assign("faxtoprinter", "");
     }
 
 
@@ -604,35 +621,30 @@ class gofaxAccount extends plugin
 
     plugin::remove_from_parent();
 
-    /* Zero out arrays */
-    foreach (array("goFaxRBlocklist", "goFaxRBlockgroups", "goFaxSBlocklist",
-          "goFaxSBlockgroups", "facsimileAlternateTelephoneNumber") as $val){
-
-      $this->attrs[$val]= array();
-    }
-
     /* Adapt mail settings if needed */
-    if ($this->parent->by_object['mailAccount']->is_account){
+    if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
       unset($this->attrs['mail']);
     }
 
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->dn);
     $this->cleanup();
-$ldap->modify ($this->attrs); 
+    $ldap->modify ($this->attrs); 
 
-    show_ldap_error($ldap->get_error());
+    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));
 
     /* Optionally execute a command after we're done */
-    $this->handle_post_events('remove');
+    $this->handle_post_events('remove',array("uid"=> $this->uid));
   }
 
 
   /* Check formular input */
   function check()
   {
-    /* Reset message array */
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     /* must: facsimileTelephoneNumber */
     if ($this->facsimileTelephoneNumber == ""){
@@ -646,7 +658,7 @@ $ldap->modify ($this->attrs);
     /* IF mail is specified (which is only the case if there's no mail account
        present), check if it's valid..  */
     if (@isset($this->parent->by_object['mailAccount']) &&
-        $this->goFaxDeliveryMode && 32){
+        $this->goFaxDeliveryMode & 32){
       if ($this->mail == ""){
         $message[]= _("Mail delivery is checked, but no address has been specified.");
       } elseif (!is_email($this->mail)){
@@ -665,18 +677,30 @@ $ldap->modify ($this->attrs);
   /* Save data to object */
   function save_object()
   {
+    $edit_mode = (!is_object($this->parent) && !isset($_SESSION['edit']));
     if (isset($_POST['faxTab'])){
       plugin::save_object();
 
-      /* Adapt combobox values */
-      $tmp= 0;
-      if (isset($_POST["fax_to_mail"]) && $_POST["fax_to_mail"] == 1){
-        $tmp+= 32;
+
+      $tmp = 0+$this->goFaxDeliveryMode;
+
+      if($this->acl_is_writeable("faxtomail",$edit_mode)){
+        if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){  
+          $tmp |= 32;
+        }elseif($tmp & 32){
+          $tmp &= (!32);
+        }
       }
-      if (isset($_POST["fax_to_printer"]) && $_POST["fax_to_printer"] == 1){
-        $tmp+= 64;
+      if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
+        if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){  
+          $tmp |= 64;
+        }elseif($tmp & 64){
+          $tmp &= !64;
+        }
       }
-      if (chkacl ($this->acl, "goFaxIsEnabled") == ""){
+      $this->goFaxDeliveryMode = $tmp;
+
+      if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
           $this->goFaxIsEnabled= "0";
         } else {
@@ -684,32 +708,17 @@ $ldap->modify ($this->attrs);
         }
       }
 
-      if (isset($_POST['facsimileTelephoneNumber'])){
-        if ($_POST['facsimileTelephoneNumber'] != $this->facsimileTelephoneNumber){
-          $this->is_modified= TRUE;
-        }
-        $this->facsimileTelephoneNumber= $_POST['facsimileTelephoneNumber'];
-      }
-
-      if (isset($_POST['mail'])){
-        if ($this->mail != $_POST['mail']){
-          $this->is_modified= TRUE;
-        }
+    
+      if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
         $this->mail= $_POST['mail'];
       }
 
-      /* Write to object */
-      if (chkacl ($this->acl, "goFaxDeliveryMode") == ""){
-        if ($tmp != $this->goFaxDeliveryMode){
-          $this->is_modified= TRUE;
-        }
-        $this->goFaxDeliveryMode= "$tmp";
-      }
-
       /* Check if mail account is active and correct the internal
          reference to represent the current status. */
-      if (isset($this->parent)&&($this->parent->by_object['mailAccount']->is_account)){
-        $this->has_mailAccount= TRUE;
+      if(isset($this->parent)){
+        if (isset($this->parent->by_object['mailAccount']->is_account)&&($this->parent->by_object['mailAccount']->is_account)){
+          $this->has_mailAccount= TRUE;
+        }
       }
     }
 
@@ -728,27 +737,38 @@ $ldap->modify ($this->attrs);
       $this->attrs[$val]= $this->$val;
     }
 
+    if(!$this->attrs['goFaxDeliveryMode']){
+      $this->attrs['goFaxDeliveryMode'] = 0;
+    }
+  
+    /* Do not save mail address ... it was possibly changed by mail plugin */
     /* Adapt mail settings if needed */
-    unset($this->attrs['mail']);
-    if (!$this->has_mailAccount && $this->goFaxDeliveryMode && 32){
-      $this->attrs['mail']= $this->mail;
+    if ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
+      unset($this->attrs['mail']);
     }
 
     /* Write back to ldap */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->dn);
     $this->cleanup();
-$ldap->modify ($this->attrs); 
+    $ldap->modify ($this->attrs); 
 
-    show_ldap_error($ldap->get_error());
+    /* Log last action */
+    if($this->initially_was_account){
+      new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+    }else{
+      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));
 
     /* Optionally execute a command after we're done */
     if ($this->initially_was_account == $this->is_account){
       if ($this->is_modified){
-        $this->handle_post_events("mofify");
+        $this->handle_post_events("mofidy",array("uid" => $this->uid));
       }
     } else {
-      $this->handle_post_events("add");
+      $this->handle_post_events("add",array("uid" => $this->uid));
     }
 
   }
@@ -787,7 +807,50 @@ $ldap->modify ($this->attrs);
         $this->facsimileAlternateTelephoneNumber);
   }
 
+  function getCopyDialog()
+  {
+    $str    = "";
+    $smarty = get_smarty();
+    $smarty->assign("facsimileTelephoneNumber", $this->facsimileTelephoneNumber);
+    $str['string']   = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
+    $str['status'] ="";
+    return($str);
+  }
 
+  function SaveCopyDialog()
+  {
+    if(isset($_POST['facsimileTelephoneNumber'])){
+      $this->facsimileTelephoneNumber = $_POST['facsimileTelephoneNumber'];
+    }
+  }
+
+
+  /* Return plugin informations for acl handling 
+      #FIXME some attributes are still missing in this plugin acls */
+  static function plInfo()
+  {
+    return (array(  
+          "plShortName"     => _("Fax"),
+          "plDescription"   => _("Fax account settings"),
+          "plSelfModify"    => TRUE,
+          "plDepends"       => array("user"),
+          "plPriority"      => 6,             
+          "plSection"       => "personal",  
+          "plCategory"      => array("users"),
+          "plOptions"       => array(),
+
+          "plProvidedAcls"  => array(
+            "goFaxIsEnabled"                    => _("Enable/Disable fax"),
+            "goFaxRBlocklist"                   => _("Receive blocklist"),
+            "goFaxSBlocklist"                   => _("Send blocklist"),
+            "facsimileTelephoneNumber"          => _("Fax number"), // goFaxDeliveryMode
+            "facsimileAlternateTelephoneNumber" => _("Alternate fax number"), // goFaxDeliveryMode
+            "faxtomail"                         => _("Deliver fax as mail"),
+            "faxtoprinter"                      => _("Deliver fax to printer"),
+            "goFaxFormat"                       => _("Delivery format"),
+            "goFaxLanguage"                     => _("Language"))
+          ));
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: