<?php
/**
 * This file implements the UI for item links in the filemanager.
 *
 * This file is part of the evoCore framework - {@link http://evocore.net/}
 * See also {@link http://sourceforge.net/projects/evocms/}.
 *
 * @copyright (c)2003-2006 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * {@internal License choice
 * - If you have received this file as part of a package, please find the license.txt file in
 *   the same folder or the closest folder above for complete license terms.
 * - If you have received this file individually (e-g: from http://cvs.sourceforge.net/viewcvs.py/evocms/)
 *   then you must choose one of the following licenses before using the file:
 *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
 *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
 * }}
 *
 * {@internal Open Source relicensing agreement:
 * }}
 *
 * @package admin
 *
 * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
 * @author fplanque: Francois PLANQUE.
 *
 * @version $Id: _files_links.inc.php,v 1.6.2.2 2006/11/04 19:54:56 fplanque Exp $
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );


/**
 * @var Item
 */
global $edited_Item;


$Form = & new Form( NULL, 'fm_links', 'post', 'fieldset' );

$Form->global_icon( T_('Quit link mode!'), 'close', regenerate_url( 'fm_mode' ) );

$Form->begin_form( 'fform', sprintf( T_('Link files to &laquo;%s&raquo;...'), $edited_Item->dget('title') ) );

$Form->hidden_ctrl();

$edited_Item->edit_link( '<p>', '</p>', T_('Edit this post') );

$Results = & new Results(
					'SELECT link_ID, link_ltype_ID, T_files.*
						 FROM T_links INNER JOIN T_files ON link_file_ID = file_ID
						WHERE link_itm_ID = '.$edited_Item->ID,
					'link_' );

$Results->title = T_('Existing links');

// TYPE COLUMN:
function file_type( & $row )
{
	global $current_File;

	// Instantiate a File object for this line:
	$current_File = new File( $row->file_root_type, $row->file_root_ID, $row->file_path ); // COPY!
	// Flow meta data into File object:
	$current_File->load_meta( false, $row );

	// File type:
	return $current_File->get_view_link( $current_File->get_icon(), T_('Let browser handle this file!')  ).' '.$current_File->get_type();
}
$Results->cols[] = array(
						'th' => T_('Type'),
						'td_class' => 'left',
						'td' => '%file_type( {row} )%',
					);


// PATH COLUMN:
function file_path()
{
	/**
	 * @global File
	 */
	global $current_File;
	global $edited_Item;

	// File relative path & name:
	return $current_File->edit_link( '&amp;fm_mode=link_item&amp;item_ID='.$edited_Item->ID );
}
$Results->cols[] = array(
						'th' => T_('Path'),
						'order' => 'file_path',
						'td_class' => 'left',
						'td' => '%file_path()%',
					);

$Results->cols[] = array(
						'th' => T_('Title'),
						'order' => 'file_title',
						'td_class' => 'left',
						'td' => '$file_title$',
					);


function file_actions( $link_ID )
{
	global $current_File, $edited_Item;

	$title = T_('Locate this file!');

	$r = $current_File->edit_link( '&amp;fm_mode=link_item&amp;item_ID='.$edited_Item->ID, get_icon( 'locate', 'imgtag', array( 'title'=>$title ) ), $title );

	return $r.' '.action_icon( T_('Delete this link!'), 'unlink',
                      regenerate_url( 'action', 'link_ID='.$link_ID.'&amp;action=unlink') );
}
$Results->cols[] = array(
						'th' => T_('Actions'),
						'td_class' => 'center',
						'td' => '%file_actions( #link_ID# )%',
					);

$Results->display();

printf( '<p>'.T_('Click on a link icon %s below to link an additional file to this item.').'</p>', get_icon( 'link' ) );

$Form->end_form( );


/*
 nolog */
?>