Project: stupidCMS
Code Location: https://stupidcms.svn.sourceforge.net/svnroot/stupidcms
Browse
/
Download File
categories.php
<?php
/* Copyright (C) 2011  Jacopo Cascioli

This file is part of stupidCMS

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>. */
require "layout.php";
require "format.php";
require "settings.php";

/* mysql connection */
$con = mysql_connect($server, $user, $password);
mysql_select_db($database, $con);

/* finds generic vars */
$query = mysql_query("SELECT * FROM general");
$general = mysql_fetch_array($query);
$title = $general[1];
$description = $general[2];
$sentence = $general[3];
$license = $general[4];
$version = $general[5];
$lastupdate = date("l j F Y", $general[6]);


$mode = $_GET["mode"];
$show = $_GET["show"];
if ($show == 'categories') {$table_name = 'category';}
elseif ($show == 'languages'){$table_name = 'language';}
if ($mode == 0)
{
	/* shows a list of categories */
	$query = mysql_query("SELECT * FROM $show");
	$raw_categories_list = fetch_all($query);
	if ($show == 'languages'){$main_content = format_generic_list(0, $raw_categories_list);}
	elseif ($show == 'categories'){$main_content = format_generic_list(1, $raw_categories_list);}
	
	$navbar = format_navbar(0, 0, 0);
	$page_slide = '';
}
elseif ($mode == 1)
{
	/* shows posts in a category */
	$given_category = $_GET[$table_name];
	$from_last = $_GET["fromlast"];
	
	if (!$from_last)
	{
		$query = mysql_query("SELECT * FROM posts WHERE $table_name='$given_category' ORDER BY id DESC LIMIT 0,10");
		$posts = fetch_all($query);
		$formatted_posts = format_posts($posts);
		$page_slide = format_page_slide(1, 2, $given_category);
	}
	else
	{
		$query = mysql_query("SELECT * FROM posts WHERE $table_name='$given_category' ORDER BY id DESC");
		$posts_array = fetch_all($query);
		$posts = limit_workaround($posts_array, $from_last, 10);
		$page_slide = format_page_slide($from_last, 2, $given_category);
		$formatted_posts = format_posts($posts);
	}
	
	$main_content = $formatted_posts.$page_slide;
}
$navbar = format_navbar($show, $mode, $given_category);
$header = sprintf($header, $title, $description, $navbar);
$footer = sprintf($footer, $lastupdate, $version, $license);

printf($html_base, $title, $header, $main_content, 
$footer);

?>