保留计划插件为orangehrm

时间:2015-03-15 07:40:10

标签: javascript php html orangehrm

我正在使用Orangehrm 3.2.1(最新版本)。下面是我用来为我雇用的员工显示休假计划日历的PHP代码,因为从Orangehrm购买的代价太高。当我运行这个脚本时,我在浏览器上显示了一部分代码....

".$seeDate.""; ?>
Month:      Year:       
".$i."
"; } ?> "; $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 <= $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 ?>

屏幕上显示的代码是我的PHP脚本的一部分。我需要进行任何修改吗?我玩了很多但似乎没有把它弄好。与orangehrm version 2.5相比较的代码已更改,并且已在下面的脚本中使用//标记。

<?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 "<option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\" selected>".$row['(EXTRACT(Year FROM leave_date))']."</option><br>";*/
     echo "<option value=\"".$row['(EXTRACT(Year FROM date))']."\" selected>".$row['(EXTRACT(Year FROM date))']."</option><br>";
  } else {
 //          echo "<option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\">".$row['(EXTRACT(Year FROM leave_date))']."</option><br>";
     echo "<option value=\"".$row['(EXTRACT(Year FROM date))']."\">".$row['(EXTRACT(Year FROM date))']."</option><br>";
  }

}

}//


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 > 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 > 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 > 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<br>";
     return "default";
  } else {
     while ($row = mysql_fetch_array( $result ) ) {
        if ($row['leave_length_days'] < 1.0 ) {
           if ( ($row['start_time'] >= "08:00:00") && ($row['start_time'] <= "09:00:00")  )
              return "absence_partial_m";
           else if ( ($row['start_time'] >= "13:00:00") && ($row['start_time'] <= "18:00:00")  )
              return "absence_partial_a";
        } else
 // echo "full abs<br>";
           return "absence_full";


     }//
  }
}


  $numDays = monthDays($month, $year);
 ?>

 <HTML>
 <HEAD><TITLE>Vacation Plan</TITLE>
 <script type="text/javascript">
 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 + "&year=" + year;

  window.location = URL;

  return false;
 }
 </script>
 <style type="text/css">
 <!--
.style2 {font-size: 12px; }
td{ border:solid 1px red;}
-->
</style>
</HEAD>
<BODY>
<?

?>
<?php if (!empty($logoLink))
echo "<img src='$logoLink'/>";
?>
<center>
<div id="sort" style="padding-right: 10%">
<form id="frmSort" name="frmSort" onsubmit="return sort(this); return false;">
  <?
$seeDate = date("F Y", strtotime($seeDate));
echo "<h2>".$seeDate."</h2>";
?>
  <div align="right">
  <strong>Month</strong>:
  <?php
     $curr_month = $month;

     $auxmonth = array (1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
     $select = "<select name=\"listMonth\">\n";

     foreach ($auxmonth as $key => $val) {
        $select .= "\t<option val=\"".$key."\"";
     if ($key == $curr_month) {
        $select .= " selected>".$val."\n";
     } else {
        $select .= ">".$val."\n";
     }
  }
  echo $select;
 ?>
    </select>
  <img src="img/pixel.gif" width="1" height="1" /><img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" /><img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" /><strong>Year</strong>:
  <select name="listYear" id="listYear">
    <?php getYears($year); ?>
  </select>
  <img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" />
  <input type="submit" name="Submit" value="Select" />
 </form>
 </div>
 <div id="table">
 <table width="90%" border="0" cellspacing="1" cellpadding="1">
 <tr>
  <td >&nbsp;</td>
  <?
   for($i = 1; $i <= $numDays; $i++) {
      echo "<td bgcolor=\"#FFFFFF\" width=\"15\"><div align=\"center\"><strong>".$i."</strong></div></td>";
     }
  ?>
  </tr>
  <?
 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<br>";
   $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 "<tr>";
     if ( $even % 2)
        echo " <td bgcolor=\"#FFFFFF\" width=\"10%\"><div align=\"right\">".$employee_firstname . " " . $employee_lastname . "</div></td>";
     else
        echo " <td bgcolor=\"#FFFFFF\" width=\"10%\"><div align=\"right\">".$employee_firstname . " " . $employee_lastname . "</div></td>";

     $even++;

// echo "$even $numDays<br>";
     for ($i = 1; $i <= $numDays; $i++) {

        $day = checkDay($employee_num, $i, $month, $year);
// echo "$employee_num, $i, $month, $year $day<br>";

        switch ($day) {
           case 'holiday':
              echo " <td bgcolor=\"#0000FF\"></td>";
              break;
           case 'weekend':
              echo " <td bgcolor=\"#999999\"></td>";
              break;
           case 'absence_full':
              echo " <td bgcolor=\"#FF0000\"></td>";
              break;
           case 'absence_partial_m':
              echo " <td bgcolor=\"#FFFF00\"><center>M</center></td>";
              break;
           case 'absence_partial_a':
              echo " <td bgcolor=\"#FFFF00\"><center>A</center></td>";
              break;
           default:
              echo " <td bgcolor=\"##00FF00\"></td>";
              break;
        }//switch
     }//for

     echo "</tr>";
  }//while

  ?>

</table>
</div>
</center>
<br/>
<div style="padding-left: 5%">
<table width="25%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td bgcolor="#00FF00">&nbsp;</td>
<td><div align="left" class="style2">Available</div></td>
</tr>
<tr>
<td width="11%" bgcolor="#FF0000">&nbsp;</td>
<td width="89%"><div align="left" class="style2">Absence</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">&nbsp;</td>
<td><div align="left" class="style2">WeekEnd</div></td>
</tr>
<tr>
<td bgcolor="#0000FF">&nbsp;</td>
<td><div align="left" class="style2">Public Holiday </div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><div align="center">M</div></td>
<td><div align="left" class="style2">Partial Absence (Morning) </div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><div align="center">A</div></td>
<td><span class="style2"> Partial Absence (Afternoon) </span></td>
</tr>
</table>
</div>
<br/>
<div align="center"> </div>
</BODY>
</HTML>

2 个答案:

答案 0 :(得分:0)

感谢您分享代码。 我似乎已经使用3.3了! :)

我没有得到你得到的错误。 尝试在开头添加调试代码:之后

ini_set(&#39; display_errors&#39;,&#39; On&#39;);

我发现全天缺席并没有显示,所以我通过删除编辑了代码 第137行的评论:

    } else

// echo&#34; full abs
&#34 ;;            返回&#34; absence_full&#34 ;;

不知道为什么我不得不以分号离开 - 因此:

    } else
    ;
       return "absence_full";

答案 1 :(得分:0)

如果你要使用<? ?>

,你需要在PHP ini中打开short_tags