- 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>";