X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fsystems%2Fclass_glpiAttachmentPool.inc;h=d36409ea5f25dabe808c4ebccb1fe006c4d1ff3c;hb=14a1125842be8515bd8b8f7117081e00f40470b5;hp=b41d4a0b9a01e53d448736d98776836abccec570;hpb=e91294fb9447f8587203e2219bfab4f4cb563348;p=gosa.git diff --git a/plugins/admin/systems/class_glpiAttachmentPool.inc b/plugins/admin/systems/class_glpiAttachmentPool.inc index b41d4a0b9..d36409ea5 100644 --- a/plugins/admin/systems/class_glpiAttachmentPool.inc +++ b/plugins/admin/systems/class_glpiAttachmentPool.inc @@ -2,20 +2,15 @@ class glpiAttachmentPool extends plugin { - /* CLI vars */ - var $cli_summary= "Manage server basic objects"; - var $cli_description= "Some longer text\nfor help"; - var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); - /* attribute list for save action */ var $ignore_account = TRUE; - var $attributes = array("name","comment","mime","filename"); + var $attributes = array("name","comment","mime","filename","date_mod"); var $objectclasses = array("whatever"); var $parent; var $edit = false; var $entry = false; - + var $date_mod =""; var $name =""; var $comment =""; var $mime =""; @@ -97,8 +92,25 @@ class glpiAttachmentPool extends plugin } if((isset($_POST['delete_glpi_confirm']))&&(isset($attach[$this->delAttach]))){ - $this->parent->handle->deleteAttachment($this->delAttach); - $attach = $this->parent->handle->getAttachments(); + if($this->parent->handle->is_attachmentUsed($this->delAttach)){ + $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(); + } } /* Someone tries to upload a file */ @@ -113,20 +125,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 @@ -136,6 +152,7 @@ class glpiAttachmentPool extends plugin /* save attachment*/ if(($this->edit == true)&&(isset($_POST['SaveAttachment']))){ if(count($this->check())==0){ + $this->date_mod = date("Y-m-d H:i:s"); $this->save_entry(); $this->edit= false; $this->entry = array(); @@ -157,10 +174,10 @@ class glpiAttachmentPool extends plugin */ if($this->edit == true){ foreach($this->attributes as $attr){ - $smarty->assign($attr,htmlentities($this->$attr)); + $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."); @@ -234,7 +251,7 @@ class glpiAttachmentPool extends plugin $listhead = "