<?php
/**
 * <pre>
 * Invision Power Services
 * Database records 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_database_records extends output
{

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

/**
 * Add or edit a record
 *
 * @access	public
 * @param	string		add|edit
 * @param	array		Database data
 * @param	array 		Fields
 * @param	array 		Record data
 * @param	object		Field abstraction class
 * @param	string 		Categories
 * @param	bool		This is a revision
 * @return	string		HTML
 */
public function recordForm( $type, $database, $fields, $record, $fieldClass, $categories='', $revision=false )
{
$IPBHTML = "";
//--starthtml--//
$text			= $revision ? $this->lang->words['editing_revision_title'] : ( $type == 'edit' ? $this->lang->words['editing_record_title'] . $record[ $database['database_field_title'] ] : $this->lang->words['adding_record_title'] );
$action			= $revision ? 'doEditRevision' : ( $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=records&amp;id={$database['database_id']}' 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>

HTML;

if( $this->request['preview'] )
{
	$IPBHTML .= <<<HTML
<!--Make sure we style previewed stuff -->
<style type='text/css'>
strong.bbc				{	font-weight: bold !important; }
em.bbc 					{	font-style: italic !important; }
span.bbc_underline 		{ 	text-decoration: underline !important; }
div.bbc_center 			{	text-align: center; }
div.bbc_left 			{	text-align: left; }
div.bbc_right 			{	text-align: right; }
div.bbc_indent 			{	margin-left: 50px; }
del.bbc 				{	text-decoration: line-through !important; }
ul.bbc 					{	list-style: disc outside; margin-left: 30px; }
	ul.bbc ul.bbc 			{	list-style-type: circle; }
		ul.bbc ul.bbc ul.bbc 	{	list-style-type: square; }
ol.bbc 					{ margin-left: 30px; list-style-type: decimal; }
	ol.bbc.lower-alpha		{ 	list-style-type: lower-alpha; }
	ol.bbc.upper-alpha		{ 	list-style-type: upper-alpha; }
	ol.bbc.lower-roman		{ 	list-style-type: lower-roman; }
	ol.bbc.upper-roman		{ 	list-style-type: upper-roman; }
hr.bbc 					{ 	display: block; border-top: 2px solid #777; }
div.bbc_spoiler 		{	 }
div.bbc_spoiler span	{ 	font-weight: bold; }
div.bbc_spoiler_wrapper	{ 	border: 1px inset #777; padding: 4px; }
div.bbc_spoiler_content	{ 	 }
input.bbc_spoiler_show	{ 	width: 45px; font-size: .7em; margin: 0px; padding: 0px; }
pre.prettyprint 		{ padding: 5px; background: #f8f8f8; border: 1px solid #c9c9c9; overflow: auto; margin-left: 10px; font-size: 11px; line-height: 110%; }

/* Quote boxes */
p.citation {
	background: #d3e9dc url(../../style_images/master/citation_bg.png) no-repeat right;
	color: #2b3730;
	font-size: 0.9em;
	font-weight: bold;
	border-width: 1px 1px 0 3px;
	border-style: solid;
	border-color: #6fa987;
	padding: 5px 8px;
}

	div.blockquote {
		background: #f3f9f6;
		font-size: 0.9em;
		border-width: 1px 1px 1px 3px;
		border-style: solid;
		border-color: #6fa987;
		margin: 0px;
		margin-top: 0px;
	}

		div.blockquote p.citation {
			background-color: #e5d2e9;
			color: #413544;
			border-color: #ae7eb9;
		}
		
		div.blockquote div.blockquote {
			background: #f9f5fa;
			font-size: 1em;
			border-color: #ae7eb9;
			margin: -0px 15px 0px 15px;
		}

			div.blockquote div.blockquote p.citation {
				background-color: #e9e7d1;
				color: #474534;
				border-color: #b2ab72;
			}

			div.blockquote div.blockquote div.blockquote {
				background: #f9f8f3;
				border-color: #b2ab72;
			}
			
			div.blockquote p.citation {
				margin: 6px 15px 0 15px;
				font-size: 1em;
			}

div.quote {
	padding: 12px;
} 

div.quote p.blockquote {
	margin-left: -12px;
}

cite {
	display: block;
	font-weight: bold;
}

	blockquote cite {
		font-size: 1em;
	}
</style>
<div class='acp-box'>
	<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['preview_record_details']}</h2>
	<table style='width:100%;' class='form_table alternate_rows double_pad'>
HTML;

foreach( $fields as $field )
{
	$_field	= $fieldClass->getFieldValuePreview( $field, $record );
	
	$IPBHTML .= <<<HTML
		<tr>
			<td style='width:40%;'><label>{$field['field_name']}</label></td>
			<td>{$_field}</td>
		</tr>
HTML;
}

$IPBHTML .= <<<HTML
	</table>
</div>
<br />
HTML;
}

$IPBHTML .= <<<HTML
<form action='{$this->settings['base_url']}{$this->form_code}&amp;do={$action}&amp;id={$database['database_id']}' method='post' id='adminform' name='adform' enctype='multipart/form-data'>
<input type='hidden' name='record' value='{$record['primary_id_field']}' />
<input type='hidden' name='post_key' value='{$record['post_key']}' />
<div class='acp-box'>
	<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['edit_record_details']}</h2>
	<table style='width:100%;' class='form_table alternate_rows double_pad'>
HTML;

if( $categories )
{
	$IPBHTML .= <<<HTML
		<tr>
			<td style='width:40%;'><label>{$this->lang->words['record_form_cat']}</label></td>
			<td><select name='category_id' id='category_id'>{$categories}</select></td>
		</tr>
HTML;
}

$furl		= $this->registry->output->formInput( 'record_static_furl', $record['record_static_furl'] );
$metak		= $this->registry->output->formTextarea( 'record_meta_keywords', $record['record_meta_keywords'], 40, 5, '', '', 'normal' );
$metad		= $this->registry->output->formTextarea( 'record_meta_description', $record['record_meta_description'], 40, 5, '', '', 'normal' );

foreach( $fields as $field )
{
	$_default	= $record['field_' . $field['field_id'] ];
	
	if( isset($_POST['field_' . $field['field_id'] ]) )
	{
		if( is_array($_POST['field_' . $field['field_id'] ]) )
		{
			$_default	= ',' . implode( ',', $_POST['field_' . $field['field_id'] ] ) . ',';
		}
		else
		{
			$_default	= $field['field_type'] == 'input' ? IPSText::textToForm( $_POST['field_' . $field['field_id'] ] ) : $_POST['field_' . $field['field_id'] ];
		}
	}

	$_field	= $fieldClass->getAcpField( $field, $_default );
	$_desc	= $field['field_description'] ? " <div class='desctext'>{$field['field_description']}</div>" : '';
	
	$IPBHTML .= <<<HTML
		<tr>
			<td style='width:40%;'><label>{$field['field_name']}</label>{$_desc}</td>
			<td>{$_field}</td>
		</tr>
HTML;
}

$IPBHTML .= <<<HTML
		<tr>
			<td style='width:40%;'><label>{$this->lang->words['record_form_furl']}</label> <div class='desctext'>{$this->lang->words['record_form_furl_desc']}</div></td>
			<td>{$furl}</td>
		</tr>
		<tr>
			<td style='width:40%;'><label>{$this->lang->words['dbform__meta_keywords']}</label> <div class='desctext'>{$this->lang->words['meta_tags__override']}</div></td>
			<td>{$metak}</td>
		</tr>
		<tr>
			<td style='width:40%;'><label>{$this->lang->words['dbform__meta_description']}</label> <div class='desctext'>{$this->lang->words['meta_tags__override']}</div></td>
			<td>{$metad}</td>
		</tr>
	
HTML;

$IPBHTML .= <<<HTML
	</table>

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

if( $type == 'add' )
{
	$IPBHTML .= <<<HTML
		<input type='submit' name='save_and_another' value=' {$this->lang->words['button__saveplus']} ' class="button primary" />
HTML;
}

$IPBHTML .= <<<HTML
		<input type='submit' name='preview' value=' {$this->lang->words['button__preview']} ' class="button primary" />
	</div>
</div>	
</form>
HTML;

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

/**
 * Show the list of records within a database
 *
 * @access	public
 * @param	array 		Database
 * @param	array 		Fields
 * @param	array 		Records
 * @param	string		Pages
 * @param	object		Field abstraction class
 * @param	string		Query string for page links
 * @param	string		Category filter HTML (if categories defined)
 * @param	int			Number of queued comments
 * @return	string		HTML
 */
public function records( $database, $fields, $records, $pages, $fieldClass, $queryString, $categoryFilter='', $qc=0 )
{
$IPBHTML = "";
//--starthtml--//

$_fieldSt	= intval($this->request['field_st']) ? intval($this->request['field_st']) : 0;
$_maxFields	= count($fields);
$_limit		= 5;
$_skipped	= 0;
$_drawn		= 0;
$_previous	= '';
$_next		= '&nbsp;';

if( $_fieldSt > 0 )
{
	$_prevCnt	= $_fieldSt - $_limit;
	$_previous	= "<a href='{$this->settings['base_url']}{$this->form_code}&amp;st={$this->request['st']}&amp;field_st={$_prevCnt}{$queryString}' title='{$this->lang->words['view_prev_rec_fields']}'>{$this->lang->words['_laquo']}</a> ";
}


if( $qc )
{
	$this->registry->output->global_message	= sprintf( $this->lang->words['queued_comm_link'], $this->settings['base_url'] . $this->form_code, $qc );
}

//-----------------------------------------
// Sort options
//-----------------------------------------

$_sort	= array(
				'primary_id_field'	=> $this->request['sort_col'] == 'primary_id_field' ? " selected='selected'" : '',
				'member_id'			=> $this->request['sort_col'] == 'member_id' ? " selected='selected'" : '',
				'record_saved'		=> $this->request['sort_col'] == 'record_saved' ? " selected='selected'" : '',
				'record_updated'	=> $this->request['sort_col'] == 'record_updated' ? " selected='selected'" : '',
				'rating_real'		=> $this->request['sort_col'] == 'rating_real' ? " selected='selected'" : '',
				'record_views'		=> $this->request['sort_col'] == 'record_views' ? " selected='selected'" : '',
				'record_approved'	=> $this->request['sort_col'] == 'record_approved' ? " selected='selected'" : '',
				'record_comments'	=> $this->request['sort_col'] == 'record_comments' ? " selected='selected'" : '',
				'record_locked'		=> $this->request['sort_col'] == 'record_locked' ? " selected='selected'" : '',
				);

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$this->lang->words['dbrecords_title']} {$database['database_name']}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=add&amp;id={$database['database_id']}' title='{$this->lang->words['add_record_alt']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/add.png' alt='{$this->lang->words['icon']}' />
				{$this->lang->words['add_record_button']}
			</a>
		</li>
		<li>
			<a href='{$this->settings['base_url']}&amp;module=databases&amp;section=fields&amp;id={$database['database_id']}' title='{$this->lang->words['switch_manage_fields']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/layout_content.png' alt='{$this->lang->words['icon']}' />
				{$this->lang->words['switch_manage_fields']}
			</a>
		</li>
		<li>
			<a href='{$this->settings['base_url']}&amp;module=databases&amp;section=categories&amp;id={$database['database_id']}' title='{$this->lang->words['switch_manage_cats']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/folder.png' alt='{$this->lang->words['icon']}' />
				{$this->lang->words['switch_manage_cats']}
			</a>
		</li>
	</ul>
</div>

<div>{$pages}</div>

<script type='text/javascript' src='{$this->settings['js_app_url']}acp.ccs.js'></script>
<div class='acp-box clear'>
	<h3>{$this->lang->words['all_created_records_t']}</h3>
	<div class="acp-actionbar">
		<form action='{$this->settings['base_url']}{$this->form_code}' method='post'>
			{$this->lang->words['db_records__search']}
			<input type='text' name='search_value' length='12' value='{$this->request['search_value']}' />
HTML;

if( $categoryFilter )
{
	$IPBHTML .= <<<HTML
	{$this->lang->words['db_records__catfilter']}
	<select name='category' id='category'>
		<option value='0'>{$this->lang->words['db_records__cf_all']}</option>
		{$categoryFilter}
	</select>
HTML;
}

$IPBHTML .= <<<HTML
			{$this->lang->words['db_records__sortby']} 
			<select name='sort_col'>
				<option value='primary_id_field'{$_sort['primary_id_field']}>{$this->lang->words['field__id']}</option>
				<option value='member_id'{$_sort['member_id']}>{$this->lang->words['field__member']}</option>
				<option value='record_saved'{$_sort['record_saved']}>{$this->lang->words['field__saved']}</option>
				<option value='record_updated'{$_sort['record_updated']}>{$this->lang->words['field__updated']}</option>
				<option value='rating_real'{$_sort['rating_real']}>{$this->lang->words['field__rating']}</option>
				<option value='record_views'{$_sort['record_views']}>{$this->lang->words['field__views']}</option>
				<option value='record_approved'{$_sort['record_approved']}>{$this->lang->words['field__approved']}</option>
				<option value='record_comments'{$_sort['record_comments']}>{$this->lang->words['field__comments']}</option>
				<option value='record_locked'{$_sort['record_locked']}>{$this->lang->words['field__locked']}</option>
				
HTML;

foreach( $fields as $field )
{
	if( !in_array( $field['field_type'], array( 'input', 'textarea', 'radio', 'select', 'editor' ) ) )
	{
		continue;
	}
	
	$selected	= '';
	
	if( $this->request['sort_col'] == 'field_' . $field['field_id'] )
	{
		$selected	= " selected='selected'";
	}

	$IPBHTML .= <<<HTML
				<option value='field_{$field['field_id']}'{$selected}>{$field['field_name']}</option>
HTML;
}

$_asc	= $this->request['sort_order'] == 'asc' ? " selected='selected'" : '';
$_desc	= $this->request['sort_order'] == 'desc' ? " selected='selected'" : '';

$_opt10	= $this->request['per_page'] == 10 ? " selected='selected'" : '';
$_opt25	= $this->request['per_page'] == 25 ? " selected='selected'" : '';
$_opt50	= $this->request['per_page'] == 50 ? " selected='selected'" : '';
$_opt75	= $this->request['per_page'] == 75 ? " selected='selected'" : '';
$_opthu	= $this->request['per_page'] == 100 ? " selected='selected'" : '';

$IPBHTML .= <<<HTML
				
			</select> {$this->lang->words['db_records__in']}
			<select name='sort_order'>
				<option value='asc'{$_asc}>{$this->lang->words['db_records__asc']}</option>
				<option value='desc'{$_desc}>{$this->lang->words['db_records__desc']}</option>
			</select> {$this->lang->words['db_records__order']}
			<select name='per_page'>
				<option value='10'{$_opt10}>10</option>
				<option value='25'{$_opt25}>25</option>
				<option value='50'{$_opt50}>50</option>
				<option value='75'{$_opt75}>75</option>
				<option value='100'{$_opt100}>100</option>
			</select> {$this->lang->words['db_records__results']}
			<input value="{$this->lang->words['dbrecord_resort']}" class="button primary" accesskey="s" type="submit" />
		</form>
	</div>
	<table class='alternate_rows double_pad adv_controls'>
		<tr>
			<th style='width: auto'>{$_previous}{$this->lang->words['th__record_id']}</th>
HTML;

foreach( $fields as $field )
{
	if( $_fieldSt > 0 AND $_skipped < $_fieldSt )
	{
		$_skipped++;
		continue;
	}
	
	if( $_drawn >= $_limit )
	{
		break;
	}
	
	$_drawn++;

	$IPBHTML .= <<<HTML
			<th style='width: auto'>{$field['field_name']}</th>
HTML;
}

if( $_drawn + $_fieldSt < $_maxFields )
{
	$_nextCnt	= $_fieldSt + $_limit;
	$_next		= "<a href='{$this->settings['base_url']}{$this->form_code}&amp;st={$this->request['st']}&amp;field_st={$_nextCnt}{$queryString}' title='{$this->lang->words['view_more_rec_fields']}'>{$this->lang->words['_raquo']}</a> ";
}

$IPBHTML .= <<<HTML
			<th style='width: auto'>{$_next}</th>
		</tr>
HTML;

if( !count( $records ) )
{
	$colspan	= 2 + count($fields);
	
	$IPBHTML .= <<<HTML
	<tr>
		<td colspan='{$colspan}'>
			<div style='padding: 20px; text-align: center'>
				<em>{$this->lang->words['no_records_created_yet']} <a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=add&amp;id={$database['database_id']}'>{$this->lang->words['create_record_now']}</a></em>
			</div>
		</td>
	</tr>
HTML;
}
else
{
	foreach( $records as $record )
	{
		$_cssClass		= $record['record_approved'] ? '' : '_red';
	
		$IPBHTML .= <<<HTML
		<tr class='{$_cssClass} control_row'>
			<td><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=edit&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}' title='{$this->lang->words['edit_record_menu']}'>{$record['primary_id_field']}</a></td>
HTML;

		$_skipped	= 0;
		$_drawn		= 0;
		
		foreach( $fields as $field )
		{
			if( $_fieldSt > 0 AND $_skipped < $_fieldSt )
			{
				$_skipped++;
				continue;
			}
			
			if( $_drawn >= $_limit )
			{
				break;
			}
			
			$_drawn++;
	
			$_display	= $fieldClass->getFieldValue( $field, $record, 100 );
			
			$_pinned	= '';
			
			if( $record['record_pinned'] AND $_drawn == 1 )
			{
				$_pinned	= $this->registry->getClass('output')->getTemplate('forum')->topicPrefixWrap( $this->settings['pre_pinned'] );
			}
			
			$IPBHTML .= <<<HTML
			<td>{$_pinned}{$_display}</td>
HTML;
		}
		
		$revisions	= '';
		$comments	= '';
		
		if( $database['database_revisions'] )
		{
			$revisions	= "<li class='icon view'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=revisions&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}'>{$this->lang->words['record_revisions_menu']}</a></li>";
		}
		
		if( $database['database_comments'] )
		{
			$comments	= "<li class='icon view'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=comments&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}'>{$this->lang->words['record_comments_menu']}</a></li>";
		}
		
		if( $record['record_locked'] )
		{
			$locked	= "<li class='icon manage'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=lock&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}'>{$this->lang->words['unlock_record__menu']}</a></li>";
		}
		else
		{
			$locked	= "<li class='icon manage'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=lock&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}'>{$this->lang->words['lock_record__menu']}</a></li>";
		}
		
		if( $record['record_pinned'] )
		{
			$pinned	= "<li class='icon manage'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=pin&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}'>{$this->lang->words['unpin_record__menu']}</a></li>";
		}
		else
		{
			$pinned	= "<li class='icon manage'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=pin&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}'>{$this->lang->words['pin_record__menu']}</a></li>";
		}
		
		if( $record['record_approved'] )
		{
			$approved	= "<li class='icon manage'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=approve&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}'>{$this->lang->words['unapp_record__menu']}</a></li>";
		}
		else
		{
			$approved	= "<li class='icon manage'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=approve&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}'>{$this->lang->words['app_record__menu']}</a></li>";
		}
		
		$IPBHTML .= <<<HTML
			<td>
				<ul class='controls'>
					<li class='left'>
						<a class='edit' href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=edit&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}'>{$this->lang->words['edit_record_menu']}</a>
					</li>
					<li class='right ipbmenu' id='menu_folder{$record['primary_id_field']}'>
						{$this->lang->words['folder_options_alt']}
					</li>
				</ul>
				<ul class='acp-menu' id='menu_folder{$record['primary_id_field']}_menucontent'>
					<li class='icon delete'><a href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=delete&amp;id={$database['database_id']}&amp;record={$record['primary_id_field']}' );">{$this->lang->words['delete_record_menu']}</a></li>
					{$approved}
					{$locked}
					{$pinned}
					{$revisions}
					{$comments}
				</ul>
			</td>
		</tr>
HTML;
	}
}


				
$IPBHTML .= <<<HTML
	</table>
	<div class="acp-actionbar">
		<form action='{$this->settings['base_url']}{$this->form_code}' method='post'>
			{$this->lang->words['db_records__search']}
			<input type='text' name='search_value' length='12' value='{$this->request['search_value']}' />
HTML;

if( $categoryFilter )
{
	$IPBHTML .= <<<HTML
	{$this->lang->words['db_records__catfilter']}
	<select name='category' id='category'>
		<option value='0'>{$this->lang->words['db_records__cf_all']}</option>
		{$categoryFilter}
	</select>
HTML;
}

$IPBHTML .= <<<HTML
			{$this->lang->words['db_records__sortby']} 
			<select name='sort_col'>
				<option value='primary_id_field'{$_sort['primary_id_field']}>{$this->lang->words['field__id']}</option>
				<option value='member_id'{$_sort['member_id']}>{$this->lang->words['field__member']}</option>
				<option value='record_saved'{$_sort['record_saved']}>{$this->lang->words['field__saved']}</option>
				<option value='record_updated'{$_sort['record_updated']}>{$this->lang->words['field__updated']}</option>
				<option value='rating_real'{$_sort['rating_real']}>{$this->lang->words['field__rating']}</option>
				<option value='record_views'{$_sort['record_views']}>{$this->lang->words['field__views']}</option>
				<option value='record_approved'{$_sort['record_approved']}>{$this->lang->words['field__approved']}</option>
				<option value='record_comments'{$_sort['record_comments']}>{$this->lang->words['field__comments']}</option>
				<option value='record_locked'{$_sort['record_locked']}>{$this->lang->words['field__locked']}</option>
				
HTML;

foreach( $fields as $field )
{
	if( !in_array( $field['field_type'], array( 'input', 'textarea', 'radio', 'select', 'editor' ) ) )
	{
		continue;
	}
	
	$selected	= '';
	
	if( $this->request['sort_col'] == 'field_' . $field['field_id'] )
	{
		$selected	= " selected='selected'";
	}

	$IPBHTML .= <<<HTML
				<option value='field_{$field['field_id']}'{$selected}>{$field['field_name']}</option>
HTML;
}

$_asc	= $this->request['sort_order'] == 'asc' ? " selected='selected'" : '';
$_desc	= $this->request['sort_order'] == 'desc' ? " selected='selected'" : '';

$_opt10	= $this->request['per_page'] == 10 ? " selected='selected'" : '';
$_opt25	= $this->request['per_page'] == 25 ? " selected='selected'" : '';
$_opt50	= $this->request['per_page'] == 50 ? " selected='selected'" : '';
$_opt75	= $this->request['per_page'] == 75 ? " selected='selected'" : '';
$_opthu	= $this->request['per_page'] == 100 ? " selected='selected'" : '';

$IPBHTML .= <<<HTML
				
			</select> {$this->lang->words['db_records__in']}
			<select name='sort_order'>
				<option value='asc'{$_asc}>{$this->lang->words['db_records__asc']}</option>
				<option value='desc'{$_desc}>{$this->lang->words['db_records__desc']}</option>
			</select> {$this->lang->words['db_records__order']}
			<select name='per_page'>
				<option value='10'{$_opt10}>10</option>
				<option value='25'{$_opt25}>25</option>
				<option value='50'{$_opt50}>50</option>
				<option value='75'{$_opt75}>75</option>
				<option value='100'{$_opt100}>100</option>
			</select> {$this->lang->words['db_records__results']}
			<input value="{$this->lang->words['dbrecord_resort']}" class="button primary" accesskey="s" type="submit" />
		</form>
	</div>
</div>

<br />
<div>{$pages}</div>

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

/**
 * Show the list of revisions for a particular record
 *
 * @access	public
 * @param	array 		Database
 * @param	array 		Fields
 * @param	array 		Record data
 * @param	array 		Revisions for this record
 * @return	string		HTML
 */
public function revisions( $database, $fields, $record, $revisions )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$this->lang->words['dbrevisions_title']} {$record['title']}</h2>
</div>

<script type='text/javascript' src='{$this->settings['js_app_url']}acp.ccs.js'></script>
<div class='acp-box clear'>
	<h3>{$this->lang->words['all_saved_revisions']}</h3>
	<table class='alternate_rows double_pad adv_controls'>
		<tr>
			<th style='width: auto'>{$this->lang->words['th__revision_date']}</th>
			<th style='width: auto'>{$this->lang->words['th__revision_member']}</th>
			<th style='width: 5%'>&nbsp;</th>
		</tr>
HTML;

if( !count( $revisions ) )
{
	$IPBHTML .= <<<HTML
	<tr>
		<td colspan='3'>
			<div style='padding: 20px; text-align: center'>
				<em>{$this->lang->words['no_revisions_saved_yet']}</em>
			</div>
		</td>
	</tr>
HTML;
}
else
{
	foreach( $revisions as $revision )
	{
		$data	= unserialize($revision['revision_data']);
		$date	= $this->registry->class_localization->getDate( $revision['revision_date'], 'LONG' );
		
		$IPBHTML .= <<<HTML
		<tr class='control_row'
			<td>{$date}</td>
			<td><a href='{$this->settings['board_url']}/index.php?showuser={$revision['member_id']}'>{$revision['members_display_name']}</a></td>
			<td>
				<ul class='controls'>
					<li class='left'>
						<a class='edit' href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=editRevision&amp;id={$database['database_id']}&amp;revision={$revision['revision_id']}'>{$this->lang->words['edit_revision_menu']}</a>
					</li>
					<li class='right ipbmenu' id='menu_folder{$revision['revision_id']}'>
						{$this->lang->words['folder_options_alt']}
					</li>
				</ul>
				<ul class='acp-menu' id='menu_folder{$revision['revision_id']}_menucontent'>
					<li class='icon delete'><a href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=deleteRevision&amp;id={$database['database_id']}&amp;revision={$revision['revision_id']}' );">{$this->lang->words['delete_revision_menu']}</a></li>
					<li class='icon manage'><a href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=restoreRevision&amp;id={$database['database_id']}&amp;revision={$revision['revision_id']}', '{$this->lang->words['restore_are_you_sure']}' );">{$this->lang->words['restore_revision_menu']}</a></li>
					<li class='icon view'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=compareRevision&amp;id={$database['database_id']}&amp;revision={$revision['revision_id']}'>{$this->lang->words['compare_revision_menu']}</a></li>
				</ul>
			</td>
		</tr>
HTML;
	}
}

$IPBHTML .= <<<HTML
	</table>
</div>

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

/**
 * Show the list of revisions for a particular record
 *
 * @access	public
 * @param	array 		Database
 * @param	array 		Fields
 * @param	array 		Differences data
 * @return	string		HTML
 */
public function compareRevisions( $database, $fields, $differences )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$this->lang->words['dbview_revision']}</h2>
</div>

<script type='text/javascript' src='{$this->settings['js_app_url']}acp.ccs.js'></script>
<div class='acp-box clear'>
	<h3>{$this->lang->words['revision_comparison_list']}</h3>
	<table width='100%' cellpadding='0' cellspacing='0' class='form_table alternate_rows double_pad'>
HTML;

if( count( $fields ) )
{
	foreach( $fields as $_field )
	{
		$IPBHTML .= <<<HTML
		<tr>
			<td style='width: 40%;'><label>{$_field['field_name']}</label></td>
			<td>{$differences[ $_field['field_id'] ]}</td>
		</tr>
HTML;
	}
}

$IPBHTML .= <<<HTML
	</table>
</div>
<div style='padding:4px;margin:4px;'>
	<span class='diffred'>{$this->lang->words['rev_removedhtml']}</span> &middot; <span class='diffgreen'>{$this->lang->words['rev_addedhtml']}</span>
</div>

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

/**
 * Show the list of comments for a particular record (stored as replies to a topic)
 *
 * @access	public
 * @param	array 		Database
 * @param	array 		Record data
 * @param	array 		Comments
 * @param	string		Page links
 * @return	string		HTML
 */
public function topicComments( $database, $record, $comments, $pagelinks )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
	<div class='section_title'>
		<h2>{$this->lang->words['dbcomments_title']} {$record['title']}</h2>
	</div>
HTML;

$IPBHTML .= <<<HTML
<div>{$pages}</div>

<script type='text/javascript' src='{$this->settings['js_app_url']}acp.ccs.js'></script>
<div class='acp-box clear'>
	<h3>{$this->lang->words['all_saved_comments']}</h3>
	<table class='alternate_rows double_pad adv_controls'>
HTML;

if( !count( $comments ) )
{
	$IPBHTML .= <<<HTML
	<tr>
		<td style='width:100%;'>
			<div style='padding: 20px; text-align: center'>
				<em>{$this->lang->words['no_comments_saved_yet']}</em>
			</div>
		</td>
	</tr>
HTML;
}
else
{
	foreach( $comments as $comment )
	{
		$date			= $this->registry->class_localization->getDate( $comment['post_date'], 'LONG' );
		$_commentText	= !$comment['queued'] ? $this->lang->words['unapp_comment_menu'] : $this->lang->words['app_comment_menu'];
		$_cssClass		= !$comment['queued'] ? '' : '_red';

		$IPBHTML .= <<<HTML
		<tr class='{$_cssClass} control_row'>
			<td style='width:95%;'>
				<div style='float:left;padding-right: 10px;'>
					<img src='{$comment['pp_thumb_photo']}' width='{$comment['pp_thumb_width']}' height='{$comment['pp_thumb_height']}' class='photo' />
					<h4>
						<a href="{$this->settings['board_url']}/index.php?showuser={$comment['member_id']}">{$comment['members_display_name']}</a>
					</h4>
				</div>
				<span class='posted_date desc'>
					{$date} &middot; ({$this->lang->words['comment_ip_addy']}<a href='{$this->settings['_base_url']}&amp;app=members&amp;module=members&amp;section=tools&amp;do=learn_ip&amp;ip={$comment['ip_address']}'>{$comment['ip_address']}</a>)
				</span>
				<div id='comment_{$comment['comment_id']}' class='comment_content'>
					{$comment['post']}
				</div>
			</td>
			<td style='vertical-align:top;'>
				<ul class='controls'>
					<li class='left'>
						<a class='edit' href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=editComment&amp;id={$database['database_id']}&amp;pid={$comment['pid']}'>{$this->lang->words['edit_comment_menu']}</a>
					</li>
					<li class='right ipbmenu' id='menu_folder{$comment['pid']}'>
						{$this->lang->words['folder_options_alt']}
					</li>
				</ul>
				<ul class='acp-menu' id='menu_folder{$comment['pid']}_menucontent'>
					<li class='icon manage'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=toggleComment&amp;id={$database['database_id']}&amp;pid={$comment['pid']}'>{$_commentText}</a></li>
					<li class='icon delete'><a href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=deleteComment&amp;id={$database['database_id']}&amp;pid={$comment['pid']}' );">{$this->lang->words['delete_comment_menu']}</a></li>
				</ul>
			</td>
		</tr>
HTML;
	}
}

$IPBHTML .= <<<HTML
	</table>
</div>
<div>{$pages}</div>

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


/**
 * Show the list of comments for a particular record
 *
 * @access	public
 * @param	array 		Database
 * @param	array 		Record data
 * @param	array 		Comments
 * @param	string		Page links
 * @return	string		HTML
 */
public function comments( $database, $record, $comments, $pagelinks )
{
$IPBHTML = "";
//--starthtml--//

if( $this->request['filter'] == 'queued' )
{
	$IPBHTML .= <<<HTML
	<div class='section_title'>
		<h2>{$this->lang->words['dbcomments_title_q']}</h2>
	</div>
HTML;

	$subtitle	= $this->lang->words['all_q_comm_f'];
}
else
{
	$IPBHTML .= <<<HTML
	<div class='section_title'>
		<h2>{$this->lang->words['dbcomments_title']} {$record['title']}</h2>
	</div>
HTML;
	
	$subtitle	= $this->lang->words['all_saved_comments'];
}

$IPBHTML .= <<<HTML
<div>{$pages}</div>

<script type='text/javascript' src='{$this->settings['js_app_url']}acp.ccs.js'></script>
<div class='acp-box clear'>
	<h3>{$subtitle}</h3>
	<table class='alternate_rows double_pad adv_controls'>
HTML;

if( !count( $comments ) )
{
	$_noneText	= $this->request['filter'] == 'queued' ? $this->lang->words['nomore_q_comments'] : $this->lang->words['no_comments_saved_yet'];
	
	$IPBHTML .= <<<HTML
	<tr>
		<td style='width:100%;'>
			<div style='padding: 20px; text-align: center'>
				<em>{$_noneText}</em>
			</div>
		</td>
	</tr>
HTML;
}
else
{
	foreach( $comments as $comment )
	{
		$date			= $this->registry->class_localization->getDate( $comment['comment_date'], 'LONG' );
		$_commentText	= $comment['comment_approved'] ? $this->lang->words['unapp_comment_menu'] : $this->lang->words['app_comment_menu'];
		$_cssClass		= $comment['comment_approved'] ? '' : '_red';
		
		$_extraLink		= '';
		
		if( $this->request['filter'] == 'queued' )
		{
			$_extraLink	= "<div class='q-c-link'><a href='{$this->settings['base_url']}{$this->form_code}&amp;do=edit&amp;record={$comment['comment_record_id']}'>{$this->lang->words['qc_edit_record']}</a></div>";
		}
	
		$IPBHTML .= <<<HTML
		<tr class='{$_cssClass} control_row'>
			<td style='width:95%;'>
				<div style='float:left;padding-right: 10px;'>
					<img src='{$comment['pp_thumb_photo']}' width='{$comment['pp_thumb_width']}' height='{$comment['pp_thumb_height']}' class='photo' />
					<h4>
						<a href="{$this->settings['board_url']}/index.php?showuser={$comment['member_id']}">{$comment['members_display_name']}</a>
					</h4>
				</div>
				<span class='posted_date desc'>
					{$date} &middot; ({$this->lang->words['comment_ip_addy']}<a href='{$this->settings['_base_url']}&amp;app=members&amp;module=members&amp;section=tools&amp;do=learn_ip&amp;ip={$comment['comment_ip_address']}'>{$comment['comment_ip_address']}</a>)
				</span>
				<div id='comment_{$comment['comment_id']}' class='comment_content'>
					{$comment['comment_post']}
				</div>
				{$_extraLink}
			</td>
			<td style='vertical-align:top;'>
				<ul class='controls'>
					<li class='left'>
						<a class='edit' href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=editComment&amp;id={$database['database_id']}&amp;comment={$comment['comment_id']}&amp;filter={$this->request['filter']}'>{$this->lang->words['edit_comment_menu']}</a>
					</li>
					<li class='right ipbmenu' id='menu_folder{$comment['comment_id']}'>
						{$this->lang->words['folder_options_alt']}
					</li>
				</ul>
				<ul class='acp-menu' id='menu_folder{$comment['comment_id']}_menucontent'>
					<li class='icon manage'><a href='{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=toggleComment&amp;id={$database['database_id']}&amp;comment={$comment['comment_id']}&amp;filter={$this->request['filter']}'>{$_commentText}</a></li>
					<li class='icon delete'><a href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}&amp;module=databases&amp;section=records&amp;do=deleteComment&amp;id={$database['database_id']}&amp;comment={$comment['comment_id']}&amp;filter={$this->request['filter']}' );">{$this->lang->words['delete_comment_menu']}</a></li>
				</ul>
			</td>
		</tr>
HTML;
	}
}

$IPBHTML .= <<<HTML
	</table>
</div>
<div>{$pages}</div>

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

/**
 * Edit a comment
 *
 * @access	public
 * @param	array		Database data
 * @param	array 		Comment data
 * @param	string		Editor HTML
 * @return	string		HTML
 */
public function commentForm( $database, $comment, $editor )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$this->lang->words['editing_a_comment']}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}{$this->form_code}&amp;do=comments&amp;record={$comment['comment_record_id']}' 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=doEditComment' method='post' id='adminform' name='adform'>
<input type='hidden' name='filter' value='{$this->request['filter']}' />
<input type='hidden' name='comment_id' value='{$comment['comment_id']}' />
<input type='hidden' name='pid' value='{$comment['pid']}' />
<div class='acp-box'>
	{$editor}

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

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

}