Code

Fixed a couple of static/non-static error messages
[gosa.git] / plugins / gofax / faxaccount / class_gofaxAccount.inc
index 69f71772dc2349bff6d0f1229745a11f12f8cfab..eca2228577a9cc7591826a1803e03327489faafd 100644 (file)
@@ -11,6 +11,10 @@ class gofaxAccount extends plugin
   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;
+
   /* Fax attributes */
   var $goFaxDeliveryMode= "";
   var $facsimileTelephoneNumber= "";
@@ -25,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();
@@ -33,22 +38,40 @@ 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
+     */
+    if(!isset($_SESSION["Fax_Filter"])){
+      $_SESSION['Fax_Filter']['depselect'] = $this->config->current['BASE'];
+    }
+
     if ($dn != "new"){
       /* 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]);
@@ -60,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 */
@@ -71,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();
@@ -84,8 +111,29 @@ class gofaxAccount extends plugin
 
   function execute()
   {
-       /* Call parent execute */
-       plugin::execute();
+    /* 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
+     */
+    if((isset($_GET['act']))&&($_GET['act']=="dep_open")){
+
+      if(strlen(base64_decode($_GET['dep_id']))>= strlen($this->config->current['BASE'])){
+        $_SESSION['Fax_Filter']['depselect']= base64_decode($_GET['dep_id']);
+      }else{
+        $_SESSION['Fax_Filter']['depselect']= $this->config->current['BASE'];
+      }
+    }
+
+    /* 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();
@@ -109,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();
@@ -118,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);
       }
@@ -131,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;
@@ -148,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']);
       }
     }
@@ -169,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);
 
@@ -201,10 +244,17 @@ class gofaxAccount extends plugin
       }
     }
 
+    /* Hickert : 11.11.05
+     * Add selection from divSelelect to our Blocklist 
+     */
     /* Add list to blocklist */
-    if (isset($_POST['add_blocklist']) && isset($_POST['predefined_list'])){
-      $this->current_blocklist= array_merge($this->current_blocklist,
-          $_POST['predefined_list']);
+    if (isset($_POST['add_blocklist'])){
+      foreach($_POST as $name => $value){
+        if(preg_match("/ADDLIST_/i",$name)){
+          $this->current_blocklist= array_merge($this->current_blocklist, array(base64_decode($value)));
+
+        }
+      } 
       $this->current_blocklist= array_unique($this->current_blocklist);
       sort($this->current_blocklist);
       reset($this->current_blocklist);
@@ -231,7 +281,7 @@ class gofaxAccount extends plugin
     }
 
 
-        /* Blocklist edit finished */
+    /* Blocklist edit finished */
     if (isset($_POST['edit_blocklists_finish'])){
 
       /* Incoming or outgoing? */
@@ -264,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'])){
@@ -304,7 +352,6 @@ class gofaxAccount extends plugin
         }
         $faxfilter['fuser']= $s;
       }
-      register_global("faxfilter", $faxfilter);
 
       if ($faxfilter['regex'] != '*' && $faxfilter['regex'] != ""){
         $regex= $faxfilter['regex'];
@@ -318,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]]=
@@ -329,9 +375,6 @@ class gofaxAccount extends plugin
           $attrs['facsimileTelephoneNumber'][0]."]";
       }
 
-
-      
-
       /* Show dialog */
       $smarty->assign("search_image", get_template_path('images/search.png'));
       $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
@@ -355,96 +398,182 @@ class gofaxAccount extends plugin
       $display.= $smarty->fetch (get_template_path('locals.tpl', TRUE, dirname(__FILE__)));
       return ($display);
     }
-      
-    
+
+
     /* Manage incoming blocklists */
     if ($this->in_blocklist_dialog){
+
+      /* This handles the divSelectBox */
+
+      /* 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'];
+      $ldap->cd($base);
+
+      /* Ge all Blocklists */
       $ldap->search ("(objectClass=goFaxRBlock)",array("cn","description"));
       while ($attrs= $ldap->fetch()){
-        $list[$attrs['cn'][0]]=
-          $attrs['description'][0].
-          " [".$attrs['cn'][0]."]";
+
+        /* Generate list depending on description */
+        if(isset($attrs['description'][0])){
+          $list[$attrs['cn'][0]]=
+            $attrs['description'][0].
+            " [".$attrs['cn'][0]."]";
+        }else{
+          $list[$attrs['cn'][0]]= $attrs['cn'][0];
+        }
       }
 
+      /* Create our divselect box */
       $divSel = new divSelectBox("divSelectPredefined");
-      $divSel->setHeight(300);
-      $divSel->setWidth(350);
-      
+      $divSel->setHeight(296);
+
+      /* NEW LIST MANAGMENT
+       * We also need to search for the departments
+       * So we are able to navigate like in konquerer
+       */
+      $this->departments= array();
+   
+      /* Get all departments within the current department */ 
+      $base = $_SESSION['Fax_Filter']['depselect'];
+      $ldap->ls("(objectClass=gosaDepartment)",$base);
+
+      /* Base back is used to go one department up in our ldap tree */
+      $base_back = preg_replace("/^[^,]+,/","",$base);
+
+      /* Only show base_back if it is needed */
+      if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
+        $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]"; 
+      }
+
+      /* Fetch all returned departments an add them to our divlist */
+      while($value = $ldap->fetch()){
+        if($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];
+        }
+      }
+      /* END NEW LIST MANAGMENT
+       */
+
+      // This links specifies the department open link 
+      $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
+
+      /* Insert departments in divsel */
+      foreach($this->departments as $key=> $val){
+        if(!isset($this->config->departments[trim($key)])){
+          $this->config->departments[trim($key)]="";
+        }
+        $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
+        $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
+        $divSel->AddEntry(array($field1,$field2));
+      }
+
+      /* Append predefined Blocklists */
       foreach($list as $entry => $value){
         $divSel->AddEntry(array(
-                            array("string"=>"<a href='?plug=".$_GET['plug']."&add=".base64_encode($entry)."'>
-                                            <img src='images/back.png' border=0 alt='<'>"._("Add")."</a>"),
-                            array("string"=>$entry),
-                            array("string"=>$value,"attach"=>"style='border:0px;'")
-                            ));
+              array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
+              array("string"=>$value,"attach"=>"style='border:0px;'")
+              ));
       }
-              
-
 
       /* 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());
-      
-      if (isset($_POST['department'])){
-        $smarty->assign("department", $_POST['department']);
-      } else {
-        $smarty->assign("department", "");
-      }
-
-
-
       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
       return ($display);
     }
 
     /* Manage outgoing blocklists */
+
     if ($this->out_blocklist_dialog){
-      $ldap->search ("(objectClass=goFaxSBlock)");
+
+      /* This handles the divSelectBox */
+
+      /* 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'];
+      $ldap->cd($base);
+
+      /* Ge all Blocklists */ 
+      $ldap->search ("(objectClass=goFaxSBlock)",array("cn","description"));
       while ($attrs= $ldap->fetch()){
-        if (isset($attrs['description'][0])){
-          $list[$attrs['cn'][0]]= $attrs['cn'][0].
-            " [".$attrs['description'][0]."]";
-        } else {
+        if(isset($attrs['description'][0])){
+          $list[$attrs['cn'][0]]=
+            $attrs['description'][0].
+            " [".$attrs['cn'][0]."]";
+        }else{
           $list[$attrs['cn'][0]]= $attrs['cn'][0];
         }
       }
 
+      /*Create DivSel*/
       $divSel = new divSelectBox("divSelectPredefined");
-      $divSel->setHeight(300);
-      $divSel->setWidth(350);
+      $divSel->setHeight(296);
+
+      /* NEW LIST MANAGMENT
+       * We also need to search for the departments
+       * So we are able to navigate like in konquerer
+       */
+      $this->departments= array();
+      $ldap->ls("(objectClass=gosaDepartment)",$base);
+
+      /* Generate Back url, and append if it is needed */
+      $base_back = preg_replace("/^[^,]+,/","",$base);
+      if((strlen($base_back)>= strlen($this->config->current['BASE']))&&($base!=$this->config->current['BASE'])){
+        $this->departments[preg_replace("/^[^,]+,/","",$base)] = ".. - ["._("back")."]";
+      }
+
+      /* Get all departments */
+      while($value = $ldap->fetch()){
+        if(isset($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];
+        }
+      }
+      /* END NEW LIST MANAGMENT
+       */
+
+      // Defining Links
+      $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
+
+      /* Insert departments in divlist*/
+      foreach($this->departments as $key=> $val){
+        if(!isset($this->config->departments[trim($key)])){
+          $this->config->departments[trim($key)]="";
+        }
 
+        $field1 = array("string" => "<img src='images/folder.png' alt='department'>","attach"=>"style='width:16px;text-align:center;'");
+        $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val),"attach"=>" style='border:none'");
+        $divSel->AddEntry(array($field1,$field2));
+      }
+
+      /* Append Blocklits */
       foreach($list as $entry => $value){
         $divSel->AddEntry(array(
-                            array("string"=>"<a href='?plug=".$_GET['plug']."&add=".base64_encode($entry)."'>
-                                            <img src='images/back.png' border=0 alt='<'>"._("Add")."</a>"),
-                            array("string"=>$entry),
-                            array("string"=>$value,"attach"=>"style='border:0px;'")
-                            ));
+              array("string"=>"<input type='checkbox' value='".base64_encode($entry)."' name='ADDLIST_".base64_encode($entry)."'>"),
+              array("string"=>$value,"attach"=>"style='border:0px;'")
+              ));
       }
 
-
       /* 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());
-      if (isset($_POST['department'])){
-        $smarty->assign("department", $_POST['department']);
-      } else {
-        $smarty->assign("department", "");
-      }
-
       $display.= $smarty->fetch (get_template_path('lists.tpl', TRUE, dirname(__FILE__)));
       return ($display);
     }
 
 
     /* 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 */
@@ -453,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"){
@@ -466,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", "");
     }
 
 
@@ -490,33 +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);
-    $ldap->modify($this->attrs);
-    show_ldap_error($ldap->get_error());
+    $this->cleanup();
+    $ldap->modify ($this->attrs); 
+
+    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 == ""){
@@ -530,14 +658,14 @@ class gofaxAccount extends plugin
     /* 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)){
         $message[]= _("The mail address you've entered is invalid.");
       }
     }
+
     // 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.");
@@ -549,18 +677,30 @@ class gofaxAccount extends plugin
   /* 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 {
@@ -568,32 +708,17 @@ class gofaxAccount extends plugin
         }
       }
 
-      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 ($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;
+        }
       }
     }
 
@@ -612,25 +737,38 @@ class gofaxAccount extends plugin
       $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);
-    $ldap->modify($this->attrs);
-    show_ldap_error($ldap->get_error());
+    $this->cleanup();
+    $ldap->modify ($this->attrs); 
+
+    /* 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));
     }
 
   }
@@ -669,7 +807,50 @@ class gofaxAccount extends plugin
         $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: