sammarks

My Longest AJAX File

May 29th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. <?php
  2.     include("../../php/fw.php"); $f = new PTracker();
  3.    
  4.     // Initialize Variables
  5.     $db = $f->Connect();
  6.     $prefix = $f->GetOpt("db", "tablePrefix");
  7.    
  8.     $title = $_POST["title"];
  9.     $authorID = $_POST["authorID"];
  10.     $authorUsername = $_POST["authorUsername"];
  11.     $projectID = $_POST["projectID"];
  12.     $projectName = $_POST["projectName"];
  13.     $priorityID = $_POST["priorityID"];
  14.     $priorityName = $_POST["priorityName"];
  15.     $priorityColor = $_POST["priorityColor"];
  16.     $stateID = $_POST["stateID"];
  17.     $stateName = $_POST["stateName"];
  18.     $type = $_POST["type"];
  19.     $assignedTo = $_POST["assignedTo"];
  20.     $assignedToID = $_POST["assignedToID"];
  21.    
  22.     $jsonReturn = array();
  23.     $jsonReturn["error"] = 50;
  24.     $jsonReturn["errorMessage"] = "okay";
  25.    
  26.     // Create queries.
  27.     $checkTitleQuery = "select * from ".$prefix."tickets where `title` = '$title' where `projectID` = '$projectID';";
  28.     $updateTicketCount = "update ".$prefix."projects set `tickets` = `tickets` + 1 where `id` = '$projectID';";
  29.     $insertQuery = "insert into ".$prefix."tickets (
  30.         `title`, `authorID`, `authorUsername`, `projectID`, `projectName`, `priorityID`,
  31.         `priorityName`, `priorityColor`, `stateID`, `stateName`, `type`, `assignedTo`, `assignedToID`) values (
  32.         '$title', '$authorID', '$authorUsername', '$projectID', '$projectName', '$priorityID', '$priorityName',
  33.         '$priorityColor', '$stateID', '$stateName', '$type', '$assignedTo', '$assignedToID' );";
  34.        
  35.     // Perform Checks
  36.     $res = $db->query($checkTitleQuery);
  37.     if (mysqli_error($db) != "") {
  38.         $jsonReturn["error"] = 100;
  39.         $jsonReturn["errorMessage"] = mysqli_error($db);
  40.         die(json_encode($jsonReturn));
  41.     }
  42.     if ($res->num_rows > 0) {
  43.         $jsonReturn["error"] = 101;
  44.         $jsonReturn["errorMessage"] = "That ticket already exists.";
  45.         die(json_encode($jsonReturn));
  46.     }
  47.    
  48.     // Insert into the table.
  49.     $db->query($insertQuery);
  50.     if (mysqli_error($db) != "") {
  51.         $jsonReturn["error"] = 100;
  52.         $jsonReturn["errorMessage"] = mysqli_error($db);
  53.         die(json_encode($jsonReturn));
  54.     }
  55.    
  56.     // Update the ticket count.
  57.     $db->query($updateTicketCount);
  58.     if (mysqli_error($db) != "") {
  59.         $jsonReturn["error"] = 100;
  60.         $jsonReturn["errorMessage"] = mysqli_error($db);
  61.         die(json_encode($jsonReturn));
  62.     }
  63.    
  64.     // All was successful.
  65.     die(json_encode($jsonReturn));
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment