コード例 #1
0
	/**
	* DisplayChart
	* Sets the URL for chart data and sets the variables to display the chart
	*
	* @param String $chartname The variable name for the chart
	* @param String $chart_area The statistics area the chart is for
	* @param Int $statid The statid the chart is for
	* @param String $type The type of chart to display
	* @param Array $settings Settings for the chart
	*
	* @see InsertChartImage
	*
	* @return Void Returns nothing
	*/
	function DisplayChart($chartname='', $chart_area='', $statid=0, $type = 'pie', $settings = null)
	{
		$data_url = 'stats_chart.php?graph=' . urlencode(strtolower($chartname)) . '&Area='.urlencode(strtolower($chart_area)) . '&statid=' . (int)$statid . '&' . IEM::SESSION_NAME . '=' . IEM::sessionID();

		$this->InsertChartImage($chartname,$data_url);
	}
コード例 #2
0
ファイル: imagemanager.php プロジェクト: hungnv0789/vhtm
	/**
	* ManageImages
	* Perform the action to display the UI for managing Images.
	*
	* @param Interger $userid The user id of current login user.
	*
	* @return Void Doesn't return anything. Display the template to the browser.
	*/
	function ManageImages () {
		$api = $this->GetApi();
		$settingApi = $this->GetApi('settings');
		$GLOBALS['adminUrl'] = SENDSTUDIO_APPLICATION_URL.'/admin';
		$GLOBALS['imgLocation'] = $api->GetImageDir();
		$params = '';
		foreach ($_GET as $k=>$v) {
			$params[] = $k.'='.$v;
		}
		if ($params) {
			$params = '?'.implode('&', $params);
		}

		$tpl = GetTemplateSystem();
		$tpl->Assign('SessionName', IEM::SESSION_NAME);
		$tpl->Assign('SessionID', IEM::sessionID());
		$tpl->Assign('Params', $params);
		echo $tpl->ParseTemplate('Image_Manage');
		die();
	}
コード例 #3
0
	/**
	* Process
	* This processes the ajax requests.
	* There are only two types of request - importfile and importurl.
	*
	* If it's importfile, it will display the 'fileupload' iframe again, and also process the file if there was one uploaded. It base 64 encodes the data to pass to javascript, this saves having to worry about newlines, quotes and so on. The javascript decodes it itself, then calls the DoImport function in the includes/js/javascript.js file.
	*
	* If it's importurl, it simply calls GetPageContents and returns that.
	*
	* @see GetPageContents
	*
	* @return Void Doesn't return anything, simply prints out the results.
	*/
	function Process()
	{
		// make sure they are logged in appropriately.
		if (!IEM::getCurrentUser()) {
			return;
		}

		$GLOBALS['ImportType'] = 'HTML';
		if (isset($_GET['ImportType']) && strtolower($_GET['ImportType']) == 'text') {
			$GLOBALS['ImportType'] = 'Text';
		}

		if (isset($_GET['DisplayFileUpload'])) {
			$this->ParseTemplate('Editor_FileUpload');
			return;
		}

		$user = GetUser();

		if (isset($_POST['what'])) {
			$what = $_POST['what'];

			switch (strtolower($what)) {
				case 'check_existing':
					// this is used when editing an autoresponder and you check the "send to existing" box.
					// it will alert you if you have sent this autoresponder to any recipients before
					// so you're aware that they will receive it again.

					$autoresponder_id = (isset($_POST['auto'])) ? (int)$_POST['auto'] : 0;
					if ($autoresponder_id <= 0) {
						exit;
					}

					$this->LoadLanguageFile('autoresponders');

					require_once(SENDSTUDIO_API_DIRECTORY . '/autoresponders.php');
					$auto_api = new Autoresponders_API();

					$userid = $user->userid;

					// If user is an admin, omit the userid so that it won't get checked
					if ($user->Admin()) {
						$userid = 0;
					}

					$already_sent_to = $auto_api->GetRecipientCount($autoresponder_id, $userid);
					if (!$already_sent_to) {
						exit;
					}

					if ($already_sent_to > 0) {
						$msg = sprintf(GetLang('AutoresponderAlreadySentTo'), $this->FormatNumber($already_sent_to));
						echo $msg;
					}
					exit;
				break;

				case 'importlinks':
					$listid = false;
					$processing_list = IEM::sessionGet('LinksForList');
					if ($processing_list) {
						$listid = (int)$processing_list;
					}

					$links = $user->GetAvailableLinks($listid);

					$link_list = 'mylinks[-1]=\'' . GetLang('FilterAnyLink') . '\';' . "\n";
					foreach ($links as $linkid => $url) {
						$link_list .= 'mylinks[' . $linkid . ']=\'' . addslashes($url) . '\';' . "\n";
					}
					echo $link_list;
				break;

				case 'importnewsletters':
					$listid = false;

					$processing_list = IEM::sessionGet('NewsForList');
					if ($processing_list) {
						$listid = (int)$processing_list;
					}

					$news = $user->GetAvailableNewsletters($listid);

					$news_list = 'mynews[-1]=\'' . GetLang('FilterAnyNewsletter') . '\';' . "\n";
					foreach ($news as $newsid => $name) {
						$news_list .= 'mynews[' . $newsid . ']=\'' . addslashes($name) . '\';' . "\n";
					}
					echo $news_list;
				break;

				case 'importfile':
					if (!empty($_FILES['newsletterfile'])) {
						if (is_uploaded_file($_FILES['newsletterfile']['tmp_name'])) {
							$page = file_get_contents($_FILES['newsletterfile']['tmp_name']);

							$page = self::ScrubPage($page);

							header('Content-type: text/html;');

							?>
							<script>
								parent.ajaxData = '<?php echo addcslashes($page,"'\\\n\r"); ?>';
								parent.DoImport('file', '<?php echo $GLOBALS['ImportType']; ?>');
							</script>
							<?php
						}
					}
					$this->ParseTemplate('Editor_FileUpload');
				break;

				case 'importurl':
					$url = false;
					if (isset($_POST['url'])) {
						$url = $_POST['url'];
					}
					list($page, $statusmsg) = $this->GetPageContents($url);
					if ($page) {
						// if there is a base href, don't worry about converting the links and images.
						// the email class does this when it sends the content.
						if (preg_match('%base href=%is', $page)) {
							echo $page;
							break;
						}

						$page = self::ScrubPage($page);

						/**
						* $url starts off as something like http://www.domain.com/path/index.html
						*
						* Grab the scheme & hostname from the url.
						*/
						$urlparts = parse_url($url);
						$baseurl = $urlparts['scheme'] . '://';
						$baseurl .= $urlparts['host'];

						/**
						* If there is a path (eg '/path/index.html'), break it up into sections.
						*
						* Then if there is an extension to the path, we assume it's a file (the extension in this case is 'html').
						*
						* So we need to take the basename of the file (/path) and add that to our url.
						*
						* If the url starts off as http://www.domain.com/path/
						* there will be no extension for '/path' so we assume it's a directory
						* So that means we have to add the 'basename' of the url ('/path') to the base url.
						*
						* If the url starts off as http://www.domain.com then there will be no path to worry about at all,
						* so we can skip that whole section
						*
						*/
						if (isset($urlparts['path'])) {
							$path_parts = pathinfo($urlparts['path']);
							$baseurl .= $path_parts['dirname'];

							if (!isset($path_parts['extension'])) {
                                $baseurl .= '/'.$path_parts['basename'];
							}
						}

						// Remove trailing '\' from base URL
						$baseurl = preg_replace('/(%5c|\\\\)$/i', '', $baseurl);

						// make sure the baseurl always has a '/' on the end - ie we need to point to a directory not a file.
						if (substr($baseurl, -1) != '/') {
							$baseurl .= '/';
						}

						// Modified to parse HTML and find src and href, and convert it into an absolute resource link
						$pattern = '~(?<=src=["\']|href=["\']|link=["\']|background=["\']|url\()(?![a-z0-9]*?\://|\%\%|mailto\:|#|javascript\:|news\:)(.*?)(?=["\'])~i';
						$page = preg_replace($pattern, "{$baseurl}\$1", $page);

						/**
						* Clean up links that started out looking like
						* http://host/path/to/file.ext
						* and ended up looking like
						* http://host/path/to//path/to/file.ext
						*/
						if (isset($path_parts['dirname'])) {
							$path = $path_parts['dirname'];
							if (strlen($path) > 1) {
								$page = str_replace($path . '/' . $path, $path, $page);
							}
						}

						/**
						* Clean up the urls so they don't have double slashes or '/./' in them.
						*/
						$page = str_replace(array('/./', '//'), '/', $page);

						/**
						* However that breaks our scheme (http or https) so we need to re-fix those again.
						*/
						$page = str_replace(array('http:/', 'https:/'), array('http://', 'https://'), $page);

						echo $page;
					}
				break;

				case 'save_version':
					// Only admin user can save "version"
					if (!$user->Admin()) {
						exit();
					}

					$lines = array();

					if (isset($_POST['latest'])) {
						$lines[] = 'latest=' . $_POST['latest'];
					}

					if (isset($_POST['feature'])) {
						$lines[] = 'feature=' . $_POST['feature'];
					}

					if (isset($_POST['latest_critical'])) {
						$lines[] = 'latest_critical=' . (int)$_POST['latest_critical'];
					}

					if (isset($_POST['feature_critical'])) {
						$lines[] = 'feature_critical=' . (int)$_POST['feature_critical'];
					}

					$fp = fopen(IEM_STORAGE_PATH . '/.version', 'w');
					if ($fp) {
						foreach ($lines as $line) {
							$line .= "\r\n";
							fputs($fp, $line);
						}
						fclose($fp);
					}
				break;

				case 'googlecalendar':
					$this->LoadLanguageFile('Subscribers');
					if (strlen($user->googlecalendarusername) && strlen($user->googlecalendarpassword)) {
						if (isset($_POST['google']) && is_array($_POST['google'])) {
							$google = $_POST['google'];
							$google['username'] = $user->googlecalendarusername;
							$google['password'] = $user->googlecalendarpassword;
							if (isset($google['allday']) && $google['allday']) {
								IEM::sessionSet('gcal_allday',true);
							} else {
								IEM::sessionSet('gcal_allday',false);
							}

							try {
								$this->GoogleCalendarAdd($google);
								echo 'top.tb_remove();';
							} catch (GoogleCalendarException $e) {
								switch ($e->getCode()) {
									case GoogleCalendarException::BADAUTH;
										echo 'alert("' . GetLang('GoogleCalendarAuth') . '");';
									break;
									default:
										echo 'alert("' . GetLang('GoogleCalendarException') . '");';
										echo "//" . $e->getMessage();
								}

							}
						}
					}
				break;
				case 'imagemanagerrename':
					$api = $this->GetApi('ImageManager');

					// lets get the extension from the old filename
					$ext = substr(strrchr($_POST['fromName'], "."), 0);
					$_POST['toName'] = $_POST['toName'] . $ext;

					$return = array();
					if(strpos($_POST['toName'], '/') !== false || strpos($_POST['toName'], '\\') !== false ){
						$return['success'] = false;
						$return['message'] = GetLang('ImageManagerRenameInvalidFileName');
						die(json_encode($return));
					}

					if(!$this->IsImageFile($_POST['toName'])){
						$return['success'] = false;
						$return['message'] = GetLang('ImageManagerRenameInvalidFileName');
						die(json_encode($return));
					}
					if(!file_exists($api->GetImagePath() . '/' . $_POST['fromName'])){
						$return['success'] = false;
						$return['message'] = GetLang('ImageManagerFileDoesntExistRename');
						die(json_encode($return));
					}

					if(file_exists($api->GetImagePath() . '/' . $_POST['toName'])){
						$return['success'] = false;
						$return['message'] = GetLang('ImageManagerRenameFileAlreadyExists');
						die(json_encode($return));
					}

					if(!@rename($api->GetImagePath() . '/' . $_POST['fromName'], $api->GetImagePath() . '/' . $_POST['toName'])){
						if(isset($php_errormsg)){
							$msgBits = explode(':', $php_errormsg);
							if(isset($msgBits[1])){
								$message =  $msgBits[1] . '.';
							}else{
								$message =  $php_errormsg  . '.';
							}
						}else{
							$message = 'Unknown error.';
						}
						$return['success'] = false;
						$return['message'] = $message;
						die(json_encode($return));
					}

					$return['success'] = true;
					$newName = $_POST['toName'];
					$newName = substr($newName, 0, strrpos($newName, "."));
					$return['newname'] = strtolower(htmlspecialchars($newName));
					$return['newrealname'] = strtolower(htmlspecialchars($_POST['toName']));
					$return['newurl'] = $api->GetImageDir() . urlencode(strtolower($_POST['toName']));
					echo json_encode($return);
					die();
				break;
				case 'imagemanagerdelete':

					$api = $this->GetApi('ImageManager');
					$successImages = $errorFiles = $return = array();

					if(!is_array($_POST['deleteimages']) || empty($_POST['deleteimages'])) {
						$return['success'] = false;
						$return['message'] = GetLang('ImageManagerNoImagesSelectedDelete');
						die(json_encode($return));
					}

					foreach($_POST['deleteimages'] as $k=>$image) {
						if(file_exists($api->GetImagePath() . '/' . $image)){
							if(!@unlink($api->GetImagePath() . '/' . $image)) {
								if(isset($php_errormsg)){
									$msgBits = explode(':', $php_errormsg);
									if(isset($msgBits[1])){
										$errorFiles =  $msgBits[1] .'.';
									}else{
										$errorFiles =  $php_errormsg  .'.';
									}
								}else{
									$errorFiles[] = GetLang('ImageManagerUnableDeleteError') . ' ' . $image;
								}
								unset($php_errormsg);
							}else{
								$ext = strrchr($image, '.');
								if($ext !== false) {
									$image = substr($image, 0, -strlen($ext));
								}
								$successImages[] = $image;
							}
						}
					}
					if(!empty($errorFiles)){
						$return['success'] = false;
						$return['message'] = GetLang('ImageManagerDeleteErrors') . $this->ArrayToList($errorFiles);
						die(json_encode($return));
					}

					$return['success'] = true;
					$return['successimages'] = $successImages;
					if(count($successImages) == 1){
						$return['message'] = GetLang('ImageManagerDeleteSuccessSingle');
					}elseif(count($successImages) > 1){
						$return['message'] = sprintf(GetLang('ImageManagerDeleteSuccessMulti'), count($successImages));
					}
					echo json_encode($return);
					die();
				break;
				case 'imagemanagerimagenumshown':
					$api = $this->GetApi('ImageManager');
					$api->Init();
					$return['text'] = $api->GetImageNumberShownText();
					echo json_encode($return);
				break;
				case 'imagemanagermanage':
					$api = $this->GetApi('ImageManager');
					$settingApi = $this->GetApi('settings');
					$GLOBALS['imgLocation'] = $api->GetImageDir();

					// Sorting of the images
					$validSort = array("name.asc", "name.desc", "modified.desc", "modified.asc", "size.asc", "size.desc");
					$sortby = '';
					if(isset($_GET['SortBy'])){
						$sortby = $_GET['SortBy'];
						$sortBits = explode('.', $sortby);
						$_GET['SortBy'] = $sortBits[0];
						$_GET['Direction'] = $sortBits[1];
					}

					$perpage = $this->GetPerPage();
					$DisplayPage = $this->GetCurrentPage();
					$start = 0;
					$sortinfo = $this->GetSortDetails();


					// if sorting field and direction is defined
					if (isset($sortinfo['Direction']) && isset($sortinfo['SortBy'])) {
						$sortby = $sortinfo['SortBy'].'.'.$sortinfo['Direction'];
					}

					// Default sorting field and direction
					if(empty($sortby) || !in_array($sortby, $validSort, true)){
						$sortby = 'name.asc';
						list($sortinfo['SortBy'], $sortinfo['Direction']) = explode('.', $sortby);
					}

					// Init the images sorting field and direction
					$api->Init($sortinfo['Direction'], $sortinfo['SortBy']);

					// Pagination setup
					$GLOBALS['SortList'] = '';
					foreach ($validSort as $eachSort) {
						$eachSortBits = explode('.', $eachSort);
						$displayText = GetLang('Sort'.ucwords($eachSortBits[0]).ucwords($eachSortBits[1]));
						$sel = '';
						if ($eachSort == $sortby) {
							$sel = ' SELECTED ';
						}
						$GLOBALS['SortList'] .= '<option value="'.$eachSort.'" '.$sel.'>' . $displayText . '</option> ';
					}
					if (strtolower($perpage) != 'all') {
						$api->start = ($perpage * $DisplayPage) - $perpage;
						$api->finish = ($perpage * $DisplayPage);
					}

					$NumberOfImages = ($api->CountDirItems())?$api->CountDirItems():1;

					$this->SetupPaging($NumberOfImages, $DisplayPage, $perpage);
					$GLOBALS['FormAction'] = 'Action=ProcessPaging';
					$paging = $this->ParseTemplate('Paging', true);
					$GLOBALS['dirImages'] = '';
					$dirImages = $api->GetImageDirFiles();

					$GLOBALS['Intro_Help'] = GetLang('Help_ImageManagerManage');
					$GLOBALS['Intro'] = GetLang('ImageManagerManage');
					$GLOBALS['NumImageShown'] = $api->GetImageNumberShownText();

					$GLOBALS['ImageManager_AddButton'] = '<input id="btnUpload" type="button" value="'.GetLang('ImageManagerUploadImages').'" class="SmallButton" />';
					$showDeleteBtn = "display:none";
					if ($api->CountDirItems()) {
						$showDeleteBtn = "";
						foreach ($dirImages as $dirImage) {
                            $GLOBALS['dirImages'] .= "AdminImageManager.AddImage( '".addslashes($dirImage['name'])."', '".addslashes($dirImage['url'])."', '".$dirImage['size']." Bytes', '".$dirImage['width']."', '".$dirImage['height']."', '".$dirImage['origwidth']." X ".$dirImage['origheight']."', '".$dirImage['id']."'); ";							$GLOBALS['DisplayImagePanel'] = 'block';
						}
					} else {
						$GLOBALS['DisplayImagePanel'] = 'none';
						$GLOBALS['Message'] = $GLOBALS['Message'] = $this->PrintSuccess('NoImage');
					}
					$GLOBALS['ImageManager_DeleteButton'] = '<input id="deleteButton" type="button" value="'.GetLang('DeleteSelected').'"  class="SmallButton" style="'.$showDeleteBtn.';" />';

					$tpl = GetTemplateSystem();
					$tpl->Assign('SessionName', IEM::SESSION_NAME);
					$tpl->Assign('Pagination', $paging);
					$tpl->Assign('SessionID', IEM::sessionID());
					echo $tpl->ParseTemplate('Image_Manager_Sub');
				break;
			}
		}
	}
コード例 #4
0
ファイル: index.php プロジェクト: hungnv0789/vhtm
	function PrintNewsletterStatsChart($statid=0)
	{
		$statsapi = $this->GetApi('Stats');

		include(dirname(__FILE__) . '/amcharts/amcharts.php');

		$perpage = 1;
		$summary = $statsapi->GetNewsletterSummary($statid, true, $perpage);

		$sent_size = $summary['sendsize'];

		$total_bounces = $summary['bouncecount_unknown'] + $summary['bouncecount_hard'] + $summary['bouncecount_soft'];

		// now for the opens page.
		// by default this is for all opens, not unique opens.
		$only_unique = false;
		if (isset($_GET['Unique'])) {
			$only_unique = true;
		}

		$unopened = $sent_size - $summary['emailopens_unique'] - $total_bounces;
		if ($unopened < 0) {
			$unopened = 0;
		}

		$data_url = 'stats_chart.php?Opens='. $summary['emailopens_unique'] . '&Unopened=' . $unopened . '&Bounced=' . $total_bounces . '&' . IEM::SESSION_NAME . '=' . IEM::sessionID();

		// Newsletter Summary Chart
		$chart = InsertChart('pie', $data_url, array('graph_title' => GetLang("NewsletterSummaryChart"), 'y_position' => '150', 'x_position' => '300', 'legend_x_position' => '0', 'legend_y_position' => '230', 'title_align' => 'left'));

		echo $chart;
	}
コード例 #5
0
ファイル: stats.php プロジェクト: hungnv0789/vhtm
		/**
		 * TriggerEmailsStats_View
		 * Handle listing of the trigger emails statistics
		 *
		 * @return Void Prints output directly to stdout without returning anything.
		 *
		 * @uses Stats_API::GetTriggerEmailsStats()
		 */
		function TriggerEmailsStats_View()
		{
			// ----- Sanitize and declare variables that is going to be used in this function
				$user = IEM::userGetCurrent();

				$id					= intval($this->_getGETRequest('id', ''));

				$record				= array();
				$triggerrecord		= array();

				$api				= $this->GetApi();
				$triggerapi			= $this->GetApi('TriggerEmails');

				$page = array(
					'messages'		=> GetFlashMessages(),
					'whichtab'		=> intval($this->_getGETRequest('tab', 1)),
					'unique_open'	=> ($this->_getGETRequest('Unique', false) ? true : false),
					'session_token'	=> md5(uniqid(rand()))
				);

				$tabs				= array(
					'snapshot'		=> array(),
					'open'			=> array(),
					'links'			=> array(),
					'bounces'		=> array(),
					'unsubscribe'	=> array(),
					'forward'		=> array(),
					'recipients'	=> array()
				);

			// ----

			if ($id == 0) {
				return $this->TriggerEmailsStats_List();
			}

			// Make sure that user can access this particular trigger email statistics
			if (!$this->_TriggerEmailsStats_Access($id)) {
				return $this->TriggerEmailsStats_List();
			}

			// ----- Load trigger emails statistics record
				$record = $api->GetTriggerEmailsStatsRecord($id);
				$triggerrecord = $triggerapi->GetRecordByID($id, true, true);

				if (!isset($triggerrecord['triggeractions']) || !is_array($triggerrecord['triggeractions'])) {
					$triggerrecord['triggeractions'] = array();
				}

				if (!isset($triggerrecord['triggeractions']['send']) || !is_array($triggerrecord['triggeractions']['send'])) {
					$triggerrecord['triggeractions']['send'] = array();
				}

				$temp = array('trackopens', 'tracklinks');
				foreach ($temp as $each) {
					if (!isset($triggerrecord['triggeractions']['send'][$each])) {
						$triggerrecord['triggeractions']['send'][$each] = 0;
					}
				}

				if (empty($record)) {
					return $this->TriggerEmailsStats_List();
				}
			// -----


			// Log this to "User Activity Log"
			IEM::logUserActivity($_SERVER['REQUEST_URI'], 'images/chart_bar.gif', $record['triggeremailsname']);

			// ----- Calculate some common variables for the record
				$record['processed_totalsent'] = intval($record['htmlrecipients']) + intval($record['textrecipients']) + intval($record['multipartrecipients']);
				$record['processed_unopened'] = abs($record['processed_totalsent'] - $record['emailopens_unique']);
				$record['processed_totalbounced'] = intval($record['bouncecount_soft']) + intval($record['bouncecount_hard']) + intval($record['bouncecount_unknown']);

				if ($record['processed_totalsent'] != 0) {
					if ($triggerrecord['triggeractions']['send']['trackopens'] != 0) {
						$record['processed_timeframe_emailopens_total'] = intval($api->GetOpens($record['statid'], 1, 'all', $page['unique_open'], $this->CalendarRestrictions['opens'], true));
						$record['processed_timeframe_emailopens_unique'] = intval($api->GetOpens($record['statid'], 1, 'all', $page['unique_open'], $this->CalendarRestrictions['opens'], true));
					}

					if ($triggerrecord['triggeractions']['send']['tracklinks'] != 0) {
						$record['processed_timeframe_linkclicks_total'] = intval($api->GetClicks($record['statid'], 1, 'all', 'a', $this->CalendarRestrictions['clicks'], true));
						$record['processed_timeframe_linkclicks_unique'] = intval($api->GetUniqueClicks($record['statid'], 'a', $this->CalendarRestrictions['clicks']));
						$record['processed_timeframe_linkclicks_individuals'] = intval($api->GetUniqueClickRecipients($record['statid'], $this->CalendarRestrictions['clicks'], 'a'));
					}

					$record['processed_timeframe_bounces'] = intval($api->GetBounces($record['statid'], 1, 'all', 'any', $this->CalendarRestrictions['bounces'], true));

					$record['processed_timeframe_unsubscribes'] = intval($api->GetUnsubscribes($record['statid'], 1, 'all', $this->CalendarRestrictions['unsubscribes'], true));

					if (array_key_exists('forwards', $this->CalendarRestrictions) && !empty($this->CalendarRestrictions['forwards'])) {
						$record['processed_timeframe_forwards'] = intval($api->GetForwards($record['statid'], 1, 'all', $this->CalendarRestrictions['forwards'], true));
					} else {
						$record['processed_timeframe_forwards']	= intval($record['emailforwards']);
					}

					$record['processed_timeframe_totalsent'] = 0;

					// Set up session information that correspond to the current stats (this information in the session will not be cleaned up, need to refactor)
					// The session infromation is used to print out a table that list email addressess for "open" and "link" tabs
					IEM::sessionSet($page['session_token'], array(
						'statid'				=> $record['statid'],
						'calendar_restrictions'	=> $this->CalendarRestrictions,
						'unique_open_only'		=> $page['unique_open'],
						'summary'				=> $record
					));
				}
			// -----





			// Load additional language variable for displaying trigger email statistics
			$this->LoadLanguageFile('TriggerEmails');

			// Include the charting tool
			include_once (SENDSTUDIO_FUNCTION_DIRECTORY . '/amcharts/amcharts.php');


			// ----- Tab 1: Snapshot
				$tabs['snapshot']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Snapshots_Intro'), $record['triggeremailsname']);
				$tabs['snapshot']['newsletter_uniqueopen'] = sprintf(GetLang('EmailOpens_Unique'), $this->FormatNumber($record['emailopens_unique']));
				$tabs['snapshot']['newsletter_totalopen'] = sprintf(GetLang('EmailOpens_Total'), $this->FormatNumber($record['emailopens']));
				$tabs['snapshot']['newsletter_bounce'] = $this->FormatNumber($record['processed_totalbounced']);
				$tabs['snapshot']['url_open_url'] = 'index.php?Page=Stats&Action=TriggerEmails&SubAction=view&tab=2&id=' . $id;
				$tabs['snapshot']['url_openunique_url'] = $tabs['snapshot']['url_open_url'] . '&Unique=1';

				$tabs['snapshot']['summary_chart'] = InsertChart(
					'pie',
					'stats_chart.php?Opens=' . $record['emailopens_unique'] . '&Unopened=' . $record['processed_unopened'] . '&Bounced=' . $record['processed_totalbounced'] . '&Area=TriggerEmails&'. IEM::SESSION_NAME . '=' . IEM::sessionID(),
					array('graph_title' => sprintf(GetLang('TriggerEmails_Stats_Snapshots_ChartTitle'), $record['triggeremailsname'])));
			// -----

			// ----- Tab 2: Open rates
				$tabs['open']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Open_Intro'), $record['triggeremailsname']);

				// setup calendar
				$GLOBALS['TabID'] = '1';
				$this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=2&id=' . $id);
				$tabs['open']['calendar'] = $GLOBALS['Calendar'];
				unset($GLOBALS['TabID']);
				unset($GLOBALS['Calendar']);


				// Set up error message if no "opens" count is not available
				if (!array_key_exists('processed_timeframe_emailopens_total', $record) || !$record['processed_timeframe_emailopens_total']) {
					$tempMessage = 'TriggerEmails_Stats_Open_Error_HasNotBeenOpened';
					$tempRestriction = $this->CalendarRestrictions;

					if ($triggerrecord['triggeractions']['send']['trackopens'] == 0) {
						$tempMessage = 'TriggerEmails_Stats_Open_Error_NotOpenTracked';
					} elseif (array_key_exists('opens', $tempRestriction) && !empty($tempRestriction['opens'])) {
						$tempMessage = 'TriggerEmails_Stats_Open_Error_HasNotBeenOpened_CalendarProblem';
					}

					$GLOBALS['Error'] = GetLang($tempMessage);
					$tabs['open']['message'] = $this->ParseTemplate('ErrorMsg', true, false);
					unset($GLOBALS['Error']);


				// Set up open information otherwise
				} else {
					$tabs['open']['email_opens_total'] = $this->FormatNumber($record['processed_timeframe_emailopens_total']);
					$tabs['open']['email_opens_unique'] = $this->FormatNumber($record['processed_timeframe_emailopens_unique']);

					// ----- Most opens
						$tempMostOpens = $api->GetMostOpens($record['statid'], $this->CalendarRestrictions['opens']);
						$tempNow = getdate();

						if (isset($tempMostOpens['mth'])) {
							$tabs['open']['most_open_date'] = $this->Months[$tempMostOpens['mth']] . ' ' . $tempMostOpens['yr'];

						} elseif (isset($tempMostOpens['hr'])) {
							$tabs['open']['most_open_date'] = date(GetLang('Daily_Time_Display'),mktime($tempMostOpens['hr'], 1, 1, 1, 1, $tempNow['year']));

						} elseif (isset($tempMostOpens['dow'])) {
							$pos = array_search($tempMostOpens['dow'], array_keys($this->days_of_week));
							$tabs['open']['most_open_date'] = date(GetLang('Date_Display_Display'), strtotime("last " . $this->days_of_week[$pos]));

						} elseif (isset($tempMostOpens['dom'])) {
							$month = $tempNow['mon'];
							// if the day-of-month is after "today", it's going to be for "last month" so adjust the month accordingly.
							if ($tempMostOpens['dom'] > $tempNow['mday']) {
								$month = $tempNow['mon'] - 1;
							}

							$tabs['open']['most_open_date'] = date(GetLang('Date_Display_Display'),mktime(0, 0, 1, $month, $tempMostOpens['dom'], $tempNow['year']));
						}

						unset($tempNow);
						unset($tempMostOpens);
					// -----

					// ----- Average opens
						$tabs['open']['average_opens'] = 0;
						if ($record['processed_totalsent'] > 0) {
							$tempAverage = $record['processed_timeframe_emailopens_total'] / $record['processed_totalsent'];
							$tabs['open']['average_opens'] = $this->FormatNumber($tempAverage, 3);
							unset($tempAverage);
						}
					// -----

					// ----- Open rate
						$tabs['open']['open_rate'] = '0%';
						if ($record['processed_totalsent'] > 0) {
							$tempOpenRate = $record['processed_timeframe_emailopens_unique'] / $record['processed_totalsent'] * 100;
							$tabs['open']['open_rate'] = $this->FormatNumber($tempOpenRate, 2) . '%' ;
							unset($tempOpenRate);
						}
					// -----

					// Setup chart
					$this->DisplayChart('OpenChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('OpensChart')));
					$tabs['open']['open_chart'] = $GLOBALS['OpenChart'];
					unset($GLOBALS['OpenChart']);
				}
			// -----

			// ----- Tab 3: Links (TODO: when user chooses a specific link. Currently this is being ignored)
				$tabs['links']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Links_Intro'), $record['triggeremailsname']);

				// setup calendar
				$GLOBALS['TabID'] = '2';
				$this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=3&id=' . $id);
				$tabs['links']['calendar'] = $GLOBALS['Calendar'];
				unset($GLOBALS['TabID']);
				unset($GLOBALS['Calendar']);

				// Set up error message if no "links" count is not available
				if (!array_key_exists('processed_timeframe_linkclicks_total', $record) || !$record['processed_timeframe_linkclicks_total']) {
					$tempMessage = 'TriggerEmails_Stats_Links_Error_NoLinksFound';
					$tempRestriction = $this->CalendarRestrictions;

					if ($triggerrecord['triggeractions']['send']['tracklinks'] == 0) {
						$tempMessage = 'TriggerEmails_Stats_Links_Error_NotLinkTracked';
					} elseif (array_key_exists('clicks', $tempRestriction) && !empty($tempRestriction['clicks'])) {
						$tempMessage = 'TriggerEmails_Stats_Links_Error_NoLinksFound_CalendarProblem';
					}

					$GLOBALS['Error'] = GetLang($tempMessage);
					$tabs['links']['message'] = $this->ParseTemplate('ErrorMsg', true, false);
					unset($GLOBALS['Error']);


				// Set up open information otherwise
				} else {
					$tabs['links']['linkclicks_total'] = $this->FormatNumber($record['processed_timeframe_linkclicks_total']);
					$tabs['links']['linkclicks_unique'] = $this->FormatNumber($record['processed_timeframe_linkclicks_unique']);
					$tabs['links']['linkclicks_individuals'] = $this->FormatNumber($record['processed_timeframe_linkclicks_individuals']);

					// ----- Most popular
						$most_popular_link = $api->GetMostPopularLink($record['statid'], 'a', $this->CalendarRestrictions['clicks']);
						$most_popular_link = htmlspecialchars($most_popular_link, ENT_QUOTES, SENDSTUDIO_CHARSET);

						$tabs['links']['most_popular_link'] = $most_popular_link;
						$tabs['links']['most_popular_link_short'] = $this->TruncateName($most_popular_link, 20);

						unset($most_popular_link);
					// -----

					// ----- Average clicks per-email-opens
						$tabs['links']['average_clicks'] = '0';
						if ($record['emailopens'] > 0) {
							$tabs['links']['average_clicks'] = $this->FormatNumber(($record['linkclicks'] / $record['emailopens']), 3);
						}
					// -----

					// ----- Clickthrough rate
						$tabs['links']['click_through'] = '0%';
						if ($record['processed_totalsent'] > 0) {
							$tempClickThroughRate = $record['processed_timeframe_linkclicks_unique'] / $record['processed_totalsent'] * 100;
							$tabs['links']['click_through'] = $this->FormatNumber($tempClickThroughRate, 2) . '%';
							unset($tempClickThroughRate);
						}
					// -----

					// Setup chart
					$this->DisplayChart('LinksChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('LinksClickedChart')));
					$tabs['links']['link_chart'] = $GLOBALS['LinksChart'];
					unset($GLOBALS['LinksChart']);
				}
			// -----

			// ----- Tab 4: Bounces (TODO: Cannot filter the bounce under soft/hard)
				$tabs['bounces']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Bounces_Intro'), $record['triggeremailsname']);

				// setup calendar
				$GLOBALS['TabID'] = '3';
				$this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=4&id=' . $id);
				$tabs['bounces']['calendar'] = $GLOBALS['Calendar'];
				unset($GLOBALS['TabID']);
				unset($GLOBALS['Calendar']);

				// Set up error message if no "bounces" count is not available
				if (!array_key_exists('processed_timeframe_bounces', $record) || !$record['processed_timeframe_bounces']) {
					$tempMessage = 'TriggerEmails_Stats_Bounces_Error_NoBouncesFound';
					$tempRestriction = $this->CalendarRestrictions;

					if (array_key_exists('clicks', $tempRestriction) && !empty($tempRestriction['clicks'])) {
						$tempMessage = 'TriggerEmails_Stats_Links_Error_NoLinksFound_CalendarProblem';
					}

					$GLOBALS['Error'] = GetLang($tempMessage);
					$tabs['bounces']['message'] = $this->ParseTemplate('ErrorMsg', true, false);
					unset($GLOBALS['Error']);


				// Set up open information otherwise
				} else {
					$tabs['bounces']['bounces_total'] = $this->FormatNumber($record['processed_totalbounced']);
					$tabs['bounces']['bounces_soft'] = $this->FormatNumber(intval($record['bouncecount_soft']));
					$tabs['bounces']['bounces_hard'] = $this->FormatNumber(intval($record['bouncecount_hard']));
					$tabs['bounces']['bounces_unknown'] = $this->FormatNumber(intval($record['bouncecount_unknown']));

					// Setup chart
					$this->DisplayChart('BounceChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('BounceChart')));
					$tabs['bounces']['bounce_chart'] = $GLOBALS['BounceChart'];
					unset($GLOBALS['BounceChart']);
				}
			// -----

			// ----- Tab 5: Unsubscribe
				$tabs['unsubscribes']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Unsubscribes_Intro'), $record['triggeremailsname']);

				// setup calendar
				$GLOBALS['TabID'] = '4';
				$this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=5&id=' . $id);
				$tabs['unsubscribes']['calendar'] = $GLOBALS['Calendar'];
				unset($GLOBALS['TabID']);
				unset($GLOBALS['Calendar']);

				// Set up error message if no "unsubscribes" count is not available
				if (!array_key_exists('processed_timeframe_unsubscribes', $record) || !$record['processed_timeframe_unsubscribes']) {
					$tempMessage = 'TriggerEmails_Stats_Unsubscribes_Error_NoUnsubscribesFound';
					$tempRestriction = $this->CalendarRestrictions;

					if (array_key_exists('bounces', $tempRestriction) && !empty($tempRestriction['bounces'])) {
						$tempMessage = 'TriggerEmails_Stats_Unsubscribes_Error_NoUnsubscribesFound_CalendarProblem';
					}

					$GLOBALS['Error'] = GetLang($tempMessage);
					$tabs['unsubscribes']['message'] = $this->ParseTemplate('ErrorMsg', true, false);
					unset($GLOBALS['Error']);


				// Set up open information otherwise
				} else {
					$tabs['unsubscribes']['unsubscribes_total'] = $this->FormatNumber($record['processed_timeframe_unsubscribes']);

					// ----- Most unsubscribe
						$tempMostUnsubscribes = $api->GetMostUnsubscribes($record['statid'], $this->CalendarRestrictions['unsubscribes']);
						$tempNow = getdate();

						if (isset($tempMostUnsubscribes['mth'])) {
							$tabs['unsubscribes']['unsubscribes_most'] = $this->Months[$tempMostUnsubscribes['mth']] . ' ' . $tempMostUnsubscribes['yr'];

						} elseif (isset($tempMostUnsubscribes['hr'])) {
							$tabs['unsubscribes']['unsubscribes_most'] = $this->PrintDate(mktime($tempMostUnsubscribes['hr'], 1, 1, 1, 1, $tempNow['year']), GetLang('Daily_Time_Display'));

						} elseif (isset($tempMostUnsubscribes['dow'])) {
							$pos = array_search($tempMostUnsubscribes['dow'], array_keys($this->days_of_week));
							// we need to add 1 hour here otherwise we get the wrong day from strtotime.
							$tabs['unsubscribes']['unsubscribes_most'] = $this->PrintDate(strtotime("last " . $this->days_of_week[$pos] . " +1 hour"), GetLang('Date_Display_Display'));

						} elseif (isset($tempMostUnsubscribes['dom'])) {
							$month = $tempNow['mon'];
							// if the day-of-month is after "today", it's going to be for "last month" so adjust the month accordingly.
							if ($tempMostUnsubscribes['dom'] > $tempNow['mday']) {
								$month = $tempNow['mon'] - 1;
							}

							$tabs['unsubscribes']['unsubscribes_most'] = $this->PrintDate(mktime(0, 0, 1, $month, $tempMostUnsubscribes['dom'], $tempNow['year']), GetLang('Date_Display_Display'));
						}

						unset($tempNow);
						unset($tempMostUnsubscribes);
					// -----

					// Setup chart
					$this->DisplayChart('UnsubscribeChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('UnsubscribesChart')));
					$tabs['unsubscribes']['unsubscribe_chart'] = $GLOBALS['UnsubscribeChart'];
					unset($GLOBALS['UnsubscribeChart']);
				}
			// -----

			// ----- Tab 6: Forwards
				$tabs['forwards']['intro'] = sprintf(GetLang('TriggerEmails_Stats_Forwards_Intro'), $record['triggeremailsname']);

				// setup calendar
				$GLOBALS['TabID'] = '5';
				$this->SetupCalendar('Action=ProcessCalendar&SubAction=TriggerEmails&NextAction=View&tab=6&id=' . $id);
				$tabs['forwards']['calendar'] = $GLOBALS['Calendar'];
				unset($GLOBALS['TabID']);
				unset($GLOBALS['Calendar']);

				// Set up error message if no "forwards" count is not available
				if (!array_key_exists('processed_timeframe_forwards', $record) || !$record['processed_timeframe_forwards']) {
					$tempMessage = 'TriggerEmails_Stats_Forwards_Error_NoForwardFound';
					$tempRestriction = $this->CalendarRestrictions;

					if (array_key_exists('forwards', $tempRestriction) && !empty($tempRestriction['forwards'])) {
						$tempMessage = 'TriggerEmails_Stats_Forwards_Error_NoForwardFound_CalendarProblem';
					}

					$GLOBALS['Error'] = GetLang($tempMessage);
					$tabs['forwards']['message'] = $this->ParseTemplate('ErrorMsg', true, false);
					unset($GLOBALS['Error']);


				// Set up open information otherwise
				} else {
					$tabs['forwards']['forward_total'] = $this->FormatNumber($record['processed_timeframe_forwards']);

					// ----- Total new Signups
						$temp = intval($api->GetForwards($record['statid'], 1, 'all', $this->CalendarRestrictions['forwards'], true, true));
						$tabs['forwards']['forward_signups'] = $this->FormatNumber($temp);
						unset($temp);
					// -----

					// Setup chart
					$this->DisplayChart('ForwardsChart', 'triggeremails', $record['statid'], 'column', array('graph_title' => GetLang('ForwardsChart')));
					$tabs['forwards']['forwards_chart'] = $GLOBALS['ForwardsChart'];
					unset($GLOBALS['ForwardsChart']);
				}
			// -----

			// ----- Tab 7: Contact info
				$tabs['recipients'] = $this->_TriggerEmailsStats_View_Tab7($record);
			// -----

			// ----- Tab 8: Failed sending info
				$tabs['failed'] = $this->_TriggerEmailsStats_View_Tab8($record);
			// -----



			// ----- Print HTML
				$tpl = GetTemplateSystem();
				$tpl->Assign('PAGE', $page);
				$tpl->Assign('record', $record);
				$tpl->Assign('tabs', $tabs);

				return $tpl->ParseTemplate('Stats_Triggeremails_Summary', true);
			// -----
		}
コード例 #6
0
ファイル: splittest_stats.php プロジェクト: hungnv0789/vhtm
 /**
  * generateCharts
  * Generates charts for summary, open, click, bounce and unsubscribe stats.
  *
  * @param String $splitname The name of the split test.
  * @param String $campaigns Campaign data for the split test.
  * @param String $subaction Can be 'print' to insert images instead of flash charts.
  *
  * @return Array The chart data to output.
  */
 protected function generateCharts($splitname, $campaigns, $subaction = null)
 {
     require_once SENDSTUDIO_BASE_DIRECTORY . '/functions/amcharts/amcharts.php';
     $stats_api = $this->GetApi('Splittest_Stats');
     $statsChartUrl = SENDSTUDIO_APPLICATION_URL . '/admin/stats_chart.php?graph=custom_bar&' . IEM::SESSION_NAME . '=' . IEM::sessionID() . '&';
     $chartType = 'column';
     $summaryDataURL = $statsChartUrl . $stats_api->barChartSummaryDataURL($campaigns, 'Opens,Clicks,Bounces,Unsubscribes');
     $charts = array();
     $charts['summary_chart'] = self::InsertChartImage('SplittestSummaryChart', $summaryDataURL, array('graph_title' => sprintf(GetLang('Addon_splittest_Stats_Summary'), $splitname)), $subaction);
     // Splittest Sumamry Open Rate Chart
     $openrateDataURL = $statsChartUrl . $stats_api->barChartDataURL($campaigns, 'emailopens_unique', true, true, true);
     $charts['openrate_chart'] = self::InsertChartImage('SplittestOpenChart', $openrateDataURL, array('graph_title' => sprintf(GetLang('Addon_splittest_Stats_Total_UniqueOpens'), $splitname)), $subaction);
     // Splittest Sumamry Link Clicks Chart
     $linkclicksDataURL = $statsChartUrl . $stats_api->barChartDataURL($campaigns, 'linkclicks', true, true, true);
     $charts['clickrate_chart'] = self::InsertChartImage('SplittestLinkChart', $linkclicksDataURL, array('graph_title' => sprintf(GetLang('Addon_splittest_Stats_Total_LinkClicks'), $splitname)), $subaction);
     // Splittest Bounce Count Chart
     $bounceDataURL = $statsChartUrl . $stats_api->barChartDataURL($campaigns, 'bouncecount_total', true, true);
     $charts['bouncerate_chart'] = self::InsertChartImage('SplittestBounceChart', $bounceDataURL, array('graph_title' => sprintf(GetLang('Addon_splittest_Stats_Total_Bounces'), $splitname)), $subaction);
     // Splittest Unsubscribe Count Chart
     $unsubscribeDataURL = $statsChartUrl . $stats_api->barChartDataURL($campaigns, 'unsubscribecount', true, true);
     $charts['unsubscribes_chart'] = self::InsertChartImage('SplittestUnsubscribeChart', $unsubscribeDataURL, array('graph_title' => sprintf(GetLang('Addon_splittest_Stats_Total_Unsubscribes'), $splitname)), $subaction);
     return $charts;
 }