diff --git a/htdocs/comm/prospect/list.php b/htdocs/comm/prospect/list.php index 47c051a4f47e6b0616715a6004b0f26a1c58c665..176d71c77be012e2ba3487c8a26eb07292257b56 100644 --- a/htdocs/comm/prospect/list.php +++ b/htdocs/comm/prospect/list.php @@ -219,34 +219,23 @@ $sql.= " AND s.client IN (2, 3)"; $sql.= ' AND s.entity IN ('.getEntity('societe', 1).')'; if ((!$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; if ($socid) $sql.= " AND s.rowid = " .$socid; -if ($search_stcomm != '') $sql.= " AND s.fk_stcomm=".$search_stcomm; -if ($catid > 0) $sql.= " AND cs.fk_categorie = ".$catid; -if ($catid == -2) $sql.= " AND cs.fk_categorie IS NULL"; -if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$search_categ; -if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL"; -if ($search_nom) { - $sql .= natural_search('s.nom', $search_nom); -} +if ($search_stcomm != '') $sql.= natural_search("s.fk_stcomm",$search_stcomm,2); +if ($catid > 0) $sql.= " AND cs.fk_categorie = ".$catid; +if ($catid == -2) $sql.= " AND cs.fk_categorie IS NULL"; +if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$search_categ; +if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL"; +if ($search_nom) $sql .= natural_search('s.nom', $search_nom); if ($search_zipcode) $sql .= " AND s.zip LIKE '".$db->escape(strtolower($search_zipcode))."%'"; -if ($search_town) { - $sql .= natural_search('s.town', $search_town); -} -if ($search_state) { - $sql .= natural_search('d.nom', $search_state); -} -if ($search_datec) $sql .= " AND s.datec LIKE '%".$db->escape($search_datec)."%'"; +if ($search_town) $sql .= natural_search('s.town', $search_town); +if ($search_state) $sql .= natural_search('d.nom', $search_state); +if ($search_datec) $sql .= " AND s.datec LIKE '%".$db->escape($search_datec)."%'"; if ($search_status!='') $sql .= " AND s.status = ".$db->escape($search_status); // Insert levels filters -if ($search_levels) -{ - $sql .= " AND s.fk_prospectlevel IN (".$search_levels.')'; -} +if ($search_levels) $sql .= " AND s.fk_prospectlevel IN (".$search_levels.')'; // Insert sale filter -if ($search_sale > 0) +if ($search_sale > 0) $sql .= " AND sc.fk_user = ".$db->escape($search_sale); +if ($socname) { - $sql .= " AND sc.fk_user = ".$db->escape($search_sale); -} -if ($socname) { $sql .= natural_search('s.nom', $search_nom); $sortfield = "s.nom"; $sortorder = "ASC"; @@ -362,22 +351,17 @@ if ($resql) print '<input class="flat" type="text" size="10" name="search_datec" value="'.$search_datec.'">'; print '</td>'; - // Added by Matelli + // Prospect levelt print '<td class="liste_titre" align="center">'; - // Generate in $options_from the list of each option sorted - $options_from = '<option value=""> </option>'; + $options_from = '<option value=""> </option>'; // Generate in $options_from the list of each option sorted foreach ($tab_level as $tab_level_sortorder => $tab_level_label) { $options_from .= '<option value="'.$tab_level_sortorder.'"'.($search_level_from == $tab_level_sortorder ? ' selected':'').'>'; $options_from .= $langs->trans($tab_level_label); $options_from .= '</option>'; } - - // Reverse the list - array_reverse($tab_level, true); - - // Generate in $options_to the list of each option sorted in the reversed order - $options_to = '<option value=""> </option>'; + array_reverse($tab_level, true); // Reverse the list + $options_to = '<option value=""> </option>'; // Generate in $options_to the list of each option sorted in the reversed order foreach ($tab_level as $tab_level_sortorder => $tab_level_label) { $options_to .= '<option value="'.$tab_level_sortorder.'"'.($search_level_to == $tab_level_sortorder ? ' selected':'').'>'; @@ -392,8 +376,11 @@ if ($resql) print '</td>'; + // Prospect status print '<td class="liste_titre" align="center">'; - print ' '; + // TODO Add here a list of prospect status + //print $form->selectarray($htmlname, $array, $search_stcomm); + //print ' '; print '</td>'; print '<td class="liste_titre" align="center">'; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 39634e6af3103c09d84f4b4f0833362d291b09ee..6eab9d8b545846326e9132d3844fb98e5fa351ae 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4304,36 +4304,40 @@ class Form /** * Return a HTML select string, built from an array of key+value. - * Note: Do not use returned string into a langs->trans function, content may be entity encoded twice. + * Note: Do not apply langs->trans function on returned content, content may be entity encoded twice. * - * @param string $htmlname Name of html select area - * @param array $array Array with key+value - * @param string $id Preselected key - * @param int $show_empty 0 no empty value allowed, 1 to add an empty value into list (value is '' or ' '). - * @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value" - * @param int $value_as_key 1 to use value as key - * @param string $moreparam Add more parameters onto the select tag - * @param int $translate Translate and encode value - * @param int $maxlen Length maximum for labels - * @param int $disabled Html select box is disabled - * @param int $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' = Do not sort - * @param string $morecss Add more class to css styles - * @param int $addjscombo Add js combo - * @return string HTML select string. + * @param string $htmlname Name of html select area. Must start with "multi" if this is a multiselect + * @param array $array Array with key+value + * @param string|string[] $id Preselected key or preselected keys for multiselect + * @param int $show_empty 0 no empty value allowed, 1 to add an empty value into list (value is '' or ' '). + * @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value" + * @param int $value_as_key 1 to use value as key + * @param string $moreparam Add more parameters onto the select tag + * @param int $translate Translate and encode value + * @param int $maxlen Length maximum for labels + * @param int $disabled Html select box is disabled + * @param int $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' = Do not sort + * @param string $morecss Add more class to css styles + * @param int $addjscombo Add js combo + * @return string HTML select string. * @see multiselectarray */ static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0) { global $conf, $langs; + // Do we want a multiselect ? + $multiselect = 0; + if (preg_match('/^multi/',$htmlname)) $multiselect = 1; + if ($value_as_key) $array=array_combine($array, $array); $out=''; // Add code for jquery to use multiselect - if ($addjscombo && empty($conf->dol_use_jmobile) && (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT'))) + if ($addjscombo && empty($conf->dol_use_jmobile) && $multiselect) { - $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT'):$conf->global->MAIN_USE_JQUERY_MULTISELECT; + $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT')?constant('REQUIRE_JQUERY_MULTISELECT'):'select2':$conf->global->MAIN_USE_JQUERY_MULTISELECT; $out.='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' --> <script type="text/javascript"> $(document).ready(function () { @@ -4393,12 +4397,11 @@ class Form /** - * Return a HTML select string, built from an array of key+value. - * Note: Do not use returned string into a langs->trans function, content may be entity encoded twice. + * Return a HTML select string, built from an array of key+value but content returned into select come from an Ajax call of an URL. + * Note: Do not apply langs->trans function on returned content, content may be entity encoded twice. * - * @param string $url Url * @param string $htmlname Name of html select area - * @param array $array Array with key+value + * @param string $url Url * @param string $id Preselected key * @param int $show_empty 0 no empty value allowed, 1 to add an empty value into list (value is '' or ' '). * @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value" @@ -4412,7 +4415,7 @@ class Form * @param int $addjscombo Add js combo * @return string HTML select string. */ - static function selectArrayAjax($url, $htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0) + static function selectArrayAjax($htmlname, $url, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0) { $out = ''; @@ -4455,7 +4458,7 @@ class Form } else { - // TODO get values from ajax page to use a standard already completed array + // TODO get all values from $url into $array } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 3d756fb8e325b12afa3fe3c842102eaadcef4f27..63ab76dcb2fff924c2c15f734bd221f716b02525 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4974,21 +4974,22 @@ function dol_getmypid() /** - * Generate natural SQL search string + * Generate natural SQL search string for a criteria (this criteria can be tested on one or several fields) * - * @param string|string[] $fields String or array of strings, filled with the name of fields in the SQL query + * @param string|string[] $fields String or array of strings, filled with the name of all fields in the SQL query we must check (combined with a OR) * @param string $value The value to look for. - * If param $numeric is 0, can contains several keywords separated with a space, like "keyword1 keyword2" = We want record field like keyword1 and field like keyword2 - * If param $numeric is 1, can contains an operator <>= like "<10" or ">=100.5 < 1000" - * @param integer $numeric 0=value is list of keywords, 1=value is a numeric test + * If param $mode is 0, can contains several keywords separated with a space, like "keyword1 keyword2" = We want record field like keyword1 and field like keyword2 + * If param $mode is 1, can contains an operator <, > or = like "<10" or ">=100.5 < 1000" + * If param $mode is 2, can contains a list of id separated by comma like "1,3,4" + * @param integer $mode 0=value is list of keywords, 1=value is a numeric test (Example ">5.5 <10"), 2=value is a list of id separated with comma (Example '1,3,4') * @param integer $nofinaland 1=Do now output the final 'AND' * @return string $res The statement to append to the SQL query */ -function natural_search($fields, $value, $numeric=0, $nofinaland=0) +function natural_search($fields, $value, $mode=0, $nofinaland=0) { global $db,$langs; - if ($numeric) + if ($mode == 1) { $value=preg_replace('/([<>=]+)\s+([0-9'.preg_quote($langs->trans("DecimalSeparator"),'/').'\-])/','\1\2',$value); // Clean string '< 10' into '<10' so we can the explode on space to get all tests to do } @@ -5005,7 +5006,7 @@ function natural_search($fields, $value, $numeric=0, $nofinaland=0) $newres = ''; foreach ($fields as $field) { - if ($numeric) + if ($mode == 1) { $operator='='; $newcrit = preg_replace('/([<>=]+)/','',trim($crit)); @@ -5029,8 +5030,13 @@ function natural_search($fields, $value, $numeric=0, $nofinaland=0) $i2++; // a criteria was added to string } } - else + else if ($mode == 2) { + $newres .= ($i2 > 0 ? ' OR ' : '') . $field . " IN (" . $db->escape(trim($crit)) . ")"; + $i2++; // a criteria was added to string + } + else + { $newres .= ($i2 > 0 ? ' OR ' : '') . $field . " LIKE '%" . $db->escape(trim($crit)) . "%'"; $i2++; // a criteria was added to string } diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 7bba3d5edfa0164dc15994771eb11778730f261b..b1197202d1b331ec95ac7a358e642b23ec6283ec 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -583,11 +583,11 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $langs->load("commercial"); $newmenu->add("/comm/prospect/list.php?leftmenu=prospects", $langs->trans("ListProspectsShort"), 1, $user->rights->societe->lire, '', $mainmenu, 'prospects'); - if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&stcomm=-1", $langs->trans("LastProspectDoNotContact"), 2, $user->rights->societe->lire); - if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&stcomm=0", $langs->trans("LastProspectNeverContacted"), 2, $user->rights->societe->lire); - if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&stcomm=1", $langs->trans("LastProspectToContact"), 2, $user->rights->societe->lire); - if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&stcomm=2", $langs->trans("LastProspectContactInProcess"), 2, $user->rights->societe->lire); - if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&stcomm=3", $langs->trans("LastProspectContactDone"), 2, $user->rights->societe->lire); + if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&search_stcomm=-1", $langs->trans("LastProspectDoNotContact"), 2, $user->rights->societe->lire); + if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&search_stcomm=0", $langs->trans("LastProspectNeverContacted"), 2, $user->rights->societe->lire); + if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&search_stcomm=1", $langs->trans("LastProspectToContact"), 2, $user->rights->societe->lire); + if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&search_stcomm=2", $langs->trans("LastProspectContactInProcess"), 2, $user->rights->societe->lire); + if (empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/comm/prospect/list.php?sortfield=s.datec&sortorder=desc&begin=&search_stcomm=3", $langs->trans("LastProspectContactDone"), 2, $user->rights->societe->lire); $newmenu->add("/societe/soc.php?leftmenu=prospects&action=create&type=p", $langs->trans("MenuNewProspect"), 2, $user->rights->societe->creer); //$newmenu->add("/contact/list.php?leftmenu=customers&type=p", $langs->trans("Contacts"), 2, $user->rights->societe->contact->lire); diff --git a/htdocs/public/test/test_forms.php b/htdocs/public/test/test_forms.php index c0c81882fe223677ce47039a82d115b3a5e0c04c..f14652f6dc069018dc26928fd12f841cf3c0fcd8 100644 --- a/htdocs/public/test/test_forms.php +++ b/htdocs/public/test/test_forms.php @@ -51,7 +51,7 @@ print "Test 4c: a select with ajax refresh<br>\n"; //$array=array(0=>'',1=>'Search into xxx',2=>'Search into yyy',3=>'Search into zzz'); $array=array(); $selected=-1; -print $form->selectArrayAjax(DOL_URL_ROOT.'/core/ajax/selecsearchbox.php', 'testselectc', $array, $selected, 1, 0, 0, 'style="min-width: 250px;"', 0, 0, 0, '', '', 1); +print $form->selectArrayAjax('testselectc', DOL_URL_ROOT.'/core/ajax/selecsearchbox.php', $selected, 1, 0, 0, 'style="min-width: 250px;"', 0, 0, 0, '', '', 1); */ print '<br><br>'."\n";