In this article we will consider a customization of Guriddo Scheduler PHP.
Prior to version 5.1.0 it was very difficult to add additional fields in the form. With version 5.1.0 we introduce a very easy way of adding new fields and design the scheduler form.
In this article I will demonstrate adding of two fields – one input and one select and show additional features that are very useful.
To add the fields we need first to create these fields in database event table. If using MySql the db_mysql.sql provided into the package in directory (php/PHPSuito/Scheduler/backend/ ) look like
CREATE TABLE IF NOT EXISTS events ( event_id int(11) unsigned NOT NULL AUTO_INCREMENT, user_id int(10) unsigned NOT NULL DEFAULT '0', start_event int(10) unsigned NOT NULL DEFAULT '0', end_event int(10) unsigned NOT NULL DEFAULT '0', title varchar(255) NOT NULL, description text NOT NULL, location varchar(255) NOT NULL DEFAULT '', categories varchar(255) NOT NULL DEFAULT '', access varchar(255) NOT NULL DEFAULT '', all_day tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (event_id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
We will add the fields named text_field as text and select_field as integer. The table will look like
CREATE TABLE events ( event_id int(11) UNSIGNED NOT NULL, user_id int(10) UNSIGNED NOT NULL DEFAULT '0', start_event int(10) UNSIGNED NOT NULL DEFAULT '0', end_event int(10) UNSIGNED NOT NULL DEFAULT '0', title varchar(255) NOT NULL, description text NOT NULL, location varchar(255) NOT NULL DEFAULT '', categories varchar(255) NOT NULL DEFAULT '', access varchar(255) NOT NULL DEFAULT '', all_day tinyint(1) NOT NULL DEFAULT '0', text_field varchar(50) NOT NULL, select_field int(11) NOT NULL, PRIMARY KEY (event_id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Execute the SQL script to add the table to your database or add these fields using other known ways.
The second step is to add these fields in database.php definition so that the scheduler know what fields to use. Open the file database.php in directory php/PHPSuito/Scheduler/backend/ and locate the private php variable $dbmap. At end of array add these two fields like this (see the last two fields):
protected $dbmap = array( "event_id"=>"id", // this is a id key "title"=>"title", "start_event"=>"start", "end_event"=>"end", "description"=>"description", "location"=>"location", "categories"=>"className", "access"=>"access", "all_day"=>"allDay", "user_id"=>"user_id", "text_field"=>"text_field", "select_field"=>"select_field" );
Now we need to add these fields in our html template, so that they are shown to the user. We will add these fields before the description field. You can add the fields in arbitrary place in the form. To do this open the file calendar.html in directory php/PHPSuito/Scheduler/templates/ from the package. Locate the description field (id=”description) and befor it add the following text:
... <tr> <td> <label for="text_field"> My text:</label> </td> <td> <input class="ui-widget-content ui-corner-all ui-input" id="text_field" name="text_field" size="50"/> </td> </tr> <tr> <td> <label for="select_field"> My select:</label> </td> <td> <select id="select_field" name="select_field"> [@option_select_field] </select> </td> </tr> ...
Ads can be seen the id and name properties should have the same names as defined in
the $dbmap array. Note how option of the select_field is defined.
The final step is definition of the select data. With version 5.1.0 we introduce a new method called setSelectOptions.
This method accept two parameter – the first one is the templateid and the second
option is the data. Data can be array or SQL query with two fields – representing the
value and text for the select. We will use array. To do this open the evencal.php
(the php definition script for the scheduler) and add the following line before
... $eventcal->setSelectOptions('option_select_field', array(1=>"One",2=>"Two")); $eventcal->render();
Note that the first parameter in setSelectOptions is the templateid defined in the template as [@option_select_field].
Run the script.
Additionally to these features we have added another method – setUserData. The purpose of this method is to add update additional (hidden field information defined in the event table). Let suppose that we added a field db_user which purpose is to record which user have added updated the record (not calendar user). Let suppose that the session variable contain the user name information. The line:
... $eventcal->setUserData( array('db_user'=>$SESSION['usernname']) ); ...
will add/update that field with the username every time the action of adding or updating is performed.
Copyright 2014 TriRand LtdAll Rights ReservedRSSBack to Top