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