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