Code

Fixed a couple of static/non-static error messages
[gosa.git] / plugins / gofax / faxaccount / class_gofaxAccount.inc
index f96b9ab20579dd7751a2c06d45fae7b3e70b7465..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,15 +38,19 @@ class gofaxAccount extends plugin
   var $in_blocklist_dialog= FALSE;
   var $out_blocklist_dialog= FALSE;
   var $current_blocklist= array();
+  var $view_logged = FALSE;
 
-  var $uid ="";
+  /* Copy & paste variables */
+  var $CopyPasteVars=array("facsimileTelephoneNumber");//,"goFaxRBlocklist","goFaxRBlockgroups","goFaxSBlocklist","goFaxSBlockgroups");
 
   /* attribute list for save action */
-  var $attributes= array("goFaxDeliveryMode", "goFaxIsEnabled","goFaxRBlockgroups","facsimileAlternateTelephoneNumber","facsimileTelephoneNumber",
-      "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);
@@ -86,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();
@@ -101,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
      */
@@ -113,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();
 
@@ -135,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();
@@ -144,7 +166,7 @@ class gofaxAccount extends plugin
 
     /* Show tab dialog headers */
     $display= "";
-    if ($this->parent != NULL){
+    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."));
@@ -157,7 +179,7 @@ class gofaxAccount extends plugin
 
     /* Trigger Add local fax alternatives dialog */
     if (isset($_POST['add_local_alternate'])){
-      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber")){
+      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
         $this->locals_dialog= TRUE;    
         $this->dialog= TRUE;   
       }
@@ -165,7 +187,7 @@ class gofaxAccount extends plugin
 
     /* Add alternatives from dialog */
     if (isset($_POST['add_locals_finish']) && isset($_POST['local_list'])){
-      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber")){
+      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
         foreach ($_POST['local_list'] as $val){
           $this->addAlternate($val);
           $this->is_modified= TRUE;
@@ -175,14 +197,14 @@ class gofaxAccount extends plugin
 
     /* Add alternatives */
     if (isset($_POST['add_alternate']) && !empty($_POST['forward_address']) && is_phone_nr($_POST['forward_address'])){ 
-      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber")){
+      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
         $this->addAlternate($_POST['forward_address']);
       }
     }
 
     /* Delete alternate fax number */
     if (isset($_POST['delete_alternate']) && isset($_POST['alternate_list']) && count($_POST['alternate_list'])){ 
-      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber")){
+      if($this->acl_is_writeable("facsimileAlternateTelephoneNumber",$edit_mode)){
         $this->delAlternate ($_POST['alternate_list']);
       }
     }
@@ -190,7 +212,7 @@ class gofaxAccount extends plugin
 
     /* Edit incoming blocklists */
     if (isset($_POST['edit_incoming'])){
-      if($this->acl_is_writeable("goFaxRBlocklist"))  {
+      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);
@@ -549,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 */
@@ -563,7 +586,7 @@ class gofaxAccount extends plugin
 
     $tmp = $this->plInfo();
     foreach($tmp['plProvidedAcls'] as $acl => $desc){
-      $smarty->assign($acl."ACL",$this->getacl($acl));
+      $smarty->assign($acl."ACL",$this->getacl($acl,$edit_mode));
     }
 
     /* Load checkboxes */
@@ -598,13 +621,6 @@ 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 ((isset($this->parent->by_object['mailAccount']->is_account)) && ($this->parent->by_object['mailAccount']->is_account)){
       unset($this->attrs['mail']);
@@ -615,6 +631,8 @@ class gofaxAccount extends plugin
     $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 */
@@ -640,7 +658,7 @@ 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)){
@@ -659,20 +677,21 @@ 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();
 
 
       $tmp = 0+$this->goFaxDeliveryMode;
 
-      if($this->acl_is_writeable("faxtomail")){
+      if($this->acl_is_writeable("faxtomail",$edit_mode)){
         if (isset($_POST["faxtomail"]) && $_POST["faxtomail"] == 1){  
           $tmp |= 32;
         }elseif($tmp & 32){
           $tmp &= (!32);
         }
       }
-      if($this->acl_is_writeable("faxtoprinter")){
+      if($this->acl_is_writeable("faxtoprinter",$edit_mode)){
         if (isset($_POST["faxtoprinter"]) && $_POST["faxtoprinter"] == 1){  
           $tmp |= 64;
         }elseif($tmp & 64){
@@ -681,7 +700,7 @@ class gofaxAccount extends plugin
       }
       $this->goFaxDeliveryMode = $tmp;
 
-      if($this->acl_is_writeable("goFaxIsEnabled")){
+      if($this->acl_is_writeable("goFaxIsEnabled",$edit_mode)){
         if (isset($_POST["goFaxIsEnabled"]) && $_POST["goFaxIsEnabled"] == "1"){
           $this->goFaxIsEnabled= "0";
         } else {
@@ -690,14 +709,16 @@ class gofaxAccount extends plugin
       }
 
     
-      if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail")){
+      if (isset($_POST['mail']) && $this->acl_is_writeable("faxtomail",$edit_mode)){
         $this->mail= $_POST['mail'];
       }
 
       /* Check if mail account is active and correct the internal
          reference to represent the current status. */
-      if (isset($this->parent->by_object['mailAccount']->is_account)&&($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;
+        }
       }
     }
 
@@ -720,10 +741,10 @@ class gofaxAccount extends plugin
       $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 */
@@ -732,6 +753,13 @@ class gofaxAccount extends plugin
     $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 */
@@ -799,7 +827,7 @@ class gofaxAccount extends plugin
 
   /* Return plugin informations for acl handling 
       #FIXME some attributes are still missing in this plugin acls */
-  function plInfo()
+  static function plInfo()
   {
     return (array(  
           "plShortName"     => _("Fax"),