Jump to content


Pedro Bernal

Member Since 22 Jan 2014
Offline Last Active Feb 20 2015 12:35 AM
-----

Topics I've Started

How to add some custom anotations in a Form

10 February 2015 - 06:29 AM

Hi, I want to know if is there a way to add some aclarations or anotations for fields into a groceryCrud form, in order to clarify what information should the user enter in some tricky fields.

 

Thanks.


Problem auditing queries in Codeigniter with Grocerycrud

24 September 2014 - 03:45 PM

I need to audit the insert, edit and delete queries from my application, I tried using a hook that calls a model that save the query into a table in my database, however it is just saving the SHOW, DESCRIBE and SELECT statements, but the update, adding and deleting actions that I perform on the GroceryCrud views are not being saved.

Can someone help me to figure it out why, Thanks!

Hook code:

<?php
class Db_log {


    function __construct() 
    {
    }


    function logQueries() 
    {
        $CI = & get_instance();
        $CI->load->model("model_log");
        $filepath = APPPATH . 'logs/Query-log-' . date('Y-m-d') . '.php'; // Creating Query Log file with today's date in application/logs folder
        $handle = fopen($filepath, "a+");                 // Opening file with pointer at the end of the file
        $times = $CI->db->query_times;                   // Get execution time of all the queries executed by controller
        foreach ($CI->db->queries as $key => $query) 
        { 
            $sql = $query . " \n Execution Time:" . $times[$key]; // Generating SQL file alongwith execution time
            fwrite($handle, $sql . "\n\n");              // Writing it in the log file
            $CI->model_log->log($sql);                     // Calling the model
        }
        fclose($handle);      // Close the file
    } 
}


?>

 

 

Model code:

<?php
Class Model_log extends CI_Model
{
 public function log($sql)
  {
    if($_SESSION<>null)
    {
      $this-> db ->select('*');
      $this-> db ->from('usuarios');
      $this -> db -> where('nombre', $_SESSION["usuario"]);
      $query = $this->db->get();
      $user_data= get_object_vars($query->row());
      $sql = str_replace("'", "", $sql);
      date_default_timezone_set('America/Bogota');
      $date = date('Y-m-d H:i:s', time());
      $this->db->query("
          INSERT INTO `log`(`query`, `usuario`, `fecha`)
           VALUES
            ('".$sql."',".$user_data["id"].",'".$date."')");
    }
  }
}
?>
 
  

 

 


Error with query using mayor or equal in Grocery Crud and Code Igniter

26 May 2014 - 05:34 PM

I am having an issue with grocerycrud, I am collecting decimal values every 5 minutes and storing them into a table named medidas_ludlum_5min, I have a view that allows to the user select a date range, a value and ">", "=" or ">=" options.

After that I process the selection with a switch in my controller and with GroceryCrud I am showing the results of the query.

When I select values higher than 0, it works good and I have two results:

Code:

$crud->where('(FK_ludlum="'.$ludlum_id.'"
and measurement > "'.$medida.'"
and fecha between "'.$fechainicio.'" and "'.$fechafin.'")',null,FALSE);

Results:

Measurement____________________Date

10_____________________________22/04/2014 - 17:18

11.5___________________________22/04/2014 - 17:23

However using the same date range with >= than 0 I just got the cero values.

Code:

$crud->where('(FK_ludlum="'.$ludlum_id.'"
and measurement >= "'.$medida.'"
and fecha between "'.$fechainicio.'" and "'.$fechafin.'")',null,FALSE);

Results:

Measurement____________________Date

0______________________________22/04/2014 - 17:13

0______________________________22/04/2014 - 17:28

0______________________________22/04/2014 - 17:33

0______________________________22/04/2014 - 17:38

0______________________________22/04/2014 - 17:43

As you can see the two values higher than cero are not presented in the groceryCrud table.

 

As an additional note I am using the same query to feed a google chart and it works perfect:

$sql = $this->db->query('SELECT * FROM medidas_ludlum_5min where FK_ludlum="'.$id.'"
and measurement >= "'.$medida.'"
and fecha between "'.$fechainicio.'" and "'.$fechafin.'"');

I dont know why is this happening any help will be apreciated, If someone needs more code just tell me and I can post it or message it.

Thanks!


Issue whith export and print buttons

13 March 2014 - 04:13 PM

Hi there I am having an issue: The export and print buttons doesnt work when I include a where method into my controller function, is there a way to fix it?.

 

 

Thanks!

 

Here is the code of my controller.

 $fechainicio = $this->input->post('fechainicio');
      $fechafin = $this->input->post('fechafin');
      $crud = new grocery_CRUD();
      $crud->where('fksitio',$_SESSION['site']);
      $crud->where('fecha >=',$fechainicio);
      $crud->where('fecha <=',$fechafin);
      $crud->set_table('formatos');
      $crud->set_field_upload('adjunto','assets/uploads');
      $crud->columns('fksitio', 'fecha', 'resultado','comentarios','adjunto');
      $crud->edit_fields('fksitio', 'fecha', 'resultado','comentarios','adjunto');
      $crud->display_as('fksitio','Sitio');$crud->display_as('adjunto','Archivo');
      $crud->set_language("spanish");
      $crud->set_primary_key('nombre','sitios');
      $crud->set_relation('fksitio','sitios','nombre');   
      $output = $crud->render();
      $data['username'] = $session_data['username'];
      $data['level'] = $session_data['level'];
      $this->load->view('CRUD_Formatos.php', $output);

disable buttons in add/edit forms

11 March 2014 - 09:46 PM

Hi, I want to know if there is a way to disable the button "Save and go back to list" in the add form, or where is it in the code?, so I can edit it.

 

Thanks!