<?php 

function GetServiceType($value)
{
    $servicetype = "";
    if($value == 1)
    {
        $servicetype = "One Service Charge";
    }
    else if($value == 2)
    {
        $servicetype = "Service package listing";
    }
    return $servicetype;
}


function GetUserID($username, \database $con)
{
    $user_id = "";
    $sql = "select id from users where email=:username";
    $q=$con->select_query($sql,array(':username'=>$username));
    foreach($q as $r)
    {
        $user_id = $r['id'];
    }
    return $user_id;
}

function GetTotalComplaint($userid, \database $con)
{
    $total = 0;
    $sql = "select id from complaints where user_id=:id";
    $q=$con->select_query($sql,array(':id'=>$userid));
    $total = count($q);
    return $total;
}

function GetTotalAcceptedComplaint($userid, \database $con)
{
    $total = 0;
    $sql = "select id from complaints where user_id=:id AND status=:status";
    $q=$con->select_query($sql,array(':id'=>$userid,':status'=>ACCEPTED_STATUS));
    $total = count($q);
    return $total;
}

function GetTotalResolvedComplaint($userid, \database $con)
{
    $total = 0;
    $sql = "select id from complaints where user_id=:id AND status=:status";
    $q=$con->select_query($sql,array(':id'=>$userid,':status'=>RESOLVED_STATUS));
    $total = count($q);
    return $total;
}

function GetTotalPendingComplaint($userid, \database $con)
{
    $total = 0;
    $sql = "select id from complaints where user_id=:id AND status=:status";
    $q=$con->select_query($sql,array(':id'=>$userid,':status'=>PENDING_STATUS));
    $total = count($q);
    return $total;
}

function GetUser($userid, \database $con)
{
    $user = array();
    $sql = "select * from users where id = :id";
    $q=$con->select_query($sql,array(':id'=>$userid));
    foreach($q as $r)
    {
        $user = $r;
    }
    return $user;
}

function GetServiceRating($value)
{
    $rating = "";
    if($value == PROMPT_SERVICE_RATING)
    {
        $rating = "Service was prompt";
    }
    else if($value == SLOW_SERVICE_RATING)
    {
        $rating = "Service was slow";
    }
    else if($value == RECURRING_PROBLEM_RATING)
    {
        $rating = "This is a recurring problem";
    }
    return $rating;
}

function GetComplaintStatus($value)
{
    $status = "";
    if($value == PENDING_STATUS)
    {
        $status = "Pending";
    }
    else if($value == RESOLVED_STATUS)
    {
        $status = "Resolved";
    }
    else if($value == ACCEPTED_STATUS)
    {
        $status = "Closed";
    }
    return $status;
}

function GetStateName($state, \database $con)
{
    $statename = "";
    $sql = "select name from state where id=:id";
    $q=$con->select_query($sql,array(':id'=>$state));
    foreach($q as $r)
    {
        $statename = $r['name'];
    }    
    return $statename;
}

function GetLgaName($lga, \database $con)
{
    $lganame = "";
    $sql = "select name from localgovt where id=:id";
    $q=$con->select_query($sql,array(':id'=>$lga));
    foreach($q as $r)
    {
        $lganame = $r['name'];
    }
    return $lganame;
}

function GetDiscoName($disco, \database $con)
{
    $disconame = "";
    $sql = "select name from discos where id=:id";
    $q=$con->select_query($sql,array(':id'=>$disco));
    foreach($q as $r)
    {
        $disconame = $r['name'];
    }
    return $disconame;
}

function GetComplaintCategoryName($category, \database $con)
{
    $categoryname = "";
    $sql = "select name from complaint_category where id=:id";
    $q=$con->select_query($sql,array(':id'=>$category));
    foreach($q as $r)
    {
        $categoryname = $r['name'];
    }
    return $categoryname;
}

function GetNumberOfComments($complaintid,\database $con)
{
    $count = "";
    $sql = "select id from complaints_comments where complaint_id=:id";
    $q=$con->select_query($sql,array(':id'=>$complaintid));
    $count = count($q);
    return $count;
}
?>