- return ~file_name~_edit_main();
- }
-<!--~}~--><!--~opt_display_1_else {~-->
- return ~file_name~_edit_main();
-<!--~}~-->
-}<!--~opt_display_2 {~-->
-
-function ~file_name~_display_main() {
- $id = format_int($_REQUEST['~file_name~_id']);
- unset($_REQUEST['~file_name~_id']);
- if(!$id) {
- message('Error: Broken link');
- return './~file_name~';
- }
- $row = db_get_assoc('~table_name~', 'id,'.~file_name upper~_DB_FIELDS, 'where id=%i', $id);
- if(!$row) {
- message('Error: ~singular cap~ not found');
- return './~file_name~';
- }
- tem_set('display', $row);
-}<!--~}~-->
-
-function ~file_name~_edit_main() {<!--~pulldowns {~-->
- pulldown('~name~', array('option 1', 'option 2', 'option 3'));
-<!--~}~--><!--~opt_db_3 {~-->
- $edit_id = format_int($_REQUEST['~file_name~_edit_id']);
- unset($_REQUEST['~file_name~_edit_id']);
- if($edit_id) {
- # add hidden field for database id of row we're editing
- tem_set('~file_name~_edit_id', $edit_id);
- tem_set('editing', 'show');
- tem_set('edit_msg', 'show');
- }
-
- $delete_id = format_int($_REQUEST['~file_name~_delete_id']);
- unset($_REQUEST['~file_name~_delete_id']);
- if($delete_id) {
- db_delete('~table_name~', 'where id=%i', $delete_id);
- message('~singular cap~ deleted.');
-
- return './~file_name~';
- }
-
- if(!$edit_id) {<!--~opt_listing_1 {~-->
- if(!isset($_REQUEST['~file_name~_new']) && !isset($_REQUEST['~always_field~'])) {
- ~file_name~_display_listing();
- return;
- }
-<!--~}~-->
- tem_set('new_msg', 'show');
- }<!--~}~-->
+ $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);
+}~}~