<?php 
//function encabezado(){
?>
 <script language="JavaScript">
<!--
function mensaje_demora()
{
   alert("Este proceso es demorado, Porfavor sea paciente!!!!\n\nCARPEDIEM COLMBIA");
}
function checkAll() {
for (var j = 1; j <= 14; j++) {
box = eval("document.checkboxform.c");
if (box.checked == false) box.checked = true;
   }
}
function rusure(){
        question = confirm("Esta seguro que desea eliminar")
        if (question !="0"){
                self.location = ""
       }
      }
function validarforma()
{
  var i,p,q,nm,test,num,min,max,errors='',args=validarforma.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
   test=args[i+2]; val=MM_findObj(args[i]);
    if (val)
         {
         nm=val.name;
          if ((val=val.value)!="")
          {
       if (test.indexOf('isEmail')!=-1)
           {
            p=val.indexOf('@');
        if (p<1 || p==(val.length-1))
                 errors+='- '+nm+' must contain an e-mail address.\n';
       }
            else if (test!='R')
                 {
                  num = parseFloat(val);
        if (isNaN(val))
                 errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1)
                 {
                   p=test.indexOf(':');
           min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num)
                   errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
         }
                 }
                 }
                 else if (test.charAt(0) == 'R') errors += '-> '+nm+' es Requerido.<-\n';
                 }
         }
                 if (errors)
                 alert('Hay Algunos Campos Requeridos:\n\n'+errors);
         document.MM_returnValue = (errors == '');
}
function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
 <?php
 echo"<html>";
  echo"<html onMouseOver=\"self.status='Powered by Carpediem Colombia Ltda'; return true\">";
   echo"<head>";
    echo"<title>.::WebSim Gama::. </title>";
	echo"<meta name=\"author\" content='DESARROLLO WEB'>";
	echo"<link rel='stylesheet' href='css/style.css' type=\"text/css\">";
	echo"<link rel=\"SHORTCUT ICON\" href=imagenes/vc.png>";
   echo"</head>";
   echo"<body leftmargin=\"0\" topmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" bgcolor=\"#ffffff\">";
 //}
	include("conexion/conexion.php");
	include("Menu/menu_inicio.php");  
        include("Menu/menu.php"); 
        include("funciones/funciones_backup.php");   
	//encabezado("Modifica Menu"); 
	$id=$_GET['id'];
	$tipo=$_GET['tipo'];
	$nombre=$_GET['nombre'];
	$usertype=$_GET['usertype'];
	$pagina='ACTUALIZAR MENU';
	if($tipo==2 && !isset($Ejecutar)){
		echo "<script>
		alert('Esta Seguro Que Desea Eliminar Este Menu');
		</script>";
		$read="readonly='readonly'";
		$read2="disabled";
		$pagina='ELIMINAR MENU';
	}
?><center>
<form action="" method="POST">
<table width="300" border="0" class="primaria">
<tr class=miTable_tr>
<td colspan="2" class=miTable_th1><div align="center">..:: <? echo $pagina;?> ::..</div></td>
</td>
</tr>
<tr class=miTable_tr>
<td class="miTable_td" width="150">Nombre Menu:</td>
<td class="miTable_td" width="150"><input type="text" name="nombre" value="<? echo $nombre;?>" class="inputbox" "<? echo $read;?>" size="25">
<input type="hidden" name="id" value="<? echo $id;?>" class="inputbox" "<? echo $read;?>" size="25"></td>
</tr>
<tr class=miTable_tr>
<td class="miTable_td" width="150">Perfil:</td>
<td class="miTable_td" width="150">
<select name="usertype" class="inputbox" "<? echo $read2;?>">
<?
if($usertype==1){
echo "<option value=1>Administrador</option>";
echo "<option value=2>Consulta</option>";
}else{
echo "<option value=2>Consulta</option>";
echo "<option value=1>Administrador</option>";
}
?>
</select>
</td>
</tr>
<tr class=miTable_tr>
<td class=miTable_th1 colspan="2">
<div align="center">
<input type="submit" name="Ejecutar" value="Ejecutar" class="inputbox">
</div>
</td>
</tr>
</table>
</form>
</center>
<?
if($tipo==1 && isset($Ejecutar)){
	class actualizarMenu{
		var $consultarObj;
		var $conexionObj;
		var $estado;
		function setConsultar($id,$nombre,$usertype){
	  		$this->consultarObj=new menu();
	  		$this->consultarObj->setId($id);
			$this->consultarObj->setNombre($nombre);
			$this->consultarObj->setUsertype($usertype);
		}
		function getConsultar(){
			return $this->consultarObj;
		}
		function validar(){
			$this->conexionObj= new conexion();
			$this->conexionObj->conectarse();
			$rst_validar=$this->conexionObj->consultar("SELECT * FROM menu WHERE id='".$this->consultarObj->getId()."'");
			if(mysql_num_rows($rst_validar)>=1){
				echo $id=$this->consultarObj->getId();
				echo $nombre=$this->consultarObj->getNombre();
				echo $usertype=$this->consultarObj->getUsertype();
				$this->modificarMenu($id,$nombre,$usertype);
			}else{
				$msgBOX2 = "No Se Encontro Menu.";
				echo "<script>
				alert('$msgBOX2');
				window.close();
	  		  	</script>";
			}
	
		}
		function modificarMenu($id,$nombre,$usertype){
			$rst_modificar=$this->conexionObj->consultar("UPDATE menu SET nombre = '".$nombre."', usertype = '".$usertype."' WHERE id = ".$id."");
			$affected_modificar=mysql_affected_rows();
			if($affected_modificar>=1){
				$msgBOX2 = "Se Actualizo Menu.";
				echo "<script>
	            opener.document.location.reload();
				alert('$msgBOX2');
				window.close();
	  		  	</script>";
			}else{
				$msgBOX2 = "No Se Pudo Actualizar Menu.";
				echo "<script>
	            alert('$msgBOX2');
				window.close();
	  		  	</script>";
			}

		}
}// FIN DE LA CLASE CREARUSUARIO
// CREACION DEL OBJETO
$actualizarMenuObj=new actualizarMenu();
// CONFIGURANDO LAS PROPIEDADES DEL OBJETO
$actualizarMenuObj->setConsultar($_POST['id'],$_POST['nombre'],$_POST['usertype']);
// LAMANDO EL METODO DE NEGOCIO
$actualizarMenuObj->validar();
}elseif($tipo==2 && isset($Ejecutar)){
	class eliminarMenu{
		var $consultarObj;
		var $conexionObj;
		var $estado;
		function setConsultar($id){
			$this->consultarObj=new menu();
	  		$this->consultarObj->setId($id);
		}
		function getConsultar(){
			return $this->consultarObj;
		}
		function validar(){
			$this->conexionObj= new conexion();
			$this->conexionObj->conectarse();
			$rst_validar=$this->conexionObj->consultar("SELECT * FROM menu WHERE id='".$this->consultarObj->getId()."'");
			if(mysql_num_rows($rst_validar)>=1){
				$id=$this->consultarObj->getId();
				$this->eliminaMenu($id);
			}else{
				$msgBOX2 = "No Se Encontro Menu.";
				echo "<script>
	            alert('$msgBOX2');
				window.close();
	  		  	</script>";
			}
		}
		function eliminaMenu($id){
			$rst_modificar=$this->conexionObj->consultar("DELETE FROM menu WHERE id = ".$id."");
			$affected_modificar=mysql_affected_rows();
			if($affected_modificar>=1){
				$msgBOX2 = "Se Elimino Menu.";
				echo "<script>
	            opener.document.location.reload();
				alert('$msgBOX2');
				window.close();
	  		  	</script>";
			}else{
				$msgBOX2 = "No Se Pudo Eliminar Menu.";
				echo "<script>
	            alert('$msgBOX2');
				window.close();
	  		  	</script>";
			}
		}
}// FIN DE LA CLASE ELIMINARFUNCIONALIDAD
// CREACION DEL OBJETO
$eliminarMenuObj=new eliminarMenu();
// CONFIGURANDO LAS PROPIEDADES DEL OBJETO
$eliminarMenuObj->setConsultar($_POST['id']);
// LAMANDO EL METODO DE NEGOCIO
$eliminarMenuObj->validar();
}
	echo"<table width=300 border=0 align=center cellpadding=0 cellspacing=0>";
	echo"<tbody><tr>";
	echo"<td></td>";
	echo"</tr>";
	echo"<tr>";
?><td><CENTER>
<? pie_de_pagina();?>
</CENTER>
</td>
<?php
	echo"</tr>";
	echo"</tbody></table>";
	echo"</body>";
	echo"</html>";
?>