X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=plugins%2Ffunction.select_db_table.php;h=eef9e1d64164fb61fdf91dc3d448410b833d5beb;hb=794feea76e0979eba4e125bb91b7ea43680f26e0;hp=b9b948d8dfee8fb40d47893a9c81ed80c3efcef1;hpb=0337d704b62718d7c77106c0e4c4e26fb02beacf;p=platal.git diff --git a/plugins/function.select_db_table.php b/plugins/function.select_db_table.php index b9b948d..eef9e1d 100644 --- a/plugins/function.select_db_table.php +++ b/plugins/function.select_db_table.php @@ -1,6 +1,6 @@ xdb->iterRow($sql); +function select_options($table,$valeur,$champ="text",$pad=false, + $where="",$join="",$group="") +{ + $fields = 't.id,' . $champ; + $order = $champ; + if ($group) { + $fields .= ',' . $group; + $order = $group . ',' . $order; + } + $sql = "SELECT $fields FROM $table AS t $join $where ORDER BY $order"; + $res = XDB::iterRow($sql); $sel = ' selected="selected"'; // on ajoute une entree vide si $pad est vrai $html = ""; if ($pad) { - $html.= '\n"; + $html.= '\n"; + } + $optgrp = null; + while (list($my_id,$my_text,$my_grp) = $res->next()) { + if ($my_grp != $optgrp) { + if (!is_null($optgrp)) { + $html .= ''; + } + $html .= ''; + $optgrp = $my_grp; + } + $html .= sprintf("\n", + $my_id, $valeur==$my_id ? $sel : "", pl_entities($my_text)); } - while (list($my_id,$my_text) = $res->next()) { - $html .= sprintf("\n",$my_id,($valeur==$my_id?$sel:""),$my_text); + if (!is_null($optgrp)) { + $html .= ''; } return $html; } function smarty_function_select_db_table($params, &$smarty) { if(empty($params['table'])) - return; + return; if(empty($params['champ'])) - $params['champ'] = 'text'; + $params['champ'] = 'text'; if(empty($params['pad']) || !($params['pad'])) - $pad = false; + $pad = false; else - $pad = true; + $pad = true; if(empty($params['where'])) - $params['where'] = ''; - return select_options($params['table'], $params['valeur'], $params['champ'], $pad, $params['where']); + $params['where'] = ''; + return select_options($params['table'], $params['valeur'], $params['champ'], $pad, + $params['where'], $params['join'], $params['group']); } +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>