"coco, post: 69528, member: 20298":
Can this mod be modified for TTv.3.0 MySQLI
I run UFFENO1 version but when post message and press Help Me give me error Database Error. Please report this to an administrator.
Thanks in advance
"coco, post: 69530, member: 20298":
Thank you spiritblue but again same error :(
CREATE TABLE IF NOT EXISTS `helpdesk` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(60) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`msg_problem` text COLLATE utf8_unicode_ci,
`added` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`solved_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`solved` enum('no','yes','ignored') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',
`added_by` int(10) NOT NULL DEFAULT '0',
`solved_by` int(10) NOT NULL DEFAULT '0',
`msg_answer` text COLLATE utf8_unicode_ci,
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
//=== HELP DESK message
if (get_user_class() >= 5){
$resa = SQL_Query_exec("select count(id) as problems from helpdesk WHERE solved = 'no'");
$arra = mysqli_fetch_assoc($resa);
$problems = $arra['problems'];
if ($problems > 0)
echo("<p><table align=center border=0 cellspacing=0 cellpadding=10 bgcolor=red><tr><td style='padding: 10px; background: #A60A15'>".
"Hi <b>$CURUSER[username]</b>, there ".($problems == 1 ? 'is' : 'are')." <b>$problems question".($problems == 1 ? '' : 's')."</b> at the HELP DESK that needs a reply.<br>please click <b><a href=helpdesk.php?action=problems>HERE</a></b> to deal with it.".
"</td></tr></table></p><br />");
}
CREATE TABLE IF NOT EXISTS `support_desk` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(60) NOT NULL DEFAULT '',
`msg_problem` TEXT NULL,
`added` DATETIME NOT NULL,
`added_by` INT UNSIGNED NOT NULL DEFAULT 0,
`solved` ENUM('no','yes','ignored') NOT NULL DEFAULT 'no',
`solved_by` INT UNSIGNED NOT NULL DEFAULT 0,
`solved_date` DATETIME NULL DEFAULT NULL,
`msg_answer` TEXT NULL,
KEY `solved` (`solved`),
KEY `added_by` (`added_by`)
) ENGINE=MyISAM;<?php
// Help Desk (originally from TBDev, adapted for TorrentTrader by the community).
// Updated for PHP 8, with staff-only actions and a polite wording.
require_once("backend/functions.php");
dbconn();
loggedinonly();
// lowest class that may answer tickets, and that may delete closed tickets
const HD_STAFF_CLASS = 5;
const HD_CLEANUP_CLASS = 7;
$class = (int) get_user_class();
$is_staff = $class >= HD_STAFF_CLASS;
function hd_e($value) {
return htmlspecialchars((string) $value, ENT_QUOTES);
}
function hd_duration($seconds) {
$seconds = (int) $seconds;
foreach (array(array(604800, "HD_TIME_WEEK", "HD_TIME_WEEKS"), array(86400, "HD_TIME_DAY", "HD_TIME_DAYS"), array(3600, "HD_TIME_HOUR", "HD_TIME_HOURS"), array(60, "HD_TIME_MIN", "HD_TIME_MINS")) as $unit) {
if ($seconds >= $unit[0]) {
$n = intdiv($seconds, $unit[0]);
return "$n " . T_($n == 1 ? $unit[1] : $unit[2]);
}
}
return T_("HD_TIME_LESS");
}
function hd_user_link($id, $name) {
return $name !== null ? "<a href='account-details.php?id=" . (int) $id . "'><b>" . class_user($name) . "</b></a>" : "-";
}
function hd_require_staff($is_staff) {
if (!$is_staff) show_error_msg(T_("ERROR"), T_("HD_NOT_ALLOWED"), 1);
}
// ---- form actions
$do = $_POST["do"] ?? "";
if ($do === "ask") {
$title = trim((string) ($_POST["title"] ?? ""));
$problem = trim((string) ($_POST["msg_problem"] ?? ""));
if ($title === "" || $problem === "") show_error_msg(T_("ERROR"), T_("HD_FILL_IN_BOTH"), 1);
$user = (int) $CURUSER["id"];
$since = get_date_time(time() - 600);
$dupe = mysqli_fetch_row(SQL_Query_exec("SELECT COUNT(*) FROM support_desk WHERE added_by = $user AND title = " . sqlesc(substr($title, 0, 60)) . " AND added > '$since'"));
if (!$dupe || (int) $dupe[0] === 0) {
SQL_Query_exec("INSERT INTO support_desk (title, msg_problem, added, added_by) VALUES (" . sqlesc(substr($title, 0, 60)) . ", " . sqlesc($problem) . ", '" . get_date_time() . "', $user)");
}
autolink("index.php", T_("HD_SENT"));
}
if ($do === "answer") {
hd_require_staff($is_staff);
$id = (int) ($_POST["id"] ?? 0);
$answer = trim((string) ($_POST["msg_answer"] ?? ""));
$ticket = mysqli_fetch_assoc(SQL_Query_exec("SELECT d.*, u.username FROM support_desk d LEFT JOIN users u ON u.id = d.added_by WHERE d.id = $id"));
if (!$ticket || $answer === "") show_error_msg(T_("ERROR"), T_("HD_FILL_IN_ANSWER"), 1);
SQL_Query_exec("UPDATE support_desk SET solved = 'yes', solved_by = " . (int) $CURUSER["id"] . ", solved_date = '" . get_date_time() . "', msg_answer = " . sqlesc($answer) . " WHERE id = $id");
$msg = "" . T_("HD_TITLE") . "\n\n" . $ticket["username": . "]" . $ticket["msg_problem"] . "
\n" . T_("HD_ANSWER") . ": $answer\n\n" . T_("HD_REGARDS");
SQL_Query_exec("INSERT INTO messages (sender, receiver, added, subject, msg, poster) VALUES (" . (int) $CURUSER["id"] . ", " . (int) $ticket["added_by"] . ", '" . get_date_time() . "', " . sqlesc(T_("HD_TITLE")) . ", " . sqlesc($msg) . ", " . (int) $CURUSER["id"] . ")");
autolink("helpdesk.php?action=problems", T_("HD_ANSWER_SENT"));
}
if ($do === "ignore") {
hd_require_staff($is_staff);
$id = (int) ($_POST["id"] ?? 0);
SQL_Query_exec("UPDATE support_desk SET solved = 'ignored', solved_by = " . (int) $CURUSER["id"] . ", solved_date = '" . get_date_time() . "' WHERE id = $id AND solved = 'no'");
autolink("helpdesk.php?action=problems", T_("HD_IGNORED_DONE"));
}
if ($do === "cleanup") {
if ($class < HD_CLEANUP_CLASS) show_error_msg(T_("ERROR"), T_("HD_NOT_ALLOWED"), 1);
SQL_Query_exec("DELETE FROM support_desk WHERE solved IN ('yes', 'ignored')");
autolink("helpdesk.php?action=problems", T_("HD_CLEANED"));
}
// ---- staff: one ticket, or the list
if (($_GET["action"] ?? "") === "problems") {
hd_require_staff($is_staff);
$id = (int) ($_GET["id"] ?? 0);
stdhead(T_("HD_TITLE"));
begin_frame(T_("HD_TITLE"));
if ($id > 0) {
$ticket = mysqli_fetch_assoc(SQL_Query_exec("SELECT d.*, a.username AS added_name, s.username AS solved_name FROM support_desk d LEFT JOIN users a ON a.id = d.added_by LEFT JOIN users s ON s.id = d.solved_by WHERE d.id = $id"));
if (!$ticket) {
echo "<p>" . T_("HD_NOT_FOUND") . "</p>";
} else {
$replies = array(T_("HD_REPLY_FAQ_TEXT"), T_("HD_REPLY_FORUMS_TEXT"), T_("HD_REPLY_MORE_TEXT"));
?>
<table class="table_table" cellpadding="5" width="100%">
<tr><th class="table_head" colspan="2"><?php echo hd_e($ticket["title"]); ?></th></tr>
<tr><td class="table_col1" width="140"><b><?php echo T_("ADDED"); ?></b></td><td class="table_col2"><?php echo hd_e(utc_to_tz($ticket["added"])); ?> · <?php echo hd_user_link($ticket["added_by"], $ticket["added_name"]); ?></td></tr>
<tr><td class="table_col1"><b><?php echo T_("HD_PROBLEM"); ?></b></td><td class="table_col2"><div class="hd-text"><?php echo nl2br(hd_e($ticket["msg_problem"])); ?></div></td></tr>
<?php if ($ticket["solved"] === "no") { ?>
<tr><td class="table_col1"><b><?php echo T_("HD_ANSWER"); ?></b></td><td class="table_col2">
<form method="post" action="helpdesk.php" id="hd-answer">
<input type="hidden" name="do" value="answer" />
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<label><?php echo T_("HD_STANDARD_REPLIES"); ?>
<select id="hd-reply"><option value=""></option>
<option value="<?php echo hd_e($replies[0]); ?>"><?php echo T_("HD_REPLY_FAQ"); ?></option>
<option value="<?php echo hd_e($replies[1]); ?>"><?php echo T_("HD_REPLY_FORUMS"); ?></option>
<option value="<?php echo hd_e($replies[2]); ?>"><?php echo T_("HD_REPLY_MORE"); ?></option>
</select>
</label><br />
<textarea name="msg_answer" id="hd-answer-text" rows="10" class="hd-area" required></textarea>
<div><a href="tags.php"><?php echo T_("HD_BBCODE_ALLOWED"); ?></a></div>
<input type="submit" value="<?php echo T_("HD_SEND_ANSWER"); ?>" />
</form>
<form method="post" action="helpdesk.php" class="hd-inline" onsubmit="return confirm('<?php echo hd_e(T_("HD_IGNORE_CONFIRM")); ?>');">
<input type="hidden" name="do" value="ignore" /><input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="submit" value="<?php echo T_("HD_IGNORE"); ?>" />
</form>
<script>
document.getElementById("hd-reply").addEventListener("change", function () {
if (this.value) document.getElementById("hd-answer-text").value = this.value;
});
</script>
</td></tr>
<?php } else { ?>
<tr><td class="table_col1"><b><?php echo T_("HD_STATUS"); ?></b></td><td class="table_col2"><b class="<?php echo $ticket["solved"] === "yes" ? "hd-good" : "hd-warn"; ?>"><?php echo T_($ticket["solved"] === "yes" ? "HD_SOLVED" : "HD_IGNORED"); ?></b> · <?php echo hd_e(utc_to_tz((string) $ticket["solved_date"])); ?> · <?php echo hd_user_link($ticket["solved_by"], $ticket["solved_name"]); ?></td></tr>
<?php if ($ticket["solved"] === "yes") { ?>
<tr><td class="table_col1"><b><?php echo T_("HD_ANSWER"); ?></b></td><td class="table_col2"><div class="hd-text"><?php echo nl2br(hd_e($ticket["msg_answer"])); ?></div></td></tr>
<?php } ?>
<?php } ?>
</table>
<?php
}
echo "<p><a href='helpdesk.php?action=problems'>" . T_("HD_BACK_TO_LIST") . "</a></p>";
} else {
$res = SQL_Query_exec("SELECT d.*, a.username AS added_name, s.username AS solved_name FROM support_desk d LEFT JOIN users a ON a.id = d.added_by LEFT JOIN users s ON s.id = d.solved_by ORDER BY (d.solved = 'no') DESC, d.added DESC");
echo "<table class='table_table' cellpadding='5' width='100%'><tr>";
foreach (array(T_("ADDED"), T_("HD_ADDED_BY"), T_("HD_PROBLEM"), T_("HD_STATUS"), T_("HD_HANDLED_BY"), T_("HD_SOLVED_IN")) as $heading) echo "<th class='table_head'>$heading</th>";
echo "</tr>";
$any = false;
while ($res && ($row = mysqli_fetch_assoc($res))) {
$any = true;
$took = "-";
$speed = "";
if ($row["solved_date"] !== null) {
$seconds = strtotime($row["solved_date"]) - strtotime($row["added"]);
$took = hd_duration($seconds);
$speed = $seconds <= 1800 ? "hd-good" : ($seconds <= 7200 ? "hd-warn" : "hd-bad");
}
$status = array("no" => array("HD_OPEN", "hd-bad"), "yes" => array("HD_SOLVED", "hd-good"), "ignored" => array("HD_IGNORED", "hd-warn"))[$row["solved"]];
echo "<tr align='center'><td class='table_col1'>" . hd_e(utc_to_tz($row["added"])) . "</td>"
. "<td class='table_col2'>" . hd_user_link($row["added_by"], $row["added_name"]) . "</td>"
. "<td class='table_col1'><a href='helpdesk.php?action=problems&id=" . (int) $row["id"] . "'><b>" . hd_e($row["title"]) . "</b></a></td>"
. "<td class='table_col2'><b class='$status[1]'>" . T_($status[0]) . "</b></td>"
. "<td class='table_col1'>" . hd_user_link($row["solved_by"], $row["solved_name"]) . "</td>"
. "<td class='table_col2'><b class='$speed'>$took</b></td></tr>";
}
if (!$any) echo "<tr><td class='table_col1' colspan='6' align='center'>" . T_("HD_NO_TICKETS") . "</td></tr>";
echo "</table>";
echo "<p class='hd-legend'>" . T_("HD_RESPONSE_TIME") . ": <b class='hd-good'>" . T_("HD_GREAT") . "</b>, <b class='hd-warn'>" . T_("HD_ACCEPTABLE") . "</b>, <b class='hd-bad'>" . T_("HD_SLOW") . "</b></p>";
if ($class >= HD_CLEANUP_CLASS) {
echo "<form method='post' action='helpdesk.php' onsubmit=\"return confirm('" . hd_e(T_("HD_DELETE_CONFIRM")) . "');\"><input type='hidden' name='do' value='cleanup' /><input type='submit' value='" . T_("HD_DELETE_CLOSED") . "' /></form>";
}
}
end_frame();
stdfoot();
exit;
}
// ---- members: ask for help
stdhead(T_("HD_TITLE"));
begin_frame(T_("HD_TITLE"));
if ($is_staff) {
echo "<p><a href='helpdesk.php?action=problems'><b>" . T_("HD_TROUBLE_TICKETS") . "</b></a></p>";
}
?>
<div class="hd-info">
<p><?php echo T_("HD_INFO1"); ?></p>
<p><?php echo T_("HD_INFO2"); ?></p>
<p><?php echo T_("HD_INFO3"); ?></p>
</div>
<form method="post" action="helpdesk.php" class="hd-form">
<input type="hidden" name="do" value="ask" />
<label><?php echo T_("HD_SUBJECT"); ?>
<input type="text" name="title" maxlength="60" required />
</label>
<label><?php echo T_("HD_PROBLEM"); ?>
<textarea name="msg_problem" rows="12" class="hd-area" required></textarea>
</label>
<input type="submit" value="<?php echo T_("HD_HELP_ME"); ?>" />
</form>
<?php
end_frame();
stdfoot();
?>.hd-good { color: green; }
.hd-warn { color: darkorange; }
.hd-bad { color: red; }
.hd-area { width: 100%; box-sizing: border-box; }
.hd-form { display: flex; flex-direction: column; gap: 12px; max-width: 760px; }
.hd-form label { display: flex; flex-direction: column; gap: 4px; font-weight: bold; }<td align="center"><a href="admincp.php?action=sqlerr"><img src="images/admin/sql_error.png" border="0" width="118" width="80" alt="" /><br />SQL Error<br /></a></td><td align="center"><a href="helpdesk.php?action=problems"><img src="images/admin/help-desk.png" border="0" width="32" height="32" alt="" /><br />Helpdesk</a></td>// Tells staff on the home page when Help Desk requests are waiting.
if (!empty($CURUSER) && (int) $CURUSER["class"] >= 5) {
$hd_res = SQL_Query_exec("SELECT COUNT(*) FROM support_desk WHERE solved = 'no'");
$hd_row = $hd_res ? mysqli_fetch_row($hd_res) : null;
$hd_open = $hd_row ? (int) $hd_row[0] : 0;
if ($hd_open > 0) {
begin_frame(T_("HD_TITLE"));
echo "<p>"
. ($hd_open === 1 ? T_("HD_STAFF_NOTICE_ONE") : sprintf(T_("HD_STAFF_NOTICE_MANY"), $hd_open))
. " <a href='helpdesk.php?action=problems'><b>" . T_("HD_STAFF_NOTICE_LINK") . "</b></a></p>";
end_frame();
}
}$LANG["HD_TITLE"] = 'Help Desk';
$LANG["HD_TROUBLE_TICKETS"] = 'View open support requests';
$LANG["HD_INFO1"] = 'Before asking, please check the <a href="faq.php">FAQ</a> and search the <a href="forums.php">Forums</a>, as your question may already be answered there.';
$LANG["HD_INFO2"] = 'Please give as much detail as you can so we can help you quickly. Requests are answered in the order they are received. Please treat our volunteers with respect.';
$LANG["HD_INFO3"] = 'If you are asking for a reseed, please include the link to the torrent.';
$LANG["HD_SUBJECT"] = 'Subject';
$LANG["HD_PROBLEM"] = 'Your question';
$LANG["HD_HELP_ME"] = 'Send request';
$LANG["HD_SENT"] = 'Thank you. Your request has been sent, and you will receive the answer by private message.';
$LANG["HD_FILL_IN_BOTH"] = 'Please fill in both the subject and your question.';
$LANG["HD_FILL_IN_ANSWER"] = 'Please enter an answer.';
$LANG["HD_NOT_ALLOWED"] = 'You do not have permission to do this.';
$LANG["HD_NOT_FOUND"] = 'This request could not be found.';
$LANG["HD_ADDED_BY"] = 'Asked by';
$LANG["HD_ANSWER"] = 'Answer';
$LANG["HD_STATUS"] = 'Status';
$LANG["HD_HANDLED_BY"] = 'Handled by';
$LANG["HD_SOLVED_IN"] = 'Time to answer';
$LANG["HD_OPEN"] = 'Open';
$LANG["HD_SOLVED"] = 'Solved';
$LANG["HD_IGNORED"] = 'Closed without reply';
$LANG["HD_IGNORE"] = 'Close without reply';
$LANG["HD_IGNORE_CONFIRM"] = 'Close this request without replying?';
$LANG["HD_IGNORED_DONE"] = 'The request has been closed.';
$LANG["HD_SEND_ANSWER"] = 'Send answer';
$LANG["HD_ANSWER_SENT"] = 'Your answer has been sent to the member.';
$LANG["HD_BACK_TO_LIST"] = 'Back to all requests';
$LANG["HD_NO_TICKETS"] = 'There are no support requests.';
$LANG["HD_STANDARD_REPLIES"] = 'Standard replies:';
$LANG["HD_BBCODE_ALLOWED"] = 'BB Code is allowed';
$LANG["HD_REPLY_FAQ"] = 'See the FAQ';
$LANG["HD_REPLY_FAQ_TEXT"] = 'Thank you for your question. You can find the answer in our [url=faq.php]FAQ[/url]. Please let us know if anything is still unclear.';
$LANG["HD_REPLY_FORUMS"] = 'Search the forums';
$LANG["HD_REPLY_FORUMS_TEXT"] = 'Thank you for your question. This has been covered before, so a search of our [url=forums.php]Forums[/url] should help. Please let us know if you cannot find it.';
$LANG["HD_REPLY_MORE"] = 'Ask for more details';
$LANG["HD_REPLY_MORE_TEXT"] = 'Thank you for your question. Could you please give us a little more detail so that we can help you?';
$LANG["HD_REGARDS"] = 'Kind regards, the Help Desk team';
$LANG["HD_RESPONSE_TIME"] = 'Response time';
$LANG["HD_GREAT"] = 'under 30 minutes';
$LANG["HD_ACCEPTABLE"] = 'under 2 hours';
$LANG["HD_SLOW"] = 'over 2 hours';
$LANG["HD_DELETE_CLOSED"] = 'Delete solved and closed requests';
$LANG["HD_DELETE_CONFIRM"] = 'Delete all solved and closed requests? This cannot be undone.';
$LANG["HD_CLEANED"] = 'Solved and closed requests have been deleted.';
$LANG["HD_TIME_WEEK"] = 'week';
$LANG["HD_TIME_WEEKS"] = 'weeks';
$LANG["HD_TIME_DAY"] = 'day';
$LANG["HD_TIME_DAYS"] = 'days';
$LANG["HD_TIME_HOUR"] = 'hour';
$LANG["HD_TIME_HOURS"] = 'hours';
$LANG["HD_TIME_MIN"] = 'minute';
$LANG["HD_TIME_MINS"] = 'minutes';
$LANG["HD_TIME_LESS"] = 'less than a minute';
$LANG["HD_STAFF_NOTICE_ONE"] = 'There is 1 Help Desk request waiting for an answer.';
$LANG["HD_STAFF_NOTICE_MANY"] = 'There are %d Help Desk requests waiting for an answer.';
$LANG["HD_STAFF_NOTICE_LINK"] = 'Open the Help Desk';No users online
Torrents
Members
Online