PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/trending.php

https://bitbucket.org/Yatindra_Mohite/city_app_indore
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
  1. <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
  2. <link href="https://cdn.datatables.net/plug-ins/1.10.6/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
  3. <?php
  4. ob_start();
  5. error_reporting(0);
  6. include('header.php');
  7. include('sidebarmenu.php');
  8. include('include/dbconnection.php');
  9. $chk=0;
  10. if(isset($_POST['add_trending']))
  11. {
  12. $name = $_POST['name'];
  13. $date= $_POST['date'];
  14. $enddt= $_POST['enddt'];
  15. $tm= $_POST['time'];
  16. $endtime = $_POST['endtime'];
  17. $address = $_POST['address'];
  18. if($enddt != '' && $enddt != $date)
  19. {
  20. $currdate = $date.' to '.$enddt;
  21. }else
  22. {
  23. $currdate = $date;
  24. }
  25. if($endtime != '')
  26. {
  27. $currtime = $tm.' to '.$endtime;
  28. }else
  29. {
  30. $currtime = $tm;
  31. }
  32. $address1 = $currdate.'<br>'.$currtime.'<br>'.$address;
  33. //echo $address1; exit;
  34. $base_url = 'http://base3.engineerbabu.com/city_app_indore/';
  35. $time = round(microtime(true) * 1000);
  36. //echo"fhdgfrhdnfkdhf9dsufdnsklfnsdiu".$image_name;
  37. $image_name= ($_FILES['file']['name']);
  38. $image_name = $time.$image_name;
  39. move_uploaded_file($_FILES["file"]['tmp_name'],"trending/".$image_name);
  40. if($_FILES['file']['name'])
  41. {
  42. $location="trending/".$image_name;
  43. }else
  44. {
  45. $location = "";
  46. }
  47. $image1 = $base_url.$location;
  48. $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')");
  49. if($query)
  50. {
  51. $query1 = mysqli_query($conn,"SELECT * FROM `user`");
  52. if(mysqli_num_rows($query1)>0)
  53. {
  54. $gcmRegIds = array();
  55. $i = 0;
  56. while($query_row = mysqli_fetch_assoc($query1))
  57. {
  58. $i++;
  59. $gcmRegIds[floor($i/1000)][] = $query_row['device_token'];
  60. }
  61. $pushMessage= array("name" =>$name, "address" =>$address1,"table_key" =>'trending',"image"=>$image1,"mobile"=>"");
  62. if(isset($gcmRegIds))
  63. {
  64. $message = $pushMessage;
  65. $pushStatus = array();
  66. foreach($gcmRegIds as $val) $pushStatus[] = sendPushNotification($val, $message);
  67. }
  68. } header('location:trending.php');
  69. }
  70. else
  71. {
  72. echo 'Failed';
  73. }
  74. }
  75. function sendPushNotification($registration_ids, $message)
  76. {
  77. //print_r($message);exit;
  78. $url = 'https://android.googleapis.com/gcm/send';
  79. $fields = array(
  80. 'registration_ids' => $registration_ids,
  81. 'data' => array("message"=>$message),
  82. );
  83. define('GOOGLE_API_KEY', 'AIzaSyB--dodvnt6cba-sBz4XKZ3s6T-HjlyuVA' );
  84. $headers = array(
  85. 'Authorization:key=' . GOOGLE_API_KEY,
  86. 'Content-Type: application/json'
  87. );
  88. $ch = curl_init();
  89. curl_setopt($ch, CURLOPT_URL, $url);
  90. curl_setopt($ch, CURLOPT_POST, true);
  91. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  92. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  93. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  94. $result = curl_exec($ch);
  95. // if($result === false)
  96. // die('Curl failed ' . curl_error());
  97. curl_close($ch);
  98. return $result;
  99. }
  100. ?>
  101. <!--sidebar end-->
  102. <!--main content start-->
  103. <section id="main-content">
  104. <section class="wrapper">
  105. <!-- page start-->
  106. <div class="row">
  107. <div class="col-lg-12">
  108. <section >
  109. <center><h3> <span><?php if($chk==10){echo"Insert Successfully";}if($chk==20){echo"Already Exist";} ?></span></h3></center>
  110. <div class="panel-body">
  111. <a href="#myModal-1" data-toggle="modal" class="btn btn-danger">Add Trending</a>
  112. <div aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal-1" class="modal fade">
  113. <div class="modal-dialog" style="margin: 100px auto;">
  114. <div class="modal-content" style="">
  115. <div class="modal-header">
  116. <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
  117. <h4 class="modal-title">Add Trending</h4>
  118. </div>
  119. <div class="modal-body">
  120. <form class="" role="form" action="" method="post" enctype="multipart/form-data">
  121. <div class="form-group">
  122. <label >Name</label>
  123. <input type="text" name="name" class="form-control" placeholder="Enter Name" required>
  124. </div>
  125. <!-- <div class="form-group" >
  126. <label >Category</label>
  127. <Select id="language_id" name="category" style="position:relative;" onchange="change_alb_cat(this.value)" class='form-control input-sm m-bot15' required>
  128. <option value=''>Select category</option>
  129. <option value='55'>Meet Ups</option>
  130. <option value='56'>Trade fairs</option>
  131. <option value='57'>Education</option>
  132. <option value='58'>Exhibition</option>
  133. <option value='59'>Fashion Show</option>
  134. <option value='60'>Concerts</option>
  135. <option value='61'>Conference</option>
  136. </Select>
  137. </div> -->
  138. <div class="form-group">
  139. <label >Start Date</label>
  140. <input type="Date" name="date" class="form-control" placeholder="Inser Date" required>
  141. </div>
  142. <div class="form-group">
  143. <label> End Date</label>
  144. <input type="Date" name="enddt" class="form-control" placeholder="Inser Date" required>
  145. </div>
  146. <div class="form-group">
  147. <label >Time</label>
  148. <input type="time" name="time" class="form-control" placeholder="Insert Time" required>
  149. </div>
  150. <div class="form-group">
  151. <label >End Time</label>
  152. <input type="time" name="endtime" class="form-control" placeholder="Insert Time" >
  153. </div>
  154. <div class="form-group">
  155. <label >Address</label>
  156. <input type="text" name="address" class="form-control" placeholder="Insert Address" required>
  157. </div>
  158. <div class="form-group" style="margine-top:3px;">
  159. <label>Image</label>
  160. <input type="file" name="file" class="form-control" >
  161. </div>
  162. <button type="submit" name="add_trending" class="btn btn-primary">Add</button>
  163. </form>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. </section>
  171. </div>
  172. </div>
  173. <div class="col-sm-12">
  174. <section class="panel">
  175. <div class="panel-body">
  176. <section id="unseen">
  177. <table id="example_my" class="table table-bordered table-striped table-condensed">
  178. <thead>
  179. <tr>
  180. <th><center>Sno.</center></th>
  181. <th><center>Name</center></th>
  182. <th><center>Start Date</center></th>
  183. <th><center>End Date</center></th>
  184. <th><center>Start Time</center></th>
  185. <th><center>End Time</center></th>
  186. <th><center>Address</center></th>
  187. <th><center>Action</center></th>
  188. </tr>
  189. </thead>
  190. <tbody>
  191. <?php
  192. $result = mysqli_query($conn,"SELECT * FROM `trending` order by id desc");
  193. $sno=1;
  194. while($rowselect = mysqli_fetch_array($result))
  195. {
  196. $date = $rowselect['date'];
  197. $enddt = $rowselect['enddt'];
  198. $endtime = $rowselect['endtime'];
  199. //echo "SELECT * FROM `speciality` where id = '$spe_id'";
  200. if($enddt != '')
  201. {
  202. $endDate = date("d-m-Y", strtotime($enddt));
  203. }else
  204. {
  205. $endDate = '---';
  206. }
  207. if($endtime != '')
  208. {
  209. $endtm = $rowselect['time'];
  210. }else
  211. {
  212. $endtm = '---';
  213. }
  214. $newDate = date("d-m-Y", strtotime($date));
  215. echo"<tr id='trrow".$rowselect['id']."'>
  216. <td ><center>".$sno."</center></td>
  217. <td><center>".$rowselect['name']."</center> </td>
  218. <td><center>".$newDate."</center></td>
  219. <td><center>".$endDate."</center></td>
  220. <td><center>".$rowselect['time']."</center></td>
  221. <td><center>".$endtm."</center></td>
  222. <td><center>".$rowselect['address']."</center></td>
  223. <td><center>
  224. <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>
  225. <a id='delete".$rowselect['id']."' onclick='deletemain(\"".$rowselect['id']."\");' class='btn btn-danger' href='#' title='Delete' data-rel='tooltip' >
  226. <i class='fa fa-trash-o '></i>
  227. </a>
  228. </center>
  229. </td>
  230. </tr>";
  231. $sno++;
  232. }
  233. ?>
  234. </tbody>
  235. </table>
  236. </section>
  237. </div>
  238. </section>
  239. </div>
  240. </div>
  241. <!-- page end-->
  242. </section>
  243. </section>
  244. <!--main content end-->
  245. <!--right sidebar start-->
  246. <!--right sidebar end-->
  247. <script>
  248. function deletemain(data)
  249. {
  250. var r = confirm('Are you really want to delete this language ?');
  251. if(r==true)
  252. {
  253. $('#trrow'+data).hide();
  254. $.ajax({
  255. url:'delete2.php?status=6&id='+data,
  256. success:function(data){
  257. //alert(data);
  258. }
  259. });
  260. }
  261. }
  262. </script>
  263. </section>
  264. <script src="https://code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
  265. <script src="https://cdn.datatables.net/1.10.6/js/jquery.dataTables.min.js" type="text/javascript"></script>
  266. <script src="https://cdn.datatables.net/plug-ins/1.10.6/integration/bootstrap/3/dataTables.bootstrap.js" type="text/javascript"></script>
  267. <script>
  268. $(document).ready(function() {
  269. $('#example_my').dataTable();
  270. } );
  271. </script>
  272. <script src="bs3/js/bootstrap.min.js"></script>
  273. <script src="js/jquery.scrollTo/jquery.scrollTo.js"></script>
  274. <script src="js/dashboard.js"></script>
  275. <script src="js/jquery.customSelect.min.js" ></script>
  276. <script src="js/scripts.js"></script>
  277. </body>
  278. </html>