Initial checkin v13.0

This commit is contained in:
Thilina Hasantha
2015-10-10 20:18:50 +05:30
parent 5fdd19b2c5
commit eb3439b29d
1396 changed files with 318492 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
<?php
/*
This file is part of iCE Hrm.
iCE Hrm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
iCE Hrm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with iCE Hrm. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------
Original work Copyright (c) 2012 [Gamonoid Media Pvt. Ltd]
Developer: Thilina Hasantha (thilina.hasantha[at]gmail.com / facebook.com/thilinah)
*/
class UsersActionManager extends SubActionManager{
public function changePassword($req){
if($this->user->user_level == 'Admin' || $this->user->id == $req->id){
$user = $this->baseService->getElement('User',$req->id);
if(empty($user->id)){
return new IceResponse(IceResponse::ERROR,"Please save the user first");
}
$user->password = md5($req->pwd);
$ok = $user->Save();
if(!$ok){
return new IceResponse(IceResponse::ERROR,$user->ErrorMsg());
}
return new IceResponse(IceResponse::SUCCESS,$user);
}
return new IceResponse(IceResponse::ERROR);
}
public function saveUser($req){
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->employee = (empty($req->employee) || $req->employee == "NULL" )?NULL:$req->employee;
$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");
$employee = null;
if(!empty($user->employee)){
$employee = $this->baseService->getElement('Employee',$user->employee,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, $employee);
}
return new IceResponse(IceResponse::SUCCESS,$user);
}
return new IceResponse(IceResponse::ERROR, "Not Allowed");
}
private function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
}

View File

@@ -0,0 +1,56 @@
<?php
if (!class_exists('UsersAdminManager')) {
class UsersAdminManager extends AbstractModuleManager{
public function initializeUserClasses(){
}
public function initializeFieldMappings(){
}
public function initializeDatabaseErrorMappings(){
}
public function setupModuleClassDefinitions(){
$this->addModelClass('User');
}
}
}
if (!class_exists('User')) {
class User extends ICEHRM_Record {
public function getAdminAccess(){
return array("get","element","save","delete");
}
public function getUserAccess(){
return array();
}
public function validateSave($obj){
$userTemp = new User();
if(empty($obj->id)){
$users = $userTemp->Find("email = ?",array($obj->email));
if(count($users) > 0){
return new IceResponse(IceResponse::ERROR,"A user with same authentication email already exist");
}
}else{
$users = $userTemp->Find("email = ? and id <> ?",array($obj->email, $obj->id));
if(count($users) > 0){
return new IceResponse(IceResponse::ERROR,"A user with same authentication email already exist");
}
}
return new IceResponse(IceResponse::SUCCESS,"");
}
var $_table = 'Users';
}
}

View File

@@ -0,0 +1,46 @@
<?php
class UsersEmailSender{
var $emailSender = null;
var $subActionManager = null;
public function __construct($emailSender, $subActionManager){
$this->emailSender = $emailSender;
$this->subActionManager = $subActionManager;
}
public function sendWelcomeUserEmail($user, $password, $employee = NULL){
$params = array();
if(!empty($employee)){
$params['name'] = $employee->first_name." ".$employee->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");
}
}
}