diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index 6411c76eeab..450057cba1f 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -1,19 +1,20 @@ + * Copyright (C) 2015 Marcos García * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ /** * \file htdocs/core/class/html.formprojet.class.php @@ -52,11 +53,59 @@ class FormProjets * @param int $option_only Return only html options lines without the select tag * @param int $show_empty Add an empty line * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) - * @param int $forcefocus Force focus on field (works with javascript only) - * @param int $disabled Disabled + * @param int $forcefocus Force focus on field (works with javascript only) + * @param int $disabled Disabled + * @param int $mode 0 for HTML mode and 1 for JSON mode + * @param string $filterkey Key to filter * @return int Nber of project if OK, <0 if KO */ - function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0) + 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 = '') + { + global $langs,$conf; + + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT)) + { + $placeholder=''; + + if ($selected && empty($selected_input_value)) + { + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + $project = new Project($this->db); + $project->fetch($selected); + $selected_input_value=$project->ref; + } + $urloption='socid='.$socid.'&htmlname='.$htmlname; + print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PROJECT_USE_SEARCH_TO_SELECT, 0, array( +// 'update' => array( +// 'projectid' => 'id' +// ) + )); + + print ''; + } + else + { + print $this->select_projects_list($socid, $selected, $htmlname, $maxlength, $option_only, $show_empty, $discard_closed, $forcefocus, $disabled, 0, $filterkey); + } + } + + /** + * Returns an array with projects qualified for a third party + * + * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id) + * @param int $selected Id project preselected + * @param string $htmlname Nom de la zone html + * @param int $maxlength Maximum length of label + * @param int $option_only Return only html options lines without the select tag + * @param int $show_empty Add an empty line + * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) + * @param int $forcefocus Force focus on field (works with javascript only) + * @param int $disabled Disabled + * @param int $mode 0 for HTML mode and 1 for JSON mode + * @param string $filterkey Key to filter + * @return int Nber of project if OK, <0 if KO + */ + 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 = '') { global $user,$conf,$langs; @@ -81,6 +130,10 @@ class FormProjets if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")"; if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)"; + if (!empty($filterkey)) { + $sql .= ' AND p.title LIKE "%'.$this->db->escape($filterkey).'%"'; + $sql .= ' OR p.ref LIKE "%'.$this->db->escape($filterkey).'%"'; + } $sql.= " ORDER BY p.ref ASC"; dol_syslog(__METHOD__, LOG_DEBUG); @@ -126,7 +179,7 @@ class FormProjets continue; } - $labeltoshow=dol_trunc($obj->ref,18); + $labeltoshow=dol_trunc($obj->ref,18).' - '.$obj->title; //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')'; //else $labeltoshow.=' ('.$langs->trans("Private").')'; $labeltoshow.=' '.dol_trunc($obj->title,$maxlength); @@ -171,19 +224,30 @@ class FormProjets $resultat.=''; } $out.= $resultat; + + $outarray[] = array( + 'key' => (int) $obj->rowid, + 'value' => $obj->ref, + 'ref' => $obj->ref, + 'label' => $labeltoshow, + 'disabled' => (bool) $disabled + ); } } $i++; } } - if (empty($option_only)) { - $out.= ''; - } - - print $out; $this->db->free($resql); - return $num; + + if (!$mode) { + if (empty($option_only)) { + $out.= ''; + } + print $out; + } else { + return $outarray; + } } else { @@ -299,7 +363,7 @@ class FormProjets $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); } // Label for task - $labeltoshow.=' - '.$obj->tref.' '.dol_trunc($obj->tlabel,$maxlenght); + $labeltoshow.=' - '.$obj->tref.' '.dol_trunc($obj->tlabel,$maxlength); if (!empty($selected) && $selected == $obj->rowid) { diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index c81b8b4b3a1..7c9a4b85a9a 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1598,6 +1598,7 @@ ProjectsSetup=Project module setup ProjectsModelModule=Project reports document model TasksNumberingModules=Tasks numbering module TaskModelModule=Tasks reports document model +UseSearchToSelectProject=Use autocompletion fields to choose project (instead of using a list box) ##### ECM (GED) ##### ECMSetup = GED Setup ECMAutoTree = Automatic tree folder and document diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index 2e0e9216687..e67e8bb3655 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -5,6 +5,7 @@ * Copyright (C) 2011-2013 Philippe Grand * Copyright (C) 2013 Florian Henry * Copyright (C) 2015 Juanjo Menent + * Copyright (C) 2015 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -280,6 +281,14 @@ else if ($action == 'setmodtask') dolibarr_set_const($db, "PROJECT_TASK_ADDON",$value,'chaine',0,'',$conf->entity); } +elseif ($action == 'updateoptions') { + if (GETPOST('PROJECT_USE_SEARCH_TO_SELECT')) { + $companysearch = GETPOST('activate_PROJECT_USE_SEARCH_TO_SELECT', 'alpha'); + if (dolibarr_set_const($db, "PROJECT_USE_SEARCH_TO_SELECT", $companysearch, 'chaine', 0, '', $conf->entity)) { + $conf->global->PROJECT_USE_SEARCH_TO_SELECT = $companysearch; + } + } +} /* @@ -813,6 +822,47 @@ foreach ($dirmodels as $reldir) print '
'; +print_titre($langs->trans("Other")); + +// Other options +$form=new Form($db); +$var=true; + +print '
'; +print ''; +print ''; + +print ''; +print ''; +print "\n"; +print ''."\n"; +print ''."\n"; + + +$var=!$var; +print ""; +print ''; +if (! $conf->use_javascript_ajax) +{ + print '"; +} +else +{ + print '"; +} +print '
".$langs->trans("Parameters")."'.$langs->trans("Value").' 
'.$langs->trans("UseSearchToSelectProject").''; + print $langs->trans("NotAvailableWhenAjaxDisabled"); + print "'; + $arrval=array('0'=>$langs->trans("No"), + '1'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch",1).')', + '2'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch",2).')', + '3'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch",3).')', + ); + print $form->selectarray("activate_PROJECT_USE_SEARCH_TO_SELECT",$arrval,$conf->global->PROJECT_USE_SEARCH_TO_SELECT); + print ''; + print ''; + print "
'; + $db->close(); llxFooter();