/**
  * Executes a custom action for a class attribute which was defined on the web page.
  *
  * @param eZHTTPTool $http
  * @param string $action
  * @param eZContentClassAttribute $classAttribute
  */
 public function customClassAttributeHTTPAction($http, $action, $classAttribute)
 {
     $id = $classAttribute->attribute('id');
     $base = "ContentClass";
     $content = $classAttribute->content();
     $customActionVarName = "CustomActionButton";
     $customActionKeyName = "{$id}_{$action}";
     $idArrayName = join('_', array($base, 'sckenhancedselection_id', $id));
     $idArray = array();
     if ($http->hasPostVariable($idArrayName)) {
         $idArray = $http->postVariable($idArrayName);
     }
     switch ($action) {
         case 'new_option':
             $maxID = 0;
             foreach ($content['options'] as $option) {
                 if (intval($option['id']) > $maxID) {
                     $maxID = intval($option['id']);
                 }
             }
             $maxID++;
             $content['options'][] = array('id' => $maxID, 'name' => '', 'identifier' => '', 'priority' => 1);
             break;
         case 'remove_optionlist':
             $removeArrayName = join('_', array($base, "sckenhancedselection_remove", $id));
             if ($http->hasPostVariable($removeArrayName)) {
                 $removeArray = $http->postVariable($removeArrayName);
                 foreach ($removeArray as $removeID) {
                     unset($idArray[$removeID]);
                     unset($content['options'][$removeID]);
                 }
             }
             break;
         case 'move_up':
             $customActionVar = $http->postVariable($customActionVarName);
             // This is where the user clicked
             $customActionValue = $customActionVar[$customActionKeyName];
             // Up == swap selected row with the one above
             // Or: Move the row above below the selected one
             $this->swapRows($customActionValue - 1, $customActionValue, $content, $idArray);
             break;
         case 'move_down':
             $customActionVar = $http->postVariable($customActionVarName);
             // This is where the user clicked
             $customActionValue = $customActionVar[$customActionKeyName];
             // Down == swap selected row with the one below
             // Or: Move the selected row below the one below
             $this->swapRows($customActionValue, $customActionValue + 1, $content, $idArray);
             break;
         case 'sort_optionlist':
             $sortName = join('_', array($base, 'sckenhancedselection_sort_order', $id));
             if ($http->hasPostVariable($sortName)) {
                 $sort = $http->postVariable($sortName);
                 $sortArray = array();
                 $sortOrder = SORT_ASC;
                 $sortType = SORT_STRING;
                 $numericSorts = array('prior');
                 if (strpos($sort, '_') !== false) {
                     list($type, $ranking) = explode('_', $sort);
                     $currentOptions = $content['options'];
                     if ($ranking === 'desc') {
                         $sortOrder = SORT_DESC;
                     }
                     if (in_array($type, $numericSorts)) {
                         $sortType = SORT_NUMERIC;
                     }
                     // Use POST priorities instead of the stored ones
                     // Otherwise you have to store new priorities before you can sort
                     $priorityArray = array();
                     if ($type == 'prior') {
                         $priorityArray = $http->postVariable(join('_', array($base, 'sckenhancedselection_priority', $id)));
                     }
                     foreach (array_keys($currentOptions) as $key) {
                         $option = $currentOptions[$key];
                         switch ($type) {
                             case 'prior':
                                 if (isset($priorityArray[$option['id']])) {
                                     $option['priority'] = $priorityArray[$option['id']];
                                 }
                                 $sortArray[] = $option['priority'];
                                 break;
                             case 'alpha':
                             default:
                                 $sortArray[] = $option['name'];
                                 break;
                         }
                         unset($option);
                     }
                     array_multisort($sortArray, $sortOrder, $sortType, $currentOptions);
                     $idArray = array();
                     foreach ($currentOptions as $option) {
                         $idArray[] = $option['id'];
                     }
                     $content['options'] = $currentOptions;
                 } else {
                     eZDebug::writeError("Unknown sort value. Please use the form type_order (ex. alpha_asc)", "SckEnhancedSelectionType");
                 }
             }
             break;
         default:
             eZDebug::writeError("Unknown class HTTP action: {$action}", "SckEnhancedSelectionType");
     }
     $classAttribute->setContent($content);
     $classAttribute->store();
     $http->setPostVariable($idArrayName, $idArray);
 }