public function markRead($notificationObj)
 {
     $userId = parent::getUserId();
     if ($userId == false) {
         return "Invalid User";
     }
     $sth = $this->db->prepare("UPDATE Notifications SET NotificationRead = 1 WHERE NotificationId = :notificationId AND UserId = :userId LIMIT 1");
     $sth->execute(array(":notificationId" => $notificationObj["id"], ":userId" => $userId));
     // ASSume success
     $response = $this->defaultResponseObj;
     $response["Success"] = true;
     $response["DB_Error"] = $sth->errorInfo();
     return $response;
 }
 public function disconnect($deleteObj)
 {
     $response = $this->defaultResponseObj;
     $userId = parent::getUserId();
     if ($userId == false) {
         return "Invalid User";
     }
     $contextio = new ContextIO(CONTEXTIO_KEY, CONTEXTIO_SECRET);
     $apiResponse = $contextio->deleteUser($deleteObj["contextio_id"]);
     if ($apiResponse == false) {
         // Failed to delete the account
         $response["Message"] = "Account not found. Contact us for additional assistance.";
     } else {
         $rawResponse = $apiResponse->getRawResponse();
         $rawResponse = json_encode($rawResponse, true);
         if (property_exists($rawResponse, "error") && $rawResponse["error"] != "") {
             // Failed to delete the account
             $response["Message"] = "Unable to unlink account at this time. Try again later or contact us for additional assistance.";
             $response["ApiResponse"] = $apiResponse->getRawResponse();
         } else {
             // Deleted account, delete reference from our database
             $sth = $this->db->prepare("DELETE FROM EmailAccounts WHERE Contextio_Id = :id LIMIT 1");
             $sth->execute(array(":id" => $deleteObj["contextio_id"]));
             $response["Success"] = true;
             $response["Message"] = "Account has been successfully unlinked.";
         }
     }
     return $response;
 }
Example #3
0
 public function vote($voteObj)
 {
     $userId = parent::getUserId();
     if ($userId == false) {
         return "Invalid AuthToken";
     }
     // Get the current vote
     $sth = $this->db->prepare("SELECT * FROM Votes WHERE UserId = :userId AND ShareId = :shareId LIMIT 1");
     $success = $sth->execute(array(":userId" => $userId, ":shareId" => $voteObj["shareId"]));
     $result = $sth->fetch();
     if ($success && $result != false) {
         $up = 0;
         $down = 0;
         if ($voteObj["voteType"] == "down") {
             // Change to a down vote
             $down = 1;
         } else {
             if ($voteObj["voteType"] == "up") {
                 $up = 1;
             }
         }
         $sthUpdateVote = $this->db->prepare("UPDATE Votes SET UpVote = :up, DownVote = :down WHERE UserId = :userId AND ShareId = :shareId LIMIT 1");
         $sthUpdateVote->execute(array(":up" => $up, ":down" => $down, ":userId" => $userId, "shareId" => $voteObj["shareId"]));
         //print_r($sthUpdateVote->errorInfo());
     } else {
         $up = 0;
         $down = 0;
         // Submit a new vote
         if ($voteObj["voteType"] == "up") {
             $up = 1;
         } else {
             if ($voteObj["voteType"] == "down") {
                 $down = 1;
             }
         }
         $sthNewVote = $this->db->prepare("INSERT INTO Votes (VoteId, UserId, ShareId, UpVote, DownVote, Flag)\n\t\t\t\t\t\t\t\tVALUES ('', :userId, :shareId, :up, :down, 0)");
         $sthNewVote->execute(array(":userId" => $userId, ":shareId" => $voteObj["shareId"], ":up" => $up, ":down" => $down));
     }
     // Update the rank after every vote
     $this->_calculateRank($voteObj["shareId"]);
     // Record the action
     $notifications = new Notifications();
     $notifications->recordAction($userId, $voteObj["voteType"], $voteObj["shareId"]);
     $response = $this->defaultResponseObj;
     $response["Success"] = true;
     $response["Message"] = "Vote recorded";
     return $response;
 }
Example #4
0
 public static function adminId()
 {
     return Model::getUserId();
 }
Example #5
0
<?php

require_once "app/configs/Global_Config.php";
$mysqli = new Mysql_Connection();
$model = new Model($mysqli->getConn());
$view = new View($model);
$user = "******";
$userid = "NOT YET SET";
$chainname = "NOT SET";
$troveid = "NOT SET";
$keywords = "NOT SET";
$notes = "NOT SET";
if (isset($_POST['AddUser'])) {
    $user = $_POST['AddUser'];
    $userid = $model->getUserId($user);
}
if (isset($_POST['AddChain'])) {
    $chainname = $_POST['AddChain'];
}
if (isset($_POST['AddSource'])) {
    $troveid = $_POST['AddSource'];
}
if (isset($_POST['AddKeywords'])) {
    $keywords = trim($_POST['AddKeywords']);
}
if (isset($_POST['AddNotes'])) {
    $notes = trim($_POST['AddNotes']);
}
if ($model->addSourceToChain($userid, $chainname, $keywords, $notes, $troveid) === TRUE) {
    $res = $view->showChain($model->getChainSources($_POST['AddChain']));
    echo $res;
Example #6
0
function userId(Model $model, $field, $value)
{
    $user_id_data = $model->getUserId($field, $value);
    return $user_id_data['user_id'];
}