Announcement

Collapse
No announcement yet.

Handsontable array variable import, export

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Handsontable array variable import, export

    Hello

    I'm trying to manage Handsontable to import easy "only for the user" some data from excel. Already manage to visualize some data from a table, but I no find any solution to retrieve the JavaScript variable (only one array) to make SC manipulating the array and insert the data in the table, I know its more simple other options but I don't what manage the security of the insert. I want put a button to export the array to SC and return to the previews page
    This is the code of the Blank application
    [CODE]$prueba_sql = "SELECT *
    FROM sec_groups_apps
    LIMIT 10";
    sc_lookup(prueba, $prueba_sql);
    $contador = count({prueba});
    $test = 0;
    while($test < $contador){
    $uno = {prueba[$test][0]};
    $dos = {prueba[$test][1]};
    $tre = {prueba[$test][2]};
    $for = {prueba[$test][3]};
    $five = {prueba[$test][4]};
    $six = {prueba[$test][5]};
    $seven = {prueba[$test][6]};
    $cadena_array[] = "['$uno', '$dos', '$tre', '$for', '$five', '$six', '$seven']";
    $test++;
    }
    $cadena = "[".implode(', ', $cadena_array)."]";

    $jquerry_path = $this->Ini->path_prod;
    //echo "esta es la cadena <br> $cadena";
    $direccion_pagina = $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];


    //aqui se coloca todo lo que se quiere para que muestre la pagina
    [COLOR="#3333FF"]echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">

    <head>
    <title>sin título</title>
    <meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />
    <meta name=\"generator\" content=\"Geany 1.24\" />

    <!--
    Loading Handsontable (full distribution that includes all dependencies apart from jQuery)
    -->
    <script data-jsfiddle=\"common\" src=\"$jquerry_path/dist/handsontable.full.js\"></script>
    <link data-jsfiddle=\"common\" rel=\"stylesheet\" media=\"screen\" href=\"$jquerry_path/dist/handsontable.full.css\">

    <script type=\"text/javascript\" src=\"$jquerry_path/third/jquery/js/jquery.js\"></script>
    <script type=\"text/javascript\">
    $(document).ready(function(){

    $(\".accordion h3:first\").addClass(\"active\");
    $(\".accordion p:not(:first)\").hide();

    $(\".accordion h3\").click(function(){
    $(this).next(\"p\").slideToggle(\"slow\")
    .siblings(\"p:visible\").slideUp(\"slow\");
    $(this).toggleClass(\"active\");
    $(this).siblings(\"h3\").removeClass(\"active\");
    });

    });
    </script>

    <script>
    $(document).ready(function(){
    $(\"button\").click(function(){
    $.ajax(
    {
    url: \"$direccion_pagina\",
    dataType: 'json',
    type: 'POST',
    data: {matriz: miContenedor.misDatos},
    success: function ()
    {}
    });
    });
    </script>



    </head>

    <body>%3
    Last edited by GhoulRul; 03-31-2015, 04:12 PM. Reason: solved

  • #2
    Solved partial

    I solved this, this need tow app_blank, one whit the page and other for processing the results,
    the table is this
    Code:
    CREATE TABLE `prueba2` (
    	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    	`id_req` INT(11) NULL DEFAULT '1',
    	`uno` MEDIUMTEXT NULL,
    	`dos` MEDIUMTEXT NULL,
    	`tres` MEDIUMTEXT NULL,
    	`four` MEDIUMTEXT NULL,
    	`five` MEDIUMTEXT NULL,
    	`six` MEDIUMTEXT NULL,
    	`seven` MEDIUMTEXT NULL,
    	PRIMARY KEY (`id`),
    	INDEX `id_req` (`id_req`)
    )
    COMMENT='para probar insertar datos desde la tabla de javascript'
    COLLATE='utf8_general_ci'
    ENGINE=InnoDB
    The page app_blank is this
    Code:
    $REQUI = 2;
    $prueba_sql = "SELECT 
    		uno, 
    		dos, 
    		tres, 
    		four, 
    		five, 
    		six, 
    		seven 
    	FROM prueba2
    	WHERE uno = $REQUI
    	ORDER BY nombre DESC
    	LIMIT 10";
    sc_lookup(prueba, $prueba_sql);
    $contador = count({prueba});
    $test = 0;
    while($test < $contador){
    	$uno = {prueba[$test][0]};
    	$dos = {prueba[$test][1]};
    	$tre = {prueba[$test][2]};
    	$for = {prueba[$test][3]};
    	$five = {prueba[$test][4]};
    	$six = {prueba[$test][5]};
    	$seven = {prueba[$test][6]};
    	$cadena_array[] = "['$uno', '$dos', '$tre', '$for', '$five', '$six', '$seven']";
    	$test++;
    }
    $cadena = "[".implode(', ', $cadena_array)."]";
    sc_set_global($cadena);
    $jquerry_path = $this->Ini->path_prod;
    //echo "esta es la cadena <br> $cadena";
    $direccion_pagina = $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
    //echo "$direccion_pagina <br>";
    $direccion_pagina = $_SERVER['HTTP_HOST']."/scriptcase/app/WHERE/procesar_blank1/index.php";
    //echo "$direccion_pagina <br>";
    //aqui se coloca todo lo que se quiere para que muestre la pagina
    echo "<!DOCTYPE html>
    <html>
    <head>
    <script data-jsfiddle=\"common\" src=\"$jquerry_path/dist/handsontable.full.js\"></script>
      <link data-jsfiddle=\"common\" rel=\"stylesheet\" media=\"screen\" href=\"$jquerry_path/dist/handsontable.full.css\">
    
    <script>
    function loadXMLDoc()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");
      }
    
    
    var hola = JSON.stringify(misDatos);
    xmlhttp.open(\"POST\",\"/scriptcase/app/WHERE/procesar_blank1/index.php\",true);
    xmlhttp.setRequestHeader(\"Content-type\",\"application/x-www-form-urlencoded\");
    xmlhttp.send(\"Matriz=\"+ hola +\"&requId=".$REQUI."\");
    }
    </script>
    
    
    </head>
    
    
    <body>
    
    <CENTER><h2>GRID AUTOMATCA</h2>
    <button type=\"button\" onclick=\"loadXMLDoc()\">SALVAR</button></CENTER>
    <div id=\"myDiv\"></div><br>
    
    
     <div id=\"miHandsontable\"></div>
    <div id=\"rulo\"><div>
    <script>
    var misDatos = ".$cadena."
    var miContenedor = document.getElementById(\"miHandsontable\")
    	var miHandsontable = new Handsontable(miContenedor, {
    data: misDatos,
    startRows: 8,
    startCols: 7,
    rowHeaders: true,
    colHeaders: ['Cantidad Solicitada', 'Codigo', 'Descripcion', 'Largo(Flauta)', 'Ancho', 'OT', 'Pieza'],
    columns: [
    {},
    {},
    {},
    {},
    {},
    {},
    {}
    ],
    minSpareRows: 1 // Una fila en blanco
    
    });
    </script>
    </body>
    </html>
    ";
    The app_blank to processes
    Code:
    $sql_insert_prueba = "INSERT INTO prueba (nombre, apellidos) VALUE ('$nombre', '$apellido')";
    sc_exec_sql($sql_insert_prueba);
    $requi = $_POST["requId"];
    if (isset($_POST["Matriz"])){
    	$array_cadena = $_POST["Matriz"];
    	$array_matriz = preg_split('/(([^\[][*][^\]]))/', $array_cadena);
    	$array_matriz = json_decode($array_cadena);
    	
    	$j = count($array_matriz)-1;
    	for($i = 0; $i < $j; $i++){
    		$uno = $array_matriz[$i][0];
    		$dos = $array_matriz[$i][1];
    		$tres = $array_matriz[$i][2];
    		$four = $array_matriz[$i][3];
    		$five = $array_matriz[$i][4];
    		$six = $array_matriz[$i][5];
    		$seven = $array_matriz[$i][6];		
    		//se debe colocar una forma de prueba para evitar ingresar filas vacias
    		$array_para[] = "($requi, '$uno', '$dos', '$tres', '$four', '$five', '$six', '$seven')";
    		}
    	$array_cadena = implode(',', $array_para);
    	
    }else{
    	$array_cadena = "(1, 'HOLA', 'HOLA', 'HOLA', 'HOLA', 'HOLA', 'HOLA', 'HOLA')";
    }
    
    $sql_insert_prueba2 = "INSERT INTO prueba2 (id_req, uno, dos, tres, four, five, six, seven) 
    	VALUE $array_cadena";
    sc_exec_sql($sql_insert_prueba2);
    It still some work to do, but this retrieve information of the cells and put in to a table.
    this the page of the grid excel like
    http://handsontable.com/

    hansom.png
    How to close the app_blank_page and return to previews app
    Last edited by GhoulRul; 03-04-2015, 08:39 PM.

    Comment


    • #3
      If link the blank as modal then try to add this line as last line in ur blank app:

      echo "<script>parent.window.tb_remove();</script>";

      Otherwise
      echo "<script>window.close();</script>";
      __________________
      S. M. Rajibul Huda
      CEO & Founder
      www.efficienterp.com

      Comment

      Working...
      X