can u please refer the marking guide

1 answer below »
can u please refer the marking guide
Answered Same DaySep 20, 2021ITECH3108Federation University Australia

Answer To: can u please refer the marking guide

Mohd answered on Sep 25 2021
137 Votes
php/ajax/ajax.php
include "config.php";
include_once "Common.php";
if (isset($_POST['addEvent']) == "addEvent"){
$eventName = $_POST['eventName'];
$eventTime = $_POST['eventTime'];
$posterName = $_POST['posterName'];
$eventDescription = $_POST['eventDescription'];
$common = new Common();
$save = $common->saveEvents($connection,$eventName,$eventTime,$posterName,$eventDescription);
if ($save){
echo "test^saved";
}
}
if (isset($_POST['getAllEvents']) == "getAllEvents"){
$eventData = '';
$common = new Common();
$allEvents = $common->getAllEvents($connection);
if ($allEvents->num_rows>0){
while ($row = $allEvents->fetch_object()){
$eventId = $row->id;
$eventName = $row->eventName;
$eventTime = $row->eventTime;
$postedDate = date('jS M Y', strtotime($row->postedDate));
$posterName = $row->posterName;
$eventDescription = $row->eventDescription;
$getVoteCount = $common->getVoteCount($connection,$eventId);
if ( $posterName !=""){
$posterName = $posterName;
}else{
$posterName = "Anonymous";
}
$eventDetailUrl = "post?id=".$eventId;
$eventData .= '

  • '.$eventName.'

    '.$postedDate.'
    class="btn btn-warning btn-sm">Vote '.$getVoteCount.'
    class="btn btn-success btn-sm">Suggest
    '.$posterName.'

  • ';
    }
    }
    echo "test^".$eventData;
    }
    if (isset($_POST['voteTheEvent']) == "voteTheEvent"){
    $voterName = $_POST['voterName'];
    $eventId = $_POST['eventId'];
    $common = new Common();
    $save = $common->saveVotting($connection,$voterName,$eventId);
    if ($save){
    echo "test^voted";
    }
    }
    if (isset($_POST['addVoter']) == "addVoter"){
    $voterName = $_POST['voterName'];
    $eventId = $_POST['eventId'];
    $common = new Common();
    $add = $common->addVoter($connection,$voterName,$eventId);
    if ($add){
    echo "test^added";
    }
    }
    if (isset($_POST['getAllVoters']) == "getAllVoters"){
    $eventId = $_POST['eventId'];
    $data = '';
    $data .= '
    Voter Name
    ';
    $common = new Common();
    $voters = $common->getAllVoters($connection,$eventId);
    if ($voters->num_rows>0){
    while ($row = $voters->fetch_object()){
    $data .= '

    '.$row->voters.'
    ';
    }
    }
    echo "test^".$data;
    }
    if (isset($_POST['suggestTiming']) == "suggestTiming"){
    $posterName = $_POST['posterName'];
    $suggestTiming = $_POST['suggestedTime'];
    $eventId = $_POST['eventId'];
    $common = new Common();
    $save = $common->saveSuggestion($connection,$posterName,$suggestTiming,$eventId);
    if ($save){
    echo "test^saved";
    }
    }
    if (isset($_POST['getAllSuggestions']) == "getAllSuggestions"){
    $data = '';
    $eventId = $_POST['eventId'];
    $common = new Common();
    $voters = $common->getAllSuggestions($connection,$eventId);
    if ($voters->num_rows>0){
    while ($row = $voters->fetch_object()){
    if ( $row->user !=""){
    $suggestor = $row->user;
    }else{
    $suggestor = "Anonymous";
    }
    $data .= '

    '.$row->suggestedTime.'
    '.$suggestor.'
    ';
    }
    }
    echo "test^".$data;
    }
    php/ajax/Common.php
    class Common
    {
    public function saveEvents($connection,$eventName,$eventTime,$posterName,$eventDescription )
    {
    if ($posterName == ""){
    $posterName = "";
    }else{
    $posterName = $posterName;
    }
    $mainQuery = "INSERT INTO dancing_events SET eventName='$eventName',eventTime='$eventTime',posterName='$posterName',eventDescription='$eventDescription'";
    $result1 = $connection->query($mainQuery) or die("Error in event Query".$connection->error);
    return $result1;
    }
    public function getAllEvents($connection)
    {
    $mainQuery = "SELECT * FROM dancing_events ORDER BY id DESC ";
    $result1 = $connection->query($mainQuery) or die("Error in event fetching query".$connection->error);
    return $result1;
    }
    public function getEventDetail($connection,$postId)
    {
    $query = "SELECT * FROM dancing_events WHERE id='$postId'" ;
    $result1 = $connection->query($query) or die("Error in event fetching query".$connection->error);
    return $result1;
    }
    public function saveVotting($connection,$voterName,$eventId)
    {
    $query = "INSERT INTO votes SET eventId='$eventId',voterName='$voterName'";
    $result1 = $connection->query($query) or die("Error in query".$connection->error);
    return $result1;
    }
    public function getVoteCount($connection,$eventId)
    {
    $query = "SELECT COUNT(*) as totalVotes FROM votes WHERE eventId='$eventId'";
    $result1 = $connection->query($query) or die("Error in query".$connection->error);
    if ($result1){
    $row = $result1->fetch_object();
    }
    return $row->totalVotes;
    }
    public function addVoter($connection,$voterName,$eventId)
    {
    $query = "INSERT INTO voters SET voters='$voterName',eventId='$eventId'";
    $result1 = $connection->query($query) or die("Error in query".$connection->error);
    return $result1;
    }
    public function getAllVoters($connection,$eventID)
    {
    $query = "SELECT * FROM voters WHERE eventId='$eventID' ";
    $result1 = $connection->query($query) or die("Error in query".$connection->error);
    return $result1;
    }
    public function saveSuggestion($connection,$posterName,$suggestTiming,$eventId)
    {
    if ($posterName !=""){
    $posterName = $posterName;
    }else{
    $posterName = "";
    }
    $query = "INSERT INTO time_suggestions SET eventId='$eventId',suggestedTime='$suggestTiming',user='$posterName'";
    $result1 = $connection->query($query) or die("Error in query".$connection->error);
    return $result1;
    }
    public function getAllSuggestions($connection,$eventID)
    {
    $query = "SELECT * FROM time_suggestions WHERE eventId='$eventID'";
    $result1 = $connection->query($query) or die("Error in query".$connection->error);
    return $result1;
    }
    }
    php/ajax/config.php
    global $connection;
    $connection = new Mysqli("localhost","root","","dancing_event");
    if (!$connection){
    die("Error in connection".$connection->connect_error);
    }
    .htaccess
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    api.php
    include "php/ajax/config.php";
    include_once "php/ajax/Common.php";
    if (isset($_GET['name'])){
    $apiName = $_GET['name'];
    switch ($apiName){
    case "events":
    $response = array();
    $common = new Common();
    $allEvents = $common->getAllEvents($connection);
    while ($row = $allEvents->fetch_object()){
    $response[] = $row;
    }
    echo json_encode($response);
    break;
    }
    }
    dancing_event.sql
    -- phpMyAdmin SQL Dump
    -- version 4.8.3
    -- https://www.phpmyadmin.net/
    --
    -- Host: 127.0.0.1
    -- Generation Time: Sep 25, 2019 at 06:02 PM
    -- Server version: 10.1.36-MariaDB
    -- PHP Version: 7.0.32
    SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
    SET AUTOCOMMIT = 0;
    START TRANSACTION;
    SET time_zone = "+00:00";
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8mb4 */;
    --
    -- Database: `dancing_event`
    --
    -- --------------------------------------------------------
    --
    -- Table structure for table `dancing_events`
    --
    CREATE TABLE `dancing_events` (
    `id` int(11) NOT NULL,
    `eventName` varchar(255) NOT NULL,
    `eventTime` varchar(100) NOT NULL,
    `postedDate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `posterName` varchar(100) NOT NULL,
    `eventDescription` varchar(255) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    --
    -- Dumping data for table `dancing_events`
    --
    INSERT INTO `dancing_events` (`id`, `eventName`, `eventTime`, `postedDate`,...
    SOLUTION.PDF

    Answer To This Question Is Available To Download

    Related Questions & Answers

    More Questions »

    Submit New Assignment

    Copy and Paste Your Assignment Here