<?php

/**
* getLookupMainTableSettings - tests whether the lookup link exists between the tables
*
*  returns array with ProjectSettings class for main table if the link exists in project settings.
*  returns NULL otherwise
*/
function getLookupMainTableSettings($lookupTable, $mainTableShortName, $mainField, $desiredPage = "")
{
	global $lookupTableLinks;
	if(!isset($lookupTableLinks[$lookupTable]))
		return null;
	if(!isset($lookupTableLinks[$lookupTable][$mainTableShortName.".".$mainField]))
		return null;
	$arr = &$lookupTableLinks[$lookupTable][$mainTableShortName.".".$mainField];
	$effectivePage = $desiredPage;
	if(!isset($arr[$effectivePage]))
	{
		$effectivePage = PAGE_EDIT;
		if(!isset($arr[$effectivePage]))
		{
			if($desiredPage == "" && 0 < count($arr))
			{
				$effectivePage = $arr[0];
			}
			else
				return null;
		}
	}
	return new ProjectSettings($arr[$effectivePage]["table"], $effectivePage);
}

/** 
* $lookupTableLinks array stores all lookup links between tables in the project
*/
function InitLookupLinks()
{
	global $lookupTableLinks;

	$lookupTableLinks = array();

		if( !isset( $lookupTableLinks["cat_paises"] ) ) {
			$lookupTableLinks["cat_paises"] = array();
		}
		if( !isset( $lookupTableLinks["cat_paises"]["cat_entidad.pais"] )) {
			$lookupTableLinks["cat_paises"]["cat_entidad.pais"] = array();
		}
		$lookupTableLinks["cat_paises"]["cat_entidad.pais"]["edit"] = array("table" => "cat_entidad", "field" => "pais", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_municipio"] ) ) {
			$lookupTableLinks["cat_municipio"] = array();
		}
		if( !isset( $lookupTableLinks["cat_municipio"]["cat_municipio.municipio"] )) {
			$lookupTableLinks["cat_municipio"]["cat_municipio.municipio"] = array();
		}
		$lookupTableLinks["cat_municipio"]["cat_municipio.municipio"]["edit"] = array("table" => "cat_municipio", "field" => "municipio", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_entidad"] ) ) {
			$lookupTableLinks["cat_entidad"] = array();
		}
		if( !isset( $lookupTableLinks["cat_entidad"]["cat_municipio.entidad"] )) {
			$lookupTableLinks["cat_entidad"]["cat_municipio.entidad"] = array();
		}
		$lookupTableLinks["cat_entidad"]["cat_municipio.entidad"]["edit"] = array("table" => "cat_municipio", "field" => "entidad", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_niveldependencia"] ) ) {
			$lookupTableLinks["cat_niveldependencia"] = array();
		}
		if( !isset( $lookupTableLinks["cat_niveldependencia"]["dependencias.nivel"] )) {
			$lookupTableLinks["cat_niveldependencia"]["dependencias.nivel"] = array();
		}
		$lookupTableLinks["cat_niveldependencia"]["dependencias.nivel"]["edit"] = array("table" => "dependencias", "field" => "nivel", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_paises"] ) ) {
			$lookupTableLinks["cat_paises"] = array();
		}
		if( !isset( $lookupTableLinks["cat_paises"]["dependencias.pais"] )) {
			$lookupTableLinks["cat_paises"]["dependencias.pais"] = array();
		}
		$lookupTableLinks["cat_paises"]["dependencias.pais"]["edit"] = array("table" => "dependencias", "field" => "pais", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_entidad"] ) ) {
			$lookupTableLinks["cat_entidad"] = array();
		}
		if( !isset( $lookupTableLinks["cat_entidad"]["dependencias.entidad"] )) {
			$lookupTableLinks["cat_entidad"]["dependencias.entidad"] = array();
		}
		$lookupTableLinks["cat_entidad"]["dependencias.entidad"]["edit"] = array("table" => "dependencias", "field" => "entidad", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_municipio"] ) ) {
			$lookupTableLinks["cat_municipio"] = array();
		}
		if( !isset( $lookupTableLinks["cat_municipio"]["dependencias.municipio"] )) {
			$lookupTableLinks["cat_municipio"]["dependencias.municipio"] = array();
		}
		$lookupTableLinks["cat_municipio"]["dependencias.municipio"]["edit"] = array("table" => "dependencias", "field" => "municipio", "page" => "edit");
		if( !isset( $lookupTableLinks["persona"] ) ) {
			$lookupTableLinks["persona"] = array();
		}
		if( !isset( $lookupTableLinks["persona"]["pers_contactodep.id_persona"] )) {
			$lookupTableLinks["persona"]["pers_contactodep.id_persona"] = array();
		}
		$lookupTableLinks["persona"]["pers_contactodep.id_persona"]["edit"] = array("table" => "pers_contactodep", "field" => "id_persona", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_oficinas"] ) ) {
			$lookupTableLinks["cat_oficinas"] = array();
		}
		if( !isset( $lookupTableLinks["cat_oficinas"]["pers_contactodep.id_oficina"] )) {
			$lookupTableLinks["cat_oficinas"]["pers_contactodep.id_oficina"] = array();
		}
		$lookupTableLinks["cat_oficinas"]["pers_contactodep.id_oficina"]["edit"] = array("table" => "pers_contactodep", "field" => "id_oficina", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_titulosprofesionales"] ) ) {
			$lookupTableLinks["cat_titulosprofesionales"] = array();
		}
		if( !isset( $lookupTableLinks["cat_titulosprofesionales"]["persona.titulo"] )) {
			$lookupTableLinks["cat_titulosprofesionales"]["persona.titulo"] = array();
		}
		$lookupTableLinks["cat_titulosprofesionales"]["persona.titulo"]["edit"] = array("table" => "persona", "field" => "titulo", "page" => "edit");
		if( !isset( $lookupTableLinks["dependencias"] ) ) {
			$lookupTableLinks["dependencias"] = array();
		}
		if( !isset( $lookupTableLinks["dependencias"]["persona.dependencia"] )) {
			$lookupTableLinks["dependencias"]["persona.dependencia"] = array();
		}
		$lookupTableLinks["dependencias"]["persona.dependencia"]["edit"] = array("table" => "persona", "field" => "dependencia", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_cargospublicos"] ) ) {
			$lookupTableLinks["cat_cargospublicos"] = array();
		}
		if( !isset( $lookupTableLinks["cat_cargospublicos"]["persona.cargo_publico"] )) {
			$lookupTableLinks["cat_cargospublicos"]["persona.cargo_publico"] = array();
		}
		$lookupTableLinks["cat_cargospublicos"]["persona.cargo_publico"]["edit"] = array("table" => "persona", "field" => "cargo_publico", "page" => "edit");
		if( !isset( $lookupTableLinks["persona"] ) ) {
			$lookupTableLinks["persona"] = array();
		}
		if( !isset( $lookupTableLinks["persona"]["reg_contacto.persona_id"] )) {
			$lookupTableLinks["persona"]["reg_contacto.persona_id"] = array();
		}
		$lookupTableLinks["persona"]["reg_contacto.persona_id"]["edit"] = array("table" => "reg_contacto", "field" => "persona_id", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_municipio"] ) ) {
			$lookupTableLinks["cat_municipio"] = array();
		}
		if( !isset( $lookupTableLinks["cat_municipio"]["reg_contacto.municipio"] )) {
			$lookupTableLinks["cat_municipio"]["reg_contacto.municipio"] = array();
		}
		$lookupTableLinks["cat_municipio"]["reg_contacto.municipio"]["edit"] = array("table" => "reg_contacto", "field" => "municipio", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_entidad"] ) ) {
			$lookupTableLinks["cat_entidad"] = array();
		}
		if( !isset( $lookupTableLinks["cat_entidad"]["reg_contacto.entidad"] )) {
			$lookupTableLinks["cat_entidad"]["reg_contacto.entidad"] = array();
		}
		$lookupTableLinks["cat_entidad"]["reg_contacto.entidad"]["edit"] = array("table" => "reg_contacto", "field" => "entidad", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_paises"] ) ) {
			$lookupTableLinks["cat_paises"] = array();
		}
		if( !isset( $lookupTableLinks["cat_paises"]["reg_contacto.pais"] )) {
			$lookupTableLinks["cat_paises"]["reg_contacto.pais"] = array();
		}
		$lookupTableLinks["cat_paises"]["reg_contacto.pais"]["edit"] = array("table" => "reg_contacto", "field" => "pais", "page" => "edit");
		if( !isset( $lookupTableLinks["dependencias"] ) ) {
			$lookupTableLinks["dependencias"] = array();
		}
		if( !isset( $lookupTableLinks["dependencias"]["cat_oficinas.dependencia"] )) {
			$lookupTableLinks["dependencias"]["cat_oficinas.dependencia"] = array();
		}
		$lookupTableLinks["dependencias"]["cat_oficinas.dependencia"]["edit"] = array("table" => "cat_oficinas", "field" => "dependencia", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_municipio"] ) ) {
			$lookupTableLinks["cat_municipio"] = array();
		}
		if( !isset( $lookupTableLinks["cat_municipio"]["cat_oficinas.municipio"] )) {
			$lookupTableLinks["cat_municipio"]["cat_oficinas.municipio"] = array();
		}
		$lookupTableLinks["cat_municipio"]["cat_oficinas.municipio"]["edit"] = array("table" => "cat_oficinas", "field" => "municipio", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_entidad"] ) ) {
			$lookupTableLinks["cat_entidad"] = array();
		}
		if( !isset( $lookupTableLinks["cat_entidad"]["cat_oficinas.entidad"] )) {
			$lookupTableLinks["cat_entidad"]["cat_oficinas.entidad"] = array();
		}
		$lookupTableLinks["cat_entidad"]["cat_oficinas.entidad"]["edit"] = array("table" => "cat_oficinas", "field" => "entidad", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_paises"] ) ) {
			$lookupTableLinks["cat_paises"] = array();
		}
		if( !isset( $lookupTableLinks["cat_paises"]["cat_oficinas.pais"] )) {
			$lookupTableLinks["cat_paises"]["cat_oficinas.pais"] = array();
		}
		$lookupTableLinks["cat_paises"]["cat_oficinas.pais"]["edit"] = array("table" => "cat_oficinas", "field" => "pais", "page" => "edit");
		if( !isset( $lookupTableLinks["omega2_uggroups"] ) ) {
			$lookupTableLinks["omega2_uggroups"] = array();
		}
		if( !isset( $lookupTableLinks["omega2_uggroups"]["admin_users.groupid"] )) {
			$lookupTableLinks["omega2_uggroups"]["admin_users.groupid"] = array();
		}
		$lookupTableLinks["omega2_uggroups"]["admin_users.groupid"]["edit"] = array("table" => "admin_users", "field" => "groupid", "page" => "edit");
		if( !isset( $lookupTableLinks["dependencias"] ) ) {
			$lookupTableLinks["dependencias"] = array();
		}
		if( !isset( $lookupTableLinks["dependencias"]["dep_ofna_pers.dep_dep_id"] )) {
			$lookupTableLinks["dependencias"]["dep_ofna_pers.dep_dep_id"] = array();
		}
		$lookupTableLinks["dependencias"]["dep_ofna_pers.dep_dep_id"]["edit"] = array("table" => "dep_ofna_pers", "field" => "dep_dep_id", "page" => "edit");
		if( !isset( $lookupTableLinks["cat_oficinas"] ) ) {
			$lookupTableLinks["cat_oficinas"] = array();
		}
		if( !isset( $lookupTableLinks["cat_oficinas"]["dep_ofna_pers.ofna_ofna_id"] )) {
			$lookupTableLinks["cat_oficinas"]["dep_ofna_pers.ofna_ofna_id"] = array();
		}
		$lookupTableLinks["cat_oficinas"]["dep_ofna_pers.ofna_ofna_id"]["edit"] = array("table" => "dep_ofna_pers", "field" => "ofna_ofna_id", "page" => "edit");
		if( !isset( $lookupTableLinks["persona"] ) ) {
			$lookupTableLinks["persona"] = array();
		}
		if( !isset( $lookupTableLinks["persona"]["dep_ofna_pers.cont_pers_id"] )) {
			$lookupTableLinks["persona"]["dep_ofna_pers.cont_pers_id"] = array();
		}
		$lookupTableLinks["persona"]["dep_ofna_pers.cont_pers_id"]["edit"] = array("table" => "dep_ofna_pers", "field" => "cont_pers_id", "page" => "edit");
}

?>