dolibarr  17.0.4
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 
31 {
35  public $db;
36 
40  public $error = '';
41 
42  public $errors = array();
43 
44 
45  public $nboftasks;
46 
47 
53  public function __construct($db)
54  {
55  $this->db = $db;
56  }
57 
58  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
80  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 = '')
81  {
82  // phpcs:enable
83  global $langs, $conf, $form;
84 
85  $selected_input_value = '';
86  if (is_object($selected)) {
87  $selected_input_value = $selected->ref;
88  $selected = $selected->id;
89  }
90 
91  $out = '';
92 
93  if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT)) {
94  $placeholder = '';
95 
96  if ($selected && empty($selected_input_value)) {
97  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
98  $project = new Project($this->db);
99  $project->fetch($selected);
100  $selected_input_value = $project->ref;
101  }
102  $urloption = 'socid='.((int) $socid).'&htmlname='.urlencode($htmlname).'&discardclosed='.((int) $discard_closed);
103  if ($morefilter == 'usage_organize_event=1') {
104  $urloption .= '&usage_organize_event=1';
105  }
106  $out .= '<input type="text" class="minwidth200'.($morecss ? ' '.$morecss : '').'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' />';
107 
108  $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array());
109  } else {
110  $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);
111  }
112  if ($discard_closed > 0) {
113  if (!empty($form)) {
114  $out .= $form->textwithpicto('', $langs->trans("ClosedProjectsAreHidden"));
115  }
116  }
117 
118  if (empty($nooutput)) {
119  print $out;
120  return '';
121  } else {
122  return $out;
123  }
124  }
125 
126  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
148  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 = '')
149  {
150  // phpcs:enable
151  global $user, $conf, $langs;
152 
153  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
154 
155  if (empty($htmlid)) {
156  $htmlid = $htmlname;
157  }
158 
159  $out = '';
160  $outarray = array();
161 
162  $hideunselectables = false;
163  if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
164  $hideunselectables = true;
165  }
166 
167  $projectsListId = false;
168  if (empty($user->rights->projet->all->lire)) {
169  $projectstatic = new Project($this->db);
170  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
171  }
172 
173  // Search all projects
174  $sql = "SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias";
175  $sql .= " FROM ".$this->db->prefix()."projet as p LEFT JOIN ".$this->db->prefix()."societe as s ON s.rowid = p.fk_soc";
176  $sql .= " WHERE p.entity IN (".getEntity('project').")";
177  if ($projectsListId !== false) {
178  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
179  }
180  if ($socid == 0) {
181  $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
182  }
183  if ($socid > 0) {
184  if (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)) {
185  $sql .= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
186  } elseif ($conf->global->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.
187  $sql .= " AND (p.fk_soc IN (".$this->db->sanitize(((int) $socid).", ".$conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY).") OR p.fk_soc IS NULL)";
188  }
189  }
190  if (!empty($filterkey)) {
191  $sql .= natural_search(array('p.title', 'p.ref'), $filterkey);
192  }
193  if ($morefilter) {
194  $sql .= ' AND ('.$this->db->sanitize($morefilter, 0, 1).')';
195  }
196  $sql .= " ORDER BY p.ref ASC";
197 
198  $resql = $this->db->query($sql);
199  if ($resql) {
200  if (!empty($conf->use_javascript_ajax)) {
201  $morecss .= ' minwidth100';
202  }
203  if (empty($option_only)) {
204  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlid.'" name="'.$htmlname.'">';
205  }
206  if (!empty($show_empty)) {
207  $out .= '<option value="0">&nbsp;</option>';
208  }
209  $num = $this->db->num_rows($resql);
210  $i = 0;
211  if ($num) {
212  while ($i < $num) {
213  $obj = $this->db->fetch_object($resql);
214  // 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.
215  if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight('societe', 'lire')) {
216  // Do nothing
217  } else {
218  if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) { // We discard closed except if selected
219  $i++;
220  continue;
221  }
222 
223  $labeltoshow = dol_trunc($obj->ref, 18);
224  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
225  //else $labeltoshow.=' ('.$langs->trans("Private").')';
226  $labeltoshow .= ', '.dol_trunc($obj->title, $maxlength);
227  if ($obj->name) {
228  $labeltoshow .= ' - '.$obj->name;
229  if ($obj->name_alias) {
230  $labeltoshow .= ' ('.$obj->name_alias.')';
231  }
232  }
233 
234  $disabled = 0;
235  if ($obj->fk_statut == 0) {
236  $disabled = 1;
237  $labeltoshow .= ' - '.$langs->trans("Draft");
238  } elseif ($obj->fk_statut == 2) {
239  if ($discard_closed == 2) {
240  $disabled = 1;
241  }
242  $labeltoshow .= ' - '.$langs->trans("Closed");
243  } elseif (empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
244  $disabled = 1;
245  $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
246  }
247 
248  if (!empty($selected) && $selected == $obj->rowid) {
249  $out .= '<option value="'.$obj->rowid.'" selected';
250  //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
251  $out .= '>'.$labeltoshow.'</option>';
252  } else {
253  if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
254  $resultat = '';
255  } else {
256  $resultat = '<option value="'.$obj->rowid.'"';
257  if ($disabled) {
258  $resultat .= ' disabled';
259  }
260  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
261  //else $labeltoshow.=' ('.$langs->trans("Private").')';
262  $resultat .= '>';
263  $resultat .= $labeltoshow;
264  $resultat .= '</option>';
265  }
266  $out .= $resultat;
267 
268  $outarray[] = array(
269  'key' => (int) $obj->rowid,
270  'value' => $obj->ref,
271  'ref' => $obj->ref,
272  'labelx' => $labeltoshow,
273  'label' => ((bool) $disabled) ? '<span class="opacitymedium">'.$labeltoshow.'</span>' : $labeltoshow,
274  'disabled' => (bool) $disabled
275  );
276  }
277  }
278  $i++;
279  }
280  }
281 
282  $this->db->free($resql);
283 
284  if (!$mode) {
285  if (empty($option_only)) {
286  $out .= '</select>';
287  }
288 
289  // Use select2 selector
290  if (!empty($conf->use_javascript_ajax)) {
291  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
292  $comboenhancement = ajax_combobox($htmlid, array(), 0, $forcefocus);
293  $out .= $comboenhancement;
294  $morecss .= ' minwidth100';
295  }
296 
297  if (empty($nooutput)) {
298  print $out;
299  return '';
300  } else {
301  return $out;
302  }
303  } else {
304  return $outarray;
305  }
306  } else {
307  dol_print_error($this->db);
308  return -1;
309  }
310  }
311 
330  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)
331  {
332  global $user, $conf, $langs;
333 
334  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
335 
336  if (is_null($usertofilter)) {
337  $usertofilter = $user;
338  }
339 
340  $out = '';
341 
342  $hideunselectables = false;
343  if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
344  $hideunselectables = true;
345  }
346 
347  if (empty($projectsListId)) {
348  if (empty($usertofilter->rights->projet->all->lire)) {
349  $projectstatic = new Project($this->db);
350  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
351  }
352  }
353 
354  // Search all projects
355  $sql = "SELECT t.rowid, t.ref as tref, t.label as tlabel, t.progress,";
356  $sql .= " p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, p.usage_task,";
357  $sql .= " s.nom as name";
358  $sql .= " FROM ".$this->db->prefix()."projet as p";
359  $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON s.rowid = p.fk_soc,";
360  $sql .= " ".$this->db->prefix()."projet_task as t";
361  $sql .= " WHERE p.entity IN (".getEntity('project').")";
362  $sql .= " AND t.fk_projet = p.rowid";
363  if ($projectsListId) {
364  $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")";
365  }
366  if ($socid == 0) {
367  $sql .= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
368  }
369  if ($socid > 0) {
370  $sql .= " AND (p.fk_soc=".((int) $socid)." OR p.fk_soc IS NULL)";
371  }
372  $sql .= " ORDER BY p.ref, t.ref ASC";
373 
374  $resql = $this->db->query($sql);
375  if ($resql) {
376  // Use select2 selector
377  if (empty($option_only) && !empty($conf->use_javascript_ajax)) {
378  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
379  $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus);
380  $out .= $comboenhancement;
381  $morecss .= ' minwidth150';
382  }
383 
384  if (empty($option_only)) {
385  $out .= '<select class="valignmiddle flat'.($morecss ? ' '.$morecss : '').'"'.($disabled ? ' disabled="disabled"' : '').' id="'.$htmlname.'" name="'.$htmlname.'">';
386  }
387  if (!empty($show_empty)) {
388  $out .= '<option value="0" class="optiongrey">';
389  if (!is_numeric($show_empty)) {
390  //if (!empty($conf->use_javascript_ajax)) $out .= '<span class="opacitymedium">aaa';
391  $out .= $show_empty;
392  //if (!empty($conf->use_javascript_ajax)) $out .= '</span>';
393  } else {
394  $out .= '&nbsp;';
395  }
396  $out .= '</option>';
397  }
398 
399  $num = $this->db->num_rows($resql);
400  $i = 0;
401  if ($num) {
402  while ($i < $num) {
403  $obj = $this->db->fetch_object($resql);
404  // 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.
405  if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire)) {
406  // Do nothing
407  } else {
408  if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) {
409  $i++;
410  continue;
411  }
412 
413  $labeltoshow = '';
414  $titletoshow = '';
415 
416  $disabled = 0;
417  if ($obj->fk_statut == Project::STATUS_DRAFT) {
418  $disabled = 1;
419  } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
420  if ($discard_closed == 2) {
421  $disabled = 1;
422  }
423  } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
424  $disabled = 1;
425  }
426 
427  if (preg_match('/all/', $showmore)) {
428  $labeltoshow .= dol_trunc($obj->ref, 18); // Project ref
429  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
430  //else $labeltoshow.=' ('.$langs->trans("Private").')';
431  $labeltoshow .= ' '.dol_trunc($obj->title, $maxlength);
432  $titletoshow = $labeltoshow;
433 
434  if ($obj->name) {
435  $labeltoshow .= ' ('.$obj->name.')';
436  $titletoshow .= ' <span class="opacitymedium">('.$obj->name.')</span>';
437  }
438 
439  $disabled = 0;
440  if ($obj->fk_statut == Project::STATUS_DRAFT) {
441  $disabled = 1;
442  $labeltoshow .= ' - '.$langs->trans("Draft");
443  $titletoshow .= ' - <span class="opacitymedium">'.$langs->trans("Draft").'</span>';
444  } elseif ($obj->fk_statut == Project::STATUS_CLOSED) {
445  if ($discard_closed == 2) {
446  $disabled = 1;
447  }
448  $labeltoshow .= ' - '.$langs->trans("Closed");
449  $titletoshow .= ' - <span class="opacitymedium">'.$langs->trans("Closed").'</span>';
450  } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
451  $disabled = 1;
452  $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
453  $titletoshow .= ' - <span class="opacitymedium">'.$langs->trans("LinkedToAnotherCompany").'</span>';
454  }
455  $labeltoshow .= ' - ';
456  $titletoshow .= ' - ';
457  }
458 
459  // Label for task
460  $labeltoshow .= $obj->tref.' '.dol_trunc($obj->tlabel, $maxlength);
461  $titletoshow .= $obj->tref.' '.dol_trunc($obj->tlabel, $maxlength);
462  if ($obj->usage_task && preg_match('/progress/', $showmore)) {
463  $labeltoshow .= ' <span class="opacitymedium">('.$obj->progress.'%)</span>';
464  $titletoshow .= ' <span class="opacitymedium">('.$obj->progress.'%)</span>';
465  }
466 
467  if (!empty($selected) && $selected == $obj->rowid) {
468  $out .= '<option value="'.$obj->rowid.'" selected';
469  $out .= ' data-html="'.dol_escape_htmltag($titletoshow).'"';
470  //if ($disabled) $out.=' disabled'; // with select2, field can't be preselected if disabled
471  $out .= '>'.$labeltoshow.'</option>';
472  } else {
473  if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
474  $resultat = '';
475  } else {
476  $resultat = '<option value="'.$obj->rowid.'"';
477  if ($disabled) {
478  $resultat .= ' disabled';
479  }
480  //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
481  //else $labeltoshow.=' ('.$langs->trans("Private").')';
482  $resultat .= ' data-html="'.dol_escape_htmltag($titletoshow).'"';
483  $resultat .= '>';
484  $resultat .= $labeltoshow;
485  $resultat .= '</option>';
486  }
487  $out .= $resultat;
488  }
489  }
490  $i++;
491  }
492  }
493  if (empty($option_only)) {
494  $out .= '</select>';
495  }
496 
497  $this->nboftasks = $num;
498 
499  print $out;
500 
501  $this->db->free($resql);
502  return $num;
503  } else {
504  dol_print_error($this->db);
505  return -1;
506  }
507  }
508 
509 
510  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
522  public function select_element($table_element, $socid = 0, $morecss = '', $limitonstatus = -2, $projectkey = "fk_projet", $placeholder = '')
523  {
524  // phpcs:enable
525  global $conf, $langs;
526 
527  if ($table_element == 'projet_task') {
528  return ''; // Special cas of element we never link to a project (already always done)
529  }
530 
531  $linkedtothirdparty = false;
532  if (!in_array($table_element, array(
533  'don',
534  'expensereport_det',
535  'expensereport', 'loan',
536  'stock_mouvement',
537  'payment_salary',
538  'payment_various',
539  'salary',
540  'chargesociales',
541  'entrepot')
542  )) {
543  $linkedtothirdparty = true;
544  }
545 
546  $sqlfilter = '';
547 
548  //print $table_element;
549  switch ($table_element) {
550  case "loan":
551  $sql = "SELECT t.rowid, t.label as ref";
552  break;
553  case "facture":
554  $sql = "SELECT t.rowid, t.ref as ref";
555  break;
556  case "facture_fourn":
557  $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
558  break;
559  case "commande_fourn":
560  case "commande_fournisseur":
561  $sql = "SELECT t.rowid, t.ref, t.ref_supplier";
562  break;
563  case "facture_rec":
564  $sql = "SELECT t.rowid, t.titre as ref";
565  break;
566  case "actioncomm":
567  $sql = "SELECT t.id as rowid, t.label as ref";
568  $projectkey = "fk_project";
569  break;
570  case "expensereport":
571  return '';
572  case "expensereport_det":
573  /*$sql = "SELECT rowid, '' as ref"; // table is llx_expensereport_det
574  $projectkey="fk_projet";
575  break;*/
576  return '';
577  case "commande":
578  case "contrat":
579  case "fichinter":
580  $sql = "SELECT t.rowid, t.ref";
581  break;
582  case 'stock_mouvement':
583  $sql = "SELECT t.rowid, t.label as ref";
584  $projectkey = 'fk_origin';
585  break;
586  case "payment_salary":
587  $sql = "SELECT t.rowid, t.num_payment as ref"; // TODO In a future fill and use real ref field
588  break;
589  case "payment_various":
590  $sql = "SELECT t.rowid, t.num_payment as ref";
591  break;
592  case "chargesociales":
593  default:
594  $sql = "SELECT t.rowid, t.ref";
595  break;
596  }
597  if ($linkedtothirdparty) {
598  $sql .= ", s.nom as name";
599  }
600  $sql .= " FROM ".$this->db->prefix().$table_element." as t";
601  if ($linkedtothirdparty) {
602  $sql .= ", ".$this->db->prefix()."societe as s";
603  }
604  $sql .= " WHERE ".$projectkey." is null";
605  if (!empty($socid) && $linkedtothirdparty) {
606  if (is_numeric($socid)) {
607  $sql .= " AND t.fk_soc = ".((int) $socid);
608  } else {
609  $sql .= " AND t.fk_soc IN (".$this->db->sanitize($socid).")";
610  }
611  }
612  if (!in_array($table_element, array('expensereport_det', 'stock_mouvement'))) {
613  $sql .= ' AND t.entity IN ('.getEntity('project').')';
614  }
615  if ($linkedtothirdparty) {
616  $sql .= " AND s.rowid = t.fk_soc";
617  }
618  if ($sqlfilter) {
619  $sql .= " AND ".$sqlfilter;
620  }
621  $sql .= " ORDER BY ref DESC";
622 
623  dol_syslog(get_class($this).'::select_element', LOG_DEBUG);
624  $resql = $this->db->query($sql);
625  if ($resql) {
626  $num = $this->db->num_rows($resql);
627  $i = 0;
628  $sellist = '';
629 
630  if ($num > 0) {
631  $sellist = '<select class="flat elementselect css'.$table_element.($morecss ? ' '.$morecss : '').'" name="elementselect">';
632  $sellist .= '<option value="-1"'.($placeholder ? ' class="optiongrey"' : '').'>'.$placeholder.'</option>';
633  while ($i < $num) {
634  $obj = $this->db->fetch_object($resql);
635  $ref = $obj->ref ? $obj->ref : $obj->rowid;
636  if (!empty($obj->ref_supplier)) {
637  $ref .= ' ('.$obj->ref_supplier.')';
638  }
639  if (!empty($obj->name)) {
640  $ref .= ' - '.$obj->name;
641  }
642  $sellist .= '<option value="'.$obj->rowid.'">'.$ref.'</option>';
643  $i++;
644  }
645  $sellist .= '</select>';
646  }
647  /*else
648  {
649  $sellist = '<select class="flat" name="elementselect">';
650  $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
651  $sellist.= '</select>';
652  }*/
653  $this->db->free($resql);
654 
655  return $sellist;
656  } else {
657  dol_print_error($this->db);
658  $this->error = $this->db->lasterror();
659  $this->errors[] = $this->db->lasterror();
660  dol_syslog(get_class($this)."::select_element ".$this->error, LOG_ERR);
661  return -1;
662  }
663  }
664 
665 
680  public function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '', $noadmininfo = 0, $addcombojs = 0)
681  {
682  global $conf, $langs, $user;
683 
684  $sql = "SELECT rowid, code, label, percent";
685  $sql .= " FROM ".$this->db->prefix().'c_lead_status';
686  $sql .= " WHERE active = 1";
687  $sql .= " ORDER BY position";
688 
689  $resql = $this->db->query($sql);
690  if ($resql) {
691  $num = $this->db->num_rows($resql);
692  $i = 0;
693  if ($num > 0) {
694  $sellist = '<select class="flat oppstatus'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
695  if ($showempty) {
696  // Without &nbsp, strange move of screen when switching value
697  $sellist .= '<option value="-1">&nbsp;</option>';
698  }
699  if ($showallnone) {
700  $sellist .= '<option value="all"'.($preselected == 'all' ? ' selected="selected"' : '').'>-- '.$langs->trans("OnlyOpportunitiesShort").'</option>';
701  $sellist .= '<option value="openedopp"'.($preselected == 'openedopp' ? ' selected="selected"' : '').'>-- '.$langs->trans("OpenedOpportunitiesShort").'</option>';
702  $sellist .= '<option value="notopenedopp"'.($preselected == 'notopenedopp' ? ' selected="selected"' : '').'>-- '.$langs->trans("NotOpenedOpportunitiesShort").'</option>';
703  $sellist .= '<option value="none"'.($preselected == 'none' ? ' selected="selected"' : '').'>-- '.$langs->trans("NotAnOpportunityShort").'</option>';
704  }
705  while ($i < $num) {
706  $obj = $this->db->fetch_object($resql);
707 
708  $sellist .= '<option value="'.$obj->rowid.'" defaultpercent="'.$obj->percent.'" elemcode="'.$obj->code.'"';
709  if ($obj->rowid == $preselected) {
710  $sellist .= ' selected="selected"';
711  }
712  $sellist .= '>';
713  if ($useshortlabel) {
714  $finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
715  } else {
716  $finallabel = ($langs->transnoentitiesnoconv("OppStatus".$obj->code) != "OppStatus".$obj->code ? $langs->transnoentitiesnoconv("OppStatus".$obj->code) : $obj->label);
717  if ($showpercent) {
718  $finallabel .= ' ('.$obj->percent.'%)';
719  }
720  }
721  $sellist .= $finallabel;
722  $sellist .= '</option>';
723  $i++;
724  }
725  $sellist .= '</select>';
726 
727  if ($user->admin && !$noadmininfo) {
728  $sellist .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
729  }
730 
731  if ($addcombojs) {
732  $sellist .= ajax_combobox($htmlname);
733  }
734  }
735  /*else
736  {
737  $sellist = '<select class="flat" name="elementselect">';
738  $sellist.= '<option value="0" disabled>'.$langs->trans("None").'</option>';
739  $sellist.= '</select>';
740  }*/
741  $this->db->free($resql);
742 
743  return $sellist;
744  } else {
745  $this->error = $this->db->lasterror();
746  $this->errors[] = $this->db->lasterror();
747  dol_syslog(get_class($this)."::selectOpportunityStatus ".$this->error, LOG_ERR);
748  return -1;
749  }
750  }
751 }
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:449
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.
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.
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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_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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
$conf db
API class for accounts.
Definition: inc.php:41