submit.php 6.16 KB
Newer Older
Dries's avatar
Dries committed
1 2
<?PHP

Dries's avatar
 
Dries committed
3
function submit_enter() {
Dries's avatar
Dries committed
4 5
  include "functions.inc";
  include "theme.inc";
Dries's avatar
 
Dries committed
6
  
7
  global $user;
Dries's avatar
Dries committed
8

Dries's avatar
 
Dries committed
9
  $output .= "<FORM ACTION=\"submit.php\" METHOD=\"post\">\n";
Dries's avatar
Dries committed
10

Dries's avatar
 
Dries committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  $output .= "<P>\n <B>Your name:</B><BR>\n";
  if ($user) $output .= " <A HREF=\"account.php\">$user->userid</A> &nbsp; &nbsp; <SMALL>[ <A HREF=\"account.php?op=logout\">logout</A> ]</SMALL>\n";
  else $output .= " $anonymous &nbsp; &nbsp; <SMALL>[ <A HREF=\"account.php\">login</A> | <A HREF=\"account.php\">create an account</A> ]</SMALL>\n"; 
  $output .= "</P>\n";
 
  $output .= "<P>\n";
  $output .= " <B>Subject:</B><BR>\n";
  $output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\"><BR>\n";
  $output .= " <SMALL><I>Bad subjects are 'Check this out!' or 'An article'.  Be descriptive, clear and simple!</I></SMALL>\n";
  $output .= "</P>\n";

  $output .= "<P><B>Category:</B><BR>\n";
  $output .= " <SELECT NAME=\"category\">\n";
    
  for ($i = 0; $i < sizeof($categories); $i++) {
    $output .= "  <OPTION VALUE=\"$categories[$i]\">$categories[$i]</OPTION>\n";
  }
  
  $output .= " </SELECT>\n";
  $output .= "</P>\n";

  $output .= "<P>\n"; 
  $output .= " <B>Abstract:</B><BR>\n";
  $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"abstract\"></TEXTAREA><BR>\n";
  $output .= " <SMALL><I>HTML is nice and dandy, but double check those URLs and HTML tags!</I></SMALL>\n";
  $output .= "</P>\n";

  $output .= "<P>\n"; 
  $output .= " <B>Extended story:</B><BR>\n";
  $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"story\"></TEXTAREA><BR>\n";
  $output .= " <SMALL><I>HTML is nice and dandy, but double check those URLs and HTML tags!</I></SMALL>\n";
  $output .= "</P>\n";
Dries's avatar
Dries committed
43
 
Dries's avatar
 
Dries committed
44 45 46
  $output .= "<P>\n";
  $output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview submission\"> (You must preview at least once before you can submit.)\n";
  $output .= "</P>\n";
Dries's avatar
Dries committed
47

Dries's avatar
 
Dries committed
48 49 50
  $output .= "<P>\n";
  $output .= " <SMALL><B>Important:</B> remember to include the exact URL of your <U>source</U> in case you refer to a story found on another website or your submission might be rejected!</SMALL>\n";
  $output .= "</P>\n";
Dries's avatar
Dries committed
51
 
Dries's avatar
 
Dries committed
52 53 54 55 56
  $output .= "</FORM>\n";
  
  $theme->header();
  $theme->box("Submit a story", $output);
  $theme->footer();
Dries's avatar
Dries committed
57 58
}

Dries's avatar
 
Dries committed
59
function submit_preview($name, $address, $subject, $abstract, $story, $category) {
60
  global $user;
Dries's avatar
 
Dries committed
61

Dries's avatar
Dries committed
62 63
  include "functions.inc";
  include "theme.inc";
Dries's avatar
 
Dries committed
64

Dries's avatar
 
Dries committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  $output .= "<FORM ACTION=\"submit.php\" METHOD=\"post\">\n";

  $output .= "<P>\n";
  $output .= " <B>Your name:</B><BR>\n";
  if ($user) $output .= " <A HREF=\"account.php\">$user->userid</A> &nbsp; &nbsp; <SMALL> [ <A HREF=\"account.php?op=logout\">logout</A> ]</SMALL>\n";
  else $output .= " $anonymous &nbsp; &nbsp; <SMALL>[ <A HREF=\"$account.php\">login</A> | <A HREF=\"account.php\">create an account</A> ]</SMALL>\n";
  $output .= "</P>\n";

  $output .= "<P>\n";
  $output .= " <B>Subject:</B><BR>\n";
  $output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" VALUE=\"". stripslashes($subject) ."\"><BR>\n";
  $output .= " <SMALL><I>Bad subjects are 'Check this out!' or 'An article'.  Be descriptive, clear and simple!</I></SMALL>\n";
  $output .= "</P>\n";

  $output .= "<P><B>Category:</B><BR>\n";
  $output .= " <SELECT NAME=\"category\">\n";
  for ($i = 0; $i < sizeof($categories); $i++) {
    $output .= "  <OPTION VALUE=\"$categories[$i]\" ";
    if ($category == $categories[$i]) $output .= "SELECTED";
    $output .= ">$categories[$i]</OPTION>\n";
  }
  $output .= "</SELECT>\n";
  $output .= "</P>\n";

  $output .= "<P>\n";
  $output .= "<B>Abstract:</B><BR>\n";
  $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"abstract\">". stripslashes($abstract) ."</TEXTAREA><BR>\n";
  $output .= " <SMALL><I>HTML is nice and dandy, but double check those URLs and HTML tags!</I></SMALL>\n";
  $output .= "</P>\n";

  $output .= "<P>\n";
  $output .= " <B>Extended story:</B><BR>\n";
  $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"story\">". stripslashes($story) ."</TEXTAREA><BR>\n";
  $output .= " <SMALL><I>HTML is nice and dandy, but double check those URLs and HTML tags!</I></SMALL>\n";
  $output .= "</P>\n";
Dries's avatar
Dries committed
100
 
Dries's avatar
 
Dries committed
101 102 103
  $output .= "<P>\n";
  $output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview submission\"> <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Submit submission\">\n";
  $output .= "</P>\n";
Dries's avatar
Dries committed
104

Dries's avatar
 
Dries committed
105 106 107
  $output .= "<P>\n";
  $output .= " <SMALL><B>Important:</B> remember to include the exact URL of your <U>source</U> in case you refer to a story found on another website or your submission might be rejected!</SMALL>\n";
  $output .= "</P>\n";
Dries's avatar
Dries committed
108

Dries's avatar
 
Dries committed
109 110 111 112 113 114
  $output .= "</FORM>\n";
  
  $theme->header();
  $theme->preview("", $user->userid, date("l, F d, Y - H:i A", time()), stripslashes($subject), "we-hate-typoes", stripslashes($abstract), "", stripslashes($story));
  $theme->box("Submit a story", $output);
  $theme->footer();
Dries's avatar
Dries committed
115 116
}

Dries's avatar
 
Dries committed
117
function submit_submit($name, $address, $subject, $abstract, $article, $category) {
118
  global $user;
Dries's avatar
 
Dries committed
119

Dries's avatar
Dries committed
120
  include "functions.inc";
Dries's avatar
 
Dries committed
121
  include "theme.inc";
Dries's avatar
Dries committed
122 123

  ### Display confirmation message:
Dries's avatar
 
Dries committed
124

Dries's avatar
Dries committed
125
  $theme->header(); 
Dries's avatar
 
Dries committed
126
  $theme->box("Thanks for your submission.", "Thanks for your submission.  The submission moderators in our basement will frown at it, poke at it, and vote for it!");
Dries's avatar
Dries committed
127 128 129 130
  $theme->footer();

  ### Add submission to queue:
  if ($user) {
131 132
    $uid = $user->id;
    $name = $user->userid;
Dries's avatar
Dries committed
133 134 135 136 137 138
  }
  else {
    $uid = -1;
    $name = $anonymous;
  }

Dries's avatar
 
Dries committed
139
  db_query("INSERT INTO submissions (uid, uname, subject, article, timestamp, category, abstract, score, votes) VALUES ('$uid', '$name', '$subject', '$article', '". time() ."', '$category', '$abstract', '0', '0')");
Dries's avatar
Dries committed
140 141 142 143 144 145 146 147 148
  
  ### Send notification mail (if required):
  if ($notify) {
    $message = "New submission:\n\nsubject...: $subject\nauthor....: $name\ncategory..: $category\nabstract..:\n$abstract\n\narticle...:\n$article";
    mail($notify_email, "$notify_subject $subject", $message, "From: $notify_from\nX-Mailer: PHP/" . phpversion());
  }
}

switch($op) {
Dries's avatar
 
Dries committed
149 150
  case "Preview submission":
    submit_preview($name, $address, $subject, $abstract, $story, $category);
Dries's avatar
Dries committed
151
    break;
Dries's avatar
 
Dries committed
152 153
  case "Submit submission":
    submit_submit($name, $address, $subject, $abstract, $story, $category);
Dries's avatar
Dries committed
154 155
    break;
  default:
Dries's avatar
 
Dries committed
156
    submit_enter();
Dries's avatar
Dries committed
157 158 159 160
    break;
}

?>