-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpgp.ajax.govr.php
111 lines (101 loc) · 4.09 KB
/
wpgp.ajax.govr.php
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
<?php /* -*- Mode: php; c-basic-offset:4; -*- */
/* Copyright (C) 2011 Governo do Estado do Rio Grande do Sul
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function wpgp_ajax_govr_create_theme() {
$name = $_POST['data']['theme_name'];
wpgp_db_govr_create_theme($name);
}
function wpgp_ajax_govr_delete_theme() {
$id = $_POST['data']['theme_id'];
if (!wpgp_db_govr_delete_theme($id)) {
die("non-empty");
}
}
function wpgp_ajax_govr_create_contrib() {
$current_user = wp_get_current_user();
wpgp_db_govr_create_contrib($_POST['data']['title'],
$_POST['data']['theme_id'],
$_POST['data']['content'],
$current_user->ID,
$_POST['data']['part']);
}
function wpgp_ajax_govr_delete_contrib() {
$id = $_POST['data']['id'];
$org = wpgp_db_govr_get_contrib($id);
wpgp_db_govr_delete_contrib($id, !!$org['created_by_moderation']);
}
function wpgp_ajax_govr_update_contrib() {
$org = wpgp_db_govr_get_contrib($_POST['data']['id']);
switch ($_POST['data']['field']) {
case 'content':
case 'title':
case 'status':
case 'theme_id':
wpgp_db_govr_update_contrib($_POST['data']['id'],
$_POST['data']['field'],
$_POST['data']['value']);
break;
case 'parent':
$_POST['data']['value'] =
trim($_POST['data']['value']) === "" ? "0" : $_POST['data']['value'];
if ($_POST['data']['value'] != "0") {
$parent = wpgp_db_govr_get_contrib($_POST['data']['value']);
if ($parent == null) {
die("not-found");
}
}
wpgp_db_govr_update_contrib($_POST['data']['id'],
$_POST['data']['field'],
$_POST['data']['value']);
break;
case 'part':
$org = wpgp_db_govr_get_contrib($_POST['data']['id']);
if ($_POST['data']['value'] != "0") {
/* If the string comes empty the user want to nuke all
* children contribs, let's grant his/her wish */
if (empty($_POST['data']['value'])) {
foreach (wpgp_govr_contrib_get_parents($org) as $parent) {
wpgp_govr_contrib_remove_part($parent, $org);
}
die('ok');
}
if (wpgp_govr_contrib_insert_parts($org, $_POST['data']['value'])) {
die('ok');
} else {
die('not-found');
}
}
die("ok");
break;
}
}
function wpgp_ajax_govr_contrib_answer() {
wpgp_db_govr_contrib_answer(
$_POST['data']['id'],
$_POST['data']['answer'],
$_POST['data']['category'],
$_POST['data']['date'],
$_POST['data']['data'],
$_POST['data']['answer_order']);
die("ok");
}
add_action('wp_ajax_govr_create_theme', 'wpgp_ajax_govr_create_theme');
add_action('wp_ajax_govr_delete_theme', 'wpgp_ajax_govr_delete_theme');
add_action('wp_ajax_govr_create_contrib', 'wpgp_ajax_govr_create_contrib');
add_action('wp_ajax_govr_delete_contrib', 'wpgp_ajax_govr_delete_contrib');
add_action('wp_ajax_govr_update_contrib', 'wpgp_ajax_govr_update_contrib');
add_action('wp_ajax_govr_contrib_answer', 'wpgp_ajax_govr_contrib_answer');
?>