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

if($_POST)
{
      $ch = curl_init();
        $cfile = new CURLFile($_FILES['image']['tmp_name'], $_FILES['image']['type'], $_FILES['image']['name']);

        $data = array("myimage"=>$cfile,"title"=>$_POST['title']);
 
        $url = "https://bps.savarnacloudtech.com/api/downloads.php";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        $responce = curl_exec($ch);
// print_r($data);
// die();
        redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"website", "page_id"=>$pgMod)));
}

elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
    $ch = curl_init();
            $data = array("image"=>$_GET['img'],"action"=>$_GET['action'],"id"=>$_GET['id'],"page_id"=>"downloads");
            $url = "https://bps.savarnacloudtech.com/api/delete.php";
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
            $responce = curl_exec($ch);
            redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"website", "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   facilities where  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 Downloads</h3>
				</div>
				<!-- / Forms: Top Bar -->

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

					
                        
                        <div class="control-group">
							<label class="control-label" for="heading">File</label>
							<div class="controls">
								<input type="file" id="image" name="image" class="input-block-level" value="<?php echo $aryForm['image'] ?>" >
							<?php if(isset($aryForm['file'])){?>
								<img src="<?php echo $aryForm['file'] ?>" style="width:10%" >
								<?php } ?>
							</div>
						</div>
						
						<div class="control-group">
							<label class="control-label" for="heading">Title</label>
							<div class="controls">
								<input type="text" id="image" name="title" class="input-block-level" value="<?php echo $aryForm['title'] ?>">
							</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=website&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"=>"website", "page_id"=>$pgMod,"action"=>"add");

            $url = "https://bps.savarnacloudtech.com/api/get_downloads.php";

            $context  = stream_context_create($options);
            $result = file_get_contents($url, false, $context);

            $temp = json_decode($result,true);
            // $aryList = $temp['slider'];
      
            ?>
            <table class="table" id="example"> 
                <thead>
                    <tr>
                       

                     <th>S.No</th>
                    <th>Title</th>
                    <th>File</th>
                    <th>Action</th>    
                    </tr>
                </thead>
                <tbody>
                <?php foreach($temp as $res){
                   
                    $i++; 
                $aryPgAct["id"]=$res['id'];
                ?>
                    <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                        <th  style="font-weight: 600; color: green;padding: 0.75rem;" ><?php echo $i;?></th>
                        <th  style="font-weight: 600; color: green;padding: 0.75rem;" ><?php echo $res['title'];?></th>
   
      <td style="padding: 0.75rem;">
          <!--<img src="<?php echo $res["file"]; ?>" alt="Service image" style="height: 100px;">-->
           <embed src="<?php echo $res['file']; ?>" width="129" height="150" 
 type="application/pdf">
          </td>
                        <td>
                            <a class="btn btn-primary" href="<?php echo $res['file']; ?>" target="_blank" ><i class="fa fa-eye"></i>View</a>
                            
                            <?php $aryPgAct['action']="delete"; 
                             $aryPgAct['img']=$clist['slider'];
                            ?>
                            <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
       
        ?>
        </div>
  </div>
</div>
	<?php
}
?>
<!-- / Forms -->