-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanswerpost.php
More file actions
92 lines (72 loc) · 3.1 KB
/
Copy pathanswerpost.php
File metadata and controls
92 lines (72 loc) · 3.1 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php require_once 'include/lib.php';
$answer =new item_class();
$filter =new filter_class();
$answer->set('questions');
$qid =$_POST['qid'];
$uid =$_POST['uid'];
$user=new user_class();
$user->id=$uid;
$body =$filter->escape($_POST['myTextArea']);
if(!$body){
echo "Where is the Answer!";
echo $body;
}
else
{
$res=$answer->sql_query("BEGIN WORK;");
if(!$res)
{
//Damn! the query failed, quit
echo 'An error occured while creating your topic. Please try again later.';
}
else
{
if( strlen($body)<10 )
{
echo "Your Answer should be in between 10 and 10000 charecters!";
}
else
{
//$date=time();
//"date_created"=>$date,
$data=array("qid"=>$qid,"uid"=>$uid,"body"=>$body);
$answer->set('answers');
$answer->insert($data);
$aid=$answer::$link->insert_id;
if(!$answer->result)
{
//something went wrong, display the error
echo 'An error occured while inserting your data. Please try again later.' ;
$sql = "ROLLBACK;";
$answer->sql_query($sql);
}
else
{
$owner=new item_class();
$owner->set("notification");
$question=new item_class();
$question->sql_query("CALL updateAnswerCount($qid,1)");
$sql = "COMMIT;";
$answer->sql_query($sql);
/**************update tag score on users**********/
$answer->sql_query("select * from question_tags where qid=$qid");
while($tag_data=$answer->load_datas()){
$user->newAnsTagScore($tag_data['tid']);
}
//after a lot of work, the query succeeded!
echo 'You have successfully entered your answer';
$owner->sql_query("select owner_id,title from questions where id=$qid");
$owner_data=$owner->load_datas();
$fid=$owner_data['owner_id'];
$q_title=substr($owner_data['title'],0,25);
$q_title.="...";
if($fid!=$uid){
$insertNot=array("message"=>$q_title,"aid"=>$aid,"fid"=>$uid,"uid"=>$fid,"qid"=>$qid);
$owner->insert($insertNot);
}
header("Location:question.php?id=$qid");
}
}
}
}
?>