public function addTemplateEntry($element, $name=null, $client=1, $enabled=1, $home=0, $styles=null, $protected=0)
	{
		if ($this->baseDb->tableExists('#__extensions'))
		{
			if (!isset($name))
			{
				if (substr($element, 0, 4) == 'tpl_')
				{
					$name    = substr($element, 4);
					$element = $name;
				}
				else
				{
					$name = $element;
				}

				$name = ucwords($name);
			}

			// First, see if it already exists
			$query = "SELECT `extension_id` FROM `#__extensions` WHERE `type` = 'template' AND (`element` = '{$element}' OR `element` LIKE '{$name}') AND `client_id` = '{$client}'";
			$this->baseDb->setQuery($query);

			if (!$this->baseDb->loadResult())
			{
				$query  = "INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `ordering`, `state`)";
				$query .= " VALUES ('{$name}', 'template', '{$element}', '', '{$client}', '{$enabled}', '1', '{$protected}', '{}', '{}', '', '', '0', '0', '0')";
				$this->baseDb->setQuery($query);
				$this->baseDb->query();

				$this->log(sprintf('Added extension entry for template "%s"', $element));

				if ($this->baseDb->tableExists('#__template_styles'))
				{
					// If we're setting this template to be default, disable others first
					if ($home)
					{
						$query = "UPDATE `#__template_styles` SET `home` = 0 WHERE `client_id` = '{$client}'";
						$this->baseDb->setQuery($query);
						$this->baseDb->query();

						$this->log(sprintf('Disabling "home" for all other templates (client "%s")', $client));
					}

					$query  = "INSERT INTO `#__template_styles` (`template`, `client_id`, `home`, `title`, `params`)";
					$query .= " VALUES ('{$element}', '{$client}', '{$home}', '{$name}', " . ((isset($styles)) ? $this->baseDb->quote(json_encode($styles)) : "'{}'") . ")";
					$this->baseDb->setQuery($query);
					$this->baseDb->query();

					$this->log(sprintf('Added style entry for template "%s"', $element));
				}
			}
			else
			{
				$this->log(sprintf('Extension entry already exists for template "%s"', $element));
			}

			return true;
		}

		$this->log(sprintf('Required table not found for adding template "%s"', $element), 'warning');

		return false;
	}