From 783f7134cb859b55c89b11bde80f4f0a11602fbe Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 5 Jan 2006 08:27:20 +0000 Subject: [PATCH] Glpi, dialog can be saved, 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 | 85 +++++++++++++++++++ plugins/admin/systems/class_glpiAccount.inc | 62 +++++++++++--- .../systems/class_glpiDeviceManagement.inc | 1 - plugins/admin/systems/glpi.tpl | 3 +- 4 files changed, 135 insertions(+), 16 deletions(-) diff --git a/include/class_glpi.inc b/include/class_glpi.inc index 2170e0089..592c5f781 100644 --- a/include/class_glpi.inc +++ b/include/class_glpi.inc @@ -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"); diff --git a/plugins/admin/systems/class_glpiAccount.inc b/plugins/admin/systems/class_glpiAccount.inc index 71306352c..c3015a316 100644 --- a/plugins/admin/systems/class_glpiAccount.inc +++ b/plugins/admin/systems/class_glpiAccount.inc @@ -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: diff --git a/plugins/admin/systems/class_glpiDeviceManagement.inc b/plugins/admin/systems/class_glpiDeviceManagement.inc index 79c628ba5..6e77e39f0 100644 --- a/plugins/admin/systems/class_glpiDeviceManagement.inc +++ b/plugins/admin/systems/class_glpiDeviceManagement.inc @@ -57,7 +57,6 @@ class glpiDeviceManagement extends plugin function execute() { - print_a($this->Selected); /* Call parent execute */ plugin::execute(); diff --git a/plugins/admin/systems/glpi.tpl b/plugins/admin/systems/glpi.tpl index cf2b27221..8832d2cb1 100644 --- a/plugins/admin/systems/glpi.tpl +++ b/plugins/admin/systems/glpi.tpl @@ -89,9 +89,8 @@ - test -- 2.30.2