card.php 60 KB

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