<?php
if (!class_exists('vBShop_Item_Core'))
{
	die('No direct access allowed.');
}

class vBShop_Item_forumpassword extends vBShop_Item_Core
{
	/**
	* The constructor
	*
	* @param	vBulletin	vBulletin registry
	* @param	array		Item info
	*/	
	public function __construct(&$registry, &$item)
	{
		parent::__construct($registry, $item);
		
		// Set purchase template
		$this->config['purchasetemplate'] = 'dbtech_vbshop_configure_forumpassword';
	}
	
	/**
	* Function to call before every action
	*/	
	public function action()
	{
		if (!parent::action())
		{
			// This type is inactive
			return false;
		}
		
		// We made it!
		return true;
	}
	
	/**
	* Prints out an AdminCP form
	*/	
	public function print_admin_form($code)
	{
		global $vbphrase;

		$forums = array();
		foreach ($this->registry->forumcache AS $forumid => $forum)
		{
			if (!$forum['password'])
			{
				// Only passworded forums may apply
				continue;
			}
			$forums[$forumid] = $forum['title'] . ' ' . iif(!($forum['options'] & $this->registry->bf_misc_forumoptions['allowposting']), " ($vbphrase[forum_is_closed_for_posting])");
		}

		print_select_row($vbphrase['dbtech_vbshop_password_forums'], 'item[code][forums][]', $forums, $code['forums'], 0, 10, true);
	}

	/**
	* Form to purchase an item
	*/	
	public function render()
	{
		$forums = array();
		foreach ($code['forums'] as $forumid)
		{
			$forum = $this->registry->forumcache[$forumid];

			if (!$forum['password'])
			{
				// Only passworded forums may apply
				continue;
			}
			$forums[] = '<strong>' . $forum['title'] . ':</strong> ' . $forum['password'];
		}

		// Show ze passwordz
		$this->config['forumpasswords'] = implode('</li><li>', $forums);

		return parent::render();
	}	
	
	/**
	* Configure an item
	*
	* @param	integer		Purchase ID
	* @param	mixed		Recipient
	*/	
	public function configure($purchaseid, $recipient = null)
	{
		global $vbphrase;
		
		// Dummy function as it's just showing forum passwords
	}	
}
?>