diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index c74e35d31f6..ea4f0b29d76 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -166,6 +166,8 @@ class FormFile $out .= ''; $out .= ''; $out .= ''; + $out .= ''; + $out .= ''; $out .= 'global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled="disabled"':''); $out .= '>'; @@ -1011,6 +1013,85 @@ class FormFile include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php'; } + + public function list_of_links($object, $permtodelete=1) + { + + global $user, $conf, $langs, $hookmanager, $user; + global $bc; + global $sortfield, $sortorder, $maxheightmini; + + require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + $link = new Link($this->db); + $links = array(); + //HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXX + if ($sortfield == "name") { + $sortfield = "label"; + } elseif ($sortfield == "date") { + $sortfield = "datea"; + } else { + $sortfield = null; + } + $res = $link->fetchAll($links, $object->element, $object->id, $sortfield, $sortorder); + $param = (isset($object->id)?'&id='.$object->id:'').$param; + + // Show list of associated links + print ''; + print ''; + print_liste_field_titre($langs->trans("Documents2"),$_SERVER['PHP_SELF'],"name","",$param,'align="left"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Size"),"","","","",'align="center"'); + print_liste_field_titre($langs->trans("Date"),$_SERVER['PHP_SELF'],"date","",$param,'align="center"',$sortfield,$sortorder); + if (empty($useinecm)) print_liste_field_titre('',$_SERVER['PHP_SELF'],"","",$param,'align="center"'); + print_liste_field_titre('','',''); + print ''; + + + $nboflinks = count($links); + + if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; + + $var = true; + foreach($links as $link) { + $var=!$var; + print ''; + print '\n"; + print ''; + print ''; + // Preview + /*if (empty($useinecm)) + { + print ''; + }*/ + print ''; + // Delete or view link + // ($param must start with &) + print '"; + print "\n"; + } + if ($nboflinks == 0) + { + print ''; + } + print "
'; + //print "XX".$file['name']; //$file['name'] must be utf8 + print ''; + print $link->label; + print ''; + print " '.dol_print_date($link->datea, "dayhour", "tzuser").''; + $tmp=explode('.',$file['name']); + $minifile=$tmp[0].'_mini.'.$tmp[1]; + if (image_format_supported($file['name']) > 0) print ''; + else print ' '; + print ' '; + if ($permtodelete) print ''.img_delete().''; + else print ' '; + print "
'; + if (empty($textifempty)) print $langs->trans("NoLinkFound"); + else print $textifempty; + print '
"; + + return $nboflinks; + } } diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 616bd3f60d5..fdcb65bc859 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1055,13 +1055,16 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio } } } elseif ($link) { + var_dump($_POST); if (dol_mkdir($upload_dir) >= 0) { require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; $linkObject = new Link($db); $linkObject->entity = $conf->entity; $linkObject->url = $link; + $linkObject->objecttype = GETPOST('objecttype', 'alpha'); + $linkObject->objectid = GETPOST('objectid', 'int'); $res = $linkObject->create($user); - if ($res) { + if ($res > 0) { setEventMessage($langs->trans("LinkComplete")); } else { setEventMessage($langs->trans("ErrorFileNotLinked"), 'errors'); diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php index 27e01eec7bc..6ddf67c2133 100644 --- a/htdocs/societe/document.php +++ b/htdocs/societe/document.php @@ -162,10 +162,13 @@ if ($object->id) // Show upload form $formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$object->id,'',0,0,$user->rights->societe->creer,50,$object); + //TODO FACTORIZE THIS // List of document $formfile->list_of_documents($filearray,$object,'societe'); - print "

"; + print "
"; + $formfile->list_of_links($object); + print "
"; } else {