diff --git a/plugins/admin/systems/class_glpiAccount.inc b/plugins/admin/systems/class_glpiAccount.inc
index b15af4bde4b1b1b90defbc95a27cdecf45bb3d8d..a949632ea29f06e2a84a6d4d45dc0397a1f30eda 100644 (file)
/* Remove Attachment fro this tab
*/
+
+ $once = true;
+ foreach($_POST as $name => $value){
+ if((preg_match("/^delAttachment_/",$name))&&($once)){
+ $once= false;
+ $name = preg_replace("/^delAttachment_/","",$name);
+ $entry = preg_replace("/_.*$/","",$name);
+ if(isset($this->usedAttachments[$entry])){
+ unset($this->usedAttachments[$entry]);
+ }
+ }
+ }
if((isset($_POST['RemoveAttachment']))&&(isset($_POST['Attachments']))){
- if(isset($this->usedAttachments[$_POST['Attachments']])){
- unset($this->usedAttachments[$_POST['Attachments']]);
+ foreach($_POST['Attachments'] as $entry){
+ if(isset($this->usedAttachments[$entry])){
+ unset($this->usedAttachments[$entry]);
+ }
}
}
/* This appends a new system to our sytem types
*/
if((isset($_POST['add_type']))&&(!empty($_POST['type_string']))){
- $this->handle->addSystemType($_POST['type_string']);
+ $attr = $this->handle->getSystemTypes();
+ if(in_array(trim($_POST['type_string']),$attr)){
+ print_red(_("Adding new sytem type failed, this system type name is already used.")) ;
+ }else{
+ $this->handle->addSystemType(trim($_POST['type_string']));
+ }
}
/* 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
*/
if((isset($_POST['rename_type']))&&(!empty($_POST['select_type']))&&(!empty($_POST['type_string']))){
- $this->handle->updateSystemType($_POST['type_string'],$_POST['select_type']);
+ $attr = $this->handle->getSystemTypes();
+ if(in_array(trim($_POST['type_string']),$attr)){
+ print_red(_("Rename failed, this system type name is already used.")) ;
+ }else{
+ $this->handle->updateSystemType($_POST['type_string'],trim($_POST['select_type']));
+ }
}
/* Someone wants to edit the system types ...
/* Add new os to the db
*/
if((isset($_POST['add_os']))&&(!empty($_POST['is_string']))){
- $this->handle->addOS($_POST['is_string']);
+ $attr = $this->handle->getOSTypes();
+ if(in_array(trim($_POST['is_string']),$attr)){
+ print_red(_("Adding new operating system failed, specifed name is already used.")) ;
+ }else{
+ $this->handle->addOS(trim($_POST['is_string']));
+ }
}
/* 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
*/
if((isset($_POST['rename_os']))&&(!empty($_POST['select_os']))&&(!empty($_POST['is_string']))){
- $this->handle->updateOS($_POST['is_string'],$_POST['select_os']);
+ $attr = $this->handle->getOSTypes();
+ if(in_array(trim($_POST['is_string']),$attr)){
+ print_red(_("Updating operating system failed, specifed name is already used.")) ;
+ }else{
+ $this->handle->updateOS($_POST['is_string'],$_POST['select_os']);
+ }
}
/* Open dialog to edit os types
/* 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));
}
/* Assign used Attachments
*/
- $smarty->assign("Attachments", $this->getUsedAttachments());
- $smarty->assign("AttachmentKeys", array_flip($this->getUsedAttachments()));
+ $divlist = new divSelectBox("glpiAttachmentsList");
+ $divlist-> SetHeight(150);
+ $atts = $this->getUsedAttachments(true);
+ $downlink = "<a href='get_attachment.php?id=%s' target='_blank'>%s</a>";
+ $del_link = "<input type='image' src='images/edittrash.png' name='delAttachment_%s'>";
+ foreach($atts as $id => $attachment){
+ $divlist->AddEntry
+ (
+ array(
+ array("string"=>$attachment['name']),
+ array("string"=>$attachment['mime']),
+ array("string"=>sprintf($downlink,$id,$attachment['filename'])),
+ array("string"=>sprintf($del_link,$attachment['ID']),"attach"=>"style='border-right:0px;'"),
+ )
+ );
+ }
+
+ $smarty->assign("AttachmentsDiv" ,$divlist->DrawList());
/* Handle contact person
Assign name ... to smarty, if set
*/
/* Save data to object */
function save_object()
{
+ if(!isset($_POST['glpi_tpl_posted'])) {
+ return ;
+ }
plugin::save_object();
foreach($this->attributes as $attrs){
if(isset($_POST[$attrs])){
}
/* Return used attachments */
- function getUsedAttachments()
+ function getUsedAttachments($divlist = false)
{
$atts =$this->handle->getAttachments();
$ret = array();
foreach($atts as $entry){
if(in_array($entry['ID'],$this->usedAttachments)){
+ if($divlist){
+ $ret[$entry['ID']] = $entry;
+ }else{
+ $cm ="";
+ if(isset($entry['comment'])){
+ $cm=" [".$entry['comment']."]";
+ }
+ if(isset($entry['mime'])){
+ $cm.=" -".$entry['mime']."";
+ }
- $cm ="";
- if(isset($entry['comment'])){
- $cm=" [".$entry['comment']."]";
- }
- if(isset($entry['mime'])){
- $cm.=" -".$entry['mime']."";
+ $ret[$entry['ID']]= $entry['name'].$cm;
}
-
- $ret[$entry['ID']]= $entry['name'].$cm;
}
}
return($ret);