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


if($_POST)
{
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;

	if($flgEr!=TRUE && $pgAct=="add")
	{
    $_POST["added_by"]=$_SESSION["admin"]["uid"];

		$flgIn=$db->insertAry("publication",$_POST);
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Library", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{
		$flgUp=$db->updateAry("publication",$_POST,"where id='".$_GET['id']."'");
		if(!is_null($flgUp))
		{
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Library", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		}
	} 
}		
elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete("publication", "where id='".$_GET['id']."'");
	if(!is_null($res)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Library", "page_id"=>$pgMod)));
}
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($pgAct=="edit" && $_GET["id"]!="")
{   
	$aryForm=$db->getRow("SELECT * FROM publication WHERE id='".$_GET['id']."'");
}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''))
{ 
	if(isset($_SESSION['form']))
	{
		$aryForm=$_SESSION['form'];
		unset($_SESSION['form']);
	}
?>
<!-- Forms --> 
<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 96.7% !important;overflow: inherit !important;} 
</style>
<form method="post" action="" enctype="multipart/form-data">
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Add New Publisher</h3>
                <div style="float:right; margin-top:5px">
                <!--<button type="button" onclick="printDiv('printableDiv')" class="btn btn-primary">Print</button>-->
                    <button type="submit" class="btn btn-primary"> Save</button>
                    <button type="reset" class="btn"> Cancel</button>
                </div>
            </div>
            <div class="well"  id="printableDiv">
			<!-- Forms: Box -->
			<div class="span6">
				<div class="well no-padding">

                        <div class="control-group">
							<label>Publisher Name <span style="color:red;font-size:18px;">*</span></label>
							<input type="text" name="publisher" class="input-block-level" value="<?php echo $aryForm["publisher"]; ?>" required>
						</div>

						<div class="control-group">
							<label>Phone No. <span style="color:red;font-size:18px;">*</span></label>
							<input type="text" name="mobile" class="input-block-level" value="<?php echo $aryForm["mobile"]; ?>" required>
						</div>

  						<div class="control-group">
							<label>Email</label>
							<input type="text" name="email" class="input-block-level" value="<?php echo $aryForm["email"]; ?>" >
						</div>

						<div class="control-group">
							<label>Address</label>
                            <textarea name="address" class="input-block-level" rows="5"><?php echo $aryForm["address"]; ?></textarea>
						</div>

                </div>
           </div>
           <div class="span6">
				<div class="well no-padding">

                        <div class="control-group">
							<label>Contact Person Name</label>
							<input type="text" name="person" class="input-block-level" value="<?php echo $aryForm["person"]; ?>" >
						</div>

						<div class="control-group">
							<label>Contact No.</label>
							<input type="text" name="contact" class="input-block-level" value="<?php echo $aryForm["contact"]; ?>" >
						</div>

  						<div class="control-group">
							<label>Contact Email</label>
							<input type="text" name="contact_email" class="input-block-level" value="<?php echo $aryForm["contact_email"]; ?>" >
						</div>

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

			</div>
            </div>
        </div>
        
	</div>
</form>
<!-- / Forms -->
<?php
}
else{
	?>
	<div class="row-fluid"><div class="span12"><div class="top-bar">
    <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
    <button style="float:right; margin-top:5px" onclick="window.location='./?src=Library&page_id=<?php echo $pgMod; ?>&action=add'" class="btn" type="button">Add <?php echo $pgMod; ?></button>
    </div>
    <div class="well no-padding">
	<?php
	$aryPgAct=array("src"=>"Library", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("select * from publication ");
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example">
            <thead>
                <tr>
                    <th>S No.</th>
                    <th>Publication</th>
                    <th>Phone No.</th>
                    <th>Email</th>
                    <th>Contact Person</th>
                    <th>Contact No.</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
                $aryPgAct["id"]=$clist['id'];
            ?>
                <tr>
                    <td><?php echo $i; ?></td>
                    <td><?php echo $clist["publisher"] ?></td>
                    <td><?php echo $clist["mobile"] ?></td>
                    <td><?php echo $clist["email"] ?></td>
                    <td><?php echo $clist["person"] ?></td>
                    <td><?php echo $clist["contact"] ?></td>
                    <td>
                     <?php $aryPgAct['action']="edit"; ?>
                         <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</button></a>
                    <?php $aryPgAct['action']="delete"; ?>
                         <a href="javascript:;" onclick="del('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>  
                    </td>
                </tr>
            <?php } ?>
            </tbody>
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?>
	</div></div></div>
	<?php
}
?>