Author Topic: Will someone write me a small php snippet of code for.....  (Read 8308 times)

0 Members and 1 Guest are viewing this topic.

Offline lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Hi,
Can someone write me a small snippet of php coding that I can place in all my necessary php files that will do the following:

Get the users logged in name.
Check the mysql database for any category that is the same as the username
return the category #id of that matching category.

Basically I just want to have a direct link in the logininfo.html file so that when a user logs in, they have a direct link to the category that is the same as thier username.

On my system when a user registers I create a category with the same name as the user, and give only that user permission to upload, so it's their private category which is the same name as their logged in username.

Thanks,

Offline Apollo13

  • Addicted member
  • ******
  • Posts: 1.093
    • View Profile
Will someone write me a small php snippet of code for.....
« Reply #1 on: May 08, 2003, 06:48:01 PM »
Well V@no just did a mod private category... AMybe this is what u are looking 4...

Offline lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Will someone write me a small php snippet of code for.....
« Reply #2 on: May 08, 2003, 06:53:37 PM »
Thanks, No, thats too elaborate for my system, also it doesnt incoporate some other mods that i have in mine.

I just need a direct link to a category that is the same as the users name, even an alteration of the search function to search by category name and return that category would work I think.

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
Will someone write me a small php snippet of code for.....
« Reply #3 on: May 08, 2003, 09:07:06 PM »
well, then try this one:
in /includes/page_header.php find:
Code: [Select]
$site_template->register_vars(array(
that must be the first one from the top of the file ;)
replace it with:
Code: [Select]
$user_cat_id = "";
foreach($cat_cache as $key => $val){
if ("General" == $cat_cache[$key]['cat_name']) {
$user_cat_id = $key;
break;
}
}
$site_template->register_vars(array(
"user_cat_url" => ($user_cat_id) ? "&raquo; <a href=\"".$site_sess->url(ROOT_PATH."categories.php?cat_id=".$user_cat_id)."\">My category</a><br />" : "",


now u can use in any templates this tag:
{user_cat_url}

P.S. this is case sencetive, so if username is "Jack" and category name is "jack" it wont work.
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 lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Will someone write me a small php snippet of code for.....
« Reply #4 on: May 09, 2003, 05:48:17 PM »
Thanks,
I put the following in page_header.php in my includes directory:
Code: [Select]
//-----------------------------------------------------
//--- Register Global Vars ----------------------------
//-----------------------------------------------------
$total_images = 0;
$total_categories = 0;
$auth_cat_sql['auth_viewcat']['IN'] = 0;
$auth_cat_sql['auth_viewcat']['NOTIN'] = 0;
if (!empty($cat_cache)) {
  foreach ($cat_cache as $key => $val) {
    if (check_permission("auth_viewcat", $key)) {
      $total_categories++;
      if (isset($val['num_images'])) {
        $total_images += $val['num_images'];
      }
      else {
        $cat_cache[$key]['num_images'] = 0;
      }
      $auth_cat_sql['auth_viewcat']['IN'] .= ", ".$key;
    }
    else {
      $auth_cat_sql['auth_viewcat']['NOTIN'] .= ", ".$key;
    }
  }
}

  $user_cat_id = "";
foreach($cat_cache as $key => $val){
    if ("General" == $cat_cache[$key]['cat_name']) {
        $user_cat_id = $key;
        break;
    }
}
$site_template->register_vars(array(
"user_cat_url" => ($user_cat_id) ? "&raquo; <a href=\"".$site_sess->url(ROOT_PATH."categories.php?cat_id=".$user_cat_id)."\">My category</a>" : "",

"media_url" => MEDIA_PATH,
  "thumb_url" => THUMB_PATH,
  "icon_url" => ICON_PATH,
  "template_url" => TEMPLATE_PATH,
  "template_image_url" => TEMPLATE_PATH."/images",


I left in the top bit so you can see where I put it.

Now in my user_logininfo.html template I put {user_cat_url}

But then I login, and the user_logininfo.html doesnt show anything for {user_cat_url} its just a blank area.

What did I do wrong?  Theres no errors, its just blank where it should show My Category :

Offline lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Will someone write me a small php snippet of code for.....
« Reply #5 on: May 09, 2003, 06:10:03 PM »
Okay, I figured out part of it.

General needs to be changed to the parent category.

But my category structure is like
Users Galleries (main category)
A (Sub category under Users Galleries)
Anton (Sub Category under the A Subcategory)

I think this wont read past the main category, because now that I changed General to Users Galleries, it always gives back the same cat id of 30, which is what Users Galleries is in my database.

Help.  :(

Okay just tried something though,
I took the lakeside category and made it a subcategory of my Users Galleries
So it goes like this:
Users Galleries (main category)
lakeside (sub category under Users Galleries)

But it still only brings back the cat id of the Users Galleries and not lakeside category when logged in as lakeside.

Offline lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
V@no?
« Reply #6 on: May 10, 2003, 05:56:32 PM »
V@no, do you know what I did wrong here?

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: V@no?
« Reply #7 on: May 10, 2003, 06:05:51 PM »
Quote from: lakeside
V@no, do you know what I did wrong here?

ops...I'm sorry, I posted code from my "test" script...so, u must replace:
Code: [Select]
   if ("General" == $cat_cache[$key]['cat_name']) {
with:
Code: [Select]
   if ($user_info['user_name'] == $cat_cache[$key]['cat_name']) {
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 lakeside

  • Full Member
  • ***
  • Posts: 123
    • View Profile
Will someone write me a small php snippet of code for.....
« Reply #8 on: May 10, 2003, 06:13:20 PM »
EXCELLENT!  My everlasting thanks for this, this was the number one requested feature of our registered users.