public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
 {
     // Bootstrap session so that Session::get() accesses the right instance
     $dummyController = new Controller();
     $dummyController->setSession($session);
     $dummyController->setRequest($request);
     $dummyController->pushCurrent();
     // Block non-authenticated users from setting the stage mode
     if (!Versioned::can_choose_site_stage($request)) {
         $permissionMessage = sprintf(_t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. ' . '<a href="%s">Click here to go back to the published site.</a>'), Controller::join_links(Director::baseURL(), $request->getURL(), "?stage=Live"));
         // Force output since RequestFilter::preRequest doesn't support response overriding
         $response = Security::permissionFailure($dummyController, $permissionMessage);
         $session->inst_save();
         $dummyController->popCurrent();
         // Prevent output in testing
         if (class_exists('SapphireTest', false) && SapphireTest::is_running_test()) {
             throw new SS_HTTPResponse_Exception($response);
         }
         $response->output();
         die;
     }
     Versioned::choose_site_stage();
     $dummyController->popCurrent();
     return true;
 }
 public function run($request)
 {
     $strCSVPath = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/IP2LOCATION-DB.CSV';
     if (!file_exists($strCSVPath)) {
         echo "<p>I cant find the IP2LOCATION-DB.CSV file to import any data.<br>\n\t\t\t\tPlease download DB3.LITE database from <a href='http://lite.ip2location.com/'>http://lite.ip2location.com/</a>.<br>\n\t\t\t\tNOTE: It's adviced to edit the DB to only include the countries you want to handle, it contains 2 million records!!!<br>\n\t\t\t\tOr make a CSV contain these columns<br>\n\t\t\t\t`IPFrom`,`IPTo`,`Country`,`CountryName`,`Region`,`City`\n\t\t\t\t</p>";
     } else {
         if (!isset($_REQUEST['confirm'])) {
             $strLink = Director::baseURL() . 'dev/tasks/ImportIPToLocationTask?confirm=1';
             echo "<p>CAUTION!!!<br>\n\t\t\t\t\tPlease confirm your action<br>\n\t\t\t\t\t<a href='{$strLink}'>I confirm the action</a><br>\n\t\t\t\t\t<a href='{$strLink}&emptydb=1'>I confirm the action, please empty the DB before you import</a>\n\t\t\t\t\t</p>";
         } else {
             increase_time_limit_to();
             if (isset($_REQUEST['emptydb'])) {
                 DB::query('TRUNCATE `IpToLocation`;');
             }
             $arrFields = array_keys(Config::inst()->get('IpToLocation', 'db'));
             $handle = fopen($strCSVPath, "r");
             if ($handle) {
                 while (($line = fgets($handle)) !== false) {
                     $line = str_replace('","', '___', $line);
                     $line = str_replace('"', '', $line);
                     $arrParts = Convert::raw2sql(explode("___", $line));
                     unset($arrParts[3]);
                     DB::query('INSERT INTO `IpToLocation` (`' . implode('`,`', $arrFields) . '`) VALUES (\'' . implode('\',\'', $arrParts) . '\')');
                 }
                 fclose($handle);
             } else {
                 echo 'Error opening file';
             }
         }
     }
 }
 public static function cleanBackUrl($back_url)
 {
     if (empty($back_url) || !empty($back_url) && !Director::is_site_url($back_url)) {
         $back_url = Director::baseURL();
     }
     return $back_url;
 }
	function index() {
		$tasks = $this->getTasks();

		// Web mode
		if(!Director::is_cli()) {
			$renderer = new DebugView();
			$renderer->writeHeader();
			$renderer->writeInfo("Sapphire Development Tools: Tasks", Director::absoluteBaseURL());
			$base = Director::baseURL();
			if(strpos($base,-1) != '/') $base .= '/';
			
			echo "<ul>";
			foreach($tasks as $task) {
				echo "<li>";
				echo "<a href=\"{$base}dev/tasks/" . $task['class'] . "\">" . $task['title'] . "</a><br />";
				echo "<span class=\"description\">" . $task['description'] . "</span>";
				echo "</li>\n";
			}
			echo "</ul>";

			$renderer->writeFooter();
		// CLI mode
		} else {
			echo "SAPPHIRE DEVELOPMENT TOOLS: Tasks\n--------------------------\n\n";
			foreach($tasks as $task) {
				echo " * $task: sake dev/tasks/" . $task['class'] . "\n";
			}
		}
	}
Exemple #5
0
 public function getContinueLink()
 {
     if ($maincategory = DataObject::get_one('ProductCategory', "", true, "ParentID ASC, ID ASC")) {
         return $maincategory->Link();
     }
     return Director::baseURL();
 }
 function index()
 {
     $actions = array("build" => "Build/rebuild this environment (formerly db/build).  Call this whenever you have updated your project sources", "reset" => "Reset this environment - truncate the database and rebuild.  This is useful after testing to start with a fresh working copy", "tests" => "See a list of unit tests to run", "tests/all" => "Run all tests", "jstests" => "See a list of JavaScript tests to run", "jstests/all" => "Run all JavaScript tests", "modules/add" => "Add a module, for example, 'sake dev/modules/add ecommerce'", "tasks" => "See a list of build tasks to run", "viewcode" => "Read source code in a literate programming style");
     // Web mode
     if (!Director::is_cli()) {
         // This action is sake-only right now.
         unset($actions["modules/add"]);
         $renderer = new DebugView();
         $renderer->writeHeader();
         $renderer->writeInfo("Sapphire Development Tools", Director::absoluteBaseURL());
         $base = Director::baseURL();
         echo '<div class="options"><ul>';
         foreach ($actions as $action => $description) {
             echo "<li><a href=\"{$base}dev/{$action}\"><b>/dev/{$action}:</b> {$description}</a></li>\n";
         }
         $renderer->writeFooter();
         // CLI mode
     } else {
         echo "SAPPHIRE DEVELOPMENT TOOLS\n--------------------------\n\n";
         echo "You can execute any of the following commands:\n\n";
         foreach ($actions as $action => $description) {
             echo "  sake dev/{$action}: {$description}\n";
         }
         echo "\n\n";
     }
 }
 /**
  * Ajax call from browser
  * @param SS_HTTPRequest $request sent by browser
  * @return string json response to send to back to the browser
  */
 public function analyse(SS_HTTPRequest $request)
 {
     // Set the tenon options
     $tenon_options = $this->buildOptions($request);
     // Origin check
     if (strpos($request->postVar('tURL'), Director::absoluteURL(Director::baseURL())) === 0) {
         // Only proceed if the key is set
         if (strlen(trim($tenon_options["key"])) > 28 && ctype_xdigit(trim($tenon_options["key"]))) {
             // Store the page and create a hash of its contents
             $this->tenon_page = $request->postVar('tURL');
             $this->tenon_hash = $this->createHash($request);
             $this->log("TenonAjax.requestTenon", "url=" . $this->tenon_url . ", options=" . print_r($tenon_options, true));
             // If the page/hash combination has not already been checked, do it now
             if (!$this->existingPageHash()) {
                 if ($this->requestSend($tenon_options) && $this->responseSave() && $this->savePageHash()) {
                     $out = $this->jsonResponse(true);
                     $this->log("TenonAjax.analyse", "out={$out}");
                     return $out;
                 }
             }
         }
     } else {
         $this->log('Invalid request received by ' . Director::absoluteURL(Director::baseURL()) . ' from ' . $request->postVar('tURL'));
     }
     return $this->jsonResponse(false);
 }
 function Link($action = null)
 {
     if ($this->customLink) {
         return Director::baseURL() . 'ObjectSelectorField_Controller/find/?sourceObject=' . $this->sourceObject . '&displayField=' . $this->getDisplayFieldOptions() . '&multi=' . $this->hasMultiSortOptions();
     }
     return parent::Link($action);
 }
 function submitPoll($data, $form)
 {
     $choiceIDs = is_array($data['PollChoices']) ? $data['PollChoices'] : array($data['PollChoices']);
     $choicesIDs = implode(',', $choiceIDs);
     $choices = DataObject::get('PollChoice', sprintf('"ID" IN (%s)', $choicesIDs));
     if ($choices) {
         foreach ($choices as $choice) {
             $choice->addVote();
         }
         $form->poll->markAsVoted();
     }
     // Redirect back to anchor (partly copied from Director::redirectBack)
     if (self::$redirect_to_anchor) {
         if ($this->request->requestVar('_REDIRECT_BACK_URL')) {
             $url = $this->request->requestVar('_REDIRECT_BACK_URL');
         } else {
             if ($this->request->getHeader('Referer')) {
                 $url = $this->request->getHeader('Referer');
             } else {
                 $url = Director::baseURL();
             }
         }
         $url .= '#' . self::$redirect_to_anchor . '-' . $this->poll->ID;
         $this->controller->redirect($url);
     } else {
         $this->controller->redirectBack();
     }
 }
 function index()
 {
     $actions = array("build" => "Build/rebuild this environment.  Call this whenever you have updated your project sources", "buildcache" => "Rebuild the static cache, if you're using StaticPublisher", "tests" => "See a list of unit tests to run", "tests/all" => "Run all tests", "tests/startsession" => "Start a test session in your browser (gives you a temporary database with default content)", "tests/endsession" => "Ends a test session", "jstests" => "See a list of JavaScript tests to run", "jstests/all" => "Run all JavaScript tests", "tasks" => "See a list of build tasks to run");
     // Web mode
     if (!Director::is_cli()) {
         // This action is sake-only right now.
         unset($actions["modules/add"]);
         $renderer = DebugView::create();
         $renderer->writeHeader();
         $renderer->writeInfo("SilverStripe Development Tools", Director::absoluteBaseURL());
         $base = Director::baseURL();
         echo '<div class="options"><ul>';
         $evenOdd = "odd";
         foreach ($actions as $action => $description) {
             echo "<li class=\"{$evenOdd}\"><a href=\"{$base}dev/{$action}\"><b>/dev/{$action}:</b> {$description}</a></li>\n";
             $evenOdd = $evenOdd == "odd" ? "even" : "odd";
         }
         $renderer->writeFooter();
         // CLI mode
     } else {
         echo "SILVERSTRIPE DEVELOPMENT TOOLS\n--------------------------\n\n";
         echo "You can execute any of the following commands:\n\n";
         foreach ($actions as $action => $description) {
             echo "  sake dev/{$action}: {$description}\n";
         }
         echo "\n\n";
     }
 }
 public static function getSmileyDir()
 {
     $smileyDir = Director::makeRelative(realpath(dirname(__FILE__) . "/../images/smileys/"));
     $smileyDir = str_replace("\\", "/", $smileyDir);
     $smileyDir = Director::baseURL() . $smileyDir;
     return $smileyDir;
 }
 public function index()
 {
     // Web mode
     if (!Director::is_cli()) {
         $renderer = DebugView::create();
         $renderer->writeHeader();
         $renderer->writeInfo("SilverStripe Development Tools", Director::absoluteBaseURL());
         $base = Director::baseURL();
         echo '<div class="options"><ul>';
         $evenOdd = "odd";
         foreach (self::get_links() as $action => $description) {
             echo "<li class=\"{$evenOdd}\"><a href=\"{$base}dev/{$action}\"><b>/dev/{$action}:</b>" . " {$description}</a></li>\n";
             $evenOdd = $evenOdd == "odd" ? "even" : "odd";
         }
         $renderer->writeFooter();
         // CLI mode
     } else {
         echo "SILVERSTRIPE DEVELOPMENT TOOLS\n--------------------------\n\n";
         echo "You can execute any of the following commands:\n\n";
         foreach (self::get_links() as $action => $description) {
             echo "  sake dev/{$action}: {$description}\n";
         }
         echo "\n\n";
     }
 }
 public function getProfileLink($action = null)
 {
     if ($directorypage = MembersDirectoryPage::get()->first()) {
         return Controller::join_links($directorypage->Link(), "view", $this->owner->ID, $action);
     }
     return Director::baseURL() . MemberProfilePage_Controller::config()->url_segment;
 }
 /**
  * Finds the path for specified file.
  *
  * @param string $fileOrUrl
  * @return string|boolean
  */
 protected static function path_for_file($fileOrUrl)
 {
     if (preg_match('{^//|http[s]?}', $fileOrUrl)) {
         return $fileOrUrl;
     } elseif (Director::fileExists($fileOrUrl)) {
         $filePath = preg_replace('/\\?.*/', '', Director::baseFolder() . '/' . $fileOrUrl);
         $prefix = Director::baseURL();
         $mtimesuffix = "";
         $suffix = '';
         if (Requirements::get_suffix_requirements()) {
             $mtimesuffix = "?m=" . filemtime($filePath);
             $suffix = '&';
         }
         if (strpos($fileOrUrl, '?') !== false) {
             if (strlen($suffix) == 0) {
                 $suffix = '?';
             }
             $suffix .= substr($fileOrUrl, strpos($fileOrUrl, '?') + 1);
             $fileOrUrl = substr($fileOrUrl, 0, strpos($fileOrUrl, '?'));
         } else {
             $suffix = '';
         }
         return "{$prefix}{$fileOrUrl}{$mtimesuffix}{$suffix}";
     } else {
         return false;
     }
 }
    /**
     * returns a link for sorting objects. You can use this in the CMS like this....
     * <code>
     * if(class_exists("DataObjectSorterController")) {
     * 	$fields->addFieldToTab("Root.Position", new LiteralField("AdvertisementsSorter", DataObjectSorterController::popup_link("Advertisement", $filterField = "", $filterValue = "", $linkText = "sort ".Advertisement::$plural_name, $titleField = "FullTitle")));
     * }
     * else {
     * 	$fields->addFieldToTab("Root.Position", new NumericField($name = "Sort", "Sort index number (the lower the number, the earlier it shows up"));
     * }
     * </code>
     *
     * @param String $className - DataObject Class Name you want to sort
     * @param String | Int $filterField - Field you want to filter for OR ParentID number (i.e. you are sorting children of Parent with ID = $filterField)
     * @param String $filterValue - filter field should be equal to this integer OR string. You can provide a list of IDs like this: 1,2,3,4 where the filterFiel is probably equal to ID or MyRelationID
     * @param String $linkText - text to show on the link
     * @param String $titleField - field to show in the sort list. This defaults to the DataObject method "getTitle", but you can use "name" or something like that.
     * @return String
     */
    public static function popup_link($className, $filterField = "", $filterValue = "", $linkText = "sort this list", $titleField = "")
    {
        Requirements::javascript("dataobjectsorter/javascript/jquery.simplemodal-1.4.4.js");
        Requirements::javascript("dataobjectsorter/javascript/dataobjectmodalpopup.js");
        Requirements::themedCSS("dataobjectmodalpopup", "dataobjectsorter");
        $where = "";
        if ($filterField) {
            $singletonObj = singleton($className);
            if ($singletonObj->hasDatabaseField($filterField)) {
                $where = "\"{$filterField}\" = '{$filterValue}'";
            }
        }
        $objects = $className::get();
        if ($where) {
            $objects = $objects->where($where);
        }
        $obj = $objects->first();
        if ($obj && $obj->canEdit()) {
            $link = 'dataobjectsorter/sort/' . $className . "/";
            if ($filterField) {
                $link .= $filterField . '/';
            }
            if ($filterValue) {
                $link .= $filterValue . '/';
            }
            if ($titleField) {
                $link .= $titleField . '/';
            }
            $link = Director::baseURL() . $link;
            return '
			<a href="' . $link . '" class="modalPopUp" data-width="800" data-height="600" data-rel="window.open(\'' . $link . '\', \'sortlistFor' . $className . $filterField . $filterValue . '\',\'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=600,left = 440,top = 200\'); return false;">' . $linkText . '</a>';
        }
    }
 public function run($request)
 {
     $strCSVPath = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/dbip-city.csv';
     if (!file_exists($strCSVPath)) {
         echo "<p>I cant find the dbip-city.csv file to import any data.<br>\n\t\t\t\tPlease download any database from <a href='https://db-ip.com/db/'>https://db-ip.com/db/</a>.<br>\n\t\t\t\tNOTE: It's adviced to edit the DB to only include the countries you want to handle, it contains 2 million records!!!<br>\n\t\t\t\tOr make a CSV contain these columns<br>\n\t\t\t\t`IPFrom`,`IPTo`,`Country`,`Region`,`City`\n\t\t\t\t</p>";
         //"0.0.0.0","0.255.255.255","US","California","Los Angeles"
     } else {
         if (!isset($_REQUEST['confirm'])) {
             $strLink = Director::baseURL() . 'dev/tasks/ImportDBIPcom?confirm=1';
             echo "<p>CAUTION!!!<br>\n\t\t\t\t\tPlease confirm your action<br>\n\t\t\t\t\t<a href='{$strLink}'>I confirm the action</a><br>\n\t\t\t\t\t<a href='{$strLink}&emptydb=1'>I confirm the action, please empty the DB before you import</a>\n\t\t\t\t\t</p>";
         } else {
             increase_time_limit_to();
             if (isset($_REQUEST['emptydb'])) {
                 DB::query('TRUNCATE `IpToLocation`;');
             }
             $arrFields = array_keys(Config::inst()->get('IpToLocation', 'db'));
             $handle = fopen($strCSVPath, "r");
             if ($handle) {
                 while (($line = fgets($handle)) !== false) {
                     $line = str_replace('","', '___', $line);
                     $line = str_replace('"', '', $line);
                     $arrParts = Convert::raw2sql(explode("___", $line));
                     $arrParts[0] = ContinentalContentUtils::IPAddressToIPNumber($arrParts[0]);
                     $arrParts[1] = ContinentalContentUtils::IPAddressToIPNumber($arrParts[1]);
                     DB::query('INSERT INTO `IpToLocation` (`' . implode('`,`', $arrFields) . '`) VALUES (\'' . implode('\',\'', $arrParts) . '\')');
                 }
                 fclose($handle);
             } else {
                 echo 'Error opening file';
             }
         }
     }
 }
 /**
  * Form action handler for ContactInquiryForm.
  *
  * @param array $data The form request data submitted
  * @param Form $form The {@link Form} this was submitted on
  */
 function dosave(array $data, Form $form, SS_HTTPRequest $request)
 {
     $SQLData = Convert::raw2sql($data);
     $attrs = $form->getAttributes();
     if ($SQLData['Comment'] != '' || $SQLData['Url'] != '') {
         // most probably spam - terminate silently
         Director::redirect(Director::baseURL() . $this->URLSegment . "/success");
         return;
     }
     $item = new ContactInquiry();
     $form->saveInto($item);
     // $form->sessionMessage(_t("ContactPage.FORMMESSAGEGOOD", "Your inquiry has been submitted. Thanks!"), 'good');
     $item->write();
     $mailFrom = $this->currController->MailFrom ? $this->currController->MailFrom : $SQLData['Email'];
     $mailTo = $this->currController->MailTo ? $this->currController->MailTo : Email::getAdminEmail();
     $mailSubject = $this->currController->MailSubject ? $this->currController->MailSubject . ' - ' . $SQLData['Ref'] : _t('ContactPage.SUBJECT', '[web] New contact inquiry - ') . ' ' . $data['Ref'];
     $email = new Email($mailFrom, $mailTo, $mailSubject);
     $email->replyTo($SQLData['Email']);
     $email->setTemplate("ContactInquiry");
     $email->populateTemplate($SQLData);
     $email->send();
     // $this->controller->redirectBack();
     if ($email->send()) {
         $this->controller->redirect($this->controller->Link() . "success");
     } else {
         $this->controller->redirect($this->controller->Link() . "error");
     }
     return false;
 }
    function __construct()
    {
        $this->subject = _t('Member.EMAILSIGNUPSUBJECT', "Your business has been created at " . Director::baseURL());
        $this->body = '
			<h2>' . _t('Member.GREETING', 'Welcome to ' . Director::baseURL()) . ', $FirstName.</h2>
			<p>' . _t('Member.EMAILSIGNUPINTRO1', 'Your business has been created at ' . Director::baseURL() . '. Your login details are listed below for future reference.') . '</p>

			<p>' . _t('Member.EMAILSIGNUPINTRO2', 'You can login to the website using the credentials listed below') . ':
				<ul>
					<li><strong>' . _t('Member.EMAIL') . ':</strong> $Email</li>
					<li><strong>' . _t('Member.PASSWORD') . ':</strong> $Password</li>
				</ul>
			</p>

			<h3>' . _t('Member.CONTACTINFO', 'Contact Information') . '</h3>
			<ul>
				<li><strong>' . _t('Member.NAME', 'Name') . ':</strong> $FirstName $Surname</li>
				<% if Phone %>
					<li><strong>' . _t('Member.PHONE', 'Phone') . ':</strong> $Phone</li>
				<% end_if %>

				<% if Mobile %>
					<li><strong>' . _t('Member.MOBILE', 'Mobile') . ':</strong> $Mobile</li>
				<% end_if %>

			</ul>
		';
    }
 public function testFindLink()
 {
     $this->checkoutpage = $this->objFromFixture('CheckoutPage', 'checkout');
     $this->checkoutpage->publish('Stage', 'Live');
     $link = CheckoutPage::find_link();
     $this->assertEquals(Director::baseURL() . 'checkout/', $link, 'find_link() returns the correct link to checkout.');
 }
 public function getContinueLink()
 {
     $maincategory = ProductCategory::get()->sort(array("ParentID" => "ASC", "ID" => "ASC"))->first();
     if ($maincategory) {
         return $maincategory->Link();
     }
     return Director::baseURL();
 }
 public function customJQueryScripts($html = '')
 {
     $html .= 'var baseURL = "' . Director::baseURL() . '";';
     $html .= 'var linkURL = "' . $this->Link() . '";';
     $html .= 'var directivesURL = "' . DIRECTIVES_PATH . '";';
     $html .= 'var ThemeDir = "' . $this->ThemeDir() . '";';
     Requirements::customScript($html);
 }
 /**
  *
  * @param GridField $gridField
  * @param DataObject $record
  * @param string $columnName
  * @return string - the HTML for the column 
  */
 public function getColumnContent($gridField, $record, $columnName)
 {
     if (!$record->canEdit()) {
         return;
     }
     $data = new ArrayData(array('Link' => Controller::join_links(Director::baseURL(), '/admin/pages/edit/show/', $record->ID)));
     return $data->renderWith('GridFieldEditButton');
 }
 /**
  * @param String $action
  * @return String (Link)
  */
 function Link($action = null)
 {
     $URLSegment = Config::inst()->get($this->class, "url_segment");
     if (!$URLSegment) {
         $URLSegment = $this->class;
     }
     return Controller::join_links(Director::baseURL(), $URLSegment, $action);
 }
Exemple #24
0
 public function setBounceHandlerURL($bounceHandlerURL)
 {
     if ($bounceHandlerURL) {
         $this->bounceHandlerURL = $bounceHandlerURL;
     } else {
         $this->bounceHandlerURL = $_SERVER['HTTP_HOST'] . Director::baseURL() . 'Email_BounceHandler';
     }
 }
 public function go()
 {
     $ad = $this->GetAdAndLogClick($this->request->param('ID'));
     if ($ad) {
         $target = $ad->getTarget();
         $this->redirect($target ? $target : Director::baseURL());
     }
 }
 public function Link($slug = null)
 {
     if ($slug) {
         return Controller::join_links(Director::baseURL(), 'land', $slug);
     } else {
         return Controller::join_links(Director::baseURL(), 'land');
     }
 }
Exemple #27
0
 /**
  * Set a cookie variable
  * @param name The variable name
  * @param value The variable value.  May be an array or object if you wish.
  * @param expiryDays The expiry time, in days.  Defaults to 90.
  */
 static function set($name, $value, $expiryDays = 90)
 {
     if (!headers_sent($file, $line)) {
         setcookie($name, $value, time() + 86400 * $expiryDays, Director::baseURL());
         $_COOKIE[$name] = $value;
     } else {
         // if(Director::isDevMode()) user_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING);
     }
 }
 public function run($request)
 {
     $strLocationCSV = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/GeoLiteCity-Location.csv';
     $strIPCSV = CONTINENTAL_CONTENT_PATH . '/code/ThirdParty/GeoLiteCity-Blocks.csv';
     if (!file_exists($strLocationCSV) || !file_exists($strIPCSV)) {
         echo "<p>I cant find the GeoLiteCity-Location.csv or GeoLiteCity-Blocks.csv file to import any data.<br>\n\t\t\t\tPlease download the database from <a href='http://dev.maxmind.com/geoip/legacy/geolite/'>http://dev.maxmind.com/geoip/legacy/geolite/</a>.<br>\n\t\t\t\tNOTE: It's adviced to edit the DB to only include the countries you want to handle, it contains 2 million records!!!<br>\n\t\t\t\t</p>";
     } else {
         if (!isset($_REQUEST['confirm'])) {
             $strLink = Director::baseURL() . 'dev/tasks/ImportMaxMindToDatabase?confirm=1';
             echo "<p>CAUTION!!!<br>\n\t\t\t\t\tPlease confirm your action<br>\n\t\t\t\t\t<a href='{$strLink}'>I confirm the action</a><br>\n\t\t\t\t\t<a href='{$strLink}&emptydb=1'>I confirm the action, please empty the DB before you import</a>\n\t\t\t\t\t</p>";
         } else {
             $arrFields = array_keys(Config::inst()->get('IpToLocation', 'db'));
             increase_time_limit_to();
             if (isset($_REQUEST['emptydb'])) {
                 DB::query('TRUNCATE `IpToLocation`;');
             }
             $arrLocations = array();
             $handle = fopen($strLocationCSV, "r");
             if ($handle) {
                 $i = 0;
                 while (($line = fgets($handle)) !== false) {
                     $i += 1;
                     if ($i > 3) {
                         $line = str_replace('","', '**', $line);
                         $line = str_replace(',', '**', $line);
                         $line = str_replace('"', '', $line);
                         $arrParts = Convert::raw2sql(explode("**", $line));
                         $arrLocations[$arrParts[0]] = array('Country' => $arrParts[1], 'Region' => $arrParts[2], 'City' => $arrParts[3]);
                     }
                 }
                 fclose($handle);
             } else {
                 echo 'Error opening file';
             }
             $ipHandle = fopen($strIPCSV, "r");
             if ($ipHandle) {
                 $i = 0;
                 while (($line = fgets($ipHandle)) !== false) {
                     $i += 1;
                     if ($i > 3) {
                         $line = str_replace("\n", "", $line);
                         $line = str_replace('","', '___', $line);
                         $line = str_replace('"', '', $line);
                         $arrParts = Convert::raw2sql(explode("___", $line));
                         if (count($arrParts) == 3 && isset($arrLocations[$arrParts[2]])) {
                             $strSQL = 'INSERT INTO `IpToLocation` (`' . implode('`,`', $arrFields) . '`) VALUES (\'' . implode('\',\'', array_merge(array('IPFrom' => $arrParts[0], 'IPTo' => $arrParts[1]), $arrLocations[$arrParts[2]])) . '\')';
                             DB::query($strSQL);
                         }
                     }
                 }
             } else {
                 echo 'Error opening file';
             }
         }
     }
 }
    public function getColumnContent($gridField, $record, $columnName)
    {
        Requirements::css(POSTMARK_RELATIVE_PATH . '/css/GridFieldCustomerReadEmailsButton.css');
        $link = Director::baseURL() . 'admin/messages?q[Search]=' . $record->Email;
        $text = _t('CRMAdmin.ReadEmails', 'Read Emails');
        return <<<HTML
<a class="action action-detail read-more-link icon-open_in_new" href="{$link}" title="{$text}"></a>

HTML;
    }
 public function updateCMSFields(FieldList $fields)
 {
     parent::updateCMSFields($fields);
     // Fix URLSegment field issue for root pages
     if (!SiteTree::config()->nested_urls || empty($this->owner->ParentID)) {
         $baseLink = Director::absoluteURL(Controller::join_links(Director::baseURL(), Fluent::alias(Fluent::current_locale()), '/'));
         $urlsegment = $fields->dataFieldByName('URLSegment');
         $urlsegment->setURLPrefix($baseLink);
     }
 }