public function installModule($module, $position, $always=true, $params='', $client=0, $menus=0)
	{
		$title    = $this->baseDb->quote(ucfirst($module));
		$position = $this->baseDb->quote($position);
		$module   = $this->baseDb->quote('mod_' . strtolower($module));
		$client   = $this->baseDb->quote((int)$client);
		$access   = ($this->baseDb->tableExists('#__extensions')) ? 1 : 0;

		// Build params string
		if (is_array($params) && !$this->baseDb->tableExists('#__extensions'))
		{
			$p = '';
			foreach ($params as $k => $v)
			{
				$p .= "{$k}={$v}\n";
			}

			$params = $this->baseDb->quote($p);
		}
		else
		{
			$params = $this->baseDb->quote(json_encode($params));
		}

		if (!$always)
		{
			$query = "SELECT `id` FROM `#__modules` WHERE `module` = {$module}";
			$this->db->setQuery($query);

			if ($this->db->loadResult())
			{
				return true;
			}
		}

		$query = "SELECT MAX(ordering) FROM `#__modules` WHERE `position` = {$position}";
		$this->baseDb->setQuery($query);
		$ordering = (int)(($this->baseDb->loadResult()) ? $this->baseDb->loadResult() + 1 : 0);

		$query  = "INSERT INTO `#__modules` ";
		$query .= "(`title` , `content`, `ordering` , `position` , `published`, `module` , `access` , `showtitle`, `params` , `client_id`) VALUES ";
		$query .= "({$title}, ''       , {$ordering}, {$position}, 1          , {$module}, {$access}, 0          , {$params}, {$client}  )";

		$this->baseDb->setQuery($query);
		$this->baseDb->query();
		$id = $this->baseDb->quote($this->baseDb->insertid());

		$menus = (array)$menus;
		foreach ($menus as $menu)
		{
			$menu  = $this->baseDb->quote($menu);
			$query = "INSERT INTO `#__modules_menu` (`moduleid`, `menuid`) VALUES ({$id}, {$menu})";
			$this->baseDb->setQuery($query);
			$this->baseDb->query();

			$this->log(sprintf('Added module_menu entry for module "%s" to menu "%s"', $module, $menu));
		}
	}