Teknik is a suite of services with attractive and functional interfaces.
https://www.teknik.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
<?php |
|
require_once('config.php'); |
|
|
|
//check to see that the form has been submitted |
|
$id = 0; |
|
$vote = ""; |
|
$points = 0; |
|
if(isset($_POST) && $logged_in) |
|
{ |
|
$user_id = $user->id; |
|
$id = rawurldecode($_POST['id']); |
|
$table = rawurldecode($_POST['table']); |
|
$points = rawurldecode($_POST['vote']); |
|
$user_vote = $db->select('votes', 'table_name=? AND row_id=? AND user_id=? ORDER BY id DESC LIMIT 1', array($table, $id, $user_id)); |
|
if ($user_vote) |
|
{ |
|
$old_points = $user_vote['points']; |
|
if ($old_points != $points) |
|
{ |
|
$points = $old_points + $points; |
|
} |
|
$data = array( |
|
"points" => $points |
|
); |
|
//update the row in the database |
|
$db->update($data, 'votes', 'id=?', array($user_vote['id'])); |
|
} |
|
else |
|
{ |
|
$data = array( |
|
"table_name" => $table, |
|
"row_id" => $id, |
|
"user_id" => $user_id, |
|
"points" => $points |
|
); |
|
|
|
$db->insert($data, 'votes'); |
|
} |
|
$results = $db->select('votes', 'table_name=? AND row_id=?', array($table, $id), 'sum(points) totalPoints'); |
|
$votes = $results['totalPoints']; |
|
echo $votes; |
|
} |
|
else |
|
{ |
|
echo "false"; |
|
} |
|
?>
|