dolibarr 22.0.5
html.formprojet.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2013 Florian Henry <florian.henry@open-concept.pro>
3 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Benjamin Falière <benjamin.faliere@altairis.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
30
34class FormProjets extends Form
35{
39 public $db;
40
44 public $error = '';
45
46 public $errors = array();
47
48
52 public $nboftasks;
53
54
60 public function __construct($db)
61 {
62 $this->db = $db;
63 }
64
65 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
66
88 public function select_projects($socid = -1, $selected = '', $htmlname = 'projectid', $maxlength = 16, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $morecss = '', $htmlid = '', $morefilter = '')
89 {
90 // phpcs:enable
91 global $langs, $conf, $form;
92
93 $selected_input_value = '';
94 if (is_object($selected)) {
95 $selected_input_value = $selected->ref;
96 $selected = $selected->id;
97 }
98
99 $out = '';
100
101 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
102 $placeholder = '';
103
104 if ($selected && empty($selected_input_value)) {
105 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
106 $project = new Project($this->db);
107 $project->fetch((int) $selected);
108 $selected_input_value = $project->ref;
109 }
110 $urloption = 'socid=' . ((int) $socid) . '&htmlname=' . urlencode($htmlname) . '&discardclosed=' . ((int) $discard_closed);
111 if ($morefilter == 'usage_organize_event=1') {
112 $urloption .= '&usage_organize_event=1';
113 }
114 $out .= '<input type="text" class="minwidth200' . ($morecss ? ' ' . $morecss : '') . '" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' />';
115
116 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, getDolGlobalInt('PROJECT_USE_SEARCH_TO_SELECT'), 0, array());
117 } else {
118 $out .= $this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, abs($discard_closed), $forcefocus, $disabled, 0, $filterkey, 1, $forceaddid, $htmlid, $morecss, $morefilter);
119 }
120 if ($discard_closed > 0) {
121 if (!empty($form)) {
122 $out .= $form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
123 }
124 }
125
126 if (empty($nooutput)) {
127 print $out;
128 return '';
129 } else {
130 return $out;
131 }
132 }
133
134 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
135
157 public function select_projects_list($socid = -1, $selected = 0, $htmlname = 'projectid', $maxlength = 24, $option_only = 0, $show_empty = 1, $discard_closed = 0, $forcefocus = 0, $disabled = 0, $mode = 0, $filterkey = '', $nooutput = 0, $forceaddid = 0, $htmlid = '', $morecss = 'maxwidth500', $morefilter = '')
158 {
159 // phpcs:enable
160 global $user, $conf, $langs;
161
162 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
163
164 if (empty($htmlid)) {
165 $htmlid = $htmlname;
166 }
167
168 $out = '';
169 $outarray = array();
170
171 $hideunselectables = false;
172 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES')) {
173 $hideunselectables = true;
174 }
175 if (getDolGlobalInt('PROJECT_ALWAYS_DISCARD_CLOSED_PROJECTS_IN_SELECT')) {
176 $discard_closed = 1;
177 }
178
179 $projectsListId = false;
180 if (!$user->hasRight('projet', 'all', 'lire')) {
181 $projectstatic = new Project($this->db);
182 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
183 }
184
185 // Search all projects
186 $sql = "SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias";
187 $sql .= " FROM " . $this->db->prefix() . "projet as p LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
188 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
189 if ($projectsListId !== false) {
190 $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")";
191 }
192 if ($socid == 0) {
193 $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
194 }
195 if ($socid > 0) {
196 if (!getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) {
197 $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)";
198 } elseif (getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') != 'all') { // PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY is 'all' or a list of ids separated by coma.
199 $sql .= " AND (p.fk_soc IN (" . $this->db->sanitize(((int) $socid) . ", " . getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) . ") OR p.fk_soc IS NULL)";
200 }
201 }
202 if (!empty($filterkey)) {
203 $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
204 }
205 if ($morefilter) {
206 $sql .= ' AND (' . $this->db->sanitize($morefilter, 0, 1) . ')';
207 }
208 $sql .= " ORDER BY p.ref ASC";
209
210 $resql = $this->db->query($sql);
211 if ($resql) {
212 if (!empty($conf->use_javascript_ajax)) {
213 $morecss .= ' minwidth100';
214 }
215 if (empty($option_only)) {
216 $out .= '<select class="flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlid . '" name="' . $htmlname . '">';
217 }
218 if (!empty($show_empty)) {
219 if (is_numeric($show_empty)) {
220 $out .= '<option value="0">&nbsp;</option>';
221 } else {
222 $out .= '<option value="-1">'.$show_empty.'</option>';
223 }
224 }
225 $num = $this->db->num_rows($resql);
226 $i = 0;
227 if ($num) {
228 while ($i < $num) {
229 $obj = $this->db->fetch_object($resql);
230 // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
231 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
232 // Do nothing
233 } else {
234 if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) { // We discard closed except if selected
235 $i++;
236 continue;
237 }
238
239 $labeltoshow = dol_trunc($obj->ref, 18);
240 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
241 //else $labeltoshow.=' ('.$langs->trans("Private").')';
242 $labeltoshow .= ', ' . dol_trunc($obj->title, $maxlength);
243 if ($obj->name) {
244 $labeltoshow .= ' - ' . $obj->name;
245 if ($obj->name_alias) {
246 $labeltoshow .= ' (' . $obj->name_alias . ')';
247 }
248 }
249
250 $disabled = 0;
251 if ($obj->fk_statut == 0) {
252 $disabled = 1;
253 $labeltoshow .= ' - ' . $langs->trans("Draft");
254 } elseif ($obj->fk_statut == 2) {
255 if ($discard_closed == 2) {
256 $disabled = 1;
257 }
258 $labeltoshow .= ' - ' . $langs->trans("Closed");
259 } elseif (!getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
260 $disabled = 1;
261 $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany");
262 }
263
264 if (!empty($selected) && $selected == $obj->rowid) {
265 $out .= '<option value="' . $obj->rowid . '" selected';
266 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
267 $out .= '>' . $labeltoshow . '</option>';
268 } else {
269 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
270 $resultat = '';
271 } else {
272 $resultat = '<option value="' . $obj->rowid . '"';
273 if ($disabled) {
274 $resultat .= ' disabled';
275 }
276 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
277 //else $labeltoshow.=' ('.$langs->trans("Private").')';
278 $resultat .= '>';
279 $resultat .= $labeltoshow;
280 $resultat .= '</option>';
281 }
282 $out .= $resultat;
283
284 $outarray[] = array(
285 'key' => (int) $obj->rowid,
286 'value' => $obj->ref,
287 'ref' => $obj->ref,
288 'labelx' => $labeltoshow,
289 'label' => ($disabled ? '<span class="opacitymedium">' . $labeltoshow . '</span>' : $labeltoshow),
290 'disabled' => (bool) $disabled
291 );
292 }
293 }
294 $i++;
295 }
296 }
297
298 $this->db->free($resql);
299
300 if (!$mode) {
301 if (empty($option_only)) {
302 $out .= '</select>';
303 }
304
305 // Use select2 selector
306 if (!empty($conf->use_javascript_ajax)) {
307 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
308 $comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
309 $out .= $comboenhancement;
310 $morecss .= ' minwidth100';
311 }
312
313 if (empty($nooutput)) {
314 print $out;
315 return '';
316 } else {
317 return $out;
318 }
319 } else {
320 return $outarray;
321 }
322 } else {
323 dol_print_error($this->db);
324 return -1;
325 }
326 }
327
348 public function selectTasks($socid = -1, $selected = 0, $htmlname = 'taskid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showmore = 'all', $usertofilter = null, $nooutput = 0)
349 {
350 global $user, $conf, $langs;
351
352 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
353
354 if (is_null($usertofilter)) {
355 $usertofilter = $user;
356 }
357
358 $out = '';
359
360 $hideunselectables = false;
361 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES')) {
362 $hideunselectables = true;
363 }
364
365 if (empty($projectsListId)) {
366 if (!$usertofilter->hasRight('projet', 'all', 'lire')) {
367 $projectstatic = new Project($this->db);
368 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
369 }
370 }
371
372 // Search all projects
373 $sql = "SELECT t.rowid, t.ref as tref, t.label as tlabel, t.progress,";
374 $sql .= " p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, p.usage_task,";
375 $sql .= " s.nom as name";
376 $sql .= " FROM " . $this->db->prefix() . "projet as p";
377 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc,";
378 $sql .= " " . $this->db->prefix() . "projet_task as t";
379 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
380 $sql .= " AND t.fk_projet = p.rowid";
381 if ($projectsListId) {
382 $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")";
383 }
384 if ($socid == 0) {
385 $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
386 }
387 if ($socid > 0) {
388 $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)";
389 }
390 $sql .= " ORDER BY p.ref, t.ref ASC";
391
392 $resql = $this->db->query($sql);
393 if ($resql) {
394 // Use select2 selector
395 if (empty($option_only) && !empty($conf->use_javascript_ajax)) {
396 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
397 $comboenhancement = ajax_combobox($htmlname, [], 0, $forcefocus);
398 $out .= $comboenhancement;
399 $morecss .= ' minwidth150imp';
400 }
401
402 if (empty($option_only)) {
403 $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlname . '" name="' . $htmlname . '">'."\n";
404 }
405 if (!empty($show_empty)) {
406 $out .= '<option value="0" class="optiongrey">';
407 if (!is_numeric($show_empty)) {
408 //if (!empty($conf->use_javascript_ajax)) $out .= '<span class="opacitymedium">';
409 $out .= $show_empty;
410 //if (!empty($conf->use_javascript_ajax)) $out .= '</span>';
411 } else {
412 $out .= '&nbsp;';
413 }
414 $out .= '</option>'."\n";
415 }
416
417 $num = $this->db->num_rows($resql);
418 $i = 0;
419 if ($num) {
420 while ($i < $num) {
421 $obj = $this->db->fetch_object($resql);
422 // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
423 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe', 'lire')) {
424 // Do nothing
425 } else {
426 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
427 $i++;
428 continue;
429 }
430
431 $labeltoshow = '';
432 $labeltoshowhtml = '';
433
434 $disabled = 0;
435 if ($obj->fk_statut == Project::STATUS_DRAFT) {
436 $disabled = 1;
437 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
438 if ($discard_closed == 2) {
439 $disabled = 1;
440 }
441 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
442 $disabled = 1;
443 }
444
445 if (preg_match('/all/', $showmore)) {
446 $labeltoshow .= dol_trunc($obj->ref, 18); // Project ref
447 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
448 //else $labeltoshow.=' ('.$langs->trans("Private").')';
449 $labeltoshow .= ' ' . dol_trunc($obj->title, $maxlength);
450 $labeltoshowhtml = $labeltoshow;
451
452 if ($obj->name) {
453 $labeltoshow .= ' (' . $obj->name . ')';
454 $labeltoshowhtml .= ' <span class="opacitymedium">(' . $obj->name . ')</span>';
455 }
456
457 $disabled = 0;
458 if ($obj->fk_statut == Project::STATUS_DRAFT) {
459 $disabled = 1;
460 $labeltoshow .= ' - ' . $langs->trans("Draft");
461 $labeltoshowhtml .= ' - <span class="opacitymedium">' . $langs->trans("Draft") . '</span>';
462 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
463 if ($discard_closed == 2) {
464 $disabled = 1;
465 }
466 $labeltoshow .= ' - ' . $langs->trans("Closed");
467 $labeltoshowhtml .= ' - <span class="opacitymedium">' . $langs->trans("Closed") . '</span>';
468 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
469 $disabled = 1;
470 $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany");
471 $labeltoshowhtml .= ' - <span class="opacitymedium">' . $langs->trans("LinkedToAnotherCompany") . '</span>';
472 }
473 $labeltoshow .= ' - ';
474 $labeltoshowhtml .= ' - ';
475 }
476
477 // Label for task
478 $labeltoshow .= $obj->tref . ' ' . dol_trunc($obj->tlabel, $maxlength);
479 $labeltoshowhtml .= $obj->tref . ' - ' . dol_trunc($obj->tlabel, $maxlength);
480 if ($obj->usage_task && preg_match('/progress/', $showmore)) {
481 $labeltoshow .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>';
482 $labeltoshowhtml .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>';
483 }
484
485 if (!empty($selected) && $selected == $obj->rowid) {
486 $out .= '<option value="' . $obj->rowid . '" selected';
487 $out .= ' data-html="' . dol_escape_htmltag($labeltoshowhtml) . '"';
488 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
489 $out .= '>' . $labeltoshow . '</option>'."\n";
490 } else {
491 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
492 $resultat = '';
493 } else {
494 $resultat = '<option value="' . $obj->rowid . '"';
495 if ($disabled) {
496 $resultat .= ' disabled';
497 }
498 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
499 //else $labeltoshow.=' ('.$langs->trans("Private").')';
500 $resultat .= ' data-html="' . dol_escape_htmltag($labeltoshowhtml) . '"';
501 $resultat .= '>';
502 $resultat .= $labeltoshow;
503 $resultat .= '</option>'."\n";
504 }
505 $out .= $resultat;
506 }
507 }
508 $i++;
509 }
510 }
511 if (empty($option_only)) {
512 $out .= '</select>'."\n";
513 }
514
515 $this->nboftasks = $num;
516 $this->db->free($resql);
517
518 // Output or return
519 if (empty($nooutput)) {
520 print $out;
521 } else {
522 return $out;
523 }
524
525 return $num;
526 } else {
527 dol_print_error($this->db);
528 return -1;
529 }
530 }
531
532
533 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
534
546 public function select_element($table_element, $socid = 0, $morecss = '', $limitonstatus = -2, $projectkey = "fk_projet", $placeholder = '')
547 {
548 // phpcs:enable
549 global $conf, $langs;
550
551 if ($table_element == 'projet_task') {
552 return ''; // Special case of element we never link to a project (already always done)
553 }
554
555 $linkedtothirdparty = false;
556 if (!in_array(
557 $table_element,
558 array(
559 'don',
560 'expensereport_det',
561 'expensereport', 'loan',
562 'stock_mouvement',
563 'payment_salary',
564 'payment_various',
565 'salary',
566 'chargesociales',
567 'entrepot')
568 )) {
569 $linkedtothirdparty = true;
570 }
571
572 $sqlfilter = '';
573
574 //print $table_element;
575 switch ($table_element) {
576 case "loan":
577 $sql = "SELECT t.rowid, t.label as ref";
578 break;
579 case "facture":
580 $sql = "SELECT t.rowid, t.ref as ref";
581 break;
582 case "facture_fourn":
583 $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
584 break;
585 case "commande_fourn":
586 case "commande_fournisseur":
587 $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
588 break;
589 case "facture_rec":
590 $sql = "SELECT t.rowid, t.titre as ref";
591 break;
592 case "actioncomm":
593 $sql = "SELECT t.id as rowid, t.label as ref";
594 $projectkey = "fk_project";
595 break;
596 case "expensereport":
597 return '';
598 case "expensereport_det":
599 /*$sql = "SELECT rowid, '' as ref"; // table is llx_expensereport_det
600 $projectkey="fk_projet";
601 break;*/
602 return '';
603 case "commande":
604 case "contrat":
605 case "fichinter":
606 $sql = "SELECT t.rowid, t.ref";
607 break;
608 case 'stock_mouvement':
609 $sql = "SELECT t.rowid, t.label as ref";
610 $projectkey = 'fk_origin';
611 break;
612 case "payment_salary":
613 $sql = "SELECT t.rowid, t.num_payment as ref"; // TODO In a future fill and use real ref field
614 break;
615 case "payment_various":
616 $sql = "SELECT t.rowid, t.num_payment as ref";
617 break;
618 case "chargesociales":
619 default:
620 $sql = "SELECT t.rowid, t.ref";
621 break;
622 }
623 if ($linkedtothirdparty) {
624 $sql .= ", s.nom as name";
625 }
626 $sql .= " FROM " . $this->db->prefix() . $table_element . " as t";
627 if ($linkedtothirdparty) {
628 $sql .= ", " . $this->db->prefix() . "societe as s";
629 }
630 $sql .= " WHERE " . $projectkey . " is null";
631 if (!empty($socid) && $linkedtothirdparty) {
632 if (is_numeric($socid)) {
633 $sql .= " AND t.fk_soc = " . ((int) $socid);
634 } else {
635 $sql .= " AND t.fk_soc IN (" . $this->db->sanitize($socid) . ")";
636 }
637 }
638 if (!in_array($table_element, array('expensereport_det', 'stock_mouvement'))) {
639 $sql .= ' AND t.entity IN (' . getEntity('project') . ')';
640 }
641 if ($linkedtothirdparty) {
642 $sql .= " AND s.rowid = t.fk_soc";
643 }
644 if ($sqlfilter) {
645 $sql .= " AND " . $sqlfilter;
646 }
647 $sql .= " ORDER BY ref DESC";
648
649 dol_syslog(get_class($this) . '::select_element', LOG_DEBUG);
650 $resql = $this->db->query($sql);
651 if ($resql) {
652 $num = $this->db->num_rows($resql);
653 $i = 0;
654 $sellist = '';
655
656 if ($num > 0) {
657 $sellist = '<select class="flat elementselect css' . $table_element . ($morecss ? ' ' . $morecss : '') . '" name="elementselect">';
658 $sellist .= '<option value="-1"' . ($placeholder ? ' class="optiongrey"' : '') . '>' . $placeholder . '</option>';
659 while ($i < $num) {
660 $obj = $this->db->fetch_object($resql);
661 $ref = $obj->ref ? $obj->ref : $obj->rowid;
662 if (!empty($obj->ref_supplier)) {
663 $ref .= ' (' . $obj->ref_supplier . ')';
664 }
665 if (!empty($obj->name)) {
666 $ref .= ' - ' . $obj->name;
667 }
668 $sellist .= '<option value="' . $obj->rowid . '">' . $ref . '</option>';
669 $i++;
670 }
671 $sellist .= '</select>';
672 }
673 /*else
674 {
675 $sellist = '<select class="flat" name="elementselect">';
676 $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
677 $sellist.= '</select>';
678 }*/
679 $this->db->free($resql);
680
681 return $sellist;
682 } else {
683 dol_print_error($this->db);
684 $this->error = $this->db->lasterror();
685 $this->errors[] = $this->db->lasterror();
686 dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);
687 return -1;
688 }
689 }
690
691
706 public function selectOpportunityStatus($htmlname, $preselected = -1, $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '', $noadmininfo = 0, $addcombojs = 0)
707 {
708 global $conf, $langs, $user;
709
710 $sql = "SELECT rowid, code, label, percent";
711 $sql .= " FROM " . $this->db->prefix() . 'c_lead_status';
712 $sql .= " WHERE active = 1";
713 $sql .= " ORDER BY position";
714
715 $resql = $this->db->query($sql);
716 if ($resql) {
717 $num = $this->db->num_rows($resql);
718 $i = 0;
719 $sellist = '';
720 if ($num > 0) {
721 $sellist = '<select class="flat oppstatus' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlname . '" name="' . $htmlname . '">';
722 if ($showempty) {
723 // Without &nbsp, strange move of screen when switching value
724 $sellist .= '<option value="-1">&nbsp;</option>';
725 }
726 if ($showallnone) {
727 $sellist .= '<option value="all"' . ($preselected == 'all' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OnlyOpportunitiesShort") . '</option>';
728 $sellist .= '<option value="openedopp"' . ($preselected == 'openedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OpenedOpportunitiesShort") . '</option>';
729 $sellist .= '<option value="notopenedopp"' . ($preselected == 'notopenedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotOpenedOpportunitiesShort") . '</option>';
730 $sellist .= '<option value="none"' . ($preselected == 'none' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotAnOpportunityShort") . '</option>';
731 }
732 while ($i < $num) {
733 $obj = $this->db->fetch_object($resql);
734
735 $sellist .= '<option value="' . $obj->rowid . '" defaultpercent="' . $obj->percent . '" elemcode="' . $obj->code . '"';
736 if ($obj->rowid == $preselected) {
737 $sellist .= ' selected="selected"';
738 }
739 $sellist .= '>';
740 if ($useshortlabel) {
741 $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label);
742 } else {
743 $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label);
744 if ($showpercent) {
745 $finallabel .= ' (' . $obj->percent . '%)';
746 }
747 }
748 $sellist .= $finallabel;
749 $sellist .= '</option>';
750 $i++;
751 }
752 $sellist .= '</select>';
753
754 if ($user->admin && !$noadmininfo) {
755 $sellist .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
756 }
757
758 if ($addcombojs) {
759 $sellist .= ajax_combobox($htmlname);
760 }
761 }
762 /*else
763 {
764 $sellist = '<select class="flat" name="elementselect">';
765 $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
766 $sellist.= '</select>';
767 }*/
768 $this->db->free($resql);
769
770 return $sellist;
771 } else {
772 $this->error = $this->db->lasterror();
773 $this->errors[] = $this->db->lasterror();
774 dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR);
775 return -1;
776 }
777 }
778
787 public function selectProjectsStatus($selected = '', $short = 0, $htmlname = 'order_status')
788 {
789 $options = array();
790
791 // 7 is same label than 6. 8 does not exists (billed is another field)
792 $statustohow = array(
793 '0' => '0',
794 '1' => '1',
795 '2' => '2',
796 );
797
798 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
799 $tmpproject = new Project($this->db);
800
801 foreach ($statustohow as $key => $value) {
802 $tmpproject->statut = $key; // deprecated
803 $tmpproject->status = $key;
804 $options[$value] = $tmpproject->getLibStatut($short);
805 }
806
807 if (is_array($selected)) {
808 $selectedarray = $selected;
809 } elseif ($selected == 99) {
810 $selectedarray = array(0,1);
811 } else {
812 $selectedarray = explode(',', $selected);
813 }
814
815 print Form::multiselectarray($htmlname, $options, $selectedarray, 0, 0, 'minwidth100');
816 }
817
830 public function selectInvoiceAndLine($selectedInvoiceId = 0, $selectedLineId = 0, $htmlNameInvoice = 'invoiceid', $htmlNameInvoiceLine = 'invoicelineid', $morecss = 'maxwidth500', $filters = array(), $lineOnly = 0)
831 {
832 global $user, $conf, $langs;
833
834 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
835
836 $out = '';
837 if (empty($lineOnly)) {
838 // Search Invoice
839 $sql = "SELECT f.rowid, f.ref as fref,";
840 $sql .= ' s.nom as name';
841 $sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
842 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
843 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
844 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
845 if (!empty($filters)) {
846 foreach ($filters as $key => $value) {
847 if ($key == 'p.rowid') {
848 $sql .= " AND p.rowid=" . (int) $value;
849 }
850 if ($key == 'f.rowid') {
851 $sql .= " AND f.rowid=" . (int) $value;
852 }
853 }
854 }
855 $sql .= " ORDER BY p.ref, f.ref ASC";
856
857 $resql = $this->db->query($sql);
858 if ($resql) {
859 // Use select2 selector
860 if (!empty($conf->use_javascript_ajax)) {
861 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
862 $comboenhancement = ajax_combobox($htmlNameInvoice, array(array('method' => 'getLines', 'url' => dol_buildpath('/core/ajax/ajaxinvoiceline.php', 1), 'htmlname' => $htmlNameInvoiceLine)), 0, 0);
863 $out .= $comboenhancement;
864 $morecss = 'minwidth200imp maxwidth500';
865 }
866
867 $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoice . '" name="' . $htmlNameInvoice . '">';
868 $num = $this->db->num_rows($resql);
869 if ($num) {
870 while ($obj = $this->db->fetch_object($resql)) {
871 $labeltoshow = $obj->fref; // Invoice ref
872 if ($obj->name) {
873 $labeltoshow .= ' - ' . $obj->name;
874 }
875
876 $out .= '<option value="' . $obj->rowid . '" ';
877 if (!empty($selectedInvoiceId) && $selectedInvoiceId == $obj->rowid) {
878 $out .= ' selected ';
879 }
880 $out .= '>' . $labeltoshow . '</option>';
881 }
882 }
883 $out .= '</select>';
884 } else {
885 dol_print_error($this->db, $this->db->lasterror);
886 return '';
887 }
888 }
889
890 // Search Invoice Line
891 $sql = "SELECT fd.rowid, fd.label, fd.description";
892 $sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
893 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
894 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
895 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facturedet as fd ON fd.fk_facture = f.rowid';
896 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
897 if (!empty($filters)) {
898 foreach ($filters as $key => $value) {
899 if ($key == 'p.rowid') {
900 $sql .= " AND p.rowid=" . (int) $value;
901 }
902 }
903 }
904 if (!empty($selectedInvoiceId)) {
905 $sql .= " AND f.rowid=" . (int) $selectedInvoiceId;
906 }
907 $sql .= " ORDER BY p.ref, f.ref ASC";
908 $resql = $this->db->query($sql);
909 if ($resql) {
910 // Use select2 selector
911 if (empty($lineOnly)) {
912 if (!empty($conf->use_javascript_ajax)) {
913 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
914 $comboenhancement = ajax_combobox($htmlNameInvoiceLine, [], 0, 0);
915 $out .= $comboenhancement;
916 $morecss = 'minwidth200imp maxwidth500';
917 }
918
919 $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoiceLine . '" name="' . $htmlNameInvoiceLine . '">';
920 }
921 $num = $this->db->num_rows($resql);
922 if ($num) {
923 while ($obj = $this->db->fetch_object($resql)) {
924 $labeltoshow .= $obj->description; // Invoice ref
925
926 $out .= '<option value="' . $obj->rowid . '" ';
927 if (!empty($selectedLineId) && $selectedLineId == $obj->rowid) {
928 $out .= ' selected ';
929 }
930 $out .= '>' . $labeltoshow . '</option>';
931 }
932 }
933 if (empty($lineOnly)) {
934 $out .= '</select>';
935 }
936 } else {
937 dol_print_error($this->db, $this->db->lasterror);
938 return '';
939 }
940
941 return $out;
942 }
943
956 public function formOpportunityStatus($page, $selected = '', $percent_value = 0, $htmlname_status = 'none', $htmlname_percent = 'none', $filter = '', $nooutput = 0)
957 {
958 // phpcs:enable
959 global $conf, $langs;
960
961 $out = '';
962 if ($htmlname_status != "none" && $htmlname_percent != 'none') {
963 $out .= '<form method="post" action="' . $page . '">';
964 $out .= '<input type="hidden" name="action" value="set_opp_status">';
965 $out .= '<input type="hidden" name="token" value="' . newToken() . '">';
966 $out .= $this-> selectOpportunityStatus($htmlname_status, $selected, 1, 0, 0, 0, 'minwidth150 inline-block valignmiddle', 1, 1);
967 $out .= ' / <span title="'.$langs->trans("OpportunityProbability").'"> ';
968 $out .= '<input class="width50 right" type="text" id="'.$htmlname_percent.'" name="'.$htmlname_percent.'" title="'.dol_escape_htmltag($langs->trans("OpportunityProbability")).'" value="'.$percent_value.'"> %';
969 $out .= '</span>';
970 $out .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans("Modify") . '">';
971 $out .= '</form>';
972 } else {
973 if ($selected > 0) {
974 $code = dol_getIdFromCode($this->db, $selected, 'c_lead_status', 'rowid', 'code');
975 $out .= $langs->trans("OppStatus".$code);
976
977 // Opportunity percent
978 $out .= ' / <span title="'.$langs->trans("OpportunityProbability").'"> ';
979 $out .= price($percent_value, 0, $langs, 1, 0).' %';
980 $out .= '</span>';
981 } else {
982 $out .= "&nbsp;";
983 }
984 }
985
986 if ($nooutput) {
987 return $out;
988 } else {
989 print $out;
990 }
991 }
992}
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to transform a common input text or select field into ...
Definition ajax.lib.php:49
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:475
Class to manage generation of HTML components Only common components must be here.
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $nu='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Class to manage building of HTML components.
selectTasks($socid=-1, $selected=0, $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500', $projectsListId='', $showmore='all', $usertofilter=null, $nooutput=0)
Output a combo list with tasks qualified for a third party.
select_element($table_element, $socid=0, $morecss='', $limitonstatus=-2, $projectkey="fk_projet", $placeholder='')
Build a HTML select list of element of same thirdparty to suggest to link them to project.
selectProjectsStatus($selected='', $short=0, $htmlname='order_status')
Return combo list of different statuses of orders.
select_projects_list($socid=-1, $selected=0, $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey='', $nooutput=0, $forceaddid=0, $htmlid='', $morecss='maxwidth500', $morefilter='')
Returns an array with projects qualified for a third party.
select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=16, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0, $mode=0, $filterkey='', $nooutput=0, $forceaddid=0, $morecss='', $htmlid='', $morefilter='')
Output a combo list with projects qualified for a third party / user.
selectOpportunityStatus($htmlname, $preselected=-1, $showempty=1, $useshortlabel=0, $showallnone=0, $showpercent=0, $morecss='', $noadmininfo=0, $addcombojs=0)
Build a HTML select list of element of same thirdparty to suggest to link them to project.
selectInvoiceAndLine($selectedInvoiceId=0, $selectedLineId=0, $htmlNameInvoice='invoiceid', $htmlNameInvoiceLine='invoicelineid', $morecss='maxwidth500', $filters=array(), $lineOnly=0)
Output a combo list with invoices and lines qualified for a project.
formOpportunityStatus($page, $selected='', $percent_value=0, $htmlname_status='none', $htmlname_percent='none', $filter='', $nooutput=0)
Output html select to select opportunity status.
__construct($db)
Constructor.
Class to manage projects.
const STATUS_CLOSED
Closed status.
const STATUS_DRAFT
Draft status.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79