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

if($_POST)
{
			 
//echo "<pre>";print_r($_REQUEST);print_r($_FILES);exit;	
	
 $_SESSION['form']=$_POST;
 $flgEr=FALSE;

	if(!isset($_POST['heading']) || trim($_POST['heading'])=='')
	{
			$flgEr=TRUE;

			echo "error==>Please enter  Heading";

	}elseif(!isset($_POST['ctype']) || trim($_POST['ctype'])=='')
	{

			$flgEr=TRUE;

			echo "error==>Please Select slider type ";

	}else{

			$socailData=json_encode($_POST["social"]);

			$status=0;
			
			if(isset($_POST["status"]))$status=1;

			$aryData=array(	'status'=>$status,

						'heading'=>POST('heading'),

						'type'=>POST('ctype'),

						'link'=>POST('link'),
						
						'school_id'=>$_SESSION['admin']['school_id']

						);

			if(isset($_FILES["image"]["name"]) && !empty($_FILES["image"]["name"]))

			{

				$lfilename = basename($_FILES['image']['name']);

				$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));

				if(!in_array($lext,array('exe','html','htm','php')))

				{

					$lnewfile=md5(microtime()).".".$lext;

					if(move_uploaded_file($_FILES['image']['tmp_name'],"./uploads/content/".$lnewfile))
					{

						$aryData['image']=$lnewfile;	

					}

				}

			 }

	}
	
	
	
	if($flgEr!=TRUE && $pgAct=="add") 
	{
         $flgIn=$db->insertAry("slider",$aryData);
	   if(!is_null($flgIn))
	   	{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"cms", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{
//echo "this section has to be perform<pre>";print_r($aryData);exit;
		
		$flgUp=$db->updateAry("slider",$aryData,"where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
		if(!is_null($flgUp))
		{
			$_SESSION['msg']='updated Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"cms", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		
		}
	} 
}		
elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete("slider","where school_id='".$_SESSION["admin"]["school_id"]."' and 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"=>"cms", "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 slider WHERE school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''))
{
//	echo "<pre>";print_r($aryForm);echo "</pre>".$aryForm['root'];exit;
?>
<!-- Forms --> 
	<div class="row-fluid">
        <form method="post" action="" enctype="multipart/form-data">
			<!-- Forms: Box -->
			<div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i> Create a New Slider</h3>
				</div>
				<!-- / Forms: Top Bar -->

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

						<div class="control-group">
							<label class="control-label" for="heading">Heading</label>
							<div class="controls">
								<input type="text" id="heading" name="heading" class="input-block-level" value="<?php if($_POST)echo $_POST["heading"]; else echo $aryForm["heading"]; ?>">
							</div>
						</div> 
                        
                        <div class="control-group">
							<label class="control-label" for="heading">Type</label>
							
                            <div class="controls">
								<select id="type" name="ctype" class="form-control" >

          <?php

                    $types=$db->getRows("select distinct type from slider where status=1");

                    foreach($types as $typ){

                    ?>

          <option value="<?php echo $typ["type"]; ?>" <?php echo selected($typ['type'],$aryForm['type']); ?>><?php echo $typ["type"]; ?></option>

          <?php } ?>

        </select>
							</div>
						</div>
                        
                        <div class="control-group">
							<label class="control-label" for="heading">Image</label>
							<div class="controls">
								<input type="file" id="image" name="image" class="input-block-level" >
							</div>
						</div>
                        
                        <div class="control-group">
							<label class="control-label" for="root">Link Name</label>
							<div class="controls">
								<input type="text" id="link" name="link" class="input-block-level" value="<?php if($_POST)echo $_POST["link"]; else  echo $aryForm["link"]; ?>"  >
							</div>
						</div>
                        
                        <div class="control-group">
							<label class="control-label" for="status">Status</label>
							<div class="controls">
								<input type="checkbox" id="status" name="status" class="input-block-level" <?php if($aryForm['status']=='1')echo "checked";?>>
							</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>
<?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=cms&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"=>"cms", "page_id"=>$pgMod,"action"=>"add");
        $aryList=$db->getRows("SELECT * FROM slider "); $i=0;
        if(is_array($aryList) && count($aryList)>0)
        {
            ?>
            <table class="table" id="example"> 
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Link</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                <?php foreach($aryList as $clist){ $i++; 
                $aryPgAct["id"]=$clist['id'];
                ?>
                    <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                        <td><?php echo $clist["class"] ?></td>
                        <td><?php echo $clist["fee"] ?></td>
                        <td><?php echo $clist["installment"] ?></td>
                        <td>
                        
                        <?php $aryPgAct['action']="create";$aryPgAct['page_id']="monthlyReport";$aryPgAct['class']=$clist["class"]; ?>
                             <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Monthly Report</button></a>
                        <?php $aryPgAct['action']="edit";$aryPgAct['page_id']=$pgMod; ?>
                             <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>
                <tfoot>
                    <tr>
                        <th></th>
                        <th colspan="3"></th>
                    </tr>
                </tfoot>
            </table>
            <?php
        }
        else{
    //window.location.assign(url);
    
            ?>
    <script language="javascript">
    function editData(a)
    {
    alert("val"+a);
    }
    </script> 
         
            <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>-->
              
    <section class="content">
    
      <div class="box edit" style="display:none"> </div>
    
        <div class="box view">
    
       
       
        <div class="box-body">
    
          
          <table  class="table table-bordered table-striped">
          
    
            <thead>
    
              <tr>
    
                    <th>Type</th>
                    <th>Image</th>
                    <th>Status</th>
                    <th>Action</th>    

              </tr>
    
            </thead>
    
            <tbody>
            
    <?php  
    	$aryPgAct=array("src"=>"cms", "page_id"=>$pgMod,"action"=>"add");
        $sliders=$db->getRows("select * from slider");		
    //	echo "<pre>";print_r($sql_limit);echo "</pre>";
    
     foreach($sliders as $sldr){
         $aryPgAct["id"]=$sldr['id'];
     ?>
                 <tr>
                     <td><?php echo $sldr['type']?></td>
                     <td><img src="<?php echo URL_ROOT."uploads/content/".$sldr['image']?>" width='100px'><br><?php echo $sldr['image']?></td>
                     <td><?php
                         if($sldr["status"]==1)
                            echo "<small class='label  bg-green'>Active</small>";
                            else
                            echo "<small class='label  bg-red'>Inactive</small>";
                    ?></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  
    
        //$sql_limit=$db->getRows("select * from ".CONTENT_HEAD);		
    
    
    
     ?>
    
    
    
    
    
    
        </div>
    
        <!-- /.box-body --> 
    
      </div>
    
      <!-- /.box --> 
    
    </section>
              
              
              
            </div>
            <?php
        }
        ?>
        </div>
  </div>
</div>
	<?php
}
?>
<!-- / Forms -->