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

Dries's avatar
 
Dries committed
3
function submit_enter() {
Dries's avatar
 
Dries committed
4
  global $anonymous, $categories, $allowed_html, $theme, $user;
Dries's avatar
 
Dries committed
5
  
Dries's avatar
 
Dries committed
6
  ### Guidlines:
Dries's avatar
 
Dries committed
7
  $output .= droplet_get("submit_information");
Dries's avatar
 
Dries committed
8 9

  ### Submission form:
Dries's avatar
 
Dries committed
10
  $output .= "<FORM ACTION=\"submit.php\" METHOD=\"post\">\n";
Dries's avatar
Dries committed
11

Dries's avatar
 
Dries committed
12
  $output .= "<P>\n <B>Your name:</B><BR>\n";
Dries's avatar
 
Dries committed
13
  $output .= format_username($user->userid);
Dries's avatar
 
Dries committed
14 15 16 17
  $output .= "</P>\n";
 
  $output .= "<P>\n";
  $output .= " <B>Subject:</B><BR>\n";
Dries's avatar
 
Dries committed
18
  $output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" MAXLENGTH=\"60\"><BR>\n";
Dries's avatar
 
Dries committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
  $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";
Dries's avatar
 
Dries committed
34
  $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"abstract\" MAXLENGTH=\"20\"></TEXTAREA><BR>\n";
Dries's avatar
 
Dries committed
35
  $output .= " <SMALL><I>Allowed HTML tags: ". htmlspecialchars($allowed_html) .".</I></SMALL>\n";
Dries's avatar
 
Dries committed
36 37 38 39
  $output .= "</P>\n";

  $output .= "<P>\n"; 
  $output .= " <B>Extended story:</B><BR>\n";
Dries's avatar
 
Dries committed
40
  $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"article\"></TEXTAREA><BR>\n";
Dries's avatar
 
Dries committed
41
  $output .= " <SMALL><I>Allowed HTML tags: ". htmlspecialchars($allowed_html) .".</I></SMALL>\n";
Dries's avatar
 
Dries committed
42
  $output .= "</P>\n";
Dries's avatar
Dries committed
43
 
Dries's avatar
 
Dries committed
44
  $output .= "<P>\n";
Dries's avatar
 
Dries committed
45 46
  $output .= " You must preview at least once before you can submit:<BR>\n";
  $output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview submission\">\n";
Dries's avatar
 
Dries committed
47
  $output .= "</P>\n";
Dries's avatar
Dries committed
48
 
Dries's avatar
 
Dries committed
49 50 51 52 53
  $output .= "</FORM>\n";
  
  $theme->header();
  $theme->box("Submit a story", $output);
  $theme->footer();
Dries's avatar
Dries committed
54 55
}

Dries's avatar
 
Dries committed
56
function submit_preview($subject, $abstract, $article, $category) {
Dries's avatar
 
Dries committed
57
  global $categories, $allowed_html, $theme, $user;
Dries's avatar
 
Dries committed
58

Dries's avatar
 
Dries committed
59 60
  include "includes/story.inc";

Dries's avatar
 
Dries committed
61 62 63 64
  $output .= "<FORM ACTION=\"submit.php\" METHOD=\"post\">\n";

  $output .= "<P>\n";
  $output .= " <B>Your name:</B><BR>\n";
Dries's avatar
 
Dries committed
65
  $output .= format_username($user->userid);
Dries's avatar
 
Dries committed
66 67 68 69
  $output .= "</P>\n";

  $output .= "<P>\n";
  $output .= " <B>Subject:</B><BR>\n";
Dries's avatar
 
Dries committed
70
  $output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" MAXLENGTH=\"60\" VALUE=\"". check_output(check_field($subject)) ."\"><BR>\n";
Dries's avatar
 
Dries committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  $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";
Dries's avatar
 
Dries committed
86
  $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"abstract\">". check_output($abstract) ."</TEXTAREA><BR>\n";
Dries's avatar
 
Dries committed
87
  $output .= " <SMALL><I>Allowed HTML tags: ". htmlspecialchars($allowed_html) .".</I></SMALL>\n";
Dries's avatar
 
Dries committed
88 89 90 91
  $output .= "</P>\n";

  $output .= "<P>\n";
  $output .= " <B>Extended story:</B><BR>\n";
Dries's avatar
 
Dries committed
92
  $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"article\">". check_output($article) ."</TEXTAREA><BR>\n";
Dries's avatar
 
Dries committed
93
  $output .= " <SMALL><I>Allowed HTML tags: ". htmlspecialchars($allowed_html) .".</I></SMALL>\n";
Dries's avatar
 
Dries committed
94
  $output .= "</P>\n";
Dries's avatar
 
Dries committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

  if (empty($subject)) {
    $output .= "<P>\n";
    $output .= " <FONT COLOR=\"red\"><B>Warning:</B></FONT> you did not supply a <U>subject</U>.\n";
    $outout .= "</P>\n";
    $output .= "<P>\n";
    $output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview submission\">\n";
    $output .= "</P>\n";
  }
  else if (empty($abstract)) {
    $output .= "<P>\n";
    $output .= " <FONT COLOR=\"red\"><B>Warning:</B></FONT> you did not supply an <U>abstract</U>.\n";
    $outout .= "</P>\n";
    $output .= "<P>\n";
    $output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview submission\">\n";
    $output .= "</P>\n";
  }
  else { 
    $output .= "<P>\n";
Dries's avatar
 
Dries committed
114 115
    $output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Preview submission\">\n";
    $output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Submit submission\">\n";
Dries's avatar
 
Dries committed
116 117
    $output .= "</P>\n";
  }
Dries's avatar
Dries committed
118

Dries's avatar
 
Dries committed
119 120 121
  $output .= "</FORM>\n";
  
  $theme->header();
Dries's avatar
Dries committed
122
  $theme->article(new Story($user->userid, $subject, $abstract, $article, $category, time()));
Dries's avatar
 
Dries committed
123 124
  $theme->box("Submit a story", $output);
  $theme->footer();
Dries's avatar
Dries committed
125 126
}

Dries's avatar
 
Dries committed
127
function submit_submit($subject, $abstract, $article, $category) {
Dries's avatar
 
Dries committed
128
  global $user, $theme;
Dries's avatar
Dries committed
129

Dries's avatar
 
Dries committed
130 131 132
  ### Add log entry:
  watchdog("story", "added new story with subject `$subject'");
  
Dries's avatar
 
Dries committed
133
  ### Add submission to SQL table:
Dries's avatar
 
Dries committed
134
  db_query("INSERT INTO stories (author, subject, abstract, article, category, timestamp) VALUES ('$user->id', '". check_input($subject) ."', '". check_input($abstract) ."', '". check_input($article) ."', '". check_input($category) ."', '". time() ."')");
Dries's avatar
 
Dries committed
135
  
Dries's avatar
Dries committed
136 137
  ### Display confirmation message:
  $theme->header(); 
Dries's avatar
 
Dries committed
138
  $theme->box("Thank you for your submission.", droplet_get("submit_confirmation"));
Dries's avatar
Dries committed
139 140 141
  $theme->footer();
}

Dries's avatar
Dries committed
142
include "includes/theme.inc";
Dries's avatar
 
Dries committed
143

Dries's avatar
Dries committed
144
switch($op) {
Dries's avatar
 
Dries committed
145
  case "Preview submission":
Dries's avatar
 
Dries committed
146
    submit_preview($subject, $abstract, $article, $category);
Dries's avatar
Dries committed
147
    break;
Dries's avatar
 
Dries committed
148
  case "Submit submission":
Dries's avatar
 
Dries committed
149
    submit_submit($subject, $abstract, $article, $category);
Dries's avatar
Dries committed
150 151
    break;
  default:
Dries's avatar
 
Dries committed
152
    submit_enter();
Dries's avatar
Dries committed
153 154 155
    break;
}

Dries's avatar
Dries committed
156
?>