protected function execute($report, $query, $parameters) { //var_dump($query); //return; $report->DB()->SetFetchMode(ADODB_FETCH_ASSOC); LogManager::getInstance()->debug("Query: " . $query); LogManager::getInstance()->debug("Parameters: " . json_encode($parameters)); $rs = $report->DB()->Execute($query, $parameters); if (!$rs) { LogManager::getInstance()->info($report->DB()->ErrorMsg()); return array("ERROR", "Error generating report"); } $reportNamesFilled = false; $columnNames = array(); $reportData = array(); foreach ($rs as $rowId => $row) { $reportData[] = array(); if (!$reportNamesFilled) { $countIt = 0; foreach ($row as $name => $value) { $countIt++; $columnNames[$countIt] = $name; $reportData[count($reportData) - 1][] = $value; } $reportNamesFilled = true; } else { foreach ($row as $name => $value) { $reportData[count($reportData) - 1][] = $this->transformData($name, $value); } } } array_unshift($reportData, $columnNames); return $reportData; }
public function getWhereQuery($request) { $employeeList = array(); if (!empty($request['employee'])) { $employeeList = json_decode($request['employee'], true); } if (in_array("NULL", $employeeList)) { $employeeList = array(); } if (!empty($employeeList) && ($request['project'] != "NULL" && !empty($request['project']))) { $query = "where employee in (" . implode(",", $employeeList) . ") and date_start >= ? and date_end <= ? and project = ?;"; $params = array($request['date_start'], $request['date_end'], $request['project']); } else { if (!empty($employeeList)) { $query = "where employee in (" . implode(",", $employeeList) . ") and date_start >= ? and date_end <= ?;"; $params = array($request['date_start'], $request['date_end']); } else { if ($request['project'] != "NULL" && !empty($request['project'])) { $query = "where project = ? and date_start >= ? and date_end <= ?;"; $params = array($request['project'], $request['date_start'], $request['date_end']); } else { $query = "where date_start >= ? and date_end <= ?;"; $params = array($request['date_start'], $request['date_end']); } } } LogManager::getInstance()->info("Query:" . $query); LogManager::getInstance()->info("Params:" . json_encode($params)); return array($query, $params); }
public function getLeavesForMeAndSubordinates($req) { $map = json_decode('{"employee":["Employee","id","first_name+last_name"],"leave_type":["LeaveType","id","name"]}'); $employee = $this->baseService->getElement('Employee', $this->getCurrentProfileId(), null, true); $employeeLeave = new EmployeeLeave(); $startDate = date("Y-m-d H:i:s", $req->start); $endDate = date("Y-m-d H:i:s", $req->end); $list = $employeeLeave->Find("status in ('Approved','Pending') and ((date_start >= ? and date_start <= ? ) or (date_end >= ? and date_end <= ?))", array($startDate, $endDate, $startDate, $endDate)); if (!$list) { LogManager::getInstance()->info($employeeLeave->ErrorMsg()); } if (!empty($map)) { $list = $this->baseService->populateMapping($list, $map); } $data = array(); $leaveType = new LeaveType(); $leaveTypesTemp = $leaveType->Find("1=1"); $leaveTypes = array(); foreach ($leaveTypesTemp as $leaveType) { $leaveTypes[$leaveType->name] = $leaveType; } foreach ($list as $leave) { $data[] = $this->leaveToEvent($leave, $leaveTypes); } $holiday = new HoliDay(); $holidays = $holiday->Find("1=1", array()); foreach ($holidays as $holiday) { $data[] = $this->holidayToEvent($holiday); } echo json_encode($data); exit; }
public function getChildCompanyStuctures($companyStructId) { $childIds = array(); $childIds[] = $companyStructId; $nodeIdsAtLastLevel = $childIds; $count = 0; do { $count++; $companyStructTemp = new CompanyStructure(); if (empty($nodeIdsAtLastLevel) || empty($childIds)) { break; } $idQuery = "parent in (" . implode(",", $nodeIdsAtLastLevel) . ") and id not in(" . implode(",", $childIds) . ")"; LogManager::getInstance()->debug($idQuery); $list = $companyStructTemp->Find($idQuery, array()); if (!$list) { LogManager::getInstance()->debug($companyStructTemp->ErrorMsg()); } $nodeIdsAtLastLevel = array(); foreach ($list as $item) { $childIds[] = $item->id; $nodeIdsAtLastLevel[] = $item->id; } } while (count($list) > 0 && $count < 10); return $childIds; }
public function sendWelcomeUserEmail($user, $password, $profile = NULL) { $params = array(); if (!empty($profile)) { $params['name'] = $profile->first_name . " " . $profile->last_name; } else { $params['name'] = $user->username; } $params['url'] = CLIENT_BASE_URL; $params['password'] = $password; $params['email'] = $user->email; $params['username'] = $user->username; $email = $this->subActionManager->getEmailTemplate('welcomeUser.html'); $emailTo = null; if (!empty($user)) { $emailTo = $user->email; } if (!empty($emailTo)) { if (!empty($this->emailSender)) { LogManager::getInstance()->info("[sendWelcomeUserEmail] sending email to {$emailTo} : " . $email); $this->emailSender->sendEmail("Your IceHrm account is ready", $emailTo, $email, $params); } } else { LogManager::getInstance()->info("[sendWelcomeUserEmail] email is empty"); } }
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); }
public function init() { //Add Employee time sheets if it is not already created for current week $empId = $this->getCurrentProfileId(); if (date('w', strtotime("now")) == 0) { $start = date("Y-m-d", strtotime("now")); } else { $start = date("Y-m-d", strtotime("last Sunday")); } if (date('w', strtotime("now")) == 6) { $end = date("Y-m-d", strtotime("now")); } else { $end = date("Y-m-d", strtotime("next Saturday")); } $timeSheet = new EmployeeTimeSheet(); $timeSheet->Load("employee = ? and date_start = ? and date_end = ?", array($empId, $start, $end)); if ($timeSheet->date_start == $start && $timeSheet->employee == $empId) { } else { if (!empty($empId)) { $timeSheet->employee = $empId; $timeSheet->date_start = $start; $timeSheet->date_end = $end; $timeSheet->status = "Pending"; $ok = $timeSheet->Save(); if (!$ok) { LogManager::getInstance()->info("Error creating time sheet : " . $timeSheet->ErrorMsg()); } } } //Generate missing timesheets }
public function getLeavesForMeAndSubordinates($req){ $shareCalendar = $this->baseService->settingsManager->getSetting("Leave: Share Calendar to Whole Company"); $map = json_decode('{"employee":["Employee","id","first_name+last_name"],"leave_type":["LeaveType","id","name"]}'); $employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true); if($shareCalendar != "1"){ $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?",array($employee->id)); $subordinatesIds = $employee->id; foreach($subordinates as $sub){ if($subordinatesIds != ""){ $subordinatesIds.=","; } $subordinatesIds.=$sub->id; } $employeeLeave = new EmployeeLeave(); $startDate = date("Y-m-d H:i:s",$req->start); $endDate = date("Y-m-d H:i:s",$req->end); $list = $employeeLeave->Find("employee in (".$subordinatesIds.") and status in ('Approved','Pending') and ((date_start >= ? and date_start <= ? ) or (date_end >= ? and date_end <= ?))",array($startDate,$endDate,$startDate,$endDate)); }else{ $employeeLeave = new EmployeeLeave(); $startDate = date("Y-m-d H:i:s",$req->start); $endDate = date("Y-m-d H:i:s",$req->end); $list = $employeeLeave->Find("status in ('Approved','Pending') and ((date_start >= ? and date_start <= ? ) or (date_end >= ? and date_end <= ?))",array($startDate,$endDate,$startDate,$endDate)); } if(!$list){ LogManager::getInstance()->info($employeeLeave->ErrorMsg()); } if(!empty($map)){ $list = $this->baseService->populateMapping($list,$map); } $data = array(); foreach($list as $leave){ $data[] = $this->leaveToEvent($leave); } $holiday = new HoliDay(); $holidays = $holiday->Find("1=1",array()); foreach($holidays as $holiday){ $data[] = $this->holidayToEvent($holiday); } echo json_encode($data); exit(); }
public function init() { if (SettingsManager::getInstance()->getSetting("Api: REST Api Enabled") == "1") { $user = BaseService::getInstance()->getCurrentUser(); $dbUser = new User(); $dbUser->Load("id = ?", array($user->id)); $resp = RestApiManager::getInstance()->getAccessTokenForUser($dbUser); if ($resp->getStatus() != IceResponse::SUCCESS) { LogManager::getInstance()->error("Error occured while creating REST Api acces token for " . $user->username); } } }
function debug($message, $file = null, $line = null) { $logManager =& LogManager::getInstance(); $logger = $logManager->getLogger('debuglogger'); $options = array('m' => $message, 'N' => 'DEBUG', 'p' => LEVEL_DEBUG); if ($file) { $options['f'] = $file; } if ($line) { $options['l'] = $line; } $message =& new Message($options); $logger->log($message); }
public function deleteObject($bucket, $key) { $res = null; try { $res = $this->s3->deleteObject(array('Bucket' => $bucket, 'Key' => $key)); } catch (Exception $e) { LogManager::getInstance()->info($e->getMessage()); return NULL; } LogManager::getInstance()->info("Response from s3:" . print_r($res, true)); $result = $res->get('RequestId'); if (!empty($result)) { return $result; } return NULL; }
public function execute($cron) { $email = new IceEmail(); $emails = $email->Find("status = ? limit 10", array('Pending')); $emailSender = BaseService::getInstance()->getEmailSender(); foreach ($emails as $email) { try { $emailSender->sendEmailFromDB($email); } catch (Exception $e) { LogManager::getInstance()->error("Error sending email:" . $e->getMessage()); } $email->status = 'Sent'; $email->updated = date('Y-m-d H:i:s'); $email->Save(); } }
/** * Default Error Handler. This will be called with the following params * * @param $dbms the RDBMS you are connecting to * @param $fn the name of the calling function (in uppercase) * @param $errno the native error number from the database * @param $errmsg the native error msg from the database * @param $p1 $fn specific parameter - see below * @param $p2 $fn specific parameter - see below * @param $thisConn $current connection object - can be false if no connection object created */ function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection) { if (error_reporting() == 0) { return; } // obey @ protocol switch ($fn) { case 'EXECUTE': $sql = $p1; $inputparams = $p2; $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}(\"{$sql}\")\n"; break; case 'PCONNECT': case 'CONNECT': $host = $p1; $database = $p2; $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}({$host}, '****', '****', {$database})\n"; break; default: $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}({$p1}, {$p2})\n"; break; } /* * Log connection error somewhere * 0 message is sent to PHP's system logger, using the Operating System's system * logging mechanism or a file, depending on what the error_log configuration * directive is set to. * 1 message is sent by email to the address in the destination parameter. * This is the only message type where the fourth parameter, extra_headers is used. * This message type uses the same internal function as mail() does. * 2 message is sent through the PHP debugging connection. * This option is only available if remote debugging has been enabled. * In this case, the destination parameter specifies the host name or IP address * and optionally, port number, of the socket receiving the debug information. * 3 message is appended to the file destination */ if (defined('ADODB_ERROR_LOG_TYPE')) { $t = date('Y-m-d H:i:s'); if (defined('ADODB_ERROR_LOG_DEST')) { LogManager::getInstance()->info("({$t}) {$s}", ADODB_ERROR_LOG_TYPE, ADODB_ERROR_LOG_DEST); } else { LogManager::getInstance()->info("({$t}) {$s}", ADODB_ERROR_LOG_TYPE); } } //print "<p>$s</p>"; trigger_error($s, ADODB_ERROR_HANDLER_TYPE); }
public function saveUser($req) { $profileVar = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME; $profileClass = ucfirst(SIGN_IN_ELEMENT_MAPPING_FIELD_NAME); if ($this->user->user_level == 'Admin') { $user = new User(); $user->Load("email = ?", array($req->email)); if ($user->email == $req->email) { return new IceResponse(IceResponse::ERROR, "User with same email already exists"); } $user->Load("username = ?", array($req->username)); if ($user->username == $req->username) { return new IceResponse(IceResponse::ERROR, "User with same username already exists"); } $user = new User(); $user->email = $req->email; $user->username = $req->username; $password = $this->generateRandomString(6); $user->password = md5($password); $user->profile = empty($req->profile) || $req->profile == "NULL" ? NULL : $req->profile; $user->user_level = $req->user_level; $user->last_login = date("Y-m-d H:i:s"); $user->last_update = date("Y-m-d H:i:s"); $user->created = date("Y-m-d H:i:s"); $profile = null; if (!empty($user->profile)) { $profile = $this->baseService->getElement($profileClass, $user->profile, null, true); } $ok = $user->Save(); if (!$ok) { LogManager::getInstance()->info($user->ErrorMsg() . "|" . json_encode($user)); return new IceResponse(IceResponse::ERROR, "Error occured while saving the user"); } $user->password = ""; $user = $this->baseService->cleanUpAdoDB($user); if (!empty($this->emailSender)) { $usersEmailSender = new UsersEmailSender($this->emailSender, $this); $usersEmailSender->sendWelcomeUserEmail($user, $password, $profile); } return new IceResponse(IceResponse::SUCCESS, $user); } return new IceResponse(IceResponse::ERROR, "Not Allowed"); }
public function addAudit($type, $data) { $audit = new Audit(); $audit->user = $this->user->id; $audit->ip = $_SERVER['REMOTE_ADDR']; $audit->time = date("Y-m-d H:i:s"); $audit->time = gmdate('Y-m-d H:i:s', strtotime($audit->time)); $audit->type = $type; $audit->details = $data; $currentEmpId = $this->getCurrentProfileId(); if (!empty($currentEmpId)) { $employee = $this->baseService->getElement('Employee', $this->getCurrentProfileId(), null, true); $audit->employee = $employee->first_name . " " . $employee->last_name . " [EmpId = " . $employee->employee_id . "]"; } $ok = $audit->Save(); if (!$ok) { LogManager::getInstance()->info("Error adding audit:" . $audit->ErrorMsg()); } }
function showIndex() { $filter = fvSite::$fvSession->get(fvRequest::getInstance()->getRequestParameter("requestURL") . "/filter"); $query = null; $params = array(); if (is_array($filter)) { if (!empty($filter['object_name'])) { $query .= ($query ? " AND " : '') . "object_name LIKE ?"; $params[] = '%' . $filter['object_name'] . "%"; $this->__assign('filter_object_name', $filter['object_name']); } if (!empty($filter['date_from'])) { $query .= ($query ? " AND " : '') . "date >= ?"; $params[] = $filter['date_from']; $this->__assign('filter_date_from', $filter['date_from']); } if (!empty($filter['date_to'])) { $query .= ($query ? " AND " : '') . "date <= ?"; $params[] = $filter['date_to']; $this->__assign('filter_date_to', $filter['date_to']); } if (!empty($filter['message'])) { $query .= ($query ? " AND " : '') . "message LIKE ?"; $params[] = '%' . $filter['message'] . '%'; $this->__assign('filter_message', $filter['message']); } if (!empty($filter['operation'])) { $query .= ($query ? " AND " : '') . "operation = ?"; $params[] = $filter['operation']; $this->__assign('filter_operation', $filter['operation']); } if (!empty($filter['manager_id'])) { $query .= ($query ? " AND " : '') . "manager_id = ?"; $params[] = $filter['manager_id']; $this->__assign('filter_manager_id', $filter['manager_id']); } } $pager = new fvPager(LogManager::getInstance()); $this->__assign('Logs', $pager->paginate($query, "date DESC", $params)); $this->__assign('UserManager', UserManager::getInstance()); return $this->__display('log_list.tpl'); }
public function getWhereQuery($request) { $employeeList = array(); if (!empty($request['employee'])) { $employeeList = json_decode($request['employee'], true); } if (in_array("NULL", $employeeList)) { $employeeList = array(); } if (!empty($employeeList)) { $query = "where employee in (" . implode(",", $employeeList) . ") and in_time >= ? and out_time <= ? order by in_time desc;"; $params = array($request['date_start'] . " 00:00:00", $request['date_end'] . " 23:59:59"); } else { $query = "where in_time >= ? and out_time <= ? order by in_time desc;"; $params = array($request['date_start'] . " 00:00:00", $request['date_end'] . " 23:59:59"); } LogManager::getInstance()->info("Query:" . $query); LogManager::getInstance()->info("Params:" . json_encode($params)); return array($query, $params); }
public function getData($report, $request) { $employeeCache = array(); $employeeList = array(); if (!empty($request['employee'])) { $employeeList = json_decode($request['employee'], true); } if (in_array("NULL", $employeeList)) { $employeeList = array(); } $employee_query = ""; if (!empty($employeeList)) { $employee_query = "employee in (" . implode(",", $employeeList) . ") and "; } $timeSheet = new EmployeeTimeSheet(); if ($request['status'] != "NULL") { $timeSheets = $timeSheet->Find($employee_query . "status = ? and date_start >= ? and date_end <= ?", array($request['status'], $request['date_start'], $request['date_end'])); } else { $timeSheets = $timeSheet->Find($employee_query . "date_start >= ? and date_end <= ?", array($request['date_start'], $request['date_end'])); } if (!$timeSheets) { LogManager::getInstance()->info($timeSheet->ErrorMsg()); } $reportData = array(); $reportData[] = array("Employee ID", "Employee", "Name", "Start", "End", "Total Time", "Status"); foreach ($timeSheets as $ts) { $employee = $employeeCache[$ts->employee]; if (empty($employee)) { $employee = new Employee(); $employee->Load("id = ?", array($ts->employee)); if (empty($employee->id)) { continue; } $employeeCache[$employee->id] = $employee; } $reportData[] = array($employee->employee_id, $employee->first_name . " " . $employee->last_name, date("F j, Y", strtotime($ts->date_start)) . " - " . date("F j, Y", strtotime($ts->date_end)), $ts->date_start, $ts->date_end, $ts->getTotalTime(), $ts->status); } return $reportData; }
/** * Returns array('success'=>1) or array('error'=>'error message') */ function handleUpload($uploadDirectory, $saveFileName, $replaceOldFile = FALSE) { if (!is_writable($uploadDirectory)) { return array('success' => 0, 'error' => "Server error. Upload directory ({$uploadDirectory}) is not writable"); } if (!$this->file) { return array('success' => 0, 'error' => 'No files were uploaded.'); } $size = $this->file->getSize(); LogManager::getInstance()->info('file size =' . $size); LogManager::getInstance()->info('file size limit =' . $this->sizeLimit); if ($size == 0) { return array('success' => 0, 'error' => 'File is empty'); } if ($size > $this->sizeLimit) { return array('success' => 0, 'error' => 'File is too large'); } $pathinfo = pathinfo($this->file->getName()); $filename = $pathinfo['filename']; //$filename = md5(uniqid()); $ext = $pathinfo['extension']; if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) { $these = implode(', ', $this->allowedExtensions); return array('success' => 0, 'error' => 'File has an invalid extension, it should be one of ' . $these . '.'); } //$filename .= microtime(true); $filename = $saveFileName; // file with only name $saveFileName = $saveFileName . '.' . strtolower($ext); // file with extention $final_img_location = $uploadDirectory . $saveFileName; if ($this->file->save($final_img_location)) { $arr = explode("/", $final_img_location); return array('success' => 1, 'filename' => $arr[count($arr) - 1], 'error' => ''); } else { return array('success' => 0, 'error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered'); } }
public function addNotification($toUser, $message, $action, $type) { $profileVar = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME; $profileClass = ucfirst(SIGN_IN_ELEMENT_MAPPING_FIELD_NAME); $userEmp = new User(); $userEmp->load("profile = ?", array($toUser)); if (!empty($userEmp->{$profileVar}) && $userEmp->{$profileVar} == $toUser) { $toUser = $userEmp->id; } else { return; } $noti = new Notification(); $user = $this->baseService->getCurrentUser(); $noti->fromUser = $user->id; $noti->fromProfile = $user->{$profileVar}; $noti->toUser = $toUser; $noti->message = $message; if (!empty($noti->fromProfile)) { $profile = $this->baseService->getElement($profileClass, $noti->fromProfile, null, true); if (!empty($profile)) { $fs = new FileService(); $profile = $fs->updateProfileImage($profile); $noti->image = $profile->image; } } if (empty($noti->image)) { $noti->image = BASE_URL . "images/user_male.png"; } $noti->action = $action; $noti->type = $type; $noti->time = date('Y-m-d H:i:s'); $noti->status = 'Unread'; $ok = $noti->Save(); if (!$ok) { LogManager::getInstance()->info("Error adding notification: " . $noti->ErrorMsg()); } }
public function deleteElement($table, $id) { $fileFields = $this->fileFields; $ele = new $table(); $ele->Load('id = ?', array($id)); $this->checkSecureAccess("delete", $ele); if (isset($this->nonDeletables[$table])) { $nonDeletableTable = $this->nonDeletables[$table]; if (!empty($nonDeletableTable)) { foreach ($nonDeletableTable as $field => $value) { if ($ele->{$field} == $value) { return "This item can not be deleted"; } } } } $ok = $ele->Delete(); if (!$ok) { $error = $ele->ErrorMsg(); LogManager::getInstance()->info($error); return $this->findError($error); } else { //Backup if ($table == "Profile") { $newObj = $this->cleanUpAdoDB($ele); $dataEntryBackup = new DataEntryBackup(); $dataEntryBackup->tableType = $table; $dataEntryBackup->data = json_encode($newObj); $dataEntryBackup->Save(); } $this->audit(IceConstants::AUDIT_DELETE, "Deleted an object in " . $table . " [id:" . $ele->id . "]"); } if (isset($fileFields[$table])) { foreach ($fileFields[$table] as $k => $v) { if (!empty($ele->{$k})) { FileService::getInstance()->deleteFileByField($ele->{$k}, $v); } } } return null; }
/** * Get associative array of by retriving data from $table using $key field ans key and $value field as value. Mainly used for getting data for populating option lists of select boxes when adding and editing items * @method getFieldValues * @param $table {String} model class name of the table to get data (e.g for Users table model class name is User) * @param $key {String} key field name * @param $value {String} value field name (multiple fileds cam be concatinated using +) - e.g first_name+last_name * @param $method {String} if not empty, use this menthod to get only a selected set of objects from db instead of retriving all objects. This method should be defined in class $table and should return an array of objects of type $table * @return {Array} associative array */ public function getFieldValues($table, $key, $value, $method, $methodParams = NULL) { $values = explode("+", $value); $ret = array(); $ele = new $table(); if (!empty($method)) { LogManager::getInstance()->debug("Call method for getFieldValues:" . $method); LogManager::getInstance()->debug("Call method params for getFieldValues:" . json_decode($methodParams)); if (method_exists($ele, $method)) { if (!empty($methodParams)) { $list = $ele->{$method}(json_decode($methodParams)); } else { $list = $ele->{$method}(array()); } } else { LogManager::getInstance()->debug("Could not find method:" . $method . " in Class:" . $table); $list = $ele->Find('1 = 1', array()); } } else { $list = $ele->Find('1 = 1', array()); } foreach ($list as $obj) { if (count($values) == 1) { $ret[$obj->{$key}] = $obj->{$value}; } else { $objVal = ""; foreach ($values as $v) { if ($objVal != "") { $objVal .= " "; } $objVal .= $obj->{$v}; } $ret[$obj->{$key}] = $objVal; } } return $ret; }
public function changeLeaveStatus($req) { $employee = $this->baseService->getElement('Employee', $this->getCurrentProfileId(), null, true); $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?", array($employee->id)); $subordinatesIds = array(); foreach ($subordinates as $sub) { $subordinatesIds[] = $sub->id; } $employeeLeave = new EmployeeLeave(); $employeeLeave->Load("id = ?", array($req->id)); if ($employeeLeave->id != $req->id) { return new IceResponse(IceResponse::ERROR, "Leave not found"); } if (!in_array($employeeLeave->employee, $subordinatesIds) && $this->user->user_level != 'Admin') { return new IceResponse(IceResponse::ERROR, "This leave does not belong to any of your subordinates"); } $oldLeaveStatus = $employeeLeave->status; $employeeLeave->status = $req->status; if ($oldLeaveStatus == $req->status) { return new IceResponse(IceResponse::SUCCESS, ""); } $ok = $employeeLeave->Save(); if (!$ok) { LogManager::getInstance()->info($employeeLeave->ErrorMsg()); return new IceResponse(IceResponse::ERROR, "Error occured while saving leave infomation. Please contact admin"); } $employeeLeaveLog = new EmployeeLeaveLog(); $employeeLeaveLog->employee_leave = $employeeLeave->id; $employeeLeaveLog->user_id = $this->baseService->getCurrentUser()->id; $employeeLeaveLog->status_from = $oldLeaveStatus; $employeeLeaveLog->status_to = $employeeLeave->status; $employeeLeaveLog->created = date("Y-m-d H:i:s"); $employeeLeaveLog->data = isset($req->reason) ? $req->reason : ""; $ok = $employeeLeaveLog->Save(); if (!$ok) { LogManager::getInstance()->info($employeeLeaveLog->ErrorMsg()); } if (!empty($this->emailSender) && $oldLeaveStatus != $employeeLeave->status) { $leavesEmailSender = new LeavesEmailSender($this->emailSender, $this); $leavesEmailSender->sendLeaveStatusChangedEmail($employee, $employeeLeave); } $this->baseService->audit(IceConstants::AUDIT_ACTION, "Leave status changed \\ from:" . $oldLeaveStatus . "\\ to:" . $employeeLeave->status . " \\ id:" . $employeeLeave->id); if ($employeeLeave->status != "Pending") { $notificationMsg = "Your leave has been {$employeeLeave->status} by " . $employee->first_name . " " . $employee->last_name; if (!empty($req->reason)) { $notificationMsg .= " (Note:" . $req->reason . ")"; } } $this->baseService->notificationManager->addNotification($employeeLeave->employee, $notificationMsg, '{"type":"url","url":"g=modules&n=leaves&m=module_Leaves#tabEmployeeLeaveApproved"}', IceConstants::NOTIFICATION_LEAVE); return new IceResponse(IceResponse::SUCCESS, ""); }
<?php header('Access-Control-Allow-Origin: *'); header('Content-Type: application/json'); define('CLIENT_PATH', dirname(__FILE__)); include "config.base.php"; include "include.common.php"; include "server.includes.inc.php"; //clean request uri LogManager::getInstance()->info("REQUEST_URI :" . $_SERVER['REQUEST_URI']); $parts = explode("?", $_SERVER['REQUEST_URI']); $uri = $parts[0]; if (substr($uri, -1) == "/") { $uri = substr($uri, 0, -1); } LogManager::getInstance()->info("REQUEST_URI Cleaned :" . $uri); $type = strtolower($_SERVER['REQUEST_METHOD']); $supportedMethods = array('get', 'post', 'put', 'delete'); if (!in_array($type, $supportedMethods)) { echo json_encode(new IceResponse(IceResponse::ERROR, "Method not supported")); exit; } $response = RestApiManager::getInstance()->process($type, $uri, $_REQUEST); if ($response->getStatus() == IceResponse::SUCCESS) { echo json_encode($response, JSON_PRETTY_PRINT); } else { echo json_encode($response, JSON_PRETTY_PRINT); } exit;
private function getEmployeeById($id){ $sup = new Employee(); $sup->Load("id = ?",array($id)); if($sup->id != $id){ LogManager::getInstance()->info("Employee not found"); return null; } return $sup; }
public function sendLeaveStatusChangedEmail($employee, $leave) { $emp = $this->getEmployeeById($leave->employee); $params = array(); $params['name'] = $emp->first_name . " " . $emp->last_name; $params['startdate'] = $leave->date_start; $params['enddate'] = $leave->date_end; $params['status'] = $leave->status; $email = $this->subActionManager->getEmailTemplate('leaveStatusChanged.html'); $user = $this->subActionManager->getUserFromProfileId($emp->id); $emailTo = null; if (!empty($user)) { $emailTo = $user->email; } if (!empty($emailTo)) { if (!empty($this->emailSender)) { $this->emailSender->sendEmail("Leave Application " . $leave->status, $emailTo, $email, $params); } } else { LogManager::getInstance()->info("[sendLeaveStatusChangedEmail] email is empty"); } }
public function savePunch($req){ $req->date = $req->time; /* if(strtotime($req->date) > strtotime($req->cdate)){ return new IceResponse(IceResponse::ERROR,"You are not allowed to punch a future time"); } */ //check if there is an open punch $openPunch = $this->getPunch($req)->getData(); if(empty($openPunch)){ $openPunch = new Attendance(); } $dateTime = $req->date; $arr = explode(" ",$dateTime); $date = $arr[0]; $currentDateTime = $req->cdate; $arr = explode(" ",$currentDateTime); $currentDate = $arr[0]; if($currentDate != $date){ return new IceResponse(IceResponse::ERROR,"You are not allowed to punch time for a previous date"); } $employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true); //check if dates are differnet $arr = explode(" ",$openPunch->in_time); $inDate = $arr[0]; if(!empty($openPunch->in_time) && $inDate != $date){ return new IceResponse(IceResponse::ERROR,"Attendance entry should be within a single day"); } //compare dates if(!empty($openPunch->in_time) && strtotime($dateTime) <= strtotime($openPunch->in_time)){ return new IceResponse(IceResponse::ERROR,"Punch-in time should be lesser than Punch-out time"); } //Find all punches for the day $attendance = new Attendance(); $attendanceList = $attendance->Find("employee = ? and DATE_FORMAT( in_time, '%Y-%m-%d' ) = ?",array($employee->id,$date)); foreach($attendanceList as $attendance){ if(!empty($openPunch->in_time)){ if($openPunch->id == $attendance->id){ continue; } if(strtotime($attendance->out_time) >= strtotime($dateTime) && strtotime($attendance->in_time) <= strtotime($dateTime)){ //-1---0---1---0 || ---0--1---1---0 return new IceResponse(IceResponse::ERROR,"Time entry is overlapping with an existing one 1"); }else if(strtotime($attendance->out_time) >= strtotime($openPunch->in_time) && strtotime($attendance->in_time) <= strtotime($openPunch->in_time)){ //---0---1---0---1 || ---0--1---1---0 return new IceResponse(IceResponse::ERROR,"Time entry is overlapping with an existing one 2"); }else if(strtotime($attendance->out_time) <= strtotime($dateTime) && strtotime($attendance->in_time) >= strtotime($openPunch->in_time)){ //--1--0---0--1-- return new IceResponse(IceResponse::ERROR,"Time entry is overlapping with an existing one 3 ".$attendance->id); } }else{ if(strtotime($attendance->out_time) >= strtotime($dateTime) && strtotime($attendance->in_time) <= strtotime($dateTime)){ //---0---1---0 return new IceResponse(IceResponse::ERROR,"Time entry is overlapping with an existing one 4"); } } } if(!empty($openPunch->in_time)){ $openPunch->out_time = $dateTime; $openPunch->note = $req->note; $this->baseService->audit(IceConstants::AUDIT_ACTION, "Punch Out \ time:".$openPunch->out_time); }else{ $openPunch->in_time = $dateTime; $openPunch->out_time = '0000-00-00 00:00:00'; $openPunch->note = $req->note; $openPunch->employee = $employee->id; $this->baseService->audit(IceConstants::AUDIT_ACTION, "Punch In \ time:".$openPunch->in_time); } $ok = $openPunch->Save(); if(!$ok){ LogManager::getInstance()->info($openPunch->ErrorMsg()); return new IceResponse(IceResponse::ERROR,"Error occured while saving attendance"); } return new IceResponse(IceResponse::SUCCESS,$openPunch); }
public function getSubEmployeeTimeSheets($req) { $employee = $this->baseService->getElement('Employee', $this->getCurrentProfileId(), null, true); $subordinate = new Employee(); $subordinates = $subordinate->Find("supervisor = ?", array($employee->id)); $subordinatesIds = ""; foreach ($subordinates as $sub) { if ($subordinatesIds != "") { $subordinatesIds .= ","; } $subordinatesIds .= $sub->id; } $subordinatesIds .= ""; $mappingStr = $req->sm; $map = json_decode($mappingStr); $timeSheet = new EmployeeTimeSheet(); $list = $timeSheet->Find("employee in (" . $subordinatesIds . ")", array()); if (!$list) { LogManager::getInstance()->info($timeSheet->ErrorMsg()); } if (!empty($mappingStr)) { $list = $this->baseService->populateMapping($list, $map); } return new IceResponse(IceResponse::SUCCESS, $list); }
protected function sendMail($subject, $body, $toEmail, $fromEmail, $replyToEmail = null, $ccList = array(), $bccList = array()) { if (empty($replyToEmail)) { $replyToEmail = $fromEmail; } LogManager::getInstance()->info("Sending email to: " . $toEmail . "/ from: " . $fromEmail); $host = $this->settings->getSetting("Email: SMTP Host"); $username = $this->settings->getSetting("Email: SMTP User"); $password = $this->settings->getSetting("Email: SMTP Password"); $port = $this->settings->getSetting("Email: SMTP Port"); if (empty($port)) { $port = '25'; } if ($this->settings->getSetting("Email: SMTP Authentication Required") == "0") { $auth = array('host' => $host, 'auth' => false); } else { $auth = array('host' => $host, 'auth' => true, 'username' => $username, 'port' => $port, 'password' => $password); } //$smtp = Mail::factory('smtp',$auth); require_once 'email-class/PHPMailerAutoload.php'; $mail = new PHPMailer(); $mail->isSMTP(); $mail->CharSet = "iso-8859-1"; $mail->SMTPDebug = 0; $mail->Debugoutput = 'html'; $mail->IsHTML(true); $mail->Host = $host; $mail->Port = $port; $mail->SMTPAuth = true; // enable SMTP authentication $mail->Username = $username; $mail->Password = $password; $mail->setFrom($username, 'Smarttrak'); $mail->AddReplyTo($replyToEmail, 'Reply to name'); $mail->addAddress($toEmail); $mail->Subject = $subject; $mail->MsgHTML($body); /* if (!$mail->send()) { echo "Error: " . $mail->ErrorInfo . ' '; } else { echo "Done"; } */ /* $headers = array ('MIME-Version' => '1.0', 'Content-type' => 'text/html', 'charset' => 'iso-8859-1', 'From' => $fromEmail, 'To' => $toEmail, 'Reply-To' => $replyToEmail, 'Subject' => $subject); $mail = $smtp->send($toEmail, $headers, $body); */ return $mail->send() ? true : false; }
public function loadModulePermissions($group, $name, $userLevel) { $module = new Module(); $module->Load("update_path = ?", array($group . ">" . $name)); LogManager::getInstance()->info(" Current Mod :" . json_encode($module)); $arr = array(); $arr['user'] = json_decode($module->user_levels, true); $arr['user_roles'] = !empty($module->user_roles) ? json_decode($module->user_roles, true) : array(); $permission = new Permission(); $modulePerms = $permission->Find("module_id = ? and user_level = ?", array($module->id, $userLevel)); $perms = array(); foreach ($modulePerms as $p) { $perms[$p->permission] = $p->value; } $arr['perm'] = $perms; return $arr; }