/**
  * Get's the previous URL that lead up to the current request.
  *
  * NOTE: Honestly, this should be built into SS_HTTPRequest, but we can't depend on that right now... so instead,
  * this is being copied verbatim from Controller (in the framework).
  *
  * @param SS_HTTPRequest $request
  * @return string
  */
 protected function getBackURL(SS_HTTPRequest $request)
 {
     // Initialize a sane default (basically redirects to root admin URL).
     $controller = $this->getToplevelController();
     $url = method_exists($this->requestHandler, "Link") ? $this->requestHandler->Link() : $controller->Link();
     // Try to parse out a back URL using standard framework technique.
     if ($request->requestVar('BackURL')) {
         $url = $request->requestVar('BackURL');
     } else {
         if ($request->isAjax() && $request->getHeader('X-Backurl')) {
             $url = $request->getHeader('X-Backurl');
         } else {
             if ($request->getHeader('Referer')) {
                 $url = $request->getHeader('Referer');
             }
         }
     }
     return $url;
 }
 /**
  * Import the current file
  * @param  SS_HTTPRequest $request
  */
 public function import(SS_HTTPRequest $request)
 {
     $hasheader = (bool) $request->postVar('HasHeader');
     $cleardata = $this->component->getCanClearData() ? (bool) $request->postVar('ClearData') : false;
     if ($request->postVar('action_import')) {
         $file = File::get()->byID($request->param('FileID'));
         if (!$file) {
             return "file not found";
         }
         $colmap = Convert::raw2sql($request->postVar('mappings'));
         if ($colmap) {
             //save mapping to cache
             $this->cacheMapping($colmap);
             //do import
             $results = $this->importFile($file->getFullPath(), $colmap, $hasheader, $cleardata);
             $this->gridField->getForm()->sessionMessage($results->getMessage(), 'good');
         }
     }
     $controller = $this->getToplevelController();
     $url = method_exists($this->requestHandler, "Link") ? $this->requestHandler->Link() : $controller->Link();
     $controller->redirect($url);
 }