1 /* cmd_neonhelp_requests.c - NeonServ v5.6
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_neonhelp.h"
24 CMD_BIND(neonhelp_cmd_requests) {
30 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
32 if (!(row = mysql_fetch_row(res))) return;
33 //check if the user is a supporter (access in the support channel)
34 if((user->flags & USERFLAG_ISAUTHED)) {
35 if(user->flags & USERFLAG_HAS_USERID)
36 userid = user->user_id;
38 printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
40 if ((row2 = mysql_fetch_row(res)) != NULL) {
41 userid = atoi(row2[0]);
42 user->user_id = userid;
43 user->flags |= USERFLAG_HAS_USERID;
47 printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` WHERE `chanuser_uid` = '%d' AND `channel_name` = '%s'", userid, escape_string(row[0]));
49 if ((row2 = mysql_fetch_row(res)) != NULL) {
50 int cflags = atoi(row2[1]);
51 if(!(cflags & DB_CHANUSER_SUSPENDED))
52 caccess = atoi(row2[0]);
56 reply(textclient, user, "MODCMD_ACCESS_DENIED");
60 printf_mysql_query("SELECT `id`, `time`, `text` FROM `helpserv_requests` WHERE `botid` = '%d' AND `status` != 2 ORDER BY `time` DESC", client->clientid);
62 table = table_init(5, mysql_num_rows(res) + 1, 0);
64 content[0] = get_language_string(user, "NH_REQUESTS_HEADER_ID");
65 content[1] = get_language_string(user, "NH_REQUESTS_HEADER_STATUS");
66 content[2] = get_language_string(user, "NH_REQUESTS_HEADER_NICK");
67 content[3] = get_language_string(user, "NH_REQUESTS_HEADER_TIME");
68 content[4] = get_language_string(user, "NH_REQUESTS_HEADER_REQUEST");
69 table_add(table, content);
71 struct NeonHelpNode *helpnode;
73 while ((row = mysql_fetch_row(res)) != NULL) {
75 suppid = atoi(row[0]);
76 if(client->flags & SOCKET_HAVE_HELPNODE) {
77 for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
78 if(helpnode->suppid == suppid) {
80 content[1] = get_language_string(user, "NH_REQUESTS_STATE_ACTIVE");
82 content[1] = get_language_string(user, "NH_REQUESTS_STATE_PENDING");
83 content[2] = helpnode->user->nick;
88 content[1] = get_language_string(user, "NH_REQUESTS_STATE_ERROR");
91 timeToStr(user, (time(0) - atoi(row[1])), 2, timestr);
94 if((p = strstr(row[2], "\n")))
97 table_add(table, content);
100 char **table_lines = table_end(table);
102 for(i = 0; i < table->entrys; i++) {
103 reply(textclient, user, table_lines[i]);
105 if(table->entrys == 1)
106 reply(textclient, user, "NS_TABLE_NONE");