<?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 User View
 *
 * @author Varun Shoor
 */
class View_User extends SWIFT_View
{
	/**
	 * 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 User Form
	 *
	 * @author Varun Shoor
	 * @param int $_mode The Render Mode
	 * @param object $_SWIFT_UserObject The SWIFT_User Object Pointer (Only for EDIT Mode)
	 * @param bool $_isQuickInsert (OPTIONAL) Whether this is being executed using quick insert
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function Render($_mode, SWIFT_User $_SWIFT_UserObject = null, $_isQuickInsert = false)
	{
		$_SWIFT = SWIFT::GetInstance();

		if (!$this->GetIsClassLoaded())
		{
			return false;
		}

		$_userGroupCache = $this->Cache->Get('usergroupcache');
		$_languageCache = $this->Cache->Get('languagecache');
		$_slaPlanCache = $this->Cache->Get('slaplancache');

		// Calculate the URL
		if ($_isQuickInsert == true)
		{
			$this->UserInterface->Start(get_class($this),'/Base/User/QuickInsertSubmit', SWIFT_UserInterface::MODE_INSERT, true, false, false, false, 'quickinsertuserdiv');
		} else if ($_mode == SWIFT_UserInterface::MODE_EDIT) {
			$this->UserInterface->Start(get_class($this), '/Base/User/EditSubmit/' . $_SWIFT_UserObject->GetUserID(), SWIFT_UserInterface::MODE_EDIT, false, true);
		} else {
			$this->UserInterface->Start(get_class($this), '/Base/User/InsertSubmit', SWIFT_UserInterface::MODE_INSERT, false, true);
		}

		$_userFullName = '';
		$_userSalutation = SWIFT_User::SALUTATION_NONE;
		$_userDesignation = '';
		$_userAvatarImage = SWIFT::Get('themepath') . 'images/icon_defaultavatar.gif';
		$_userIsEnabled = true;
		$_userExpiry = '';
		$_userPhone = '';
		$_userOrganization = '';
		$_userOrganizationAutoComplete = 0;
		$_userRole = SWIFT_User::ROLE_USER;
		$_userGroupID = SWIFT_UserGroup::RetrieveDefaultUserGroupID(SWIFT_UserGroup::TYPE_REGISTERED);
		$_userTimeZonePHP = '';
		$_userEnableDST = true;
		$_userLanguageID = false;
		$_userSLAPlanID = false;
		$_userSLAExpiry = '';
		$_userTagContainer = array();
		$_userEmailContainer = array();
		$_SWIFT_UserOrganizationObject = false;
		$_profileImageBottom = '';
		$_userID = 0;

		if ($_mode == SWIFT_UserInterface::MODE_EDIT)
		{
			if ($_SWIFT->Staff->GetPermission('staff_canupdateuser') != '0') {
				$this->UserInterface->Toolbar->AddButton($this->Language->Get('update'), 'icon_check.gif');
			}

			if ($_SWIFT_UserObject->GetProperty('isvalidated') != '1')
			{
				$this->UserInterface->Toolbar->AddButton($this->Language->Get('markasverified'), 'icon_check.gif', '/Base/User/MarkAsVerified/' . $_SWIFT_UserObject->GetUserID(), SWIFT_UserInterfaceToolbar::LINK_VIEWPORT);
			}

			if ($_SWIFT->Staff->GetPermission('staff_caninsertusernote') != '0')
			{
				$this->UserInterface->Toolbar->AddButton($this->Language->Get('addnote'), 'icon_note.png', "UICreateWindow('" . SWIFT::Get('basename') . '/Base/User/AddNote/' . $_SWIFT_UserObject->GetUserID() . "', 'addnote', '". $_SWIFT->Language->Get('addnote') ."', '". $_SWIFT->Language->Get('loadingwindow') ."', 600, 360, true, this);", SWIFT_UserInterfaceToolbar::LINK_JAVASCRIPT, '', '', false);
			}

			if ($_SWIFT->Staff->GetPermission('staff_canupdateuser') != '0')
			{
				$this->UserInterface->Toolbar->AddButton($this->Language->Get('changepassword'), 'icon_lock.gif', "UICreateWindow('" . SWIFT::Get('basename') . '/Base/User/ChangePassword/' . $_SWIFT_UserObject->GetUserID() . "', 'changepassword', '". $_SWIFT->Language->Get('changepassword') ."', '". $_SWIFT->Language->Get('loadingwindow') ."', 400, 280, true, this);", SWIFT_UserInterfaceToolbar::LINK_JAVASCRIPT, '', '', false);
			}

			/**
			 * BUG FIX - Saloni Dhall
			 *
			 * SWIFT-3018: "Login as User" permission bug
			 *
			 */
			if ($_SWIFT->Staff->GetPermission('staff_loginasuser') != '0')
			{
				$this->UserInterface->Toolbar->AddButton($this->Language->Get('loginasuser'), 'icon_user2.png', SWIFT::Get('basename') . '/Base/User/LoginAsUser/' . $_SWIFT_UserObject->GetUserID(), SWIFT_UserInterfaceToolbar::LINK_NEWWINDOW);
			}

			$this->UserInterface->Toolbar->AddButton('');
			$this->UserInterface->Toolbar->AddButton($this->Language->Get('delete'), 'icon_delete.gif', '/Base/User/Delete/' . $_SWIFT_UserObject->GetUserID(), SWIFT_UserInterfaceToolbar::LINK_CONFIRM, '', '', false);
			$this->UserInterface->Toolbar->AddButton($this->Language->Get('help'), 'icon_help.gif', SWIFT_Help::RetrieveHelpLink('user'), SWIFT_UserInterfaceToolbar::LINK_NEWWINDOW);

			$_userFullName = $_SWIFT_UserObject->GetProperty('fullname');
			$_userDesignation = $_SWIFT_UserObject->GetProperty('userdesignation');
			$_userSalutation = $_SWIFT_UserObject->GetProperty('salutation');
			$_userPhone = $_SWIFT_UserObject->GetProperty('phone');
			$_userTimeZonePHP = $_SWIFT_UserObject->GetProperty('timezonephp');

			$_userIsEnabled = intval($_SWIFT_UserObject->GetProperty('isenabled'));
			$_userExpiry = intval($_SWIFT_UserObject->GetProperty('userexpirytimeline'));
			$_userRole = intval($_SWIFT_UserObject->GetProperty('userrole'));
			$_userGroupID = intval($_SWIFT_UserObject->GetProperty('usergroupid'));
			$_userEnableDST = intval($_SWIFT_UserObject->GetProperty('enabledst'));
			$_userLanguageID = intval($_SWIFT_UserObject->GetProperty('languageid'));
			$_userSLAPlanID = intval($_SWIFT_UserObject->GetProperty('slaplanid'));
			$_userSLAExpiry = intval($_SWIFT_UserObject->GetProperty('slaexpirytimeline'));

			$_userID = $_SWIFT_UserObject->GetUserID();

			if (SWIFT_UserProfileImage::UserHasProfileImage($_SWIFT_UserObject->GetUserID()))
			{
				$_userAvatarImage = SWIFT::Get('basename') . '/Base/User/GetProfileImage/' . $_SWIFT_UserObject->GetUserID();
				$_profileImageBottom = '<br /><a href="' . SWIFT::Get('basename') . '/Base/User/ClearProfileImage/' . $_SWIFT_UserObject->GetUserID() . '" viewport="1"><img src="' . SWIFT::Get('themepathimages') . 'icon_calclose.gif" align="absmiddle" border="0" /> ' . $this->Language->Get('clear') . '</a>';
			}

			if ($_SWIFT_UserObject->GetProperty('userorganizationid'))
			{
				try
				{
					$_SWIFT_UserOrganizationObject = new SWIFT_UserOrganization($_SWIFT_UserObject->GetProperty('userorganizationid'));
					if ($_SWIFT_UserOrganizationObject instanceof SWIFT_UserOrganization && $_SWIFT_UserOrganizationObject->GetIsClassLoaded())
					{
						$_userOrganization = $_SWIFT_UserOrganizationObject->GetProperty('organizationname');
						$_userOrganizationAutoComplete = intval($_SWIFT_UserOrganizationObject->GetUserOrganizationID());
					}
				} catch (SWIFT_Exception $_SWIFT_ExceptionObject) {

				}
			}

			$_userTagContainer = SWIFT_Tag::GetTagList(SWIFT_TagLink::TYPE_USER, $_SWIFT_UserObject->GetUserID());

			$_userEmailContainer = SWIFT_UserEmail::RetrieveList($_SWIFT_UserObject->GetUserID());
		} else {
			if (!$_isQuickInsert)
			{
				$this->UserInterface->Toolbar->AddButton($this->Language->Get('insert'), 'icon_addplus.gif');
				$this->UserInterface->Toolbar->AddButton($this->Language->Get('help'), 'icon_help.gif', SWIFT_Help::RetrieveHelpLink('user'), SWIFT_UserInterfaceToolbar::LINK_NEWWINDOW);
			}
		}


		/*
		 * ###############################################
		 * BEGIN GENERAL TAB
		 * ###############################################
		 */

		$_GeneralTabObject = $this->UserInterface->AddTab($this->Language->Get('tabgeneral'), 'icon_form.gif', 'general', true);

		if ($_isQuickInsert)
		{
			$_GeneralTabObject->Overflow(480);
		}

		if ($_mode == SWIFT_UserInterface::MODE_EDIT)
		{
			$_notesHTML = $this->RenderUserNotes($_SWIFT_UserObject);

			if (!empty($_notesHTML))
			{
				$_GeneralTabObject->RowHTML('<tr class="gridrow3" id="usernotescontainerdivholder"><td colspan="2" align="left" valign="top class="gridrow3"><div id="usernotescontainerdiv">' . $_notesHTML . '</div></td></tr>');
			} else {
				$_GeneralTabObject->RowHTML('<tr class="gridrow3" style="display: none;" id="usernotescontainerdivholder"><td colspan="2" align="left" valign="top class="gridrow3"><div id="usernotescontainerdiv"></div></td></tr>');
			}
		}

		if (!$_isQuickInsert)
		{
			$_GeneralTabObject->RowHTML('<tr><td colspan="2" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top" width="105"><img style="padding: 10px;" src="' . $_userAvatarImage . '" align="absmiddle" border="0" />' . $_profileImageBottom . '</td><td align="left" valign="top" width=""><table width="100%" border="0" cellspacing="1" cellpadding="4">');
		}

		$_salutationList = SWIFT_User::RetrieveSalutationList();
		$_salutationHTML = '<select name="salutation" class="swiftselect">';
		foreach ($_salutationList as $_key => $_val)
		{
			$_isSelected = false;
			if (($_userSalutation == $_key && !isset($_POST['salutation'])) || (isset($_POST['salutation']) && $_POST['salutation'] == $_key))
			{
				$_isSelected = true;
			}

			$_salutationHTML .= '<option value="' . $_key . '"' . IIF($_isSelected, ' selected') . '>' . $_val . '</option>';
		}
		$_salutationHTML .= '</select>';

		if (isset($_POST['fullname']))
		{
			$_userFullName = $_POST['fullname'];
		}
		$_fullNameHTML = '&nbsp;<input type="text" class="swifttext" name="fullname" value="' . htmlspecialchars($_userFullName) . '" size="20" />';

		$_columnClass = '';
		if (in_array('fullname', SWIFT::GetErrorFieldContainer()))
		{
			$_columnClass = 'errorrow';
		}

		$_GeneralTabObject->DefaultDescriptionRow($this->Language->Get('userfullname'), $this->Language->Get('desc_userfullname'), $_salutationHTML . $_fullNameHTML, '', $_columnClass);
		$_GeneralTabObject->TextAutoComplete('organization', $this->Language->Get('userorganization'), '/Base/UserOrganization/QuickSearch', $this->Language->Get('desc_userorganization'), $_userOrganization, $_userOrganizationAutoComplete, 'icon_userorganization.png');
		$_GeneralTabObject->Text('userdesignation', $this->Language->Get('userdesignation'), $this->Language->Get('desc_userdesignation'), $_userDesignation);

		if (!$_isQuickInsert)
		{
			$_GeneralTabObject->RowHTML('</table></td></tr></table></td></tr>');
		}

		if ($_SWIFT->Staff->GetPermission('staff_canupdatetags') != '0')
		{
			$_GeneralTabObject->TextMultipleAutoComplete('tags', false, false, '/Base/Tags/QuickSearch', $_userTagContainer, 'icon_taginput.png', 'gridrow1', true);
		}

		$this->Controller->CustomFieldRendererStaff->Render(SWIFT_CustomFieldRenderer::TYPE_STATIC, $_mode, array(SWIFT_CustomFieldGroup::GROUP_USER), $_GeneralTabObject, $_userID);

		if ($_mode == SWIFT_UserInterface::MODE_INSERT)
		{
			$this->Controller->CustomFieldRendererStaff->Render(SWIFT_CustomFieldRenderer::TYPE_FIELDS, $_mode, array(SWIFT_CustomFieldGroup::GROUP_USER), $_GeneralTabObject, $_userID);
		}

		$_GeneralTabObject->Title($this->Language->Get('generaloptions'), 'icon_doublearrows.gif');

		$_GeneralTabObject->TextMultipleAutoComplete('emails', $this->Language->Get('useremails'), $this->Language->Get('desc_useremails'), false, $_userEmailContainer, 'icon_email.gif', false, false, 2, false, false, false, '', array('containemail' => '1'));

		$_GeneralTabObject->Text('phone', $this->Language->Get('userphone'), $this->Language->Get('desc_userphone'), $_userPhone, 'text' , 30 , 25);

		$_itemContainer = array();
		$_index = 0;
		foreach (array(SWIFT_User::ROLE_USER => $this->Language->Get('userroleuser'), SWIFT_User::ROLE_MANAGER => $this->Language->Get('userrolemanager')) as $_key => $_val)
		{
			$_itemContainer[$_index]['title'] = $_val;
			$_itemContainer[$_index]['value'] = $_key;

			if ($_key == $_userRole)
			{
				$_itemContainer[$_index]['checked'] = true;
			}

			$_index++;
		}

		$_GeneralTabObject->Radio('userrole', $this->Language->Get('userrole'), $this->Language->Get('desc_userrole'), $_itemContainer, false);

		$_optionsContainer = array();
		$_index = 0;
		foreach ($_userGroupCache as $_key => $_val)
		{
			if ($_val['grouptype'] != SWIFT_UserGroup::TYPE_REGISTERED)
			{
				continue;
			}

			$_optionsContainer[$_index]['title'] = $_val['title'];
			$_optionsContainer[$_index]['value'] = $_val['usergroupid'];

			if ($_val['usergroupid'] == $_userGroupID)
			{
				$_optionsContainer[$_index]['selected'] = true;
			}

			$_index++;
		}

		$_GeneralTabObject->Select('usergroupid', $this->Language->Get('usergroup'), $this->Language->Get('desc_usergroup'), $_optionsContainer);

		if (!$_isQuickInsert)
		{
			$_GeneralTabObject->YesNo('isenabled', $this->Language->Get('isenabled'), $this->Language->Get('desc_isenabled'), $_userIsEnabled);

			$_userExpiryDate = '';
			if (!empty($_userExpiry)) {
				$_userExpiryDate = gmdate(SWIFT_Date::GetCalendarDateFormat(), $_userExpiry);
			}
			$_GeneralTabObject->Date('userexpirytimeline', $this->Language->Get('userexpiry'), $this->Language->Get('desc_userexpiry'), $_userExpiryDate);

			// Only display the add note column in Insert
			if ($_mode == SWIFT_UserInterface::MODE_INSERT)
			{
				$_GeneralTabObject->Notes('usernotes', $this->Language->Get('addnotes'));
			}
		}


		/*
		 * ###############################################
		 * END GENERAL TAB
		 * ###############################################
		 */



		/*
		 * ###############################################
		 * BEGIN PROFILE TAB
		 * ###############################################
		 */

		$_ProfileTabObject = $this->UserInterface->AddTab($this->Language->Get('tabprofile'), 'icon_settings2.gif', 'profile', false);

		if ($_mode == SWIFT_UserInterface::MODE_EDIT)
		{
			$this->Controller->CustomFieldRendererStaff->Render(SWIFT_CustomFieldRenderer::TYPE_FIELDS, $_mode, array(SWIFT_CustomFieldGroup::GROUP_USER), $_ProfileTabObject, $_userID);
		}

		if (!$_isQuickInsert)
		{
			$_ProfileTabObject->Title($this->Language->Get('personalizeoptions'), 'icon_doublearrows.gif');

			$_ProfileTabObject->File('profileimage', $this->Language->Get('userprofileimage'), $this->Language->Get('desc_userprofileimage'), '');

			$_ProfileTabObject->Title($this->Language->Get('generaloptions'), 'icon_doublearrows.gif');

			$_optionsContainer = array();
			$_index = 0;

			foreach ($this->Controller->TimeZoneContainer->GetTimeZoneList() as $_key => $_val)
			{
				$_optionsContainer[$_index]['title'] = $_val['title'];
				$_optionsContainer[$_index]['value'] = $_val['value'];

				if ($_val['value'] == $_userTimeZonePHP)
				{
					$_optionsContainer[$_index]['selected'] = true;
				}

				$_index++;
			}

			$_ProfileTabObject->Select('timezonephp', $this->Language->Get('usertimezone'), $this->Language->Get('desc_usertimezone'), $_optionsContainer);

			$_ProfileTabObject->YesNo('enabledst', $this->Language->Get('userenabledst'), $this->Language->Get('desc_userenabledst'), $_userEnableDST);

			$_optionsContainer = array();
			$_index = 1;

			$_optionsContainer[0]['title'] = $this->Language->Get('defaultlanguage');
			$_optionsContainer[0]['value'] = 0;
			if (!$_userLanguageID)
			{
				$_optionsContainer[0]['selected'] = true;
			}

			foreach ($_languageCache as $_key => $_val)
			{
				if($_val['isenabled'] == 1)
				{
				$_optionsContainer[$_index]['title'] = $_val['title'];
				$_optionsContainer[$_index]['value'] = $_val['languageid'];

				if ($_val['languageid'] == $_userLanguageID)
				{
					$_optionsContainer[$_index]['selected'] = true;
				}

				$_index++;
				}
			}

			$_ProfileTabObject->Select('languageid', $this->Language->Get('userlanguage'), $this->Language->Get('desc_userlanguage'), $_optionsContainer);
		}

		if (SWIFT_App::IsInstalled(APP_TICKETS))
		{
			$_ProfileTabObject->Title($this->Language->Get('usercustomsla'), 'icon_doublearrows.gif');

			$_optionsContainer = array();
			$_index = 1;

			$_optionsContainer[0]['title'] = $this->Language->Get('defaultslaplan');
			$_optionsContainer[0]['value'] = 0;
			if (!$_userSLAPlanID)
			{
				$_optionsContainer[0]['selected'] = true;
			}

			foreach ($_slaPlanCache as $_key => $_val)
			{
				$_optionsContainer[$_index]['title'] = $_val['title'];
				$_optionsContainer[$_index]['value'] = $_val['slaplanid'];

				if ($_val['slaplanid'] == $_userSLAPlanID)
				{
					$_optionsContainer[$_index]['selected'] = true;
				}

				$_index++;
			}

			$_ProfileTabObject->Select('slaplanid', $this->Language->Get('userslaplan'), $this->Language->Get('desc_userslaplan'), $_optionsContainer);

			$_userSLAExpiryDate = '';
			if (!empty($_userSLAExpiry)) {
				$_userSLAExpiryDate = gmdate(SWIFT_Date::GetCalendarDateFormat(), $_userSLAExpiry);
			}

			$_ProfileTabObject->Date('slaexpirytimeline', $this->Language->Get('userslaexpiry'), $this->Language->Get('desc_userslaexpiry'), $_userSLAExpiryDate);
		} else {
			$this->UserInterface->Hidden('slaplanid', '0');
			$this->UserInterface->Hidden('slaexpirytimeline', '0');
		}

		/*
		 * ###############################################
		 * END PROFILE TAB
		 * ###############################################
		 */



		/*
		 * ###############################################
		 * BEGIN ORGANIZATION TAB
		 * ###############################################
		 */

		if ($_mode == SWIFT_UserInterface::MODE_EDIT && $_SWIFT_UserOrganizationObject instanceof SWIFT_UserOrganization && $_SWIFT_UserOrganizationObject->GetIsClassLoaded())
		{
			$_userOrganizationTagContainer = SWIFT_Tag::GetTagList(SWIFT_TagLink::TYPE_USERORGANIZATION, $_SWIFT_UserOrganizationObject->GetUserOrganizationID());

			$_OrganizationTabObject = $this->UserInterface->AddTab($this->Language->Get('taborganization'), 'icon_userorganization.png', 'organization', false);
			$_OrganizationTabObject->LoadToolbar();

			$_OrganizationTabObject->Toolbar->AddButton($this->Language->Get('update'), 'icon_check.gif');
			$_OrganizationTabObject->Toolbar->AddButton($this->Language->Get('edit'), 'icon_edit.gif', '/Base/UserOrganization/Edit/' . $_SWIFT_UserOrganizationObject->GetUserOrganizationID(), SWIFT_UserInterfaceToolbar::LINK_VIEWPORT);

			if ($_SWIFT->Staff->GetPermission('staff_caninsertusernote') != '0')
			{
				$_OrganizationTabObject->Toolbar->AddButton($this->Language->Get('addnote'), 'icon_note.png', "UICreateWindow('" . SWIFT::Get('basename') . '/Base/User/AddNote/' . $_SWIFT_UserObject->GetUserID() . "/1', 'addnote', '". $_SWIFT->Language->Get('addnote') ."', '". $_SWIFT->Language->Get('loadingwindow') ."', 600, 360, true, this);", SWIFT_UserInterfaceToolbar::LINK_JAVASCRIPT, '', '', false);
			}

			$_OrganizationTabObject->Toolbar->AddButton($this->Language->Get('help'), 'icon_help.gif', SWIFT_Help::RetrieveHelpLink('user'), SWIFT_UserInterfaceToolbar::LINK_NEWWINDOW);

			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationname'), '', htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('organizationname')));

			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationtype2'), '', htmlspecialchars(SWIFT_UserOrganization::GetOrganizationTypeLabel($_SWIFT_UserOrganizationObject->GetProperty('organizationtype'))));

			if ($_SWIFT->Staff->GetPermission('staff_canupdatetags') != '0')
			{
				$_OrganizationTabObject->TextMultipleAutoComplete('organizationtags', false, false, '/Base/Tags/QuickSearch', $_userOrganizationTagContainer, 'icon_taginput.png', 'gridrow1', true);
			}

			$_OrganizationTabObject->Title($this->Language->Get('contactdetails'), 'icon_doublearrows.gif');
			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationaddress'), '', nl2br(htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('address'))));
			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationcity'), '', htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('city')));
			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationstate'), '', htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('state')));
			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationpostalcode'), '', htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('postalcode')));
			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationcountry'), '', htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('country')));
			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationphone'), '', htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('phone')));
			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationfax'), '', htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('fax')));
			$_OrganizationTabObject->DefaultDescriptionRow($this->Language->Get('organizationwebsite'), '', htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('website')));
		}

		/*
		 * ###############################################
		 * END ORGANIZATION TAB
		 * ###############################################
		 */



		/*
		 * ###############################################
		 * BEGIN GEOIP TAB
		 * ###############################################
		 */

		if ($_mode == SWIFT_UserInterface::MODE_EDIT && $_SWIFT_UserObject->GetProperty('hasgeoip') == '1')
		{
			$_GeoIPTabObject = $this->UserInterface->AddTab($this->Language->Get('tabgeoip'), 'icon_geoip.gif', 'geoip', false);
			$_GeoIPTabObject->SetColumnWidth('150px');

			$_geoIPKeys = array('geoiporganization', 'geoipisp', 'geoipnetspeed', 'geoiptimezone', 'geoipcountry', 'geoipcountrydesc',
									'geoipregion', 'geoipcity', 'geoippostalcode', 'geoiplatitude', 'geoiplongitude', 'geoipmetrocode',
										'geoipareacode');

			foreach ($_geoIPKeys as $_keyName)
			{
				if ($_SWIFT_UserObject->GetProperty($_keyName) != '')
				{
					$_GeoIPTabObject->DefaultDescriptionRow($this->Language->Get($_keyName), '', htmlspecialchars($_SWIFT_UserObject->GetProperty($_keyName)));
				}
			}

		}

		/*
		 * ###############################################
		 * END GEOIP TAB
		 * ###############################################
		 */


		/*
		 * ###############################################
		 * BEGIN TICKETS TAB
		 * ###############################################
		 */

		if ($_mode == SWIFT_UserInterface::MODE_EDIT && SWIFT_App::IsInstalled(APP_TICKETS))
		{
			SWIFT_Loader::LoadModel('Ticket:Ticket', APP_TICKETS);
			$_ticketHistoryCounterHTML = '';
			$_ticketHistoryCount = SWIFT_Ticket::GetHistoryCountOnUser($_SWIFT_UserObject, $_userEmailContainer);
			if ($_ticketHistoryCount > 0) {
				$_ticketHistoryCount = number_format($_ticketHistoryCount, 0);
			}

			$_TicketsTabObject = $this->UserInterface->AddTab($this->Language->Get('tabtickets'), 'icon_tickets.png', 'tickets', false, false, 0, SWIFT::Get('basename') . '/Tickets/Ticket/HistoryUser/' . $_SWIFT_UserObject->GetUserID() . '/' . substr(BuildHash(), 6));
			$_TicketsTabObject->SetTabCounter($_ticketHistoryCount);
		}

		/*
		 * ###############################################
		 * END TICKETS TAB
		 * ###############################################
		 */



		/*
		 * ###############################################
		 * BEGIN CHATS TAB
		 * ###############################################
		 */

		if ($_mode == SWIFT_UserInterface::MODE_EDIT && SWIFT_App::IsInstalled(APP_LIVECHAT))
		{
			SWIFT_Loader::LoadModel('Chat:Chat', APP_LIVECHAT);
			$_chatHistoryCounterHTML = '';
			$_chatHistoryCount = SWIFT_Chat::GetHistoryCountOnUser($_SWIFT_UserObject, $_userEmailContainer);
			if ($_chatHistoryCount > 0) {
				$_chatHistoryCount = number_format($_chatHistoryCount, 0);
			}

			$_historyArguments = 'userid=' . $_SWIFT_UserObject->GetUserID() . '&random=' . substr(BuildHash(), 6);
			$_ChatsTabObject = $this->UserInterface->AddTab($this->Language->Get('tabchats'), 'icon_livesupport.gif', 'livechat', false, false, 0, SWIFT::Get('basename') . '/LiveChat/ChatHistory/History/' . base64_encode($_historyArguments));
			$_ChatsTabObject->SetTabCounter($_chatHistoryCount);
		}

		/*
		 * ###############################################
		 * END CHATS TAB
		 * ###############################################
		 */


		/*
		 * ###############################################
		 * BEGIN CALLS TAB
		 * ###############################################
		 */
		if ($_mode == SWIFT_UserInterface::MODE_EDIT && SWIFT_App::IsInstalled(APP_LIVECHAT))
		{

			$_callHistoryCounterHTML = '';
			SWIFT_Loader::LoadModel('Call:Call', APP_LIVECHAT);
			$_callHistoryCount = SWIFT_Call::GetHistoryCountOnUser($_SWIFT_UserObject, $_userEmailContainer);
			if ($_callHistoryCount > 0) {
				$_callHistoryCount = number_format($_callHistoryCount, 0);
			}

			$_userIDCall = -1;
			if ($_SWIFT_UserObject instanceof SWIFT_User && $_SWIFT_UserObject->GetIsClassLoaded())
			{
				$_userIDCall = $_SWIFT_UserObject->GetUserID();
			}

			$_callEmailList = '';
			foreach ($_userEmailContainer as $_callEmailAddress)
			{
				$_callEmailList .= '&email[]=' . urlencode($_callEmailAddress);
			}

			$_CallsTabObject = $this->UserInterface->AddTab($this->Language->Get('tabcalls'), 'icon_phone.gif', 'calls', false, false, 0, SWIFT::Get('basename') . '/LiveChat/Call/History/' . base64_encode('userid=' . intval($_userIDCall) . $_callEmailList));

			$_CallsTabObject->SetTabCounter($_callHistoryCount);
		}

		/*
		 * ###############################################
		 * END CALLS TAB
		 * ###############################################
		 */



		/*
		 * ###############################################
		 * BEGIN BILLING TAB
		 * ###############################################
		 */

		if ($_mode == SWIFT_UserInterface::MODE_EDIT && SWIFT_App::IsInstalled(APP_TICKETS))
		{
			SWIFT_Loader::LoadModel('TimeTrack:TicketTimeTrack', APP_TICKETS);
			$_timeTrackCounterHTML = '';
			$_timeTrackCount = SWIFT_TicketTimeTrack::GetTimeTrackCountOnUser($_SWIFT_UserObject);
			if ($_timeTrackCount > 0) {
				$_timeTrackCount = number_format($_timeTrackCount, 0);
			}

			$_BillingTabObject = $this->UserInterface->AddTab($this->Language->Get('tabbilling') . $_timeTrackCounterHTML, 'icon_spacer.gif', 'billing', false, false, 0, SWIFT::Get('basename') . '/Tickets/Ticket/BillingUser/' . $_SWIFT_UserObject->GetUserID() . '/' . substr(BuildHash(), 6));

			$_BillingTabObject->SetTabCounter($_timeTrackCount);
		}

		/*
		 * ###############################################
		 * END BILLING TAB
		 * ###############################################
		 */

		// Begin Hook: staff_user_tabs
		unset($_hookCode);
		($_hookCode = SWIFT_Hook::Execute('staff_user_tabs')) ? eval($_hookCode) : false;
		// End Hook

		$this->UserInterface->End();

		return true;
	}

	/**
	 * Render the User Grid
	 *
	 * @author Varun Shoor
	 * @param int $_searchStoreID The Search Store ID
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function RenderGrid($_searchStoreID = false)
	{
		$_SWIFT = SWIFT::GetInstance();

		if (!$this->GetIsClassLoaded())
		{
			return false;
		}

		$this->Load->Library('UserInterface:UserInterfaceGrid', array('usergrid', false, true));

		$_filterQuerySQLPrefix = 'useremails.*, users.fullname AS userfullname, users.isenabled AS isenabled, users.isvalidated AS isvalidated, usergroups.title AS usergrouptitle, userorganizations.organizationname AS userorganizationname, userorganizations.userorganizationid AS userorganizationid';

		if ($this->UserInterfaceGrid->GetMode() == SWIFT_UserInterfaceGrid::MODE_SEARCH)
		{
			$_searchQuerySuffix = "FROM " . TABLE_PREFIX . "useremails AS useremails
				LEFT JOIN " . TABLE_PREFIX . "users AS users ON (useremails.linktypeid = users.userid)
				LEFT JOIN " . TABLE_PREFIX . "userorganizations AS userorganizations ON (users.userorganizationid = userorganizations.userorganizationid)
				LEFT JOIN " . TABLE_PREFIX . "usergroups AS usergroups ON (users.usergroupid = usergroups.usergroupid)
				WHERE useremails.linktype = '" . SWIFT_UserEmail::LINKTYPE_USER . "' AND
					((" . $this->UserInterfaceGrid->BuildSQLSearch('useremails.email') . ") OR (" . $this->UserInterfaceGrid->BuildSQLSearch('users.fullname') . "))";

			$this->UserInterfaceGrid->SetSearchQuery("SELECT " . $_filterQuerySQLPrefix . ' ' . $_searchQuerySuffix, "SELECT COUNT(*) AS totalitems " . $_searchQuerySuffix);
		}

		$this->UserInterfaceGrid->SetSearchStoreOptions($_searchStoreID,
				"SELECT " . $_filterQuerySQLPrefix . " FROM " . TABLE_PREFIX . "useremails AS useremails
					LEFT JOIN " . TABLE_PREFIX . "users AS users ON (useremails.linktypeid = users.userid)
					LEFT JOIN " . TABLE_PREFIX . "userorganizations AS userorganizations ON (users.userorganizationid = userorganizations.userorganizationid)
					LEFT JOIN " . TABLE_PREFIX . "usergroups AS usergroups ON (users.usergroupid = usergroups.usergroupid)
					WHERE useremails.useremailid IN (%s)", SWIFT_SearchStore::TYPE_USERS, SWIFT::Get('basename') . '/Base/User/Manage/-1');

		$this->UserInterfaceGrid->SetQuery(
		"SELECT " . $_filterQuerySQLPrefix . " FROM " . TABLE_PREFIX . "useremails AS useremails
			LEFT JOIN " . TABLE_PREFIX . "users AS users ON (useremails.linktypeid = users.userid)
			LEFT JOIN " . TABLE_PREFIX . "userorganizations AS userorganizations ON (users.userorganizationid = userorganizations.userorganizationid)
			LEFT JOIN " . TABLE_PREFIX . "usergroups AS usergroups ON (users.usergroupid = usergroups.usergroupid) WHERE useremails.linktype = '" . SWIFT_UserEmail::LINKTYPE_USER . "'"

		, "SELECT COUNT(*) AS totalitems FROM " . TABLE_PREFIX . "useremails AS useremails
			LEFT JOIN " . TABLE_PREFIX . "users AS users ON (useremails.linktypeid = users.userid)
			WHERE useremails.linktype = '" . SWIFT_UserEmail::LINKTYPE_USER . "'");

		// Set Tag Lookup Queries..
		$this->UserInterfaceGrid->SetTagOptions(SWIFT_TagLink::TYPE_USER, "SELECT " . $_filterQuerySQLPrefix . " FROM " . TABLE_PREFIX . "useremails AS useremails
			LEFT JOIN " . TABLE_PREFIX . "users AS users ON (useremails.linktypeid = users.userid)
			LEFT JOIN " . TABLE_PREFIX . "userorganizations AS userorganizations ON (users.userorganizationid = userorganizations.userorganizationid)
			LEFT JOIN " . TABLE_PREFIX . "usergroups AS usergroups ON (users.usergroupid = usergroups.usergroupid)

			WHERE useremails.linktype = '" . SWIFT_UserEmail::LINKTYPE_USER . "' AND users.userid IN (%s)"

		, "SELECT COUNT(*) AS totalitems FROM " . TABLE_PREFIX . "useremails AS useremails
			LEFT JOIN " . TABLE_PREFIX . "users AS users ON (useremails.linktypeid = users.userid)
			LEFT JOIN " . TABLE_PREFIX . "userorganizations AS userorganizations ON (users.userorganizationid = userorganizations.userorganizationid)
			LEFT JOIN " . TABLE_PREFIX . "usergroups AS usergroups ON (users.usergroupid = usergroups.usergroupid)
			WHERE useremails.linktype = '" . SWIFT_UserEmail::LINKTYPE_USER . "' AND users.userid IN (%s)");

		$this->UserInterfaceGrid->SetRecordsPerPage(20);

		$this->UserInterfaceGrid->AddField(new SWIFT_UserInterfaceGridField('useremailid', 'useremailid', SWIFT_UserInterfaceGridField::TYPE_ID));

		$this->UserInterfaceGrid->AddField(new SWIFT_UserInterfaceGridField('icon', '&nbsp;', SWIFT_UserInterfaceGridField::TYPE_CUSTOM, 16, SWIFT_UserInterfaceGridField::ALIGN_CENTER));
		$this->UserInterfaceGrid->AddField(new SWIFT_UserInterfaceGridField('useremails.email', $this->Language->Get('useremail'), SWIFT_UserInterfaceGridField::TYPE_DB, 0, SWIFT_UserInterfaceGridField::ALIGN_LEFT, SWIFT_UserInterfaceGridField::SORT_ASC), true);
		$this->UserInterfaceGrid->AddField(new SWIFT_UserInterfaceGridField('users.fullname', $this->Language->Get('userfullname'), SWIFT_UserInterfaceGridField::TYPE_DB, 200, SWIFT_UserInterfaceGridField::ALIGN_LEFT));
		$this->UserInterfaceGrid->AddField(new SWIFT_UserInterfaceGridField('userorganizations.organizationname', $this->Language->Get('userorganization'), SWIFT_UserInterfaceGridField::TYPE_DB, 250, SWIFT_UserInterfaceGridField::ALIGN_LEFT));
		$this->UserInterfaceGrid->AddField(new SWIFT_UserInterfaceGridField('usergroups.title', $this->Language->Get('usergroup'), SWIFT_UserInterfaceGridField::TYPE_DB, 200, SWIFT_UserInterfaceGridField::ALIGN_LEFT));

		$this->UserInterfaceGrid->SetRenderCallback(array('View_User', 'GridRender'));
		$this->UserInterfaceGrid->AddMassAction(new SWIFT_UserInterfaceGridMassAction($this->Language->Get('delete'), 'icon_delete.gif', array('Controller_User', 'DeleteList'), $this->Language->Get('actionconfirm')));

		if ($_SWIFT->Staff->GetPermission('staff_canupdateuser') != '0')
		{
			$this->UserInterfaceGrid->AddMassAction(new SWIFT_UserInterfaceGridMassAction($this->Language->Get('enable'), 'icon_check.gif', array('Controller_User', 'EnableList'), $this->Language->Get('actionconfirm')));
			$this->UserInterfaceGrid->AddMassAction(new SWIFT_UserInterfaceGridMassAction($this->Language->Get('disable'), 'icon_toolbarblock.gif', array('Controller_User', 'DisableList'), $this->Language->Get('actionconfirm')));

			$this->UserInterfaceGrid->SetMassActionPanel($this->RenderMassActionPanel(),
				array('Controller_User', 'MassActionPanel'));
		}

		$this->UserInterfaceGrid->SetNewLinkViewport(SWIFT::Get('basename') . "/Base/User/Insert");

		$this->UserInterfaceGrid->Render();

		$this->UserInterfaceGrid->Display();

		return true;
	}

	/**
	 * Renders the Mass Action Panel and returns the HTML
	 *
	 * @author Varun Shoor
	 * @return string "Mass Action Panel HTML" on Success, "false" otherwise
	 */
	protected function RenderMassActionPanel() {
		$_SWIFT = SWIFT::GetInstance();

		$_userGroupCache = $_SWIFT->Cache->Get('usergroupcache');

		$_GeneralTabObject = new SWIFT_UserInterfaceTab($this->UserInterface, $_SWIFT->Language->Get('tabmassaction'), 'icon_form.gif', 0,
				'general', true, false, 4);
		$_GeneralTabObject->SetColumnWidth('150');

		$_GeneralTabObject->LoadToolbar();
		$_GeneralTabObject->Toolbar->AddButton($_SWIFT->Language->Get('update'), 'icon_check.gif', 'GridMassActionPanel(\'' . 'usergrid' .
				'\', \'\');', SWIFT_UserInterfaceToolbar::LINK_JAVASCRIPT);
		$_GeneralTabObject->Toolbar->AddButton($_SWIFT->Language->Get('help'), 'icon_help.gif', SWIFT_Help::RetrieveHelpLink('user'), SWIFT_UserInterfaceToolbar::LINK_NEWWINDOW);

		/**
		 * ---------------------------------------------
		 * Field Rendering Logic
		 * ---------------------------------------------
		 */

		$_GeneralTabObject->TextAutoComplete('organization', $this->Language->Get('userorganization'), '/Base/UserOrganization/QuickSearch', '', '', '', 'icon_userorganization.png');

		$_optionsContainer = array();
		$_optionsContainer[0]['title'] = $this->Language->Get('nochange');
		$_optionsContainer[0]['value'] = '0';
		$_optionsContainer[0]['selected'] = true;

		$_index = 1;

		foreach ($_userGroupCache as $_key => $_val)
		{
			if ($_val['grouptype'] != SWIFT_UserGroup::TYPE_REGISTERED)
			{
				continue;
			}

			$_optionsContainer[$_index]['title'] = $_val['title'];
			$_optionsContainer[$_index]['value'] = $_val['usergroupid'];

			$_index++;
		}

		$_GeneralTabObject->Select('usergroupid', $this->Language->Get('usergroup'), '', $_optionsContainer);



		/**
		 * ---------------------------------------------
		 * Tab Rendering Logic
		 * ---------------------------------------------
		 */
		$_tabContainer = array();
		$_tabContainer[] = $_GeneralTabObject;

		$_formName = 'usergrid';

		return SWIFT_UserInterfaceControlPanel::RenderMassActionPanelTabs($_formName, $_tabContainer);
	}

	/**
	 * The Grid Rendering Function
	 *
	 * @author Varun Shoor
	 * @param array $_fieldContainer The Field Record Value Container
	 * @return array The Processed Field Container Array
	 */
	static public function GridRender($_fieldContainer)
	{
		$_SWIFT = SWIFT::GetInstance();

		$_userURL = SWIFT::Get('basename') . '/Base/User/Edit/' . intval($_fieldContainer['linktypeid']);

		$_fieldContainer['icon'] = '<img src="' . SWIFT::Get('themepath') . 'images/' . IIF($_fieldContainer['isenabled'] == '0', 'icon_block.gif', 'icon_user2.png') .'" align="absmiddle" border="0" />';

		$_fieldContainer['useremails.email'] = IIF($_fieldContainer['isvalidated'] != '1', '<s>') . '<a href="' . $_userURL . '" viewport="1">' . htmlspecialchars($_fieldContainer['email']) . '</a>' . IIF($_fieldContainer['isvalidated'] != '1', '</s>');

		$_fieldContainer['users.fullname'] = htmlspecialchars($_fieldContainer['userfullname']);

		if (!empty($_fieldContainer['userorganizationname']))
		{
			$_fieldContainer['userorganizations.organizationname'] = '<a href="' . SWIFT::Get('basename') . '/Base/UserOrganization/Edit/' . intval($_fieldContainer['userorganizationid']) . '" viewport="1"><img src="' . SWIFT::Get('themepath') . 'images/' . 'icon_userorganization.png' .'" align="absmiddle" border="0" /> ' . htmlspecialchars($_fieldContainer['userorganizationname']) . '</a>';
		} else {
			$_fieldContainer['userorganizations.organizationname'] = $_SWIFT->Language->Get('na');
		}

		if (!empty($_fieldContainer['usergrouptitle']))
		{
			$_fieldContainer['usergroups.title'] = htmlspecialchars($_fieldContainer['usergrouptitle']);
		} else {
			$_fieldContainer['usergroups.title'] = $_SWIFT->Language->Get('na');
		}

		return $_fieldContainer;
	}

	/**
	 * Render the Notes for the given User (including his organization notes)
	 *
	 * @author Varun Shoor
	 * @param object $_SWIFT_UserObject The SWIFT_User Object
	 * @return mixed "_renderedHTML" (STRING) on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded or If Invalid Data is Provided
	 */
	public function RenderUserNotes(SWIFT_User $_SWIFT_UserObject)
	{
		$_SWIFT = SWIFT::GetInstance();

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

			return false;
		} else if (!$_SWIFT_UserObject instanceof SWIFT_User || !$_SWIFT_UserObject->GetIsClassLoaded()) {
			throw new SWIFT_Exception(SWIFT_INVALIDDATA);

			return false;
		} else if ($_SWIFT->Staff->GetPermission('staff_canviewusernotes') == '0') {
			return '';
		}

		// Retrieve notes
		$_userNoteContainer = array();
		$_renderedHTML = '';

		$this->Database->Query("SELECT usernotes.*, usernotedata.* FROM " . TABLE_PREFIX . "usernotes AS usernotes LEFT JOIN " . TABLE_PREFIX . "usernotedata AS usernotedata ON (usernotes.usernoteid = usernotedata.usernoteid) WHERE (usernotes.linktype = '" . SWIFT_UserNote::LINKTYPE_USER . "' AND usernotes.linktypeid = '" . intval($_SWIFT_UserObject->GetUserID()) . "') OR (usernotes.linktype = '" . SWIFT_UserNote::LINKTYPE_ORGANIZATION . "' AND usernotes.linktypeid = '" . intval($_SWIFT_UserObject->GetProperty('userorganizationid')) . "') ORDER BY usernotes.dateline DESC");
		while ($this->Database->NextRecord())
		{
			$_userNoteContainer[] = $this->Database->Record;

			unset($_icon);

			if ($this->Database->Record['linktype'] == SWIFT_UserNote::LINKTYPE_USER)
			{
				$_icon = 'icon_user2.png';
			} else if ($this->Database->Record['linktype'] == SWIFT_UserNote::LINKTYPE_ORGANIZATION) {
				$_icon = 'icon_userorganization.png';
			}

			$_renderedHTML .= '<div id="note' . intval(SWIFT_UserNote::GetSanitizedNoteColor($this->Database->Record['notecolor'])) . '" class="bubble"><div class="notebubble"><blockquote><p>' . nl2br(htmlspecialchars($this->Database->Record['notecontents'])) . '</p></blockquote></div><cite class="tip"><strong><img src="' . SWIFT::Get('themepath') . 'images/' . $_icon . '" align="absmiddle" border="0" /> ' . sprintf($this->Language->Get('notetitle'), htmlspecialchars($this->Database->Record['staffname']), SWIFT_Date::Get(SWIFT_Date::TYPE_DATETIME, $this->Database->Record['dateline']))

			. IIF(!empty($this->Database->Record['editedstaffid']) && !empty($this->Database->Record['editedstaffname']), sprintf($this->Language->Get('noteeditedtitle'), htmlspecialchars($this->Database->Record['editedstaffname']), SWIFT_Date::Get(SWIFT_Date::TYPE_DATETIME, $this->Database->Record['editedtimeline'])))

			. '</strong><div style="float: right; padding-right: 4px;">';

			if ($_SWIFT->Staff->GetPermission('staff_canupdateusernote') != '0')
			{
				$_renderedHTML .= '<a href="javascript: void(0);" onclick="javascript: UICreateWindow(\'' . SWIFT::Get('basename') . '/Base/User/EditNote/' . $_SWIFT_UserObject->GetUserID() . '/' . intval($this->Database->Record['usernoteid']) . "', 'editnote', '". $this->Language->Get('editnote') ."', '". $this->Language->Get('loadingwindow') . '\', 600, 360, true, this);"><img src="' . SWIFT::Get('themepath') . 'images/icon_editgray.gif' . '" align="absmiddle" border="0" /></a> ';
			}

			if ($_SWIFT->Staff->GetPermission('staff_candeleteusernote') != '0')
			{
				$_renderedHTML .= '<a href="javascript: void(0);" onclick="javascript: UserDeleteNote(\'' . addslashes($this->Language->Get('usernotedelconfirm')) . '\', \'' . intval($_SWIFT_UserObject->GetUserID()) . '/' . intval($this->Database->Record['usernoteid']) . '\');"><img src="' . SWIFT::Get('themepath') . 'images/icon_delete.gif' . '" align="absmiddle" border="0" /></a>';
			}

			$_renderedHTML .= '</div></cite></div>';
		}

		return $_renderedHTML;
	}

	/**
	 * Render the Change Password Dialog
	 *
	 * @author Varun Shoor
	 * @param object $_SWIFT_UserObject The SWIFT_User Object Pointer
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function RenderChangePasswordForm(SWIFT_User $_SWIFT_UserObject)
	{
		$_SWIFT = SWIFT::GetInstance();

		if (!$this->GetIsClassLoaded())
		{
			return false;
		}

		$this->UserInterface->Start('userchangepassword', '/Base/User/ChangePasswordSubmit/' . $_SWIFT_UserObject->GetUserID(), SWIFT_UserInterface::MODE_EDIT, false);
		$this->UserInterface->SetDialogOptions(false);

		$this->UserInterface->Toolbar->AddButton($this->Language->Get('update'), 'icon_check.gif');
		$this->UserInterface->Toolbar->AddButton($this->Language->Get('generateandemail'), 'icon_email.gif', '/Base/User/GeneratePassword/' . $_SWIFT_UserObject->GetUserID(), SWIFT_UserInterfaceToolbar::LINK_CONFIRM, '', '', false);
		$this->UserInterface->Toolbar->AddButton($this->Language->Get('help'), 'icon_help.gif', SWIFT_Help::RetrieveHelpLink('user'), SWIFT_UserInterfaceToolbar::LINK_NEWWINDOW);

		/*
		 * ###############################################
		 * BEGIN PASSWORD TAB
		 * ###############################################
		 */

		$_GeneralTabObject = $this->UserInterface->AddTab($this->Language->Get('tabgeneral'), 'icon_lock.gif', 'changepwtab', true);

		$_GeneralTabObject->Password('password', $this->Language->Get('userpassword'), '');
		$_GeneralTabObject->Password('passwordagain', $this->Language->Get('userpasswordagain'), '');

		/*
		 * ###############################################
		 * END PASSWORD TAB
		 * ###############################################
		 */

		$this->UserInterface->End();

		return true;
	}

	/**
	 * Render the Add Note Dialog
	 *
	 * @author Varun Shoor
	 * @param int $_mode The Render Mode
	 * @param object $_SWIFT_UserObject The SWIFT_User Object Pointer
	 * @param object $_SWIFT_UserNoteObject The SWIFT_UserNote Object Poitner
	 * @param bool $_isOrganizationNote Whether this is an Organization Note
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function RenderNoteForm($_mode, SWIFT_User $_SWIFT_UserObject, SWIFT_UserNote $_SWIFT_UserNoteObject = null, $_isOrganizationNote = false)
	{
		$_SWIFT = SWIFT::GetInstance();

		if (!$this->GetIsClassLoaded())
		{
			return false;
		}

		// Calculate the URL
		if ($_mode == SWIFT_UserInterface::MODE_INSERT)
		{
			$this->UserInterface->Start('useraddnotes', '/Base/User/AddNoteSubmit/' . $_SWIFT_UserObject->GetUserID(), SWIFT_UserInterface::MODE_EDIT, true, false, false, false, 'usernotescontainerdiv');
		} else {
			$this->UserInterface->Start('useraddnotes', '/Base/User/EditNoteSubmit/' . $_SWIFT_UserObject->GetUserID() . '/' . $_SWIFT_UserNoteObject->GetUserNoteID(), SWIFT_UserInterface::MODE_EDIT, true, false, false, false, 'usernotescontainerdiv');
		}

		$this->UserInterface->Toolbar->AddButton($this->Language->Get('help'), 'icon_help.gif', SWIFT_Help::RetrieveHelpLink('user'), SWIFT_UserInterfaceToolbar::LINK_NEWWINDOW);

		$_defaultNoteContents = '';
		$_defaultNoteColor = 1;
		if ($_SWIFT_UserNoteObject instanceof SWIFT_UserNote && $_SWIFT_UserNoteObject->GetIsClassLoaded())
		{
			$_defaultNoteContents = $_SWIFT_UserNoteObject->GetProperty('notecontents');
			$_defaultNoteColor = intval($_SWIFT_UserNoteObject->GetProperty('notecolor'));
		}

		$this->UserInterface->Hidden('isorganizationnote', intval($_isOrganizationNote));

		/*
		 * ###############################################
		 * BEGIN ADD NOTES TAB
		 * ###############################################
		 */

		$_AddNoteTabObject = $this->UserInterface->AddTab(IIF($_mode == SWIFT_UserInterface::MODE_INSERT, $this->Language->Get('tabaddnote'), $this->Language->Get('tabeditnote')), 'icon_note.png', 'addnote', true);

		$_AddNoteTabObject->Notes('usernotes', $this->Language->Get('addnotes'), $_defaultNoteContents, $_defaultNoteColor);

		/*
		 * ###############################################
		 * END ADD NOTES TAB
		 * ###############################################
		 */

		$this->UserInterface->End();

		return true;
	}

	/**
	 * Render the Information Box
	 *
	 * @author Varun Shoor
	 * @param SWIFT_User $_SWIFT_UserObject The SWIFT_User Object
	 * @return bool "true" on Success, "false" otherwise
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function RenderInfoBox(SWIFT_User $_SWIFT_UserObject) {
		$_SWIFT = SWIFT::GetInstance();

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

			return false;
		}

		$_informationHTML = '';

		$_userGroupCache = $this->Cache->Get('usergroupcache');

		$_userURL = SWIFT::Get('basename') . '/Base/User/Edit/' . $_SWIFT_UserObject->GetUserID();
		$_informationHTML .= '<div class="navinfoitem">' .
				'<div class="navinfoitemtitle">' . $this->Language->Get('infobuser') . '</div><div class="navinfoitemcontainer"><span class="navinfoitemlink"><a href="' . $_userURL . '" viewport="1">' . StripName(htmlspecialchars($_SWIFT_UserObject->GetProperty('fullname')), 20) . '</a></span>&nbsp;</div></div>';

		$_SWIFT_UserOrganizationObject = false;
		if ($_SWIFT_UserObject->GetProperty('userorganizationid'))
		{
			try
			{
				$_SWIFT_UserOrganizationObject = new SWIFT_UserOrganization($_SWIFT_UserObject->GetProperty('userorganizationid'));
				if ($_SWIFT_UserOrganizationObject instanceof SWIFT_UserOrganization && $_SWIFT_UserOrganizationObject->GetIsClassLoaded())
				{
				}
			} catch (SWIFT_Exception $_SWIFT_ExceptionObject) {

			}
		}

		if ($_SWIFT_UserOrganizationObject instanceof SWIFT_UserOrganization && $_SWIFT_UserOrganizationObject->GetIsClassLoaded())
		{
			$_userOrganizationURL = SWIFT::Get('basename') . '/Base/UserOrganization/Edit/' . $_SWIFT_UserOrganizationObject->GetUserOrganizationID();

			$_informationHTML .= '<div class="navinfoitem">' .
					'<div class="navinfoitemtitle">' . $this->Language->Get('infobuserorganization') . '</div><div class="navinfoitemcontainer"><span class="navinfoitemlink"><a href="' . $_userOrganizationURL . '" viewport="1">' . StripName(htmlspecialchars($_SWIFT_UserOrganizationObject->GetProperty('organizationname')), 20) . '</a></span>&nbsp;</div></div>';
		}

		if ($_SWIFT_UserObject instanceof SWIFT_User && $_SWIFT_UserObject->GetIsClassLoaded() && isset($_userGroupCache[$_SWIFT_UserObject->GetProperty('usergroupid')]))
		{
			$_informationHTML .= '<div class="navinfoitemtext">' .
					'<div class="navinfoitemtitle">' . $this->Language->Get('infobusergroup') . '</div><div class="navinfoitemcontent">' . StripName(htmlspecialchars($_userGroupCache[$_SWIFT_UserObject->GetProperty('usergroupid')]['title']), 20) . '</div></div>';
		}

		if ($_SWIFT_UserObject->GetProperty('lastvisit') != '0')
		{
			$_informationHTML .= '<div class="navinfoitemtext">' .
					'<div class="navinfoitemtitle">' . $this->Language->Get('infolastlogin') . '</div><div class="navinfoitemcontent">' . SWIFT_Date::Get(SWIFT_Date::TYPE_DATETIME, $_SWIFT_UserObject->GetProperty('lastvisit')) . '</div></div>';
		}

		// Begin Hook: staff_user_infobox
		unset($_hookCode);
		($_hookCode = SWIFT_Hook::Execute('staff_user_infobox')) ? eval($_hookCode) : false;
		// End Hook

		$this->UserInterface->AddNavigationBox($this->Language->Get('informationbox'), $_informationHTML);

		return true;
	}
}
?>