Author Topic: [MOD] Categories upload dropdown form  (Read 58457 times)

0 Members and 1 Guest are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[MOD] Categories upload dropdown form
« on: May 02, 2005, 08:29:02 AM »
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 1
Open member.php
Find:
Code: [Select]
    "cat_name" => ($cat_id != 0) ? htmlspecialchars($cat_cache[$cat_id]['cat_name']) : get_category_dropdown($cat_id),Replace it with:
Code: [Select]
/*
  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 2
Open includes/functions.php
At the end, above closing ?> insert:
Code: [Select]
/*
  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 3
Open templates/<your template>/style.css
Add this block:
Code: [Select]
/* 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 4
This 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.html
Insert inside <form> this:
Code: [Select]
onsubmit="if(cat_id.value==0){alert('{cat_name_required}');return false;}"In the default template the result would be the following:
Quote
<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
    Code: [Select]
    //    "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:
    Code: [Select]
        "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.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline vanish

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • White Album
Re: [MOD] Categories upload dropdown form
« Reply #1 on: May 02, 2005, 01:38:00 PM »
Step 4 don't working. Alert never shown...
This code is right:
Code: [Select]
onsubmit="if (cat_id.options[cat_id.selectedIndex].value==0){ alert('{cat_name_required}'); return false;} uploadbutton.disabled=true;"

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: [MOD] Categories upload dropdown form
« Reply #2 on: May 03, 2005, 06:19:18 AM »
Quote
It will show an alert message if visitor selected a category where they are not allowed upload in to.

I don't  see any alert  :roll: :roll:  :?:

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Categories upload dropdown form
« Reply #3 on: May 03, 2005, 06:51:30 AM »
yes, vanish, thank you.
my JS knowlege is very limited, but this also worked fine in my tests:
Code: [Select]
onSubmit="if(cat_id.value==0){alert('{cat_name_required}');return false;}"
Step 4 is updated.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: [MOD] Categories upload dropdown form
« Reply #4 on: May 03, 2005, 07:22:00 AM »
I have update step 4 and i still don see the message http://69.56.196.226/~ascanio/member.php?action=uploadform

Offline vanish

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • White Album
Re: [MOD] Categories upload dropdown form
« Reply #5 on: May 03, 2005, 09:41:47 AM »
V@no, you have made misprint:
Quote
onsubmit="if(cat_id.value==0){alert('{cat_name_required}');return false;} return false;} uploadbutton.disabled=true;"
and ascanio paste this code in his page...

Offline ascanio

  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • http://www.surfourspace.net
Re: [MOD] Categories upload dropdown form
« Reply #6 on: May 03, 2005, 04:23:46 PM »
where it is supose to apear the alert message cuz i don't see anything :S

Offline vanish

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
    • White Album
Re: [MOD] Categories upload dropdown form
« Reply #7 on: May 03, 2005, 09:47:01 PM »
Right is:
Code: [Select]
onsubmit="if (cat_id.value==0){ alert('{cat_name_required}'); return false;} uploadbutton.disabled=true;"
or
Code: [Select]
onsubmit="if (cat_id.options[cat_id.selectedIndex].value==0){ alert('{cat_name_required}'); return false;} uploadbutton.disabled=true;"

Offline himu

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
    • Point Of View
Re: [MOD] Categories upload dropdown form
« Reply #8 on: March 03, 2006, 06:52:35 AM »
Hey V@no,
After installing this MOD
i am having following problem.. although the function "image upload" and "category dropdown" is working properly ...
check the attached file:
if i choose following settings, i only get this error if i choose member.php?action=uploadform:
Quote
//    "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\">",
but member.php?action=uploadform&cat_id=37 does not show this error.
BUT if i choose following settings, i get this error for both the options:
Quote
    "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\">",

HELP  :( :oops:
« Last Edit: March 03, 2006, 07:28:46 AM by himu »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Categories upload dropdown form
« Reply #9 on: March 03, 2006, 07:15:58 AM »
And what if you replace
Code: [Select]
      $category_list .= $cat_cache[$category_id]['cat_name']."</option>\n";with:
Code: [Select]
      $category_list .= str_replace("\"", "&quot;", str_replace("<", "&lt;", str_replace(">", "&gt;", $cat_cache[$category_id]['cat_name'])))."</option>\n";
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline himu

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
    • Point Of View
Re: [MOD] Categories upload dropdown form
« Reply #10 on: March 03, 2006, 07:33:33 AM »
That's in function.php .. the problem might be in member.php  :?:
anyway still no change ...  :(

And what if you replace
Code: [Select]
      $category_list .= $cat_cache[$category_id]['cat_name']."</option>\n";with:
Code: [Select]
      $category_list .= str_replace("\"", "&quot;", str_replace("<", "&lt;", str_replace(">", "&gt;", $cat_cache[$category_id]['cat_name'])))."</option>\n";

Offline himu

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
    • Point Of View
Re: [MOD] Categories upload dropdown form
« Reply #11 on: March 04, 2006, 07:44:01 AM »
V@no,

I also see following stuff in the Title bar:
Please Help...  :cry:

Offline webslingers

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: [MOD] Categories upload dropdown form
« Reply #12 on: April 19, 2006, 11:49:17 PM »
In step 1 it says to search for:
"cat_name" => ($cat_id != 0) ? htmlspecialchars($cat_cache[$cat_id]['cat_name']) : get_category_dropdown($cat_id),

but I have:
"cat_name" => ($cat_id != 0) ? format_text($cat_cache[$cat_id]['cat_name']) : get_category_dropdown($cat_id

What should I do about this?

Thanks

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Categories upload dropdown form
« Reply #13 on: April 20, 2006, 01:24:09 AM »
just replace it with the new block of code and then replace htmlspecialchars with format_text
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline sy4k4

  • Pre-Newbie
  • Posts: 9
    • View Profile
Re: [MOD] Categories upload dropdown form
« Reply #14 on: July 25, 2006, 12:37:59 AM »
i have error message

Please fill out the Category field!

4images 1.72