submission.php 4.59 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?
Dries's avatar
 
Dries committed
2

3 4
include_once "includes/submission.inc";
include_once "includes/common.inc";
Dries's avatar
 
Dries committed
5

Dries's avatar
 
Dries committed
6
function submission_display_main() {
Dries's avatar
 
Dries committed
7
  global $theme, $user;
Dries's avatar
 
Dries committed
8

Dries's avatar
 
Dries committed
9
  // Perform query:
Dries's avatar
 
Dries committed
10
  $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.status = 1 ORDER BY s.id");
Dries's avatar
 
Dries committed
11

Dries's avatar
 
Dries committed
12 13
  $content .= "<P>". t("Anyone who happens by, and has some news or some thoughts they'd like to share, can <A HREF=\"submit.php\">submit</A> new content for consideration.  After someone has submitted something, their story is added to a queue.  All registered users can access this list of pending stories, that is, stories that have been submitted, but do not yet appear on the public front page.  Those registered users can vote whether they think the story should be posted or not.  When enough people vote to post a story, the story is pushed over the threshold and up it goes on the public page.  On the other hand, when too many people voted to drop a story, the story will get trashed."). "</P>";
  $content .= "<P>". t("Basically, this means that you, the community, are truly the editors of this site as you have the final decision on the content of this site.  It's you judging the overall quality of a story.  But remember, vote on whether the story is interesting, not on whether you agree with it or not.  If the story goes up, you can disagree all you want, but don't vote `no' because you think the ideas expressed are wrong.  Instead, vote `no' when you think the story is plain boring.") ."</P>";
Dries's avatar
 
Dries committed
14
  $content .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n";
Dries's avatar
 
Dries committed
15
  $content .= " <TR BGCOLOR=\"$bgcolor1\"><TH>". t("Subject") ."</TH><TH>". t("Section") ."</TH><TH>". t("Date") ."</TH><TH>". t("Author") ."</TH><TH>". t("Score") ."</TH></TR>\n";
Dries's avatar
 
Dries committed
16
  while ($submission = db_fetch_object($result)) {
17
    if ($user->id == $submission->author || user_get_history($user->history, "s$submission->id")) $content .= " <TR><TD WIDTH=\"100%\"><A HREF=\"submission.php?op=view&id=$submission->id\">". check_output($submission->subject) ."</A></TD><TD>$submission->section</TD><TD ALIGN=\"center\">". date("Y-m-d", $submission->timestamp) ."<BR>". date("H:m:s", $submission->timestamp) ."</TD><TD ALIGN=\"center\">". format_username($submission->userid) ."</TD><TD ALIGN=\"center\">". submission_score($submission->id) ."</TD></TR>\n";
Dries's avatar
 
Dries committed
18
    else $content .= " <TR><TD WIDTH=\"100%\"><A HREF=\"submission.php?op=view&id=$submission->id\">". check_output($submission->subject) ."</A></TD><TD>$submission->section</TD><TD ALIGN=\"center\">". date("Y-m-d", $submission->timestamp) ."<BR>". date("H:m:s", $submission->timestamp) ."</TD><TD ALIGN=\"center\">". format_username($submission->userid) ."</TD><TD ALIGN=\"center\"><A HREF=\"submission.php?op=view&id=$submission->id\">". t("vote") ."</A></TD></TR>\n";
Dries's avatar
 
Dries committed
19 20 21 22
  }
  $content .= "</TABLE>\n";

  $theme->header();
Dries's avatar
 
Dries committed
23
  $theme->box(t("Open submission queue - Pending stories"), $content);
Dries's avatar
 
Dries committed
24 25 26
  $theme->footer();
}

Dries's avatar
 
Dries committed
27
function submission_display_item($id) {
Dries's avatar
 
Dries committed
28
  global $theme, $user, $submission_votes;
Dries's avatar
 
Dries committed
29

Dries's avatar
 
Dries committed
30 31 32
  $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.id = $id");
  $submission = db_fetch_object($result);

Dries's avatar
Dries committed
33 34
  if ($user->id == $submission->author || user_get_history($user->history, "s$submission->id")) {
    header("Location: story.php?id=$submission->id");
Dries's avatar
 
Dries committed
35 36
  }
  else {
Dries's avatar
Dries committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    $output .= "<FORM ACTION=\"submission.php\" METHOD=\"post\">\n";
    $output .= "<P>\n";
    $output .= " <B>Vote:</B><BR>\n";
    $output .= " <SELECT NAME=\"vote\">\n";
    foreach ($submission_votes as $key=>$value) $output .= "  <OPTION VALUE=\"$value\">$key</OPTION>\n";
    $output .= " </SELECT>\n";
    $output .= "</P>\n";
    $output .= "<P>\n";
    $output .= " <B>Comment:</B><BR>\n";
    $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"7\" NAME=\"comment\"></TEXTAREA>\n";
    $output .= "</P>\n";
    $output .= "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$submission->id\">\n";
    $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Vote\">\n";
    $output .= "</FORM>\n";

Dries's avatar
 
Dries committed
52
    $theme->header();
53
    $theme->article($submission, "[ <A HREF=\"submission.php\"><FONT COLOR=\"$theme->link\">back</FONT></A> ]");
Dries's avatar
Dries committed
54
    $theme->box("Moderate story", $output);
Dries's avatar
 
Dries committed
55
    $theme->footer();
Dries's avatar
 
Dries committed
56
  }
Dries's avatar
 
Dries committed
57 58
}

Dries's avatar
 
Dries committed
59
// Security check:
Dries's avatar
 
Dries committed
60 61 62 63 64
if (strstr($id, " ")) {
  watchdog("error", "submission: attempt to provide malicious input through URI");
  exit();
}

Dries's avatar
 
Dries committed
65
if ($user->id) {
66 67 68

  user_rehash();

Dries's avatar
 
Dries committed
69 70
  switch($op) {
    case "view":
Dries's avatar
 
Dries committed
71
      submission_display_item($id);
Dries's avatar
 
Dries committed
72 73
      break;
    case "Vote";
Dries's avatar
 
Dries committed
74
      submission_vote($id, $vote, $comment);
Dries's avatar
 
Dries committed
75
      // fall through
Dries's avatar
 
Dries committed
76
    default:
Dries's avatar
 
Dries committed
77
      submission_display_main();
Dries's avatar
 
Dries committed
78 79 80 81
      break;
  }
}

Dries's avatar
 
Dries committed
82
?>