card.php 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  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. * Copyright (C) 2023 Charlene Benke <charlene@patas_monkey.com>
  6. * Copyright (C) 2023 Christian Foellmann <christian@foellmann.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/projet/card.php
  23. * \ingroup projet
  24. * \brief Project card
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  37. // Load translation files required by the page
  38. $langsLoad=array('projects', 'companies');
  39. if (isModEnabled('eventorganization')) {
  40. $langsLoad[]='eventorganization';
  41. }
  42. $langs->loadLangs($langsLoad);
  43. $id = GETPOST('id', 'int');
  44. $ref = GETPOST('ref', 'alpha');
  45. $action = GETPOST('action', 'aZ09');
  46. $backtopage = GETPOST('backtopage', 'alpha');
  47. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  48. $backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
  49. $cancel = GETPOST('cancel', 'alpha');
  50. $confirm = GETPOST('confirm', 'aZ09');
  51. $dol_openinpopup = 0;
  52. if (!empty($backtopagejsfields)) {
  53. $tmpbacktopagejsfields = explode(':', $backtopagejsfields);
  54. $dol_openinpopup = $tmpbacktopagejsfields[0];
  55. }
  56. $status = GETPOST('status', 'int');
  57. $opp_status = GETPOST('opp_status', 'int');
  58. $opp_percent = price2num(GETPOST('opp_percent', 'alphanohtml'));
  59. $objcanvas = GETPOST("objcanvas", "alphanohtml");
  60. $comefromclone = GETPOST("comefromclone", "alphanohtml");
  61. $date_start = dol_mktime(0, 0, 0, GETPOST('projectstartmonth', 'int'), GETPOST('projectstartday', 'int'), GETPOST('projectstartyear', 'int'));
  62. $date_end = dol_mktime(0, 0, 0, GETPOST('projectendmonth', 'int'), GETPOST('projectendday', 'int'), GETPOST('projectendyear', 'int'));
  63. $date_start_event = dol_mktime(GETPOSTINT('date_start_eventhour'), GETPOSTINT('date_start_eventmin'), GETPOSTINT('date_start_eventsec'), GETPOSTINT('date_start_eventmonth'), GETPOSTINT('date_start_eventday'), GETPOSTINT('date_start_eventyear'), 'tzuserrel');
  64. $date_end_event = dol_mktime(GETPOSTINT('date_end_eventhour'), GETPOSTINT('date_end_eventmin'), GETPOSTINT('date_end_eventsec'), GETPOSTINT('date_end_eventmonth'), GETPOSTINT('date_end_eventday'), GETPOSTINT('date_end_eventyear'), 'tzuserrel');
  65. $location = GETPOST('location', 'alphanohtml');
  66. $fk_project = GETPOSTINT('fk_project');
  67. $mine = GETPOST('mode') == 'mine' ? 1 : 0;
  68. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  69. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  70. $hookmanager->initHooks(array('projectcard', 'globalcard'));
  71. $object = new Project($db);
  72. $extrafields = new ExtraFields($db);
  73. // Load object
  74. //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.
  75. if ($id > 0 || !empty($ref)) {
  76. $ret = $object->fetch($id, $ref); // If we create project, ref may be defined into POST but record does not yet exists into database
  77. if ($ret > 0) {
  78. $object->fetch_thirdparty();
  79. if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($object, 'fetchComments') && empty($object->comments)) {
  80. $object->fetchComments();
  81. }
  82. $id = $object->id;
  83. }
  84. }
  85. // fetch optionals attributes and labels
  86. $extrafields->fetch_name_optionals_label($object->table_element);
  87. // Security check
  88. $socid = GETPOST('socid', 'int');
  89. //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.
  90. restrictedArea($user, 'projet', $object->id, 'projet&project');
  91. if ($id == '' && $ref == '' && ($action != "create" && $action != "add" && $action != "update" && !GETPOST("cancel"))) {
  92. accessforbidden();
  93. }
  94. $permissiontoadd = $user->hasRight('projet', 'creer');
  95. $permissiontodelete = $user->hasRight('projet', 'supprimer');
  96. $permissiondellink = $user->hasRight('projet', 'creer'); // Used by the include of actions_dellink.inc.php
  97. /*
  98. * Actions
  99. */
  100. $parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
  101. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  102. if ($reshook < 0) {
  103. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  104. }
  105. if (empty($reshook)) {
  106. $backurlforlist = DOL_URL_ROOT.'/projet/list.php';
  107. // Cancel
  108. if ($cancel) {
  109. if (GETPOST("comefromclone") == 1) {
  110. $result = $object->delete($user);
  111. if ($result > 0) {
  112. header("Location: index.php");
  113. exit;
  114. } else {
  115. dol_syslog($object->error, LOG_DEBUG);
  116. setEventMessages($langs->trans("CantRemoveProject", $langs->transnoentitiesnoconv("ProjectOverview")), null, 'errors');
  117. }
  118. }
  119. }
  120. if (empty($backtopage) || ($cancel && empty($id))) {
  121. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  122. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  123. $backtopage = $backurlforlist;
  124. } else {
  125. $backtopage = DOL_URL_ROOT.'/projet/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  126. }
  127. }
  128. }
  129. if ($cancel) {
  130. if (!empty($backtopageforcancel)) {
  131. header("Location: ".$backtopageforcancel);
  132. exit;
  133. } elseif (!empty($backtopage)) {
  134. header("Location: ".$backtopage);
  135. exit;
  136. }
  137. $action = '';
  138. }
  139. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  140. // Action setdraft object
  141. if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) {
  142. $result = $object->setStatut($object::STATUS_DRAFT, null, '', 'PROJECT_MODIFY');
  143. if ($result >= 0) {
  144. // Nothing else done
  145. } else {
  146. $error++;
  147. setEventMessages($object->error, $object->errors, 'errors');
  148. }
  149. $action = '';
  150. }
  151. // Action add
  152. if ($action == 'add' && $permissiontoadd) {
  153. $error = 0;
  154. if (!GETPOST('ref')) {
  155. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
  156. $error++;
  157. }
  158. if (!GETPOST('title')) {
  159. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ProjectLabel")), null, 'errors');
  160. $error++;
  161. }
  162. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  163. if (GETPOST('usage_opportunity') != '' && !(GETPOST('opp_status') > 0)) {
  164. $error++;
  165. setEventMessages($langs->trans("ErrorOppStatusRequiredIfUsage"), null, 'errors');
  166. }
  167. if (GETPOST('opp_amount') != '' && !(GETPOST('opp_status') > 0)) {
  168. $error++;
  169. setEventMessages($langs->trans("ErrorOppStatusRequiredIfAmount"), null, 'errors');
  170. }
  171. }
  172. // Create with status validated immediatly
  173. if (getDolGlobalString('PROJECT_CREATE_NO_DRAFT') && !$error) {
  174. $status = Project::STATUS_VALIDATED;
  175. }
  176. if (!$error) {
  177. $error = 0;
  178. $db->begin();
  179. $object->ref = GETPOST('ref', 'alphanohtml');
  180. $object->fk_project = GETPOST('fk_project', 'int');
  181. $object->title = GETPOST('title', 'alphanohtml');
  182. $object->socid = GETPOST('socid', 'int');
  183. $object->description = GETPOST('description', 'restricthtml'); // Do not use 'alpha' here, we want field as it is
  184. $object->public = GETPOST('public', 'alphanohtml');
  185. $object->opp_amount = price2num(GETPOST('opp_amount', 'alphanohtml'));
  186. $object->budget_amount = price2num(GETPOST('budget_amount', 'alphanohtml'));
  187. $object->date_c = dol_now();
  188. $object->date_start = $date_start;
  189. $object->date_end = $date_end;
  190. $object->date_start_event = $date_start_event;
  191. $object->date_end_event = $date_end_event;
  192. $object->location = $location;
  193. $object->statut = $status;
  194. $object->opp_status = $opp_status;
  195. $object->opp_percent = $opp_percent;
  196. $object->usage_opportunity = (GETPOST('usage_opportunity', 'alpha') == 'on' ? 1 : 0);
  197. $object->usage_task = (GETPOST('usage_task', 'alpha') == 'on' ? 1 : 0);
  198. $object->usage_bill_time = (GETPOST('usage_bill_time', 'alpha') == 'on' ? 1 : 0);
  199. $object->usage_organize_event = (GETPOST('usage_organize_event', 'alpha') == 'on' ? 1 : 0);
  200. // Fill array 'array_options' with data from add form
  201. $ret = $extrafields->setOptionalsFromPost(null, $object);
  202. if ($ret < 0) {
  203. $error++;
  204. }
  205. $result = $object->create($user);
  206. if (!$error && $result > 0) {
  207. // Add myself as project leader
  208. $typeofcontact = 'PROJECTLEADER';
  209. $result = $object->add_contact($user->id, $typeofcontact, 'internal');
  210. // -3 means type not found (PROJECTLEADER renamed, de-activated or deleted), so don't prevent creation if it has been the case
  211. if ($result == -3) {
  212. setEventMessage('ErrorPROJECTLEADERRoleMissingRestoreIt', 'errors');
  213. $error++;
  214. } elseif ($result < 0) {
  215. $langs->load("errors");
  216. setEventMessages($object->error, $object->errors, 'errors');
  217. $error++;
  218. }
  219. } else {
  220. $langs->load("errors");
  221. setEventMessages($object->error, $object->errors, 'errors');
  222. $error++;
  223. }
  224. if (!$error && !empty($object->id) > 0) {
  225. // Category association
  226. $categories = GETPOST('categories', 'array');
  227. $result = $object->setCategories($categories);
  228. if ($result < 0) {
  229. $langs->load("errors");
  230. setEventMessages($object->error, $object->errors, 'errors');
  231. $error++;
  232. }
  233. }
  234. if (!$error) {
  235. $db->commit();
  236. if (!empty($backtopage)) {
  237. $backtopage = preg_replace('/--IDFORBACKTOPAGE--|__ID__/', $object->id, $backtopage); // New method to autoselect project after a New on another form object creation
  238. $backtopage = $backtopage.'&projectid='.$object->id; // Old method
  239. header("Location: ".$backtopage);
  240. exit;
  241. } else {
  242. header("Location:card.php?id=".$object->id);
  243. exit;
  244. }
  245. } else {
  246. $db->rollback();
  247. unset($_POST["ref"]);
  248. $action = 'create';
  249. }
  250. } else {
  251. $action = 'create';
  252. }
  253. }
  254. if ($action == 'update' && empty(GETPOST('cancel')) && $permissiontoadd) {
  255. $error = 0;
  256. if (empty($ref)) {
  257. $error++;
  258. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
  259. }
  260. if (!GETPOST("title")) {
  261. $error++;
  262. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ProjectLabel")), null, 'errors');
  263. }
  264. $db->begin();
  265. if (!$error) {
  266. $object->oldcopy = clone $object;
  267. $old_start_date = $object->date_start;
  268. $object->ref = GETPOST('ref', 'alpha');
  269. $object->fk_project = GETPOST('fk_project', 'int');
  270. $object->title = GETPOST('title', 'alphanohtml'); // Do not use 'alpha' here, we want field as it is
  271. $object->statut = GETPOST('status', 'int');
  272. $object->socid = GETPOST('socid', 'int');
  273. $object->description = GETPOST('description', 'restricthtml'); // Do not use 'alpha' here, we want field as it is
  274. $object->public = GETPOST('public', 'alpha');
  275. $object->date_start = (!GETPOST('projectstart')) ? '' : $date_start;
  276. $object->date_end = (!GETPOST('projectend')) ? '' : $date_end;
  277. $object->date_start_event = (!GETPOST('date_start_event')) ? '' : $date_start_event;
  278. $object->date_end_event = (!GETPOST('date_end_event')) ? '' : $date_end_event;
  279. $object->location = $location;
  280. if (GETPOSTISSET('opp_amount')) {
  281. $object->opp_amount = price2num(GETPOST('opp_amount', 'alpha'));
  282. }
  283. if (GETPOSTISSET('budget_amount')) {
  284. $object->budget_amount = price2num(GETPOST('budget_amount', 'alpha'));
  285. }
  286. if (GETPOSTISSET('opp_status')) {
  287. $object->opp_status = $opp_status;
  288. }
  289. if (GETPOSTISSET('opp_percent')) {
  290. $object->opp_percent = $opp_percent;
  291. }
  292. $object->usage_opportunity = (GETPOST('usage_opportunity', 'alpha') == 'on' ? 1 : 0);
  293. $object->usage_task = (GETPOST('usage_task', 'alpha') == 'on' ? 1 : 0);
  294. $object->usage_bill_time = (GETPOST('usage_bill_time', 'alpha') == 'on' ? 1 : 0);
  295. $object->usage_organize_event = (GETPOST('usage_organize_event', 'alpha') == 'on' ? 1 : 0);
  296. // Fill array 'array_options' with data from add form
  297. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  298. if ($ret < 0) {
  299. $error++;
  300. }
  301. }
  302. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  303. if ($object->opp_amount && ($object->opp_status <= 0)) {
  304. $error++;
  305. setEventMessages($langs->trans("ErrorOppStatusRequiredIfAmount"), null, 'errors');
  306. }
  307. }
  308. if (!$error) {
  309. $result = $object->update($user);
  310. if ($result < 0) {
  311. $error++;
  312. if ($result == -4) {
  313. setEventMessages($langs->trans("ErrorRefAlreadyExists"), null, 'errors');
  314. } else {
  315. setEventMessages($object->error, $object->errors, 'errors');
  316. }
  317. } else {
  318. // Category association
  319. $categories = GETPOST('categories', 'array');
  320. $result = $object->setCategories($categories);
  321. if ($result < 0) {
  322. $error++;
  323. setEventMessages($object->error, $object->errors, 'errors');
  324. }
  325. }
  326. }
  327. if (!$error) {
  328. if (GETPOST("reportdate") && ($object->date_start != $old_start_date)) {
  329. $result = $object->shiftTaskDate($old_start_date);
  330. if ($result < 0) {
  331. $error++;
  332. setEventMessages($langs->trans("ErrorShiftTaskDate").':'.$object->error, $object->errors, 'errors');
  333. }
  334. }
  335. }
  336. // Check if we must change status
  337. if (GETPOST('closeproject')) {
  338. $resclose = $object->setClose($user);
  339. if ($resclose < 0) {
  340. $error++;
  341. setEventMessages($langs->trans("FailedToCloseProject").':'.$object->error, $object->errors, 'errors');
  342. }
  343. }
  344. if ($error) {
  345. $db->rollback();
  346. $action = 'edit';
  347. } else {
  348. $db->commit();
  349. if (GETPOST('socid', 'int') > 0) {
  350. $object->fetch_thirdparty(GETPOST('socid', 'int'));
  351. } else {
  352. unset($object->thirdparty);
  353. }
  354. }
  355. }
  356. // Build doc
  357. if ($action == 'builddoc' && $permissiontoadd) {
  358. // Save last template used to generate document
  359. if (GETPOST('model')) {
  360. $object->setDocModel($user, GETPOST('model', 'alpha'));
  361. }
  362. $outputlangs = $langs;
  363. if (GETPOST('lang_id', 'aZ09')) {
  364. $outputlangs = new Translate("", $conf);
  365. $outputlangs->setDefaultLang(GETPOST('lang_id', 'aZ09'));
  366. }
  367. $result = $object->generateDocument($object->model_pdf, $outputlangs);
  368. if ($result <= 0) {
  369. setEventMessages($object->error, $object->errors, 'errors');
  370. $action = '';
  371. }
  372. }
  373. // Delete file in doc form
  374. if ($action == 'remove_file' && $permissiontoadd) {
  375. if ($object->id > 0) {
  376. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  377. $langs->load("other");
  378. $upload_dir = $conf->project->multidir_output[$object->entity];
  379. $file = $upload_dir.'/'.GETPOST('file');
  380. $ret = dol_delete_file($file, 0, 0, 0, $object);
  381. if ($ret) {
  382. setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
  383. } else {
  384. setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
  385. }
  386. $action = '';
  387. }
  388. }
  389. if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
  390. $result = $object->setValid($user);
  391. if ($result <= 0) {
  392. setEventMessages($object->error, $object->errors, 'errors');
  393. }
  394. }
  395. if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) {
  396. $result = $object->setClose($user);
  397. if ($result <= 0) {
  398. setEventMessages($object->error, $object->errors, 'errors');
  399. }
  400. }
  401. if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) {
  402. $result = $object->setValid($user);
  403. if ($result <= 0) {
  404. setEventMessages($object->error, $object->errors, 'errors');
  405. }
  406. }
  407. if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
  408. $object->fetch($id);
  409. $result = $object->delete($user);
  410. if ($result > 0) {
  411. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  412. if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['project'])) {
  413. $tmpurl = $_SESSION['pageforbacktolist']['project'];
  414. $tmpurl = preg_replace('/__SOCID__/', $object->socid, $tmpurl);
  415. $urlback = $tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?'). 'restore_lastsearch_values=1';
  416. } else {
  417. $urlback = DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1';
  418. }
  419. header("Location: ".$urlback);
  420. exit;
  421. } else {
  422. dol_syslog($object->error, LOG_DEBUG);
  423. setEventMessages($object->error, $object->errors, 'errors');
  424. }
  425. }
  426. if ($action == 'confirm_clone' && $permissiontoadd && $confirm == 'yes') {
  427. $clone_contacts = GETPOST('clone_contacts') ? 1 : 0;
  428. $clone_tasks = GETPOST('clone_tasks') ? 1 : 0;
  429. $clone_project_files = GETPOST('clone_project_files') ? 1 : 0;
  430. $clone_task_files = GETPOST('clone_task_files') ? 1 : 0;
  431. $clone_notes = GETPOST('clone_notes') ? 1 : 0;
  432. $move_date = GETPOST('move_date') ? 1 : 0;
  433. $clone_thirdparty = GETPOST('socid', 'int') ? GETPOST('socid', 'int') : 0;
  434. $result = $object->createFromClone($user, $object->id, $clone_contacts, $clone_tasks, $clone_project_files, $clone_task_files, $clone_notes, $move_date, 0, $clone_thirdparty);
  435. if ($result <= 0) {
  436. setEventMessages($object->error, $object->errors, 'errors');
  437. } else {
  438. // Load new object
  439. $newobject = new Project($db);
  440. $newobject->fetch($result);
  441. $newobject->fetch_optionals();
  442. $newobject->fetch_thirdparty(); // Load new object
  443. $object = $newobject;
  444. $action = 'view';
  445. $comefromclone = true;
  446. setEventMessages($langs->trans("ProjectCreatedInDolibarr", $newobject->ref), "", 'mesgs');
  447. //var_dump($newobject); exit;
  448. }
  449. }
  450. // Actions to send emails
  451. $triggersendname = 'PROJECT_SENTBYMAIL';
  452. $paramname = 'id';
  453. $autocopy = 'MAIN_MAIL_AUTOCOPY_PROJECT_TO'; // used to know the automatic BCC to add
  454. $trackid = 'proj'.$object->id;
  455. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  456. }
  457. /*
  458. * View
  459. */
  460. $form = new Form($db);
  461. $formfile = new FormFile($db);
  462. $formproject = new FormProjets($db);
  463. $userstatic = new User($db);
  464. $title = $langs->trans("Project").' - '.$object->ref.(!empty($object->thirdparty->name) ? ' - '.$object->thirdparty->name : '').(!empty($object->title) ? ' - '.$object->title : '');
  465. if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE)) {
  466. $title = $object->ref.(!empty($object->thirdparty->name) ? ' - '.$object->thirdparty->name : '').(!empty($object->title) ? ' - '.$object->title : '');
  467. }
  468. $help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos|DE:Modul_Projekte";
  469. llxHeader("", $title, $help_url);
  470. $titleboth = $langs->trans("LeadsOrProjects");
  471. $titlenew = $langs->trans("NewLeadOrProject"); // Leads and opportunities by default
  472. if (!getDolGlobalInt('PROJECT_USE_OPPORTUNITIES')) {
  473. $titleboth = $langs->trans("Projects");
  474. $titlenew = $langs->trans("NewProject");
  475. }
  476. if (getDolGlobalInt('PROJECT_USE_OPPORTUNITIES') == 2) { // 2 = leads only
  477. $titleboth = $langs->trans("Leads");
  478. $titlenew = $langs->trans("NewLead");
  479. }
  480. if ($action == 'create' && $user->hasRight('projet', 'creer')) {
  481. /*
  482. * Create
  483. */
  484. $thirdparty = new Societe($db);
  485. if ($socid > 0) {
  486. $thirdparty->fetch($socid);
  487. }
  488. print load_fiche_titre($titlenew, '', 'project');
  489. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  490. print '<input type="hidden" name="action" value="add">';
  491. print '<input type="hidden" name="token" value="'.newToken().'">';
  492. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  493. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  494. print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
  495. print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
  496. print dol_get_fiche_head();
  497. print '<table class="border centpercent tableforfieldcreate">';
  498. $defaultref = '';
  499. $modele = !getDolGlobalString('PROJECT_ADDON') ? 'mod_project_simple' : $conf->global->PROJECT_ADDON;
  500. // Search template files
  501. $file = '';
  502. $classname = '';
  503. $filefound = 0;
  504. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  505. foreach ($dirmodels as $reldir) {
  506. $file = dol_buildpath($reldir."core/modules/project/".$modele.'.php', 0);
  507. if (file_exists($file)) {
  508. $filefound = 1;
  509. $classname = $modele;
  510. break;
  511. }
  512. }
  513. if ($filefound) {
  514. $result = dol_include_once($reldir."core/modules/project/".$modele.'.php');
  515. $modProject = new $classname();
  516. $defaultref = $modProject->getNextValue($thirdparty, $object);
  517. }
  518. if (is_numeric($defaultref) && $defaultref <= 0) {
  519. $defaultref = '';
  520. }
  521. // Ref
  522. $suggestedref = (GETPOST("ref") ? GETPOST("ref") : $defaultref);
  523. 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).'">';
  524. if ($suggestedref) {
  525. print ' '.$form->textwithpicto('', $langs->trans("YouCanCompleteRef", $suggestedref));
  526. }
  527. print '</td></tr>';
  528. // Label
  529. print '<tr><td><span class="fieldrequired">'.$langs->trans("Label").'</span></td><td><input class="width500 maxwidth150onsmartphone" type="text" name="title" value="'.dol_escape_htmltag(GETPOST("title", 'alphanohtml')).'" autofocus></td></tr>';
  530. // Parent
  531. if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
  532. print '<tr><td>'.$langs->trans("Parent").'</td><td class="maxwidthonsmartphone">';
  533. print img_picto('', 'project', 'class="pictofixedwidth"');
  534. $formproject->select_projects(-1, '', 'fk_project', 64, 0, 1, 1, 0, 0, 0, '', 0, 0, '', '', '');
  535. print '</td></tr>';
  536. }
  537. // Usage (opp, task, bill time, ...)
  538. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
  539. print '<tr><td class="tdtop">';
  540. print $langs->trans("Usage");
  541. print '</td>';
  542. print '<td>';
  543. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  544. print '<input type="checkbox" id="usage_opportunity" name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') ? ' checked="checked"' : '') : ' checked="checked"').'"> ';
  545. $htmltext = $langs->trans("ProjectFollowOpportunity");
  546. print '<label for="usage_opportunity">'.$form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext).'</label>';
  547. print '<script>';
  548. print '$( document ).ready(function() {
  549. jQuery("#usage_opportunity").change(function() {
  550. if (jQuery("#usage_opportunity").prop("checked")) {
  551. console.log("Show opportunities fields");
  552. jQuery(".classuseopportunity").show();
  553. } else {
  554. console.log("Hide opportunities fields "+jQuery("#usage_opportunity").prop("checked"));
  555. jQuery(".classuseopportunity").hide();
  556. }
  557. });
  558. ';
  559. if (GETPOSTISSET('usage_opportunity') && !GETPOST('usage_opportunity')) {
  560. print 'jQuery(".classuseopportunity").hide();';
  561. }
  562. print '});';
  563. print '</script>';
  564. print '<br>';
  565. }
  566. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  567. print '<input type="checkbox" id="usage_task" name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') ? ' checked="checked"' : '') : ' checked="checked"').'"> ';
  568. $htmltext = $langs->trans("ProjectFollowTasks");
  569. print '<label for="usage_task">'.$form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext).'</label>';
  570. print '<script>';
  571. print '$( document ).ready(function() {
  572. jQuery("#usage_task").change(function() {
  573. if (jQuery("#usage_task").prop("checked")) {
  574. console.log("Show task fields");
  575. jQuery(".classusetask").show();
  576. } else {
  577. console.log("Hide tasks fields "+jQuery("#usage_task").prop("checked"));
  578. jQuery(".classusetask").hide();
  579. }
  580. });
  581. ';
  582. if (GETPOSTISSET('usage_task') && !GETPOST('usage_task')) {
  583. print 'jQuery(".classusetask").hide();';
  584. }
  585. print '});';
  586. print '</script>';
  587. print '<br>';
  588. }
  589. if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
  590. print '<input type="checkbox" id="usage_bill_time" name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') ? ' checked="checked"' : '') : '').'"> ';
  591. $htmltext = $langs->trans("ProjectBillTimeDescription");
  592. print '<label for="usage_bill_time">'.$form->textwithpicto($langs->trans("BillTime"), $htmltext).'</label>';
  593. print '<script>';
  594. print '$( document ).ready(function() {
  595. jQuery("#usage_bill_time").change(function() {
  596. if (jQuery("#usage_bill_time").prop("checked")) {
  597. console.log("Show bill time fields");
  598. jQuery(".classusebilltime").show();
  599. } else {
  600. console.log("Hide bill time fields "+jQuery("#usage_bill_time").prop("checked"));
  601. jQuery(".classusebilltime").hide();
  602. }
  603. });
  604. ';
  605. if (GETPOSTISSET('usage_bill_time') && !GETPOST('usage_bill_time')) {
  606. print 'jQuery(".classusebilltime").hide();';
  607. }
  608. print '});';
  609. print '</script>';
  610. print '<br>';
  611. }
  612. if (isModEnabled('eventorganization')) {
  613. print '<input type="checkbox" id="usage_organize_event" name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') ? ' checked="checked"' : '') : '').'"> ';
  614. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  615. print '<label for="usage_organize_event">'.$form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext).'</label>';
  616. print '<script>';
  617. print '$( document ).ready(function() {
  618. jQuery("#usage_organize_event").change(function() {
  619. if (jQuery("#usage_organize_event").prop("checked")) {
  620. console.log("Show organize event fields");
  621. jQuery(".classuseorganizeevent").show();
  622. } else {
  623. console.log("Hide organize event fields "+jQuery("#usage_organize_event").prop("checked"));
  624. jQuery(".classuseorganizeevent").hide();
  625. }
  626. });
  627. ';
  628. if (!GETPOST('usage_organize_event')) {
  629. print 'jQuery(".classuseorganizeevent").hide();';
  630. }
  631. print '});';
  632. print '</script>';
  633. }
  634. print '</td>';
  635. print '</tr>';
  636. }
  637. // Thirdparty
  638. if (isModEnabled('societe')) {
  639. print '<tr><td>';
  640. print(!getDolGlobalString('PROJECT_THIRDPARTY_REQUIRED') ? '' : '<span class="fieldrequired">');
  641. print $langs->trans("ThirdParty");
  642. print(!getDolGlobalString('PROJECT_THIRDPARTY_REQUIRED') ? '' : '</span>');
  643. print '</td><td class="maxwidthonsmartphone">';
  644. $filter = '';
  645. if (getDolGlobalString('PROJECT_FILTER_FOR_THIRDPARTY_LIST')) {
  646. $filter = $conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST;
  647. }
  648. $text = img_picto('', 'company').$form->select_company(GETPOST('socid', 'int'), 'socid', $filter, 'SelectThirdParty', 1, 0, array(), 0, 'minwidth300 widthcentpercentminusxx maxwidth500');
  649. if (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') && empty($conf->dol_use_jmobile)) {
  650. $texthelp = $langs->trans("IfNeedToUseOtherObjectKeepEmpty");
  651. print $form->textwithtooltip($text.' '.img_help(), $texthelp, 1);
  652. } else {
  653. print $text;
  654. }
  655. if (!GETPOSTISSET('backtopage')) {
  656. $url = '/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create');
  657. $newbutton = '<span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span>';
  658. // TODO @LDR Implement this
  659. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
  660. $tmpbacktopagejsfields = 'addthirdparty:socid,search_socid';
  661. print dolButtonToOpenUrlInDialogPopup('addthirdparty', $langs->transnoentitiesnoconv('AddThirdParty'), $newbutton, $url, '', '', '', $tmpbacktopagejsfields);
  662. } else {
  663. print ' <a href="'.DOL_URL_ROOT.$url.'">'.$newbutton.'</a>';
  664. }
  665. }
  666. print '</td></tr>';
  667. }
  668. // Status
  669. if ($status != '') {
  670. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  671. print '<input type="hidden" name="status" value="'.$status.'">';
  672. print $object->LibStatut($status, 4);
  673. print '</td></tr>';
  674. }
  675. // Visibility
  676. print '<tr><td>'.$langs->trans("Visibility").'</td><td class="maxwidthonsmartphone">';
  677. $array = array();
  678. if (!getDolGlobalString('PROJECT_DISABLE_PRIVATE_PROJECT')) {
  679. $array[0] = $langs->trans("PrivateProject");
  680. }
  681. if (!getDolGlobalString('PROJECT_DISABLE_PUBLIC_PROJECT')) {
  682. $array[1] = $langs->trans("SharedProject");
  683. }
  684. if (count($array) > 0) {
  685. print $form->selectarray('public', $array, GETPOST('public'), 0, 0, 0, '', 0, 0, 0, '', '', 1);
  686. } else {
  687. print '<input type="hidden" name="public" id="public" value="'.GETPOST('public').'">';
  688. if (GETPOST('public') == 0) {
  689. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  690. print $langs->trans("PrivateProject");
  691. } else {
  692. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  693. print $langs->trans("SharedProject");
  694. }
  695. }
  696. print '</td></tr>';
  697. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  698. // Opportunity status
  699. print '<tr class="classuseopportunity"><td><span class="fieldrequired">'.$langs->trans("OpportunityStatus").'</span></td>';
  700. print '<td class="maxwidthonsmartphone">';
  701. print $formproject->selectOpportunityStatus('opp_status', GETPOSTISSET('opp_status') ? GETPOST('opp_status') : $object->opp_status, 1, 0, 0, 0, '', 0, 1);
  702. // Opportunity probability
  703. print ' <input class="width50 right" type="text" id="opp_percent" name="opp_percent" title="'.dol_escape_htmltag($langs->trans("OpportunityProbability")).'" value="'.dol_escape_htmltag(GETPOSTISSET('opp_percent') ? GETPOST('opp_percent') : '').'"><span class="hideonsmartphone"> %</span>';
  704. print '<input type="hidden" name="opp_percent_not_set" id="opp_percent_not_set" value="'.dol_escape_htmltag(GETPOSTISSET('opp_percent') ? '0' : '1').'">';
  705. print '</td>';
  706. print '</tr>';
  707. // Opportunity amount
  708. print '<tr class="classuseopportunity"><td>'.$langs->trans("OpportunityAmount").'</td>';
  709. print '<td><input class="width75 right" type="text" name="opp_amount" value="'.dol_escape_htmltag(GETPOSTISSET('opp_amount') ? GETPOST('opp_amount') : '').'">';
  710. print ' '.$langs->getCurrencySymbol($conf->currency);
  711. print '</td>';
  712. print '</tr>';
  713. }
  714. // Budget
  715. print '<tr><td>'.$langs->trans("Budget").'</td>';
  716. print '<td><input class="width75 right" type="text" name="budget_amount" value="'.dol_escape_htmltag(GETPOSTISSET('budget_amount') ? GETPOST('budget_amount') : '').'">';
  717. print ' '.$langs->getCurrencySymbol($conf->currency);
  718. print '</td>';
  719. print '</tr>';
  720. // Date project
  721. print '<tr><td>'.$langs->trans("Date").(isModEnabled('eventorganization') ? ' <span class="classuseorganizeevent">('.$langs->trans("Project").')</span>' : '').'</td><td>';
  722. print $form->selectDate(($date_start ? $date_start : ''), 'projectstart', 0, 0, 0, '', 1, 0);
  723. print ' <span class="opacitymedium"> '.$langs->trans("to").' </span> ';
  724. print $form->selectDate(($date_end ? $date_end : -1), 'projectend', 0, 0, 0, '', 1, 0);
  725. print '</td></tr>';
  726. if (isModEnabled('eventorganization')) {
  727. // Date event
  728. print '<tr class="classuseorganizeevent"><td>'.$langs->trans("Date").' ('.$langs->trans("Event").')</td><td>';
  729. print $form->selectDate(($date_start_event ? $date_start_event : -1), 'date_start_event', 1, 1, 1, '', 1, 0);
  730. print ' <span class="opacitymedium"> '.$langs->trans("to").' </span> ';
  731. print $form->selectDate(($date_end_event ? $date_end_event : -1), 'date_end_event', 1, 1, 1, '', 1, 0);
  732. print '</td></tr>';
  733. // Location
  734. print '<tr class="classuseorganizeevent"><td>'.$langs->trans("Location").'</td>';
  735. print '<td><input class="minwidth300 maxwidth500" type="text" name="location" value="'.dol_escape_htmltag($location).'"></td>';
  736. print '</tr>';
  737. }
  738. // Description
  739. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  740. print '<td>';
  741. $doleditor = new DolEditor('description', GETPOST("description", 'restricthtml'), '', 90, 'dolibarr_notes', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
  742. $doleditor->Create();
  743. print '</td></tr>';
  744. if (isModEnabled('categorie')) {
  745. // Categories
  746. print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
  747. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PROJECT, '', 'parent', 64, 0, 1);
  748. $arrayselected = GETPOST('categories', 'array');
  749. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  750. print "</td></tr>";
  751. }
  752. // Other options
  753. $parameters = array();
  754. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  755. print $hookmanager->resPrint;
  756. if (empty($reshook)) {
  757. print $object->showOptionals($extrafields, 'create');
  758. }
  759. print '</table>';
  760. print dol_get_fiche_end();
  761. print $form->buttonsSaveCancel('CreateDraft');
  762. print '</form>';
  763. // Change probability from status or role of project
  764. // Set also dependencies between use taks and bill time
  765. print '<script type="text/javascript">
  766. jQuery(document).ready(function() {
  767. function change_percent()
  768. {
  769. var element = jQuery("#opp_status option:selected");
  770. var defaultpercent = element.attr("defaultpercent");
  771. /*if (jQuery("#opp_percent_not_set").val() == "") */
  772. jQuery("#opp_percent").val(defaultpercent);
  773. }
  774. /*init_myfunc();*/
  775. jQuery("#opp_status").change(function() {
  776. change_percent();
  777. });
  778. jQuery("#usage_task").change(function() {
  779. console.log("We click on usage task "+jQuery("#usage_task").is(":checked"));
  780. if (! jQuery("#usage_task").is(":checked")) {
  781. jQuery("#usage_bill_time").prop("checked", false);
  782. }
  783. });
  784. jQuery("#usage_bill_time").change(function() {
  785. console.log("We click on usage to bill time");
  786. if (jQuery("#usage_bill_time").is(":checked")) {
  787. jQuery("#usage_task").prop("checked", true);
  788. }
  789. });
  790. });
  791. </script>';
  792. } elseif ($object->id > 0) {
  793. /*
  794. * Show or edit
  795. */
  796. $res = $object->fetch_optionals();
  797. // To verify role of users
  798. $userAccess = $object->restrictedProjectArea($user, 'read');
  799. $userWrite = $object->restrictedProjectArea($user, 'write');
  800. $userDelete = $object->restrictedProjectArea($user, 'delete');
  801. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  802. // Confirmation validation
  803. if ($action == 'validate') {
  804. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProject'), $langs->trans('ConfirmValidateProject'), 'confirm_validate', '', 0, 1);
  805. }
  806. // Confirmation close
  807. if ($action == 'close') {
  808. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CloseAProject"), $langs->trans("ConfirmCloseAProject"), "confirm_close", '', '', 1);
  809. }
  810. // Confirmation reopen
  811. if ($action == 'reopen') {
  812. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ReOpenAProject"), $langs->trans("ConfirmReOpenAProject"), "confirm_reopen", '', '', 1);
  813. }
  814. // Confirmation delete
  815. if ($action == 'delete') {
  816. $text = $langs->trans("ConfirmDeleteAProject");
  817. $task = new Task($db);
  818. $taskarray = $task->getTasksArray(0, 0, $object->id, 0, 0);
  819. $nboftask = count($taskarray);
  820. if ($nboftask) {
  821. $text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoRemoveTasks", $nboftask);
  822. }
  823. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("DeleteAProject"), $text, "confirm_delete", '', '', 1);
  824. }
  825. // Clone confirmation
  826. if ($action == 'clone') {
  827. $formquestion = array(
  828. 'text' => $langs->trans("ConfirmClone"),
  829. 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')),
  830. array('type' => 'checkbox', 'name' => 'clone_contacts', 'label' => $langs->trans("CloneContacts"), 'value' => true),
  831. array('type' => 'checkbox', 'name' => 'clone_tasks', 'label' => $langs->trans("CloneTasks"), 'value' => true),
  832. array('type' => 'checkbox', 'name' => 'move_date', 'label' => $langs->trans("CloneMoveDate"), 'value' => true),
  833. array('type' => 'checkbox', 'name' => 'clone_notes', 'label' => $langs->trans("CloneNotes"), 'value' => true),
  834. array('type' => 'checkbox', 'name' => 'clone_project_files', 'label' => $langs->trans("CloneProjectFiles"), 'value' => false),
  835. array('type' => 'checkbox', 'name' => 'clone_task_files', 'label' => $langs->trans("CloneTaskFiles"), 'value' => false)
  836. );
  837. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ToClone"), $langs->trans("ConfirmCloneProject"), "confirm_clone", $formquestion, '', 1, 400, 590);
  838. }
  839. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  840. print '<input type="hidden" name="token" value="'.newToken().'">';
  841. print '<input type="hidden" name="action" value="update">';
  842. print '<input type="hidden" name="id" value="'.$object->id.'">';
  843. print '<input type="hidden" name="comefromclone" value="'.$comefromclone.'">';
  844. $head = project_prepare_head($object);
  845. if ($action == 'edit' && $userWrite > 0) {
  846. print dol_get_fiche_head($head, 'project', $langs->trans("Project"), 0, ($object->public ? 'projectpub' : 'project'));
  847. print '<table class="border centpercent">';
  848. // Ref
  849. $suggestedref = $object->ref;
  850. print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Ref").'</td>';
  851. print '<td><input size="25" name="ref" value="'.$suggestedref.'">';
  852. print ' '.$form->textwithpicto('', $langs->trans("YouCanCompleteRef", $suggestedref));
  853. print '</td></tr>';
  854. // Label
  855. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td>';
  856. print '<td><input class="quatrevingtpercent" name="title" value="'.dol_escape_htmltag($object->title).'"></td></tr>';
  857. // Status
  858. print '<tr><td class="fieldrequired">'.$langs->trans("Status").'</td><td>';
  859. print '<select class="flat" name="status" id="status">';
  860. $statuses = $object->labelStatusShort;
  861. if (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_PROJECT')) {
  862. unset($statuses[$object::STATUS_DRAFT]);
  863. }
  864. foreach ($statuses as $key => $val) {
  865. print '<option value="'.$key.'"'.((GETPOSTISSET('status') ? GETPOST('status') : $object->statut) == $key ? ' selected="selected"' : '').'>'.$langs->trans($val).'</option>';
  866. }
  867. print '</select>';
  868. print ajax_combobox('status');
  869. print '</td></tr>';
  870. // Parent
  871. if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
  872. print '<tr><td>'.$langs->trans("Parent").'</td><td class="maxwidthonsmartphone">';
  873. print img_picto('', 'project', 'class="pictofixedwidth"');
  874. $formproject->select_projects(-1, $object->fk_project, 'fk_project', 64, 0, 1, 1, 0, 0, 0, '', 0, 0, '', '', '');
  875. print '</td></tr>';
  876. }
  877. // Usage
  878. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
  879. print '<tr><td class="tdtop">';
  880. print $langs->trans("Usage");
  881. print '</td>';
  882. print '<td>';
  883. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  884. print '<input type="checkbox" id="usage_opportunity" name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'> ';
  885. $htmltext = $langs->trans("ProjectFollowOpportunity");
  886. print '<label for="usage_opportunity">'.$form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext).'</label>';
  887. print '<script>';
  888. print '$( document ).ready(function() {
  889. jQuery("#usage_opportunity").change(function() {
  890. set_usage_opportunity();
  891. });
  892. set_usage_opportunity();
  893. function set_usage_opportunity() {
  894. console.log("set_usage_opportunity");
  895. if (jQuery("#usage_opportunity").prop("checked")) {
  896. console.log("Show opportunities fields");
  897. jQuery(".classuseopportunity").show();
  898. } else {
  899. console.log("Hide opportunities fields "+jQuery("#usage_opportunity").prop("checked"));
  900. jQuery(".classuseopportunity").hide();
  901. }
  902. }
  903. });';
  904. print '</script>';
  905. print '<br>';
  906. }
  907. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  908. print '<input type="checkbox" id="usage_task" name="usage_task"' . (GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')) . '> ';
  909. $htmltext = $langs->trans("ProjectFollowTasks");
  910. print '<label for="usage_task">'.$form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext).'</label>';
  911. print '<script>';
  912. print '$( document ).ready(function() {
  913. jQuery("#usage_task").change(function() {
  914. set_usage_task();
  915. });
  916. set_usage_task();
  917. function set_usage_task() {
  918. console.log("set_usage_task");
  919. if (jQuery("#usage_task").prop("checked")) {
  920. console.log("Show task fields");
  921. jQuery(".classusetask").show();
  922. } else {
  923. console.log("Hide task fields "+jQuery("#usage_task").prop("checked"));
  924. jQuery(".classusetask").hide();
  925. }
  926. }
  927. });';
  928. print '</script>';
  929. print '<br>';
  930. }
  931. if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
  932. 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"' : '')) . '> ';
  933. $htmltext = $langs->trans("ProjectBillTimeDescription");
  934. print '<label for="usage_bill_time">'.$form->textwithpicto($langs->trans("BillTime"), $htmltext).'</label>';
  935. print '<script>';
  936. print '$( document ).ready(function() {
  937. jQuery("#usage_bill_time").change(function() {
  938. set_usage_bill_time();
  939. });
  940. set_usage_bill_time();
  941. function set_usage_bill_time() {
  942. console.log("set_usage_bill_time");
  943. if (jQuery("#usage_bill_time").prop("checked")) {
  944. console.log("Show bill time fields");
  945. jQuery(".classusebilltime").show();
  946. } else {
  947. console.log("Hide bill time fields "+jQuery("#usage_bill_time").prop("checked"));
  948. jQuery(".classusebilltime").hide();
  949. }
  950. }
  951. });';
  952. print '</script>';
  953. print '<br>';
  954. }
  955. if (isModEnabled('eventorganization')) {
  956. 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"' : '')) . '> ';
  957. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  958. print '<label for="usage_organize_event">'.$form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext).'</label>';
  959. print '<script>';
  960. print '$( document ).ready(function() {
  961. jQuery("#usage_organize_event").change(function() {
  962. set_usage_event();
  963. });
  964. set_usage_event();
  965. function set_usage_event() {
  966. console.log("set_usage_event");
  967. if (jQuery("#usage_organize_event").prop("checked")) {
  968. console.log("Show organize event fields");
  969. jQuery(".classuseorganizeevent").show();
  970. } else {
  971. console.log("Hide organize event fields "+jQuery("#usage_organize_event").prop("checked"));
  972. jQuery(".classuseorganizeevent").hide();
  973. }
  974. }
  975. });';
  976. print '</script>';
  977. }
  978. print '</td></tr>';
  979. }
  980. print '</td></tr>';
  981. // Thirdparty
  982. if (isModEnabled('societe')) {
  983. print '<tr><td>';
  984. print(!getDolGlobalString('PROJECT_THIRDPARTY_REQUIRED') ? '' : '<span class="fieldrequired">');
  985. print $langs->trans("ThirdParty");
  986. print(!getDolGlobalString('PROJECT_THIRDPARTY_REQUIRED') ? '' : '</span>');
  987. print '</td><td>';
  988. $filter = '';
  989. if (getDolGlobalString('PROJECT_FILTER_FOR_THIRDPARTY_LIST')) {
  990. $filter = $conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST;
  991. }
  992. $text = img_picto('', 'company', 'class="pictofixedwidth"');
  993. $text .= $form->select_company(!empty($object->thirdparty->id) ? $object->thirdparty->id : "", 'socid', $filter, 'None', 1, 0, array(), 0, 'minwidth300');
  994. if (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') && empty($conf->dol_use_jmobile)) {
  995. $texthelp = $langs->trans("IfNeedToUseOtherObjectKeepEmpty");
  996. print $form->textwithtooltip($text.' '.img_help(), $texthelp, 1, 0, '', '', 2);
  997. } else {
  998. print $text;
  999. }
  1000. print '</td></tr>';
  1001. }
  1002. // Visibility
  1003. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  1004. $array = array();
  1005. if (!getDolGlobalString('PROJECT_DISABLE_PRIVATE_PROJECT')) {
  1006. $array[0] = $langs->trans("PrivateProject");
  1007. }
  1008. if (!getDolGlobalString('PROJECT_DISABLE_PUBLIC_PROJECT')) {
  1009. $array[1] = $langs->trans("SharedProject");
  1010. }
  1011. if (count($array) > 0) {
  1012. print $form->selectarray('public', $array, $object->public, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  1013. } else {
  1014. print '<input type="hidden" id="public" name="public" value="'.$object->public.'">';
  1015. if ($object->public == 0) {
  1016. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  1017. print $langs->trans("PrivateProject");
  1018. } else {
  1019. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  1020. print $langs->trans("SharedProject");
  1021. }
  1022. }
  1023. print '</td></tr>';
  1024. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  1025. $classfortr = ($object->usage_opportunity ? '' : ' hideobject');
  1026. // Opportunity status
  1027. print '<tr class="classuseopportunity'.$classfortr.'"><td>'.$langs->trans("OpportunityStatus").'</td>';
  1028. print '<td>';
  1029. print '<div>';
  1030. print $formproject->selectOpportunityStatus('opp_status', $object->opp_status, 1, 0, 0, 0, 'minwidth150 inline-block valignmiddle', 1, 1);
  1031. // Opportunity probability
  1032. print ' <input class="width50 right" type="text" id="opp_percent" name="opp_percent" title="'.dol_escape_htmltag($langs->trans("OpportunityProbability")).'" value="'.(GETPOSTISSET('opp_percent') ? GETPOST('opp_percent') : (strcmp($object->opp_percent, '') ? vatrate($object->opp_percent) : '')).'"> %';
  1033. print '<span id="oldopppercent" class="opacitymedium"></span>';
  1034. print '</div>';
  1035. print '<div id="divtocloseproject" class="inline-block valign clearboth paddingtop" style="display: none;">';
  1036. print '<input type="checkbox" id="inputcloseproject" name="closeproject" />';
  1037. print '<label for="inputcloseproject">';
  1038. print $form->textwithpicto($langs->trans("AlsoCloseAProject"), $langs->trans("AlsoCloseAProjectTooltip")).'</label>';
  1039. print ' </div>';
  1040. print '</td>';
  1041. print '</tr>';
  1042. // Opportunity amount
  1043. print '<tr class="classuseopportunity'.$classfortr.'"><td>'.$langs->trans("OpportunityAmount").'</td>';
  1044. print '<td><input class="width75 right" type="text" name="opp_amount" value="'.(GETPOSTISSET('opp_amount') ? GETPOST('opp_amount') : (strcmp($object->opp_amount, '') ? price2num($object->opp_amount) : '')).'">';
  1045. print $langs->getCurrencySymbol($conf->currency);
  1046. print '</td>';
  1047. print '</tr>';
  1048. }
  1049. // Budget
  1050. print '<tr><td>'.$langs->trans("Budget").'</td>';
  1051. print '<td><input class="width75 right" type="text" name="budget_amount" value="'.(GETPOSTISSET('budget_amount') ? GETPOST('budget_amount') : (strcmp($object->budget_amount, '') ? price2num($object->budget_amount) : '')).'">';
  1052. print $langs->getCurrencySymbol($conf->currency);
  1053. print '</td>';
  1054. print '</tr>';
  1055. // Date project
  1056. print '<tr><td>'.$langs->trans("Date").(isModEnabled('eventorganization') ? ' <span class="classuseorganizeevent">('.$langs->trans("Project").')</span>' : '').'</td><td>';
  1057. print $form->selectDate($object->date_start ? $object->date_start : -1, 'projectstart', 0, 0, 0, '', 1, 0);
  1058. print ' <span class="opacitymedium"> '.$langs->trans("to").' </span> ';
  1059. print $form->selectDate($object->date_end ? $object->date_end : -1, 'projectend', 0, 0, 0, '', 1, 0);
  1060. $object->getLinesArray(null, 0);
  1061. if (!empty($object->usage_task) && !empty($object->lines)) {
  1062. print ' <span id="divreportdate" class="hidden">&nbsp; &nbsp; <input type="checkbox" class="valignmiddle" id="reportdate" name="reportdate" value="yes" ';
  1063. if ($comefromclone) {
  1064. print 'checked ';
  1065. }
  1066. print '/><label for="reportdate" class="valignmiddle opacitymedium">'.$langs->trans("ProjectReportDate").'</label></span>';
  1067. }
  1068. print '</td></tr>';
  1069. if (isModEnabled('eventorganization')) {
  1070. // Date event
  1071. print '<tr class="classuseorganizeevent"><td>'.$langs->trans("Date").' ('.$langs->trans("Event").')</td><td>';
  1072. print $form->selectDate(($date_start_event ? $date_start_event : ($object->date_start_event ? $object->date_start_event : -1)), 'date_start_event', 1, 1, 1, '', 1, 0);
  1073. print ' <span class="opacitymedium"> '.$langs->trans("to").' </span> ';
  1074. print $form->selectDate(($date_end_event ? $date_end_event : ($object->date_end_event ? $object->date_end_event : -1)), 'date_end_event', 1, 1, 1, '', 1, 0);
  1075. print '</td></tr>';
  1076. // Location
  1077. print '<tr class="classuseorganizeevent"><td>'.$langs->trans("Location").'</td>';
  1078. print '<td><input class="minwidth300 maxwidth500" type="text" name="location" value="'.dol_escape_htmltag(GETPOSTISSET('location') ? GETPOST('location') : $object->location).'"></td>';
  1079. print '</tr>';
  1080. }
  1081. // Description
  1082. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  1083. print '<td>';
  1084. $doleditor = new DolEditor('description', $object->description, '', 90, 'dolibarr_notes', '', false, true, getDolGlobalInt('FCKEDITOR_ENABLE_SOCIETE'), ROWS_3, '90%');
  1085. $doleditor->Create();
  1086. print '</td></tr>';
  1087. // Tags-Categories
  1088. if (isModEnabled('categorie')) {
  1089. $arrayselected = array();
  1090. print '<tr><td>'.$langs->trans("Categories").'</td><td>';
  1091. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PROJECT, '', 'parent', 64, 0, 1);
  1092. $c = new Categorie($db);
  1093. $cats = $c->containing($object->id, Categorie::TYPE_PROJECT);
  1094. foreach ($cats as $cat) {
  1095. $arrayselected[] = $cat->id;
  1096. }
  1097. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, '0');
  1098. print "</td></tr>";
  1099. }
  1100. // Other options
  1101. $parameters = array();
  1102. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1103. print $hookmanager->resPrint;
  1104. if (empty($reshook)) {
  1105. print $object->showOptionals($extrafields, 'edit');
  1106. }
  1107. print '</table>';
  1108. } else {
  1109. print dol_get_fiche_head($head, 'project', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
  1110. // Project card
  1111. if (!empty($_SESSION['pageforbacktolist']) && !empty($_SESSION['pageforbacktolist']['project'])) {
  1112. $tmpurl = $_SESSION['pageforbacktolist']['project'];
  1113. $tmpurl = preg_replace('/__SOCID__/', $object->socid, $tmpurl);
  1114. $linkback = '<a href="'.$tmpurl.(preg_match('/\?/', $tmpurl) ? '&' : '?'). 'restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1115. } else {
  1116. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1117. }
  1118. $morehtmlref = '<div class="refidno">';
  1119. // Title
  1120. $morehtmlref .= dol_escape_htmltag($object->title);
  1121. $morehtmlref .= '<br>';
  1122. // Thirdparty
  1123. if (!empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
  1124. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'project');
  1125. }
  1126. // Parent
  1127. if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
  1128. if (!empty($object->fk_project) && $object->fk_project) {
  1129. $parent = new Project($db);
  1130. $parent->fetch($object->fk_project);
  1131. $morehtmlref .= $langs->trans("Child of").' '.$parent->getNomUrl(1, 'project').' '.$parent->title;
  1132. }
  1133. }
  1134. $morehtmlref .= '</div>';
  1135. // Define a complementary filter for search of next/prev ref.
  1136. if (!$user->hasRight('projet', 'all', 'lire')) {
  1137. $objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
  1138. $object->next_prev_filter = "rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  1139. }
  1140. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  1141. print '<div class="fichecenter">';
  1142. print '<div class="fichehalfleft">';
  1143. print '<div class="underbanner clearboth"></div>';
  1144. print '<table class="border tableforfield centpercent">';
  1145. // Usage
  1146. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
  1147. print '<tr><td class="tdtop">';
  1148. print $langs->trans("Usage");
  1149. print '</td>';
  1150. print '<td>';
  1151. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  1152. print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'> ';
  1153. $htmltext = $langs->trans("ProjectFollowOpportunity");
  1154. print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
  1155. print '<br>';
  1156. }
  1157. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  1158. print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'> ';
  1159. $htmltext = $langs->trans("ProjectFollowTasks");
  1160. print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
  1161. print '<br>';
  1162. }
  1163. if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
  1164. 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"' : '')).'> ';
  1165. $htmltext = $langs->trans("ProjectBillTimeDescription");
  1166. print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
  1167. print '<br>';
  1168. }
  1169. if (isModEnabled('eventorganization')) {
  1170. 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"' : '')).'> ';
  1171. $htmltext = $langs->trans("EventOrganizationDescriptionLong");
  1172. print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
  1173. }
  1174. print '</td></tr>';
  1175. }
  1176. // Visibility
  1177. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  1178. if ($object->public) {
  1179. print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
  1180. print $langs->trans('SharedProject');
  1181. } else {
  1182. print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
  1183. print $langs->trans('PrivateProject');
  1184. }
  1185. print '</td></tr>';
  1186. if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') && !empty($object->usage_opportunity)) {
  1187. // Opportunity status
  1188. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  1189. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  1190. if ($code) {
  1191. print $langs->trans("OppStatus".$code);
  1192. }
  1193. // Opportunity percent
  1194. print ' <span title="'.$langs->trans("OpportunityProbability").'"> / ';
  1195. if (strcmp($object->opp_percent, '')) {
  1196. print price($object->opp_percent, 0, $langs, 1, 0).' %';
  1197. }
  1198. print '</span></td></tr>';
  1199. // Opportunity Amount
  1200. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  1201. if (strcmp($object->opp_amount, '')) {
  1202. print '<span class="amount">'.price($object->opp_amount, 0, $langs, 1, 0, -1, $conf->currency).'</span>';
  1203. if (strcmp($object->opp_percent, '')) {
  1204. 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>';
  1205. }
  1206. }
  1207. print '</td></tr>';
  1208. }
  1209. // Budget
  1210. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  1211. if (!is_null($object->budget_amount) && strcmp($object->budget_amount, '')) {
  1212. print '<span class="amount">'.price($object->budget_amount, 0, $langs, 1, 0, 0, $conf->currency).'</span>';
  1213. }
  1214. print '</td></tr>';
  1215. // Date start - end project
  1216. print '<tr><td>'.$langs->trans("Dates").'</td><td>';
  1217. $start = dol_print_date($object->date_start, 'day');
  1218. print($start ? $start : '?');
  1219. $end = dol_print_date($object->date_end, 'day');
  1220. print ' <span class="opacitymedium">-</span> ';
  1221. print($end ? $end : '?');
  1222. if ($object->hasDelay()) {
  1223. print img_warning("Late");
  1224. }
  1225. print '</td></tr>';
  1226. // Other attributes
  1227. $cols = 2;
  1228. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1229. print '</table>';
  1230. print '</div>';
  1231. print '<div class="fichehalfright">';
  1232. print '<div class="underbanner clearboth"></div>';
  1233. print '<table class="border tableforfield centpercent">';
  1234. // Description
  1235. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  1236. print dol_htmlentitiesbr($object->description);
  1237. print '</td></tr>';
  1238. // Categories
  1239. if (isModEnabled('categorie')) {
  1240. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
  1241. print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
  1242. print "</td></tr>";
  1243. }
  1244. print '</table>';
  1245. print '</div>';
  1246. print '</div>';
  1247. print '<div class="clearboth"></div>';
  1248. }
  1249. print dol_get_fiche_end();
  1250. if ($action == 'edit' && $userWrite > 0) {
  1251. print $form->buttonsSaveCancel();
  1252. }
  1253. print '</form>';
  1254. // Set also dependencies between use taks and bill time
  1255. print '<script type="text/javascript">
  1256. jQuery(document).ready(function() {
  1257. jQuery("#usage_task").change(function() {
  1258. console.log("We click on usage task "+jQuery("#usage_task").is(":checked"));
  1259. if (! jQuery("#usage_task").is(":checked")) {
  1260. jQuery("#usage_bill_time").prop("checked", false);
  1261. }
  1262. });
  1263. jQuery("#usage_bill_time").change(function() {
  1264. console.log("We click on usage to bill time");
  1265. if (jQuery("#usage_bill_time").is(":checked")) {
  1266. jQuery("#usage_task").prop("checked", true);
  1267. }
  1268. });
  1269. jQuery("#projectstart").change(function() {
  1270. console.log("We modify the start date");
  1271. jQuery("#divreportdate").show();
  1272. });
  1273. });
  1274. </script>';
  1275. // Change probability from status
  1276. if (!empty($conf->use_javascript_ajax) && getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
  1277. // Default value to close or not when we set opp to 'WON'.
  1278. $defaultcheckedwhenoppclose = 1;
  1279. if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
  1280. $defaultcheckedwhenoppclose = 0;
  1281. }
  1282. print '<!-- Javascript to manage opportunity status change -->';
  1283. print '<script type="text/javascript">
  1284. jQuery(document).ready(function() {
  1285. function change_percent()
  1286. {
  1287. var element = jQuery("#opp_status option:selected");
  1288. var defaultpercent = element.attr("defaultpercent");
  1289. var defaultcloseproject = '.((int) $defaultcheckedwhenoppclose).';
  1290. var elemcode = element.attr("elemcode");
  1291. var oldpercent = \''.dol_escape_js($object->opp_percent).'\';
  1292. console.log("We select "+elemcode);
  1293. /* Define if checkbox to close is checked or not */
  1294. var closeproject = 0;
  1295. if (elemcode == \'LOST\') closeproject = 1;
  1296. if (elemcode == \'WON\') closeproject = defaultcloseproject;
  1297. if (closeproject) jQuery("#inputcloseproject").prop("checked", true);
  1298. else jQuery("#inputcloseproject").prop("checked", false);
  1299. /* Make the close project checkbox visible or not */
  1300. console.log("closeproject="+closeproject);
  1301. if (elemcode == \'WON\' || elemcode == \'LOST\')
  1302. {
  1303. jQuery("#divtocloseproject").show();
  1304. }
  1305. else
  1306. {
  1307. jQuery("#divtocloseproject").hide();
  1308. }
  1309. /* Change percent with default percent (defaultpercent) if new status (defaultpercent) is higher than current (jQuery("#opp_percent").val()) */
  1310. if (oldpercent != \'\' && (parseFloat(defaultpercent) < parseFloat(oldpercent)))
  1311. {
  1312. console.log("oldpercent="+oldpercent+" defaultpercent="+defaultpercent+" def < old");
  1313. if (jQuery("#opp_percent").val() != \'\' && oldpercent != \'\') {
  1314. jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+price2numjs(oldpercent)+\' %\');
  1315. }
  1316. if (parseFloat(oldpercent) != 100 && elemcode != \'LOST\') { jQuery("#opp_percent").val(oldpercent); }
  1317. else { jQuery("#opp_percent").val(price2numjs(defaultpercent)); }
  1318. } else {
  1319. console.log("oldpercent="+oldpercent+" defaultpercent="+defaultpercent);
  1320. if (jQuery("#opp_percent").val() == \'\' || (parseFloat(jQuery("#opp_percent").val()) < parseFloat(defaultpercent))) {
  1321. if (jQuery("#opp_percent").val() != \'\' && oldpercent != \'\') {
  1322. jQuery("#oldopppercent").text(\' - '.dol_escape_js($langs->transnoentities("PreviousValue")).': \'+price2numjs(oldpercent)+\' %\');
  1323. }
  1324. jQuery("#opp_percent").val(price2numjs(defaultpercent));
  1325. }
  1326. }
  1327. }
  1328. jQuery("#opp_status").change(function() {
  1329. change_percent();
  1330. });
  1331. });
  1332. </script>';
  1333. }
  1334. /*
  1335. * Actions Buttons
  1336. */
  1337. print '<div class="tabsAction">';
  1338. $parameters = array();
  1339. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1340. // modified by hook
  1341. if (empty($reshook)) {
  1342. if ($action != "edit" && $action != 'presend') {
  1343. // Create event
  1344. /*if (isModEnabled('agenda') && !empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a
  1345. // "workflow" action so should appears somewhere else on
  1346. // page.
  1347. {
  1348. 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>';
  1349. }*/
  1350. // Send
  1351. if (empty($user->socid)) {
  1352. if ($object->statut != Project::STATUS_CLOSED) {
  1353. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');
  1354. }
  1355. }
  1356. // Accounting Report
  1357. /*
  1358. $accouting_module_activated = isModEnabled('comptabilite') || isModEnabled('accounting');
  1359. if ($accouting_module_activated && $object->statut != Project::STATUS_DRAFT) {
  1360. $start = dol_getdate((int) $object->date_start);
  1361. $end = dol_getdate((int) $object->date_end);
  1362. $url = DOL_URL_ROOT.'/compta/accounting-files.php?projectid='.$object->id;
  1363. if (!empty($object->date_start)) $url .= '&amp;date_startday='.$start['mday'].'&amp;date_startmonth='.$start['mon'].'&amp;date_startyear='.$start['year'];
  1364. if (!empty($object->date_end)) $url .= '&amp;date_stopday='.$end['mday'].'&amp;date_stopmonth='.$end['mon'].'&amp;date_stopyear='.$end['year'];
  1365. print dolGetButtonAction('', $langs->trans('ExportAccountingReportButtonLabel'), 'default', $url, '');
  1366. }
  1367. */
  1368. // Back to draft
  1369. if (!getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') && !getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_PROJECT')) {
  1370. if ($object->statut != Project::STATUS_DRAFT && $user->hasRight('projet', 'creer')) {
  1371. if ($userWrite > 0) {
  1372. print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"].'?action=confirm_setdraft&amp;confirm=yes&amp;token='.newToken().'&amp;id='.$object->id, '');
  1373. } else {
  1374. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('SetToDraft'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1375. }
  1376. }
  1377. }
  1378. // Modify
  1379. if ($object->statut != Project::STATUS_CLOSED && $user->hasRight('projet', 'creer')) {
  1380. if ($userWrite > 0) {
  1381. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id, '');
  1382. } else {
  1383. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('Modify'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1384. }
  1385. }
  1386. // Validate
  1387. if ($object->statut == Project::STATUS_DRAFT && $user->hasRight('projet', 'creer')) {
  1388. if ($userWrite > 0) {
  1389. print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=validate&amp;token='.newToken().'&amp;id='.$object->id, '');
  1390. } else {
  1391. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1392. }
  1393. }
  1394. // Close
  1395. if ($object->statut == Project::STATUS_VALIDATED && $user->hasRight('projet', 'creer')) {
  1396. if ($userWrite > 0) {
  1397. print dolGetButtonAction('', $langs->trans('Close'), 'default', $_SERVER["PHP_SELF"].'?action=close&amp;token='.newToken().'&amp;id='.$object->id, '');
  1398. } else {
  1399. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('Close'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1400. }
  1401. }
  1402. // Reopen
  1403. if ($object->statut == Project::STATUS_CLOSED && $user->hasRight('projet', 'creer')) {
  1404. if ($userWrite > 0) {
  1405. print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&amp;token='.newToken().'&amp;id='.$object->id, '');
  1406. } else {
  1407. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('ReOpen'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1408. }
  1409. }
  1410. // Buttons Create
  1411. if (!getDolGlobalString('PROJECT_HIDE_CREATE_OBJECT_BUTTON')) {
  1412. $arrayforbutaction = array(
  1413. 10 => array('lang'=>'propal', 'enabled'=>isModEnabled("propal"), 'perm'=>$user->hasRight('propal', 'creer'), 'label' => 'AddProp', 'url'=>'/comm/propal/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1414. 20 => array('lang'=>'orders', 'enabled'=>isModEnabled("commande"), 'perm'=>$user->hasRight('commande', 'creer'), 'label' => 'CreateOrder', 'url'=>'/commande/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1415. 30 => array('lang'=>'bills', 'enabled'=>isModEnabled("facture"), 'perm'=>$user->hasRight('facture', 'creer'), 'label' => 'CreateBill', 'url'=>'/compta/facture/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1416. 40 => array('lang'=>'supplier_proposal', 'enabled'=>isModEnabled("supplier_proposal"), 'perm'=>$user->hasRight('supplier_proposal', 'creer'), 'label' => 'AddSupplierProposal', 'url'=>'/supplier_proposal/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1417. 50 => array('lang'=>'suppliers', 'enabled'=>isModEnabled("supplier_order"), 'perm'=>$user->hasRight('fournisseur', 'commande', 'creer'), 'label' => 'AddSupplierOrder', 'url'=>'/fourn/commande/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1418. 60 => array('lang'=>'suppliers', 'enabled'=>isModEnabled("supplier_invoice"), 'perm'=>$user->hasRight('fournisseur', 'facture', 'creer'), 'label' => 'AddSupplierInvoice', 'url'=>'/fourn/facture/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1419. 70 => array('lang'=>'interventions', 'enabled'=>isModEnabled("ficheinter"), 'perm'=>$user->hasRight('fichinter', 'creer'), 'label' => 'AddIntervention', 'url'=>'/fichinter/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1420. 80 => array('lang'=>'contracts', 'enabled'=>isModEnabled("contrat"), 'perm'=>$user->hasRight('contrat', 'creer'), 'label' => 'AddContract', 'url'=>'/contrat/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1421. 90 => array('lang'=>'trips', 'enabled'=>isModEnabled("expensereport"), 'perm'=>$user->hasRight('expensereport', 'creer'), 'label' => 'AddTrip', 'url'=>'/expensereport/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1422. 100 => array('lang'=>'donations', 'enabled'=>isModEnabled("don"), 'perm'=>$user->hasRight('don', 'creer'), 'label' => 'AddDonation', 'url'=>'/don/card.php?action=create&amp;projectid='.$object->id.'&amp;socid='.$object->socid),
  1423. );
  1424. $params = array('backtopage' => $_SERVER["PHP_SELF"].'?id='.$object->id);
  1425. print dolGetButtonAction('', $langs->trans("Create"), 'default', $arrayforbutaction, '', 1, $params);
  1426. }
  1427. // Clone
  1428. if ($user->hasRight('projet', 'creer')) {
  1429. if ($userWrite > 0) {
  1430. print dolGetButtonAction('', $langs->trans('ToClone'), 'default', $_SERVER["PHP_SELF"].'?action=clone&amp;token='.newToken().'&amp;id='.$object->id, '');
  1431. } else {
  1432. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('ToClone'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1433. }
  1434. }
  1435. // Delete
  1436. if ($user->hasRight('projet', 'supprimer') || ($object->statut == Project::STATUS_DRAFT && $user->hasRight('projet', 'creer'))) {
  1437. if ($userDelete > 0 || ($object->statut == Project::STATUS_DRAFT && $user->hasRight('projet', 'creer'))) {
  1438. print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');
  1439. } else {
  1440. print dolGetButtonAction($langs->trans('NotOwnerOfProject'), $langs->trans('Delete'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1441. }
  1442. }
  1443. }
  1444. }
  1445. print "</div>";
  1446. if (GETPOST('modelselected')) {
  1447. $action = 'presend';
  1448. }
  1449. if ($action != 'presend') {
  1450. print '<div class="fichecenter"><div class="fichehalfleft">';
  1451. print '<a name="builddoc"></a>'; // ancre
  1452. if (getDolGlobalInt('PROJECT_ENABLE_SUB_PROJECT')) {
  1453. /*
  1454. * Sub-projects (children)
  1455. */
  1456. $children = $object->getChildren();
  1457. if ($children) {
  1458. print '<table class="centpercent notopnoleftnoright table-fiche-title">';
  1459. print '<tr class="titre"><td class="nobordernopadding valignmiddle col-title">';
  1460. print '<div class="titre inline-block">'.$langs->trans('Sub-projects').'</div>';
  1461. print '</td></tr></table>';
  1462. print '<div class="div-table-responsive-no-min">';
  1463. print '<table class="centpercent noborder'.($morecss ? ' '.$morecss : '').'">';
  1464. print '<tr class="liste_titre">';
  1465. print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', '', '', '', '', '', '', 1);
  1466. print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', '', '', '', '', '', '', 1);
  1467. print getTitleFieldOfList('Status', 0, $_SERVER["PHP_SELF"], '', '', '', '', '', '', '', 1);
  1468. print '</tr>';
  1469. print "\n";
  1470. $subproject = new Project($db);
  1471. foreach ($children as $child) {
  1472. $subproject->fetch($child->rowid);
  1473. print '<tr class="oddeven">';
  1474. print '<td class="nowraponall">'.$subproject->getNomUrl(1, 'project').'</td>';
  1475. print '<td class="nowraponall tdoverflowmax125">'.$child->title.'</td>';
  1476. print '<td class="nowraponall">'.$subproject->getLibStatut(5).'</td>';
  1477. print '</tr>';
  1478. }
  1479. print '</table>';
  1480. print '</div>';
  1481. }
  1482. }
  1483. /*
  1484. * Generated documents
  1485. */
  1486. $filename = dol_sanitizeFileName($object->ref);
  1487. $filedir = $conf->project->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
  1488. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1489. $genallowed = ($user->hasRight('projet', 'lire') && $userAccess > 0);
  1490. $delallowed = ($user->hasRight('projet', 'creer') && $userWrite > 0);
  1491. print $formfile->showdocuments('project', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 0, 0, '', '', '', '', '', $object);
  1492. print '</div><div class="fichehalfright">';
  1493. $MAXEVENT = 10;
  1494. $morehtmlcenter = '<div class="nowraponall">';
  1495. $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT.'/projet/messaging.php?id='.$object->id);
  1496. $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/projet/agenda.php?id='.$object->id);
  1497. $morehtmlcenter .= '</div>';
  1498. // List of actions on element
  1499. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1500. $formactions = new FormActions($db);
  1501. $somethingshown = $formactions->showactions($object, 'project', 0, 1, '', $MAXEVENT, '', $morehtmlcenter);
  1502. print '</div></div>';
  1503. }
  1504. // Presend form
  1505. $modelmail = 'project';
  1506. $defaulttopic = 'SendProjectRef';
  1507. $defaulttopiclang = 'projects';
  1508. $diroutput = $conf->project->multidir_output[$object->entity];
  1509. $autocopy = 'MAIN_MAIL_AUTOCOPY_PROJECT_TO'; // used to know the automatic BCC to add
  1510. $trackid = 'proj'.$object->id;
  1511. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  1512. // Hook to add more things on page
  1513. $parameters = array();
  1514. $reshook = $hookmanager->executeHooks('mainCardTabAddMore', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1515. } else {
  1516. print $langs->trans("RecordNotFound");
  1517. }
  1518. // End of page
  1519. llxFooter();
  1520. $db->close();