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 =
'')
80 global $langs, $conf,
$form;
82 $selected_input_value =
'';
83 if (is_object($selected)) {
84 $selected_input_value = $selected->ref;
85 $selected = $selected->id;
90 if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT)) {
93 if ($selected && empty($selected_input_value)) {
94 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
96 $project->fetch($selected);
97 $selected_input_value = $project->ref;
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';
103 $out .=
'<input type="text" class="minwidth200'.($morecss ?
' '.$morecss :
'').
'" name="search_'.$htmlname.
'" id="search_'.$htmlname.
'" value="'.$selected_input_value.
'"'.$placeholder.
' />';
105 $out .=
ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.
'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array());
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);
109 if ($discard_closed > 0) {
111 $out .=
$form->textwithpicto(
'', $langs->trans(
"ClosedProjectsAreHidden"));
115 if (empty($nooutput)) {
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 =
'')
148 global $user, $conf, $langs;
150 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
152 if (empty($htmlid)) {
159 $hideunselectables =
false;
160 if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
161 $hideunselectables =
true;
164 $projectsListId =
false;
165 if (empty($user->rights->projet->all->lire)) {
167 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
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).
")";
178 $sql .=
" AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
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') {
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)";
187 if (!empty($filterkey)) {
191 $sql .=
' AND ('.$this->db->sanitize($morefilter, 0, 1).
')';
193 $sql .=
" ORDER BY p.ref ASC";
197 if (!empty($conf->use_javascript_ajax)) {
198 $morecss .=
' minwidth100';
200 if (empty($option_only)) {
201 $out .=
'<select class="flat'.($morecss ?
' '.$morecss :
'').
'"'.($disabled ?
' disabled="disabled"' :
'').
' id="'.$htmlid.
'" name="'.$htmlname.
'">';
203 if (!empty($show_empty)) {
204 $out .=
'<option value="0"> </option>';
210 $obj = $this->
db->fetch_object(
$resql);
212 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->hasRight(
'societe',
'lire')) {
215 if ($discard_closed == 1 && $obj->fk_statut == 2 && $obj->rowid != $selected) {
223 $labeltoshow .=
', '.dol_trunc($obj->title, $maxlength);
225 $labeltoshow .=
' - '.$obj->name;
226 if ($obj->name_alias) {
227 $labeltoshow .=
' ('.$obj->name_alias.
')';
232 if ($obj->fk_statut == 0) {
234 $labeltoshow .=
' - '.$langs->trans(
"Draft");
235 } elseif ($obj->fk_statut == 2) {
236 if ($discard_closed == 2) {
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)) {
242 $labeltoshow .=
' - '.$langs->trans(
"LinkedToAnotherCompany");
245 if (!empty($selected) && $selected == $obj->rowid) {
246 $out .=
'<option value="'.$obj->rowid.
'" selected';
248 $out .=
'>'.$labeltoshow.
'</option>';
250 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
253 $resultat =
'<option value="'.$obj->rowid.
'"';
255 $resultat .=
' disabled';
260 $resultat .= $labeltoshow;
261 $resultat .=
'</option>';
266 'key' => (
int) $obj->rowid,
267 'value' => $obj->ref,
269 'labelx' => $labeltoshow,
270 'label' => ($disabled ?
'<span class="opacitymedium">'.$labeltoshow.
'</span>' : $labeltoshow),
271 'disabled' => (
bool) $disabled
282 if (empty($option_only)) {
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';
294 if (empty($nooutput)) {
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)
329 global $user, $conf, $langs;
331 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
333 if (is_null($usertofilter)) {
334 $usertofilter = $user;
339 $hideunselectables =
false;
340 if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) {
341 $hideunselectables =
true;
344 if (empty($projectsListId)) {
345 if (empty($usertofilter->rights->projet->all->lire)) {
347 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1);
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).
")";
364 $sql .=
" AND (p.fk_soc=0 OR p.fk_soc IS NULL)";
367 $sql .=
" AND (p.fk_soc=".((int) $socid).
" OR p.fk_soc IS NULL)";
369 $sql .=
" ORDER BY p.ref, t.ref ASC";
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';
381 if (empty($option_only)) {
382 $out .=
'<select class="valignmiddle flat'.($morecss ?
' '.$morecss :
'').
'"'.($disabled ?
' disabled="disabled"' :
'').
' id="'.$htmlname.
'" name="'.$htmlname.
'">';
384 if (!empty($show_empty)) {
385 $out .=
'<option value="0" class="optiongrey">';
386 if (!is_numeric($show_empty)) {
400 $obj = $this->
db->fetch_object(
$resql);
402 if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire)) {
417 if ($discard_closed == 2) {
420 } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) {
424 if (preg_match(
'/all/', $showmore)) {
425 $labeltoshow .=
dol_trunc($obj->ref, 18);
428 $labeltoshow .=
' '.dol_trunc($obj->title, $maxlength);
429 $titletoshow = $labeltoshow;
432 $labeltoshow .=
' ('.$obj->name.
')';
433 $titletoshow .=
' <span class="opacitymedium">('.$obj->name.
')</span>';
439 $labeltoshow .=
' - '.$langs->trans(
"Draft");
440 $titletoshow .=
' - <span class="opacitymedium">'.$langs->trans(
"Draft").
'</span>';
442 if ($discard_closed == 2) {
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)) {
449 $labeltoshow .=
' - '.$langs->trans(
"LinkedToAnotherCompany");
450 $titletoshow .=
' - <span class="opacitymedium">'.$langs->trans(
"LinkedToAnotherCompany").
'</span>';
452 $labeltoshow .=
' - ';
453 $titletoshow .=
' - ';
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>';
464 if (!empty($selected) && $selected == $obj->rowid) {
465 $out .=
'<option value="'.$obj->rowid.
'" selected';
466 $out .=
' data-html="'.dol_escape_htmltag($titletoshow).
'"';
468 $out .=
'>'.$labeltoshow.
'</option>';
470 if ($hideunselectables && $disabled && ($selected != $obj->rowid)) {
473 $resultat =
'<option value="'.$obj->rowid.
'"';
475 $resultat .=
' disabled';
479 $resultat .=
' data-html="'.dol_escape_htmltag($titletoshow).
'"';
481 $resultat .= $labeltoshow;
482 $resultat .=
'</option>';
490 if (empty($option_only)) {
494 $this->nboftasks = $num;
519 public function select_element($table_element, $socid = 0, $morecss =
'', $limitonstatus = -2, $projectkey =
"fk_projet", $placeholder =
'')
522 global $conf, $langs;
524 if ($table_element ==
'projet_task') {
528 $linkedtothirdparty =
false;
529 if (!in_array($table_element, array(
532 'expensereport',
'loan',
540 $linkedtothirdparty =
true;
546 switch ($table_element) {
548 $sql =
"SELECT t.rowid, t.label as ref";
551 $sql =
"SELECT t.rowid, t.ref as ref";
553 case "facture_fourn":
554 $sql =
"SELECT t.rowid, t.ref, t.ref_supplier";
556 case "commande_fourn":
557 case "commande_fournisseur":
558 $sql =
"SELECT t.rowid, t.ref, t.ref_supplier";
561 $sql =
"SELECT t.rowid, t.titre as ref";
564 $sql =
"SELECT t.id as rowid, t.label as ref";
565 $projectkey =
"fk_project";
567 case "expensereport":
569 case "expensereport_det":
577 $sql =
"SELECT t.rowid, t.ref";
579 case 'stock_mouvement':
580 $sql =
"SELECT t.rowid, t.label as ref";
581 $projectkey =
'fk_origin';
583 case "payment_salary":
584 $sql =
"SELECT t.rowid, t.num_payment as ref";
586 case "payment_various":
587 $sql =
"SELECT t.rowid, t.num_payment as ref";
589 case "chargesociales":
591 $sql =
"SELECT t.rowid, t.ref";
594 if ($linkedtothirdparty) {
595 $sql .=
", s.nom as name";
597 $sql .=
" FROM ".$this->db->prefix().$table_element.
" as t";
598 if ($linkedtothirdparty) {
599 $sql .=
", ".$this->db->prefix().
"societe as s";
601 $sql .=
" WHERE ".$projectkey.
" is null";
602 if (!empty($socid) && $linkedtothirdparty) {
603 if (is_numeric($socid)) {
604 $sql .=
" AND t.fk_soc = ".((int) $socid);
606 $sql .=
" AND t.fk_soc IN (".$this->db->sanitize($socid).
")";
609 if (!in_array($table_element, array(
'expensereport_det',
'stock_mouvement'))) {
610 $sql .=
' AND t.entity IN ('.getEntity(
'project').
')';
612 if ($linkedtothirdparty) {
613 $sql .=
" AND s.rowid = t.fk_soc";
616 $sql .=
" AND ".$sqlfilter;
618 $sql .=
" ORDER BY ref DESC";
620 dol_syslog(get_class($this).
'::select_element', LOG_DEBUG);
626 $sellist =
'<select class="flat elementselect css'.$table_element.($morecss ?
' '.$morecss :
'').
'" name="elementselect">';
627 $sellist .=
'<option value="-1"'.($placeholder ?
' class="optiongrey"' :
'').
'>'.$placeholder.
'</option>';
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.
')';
634 if (!empty($obj->name)) {
635 $ref .=
' - '.$obj->name;
637 $sellist .=
'<option value="'.$obj->rowid.
'">'.$ref.
'</option>';
640 $sellist .=
'</select>';
653 $this->error = $this->
db->lasterror();
654 $this->errors[] = $this->
db->lasterror();
655 dol_syslog(get_class($this).
"::select_element ".$this->error, LOG_ERR);
675 public function selectOpportunityStatus($htmlname, $preselected =
'-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss =
'', $noadmininfo = 0, $addcombojs = 0)
677 global $conf, $langs, $user;
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";
689 $sellist =
'<select class="flat oppstatus'.($morecss ?
' '.$morecss :
'').
'" id="'.$htmlname.
'" name="'.$htmlname.
'">';
692 $sellist .=
'<option value="-1"> </option>';
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>';
701 $obj = $this->
db->fetch_object(
$resql);
703 $sellist .=
'<option value="'.$obj->rowid.
'" defaultpercent="'.$obj->percent.
'" elemcode="'.$obj->code.
'"';
704 if ($obj->rowid == $preselected) {
705 $sellist .=
' selected="selected"';
708 if ($useshortlabel) {
709 $finallabel = ($langs->transnoentitiesnoconv(
"OppStatus".$obj->code) !=
"OppStatus".$obj->code ? $langs->transnoentitiesnoconv(
"OppStatus".$obj->code) : $obj->label);
711 $finallabel = ($langs->transnoentitiesnoconv(
"OppStatus".$obj->code) !=
"OppStatus".$obj->code ? $langs->transnoentitiesnoconv(
"OppStatus".$obj->code) : $obj->label);
713 $finallabel .=
' ('.$obj->percent.
'%)';
716 $sellist .= $finallabel;
717 $sellist .=
'</option>';
720 $sellist .=
'</select>';
722 if ($user->admin && !$noadmininfo) {
723 $sellist .=
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
740 $this->error = $this->
db->lasterror();
741 $this->errors[] = $this->
db->lasterror();
742 dol_syslog(get_class($this).
"::selectOpportunityStatus ".$this->error, LOG_ERR);
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...
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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.