PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/www/docs/video/next.php

https://github.com/palfrey/twfy
PHP | 105 lines | 80 code | 4 blank | 21 comment | 13 complexity | f38cdb3c46821426056db50d52033cfb MD5 | raw file
  1. <?php
  2. include_once "../../includes/easyparliament/init.php";
  3. include_once INCLUDESPATH . 'easyparliament/video.php';
  4. $action = get_http_var('action');
  5. $pid = intval(get_http_var('pid'));
  6. $major = intval(get_http_var('major'));
  7. if (!$major) $major = 1;
  8. if ($action == 'next' || $action=='nextneeded') {
  9. $gid = get_http_var('gid');
  10. $file = intval(get_http_var('file'));
  11. $time = intval(get_http_var('time'));
  12. $db = new ParlDB;
  13. $gid = "uk.org.publicwhip/$gid";
  14. $q_gid = mysql_escape_string($gid);
  15. $q = $db->query("select hdate,hpos,major from hansard where gid='$q_gid'");
  16. if (!$q->rows()) {
  17. # Shouldn't happen, but means a bot has got the URL somehow or similar
  18. header('Location: http://www.theyworkforyou.com/video/');
  19. exit;
  20. }
  21. $hdate = $q->field(0, 'hdate');
  22. $hpos = $q->field(0, 'hpos');
  23. $major = $q->field(0, 'major');
  24. $q = $db->query("select gid, hpos from hansard
  25. where hpos>$hpos and hdate='$hdate' and major=$major
  26. and (htype=12 or htype=13) "
  27. . ($action=='nextneeded'?'and video_status in (1,3)':'') . "
  28. ORDER BY hpos LIMIT 1");
  29. if (!$q->rows()) {
  30. $PAGE->page_start();
  31. $PAGE->stripe_start();
  32. echo '<p>You appear to have reached the end of the day (or
  33. everything after where you have just done has already been stamped).
  34. Congratulations, now <a href="/video/">get stuck in somewhere else</a>!
  35. ;-)</p>';
  36. $PAGE->stripe_end();
  37. $PAGE->page_end();
  38. } else {
  39. $new_gid = $q->field(0, 'gid');
  40. $new_hpos = $q->field(0, 'hpos');
  41. if ($action=='nextneeded') {
  42. $q = $db->query("select adate, atime from hansard, video_timestamps
  43. where hansard.gid = video_timestamps.gid and deleted=0
  44. and hpos<$new_hpos and hdate='$hdate' and major=$major
  45. and (htype=12 or htype=13) and (user_id is null or user_id!=-1)
  46. order by hpos desc limit 1");
  47. $adate = $q->field(0, 'adate');
  48. $atime = $q->field(0, 'atime');
  49. $videodb = video_db_connect();
  50. if ($videodb) {
  51. $video = video_from_timestamp($videodb, $adate, $atime);
  52. $file = $video['id'];
  53. $time = $video['offset'];
  54. }
  55. }
  56. $new_gid = fix_gid_but_leave_section($new_gid);
  57. header('Location: /video/?from=next&file=' . $file . '&gid=' . $new_gid . '&start=' . $time);
  58. }
  59. } elseif ($action == 'random' && $pid) {
  60. $db = new ParlDB;
  61. $q = $db->query("select gid from hansard, member
  62. where video_status in (1,3) and major=$major
  63. and (htype=12 or htype=13)
  64. and hansard.speaker_id = member.member_id and person_id=$pid
  65. ORDER BY RAND() LIMIT 1");
  66. $new_gid = fix_gid_but_leave_section($q->field(0, 'gid'));
  67. header('Location: /video/?from=random&pid=' . $pid . '&gid=' . $new_gid);
  68. } elseif ($action == 'random') {
  69. $db = new ParlDB;
  70. $q = $db->query("select gid, hpos, hdate from hansard
  71. where video_status in (1,3) and major=$major
  72. and (htype=12 or htype=13)
  73. ORDER BY RAND() LIMIT 1");
  74. $gid = $q->field(0, 'gid');
  75. /*
  76. $hpos = $q->field(0, 'hpos');
  77. $hdate = $q->field(0, 'hdate');
  78. # Look a few speeches back to see if any have been matched
  79. # Harder as need to check all since are /not/ done
  80. $q = $db->query("select gid from hansard
  81. where hpos<$hpos and hpos>=$hpos-5 and major=$major and hdate='$hdate'
  82. and htype in (12,13) and video_status in (5,7)
  83. order by hpos desc limit 1");
  84. if ($q->rows()) {
  85. # Take the next speech, presumably needed
  86. $hpos = $q->field(0, 'hpos');
  87. $q = $db->query("select gid from hansard
  88. where hpos>$hpos and major=$major and hdate='$hdate'
  89. and htype in (12,13)
  90. order by hpos limit 1");
  91. $gid = $q->field(0, 'gid');
  92. }
  93. */
  94. $gid = fix_gid_but_leave_section($gid);
  95. header('Location: /video/?from=random&gid=' . $gid);
  96. } else {
  97. # Illegal action
  98. }
  99. function fix_gid_but_leave_section($gid) {
  100. return str_replace('uk.org.publicwhip/', '', $gid);
  101. }