<?php
/**
 * <pre>
 * Invision Power Services
 * File manager skin file
 * Last Updated: $Date: 2010-03-17 20:40:29 -0400 (Wed, 17 Mar 2010) $
 * </pre>
 *
 * @author 		$Author: bfarber $
 * @copyright	(c) 2001 - 2009 Invision Power Services, Inc.
 * @license		http://www.invisionpower.com/community/board/license.html
 * @package		IP.Content
 * @link		http://www.invisionpower.com
 * @since		1st March 2009
 * @version		$Revision: 222 $
 */
 
class cp_skin_filemanager extends output
{

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

/**
 * Button to download .htaccess from advanced settings page
 *
 * @access	public
 * @return	string		HTML
 */
public function downloadHtaccess()
{
$IPBHTML = "";
//--starthtml--//

$IPBHTML .= <<<HTML
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}&amp;module=settings&amp;section=settings&amp;do=download' title='{$this->lang->words['download_htaccess']}'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/disk.png' alt='{$this->lang->words['icon']}' />
				{$this->lang->words['download_htaccess']}
			</a>
		</li>
	</ul>

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

/**
 * Form to specify where to move items to
 *
 * @access	public
 * @param	string		Start point for items we are moving
 * @param	array 		Folders we can omit as option to move to
 * @param	array 		Folders we can move to
 * @param	array 		Pages we are moving
 * @return	string		HTML
 */
public function moveToForm( $startPoint, $ignorable, $folders, $pages )
{
$IPBHTML = "";
//--starthtml--//

$_global = $this->registry->output->loadTemplate( 'cp_skin_ccsglobal' );
$IPBHTML .= $_global->getJsLangs();

$IPBHTML .= <<<HTML
<div class='acp-box'>
	<h3>{$this->lang->words['move_to_form_header']}</h3>
	<form action='{$this->settings['base_url']}{$this->form_code}&amp;do=multi&amp;action=move' method='post'>
	<input type='hidden' name='return' value='{$this->request['return']}' />
	<ul class='acp-form alternate_rows'>
		<li>
			<input type='radio' name='moveto' value='/' />
			<img src='{$this->settings['skin_acp_url']}/_newimages/ccs/folder.png' alt='{$this->lang->words['folder_alt']}' /> /
		</li>
HTML;

	foreach( $folders as $folder )
	{
		if( $folder == '/' OR $folder == $startPoint OR in_array( $folder, $ignorable ) )
		{
			continue;
		}

		$display	= str_replace( $defaultPath . '/', '/', $folder );
			
		$IPBHTML .= <<<HTML
	<li>
		<input type='radio' name='moveto' value='{$folder}' />
		<img src='{$this->settings['skin_acp_url']}/_newimages/ccs/folder.png' alt='{$this->lang->words['folder_alt']}' /> {$display}
	</li>
HTML;
	}

$IPBHTML .= <<<HTML
	</ul>
	<div class="acp-actionbar">
		<input type='submit' value=' {$this->lang->words['move__button']} ' class="button primary" />
	</div>
	<h3>{$this->lang->words['moved_files_summary']}</h3>
	<ul class='alternate_rows filemanager'>
HTML;

if( is_array($this->request['folders']) AND count($this->request['folders']) )
{
	foreach( $this->request['folders'] as $folder )
	{
		$paths	= explode( '/', urldecode($folder) );
		$path	= array_pop( $paths );
		
		$IPBHTML .= <<<HTML
	<li class='record'>
		<div>
			<input type='checkbox' checked='checked' name='folders[]' value='{$folder}' />
			<img src='{$this->settings['skin_acp_url']}/_newimages/ccs/folder.png' alt='{$this->lang->words['folder_alt']}' />
			{$path}
		</div>
	</li>
HTML;

	}
}

if( is_array($pages) AND count($pages) )
{
	foreach( $pages as $page )
	{
		$IPBHTML .= <<<HTML
	<li class='record'>
		<div>
			<input type='checkbox' checked='checked' name='pages[]' value='{$page['page_id']}' />
			<img src='{$this->settings['skin_acp_url']}/_newimages/ccs/file.png' alt='{$this->lang->words['file_alt']}' />
			{$page['page_folder']}/{$page['page_seo_name']}
		</div>
	</li>
HTML;

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

/**
 * Create or edit directory
 *
 * @access	public
 * @param	string		Add/edit
 * @return	string		HTML
 */
public function directoryForm( $type )
{
$IPBHTML = "";
//--starthtml--//

$text	= $type == 'add' ? $this->lang->words['adding_a_folder'] : $this->lang->words['renaming_a_folder'];

$_global = $this->registry->output->loadTemplate( 'cp_skin_ccsglobal' );
$IPBHTML .= $_global->getJsLangs();

$IPBHTML .= <<<HTML
<div class='acp-box'>
	<h3>{$text}</h3>
	<form action='{$this->settings['base_url']}{$this->form_code}' method='post'>
HTML;

if( $type == 'add' )
{
	$formField		= $this->registry->output->formInput( 'folder_name' );
	
	$IPBHTML .= "		<input type='hidden' name='do' value='doCreateFolder' />
		<input type='hidden' name='parent' value='{$this->request['in']}' />";
}
else
{
	$folders		= explode ( '/', urldecode($this->request['dir']) );
	$folderName		= array_pop( $folders );
	$formField		= $this->registry->output->formInput( 'folder_name', $folderName );

	$IPBHTML .= "		<input type='hidden' name='do' value='doRenameFolder' />
		<input type='hidden' name='current' value='{$this->request['dir']}' />";
}

$IPBHTML .= <<<HTML
	<ul class='acp-form alternate_rows'>
		<li>
			<label>{$this->lang->words['set_folder_name']}</label>
			{$formField}
		</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 main screen
 *
 * @access	public
 * @param	string		Current path
 * @param	array 		Folders in the path
 * @param	array 		Files in the path
 * @param	array		Unfinished pages
 * @return	string		HTML
 */
public function overview( $path, Array $folders, Array $files, Array $unfinished )
{
$IPBHTML = "";
//--starthtml--//

$urlencodePath	= urlencode($path);

$_global = $this->registry->output->loadTemplate( 'cp_skin_ccsglobal' );
$IPBHTML .= $_global->getJsLangs();

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

<div class='section_title'>
	<h2>{$this->lang->words['page_and_file_man']}</h2>
</div>

<form action='{$this->settings['base_url']}&amp;module=pages&amp;section=manage&amp;do=multi' method='post'>
<input type='hidden' name='return' value='{$urlencodePath}' />
<div class='acp-box adv_controls' id='page_manager'>
	<h3>
		<div id='page_search'>
			<input type='text' value='{$this->lang->words['pages__filterpages']}' id='page_search_box' spellcheck='false' size='16' /> <a href='#' class='cancel' id='cancel_filter'><img src='{$this->settings['skin_acp_url']}/_newimages/icons/cross.png' alt='{$this->lang->words['cancel']}' /></a>
		</div>
		{$this->lang->words['pages__yourfoldspages']}
	</h3>
	<div class='tablesubheader list_row control_row' style='position: relative'>
		<span id='page_subtitle'>
			<ul class='controls no_extra'>
				<li class='left'>
					<a rel='{$this->request['dir']}' class='new_folder' id='root_add_folder' href='{$this->settings['base_url']}&amp;module=pages&amp;section=manage&amp;do=newDir&amp;in={$path}' title='{$this->lang->words['add_folder_alt']}'> {$this->lang->words['add_folder_alt']}</a>
				</li>
				<li class='right ipbmenu' id='menu_page_root'>
					<a href='#' class='page_add' title='{$this->lang->words['add_content_button']}'>{$this->lang->words['add_content_button']}</a>
				</li>
			</ul>
			<img src='{$this->settings['skin_acp_url']}/_newimages/ccs/folder.png' alt='{$this->lang->words['folder_alt']}' /> {$this->lang->words['pages__siteroot']}
		</span>
	</div>
	<div id='filter_results'></div>
HTML;
	
	if( !count( $folders ) && !count( $files ) )
	{
		$IPBHTML .= <<<HTML
		<div class='no_items' style='text-align: center'>
			<em>{$this->lang->words['no_pages_created']} <a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;in=%2F'>{$this->lang->words['create_one_now']}</a></em>
		</div>
HTML;
	}
	else
	{

		$IPBHTML .= <<<HTML
		<div id='f_wrap_root'>
HTML;

		foreach( $folders as $object )
		{
			$IPBHTML .= $this->showFolder( $object );
		}
	
		foreach( $files as $object )
		{
			$IPBHTML .= $this->showFile( $object );
		}
		
		$IPBHTML .= <<<HTML
	</div>
HTML;

}

$IPBHTML .= <<<HTML
	<div class="acp-actionbar">
		<div>
			{$this->lang->words['with_selected__form']} 
			<select name='action' id='multi-action'>
				<option value='move'>{$this->lang->words['form__move_items']}</option>
				<option value='delete'>{$this->lang->words['form__delete_items']}</option>
			</select>
			<input type="submit" value="{$this->lang->words['form__go']}" class="button primary" onclick="return confirmsubmit();" />
		</div>
	</div>
</div>
</form>

<ul class='acp-menu' id='menu_page_root_menucontent'>
	<li class='icon ccs-file'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;in=' title='{$this->lang->words['add_page_button']}'>{$this->lang->words['add_page_button']}</a></li>
	<li class='icon ccs-css'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;fileType=css&amp;in=' title='{$this->lang->words['add_css_button']}'>{$this->lang->words['add_css_button']}</a></li>
	<li class='icon ccs-js'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;fileType=js&amp;in=' title='{$this->lang->words['add_js_button']}'>{$this->lang->words['add_js_button']}</a></li>
</ul>
<script type='text/javascript'>
	ipb.templates['ccs_folder_wrap'] = new Template("<div id='f_wrap_#{id}' class='folder_wrap' style='display: none'><div>#{content}</div></div>");
	ipb.templates['ccs_new_folder'] = new Template("<div><h3>{$this->lang->words['jst_new_folder']}</h3><div style='padding: 10px'><strong>{$this->lang->words['jst_foldername']}</strong>&nbsp;&nbsp;<input type='text' class='input_text' size='20' id='folder_name_#{id}' />&nbsp;&nbsp;<input type='submit' class='realbutton' value=' {$this->lang->words['jst__create']} ' id='create_folder_#{id}' /></div</div>");
	ipb.templates['ccs_delete_folder'] = new Template("<div><h3>{$this->lang->words['jst_confirm']}</h3><div style='padding: 10px; text-align: center;'><strong>{$this->lang->words['jst_delete_fold']}</strong><br /><br /><input type='submit' class='realbutton redbutton' id='del_#{id}' value='{$this->lang->words['jst_confirm']}' /> <input type='submit' class='realbutton' value='{$this->lang->words['jst_cancel']}' id='cancel_del_#{id}' /></div></div>");
	ipb.templates['ccs_empty_folder'] = new Template("<div><h3>{$this->lang->words['jst_confirm']}</h3><div style='padding: 10px; text-align: center;'><strong>{$this->lang->words['jst_empty_fold']}</strong><br /><br /><input type='submit' class='realbutton redbutton' id='empty_#{id}' value='{$this->lang->words['jst_confirm']}' /> <input type='submit' class='realbutton' value='{$this->lang->words['jst_cancel']}' id='cancel_empty_#{id}' /></div></div>");
	
	// Filter templates
	ipb.templates['ccs_filter_row'] = new Template("<div class='filter_row'><img src='{$this->settings['skin_acp_url']}/_newimages/ccs/#{type}.png' class='icon' alt='{$this->lang->words['folder_alt']}' /><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;do=quickEdit&amp;page=#{id}'>#{name}</a><br /><span class='desctext'>#{path}</span></div>");
	ipb.templates['ccs_filter_none'] = new Template("<div class='filter_row no_results'>{$this->lang->words['jst_filternoma']}</div>");
</script>
HTML;

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


/**
 * Show a single folder
 *
 * @access	public
 * @param	array 		Folders data
 * @return	string		HTML
 */
public function showFolder( $object )
{
$IPBHTML = "";
//--starthtml--//

$path	= urlencode( $object['full_path'] );
$mtime	= $this->registry->getClass('class_localization')->getDate( $object['last_modified'], 'SHORT', 1 );
$id		= md5( $path );

$IPBHTML .= <<<HTML
	<div class='folder list_row control_row' id='f_{$id}'>
HTML;

	$name	= $object['name'] != '..' ?
			"<a href='{$this->settings['base_url']}&amp;module=pages&amp;section=manage&amp;do=editFolder&amp;dir={$path}' class='path' rel=\"{$path}\"><img src='{$this->settings['skin_acp_url']}/_newimages/ccs/folder.png' class='icon' alt='{$this->lang->words['folder_alt']}' /></a>" :
			"<img src='{$this->settings['skin_acp_url']}/_newimages/ccs/folder.png' alt='{$this->lang->words['folder_alt']}' />";

	if( $object['name'] != '..' )
	{
		$IPBHTML .= <<<HTML
			<ul class='controls'>
				<li class='left'>
					<a class='new_folder' href='{$this->settings['base_url']}&amp;module=pages&amp;section=manage&amp;do=newDir&amp;in={$path}' title='{$this->lang->words['add_folder_alt']}'> {$this->lang->words['add_folder_alt']}</a>
				</li>
				<li class='center ipbmenu' id='menu_page{$id}'>
					<a href='#' class='page_add'>{$this->lang->words['add_content_button']}</a>
				</li>
				<li class='right ipbmenu' id='menu_folder{$id}'>
					{$this->lang->words['folder_options_alt']}
				</li>
			</ul>
			<ul class='acp-menu' id='menu_folder{$id}_menucontent'>
				<li class='icon edit'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=manage&amp;do=editFolder&amp;dir={$path}'>{$this->lang->words['edit_folder_name']}</a></li>
				<li class='icon delete'><a href='#' class='empty_folder' id='empty_folder_{$id}' rel="{$path}">{$this->lang->words['empty_folder']}</a></li>
				<li class='icon delete'><a href='#' class='delete_folder' id='delete_folder_{$id}' rel="{$path}">{$this->lang->words['delete_folder_link']}</a></li>
				<li class='icon export'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=manage&amp;do=multi&amp;action=move&amp;folders[]={$path}'>{$this->lang->words['move_folder_link']}</a></li>
			</ul>
			<ul class='acp-menu' id='menu_page{$id}_menucontent'>
				<li class='icon ccs-file'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;in={$path}' title='{$this->lang->words['add_page_button']}'>{$this->lang->words['add_page_button']}</a></li>
				<li class='icon ccs-css'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;fileType=css&amp;in={$path}' title='{$this->lang->words['add_css_button']}'>{$this->lang->words['add_css_button']}</a></li>
				<li class='icon ccs-js'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;fileType=js&amp;in={$path}' title='{$this->lang->words['add_js_button']}'>{$this->lang->words['add_js_button']}</a></li>
			</ul>
			
			<!--<div class='manage'>
				<img class='ipbmenu' id="menu_folder{$id}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['folder_options_alt']}' />
				
			</div>-->

			{$name}<input type='checkbox' name='folders[]' value='{$path}' class='check' />&nbsp;<strong><a href='{$this->settings['base_url']}{$this->form_code}&amp;do=viewdir&amp;dir={$path}'>{$object['name']}</a></strong>
			<br />
			<span class='desctext'>{$mtime}</span>
HTML;
	}
	else
	{
		$IPBHTML .= <<<HTML
				{$name}&nbsp;<strong><a href='{$this->settings['base_url']}{$this->form_code}&amp;do=viewdir&amp;dir={$path}'>{$object['name']}</a></strong>
HTML;
	}

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

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

/**
 * Show a single file
 *
 * @access	public
 * @param	string		Current path
 * @param	array 		Folders in the path
 * @param	array 		Files in the path
 * @param	array		Unfinished pages
 * @return	string		HTML
 */
public function showFile( $object )
{
$IPBHTML = "";
//--starthtml--//

$path	= urlencode( $object['full_path'] );
$icon	= $object['icon'] ? $object['icon'] . '.png' : 'file.png';
$size	= $object['directory']	? ''		: IPSLib::sizeFormat( $object['size'] );
$mtime	= $this->registry->getClass('class_localization')->getDate( $object['last_modified'], 'SHORT', 1 );
$id		= md5( $path );

$url	= $this->registry->ccsFunctions->returnPageUrl( array( 'page_folder' => $object['path'], 'page_seo_name' => $object['name'], 'page_id' => $object['page_id'] ) );

$texts	= array(
				'edit'		=> $this->lang->words['edit_page_link'],
				'delete'	=> $this->lang->words['delete_page_link'],
				'move'		=> $this->lang->words['move_page_link'],
				);

if( $object['icon'] != 'page' )
{
	$texts	= array(
					'edit'		=> $this->lang->words['edit_pagefile_link'],
					'delete'	=> $this->lang->words['delete_file_link'],
					'move'		=> $this->lang->words['move_pagefile_link'],
					);
}

$IPBHTML .= <<<HTML
<div class='file list_row control_row' id='record_{$object['page_id']}'>
	
	<ul class='controls'>
		<li class='left'>
			<a class='edit' href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;do=quickEdit&amp;page={$object['page_id']}'>{$texts['edit']}</a>
		</li>		
		<li class='right ipbmenu' id='menu_{$id}'>
			{$this->lang->words['folder_options_alt']}
		</li>
	</ul>
	<ul class='acp-menu' id='menu_{$id}_menucontent'>
		<li class='icon edit'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;do=quickEdit&amp;page={$object['page_id']}'>{$texts['edit']}</a></li>
		<li class='icon delete'><a href='#' onclick="return acp.confirmDelete( '{$this->settings['base_url']}&amp;module=pages&amp;section=pages&amp;do=delete&amp;page={$object['page_id']}' );">{$texts['delete']}</a></li>
		<li class='icon export'><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=manage&amp;do=multi&amp;action=move&amp;pages[]={$object['page_id']}'>{$texts['move']}</a></li>
	</ul>
	
	<a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;do=quickEdit&amp;page={$object['page_id']}'><img src='{$this->settings['skin_acp_url']}/_newimages/ccs/{$icon}' class='icon' alt='{$this->lang->words['file_alt']}' /></a><input type='checkbox' name='pages[]' value='{$object['page_id']}' class='check' />
	<strong><a href='{$this->settings['base_url']}&amp;module=pages&amp;section=wizard&amp;do=quickEdit&amp;page={$object['page_id']}'>{$object['name']}</a></strong> <span class='view-page'><a href='{$url}' target='_blank' title='{$this->lang->words['view_page_title']}'><img src='{$this->settings['skin_acp_url']}/_newimages/ccs/page_go.png' alt='{$this->lang->words['view_page_title']}' /></a></span>

	<br />
	<span class='desctext'>{$mtime}  ({$size})</span>
</div>
HTML;
//--endhtml--//
return $IPBHTML;
}


}