/**
  * ParseTemplate
  * Loads the template that you pass in. Replaces any placeholders that you set in GlobalAreas and then goes through, looks for language placeholders, request vars, global vars and replaces them all.
  *
  * @param Template The name of the template to load and then display.
  * @param Return Whether to return the template or just display it. Default is to display it.
  * @param Recurse Whether to recurse into other templates that are included or not.
  *
  * @see GetLang
  * @see GlobalAreas
  * @see _GenerateHelpTip
  * @see GetSession
  * @see Session::LoggedIn
  * @see Session::Get
  * @see User::Admin
  *
  * @return mixed Returns the template if specified otherwise it returns nothing.
  */
 function ParseTemplate($templatename = false, $return = false, $recurse = true)
 {
     if (!$templatename) {
         return false;
     }
     $templatename = strtolower($templatename);
     $template_file = TRACKPOINT_TEMPLATE_DIRECTORY . '/' . $templatename . '.tpl';
     if (!is_file($template_file)) {
         trigger_error(sprintf(GetLang('ErrCouldntLoadTemplate'), ucwords($templatename)), E_USER_ERROR);
     }
     $template = implode('', file($template_file));
     $GLOBALS['TrackPointURL'] = TRACKPOINT_APPLICATION_URL;
     $session =& GetSession();
     if (!$session->LoggedIn()) {
         $template = str_replace('%%GLOBAL_MenuTable%%', '', $template);
         $template = str_replace('%%GLOBAL_TextLinks%%', '', $template);
     }
     list($license_error, $msg) = tpQmz44Rtt();
     if ($session->LoggedIn()) {
         $user = $session->Get('UserDetails');
         if (!isset($GLOBALS['TrackPointUserID'])) {
             $GLOBALS['TrackPointUserID'] = $user->userid;
         }
         $GLOBALS['UserFullName'] = $user->fullname;
         $GLOBALS['UserUserName'] = $user->username;
         $GLOBALS['UserEmailAddress'] = $user->emailaddress;
         if ($templatename == 'header') {
             $switched_user = $session->Get('SwitchUser');
             $switched_username = $session->Get('SwitchUserName');
             $username = $user->username;
             if ($switched_username) {
                 $username = $switched_username;
             }
             $textlink = sprintf(GetLang('ViewingStatsAs'), $username) . '  |  ';
             // if we're viewing the users page = don't show who we're viewing stats as. This may cause confusion as you change between users and it doesn't reflect in the header.
             if (isset($_GET['Page']) && strtolower($_GET['Page']) == 'users') {
                 $textlink = '';
             }
             $textlink .= '<a class="menu" href="index.php">' . GetLang('Home') . '</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a class="menu" href="index.php?Page=Track">' . GetLang('GetTrackingCode') . '</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a class="menu" href="index.php?Page=Conversion">' . GetLang('GetConversionCode') . '</a>&nbsp;&nbsp;|';
             if (!$user->Admin()) {
                 $textlink .= '&nbsp;&nbsp;<a class="menu" href="index.php?Page=ManageAccount">' . GetLang('MyAccount') . '</a>&nbsp;&nbsp;|';
             }
             foreach (array('Users', 'Settings') as $area) {
                 if ($user->HasAccess($area)) {
                     $textlink .= '&nbsp;&nbsp;<a class="menu" href="index.php?Page=' . $area . '">' . GetLang($area) . '</a>&nbsp;&nbsp;|';
                 }
             }
             if (!isset($_GET['Page']) || $_GET['Page'] != 'Settings') {
                 if ($license_error) {
                     $textlink = '';
                     if ($user->HasAccess('Settings')) {
                         $textlink .= '&nbsp;&nbsp;<a class="menu" href="index.php?Page=Settings">' . GetLang('Settings') . '</a>&nbsp;&nbsp;|';
                     }
                     $textlink .= '&nbsp;&nbsp;<a class="menu" href="index.php?Page=Logout">' . GetLang('Logout') . '</a>';
                     $template = str_replace('%%GLOBAL_TextLinks%%', $textlink, $template);
                     $template .= '<div class="body" style="font-size: 13px">' . $msg . '. <a class="menu" href="index.php?Page=Settings" style="font-size: 13px; color: blue;">Click here to update your settings</a>.</div><table><tr><td width="25"><img src="images/blank.gif" width="25" height="10"></td><td width="100%">';
                     // Parse out the language pack variables in the template file
                     preg_match_all("/(?siU)(%%LNG_[a-zA-Z0-9_]{1,}%%)/", $template, $matches);
                     foreach ($matches[0] as $match) {
                         $langvar = str_replace(array('%', 'LNG_'), '', $match);
                         $template = str_replace($match, GetLang($langvar), $template);
                     }
                     echo $template;
                     $this->PrintFooter();
                     exit;
                 }
             }
             if ($license_error && (!isset($_GET['Page']) || $_GET['Page'] == 'Settings')) {
                 $textlink = '';
                 if ($user->HasAccess('Settings')) {
                     $textlink .= '&nbsp;&nbsp;<a class="menu" href="index.php?Page=Settings">' . GetLang('Settings') . '</a>&nbsp;&nbsp;|';
                 }
             }
             $textlink .= '&nbsp;&nbsp;<a class="menu" href="index.php?Page=Logout">' . GetLang('Logout') . '</a>';
             $template = str_replace('%%GLOBAL_TextLinks%%', $textlink, $template);
         }
     }
     if ($license_error && $templatename == 'menu') {
         $template = '<table><tr><td width="25"><img src="images/blank.gif" width="25" height="10"></td><td width="100%">';
     }
     foreach ($this->GlobalAreas as $area => $val) {
         $template = str_replace('%%GLOBAL_' . $area . '%%', $val, $template);
     }
     $matches = array();
     // Parse out the language pack help variables in the template file
     preg_match_all("/(?siU)(%%LNG_HLP_[a-zA-Z0-9_]{1,}%%)/", $template, $matches);
     foreach ($matches[0] as $match) {
         $HelpTip = $this->_GenerateHelpTip($match);
         $template = str_replace($match, $HelpTip, $template);
     }
     // Parse out the language pack variables in the template file
     preg_match_all("/(?siU)(%%LNG_[a-zA-Z0-9_]{1,}%%)/", $template, $matches);
     foreach ($matches[0] as $match) {
         $langvar = str_replace(array('%', 'LNG_'), '', $match);
         $template = str_replace($match, GetLang($langvar), $template);
     }
     // Parse out the request variables in the template file
     preg_match_all("/(?siU)(%%REQUEST_[a-zA-Z0-9_]{1,}%%)/", $template, $matches);
     foreach ($matches[0] as $match) {
         $request_var = str_replace(array('%', 'REQUEST_'), '', $match);
         $request_value = isset($_REQUEST[$request_var]) ? $_REQUEST[$request_var] : '';
         $template = str_replace($match, $request_value, $template);
     }
     // Parse out the global variables in the template file
     preg_match_all("/(?siU)(%%GLOBAL_[a-zA-Z0-9_]{1,}%%)/", $template, $matches);
     foreach ($matches[0] as $match) {
         $global_var = str_replace(array('%', 'GLOBAL_'), '', $match);
         $global_value = isset($GLOBALS[$global_var]) ? $GLOBALS[$global_var] : '';
         if (is_array($global_value)) {
             continue;
         }
         $template = str_replace($match, $global_value, $template);
     }
     if ($recurse) {
         // Parse out the global variables in the template file
         preg_match_all("/(?siU)(%%TPL_[a-zA-Z0-9_]{1,}%%)/", $template, $matches);
         foreach ($matches[0] as $match) {
             $template_var = str_replace(array('%', 'TPL_'), '', $match);
             $subtemplate = $this->ParseTemplate($template_var, true, $recurse);
             $template = str_replace($match, $subtemplate, $template);
         }
     }
     // Parse out the static variables in the template file
     $template = str_replace('%%PAGE_TITLE%%', GetLang('PageTitle'), $template);
     // this is for the 'Page' part for links. Eg -
     // index.php?Page=Stats
     $thispage = get_class($this);
     $template = str_replace('%%PAGE%%', $thispage, $template);
     if ($return) {
         return $template;
     }
     echo $template;
 }
Example #2
0
 /**
  * Process
  * Works out which step everything is up to. Handles error detection etc.
  *
  * @see Install_Step1
  * @see Install_Step2
  * @see Install_Step3
  * @see Install_Step4
  * @see CheckPermissions
  *
  * @return void
  */
 function Process()
 {
     $session =& GetSession();
     $installsettings = $session->Get('InstallSettings');
     if (!$installsettings) {
         $installsettings = array();
     }
     $this->PrintHeader();
     $action = isset($_GET['Action']) ? strtolower($_GET['Action']) : false;
     switch ($action) {
         case 'step2':
             if (!isset($_POST['LicenseKey'])) {
                 $this->ErrorFound = 'The specified license key is invalid, please contact <a href=\'mailto:trackpoint@interspire.com\' style=\'color: blue\'>trackpoint@interspire.com</a> for a new key.';
                 $this->Install_Step1();
                 break;
             }
             list($license_error, $msg) = tpQmz44Rtt($_POST['LicenseKey']);
             if ($license_error) {
                 $this->ErrorFound = 'The specified license key is invalid, please contact <a href=\'mailto:trackpoint@interspire.com\' style=\'color: blue\'>trackpoint@interspire.com</a> for a new key.';
                 $this->Install_Step1();
                 break;
             }
             $installsettings['LICENSEKEY'] = $_POST['LicenseKey'];
             $session->Set('InstallSettings', $installsettings);
             $this->Install_Step2();
             break;
         case 'step3':
             $installsettings['TRACKINGLOGS'] = false;
             $installsettings['SERVERTIMEZONE'] = $_POST['servertimezone'];
             $installsettings['APPLICATION_URL'] = $_POST['application_url'];
             $installsettings['COOKIE_TIME'] = '2190';
             $installsettings['DELETECOOKIE'] = false;
             $installsettings['EMAIL_ADDRESS'] = $_POST['email_address'];
             $session->Set('InstallSettings', $installsettings);
             $this->Install_Step3();
             break;
         case 'step4':
             $dbtype = $_POST['dbtype'];
             require TRACKPOINT_LIB_DIRECTORY . '/database/' . $dbtype . '.php';
             $db_type = $dbtype . 'Db';
             $db =& new $db_type();
             $hostname = $_POST['databaseserver'];
             $username = $_POST['databaseuser'];
             $password = $_POST['databasepass'];
             $database = $_POST['databasename'];
             $connection = $db->Connect($hostname, $username, $password, $database);
             if (!$connection) {
                 list($msg, $level) = $db->GetError();
                 $this->ErrorFound = $msg;
                 $this->Install_Step3();
                 break;
             }
             $GLOBALS['TablePrefix'] = $_POST['tableprefix'];
             $schema = trim($this->ParseTemplate('schema.' . $dbtype, true));
             $queries = explode(';', $schema);
             $errors = array();
             foreach ($queries as $qry) {
                 if (!$qry) {
                     continue;
                 }
                 $result = $db->Query($qry);
                 if (!$result) {
                     list($msg, $level) = $db->GetError();
                     $errors[] = $msg;
                 }
             }
             if (!empty($errors)) {
                 $this->ErrorFound = implode('<br/>', $errors);
                 $this->Install_Step3();
                 break;
             }
             $installsettings['DATABASE_TYPE'] = $dbtype;
             $installsettings['DATABASE_USER'] = $username;
             $installsettings['DATABASE_PASS'] = $password;
             $installsettings['DATABASE_HOST'] = $hostname;
             $installsettings['DATABASE_NAME'] = $database;
             $installsettings['TABLEPREFIX'] = $_POST['tableprefix'];
             $session->Set('InstallSettings', $installsettings);
             $this->Install_Step4();
             break;
         case 'step1':
             $this->CheckPermissions();
             $this->Install_Step1();
             break;
         default:
             $session->Remove('InstallSettings');
             $this->Install_Start();
     }
     $this->PrintFooter();
 }