-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.updateitem.php
More file actions
117 lines (99 loc) · 3.55 KB
/
Copy pathaction.updateitem.php
File metadata and controls
117 lines (99 loc) · 3.55 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
#----------------------------------------------------------------------
# Module: MBVFaq - a simple FAQ module
# Action: updateitem
#----------------------------------------------------------------------
# See file MBVFaq.module.php for full details of copyright, licence, etc.
#----------------------------------------------------------------------
if (isset($params['cancel'])) { // if cancel was pressed don't do update
$this->Redirect($id, 'defaultadmin');
}
$querydata = array();
if (isset($params['category']) && $params['category'] != '') {
$category = $params['category'];
} else {
$category = 0;
} //default (first) category
$querydata[] = $category;
if (isset($params['short_question'])) {
$querydata[] = $params['short_question'];
} else {
$querydata[] = '';
} //here we need something, no question >> no post!
if (isset($params['long_question'])) {
$querydata[] = $params['long_question'];
} else {
$querydata[] = '';
}
if (isset($params['short_answer'])) {
$querydata[] = $params['short_answer'];
} else {
$querydata[] = '';
} // ok as long as there is a long answer
//if not, it won't be shown whether it's active or not
if (isset($params['long_answer'])) {
$querydata[] = $params['long_answer'];
} else {
$querydata[] = '';
} // ok as long as there is a short answer,
//if not, it won't be shown whether it is active or not
if (isset($params['owner']) && $params['owner'] !='') {
$querydata[] = $params['owner'];
} else {
$querydata[] = get_userid(FALSE);
} //set current user as owner
$now = date("Y-m-d H:i:s");
if (isset($params['create_date']) && $params['create_date'] != '') {
$querydata[] = date('Y-m-d H:i:s', strtotime($params['create_date']));
} else {
$querydata[] = $now;
}
$querydata[] = $now; //modified now
if (isset($params['active']) && $params['active'] !='') {
$querydata[] = $params['active'];
} else {
$querydata[] = 0;
} // default is inactive
$item_id = $params['item_id'];
if ($item_id == '-1') {
$add = TRUE;
$item_id = $db->GenID($this->ItemTable.'_seq');
$oldcategory = FALSE;
} else {
$add = FALSE;
$sql = "SELECT category_id FROM $this->ItemTable WHERE item_id=?";
$oldcategory = $db->GetOne($sql, array($item_id));
}
if (!empty($params['vieworder'])) {
$order = $params['vieworder'];
} else {
$order = 9999999999;
} //PHP_INT_MAX - 10000; default to last in category
//check if there's already another in the category and with the specified order-number
$sql = "SELECT item_id FROM $this->ItemTable WHERE category_id=? AND vieworder=?";
$check = $db->GetOne($sql, array($category, $order));
if ($check !== FALSE && $check != $item_id) {
$before = TRUE; //need insert-before
$querydata[] = -1; //order will be updated afterwards
} else {
$before = FALSE;
$querydata[] = $order;
}
$querydata[] = $item_id;
if ($add) { //it's a new post
$sql = "INSERT INTO $this->ItemTable (category_id, short_question, long_question, short_answer, long_answer, owner, create_date, last_modified_date, active, vieworder, item_id) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
} else {
$sql = "UPDATE $this->ItemTable SET category_id=?, short_question=?, long_question=?, short_answer=?, long_answer=?, owner=?, create_date=?, last_modified_date=?, active=?, vieworder=? WHERE item_id=?";
}
$db->Execute($sql, $querydata);
$funcs = new MBVForder();
//re-sequence affected vieworder fields
if ($before) {
$funcs->ReorderRows($this, $category, array($item_id), $order);
} else {
$funcs->ReorderRows($this, $category);
}
if (!($oldcategory === FALSE || $oldcategory == $category)) {
$funcs->ReorderRows($this, $oldcategory);
}
$this->Redirect($id, 'defaultadmin');