<?php
/**********************************************************************
***********************************************************************/
$path_to_root="..";
$page_security = 'SA_UPLOAD_PROJECT_IMAGES';

include_once($path_to_root . "/includes/db_pager.inc");
include_once($path_to_root . "/includes/session.inc");

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/dashboard/includes/db/upload_project_gallery_images_db.inc");
include_once($path_to_root . "/dashboard/includes/ui/upload_project_gallery_images_ui.inc");
include_once($path_to_root . "/dashboard/includes/ui/project_gallery_ui.inc");
include_once($path_to_root . "/admin/db/transactions_db.inc");



if (isset($_GET['vw'])){
	$view_id = $_GET['vw'];
}
else{
	$view_id = find_submit('view');
}


if ($view_id != -1)
{
	view_project_gallery_image($view_id);
        
}

if (isset($_GET['dl']))
	$download_id = $_GET['dl'];
else
	$download_id = find_submit('download');

if ($download_id != -1)
{
	download_project_gallery_image($download_id);
}

$js = "";
if ($SysPrefs->use_popup_windows){
	$js .= get_js_open_window(800, 500);
}
if (user_use_date_picker()) {
	$js .= get_js_date_picker();
}
page(_($help_context = "Upload Project Gallery Images"), false, false, "", $js);

simple_page_mode(true);
//----------------------------------------------------------------------------------------
if (isset($_GET['filterType'])) // catch up external links
	$_POST['filterType'] = $_GET['filterType'];
if (isset($_GET['trans_no']))
	$_POST['trans_no'] = $_GET['trans_no'];

if ($Mode == 'ADD_ITEM' || $Mode == 'UPDATE_ITEM')
{

        upload_project_gallery_image($Mode, $selected_id);
        
	refresh_pager('trans_tbl');
	$Ajax->activate('_page_body');
	$Mode = 'RESET';
        
}

if ($Mode == 'Delete')
{
	delete_selected_project_gallery_image($Mode, $selected_id);
}

if ($Mode == 'RESET')
{
	unset($_POST['trans_no']);
	unset($_POST['description']);
	$selected_id = -1;
}


//----------------------------------------------------------------------------------------

global $Ajax;

start_form(true);

viewing_controls();

display_rows($_POST['project_id'], $_POST['filtering_section_id'], $_POST['from_date'], $_POST['to_date']);

br(2);

start_table(TABLESTYLE2);

if ($selected_id != -1)
{
	if ($Mode == 'Edit')
	{
		$row = get_project_gallery_image($selected_id);
		$_POST['image_date']  = sql2date($row["image_date"]);
		$_POST['section_id']  = $row["section_id"];
		$_POST['description']  = $row["description"];
//		hidden('trans_no', $row['trans_no']);
		hidden('unique_name', $row['unique_name']);
	}	
	hidden('selected_id', $selected_id);
}

	
$Ajax->activate('filtering_section_id');
$Ajax->activate('section_id');

date_row("Date:", 'image_date');
project_sections_list_row("Section", 'section_id', $_POST['project_id'], null, "Select a project section");
text_row_ex(_("Description").':', 'description', 40);
file_row(_("Attached File") . ":", 'filename', 'filename');

end_table(1);

submit_add_or_update_center($selected_id == -1, '', 'process');

end_form();

end_page();

?>
