In the 101 tutorial, I showed a very brief, easy way to add custom field capturing to GARS. In this version, I build off of the example given and create a slightly more sophisticated version to show off a couple more stages.
In this version of the Movie rating pull down box, I add the ability for the admin to select which ratings to show in the pull down box via the Settings stage and the persist settings stage. I am assuming you have already read the 101 tutorial!
Please note that this is not exactly how I would approach this, its just meant to try and be a guide that should be semi easy to
follow
.
Make sure you clean the input!
Here is the 102 completed code:
PHP Code:
<?php
if ($stage == "settings")
{
print_description_row("This module will allow users to select a rating for the movie");
if ($settings['my_rating_settings'])
{
foreach($settings['my_rating_settings'] as $key => $value)
{
if (!$keys)
{
$keys ="$key";
$texts = "$value";
}
else
{
$keys .=",$key";
$texts .= ",$value";
}
}
}
print_input_row("Ratings:<dfn>Enter each rating letter seperated by a comma (i.e. G,PG,R)</dfn>", "my_rating_keys[$itemid]", $keys);
print_input_row("Text:<dfn>Enter each rating description seperated by a comma (i.e. G - General,PG - Parental Guidance</dfn>", "my_rating_text[$itemid]", $texts);
}
elseif ($stage == "persistsettings")
{
global $vbulletin;
$vbulletin->input->clean_array_gpc('p',array(
'my_rating_keys' => TYPE_ARRAY_ARRAY_STR,
'my_rating_text' => TYPE_ARRAY_ARRAY_STR
));
$keys = $vbulletin->GPC['my_rating_keys'][$itemid];
$text = $vbulletin->GPC['my_rating_text'][$itemid];
$keyarray = explode(",",$keys);
$textarray = explode(",", $text);
$results = array();
if (is_array($keyarray))
{
foreach($keyarray as $itemkey => $itemvalue)
{
$results[$itemvalue] = $textarray[$itemkey];
}
}
$settings['my_rating_settings'] = $results;
}
elseif ($stage == "edit")
{
$items = $settings['my_rating_settings'];
if (is_array($items))
{
$output .= "Rating: <SELECT name=\"custom1[my_rating]\">";
foreach($items as $arraykey => $arrayvalue)
{
if ($values['my_rating'] == $arraykey)
{
$selected = "selected=\"selected\"";
}
else
{
$selected = "";
}
$output .= "<OPTION value=\"$arraykey\" $selected >$arrayvalue</OPTION>";
}
$output .="</SELECT>";
}
}
elseif($stage == "persist")
{
$my_rating = $this->vb->GPC['custom1']['my_rating'];
$values['my_rating'] = $my_rating;
}
elseif($stage == "display")
{
$title = "Rating";
$items = $settings['my_rating_settings'];
$bits = "<tr><td class=\"alt1\" align=\"center\">" . $items[$values['my_rating']] . "</td></tr>";
eval('$output.="' . fetch_template('GARS_mod_container') . '";');
}
?>