Skip to content

Commit

Permalink
Fix: broken features for fileupload
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Apr 22, 2013
1 parent 6b8c4fc commit 63a5aee
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion htdocs/comm/action/document.php
Expand Up @@ -263,7 +263,7 @@

// Affiche formulaire upload
$formfile=new FormFile($db);
$formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/action/document.php?id='.$act->id,'',0,0,($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create));
$formfile->form_attach_new_file(DOL_URL_ROOT.'/comm/action/document.php?id='.$act->id,'',0,0,($user->rights->agenda->myactions->create||$user->rights->agenda->allactions->create),50,$act);


// List of document
Expand Down
28 changes: 27 additions & 1 deletion htdocs/core/class/fileupload.class.php
Expand Up @@ -56,6 +56,8 @@ function __construct($options=null,$fk_element=null,$element=null)
$filename = $regs[2];
}

$parentForeignKey = '';

// For compatibility
if ($element == 'propal') {
$pathname = 'comm/propal';
Expand All @@ -69,6 +71,14 @@ function __construct($options=null,$fk_element=null,$element=null)
$element = $pathname = 'projet';
$dir_output=$conf->$element->dir_output;
}
elseif ($element == 'project_task') {
$pathname = 'projet'; $filename='task';
$dir_output=$conf->projet->dir_output;
$parentForeignKey = 'fk_project';
$parentClass = 'Project';
$parentElement = 'projet';
$parentObject = 'project';
}
elseif ($element == 'fichinter') {
$element='ficheinter';
$dir_output=$conf->$element->dir_output;
Expand All @@ -80,6 +90,10 @@ function __construct($options=null,$fk_element=null,$element=null)
elseif ($element == 'invoice_supplier') {
$pathname = 'fourn'; $filename='fournisseur.facture';
$dir_output=$conf->fournisseur->facture->dir_output;
}
elseif ($element == 'action') {
$pathname = 'comm/action'; $filename='actioncomm';
$dir_output=$conf->agenda->dir_output;
} else {
$dir_output=$conf->$element->dir_output;
}
Expand All @@ -97,11 +111,23 @@ function __construct($options=null,$fk_element=null,$element=null)
$object = new $classname($db);

$object->fetch($fk_element);
$object->fetch_thirdparty();
if (!empty($parentForeignKey)) {
dol_include_once('/'.$parentElement.'/class/'.$parentObject.'.class.php');
$parent = new $parentClass($db);
$parent->fetch($object->$parentForeignKey);
if (!empty($parent->socid)) {
$parent->fetch_thirdparty();
}
$object->$parentObject = dol_clone($parent);
} else {
$object->fetch_thirdparty();
}

$object_ref = dol_sanitizeFileName($object->ref);
if ($element == 'invoice_supplier') {
$object_ref = get_exdir($object->id, 2) . $object_ref;
} else if ($element == 'project_task') {
$object_ref = $object->project->ref . '/' . $object_ref;
}

$this->options = array(
Expand Down
1 change: 1 addition & 0 deletions htdocs/projet/class/task.class.php
Expand Up @@ -171,6 +171,7 @@ function fetch($id)
$sql.= " t.label,";
$sql.= " t.description,";
$sql.= " t.duration_effective,";
$sql.= " t.datec,";
$sql.= " t.dateo,";
$sql.= " t.datee,";
$sql.= " t.fk_user_creat,";
Expand Down
8 changes: 6 additions & 2 deletions htdocs/projet/tasks/document.php
Expand Up @@ -93,7 +93,11 @@
{
$projectstatic->fetch($object->fk_project);

if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
if (! empty($projectstatic->socid)) {
$projectstatic->fetch_thirdparty();
}

$object->project = dol_clone($projectstatic);

$upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref);
}
Expand All @@ -114,7 +118,7 @@
{
$langs->load("other");
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$ret=dol_delete_file($file);
$ret=dol_delete_file($file,0,0,0,$object);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
Expand Down

0 comments on commit 63a5aee

Please sign in to comment.