<?php

//the global file operation
//include("../public/impOpreation.php");
session_start();
ob_start();
//global varable
global $showoutside;

//to check if the page from .htacess
//$showoutside = $_GET['sn'];
// get the config file
include_once("../public/config.php");



//here the db files that include in the file
// GOES HERE ....................
include("../public/include_dao.php");

//Savedaily
require_once('../models/dao/SavedailyDAO.class.php');
require_once('../models/dto/Savedaily.class.php');
require_once('../models/mysql/SavedailyMySqlDAO.class.php');
require_once('../models/mysql/ext/SavedailyMySqlExtDAO.class.php');

//Save
require_once('../models/dao/SaveDAO.class.php');
require_once('../models/dto/Save.class.php');
require_once('../models/mysql/SaveMySqlDAO.class.php');
require_once('../models/mysql/ext/SaveMySqlExtDAO.class.php');




//get the do the action
$do = $_GET['do'];


/* ======================

  Controller Name :- settlementsaveAjaxCTRL

  OPERTATION in Controller

  1-get save cuurent value by saveid using ajax
  2-display show form where search by saveid using ajax

  ======================== */


//here goes the instances and general variables


$mySavedailyRecord = new SavedailyMySqlDAO();
$mySavedailyEx = new SavedailyMySqlExtDAO();

$mySaveRecord = new SaveMySqlDAO();



//check and use the condetion that suite this action
if ($do == "show") {


    // here the function that do the action
    $saveData = loadSave();
    $smarty->assign("saveData", $saveData);


    $saveId = $_REQUEST['saveid'];


    if (isset($saveId) && $saveId != "-1") {
        $savedailyData = showBySaveId($saveId);
    }

    $smarty->assign("savedailyData", $savedailyData);

    //here the smarty templates
    $smarty->display("settlementsaveview/settlementsave.html");
} elseif ($do == "getSaveValue") {
    $saveId = $_GET['saveId'];

    // here the function that do the action
    $savecurrentValue = getSaveValue($saveId);

    echo $savecurrentValue;
}






/* ===============================
  function in this CONTROLLER
  ================================ */

//select all save data
function loadSave() {

    //to use the variable out side the funcion
    global $mySaveRecord;

    //load all save data
    $saveData = $mySaveRecord->queryByConditions(0);

    return $saveData;
}

//show by saveid
function showBySaveId($SaveId) {
    //to use the variable out side the funcion
    global $mySavedailyEx;

    $savedailyData = $mySavedailyEx->queryWithModelIdAndSave($SaveId);

    return $savedailyData;
}

// get savecurrentvalue from save tbl
function getSaveValue($saveid) {

    //to use the variable out side the funcion
    global $mySaveRecord;

    $saveData = $mySaveRecord->load($saveid);
    $savecurrentvalue = $saveData->savecurrentvalue;

    return $savecurrentvalue;
}

?>