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 $size Length of input file area
* @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 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
*/
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;
$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 GED module, otherwise, force useajax to 0
// TODO: This does not support option savingdocmask
// TODO: This break feature to upload links too
return $this->_formAjaxFileUpload($object);
}
else
{
{
$maxlength=$size;
$out = "\n\n<!-- Start form attach new file -->\n";
@ -155,37 +157,46 @@ class FormFile
$out .= '</form>';
if (empty($sectionid)) $out .= '<br>';
$out .= "\n<!-- End form attach new file -->\n\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 .= "\n<!-- End form attach new file -->\n";
$out .= '<table width="100%" class="nobordernopadding">';
$out .= '<tr>';
$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("Upload").'"';
$out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled="disabled"':'');
$out .= '>';
$out .= '</td></tr>';
$out .= '</table>';
if ($linkfiles)
{
$out .= "\n<!-- Start form attach new link -->\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">';
$out .= '<tr>';
$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))
{
print $out;
}
print $hookmanager->resPrint;
return 1;
@ -1018,10 +1029,18 @@ class FormFile
include DOL_DOCUMENT_ROOT.'/core/tpl/ajax/fileupload_view.tpl.php';
}
/**
* 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)
{
global $user, $conf, $langs, $user;
global $bc;
global $sortfield, $sortorder;

View File

@ -406,7 +406,7 @@ print '</div>';
if ($action == 'delete' && empty($conf->use_javascript_ajax))
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
}
dol_htmloutput_mesg($mesg);
@ -456,7 +456,7 @@ print '</div>';
if ($action == 'delete_section')
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section, $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection','','',1);
}
// End confirm
@ -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))
{
$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;';

View File

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

View File

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