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

//include_once($path_to_root . "/includes/ui/ui_lists.inc");
//
//$_search_button = "<input %s type='submit' class='combo_submit' style='border:0;background:url($path_to_root/themes/"
//	."%s/images/locate.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Set filter")."'> ";
//
//$_select_button = "<input %s type='submit' class='combo_select' style='border:0;background:url($path_to_root/themes/"
//	."%s/images/button_ok.png) no-repeat;%s' aspect='fallback' name='%s' value=' ' title='"._("Select")."'> ";
//
//$all_items = ALL_TEXT;


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

function group_companies_list($name, $selected_id=null, $all_option = false, $submit_on_change=false)
{

	$sql = "SELECT company_code, CONCAT(company_code, ' - ', company_name) company_name 
            FROM group_companies ";
    
	return combo_input($name, $selected_id, $sql, 'company_code', 'company_name', 
	array(
		'spec_option' => $all_option === true ? _("") : $all_option,
                'select_submit'=> $submit_on_change,
                'async' => false,
                'spec_id' => ALL_TEXT,
                'order' => array('default_company DESC') 
	) );
}

function group_companies_list_cells($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td>$label</td>\n";
	echo "<td>";
	echo group_companies_list($name, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function group_companies_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	group_companies_list_cells(null, $name, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}
//----------------------------------------------------------------------------------------------




function group_company_employees_simple_list($name, $company_code, $selected_id=null, $all_option = false, $submit_on_change=false)
{
    $group_company_db = get_group_company_db_name($company_code);

	$sql = "SELECT employee_code, 
                    CONCAT(employee_code, ' - ', initials, ' ', last_name) name 
            FROM ".$group_company_db.".".TB_PREF."employee_master ";
    
	return combo_input($name, $selected_id, $sql, 'employee_code', 'name', 
	array(
		'spec_option' => $all_option === true ? _("") : $all_option,
                'spec_id' => ALL_TEXT,
                'select_submit'=> $submit_on_change 
	) );
}

function group_company_employees_simple_list_cells($label, $name, $company_code, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td>$label</td>\n";
	echo "<td>";
	echo group_company_employees_simple_list($name, $company_code, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function group_company_employees_simple_list_row($label, $name, $company_code, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	group_company_employees_simple_list_cells(null, $name, $company_code, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}


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




function group_company_employee_ids_simple_list($name, $company_code, $selected_id=null, $all_option = false, $submit_on_change=false)
{
    $group_company_db = get_group_company_db_name($company_code);

	$sql = "SELECT employee_id, CONCAT(employee_code, ' - ', initials, ' ', last_name) name ";
        
        if(strlen($company_code) > 0){
            $sql .= " FROM ".$group_company_db.".".TB_PREF."employee_master ";
        }
        else{
            $sql .= " FROM ".TB_PREF."employee_master WHERE employee_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxx' ";
        }
    
	return combo_input($name, $selected_id, $sql, 'employee_id', 'name', 
	array(
		'spec_option' => $all_option === true ? _("") : $all_option,
                'spec_id' => ALL_TEXT,
                'select_submit'=> $submit_on_change 
	) );
}

function group_company_employee_ids_simple_list_cells($label, $name, $company_code, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	if ($label != null)
		echo "<td>$label</td>\n";
	echo "<td>";
	echo group_company_employee_ids_simple_list($name, $company_code, $selected_id, $all_option, $submit_on_change);
	echo "</td>\n";
}

function group_company_employee_ids_simple_list_row($label, $name, $company_code, $selected_id=null, $all_option = false, $submit_on_change=false)
{
	echo "<tr><td class='label'>$label</td>";
	group_company_employee_ids_simple_list_cells(null, $name, $company_code, $selected_id, $all_option, $submit_on_change);
	echo "</tr>\n";
}
//----------------------------------------------------------------------------------------------