card.php 71 KB

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