<?php
/**
 * ###############################################
 *
 * SWIFT Framework
 * _______________________________________________
 *
 * @author		Varun Shoor
 *
 * @package		SWIFT
 * @copyright	Copyright (c) 2001-2012, Kayako
 * @license		http://www.kayako.com/license
 * @link		http://www.kayako.com
 *
 * ###############################################
 */

/**
 * The Dashboard View
 *
 * @author Varun Shoor
 */
class View_Home extends SWIFT_View
{
	private $_infoClass = '2';

	/**
	 * Constructor
	 *
	 * @author Varun Shoor
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function __construct()
	{
		parent::__construct();

		return true;
	}

	/**
	 * Destructor
	 *
	 * @author Varun Shoor
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function __destruct()
	{
		parent::__destruct();

		return true;
	}

	/**
	 * Render the Error HTML
	 *
	 * @author Varun Shoor
	 * @param string $_title The Box Title
	 * @param string $_contents The Box Contents
	 * @param string $_date The Date Row Data
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderError($_title, $_contents, $_date = '')
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		} else if (empty($_title) || empty($_contents)) {
			return false;
		}

		return '<div class="dashboardboxerror"><div class="dashboardboxtitlecontainer"><div class="dashboardboxtitle">' . $_title . '</div><div class="dashboardboxdate">' . $_date . '</div></div>' . $_contents . '</div>';
	}

	/**
	 * Render the Alert HTML
	 *
	 * @author Varun Shoor
	 * @param string $_title The Box Title
	 * @param string $_contents The Box Contents
	 * @param string $_date The Date Row Data
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderAlert($_title, $_contents, $_date = '')
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		} else if (empty($_title) || empty($_contents)) {
			return false;
		}

		return '<div class="dashboardboxalert"><div class="dashboardboxtitlecontainer"><div class="dashboardboxtitle">' . $_title . '</div><div class="dashboardboxdate">' . $_date . '</div></div>' . $_contents . '</div>';
	}

	/**
	 * Renders the Info HTML
	 *
	 * @author Varun Shoor
	 * @param string $_title The Box Title
	 * @param string $_contents The Box Contents
	 * @param string $_date The Date Row Data
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderInfo($_title, $_contents, $_date = '')
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		} else if (empty($_title) || empty($_contents)) {
			return false;
		}

		if ($this->_infoClass == '1')
		{
			$this->_infoClass = '2';
		} else {
			$this->_infoClass = '1';
		}

		return '<div class="dashboardboxinfo' . $this->_infoClass . '"><div class="dashboardboxtitlecontainer"><div class="dashboardboxtitle">' . $_title . '</div><div class="dashboardboxdate">' . $_date . '</div></div>' . $_contents . '</div>';
	}

	/**
	 * Renders the Dashboard
	 *
	 * @author Varun Shoor
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderDashboard($_counterContainer = array())
	{
		$_SWIFT = SWIFT::GetInstance();

		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		$_staffLastVisit = $_SWIFT->Staff->GetProperty('lastvisit');
		if (empty($_staffLastVisit))
		{
			$_lastVisit = $this->Language->Get('never');
		} else {
			$_lastVisit = SWIFT_Date::Get(SWIFT_Date::TYPE_DATETIME, $_SWIFT->Staff->GetProperty('lastvisit'));
		}

		$_staffDesignation = $_SWIFT->Staff->GetProperty('designation');
		$_designationExtended = '';

		if (!empty($_staffDesignation))
		{
			$_designationExtended = ' (' . htmlspecialchars($_staffDesignation) . ')';
		}

		echo '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="dashboardlayoutborder" style="margin-top: 0;">
		<tr>
		<td align="left" valign="bottom" id="dashboardcontainer">
		<div id="dashboardtitle">'. $this->Language->Get('dashdashboard') . '</div>
		</td>
		</tr>
		<tr><td align="left" valign="top">

		<div style="PADDING: 8px;">

		<!-- BEGIN FIRST ROW (DATE, USERDETAILS) -->
		<table width="100%" border="0" cellspacing="1" cellpadding="0">
		<tr>
		<td align="left" valign="top" width="">

		<div style="display: inline-block; float: right;">';

		echo $this->RenderCounters($_counterContainer);

		echo '</div>

			<div style="float: left; padding-left: 8px;">
			<table width="100%" border="0" cellspacing="1" cellpadding="0">
			<tr>
			<td align="left" valign="middle" width="80">
			<div class="dashboardavatarimage">
			<img src="' . SWIFT::Get('basename') . '/Base/StaffProfile/DisplayAvatar/' . $_SWIFT->Staff->GetStaffID() . '/' . md5($_SWIFT->Staff->GetProperty('email')) . '/80/0" align="absmiddle" />
			</div>
			</td>
			<td align="left" valign="top" width=""><div class="dashboardrightcontents"><div class="dashboardusername">' . htmlspecialchars($_SWIFT->Staff->GetProperty('fullname')) . '</div>
			<div class="smalltext">' . $this->Language->Get('dashusername') . ' ' . htmlspecialchars($_SWIFT->Staff->GetProperty('username')) . '<br />
			' . $this->Language->Get('dashemail') . ' ' . htmlspecialchars($_SWIFT->Staff->GetProperty('email')) . '<br />
			' . $this->Language->Get('dashlastlogin') . ' ' . $_lastVisit . '<br /></div></div>
			</td>
			</tr>
			</table>
			</div>
		</td>
		<td align="left" valign="top" width="300">

		<div style="float: right;">
		<table width="100%" border="0" cellspacing="1" cellpadding="0">
		<tr>
		<td align="left" valign="top" width="80">
			<div class="dashboarddate">
				<div class="dashboarddatecontainer">
				<div class="dashboardmonthholder"><div class="dashboardmonthsub">' . SWIFT_Date::Get(SWIFT_Date::TYPE_CUSTOM, false, '%b') .'</div></div>
				<div class="dashboarddateholder"><div class="dashboarddatesub">' . SWIFT_Date::Get(SWIFT_Date::TYPE_CUSTOM, false, '%A') . '</div><div class="dashboarddatedcontainer">' . SWIFT_Date::Get(SWIFT_Date::TYPE_CUSTOM, false, '%d') . '</div></div>
				</div>
			</div>
		</td>
		</tr></table>
		</div>

		</td>
		</tr></table>
		<!-- END FIRST ROW -->

		<!-- BEGIN SECOND ROW -->
		<table width="100%" border="0" cellspacing="1" cellpadding="4">
		<tr>
		<td align="left" valign="top" width="">
		<div id="dashboardtabs"><ul>';

		$_tabContainer = $this->Controller->_GetTabContainer();

		$_tabHTML = '';
		if (_is_array($_tabContainer))
		{
			foreach ($_tabContainer as $_key => $_val)
			{
				echo '<li><a href="#dashboardtabs-' . $_val[Controller_Home::TAB_NAME] . '">' . IIF(!empty($_val[Controller_Home::TAB_COUNTER]), '<div class="notecounterredver">' . $_val[Controller_Home::TAB_COUNTER] . '</div>') . '<img src="' . SWIFT::Get('themepath') . 'images/' . $_val[Controller_Home::TAB_ICON] . '' . '" align="absmiddle" border="0" /> ' . $_val[Controller_Home::TAB_TITLE] . '</a></li>';

				$_tabHTML .= '<div id="dashboardtabs-' . $_val[Controller_Home::TAB_NAME] . '"><div class="ui-tabs-vertical-custom-prop"></div>';

				$_tabHTML .= $_val[Controller_Home::TAB_CONTENTS];

				$_tabHTML .= '<div class="ui-tabs-vertical-custom-clear"></div></div>';
			}
		}

		echo '</ul>';

		echo $_tabHTML;

		echo '</div>
		</td>
		';

		if (SWIFT_App::IsInstalled(APP_TICKETS))
		{
			$_departmentProgressContainer = SWIFT_TicketViewRenderer::GetDashboardDepartmentProgress();
			$_ownerProgressContainer = SWIFT_TicketViewRenderer::GetDashboardOwnerProgress();
			$_statusProgressContainer = SWIFT_TicketViewRenderer::GetDashboardStatusProgress();
			$_typeProgressContainer = SWIFT_TicketViewRenderer::GetDashboardTypeProgress();
			$_priorityProgressContainer = SWIFT_TicketViewRenderer::GetDashboardPriorityProgress();

			$_showBar = false;
			if (count($_departmentProgressContainer) || count($_statusProgressContainer) || count($_typeProgressContainer) || count($_priorityProgressContainer))
			{
				$_showBar = true;
			}

			if ($_showBar) {
				echo '<td align="left" valign="top" width="250">';
				/*
				 * ##########################################################################
				 * Live chat tag for trial licenses
				 * ##########################################################################
				 */
				if (SWIFT::Get('licenseistrial') == 1) {
					echo '<div class="kayakochatbuttoncontainer">
						<table align="center">
							<tr>
								<td align="center" valign="middle">
									' . $this->Language->Get('chatwithkayako') . '
								</td>
								<td>
									<!-- BEGIN TAG CODE - DO NOT EDIT! --><div><div id="proactivechatcontainer83acjjnu4e"></div><table border="0" cellspacing="2" cellpadding="2"><tr><td align="center" id="swifttagcontainer83acjjnu4e"><div style="display: inline;" id="swifttagdatacontainer83acjjnu4e"></div><a target="_blank" href="https://support.kayako.com/visitor/index.php?/default/LiveChat/Chat/Request/_sessionID=/_promptType=chat/_proactive=0/_filterDepartmentID=/_randomNumber=nlz6vk15winiik35co8j1k51i4x48k6y/_fullName=/_email=/" class="livechatlink"><img src="https://support.kayako.com/visitor/index.php?/default/LiveChat/HTML/NoJSImage/cHJvbXB0dHlwZT1jaGF0JnVuaXF1ZWlkPTgzYWNqam51NGUmdmVyc2lvbj00LjY3LjAmcHJvZHVjdD1GdXNpb24mY3VzdG9tb25saW5lPSZjdXN0b21vZmZsaW5lPSZjdXN0b21hd2F5PSZjdXN0b21iYWNrc2hvcnRseT0KM2FmMjM4OGZmMDE5OWU4ZjA4MzQ1OTM2MWZjNWI0ODk5ZWE0NzZkZg==" align="absmiddle" border="0" /></a></td> </tr></table></div><!-- END TAG CODE - DO NOT EDIT! -->
								</td>
							</tr>
						</table>
				 	</div>';
				}

				echo '<div class="tabparent">
	<ul class="tab">
		<li>
			<a href="javascript:void(0);" class="currenttab">
			<span>
			<div class="dashboardoverviewtab">' . $this->Language->Get('overview') . '</div>
			</span>
			</a>
		</li>
	</ul>
<div class="basictabcontent stats">
<table width="100%" cellspacing="1" cellpadding="4" border="0">
<tbody>
<tr>
<td class="gridrow2 stats" valign="top" align="left">

';
				if (count($_departmentProgressContainer))
				{
					echo '<div class="dashboardprogresscontainer">';
					echo '<table class="hlineheader"><tr><th rowspan="2" nowrap>' . $this->Language->Get('dashdepartmentprogress') . '</th><td>&nbsp;</td></tr><tr><td class="hlinelower">&nbsp;</td></tr></table>';
					echo $this->RenderProgress($_departmentProgressContainer);
					echo '</div>';
				}

				if (count($_statusProgressContainer))
				{
					echo '<div class="dashboardprogresscontainer">';
					echo '<table class="hlineheader"><tr><th rowspan="2" nowrap>' . $this->Language->Get('dashstatusprogress') . '</th><td>&nbsp;</td></tr><tr><td class="hlinelower">&nbsp;</td></tr></table>';
					echo $this->RenderProgress($_statusProgressContainer, true);
					echo '</div>';
				}

				if (count($_typeProgressContainer))
				{
					echo '<div class="dashboardprogresscontainer">';
					echo '<table class="hlineheader"><tr><th rowspan="2" nowrap>' . $this->Language->Get('dashtypeprogress') . '</th><td>&nbsp;</td></tr><tr><td class="hlinelower">&nbsp;</td></tr></table>';
					echo $this->RenderProgress($_typeProgressContainer, true);
					echo '</div>';
				}

				if (count($_priorityProgressContainer))
				{
					echo '<div class="dashboardprogresscontainer">';
					echo '<table class="hlineheader"><tr><th rowspan="2" nowrap>' . $this->Language->Get('dashpriorityprogress') . '</th><td>&nbsp;</td></tr><tr><td class="hlinelower">&nbsp;</td></tr></table>';
					echo $this->RenderProgress($_priorityProgressContainer, true);
					echo '</div>';
				}

				if (count($_ownerProgressContainer))
				{
					echo '<div class="dashboardprogresscontainer">';
					echo '<table class="hlineheader"><tr><th rowspan="2" nowrap>' . $this->Language->Get('dashownerprogress') . '</th><td>&nbsp;</td></tr><tr><td class="hlinelower">&nbsp;</td></tr></table>';
					echo $this->RenderProgress($_ownerProgressContainer);
					echo '</div>';
				}

				echo '</td></tr>
				</tbody>
				</table>
				</div></div></td>';
			}
		}

		echo '</tr>
		</table>
		<!-- END SECOND ROW -->

		<script type="text/javascript">
		QueueFunction(function() {
			$("#dashboardtabs").tabs().addClass(\'ui-tabs-vertical ui-helper-clearfix\').removeClass(\'ui-corner-all ui-widget-content\');
			$("#dashboardtabs li").removeClass(\'ui-corner-top\').addClass(\'ui-corner-left\');
		});

		$(function() {
			ClearFunctionQueue();
		});
		</script>

		</div></td></tr></table>
		<div id="klic"></div>
		';
	}

	/**
	 * Render the Chat Tab View
	 *
	 * @author Varun Shoor
	 * @param array $_chatObjectContainer The Chat Object Container
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderRecentChatTabView($_chatObjectContainer)
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		$_showingSuffix = '';
		if (count($_chatObjectContainer[1]))
		{
			$_showingSuffix = sprintf($this->Language->Get('showingmsg'), count($_chatObjectContainer[1]), $_chatObjectContainer[0]);
		}

		$_tabContents = '<div>';

		$_tabContents .= $this->RenderTabHeader($this->Language->Get('tabrecentchats') . $_showingSuffix, '/LiveChat/ChatHistory/Manage');

		$_tabContents .= '<div class="dashboardtabdatacontainer">';

		if (!_is_array($_chatObjectContainer[1]))
		{
			$_tabContents .= '<div class="dashboardmsg">' . $this->Language->Get('noinfoinview') . '</div>';
		} else {

			$_rowClass = 'gridrow1';

			$_tabContents .= '<div class="gridcontentborder"><table cellspacing="1" cellpadding="4" border="0" width="100%">';
			$_tabContents .= '<tr class="gridtabletitlerow">
	<td class="gridtabletitlerow" width="20" valign="middle" align="center"> </td>
	<td class="gridtabletitlerow" width="100" valign="middle" align="left">' . $this->Language->Get('lcchatid') . '</td>
	<td class="gridtabletitlerow" valign="middle" align="left">' . $this->Language->Get('lcfullname') . '</td>
	<td class="gridtabletitlerow" width="160" valign="middle" align="left">' . $this->Language->Get('lcstaff') . '</td>
	<td class="gridtabletitlerow" width="160" valign="middle" align="left">' . $this->Language->Get('lcdepartment') . '</td>
	</tr>';
			if (_is_array($_chatObjectContainer[1]))
			{
				foreach ($_chatObjectContainer[1] as $_key => $_val)
				{
					if ($_rowClass == 'gridrow1')
					{
						$_rowClass = 'gridrow2';
					} else {
						$_rowClass = 'gridrow1';
					}

					$_chatLink = SWIFT::Get('basename') . '/LiveChat/ChatHistory/ViewChat/' . intval($_val['chatobjectid']);

					$_tabContents .= '<tr class="' . $_rowClass . '"><td class="' . $_rowClass . '" valign="middle" align="center"><img src="' . SWIFT::Get('themepathimages') . 'icon_chatballoon.png' . '" align="absmiddle" border="0" /></td><td class="' . $_rowClass . '" valign="middle" align="left"><a href="' . $_chatLink . '" viewport="1">' . htmlspecialchars($_val['chatobjectmaskid']) . '</a></td><td class="' . $_rowClass . '" valign="middle" align="left"><a href="' . $_chatLink . '" viewport="1">' . htmlspecialchars($_val['userfullname']) . '</a></td><td class="' . $_rowClass . '" valign="middle" align="left">' . htmlspecialchars($_val['staffname']) . '</td><td class="' . $_rowClass . '" valign="middle" align="left">' . htmlspecialchars($_val['departmenttitle']) . '</td></tr>';

				}
			}
			$_tabContents .= '</table></div>';

		}

		$_tabContents .= '</div>';
		$_tabContents .= '</div>';


		return $_tabContents;
	}

	/**
	 * Render the Message Tab View
	 *
	 * @author Varun Shoor
	 * @param array $_messageContainer The Message Container
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderRecentMessageTabView($_messageContainer)
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		$_departmentCache = $this->Cache->Get('departmentcache');


		$_showingSuffix = '';
		if (count($_messageContainer[1]))
		{
			$_showingSuffix = sprintf($this->Language->Get('showingmsg'), count($_messageContainer[1]), $_messageContainer[0]);
		}

		$_tabContents = '<div>';

		$_tabContents .= $this->RenderTabHeader($this->Language->Get('tabrecentmessages') . $_showingSuffix, '/LiveChat/Message/Manage');

		$_tabContents .= '<div class="dashboardtabdatacontainer">';

		if (!_is_array($_messageContainer[1]))
		{
			$_tabContents .= '<div class="dashboardmsg">' . $this->Language->Get('noinfoinview') . '</div>';
		} else {

			$_rowClass = 'gridrow1';

			$_tabContents .= '<div class="gridcontentborder"><table cellspacing="1" cellpadding="4" border="0" width="100%">';
			$_tabContents .= '<tr class="gridtabletitlerow">
	<td class="gridtabletitlerow" width="20" valign="middle" align="center"> </td>
	<td class="gridtabletitlerow" width="100" valign="middle" align="left">' . $this->Language->Get('lcmessageid') . '</td>
	<td class="gridtabletitlerow" valign="middle" align="left">' . $this->Language->Get('lcsubject') . '</td>
	<td class="gridtabletitlerow" width="160" valign="middle" align="center">' . $this->Language->Get('lcfullname') . '</td>
	<td class="gridtabletitlerow" width="160" valign="middle" align="center">' . $this->Language->Get('lcdepartment') . '</td>
	</tr>';
			if (_is_array($_messageContainer[1]))
			{
				foreach ($_messageContainer[1] as $_key => $_val)
				{
					if ($_rowClass == 'gridrow1')
					{
						$_rowClass = 'gridrow2';
					} else {
						$_rowClass = 'gridrow1';
					}

					$_messageLink = SWIFT::Get('basename') . '/LiveChat/Message/ViewMessage/' . intval($_val['messageid']);

					if ($_val['messagetype'] == SWIFT_MessageManager::MESSAGE_CLIENT || $_val['messagetype'] == SWIFT_MessageManager::MESSAGE_STAFF)
					{
						$_messageIcon = 'icon_email.gif';
					} else if ($_val['messagetype'] == SWIFT_MessageManager::MESSAGE_CLIENTSURVEY) {
						$_messageIcon = 'icon_survey.gif';
					} else {
						$_messageIcon = 'icon_email.gif';
					}

					$_departmentTitle = $this->Language->Get('na');
					if (isset($_departmentCache[$_val['departmentid']]))
					{
						$_departmentTitle = $_departmentCache[$_val['departmentid']]['title'];
					}

					$_tabContents .= '<tr class="' . $_rowClass . '"><td class="' . $_rowClass . '" valign="middle" align="center"><img src="' . SWIFT::Get('themepathimages') . $_messageIcon . '" align="absmiddle" border="0" /></td><td class="' . $_rowClass . '" valign="middle" align="left"><a href="' . $_messageLink . '" viewport="1">' . htmlspecialchars($_val['messagemaskid']) . '</a></td><td class="' . $_rowClass . '" valign="middle" align="left"><a href="' . $_messageLink . '" viewport="1">' . htmlspecialchars($_val['subject']) . '</a></td><td class="' . $_rowClass . '" valign="middle" align="center">' . htmlspecialchars($_val['fullname']) . '</td><td class="' . $_rowClass . '" valign="middle" align="center">' . htmlspecialchars($_departmentTitle) . '</td></tr>';

				}
			}
			$_tabContents .= '</table></div>';

		}

		$_tabContents .= '</div>';
		$_tabContents .= '</div>';


		return $_tabContents;
	}

	/**
	 * Render the Overdue Tickets View
	 *
	 * @author Varun Shoor
	 * @param array $_ticketsContainer The Tickets Container
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderOverdueTicketsTabView($_ticketsContainer)
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		$_departmentCache = $this->Cache->Get('departmentcache');
		$_ticketStatusCache = $this->Cache->Get('statuscache');
		$_ticketPriorityCache = $this->Cache->Get('prioritycache');
		$_ticketTypeCache = $this->Cache->Get('tickettypecache');
		$_staffCache = $this->Cache->Get('staffcache');

		$_showingSuffix = '';
		if (count($_ticketsContainer[1]))
		{
			$_showingSuffix = sprintf($this->Language->Get('showingmsg'), count($_ticketsContainer[1]), $_ticketsContainer[0]);
		}

		$_tabContents = '<div>';

		$_tabContents .= $this->RenderTabHeader($this->Language->Get('taboverduetickets') . $_showingSuffix, '/Tickets/Search/Overdue');

		$_tabContents .= '<div class="dashboardtabdatacontainer">';

		if (!_is_array($_ticketsContainer[1]))
		{
			$_tabContents .= '<div class="dashboardmsg">' . $this->Language->Get('noinfoinview') . '</div>';
		} else {

			$_rowClass = 'gridrow1';

			$_tabContents .= '<div class="gridcontentborder"><table cellspacing="1" cellpadding="4" border="0" width="100%">';
			$_tabContents .= '<tr class="gridtabletitlerow">
	<td class="gridtabletitlerow" width="20" valign="middle" align="center"> </td>
	<td class="gridtabletitlerow" width="100" valign="middle" align="left">' . $this->Language->Get('dashticketid') . '</td>
	<td class="gridtabletitlerow" valign="middle" align="left">' . $this->Language->Get('dashsubject') . '</td>
	<td class="gridtabletitlerow" width="140" valign="middle" align="left">' . $this->Language->Get('dashowner') . '</td>
	<td class="gridtabletitlerow" width="140" valign="middle" align="left">' . $this->Language->Get('dashdepartment') . '</td>
	<td class="gridtabletitlerow" width="100" valign="middle" align="left">' . $this->Language->Get('dashstatus') . '</td>
	</tr>';
			if (_is_array($_ticketsContainer[1]))
			{
				foreach ($_ticketsContainer[1] as $_ticketID => $_ticket)
				{
					$_SWIFT_TicketObject = new SWIFT_Ticket(new SWIFT_DataStore($_ticket));
					if ($_rowClass == 'gridrow1')
					{
						$_rowClass = 'gridrow2';
					} else {
						$_rowClass = 'gridrow1';
					}

					$_departmentTitle = $_statusTitle = $_typeTitle = $_priorityTitle = $_ownerTitle = $this->Language->Get('na');

					if ($_SWIFT_TicketObject->GetProperty('departmentid') == '0')
					{
						$_departmentTitle = $this->Language->Get('trash');
					} else if (isset($_departmentCache[$_SWIFT_TicketObject->GetProperty('departmentid')])) {
						$_departmentTitle = $_departmentCache[$_SWIFT_TicketObject->GetProperty('departmentid')]['title'];
					}

					if ($_SWIFT_TicketObject->GetProperty('ownerstaffid') == '0')
					{
						$_ownerTitle = $this->Language->Get('unassigned');
					} else if (isset($_staffCache[$_SWIFT_TicketObject->GetProperty('ownerstaffid')])) {
						$_ownerTitle = $_staffCache[$_SWIFT_TicketObject->GetProperty('ownerstaffid')]['fullname'];
					}

					if (isset($_ticketStatusCache[$_SWIFT_TicketObject->GetProperty('ticketstatusid')]))
					{
						$_statusTitle = $_ticketStatusCache[$_SWIFT_TicketObject->GetProperty('ticketstatusid')]['title'];
					}

					if (isset($_ticketTypeCache[$_SWIFT_TicketObject->GetProperty('tickettypeid')]))
					{
						$_typeTitle = $_ticketTypeCache[$_SWIFT_TicketObject->GetProperty('tickettypeid')]['title'];
					}

					if (isset($_ticketPriorityCache[$_SWIFT_TicketObject->GetProperty('priorityid')]))
					{
						$_priorityTitle = $_ticketPriorityCache[$_SWIFT_TicketObject->GetProperty('priorityid')]['title'];
					}

					$_ticketLink = SWIFT::Get('basename') . '/Tickets/Ticket/View/' . intval($_ticketID);

					$_tabContents .= '<tr class="' . $_rowClass . '"><td class="' . $_rowClass . '" valign="middle" align="center"><img src="' . SWIFT::Get('themepathimages') . 'icon_ticket.png' . '" align="absmiddle" border="0" /></td><td class="' . $_rowClass . '" valign="middle" align="left"><a href="' . $_ticketLink . '" viewport="1">' . htmlspecialchars($_SWIFT_TicketObject->GetTicketDisplayID()) . '</a></td><td class="' . $_rowClass . '" valign="middle" align="left"><a href="' . $_ticketLink . '" viewport="1">' . htmlspecialchars($_SWIFT_TicketObject->GetProperty('subject')) . '</a></td><td class="' . $_rowClass . '" valign="middle" align="left">' . htmlspecialchars($_ownerTitle) . '</td><td class="' . $_rowClass . '" valign="middle" align="left">' . htmlspecialchars($_departmentTitle) . '</td><td class="' . $_rowClass . '" valign="middle" align="left">' . htmlspecialchars($_statusTitle) . '</td></tr>';

				}
			}
			$_tabContents .= '</table></div>';

		}

		$_tabContents .= '</div>';
		$_tabContents .= '</div>';


		return $_tabContents;
	}

	/**
	 * Render the Tab Header
	 *
	 * @author Varun Shoor
	 * @param string $_headerTitle The Header Title
	 * @param string $_extendedLink (OPTIONAL) The Extended Link to View More Info
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderTabHeader($_headerTitle, $_extendedLink = false)
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		$_renderHTML = '<div>';

		if (!empty($_extendedLink))
		{
			$_renderHTML .= '<div style="float: right;"><div class="viewmore" onclick="javascript: loadViewportData(\'' . $_extendedLink . '\');"></div></div>';
		}
		$_renderHTML .= '<table class="hlineheaderext"><tr><th rowspan="2" nowrap>' . $_headerTitle . '</th><td>&nbsp;</td></tr><tr><td class="hlinelower">&nbsp;</td></tr></table>';
		$_renderHTML .= '</div>';

		return $_renderHTML;
	}

	/**
	 * Render Counters
	 *
	 * @author Varun Shoor
	 * @param array $_counterContainer The Counter Container
	 * @return string The Rendered HTML
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderCounters($_counterContainer)
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		$_renderHTML = '';

		foreach ($_counterContainer as $_counter) {
			if (empty($_counter[1]))
			{
				continue;
			}

			$_renderHTML .= '
			<div class="dashboardcounter" onclick="javascript: loadViewportData(\'' . $_counter[2] . '\');">
				<div class="dashboardcounterparent">
					<div class="dashboardcounterheader">' . $_counter[0] . '</div>
					<div class="dashboardcounternumber">' . $_counter[1] . '</div>
				</div>
			</div>
			';
		}

		return $_renderHTML;
	}

	/**
	 * Render the Progress Bars
	 *
	 * @author Varun Shoor
	 * @param array $_progressContainer The Progress Container
	 * @param bool $_fixedColor (OPTIONAL) Whether to use a fixed color
	 * @return string The Rendered HTML
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	protected function RenderProgress($_progressContainer, $_fixedColor = false)
	{
		if (!$this->GetIsClassLoaded())
		{
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		$_widthCeil = 85;

		$_color90 = '#cc1111';
		$_color80 = '#ad1010';
		$_color70 = '#950d0d';
		$_color60 = '#085386';
		$_color50 = '#085386';
		$_color40 = '#085d97';
		$_color30 = '#0b6eb3';
		$_color20 = '#457506';
		$_color10 = '#508806';
		$_color0 = '#5da105';


		$_totalItems = 0;
		foreach ($_progressContainer as $_progressItem) {
			$_totalItems += $_progressItem['count'];
		}

		$_renderHTML = '';
		foreach ($_progressContainer as $_progressItem) {
			if (empty($_progressItem['count']))
			{
				continue;
			}

			$_progressItem['percentage'] = ($_progressItem['count']/$_totalItems)*100;

			$_progressItem['width'] = ($_progressItem['percentage']*$_widthCeil)/100;

			if ($_fixedColor && !isset($_progressItem['color']))
			{
				$_progressItem['color'] = $_color40;
			} else if (!isset($_progressItem['color'])) {
				if ($_progressItem['percentage'] >= 90)
				{
					$_progressItem['color'] = $_color90;
				} else if ($_progressItem['percentage'] >= 80 && $_progressItem['percentage'] < 90) {
					$_progressItem['color'] = $_color80;
				} else if ($_progressItem['percentage'] >= 70 && $_progressItem['percentage'] < 80) {
					$_progressItem['color'] = $_color70;
				} else if ($_progressItem['percentage'] >= 60 && $_progressItem['percentage'] < 80) {
					$_progressItem['color'] = $_color60;
				} else if ($_progressItem['percentage'] >= 50 && $_progressItem['percentage'] < 60) {
					$_progressItem['color'] = $_color50;
				} else if ($_progressItem['percentage'] >= 40 && $_progressItem['percentage'] < 50) {
					$_progressItem['color'] = $_color40;
				} else if ($_progressItem['percentage'] >= 30 && $_progressItem['percentage'] < 40) {
					$_progressItem['color'] = $_color30;
				} else if ($_progressItem['percentage'] >= 20 && $_progressItem['percentage'] < 30) {
					$_progressItem['color'] = $_color20;
				} else if ($_progressItem['percentage'] >= 10 && $_progressItem['percentage'] < 20) {
					$_progressItem['color'] = $_color10;
				} else {
					$_progressItem['color'] = $_color0;
				}
			}

			$_finalWidth = round($_progressItem['width']);

			$_progressPercentage = round($_progressItem['percentage'], 0);
			if ($_progressItem['percentage'] < 0) {
				$_progressPercentage = round($_progressItem['percentage'], 2);
			}

			$_renderHTML .= '<div class="dashboardprogress"' . IIF(!empty($_progressItem['link']), ' onclick="javascript: loadViewportData(\'' . $_progressItem['link'] . '\');"') . '>
			<div class="dashboardprogresstitle">' . StripName(htmlspecialchars($_progressItem['title']), 30) . '</div>
			<div style="float: right;">
			<div class="dashboardprogressperc">' . $_progressPercentage . '%</div>
			<div class="dashboardprogressbarparent"><div class="dashboardprogressbar" style="margin-right: ' . round($_widthCeil-$_finalWidth) . 'px; width: ' . $_finalWidth . 'px; background: ' . $_progressItem['color'] . ';"></div></div>
			</div>
			<div class="dashboardprogresscount">' . number_format(intval($_progressItem['count']), 0) . '</div>
			</div>';
		}

		return $_renderHTML;
	}
}
?>