dolibarr 21.0.0-beta
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 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($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, $conf->global->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
158 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 = '')
159 {
160 // phpcs:enable
161 global $user, $conf, $langs;
162
163 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
164
165 if (empty($htmlid)) {
166 $htmlid = $htmlname;
167 }
168
169 $out = '';
170 $outarray = array();
171
172 $hideunselectables = false;
173 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES')) {
174 $hideunselectables = true;
175 }
176 if (getDolGlobalInt('PROJECT_ALWAYS_DISCARD_CLOSED_PROJECTS_IN_SELECT')) {
177 $discard_closed = 1;
178 }
179
180 $projectsListId = false;
181 if (!$user->hasRight('projet', 'all', 'lire')) {
182 $projectstatic = new Project($this->db);
183 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
184 }
185
186 // Search all projects
187 $sql = "SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias";
188 $sql .= " FROM " . $this->db->prefix() . "projet as p LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
189 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
190 if ($projectsListId !== false) {
191 $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")";
192 }
193 if ($socid == 0) {
194 $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
195 }
196 if ($socid > 0) {
197 if (!getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) {
198 $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)";
199 } 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.
200 $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)";
201 }
202 }
203 if (!empty($filterkey)) {
204 $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
205 }
206 if ($morefilter) {
207 $sql .= ' AND (' . $this->db->sanitize($morefilter, 0, 1) . ')';
208 }
209 $sql .= " ORDER BY p.ref ASC";
210
211 $resql = $this->db->query($sql);
212 if ($resql) {
213 if (!empty($conf->use_javascript_ajax)) {
214 $morecss .= ' minwidth100';
215 }
216 if (empty($option_only)) {
217 $out .= '<select class="flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlid . '" name="' . $htmlname . '">';
218 }
219 if (!empty($show_empty)) {
220 if (is_numeric($show_empty)) {
221 $out .= '<option value="0">&nbsp;</option>';
222 } else {
223 $out .= '<option value="-1">'.$show_empty.'</option>';
224 }
225 }
226 $num = $this->db->num_rows($resql);
227 $i = 0;
228 if ($num) {
229 while ($i < $num) {
230 $obj = $this->db->fetch_object($resql);
231 // 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.
232 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
233 // Do nothing
234 } else {
235 if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) { // We discard closed except if selected
236 $i++;
237 continue;
238 }
239
240 $labeltoshow = dol_trunc($obj->ref, 18);
241 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
242 //else $labeltoshow.=' ('.$langs->trans("Private").')';
243 $labeltoshow .= ', ' . dol_trunc($obj->title, $maxlength);
244 if ($obj->name) {
245 $labeltoshow .= ' - ' . $obj->name;
246 if ($obj->name_alias) {
247 $labeltoshow .= ' (' . $obj->name_alias . ')';
248 }
249 }
250
251 $disabled = 0;
252 if ($obj->fk_statut == 0) {
253 $disabled = 1;
254 $labeltoshow .= ' - ' . $langs->trans("Draft");
255 } elseif ($obj->fk_statut == 2) {
256 if ($discard_closed == 2) {
257 $disabled = 1;
258 }
259 $labeltoshow .= ' - ' . $langs->trans("Closed");
260 } elseif (!getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
261 $disabled = 1;
262 $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany");
263 }
264
265 if (!empty($selected) && $selected == $obj->rowid) {
266 $out .= '<option value="' . $obj->rowid . '" selected';
267 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
268 $out .= '>' . $labeltoshow . '</option>';
269 } else {
270 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
271 $resultat = '';
272 } else {
273 $resultat = '<option value="' . $obj->rowid . '"';
274 if ($disabled) {
275 $resultat .= ' disabled';
276 }
277 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
278 //else $labeltoshow.=' ('.$langs->trans("Private").')';
279 $resultat .= '>';
280 $resultat .= $labeltoshow;
281 $resultat .= '</option>';
282 }
283 $out .= $resultat;
284
285 $outarray[] = array(
286 'key' => (int) $obj->rowid,
287 'value' => $obj->ref,
288 'ref' => $obj->ref,
289 'labelx' => $labeltoshow,
290 'label' => ($disabled ? '<span class="opacitymedium">' . $labeltoshow . '</span>' : $labeltoshow),
291 'disabled' => (bool) $disabled
292 );
293 }
294 }
295 $i++;
296 }
297 }
298
299 $this->db->free($resql);
300
301 if (!$mode) {
302 if (empty($option_only)) {
303 $out .= '</select>';
304 }
305
306 // Use select2 selector
307 if (!empty($conf->use_javascript_ajax)) {
308 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
309 $comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
310 $out .= $comboenhancement;
311 $morecss .= ' minwidth100';
312 }
313
314 if (empty($nooutput)) {
315 print $out;
316 return '';
317 } else {
318 return $out;
319 }
320 } else {
321 return $outarray;
322 }
323 } else {
324 dol_print_error($this->db);
325 return -1;
326 }
327 }
328
349 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)
350 {
351 global $user, $conf, $langs;
352
353 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
354
355 if (is_null($usertofilter)) {
356 $usertofilter = $user;
357 }
358
359 $out = '';
360
361 $hideunselectables = false;
362 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES')) {
363 $hideunselectables = true;
364 }
365
366 if (empty($projectsListId)) {
367 if (!$usertofilter->hasRight('projet', 'all', 'lire')) {
368 $projectstatic = new Project($this->db);
369 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
370 }
371 }
372
373 // Search all projects
374 $sql = "SELECT t.rowid, t.ref as tref, t.label as tlabel, t.progress,";
375 $sql .= " p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, p.usage_task,";
376 $sql .= " s.nom as name";
377 $sql .= " FROM " . $this->db->prefix() . "projet as p";
378 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc,";
379 $sql .= " " . $this->db->prefix() . "projet_task as t";
380 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
381 $sql .= " AND t.fk_projet = p.rowid";
382 if ($projectsListId) {
383 $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")";
384 }
385 if ($socid == 0) {
386 $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
387 }
388 if ($socid > 0) {
389 $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)";
390 }
391 $sql .= " ORDER BY p.ref, t.ref ASC";
392
393 $resql = $this->db->query($sql);
394 if ($resql) {
395 // Use select2 selector
396 if (empty($option_only) && !empty($conf->use_javascript_ajax)) {
397 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
398 $comboenhancement = ajax_combobox($htmlname, [], 0, $forcefocus);
399 $out .= $comboenhancement;
400 $morecss .= ' minwidth150imp';
401 }
402
403 if (empty($option_only)) {
404 $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlname . '" name="' . $htmlname . '">';
405 }
406 if (!empty($show_empty)) {
407 $out .= '<option value="0" class="optiongrey">';
408 if (!is_numeric($show_empty)) {
409 //if (!empty($conf->use_javascript_ajax)) $out .= '<span class="opacitymedium">';
410 $out .= $show_empty;
411 //if (!empty($conf->use_javascript_ajax)) $out .= '</span>';
412 } else {
413 $out .= '&nbsp;';
414 }
415 $out .= '</option>';
416 }
417
418 $num = $this->db->num_rows($resql);
419 $i = 0;
420 if ($num) {
421 while ($i < $num) {
422 $obj = $this->db->fetch_object($resql);
423 // 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.
424 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe', 'lire')) {
425 // Do nothing
426 } else {
427 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
428 $i++;
429 continue;
430 }
431
432 $labeltoshow = '';
433 $labeltoshowhtml = '';
434
435 $disabled = 0;
436 if ($obj->fk_statut == Project::STATUS_DRAFT) {
437 $disabled = 1;
438 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
439 if ($discard_closed == 2) {
440 $disabled = 1;
441 }
442 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
443 $disabled = 1;
444 }
445
446 if (preg_match('/all/', $showmore)) {
447 $labeltoshow .= dol_trunc($obj->ref, 18); // Project ref
448 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
449 //else $labeltoshow.=' ('.$langs->trans("Private").')';
450 $labeltoshow .= ' ' . dol_trunc($obj->title, $maxlength);
451 $labeltoshowhtml = $labeltoshow;
452
453 if ($obj->name) {
454 $labeltoshow .= ' (' . $obj->name . ')';
455 $labeltoshowhtml .= ' <span class="opacitymedium">(' . $obj->name . ')</span>';
456 }
457
458 $disabled = 0;
459 if ($obj->fk_statut == Project::STATUS_DRAFT) {
460 $disabled = 1;
461 $labeltoshow .= ' - ' . $langs->trans("Draft");
462 $labeltoshowhtml .= ' - <span class="opacitymedium">' . $langs->trans("Draft") . '</span>';
463 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
464 if ($discard_closed == 2) {
465 $disabled = 1;
466 }
467 $labeltoshow .= ' - ' . $langs->trans("Closed");
468 $labeltoshowhtml .= ' - <span class="opacitymedium">' . $langs->trans("Closed") . '</span>';
469 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
470 $disabled = 1;
471 $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany");
472 $labeltoshowhtml .= ' - <span class="opacitymedium">' . $langs->trans("LinkedToAnotherCompany") . '</span>';
473 }
474 $labeltoshow .= ' - ';
475 $labeltoshowhtml .= ' - ';
476 }
477
478 // Label for task
479 $labeltoshow .= $obj->tref . ' ' . dol_trunc($obj->tlabel, $maxlength);
480 $labeltoshowhtml .= $obj->tref . ' - ' . dol_trunc($obj->tlabel, $maxlength);
481 if ($obj->usage_task && preg_match('/progress/', $showmore)) {
482 $labeltoshow .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>';
483 $labeltoshowhtml .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>';
484 }
485
486 if (!empty($selected) && $selected == $obj->rowid) {
487 $out .= '<option value="' . $obj->rowid . '" selected';
488 $out .= ' data-html="' . dol_escape_htmltag($labeltoshowhtml) . '"';
489 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
490 $out .= '>' . $labeltoshow . '</option>';
491 } else {
492 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
493 $resultat = '';
494 } else {
495 $resultat = '<option value="' . $obj->rowid . '"';
496 if ($disabled) {
497 $resultat .= ' disabled';
498 }
499 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
500 //else $labeltoshow.=' ('.$langs->trans("Private").')';
501 $resultat .= ' data-html="' . dol_escape_htmltag($labeltoshowhtml) . '"';
502 $resultat .= '>';
503 $resultat .= $labeltoshow;
504 $resultat .= '</option>';
505 }
506 $out .= $resultat;
507 }
508 }
509 $i++;
510 }
511 }
512 if (empty($option_only)) {
513 $out .= '</select>';
514 }
515
516 $this->nboftasks = $num;
517 $this->db->free($resql);
518
519 // Output or return
520 if (empty($nooutput)) {
521 print $out;
522 } else {
523 return $out;
524 }
525
526 return $num;
527 } else {
528 dol_print_error($this->db);
529 return -1;
530 }
531 }
532
533
534 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
535
547 public function select_element($table_element, $socid = 0, $morecss = '', $limitonstatus = -2, $projectkey = "fk_projet", $placeholder = '')
548 {
549 // phpcs:enable
550 global $conf, $langs;
551
552 if ($table_element == 'projet_task') {
553 return ''; // Special case of element we never link to a project (already always done)
554 }
555
556 $linkedtothirdparty = false;
557 if (!in_array(
558 $table_element,
559 array(
560 'don',
561 'expensereport_det',
562 'expensereport', 'loan',
563 'stock_mouvement',
564 'payment_salary',
565 'payment_various',
566 'salary',
567 'chargesociales',
568 'entrepot')
569 )) {
570 $linkedtothirdparty = true;
571 }
572
573 $sqlfilter = '';
574
575 //print $table_element;
576 switch ($table_element) {
577 case "loan":
578 $sql = "SELECT t.rowid, t.label as ref";
579 break;
580 case "facture":
581 $sql = "SELECT t.rowid, t.ref as ref";
582 break;
583 case "facture_fourn":
584 $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
585 break;
586 case "commande_fourn":
587 case "commande_fournisseur":
588 $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
589 break;
590 case "facture_rec":
591 $sql = "SELECT t.rowid, t.titre as ref";
592 break;
593 case "actioncomm":
594 $sql = "SELECT t.id as rowid, t.label as ref";
595 $projectkey = "fk_project";
596 break;
597 case "expensereport":
598 return '';
599 case "expensereport_det":
600 /*$sql = "SELECT rowid, '' as ref"; // table is llx_expensereport_det
601 $projectkey="fk_projet";
602 break;*/
603 return '';
604 case "commande":
605 case "contrat":
606 case "fichinter":
607 $sql = "SELECT t.rowid, t.ref";
608 break;
609 case 'stock_mouvement':
610 $sql = "SELECT t.rowid, t.label as ref";
611 $projectkey = 'fk_origin';
612 break;
613 case "payment_salary":
614 $sql = "SELECT t.rowid, t.num_payment as ref"; // TODO In a future fill and use real ref field
615 break;
616 case "payment_various":
617 $sql = "SELECT t.rowid, t.num_payment as ref";
618 break;
619 case "chargesociales":
620 default:
621 $sql = "SELECT t.rowid, t.ref";
622 break;
623 }
624 if ($linkedtothirdparty) {
625 $sql .= ", s.nom as name";
626 }
627 $sql .= " FROM " . $this->db->prefix() . $table_element . " as t";
628 if ($linkedtothirdparty) {
629 $sql .= ", " . $this->db->prefix() . "societe as s";
630 }
631 $sql .= " WHERE " . $projectkey . " is null";
632 if (!empty($socid) && $linkedtothirdparty) {
633 if (is_numeric($socid)) {
634 $sql .= " AND t.fk_soc = " . ((int) $socid);
635 } else {
636 $sql .= " AND t.fk_soc IN (" . $this->db->sanitize($socid) . ")";
637 }
638 }
639 if (!in_array($table_element, array('expensereport_det', 'stock_mouvement'))) {
640 $sql .= ' AND t.entity IN (' . getEntity('project') . ')';
641 }
642 if ($linkedtothirdparty) {
643 $sql .= " AND s.rowid = t.fk_soc";
644 }
645 if ($sqlfilter) {
646 $sql .= " AND " . $sqlfilter;
647 }
648 $sql .= " ORDER BY ref DESC";
649
650 dol_syslog(get_class($this) . '::select_element', LOG_DEBUG);
651 $resql = $this->db->query($sql);
652 if ($resql) {
653 $num = $this->db->num_rows($resql);
654 $i = 0;
655 $sellist = '';
656
657 if ($num > 0) {
658 $sellist = '<select class="flat elementselect css' . $table_element . ($morecss ? ' ' . $morecss : '') . '" name="elementselect">';
659 $sellist .= '<option value="-1"' . ($placeholder ? ' class="optiongrey"' : '') . '>' . $placeholder . '</option>';
660 while ($i < $num) {
661 $obj = $this->db->fetch_object($resql);
662 $ref = $obj->ref ? $obj->ref : $obj->rowid;
663 if (!empty($obj->ref_supplier)) {
664 $ref .= ' (' . $obj->ref_supplier . ')';
665 }
666 if (!empty($obj->name)) {
667 $ref .= ' - ' . $obj->name;
668 }
669 $sellist .= '<option value="' . $obj->rowid . '">' . $ref . '</option>';
670 $i++;
671 }
672 $sellist .= '</select>';
673 }
674 /*else
675 {
676 $sellist = '<select class="flat" name="elementselect">';
677 $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
678 $sellist.= '</select>';
679 }*/
680 $this->db->free($resql);
681
682 return $sellist;
683 } else {
684 dol_print_error($this->db);
685 $this->error = $this->db->lasterror();
686 $this->errors[] = $this->db->lasterror();
687 dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);
688 return -1;
689 }
690 }
691
692
707 public function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '', $noadmininfo = 0, $addcombojs = 0)
708 {
709 global $conf, $langs, $user;
710
711 $sql = "SELECT rowid, code, label, percent";
712 $sql .= " FROM " . $this->db->prefix() . 'c_lead_status';
713 $sql .= " WHERE active = 1";
714 $sql .= " ORDER BY position";
715
716 $resql = $this->db->query($sql);
717 if ($resql) {
718 $num = $this->db->num_rows($resql);
719 $i = 0;
720 $sellist = '';
721 if ($num > 0) {
722 $sellist = '<select class="flat oppstatus' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlname . '" name="' . $htmlname . '">';
723 if ($showempty) {
724 // Without &nbsp, strange move of screen when switching value
725 $sellist .= '<option value="-1">&nbsp;</option>';
726 }
727 if ($showallnone) {
728 $sellist .= '<option value="all"' . ($preselected == 'all' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OnlyOpportunitiesShort") . '</option>';
729 $sellist .= '<option value="openedopp"' . ($preselected == 'openedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OpenedOpportunitiesShort") . '</option>';
730 $sellist .= '<option value="notopenedopp"' . ($preselected == 'notopenedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotOpenedOpportunitiesShort") . '</option>';
731 $sellist .= '<option value="none"' . ($preselected == 'none' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotAnOpportunityShort") . '</option>';
732 }
733 while ($i < $num) {
734 $obj = $this->db->fetch_object($resql);
735
736 $sellist .= '<option value="' . $obj->rowid . '" defaultpercent="' . $obj->percent . '" elemcode="' . $obj->code . '"';
737 if ($obj->rowid == $preselected) {
738 $sellist .= ' selected="selected"';
739 }
740 $sellist .= '>';
741 if ($useshortlabel) {
742 $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label);
743 } else {
744 $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label);
745 if ($showpercent) {
746 $finallabel .= ' (' . $obj->percent . '%)';
747 }
748 }
749 $sellist .= $finallabel;
750 $sellist .= '</option>';
751 $i++;
752 }
753 $sellist .= '</select>';
754
755 if ($user->admin && !$noadmininfo) {
756 $sellist .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
757 }
758
759 if ($addcombojs) {
760 $sellist .= ajax_combobox($htmlname);
761 }
762 }
763 /*else
764 {
765 $sellist = '<select class="flat" name="elementselect">';
766 $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
767 $sellist.= '</select>';
768 }*/
769 $this->db->free($resql);
770
771 return $sellist;
772 } else {
773 $this->error = $this->db->lasterror();
774 $this->errors[] = $this->db->lasterror();
775 dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR);
776 return -1;
777 }
778 }
779
788 public function selectProjectsStatus($selected = '', $short = 0, $hmlname = 'order_status')
789 {
790 $options = array();
791
792 // 7 is same label than 6. 8 does not exists (billed is another field)
793 $statustohow = array(
794 '0' => '0',
795 '1' => '1',
796 '2' => '2',
797 );
798
799 $tmpproject = new Project($this->db);
800
801 foreach ($statustohow as $key => $value) {
802 $tmpproject->statut = $key;
803 $options[$value] = $tmpproject->getLibStatut($short);
804 }
805
806 if (is_array($selected)) {
807 $selectedarray = $selected;
808 } elseif ($selected == 99) {
809 $selectedarray = array(0,1);
810 } else {
811 $selectedarray = explode(',', $selected);
812 }
813
814 print Form::multiselectarray($hmlname, $options, $selectedarray, 0, 0, 'minwidth100');
815 }
816
829 public function selectInvoiceAndLine($selectedInvoiceId = 0, $selectedLineId = 0, $htmlNameInvoice = 'invoiceid', $htmlNameInvoiceLine = 'invoicelineid', $morecss = 'maxwidth500', $filters = array(), $lineOnly = 0)
830 {
831 global $user, $conf, $langs;
832
833 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
834
835 $out = '';
836 if (empty($lineOnly)) {
837 // Search Invoice
838 $sql = "SELECT f.rowid, f.ref as fref,";
839 $sql .= ' s.nom as name';
840 $sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
841 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
842 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
843 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
844 if (!empty($filters)) {
845 foreach ($filters as $key => $value) {
846 if ($key == 'p.rowid') {
847 $sql .= " AND p.rowid=" . (int) $value;
848 }
849 if ($key == 'f.rowid') {
850 $sql .= " AND f.rowid=" . (int) $value;
851 }
852 }
853 }
854 $sql .= " ORDER BY p.ref, f.ref ASC";
855
856 $resql = $this->db->query($sql);
857 if ($resql) {
858 // Use select2 selector
859 if (!empty($conf->use_javascript_ajax)) {
860 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
861 $comboenhancement = ajax_combobox($htmlNameInvoice, array(array('method' => 'getLines', 'url' => dol_buildpath('/core/ajax/ajaxinvoiceline.php', 1), 'htmlname' => $htmlNameInvoiceLine)), 0, 0);
862 $out .= $comboenhancement;
863 $morecss = 'minwidth200imp maxwidth500';
864 }
865
866 $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoice . '" name="' . $htmlNameInvoice . '">';
867 $num = $this->db->num_rows($resql);
868 if ($num) {
869 while ($obj = $this->db->fetch_object($resql)) {
870 $labeltoshow = $obj->fref; // Invoice ref
871 if ($obj->name) {
872 $labeltoshow .= ' - ' . $obj->name;
873 }
874
875 $out .= '<option value="' . $obj->rowid . '" ';
876 if (!empty($selectedInvoiceId) && $selectedInvoiceId == $obj->rowid) {
877 $out .= ' selected ';
878 }
879 $out .= '>' . $labeltoshow . '</option>';
880 }
881 }
882 $out .= '</select>';
883 } else {
884 dol_print_error($this->db, $this->db->lasterror);
885 return '';
886 }
887 }
888
889 // Search Invoice Line
890 $sql = "SELECT fd.rowid, fd.label, fd.description";
891 $sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
892 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
893 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
894 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facturedet as fd ON fd.fk_facture = f.rowid';
895 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
896 if (!empty($filters)) {
897 foreach ($filters as $key => $value) {
898 if ($key == 'p.rowid') {
899 $sql .= " AND p.rowid=" . (int) $value;
900 }
901 }
902 }
903 if (!empty($selectedInvoiceId)) {
904 $sql .= " AND f.rowid=" . (int) $selectedInvoiceId;
905 }
906 $sql .= " ORDER BY p.ref, f.ref ASC";
907 $resql = $this->db->query($sql);
908 if ($resql) {
909 // Use select2 selector
910 if (empty($lineOnly)) {
911 if (!empty($conf->use_javascript_ajax)) {
912 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
913 $comboenhancement = ajax_combobox($htmlNameInvoiceLine, [], 0, 0);
914 $out .= $comboenhancement;
915 $morecss = 'minwidth200imp maxwidth500';
916 }
917
918 $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoiceLine . '" name="' . $htmlNameInvoiceLine . '">';
919 }
920 $num = $this->db->num_rows($resql);
921 if ($num) {
922 while ($obj = $this->db->fetch_object($resql)) {
923 $labeltoshow .= $obj->description; // Invoice ref
924
925 $out .= '<option value="' . $obj->rowid . '" ';
926 if (!empty($selectedLineId) && $selectedLineId == $obj->rowid) {
927 $out .= ' selected ';
928 }
929 $out .= '>' . $labeltoshow . '</option>';
930 }
931 }
932 if (empty($lineOnly)) {
933 $out .= '</select>';
934 }
935 } else {
936 dol_print_error($this->db, $this->db->lasterror);
937 return '';
938 }
939
940 return $out;
941 }
942
955 public function formOpportunityStatus($page, $selected = '', $percent_value = 0, $htmlname_status = 'none', $htmlname_percent = 'none', $filter = '', $nooutput = 0)
956 {
957 // phpcs:enable
958 global $conf, $langs;
959
960 $out = '';
961 if ($htmlname_status != "none" && $htmlname_percent != 'none') {
962 $out .= '<form method="post" action="' . $page . '">';
963 $out .= '<input type="hidden" name="action" value="set_opp_status">';
964 $out .= '<input type="hidden" name="token" value="' . newToken() . '">';
965 $out .= $this-> selectOpportunityStatus($htmlname_status, $selected, 1, 0, 0, 0, 'minwidth150 inline-block valignmiddle', 1, 1);
966 $out .= ' / <span title="'.$langs->trans("OpportunityProbability").'"> ';
967 $out .= '<input class="width50 right" type="text" id="'.$htmlname_percent.'" name="'.$htmlname_percent.'" title="'.dol_escape_htmltag($langs->trans("OpportunityProbability")).'" value="'.$percent_value.'"> %';
968 $out .= '</span>';
969 $out .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="' . $langs->trans("Modify") . '">';
970 $out .= '</form>';
971 } else {
972 if ($selected > 0) {
973 $code = dol_getIdFromCode($this->db, $selected, 'c_lead_status', 'rowid', 'code');
974 $out .= $langs->trans("OppStatus".$code);
975
976 // Opportunity percent
977 $out .= ' / <span title="'.$langs->trans("OpportunityProbability").'"> ';
978 $out .= price($percent_value, 0, $langs, 1, 0).' %';
979 $out .= '</span>';
980 } else {
981 $out .= "&nbsp;";
982 }
983 }
984
985 if ($nooutput) {
986 return $out;
987 } else {
988 print $out;
989 }
990 }
991}
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:459
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='', $elemtype='', $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, $hmlname='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.
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.
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.
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.
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.
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'.
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