Upgraded to latest icehrm core

This commit is contained in:
Thilina Hasantha
2015-12-13 02:56:30 +05:30
parent 8dacf2a8f1
commit ca3492e30e
56 changed files with 1525 additions and 689 deletions

View File

@@ -59,6 +59,11 @@ abstract class AbstractModuleManager{
}
*/
public abstract function setupModuleClassDefinitions();
public function getDashboardItem(){
return null;
}
public function setupRestEndPoints(){

View File

@@ -0,0 +1,218 @@
<?php
abstract class ApproveAdminActionManager extends SubActionManager{
public abstract function getModelClass();
public abstract function getItemName();
public abstract function getModuleName();
public abstract function getModuleTabUrl();
public function changeStatus($req){
$class = $this->getModelClass();
$itemName = $this->getItemName();
$obj = new $class();
$obj->Load("id = ?",array($req->id));
if($obj->id != $req->id){
return new IceResponse(IceResponse::ERROR,"$itemName not found");
}
if($this->user->user_level != 'Admin' && $this->user->user_level != 'Manager'){
return new IceResponse(IceResponse::ERROR,"Only an admin or manager can do this");
}
$oldStatus = $obj->status;
$obj->status = $req->status;
$ok = $obj->Save();
if(!$ok){
LogManager::getInstance()->info($obj->ErrorMsg());
return new IceResponse(IceResponse::ERROR,"Error occurred while saving $itemName information. Please contact admin");
}
$this->baseService->audit(IceConstants::AUDIT_ACTION, "$itemName status changed from:".$oldStatus." to:".$obj->status." id:".$obj->id);
$currentEmpId = $this->getCurrentProfileId();
if(!empty($currentEmpId)){
$employee = $this->baseService->getElement('Employee',$currentEmpId);
$notificationMsg = "Your $itemName has been $obj->status by ".$employee->first_name." ".$employee->last_name;
if(!empty($req->reason)){
$notificationMsg.=" (Note:".$req->reason.")";
}
$this->baseService->notificationManager->addNotification($obj->employee,$notificationMsg,'{"type":"url","url":"'.$this->getModuleTabUrl().'"}',$this->getModuleName(), null, false, true);
}
return new IceResponse(IceResponse::SUCCESS,"");
}
}
abstract class ApproveModuleActionManager extends SubActionManager{
public abstract function getModelClass();
public abstract function getItemName();
public abstract function getModuleName();
public abstract function getModuleTabUrl();
public function cancel($req){
$employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true);
$class = $this->getModelClass();
$itemName = $this->getItemName();
$obj = new $class();
$obj->Load("id = ?",array($req->id));
if($obj->id != $req->id){
return new IceResponse(IceResponse::ERROR,"$itemName record not found");
}
if($this->user->user_level != 'Admin' && $this->getCurrentProfileId() != $obj->employee){
return new IceResponse(IceResponse::ERROR,"Only an admin or owner of the $itemName can do this");
}
if($obj->status != 'Approved'){
return new IceResponse(IceResponse::ERROR,"Only an approved $itemName can be cancelled");
}
$obj->status = 'Cancellation Requested';
$ok = $obj->Save();
if(!$ok){
LogManager::getInstance()->error("Error occurred while cancelling the $itemName:".$obj->ErrorMsg());
return new IceResponse(IceResponse::ERROR,"Error occurred while cancelling the $itemName. Please contact admin.");
}
$this->baseService->audit(IceConstants::AUDIT_ACTION, "Expense cancellation | start:".$obj->date_start."| end:".$obj->date_end);
$notificationMsg = $employee->first_name." ".$employee->last_name." cancelled a expense. Visit expense management module to approve";
$this->baseService->notificationManager->addNotification($employee->supervisor,$notificationMsg,'{"type":"url","url":"'.$this->getModuleTabUrl().'"}',
$this->getModuleTabUrl(), null, false, true);
return new IceResponse(IceResponse::SUCCESS,$obj);
}
}
class ApproveModel extends ICEHRM_Record {
public function executePreSaveActions($obj){
$preApprove = SettingsManager::getInstance()->getSetting($this->preApproveSettingName);
$sendNotificationEmail = true;
if(empty($obj->status)){
if($preApprove == "1"){
$obj->status = "Approved";
$sendNotificationEmail = false;
}else{
$obj->status = "Pending";
}
}
if($preApprove){
return new IceResponse(IceResponse::SUCCESS,$obj);
}
$currentEmpId = BaseService::getInstance()->getCurrentProfileId();
//Auto approve if the current user is an admin
if(!empty($currentEmpId)){
$employee = BaseService::getInstance()->getElement('Employee',$currentEmpId);
if(!empty($employee->supervisor)) {
$notificationMsg = "A new ".$this->notificationUnitName." has been added by " . $employee->first_name . " " . $employee->last_name . ". Please visit ".$this->notificationModuleName." module to review it";
BaseService::getInstance()->notificationManager->addNotification($employee->supervisor, $notificationMsg, '{"type":"url","url":"'.$this->notificationUnitAdminUrl.'"}', $this->notificationModuleName, null, false, $sendNotificationEmail);
}else{
$user = BaseService::getInstance()->getCurrentUser();
if($user->user_level == "Admin"){
//Auto approve
$obj->status = "Approved";
$notificationMsg = "Your ".$this->notificationUnitName." is auto approved since you are an administrator and do not have any supervisor assigned";
BaseService::getInstance()->notificationManager->addNotification(null, $notificationMsg, '{"type":"url","url":"'.$this->notificationUnitAdminUrl.'"}', $this->notificationModuleName, $user->id, false, $sendNotificationEmail);
}else{
//If the user do not have a supervisor, notify all admins
$admins = BaseService::getInstance()->getAllAdmins();
foreach($admins as $admin){
$notificationMsg = "A new ".$this->notificationUnitName." has been added by " . $employee->first_name . " " . $employee->last_name . ". Please visit ".$this->notificationModuleName." module to review it. You are getting this notification since you are an administrator and the user do not have any supervisor assigned.";
BaseService::getInstance()->notificationManager->addNotification(null, $notificationMsg, '{"type":"url","url":"'.$this->notificationUnitAdminUrl.'"}', $this->notificationModuleName, $admin->id, false, $sendNotificationEmail);
}
}
}
}
return new IceResponse(IceResponse::SUCCESS,$obj);
}
public function executePreUpdateActions($obj){
$preApprove = SettingsManager::getInstance()->getSetting($this->preApproveSettingName);
$sendNotificationEmail = true;
$fieldsToCheck = $this->fieldsNeedToBeApproved();
$travelRequest = new EmployeeTravelRecord();
$travelRequest->Load('id = ?',array($obj->id));
$needToApprove = false;
if($preApprove != "1"){
foreach($fieldsToCheck as $field){
if($obj->$field != $travelRequest->$field) {
$needToApprove = true;
break;
}
}
}else{
$sendNotificationEmail = false;
}
if($preApprove){
return new IceResponse(IceResponse::SUCCESS,$obj);
}
if($needToApprove && $obj->status != 'Pending'){
$currentEmpId = BaseService::getInstance()->getCurrentProfileId();
//Auto approve if the current user is an admin
if(!empty($currentEmpId)){
$employee = BaseService::getInstance()->getElement('Employee',$currentEmpId);
if(!empty($employee->supervisor)) {
$notificationMsg = $this->notificationUnitPrefix." ".$this->notificationUnitName." has been updated by " . $employee->first_name . " " . $employee->last_name . ". Please visit ".$this->notificationModuleName." module to review it";
BaseService::getInstance()->notificationManager->addNotification($employee->supervisor, $notificationMsg, '{"type":"url","url":"'.$this->notificationUnitAdminUrl.'"}', $this->notificationModuleName, null, false, $sendNotificationEmail);
}else{
$user = BaseService::getInstance()->getCurrentUser();
if($user->user_level == "Admin"){
}else{
//If the user do not have a supervisor, notify all admins
$admins = BaseService::getInstance()->getAllAdmins();
foreach($admins as $admin){
$notificationMsg = $this->notificationUnitPrefix." ".$this->notificationUnitName." request has been updated by " . $employee->first_name . " " . $employee->last_name . ". Please visit ".$this->notificationModuleName." module to review it. You are getting this notification since you are an administrator and the user do not have any supervisor assigned.";
BaseService::getInstance()->notificationManager->addNotification(null, $notificationMsg, '{"type":"url","url":"g=admin&n=travel&m=admin_Employees"}', "Travel Module", $admin->id, false, $sendNotificationEmail);
}
}
}
}
}
return new IceResponse(IceResponse::SUCCESS,$obj);
}
}

View File

@@ -1103,6 +1103,30 @@ class BaseService{
$data = $customField->Find("type = ?",array($type));
return $data;
}
public function getAllAdmins(){
$user = new User();
$admins = $user->Find('user_level = ?',array('Admin'));
return $admins;
}
public function getCurrentEmployeeTimeZone(){
$cemp = $this->getCurrentProfileId();
if(empty($cemp)){
return NULL;
}
$emp = new Employee();
$emp->Load("id = ?",array($cemp));
if(empty($emp->id) || empty($emp->department)){
return NULL;
}
$dept = new CompanyStructure();
$dept->Load("id = ?",array($emp->department));
return $dept->timezone;
}
}
class IceConstants{

View File

@@ -6,7 +6,7 @@ class CronUtils{
private static $me = null;
private function __construct($clientBasePath, $cronFile){
$this->clientBasePath = $clientBasePath;
$this->clientBasePath = $clientBasePath."/";
$this->cronFile = $cronFile;
}
@@ -20,14 +20,178 @@ class CronUtils{
public function run(){
$ams = scandir($this->clientBasePath);
$count = 0;
foreach($ams as $am){
if(is_dir($this->clientBasePath.$am) && $am != '.' && $am != '..'){
$command = "php ".$this->cronFile." -c".$this->clientBasePath.$am;
//$command = "php ".$this->cronFile." -c".$this->clientBasePath.$am;
$command = "php ".$this->clientBasePath.$am."/".$this->cronFile;
echo "Run:".$command."\r\n";
passthru($command, $res);
echo "Result :".$res."\r\n";
$count++;
if($count > 25){
sleep(1);
$count = 0;
}
}
}
}
}
}
class IceCron{
const MINUTELY = "Minutely";
const HOURLY = "Hourly";
const DAILY = "Daily";
const WEEKLY = "Weekly";
const MONTHLY = "Monthly";
const YEARLY = "Yearly";
private $cron;
public function __construct($cron){
$this->cron = $cron;
}
public function isRunNow(){
LogManager::getInstance()->debug("Cron ".print_r($this->cron,true));
$lastRunTime = $this->cron->lastrun;
if(empty($lastRunTime)){
LogManager::getInstance()->debug("Cron ".$this->cron->name." is running since last run time is empty");
return true;
}
$type = $this->cron->type;
$frequency = intval($this->cron->frequency);
$time = intval($this->cron->time);
if(empty($frequency) || !is_int($frequency)){
LogManager::getInstance()->debug("Cron ".$this->cron->name." is not running since frequency is not an integer");
return false;
}
if($type == self::MINUTELY){
$diff = (strtotime("now") - strtotime($lastRunTime));
if(empty($this->time) || !is_int($time)){
if($diff > 60){
return true;
}
}else{
if($diff > 60 * $time){
return true;
}
}
}else if($type == self::HOURLY){
if(empty($time) || !is_int($time)){
if(date('H') != date('H',strtotime($lastRunTime))){
return true;
}
}else{
if(intval(date('m')) <= intval($time) && date('H') != date('H',strtotime($lastRunTime))){
return true;
}
}
}else if($type == self::DAILY){
if(empty($time) || !is_int($time)){
if(date('d') != date('d',strtotime($lastRunTime))){
return true;
}
}else{
if(intval(date('H')) <= intval($time) && date('d') != date('d',strtotime($lastRunTime))){
return true;
}
}
}else if($type == self::MONTHLY){
if(empty($time) || !is_int($time)){
if(date('m') != date('m',strtotime($lastRunTime))){
return true;
}
}else{
if(intval(date('d')) <= intval($time) && date('m') != date('m',strtotime($lastRunTime))){
return true;
}
}
}else if($type == self::YEARLY){
if(empty($time) || !is_int($time)){
if(date('Y') != date('Y',strtotime($lastRunTime))){
return true;
}
}else{
if(intval(date('m')) <= intval($time) && date('Y') != date('Y',strtotime($lastRunTime))){
return true;
}
}
}
return false;
}
public function execute(){
$class = $this->cron->class;
$obj = new $class();
$obj->execute($this->cron);
$this->cronCompleted();
}
private function cronCompleted(){
$this->cron->lastrun = date("Y-m-d H:i:s");
$ok = $this->cron->Save();
if(!$ok){
LogManager::getInstance()->error("Error saving cron due to :".$this->cron->ErrorMsg());
}
}
}
interface IceTask{
public function execute($cron);
}
abstract class EmailIceTask implements IceTask{
public abstract function execute($cron);
public function sendEmployeeEmails($emailList, $subject){
foreach($emailList as $employeeId => $emailData){
$ccList = array();
if(SettingsManager::getInstance()->getSetting('Notifications: Copy Document Expiry Emails to Manager') == '1'){
$employee = new Employee();
$employee->Load("id = ?",array($employeeId));
if(!empty($employee->supervisor)){
$supperuser = BaseService::getInstance()->getUserFromProfileId($employee->supervisor);
if(!empty($supperuser)){
$ccList[] = $supperuser->email;
}
}
}
$user = BaseService::getInstance()->getUserFromProfileId($employeeId);
if(!empty($user) && !empty($user->email)){
$email = new IceEmail();
$email->subject = $subject;
$email->toEmail = $user->email;
$email->template = $emailData;
$email->params = '[]';
$email->cclist = json_encode($ccList);
$email->bcclist = '[]';
$email->status = 'Pending';
$email->created = date('Y-m-d H:i:s');
$email->updated = date('Y-m-d H:i:s');
$ok = $email->Save();
if(!$ok){
LogManager::getInstance()->error("Error Saving Email: ".$email->ErrorMsg());
}
}
}
}
}

View File

@@ -13,6 +13,56 @@ abstract class EmailSender{
$this->settings = $settings;
}
public function sendEmailFromNotification($notification){
$toEmail = null;
$user = new User();
$user->Load("id = ?",array($notification->toUser));
if(!empty($user->email)){
$name = "User";
$employee = new Employee();
$employee->Load("id = ?",array($user->employee));
if($employee->id == $user->employee && !empty($employee->id)){
$name = $employee->first_name;
}
$action = json_decode($notification->action);
$emailBody = file_get_contents(APP_BASE_PATH.'/templates/email/notificationEmail.html');
$emailBody = str_replace("#_user_#", $name, $emailBody);
$emailBody = str_replace("#_message_#", $notification->message, $emailBody);
if($action->type == "url"){
$emailBody = str_replace("#_url_#", CLIENT_BASE_URL."?".$action->url, $emailBody);
}
$this->sendEmail('IceHrm Notification from '.$notification->type,
$user->email,
$emailBody,
array(),
array(),
array()
);
}
}
public function sendEmailFromDB($email){
$params = array();
if(!empty($email->params)){
$params = json_decode($email->params, true);
}
$cclist = array();
if(!empty($email->cclist)){
$cclist = json_decode($email->cclist, true);
}
$bcclist = array();
if(!empty($email->bcclist)){
$bcclist = json_decode($email->bcclist, true);
}
$resp = $this->sendEmail($email->subject, $email->toEmail, $email->template, $params, $cclist, $bcclist);
}
public function sendEmail($subject, $toEmail, $template, $params, $ccList = array(), $bccList = array()){
$body = $template;
@@ -225,7 +275,7 @@ class SMTPEmailSender extends EmailSender{
$mail = $smtp->send($toEmail, $headers, $body);
return true;
return $mail;
}
}
@@ -255,6 +305,6 @@ class PHPMailer extends EmailSender{
LogManager::getInstance()->info("PHP mailer result : ".$res);
return true;
return $res;
}
}

View File

@@ -12,8 +12,8 @@ class ReportHandler{
return $this->executeReport($report,$query,$where[1]);
}else if($report->type == 'Class'){
$className = $report->query;
include MODULE_PATH.'/reportClasses/ReportBuilder.php';
include MODULE_PATH.'/reportClasses/'.$className.".php";
include APP_BASE_PATH.'admin/reports/reportClasses/ReportBuilder.php';
include APP_BASE_PATH.'admin/reports/reportClasses/'.$className.".php";
$cls = new $className();
$data = $cls->getData($report,$request);
return $this->generateReport($report,$data);

View File

@@ -153,10 +153,27 @@ class UIManager{
}
if($this->user->user_level == "Admin"){
$reg = '';
$num = '';
if(class_exists('ProVersion')){
$pro = new ProVersion();
if(!empty($pro->employeeLimit)){
$num = "<br/>Employee Limit: ".$pro->employeeLimit;
}
if(method_exists($pro,'getRegisteredTo')){
$reg = "<br/>Registered To: ".$pro->getRegisteredTo();
}
}
$manuItems[] = new MenuItemTemplate('menuButtonHelp', array(
"APP_NAME"=>APP_NAME,
"VERSION"=>VERSION,
"VERSION_DATE"=>VERSION_DATE
"VERSION_DATE"=>VERSION_DATE,
"REG"=>$reg,
"NUM"=>$num
));
}
@@ -199,6 +216,23 @@ class UIManager{
return $str;
}
public function getCompanyLogoUrl(){
$logoFileSet = false;
$logoFileName = CLIENT_BASE_PATH."data/logo.png";
$logoSettings = SettingsManager::getInstance()->getSetting("Company: Logo");
if(!empty($logoSettings)){
$logoFileName = FileService::getInstance()->getFileUrl($logoSettings);
$logoFileSet = true;
}
if(!$logoFileSet && !file_exists($logoFileName)){
return BASE_URL."images/logo.png";
}
return $logoFileName;
}
}