3 # This form requires wfpl. See: http://jasonwoof.org/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), and create the file
18 # 'code/db_connect.php' which calls db_connect() see:
19 # code/wfpl/examples/db_connect.php
21 # if you rename any of the database fields, you'll need to update this:
23 define('~file_name upper~_DB_FIELDS', '~db_fields~');
24 ~}~~upload_settings {~
25 # Set this to the path to your uploads directory. It can be relative to the
26 # location of this script. IT MUST END WITH A SLASH
27 $GLOBALS['upload_directory'] = 'uploads/';
29 $GLOBALS['~name~_file_name'] = uniqid() . getmypid() . '.txt'; # comment this out to use uploader's filename
31 $GLOBALS['~name~_max_width'] = '400';
32 $GLOBALS['~name~_max_height'] = '400';~thumb_settings {~
33 $GLOBALS['~name~_thumb_max_width'] = '70';
34 $GLOBALS['~name~_thumb_max_height'] = '70';
35 $GLOBALS['~name~_file_name'] = uniqid() . getmypid() . '.jpg'; # comment this out to use uploader's filename
38 require_once('code/wfpl/format.php');
39 require_once('code/wfpl/email.php');~uploads_include {~
40 require_once('code/wfpl/upload.php');~}~
42 function ~file_name~_get_fields() {
45 $data['~name~'] = format_~format~(_REQUEST_cut('~name~')~pulldown_format_extra {~, '~name~'~}~);~}~~image_upload {~
47 if($_FILES['~name~'] && $_FILES['~name~']['error'] == 0) {
48 $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']~}~);
50 if(_REQUEST_cut('delete_~name~') == 'Yes') {
53 $data['~name~'] = format_image_w_h~thumb_w_h {~_thumb_w_h~}~(_REQUEST_cut('old_~name~'));
56 unset($_FILES['~name~']);~}~~file_upload {~
58 $~name~_filename_tmp = $GLOBALS['~name~_file_name'];
59 if(!$~name~_filename_tmp) {
60 $~name~_filename_tmp = format_filename(_REQUEST_cut('~name~'));
62 if($_FILES['~name~'] && $_FILES['~name~']['error'] == 0) {
63 $data['~name~'] = save_uploaded_file('~name~', $GLOBALS['upload_directory'] . $~name~_filename_tmp);
65 if(_REQUEST_cut('delete_~name~') == 'Yes') {
68 $data['~name~'] = format_path(_REQUEST_cut('old_~name~'));
71 unset($_FILES['~name~']);~}~
74 }~opt_public_something {~
77 function ~public_file_name~_main() {~opt_public_display {~
78 $id = _REQUEST_cut('id');
80 return ~file_name~_main_display($id);~opt_public_form unset {~
82 message("Error: Broken Link (~singular cap~ #$id not found)");
83 return './'; # FIXME where should this go?~}~
84 }~}~~opt_public_form {~
85 return ~file_name~_main_form();~}~
89 function ~file_name~_main() {~opt_pass {~
90 if(logged_in_as_admin()) {
91 tem_set('admin_privs');
93 $_REQUEST['url'] = this_url();
97 $id = _REQUEST_cut('edit_id');
99 return ~file_name~_main_form($id);
102 $id = _REQUEST_cut('~file_name~_delete_id');
104 return ~file_name~_main_delete($id);
107 if(_REQUEST_cut('new')) {
108 return ~file_name~_main_form();
111 if(_REQUEST_cut('list')) {
112 return ~file_name~_main_listing();
115 $id = _REQUEST_cut('id');
117 return ~file_name~_main_display($id);
120 if(_REQUEST_cut('download_csv')) {
121 return ~file_name~_csv_download();
124 if(isset($_POST['~always_field~'])) {
125 return ~file_name~_main_form();
129 return ~file_name~_main_listing();~}~~opt_listing unset {~
130 return ~file_name~_main_form();~}~
133 function ~file_name~_main_display($id) {
134 $data = db_get_assoc('~table_name~', 'id,'.~file_name upper~_DB_FIELDS, 'where id=%i', $id);
136 message("Error: Broken Link (~singular cap~ #$id not found)");~opt_public_something {~
137 return './' . $GLOBALS['wfpl_basename'];~}~~opt_public_something unset {~
138 return './~file_name~';~}~
140 tem_set('display', $data);
143 function ~file_name~_main_delete($id) {
144 db_delete('~table_name~', 'where id=%i', $id);
145 message('~singular cap~ deleted.');
146 return './~file_name~';
149 function ~file_name~_csv_download() {
150 require_once('code/wfpl/csv.php');
151 $rows = db_get_rows('~table_name~', 'id,'.~file_name upper~_DB_FIELDS, 'order by id');
152 array_unshift($rows, explode(',',~file_name upper~_DB_FIELDS));
153 array2d_to_csv_download($rows, '~file_name~.csv');
156 function ~file_name~_main_listing() {
159 $sort = _REQUEST_cut('sort');
160 if($sort && substr($sort, 0, 1) === '-') {
161 $sort = substr($sort, 1);
164 $data["sorting-by-$sort"] = '-';
166 $legal_sorts = explode(',', ~file_name upper~_DB_FIELDS);
167 if(!$sort || !in_array($sort, $legal_sorts)) {
168 $sort = '~always_field~';
171 $data['rows'] = db_get_assocs('~table_name~', 'id~listing_fields_1 {~,~name~~}~', "order by $sort $desc limit 1000");
172 tem_set('listings', $data);
175 function ~file_name~_main_form($id = false) {~pulldowns {~
176 pulldown('~name~', ~pulldown_options~);~}~~has_pulldowns {~
182 if(isset($_POST['~always_field~'])) {
183 $data = ~file_name~_get_fields();
185 if("you're happy with the POSTed values") {~opt_db {~
187 db_update_assoc('~table_name~', $data, 'where id=%i', $id);
188 message('~singular cap~ updated.');
190 db_insert_assoc('~table_name~', $data);
191 message('~singular cap~ saved.');
193 if($GLOBALS['~file_name~_form_recipient'] != 'fixme@example.com') {
194 $to = $GLOBALS['~file_name~_form_recipient'];
195 $from = 'noreply@~this_domain~';
197 if(isset($data['email']) and valid_email($data['email'])) {
198 $reply_to = $data['email'];
199 if($data['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $data['name']) !== false) {
200 $reply_to = "$data[name] <$reply_to>";
203 $subject = '~plural cap~ form submitted';
204 $email_template = new tem();
205 $email_template->load('~public_file_name~.email.txt');
206 $email_template->sets($data);
207 $message = $email_template->run();
210 if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
211 message('Due to an internal error, your message could not be sent. Please try again later.');
214 message('Message sent');
217 if($error !== true) {~opt_public_something {~
218 if($GLOBALS['wfpl_basename'] == '~file_name~') {
219 return './~file_name~';
221 # FIXME create this page or change this to go elsewhere
222 return './~public_file_name~_thanks';
223 }~}~~opt_public_something unset {~~opt_db unset {~
224 # FIXME create this page or change this to go elsewhere~}~
225 return './~file_name~~opt_db unset {~_thanks~}~';~}~
228 # otherwise, we display the form again. We've got the form field
229 # values in $data and will put those back in the filds below. You
230 # should add some message asking people to fix their entry in
231 # whatever way you require.~opt_db {~
233 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
234 $data = db_get_assoc('~table_name~', ~file_name upper~_DB_FIELDS, 'where id=%i', $id);~}~
236 # form not submitted, you can set default values like so:
237 #$data = array('~always_field~' => 'Yes');
241 tem_set('$upload_max_filesize', upload_max_filesize());~}~
243 tem_set('form', $data);~show_extra_headers {~