<?php
/*
* Developed by Muhammed Nilufer Nilar
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
require_once('../classes/Plan.php');
require_once('../templates/planTemplate.php');
ob_start();
session_start();
if(!isset($_GET['code'])){
echo "Incorret request";
exit;
}
$mode = $_GET['code'];
switch($mode){
case 'new' :
flushPlanTemplate();
break;
case 'add' :
//echo "<pre>"; print_r($_POST);exit;
if( $_POST['id']=='' ){
$id = Plan::getLastId() + 1 ;
$saveMode = 'insert';
$successMessage = "<p class='greenhighlight'>Plan Record Saved Successfully!</p>";
$failureMessage = "Plan Record Saving Failed!<br>Entered data loaded below.";
}
else{
$id = $_POST['id'];
$saveMode = 'update';
$successMessage = "<p class='greenhighlight'>Plan Record Updated Successfully!</p>";
$failureMessage = "Plan Record Update Failed!<br>Entered data loaded below.";
}
//echo $newId;exit;
$planObj = new Plan($id, $_POST['txtname'], $_POST['txtdescription'], date('Y-m-d H:i:s') , $_SESSION['full_name']);
// echo "<pre>";print_r($planObj);exit;
$planObj->prepareToSave();
$saveStatus = $planObj->Save($saveMode, $error);
if($saveStatus){
$msg = $successMessage;
$error = '';
$planObj->getPlanById($error);
$planObj->prepareToShow();
}
else{
$msg = "<p class='redhighlight'>" . $failureMessage . "<br>" . $error . "</p>";
if($saveMode == 'insert'){
$planObj->id = null;
}
}
flushPlanTemplate($planObj, $msg);
//header('Location: ../templates/supportRequestForm.php');
break;
case 'all' :
$recsPerPage = 5;
if( !isset($_GET['pgno']) ){
$pgNo = 1;
}
else{
$pgNo = $_GET['pgno'];
}
$count = Plan::countAllPlans();
$head = (int)($count / $recsPerPage);
$tail = $count % $recsPerPage;
//echo $head . " " . $tail;exit;
if ($tail == 0)
$numOfPages = $head;
else
$numOfPages = ++$head;
//echo $count;exit;
$plans = Plan::fetchAllPlans($pgNo, $recsPerPage);
flushListTemplate($plans, $numOfPages, $pgNo);
break;
case 'single' :
$id = $_GET['id'];
$planObj = new Plan($id);
$msg = '';
$getStatus = $planObj->getPlanById($msg);
if($getStatus){
// echo "<pre>"; print_r($planObj);exit;
flushPlanTemplate($planObj);
}
else{
echo "<p class='redhighlight'>Mysql Error: " . mysql_errno() . "<br>" .mysql_error() . "</p>";exit;
header("Location: PlanController.php?code=all");
}
break;
case 'delete' :
$id = $_GET['id'];
$planObj = new Plan($id);
$error = '';
$delStatus = $planObj->Delete($error);
if($delStatus){
$msg = "<p class='greenhighlight'>Plan Record Deleted Successfully!</p>";
}
else{
$msg = "<p class='redhighlight'>Plan delete failed!" . "<br>" . $error . "</p>";
}
echo $msg;
break;
case 'default' :
echo "Wrong url";
break;
}
?>