X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=plugins%2Ffunction.select_db_table.php;h=bc83d956b64545919de63bf346ff558ffd0b8800;hb=refs%2Fheads%2Fcore%2Fmaster;hp=47103f3553423af3e693e648fe6984b7531590a3;hpb=50a40a33a496131e817df875607ea5542d096a64;p=platal.git
diff --git a/plugins/function.select_db_table.php b/plugins/function.select_db_table.php
index 47103f3..bc83d95 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, $value, $field, $pad, $where, $join, $group)
+{
+ $fields = 't.id,' . $field;
+ $order = $field;
+ if ($group) {
+ $fields .= ',' . $group;
+ $order = $group . ',' . $order;
+ } else {
+ $fields .= ', NULL';
+ }
+ $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 = "";
+ // An empty entry is added when $pad is true.
+ $html = '';
if ($pad) {
- $html.= '\n";
+ $html .= '\n";
}
- while (list($my_id,$my_text) = $res->next()) {
- $html .= sprintf("\n",$my_id,($valeur==$my_id?$sel:""),$my_text);
+ $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;
- if(empty($params['champ']))
- $params['champ'] = 'text';
- if(empty($params['pad']) || !($params['pad']))
- $pad = false;
- else
- $pad = true;
- if(empty($params['where']))
- $params['where'] = '';
- return select_options($params['table'], $params['valeur'], $params['champ'], $pad, $params['where']);
+function smarty_function_select_db_table($params, $smarty) {
+ if (empty($params['table']) || !array_key_exists('valeur', $params)) {
+ return;
+ }
+ if (empty($params['champ'])) {
+ $params['champ'] = 'text';
+ }
+ foreach (array('where', 'join', 'group') as $value) {
+ if (empty($params[$value])) {
+ $params[$value] = '';
+ }
+ }
+ $pad = (!empty($params['pad']) && $params['pad']);
+
+ 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 fenc=utf-8:
?>