<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PROJECT_JOBS';
if (!@$_GET['popup'])
	$path_to_root = "../..";
else	
	$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
//include_once($path_to_root . "/inventory/includes/inventory_db.inc");
include_once($path_to_root . "/projects/includes/ui/project_sites_ui.inc");
include_once($path_to_root . "/projects/includes/db/project_sites_db.inc");
$js = '';

if (user_use_date_picker()) {
    
        $js .= get_js_date_picker();
}

if (!@$_GET['popup'])
        page(_($help_context = "Project Jobs"),false,false,"",$js);

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

check_db_has_projects(_("There are no projects defined in the system."));

simple_page_mode(true);
//---------------------------------------------------------------------------------------------------
$input_error = 0;

if (isset($_GET['project_id']))
{
	$_POST['project_id'] = $_GET['project_id'];
}


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

//set_global_stock_item($_POST['project_id']);
function clear_site_data()
{
	unset($_POST['site_name']);
	unset($_POST['project_site_status_code']);
	unset($_POST['contact_no']);
	unset($_POST['comment']);
	unset($_POST['inactive']);
	
}


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

if ($Mode=='ADD_ITEM') 
{
    handle_add_project_site($Mode, $selected_id);    
}


if ($Mode=='UPDATE_ITEM') 
{
    handle_update_project_site($Mode, $selected_id);
}
//------------------------------------------------------------------------------------------------------

//if ($Mode == 'Delete')
//{
//	//the link to delete a selected record was clicked
//	delete_site($_POST['project_id'], $selected_id);
//	display_notification(_("The selected task has been deleted."));
//	$Mode = 'RESET';
//}

if ($Mode == 'RESET')
{
	$selected_id = -1;
}

//--------------------------------------------------------------------------------------------------------
//$tasks = get_task($_POST['project_id']);

global $Ajax;

if (!@$_GET['popup'])
	start_form();

	br(2);
    
div_start('price_details');
    
start_table(TABLESTYLE_NOBORDER);
start_row();
project_list_cells(_("Project:"), 'project_id', null,
  _('Select a Project'), true);

$project_id = get_post('project_id');
end_row();
end_table();

br();

$Ajax->activate('price_table');

div_start('price_table');
display_project_sites();
div_end();


br(3);

$Ajax->activate('price_details');

div_start('price_details');
display_project_site_edit_controls($Mode, $selected_id);
div_end();

if (!@$_GET['popup'])
{
	end_form(2);
	end_page(@$_GET['popup'], false, false);
}	
?>
