[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | ©Steve Dunstan 2001-2002 7 | http://e107.org 8 | jalist@e107.org 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $Source: /cvsroot/e107/e107_0.7/e107_handlers/userclass_class.php,v $ 14 | $Revision: 1.20 $ 15 | $Date: 2006/12/04 13:43:47 $ 16 | $Author: mrpete $ 17 +----------------------------------------------------------------------------+ 18 */ 19 20 if (!defined('e107_INIT')) { exit; } 21 22 @include_once(e_LANGUAGEDIR.e_LANGUAGE."/lan_userclass.php"); 23 @include_once(e_LANGUAGEDIR."English/lan_userclass.php"); 24 25 /* 26 With $optlist you can now specify which classes are shown in the dropdown. 27 All or none can be included, separated by comma (or whatever). 28 Valid options are: 29 public 30 guest 31 nobody 32 member 33 readonly 34 admin 35 main - main admin 36 classes - shows all classes 37 matchclass - if 'classes' is set, this option will only show the classes that the user is a member of 38 language - list of languages. 39 40 */ 41 42 function r_userclass($fieldname, $curval = 0, $mode = "off", $optlist = "") { 43 global $pref; 44 45 $text = "<select class='tbox' name='{$fieldname}'>\n"; 46 if (!$optlist || strpos($optlist, "public") !== FALSE) { 47 $s = ($curval == e_UC_PUBLIC) ? "selected='selected'" : ""; 48 $text .= "<option value='".e_UC_PUBLIC."' ".$s.">".UC_LAN_0."</option>\n"; 49 } 50 51 if (!$optlist || strpos($optlist, "guest") !== FALSE) { 52 $s = ($curval == e_UC_GUEST) ? "selected='selected'" : ""; 53 $text .= "<option value='".e_UC_GUEST."' ".$s.">".UC_LAN_1."</option>\n"; 54 } 55 if (!$optlist || strpos($optlist, "nobody") !== FALSE) { 56 $s = ($curval == e_UC_NOBODY) ? "selected='selected'" : ""; 57 $text .= "<option value='".e_UC_NOBODY."' ".$s.">".UC_LAN_2."</option>\n"; 58 } 59 if (!$optlist || strpos($optlist, "member") !== FALSE) { 60 $s = ($curval == e_UC_MEMBER) ? "selected='selected'" : ""; 61 $text .= "<option value='".e_UC_MEMBER."' ".$s.">".UC_LAN_3."</option>\n"; 62 } 63 if ($mode != "off" || strpos($optlist, "admin") !== FALSE) 64 { 65 $s = ($curval == e_UC_ADMIN) ? "selected='selected'" : ""; 66 $text .= "<option value='".e_UC_ADMIN."' ".$s.">".UC_LAN_5."</option>\n"; 67 } 68 if ($mode != "off" || strpos($optlist, "main") !== FALSE) 69 { 70 $s = ($curval == e_UC_MAINADMIN) ? "selected='selected'" : ""; 71 $text .= "<option value='".e_UC_MAINADMIN."' ".$s.">".UC_LAN_6."</option>\n"; 72 } 73 if (!$optlist || strpos($optlist, "classes") !== FALSE) 74 { 75 $classList = get_userclass_list(); 76 foreach($classList as $row) 77 { 78 extract($row); 79 if (strpos($optlist, "matchclass") === FALSE || getperms("0") || check_class($userclass_id)) 80 { 81 $s = ($userclass_id == $curval) ? "selected='selected'" : ""; 82 $text .= "<option value='$userclass_id' ".$s.">".$userclass_name ."</option>\n"; 83 } 84 } 85 } 86 if (($mode != "off" && $mode != "admin") || strpos($optlist, "readonly") !== FALSE) 87 { 88 $s = ($curval == e_UC_READONLY) ? "selected='selected'" : ""; 89 $text .= "<option value='".e_UC_READONLY."' ".$s.">".UC_LAN_4."</option>\n"; 90 } 91 92 if (strpos($optlist, "language") !== FALSE && $pref['multilanguage']) { 93 $text .= "<option value=''> ------ </option>\n"; 94 $tmpl = explode(",",e_LANLIST); 95 foreach($tmpl as $lang){ 96 $s = ($curval == $lang) ? " selected='selected'" : ""; 97 $text .= "<option value='$lang' ".$s.">".$lang."</option>\n"; 98 } 99 } 100 101 102 $text .= "</select>\n"; 103 return $text; 104 } 105 106 function r_userclass_radio($fieldname, $curval = '') 107 { 108 ($curval == e_UC_PUBLIC) ? $c = " checked" : $c = ""; 109 $text = "<input type='radio' name='{$fieldname}' value='".e_UC_PUBLIC."' ".$c." />".UC_LAN_0."<br />"; 110 ($curval == e_UC_NOBODY) ? $c = " checked" : $c = ""; 111 $text .= "<input type='radio' name='{$fieldname}' value='".e_UC_NOBODY."' ".$c." />".UC_LAN_2."<br />"; 112 ($curval == e_UC_GUEST) ? $c = " checked" : $c = ""; 113 $text .= "<input type='radio' name='{$fieldname}' value='".e_UC_GUEST."' ".$c." />".UC_LAN_1."<br />"; 114 ($curval == e_UC_MEMBER) ? $c = " checked" : $c = ""; 115 $text .= "<input type='radio' name='{$fieldname}' value='".e_UC_MEMBER."' ".$c." />".UC_LAN_3."<br />"; 116 $classList = get_userclass_list(); 117 foreach($classList as $row) 118 { 119 extract($row); 120 ($row['userclass_id'] == $curval) ? $c = " checked" : $c = ""; 121 $text .= "<input type='radio' name='{$fieldname}' value='{$row['userclass_id']}' ".$c." />{$row['userclass_name']}<br />"; 122 } 123 return $text; 124 } 125 126 function r_userclass_check($fieldname, $curval = '', $optlist = "") 127 { 128 global $pref; 129 $curArray = explode(",", $curval); 130 $ret = ""; 131 $ret .= "<div class='tbox' style='margin-left:0px;margin-right:auto;width:60%;height:58px;overflow:auto'>"; 132 if (!$optlist || strpos($optlist, "public") !== FALSE) 133 { 134 $c = (in_array(e_UC_PUBLIC, $curArray)) ? " checked='checked' " : ""; 135 $ret .= "<label><input type='checkbox' name='{$fieldname}[".e_UC_PUBLIC."]' value='1' {$c} /> ".UC_LAN_0."</label><br />"; 136 } 137 138 if (!$optlist || strpos($optlist, "guest") !== FALSE) 139 { 140 $c = (in_array(e_UC_GUEST, $curArray)) ? " checked='checked' " : ""; 141 $ret .= "<label><input type='checkbox' name='{$fieldname}[".e_UC_GUEST."]' value='1' {$c} /> ".UC_LAN_1."</label><br />"; 142 } 143 144 if (!$optlist || strpos($optlist, "nobody") !== FALSE) 145 { 146 $c = (in_array(e_UC_NOBODY, $curArray)) ? " checked='checked' " : ""; 147 $ret .= "<label><input type='checkbox' name='{$fieldname}[".e_UC_NOBODY."]' value='1' {$c} /> ".UC_LAN_2."</label><br />"; 148 } 149 150 if (!$optlist || strpos($optlist, "member") !== FALSE) 151 { 152 $c = (in_array(e_UC_MEMBER, $curArray)) ? " checked='checked' " : ""; 153 $ret .= "<label><input type='checkbox' name='{$fieldname}[".e_UC_MEMBER."]' value='1' {$c} /> ".UC_LAN_3."</label><br />"; 154 } 155 156 if (!$optlist || strpos($optlist, "admin") !== FALSE) 157 { 158 $c = (in_array(e_UC_ADMIN, $curArray)) ? " checked='checked' " : ""; 159 $ret .= "<label><input type='checkbox' name='{$fieldname}[".e_UC_ADMIN."]' value='1' {$c} /> ".UC_LAN_5."</label><br />"; 160 } 161 162 if (!$optlist || strpos($optlist, "readonly") !== FALSE) 163 { 164 $c = (in_array(e_UC_READONLY, $curArray)) ? " checked='checked' " : ""; 165 $ret .= "<label><input type='checkbox' name='{$fieldname}[".e_UC_READONLY."]' value='1' {$c} /> ".UC_LAN_4."</label><br />"; 166 } 167 168 if (!$optlist || strpos($optlist, "classes") !== FALSE) 169 { 170 $classList = get_userclass_list(); 171 foreach($classList as $row) 172 { 173 if (strpos($optlist, "matchclass") === FALSE || getperms("0") || check_class($row['userclass_id'])) { 174 $c = (in_array($row['userclass_id'], $curArray)) ? " checked='checked' " : ""; 175 $ret .= "<label><input type='checkbox' name='{$fieldname}[{$row['userclass_id']}]' value='1' {$c} /> {$row['userclass_name']}</label><br />"; 176 } 177 } 178 } 179 180 if (strpos($optlist, "language") !== FALSE && $pref['multilanguage']) { 181 $ret .= "<hr />\n"; 182 $tmpl = explode(",",e_LANLIST); 183 foreach($tmpl as $lang){ 184 $c = (in_array($lang, $curArray)) ? " checked='checked' " : ""; 185 $ret .= "<label><input type='checkbox' name='{$fieldname}[{$lang}]' value='1' {$c} /> {$lang}</label><br />"; 186 } 187 } 188 189 190 191 $ret .= "</div>"; 192 return $ret; 193 } 194 195 function get_userclass_list() 196 { 197 if($classList = getcachedvars('uclass_list')) 198 { 199 return $classList; 200 } 201 else 202 { 203 global $sql; 204 $sql->db_Select('userclass_classes', "*", "ORDER BY userclass_name", "nowhere"); 205 $classList = $sql->db_getList(); 206 cachevars('uclass_list', $classList); 207 return $classList; 208 } 209 } 210 211 function r_userclass_name($id) { 212 $class_names = getcachedvars('userclass_names'); 213 if(!is_array($class_names)) 214 { 215 $sql = new db; 216 $class_names[e_UC_PUBLIC] = UC_LAN_0; 217 $class_names[e_UC_GUEST] = UC_LAN_1; 218 $class_names[e_UC_NOBODY] = UC_LAN_2; 219 $class_names[e_UC_MEMBER] = UC_LAN_3; 220 $class_names[e_UC_READONLY] = UC_LAN_4; 221 $class_names[e_UC_ADMIN] = UC_LAN_5; 222 if ($sql->db_Select("userclass_classes", "userclass_id, userclass_name", "ORDER BY userclass_name", "nowhere")) 223 { 224 while($row = $sql->db_Fetch()) 225 { 226 $class_names[$row['userclass_id']] = $row['userclass_name']; 227 } 228 } 229 cachevars('userclass_names', $class_names); 230 } 231 return $class_names[$id]; 232 } 233 234 class e_userclass { 235 function class_add($cid, $uinfoArray) 236 { 237 global $tp; 238 $sql2 = new db; 239 foreach($uinfoArray as $uid => $curclass) 240 { 241 if ($curclass) 242 { 243 $newarray = array_unique(array_merge(explode(',', $curclass), array($cid))); 244 $new_userclass = implode(',', $newarray); 245 } 246 else 247 { 248 $new_userclass = $cid; 249 } 250 $sql2->db_Update('user', "user_class='".$tp -> toDB($new_userclass, true)."' WHERE user_id=".intval($uid)); 251 } 252 } 253 254 function class_remove($cid, $uinfoArray) 255 { 256 global $tp; 257 $sql2 = new db; 258 foreach($uinfoArray as $uid => $curclass) 259 { 260 $newarray = array_diff(explode(',', $curclass), array('', $cid)); 261 if (count($newarray) > 1) 262 { 263 $new_userclass = implode(',', $newarray); 264 } 265 else 266 { 267 $new_userclass = $newarray[0]; 268 } 269 $sql2->db_Update('user', "user_class='".$tp -> toDB($new_userclass, true)."' WHERE user_id=".intval($uid)); 270 } 271 } 272 273 function class_create($ulist, $class_prefix = "NEW_CLASS_", $num = 0) 274 { 275 global $sql; 276 $varname = "uc_".$ulist; 277 if($ret = getcachedvars($varname)) 278 { 279 return $ret; 280 } 281 $ul = explode(",", $ulist); 282 array_walk($ul, array($this, 'munge')); 283 $qry = " 284 SELECT user_id, user_class from #user AS u 285 WHERE user_name = ".implode(" OR user_name = ", $ul); 286 if($sql->db_Select_gen($qry)) 287 { 288 while($row = $sql->db_Fetch()) 289 { 290 $idList[$row['user_id']] = $row['user_class']; 291 292 } 293 while($sql->db_Count("userclass_classes","(*)","WHERE userclass_name = '".strtoupper($class_prefix.$num)."'")) 294 { 295 $num++; 296 } 297 $newname = strtoupper($class_prefix.$num); 298 $i = 1; 299 while ($sql->db_Select('userclass_classes', '*', "userclass_id='".intval($i)."' ") && $i < 255) 300 { 301 $i++; 302 } 303 if ($i < 255) 304 { 305 $sql->db_Insert("userclass_classes", "{$i}, '{$newname}', 'Auto_created_class', 254"); 306 $this->class_add($i, $idList); 307 cachevars($varname, $i); 308 return $i; 309 } 310 } 311 312 } 313 314 function munge(&$value, &$key) 315 { 316 $value = "'".trim($value)."'"; 317 } 318 } 319 320 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |