Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by diego on Dec 30, 2009 10:16
open dhtmlx forum
insert in postgresql

hi,

I would like to know how to manually insert into the schedule. I have it from the page as follows:

    global $DB_SERVER,$DB_PORT,$DB_NAME,$DB_USER,$DB_PASSWORD;

$res = pg_connect("host=$DB_SERVER port=$DB_PORT dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD");


    function insercion($action){

        $status = $action->get_status();

        $id_evento = $action->get_value("id_evento");

        $start_date = $action->get_value("start_date");
        $end_date = $action->get_value("end_date");
        $evento_nombre = $action->get_value("evento_nombre");
        $detalles = $action->get_value("detalles");


        if ($status == "inserted"){
            $scheduler->sql->query(""INSERT INTO eventos (id_evento, start_date,end_date,evento_nombre) VALUES ((id_evento, start_date,end_date,evento_nombre) );
            $action->success();
        }

    }

    $scheduler = new schedulerConnector($res,"Postgre");

    $scheduler->event->attach("afterProcessing","insercion");

    $scheduler->render_table("eventos","id_evento","start_date,end_date,evento_nombre,detalles");

how to capture the values to create a new event
Answer posted by Alex (support) on Jan 04, 2010 04:18

Hello,

you can use addEvent method to insert new event

http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxscheduler:api_method_dhtmlxscheduler_addevent

In order to send request with an event that is added by addEvent method you can use the following method:

dataProcessor.setUpdated(event_id,true,"inserted");

dataProcessor.sendData();

Here dataProcessor is DataProcessor object.

Answer posted by Stanislav (support) on Jan 04, 2010 05:07
a) If you want to intercept insert action, you need to use beforeInsert , not the afterProcessing server side event. 
b) 
 $action->success(); 
need to be replaced with 
 $action->success($new_id_value);  //inform about new ID of event
Answer posted by diego on Jan 04, 2010 07:35
hi,

thank you very much for answering my question and thanks for your effort and dedication.

what happens is this this is my page events.php

<?php
    include ('../componentes/codebase/connector/scheduler_connector.php');
    include_once('../componentes/codebase/connector/db_postgre.php');
    require_once("../componentes/comunicacion.inc");
   
    global $DB_SERVER,$DB_PORT,$DB_NAME,$DB_USER,$DB_PASSWORD;
  $res = pg_connect("host=$DB_SERVER port=$DB_PORT dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD");

    function insercion($action){
        $status = $action->get_status();
 
        if ($status == "inserted"){
            $scheduler->sql->query("insert","INSERT INTO eventos(id_evento,start_date,end_date,evento_nombre,detalles) VALUES ("xxxx,xxxx,xxxx,xxxxx");
            $action->success();
        }
    }

 
    $scheduler = new schedulerConnector($res,"Postgre");
    $scheduler->event->attach("afterProcessing","insercion");
    $scheduler->render_table("eventos","id_evento","start_date,end_date,evento_nombre,detalles");
?>

What I would like to know is how to receive data from the timetable on the events page I noticed that when you create an event sent by the POST method

1262619087106_!nativeeditor_statusinserted
1262619087106_end_date2010-01-04 06:05
1262619087106_id1262619087106
1262619087106_start_date2010-01-04 06:00
1262619087106_textexample event text description
ids1262619087106

how can I retrieve the data on my sales page to send the attachment manually

insistence and apologize for any inconvenience caused and thanks for your time


Answer posted by Stanislav (support) on Jan 04, 2010 07:42
If you mean the same page where scheduler resides, you can use

var ev = scheduler.getEvent(id);
var text = ev.text;
var start_date = scheduler.template.xml_format(ev.start_date);
var end_date = scheduler.template.xml_format(ev.start_date);

Id - id of added|updated event.
Answer posted by diego on Jan 04, 2010 08:38

thank you very much for your response

but what I need is to receive the data on the webpage dataprocesor

constructs the page where the calendar is this:


<script type="text/javascript" charset="utf-8">
    function init() {
         
        scheduler.config.xml_date="%Y-%m-%d %H:%i";
        scheduler.config.lightbox.sections=[     
            {name:"description", height:130, map_to:"text", type:"textarea" , focus:true},
            //{name:"location", height:43, type:"textarea", map_to:"details" },
            {name:"time", height:72, type:"time", map_to:"auto"}
        ]
        scheduler.config.first_hour=4;
        //scheduler.locale.labels.section_location="Location";
        scheduler.config.details_on_create=true;
        scheduler.config.details_on_dblclick=true;
     
        scheduler.init('scheduler_here',null,"month");
        scheduler.load("events.php?uid="+scheduler.uid());
         
        var dp = new dataProcessor("events.php");
        dp.init(scheduler);
 
    }


your code if I would serve on that page but I need to recover the data on page events.php that is:

include ('../componentes/codebase/connector/scheduler_connector.php');
    include_once('../componentes/codebase/connector/db_postgre.php');
    require_once("../componentes/comunicacion.inc");
   
    global $DB_SERVER,$DB_PORT,$DB_NAME,$DB_USER,$DB_PASSWORD;
  $res = pg_connect("host=$DB_SERVER port=$DB_PORT dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD");

    function insercion($action){
        $status = $action->get_status();
 
        if ($status == "inserted"){
            //$action->set_status("deleted");
            $scheduler->sql->query("insert","INSERT INTO eventos(id_evento,start_date,end_date,evento_nombre,detalles) VALUES (xxxxx,xxxx,xxxxx,xxxx);
            $action->success();
        }
    }

 
    $scheduler = new schedulerConnector($res,"Postgre");
    //$scheduler->enable_log("log.txt",true);
    $scheduler->event->attach("afterProcessing","insercion");
    $scheduler->render_table("eventos","id_evento","start_date,end_date,evento_nombre,detalles");

and when I check the events page I get the following error:

Fatal error: Uncaught exception 'Exception' with message 'Incorrect incoming data, ID of incoming records not recognized' in /var/www/sitiosphp/medicos/componentes/codebase/connector/dataprocessor.php:64 Stack trace: #0 /var/www/sitiosphp/medicos/componentes/codebase/connector/base_connector.php(336): DataProcessor->process(Object(DataConfig), Object(DataRequestConfig)) #1 /var/www/sitiosphp/medicos/componentes/codebase/connector/base_connector.php(290): Connector->render() #2 /var/www/sitiosphp/medicos/scripts/events.php(32): Connector->render_table('eventos', 'id_evento', 'start_date,end_...') #3 {main} thrown in /var/www/sitiosphp/medicos/componentes/codebase/connector/dataprocessor.php on line 64


thanks for your time

Attachments (2)
Answer posted by diego on Jan 05, 2010 05:08
hi,

This would serve to the page that draws the schedule

var ev = scheduler.getEvent(id);
var text = ev.text;
var start_date = scheduler.template.xml_format(ev.start_date);
var end_date = scheduler.template.xml_format(ev.start_date);

as I do the same but from a php page
Answer posted by Stanislav (support) on Jan 05, 2010 07:20
>>Fatal error: Uncaught exception 'Exception' with message 'Incorrect incoming data, ID of incoming records not recognized' 
Such error can occurs if you are calling
        events.php?editing=true
which marks dataprocessor call, but there is no valid $_POST["ids"] value. 



if ($status == "inserted"){

      $id_evento = $action->get_id();
      $start_date = $action->get_value("start_date");
      $end_date = $action->get_value("end_date");
      $evento_nombre = $action->get_value("evento_nombre");
      $detalles = $action->get_value("detalles");


      $scheduler->sql->query("insert","INSERT INTO eventos(id_evento,start_date,end_date,evento_nombre,detalles) VALUES ('{$id_evento}','{$start_date}','{$end_date}','{$evento_nombre}','{$detalles}')");
      $action->success(); // <= parameter need to be added if ID is changes
}


Answer posted by diego on Jan 08, 2010 07:16
thanks for your response and your time

not if you could help me as I fix the problem because what I want is to delete operations, insert and update manually and retrieve the data in the php page that assumed it to this form:

$id_evento = $action->get_id();
      $start_date = $action->get_value("start_date");
      $end_date = $action->get_value("end_date");
      $evento_nombre = $action->get_value("evento_nombre");
      $detalles = $action->get_value("detalles");


and if this is not good or if I'm wrong

      $scheduler->sql->query("insert","INSERT INTO eventos(id_evento,start_date,end_date,evento_nombre,detalles) VALUES ('{$id_evento}','{$start_date}','{$end_date}','{$evento_nombre}','{$detalles}')");
      $action->success();


please help, thanks
http://www.google.com.co/images/cleardot.gif" style="margin-right: 0.33em; cursor: pointer; visibility: visible;" id="zippyicon" class="buttons square13 zippy-plus">
Answer posted by Stanislav (support) on Jan 12, 2010 09:40
Inside any server side event ( beforeInsert, beforeUpdate, beforeDelete, etc. ) you can use the same code as above to fetch parameters and execute your custom SQL
To have custom logic for insert|update|delete you will need to attach code for 3 above mentioned events. 

function my_code($action){
    $id_evento = $action->get_id();
    $start_date = $action->get_value("start_date");
    $end_date = $action->get_value("end_date");
    $evento_nombre = $action->get_value("evento_nombre");
    $detalles = $action->get_value("detalles");

    $sch->sql->query("insert","INSERT INTO eventos(id_evento,start_date,end_date,evento_nombre,detalles) VALUES  ('{$id_evento}','{$start_date}','{$end_date}','{$evento_nombre}','{$detalles}')");
 
    $action->success();
}
$sch->event("beforeInsert",my_code)
$sch->render...