card.php 70 KB

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