From 4ec4f4fac73815354ad677ea1f7cb25317dec9a6 Mon Sep 17 00:00:00 2001 From: secretr Date: Tue, 20 Jan 2009 22:37:49 +0000 Subject: [PATCH] e_form - full userclass support - select, checkbox lists, newspost updated to use them --- e107_admin/newspost.php | 12 +++---- e107_handlers/form_handler.php | 50 +++++++++++++++++++++++------- e107_handlers/userclass_class.php | 16 +++++----- e107_themes/_blank/admin_style.css | 1 + 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index ef9f07520..650aaafc9 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -9,8 +9,8 @@ * News Administration * * $Source: /cvs_backup/e107_0.8/e107_admin/newspost.php,v $ - * $Revision: 1.28 $ - * $Date: 2009-01-20 21:29:23 $ + * $Revision: 1.29 $ + * $Date: 2009-01-20 22:37:49 $ * $Author: secretr $ */ require_once("../class2.php"); @@ -1080,8 +1080,8 @@ class admin_newspost $text .= " ".NWSLAN_22.": -
- ".$e107->user_class->vetted_tree("news_userclass", array($e107->user_class,'checkbox'), $_POST['news_class'], "nobody,public,guest,member,admin,classes,language")."
+ + ".$frm->uc_checkbox('news_userclass', $_POST['news_class'], 'nobody,public,guest,member,admin,classes,language', 'description=1')."
".NWSLAN_84."
@@ -1479,13 +1479,13 @@ class admin_newspost ".LAN_NEWS_51." - ".$frm->uc_select('news_editauthor', $pref['news_editauthor'], 'nobody,main,admin,classes', 'tabindex='.$frm->getNext())." + ".$frm->uc_select('news_editauthor', $pref['news_editauthor'], 'nobody,main,admin,classes')." ".NWSLAN_106." - ".$frm->uc_select('subnews_class', $pref['subnews_class'], 'nobody,public,guest,member,admin,classes', 'tabindex='.$frm->getNext())." + ".$frm->uc_select('subnews_class', $pref['subnews_class'], 'nobody,public,guest,member,admin,classes')." diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 07e3e5fd4..a415f85cb 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -9,8 +9,8 @@ * Form Handler * * $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $ - * $Revision: 1.20 $ - * $Date: 2009-01-20 20:46:26 $ + * $Revision: 1.21 $ + * $Date: 2009-01-20 22:37:49 $ * $Author: secretr $ * */ @@ -71,7 +71,7 @@ class e_form { $this->_tabindex_enabled = $enable_tabindex; $e107 = &e107::getInstance(); - $this->uc = &$e107->user_class; + $this->_uc = &$e107->user_class; } function text($name, $value, $maxlength = 200, $options = array()) @@ -162,6 +162,37 @@ class e_form return $this->checkbox($name, $selector, false, array('id'=>false,'class'=>'checkbox toggle-all')); } + function uc_checkbox($name, $current_value, $uc_options, $field_options = array()) + { + if(!is_array($field_options)) parse_str($field_options, $field_options); + return ' +
+ '.$this->_uc->vetted_tree($name, array($this, '_uc_checkbox_cb'), $current_value, $uc_options, $field_options).' +
+ '; + } + + function _uc_checkbox_cb($treename, $classnum, $current_value, $nest_level, $field_options) + { + if($classnum == e_UC_BLANK) + return ''; + + $tmp = explode(',', $current_value); + + $class = $style = ''; + if($nest_level == 0) + { + $class = " strong"; + } + else + { + $style = " style='text-indent:" . (1.2 * $nest_level) . "em'"; + } + $descr = varset($field_options['description']) ? ' ('.$this->_uc->uc_get_classdescription($classnum).')' : ''; + + return "
".$this->checkbox($treename.'[]', $classnum, in_array($classnum, $tmp), $field_options).$this->label($this->_uc->uc_get_classname($classnum), $treename.'[]', $classnum).$descr."
\n"; + } + function radio($name, $value, $checked = false, $options = array()) { $options['checked'] = $checked; //comes as separate argument just for convenience @@ -209,12 +240,10 @@ class e_form { return $this->select_open($name, $options)."\n".$this->option_multi($option_array, $selected)."\n".$this->select_close(); } - - //UNDER CONSTRUCTION - function uc_select($name, $default, $uc_options, $select_options = array(), $opt_options = array()) + + function uc_select($name, $current_value, $uc_options, $select_options = array(), $opt_options = array()) { - $ret = $this->uc->vetted_tree($name, array($this, '_uc_select_cb'), $default, $uc_options, $opt_options); - return $this->select_open($name, $select_options).$ret.$this->select_close(); + return $this->select_open($name, $select_options).$this->_uc->vetted_tree($name, array($this, '_uc_select_cb'), $current_value, $uc_options, $opt_options).$this->select_close(); } // Callback for vetted_tree - Creates the option list for a selection box @@ -238,10 +267,9 @@ class e_form { $prefix = '  '.str_repeat('--', $nest_level - 1).'>'; $style = ''; - } - return $this->option($prefix.$this->uc->uc_get_classname($classnum), $classnum, in_array($classnum, $tmp), "style={$style}"); + } + return $this->option($prefix.$this->_uc->uc_get_classname($classnum), $classnum, in_array($classnum, $tmp), "style={$style}"); } - //UNDER CONSTRUCTION END function optgroup_open($label, $disabled) { diff --git a/e107_handlers/userclass_class.php b/e107_handlers/userclass_class.php index 1e47ce6bb..c421e9e18 100644 --- a/e107_handlers/userclass_class.php +++ b/e107_handlers/userclass_class.php @@ -11,9 +11,9 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/userclass_class.php,v $ -| $Revision: 1.29 $ -| $Date: 2009-01-20 22:22:01 $ -| $Author: e107steved $ +| $Revision: 1.30 $ +| $Date: 2009-01-20 22:37:49 $ +| $Author: secretr $ +----------------------------------------------------------------------------+ */ @@ -482,7 +482,7 @@ class user_class $current_value is a single class number for single-select dropdown; comma separated array of class numbers for checkbox list or multi-select $optlist works the same as for other class displays */ - function vetted_sub_tree($treename, $callback,$listnum,$nest_level,$current_value, $perms) + function vetted_sub_tree($treename, $callback,$listnum,$nest_level,$current_value, $perms, $opt_options) { $ret = ''; $nest_level++; @@ -491,9 +491,9 @@ class user_class // Looks like we don't need to differentiate between function and class calls if (isset($perms[$p])) { - $ret .= call_user_func($callback,$treename, $p,$current_value,$nest_level); + $ret .= call_user_func($callback,$treename, $p,$current_value,$nest_level, $opt_options); } - $ret .= $this->vetted_sub_tree($treename, $callback,$p,$nest_level,$current_value, $perms); + $ret .= $this->vetted_sub_tree($treename, $callback,$p,$nest_level,$current_value, $perms, $opt_options); } return $ret; } @@ -514,9 +514,9 @@ class user_class { if (isset($perms[$p])) { - $ret .= call_user_func($callback,$treename, $p,$current_value,0); + $ret .= call_user_func($callback,$treename, $p,$current_value,0, $opt_options); } - $ret .= $this->vetted_sub_tree($treename, $callback,$p,0, $current_value, $perms. $opt_options); + $ret .= $this->vetted_sub_tree($treename, $callback,$p,0, $current_value, $perms, $opt_options); } return $ret; } diff --git a/e107_themes/_blank/admin_style.css b/e107_themes/_blank/admin_style.css index 009e447ac..b976ecf3c 100644 --- a/e107_themes/_blank/admin_style.css +++ b/e107_themes/_blank/admin_style.css @@ -147,6 +147,7 @@ label { cursor: pointer; } .field-help { width: 280px; line-height: 1.4em; padding-top: 3px; color:#333333; font-size: 11px; } .label-note { font-style: italic; } .form-note { font-style: italic; } +.field-spacer.strong { font-weight: bold } /* Related JS functionality - .autocheck together with .auto-toggle-area (see admin/image.php) */ .auto-toggle-area { width: 280px; cursor: pointer; }