As many of you know 4images has a build-in categories dropdown form on upload page if u access it without specifying a category id (
http://example.com/4images/member.php?action=uploadform)
Its all good, but if u have different upload permissions for the categories, visitor might get upset if they select a category, select a file, hit upload button and see error messages that sais "you dont have permission to upload in that category"... In other words, the build-in dropdown form does not show which category is allowed for uploading.
This mod will fix that issue, it will show in different colors the categories with upload permissions and without:
--------- [ Changed files ] -----------member.php
includes/functions.php
templates/<your template>/style.css
templates/<your template>/member_uploadform.html (optional)
----------- [ Installation ] -------------Step 1Open
member.phpFind:
"cat_name" => ($cat_id != 0) ? htmlspecialchars($cat_cache[$cat_id]['cat_name']) : get_category_dropdown($cat_id),
Replace it with:
/*
MOD UPLOAD CATEGORIES DROPDOWN
ORIGINAL LINE:
"cat_name" => ($cat_id != 0) ? htmlspecialchars($cat_cache[$cat_id]['cat_name']) : get_category_dropdown($cat_id),
*/
/*
MOD UPLOAD CATEGORIES DROPDOWN
BEGIN REPLACE
*/
// "cat_name" => get_category_dropdown_upload($cat_id),
"cat_name" => ($cat_id != 0 && (!isset($HTTP_POST_VARS['showdropdown']))) ? htmlspecialchars($cat_cache[$cat_id]['cat_name']) : get_category_dropdown_upload($cat_id)."<input type=\"hidden\" name=\"showdropdown\" value=\"1\">",
"cat_name_required" => addslashes(preg_replace("/".$site_template->start."field_name".$site_template->end."/siU", str_replace(":", "", $lang['category']), $lang['field_required'])),
/*
MOD UPLOAD CATEGORIES DROPDOWN
END REPLACE
*/
Step 2Open
includes/functions.phpAt the end,
above closing
?> insert:
/*
MOD UPLOAD CATEGORIES DROPDOWN
BEGIN INSERT
*/
function get_category_dropdown_upload_bits($cat_id = 0, $cid = 0, $depth = 1)
{
global $site_db, $drop_down_cat_cache, $cat_cache, $config;
if (!isset($drop_down_cat_cache[$cid]))
{
return "";
}
$category_list = "";
foreach ($drop_down_cat_cache[$cid] as $key => $category_id)
{
if (check_permission("auth_viewcat", $category_id))
{
if (check_permission("auth_upload", $category_id))
{
$disable = 0;
}
else
{
$disable = 1;
}
$category_list .= "<option value=\"".(($disable) ? 0 : $category_id)."\"";
if ($cat_id == $category_id)
{
$category_list .= " selected=\"selected\"";
}
if ($disable)
{
if (($cat_cache[$category_id]['cat_parent_id'] == 0))
{
$category_list .= " class=\"dropdowndisable\""; //upload not avalable and this is a main category
}
else
{
$category_list .= " class=\"dropdowndisable\""; //upload not avalable
}
}
else
{
if (($cat_cache[$category_id]['cat_parent_id'] == 0))
{
// $category_list .= " class=\"dropdownmarker\""; //upload avalable and this is a main category
}
else
{
// $category_list .= " class=\"dropdownok\""; //upload avalable
}
}
// $category_list .= ">".(($disable) ? "- " : "+ ");
$category_list .= ">";
if ($depth > 1)
{
$category_list .= str_repeat("--", $depth - 1)." ";
}
$category_list .= $cat_cache[$category_id]['cat_name']."</option>\n";
$category_list .= get_category_dropdown_upload_bits($cat_id, $category_id, $depth + 1);
}
}
unset($drop_down_cat_cache[$cid]);
return $category_list;
}
function get_category_dropdown_upload($cat_id = 0)
{
global $lang, $drop_down_cat_cache, $cat_parent_cache;
$category = "\n<select name=\"cat_id\" class=\"categoryselect\">\n";
$category .= "<option value=\"0\">".$lang['select_category']."</option>\n";
$category .= "<option value=\"0\">---------------------------------------------------------</option>\n";
$drop_down_cat_cache = array();
$drop_down_cat_cache = $cat_parent_cache;
$category .= get_category_dropdown_upload_bits($cat_id);
$category .= "</select>\n";
return $category;
}
/*
MOD UPLOAD CATEGORIES DROPDOWN
END INSERT
*/
Step 3Open
templates/<your template>/style.cssAdd this block:
/* parent category, not allowed upload */
.dropdownmarkerdisable {
font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif;
background-color: #EEEEEE;
color: #A7A7A7;
font-size: 11px;
}
/* child category, not allowed upload */
.dropdowndisable {
font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif;
color: #BEBEBE;
font-size: 11px;
}
/* child category, allowed upload */
.dropdownok {
font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif;
color: #136c99;
font-size: 11px;
}
(the style is based on default template)
Step 4This is an optional step. It will show an alert message if visitor selected a category where they are not allowed upload in to.
Open
templates/<your template>/member_uploadform.htmlInsert inside
<form> this:
onsubmit="if(cat_id.value==0){alert('{cat_name_required}');return false;}"
In the default template the result would be the following:
<form method="post" action="{url_member}" enctype="multipart/form-data" onsubmit="if(cat_id.value==0){alert('{cat_name_required}');return false;} uploadbutton.disabled=true;">
--------- [ Tweaks ] ----------- If you would like to see categories dropdown even if a category id specifyed (http://example.com/4images/member.php?action=uploadform&cat_id=123) then in Step 1 replace
// "cat_name" => get_category_dropdown_upload($cat_id),
"cat_name" => ($cat_id != 0 && (!isset($HTTP_POST_VARS['showdropdown']))) ? htmlspecialchars($cat_cache[$cat_id]['cat_name']) : get_category_dropdown_upload($cat_id)."<input type=\"hidden\" name=\"showdropdown\" value=\"1\">",
With this: "cat_name" => get_category_dropdown_upload($cat_id),
// "cat_name" => ($cat_id != 0 && (!isset($HTTP_POST_VARS['showdropdown']))) ? htmlspecialchars($cat_cache[$cat_id]['cat_name']) : get_category_dropdown_upload($cat_id)."<input type=\"hidden\" name=\"showdropdown\" value=\"1\">",
- If you would like see different styles for allowed upload parent categories and allowed upload child categories (subcategories), uncomment commented lines in Step 2 (read the comments for more info which line uses when)
NOTE:
Opera users will see dropdown with one color, because Opera does not support style for individual items in the dropdown.