Okay--I'll explain what I'm trying to do, and what I've done, and maybe somebody can point out the flaw (or tell me an easier way to do this).
We have three basic user levels in addition to the admin: moderator, Validated, and general users. General users are allowed to submit stories to the general and challenge categories only. Validated users can submit to those plus the validated category, and moderators can submit to those plus the moderator category.
The problem we were running into is that people were just submitting to whatever category they want, regardless of their status. We can't lock the categories & move the stories ourselves, because it's just too many. We also can't constantly be moving the "accidentally" placed stories.
So what I wanted to do was modify the categories.php include so that their selection form would only include their selectable categories. It works...kind of. I made a new page (categoriesnew.php) and included it in the storyform instead. When a user views the Add New Story page, it works--they just see their allowed categories. In the images below, Moderator is the Mod category, Top Level is Validated, and Locked is General. This user is a Validated user.
.
What does NOT work is that when they click on a category (like Top Level), it brings up the Back to Main Categories text and when they click that, voila: all three categories, even the one they aren't supposed to see:
.
Does anyone have any suggestions as to what else I need to do to keep them from seeing those categories? I think it has something to do with the javascript function, but I know nothing about javascript. π
function resetCats(catoptions) {
var selItem = document.getElementById(catoptions).selectedIndex;
var selValue = document.getElementById(catoptions).options[selItem].value;
var element = document.getElementById(catoptions);
element.options.length = 0;
element.options[element.options.length] = new Option(lang['Back2Cats'], -1);
for(z = 0; z < categories.length; z++) {
if(categories[z].pid == selValue || categories[z].catid == selValue)
element.options[element.options.length] = new Option(categories[z].name, categories[z].catid);
}
if(selValue != -1) element.options.selectedIndex = 1;
}
EDIT TO ADD: What I need to know is how to change the list of categories that the script pulls. Where is it getting the list of catoptions from? If I can modify that (or just add a new function for each user level), I can make this work properly.
Here's the categoriesnew.php if it helps:
<?php
if(!defined("_CHARSET")) exit( );
if(!isset($catid)) $catid = array( );
if(isVAL) {
$output .= "<div style='width: 99.9%; float: left;'>rn
<div style='width: 40%; float: left;'><label for='catoptions'>"._CATOPTIONS."</label> <br />
<select name='catoptions' id='catoptions' multiple='multiple' size='8' onchange='resetCats("catoptions");' style='width: 100%;'>";
$selectedCats = "";
$cats = array( );
$catlistnew = array( );
$catresultsnew = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_categories WHERE slevel <=1 ORDER BY leveldown, displayorder");
while ($catnew = dbassoc($catresultsnew)) {
$catlistnew[$catnew['catid']] = array("name" => stripslashes($catnew['category']), "pid" => $catnew['parentcatid'], "order" => $catnew['displayorder'], "locked" => $catnew['locked'], "leveldown" => $catnew['leveldown']);
}
foreach($catlistnew as $catnew => $info) {
if($info['pid'] == -1)
$output .= "<option value='$catnew'".(isset($info['locked']) ? " class='locked'" : "").">".$info['name']."</option>rn";
if((is_array($catid) && in_array($catnew, $catid)) && $info['locked'] != 1) {
$selectedCats .= "<option value='$catnew'>".$info['name']."</option>rn";
$cats[] = $catnew;
}
}
$output .= "</select></div>
<div style='float: left; width: 20%; text-align: center; padding-top: 3em;'>
<input type='button' class='button' value='Select' name='Select' onClick='addCat("catoptions", "selectCats");'><br /><br />
<input type='button' class='button' value='"._REMOVE."' onClick='removeCat("selectCats");'>
</div>
<div style='width: 40%; float: left;'>
<label for='catoptions'>"._SELECTCATS."</label> ".(count($cats) < 1 ? "<span style="font-weight: bold; color: red">*</span>" : "")."<br />
<select name='selectCats' id='selectCats' multiple='multiple' size='8' style='width: 100%;'>".
(!empty($selectedCats) ? $selectedCats : "")."</select></div>
</div>
<input type='hidden' name='catid' id='catid' value='".(isset($cats) ? implode(",", $cats) : "")."'>";
}
else if(!isMOD) {
$output .= "<div style='width: 99.9%; float: left;'>rn
<div style='width: 40%; float: left;'><label for='catoptions'>"._CATOPTIONS."</label> <br />
<select name='catoptions' id='catoptions' multiple='multiple' size='8' onchange='resetCats("catoptions");' style='width: 100%;'>";
$selectedCats = "";
$cats = array( );
$catlistnew = array( );
$catresultsnew = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_categories WHERE slevel <=2 ORDER BY leveldown, displayorder");
while ($catnew = dbassoc($catresultsnew)) {
$catlistnew[$catnew['catid']] = array("name" => stripslashes($catnew['category']), "pid" => $catnew['parentcatid'], "order" => $catnew['displayorder'], "locked" => $catnew['locked'], "leveldown" => $catnew['leveldown']);
}
foreach($catlistnew as $catnew => $info) {
if($info['pid'] == -1)
$output .= "<option value='$catnew'".(isset($info['locked']) ? " class='locked'" : "").">".$info['name']."</option>rn";
if((is_array($catid) && in_array($catnew, $catid)) && $info['locked'] != 1) {
$selectedCats .= "<option value='$catnew'>".$info['name']."</option>rn";
$cats[] = $catnew;
}
}
$output .= "</select></div>
<div style='float: left; width: 20%; text-align: center; padding-top: 3em;'>
<input type='button' class='button' value='Select' name='Select' onClick='addCat("catoptions", "selectCats");'><br /><br />
<input type='button' class='button' value='"._REMOVE."' onClick='removeCat("selectCats");'>
</div>
<div style='width: 40%; float: left;'>
<label for='catoptions'>"._SELECTCATS."</label> ".(count($cats) < 1 ? "<span style="font-weight: bold; color: red">*</span>" : "")."<br />
<select name='selectCats' id='selectCats' multiple='multiple' size='8' style='width: 100%;'>".
(!empty($selectedCats) ? $selectedCats : "")."</select></div>
</div>
<input type='hidden' name='catid' id='catid' value='".(isset($cats) ? implode(",", $cats) : "")."'>";
}
else {
$output .= "<div style='width: 99.9%; float: left;'>rn
<div style='width: 40%; float: left;'><label for='catoptions'>"._CATOPTIONS."</label> <br />
<select name='catoptions' id='catoptions' multiple='multiple' size='8' onchange='resetCats("catoptions");' style='width: 100%;'>";
$selectedCats = "";
$cats = array( );
$catlistnew = array( );
$catresultsnew = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_categories WHERE slevel =0 ORDER BY leveldown, displayorder");
while ($catnew = dbassoc($catresultsnew)) {
$catlistnew[$catnew['catid']] = array("name" => stripslashes($catnew['category']), "pid" => $catnew['parentcatid'], "order" => $catnew['displayorder'], "locked" => $catnew['locked'], "leveldown" => $catnew['leveldown']);
}
foreach($catlistnew as $catnew => $info) {
if($info['pid'] == -1)
$output .= "<option value='$catnew'".(isset($info['locked']) ? " class='locked'" : "").">".$info['name']."</option>rn";
if((is_array($catid) && in_array($catnew, $catid)) && $info['locked'] != 1) {
$selectedCats .= "<option value='$catnew'>".$info['name']."</option>rn";
$cats[] = $catnew;
}
}
$output .= "</select></div>
<div style='float: left; width: 20%; text-align: center; padding-top: 3em;'>
<input type='button' class='button' value='Select' name='Select' onClick='addCat("catoptions", "selectCats");'><br /><br />
<input type='button' class='button' value='"._REMOVE."' onClick='removeCat("selectCats");'>
</div>
<div style='width: 40%; float: left;'>
<label for='catoptions'>"._SELECTCATS."</label> ".(count($cats) < 1 ? "<span style="font-weight: bold; color: red">*</span>" : "")."<br />
<select name='selectCats' id='selectCats' multiple='multiple' size='8' style='width: 100%;'>".
(!empty($selectedCats) ? $selectedCats : "")."</select></div>
</div>
<input type='hidden' name='catid' id='catid' value='".(isset($cats) ? implode(",", $cats) : "")."'>";
}
?>
URL to your eFiction: http://www.mickiclark.com/efiction33
Version of eFiction: 3.3.1
Have you bridged eFiction, if so with what?: SMF
Version of PHP:
Version of MySQL: MySQL 4.1.14
You'll have to re-write the javascript.
