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 to events of the past, present and future.

Creating the application

1. The table that will be used for the calendar implementation 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 table fields that will be used in the application.

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

Options

  • Id: Used to identify the record, select the primary key field in this table. (Int (11))
  • Title: Used to store the subject of each activity that is displayed in the application. ((Varchar (50))
  • Start date: the start date of the activity will be recorded. * (Date or datetime)
  • Start Time: Will record the start time of the activity. * (Date or datetime)
  • End date: end date of the activity will be recorded. * (Date or datetime)
  • End Time: Will record the finish time of the activity. * (Date or datetime)
  • Recurrence: Used to state whether the event repeats in a month, week or day. (Int) (1)
  • Period: Used to state the type of recurrence reptição: month, week or day. (Int) (1)   > Note: If you have a field of type datetime in the database, you can list the options date and time using the same datetime field from the database. The application will take the two values and will concatenate them before saving 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 to exemplify the use of colors in the events

To demonstrate this feature, we’ll create a php function to automatically insert records the dates of today, yesterday and tomorrow, every time the application runs.

5. First let’s create a PHP function, accessing, in the application menu, the item: “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);
              $hoje   = date("Y-m-d");
              $ontem = date('Y-m-d', strtotime("-1 day",strtotime($hoje)));
              $amanha = date('Y-m-d', strtotime("+1 day",strtotime($hoje)));
 
// This macro will protect the value passed as paramenter according with the used database.
$ontem  = sc_sql_protect($ontem, "date");
              $hoje   = sc_sql_protect($hoje, "date");
              $amanha = sc_sql_protect($amanha, "date");
// Capturing value to check.
if($hoje==1){
 
              }
              sc_lookup(yesterday,"select count(*) from events where start_date = $ontem");
              sc_lookup(today,"select count(*) from events where start_date = $hoje");
              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',$hoje,NULL,$hoje,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',$hoje,NULL,$hoje,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 perform the function call in onScriptInit event, it will be executed whenever the application is started.

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

Tutorials in the same category

Calendar per User

In this tutorial we will see how to create a calendar for implementation to filter by users. For thi...

Calendar Application

1. The table that will be used for the calendar implementation is “events”. CREATE TABLE `event...

Comment this post