Minor enhancement with link feature

This commit is contained in:
Laurent Destailleur 2013-11-07 02:56:56 +01:00
parent 27fede8848
commit cf8ff25d5b
4 changed files with 54 additions and 33 deletions

View File

@ -60,12 +60,13 @@ class FormFile
* @param int $perm Value of permission to allow upload * @param int $perm Value of permission to allow upload
* @param int $size Length of input file area * @param int $size Length of input file area
* @param Object $object Object to use (when attachment is done on an element) * @param Object $object Object to use (when attachment is done on an element)
* @param string $options Options * @param string $options Add an option column
* @param boolean $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used. * @param boolean $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used.
* @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__' * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
* @param string $linkfiles 1=Also add form to link files, 0=Do not show form to link files
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='') function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1)
{ {
global $conf,$langs, $hookmanager; global $conf,$langs, $hookmanager;
$hookmanager->initHooks(array('formfile')); $hookmanager->initHooks(array('formfile'));
@ -77,10 +78,11 @@ class FormFile
// TODO: Cheeck this works with 2 forms on same page // TODO: Cheeck this works with 2 forms on same page
// TODO: Cheeck this works with GED module, otherwise, force useajax to 0 // TODO: Cheeck this works with GED module, otherwise, force useajax to 0
// TODO: This does not support option savingdocmask // TODO: This does not support option savingdocmask
// TODO: This break feature to upload links too
return $this->_formAjaxFileUpload($object); return $this->_formAjaxFileUpload($object);
} }
else else
{ {
$maxlength=$size; $maxlength=$size;
$out = "\n\n<!-- Start form attach new file -->\n"; $out = "\n\n<!-- Start form attach new file -->\n";
@ -155,37 +157,46 @@ class FormFile
$out .= '</form>'; $out .= '</form>';
if (empty($sectionid)) $out .= '<br>'; if (empty($sectionid)) $out .= '<br>';
$out .= "\n<!-- End form attach new file -->\n\n"; $out .= "\n<!-- End form attach new file -->\n";
$langs->load('link');
$title = $langs->trans("LinkANewFile");
$out .= load_fiche_titre($title, null, null);
$out .= '<form name="formuserfile" action="'.$url.'" method="POST">';
$out .= '<input type="hidden" id="formuserfile_section_dir" name="section_dir" value="">';
$out .= '<input type="hidden" id="formuserfile_section_id" name="section_id" value="'.$sectionid.'">';
$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$out .= '<table width="100%" class="nobordernopadding">'; if ($linkfiles)
$out .= '<tr>'; {
$out .= '<td valign="middle" class="nowrap">'; $out .= "\n<!-- Start form attach new link -->\n";
$out .= $langs->trans("Link") . ': '; $langs->load('link');
$out .= '<input type="text" name="link" id="link">'; $title = $langs->trans("LinkANewFile");
$out .= ' &nbsp; ' . $langs->trans("Label") . ': '; $out .= load_fiche_titre($title, null, null);
$out .= '<input type="text" name="label" id="label">'; $out .= '<form name="formuserfile" action="'.$url.'" method="POST">';
$out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">'; $out .= '<input type="hidden" id="formuserfile_section_dir" name="section_dir" value="">';
$out .= '<input type="hidden" name="objectid" value="' . $object->id . '">'; $out .= '<input type="hidden" id="formuserfile_section_id" name="section_id" value="'.$sectionid.'">';
$out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("Upload").'"'; $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled="disabled"':'');
$out .= '>'; $out .= '<table width="100%" class="nobordernopadding">';
$out .= '</td></tr>'; $out .= '<tr>';
$out .= '</table>'; $out .= '<td valign="middle" class="nowrap">';
$out .= $langs->trans("Link") . ': ';
$out .= '<input type="text" name="link" id="link">';
$out .= ' &nbsp; ' . $langs->trans("Label") . ': ';
$out .= '<input type="text" name="label" id="label">';
$out .= '<input type="hidden" name="objecttype" value="' . $object->element . '">';
$out .= '<input type="hidden" name="objectid" value="' . $object->id . '">';
$out .= '<input type="submit" class="button" name="linkit" value="'.$langs->trans("ToLink").'"';
$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled="disabled"':'');
$out .= '>';
$out .= '</td></tr>';
$out .= '</table>';
$out .= '</form><br>';
$parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm);
$res = $hookmanager->executeHooks('formattachOptions',$parameters,$object);
$out .= "\n<!-- End form attach new file -->\n";
}
$out .= '</form><br>';
$parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm);
$res = $hookmanager->executeHooks('formattachOptions',$parameters,$object);
if (empty($res)) if (empty($res))
{ {
print $out; print $out;
} }
print $hookmanager->resPrint; print $hookmanager->resPrint;
return 1; return 1;
@ -1019,9 +1030,17 @@ class FormFile
} }
/**
* Show array with linked files
*
* @param Object $object Object
* @param int $permtodelete Deletion is allowed
* @param string $action Action
* @param string $selected ???
* @return int Number of links
*/
public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null) public function listOfLinks($object, $permtodelete=1, $action=null, $selected=null)
{ {
global $user, $conf, $langs, $user; global $user, $conf, $langs, $user;
global $bc; global $bc;
global $sortfield, $sortorder; global $sortfield, $sortorder;

View File

@ -775,7 +775,7 @@ include_once DOL_DOCUMENT_ROOT.'/core/ajax/ajaxdirpreview.php';
if ((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) || ! empty($section)) if ((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS)) || ! empty($section))
{ {
$formfile=new FormFile($db); $formfile=new FormFile($db);
$formfile->form_attach_new_file(DOL_URL_ROOT.'/ecm/index.php', 'none', 0, ($section?$section:-1), $user->rights->ecm->upload, 48); $formfile->form_attach_new_file(DOL_URL_ROOT.'/ecm/index.php', 'none', 0, ($section?$section:-1), $user->rights->ecm->upload, 48, null, '', 0, '', 0);
} }
else print '&nbsp;'; else print '&nbsp;';

View File

@ -155,6 +155,7 @@ Valid=Valid
Approve=Approve Approve=Approve
ReOpen=Re-Open ReOpen=Re-Open
Upload=Send file Upload=Send file
ToLink=Link
Select=Select Select=Select
Choose=Choose Choose=Choose
ChooseLangage=Please choose your language ChooseLangage=Please choose your language

View File

@ -155,6 +155,7 @@ Valid=Valider
Approve=Approuver Approve=Approuver
ReOpen=Réouvrir ReOpen=Réouvrir
Upload=Envoyer fichier Upload=Envoyer fichier
ToLink=Lier
Select=Sélectionner Select=Sélectionner
Choose=Choisir Choose=Choisir
ChooseLangage=Choisissez votre langue ChooseLangage=Choisissez votre langue