1 /* cmd_neonhelp_stats.c - NeonServ v5.5
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_stats) {
29 printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
31 if (!(row = mysql_fetch_row(res))) return;
32 //check if the user is a supporter (access in the support channel)
33 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");
63 printf_mysql_query("SELECT DISTINCT a.`supporter`, `user_user`, (SELECT COUNT(*) FROM `helpserv_requests` AS b WHERE b.`supporter` = a.`supporter` AND b.`time` > (UNIX_TIMESTAMP()-(3600*24))), (SELECT COUNT(*) FROM `helpserv_requests` AS b WHERE b.`supporter` = a.`supporter` AND b.`time` > (UNIX_TIMESTAMP()-(3600*24*7))), (SELECT COUNT(*) FROM `helpserv_requests` AS b WHERE b.`supporter` = a.`supporter` AND b.`time` > (UNIX_TIMESTAMP()-(3600*24*7*4))) FROM `helpserv_requests` AS a LEFT JOIN `users` ON a.`supporter` = `user_id` WHERE a.`time` > (UNIX_TIMESTAMP()-(3600*24*7*4)) AND `botid` = '%d' ORDER BY `user_user` ASC", client->clientid);
65 table = table_init(4, mysql_num_rows(res) + 1, 0);
67 content[0] = get_language_string(user, "NH_STATS_HEADER_USER");
68 content[1] = get_language_string(user, "NH_STATS_HEADER_LAST_24H");
69 content[2] = get_language_string(user, "NH_STATS_HEADER_LAST_7DAY");
70 content[3] = get_language_string(user, "NH_STATS_HEADER_LAST_30DAY");
71 table_add(table, content);
72 while ((row = mysql_fetch_row(res)) != NULL) {
73 content[0] = (strcmp(row[0], "-1") ? row[1] : "-");
77 table_add(table, content);
79 char **table_lines = table_end(table);
81 for(i = 0; i < table->entrys; i++) {
82 reply(textclient, user, table_lines[i]);
84 if(table->entrys == 1)
85 reply(textclient, user, "NS_TABLE_NONE");