card.php 74 KB

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