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; }
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); }
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); }
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); }
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']); }
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); }