<?php
session_start();
/*
asaancart - easy shopping cart solution
---------------------------------------
Copyright 2009 Nasir Ahmad Khan
Email: hide@address.com
This file is part of asaancart - open source easy shopping cart solution.
asaancart 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.
asaancart 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 asaancart. If not, see <http://www.gnu.org/licenses/>.
*/
include("../config/config.php");
include("includes/chk_login_status_inc.php");
$smarty->assign('title','Manage Content Blocks');
$smarty->assign('msg', "");
if($_POST['btn_submit']=="Create"){
$block_heading = $_POST['block_heading'];
$block_text = $_POST['block_text'];
$page_to_add = $_POST['page_to_add'];
$sql = "SELECT * FROM content_block WHERE block_heading='".$block_heading."'";
$results = mysql_query($sql);
$total_page = mysql_num_rows($results);
if($total_page>0){
$smarty->assign('msg', "<span style='color:red'>Sorry, this block has already been created</span>");
}else{
$sql = "INSERT INTO content_block (block_heading, block_text) VALUES ('$block_heading', '$block_text')";
$results = mysql_query($sql);
//update block_contents
//delete all pages in this block and then add new selection
$sql = "SELECT * FROM content_block WHERE block_heading='".$block_heading."'";
$results = mysql_query($sql);
while($row = mysql_fetch_assoc($results) )
{
$block_id = $row['block_id'];
}
$sql = "DELETE FROM block_contents WHERE block_id=".$block_id;
$results = mysql_query($sql);
foreach ($page_to_add as $temp_page_id){
$sql = "INSERT INTO block_contents (block_id, page_id) VALUES ($block_id, $temp_page_id)";
$results = mysql_query($sql);
}// end for each
//end update block contetns
$smarty->assign('msg', "<span>Done, block created successfully</span>");
}//page cnt
}
if($_POST['btn_submit']=="Save"){
$block_id = $_POST['block_id'];
$block_heading = $_POST['block_heading'];
$block_text = $_POST['block_text'];
$page_to_add = $_POST['page_to_add'];
$sql = "UPDATE content_block SET block_heading='$block_heading', block_text='$block_text' WHERE block_id='".$block_id."'";
$results = mysql_query($sql);
//update block_contents
//delete all pages in this block and then add new selection
$sql = "DELETE FROM block_contents WHERE block_id=".$block_id;
$results = mysql_query($sql);
foreach ($page_to_add as $temp_page_id){
$sql = "INSERT INTO block_contents (block_id, page_id) VALUES ($block_id, $temp_page_id)";
$results = mysql_query($sql);
}// end for each
//end update block contetns
$smarty->assign('msg', "<span>Done, block saved successfully</span>");
}
if($_GET['action']=="showBlockContent"){
$sql = "SELECT * FROM content_block WHERE block_id=".$_GET['block_id'];
$results = mysql_query($sql);
$total_block = mysql_num_rows($results);
if($total_block>0){
while($row = mysql_fetch_assoc($results) )
{
$block_content[] = $row;
}
}else{
$total_block = 0;
}//page cnt
//manage
$sql = "SELECT * FROM content_page ORDER BY page_name";
$results = mysql_query($sql);
$total_page = mysql_num_rows($results);
$smarty->assign('total_page', $total_page);
while($row = mysql_fetch_assoc($results) )
{
$page_list[] = $row;
}
$smarty->assign('page_list', $page_list);
//end manage
//manage page id in block id
$sql = "SELECT * FROM block_contents WHERE block_id=".$_GET['block_id'];
$results = mysql_query($sql);
$total_pages_in_block = mysql_num_rows($results);
$smarty->assign('total_pages_in_block', $total_pages_in_block);
while($row = mysql_fetch_assoc($results) )
{
$pages_in_block[] = $row;
}
$smarty->assign('pages_in_block', $pages_in_block);
//end manage
$smarty->assign('total_block', $total_block);
$smarty->assign('block_content', $block_content);
$smarty->display('show_block_content.tpl');
}elseif($_GET['action']=="deleteBlock"){
$sql = "DELETE FROM content_block WHERE block_id=".$_GET['block_id'];
$results = mysql_query($sql);
//manage
$sql = "SELECT * FROM content_block ORDER BY block_heading";
$results = mysql_query($sql);
$total_page = mysql_num_rows($results);
$smarty->assign('total_block', $total_block);
while($row = mysql_fetch_assoc($results) )
{
$block_list[] = $row;
}
$smarty->assign('block_list', $block_list);
//end manage
$smarty->display('list_all_content_block.tpl');
}elseif($_GET['action']=="updateSelectList"){
//manage
$sql = "SELECT * FROM content_block ORDER BY block_heading";
$results = mysql_query($sql);
while($row = mysql_fetch_assoc($results) )
{
$block_list[] = $row;
}
$smarty->assign('block_list', $block_list);
//end manage
//manage
$sql = "SELECT * FROM content_page ORDER BY page_name";
$results = mysql_query($sql);
$total_page = mysql_num_rows($results);
$smarty->assign('total_page', $total_page);
while($row = mysql_fetch_assoc($results) )
{
$page_list[] = $row;
}
$smarty->assign('page_list', $page_list);
//end manage
//manage page id in block id
$sql = "SELECT * FROM block_contents WHERE block_id=".$_GET['block_id'];
$results = mysql_query($sql);
$total_pages_in_block = mysql_num_rows($results);
$smarty->assign('total_pages_in_block', $total_pages_in_block);
while($row = mysql_fetch_assoc($results) )
{
$pages_in_block[] = $row;
}
$smarty->assign('pages_in_block', $pages_in_block);
//end manage
$smarty->display('select_list_block.tpl');
}else{
//manage
$sql = "SELECT * FROM content_page ORDER BY page_name";
$results = mysql_query($sql);
$total_page = mysql_num_rows($results);
$smarty->assign('total_page', $total_page);
while($row = mysql_fetch_assoc($results) )
{
$page_list[] = $row;
}
$smarty->assign('page_list', $page_list);
//end manage
//manage
$sql = "SELECT * FROM content_block ORDER BY block_heading";
$results = mysql_query($sql);
$total_block = mysql_num_rows($results);
$smarty->assign('total_block', $total_block);
while($row = mysql_fetch_assoc($results) )
{
$block_list[] = $row;
}
$smarty->assign('block_list', $block_list);
//end manage
$smarty->display('manage_content_blocks.tpl');
}
?>