card.php 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  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->project->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="backtopageforcancel" value="'.$backtopageforcancel.'">';
  448. print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
  449. print dol_get_fiche_head();
  450. print '<table class="border centpercent tableforfieldcreate">';
  451. $defaultref = '';
  452. $modele = empty($conf->global->PROJECT_ADDON) ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
  453. // Search template files
  454. $file = ''; $classname = ''; $filefound = 0;
  455. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  456. foreach ($dirmodels as $reldir) {
  457. $file = dol_buildpath($reldir."core/modules/project/".$modele.'.php', 0);
  458. if (file_exists($file)) {
  459. $filefound = 1;
  460. $classname = $modele;
  461. break;
  462. }
  463. }
  464. if ($filefound) {
  465. $result = dol_include_once($reldir."core/modules/project/".$modele.'.php');
  466. $modProject = new $classname;
  467. $defaultref = $modProject->getNextValue($thirdparty, $object);
  468. }
  469. if (is_numeric($defaultref) && $defaultref <= 0) {
  470. $defaultref = '';
  471. }
  472. // Ref
  473. $suggestedref = (GETPOST("ref") ? GETPOST("ref") : $defaultref);
  474. 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).'">';
  475. print ' '.$form->textwithpicto('', $langs->trans("YouCanCompleteRef", $suggestedref));
  476. print '</td></tr>';
  477. // Label
  478. 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>';
  479. // Usage (opp, task, bill time, ...)
  480. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  481. print '<tr><td class="tdtop">';
  482. print $langs->trans("Usage");
  483. print '</td>';
  484. print '<td>';
  485. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  486. print '<input type="checkbox" id="usage_opportunity" name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ' checked="checked"').'"> ';
  487. $htmltext = $langs->trans("ProjectFollowOpportunity");
  488. print '<label for="usage_opportunity">'.$form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext).'</label>';
  489. print '<script>';
  490. print '$( document ).ready(function() {
  491. jQuery("#usage_opportunity").change(function() {
  492. if (jQuery("#usage_opportunity").prop("checked")) {
  493. console.log("Show opportunities fields");
  494. jQuery(".classuseopportunity").show();
  495. } else {
  496. console.log("Hide opportunities fields "+jQuery("#usage_opportunity").prop("checked"));
  497. jQuery(".classuseopportunity").hide();
  498. }
  499. });
  500. });';
  501. print '</script>';
  502. print '<br>';
  503. }
  504. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  505. print '<input type="checkbox" id="usage_task" name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ' checked="checked"').'"> ';
  506. $htmltext = $langs->trans("ProjectFollowTasks");
  507. print '<label for="usage_task">'.$form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext).'</label>';
  508. print '<br>';
  509. }
  510. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  511. print '<input type="checkbox" id="usage_bill_time" name="usage_bill_time"'.(GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '').'"> ';
  512. $htmltext = $langs->trans("ProjectBillTimeDescription");
  513. print '<label for="usage_bill_time">'.$form->textwithpicto($langs->trans("BillTime"), $htmltext).'</label>';
  514. print '<br>';
  515. }
  516. if (!empty($conf->eventorganization->enabled)) {
  517. print '<input type="checkbox" id="usage_organize_event" name="usage_organize_event"'.(GETPOST('usage_organize_event', 'alpha')!=''?' checked="checked"':'').'"> ';
  518. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  519. print '<label for="usage_organize_event">'.$form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext).'</label>';
  520. }
  521. print '</td>';
  522. print '</tr>';
  523. }
  524. // Thirdparty
  525. if (isModEnabled('societe')) {
  526. print '<tr><td>';
  527. print (empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) ? '' : '<span class="fieldrequired">');
  528. print $langs->trans("ThirdParty");
  529. print (empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) ? '' : '</span>');
  530. print '</td><td class="maxwidthonsmartphone">';
  531. $filteronlist = '';
  532. if (!empty($conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST)) {
  533. $filteronlist = $conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST;
  534. }
  535. $text = img_picto('', 'company').$form->select_company(GETPOST('socid', 'int'), 'socid', $filteronlist, 'SelectThirdParty', 1, 0, array(), 0, 'minwidth300 widthcentpercentminusxx maxwidth500');
  536. if (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) && empty($conf->dol_use_jmobile)) {
  537. $texthelp = $langs->trans("IfNeedToUseOtherObjectKeepEmpty");
  538. print $form->textwithtooltip($text.' '.img_help(), $texthelp, 1);
  539. } else {
  540. print $text;
  541. }
  542. if (!GETPOSTISSET('backtopage')) {
  543. $url = '/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create');
  544. $newbutton = '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span>';
  545. // TODO @LDR Implement this
  546. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
  547. $tmpbacktopagejsfields = 'addthirdparty:socid,search_socid';
  548. print dolButtonToOpenUrlInDialogPopup('addthirdparty', $langs->transnoentitiesnoconv('AddThirdParty'), $newbutton, $url, '', '', $tmpbacktopagejsfields);
  549. } else {
  550. print ' <a href="'.DOL_URL_ROOT.$url.'">'.$newbutton.'</a>';
  551. }
  552. }
  553. print '</td></tr>';
  554. }
  555. // Status
  556. if ($status != '') {
  557. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  558. print '<input type="hidden" name="status" value="'.$status.'">';
  559. print $object->LibStatut($status, 4);
  560. print '</td></tr>';
  561. }
  562. // Visibility
  563. print '<tr><td>'.$langs->trans("Visibility").'</td><td class="maxwidthonsmartphone">';
  564. $array = array();
  565. if (empty($conf->global->PROJECT_DISABLE_PRIVATE_PROJECT)) {
  566. $array[0] = $langs->trans("PrivateProject");
  567. }
  568. if (empty($conf->global->PROJECT_DISABLE_PUBLIC_PROJECT)) {
  569. $array[1] = $langs->trans("SharedProject");
  570. }
  571. if (count($array) > 0) {
  572. print $form->selectarray('public', $array, GETPOST('public'), 0, 0, 0, '', 0, 0, 0, '', '', 1);
  573. } else {
  574. print '<input type="hidden" name="public" id="public" value="'.GETPOST('public').'">';
  575. if (GETPOST('public') == 0) {
  576. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  577. print $langs->trans("PrivateProject");
  578. } else {
  579. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  580. print $langs->trans("SharedProject");
  581. }
  582. }
  583. print '</td></tr>';
  584. // Date start
  585. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  586. print $form->selectDate(($date_start ? $date_start : ''), 'projectstart', 0, 0, 0, '', 1, 0);
  587. print '</td></tr>';
  588. // Date end
  589. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  590. print $form->selectDate(($date_end ? $date_end : -1), 'projectend', 0, 0, 0, '', 1, 0);
  591. print '</td></tr>';
  592. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  593. // Opportunity status
  594. print '<tr class="classuseopportunity"><td>'.$langs->trans("OpportunityStatus").'</td>';
  595. print '<td class="maxwidthonsmartphone">';
  596. print $formproject->selectOpportunityStatus('opp_status', GETPOSTISSET('opp_status') ? GETPOST('opp_status') : $object->opp_status, 1, 0, 0, 0, '', 0, 1);
  597. print '</tr>';
  598. // Opportunity probability
  599. print '<tr class="classuseopportunity"><td>'.$langs->trans("OpportunityProbability").'</td>';
  600. 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>';
  601. print '<input type="hidden" name="opp_percent_not_set" id="opp_percent_not_set" value="'.dol_escape_htmltag(GETPOSTISSET('opp_percent') ? '0' : '1').'">';
  602. print '</td>';
  603. print '</tr>';
  604. // Opportunity amount
  605. print '<tr class="classuseopportunity"><td>'.$langs->trans("OpportunityAmount").'</td>';
  606. print '<td><input size="5" type="text" name="opp_amount" value="'.dol_escape_htmltag(GETPOSTISSET('opp_amount') ? GETPOST('opp_amount') : '').'"></td>';
  607. print '</tr>';
  608. }
  609. // Budget
  610. print '<tr><td>'.$langs->trans("Budget").'</td>';
  611. print '<td><input size="5" type="text" name="budget_amount" value="'.dol_escape_htmltag(GETPOSTISSET('budget_amount') ? GETPOST('budget_amount') : '').'"></td>';
  612. print '</tr>';
  613. // Description
  614. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  615. print '<td>';
  616. $doleditor = new DolEditor('description', GETPOST("description", 'restricthtml'), '', 90, 'dolibarr_notes', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
  617. $doleditor->Create();
  618. print '</td></tr>';
  619. if (!empty($conf->categorie->enabled)) {
  620. // Categories
  621. print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
  622. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PROJECT, '', 'parent', 64, 0, 1);
  623. $arrayselected = GETPOST('categories', 'array');
  624. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  625. print "</td></tr>";
  626. }
  627. // Other options
  628. $parameters = array();
  629. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  630. print $hookmanager->resPrint;
  631. if (empty($reshook)) {
  632. print $object->showOptionals($extrafields, 'create');
  633. }
  634. print '</table>';
  635. print dol_get_fiche_end();
  636. print $form->buttonsSaveCancel('CreateDraft');
  637. print '</form>';
  638. // Change probability from status
  639. print '<script type="text/javascript">
  640. jQuery(document).ready(function() {
  641. function change_percent()
  642. {
  643. var element = jQuery("#opp_status option:selected");
  644. var defaultpercent = element.attr("defaultpercent");
  645. /*if (jQuery("#opp_percent_not_set").val() == "") */
  646. jQuery("#opp_percent").val(defaultpercent);
  647. }
  648. /*init_myfunc();*/
  649. jQuery("#opp_status").change(function() {
  650. change_percent();
  651. });
  652. jQuery("#usage_task").change(function() {
  653. console.log("We click on usage task "+jQuery("#usage_task").is(":checked"));
  654. if (! jQuery("#usage_task").is(":checked")) {
  655. jQuery("#usage_bill_time").prop("checked", false);
  656. }
  657. });
  658. jQuery("#usage_bill_time").change(function() {
  659. console.log("We click on usage to bill time");
  660. if (jQuery("#usage_bill_time").is(":checked")) {
  661. jQuery("#usage_task").prop("checked", true);
  662. }
  663. });
  664. });
  665. </script>';
  666. } elseif ($object->id > 0) {
  667. /*
  668. * Show or edit
  669. */
  670. $res = $object->fetch_optionals();
  671. // To verify role of users
  672. $userAccess = $object->restrictedProjectArea($user, 'read');
  673. $userWrite = $object->restrictedProjectArea($user, 'write');
  674. $userDelete = $object->restrictedProjectArea($user, 'delete');
  675. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  676. // Confirmation validation
  677. if ($action == 'validate') {
  678. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProject'), $langs->trans('ConfirmValidateProject'), 'confirm_validate', '', 0, 1);
  679. }
  680. // Confirmation close
  681. if ($action == 'close') {
  682. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CloseAProject"), $langs->trans("ConfirmCloseAProject"), "confirm_close", '', '', 1);
  683. }
  684. // Confirmation reopen
  685. if ($action == 'reopen') {
  686. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ReOpenAProject"), $langs->trans("ConfirmReOpenAProject"), "confirm_reopen", '', '', 1);
  687. }
  688. // Confirmation delete
  689. if ($action == 'delete') {
  690. $text = $langs->trans("ConfirmDeleteAProject");
  691. $task = new Task($db);
  692. $taskarray = $task->getTasksArray(0, 0, $object->id, 0, 0);
  693. $nboftask = count($taskarray);
  694. if ($nboftask) {
  695. $text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoRemoveTasks", $nboftask);
  696. }
  697. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteAProject"), $text, "confirm_delete", '', '', 1);
  698. }
  699. // Clone confirmation
  700. if ($action == 'clone') {
  701. $formquestion = array(
  702. 'text' => $langs->trans("ConfirmClone"),
  703. 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 maxwidth250')),
  704. array('type' => 'checkbox', 'name' => 'clone_contacts', 'label' => $langs->trans("CloneContacts"), 'value' => true),
  705. array('type' => 'checkbox', 'name' => 'clone_tasks', 'label' => $langs->trans("CloneTasks"), 'value' => true),
  706. array('type' => 'checkbox', 'name' => 'move_date', 'label' => $langs->trans("CloneMoveDate"), 'value' => true),
  707. array('type' => 'checkbox', 'name' => 'clone_notes', 'label' => $langs->trans("CloneNotes"), 'value' => true),
  708. array('type' => 'checkbox', 'name' => 'clone_project_files', 'label' => $langs->trans("CloneProjectFiles"), 'value' => false),
  709. array('type' => 'checkbox', 'name' => 'clone_task_files', 'label' => $langs->trans("CloneTaskFiles"), 'value' => false)
  710. );
  711. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ToClone"), $langs->trans("ConfirmCloneProject"), "confirm_clone", $formquestion, '', 1, 400, 590);
  712. }
  713. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  714. print '<input type="hidden" name="token" value="'.newToken().'">';
  715. print '<input type="hidden" name="action" value="update">';
  716. print '<input type="hidden" name="id" value="'.$object->id.'">';
  717. print '<input type="hidden" name="comefromclone" value="'.$comefromclone.'">';
  718. $head = project_prepare_head($object);
  719. if ($action == 'edit' && $userWrite > 0) {
  720. print dol_get_fiche_head($head, 'project', $langs->trans("Project"), 0, ($object->public ? 'projectpub' : 'project'));
  721. print '<table class="border centpercent">';
  722. // Ref
  723. $suggestedref = $object->ref;
  724. print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Ref").'</td>';
  725. print '<td><input size="25" name="ref" value="'.$suggestedref.'">';
  726. print ' '.$form->textwithpicto('', $langs->trans("YouCanCompleteRef", $suggestedref));
  727. print '</td></tr>';
  728. // Label
  729. print '<tr><td class="fieldrequired">'.$langs->trans("ProjectLabel").'</td>';
  730. print '<td><input class="quatrevingtpercent" name="title" value="'.dol_escape_htmltag($object->title).'"></td></tr>';
  731. // Status
  732. print '<tr><td class="fieldrequired">'.$langs->trans("Status").'</td><td>';
  733. print '<select class="flat" name="status">';
  734. foreach ($object->statuts_short as $key => $val) {
  735. print '<option value="'.$key.'"'.((GETPOSTISSET('status') ?GETPOST('status') : $object->statut) == $key ? ' selected="selected"' : '').'>'.$langs->trans($val).'</option>';
  736. }
  737. print '</select>';
  738. print '</td></tr>';
  739. // Usage
  740. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  741. print '<tr><td class="tdtop">';
  742. print $langs->trans("Usage");
  743. print '</td>';
  744. print '<td>';
  745. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  746. print '<input type="checkbox" id="usage_opportunity" name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  747. $htmltext = $langs->trans("ProjectFollowOpportunity");
  748. print '<label for="usage_opportunity">'.$form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext).'</label>';
  749. print '<script>';
  750. print '$( document ).ready(function() {
  751. jQuery("#usage_opportunity").change(function() {
  752. if (jQuery("#usage_opportunity").prop("checked")) {
  753. console.log("Show opportunities fields");
  754. jQuery(".classuseopportunity").show();
  755. } else {
  756. console.log("Hide opportunities fields "+jQuery("#usage_opportunity").prop("checked"));
  757. jQuery(".classuseopportunity").hide();
  758. }
  759. });
  760. });';
  761. print '</script>';
  762. print '<br>';
  763. }
  764. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  765. print '<input type="checkbox" id="usage_task" name="usage_task"' . (GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')) . '"> ';
  766. $htmltext = $langs->trans("ProjectFollowTasks");
  767. print '<label for="usage_task">'.$form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext).'</label>';
  768. print '<br>';
  769. }
  770. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  771. 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"' : '')) . '"> ';
  772. $htmltext = $langs->trans("ProjectBillTimeDescription");
  773. print '<label for="usage_bill_time">'.$form->textwithpicto($langs->trans("BillTime"), $htmltext).'</label>';
  774. print '<br>';
  775. }
  776. if (!empty($conf->eventorganization->enabled)) {
  777. 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"' : '')) . '"> ';
  778. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  779. print '<label for="usage_organize_event">'.$form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext).'</label>';
  780. }
  781. print '</td></tr>';
  782. }
  783. print '</td></tr>';
  784. // Thirdparty
  785. if (isModEnabled('societe')) {
  786. print '<tr><td>';
  787. print (empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) ? '' : '<span class="fieldrequired">');
  788. print $langs->trans("ThirdParty");
  789. print (empty($conf->global->PROJECT_THIRDPARTY_REQUIRED) ? '' : '</span>');
  790. print '</td><td>';
  791. $filteronlist = '';
  792. if (!empty($conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST)) {
  793. $filteronlist = $conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST;
  794. }
  795. $text = $form->select_company($object->thirdparty->id, 'socid', $filteronlist, 'None', 1, 0, array(), 0, 'minwidth300');
  796. if (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) && empty($conf->dol_use_jmobile)) {
  797. $texthelp = $langs->trans("IfNeedToUseOtherObjectKeepEmpty");
  798. print $form->textwithtooltip($text.' '.img_help(), $texthelp, 1, 0, '', '', 2);
  799. } else {
  800. print $text;
  801. }
  802. print '</td></tr>';
  803. }
  804. // Visibility
  805. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  806. $array = array();
  807. if (empty($conf->global->PROJECT_DISABLE_PRIVATE_PROJECT)) {
  808. $array[0] = $langs->trans("PrivateProject");
  809. }
  810. if (empty($conf->global->PROJECT_DISABLE_PUBLIC_PROJECT)) {
  811. $array[1] = $langs->trans("SharedProject");
  812. }
  813. if (count($array) > 0) {
  814. print $form->selectarray('public', $array, $object->public, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  815. } else {
  816. print '<input type="hidden" id="public" name="public" value="'.$object->public.'">';
  817. if ($object->public == 0) {
  818. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  819. print $langs->trans("PrivateProject");
  820. } else {
  821. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  822. print $langs->trans("SharedProject");
  823. }
  824. }
  825. print '</td></tr>';
  826. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  827. $classfortr = ($object->usage_opportunity ? '' : ' hideobject');
  828. // Opportunity status
  829. print '<tr class="classuseopportunity'.$classfortr.'"><td>'.$langs->trans("OpportunityStatus").'</td>';
  830. print '<td>';
  831. print $formproject->selectOpportunityStatus('opp_status', $object->opp_status, 1, 0, 0, 0, 'inline-block valignmiddle', 0, 1);
  832. print '<div id="divtocloseproject" class="inline-block valign" style="display: none;"> &nbsp; &nbsp; ';
  833. print '<input type="checkbox" id="inputcloseproject" name="closeproject" />';
  834. print '<label for="inputcloseproject">'.$langs->trans("AlsoCloseAProject").'</label>';
  835. print '</div>';
  836. print '</td>';
  837. print '</tr>';
  838. // Opportunity probability
  839. print '<tr class="classuseopportunity'.$classfortr.'"><td>'.$langs->trans("OpportunityProbability").'</td>';
  840. 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) : '')).'"> %';
  841. print '<span id="oldopppercent"></span>';
  842. print '</td>';
  843. print '</tr>';
  844. // Opportunity amount
  845. print '<tr class="classuseopportunity'.$classfortr.'"><td>'.$langs->trans("OpportunityAmount").'</td>';
  846. 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) : '')).'">';
  847. print $langs->getCurrencySymbol($conf->currency);
  848. print '</td>';
  849. print '</tr>';
  850. }
  851. // Date start
  852. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  853. print $form->selectDate($object->date_start ? $object->date_start : -1, 'projectstart', 0, 0, 0, '', 1, 0);
  854. print ' &nbsp; &nbsp; <input type="checkbox" class="valignmiddle" id="reportdate" name="reportdate" value="yes" ';
  855. if ($comefromclone) {
  856. print ' checked ';
  857. }
  858. print '/><label for="reportdate" class="opacitymedium">'.$langs->trans("ProjectReportDate").'</label>';
  859. print '</td></tr>';
  860. // Date end
  861. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  862. print $form->selectDate($object->date_end ? $object->date_end : -1, 'projectend', 0, 0, 0, '', 1, 0);
  863. print '</td></tr>';
  864. // Budget
  865. print '<tr><td>'.$langs->trans("Budget").'</td>';
  866. 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) : '')).'">';
  867. print $langs->getCurrencySymbol($conf->currency);
  868. print '</td>';
  869. print '</tr>';
  870. // Description
  871. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  872. print '<td>';
  873. $doleditor = new DolEditor('description', $object->description, '', 90, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
  874. $doleditor->Create();
  875. print '</td></tr>';
  876. // Tags-Categories
  877. if (isModEnabled('categorie')) {
  878. print '<tr><td>'.$langs->trans("Categories").'</td><td>';
  879. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PROJECT, '', 'parent', 64, 0, 1);
  880. $c = new Categorie($db);
  881. $cats = $c->containing($object->id, Categorie::TYPE_PROJECT);
  882. foreach ($cats as $cat) {
  883. $arrayselected[] = $cat->id;
  884. }
  885. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, '0');
  886. print "</td></tr>";
  887. }
  888. // Other options
  889. $parameters = array();
  890. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  891. print $hookmanager->resPrint;
  892. if (empty($reshook)) {
  893. print $object->showOptionals($extrafields, 'edit');
  894. }
  895. print '</table>';
  896. } else {
  897. print dol_get_fiche_head($head, 'project', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  898. // Project card
  899. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  900. $morehtmlref = '<div class="refidno">';
  901. // Title
  902. $morehtmlref .= dol_escape_htmltag($object->title);
  903. // Thirdparty
  904. $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : ';
  905. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  906. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'project');
  907. }
  908. $morehtmlref .= '</div>';
  909. // Define a complementary filter for search of next/prev ref.
  910. if (empty($user->rights->projet->all->lire)) {
  911. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  912. $object->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  913. }
  914. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  915. print '<div class="fichecenter">';
  916. print '<div class="fichehalfleft">';
  917. print '<div class="underbanner clearboth"></div>';
  918. print '<table class="border tableforfield" width="100%">';
  919. // Usage
  920. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
  921. print '<tr><td class="tdtop">';
  922. print $langs->trans("Usage");
  923. print '</td>';
  924. print '<td>';
  925. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  926. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
  927. $htmltext = $langs->trans("ProjectFollowOpportunity");
  928. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  929. print '<br>';
  930. }
  931. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  932. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
  933. $htmltext = $langs->trans("ProjectFollowTasks");
  934. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  935. print '<br>';
  936. }
  937. if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
  938. 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"' : '')).'"> ';
  939. $htmltext = $langs->trans("ProjectBillTimeDescription");
  940. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  941. print '<br>';
  942. }
  943. if (!empty($conf->eventorganization->enabled)) {
  944. 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"' : '')).'"> ';
  945. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  946. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  947. }
  948. print '</td></tr>';
  949. }
  950. // Visibility
  951. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  952. if ($object->public) {
  953. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  954. print $langs->trans('SharedProject');
  955. } else {
  956. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  957. print $langs->trans('PrivateProject');
  958. }
  959. print '</td></tr>';
  960. if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) && !empty($object->usage_opportunity)) {
  961. // Opportunity status
  962. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  963. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  964. if ($code) {
  965. print $langs->trans("OppStatus".$code);
  966. }
  967. print '</td></tr>';
  968. // Opportunity percent
  969. print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
  970. if (strcmp($object->opp_percent, '')) {
  971. print price($object->opp_percent, 0, $langs, 1, 0).' %';
  972. }
  973. print '</td></tr>';
  974. // Opportunity Amount
  975. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  976. if (strcmp($object->opp_amount, '')) {
  977. print '<span class="amount">'.price($object->opp_amount, 0, $langs, 1, 0, -1, $conf->currency).'</span>';
  978. if (strcmp($object->opp_percent, '')) {
  979. 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>';
  980. }
  981. }
  982. print '</td></tr>';
  983. // Opportunity Weighted Amount
  984. /*
  985. print '<tr><td>'.$langs->trans('OpportunityWeightedAmount').'</td><td>';
  986. if (strcmp($object->opp_amount, '') && strcmp($object->opp_percent, '')) {
  987. print '<span class="amount">'.price($object->opp_amount * $object->opp_percent / 100, 0, $langs, 1, 0, -1, $conf->currency).'</span>';
  988. }
  989. print '</td></tr>';
  990. */
  991. }
  992. // Date start - end
  993. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  994. $start = dol_print_date($object->date_start, 'day');
  995. print ($start ? $start : '?');
  996. $end = dol_print_date($object->date_end, 'day');
  997. print ' - ';
  998. print ($end ? $end : '?');
  999. if ($object->hasDelay()) {
  1000. print img_warning("Late");
  1001. }
  1002. print '</td></tr>';
  1003. // Budget
  1004. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  1005. if (strcmp($object->budget_amount, '')) {
  1006. print '<span class="amount">'.price($object->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  1007. }
  1008. print '</td></tr>';
  1009. // Other attributes
  1010. $cols = 2;
  1011. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1012. print '</table>';
  1013. print '</div>';
  1014. print '<div class="fichehalfright">';
  1015. print '<div class="underbanner clearboth"></div>';
  1016. print '<table class="border tableforfield centpercent">';
  1017. // Description
  1018. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  1019. print dol_htmlentitiesbr($object->description);
  1020. print '</td></tr>';
  1021. // Categories
  1022. if (isModEnabled('categorie')) {
  1023. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  1024. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  1025. print "</td></tr>";
  1026. }
  1027. print '</table>';
  1028. print '</div>';
  1029. print '</div>';
  1030. print '<div class="clearboth"></div>';
  1031. }
  1032. print dol_get_fiche_end();
  1033. if ($action == 'edit' && $userWrite > 0) {
  1034. print $form->buttonsSaveCancel();
  1035. }
  1036. print '</form>';
  1037. // Change probability from status
  1038. if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
  1039. // Default value to close or not when we set opp to 'WON'.
  1040. $defaultcheckedwhenoppclose = 1;
  1041. if (empty($conf->global->PROJECT_HIDE_TASKS)) {
  1042. $defaultcheckedwhenoppclose = 0;
  1043. }
  1044. print '<!-- Javascript to manage opportunity status change -->';
  1045. print '<script type="text/javascript">
  1046. jQuery(document).ready(function() {
  1047. function change_percent()
  1048. {
  1049. var element = jQuery("#opp_status option:selected");
  1050. var defaultpercent = element.attr("defaultpercent");
  1051. var defaultcloseproject = '.((int) $defaultcheckedwhenoppclose).';
  1052. var elemcode = element.attr("elemcode");
  1053. var oldpercent = \''.dol_escape_js($object->opp_percent).'\';
  1054. console.log("We select "+elemcode);
  1055. /* Define if checkbox to close is checked or not */
  1056. var closeproject = 0;
  1057. if (elemcode == \'LOST\') closeproject = 1;
  1058. if (elemcode == \'WON\') closeproject = defaultcloseproject;
  1059. if (closeproject) jQuery("#inputcloseproject").prop("checked", true);
  1060. else jQuery("#inputcloseproject").prop("checked", false);
  1061. /* Make the close project checkbox visible or not */
  1062. console.log("closeproject="+closeproject);
  1063. if (elemcode == \'WON\' || elemcode == \'LOST\')
  1064. {
  1065. jQuery("#divtocloseproject").show();
  1066. }
  1067. else
  1068. {
  1069. jQuery("#divtocloseproject").hide();
  1070. }
  1071. /* Change percent with default percent (defaultpercent) if new status (defaultpercent) is higher than current (jQuery("#opp_percent").val()) */
  1072. console.log("oldpercent="+oldpercent);
  1073. if (oldpercent != \'\' && (parseFloat(defaultpercent) < parseFloat(oldpercent)))
  1074. {
  1075. if (jQuery("#opp_percent").val() != \'\' && oldpercent != \'\') jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+oldpercent+\' %\');
  1076. if (parseFloat(oldpercent) != 100) { jQuery("#opp_percent").val(oldpercent); }
  1077. else { jQuery("#opp_percent").val(defaultpercent); }
  1078. }
  1079. else
  1080. {
  1081. if ((parseFloat(jQuery("#opp_percent").val()) < parseFloat(defaultpercent)));
  1082. {
  1083. if (jQuery("#opp_percent").val() != \'\' && oldpercent != \'\') jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+oldpercent+\' %\');
  1084. jQuery("#opp_percent").val(defaultpercent);
  1085. }
  1086. }
  1087. }
  1088. jQuery("#opp_status").change(function() {
  1089. change_percent();
  1090. });
  1091. });
  1092. </script>';
  1093. }
  1094. /*
  1095. * Actions Buttons
  1096. */
  1097. print '<div class="tabsAction">';
  1098. $parameters = array();
  1099. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1100. // modified by hook
  1101. if (empty($reshook)) {
  1102. if ($action != "edit" && $action != 'presend') {
  1103. // Create event
  1104. /*if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a
  1105. // "workflow" action so should appears somewhere else on
  1106. // page.
  1107. {
  1108. 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>';
  1109. }*/
  1110. // Send
  1111. if (empty($user->socid)) {
  1112. if ($object->statut != Project::STATUS_CLOSED) {
  1113. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?action=presend&amp;token='.newToken().'&amp;id='.$object->id.'&amp;mode=init#formmailbeforetitle', '');
  1114. }
  1115. }
  1116. // Accounting Report
  1117. /*
  1118. $accouting_module_activated = !empty($conf->comptabilite->enabled) || !empty($conf->accounting->enabled);
  1119. if ($accouting_module_activated && $object->statut != Project::STATUS_DRAFT) {
  1120. $start = dol_getdate((int) $object->date_start);
  1121. $end = dol_getdate((int) $object->date_end);
  1122. $url = DOL_URL_ROOT.'/compta/accounting-files.php?projectid='.$object->id;
  1123. if (!empty($object->date_start)) $url .= '&amp;date_startday='.$start['mday'].'&amp;date_startmonth='.$start['mon'].'&amp;date_startyear='.$start['year'];
  1124. if (!empty($object->date_end)) $url .= '&amp;date_stopday='.$end['mday'].'&amp;date_stopmonth='.$end['mon'].'&amp;date_stopyear='.$end['year'];
  1125. print dolGetButtonAction('', $langs->trans('ExportAccountingReportButtonLabel'), 'default', $url, '');
  1126. }
  1127. */
  1128. // Modify
  1129. if ($object->statut != Project::STATUS_CLOSED && $user->rights->projet->creer) {
  1130. if ($userWrite > 0) {
  1131. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&amp;token='.newToken().'&amp;id='.$object->id, '');
  1132. } else {
  1133. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('Modify'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1134. }
  1135. }
  1136. // Validate
  1137. if ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer) {
  1138. if ($userWrite > 0) {
  1139. print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=validate&amp;token='.newToken().'&amp;id='.$object->id, '');
  1140. } else {
  1141. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1142. }
  1143. }
  1144. // Close
  1145. if ($object->statut == Project::STATUS_VALIDATED && $user->rights->projet->creer) {
  1146. if ($userWrite > 0) {
  1147. print dolGetButtonAction('', $langs->trans('Close'), 'default', $_SERVER["PHP_SELF"].'?action=close&amp;token='.newToken().'&amp;id='.$object->id, '');
  1148. } else {
  1149. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('Close'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1150. }
  1151. }
  1152. // Reopen
  1153. if ($object->statut == Project::STATUS_CLOSED && $user->rights->projet->creer) {
  1154. if ($userWrite > 0) {
  1155. print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&amp;token='.newToken().'&amp;id='.$object->id, '');
  1156. } else {
  1157. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('ReOpen'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1158. }
  1159. }
  1160. // Add button to create objects from project
  1161. if (!empty($conf->global->PROJECT_SHOW_CREATE_OBJECT_BUTTON)) {
  1162. if (!empty($conf->propal->enabled) && $user->rights->propal->creer) {
  1163. $langs->load("propal");
  1164. print dolGetButtonAction('', $langs->trans('AddProp'), 'default', DOL_URL_ROOT.'/comm/propal/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1165. }
  1166. if (!empty($conf->commande->enabled) && $user->rights->commande->creer) {
  1167. $langs->load("orders");
  1168. print dolGetButtonAction('', $langs->trans('CreateOrder'), 'default', DOL_URL_ROOT.'/commande/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1169. }
  1170. if (isModEnabled('facture') && $user->rights->facture->creer) {
  1171. $langs->load("bills");
  1172. print dolGetButtonAction('', $langs->trans('CreateBill'), 'default', DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1173. }
  1174. if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->creer) {
  1175. $langs->load("supplier_proposal");
  1176. print dolGetButtonAction('', $langs->trans('AddSupplierProposal'), 'default', DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1177. }
  1178. if (!empty($conf->supplier_order->enabled) && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
  1179. $langs->load("suppliers");
  1180. print dolGetButtonAction('', $langs->trans('AddSupplierOrder'), 'default', DOL_URL_ROOT.'/fourn/commande/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1181. }
  1182. if (!empty($conf->supplier_invoice->enabled) && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  1183. $langs->load("suppliers");
  1184. print dolGetButtonAction('', $langs->trans('AddSupplierInvoice'), 'default', DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1185. }
  1186. if (!empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer) {
  1187. $langs->load("interventions");
  1188. print dolGetButtonAction('', $langs->trans('AddIntervention'), 'default', DOL_URL_ROOT.'/fichinter/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1189. }
  1190. if (!empty($conf->contrat->enabled) && $user->rights->contrat->creer) {
  1191. $langs->load("contracts");
  1192. print dolGetButtonAction('', $langs->trans('AddContract'), 'default', DOL_URL_ROOT.'/contrat/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1193. }
  1194. if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->creer) {
  1195. $langs->load("trips");
  1196. print dolGetButtonAction('', $langs->trans('AddTrip'), 'default', DOL_URL_ROOT.'/expensereport/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1197. }
  1198. if (!empty($conf->don->enabled) && $user->rights->don->creer) {
  1199. $langs->load("donations");
  1200. print dolGetButtonAction('', $langs->trans('AddDonation'), 'default', DOL_URL_ROOT.'/don/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid, '');
  1201. }
  1202. }
  1203. // Clone
  1204. if ($user->rights->projet->creer) {
  1205. if ($userWrite > 0) {
  1206. print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&amp;token='.newToken().'&amp;id='.$object->id, '');
  1207. } else {
  1208. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1209. }
  1210. }
  1211. // Delete
  1212. if ($user->rights->projet->supprimer || ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer)) {
  1213. if ($userDelete > 0 || ($object->statut == Project::STATUS_DRAFT && $user->rights->projet->creer)) {
  1214. print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&amp;token='.newToken().'&amp;id='.$object->id, '');
  1215. } else {
  1216. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1217. }
  1218. }
  1219. }
  1220. }
  1221. print "</div>";
  1222. if (GETPOST('modelselected')) {
  1223. $action = 'presend';
  1224. }
  1225. if ($action != 'presend') {
  1226. print '<div class="fichecenter"><div class="fichehalfleft">';
  1227. print '<a name="builddoc"></a>'; // ancre
  1228. /*
  1229. * Generated documents
  1230. */
  1231. $filename = dol_sanitizeFileName($object->ref);
  1232. $filedir = $conf->project->dir_output."/".dol_sanitizeFileName($object->ref);
  1233. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1234. $genallowed = ($user->rights->projet->lire && $userAccess > 0);
  1235. $delallowed = ($user->rights->projet->creer && $userWrite > 0);
  1236. print $formfile->showdocuments('project', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf);
  1237. print '</div><div class="fichehalfright">';
  1238. $MAXEVENT = 10;
  1239. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/projet/info.php?id='.$object->id);
  1240. // List of actions on element
  1241. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1242. $formactions = new FormActions($db);
  1243. $somethingshown = $formactions->showactions($object, 'project', 0, 1, '', $MAXEVENT, '', $morehtmlcenter);
  1244. print '</div></div>';
  1245. }
  1246. // Presend form
  1247. $modelmail = 'project';
  1248. $defaulttopic = 'SendProjectRef';
  1249. $diroutput = $conf->project->dir_output;
  1250. $autocopy = 'MAIN_MAIL_AUTOCOPY_PROJECT_TO'; // used to know the automatic BCC to add
  1251. $trackid = 'proj'.$object->id;
  1252. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  1253. // Hook to add more things on page
  1254. $parameters = array();
  1255. $reshook = $hookmanager->executeHooks('mainCardTabAddMore', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1256. } else {
  1257. print $langs->trans("RecordNotFound");
  1258. }
  1259. // End of page
  1260. llxFooter();
  1261. $db->close();