Code

Updated edit windows, 100% width ; size = 12
[gosa.git] / plugins / admin / systems / class_glpiAccount.inc
index 6d7813e8c6205277e6265ee023f6fa6327f387a7..643503a2fd6c4db528b82673baddbcfb7f20c8a2 100644 (file)
@@ -8,50 +8,54 @@ class glpiAccount extends plugin
   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
 
   /* attribute list for save action */
-  var $ignore_account= TRUE;
+  var $ignore_account= FALSE;
   var $attributes= array("ID","name","contact",
       "tech_num","comments","date_mod","os","location","domain","network","contact_num",
       "model","type","is_template","FK_glpi_enterprise","deleted");
 
-  var $ID                 ;
-  var $name               ="";
-  var $contact            ="";
-  var $contact_num        ="";
-
-  var $tech_num           ="";
-  var $comments           ="";
-
-  var $addUser            ="";
+  var $ID                 ;       // Is set if this entry is edited 
+  var $name               = "";    // This should be the dn of this entry 
+  var $contact            = "";    // Empty
+    
+  var $comments           = "";    // Comment
+  
+  var $contact_num        = "";    // Contact person
+  var $tech_num           = "";    // Technical responsible person
+  
+  var $addUser            = "";    // This is used to remember if a dialog was opened for tech_num or contact_num 
 
-  var $date_mod           ="";
-  var $os                 =0;
-  var $location           =0;
-  var $domain             =0;
-  var $network            =0; 
+  var $date_mod           = "";    // Modification timestamp
+  var $os                 = 0;     // Operating system
+  var $location           = 0;     // Not used yet
+  var $domain             = 0;     // ? Set to 0
+  var $network            = 0;     // ? Set to 0 
 
-  var $model              =0;
-  var $type               =0;
-  var $is_template        =0;
-  var $FK_glpi_enterprise =0;
-  var $deleted            ="N";
+  var $model              = 0;     // ? Can't remember this, it isn't used in GOsa 
+  var $type               = 0;     // System type id
+  var $is_template        = 0;     // Used as template ?
+  var $FK_glpi_enterprise = 0;     // Manufacturer id
+  var $deleted            = "N";   // Deleted entries should have this set to Y
 
+  /* Not necessary, cause we use mysql databse */
   var $objectclasses= array("whatever");
 
+  /* Used to remember if this was an account (simply: is this an edited entry) */
   var $initialy_was_account = false;
 
-  var $edit_type    =false;
-  var $edit_os    =false;
+  /* Remember current dialog */
+  var $edit_type            = false;
+  var $edit_os              = false;
 
   var $data;
-  var $handle = NULL;
+  var $handle = NULL;               // Glpi class handle used to query database
 
-  var $cur_dialog = NULL;
+  var $cur_dialog = NULL;           // This contains the sub dialog handle
 
-  var $orig_dn;
-  var $ui;
+  var $orig_dn;                     // To check if dn, has changed 
+  var $ui;                          // Some GOsa specific user informations 
   
-  var $usedDevices = array();
-
+  var $usedDevices      = array();  // Which devices are currently selected 
+  var $usedAttachments  = array();  // Used Attachments 
 
   /* Contructor 
      Sets default values and checks if we already have an existing glpi account
@@ -61,22 +65,27 @@ class glpiAccount extends plugin
     plugin::plugin ($config, $dn);
     $this->ui= get_userinfo();
 
+    /* Abort class construction, if no db is defined */
     if(!isset($this->config->data['SERVERS']['GLPI'])){
       return;
     }
 
+    // Get informations about databse connection
     $this->data = $this->config->data['SERVERS']['GLPI'];
 
+    // Abort if mysql extension is missing 
     if(!is_callable("mysql_connect")){
       return;
     }
 
+    // Create handle of glpi class, and check if database connection is established 
     $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
 
     if(!$this->handle->is_connected){
       return;
     } 
 
+    // If this dn is already used in database, then get all informations for this entry 
     if($this->handle->is_account($this->dn)){
       $this->is_account = true;
       $tmp = ($this->handle->getComputerInformations($this->dn));
@@ -85,14 +94,21 @@ class glpiAccount extends plugin
         $this->$attr = $tmp[0][$attr];
       }
       $this->usedDevices = $this->handle->getUsedDevices($tmp[0]['ID']);
-
+      $atts = $this->handle->getAssignAttachments($tmp[0]['ID']);
+      foreach($atts as $attachment){
+        
+        $this->usedAttachments[$attachment['FK_doc']]=$attachment['FK_doc']; 
+      }
     }else{
       $this->is_account = false;
     }
 
-    $this->name = $this->dn;
-    $this->orig_dn = $this->dn;
+    /* set defaults */
+    $this->name                 = $this->dn;
+    $this->orig_dn              = $this->dn;
     $this->initialy_was_account = $this->is_account;
+
+
   }
 
   function execute()
@@ -108,7 +124,7 @@ class glpiAccount extends plugin
         To avoid undefined indexes, if there is an error with the glpi db
      */ 
     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers",
-                  "OSs","TechnicalResponsibles","InstalledDevices","Attachments",
+                  "OSs","TechnicalResponsibles","InstalledDevices","Attachments","AttachmentKeys",
                   "OSKeys","OSs","ManufacturerKeys","InstalledDeviceKeys") as $attr){
       $smarty->assign($attr,array());
       $smarty->assign($attr."ACL"," disabled ");
@@ -145,13 +161,31 @@ class glpiAccount extends plugin
       return($smarty->fetch(get_template_path('glpi.tpl', TRUE)));
     } 
 
-    /*  All check are ok
+    /*  All checks are ok
         Lets handle Posts, templates etc below ...
      */
     
     $users = $this->handle->getUsers();
     $ldap= $this->config->get_ldap_link();
-  
+    /* Check for Trading button Post
+     */
+    if(isset($_POST['Trading'])){
+      print_red(_("This feature is not implemented yet."));
+    }
+
+    /* Check for Software button Post
+     */
+    if(isset($_POST['Software'])){
+      print_red(_("This feature is not implemented yet."));
+    }
+
+    /* Check for Contract button Post
+     */
+    if(isset($_POST['Contracts'])){
+      print_red(_("This feature is not implemented yet."));
+    }
     /* Add Device was requested, open new dialog
      */
     if(isset($_POST['AddDevice'])){
@@ -159,6 +193,45 @@ class glpiAccount extends plugin
       $this->cur_dialog = new glpiDeviceManagement($this->config,$this->dn,$this->usedDevices);
     }
 
+    /* Attachment pool was closed with use
+     */
+    if(isset($_POST['UseAttachment'])){
+      if(count($this->cur_dialog->check())){
+        foreach($this->cur_dialog->check() as $msg){
+          print_red($msg);
+        }
+      }else{
+        $this->cur_dialog->save_object();
+        $this->usedAttachments = $this->cur_dialog->save();
+        $this->cur_dialog = false;
+        $this->edit_type = false; 
+      }
+    }
+   
+    /* Attachment pool was closed with abort
+     */ 
+    if(isset($_POST['AbortAttachment'])){
+      $this->cur_dialog = false;
+      $this->edit_type = false; 
+    }
+
+    /* Open Attachment pool to add/edit Attachments
+     */
+    if(isset($_POST['AddAttachment'])){
+      $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
+      $this->dialog = true;
+    }
+    
+    /* Remove Attachment fro this tab 
+     */
+    if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments']))){
+      foreach($_POST['Attachments'] as $entry){
+        if(isset($this->usedAttachments[$entry])){
+          unset($this->usedAttachments[$entry]);
+        }
+      }
+    }
+
     /* We have selected some devices and pressed use button 
      */
     if(isset($_POST['SelectDeviceSave'])){
@@ -200,7 +273,21 @@ class glpiAccount extends plugin
     /* Remove selected type from our system types list
      */
     if((isset($_POST['del_type']))&&(!empty($_POST['select_type']))){
-      $this->handle->removeSystemType($_POST['select_type']);  
+      $tmp = $this->handle->is_systemTypeUsed($_POST['select_type']);
+      if(count($tmp)){
+        $names = "";
+        foreach($tmp as $name){
+          $names .= ", ".$name;
+        }
+        $names = preg_replace("/^, /","",$names); 
+        $names = trim($names);
+        if(count($tmp) == 3){
+          $names .= " ...";
+        }
+        print_red(sprintf(_("You can't delete this system type, it is still in use by these system(s) '%s'"),$names));
+      }else{
+        $this->handle->removeSystemType($_POST['select_type']); 
+      } 
     }
 
     /* Rename selected system type to given string
@@ -242,7 +329,24 @@ class glpiAccount extends plugin
     /* Delete selected os from list and db
      */
     if((isset($_POST['del_os']))&&(!empty($_POST['select_os']))){
-      $this->handle->removeOS_byID($_POST['select_os']);  
+      $tmp = $this->handle->is_osUsed($_POST['select_os']);
+  
+      if(count($tmp)){
+
+        $names = "";
+        foreach($tmp as $name){
+          $names .= ", ".$name;
+        }
+        $names = preg_replace("/^, /","",$names);
+        $names = trim($names);
+        if(count($tmp) == 3){
+          $names .= " ...";
+        }
+        print_red(sprintf(_("You can't delete this operating system, it is still in use by these system(s) '%s'"),$names));
+
+      }else{
+        $this->handle->removeOS_byID($_POST['select_os']);  
+      }
     }
 
     /* Rename selected os to given string
@@ -265,7 +369,7 @@ class glpiAccount extends plugin
      */
     if(isset($_POST['SelectContactPerson'])){
       $this->addUser = "contact";
-      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
     }
 
     /* Open dialog which allows to edit the manufacturers
@@ -284,6 +388,7 @@ class glpiAccount extends plugin
 
     /* Abort user selection
      */
+    $smarty->assign("AbortSelectUser","SelectUserCancel");
     if(isset($_POST['SelectUserCancel'])){
       $this->dialog = false;
       $this->addUser ="";
@@ -294,7 +399,7 @@ class glpiAccount extends plugin
      */
     if(isset($_POST['SelectTechPerson'])){
       $this->addUser ="tech";
-      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn);
+      $this->cur_dialog= new glpiSelectUser($this->config,$this->dn,"user_tech_num");
     }
 
     /* Technical responsible person selected*/
@@ -349,17 +454,22 @@ class glpiAccount extends plugin
       $this->dialog=true;
       $this->cur_dialog->parent = &$this;
       return($this->cur_dialog->execute());
+    }else{
+      $this->dialog= false;
     }
 
     /* Assign smarty defaults */ 
     foreach(array("SystemTypes","SystemTypeKeys","Manufacturers","OSs","TechnicalResponsibles","InstalledDevices","Attachments") as $attr){
       $smarty->assign($attr,array());
+    }
+
+    foreach($this->attributes as $attr){
       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
     }
 
     /* Assign some vars to smarty 
      */
-    foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num") as $attr){
+    foreach(array("type","FK_glpi_enterprise","os","tech_num","contact_num","Attachments","InstalledDevices") as $attr){
       $smarty->assign($attr,"");
       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
     }
@@ -406,6 +516,11 @@ class glpiAccount extends plugin
     $smarty->assign("Manufacturers",          $this->handle->getEnterprises());
     $smarty->assign("FK_glpi_enterprise",     $this->FK_glpi_enterprise);
 
+    /* Assign used Attachments
+    */
+    $smarty->assign("Attachments",            $this->getUsedAttachments());
+    $smarty->assign("AttachmentKeys",         array_flip($this->getUsedAttachments()));
+
     /* Handle contact person 
        Assign name ... to smarty, if set
      */ 
@@ -441,13 +556,22 @@ class glpiAccount extends plugin
 
   function remove_from_parent()
   {
+    $this->handle = new glpiDB($this->data['SERVER'],$this->data['LOGIN'],$this->data['PASSWORD'],$this->data['DB']);
+    if($this->initialy_was_account){
+      $this->handle->removeComputerInformations($this->dn); 
+    }
+  
   }
 
   function getDevices(){
     $ret = array();
     foreach($this->usedDevices as $type => $entries){
       foreach($entries as $ent){
-        $ret[] = $ent['designation']." [".$type."]";
+        if(isset($ent['designation'])){
+          $ret[] = $ent['designation']." [".$type."]";
+        }else{
+          $ret[] = $ent['name']." [".$type."]";
+        }
       }
     }
     return($ret); 
@@ -495,11 +619,35 @@ class glpiAccount extends plugin
       }elseif($this->is_account){
         $this->handle->addComputerInformations($attrs,$this->dn);
       }
-      $tmp = ($this->handle->getComputerInformations($this->dn));
+      $tmp = $this->handle->getComputerInformations($this->dn);
       $this->handle->addDevicesToComputer($this->usedDevices,$tmp[0]['ID']);
+      $this->handle->addAttachmentsToComputer($this->usedAttachments,$tmp[0]['ID']);
     }
   }
 
+  /* Return used attachments */
+  function getUsedAttachments()
+  {
+    $atts =$this->handle->getAttachments();
+    $ret = array();
+    foreach($atts as $entry){
+      if(in_array($entry['ID'],$this->usedAttachments)){
+
+        $cm ="";
+        if(isset($entry['comment'])){
+          $cm=" [".$entry['comment']."]";
+        }
+        if(isset($entry['mime'])){
+          $cm.=" -".$entry['mime']."";
+        }
+
+        $ret[$entry['ID']]= $entry['name'].$cm;
+      }
+    }
+    return($ret);
+  }
+  
+
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: