Exemplo n.º 1
0
 public static function resetCrontab()
 {
     $cron_file = 'cron.txt';
     $cron = new FileWriter($cron_file, 'a');
     $setSessionPath = '/home1/enderrac/SpirePHP/setSessionWinner.php';
     $stm = "SELECT EXTRACT(MINUTE from end_ts) as minute, " . "\tEXTRACT(HOUR from end_ts) as hour, " . "\tEXTRACT(day from end_ts) as day_of_month, " . "\tEXTRACT(MONTH from end_ts) as month, " . "\tEXTRACT(dow from end_ts) as day_of_week, " . "\tid " . "FROM SPIRE.SESSIONS ";
     $result = ConnDB::query_db($stm);
     $fnHash = null;
     if (!$result) {
         $cron->writeLine("ERROR");
         $fnHash = MyUtil::fnOk(false, "SQL Error getting Session Info", null);
     } else {
         while ($row = pg_fetch_assoc($result)) {
             $cron->writeLine($row['minute'] . " " . $row['hour'] . " " . $row['day_of_month'] . " " . $row['month'] . " " . $row['day_of_week'] . " {$setSessionPath} " . $row['id']);
         }
         $rmCron = shell_exec('crontab -r');
         if ($rmCron != null) {
             $setCron = shell_exec('crontab $cron_file');
             if ($setCron != null) {
                 $delCronTmp = shell_exec('rm $cron_file');
                 if ($delCronTmp != null) {
                     $fnHash = MyUtil::fnOk(true, "Updated Cron and Session", null);
                 }
                 $fnHash = MyUtil::fnOk(false, "Cron Tmp File not Deleted", null);
             }
             $fnHash = MyUtil::fnOk(false, "Cron not set to tmp", null);
         } else {
             $fnHash = MyUtil::fnOk(false, "Original cron not deleted", null);
         }
         return $fnHash;
     }
     return $fnHash;
 }
Exemplo n.º 2
0
 private static function saveToken($user_id, $token, $session_id)
 {
     $stm = "INSERT INTO " . self::$table_name . "(USER_ID, TOKEN_ID, SESSION_ID) VALUES ('{$user_id}', '{$token}', CAST(COALESCE(nullIf('{$session_id}',''),'0') as integer))";
     $result = ConnDB::query_db($stm);
     if (!$result) {
         return MyUtil::fnOk(false, "SQL Error", null);
     }
     return MyUtil::fnOk(true, "Token Inserted", $result);
 }
Exemplo n.º 3
0
 private static function hasUserVoted($user, $session)
 {
     $stm = "SELECT COUNT(*) as is_vote FROM " . self::$table_name . " WHERE SESSION_ID = {$session} AND USER_ID = {$user} AND INSERT_DT = CURRENT_DATE ";
     $result = ConnDB::query_db($stm);
     if (!$result) {
         return MyUtil::fnOk(false, "SQL Error", null);
     }
     $row = pg_fetch_assoc($result);
     return MyUtil::fnOk(true, "", $row['is_vote'] == 1);
 }
Exemplo n.º 4
0
            if ($artistHash['ok']) {
                JsonResponse::sendResponse(200, $artistHash['result']);
            } else {
                JsonResponse::sendResponse(400, $artistHash['reason']);
            }
        } else {
            JsonResponse::sendResponse(404, "Invalid Spire API Request");
        }
    } elseif (isset($_GET['videoartist'])) {
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            //check if token user has artist rights
            $video = $_POST['fields'];
            $target_dir = "/home1/enderrac/public_html/spiresessions/video-uploads/";
            $target_file = $target_dir . basename($video['artist_id'] . "-" . $video['name'] . "-" . time() . "-" . $_FILES["videoToUpload"]["name"]);
            $fileType = pathinfo($target_file, PATHINFO_EXTENSION);
            if (move_uploaded_file($_FILES["videoToUpload"]["tmp_name"], $target_file)) {
                $fnHash = VideoDAO::insertVideo(MyUtil::get_hash_value($video, 'artist_id'), MyUtil::get_hash_value($video, 'session_id'), MyUtil::get_hash_value($video, 'name'), MyUtil::get_hash_value($video, 'description'), MyUtil::get_hash_value($video, 'youtube_id'), MyUtil::get_hash_value($video, 'iframe_url'), MyUtil::get_hash_value($video, 'votes'), MyUtil::get_hash_value($video, 'upload_status_nbr'), MyUtil::get_hash_value($video, 'video_status_nbr'), $target_file, MyUtil::get_hash_value($video, 'is_active'));
                if ($fnHash['ok']) {
                    JsonResponse::sendResponse(200, "Successfully Created");
                } else {
                    JsonResponse::sendResponse(500, $fnHash['reason']);
                }
            }
        } elseif ($_SERVER['REQUEST_METHOD'] == "PUT") {
        } else {
            JsonResponse::sendResponse(404, "Invalid Spire API Request");
        }
    } else {
        JsonResponse::sendResponse(404, "Invalid Spire API Request");
    }
}
Exemplo n.º 5
0
 public static function getArtistFromUser($orig_id)
 {
     //id must be an integer
     $id = MyUtil::parseInt($orig_id);
     if (!$id) {
         return MyUtil::fnOk(false, "Must be a valid id: {$orig_id}", null);
     }
     $stm = " SELECT art.* " . " FROM spire.user_to_artist ua " . "    JOIN spire.artists art ON ua.artist_id = art.id " . " WHERE ua.user_id = {$id} ";
     $result = ConnDB::query_db($stm);
     if (!$result) {
         return MyUtil::fnOk(false, "SQL Error", null);
     }
     $retArray = [];
     while ($row = pg_fetch_assoc($result)) {
         array_push($retArray, $row);
     }
     return MyUtil::fnOk(true, "Found Artist Id", $retArray);
 }
Exemplo n.º 6
0
 public static function getArtistIdFromUser($id)
 {
     //id must be an integer
     $id = MyUtil::parseInt($id);
     if (!$id) {
         return MyUtil::fnOk(false, "Must be a valid id: {$id}", null);
     }
     $stm = "SELECT artist_id from spire.user_to_artist where user_id = {$id} ";
     $result = ConnDB::query_db($stm);
     if (!$result) {
         return MyUtil::fnOk(false, "SQL Error", null);
     }
     return MyUtil::fnOk(true, "Found Artist Id", $result['artist_id']);
 }
Exemplo n.º 7
0
 public static function deleteSession($id)
 {
     //id must be an integer
     $orig_id = $id;
     $id = MyUtil::parseInt($id);
     if ($id == null) {
         return MyUtil::fnOk(false, "Must be a valid id: {$orig_id}", null);
     }
     $stm = "DELETE FROM " . self::$table_name . " WHERE id = {$id}";
     $result = ConnDB::query_db($stm);
     if (!$result) {
         return MyUtil::fnOk(false, "SQL Error", null);
     }
     return MyUtil::fnOk(true, "Session Deleted", $result);
 }