/**
  * Method used to quickly change the ranking of a reminder action
  * from the administration screen.
  *
  * @access  public
  * @param   integer $rem_id The reminder ID
  * @param   integer $rma_id The reminder action ID
  * @param   string $rank_type Whether we should change the entry down or up (options are 'asc' or 'desc')
  * @return  boolean
  */
 function changeRank($rem_id, $rma_id, $rank_type)
 {
     // check if the current rank is not already the first or last one
     $ranking = Reminder_Action::_getRanking($rem_id);
     $ranks = array_values($ranking);
     $ids = array_keys($ranking);
     $last = end($ids);
     $first = reset($ids);
     if ($rank_type == 'asc' && $rma_id == $first || $rank_type == 'desc' && $rma_id == $last) {
         return false;
     }
     if ($rank_type == 'asc') {
         $diff = -1;
     } else {
         $diff = 1;
     }
     $new_rank = $ranking[$rma_id] + $diff;
     if (in_array($new_rank, $ranks)) {
         // switch the rankings here...
         $index = array_search($new_rank, $ranks);
         $replaced_rma_id = $ids[$index];
         $stmt = "UPDATE\n                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_action\n                     SET\n                        rma_rank=" . Misc::escapeInteger($ranking[$rma_id]) . "\n                     WHERE\n                        rma_id=" . Misc::escapeInteger($replaced_rma_id);
         $GLOBALS["db_api"]->dbh->query($stmt);
     }
     $stmt = "UPDATE\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_action\n                 SET\n                    rma_rank=" . Misc::escapeInteger($new_rank) . "\n                 WHERE\n                    rma_id=" . Misc::escapeInteger($rma_id);
     $GLOBALS["db_api"]->dbh->query($stmt);
     return true;
 }