<?php session_start();
require_once 'config.php';
require_once 'auth.php';
$PageName = "PDF's";
$UserId = $_SESSION['User']['id'];
 ?>
<!doctype html>
<html lang="en" class="h-100">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="generator" content="">
    <title><?php echo $Proj_Title; ?></title>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <link rel="apple-touch-icon" href="img/favicon180.png" sizes="180x180">
    <link rel="icon" href="img/favicon32.png" sizes="32x32" type="image/png">
    <link rel="icon" href="img/favicon16.png" sizes="16x16" type="image/png">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&amp;display=swap" rel="stylesheet">
    <link href="vendor/swiper/css/swiper.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet" id="style">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body class="body-scroll d-flex flex-column h-100 menu-overlay">
    <main class="flex-shrink-0 main">
        <?php include_once 'back-header.php'; ?> 
        <div class="main-container">
            
            <div class="container mb-4">
               
                <div class="row">
                      <?php 
            $i=1;
                    //$sql2 = "SELECT tp.* FROM tbl_buy_pdf_details tbp LEFT JOIN tbl_pdf_sell tp ON tbp.PdfId=tp.id WHERE tbp.UserId='$UserId'";
                    $sql2 = "SELECT * FROM tbl_pdf_sell WHERE Status=1";
                    $res2 = getList($sql2);
                    $rncnt3 = getRow($sql2);
                    if($rncnt3 > 0){
                    foreach($res2 as $row){ 
                           $url =  $SiteUrl.'uploads/'.$row["Files"];
                           $sql3 = "SELECT * FROM tbl_buy_pdf_details WHERE PdfId='".$row['id']."' AND UserId='$UserId'";
                           $rncnt4 = getRow($sql3);
                        ?>
                    <div class="col-12 col-md-6">
                        <div class="card border-0 mb-4">
                            <div class="card-body">
                                <div class="row align-items-center">
                                    <div class="col-auto pr-0">
                                        <div class="avatar avatar-50 border-0 bg-default-light rounded-circle text-default">
                                           <?php if($row["Photo"] == '') {?>
                                      <img src="no_image.jpg" style="width: 50px;height: 50px;"> 
                                      <?php } else {?>
                                      <img src="<?php echo $UploadUrl;?>/uploads/<?php echo $row["Photo"];?>" style="width: 50px;height: 50px;">
                                      <?php }  ?>
                                        </div>
                                    </div>
                                    <div class="col-6 align-self-center">
                                        <a href="pdf-details.php?id=<?php echo $row['id'];?>"><h6 class="mb-1"><?php echo $row['Title'];?></h6></a>
                                        <?php if($row['Type'] == 'Free'){?>
                                        <h6 class="mb-1">FREE</h6>
                                        <?php }  else{?>
                                         <h6 class="mb-1">&#8377; <?php echo number_format($row['Amount'],2);?></h6>
                                         <?php } ?>
                                    </div>
                                    <div class="col-auto align-self-center border-left">
                                         <?php if($rncnt4 > 0){?>
                                          <a href="JavaScript:Void(0);" 
onclick="onDownloadFileFromUrl('<?php echo $url;?>','<?php echo $row["Files"];?>')"><button class="btn btn-40 bg-default-light text-default rounded-circle">
                                            <i class="fa fa-download"></i>
                                        </button></a>
                                        <?php } 
                                        else if($row['Type'] == 'Free'){?>
                                       
                                        <a href="JavaScript:Void(0);" 
onclick="onDownloadFileFromUrl('<?php echo $url;?>','<?php echo $row["Files"];?>')"><button class="btn btn-40 bg-default-light text-default rounded-circle">
                                            <i class="fa fa-download"></i>
                                        </button></a>
                                        <?php }  else{?>
                                       
                                       <a href="razorpay/pay2.php?userid=<?php echo $UserId;?>&pdfid=<?php echo $row['id'];?>&amount=<?php echo $row['Amount'];?>" style="padding-top: 10px;"><button class="btn btn-sm btn-default rounded" style="font-size: 10px;">Buy Now</button></a> 
                                   <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php } } else{?>
                        <h3 style="color:red;padding-left: 10px;font-size: 20px;">No PDF Found</h3>
                    <?php } ?>
                </div>
                
                <!--<div class="row">
                    <?php 
            $i=1;
                    $sql2 = "SELECT tp.* FROM tbl_buy_pdf_details tbp LEFT JOIN tbl_pdf_sell tp ON tbp.PdfId=tp.id WHERE tbp.UserId='$UserId'";
                    
                    $res2 = getList($sql2);
                    $rncnt3 = getRow($sql2);
                    if($rncnt3 > 0){
                    foreach($res2 as $row){ 
                         $url =  $SiteUrl.'uploads/'.$row["Files"];
                        ?>
                    <div class="col-12 col-md-6">
                        <div class="card mb-4">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col">
                                        <h5 class="mb-1"><?php echo $row['Title']; ?> </h5>
                                     </div>
                                    <?php 
                               
                                if($row["Files"] == ''){} 
                                else {?> 
                                    <div class="col-auto pl-0">
                                        <a href="JavaScript:Void(0);" 
onclick="onDownloadFileFromUrl('<?php echo $url;?>','<?php echo $row["Files"];?>')"><button class="btn btn-40 bg-default-light text-default rounded-circle">
                                            <i class="fa fa-download"></i>
                                        </button></a>
                                    </div>
                                    <?php }?>
                                </div>
                               
                            </div>
                        </div>
                    </div>
                    <?php } } else{?>
                        <h3 style="color:red;padding-left: 10px;font-size: 16px;">No Pdf Purchase</h3>
                    <?php } ?>
                </div>-->
            </div>

        </div>
    </main>
 <?php include_once 'footer.php'; ?>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="vendor/swiper/js/swiper.min.js"></script>
<script src="js/main.js"></script>
<script src="js/color-scheme-demo.js"></script>
<script src="js/app.js"></script>
<script>
    function onDownloadFileFromUrl(url,filename){
         Android.onDownloadFileFromUrl(''+url+'',''+filename+'');
    }
</script>
</body>
</html>
