How can I do a table update in phpmyadmin from codeigniter using the webix javascript library (specifically scheduler.js)?

43 views Asked by At

I understand that the connection is made from Codeigniter's database.php, there I have to set both username, password, db_name, etc.

On the other hand, we also have the Webix library, where the views, controllers and models already come, in fact I already have code.

This is my webix view code, the file is called calendar.php

<html> <head>
    <title>calendarPHP</title>
    <!-- Webix Library -->
    <script src="<?php echo base_url('PIXXEL/public/webix/codebase/webix.js'); ?>" type="text/javascript"></script>
    <link rel="stylesheet" href="<?php echo base_url('PIXXEL/public/webix/codebase/webix.css'); ?>" type="text/css">

    <!-- Scheduler -->
    <script src="<?php echo base_url('PIXXEL/public/scheduler/codebase/scheduler.js'); ?>" type="text/javascript"></script>
    <link rel="stylesheet" href="<?php echo base_url('PIXXEL/public/scheduler/codebase/scheduler.css'); ?>" type="text/css"> </head> <body>
    <!-- Scheduler constructor -->
    <script>
        webix.ui({
            view: "scheduler",
            url: "https://docs.webix.com/calendar-backend/",
            on: {
                onItemClick: function(id) {
                // Obtener los datos del evento seleccionado
                var event = this.getEvent(id);
                var eventData = {
                    eventoprueba: event.text,
                    fecha: event.start_date,
                    hora_inicial: event.start_date.getHours() + ":" + event.start_date.getMinutes() + ":00",
                    hora_final: event.end_date.getHours() + ":" + event.end_date.getMinutes() + ":00",
                    notas: event.notes
                };

                // Enviar los datos al backend para guardarlos en la base de datos
                webix.ajax().post("http://localhost/PIXXEL/app/Controllers/CitasController/actualizar_cita", eventData);
                }
            }
            });
    </script> </body> </html>

here I have the Model called CitaModel.php

<?php

namespace App\Models;

use CodeIgniter\Model;

class QuoteModel extends Model
{
     protected $table = 'appointments';

     public function insertQuote($data)
     {
         return $this->insert($data);
     }
}

And this is my controller called AppointmentsController.php

<?php

namespace App\Controllers;

use App\Models\CitaModel;

class AppointmentsController extends BaseController
{
     public function insert_quote()
     {
         $appointmentModel = new AppointmentModel();

         // Get the data sent by Webix
         $testevent = $this->request->getPost('testevent');
         $date = $this->request->getPost('date');
         $start_time = $this->request->getPost('start_time');
         $end_time = $this->request->getPost('end_time');
         $notes = $this->request->getPost('notes');

         // Create an array with the appointment data
         $quotedata = [
             'testevent' => $testevent,
             'date' => $date,
             'start_time' => $start_time,
             'end_time' => $end_time,
             'notes' => $notes
         ];

         // Insert the citation into the database
         $appointmentModel->insert Appointment($appointmentdata);

         // Send a response to the client (Webix)
         return $this->response->setJSON(['success' => true]);
     }

     public function update_quote()
{
     $appointmentModel = new AppointmentModel();

     // Get the data sent by Webix
     $testevent = $this->request->getPost('testevent');
     $date = $this->request->getPost('date');
     $start_time = $this->request->getPost('start_time');
     $end_time = $this->request->getPost('end_time');
     $notes = $this->request->getPost('notes');

     // Create an array with the updated data of the appointment
     $quotedata = [
         'testevent' => $testevent,
         'date' => $date,
         'start_time' => $start_time,
         'end_time' => $end_time,
         'notes' => $notes
     ];

     // Update the citation in the database
     $appointmentModel->update($appointmentdata);

     // Send a response to the client (Webix)
     return $this->response->setJSON(['success' => true]);
}

The good function is supposed to be the second one, that of update_quote, because I realized that I have to do UPDATE statements in phpmyadmin to update the already created table.

What is it that doesn't make sense to me?

I understand that we refer to the Webix script scheduler.js, I also understand that this file is not modifiable, wow, it can be modified but the code is unreadable, there are no spaces or indents, also on the Internet it says that there is no need to do it, I understand , of course you have to reference them () and such.

What doesn't make sense to me, is, how do I tell the code to update my 'Appointments' table when I hit the Done button of my webix view:

WEBIX view

enter image description here

This view, of course, comes from calendar.php in the views folder...

As a final paragraph, I would like that when I click "Done" my appointments table is updated depending on the data that I entered in my scheduler.js form (?: I don't even know if it's a form), how can I achieve that? :

enter image description here

I have seen the need to also ask ChatGPT for help but we know that for logic it is not very good, even so it clarified some ideas for me.

THANK YOU

0

There are 0 answers