From: Jason Woofenden Date: Fri, 6 Nov 2015 22:04:17 +0000 (-0500) Subject: SCHEMA CHANGE, clean up /admin_images X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl-cms.git;a=commitdiff_plain;h=a2eea0ebfb5a15b80fc0d76be90f4ab453539be0 SCHEMA CHANGE, clean up /admin_images --- diff --git a/admin_images.html b/admin_images.html index f9d7063..d36df35 100644 --- a/admin_images.html +++ b/admin_images.html @@ -71,13 +71,17 @@

[Add a new image]

- + + - - - - - + + + + + +
ImageNameCaption 
+ +
~name html~(blank)~caption html~(blank)[delete this image]
Name: ~name html~
Caption: ~caption html~
[edit][delete]
diff --git a/admin_images.php b/admin_images.php index 73d16c6..2a5ae51 100644 --- a/admin_images.php +++ b/admin_images.php @@ -127,7 +127,22 @@ function admin_images_main_delete($id) { } function admin_images_main_listing() { - $listing_rows = db_get_assocs('cms_images', 'id,image,name,caption', 'order by name, caption'); + $sort_by = 'name'; + $sorts = array( + 'age' => 'created_at desc', + 'name' => "coalesce(nullif(name, ''), caption), created_at", + 'caption' => "coalesce(nullif(caption, ''), name), created_at" + ); + if (isset($_REQUEST['sort'])) { + foreach ($sorts as $s => $sql) { + if ($_REQUEST['sort'] == $s) { + $sort_by = $s; + break; + } + } + } + tem_set("sort_by_$sort_by"); + $listing_rows = db_get_assocs('cms_images', 'id,image,name,caption', 'order by ' . $sorts[$sort_by]); tem_set('listings', $listing_rows); } diff --git a/admin_images.sql b/admin_images.sql index 815969e..27e29e7 100644 --- a/admin_images.sql +++ b/admin_images.sql @@ -4,5 +4,5 @@ create table cms_images ( image varchar(240) not null default "", name varchar(200) not null default "", caption varchar(200) not null default "", - sizes text not null default "" + created_at int not null default 0 ); diff --git a/admin_pages.php b/admin_pages.php index 382ff5c..768b47d 100644 --- a/admin_pages.php +++ b/admin_pages.php @@ -75,7 +75,7 @@ function admin_pages_main_delete($id) { # get all images from admin_images (for cms) function admin_pages_get_images() { $out = []; - $rows = db_get_assocs('cms_images', 'image,name,caption', 'order by name, caption, image'); + $rows = db_get_assocs('cms_images', 'image,name,caption', "order by coalesce(nullif(name, ''), caption), created_at"); if ($rows) { $id = -1; foreach($rows as &$row) { $id += 1; diff --git a/style.styl b/style.styl index 88d0420..7e11c32 100644 --- a/style.styl +++ b/style.styl @@ -421,3 +421,7 @@ table.evenodd display: block padding: 3px 10px 4px 17px font-size: font_size_large +#admin_images_body .th_toggle_buttons + font-weight: normal + color: #777 + space_evenly()