Code

Fixed a couple of static/non-static error messages
[gosa.git] / plugins / admin / systems / class_glpiPrinterAccount.inc
index 4ee03e31ab7069c4b318b61ca5d43537205b99e1..049249cd5aaba106cd2b8d8abc872c3e44967888 100644 (file)
@@ -66,12 +66,14 @@ class glpiPrinterAccount extends plugin
   var $usedAttachments  = array();  // Used Attachments 
   var $usedCartridges   = array();  // Used Cartridges
 
+  var $view_logged      = FALSE;
+
   /* Contructor 
      Sets default values and checks if we already have an existing glpi account
    */
-  function glpiPrinterAccount ($config, $dn= NULL)
+  function glpiPrinterAccount (&$config, $dn= NULL, $parent= NULL)
   {
-    plugin::plugin ($config, $dn);
+    plugin::plugin ($config, $dn, $parent);
     $this->ui= get_userinfo();
 
     $this->is_account = false;
@@ -132,22 +134,32 @@ class glpiPrinterAccount extends plugin
     /* Call parent execute */
     plugin::execute();
 
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","printer/".get_class($this),$this->dn);
+    }
+
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
 
-    $smarty->assign("CartridgesACL",chkacl($this->acl,"Cartridges"));
+    $smarty->assign("CartridgesACL",$this->getacl("Cartridges"));
 
     /*  Assign smarty defaults 
         To avoid undefined indexes, if there is an error with the glpi db
      */ 
-    foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers","Attachments","AttachmentKeys","CartridgeKeys","Cartridges") as $attr){
+    foreach(array("PrinterTypeKeys","PrinterTypes","ManufacturerKeys","Manufacturers",
+                  "Attachments","AttachmentKeys","CartridgeKeys","Cartridges") as $attr){
       $smarty->assign($attr,array());
-      $smarty->assign($attr."ACL"," disabled ");
     }
     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","comments","flags_serial","flags_par","flags_usb","AttachmentsDiv") as $attr){
       $smarty->assign($attr,"");
-      $smarty->assign($attr."ACL"," disabled ");
+    }
+
+    /* Assign acls */
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translation){
+      $smarty->assign($name."ACL",$this->getacl($name));
     }
 
     /* Check if there is a glpi database server defined 
@@ -190,16 +202,20 @@ class glpiPrinterAccount extends plugin
      */
 
     /* Do we need to flip is_account state? */
-    if (isset($_POST['modify_state'])){
-      $this->is_account= !$this->is_account;
+    if(isset($_POST['modify_state'])){
+      if($this->is_account && $this->acl_is_removeable()){
+        $this->is_account= FALSE;
+      }elseif(!$this->is_account && $this->acl_is_createable()){
+        $this->is_account= TRUE;
+      }
     }
 
     /* Show tab dialog headers */
     if ($this->is_account){
-      $display= $this->show_header(_("Remove inventory"),
+      $display= $this->show_disable_header(_("Remove inventory"),
           _("This server has inventory features enabled. You can disable them by clicking below."));
     } else {
-      $display= $this->show_header(_("Add inventory"),
+      $display= $this->show_enable_header(_("Add inventory"),
           _("This server has inventory features disabled. You can enable them by clicking below."));
       return ($display);
     }
@@ -211,7 +227,7 @@ class glpiPrinterAccount extends plugin
      */
 
     /* Rename was requested */
-    if(isset($_POST['Rename_PType_OK'])){
+    if(isset($_POST['Rename_PType_OK']) && $this->acl_is_writeable("type")){
       $tmp = $this->handle->getPrinterTypes();
       $allok = true;
       foreach($tmp as $id => $name){
@@ -235,7 +251,7 @@ class glpiPrinterAccount extends plugin
 
     /* Printer type management
      */
-    if(isset($_POST['edit_type'])){
+    if(isset($_POST['edit_type']) && $this->acl_is_writeable("type")){
       $this->dialog = true;
       $this->edit_type=true;
     }
@@ -249,7 +265,7 @@ class glpiPrinterAccount extends plugin
 
     /* This appends a new printer to our sytem types
      */
-    if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){
+    if((isset($_POST['add_type']))&&(!empty($_POST['type_string'])) && $this->acl_is_writeable("type")){
     
       $tmp = $this->handle->getPrinterTypes();
       $allok = true;
@@ -267,7 +283,7 @@ class glpiPrinterAccount extends plugin
 
     /* Remove selected type from our printer types list
      */
-    if((isset($_POST['del_type']))&&(!empty($_POST['select_type']))){
+    if((isset($_POST['del_type']))&&(!empty($_POST['select_type'])) && $this->acl_is_writeable("type")){
       $tmp = $this->handle->is_printerTypeUsed($_POST['select_type']);
       if(count($tmp)){
         $str = "";
@@ -283,7 +299,7 @@ class glpiPrinterAccount extends plugin
 
     /* Rename selected printer type to given string
      */
-    if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))||($this->rename)){
+    if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))||($this->rename) && $this->acl_is_writeable("type")){
       $this->rename = true;
 
       $smarty->assign("Method","rename");
@@ -321,7 +337,7 @@ class glpiPrinterAccount extends plugin
 
     /* Open dialog which allows to edit the manufacturers
      */
-    if(isset($_POST['edit_manufacturer'])){
+    if(isset($_POST['edit_manufacturer']) && $this->acl_is_writeable("FK_glpi_enterprise")){
       $this->cur_dialog = new glpiManufacturer($this->config,$this->dn);
       $this->dialog = true;
       $this->editManufacturer =true;
@@ -345,14 +361,14 @@ class glpiPrinterAccount extends plugin
     /* Show dialog to select a new contact person
      * Select a contact person
      */
-    if(isset($_POST['SelectContactPerson'])){
+    if(isset($_POST['SelectContactPerson']) && $this->acl_is_writeable("contact_num")){
       $this->addUser = "contact";
       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
     }
 
     /* Selecte technical responsible person
      */
-    if(isset($_POST['SelectTechPerson'])){
+    if(isset($_POST['SelectTechPerson']) && $this->acl_is_writeable("tech_num")){
       $this->addUser ="tech";
       $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
     }
@@ -376,7 +392,8 @@ class glpiPrinterAccount extends plugin
       if(!in_array($id,$users)){
 
         /* If this user doesn't exists in glpi db, we must create him */
-        $atr = $ldap->fetch($ldap->cat($id));
+        $ldap->cat($id, array('cn', 'mail', 'telephoneNumber'));
+        $atr = $ldap->fetch();
         $tmp = array();
         $use = array( "cn"              =>"name",
             "mail"            =>"email",
@@ -417,7 +434,7 @@ class glpiPrinterAccount extends plugin
     
     /* Attachment pool was closed with use
      */
-    if(isset($_POST['UseAttachment'])){
+    if(isset($_POST['UseAttachment']) && $this->acl_is_writeable("Attachments")){
       if(count($this->cur_dialog->check())){
         foreach($this->cur_dialog->check() as $msg){
           print_red($msg);
@@ -439,7 +456,7 @@ class glpiPrinterAccount extends plugin
 
     /* Open Attachment pool to add/edit Attachments
      */
-    if(isset($_POST['AddAttachment'])){
+    if(isset($_POST['AddAttachment']) && $this->acl_is_writeable("Attachments")){
       $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
       $this->dialog = true;
     }
@@ -448,7 +465,7 @@ class glpiPrinterAccount extends plugin
      */
     $once = true;
     foreach($_POST as $name => $value){
-      if((preg_match("/^delAttachment_/",$name))&&($once)){
+      if((preg_match("/^delAttachment_/",$name))&&($once) && $this->acl_is_writeable("Attachments")){
         $once= false;
         $name = preg_replace("/^delAttachment_/","",$name);
         $entry = preg_replace("/_.*$/","",$name);
@@ -457,7 +474,7 @@ class glpiPrinterAccount extends plugin
         }
       }
     }
-    if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments']))){
+    if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments'])) && $this->acl_is_writeable("Attachments")){
       if(isset($this->usedAttachments[$_POST['Attachments']])){
         unset($this->usedAttachments[$_POST['Attachments']]);
       }
@@ -489,7 +506,7 @@ class glpiPrinterAccount extends plugin
 
     /* Remove cartridge  
      */
-    if((isset($_POST['RemoveCartridge']))&&(isset($_POST['Cartridges']))){
+    if((isset($_POST['RemoveCartridge']))&&(isset($_POST['Cartridges'])) && $this->acl_is_writeable("ManageCartridges")){
 
       foreach($_POST['Cartridges'] as $cartID){
 
@@ -505,7 +522,7 @@ class glpiPrinterAccount extends plugin
 
     /* Open Attachment pool to add/edit Attachments
      */
-    if(isset($_POST['AddCartridge'])){
+    if(isset($_POST['AddCartridge']) && $this->acl_is_writeable("ManageCartridges")){
       $this->cur_dialog = new glpiPrinterCartridges($this->config,$this->dn,$this->type);
       $this->dialog = true;
     }
@@ -517,7 +534,7 @@ class glpiPrinterAccount extends plugin
     /* if( cur_dialog != false || cur_dialog != NULL) 
      * There is a dialog which wants to be displayed 
      */
-    if($this->cur_dialog){
+    if($this->cur_dialog && is_object($this->cur_dialog)){
       $this->cur_dialog->save_object();
       $this->dialog=true;
       $this->cur_dialog->parent = &$this;
@@ -533,20 +550,12 @@ class glpiPrinterAccount extends plugin
     /* Assign smarty defaults */ 
     foreach(array("PrinterTypes","PrinterTypeKeys","Manufacturers","TechnicalResponsibles","Attachments","Cartridges") as $attr){
       $smarty->assign($attr,array());
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
     }
 
     /* Assign some vars to smarty 
      */
     foreach(array("type","FK_glpi_enterprise","tech_num","contact_num","flags_serial","flags_par","flags_usb") as $attr){
       $smarty->assign($attr,"");
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
-    }
-
-
-    /* Assign ACLs to smarty*/
-    foreach($this->attributes as $attr){
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
     }
 
     $smarty->assign("comments",               $this->comments);
@@ -599,7 +608,8 @@ class glpiPrinterAccount extends plugin
      *  Assign contact and technical responsible person 
      */
     if(isset($users[$this->contact_num])){
-      $tr = $ldap->fetch($ldap->cat($users[$this->contact_num]));
+      $ldap->cat($users[$this->contact_num], array('givenName', 'sn', 'uid'));
+      $tr = $ldap->fetch();
       $str = "";
       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
@@ -613,7 +623,8 @@ class glpiPrinterAccount extends plugin
        Assign name ... to smarty, if set
      */ 
     if(isset($users[$this->tech_num])){
-      $tr = $ldap->fetch($ldap->cat($users[$this->tech_num]));
+      $ldap->cat($users[$this->tech_num], array('givenName', 'sn', 'uid'));
+      $tr = $ldap->fetch();
       $str = "";
       if(isset($tr['givenName'][0])){   $str .= $tr['givenName'][0]." ";      }
       if(isset($tr['sn'][0])) {         $str .= $tr['sn'][0]." ";             }
@@ -633,7 +644,7 @@ class glpiPrinterAccount extends plugin
       }
     }
     if($disp==false){
-      $smarty->assign("typeACL","disabled");
+      $smarty->assign("typeACL", $this->getacl("type",true));
     }
 
     $display.= $smarty->fetch(get_template_path('glpiPrinter.tpl', TRUE));
@@ -644,7 +655,8 @@ class glpiPrinterAccount extends plugin
   {
     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
     if($this->initially_was_account){
-      $this->handle->removePrinterInformations($this->dn); 
+      $this->handle->removePrinterInformations($this->dn);
+      new log("remove","printer/".get_class($this),$this->dn); 
     }
   }
 
@@ -660,11 +672,17 @@ class glpiPrinterAccount extends plugin
         }
       }
 
+      if(isset($_POST['FK_glpi_enterprise']) && $this->acl_is_writeable("FKglpienterprise")){
+        $this->FK_glpi_enterprise = $_POST['FK_glpi_enterprise'];
+      }
+
       foreach(array("flags_serial","flags_par","flags_usb") as $checkboxes){
-        if(isset($_POST[$checkboxes])){
-          $this->$checkboxes = 1;
-        }else{
-          $this->$checkboxes = 0;
+        if($this->acl_is_writeable($checkboxes)){
+          if(isset($_POST[$checkboxes])){
+            $this->$checkboxes = 1;
+          }else{
+            $this->$checkboxes = 0;
+          }
         }
       }
     }
@@ -699,8 +717,10 @@ class glpiPrinterAccount extends plugin
       $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
       if($this->initially_was_account&&$this->is_account){
         $this->handle->updatePrinterInformations($attrs,$this->dn);
+        new log("modify","printer/".get_class($this),$this->dn); 
       }elseif($this->is_account){
         $this->handle->addPrinterInformations($attrs,$this->dn);
+        new log("create","printer/".get_class($this),$this->dn); 
       }
       $tmp = $this->handle->getPrinterInformations($this->dn);
       $this->handle->addAttachmentsToPrinter($this->usedAttachments,$tmp[0]['ID']);
@@ -754,7 +774,34 @@ class glpiPrinterAccount extends plugin
     return($ret);
   }  
 
+     /* Return plugin informations for acl handling */
+  static function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Glpi"),
+          "plDescription" => _("Printer inventory extension"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 10,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("printer"),
+
+          "plProvidedAcls"=> array(
+            "flags_serial"         => _("Supports serial interface"),
+            "flags_par"            => _("Supports parallel interface"),
+            "flags_usb"            => _("Supports usb interface"),
+            "tech_num"             => _("Technical responsible"),
+            "comments"             => _("Comments"),
+            "location"             => _("Location"),
+            "contact_num"          => _("Contact person"),
+            "type"                 => _("Type"),
+            "FKglpienterprise"   => _("Manufacturer"),
+
+            "Attachments"          => _("Attachments"),
+        
+            "ManageCartridges"            => _("Cartridge settings"))
+          ));
+  }
 }
-
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>