1 | <?php |
---|
2 | /*================================================================================================== |
---|
3 | Clase para trabajar con menús contextuales. |
---|
4 | |
---|
5 | Especificaciones de las etiquetas XML: |
---|
6 | - MENUCONTEXTUAL: Elemento raiz en el se especifican los atributos del <DIV> |
---|
7 | - ITEM: Especificaciones de cada item. |
---|
8 | - SEPARADOR: Indica una linea divisoria entre items |
---|
9 | |
---|
10 | Especificaciones de atributos: |
---|
11 | - idctx: Identificador del menu contextual (DIV) |
---|
12 | - imgitem: La url de la imagen que acompañará al literal |
---|
13 | - alignitem: La alineación del texto del item (por defecto left) |
---|
14 | - textoitem: El literal del item |
---|
15 | - subflotante: Si el item despliega otro menu contextual. El valor es el id de ése |
---|
16 | - maxanchu: Máxima anchura del menu contextual |
---|
17 | - swimg: Vale 1 si el menu tiene algún item con imagen y 0 en caso contrario |
---|
18 | - alpulsar: Nombre de la función javascript que se ejecutará en respuesta al evento onclick |
---|
19 | - clase: Estilo CSS que tendrán los item menu contextual |
---|
20 | - origen_x: Posición de origen, coordenada x |
---|
21 | - origen_y: Posición de origen, coordenada y |
---|
22 | |
---|
23 | |
---|
24 | Especificaciones de eventos: |
---|
25 | - Los eventos onmouseover y onmouseout están implicitos en la clase por defecto |
---|
26 | Especificaciones de submenus: |
---|
27 | - Si una opción lleva un submenu asociado el id de éste va en el atributo name del <TR> |
---|
28 | |
---|
29 | |
---|
30 | ==================================================================================================*/ |
---|
31 | class MenuContextual{ |
---|
32 | Function __construct($urlImages="../images/flotantes"){ |
---|
33 | $this->urlImg=$urlImages; |
---|
34 | } |
---|
35 | /*--------------------------------------------------------------------------------------------- |
---|
36 | Devuelve una cadena en formato HTML de un layer para usarlo como menu contextual |
---|
37 | Parametros: |
---|
38 | - cadenaXML: Una cadena en formato XML con los atributos de cada item |
---|
39 | ---------------------------------------------------------------------------------------------*/ |
---|
40 | function CreaMenuContextual($cadenaXML){ |
---|
41 | $idx=0; |
---|
42 | $layer=""; |
---|
43 | $idctx=""; |
---|
44 | $maxanchu=100; |
---|
45 | $swimg=0; |
---|
46 | $imgitem=""; |
---|
47 | $alignitem=""; |
---|
48 | $textoitem=""; |
---|
49 | $clase=""; |
---|
50 | $subflotante=""; |
---|
51 | $origen_x="0"; |
---|
52 | $origen_y="0"; |
---|
53 | |
---|
54 | $gXML=new XmlPhp($cadenaXML,0); |
---|
55 | $gXML->NodoRaiz(); |
---|
56 | $atributosHTML=$gXML->Atributos(); |
---|
57 | $atributosHTML=$gXML->TomaAtributoEspecial("maxanchu",$maxanchu,$atributosHTML); |
---|
58 | $atributosHTML=$gXML->TomaAtributoEspecial("swimg",$swimg,$atributosHTML); |
---|
59 | $atributosHTML=$gXML->TomaAtributoEspecial("clase",$clase,$atributosHTML); |
---|
60 | $atributosHTML=$gXML->TomaAtributoEspecial("idctx",$idctx,$atributosHTML); |
---|
61 | $atributosHTML=$gXML->TomaAtributoEspecial("origen_x",$origen_x,$atributosHTML); |
---|
62 | $atributosHTML=$gXML->TomaAtributoEspecial("origen_y",$origen_y,$atributosHTML); |
---|
63 | if(empty($origen_x)) $origen_x=0; |
---|
64 | if(empty($origen_y)) $origen_y=0; |
---|
65 | if (!$clase) $clase="menu_contextual"; |
---|
66 | $layer.='<DIV class="'.$clase.'" id="'.$idctx.'" width='.$maxanchu.' style="visibility:hidden;position:absolute;top:'.$origen_y.';left:'.$origen_x.'" >'; |
---|
67 | $nuitems=2; |
---|
68 | if ($gXML->PrimerNodoHijo()){ |
---|
69 | $layer.='<TABLE border=0 width='.$maxanchu.' border=0 cellspacing=0 cellpadding=0>'; |
---|
70 | $layer.='<TR width='.$maxanchu.' height=3>'; // Primera linea |
---|
71 | $layer.='<TD width=3 background="'.$this->urlImg.'/esi.gif"></TD>'; |
---|
72 | $layer.='<TD colspan=6 background="'.$this->urlImg.'/lsu.gif"></TD>'; |
---|
73 | $layer.='<TD width=3 background="'.$this->urlImg.'/esd.gif"></TD>'; |
---|
74 | $layer.='</TR>'; |
---|
75 | |
---|
76 | $layer.='<TR width='.$maxanchu.' height=3>'; // Linea de relleno |
---|
77 | $layer.='<TD width=3 background="'.$this->urlImg.'/liz.gif"></TD>'; |
---|
78 | $layer.='<TD width=3></TD>'; |
---|
79 | $layer.='<TD colspan=4></TD>'; |
---|
80 | $layer.='<TD width=3></TD>'; |
---|
81 | $layer.='<TD width=3 background="'.$this->urlImg.'/ldr.gif"></TD>'; |
---|
82 | $layer.='</TR>'; |
---|
83 | do{ |
---|
84 | $nuitems++; |
---|
85 | $atributosHTML=$gXML->Atributos(); |
---|
86 | $tiponodo=$gXML->NombreNodo(); |
---|
87 | if ($tiponodo=="ITEM"){ |
---|
88 | $atributosHTML=$gXML->TomaAtributoEspecial("imgitem",$imgitem,$atributosHTML); |
---|
89 | $atributosHTML=$gXML->TomaAtributoEspecial("textoitem",$textoitem,$atributosHTML); |
---|
90 | $atributosHTML=$gXML->TomaAtributoEspecial("subflotante",$subflotante,$atributosHTML); |
---|
91 | $atributosHTML=$gXML->TomaAtributoEspecial("alpulsar",$alpulsar,$atributosHTML); |
---|
92 | $atributosHTML=$gXML->TomaAtributoEspecial("alignitem",$alignitem,$atributosHTML); |
---|
93 | |
---|
94 | if ($alignitem==null) $alignitem="left"; |
---|
95 | |
---|
96 | $clickcontextual=' onclick="'.$alpulsar.'" '; |
---|
97 | $oncontextual=' onmouseover="sobre_contextual(this)" '; |
---|
98 | $offcontextual=""; |
---|
99 | |
---|
100 | $idx++; |
---|
101 | $layer.='<TR id='.$idx.' name="'.$subflotante.'" width='.$maxanchu.' '.$clickcontextual.' '.$oncontextual.' '.$offcontextual.' height=20>'; // Linea de item |
---|
102 | $layer.='<TD width=3 background="'.$this->urlImg.'/liz.gif"></TD>'; |
---|
103 | $layer.='<TD width=3></TD>'; |
---|
104 | |
---|
105 | if ($imgitem!=null){ // Item con imagen |
---|
106 | $imgonclick=""; |
---|
107 | $layer.='<TD width=20 align=center id="TDimg-'.$idx .'"><IMG width=16 src="'.$imgitem.'"></TD>'; |
---|
108 | $layer.='<TD width=3></TD>'; |
---|
109 | $layer.='<TD align='.$alignitem.' id="TDLit-'.$idx .'" width='.($maxanchu-38).' '.$atributosHTML.'><A href="javascript:void(0)" style="text-decoration: none"><SPAN>'.$textoitem.'</SPAN></A></TD>'; |
---|
110 | } |
---|
111 | else{ |
---|
112 | if ($swimg==1){ // Hay algún item con imagen |
---|
113 | $layer.='<TD width=20></TD>'; |
---|
114 | $layer.='<TD width=3></TD>'; |
---|
115 | $layer.='<TD align='.$alignitem.' width='.($maxanchu-38).' '.$atributosHTML.'><A href="#" style="text-decoration: none"><SPAN>'.$textoitem.'</SPAN></A></TD>'; |
---|
116 | } |
---|
117 | else{ |
---|
118 | $layer.='<TD width=10></TD>'; |
---|
119 | $layer.='<TD colspan=2 align='.$alignitem.' width='.($maxanchu-25).' ' .$atributosHTML.' ><A href="#" style="text-decoration: none"><SPAN>'.$textoitem.'</SPAN></A></TD>'; |
---|
120 | } |
---|
121 | } |
---|
122 | if ($subflotante!=null) |
---|
123 | $layer.='<TD valign=middle><IMG width=3 name="swsbfn" align=left src="'.$this->urlImg.'/swsbfn.gif">'; |
---|
124 | else |
---|
125 | $layer.='<TD width=3 >'; |
---|
126 | $layer.='</TD>'; |
---|
127 | $layer.='<TD width=3></TD>'; |
---|
128 | $layer.='<TD width=3 background="'.$this->urlImg.'/ldr.gif"></TD>'; |
---|
129 | $layer.='</TR>'; |
---|
130 | } |
---|
131 | if ($tiponodo=="SEPARADOR"){ // Separadores |
---|
132 | $layer.='<TR width='.$maxanchu.' height=16>'; // Linea de separación |
---|
133 | $layer.='<TD width=3 background="'.$this->urlImg.'/liz.gif"></TD>'; |
---|
134 | $layer.='<TD width=3></TD>'; |
---|
135 | $layer.='<TD colspan=4 background="'.$this->urlImg.'/sep.gif"></TD>'; |
---|
136 | $layer.='<TD width=3></TD>'; |
---|
137 | $layer.='<TD width=3 background="'.$this->urlImg.'/ldr.gif"></TD>'; |
---|
138 | $layer.='</TR>'; |
---|
139 | } |
---|
140 | |
---|
141 | }while($gXML->SiguienteNodoHermano()); |
---|
142 | |
---|
143 | $layer.='<TR width='.$maxanchu.' height=3>'; // Linea de relleno |
---|
144 | $layer.='<TD width=3 background="'.$this->urlImg.'/liz.gif"></TD>'; |
---|
145 | $layer.='<TD width=3></TD>'; |
---|
146 | $layer.='<TD colspan=4></TD>'; |
---|
147 | $layer.='<TD width=3></TD>'; |
---|
148 | $layer.='<TD width=3 background="'.$this->urlImg.'/ldr.gif"></TD>'; |
---|
149 | $layer.='</TR>'; |
---|
150 | |
---|
151 | |
---|
152 | $layer.='<TR width='.$maxanchu.' height=3>'; // Última linea |
---|
153 | $layer.='<TD width=3 background="'.$this->urlImg.'/eii.gif"></TD>'; |
---|
154 | $layer.='<TD colspan=6 background="'.$this->urlImg.'/lin.gif"></TD>'; |
---|
155 | $layer.='<TD width=3 background="'.$this->urlImg.'/eid.gif"></TD>'; |
---|
156 | $layer.='</TR>'; |
---|
157 | $layer.='</TABLE>'; |
---|
158 | $layer.='<INPUT type=hidden value="-1">'; // Representará el índice seleccionado |
---|
159 | $layer.='</DIV>'; |
---|
160 | } |
---|
161 | return($layer); |
---|
162 | } |
---|
163 | } |
---|