Guest User

Untitled

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