-function ~form_name~() {<!--~opt_http_pass_2 start~-->
- # To remove password protection, just delete this block:
- if (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != AUTH_USER || $_SERVER['PHP_AUTH_PW'] != AUTH_PASS) {
- header('WWW-Authenticate: Basic realm="' . AUTH_REALM . '"');
- header('HTTP/1.0 401 Unauthorized');
- echo '401 Unauthorized';
- exit;
- }
- <!--~end~--><!--~opt_db_3 start~-->
- $edit_id = format_int($_REQUEST['~form_name~_edit_id']);
- unset($_REQUEST['~form_name~_edit_id']);
- if($edit_id) {
- # add hidden field for database id of row we're editing
- tem_set('~form_name~_edit_id', $edit_id);
- tem_sub('editing');
- tem_sub('edit_msg');
- }
-
- $delete_id = format_int($_REQUEST['~form_name~_delete_id']);
- unset($_REQUEST['~form_name~_delete_id']);
- if($delete_id) {
- db_delete('~form_name~', 'where id=%i', $delete_id);
- message('Entry deleted.');
-
- # FIXME: what to do after delete?
- return;
- }
-
- if(!$edit_id && !$delet_id) {
- tem_sub('new_msg');
- }<!--~end~-->
-
- if(isset($_REQUEST['~always_field~'])) {
- list(~php_fields~) = ~form_name~_get_fields();
-
- if("you're happy with the POSTed values") {<!--~opt_db_4 start~-->
- if(file_exists($db_connector = 'db_connect.php') || file_exists($db_connector = 'code/db_connect.php')) {
- require_once($db_connector);
- if($edit_id) {<!--~image_db start~-->
- # uploading nothing means leaving it as is.
- if(!$~name~ && $delete_~name~ != 'Yes') {
- $~name~ = db_get_value('~form_name~', '~name~', 'where id=%i', $edit_id);
- }
- <!--~end~-->
- db_update('~form_name~', '~db_fields~', ~php_fields~, 'where id=%i', $edit_id);
- message('Entry updated.');
- } else {
- db_insert('~form_name~', '~db_fields~', ~php_fields~);
- message('Entry saved.');
- }
- }<!--~end~--><!--~opt_email_2 start~-->
- if($GLOBALS['~form_name~_form_recipient'] != "fixme@example.com") {
- $to = $GLOBALS['~form_name~_form_recipient'];
- if(isset($_REQUEST['email']) and valid_email($_REQUEST['email'])) {
- $from = $_REQUEST['email'];
- if($_REQUEST['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $_REQUEST['name']) !== false) {
- $from = "$_REQUEST[name] <$from>";
+function ~file_name~_main_listing() {
+ $data = array();
+ $desc = '';
+ $sort = _REQUEST_cut('sort');
+ if($sort && substr($sort, 0, 1) === '-') {
+ $sort = substr($sort, 1);
+ $desc = ' DESC ';
+ } else {
+ $data["sorting-by-$sort"] = '-';
+ }
+ $legal_sorts = explode(',', ~file_name upper~_DB_FIELDS);
+ if(!$sort || !in_array($sort, $legal_sorts)) {
+ $sort = '~always_field~';
+ }
+
+ $data['rows'] = db_get_assocs('~table_name~', 'id~listing_fields_1 {~,~name~~}~', "order by $sort $desc limit 1000");
+ tem_set('listings', $data);
+}~}~
+
+function ~file_name~_main_form($id = false) {~pulldowns {~
+ pulldown('~name~', ~pulldown_options~);~}~~has_pulldowns {~
+~}~~opt_db {~
+ if($id) {
+ tem_set('id', $id);
+ }
+~}~
+ if(isset($_POST['~always_field~'])) {
+ $data = ~file_name~_get_fields();
+
+ if("you're happy with the POSTed values") {~opt_db {~
+ if($id) {
+ db_update_assoc('~table_name~', $data, 'where id=%i', $id);
+ message('~singular cap~ updated.');
+ } else {
+ db_insert_assoc('~table_name~', $data);
+ message('~singular cap~ saved.');
+ }~}~~opt_email {~
+ if($GLOBALS['~file_name~_form_recipient'] != 'fixme@example.com') {
+ $to = $GLOBALS['~file_name~_form_recipient'];
+ $from = 'noreply@~this_domain~';
+ $reply_to = $to;
+ if(isset($data['email']) and valid_email($data['email'])) {
+ $reply_to = $data['email'];
+ if($data['name'] and ereg('^[a-zA-Z0-9_\' -]*$', $data['name']) !== false) {
+ $reply_to = "$data[name] <$reply_to>";