Guest User

Untitled

a guest
Sep 1st, 2016
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.25 KB | None | 0 0
  1. <?php
  2.  
  3. include('connection.php');
  4. $register="register";
  5. $login="login";
  6.  
  7. //readAllTimes
  8. $inTime_All="inTime_All";
  9. $outTime_All="outTime_All";
  10.  
  11. //insert
  12. $presetDateInsert="presetDateInsert";
  13. $inTimeInsert="inTimeInsert";
  14. $outTimeInsert="outTimeInsert";
  15.  
  16. //update
  17. $presentDateUpdate="presentDateUpdate";
  18. $inTimeUpdate="inTimeUpdate";
  19. $outTimeUpdate="outTimeUpdate";
  20.  
  21. //status
  22. $presetDateStatus="presetDateStatus";
  23. $inTimeStatus="inTimeStatus";
  24. $outTimeStatus="outTimeStatus";
  25.  
  26. $all_details="all_details";
  27.  
  28. $updateOuTimeAndInsertInTime="updateOuTimeAndInsertInTime";
  29. $presetDate_InTime="presetDate_InTime";
  30.  
  31. $task=$_REQUEST['task'];
  32.  
  33. if($task==$register){
  34. register();
  35. } else if($task==$login) {
  36. login();
  37. }else if($task==$inTimeStatus){
  38. getStatus();
  39. }else if($task==$outTimeStatus){
  40. getStatusForOutTime();
  41. }else if($task==$presetDateStatus){
  42. getStatusForPresentDate();
  43. }else if($task==$presetDate_InTime){
  44. setPresetDate_InTime();
  45. }else if($task==$updateOuTimeAndInsertInTime){
  46. setUpdateOuTimeAndInsertInTime();
  47. }else if($task==$inTimeInsert){
  48. inTimeInsert();
  49. }else if($task==$outTimeInsert){
  50. outTimeInsert();
  51. }else if($task==$presetDateInsert){
  52. presetDateInsert();
  53. }else if($task==$inTimeUpdate){
  54. inTimeUpdate();
  55. }else if($task==$outTimeUpdate){
  56. outTimeUpdate();
  57. }else if($task==$presentDateUpdate){
  58. presentDateUpdate();
  59. }else if($task==$inTime_All){
  60. getAll("intime_mgt",$_REQUEST['employeeId']);
  61. }else if($task==$outTime_All){
  62. getAll("outtime_mgt",$_REQUEST['employeeId']);
  63. }else if($task==$all_details){
  64. getAll_Details("intime_mgt",$_REQUEST['employeeId']);
  65. }else if($task=="all_details_present_date"){
  66. getAll_Details("presetdatetable",$_REQUEST['employeeId']);
  67. }else if($task=="all_details_out_time"){
  68. getAll_Details("outtime_mgt",$_REQUEST['employeeId']);
  69. }else if($task=="admin_view"){
  70. adminViewAllEmployee();
  71. }else if($task=="adminregister"){
  72. adminregister();
  73. }else if ($task=="admin_login"){
  74. admin_login();
  75. }
  76. function admin_login(){
  77.  
  78. if((isset($_POST["mobile"])) && ($_POST["mobile"]!="") && (isset($_POST["password"])) && ($_POST["password"]!=""))
  79. {
  80. $userid=$_POST['mobile'];
  81. $password=$_POST['password'];
  82. $result = mysql_query("SELECT * FROM adminregister WHERE mobile='$userid'");
  83. $response["login_admin"] = array();
  84. if(mysql_num_rows($result) ==1)
  85. {
  86.  
  87. while($row = mysql_fetch_array($result))
  88. {
  89. $user = array();
  90.  
  91. $username=$row['mobile'];
  92. $passwd=$row['password'];
  93.  
  94.  
  95. if(($password==$passwd) && ($userid==$username))
  96. {
  97.  
  98. $response["success_code"] = 0;
  99. $response["status"]="Success";
  100. $response["message"]="Login Success";
  101.  
  102. $user["name"] = $row["name"];
  103. $user["password"] = $row["password"];
  104. $user["mobileNumber"] = $row["mobile"];
  105. $user["adminId"] = $row["adminId"];
  106.  
  107. array_push($response["login_admin"], $user);
  108.  
  109. }
  110. else
  111. {
  112. $user = array();
  113. $response["success_code"] = 1;
  114. $response["status"]="failure";
  115. $response["message"]="Invalid User";
  116.  
  117. }
  118. } }
  119. else {
  120.  
  121. $user_not_found = array();
  122. $response["success_code"] = 1;
  123. $response["status"]="not_found";
  124. $response["message"]="User not found";
  125.  
  126.  
  127.  
  128. }
  129.  
  130. }
  131. echo json_encode($response);
  132. }
  133. function adminregister(){
  134.  
  135. echo $_POST['adminId']." ".$_POST['name']." ".$_POST['password']." ".$_POST['mobile']." ".$_POST['emailId'];
  136. $sql = "INSERT INTO `adminregister` (adminId,name,password, mobile,emailId) VALUES ('".$_POST['adminId']."', '".$_POST['name']."','".$_POST['password']."', '".$_POST['mobile']."', '".$_POST['emailId']."')";
  137. $retval = mysql_query( $sql );
  138. if(! $retval ) {
  139. die('Could not enter data: ' . mysql_error());
  140. $json = array("status" => "failure","message" => "Invalid User","code" => "1");
  141. }
  142.  
  143. $json = array("status" => "success","message" => "Insert Intime Success","code" => "0");
  144. echo json_encode($json);
  145.  
  146. }
  147.  
  148. function adminViewAllEmployee(){
  149.  
  150. $response = array();
  151. $result = mysql_query("SELECT * FROM userregistration");
  152. $response["employeeDetails"] = array();
  153. if(mysql_num_rows($result) >=1)
  154. {
  155. while($row = mysql_fetch_array($result))
  156. {
  157. $user = array();
  158. $response["success_code"] = 0;
  159. $response["status"]="Success";
  160. $response["message"]="All Datas Success";
  161.  
  162. $user["empName"] = $row['name'];
  163. $user["employeeId"] = $row['employeeId'];
  164. $user["empMobileNumber"] = $row['mobileNumber'];
  165.  
  166. array_push($response["employeeDetails"], $user);
  167. }
  168. }
  169. echo json_encode($response);;
  170. }
  171.  
  172. function getAll_Details($db_name,$employeeId){
  173.  
  174. $response = array();
  175.  
  176. $result = mysql_query("SELECT * FROM $db_name WHERE employeeId='$employeeId'");
  177.  
  178. $response["all"] = array();
  179. if(mysql_num_rows($result) >=1)
  180. {
  181. $currentDate=date("Y-m-d") ;
  182.  
  183.  
  184. while($row = mysql_fetch_array($result))
  185. {
  186. $db_date;
  187. $user = array();
  188.  
  189. if($db_name=="intime_mgt")
  190. {
  191. $response["success_code"] = 0;
  192. $response["status"]="Success";
  193. $response["message"]="All Datas Success";
  194.  
  195. $in_date= substr($row["inTime"],0,10) ;
  196.  
  197. $user["inTime"] = $in_date;
  198.  
  199. $user["timeSpent"]=$row["timeSpent"];
  200. array_push($response["all"], $user);
  201. }
  202. else if ($db_name=="outtime_mgt")
  203. {
  204. $response["success_code"] = 0;
  205. $response["status"]="Success";
  206. $response["message"]="All Datas Success";
  207. $out_date= substr($row["outTime"],0,10) ;
  208. $user["outTime"] = $out_date;
  209. $user["timeSpent"]=$row["timeSpent"];
  210. array_push($response["all"], $user);
  211. }else {
  212. $response["success_code"] = 0;
  213. $response["status"]="Success";
  214. $response["message"]="All Datas Success";
  215. $user["presentdate"] = $row["presetDate"];
  216. array_push($response["all"], $user);
  217. }
  218.  
  219.  
  220. }
  221. }
  222. else {
  223. $user_not_found = array();
  224. $response["success_code"] = 1;
  225. $response["status"]="not_found";
  226. $response["message"]="User not found";
  227. array_push($response["all"], $user);
  228.  
  229. }
  230. echo json_encode($response);
  231.  
  232. }
  233.  
  234. function setPresetDate_InTime(){
  235.  
  236.  
  237. presetDateInsert();
  238. inTimeInsert();
  239.  
  240.  
  241.  
  242. }
  243. function setUpdateOuTimeAndInsertInTime(){
  244.  
  245.  
  246. outTimeUpdate();
  247. inTimeInsert();
  248.  
  249.  
  250. }
  251.  
  252. function getStatusForPresentDate(){
  253.  
  254. $response = array();
  255. if((isset($_POST["employeeId"])) && ($_POST["employeeId"]!="") )
  256. {
  257. $employeeId=$_POST['employeeId'];
  258.  
  259. /*$sql="SELECT * FROM presetDateTable where employeeId=$employeeId";*/
  260. $sql="SELECT * FROM `presetdatetable` WHERE employeeId='$employeeId' order by id desc limit 1";
  261. /*$sql="SELECT * FROM intime_mgt where id=(select MAX(id)from intime_mgt)";*/
  262. $result = mysql_query($sql);
  263.  
  264. $response["intime_status"] = array();
  265. $user = array();
  266. if(mysql_num_rows($result) >=1){
  267. $statusId;
  268. $inTime;
  269. $id;
  270. $employeeId;
  271. while($row = mysql_fetch_array($result))
  272. {
  273.  
  274. $response["success_code"] = 0;
  275. $response["status"]="Success";
  276. $response["message"]="Fetched Datas Success";
  277.  
  278. $id=$row['id'];
  279. $date =$row['presetDate'];
  280. $employeeId=$row['employeeId'];
  281.  
  282. }
  283.  
  284. $user['id']=$id;
  285. $user['presentdate']=$date;
  286. $user['employeeId']=$employeeId;
  287. array_push($response["intime_status"], $user);
  288.  
  289. }else{
  290. $user = array();
  291. $response["success_code"] = 1;
  292. $response["status"]="Failure";
  293. $response["message"]="Not Found";
  294.  
  295.  
  296. }
  297.  
  298. }else{
  299. $user = array();
  300.  
  301. $response["success_code"] = 1;
  302. $response["status"]="Wrong";
  303. $response["message"]="Something Went Wrong";
  304.  
  305. }
  306. echo json_encode($response);
  307. }
  308.  
  309.  
  310.  
  311. function presetDateInsert(){
  312.  
  313. $response = array();
  314. $sql = "INSERT INTO `presetdatetable` (employeeId,presetDate) VALUES ('".$_POST['employeeId']."', '".$_POST['presetDate']."')";
  315. $retval = mysql_query( $sql );
  316. if(! $retval ) {
  317. die('Could not enter data: ' . mysql_error());
  318. $json = array("status" => "failure","message" => "Invalid User","code" => "1");
  319. }
  320.  
  321.  
  322. $response["success_code"] = 0;
  323. $response["message"] = "insert preset date";
  324.  
  325.  
  326.  
  327. echo json_encode($response);
  328. }
  329.  
  330. function presentDateUpdate(){
  331.  
  332.  
  333. $response = array();
  334. $id=$_POST['id'];
  335. $date=$_POST['date'];
  336.  
  337. $result = mysql_query("UPDATE presetdatetable SET presetDate ='$date' WHERE id = $id");
  338. $response["present_date_update_status"] = array();
  339. if ($result) {
  340.  
  341.  
  342. $response["success_code"] = 0;
  343. $response["message"] = "successfully updated present date";
  344.  
  345.  
  346. } else {
  347. $response["success_code"] = 1;
  348. $response["message"] = "not updated";
  349.  
  350.  
  351. }
  352. echo json_encode($response);
  353.  
  354. }
  355.  
  356.  
  357. function outTimeInsert(){
  358.  
  359. $response["out_Time_Insert_status"] = array();
  360. $sql = "INSERT INTO `outtime_mgt` (employeeId,outTime,statusId) VALUES ('".$_POST['employeeId']."', '".$_POST['outTime']."', '".$_POST['statusId']."' )";
  361. $retval = mysql_query( $sql );
  362. if(! $retval ) {
  363.  
  364. die('Could not enter data: ' . mysql_error());
  365. $json = array("status" => "failure","message" => "Invalid User","code" => "1");
  366. }
  367. $response["success_code"] = 0;
  368. $response["message"] = "OutTime Insert";
  369.  
  370. echo json_encode($response);
  371. }
  372.  
  373.  
  374. function outTimeUpdate(){
  375.  
  376. $response = array();
  377. $id=$_POST['id'];
  378. $employeeId=$_POST['employeeId'];
  379. $updateStatus=$_POST['updateStatus'];
  380. $duration=$_POST['duration'];
  381. $timeSpent=$_POST['timeSpent'];
  382. $inTime=$_POST['inTime'];
  383. $statusId=$_POST['updateStatus'];
  384. $result = mysql_query("UPDATE outtime_mgt SET intime ='$inTime',duration='$duration',statusId=$statusId,timeSpent='$timeSpent' WHERE id = $id");
  385. $response["outTime_update_status"] = array();
  386. if ($result) {
  387.  
  388.  
  389. $response["success_code"] = 0;
  390. $response["message"] = "successfully updated OutTime";
  391.  
  392.  
  393. } else {
  394. $response["success_code"] = 1;
  395. $response["message"] = "not updated";
  396.  
  397.  
  398. }
  399. echo json_encode($response);
  400.  
  401.  
  402.  
  403.  
  404. }
  405.  
  406. function inTimeUpdate(){
  407.  
  408.  
  409. $response = array();
  410. $statusId=$_POST['statusId'];
  411. $outTime=$_POST['outTime'];
  412. $duration=$_POST['duration'];
  413. $id=$_POST['id'];
  414. $timeSpent=$_POST['timeSpent'];
  415.  
  416. $result = mysql_query("UPDATE intime_mgt SET outTime ='$outTime',duration ='$duration',statusId ='$statusId',timeSpent='$timeSpent' WHERE id = $id");
  417. $response["intime_update_status"] = array();
  418. if ($result) {
  419. // successfully updated
  420. $response["success"] = 0;
  421. $response["message"] = "Successfully updated..";
  422. // echoing JSON response
  423. echo json_encode($response);
  424. } else {
  425. $response["success"] = 1;
  426. $response["message"] = "not updated..";
  427. echo json_encode($response);
  428. }
  429.  
  430. }
  431.  
  432.  
  433.  
  434. function inTimeInsert(){
  435.  
  436.  
  437. $sql = "INSERT INTO `intime_mgt` (employeeId,inTime,outTime, statusId) VALUES ('".$_POST['employeeId']."', '".$_POST['inTime']."','".$_POST['outTime']."', '".$_POST['statusId']."' )";
  438. $retval = mysql_query( $sql );
  439. if(! $retval ) {
  440. die('Could not enter data: ' . mysql_error());
  441. $json = array("status" => "failure","message" => "Invalid User","code" => "1");
  442. }
  443.  
  444. $json = array("status" => "success","message" => "Insert Intime Success","code" => "0");
  445. echo json_encode($json);
  446. }
  447.  
  448.  
  449.  
  450.  
  451. function getAll($db_name,$employeeId){
  452.  
  453. $response = array();
  454. $result = mysql_query("SELECT * FROM $db_name WHERE employeeId='$employeeId'");
  455. $response["all"] = array();
  456. if(mysql_num_rows($result) >=1)
  457. {
  458. $currentDate=date("Y-m-d") ;
  459. while($row = mysql_fetch_array($result))
  460. {
  461. $db_date;
  462. $user = array();
  463. if($db_name=="intime_mgt")
  464. {
  465. $db_date=$row["inTime"];
  466. }
  467. else if ($db_name=="outtime_mgt")
  468. {
  469. $db_date=$row["outTime"];
  470. }
  471. $in_date= substr($db_date,0,10) ;
  472. $date_Tim=$_POST['dateString'];
  473. if($date_Tim==$in_date){
  474. $response["success_code"] = 0;
  475. $response["status"]="Success";
  476. $response["message"]="All Datas Success";
  477.  
  478. $user["inTime"] = $row["inTime"];
  479. $user["outTime"] = $row["outTime"];
  480. $user["duration"] = $row["duration"];
  481. $user["timeSpent"]=$row["timeSpent"];
  482. array_push($response["all"], $user);
  483.  
  484. }
  485. }
  486. }
  487. else {
  488. $user_not_found = array();
  489. $response["success_code"] = 1;
  490. $response["status"]="not_found";
  491. $response["message"]="User not found";
  492.  
  493. }
  494. echo json_encode($response);
  495.  
  496. }
  497.  
  498.  
  499. function getStatusForOutTime(){
  500.  
  501. $response = array();
  502. if((isset($_POST["employeeId"])) && ($_POST["employeeId"]!="") )
  503. {
  504. $employeeId=$_POST['employeeId'];
  505.  
  506. /*$sql="SELECT * FROM outtime_mgt where employeeId=$employeeId";*/
  507. $sql="SELECT * FROM `outtime_mgt` WHERE employeeId='$employeeId' order by id desc limit 1";
  508. /*$sql="SELECT * FROM intime_mgt where id=(select MAX(id)from intime_mgt)";*/
  509. $result = mysql_query($sql);
  510.  
  511. $response["outTime_status"] = array();
  512. $user = array();
  513. if(mysql_num_rows($result) >=1){
  514. $statusId;
  515. $inTime;
  516. $id;
  517. $employeeId;
  518. while($row = mysql_fetch_array($result))
  519. {
  520.  
  521. $response["success_code"] = 0;
  522. $response["status"]="Success";
  523. $response["message"]="Fetched Datas Success";
  524. $statusId=$row['statusId'];
  525. $inTime=$row['outTime'];
  526. $id=$row['id'];
  527. $employeeId =$row['employeeId'];
  528. $outTime =$row['inTime'];
  529. $timeSpentInTime =$row['timeSpent'];
  530.  
  531. $user['timeSpent']=$timeSpentInTime;
  532. $user['inTime']=$inTime;
  533. $user['id']=$id;
  534. $user['statusId']=$statusId;
  535. $user['outTime']=$outTime;
  536. $user['employeeId']=$employeeId;
  537.  
  538. array_push($response["outTime_status"], $user);
  539.  
  540. }
  541.  
  542. }else{
  543. $user = array();
  544. $response["success_code"] = 1;
  545. $response["status"]="Failure";
  546. $response["message"]="Not Found";
  547.  
  548.  
  549. }
  550.  
  551. }else{
  552. $user = array();
  553. $response["success_code"] = 1;
  554. $response["status"]="Wrong";
  555. $response["message"]="Something Went Wrong";
  556.  
  557. }
  558. echo json_encode($response);
  559. }
  560.  
  561.  
  562.  
  563. function getStatus(){
  564.  
  565. $response = array();
  566. if((isset($_POST["employeeId"])) && ($_POST["employeeId"]!="") )
  567. {
  568. $employeeId=$_POST['employeeId'];
  569.  
  570. /*$sql="SELECT * FROM intime_mgt where employeeId=$employeeId";*/
  571. $sql="SELECT * FROM `intime_mgt` WHERE employeeId='$employeeId' order by id desc limit 1";
  572. /*$sql="SELECT * FROM intime_mgt where id=(select MAX(id)from intime_mgt)";*/
  573. $result = mysql_query($sql);
  574.  
  575. $response["intime_status"] = array();
  576. $user = array();
  577. if(mysql_num_rows($result) >=1){
  578. $statusId;
  579. $inTime;
  580. $id;
  581. $employeeId;
  582. while($row = mysql_fetch_array($result))
  583. {
  584.  
  585. $response["success_code"] = 0;
  586. $response["status"]="Success";
  587. $response["message"]="Fetched Datas Success";
  588. $statusId=$row['statusId'];
  589. $inTime=$row['inTime'];
  590. $id=$row['id'];
  591. $employeeId =$row['employeeId'];
  592. $outTime =$row['outTime'];
  593. $timeSpentInTime =$row['timeSpent'];
  594.  
  595. $user['timeSpent']=$timeSpentInTime;
  596. $user['inTime']=$inTime;
  597. $user['id']=$id;
  598. $user['statusId']=$statusId;
  599. $user['employeeId']=$employeeId;
  600. $user['outTime']=$outTime;
  601. array_push($response["intime_status"], $user);
  602.  
  603. }
  604.  
  605.  
  606. }else{
  607. $user = array();
  608. $response["success_code"] = 1;
  609. $response["status"]="Failure";
  610. $response["message"]="Not Found";
  611.  
  612.  
  613. }
  614.  
  615. }else{
  616. $user = array();
  617.  
  618. $response["success_code"] = 1;
  619. $response["status"]="Wrong";
  620. $response["message"]="Something Went Wrong";
  621.  
  622. }
  623. echo json_encode($response);
  624. }
  625.  
  626. function login()
  627. {
  628.  
  629. $response = array();
  630.  
  631. if((isset($_POST["mobileNumber"])) && ($_POST["mobileNumber"]!="") && (isset($_POST["password"])) && ($_POST["password"]!=""))
  632. {
  633. $userid=$_POST['mobileNumber'];
  634. $password=$_POST['password'];
  635. $result = mysql_query("SELECT * FROM userregistration WHERE mobileNumber='$userid'");
  636. $response["login"] = array();
  637. if(mysql_num_rows($result) ==1)
  638. {
  639.  
  640. while($row = mysql_fetch_array($result))
  641. {
  642. $user = array();
  643.  
  644. $username=$row['mobileNumber'];
  645. $passwd=$row['password'];
  646.  
  647.  
  648.  
  649.  
  650. if(($password==$passwd) && ($userid==$username))
  651. {
  652.  
  653. $response["success_code"] = 0;
  654. $response["status"]="Success";
  655. $response["message"]="Login Success";
  656.  
  657. $user["name"] = $row["name"];
  658. $user["password"] = $row["password"];
  659. $user["mobileNumber"] = $row["mobileNumber"];
  660. $user["employeeId"] = $row["employeeId"];
  661. $user["deviceId"] = $row["deviceId"];
  662. $user["dob"] = $row["dob"];
  663. array_push($response["login"], $user);
  664.  
  665. }
  666. else
  667. {
  668. $user = array();
  669. $response["success_code"] = 1;
  670. $response["status"]="failure";
  671. $response["message"]="Invalid User";
  672.  
  673.  
  674.  
  675. }
  676. } }
  677. else {
  678.  
  679. $user_not_found = array();
  680. $response["success_code"] = 1;
  681. $response["status"]="not_found";
  682. $response["message"]="User not found";
  683.  
  684.  
  685.  
  686. }
  687.  
  688. }
  689. echo json_encode($response);
  690. }
  691.  
  692.  
  693. function register(){
  694.  
  695. if((isset($_POST["mobileNumber"])) && ($_POST["mobileNumber"]!="") && (isset($_POST["deviceId"])) && ($_POST["deviceId"]!=""))
  696. {
  697. $userid=$_POST['mobileNumber'];
  698. $deviceId=$_POST['deviceId'];
  699.  
  700. $result = mysql_query("SELECT * FROM userregistration WHERE deviceId='$deviceId'");
  701.  
  702. if(mysql_num_rows($result) ==0){
  703. $result1 = mysql_query("SELECT * FROM userregistration WHERE mobileNumber='$userid'");
  704. if(mysql_num_rows($result1) ==0){
  705. $sql = "INSERT INTO `userregistration` (name,mobileNumber, password, employeeId,deviceId,dob) VALUES ('".$_POST['name']."', '".$_POST['mobileNumber']."','".$_POST['password']."', '".$_POST['employeeId']."','".$_POST['deviceId']."', '".$_POST['dob']."' )";
  706.  
  707.  
  708.  
  709. $retval = mysql_query( $sql
  710. );
  711.  
  712. if(! $retval ) {
  713. die('Could not enter data: ' . mysql_error());
  714.  
  715. $json = array("status" => "failure","message" => "Invalid User","code" => "1");
  716. }
  717.  
  718. $json = array("status" => "success","message" => "Reegistration Success","code" => "0");
  719. echo json_encode($json);
  720. }else{
  721. $json = array("status" => "failure","message" =>"Mobile Number Already Exist,Please Contact Admin!!!","code" => "1");
  722. echo json_encode($json);
  723. }
  724. }else{
  725.  
  726. $json = array("status" => "failure","message" =>"This Device Already Exist","code" => "1");
  727. echo json_encode($json);
  728. }
  729.  
  730. } else{
  731. $json = array("status" => "failure","message" =>"Enter Mobile Number","code" => "1");
  732. echo json_encode($json);
  733. }
  734.  
  735. }
  736.  
  737.  
  738.  
  739. ?>
Add Comment
Please, Sign In to add comment