Ejemplo n.º 1
49
<?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();
Ejemplo n.º 2
48
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"]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
<?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'];
upvote($story_ID);
header("Location: ../index.php");
Ejemplo n.º 4
18
 if ($row = pg_fetch_array($check)) {
     $checkok = true;
     $prevvote = $row['vote'] == 't' ? true : false;
     $idprevvote = $row['idvotexuser'];
 }
 if ($_POST['action'] == "up") {
     if ($checkok) {
         if ($prevvote) {
             echo 'nothing';
             //if he already voted for good
         } else {
             changevote($_POST['video'], $_SESSION['usrid']);
             echo 'changedu';
         }
     } else {
         if (upvote($_POST['video'])) {
             newvote($_POST['video'], $_SESSION['usrid'], "true");
             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';
Ejemplo n.º 5
6
<?php

if (isset($_GET['i'])) {
    if ($_GET['i'] == 0) {
        recarregar();
    } else {
        upvote();
    }
} else {
    echo "Function not found or wrong input";
}
function upvote()
{
    //echo $_GET['i'];
    $hostname = "localhost";
    $username = "******";
    $password = "";
    $conexion = @mysql_connect("{$hostname}", "{$username}", "{$password}") or die(mysqli_connect_error());
    mysql_select_db("test") or die(mysql_error());
    $result = mysql_query("UPDATE mulheres SET voto = voto + 1 WHERE ID='" . $_GET['i'] . "'");
    //echo $result;
    mysql_close($conexion);
    recarregar();
}
function recarregar()
{
    //echo $_GET['i'];
    $hostname = "localhost";
    $username = "******";
    $password = "";
    $conexion = @mysql_connect("{$hostname}", "{$username}", "{$password}") or die(mysqli_connect_error());