<?php
/**
 * <pre>
 * Invision Power Services
 * Databases skin file
 * Last Updated: $Date: 2009-08-23 21:54:28 -0400 (Sun, 23 Aug 2009) $
 * </pre>
 *
 * @author 		$Author: bfarber $
 * @copyright	(c) 2001 - 2009 Invision Power Services, Inc.
 * @license		http://www.invisionpower.com/community/board/license.html
 * @package		IP.Content
 * @link		http://www.invisionpower.com
 * @since		2nd September 2009
 * @version		$Revision: 67 $
 */
 
class cp_skin_databases extends output
{

/**
 * Prevent our main destructor being called by this class
 *
 * @access	public
 * @return	void
 */
public function __destruct()
{
}

/**
 * Add or edit a database
 *
 * @access	public
 * @param	string		add|edit
 * @param	array		Database data
 * @param	array 		Available templates
 * @param	array 		Available fields
 * @param	array 		Template categories
 * @return	string		HTML
 */
public function databaseForm( $type, $database, $templates, $fields, $categories )
{
$IPBHTML = "";
//--starthtml--//

//-----------------------------------------
// Mix in our submitted config
//-----------------------------------------

if( is_array($_POST) AND count($_POST) )
{
	$database		= array_merge( $database, $_POST );
}

$name			= $this->registry->output->formInput( 'database_name', $database['database_name'] );
$key			= $this->registry->output->formInput( 'database_key', $database['database_key'] );
$desc			= $this->registry->output->formTextarea( 'database_description', $database['database_description'], 40, 5, '', '', 'normal' );

$metak			= $this->registry->output->formTextarea( 'database_meta_keywords', $database['database_meta_keywords'], 40, 5, '', '', 'normal' );
$metad			= $this->registry->output->formTextarea( 'database_meta_description', $database['database_meta_description'], 40, 5, '', '', 'normal' );

$templateL		= $this->registry->output->formDropdown( 'database_template_listing', $templates[2], $database['database_template_listing'], null, null, null, $categories );
$templateR		= $this->registry->output->formDropdown( 'database_template_display', $templates[3], $database['database_template_display'], null, null, null, $categories );
$templateC		= $this->registry->output->formDropdown( 'database_template_categories', $templates[1], $database['database_template_categories'], null, null, null, $categories );

$userEdit		= $this->registry->output->formYesNo( 'database_user_editable', $database['database_user_editable'] );
$wikiEdit		= $this->registry->output->formYesNo( 'database_all_editable', $database['database_all_editable'] );
$open			= $this->registry->output->formYesNo( 'database_open', $database['database_open'] );
$comments		= $this->registry->output->formYesNo( 'database_comments', $database['database_comments'] );
$commentBump	= $this->registry->output->formYesNo( 'database_comment_bump', $database['database_comment_bump'] );
$approve		= $this->registry->output->formYesNo( 'database_record_approve', $database['database_record_approve'] );
$approveComment	= $this->registry->output->formYesNo( 'database_comment_approve', $database['database_comment_approve'] );
$rate			= $this->registry->output->formYesNo( 'database_rate', $database['database_rate'] );
$revisions		= $this->registry->output->formYesNo( 'database_revisions', $database['database_revisions'] );

$perpage		= $this->registry->output->formInput( 'database_field_perpage', $database['database_field_perpage'] ? $database['database_field_perpage'] : 25 );
$_orders		= array( array( 'asc', $this->lang->words['db_records__asc'] ), array( 'desc', $this->lang->words['db_records__desc'] ) );
$fieldorder		= $this->registry->output->formDropdown( 'database_field_direction', $_orders, $database['database_field_direction'] ? $database['database_field_direction'] : 'desc' );

$fieldTitle		= $this->registry->output->formDropdown( 'database_field_title', $fields, $database['database_field_title'] ? $database['database_field_title'] : 'primary_id_field' );
$fieldContent	= $this->registry->output->formDropdown( 'database_field_content', $fields, $database['database_field_content'] ? $database['database_field_content'] : 'primary_id_field' );
$fieldSort		= $this->registry->output->formDropdown( 'database_field_sort', $fields, $database['database_field_sort'] ? $database['database_field_sort'] : 'record_updated' );

$_rss			= explode( ';', $database['database_rss'] );
$rssEnable		= $this->registry->output->formYesNo( 'database_rss_enable', intval($_rss[0]) );
$rssRecache		= $this->registry->output->formInput( 'database_rss_recache', isset($_rss[1]) ? intval($_rss[1]) : 12 );
$rssTotal		= $this->registry->output->formInput( 'database_rss_count', isset($_rss[2]) ? intval($_rss[2]) : 20 );

$singlow		= $this->registry->output->formInput( 'database_lang_sl', $database['database_lang_sl'] ? $database['database_lang_sl'] : $this->lang->words['database_lang_sl'] );
$plurallow		= $this->registry->output->formInput( 'database_lang_pl', $database['database_lang_pl'] ? $database['database_lang_pl'] : $this->lang->words['database_lang_pl'] );
$singupper		= $this->registry->output->formInput( 'database_lang_su', $database['database_lang_su'] ? $database['database_lang_su'] : $this->lang->words['database_lang_su'] );
$pluralupper	= $this->registry->output->formInput( 'database_lang_pu', $database['database_lang_pu'] ? $database['database_lang_pu'] : $this->lang->words['database_lang_pu'] );

//-----------------------------------------
// Forum posting options
//-----------------------------------------

require_once( IPSLib::getAppDir( 'forums' ) . '/sources/classes/forums/class_forums.php' );
require_once( IPSLib::getAppDir( 'forums' ) . '/sources/classes/forums/admin_forum_functions.php' );

$aff = new admin_forum_functions( $this->registry );
$aff->forumsInit();
$_forums = $aff->adForumsForumList(1);
		
$fsynch			= $this->registry->output->formYesNo( 'database_forum_record', $database['database_forum_record'] );
$fcomments		= $this->registry->output->formYesNo( 'database_forum_comments', $database['database_forum_comments'] );
$fdelete		= $this->registry->output->formYesNo( 'database_forum_delete', $database['database_forum_delete'] );
$fforum			= $this->registry->output->formDropdown( 'database_forum_forum', $_forums, $database['database_forum_forum'] );
$fprefix		= $this->registry->output->formInput( 'database_forum_prefix', $database['database_forum_prefix'] );
$fsuffix		= $this->registry->output->formInput( 'database_forum_suffix', $database['database_forum_suffix'] );

require_once( IPS_ROOT_PATH . 'sources/classes/class_public_permissions.php' );
$permissions = new classPublicPermissions( ipsRegistry::instance() );
$matrix			= $permissions->adminPermMatrix( 'database', $database );
		
$text			= $type == 'edit' ? $this->lang->words['editing_db_title'] . $database['database_name'] : $this->lang->words['adding_db_title'];
$action			= $type == 'edit' ? 'doEdit' : 'doAdd';

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$text}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}&amp;module=databases&amp;section=databases' title='{$this->lang->words['cancel_edit_alt']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/delete.png' alt='{$this->lang->words['icon']}' />
				{$this->lang->words['button__cancel']}
			</a>
		</li>
	</ul>
</div>

<script type='text/javascript' src='{$this->settings['js_app_url']}acp.ccs.js'></script>

<form action='{$this->settings['base_url']}{$this->form_code}&amp;do={$action}&amp;id={$database['database_id']}' method='post' id='adminform' name='adform'>
<ul id='tabstrip_ccs_page' class='tab_bar no_title'>
	<li id='tabtab-CCSPAGE|1' class=''>{$this->lang->words['tab__db_main']}</li>
	<li id='tabtab-CCSPAGE|2' class=''>{$this->lang->words['tab__db_extra']}</li>
	<li id='tabtab-CCSPAGE|3' class=''>{$this->lang->words['tab__db_forum']}</li>
	<li id='tabtab-CCSPAGE|4' class=''>{$this->lang->words['tab__db_perms']}</li>
</ul>

<script type="text/javascript">
//<![CDATA[
document.observe("dom:loaded",function() 
{
ipbAcpTabStrips.register('tabstrip_ccs_page');
});
 //]]>
</script>
	
<div class='acp-box'>
	<div id='tabpane-CCSPAGE|1'>
		<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['edit_db_main_details']}</h2>
		<ul class='acp-form alternate_rows'>
			<li>
				<label>{$this->lang->words['dbform__name']}</label>
				{$name}
			</li>
			<li>
				<label>{$this->lang->words['dbform__key']} <span class='desctext'>{$this->lang->words['dbform__key_desc']}</span></label>
				{$key}
			</li>
			<li>
				<label>{$this->lang->words['dbform__desc']}</label>
				{$desc}
			</li>
			<li>
				<label>{$this->lang->words['dbform__cats']} <span class='desctext'>{$this->lang->words['dbform__cats_desc']}</span></label>
				{$templateC}
			</li>
			<li>
				<label>{$this->lang->words['dbform__list']} <span class='desctext'>{$this->lang->words['dbform__list_desc']}</span></label>
				{$templateL}
			</li>
			<li>
				<label>{$this->lang->words['dbform__disp']} <span class='desctext'>{$this->lang->words['dbform__disp_desc']}</span></label>
				{$templateR}
			</li>
			<li>
				<label>{$this->lang->words['dbform__langbits']} <span class='desctext'>{$this->lang->words['dbform__langbits_desc']}</span></label>
				<table id='db_languages'>
					<tr>
						<td><strong class='antilabel'>{$this->lang->words['langbits_sing_low']}</strong></td>
						<td>{$singlow}</td>
					</tr>
					<tr>
						<td><strong class='antilabel'>{$this->lang->words['langbits_plur_low']}</strong></td>
						<td>{$plurallow}</td>
					</tr>
					<tr>
						<td><strong class='antilabel'>{$this->lang->words['langbits_sing_upp']}</strong></td>
						<td>{$singupper}</td>
					</tr>
					<tr>
						<td><strong class='antilabel'>{$this->lang->words['langbits_plur_upp']}</strong></td>
						<td>{$pluralupper}</td>
					</tr>
				</table>
			</li>
			<li>
				<label>{$this->lang->words['dbform__meta_keywords']}</label>
				{$metak}
			</li>
			<li>
				<label>{$this->lang->words['dbform__meta_description']}</label>
				{$metad}
			</li>
		</ul>
	</div>
	
	<div id='tabpane-CCSPAGE|2'>
		<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['edit_db_extra_options']}</h2>
		<ul class='acp-form alternate_rows'>
			<li>
				<label>{$this->lang->words['dbform__useredit']} <span class='desctext'>{$this->lang->words['dbform__useredit_desc']}</span></label>
				{$userEdit}
			</li>
			<li>
				<label>{$this->lang->words['dbform__wikiedit']} <span class='desctext'>{$this->lang->words['dbform__wikiedit_desc']}</span></label>
				{$wikiEdit}
			</li>
			<li>
				<label>{$this->lang->words['dbform__recapprove']} <span class='desctext'>{$this->lang->words['dbform__recapprove_desc']}</span></label>
				{$approve}
			</li>
			<li>
				<label>{$this->lang->words['dbform__revise']} <span class='desctext'>{$this->lang->words['dbforum__revise_desc']}</span></label>
				{$revisions}
			</li>
			<li>
				<label>{$this->lang->words['dbform__open']} <span class='desctext'>{$this->lang->words['dbform__open_desc']}</span></label>
				{$open}
			</li>
			<li>
				<label>{$this->lang->words['dbform__comments']} <span class='desctext'>{$this->lang->words['dbform__comments_desc']}</span></label>
				{$comments}
			</li>
			<li>
				<label>{$this->lang->words['dbform__acomments']} <span class='desctext'>{$this->lang->words['dbform__acomments_desc']}</span></label>
				{$approveComment}
			</li>
			<li>
				<label>{$this->lang->words['dbform__bcomments']} <span class='desctext'>{$this->lang->words['dbform__bcomments_desc']}</span></label>
				{$commentBump}
			</li>
			<li>
				<label>{$this->lang->words['dbform__rate']} <span class='desctext'>{$this->lang->words['dbform__rate_desc']}</span></label>
				{$rate}
			</li>
			<li>
				<label>{$this->lang->words['dbform__rss']} <span class='desctext'>{$this->lang->words['dbform__rss_desc']}</span></label>
				{$rssEnable}
			</li>
			<li>
				<label>{$this->lang->words['dbform__rssc']} <span class='desctext'>{$this->lang->words['dbform__rssc_desc']}</span></label>
				{$rssTotal}
			</li>
			<li>
				<label>{$this->lang->words['dbform__rssr']} <span class='desctext'>{$this->lang->words['dbform__rssr_desc']}</span></label>
				{$rssRecache}
			</li>
		</ul>
		<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['edit_db_field_opts']}</h2>
		<ul class='acp-form alternate_rows'>
			<li>
				<label>{$this->lang->words['dbform__fieldtitle']} <span class='desctext'>{$this->lang->words['dbform__fieldtitle_desc']}</span></label>
				{$fieldTitle}
			</li>
			<li>
				<label>{$this->lang->words['dbform__fieldcontent']} <span class='desctext'>{$this->lang->words['dbform__fieldcontent_desc']}</span></label>
				{$fieldContent}
			</li>
			<li>
				<label>{$this->lang->words['dbform__fieldsort']} <span class='desctext'>{$this->lang->words['dbform__fieldsort_desc']}</span></label>
				{$fieldSort}
			</li>
			<li>
				<label>{$this->lang->words['dbform__fieldorder']} <span class='desctext'>{$this->lang->words['dbform__fieldorder_desc']}</span></label>
				{$fieldorder}
			</li>
			<li>
				<label>{$this->lang->words['dbform__perpage']} <span class='desctext'>{$this->lang->words['dbform__perpage_desc']}</span></label>
				{$perpage}
			</li>
		</ul>
	</div>
	
	<div id='tabpane-CCSPAGE|3'>
		<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['db_forum_options']}</h2>
		<ul class='acp-form alternate_rows'>
			<li>
				<label>{$this->lang->words['dbform__fsynch']} <span class='desctext'>{$this->lang->words['dbform__fsynch_desc']}</span></label>
				{$fsynch}
			</li>
			<li>
				<label>{$this->lang->words['dbform__fcomments']} <span class='desctext'>{$this->lang->words['dbform__fcomments_desc']}</span></label>
				{$fcomments}
			</li>
			<li>
				<label>{$this->lang->words['dbform__fforum']} <span class='desctext'>{$this->lang->words['dbform__fforum_desc']}</span></label>
				{$fforum}
			</li>
			<li>
				<label>{$this->lang->words['dbform__fprefix']} <span class='desctext'>{$this->lang->words['dbform__fprefix_desc']}</span></label>
				{$fprefix}
			</li>
			<li>
				<label>{$this->lang->words['dbform__fsuffix']} <span class='desctext'>{$this->lang->words['dbform__fsuffix_desc']}</span></label>
				{$fsuffix}
			</li>
			<li>
				<label>{$this->lang->words['dbform__fdelete']} <span class='desctext'>{$this->lang->words['dbform__fdelete_desc']}</span></label>
				{$fdelete}
			</li>
		</ul>
	</div>
	
	<div id='tabpane-CCSPAGE|4'>
		<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['edit_db_permissions_tab']}</h2>
		<div class='information-box'>{$this->lang->words['cd_noguest_commentrate']}</div>
		<div style='padding-top:10px'>
			{$matrix}
		</div>
	</div>

	<div class="acp-actionbar">
		<input type='submit' value=' {$this->lang->words['button__save']} ' class="button primary" />
	</div>
</div>	
</form>
HTML;

//--endhtml--//
return $IPBHTML;
}

/**
 * Show the list of created databases
 *
 * @access	public
 * @param	array 		Databases
 * @return	string		HTML
 */
public function databases( $databases )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$this->lang->words['databases_title']}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}&amp;module=databases&amp;section=databases&amp;do=add' title='{$this->lang->words['add_db_alt']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/table_add.png' alt='{$this->lang->words['icon']}' />
				{$this->lang->words['add_database_button']}
			</a>
		</li>
	</ul>
</div>
HTML;

$IPBHTML .= <<<HTML
<script type='text/javascript' src='{$this->settings['js_app_url']}acp.ccs.js'></script>
<div class='acp-box'>
	<h3>{$this->lang->words['all_created_dbs_title']}</h3>
	<table class='alternate_rows double_pad adv_controls'>
		<tr>
			<th style='width: 48%'>{$this->lang->words['db_name_th']}</th>
			<th style='width: 10%'>{$this->lang->words['db_fields_th']}</th>
			<th style='width: 10%'>{$this->lang->words['db_records_th']}</th>
			<th style='width: 10%'>{$this->lang->words['db_open_th']}</th>
			<th style='width: 10%'>{$this->lang->words['db_comments_th']}</th>
			<th style='width: 10%'>{$this->lang->words['db_rating_th']}</th>
			<th style='width: 2%'>&nbsp;</th>
		</tr>
HTML;

if( !count( $databases ) )
{
	$IPBHTML .= <<<HTML
	<tr>
		<td colspan='7'>
			<div style='padding: 20px; text-align: center'>
				<em>{$this->lang->words['no_dbs_created_yet']} <a href='{$this->settings['base_url']}&amp;module=databases&amp;section=databases&amp;do=add'>{$this->lang->words['create_db_now']}</a></em>
			</div>
		</td>
	</tr>
HTML;
}
else
{
	foreach( $databases as $db )
	{
		$name	= "<a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;id={$db['database_id']}'><strong>{$db['database_name']}</strong></a>";
		
		if( $db['database_description'] )
		{
			$name	.= "<div class='desctext'>{$db['database_description']}</div>";
		}
		
		$_open		= $db['database_open'] ? 'tick.png' : 'cross.png';
		$_comment	= $db['database_comments'] ? 'tick.png' : 'cross.png';
		$_rate		= $db['database_rate'] ? 'tick.png' : 'cross.png';
		
		$IPBHTML .= <<<HTML
	<tr class='control_row'>
		<td>{$name}</td>
		<td>{$db['database_field_count']}</td>
		<td>{$db['database_record_count']}</td>
		<td><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_open}' alt='{$this->lang->words['icon']}' /></td>
		<td><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_comment}' alt='{$this->lang->words['icon']}' /></td>
		<td><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_rate}' alt='{$this->lang->words['icon']}' /></td>
		<td>
			<ul class='controls'>
				<li class='left'>
					<a class='edit' href='{$this->settings['base_url']}&amp;module=databases&amp;section=databases&amp;do=edit&amp;id={$db['database_id']}'>{$this->lang->words['edit_database_menu']}</a>
				</li>
				<li class='right ipbmenu' id='menu_folder{$db['database_id']}'>
					{$this->lang->words['folder_options_alt']}
				</li>
			</ul>
			<ul class='acp-menu' id='menu_folder{$db['database_id']}_menucontent'>
				<li class='icon delete'><a href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}&amp;module=databases&amp;section=databases&amp;do=delete&amp;id={$db['database_id']}' );">{$this->lang->words['delete_database_menu']}</a></li>
				<li class='icon view'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=fields&amp;id={$db['database_id']}'>{$this->lang->words['fields_database_menu']}</a></li>
				<li class='icon view'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;id={$db['database_id']}'>{$this->lang->words['records_database_menu']}</a></li>
				<li class='icon view'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=categories&amp;id={$db['database_id']}'>{$this->lang->words['cats_database_menu']}</a></li>
				<li class='icon view'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=moderators&amp;id={$db['database_id']}'>{$this->lang->words['manage_moderators_menu']}</a></li>
			</ul>
		</td>
	</tr>
HTML;
	}
}

$IPBHTML .= <<<HTML
	</table>
</div>
HTML;
//--endhtml--//
return $IPBHTML;
}

}