Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $user_id = $_SESSION['user_id'];
  4. //$polls_id = $_SESSION['polls_id'];
  5. if($_GET) {
  6. if(isset($_GET['insert'])) {
  7. vote_poll1($user_id, $polls_id);
  8. }
  9. elseif(isset($_GET['select'])) {
  10. vote_poll2($user_id, $polls_id);
  11. }
  12. }
  13.  
  14. function vote_poll1($user_id, $polls_id){
  15. $postdata = http_build_query(
  16. array(
  17. 'user_id' => $user_id,
  18. 'poll_id' => $polls_id,
  19. 'vote_value' => '1'
  20. )
  21. );
  22.  
  23. $opts = array(
  24. 'http' => array(
  25. 'method' => 'POST',
  26. 'header' => 'Content-type: application/x-www-form-urlencoded',
  27. 'content' => $postdata
  28. )
  29. );
  30.  
  31. $context = stream_context_create($opts);
  32. $result = file_get_contents('http://whichis4me.herokuapp.com/api/v1/polls/'. $polls_id . '/castvote', false, $context);
  33.  
  34. public function getButtons() {
  35. //$_SESSION['polls_id'] = $this->polls_id;
  36. //echo $_SESSION['polls_id'];
  37. echo $this->polls_id;
  38.  
  39. echo '<script src="https://code.jquery.com/jquery-2.0.0.js"></script>';
  40. echo '<form action="ajax.php" id=' . $this->polls_id . '>';
  41. echo "t";
  42. echo '<input type="submit" class="button" name="insert" value="Click here to vote" />';
  43. echo "tttttt ";
  44. echo '<input type="submit" class="button" name="select" value="Click here to vote" />';
  45. echo "</form>";
  46. echo "<script>";
  47. echo "$(document).ready(function(){";
  48. echo "$('.button').click(function(){";
  49. echo "var clickBtnValue = $(this).val();";
  50. echo "var idValue = $(this).attr('id')";
  51. echo "var ajaxurl = 'ajax.php'";
  52. //echo "var id = " . $this->polls_id;
  53. echo "data = {'action': clickBtnValue, 'id': idValue};";
  54. echo "$.post(ajaxurl, data, function (response) {";
  55. echo 'alert("Action performed successfully");';
  56. echo "});";
  57. echo "});";
  58. echo "});";
  59. echo "</script>";
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement