1 /* cmd_neonhelp_history.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"
21 * argv[0] matching string
24 CMD_BIND(neonhelp_cmd_history) {
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 char *match_str = escape_string(argv[0]);
61 printf_mysql_query("SELECT `id`, `nick`, `hand`, `host`, `time`, `text`, `status`, `supporter`, `users`.`user_user`, MD5(CONCAT(`id`, `host`, `time`, `supporter`)) FROM `helpserv_requests` LEFT JOIN `users` ON `supporter` = `user_id` WHERE `botid` = '%d' AND (`host` LIKE '%%%s%%' OR `hand` LIKE '%%%s%%' OR `nick` LIKE '%%%s%%') ORDER BY `time` ASC LIMIT 100", client->clientid, match_str, match_str, match_str);
63 table = table_init(6, mysql_num_rows(res)*3 + 1, 0);
64 table->col_flags[1] |= TABLE_FLAG_COL_SKIP_NULL;
65 table->col_flags[2] |= TABLE_FLAG_COL_SKIP_NULL;
66 table->col_flags[3] |= TABLE_FLAG_COL_SKIP_NULL;
67 table->col_flags[4] |= TABLE_FLAG_COL_SKIP_NULL;
69 content[0] = get_language_string(user, "NH_REQUESTS_HEADER_ID");
70 content[1] = get_language_string(user, "NH_REQUESTS_HEADER_NICK");
71 content[2] = get_language_string(user, "NH_REQUESTS_HEADER_AUTH");
72 content[3] = get_language_string(user, "NH_REQUESTS_HEADER_MASK");
73 content[4] = get_language_string(user, "NH_REQUESTS_HEADER_TIME");
74 content[5] = get_language_string(user, "NH_REQUESTS_HEADER_STATUS");
75 table_add(table, content);
79 char statestr[MAXLEN];
80 while ((row = mysql_fetch_row(res)) != NULL) {
85 rawtime = atoi(row[4]);
86 timeinfo = localtime(&rawtime);
87 strftime(timestr, MAXLEN, "%d.%m.%Y %H:%M:%S", timeinfo);
89 switch(atoi(row[6])) {
91 content[5] = get_language_string(user, "NH_REQUESTS_STATE_PENDING");
94 sprintf(statestr, "%s (%s)", get_language_string(user, "NH_REQUESTS_STATE_ACTIVE"), row[8]);
95 content[5] = statestr;
98 sprintf(statestr, "%s (%s)", get_language_string(user, "NH_REQUESTS_STATE_CLOSED"), (strcmp(row[7], "0") ? row[8] : "*"));
99 content[5] = statestr;
102 table_add(table, content);
104 if((p = strstr(row[5], "\n")))
111 sprintf(statestr, "\00314\002\002%s\003", row[5]);
112 content[5] = statestr;
113 table_add(table, content);
115 sprintf(setting, "modules.%s.log_link", get_module_name(module_id));
116 if((p = get_string_field(setting))) {
117 statestr[0] = '\003';
120 int pos = sprintf(statestr+3, p, row[0], row[9]);
121 statestr[pos+3] = '\003';
122 statestr[pos+4] = '\0';
123 content[5] = statestr;
124 table_add(table, content);
128 char **table_lines = table_end(table);
130 for(i = 0; i < table->entrys; i++) {
131 reply(textclient, user, table_lines[i]);
133 if(table->entrys == 1)
134 reply(textclient, user, "NS_TABLE_NONE");