<?php
$target = 'guia';
include("funciones/funciones_backup.php");
include("conexion/conexion.php");
include("Menu/menu_inicio.php");
include("Usuarios/mensajeros.php");
include("logos.php");
unset($_SESSION['cadena_csv']);
unset($_SESSION['nombcsv']);
$fecha_actual = date("Y-m-d");
$_SESSION['nombcsv']='ConsultaOrdenArea_' . $fecha_actual . '.csv';
$_SESSION['cadena_csv']= "ORDEN;AREA;";
$nombrepagina = "CONSULTA ORDEN - ZONA";
encabezado($target);
$user = $_SESSION['validar'];
$filas = 1;
if ($filas == 1) {

    class llamado {

        var $menuObj;

        function validar1($id_user, $id_sucursal) {
            $this->menuObj = new menu_inicio();
            $this->menuObj->menu2($id_user, $id_sucursal);
        }

    }

    $llamadoObj = new llamado();
    $llamadoObj->validar1($_GET['id_user'], $_GET['suc']);
    entrada($user, $_GET['id_user'], $_GET['suc']);
    echo"</td>";
    echo"<td width=79% background=\"imagenes/bg3.jpg\" valign=top>";
    mostrar_cabeza_trabajo($nombrepagina);

    class obtiene {

        var $userObj;

        function obtener($perfil) {
            $this->userObj = new select_zonas();
            $tabla = $this->userObj->get_tabla($_GET['suc']);
            $_SESSION['tabla_guia'] = $tabla;
        }

    }
    ?>
    <link rel="stylesheet" href="css/demos.css" media="screen" type="text/css">
    <link rel="stylesheet" href="css/modal-message.css" type="text/css">
    <script type="text/javascript" src="js/modal-message.js"></script>
    <script type="text/javascript">
        messageObj = new DHTML_modalMessage();	// We only create one object of this class
        messageObj.setShadowOffset(0);	// Large shadow
        function displayStaticMessage(messageContent, cssClass, src)
        {


            document.backup.guia.disabled = true;
            messageObj.setHtmlContent(messageContent);
            messageObj.setSize(450, 120);
            messageObj.setCssClassMessageBox(cssClass);
            messageObj.setSource(false);	// no html source since we want to use a static message here.
            messageObj.setShadowDivVisible(false);	// Disable shadow for these boxes
            messageObj.display();

        }
        function cierraMessage()
        {
            messageObj.close();
            document.backup.guia.disabled = false;
            document.backup.guia.focus();
        }


        function reproducir() {
            document.all['cancion'].src = 'sound/alert.wav'
        }

    </script>
    <script language="javascript" src="js/popcalendar.js"></script>
    <form action="" method="POST" name="backup"><CENTER>
            <table width="300" border="0" class="primaria">

                <tr class=miTable_tr>
                    <td colspan="2" class=miTable_th1><div align="center">..:: ORDEN - ZONA ::..</div></td>
                </tr>

                <tr class="miTable_tr">
                    <td width="100" class="miTable_td">
                        No ODS:
                    </td>
                    <td width="200" class="miTable_td">
                        <textarea cols="20" rows="7" name="arr_ods" id="guia"></textarea>
                    </td>
                </tr>
                <tr class=miTable_tr>
                    <td class=miTable_th1 colspan="2">
                        <div align="center">
                            <input type="submit" name="Registrar" value="Consultar" class="inputbox">
                        </div>
                    </td>
                </tr>
            </table>
            
           <table>
                    <tr class="miTable_tr">
                    <td colspan='4' class="miTable_td">
                <center>                    
                   

                </center>
                </td>
           </table>
            
            
            <?
            $db = new conexion();
            $db->conectarse();

            function titulos() {
              
                echo "<div style='overflow-x:scroll;overflow-y:scroll;width:720px;height:400px'>";
                echo "<table border='0' width='720' class='primaria'>";
                echo "<tr class=miTable_tr>";
          
      
            }

            function DibujaOds($num_ods) {
$mysqli = mysqli_connect("192.157.230.224", "web", "nd2016*", "gama");
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

   $result = mysqli_query($mysqli, "call os_zona('" . $num_ods . "')");
    
        $_SESSION['cadena_csv'] .=$num_ods.';'.trim($area).';';
           echo   '<div class="container">
                    <div class="table-responsive">   
                        <table class=""id="tabla_zona" border="1"  cellspacing="0" width="100%">
                            <thead>
                                <tr>
                                    <th>Estado<span></span></th>
<th>1</th>
<th>10</th>
<th>15</th>
<th>16</th>
<th>2</th>
<th>3</th>
<th>331</th>
<th>4</th>
<th>431</th>
<th>5</th>
<th>531</th>
<th>6</th>
<th>7</th>
<th>8</th>
<th>9</th>
<th>17</th>
<th>18</th>
<th>19</th>
<th>20<span>&nbsp</span></th>
                                </tr>
                            </thead>
                            <tbody >
                                '; 
while($value = mysqli_fetch_assoc($result))
    {
 $nombre=$value['nombre'];
$os=$value['os'];
$id_estado=$value['id_estado'];
$zona_1=$value['_1'];
$zona_10=$value['_10'];
$zona_15=$value['_15'];
$zona_16=$value['_16'];
$zona_2=$value['_2'];
$zona_3=$value['_3'];
$zona_331=$value['_331'];    
$zona_4=$value['_4'];
$zona_431=$value['_431'];
$zona_5=$value['_5'];
$zona_531=$value['_531'];
$zona_6=$value['_6'];
$zona_7=$value['_7'];
$zona_8=$value['_8'];
$zona_9=$value['_9'];
$zona_17=$value['_17'];
$zona_18=$value['_18'];
$zona_19=$value['_19'];
 $zona_20=$value['_20'];
echo '
<tr>
        <td>'.$nombre.'</td>
<td>'.$zona_1.'</td>
<td>'.$zona_10.'</td>
<td>'.$zona_15.'</td>
<td>'.$zona_16.'</td>
<td>'.$zona_2.'</td>
<td>'.$zona_3.'</td>
<td>'.$zona_331.'</td>
<td>'.$zona_4.'</td>
<td>'.$zona_431.'</td>
<td>'.$zona_5.'</td>
<td>'.$zona_531.'</td>
<td>'.$zona_6.'</td>
<td>'.$zona_7.'</td>
<td>'.$zona_8.'</td>
<td>'.$zona_9.'</td>
<td>'.$zona_17.'</td>
<td>'.$zona_18.'</td>
<td>'.$zona_19.'</td>
<td>'.$zona_20.'<span>&nbsp</span></td>

</tr>';  
}
echo '
                            </tbody>
                        </table>
                    </div>
                </div>';

              
}
            if (empty($arr_ods)) {
                if (!empty($f1) and !empty($f2)) {
                    titulos();
                    $rsEst = $db->consultar("select orden from ordenes where fecha_creacion>='" . $f1 . "' and fecha_creacion<='" . $f2 . "'");
                    while ($ret = mysql_fetch_array($rsEst)) {
                        $num_ods = $ret['orden'];
                        DibujaOds($num_ods);
                    }
                }
            } else {
                $input = explode("\n", $arr_ods);
                $arr_ods = array_unique($input);
                titulos();

                for ($ytr = 0; $ytr <= count($arr_ods); $ytr++) {
                    $num_ods = trim($arr_ods[$ytr]);
                    if (!empty($num_ods)) {
                        DibujaOds($num_ods);
                    }
                }
            }

            echo "</div>";            
            echo "</table>";
            mostrar_pie();
        }
//$pla=$_SESSION['planilla'];
        echo"</td>";
        echo"</tr>";
        echo"</table>";
        echo"<table width=503 border=0 align=center cellpadding=0 cellspacing=0>";
        echo"<tbody><tr>";
        echo"<td></td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td height=7 background=imagenes/lineas_pie.jpg><img src=index2_files/spacer.html width=1 height=15></td>";
        echo"</tr>";
        echo"<tr>";
        ?>
        <td>
        <center>
            <? pie_de_pagina(); ?>
        </center>
        </td>
        <?php
        echo"</tr>";
        echo"</tbody></table>";

        echo"</center>";
        echo"</body>";
        echo"</html>";
        ?>
    </CENTER>
</form>
<script>function copiarAlPortapapeles(tableId) {
  var textRange = document.body.createTextRange(); 
    textRange.moveToElementText(document.getElementById(tableId)); 
    textRange.execCommand("Copy");
}</script>
