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:
12 <!--~opt_email_1 {~-->
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';
15 <!--~}~--><!--~opt_db_1 {~-->
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/';
28 <!--~}~--><!--~image_settings {~-->
29 $GLOBALS['~name~_max_width'] = '400';
30 $GLOBALS['~name~_max_height'] = '400';<!--~thumb_settings {~-->
31 $GLOBALS['~name~_thumb_max_width'] = '70';
32 $GLOBALS['~name~_thumb_max_height'] = '70';
33 $GLOBALS['~name~_file_name'] = uniqid() . getmypid() . '.jpg'; # comment this out to use uploader's filename
36 require_once('code/wfpl/template.php');
37 require_once('code/wfpl/format.php');
38 require_once('code/wfpl/messages.php');
39 require_once('code/wfpl/email.php');<!--~opt_db_2 {~-->
40 require_once('code/db_connect.php');<!--~}~--><!--~image_include {~-->
41 require_once('code/wfpl/upload.php');<!--~}~-->
43 function ~file_name~_get_fields() {
46 $data['~name~'] = format_~format~($_REQUEST['~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['delete_~name~'] == 'Yes') {
53 $data['~name~'] = format_image_w_h<!--~thumb_w_h {~-->_thumb_w_h<!--~}~-->($_REQUEST['old_~name~']);
60 <!--~opt_listing_2 {~-->
61 # You may pass a "where clause" for the db query.
62 function ~file_name~_display_listing($where = 'order by ~always_field~ limit 100') {
63 $rows = db_get_assocs('~table_name~', 'id<!--~listing_fields_1 {~-->,~name~<!--~}~-->', $where);
64 if($rows == false || count($rows) == 0) {
65 tem_set('listings', array('empty_listing' => true));
69 # make sure there's something clickable
70 foreach($rows as &$row) {
71 if($row['~always_field~'] == '') {
72 $row['~always_field~'] = '--';
75 tem_set('listings', array(
76 'populated_listing' => true,
81 function ~file_name~_main() {<!--~opt_pass {~-->
82 if(!logged_in_as_admin()) {
83 $GLOBALS['url'] = this_url();
86 <!--~}~--><!--~opt_display_1 {~-->
87 if(isset($_REQUEST['~file_name~_id'])) {
88 return ~file_name~_display_main();
90 return ~file_name~_edit_main();
92 <!--~}~--><!--~opt_display_1_else {~-->
93 return ~file_name~_edit_main();
95 }<!--~opt_display_2 {~-->
97 function ~file_name~_display_main() {
98 $id = format_int($_REQUEST['~file_name~_id']);
99 unset($_REQUEST['~file_name~_id']);
101 message('Error: Broken link');
102 return './~file_name~';
104 $row = db_get_assoc('~table_name~', 'id,'.~file_name upper~_DB_FIELDS, 'where id=%i', $id);
106 message('Error: ~singular cap~ not found');
107 return './~file_name~';
109 tem_set('display', $row);
112 function ~file_name~_edit_main() {<!--~pulldowns {~-->
113 pulldown('~name~', array('option 1', 'option 2', 'option 3'));
114 <!--~}~--><!--~opt_db_3 {~-->
115 $edit_id = format_int($_REQUEST['~file_name~_edit_id']);
116 unset($_REQUEST['~file_name~_edit_id']);
118 # add hidden field for database id of row we're editing
119 tem_set('~file_name~_edit_id', $edit_id);
120 tem_set('editing', 'show');
121 tem_set('edit_msg', 'show');
124 $delete_id = format_int($_REQUEST['~file_name~_delete_id']);
125 unset($_REQUEST['~file_name~_delete_id']);
127 db_delete('~table_name~', 'where id=%i', $delete_id);
128 message('~singular cap~ deleted.');
130 return './~file_name~';
133 if(!$edit_id) {<!--~opt_listing_1 {~-->
134 if(!isset($_REQUEST['~file_name~_new']) && !isset($_REQUEST['~always_field~'])) {
135 ~file_name~_display_listing();
139 tem_set('new_msg', 'show');
142 if(isset($_POST['~always_field~'])) {
143 $data = ~file_name~_get_fields();
145 if("you're happy with the POSTed values") {<!--~opt_db_4 {~-->
147 db_update_assoc('~table_name~', $data, 'where id=%i', $edit_id);
148 message('~singular cap~ updated.');
150 db_insert_assoc('~table_name~', $data);
151 message('~singular cap~ saved.');
152 }<!--~}~--><!--~opt_email_2 {~-->
153 if($GLOBALS['~file_name~_form_recipient'] != 'fixme@example.com') {
154 $to = $GLOBALS['~file_name~_form_recipient'];
155 $from = 'noreply@~this_domain~';
157 if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
158 $reply_to = $_REQUEST['email'];
159 if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
160 $reply_to = "$_REQUEST[name] <$reply_to>";
163 $subject = '~plural cap~ form submitted';
164 $email_template = new tem();
165 $email_template->load('~file_name~.email.txt');
166 $email_template->sets($data);
167 $message = $email_template->run();
170 if(email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
171 message('Due to an internal error, your message could not be sent. Please try again later.');
174 message('Message sent');
177 if($error !== true) {
178 return './~file_name~'; # FIXME is this the page you want to go to after successful form submission?
181 # otherwise, we display the form again. ~file_name~_get_fields() has
182 # already put the posted values back into the template engine, so they will
183 # show up in the form fields. You should add some message asking people to
184 # fix their entry in whatever way you require.<!--~opt_db_5 {~-->
186 # we've recieved an edit id, but no data. So we grab the values to be edited from the database
187 $data = db_get_assoc('~table_name~', ~file_name upper~_DB_FIELDS, 'where id=%i', $edit_id);<!--~}~-->
189 # form not submitted, you can set default values like so:
190 #$data = array('~always_field~' => 'Yes');
192 }<!--~upload_max {~-->
194 tem_set('upload_max_filesize', upload_max_filesize());<!--~}~-->
196 tem_set('form', $data);<!--~show_extra_headers {~-->
197 tem_set('extra_headers', 'show');<!--~}~-->