Store hidden data in DB

Store hidden data in DB

fedefazzfedefazz Posts: 19Questions: 6Answers: 1

Hi, i m working with Server Side Editor and PHP sessions. All works great. Now i'm trying to store in the DB the session name, i want this to store the name of the person who modifies the DB.
In my DB's table there is a fiel name "modifiBy".
My question is: How can i add the $_SESSION['user'] to Editor and send it to the table in the DB? Thanks to all.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Absolutely this can be done - using the Field->setValue() method:

    Documentation for it is available here.

    Allan

  • fedefazzfedefazz Posts: 19Questions: 6Answers: 1

    Thaks for the quick answer. Where should i place this code? In the main editor or in the dates.php?

    $editor->field(
    new Field( 'last_author' )
    ->setValue( $_SESSION['user_id'] )
    );

    Thaks

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I would suggest just adding the ->setValue() chaining method to wherever you currently define the field that you want to set the value of.

    Allan

  • fedefazzfedefazz Posts: 19Questions: 6Answers: 1

    Allan sorry i don't understand where to place the code. i post my code. I want to send the session user to de data base. But i don't want to show this field in the table or in the editor, only send it to the Data Base.

    var editor; // use a global for the submit and return data rendering in the examples
    $(document).ready(function() {

    editor = new $.fn.dataTable.Editor( {
        "ajax": "examples/php/dates.php",
        "table": "#example",
        "fields": [ {
                label: "Empresa:",
                name:  "empresa"
            },{
                 label: "Tipo de Trabajo:",
                 name:  "tipo_trabajo",
                 type:  "select",
                 options: [
                    { label: "Sistema Atomizado", value: "Sistema Atomizado" },
                    { label: "Web", value: "Web" },
                    { label: "Cuadernos", value: "Cuadernos" },
                    { label: "Pads", value: "Pads" },
                    { label: "Aviso", value: "Aviso" },
                    { label: "Imagen Corporativa", value: "Imagen Corporativa" },
                    { label: "Hosting", value: "Hosting" },
                    { label: "Otro", value: "Otro" },
    
    
                ]
            },
    
    
            {
                type:  "textarea",
                label: "Detalle del Trabajo:",
                name: "detalle_trabajo",
            }, {
                label: "Nº Fac:",
                name:  "factura"
            },
            {
                label: "Importe:",
                name: "importe",
            },
            {
                label: "Total Facturado:",
                name: "importe_total",
                type: "readonly"
            },
    
    
    
    
            {
                label: "IVA:",
                name: "IVA",
                type:  "radio",
                options: [
                 "Si",
                 "No"
    
    ]
            },
            {
                label:      "Fecha:",
                name:       "fecha_venta",
                type:       "date",
                def:        function () { return new Date(); },
                dateFormat: 'dd-mm-yy',
                options: {
                changeMonth: true,
                changeYear: true
                }
            },
            {
                 label: "Vendedor:",
                 name:  "vendedor",
                 type:  "select",
                 options: [
                    { label: "Daniel", value: "Daniel" },
                    { label: "Rocio", value: "Rocio" },
                    { label: "Natalia", value: "Natalia" },
                    { label: "Lucas", value: "Lucas" },
                    { label: "Yasmin", value: "Yasmin" }
                ]
            },
            {
                 type:  "textarea",
                 label: "Comentarios:",
                 name:  "comentarios"
            }
    
        ],
    
    i18n: {
            create: {
                button: "Nuevo",
                title:  "Nuevo Registro",
                submit: "Crear"
            },
            edit: {
                button: "Editar",
                title:  "Editar Registro",
                submit: "Actualizar"
            },
            remove: {
                button: "Eliminar",
                title:  "Eliminar",
                submit: "Eliminar",
                confirm: {
                    _: "Esta seguro que desea eliminar %d registro?",
                    1: "Esta seguro que desea eliminar 1 registros?"
                }
            },
            error: {
                system: "Un error a ocurrido contactese con el administrador"
            }
        }
    } );
    
    
    
    function multiply () {
    
    
        if(editor.field( 'IVA' ).val() == "Si"){
        editor.field( 'importe_total' ).val(editor.field( 'importe' ).val() * 1.21);
        }
        else{
        editor.field( 'importe_total' ).val(editor.field( 'importe' ).val() * 1);
        }
    

    }

    editor.field( 'importe' ).input().on( 'keyup', multiply );
    editor.field( 'IVA' ).input().on( 'click', multiply );
    // Activate the bubble editor on click of a table cell
    $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
    editor.bubble( this );
    } );

    $('#example').DataTable( {
        "columnDefs": [
    { "searchable": false, "targets": [4,0]}
    

    ],
    "footerCallback": function( thead, data, start, end, display ) {
    $(thead).find('th').eq(0).css({"background-color":"#C8ECA9"})
    },
    "footerCallback": function( tfoot, data, start, end, display ) {
    $(tfoot).find('th').eq(0).html("");
    $(tfoot).find('th').eq(1).html("");
    $(tfoot).find('th').eq(2).html("");
    $(tfoot).find('th').eq(3).html("");
    $(tfoot).find('th').eq(4).html("");
    $(tfoot).find('th').eq(5).html("");
    $(tfoot).find('th').eq(6).html("");
    $(tfoot).find('th').eq(7).html("");
    $(tfoot).find('th').eq(8).html("");
    $(tfoot).find('th').eq(9).html("");
    },

         responsive: true,
          "fnRowCallback": function( nRow, aData ) {
         var id = aData.estado_trabajo; // ID is returned by the server as part of the data
         var $nRow = $(nRow); // cache the row wrapped up in jQuery
         if (id == "Entregado") {
         $nRow.css({"background-color":"#C8ECA9"})
         }
        else if (id == "Imprenta") {
        $nRow.css({"background-color":"#2DA7F5"})
        }
        return nRow
        },
    
        "pageLength": 15,
    
        "processing": true,
        dom: "Tfrtip",
        ajax: {
            url: "examples/php/dates.php",
            type: "POST"
        },
        serverSide: true,
        columns: [
            { data: null, defaultContent: '', orderable: false },
            { data: "empresa" },
            { data: "tipo_trabajo" },
            { data: "detalle_trabajo" },
            { data: "factura" },
            { data: "IVA" },
            { data: "importe_total", render: $.fn.dataTable.render.number( ' ', '.', 0, ' $ ' ) },
            { data: "fecha_venta" },
            { data: "vendedor" },
            { data: "comentarios" },
        ],order: [ 7, 'desc' ],
        tableTools: {
            sRowSelect: "os",
            sRowSelector: 'td:first-child',
            sSwfPath: "TableTools/swf/copy_csv_xls_pdf.swf",
            aButtons: [
                { sExtends: "editor_create", editor: editor },
                { sExtends: "editor_edit",   editor: editor },
                { sExtends: "editor_remove", editor: editor },
                {
                    sExtends: "collection",
                    sButtonText: "Exportar",
                   sButtonClass: "save-collection hidden-xs",
                    aButtons: [ 'copy', 'csv', 'xls', 'pdf' ]
                },
                {
                    sExtends: "print",
                    sButtonText: "Imprimir",
                    sButtonClass: "hidden-xs",
                    sInfo: "Presiones la tecla 'Escape' para salir"
    
                    },
            ]
        },
        language: {
            processing:     "Procesando...",
            search:         "Buscar:",
            lengthMenu:     "Afficher _MENU_ éléments",
            info:           "Mostrando  _START_  de  _END_ - <b>Total:</b> _TOTAL_ registros",
            infoEmpty:      "Affichage de l'&eacute;lement 0 &agrave; 0 sur 0 &eacute;l&eacute;ments",
            infoFiltered:   "(Filtrando _MAX_ &eacute;l&eacute;ments au total)",
            infoPostFix:    "",
            loadingRecords: "Cargando...",
            zeroRecords:    "No se han encontrado registros",
            emptyTable:     "La tabla esta vacia",
            paginate: {
                first:      "Primera",
                previous:   "Anterior",
                next:       "Siguiente",
                last:       "Ultima"
            },
            aria: {
                sortAscending:  ": Ordenar Ascendente",
                sortDescending: ": Ordenar Descendente"
            }
        }
    } );
    

    } );

  • fedefazzfedefazz Posts: 19Questions: 6Answers: 1
    Answer ✓

    Allan, problem solved. i add i line in the dates.php.

    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'ventas_2015' )
    ->fields(
    Field::inst( 'empresa' ),
    Field::inst( 'tipo_trabajo' ),
    Field::inst( 'detalle_trabajo' ),
    Field::inst( 'factura' ),
    Field::inst( 'IVA' ),
    Field::inst( 'importe_total' ),
    Field::inst( 'fecha_venta' )
    ->validator( 'Validate::dateFormat', array(
    "empty" => false,
    "format" => Format::DATE_ISO_8601,
    "message" => "Please enter a date in the format yyyy-mm-dd"
    ) )
    ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
    ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601),
    Field::inst( 'vendedor' ),
    Field::inst( 'comentarios' ),
    Field::inst( 'modificadox')->setValue( $usuario )

    )
    

    Sorry and thanks for all

This discussion has been closed.