card.php 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  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 3 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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/projet/card.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/doleditor.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  34. // Load translation files required by the page
  35. $langsLoad=array('projects', 'companies');
  36. if (!empty($conf->eventorganization->enabled)) {
  37. $langsLoad[]='eventorganization';
  38. }
  39. $langs->loadLangs($langsLoad);
  40. $id = GETPOST('id', 'int');
  41. $ref = GETPOST('ref', 'alpha');
  42. $action = GETPOST('action', 'aZ09');
  43. $backtopage = GETPOST('backtopage', 'alpha');
  44. $backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
  45. $cancel = GETPOST('cancel', 'alpha');
  46. $confirm = GETPOST('confirm', 'aZ09');
  47. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  48. $status = GETPOST('status', 'int');
  49. $opp_status = GETPOST('opp_status', 'int');
  50. $opp_percent = price2num(GETPOST('opp_percent', 'alpha'));
  51. if ($id == '' && $ref == '' && ($action != "create" && $action != "add" && $action != "update" && !GETPOST("cancel"))) {
  52. accessforbidden();
  53. }
  54. $mine = GETPOST('mode') == 'mine' ? 1 : 0;
  55. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  56. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  57. $hookmanager->initHooks(array('projectcard', 'globalcard'));
  58. $object = new Project($db);
  59. $extrafields = new ExtraFields($db);
  60. // Load object
  61. //include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Can't use generic include because when creating a project, ref is defined and we dont want error if fetch fails from ref.
  62. if ($id > 0 || !empty($ref)) {
  63. $ret = $object->fetch($id, $ref); // If we create project, ref may be defined into POST but record does not yet exists into database
  64. if ($ret > 0) {
  65. $object->fetch_thirdparty();
  66. if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) {
  67. $object->fetchComments();
  68. }
  69. $id = $object->id;
  70. }
  71. }
  72. // fetch optionals attributes and labels
  73. $extrafields->fetch_name_optionals_label($object->table_element);
  74. $date_start = dol_mktime(0, 0, 0, GETPOST('projectstartmonth', 'int'), GETPOST('projectstartday', 'int'), GETPOST('projectstartyear', 'int'));
  75. $date_end = dol_mktime(0, 0, 0, GETPOST('projectendmonth', 'int'), GETPOST('projectendday', 'int'), GETPOST('projectendyear', 'int'));
  76. // Security check
  77. $socid = GETPOST('socid', 'int');
  78. //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  79. restrictedArea($user, 'projet', $object->id, 'projet&project');
  80. $permissiondellink = $user->rights->projet->creer; // Used by the include of actions_dellink.inc.php
  81. /*
  82. * Actions
  83. */
  84. $parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
  85. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  86. if ($reshook < 0) {
  87. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  88. }
  89. if (empty($reshook)) {
  90. $backurlforlist = DOL_URL_ROOT.'/projet/list.php';
  91. // Cancel
  92. if ($cancel) {
  93. if (GETPOST("comefromclone") == 1) {
  94. $result = $object->delete($user);
  95. if ($result > 0) {
  96. header("Location: index.php");
  97. exit;
  98. } else {
  99. dol_syslog($object->error, LOG_DEBUG);
  100. setEventMessages($langs->trans("CantRemoveProject", $langs->transnoentitiesnoconv("ProjectOverview")), null, 'errors');
  101. }
  102. }
  103. }
  104. if (empty($backtopage) || ($cancel && empty($id))) {
  105. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  106. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  107. $backtopage = $backurlforlist;
  108. } else {
  109. $backtopage = DOL_URL_ROOT.'/projet/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  110. }
  111. }
  112. }
  113. if ($cancel) {
  114. if (!empty($backtopageforcancel)) {
  115. header("Location: ".$backtopageforcancel);
  116. exit;
  117. } elseif (!empty($backtopage)) {
  118. header("Location: ".$backtopage);
  119. exit;
  120. }
  121. $action = '';
  122. }
  123. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  124. if ($action == 'add' && $user->rights->projet->creer) {
  125. $error = 0;
  126. if (!GETPOST('ref')) {
  127. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
  128. $error++;
  129. }
  130. if (!GETPOST('title')) {
  131. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ProjectLabel")), null, 'errors');
  132. $error++;
  133. }
  134. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  135. if (GETPOST('opp_amount') != '' && !(GETPOST('opp_status') > 0)) {
  136. $error++;
  137. setEventMessages($langs->trans("ErrorOppStatusRequiredIfAmount"), null, 'errors');
  138. }
  139. }
  140. // Create with status validated immediatly
  141. if (!empty($conf->global->PROJECT_CREATE_NO_DRAFT)) {
  142. $status = Project::STATUS_VALIDATED;
  143. }
  144. if (!$error) {
  145. $error = 0;
  146. $db->begin();
  147. $object->ref = GETPOST('ref', 'alphanohtml');
  148. $object->title = GETPOST('title', 'alphanohtml');
  149. $object->socid = GETPOST('socid', 'int');
  150. $object->description = GETPOST('description', 'restricthtml'); // Do not use 'alpha' here, we want field as it is
  151. $object->public = GETPOST('public', 'alphanohtml');
  152. $object->opp_amount = price2num(GETPOST('opp_amount', 'alphanohtml'));
  153. $object->budget_amount = price2num(GETPOST('budget_amount', 'alphanohtml'));
  154. $object->date_c = dol_now();
  155. $object->date_start = $date_start;
  156. $object->date_end = $date_end;
  157. $object->statut = $status;
  158. $object->opp_status = $opp_status;
  159. $object->opp_percent = $opp_percent;
  160. $object->usage_opportunity = (GETPOST('usage_opportunity', 'alpha') == 'on' ? 1 : 0);
  161. $object->usage_task = (GETPOST('usage_task', 'alpha') == 'on' ? 1 : 0);
  162. $object->usage_bill_time = (GETPOST('usage_bill_time', 'alpha') == 'on' ? 1 : 0);
  163. $object->usage_organize_event = (GETPOST('usage_organize_event', 'alpha') == 'on' ? 1 : 0);
  164. // Fill array 'array_options' with data from add form
  165. $ret = $extrafields->setOptionalsFromPost(null, $object);
  166. if ($ret < 0) {
  167. $error++;
  168. }
  169. $result = $object->create($user);
  170. if (!$error && $result > 0) {
  171. // Add myself as project leader
  172. $typeofcontact = 'PROJECTLEADER';
  173. $result = $object->add_contact($user->id, $typeofcontact, 'internal');
  174. // -3 means type not found (PROJECTLEADER renamed, de-activated or deleted), so don't prevent creation if it has been the case
  175. if ($result == -3) {
  176. setEventMessage('ErrorPROJECTLEADERRoleMissingRestoreIt', 'errors');
  177. $error++;
  178. } elseif ($result < 0) {
  179. $langs->load("errors");
  180. setEventMessages($object->error, $object->errors, 'errors');
  181. $error++;
  182. }
  183. } else {
  184. $langs->load("errors");
  185. setEventMessages($object->error, $object->errors, 'errors');
  186. $error++;
  187. }
  188. if (!$error && !empty($object->id) > 0) {
  189. // Category association
  190. $categories = GETPOST('categories', 'array');
  191. $result = $object->setCategories($categories);
  192. if ($result < 0) {
  193. $langs->load("errors");
  194. setEventMessages($object->error, $object->errors, 'errors');
  195. $error++;
  196. }
  197. }
  198. if (!$error) {
  199. $db->commit();
  200. if (!empty($backtopage)) {
  201. $backtopage = preg_replace('/--IDFORBACKTOPAGE--|__ID__/', $object->id, $backtopage); // New method to autoselect project after a New on another form object creation
  202. $backtopage = $backtopage.'&projectid='.$object->id; // Old method
  203. header("Location: ".$backtopage);
  204. exit;
  205. } else {
  206. header("Location:card.php?id=".$object->id);
  207. exit;
  208. }
  209. } else {
  210. $db->rollback();
  211. unset($_POST["ref"]);
  212. $action = 'create';
  213. }
  214. } else {
  215. $action = 'create';
  216. }
  217. }
  218. if ($action == 'update' && empty(GETPOST('cancel')) && $user->rights->projet->creer) {
  219. $error = 0;
  220. if (empty($ref)) {
  221. $error++;
  222. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
  223. }
  224. if (!GETPOST("title")) {
  225. $error++;
  226. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ProjectLabel")), null, 'errors');
  227. }
  228. $db->begin();
  229. if (!$error) {
  230. $object->oldcopy = clone $object;
  231. $old_start_date = $object->date_start;
  232. $object->ref = GETPOST('ref', 'alpha');
  233. $object->title = GETPOST('title', 'alphanohtml'); // Do not use 'alpha' here, we want field as it is
  234. $object->statut = GETPOST('status', 'int');
  235. $object->socid = GETPOST('socid', 'int');
  236. $object->description = GETPOST('description', 'restricthtml'); // Do not use 'alpha' here, we want field as it is
  237. $object->public = GETPOST('public', 'alpha');
  238. $object->date_start = (!GETPOST('projectstart')) ? '' : $date_start;
  239. $object->date_end = (!GETPOST('projectend')) ? '' : $date_end;
  240. if (GETPOSTISSET('opp_amount')) {
  241. $object->opp_amount = price2num(GETPOST('opp_amount', 'alpha'));
  242. }
  243. if (GETPOSTISSET('budget_amount')) {
  244. $object->budget_amount = price2num(GETPOST('budget_amount', 'alpha'));
  245. }
  246. if (GETPOSTISSET('opp_status')) {
  247. $object->opp_status = $opp_status;
  248. }
  249. if (GETPOSTISSET('opp_percent')) {
  250. $object->opp_percent = $opp_percent;
  251. }
  252. $object->usage_opportunity = (GETPOST('usage_opportunity', 'alpha') == 'on' ? 1 : 0);
  253. $object->usage_task = (GETPOST('usage_task', 'alpha') == 'on' ? 1 : 0);
  254. $object->usage_bill_time = (GETPOST('usage_bill_time', 'alpha') == 'on' ? 1 : 0);
  255. $object->usage_organize_event = (GETPOST('usage_organize_event', 'alpha') == 'on' ? 1 : 0);
  256. // Fill array 'array_options' with data from add form
  257. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  258. if ($ret < 0) {
  259. $error++;
  260. }
  261. }
  262. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  263. if ($object->opp_amount && ($object->opp_status <= 0)) {
  264. $error++;
  265. setEventMessages($langs->trans("ErrorOppStatusRequiredIfAmount"), null, 'errors');
  266. }
  267. }
  268. if (!$error) {
  269. $result = $object->update($user);
  270. if ($result < 0) {
  271. $error++;
  272. if ($result == -4) {
  273. setEventMessages($langs->trans("ErrorRefAlreadyExists"), null, 'errors');
  274. } else {
  275. setEventMessages($object->error, $object->errors, 'errors');
  276. }
  277. } else {
  278. // Category association
  279. $categories = GETPOST('categories', 'array');
  280. $result = $object->setCategories($categories);
  281. if ($result < 0) {
  282. $error++;
  283. setEventMessages($object->error, $object->errors, 'errors');
  284. }
  285. }
  286. }
  287. if (!$error) {
  288. if (GETPOST("reportdate") && ($object->date_start != $old_start_date)) {
  289. $result = $object->shiftTaskDate($old_start_date);
  290. if ($result < 0) {
  291. $error++;
  292. setEventMessages($langs->trans("ErrorShiftTaskDate").':'.$object->error, $object->errors, 'errors');
  293. }
  294. }
  295. }
  296. // Check if we must change status
  297. if (GETPOST('closeproject')) {
  298. $resclose = $object->setClose($user);
  299. if ($resclose < 0) {
  300. $error++;
  301. setEventMessages($langs->trans("FailedToCloseProject").':'.$object->error, $object->errors, 'errors');
  302. }
  303. }
  304. if ($error) {
  305. $db->rollback();
  306. $action = 'edit';
  307. } else {
  308. $db->commit();
  309. if (GETPOST('socid', 'int') > 0) {
  310. $object->fetch_thirdparty(GETPOST('socid', 'int'));
  311. } else {
  312. unset($object->thirdparty);
  313. }
  314. }
  315. }
  316. // Build doc
  317. if ($action == 'builddoc' && $user->rights->projet->creer) {
  318. // Save last template used to generate document
  319. if (GETPOST('model')) {
  320. $object->setDocModel($user, GETPOST('model', 'alpha'));
  321. }
  322. $outputlangs = $langs;
  323. if (GETPOST('lang_id', 'aZ09')) {
  324. $outputlangs = new Translate("", $conf);
  325. $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
  326. }
  327. $result = $object->generateDocument($object->model_pdf, $outputlangs);
  328. if ($result <= 0) {
  329. setEventMessages($object->error, $object->errors, 'errors');
  330. $action = '';
  331. }
  332. }
  333. // Delete file in doc form
  334. if ($action == 'remove_file' && $user->rights->projet->creer) {
  335. if ($object->id > 0) {
  336. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  337. $langs->load("other");
  338. $upload_dir = $conf->projet->dir_output;
  339. $file = $upload_dir.'/'.GETPOST('file');
  340. $ret = dol_delete_file($file, 0, 0, 0, $object);
  341. if ($ret) {
  342. setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
  343. } else {
  344. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
  345. }
  346. $action = '';
  347. }
  348. }
  349. if ($action == 'confirm_validate' && $confirm == 'yes') {
  350. $result = $object->setValid($user);
  351. if ($result <= 0) {
  352. setEventMessages($object->error, $object->errors, 'errors');
  353. }
  354. }
  355. if ($action == 'confirm_close' && $confirm == 'yes') {
  356. $result = $object->setClose($user);
  357. if ($result <= 0) {
  358. setEventMessages($object->error, $object->errors, 'errors');
  359. }
  360. }
  361. if ($action == 'confirm_reopen' && $confirm == 'yes') {
  362. $result = $object->setValid($user);
  363. if ($result <= 0) {
  364. setEventMessages($object->error, $object->errors, 'errors');
  365. }
  366. }
  367. if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $user->rights->projet->supprimer) {
  368. $object->fetch($id);
  369. $result = $object->delete($user);
  370. if ($result > 0) {
  371. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  372. header("Location: list.php?restore_lastsearch_values=1");
  373. exit;
  374. } else {
  375. dol_syslog($object->error, LOG_DEBUG);
  376. setEventMessages($object->error, $object->errors, 'errors');
  377. }
  378. }
  379. if ($action == 'confirm_clone' && $user->rights->projet->creer && $confirm == 'yes') {
  380. $clone_contacts = GETPOST('clone_contacts') ? 1 : 0;
  381. $clone_tasks = GETPOST('clone_tasks') ? 1 : 0;
  382. $clone_project_files = GETPOST('clone_project_files') ? 1 : 0;
  383. $clone_task_files = GETPOST('clone_task_files') ? 1 : 0;
  384. $clone_notes = GETPOST('clone_notes') ? 1 : 0;
  385. $move_date = GETPOST('move_date') ? 1 : 0;
  386. $clone_thirdparty = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : 0;
  387. $result = $object->createFromClone($user, $object->id, $clone_contacts, $clone_tasks, $clone_project_files, $clone_task_files, $clone_notes, $move_date, 0, $clone_thirdparty);
  388. if ($result <= 0) {
  389. setEventMessages($object->error, $object->errors, 'errors');
  390. } else {
  391. // Load new object
  392. $newobject = new Project($db);
  393. $newobject->fetch($result);
  394. $newobject->fetch_optionals();
  395. $newobject->fetch_thirdparty(); // Load new object
  396. $object = $newobject;
  397. $action = 'edit';
  398. $comefromclone = true;
  399. }
  400. }
  401. // Actions to send emails
  402. $triggersendname = 'PROJECT_SENTBYMAIL';
  403. $paramname = 'id';
  404. $autocopy = 'MAIN_MAIL_AUTOCOPY_PROJECT_TO'; // used to know the automatic BCC to add
  405. $trackid = 'proj'.$object->id;
  406. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  407. }
  408. /*
  409. * View
  410. */
  411. $form = new Form($db);
  412. $formfile = new FormFile($db);
  413. $formproject = new FormProjets($db);
  414. $userstatic = new User($db);
  415. $title = $langs->trans("Project").' - '.$object->ref.(!empty($object->thirdparty->name) ? ' - '.$object->thirdparty->name : '').(!empty($object->title) ? ' - '.$object->title : '');
  416. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE)) {
  417. $title = $object->ref.(!empty($object->thirdparty->name) ? ' - '.$object->thirdparty->name : '').(!empty($object->title) ? ' - '.$object->title : '');
  418. }
  419. $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte";
  420. llxHeader("", $title, $help_url);
  421. $titleboth = $langs->trans("LeadsOrProjects");
  422. $titlenew = $langs->trans("NewLeadOrProject"); // Leads and opportunities by default
  423. if (empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  424. $titleboth = $langs->trans("Projects");
  425. $titlenew = $langs->trans("NewProject");
  426. }
  427. if ($conf->global->PROJECT_USE_OPPORTUNITIES == 2) { // 2 = leads only
  428. $titleboth = $langs->trans("Leads");
  429. $titlenew = $langs->trans("NewLead");
  430. }
  431. if ($action == 'create' && $user->rights->projet->creer) {
  432. /*
  433. * Create
  434. */
  435. $thirdparty = new Societe($db);
  436. if ($socid > 0) {
  437. $thirdparty->fetch($socid);
  438. }
  439. print load_fiche_titre($titlenew, '', 'project');
  440. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  441. print '<input type="hidden" name="action" value="add">';
  442. print '<input type="hidden" name="token" value="'.newToken().'">';
  443. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  444. print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
  445. print dol_get_fiche_head();
  446. print '<table class="border centpercent tableforfieldcreate">';
  447. $defaultref = '';
  448. $modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
  449. // Search template files
  450. $file = ''; $classname = ''; $filefound = 0;
  451. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  452. foreach ($dirmodels as $reldir) {
  453. $file = dol_buildpath($reldir."core/modules/project/".$modele.'.php', 0);
  454. if (file_exists($file)) {
  455. $filefound = 1;
  456. $classname = $modele;
  457. break;
  458. }
  459. }
  460. if ($filefound) {
  461. $result = dol_include_once($reldir."core/modules/project/".$modele.'.php');
  462. $modProject = new $classname;
  463. $defaultref = $modProject->getNextValue($thirdparty, $object);
  464. }
  465. if (is_numeric($defaultref) && $defaultref <= 0) {
  466. $defaultref = '';
  467. }
  468. // Ref
  469. $suggestedref = (GETPOST("ref") ? GETPOST("ref") : $defaultref);
  470. print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td class><input class="maxwidth150onsmartphone" type="text" name="ref" value="'.dol_escape_htmltag($suggestedref).'">';
  471. print ' '.$form->textwithpicto('', $langs->trans("YouCanCompleteRef", $suggestedref));
  472. print '</td></tr>';
  473. // Label
  474. print '<tr><td><span class="fieldrequired">'.$langs->trans("ProjectLabel").'</span></td><td><input class="width500 maxwidth150onsmartphone" type="text" name="title" value="'.dol_escape_htmltag(GETPOST("title", 'alphanohtml')).'" autofocus></td></tr>';
  475. // Usage (opp, task, bill time, ...)
  476. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  477. print '<tr><td class="tdtop">';
  478. print $langs->trans("Usage");
  479. print '</td>';
  480. print '<td>';
  481. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  482. print '<input type="checkbox" id="usage_opportunity" name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ' checked="checked"').'"> ';
  483. $htmltext = $langs->trans("ProjectFollowOpportunity");
  484. print '<label for="usage_opportunity">'.$form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext).'</label>';
  485. print '<script>';
  486. print '$( document ).ready(function() {
  487. jQuery("#usage_opportunity").change(function() {
  488. if (jQuery("#usage_opportunity").prop("checked")) {
  489. console.log("Show opportunities fields");
  490. jQuery(".classuseopportunity").show();
  491. } else {
  492. console.log("Hide opportunities fields "+jQuery("#usage_opportunity").prop("checked"));
  493. jQuery(".classuseopportunity").hide();
  494. }
  495. });
  496. });';
  497. print '</script>';
  498. print '<br>';
  499. }
  500. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  501. print '<input type="checkbox" id="usage_task" name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ' checked="checked"').'"> ';
  502. $htmltext = $langs->trans("ProjectFollowTasks");
  503. print '<label for="usage_task">'.$form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext).'</label>';
  504. print '<br>';
  505. }
  506. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  507. print '<input type="checkbox" id="usage_bill_time" name="usage_bill_time"'.(GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '').'"> ';
  508. $htmltext = $langs->trans("ProjectBillTimeDescription");
  509. print '<label for="usage_bill_time">'.$form->textwithpicto($langs->trans("BillTime"), $htmltext).'</label>';
  510. print '<br>';
  511. }
  512. if (!empty($conf->eventorganization->enabled)) {
  513. print '<input type="checkbox" id="usage_organize_event" name="usage_organize_event"'.(GETPOST('usage_organize_event', 'alpha')!=''?' checked="checked"':'').'"> ';
  514. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  515. print '<label for="usage_organize_event">'.$form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext).'</label>';
  516. }
  517. print '</td>';
  518. print '</tr>';
  519. }
  520. // Thirdparty
  521. if ($conf->societe->enabled) {
  522. print '<tr><td>';
  523. print (empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) ? '' : '<span class="fieldrequired">');
  524. print $langs->trans("ThirdParty");
  525. print (empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) ? '' : '</span>');
  526. print '</td><td class="maxwidthonsmartphone">';
  527. $filteronlist = '';
  528. if (!empty($conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST)) {
  529. $filteronlist = $conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST;
  530. }
  531. $text = img_picto('', 'company').$form->select_company(GETPOST('socid', 'int'), 'socid', $filteronlist, 'SelectThirdParty', 1, 0, array(), 0, 'minwidth300 widthcentpercentminusxx maxwidth500');
  532. if (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) && empty($conf->dol_use_jmobile)) {
  533. $texthelp = $langs->trans("IfNeedToUseOtherObjectKeepEmpty");
  534. print $form->textwithtooltip($text.' '.img_help(), $texthelp, 1);
  535. } else {
  536. print $text;
  537. }
  538. if (!GETPOSTISSET('backtopage')) {
  539. $url = '/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create');
  540. $newbutton = '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span>';
  541. // TODO @LDR Impletment this
  542. //$tmpbacktopagejsfields = 'socid:search_socid';
  543. //print dolButtonToOpenUrlInDialogPopup('addthirdparty', $langs->transnoentitiesnoconv('AddThirdParty'), $newbutton, $url, '', '', $tmpbacktopagejsfields);
  544. print ' <a href="'.DOL_URL_ROOT.$url.'">'.$newbutton.'</a>';
  545. }
  546. print '</td></tr>';
  547. }
  548. // Status
  549. if ($status != '') {
  550. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  551. print '<input type="hidden" name="status" value="'.$status.'">';
  552. print $object->LibStatut($status, 4);
  553. print '</td></tr>';
  554. }
  555. // Visibility
  556. print '<tr><td>'.$langs->trans("Visibility").'</td><td class="maxwidthonsmartphone">';
  557. $array = array();
  558. if (empty($conf->global->PROJECT_DISABLE_PRIVATE_PROJECT)) {
  559. $array[0] = $langs->trans("PrivateProject");
  560. }
  561. if (empty($conf->global->PROJECT_DISABLE_PUBLIC_PROJECT)) {
  562. $array[1] = $langs->trans("SharedProject");
  563. }
  564. if (count($array) > 0) {
  565. print $form->selectarray('public', $array, GETPOST('public'), 0, 0, 0, '', 0, 0, 0, '', '', 1);
  566. } else {
  567. print '<input type="hidden" name="public" id="public" value="'.GETPOST('public').'">';
  568. if (GETPOST('public') == 0) {
  569. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  570. print $langs->trans("PrivateProject");
  571. } else {
  572. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  573. print $langs->trans("SharedProject");
  574. }
  575. }
  576. print '</td></tr>';
  577. // Date start
  578. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  579. print $form->selectDate(($date_start ? $date_start : ''), 'projectstart', 0, 0, 0, '', 1, 0);
  580. print '</td></tr>';
  581. // Date end
  582. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  583. print $form->selectDate(($date_end ? $date_end : -1), 'projectend', 0, 0, 0, '', 1, 0);
  584. print '</td></tr>';
  585. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  586. // Opportunity status
  587. print '<tr class="classuseopportunity"><td>'.$langs->trans("OpportunityStatus").'</td>';
  588. print '<td class="maxwidthonsmartphone">';
  589. print $formproject->selectOpportunityStatus('opp_status', GETPOSTISSET('opp_status') ? GETPOST('opp_status') : $object->opp_status, 1, 0, 0, 0, '', 0, 1);
  590. print '</tr>';
  591. // Opportunity probability
  592. print '<tr class="classuseopportunity"><td>'.$langs->trans("OpportunityProbability").'</td>';
  593. print '<td><input size="5" type="text" id="opp_percent" name="opp_percent" value="'.dol_escape_htmltag(GETPOSTISSET('opp_percent') ? GETPOST('opp_percent') : '').'"><span class="hideonsmartphone"> %</span>';
  594. print '<input type="hidden" name="opp_percent_not_set" id="opp_percent_not_set" value="'.dol_escape_htmltag(GETPOSTISSET('opp_percent') ? '0' : '1').'">';
  595. print '</td>';
  596. print '</tr>';
  597. // Opportunity amount
  598. print '<tr class="classuseopportunity"><td>'.$langs->trans("OpportunityAmount").'</td>';
  599. print '<td><input size="5" type="text" name="opp_amount" value="'.dol_escape_htmltag(GETPOSTISSET('opp_amount') ? GETPOST('opp_amount') : '').'"></td>';
  600. print '</tr>';
  601. }
  602. // Budget
  603. print '<tr><td>'.$langs->trans("Budget").'</td>';
  604. print '<td><input size="5" type="text" name="budget_amount" value="'.dol_escape_htmltag(GETPOSTISSET('budget_amount') ? GETPOST('budget_amount') : '').'"></td>';
  605. print '</tr>';
  606. // Description
  607. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  608. print '<td>';
  609. $doleditor = new DolEditor('description', GETPOST("description", 'restricthtml'), '', 90, 'dolibarr_notes', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
  610. $doleditor->Create();
  611. print '</td></tr>';
  612. if (!empty($conf->categorie->enabled)) {
  613. // Categories
  614. print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
  615. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PROJECT, '', 'parent', 64, 0, 1);
  616. $arrayselected = GETPOST('categories', 'array');
  617. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  618. print "</td></tr>";
  619. }
  620. // Other options
  621. $parameters = array();
  622. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  623. print $hookmanager->resPrint;
  624. if (empty($reshook)) {
  625. print $object->showOptionals($extrafields, 'create');
  626. }
  627. print '</table>';
  628. print dol_get_fiche_end();
  629. print $form->buttonsSaveCancel('CreateDraft');
  630. print '</form>';
  631. // Change probability from status
  632. print '<script type="text/javascript">
  633. jQuery(document).ready(function() {
  634. function change_percent()
  635. {
  636. var element = jQuery("#opp_status option:selected");
  637. var defaultpercent = element.attr("defaultpercent");
  638. /*if (jQuery("#opp_percent_not_set").val() == "") */
  639. jQuery("#opp_percent").val(defaultpercent);
  640. }
  641. /*init_myfunc();*/
  642. jQuery("#opp_status").change(function() {
  643. change_percent();
  644. });
  645. jQuery("#usage_task").change(function() {
  646. console.log("We click on usage task "+jQuery("#usage_task").is(":checked"));
  647. if (! jQuery("#usage_task").is(":checked")) {
  648. jQuery("#usage_bill_time").prop("checked", false);
  649. }
  650. });
  651. jQuery("#usage_bill_time").change(function() {
  652. console.log("We click on usage to bill time");
  653. if (jQuery("#usage_bill_time").is(":checked")) {
  654. jQuery("#usage_task").prop("checked", true);
  655. }
  656. });
  657. });
  658. </script>';
  659. } elseif ($object->id > 0) {
  660. /*
  661. * Show or edit
  662. */
  663. $res = $object->fetch_optionals();
  664. // To verify role of users
  665. $userAccess = $object->restrictedProjectArea($user, 'read');
  666. $userWrite = $object->restrictedProjectArea($user, 'write');
  667. $userDelete = $object->restrictedProjectArea($user, 'delete');
  668. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  669. // Confirmation validation
  670. if ($action == 'validate') {
  671. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProject'), $langs->trans('ConfirmValidateProject'), 'confirm_validate', '', 0, 1);
  672. }
  673. // Confirmation close
  674. if ($action == 'close') {
  675. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CloseAProject"), $langs->trans("ConfirmCloseAProject"), "confirm_close", '', '', 1);
  676. }
  677. // Confirmation reopen
  678. if ($action == 'reopen') {
  679. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ReOpenAProject"), $langs->trans("ConfirmReOpenAProject"), "confirm_reopen", '', '', 1);
  680. }
  681. // Confirmation delete
  682. if ($action == 'delete') {
  683. $text = $langs->trans("ConfirmDeleteAProject");
  684. $task = new Task($db);
  685. $taskarray = $task->getTasksArray(0, 0, $object->id, 0, 0);
  686. $nboftask = count($taskarray);
  687. if ($nboftask) {
  688. $text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoRemoveTasks", $nboftask);
  689. }
  690. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteAProject"), $text, "confirm_delete", '', '', 1);
  691. }
  692. // Clone confirmation
  693. if ($action == 'clone') {
  694. $formquestion = array(
  695. 'text' => $langs->trans("ConfirmClone"),
  696. array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int') > 0 ?GETPOST('socid', 'int') : $object->socid, 'socid', '', "None", 0, 0, null, 0, 'minwidth200')),
  697. array('type' => 'checkbox', 'name' => 'clone_contacts', 'label' => $langs->trans("CloneContacts"), 'value' => true),
  698. array('type' => 'checkbox', 'name' => 'clone_tasks', 'label' => $langs->trans("CloneTasks"), 'value' => true),
  699. array('type' => 'checkbox', 'name' => 'move_date', 'label' => $langs->trans("CloneMoveDate"), 'value' => true),
  700. array('type' => 'checkbox', 'name' => 'clone_notes', 'label' => $langs->trans("CloneNotes"), 'value' => true),
  701. array('type' => 'checkbox', 'name' => 'clone_project_files', 'label' => $langs->trans("CloneProjectFiles"), 'value' => false),
  702. array('type' => 'checkbox', 'name' => 'clone_task_files', 'label' => $langs->trans("CloneTaskFiles"), 'value' => false)
  703. );
  704. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ToClone"), $langs->trans("ConfirmCloneProject"), "confirm_clone", $formquestion, '', 1, 300, 590);
  705. }
  706. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  707. print '<input type="hidden" name="token" value="'.newToken().'">';
  708. print '<input type="hidden" name="action" value="update">';
  709. print '<input type="hidden" name="id" value="'.$object->id.'">';
  710. print '<input type="hidden" name="comefromclone" value="'.$comefromclone.'">';
  711. $head = project_prepare_head($object);
  712. if ($action == 'edit' && $userWrite > 0) {
  713. print dol_get_fiche_head($head, 'project', $langs->trans("Project"), 0, ($object->public ? 'projectpub' : 'project'));
  714. print '<table class="border centpercent">';
  715. // Ref
  716. $suggestedref = $object->ref;
  717. print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Ref").'</td>';
  718. print '<td><input size="25" name="ref" value="'.$suggestedref.'">';
  719. print ' '.$form->textwithpicto('', $langs->trans("YouCanCompleteRef", $suggestedref));
  720. print '</td></tr>';
  721. // Label
  722. print '<tr><td class="fieldrequired">'.$langs->trans("ProjectLabel").'</td>';
  723. print '<td><input class="quatrevingtpercent" name="title" value="'.dol_escape_htmltag($object->title).'"></td></tr>';
  724. // Status
  725. print '<tr><td class="fieldrequired">'.$langs->trans("Status").'</td><td>';
  726. print '<select class="flat" name="status">';
  727. foreach ($object->statuts_short as $key => $val) {
  728. print '<option value="'.$key.'"'.((GETPOSTISSET('status') ?GETPOST('status') : $object->statut) == $key ? ' selected="selected"' : '').'>'.$langs->trans($val).'</option>';
  729. }
  730. print '</select>';
  731. print '</td></tr>';
  732. // Usage
  733. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  734. print '<tr><td class="tdtop">';
  735. print $langs->trans("Usage");
  736. print '</td>';
  737. print '<td>';
  738. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  739. print '<input type="checkbox" id="usage_opportunity" name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  740. $htmltext = $langs->trans("ProjectFollowOpportunity");
  741. print '<label for="usage_opportunity">'.$form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext).'</label>';
  742. print '<script>';
  743. print '$( document ).ready(function() {
  744. jQuery("#usage_opportunity").change(function() {
  745. if (jQuery("#usage_opportunity").prop("checked")) {
  746. console.log("Show opportunities fields");
  747. jQuery(".classuseopportunity").show();
  748. } else {
  749. console.log("Hide opportunities fields "+jQuery("#usage_opportunity").prop("checked"));
  750. jQuery(".classuseopportunity").hide();
  751. }
  752. });
  753. });';
  754. print '</script>';
  755. print '<br>';
  756. }
  757. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  758. print '<input type="checkbox" id="usage_task" name="usage_task"' . (GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')) . '"> ';
  759. $htmltext = $langs->trans("ProjectFollowTasks");
  760. print '<label for="usage_task">'.$form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext).'</label>';
  761. print '<br>';
  762. }
  763. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  764. print '<input type="checkbox" id="usage_bill_time" name="usage_bill_time"' . (GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_bill_time ? ' checked="checked"' : '')) . '"> ';
  765. $htmltext = $langs->trans("ProjectBillTimeDescription");
  766. print '<label for="usage_bill_time">'.$form->textwithpicto($langs->trans("BillTime"), $htmltext).'</label>';
  767. print '<br>';
  768. }
  769. if (!empty($conf->eventorganization->enabled)) {
  770. print '<input type="checkbox" id="usage_organize_event" name="usage_organize_event"'. (GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_organize_event ? ' checked="checked"' : '')) . '"> ';
  771. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  772. print '<label for="usage_organize_event">'.$form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext).'</label>';
  773. }
  774. print '</td></tr>';
  775. }
  776. print '</td></tr>';
  777. // Thirdparty
  778. if ($conf->societe->enabled) {
  779. print '<tr><td>';
  780. print (empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) ? '' : '<span class="fieldrequired">');
  781. print $langs->trans("ThirdParty");
  782. print (empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) ? '' : '</span>');
  783. print '</td><td>';
  784. $filteronlist = '';
  785. if (!empty($conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST)) {
  786. $filteronlist = $conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST;
  787. }
  788. $text = $form->select_company($object->thirdparty->id, 'socid', $filteronlist, 'None', 1, 0, array(), 0, 'minwidth300');
  789. if (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) && empty($conf->dol_use_jmobile)) {
  790. $texthelp = $langs->trans("IfNeedToUseOtherObjectKeepEmpty");
  791. print $form->textwithtooltip($text.' '.img_help(), $texthelp, 1, 0, '', '', 2);
  792. } else {
  793. print $text;
  794. }
  795. print '</td></tr>';
  796. }
  797. // Visibility
  798. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  799. $array = array();
  800. if (empty($conf->global->PROJECT_DISABLE_PRIVATE_PROJECT)) {
  801. $array[0] = $langs->trans("PrivateProject");
  802. }
  803. if (empty($conf->global->PROJECT_DISABLE_PUBLIC_PROJECT)) {
  804. $array[1] = $langs->trans("SharedProject");
  805. }
  806. if (count($array) > 0) {
  807. print $form->selectarray('public', $array, $object->public, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  808. } else {
  809. print '<input type="hidden" id="public" name="public" value="'.$object->public.'">';
  810. if ($object->public == 0) {
  811. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  812. print $langs->trans("PrivateProject");
  813. } else {
  814. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  815. print $langs->trans("SharedProject");
  816. }
  817. }
  818. print '</td></tr>';
  819. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  820. $classfortr = ($object->usage_opportunity ? '' : ' hideobject');
  821. // Opportunity status
  822. print '<tr class="classuseopportunity'.$classfortr.'"><td>'.$langs->trans("OpportunityStatus").'</td>';
  823. print '<td>';
  824. print $formproject->selectOpportunityStatus('opp_status', $object->opp_status, 1, 0, 0, 0, 'inline-block valignmiddle', 0, 1);
  825. print '<div id="divtocloseproject" class="inline-block valign" style="display: none;"> &nbsp; &nbsp; ';
  826. print '<input type="checkbox" id="inputcloseproject" name="closeproject" />';
  827. print '<label for="inputcloseproject">'.$langs->trans("AlsoCloseAProject").'</label>';
  828. print '</div>';
  829. print '</td>';
  830. print '</tr>';
  831. // Opportunity probability
  832. print '<tr class="classuseopportunity'.$classfortr.'"><td>'.$langs->trans("OpportunityProbability").'</td>';
  833. print '<td><input size="5" type="text" id="opp_percent" name="opp_percent" value="'.(GETPOSTISSET('opp_percent') ? GETPOST('opp_percent') : (strcmp($object->opp_percent, '') ?vatrate($object->opp_percent) : '')).'"> %';
  834. print '<span id="oldopppercent"></span>';
  835. print '</td>';
  836. print '</tr>';
  837. // Opportunity amount
  838. print '<tr class="classuseopportunity'.$classfortr.'"><td>'.$langs->trans("OpportunityAmount").'</td>';
  839. print '<td><input size="5" type="text" name="opp_amount" value="'.(GETPOSTISSET('opp_amount') ? GETPOST('opp_amount') : (strcmp($object->opp_amount, '') ? price2num($object->opp_amount) : '')).'"></td>';
  840. print '</tr>';
  841. }
  842. // Date start
  843. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  844. print $form->selectDate($object->date_start ? $object->date_start : -1, 'projectstart', 0, 0, 0, '', 1, 0);
  845. print ' &nbsp; &nbsp; <input type="checkbox" class="valignmiddle" id="reportdate" name="reportdate" value="yes" ';
  846. if ($comefromclone) {
  847. print ' checked ';
  848. }
  849. print '/><label for="reportdate">'.$langs->trans("ProjectReportDate").'</label>';
  850. print '</td></tr>';
  851. // Date end
  852. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  853. print $form->selectDate($object->date_end ? $object->date_end : -1, 'projectend', 0, 0, 0, '', 1, 0);
  854. print '</td></tr>';
  855. // Budget
  856. print '<tr><td>'.$langs->trans("Budget").'</td>';
  857. print '<td><input size="5" type="text" name="budget_amount" value="'.(GETPOSTISSET('budget_amount') ? GETPOST('budget_amount') : (strcmp($object->budget_amount, '') ? price2num($object->budget_amount) : '')).'"></td>';
  858. print '</tr>';
  859. // Description
  860. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  861. print '<td>';
  862. $doleditor = new DolEditor('description', $object->description, '', 90, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_3, '90%');
  863. $doleditor->Create();
  864. print '</td></tr>';
  865. // Tags-Categories
  866. if ($conf->categorie->enabled) {
  867. print '<tr><td>'.$langs->trans("Categories").'</td><td>';
  868. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PROJECT, '', 'parent', 64, 0, 1);
  869. $c = new Categorie($db);
  870. $cats = $c->containing($object->id, Categorie::TYPE_PROJECT);
  871. foreach ($cats as $cat) {
  872. $arrayselected[] = $cat->id;
  873. }
  874. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, '0');
  875. print "</td></tr>";
  876. }
  877. // Other options
  878. $parameters = array();
  879. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  880. print $hookmanager->resPrint;
  881. if (empty($reshook)) {
  882. print $object->showOptionals($extrafields, 'edit');
  883. }
  884. print '</table>';
  885. } else {
  886. print dol_get_fiche_head($head, 'project', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  887. // Project card
  888. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  889. $morehtmlref = '<div class="refidno">';
  890. // Title
  891. $morehtmlref .= dol_escape_htmltag($object->title);
  892. // Thirdparty
  893. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : ';
  894. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  895. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'project');
  896. }
  897. $morehtmlref .= '</div>';
  898. // Define a complementary filter for search of next/prev ref.
  899. if (empty($user->rights->projet->all->lire)) {
  900. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  901. $object->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  902. }
  903. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  904. print '<div class="fichecenter">';
  905. print '<div class="fichehalfleft">';
  906. print '<div class="underbanner clearboth"></div>';
  907. print '<table class="border tableforfield" width="100%">';
  908. // Usage
  909. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  910. print '<tr><td class="tdtop">';
  911. print $langs->trans("Usage");
  912. print '</td>';
  913. print '<td>';
  914. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  915. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  916. $htmltext = $langs->trans("ProjectFollowOpportunity");
  917. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  918. print '<br>';
  919. }
  920. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  921. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
  922. $htmltext = $langs->trans("ProjectFollowTasks");
  923. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  924. print '<br>';
  925. }
  926. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  927. print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_bill_time ? ' checked="checked"' : '')).'"> ';
  928. $htmltext = $langs->trans("ProjectBillTimeDescription");
  929. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  930. print '<br>';
  931. }
  932. if (!empty($conf->eventorganization->enabled)) {
  933. print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_organize_event ? ' checked="checked"' : '')).'"> ';
  934. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  935. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  936. }
  937. print '</td></tr>';
  938. }
  939. // Visibility
  940. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  941. if ($object->public) {
  942. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  943. print $langs->trans('SharedProject');
  944. } else {
  945. print img_picto($langs->trans('SharedProject'), 'private', 'class="paddingrightonly"');
  946. print $langs->trans('PrivateProject');
  947. }
  948. print '</td></tr>';
  949. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) && !empty($object->usage_opportunity)) {
  950. // Opportunity status
  951. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  952. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  953. if ($code) {
  954. print $langs->trans("OppStatus".$code);
  955. }
  956. print '</td></tr>';
  957. // Opportunity percent
  958. print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
  959. if (strcmp($object->opp_percent, '')) {
  960. print price($object->opp_percent, 0, $langs, 1, 0).' %';
  961. }
  962. print '</td></tr>';
  963. // Opportunity Amount
  964. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  965. if (strcmp($object->opp_amount, '')) {
  966. print '<span class="amount">'.price($object->opp_amount, 0, $langs, 1, 0, -1, $conf->currency).'</span>';
  967. if (strcmp($object->opp_percent, '')) {
  968. print ' &nbsp; &nbsp; &nbsp; <span title="'.dol_escape_htmltag($langs->trans('OpportunityWeightedAmount')).'"><span class="opacitymedium">'.$langs->trans("Weighted").'</span>: <span class="amount">'.price($object->opp_amount * $object->opp_percent / 100, 0, $langs, 1, 0, -1, $conf->currency).'</span></span>';
  969. }
  970. }
  971. print '</td></tr>';
  972. // Opportunity Weighted Amount
  973. /*
  974. print '<tr><td>'.$langs->trans('OpportunityWeightedAmount').'</td><td>';
  975. if (strcmp($object->opp_amount, '') && strcmp($object->opp_percent, '')) {
  976. print '<span class="amount">'.price($object->opp_amount * $object->opp_percent / 100, 0, $langs, 1, 0, -1, $conf->currency).'</span>';
  977. }
  978. print '</td></tr>';
  979. */
  980. }
  981. // Date start - end
  982. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  983. $start = dol_print_date($object->date_start, 'day');
  984. print ($start ? $start : '?');
  985. $end = dol_print_date($object->date_end, 'day');
  986. print ' - ';
  987. print ($end ? $end : '?');
  988. if ($object->hasDelay()) {
  989. print img_warning("Late");
  990. }
  991. print '</td></tr>';
  992. // Budget
  993. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  994. if (strcmp($object->budget_amount, '')) {
  995. print '<span class="amount">'.price($object->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  996. }
  997. print '</td></tr>';
  998. // Other attributes
  999. $cols = 2;
  1000. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1001. print '</table>';
  1002. print '</div>';
  1003. print '<div class="fichehalfright">';
  1004. print '<div class="underbanner clearboth"></div>';
  1005. print '<table class="border tableforfield centpercent">';
  1006. // Description
  1007. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  1008. print dol_htmlentitiesbr($object->description);
  1009. print '</td></tr>';
  1010. // Categories
  1011. if ($conf->categorie->enabled) {
  1012. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  1013. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  1014. print "</td></tr>";
  1015. }
  1016. print '</table>';
  1017. print '</div>';
  1018. print '</div>';
  1019. print '<div class="clearboth"></div>';
  1020. }
  1021. print dol_get_fiche_end();
  1022. if ($action == 'edit' && $userWrite > 0) {
  1023. print $form->buttonsSaveCancel();
  1024. }
  1025. print '</form>';
  1026. // Change probability from status
  1027. if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  1028. // Default value to close or not when we set opp to 'WON'.
  1029. $defaultcheckedwhenoppclose = 1;
  1030. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  1031. $defaultcheckedwhenoppclose = 0;
  1032. }
  1033. print '<!-- Javascript to manage opportunity status change -->';
  1034. print '<script type="text/javascript">
  1035. jQuery(document).ready(function() {
  1036. function change_percent()
  1037. {
  1038. var element = jQuery("#opp_status option:selected");
  1039. var defaultpercent = element.attr("defaultpercent");
  1040. var defaultcloseproject = '.$defaultcheckedwhenoppclose.';
  1041. var elemcode = element.attr("elemcode");
  1042. var oldpercent = \''.dol_escape_js($object->opp_percent).'\';
  1043. console.log("We select "+elemcode);
  1044. /* Define if checkbox to close is checked or not */
  1045. var closeproject = 0;
  1046. if (elemcode == \'LOST\') closeproject = 1;
  1047. if (elemcode == \'WON\') closeproject = defaultcloseproject;
  1048. if (closeproject) jQuery("#inputcloseproject").prop("checked", true);
  1049. else jQuery("#inputcloseproject").prop("checked", false);
  1050. /* Make the close project checkbox visible or not */
  1051. console.log("closeproject="+closeproject);
  1052. if (elemcode == \'WON\' || elemcode == \'LOST\')
  1053. {
  1054. jQuery("#divtocloseproject").show();
  1055. }
  1056. else
  1057. {
  1058. jQuery("#divtocloseproject").hide();
  1059. }
  1060. /* Change percent with default percent (defaultpercent) if new status (defaultpercent) is higher than current (jQuery("#opp_percent").val()) */
  1061. console.log("oldpercent="+oldpercent);
  1062. if (oldpercent != \'\' && (parseFloat(defaultpercent) < parseFloat(oldpercent)))
  1063. {
  1064. if (jQuery("#opp_percent").val() != \'\' && oldpercent != \'\') jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+oldpercent+\' %\');
  1065. if (parseFloat(oldpercent) != 100) { jQuery("#opp_percent").val(oldpercent); }
  1066. else { jQuery("#opp_percent").val(defaultpercent); }
  1067. }
  1068. else
  1069. {
  1070. if ((parseFloat(jQuery("#opp_percent").val()) < parseFloat(defaultpercent)));
  1071. {
  1072. if (jQuery("#opp_percent").val() != \'\' && oldpercent != \'\') jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+oldpercent+\' %\');
  1073. jQuery("#opp_percent").val(defaultpercent);
  1074. }
  1075. }
  1076. }
  1077. jQuery("#opp_status").change(function() {
  1078. change_percent();
  1079. });
  1080. });
  1081. </script>';
  1082. }
  1083. /*
  1084. * Actions Buttons
  1085. */
  1086. print '<div class="tabsAction">';
  1087. $parameters = array();
  1088. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1089. // modified by hook
  1090. if (empty($reshook)) {
  1091. if ($action != "edit" && $action != 'presend') {
  1092. // Create event
  1093. /*if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a
  1094. // "workflow" action so should appears somewhere else on
  1095. // page.
  1096. {
  1097. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '&amp;projectid=' . $object->id . '">' . $langs->trans("AddAction") . '</a>';
  1098. }*/
  1099. // Send
  1100. if (empty($user->socid)) {
  1101. if ($object->statut != Project::STATUS_CLOSED) {
  1102. print '<a class="butAction" href="card.php?id='.$object->id.'&amp;action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>';
  1103. }
  1104. }
  1105. // Modify
  1106. if ($object->statut != Project::STATUS_CLOSED && $user->rights->projet->creer) {
  1107. if ($userWrite > 0) {
  1108. print '<a class="butAction" href="card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  1109. } else {
  1110. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Modify').'</a>';
  1111. }
  1112. }
  1113. // Validate
  1114. if ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer) {
  1115. if ($userWrite > 0) {
  1116. print '<a class="butAction" href="card.php?id='.$object->id.'&action=validate&token='.newToken().'">'.$langs->trans("Validate").'</a>';
  1117. } else {
  1118. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Validate').'</a>';
  1119. }
  1120. }
  1121. // Close
  1122. if ($object->statut == Project::STATUS_VALIDATED && $user->rights->projet->creer) {
  1123. if ($userWrite > 0) {
  1124. print '<a class="butAction" href="card.php?id='.$object->id.'&amp;action=close">'.$langs->trans("Close").'</a>';
  1125. } else {
  1126. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Close').'</a>';
  1127. }
  1128. }
  1129. // Reopen
  1130. if ($object->statut == Project::STATUS_CLOSED && $user->rights->projet->creer) {
  1131. if ($userWrite > 0) {
  1132. print '<a class="butAction" href="card.php?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>';
  1133. } else {
  1134. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('ReOpen').'</a>';
  1135. }
  1136. }
  1137. // Add button to create objects from project
  1138. if (!empty($conf->global->PROJECT_SHOW_CREATE_OBJECT_BUTTON)) {
  1139. if (!empty($conf->propal->enabled) && $user->rights->propal->creer) {
  1140. $langs->load("propal");
  1141. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddProp").'</a>';
  1142. }
  1143. if (!empty($conf->commande->enabled) && $user->rights->commande->creer) {
  1144. $langs->load("orders");
  1145. print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("CreateOrder").'</a>';
  1146. }
  1147. if (!empty($conf->facture->enabled) && $user->rights->facture->creer) {
  1148. $langs->load("bills");
  1149. print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
  1150. }
  1151. if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->creer) {
  1152. $langs->load("supplier_proposal");
  1153. print '<a class="butAction" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddSupplierProposal").'</a>';
  1154. }
  1155. if (!empty($conf->supplier_order->enabled) && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
  1156. $langs->load("suppliers");
  1157. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddSupplierOrder").'</a>';
  1158. }
  1159. if (!empty($conf->supplier_invoice->enabled) && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  1160. $langs->load("suppliers");
  1161. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddSupplierInvoice").'</a>';
  1162. }
  1163. if (!empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer) {
  1164. $langs->load("interventions");
  1165. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddIntervention").'</a>';
  1166. }
  1167. if (!empty($conf->contrat->enabled) && $user->rights->contrat->creer) {
  1168. $langs->load("contracts");
  1169. print '<a class="butAction" href="'.DOL_URL_ROOT.'/contrat/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddContract").'</a>';
  1170. }
  1171. if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->creer) {
  1172. $langs->load("trips");
  1173. print '<a class="butAction" href="'.DOL_URL_ROOT.'/expensereport/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddTrip").'</a>';
  1174. }
  1175. if (!empty($conf->don->enabled) && $user->rights->don->creer) {
  1176. $langs->load("donations");
  1177. print '<a class="butAction" href="'.DOL_URL_ROOT.'/don/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddDonation").'</a>';
  1178. }
  1179. }
  1180. // Clone
  1181. if ($user->rights->projet->creer) {
  1182. if ($userWrite > 0) {
  1183. print '<a class="butAction" href="card.php?id='.$object->id.'&action=clone">'.$langs->trans('ToClone').'</a>';
  1184. } else {
  1185. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('ToClone').'</a>';
  1186. }
  1187. }
  1188. // Delete
  1189. if ($user->rights->projet->supprimer || ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer)) {
  1190. if ($userDelete > 0 || ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer)) {
  1191. print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
  1192. } else {
  1193. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Delete').'</a>';
  1194. }
  1195. }
  1196. }
  1197. }
  1198. print "</div>";
  1199. if (GETPOST('modelselected')) {
  1200. $action = 'presend';
  1201. }
  1202. if ($action != 'presend') {
  1203. print '<div class="fichecenter"><div class="fichehalfleft">';
  1204. print '<a name="builddoc"></a>'; // ancre
  1205. /*
  1206. * Generated documents
  1207. */
  1208. $filename = dol_sanitizeFileName($object->ref);
  1209. $filedir = $conf->projet->dir_output."/".dol_sanitizeFileName($object->ref);
  1210. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1211. $genallowed = ($user->rights->projet->lire && $userAccess > 0);
  1212. $delallowed = ($user->rights->projet->creer && $userWrite > 0);
  1213. print $formfile->showdocuments('project', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf);
  1214. print '</div><div class="fichehalfright">';
  1215. $MAXEVENT = 10;
  1216. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', DOL_URL_ROOT.'/projet/info.php?id='.$object->id);
  1217. // List of actions on element
  1218. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1219. $formactions = new FormActions($db);
  1220. $somethingshown = $formactions->showactions($object, 'project', 0, 1, '', $MAXEVENT, '', $morehtmlcenter);
  1221. print '</div></div>';
  1222. }
  1223. // Presend form
  1224. $modelmail = 'project';
  1225. $defaulttopic = 'SendProjectRef';
  1226. $diroutput = $conf->projet->dir_output;
  1227. $autocopy = 'MAIN_MAIL_AUTOCOPY_PROJECT_TO'; // used to know the automatic BCC to add
  1228. $trackid = 'proj'.$object->id;
  1229. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  1230. // Hook to add more things on page
  1231. $parameters = array();
  1232. $reshook = $hookmanager->executeHooks('mainCardTabAddMore', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1233. } else {
  1234. print $langs->trans("RecordNotFound");
  1235. }
  1236. // End of page
  1237. llxFooter();
  1238. $db->close();