<?php /* * Following code will get single job details * A job is identified by job id (jobid) */ // array for JSON response $response = array(); // check for post data if (isset($_GET['jobid'])) { // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $con = new DB_CONNECT(); $jobid = safe($con->getlink(), $_GET['jobid']); // get a job from products table $result = mysqli_query($con->getlink(), "SELECT * FROM roster WHERE jobid = '{$jobid}'"); if (!empty($result)) { // check for empty result if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_array($result); $job = array(); $job["jobid"] = $row["jobid"]; $job["jobstatus"] = $row["jobstatus"]; $job["comments"] = $row["comments"]; // user node $response["job"] = array(); array_push($response["job"], $job); // success $response["success"] = 1; // echoing JSON response
<?php /* * Following code will delete a job from table * A job is identified by request id (jobid) */ // array for JSON response $response = array(); // check for required fields if (isset($_POST['jobid'])) { // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $con = new DB_CONNECT(); $jobid = safe($con->getlink(), $_POST['jobid']); // mysql update row with matched jobid $result = mysqli_query($con->getlink(), "DELETE FROM roster WHERE jobid = '{$jobid}'"); // check if row deleted or not if ($result) { // successfully updated $response["success"] = 1; $response["message"] = "Job successfully deleted"; // echoing JSON response echo json_encode($response); } else { // no job found $response["success"] = 0; $response["message"] = "No job found"; // echo no users JSON echo json_encode($response); }
<?php /* * Following code will list all the products */ // array for JSON response $response = array(); // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $con = new DB_CONNECT(); // get all products from products table $result = mysqli_query($con->getlink(), "SELECT * FROM roster"); // check for empty result if (mysqli_num_rows($result) > 0) { // looping through all results // jobs node ////////*****$response["jobs"] = array(); //$response["jobs"] = array(); while ($row = mysqli_fetch_array($result)) { // temp user array $job = array(); $job["rid"] = $row["rid"]; $job["fname"] = $row["fname"]; $job["lname"] = $row["lname"]; $job["mphone"] = $row["mphone"]; $job["hphone"] = $row["hphone"]; $job["jobid"] = $row["jobid"]; $job["sch_start_date"] = $row["sch_start_date"]; $job["sch_start_time"] = $row["sch_start_time"]; $job["jobduration"] = $row["jobduration"];
<?php /* * Following code will update a job information * A job is identified by job id (jobid) */ // array for JSON response $response = array(); // check for required fields if (isset($_POST['jobid']) && isset($_POST['jobstatus']) && isset($_POST['comments'])) { // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $con = new DB_CONNECT(); $jobid = safe($con->getlink(), $_POST['jobid']); $jobstatus = safe($con->getlink(), $_POST['jobstatus']); $comments = safe($con->getlink(), $_POST['comments']); // mysql update row with matched jobid $result = mysqli_query($con->getlink(), "UPDATE roster \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSET jobstatus = '{$jobstatus}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcomments = '{$comments}'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE jobid = '{$jobid}'"); // check if row inserted or not if ($result) { // successfully updated $response["success"] = 1; $response["message"] = "Job successfully updated."; // echoing JSON response echo json_encode($response); } else { // } } else { // required field is missing
<?php /* * Following code will create a new product row * All product details are read from HTTP Post Request */ // array for JSON response $response = array(); // check for required fields if (isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['mphone']) && isset($_POST['hphone']) && isset($_POST['jobid']) && isset($_POST['sch_start_date']) && isset($_POST['sch_start_time']) && isset($_POST['jobduration']) && isset($_POST['act_start_date']) && isset($_POST['act_start_time']) && isset($_POST['act_end_date']) && isset($_POST['act_end_time']) && isset($_POST['jobstatus']) && isset($_POST['address']) && isset($_POST['comments'])) { // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $con = new DB_CONNECT(); $fname = safe($con->getlink(), $_POST['fname']); $lname = safe($con->getlink(), $_POST['lname']); $mphone = safe($con->getlink(), $_POST['mphone']); $hphone = safe($con->getlink(), $_POST['hphone']); $jobid = safe($con->getlink(), $_POST['jobid']); $sch_start_date = safe($con->getlink(), $_POST['sch_start_date']); $sch_start_time = safe($con->getlink(), $_POST['sch_start_time']); $jobduration = safe($con->getlink(), $_POST['jobduration']); $act_start_date = safe($con->getlink(), $_POST['act_start_date']); $act_start_time = safe($con->getlink(), $_POST['act_start_time']); $act_end_date = safe($con->getlink(), $_POST['act_end_date']); $act_end_time = safe($con->getlink(), $_POST['act_end_time']); $jobstatus = safe($con->getlink(), $_POST['jobstatus']); $address = safe($con->getlink(), $_POST['address']); $comments = safe($con->getlink(), $_POST['comments']); // mysql inserting a new row $result = mysqli_query($con->getlink(), "INSERT INTO roster (fname, lname, mphone, hphone, jobid, sch_start_date, sch_start_time, jobduration, act_start_date, act_start_time, act_end_date, act_end_time, jobstatus, address, comments) VALUES('{$fname}','{$lname}', '{$mphone}', '{$hphone}', '{$jobid}', '{$sch_start_date}', '{$sch_start_time}', '{$jobduration}', '{$act_start_date}', '{$act_start_time}', '{$act_end_date}', '{$act_end_time}', '{$jobstatus}', '{$address}', '{$comments}')");