09 Contact Staff

Started by rickandmary, July 21, 2012, 09:38:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rickandmary

#1
This is very useful and allows members to send a message to all staff, you will need to add a link for contact staff to bittorrent.php. First execute the sql

SQL
CREATE TABLE `staffmessages` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `sender` int(10) unsigned NOT NULL DEFAULT '0',
  `added` int(11) DEFAULT '0',
  `msg` text,
  `subject` varchar(100) NOT NULL DEFAULT '',
  `answeredby` int(10) unsigned NOT NULL DEFAULT '0',
  `answered` int(1) NOT NULL DEFAULT '0',
  `answer` text,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=600 ;


contactstaff.php save and upload to root
<?php
/*
+------------------------------------------------
|   TBDev.net BitTorrent Tracker PHP
|   =============================================
|   by CoLdFuSiOn
|   (c) 2003 - 2009 TBDev.Net
|   http://www.tbdev.net
|   =============================================
|   svn: http://sourceforge.net/projects/tbdevnet/
|   Licence Info: GPL
+------------------------------------------------
|   $Date$
|   $Revision$
|   $Author$
|   $URL$
|
+------------------------------------------------
*/
    
require_once "include/bittorrent.php";
    require_once 
"include/user_functions.php";
    require_once 
"include/pager_functions.php";
    require_once 
"include/html_functions.php";

    
dbconn(false);
    
loggedinorreturn();

$lang array_merge(load_language('global'), load_language('contactstaff'));

if($_SERVER['REQUEST_METHOD']  == 'POST') {

$msg = isset($_POST['msg']) ? $_POST['msg'] : '';
$subject = isset($_POST['subject']) ? $_POST['subject'] : '';
$returnto = isset($_POST['returnto']) ? $_POST['returnto'] : $_SERVER['PHP_SELF'];

if (empty($msg))
stderr($lang['contactstaff_error'],$lang['contactstaff_no_msg']);

if (empty($subject))
stderr($lang['contactstaff_error'],$lang['contactstaff_no_sub']);

if(mysql_query('INSERT INTO staffmessages (sender, added, msg, subject) VALUES('.$CURUSER['id'].', '.time().', '.sqlesc($msg).', '.sqlesc($subject).')')) {
header('Refresh: 3; url='.urldecode($returnto)); //redirect but wait 3 seconds
stderr($lang['contactstaff_success'],$lang['contactstaff_success_msg']);
} else
stderr($lang['contactstaff_error'],sprintf($lang['contactstaff_mysql_err'],mysql_error()));
} else  {
   
    
$HTMLOUT  ="<form method='post' name='message' action='".$_SERVER['PHP_SELF']."'>
 <table class='main' width='450' border='0' cellspacing='0' cellpadding='2'>
  <tr><td align='center' colspan='2'>
<h1>
{$lang['contactstaff_title']}</h1>
<p class='small'>
{$lang['contactstaff_info']}</p>
  </td></tr>
  <tr><td align='right'>
{$lang['contactstaff_subject']}
  </td><td align='left'>
<input type='text' size='50' name='subject' style='margin-left: 5px;' />
  </td></tr>
<tr><td align='center' colspan='2'>"
;
        if (isset(
$_GET['returnto']))
$HTMLOUT .="<input type='hidden' name='returnto' value='".urlencode($_GET['returnto'])."' />";
        
$HTMLOUT .="<textarea name='msg' cols='80' rows='15'></textarea>
                       </td>
                     </tr>
                    <tr><td align='center' colspan='2'><input type='submit' value='
{$lang['contactstaff_sendit']}' class='btn' /></td></tr>
                    </table>
        </form>"
;

    print 
stdhead($lang['contactstaff_header']).$HTMLOUT stdfoot();
}
?>


staffbox.php save and upload to root
<?php
/*
+------------------------------------------------
|   TBDev.net BitTorrent Tracker PHP
|   =============================================
|   by CoLdFuSiOn
|   (c) 2003 - 2009 TBDev.Net
|   http://www.tbdev.net
|   =============================================
|   svn: http://sourceforge.net/projects/tbdevnet/
|   Licence Info: GPL
+------------------------------------------------
|   $Date$
|   $Revision$
|   $Author$
|   $URL$
|
+------------------------------------------------
*/
    
require_once "include/bittorrent.php";
    require_once 
"include/user_functions.php";
    require_once 
"include/pager_functions.php";
    require_once 
"include/html_functions.php";
    require_once 
"include/bbcode_functions.php";

    
dbconn(false);
    
loggedinorreturn();

function mkint($x) {
return 0+$x;
}

    
$lang array_merge(load_language('global'), load_language('staffbox'));

    if (
$CURUSER['class'] < UC_MODERATOR)
        
stderr($lang['staffbox_err'], $lang['staffbox_class']);
$valid_do = array('view','delete','setanswered','restart','');

$do = isset($_GET['do']) && in_array($_GET['do'],$valid_do) ? $_GET['do']  : (isset($_POST['do']) && in_array($_POST['do'],$valid_do) ? $_POST['do'] : '');
$id = isset($_GET['id']) ? (int)$_GET['id'] : (isset($_POST['id']) && is_array($_POST['id']) ? array_map('mkint',$_POST['id']) : 0);
$message = isset($_POST['message']) && !empty($_POST['message']) ? $_POST['message'] : '';
$reply = isset($_POST['reply']) && $_POST['reply'] == true false;

switch($do) {
case 'delete' 
if($id 0) {
if(mysql_query('DELETE FROM staffmessages WHERE id IN ('.join(',',$id).')')) {
header('Refresh: 2; url='.$_SERVER['PHP_SELF']);
stderr($lang['staffbox_success'],$lang['staffbox_delete_ids']);
} else 
stderr($lang['staffbox_err'],sprintf($lang['staffbox_sql_err'],mysql_error()));
} else 
stderr($lang['staffbox_err'],$lang['staffbox_odd_err']);
break;
case 'setanswered' 
if($id 0) {
if($reply && empty($message)) {
stderr($lang['staffbox_err'],$lang['staffbox_no_message']);
exit;
}

$q mysql_query('SELECT s.msg,s.sender,s.subject,u.username FROM staffmessages as s LEFT JOIN users as u ON s.sender=u.id WHERE s.id IN ('.join(',',$id).')') or sqlerr(__FILE__,__LINE__);
$a mysql_fetch_assoc($q);
$response htmlspecialchars($message)."\n---"$a['username']." wrote ---\n".$a['msg'];
mysql_query('INSERT INTO messages(sender,receiver,added,subject,msg) VALUES('.$CURUSER['id'].','.$a['sender'].','.time().','.sqlesc('RE: '.$a['subject']).','.sqlesc($response).')') or sqlerr(__FILE__,__LINE__);

$message ', answer='.sqlesc($message);
if(mysql_query('UPDATE staffmessages SET answered=\'1\', answeredby='.$CURUSER['id'].' '.$message.' WHERE id IN ('.join(',',$id).')')) {
header('Refresh: 2; url='.$_SERVER['PHP_SELF']);
stderr($lang['staffbox_success'],$lang['staffbox_setanswered_ids']);
} else 
stderr($lang['staffbox_err'],sprintf($lang['staffbox_sql_err'],mysql_error()));
} else 
stderr($lang['staffbox_err'],$lang['staffbox_odd_err']);
break;
case 'view' :
if($id 0) {
$q mysql_query('SELECT s.id, s.added, s.msg, s.subject, s.answered, s.answer, s.answeredby, s.sender, s.answer, u.username , u2.username as username2 
FROM staffmessages  as s
LEFT JOIN users as u ON s.sender = u.id 
LEFT JOIN users as u2 ON s.answeredby = u2.id 
WHERE s.id = '
.$id) or sqlerr(__FILE__,__LINE__);
if(mysql_num_rows($q) == 1) {
$a mysql_fetch_assoc($q);
$HTMLOUT begin_main_frame().begin_frame($lang['staffbox_pm_view']);
$HTMLOUT .= "<form action='".$_SERVER['PHP_SELF']."' method='post'>
<table width='80%' border='1' cellspacing='0' cellpadding='5' align='center'>
 <tr><td>
{$lang['staffbox_pm_from']}&nbsp;<a href='userdetails.php?id=".$a['sender']."'>".$a['username']."</a> at ".get_date($a['added'],'DATE',1)."<br/>
 
{$lang['staffbox_pm_subject']} : <b>".htmlspecialchars($a['subject'])."</b><br/>
 
{$lang['staffbox_pm_answered']} : <b>".($a['answeredby'] > "<a href='userdetails.php?id=".$a['answeredby']."'>".$a['username2']."</a>" "<span style='color:#ff0000'>No</span>")."</b>
</td></tr>
<tr><td>"
.format_comment($a['msg'])."
</td></tr>
<tr><td>
{$lang['staffbox_pm_answer']}<br/>
"
.($a['answeredby'] == "<textarea rows='5' cols='75' name='message' ></textarea>" : ($a['answer'] ? format_comment($a['answer']) : "<b>{$lang['staffbox_pm_noanswer']}</b>"))."
</td></tr>
<tr><td align='left'>
<select name='do'>
<option value='setanswered' "
.($a['answeredby'] > 'disabled=\'disabled\'' "" )." >{$lang['staffbox_pm_reply']}</option>
<option value='restart' "
.($a['answeredby'] != $CURUSER['id'] ? 'disabled=\'disabled\'' "" )." >{$lang['staffbox_pm_restart']}</option>
<option value='delete'>
{$lang['staffbox_pm_delete']}</option>
</select>
<input type='hidden' name='reply' value='1'/>
<input type='hidden' name='id[]' value='"
.$a['id']."'/><input type='submit' value='{$lang['staffbox_confirm']}' />
</td></tr>
</table>
</form>"
;
$HTMLOUT.= end_frame().end_main_frame();
print(stdhead('StaffBox').$HTMLOUT.stdfoot());
} else 
stderr($lang['staffbox_err'],$lang['staffbox_msg_noid']);
} else
stderr($lang['staffbox_err'],$lang['staffbox_odd_err']);
break;
case 'restart' 
if($id 0) {
if(mysql_query('UPDATE staffmessages SET answered=\'0\', answeredby=\'0\' WHERE id IN ('.join(',',$id).')')) {
header('Refresh: 2; url='.$_SERVER['PHP_SELF']);
stderr($lang['staffbox_success'],$lang['staffbox_restart_ids']);
} else 
stderr($lang['staffbox_err'],sprintf($lang['staffbox_sql_err'],mysql_error()));
} else 
stderr($lang['staffbox_err'],$lang['staffbox_odd_err']);
break;
default: 
$count_msgs get_row_count('staffmessages');
    
$perpage 4;
    
$pager pager($perpage$count_msgs'staffbox.php?');

   

    if (!
$count_msgs)
stderr($lang['staffbox_err'],$lang['staffbox_no_msgs']);
else {

$HTMLOUT begin_main_frame().begin_frame($lang['staffbox_info']);
    
$HTMLOUT .= $pager['pagertop'];

$HTMLOUT .="<form method='post' name='staffbox' action='".$_SERVER['PHP_SELF']."'>";
    
$HTMLOUT .="<table width='90%' border='1' cellspacing='0' cellpadding='5' align='center'>";
    
$HTMLOUT .="<tr>
                 <td class='colhead' align='center' width='100%'>
{$lang['staffbox_subject']}</td>
                 <td class='colhead' align='center'>
{$lang['staffbox_sender']}</td>
                 <td class='colhead' align='center'>
{$lang['staffbox_added']}</td>
                 <td class='colhead' align='center'>
{$lang['staffbox_answered']}</td>
                 <td class='colhead' align='center'><input type='checkbox' name='t' onclick=\"checkbox('staffbox')\" /></td>
                </tr>"
;

    
$r mysql_query('SELECT s.id, s.added, s.subject, s.answered, s.answeredby, s.sender, s.answer, u.username , u2.username as username2 
FROM staffmessages  as s
LEFT JOIN users as u ON s.sender = u.id 
LEFT JOIN users as u2 ON s.answeredby = u2.id 
ORDER BY id desc '
.$pager['limit']) or sqlerr(__FILE____LINE__);

    while (
$a mysql_fetch_assoc($r))
$HTMLOUT .="<tr>
                   <td align='center'><a href='"
.$_SERVER['PHP_SELF']."?do=view&amp;id=".$a['id']."'>" .htmlspecialchars($a['subject']). "</a></td>
                   <td align='center'><b>"
.($a['username'] ? "<a href='userdetails.php?id=".$a['sender']."'>".$a['username']."</a>" "Unknown[".$a['sender']."]")."</b></td>
                   <td align='center' nowrap='nowrap'>" 
.get_date($a['added'],'DATE',1)."<br/><span class='small'>".get_date($a['added'],0,0,1)."</span></td>
   <td align='center'><b>"
.($a['answeredby'] > "by <a href='userdetails.php?id=".$a['answeredby']."'>".$a['username2']."</a>" "<span style='color:#ff0000'>No</span>")."</b></td>
                   <td align='center'><input type='checkbox' name='id[]' value='" 
$a['id'] . "' /></td>
                  </tr>\n"
;

$HTMLOUT .="<tr><td align='right' colspan='5'>
<select name='do'>
<option value='delete'>
{$lang['staffbox_do_delete']}</option>
<option value='setanswered'>
{$lang['staffbox_do_set']}</option>
</select>
<input type='submit' value='
{$lang['staffbox_confirm']}' /></td></tr>
</table></form>"
;

    
$HTMLOUT .= $pager['pagerbottom'];

    
$HTMLOUT .= end_frame().end_main_frame();
    }
    print 
stdhead($lang['staffbox_head']) . $HTMLOUT stdfoot();
}

?>


lang_contactstaff.php save and upload to lang/en/

<?php

$lang 
= array(

#Contact Staff
'contactstaff_title'           => 'Send message to staff',
'contactstaff_info'            => 'If you wish to contact the staff due to a certain user or just a general problem please use this!',
'contactstaff_subject'         => 'Subject',
'contactstaff_sendit'          => 'Send It!',
'contactstaff_header'          => 'ContactStaff',
'contactstaff_error'           => 'Error',
#takecontact - 2 files merged
'contactstaff_no_sub'          => 'Your messages doesn\'t have a subject',
'contactstaff_no_msg'          => 'Your messages doesn\'t have a body',
'contactstaff_success'         => 'Success',
'contactstaff_success_msg'     => 'Message was sent! Wait for staff to respond now! Please wait while redirecting...',
'contactstaff_mysql_err'       => 'There was something wrong, Mysql Err: %s',

);

?>


lang_staffbox.php save and upload to lang/en/
<?php
$lang 
= array(
 
'staffbox_head' => 'StaffBox',
 
'staffbox_class' => 'You can\'t use this!',
 
'staffbox_err' => 'Error',
 
'staffbox_odd_err' => 'Something was wrong, I have no idea what!',
 
'staffbox_success' => 'Success',
 
'staffbox_info' => 'Staff Box - messages sent by users',
 
'staffbox_no_msgs' => 'There is no message for the staff',
 
'staffbox_confirm' => 'Confirm',
 
'staffbox_vanswer' => 'View Answer',
 
'staffbox_subject' => 'Subject',
 
'staffbox_sender' => 'Sender',
 
'staffbox_added' => 'Added',
 
'staffbox_do_delete' => 'Delete',
 
'staffbox_do_set' => 'Set answered',
 
'staffbox_answered' => 'Answered',
 
'staffbox_sql_err' => 'There was an error with the query please contact the staff! Mysql Error : %s',
 
'staffbox_delete_ids' => 'The messege(s) you selected were deleted! Wait while redirecting...',
 
'staffbox_setanswered_ids' => 'The messege(s) you selected were set as answered! Wait while redirecting...',
 
'staffbox_msg_noid' => 'There is message with this id',
 
'staffbox_pm_view' => 'Message to staff',
 
'staffbox_pm_subject' => 'Subject',
 
'staffbox_pm_from' => 'From',
 
'staffbox_pm_answered' => 'Answered by',
 
'staffbox_pm_reply' => 'Reply',
 
'staffbox_pm_delete' => 'Delete',
 
'staffbox_pm_answer' => 'Staff response:',
 
'staffbox_pm_noanswer' => 'No answer from the staff',
 
'staffbox_no_message' => 'You didn\'t write any message for the user!',
 
'staffbox_pm_restart' => 'Reset',
 
'staffbox_restart_ids' => 'The messege(s) you selected were Reset for someone else to deal with! Wait while redirecting...',
);
?>


add to bittorrent.php so staff are alerted when a new message has been posted

if($TBDEV['staffmsg_alert'] && $CURUSER['class'] >= UC_MODERATOR) {
                $num = mysql_result(mysql_query('SELECT count(id) FROM staffmessages WHERE answeredby = 0'),0);
                if($num > 0)
                $htmlout .= "<p><table border='0' cellspacing='0' cellpadding='10'>
                  <tr><td style='padding: 10px; background: #ccc'>\n
                  <b><a href='staffbox.php'>".sprintf($lang['gl_staffmsg_alert'], $num). "!</a></b>
                  </td></tr></table><br/>";
        }


add this to lang_global.php under other message alert

gl_staffmsg_alert'             =>      "There is %s new message for the staff",

add to config.php

$TBDEV['staffmsg_alert'] = 1;

I don't think i forgot to add anything, if i have let me know and i will add it, thanks to the author of this mod