Guest User

Untitled

a guest
Jan 3rd, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. <?php
  2.  
  3. //fetch.php
  4.  
  5. $connect = new PDO('mysql:host=localhost;dbname=manpower', 'root', '');
  6.  
  7. $query = "
  8. SELECT * FROM supplier_job WHERE jobStatus='offline' order by jobID DESC
  9. ";
  10. $statement = $connect->prepare($query);
  11. $statement->execute();
  12. $result = $statement->fetchAll();
  13. $output = '';
  14. foreach($result as $row)
  15. {
  16. $rating = count_rating($row['jobID'], $connect);
  17. $color = '';
  18. $output .= '
  19.  
  20. <ul class="list-inline" data-rating="'.$rating.'" title="Average Rating - '.$rating.'">
  21. ';
  22.  
  23. for($count=1; $count<=5; $count++)
  24. {
  25. if($count <= $rating)
  26. {
  27. $color = 'color:#ffcc00;';
  28. }
  29. else
  30. {
  31. $color = 'color:#ccc;';
  32. }
  33. $output .= '<li title="'.$count.'" jobID="'.$row['jobID'].'-'.$count.'" data-index="'.$count.'" data-job_id="'.$row['jobID'].'" data-rating="'.$rating.'" class="rating" style="cursor:pointer; '.$color.' font-size:16px;">&#9733;</li>';
  34. }
  35. $output .= '
  36. </ul>
  37. ';
  38. }
  39. echo $output;
  40.  
  41. function count_rating($job_id, $connect)
  42. {
  43. $output = 0;
  44. $query = "SELECT AVG(rating) as rating FROM ratings WHERE job_id = '".$job_id."'";
  45. $statement = $connect->prepare($query);
  46. $statement->execute();
  47. $result = $statement->fetchAll();
  48. $total_row = $statement->rowCount();
  49. if($total_row > 0)
  50. {
  51. foreach($result as $row)
  52. {
  53. $output = round($row["rating"]);
  54. }
  55. }
  56. return $output;
  57. }
  58.  
  59.  
  60. ?>
  61.  
  62. <?php
  63. $servername="localhost";
  64. $username="root";
  65. $password="";
  66. $databasename="manpower";
  67.  
  68. //create connection
  69. $conn=mysqli_connect($servername,$username,$password,$databasename);
  70.  
  71. $queryJob="SELECT * FROM supplier_job WHERE jobStatus='offline' order by jobID DESC";
  72.  
  73. $resultJob=mysqli_query($conn,$queryJob);
  74. if(mysqli_num_rows($resultJob)>0){
  75. while($rowJob=mysqli_fetch_assoc($resultJob)){
  76.  
  77. $locationID=$rowJob['locationID'];
  78. $queryLocation="SELECT * FROM location WHERE locID='$locationID'";
  79. $resultLocation=mysqli_query($conn,$queryLocation);
  80.  
  81. $rowLocation=mysqli_fetch_assoc($resultLocation);
  82. $locationName=$rowLocation['locName'];
  83. $locationAddress=$rowLocation['locStreet'].", ".$rowLocation['locVillage'].", ".$rowLocation['locCity'];
  84.  
  85.  
  86. echo "
  87. <html>
  88. <head>
  89. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  90. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  91. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  92. </head>
  93.  
  94. <div class='single-post d-flex flex-row'><div class='thumb'>
  95. <img src='../img/img-worker/post.png' alt=''>
  96. </div>
  97. <div class='details'>
  98. <div class='title d-flex flex-row justify-content-between'>
  99. <div class='titles'>
  100. <a href=''><h4>".$rowJob['jobTitle']."<small> Published on ".$rowJob['jobPublished']."</small></h4></a>
  101. <h6>By ".$locationName."</h6>
  102. <span id="job_list"></span>
  103.  
  104.  
  105. </div>
  106. <ul>
  107. <li><a class='btn btn-primary' href='./query_boxes/supplier_jobs_accept_accept_jobs.php?jobID=".$rowJob['jobID']."'>Apply</a></li>
  108. </ul>
  109. </div>
  110. <p >".$rowJob['jobCount']." pieces needs to do ".$rowJob['jobType'].". Every manpower member has to work at most ".$rowJob['jobPeriod']." days.
  111. <strong></strong> Job should be complete within ".$rowJob['jobPeriod']." days.</p>
  112.  
  113. <h5>Job Nature: ".$rowJob['jobNature']."</h5>
  114. <p class='address'><span class=''></span>".$locationAddress."</p>
  115. <p class='address'><span class=''></span>".$rowJob['workersJoined']." joined.</p>
  116. </div></div>
  117.  
  118.  
  119. </html>
  120.  
  121. ";
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128. }
  129. }
  130.  
  131. ?>
  132. <script>
  133. $(document).ready(function(){
  134.  
  135. load_supplier_jobs_accept_data();
  136.  
  137. function load_supplier_jobs_accept_data()
  138. {
  139. $.ajax({
  140. url:"fetchrate.php",
  141. method:"POST",
  142. success:function(data)
  143. {
  144. $('#job_list').html(data);
  145. }
  146. });
  147. }
  148.  
  149. $(document).on('mouseenter', '.rating', function(){
  150. var supplier_jobs_accept = $(this).data("supplier_jobs_accept");
  151. var job_id = $(this).data('job_id');
  152. remove_background(job_id);
  153. for(var count = 1; count<=supplier_jobs_accept; count++)
  154. {
  155. $('#'+job_id+'-'+count).css('color', '#ffcc00');
  156. }
  157. });
  158.  
  159. function remove_background(job_id)
  160. {
  161. for(var count = 1; count <= 5; count++)
  162. {
  163. $('#'+job_id+'-'+count).css('color', '#ccc');
  164. }
  165. }
  166.  
  167. $(document).on('mouseleave', '.rating', function(){
  168. var supplier_jobs_accept = $(this).data("supplier_jobs_accept");
  169. var job_id = $(this).data('job_id');
  170. var rating = $(this).data("rating");
  171. remove_background(job_id);
  172. //alert(rating);
  173. for(var count = 1; count<=rating; count++)
  174. {
  175. $('#'+job_id+'-'+count).css('color', '#ffcc00');
  176. }
  177. });
  178.  
  179. $(document).on('click', '.rating', function(){
  180. var supplier_jobs_accept = $(this).data("supplier_jobs_accept");
  181. var job_id = $(this).data('job_id');
  182. $.ajax({
  183. url:"insert_rating.php",
  184. method:"POST",
  185. data:{supplier_jobs_accept:supplier_jobs_accept, job_id:job_id},
  186. success:function(data)
  187. {
  188. if(data == 'done')
  189. {
  190. load_supplier_jobs_accept_data();
  191. alert("You have rate "+supplier_jobs_accept +" out of 5");
  192. }
  193. else
  194. {
  195. alert("There is some problem in System");
  196. }
  197. }
  198. });
  199.  
  200. });
  201.  
  202. });
  203. </script>
Add Comment
Please, Sign In to add comment