Guest User

Untitled

a guest
Aug 26th, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.50 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $register="register";
  5. $login="login";
  6. $getStatus="getStatus";
  7. $insertInTime="insertInTime";
  8. $insertOutTime="insertOutTime";
  9. $updateInTime="updateInTime";
  10. $updateOutTime="updateOutTime";
  11. $inTime_All="inTime_All";
  12. $outTime_All="outTime_All";
  13.  
  14. $task=$_REQUEST['task'];
  15.  
  16. if($task==$register){
  17. register();
  18. }
  19. else if($task==$login) {
  20. login();
  21. }else if($task==$getStatus){
  22. getStatus();
  23. }else if($task==$insertInTime){
  24. onInsertInTime();
  25. }else if($task==$insertOutTime){
  26. onInsertOutTime();
  27. }else if($task==$updateInTime){
  28. onUpdateInTime();
  29. }else if($task==$updateOutTime){
  30. onUpdateOutTime();
  31. }
  32. else if($task==$inTime_All){
  33. getAll("intime_mgt",$_REQUEST['employeeId']);
  34. }else if($task==$outTime_All){
  35. getAll("outtime_mgt",$_REQUEST['employeeId']);
  36. }
  37.  
  38.  
  39.  
  40. function getAll($db_name,$employeeId){
  41.  
  42. $con= mysql_connect('localhost','root','');
  43. if(!$con)
  44. {
  45. die('could not connect;'.mysql_error());
  46. }
  47.  
  48.  
  49. mysql_select_db('timemanagement');
  50. $response = array();
  51.  
  52. $result = mysql_query("SELECT * FROM $db_name WHERE employeeId='$employeeId'");
  53.  
  54. $response["all"] = array();
  55. if(mysql_num_rows($result) >=1)
  56. {
  57. $currentDate=date("Y-m-d") ;
  58.  
  59.  
  60. while($row = mysql_fetch_array($result))
  61. {
  62. $user = array();
  63.  
  64. $db_date=$row["inTime"];
  65.  
  66.  
  67. $response["success_code"] = 0;
  68. $response["status"]="Success";
  69. $response["message"]="All Datas Success";
  70.  
  71. $user["inTime"] = $db_date;
  72. $user["outTime"] = $row["outTime"];
  73. $user["duration"] = $row["duration"];
  74.  
  75. array_push($response["all"], $user);
  76.  
  77.  
  78. } }
  79. else {
  80.  
  81. $user_not_found = array();
  82. $response["success_code"] = 1;
  83. $response["status"]="not_found";
  84. $response["message"]="User not found";
  85.  
  86. }
  87. /* echo json_encode($response);*/
  88.  
  89. }
  90.  
  91.  
  92. function onUpdateOutTime(){
  93. echo "onUpdateOutTime";
  94. }
  95. function onUpdateInTime(){
  96.  
  97. $con= mysql_connect('localhost','root','');
  98. if(!$con)
  99. {
  100. die('could not connect;'.mysql_error());
  101. }
  102. mysql_select_db('timemanagement');
  103. $response = array();
  104. $statusId=$_POST['statusId'];
  105. $outTime=$_POST['outTime'];
  106. $duration=$_POST['duration'];
  107. $id=$_POST['id'];
  108. $result = mysql_query("UPDATE intime_mgt SET outTime ='$outTime',duration ='$duration',statusId ='$statusId' WHERE id = $id");
  109. $response["intime_update_status"] = array();
  110. if ($result) {
  111.  
  112.  
  113. $sql = "INSERT INTO `outtime_mgt` (employeeId,outTime,statusId) VALUES ('".$_POST['employeeId']."', '".$_POST['outTime']."', '".$_POST['statusId']."' )";
  114. $retval = mysql_query( $sql, $con );
  115. if(! $retval ) {
  116. die('Could not enter data: ' . mysql_error());
  117. $json = array("status" => "failure","message" => "Invalid User","code" => "1");
  118. }
  119.  
  120.  
  121. $response["success_code"] = 0;
  122. $response["message"] = "successfully updated";
  123. echo json_encode($response);
  124.  
  125. } else {
  126. $response["success_code"] = 1;
  127. $response["message"] = "not updated";
  128. echo json_encode($response);
  129.  
  130. }
  131. }
  132.  
  133.  
  134. function onInsertOutTime(){
  135. echo "onInsertOutTime";
  136.  
  137. }
  138. function onInsertInTime(){
  139.  
  140. $con= mysql_connect('localhost','root','');
  141. if(!$con)
  142. {
  143. die('could not connect;'.mysql_error());
  144. }
  145. mysql_select_db('timemanagement');
  146.  
  147. $sql = "INSERT INTO `intime_mgt` (employeeId,inTime,outTime, statusId,duration) VALUES ('".$_POST['employeeId']."', '".$_POST['inTime']."','".$_POST['outTime']."', '".$_POST['statusId']."','".$_POST['duration']."' )";
  148. $retval = mysql_query( $sql, $con );
  149. if(! $retval ) {
  150. die('Could not enter data: ' . mysql_error());
  151. $json = array("status" => "failure","message" => "Invalid User","code" => "1");
  152. }
  153.  
  154. $json = array("status" => "success","message" => "Insert Intime Success","code" => "0");
  155. echo json_encode($json);
  156. }
  157. function getStatus(){
  158.  
  159. $con= mysql_connect('localhost','root','');
  160. if(!$con)
  161. {
  162. die('could not connect;'.mysql_error());
  163. }
  164. mysql_select_db('timemanagement');
  165. $response = array();
  166. if((isset($_POST["employeeId"])) && ($_POST["employeeId"]!="") )
  167. {
  168. $employeeId=$_POST['employeeId'];
  169. $sql="SELECT * FROM intime_mgt where id=(select MAX(id)from intime_mgt)";
  170. $result = mysql_query($sql,$con);
  171.  
  172. $response["intime_status"] = array();
  173.  
  174. if(mysql_num_rows($result) >=1){
  175. while($row = mysql_fetch_array($result))
  176. {
  177. $user = array();
  178.  
  179. $response["success_code"] = 0;
  180. $response["status"]="Success";
  181. $response["message"]="Fetched Datas Success";
  182.  
  183. $user['statusId']=$row['statusId'];
  184. $user['inTime']=$row['inTime'];
  185. $user['id']=$row['id'];
  186.  
  187. array_push($response["intime_status"], $user);
  188. echo json_encode($response);
  189.  
  190. }
  191. }else{
  192. $user = array();
  193. $response["success_code"] = 1;
  194. $response["status"]="Failure";
  195. $response["message"]="Not Found";
  196. echo json_encode($response);
  197.  
  198. }
  199.  
  200. }else{
  201. $user = array();
  202.  
  203. $response["success_code"] = 1;
  204. $response["status"]="Wrong";
  205. $response["message"]="Something Went Wrong";
  206. echo json_encode($response);
  207. }
  208.  
  209. }
  210.  
  211. function login()
  212. {
  213. $con= mysql_connect('localhost','root','');
  214. if(!$con)
  215. {
  216. die('could not connect;'.mysql_error());
  217. }
  218. mysql_select_db('timemanagement');
  219. $response = array();
  220.  
  221. if((isset($_POST["mobileNumber"])) && ($_POST["mobileNumber"]!="") && (isset($_POST["password"])) && ($_POST["password"]!=""))
  222. {
  223. $userid=$_POST['mobileNumber'];
  224. $password=$_POST['password'];
  225. $result = mysql_query("SELECT * FROM userregistration WHERE mobileNumber='$userid'");
  226. $response["login"] = array();
  227. if(mysql_num_rows($result) ==1)
  228. {
  229.  
  230. while($row = mysql_fetch_array($result))
  231. {
  232. $user = array();
  233.  
  234. $username=$row['mobileNumber'];
  235. $passwd=$row['password'];
  236.  
  237.  
  238.  
  239.  
  240. if(($password==$passwd) && ($userid==$username))
  241. {
  242.  
  243. $response["success_code"] = 0;
  244. $response["status"]="Success";
  245. $response["message"]="Login Success";
  246.  
  247. $user["name"] = $row["name"];
  248. $user["password"] = $row["password"];
  249. $user["mobileNumber"] = $row["mobileNumber"];
  250. $user["employeeId"] = $row["employeeId"];
  251. $user["deviceId"] = $row["deviceId"];
  252. $user["dob"] = $row["dob"];
  253. array_push($response["login"], $user);
  254. echo json_encode($response);
  255. }
  256. else
  257. {
  258. $user = array();
  259. $response["success_code"] = 1;
  260. $response["status"]="failure";
  261. $response["message"]="Invalid User";
  262. /*array_push($response["login"], $user);*/
  263. echo json_encode($response);
  264.  
  265. }
  266. } }
  267. else {
  268.  
  269. $user_not_found = array();
  270. $response["success_code"] = 1;
  271. $response["status"]="not_found";
  272. $response["message"]="User not found";
  273. /*array_push($response["login"], $user_not_found);*/
  274. echo json_encode($response);
  275.  
  276. }
  277.  
  278. }
  279. }
  280.  
  281.  
  282. function register(){
  283.  
  284. $con= mysql_connect('localhost','root','');
  285. if(!$con)
  286. {
  287. die('could not connect;'.mysql_error());
  288. }
  289. mysql_select_db('timemanagement');
  290.  
  291. if((isset($_POST["mobileNumber"])) && ($_POST["mobileNumber"]!="") && (isset($_POST["deviceId"])) && ($_POST["deviceId"]!=""))
  292. {
  293. $userid=$_POST['mobileNumber'];
  294. $deviceId=$_POST['deviceId'];
  295.  
  296. $result = mysql_query("SELECT * FROM userregistration WHERE deviceId='$deviceId'");
  297.  
  298. if(mysql_num_rows($result) ==0){
  299. $result1 = mysql_query("SELECT * FROM userregistration WHERE mobileNumber='$userid'");
  300. if(mysql_num_rows($result1) ==0){
  301. $sql = "INSERT INTO `userregistration` (name,mobileNumber, password, employeeId,deviceId,dob) VALUES ('".$_POST['name']."', '".$_POST['mobileNumber']."','".$_POST['password']."', '".$_POST['employeeId']."','".$_POST['deviceId']."', '".$_POST['dob']."' )";
  302.  
  303. mysql_select_db('timemanagement');
  304.  
  305. $retval = mysql_query( $sql, $con );
  306.  
  307. if(! $retval ) {
  308. die('Could not enter data: ' . mysql_error());
  309.  
  310. $json = array("status" => "failure","message" => "Invalid User","code" => "1");
  311. }
  312.  
  313. $json = array("status" => "success","message" => "Reegistration Success","code" => "0");
  314. echo json_encode($json);
  315. }else{
  316. $json = array("status" => "failure","message" =>"Mobile Number Already Exist,Please Contact Admin!!!","code" => "1");
  317. echo json_encode($json);
  318. }
  319. }else{
  320.  
  321. $json = array("status" => "failure","message" =>"This Device Already Exist","code" => "1");
  322. echo json_encode($json);
  323. }
  324.  
  325. } else{
  326. $json = array("status" => "failure","message" =>"Enter Mobile Number","code" => "1");
  327. echo json_encode($json);
  328. }
  329. mysql_close($con);
  330. }
  331.  
  332.  
  333.  
  334. ?>
Add Comment
Please, Sign In to add comment