コード例 #1
49
ファイル: helper.php プロジェクト: uclastudentmedia/oldmedia
<?php

$which = $_GET['choice'];
$ind = $_GET['index'];
switch ($which) {
    case "up":
        upvote($ind);
        break;
    case "down":
        downvote($ind);
        break;
}
function upvote($index)
{
    $myfile = fopen("notes.txt", "r") or die("Unable to open file!");
    $notesArray = json_decode(fread($myfile, filesize("notes.txt")), true);
    fclose($myfile);
    $notesArray[(int) $index]['upvotes'] = (int) $notesArray[$index]['upvotes'] + 1;
    $writefile = fopen("notes.txt", "w") or die("Unable to open file!");
    fwrite($writefile, json_encode($notesArray));
    $fclose();
}
function downvote($index)
{
    $myfile = fopen("notes.txt", "r") or die("Unable to open file!");
    $notesArray = json_decode(fread($myfile, filesize("notes.txt")), true);
    fclose($myfile);
    $notesArray[(int) $index]['upvotes'] = (int) $notesArray[$index]['downvotes'] - 1;
    $writefile = fopen("notes.txt", "w") or die("Unable to open file!");
    fwrite($writefile, json_encode($notesArray));
    $fclose();
コード例 #2
48
ファイル: serverSide.php プロジェクト: Tanyavdc/holyyak
function perform_operation($op)
{
    if ($op == 'login') {
        validate_user($_POST["useremail"], $_POST["userpassword"]);
    } else {
        if ($op == 'getyaks') {
            get_yaks($_POST["longitude"], $_POST["latitude"]);
        } else {
            if ($op == 'post_yak') {
                post_yak($_POST["postedyak"], $_POST["latitude"], $_POST["longitude"]);
            } else {
                if ($op == 'banned_user') {
                    banned_user($_POST["useremail"]);
                } else {
                    if ($op == 'add_user') {
                        add_user($_POST["useremail"], $_POST["userpassword"]);
                    } else {
                        if ($op == 'send_email') {
                            send_email($_POST["email"]);
                        } else {
                            if ($op == 'getHot_yaks') {
                                getHot_yaks();
                            } else {
                                if ($op == 'getCold_yaks') {
                                    getCold_yaks();
                                } else {
                                    if ($op == 'upvote') {
                                        upvote($_POST["id"]);
                                    } else {
                                        if ($op == 'downvote') {
                                            downvote($_POST["id"]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
コード例 #3
0
        break;
    case 'tipUpvote':
        tipUpvote();
        break;
    case 'tipDownvote':
        tipDownvote();
        break;
    case 'getCounters':
        $outp = getCounters();
        echo $outp;
        break;
    case 'upvote':
        upvote();
        break;
    case 'downvote':
        downvote();
        break;
    case 'getTips':
        echo getTips();
        break;
}
function tipUpvote()
{
    global $dbh;
    $data = json_decode(file_get_contents("php://input"));
    $tip_id = $data->tip_id;
    $sql = "UPDATE general_tips SET vote = vote + 1 where id = {$tip_id}";
    $stmt = $dbh->prepare($sql);
    $stmt->execute();
}
function tipDownvote()
<?php

require 'config.php';
require 'functions.php';
session_start();
if (!isset($_SESSION['username'])) {
    header("Location: ../index.php?error=1");
    exit;
}
if (!isset($_GET['id'])) {
    header("Location: ../index.php");
    exit;
}
$story_ID = $_GET['id'];
downvote($story_ID);
header("Location: ../index.php");
コード例 #5
0
                    echo 'yes';
                } else {
                    echo 'no';
                }
            }
        } else {
            if ($_POST['action'] == "down") {
                if ($checkok) {
                    if (!$prevvote) {
                        echo 'nothing';
                        //if he already voted for bad
                    } else {
                        changevote($_POST['video'], $_SESSION['usrid']);
                        echo 'changedd';
                    }
                } else {
                    if (downvote($_POST['video'])) {
                        newvote($_POST['video'], $_SESSION['usrid'], "false");
                        echo 'yes';
                    } else {
                        echo 'no';
                    }
                }
            } else {
                echo 'no';
            }
        }
    } else {
        echo 'no';
    }
}