Code

Glpi, dialog can be saved,
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 5 Jan 2006 08:27:20 +0000 (08:27 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 5 Jan 2006 08:27:20 +0000 (08:27 +0000)
Checks missing :
- Check if name exists ...
REmove account is not implementes right now.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2409 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_glpi.inc
plugins/admin/systems/class_glpiAccount.inc
plugins/admin/systems/class_glpiDeviceManagement.inc
plugins/admin/systems/glpi.tpl

index 2170e0089aee68e6ce833d7c31918d6ba9cb1ee1..592c5f7819bd989eb589d89dde34db75ac2c8b66 100644 (file)
@@ -824,6 +824,40 @@ class glpiDB{
                return($this->is_connected);
        }
 
+       function addAttachmentsToComputer($attr,$id)
+       {
+        if(($id == "" )||(!is_numeric($id))){
+            return (false);
+        }
+        if($this->is_connected){
+            $qry = "DELETE FROM glpi_doc_device WHERE (FK_device=".$id.") AND (device_type=1);";
+            $this->query($qry);
+                       
+                       foreach($attr as $aid => $entry){
+                               $str = "INSERT INTO glpi_doc_device (FK_doc,FK_device,device_type,is_template) 
+                                                                                               VALUES
+                                                                                                       ($aid,$id,1,'0');";
+                               $this->query($str);
+                       }
+        }else{
+            echo "not connected";
+            return(false);
+        }
+       }
+
+       function getAssignAttachments($id)
+       {
+
+               if($this->is_connected){
+                       $qry= "SELECT * FROM glpi_doc_device WHERE (device_type=1) AND (FK_device=".$id.");";
+                       $ret = $this->query($qry);
+                       return($ret);
+               }else{
+            echo "not connected";
+            return(false);
+        }
+       }
+
        function deleteAttachment($id)
        {
                if($this->is_connected){
@@ -847,6 +881,57 @@ class glpiDB{
         }
        }
        
+       function saveAttachments($attrs,$id = -1)
+       {
+               if($this->is_connected){
+                       $atr = array("name","filename","rubrique","mime","date_mod","comment","deleted","link");
+                       $tmp = array();
+                       foreach($atr as $at){
+                               if(isset($attrs[$at])){
+                                       $tmp[$at] = $attrs[$at];
+                               }
+                       }
+                       if(count($tmp)==0){
+                               return(false);
+                       }else{
+
+                               // Add
+                               if($id == -1){
+                                       $str = "INSERT INTO glpi_docs ";
+                                       $namen = "";
+                                       $values= "";
+                                       foreach($tmp as $name => $value){       
+                                               $namen .= $name.", ";
+                                               if(is_numeric($value)){
+                                                       $values .= $value.", ";
+                                               }else{
+                                                       $values .= "'".$value."', ";
+                                               }
+                                       }
+                                       $values = preg_replace("/, $/","",$values);
+                                       $namen  = preg_replace("/, $/","",$namen);
+                                       $str .= "(".$namen.") VALUES (".$values.");";
+                                       print $str;
+                               }else{
+                                       $str = "UPDATE glpi_docs SET ";
+                                       foreach($tmp as $name => $value){       
+                                               $str .= $name."= ";
+                                               if(is_numeric($value)){
+                                                       $str .= $value.", ";
+                                               }else{
+                                                       $str .= "'".$value."', ";
+                                               }
+                                       }
+                                       $str = preg_replace("/, $/","",$str);
+                                       $str .= " WHERE ID=".$id.";";
+                               }
+                               $this->query($str);
+                       }
+               }else{
+                       echo "not connected";
+                       return(false);
+               }
+       }
 
 }
 //$s = new glpiDB("vserver-01","glpi","tester","glpi");
index 71306352ca3e6386314129ad3b307abb0295caa8..c3015a316e6b9da784bac736b591bc41dfac8efb 100644 (file)
@@ -50,8 +50,8 @@ class glpiAccount extends plugin
   var $orig_dn;
   var $ui;
   
-  var $usedDevices = array();
-
+  var $usedDevices      = array();
+  var $usedAttachments  = array();
 
   /* Contructor 
      Sets default values and checks if we already have an existing glpi account
@@ -85,7 +85,11 @@ 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;
     }
@@ -93,6 +97,8 @@ class glpiAccount extends plugin
     $this->name = $this->dn;
     $this->orig_dn = $this->dn;
     $this->initialy_was_account = $this->is_account;
+
+
   }
 
   function execute()
@@ -159,9 +165,6 @@ 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'])){
@@ -170,9 +173,10 @@ class glpiAccount extends plugin
           print_red($msg);
         }
       }else{
-        /****/
-        echo "blabla attaching something ..... ";
-
+        $this->cur_dialog->save_object();
+        $this->usedAttachments = $this->cur_dialog->save();
+        $this->cur_dialog = false;
+        $this->edit_type = false; 
       }
     }
    
@@ -186,14 +190,16 @@ class glpiAccount extends plugin
     /* Open Attachment pool to add/edit Attachments
      */
     if(isset($_POST['AddAttachment'])){
-      $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn);
+      $this->cur_dialog = new glpiAttachmentPool($this->config,$this->dn,$this->usedAttachments);
       $this->dialog = true;
     }
     
     /* Remove Attachment fro this tab 
      */
-    if(isset($_POST['RemoveAttachment'])){
-        
+    if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments']))){
+      if(isset($this->usedAttachments[$_POST['Attachments']])){
+        unset($this->usedAttachments[$_POST['Attachments']]);
+      }
     }
 
     /* We have selected some devices and pressed use button 
@@ -386,6 +392,8 @@ class glpiAccount extends plugin
       $this->dialog=true;
       $this->cur_dialog->parent = &$this;
       return($this->cur_dialog->execute());
+    }else{
+      $this->dialog= false;
     }
 
     /* Assign smarty defaults */ 
@@ -443,6 +451,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
      */ 
@@ -532,11 +545,34 @@ 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']);
     }
   }
 
+  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:
index 79c628ba57da2f21f5e70ceb0637ce377088be4e..6e77e39f0e9bc13996e8333c33abeef5d033cd6c 100644 (file)
@@ -57,7 +57,6 @@ class glpiDeviceManagement extends plugin
 
   function execute()
   {
-    print_a($this->Selected);
     /* Call parent execute */
     plugin::execute();
 
index cf2b27221d16685f2f56e6ecd7a95f12fb3bf859..8832d2cb1ba4c04448c4f103f3be09d6e5d7a34d 100644 (file)
@@ -89,9 +89,8 @@
                                <tr>
                                        <td>
                                                <select name="Attachments" {$AttachmentsACL} style="height:120px;width:100%;" multiple>
-                                                       {html_options values=$Attachments output=$Attachments}
+                                                       {html_options values=$AttachmentKeys output=$Attachments}
                                                </select>
-                                               test
                                                <input name="AddAttachment"     value="{t}Add{/t}" type="submit">       
                                                <input name="RemoveAttachment"  value="{t}Remove{/t}" type="submit">    
                                        </td>