Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. <?php
  2. //NOT MEANT TO BE LOADED BY BROWSER. ONLY AJAX CALLS.
  3. header('Cache-Control: no-cache, must-revalidate');
  4. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  5. header('Content-type: application/json');
  6. require("../util/sql.php");
  7. require("../util/usercheck.php");
  8. require("../util/json.php");
  9. require("../util/undo.php");
  10.  
  11. isset($_SESSION['user']) or dieWithError("Not Logged On!");
  12. assertSuperuser() or dieWithError("Unauthorised!");
  13.  
  14. isset($_GET['tab']) or dieWithError("Invalid Request!");
  15.  
  16. $user = $_SESSION['user'];
  17.  
  18.  
  19. function mustBeSet($obj){
  20. isset($obj) or dieWithError("Invalid Request");
  21. return $obj;
  22. }
  23.  
  24. switch($_GET['tab']){
  25. case 'csc': //country state city..
  26. $add = mysql_real_escape_string(mustBeSet($_GET['type']));
  27. switch($add){
  28. case 'addCountry':
  29. $country = mysql_real_escape_string(mustBeSet($_POST['country']));
  30. $res = mysql_query("insert into `country`(`Name`) values('$country');") or dieWithError("Unable to insert!");
  31. $id = mysql_insert_id();
  32. $undoId = addMySQLUndo("delete from `country` where Id=$id;");
  33. dieWithGoodResult(array("id"=>$id,"undoID"=>$undoId));
  34. case 'addState':
  35. $countryId = mysql_real_escape_string(mustBeSet($_POST['country_id']));
  36. $state = mysql_real_escape_string(mustBeSet($_POST['state']));
  37. $res = mysql_query("insert into `state`(`Name`,`CountryId`) values('$state',$countryId);") or dieWithError("Unable to insert!");
  38. $id = mysql_insert_id();
  39. $undoId = addMySQLUndo("delete from `state` where Id=$id;");
  40. dieWithGoodResult(array("id"=>$id, "undoID"=>$undoId));
  41. case 'addCity':
  42. $stateId = mysql_real_escape_string(mustBeSet($_POST['state_id']));
  43. $city = mysql_real_escape_string(mustBeSet($_POST['city']));
  44. $res = mysql_query("insert into `city`(`Name`,`StateId`) values('$city',$stateId);")or dieWithError("Unable to insert");
  45. $id = mysql_insert_id();
  46. $undoId = addMySQLUndo("delete from `city` where Id=$id;");
  47. dieWithGoodResult(array("id"=>$id, "undoID"=>$undoId));
  48. case 'addZone':
  49. $priId = mysql_real_escape_string(mustBeSet($_POST['pri_id']));
  50. $zone = mysql_real_escape_string(mustBeSet($_POST['zone']));
  51. $res = mysql_query("insert into `zone`(`PrimaryOrganizationID`,`Name`) values($priId,'$zone');")or dieWithError("Unable to insert");
  52. $id = mysql_insert_id();
  53. $undoId = addMySQLUndo("delete from `city` where Id=$id;");
  54. dieWithGoodResult(array("id"=>$id, "undoID"=>$undoId));
  55. case 'getCountries':
  56. $res = mysql_query("select `Id`,`Name` from `country`;") or dieWithError("Unable to retrieve");
  57. $arr = getAllRecords($res);
  58. dieWithGoodResult(array("records"=>$arr));
  59. case 'getStates':
  60. $countryId = mysql_real_escape_string(mustBeSet($_POST['country_id']));
  61. $res = mysql_query("select `Id`,`Name` from `state` where CountryId=$countryId;") or dieWithError("Unable to retrieve");
  62. $arr = getAllRecords($res);
  63. dieWithGoodResult(array("records"=>$arr));
  64. case 'getCities':
  65. $stateId = mysql_real_escape_string(mustBeSet($_POST['state_id']));
  66. $res = mysql_query("select `Id`,`Name` from `city` where StateId=$stateId;") or dieWithError("Unable to retrieve");
  67. $arr = getAllRecords($res);
  68. dieWithGoodResult(array("records"=>$arr));
  69. case 'getZones':
  70. $priId = mysql_real_escape_string(mustBeSet($_POST['pri_id']));
  71. $res = mysql_query("select * from `zone` where PrimaryOrganizationID=$priId;") or dieWithError("Unable to retrieve");
  72. $arr = getAllRecords($res);
  73. dieWithGoodResult(array("records"=>$arr));
  74. case 'getSecOrg':
  75. $priId = mysql_real_escape_string(mustBeSet($_POST['pri_id']));
  76. $res = mysql_query("select * from `secondaryorganizationmaster` where PrimaryOrganizationID=$priId and current=1;") or dieWithError("Unable to retrieve");
  77. $arr = getAllRecords($res);
  78. dieWithGoodResult(array("records"=>$arr));
  79. default:
  80. mustBeSet(null);
  81. }
  82. case 'pri':
  83. $name = mysql_real_escape_string(mustBeSet($_POST['pri_name']));
  84. if (isset($_POST['pri_id'])){
  85. $id = mysql_real_escape_string($_POST['pri_id']);
  86. if (!is_numeric($id))
  87. dieWithError("Id should be numeric!");
  88. $res = mysql_query("select * from `primaryorganizationmaster` where Id=$id;") or dieWithError("No such Id exists.");
  89. $row = mysql_fetch_array($res);
  90. $name = $row['Name'];
  91. }else{
  92. $res=mysql_query("insert into `primaryorganizationmaster`(`Name`,`CreatedBy`,`CreatedOn`,`Current`) values('$name','$user',NOW(),1);") or dieWithError("Unable to insert: " .mysql_error());
  93. $id = mysql_insert_id();
  94. $undoId = addMySQLUndo("delete from `primaryorganizationmaster` where Id=$id;");
  95. dieWithGoodResult(array("id"=>$id,"undoID"=>$undoId));
  96. }
  97. break;
  98. case 'SecOrg':
  99. switch(mustBeSet($_GET['type'])){
  100. case "update":
  101. $id = mysql_real_escape_string(mustBeSet($_POST['sec_id']));
  102. $newval = mysql_real_escape_string(mustBeSet($_POST['name']));
  103. if (!is_numeric($id))
  104. dieWithError("Id should be numeric!");
  105. $res = mysql_query("update secondaryorganizationmaster set Current=0 where Id=$id;") or dieWithError("No such Id exists.");
  106. $row = mysql_fetch_assoc(mysql_query("select * from secondaryorganizationmaster where Id=$id;"));
  107.  
  108. $query = "insert into `secondaryorganizationmaster`(`PrimaryOrganizationID`, `Name`, `Country`, `State`, `City`, `Zone`, `Address`, `PostalCode`, `BoardLineNo`, `EmailAddress`, `CreatedBy`,`CreatedOn`,`Current`,`OriginalPK`) values({$row['PrimaryOrganizationID']}, '$newval', {$row['Country']}, {$row['State']}, {$row['City']}, {$row['Zone']}, '{$row['Address']}', '{$row['PostalCode']}', '{$row['BoardLineNo']}', '{$row['EmailAddress']}','{$user}',NOW(),1,{$row['OriginalPK']});";
  109.  
  110. $res = mysql_query($query) or dieWithError("ERRRORORO!!");
  111. dieWithGoodResult(array());
  112.  
  113. }
  114.  
  115. case 'usr':
  116. $usrFname = mysql_real_escape_string(mustBeSet($_POST['usr_Fname']));
  117. $superuser= mustbeSet($_POST['usr_Su'])=="true"? "1":"0";
  118. $usrLname = mysql_real_escape_string(mustBeSet($_POST['usr_Lname']));
  119. $usrID = mysql_real_escape_string(mustBeSet($_POST['usr_Id']));
  120. $usrPassword = mysql_real_escape_string(mustBeSet($_POST['usr_Password']));
  121. $str = "insert into `usermaster`(`UserID`,`Password`,`Fname`,`Lname`,`Validity`,`SuperUser`,`CreatedBy`,`CreatedOn`)
  122. values ('$usrID','$usrPassword','$usrFname','$usrLname',365,$superuser,'$user',NOW());";
  123. //echo $str;
  124. $res = mysql_query($str); //validity,superuser missing
  125. mustBeSet($res,"Unable to insert!");
  126. dieWithGoodResult(array("id"=>$usrID));
  127. break;
  128. }
  129. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement