/trending.php
PHP | 325 lines | 271 code | 47 blank | 7 comment | 17 complexity | 871ad5ae750a7be33da8667cfbc18494 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
- <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
- <link href="https://cdn.datatables.net/plug-ins/1.10.6/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
- <?php
- ob_start();
- error_reporting(0);
- include('header.php');
- include('sidebarmenu.php');
- include('include/dbconnection.php');
- $chk=0;
- if(isset($_POST['add_trending']))
- {
- $name = $_POST['name'];
- $date= $_POST['date'];
- $enddt= $_POST['enddt'];
- $tm= $_POST['time'];
- $endtime = $_POST['endtime'];
- $address = $_POST['address'];
- if($enddt != '' && $enddt != $date)
- {
- $currdate = $date.' to '.$enddt;
- }else
- {
- $currdate = $date;
- }
- if($endtime != '')
- {
- $currtime = $tm.' to '.$endtime;
- }else
- {
- $currtime = $tm;
- }
-
- $address1 = $currdate.'<br>'.$currtime.'<br>'.$address;
- //echo $address1; exit;
- $base_url = 'http://base3.engineerbabu.com/city_app_indore/';
- $time = round(microtime(true) * 1000);
- //echo"fhdgfrhdnfkdhf9dsufdnsklfnsdiu".$image_name;
- $image_name= ($_FILES['file']['name']);
- $image_name = $time.$image_name;
-
- move_uploaded_file($_FILES["file"]['tmp_name'],"trending/".$image_name);
-
- if($_FILES['file']['name'])
- {
- $location="trending/".$image_name;
-
- }else
- {
- $location = "";
- }
- $image1 = $base_url.$location;
-
- $query = mysqli_query($conn,"INSERT INTO trending(`name`,`date`,`enddt`,`time`,`endtime`,`address`,`created_at`,`image`)values('$name','$date','$enddt','$tm','$endtime','$address','$time','$location')");
-
- if($query)
- {
- $query1 = mysqli_query($conn,"SELECT * FROM `user`");
-
- if(mysqli_num_rows($query1)>0)
- {
- $gcmRegIds = array();
- $i = 0;
- while($query_row = mysqli_fetch_assoc($query1))
- {
- $i++;
- $gcmRegIds[floor($i/1000)][] = $query_row['device_token'];
- }
-
- $pushMessage= array("name" =>$name, "address" =>$address1,"table_key" =>'trending',"image"=>$image1,"mobile"=>"");
-
- if(isset($gcmRegIds))
- {
- $message = $pushMessage;
- $pushStatus = array();
- foreach($gcmRegIds as $val) $pushStatus[] = sendPushNotification($val, $message);
- }
- } header('location:trending.php');
- }
- else
- {
- echo 'Failed';
- }
- }
- function sendPushNotification($registration_ids, $message)
- {
- //print_r($message);exit;
- $url = 'https://android.googleapis.com/gcm/send';
- $fields = array(
- 'registration_ids' => $registration_ids,
- 'data' => array("message"=>$message),
- );
- define('GOOGLE_API_KEY', 'AIzaSyB--dodvnt6cba-sBz4XKZ3s6T-HjlyuVA' );
- $headers = array(
- 'Authorization:key=' . GOOGLE_API_KEY,
- 'Content-Type: application/json'
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
- $result = curl_exec($ch);
- // if($result === false)
- // die('Curl failed ' . curl_error());
- curl_close($ch);
- return $result;
- }
- ?>
- <!--sidebar end-->
-
- <!--main content start-->
- <section id="main-content">
- <section class="wrapper">
- <!-- page start-->
- <div class="row">
- <div class="col-lg-12">
- <section >
- <center><h3> <span><?php if($chk==10){echo"Insert Successfully";}if($chk==20){echo"Already Exist";} ?></span></h3></center>
- <div class="panel-body">
-
- <a href="#myModal-1" data-toggle="modal" class="btn btn-danger">Add Trending</a>
-
- <div aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal-1" class="modal fade">
- <div class="modal-dialog" style="margin: 100px auto;">
- <div class="modal-content" style="">
- <div class="modal-header">
- <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
- <h4 class="modal-title">Add Trending</h4>
- </div>
- <div class="modal-body">
-
- <form class="" role="form" action="" method="post" enctype="multipart/form-data">
- <div class="form-group">
- <label >Name</label>
- <input type="text" name="name" class="form-control" placeholder="Enter Name" required>
- </div>
- <!-- <div class="form-group" >
- <label >Category</label>
- <Select id="language_id" name="category" style="position:relative;" onchange="change_alb_cat(this.value)" class='form-control input-sm m-bot15' required>
- <option value=''>Select category</option>
- <option value='55'>Meet Ups</option>
- <option value='56'>Trade fairs</option>
- <option value='57'>Education</option>
- <option value='58'>Exhibition</option>
- <option value='59'>Fashion Show</option>
- <option value='60'>Concerts</option>
- <option value='61'>Conference</option>
- </Select>
- </div> -->
- <div class="form-group">
- <label >Start Date</label>
- <input type="Date" name="date" class="form-control" placeholder="Inser Date" required>
- </div>
- <div class="form-group">
- <label> End Date</label>
- <input type="Date" name="enddt" class="form-control" placeholder="Inser Date" required>
- </div>
- <div class="form-group">
- <label >Time</label>
- <input type="time" name="time" class="form-control" placeholder="Insert Time" required>
- </div>
- <div class="form-group">
- <label >End Time</label>
- <input type="time" name="endtime" class="form-control" placeholder="Insert Time" >
- </div>
- <div class="form-group">
- <label >Address</label>
- <input type="text" name="address" class="form-control" placeholder="Insert Address" required>
- </div>
- <div class="form-group" style="margine-top:3px;">
- <label>Image</label>
- <input type="file" name="file" class="form-control" >
- </div>
-
- <button type="submit" name="add_trending" class="btn btn-primary">Add</button>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </section>
- </div>
- </div>
- <div class="col-sm-12">
- <section class="panel">
- <div class="panel-body">
- <section id="unseen">
- <table id="example_my" class="table table-bordered table-striped table-condensed">
- <thead>
- <tr>
- <th><center>Sno.</center></th>
- <th><center>Name</center></th>
- <th><center>Start Date</center></th>
- <th><center>End Date</center></th>
- <th><center>Start Time</center></th>
- <th><center>End Time</center></th>
- <th><center>Address</center></th>
- <th><center>Action</center></th>
- </tr>
- </thead>
- <tbody>
-
- <?php
- $result = mysqli_query($conn,"SELECT * FROM `trending` order by id desc");
- $sno=1;
- while($rowselect = mysqli_fetch_array($result))
- {
- $date = $rowselect['date'];
- $enddt = $rowselect['enddt'];
- $endtime = $rowselect['endtime'];
- //echo "SELECT * FROM `speciality` where id = '$spe_id'";
- if($enddt != '')
- {
- $endDate = date("d-m-Y", strtotime($enddt));
- }else
- {
- $endDate = '---';
- }
- if($endtime != '')
- {
- $endtm = $rowselect['time'];
- }else
- {
- $endtm = '---';
- }
- $newDate = date("d-m-Y", strtotime($date));
-
-
- echo"<tr id='trrow".$rowselect['id']."'>
- <td ><center>".$sno."</center></td>
- <td><center>".$rowselect['name']."</center> </td>
- <td><center>".$newDate."</center></td>
- <td><center>".$endDate."</center></td>
- <td><center>".$rowselect['time']."</center></td>
- <td><center>".$endtm."</center></td>
- <td><center>".$rowselect['address']."</center></td>
- <td><center>
- <a id='edit".$rowselect['id']."' class='btn btn-info' href='trending_update.php?id=".$rowselect['id']."' title='Edit' data-rel='tooltip' > <i class='fa fa-pencil'></i> </a>
- <a id='delete".$rowselect['id']."' onclick='deletemain(\"".$rowselect['id']."\");' class='btn btn-danger' href='#' title='Delete' data-rel='tooltip' >
- <i class='fa fa-trash-o '></i>
- </a>
- </center>
- </td>
- </tr>";
- $sno++;
- }
- ?>
-
- </tbody>
- </table>
- </section>
- </div>
- </section>
- </div>
- </div>
- <!-- page end-->
- </section>
- </section>
- <!--main content end-->
- <!--right sidebar start-->
- <!--right sidebar end-->
- <script>
- function deletemain(data)
- {
- var r = confirm('Are you really want to delete this language ?');
- if(r==true)
- {
- $('#trrow'+data).hide();
- $.ajax({
- url:'delete2.php?status=6&id='+data,
- success:function(data){
- //alert(data);
- }
- });
- }
- }
-
- </script>
- </section>
- <script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
- <script src="https://cdn.datatables.net/1.10.6/js/jquery.dataTables.min.js" type="text/javascript"></script>
- <script src="https://cdn.datatables.net/plug-ins/1.10.6/integration/bootstrap/3/dataTables.bootstrap.js" type="text/javascript"></script>
- <script>
- $(document).ready(function() {
- $('#example_my').dataTable();
- } );
- </script>
- <script src="bs3/js/bootstrap.min.js"></script>
- <script src="js/jquery.scrollTo/jquery.scrollTo.js"></script>
- <script src="js/dashboard.js"></script>
- <script src="js/jquery.customSelect.min.js" ></script>
- <script src="js/scripts.js"></script>
- </body>
- </html>