Author Topic: Easier way to add/sort categories?  (Read 50391 times)

0 Members and 1 Guest are viewing this topic.

Offline bgmurphy

  • Full Member
  • ***
  • Posts: 113
    • View Profile
Easier way to add/sort categories?
« Reply #15 on: June 18, 2003, 05:11:52 PM »
jan -

thanx for this snippet  :D

it was very frustrating to add the category and then move it to the top of a long list until i found this !!

now ... the next question ...  8)

is it possible to create a collapsable menu structure in the admin panel for the categories routine so that one does not have to see a long list when working in admin > add(edit) cateogories ??

thanx
bruce

Offline zzzmarcus

  • Pre-Newbie
  • Posts: 4
    • View Profile
    • http://www.silverfish.cc
Re: Easier way to add/sort categories?
« Reply #16 on: June 29, 2005, 04:22:06 AM »
Would you mind posting that file again? The link is dead.

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
Re: Easier way to add/sort categories?
« Reply #17 on: July 04, 2005, 05:40:35 PM »
Fixed
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: Easier way to add/sort categories?
« Reply #18 on: July 04, 2005, 06:55:30 PM »
hi Jan,

also ... thanks for this nice tiny mod ...   :D

mawenzi
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline H2015

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: Easier way to add/sort categories?
« Reply #19 on: July 08, 2005, 12:28:18 AM »
Jan, you SAVED MY LIFE.  8O

I've been literally begging friends to help me with something like this and I had a post here about this problem but I didn't get the help I needed except getting forwarded to the "sort by alphabetical order" mod which is not what I wanted.

I have a fansite on a singer where I get new and old pics daily and must oder them by the date the picture was taken and it's an extremely long list of categories so you can imagine how many times I click the "move up" button whenever I wanted to update! What you did is exactly what I needed and I also must say thank you to X-Fan for asking for it correctly!

I can't thank you enough Jan, you made my day!!!

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: Easier way to add/sort categories?
« Reply #20 on: July 08, 2005, 12:47:33 AM »
... so you can imagine how many times I click the "move up" button ...
... yes, I can ... :mrgreen:

mawenzi
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline kief24

  • Sr. Member
  • ****
  • Posts: 267
    • View Profile
Re: Easier way to add/sort categories?
« Reply #21 on: September 07, 2005, 03:31:05 PM »
this is great !

thx Jan !

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: Easier way to add/sort categories?
« Reply #22 on: October 26, 2005, 11:29:09 PM »
what a great MOD!

additional to this MOD I have  implemented the following MOD:
[MOD] Category Image v1.0.1 by V@no
http://www.4homepages.de/forum/index.php?topic=6922.0

I took the original file categories.php and implemented the MOD from V@no.
I could enter an Image-ID and save the category. Everythink worked fine.

Than I took the file categories.php from this MOD and implemented the MOD from V@no.
Now I could enter an Image-ID and save. Everytime I load the category again, the Image-ID wasn't display anymore (but still stored in the DB).

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: Easier way to add/sort categories?
« Reply #23 on: November 09, 2005, 07:26:42 PM »
Jan, V@no

Is it possible to have a look on my problem?

Thank you!

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: Easier way to add/sort categories?
« Reply #24 on: November 10, 2005, 12:21:28 AM »
My bet would be you missted step 2.3 or/and 2.5
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 TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: Easier way to add/sort categories?
« Reply #25 on: November 13, 2005, 12:18:32 PM »
No, I didn't miss it. here is my categories.php

Code: [Select]
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: categories.php                                       *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7                                                  *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/

define('IN_CP'1);
define('ROOT_PATH''./../');
require(
'admin_global.php');

include(
ROOT_PATH.'includes/search_utils.php');

if (
$action == "") {
  
$action "modifycats";
}

$access_field_array = array(
  
"auth_viewcat" => AUTH_ALL,
  
"auth_viewimage" => AUTH_ALL,
  
"auth_download" => AUTH_ACL,
  
"auth_upload" => AUTH_ACL,
  
"auth_directupload" => AUTH_ACL,
  
"auth_vote" => AUTH_ACL,
  
"auth_sendpostcard" => AUTH_ACL,
  
"auth_readcomment" => AUTH_ACL,
  
"auth_postcomment" => AUTH_ACL
);

$access_array = array(
  
AUTH_ALL => $lang['all'],
  
AUTH_USER => $lang['userlevel_registered'],
  
AUTH_ACL => $lang['private'],
  
AUTH_ADMIN => $lang['userlevel_admin']
);

function 
show_access_select($title ""$type$status) {
  global 
$access_array$HTTP_POST_VARS;
  if (isset(
$HTTP_POST_VARS[$type])) {
    
$status $HTTP_POST_VARS[$type];
  }
  echo 
"<tr class=\"".get_row_bg()."\" valign=\"top\">\n<td><p class=\"rowtitle\">".$title."</p></td>\n";
  echo 
"<td>\n<select name=\"".$type."\">\n";
  foreach (
$access_array as $key => $val) {
    echo 
"<option value=\"".$key."\"";
    if (
$status == $key) {
      echo 
" selected=\"selected\"";
    }
    echo 
">".$val."</option>\n";
  }
  echo 
"</select>\n</td>\n</tr>\n";
}

function 
create_cat_folder($path$mode) {
  if (@
is_dir($path)) {
    @
chmod($path$mode);
    return 
true;
  }
  else {
    
$oldumask umask(0);
    
$result mkdir($path$mode);
    
umask($oldumask);
    if (!@
is_dir($path) || !$result) {
      
$result mkdir($path0755);
      @
chmod($path$mode);
    }
    return 
$result;
  }
}

function 
remove_cat_folder($path) {
  
$ok 1;
  if (@
is_dir($path)) {
    
$handle opendir($path);
    while (
$file = @readdir($handle)) {
      if (
$file != "." && $file != "..") {
        
$ok = (!remove_cat_folder($path."/".$file)) ? $ok;
      }
    }
    
closedir($handle);
    
$ok = (!rmdir($path)) ? $ok;
  }
  else {
    
$ok = (!unlink($path)) ? $ok;
  }
  return 
$ok;
}

function 
remove_subcategories($cid 0$depth 1) {
  global 
$site_db$error_log$lang$category_cache;

  if (!isset(
$category_cache[$cid])) {
    return 
false;
  }
  foreach (
$category_cache[$cid] as $key => $cats) {
    echo 
"<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\"><tr><td>\n";
    if (
$depth 1) {
      echo 
str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;"$depth 1)."\n";
    }
    echo 
"</td><td>\n";

    
$sql "DELETE FROM ".GROUP_ACCESS_TABLE.
            WHERE cat_id = "
.$cats['cat_id'];
    
$site_db->query($sql);

    
$sql "DELETE FROM ".CATEGORIES_TABLE.
            WHERE cat_id = "
.$cats['cat_id'];

    if (
$site_db->query($sql)) {
      echo 
$lang['cat_delete_success']." <b>".$cats['cat_name']."</b> (ID: ".$cats['cat_id'].")<br />\n";
    }
    else {
      
$error_log[] = $lang['cat_delete_error']." <b>".$cats['cat_name']."</b> (ID: ".$cats['cat_id'].")";
    }

    
$sql "SELECT image_id 
            FROM "
.IMAGES_TABLE.
            WHERE cat_id = "
.$cats['cat_id'];
    
$img_result $site_db->query($sql);

    
$image_ids_sql 0;
    while (
$image_row $site_db->fetch_array($img_result)) {
      
$image_ids_sql .= (($image_ids_sql != "") ? ", " "").$image_row['image_id'];
    }

    
$sql "DELETE FROM ".IMAGES_TABLE.
            WHERE image_id IN (
$image_ids_sql)";
    if (
$site_db->query($sql)) {
      echo 
"-&raquo ".$lang['image_delete_success']."<br />\n";
    }
    else {
      
$error_log[] = $lang['image_delete_error']." (".$cats['cat_name'].", ID: ".$cats['cat_id'].")";
    }

    if (!empty(
$cats['cat_id'])) {
      if (
remove_cat_folder(MEDIA_PATH."/".$cats['cat_id'])) {
        echo 
"-&raquo ".$lang['file_delete_success']."<br />\n";
      }
      else {
        
$error_log[] = $lang['file_delete_error']." (".$cats['cat_name'].", ID: ".$cats['cat_id'].")";
      }
      if (
remove_cat_folder(THUMB_PATH."/".$cats['cat_id'])) {
        echo 
"-&raquo ".$lang['thumb_delete_success']."<br />\n";
      }
      else {
        
$error_log[] = $lang['thumb_delete_error']." (".$cats['cat_name'].", ID: ".$cats['cat_id'].")";
      }
    }

    
$sql "DELETE FROM ".COMMENTS_TABLE.
            WHERE image_id IN (
$image_ids_sql)";
    if (
$site_db->query($sql)) {
      echo 
"-&raquo ".$lang['comments_delete_success']."<br />\n";
    }
    else {
      
$error_log[] = $lang['comments_delete_error']." (".$cats['cat_name'].", ID: ".$cats['cat_id'].")";
    }

    
remove_searchwords($image_ids_sql);

    echo 
"<br /></td></tr></table>\n";
    
remove_subcategories($cats['cat_id'], $depth 1);
  }
  unset(
$category_cache[$cid]);
  return 
true;
}

function 
show_category_rows($cid 0$depth 1) {
  global 
$site_db$site_sess$lang$category_cache;

  if (!isset(
$category_cache[$cid])) {
    return 
false;
  }
  foreach (
$category_cache[$cid] as $key => $cats) {
    
$class "tablerow2";
    if (
$cats['cat_parent_id'] == 0) {
      
$class "tablerow";
    }
    echo 
"<tr class=\"$class\">\n<td>\n";
    if (
$depth 1) {
      echo 
str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;"$depth 1)."<img src=\"images/folder_path.gif\" alt=\"\">\n";
    }
    echo 
"<img src=\"".ROOT_PATH."admin/images/folder.gif\" alt=\"\"><b><a href=\"".$site_sess->url(ROOT_PATH."categories.php?cat_id=".$cats['cat_id'])."\" target=\"_blank\">".$cats['cat_name']."</a>\n</b>&nbsp;&nbsp;&nbsp;&nbsp;";
    
show_text_link($lang['edit'], "categories.php?action=editcat&cat_id=".$cats['cat_id']);
    
show_text_link($lang['delete'], "categories.php?action=removecat&cat_id=".$cats['cat_id']);
    
show_text_link($lang['add_subcategory'], "categories.php?action=addcat&cat_parent_id=".$cats['cat_id']);
    echo 
"\n</td>\n<td align=\"center\">";
    echo 
"<a href=\"".$site_sess->url("categories.php?action=ordercat&move=up&cat_id=".$cats['cat_id'])."\"><img src=\"images/arrow_up.gif\" border=\"0\"></a>\n";
    echo 
"<a href=\"".$site_sess->url("categories.php?action=ordercat&move=down&cat_id=".$cats['cat_id'])."\"><img src=\"images/arrow_down.gif\" border=\"0\"></a>\n";
    echo 
"</td>\n</tr>\n";
    
show_category_rows($cats['cat_id'], $depth 1);
  }
  unset(
$category_cache[$cid]);
}

function 
update_cat_order($parent_id 0) {
  global 
$site_db;
  
$sql "SELECT cat_id 
          FROM "
.CATEGORIES_TABLE.
          WHERE cat_parent_id = 
$parent_id 
          ORDER BY cat_order ASC"
;
  
$result $site_db->query($sql);
  
$i 10;
  while (
$row $site_db->fetch_array($result)) {
    
$sql "UPDATE ".CATEGORIES_TABLE.
            SET cat_order = 
$i 
            WHERE cat_id = "
.$row['cat_id'];
    
$site_db->query($sql);
    
$i += 10;
  }
}

function 
get_cat_order_dropdown($parent_id 0$cat_order 0) {
  global 
$cat_cache$cat_parent_cache$lang$HTTP_POST_VARS;

  
$category_list "  
<script>
<!--
var group = new Array();
"
;
foreach (
$cat_parent_cache as $key => $val) {
  
$i 0;
  
$category_list .= "group[".$key."] = new Array();\n";
  
$category_list .= "group[".$key."][".$i++."] = new Option(\"".$lang['at_end']."\", \"0\");\n";
  
$category_list .= "group[".$key."][".$i++."] = new Option(\"".$lang['at_beginning']."\", \"5\");\n";
  foreach (
$val as $val2) {
    
$category_list .= "group[".$key."][".$i++."] = new Option(\"".$lang['after']." ".$cat_cache[$val2]['cat_name']."\", \"".($cat_cache[$val2]['cat_order'] + 5)."\");\n";
  }
  
$category_list .= "\n";
}
$category_list .= "
function redirect(x) {
  for (m = document.add_cat_form.cat_order.length - 1; m > 0; m--) {
    document.add_cat_form.cat_order.options[m] = null;
  }
  for (i = 0; i < group[x].length; i++) {
    document.add_cat_form.cat_order.options[i] = new Option(group[x][i].text, group[x][i].value);
  }
  document.add_cat_form.cat_order.options[0].selected = true;
}
//-->
</script>
"
;
  
  
$category_list .= "\n<select name=\"cat_order\" class=\"categoryselect\">\n";
  
$category_list .= "<option value=\"0\"";
  if (isset(
$HTTP_POST_VARS['cat_order']) && $HTTP_POST_VARS['cat_order'] == 0) {
    
$category_list .= " selected=\"selected\"";
  }
  
$category_list .= ">".$lang['at_end']."</option>\n";
  
$category_list .= "<option value=\"5\"";
  if (isset(
$HTTP_POST_VARS['cat_order']) && $HTTP_POST_VARS['cat_order'] == 5) {
    
$category_list .= " selected=\"selected\"";
  }
  elseif (!isset(
$HTTP_POST_VARS['cat_order']) && $cat_order == 10) {
    
$category_list .= " selected=\"selected\"";
  }
  
$category_list .= ">".$lang['at_beginning']."</option>\n";
  foreach (
$cat_parent_cache[$parent_id] as $key => $val) {
    
$category_list .= "<option value=\"".($cat_cache[$val]['cat_order'] + 5)."\"";
    if (isset(
$HTTP_POST_VARS['cat_order']) && $HTTP_POST_VARS['cat_order'] == ($cat_cache[$val]['cat_order'] + 5)) {
      
$category_list .= " selected=\"selected\"";
    }
    elseif (!isset(
$HTTP_POST_VARS['cat_order']) && $cat_cache[$val]['cat_order'] == $cat_order 10) {
      
$category_list .= " selected=\"selected\"";
    }
    
$category_list .= ">".$lang['after']." ".$cat_cache[$val]['cat_name']."</option>\n";
  }
  
$category_list .= "</select>\n";
  return 
$category_list;
}

show_admin_header();

if (
$action == "ordercat") {
  
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : intval($HTTP_GET_VARS['cat_id']);
  
$move = (isset($HTTP_POST_VARS['move'])) ? trim($HTTP_POST_VARS['move']) : trim($HTTP_GET_VARS['move']);

  
$number = ($move == "up") ? -15 15;

  
$sql "UPDATE ".CATEGORIES_TABLE.
          SET cat_order = cat_order + 
$number 
          WHERE cat_id = 
$cat_id";
  
$site_db->query($sql);

  
update_cat_order($cat_cache[$cat_id]['cat_parent_id']);
  
$action "modifycats";
}

if (
$action == "deletecat") {
  
$error_log = array();
  
show_table_header($lang['main_category'], 1);
  
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : intval($HTTP_GET_VARS['cat_id']);

  
$sql "SELECT cat_id, cat_name, cat_parent_id 
          FROM "
.CATEGORIES_TABLE.
          ORDER BY cat_order, cat_name ASC"
;
  
$result $site_db->query($sql);
  
$category_cache = array();
  while (
$row $site_db->fetch_array($result)) {
    
$category_cache[$row['cat_parent_id']][$row['cat_id']] = $row;
  }

  echo 
"<tr><td class=\"tablerow\">\n";
  echo 
"<table border=\"0\" cellpadding=\"2\" cellspacing=0><tr><td>&nbsp;</td><td>\n";

  
$sql "DELETE FROM ".GROUP_ACCESS_TABLE.
          WHERE cat_id = "
.$cat_id;
  
$site_db->query($sql);

  
$sql "DELETE FROM ".CATEGORIES_TABLE.
          WHERE cat_id = "
.$cat_id;

  if (
$site_db->query($sql)) {
    echo 
$lang['cat_delete_success']." <b>".$cat_cache[$cat_id]['cat_name']."</b> (ID: ".$cat_id.")<br />\n";
  }
  else {
    
$error_log[] = $lang['cat_delete_error']." <b>".$cat_cache[$cat_id]['cat_name']."</b> (ID: ".$cat_id.")";
  }

  
$sql "SELECT image_id 
          FROM "
.IMAGES_TABLE.
          WHERE cat_id = "
.$cat_id;
  
$img_result $site_db->query($sql);

  
$image_ids_sql 0;
  while (
$image_row $site_db->fetch_array($img_result)) {
    
$image_ids_sql .= (($image_ids_sql != "") ? ", " "").$image_row['image_id'];
  }

  
$sql "DELETE FROM ".IMAGES_TABLE.
          WHERE image_id IN (
$image_ids_sql)";
  if (
$site_db->query($sql)) {
    echo 
"-&raquo ".$lang['image_delete_success']."<br />\n";
  }
  else {
    
$error_log[] = $lang['image_delete_error']." (".$cat_cache[$cat_id]['cat_name'].", ID: ".$cat_id.")";
  }

  if (!empty(
$cat_id)) {
    if (
remove_cat_folder(MEDIA_PATH."/".$cat_id)) {
      echo 
"-&raquo ".$lang['file_delete_success']."<br />\n";
    }
    else {
      
$error_log[] = $lang['file_delete_error']." (".$cat_cache[$cat_id]['cat_name'].", ID: ".$cat_id.")";
    }
    if (
remove_cat_folder(THUMB_PATH."/".$cat_id)) {
      echo 
"-&raquo ".$lang['thumb_delete_success']."<br />\n";
    }
    else {
      
$error_log[] = $lang['thumb_delete_error']." (".$cat_cache[$cat_id]['cat_name'].", ID: ".$cat_id.")";
    }
  }

  
$sql "DELETE FROM ".COMMENTS_TABLE.
          WHERE image_id IN (
$image_ids_sql)";
  if (
$site_db->query($sql)) {
    echo 
"-&raquo ".$lang['comments_delete_success']."<br />\n";
  }
  else {
    
$error_log[] = $lang['comments_delete_error']." (".$cat_cache[$cat_id]['cat_name'].", ID: ".$cat_id.")";
  }

  
remove_searchwords($image_ids_sql);

  echo 
"<br /></td></tr></table>\n";
  echo 
"</td></tr>\n";
  
show_table_separator($lang['sub_categories'], 1);
  echo 
"<tr><td class=\"tablerow\">\n";
  if (!
remove_subcategories($cat_id)) {
    echo 
$lang['no_subcategories'];
  }
  echo 
"</td></tr>\n";
  
show_table_footer();
  if (!empty(
$error_log)) {
    
show_table_header("Error Log:"1);
    echo 
"<tr><td class=\"tablerow\">\n";
    echo 
"<table border=\"0\" cellpadding=\"\"2 cellspacing=\"0\"><tr><td>&nbsp;</td><td>\n";
    echo 
"<b>".$lang['error_log_desc']."</b>\n<ul>\n";
    foreach (
$error_log as $key => $val) {
      
printf ("<li>%s</li>\n"$val);
    }
    echo 
"</ul>\n</td></tr></table>\n";
    echo 
"</td></tr>\n";
    
show_table_footer();
  }
  echo 
"<p>";
  
show_text_link($lang['back_overview'],"categories.php?action=modifycats");
}

if (
$action == "removecat") {
  
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : intval($HTTP_GET_VARS['cat_id']);

  
show_form_header("categories.php""deletecat");
  
show_hidden_input("cat_id"$cat_id);
  
show_table_header($lang['delete'].": ".$cat_cache[$cat_id]['cat_name'], 2);
  
show_description_row($lang['delete_cat_confirm']);
  
show_form_footer($lang['yes'], ""2$lang['no']);
}

if (
$action == "savecat") {
  
$error = array();
  
$cat_name un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
  
$cat_description un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
  
$cat_parent_id intval($HTTP_POST_VARS['cat_parent_id']);
  
$cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;

  
$auth_viewcat $HTTP_POST_VARS['auth_viewcat'];
  
$auth_viewimage $HTTP_POST_VARS['auth_viewimage'];
  
$auth_download $HTTP_POST_VARS['auth_download'];
  
$auth_upload $HTTP_POST_VARS['auth_upload'];
  
$auth_directupload $HTTP_POST_VARS['auth_directupload'];
  
$auth_vote $HTTP_POST_VARS['auth_vote'];
  
$auth_sendpostcard $HTTP_POST_VARS['auth_sendpostcard'];
  
$auth_readcomment $HTTP_POST_VARS['auth_readcomment'];
  
$auth_postcomment $HTTP_POST_VARS['auth_postcomment'];
  
$cat_combination $HTTP_POST_VARS['cat_combination'];

  
  
//Category Image
  
$cat_image = (intval($HTTP_POST_VARS['cat_image'])) ? intval($HTTP_POST_VARS['cat_image']) : 0;
//End Category Image

  
if ($cat_name == "") {
    
$error['cat_name'] = 1;
  }

  if (empty(
$error)) {
    if (!
$cat_order) {
      
$sql "SELECT cat_order 
              FROM "
.CATEGORIES_TABLE.
              WHERE cat_parent_id = 
$cat_parent_id 
              ORDER BY cat_order DESC
              LIMIT 1"
;
      
$catorder $site_db->query_firstrow($sql);
      
$cat_order $catorder['cat_order'] + 10;
      
$do_update_cat_order 0;
    }
    else {
      
$do_update_cat_order 1;
    }

   
$sql "INSERT INTO ".CATEGORIES_TABLE."
            (cat_name, cat_description, cat_parent_id, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_image, cat_combination)
            VALUES
            ('
$cat_name', '$cat_description', $cat_parent_id$cat_order$auth_viewcat$auth_viewimage$auth_download$auth_upload$auth_directupload$auth_vote$auth_sendpostcard$auth_readcomment$auth_postcomment$cat_image, '$cat_combination')";
    
$result $site_db->query($sql);
    
$cat_id $site_db->get_insert_id();

    if (
$result && $cat_id) {
      if (
$do_update_cat_order) {
        
update_cat_order($cat_parent_id);
      }
      
$msg $lang['cat_add_success'];
      
create_cat_folder(MEDIA_PATH."/".$cat_idCHMOD_DIRS);
      
create_cat_folder(THUMB_PATH."/".$cat_idCHMOD_DIRS);
    }
    else {
      
$msg $lang['cat_add_error'];
    }
    
$action "modifycats";
  }
  else {
    
$msg sprintf("<span class=\"marktext\">%s</span>"$lang['lostfield_error']);
    
$action "addcat";
  }
}

if (
$action == "addcat") {
  if (
$msg != "") {
    
printf("<b>%s</b>\n"$msg);
  }
  
show_form_header("categories.php""savecat""add_cat_form");
  
show_table_header($lang['nav_categories_add'], 2);
  
show_input_row($lang['field_category_name'], "cat_name"""$textinput_size);
  
show_textarea_row($lang['field_description_ext'], "cat_description"""$textarea_size);

  
$cat_parent_id = (isset($HTTP_GET_VARS['cat_parent_id'])) ? $HTTP_GET_VARS['cat_parent_id'] : 0;
  
$category "\n<select name=\"cat_parent_id\" class=\"categoryselect\" onChange=\"redirect(this.options[this.selectedIndex].value)\">\n";
  
$category .= "<option value=\"0\">".$lang['main_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_bits($cat_parent_id);
  
$category .= "</select>\n";
  
show_custom_row($lang['field_parent'], $category);
  
show_custom_row($lang['cat_order'], get_cat_order_dropdown($cat_parent_id));

  
$permission_headline $lang['permissions'];
  if (
$cat_parent_id != 0) {
    
$new_access_field_array = array();

    
$sql "SELECT cat_name, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment 
            FROM "
.CATEGORIES_TABLE.
            WHERE cat_id = 
$cat_parent_id";
    
$row $site_db->query_firstrow($sql);

    foreach (
$access_field_array as $key => $val) {
      
$new_access_field_array[$key] = $row[$key];
    }
    unset(
$access_field_array);
    
$access_field_array $new_access_field_array;
    
$permission_headline .= "<span class=\"smalltext\"><br>".$lang['permissions_inherited']." (".$row['cat_name'].")</span>";
  }

  
show_table_separator($permission_headline2);
  foreach (
$access_field_array as $key => $val) {
    
show_access_select($lang[$key], $key$val);
  }

  
show_form_footer($lang['add'], $lang['reset'], 2);
}

if (
$action == "updatecat") {
  
$error = array();
  
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : intval($HTTP_GET_VARS['cat_id']);

  
$cat_parent_id intval($HTTP_POST_VARS['cat_parent_id']);
  
$cat_name un_htmlspecialchars(trim($HTTP_POST_VARS['cat_name']));
  
$cat_description un_htmlspecialchars(trim($HTTP_POST_VARS['cat_description']));
  
$cat_hits intval(trim($HTTP_POST_VARS['cat_hits']));
  
$cat_order = (isset($HTTP_POST_VARS['cat_order'])) ? intval($HTTP_POST_VARS['cat_order']) : 0;

  
$auth_viewcat $HTTP_POST_VARS['auth_viewcat'];
  
$auth_viewimage $HTTP_POST_VARS['auth_viewimage'];
  
$auth_download $HTTP_POST_VARS['auth_download'];
  
$auth_upload $HTTP_POST_VARS['auth_upload'];
  
$auth_directupload $HTTP_POST_VARS['auth_directupload'];
  
$auth_vote $HTTP_POST_VARS['auth_vote'];
  
$auth_sendpostcard $HTTP_POST_VARS['auth_sendpostcard'];
  
$auth_readcomment $HTTP_POST_VARS['auth_readcomment'];
  
$auth_postcomment $HTTP_POST_VARS['auth_postcomment'];
  
$cat_combination $HTTP_POST_VARS['cat_combination'];

  
  
//Category Image
  
$cat_image = (intval($HTTP_POST_VARS['cat_image'])) ? intval($HTTP_POST_VARS['cat_image']) : 0;
//End Category Image

  
if ($cat_parent_id == $cat_id) {
    
$msg .= sprintf("<span class=\"marktext\">%s</span><br />"$lang['parent_cat_error']);
    
$error['cat_parent_id'] = 1;
  }
  if (
$cat_name == "") {
    
$error['cat_name'] = 1;
  }

  if (empty(
$error)) {
    if (!
$cat_order) {
      
$sql "SELECT cat_order 
              FROM "
.CATEGORIES_TABLE.
              WHERE cat_parent_id = 
$cat_parent_id 
              ORDER BY cat_order DESC
              LIMIT 1"
;
      
$catorder $site_db->query_firstrow($sql);
      
$cat_order $catorder['cat_order'] + 10;
      
$do_update_cat_order 0;
    }
    else {
      
$do_update_cat_order 1;
    }

    
$sql "UPDATE ".CATEGORIES_TABLE.
SET cat_name = '
$cat_name', cat_description = '$cat_description', cat_parent_id = $cat_parent_id, cat_hits = $cat_hits, auth_viewcat = $auth_viewcat, auth_viewimage = $auth_viewimage, auth_download = $auth_download, auth_upload = $auth_upload, auth_directupload = $auth_directupload, auth_vote = $auth_vote, auth_sendpostcard = $auth_sendpostcard, auth_readcomment = $auth_readcomment, auth_postcomment = $auth_postcomment, cat_image = $cat_image, cat_combination = '$cat_combination'
    WHERE cat_id = 
$cat_id";
    
$result $site_db->query($sql);
    if (
$do_update_cat_order) {
      
update_cat_order($cat_parent_id);
    }
    
$msg = ($result) ? $lang['cat_edit_success'] : $lang['cat_edit_error'];
    
$action "editcat";
  }
  else {
    
$msg .= sprintf("<span class=\"marktext\">%s</span>"$lang['lostfield_error']);
    
$action "editcat";
  }
}

if (
$action == "editcat") {
  if (
$msg != "") {
    
printf("<b>%s</b>\n"$msg);
  }
  echo 
"<form action=\"".$PHP_SELF."\" name=\"edit_cat_form\">";
  echo 
"<input type=\"hidden\" name=\"action\" value=\"editcat\" />";
  echo 
"\n<select name=\"cat_id\" class=\"categoryselect\">\n";
  
$drop_down_cat_cache $cat_parent_cache;
  echo 
get_category_dropdown_bits($cat_id);
  echo 
"</select>\n";
  echo 
" <input type=\"submit\" value=\"".$lang['nav_categories_edit']."\" class=\"button\" />";
  echo 
"</form>";

  
$cat_id = (isset($HTTP_POST_VARS['cat_id'])) ? intval($HTTP_POST_VARS['cat_id']) : intval($HTTP_GET_VARS['cat_id']);

$sql "SELECT cat_name, cat_description, cat_parent_id, cat_hits, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_image, cat_combination
          FROM "
.CATEGORIES_TABLE.
          WHERE cat_id = 
$cat_id";
  
$cat_row $site_db->query_firstrow($sql);

  
show_form_header("categories.php""updatecat");
  
show_hidden_input("cat_id"$cat_id);
  
show_table_header($lang['nav_categories_edit'], 2);
  
show_input_row($lang['field_category_name'], "cat_name"$cat_row['cat_name'], $textinput_size);
  
show_textarea_row($lang['field_description_ext'], "cat_description"$cat_row['cat_description'], $textarea_size);
  
  
$cat_parent_id $cat_row['cat_parent_id'];
  
$category "\n<select name=\"cat_parent_id\" class=\"categoryselect\" onChange=\"redirect(this.options[this.selectedIndex].value)\">\n";
  
$category .= "<option value=\"0\">".$lang['main_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_bits($cat_parent_id);
  
$category .= "</select>\n";
  
show_custom_row($lang['field_parent'], $category);
  
show_custom_row($lang['cat_order'], get_cat_order_dropdown($cat_parent_id$cat_row['cat_order']));

  
show_input_row($lang['field_hits'], "cat_hits"$cat_row['cat_hits'], 5);

  
show_table_separator($lang['permissions'], 2);
  foreach (
$access_field_array as $key => $val) {
    
show_access_select($lang[$key], $key$cat_row[$key]);
  }

// Category image 
  
$cat_image "";
  if (
$result['cat_image'])
  {
    
$sql "SELECT image_id, image_media_file, image_thumb_file, image_name, cat_id
            FROM "
.IMAGES_TABLE."
            WHERE image_id = "
.$result['cat_image'];
    if (
$image_row $site_db->query_firstrow($sql))
    {
      if (!
get_file_path($image_row['image_thumb_file'], "thumb"$image_row['cat_id'], 00))
      {
        
$cat_image ICON_PATH."/".get_file_extension($image_row['image_media_file']).".gif";
      }
      else
      {
        
$cat_image get_file_path($image_row['image_thumb_file'], "thumb"$image_row['cat_id'], 01);
      }
      
$file_info = @getimagesize($cat_image);
      
$dim 50;
      
$width $file_info[0];
      
$height $file_info[1];
      if (
$width && $height) {
        if (
$width $dim || $height $dim) {
          @
$ratio $width $height;
          if (
$ratio 1) {
            
$new_width $dim;
            
$new_height round(($dim/$width) * $height);
          }else {
            
$new_width round(($dim/$height) * $width);
            
$new_height $dim;
          }
        }else{
          
$new_width $width;
          
$new_height $height;
        }
      }else{
        
$new_width $dim;
        
$new_height $dim;
      }
      
$cat_image "<a href=\"".$site_sess->url(ROOT_PATH."details.php?image_id=".$result['cat_image'])."\" target=\"_blank\"><img src=\"".$cat_image."\" width=\"".$new_width."\" height=\"".$new_height."\"></a>&nbsp;<a href=\"".$site_sess->url(ROOT_PATH."details.php?image_id=".$result['cat_image'])."\" target=\"_blank\">".$image_row['image_name']."</a>";
    }
   
  }
  
$value $result['cat_image'];
  if (isset(
$HTTP_POST_VARS['cat_image'])/* && $value == ""*/) {
    
$value stripslashes($HTTP_POST_VARS['cat_image']);
  }
  echo 
"<tr class=\"".get_row_bg()."\">\n<td><p class=\"rowtitle\">Category image</p></td>\n<td><p><input type=\"text\" size=\"5\" name=\"cat_image\" value=\"".$value."\">&nbsp;$cat_image</p></td>\n</tr>\n";
//End Category image

 
$cat_combination $result['cat_combination']; 
     echo 
"<tr class=\"".get_row_bg()."\">\n<td><p class=\"rowtitle\">Sub-Kategorie</p></td>\n<td><p><input type=\"text\" size=\"15\" name=\"cat_combination\" value=\"".$cat_combination."\"></p></td>\n</tr>\n";
     

  
show_form_footer($lang['save_changes'], $lang['reset'], 2$lang['back']);
}

if (
$action == "modifycats") {
  if (
$msg != "") {
    
printf("<b>%s</b>\n<p>"$msg);
  }

$sql "SELECT cat_id, cat_name, cat_description, cat_parent_id, cat_hits, cat_order, auth_viewcat, auth_viewimage, auth_download, auth_upload, auth_directupload, auth_vote, auth_sendpostcard, auth_readcomment, auth_postcomment, cat_image
          FROM "
.CATEGORIES_TABLE.
          ORDER BY cat_order, cat_name ASC"
;
  
$result $site_db->query($sql);

  
$category_cache = array();
  while (
$row $site_db->fetch_array($result)) {
    
$category_cache[$row['cat_parent_id']][$row['cat_id']] = $row;
  }

  echo 
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" align=\"center\"><tr><td class=\"tableborder\">\n<table cellpadding=\"3\" cellspacing=\"1\" border=\"0\" width=\"100%\">\n";
  echo 
"<tr class=\"tableseparator\">\n";
  echo 
"<td class=\"tableseparator\">".$lang['nav_categories_edit']."</td>\n<td class=\"tableseparator\" align=\"center\">".$lang['cat_order']."</td>\n</tr>\n";
  if (
sizeof($category_cache) == 0) {
    echo 
"<tr class=\"".get_row_bg()."\">\n<td colspan=\"2\">".$lang['no_categories']."</td></tr>";
  }
  else {
    
show_category_rows();
  }
  
show_table_footer();
}
show_admin_footer();
?>

Hope, you can help me. 

Offline Lunique

  • Full Member
  • ***
  • Posts: 109
  • V 1.7.7
    • View Profile
Re: Easier way to add/sort categories?
« Reply #26 on: November 20, 2005, 02:07:04 AM »
Great Mod thank you !
Just what I'm waiting for...

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: Easier way to add/sort categories?
« Reply #27 on: November 20, 2005, 04:34:27 PM »
Anybody who can help me?

Thank you!!

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: Easier way to add/sort categories?
« Reply #28 on: November 22, 2005, 11:03:37 PM »
Jan, V@no

Is it possible to have a look on my problem?

Thank you!

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: Easier way to add/sort categories?
« Reply #29 on: November 23, 2005, 01:28:10 AM »
above
Code: [Select]
  $cat_image = "";insert:
Code: [Select]
  $result = $cat_row;
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)