<?php
$pgMod="setting";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);


if($_POST)
{
	if(!isset($_POST['per_day_fine']) || trim($_POST['per_day_fine'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Per Day Fine Required");
	}
	elseif(!isset($_POST['issue_day']) || trim($_POST['issue_day'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Issue Day is Required");
	}
	if($flgEr===TRUE)
	{
		array_push($alert_err,"Some Error Occured");
	}
	else
	{
		foreach($_POST as $field=>$value)
		{
			$flgUp=$db->update("update settings set `value`='".$value."' where `field`='".$field."'");
		}
		$_SESSION["msg"]="Updated Successfully";
		unset($_SESSION['form']);
	}
}		
if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
if(isset($_SESSION['form'])){
	$aryForm=$_SESSION['form'];
	unset($_SESSION['form']);
}
else{
	$aryFormTemp=$db->getRows("select * from settings where school_id='".$_SESSION["admin"]["school_id"]."' and field in ('per_day_fine ','issue_day')");
	if(!is_null($aryFormTemp) && is_array($aryFormTemp) && count($aryFormTemp)>0)
	{
		foreach($aryFormTemp as $iFormTemp)
		{
			$aryForm[$iFormTemp['field']]=$iFormTemp['value'];
		}
	}
}

?>
<!-- Forms --> 
<div class="row-fluid">
    <form method="post" action="">
        <!-- Forms: Box -->
        <div class="span12">

            <!-- Forms: Top Bar -->
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Library Setting</h3>
            </div>
            <!-- / Forms: Top Bar -->

            <!-- Forms: Content -->
            <div class="well no-padding">

                    <div class="control-group">
                        <label class="control-label" for="per_day_fine">Per Day Fine</label>
                        <div class="controls">
                            <input type="text" id="per_day_fine" name="per_day_fine" class="input-block-level" value="<?php echo $aryForm["per_day_fine"] ?>">
                        </div>
                    </div>
                    <div class="control-group hide">
                        <label class="control-label" for="issue_day">Issue Day</label>
                        <div class="controls">
                            <input type="text" id="issue_day" name="issue_day" class="input-block-level" value="<?php echo $aryForm["issue_day"] ?>">
                        </div>
                    </div>
                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary"> Save</button>
                        <button type="button" class="btn"> Cancel</button>
                    </div>
                    
            </div>
            <!-- / Forms: Content -->

        </div>
        <!-- / Forms: Box -->

    </form>
</div>
<!-- / Forms -->