JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
listings sort when you click headers
[wfpl.git] / metaform / template.php
index fa05c07..6479fc5 100644 (file)
@@ -143,8 +143,22 @@ function ~file_name~_main_delete($id) {
 }~}~~opt_listing {~
 
 function ~file_name~_main_listing() {
-       $listing_rows = db_get_assocs('~table_name~', 'id~listing_fields_1 {~,~name~~}~', 'order by ~always_field~ limit 1000');
-       tem_set('listings', $listing_rows);
+       $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 {~