card.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  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 Implement 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) : '')).'">';
  840. print $langs->getCurrencySymbol($conf->currency);
  841. print '</td>';
  842. print '</tr>';
  843. }
  844. // Date start
  845. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  846. print $form->selectDate($object->date_start ? $object->date_start : -1, 'projectstart', 0, 0, 0, '', 1, 0);
  847. print ' &nbsp; &nbsp; <input type="checkbox" class="valignmiddle" id="reportdate" name="reportdate" value="yes" ';
  848. if ($comefromclone) {
  849. print ' checked ';
  850. }
  851. print '/><label for="reportdate" class="opacitymedium">'.$langs->trans("ProjectReportDate").'</label>';
  852. print '</td></tr>';
  853. // Date end
  854. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  855. print $form->selectDate($object->date_end ? $object->date_end : -1, 'projectend', 0, 0, 0, '', 1, 0);
  856. print '</td></tr>';
  857. // Budget
  858. print '<tr><td>'.$langs->trans("Budget").'</td>';
  859. 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) : '')).'">';
  860. print $langs->getCurrencySymbol($conf->currency);
  861. print '</td>';
  862. print '</tr>';
  863. // Description
  864. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  865. print '<td>';
  866. $doleditor = new DolEditor('description', $object->description, '', 90, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_3, '90%');
  867. $doleditor->Create();
  868. print '</td></tr>';
  869. // Tags-Categories
  870. if ($conf->categorie->enabled) {
  871. print '<tr><td>'.$langs->trans("Categories").'</td><td>';
  872. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PROJECT, '', 'parent', 64, 0, 1);
  873. $c = new Categorie($db);
  874. $cats = $c->containing($object->id, Categorie::TYPE_PROJECT);
  875. foreach ($cats as $cat) {
  876. $arrayselected[] = $cat->id;
  877. }
  878. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, '0');
  879. print "</td></tr>";
  880. }
  881. // Other options
  882. $parameters = array();
  883. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  884. print $hookmanager->resPrint;
  885. if (empty($reshook)) {
  886. print $object->showOptionals($extrafields, 'edit');
  887. }
  888. print '</table>';
  889. } else {
  890. print dol_get_fiche_head($head, 'project', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  891. // Project card
  892. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  893. $morehtmlref = '<div class="refidno">';
  894. // Title
  895. $morehtmlref .= dol_escape_htmltag($object->title);
  896. // Thirdparty
  897. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : ';
  898. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  899. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'project');
  900. }
  901. $morehtmlref .= '</div>';
  902. // Define a complementary filter for search of next/prev ref.
  903. if (empty($user->rights->projet->all->lire)) {
  904. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  905. $object->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  906. }
  907. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  908. print '<div class="fichecenter">';
  909. print '<div class="fichehalfleft">';
  910. print '<div class="underbanner clearboth"></div>';
  911. print '<table class="border tableforfield" width="100%">';
  912. // Usage
  913. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  914. print '<tr><td class="tdtop">';
  915. print $langs->trans("Usage");
  916. print '</td>';
  917. print '<td>';
  918. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  919. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  920. $htmltext = $langs->trans("ProjectFollowOpportunity");
  921. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  922. print '<br>';
  923. }
  924. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  925. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
  926. $htmltext = $langs->trans("ProjectFollowTasks");
  927. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  928. print '<br>';
  929. }
  930. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  931. 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"' : '')).'"> ';
  932. $htmltext = $langs->trans("ProjectBillTimeDescription");
  933. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  934. print '<br>';
  935. }
  936. if (!empty($conf->eventorganization->enabled)) {
  937. 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"' : '')).'"> ';
  938. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  939. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  940. }
  941. print '</td></tr>';
  942. }
  943. // Visibility
  944. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  945. if ($object->public) {
  946. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  947. print $langs->trans('SharedProject');
  948. } else {
  949. print img_picto($langs->trans('SharedProject'), 'private', 'class="paddingrightonly"');
  950. print $langs->trans('PrivateProject');
  951. }
  952. print '</td></tr>';
  953. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) && !empty($object->usage_opportunity)) {
  954. // Opportunity status
  955. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  956. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  957. if ($code) {
  958. print $langs->trans("OppStatus".$code);
  959. }
  960. print '</td></tr>';
  961. // Opportunity percent
  962. print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
  963. if (strcmp($object->opp_percent, '')) {
  964. print price($object->opp_percent, 0, $langs, 1, 0).' %';
  965. }
  966. print '</td></tr>';
  967. // Opportunity Amount
  968. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  969. if (strcmp($object->opp_amount, '')) {
  970. print '<span class="amount">'.price($object->opp_amount, 0, $langs, 1, 0, -1, $conf->currency).'</span>';
  971. if (strcmp($object->opp_percent, '')) {
  972. 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>';
  973. }
  974. }
  975. print '</td></tr>';
  976. // Opportunity Weighted Amount
  977. /*
  978. print '<tr><td>'.$langs->trans('OpportunityWeightedAmount').'</td><td>';
  979. if (strcmp($object->opp_amount, '') && strcmp($object->opp_percent, '')) {
  980. print '<span class="amount">'.price($object->opp_amount * $object->opp_percent / 100, 0, $langs, 1, 0, -1, $conf->currency).'</span>';
  981. }
  982. print '</td></tr>';
  983. */
  984. }
  985. // Date start - end
  986. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  987. $start = dol_print_date($object->date_start, 'day');
  988. print ($start ? $start : '?');
  989. $end = dol_print_date($object->date_end, 'day');
  990. print ' - ';
  991. print ($end ? $end : '?');
  992. if ($object->hasDelay()) {
  993. print img_warning("Late");
  994. }
  995. print '</td></tr>';
  996. // Budget
  997. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  998. if (strcmp($object->budget_amount, '')) {
  999. print '<span class="amount">'.price($object->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  1000. }
  1001. print '</td></tr>';
  1002. // Other attributes
  1003. $cols = 2;
  1004. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1005. print '</table>';
  1006. print '</div>';
  1007. print '<div class="fichehalfright">';
  1008. print '<div class="underbanner clearboth"></div>';
  1009. print '<table class="border tableforfield centpercent">';
  1010. // Description
  1011. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  1012. print dol_htmlentitiesbr($object->description);
  1013. print '</td></tr>';
  1014. // Categories
  1015. if ($conf->categorie->enabled) {
  1016. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  1017. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  1018. print "</td></tr>";
  1019. }
  1020. print '</table>';
  1021. print '</div>';
  1022. print '</div>';
  1023. print '<div class="clearboth"></div>';
  1024. }
  1025. print dol_get_fiche_end();
  1026. if ($action == 'edit' && $userWrite > 0) {
  1027. print $form->buttonsSaveCancel();
  1028. }
  1029. print '</form>';
  1030. // Change probability from status
  1031. if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  1032. // Default value to close or not when we set opp to 'WON'.
  1033. $defaultcheckedwhenoppclose = 1;
  1034. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  1035. $defaultcheckedwhenoppclose = 0;
  1036. }
  1037. print '<!-- Javascript to manage opportunity status change -->';
  1038. print '<script type="text/javascript">
  1039. jQuery(document).ready(function() {
  1040. function change_percent()
  1041. {
  1042. var element = jQuery("#opp_status option:selected");
  1043. var defaultpercent = element.attr("defaultpercent");
  1044. var defaultcloseproject = '.$defaultcheckedwhenoppclose.';
  1045. var elemcode = element.attr("elemcode");
  1046. var oldpercent = \''.dol_escape_js($object->opp_percent).'\';
  1047. console.log("We select "+elemcode);
  1048. /* Define if checkbox to close is checked or not */
  1049. var closeproject = 0;
  1050. if (elemcode == \'LOST\') closeproject = 1;
  1051. if (elemcode == \'WON\') closeproject = defaultcloseproject;
  1052. if (closeproject) jQuery("#inputcloseproject").prop("checked", true);
  1053. else jQuery("#inputcloseproject").prop("checked", false);
  1054. /* Make the close project checkbox visible or not */
  1055. console.log("closeproject="+closeproject);
  1056. if (elemcode == \'WON\' || elemcode == \'LOST\')
  1057. {
  1058. jQuery("#divtocloseproject").show();
  1059. }
  1060. else
  1061. {
  1062. jQuery("#divtocloseproject").hide();
  1063. }
  1064. /* Change percent with default percent (defaultpercent) if new status (defaultpercent) is higher than current (jQuery("#opp_percent").val()) */
  1065. console.log("oldpercent="+oldpercent);
  1066. if (oldpercent != \'\' && (parseFloat(defaultpercent) < parseFloat(oldpercent)))
  1067. {
  1068. if (jQuery("#opp_percent").val() != \'\' && oldpercent != \'\') jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+oldpercent+\' %\');
  1069. if (parseFloat(oldpercent) != 100) { jQuery("#opp_percent").val(oldpercent); }
  1070. else { jQuery("#opp_percent").val(defaultpercent); }
  1071. }
  1072. else
  1073. {
  1074. if ((parseFloat(jQuery("#opp_percent").val()) < parseFloat(defaultpercent)));
  1075. {
  1076. if (jQuery("#opp_percent").val() != \'\' && oldpercent != \'\') jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+oldpercent+\' %\');
  1077. jQuery("#opp_percent").val(defaultpercent);
  1078. }
  1079. }
  1080. }
  1081. jQuery("#opp_status").change(function() {
  1082. change_percent();
  1083. });
  1084. });
  1085. </script>';
  1086. }
  1087. /*
  1088. * Actions Buttons
  1089. */
  1090. print '<div class="tabsAction">';
  1091. $parameters = array();
  1092. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1093. // modified by hook
  1094. if (empty($reshook)) {
  1095. if ($action != "edit" && $action != 'presend') {
  1096. // Create event
  1097. /*if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a
  1098. // "workflow" action so should appears somewhere else on
  1099. // page.
  1100. {
  1101. 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>';
  1102. }*/
  1103. // Send
  1104. if (empty($user->socid)) {
  1105. if ($object->statut != Project::STATUS_CLOSED) {
  1106. print '<a class="butAction" href="card.php?id='.$object->id.'&amp;action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>';
  1107. }
  1108. }
  1109. // Modify
  1110. if ($object->statut != Project::STATUS_CLOSED && $user->rights->projet->creer) {
  1111. if ($userWrite > 0) {
  1112. print '<a class="butAction" href="card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  1113. } else {
  1114. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Modify').'</a>';
  1115. }
  1116. }
  1117. // Validate
  1118. if ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer) {
  1119. if ($userWrite > 0) {
  1120. print '<a class="butAction" href="card.php?id='.$object->id.'&action=validate&token='.newToken().'">'.$langs->trans("Validate").'</a>';
  1121. } else {
  1122. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Validate').'</a>';
  1123. }
  1124. }
  1125. // Close
  1126. if ($object->statut == Project::STATUS_VALIDATED && $user->rights->projet->creer) {
  1127. if ($userWrite > 0) {
  1128. print '<a class="butAction" href="card.php?id='.$object->id.'&amp;action=close">'.$langs->trans("Close").'</a>';
  1129. } else {
  1130. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Close').'</a>';
  1131. }
  1132. }
  1133. // Reopen
  1134. if ($object->statut == Project::STATUS_CLOSED && $user->rights->projet->creer) {
  1135. if ($userWrite > 0) {
  1136. print '<a class="butAction" href="card.php?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>';
  1137. } else {
  1138. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('ReOpen').'</a>';
  1139. }
  1140. }
  1141. // Add button to create objects from project
  1142. if (!empty($conf->global->PROJECT_SHOW_CREATE_OBJECT_BUTTON)) {
  1143. if (!empty($conf->propal->enabled) && $user->rights->propal->creer) {
  1144. $langs->load("propal");
  1145. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddProp").'</a>';
  1146. }
  1147. if (!empty($conf->commande->enabled) && $user->rights->commande->creer) {
  1148. $langs->load("orders");
  1149. print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("CreateOrder").'</a>';
  1150. }
  1151. if (!empty($conf->facture->enabled) && $user->rights->facture->creer) {
  1152. $langs->load("bills");
  1153. print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
  1154. }
  1155. if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->creer) {
  1156. $langs->load("supplier_proposal");
  1157. print '<a class="butAction" href="'.DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddSupplierProposal").'</a>';
  1158. }
  1159. if (!empty($conf->supplier_order->enabled) && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
  1160. $langs->load("suppliers");
  1161. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddSupplierOrder").'</a>';
  1162. }
  1163. if (!empty($conf->supplier_invoice->enabled) && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  1164. $langs->load("suppliers");
  1165. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddSupplierInvoice").'</a>';
  1166. }
  1167. if (!empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer) {
  1168. $langs->load("interventions");
  1169. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddIntervention").'</a>';
  1170. }
  1171. if (!empty($conf->contrat->enabled) && $user->rights->contrat->creer) {
  1172. $langs->load("contracts");
  1173. print '<a class="butAction" href="'.DOL_URL_ROOT.'/contrat/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddContract").'</a>';
  1174. }
  1175. if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->creer) {
  1176. $langs->load("trips");
  1177. print '<a class="butAction" href="'.DOL_URL_ROOT.'/expensereport/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddTrip").'</a>';
  1178. }
  1179. if (!empty($conf->don->enabled) && $user->rights->don->creer) {
  1180. $langs->load("donations");
  1181. print '<a class="butAction" href="'.DOL_URL_ROOT.'/don/card.php?action=create&projectid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddDonation").'</a>';
  1182. }
  1183. }
  1184. // Clone
  1185. if ($user->rights->projet->creer) {
  1186. if ($userWrite > 0) {
  1187. print '<a class="butAction" href="card.php?id='.$object->id.'&action=clone">'.$langs->trans('ToClone').'</a>';
  1188. } else {
  1189. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('ToClone').'</a>';
  1190. }
  1191. }
  1192. // Delete
  1193. if ($user->rights->projet->supprimer || ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer)) {
  1194. if ($userDelete > 0 || ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer)) {
  1195. print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
  1196. } else {
  1197. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Delete').'</a>';
  1198. }
  1199. }
  1200. }
  1201. }
  1202. print "</div>";
  1203. if (GETPOST('modelselected')) {
  1204. $action = 'presend';
  1205. }
  1206. if ($action != 'presend') {
  1207. print '<div class="fichecenter"><div class="fichehalfleft">';
  1208. print '<a name="builddoc"></a>'; // ancre
  1209. /*
  1210. * Generated documents
  1211. */
  1212. $filename = dol_sanitizeFileName($object->ref);
  1213. $filedir = $conf->projet->dir_output."/".dol_sanitizeFileName($object->ref);
  1214. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1215. $genallowed = ($user->rights->projet->lire && $userAccess > 0);
  1216. $delallowed = ($user->rights->projet->creer && $userWrite > 0);
  1217. print $formfile->showdocuments('project', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf);
  1218. print '</div><div class="fichehalfright">';
  1219. $MAXEVENT = 10;
  1220. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/projet/info.php?id='.$object->id);
  1221. // List of actions on element
  1222. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1223. $formactions = new FormActions($db);
  1224. $somethingshown = $formactions->showactions($object, 'project', 0, 1, '', $MAXEVENT, '', $morehtmlcenter);
  1225. print '</div></div>';
  1226. }
  1227. // Presend form
  1228. $modelmail = 'project';
  1229. $defaulttopic = 'SendProjectRef';
  1230. $diroutput = $conf->projet->dir_output;
  1231. $autocopy = 'MAIN_MAIL_AUTOCOPY_PROJECT_TO'; // used to know the automatic BCC to add
  1232. $trackid = 'proj'.$object->id;
  1233. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  1234. // Hook to add more things on page
  1235. $parameters = array();
  1236. $reshook = $hookmanager->executeHooks('mainCardTabAddMore', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1237. } else {
  1238. print $langs->trans("RecordNotFound");
  1239. }
  1240. // End of page
  1241. llxFooter();
  1242. $db->close();