Advertisement
Guest User

Untitled

a guest
May 15th, 2018
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.37 KB | None | 0 0
  1. <?php
  2. header("Access-Control-Allow-Origin: *");
  3. header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
  4. header('Content-Type: application/json');
  5. $dbhost = "=";
  6. $dbname = "";
  7. $dbusername = "";
  8. $dbpassword = "";
  9.  
  10.  
  11. if($_GET['action'] == 'get_projects'){
  12. $params = json_decode(file_get_contents('php://input'),true);
  13. try {
  14. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  15.  
  16. $stmt = $pdo->prepare("SELECT * FROM projects");
  17. $stmt->execute();
  18. $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
  19. echo json_encode(array(
  20. 'success' => true,
  21. 'data' => $data,
  22. ));
  23. } catch (PDOException $e){
  24. echo json_encode(
  25. array(
  26. 'success' => false,
  27. 'message' => $e->getMessage(),
  28. )
  29. );
  30. }
  31. }
  32.  
  33. if($_GET['action'] == 'get_project'){
  34. $params = json_decode(file_get_contents('php://input'),true);
  35. try {
  36. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  37.  
  38. $stmt = $pdo->prepare("SELECT * FROM projects WHERE id = :id");
  39. $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
  40. $stmt->execute();
  41. $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
  42. echo json_encode(array(
  43. 'success' => true,
  44. 'data' => $data,
  45. ));
  46. } catch (PDOException $e){
  47. echo json_encode(
  48. array(
  49. 'success' => false,
  50. 'message' => $e->getMessage(),
  51. )
  52. );
  53. }
  54. }
  55.  
  56.  
  57. if($_GET['action'] == 'update_project'){
  58. $params = json_decode(file_get_contents('php://input'),true);
  59. try {
  60. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  61. $stmt = $pdo->prepare("UPDATE projects SET name = :name, description = :description, status = :status WHERE id = :id");
  62. $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
  63. $stmt->bindParam(':name', $params['name']);
  64. $stmt->bindParam(':description', $params['description']);
  65. $stmt->bindParam(':status', $params['status']);
  66. $stmt->execute();
  67. echo json_encode(
  68. array('success' => true)
  69. );
  70. } catch (PDOException $e){
  71. echo json_encode(
  72. array(
  73. 'success' => false,
  74. 'message' => $e->getMessage(),
  75. )
  76. );
  77. }
  78. }
  79.  
  80. if($_GET['action'] == 'add_project'){
  81. $params = json_decode(file_get_contents('php://input'),true);
  82. try {
  83. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  84. $stmt = $pdo->prepare("INSERT INTO projects (name, description, author_id, status, create_date) VALUES (:name, :description, :author_id, :status, :create_date)");
  85. $stmt->bindParam(':name', $params['name']);
  86. $stmt->bindParam(':description', $params['description']);
  87. $stmt->bindParam(':author_id', $params['author_id'], PDO::PARAM_INT);
  88. $stmt->bindParam(':status', $params['status']);
  89. $date = date("Y-m-d H:i:s");
  90. $stmt->bindParam(":create_date", $date);
  91. $stmt->execute();
  92.  
  93. $newProjectId = $pdo->lastInsertId();
  94.  
  95. echo json_encode(
  96. array(
  97. 'success' => true,
  98. 'project_id' => $newProjectId,
  99. )
  100. );
  101. } catch (PDOException $e){
  102. echo json_encode(
  103. array(
  104. 'success' => false,
  105. 'message' => $e->getMessage(),
  106. )
  107. );
  108. }
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. // USERS
  118. if($_GET['action'] == 'add_user'){
  119. $params = json_decode(file_get_contents('php://input'),true);
  120.  
  121. try {
  122. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  123. $stmt = $pdo->prepare("INSERT INTO users (firstname, lastname, email, password, profession, system_role, create_date) VALUES (:firstname, :lastname, :email, :password, :profession, :system_role, :create_date)");
  124. $stmt->bindParam(':firstname', $params['firstname']);
  125. $stmt->bindParam(':lastname', $params['lastname']);
  126. $stmt->bindParam(':email', $params['email']);
  127.  
  128. $stmt->bindParam(':profession', $params['profession']);
  129. $stmt->bindParam(':system_role', $params['system_role']);
  130.  
  131. $password = md5($params['password']);
  132. $stmt->bindParam(':password', $password);
  133.  
  134. $date = date("Y-m-d H:i:s");
  135. $stmt->bindParam(":create_date", $date);
  136. $stmt->execute();
  137.  
  138. $newUserId = $pdo->lastInsertId();
  139.  
  140. echo json_encode(
  141. array(
  142. 'success' => true,
  143. 'user_id' => $newUserId,
  144. )
  145. );
  146. } catch (PDOException $e){
  147. echo json_encode(
  148. array(
  149. 'success' => false,
  150. 'message' => $e->getMessage(),
  151. )
  152. );
  153. }
  154. }
  155.  
  156. if($_GET['action'] == 'get_user'){
  157. $params = json_decode(file_get_contents('php://input'),true);
  158. try {
  159. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  160.  
  161. $stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");
  162. $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
  163. $stmt->execute();
  164. $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
  165. echo json_encode(array(
  166. 'success' => true,
  167. 'data' => $data,
  168. ));
  169. } catch (PDOException $e){
  170. echo json_encode(
  171. array(
  172. 'success' => false,
  173. 'message' => $e->getMessage(),
  174. )
  175. );
  176. }
  177. }
  178.  
  179. if($_GET['action'] == 'get_users'){
  180. $params = json_decode(file_get_contents('php://input'),true);
  181. try {
  182. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  183.  
  184. $stmt = $pdo->prepare("SELECT * FROM users");
  185. $stmt->execute();
  186. $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
  187. echo json_encode(array(
  188. 'success' => true,
  189. 'data' => $data,
  190. ));
  191. } catch (PDOException $e){
  192. echo json_encode(
  193. array(
  194. 'success' => false,
  195. 'message' => $e->getMessage(),
  196. )
  197. );
  198. }
  199. }
  200.  
  201.  
  202. if($_GET['action'] == 'login'){
  203. $params = json_decode(file_get_contents('php://input'),true);
  204. try {
  205. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  206.  
  207. $stmt = $pdo->prepare("SELECT * FROM users WHERE email = :email && password = :password");
  208. $stmt->bindParam(':email', $params['email']);
  209.  
  210. $password = md5($params['password']);
  211. $stmt->bindParam(':password', $password);
  212.  
  213. $stmt->execute();
  214. $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
  215.  
  216. // $data = var_dump($data[0], array('password'));
  217. unset($data[0]['password']);
  218.  
  219. echo json_encode(array(
  220. 'success' => true,
  221. 'data' => $data,
  222. ));
  223. } catch (PDOException $e){
  224. echo json_encode(
  225. array(
  226. 'success' => false,
  227. 'message' => $e->getMessage(),
  228. )
  229. );
  230. }
  231. }
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238. //ISSUES
  239. if($_GET['action'] == 'get_issues'){
  240. $params = json_decode(file_get_contents('php://input'),true);
  241. try {
  242. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  243.  
  244. $stmt = $pdo->prepare("SELECT * FROM issues WHERE project_id = :project_id");
  245. $stmt->bindParam(':project_id', $params['project_id'], PDO::PARAM_INT);
  246. $stmt->execute();
  247. $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
  248. echo json_encode(array(
  249. 'success' => true,
  250. 'data' => $data,
  251. ));
  252. } catch (PDOException $e){
  253. echo json_encode(
  254. array(
  255. 'success' => false,
  256. 'message' => $e->getMessage(),
  257. )
  258. );
  259. }
  260. }
  261.  
  262. if($_GET['action'] == 'get_issue'){
  263. $params = json_decode(file_get_contents('php://input'),true);
  264. try {
  265. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  266.  
  267. $stmt = $pdo->prepare("SELECT * FROM issues WHERE id = :id");
  268. $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
  269. $stmt->execute();
  270. $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
  271. echo json_encode(array(
  272. 'success' => true,
  273. 'data' => $data,
  274. ));
  275. } catch (PDOException $e){
  276. echo json_encode(
  277. array(
  278. 'success' => false,
  279. 'message' => $e->getMessage(),
  280. )
  281. );
  282. }
  283. }
  284.  
  285. if($_GET['action'] == 'update_issue'){
  286. $params = json_decode(file_get_contents('php://input'),true);
  287. try {
  288. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  289. $stmt = $pdo->prepare("UPDATE issues SET name = :name, description = :description, status = :status, priority = :priority, estimated_time = :estimated_time, assigneduser_id = :assigneduser_id, type = :type, progress = :progress WHERE id = :id");
  290. $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
  291. $stmt->bindParam(':assigneduser_id', $params['assigneduser_id'], PDO::PARAM_INT);
  292. $stmt->bindParam(':name', $params['name']);
  293. $stmt->bindParam(':description', $params['description']);
  294. $stmt->bindParam(':status', $params['status']);
  295. $stmt->bindParam(':priority', $params['priority']);
  296. $stmt->bindParam(':estimated_time', $params['estimated_time']);
  297. $stmt->bindParam(':type', $params['type']);
  298. $stmt->bindParam(':progress', $params['progress']);
  299. $stmt->execute();
  300. echo json_encode(
  301. array('success' => true)
  302. );
  303. } catch (PDOException $e){
  304. echo json_encode(
  305. array(
  306. 'success' => false,
  307. 'message' => $e->getMessage(),
  308. )
  309. );
  310. }
  311. }
  312.  
  313. if($_GET['action'] == 'add_issue'){
  314. $params = json_decode(file_get_contents('php://input'),true);
  315. try {
  316. $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
  317. $stmt = $pdo->prepare("INSERT INTO issues (name, description, author_id, project_id, status, priority, estimated_time, assigneduser_id, worked_time, type, progress, create_date) VALUES (:name, :description, :author_id, :project_id, :status, :priority, :estimated_time, :assigneduser_id, :worked_time, :type, :progress, :create_date)");
  318. $stmt->bindParam(':name', $params['name']);
  319. $stmt->bindParam(':description', $params['description']);
  320. $stmt->bindParam(':author_id', $params['author_id'], PDO::PARAM_INT);
  321. $stmt->bindParam(':project_id', $params['project_id'], PDO::PARAM_INT);
  322. $stmt->bindParam(':assigneduser_id', $params['assigneduser_id'], PDO::PARAM_INT);
  323. $stmt->bindParam(':status', $params['status']);
  324. $stmt->bindParam(':priority', $params['priority']);
  325. $stmt->bindParam(':estimated_time', $params['estimated_time']);
  326. $stmt->bindParam(':worked_time', $params['worked_time']);
  327. $stmt->bindParam(':type', $params['type']);
  328. $stmt->bindParam(':progress', $params['progress']);
  329. $date = date("Y-m-d H:i:s");
  330. $stmt->bindParam(":create_date", $date);
  331. $stmt->execute();
  332.  
  333. $newIssueId = $pdo->lastInsertId();
  334.  
  335. echo json_encode(
  336. array(
  337. 'success' => true,
  338. 'issue_id' => $newIssueId,
  339. )
  340. );
  341. } catch (PDOException $e){
  342. echo json_encode(
  343. array(
  344. 'success' => false,
  345. 'message' => $e->getMessage(),
  346. )
  347. );
  348. }
  349. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement