submit.php 5.35 KB
Newer Older
Dries's avatar
Dries committed
1 2 3 4 5 6 7
<?PHP

function defaultDisplay() {
  include "functions.inc";
  include "theme.inc";
  $theme->header();

8
  global $user;
Dries's avatar
Dries committed
9 10 11 12 13

  print "<FORM ACTION=\"submit.php\" METHOD=\"post\">";

  print "<P>\n <B>Your name:</B><BR>";
  if ($user) {
14
    echo " <A HREF=\"account.php\">$user->userid</A> &nbsp; &nbsp; <FONT SIZE=\"2\">[ <A HREF=\"account.php?op=logout\">logout</A> ]</FONT>";
Dries's avatar
Dries committed
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  } else {
    echo "$anonymous &nbsp; &nbsp; <FONT SIZE=\"2\">[ <A HREF=\"account.php\">login</A> | <A HREF=\"account.php\">create an account</A> ]</FONT>";
  } 
  ?>

  <P>
   <B>Subject:</B><BR>
   <INPUT TYPE="text" NAME="subject" SIZE="50"><BR>
   <FONT SIZE="2"><I>Bad subjects are 'Check this out!' or 'An article'.  Be descriptive, clear and simple!</I></FONT>
  </P>

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

  <P> 
   <B>Abstract:</B></I><BR>
   <TEXTAREA WRAP="virtual" COLS="50" ROWS="8" NAME="abstract"></TEXTAREA><BR>
   <FONT SIZE="2"><I>HTML is nice and dandy, but double check those URLs and HTML tags!</FONT>
  </P>

  <P> 
   <B>Extended story:</B></I><BR>
   <TEXTAREA WRAP="virtual" COLS="50" ROWS="15" NAME="story"></TEXTAREA><BR>
   <FONT SIZE="2"><I>HTML is nice and dandy, but double check those URLs and HTML tags!</FONT>
  </P>
 
  <P>
   <INPUT TYPE="submit" NAME="op" VALUE="Preview story"> (You must preview at least once before you can submit.)
  </P>

  <P>
   <FONT SIZE="2"><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!</FONT>
  </P>
 
  </FORM>
  <?PHP
   $theme->footer();
}

function PreviewStory($name, $address, $subject, $abstract, $story, $category) {
62
  global $user;
Dries's avatar
Dries committed
63 64 65 66
  include "functions.inc";
  include "theme.inc";
  $theme->header();

Dries's avatar
 
Dries committed
67

Dries's avatar
Dries committed
68
  print "<B>Preview:</B><BR>";
69
  $theme->preview("", $user->userid, date("l, F d, Y - H:i A", time()), stripslashes($subject), "we-hate-typoes", stripslashes($abstract), "", stripslashes($story));
Dries's avatar
 
Dries committed
70

Dries's avatar
Dries committed
71 72 73 74
  print "<FORM ACTION=\"submit.php\" METHOD=\"post\">";

  print "<P>\n <B>Your name:</B><BR>";
  if ($user) {
75
    echo " <A HREF=\"account.php\">$user->userid</A> &nbsp; &nbsp; <FONT SIZE=\"2\"> [ <A HREF=\"account.php?op=logout\">logout</A> ]</FONT>";
Dries's avatar
Dries committed
76 77 78 79 80 81 82
  } else {
    echo "$anonymous &nbsp; &nbsp; <FONT SIZE=\"2\">[ <A HREF=\"$account.php\">login</A> | <A HREF=\"account.php\">create an account</A> ]</FONT>";
  } 
  ?>

  <P>
   <B>Subject:</B><BR>
Dries's avatar
 
Dries committed
83
   <INPUT TYPE="text" NAME="subject" SIZE="50" VALUE="<? print stripslashes($subject); ?>"><BR>
Dries's avatar
Dries committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
   <FONT SIZE="2"><I>Bad subjects are 'Check this out!' or 'An article'.  Be descriptive, clear and simple!</I></FONT>
  </P>

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

  <P> 
   <B>Abstract:</B></I><BR>
Dries's avatar
 
Dries committed
101
   <TEXTAREA WRAP="virtual" COLS="50" ROWS="8" NAME="abstract"><? print stripslashes($abstract); ?></TEXTAREA><BR>
Dries's avatar
Dries committed
102 103 104 105 106
   <FONT SIZE="2"><I>HTML is nice and dandy, but double check those URLs and HTML tags!</FONT>
  </P>

  <P> 
   <B>Extended story:</B></I><BR>
Dries's avatar
 
Dries committed
107
   <TEXTAREA WRAP="virtual" COLS="50" ROWS="15" NAME="story"><? print stripslashes($story); ?></TEXTAREA><BR>
Dries's avatar
Dries committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
   <FONT SIZE="2"><I>HTML is nice and dandy, but double check those URLs and HTML tags!</FONT>
  </P>
 
  <P>
   <INPUT TYPE="submit" NAME="op" VALUE="Preview again"> <INPUT TYPE="submit" NAME="op" VALUE="Submit story">
  </P>

  <P>
   <FONT SIZE="2"><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!</FONT>
  </P>

  </FORM>
  <?PHP
   $theme->footer();
}

function submitStory($name, $address, $subject, $abstract, $article, $category) {
125
  global $user;
Dries's avatar
Dries committed
126 127 128 129 130
  include "functions.inc";

  ### Display confirmation message:
  include "theme.inc";
  $theme->header(); 
Dries's avatar
 
Dries committed
131
  $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
132 133 134 135
  $theme->footer();

  ### Add submission to queue:
  if ($user) {
136 137
    $uid = $user->id;
    $name = $user->userid;
Dries's avatar
Dries committed
138 139 140 141 142 143
  }
  else {
    $uid = -1;
    $name = $anonymous;
  }

Dries's avatar
 
Dries committed
144
  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
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  
  ### 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) {
  case "Preview story":
    PreviewStory($name, $address, $subject, $abstract, $story, $category);
    break;
  case "Preview again":
    PreviewStory($name, $address, $subject, $abstract, $story, $category);
    break;
  case "Submit story":
    SubmitStory($name, $address, $subject, $abstract, $story, $category);
    break;
  default:
    defaultDisplay();
    break;
}

?>