+<!--~opt_listing {~-->
+# You may pass a "where clause" for the db query.
+function ~file_name~_display_listing($where = 'order by ~always_field~ limit 100') {
+ $rows = db_get_assocs('~table_name~', 'id<!--~listing_fields_1 {~-->,~name~<!--~}~-->', $where);
+ if($rows == false || count($rows) == 0) {
+ tem_set('listings', array('empty_listing' => true));
+ return;
+ }
+
+ # make sure there's something clickable
+ foreach($rows as &$row) {
+ if($row['~always_field~'] == '') {
+ $row['~always_field~'] = '--';
+ }
+ }
+ tem_set('listings', array(
+ 'populated_listing' => true,
+ 'rows' => $rows));
+ return true;
+}
+<!--~}~-->
+function ~file_name~_main() {<!--~opt_pass {~-->
+ if(!logged_in_as_admin()) {
+ $_REQUEST['url'] = this_url();
+ return 'admin_login';
+ }
+<!--~}~--><!--~opt_display {~-->
+ if(isset($_REQUEST['~file_name~_id'])) {
+ return ~file_name~_display_main();
+ } else {
+ return ~file_name~_edit_main();
+ }
+}
+
+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 {~-->
+ $edit_id = format_int($_REQUEST['~file_name~_edit_id']);
+ unset($_REQUEST['~file_name~_edit_id']);