Tutorial: Calendar Application with print button and event color per day

In this example, we will see how to embed the print button in the Calendar application and also exemplify the automatic functionality of colors in past, present and future events.

Creating an application

1. The table that will be used for the implementation of the calendar is “events”.

CREATE TABLE `events` (`id` INT(11) NOT NULL AUTO_INCREMENT,`title` VARCHAR(64) DEFAULT NULL,`description` VARCHAR(128) DEFAULT NULL,`start_date` DATE DEFAULT NULL,`start_time` TIME DEFAULT NULL,`end_date` DATE DEFAULT NULL,`end_time` TIME DEFAULT NULL,`recurrent` VARCHAR(1) DEFAULT NULL,`period` VARCHAR(1) DEFAULT NULL,`users` VARCHAR(10) DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;


2. Select the fields from the table that will be used in the application.

Items with “*” are required to create the application. The other fields are only used for calendar information.

Options

  • Id: Used to identify the record, select the primary key field in this table. (Int (11))
  • Title: It is used to store the theme of each activity that is displayed in the application. ((Varchar (50))
  • Start date: The start date of the activity will be recorded. * (Date or date and time)
  • Start Time: It will record the start time of the activity. * (Date or date and time)
  • End date : The activity end date will be recorded. * (Date or date and time)
  • End Time: The activity end time will be recorded. * (Date or date and time)
  • Recurrence: Used to indicate whether the event is repeat in a month, week or day. (Int) (1)
  • Period: Used to indicate the type of repetition reptição: month, week or day. (Int) (1)> Note: If you have a datetime type field in the database, you can list the date and time options using the same datetime field of the database.The application will take both values ​​and concatenate them before saving them in the database

Inserting the Print button

3. Visit the “Print” item in the application menu

4. Enable the option: “Show Print button.”

Creating a function for axis Multiply the use of colors in events.

To demonstrate this feature, we will create a php function to automatically insert records for today, yesterday and tomorrow, every time the application is run.

5. First, we create a PHP function, accessing, in the application menu, the element: “Programming >> PHP Methods >> New method”.

6. The method name will be “check_date” and will have the following code:

// Always insert record for TODAY, YESTERDAY and TOMORROW!// $ ontem = (date (“Y”)). “-“. (date (“m”)). “-“. (date (“d”) – 1);              $ leaf   = date(“Ymd”);              $ ontem = date(‘Ymd’, strtotime(“-1 day”,strtotimeleaf($)));              $ amanha = date(‘Ymd’, strtotime(“+1 day”,strtotimeleaf($))); // This macro will protect the value passed as paramenter according to the used database.$ ontem  = sc_sql_protect($ ontem, “date”);              $ leaf   = sc_sql_protectleaflet($, “date”);              $ amanha = sc_sql_protect($ amanha, “date”);// Capturing value to check.if($ leaf==1) {               }              sc_lookup(yesterday,”select count (*) from events where start_date = $ ontem“);              sc_lookup(today,”select count (*) from events where start_date =leaf $“);              sc_lookup(tomorrow,”select count (*) from events where start_date = $ amanha“);               // Insert Record event has nothing yesterday.if(empty({yesterday[0] [0]})) {               if($this- >Ini- >nm_tpbanco == ‘pdo_sqlsrv’) {               sc_exec_sql(”              SET DATEFORMAT ymd;              insert into events (title, description, start_date, start_time, end_date, end_time, recurrent, period, users)               values               (‘Event’, ‘Description’,$ ontem, NULL,$ ontem, NULL, ‘ N ‘,’ D ‘,’ ‘) “);               } else {               sc_exec_sql(”              insert into events (title, description, start_date, start_time, end_date, end_time, recurrent, period, users)               values               (‘Event’, ‘Description’,$ ontem, NULL,$ ontem, NULL, ‘N’, ‘ D ‘,’ ‘) “);               }              }// Insert Record event has nothing today.if(empty({today[0] [0]})) {               if($this- >Ini- >nm_tpbanco == ‘pdo_sqlsrv’) {               sc_exec_sql(”              SET DATEFORMAT ymd;              insert into events (title, description, start_date, start_time, end_date, end_time, recurrent, period, users)               values               (‘Event’, ‘Description’,$ leaf, NULL,$ leaf, NULL, ‘ N ‘,’ D ‘,’ ‘) “);               } else {               sc_exec_sql(”              insert into events (title, description, start_date, start_time, end_date, end_time, recurrent, period, users)              values               (‘Event’, ‘Description’,$ leaf, NULL,$ leaf, NULL, ‘N’, ‘ D ‘,’ ‘) “);               }               }// Insert Record event has nothing today.if(empty({tomorrow[0] [0]})) {               if($this- >Ini- >nm_tpbanco == ‘pdo_sqlsrv’) {               sc_exec_sql(”              SET DATEFORMAT ymd;              insert into events (title, description, start_date, start_time, end_date, end_time, recurrent, period, users)               values               (‘Event’, ‘Description’,$ amanha, NULL,$ amanha, NULL, ‘ N ‘,’ D ‘,’ ‘) “);               } else {               sc_exec_sql(“insert into events (title, description, start_date, start_time, end_date, end_time, recurrent, period, users) values               (‘Event’, ‘Description’,$ amanha, NULL,$ amanha, NULL, ‘N’, ‘ D ‘,’ ‘) “);               }            }

7. Then we make the function call in the onScriptInit event, it will be executed every time the application is started.

8. Click on “Run application” to generate the data source and view the application.

Tutorials in the same category

Tutorial: Evaluation Field in Forms

In this tutorial, you will see how to create a Form using the evaluation fields. Creating the Form ...

Tutorial: Grid fixed columns

In this sample we’ll see the option fixed column on the grid. This way we’ll be able to do a hor...

Tutorial: New Refined Search

In this sample we’ll develop one grid using the option refined search, that will allow us to searc...

Tutorial: Grid Mobile

In this sample, we’ll see the configuration of one grid application for mobile. Creating a ...

Comment this post