Esempio n. 1
0
<?php

header("Content-Type: application/json");
require_once "config/config.inc";
if (isset($_POST["song"]) && isset($_SESSION['online'])) {
    $db = $_SESSION['db'];
    $id_user = $_SESSION["user"]->getId();
    $id_song = $_POST["song"];
    $known = $_POST['known'] === 'true' ? true : false;
    $owned = $_POST['owned'] === 'true' ? true : false;
    if (Know::userKnowsSong($id_user, $id_song)) {
        if ($known && $owned) {
            $stmt = $db->prepare("update know set owned = 1 where user = :user and song = :song;");
        } elseif ($known && !$owned) {
            $stmt = $db->prepare("update know set owned = 0 where user = :user and song = :song;");
        } else {
            $stmt = $db->prepare("delete from know where user = :user and song = :song;");
            $stmt2 = $db->prepare("delete from rate where user = :user and song = :song;");
            $stmt2->execute(array("user" => $id_user, "song" => $id_song));
            $stmt2->closeCursor();
        }
    } else {
        if ($owned) {
            $stmt = $db->prepare("insert into know values (:user, :song, 1, unix_timestamp());");
        } else {
            $stmt = $db->prepare("insert into know values (:user, :song, 0, unix_timestamp());");
        }
    }
    $stmt->execute(array("user" => $id_user, "song" => $id_song));
    $stmt->closeCursor();
    print json_encode(array("status" => "OK", "stackTrace" => "alright", "known" => $_POST['known'], "owned" => $_POST['owned']));
Esempio n. 2
0
    print Know::userKnowsSong($user->getId(), $song->getId()) ? 'checked' : '';
    ?>
>Known
				</label>
				<label class="btn btn-success <?php 
    print Know::userOwnsSong($user->getId(), $song->getId()) ? 'active' : '';
    ?>
" id="owned_label" data-complete-text="Owned" onclick="javascript:checkKO(false);">
					<input id="owned_checkbox" type="checkbox" style="display:none;" <?php 
    print Know::userKnowsSong($user->getId(), $song->getId()) ? 'checked' : '';
    ?>
>Owned
				</label>
			</div>
			<div id="rate_song" class="<?php 
    print Know::userKnowsSong($user->getId(), $song->getId()) ? '' : 'invisible';
    ?>
">
				<div class="padded"></div>
				<div class="padded"></div>
				<div class="padded"></div>
				<div class="padded"></div>
				<h3 class="text-left padded">
					Grade: <span id="rating_grade"><?php 
    print $song->isRatedBy($user->getId()) ? $song->gradeBy($user->getId()) : '-';
    ?>
</span> / 10
					<div id="ratesl">
						<div class="slider slider-horizontal" id="rate_slider" style="cursor:pointer;"></div>
					</div>
				</h3>