Spade

Mini Shell

Directory:~$ /proc/self/root/home/lmsyaran/public_html/css/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ //proc/self/root/home/lmsyaran/public_html/css/Helper.zip

PK�[q�
bootstrap.phpnu�[���<?php
/**
 * @version        4.3.0
 * @package        Joomla
 * @subpackage     Helpdesk Pro
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2013 - 2021 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

use Joomla\CMS\Factory;

class HelpdeskProHelperBootstrap
{
	/**
	 * Bootstrap Helper instance
	 *
	 * @var PMFormHelperBootstrap
	 */
	protected static $instance;

	/**
	 * Twitter bootstrap version, default 2
	 * @var string
	 */
	protected $bootstrapVersion;

	/**
	 * UI component
	 *
	 * @var MPFUiInterface
	 */
	protected $ui;

	/**
	 * The class mapping to map between twitter bootstrap 2 and twitter
bootstrap 3
	 * @var string
	 */
	protected static $classMaps;

	/**
	 * Get bootstrap helper object
	 *
	 * @return PMFormHelperBootstrap
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			$config = HelpdeskproHelper::getConfig();

			if (Factory::getApplication()->isClient('administrator')
&& version_compare(JVERSION, '3.9.99',
'<'))
			{
				self::$instance = new self('2');
			}
			else
			{
				self::$instance = new self($config->twitter_bootstrap_version);
			}
		}

		return static::$instance;
	}

	/**
	 * Constructor, initialize the classmaps array
	 *
	 * @param   string  $ui
	 * @param   array   $classMaps
	 *
	 * @throws Exception
	 */
	public function __construct($ui, $classMaps = [])
	{
		if (empty($ui))
		{
			$ui = 2;
		}

		switch ($ui)
		{
			case 2:
			case 3:
			case 4:
			case 5:
				$uiClass = 'HDPUiBootstrap' . $ui;
				break;
			default:
				$uiClass = 'HDPUi' . ucfirst($ui);
				break;
		}

		$this->bootstrapVersion = $ui;

		if (!class_exists($uiClass))
		{
			throw new Exception(sprintf('UI class %s not found',
$uiClass));
		}

		$this->ui = new $uiClass($classMaps);
	}

	/**
	 * Get the mapping of a given class
	 *
	 * @param   string  $class  The input class
	 *
	 * @return string The mapped class
	 */
	public function getClassMapping($class)
	{
		return $this->ui->getClassMapping($class);
	}

	/**
	 * Get twitter bootstrap version
	 *
	 * @return int|string
	 */
	public function getBootstrapVersion()
	{
		return $this->bootstrapVersion;
	}

	/**
	 * Method to get input with prepend add-on
	 *
	 * @param   string  $input
	 * @param   string  $addOn
	 *
	 * @return string
	 */
	public function getPrependAddon($input, $addOn)
	{
		return $this->ui->getPrependAddon($input, $addOn);
	}

	/**
	 * Method to get input with append add-on
	 *
	 * @param   string  $input
	 * @param   string  $addOn
	 *
	 * @return string
	 */
	public function getAppendAddon($input, $addOn)
	{
		return $this->ui->getAppendAddon($input, $addOn);
	}

	/**
	 * Get framework own css class
	 *
	 * @param   string  $class
	 * @param   int     $behavior
	 *
	 * @return string
	 */
	public function getFrameworkClass($class, $behavior = 0)
	{
		return $this->ui->getFrameworkClass($class, $behavior);
	}
}PK�[��Q��Database.phpnu�[���<?php
/**
 * @version        4.3.0
 * @package        Joomla
 * @subpackage     Helpdesk Pro
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2013 - 2021 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

namespace OSSolution\HelpdeskPro\Site\Helper;

use OSL\Container\Container;
use OSL\Utils\Database as DatabaseUtils;

defined('_JEXEC') or die;

class Database
{
	/**
	 * Get all published categories
	 *
	 * @param   string  $order
	 * @param   array   $filters
	 * @param   string  $fieldSuffix
	 * @param   int     $categoryType
	 *
	 * @return array
	 */
	public static function getAllCategories($order = 'title',
$filters = array(), $fieldSuffix = '', $categoryType = 1)
	{
		$db    = Container::getInstance('com_helpdeskpro')->db;
		$query = $db->getQuery(true);
		$query->select('id, parent_id, managers')
			->select($db->quoteName('title' . $fieldSuffix,
'title'))
			->from('#__helpdeskpro_categories')
			->where('published=1')
			->where('category_type IN (0, ' . $categoryType .
')')
			->order($order);

		foreach ($filters as $filter)
		{
			$query->where($filter);
		}

		$db->setQuery($query);

		return $db->loadObjectList();
	}

	/**
	 * Get all published statuses
	 *
	 * @param   string  $order
	 * @param   string  $fieldSuffix
	 *
	 * @return array
	 */
	public static function getAllStatuses($order = 'ordering',
$fieldSuffix = '')
	{
		$db    = Container::getInstance('com_helpdeskpro')->db;
		$query = $db->getQuery(true);
		$query->select('id, title')
			->from('#__helpdeskpro_statuses')
			->where('published=1')
			->order($order);

		if ($fieldSuffix)
		{
			DatabaseUtils::getMultilingualFields($query, array('title'),
$fieldSuffix);
		}

		$db->setQuery($query);

		return $db->loadObjectList();
	}

	/**
	 * Get all published priorities
	 *
	 * @param   string  $order
	 * @param   string  $fieldSuffix
	 *
	 * @return array
	 */
	public static function getAllPriorities($order = 'ordering',
$fieldSuffix = '')
	{
		$db    = Container::getInstance('com_helpdeskpro')->db;
		$query = $db->getQuery(true);
		$query->select('id, title')
			->from('#__helpdeskpro_priorities')
			->where('published=1')
			->order($order);

		if ($fieldSuffix)
		{
			DatabaseUtils::getMultilingualFields($query, array('title'),
$fieldSuffix);
		}

		$db->setQuery($query);

		return $db->loadObjectList();
	}

	/**
	 * Get all published labels
	 *
	 * @param   string  $order
	 *
	 * @return array
	 */
	public static function getAllLabels($order = 'title')
	{
		$db    = Container::getInstance('com_helpdeskpro')->db;
		$query = $db->getQuery(true);
		$query->select('id, title')
			->from('#__helpdeskpro_labels')
			->where('published=1')
			->order($order);
		$db->setQuery($query);

		return $db->loadObjectList();
	}

	/**
	 * Get all published labels
	 *
	 * @param   int  $staffGroupId
	 *
	 * @return array
	 */
	public static function getAllStaffs($staffGroupId)
	{
		$db           =
Container::getInstance('com_helpdeskpro')->db;
		$query        = $db->getQuery(true);
		$config       = Helper::getConfig();
		$displayField = $config->get('staff_display_field',
'username') ?: 'username';

		$query->select("a.id, a.username, a.name, a.email")
			->from("#__users AS a")
			->innerJoin("#__user_usergroup_map AS b ON a.id =
b.user_id")
			->where("group_id=" . (int) $staffGroupId)
			->order($displayField);
		$db->setQuery($query);

		return $db->loadObjectList();
	}

	/**
	 * Get all custom fields which will be displayed in list view
	 *
	 * @param   string  $fieldSuffix
	 *
	 * @return array
	 */
	public static function getFieldsOnListView($fieldSuffix = null)
	{
		$db    = Container::getInstance('com_helpdeskpro')->db;
		$query = $db->getQuery(true);

		$query->select('*')
			->from('#__helpdeskpro_fields')
			->where('show_in_list_view=1')
			->where('published=1')
			->order('ordering');

		if ($fieldSuffix)
		{
			DatabaseUtils::getMultilingualFields($query, array('title',
'description', 'values', 'default_values'),
$fieldSuffix);
		}

		$db->setQuery($query);

		return $db->loadObjectList();
	}
}PK�[×J�ѼѼ
Helper.phpnu�[���<?php
/**
 * @version        3.5.0
 * @package        Joomla
 * @subpackage     Helpdesk Pro
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2013 - 2019 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

namespace OSSolution\HelpdeskPro\Site\Helper;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Mail\MailHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\User\UserHelper;
use OSL\Utils\Database as DatabaseUtils;
use OSSolution\HelpdeskPro\Site\Helper\Route as RouteHelper;

defined('_JEXEC') or die;

class Helper
{
	/**
	 * Get current installed version of Helpdesk Pro
	 *
	 * @return string
	 */
	public static function getInstalledVersion()
	{
		return '4.1.0';
	}

	/**
	 * Helper method to check if the extension is running on Joomla 4
	 *
	 * @return bool
	 */
	public static function isJoomla4()
	{
		return version_compare(JVERSION, '4.0.0-dev', 'ge');
	}

	/**
	 * Get configuration data and store in config object
	 *
	 * @return \OSL\Config\Config
	 */
	public static function getConfig()
	{
		static $config;

		if (!$config)
		{
			$db    = Factory::getDbo();
			$query = $db->getQuery(true);
			$query->select('*')->from('#__helpdeskpro_configs');
			$db->setQuery($query);
			$rows = $db->loadObjectList();
			$data = [];

			foreach ($rows as $row)
			{
				$data[$row->config_key] = $row->config_value;
			}

			$config = new \OSL\Config\Config($data);
		}

		return $config;
	}

	/**
	 * Get the email messages used for sending emails
	 *
	 * @return \OSL\Config\Config
	 */
	public static function getEmailMessages()
	{
		static $message;

		if (!$message)
		{
			$db    = Factory::getDbo();
			$query = $db->getQuery(true);
			$query->select('*')->from('#__helpdeskpro_emails');
			$db->setQuery($query);
			$rows = $db->loadObjectList();
			$data = [];

			foreach ($rows as $row)
			{
				$data[$row->email_key] = $row->email_message;
			}

			$message = new \OSL\Config\Config($data);
		}

		return $message;
	}

	/**
	 * Get all custom fields assigned to certain category
	 *
	 * @param   int    $categoryId
	 * @param   array  $filters
	 *
	 * @return mixed
	 */
	public static function getFields($categoryId, $filters = [])
	{
		$db    = Factory::getDbo();
		$query = $db->getQuery(true);
		$query->select('id, name, fieldtype, title')
			->from('#__helpdeskpro_fields')
			->where('(category_id = -1 OR id IN (SELECT field_id FROM
#__helpdeskpro_field_categories WHERE category_id=' . (int)
$categoryId . '))')
			->where('published = 1');

		foreach ($filters as $filter)
		{
			$query->where($filter);
		}

		$db->setQuery($query);

		return $db->loadObjectList();
	}

	/**
	 * Get all custom fields
	 *
	 * @return array
	 */
	public static function getAllFields()
	{
		$db    = Factory::getDbo();
		$query = $db->getQuery(true);
		$query->select('*, extra AS extra_attributes, 0 AS max_length,
"" AS place_holder')
			->from('#__helpdeskpro_fields')
			->where('published = 1')
			->order('ordering');

		if ($fieldSuffix = Helper::getFieldSuffix())
		{
			\OSL\Utils\Database::getMultilingualFields($query, ['title',
'description', 'values', 'default_values'],
$fieldSuffix);
		}

		$db->setQuery($query);

		return $db->loadObjectList();
	}

	/**
	 * Get the association array contains the relationship between field and
categories
	 *
	 * @return array
	 */
	public static function getFieldCategoryRelation()
	{
		$db    = Factory::getDbo();
		$query = $db->getQuery(true);
		$query->select('id')
			->from('#__helpdeskpro_fields')
			->where('published = 1')
			->where('category_id = -1');
		$db->setQuery($query);

		$relation[0] = $db->loadColumn();

		$query->clear()
			->select('*')
			->from('#__helpdeskpro_field_categories');
		$db->setQuery($query);
		$fieldCategories = $db->loadObjectList();

		foreach ($fieldCategories as $fieldCategory)
		{
			$relation[$fieldCategory->category_id][] =
$fieldCategory->field_id;
		}


		return $relation;
	}

	/**
	 * Get specify config value
	 *
	 * @param   string  $key
	 *
	 * @return string
	 */
	public static function getConfigValue($key)
	{
		$config = static::getConfig();

		return $config->get($key);
	}

	/**
	 * Get Itemid of Helpdesk Pro componnent
	 *
	 * @return int
	 */
	public static function getItemid()
	{
		$db    = Factory::getDbo();
		$user  = Factory::getUser();
		$query = $db->getQuery(true);
		$query->select('id')
			->from('#__menu AS a')
			->where('a.link LIKE
"%index.php?option=com_helpdeskpro&view=tickets%"')
			->where('a.published=1')
			->where('a.access IN (' . implode(',',
$user->getAuthorisedViewLevels()) . ')');

		if (Multilanguage::isEnabled())
		{
			$query->where('a.language IN (' .
$db->quote(Factory::getLanguage()->getTag()) . ',' .
$db->Quote('*') . ')');
		}

		$query->order('a.access');
		$db->setQuery($query);
		$itemId = $db->loadResult();

		if (!$itemId)
		{
			$Itemid =
Factory::getApplication()->input->getInt('Itemid');

			if ($Itemid == 1)
			{
				$itemId = 999999;
			}
			else
			{
				$itemId = $Itemid;
			}
		}

		return $itemId;
	}

	/**
	 * Get field suffix used in sql query
	 *
	 * @param   string  $activeLanguage
	 *
	 * @return string
	 */
	public static function getFieldSuffix($activeLanguage = null)
	{
		$prefix = '';

		if (Multilanguage::isEnabled())
		{
			if (!$activeLanguage)
			{
				$activeLanguage = Factory::getLanguage()->getTag();
			}

			if ($activeLanguage != self::getDefaultLanguage())
			{
				$db    = Factory::getDbo();
				$query = $db->getQuery(true);
				$query->select('`sef`')
					->from('#__languages')
					->where('lang_code = ' . $db->quote($activeLanguage))
					->where('published = 1');
				$db->setQuery($query);
				$sef = $db->loadResult();

				if ($sef)
				{
					$prefix = '_' . $sef;
				}
			}
		}

		return $prefix;
	}

	/**
	 * load editable
	 */
	public static function loadEditable($loadJs = true)
	{
		$document = Factory::getDocument();
		$rootUri  = Uri::root(true);
		$config   = static::getConfig();

		if ($config->twitter_bootstrap_version === '4' &&
Factory::getApplication()->isClient('site'))
		{
			return;
		}

		if ($config->twitter_bootstrap_version == '3' &&
Factory::getApplication()->isClient('site'))
		{
			$editable = 'bs3editable';
		}
		else
		{
			$editable = 'editable';
		}

		$document->addStyleSheet($rootUri .
'/media/com_helpdeskpro/assets/js/' . $editable .
'/css/bootstrap-editable.css');

		if ($loadJs)
		{
			$document->addScript($rootUri .
'/media/com_helpdeskpro/assets/js/' . $editable .
'/js/bootstrap-editable.min.js');
		}
	}

	/**
	 * Load highlighter script so that the code will be highlighted
	 */
	public static function loadHighlighter()
	{
		$config             = self::getConfig();
		$supportedLanguages = explode(',',
$config->programming_languages);
		$syntaxPath         = Uri::root(true) .
'/media/com_helpdeskpro/assets/js/syntaxhighlighter3/';
		$document           = Factory::getDocument();
		$document->addScript($syntaxPath . 'scripts/shCore.js');
		$languages = [
			'AS3',
			'Bash',
			'Cpp',
			'CSharp',
			'Css',
			'Delphi',
			'Diff',
			'Groovy',
			'Java',
			'JavaFX',
			'JScript',
			'Perl',
			'Php',
			'Plain',
			'PowerShell',
			'Python',
			'Ruby',
			'Scala',
			'Sql',
			'Vb',
			'Xml'];

		foreach ($languages as $language)
		{
			if (in_array($language, $supportedLanguages))
			{
				$document->addScript($syntaxPath . 'scripts/shBrush' .
$language . '.js');
			}
		}

		$theme = 'Default';
		$document->addStyleSheet($syntaxPath . 'styles/shCore' .
$theme . '.css');
		$document->addStyleSheet($syntaxPath . 'styles/shTheme' .
$theme . '.css');
		$document->addScriptDeclaration('
			  SyntaxHighlighter.all();
		 ');
	}

	/**
	 *
	 *
	 * @return string
	 */
	public static function validateEngine()
	{
		$dateNow    = HTMLHelper::_('date', Factory::getDate(),
'Y/m/d');
		$validClass = [
			"",
			"validate[custom[integer]]",
			"validate[custom[number]]",
			"validate[custom[email]]",
			"validate[custom[url]]",
			"validate[custom[phone]]",
			"validate[custom[date],past[$dateNow]]",
			"validate[custom[ipv4]]",
			"validate[minSize[6]]",
			"validate[maxSize[12]]",
			"validate[custom[integer],min[-5]]",
			"validate[custom[integer],max[50]]"];

		return json_encode($validClass);
	}

	/**
	 *
	 * Get role of the given user
	 *
	 * @param $userId
	 *
	 * @return mixed
	 */
	public static function getUserRole($userId = 0)
	{
		static $roles = [];

		if (!$userId)
		{
			$userId = Factory::getUser()->id;
		}

		if (!isset($roles[$userId]))
		{
			$role = 'user';

			if ($userId)
			{
				$user = Factory::getUser($userId);

				if ($user->authorise('core.admin',
'com_helpdeskpro'))
				{
					$role = 'admin';
				}
				else
				{
					$manageCategoryIds =
Helper::getTicketCategoryIds($user->username);

					if (count($manageCategoryIds) >= 1 && $manageCategoryIds[0]
!= 0)
					{
						$role = 'manager';
					}
					else
					{
						$config = self::getConfig();

						if ($config->staff_group_id)
						{
							$staffs = Database::getAllStaffs($config->staff_group_id);

							foreach ($staffs as $staff)
							{
								if ($staff->id == $userId)
								{
									$role = 'staff';
									break;
								}
							}
						}
					}
				}
			}

			$roles[$userId] = $role;
		}

		return $roles[$userId];
	}

	/**
	 * Get list of current online users
	 *
	 * @return array
	 */
	public static function getOnlineUsers()
	{
		$db    = Factory::getDbo();
		$query = $db->getQuery(true);
		$query->select('DISTINCT u.id');
		$query->from('#__session AS s');
		$query->innerJoin('#__users AS u ON s.userid = u.id');
		$query->where('s.guest = 0');
		$db->setQuery($query);

		return $db->loadColumn();
	}

	/**
	 * Load language from main component
	 *
	 */
	public static function loadLanguage()
	{
		static $loaded;

		if (!$loaded)
		{
			$lang = Factory::getLanguage();
			$tag  = $lang->getTag();

			if (!$tag)
			{
				$tag = 'en-GB';
			}

			$lang->load('com_helpdeskpro', JPATH_ROOT, $tag);
			$loaded = true;
		}
	}

	/**
	 * Display copy right information
	 *
	 */
	public static function displayCopyRight()
	{
		echo '<div class="copyright clearfix row-fluid"
style="text-align:center;margin-top: 5px;"><a
href="http://joomdonation.com/components/helpdesk-pro.html"
target="_blank"><strong>Helpdesk
Pro</strong></a> version ' . self::getInstalledVersion() .
', Copyright (C) 2012 - ' . date('Y') . ' <a
href="http://joomdonation.com"
target="_blank"><strong>Ossolution
Team</strong></a></div>';
	}

	/**
	 * Get ticket categories managed by the given user
	 *
	 * @param   string  $username
	 *
	 * @return array
	 */
	public static function getTicketCategoryIds($username)
	{
		static $categories = [];

		if (!isset($categories[$username]))
		{
			$db    = Factory::getDbo();
			$query = $db->getQuery(true);
			$query->select('id')
				->from('#__helpdeskpro_categories')
				->where("managers='$username' OR managers LIKE
'$username,%' OR managers LIKE '%,$username,%' OR
managers LIKE '%,$username'");
			$db->setQuery($query);

			$categoryIds = $db->loadColumn();

			if (!count($categoryIds))
			{
				$categoryIds = [0];
			}

			$categories[$username] = $categoryIds;
		}

		return $categories[$username];
	}

	/**
	 * Method to check to see whether the user can edit the comment
	 *
	 * @param   \JUser  $user
	 * @param   int     $id
	 *
	 * @return bool
	 */
	public static function canUpdateComment($user, $id)
	{
		if (static::isJoomla4())
		{
			return false;
		}

		// User has edit permission in helpdesk pro will be able to edit the
comment
		if ($user->authorise('core.edit',
'com_helpdeskpro'))
		{
			return true;
		}

		// Owner of the ticket can edit the comment
		$db    = Factory::getDbo();
		$query = $db->getQuery(true);
		$query->select('user_id')
			->from('#__helpdeskpro_messages')
			->where('id = ' . $id);
		$db->setQuery($query);
		$message = $db->loadObject();

		if ($message && $user->id && ($message->user_id ==
$user->id) && $user->authorise('core.editown',
'com_helpdeskpro'))
		{
			return true;
		}

		// Otherwise, he could not edit the comment
		return false;
	}

	/**
	 * Helper methd to check to see whether the user can edit the comment
	 *
	 * @param   \JUser  $user
	 * @param           $id
	 *
	 * @return bool
	 */
	public static function canDeleteComment($user, $id)
	{
		// User has edit permission in helpdesk pro will be able to edit the
comment
		if ($user->authorise('core.delete',
'com_helpdeskpro'))
		{
			return true;
		}

		// Owner of the ticket can edit the comment
		$db    = Factory::getDbo();
		$query = $db->getQuery(true);
		$query->select('user_id')
			->from('#__helpdeskpro_messages')
			->where('id = ' . $id);
		$db->setQuery($query);
		$message = $db->loadObject();

		if ($message && $user->id && ($message->user_id ==
$user->id))
		{
			return true;
		}

		// Otherwise, he could not edit the comment

		return false;
	}

	/**
	 * Check ticket access
	 *
	 * @param   \Ossolution\HelpdeskPro\Admin\Table\Ticket  $item
	 *
	 * @return bool
	 */
	public static function checkTicketAccess($item)
	{
		$user   = Factory::getUser();
		$config = Helper::getConfig();

		if (!$item->id)
		{
			return false;
		}

		if ($item->is_ticket_code &&
$config->allow_public_user_submit_ticket)
		{
			return true;
		}

		if (!$user->id)
		{
			return false;
		}

		if ($user->id == $item->user_id || $user->email ==
$item->email)
		{
			return true;
		}

		if ($user->id == $item->staff_id)
		{
			return true;
		}

		if ($user->authorise('core.admin',
'com_helpdeskpro'))
		{
			return true;
		}

		$managedCategoryIds =
Helper::getTicketCategoryIds($user->get('username'));

		if (in_array($item->category_id, $managedCategoryIds))
		{
			return true;
		}

		return false;
	}

	/**
	 * Get CB avatar of the given user to display on the ticket
	 *
	 * @param   int  $userId
	 *
	 * @return string relative path to the avatar
	 */
	public static function getCBAvatar($userId)
	{
		static $avatars;

		if (!isset($avatars[$userId]))
		{
			$db    = Factory::getDbo();
			$query = $db->getQuery(true);
			$query->select('avatar')
				->from('#__comprofiler')
				->where('user_id=' . $userId . ' AND
avatarapproved=1');
			$db->setQuery($query);
			$avatar = $db->loadResult();
			if (!$avatar)
				$avatar = '';
			$avatars[$userId] = $avatar;
		}

		return $avatars[$userId];
	}

	/**
	 * This function is used to check to see whether we need to update the
database to support multilingual or not
	 *
	 * @return boolean
	 */
	public static function isSyncronized()
	{
		$db             = Factory::getDbo();
		$fields         =
$db->getTableColumns('#__helpdeskpro_categories');
		$fields         = array_keys($fields);
		$extraLanguages = self::getLanguages(self::getDefaultLanguage());

		if (count($extraLanguages))
		{
			foreach ($extraLanguages as $extraLanguage)
			{
				$prefix = $extraLanguage->sef;

				if (!in_array('title_' . $prefix, $fields))
				{
					return false;
				}
			}
		}

		return true;
	}

	/**
	 * Syncronize Helpdesk Pro database to support multilingual
	 */
	public static function setupMultilingual()
	{
		$db        = Factory::getDbo();
		$languages = self::getLanguages();

		if (count($languages))
		{
			foreach ($languages as $language)
			{
				#Process for #__helpdeskpro_categories table							
				$prefix = $language->sef;
				$fields =
array_keys($db->getTableColumns('#__helpdeskpro_categories'));

				if (!in_array('title_' . $prefix, $fields))
				{
					$fieldName = 'title_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_categories` ADD 
`$fieldName` VARCHAR( 255 );";
					$db->setQuery($sql);
					$db->execute();

					$fieldName = 'description_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_categories` ADD 
`$fieldName` TEXT NULL;";
					$db->setQuery($sql);
					$db->execute();
				}

				if (!in_array('alias_' . $prefix, $fields))
				{
					$fieldName = 'alias_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_categories` ADD 
`$fieldName` VARCHAR( 255 );";
					$db->setQuery($sql);
					$db->execute();
				}

				#Process for #__helpdeskpro_statuses table
				$fields =
array_keys($db->getTableColumns('#__helpdeskpro_statuses'));
				if (!in_array('title_' . $prefix, $fields))
				{
					$fieldName = 'title_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_statuses` ADD 
`$fieldName` VARCHAR( 255 );";
					$db->setQuery($sql);
					$db->execute();
				}

				#Process for #__helpdeskpro_priorities table
				$fields =
array_keys($db->getTableColumns('#__helpdeskpro_priorities'));
				if (!in_array('title_' . $prefix, $fields))
				{
					$fieldName = 'title_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_priorities` ADD 
`$fieldName` VARCHAR( 255 );";
					$db->setQuery($sql);
					$db->execute();
				}

				#Process for #__helpdeskpro_fields table
				$fields =
array_keys($db->getTableColumns('#__helpdeskpro_fields'));
				if (!in_array('title_' . $prefix, $fields))
				{
					$fieldName = 'title_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_fields` ADD 
`$fieldName` VARCHAR( 255 );";
					$db->setQuery($sql);
					$db->execute();

					$fieldName = 'description_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_fields` ADD 
`$fieldName` TEXT NULL;";
					$db->setQuery($sql);
					$db->execute();

					$fieldName = 'values_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_fields` ADD 
`$fieldName` TEXT NULL;";
					$db->setQuery($sql);
					$db->execute();

					$fieldName = 'default_values_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_fields` ADD 
`$fieldName` TEXT NULL;";
					$db->setQuery($sql);
					$db->execute();
				}

				// Process for #__helpdeskpro_articles tabl
				$fields =
array_keys($db->getTableColumns('#__helpdeskpro_articles'));

				if (!in_array('title_' . $prefix, $fields))
				{
					$fieldName = 'title_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_articles` ADD 
`$fieldName` VARCHAR( 255 );";
					$db->setQuery($sql);
					$db->execute();

					$fieldName = 'text_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_articles` ADD 
`$fieldName` TEXT NULL;";
					$db->setQuery($sql);
					$db->execute();
				}

				if (!in_array('alias_' . $prefix, $fields))
				{
					$fieldName = 'alias_' . $prefix;
					$sql       = "ALTER TABLE  `#__helpdeskpro_articles` ADD 
`$fieldName` VARCHAR( 255 );";
					$db->setQuery($sql);
					$db->execute();
				}
			}
		}
	}

	/**
	 * Process BB code for the given message
	 *
	 * @param   string  $message
	 *
	 * @return string
	 */
	public static function processBBCode($message)
	{
		require_once JPATH_ROOT .
'/administrator/components/com_helpdeskpro/libraries/bbcodeparser.php';

		$config = self::getConfig();

		if (!$config->use_html_editor)
		{
			$message = nl2br($message);
		}

		return \BBCodeParser::parse($message);
	}

	/**
	 *  Method to add ticket or comment attachments to mailer for sending
emails
	 *
	 * @param   \JMail  $mailer
	 * @param   object  $row
	 */
	protected static function addAttachmentsToMailer($mailer, $row)
	{
		$originalFileNames = explode('|',
$row->original_filenames);
		$attachments       = explode('|', $row->attachments);

		for ($i = 0, $n = count($attachments); $i < $n; $i++)
		{
			$attachment       = $attachments[$i];
			$originalFileName = $originalFileNames[$i];

			if (file_exists(JPATH_ROOT .
'/media/com_helpdeskpro/attachments/' . $attachment))
			{
				$mailer->addAttachment(JPATH_ROOT .
'/media/com_helpdeskpro/attachments/' . $attachment,
$originalFileName);
			}
		}
	}

	/**
	 * Send email to super administrator and user
	 *
	 * @param   object  $row     The message object
	 * @param   object  $ticket  The ticket object
	 * @param   object  $config
	 */
	public static function sendTicketUpdatedEmailToCustomer($row, $ticket,
$config)
	{
		$user        = Factory::getUser();
		$mailer      = static::getMailer();
		$db          = Factory::getDbo();
		$message     = self::getEmailMessages();
		$fieldSuffix = self::getFieldSuffix($ticket->language);

		$query = $db->getQuery(true)
			->select('name')
			->from('#__users')
			->where('id = ' . (int) $row->user_id);
		$db->setQuery($query);
		$manageName = $db->loadResult();

		$replaces = self::getCommonTicketTags($ticket, $config);

		if ($config->use_html_editor)
		{
			$replaces['ticket_comment'] = $row->message;
		}
		else
		{
			$replaces['ticket_comment'] = nl2br($row->message);
		}

		$replaces['manager_name'] = $manageName;

		if ($fieldSuffix &&
$message->{'ticket_updated_user_email_subject' .
$fieldSuffix})
		{
			$subject = $message->{'ticket_updated_user_email_subject' .
$fieldSuffix};
		}
		else
		{
			$subject = $message->ticket_updated_user_email_subject;
		}

		if ($fieldSuffix &&
strlen(strip_tags($message->{'ticket_updated_user_email_body'
. $fieldSuffix})))
		{
			$body = $message->{'ticket_updated_user_email_body' .
$fieldSuffix};
		}
		else
		{
			$body = $message->ticket_updated_user_email_body;
		}

		foreach ($replaces as $key => $value)
		{
			$key     = strtoupper($key);
			$body    = str_replace("[$key]", $value, $body);
			$subject = str_replace("[$key]", $value, $subject);
		}

		if ($config->notify_manager_when_staff_reply &&
($ticket->staff_id == $user->id))
		{
			// Staff reply to ticket
			$emails = static::getTicketNotificationEmails($ticket);
			$mailer->addBcc($emails);
		}
		elseif ($config->notify_other_managers_when_a_manager_reply &&
$ticket->staff_id != $user->id)
		{
			// Admin or manager reply to a ticket
			$emails = static::getTicketNotificationEmails($ticket);

			// Exclude email of the current manager from receiving notification
			$emails = array_diff($emails, [$user->email]);

			if (count($emails))
			{
				$mailer->addBcc($emails);
			}
		}

		// Add ticket attachments to email if configured
		if ($config->send_ticket_attachments_to_email &&
$row->attachments)
		{
			static::addAttachmentsToMailer($mailer, $row);
		}

		if ($ticket->user_id)
		{
			$userEmail = static::getUserEmail($ticket->user_id);

			if ($userEmail != $ticket->email)
			{
				$ticket->email = $userEmail;

				$query->clear()
					->update('#__helpdeskpro_tickets')
					->set('email = ' . $db->quote($userEmail))
					->where('user_id = ' . $ticket->user_id);
				$db->setQuery($query)
					->execute();
			}
		}


		static::send($mailer, [$ticket->email], $subject, $body);
	}

	/**
	 * Send email to super administrator and user
	 *
	 * @param   object  $row     The message object
	 * @param   object  $ticket  The ticket object
	 * @param   object  $config
	 */
	public static function sendTicketUpdatedEmailToManagers($row, $ticket,
$config)
	{
		$mailer      = static::getMailer();
		$message     = self::getEmailMessages();
		$fieldSuffix = self::getFieldSuffix($ticket->language);

		$replaces = self::getCommonTicketTags($ticket, $config);

		if ($config->use_html_editor)
		{
			$replaces['ticket_comment'] = $row->message;
		}
		else
		{
			$replaces['ticket_comment'] = nl2br($row->message);
		}

		$emails = static::getTicketNotificationEmails($ticket, true);

		if ($message->{'ticket_updated_admin_email_subject' .
$fieldSuffix})
		{
			$subject = $message->{'ticket_updated_admin_email_subject'
. $fieldSuffix};
		}
		else
		{
			$subject = $message->ticket_updated_admin_email_subject;
		}

		if
(strlen(strip_tags($message->{'ticket_updated_admin_email_body'
. $fieldSuffix})))
		{
			$body = $message->{'ticket_updated_admin_email_body' .
$fieldSuffix};
		}
		else
		{
			$body = $message->ticket_updated_admin_email_body;
		}

		foreach ($replaces as $key => $value)
		{
			$key     = strtoupper($key);
			$body    = str_replace("[$key]", $value, $body);
			$subject = str_replace("[$key]", $value, $subject);
		}

		// Add ticket attachments to email if configured
		if ($config->send_ticket_attachments_to_email &&
$row->attachments)
		{
			static::addAttachmentsToMailer($mailer, $row);
		}

		static::send($mailer, $emails, $subject, $body);
	}

	/**
	 * Send email to super administrator and user
	 *
	 * @param   object  $row     The message object
	 * @param   object  $ticket  The ticket object
	 * @param   object  $config
	 */
	public static function sendNewTicketNotificationEmails($row, $config)
	{
		$mailer      = static::getMailer();
		$message     = self::getEmailMessages();
		$fieldSuffix = self::getFieldSuffix($row->language);

		$replaces = self::getCommonTicketTags($row, $config);

		$emails = static::getTicketNotificationEmails($row);

		if ($message->{'new_ticket_admin_email_subject' .
$fieldSuffix})
		{
			$subject = $message->{'new_ticket_admin_email_subject' .
$fieldSuffix};
		}
		else
		{
			$subject = $message->new_ticket_admin_email_subject;
		}

		if
(strlen(strip_tags($message->{'new_ticket_admin_email_body' .
$fieldSuffix})))
		{
			$body = $message->{'new_ticket_admin_email_body' .
$fieldSuffix};
		}
		else
		{
			$body = $message->new_ticket_admin_email_body;
		}

		foreach ($replaces as $key => $value)
		{
			$body    = str_ireplace("[$key]", $value, $body);
			$subject = str_ireplace("[$key]", $value, $subject);
		}

		// Add ticket attachments to email if configured
		if ($config->send_ticket_attachments_to_email &&
$row->attachments)
		{
			static::addAttachmentsToMailer($mailer, $row);
		}

		static::send($mailer, $emails, $subject, $body);

		$mailer->clearAllRecipients();
		$mailer->clearAttachments();

		if (!MailHelper::isEmailAddress($row->email))
		{
			return;
		}

		//Send email to user
		if ($message->{'new_ticket_user_email_subject' .
$fieldSuffix})
		{
			$subject = $message->{'new_ticket_user_email_subject' .
$fieldSuffix};
		}
		else
		{
			$subject = $message->new_ticket_user_email_subject;
		}

		if
(strlen(strip_tags($message->{'new_ticket_user_email_body' .
$fieldSuffix})))
		{
			$body = $message->{'new_ticket_user_email_body' .
$fieldSuffix};
		}
		else
		{
			$body = $message->new_ticket_user_email_body;
		}

		foreach ($replaces as $key => $value)
		{
			$body    = str_ireplace("[$key]", $value, $body);
			$subject = str_ireplace("[$key]", $value, $subject);
		}

		if ($row->user_id)
		{
			$userEmail = static::getUserEmail($row->user_id);

			if ($userEmail != $row->email)
			{
				$row->email = $userEmail;

				$db    = Factory::getDbo();
				$query = $db->getQuery(true)
					->update('#__helpdeskpro_tickets')
					->set('email = ' . $db->quote($userEmail))
					->where('user_id = ' . $row->user_id);
				$db->setQuery($query)
					->execute();
			}
		}

		static::send($mailer, [$row->email], $subject, $body);
	}

	/**
	 * Send Ticket assigned email
	 *
	 * @param   object  $row
	 * @param   object  $config
	 */
	public static function sendTicketAssignedEmails($row, $config)
	{
		if (!$row->staff_id)
		{
			return;
		}

		$mailer                   = static::getMailer();
		$message                  = self::getEmailMessages();
		$fieldSuffix              = self::getFieldSuffix($row->language);
		$replaces                 = self::getCommonTicketTags($row, $config);
		$replaces['MANAGER_NAME'] = Factory::getUser()->name;

		if ($message->{'customer_ticket_assigned_email_subject' .
$fieldSuffix})
		{
			$subject =
$message->{'customer_ticket_assigned_email_subject' .
$fieldSuffix};
		}
		else
		{
			$subject = $message->customer_ticket_assigned_email_subject;
		}

		if
(strlen(strip_tags($message->{'customer_ticket_assigned_email_body'
. $fieldSuffix})))
		{
			$body = $message->{'customer_ticket_assigned_email_body' .
$fieldSuffix};
		}
		else
		{
			$body = $message->customer_ticket_assigned_email_body;
		}

		foreach ($replaces as $key => $value)
		{
			$body    = str_ireplace("[$key]", $value, $body);
			$subject = str_ireplace("[$key]", $value, $subject);
		}

		static::send($mailer, [$row->email], $subject, $body);

		$mailer->clearAllRecipients();

		// Get staff email
		$db    = Factory::getDbo();
		$query = $db->getQuery(true)
			->select('email')
			->from('#__users')
			->where('id = ' . $row->staff_id);
		$db->setQuery($query);
		$staffEmail = $db->loadResult();

		if (!MailHelper::isEmailAddress($staffEmail))
		{
			return;
		}

		//Send email to staff
		if ($message->{'ticket_assiged_email_subject' .
$fieldSuffix})
		{
			$subject = $message->{'ticket_assiged_email_subject' .
$fieldSuffix};
		}
		else
		{
			$subject = $message->ticket_assiged_email_subject;
		}

		if (strlen(strip_tags($message->{'ticket_assiged_email_body'
. $fieldSuffix})))
		{
			$body = $message->{'ticket_assiged_email_body' .
$fieldSuffix};
		}
		else
		{
			$body = $message->ticket_assiged_email_body;
		}

		foreach ($replaces as $key => $value)
		{
			$body    = str_ireplace("[$key]", $value, $body);
			$subject = str_ireplace("[$key]", $value, $subject);
		}

		static::send($mailer, [$staffEmail], $subject, $body);
	}


	/**
	 * Send ticket closed email to customer
	 *
	 * @param $row
	 * @param $config
	 */
	public static function sendTicketClosedEmail($row, $config)
	{
		$user = Factory::getUser();

		$mailer      = static::getMailer();
		$message     = self::getEmailMessages();
		$fieldSuffix = self::getFieldSuffix($row->language);
		$replaces    = self::getCommonTicketTags($row, $config);

		// Customer close ticket, sending email to managers
		if ($user->id == $row->user_id)
		{
			if ($message->{'manager_ticket_closed_email_subject' .
$fieldSuffix})
			{
				$subject =
$message->{'manager_ticket_closed_email_subject' .
$fieldSuffix};
			}
			else
			{
				$subject = $message->manager_ticket_closed_email_subject;
			}

			if
(strlen(strip_tags($message->{'manager_ticket_closed_email_body'
. $fieldSuffix})))
			{
				$body = $message->{'manager_ticket_closed_email_body' .
$fieldSuffix};
			}
			else
			{
				$body = $message->manager_ticket_closed_email_body;
			}

			foreach ($replaces as $key => $value)
			{
				$body    = str_ireplace("[$key]", $value, $body);
				$subject = str_ireplace("[$key]", $value, $subject);
			}

			// Get all managers + staff email
			$emails = static::getTicketNotificationEmails($row, true);

			static::send($mailer, $emails, $subject, $body);

			return;
		}

		// Manager or staff closes ticket, send notification email to customer
		$replaces['MANAGER_NAME'] = Factory::getUser()->name;

		if ($message->{'customer_ticket_closed_email_subject' .
$fieldSuffix})
		{
			$subject =
$message->{'customer_ticket_closed_email_subject' .
$fieldSuffix};
		}
		else
		{
			$subject = $message->customer_ticket_closed_email_subject;
		}

		if
(strlen(strip_tags($message->{'customer_ticket_closed_email_body'
. $fieldSuffix})))
		{
			$body = $message->{'customer_ticket_closed_email_body' .
$fieldSuffix};
		}
		else
		{
			$body = $message->customer_ticket_closed_email_body;
		}

		foreach ($replaces as $key => $value)
		{
			$body    = str_ireplace("[$key]", $value, $body);
			$subject = str_ireplace("[$key]", $value, $subject);
		}

		static::send($mailer, [$row->email], $subject, $body);
	}

	/**
	 * Send ticket status change email to customer
	 *
	 * @param $row
	 * @param $config
	 */
	public static function sendTicketStatusChangeEmail($row, $oldStatus,
$newStatus, $config)
	{
		$user = Factory::getUser();

		$mailer      = static::getMailer();
		$db          = Factory::getDbo();
		$message     = self::getEmailMessages();
		$fieldSuffix = self::getFieldSuffix($row->language);
		$replaces    = self::getCommonTicketTags($row, $config);

		$query = $db->getQuery(true)
			->select('title')
			->from('#__helpdeskpro_statuses')
			->where('id = ' . (int) $oldStatus);

		if ($fieldSuffix)
		{
			DatabaseUtils::getMultilingualFields($query, ['title'],
$fieldSuffix);
		}

		$db->setQuery($query);

		$replaces['old_status'] = $db->loadResult();

		$query->clear('where')
			->where('id = ' . (int) $newStatus);
		$db->setQuery($query);

		$replaces['new_status'] = $db->loadResult();

		// Customer close ticket, sending email to managers
		if ($user->id == $row->user_id)
		{
			if
($message->{'manager_ticket_status_changed_email_subject' .
$fieldSuffix})
			{
				$subject =
$message->{'manager_ticket_status_changed_email_subject' .
$fieldSuffix};
			}
			else
			{
				$subject = $message->manager_ticket_status_changed_email_subject;
			}

			if
(strlen(strip_tags($message->{'manager_ticket_status_changed_email_body'
. $fieldSuffix})))
			{
				$body =
$message->{'manager_ticket_status_changed_email_body' .
$fieldSuffix};
			}
			else
			{
				$body = $message->manager_ticket_status_changed_email_body;
			}

			foreach ($replaces as $key => $value)
			{
				$body    = str_ireplace("[$key]", $value, $body);
				$subject = str_ireplace("[$key]", $value, $subject);
			}

			// Get all managers + staff emails
			$emails = static::getTicketNotificationEmails($row, true);

			static::send($mailer, $emails, $subject, $body);

			return;
		}

		// Manager or staff change ticket status, send notification email to
customer
		$replaces['MANAGER_NAME'] = Factory::getUser()->name;

		if
($message->{'customer_ticket_status_changed_email_subject' .
$fieldSuffix})
		{
			$subject =
$message->{'customer_ticket_status_changed_email_subject' .
$fieldSuffix};
		}
		else
		{
			$subject = $message->customer_ticket_status_changed_email_subject;
		}

		if
(strlen(strip_tags($message->{'customer_ticket_status_changed_email_body'
. $fieldSuffix})))
		{
			$body =
$message->{'customer_ticket_status_changed_email_body' .
$fieldSuffix};
		}
		else
		{
			$body = $message->customer_ticket_status_changed_email_body;
		}

		foreach ($replaces as $key => $value)
		{
			$body    = str_ireplace("[$key]", $value, $body);
			$subject = str_ireplace("[$key]", $value, $subject);
		}

		static::send($mailer, [$row->email], $subject, $body);
	}

	/**
	 * Get common tags related to ticket and use it for sending emails
	 *
	 * @param   \OSSolution\HelpdeskPro\Admin\Table\Ticket  $row
	 * @param   \stdClass                                   $config
	 *
	 * @return array
	 */
	public static function getCommonTicketTags($row, $config)
	{
		$siteUrl     = Uri::root();
		$fieldSuffix = self::getFieldSuffix($row->language);
		$db          = Factory::getDbo();
		$query       = $db->getQuery(true);
		$replaces    = [];

		$replaces['ticket_id']      = $row->id;
		$replaces['ticket_subject'] = $row->subject;
		$replaces['name']           = $row->name;
		$replaces['email']          = $row->email;

		if ($row->staff_id)
		{
			$query->clear()
				->select('name')
				->from('#__users')
				->where('id = ' . (int) $row->staff_id);
			$db->setQuery($query);
			$replaces['staff_name'] = $db->loadResult();
		}
		else
		{
			$replaces['staff_name'] = '';
		}

		if ($config->use_html_editor)
		{
			$replaces['ticket_message'] = $row->message;
		}
		else
		{
			$replaces['ticket_message'] = nl2br($row->message);
		}

		$replaces['frontend_link']               = $siteUrl .
RouteHelper::getTicketRoute($row->id);
		$replaces['backend_link']                = $siteUrl .
'administrator/index.php?option=com_helpdeskpro&view=ticket&id='
. $row->id;
		$replaces['frontend_link_without_login'] = $siteUrl .
RouteHelper::getTicketRoute($row->ticket_code, false);

		$query->clear()
			->select('id, name, title')
			->from('#__helpdeskpro_fields')
			->where('published=1')
			->where('(category_id = -1 OR id IN (SELECT field_id FROM
#__helpdeskpro_field_categories WHERE category_id=' .
$row->category_id . '))')
			->order('ordering');
		$db->setQuery($query);
		$rowFields = $db->loadObjectList();
		$fields    = [];

		for ($i = 0, $n = count($rowFields); $i < $n; $i++)
		{
			$rowField              = $rowFields[$i];
			$fields[$rowField->id] = $rowField->name;
		}

		$query->clear()
			->select('*')
			->from('#__helpdeskpro_field_value')
			->where('ticket_id = ' . $row->id);
		$db->setQuery($query);
		$rowValues = $db->loadObjectList();

		for ($i = 0, $n = count($rowValues); $i < $n; $i++)
		{
			$rowValue                               = $rowValues[$i];
			$replaces[$fields[$rowValue->field_id]] = $rowValue->field_value;
		}

		$query->clear()
			->select('name')
			->from('#__helpdeskpro_fields');
		$db->setQuery($query);
		$fields = $db->loadColumn();

		foreach ($fields as $field)
		{
			if (!isset($replaces[$field]))
			{
				$replaces[$field] = '';
			}
		}

		$query->clear()
			->select($db->quoteName('title' . $fieldSuffix))
			->from('#__helpdeskpro_categories')
			->where('id = ' . $row->category_id);
		$db->setQuery($query);
		$replaces['ticket_category'] =
$replaces['category_title'] = $db->loadResult();

		// Ticket status
		$query->clear()
			->select($db->quoteName('title' . $fieldSuffix))
			->from('#__helpdeskpro_statuses')
			->where('id = ' . (int) $row->status_id);
		$db->setQuery($query);
		$replaces['ticket_status'] = $db->loadResult();

		// Ticket priority
		$query->clear()
			->select($db->quoteName('title' . $fieldSuffix))
			->from('#__helpdeskpro_priorities')
			->where('id = ' . (int) $row->priority_id);
		$db->setQuery($query);
		$replaces['ticket_priority'] = $db->loadResult();

		return $replaces;
	}

	/**
	 *
	 * Function to get all available languages except the default language
	 * @return array object list
	 */
	public static function getLanguages()
	{
		$db      = Factory::getDbo();
		$query   = $db->getQuery(true);
		$default = self::getDefaultLanguage();
		$query->select('lang_id, lang_code, title, `sef`')
			->from('#__languages')
			->where('published = 1')
			->where('lang_code != "' . $default .
'"')
			->order('ordering');
		$db->setQuery($query);
		$languages = $db->loadObjectList();

		return $languages;
	}

	/**
	 * Get front-end default language
	 * @return string
	 */
	public static function getDefaultLanguage()
	{
		$params = ComponentHelper::getParams('com_languages');

		return $params->get('site', 'en-GB');
	}

	/**
	 * Get formatted file size of a file
	 *
	 * @param   string  $filePath
	 *
	 * @return string
	 */
	public static function getSize($filePath)
	{
		$kb   = 1024;
		$mb   = 1024 * $kb;
		$gb   = 1024 * $mb;
		$tb   = 1024 * $gb;
		$size = @filesize($filePath);

		if ($size)
		{
			if ($size < $kb)
			{
				$final    = round($size, 2);
				$fileSize = $final . ' ' . 'Byte';
			}
			elseif ($size < $mb)
			{
				$final    = round($size / $kb, 2);
				$fileSize = $final . ' ' . 'KB';
			}
			elseif ($size < $gb)
			{
				$final    = round($size / $mb, 2);
				$fileSize = $final . ' ' . 'MB';
			}
			elseif ($size < $tb)
			{
				$final    = round($size / $gb, 2);
				$fileSize = $final . ' ' . 'GB';
			}
			else
			{
				$final    = round($size / $tb, 2);
				$fileSize = $final . ' ' . 'TB';
			}
		}
		else
		{
			if ($size == 0)
			{
				$fileSize = 'EMPTY';
			}
			else
			{
				$fileSize = 'ERROR';
			}
		}

		return $fileSize;
	}

	/**
	 * Store ticket from input data
	 *
	 * @param   array  $data
	 *
	 * @return bool
	 */
	public static function storeTicket($data)
	{
		jimport('joomla.user.helper');

		$container =
\OSL\Container\Container::getInstance('com_helpdeskpro');

		$db     = $container->db;
		$user   = $container->user;
		$config = Helper::getConfig();

		$row = $container->factory->createTable('Ticket', $db);
		$row->bind($data);

		if ($user->get('id'))
		{
			$row->user_id = $user->get('id');
		}
		else
		{
			$sql = 'SELECT id FROM #__users WHERE email=' .
$db->quote($data['email']);
			$db->setQuery($sql);
			$row->user_id = $db->loadResult();
		}

		$row->status_id = $config->new_ticket_status_id;

		while (true)
		{
			$ticketCode = strtolower(UserHelper::genRandomPassword(10));
			$sql        = 'SELECT COUNT(*) FROM #__helpdeskpro_tickets WHERE
ticket_code=' . $db->quote($ticketCode);
			$db->setQuery($sql);
			$total = $db->loadResult();

			if (!$total)
			{
				break;
			}
		}

		$row->ticket_code  = $ticketCode;
		$row->created_date = $row->modified_date = gmdate('Y-m-d
H:i:s');
		$row->store(); //Store custom fields information for this ticket	

		Helper::sendNewTicketNotificationEmails($row, $config);

		return true;
	}

	/**
	 * Get email of user
	 *
	 * @param   int  $userId
	 *
	 * @return string
	 */
	public static function getUserEmail($userId)
	{
		$db    = Factory::getDbo();
		$query = $db->getQuery(true)
			->select('email')
			->from('#__users')
			->where('id = ' . (int) $userId);
		$db->setQuery($query);

		return $db->loadResult();
	}

	/**
	 * Get avatar of user
	 *
	 * @param   int  $userId
	 *
	 * @return string
	 */
	public static function getUserAvatar($userId)
	{
		static $avatars = [];

		if (!isset($avatars[$userId]))
		{
			// Default avatar
			$avatars[$userId] =
'media/com_helpdeskpro/assets/images/icons/icon-user.jpeg';

			$db    = Factory::getDbo();
			$query = $db->getQuery(true);

			if (ComponentHelper::isInstalled('com_comprofiler') &&
ComponentHelper::isEnabled('com_comprofiler'))
			{
				$query->select('avatar')
					->from('#__comprofiler')
					->where('user_id=' . $userId . ' AND avatarapproved
= 1');
				$db->setQuery($query);
				$avatar = $db->loadResult();

				if ($avatar && file_exists(JPATH_ROOT .
'/images/comprofiler/' . $avatar))
				{
					$avatars[$userId] = 'images/comprofiler/' . $avatar;
				}
			}
			elseif (ComponentHelper::isInstalled('com_kunena') &&
ComponentHelper::isEnabled('com_kunena'))
			{
				$query->select('avatar')
					->from('#__kunena_users')
					->where('userid=' . $userId);
				$db->setQuery($query);
				$avatar = $db->loadResult();

				if ($avatar && file_exists(JPATH_ROOT .
'/media/kunena/avatars/resized/size72/' . $avatar))
				{
					$avatars[$userId] = 'media/kunena/avatars/resized/size72/' .
$avatar;
				}
			}
		}

		return $avatars[$userId];
	}


	/**
	 * Get Notification Emails for a given ticket
	 *
	 * @param   \Joomla\CMS\Table\Table  $ticket
	 *
	 * @return array
	 */
	public static function getTicketNotificationEmails($ticket,
$includeStaffEmail = false)
	{
		$config = static::getConfig();
		$db     = Factory::getDbo();
		$query  = $db->getQuery(true)
			->select('managers')
			->from('#__helpdeskpro_categories')
			->where('id = ' . (int) $ticket->category_id);
		$db->setQuery($query);
		$managers = trim($db->loadResult());

		if ($managers)
		{
			$managers = explode(',', $managers);
			$managers = array_map('trim', $managers);
			$query->clear()
				->select('email')
				->from('#__users')
				->where('username IN ("' .
implode('","', $managers) . '")');
			$db->setQuery($query);
			$emails = $db->loadColumn();
		}
		else
		{
			$config = static::getConfig();
			$emails = array_map('trim', explode(',',
$config->notification_emails));
		}

		if ($includeStaffEmail &&
$config->notify_staff_when_customer_reply &&
$ticket->staff_id)
		{
			$db    = Factory::getDbo();
			$query = $db->getQuery(true)
				->select('email')
				->from('#__users')
				->where('id = ' . (int) $ticket->staff_id);
			$db->setQuery($query);
			$email = $db->loadResult();

			if (MailHelper::isEmailAddress($email))
			{
				$emails[] = $email;
			}
		}

		return $emails;
	}

	/**
	 * Create and initialize mailer object from configuration data
	 *
	 * @return \JMail
	 */
	public static function getMailer()
	{
		$mailer = Factory::getMailer();
		$config = static::getConfig();

		if ($config->reply_to_email)
		{
			$mailer->addReplyTo($config->reply_to_email);
		}

		if ($config->from_name)
		{
			$fromName = $config->from_name;
		}
		else
		{
			$fromName = Factory::getConfig()->get('fromname');
		}

		if ($config->from_email)
		{
			$fromEmail = $config->from_email;
		}
		else
		{
			$fromEmail = Factory::getConfig()->get('mailfrom');
		}

		$mailer->setSender([$fromEmail, $fromName]);

		$mailer->isHtml(true);

		return $mailer;
	}

	/**
	 * Process sending after all the data has been initialized
	 *
	 * @param   \JMail  $mailer
	 * @param   array   $emails
	 * @param   string  $subject
	 * @param   string  $body
	 *
	 */
	public static function send($mailer, $emails, $subject, $body)
	{
		if (empty($subject))
		{
			return;
		}

		$emails = (array) $emails;

		$emails = array_map('trim', $emails);

		for ($i = 0, $n = count($emails); $i < $n; $i++)
		{
			if (!MailHelper::isEmailAddress($emails[$i]))
			{
				unset($emails[$i]);
			}
		}

		$emails = array_unique($emails);

		if (count($emails) == 0)
		{
			return;
		}

		$email = $emails[0];
		$mailer->addRecipient($email);

		if (count($emails) > 1)
		{
			unset($emails[0]);
			$bccEmails = $emails;
			$mailer->addBcc($bccEmails);
		}

		$body = static::convertImgTags($body);

		try
		{
			$mailer->setSubject($subject)
				->setBody($body)
				->Send();
		}
		catch (\Exception $e)
		{
			Factory::getApplication()->enqueueMessage($e->getMessage(),
'warning');
		}
	}

	/**
	 * Convert all img tags to use absolute URL
	 *
	 * @param   string  $text
	 *
	 * @return string
	 */
	public static function convertImgTags($text)
	{
		$app = Factory::getApplication();

		$siteUrl    = Uri::root();
		$rootURL    = rtrim(Uri::root(), '/');
		$subpathURL = Uri::root(true);

		if (!empty($subpathURL) && ($subpathURL != '/'))
		{
			$rootURL = substr($rootURL, 0, -1 * strlen($subpathURL));
		}

		// Replace index.php URI by SEF URI.
		if (strpos($text, 'href="index.php?') !== false)
		{
			preg_match_all('#href="index.php\?([^"]+)"#m',
$text, $matches);

			foreach ($matches[1] as $urlQueryString)
			{

				if ($app->isClient('site'))
				{
					$text = str_replace(
						'href="index.php?' . $urlQueryString .
'"',
						'href="' . $rootURL . Route::_('index.php?'
. $urlQueryString) . '"',
						$text
					);
				}
				else
				{
					$text = str_replace(
						'href="index.php?' . $urlQueryString .
'"',
						'href="' . $siteUrl . 'index.php?' .
$urlQueryString . '"',
						$text
					);
				}
			}
		}

		$patterns     = [];
		$replacements = [];
		$i            = 0;
		$src_exp      = "/src=\"(.*?)\"/";
		$link_exp     =
"[^http:\/\/www\.|^www\.|^https:\/\/|^http:\/\/]";

		preg_match_all($src_exp, $text, $out, PREG_SET_ORDER);

		foreach ($out as $val)
		{
			$links = preg_match($link_exp, $val[1], $match, PREG_OFFSET_CAPTURE);

			if ($links == '0')
			{
				$patterns[$i]     = $val[1];
				$patterns[$i]     = "\"$val[1]";
				$replacements[$i] = $siteUrl . $val[1];
				$replacements[$i] = "\"$replacements[$i]";
			}

			$i++;
		}

		$text = str_replace($patterns, $replacements, $text);

		return $text;
	}
}PK�[a��800Html.phpnu�[���<?php
/**
 * @version        4.3.0
 * @package        Joomla
 * @subpackage     Helpdesk Pro
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2013 - 2021 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

namespace OSSolution\HelpdeskPro\Site\Helper;

use Joomla\CMS\Filesystem\File;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Table\Table;
use Joomla\Registry\Registry;
use OSL\Container\Container;

defined('_JEXEC') or die;

class Html
{
	/**
	 * Render ShowOn string
	 *
	 * @param array $fields
	 *
	 * @return string
	 */
	public static function renderShowOn($fields)
	{
		$output = [];

		$i = 0;

		foreach ($fields as $name => $values)
		{
			$i++;

			$values = (array) $values;

			$data = [
				'field'  => $name,
				'values' => $values,
				'sign'   => '=',
			];

			$data['op'] = $i > 1 ? 'AND' : '';

			$output[] = json_encode($data);
		}

		return '[' . implode(',', $output) . ']';
	}

	public static function buildCategoryDropdown($selected, $name =
'parent_id', $attr = null, $rows = [])
	{
		if (empty($rows))
		{
			$db    = Container::getInstance('com_helpdeskpro')->db;
			$query = $db->getQuery(true);
			$query->select('id, parent_id, title')
				->from('#__helpdeskpro_categories')
				->where('category_type IN (0, 1)')
				->where('published=1');
			$db->setQuery($query);
			$rows = $db->loadObjectList();
		}

		$children = [];

		if ($rows)
		{
			// first pass - collect children
			foreach ($rows as $v)
			{
				$pt   = (int) $v->parent_id;
				$list = @$children[$pt] ? $children[$pt] : [];
				array_push($list, $v);
				$children[$pt] = $list;
			}
		}

		$list      = HTMLHelper::_('menu.treerecurse', 0, '',
[], $children, 9999, 0, 0);
		$options   = [];
		$options[] = HTMLHelper::_('select.option', '0',
Text::_('HDP_SELECT_CATEGORY'));

		foreach ($list as $item)
		{
			$options[] = HTMLHelper::_('select.option', $item->id,
'&nbsp;&nbsp;&nbsp;' . $item->treename);
		}

		return HTMLHelper::_('select.genericlist', $options, $name,
			[
				'option.text.toHtml' => false,
				'option.text'        => 'text',
				'option.value'       => 'value',
				'list.attr'          => $attr,
				'list.select'        => $selected]);
	}

	/**
	 * Function to render a common layout which is used in different views
	 *
	 * @param string $layout
	 * @param array  $data
	 *
	 * @return string
	 * @throws \Exception
	 */
	public static function loadCommonLayout($layout, $data = [])
	{
		$app       =
Container::getInstance('com_helpdeskpro')->app;
		$themeFile = str_replace('/tmpl', '', $layout);

		if (File::exists($layout))
		{
			$path = $layout;
		}
		elseif (File::exists(JPATH_THEMES . '/' .
$app->getTemplate() . '/html/com_helpdeskpro/' . $themeFile))
		{
			$path = JPATH_THEMES . '/' . $app->getTemplate() .
'/html/com_helpdeskpro/' . $themeFile;
		}
		elseif (File::exists(JPATH_ROOT .
'/components/com_helpdeskpro/View/' . $layout))
		{
			$path = JPATH_ROOT . '/components/com_helpdeskpro/View/' .
$layout;
		}
		else
		{
			throw new \RuntimeException(Text::_('The given shared template path
is not exist'));
		}

		// Start an output buffer.
		ob_start();
		extract($data);

		// Load the layout.
		include $path;

		// Get the layout contents.
		return ob_get_clean();
	}

	/**
	 * Get page params of the given view
	 *
	 * @param $active
	 * @param $views
	 *
	 * @return Registry
	 */
	public static function getViewParams($active, $views)
	{
		if ($active && isset($active->query['view'])
&& in_array($active->query['view'], $views))
		{
			return $active->getParams();
		}

		return new Registry();
	}

	/**
	 * Helper method to prepare meta data for the document
	 *
	 * @param Registry $params
	 *
	 * @param Table  $item
	 */
	public static function prepareDocument($params, $item = null)
	{
		$container = Container::getInstance('com_helpdeskpro');

		$document = $container->document;
		$config   = $container->appConfig;

		$siteNamePosition = $config->get('sitename_pagetitles');
		$pageTitle        = $params->get('page_title');

		if ($pageTitle)
		{
			if ($siteNamePosition == 0)
			{
				$document->setTitle($pageTitle);
			}
			elseif ($siteNamePosition == 1)
			{
				$document->setTitle($config->get('sitename') . ' -
' . $pageTitle);
			}
			else
			{
				$document->setTitle($pageTitle . ' - ' .
$config->get('sitename'));
			}
		}

		if (!empty($item->meta_keywords))
		{
			$document->setMetaData('keywords',
$item->meta_keywords);
		}
		elseif ($params->get('menu-meta_keywords'))
		{
			$document->setMetaData('keywords',
$params->get('menu-meta_keywords'));
		}

		if (!empty($item->meta_description))
		{
			$document->setMetaData('description',
$item->meta_description);
		}
		elseif ($params->get('menu-meta_description'))
		{
			$document->setDescription($params->get('menu-meta_description'));
		}

		if ($params->get('robots'))
		{
			$document->setMetaData('robots',
$params->get('robots'));
		}
	}
}PK�[E.����
Jquery.phpnu�[���<?php
/**
 * @version            3.8
 * @package            Joomla
 * @subpackage         Joom Donation
 * @author             Tuan Pham Ngoc
 * @copyright          Copyright (C) 2009 - 2019 Ossolution Team
 * @license            GNU/GPL, see LICENSE.php
 */

namespace OSSolution\HelpdeskPro\Site\Helper;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;

class Jquery
{
	/**
	 * validate form
	 */
	public static function validateForm()
	{
		static $loaded = false;

		if (!$loaded)
		{
			$rootUri  = Uri::root(true);
			$document = Factory::getDocument();
			$document->addStyleSheet($rootUri .
'/media/com_helpdeskpro/assets/js/validate/css/validationEngine.jquery.css');

			// Add possible language files for jquery validation engine
			$tag   = Factory::getLanguage()->getTag();
			$tag   = substr($tag, 0, 2);
			$files = [
				"jquery.validationEngine-$tag.custom.js",
				"jquery.validationEngine-$tag.js",
				"jquery.validationEngine-en.js",
			];

			foreach ($files as $file)
			{
				if (file_exists(JPATH_ROOT .
'/media/com_helpdeskpro/assets/js/validate/js/languages/' .
$file))
				{
					$document->addScript($rootUri .
'/media/com_helpdeskpro/assets/js/validate/js/languages/' .
$file);
					break;
				}
			}

			// Add validation engine
			$document->addScript($rootUri .
'/media/com_helpdeskpro/assets/js/validate/js/jquery.validationEngine.js');

			$loaded = true;
		}
	}
}PK�[se�tXMXMmime.mapping.phpnu�[���<?php
return array(
	'__MAXPERIOD__' => '1',
	'3ds'           => 'image/x-3ds',
	'BLEND'         => 'application/x-blender',
	'C'             => 'text/x-c++src',
	'CSSL'          => 'text/css',
	'NSV'           => 'video/x-nsv',
	'XM'            => 'audio/x-mod',
	'Z'             => 'application/x-compress',
	'a'             => 'application/x-archive',
	'abw'           => 'application/x-abiword',
	'abw.gz'        => 'application/x-abiword',
	'ac3'           => 'audio/ac3',
	'adb'           => 'text/x-adasrc',
	'ads'           => 'text/x-adasrc',
	'afm'           => 'application/x-font-afm',
	'ag'            => 'image/x-applix-graphics',
	'ai'            => 'application/illustrator',
	'aif'           => 'audio/x-aiff',
	'aifc'          => 'audio/x-aiff',
	'aiff'          => 'audio/x-aiff',
	'al'            => 'application/x-perl',
	'arj'           => 'application/x-arj',
	'as'            =>
'application/x-applix-spreadsheet',
	'asc'           => 'text/plain',
	'asf'           => 'video/x-ms-asf',
	'asp'           => 'application/x-asp',
	'asx'           => 'video/x-ms-asf',
	'au'            => 'audio/basic',
	'avi'           => 'video/x-msvideo',
	'aw'            => 'application/x-applix-word',
	'bak'           => 'application/x-trash',
	'bcpio'         => 'application/x-bcpio',
	'bdf'           => 'application/x-font-bdf',
	'bib'           => 'text/x-bibtex',
	'bin'           => 'application/octet-stream',
	'blend'         => 'application/x-blender',
	'blender'       => 'application/x-blender',
	'bmp'           => 'image/bmp',
	'bz'            => 'application/x-bzip',
	'bz2'           => 'application/x-bzip',
	'c'             => 'text/x-csrc',
	'c++'           => 'text/x-c++src',
	'cc'            => 'text/x-c++src',
	'cdf'           => 'application/x-netcdf',
	'cdr'           => 'application/vnd.corel-draw',
	'cer'           => 'application/x-x509-ca-cert',
	'cert'          => 'application/x-x509-ca-cert',
	'cgi'           => 'application/x-cgi',
	'cgm'           => 'image/cgm',
	'chrt'          => 'application/x-kchart',
	'class'         => 'application/x-java',
	'cls'           => 'text/x-tex',
	'cpio'          => 'application/x-cpio',
	'cpio.gz'       =>
'application/x-cpio-compressed',
	'cpp'           => 'text/x-c++src',
	'cpt'           => 'application/mac-compactpro',
	'crt'           => 'application/x-x509-ca-cert',
	'cs'            => 'text/x-csharp',
	'csh'           => 'application/x-shellscript',
	'css'           => 'text/css',
	'csv'           =>
'text/x-comma-separated-values',
	'cur'           => 'image/x-win-bitmap',
	'cxx'           => 'text/x-c++src',
	'dat'           => 'video/mpeg',
	'dbf'           => 'application/x-dbase',
	'dc'            => 'application/x-dc-rom',
	'dcl'           => 'text/x-dcl',
	'dcm'           => 'image/x-dcm',
	'dcr'           => 'application/x-director',
	'deb'           => 'application/x-deb',
	'der'           => 'application/x-x509-ca-cert',
	'desktop'       => 'application/x-desktop',
	'dia'           => 'application/x-dia-diagram',
	'diff'          => 'text/x-patch',
	'dir'           => 'application/x-director',
	'djv'           => 'image/vnd.djvu',
	'djvu'          => 'image/vnd.djvu',
	'dll'           => 'application/octet-stream',
	'dms'           => 'application/octet-stream',
	'doc'           => 'application/msword',
	'dsl'           => 'text/x-dsl',
	'dtd'           => 'text/x-dtd',
	'dvi'           => 'application/x-dvi',
	'dwg'           => 'image/vnd.dwg',
	'dxf'           => 'image/vnd.dxf',
	'dxr'           => 'application/x-director',
	'egon'          => 'application/x-egon',
	'el'            => 'text/x-emacs-lisp',
	'eps'           => 'image/x-eps',
	'epsf'          => 'image/x-eps',
	'epsi'          => 'image/x-eps',
	'etheme'        => 'application/x-e-theme',
	'etx'           => 'text/x-setext',
	'exe'           => 'application/x-executable',
	'ez'            => 'application/andrew-inset',
	'f'             => 'text/x-fortran',
	'fig'           => 'image/x-xfig',
	'fits'          => 'image/x-fits',
	'flac'          => 'audio/x-flac',
	'flc'           => 'video/x-flic',
	'fli'           => 'video/x-flic',
	'flw'           => 'application/x-kivio',
	'fo'            => 'text/x-xslfo',
	'g3'            => 'image/fax-g3',
	'gb'            => 'application/x-gameboy-rom',
	'gcrd'          => 'text/x-vcard',
	'gen'           => 'application/x-genesis-rom',
	'gg'            => 'application/x-sms-rom',
	'gif'           => 'image/gif',
	'glade'         => 'application/x-glade',
	'gmo'           =>
'application/x-gettext-translation',
	'gnc'           => 'application/x-gnucash',
	'gnucash'       => 'application/x-gnucash',
	'gnumeric'      => 'application/x-gnumeric',
	'gra'           => 'application/x-graphite',
	'gsf'           => 'application/x-font-type1',
	'gtar'          => 'application/x-gtar',
	'gz'            => 'application/x-gzip',
	'h'             => 'text/x-chdr',
	'h++'           => 'text/x-chdr',
	'hdf'           => 'application/x-hdf',
	'hh'            => 'text/x-c++hdr',
	'hp'            => 'text/x-chdr',
	'hpgl'          => 'application/vnd.hp-hpgl',
	'hqx'           => 'application/mac-binhex40',
	'hs'            => 'text/x-haskell',
	'htm'           => 'text/html',
	'html'          => 'text/html',
	'icb'           => 'image/x-icb',
	'ice'           => 'x-conference/x-cooltalk',
	'ico'           => 'image/x-ico',
	'ics'           => 'text/calendar',
	'idl'           => 'text/x-idl',
	'ief'           => 'image/ief',
	'ifb'           => 'text/calendar',
	'iff'           => 'image/x-iff',
	'iges'          => 'model/iges',
	'igs'           => 'model/iges',
	'ilbm'          => 'image/x-ilbm',
	'iso'           => 'application/x-cd-image',
	'it'            => 'audio/x-it',
	'jar'           => 'application/x-jar',
	'java'          => 'text/x-java',
	'jng'           => 'image/x-jng',
	'jp2'           => 'image/jpeg2000',
	'jpg'           => 'image/jpeg',
	'jpe'           => 'image/jpeg',
	'jpeg'          => 'image/jpeg',
	'jpr'           =>
'application/x-jbuilder-project',
	'jpx'           =>
'application/x-jbuilder-project',
	'js'            => 'application/x-javascript',
	'kar'           => 'audio/midi',
	'karbon'        => 'application/x-karbon',
	'kdelnk'        => 'application/x-desktop',
	'kfo'           => 'application/x-kformula',
	'kil'           => 'application/x-killustrator',
	'kon'           => 'application/x-kontour',
	'kpm'           => 'application/x-kpovmodeler',
	'kpr'           => 'application/x-kpresenter',
	'kpt'           => 'application/x-kpresenter',
	'kra'           => 'application/x-krita',
	'ksp'           => 'application/x-kspread',
	'kud'           => 'application/x-kugar',
	'kwd'           => 'application/x-kword',
	'kwt'           => 'application/x-kword',
	'la'            =>
'application/x-shared-library-la',
	'latex'         => 'application/x-latex',
	'lha'           => 'application/x-lha',
	'lhs'           => 'text/x-literate-haskell',
	'lhz'           => 'application/x-lhz',
	'log'           => 'text/x-log',
	'ltx'           => 'text/x-tex',
	'lwo'           => 'image/x-lwo',
	'lwob'          => 'image/x-lwo',
	'lws'           => 'image/x-lws',
	'lyx'           => 'application/x-lyx',
	'lzh'           => 'application/x-lha',
	'lzo'           => 'application/x-lzop',
	'm'             => 'text/x-objcsrc',
	'm15'           => 'audio/x-mod',
	'm3u'           => 'audio/x-mpegurl',
	'man'           => 'application/x-troff-man',
	'md'            => 'application/x-genesis-rom',
	'me'            => 'text/x-troff-me',
	'mesh'          => 'model/mesh',
	'mgp'           => 'application/x-magicpoint',
	'mid'           => 'audio/midi',
	'midi'          => 'audio/midi',
	'mif'           => 'application/x-mif',
	'mkv'           => 'application/x-matroska',
	'mm'            => 'text/x-troff-mm',
	'mml'           => 'text/mathml',
	'mng'           => 'video/x-mng',
	'moc'           => 'text/x-moc',
	'mod'           => 'audio/x-mod',
	'moov'          => 'video/quicktime',
	'mov'           => 'video/quicktime',
	'movie'         => 'video/x-sgi-movie',
	'mp2'           => 'video/mpeg',
	'mp3'           => 'audio/x-mp3',
	'mpe'           => 'video/mpeg',
	'mpeg'          => 'video/mpeg',
	'mpg'           => 'video/mpeg',
	'mpga'          => 'audio/mpeg',
	'ms'            => 'text/x-troff-ms',
	'msh'           => 'model/mesh',
	'msod'          => 'image/x-msod',
	'msx'           => 'application/x-msx-rom',
	'mtm'           => 'audio/x-mod',
	'mxu'           => 'video/vnd.mpegurl',
	'n64'           => 'application/x-n64-rom',
	'nc'            => 'application/x-netcdf',
	'nes'           => 'application/x-nes-rom',
	'nsv'           => 'video/x-nsv',
	'o'             => 'application/x-object',
	'obj'           => 'application/x-tgif',
	'oda'           => 'application/oda',
	'odb'           =>
'application/vnd.oasis.opendocument.database',
	'odc'           =>
'application/vnd.oasis.opendocument.chart',
	'odf'           =>
'application/vnd.oasis.opendocument.formula',
	'odg'           =>
'application/vnd.oasis.opendocument.graphics',
	'odi'           =>
'application/vnd.oasis.opendocument.image',
	'odm'           =>
'application/vnd.oasis.opendocument.text-master',
	'odp'           =>
'application/vnd.oasis.opendocument.presentation',
	'ods'           =>
'application/vnd.oasis.opendocument.spreadsheet',
	'odt'           =>
'application/vnd.oasis.opendocument.text',
	'ogg'           => 'application/ogg',
	'old'           => 'application/x-trash',
	'oleo'          => 'application/x-oleo',
	'otg'           =>
'application/vnd.oasis.opendocument.graphics-template',
	'oth'           =>
'application/vnd.oasis.opendocument.text-web',
	'otp'           =>
'application/vnd.oasis.opendocument.presentation-template',
	'ots'           =>
'application/vnd.oasis.opendocument.spreadsheet-template',
	'ott'           =>
'application/vnd.oasis.opendocument.text-template',
	'p'             => 'text/x-pascal',
	'p12'           => 'application/x-pkcs12',
	'p7s'           => 'application/pkcs7-signature',
	'pas'           => 'text/x-pascal',
	'patch'         => 'text/x-patch',
	'pbm'           => 'image/x-portable-bitmap',
	'pcd'           => 'image/x-photo-cd',
	'pcf'           => 'application/x-font-pcf',
	'pcf.Z'         => 'application/x-font-type1',
	'pcl'           => 'application/vnd.hp-pcl',
	'pdb'           => 'application/vnd.palm',
	'pdf'           => 'application/pdf',
	'pem'           => 'application/x-x509-ca-cert',
	'perl'          => 'application/x-perl',
	'pfa'           => 'application/x-font-type1',
	'pfb'           => 'application/x-font-type1',
	'pfx'           => 'application/x-pkcs12',
	'pgm'           => 'image/x-portable-graymap',
	'pgn'           => 'application/x-chess-pgn',
	'pgp'           => 'application/pgp',
	'php'           => 'application/x-php',
	'php3'          => 'application/x-php',
	'php4'          => 'application/x-php',
	'pict'          => 'image/x-pict',
	'pict1'         => 'image/x-pict',
	'pict2'         => 'image/x-pict',
	'pl'            => 'application/x-perl',
	'pls'           => 'audio/x-scpls',
	'pm'            => 'application/x-perl',
	'png'           => 'image/png',
	'pnm'           => 'image/x-portable-anymap',
	'po'            => 'text/x-gettext-translation',
	'pot'           =>
'application/vnd.ms-powerpoint',
	'ppm'           => 'image/x-portable-pixmap',
	'pps'           =>
'application/vnd.ms-powerpoint',
	'ppt'           =>
'application/vnd.ms-powerpoint',
	'ppz'           =>
'application/vnd.ms-powerpoint',
	'ps'            => 'application/postscript',
	'ps.gz'         => 'application/x-gzpostscript',
	'psd'           => 'image/x-psd',
	'psf'           => 'application/x-font-linux-psf',
	'psid'          => 'audio/prs.sid',
	'pw'            => 'application/x-pw',
	'py'            => 'application/x-python',
	'pyc'           =>
'application/x-python-bytecode',
	'pyo'           =>
'application/x-python-bytecode',
	'qif'           => 'application/x-qw',
	'qt'            => 'video/quicktime',
	'qtvr'          => 'video/quicktime',
	'ra'            => 'audio/x-pn-realaudio',
	'ram'           => 'audio/x-pn-realaudio',
	'rar'           => 'application/x-rar',
	'ras'           => 'image/x-cmu-raster',
	'rdf'           => 'text/rdf',
	'rej'           => 'application/x-reject',
	'rgb'           => 'image/x-rgb',
	'rle'           => 'image/rle',
	'rm'            => 'audio/x-pn-realaudio',
	'roff'          => 'application/x-troff',
	'rpm'           => 'application/x-rpm',
	'rss'           => 'text/rss',
	'rtf'           => 'application/rtf',
	'rtx'           => 'text/richtext',
	's3m'           => 'audio/x-s3m',
	'sam'           => 'application/x-amipro',
	'scm'           => 'text/x-scheme',
	'sda'           =>
'application/vnd.stardivision.draw',
	'sdc'           =>
'application/vnd.stardivision.calc',
	'sdd'           =>
'application/vnd.stardivision.impress',
	'sdp'           =>
'application/vnd.stardivision.impress',
	'sds'           =>
'application/vnd.stardivision.chart',
	'sdw'           =>
'application/vnd.stardivision.writer',
	'sgi'           => 'image/x-sgi',
	'sgl'           =>
'application/vnd.stardivision.writer',
	'sgm'           => 'text/sgml',
	'sgml'          => 'text/sgml',
	'sh'            => 'application/x-shellscript',
	'shar'          => 'application/x-shar',
	'shtml'         => 'text/html',
	'siag'          => 'application/x-siag',
	'sid'           => 'audio/prs.sid',
	'sik'           => 'application/x-trash',
	'silo'          => 'model/mesh',
	'sit'           => 'application/x-stuffit',
	'skd'           => 'application/x-koan',
	'skm'           => 'application/x-koan',
	'skp'           => 'application/x-koan',
	'skt'           => 'application/x-koan',
	'slk'           => 'text/spreadsheet',
	'smd'           =>
'application/vnd.stardivision.mail',
	'smf'           =>
'application/vnd.stardivision.math',
	'smi'           => 'application/smil',
	'smil'          => 'application/smil',
	'sml'           => 'application/smil',
	'sms'           => 'application/x-sms-rom',
	'snd'           => 'audio/basic',
	'so'            => 'application/x-sharedlib',
	'spd'           => 'application/x-font-speedo',
	'spl'           => 'application/x-futuresplash',
	'sql'           => 'text/x-sql',
	'src'           => 'application/x-wais-source',
	'stc'           =>
'application/vnd.sun.xml.calc.template',
	'std'           =>
'application/vnd.sun.xml.draw.template',
	'sti'           =>
'application/vnd.sun.xml.impress.template',
	'stm'           => 'audio/x-stm',
	'stw'           =>
'application/vnd.sun.xml.writer.template',
	'sty'           => 'text/x-tex',
	'sun'           => 'image/x-sun-raster',
	'sv4cpio'       => 'application/x-sv4cpio',
	'sv4crc'        => 'application/x-sv4crc',
	'svg'           => 'image/svg+xml',
	'swf'           =>
'application/x-shockwave-flash',
	'sxc'           => 'application/vnd.sun.xml.calc',
	'sxd'           => 'application/vnd.sun.xml.draw',
	'sxg'           =>
'application/vnd.sun.xml.writer.global',
	'sxi'           =>
'application/vnd.sun.xml.impress',
	'sxm'           => 'application/vnd.sun.xml.math',
	'sxw'           =>
'application/vnd.sun.xml.writer',
	'sylk'          => 'text/spreadsheet',
	't'             => 'application/x-troff',
	'tar'           => 'application/x-tar',
	'tar.Z'         => 'application/x-tarz',
	'tar.bz'        =>
'application/x-bzip-compressed-tar',
	'tar.bz2'       =>
'application/x-bzip-compressed-tar',
	'tar.gz'        => 'application/x-compressed-tar',
	'tar.lzo'       => 'application/x-tzo',
	'tcl'           => 'text/x-tcl',
	'tex'           => 'text/x-tex',
	'texi'          => 'text/x-texinfo',
	'texinfo'       => 'text/x-texinfo',
	'tga'           => 'image/x-tga',
	'tgz'           => 'application/x-compressed-tar',
	'theme'         => 'application/x-theme',
	'tif'           => 'image/tiff',
	'tiff'          => 'image/tiff',
	'tk'            => 'text/x-tcl',
	'torrent'       => 'application/x-bittorrent',
	'tr'            => 'application/x-troff',
	'ts'            => 'application/x-linguist',
	'tsv'           => 'text/tab-separated-values',
	'ttf'           => 'application/x-font-ttf',
	'txt'           => 'text/plain',
	'tzo'           => 'application/x-tzo',
	'ui'            => 'application/x-designer',
	'uil'           => 'text/x-uil',
	'ult'           => 'audio/x-mod',
	'uni'           => 'audio/x-mod',
	'uri'           => 'text/x-uri',
	'url'           => 'text/x-uri',
	'ustar'         => 'application/x-ustar',
	'vcd'           => 'application/x-cdlink',
	'vcf'           => 'text/x-vcalendar',
	'vcs'           => 'text/x-vcalendar',
	'vct'           => 'text/x-vcard',
	'vfb'           => 'text/calendar',
	'vob'           => 'video/mpeg',
	'voc'           => 'audio/x-voc',
	'vor'           =>
'application/vnd.stardivision.writer',
	'vrml'          => 'model/vrml',
	'vsd'           => 'application/vnd.visio',
	'wav'           => 'audio/x-wav',
	'wax'           => 'audio/x-ms-wax',
	'wb1'           => 'application/x-quattropro',
	'wb2'           => 'application/x-quattropro',
	'wb3'           => 'application/x-quattropro',
	'wbmp'          => 'image/vnd.wap.wbmp',
	'wbxml'         => 'application/vnd.wap.wbxml',
	'wk1'           => 'application/vnd.lotus-1-2-3',
	'wk3'           => 'application/vnd.lotus-1-2-3',
	'wk4'           => 'application/vnd.lotus-1-2-3',
	'wks'           => 'application/vnd.lotus-1-2-3',
	'wm'            => 'video/x-ms-wm',
	'wma'           => 'audio/x-ms-wma',
	'wmd'           => 'application/x-ms-wmd',
	'wmf'           => 'image/x-wmf',
	'wml'           => 'text/vnd.wap.wml',
	'wmlc'          => 'application/vnd.wap.wmlc',
	'wmls'          => 'text/vnd.wap.wmlscript',
	'wmlsc'         =>
'application/vnd.wap.wmlscriptc',
	'wmv'           => 'video/x-ms-wmv',
	'wmx'           => 'video/x-ms-wmx',
	'wmz'           => 'application/x-ms-wmz',
	'wpd'           => 'application/wordperfect',
	'wpg'           => 'application/x-wpg',
	'wri'           => 'application/x-mswrite',
	'wrl'           => 'model/vrml',
	'wvx'           => 'video/x-ms-wvx',
	'xac'           => 'application/x-gnucash',
	'xbel'          => 'application/x-xbel',
	'xbm'           => 'image/x-xbitmap',
	'xcf'           => 'image/x-xcf',
	'xcf.bz2'       => 'image/x-compressed-xcf',
	'xcf.gz'        => 'image/x-compressed-xcf',
	'xht'           => 'application/xhtml+xml',
	'xhtml'         => 'application/xhtml+xml',
	'xi'            => 'audio/x-xi',
	'xls'           => 'application/vnd.ms-excel',
	'xla'           => 'application/vnd.ms-excel',
	'xlc'           => 'application/vnd.ms-excel',
	'xld'           => 'application/vnd.ms-excel',
	'xll'           => 'application/vnd.ms-excel',
	'xlm'           => 'application/vnd.ms-excel',
	'xlt'           => 'application/vnd.ms-excel',
	'xlw'           => 'application/vnd.ms-excel',
	'xm'            => 'audio/x-xm',
	'xml'           => 'text/xml',
	'xpm'           => 'image/x-xpixmap',
	'xsl'           => 'text/x-xslt',
	'xslfo'         => 'text/x-xslfo',
	'xslt'          => 'text/x-xslt',
	'xwd'           => 'image/x-xwindowdump',
	'xyz'           => 'chemical/x-xyz',
	'zabw'          => 'application/x-abiword',
	'zip'           => 'application/zip',
	'zoo'           => 'application/x-zoo',
	'123'           => 'application/vnd.lotus-1-2-3',
	'669'           => 'audio/x-mod'
);PK�[p#9#9#	Route.phpnu�[���<?php
/**
 * @version        4.3.0
 * @package        Joomla
 * @subpackage     Helpdesk Pro
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2013 - 2021 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

namespace OSSolution\HelpdeskPro\Site\Helper;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;

defined('_JEXEC') or die;

class Route
{
	/**
	 * Cached categories
	 *
	 * @var array
	 */
	protected static $categories;

	/**
	 * Cached articles, which can be passed from outside to reduce number of
queries
	 *
	 * @var array
	 */
	protected static $articles = [];

	/**
	 * Store menu items created to link to the component
	 *
	 * @var array
	 */
	protected static $lookup;

	/**
	 * Function to get Tickets Route
	 *
	 * @param   string  $language
	 *
	 * @return string
	 */
	public static function getTicketsRoute($language = '*')
	{
		$link = 'index.php?option=com_helpdeskpro&view=tickets';

		$needles = [
			'tickets' => [0],
		];

		if ($language != "*" && Multilanguage::isEnabled())
		{
			$link                .= '&lang=' . $language;
			$needles['language'] = $language;
		}

		if ($item = self::findItem($needles))
		{
			$link .= '?Itemid=' . $item;
		}

		return $link;
	}

	/**
	 * Function to get Ticket Route
	 *
	 * @param   mixed   $id  Ticket ID or Ticket Code, depends on $isId
parameter
	 * @param   bool    $isId
	 * @param   string  $language
	 *
	 * @return string
	 */
	public static function getTicketRoute($id, $isId = true, $language =
'*')
	{
		$link = 'index.php?option=com_helpdeskpro&view=ticket';

		if ($isId)
		{
			$link .= '&id=' . $id;
		}
		else
		{
			$link .= '&ticket_code=' . $id;
		}

		if ($language != "*" && Multilanguage::isEnabled())
		{
			$link .= '&lang=' . $language;
		}

		if ($isId)
		{
			if ($item = self::findItem(['tickets' => [0],
'language' => $language]))
			{
				$link .= '&Itemid=' . $item;
			}
			elseif ($item = self::findItem(['ticket' => [0],
'language' => $language]))
			{
				$link .= '&layout=default&Itemid=' . $item;
			}
		}
		else
		{
			if ($item = self::findItem(['ticket' => [0],
'language' => $language]))
			{
				$link .= '&layout=default&Itemid=' . $item;
			}
		}

		return $link;
	}

	/**
	 * Method to get articles route (display articles from a category)
	 *
	 * @param           $id
	 * @param   int     $itemId
	 * @param   string  $language
	 */
	public static function getArticlesRoute($id, $itemId = 0, $language =
'*')
	{
		$link =
'index.php?option=com_helpdeskpro&view=articles&id=' .
$id;

		$needles = ['articles' => [$id]];

		if ($language != "*" && Multilanguage::isEnabled())
		{
			$needles['language'] = $language;
			$link                .= '&lang=' . $language;
		}

		if ($item = self::findItem($needles, $itemId))
		{
			$link .= '&Itemid=' . $item;
		}

		return $link;
	}

	/**
	 * @param   int     $id
	 * @param   int     $catId
	 * @param   int     $itemId
	 * @param   string  $language
	 */
	public static function getArticleRoute($id, $catId, $itemId = 0, $language
= '*')
	{
		$id      = (int) $id;
		$needles = ['article' => [$id]];
		$link    =
'index.php?option=com_helpdeskpro&view=article&id=' .
$id;

		if (!$catId)
		{
			//Find the main category of this event
			$db    = Factory::getDbo();
			$query = $db->getQuery(true)
				->select('category_id')
				->from('#__helpdeskpro_articles')
				->where('id = ' . $id);
			$db->setQuery($query);
			$catId = (int) $db->loadResult();
		}

		if ($catId)
		{
			$needles['articles'] = self::getCategoriesPath($catId,
'id', false);
			$link                .= '&catid=' . $catId;
		}

		$needles['categories'] = [0];

		if ($language != "*" && Multilanguage::isEnabled())
		{
			$link .= '&lang=' . $language;

			$needles['language'] = $language;
		}

		if ($item = self::findItem($needles, $itemId))
		{
			$link .= '&Itemid=' . $item;
		}

		return $link;
	}

	/**
	 * Get path to the category
	 *
	 * @param   int     $id
	 * @param   string  $type
	 * @param   bool    $reverse
	 *
	 * @return array
	 */
	public static function getCategoriesPath($id, $type = 'id',
$reverse = true)
	{
		self::getCategories();;

		$paths = [];

		if ($type == 'id')
		{
			do
			{
				$paths[] = self::$categories[$id]->{$type};
				$id      = self::$categories[$id]->parent_id;
			} while ($id != 0);

			if ($reverse)
			{
				$paths = array_reverse($paths);
			}
		}
		else
		{
			$paths[] = self::$categories[$id]->{$type};
		}

		return $paths;
	}

	/**
	 * Find item id variable corresponding to the view
	 *
	 * @param   string  $view
	 * @param   int     $itemId
	 * @param   string  $language
	 *
	 * @return int
	 */
	public static function findView($view, $itemId, $language =
'*')
	{
		$needles = [
			$view => [0],
		];

		if ($language != "*" && Multilanguage::isEnabled())
		{
			$needles['language'] = $language;
		}

		if ($item = self::findItem($needles, $itemId))
		{
			return $item;
		}

		return 0;
	}

	/**
	 *
	 * Function to find Itemid
	 *
	 * @param   string  $needles
	 * @param   int     $itemId
	 *
	 * @return int
	 */
	public static function findItem($needles = null, $itemId = 0)
	{
		$app      = Factory::getApplication();
		$menus    = $app->getMenu('site');
		$language = isset($needles['language']) ?
$needles['language'] : '*';

		// Prepare the reverse lookup array.
		if (!isset(self::$lookup[$language]))
		{
			self::$lookup[$language] = array();

			$component =
ComponentHelper::getComponent('com_helpdeskpro');

			$attributes = array('component_id');
			$values     = array($component->id);

			if ($language != '*')
			{
				$attributes[] = 'language';
				$values[]     = array($needles['language'], '*');
			}

			$items = $menus->getItems($attributes, $values);

			foreach ($items as $item)
			{
				if (isset($item->query) &&
isset($item->query['view']))
				{
					$view = $item->query['view'];

					if (!isset(self::$lookup[$language][$view]))
					{
						self::$lookup[$language][$view] = array();
					}

					if (isset($item->query['id']) ||
$item->query['filter_category_id'])
					{
						$id = isset($item->query['id']) ?
$item->query['id'] :
$item->query['filter_category_id'];

						/**
						 * Here it will become a bit tricky
						 * language != * can override existing entries
						 * language == * cannot override existing entries
						 */
						if (!isset(self::$lookup[$language][$view][$id]) ||
$item->language != '*')
						{
							self::$lookup[$language][$view][$id] = $item->id;
						}
					}
				}
			}
		}

		if ($needles)
		{
			foreach ($needles as $view => $ids)
			{
				if (isset(self::$lookup[$language][$view]))
				{
					foreach ($ids as $id)
					{
						if (isset(self::$lookup[$language][$view][(int) $id]))
						{
							return self::$lookup[$language][$view][(int) $id];
						}
					}
				}
			}
		}

		//Return default item id
		return $itemId;
	}

	/**
	 * Get categories
	 *
	 * @return void
	 */
	protected static function getCategories()
	{
		$db    = Factory::getDbo();
		$query = $db->getQuery(true)
			->select('id,
parent_id')->from('#__helpdeskpro_categories')
			->where('published = 1');

		if ($fieldSuffix = Helper::getFieldSuffix())
		{
			$aliasField = $db->quoteName('alias' . $fieldSuffix);
			$query->select("IF(CHAR_LENGTH($aliasField) > 0, $aliasField,
alias) AS alias");
		}
		else
		{
			$query->select('alias');
		}

		$db->setQuery($query);

		self::$categories = $db->loadObjectList('id');
	}

	/**
	 * Add articles to cached articles
	 *
	 * @param   array  $articles
	 */
	public static function addArticles($articles)
	{
		foreach ($articles as $article)
		{
			self::$articles[$article->id] = $article;
		}
	}

	/**
	 * Get alias of category
	 *
	 * @param   int  $id
	 *
	 * @return string
	 */
	public static function getCategoryAlias($id)
	{
		self::getCategories();

		return self::$categories[$id]->alias;
	}

	/**
	 * Method to get article alias
	 *
	 * @param   int  $id
	 *
	 * @return string
	 */
	public static function getArticleAlias($id)
	{
		if (isset(self::$articles[$id]))
		{
			$db = Factory::getDbo();

			$query = $db->getQuery(true)
				->select('id')->from('#__helpdeskpro_articles')
				->where('id = ' . $id);

			if ($fieldSuffix = Helper::getFieldSuffix())
			{
				$aliasField = $db->quoteName('alias' . $fieldSuffix);
				$query->select("IF(CHAR_LENGTH($aliasField) > 0,
$aliasField, alias) AS alias");
			}
			else
			{
				$query->select('alias');
			}

			$db->setQuery($query);

			self::$articles[$id] = $db->loadObject();
		}

		return self::$articles[$id]->alias;
	}
}PK�[q�
bootstrap.phpnu�[���PK�[��Q��?Database.phpnu�[���PK�[×J�ѼѼ
Helper.phpnu�[���PK�[a��800$�Html.phpnu�[���PK�[E.����
��Jquery.phpnu�[���PK�[se�tXMXM��mime.mapping.phpnu�[���PK�[p#9#9#	'BRoute.phpnu�[���PK�e