title: Leave Plan plugin for orangehrm
body: <p>I am using <code>Orangehrm 3.2.1</code>(latest build). Below is the php code I am using to display a leave plan calendar for the employees employed with me since its too costly to buy from Orangehrm. When I run this script, I get screen on my browser which shows a part of the code....</p>
  
  <pre><code>".$seeDate.""; ?&gt;
  Month:      Year:       
  ".$i."
  "; } ?&gt; "; $even = 1; while ($row = mysql_fetch_array( $result ) ) { $employee_id = $row['employee_id']; $employee_num = $row['emp_number']; $employee_firstname = $row['emp_firstname']; $employee_lastname = $row['emp_lastname']; echo ""; if ( $even % 2) echo " "; else echo " "; $even++; // echo "$even $numDays
  "; for ($i = 1; $i &lt;= $numDays; $i++) { $day = checkDay($employee_num, $i, $month, $year); // echo "$employee_num, $i, $month, $year $day
  "; switch ($day) { case 'holiday': echo " "; break; case 'weekend': echo " "; break; case 'absence_full': echo " "; break; case 'absence_partial_m': echo " "; break; case 'absence_partial_a': echo " "; break; default: echo " "; break; }//switch }//for echo ""; }//while ?&gt;
  </code></pre>
  
  <p>The code which is seen on the screen is a part of my php script. Is there any modification that i need to carry out? I have played a lot around with it but don't seem to get it correct. The code as compared to <code>orangehrm version 2.5</code> has been changed and they have been marked  with // in the script below.</p>
  
  <pre><code>&lt;?php
  
  
  /*****************/
  /* Configuration */
  /*****************/
  
  //Database information
  $db_host = "localhost";
  $db_user = "root";
  $db_pwd = "";
  $db_name = "main";
  $db_port = 3306;
  
  
  $logoLink = "orangehrm/symfony/web/webres_513fd0981da216.38969927/themes/default/images/login/logo.png";
  
  
   /******************************/
   /* DONT EDIT BELLOW THIS LINE */
   /******************************/
  
  //Year
  if (isset($_GET['year']))
  $year = $_GET['year'];
  else
  $year = date("Y");
  
   //Month
   if (isset($_GET['month']))
   $month = $_GET['month'];
   else
   $month = date("m");
  
   $date_aux = $year . "-" . $month;
   $seeDate = date("Y-m", strtotime($date_aux));
  
   /* Number of days in a month/Year */
   function monthDays($month, $year) {
   return date("t", strtotime($year . "-" . $month . "-01"));
  }//
  
  
   //admin get Years
   function getYears($year) {
  
   global $db_host, $db_user, $db_pwd, $db_name, $db_port;
  
    if(!isset($year))
    $year = date("Y");
  
   //    $sql = "SELECT DISTINCT(EXTRACT(Year FROM leave_date)) FROM hs_hr_leave WHERE 1 ORDER BY leave_date;";
   $sql = "SELECT DISTINCT(EXTRACT(Year FROM date)) FROM ohrm_leave WHERE 1 ORDER BY date;";
  
     // Make a MySQL Connection
    mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
    mysql_select_db($db_name) or die(mysql_error());
  
    //Query
    $result = mysql_query($sql) or die(mysql_error());
  
  
    while ($row = mysql_fetch_array($result )) {
  
       if ($row['(EXTRACT(Year FROM Date))'] == $year) {/*
       echo "&lt;option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\" selected&gt;".$row['(EXTRACT(Year FROM leave_date))']."&lt;/option&gt;&lt;br&gt;";*/
       echo "&lt;option value=\"".$row['(EXTRACT(Year FROM date))']."\" selected&gt;".$row['(EXTRACT(Year FROM date))']."&lt;/option&gt;&lt;br&gt;";
    } else {
   //          echo "&lt;option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\"&gt;".$row['(EXTRACT(Year FROM leave_date))']."&lt;/option&gt;&lt;br&gt;";
       echo "&lt;option value=\"".$row['(EXTRACT(Year FROM date))']."\"&gt;".$row['(EXTRACT(Year FROM date))']."&lt;/option&gt;&lt;br&gt;";
    }
  
  }
  
  }//
  
  
  function weekDay($date) {
  
  $thisDay = date("D", strtotime($date));
  return $thisDay;
  
  }//
  
  function checkDay($employee_id, $i, $month, $year) {
  
  global $db_host, $db_user, $db_pwd, $db_name, $db_port;
  
    $date = $year . "-" . $month . "-" . $i;
  
  
   //       $sql = "SELECT * FROM hs_hr_holidays WHERE date = '$date';";
    $sql = "SELECT * FROM ohrm_holiday WHERE date = '$date';";
  
    mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
    mysql_select_db($db_name) or die(mysql_error());
  
    $result = mysql_query($sql)or die(msysql_error());
    $result_count = mysql_num_rows($result);
  
    if ($result_count &gt; 0)
       return "holiday";
  
  
    if( ( weekDay($date) == "Sat") || ( weekDay($date) == "Sun") ) {
       return "weekend";
    }
  
  
    //Get Absences
    //       $sql = "SELECT leaves.*
   //       FROM `hs_hr_leave` AS leaves
   //       WHERE (leaves.employee_id = '$employee_id') AND (leaves.leave_date = '$date') AND (leaves.leave_status &gt; 1)
  //       ORDER BY leaves.leave_date ASC;";
    $sql = "SELECT leaves.*
    FROM `ohrm_leave` AS leaves
    WHERE (leaves.emp_number = '$employee_id') AND (leaves.date = '$date') AND (leaves.status &gt; 1)
    ORDER BY leaves.date ASC;";
  
    mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
    mysql_select_db($db_name) or die(mysql_error());
  
    $result = mysql_query($sql)or die(mysql_error());
    $result_count = mysql_num_rows($result);
  
    if ( $result_count == 0 )  {
   // echo "default&lt;br&gt;";
       return "default";
    } else {
       while ($row = mysql_fetch_array( $result ) ) {
          if ($row['leave_length_days'] &lt; 1.0 ) {
             if ( ($row['start_time'] &gt;= "08:00:00") &amp;&amp; ($row['start_time'] &lt;= "09:00:00")  )
                return "absence_partial_m";
             else if ( ($row['start_time'] &gt;= "13:00:00") &amp;&amp; ($row['start_time'] &lt;= "18:00:00")  )
                return "absence_partial_a";
          } else
   // echo "full abs&lt;br&gt;";
             return "absence_full";
  
  
       }//
    }
  }
  
  
    $numDays = monthDays($month, $year);
   ?&gt;
  
   &lt;HTML&gt;
   &lt;HEAD&gt;&lt;TITLE&gt;Vacation Plan&lt;/TITLE&gt;
   &lt;script type="text/javascript"&gt;
   function sort(form) {
  
  
    var Page = "?";
  
    var month = form.listMonth.selectedIndex+1;
    var iyear = form.listYear.selectedIndex;
    var year = form.listYear.options[iyear].value;
  
    var URL = Page + "month=" + month + "&amp;year=" + year;
  
    window.location = URL;
  
    return false;
   }
   &lt;/script&gt;
   &lt;style type="text/css"&gt;
   &lt;!--
  .style2 {font-size: 12px; }
  td{ border:solid 1px red;}
  --&gt;
  &lt;/style&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
  &lt;?
  
  ?&gt;
  &lt;?php if (!empty($logoLink))
  echo "&lt;img src='$logoLink'/&gt;";
  ?&gt;
  &lt;center&gt;
  &lt;div id="sort" style="padding-right: 10%"&gt;
  &lt;form id="frmSort" name="frmSort" onsubmit="return sort(this); return false;"&gt;
    &lt;?
  $seeDate = date("F Y", strtotime($seeDate));
  echo "&lt;h2&gt;".$seeDate."&lt;/h2&gt;";
  ?&gt;
    &lt;div align="right"&gt;
    &lt;strong&gt;Month&lt;/strong&gt;:
    &lt;?php
       $curr_month = $month;
  
       $auxmonth = array (1=&gt;"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
       $select = "&lt;select name=\"listMonth\"&gt;\n";
  
       foreach ($auxmonth as $key =&gt; $val) {
          $select .= "\t&lt;option val=\"".$key."\"";
       if ($key == $curr_month) {
          $select .= " selected&gt;".$val."\n";
       } else {
          $select .= "&gt;".$val."\n";
       }
    }
    echo $select;
   ?&gt;
      &lt;/select&gt;
    &lt;img src="img/pixel.gif" width="1" height="1" /&gt;&lt;img src="img/pixel.gif" width="1" height="1" /&gt; &lt;img src="img/pixel.gif" width="1" height="1" /&gt;&lt;img src="img/pixel.gif" width="1" height="1" /&gt; &lt;img src="img/pixel.gif" width="1" height="1" /&gt;&lt;strong&gt;Year&lt;/strong&gt;:
    &lt;select name="listYear" id="listYear"&gt;
      &lt;?php getYears($year); ?&gt;
    &lt;/select&gt;
    &lt;img src="img/pixel.gif" width="1" height="1" /&gt; &lt;img src="img/pixel.gif" width="1" height="1" /&gt;
    &lt;input type="submit" name="Submit" value="Select" /&gt;
   &lt;/form&gt;
   &lt;/div&gt;
   &lt;div id="table"&gt;
   &lt;table width="90%" border="0" cellspacing="1" cellpadding="1"&gt;
   &lt;tr&gt;
    &lt;td &gt;&amp;nbsp;&lt;/td&gt;
    &lt;?
     for($i = 1; $i &lt;= $numDays; $i++) {
        echo "&lt;td bgcolor=\"#FFFFFF\" width=\"15\"&gt;&lt;div align=\"center\"&gt;&lt;strong&gt;".$i."&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;";
       }
    ?&gt;
    &lt;/tr&gt;
    &lt;?
   global $db_host, $db_user, $db_pwd, $db_name, $db_port;
   //       $sql = "SELECT emp.*
   //              FROM hs_hr_employee AS emp
   //              INNER JOIN hs_hr_users AS users ON emp.emp_number = users.emp_number
   //              WHERE (users.status = 'Enabled')
   //              ORDER BY emp.emp_firstname ASC";
    $sql = "SELECT emp.*
           FROM hs_hr_employee AS emp
           INNER JOIN ohrm_user AS users ON emp.emp_number = users.emp_number
           WHERE (users.status = 1)
           ORDER BY emp.emp_firstname ASC";
    mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
    mysql_select_db($db_name) or die(mysql_error());
    $result = mysql_query($sql)or die(mysql_error());
    $result_count = mysql_num_rows($result);
    // echo "toto:$result_count&lt;br&gt;";
     $even = 1;
     while ($row = mysql_fetch_array( $result ) ) {
       $employee_id = $row['employee_id'];
       $employee_num = $row['emp_number'];
       $employee_firstname = $row['emp_firstname'];
       $employee_lastname = $row['emp_lastname'];
       echo "&lt;tr&gt;";
       if ( $even % 2)
          echo " &lt;td bgcolor=\"#FFFFFF\" width=\"10%\"&gt;&lt;div align=\"right\"&gt;".$employee_firstname . " " . $employee_lastname . "&lt;/div&gt;&lt;/td&gt;";
       else
          echo " &lt;td bgcolor=\"#FFFFFF\" width=\"10%\"&gt;&lt;div align=\"right\"&gt;".$employee_firstname . " " . $employee_lastname . "&lt;/div&gt;&lt;/td&gt;";
  
       $even++;
  
  // echo "$even $numDays&lt;br&gt;";
       for ($i = 1; $i &lt;= $numDays; $i++) {
  
          $day = checkDay($employee_num, $i, $month, $year);
  // echo "$employee_num, $i, $month, $year $day&lt;br&gt;";
  
          switch ($day) {
             case 'holiday':
                echo " &lt;td bgcolor=\"#0000FF\"&gt;&lt;/td&gt;";
                break;
             case 'weekend':
                echo " &lt;td bgcolor=\"#999999\"&gt;&lt;/td&gt;";
                break;
             case 'absence_full':
                echo " &lt;td bgcolor=\"#FF0000\"&gt;&lt;/td&gt;";
                break;
             case 'absence_partial_m':
                echo " &lt;td bgcolor=\"#FFFF00\"&gt;&lt;center&gt;M&lt;/center&gt;&lt;/td&gt;";
                break;
             case 'absence_partial_a':
                echo " &lt;td bgcolor=\"#FFFF00\"&gt;&lt;center&gt;A&lt;/center&gt;&lt;/td&gt;";
                break;
             default:
                echo " &lt;td bgcolor=\"##00FF00\"&gt;&lt;/td&gt;";
                break;
          }//switch
       }//for
  
       echo "&lt;/tr&gt;";
    }//while
  
    ?&gt;
  
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;/center&gt;
  &lt;br/&gt;
  &lt;div style="padding-left: 5%"&gt;
  &lt;table width="25%" border="0" cellspacing="1" cellpadding="1"&gt;
  &lt;tr&gt;
  &lt;td bgcolor="#00FF00"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;div align="left" class="style2"&gt;Available&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="11%" bgcolor="#FF0000"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td width="89%"&gt;&lt;div align="left" class="style2"&gt;Absence&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td bgcolor="#CCCCCC"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;div align="left" class="style2"&gt;WeekEnd&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td bgcolor="#0000FF"&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&lt;div align="left" class="style2"&gt;Public Holiday &lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td bgcolor="#FFFF00"&gt;&lt;div align="center"&gt;M&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;div align="left" class="style2"&gt;Partial Absence (Morning) &lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td bgcolor="#FFFF00"&gt;&lt;div align="center"&gt;A&lt;/div&gt;&lt;/td&gt;
  &lt;td&gt;&lt;span class="style2"&gt; Partial Absence (Afternoon) &lt;/span&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;br/&gt;
  &lt;div align="center"&gt; &lt;/div&gt;
  &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>