Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('connection.php');
- $register="register";
- $login="login";
- //readAllTimes
- $inTime_All="inTime_All";
- $outTime_All="outTime_All";
- //insert
- $presetDateInsert="presetDateInsert";
- $inTimeInsert="inTimeInsert";
- $outTimeInsert="outTimeInsert";
- //update
- $presentDateUpdate="presentDateUpdate";
- $inTimeUpdate="inTimeUpdate";
- $outTimeUpdate="outTimeUpdate";
- //status
- $presetDateStatus="presetDateStatus";
- $inTimeStatus="inTimeStatus";
- $outTimeStatus="outTimeStatus";
- $all_details="all_details";
- $updateOuTimeAndInsertInTime="updateOuTimeAndInsertInTime";
- $presetDate_InTime="presetDate_InTime";
- $task=$_REQUEST['task'];
- if($task==$register){
- register();
- } else if($task==$login) {
- login();
- }else if($task==$inTimeStatus){
- getStatus();
- }else if($task==$outTimeStatus){
- getStatusForOutTime();
- }else if($task==$presetDateStatus){
- getStatusForPresentDate();
- }else if($task==$presetDate_InTime){
- setPresetDate_InTime();
- }else if($task==$updateOuTimeAndInsertInTime){
- setUpdateOuTimeAndInsertInTime();
- }else if($task==$inTimeInsert){
- inTimeInsert();
- }else if($task==$outTimeInsert){
- outTimeInsert();
- }else if($task==$presetDateInsert){
- presetDateInsert();
- }else if($task==$inTimeUpdate){
- inTimeUpdate();
- }else if($task==$outTimeUpdate){
- outTimeUpdate();
- }else if($task==$presentDateUpdate){
- presentDateUpdate();
- }else if($task==$inTime_All){
- getAll("intime_mgt",$_REQUEST['employeeId']);
- }else if($task==$outTime_All){
- getAll("outtime_mgt",$_REQUEST['employeeId']);
- }else if($task==$all_details){
- getAll_Details("intime_mgt",$_REQUEST['employeeId']);
- }else if($task=="all_details_present_date"){
- getAll_Details("presetdatetable",$_REQUEST['employeeId']);
- }else if($task=="all_details_out_time"){
- getAll_Details("outtime_mgt",$_REQUEST['employeeId']);
- }else if($task=="admin_view"){
- adminViewAllEmployee();
- }else if($task=="adminregister"){
- adminregister();
- }else if ($task=="admin_login"){
- admin_login();
- }
- function admin_login(){
- if((isset($_POST["mobile"])) && ($_POST["mobile"]!="") && (isset($_POST["password"])) && ($_POST["password"]!=""))
- {
- $userid=$_POST['mobile'];
- $password=$_POST['password'];
- $result = mysql_query("SELECT * FROM adminregister WHERE mobile='$userid'");
- $response["login_admin"] = array();
- if(mysql_num_rows($result) ==1)
- {
- while($row = mysql_fetch_array($result))
- {
- $user = array();
- $username=$row['mobile'];
- $passwd=$row['password'];
- if(($password==$passwd) && ($userid==$username))
- {
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="Login Success";
- $user["name"] = $row["name"];
- $user["password"] = $row["password"];
- $user["mobileNumber"] = $row["mobile"];
- $user["adminId"] = $row["adminId"];
- array_push($response["login_admin"], $user);
- }
- else
- {
- $user = array();
- $response["success_code"] = 1;
- $response["status"]="failure";
- $response["message"]="Invalid User";
- }
- } }
- else {
- $user_not_found = array();
- $response["success_code"] = 1;
- $response["status"]="not_found";
- $response["message"]="User not found";
- }
- }
- echo json_encode($response);
- }
- function adminregister(){
- echo $_POST['adminId']." ".$_POST['name']." ".$_POST['password']." ".$_POST['mobile']." ".$_POST['emailId'];
- $sql = "INSERT INTO `adminregister` (adminId,name,password, mobile,emailId) VALUES ('".$_POST['adminId']."', '".$_POST['name']."','".$_POST['password']."', '".$_POST['mobile']."', '".$_POST['emailId']."')";
- $retval = mysql_query( $sql );
- if(! $retval ) {
- die('Could not enter data: ' . mysql_error());
- $json = array("status" => "failure","message" => "Invalid User","code" => "1");
- }
- $json = array("status" => "success","message" => "Insert Intime Success","code" => "0");
- echo json_encode($json);
- }
- function adminViewAllEmployee(){
- $response = array();
- $result = mysql_query("SELECT * FROM userregistration");
- $response["employeeDetails"] = array();
- if(mysql_num_rows($result) >=1)
- {
- while($row = mysql_fetch_array($result))
- {
- $user = array();
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="All Datas Success";
- $user["empName"] = $row['name'];
- $user["employeeId"] = $row['employeeId'];
- $user["empMobileNumber"] = $row['mobileNumber'];
- array_push($response["employeeDetails"], $user);
- }
- }
- echo json_encode($response);;
- }
- function getAll_Details($db_name,$employeeId){
- $response = array();
- $result = mysql_query("SELECT * FROM $db_name WHERE employeeId='$employeeId'");
- $response["all"] = array();
- if(mysql_num_rows($result) >=1)
- {
- $currentDate=date("Y-m-d") ;
- while($row = mysql_fetch_array($result))
- {
- $db_date;
- $user = array();
- if($db_name=="intime_mgt")
- {
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="All Datas Success";
- $in_date= substr($row["inTime"],0,10) ;
- $user["inTime"] = $in_date;
- $user["timeSpent"]=$row["timeSpent"];
- array_push($response["all"], $user);
- }
- else if ($db_name=="outtime_mgt")
- {
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="All Datas Success";
- $out_date= substr($row["outTime"],0,10) ;
- $user["outTime"] = $out_date;
- $user["timeSpent"]=$row["timeSpent"];
- array_push($response["all"], $user);
- }else {
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="All Datas Success";
- $user["presentdate"] = $row["presetDate"];
- array_push($response["all"], $user);
- }
- }
- }
- else {
- $user_not_found = array();
- $response["success_code"] = 1;
- $response["status"]="not_found";
- $response["message"]="User not found";
- array_push($response["all"], $user);
- }
- echo json_encode($response);
- }
- function setPresetDate_InTime(){
- presetDateInsert();
- inTimeInsert();
- }
- function setUpdateOuTimeAndInsertInTime(){
- outTimeUpdate();
- inTimeInsert();
- }
- function getStatusForPresentDate(){
- $response = array();
- if((isset($_POST["employeeId"])) && ($_POST["employeeId"]!="") )
- {
- $employeeId=$_POST['employeeId'];
- /*$sql="SELECT * FROM presetDateTable where employeeId=$employeeId";*/
- $sql="SELECT * FROM `presetdatetable` WHERE employeeId='$employeeId' order by id desc limit 1";
- /*$sql="SELECT * FROM intime_mgt where id=(select MAX(id)from intime_mgt)";*/
- $result = mysql_query($sql);
- $response["intime_status"] = array();
- $user = array();
- if(mysql_num_rows($result) >=1){
- $statusId;
- $inTime;
- $id;
- $employeeId;
- while($row = mysql_fetch_array($result))
- {
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="Fetched Datas Success";
- $id=$row['id'];
- $date =$row['presetDate'];
- $employeeId=$row['employeeId'];
- }
- $user['id']=$id;
- $user['presentdate']=$date;
- $user['employeeId']=$employeeId;
- array_push($response["intime_status"], $user);
- }else{
- $user = array();
- $response["success_code"] = 1;
- $response["status"]="Failure";
- $response["message"]="Not Found";
- }
- }else{
- $user = array();
- $response["success_code"] = 1;
- $response["status"]="Wrong";
- $response["message"]="Something Went Wrong";
- }
- echo json_encode($response);
- }
- function presetDateInsert(){
- $response = array();
- $sql = "INSERT INTO `presetdatetable` (employeeId,presetDate) VALUES ('".$_POST['employeeId']."', '".$_POST['presetDate']."')";
- $retval = mysql_query( $sql );
- if(! $retval ) {
- die('Could not enter data: ' . mysql_error());
- $json = array("status" => "failure","message" => "Invalid User","code" => "1");
- }
- $response["success_code"] = 0;
- $response["message"] = "insert preset date";
- echo json_encode($response);
- }
- function presentDateUpdate(){
- $response = array();
- $id=$_POST['id'];
- $date=$_POST['date'];
- $result = mysql_query("UPDATE presetdatetable SET presetDate ='$date' WHERE id = $id");
- $response["present_date_update_status"] = array();
- if ($result) {
- $response["success_code"] = 0;
- $response["message"] = "successfully updated present date";
- } else {
- $response["success_code"] = 1;
- $response["message"] = "not updated";
- }
- echo json_encode($response);
- }
- function outTimeInsert(){
- $response["out_Time_Insert_status"] = array();
- $sql = "INSERT INTO `outtime_mgt` (employeeId,outTime,statusId) VALUES ('".$_POST['employeeId']."', '".$_POST['outTime']."', '".$_POST['statusId']."' )";
- $retval = mysql_query( $sql );
- if(! $retval ) {
- die('Could not enter data: ' . mysql_error());
- $json = array("status" => "failure","message" => "Invalid User","code" => "1");
- }
- $response["success_code"] = 0;
- $response["message"] = "OutTime Insert";
- echo json_encode($response);
- }
- function outTimeUpdate(){
- $response = array();
- $id=$_POST['id'];
- $employeeId=$_POST['employeeId'];
- $updateStatus=$_POST['updateStatus'];
- $duration=$_POST['duration'];
- $timeSpent=$_POST['timeSpent'];
- $inTime=$_POST['inTime'];
- $statusId=$_POST['updateStatus'];
- $result = mysql_query("UPDATE outtime_mgt SET intime ='$inTime',duration='$duration',statusId=$statusId,timeSpent='$timeSpent' WHERE id = $id");
- $response["outTime_update_status"] = array();
- if ($result) {
- $response["success_code"] = 0;
- $response["message"] = "successfully updated OutTime";
- } else {
- $response["success_code"] = 1;
- $response["message"] = "not updated";
- }
- echo json_encode($response);
- }
- function inTimeUpdate(){
- $response = array();
- $statusId=$_POST['statusId'];
- $outTime=$_POST['outTime'];
- $duration=$_POST['duration'];
- $id=$_POST['id'];
- $timeSpent=$_POST['timeSpent'];
- $result = mysql_query("UPDATE intime_mgt SET outTime ='$outTime',duration ='$duration',statusId ='$statusId',timeSpent='$timeSpent' WHERE id = $id");
- $response["intime_update_status"] = array();
- if ($result) {
- // successfully updated
- $response["success"] = 0;
- $response["message"] = "Successfully updated..";
- // echoing JSON response
- echo json_encode($response);
- } else {
- $response["success"] = 1;
- $response["message"] = "not updated..";
- echo json_encode($response);
- }
- }
- function inTimeInsert(){
- $sql = "INSERT INTO `intime_mgt` (employeeId,inTime,outTime, statusId) VALUES ('".$_POST['employeeId']."', '".$_POST['inTime']."','".$_POST['outTime']."', '".$_POST['statusId']."' )";
- $retval = mysql_query( $sql );
- if(! $retval ) {
- die('Could not enter data: ' . mysql_error());
- $json = array("status" => "failure","message" => "Invalid User","code" => "1");
- }
- $json = array("status" => "success","message" => "Insert Intime Success","code" => "0");
- echo json_encode($json);
- }
- function getAll($db_name,$employeeId){
- $response = array();
- $result = mysql_query("SELECT * FROM $db_name WHERE employeeId='$employeeId'");
- $response["all"] = array();
- if(mysql_num_rows($result) >=1)
- {
- $currentDate=date("Y-m-d") ;
- while($row = mysql_fetch_array($result))
- {
- $db_date;
- $user = array();
- if($db_name=="intime_mgt")
- {
- $db_date=$row["inTime"];
- }
- else if ($db_name=="outtime_mgt")
- {
- $db_date=$row["outTime"];
- }
- $in_date= substr($db_date,0,10) ;
- $date_Tim=$_POST['dateString'];
- if($date_Tim==$in_date){
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="All Datas Success";
- $user["inTime"] = $row["inTime"];
- $user["outTime"] = $row["outTime"];
- $user["duration"] = $row["duration"];
- $user["timeSpent"]=$row["timeSpent"];
- array_push($response["all"], $user);
- }
- }
- }
- else {
- $user_not_found = array();
- $response["success_code"] = 1;
- $response["status"]="not_found";
- $response["message"]="User not found";
- }
- echo json_encode($response);
- }
- function getStatusForOutTime(){
- $response = array();
- if((isset($_POST["employeeId"])) && ($_POST["employeeId"]!="") )
- {
- $employeeId=$_POST['employeeId'];
- /*$sql="SELECT * FROM outtime_mgt where employeeId=$employeeId";*/
- $sql="SELECT * FROM `outtime_mgt` WHERE employeeId='$employeeId' order by id desc limit 1";
- /*$sql="SELECT * FROM intime_mgt where id=(select MAX(id)from intime_mgt)";*/
- $result = mysql_query($sql);
- $response["outTime_status"] = array();
- $user = array();
- if(mysql_num_rows($result) >=1){
- $statusId;
- $inTime;
- $id;
- $employeeId;
- while($row = mysql_fetch_array($result))
- {
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="Fetched Datas Success";
- $statusId=$row['statusId'];
- $inTime=$row['outTime'];
- $id=$row['id'];
- $employeeId =$row['employeeId'];
- $outTime =$row['inTime'];
- $timeSpentInTime =$row['timeSpent'];
- $user['timeSpent']=$timeSpentInTime;
- $user['inTime']=$inTime;
- $user['id']=$id;
- $user['statusId']=$statusId;
- $user['outTime']=$outTime;
- $user['employeeId']=$employeeId;
- array_push($response["outTime_status"], $user);
- }
- }else{
- $user = array();
- $response["success_code"] = 1;
- $response["status"]="Failure";
- $response["message"]="Not Found";
- }
- }else{
- $user = array();
- $response["success_code"] = 1;
- $response["status"]="Wrong";
- $response["message"]="Something Went Wrong";
- }
- echo json_encode($response);
- }
- function getStatus(){
- $response = array();
- if((isset($_POST["employeeId"])) && ($_POST["employeeId"]!="") )
- {
- $employeeId=$_POST['employeeId'];
- /*$sql="SELECT * FROM intime_mgt where employeeId=$employeeId";*/
- $sql="SELECT * FROM `intime_mgt` WHERE employeeId='$employeeId' order by id desc limit 1";
- /*$sql="SELECT * FROM intime_mgt where id=(select MAX(id)from intime_mgt)";*/
- $result = mysql_query($sql);
- $response["intime_status"] = array();
- $user = array();
- if(mysql_num_rows($result) >=1){
- $statusId;
- $inTime;
- $id;
- $employeeId;
- while($row = mysql_fetch_array($result))
- {
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="Fetched Datas Success";
- $statusId=$row['statusId'];
- $inTime=$row['inTime'];
- $id=$row['id'];
- $employeeId =$row['employeeId'];
- $outTime =$row['outTime'];
- $timeSpentInTime =$row['timeSpent'];
- $user['timeSpent']=$timeSpentInTime;
- $user['inTime']=$inTime;
- $user['id']=$id;
- $user['statusId']=$statusId;
- $user['employeeId']=$employeeId;
- $user['outTime']=$outTime;
- array_push($response["intime_status"], $user);
- }
- }else{
- $user = array();
- $response["success_code"] = 1;
- $response["status"]="Failure";
- $response["message"]="Not Found";
- }
- }else{
- $user = array();
- $response["success_code"] = 1;
- $response["status"]="Wrong";
- $response["message"]="Something Went Wrong";
- }
- echo json_encode($response);
- }
- function login()
- {
- $response = array();
- if((isset($_POST["mobileNumber"])) && ($_POST["mobileNumber"]!="") && (isset($_POST["password"])) && ($_POST["password"]!=""))
- {
- $userid=$_POST['mobileNumber'];
- $password=$_POST['password'];
- $result = mysql_query("SELECT * FROM userregistration WHERE mobileNumber='$userid'");
- $response["login"] = array();
- if(mysql_num_rows($result) ==1)
- {
- while($row = mysql_fetch_array($result))
- {
- $user = array();
- $username=$row['mobileNumber'];
- $passwd=$row['password'];
- if(($password==$passwd) && ($userid==$username))
- {
- $response["success_code"] = 0;
- $response["status"]="Success";
- $response["message"]="Login Success";
- $user["name"] = $row["name"];
- $user["password"] = $row["password"];
- $user["mobileNumber"] = $row["mobileNumber"];
- $user["employeeId"] = $row["employeeId"];
- $user["deviceId"] = $row["deviceId"];
- $user["dob"] = $row["dob"];
- array_push($response["login"], $user);
- }
- else
- {
- $user = array();
- $response["success_code"] = 1;
- $response["status"]="failure";
- $response["message"]="Invalid User";
- }
- } }
- else {
- $user_not_found = array();
- $response["success_code"] = 1;
- $response["status"]="not_found";
- $response["message"]="User not found";
- }
- }
- echo json_encode($response);
- }
- function register(){
- if((isset($_POST["mobileNumber"])) && ($_POST["mobileNumber"]!="") && (isset($_POST["deviceId"])) && ($_POST["deviceId"]!=""))
- {
- $userid=$_POST['mobileNumber'];
- $deviceId=$_POST['deviceId'];
- $result = mysql_query("SELECT * FROM userregistration WHERE deviceId='$deviceId'");
- if(mysql_num_rows($result) ==0){
- $result1 = mysql_query("SELECT * FROM userregistration WHERE mobileNumber='$userid'");
- if(mysql_num_rows($result1) ==0){
- $sql = "INSERT INTO `userregistration` (name,mobileNumber, password, employeeId,deviceId,dob) VALUES ('".$_POST['name']."', '".$_POST['mobileNumber']."','".$_POST['password']."', '".$_POST['employeeId']."','".$_POST['deviceId']."', '".$_POST['dob']."' )";
- $retval = mysql_query( $sql
- );
- if(! $retval ) {
- die('Could not enter data: ' . mysql_error());
- $json = array("status" => "failure","message" => "Invalid User","code" => "1");
- }
- $json = array("status" => "success","message" => "Reegistration Success","code" => "0");
- echo json_encode($json);
- }else{
- $json = array("status" => "failure","message" =>"Mobile Number Already Exist,Please Contact Admin!!!","code" => "1");
- echo json_encode($json);
- }
- }else{
- $json = array("status" => "failure","message" =>"This Device Already Exist","code" => "1");
- echo json_encode($json);
- }
- } else{
- $json = array("status" => "failure","message" =>"Enter Mobile Number","code" => "1");
- echo json_encode($json);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment