card.php 48 KB

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