+/* cmd_neonhelp_requests.c - NeonServ v5.3
+ * Copyright (C) 2011-2012 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "cmd_neonhelp.h"
+
+/*
+* no args
+*/
+
+CMD_BIND(neonhelp_cmd_requests) {
+ //check permissions
+ MYSQL_RES *res;
+ MYSQL_ROW row, row2;
+ int caccess = 0;
+ int userid;
+ printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
+ res = mysql_use();
+ if (!(row = mysql_fetch_row(res))) return;
+ //check if the user is a supporter (access in the support channel)
+ if((user->flags & USERFLAG_ISAUTHED)) {
+ if(user->flags & USERFLAG_HAS_USERID)
+ userid = user->user_id;
+ else {
+ printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
+ res = mysql_use();
+ if ((row2 = mysql_fetch_row(res)) != NULL) {
+ userid = atoi(row2[0]);
+ user->user_id = userid;
+ user->flags |= USERFLAG_HAS_USERID;
+ } else
+ userid = 0;
+ }
+ 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]));
+ res = mysql_use();
+ if ((row2 = mysql_fetch_row(res)) != NULL) {
+ int cflags = atoi(row2[1]);
+ if(!(cflags & DB_CHANUSER_SUSPENDED))
+ caccess = atoi(row2[0]);
+ }
+ }
+ if(!caccess) {
+ reply(getTextBot(), user, "MODCMD_ACCESS_DENIED");
+ return;
+ }
+ struct Table *table;
+ printf_mysql_query("SELECT `id`, `time`, `text` FROM `helpserv_requests` WHERE `botid` = '%d' ORDER BY `time` DESC", client->clientid);
+ res = mysql_use();
+ table = table_init(5, mysql_num_rows(res) + 1, 0);
+ char *content[5];
+ content[0] = get_language_string(user, "NH_REQUESTS_HEADER_ID");
+ content[1] = get_language_string(user, "NH_REQUESTS_HEADER_STATUS");
+ content[2] = get_language_string(user, "NH_REQUESTS_HEADER_NICK");
+ content[3] = get_language_string(user, "NH_REQUESTS_HEADER_TIME");
+ content[4] = get_language_string(user, "NH_REQUESTS_HEADER_REQUEST");
+ table_add(table, content);
+ char timestr[MAXLEN];
+ struct NeonHelpNode *helpnode;
+ int suppid;
+ while ((row = mysql_fetch_row(res)) != NULL) {
+ content[0] = row[0];
+ suppid = atoi(row[0]);
+ if(client->flags & SOCKET_HAVE_HELPNODE) {
+ for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
+ if(helpnode->suppid == suppid) {
+ if(helpnode->status)
+ content[1] = get_language_string(user, "NH_REQUESTS_STATE_ACTIVE");
+ else
+ content[1] = get_language_string(user, "NH_REQUESTS_STATE_PENDING");
+ content[2] = helpnode->user->nick;
+ break;
+ }
+ }
+ } else {
+ content[1] = get_language_string(user, "NH_REQUESTS_STATE_ERROR");
+ content[2] = NULL;
+ }
+ timeToStr(user, (time(0) - atoi(row[1])), 2, timestr);
+ content[3] = timestr;
+ char *p;
+ if((p = strstr(row[2], "\n")))
+ *p = '\0';
+ content[4] = row[2];
+ table_add(table, content);
+ }
+ //send the table
+ char **table_lines = table_end(table);
+ int i;
+ for(i = 0; i < table->entrys; i++) {
+ reply(getTextBot(), user, table_lines[i]);
+ }
+ if(table->entrys == 1)
+ reply(getTextBot(), user, "NS_TABLE_NONE");
+}