-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddComment.php
More file actions
51 lines (44 loc) · 1.37 KB
/
addComment.php
File metadata and controls
51 lines (44 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');
include_once('config.php');
$boulder_id = $_GET['boulderid'];
$comment = $_GET['comment'];
$rating = $_GET['rating']?$_GET['rating']:0;
$difficulty = $_GET['difficulty']?$_GET['difficulty']:0;
$user_id = $_GET['user_id'];
$updated = false;
if($boulder_id){
$db = new DB();
$db->verboseMode = false;
$db->table = "boulders_comments";
if($user_id && ($difficulty > 0 || $rating > 0)){
$db->setParams(array("user_id","rating","difficulty"));
$db->setFilter("boulder_id='".$boulder_id."' AND user_id='".$user_id."' AND ( difficulty > 0 OR rating > 0)" );
$db->select();
if(list($db_user_id, $db_rating, $db_difficulty) = $db->fetchRow()){
$db->setParams(
array(
"comment"=>$comment,
"rating"=>$rating,
"difficulty"=>$difficulty
)
);
$db->update();
$updated = true;
}
}
if(!$updated){
$db->setParams(
array(
"boulder_id"=>$boulder_id,
"comment"=>$comment,
"rating"=>$rating,
"difficulty"=>$difficulty,
"user_id"=>$user_id
)
);
$db->insert();
}
}
?>