<?php
/**
 * <pre>
 * Invision Power Services
 * Article manager templates
 * Last Updated: $Date: 2010-01-19 09:19:18 -0500 (Tue, 19 Jan 2010) $
 * </pre>
 *
 * @author 		$Author: rikki $
 * @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		19th January 2010
 * @version		$Revision: 174 $
 */
 
class cp_skin_articles extends output
{

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

/**
 * Add or edit a category
 *
 * @access	public
 * @param	string		add|edit
 * @param	array		Database data
 * @param	array 		Category data
 * @param	array 		Categories
 * @param	string		Select options
 * @return	string		HTML
 */
public function categoryForm( $type, $database, $category, $categories, $selectOpts='' )
{
$IPBHTML = "";
//--starthtml--//

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

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

$name			= $this->registry->output->formInput( 'category_name', $category['category_name'] );
$furl			= $this->registry->output->formInput( 'category_furl_name', $category['category_furl_name'] );
$desc			= $this->registry->output->formTextarea( 'category_description', $category['category_description'], 40, 5, '', '', 'normal' );
$show			= $this->registry->output->formYesNo( 'category_show_records', $category['category_show_records'] );

$metak			= $this->registry->output->formTextarea( 'category_meta_keywords', $category['category_meta_keywords'], 40, 5, '', '', 'normal' );
$metad			= $this->registry->output->formTextarea( 'category_meta_description', $category['category_meta_description'], 40, 5, '', '', 'normal' );

$text			= $type == 'edit' ? $this->lang->words['editing_cat_title'] . $category['category_name'] : $this->lang->words['adding_cat_title'];
$action			= $type == 'edit' ? 'doEdit' : 'doAdd';

//-----------------------------------------
// 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);

$foverride		= $this->registry->output->formYesNo( 'category_forum_override', intval($category['category_forum_override']), 'category_forum_override', array( 'yes' => "onclick=\"\$('ccs-cat-forum').show();\"", 'no' => "onclick=\"\$('ccs-cat-forum').hide();\"" ) );
	
$fsynch			= $this->registry->output->formYesNo( 'category_forum_record', $category['category_forum_record'] );
$fcomments		= $this->registry->output->formYesNo( 'category_forum_comments', $category['category_forum_comments'] );
$fdelete		= $this->registry->output->formYesNo( 'category_forum_delete', $category['category_forum_delete'] );
$fforum			= $this->registry->output->formDropdown( 'category_forum_forum', $_forums, $category['category_forum_forum'] );
$fprefix		= $this->registry->output->formInput( 'category_forum_prefix', $category['category_forum_prefix'] );
$fsuffix		= $this->registry->output->formInput( 'category_forum_suffix', $category['category_forum_suffix'] );

//-----------------------------------------
// Permissions
//-----------------------------------------

require_once( IPS_ROOT_PATH . 'sources/classes/class_public_permissions.php' );
$permissions = new classPublicPermissions( ipsRegistry::instance() );
$matrix			= $permissions->adminPermMatrix( 'cat', $category );

$override		= $this->registry->output->formYesNo( 'category_has_perms', intval($category['category_has_perms']), 'category_has_perms', array( 'yes' => "onclick=\"\$('ccs-perm-matrix').show();\"", 'no' => "onclick=\"\$('ccs-perm-matrix').hide();\"" ) );

$_rss			= explode( ';', $category['category_rss'] );
$rssEnable		= $this->registry->output->formYesNo( 'category_rss_enable', intval($_rss[0]) );
$rssRecache		= $this->registry->output->formInput( 'category_rss_recache', isset($_rss[1]) ? intval($_rss[1]) : 12 );
$rssTotal		= $this->registry->output->formInput( 'category_rss_count', isset($_rss[2]) ? intval($_rss[2]) : 20 );
$rssExclude		= $this->registry->output->formYesNo( 'category_rss_exclude', intval($_rss[3]) );

$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=categories&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>
<form action='{$this->settings['base_url']}{$this->form_code}&amp;do={$action}' method='post' id='adminform' name='adform'>
<input type='hidden' name='category' value='{$category['category_id']}' />

<ul id='tabstrip_ccs_page' class='tab_bar no_title'>
	<li id='tabtab-CCSPAGE|1' class=''>{$this->lang->words['tab__cat_main']}</li>
	<li id='tabtab-CCSPAGE|2' class=''>{$this->lang->words['tab__cat_forum']}</li>
	<li id='tabtab-CCSPAGE|3' class=''>{$this->lang->words['tab__cat_perms']}</li>
</ul>

<div class='acp-box'>
	<div id='tabpane-CCSPAGE|1'>
		<table class='form_table double_pad alternate_rows'>
			<tr>
				<th colspan='2'>{$this->lang->words['edit_cat_details']}</th>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['catform__name']}</label></td>
				<td style='width: 60%'>{$name}</td>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['catform__furl']}</label> <div class='desctext'>{$this->lang->words['catform__furl_desc']}</div></td>
				<td style='width: 60%'>{$furl}</td>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['catform__desc']}</label></td>
				<td style='width: 60%'>{$desc}</td>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['catform__parent']}</label> <div class='desctext'>{$this->lang->words['catform__p_desc']}</div></td>
				<td style='width: 60%'><select name='category_parent_id' id='category_parent_id'>
					<option value='0'>{$this->lang->words['select_cat_one']}</option>
					{$selectOpts}
				</select></td>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['catform__records']}</label></td>
				<td style='width: 60%'>{$show}</td>
			</tr>
			<!--CAT_TEMPLATE-->
			<tr>
				<th colspan='2'>{$this->lang->words['catform_rss_opts']}</th>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['dbform__rsscat']}</label> <div class='desctext'>{$this->lang->words['dbform__rsscat_desc']}</div></td>
				<td style='width: 60%'>{$rssEnable}</td>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['dbform__rssccat']}</label> <div class='desctext'>{$this->lang->words['dbform__rssccat_desc']}</div></td>
				<td style='width: 60%'>{$rssTotal}</td>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['dbform__rssrcat']}</label> <div class='desctext'>{$this->lang->words['dbform__rssrcat_desc']}</div></td>
				<td style='width: 60%'>{$rssRecache}</td>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['dbform__rssecat']}</label> <div class='desctext'>{$this->lang->words['dbform__arssecat_desc']}</div></td>
				<td style='width: 60%'>{$rssExclude}</td>
			</tr>
			<tr>
				<th colspan='2'>{$this->lang->words['catform_meta_tags']}</th>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['dbform__meta_keywords']}</label></td>
				<td style='width: 60%'>{$metak}</td>
			</tr>
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['dbform__meta_description']}</label></td>
				<td style='width: 60%'>{$metad}</td>
			</tr>
		</table>
	</div>

	<div id='tabpane-CCSPAGE|2'>
		<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['catform__foverride']}</label>
				{$foverride}
			</li>
		</ul>
		<div id='ccs-cat-forum'>
			<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>
	
	<div id='tabpane-CCSPAGE|3'>
		<table class='form_table double_pad alternate_rows'>
			<tr>
				<th colspan='2'>{$this->lang->words['edit_cat_permissions_tab']}</th>
			</tr>
		</table>
		<ul class='acp-form alternate_rows'>
			<li>
				<label>{$this->lang->words['catform__aoverride']}</label>
				{$override}
			</li>
		</ul>
		<div style='padding-top:10px' id='ccs-perm-matrix'>
			{$matrix}
		</div>
	</div>

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

<script type='text/javascript'>
	$$('.article_expander').each( function(elem){
		var trigger = $( elem ).down('.trigger');
		var pane = $( elem ).down('.article_expander_pane');
		
		if( trigger && pane ){
			$( trigger ).observe('click', function(e){
				if( $( pane ).visible() ){
					new Effect.BlindUp( $( pane ), { duration: 0.3 } );
					$( elem ).removeClassName('open');
				} else {
					new Effect.BlindDown( $( pane ), { duration: 0.3 } );
					$( elem ).addClassName('open');
				}
			});
		}
	});

	document.observe("dom:loaded",function() 
	{
		ipbAcpTabStrips.register('tabstrip_ccs_page');
	
		if( !$('category_has_perms_yes').checked )
		{
			$('ccs-perm-matrix').hide();
		}
		
		if( !$('category_forum_override_yes').checked )
		{
			$('ccs-cat-forum').hide();
		}
	});

var noShowAlert	= true;
</script>
HTML;

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

/**
 * Get category frontpage template option
 *
 * @access	public
 * @param	array 		Category data
 * @param	array		Templates
 * @param	array 		Containers
 * @return	string		HTML
 */
public function categoryTemplate( $category, $templates, $containers )
{
$IPBHTML = "";
//--starthtml--//

$template		= $this->registry->output->formDropdown( 'category_template', $templates, $category['category_template'], null, null, null, $containers );

$IPBHTML .= <<<HTML
			<tr>
				<td style='width: 40%'><label>{$this->lang->words['catform__template']}</label><div class='desctext'>{$this->lang->words['catform__template_desc']}</div></td>
				<td style='width: 60%'>{$template}</td>
			</tr>
HTML;

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


/**
 * Show the form to move records when deleting a cat
 *
 * @access	public
 * @param	array 		Database
 * @param	array 		Category
 * @param	array 		Categories
 * @param	string		Select menu
 * @return	string		HTML
 */
public function categoryDeleteForm( $database, $category, $categories=array(), $selectOpts='' )
{
$IPBHTML = "";
//--endhtml--//

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$this->lang->words['confirm_cat_delete']}</h2>
</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=delete' method='post'>
<input type='hidden' name='category' value='{$category['category_id']}' />
<div class='acp-box'>
	<h3>{$this->lang->words['confirm_to_ccontinue_d']}</h3>
	<ul class='acp-form alternate_rows'>
		<li>
			<label>{$this->lang->words['cat_to_mvoe_to']}</label>
			<select name='move_to' id='move_to'>{$selectOpts}</select>
		</li>
	</ul>
	<div class="acp-actionbar">
		<input type='submit' value=' {$this->lang->words['button__notd']} ' class="button primary" />
		<input type='button' value=' {$this->lang->words['button__canceld']} ' class="realbutton redbutton" onclick='return acp.redirect("{$this->settings['base_url']}{$this->form_code}");' />
	</div>
</div>	
</form>

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

/**
 * Show the list of categories within a database
 *
 * @access	public
 * @param	array 		Database
 * @param	array 		Categories
 * @param	array 		Parent data (if viewing subcats)
 * @return	string		HTML
 */
public function categories( $database, $categories, $parent=array() )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$this->lang->words['articles_cats_manage']}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}{$this->form_code}&amp;do=add' title='{$this->lang->words['add_cat_alt']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/add.png' alt='{$this->lang->words['icon']}' />
				{$this->lang->words['add_category_button']}
			</a>
		</li>
		<li>
			<a href='{$this->settings['base_url']}{$this->form_code}&amp;do=recache' title='{$this->lang->words['recache_cats_button']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/arrow_refresh.png' alt='{$this->lang->words['icon']}' />
				{$this->lang->words['recache_cats_button']}
			</a>
		</li>
	</ul>
</div>
HTML;

if( $this->request['parent'] )
{
	$this->lang->words['all_created_cats_a']	= $this->lang->words['all_created_cats_t1'] . $parent['category_name'];
}

$IPBHTML .= <<<HTML
<script type='text/javascript' src='{$this->settings['js_app_url']}acp.ccs.js'></script>
<script type="text/javascript">
window.onload = function() {
	Sortable.create( 'sortable_handle', { revert: true, format: 'category_([0-9]+)', onUpdate: dropItLikeItsHot, handle: 'draghandle' } );
};

dropItLikeItsHot = function( draggableObject, mouseObject )
{
	var options = {
					method : 'post',
					parameters : Sortable.serialize( 'sortable_handle', { tag: 'li', name: 'category' } )
				};
 
	new Ajax.Request( "{$this->settings['base_url']}&{$this->form_code_js}&do=reorder&md5check={$this->registry->adminFunctions->getSecurityKey()}".replace( /&amp;/g, '&' ), options );

	return false;
};

</script>
<div class='acp-box'>
	<h3>{$this->lang->words['all_created_cats_a']}</h3>
	<ul id='sortable_handle' class='alternate_rows'>
		<li>
			<table class='double_pad adv_controls'>
				<tr>
					<th style='width: 3%'>&nbsp;</th>
					<th style='width: 42%'>{$this->lang->words['cat_name_th']}</th>
					<th style='width: 12%' class='short'>{$this->lang->words['cat_records_th']}</th>
					<th style='width: 33%'>{$this->lang->words['cat_th_fp_t']}</th>
					<th style='width: 10%'>&nbsp;</th>
				</tr>
			</table>
		</li>
HTML;

if( !count( $categories ) )
{
	$IPBHTML .= <<<HTML
		<li>
			<table class='double_pad adv_controls'>
				<tr>
					<td style='width:100%;'>
						<div style='padding: 20px; text-align: center'>
							<em>{$this->lang->words['no_acats_created_yet']} <a href='{$this->settings['base_url']}{$this->form_code}&amp;do=add'>{$this->lang->words['create_cat_now']}</a></em>
						</div>
					</td>
				</tr>
			</table>
		</li>
HTML;
}
else
{
	foreach( $categories as $category )
	{
		$name	= "<a href='{$this->settings['base_url']}{$this->form_code}&amp;do=edit&amp;category={$category['category_id']}'><strong>{$category['category_name']}</strong></a>";
		
		if( $category['category_description'] )
		{
			$name	.= "<div class='desctext'>{$category['category_description']}</div>";
		}
		
		$children	= '';
		
		if( count($category['children'] ) )
		{
			$name	.= "<div class='desctext' style='margin-top: 20px;'><strong>{$this->lang->words['subcat_prefix']}</strong> ";
			$_c		= array();
			
			foreach( $category['children'] as $child )
			{
				$_c[]	= "<a href='{$this->settings['base_url']}{$this->form_code}&amp;do=list&amp;parent={$child['category_parent_id']}'>{$child['category_name']}</a>";
			}
			
			$name	.= implode( ', ', $_c );
			$name	.= "</div>";
		}

		$IPBHTML .= <<<HTML
		<li id='category_{$category['category_id']}'>
			<table class='double_pad adv_controls'>
				<tr class='action_link_hover control_row'>
					<td style='width: 3%' class='short' style='color: #525252; font-size: 11px;'><div class='draghandle'><img src='{$this->settings['skin_acp_url']}/_newimages/drag_icon.png' alt=''></div></td>
					<td style='width: 42%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/folder.png' /> {$name}</td>
					<td style='width: 12%' class='short'>{$category['category_records']}</td>
					<td style='width: 33%'><span id='tname_for_{$category['category_id']}'><!--CAT_TEMPLATE_{$category['category_id']}--></span></td>
					<td style='width: 10%'>
						<ul class='controls no_extra'>
							<li class='left'>
								<a class='edit' href='{$this->settings['base_url']}{$this->form_code}&amp;do=edit&amp;category={$category['category_id']}' title='{$this->lang->words['edit_cat_menu']}'> {$this->lang->words['edit_cat_menu']}</a>
							</li>
							<li class='right'>
								<a class='delete' href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}{$this->form_code}&amp;do=delete&amp;category={$category['category_id']}' );"> {$this->lang->words['delete_cat_menu']}</a>
							</li>
						</ul>
					</td>
				</tr>
			</table>
		</li>
HTML;
	}
}

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

/**
 * 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[6], $database['database_template_listing'], null, null, null, $categories );
$templateR		= $this->registry->output->formDropdown( 'database_template_display', $templates[5], $database['database_template_display'], null, null, null, $categories );
$templateC		= $this->registry->output->formDropdown( 'database_template_categories', $templates[7], $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 );
$matrix			= str_replace( "Records", $this->lang->words['matrix__articles'], $matrix );
$matrix			= str_replace( "Database", $this->lang->words['matrix__articles'], $matrix );

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$this->lang->words['article_configure_title']}</h2>
</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=doEdit' method='post' id='adminform' name='adform'>
<input type='hidden' name='id' value='{$database['database_id']}' />
<!-- Here we hard code some fields, to simplify the interface -->
<input type='hidden' name='database_description' value="{$database['database_description']}" />
<input type='hidden' name='database_key' value="{$database['database_key']}" />
<input type='hidden' name='database_user_editable' value='1' />
<input type='hidden' name='database_all_editable' value='0' />
<input type='hidden' name='database_open' value='1' />
<input type='hidden' name='database_field_title' value="{$database['database_field_title']}" />
<input type='hidden' name='database_field_content' value="{$database['database_field_content']}" />

<!-- End of hardcoded fields -->
<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_article_main_details']}</h2>
		<ul class='acp-form alternate_rows'>
			<li>
				<label>{$this->lang->words['dbaform__name']}</label>
				{$name}
			</li>
			<!--<li>
				<label>{$this->lang->words['dbaform__key']} <span class='desctext'>{$this->lang->words['dbaform__key_desc']}</span></label>
				{$key}
			</li>-->
			<!--<li>
				<label>{$this->lang->words['dbaform__desc']}</label>
				{$desc}
			</li>-->
			<li class='article_expander'>
				<h4 class='trigger'>{$this->lang->words['dbform_templates_ae']}</h4>
				<ul class='acp-form article_expander_pane' style='display: none;'>
					<li>
						<label>{$this->lang->words['dbform__cats']} <span class='desctext'>{$this->lang->words['dbform__acats_desc']}</span></label>
						{$templateC}
					</li>
					<li>
						<label>{$this->lang->words['dbform__list']} <span class='desctext'>{$this->lang->words['dbform__alist_desc']}</span></label>
						{$templateL}
					</li>
					<li>
						<label>{$this->lang->words['dbform__adisp']} <span class='desctext'>{$this->lang->words['dbform__adisp_desc']}</span></label>
						{$templateR}
					</li>
				</ul>
			</li>
			<li class='article_expander'>
				<h4 class='trigger'>{$this->lang->words['dbform__langbits']}</h4>
				<div class='desctext triggerdesc'>{$this->lang->words['dbaform__langbits_desc']}</div>
				<ul class='acp-form article_expander_pane' style='display: none;'>
					<li>
						<label>{$this->lang->words['langbits_sing_low']}</label>
						{$singlow}
					</li>
					<li>
						<label>{$this->lang->words['langbits_plur_low']}</label>
						{$plurallow}
					</li>
					<li>
						<label>{$this->lang->words['langbits_sing_upp']}</label>
						{$singupper}
					</li>
					<li>
						<label>{$this->lang->words['langbits_plur_upp']}</label>
						{$pluralupper}
					</li>
				</ul>
			</li>
			<li class='article_expander'>
				<h4 class='trigger'>{$this->lang->words['dbform__metatags_ae']}</h4>
				<ul class='acp-form article_expander_pane' style='display: none;'>
					<li>
						<label>{$this->lang->words['dbform__meta_keywords']}</label>
						{$metak}
					</li>
					<li>
						<label>{$this->lang->words['dbform__meta_description']}</label>
						{$metad}
					</li>
				</ul>
			</li>
		</ul>
	</div>
	
	<div id='tabpane-CCSPAGE|2'>
		<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['edit_article_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__arevise_desc']}</span></label>
				{$revisions}
			</li>
			<!--<li>
				<label>{$this->lang->words['dbaform__open']} <span class='desctext'>{$this->lang->words['dbaform__open_desc']}</span></label>
				{$open}
			</li>-->
			<li>
				<label>{$this->lang->words['dbform__comments']} <span class='desctext'>{$this->lang->words['dbform__acomments_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['dbaform__bcomments']} <span class='desctext'>{$this->lang->words['dbaform__bcomments_desc']}</span></label>
				{$commentBump}
			</li>
			<li>
				<label>{$this->lang->words['dbform__rate']} <span class='desctext'>{$this->lang->words['dbform__arate_desc']}</span></label>
				{$rate}
			</li>
			<li>
				<label>{$this->lang->words['dbform__rss']} <span class='desctext'>{$this->lang->words['dbform__arss_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_article_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>
<script type='text/javascript'>
	$$('.article_expander').each( function(elem){
		var trigger = $( elem ).down('.trigger');
		var pane = $( elem ).down('.article_expander_pane');
		
		if( trigger && pane ){
			$( trigger ).observe('click', function(e){
				if( $( pane ).visible() ){
					new Effect.BlindUp( $( pane ), { duration: 0.3 } );
					$( elem ).removeClassName('open');
				} else {
					new Effect.BlindDown( $( pane ), { duration: 0.3 } );
					$( elem ).addClassName('open');
				}
			});
		}
	});
</script>
HTML;

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

/**
 * Add or edit a field
 *
 * @access	public
 * @param	string		add|edit
 * @param	array		Database data
 * @param	array 		Field data
 * @param	array 		Field types
 * @param	array 		Validators
 * @return	string		HTML
 */
public function fieldForm( $type, $database, $field, $types, $validators )
{
$IPBHTML = "";
//--starthtml--//

$name			= $this->registry->output->formInput( 'field_name', $field['field_name'] );
$key			= $this->registry->output->formInput( 'field_key', $field['field_key'] );
$desc			= $this->registry->output->formTextarea( 'field_description', IPSText::br2nl( $field['field_description'] ), 40, 5, '', '', 'normal' );
$extra			= $this->registry->output->formTextarea( 'field_extra', $field['field_extra'], 40, 9, '', '', 'normal' );
$html			= $this->registry->output->formYesNo( 'field_html', $field['field_html'] );

$types			= $this->registry->output->formDropdown( 'field_type', $types, $field['field_type'] );

$required		= $this->registry->output->formYesNo( 'field_required', $field['field_required'] );
$userEdit		= $this->registry->output->formYesNo( 'field_user_editable', $field['field_user_editable'] );
$length			= $this->registry->output->formInput( 'field_max_length', $field['field_max_length'] );
$numeric		= $this->registry->output->formYesNo( 'field_is_numeric', $field['field_is_numeric'] );
$truncate	 	= $this->registry->output->formInput( 'field_truncate', $field['field_truncate'] );
$default		= $this->registry->output->formTextarea( 'field_default_value', $field['field_default_value'], 40, 9, '', '', 'normal' );
$dis_list		= $this->registry->output->formYesNo( 'field_display_listing', $field['field_display_listing'] );
$dis_dis		= $this->registry->output->formYesNo( 'field_display_display', $field['field_display_display'] );

$_available		= array(
						array( 'strtolower', $this->lang->words['ffo__strtolower'] ),
						array( 'strtoupper', $this->lang->words['ffo__strtoupper'] ),
						array( 'ucfirst', $this->lang->words['ffo__ucfirst'] ),
						array( 'ucwords', $this->lang->words['ffo__ucwords'] ),
						array( 'punct', $this->lang->words['ffo__removeexcesspunct'] ),
						array( 'numerical', $this->lang->words['ffo__numericalformat'] ),
						);
$formatopts		= $this->registry->output->formMultiDropdown( 'field_format_opts[]', $_available, explode( ',', $field['field_format_opts'] ) );

$_ex			= explode( ',', $field['field_extra'] );
$fieldtype	 	= $this->registry->output->formDropdown( 'field_rel_type', array( array( 'dropdown', $this->lang->words['relfield_type_d'] ), array( 'multiselect', $this->lang->words['relfield_type_m'] ) ), $_ex[2] );

$validatorOptions	= array( array( 'none', $this->lang->words['validator__none'] ) );
$_validator			= explode( ';_;', $field['field_validator'] );

foreach( $validators as $_valid )
{
	$validatorOptions[]	= array( $_valid['key'], $_valid['language'] );
}

$fieldvalid	 		= $this->registry->output->formDropdown( 'field_validator', $validatorOptions, $_validator[0] );
$fieldvalidCustom	= $this->registry->output->formInput( 'field_validator_custom', htmlspecialchars( $_validator[1], ENT_QUOTES ) );
$fieldvalidError	= $this->registry->output->formInput( 'field_validator_error', $_validator[2] );

$text			= $type == 'edit' ? $this->lang->words['editing_field_title'] . $field['field_name'] : $this->lang->words['adding_field_title'];
$action			= $type == 'edit' ? 'doEdit' : 'doAdd';

//-----------------------------------------
// Restrict our default fields
//-----------------------------------------

$_restrictedText	= '';
$_restrictedDate	= '';

if( !IN_DEV AND in_array( $field['field_key'], array( 'article_title', 'article_body', 'article_image' ) ) )
{
	$_restrictedText	= " style='display:none;'";
}

if( !IN_DEV AND in_array( $field['field_key'], array( 'article_date', 'article_expiry', 'article_cutoff' ) ) )
{
	$_restrictedText	= " style='display:none;'";
	$_restrictedDate	= " style='display:none;'";
	
	$this->lang->words['fieldform__extra']		= $this->lang->words['fieldform__extra_date'];
	$this->lang->words['fieldform__extra_desc']	= $this->lang->words['fieldform__extra_desc_date'];
}
		
$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$text}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}{$this->form_code}' 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>
<script type='text/javascript'>
	var fieldDescriptions	= new Hash();
	fieldDescriptions.set( 'standard', "{$this->lang->words['fieldform__extra_desc']}" );
	fieldDescriptions.set( 'date', "{$this->lang->words['fieldform__extra_desc_date']}" );
	fieldDescriptions.set( 'upload', "{$this->lang->words['fieldform__extra_desc_upload']}" );

</script>
<form action='{$this->settings['base_url']}{$this->form_code}&amp;do={$action}' method='post' id='adminform' name='adform'>
<input type='hidden' name='field' id='field_edit_id' value='{$field['field_id']}' />
<input type='hidden' name='field_key' value='{$field['field_key']}' />
<div class='acp-box'>
	<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['edit_field_details']}</h2>
	<ul class='acp-form alternate_rows'>
		<li>
			<label>{$this->lang->words['fieldform__name']}</label>
			{$name}
		</li>
		<!--<li>
			<label>{$this->lang->words['fieldform__key']} <span class='desctext'>{$this->lang->words['fieldform__key_desc']}</span></label>
			{$key}
		</li>-->
		<li {$_restrictedText}>
			<label>{$this->lang->words['fieldform__desc']}</label>
			{$desc}
		</li>
		<li {$_restrictedText}>
			<label>{$this->lang->words['fieldform__type']}</label>
			{$types}
		</li>
		<li {$_restrictedText}>
			<label>{$this->lang->words['fieldform__useredit']} <span class='desctext'>{$this->lang->words['fieldform__useredit_desc']}</span></label>
			{$userEdit}
		</li>
		<li {$_restrictedText}>
			<label>{$this->lang->words['fieldform__numeric']} <span class='desctext'>{$this->lang->words['fieldform__numeric_desc']}</span></label>
			{$numeric}
		</li>
		<li>
			<label>{$this->lang->words['fieldform__default']} <span class='desctext'>{$this->lang->words['fieldform__default_desc']}</span></label>
			{$default}
		</li>
		<li class='field_type_wrapper' id='field_validator_li'{$_restrictedDate}>
			<label>{$this->lang->words['fieldform__validator']} <span class='desctext'>{$this->lang->words['fieldform__validator_desc']}</span></label>
			{$fieldvalid}<br />
			<div id='validator_custom'>
				<strong>{$this->lang->words['fieldform_validator_custom']}</strong> {$fieldvalidCustom} <br />
				<strong>{$this->lang->words['fieldform_validator_error']}</strong> {$fieldvalidError}
			</div>
		</li>
		<li {$_restrictedText}>
			<label>{$this->lang->words['fieldform__dislist']} <span class='desctext'>{$this->lang->words['fieldform__dislist_desc']}</span></label>
			{$dis_list}
		</li>
		<li {$_restrictedText}>
			<label>{$this->lang->words['fieldform__disdisplay']} <span class='desctext'>{$this->lang->words['fieldform__disdisplay_desc']}</span></label>
			{$dis_dis}
		</li>
		<li class='field_type_wrapper' id='field_html_li'{$_restrictedDate}>
			<label>{$this->lang->words['fieldform__html']}  <span class='desctext'>{$this->lang->words['fieldform__html_desc']}</span></label>
			{$html}
		</li>
		<li class='field_type_wrapper' id='field_required_li'>
			<label>{$this->lang->words['fieldform__req']}</label>
			{$required}
		</li>
		<li class='field_type_wrapper' id='field_length_li'{$_restrictedDate}>
			<label>{$this->lang->words['fieldform__length']} <span class='desctext'>{$this->lang->words['fieldform__length_desc']}</span></label>
			{$length}
		</li>
		<li class='field_type_wrapper' id='field_extra_li'>
			<label>{$this->lang->words['fieldform__extra']} <span class='desctext' id='extra_options_text'>{$this->lang->words['fieldform__extra_desc']}</span></label>
			{$extra}
		</li>
		<li class='field_type_wrapper' id='field_formatopts_li'{$_restrictedDate}>
			<label>{$this->lang->words['fieldform__formatopts']}  <span class='desctext'>{$this->lang->words['fieldform__formatopts_desc']}</span></label>
			{$formatopts}
		</li>
		<li class='field_type_wrapper' id='field_truncate_li'{$_restrictedDate}>
			<label>{$this->lang->words['fieldform__truncate']} <span class='desctext'>{$this->lang->words['fieldform__truncate_desc']}</span></label>
			{$truncate}
		</li>
		<li class='field_type_wrapper' id='field_reltype_li'{$_restrictedDate}>
			<label>{$this->lang->words['fieldform__fieldtype']}</label>
			{$fieldtype}
		</li>
		
		<li class='field_type_wrapper' id='field_databases_li'>
			<label>{$this->lang->words['fieldform__dbs']} <span class='desctext' id='extra_options_text'>{$this->lang->words['fieldform__dbs_desc']}</span></label>
			<select id='field_databases_select' name='field_database'></select>
		</li>
		<li class='field_type_wrapper' id='field_fields_li'>
			<label>{$this->lang->words['fieldform__flds']} <span class='desctext' id='extra_options_text'>{$this->lang->words['fieldform__flds_desc']}</span></label>
			<select id='field_fields_select' name='field_fields'></select>
		</li>
	</ul>

	<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 fields within a database
 *
 * @access	public
 * @param	array 		Database
 * @param	array 		Fields
 * @return	string		HTML
 */
public function fields( $database, $fields )
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$this->lang->words['manage_article_fields']}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}{$this->form_code}&amp;do=add' title='{$this->lang->words['add_field_alt']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/add.png' alt='{$this->lang->words['icon']}' />
				{$this->lang->words['add_field_button']}
			</a>
		</li>
	</ul>
</div>
HTML;

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

if( count($fields) )
{
	$IPBHTML .= <<<HTML
<script type="text/javascript">
window.onload = function() {
	Sortable.create( 'sortable_handle', { revert: true, format: 'field_([0-9]+)', onUpdate: dropItLikeItsHot, handle: 'draghandle' } );
};

dropItLikeItsHot = function( draggableObject, mouseObject )
{
	var options = {
					method : 'post',
					parameters : Sortable.serialize( 'sortable_handle', { tag: 'li', name: 'field' } )
				};
 
	new Ajax.Request( "{$this->settings['base_url']}&{$this->form_code_js}&do=reorder&md5check={$this->registry->adminFunctions->getSecurityKey()}".replace( /&amp;/g, '&' ), options );

	return false;
};
</script>
HTML;
}

$IPBHTML .= <<<HTML
<div class='acp-box'>
	<h3>{$this->lang->words['all_article_fields']}</h3>
	<ul id='sortable_handle' class='alternate_rows'>
		<li>
			<table style='width:100%;'>
				<tr>
					<th style='width: 55%'>{$this->lang->words['field_name_th']}</th>
					<th style='width: 20%'>{$this->lang->words['field_type_th']}</th>
					<th style='width: 10%'>{$this->lang->words['field_required_th']}</th>
					<th style='width: 10%'>{$this->lang->words['field_useredit_th']}</th>
					<th style='width: 5%'>&nbsp;</th>
				</tr>
			</table>
		</li>
HTML;

if( !count( $fields ) )
{
	$IPBHTML .= <<<HTML
		<li>
			<table style='width:100%;'>
				<tr>
					<td style='width:100%;'>
						<div style='padding: 20px; text-align: center'>
							<em>{$this->lang->words['no_fields_created_yet']} <a href='{$this->settings['base_url']}{$this->form_code}&amp;do=add'>{$this->lang->words['create_field_now']}</a></em>
						</div>
					</td>
				</tr>
			</table>
		</li>
HTML;
}
else
{
	$_dev	= IN_DEV;
	$_last	= true;
	$IPBHTML	.= "<li>
						<table style='width:100%;'>
							<tr>
								<th style='width: 100%'>{$this->lang->words['default_art_fields']}</th>
							</tr>
						</table>
					</li>";
	
	foreach( $fields as $field )
	{
		//-----------------------------------------
		// These fields we simply hide (no reason to edit)
		//-----------------------------------------
		
		if( !$_dev AND in_array( $field['field_key'], array( 'article_homepage', 'article_comments' ) ) )
		{
			continue;
		}
		
		//-----------------------------------------
		// These fields we don't allow much config
		//-----------------------------------------
		
		$_restricted	= false;
		
		if( in_array( $field['field_key'], array( 'article_title', 'article_body', 'article_date', 'article_expiry', 'article_cutoff', 'article_image', 'article_homepage', 'article_comments' ) ) )
		{
			$_restricted	= true;
		}
		
		if( !$_restricted )
		{
			if( $_last )
			{
				$IPBHTML	.= "<li>
									<table style='width:100%;'>
										<tr>
											<th style='width: 100%'>{$this->lang->words['custom_art_fields']}</th>
										</tr>
									</table>
								</li>";
				$_last		= false;
			}
		}

		$name	= "<a href='{$this->settings['base_url']}{$this->form_code}&amp;do=edit&amp;field={$field['field_id']}'><strong>{$field['field_name']}</strong></a>";
		
		if( $field['field_description'] )
		{
			$name	.= "<div class='desctext'>{$field['field_description']}</div>";
		}
		
		$_required	= $field['field_required'] ? 'tick.png' : 'cross.png';
		$_useredit	= $field['field_user_editable'] ? 'tick.png' : 'cross.png';
		$_type		= $this->lang->words['field_type__' . $field['field_type'] ];
		
		$_delete	= !$_restricted ? "<li class='right'><a class='delete' href='#' onclick=\"return acp.confirmDelete( '{$this->settings['base_url']}{$this->form_code}&amp;do=delete&amp;field={$field['field_id']}' );\">{$this->lang->words['delete_field_menu']}</a></li>" : '';
		if( !$_delete ){
			$extra_class = 'single';
		}
		
		$IPBHTML .= <<<HTML
		<li id='field_{$field['field_id']}'>
			<table style='width:100%;' class='adv_controls'>
				<tr class='control_row'>
					<td style='width: 3%'><div class='draghandle'><img src='{$this->settings['skin_acp_url']}/_newimages/drag_icon.png' alt=''></div></td>
					<td style='width: 50%'>{$name}</td>
					<td style='width: 20%'>{$_type}</td>
					<td style='width: 10%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_required}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 10%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_useredit}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 5%'>
						<ul class='controls no_extra {$extra_class}'>
							<li class='left'>
								<a class='edit' href='{$this->settings['base_url']}{$this->form_code}&amp;do=edit&amp;field={$field['field_id']}'>{$this->lang->words['edit_field_menu']}</a>
							</li>
							
							{$_delete}
							
						</ul>
					</td>
				</tr>
			</table>
		</li>
HTML;
	}
}

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

/**
 * Add or edit a moderator
 *
 * @access	public
 * @param	string		add|edit
 * @param	array		Database data
 * @param	array 		Moderator data
 * @return	string		HTML
 */
public function moderatorForm( $type, $database, $moderator )
{
$IPBHTML = "";
//--starthtml--//

$types			= array( array( 'group', $this->lang->words['mod_type_group'] ), array( 'member', $this->lang->words['mod_type_member'] ) );
$groups			= array();

foreach( $this->caches['group_cache'] as $id => $data )
{
	$groups[]	= array( $id, $data['g_title'] );
}

$_type			= $this->registry->output->formDropdown( 'moderator_type', $types, $moderator['moderator_type'] );
$group			= $this->registry->output->formDropdown( 'moderator_group', $groups, $moderator['moderator_type'] == 'group' ? $moderator['moderator_type_id'] : 0 );
$username		= $this->registry->output->formInput( 'moderator_member', $moderator['moderator_member'] );

$add			= $this->registry->output->formYesNo( 'moderator_add_record', $moderator['moderator_add_record'] );
$edit			= $this->registry->output->formYesNo( 'moderator_edit_record', $moderator['moderator_edit_record'] );
$delete			= $this->registry->output->formYesNo( 'moderator_delete_record', $moderator['moderator_delete_record'] );
$deletec		= $this->registry->output->formYesNo( 'moderator_delete_comment', $moderator['moderator_delete_comment'] );
$lock			= $this->registry->output->formYesNo( 'moderator_lock_record', $moderator['moderator_lock_record'] );
$unlock			= $this->registry->output->formYesNo( 'moderator_unlock_record', $moderator['moderator_unlock_record'] );
$approve		= $this->registry->output->formYesNo( 'moderator_approve_record', $moderator['moderator_approve_record'] );
$approvec		= $this->registry->output->formYesNo( 'moderator_approve_comment', $moderator['moderator_approve_comment'] );
$pin			= $this->registry->output->formYesNo( 'moderator_pin_record', $moderator['moderator_pin_record'] );
	
$text			= $type == 'edit' ? $this->lang->words['editing_editor'] : $this->lang->words['adding_editor'];
$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']}{$this->form_code}' 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}' method='post' id='adminform' name='adform'>
<input type='hidden' name='moderator' value='{$moderator['moderator_id']}' />
<div class='acp-box'>
	<h2 class='tablesubheader' style='font-weight: bold;'>{$this->lang->words['editor_perms_head']}</h2>
	<ul class='acp-form alternate_rows'>
		<li>
			<label>{$this->lang->words['modform__etype']}</label>
			{$_type}
		</li>
		<li>
			<label>{$this->lang->words['modform__esel']}</label>
			{$this->lang->words['mod_sel_group']} {$group} {$this->lang->words['mod__or_user']} {$username}
		</li>
		<li>
			<label>{$this->lang->words['modform__add']}</label>
			{$add}
		</li>
		<li>
			<label>{$this->lang->words['modform__edit']}</label>
			{$edit}
		</li>
		<li>
			<label>{$this->lang->words['modform__delete']}</label>
			{$delete}
		</li>
		<li>
			<label>{$this->lang->words['modform__deletec']}</label>
			{$deletec}
		</li>
		<li>
			<label>{$this->lang->words['modform__lock']}</label>
			{$lock}
		</li>
		<li>
			<label>{$this->lang->words['modform__pin']}</label>
			{$pin}
		</li>
		<li>
			<label>{$this->lang->words['modform__unlock']}</label>
			{$unlock}
		</li>
		<li>
			<label>{$this->lang->words['modform__approve']}</label>
			{$approve}
		</li>
		<li>
			<label>{$this->lang->words['modform__approvec']}</label>
			{$approvec}
		</li>
	</ul>

	<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 moderators within a database
 *
 * @access	public
 * @param	array 		Database
 * @param	array 		Moderators
 * @param	array 		Member data (for member moderators)
 * @return	string		HTML
 */
public function moderators( $database, $moderators, $members=array() )
{
$IPBHTML = "";
//--starthtml--//

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

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

<div class='acp-box'>
	<h3>{$this->lang->words['manage_editor_tbl_head']}</h3>
	<ul class='alternate_rows'>
		<li>
			<table style='width:100%;'>
				<tr>
					<th style='width: 26%'>{$this->lang->words['editorname_th']}</th>
					<th style='width: 8%'>{$this->lang->words['moderator_col_add']}</th>
					<th style='width: 8%'>{$this->lang->words['mod_edit_th']}</th>
					<th style='width: 8%'>{$this->lang->words['mod_del_th']}</th>
					<th style='width: 8%'>{$this->lang->words['mod_del_c_th']}</th>
					<th style='width: 8%'>{$this->lang->words['mod_lock_th']}</th>
					<th style='width: 8%'>{$this->lang->words['mod_pin_th']}</th>
					<th style='width: 8%'>{$this->lang->words['mod_unlock_th']}</th>
					<th style='width: 8%'>{$this->lang->words['mod_approve_th']}</th>
					<th style='width: 8%'>{$this->lang->words['mod_approvec_th']}</th>
					<th style='width: 2%'>&nbsp;</th>
				</tr>
			</table>
		</li>
HTML;

if( !count( $moderators ) )
{
	$IPBHTML .= <<<HTML
		<li>
			<table style='width:100%;'>
				<tr>
					<td style='width:100%;'>
						<div style='padding: 20px; text-align: center'>
							<em>{$this->lang->words['no_editors_created_yet']} <a href='{$this->settings['base_url']}{$this->form_code}&amp;do=add'>{$this->lang->words['create_editor_now']}</a></em>
						</div>
					</td>
				</tr>
			</table>
		</li>
HTML;
}
else
{
	foreach( $moderators as $moderator )
	{
		$_add		= $moderator['moderator_add_record'] ? 'tick.png' : 'cross.png';
		$_edit		= $moderator['moderator_edit_record'] ? 'tick.png' : 'cross.png';
		$_delete	= $moderator['moderator_delete_record'] ? 'tick.png' : 'cross.png';
		$_deleteC	= $moderator['moderator_delete_comment'] ? 'tick.png' : 'cross.png';
		$_lock		= $moderator['moderator_lock_record'] ? 'tick.png' : 'cross.png';
		$_pin		= $moderator['moderator_pin_record'] ? 'tick.png' : 'cross.png';
		$_unlock	= $moderator['moderator_unlock_record'] ? 'tick.png' : 'cross.png';
		$_approve	= $moderator['moderator_approve_record'] ? 'tick.png' : 'cross.png';
		$_approvec	= $moderator['moderator_approve_comment'] ? 'tick.png' : 'cross.png';

		if( $moderator['moderator_type'] == 'group' )
		{
			$name	= $this->lang->words['mod_g_prefix'] . $this->caches['group_cache'][ $moderator['moderator_type_id'] ]['g_title'];
		}
		else
		{
			$name	= "<a href='{$this->settings['board_url']}/index.php?showuser={$moderator['moderator_type_id']}' target='_blank'>{$members[ $moderator['moderator_type_id'] ]['members_display_name']}</a>";
		}
		
		$IPBHTML .= <<<HTML
		<li>
			<table style='width:100%;' class='adv_controls'>
				<tr class='control_row'>
					<td style='width: 26%'><strong>{$name}</strong></td>
					<td style='width: 8%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_add}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 8%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_edit}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 8%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_delete}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 8%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_deleteC}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 8%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_lock}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 8%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_pin}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 8%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_unlock}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 8%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_approve}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 8%'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/{$_approvec}' alt='{$this->lang->words['icon']}' /></td>
					<td style='width: 2%'>
						<ul class='controls no_extra'>
							<li class='left'>
								<a class='edit' href='{$this->settings['base_url']}{$this->form_code}&amp;do=edit&amp;moderator={$moderator['moderator_id']}'>{$this->lang->words['edit_editor_menu']}</a>
							</li>
							<li class='right'>
								<a class='delete' href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}{$this->form_code}&amp;do=delete&amp;moderator={$moderator['moderator_id']}' );">{$this->lang->words['delete_editor_menu']}</a>
							</li>
						</ul>
					</td>
				</tr>
			</table>
		</li>
HTML;
	}
}

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

/**
 * Front page form
 *
 * @access	public
 * @param	array 		Settings
 * @param	array 		Articles
 * @param	array 		Fields
 * @param	array 		Database data
 * @param	string 		Category data
 * @param	array 		Templates
 * @param	array 		Template containers
 * @return	string		HTML
 */

public function frontpageForm( $cache, $articles, $fields, $database, $categories, $templates, $containers )
{
$IPBHTML ="";
//--starthtml--//

$limit			= $this->registry->output->formInput( 'config_limit', $cache['limit'], 'config_limit', 6 );
$_orders		= array( array( 'asc', $this->lang->words['db_records__asc'] ), array( 'desc', $this->lang->words['db_records__desc'] ) );
$order			= $this->registry->output->formDropdown( 'config_order', $_orders, $cache['order'] );
$fieldSort		= $this->registry->output->formDropdown( 'config_sort', $fields, $cache['sort'] );
$template		= $this->registry->output->formDropdown( 'config_template', $templates, $cache['template'], null, null, null, $containers );


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

<div class='article_box'>
	<div style='width: 34%; float: left'>
		<div class='acp-box'>
			<form action='{$this->settings['base_url']}{$this->form_code}&amp;do=config' method='post'>
			<h3>{$this->lang->words['fp_settings']}</h3>
			<table class='form_table alternate_rows double_pad'>
				<tr>
					<th colspan='2'>{$this->lang->words['title_fp_feed']}</th>
				</tr>
				<tr>
					<td>{$this->lang->words['config_fp_upto']}</td>
					<td>
						{$limit} {$this->lang->words['config_fp_articles']}<br />
						<span class='desctext' style='font-size: 11px'>{$this->lang->words['config_fp_someless']}</span>
					</td>
				</tr>
				<tr>
					<td>{$this->lang->words['config_fp_sort']}</td>
					<td>
						{$fieldSort}
					</td>
				</tr>
				<tr>
					<td>{$this->lang->words['config_fp_order']}</td>
					<td>
						{$order}
					</td>
				</tr>
				<tr>
					<th colspan='2'>{$this->lang->words['title_fp_other']}</th>
				</tr>
				<tr>
					<td>{$this->lang->words['title_fp_template']}</td>
					<td>
						{$template}
					</td>
				</tr>
			</table>
			<div class="acp-actionbar">
				<input type='submit' value='{$this->lang->words['fp_save_settings']}' class="button primary" />
			</div>
			</form>
		</div>
	</div>
	
	<div style='width: 64%; float: right'>
		<div class='acp-box'>
			<form action='{$this->settings['base_url']}{$this->form_code}&amp;do=articles' method='post'>
			<h3>{$this->lang->words['title_fp_currentfpart']}</h3>
			<table class='double_pad alternate_rows adv_controls'>
				<tr>
					<th style='width: 2%'></th>
					<th style='width: 40%'>{$this->lang->words['th_fp_article']}</th>
					<th style='width: 25%' class='short'>{$this->lang->words['th_fp_published']}</th>
					<th style='width: 14%' class='short'>{$this->lang->words['th_fp_hits']}</th>
					<th style='width: 14%' class='short'>{$this->lang->words['th_fp_comments']}</th>
					<th style='width: auto; min-width: 50px;'></th>
				</tr>
HTML;

if( !count($articles) )
{
	$IPBHTML .= <<<HTML
				<tr>
					<td colspan='6' align='center'>{$this->lang->words['no_fp_articles_yet']}</td>
				</tr>
HTML;
}
else
{
	foreach( $articles as $article )
	{
		$IPBHTML .= <<<HTML
				<tr class='control_row'>
					<td class='short'><input type='checkbox' value='{$article['primary_id_field']}' name="articles[]" /></td>
					<td>
						<strong>{$article['title']}</strong><br />
						<span class='desctext' style='font-size: 11px'>{$this->lang->words['fp_posted_in']} <strong>{$article['category']}</strong></span>
					</td>
					<td class='short'>{$article['date']}</td>
					<td class='short'>{$article['record_views']}</td>
					<td class='short'>{$article['record_comments']}</td>
					<td>
						<ul class='controls no_extra'>
							<li class='left'>
								<a class='edit' href='{$this->settings['base_url']}module=articles&amp;section=articles&amp;do=edit&amp;record={$article['primary_id_field']}' title='{$this->lang->words['fp_edit_article']}'> {$this->lang->words['fp_edit_article']}</a>
							</li>
							<li class='right'>
								<a class='delete' href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}{$this->form_code}&amp;do=remove&amp;article={$article['primary_id_field']}', '{$this->lang->words['js_fp_rm_ar']}' );" title='{$this->lang->words['fp_rem_article']}'>{$this->lang->words['fp_rem_article']}</a>
							</li>
						</ul>
					</td>
				</tr>
HTML;
	}
}

$IPBHTML .= <<<HTML
			</table>
			<div class="acp-actionbar" style='text-align: left'>
				<input type='submit' value='{$this->lang->words['remove_sel_fp']}' class="button primary" />
			</div>
			</form>
		</div>
	</div>
	<br class='clear' />
</div>
			
HTML;
//--endhtml--//
return $IPBHTML;
}

/**
 * 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' );

$published		= $this->registry->output->formYesNo( "record_approved", $record['record_approved'] );

if( $type == 'edit' AND $record['member_id'] != $this->memberData['member_id'] )
{
	$_member	= IPSMember::load( $record['member_id'] );
	$_showYou	= "display:none;";
	$_showThem	= "";
}
else
{
	$_showThem	= "display:none;";
	$_showYou	= "";
}

$IPBHTML .= <<<HTML
<div class='section_title'>
	<h2>{$text}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}{$this->form_code}' 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;
}

$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' );
$pin		= $this->registry->output->formYesNo( 'record_pinned', $record['record_pinned'] );

$templates	= array( array( 0, $this->lang->words['artman_def_templ'], '_root_' ) );
$containers	= array();

$this->DB->build( array( 'select' => '*', 'from' => 'ccs_page_templates', 'where' => 'template_database=5' ) );
$this->DB->execute();

while( $r = $this->DB->fetch() )
{
	$templates[]	= array( $r['template_id'], $r['template_name'], $r['template_category'] );
}

$this->DB->build( array( 'select' => 'container_id, container_name', 'from' => 'ccs_containers', 'where' => "container_type='arttemplate'", 'order' => 'container_order ASC' ) );
$this->DB->execute();

while( $r = $this->DB->fetch() )
{
	$containers[ $r['container_id'] ]	= $r['container_name'];
}
		
$template	= $this->registry->output->formDropdown( 'record_template', $templates, $record['record_template'], null, null, null, $containers );

$title		= '';
$editor		= '';
$publish	= '';
$frontpage	= '';
$expiry		= '';
$comments	= '';
$ccutoff	= '';
$_fields	= '';

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 );
	
	//-----------------------------------------
	// Special fields
	//-----------------------------------------
	
	if( $field['field_key'] == 'article_title' )
	{
		$title		= $_field;
		continue;
	}
	else if( $field['field_key'] == 'article_body' )
	{
		$editor		= $_field;
		continue;
	}
	else if( $field['field_key'] == 'article_date' )
	{
		$publish	= $_field;
		continue;
	}
	else if( $field['field_key'] == 'article_homepage' )
	{
		//$frontpage	= $_field;
		$frontpage		= $this->registry->output->formYesNo( 'field_' . $field['field_id'] . '[]', IPSText::cleanPermString( $_default ) );
		continue;
	}
	else if( $field['field_key'] == 'article_expiry' )
	{
		$expiry	= $_field;
		continue;
	}
	else if( $field['field_key'] == 'article_comments' )
	{
		//$comments	= $_field;
		$comments	= $this->registry->output->formYesNo( 'field_' . $field['field_id'], $_default );
		continue;
	}
	else if( $field['field_key'] == 'article_cutoff' )
	{
		$ccutoff	= $_field;
		continue;
	}
	
	$_desc	= $field['field_description'] ? " <div class='desctext'>{$field['field_description']}</div>" : '';

	$_fields	.= <<<HTML
		<tr>
			<td style='width: 30%;'><label>{$field['field_name']}</label>{$_desc}</td>
			<td style='width: 70%;'>{$_field}</td>
		</tr>
HTML;
}

$IPBHTML .= <<<HTML
<form action='{$this->settings['base_url']}{$this->form_code}&amp;do={$action}' 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='article_box'>
	<div class='acp-box' style='width: 64%; float: left;'>
		<h3>{$this->lang->words['edit_record_details']}</h3>
		<table class='form_table alternate_rows double_pad'>
			<tr>
				<td style='width: 30%;'><strong>Article Title</strong></td>
				<td style='width: 70%;'>{$title}</td>
			</tr>
			<tr>
				<td style='width: 30%;'><label>{$this->lang->words['record_form_furl']}</label> <div class='desctext'>{$this->lang->words['record_form_furl_desc']}</div></td>
				<td style='width: 70%;'>{$furl}</td>
			</tr>
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;
}

$IPBHTML .= <<<HTML
			<tr>
				<th colspan='2'>{$this->lang->words['artbody_subtitle']}</th>
			</tr>
			<tr>
				<td colspan='2'>
					{$editor}
				</td>
			</tr>
			<tr>
				<th colspan='2'>{$this->lang->words['artman_fields']}</th>
			</tr>
			<tr>
				<td colspan='2' class='article_expander'>
					<h4 class='trigger'>{$this->lang->words['artman_override_meta']}</h4>
					<div class='article_expander_pane' style='display: none'>
						<div>
							<table class='form_table double_pad'>
								<tr>
									<td style='width: 30%;'><label>{$this->lang->words['dbform__meta_keywords']}</label> <div class='desctext'>{$this->lang->words['meta_tags__override']}</div></td>
									<td style='width: 70%;'>{$metak}</td>
								</tr>
								<tr>
									<td style='width: 30%;'><label>{$this->lang->words['dbform__meta_description']}</label> <div class='desctext'>{$this->lang->words['meta_tags__override']}</div></td>
									<td style='width: 70%;'>{$metad}</td>
								</tr>
							</table>
						</div>
					</div>
				</td>
			</tr>
			{$_fields}
		</table>
	</div>

	<div class='acp-box' style='width: 34%; float: right;'>
		<h3>{$this->lang->words['artsettings_subtitle']}</h3>
	
		<table class='form_table alternate_rows double_pad'>
			<tr>
				<th colspan='2'>{$this->lang->words['artman_publish_settings']}</th>
			</tr>
			<tr>
				<td>{$this->lang->words['art_is_published_now']}</td>
				<td>
					{$published}
				</td>
			</tr>
			<tr>
				<td>{$this->lang->words['artman_publish_date']}</td>
				<td>
					{$publish}
				</td>
			</tr>
			<tr>
				<td>{$this->lang->words['artman_expiry_date']}</td>
				<td>
					{$expiry}
					<div class='desctext'>{$this->lang->words['artman_no_expiry']}</div>
				</td>
			</tr>

			<tr>
				<td>{$this->lang->words['artman_change_author']}</td>
				<td>
					<div id='default_author_display' style='{$_showYou}'>{$this->memberData['members_display_name']} &nbsp;&nbsp;<a href='#' class='action_link' id='change_author'>{$this->lang->words['author_change_art']}</a></div>
					<div id='change_author_display' style='{$_showThem}'>
						<input type='text' size='20' class='textinput' id='record_members_display_name' name='record_members_display_name' value='{$_member['members_display_name']}' />
					</div>
				</td>
			</tr>

			<tr>
				<td>{$this->lang->words['artman_art_templ']}</td>
				<td>
					{$template}
				</td>
			<tr>
				<th colspan='2'>{$this->lang->words['artman_comment_pref']}</th>
			</tr>
			<tr>
				<td>{$this->lang->words['artman_allow_comments']}</td>
				<td>{$comments}</td>
			</tr>
			<tr>
				<td>{$this->lang->words['artman_comment_cutoff']}</td>
				<td>
					{$ccutoff}
					<div class='desctext'>{$this->lang->words['artman_no_ccutoff']}</div>
				</td>
			</tr>
			<tr>
				<th colspan='2'>{$this->lang->words['artman_fp_settings']}</th>
			</tr>
			<tr>
				<td>{$this->lang->words['artman_showon_home']}</td>
				<td>{$frontpage}</td>
			</tr>
			<tr>
				<td>{$this->lang->words['artman_pin_article']}</td>
				<td>{$pin}</td>
			</tr>
		</table>
	</div>
	<br class='clear' /><br />
	<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" />
		<input type='submit' name='preview' value=' {$this->lang->words['button__preview']} ' class="button primary" />
	</div>
</div>
</form>

<script type='text/javascript'>
	$('change_author').observe( 'click', function(e){
		new Effect.Parallel([
			new Effect.BlindUp( $('default_author_display'), { sync: true } ),
			new Effect.BlindDown( $('change_author_display'), { sync: true } )
		], { afterFinish: function(){
			autocomplete	= new ipb.Autocomplete( $('record_members_display_name'), { multibox: false, url: acp.autocompleteUrl, templates: { wrap: acp.autocompleteWrap, item: acp.autocompleteItem } } );
		} } );
		
		Event.stop(e);
		return false;
	});
	
/*	document.observe("dom:loaded", function(){
		
	});*/
	
	$$('.article_expander').each( function(elem){
		var trigger = $( elem ).down('.trigger');
		var pane = $( elem ).down('.article_expander_pane');
		
		if( trigger && pane ){
			$( trigger ).observe('click', function(e){
				if( $( pane ).visible() ){
					new Effect.BlindUp( $( pane ), { duration: 0.3 } );
					$( elem ).removeClassName('open');
				} else {
					new Effect.BlindDown( $( pane ), { duration: 0.3 } );
					$( elem ).addClassName('open');
				}
			});
		}
	});
</script>
HTML;

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

/**
 * Get sort column name
 *
 * @access	private
 * @param	string		Database column
 * @param	array 		Fields
 * @return	string		Friendly name
 */
private function _getColumn( $column, $fields )
{
	if( !$column )
	{
		return 'date';
	}
	
	switch( $column )
	{
		case 'r.primary_id_field':
		case 'primary_id_field':
			return 'id';
		break;
		
		case 'r.record_comments':
		case 'record_comments':
			return 'comments';
		break;

		case 'r.record_views':
		case 'record_views':
			return 'hits';
		break;

		case 'r.record_approved':
		case 'record_approved':
			return 'status';
		break;

		case 'c.category_name':
		case 'category_name':
			return 'category';
		break;
	}
	
	foreach( $fields as $field )
	{
		if( 'field_' . $field['field_id'] == $column OR 'r.field_' . $field['field_id'] == $column )
		{
			if( $field['field_key'] == 'article_title' )
			{
				return 'title';
			}
			else if( $field['field_key'] == 'article_date' )
			{
				return 'date';
			}
		}
	}

	return 'date';
}
	
/**
 * 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--//

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

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

$phrase		= $this->request['search_value'] ? $this->request['search_value'] : $this->lang->words['articles_search_phrase'];
$class 		= ( $this->request['search_value'] AND $this->request['search_value'] != $this->lang->words['articles_search_phrase'] ) ? '' : " class='inactive'";
$pinned		= $this->request['article_pinned'] ? " checked='checked'" : '';
$frontpage	= $this->request['article_homepage'] ? " checked='checked'" : '';
$statYes	= $this->request['record_approved'] == 'yes' ? " selected='selected'" : '';
$statNo		= $this->request['record_approved'] == 'no' ? " selected='selected'" : '';
$commYes	= $this->request['has_comments'] == 'yes' ? " selected='selected'" : '';
$commNo		= $this->request['has_comments'] == 'no' ? " selected='selected'" : '';

//-----------------------------------------
// Sorting defaults
//-----------------------------------------

$order			= $this->_getColumn( $this->request['sort_col'] ? $this->request['sort_col'] : $database['database_field_sort'], $fields );
$direction		= ( $this->request['sort_order'] && in_array( $this->request['sort_order'], array( 'asc', 'desc' ) ) ) ? $this->request['sort_order'] : $database['database_field_direction'];

$sort_id			= $order == 'id' ? " sorting" : '';
$sort_title			= $order == 'title' ? " sorting" : '';
$sort_date			= $order == 'date' ? " sorting" : '';
$sort_hits			= $order == 'hits' ? " sorting" : '';
$sort_comments		= $order == 'comments' ? " sorting" : '';
$sort_category		= $order == 'category' ? " sorting" : '';
$sort_status		= $order == 'status' ? " sorting" : '';

//-----------------------------------------
// Languages
//-----------------------------------------

$_global = $this->registry->output->loadTemplate( 'cp_skin_ccsglobal' );
$IPBHTML .= $_global->getJsLangs();
		
$IPBHTML .= <<<HTML
<script type='text/javascript' src='{$this->settings['js_app_url']}acp.tablesorter.js'></script>
<script type='text/javascript' src='{$this->settings['js_app_url']}acp.ccs.js'></script>

<div class='section_title'>
	<h2>{$this->lang->words['articles_manage_title']}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}{$this->form_code}&amp;do=add' 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>
	</ul>
</div>

<form action='{$this->settings['base_url']}{$this->form_code}' method='post'>
<div class='filter_box'>
	<div>
		<div style='float:right;'><input type='submit' value='{$this->lang->words['art_sort_apply']}' /></div>
		<strong>{$this->lang->words['articles_filter_art']}</strong>&nbsp;&nbsp;
		<input name='search_value' type='text' {$class} value='{$phrase}' size='18' id='filter_search' />&nbsp;
		<select name='category' id='category'>
			<option value='0'>{$this->lang->words['db_records__cf_all']}</option>
			<option value='-'>---------</option>
			{$categoryFilter}
		</select>
		&nbsp;
		<select name='record_approved' id='record_approved'>
			<option value='0'>{$this->lang->words['articles_filt_stat']}</option>
			<option value='0'>---------</option>
			<option value='yes'{$statYes}>{$this->lang->words['articles_filt_stat_p']}</option>
			<option value='no'{$statNo}>{$this->lang->words['articles_filt_stat_d']}</option>
		</select>
		&nbsp;
		<select name='has_comments' id='has_comments'>
			<option value='0'>{$this->lang->words['articles_filt_comments']}</option>
			<option value='0'>---------</option>
			<option value='yes'{$commYes}>{$this->lang->words['articles_filt_comments_p']}</option>
			<option value='no'{$commNo}>{$this->lang->words['articles_filt_comments_d']}</option>
		</select>
		&nbsp;
		<input type='checkbox' name='article_homepage' value='1'{$frontpage} id='filter_fp' />
		<label for='filter_fp'>{$this->lang->words['articles_filt_fp']}</label>
		&nbsp;&nbsp;
		<input type='checkbox' name='article_pinned' value='1'{$pinned} id='filter_pinned' />
		<label for='filter_pinned'>{$this->lang->words['articles_filt_pinned']}</label>
	</div>
</div>
</form>

<div id='pages_top'>{$pages}</div>

<div class='acp-box clear'>
	<h3>{$this->lang->words['all_created_records_ta']}</h3>
	<table class='double_pad alternate_rows sortable adv_controls' id='article_manager'>
		<thead>
			<tr>
				<th id='sort_id' class='sort{$sort_id}' style='width: 4%'><span class='sort_order'>&nbsp;</span></th>
				<th id='sort_title' class='sort{$sort_title}' style='width: 31%'><span class='sort_order'>{$this->lang->words['ma_th_title']}</span></th>
				<th id='sort_date' class='sort{$sort_date}' style='width: 16%'><span class='sort_order'>{$this->lang->words['ma_th_date']}</span></th>
				<th id='sort_hits' class='sort{$sort_hits}' style='width: 6%'><span class='sort_order'>{$this->lang->words['ma_th_hits']}</span></th>
				<th id='sort_comments' class='sort{$sort_comments}' style='width: 6%;'><span class='sort_order'>{$this->lang->words['ma_th_com']}</span></th>
				<th id='sort_category' class='sort{$sort_category}' style='width: 20%'><span class='sort_order'>{$this->lang->words['ma_th_category']}</span></th>
				<th id='sort_status' class='sort short{$sort_status}' style='width: 14%'><span class='sort_order'>{$this->lang->words['ma_th_status']}</span></th>
				<th style='width: 5%'></th>
			</tr>
		</thead>
		<tbody>
HTML;

if( !count( $records ) )
{
	$IPBHTML .= <<<HTML
	<tr>
		<td colspan='8'>
			<div style='padding: 20px; text-align: center'>
				<em>{$this->lang->words['no_records_created_yet']} <a href='{$this->settings['base_url']}{$this->form_code}&amp;do=add'>{$this->lang->words['create_record_now']}</a></em>
			</div>
		</td>
	</tr>
HTML;
}
else
{
	foreach( $records as $record )
	{
		$IPBHTML	.= $this->articleRow( $record, $database, $fields, $fieldClass );
	}
}


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

<div id='pages_bottom'>{$pages}</div>


<script type='text/javascript'>
	var obj = new acp.tablesorter( 
					$('article_manager'),
					{
						url: "{$this->settings['base_url']}app=ccs&module=ajax&section=articles&do=sort",
						startOrder: '{$direction}',
						startColumn: '{$order}'
					}, 
					{
						afterUpdate: function( sorter ){
							// We need to build menus
							var menus = $( sorter.table ).select('.ipbmenu');

							if( menus.length )
							{
								for( i=0;i<menus.length;i++ )
								{
									var menuid = $( menus[i] ).id;
									var menucontent = $( menuid + '_menucontent' );

									if( $( menucontent ) ){
										new ipb.Menu( $(menuid), $(menucontent) );
									}
								}
							}
						}
					}
			  );

	$('filter_search').observe('focus', function(e){
		if( $( this ).hasClassName('inactive') ){
			$( this ).removeClassName('inactive').value = '';
		}
	});
</script>
HTML;
//--endhtml--//
return $IPBHTML;
}

/**
 * Show article approved status
 *
 * @access	public
 * @return	string		HTML
 */
public function ajaxRecordDraft()
{
	return "<span class='draft'>{$this->lang->words['ma_draft']}</span>";
}

/**
 * Show article approved status
 *
 * @access	public
 * @return	string		HTML
 */
public function ajaxRecordApproved()
{
	return "<span class='published'>{$this->lang->words['ma_published']}</span>";
}

/**
 * Articles row
 *
 * @access	public
 * @param	array 		Record
 * @param	array 		Database info
 * @param	array 		Fields
 * @param	obj			Fields class
 * @return	string		HTML
 */
public function articleRow( $record, $database, $fields, $fieldClass )
{
$IPBHTML = "";
//--starthtml--//

$_cssClass		= $record['record_approved'] ? '' : '_red';
$status			= $record['record_approved'] ? $this->ajaxRecordApproved() : $this->ajaxRecordDraft();

$_pinned	= '';

if( $record['record_pinned'] )
{
	$_pinned	= $this->registry->getClass('output')->getTemplate('forum')->topicPrefixWrap( $this->settings['pre_pinned'] );
}

foreach( $fields as $field )
{
	if( $field['field_key'] == 'article_title' )
	{
		$record['title']	= $fieldClass->getFieldValue( $field, $record, 100 );
	}
	else if( $field['field_key'] == 'article_date' )
	{
		$record['date']	= $fieldClass->getFieldValue( $field, $record, 100 );
	}
}
		
$revisions	= '';
$comments	= '';

if( $database['database_revisions'] )
{
	$revisions	= "<li class='icon view'><a href='{$this->settings['base_url']}{$this->form_code}&amp;do=revisions&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']}{$this->form_code}&amp;do=comments&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']}{$this->form_code}&amp;do=lock&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']}{$this->form_code}&amp;do=lock&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']}{$this->form_code}&amp;do=pin&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']}{$this->form_code}&amp;do=pin&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']}{$this->form_code}&amp;do=approve&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']}{$this->form_code}&amp;do=approve&amp;record={$record['primary_id_field']}'>{$this->lang->words['app_record__menu']}</a></li>";
}
	
$IPBHTML .= <<<HTML
<tr id='result_{$record['primary_id_field']}' class='control_row {$_cssClass}'>
	<td class='short' style='color: #525252; font-size: 11px;'>{$record['primary_id_field']}</td>
	<td>{$_pinned}<a href='{$this->settings['base_url']}{$this->form_code}&amp;do=edit&amp;record={$record['primary_id_field']}' title='{$this->lang->words['edit_record_menu']}'>{$record['title']}</a></td>
	<td>{$record['date']}</td>
	<td class='short'>{$record['record_views']}</td>
	<td class='short'>{$record['record_comments']}</td>
	<td>{$record['category_name']}</td>
	<td class='short' style='cursor: pointer' id='toggle_status_{$record['primary_id_field']}'>
		{$status}
	</td>
	<td>
		<ul class='controls'>
			<li class='left'>
				<a class='edit' href='{$this->settings['base_url']}{$this->form_code}&amp;do=edit&amp;record={$record['primary_id_field']}' title='{$this->lang->words['edit_record_menu']}'> {$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']}{$this->form_code}&amp;do=delete&amp;record={$record['primary_id_field']}' );">{$this->lang->words['delete_record_menu']}</a></li>
			{$approved}
			{$locked}
			{$pinned}
			{$revisions}
			{$comments}
		</ul>
		<script type='text/javascript'>
			$('toggle_status_{$record['primary_id_field']}').observe('click', function(e){
				var req = "{$this->settings['base_url']}module=ajax&section=articles&do=toggle&id={$record['primary_id_field']}";
				
				new Ajax.Request(	req.replace(/&amp;/g, "&"),
									{
										method: 'post',
										parameters: { secure_key: ipb.vars['md5_hash'] },
										onSuccess: function(t)
										{
											if( t.responseText == 'error' )
											{
												alert( "{$this->lang->words['js_error_enc']}" );
												return;
											}

											$( 'toggle_status_{$record['primary_id_field']}' ).update( t.responseText );
											
											if( $( 'result_{$record['primary_id_field']}' ).hasClassName('acp-row-red') )
											{
												$( 'result_{$record['primary_id_field']}' ).removeClassName('acp-row-red');
												$( 'result_{$record['primary_id_field']}' ).addClassName('acp-row-off');
											}
											else
											{
												$( 'result_{$record['primary_id_field']}' ).removeClassName('acp-row-on');
												$( 'result_{$record['primary_id_field']}' ).removeClassName('acp-row-off');
												
												$( 'result_{$record['primary_id_field']}' ).addClassName('acp-row-red');
											}
										}
									}
								);
			});
		</script>
	</td>
</tr>
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 width='100%' cellpadding='0' cellspacing='0' class='alternate_rows double_pad'>
		<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>
			<td>{$date}</td>
			<td><a href='{$this->settings['board_url']}/index.php?showuser={$revision['member_id']}'>{$revision['members_display_name']}</a></td>
			<td>		
				<div class='manage'>
					<img class='ipbmenu' id="menu_{$revision['revision_id']}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['folder_options_alt']}' />
					<ul class='acp-menu' id='menu_{$revision['revision_id']}_menucontent'>
						<li class='icon edit'><a 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='icon delete'><a href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}{$this->form_code}&amp;do=deleteRevision&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']}{$this->form_code}&amp;do=restoreRevision&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']}{$this->form_code}&amp;do=compareRevision&amp;revision={$revision['revision_id']}'>{$this->lang->words['compare_revision_menu']}</a></li>
					</ul>
				</div>	
			</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
 *
 * @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['primary_id_field']}</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 width='100%' cellpadding='0' cellspacing='0' class='alternate_rows double_pad'>
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}'>
			<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;'>		
				<div class='manage'>
					<img class='ipbmenu' id="menu_{$comment['comment_id']}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['folder_options_alt']}' />
					<ul class='acp-menu' id='menu_{$comment['comment_id']}_menucontent'>
						<li class='icon edit'><a href='{$this->settings['base_url']}{$this->form_code}&amp;do=editComment&amp;comment={$comment['comment_id']}&amp;filter={$this->request['filter']}'>{$this->lang->words['edit_comment_menu']}</a></li>
						<li class='icon manage'><a href='{$this->settings['base_url']}{$this->form_code}&amp;do=toggleComment&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']}{$this->form_code}&amp;do=deleteComment&amp;comment={$comment['comment_id']}&amp;filter={$this->request['filter']}' );">{$this->lang->words['delete_comment_menu']}</a></li>
					</ul>
				</div>	
			</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']}' />
<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;
}


}