Work on generic filemanager component
This commit is contained in:
parent
90684750c1
commit
9b1470dab5
@ -18,35 +18,58 @@
|
||||
* or see http://www.gnu.org/
|
||||
*/
|
||||
|
||||
// Variable $upload_dir must be defined when entering here
|
||||
// Variable $upload_dir must be defined when entering here.
|
||||
// Variable $upload_dirold may also exists.
|
||||
// Variable $confirm must be defined.
|
||||
|
||||
//var_dump($upload_dir);
|
||||
//var_dump($upload_dirold);
|
||||
|
||||
|
||||
// Submit file/link
|
||||
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
if (GETPOST('sendit','none') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
{
|
||||
if ($object->id)
|
||||
{
|
||||
if (! empty($upload_dirold) && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
|
||||
$result = dol_add_file_process($upload_dirold, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'));
|
||||
else
|
||||
$result = dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'));
|
||||
}
|
||||
if (! empty($_FILES))
|
||||
{
|
||||
if (is_array($_FILES['userfile']['tmp_name'])) $userfiles=$_FILES['userfile']['tmp_name'];
|
||||
else $userfiles=array($_FILES['userfile']['tmp_name']);
|
||||
|
||||
foreach($userfiles as $key => $userfile)
|
||||
{
|
||||
if (empty($_FILES['userfile']['tmp_name'][$key]))
|
||||
{
|
||||
$error++;
|
||||
if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2){
|
||||
setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
|
||||
}
|
||||
else {
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
if (! empty($upload_dirold) && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
|
||||
{
|
||||
$result = dol_add_file_process($upload_dirold, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'));
|
||||
}
|
||||
elseif (! empty($upload_dir))
|
||||
{
|
||||
$result = dol_add_file_process($upload_dir, 0, 1, 'userfile', GETPOST('savingdocmask', 'alpha'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
elseif (GETPOST('linkit','none') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
{
|
||||
if ($object->id)
|
||||
$link = GETPOST('link', 'alpha');
|
||||
if ($link)
|
||||
{
|
||||
$link = GETPOST('link', 'alpha');
|
||||
if ($link)
|
||||
{
|
||||
if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://' && substr($link, 0, 7) != 'file://') {
|
||||
$link = 'http://' . $link;
|
||||
}
|
||||
dol_add_file_process($upload_dir, 0, 1, 'userfile', null, $link);
|
||||
if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://' && substr($link, 0, 7) != 'file://') {
|
||||
$link = 'http://' . $link;
|
||||
}
|
||||
dol_add_file_process($upload_dir, 0, 1, 'userfile', null, $link);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,8 +77,6 @@ elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
// Delete file/link
|
||||
if ($action == 'confirm_deletefile' && $confirm == 'yes')
|
||||
{
|
||||
if ($object->id)
|
||||
{
|
||||
$urlfile = GETPOST('urlfile', 'alpha', 0, null, null, 1); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
|
||||
if (GETPOST('section', 'alpha')) $file = $upload_dir . "/" . $urlfile; // For a delete of GED module urlfile contains full path from upload_dir
|
||||
else // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
|
||||
@ -71,8 +92,8 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
|
||||
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
|
||||
$dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
|
||||
|
||||
$ret = dol_delete_file($file, 0, 0, 0, $object);
|
||||
if (! empty($fileold)) dol_delete_file($fileold, 0, 0, 0, $object); // Delete file using old path
|
||||
$ret = dol_delete_file($file, 0, 0, 0, (is_object($object)?$object:null));
|
||||
if (! empty($fileold)) dol_delete_file($fileold, 0, 0, 0, (is_object($object)?$object:null)); // Delete file using old path
|
||||
|
||||
// Si elle existe, on efface la vignette
|
||||
if (preg_match('/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i',$file,$regs))
|
||||
@ -112,9 +133,20 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes')
|
||||
}
|
||||
}
|
||||
}
|
||||
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id.(!empty($withproject)?'&withproject=1':''));
|
||||
exit;
|
||||
}
|
||||
|
||||
if (is_object($object) && $object->id > 0)
|
||||
{
|
||||
if ($backtopage)
|
||||
{
|
||||
header('Location: ' . $backtopage);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id.(!empty($withproject)?'&withproject=1':''));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($action == 'confirm_updateline' && GETPOST('save','alpha') && GETPOST('link', 'alpha'))
|
||||
{
|
||||
@ -142,45 +174,44 @@ elseif ($action == 'confirm_updateline' && GETPOST('save','alpha') && GETPOST('l
|
||||
//error fetching
|
||||
}
|
||||
}
|
||||
elseif ($action == 'renamefile' && GETPOST('renamefilesave'))
|
||||
elseif ($action == 'renamefile' && GETPOST('renamefilesave','alpha'))
|
||||
{
|
||||
if ($object->id)
|
||||
// For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
|
||||
if (! empty($upload_dir))
|
||||
{
|
||||
// For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile.
|
||||
//var_dump($upload_dir);exit;
|
||||
if (! empty($upload_dir))
|
||||
$filenamefrom=dol_sanitizeFileName(GETPOST('renamefilefrom','alpha'));
|
||||
$filenameto=dol_sanitizeFileName(GETPOST('renamefileto','alpha'));
|
||||
|
||||
// Security:
|
||||
// Disallow file with some extensions. We rename them.
|
||||
// Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code.
|
||||
if (preg_match('/\.htm|\.html|\.php|\.pl|\.cgi$/i',$filenameto) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED))
|
||||
{
|
||||
$filenamefrom=dol_sanitizeFileName(GETPOST('renamefilefrom','alpha'));
|
||||
$filenameto=dol_sanitizeFileName(GETPOST('renamefileto','alpha'));
|
||||
$filenameto.= '.noexe';
|
||||
}
|
||||
|
||||
// Security:
|
||||
// Disallow file with some extensions. We rename them.
|
||||
// Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code.
|
||||
if (preg_match('/\.htm|\.html|\.php|\.pl|\.cgi$/i',$filenameto) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED))
|
||||
if ($filenamefrom && $filenameto)
|
||||
{
|
||||
$srcpath = $upload_dir.'/'.$filenamefrom;
|
||||
$destpath = $upload_dir.'/'.$filenameto;
|
||||
|
||||
$result = dol_move($srcpath, $destpath);
|
||||
if ($result)
|
||||
{
|
||||
$filenameto.= '.noexe';
|
||||
if ($object->id)
|
||||
{
|
||||
$object->addThumbs($destpath);
|
||||
}
|
||||
|
||||
// TODO Add revert function of addThumbs to remove for old name
|
||||
//$object->delThumbs($srcpath);
|
||||
|
||||
setEventMessages($langs->trans("FileRenamed"), null);
|
||||
}
|
||||
|
||||
if ($filenamefrom && $filenameto)
|
||||
else
|
||||
{
|
||||
$srcpath = $upload_dir.'/'.$filenamefrom;
|
||||
$destpath = $upload_dir.'/'.$filenameto;
|
||||
|
||||
$result = dol_move($srcpath, $destpath);
|
||||
if ($result)
|
||||
{
|
||||
$object->addThumbs($destpath);
|
||||
|
||||
// TODO Add revert function of addThumbs
|
||||
//$object->delThumbs($srcpath);
|
||||
|
||||
setEventMessages($langs->trans("FileRenamed"), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now.
|
||||
setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors');
|
||||
}
|
||||
$langs->load("errors"); // key must be loaded because we can't rely on loading during output, we need var substitution to be done now.
|
||||
setEventMessages($langs->trans("ErrorFailToRenameFile", $filenamefrom, $filenameto), null, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +229,7 @@ if ($type == 'directory')
|
||||
$relativepath=GETPOST('file','alpha');
|
||||
if ($relativepath && $relativepath!= '/') $relativepath.='/';
|
||||
$upload_dir = $dolibarr_main_data_root.'/'.$module.'/'.$relativepath;
|
||||
if (GETPOSTISSET('website'))
|
||||
if (GETPOSTISSET('website') || GETPOSTISSET('file_manager'))
|
||||
{
|
||||
$param.='&file_manager=1';
|
||||
if (!preg_match('/website=/',$param)) $param.='&website='.urlencode(GETPOST('website','alpha'));
|
||||
@ -289,40 +289,70 @@ if ($type == 'directory')
|
||||
}
|
||||
|
||||
|
||||
//if ($section)
|
||||
//{
|
||||
$useajax=1;
|
||||
if (! empty($conf->dol_use_jmobile)) $useajax=0;
|
||||
if (empty($conf->use_javascript_ajax)) $useajax=0;
|
||||
if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
|
||||
|
||||
//$param.=($param?'?':'').(preg_replace('/^&/','',$param));
|
||||
// Bottom of page
|
||||
$useajax=1;
|
||||
if (! empty($conf->dol_use_jmobile)) $useajax=0;
|
||||
if (empty($conf->use_javascript_ajax)) $useajax=0;
|
||||
if (! empty($conf->global->MAIN_ECM_DISABLE_JS)) $useajax=0;
|
||||
|
||||
if ($useajax || $action == 'delete')
|
||||
//$param.=($param?'?':'').(preg_replace('/^&/','',$param));
|
||||
|
||||
if ($useajax || $action == 'delete')
|
||||
{
|
||||
$urlfile='';
|
||||
if ($action == 'delete') $urlfile=GETPOST('urlfile','alpha');
|
||||
|
||||
if (empty($section_dir)) $section_dir=GETPOST("file","alpha");
|
||||
$section_id=$section;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||
$useglobalvars=1;
|
||||
$form = new Form($db);
|
||||
$formquestion['urlfile']=array('type'=>'hidden','value'=>$urlfile,'name'=>'urlfile'); // We must always put field, even if empty because it is fille by javascript later
|
||||
$formquestion['section']=array('type'=>'hidden','value'=>$section,'name'=>'section'); // We must always put field, even if empty because it is fille by javascript later
|
||||
$formquestion['section_id']=array('type'=>'hidden','value'=>$section_id,'name'=>'section_id'); // We must always put field, even if empty because it is fille by javascript later
|
||||
$formquestion['section_dir']=array('type'=>'hidden','value'=>$section_dir,'name'=>'section_dir'); // We must always put field, even if empty because it is fille by javascript later
|
||||
if (! empty($action) && $action == 'file_manager') $formquestion['file_manager']=array('type'=>'hidden','value'=>1,'name'=>'file_manager');
|
||||
if (! empty($website)) $formquestion['website']=array('type'=>'hidden','value'=>$website,'name'=>'website');
|
||||
if (! empty($pageid) && $pageid > 0) $formquestion['pageid']=array('type'=>'hidden','value'=>$pageid,'name'=>'pageid');
|
||||
|
||||
print $form->formconfirm($url,$langs->trans("DeleteFile"),$langs->trans("ConfirmDeleteFile"),'confirm_deletefile',$formquestion,"no",($useajax?'deletefile':0));
|
||||
}
|
||||
|
||||
if ($useajax)
|
||||
{
|
||||
print '<script type="text/javascript">';
|
||||
|
||||
// Enable jquery handlers on new generated HTML objects (same code than into lib_footer.js.php)
|
||||
// Because the content is reloaded by ajax call, we must also reenable some jquery hooks
|
||||
// Wrapper to manage document_preview
|
||||
if ($conf->browser->layout != 'phone')
|
||||
{
|
||||
$urlfile='';
|
||||
if ($action == 'delete') $urlfile=GETPOST('urlfile');
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||
$useglobalvars=1;
|
||||
$form = new Form($db);
|
||||
$formquestion=array(
|
||||
'urlfile'=>array('type'=>'hidden','value'=>$urlfile,'name'=>'urlfile'),
|
||||
'section'=>array('type'=>'hidden','value'=>$section,'name'=>'section')
|
||||
);
|
||||
print $form->formconfirm($url,$langs->trans("DeleteFile"),$langs->trans("ConfirmDeleteFile"),'confirm_deletefile',$formquestion,"no",($useajax?'deletefile':0));
|
||||
print "\n/* JS CODE TO ENABLE document_preview */\n";
|
||||
print '
|
||||
jQuery(document).ready(function () {
|
||||
jQuery(".documentpreview").click(function () {
|
||||
console.log("We click on preview for element with href="+$(this).attr(\'href\')+" mime="+$(this).attr(\'mime\'));
|
||||
document_preview($(this).attr(\'href\'), $(this).attr(\'mime\'), \''.dol_escape_js($langs->transnoentities("Preview")).'\');
|
||||
return false;
|
||||
});
|
||||
});
|
||||
' . "\n";
|
||||
}
|
||||
|
||||
if ($useajax)
|
||||
{
|
||||
// Enable jquery handlers button to delete files
|
||||
print '<script type="text/javascript">'."\n";
|
||||
print 'jQuery(document).ready(function() {'."\n";
|
||||
print 'jQuery(".deletefilelink").click(function(e) { console.log("We click on button with class deletefilelink"); jQuery("#urlfile").val(jQuery(this).attr("rel")); jQuery("#dialog-confirm-deletefile").dialog("open"); return false; });'."\n";
|
||||
print '});'."\n";
|
||||
print '</script>'."\n";
|
||||
}
|
||||
//}
|
||||
// Enable jquery handlers button to delete files
|
||||
print 'jQuery(document).ready(function() {'."\n";
|
||||
print ' jQuery(".deletefilelink").click(function(e) { '."\n";
|
||||
print ' console.log("We click on button with class deletefilelink, param='.$param.', we set urlfile to "+jQuery(this).attr("rel"));'."\n";
|
||||
print ' jQuery("#urlfile").val(jQuery(this).attr("rel"));'."\n";
|
||||
//print ' jQuery("#section_dir").val(\'aaa\');'."\n";
|
||||
print ' jQuery("#dialog-confirm-deletefile").dialog("open");'."\n";
|
||||
print ' return false;'."\n";
|
||||
print ' });'."\n";
|
||||
print '});'."\n";
|
||||
print '</script>'."\n";
|
||||
}
|
||||
|
||||
// Close db if mode is not noajax
|
||||
if ((! isset($mode) || $mode != 'noajax') && is_object($db)) $db->close();
|
||||
|
||||
@ -230,7 +230,7 @@ if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE
|
||||
}
|
||||
}
|
||||
|
||||
// Enable jquery handlers on new generated HTML objects
|
||||
// Enable jquery handlers on new generated HTML objects (same code than into lib_footer.js.php)
|
||||
// Because the content is reloaded by ajax call, we must also reenable some jquery hooks
|
||||
print "\n<!-- JS CODE TO ENABLE Tooltips on all object with class classfortooltip (reload into ajaxdirtree) -->\n";
|
||||
print '<script type="text/javascript">
|
||||
|
||||
@ -3542,7 +3542,7 @@ class Form
|
||||
* print '});'."\n";
|
||||
* print '</script>'."\n";
|
||||
*
|
||||
* @param string $page Url of page to call if confirmation is OK
|
||||
* @param string $page Url of page to call if confirmation is OK. Can contains paramaters (param 'action' and 'confirm' will be reformated)
|
||||
* @param string $title Title
|
||||
* @param string $question Question
|
||||
* @param string $action Action
|
||||
|
||||
@ -55,24 +55,25 @@ class FormFile
|
||||
|
||||
|
||||
/**
|
||||
* Show form to upload a new file
|
||||
* Show form to upload a new file.
|
||||
*
|
||||
* @param string $url Url
|
||||
* @param string $title Title zone (Title or '' or 'none')
|
||||
* @param int $addcancel 1=Add 'Cancel' button
|
||||
* @param int $sectionid If upload must be done inside a particular ECM section
|
||||
* @param int $perm Value of permission to allow upload
|
||||
* @param int $size Length of input file area. Deprecated.
|
||||
* @param int $addcancel 1=Add 'Cancel' button
|
||||
* @param int $sectionid If upload must be done inside a particular ECM section (is sectionid defined, sectiondir must not be)
|
||||
* @param int $perm Value of permission to allow upload
|
||||
* @param int $size Length of input file area. Deprecated.
|
||||
* @param Object $object Object to use (when attachment is done on an element)
|
||||
* @param string $options Add an option column
|
||||
* @param integer $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used.
|
||||
* @param integer $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). @deprecated 2 should never be used and if 1 is used, option should no be enabled.
|
||||
* @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
|
||||
* @param integer $linkfiles 1=Also add form to link files, 0=Do not show form to link files
|
||||
* @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM)
|
||||
* @param string $accept Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*')
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @param string $sectiondir If upload must be done inside a particular directory (is sectiondir defined, sectionid must not be)
|
||||
* @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='', $linkfiles=1, $htmlname='formuserfile', $accept='')
|
||||
function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='', $sectiondir='')
|
||||
{
|
||||
global $conf,$langs, $hookmanager;
|
||||
$hookmanager->initHooks(array('formfile'));
|
||||
@ -103,7 +104,7 @@ class FormFile
|
||||
if ($title != 'none') $out.=load_fiche_titre($title, null, null);
|
||||
|
||||
$out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
|
||||
$out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="">';
|
||||
$out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
|
||||
$out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">';
|
||||
$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
|
||||
@ -1083,6 +1084,8 @@ class FormFile
|
||||
// Do we have entry into database ?
|
||||
print '<!-- In database: position='.$filearray[$key]['position'].' -->'."\n";
|
||||
print '<tr id="row-'.($filearray[$key]['rowid']>0?$filearray[$key]['rowid']:'-AFTER'.$lastrowid.'POS'.($i+1)).'" '.$bcdd[$var].'>';
|
||||
|
||||
// File name
|
||||
print '<td class="tdoverflowmax300">';
|
||||
|
||||
// Show file name with link to download
|
||||
@ -1095,9 +1098,11 @@ class FormFile
|
||||
print img_mime($file['name'], $file['name'].' ('.dol_print_size($file['size'],0,0).')', 'inline-block valignbottom paddingright');
|
||||
if ($showrelpart == 1) print $relativepath;
|
||||
//print dol_trunc($file['name'],$maxlength,'middle');
|
||||
if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile')))
|
||||
if (GETPOST('action','aZ09') == 'editfile' && $file['name'] == basename(GETPOST('urlfile','alpha')))
|
||||
{
|
||||
print '</a>';
|
||||
$section_dir=dirname(GETPOST('urlfile','alpha'));
|
||||
print '<input type="hidden" name="section_dir" value="'.$section_dir.'">';
|
||||
print '<input type="hidden" name="renamefilefrom" value="'.dol_escape_htmltag($file['name']).'">';
|
||||
print '<input type="text" name="renamefileto" class="quatrevingtpercent" value="'.dol_escape_htmltag($file['name']).'">';
|
||||
$editline=1;
|
||||
@ -1107,12 +1112,15 @@ class FormFile
|
||||
print $file['name'];
|
||||
print '</a>';
|
||||
}
|
||||
// Preview link
|
||||
if (! $editline) print $this->showPreview($file, $modulepart, $filepath);
|
||||
|
||||
print "</td>\n";
|
||||
|
||||
// Size
|
||||
print '<td align="right" width="80px">'.dol_print_size($file['size'],1,1).'</td>';
|
||||
|
||||
// Date
|
||||
print '<td align="center" width="130px">'.dol_print_date($file['date'],"dayhour","tzuser").'</td>';
|
||||
|
||||
// Preview
|
||||
@ -1673,7 +1681,7 @@ class FormFile
|
||||
* @param array $file File
|
||||
* @param string $modulepart propal, facture, facture_fourn, ...
|
||||
* @param string $relativepath Relative path of docs
|
||||
* @param string $ruleforpicto Rule for picto: 0=Preview picto, 1=Use picto of mime type of file)
|
||||
* @param string $ruleforpicto Rule for picto: 0=Use the generic preview picto, 1=Use the picto of mime type of file)
|
||||
* @param string $param More param on http links
|
||||
* @return string $out Output string with HTML
|
||||
*/
|
||||
|
||||
@ -77,8 +77,8 @@ $error=0;
|
||||
* Actions
|
||||
*/
|
||||
|
||||
// Upload file
|
||||
if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
// Upload file (code similar but different than actions_linkedfiles.inc.php)
|
||||
if (GETPOST("sendit",'none') && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
{
|
||||
// Define relativepath and upload_dir
|
||||
$relativepath='';
|
||||
@ -86,14 +86,20 @@ if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
else $relativepath=$section_dir;
|
||||
$upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
|
||||
|
||||
if (empty($_FILES['userfile']['tmp_name']))
|
||||
if (is_array($_FILES['userfile']['tmp_name'])) $userfiles=$_FILES['userfile']['tmp_name'];
|
||||
else $userfiles=array($_FILES['userfile']['tmp_name']);
|
||||
|
||||
foreach($userfiles as $key => $userfile)
|
||||
{
|
||||
$error++;
|
||||
if($_FILES['userfile']['error'] == 1 || $_FILES['userfile']['error'] == 2){
|
||||
setEventMessages($langs->trans('ErrorFileSizeTooLarge'),null, 'errors');
|
||||
}
|
||||
else {
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
|
||||
if (empty($_FILES['userfile']['tmp_name'][$key]))
|
||||
{
|
||||
$error++;
|
||||
if ($_FILES['userfile']['error'][$key] == 1 || $_FILES['userfile']['error'][$key] == 2){
|
||||
setEventMessages($langs->trans('ErrorFileSizeTooLarge'), null, 'errors');
|
||||
}
|
||||
else {
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,8 +113,6 @@ if (GETPOST("sendit") && ! empty($conf->global->MAIN_UPLOAD_DOC))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Add directory
|
||||
if ($action == 'add' && $user->rights->ecm->setup)
|
||||
{
|
||||
@ -131,7 +135,7 @@ if ($action == 'add' && $user->rights->ecm->setup)
|
||||
clearstatcache();
|
||||
}
|
||||
|
||||
// Remove file
|
||||
// Remove file (code similar but different than actions_linkedfiles.inc.php)
|
||||
if ($action == 'confirm_deletefile')
|
||||
{
|
||||
if (GETPOST('confirm') == 'yes')
|
||||
@ -141,7 +145,6 @@ if ($action == 'confirm_deletefile')
|
||||
|
||||
$upload_dir = $conf->ecm->dir_output.($relativepath?'/'.$relativepath:'');
|
||||
$file = $upload_dir . "/" . GETPOST('urlfile','alpha'); // Do not use urldecode here ($_GET and $_POST are already decoded by PHP).
|
||||
//var_dump($file);exit;
|
||||
|
||||
$ret=dol_delete_file($file); // This include also the delete from file index in database.
|
||||
if ($ret)
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
<?php
|
||||
if (empty($module)) $module='ecm';
|
||||
$paramwithoutsection=preg_replace('/&?section=(\d+)/', '', $param);
|
||||
|
||||
$openeddir='/';
|
||||
?>
|
||||
@ -34,21 +35,30 @@ $(document).ready(function() {
|
||||
$('#filetree').fileTree({
|
||||
root: '<?php print dol_escape_js($openeddir); ?>',
|
||||
// Ajax called if we click to expand a dir (not a file). Parameter 'dir' is provided as a POST parameter by fileTree code to this following URL.
|
||||
script: '<?php echo DOL_URL_ROOT.'/core/ajax/ajaxdirtree.php?modulepart='.$module.'&openeddir='.urlencode($openeddir).(empty($param)?'':$param); ?>',
|
||||
script: '<?php echo DOL_URL_ROOT.'/core/ajax/ajaxdirtree.php?modulepart='.$module.'&openeddir='.urlencode($openeddir).(empty($paramwithoutsection)?'':$paramwithoutsection); ?>',
|
||||
folderEvent: 'click', // 'dblclick'
|
||||
multiFolder: false },
|
||||
// Called if we click on a file (not a dir)
|
||||
function(file) {
|
||||
console.log("We click on a file");
|
||||
$("#mesg").hide();
|
||||
loadandshowpreview(file,0);
|
||||
},
|
||||
// Called if we click on a dir (not a file)
|
||||
function(elem) {
|
||||
id=elem.attr('id').substr(12); // We get id that is 'fmdirlia_id_xxx' (id we want is xxx)
|
||||
jQuery("#<?php echo $nameforformuserfile ?>_section_dir").val(elem.attr('rel'));
|
||||
rel=elem.attr('rel')
|
||||
console.log("We click on a dir, we call the ajaxdirtree.php with modulepart=<?php echo $module; ?>, param=<?php echo $paramwithoutsection; ?>");
|
||||
console.log("We also save dir name or id into <?php echo $nameforformuserfile ?>_section_... with name section_... id="+id+" rel="+rel);
|
||||
jQuery("#<?php echo $nameforformuserfile ?>_section_dir").val(rel);
|
||||
jQuery("#<?php echo $nameforformuserfile ?>_section_id").val(id);
|
||||
jQuery("#section_dir").val(rel);
|
||||
jQuery("#section_id").val(id);
|
||||
jQuery("#section").val(id);
|
||||
jQuery('#<?php echo $nameforformuserfile ?>').show();
|
||||
console.log("We also execute the loadandshowpreview() that is on the onclick of each li defined by ajaxdirtree");
|
||||
}
|
||||
// The loadanshowpreview is also call by the 'onclick' set on each li return by ajaxdirtree
|
||||
);
|
||||
|
||||
$('#refreshbutton').click( function() {
|
||||
@ -73,7 +83,7 @@ function loadandshowpreview(filedirname,section)
|
||||
|
||||
$('#ecmfileview').empty();
|
||||
|
||||
var url = '<?php echo dol_buildpath('/core/ajax/ajaxdirpreview.php',1); ?>?action=preview&module=<?php echo $module; ?>§ion='+section+'&file='+urlencode(filedirname)<?php echo (empty($param)?'':"+'".$param."'"); ?>;
|
||||
var url = '<?php echo dol_buildpath('/core/ajax/ajaxdirpreview.php',1); ?>?action=preview&module=<?php echo $module; ?>§ion='+section+'&file='+urlencode(filedirname)<?php echo (empty($paramwithoutsection)?'':"+'".$paramwithoutsection."'"); ?>;
|
||||
$.get(url, function(data) {
|
||||
//alert('Load of url '+url+' was performed : '+data);
|
||||
pos=data.indexOf("TYPE=directory",0);
|
||||
|
||||
@ -46,6 +46,7 @@ if ($module == 'medias')
|
||||
// Confirm remove file (for non javascript users)
|
||||
if (($action == 'delete' || $action == 'file_manager_delete') && empty($conf->use_javascript_ajax))
|
||||
{
|
||||
// TODO Add website, pageid, filemanager if defined
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
|
||||
}
|
||||
|
||||
@ -103,9 +104,11 @@ if ((! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABL
|
||||
<?php
|
||||
}
|
||||
|
||||
$sectiondir=GETPOST('file','alpha');
|
||||
print '<!-- Start form to attach new file in filemanager.tpl.php sectionid='.$section.' sectiondir='.$sectiondir.' -->'."\n";
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
||||
$formfile=new FormFile($db);
|
||||
$formfile->form_attach_new_file($_SERVER["PHP_SELF"], 'none', 0, ($section?$section:-1), $permtoupload, 48, null, '', 0, '', 0, $nameforformuserfile);
|
||||
$formfile->form_attach_new_file($_SERVER["PHP_SELF"], 'none', 0, ($section?$section:-1), $permtoupload, 48, null, '', 0, '', 0, $nameforformuserfile, '', $sectiondir);
|
||||
}
|
||||
else print ' ';
|
||||
|
||||
@ -131,7 +134,7 @@ if ($action == 'delete_section')
|
||||
// End confirm
|
||||
|
||||
|
||||
if (empty($action) || $action == 'file_manager' || preg_match('/refresh/i',$action) || $action == 'delete')
|
||||
if (empty($action) || $action == 'editfile' || $action == 'file_manager' || preg_match('/refresh/i',$action) || $action == 'delete')
|
||||
{
|
||||
print '<table width="100%" class="liste noborderbottom">'."\n";
|
||||
|
||||
|
||||
@ -51,12 +51,16 @@ $page=GETPOST('page', 'alpha');
|
||||
$pageid=GETPOST('pageid', 'int');
|
||||
$pageref=GETPOST('pageref', 'aZ09');
|
||||
$action=GETPOST('action','alpha');
|
||||
$confirm=GETPOST('confirm','alpha');
|
||||
$cancel=GETPOST('cancel','alpha');
|
||||
|
||||
$section_dir = GETPOST('section_dir', 'alpha');
|
||||
$file_manager = GETPOST('file_manager', 'alpha');
|
||||
|
||||
if (GETPOST('delete')) { $action='delete'; }
|
||||
if (GETPOST('preview')) $action='preview';
|
||||
if (GETPOST('createsite')) { $action='createsite'; }
|
||||
if (GETPOST('create')) { $action='create'; }
|
||||
if (GETPOST('file_manager')) { $action='file_manager'; }
|
||||
if (GETPOST('editcss')) { $action='editcss'; }
|
||||
if (GETPOST('editmenu')) { $action='editmenu'; }
|
||||
if (GETPOST('setashome')) { $action='setashome'; }
|
||||
@ -65,6 +69,7 @@ if (GETPOST('editsource')) { $action='editsource'; }
|
||||
if (GETPOST('editcontent')) { $action='editcontent'; }
|
||||
if (GETPOST('createfromclone')) { $action='createfromclone'; }
|
||||
if (GETPOST('createpagefromclone')) { $action='createpagefromclone'; }
|
||||
if (empty($action) && $file_manager) $action='file_manager';
|
||||
|
||||
// Load variable for pagination
|
||||
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
|
||||
@ -122,10 +127,56 @@ $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain
|
||||
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
|
||||
|
||||
|
||||
$permtouploadfile = $user->rights->website->write;
|
||||
$diroutput = $conf->medias->multidir_output[$conf->entity];
|
||||
|
||||
$relativepath=$section_dir;
|
||||
$upload_dir = $diroutput.'/'.$relativepath;
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
|
||||
$backtopage=$_SERVER["PHP_SELF"].'?file_manager=1&website='.$website.'&pageid='.$pageid; // used after a confirm_deletefile into actions_linkedfiles.inc.php
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
|
||||
|
||||
if ($action == 'renamefile') $action='file_manager'; // After actions_linkedfiles, if action were renamefile, we set it to 'file_manager'
|
||||
|
||||
// Add directory
|
||||
if ($action == 'add' && $permtouploadfile)
|
||||
{
|
||||
$ecmdir->ref = 'NOTUSEDYET';
|
||||
$ecmdir->label = GETPOST("label");
|
||||
$ecmdir->description = GETPOST("desc");
|
||||
|
||||
//$id = $ecmdir->create($user);
|
||||
if ($id > 0)
|
||||
{
|
||||
header("Location: ".$_SERVER["PHP_SELF"]);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessages('Error '.$langs->trans($ecmdir->error), null, 'errors');
|
||||
$action = "create";
|
||||
}
|
||||
|
||||
clearstatcache();
|
||||
}
|
||||
|
||||
|
||||
// Remove directory
|
||||
if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes')
|
||||
{
|
||||
//$result=$ecmdir->delete($user);
|
||||
setEventMessages($langs->trans("ECMSectionWasRemoved", $ecmdir->label), null, 'mesgs');
|
||||
|
||||
clearstatcache();
|
||||
}
|
||||
|
||||
|
||||
if (GETPOST('refreshsite')) // If we change the site, we reset the pageid and cancel addsite action.
|
||||
{
|
||||
$pageid=0;
|
||||
@ -1117,7 +1168,7 @@ $moreheadjs.='</script>'."\n";
|
||||
|
||||
llxHeader($moreheadcss.$moreheadjs, $langs->trans("websiteetup"), $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', '', '<!-- Begin div class="fiche" -->'."\n".'<div class="fichebutwithotherclass">');
|
||||
|
||||
print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||
print "\n".'<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">';
|
||||
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
if ($action == 'createsite')
|
||||
@ -1156,6 +1207,10 @@ if ($action == 'edit')
|
||||
{
|
||||
print '<input type="hidden" name="action" value="update">';
|
||||
}
|
||||
if ($action == 'file_manager')
|
||||
{
|
||||
print '<input type="hidden" name="action" value="file_manager">';
|
||||
}
|
||||
|
||||
print '<div>';
|
||||
|
||||
@ -1822,7 +1877,7 @@ if ($action == 'editmeta' || $action == 'create')
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
if ($action == 'file_manager')
|
||||
if ($action == 'editfile' || $action == 'file_manager')
|
||||
{
|
||||
print '<!-- Edit Media -->'."\n";
|
||||
print '<div class="fiche"><br><br>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user