<?php
error_reporting(0);
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();
session_start();
session_cache_limiter('private');
$cache_limiter 	= session_cache_limiter();
session_cache_expire(60);
$cache_expire 	= session_cache_expire(); 
date_default_timezone_set('Asia/Manila'); 
$CURRENT_DATE 	= date('Y-m-d H:i:s');
include_once('../config/minho.php');
include_once('../config/autoloadClass.php');
$autoload	=	new autoloadClass();
$mecon		=	new condbClass();
$first			= isset($_POST['ufirstname']) 		? str_replace(",","",trim(strip_tags($_POST['ufirstname']))) : ""; 
$last			= isset($_POST['ulastname']) 	? str_replace(",","",trim(strip_tags($_POST['ulastname']))) : ""; 
$username		= isset($_POST['uusername']) 		? str_replace(",","",trim(strip_tags($_POST['uusername']))) : "";    
$utype			= isset($_POST['uusertype']) 		? str_replace(",","",trim(strip_tags($_POST['uusertype']))) : "";    
$pwd			= isset($_POST['upassword']) 		? str_replace(",","",trim(strip_tags($_POST['upassword']))) : "";    
$task			= isset($_POST['action']) 		? str_replace(",","",trim(strip_tags($_POST['action']))) : "";    
$mid			= isset($_POST['id']) 		? str_replace(",","",trim(strip_tags($_POST['id']))) : "";    
 
$currentUser 		= $_SESSION['castalia_username'];
$timeStamp		= date('Y-m-d H:i:s');
$mainArr			= array();
$mainArr2			= array();
$mainArr3			= array();
$condArr 	= array();  
$output 			= "";
$mainArr['FirstName']  = $first; 
$mainArr['LastName']  = $last; 
$mainArr['Username']  = $username; 
$mainArr['Password']  = md5("community_".$pwd."_community"); 
$mainArr['UserType']  = $utype; 
$mainArr['Status']  = "active"; 

if($utype=="documentation_staff"){
	$mainArr['SeqNo']  = 1;
}else if($utype=="documentation_supervisor"){
	$mainArr['SeqNo']  = 2;
}else if($utype=="assistant_accountant"){
	$mainArr['SeqNo']  = 3;
}else if($utype=="accountant"){
	$mainArr['SeqNo']  = 4;
}else if($utype=="admin"){
	$mainArr['SeqNo']  = 5;
}
 


if($task=="create"){
	$mainArr['CreatedBy']  	= $currentUser; 
	$mainArr['CreatedDate'] = $timeStamp; 
	$output					= $mecon->insertSingleQuery($mainArr,"user");
}else if($task=="edit"){
	$condArr['Id']			= $mid;
	$mainArr['UpdatedBy']  	= $currentUser; 
	$mainArr['UpdatedDate'] = $timeStamp; 
	$output					= $mecon->updateQuery($mainArr,"user",$condArr); 
}
 
$resultArr 						= array();
$resultArr['output']	  		= $output; 
echo json_encode($resultArr); 
exit();
ob_end_flush();