<?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/Customer.php');
require_once('../templates/customerTemplate.php');
ob_start();
session_start();
if(!isset($_GET['code'])){
echo "Incorret request";
exit;
}
$mode = $_GET['code'];
switch($mode){
case 'new' :
flushCustomerTemplate();
break;
case 'add' :
//echo "<pre>"; print_r($_POST);exit;
if( $_POST['id']=='' ){
$id = Customer::getLastId() + 1 ;
$saveMode = 'insert';
$successMessage = "<p class='greenhighlight'>Customer Record Saved Successfully!</p>";
$failureMessage = "Customer Record Saving Failed!<br>Entered data loaded below.";
}
else{
$id = $_POST['id'];
$saveMode = 'update';
$successMessage = "<p class='greenhighlight'>Customer Record Updated Successfully!</p>";
$failureMessage = "Customer Record Update Failed!<br>Entered data loaded below.";
}
//echo $newId;exit;
$cstmrObj = new Customer($id, $_POST['txtcompanyname'], $_POST['txtaddress'], $_POST['txtphone1'], $_POST['txtphone2'], $_POST['cmbplan'], $_POST['txtstartdate'], $_POST['txtenddate'], $_POST['txtdescription'], date('Y-m-d H:i:s') , $_SESSION['full_name']);
// echo "<pre>";print_r($cstmrObj);exit;
$cstmrObj->prepareToSave();
$saveStatus = $cstmrObj->Save($saveMode, $error);
if($saveStatus){
$msg = $successMessage;
$error = '';
$cstmrObj->getCustomerById($error);
$cstmrObj->prepareToShow();
}
else{
$msg = "<p class='redhighlight'>" . $failureMessage . "<br>" . $error . "</p>";
if($saveMode == 'insert'){
$cstmrObj->id = null;
}
}
flushCustomerTemplate($cstmrObj, $msg);
//header('Location: ../templates/supportRequestForm.php');
break;
case 'all' :
$recsPerPage = 5;
if( !isset($_GET['pgno']) ){
$pgNo = 1;
}
else{
$pgNo = $_GET['pgno'];
}
$count = Customer::countAllCustomers();
$head = (int)($count / $recsPerPage);
$tail = $count % $recsPerPage;
//echo $head . " " . $tail;exit;
if ($tail == 0)
$numOfPages = $head;
else
$numOfPages = ++$head;
//echo $count;exit;
$customers = Customer::fetchAllCustomers($pgNo, $recsPerPage);
// echo "<pre>"; print_r($customers);exit;
flushListTemplate($customers, $numOfPages, $pgNo);
break;
case 'single' :
$id = $_GET['id'];
$cstmrObj = new Customer($id);
$msg = '';
$getStatus = $cstmrObj->getCustomerById($msg);
if($getStatus){
// echo "<pre>"; print_r($cstmrObj);exit;
flushCustomerTemplate($cstmrObj);
}
else{
echo "<p class='redhighlight'>Mysql Error: " . mysql_errno() . "<br>" .mysql_error() . "</p>";exit;
header("Location: CustomerController.php?code=all");
}
break;
case 'delete' :
$id = $_GET['id'];
$cstmrObj = new Customer($id);
$error = '';
$delStatus = $cstmrObj->Delete($error);
if($delStatus){
$msg = "<p class='greenhighlight'>Customer Record Deleted Successfully!</p>";
}
else{
$msg = "<p class='redhighlight'>Customer delete failed!" . "<br>" . $error . "</p>";
}
echo $msg;
break;
case 'default' :
echo "Wrong url";
break;
}
?>