card.php 59 KB

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