3 # This form requires wfpl. See: http://sametwice.com/wfpl
5 # This form was initially auto-generated. If you would like to alter the
6 # parameters and generate a new one try this URL:
13 # To send results by e-mail, all you have to do is set your e-mail address here:
14 $GLOBALS['~file_name~_form_recipient'] = 'fixme@example.com';
16 # To save results to a database, you'll need to create the ~table_name~ table.
17 # The file ~file_name~.sql should help with this
19 # if you rename any of the database fields, you'll need to update this:
20 define('~file_name upper~_DB_FIELDS', '~db_fields~');
21 ~}~~upload_settings {~
22 # Set this to the path to your uploads directory. It can be relative to the
23 # location of this script. IT MUST END WITH A SLASH
24 $GLOBALS['upload_directory'] = 'uploads/';
26 $GLOBALS['~name~_file_name'] = uniqid() . getmypid() . '.txt'; # comment this out to use uploader's filename
28 $GLOBALS['~name~_max_width'] = '400';
29 $GLOBALS['~name~_max_height'] = '400';~thumb_settings {~
30 $GLOBALS['~name~_thumb_max_width'] = '70';
31 $GLOBALS['~name~_thumb_max_height'] = '70';
32 $GLOBALS['~name~_file_name'] = uniqid() . getmypid() . '.jpg'; # comment this out to use uploader's filename
35 require_once(__DIR__.'/'.'inc/wfpl/format.php');~opt_email {~
36 require_once(__DIR__.'/'.'inc/wfpl/email.php');~}~~uploads_include {~
37 require_once(__DIR__.'/'.'inc/wfpl/upload.php');~}~
39 $GLOBALS['~file_name~_field_to_caption'] = array(~name_to_caption {~
40 '~name~' => '~caption phpsq~'~ sep {~,~}~~}~
43 function ~file_name~_get_fields() {
46 $data['~name~'] = format_~format~(_REQUEST_cut('~name~')~pulldown_format_extra {~, '~name~'~}~);~}~~image_upload {~
48 if ($_FILES['~name~'] && $_FILES['~name~']['error'] == 0) {
49 $data['~name~'] = convert_uploaded_image('~name~', $GLOBALS['upload_directory'] . $GLOBALS['~name~_file_name'], $GLOBALS['~name~_max_width'], $GLOBALS['~name~_max_height']~thumb_upload_params {~, $GLOBALS['~name~_thumb_max_width'], $GLOBALS['~name~_thumb_max_height']~}~);
51 if (_REQUEST_cut('delete_~name~') == 'Yes') {
54 $data['~name~'] = format_image_w_h~thumb_w_h {~_thumb_w_h~}~(_REQUEST_cut('old_~name~'));
57 unset($_FILES['~name~']);~}~~file_upload {~
59 $~name~_filename_tmp = $GLOBALS['~name~_file_name'];
60 if (!$~name~_filename_tmp) {
61 $~name~_filename_tmp = format_filename(_REQUEST_cut('~name~'));
63 if ($_FILES['~name~'] && $_FILES['~name~']['error'] == 0) {
64 $data['~name~'] = save_uploaded_file('~name~', $GLOBALS['upload_directory'] . $~name~_filename_tmp);
66 if (_REQUEST_cut('delete_~name~') == 'Yes') {
69 $data['~name~'] = format_path(_REQUEST_cut('old_~name~'));
72 unset($_FILES['~name~']);~}~
75 }~opt_public_something {~
78 function ~public_file_name~_main() {~opt_public_display {~
79 $id = _REQUEST_cut('id');
81 return ~file_name~_main_display($id);~opt_public_form unset {~
83 message("Error: Broken Link (~singular cap~ #$id not found)");
84 return './'; # FIXME where should this go?~}~
85 }~}~~opt_public_form {~
86 return ~file_name~_main_form();~}~
90 function ~file_name~_main() {~opt_pass {~
91 session_auth_must('admin_~file_name~');
93 $id = _REQUEST_cut('edit_id');
95 return ~file_name~_main_form($id);
98 $id = _REQUEST_cut('~file_name~_delete_id');
100 return ~file_name~_main_delete($id);
103 if (_REQUEST_cut('new')) {
104 return ~file_name~_main_form();
107 if (_REQUEST_cut('list')) {
108 return ~file_name~_main_listing();
111 $id = _REQUEST_cut('id');
113 return ~file_name~_main_display($id);
116 if (_REQUEST_cut('download_csv')) {
117 return ~file_name~_csv_download();
120 if (isset($_POST['~always_field~'])) {
121 return ~file_name~_main_form();
125 return ~file_name~_main_listing();~}~~opt_listing unset {~
126 return ~file_name~_main_form();~}~
129 function ~file_name~_main_display($id) {
130 $data = db_get_assoc('~table_name~', 'id,'.~file_name upper~_DB_FIELDS, 'where id=%i', $id);
132 message("Error: Broken Link (~singular cap~ #$id not found)");~opt_public_something {~
133 return './' . $GLOBALS['wfpl_basename'];~}~~opt_public_something unset {~
134 return './~file_name~';~}~
136 tem_set('display', $data);
139 function ~file_name~_main_delete($id) {
140 db_delete('~table_name~', 'where id=%i', $id);
141 message('~singular cap~ deleted.');
142 return './~file_name~';
145 function ~file_name~_csv_download() {
146 require_once(__DIR__.'/'.'inc/wfpl/csv.php');
147 $rows = db_get_rows('~table_name~', 'id,'.~file_name upper~_DB_FIELDS, 'order by id');
148 $fields = explode(',', 'id,'.~file_name upper~_DB_FIELDS);
150 foreach ($fields as $field) {
151 if (isset($GLOBALS['~file_name~_field_to_caption'][$field])) {
152 $header[] = $GLOBALS['~file_name~_field_to_caption'][$field];
157 array_unshift($rows, $header);
158 array2d_to_csv_download($rows, '~file_name~.csv');
161 function ~file_name~_main_listing() {
164 $sort = _REQUEST_cut('sort');
165 if ($sort && substr($sort, 0, 1) === '-') {
166 $sort = substr($sort, 1);
169 $data["sorting-by-$sort"] = '-';
171 $legal_sorts = explode(',', ~file_name upper~_DB_FIELDS);
172 if (!$sort || !in_array($sort, $legal_sorts)) {
173 $sort = '~always_field~';
176 $data['rows'] = db_get_assocs('~table_name~', 'id~listing_fields_1 {~,~name~~}~', "order by $sort $desc limit 1000");
177 tem_set('listings', $data);
180 function ~file_name~_main_form($id = false) {~pulldowns {~
181 pulldown('~name~', ~pulldown_options~);~}~~has_pulldowns {~
187 if (isset($_POST['~always_field~'])) {
188 $data = ~file_name~_get_fields();
190 if ("you're happy with the POSTed values") {~opt_db {~
192 db_update_assoc('~table_name~', $data, 'where id=%i', $id);
193 message('~singular cap~ updated.');
195 db_insert_assoc('~table_name~', $data);
196 message('~singular cap~ saved.');
198 if ($GLOBALS['~file_name~_form_recipient'] != 'fixme@example.com') {
199 $to = $GLOBALS['~file_name~_form_recipient'];
200 $from = 'noreply@~this_domain~';
202 if (isset($data['email']) and valid_email($data['email'])) {
203 $reply_to = $data['email'];
204 if ($data['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $data['name']) !== false) {
205 $reply_to = "$data[name] <$reply_to>";
208 $subject = '~plural cap~ form submitted';
209 $email_template = new tem();
210 $email_template->load('~public_file_name~.email.txt');
211 $email_template->sets($data);
212 $message = $email_template->run();
215 if (email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
216 message('Due to an internal error, your message could not be sent. Please try again later.');
219 message('Message sent');
222 if ($error !== true) {~opt_public_something {~
223 if ($GLOBALS['wfpl_basename'] == '~file_name~') {
224 return './~file_name~';
226 # FIXME create this page or change this to go elsewhere
227 return './~public_file_name~_thanks';
228 }~}~~opt_public_something unset {~~opt_db unset {~
229 # FIXME create this page or change this to go elsewhere~}~
230 return './~file_name~~opt_db unset {~_thanks~}~';~}~
233 # else fall through to display the form again. Field values are in $data~opt_db {~
235 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
236 $data = db_get_assoc('~table_name~', ~file_name upper~_DB_FIELDS, 'where id=%i', $id);~}~
238 # form not submitted, you can set default values like so:
239 #$data = array('~always_field~' => 'Yes');
243 tem_set('$upload_max_filesize', upload_max_filesize());~}~
245 tem_set('form', $data);~show_extra_headers {~