示例#1
0
	/**
	 * ShowSettingsPage
	 * Prints out the settings page and pre-fills the form fields as much as it can.
	 *
	 * It will also show:
	 * - if there is a license key issue
	 * - if there is a problem with cron/scheduled tasks set up not working properly
	 * - if 'test mode' is enabled
	 * - if you disable attachments, it checks autoresponders to see if any need to be disabled
	 *
	 * @return Void Prints out the settings form, doesn't return anything.
	 */
	function ShowSettingsPage()
	{
		require_once(SENDSTUDIO_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . 'interspire_addons.php');
		$addonSystem = new Interspire_Addons();
		$addonStatus = $addonSystem->GetAvailableAddons();

		$this->PrintHeader();

		$tpl = GetTemplateSystem();

		$GLOBALS['Message'] = '';

		list($license_error, $msg) = sesion_start();

		$extra = '';

		if ($license_error) {
			$GLOBALS['Error'] = $msg;
			$GLOBALS['Message'] .= $this->ParseTemplate('ErrorMsg', true, false);
			$extra = '
				<script>
					$(function() {
						$("licensekey").select();
						$("licensekey").focus();
					});
				</script>
			';
			unset($GLOBALS['Error']);
		}

		if (!is_writable(SENDSTUDIO_INCLUDES_DIRECTORY . '/config.php')) {
			FlashMessage(sprintf(GetLang('ConfigFileNotWritable'), SENDSTUDIO_INCLUDES_DIRECTORY . '/config.php'), SS_FLASH_MSG_WARNING);
		}

		$api = $this->GetApi();
		$api->Load();

		$all_areas = $api->Areas;


		foreach ($all_areas['config'] as $k => $option) {
			$opt_name = 'SENDSTUDIO_' . $option;
			${$opt_name} = constant($opt_name);
		}


		unset($all_areas['config']);
		unset($all_areas['whitelabel']);

		foreach ($all_areas as $k => $option) {
			$opt_name = 'SENDSTUDIO_' . $option;
			${$opt_name} = constant($opt_name);
		}

		if (isset($SENDSTUDIO_FORCE_UNSUBLINK) && $SENDSTUDIO_FORCE_UNSUBLINK == 1) {
			$SENDSTUDIO_FORCE_UNSUBLINK = ' CHECKED';
		}

		if (!isset($SENDSTUDIO_FORCE_UNSUBLINK)) {
			$SENDSTUDIO_FORCE_UNSUBLINK = '';
		}

		$cron_checked = false;
		if (isset($SENDSTUDIO_CRON_ENABLED) && $SENDSTUDIO_CRON_ENABLED == 1) {
			$SENDSTUDIO_CRON_ENABLED = ' CHECKED';
			$cron_checked = true;
		}

		if (!isset($SENDSTUDIO_CRON_ENABLED)) {
			$SENDSTUDIO_CRON_ENABLED = '';
		}

		$GLOBALS['Cron_ShowInfo'] = 'none';
		if ($cron_checked) {
			$GLOBALS['Cron_ShowInfo'] = '';
		}

		$ip_tracking = false;
		if (isset($SENDSTUDIO_IPTRACKING) && $SENDSTUDIO_IPTRACKING == 1) {
			$SENDSTUDIO_IPTRACKING = ' CHECKED';
			$ip_tracking = true;
		}

		if (!isset($SENDSTUDIO_IPTRACKING)) {
			$SENDSTUDIO_IPTRACKING = '';
		}

		if (isset($SENDSTUDIO_USEMULTIPLEUNSUBSCRIBE) && $SENDSTUDIO_USEMULTIPLEUNSUBSCRIBE == 1) {
			$SENDSTUDIO_USEMULTIPLEUNSUBSCRIBE = ' CHECKED';
		}

		if (!isset($SENDSTUDIO_USEMULTIPLEUNSUBSCRIBE)) {
			$SENDSTUDIO_USEMULTIPLEUNSUBSCRIBE = '';
		}

		if (isset($SENDSTUDIO_CONTACTCANMODIFYEMAIL) && $SENDSTUDIO_CONTACTCANMODIFYEMAIL == 1) {
			$SENDSTUDIO_CONTACTCANMODIFYEMAIL = ' CHECKED';
		}

		if (!isset($SENDSTUDIO_CONTACTCANMODIFYEMAIL)) {
			$SENDSTUDIO_CONTACTCANMODIFYEMAIL = '';
		}


		$send_test_mode = false;
		if (isset($SENDSTUDIO_SEND_TEST_MODE) && $SENDSTUDIO_SEND_TEST_MODE == 1) {
			$SENDSTUDIO_SEND_TEST_MODE = ' CHECKED';
			$send_test_mode = true;
		}

		if (!isset($SENDSTUDIO_SEND_TEST_MODE) && SENDSTUDIO_SEND_TEST_MODE == 1) {
			$SENDSTUDIO_SEND_TEST_MODE = ' CHECKED';
			$send_test_mode = true;
		}

		if (!isset($SENDSTUDIO_SEND_TEST_MODE)) {
			$SENDSTUDIO_SEND_TEST_MODE = '';
		}


		if ($SENDSTUDIO_SMTP_SERVER) {
			$GLOBALS['UseSMTP'] = ' CHECKED';
			$GLOBALS['DisplaySMTP'] = "'';";
		} else {
			$GLOBALS['UseDefaultMail'] = ' CHECKED';
			$GLOBALS['DisplaySMTP'] = 'none';
		}

		$GLOBALS['ShowCronInfo'] = 'none';
		$GLOBALS['CronRunTime'] = GetLang('CronRunTime_Never');
		$GLOBALS['CronRunTime_Explain'] = GetLang('CronRunTime_Explain');
		if ($SENDSTUDIO_CRON_ENABLED) {
			$GLOBALS['ShowCronInfo'] = '';
			$cron_ok = $api->Get('cronok');
			if ($cron_ok) {
				$cron_1 = $api->Get('cronrun1');
				$cron_2 = $api->Get('cronrun2');
				if (!$cron_1) {
					$GLOBALS['CronRunTime'] = GetLang('CronRunTime_Once');
				} else {
					$diff = $this->TimeDifference($cron_2 - $cron_1);
					$GLOBALS['CronRunTime'] = sprintf(GetLang('CronRunTime_Difference'), $diff);
				}
			}
		}

		$GLOBALS['Settings_CronOptionsList'] = '';

		/**
		 * The schedule stuff is a little different and comes from the database.
		 * Look at all of the options in the schedule
		 * as addons can defined their own schedules if they need to.
		 */
		$cron_schedule = $api->Get('Schedule');
		$cron_options = array_keys($cron_schedule);


		foreach ($cron_options as $p => $cron_option) {
			if ($cron_option == 'triggeremails_p') {
				$GLOBALS['Settings_CronOptionsList'] .= '<tr style="display:none;"><td><input type="hidden" name="cron_triggeremails_p" value="' . SENDSTUDIO_CRON_TRIGGEREMAILS_P . '" /></td></tr>';
				continue;
			}

			$opt_name = 'Cron_Options';
			$GLOBALS[$opt_name] = '';
			$settings_var = ${'SENDSTUDIO_CRON_' . strtoupper($cron_option)};

			$GLOBALS['Cron_Option_SelectName'] = 'cron_' . $cron_option;

			$GLOBALS['Cron_Option_Heading'] = GetLang('Cron_Option_'.$cron_option.'_Heading');




			foreach ($api->Get($cron_option . '_options') as $opt => $desc) {
				$selected = '';
				if ($opt == $settings_var) {
					$selected = ' SELECTED';
				}
				$GLOBALS[$opt_name] .= '<option value="' . $opt . '"' . $selected . '>' . GetLang('Cron_Option_' . $desc) . '</option>';
			}


			$GLOBALS['Cron_LastRun'] = $GLOBALS['Cron_NextRun'] = '';

			$last_run = $cron_schedule[$cron_option]['lastrun'];
			if ($last_run > 0) {
				$GLOBALS['Cron_LastRun'] = IEM::timeGetUserDisplayString(GetLang('Cron_DateFormat'), $last_run);
				if ($settings_var > 0) {
					$next_run = $last_run + ($settings_var * 60);
					$GLOBALS['Cron_NextRun'] = IEM::timeGetUserDisplayString(GetLang('Cron_DateFormat'), $next_run);
				} else {
					$GLOBALS['Cron_NextRun'] = GetLang('Cron_Option_Disabled');
				}
			} else {
				$GLOBALS['Cron_LastRun'] = GetLang('Cron_Option_HasNotRun');
			}

			// Skipping any problematic CRON schedule
			if (!defined('LNG_Cron_Option_'.$cron_option.'_Heading')) {
				continue;
			}

			$GLOBALS['Cron_Option_Heading'] = GetLang('Cron_Option_'.$cron_option.'_Heading');
			$GLOBALS['Settings_CronOptionsList'] .= $this->ParseTemplate('Settings_Cron_Option', true, false);
		}





		$GLOBALS['Imap_Selected'] = $GLOBALS['Pop3_Selected'] = '';
		if (!isset($SENDSTUDIO_BOUNCE_IMAP) && SENDSTUDIO_BOUNCE_IMAP == 1) {
			$GLOBALS['Imap_Selected'] = ' SELECTED ';
		} else {
			$GLOBALS['Pop3_Selected'] = ' SELECTED ';
		}

		if (isset($SENDSTUDIO_BOUNCE_IMAP) && $SENDSTUDIO_BOUNCE_IMAP == 1) {
			$GLOBALS['Imap_Selected'] = ' SELECTED ';
		} else {
			$GLOBALS['Pop3_Selected'] = ' SELECTED ';
		}

		if (!isset($SENDSTUDIO_BOUNCE_AGREEDELETE) && SENDSTUDIO_BOUNCE_AGREEDELETE == 1) {
			$SENDSTUDIO_BOUNCE_AGREEDELETE = ' CHECKED';
		}

		if (isset($SENDSTUDIO_BOUNCE_AGREEDELETE) && $SENDSTUDIO_BOUNCE_AGREEDELETE == 1) {
			$SENDSTUDIO_BOUNCE_AGREEDELETE = ' CHECKED';
			$GLOBALS['ProcessBounceChecked'] = ' CHECKED';
		} else {
			$GLOBALS['DisplayExtraMailSettings'] = 'none';
		}

		if (!isset($SENDSTUDIO_BOUNCE_AGREEDELETEALL) && SENDSTUDIO_BOUNCE_AGREEDELETEALL == 1) {
			$SENDSTUDIO_BOUNCE_AGREEDELETEALL = ' CHECKED';
		}

		if (isset($SENDSTUDIO_BOUNCE_AGREEDELETEALL) && $SENDSTUDIO_BOUNCE_AGREEDELETEALL == 1) {
			$SENDSTUDIO_BOUNCE_AGREEDELETEALL = ' CHECKED';
		}


		if ($SENDSTUDIO_BOUNCE_EXTRASETTINGS) {
			$GLOBALS['Bounce_ExtraSettings'] = ' CHECKED';
		} else {
			$GLOBALS['DisplayExtraMailSettings'] = 'none';
		}

		$allow_attachments = false;
		if (isset($SENDSTUDIO_ALLOW_ATTACHMENTS) && $SENDSTUDIO_ALLOW_ATTACHMENTS == 1) {
			$SENDSTUDIO_ALLOW_ATTACHMENTS = ' CHECKED';
			$allow_attachments = true;
		}
		if (!isset($SENDSTUDIO_ALLOW_ATTACHMENTS) && SENDSTUDIO_ALLOW_ATTACHMENTS == 1) {
			$SENDSTUDIO_ALLOW_ATTACHMENTS = ' CHECKED';
			$allow_attachments = true;
		}
		if (!isset($SENDSTUDIO_ALLOW_ATTACHMENTS)) {
			$SENDSTUDIO_ALLOW_ATTACHMENTS = '';
		}

		$GLOBALS['ShowAttachmentSize'] = 'none';
		if ($allow_attachments) {
			$GLOBALS['ShowAttachmentSize'] = "'';";
		}

		$embedded_images = false;
		if (isset($SENDSTUDIO_ALLOW_EMBEDIMAGES) && $SENDSTUDIO_ALLOW_EMBEDIMAGES == 1) {
			$embedded_images = true;
			$SENDSTUDIO_ALLOW_EMBEDIMAGES = ' CHECKED';
		}

		if (!isset($SENDSTUDIO_ALLOW_EMBEDIMAGES) && SENDSTUDIO_ALLOW_EMBEDIMAGES == 1) {
			$embedded_images = true;
			$SENDSTUDIO_ALLOW_EMBEDIMAGES = ' CHECKED';
		}

		if (!isset($SENDSTUDIO_ALLOW_EMBEDIMAGES)) {
			$SENDSTUDIO_ALLOW_EMBEDIMAGES = '';
		}

		// this option is hidden by the embedded_images check but we should remember the 'state' in case the admin turns off embedded images and then turns it back on.
		if (isset($SENDSTUDIO_DEFAULT_EMBEDIMAGES) && $SENDSTUDIO_DEFAULT_EMBEDIMAGES == 1) {
			$SENDSTUDIO_DEFAULT_EMBEDIMAGES = ' CHECKED';
		}

		if (!isset($SENDSTUDIO_DEFAULT_EMBEDIMAGES) && SENDSTUDIO_DEFAULT_EMBEDIMAGES == 1) {
			$SENDSTUDIO_DEFAULT_EMBEDIMAGES = ' CHECKED';
		}

		if (!isset($SENDSTUDIO_DEFAULT_EMBEDIMAGES)) {
			$SENDSTUDIO_DEFAULT_EMBEDIMAGES = '';
		}

		$GLOBALS['ShowDefaultEmbeddedImages'] = 'none';
		if ($embedded_images) {
			$GLOBALS['ShowDefaultEmbeddedImages'] = "'';";
		}

		/**
		* Now we have worked out the logic of what options are pre-filled,
		* we'll just set up the variables ready for the template system to use everything.
		*/

		$disabled_functions = explode(',', SENDSTUDIO_DISABLED_FUNCTIONS);
		$php_binary = 'php';
		if (substr(strtolower(PHP_OS), 0, 3) == 'win') {
			$php_binary = 'php.exe';
		}
		$php_path = $this->Which($php_binary);

		// If we can't find the full path, just print the binary so people get the right idea.
		if ($php_path == '') {
			$php_path = $php_binary;
		}
		$php_path .= ' -f ';

		$GLOBALS['CronPath'] = $php_path . SENDSTUDIO_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'cron' . DIRECTORY_SEPARATOR . 'cron.php';

		$GLOBALS['DatabaseType'] = $SENDSTUDIO_DATABASE_TYPE;
		$GLOBALS['DatabaseUser'] = $SENDSTUDIO_DATABASE_USER;
		$GLOBALS['DatabaseHost'] = $SENDSTUDIO_DATABASE_HOST;
		$GLOBALS['DatabasePass'] = $SENDSTUDIO_DATABASE_PASS;
		$GLOBALS['DatabaseName'] = $SENDSTUDIO_DATABASE_NAME;
		$GLOBALS['DatabaseTablePrefix'] = $SENDSTUDIO_TABLEPREFIX;
		$GLOBALS['ApplicationURL'] = $SENDSTUDIO_APPLICATION_URL;
		$GLOBALS['LicenseKey'] = $SENDSTUDIO_LICENSEKEY;
		$GLOBALS['DatabaseVersion'] = $api->Db->FetchOne('SELECT version() AS version');

		$GLOBALS['System_Message'] = htmlentities($SENDSTUDIO_SYSTEM_MESSAGE, ENT_QUOTES, SENDSTUDIO_CHARSET);

		$GLOBALS['TextFooter'] = strip_tags($SENDSTUDIO_TEXTFOOTER);
		$GLOBALS['HTMLFooter'] = $SENDSTUDIO_HTMLFOOTER;

		$GLOBALS['ForceUnsubLink'] = $SENDSTUDIO_FORCE_UNSUBLINK;

		$GLOBALS['CronEnabled'] = $SENDSTUDIO_CRON_ENABLED;

		$GLOBALS['IpTracking'] = $SENDSTUDIO_IPTRACKING;
		$GLOBALS['UseMultipleUnsubscribe'] = $SENDSTUDIO_USEMULTIPLEUNSUBSCRIBE;
		$GLOBALS['ContactCanModifyEmail'] = $SENDSTUDIO_CONTACTCANMODIFYEMAIL;

		$GLOBALS['SendTestMode'] = $SENDSTUDIO_SEND_TEST_MODE;

		$GLOBALS['MaxHourlyRate'] = $SENDSTUDIO_MAXHOURLYRATE;

		$GLOBALS['MaxOverSize'] = $SENDSTUDIO_MAXOVERSIZE;

		$GLOBALS['EmailAddress'] = htmlspecialchars($SENDSTUDIO_EMAIL_ADDRESS, ENT_QUOTES, SENDSTUDIO_CHARSET);

		$GLOBALS['MaxImageWidth'] = intval($SENDSTUDIO_MAX_IMAGEWIDTH);
		$GLOBALS['MaxImageHeight'] = intval($SENDSTUDIO_MAX_IMAGEHEIGHT);

		$GLOBALS['Smtp_Server'] = htmlspecialchars($SENDSTUDIO_SMTP_SERVER, ENT_QUOTES, SENDSTUDIO_CHARSET);
		$GLOBALS['Smtp_Username'] = htmlspecialchars($SENDSTUDIO_SMTP_USERNAME, ENT_QUOTES, SENDSTUDIO_CHARSET);
		$GLOBALS['Smtp_Password'] = base64_decode($SENDSTUDIO_SMTP_PASSWORD);
		$GLOBALS['Smtp_Port'] = $SENDSTUDIO_SMTP_PORT;

		$GLOBALS['Bounce_Address'] = htmlspecialchars($SENDSTUDIO_BOUNCE_ADDRESS, ENT_QUOTES, SENDSTUDIO_CHARSET);
		$GLOBALS['Bounce_Server'] = htmlspecialchars($SENDSTUDIO_BOUNCE_SERVER, ENT_QUOTES, SENDSTUDIO_CHARSET);
		$GLOBALS['Bounce_Username'] = htmlspecialchars($SENDSTUDIO_BOUNCE_USERNAME, ENT_QUOTES, SENDSTUDIO_CHARSET);
		$GLOBALS['Bounce_Password'] = base64_decode($SENDSTUDIO_BOUNCE_PASSWORD);
		$GLOBALS['Bounce_Imap'] = $SENDSTUDIO_BOUNCE_IMAP;
		$GLOBALS['Bounce_ExtraSettings'] = htmlspecialchars($SENDSTUDIO_BOUNCE_EXTRASETTINGS, ENT_QUOTES, SENDSTUDIO_CHARSET);
		$GLOBALS['Bounce_AgreeDelete'] = $SENDSTUDIO_BOUNCE_AGREEDELETE;
		$GLOBALS['Bounce_AgreeDeleteAll'] = $SENDSTUDIO_BOUNCE_AGREEDELETEALL;

		$GLOBALS['AllowAttachments'] = $SENDSTUDIO_ALLOW_ATTACHMENTS;
		$GLOBALS['AllowEmbedImages'] = $SENDSTUDIO_ALLOW_EMBEDIMAGES;

		$GLOBALS['AttachmentSize'] = $SENDSTUDIO_ATTACHMENT_SIZE;

		$GLOBALS['EmailSize_Warning'] = $SENDSTUDIO_EMAILSIZE_WARNING;
		$GLOBALS['EmailSize_Maximum'] = $SENDSTUDIO_EMAILSIZE_MAXIMUM;

		$GLOBALS['Resend_Maximum'] = $SENDSTUDIO_RESEND_MAXIMUM;

		$GLOBALS['DefaultEmbedImages'] = $SENDSTUDIO_DEFAULT_EMBEDIMAGES;

		$GLOBALS['Copyright'] = htmlspecialchars(LNG_Copyright, ENT_QUOTES, SENDSTUDIO_CHARSET);

		$GLOBALS['Existing_App_Logo_Image'] = APPLICATION_LOGO_IMAGE;

		$GLOBALS['Existing_App_Favicon'] = APPLICATION_FAVICON;

//		$GLOBALS['EnableUpdatesCheck'] = (isset($addonStatus['updatecheck']['enabled']) && $addonStatus['updatecheck']['enabled'] == '1') ? 'CHECKED' : '';

		$GLOBALS['ShowIntroVideo'] = (SHOW_INTRO_VIDEO == true) ? 'CHECKED' : '';

		$GLOBALS['ShowSmtpComOption'] = (SHOW_SMTP_COM_OPTION == true) ? 'CHECKED' : '';

		$GLOBALS['ShowSmtpComOptionShow'] = (SHOW_SMTP_COM_OPTION == true) ? '' : 'none';



		$GLOBALS['FormAction'] = 'Action=Save';

		if (!$cron_checked) {
			$api->DisableCron();
		}

		if ($cron_checked) {
			$this->DisplayCronWarning(false);
		}

		$test_mode_report = '';
		if ($send_test_mode) {
			$jobs_api = $this->GetApi('Jobs');
			$job_found = $jobs_api->FindJob('send', 'newsletter', 0, true, false, false);
			if ($job_found) {
				$test_mode_report = $this->PrintWarning('Send_TestMode_JobsWaiting');
			}
		}

		$GLOBALS['Send_TestMode_Report'] = $test_mode_report;

		$attachments_report = '';

		if (!$allow_attachments) {
			$autos_to_disable = array();

			$auto_files = list_files(TEMP_DIRECTORY . DIRECTORY_SEPARATOR . 'autoresponders', null, true);
			if (!empty($auto_files)) {
				$autoresponder_ids = array_keys($auto_files);
				foreach ($autoresponder_ids as $p => $autoresponderid) {
					$files = $auto_files[$autoresponderid];
					if (isset($files['attachments'])) {
						if (!empty($files['attachments'])) {
							$autos_to_disable[] = $autoresponderid;
						}
					}
				}
			}

			if (!empty($autos_to_disable)) {
				$auto_api = $this->GetApi('Autoresponders');
				$disabled_list = $auto_api->DisableAutoresponders($autos_to_disable);
				if (!empty($disabled_list)) {
					$amount = sizeof(array_keys($disabled_list));
					if ($amount == 1) {
						$attachments_report .= GetLang('Autoresponders_Disabled_Attachments_One_Link');
					} else {
						$attachments_report .= sprintf(GetLang('Autoresponders_Disabled_Attachments_Many_Link'), $this->FormatNumber($amount));
					}

					$email_api = $this->GetApi('Email');
					$email_api->Set('CharSet', SENDSTUDIO_CHARSET);

					foreach ($disabled_list as $p => $disabled_details) {
						$subject = GetLang('Autoresponders_Disabled_Email_Subject');

						$message = sprintf(GetLang('Autoresponders_Disabled_Email_Message'), $disabled_details['autorespondername'], $disabled_details['listname']);

						$email_api->ClearAttachments();
						$email_api->ClearRecipients();

						$email_api->Set('Multipart', false);
						$email_api->AddBody('text', $message);
						$email_api->Set('Subject', $subject);

						$email_api->Set('FromAddress', SENDSTUDIO_EMAIL_ADDRESS);

						$email_api->AddRecipient($disabled_details['owneremail'], $disabled_details['ownername'], 't');

						$email_api->Send();
					}
					IEM::sessionSet('AutorespondersDisabled', $disabled_list);
				}
			}
			
			$newsletters_to_disable = array();
            
            $newsletter_files = list_files(TEMP_DIRECTORY . DIRECTORY_SEPARATOR . 'newsletters', null, true);
			if (!empty($newsletter_files)) {
				$newsletter_ids = array_keys($newsletter_files);
				
				
				
				foreach ($newsletter_ids as $newsid) {
			
			
			
			
			
			
                
					$files = $newsletter_files[$newsid];
					if (isset($files['attachments'])) {
						if (!empty($files['attachments'])) {
							$newsletterts_to_disable[] = $newsid;
						}
					}
                   
                }
            }            

			if (!empty($newsletters_to_disable)) {
				if ($attachments_report != '') {
					$attachments_report .= '<br/><br/>';
				}

				$news_api = $this->GetApi('Newsletters');
				$disabled_list = $news_api->DisableNewsletters($newsletters_to_disable);
				if (!empty($disabled_list)) {
					$amount = sizeof(array_keys($disabled_list));
					if ($amount == 1) {
					
						$attachments_report .= GetLang('Newsletters_Disabled_Attachments_One_Link');
					} else {
						$attachments_report .= sprintf(GetLang('Newsletters_Disabled_Attachments_Many_Link'), $this->FormatNumber($amount));
				}
				IEM::sessionSet('NewslettersDisabled', $disabled_list);
			}
		  }
		}

		$GLOBALS['DisplayAttachmentsMessage'] = "none;";
		if ($attachments_report) {
			$GLOBALS['DisplayAttachmentsMessage'] = '';
			$GLOBALS['Warning'] = $attachments_report;

			$GLOBALS['Attachments_Message'] = $this->ParseTemplate('WarningMsg', true, false);
		}

		$GLOBALS['ExtraScript'] = $extra;

		$GLOBALS['Settings_AddonsDisplay'] = $this->PrintAddonsList();

		// ----- Credit settings
			$tempPercentageWarnings = array();
			$tempFixedWarnings = array(); // TODO fixed credit warnings aren't implemented yet
			$tempWarnings = $api->GetCreditWarningsSettings();

			// If warnings can't be found, create default.
			if (empty($tempWarnings)) {
				$tempDefaultLevel = array('0', '15', '25');
				$tempWarnings = array();

				foreach ($tempDefaultLevel as $each) {
					$tempPercentageWarnings[] = array(
						'enabled' => '0',
						'creditlevel' => $each,
						'aspercentage' => '1',
						'emailsubject' => GetLang('CreditWarnings_Warnings_EmailSubjectDefaultText'),
						'emailcontents' => str_replace('%s', "{$each}%", GetLang('CreditSettings_Warnings_PercentageDefaultText'))
					);
				}

				unset($tempDefaultLevel);

			// Split the warnings into two arrays (fixed and percentage warnings)
			} else {
				foreach ($tempWarnings as $each) {
					if ($each['aspercentage']) {
						$tempPercentageWarnings[] = $each;
					} else {
						$tempFixedWarnings[] = $each;
					}
				}
			}

			unset($tempWarnings);

			$tpl->Assign('credit_settings', array(
				'autoresponders_take_credit' => (bool)SENDSTUDIO_CREDIT_INCLUDE_AUTORESPONDERS,
				'triggers_take_credit' => (bool)SENDSTUDIO_CREDIT_INCLUDE_TRIGGERS,
				'enable_credit_level_warnings' => (bool)SENDSTUDIO_CREDIT_WARNINGS,
				'warnings_percentage_level' => $tempPercentageWarnings,
				'warnings_percentage_level_choices' => array(
					'0', '5', '10', '15', '20', '25',
					'30', '35', '40', '45', '50'
				)
			));
		// -----

		// ----- Login Security settings
			$security_settings = array(
				'login_wait' => SENDSTUDIO_SECURITY_WRONG_LOGIN_WAIT,
				'threshold_login_count' => SENDSTUDIO_SECURITY_WRONG_LOGIN_THRESHOLD_COUNT,
				'threshold_login_duration' => SENDSTUDIO_SECURITY_WRONG_LOGIN_THRESHOLD_DURATION / 60,
				'ip_login_ban_duration' => SENDSTUDIO_SECURITY_BAN_DURATION / 60
			);

			$security_settings_options = array(
				'login_wait' => array(1, 2, 3, 4, 5),
				'threshold_login_count' => array(3, 4, 5, 10, 15),
				'threshold_login_duration' => array(1, 5, 10, 15),
				'ip_login_ban_duration' => array(1, 5, 10, 15)
			);

			$tpl->Assign('security_settings', $security_settings);
			$tpl->Assign('security_settings_options', $security_settings_options);
		// -----

		$tpl->Assign('AgencyEdition', get_agency_license_variables());

		$showtab = 1;
		if (isset($_GET['Tab'])) {
			$tab = (int)$_GET['Tab'];
			if ($tab > 0) {
				$showtab = $tab;
			}
		}

		$GLOBALS['Message'] .= GetFlashMessages();

		$tpl->Assign('ShowTab', $showtab);
		$tpl->Assign('DisplayPrivateLabel', (defined('APPLICATION_SHOW_WHITELABEL_MENU')? constant('APPLICATION_SHOW_WHITELABEL_MENU') : true));

		$tpl->ParseTemplate('Settings');

		$this->PrintFooter();
	}