<?php

    require_once '../app/model/db.class.php';

    $obj = new database();
    $obj->conectar(); $obj->consulta("set names 'utf8'");

    $bd = $obj->consulta("select database() as bdatos");
    $row = $obj->fetch_assoc($bd);


    //------ COPIA TABLA BOLETIN ---------------

    $sw="true";
    $i=1;

    while ($sw=="true"){

        $res = $obj->consulta("SELECT COUNT(*) AS cantidad FROM information_schema.tables WHERE table_schema = '".$row['bdatos']."' AND table_name = 'boletin_copia_".$i."'");

       $row1 = $obj->fetch_assoc($res);
       if ($row1['cantidad']==1){
           $i++;
       }else{

           $obj->consulta("create table boletin_copia_".$i." select * from boletin");
           $sw="false";
       }

    }

   //------ COPIA TABLA DETALLEBOLETIN ---------------

    $sw="true";
    $i=1;

    while ($sw=="true"){

        $res = $obj->consulta("SELECT COUNT(*) AS cantidad FROM information_schema.tables WHERE table_schema = '".$row['bdatos']."' AND table_name = 'detalleboletin_copia_".$i."'");

       $row1 = $obj->fetch_assoc($res);
       if ($row1['cantidad']==1){
           $i++;
       }else{

           $obj->consulta("create table detalleboletin_copia_".$i." select * from detalleboletin");
           $sw="false";
       }

    }

   //------ COPIA TABLA INDICADORES ---------------

    $sw="true";
    $i=1;

    while ($sw=="true"){

        $res = $obj->consulta("SELECT COUNT(*) AS cantidad FROM information_schema.tables WHERE table_schema = '".$row['bdatos']."' AND table_name = 'indicadores_copia_".$i."'");

       $row1 = $obj->fetch_assoc($res);
       if ($row1['cantidad']==1){
           $i++;
       }else{

           $obj->consulta("create table indicadores_copia_".$i." select * from indicadores");
           $sw="false";
       }

    }

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

     $obj->disconnect();

     echo "<script languaje='javascript'>alert('PROCESO TERMINADO')</script>";
     echo "<script languaje='javascript'>document.location.href='../menu.php';</script>";
?>
