Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
klinetr authored Sep 10, 2021
1 parent c94e6aa commit ceb9f03
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 0 deletions.
52 changes: 52 additions & 0 deletions DeleteContact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

<?php

$inData = getRequestInfo();

$userId = $inData["userId"];
$contactId = $inData["contactId"];

$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager");
if( $conn->connect_error )
{
returnWithError( $conn->connect_error );
}
else
{
$sql = "DELETE FROM List WHERE ID = '$contactId' AND UserID = '$userId'";
//$stmt->execute();
//$result = $stmt->get_result();
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
//$stmt->close();
$conn->close();
returnWithError("");
}

function getRequestInfo()
{
return json_decode(file_get_contents('php://input'), true);
}

function sendResultInfoAsJson( $obj )
{
header('Content-type: application/json');
echo $obj;
}

function returnWithError( $err )
{
$retValue = '{"error":"' . $err . '"}';
sendResultInfoAsJson( $retValue );
}

//function returnWithInfo( $firstName, $lastName, $id )
//{
// $retValue = '{"id":' . $id . ',"firstName":"' . $firstName . '","lastName":"' . $lastName . '","error":""}';
// sendResultInfoAsJson( $retValue );
//}

?>
69 changes: 69 additions & 0 deletions Register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
$inData = getRequestInfo();

$firstname = $inData["firstName"];
$lastname = $inData["lastName"];
$email = $inData["email"];
$phonenumber = $inData["phoneNumber"];
$login = $inData["login"];
$password = $inData["password"];
$id =0;

$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager");
if ($conn->connect_error)
{
returnWithError( $conn->connect_error );
}
else
{
$sql = "INSERT INTO Users (FirstName,LastName,Email,PhoneNumber,Login,Password)
VALUES('$firstname', '$lastname', '$email', '$phonenumber', '$login', '$password')";

if ($conn->query($sql) === TRUE) {
echo "New user created successfully", "\n";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$stmt = $conn->prepare("SELECT ID FROM Users WHERE Login=? AND Password =?");
$stmt->bind_param("ss", $login, $password);
$stmt->execute();
$result = $stmt->get_result();

if( $row = $result->fetch_assoc() )
{
returnWithInfo( $row['ID']);
}
else
{
returnWithError("No Records Found");
}

$stmt->close();
$conn->close();
returnWithError("");
}

function getRequestInfo()
{
return json_decode(file_get_contents('php://input'), true);
}

function sendResultInfoAsJson( $obj )
{
header('Content-type: application/json');
echo $obj;
}

function returnWithError( $err )
{
$retValue = '{"error":"' . $err . '"}';
sendResultInfoAsJson( $retValue );
}
function returnWithInfo( $id )
{
$retValue = '{"id":' . $id . '}';
sendResultInfoAsJson( $retValue );
}

?>
97 changes: 97 additions & 0 deletions SearchContact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

$inData = getRequestInfo();

$searchResults = "";
$searchCount = 0;
$id = 0;

$conn = new mysqli("localhost", "TheManager", "COP4331", "ContactManager");
if ($conn->connect_error)
{
returnWithError( $conn->connect_error );
}
else
{
$stmt = $conn->prepare("SELECT firstName, ID FROM List WHERE firstName LIKE ? AND UserID=?");
$contactName = "%" . $inData["search"] . "%";
$stmt->bind_param("ss", $contactName, $inData["userId"]);
$stmt->execute();

$result = $stmt->get_result();

while($row = $result->fetch_assoc())
{
if( $searchCount > 0 )
{
$searchResults .= ",";
}
$searchCount++;
$searchResults .= '"' . $row["firstName"] . ' ' . $row["ID"] . '"';
}

if( $searchCount == 0 )
{
returnWithError( "No Records Found" );
}

$stmt->close();
$stmt = $conn->prepare("SELECT lastName, ID FROM List WHERE lastName LIKE ? AND UserID=?");
$contactName = "%" . $inData["search"] . "%";
$stmt->bind_param("ss", $contactName, $inData["userId"]);
$stmt->execute();

$result = $stmt->get_result();

while($row = $result->fetch_assoc())
{
if( $searchCount > 0 )
{
$searchResults .= ",";
}
$searchCount++;
$searchResults .= '"' . $row["lastName"] . ' ' . $row["ID"] . '"';
}

if( $searchCount == 0 )
{
returnWithError( "No Records Found" );
}
else
{
returnWithInfo( $searchResults );
error($searchResults);
}
$stmt->close();
$conn->close();
}

function getRequestInfo()
{
return json_decode(file_get_contents('php://input'), true);
}

function sendResultInfoAsJson( $obj )
{
header('Content-type: application/json');
echo $obj;
}

function returnWithError( $err )
{
$retValue = '{"id":0,"firstName":"","lastName":"","error":"' . $err . '"}';
sendResultInfoAsJson( $retValue );
}

function returnWithInfo( $searchResults )
{
$retValue = '{"Contacts":[' . $searchResults . ']}';
sendResultInfoAsJson( $retValue );
}
function error($searchResults)
{
$retValue = '"error":""';
echo "\n";
sendResultInfoAsJson( $retValue );
}
?>

0 comments on commit ceb9f03

Please sign in to comment.