public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     if (!$request) {
         user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
     }
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->setDataModel($model);
     // Find our action or set to index if not found
     $action = $this->request->param("Action");
     if (!$action) {
         $action = "index";
     }
     $result = $this->{$action}($request);
     // Try to determine what response we are dealing with
     if ($result instanceof SS_HTTPResponse) {
         $this->response = $result;
     } else {
         $this->response = new SS_HTTPResponse();
         $this->response->setBody($result);
     }
     // If we had a redirection or something, halt processing.
     if ($this->response->isFinished()) {
         return $this->response;
     }
     ContentNegotiator::process($this->response);
     HTTP::add_cache_headers($this->response);
     return $this->response;
 }
 /**
  * Process all incoming requests passed to this controller, checking
  * that the file exists and passing the file through if possible.
  */
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     // Copied from Controller::handleRequest()
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->setDataModel($model);
     $url = array_key_exists('url', $_GET) ? $_GET['url'] : $_SERVER['REQUEST_URI'];
     // remove any relative base URL and prefixed slash that get appended to the file path
     // e.g. /mysite/assets/test.txt should become assets/test.txt to match the Filename field on File record
     $url = Director::makeRelative(ltrim(str_replace(BASE_URL, '', $url), '/'));
     $file = File::find($url);
     if ($this->canDownloadFile($file)) {
         // If we're trying to access a resampled image.
         if (preg_match('/_resampled\\/[^-]+-/', $url)) {
             // File::find() will always return the original image, but we still want to serve the resampled version.
             $file = new Image();
             $file->Filename = $url;
         }
         $this->extend('onBeforeSendFile', $file);
         return $this->sendFile($file);
     } else {
         if ($file instanceof File) {
             // Permission failure
             Security::permissionFailure($this, 'You are not authorised to access this resource. Please log in.');
         } else {
             // File doesn't exist
             $this->response = new SS_HTTPResponse('File Not Found', 404);
         }
     }
     return $this->response;
 }
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->setDataModel($model);
     $urlsegment = $request->param('URLSegment');
     $this->extend('onBeforeInit');
     $this->init();
     $this->extend('onAfterInit');
     // First check products against URL segment
     if ($product = Product::get()->filter(array('URLSegment' => $urlsegment, 'Disabled' => 0))->first()) {
         $controller = Catalogue_Controller::create($product);
     } elseif ($category = ProductCategory::get()->filter('URLSegment', $urlsegment)->first()) {
         $controller = Catalogue_Controller::create($category);
     } else {
         // If CMS is installed
         if (class_exists('ModelAsController')) {
             $controller = ModelAsController::create();
         }
     }
     $result = $controller->handleRequest($request, $model);
     $this->popCurrent();
     return $result;
 }
 /**
  * Action to add a product to cart.
  * 
  * @param SS_HTTPRequest $request Request to check for product data
  * 
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 12.03.2013
  */
 public function addToCart(SS_HTTPRequest $request)
 {
     $isValidRequest = false;
     $backLink = null;
     $postVars = $request->postVars();
     $params = $request->allParams();
     $productID = $params['ID'];
     $quantity = $params['OtherID'];
     if (is_null($productID) || is_null($quantity)) {
         if (array_key_exists('productID', $postVars) && array_key_exists('productQuantity', $postVars)) {
             $isValidRequest = true;
             $productID = $postVars['productID'];
             $quantity = $postVars['productQuantity'];
         }
     } else {
         $isValidRequest = true;
     }
     if ($isValidRequest) {
         $postVars['productID'] = $productID;
         $postVars['productQuantity'] = $quantity;
         if ($quantity == 0) {
             SilvercartShoppingCart::removeProduct($postVars);
         } else {
             SilvercartShoppingCart::addProduct($postVars);
         }
         if (SilvercartConfig::getRedirectToCartAfterAddToCartAction()) {
             $backLink = SilvercartTools::PageByIdentifierCodeLink('SilvercartCartPage');
         }
     }
     $this->redirectBack($backLink, '#product' . $productID);
 }
 /**
  * Due to a bug, this could be called twice before 4.0,
  * see https://github.com/silverstripe/silverstripe-framework/pull/5173
  *
  * @param SS_HTTPRequest $request
  * @param string $action
  */
 public function beforeCallActionHandler($request, $action)
 {
     // This could be called twice
     if ($this->owner->beforeCallActionHandlerCalled) {
         return;
     }
     // If we don't have an action, getViewer will be called immediatly
     // If we have custom routes, request action is different than action
     $allParams = $request->allParams();
     $requestAction = null;
     if (!empty($allParams['Action'])) {
         $requestAction = $allParams['Action'];
     }
     if (!$this->owner->hasMethod($action) || $requestAction && $requestAction != $action) {
         self::clearBuffer();
     }
     $class = get_class($this->owner);
     DebugBar::withDebugBar(function (DebugBar\DebugBar $debugbar) use($class, $action) {
         /* @var $timeData DebugBar\DataCollector\TimeDataCollector */
         $timeData = $debugbar['time'];
         if (!$timeData) {
             return;
         }
         if ($timeData->hasStartedMeasure("handle")) {
             $timeData->stopMeasure("handle");
         }
         $timeData->startMeasure("action", "{$class} action {$action}");
     });
     $this->owner->beforeCallActionHandlerCalled = true;
 }
 /**
  * Outputs the list of files, and the ID and edit dates of the Data Objects
  * @param SS_HTTPRequest $request checks the access code to make sure no
  * public spoofing
  */
 public function view(SS_HTTPRequest $request)
 {
     // close the session to allow concurrent requests
     session_write_close();
     // bump up the memory
     ini_set('memory_limit', '1024M');
     set_time_limit(0);
     $params = $request->allParams();
     // note the url format for the key code is domain.com/remoteassetsync/<keyhere>
     if (!isset($params['AccessKey'])) {
         throw new Exception('Access key not set. See Readme.md for instructions on how to set this in your yml file.');
     }
     $config = Config::inst()->forClass('RemoteAssetTask');
     if ($config->key != $params['AccessKey']) {
         throw new Exception('Key missmatch');
     }
     $myurl = Controller::join_links($config->target, 'remoteassetlist/', urlencode($config->key)) . '?m=' . time();
     // fetch the remote list of files to check
     try {
         $remotefiles = RemoteAssetTask::DownloadFile($myurl, 60000);
     } catch (Exception $e) {
         throw new SS_HTTPResponse_Exception(json_encode($e->getMessage()), 400);
     }
     // decode
     $remotejson = json_decode($remotefiles);
     // list local files
     $list = array();
     RemoteAssetListController::recurseDir('../assets', $list);
     // these are the files that are different from your list
     //$downloadlist = array_diff($remotejson, $list);
     //http://stackoverflow.com/questions/2985799/handling-large-arrays-with-array-diff
     $downloadlist = $this->leo_array_diff($remotejson, $list);
     // if you're ignoring a file, remove it from the download list
     $ignorelist = array();
     $downloadlistlen = strlen('../assets');
     foreach ($downloadlist as $key => $file) {
         foreach ($config->excludedfolders as $ignoredterm) {
             if (strpos($file, $ignoredterm) === $downloadlistlen) {
                 $ignorelist[] = $file;
                 unset($downloadlist[$key]);
             }
         }
     }
     echo '{"download":';
     print_r(json_encode(array_values($downloadlist)));
     echo ',"ignored":';
     print_r(count($ignorelist));
     echo ',"synced":';
     print_r(count($remotejson) - count($downloadlist));
     echo '}';
 }
 /**
  * On every URL that generates a 404, we'll capture it here and see if we can
  * find an old URL that it should be redirecting to.
  *
  * @param SS_HTTPRequest $request The request object
  * @throws SS_HTTPResponse_Exception
  */
 public function onBeforeHTTPError404($request)
 {
     // Build up the request parameters
     $params = array_filter(array_values($request->allParams()), function ($v) {
         return $v !== NULL;
     });
     $getvars = $request->getVars();
     unset($getvars['url']);
     $page = self::find_old_page($params);
     if ($page) {
         $res = new SS_HTTPResponse();
         $res->redirect(Controller::join_links($page, $getvars ? '?' . http_build_query($getvars) : null), 301);
         throw new SS_HTTPResponse_Exception($res);
     }
 }
 /**
  * Downloads a single file
  * @param SS_HTTPRequest $request checks the access code to make sure no
  * public spoofing
  */
 public function view(SS_HTTPRequest $request)
 {
     // close the session to allow concurrent requests
     session_write_close();
     // bump up the memory
     ini_set('memory_limit', '1024M');
     set_time_limit(0);
     $params = $request->allParams();
     // note the url format for the key code is domain.com/remoteassetsync/<keyhere>
     if (!isset($params['AccessKey'])) {
         throw new Exception('Access key not set. See Readme.md for instructions on how to set this in your yml file.');
     }
     $config = Config::inst()->forClass('RemoteAssetTask');
     if ($config->key != $params['AccessKey']) {
         throw new Exception('Key missmatch');
     }
     // download a file
     if (!$request->getVar('download')) {
         throw new Exception('Download file note set.');
     }
     $targetfile = preg_replace('/^\\.\\.\\//', '', $request->getVar('download'));
     $targetfileencoded = implode('/', array_map('rawurlencode', explode('/', $targetfile)));
     $myurl = Controller::join_links($config->target, $targetfileencoded);
     try {
         $filecontents = RemoteAssetTask::DownloadFile($myurl);
     } catch (Exception $e) {
         throw new SS_HTTPResponse_Exception($e->getMessage(), 400);
     }
     if (!$filecontents) {
         throw new SS_HTTPResponse_Exception('Failed to download.', 400);
     }
     // create new folder if none exists
     $dirname = dirname($request->getVar('download'));
     if (!is_dir($dirname)) {
         mkdir($dirname, 0777, true);
     }
     // remove old file before saving
     if (file_exists($request->getVar('download'))) {
         unlink($request->getVar('download'));
     }
     if (!file_put_contents($request->getVar('download'), $filecontents)) {
         throw new SS_HTTPResponse_Exception('Failed to write contents.', 400);
     }
     return json_encode('Success!');
 }
 /**
  * Handle the requests, checking the request file exists and is downloadable.
  * 
  * @param SS_HTTPRequest $request
  * @param DataModel $model
  * @return mixed null
  */
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     if (!$request) {
         user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
     }
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->setDataModel($model);
     $this->extend('onBeforeInit');
     // Init
     $this->baseInitCalled = false;
     $this->init();
     if (!$this->baseInitCalled) {
         user_error("init() method on class '{$this->class}' doesn't call Controller::init()." . "Make sure that you have parent::init() included.", E_USER_WARNING);
     }
     $this->extend('onAfterInit');
     $address = $this->getRequest()->getVars();
     if (empty($address['url'])) {
         return;
     }
     // make the $url normalised as "assets/somefolder/somefile.ext, so we could find the file record if it has.
     $url = Director::makeRelative(ltrim(str_replace(BASE_URL, '', $address['url']), '/'));
     $file = File::find($url);
     $exists = $file && file_exists($file->getFullPath());
     // F/S check added to File::exists() in SS v3.2.0
     if ($exists) {
         if ($this->canSendToBrowser($file)) {
             //when requesting a re-sampled image, $file is the original image, hence we need to reset the file path
             if (preg_match('/_resampled\\/[^-]+-/', $url)) {
                 $file = new Image();
                 $file->Filename = $url;
             }
             $this->sendFileToBrowser($file);
         } else {
             if ($file instanceof Image) {
                 $this->sendLockpadSamepleImageToBrowser($file);
             } else {
                 $this->treatFileAccordingToStatus($file);
             }
         }
     }
 }
 /**
  * Outputs the list of files, and the ID and edit dates of the Data Objects
  * @param SS_HTTPRequest $request checks the access code to make sure no
  * public spoofing
  */
 public function view(SS_HTTPRequest $request)
 {
     // close the session to allow concurrent requests
     session_write_close();
     // bump up the memory
     ini_set('memory_limit', '1024M');
     set_time_limit(0);
     $params = $request->allParams();
     // note the url format for the key code is domain.com/remoteassetsync/<keyhere>
     if (!isset($params['AccessKey'])) {
         throw new Exception('Access key not set. See Readme.md for instructions on how to set this in your yml file.');
     }
     $config = Config::inst()->forClass('RemoteAssetTask');
     if ($config->key != $params['AccessKey']) {
         throw new Exception('Key missmatch');
     }
     $list = array();
     RemoteAssetListController::recurseDir('../assets', $list);
     echo json_encode(array_values($list));
 }
 /**
  * @param SS_HTTPRequest $request
  */
 public function run($request)
 {
     $email = $request->remaining();
     $params = $request->allParams();
     $url = Director::absoluteURL("dev/{$params['Action']}/{$params['TaskName']}", true);
     echo '<h2>Choose Email</h2>';
     echo '<ul>';
     foreach ($this->previewableEmails as $key => $method) {
         echo '<li><a href="' . $url . '/' . $method . '">' . $method . '</a></li>';
     }
     echo '</ul><hr>';
     if ($email && in_array($email, $this->previewableEmails)) {
         $order = Order::get()->first();
         $notifier = OrderEmailNotifier::create($order)->setDebugMode(true);
         $method = "send{$email}";
         echo $notifier->{$method}();
     } else {
     }
     //this is a little hardcore way of ending the party,
     //but as it's only used for styling, it works for now
     die;
 }
 /**
  * We don't want Controller's handling of URLs, but we do need this to appear to go through the usual
  * startup procedure (push controller, call init, etc).
  *
  * So this is a duplication of Controller#handleRequest, except for the ending stanza
  */
 function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     if (!$request) {
         user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
     }
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->extend('onBeforeInit');
     // Init
     $this->baseInitCalled = false;
     $this->init();
     if (!$this->baseInitCalled) {
         user_error("init() method on class '{$this->class}' doesn't call Controller::init().  Make sure that you have parent::init() included.", E_USER_WARNING);
     }
     $this->extend('onAfterInit');
     // If we had a redirection or something, halt processing.
     if (!$this->response->isFinished()) {
         $this->response = $this->routeRequest($request);
     }
     $this->popCurrent();
     return $this->response;
 }
 public function tronsvids(SS_HTTPRequest $request)
 {
     print_r($request->allParams());
 }
 /**
  * Handles URL requests.
  *
  *  - ViewableData::handleRequest() iterates through each rule in {@link self::$url_handlers}.
  *  - If the rule matches, the named method will be called.
  *  - If there is still more URL to be processed, then handleRequest() 
  *    is called on the object that that method returns.
  *
  * Once all of the URL has been processed, the final result is returned.  
  * However, if the final result is an array, this
  * array is interpreted as being additional template data to customise the 
  * 2nd to last result with, rather than an object
  * in its own right.  This is most frequently used when a Controller's 
  * action will return an array of data with which to
  * customise the controller.
  * 
  * @param $request The {@link SS_HTTPRequest} object that is reponsible for distributing URL parsing
  * @uses SS_HTTPRequest
  * @uses SS_HTTPRequest->match()
  * @return SS_HTTPResponse|RequestHandler|string|array
  */
 function handleRequest(SS_HTTPRequest $request)
 {
     // $handlerClass is used to step up the class hierarchy to implement url_handlers inheritance
     $handlerClass = $this->class ? $this->class : get_class($this);
     if ($this->brokenOnConstruct) {
         user_error("parent::__construct() needs to be called on {$handlerClass}::__construct()", E_USER_WARNING);
     }
     $this->request = $request;
     // We stop after RequestHandler; in other words, at ViewableData
     while ($handlerClass && $handlerClass != 'ViewableData') {
         $urlHandlers = Object::get_static($handlerClass, 'url_handlers');
         if ($urlHandlers) {
             foreach ($urlHandlers as $rule => $action) {
                 if (isset($_REQUEST['debug_request'])) {
                     Debug::message("Testing '{$rule}' with '" . $request->remaining() . "' on {$this->class}");
                 }
                 if ($params = $request->match($rule, true)) {
                     // FIXME: This unnecessary coupling was added to fix a bug in Image_Uploader.
                     if ($this instanceof Controller) {
                         $this->urlParams = $request->allParams();
                     }
                     // Backwards compatible setting of url parameters, please use SS_HTTPRequest->latestParam() instead
                     //Director::setUrlParams($request->latestParams());
                     if (isset($_REQUEST['debug_request'])) {
                         Debug::message("Rule '{$rule}' matched to action '{$action}' on {$this->class}.  Latest request params: " . var_export($request->latestParams(), true));
                     }
                     // Actions can reference URL parameters, eg, '$Action/$ID/$OtherID' => '$Action',
                     if ($action[0] == '$') {
                         $action = $params[substr($action, 1)];
                     }
                     if ($this->checkAccessAction($action)) {
                         if (!$action) {
                             if (isset($_REQUEST['debug_request'])) {
                                 Debug::message("Action not set; using default action method name 'index'");
                             }
                             $action = "index";
                         } else {
                             if (!is_string($action)) {
                                 user_error("Non-string method name: " . var_export($action, true), E_USER_ERROR);
                             }
                         }
                         try {
                             $result = $this->{$action}($request);
                         } catch (SS_HTTPResponse_Exception $responseException) {
                             $result = $responseException->getResponse();
                         }
                     } else {
                         return $this->httpError(403, "Action '{$action}' isn't allowed on class {$this->class}");
                     }
                     if ($result instanceof SS_HTTPResponse && $result->isError()) {
                         if (isset($_REQUEST['debug_request'])) {
                             Debug::message("Rule resulted in HTTP error; breaking");
                         }
                         return $result;
                     }
                     // If we return a RequestHandler, call handleRequest() on that, even if there is no more URL to parse.
                     // It might have its own handler. However, we only do this if we haven't just parsed an empty rule ourselves,
                     // to prevent infinite loops. Also prevent further handling of controller actions which return themselves
                     // to avoid infinite loops.
                     if ($this !== $result && !$request->isEmptyPattern($rule) && is_object($result) && $result instanceof RequestHandler) {
                         $returnValue = $result->handleRequest($request);
                         // Array results can be used to handle
                         if (is_array($returnValue)) {
                             $returnValue = $this->customise($returnValue);
                         }
                         return $returnValue;
                         // If we return some other data, and all the URL is parsed, then return that
                     } else {
                         if ($request->allParsed()) {
                             return $result;
                             // But if we have more content on the URL and we don't know what to do with it, return an error.
                         } else {
                             return $this->httpError(404, "I can't handle sub-URLs of a {$this->class} object.");
                         }
                     }
                     return $this;
                 }
             }
         }
         $handlerClass = get_parent_class($handlerClass);
     }
     // If nothing matches, return this object
     return $this;
 }
 /**
  * Executes this controller, and return an {@link SS_HTTPResponse} object with the result.
  * 
  * This method first does a few set-up activities:
  *  - Push this controller ont to the controller stack - 
  *    see {@link Controller::curr()} for information about this.
  *  - Call {@link init()}
  *  - Defer to {@link RequestHandler->handleRequest()} to determine which action
  *    should be executed
  * 
  * Note: $requestParams['executeForm'] support was removed, 
  * make the following change in your URLs: 
  * "/?executeForm=FooBar" -> "/FooBar" 
  * Also make sure "FooBar" is in the $allowed_actions of your controller class.
  * 
  * Note: You should rarely need to overload run() - 
  * this kind of change is only really appropriate for things like nested
  * controllers - {@link ModelAsController} and {@link RootURLController} 
  * are two examples here.  If you want to make more
  * orthodox functionality, it's better to overload {@link init()} or {@link index()}.
  * 
  * Important: If you are going to overload handleRequest, 
  * make sure that you start the method with $this->pushCurrent()
  * and end the method with $this->popCurrent().  
  * Failure to do this will create weird session errors.
  * 
  * @param $request The {@link SS_HTTPRequest} object that is responsible 
  *  for distributing request parsing.
  * @return SS_HTTPResponse The response that this controller produces, 
  *  including HTTP headers such as redirection info
  */
 function handleRequest(SS_HTTPRequest $request)
 {
     if (!$request) {
         user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
     }
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->extend('onBeforeInit');
     // Init
     $this->baseInitCalled = false;
     $this->init();
     if (!$this->baseInitCalled) {
         user_error("init() method on class '{$this->class}' doesn't call Controller::init().  Make sure that you have parent::init() included.", E_USER_WARNING);
     }
     $this->extend('onAfterInit');
     // If we had a redirection or something, halt processing.
     if ($this->response->isFinished()) {
         $this->popCurrent();
         return $this->response;
     }
     $body = parent::handleRequest($request);
     if ($body instanceof SS_HTTPResponse) {
         if (isset($_REQUEST['debug_request'])) {
             Debug::message("Request handler returned SS_HTTPResponse object to {$this->class} controller; returning it without modification.");
         }
         $this->response = $body;
     } else {
         if (is_object($body)) {
             if (isset($_REQUEST['debug_request'])) {
                 Debug::message("Request handler {$body->class} object to {$this->class} controller;, rendering with template returned by {$body->class}::getViewer()");
             }
             $body = $body->getViewer($request->latestParam('Action'))->process($body);
         }
         $this->response->setBody($body);
     }
     ContentNegotiator::process($this->response);
     HTTP::add_cache_headers($this->response);
     $this->popCurrent();
     return $this->response;
 }
 /**
  * Show a report based on the URL query string.
  *
  * @param SS_HTTPRequest $request The HTTP request object
  */
 public function show($request)
 {
     $params = $request->allParams();
     return $this->showWithEditForm($params, $this->reportEditFormFor($params['ID']));
 }
 /**
  * Action to show a product detail page.
  * Returns the rendered detail page.
  * 
  * @param SS_HTTPRequest $request Request
  * 
  * @return string
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 03.07.2013
  */
 public function detail(SS_HTTPRequest $request)
 {
     $params = $request->allParams();
     $productID = $params['ID'];
     $product = SilvercartProduct::get()->byID($productID);
     $productLink = $product->Link();
     $calledLink = $request->getURL();
     if (strpos($calledLink, '/') != strpos($productLink, '/')) {
         if (strpos($productLink, '/') == 0) {
             $calledLink = '/' . $calledLink;
         } elseif (strpos($calledLink, '/') == 0) {
             $productLink = '/' . $productLink;
         }
     }
     if ($calledLink != $productLink) {
         SilvercartTools::redirectPermanentlyTo($productLink);
     }
     $this->setProduct($product);
     return $this->render();
 }
 /**
  * Fills the contact form with a predefined product question text and renders the template
  *
  * @param SS_HTTPRequest $request HTTP request
  * 
  * @return string
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 31.05.2012
  */
 public function productQuestion(SS_HTTPRequest $request)
 {
     $params = $request->allParams();
     if (!empty($params['ID']) && is_numeric($params['ID'])) {
         $product = DataObject::get_by_id('SilvercartProduct', $params['ID']);
         if ($product) {
             $silvercartContactForm = $this->getRegisteredCustomHtmlForm('SilvercartContactForm');
             $silvercartContactForm->setFormFieldValue('Message', sprintf(_t('SilvercartProduct.PRODUCT_QUESTION'), $product->Title, $product->ProductNumberShop));
         }
     }
     return $this->render();
 }
 /**
  * Renders a form to add addresses and handles it's sumbit event.
  *
  * @param SS_HTTPRequest $request the given request
  * 
  * @return type 
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 02.11.2016
  */
 public function addNewAddress(SS_HTTPRequest $request)
 {
     $params = $request->allParams();
     if (strtolower($params['ID']) == 'customhtmlformsubmit') {
         $this->CustomHtmlFormSubmit($request);
         $form = $this->getRegisteredCustomHtmlForm('SilvercartAddAddressForm');
         if ($form->submitSuccess) {
             $form->addMessage(_t('SilvercartAddressHolder.ADDED_ADDRESS_SUCCESS', 'Your address was successfully saved.'));
         } else {
             $form->addMessage(_t('SilvercartAddressHolder.ADDED_ADDRESS_FAILURE', 'Your address could not be saved.'));
         }
     }
     return $this->render();
 }
 /**
  * Search for a movie
  * Uses OMDb API to search for a movie, and returns a JSON response with a selection of
  * titles that match the search term.
  *
  * @param SS_HTTPRequest $request The request object
  * @return SS_HTTPResponse A json object containing search results
  */
 public function getmovies(SS_HTTPRequest $request)
 {
     $search = $request->allParams()['ID'];
     $api = new RestfulService('http://www.omdbapi.com/');
     $api->setQueryString(array('r' => 'xml', 'type' => 'movie', 's' => $search, 'v' => 1));
     $results = $api->request();
     $results = $api->getAttributes($results->getBody(), 'Movie');
     $titles = array();
     if ($results) {
         foreach ($results as $result) {
             $titles[] = $result->getField('Title');
         }
     }
     $response = array('search' => $search, 'results' => $titles);
     $this->response->setBody(json_encode($response));
     $this->response->addHeader('Content-type', 'application/json');
     return $this->response;
 }
 /**
  * @param SS_HTTPRequest $request
  * @return array
  */
 private function processRequestParameters(SS_HTTPRequest $request)
 {
     $params = array();
     if ($request != null) {
         $params = $request->allParams();
         $variables = $request->getVars();
         $params['startPosition'] = $params['ID'];
         if ($params['startPosition'] < 1) {
             $params['startPosition'] = 1;
         }
         if (isset($variables['searchTerm'])) {
             $params['searchTerm'] = $variables['searchTerm'];
         }
         if ($params['OtherID']) {
             $params['searchTerm'] = $params['OtherID'];
         }
     }
     return $params;
 }
 public function DeploymentDetails(SS_HTTPRequest $request)
 {
     $params = $request->allParams();
     $deployment_id = intval(Convert::raw2sql($params["ID"]));
     //get survey version
     $deployment = Survey::get()->byID($deployment_id);
     if ($deployment->ClassName === 'EntitySurvey') {
         $deployment = EntitySurvey::get()->byID($deployment_id);
     }
     if (!$deployment) {
         return $this->owner->httpError(404, 'Sorry that Deployment could not be found!.');
     }
     $back_url = $request->getVar('BackUrl');
     if (empty($back_url)) {
         $back_url = $this->owner->Link("ViewDeploymentDetails");
     }
     $data = ["Name" => 'Deployment', "Survey" => $deployment, "BackUrl" => $back_url];
     return $this->owner->Customise($data)->renderWith(array('SangriaPage_SurveyBuilderSurveyDetails', 'SangriaPage', 'SangriaPage'));
 }