card.php 71 KB

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