dolibarr 19.0.3
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 *
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
26require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
27
31class FormProjets extends Form
32{
36 public $db;
37
41 public $error = '';
42
43 public $errors = array();
44
45
46 public $nboftasks;
47
48
54 public function __construct($db)
55 {
56 $this->db = $db;
57 }
58
59 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
60
82 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 = '')
83 {
84 // phpcs:enable
85 global $langs, $conf, $form;
86
87 $selected_input_value = '';
88 if (is_object($selected)) {
89 $selected_input_value = $selected->ref;
90 $selected = $selected->id;
91 }
92
93 $out = '';
94
95 if (!empty($conf->use_javascript_ajax) && getDolGlobalString('PROJECT_USE_SEARCH_TO_SELECT')) {
96 $placeholder = '';
97
98 if ($selected && empty($selected_input_value)) {
99 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
100 $project = new Project($this->db);
101 $project->fetch($selected);
102 $selected_input_value = $project->ref;
103 }
104 $urloption = 'socid=' . ((int) $socid) . '&htmlname=' . urlencode($htmlname) . '&discardclosed=' . ((int) $discard_closed);
105 if ($morefilter == 'usage_organize_event=1') {
106 $urloption .= '&usage_organize_event=1';
107 }
108 $out .= '<input type="text" class="minwidth200' . ($morecss ? ' ' . $morecss : '') . '" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' />';
109
110 $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array());
111 } else {
112 $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);
113 }
114 if ($discard_closed > 0) {
115 if (!empty($form)) {
116 $out .= $form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
117 }
118 }
119
120 if (empty($nooutput)) {
121 print $out;
122 return '';
123 } else {
124 return $out;
125 }
126 }
127
128 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
129
151 public function select_projects_list($socid = -1, $selected = '', $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 = '')
152 {
153 // phpcs:enable
154 global $user, $conf, $langs;
155
156 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
157
158 if (empty($htmlid)) {
159 $htmlid = $htmlname;
160 }
161
162 $out = '';
163 $outarray = array();
164
165 $hideunselectables = false;
166 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES')) {
167 $hideunselectables = true;
168 }
169
170 $projectsListId = false;
171 if (!$user->hasRight('projet', 'all', 'lire')) {
172 $projectstatic = new Project($this->db);
173 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
174 }
175
176 // Search all projects
177 $sql = "SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias";
178 $sql .= " FROM " . $this->db->prefix() . "projet as p LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc";
179 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
180 if ($projectsListId !== false) {
181 $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")";
182 }
183 if ($socid == 0) {
184 $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
185 }
186 if ($socid > 0) {
187 if (!getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY')) {
188 $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)";
189 } 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.
190 $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)";
191 }
192 }
193 if (!empty($filterkey)) {
194 $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
195 }
196 if ($morefilter) {
197 $sql .= ' AND (' . $this->db->sanitize($morefilter, 0, 1) . ')';
198 }
199 $sql .= " ORDER BY p.ref ASC";
200
201 $resql = $this->db->query($sql);
202 if ($resql) {
203 if (!empty($conf->use_javascript_ajax)) {
204 $morecss .= ' minwidth100';
205 }
206 if (empty($option_only)) {
207 $out .= '<select class="flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlid . '" name="' . $htmlname . '">';
208 }
209 if (!empty($show_empty)) {
210 if (is_numeric($show_empty)) {
211 $out .= '<option value="0">&nbsp;</option>';
212 } else {
213 $out .= '<option value="-1">'.$show_empty.'</option>';
214 }
215 }
216 $num = $this->db->num_rows($resql);
217 $i = 0;
218 if ($num) {
219 while ($i < $num) {
220 $obj = $this->db->fetch_object($resql);
221 // 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.
222 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
223 // Do nothing
224 } else {
225 if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) { // We discard closed except if selected
226 $i++;
227 continue;
228 }
229
230 $labeltoshow = dol_trunc($obj->ref, 18);
231 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
232 //else $labeltoshow.=' ('.$langs->trans("Private").')';
233 $labeltoshow .= ', ' . dol_trunc($obj->title, $maxlength);
234 if ($obj->name) {
235 $labeltoshow .= ' - ' . $obj->name;
236 if ($obj->name_alias) {
237 $labeltoshow .= ' (' . $obj->name_alias . ')';
238 }
239 }
240
241 $disabled = 0;
242 if ($obj->fk_statut == 0) {
243 $disabled = 1;
244 $labeltoshow .= ' - ' . $langs->trans("Draft");
245 } elseif ($obj->fk_statut == 2) {
246 if ($discard_closed == 2) {
247 $disabled = 1;
248 }
249 $labeltoshow .= ' - ' . $langs->trans("Closed");
250 } elseif (!getDolGlobalString('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY') && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
251 $disabled = 1;
252 $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany");
253 }
254
255 if (!empty($selected) && $selected == $obj->rowid) {
256 $out .= '<option value="' . $obj->rowid . '" selected';
257 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
258 $out .= '>' . $labeltoshow . '</option>';
259 } else {
260 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
261 $resultat = '';
262 } else {
263 $resultat = '<option value="' . $obj->rowid . '"';
264 if ($disabled) {
265 $resultat .= ' disabled';
266 }
267 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
268 //else $labeltoshow.=' ('.$langs->trans("Private").')';
269 $resultat .= '>';
270 $resultat .= $labeltoshow;
271 $resultat .= '</option>';
272 }
273 $out .= $resultat;
274
275 $outarray[] = array(
276 'key' => (int) $obj->rowid,
277 'value' => $obj->ref,
278 'ref' => $obj->ref,
279 'labelx' => $labeltoshow,
280 'label' => ($disabled ? '<span class="opacitymedium">' . $labeltoshow . '</span>' : $labeltoshow),
281 'disabled' => (bool) $disabled
282 );
283 }
284 }
285 $i++;
286 }
287 }
288
289 $this->db->free($resql);
290
291 if (!$mode) {
292 if (empty($option_only)) {
293 $out .= '</select>';
294 }
295
296 // Use select2 selector
297 if (!empty($conf->use_javascript_ajax)) {
298 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
299 $comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
300 $out .= $comboenhancement;
301 $morecss .= ' minwidth100';
302 }
303
304 if (empty($nooutput)) {
305 print $out;
306 return '';
307 } else {
308 return $out;
309 }
310 } else {
311 return $outarray;
312 }
313 } else {
314 dol_print_error($this->db);
315 return -1;
316 }
317 }
318
337 public function selectTasks($socid = -1, $selected = '', $htmlname = 'taskid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showmore = 'all', $usertofilter = null)
338 {
339 global $user, $conf, $langs;
340
341 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
342
343 if (is_null($usertofilter)) {
344 $usertofilter = $user;
345 }
346
347 $out = '';
348
349 $hideunselectables = false;
350 if (getDolGlobalString('PROJECT_HIDE_UNSELECTABLES')) {
351 $hideunselectables = true;
352 }
353
354 if (empty($projectsListId)) {
355 if (!$usertofilter->hasRight('projet', 'all', 'lire')) {
356 $projectstatic = new Project($this->db);
357 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
358 }
359 }
360
361 // Search all projects
362 $sql = "SELECT t.rowid, t.ref as tref, t.label as tlabel, t.progress,";
363 $sql .= " p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, p.usage_task,";
364 $sql .= " s.nom as name";
365 $sql .= " FROM " . $this->db->prefix() . "projet as p";
366 $sql .= " LEFT JOIN " . $this->db->prefix() . "societe as s ON s.rowid = p.fk_soc,";
367 $sql .= " " . $this->db->prefix() . "projet_task as t";
368 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
369 $sql .= " AND t.fk_projet = p.rowid";
370 if ($projectsListId) {
371 $sql .= " AND p.rowid IN (" . $this->db->sanitize($projectsListId) . ")";
372 }
373 if ($socid == 0) {
374 $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
375 }
376 if ($socid > 0) {
377 $sql .= " AND (p.fk_soc=" . ((int) $socid) . " OR p.fk_soc IS NULL)";
378 }
379 $sql .= " ORDER BY p.ref, t.ref ASC";
380
381 $resql = $this->db->query($sql);
382 if ($resql) {
383 // Use select2 selector
384 if (empty($option_only) && !empty($conf->use_javascript_ajax)) {
385 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
386 $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
387 $out .= $comboenhancement;
388 $morecss .= ' minwidth150imp';
389 }
390
391 if (empty($option_only)) {
392 $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled="disabled"' : '') . ' id="' . $htmlname . '" name="' . $htmlname . '">';
393 }
394 if (!empty($show_empty)) {
395 $out .= '<option value="0" class="optiongrey">';
396 if (!is_numeric($show_empty)) {
397 //if (!empty($conf->use_javascript_ajax)) $out .= '<span class="opacitymedium">aaa';
398 $out .= $show_empty;
399 //if (!empty($conf->use_javascript_ajax)) $out .= '</span>';
400 } else {
401 $out .= '&nbsp;';
402 }
403 $out .= '</option>';
404 }
405
406 $num = $this->db->num_rows($resql);
407 $i = 0;
408 if ($num) {
409 while ($i < $num) {
410 $obj = $this->db->fetch_object($resql);
411 // 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.
412 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$usertofilter->hasRight('societe', 'lire')) {
413 // Do nothing
414 } else {
415 if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
416 $i++;
417 continue;
418 }
419
420 $labeltoshow = '';
421 $titletoshow = '';
422
423 $disabled = 0;
424 if ($obj->fk_statut == Project::STATUS_DRAFT) {
425 $disabled = 1;
426 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
427 if ($discard_closed == 2) {
428 $disabled = 1;
429 }
430 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
431 $disabled = 1;
432 }
433
434 if (preg_match('/all/', $showmore)) {
435 $labeltoshow .= dol_trunc($obj->ref, 18); // Project ref
436 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
437 //else $labeltoshow.=' ('.$langs->trans("Private").')';
438 $labeltoshow .= ' ' . dol_trunc($obj->title, $maxlength);
439 $titletoshow = $labeltoshow;
440
441 if ($obj->name) {
442 $labeltoshow .= ' (' . $obj->name . ')';
443 $titletoshow .= ' <span class="opacitymedium">(' . $obj->name . ')</span>';
444 }
445
446 $disabled = 0;
447 if ($obj->fk_statut == Project::STATUS_DRAFT) {
448 $disabled = 1;
449 $labeltoshow .= ' - ' . $langs->trans("Draft");
450 $titletoshow .= ' - <span class="opacitymedium">' . $langs->trans("Draft") . '</span>';
451 } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
452 if ($discard_closed == 2) {
453 $disabled = 1;
454 }
455 $labeltoshow .= ' - ' . $langs->trans("Closed");
456 $titletoshow .= ' - <span class="opacitymedium">' . $langs->trans("Closed") . '</span>';
457 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
458 $disabled = 1;
459 $labeltoshow .= ' - ' . $langs->trans("LinkedToAnotherCompany");
460 $titletoshow .= ' - <span class="opacitymedium">' . $langs->trans("LinkedToAnotherCompany") . '</span>';
461 }
462 $labeltoshow .= ' - ';
463 $titletoshow .= ' - ';
464 }
465
466 // Label for task
467 $labeltoshow .= $obj->tref . ' ' . dol_trunc($obj->tlabel, $maxlength);
468 $titletoshow .= $obj->tref . ' ' . dol_trunc($obj->tlabel, $maxlength);
469 if ($obj->usage_task && preg_match('/progress/', $showmore)) {
470 $labeltoshow .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>';
471 $titletoshow .= ' <span class="opacitymedium">(' . $obj->progress . '%)</span>';
472 }
473
474 if (!empty($selected) && $selected == $obj->rowid) {
475 $out .= '<option value="' . $obj->rowid . '" selected';
476 $out .= ' data-html="' . dol_escape_htmltag($titletoshow) . '"';
477 //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
478 $out .= '>' . $labeltoshow . '</option>';
479 } else {
480 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
481 $resultat = '';
482 } else {
483 $resultat = '<option value="' . $obj->rowid . '"';
484 if ($disabled) {
485 $resultat .= ' disabled';
486 }
487 //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
488 //else $labeltoshow.=' ('.$langs->trans("Private").')';
489 $resultat .= ' data-html="' . dol_escape_htmltag($titletoshow) . '"';
490 $resultat .= '>';
491 $resultat .= $labeltoshow;
492 $resultat .= '</option>';
493 }
494 $out .= $resultat;
495 }
496 }
497 $i++;
498 }
499 }
500 if (empty($option_only)) {
501 $out .= '</select>';
502 }
503
504 $this->nboftasks = $num;
505
506 print $out;
507
508 $this->db->free($resql);
509 return $num;
510 } else {
511 dol_print_error($this->db);
512 return -1;
513 }
514 }
515
516
517 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
518
530 public function select_element($table_element, $socid = 0, $morecss = '', $limitonstatus = -2, $projectkey = "fk_projet", $placeholder = '')
531 {
532 // phpcs:enable
533 global $conf, $langs;
534
535 if ($table_element == 'projet_task') {
536 return ''; // Special cas of element we never link to a project (already always done)
537 }
538
539 $linkedtothirdparty = false;
540 if (!in_array(
541 $table_element,
542 array(
543 'don',
544 'expensereport_det',
545 'expensereport', 'loan',
546 'stock_mouvement',
547 'payment_salary',
548 'payment_various',
549 'salary',
550 'chargesociales',
551 'entrepot')
552 )) {
553 $linkedtothirdparty = true;
554 }
555
556 $sqlfilter = '';
557
558 //print $table_element;
559 switch ($table_element) {
560 case "loan":
561 $sql = "SELECT t.rowid, t.label as ref";
562 break;
563 case "facture":
564 $sql = "SELECT t.rowid, t.ref as ref";
565 break;
566 case "facture_fourn":
567 $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
568 break;
569 case "commande_fourn":
570 case "commande_fournisseur":
571 $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
572 break;
573 case "facture_rec":
574 $sql = "SELECT t.rowid, t.titre as ref";
575 break;
576 case "actioncomm":
577 $sql = "SELECT t.id as rowid, t.label as ref";
578 $projectkey = "fk_project";
579 break;
580 case "expensereport":
581 return '';
582 case "expensereport_det":
583 /*$sql = "SELECT rowid, '' as ref"; // table is llx_expensereport_det
584 $projectkey="fk_projet";
585 break;*/
586 return '';
587 case "commande":
588 case "contrat":
589 case "fichinter":
590 $sql = "SELECT t.rowid, t.ref";
591 break;
592 case 'stock_mouvement':
593 $sql = "SELECT t.rowid, t.label as ref";
594 $projectkey = 'fk_origin';
595 break;
596 case "payment_salary":
597 $sql = "SELECT t.rowid, t.num_payment as ref"; // TODO In a future fill and use real ref field
598 break;
599 case "payment_various":
600 $sql = "SELECT t.rowid, t.num_payment as ref";
601 break;
602 case "chargesociales":
603 default:
604 $sql = "SELECT t.rowid, t.ref";
605 break;
606 }
607 if ($linkedtothirdparty) {
608 $sql .= ", s.nom as name";
609 }
610 $sql .= " FROM " . $this->db->prefix() . $table_element . " as t";
611 if ($linkedtothirdparty) {
612 $sql .= ", " . $this->db->prefix() . "societe as s";
613 }
614 $sql .= " WHERE " . $projectkey . " is null";
615 if (!empty($socid) && $linkedtothirdparty) {
616 if (is_numeric($socid)) {
617 $sql .= " AND t.fk_soc = " . ((int) $socid);
618 } else {
619 $sql .= " AND t.fk_soc IN (" . $this->db->sanitize($socid) . ")";
620 }
621 }
622 if (!in_array($table_element, array('expensereport_det', 'stock_mouvement'))) {
623 $sql .= ' AND t.entity IN (' . getEntity('project') . ')';
624 }
625 if ($linkedtothirdparty) {
626 $sql .= " AND s.rowid = t.fk_soc";
627 }
628 if ($sqlfilter) {
629 $sql .= " AND " . $sqlfilter;
630 }
631 $sql .= " ORDER BY ref DESC";
632
633 dol_syslog(get_class($this) . '::select_element', LOG_DEBUG);
634 $resql = $this->db->query($sql);
635 if ($resql) {
636 $num = $this->db->num_rows($resql);
637 $i = 0;
638 $sellist = '';
639
640 if ($num > 0) {
641 $sellist = '<select class="flat elementselect css' . $table_element . ($morecss ? ' ' . $morecss : '') . '" name="elementselect">';
642 $sellist .= '<option value="-1"' . ($placeholder ? ' class="optiongrey"' : '') . '>' . $placeholder . '</option>';
643 while ($i < $num) {
644 $obj = $this->db->fetch_object($resql);
645 $ref = $obj->ref ? $obj->ref : $obj->rowid;
646 if (!empty($obj->ref_supplier)) {
647 $ref .= ' (' . $obj->ref_supplier . ')';
648 }
649 if (!empty($obj->name)) {
650 $ref .= ' - ' . $obj->name;
651 }
652 $sellist .= '<option value="' . $obj->rowid . '">' . $ref . '</option>';
653 $i++;
654 }
655 $sellist .= '</select>';
656 }
657 /*else
658 {
659 $sellist = '<select class="flat" name="elementselect">';
660 $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
661 $sellist.= '</select>';
662 }*/
663 $this->db->free($resql);
664
665 return $sellist;
666 } else {
667 dol_print_error($this->db);
668 $this->error = $this->db->lasterror();
669 $this->errors[] = $this->db->lasterror();
670 dol_syslog(get_class($this) . "::select_element " . $this->error, LOG_ERR);
671 return -1;
672 }
673 }
674
675
690 public function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '', $noadmininfo = 0, $addcombojs = 0)
691 {
692 global $conf, $langs, $user;
693
694 $sql = "SELECT rowid, code, label, percent";
695 $sql .= " FROM " . $this->db->prefix() . 'c_lead_status';
696 $sql .= " WHERE active = 1";
697 $sql .= " ORDER BY position";
698
699 $resql = $this->db->query($sql);
700 if ($resql) {
701 $num = $this->db->num_rows($resql);
702 $i = 0;
703 if ($num > 0) {
704 $sellist = '<select class="flat oppstatus' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlname . '" name="' . $htmlname . '">';
705 if ($showempty) {
706 // Without &nbsp, strange move of screen when switching value
707 $sellist .= '<option value="-1">&nbsp;</option>';
708 }
709 if ($showallnone) {
710 $sellist .= '<option value="all"' . ($preselected == 'all' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OnlyOpportunitiesShort") . '</option>';
711 $sellist .= '<option value="openedopp"' . ($preselected == 'openedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("OpenedOpportunitiesShort") . '</option>';
712 $sellist .= '<option value="notopenedopp"' . ($preselected == 'notopenedopp' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotOpenedOpportunitiesShort") . '</option>';
713 $sellist .= '<option value="none"' . ($preselected == 'none' ? ' selected="selected"' : '') . '>-- ' . $langs->trans("NotAnOpportunityShort") . '</option>';
714 }
715 while ($i < $num) {
716 $obj = $this->db->fetch_object($resql);
717
718 $sellist .= '<option value="' . $obj->rowid . '" defaultpercent="' . $obj->percent . '" elemcode="' . $obj->code . '"';
719 if ($obj->rowid == $preselected) {
720 $sellist .= ' selected="selected"';
721 }
722 $sellist .= '>';
723 if ($useshortlabel) {
724 $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label);
725 } else {
726 $finallabel = ($langs->transnoentitiesnoconv("OppStatus" . $obj->code) != "OppStatus" . $obj->code ? $langs->transnoentitiesnoconv("OppStatus" . $obj->code) : $obj->label);
727 if ($showpercent) {
728 $finallabel .= ' (' . $obj->percent . '%)';
729 }
730 }
731 $sellist .= $finallabel;
732 $sellist .= '</option>';
733 $i++;
734 }
735 $sellist .= '</select>';
736
737 if ($user->admin && !$noadmininfo) {
738 $sellist .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
739 }
740
741 if ($addcombojs) {
742 $sellist .= ajax_combobox($htmlname);
743 }
744 }
745 /*else
746 {
747 $sellist = '<select class="flat" name="elementselect">';
748 $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
749 $sellist.= '</select>';
750 }*/
751 $this->db->free($resql);
752
753 return $sellist;
754 } else {
755 $this->error = $this->db->lasterror();
756 $this->errors[] = $this->db->lasterror();
757 dol_syslog(get_class($this) . "::selectOpportunityStatus " . $this->error, LOG_ERR);
758 return -1;
759 }
760 }
761
770 public function selectProjectsStatus($selected = '', $short = 0, $hmlname = 'order_status')
771 {
772 $options = array();
773
774 // 7 is same label than 6. 8 does not exists (billed is another field)
775 $statustohow = array(
776 '0' => '0',
777 '1' => '1',
778 '2' => '2',
779 );
780
781 $tmpproject = new Project($this->db);
782
783 foreach ($statustohow as $key => $value) {
784 $tmpproject->statut = $key;
785 $options[$value] = $tmpproject->getLibStatut($short);
786 }
787
788 if (is_array($selected)) {
789 $selectedarray = $selected;
790 } elseif ($selected == 99) {
791 $selectedarray = array(0,1);
792 } else {
793 $selectedarray = explode(',', $selected);
794 }
795
796 print Form::multiselectarray($hmlname, $options, $selectedarray, 0, 0, 'minwidth100');
797 }
798
811 public function selectInvoiceAndLine($selectedInvoiceId = 0, $selectedLineId = 0, $htmlNameInvoice = 'invoiceid', $htmlNameInvoiceLine = 'invoicelineid', $morecss = 'maxwidth500', $filters = array(), $lineOnly = 0)
812 {
813 global $user, $conf, $langs;
814
815 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
816
817 $out = '';
818 if (empty($lineOnly)) {
819 // Search Invoice
820 $sql = "SELECT f.rowid, f.ref as fref,";
821 $sql .= ' s.nom as name';
822 $sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
823 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
824 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
825 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
826 if (!empty($filters)) {
827 foreach ($filters as $key => $value) {
828 if ($key == 'p.rowid') {
829 $sql .= " AND p.rowid=" . (int) $value;
830 }
831 if ($key == 'f.rowid') {
832 $sql .= " AND f.rowid=" . (int) $value;
833 }
834 }
835 }
836 $sql .= " ORDER BY p.ref, f.ref ASC";
837
838 $resql = $this->db->query($sql);
839 if ($resql) {
840 // Use select2 selector
841 if (!empty($conf->use_javascript_ajax)) {
842 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
843 $comboenhancement = ajax_combobox($htmlNameInvoice, array(array('method'=>'getLines', 'url'=>dol_buildpath('/core/ajax/ajaxinvoiceline.php', 1), 'htmlname'=>$htmlNameInvoiceLine)), 0, 0);
844 $out .= $comboenhancement;
845 $morecss = 'minwidth200imp maxwidth500';
846 }
847
848 $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoice . '" name="' . $htmlNameInvoice . '">';
849 $num = $this->db->num_rows($resql);
850 if ($num) {
851 while ($obj = $this->db->fetch_object($resql)) {
852 $labeltoshow = $obj->fref; // Invoice ref
853 if ($obj->name) {
854 $labeltoshow .= ' - ' . $obj->name;
855 }
856
857 $out .= '<option value="' . $obj->rowid . '" ';
858 if (!empty($selectedInvoiceId) && $selectedInvoiceId == $obj->rowid) {
859 $out .= ' selected ';
860 }
861 $out .= '>' . $labeltoshow . '</option>';
862 }
863 }
864 $out .= '</select>';
865 } else {
866 dol_print_error($this->db->lasterror);
867 return '';
868 }
869 }
870
871 // Search Invoice Line
872 $sql = "SELECT fd.rowid, fd.label, fd.description";
873 $sql .= ' FROM ' . $this->db->prefix() . 'projet as p';
874 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'societe as s ON s.rowid = p.fk_soc';
875 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facture as f ON f.fk_projet = p.rowid';
876 $sql .= ' INNER JOIN ' . $this->db->prefix() . 'facturedet as fd ON fd.fk_facture = f.rowid';
877 $sql .= " WHERE p.entity IN (" . getEntity('project') . ")";
878 if (!empty($filters)) {
879 foreach ($filters as $key => $value) {
880 if ($key == 'p.rowid') {
881 $sql .= " AND p.rowid=" . (int) $value;
882 }
883 }
884 }
885 if (!empty($selectedInvoiceId)) {
886 $sql .= " AND f.rowid=" . (int) $selectedInvoiceId;
887 }
888 $sql .= " ORDER BY p.ref, f.ref ASC";
889 $resql = $this->db->query($sql);
890 if ($resql) {
891 // Use select2 selector
892 if (empty($lineOnly)) {
893 if (!empty($conf->use_javascript_ajax)) {
894 include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
895 $comboenhancement = ajax_combobox($htmlNameInvoiceLine, '', 0, 0);
896 $out .= $comboenhancement;
897 $morecss = 'minwidth200imp maxwidth500';
898 }
899
900 $out .= '<select class="valignmiddle flat' . ($morecss ? ' ' . $morecss : '') . '" id="' . $htmlNameInvoiceLine . '" name="' . $htmlNameInvoiceLine . '">';
901 }
902 $num = $this->db->num_rows($resql);
903 if ($num) {
904 while ($obj = $this->db->fetch_object($resql)) {
905 $labeltoshow .= $obj->description; // Invoice ref
906
907 $out .= '<option value="' . $obj->rowid . '" ';
908 if (!empty($selectedLineId) && $selectedLineId == $obj->rowid) {
909 $out .= ' selected ';
910 }
911 $out .= '>' . $labeltoshow . '</option>';
912 }
913 }
914 if (empty($lineOnly)) {
915 $out .= '</select>';
916 }
917 } else {
918 dol_print_error($this->db->lasterror);
919 return '';
920 }
921
922 return $out;
923 }
924}
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to a page to transform a common input field into an au...
Definition ajax.lib.php:47
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:455
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.
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 differents status of a orders.
select_projects_list($socid=-1, $selected='', $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.
selectTasks($socid=-1, $selected='', $htmlname='taskid', $maxlength=24, $option_only=0, $show_empty='1', $discard_closed=0, $forcefocus=0, $disabled=0, $morecss='maxwidth500', $projectsListId='', $showmore='all', $usertofilter=null)
Output a combo list with tasks qualified for a third party.
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.
__construct($db)
Constructor.
Class to manage projects.
const STATUS_CLOSED
Closed status.
const STATUS_DRAFT
Draft status.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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 dolibarr global constant string value.
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...