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");
}
}
}

View File

@@ -0,0 +1,17 @@
Dear #_name_#,<br/><br/>
Your account in <b>IceHrm</b> has been created on <a href="#_url_#">#_url_#</a><br/><br/>
<b>Please find your account information below:</b><br/><br/>
Username: <b>#_username_#</b><br/>
Email: <b>#_email_#</b> (You can use, username or email to login)<br/>
Password: <b>#_password_#</b> (Strongly advised to change this password once logged in)<br/>
<br/>
To get started, follow this link: <b><a href="#_url_#">#_url_#</a></b><br/><br/>
<font face="Arial, sans-serif" size="1" color="#4a4a4a">
THIS IS AN AUTOMATED EMAIL - REPLIES WILL BE SENT TO #_adminEmail_#
</font>
<br/>
<br/>

57
ext/admin/users/index.php Normal file
View File

@@ -0,0 +1,57 @@
<?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)
*/
$moduleName = 'users';
define('MODULE_PATH',dirname(__FILE__));
include APP_BASE_PATH.'header.php';
include APP_BASE_PATH.'modulejslibs.inc.php';
?><div class="span9">
<ul class="nav nav-tabs" id="modTab" style="margin-bottom:0px;margin-left:5px;border-bottom: none;">
<li class="active"><a id="tabUser" href="#tabPageUser">Users</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tabPageUser">
<div id="User" class="reviewBlock" data-content="List" style="padding-left:5px;">
</div>
<div id="UserForm" class="reviewBlock" data-content="Form" style="padding-left:5px;display:none;">
</div>
</div>
</div>
</div>
<script>
var modJsList = new Array();
modJsList['tabUser'] = new UserAdapter('User');
<?php if(isset($_REQUEST['action']) && $_REQUEST['action'] == "new" && isset($_REQUEST['object'])){?>
modJsList['tabUser'].newInitObject = JSON.parse(Base64.decode('<?=$_REQUEST['object']?>'));
<?php }?>
var modJs = modJsList['tabUser'];
</script>
<?php include APP_BASE_PATH.'footer.php';?>

162
ext/admin/users/lib.js Normal file
View File

@@ -0,0 +1,162 @@
/**
* Author: Thilina Hasantha
*/
function UserAdapter(endPoint) {
this.initAdapter(endPoint);
}
UserAdapter.inherits(AdapterBase);
UserAdapter.method('getDataMapping', function() {
return [
"id",
"username",
"email",
"employee",
"user_level"
];
});
UserAdapter.method('getHeaders', function() {
return [
{ "sTitle": "ID" },
{ "sTitle": "User Name" },
{ "sTitle": "Authentication Email" },
{ "sTitle": "Employee"},
{ "sTitle": "User Level"}
];
});
UserAdapter.method('getFormFields', function() {
return [
[ "id", {"label":"ID","type":"hidden","validation":""}],
[ "username", {"label":"User Name","type":"text","validation":"username"}],
[ "email", {"label":"Email","type":"text","validation":"email"}],
[ "employee", {"label":"Employee","type":"select2","allow-null":true,"remote-source":["Employee","id","first_name+last_name"]}],
[ "user_level", {"label":"User Level","type":"select","source":[["Admin","Admin"],["Manager","Manager"],["Employee","Employee"]]}]
];
});
UserAdapter.method('postRenderForm', function(object, $tempDomObj) {
if(object == null || object == undefined){
$tempDomObj.find("#changePasswordBtn").remove();
}
});
UserAdapter.method('changePassword', function() {
$('#adminUsersModel').modal('show');
$('#adminUsersChangePwd #newpwd').val('');
$('#adminUsersChangePwd #conpwd').val('');
});
UserAdapter.method('saveUserSuccessCallBack', function(callBackData,serverData) {
this.showMessage("Create User","An email has been sent to "+callBackData['email']+" with a temporary password to login to IceHrm.");
this.get([]);
});
UserAdapter.method('saveUserFailCallBack', function(callBackData,serverData) {
this.showMessage("Error",callBackData);
});
UserAdapter.method('doCustomValidation', function(params) {
var msg = null;
if(params['user_level'] != "Admin" && params['employee'] == "NULL"){
msg = "For non Admin users, you have to assign an employee when adding or editing the user.<br/>";
msg += " You may create a new employee through 'Admin'->'Employees' menu";
}
return msg;
});
UserAdapter.method('save', function() {
var validator = new FormValidation(this.getTableName()+"_submit",true,{'ShowPopup':false,"LabelErrorClass":"error"});
if(validator.checkValues()){
var params = validator.getFormParameters();
var msg = this.doCustomValidation(params);
if(msg == null){
var id = $('#'+this.getTableName()+"_submit #id").val();
if(id != null && id != undefined && id != ""){
$(params).attr('id',id);
this.add(params,[]);
}else{
var reqJson = JSON.stringify(params);
var callBackData = [];
callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'saveUserSuccessCallBack';
callBackData['callBackFail'] = 'saveUserFailCallBack';
this.customAction('saveUser','admin=users',reqJson,callBackData);
}
}else{
//$("#"+this.getTableName()+'Form .label').html(msg);
//$("#"+this.getTableName()+'Form .label').show();
this.showMessage("Error Saving User",msg);
}
}
});
UserAdapter.method('changePasswordConfirm', function() {
$('#adminUsersChangePwd_error').hide();
var passwordValidation = function (str) {
var val = /^[a-zA-Z0-9]\w{6,}$/;
return str != null && val.test(str);
};
var password = $('#adminUsersChangePwd #newpwd').val();
if(!passwordValidation(password)){
$('#adminUsersChangePwd_error').html("Password may contain only letters, numbers and should be longer than 6 characters");
$('#adminUsersChangePwd_error').show();
return;
}
var conPassword = $('#adminUsersChangePwd #conpwd').val();
if(conPassword != password){
$('#adminUsersChangePwd_error').html("Passwords don't match");
$('#adminUsersChangePwd_error').show();
return;
}
var req = {"id":this.currentId,"pwd":conPassword};
var reqJson = JSON.stringify(req);
var callBackData = [];
callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'changePasswordSuccessCallBack';
callBackData['callBackFail'] = 'changePasswordFailCallBack';
this.customAction('changePassword','admin=users',reqJson,callBackData);
});
UserAdapter.method('closeChangePassword', function() {
$('#adminUsersModel').modal('hide');
});
UserAdapter.method('changePasswordSuccessCallBack', function(callBackData,serverData) {
this.closeChangePassword();
this.showMessage("Password Change","Password changed successfully");
});
UserAdapter.method('changePasswordFailCallBack', function(callBackData,serverData) {
this.closeChangePassword();
this.showMessage("Error",callBackData);
});
UserAdapter.method('getHelpLink', function () {
return 'http://blog.icehrm.com/?page_id=132';
});

11
ext/admin/users/meta.json Normal file
View File

@@ -0,0 +1,11 @@
{
"label":"Users",
"menu":"System",
"order":"2",
"icon":"fa-user",
"user_levels":["Admin"],
"permissions":
{
}
}

View File

@@ -0,0 +1,55 @@
<form class="form-horizontal" id="_id_">
<div class="control-group">
<div class="controls">
<span class="label label-warning" id="_id__error" style="display:none;"></span>
</div>
</div>
_fields_
<div class="control-group">
<div class="controls">
<button onclick="try{modJs.save()}catch(e){};return false;" class="btn">Save</button>
<button onclick="modJs.cancel();return false;" class="btn">Cancel</button>
<button id="changePasswordBtn" onclick="modJs.changePassword();return false;" class="btn btn-primary">Change Password</button>
</div>
</div>
</form>
<div class="modal" id="adminUsersModel" tabindex="-1" role="dialog" aria-labelledby="messageModelLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><li class="fa fa-times"/></button>
<h3 style="font-size: 17px;">Change User Password</h3>
</div>
<div class="modal-body">
<form id="adminUsersChangePwd">
<div class="control-group">
<div class="controls">
<span class="label label-warning" id="adminUsersChangePwd_error" style="display:none;"></span>
</div>
</div>
<div class="control-group" id="field_newpwd">
<label class="control-label" for="newpwd">New Password</label>
<div class="controls">
<input class="" type="password" id="newpwd" name="newpwd" value="" class="form-control"/>
<span class="help-inline" id="help_newpwd"></span>
</div>
</div>
<div class="control-group" id="field_conpwd">
<label class="control-label" for="conpwd">Confirm Password</label>
<div class="controls">
<input class="" type="password" id="conpwd" name="conpwd" value="" class="form-control"/>
<span class="help-inline" id="help_conpwd"></span>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" onclick="modJs.changePasswordConfirm();">Change Password</button>
<button class="btn" onclick="modJs.closeChangePassword();">Not Now</button>
</div>
</div>
</div>
</div>