Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Access-Control-Allow-Origin: *");
- header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
- header('Content-Type: application/json');
- $dbhost = "=";
- $dbname = "";
- $dbusername = "";
- $dbpassword = "";
- if($_GET['action'] == 'get_projects'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $stmt = $pdo->prepare("SELECT * FROM projects");
- $stmt->execute();
- $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
- echo json_encode(array(
- 'success' => true,
- 'data' => $data,
- ));
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- if($_GET['action'] == 'get_project'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $stmt = $pdo->prepare("SELECT * FROM projects WHERE id = :id");
- $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
- $stmt->execute();
- $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
- echo json_encode(array(
- 'success' => true,
- 'data' => $data,
- ));
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- if($_GET['action'] == 'update_project'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $stmt = $pdo->prepare("UPDATE projects SET name = :name, description = :description, status = :status WHERE id = :id");
- $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
- $stmt->bindParam(':name', $params['name']);
- $stmt->bindParam(':description', $params['description']);
- $stmt->bindParam(':status', $params['status']);
- $stmt->execute();
- echo json_encode(
- array('success' => true)
- );
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- if($_GET['action'] == 'add_project'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $stmt = $pdo->prepare("INSERT INTO projects (name, description, author_id, status, create_date) VALUES (:name, :description, :author_id, :status, :create_date)");
- $stmt->bindParam(':name', $params['name']);
- $stmt->bindParam(':description', $params['description']);
- $stmt->bindParam(':author_id', $params['author_id'], PDO::PARAM_INT);
- $stmt->bindParam(':status', $params['status']);
- $date = date("Y-m-d H:i:s");
- $stmt->bindParam(":create_date", $date);
- $stmt->execute();
- $newProjectId = $pdo->lastInsertId();
- echo json_encode(
- array(
- 'success' => true,
- 'project_id' => $newProjectId,
- )
- );
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- // USERS
- if($_GET['action'] == 'add_user'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $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)");
- $stmt->bindParam(':firstname', $params['firstname']);
- $stmt->bindParam(':lastname', $params['lastname']);
- $stmt->bindParam(':email', $params['email']);
- $stmt->bindParam(':profession', $params['profession']);
- $stmt->bindParam(':system_role', $params['system_role']);
- $password = md5($params['password']);
- $stmt->bindParam(':password', $password);
- $date = date("Y-m-d H:i:s");
- $stmt->bindParam(":create_date", $date);
- $stmt->execute();
- $newUserId = $pdo->lastInsertId();
- echo json_encode(
- array(
- 'success' => true,
- 'user_id' => $newUserId,
- )
- );
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- if($_GET['action'] == 'get_user'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");
- $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
- $stmt->execute();
- $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
- echo json_encode(array(
- 'success' => true,
- 'data' => $data,
- ));
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- if($_GET['action'] == 'get_users'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $stmt = $pdo->prepare("SELECT * FROM users");
- $stmt->execute();
- $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
- echo json_encode(array(
- 'success' => true,
- 'data' => $data,
- ));
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- if($_GET['action'] == 'login'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $stmt = $pdo->prepare("SELECT * FROM users WHERE email = :email && password = :password");
- $stmt->bindParam(':email', $params['email']);
- $password = md5($params['password']);
- $stmt->bindParam(':password', $password);
- $stmt->execute();
- $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
- // $data = var_dump($data[0], array('password'));
- unset($data[0]['password']);
- echo json_encode(array(
- 'success' => true,
- 'data' => $data,
- ));
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- //ISSUES
- if($_GET['action'] == 'get_issues'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $stmt = $pdo->prepare("SELECT * FROM issues WHERE project_id = :project_id");
- $stmt->bindParam(':project_id', $params['project_id'], PDO::PARAM_INT);
- $stmt->execute();
- $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
- echo json_encode(array(
- 'success' => true,
- 'data' => $data,
- ));
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- if($_GET['action'] == 'get_issue'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $stmt = $pdo->prepare("SELECT * FROM issues WHERE id = :id");
- $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
- $stmt->execute();
- $data = ($stmt->rowCount())? $stmt->fetchAll(PDO::FETCH_ASSOC) : [];
- echo json_encode(array(
- 'success' => true,
- 'data' => $data,
- ));
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- if($_GET['action'] == 'update_issue'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $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");
- $stmt->bindParam(':id', $params['id'], PDO::PARAM_INT);
- $stmt->bindParam(':assigneduser_id', $params['assigneduser_id'], PDO::PARAM_INT);
- $stmt->bindParam(':name', $params['name']);
- $stmt->bindParam(':description', $params['description']);
- $stmt->bindParam(':status', $params['status']);
- $stmt->bindParam(':priority', $params['priority']);
- $stmt->bindParam(':estimated_time', $params['estimated_time']);
- $stmt->bindParam(':type', $params['type']);
- $stmt->bindParam(':progress', $params['progress']);
- $stmt->execute();
- echo json_encode(
- array('success' => true)
- );
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
- if($_GET['action'] == 'add_issue'){
- $params = json_decode(file_get_contents('php://input'),true);
- try {
- $pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbusername, $dbpassword);
- $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)");
- $stmt->bindParam(':name', $params['name']);
- $stmt->bindParam(':description', $params['description']);
- $stmt->bindParam(':author_id', $params['author_id'], PDO::PARAM_INT);
- $stmt->bindParam(':project_id', $params['project_id'], PDO::PARAM_INT);
- $stmt->bindParam(':assigneduser_id', $params['assigneduser_id'], PDO::PARAM_INT);
- $stmt->bindParam(':status', $params['status']);
- $stmt->bindParam(':priority', $params['priority']);
- $stmt->bindParam(':estimated_time', $params['estimated_time']);
- $stmt->bindParam(':worked_time', $params['worked_time']);
- $stmt->bindParam(':type', $params['type']);
- $stmt->bindParam(':progress', $params['progress']);
- $date = date("Y-m-d H:i:s");
- $stmt->bindParam(":create_date", $date);
- $stmt->execute();
- $newIssueId = $pdo->lastInsertId();
- echo json_encode(
- array(
- 'success' => true,
- 'issue_id' => $newIssueId,
- )
- );
- } catch (PDOException $e){
- echo json_encode(
- array(
- 'success' => false,
- 'message' => $e->getMessage(),
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement