X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=plugins%2Ffunction.select_db_table.php;h=e8e921c8ec16db2128c31813cfb3d0d7cbd78705;hb=4b68ab74f2c09a83e41a2949b053cbf9b44f846e;hp=1c7f0722b18da155c3f78efc9db6a97b2a592c67;hpb=a3a049fc80d3707bcc76903ab89f73974c470c0c;p=platal.git
diff --git a/plugins/function.select_db_table.php b/plugins/function.select_db_table.php
index 1c7f072..e8e921c 100644
--- a/plugins/function.select_db_table.php
+++ b/plugins/function.select_db_table.php
@@ -20,36 +20,55 @@
***************************************************************************/
-function select_options($table,$valeur,$champ="text",$pad=false,$where="") {
- $sql = "SELECT id,$champ FROM $table $where ORDER BY $champ";
+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";
}
- while (list($my_id,$my_text) = $res->next()) {
- $html .= sprintf("\n",
+ $optgrp = null;
+ while (list($my_id,$my_text,$my_grp) = $res->next()) {
+ if ($my_grp != $optgrp) {
+ if (!is_null($optgrp)) {
+ $html .= '';
+ }
+ $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']);
}
?>