From b635bdd84dbd5a0c66fb01446bde703c90af1925 Mon Sep 17 00:00:00 2001 From: e107steved Date: Tue, 8 Jan 2008 22:24:22 +0000 Subject: [PATCH] Userclasses - bug fixes, tidy display --- .../batch/usersettings_shortcodes.php | 42 ++++++++--------- e107_handlers/userclass_class.php | 38 ++++++++++----- usersettings.php | 47 ++++--------------- 3 files changed, 56 insertions(+), 71 deletions(-) diff --git a/e107_files/shortcode/batch/usersettings_shortcodes.php b/e107_files/shortcode/batch/usersettings_shortcodes.php index 8f5a88b39..47c43bead 100755 --- a/e107_files/shortcode/batch/usersettings_shortcodes.php +++ b/e107_files/shortcode/batch/usersettings_shortcodes.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_files/shortcode/batch/usersettings_shortcodes.php,v $ -| $Revision: 1.7 $ -| $Date: 2008-01-06 21:16:23 $ +| $Revision: 1.8 $ +| $Date: 2008-01-08 22:24:14 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -103,32 +103,32 @@ if($parm == 'radio') SC_END SC_BEGIN USERCLASSES -global $sql, $pref, $tp, $curVal; +global $e_userclass, $pref, $tp, $curVal; $ret = ""; if(ADMIN && $curVal['user_id'] != USERID) { return ""; } -if($sql->db_Select("userclass_classes", "*", "userclass_editclass IN(".$tp -> toDB($curVal['userclass_list'], true).") ORDER BY userclass_name")) -{ - $ucList = $sql->db_getList(); - $ret = ""; - foreach($ucList as $row) +if (!is_object($e_userclass)) $e_userclass = new user_class; +$ucList = explode(',',$e_userclass->get_editable_classes()); // List of classes which this user can edit +$ret = ''; +if(!count($ucList)) return; + + $is_checked = array(); + foreach ($ucList as $cid) + { + if (check_class($cid, $curVal['user_class'])) $is_checked[$cid] = $cid; + if(isset($_POST['class'])) { - $inclass = check_class($row['userclass_id'], $curVal['user_class']) ? TRUE : FALSE; - if(isset($_POST['class'])) - { - $inclass = in_array($row['userclass_id'], $_POST['class']); - } - $frm_checked = $inclass ? "checked='checked'" : ""; - $ret .= ""; - $ret .= ""; - $ret .= "\n"; + $is_checked[$cid] = in_array($cid, $_POST['class']); } - $ret .= "
"; - $ret .= "\n"; - $ret .= $tp->toHTML($row['userclass_name'], "", "defs")."".$tp->toHTML($row['userclass_description'], "", "defs")."
\n"; -} + } + $inclass = implode(',',$is_checked); + + $ret = "
"; + $ret .= $e_userclass->vetted_tree('class',array($e_userclass,checkbox_desc),$inclass,'editable'); + $ret .= "
\n"; + return $ret; SC_END diff --git a/e107_handlers/userclass_class.php b/e107_handlers/userclass_class.php index e436587fd..30d9a5112 100644 --- a/e107_handlers/userclass_class.php +++ b/e107_handlers/userclass_class.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_handlers/userclass_class.php,v $ -| $Revision: 1.8 $ -| $Date: 2008-01-07 22:30:19 $ +| $Revision: 1.9 $ +| $Date: 2008-01-08 22:24:22 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ */ @@ -158,18 +158,20 @@ class user_class function get_editable_classes($class_list = USERCLASS_LIST) { $ret = array(); + $blockers = array(e_UC_PUBLIC => 1, e_UC_READONLY => 1, e_UC_MEMBER => 1); $possibles = array_flip(explode(',',$class_list)); - foreach ($possibles as $uc => $uv) + unset($possibles[e_UC_PUBLIC]); + unset($possibles[e_UC_READONLY]); + foreach ($this->class_tree as $uc => $uv) { - $ec = $this->class_tree[$uc]['userclass_editclass']; - $vis = $this->class_tree[$uc]['userclass_visibility']; - if ( - (($ec == e_UC_PUBLIC) || isset($possibles[$ec])) - && - (($vis == e_UC_PUBLIC) || isset($possibles[$vis])) - ) + if (!isset($blockers[$uc])) { - $ret[] = $uc; + $ec = $this->class_tree[$uc]['userclass_editclass']; +// echo "Check class: {$uc} editclass {$ec} in array: ".(isset($possibles[$ec]) ? 'yes' : 'no').'
'; + if (isset($possibles[$ec])) + { + $ret[] = $uc; + } } } return implode(',',$ret); @@ -261,6 +263,17 @@ class user_class { $ret = array(); if (!$optlist) $optlist = 'public,guest,nobody,member,classes'; // Set defaults to simplify ongoing processing + + if ($optlist == 'editable') + { + $temp = array_flip(explode(',',$this->get_editable_classes())); + if ($just_ids) return $temp; + foreach ($temp as $c => $t) + { + $temp[$c] = $this->class_tree[$c]['userclass_name']; + } + return $temp; + } $opt_arr = explode(',',$optlist); foreach ($opt_arr as $k => $v) @@ -299,7 +312,7 @@ class user_class ) ) { - $ret[$uc_id] = $this->class_tree[$uc_id]['userclass_name']; + $ret[$uc_id] = $just_ids ? '1' : $this->class_tree[$uc_id]['userclass_name']; } } } @@ -391,7 +404,6 @@ class user_class $current_value = str_replace(' ','',$current_value); // Simplifies parameter passing for the tidy-minded $perms = $this->uc_required_class_list($optlist,TRUE); // List of classes which we can display - /* // Start with the fixed classes foreach ($this->fixed_classes as $c => $j) { diff --git a/usersettings.php b/usersettings.php index 9413b3e10..ca4f65ba3 100644 --- a/usersettings.php +++ b/usersettings.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/usersettings.php,v $ -| $Revision: 1.19 $ -| $Date: 2008-01-06 21:16:16 $ +| $Revision: 1.20 $ +| $Date: 2008-01-08 22:24:14 $ | $Author: e107steved $ +----------------------------------------------------------------------------+ @@ -23,7 +23,6 @@ Admin log events: */ -//echo "Starting usersettings
"; require_once("class2.php"); require_once(e_HANDLER."ren_help.php"); @@ -33,35 +32,6 @@ $ue = new e107_user_extended; //define("US_DEBUG",TRUE); define("US_DEBUG",FALSE); -/* -These links look redundant -if (isset($_POST['sub_news'])) -{ - header("location:".e_BASE."submitnews.php"); - exit; -} - -if (isset($_POST['sub_link'])) { - header("location:".e_PLUGIN."links_page/links.php?submit"); - exit; -} - -if (isset($_POST['sub_download'])) { - header("location:".e_BASE."upload.php"); - exit; -} - -if (isset($_POST['sub_article'])) { - header("location:".e_BASE."subcontent.php?article"); - exit; -} - -if (isset($_POST['sub_review'])) { - header("location:".e_BASE."subcontent.php?review"); - exit; -} -*/ - if (!USER) { // Must be logged in to change settings @@ -501,18 +471,20 @@ if (isset($_POST['updatesettings'])) // Update Userclass - only if its the user changing their own data (admins can do it another way) - if (!$_uid && $sql->db_Select("userclass_classes", "userclass_id", "userclass_editclass IN (".USERCLASS_LIST.")")) + if (!$_uid) { - $ucList = $sql->db_getList(); // List of classes which this user can edit - if (US_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Usersettings test","Read editable list. Current user classes: ".$udata['user_class'],FALSE,LOG_TO_ROLLING); + if (!is_object($e_userclass)) $e_userclass = new user_class; + $ucList = explode(',',$e_userclass->get_editable_classes()); // List of classes which this user can edit + if (count($ucList)) + { + if (US_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Usersettings test","Read editable list. Current user classes: ".$udata['user_class'],FALSE,LOG_TO_ROLLING); $cur_classes = explode(",", $udata['user_class']); // Current class membership $newclist = array_flip($cur_classes); // Array keys are now the class IDs // Update class list - we must take care to only change those classes a user can edit themselves - foreach ($ucList as $c) + foreach ($ucList as $cid) { - $cid = $c['userclass_id']; if(!in_array($cid, $_POST['class'])) { unset($newclist[$cid]); @@ -530,6 +502,7 @@ if (isset($_POST['updatesettings'])) if (US_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Usersettings test","Write back classes; old list: {$udata['user_class']}; new list: ".$nid,FALSE,LOG_TO_ROLLING); $changed_user_data['user_class'] = $nid; } + } }