class userManager
{
function addUser($arr,$files)
{
require_once(COMM_PATH."DatabaseManager.php");
$dbCon= new DatabaseManager();
if(isset($_REQUEST['uId']) && $_REQUEST['uId']!=''){
$query = 'UPDATE admin_users SET name="'.$_REQUEST['name'].'",usr_name="'.$_REQUEST['usr_name'].'",password="'.md5($_REQUEST['password']).'",access_level="'.$_REQUEST['access_level'].'",status="'.$_REQUEST['status'].'",decrypt_password="'.$_REQUEST['password'].'" WHERE usrid="'.$_REQUEST['uId'].'"';
$result=$dbCon->executeUpdate($query);
} else {
$query='INSERT INTO `admin_users`(name,usr_name,password,access_level,status,decrypt_password)VALUES("'.$_REQUEST['name'].'","'.$_REQUEST['usr_name'].'","'.md5($_REQUEST['password']).'","'.$_REQUEST['access_level'].'","'.$_REQUEST['status'].'","'.$_REQUEST['password'].'")';
$dbCon->executeUpdate($query);
//return $result;
}
}
function getUserList($arr,$limitStart=null,$recodsShow=null)
{
require_once(COMM_PATH."DatabaseManager.php");
$db= new DatabaseManager();
$query="SELECT * FROM `admin_users` ORDER BY usrid DESC LIMIT $limitStart,$recodsShow";
$result=$db->executeQuery($query);
return $result;
}
function getUserForEdit($uId)
{
require_once(COMM_PATH."DatabaseManager.php");
$db= new DatabaseManager();
$query='SELECT * FROM `admin_users` WHERE usrid="'.$uId.'"';
$result=$db->executeQuery($query);
return $result;
}
function deleteUser($uId){
require_once(COMM_PATH."DatabaseManager.php");
$dbCon= new DatabaseManager();
$query='DELETE FROM admin_users WHERE usrid="'.$_REQUEST['uId'].'"';
$result=$dbCon->executeUpdate($query);
return $result;
}
function updateAllstatus($uId){
require_once(COMM_PATH."DatabaseManager.php");
$dbCon= new DatabaseManager();
foreach($uId as $val){
$query='UPDATE admin_users SET status="0" WHERE usrid="'.$val.'"';
$result=$dbCon->executeUpdate($query);
}
//return $result;
}
function delAllUser($uId){
require_once(COMM_PATH."DatabaseManager.php");
$dbCon= new DatabaseManager();
foreach($uId as $val){
$query='delete from admin_users where usrid="'.$val.'"';
$result=$dbCon->executeUpdate($query);
}
}
function count_User(){
require_once(COMM_PATH."DatabaseManager.php");
$dbCon= new DatabaseManager();
$query='SELECT COUNT(*) as cnt FROM admin_users';
$result=$dbCon->executeQuery($query);
return $result[0]['cnt'];
}
}
/////////////////////////////////////////////////////////////////////init//////////////////////////////////////////////////////
require_once(ADMIN_LIB_PATH."user/userManager.php");
$userDetail = new userManager();//object for userManager class for accesing all function in userManager
//****************************PAGINATION START FROM HERE*********************************************
$numberOfRecordsPerPage = 2;
$minimumNumberOfPage = 1;
if(isset($_REQUEST['page']) && $_REQUEST['page']!=''){
$minimumNumberOfPage = $_REQUEST['page'];
}
$limitStartfrom = ($minimumNumberOfPage-1)*$numberOfRecordsPerPage;
//There is an object for count the number of record, From these we get number of page.................
$totalNumberOfRecords = $userDetail->count_User();
$totalNumberOfPages = ceil($totalNumberOfRecords/$numberOfRecordsPerPage);
$self = $_SERVER['PHP_SELF'];
if($minimumNumberOfPage>1){
$currentPage = $minimumNumberOfPage-1;
$previous = "<a href=\"$self?page=$currentPage\">Previous</a>";
$first = "<a href=\"$self?page=1\">First</a>";
}
else{
$previous =
"<a href=\"#\" class=\"disable\">Previous</a>";
$first = "<a href=\"#\" class=\"disable\">First</a>";
}
if($totalNumberOfPages>$minimumNumberOfPage){
$currentPage = $minimumNumberOfPage+1;
$next = "<a href=\"$self?page=$currentPage\">Next</a>";
$last = "<a href=\"$self?page=$totalNumberOfPages\">Last</a>";
}
else {
$next = "<a href=\"#\" class=\"disable\">Next</a>";
$last = "<a href=\"#\" class=\"disable\">Last</a>";
}
//*************************FOR INSERT AND UPDATE CALL OBJECT FROM CMS MANNAGER*********************
if(isset($_REQUEST['action']) && $_REQUEST['action']=='add_new_user')
{
$insertUser= $userDetail->addUser($_REQUEST,$_FILES);
if(isset($_REQUEST['uId']) && $_REQUEST['uId']!=''){
$returnUrlAddress ='admin-users.php?msg=2&page='.$_REQUEST['url'];
echo '<script>document.location.href="'.$returnUrlAddress.'"</script>';
exit();
} else {
echo '<script>document.location.href="admin-users.php?msg=1";</script>';
exit();
}
}
//******************************OBJECT FOR THE LISTING*************************************************
if($pg_Name=='userlist'){
$userList = $userDetail->getUserList($_REQUEST,$limitStartfrom,$numberOfRecordsPerPage);
}
//*****************************SHOW VALUE ON EDITING***************************************************
$name=$usr_name=$password=$access_level=$status='';
if(isset($_REQUEST['uId']) && $_REQUEST['uId']!='' ) {
$editList= $userDetail->getUserForEdit($_REQUEST['uId']);
if(count($editList)>0){
$name=$editList[0]['name'];
$usr_name=$editList[0]['usr_name'];
$password=$editList[0]['decrypt_password'];
$access_level=$editList[0]['access_level'];
$status=$editList[0]['status'];
}
}
//***************************js******************************************
function validateAddUser(){
if(isEmpty(document.getElementById('first_name').value)){
if(document.getElementById('server_error_msg'))
document.getElementById('server_error_msg').style.display='none';
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='Please Enter First Name.';
return false;
}
if(isEmpty(document.getElementById('last_name').value)){
if(document.getElementById('server_error_msg'))
document.getElementById('server_error_msg').style.display='none';
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='Please Enter Last Name.';
return false;
}
if(validateHtml(document.getElementById('first_name').value)){
if(document.getElementById('server_error_msg'))
document.getElementById('server_error_msg').style.display='none';
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='HTML tags are not allowed .';
return false;
}
if(validateHtml(document.getElementById('last_name').value)){
if(document.getElementById('server_error_msg'))
document.getElementById('server_error_msg').style.display='none';
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='HTML tags are not allowed .';
return false;
}
if(document.getElementById('signupDOBMonth').value=='0'){
if(document.getElementById('server_error_msg')){
document.getElementById('server_error_msg').style.display='none';
}
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='Select month of Date of Birth';
return false;
}
if(document.getElementById('signupDOBDay').value=='0'){
if(document.getElementById('server_error_msg')){
document.getElementById('server_error_msg').style.display='none';
}
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='Select day of Date of Birth';
return false;
}
if(document.getElementById('signupDOBYear').value=='0'){
if(document.getElementById('server_error_msg')){
document.getElementById('server_error_msg').style.display='none';
}
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='Select Year of Date of Birth';
return false;
}
if(isEmpty(document.getElementById('email').value)){
if(document.getElementById('server_error_msg'))
document.getElementById('server_error_msg').style.display='none';
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='Please Enter Email.';
return false;
}
if(!isEmail(document.getElementById('email').value)){
if(document.getElementById('server_error_msg'))
document.getElementById('server_error_msg').style.display='none';
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='Please Enter Valid Email Address ! It should be @ format.';
return false;
}
if(validateHtml(document.getElementById('email').value)){
if(document.getElementById('server_error_msg'))
document.getElementById('server_error_msg').style.display='none';
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='HTML tags are not allowed.';
return false;
}
if(isEmpty(document.getElementById('u_pass').value)){
if(document.getElementById('server_error_msg'))
document.getElementById('server_error_msg').style.display='none';
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='Please Enter Password.';
return false;
}
if(validateHtml(document.getElementById('u_pass').value)){
if(document.getElementById('server_error_msg'))
document.getElementById('server_error_msg').style.display='none';
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='HTML tags are not allowed.';
return false;
}
if(document.getElementById('contact_country').value=='0'){
if(document.getElementById('server_error_msg')){
document.getElementById('server_error_msg').style.display='none';
}
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='please select a country';
return false;
}
if(isEmpty(document.getElementById('city').value)){
if(document.getElementById('server_error_msg')){
document.getElementById('server_error_msg').style.display='none';
}
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='please enter a City';
return false;
}
file = document.getElementById('pic').value;
if(file!=''){
size = file.length -4;
ext = file.substring(size) ;
if(ext != ".gif" && ext != ".jpeg" && ext != ".png" && ext != ".jpg" && ext != ".GIF" && ext != "JPEG" && ext != ".PNG" && ext != ".JPG")
{
if(document.getElementById('server_error_msg')){
document.getElementById('server_error_msg').style.display='none';
}
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='please select a jpg,png or gif format image';
return false;
}
}
if (document.getElementById('Contact_Sports_other').checked==true)
{
if(isEmpty(document.getElementById('sports_other').value)){
if(document.getElementById('server_error_msg')){
document.getElementById('server_error_msg').style.display='none';
}
document.getElementById('error').style.display='';
document.getElementById('error').innerHTML='please enter other sports name.';
return false;
}
}
if (document.getElementById('Outdoor_Activities_other').checked==true)
{
if(isEmpty(document.getElementById('Act
////////////////////////////////////JS My////////////////////////////////////////////////////////////////////////////////////////
function Ajax() {
this.req = null;
this.url = null;
this.status = null;
this.statusText = '';
this.method = 'GET';
this.async = true;
this.dataPayload = null;
this.readyState = null;
this.responseText = null;
this.responseXML = null;
this.handleResp = null;
this.responseFormat = 'text', // 'text', 'xml', 'object'
this.mimeType = null;
this.headers = [];
this.init = function() {
var i = 0;
var reqTry = [
function() { return new XMLHttpRequest(); },
function() { return new ActiveXObject('Msxml2.XMLHTTP') },
function() { return new ActiveXObject('Microsoft.XMLHTTP' )} ];
while (!this.req && (i < reqTry.length)) {
try {
this.req = reqTry[i++]();
}
catch(e) {}
}
return true;
};
this.doGet = function(url, hand, format) {
this.url = url;
this.handleResp = hand;
this.responseFormat = format || 'text';
this.doReq();
};
this.doPost = function(url, dataPayload, hand, format) {
this.url = url;
this.dataPayload = dataPayload;
this.handleResp = hand;
this.responseFormat = format || 'text';
this.method = 'POST';
this.doReq();
};
this.doReq = function() {
var self = null;
var req = null;
var headArr = [];
if (!this.init()) {
alert('Could not create XMLHttpRequest object.');
return;
}
req = this.req;
req.open(this.method, this.url, this.async);
if (this.method == "POST") {
this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
if (this.method == 'POST') {
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
self = this;
req.onreadystatechange = function() {
var resp = null;
self.readyState = req.readyState;
if (req.readyState == 4) {
self.status = req.status;
self.statusText = req.statusText;
self.responseText = req.responseText;
self.responseXML = req.responseXML;
switch(self.responseFormat) {
case 'text':
resp = self.responseText;
break;
case 'xml':
resp = self.responseXML;
break;
case 'object':
resp = req;
break;
}
if (self.status > 199 && self.status < 300) {
if (!self.handleResp) {
//alert('No response handler defined ' + 'for this XMLHttpRequest object.');
return;
}
else {
self.handleResp(resp);
}
}
else {
self.handleErr(resp);
}
}
}
req.send(this.dataPayload);
};
this.abort = function() {
if (this.req) {
this.req.onreadystatechange = function() { };
this.req.abort();
this.req = null;
}
};
this.handleErr = function() {
var errorWin;
// Create new window and display error
try {
errorWin = window.open('', 'errorWin');
errorWin.document.body.innerHTML = this.responseText;
}
// If pop-up gets blocked, inform user
catch(e) {
alert('An error occurred, but the error message cannot be' +
' displayed because of your browser\'s pop-up blocker.\n' +
'Please allow pop-ups from this Web site.');
}
};
this.setMimeType = function(mimeType) {
this.mimeType = mimeType;
};
this.setHandlerResp = function(funcRef) {
this.handleResp = funcRef;
};
this.setHandlerErr = function(funcRef) {
this.handleErr = funcRef;
};
this.setHandlerBoth = function(funcRef) {
this.handleResp = funcRef;
this.handleErr = funcRef;
};
this.setRequestHeader = function(headerName, headerValue) {
this.headers.push(headerName + ': ' + headerValue);
};
}
/////////////////////////////////////db online//////////////////////////////////
/**
* The SystemDatabaseManager class provides the mechanism for interacting with the system database
*
* The class is written using the Singleton pattern.
* Here is how a reference to an instance of the class is obtained:
* <code>
* $systemDatabaseManager = SystemDatabaseManager::getInstance();
* </code>
*
* @package Database
* @author Bhart Garg
* made $userName, $host and $password as private members
* replaced constant for database with a private member
*/
class DatabaseManager {
// for offline
private static $host = 'localhost';
private static $userName = 'trip';
private static $password = 'trip';
private static $dbName = 'trip_whale';
public $conn = '';
function __construct() {
$this->conn = $this->connectToServer(DatabaseManager::$host, DatabaseManager::$userName, DatabaseManager::$password);
$this->selectDatabase(DatabaseManager::$dbName, $this->conn);
}
/**
* executes a SELECT query in the database
*
* @access public
* @param $query The SQL SELECT query to execute
* @param $comment An optional comment explaining the query
*
* @return the result set on success, or false on error
*/
public function executeQuery($query) {
$result = mysql_query($query);
if ($result === false) {
$this->closeConnection($this->conn);
exit;
}
// extract data from results, returning an associative array
$rows = Array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
/**
* executes a SELECT query in the database
*
* @access public
* @param $query The SQL SELECT query to execute
* @param $comment An optional comment explaining the query
*
* @return the result set on success, or false on error
*/
public function executeUpdate($query) {
$result = mysql_query($query);
if ($result === false) {
$this->closeConnection($this->conn);
exit;
}
if(mysql_affected_rows()>0){
return true;
} else {
return false;
}
}
/**
* returns last inserted id
*
* @param NA
* @param NA
*
* @return last insert id on success, or false on error
*/
public function lastInsertId(){
return mysql_insert_id();
}
function connectToServer($DBHost, $DBUsername, $DBPassword) {
$connection = mysql_connect($DBHost, $DBUsername, $DBPassword);
if ($connection === false) {
echo "Unable to connect to the database on $DBHost with username $DBUsername";
// through to maintenance page
exit;
}
return $connection;
}
function selectDatabase($database, $connection) {
$success = mysql_select_db($database, $connection);
if ($success === false) {
echo "Failed to select database '$database'";
return false;
}
return true;
}
function closeConnection($connection) {
$result = mysql_close($connection);
if ($result === false) {
exit;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* The SystemDatabaseManager class provides the mechanism for interacting with the system database
*
* The class is written using the Singleton pattern.
* Here is how a reference to an instance of the class is obtained:
* <code>
* $systemDatabaseManager = SystemDatabaseManager::getInstance();
* </code>
*
* @package Database
* @author Bhart Garg
* made $userName, $host and $password as private members
* replaced constant for database with a private member
*/
class DatabaseManager {
// for offline
private static $host = 'localhost';
private static $userName = 'root';
private static $password = '';
private static $dbName = 'trip_whale';
public $conn = '';
private static $instance;
function __construct() {
$this->conn = $this->connectToServer(DatabaseManager::$host, DatabaseManager::$userName, DatabaseManager::$password);
$this->selectDatabase(DatabaseManager::$dbName, $this->conn);
}
/**
* executes a SELECT query in the database
*
* @access public
* @param $query The SQL SELECT query to execute
* @param $comment An optional comment explaining the query
*
* @return the result set on success, or false on error
*/
public function executeQuery($query) {
$result = mysql_query($query);
if ($result === false) {
$this->closeConnection($this->conn);
exit;
}
// extract data from results, returning an associative array
$rows = Array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
/**
* executes a SELECT query in the database
*
* @access public
* @param $query The SQL SELECT query to execute
* @param $comment An optional comment explaining the query
*
* @return the result set on success, or false on error
*/
public function executeUpdate($query) {
$result = mysql_query($query);
if ($result === false) {
$this->closeConnection($this->conn);
exit;
}
if(mysql_affected_rows()>0){
return true;
} else {
return false;
}
}
/**
* returns last inserted id
*
* @param NA
* @param NA
*
* @return last insert id on success, or false on error
*/
public function lastInsertId(){
return mysql_insert_id();
}
function connectToServer($DBHost, $DBUsername, $DBPassword) {
$connection = mysql_connect($DBHost, $DBUsername, $DBPassword);
if ($connection === false) {
echo "Unable to connect to the database on $DBHost with username $DBUsername";
// through to maintenance page
exit;
}
return $connection;
}
function selectDatabase($database, $connection) {
$success = mysql_select_db($database, $connection);
if ($success === false) {
echo "Failed to select database '$database'";
return false;
}
return true;
}
function closeConnection($connection) {
$result = mysql_close($connection);
if ($result === false) {
exit;
}
}
//singlton method to access the classs
public static function getInstance() {
if (! isset ( self::$instance )) {
$c = __CLASS__;
self::$instance = new $c ( );
}
return self::$instance;
}
}