Index: openacs-4/packages/acs-admin/www/auth/authority-set-sort-order.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-admin/www/auth/authority-set-sort-order.tcl,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-admin/www/auth/authority-set-sort-order.tcl 7 Aug 2017 23:47:45 -0000 1.5 +++ openacs-4/packages/acs-admin/www/auth/authority-set-sort-order.tcl 21 Dec 2018 10:57:48 -0000 1.6 @@ -1,63 +1,52 @@ ad_page_contract { - Move authorities up/down to control sort order + Move an authority up or down one step in the authorities sort_order hierarchy @author Simon Carstensen (simon@collaboraid.biz) @creation-date 2003-09-09 @cvs-id $Id$ } { - authority_id:naturalnum,notnull - direction -} - -# Get the authority's sort_order -db_1row select_sort_order { - select sort_order - from auth_authorities - where authority_id = :authority_id -} - -if { $direction eq "up" } { - - db_transaction { - # Increase next authority's sort_order by one - db_dml move_next_authority_down { - update auth_authorities - set sort_order = :sort_order - where sort_order = (select max(sort_order) - from auth_authorities - where sort_order < :sort_order) + {authority_id:naturalnum,notnull} + {direction:notnull,oneof(up|down)} +} -validate { + authority_exists -requires {authority_id:naturalnum} { + if {![db_0or1row dbqd...check_authority_id {select authority_id, sort_order from auth_authorities where authority_id = :authority_id}]} { + ad_complain "Invalid authority" + return } - - # Decrease authority's sort_order by one - db_dml move_authority_up { - update auth_authorities - set sort_order = :sort_order - 1 - where authority_id = :authority_id - } } +} -} elseif { $direction eq "down"} { - - db_transaction { - # Decrease previous authority's sort_order by one - db_dml move_prev_authority_up { - update auth_authorities - set sort_order = :sort_order - where sort_order = (select min(sort_order) - from auth_authorities - where sort_order > :sort_order) - } - - # Increase authority's sort_order by one - db_dml move_authority_down { - update auth_authorities - set sort_order = :sort_order + 1 - where authority_id = :authority_id; - } +# Determine the authority which is next to the passed in authority +# in the order hierarchy depending on the direction we want to move it. +switch -- $direction { + "up" { + set op "<" + set orderby_direction desc } + "down" { + set op ">" + set orderby_direction asc + } +} -} +set sql [subst {select + authority_id as swap_authority_id, + sort_order as swap_sort_order + from auth_authorities + where sort_order $op :sort_order + order by sort_order $orderby_direction + limit 1}] +if {[db_0or1row dbqd..get_swap_authority $sql]} { + # adjust sort_order of the passed in authority + set element_arr(sort_order) $swap_sort_order + auth::authority::edit -authority_id $authority_id -array element_arr + + # adjust sort_order of the swap partner authority + set element_arr(sort_order) $sort_order + auth::authority::edit -authority_id $swap_authority_id -array element_arr +} + ad_returnredirect . ad_script_abort