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 `categories` ADD `parent_id` MEDIUMINT( 5 ) NOT NULL DEFAULT '-1';
ALTER TABLE `categories` ADD `tabletype` TINYINT( 2 ) UNSIGNED 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\"> " . htmlspecialchars($cat['name']) . "</a> ".(($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) . "\"> </td>"; else $html .= "<td> </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) . "\"> </td>"; else $html .= "<td> </td>"; }
$html .= "</tr>"; $html .= "</tbody>"; $html .= "</table>"; $html .= "</div>";
return $html; }
Now in browse.php
replace
with
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 = 0 ; foreach ( $cats as $cat ) { $catsperrow = 7 ; 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
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( $category, true, true, true ) ; $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 = 0 + $_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` ( `id` int(10) unsigned NOT NULL auto_increment, `name` varchar(30) NOT NULL default '', `image` varchar(255) NOT NULL default '', `sort_index` int(10) unsigned NOT NULL default '0', `cat_desc` varchar(30) NOT NULL default '', `parent_id` mediumint(5) NOT NULL default '-1', `tabletype` tinyint(2) unsigned 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 `categories` VALUES (7, 'DVD Film', 'DVD Film.jpg', 0, '', -1, 1); INSERT INTO `categories` VALUES (11, 'Kids', 'kids.jpg', 0, '', 7, 1); INSERT INTO `categories` VALUES (13, 'Muziek Album', 'muziek album.jpg', 0, '', -1, 1); INSERT INTO `categories` VALUES (19, 'Scripts en Templates', 'scripts en templates.jpg', 0, '', 3, 1); INSERT INTO `categories` VALUES (20, 'Software', 'software.jpg', 0, '', -1, 1); INSERT INTO `categories` VALUES (23, 'X Video Div', 'x vid div.jpg', 0, '', 7, 1); INSERT INTO `categories` VALUES (24, 'X Video XXX', 'x vid xxx.jpg', 0, '', 7, 1); INSERT INTO `categories` VALUES (25, 'X Video Film', 'x video film.jpg', 0, '', 7, 1);
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:
|