<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_EST_PROJECTS';
$path_to_root = "../..";
include($path_to_root . "/includes/session.inc");
include_once ($path_to_root . "/trace.php");
$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(900, 500);
if (user_use_date_picker())
	$js .= get_js_date_picker();
	
page(_($help_context = "Estimation Project"), @$_REQUEST['popup'], false, "", $js);

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 . "/inventory/includes/inventory_db.inc");
include_once($path_to_root . "/estimation/includes/db/est_projects_db.inc");

include_once($path_to_root . "/estimation/includes/ui/est_approve_project_ui.inc");
include_once($path_to_root . "/includes/ui/ui_lists_estimation.inc");
include_once($path_to_root . "/includes/approval_functions.inc");

include_once($path_to_root . "/estimation/includes/db/est_project_boq_items_db.inc");
include_once($path_to_root . "/admin/db/list_values_db.inc");       
        

$user_comp = user_company();

$new_item = get_post('est_project_id')== '' || get_post('est_project_id')== -1 || get_post('cancel') || get_post('clone'); 


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

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

$est_project_id = get_post('est_project_id');

if (list_updated('est_project_id')) {
	$_POST['NewProjectID'] = $est_project_id = get_post('est_project_id');
    clear_data();
	$Ajax->activate('details');
	$Ajax->activate('controls');
}

if (get_post('cancel')) {
	$_POST['NewProjectID'] = $est_project_id = $_POST['est_project_id'] = '';
    clear_data();
	set_focus('est_project_id');
	$Ajax->activate('_page_body');
}
if (list_updated('category_id') || list_updated('mb_flag')) {
	$Ajax->activate('details');
}

if (isset($_GET['Approved_id'])) 
{
    $trans_no = $_GET['Approved_id'];
    
//    $project = get_project_record($trans_no);
    $message = get_session_variable('approve_project_messages');
    clear_session_variable('approve_project_messages');

    display_notification_centered($message);
    
    hyperlink_no_params("$path_to_root/estimation/inquiry/est_unapproved_projects_inquiry.php", _("Approve another estimation project."));

    display_footer_exit();
}

function clear_data()
{
    unset($_POST['code']);
    unset($_POST['project_name']);
    unset($_POST['company_category_code']);
    unset($_POST['group_serial_no']);
    unset($_POST['company_serial_no']);
    unset($_POST['year']);
    unset($_POST['customer_category_code']);
    unset($_POST['project_category_code']);
    unset($_POST['category_serial_no']);
    unset($_POST['project_start_date']);
    unset($_POST['project_end_date']);
    unset($_POST['project_value']);
    unset($_POST['estimated_cost']);
    unset($_POST['project_manager_id']);
    unset($_POST['long_description']);
    unset($_POST['inactive']); 
    unset($_POST['customer_id']);
    unset($_POST['project_manager_name']);
    unset($_POST['contact_person']);
    unset($_POST['NewProjectID']);
	
}

function can_commit($new_item){
    $input_error = 0;
    
    if(!$new_item){
        $est_project = get_est_project_record($_POST['est_project_id']);
        if(!($est_project['approval_status'] == AS_NEW || $est_project['approval_status'] == AS_WITH_THE_APPROVER || 
                $est_project['approval_status'] == AS_AWAITING_APPROVAL || $est_project['approval_status'] == AS_BACK_TO_ORIGINATOR || 
                $est_project['approval_status'] == AS_REOPENED)){
            $message = ("This estimation project status does not allow further updating.");
            display_error($message);
            return false;
        }
        
        $current_user_id = $_SESSION['wa_current_user']->user;
        $ced_msg = can_edit_document(ST_APPROVE_EST_PROJECT, $est_project['project_id'], $est_project['next_approval_group_id'] , $current_user_id, 
                                        $est_project['created_by'], $est_project['est_project_id']);
        if($ced_msg['success'] !== true){
            display_error($ced_msg['message']);
            return false;
        }
    }    
 
    if (is_date($_POST['project_start_date']) == FALSE){

        $input_error = 1;
        display_error( _("Incorrect start date"));
        set_focus('project_start_date');
        return false;
    }
    if (is_date($_POST['project_end_date']) == FALSE){

            $input_error = 1;
            display_error( _("Incorrect end date"));
            set_focus('project_end_date');
            return false;
    }
        
    if (date1_greater_date2($_POST['project_start_date'], $_POST['project_end_date']))
	{
		$input_error = 1;
		display_error( _("Project end date can not be greater than task start date"));
		set_focus('project_end_date');
                return false;
	}

        
    if (check_num('project_value', 0) == false) 
	{
		$input_error = 1;
		display_error( _('Project value must be numeric and positive.'));
		set_focus('project_value');
                return false;
	}  
         
    if (check_num('estimated_cost', 0) == false) 
	{
		$input_error = 1;
		display_error( _('Project estimated cost must be numeric and positive.'));
		set_focus('estimated_cost');
                return false;
	} 
        
//    if (!($_POST['department_id']> 0 )) 
//    {
//            $input_error = 1;
//            display_error( _('Please selecta department.'));
//            set_focus('department_id');
//            return false;
//    }    
    
    if($new_item)
    {
//        if ($_POST['company_category_code'] == -1) 
//        {
//                $input_error = 1;
//                display_error( _('Select a company.'));
//                set_focus('company_category_code');
//                return false;
//        } 
//        if (strlen($_POST['group_serial_no']) == 0) 
//        {
//                $input_error = 1;
//                display_error( _('The group serial number must be entered.'));
//                set_focus('group_serial_no');
//                return false;
//        } 
//        if (check_num('group_serial_no', 0) == FALSE)
//        {
//                $input_error = 1;
//                display_error( _("Group serial number must be numeric."));
//                set_focus('group_serial_no');
//                return false;
//        }
//         if ($_POST['customer_category_code'] == -1) 
//        {
//                $input_error = 1;
//                display_error( _('Select a customer category.'));
//                set_focus('customer_category_code');
//                return false;
//        } 
//        if ($_POST['project_category_code'] == -1) 
//        {
//                $input_error = 1;
//                display_error( _('Select a project.'));
//                set_focus('project_category_code');
//                return false;
//        }
    }
        
//    if(!($_POST['data_access_group_id'] > 0)) 
//    {
//        $input_error = 1;
//        display_error( _('Please select a Data Access Group.'));
//        set_focus('data_access_group_id');
//        return false;
//    } 
//    
//    if (!($_POST['approval_project_id']> 0 )) 
//    {
//            $input_error = 1;
//            display_error( _('Please select an approval project.'));
//            set_focus('approval_project_id');
//            return false;
//    }
    
    return true;
}

function check_project_require_approval($est_project_id)
{
    
    $old_project = get_est_project_record($est_project_id);
    
    if(date2sql($_POST['project_start_date']) != $old_project['start_date']){
        return true;
    }
    if(date2sql($_POST['project_end_date']) != $old_project['end_date']){
        return true;
    }
    if($_POST['revenue_account'] != $old_project['revenue_account']){
        return true;
    }
    if($_POST['cost_account'] != $old_project['cost_account']){
        return true;
    }

    if(input_num('project_value') != $old_project['project_value']){
        return true;
    }
    
    return false;
}

function project_settings(&$est_project_id) 
{
	global $SysPrefs, $path_to_root, $new_item, $pic_height, $Refs;

	start_outer_table(TABLESTYLE2);

	table_section(1);

	table_section_title(_("Estimation"));
	//------------------------------------------------------------------------------------
	if ($new_item) 
	{
            if(isset($_POST['project_code_1'])){
                $code = $_POST['project_code_1'];
            }
            else{
                $code = '';
            }
            text_row("Code", "code", null, 25, 50);
            text_row(_("Description:"), 'description', null, 50, 200);
            textarea_row(_('Long Description:'), 'long_description', null, 31, 3);

            value_list_row(_("Department:"), 'department_id', 'DEPARTMENTS', null,"Select a Department");      
//            yesno_list_row("Purchase to Stock:", 'purchase_to_stock', null, 'Yes', 'No');
            date_row(_('Start date:'), 'project_start_date');

            date_row(_('End date:'), 'project_end_date');

            //date_row(_('Frozen date:'), 'frozen_date');

            customer_list_row(_('Customer:'), 'customer_id', null, _('Select Customer') ,false);
            amount_row(_('Project Value:'), 'project_value'); 
//            amount_row(_('Estimated Project Cost:'), 'estimated_cost');
            hidden('estimated_cost', 0);
            
//            $budget_details = get_project_tasks_current_budgets_total($project_id);            
//            label_row("Department Approved Budgets Total:", number_format($budget_details['current_budgets_total'], 2));            
//            label_row("Unapproved Budget Total:", number_format($budget_details['unapproved_budgets_total'],2));
            
            yesno_list_row("Rate include taxes:", 'rate_include_taxes', null, 'Yes', 'No');
            user_list_row(_("Project Manager:"), 'project_manager_id', null, false, true);
            text_row("Project Manager Name:", "project_manager_name", null, 50, 150);
            text_row("Contact Person:", "contact_person", null, 50, 150);
  
            project_list_row(_("Approval Project:"), 'approval_project_id', null, _('Select an approval project'), true, check_value('show_inactive'));

            value_list_row("Data Access Group:", 'data_access_group_id', 'DATA_ACCESS_GROUPS', null, 'Select a Data Access Group', false);
            
            global $approval_statuses;
            label_row("Approval Status:", $approval_statuses[0]);
            hidden('approved', 0);

            $fresh_item = !isset($_POST['NewProjectID']) || $new_item 
                || check_usage($_POST['est_project_id'],false);


            record_status_list_row(_("Status:"), 'inactive');

//            table_section(2);
//            table_section_title(_("Reference Structure"));
//                project_serial_category_list_row(_("Select a Company:"), 'company_category_code', null,
//                            _('Select a company'), true, 3,check_value('show_inactive')); 
//
//                ref_row(_("Group Serial No:"), 'group_serial_no', '', $Refs->get_next(103));
//
//                if($_POST['company_category_code'] != -1){
//                    $myrow = get_next_number($_POST['company_category_code']);
//                    $company_serial_no = $myrow["next_number"];
//                    label_row(_("Company Serial No:"), $company_serial_no);
//                    //text_row(_("Company Serial No:"), 'company_serial_no', $_POST['company_serial_no'], 20, 20);
//                }
//                else{
//                    label_row(_("Company Serial No:"), '');
//                }
//
//                value_list_code_row(_("Year:"), 'year', 'YEAR');
//
//                project_serial_category_list_row(_("Customer Category:"), 'customer_category_code', null,
//                            _('Select a customer'), true, 2,check_value('show_inactive'));
//
//                project_serial_category_list_row(_("Project Category:"), 'project_category_code', null,
//                            _('Select a project'), true, 1,check_value('show_inactive'));
//
//                if($_POST['project_category_code'] != -1){
//                    $result = get_next_number($_POST['project_category_code']);
//                    $project_category_code = $result["next_number"];
//
//                    label_row(_("Category Serial No:"), $project_category_code);
//                    //text_row(_("Category Serial No:"), 'project_category_code', $_POST['project_category_code'], 20, 20);
//                }
//                else{
//                    label_row(_("Category Serial No:"), '');
//                }
//             //ref_row(_("Category Serial No:"), 'category_serial_no', '', $Refs->get_next(101));
//
//            table_section_title(_("Accounts"));
//                $company_record = get_company_prefs();
//                if(!(isset($_POST['revenue_account']) && strlen($_POST['revenue_account']) > 1) || list_updated('project_id')){
//                    $_POST['revenue_account']  = $company_record["default_proj_revenue_act"];
//                }
//                if(!(isset($_POST['cost_account']) && strlen($_POST['cost_account']) > 1) || list_updated('project_id')){
//                    $_POST['cost_account']  = $company_record["default_proj_cost_act"];
//                }
//                gl_all_accounts_list_row(_("Revenue Account:"), 'revenue_account');
//                gl_all_accounts_list_row(_("Cost Account:"), 'cost_account');

            
            end_outer_table(1);
                    
            $_POST['inactive'] = 0;
	} 
	else 
	{ // Must be modifying an existing item

        if (get_post('NewProjectID') != get_post('est_project_id') || get_post('addupdate')) { 
            // first item display
            
                        $_POST['NewProjectID'] = $_POST['est_project_id'];
			$myrow = get_est_project_details($_POST['NewProjectID']);
                        
			$_POST['code'] = $myrow["code"];
                        $_POST['project_name'] = $myrow["project_name"];
                        $_POST['long_description'] = $myrow["long_description"];
			$_POST['description'] = $myrow["description"];
//			$_POST['project_manager_id'] = $myrow["project_manager_id"];
                        //$_POST['frozen_date'] = sql2date($myrow['budget_freeze_date']);
                        
//			$_POST['created_on']  = sql2date($myrow["created_on"]);
//			$_POST['updated_on']  = sql2date($myrow["updated_on"]);
//			$_POST['company_category_code']  = $myrow["company_category_code"];
//                        $_POST['group_serial_no'] =  $myrow['group_serial_no'];
//                        $_POST['customer_category_code'] =  $myrow['customer_category_code'];
//			$_POST['year'] =  $myrow['year_value'];
			//$_POST['customer_category_code'] = $myrow['customer_category_code'];
//			$_POST['project_category_code'] = $myrow['project_category_code'];
//			$_POST['category_serial_no']	= $myrow['category_serial_no'];
//			$_POST['company_serial_no']	= $myrow['company_serial_no'];	
                        
                        $_POST['department_id'] = $myrow['department_id'];
//                        $_POST['purchase_to_stock'] = $myrow['purchase_to_stock'];
                        
                        $_POST['customer_id'] = $myrow['customer_id'];
			$_POST['project_manager_name']	= $myrow['project_manager_name'];
			$_POST['contact_person']	= $myrow['contact_person'];
                        
			$_POST['inactive'] = $myrow['inactive'];
                        $_POST['bid_date'] = sql2date($myrow['bid_date']);
                        $_POST['project_start_date'] = sql2date($myrow['start_date']);
                        $_POST['project_end_date'] = sql2date($myrow['end_date']);
                        $_POST['project_value'] = $myrow['project_value'];
                        $_POST['estimated_cost'] = $myrow['estimated_cost'];
                        $_POST['rate_include_taxes'] = $myrow['rate_include_taxes'];
                        $_POST['approval_project_id'] = $myrow['project_id'];
//
//                        $_POST['cost_account'] = $myrow['cost_account'];
//                        $_POST['revenue_account'] = $myrow['revenue_account'];

                        $_POST['data_access_group_id'] = $myrow['dag_id'];
                        
                        $_POST['approval_status'] = $myrow['approval_status'];
                        $_POST['approved_cost_components_total'] = $myrow['approved_cost_components_total'];
                        $_POST['approved_overhead_components_total'] = $myrow['approved_overhead_components_total'];
                        
		}
        
                        
        label_row("No:", $_POST['est_project_id']);
                
        text_row("Code", "code", null, 25, 50);
        
        text_row(_("Description:"), 'description', null, 50, 200);
        
        textarea_row(_('Long Description:'), 'long_description', null, 31, 3);
        //hidden('NewProjectID', $_POST['NewProjectID']);
        
        
//        value_list_row(_("Department:"), 'department_id', 'DEPARTMENTS', null, "Select a department");
        $department = get_listvalue_by_id($_POST['department_id']);
        label_row("Department:", $department['value_name']);
//        yesno_list_row("Purchase to Stock:", 'purchase_to_stock', null, 'Yes', 'No');
//        
        customer_list_row(_('Customer:'), 'customer_id', null,  _('Select Customer') ,false);
        
        label_row(_('Bid Opening date:'), $_POST['bid_date']);
        date_row(_('Start date:'), 'project_start_date');
        date_row(_('End date:'), 'project_end_date');
//        date_row(_('Frozen date:'), 'frozen_date');
        text_row("Project Manager Name:", "project_manager_name", null, 50, 150);
        text_row("Contact Person:", "contact_person",null, 50, 150);
        amount_row(_("Project Value:"), 'project_value');
//        amount_row(_("Estimated Project Cost:"), 'estimated_cost');
        hidden('estimated_cost', 0);
        label_row("Project Approved Cost Components Total:", number_format($_POST['approved_cost_components_total'],2));
        label_row("Project Approved Overhead Components Total:", number_format($_POST['approved_overhead_components_total'],2));
        
//        $budget_details = get_project_tasks_current_budgets_total($_POST['project_id']);
//        label_row("Department Approved All Budgets Total:", number_format($budget_details['current_budgets_total'],2));
//        label_row("Unapproved All Budgets Total:", number_format($budget_details['unapproved_budgets_total'],2));
//            
        yesno_list_row("Rate include taxes:", 'rate_include_taxes', null, 'Yes', 'No');
//        user_list_row(_("Project Manager:"), 'project_manager_id', null, false, true);
       
        

//            $fresh_item = !isset($_POST['NewProjectID']) || $new_item 
//                    || check_usage($_POST['project_id'],false);

//        value_list_row("Data Access Group:", 'data_access_group_id', 'DATA_ACCESS_GROUPS', null, 'Select a Data Access Group', false);
        
        //project_list_row(_("Approval Project:"), 'approval_project_id', null, _('Select a project'), false);
//        $approval_project = get_project_record($_POST['approval_project_id']);
//        label_row("Approval Project:", $approval_project['project_code']." - ".$approval_project['description']);
                
        global $approval_statuses;
        $s = get_project_trans_view_str(ST_APPROVAL_LOG, $_POST['est_project_id']."&source_type_id=".ST_APPROVE_EST_PROJECT, "Approval Status");
        label_row($s,$approval_statuses[$_POST['approval_status']]);
            
//        hidden('approved', $_POST['approved']);
        
        record_status_list_row(_("Status:"), 'inactive');
        
//        table_section(2);
//        table_section_title(_("Reference Structure"));
//        label_row(_("Name:"),$_POST['project_name']);
//        label_row(_("Company Code:"),$_POST['company_category_code']);
//        label_row(_("Group Serial No:"),$_POST['group_serial_no']);
//        label_row(_("Company Serial No:"),$_POST['company_serial_no']);
//        label_row(_("Year:"),$_POST['year']);
//        label_row(_("Customer Category:"),$_POST['customer_category_code']);
//        label_row(_("Project Category:"),$_POST['project_category_code']);
//        label_row(_("Category Serial No:"),$_POST['category_serial_no']);
//        
//        table_section_title(_("Accounts"));
//            gl_all_accounts_list_row(_("Revenue Account:"), 'revenue_account', $_POST['revenue_account']);
//            gl_all_accounts_list_row(_("Cost Account:"), 'cost_account', $_POST['cost_account']);
//            
        end_outer_table(1);
                set_focus('description');

	}
        
        
    div_start('controls');
    if (!isset($_POST['NewProjectID']) || $new_item) 
    {
            submit_center('addupdate', _("Insert New Project"), true, '', 'default');
    } 
    else 
    {
            submit_center_first('addupdate', _("Update Project"), '', @$_REQUEST['popup'] ? true : 'default');

//            submit_return('select', get_post('project_id'), _("Select this items and return to document entry."), 'default');
            //submit('clone', _("Clone This Item"), true, '', true);
//            submit('delete', _("Delete This Project"), true, '', true);
            submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');
            
            br();
            
            submit_center_first('Release_Project_For_Approval', "Release for Approval", '', 'default');
    }

    div_end();
}
    
//------------------------------------------------------------------------------------

if (isset($_POST['addupdate'])) 
{ 

    if(can_commit($new_item)){

        if (!$new_item) 
        { /*so its an existing one */
            $approval_required = 0;
            //$approval_required = check_project_require_approval($est_project_id);

//            $current_budgets_total = get_project_tasks_current_budgets_total($project_id);
//            $approved_budgets_total = $current_budgets_total['current_budgets_total'];
            
            begin_transaction();
            
            update_est_project($est_project_id, $_POST['code'], $_POST['description'],
                                $_POST['long_description'], $_POST['customer_id'], 
                                $_POST['project_manager_name'],
                                $_POST['contact_person'],$_POST['inactive'],
                                $_POST['project_start_date'], $_POST['project_end_date'], 
                                input_num('project_value'),input_num('estimated_cost'),
                                $_POST['rate_include_taxes']) ;

            if($approval_required){
                $project = get_est_project_record($est_project_id);
                
                $rap_msg = reopen_project($project);               
                if($rap_msg['success'] !== true){
                    cancel_transaction();
                    display_error($rap_msg["message"]);
                }
                else{
                    commit_transaction();
                    set_focus('description');
                    $Ajax->activate('description'); // in case of status change
                    display_notification(_("Project has been updated."));
                }
            }
            else{
                commit_transaction();
                set_focus('description');
                $Ajax->activate('description'); // in case of status change
                display_notification(_("Project has been updated."));
            }
        } 
        else 
        { //it is a NEW part                  
//            $myrow = get_next_number($_POST['company_category_code']);
//            $company_serial_no = $myrow["next_number"];
//            $result = get_next_number($_POST['project_category_code']);
//            $project_category_code = $result["next_number"];
//            $name = $_POST['group_serial_no']. '/' .$company_serial_no. '/' .$_POST['year']. '/' .$_POST['customer_category_code']. '/' .$_POST['project_category_code']
//                    . '/' .$project_category_code;

            $name =  $_POST['code'].'/'.$_POST['description'].'/'.$_POST['long_description'];
                    
//            begin_transaction();
//
//            $approved = 0;
//            $add_budgets = 1;
//
//            add_est_project( $_POST['code'],$_POST['description'],$_POST['inactive'],$name,$_POST['long_description'],$_POST['department_id'],
//                $_POST['contact_person'],$_POST['project_manager_name'],$_POST['customer_id'],$_POST['project_start_date'],$_POST['project_end_date'],
//                input_num('project_value'),input_num('estimated_cost'),$_POST['rate_include_taxes'],$_POST['approval_project_id'],$_POST['data_access_group_id']);
//
////            $group_serial_no = $_POST['group_serial_no']+1;
////            save_next_reference(103, $group_serial_no);    
//
////            $compny_next_number = $company_serial_no+1;
////            save_next_number($_POST['company_category_code'], $compny_next_number);
////
////            $project_next_number = $project_category_code+1;
////            save_next_number($_POST['project_category_code'], $project_next_number);
//
//            commit_transaction();

            clear_data();

            display_notification(_("A new Estimation has been added."));
                        set_focus('description');
        }
        
        $Ajax->activate('_page_body');
    }
    
}

if (get_post('clone')) {
	unset($_POST['est_project_id']);
	$est_project_id = '';
	unset($_POST['inactive']);
	set_focus('NewProjectID');
	$Ajax->activate('_page_body');
        //l('224 inside get_post ');
}

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

//function check_usage($project_id, $dispmsg=true)
//{
//	$msg = item_in_foreign_codes($project_id);
//
//	if ($msg != '')	{
//		if($dispmsg) display_error($msg);
//		return false;
//	}
//	return true;
//}
//
//if (isset($_POST['delete']) && strlen($_POST['delete']) > 1) 
//{
//    $tasks_list = get_tasks($_POST['est_project_id']);
//    $myrow = db_fetch($tasks_list);
//    if($myrow != '')
//    {
//        display_error(_("Selected project can not be deleted.It has budgets"));
//    }
//    else 
//    {
//        $est_project_id = $_POST['est_project_id'];
//        delete_est_project($est_project_id);
//
//        display_notification(_("Selected project has been deleted."));
//
//        clear_data();
//        $Ajax->activate('_page_body'); 
//    }
//	
//}


if(isset($_POST['Release_Project_For_Approval'])){
    $rpfa_msg = release_est_project_for_approval($est_project_id);
    if($rpfa_msg['success'] !== true){
        display_error($rpfa_msg['message']);
    }
    else{
        set_session_variable('approve_project_messages',$rpfa_msg['message']);
        meta_forward($_SERVER['PHP_SELF'], "Approved_id=$est_project_id");
    }
    
}
//-------------------------------------------------------------------------------------------- 

start_form(true);

if (db_has_projects()) 
{
	start_table(TABLESTYLE_NOBORDER);
	start_row();
//    project_list_cells(_("Select a project:"), 'project_id', null,
//	  _('New project'), true, check_value('show_inactive'));
        
    est_project_list_cells(_("Select an Estimation:"), 'est_project_id', null, false, true, check_value('show_inactive'));
    
	$new_item = get_post('est_project_id')=='';
        
        if(get_post('est_project_id') == -1 || get_post('est_project_id') == ''){
            $new_item = TRUE;
        }


//	check_cells(_("Show inactive:"), 'show_inactive', null, true);
	end_row();
	end_table();

	if (get_post('_show_inactive_update')) {
		$Ajax->activate('est_project_id');
		set_focus('est_project_id');
	}
}
else
{
	hidden('est_project_id', get_post('est_project_id'));
}



div_start('details');

$est_project_id = get_post('est_project_id');


if ($est_project_id == -1){
    $est_project_id = '';
}

if (!$est_project_id){
	unset($_POST['_tabs_sel']); // force settings tab for new customer
}

tabbed_content_start('tabs', array(
		'settings' => array(_('&General settings'), $est_project_id),
//		'tasks' => array(_('&Tasks'), $project_id),
//        'sites' => array(_('&Sites'), $project_id),
//        'approval_Path' => array(_('&Approval Paths'), $project_id),
//        'invoicing_items' => array(_('&Invoicing Items'), $project_id),
//        'billing_schedule' => array(_('&Project Billing Schedule'), $est_project_id),
//        'users' => array(_('&Users'), $project_id),
	));
	
	switch (get_post('_tabs_sel')) 
        {
		default:
		case 'settings':
                        project_settings($est_project_id); 
			break;
//		case 'tasks':
//			$_GET['project_id'] = $project_id;
//			$_GET['popup'] = 1;
//			include_once($path_to_root."/projects/manage/tasks.php");
//			break;
//        case 'sites':
//                $_GET['project_id'] = $project_id;
//                $_GET['popup'] = 1;
//                include_once($path_to_root."/projects/manage/project_sites.php");
//                break;
//        case 'invoicing_items':
//                $_GET['project_id'] = $project_id;
//                $_GET['popup'] = 1;
//                include_once($path_to_root."/projects/manage/project_invoicing_items.php");
//                break;
//        case 'approval_Path':
//                $_GET['project_id'] = $project_id;
//                $_GET['popup'] = 1;
//                include_once($path_to_root."/projects/manage/project_approval_path.php");
//                break;    
        case 'billing_schedule':
			$_GET['est_project_id'] = $est_project_id;
			$_GET['popup'] = 1;
			include_once($path_to_root."/estimation/manage/est_projects_billing_schedule.php");
			break;
                    
//        case 'users':
//			$_GET['project_id'] = $project_id;
//			$_GET['popup'] = 1;
//			include_once($path_to_root."/projects/manage/users.php");
//			break;
	};
br();
tabbed_content_end();

div_end();


hidden('popup', @$_REQUEST['popup']);

end_form();

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

end_page(@$_REQUEST['popup']);


?>



























































































































