Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Mods & Themes (http://www.bvlist.com/forumdisplay.php?f=113)
-   -   [FTS 1.1] Subcats sofar (http://www.bvlist.com/showthread.php?t=4193)

Edgein 9th January 2010 22:29

[FTS 1.1] Subcats sofar
 
1 Attachment(s)
here is the start of the mod

MySQL

PHP Code:

ALTER TABLE `categoriesADD `parent_idMEDIUMINTNOT NULL DEFAULT '-1';

ALTER TABLE `categoriesADD `tabletypeTINYINTUNSIGNED NOT NULL DEFAULT '1'

in include/funcktions.php

find

PHP Code:

/**
 * genrelist()
 *
 * @return
 */
function genrelist()
{
    
$ret = array();
    
$res mysql_query("SELECT id, name FROM categories ORDER BY name");
    while (
$row mysql_fetch_array($res))
        
$ret[] = $row;
    return 
apply_filters("genrelist",$ret);


after add

PHP Code:

function genrelist2() {
 
$row mysql_query("SELECT id, name, image, parent_id, tabletype FROM categories ORDER BY name");

 while (
$mysqlcats mysql_fetch_array($row))
 
$allcats[] = $mysqlcats;

 
$allcats2 $allcats;
 
 
$i 0;
 
 foreach (
$allcats as $cat)
 {

 if (
$cat[parent_id] == -1
 {

 
$cats[] = $cat;
 
$j 0;
 foreach (
$allcats2 as $subcat)
 {

 if (
$cat[id] == $subcat[parent_id]) {

 
//Subcategories
 
$cats[$i]['subcategory'][] = $subcat;

 
//Subcategories add parenttabletype
 
$cats[$i]['subcategory'][$j]['parenttabletype'] = $cat['tabletype'];

 
//Subcategories add idtabletype
 
$cats[$i]['subcategory'][$j]['idtabletype'] = $subcat['id'].$subcat['tabletype'];

 
//Subcategories description
 
$cats[$i]['subcategory'][$j]['description'] = $cat['name']."->".$subcat['name'];

 
//All link array for cats
 
$cats[$i]['categories'] .= "cats$cat[tabletype][]=$subcat[id]&";

 
$j++;
 }
 }
 
 
//All link for cats
 
$cats[$i]['categories'] = substr($cats[$i]['categories'],0,-5);
 
$i++;

 }

 }

 return 
$cats;

}

function 
categories_table($cats$wherecatina$linkpage ''$display 'block')
{

 
$html "";

 
$html .= "<div id=\"cats\" style=\"display: {$display};\">";
 
$html .= "<table>";
 
$html .= "<tbody align=\"left\"><tr>";

 
$i 0;

 
$ncats count($cats);
 
$catsperrow $ncats;

 
$width 100/$ncats;

 if(
count($ncats) > 0);
 foreach( 
$cats as $cat )
 {
 
$html .= ($i && $i $catsperrow == 0) ? "</tr><tr>" "";
 
$html .= "<td class=\"nopad\" style=\"padding-bottom: 2px;padding-left: 50px; width: {$width}%;\"><input id=\"checkAll{$cat[tabletype]}\" type=\"checkbox\" onclick=\"checkAllFields(1,{$cat['tabletype']});\" type=\"checkbox\" " . ($cat['checked'] ? "checked " "") . "><a href=\"java script: ShowHideMainSubCats({$cat['tabletype']},{$ncats})\"><img border=\"0\" src=\"pic/plus.gif\" id=\"pic{$cat['tabletype']}\" alt=\"Show/Hide\">&nbsp;" htmlspecialchars($cat['name']) . "</a>&nbsp;".(($linkpage != '') ? "<a class=\"catlink\" href=\"{$linkpage}?{$cat['categories']}\">(All)</a>" "")."</td>\n";
 
$i++;
 }



 
$nrows ceil($ncats/$catsperrow);
 
$lastrowcols $ncats $catsperrow;

 if (
$lastrowcols != 0)
 {
 if (
$catsperrow $lastrowcols != 1)
 
$html .= "<td rowspan=\"" . ($catsperrow $lastrowcols) . "\">&nbsp;</td>";
 else
 
$html .= "<td>&nbsp;</td>";
 }

 
$html .= "</tr><tbody>";
 
$html .= "</table>";
 
$html .= "</div>";

 if(
count($cats) > 0);
 foreach( 
$cats as $cat )
 {
 
$subcats $cat[subcategory];

 if (
count($subcats) > 0)
 {
 
$html .= subcategories_table($cat$wherecatina$linkpage$ncats);
 }

 }

 return 
$html;
}


function 
subcategories_table($cats$wherecatina$linkpage ''$ncats)
{
 
$html "";
 
$html .= "<div id=\"tabletype{$cats['tabletype']}\" style=\"display: none;\">";

 
$subcats $cats['subcategory'];

 
$html .= "<table>";
 
$html .= "<tbody align=\"left\"><tr>";

 
$width 100/$ncats;
 
$catsperrow $ncats;

 
$i 0;
 if (
count($subcats) >0)
 foreach (
$subcats as $cat)
 {

 
$html .= ($i && $i $catsperrow == 0) ? "</tr><tr>" "";
 
$html .= "<td class=\"subcatlink\" style=\"padding-bottom: 2px;padding-left: 50px; width: {$width}%;\"><input type=\"checkbox\" onclick=\"checkAllFields(2,{$cats['tabletype']});\" name=\"cats{$cats['tabletype']}[]\" value=\"{$cat['id']}\" type=\"checkbox\" " . (in_array($cat['id'],$wherecatina) ? "checked " "") . ">".(($linkpage != '') ? "<a href=\"{$linkpage}?cats{$cats['tabletype']}[]={$cat['id']}\">" htmlspecialchars($cat['name']) . "</a>" htmlspecialchars($cat['name']))."</td>\n";
 
$i++;
 }


 
$nsubcats count($subcats);
 
$nrows ceil($nsubcats/$catsperrow);
 
$lastrowcols $nsubcats $catsperrow;

 if (
$lastrowcols != 0)
 {
 if (
$catsperrow $lastrowcols != 1)
 
$html .= "<td rowspan=\"" . ($catsperrow $lastrowcols) . "\">&nbsp;</td>";
 else
 
$html .= "<td>&nbsp;</td>";
 }

 
$html .= "</tr>";
 
$html .= "</tbody>";
 
$html .= "</table>";
 
$html .= "</div>";

 return 
$html;


Now in browse.php

replace

PHP Code:

$cats genrelist(); 

with

PHP Code:

$cats genrelist2(); 

remove

PHP Code:

<table class=bottom>
<
tr>
<
td class=bottom>
    <
table class=bottom>
    <
tr

above

PHP Code:

<form method="get" action="browse.php"

add

PHP Code:

<script type="text/javascript" src="browse.js"></script> 

replace

PHP Code:

$i ;
foreach ( 
$cats as $cat )
{
    
$catsperrow ;
    print ( (
$i && $i $catsperrow == 0) ? "</tr><tr>" "" ) ;
    print ( 
"<td class=bottom style=\"padding-bottom: 2px;padding-left: 7px\"><input name=c$cat[id] type=\"checkbox\" " .
        (
in_array($cat[id], $wherecatina) ? "checked " "") .
        
"value=1><a class=catlink href=browse.php?cat=$cat[id]>" htmlspecialchars($cat[name]) .
        
"</a></td>\n" ) ;
    
$i++ ;


with

PHP Code:

$cattable categories_table($cats$wherecatina"browse.php");
print(
$cattable); 

remove

PHP Code:

    </tr>
    </
table>
</
td>

<
td class=bottom

remove

PHP Code:

</td>
</
tr>
</
table

replace

PHP Code:

if ( ! $all )
    if ( ! 
$_GET && $CURUSER['notifs'] )
    {
        
$all true ;
        foreach ( 
$cats as $cat )
        {
            
$all &= $cat[id] ;
            
$mystring $CURUSER['notifs'] ;
            
$findme '[cat' $cat['id'] . ']' ;
            
$search strpos$mystring$findme ) ;
            if ( 
$search === false )
                
$catcheck false ;
            else
                
$catcheck true ;

            if ( 
$catcheck )
            {
                
$wherecatina[] = $cat[id] ;
                
$addparam .= "c$cat[id]=1&" ;
            }
        }
    } elseif ( 
$category )
    {
        
int_check$categorytruetruetrue ) ;
        
$wherecatina[] = $category ;
        
$addparam .= "cat=$category&" ;
    }
    else
    {
        
$all true ;
        foreach ( 
$cats as $cat )
        {
            
$all &= $_GET["c$cat[id]"] ;
            if ( 
$_GET["c$cat[id]"] )
            {
                
$wherecatina[] = $cat[id] ;
                
$addparam .= "c$cat[id]=1&" ;
            }
        }
    }

    if ( 
$all )
    {
        
$wherecatina = array() ;
        
$addparam "" ;
    } 

with

PHP Code:

if (!$all)
{
 if (!
$_GET && $CURUSER["notifs"])
 {
 
$i 0;
 foreach (
$cats as $cat)
 {

 
$subcats $cat[subcategory];

 if (
count($subcats) > 0)
 {
 foreach (
$subcats as $subcat)
 {

 if (
strpos($CURUSER["notifs"], "[cat{$subcat['id']}]") !== False)
 {
 
$wherecatina[] = $subcat['id'];
 
$addparam .= "cats$cat[tabletype][]=$subcat[id]&";
 }

 }
 }

 if (
count($subcats) > 0)
 {
 foreach (
$subcats as $subcat)
 {

 if ( 
in_array($subcat['id'],$wherecatina) )
 {
 
$cats[$i]['checked'] = True;
 }
 else
 {
 
$cats[$i]['checked'] = False;
 break;
 }

 }
 }
 
$i++;
 }

 }
 elseif (
$_GET)
 {

 
//$_Get categories
 
$i 0;
 if(
count($cats) > 0);
 foreach (
$cats as $cat)
 {
 
$categoriesarray $_GET["cats".$cat['tabletype']];

 if (
count($categoriesarray) > 0)
 {
 foreach (
$categoriesarray as $category)
 {
 if (!
is_valid_id($category))
 
stderr("Browse Error""Not valid browse category");
 
$wherecatina[] = $category;
 
$addparam .= "cats$cat[tabletype][]=$category&";
 }
 }

 
$subcats $cat[subcategory];

 if (
count($subcats) > 0)
 {
 foreach (
$subcats as $subcat)
 {

 if ( 
in_array($subcat['id'],$wherecatina) )
 {
 
$cats[$i]['checked'] = True;
 }
 else
 {
 
$cats[$i]['checked'] = False;
 break;
 }

 }
 }
 
$i++;

 }

 if(
$_GET[cat])
 {

 
//$_GET category

 
$getcategory $_GET['cat'];

 if (!
is_valid_id($getcategory))
 
stderr("Browse Error""Not valid browse category");

 if(
count($cats) > 0);
 foreach (
$cats as $cat)
 {
 
$subcats $cat[subcategory];

 if (
count($subcats) > 0)
 {
 foreach (
$subcats as $subcat)
 {
 if (
$subcat['id'] == $getcategory)
 {
 
$wherecatina[] = $getcategory;
 
$addparam .= "cats$cat[tabletype][]=$getcategory&";
 break;
 }
 }
 }
 if (
$subcat['id'] == $getcategory)
 break;
 }
 
 }
 
 
 }
}
else
{
 
$i 0;
 if(
count($cats) > 0);
 foreach (
$cats as $cat)
 {
 
$subcats $cat[subcategory];
 
 if (
count($subcats) > 0)
 {

 
$cats[$i]['checked'] = True;

 }
 
$i++;
 }


back to include/funcktions.php

replace

PHP Code:

$cats genrelist();
foreach (
$cats as $row)
    
$s .= "<option value=\"" $row["id"] . "\">" htmlspecialchars($row["name"]) . "</option>\n";

$s .= "</select>\n"

with

PHP Code:

$cats genrelist2();
foreach (
$cats as $cat)
{
 
$s .= "<optgroup label=\"" htmlspecialchars($cat["name"]) . "\">";
 
$subcats $cat[subcategory];

 if (
count($subcats) > 0)
 {
 foreach (
$subcats as $subcat)
 {
 
$s .= "<option value=\"" $subcat["id"] . "\">" htmlspecialchars($subcat["name"]) . "</option>\n";

 }
 }
 
$s .= "</optgroup>\n";



here is my part of the MySQL

PHP Code:

CREATE TABLE `categories` (
  `
idint(10unsigned NOT NULL auto_increment,
  `
namevarchar(30NOT NULL default '',
  `
imagevarchar(255NOT NULL default '',
  `
sort_indexint(10unsigned NOT NULL default '0',
  `
cat_descvarchar(30NOT NULL default '',
  `
parent_idmediumint(5NOT NULL default '-1',
  `
tabletypetinyint(2unsigned NOT NULL default '1',
  
PRIMARY KEY  (`id`)
ENGINE=MyISAM AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 AUTO_INCREMENT=26 ;

-- 
-- 
Gegevens worden uitgevoerd voor tabel `categories`
-- 

INSERT INTO `categoriesVALUES (7'DVD Film''DVD Film.jpg'0'', -11);
INSERT INTO `categoriesVALUES (11'Kids''kids.jpg'0''71);
INSERT INTO `categoriesVALUES (13'Muziek Album''muziek album.jpg'0'', -11);
INSERT INTO `categoriesVALUES (19'Scripts en Templates''scripts en templates.jpg'0''31);
INSERT INTO `categoriesVALUES (20'Software''software.jpg'0'', -11);
INSERT INTO `categoriesVALUES (23'X Video Div''x vid div.jpg'0''71);
INSERT INTO `categoriesVALUES (24'X Video XXX''x vid xxx.jpg'0''71);
INSERT INTO `categoriesVALUES (25'X Video Film''x video film.jpg'0''71); 

http://www.edgein.org/mysql.jpg

How it al works i dont know :drink:

i get some errors on browse.php
PHP Code:

$nrows ceil($ncats/$catsperrow);
$lastrowcols $ncats $catsperrow;
if (
$ncats $catsperrow == 0

maybe somone else can find out what i do wrong
i delete the lines no errors in browse.php but not the good way

some other pics
http://www.edgein.org/browse.jpg

http://www.edgein.org/upload.jpg
good luck with it and maybe someone can help me with the errors

greets edgein:drink:

Laffin 14th January 2010 18:41

What is tabletype for?

Edgein 14th January 2010 21:00

I was just busy the last few days
I will agree after watching one of these days


All times are GMT +2. The time now is 09:43.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.