diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php
index d1295ae99b4..dbe55558f2c 100644
--- a/htdocs/projet/fiche.php
+++ b/htdocs/projet/fiche.php
@@ -71,10 +71,36 @@ $date_end=dol_mktime(0,0,0,GETPOST('projectendmonth','int'),GETPOST('projectendd
* Actions
*/
-// Cancel
-if (GETPOST("cancel") && ! empty($backtopage))
+$parameters=array('id'=>$socid, 'objcanvas'=>$objcanvas);
+$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
+$error=$hookmanager->error; $errors=array_merge($errors, (array) $hookmanager->errors);
+
+if (empty($reshook))
{
- if (GETPOST("comefromclone")==1)
+
+ // Cancel
+ if (GETPOST("cancel") && ! empty($backtopage))
+ {
+ if (GETPOST("comefromclone")==1)
+ {
+ $result=$object->delete($user);
+ if ($result > 0)
+ {
+ header("Location: index.php");
+ exit;
+ }
+ else
+ {
+ dol_syslog($object->error,LOG_DEBUG);
+ $mesg='
'.$langs->trans("CantRemoveProject").'
';
+ }
+ }
+ header("Location: ".$backtopage);
+ exit;
+ }
+
+ //if cancel and come from clone then delete the cloned project
+ if (GETPOST("cancel") && (GETPOST("comefromclone")==1))
{
$result=$object->delete($user);
if ($result > 0)
@@ -88,273 +114,255 @@ if (GETPOST("cancel") && ! empty($backtopage))
$mesg=''.$langs->trans("CantRemoveProject").'
';
}
}
- header("Location: ".$backtopage);
- exit;
-}
-//if cancel and come from clone then delete the cloned project
-if (GETPOST("cancel") && (GETPOST("comefromclone")==1))
-{
- $result=$object->delete($user);
- if ($result > 0)
- {
- header("Location: index.php");
- exit;
- }
- else
- {
- dol_syslog($object->error,LOG_DEBUG);
- $mesg=''.$langs->trans("CantRemoveProject").'
';
- }
-}
-
-if ($action == 'add' && $user->rights->projet->creer)
-{
- $error=0;
- if (empty($_POST["ref"]))
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
';
- $error++;
- }
- if (empty($_POST["title"]))
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
';
- $error++;
- }
-
- if (! $error)
- {
- $error=0;
-
- $db->begin();
-
- $object->ref = GETPOST('ref','alpha');
- $object->title = GETPOST('title'); // Do not use 'alpha' here, we want field as it is
- $object->socid = GETPOST('socid','int');
- $object->description = GETPOST('description'); // Do not use 'alpha' here, we want field as it is
- $object->public = GETPOST('public','alpha');
- $object->datec=dol_now();
- $object->date_start=$date_start;
- $object->date_end=$date_end;
-
- // Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
-
- $result = $object->create($user);
- if ($result > 0)
- {
- // Add myself as project leader
- $result = $object->add_contact($user->id, 'PROJECTLEADER', 'internal');
- if ($result < 0)
- {
- $langs->load("errors");
- $mesg=''.$langs->trans($object->error).'
';
- $error++;
- }
- }
- else
- {
- $langs->load("errors");
- $mesg=''.$langs->trans($object->error).'
';
- $error++;
- }
-
- if (! $error)
- {
- $db->commit();
-
- header("Location:fiche.php?id=".$object->id);
- exit;
- }
- else
- {
- $db->rollback();
-
- $action = 'create';
- }
- }
- else
- {
- $action = 'create';
- }
-}
-
-if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
-{
- $error=0;
-
- if (empty($ref))
- {
- $error++;
- //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
';
- }
- if (empty($_POST["title"]))
- {
- $error++;
- //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
';
- }
-
- $db->begin();
-
- if (! $error)
- {
- $object->oldcopy = dol_clone($object);
-
- $old_start_date = $object->date_start;
-
- $object->ref = GETPOST('ref','alpha');
- $object->title = GETPOST('title'); // Do not use 'alpha' here, we want field as it is
- $object->socid = GETPOST('socid','int');
- $object->description = GETPOST('description'); // Do not use 'alpha' here, we want field as it is
- $object->public = GETPOST('public','alpha');
- $object->date_start = empty($_POST["project"])?'':$date_start;
- $object->date_end = empty($_POST["projectend"])?'':$date_end;
-
- // Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
- if ($ret < 0)
- {
- $error++;
- }
- }
-
- if (! $error)
- {
- $result=$object->update($user);
- if ($result < 0)
- {
- $error++;
- setEventMessage($object->errors,'errors');
- }
- }
-
- if (! $error)
- {
- if (GETPOST("reportdate") && ($object->date_start!=$old_start_date))
- {
- $result=$object->shiftTaskDate($old_start_date);
- if ($result < 0)
- {
- $error++;
- $mesg=''.$langs->trans("ErrorShiftTaskDate").':'.$object->error.'
';
- }
- }
- }
-
- if ($error)
- {
- $db->rollback();
- $action='edit';
- }
- else
+ if ($action == 'add' && $user->rights->projet->creer)
{
- $db->commit();
+ $error=0;
+ if (empty($_POST["ref"]))
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
';
+ $error++;
+ }
+ if (empty($_POST["title"]))
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
';
+ $error++;
+ }
- if (GETPOST('socid','int') > 0) $object->societe->fetch(GETPOST('socid','int'));
- else unset($object->societe);
- }
-}
+ if (! $error)
+ {
+ $error=0;
-// Build doc
-if ($action == 'builddoc' && $user->rights->projet->creer)
-{
- // Save last template used to generate document
- if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
+ $db->begin();
- $outputlangs = $langs;
- if (GETPOST('lang_id'))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang(GETPOST('lang_id'));
- }
- $result=project_pdf_create($db, $object, $object->modelpdf, $outputlangs);
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
- }
-}
+ $object->ref = GETPOST('ref','alpha');
+ $object->title = GETPOST('title'); // Do not use 'alpha' here, we want field as it is
+ $object->socid = GETPOST('socid','int');
+ $object->description = GETPOST('description'); // Do not use 'alpha' here, we want field as it is
+ $object->public = GETPOST('public','alpha');
+ $object->datec=dol_now();
+ $object->date_start=$date_start;
+ $object->date_end=$date_end;
-// Delete file in doc form
-if ($action == 'remove_file' && $user->rights->projet->creer)
-{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
- if ($object->id > 0)
- {
- $langs->load("other");
- $upload_dir = $conf->projet->dir_output . "/";
- $file = $upload_dir . '/' . GETPOST('file');
- $ret=dol_delete_file($file);
- if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
- else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
- }
-}
+ $result = $object->create($user);
+ if ($result > 0)
+ {
+ // Add myself as project leader
+ $result = $object->add_contact($user->id, 'PROJECTLEADER', 'internal');
+ if ($result < 0)
+ {
+ $langs->load("errors");
+ $mesg=''.$langs->trans($object->error).'
';
+ $error++;
+ }
+ }
+ else
+ {
+ $langs->load("errors");
+ $mesg=''.$langs->trans($object->error).'
';
+ $error++;
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+
+ header("Location:fiche.php?id=".$object->id);
+ exit;
+ }
+ else
+ {
+ $db->rollback();
+
+ $action = 'create';
+ }
+ }
+ else
+ {
+ $action = 'create';
+ }
+ }
+
+ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
+ {
+ $error=0;
+
+ if (empty($ref))
+ {
+ $error++;
+ //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
';
+ }
+ if (empty($_POST["title"]))
+ {
+ $error++;
+ //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
';
+ }
+
+ $db->begin();
+
+ if (! $error)
+ {
+ $object->oldcopy = dol_clone($object);
+
+ $old_start_date = $object->date_start;
+
+ $object->ref = GETPOST('ref','alpha');
+ $object->title = GETPOST('title'); // Do not use 'alpha' here, we want field as it is
+ $object->socid = GETPOST('socid','int');
+ $object->description = GETPOST('description'); // Do not use 'alpha' here, we want field as it is
+ $object->public = GETPOST('public','alpha');
+ $object->date_start = empty($_POST["project"])?'':$date_start;
+ $object->date_end = empty($_POST["projectend"])?'':$date_end;
+
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+ if ($ret < 0)
+ {
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ $result=$object->update($user);
+ if ($result < 0)
+ {
+ $error++;
+ setEventMessage($object->errors,'errors');
+ }
+ }
+
+ if (! $error)
+ {
+ if (GETPOST("reportdate") && ($object->date_start!=$old_start_date))
+ {
+ $result=$object->shiftTaskDate($old_start_date);
+ if ($result < 0)
+ {
+ $error++;
+ $mesg=''.$langs->trans("ErrorShiftTaskDate").':'.$object->error.'
';
+ }
+ }
+ }
+
+ if ($error)
+ {
+ $db->rollback();
+ $action='edit';
+ }
+ else
+ {
+ $db->commit();
+
+ if (GETPOST('socid','int') > 0) $object->societe->fetch(GETPOST('socid','int'));
+ else unset($object->societe);
+ }
+ }
+
+ // Build doc
+ if ($action == 'builddoc' && $user->rights->projet->creer)
+ {
+ // Save last template used to generate document
+ if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
+
+ $outputlangs = $langs;
+ if (GETPOST('lang_id'))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang(GETPOST('lang_id'));
+ }
+ $result=project_pdf_create($db, $object, $object->modelpdf, $outputlangs);
+ if ($result <= 0)
+ {
+ dol_print_error($db,$result);
+ exit;
+ }
+ }
+
+ // Delete file in doc form
+ if ($action == 'remove_file' && $user->rights->projet->creer)
+ {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ if ($object->id > 0)
+ {
+ $langs->load("other");
+ $upload_dir = $conf->projet->dir_output . "/";
+ $file = $upload_dir . '/' . GETPOST('file');
+ $ret=dol_delete_file($file);
+ if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
+ else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
+ }
+ }
-if ($action == 'confirm_validate' && GETPOST('confirm') == 'yes')
-{
- $result = $object->setValid($user);
- if ($result <= 0)
- {
- $mesg=''.$object->error.'
';
- }
-}
+ if ($action == 'confirm_validate' && GETPOST('confirm') == 'yes')
+ {
+ $result = $object->setValid($user);
+ if ($result <= 0)
+ {
+ $mesg=''.$object->error.'
';
+ }
+ }
-if ($action == 'confirm_close' && GETPOST('confirm') == 'yes')
-{
- $result = $object->setClose($user);
- if ($result <= 0)
- {
- $mesg=''.$object->error.'
';
- }
-}
+ if ($action == 'confirm_close' && GETPOST('confirm') == 'yes')
+ {
+ $result = $object->setClose($user);
+ if ($result <= 0)
+ {
+ $mesg=''.$object->error.'
';
+ }
+ }
-if ($action == 'confirm_reopen' && GETPOST('confirm') == 'yes')
-{
- $result = $object->setValid($user);
- if ($result <= 0)
- {
- $mesg=''.$object->error.'
';
- }
-}
+ if ($action == 'confirm_reopen' && GETPOST('confirm') == 'yes')
+ {
+ $result = $object->setValid($user);
+ if ($result <= 0)
+ {
+ $mesg=''.$object->error.'
';
+ }
+ }
-if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->projet->supprimer)
-{
- $object->fetch($id);
- $result=$object->delete($user);
- if ($result > 0)
- {
- header("Location: index.php");
- exit;
- }
- else
- {
- dol_syslog($object->error,LOG_DEBUG);
- $mesg=''.$langs->trans("CantRemoveProject").'
';
- }
-}
+ if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->projet->supprimer)
+ {
+ $object->fetch($id);
+ $result=$object->delete($user);
+ if ($result > 0)
+ {
+ header("Location: index.php");
+ exit;
+ }
+ else
+ {
+ dol_syslog($object->error,LOG_DEBUG);
+ $mesg=''.$langs->trans("CantRemoveProject").'
';
+ }
+ }
-if ($action == 'confirm_clone' && $user->rights->projet->creer && GETPOST('confirm') == 'yes')
-{
- $clone_contacts=GETPOST('clone_contacts')?1:0;
- $clone_tasks=GETPOST('clone_tasks')?1:0;
- $clone_project_files = GETPOST('clone_project_files') ? 1 : 0;
- $clone_task_files = GETPOST('clone_task_files') ? 1 : 0;
- $clone_notes=GETPOST('clone_notes')?1:0;
- $result=$object->createFromClone($object->id,$clone_contacts,$clone_tasks,$clone_project_files,$clone_task_files,$clone_notes);
- if ($result <= 0)
- {
- $mesg=''.$object->error.'
';
- }
- else
- {
- $object->fetch($result); // Load new object
- $action='edit';
- $comefromclone=true;
- }
+ if ($action == 'confirm_clone' && $user->rights->projet->creer && GETPOST('confirm') == 'yes')
+ {
+ $clone_contacts=GETPOST('clone_contacts')?1:0;
+ $clone_tasks=GETPOST('clone_tasks')?1:0;
+ $clone_project_files = GETPOST('clone_project_files') ? 1 : 0;
+ $clone_task_files = GETPOST('clone_task_files') ? 1 : 0;
+ $clone_notes=GETPOST('clone_notes')?1:0;
+ $result=$object->createFromClone($object->id,$clone_contacts,$clone_tasks,$clone_project_files,$clone_task_files,$clone_notes);
+ if ($result <= 0)
+ {
+ $mesg=''.$object->error.'
';
+ }
+ else
+ {
+ $object->fetch($result); // Load new object
+ $action='edit';
+ $comefromclone=true;
+ }
+ }
}
@@ -768,6 +776,11 @@ else
print '';
}
+
+ // Hook to add more things on page
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('mainCardTabAddMore',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+
}
llxFooter();