PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/projet/fiche.php

https://github.com/asterix14/dolibarr
PHP | 610 lines | 426 code | 102 blank | 82 comment | 117 complexity | 0b192a6ac232c3fd4c92bc01b07b2e19 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/projet/fiche.php
  21. * \ingroup projet
  22. * \brief Project card
  23. */
  24. require("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  26. require_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/modules/project/modules_project.php");
  30. $langs->load("projects");
  31. $langs->load('companies');
  32. $projectid = GETPOST('id','int');
  33. $projectref = GETPOST('ref');
  34. if ($projectid == '' && $projectref == '' && ($_GET['action'] != "create" && $_POST['action'] != "add" && $_POST["action"] != "update" && !$_POST["cancel"])) accessforbidden();
  35. $mine = GETPOST('mode')=='mine' ? 1 : 0;
  36. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  37. // Security check
  38. $socid=0;
  39. if ($user->societe_id > 0) $socid=$user->societe_id;
  40. $result = restrictedArea($user, 'projet', $projectid);
  41. /*
  42. * Actions
  43. */
  44. // Cancel
  45. if (GETPOST("cancel") && GETPOST('backtopage'))
  46. {
  47. header("Location: ".GETPOST('backtopage'));
  48. exit;
  49. }
  50. if ($_POST["action"] == 'add' && $user->rights->projet->creer)
  51. {
  52. $error=0;
  53. if (empty($_POST["ref"]))
  54. {
  55. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'</div>';
  56. $error++;
  57. }
  58. if (empty($_POST["title"]))
  59. {
  60. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
  61. $error++;
  62. }
  63. if (! $error)
  64. {
  65. $error=0;
  66. $db->begin();
  67. $project = new Project($db);
  68. $project->ref = $_POST["ref"];
  69. $project->title = $_POST["title"];
  70. $project->socid = $_POST["socid"];
  71. $project->description = $_POST["description"];
  72. $project->public = $_POST["public"];
  73. $project->datec=dol_now();
  74. $project->dateo=dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']);
  75. $project->datee=dol_mktime(12,0,0,$_POST['projectendmonth'],$_POST['projectendday'],$_POST['projectendyear']);
  76. $result = $project->create($user);
  77. if ($result > 0)
  78. {
  79. // Add myself as project leader
  80. $result = $project->add_contact($user->id, 'PROJECTLEADER', 'internal');
  81. if ($result < 0)
  82. {
  83. $langs->load("errors");
  84. $mesg='<div class="error">'.$langs->trans($project->error).'</div>';
  85. $error++;
  86. }
  87. }
  88. else
  89. {
  90. $langs->load("errors");
  91. $mesg='<div class="error">'.$langs->trans($project->error).'</div>';
  92. $error++;
  93. }
  94. if (! $error)
  95. {
  96. $db->commit();
  97. Header("Location:fiche.php?id=".$project->id);
  98. exit;
  99. }
  100. else
  101. {
  102. $db->rollback();
  103. $_GET["action"] = 'create';
  104. }
  105. }
  106. else
  107. {
  108. $_GET["action"] = 'create';
  109. }
  110. }
  111. if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
  112. {
  113. $error=0;
  114. if (empty($_POST["ref"]))
  115. {
  116. $error++;
  117. //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
  118. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'</div>';
  119. }
  120. if (empty($_POST["title"]))
  121. {
  122. $error++;
  123. //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
  124. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
  125. }
  126. if (! $error)
  127. {
  128. $project = new Project($db);
  129. $project->fetch($_POST["id"]);
  130. $project->ref = $_POST["ref"];
  131. $project->title = $_POST["title"];
  132. $project->socid = $_POST["socid"];
  133. $project->description = $_POST["description"];
  134. $project->public = $_POST["public"];
  135. $project->date_start = empty($_POST["project"])?'':dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']);
  136. $project->date_end = empty($_POST["projectend"])?'':dol_mktime(12,0,0,$_POST['projectendmonth'],$_POST['projectendday'],$_POST['projectendyear']);
  137. $result=$project->update($user);
  138. $_GET["id"]=$project->id; // On retourne sur la fiche projet
  139. }
  140. else
  141. {
  142. $_GET["id"]=$_POST["id"];
  143. $_GET['action']='edit';
  144. }
  145. }
  146. // Build doc
  147. if (GETPOST('action') == 'builddoc' && $user->rights->projet->creer)
  148. {
  149. $project = new Project($db);
  150. $project->fetch($_GET['id']);
  151. if (GETPOST('model'))
  152. {
  153. $project->setDocModel($user, GETPOST('model'));
  154. }
  155. $outputlangs = $langs;
  156. if (GETPOST('lang_id'))
  157. {
  158. $outputlangs = new Translate("",$conf);
  159. $outputlangs->setDefaultLang(GETPOST('lang_id'));
  160. }
  161. $result=project_pdf_create($db, $project, $project->modelpdf, $outputlangs);
  162. if ($result <= 0)
  163. {
  164. dol_print_error($db,$result);
  165. exit;
  166. }
  167. else
  168. {
  169. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$project->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
  170. exit;
  171. }
  172. }
  173. if (GETPOST('action') == 'confirm_validate' && GETPOST('confirm') == 'yes')
  174. {
  175. $project = new Project($db);
  176. $project->fetch(GETPOST("id"));
  177. $result = $project->setValid($user);
  178. if ($result <= 0)
  179. {
  180. $mesg='<div class="error">'.$project->error.'</div>';
  181. }
  182. }
  183. if (GETPOST('action') == 'confirm_close' && GETPOST('confirm') == 'yes')
  184. {
  185. $project = new Project($db);
  186. $project->fetch(GETPOST("id"));
  187. $result = $project->setClose($user);
  188. if ($result <= 0)
  189. {
  190. $mesg='<div class="error">'.$project->error.'</div>';
  191. }
  192. }
  193. if (GETPOST('action') == 'confirm_reopen' && GETPOST('confirm') == 'yes')
  194. {
  195. $project = new Project($db);
  196. $project->fetch(GETPOST("id"));
  197. $result = $project->setValid($user);
  198. if ($result <= 0)
  199. {
  200. $mesg='<div class="error">'.$project->error.'</div>';
  201. }
  202. }
  203. if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->projet->supprimer)
  204. {
  205. $project = new Project($db);
  206. $project->fetch(GETPOST("id"));
  207. $result=$project->delete($user);
  208. if ($result > 0)
  209. {
  210. Header("Location: index.php");
  211. exit;
  212. }
  213. else
  214. {
  215. dol_syslog($project->error,LOG_DEBUG);
  216. $mesg='<div class="error">'.$langs->trans("CantRemoveProject").'</div>';
  217. }
  218. }
  219. /*
  220. * View
  221. */
  222. $form = new Form($db);
  223. $formfile = new FormFile($db);
  224. $userstatic = new User($db);
  225. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  226. llxHeader("",$langs->trans("Projects"),$help_url);
  227. if ($_GET["action"] == 'create' && $user->rights->projet->creer)
  228. {
  229. /*
  230. * Create
  231. */
  232. print_fiche_titre($langs->trans("NewProject"));
  233. if ($mesg) print $mesg.'<br>';
  234. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  235. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  236. print '<input type="hidden" name="action" value="add">';
  237. print '<input type="hidden" name="backtopage" value="'.GETPOST('backtopage').'">';
  238. print '<table class="border" width="100%">';
  239. $project = new Project($db);
  240. $defaultref='';
  241. $obj = empty($conf->global->PROJECT_ADDON)?'mod_project_simple':$conf->global->PROJECT_ADDON;
  242. if (! empty($conf->global->PROJECT_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/".$conf->global->PROJECT_ADDON.".php"))
  243. {
  244. require_once(DOL_DOCUMENT_ROOT ."/core/modules/project/".$conf->global->PROJECT_ADDON.".php");
  245. $modProject = new $obj;
  246. $defaultref = $modProject->getNextValue($soc,$project);
  247. }
  248. if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
  249. // Ref
  250. print '<tr><td><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td><input size="12" type="text" name="ref" value="'.($_POST["ref"]?$_POST["ref"]:$defaultref).'"></td></tr>';
  251. // Label
  252. print '<tr><td><span class="fieldrequired">'.$langs->trans("Label").'</span></td><td><input size="30" type="text" name="title" value="'.$_POST["title"].'"></td></tr>';
  253. // Customer
  254. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  255. $text=$form->select_company(GETPOST("socid"),'socid','',1,1);
  256. $texthelp=$langs->trans("IfNeedToUseOhterObjectKeepEmpty");
  257. print $form->textwithtooltip($text.' '.img_help(),$texthelp,1);
  258. print '</td></tr>';
  259. // Public
  260. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  261. $array=array(0 => $langs->trans("PrivateProject"),1 => $langs->trans("SharedProject"));
  262. print $form->selectarray('public',$array,$project->public);
  263. print '</td></tr>';
  264. // Date start
  265. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  266. print $form->select_date('','project');
  267. print '</td></tr>';
  268. // Date end
  269. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  270. print $form->select_date(-1,'projectend');
  271. print '</td></tr>';
  272. // Description
  273. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  274. print '<td>';
  275. print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$_POST["description"].'</textarea>';
  276. print '</td></tr>';
  277. print '</table>';
  278. print '<br><center>';
  279. print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
  280. if (GETPOST('backtopage'))
  281. {
  282. print ' &nbsp; &nbsp; ';
  283. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  284. }
  285. print '</center>';
  286. print '</form>';
  287. }
  288. else
  289. {
  290. /*
  291. * Show or edit
  292. */
  293. if ($mesg) print $mesg;
  294. $project = new Project($db);
  295. $project->fetch($projectid,$projectref);
  296. if ($project->societe->id > 0) $result=$project->societe->fetch($project->societe->id);
  297. // To verify role of users
  298. $userAccess = $project->restrictedProjectArea($user);
  299. $head=project_prepare_head($project);
  300. dol_fiche_head($head, 'project', $langs->trans("Project"),0,($project->public?'projectpub':'project'));
  301. // Confirmation validation
  302. if ($_GET['action'] == 'validate')
  303. {
  304. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$project->id, $langs->trans('ValidateProject'), $langs->trans('ConfirmValidateProject'), 'confirm_validate','',0,1);
  305. if ($ret == 'html') print '<br>';
  306. }
  307. // Confirmation close
  308. if ($_GET["action"] == 'close')
  309. {
  310. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$project->id,$langs->trans("CloseAProject"),$langs->trans("ConfirmCloseAProject"),"confirm_close",'','',1);
  311. if ($ret == 'html') print '<br>';
  312. }
  313. // Confirmation reopen
  314. if ($_GET["action"] == 'reopen')
  315. {
  316. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$project->id,$langs->trans("ReOpenAProject"),$langs->trans("ConfirmReOpenAProject"),"confirm_reopen",'','',1);
  317. if ($ret == 'html') print '<br>';
  318. }
  319. // Confirmation delete
  320. if ($_GET["action"] == 'delete')
  321. {
  322. $text=$langs->trans("ConfirmDeleteAProject");
  323. $task=new Task($db);
  324. $taskarray=$task->getTasksArray(0,0,$project->id,0,0);
  325. $nboftask=count($taskarray);
  326. if ($nboftask) $text.='<br>'.img_warning().' '.$langs->trans("ThisWillAlsoRemoveTasks",$nboftask);
  327. $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$project->id,$langs->trans("DeleteAProject"),$text,"confirm_delete",'','',1);
  328. if ($ret == 'html') print '<br>';
  329. }
  330. if ($_GET["action"] == 'edit' && $userAccess)
  331. {
  332. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  333. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  334. print '<input type="hidden" name="action" value="update">';
  335. print '<input type="hidden" name="id" value="'.$project->id.'">';
  336. print '<table class="border" width="100%">';
  337. // Ref
  338. print '<tr><td width="30%">'.$langs->trans("Ref").'</td>';
  339. print '<td><input size="12" name="ref" value="'.$project->ref.'"></td></tr>';
  340. // Label
  341. print '<tr><td>'.$langs->trans("Label").'</td>';
  342. print '<td><input size="30" name="title" value="'.$project->title.'"></td></tr>';
  343. // Customer
  344. print '<tr><td>'.$langs->trans("Company").'</td><td>';
  345. print $form->select_societes($project->societe->id,'socid','',1,1);
  346. print '</td></tr>';
  347. // Visibility
  348. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  349. $array=array(0 => $langs->trans("PrivateProject"),1 => $langs->trans("SharedProject"));
  350. print $form->selectarray('public',$array,$project->public);
  351. print '</td></tr>';
  352. // Statut
  353. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$project->getLibStatut(4).'</td></tr>';
  354. // Date start
  355. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  356. print $form->select_date($project->date_start,'project');
  357. print '</td></tr>';
  358. // Date end
  359. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  360. print $form->select_date($project->date_end?$project->date_end:-1,'projectend');
  361. print '</td></tr>';
  362. // Description
  363. print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
  364. print '<td>';
  365. print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$project->description.'</textarea>';
  366. print '</td></tr>';
  367. print '<tr><td align="center" colspan="2">';
  368. print '<input name="update" class="button" type="submit" value="'.$langs->trans("Modify").'"> &nbsp; ';
  369. print '<input type="submit" class="button" name="cancel" Value="'.$langs->trans("Cancel").'"></td></tr>';
  370. print '</table>';
  371. print '</form>';
  372. }
  373. else
  374. {
  375. print '<table class="border" width="100%">';
  376. // Ref
  377. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
  378. // Define a complementary filter for search of next/prev ref.
  379. if (! $user->rights->projet->all->lire)
  380. {
  381. $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1);
  382. $project->next_prev_filter=" rowid in (".$projectsListId.")";
  383. }
  384. print $form->showrefnav($project,'ref','',1,'ref','ref');
  385. print '</td></tr>';
  386. // Label
  387. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$project->title.'</td></tr>';
  388. // Third party
  389. print '<tr><td>'.$langs->trans("Company").'</td><td>';
  390. if ($project->societe->id > 0) print $project->societe->getNomUrl(1);
  391. else print'&nbsp;';
  392. print '</td></tr>';
  393. // Visibility
  394. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  395. if ($project->public) print $langs->trans('SharedProject');
  396. else print $langs->trans('PrivateProject');
  397. print '</td></tr>';
  398. // Statut
  399. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$project->getLibStatut(4).'</td></tr>';
  400. // Date start
  401. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  402. print dol_print_date($project->date_start,'day');
  403. print '</td></tr>';
  404. // Date end
  405. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  406. print dol_print_date($project->date_end,'day');
  407. print '</td></tr>';
  408. // Description
  409. print '<td valign="top">'.$langs->trans("Description").'</td><td>';
  410. print nl2br($project->description);
  411. print '</td></tr>';
  412. print '</table>';
  413. }
  414. dol_fiche_end();
  415. /*
  416. * Boutons actions
  417. */
  418. print '<div class="tabsAction">';
  419. if ($_GET["action"] != "edit" )
  420. {
  421. // Validate
  422. if ($project->statut == 0 && $user->rights->projet->creer)
  423. {
  424. if ($userAccess)
  425. {
  426. print '<a class="butAction" href="fiche.php?id='.$project->id.'&action=validate">'.$langs->trans("Valid").'</a>';
  427. }
  428. else
  429. {
  430. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Valid').'</a>';
  431. }
  432. }
  433. // Modify
  434. if ($project->statut != 2 && $user->rights->projet->creer)
  435. {
  436. if ($userAccess)
  437. {
  438. print '<a class="butAction" href="fiche.php?id='.$project->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
  439. }
  440. else
  441. {
  442. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Modify').'</a>';
  443. }
  444. }
  445. // Close
  446. if ($project->statut == 1 && $user->rights->projet->creer)
  447. {
  448. if ($userAccess)
  449. {
  450. print '<a class="butAction" href="fiche.php?id='.$project->id.'&amp;action=close">'.$langs->trans("Close").'</a>';
  451. }
  452. else
  453. {
  454. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Close').'</a>';
  455. }
  456. }
  457. // Reopen
  458. if ($project->statut == 2 && $user->rights->projet->creer)
  459. {
  460. if ($userAccess)
  461. {
  462. print '<a class="butAction" href="fiche.php?id='.$project->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';
  463. }
  464. else
  465. {
  466. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('ReOpen').'</a>';
  467. }
  468. }
  469. // Delete
  470. if ($user->rights->projet->supprimer)
  471. {
  472. if ($userAccess)
  473. {
  474. print '<a class="butActionDelete" href="fiche.php?id='.$project->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';
  475. }
  476. else
  477. {
  478. print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Delete').'</a>';
  479. }
  480. }
  481. }
  482. print "</div>";
  483. print "<br>\n";
  484. if ($_GET['action'] != 'presend')
  485. {
  486. print '<table width="100%"><tr><td width="50%" valign="top">';
  487. print '<a name="builddoc"></a>'; // ancre
  488. /*
  489. * Documents generes
  490. */
  491. $filename=dol_sanitizeFileName($project->ref);
  492. $filedir=$conf->projet->dir_output . "/" . dol_sanitizeFileName($project->ref);
  493. $urlsource=$_SERVER["PHP_SELF"]."?id=".$project->id;
  494. $genallowed=($user->rights->projet->creer && $userAccess);
  495. $delallowed=($user->rights->projet->supprimer && $userAccess);
  496. $var=true;
  497. $somethingshown=$formfile->show_documents('project',$filename,$filedir,$urlsource,$genallowed,$delallowed,$project->modelpdf);
  498. print '</td><td valign="top" width="50%">';
  499. // List of actions on element
  500. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php');
  501. $formactions=new FormActions($db);
  502. $somethingshown=$formactions->showactions($project,'project',$socid);
  503. print '</td></tr></table>';
  504. }
  505. }
  506. $db->close();
  507. llxFooter();
  508. ?>