diff --git a/app/Controllers/Api/Admin/Contests/Create.php b/app/Controllers/Api/Admin/Contests/Create.php new file mode 100644 index 0000000..ad8cc8d --- /dev/null +++ b/app/Controllers/Api/Admin/Contests/Create.php @@ -0,0 +1,31 @@ + $_POST['themeid'], ':openprdate' => $openprdate, ':closeprdate'=>$closeprdate, ':opendate' => $opendate, ':closedate'=>$closedate)); + echo json_encode( + array( + 'errorcode' => 0, + 'error' => 0 + ) + ); + } +} diff --git a/app/Controllers/Api/Admin/Contests/CreateTheme.php b/app/Controllers/Api/Admin/Contests/CreateTheme.php new file mode 100644 index 0000000..6f67a55 --- /dev/null +++ b/app/Controllers/Api/Admin/Contests/CreateTheme.php @@ -0,0 +1,28 @@ + $_POST['body'], ':status' => $status)); + echo json_encode( + array( + 'errorcode' => 0, + 'error' => 0 + ) + ); + } +} diff --git a/app/Controllers/Api/Images/Rate.php b/app/Controllers/Api/Images/Rate.php index 3730ebd..b30fc0e 100644 --- a/app/Controllers/Api/Images/Rate.php +++ b/app/Controllers/Api/Images/Rate.php @@ -2,69 +2,96 @@ namespace App\Controllers\Api\Images; - - use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF}; use App\Models\{User, Vote}; - class Rate { public function __construct() { - if (isset($_GET['vote']) && isset($_GET['pid'])) { - if (Vote::photo(Auth::userid(), $_GET['pid']) === -1) { - DB::query('INSERT INTO photos_rates VALUES (\'0\', :id, :pid, :type, 0)', array(':id'=>Auth::userid(), ':pid' => $_GET['pid'], ':type'=>$_GET['vote'])); - if (Vote::photo(Auth::userid(), $_GET['pid']) != $_GET['vote']) { - DB::query('DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND type=:type', array(':id'=>Auth::userid(), ':pid' => $_GET['pid'], ':type'=>Vote::photo(Auth::userid(), $_GET['pid']))); - } - } else if (Vote::photo(Auth::userid(), $_GET['pid']) === (int)$_GET['vote']) { - DB::query('DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid', array(':id'=>Auth::userid(), ':pid' => $_GET['pid'])); - } else { - DB::query('UPDATE photos_rates SET type=:type WHERE user_id=:id AND photo_id=:pid', array(':id'=>Auth::userid(), ':pid' => $_GET['pid'], ':type'=>$_GET['vote'])); - - } - $votes = DB::query('SELECT * FROM photos_rates WHERE photo_id=:id ORDER BY id DESC', array(':id' => $_GET['pid'])); + $userId = Auth::userid(); + $photoId = $_GET['pid']; + $voteType = (int) $_GET['vote']; + $contest = (isset($_GET['action']) && $_GET['action'] === 'vote-konk') ? 1 : 0; + if ($contest === 1) { + if (Vote::photoContest($userId, $photoId) === -1) { + DB::query( + 'INSERT INTO photos_rates (id, user_id, photo_id, type, contest) VALUES (NULL, :id, :pid, :type, 1)', + [':id' => $userId, ':pid' => $photoId, ':type' => $voteType] + ); + if (Vote::photoContest($userId, $photoId) != $voteType) { + DB::query( + 'DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND type=:type AND contest=1', + [':id' => $userId, ':pid' => $photoId, ':type' => Vote::photo($userId, $photoId)] + ); + } + } elseif (Vote::photoContest($userId, $photoId) === $voteType) { + DB::query( + 'DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND contest=1', + [':id' => $userId, ':pid' => $photoId] + ); + } else { + DB::query( + 'UPDATE photos_rates SET type=:type WHERE user_id=:id AND photo_id=:pid AND contest=1', + [':id' => $userId, ':pid' => $photoId, ':type' => $voteType] + ); + } + } else { + if (Vote::photo($userId, $photoId) === -1) { + DB::query( + 'INSERT INTO photos_rates (id, user_id, photo_id, type, contest) VALUES (NULL, :id, :pid, :type, 0)', + [':id' => $userId, ':pid' => $photoId, ':type' => $voteType] + ); + if (Vote::photo($userId, $photoId) != $voteType) { + DB::query( + 'DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND type=:type AND contest=0', + [':id' => $userId, ':pid' => $photoId, ':type' => Vote::photo($userId, $photoId)] + ); + } + } elseif (Vote::photo($userId, $photoId) === $voteType) { + DB::query( + 'DELETE FROM photos_rates WHERE user_id=:id AND photo_id=:pid AND contest=0', + [':id' => $userId, ':pid' => $photoId] + ); + } else { + DB::query( + 'UPDATE photos_rates SET type=:type WHERE user_id=:id AND photo_id=:pid AND contest=0', + [':id' => $userId, ':pid' => $photoId, ':type' => $voteType] + ); + } + } + + $votes = DB::query('SELECT * FROM photos_rates WHERE photo_id=:id ORDER BY id DESC', [':id' => $photoId]); $formattedVotesPos = []; $formattedVotesNeg = []; + foreach ($votes as $vote) { $user = new User($vote['user_id']); if ($vote['type'] === 0) { - $type = 0; - $formattedVotesNeg[] = [$vote['user_id'], $user->i('username'), $type]; - } else if ($vote['type'] === 1) { - $type = 1; - $formattedVotesPos[] = [$vote['user_id'], $user->i('username'), $type]; + $formattedVotesNeg[] = [$vote['user_id'], $user->i('username'), 0]; + } elseif ($vote['type'] === 1) { + $formattedVotesPos[] = [$vote['user_id'], $user->i('username'), 1]; } - } - - if (Vote::photo(Auth::userid(), $_GET['pid']) === 0) { - $negbtn = true; - $posbtn = false; - } else if (Vote::photo(Auth::userid(), $_GET['pid']) === 1) { - $negbtn = false; - $posbtn = true; - } else { - $negbtn = false; - $posbtn = false; - } - $result = [ - 'buttons' => [$negbtn, $posbtn], - 'errors' => '', - 'rating' => Vote::count($_GET['pid']) - ]; - $votes = []; - $votes[1] = $formattedVotesPos; - $votes[0] = $formattedVotesNeg; - if (!empty($votes)) { - $result['votes'] = $votes; - } - - + $currentVote = Vote::photo($userId, $photoId); + $contCurrentVote = Vote::photoContest($userId, $photoId); + $result = [ + 'buttons' => [ + 'negbtn' => $currentVote === 0, + 'posbtn' => $currentVote === 1, + 'negbtn_contest' => $contCurrentVote === 0, + 'posbtn_contest' => $contCurrentVote === 1, + ], + 'errors' => '', + 'rating' => Vote::count($photoId), + 'votes' => [ + 1 => $formattedVotesPos, + 0 => $formattedVotesNeg + ] + ]; header('Content-Type: application/json'); echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); diff --git a/app/Controllers/Api/Images/Upload.php b/app/Controllers/Api/Images/Upload.php index ce660b2..1468402 100644 --- a/app/Controllers/Api/Images/Upload.php +++ b/app/Controllers/Api/Images/Upload.php @@ -37,7 +37,7 @@ class Upload } else { $moderated = 1; } - DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :moderated, :place, 0, :gallery, :entityid, 0, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup' => time(), ':moderated' => $moderated, ':gallery'=>$_POST['gallery'], ':entityid'=>self::$entitydata_id)); + DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :moderated, :place, 0, :gallery, :entityid, 0, 0, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup' => time(), ':moderated' => $moderated, ':gallery'=>$_POST['gallery'], ':entityid'=>self::$entitydata_id)); if (($moderated === 1) && (self::$subsnotify != 'disabled')) { $followers = DB::query('SELECT * FROM followers WHERE user_id=:uid', array(':uid' => Auth::userid())); foreach ($followers as $f) { diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index 0a5a917..5df973c 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -31,6 +31,8 @@ use \App\Controllers\Api\Admin\GetVehicleInputs as AdminGetVehicleInputs; use \App\Controllers\Api\Admin\GeoDB\Create as AdminGeoDBCreate; use \App\Controllers\Api\Admin\GeoDB\Load as AdminGeoDBLoad; use \App\Controllers\Api\Admin\GeoDB\Delete as AdminGeoDBDelete; +use \App\Controllers\Api\Admin\Contests\CreateTheme as AdminContestsCreateTheme; +use \App\Controllers\Api\Admin\Contests\Create as AdminContestsCreate; class ApiController { @@ -108,6 +110,12 @@ class ApiController public static function admingetvehicleinputs() { return new AdminGetVehicleInputs(); } + public static function admincontestscreatetheme() { + return new AdminContestsCreateTheme(); + } + public static function admincontestscreate() { + return new AdminContestsCreate(); + } public static function admingeodbcreate() { return new AdminGeoDBCreate(); } diff --git a/app/Controllers/ContestsController.php b/app/Controllers/ContestsController.php index ff9ed77..20c0d4b 100644 --- a/app/Controllers/ContestsController.php +++ b/app/Controllers/ContestsController.php @@ -17,5 +17,15 @@ class ContestsController Page::set('Contests/VotingIndex'); } + public static function waiting() + { + Page::set('Contests/VotingWaiting'); + + } + public static function sendpretend() + { + Page::set('Contests/VotingSendPretend'); + + } } \ No newline at end of file