Free OrangeHRM Leave Calendar

Rob Hammond
bloghammond
Published in
2 min readJan 9, 2012

The open source version of OrangeHRM is a great system and a really good way of managing a team’s annual leave dates. However one feature achingly missing from the free version is a leave calendar, which you have to pay $250(!) in order to add in the functionality.

I’ve knocked up an easy (and moreover free) way of getting a calendar into the system (version 2.6). Just follow the instructions below to implement a basic (not pretty) leave calendar:

1. Edit the main menu to add a link to your calendar (around line 500) by adding another element to the subs menu:

/* Start leave menu */
if (($_SESSION['empID'] != null) || $arrAllRights[Leave]['view']) {
$menuItem = new MenuItem("leave", $lang_Menu_Leave, "./index.php?menu_no_top=leave&reset=1");
$menuItem->setCurrent($_GET['menu_no_top'] == "leave");
$subs = array();
$subsubs = array();
$subs[] = new MenuItem("leavecal", $i18n->__("Leave calendar"), "./leavecal.php",'rightMenu');
if ($authorizeObj->isAdmin() && $arrAllRights[Leave]['view']) {


2. Download this awesome jQuery calendar and upload the required scripts to a folder in your OrangeHRM root folder.
3. Copy the JSON example from the demos folder into your OrangeHRM root folder, and rename the HTML file to 'leavecal.php'4. Replace the PHP code in json-events.php with the following:<?php
$db_host = "localhost";
$db_user = "db_user";
$db_pwd = "db_pass";
$db_name = "db_name";
$db_port = 3306;
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$sql = "SELECT *
FROM `hs_hr_leave`
WHERE leave_status > 1
ORDER BY leave_date ASC;";
$leave_dates = array();$res = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($res)) {
$employee_id = $row['employee_id'];
$sql1 = "SELECT `emp_firstname` FROM `hs_hr_employee` WHERE `emp_number` = '$employee_id'";
$res1 = mysql_query($sql1) or die(mysql_error());
$row1 = mysql_fetch_array($res1);
$employee = $row1[0];
$start_date = $row['leave_date'];
$end_date = $row['leave_date'];
$event_id = $row['leave_request_id'];
$title = $employee . " A/L";
array_push($leave_dates, array(
'id' => $event_id,
'title' => $title,
'start' => $start_date,
'end' => $end_date,
));
}
echo json_encode($leave_dates);
?>
And there you have it - simple, dirty, will break if/when you update the system, but hey it's quick, easy and costs nothing.

--

--

Rob Hammond
bloghammond

PS Director, EMEA at BrightEdge. Technologist, SEO, renewable energy enthusiast