1. <?php
  2. $query_anketa = $modx->db->query("
  3. SELECT id, pagetitle, content
  4. FROM site_content
  5. WHERE parent=56
  6. AND published=1 AND deleted=0
  7. ORDER BY ID DESC
  8. LIMIT 1
  9. ");
  10. $anketa = $modx->db->makeArray($query_anketa);
  11.  
  12. $anketa_id = $anketa[0]['id'];
  13. $query_odgovori = $modx->db->query("
  14. SELECT id, value
  15. FROM site_tmplvar_contentvalues
  16. WHERE contentid=$anketa_id AND tmplvarid!=18
  17. ");
  18. $odgovori= $modx->db->makeArray($query_odgovori);
  19.  
  20. $rezultati = $modx->db->getValue("SELECT value FROM site_tmplvar_contentvalues WHERE contentid=$anketa_id AND tmplvarid=18");
  21.  
  22. echo '
  23. <form action="" method="post" id="pool">
  24. <p>'.$anketa[0]['content'].'</p>
  25. <table>
  26. ';
  27. foreach($odgovori as $s){
  28. echo '
  29. <tr>
  30. <td><input type="radio" name="question" value="'.$s['id'].'"/></td>
  31. <td class="odg">'.$s['value'].'</td>
  32. </tr>
  33. ';
  34. }
  35. $rezultati=unserialize($rezultati);
  36. if($rezultati[$_POST['question']]) {
  37. $rezultati[$_POST['question']]=$rezultati[$_POST['question']]+1;
  38. }
  39. else {
  40. $rezultati[$_POST['question']]=1;
  41. }
  42.  
  43. echo '</table>
  44. <p>
  45. <br />
  46. <input type="submit" value="Glasuj" class="submit" />
  47. </p>
  48. </form>';
  49.  
  50.  
  51. if(!(count($rezultati))) {
  52. $query_rezultat = $modx->db->query("
  53. INSERT INTO site_tmplvar_contentvalues(tmplvarid, contentid, value) VALUES ('18', '$anketa_id','$res');
  54. ");
  55. }
  56. else {
  57. $res= serialize($rezultati);
  58. $query_rezultat = $modx->db->query("
  59. UPDATE site_tmplvar_contentvalues SET value='$res' WHERE tmplvarid =18 AND contentid =$anketa_id;
  60. ");
  61. }
  62.  
  63. echo'<pre style="position:absolute;font-size:9px;background:#FFF; padding:20px;">';
  64. $res2 = unserialize($res);
  65. echo '<br/>Rezultati:<br/><br/><table>';
  66. foreach($odgovori as $s){
  67. echo '
  68. <tr>
  69. <td style="padding:10px;">'.$s['value'].'</td>
  70. <td style="padding:10px;">'.$res2[$s['id']].'</td>
  71. </tr>
  72. ';
  73. }
  74. echo '</table><br/><br/>';
  75. print $anketa_id;
  76. echo'</pre>';
  77. ?>