X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_glpiAttachmentPool.inc;h=0d1ae07ff97a01880517908c81bf59d62d6ca887;hb=1371f9fb0b601838eda78e6daa92d672647294a6;hp=6ee839e4abc603e889f9d52dea4aa732b3286455;hpb=8b1c208fe0822b270c46cd1435ad206be332e0cd;p=gosa.git diff --git a/plugins/admin/systems/class_glpiAttachmentPool.inc b/plugins/admin/systems/class_glpiAttachmentPool.inc index 6ee839e4a..0d1ae07ff 100644 --- a/plugins/admin/systems/class_glpiAttachmentPool.inc +++ b/plugins/admin/systems/class_glpiAttachmentPool.inc @@ -98,9 +98,22 @@ class glpiAttachmentPool extends plugin if((isset($_POST['delete_glpi_confirm']))&&(isset($attach[$this->delAttach]))){ if($this->parent->handle->is_attachmentUsed($this->delAttach)){ - print_red(_("Can't delete this attachment, it is still in use.")); + $tmp = $this->parent->handle->is_attachmentUsed($this->delAttach); + + $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 attachment, it is still in use by these system(s) '%s'"),$names)); + }else{ $this->parent->handle->deleteAttachment($this->delAttach); + @unlink(CONFIG_DIR."/glpi/".$this->filename); $attach = $this->parent->handle->getAttachments(); } } @@ -117,20 +130,24 @@ class glpiAttachmentPool extends plugin if($FILE['error']!=0) { print_red(_("Upload wasn't successfull.")); }else{ - if(!is_dir("/etc/gosa/glpi/")){ - print_red(_("Missing directory '/etc/gosa/glpi/' to store glpi uploads.")); + if(!is_dir(CONFIG_DIR."/glpi/")){ + print_red(sprintf(_("Missing directory '%s/glpi/' to store glpi uploads."),CONFIG_DIR)); }else{ - $filen = "/etc/gosa/glpi/".$FILE['name']; - $fh = fopen($filen,"w"); - if(!$fh){ - print_red(sprintf(_("Can't create file '%s'."),$filen)); + $filen = CONFIG_DIR."/glpi/".$FILE['name']; + if(file_exists($filen)){ + print_red(_("There is already a file with the same name uploaded.")); }else{ - $str = file_get_contents($FILE['tmp_name']); - fwrite($fh,$str,strlen($str)); - fclose($fh); - $this->mime = $FILE['type']; - $this->filename = $FILE['name']; - } + $fh = fopen($filen,"w"); + if(!$fh){ + print_red(sprintf(_("Can't create file '%s'."),$filen)); + }else{ + $str = file_get_contents($FILE['tmp_name']); + fwrite($fh,$str,strlen($str)); + fclose($fh); + $this->mime = $FILE['type']; + $this->filename = $FILE['name']; + } + } // File already exists } } // Check if any error occured } // check if valid filename was uploaded @@ -165,7 +182,7 @@ class glpiAttachmentPool extends plugin $smarty->assign($attr,htmlentities(utf8_decode($this->$attr))); } if(!empty($this->filename)){ - if(is_readable("/etc/gosa/glpi/".$this->filename)){ + if(is_readable(CONFIG_DIR."/glpi/".$this->filename)){ $status =_("File is available."); }else{ $status =_("File is not readable, possibly the file is missing."); @@ -239,7 +256,7 @@ class glpiAttachmentPool extends plugin $listhead = "
". "  ". "
"; @@ -248,8 +265,8 @@ class glpiAttachmentPool extends plugin $smarty->assign("search_image", get_template_path('images/search.png')); $smarty->assign("searchu_image", get_template_path('images/search_user.png')); $smarty->assign("tree_image", get_template_path('images/tree.png')); - $smarty->assign("infoimage", get_template_path('images/info.png')); - $smarty->assign("launchimage", get_template_path('images/launch.png')); + $smarty->assign("infoimage", get_template_path('images/info_small.png')); + $smarty->assign("launchimage", get_template_path('images/small_filter.png')); $smarty->assign("apply", apply_filter()); $smarty->assign("alphabet", generate_alphabet()); $smarty->assign("attachment_regex", $_SESSION['GlpiAttachmentFilter']['filter']); @@ -309,16 +326,25 @@ class glpiAttachmentPool extends plugin /* Simple check */ function check() { - $message = array(); + /* Call common method to give check the hook */ + $message= plugin::check(); + if($this->edit){ /* check if given name is already in use */ $att = $this->parent->handle->getAttachments(); $ok = true; $this->name=trim($this->name); + foreach($att as $val){ - if($val['name'] == $this->name){ - $ok = false; + if(!isset($this->entry['ID'])){ + if($val['name'] == $this->name){ + $ok = false; + } + }else{ + if(($val['name'] == $this->name)&&($this->entry['ID'] != $val['ID'])){ + $ok = false; + } } } if(!$ok){