Title: Forum Based Mark Threads v1.1

Author: Adam Clarke

Updated By: John Briggs

Description:
This modification will allow forum moderators to mark threads (eg: [In Progress], [Resolved]).
The thread prefixes can be set via Admin Panel -> Forums -> More Options.
There are two prefix input boxes. One for closed threads and one for open threads.
There is also an on/off control via the Admin Panel -> Forums -> More Options.

Copyright:  2009 Adam Clarke. All rights reserved.

Compatability: XMB 1.9.11

Install Note: Before adding this modification to your forum you should back up all files related to this modification.

License Note: This modification is released under the GPL License. A copy is provided with this software.

=======================================================================================================================================
=======
Step 1:
=======

=====================================================================================
Go To Admin Panel -> Insert Raw SQL -> Copy & Paste Code Below & Click Submit CHanges
=====================================================================================

ALTER TABLE `$table_forums` ADD `mt_status` set('on', 'off') DEFAULT 'on' NOT NULL;
ALTER TABLE `$table_forums` ADD `mt_open` text NOT NULL;
ALTER TABLE `$table_forums` ADD `mt_close` text NOT NULL;
UPDATE `$table_forums` SET `mt_open`='In Progress, Pending';
UPDATE `$table_forums` SET `mt_close`='Resolved';

=======================================================================================================================================
=======
Step 2:
=======

=====================
Edit File: header.php
=====================

==========
Find Code:
==========

/* Set Up HTML Templates and Themes */

===============
Add Code Below:
===============

// Forum Based Mark Threads Mod Begin
// Assert Mark Threads Translation
if (!isset($lang['markthreadstatus'])) {
    require_once(ROOT.'include/translation.inc.php');
    $phrases = array();
    $phrases['markthreadstatus'] = "Mark Thread Status:";
    $phrases['markthreadopen'] = "Mark Thread Open Prefixes (Seperate with commas):";
    $phrases['markthreadclose'] = "Mark Thread Closed Prefixes (Seperate with commas):";
    $phrases['markthread'] = "Mark Thread";
    $phrases['markthreadmsg'] = "Mark Thread:";
    $phrases['markthreadsuccess'] = "This thread was marked successfully. You will now be redirected back to the thread.";
    $phrases['markthreadssuccess'] = "The selected threads were marked successfully. You will now be redirected back to the forum.";
    setManyLangValues($phrases, $langfile);
    loadLang($langfile);
}
// Forum Based Mark Threads Mod End

=======================================================================================================================================
=======
Step 3:
=======

=============
Edit File: cp.php
=============

==========
Find Code:
==========

        if ($forum['attachstatus'] == "on") {
            $checked6 = $cheHTML;
        } else {
            $checked6 = '';
        }

===============
Add Code Below:
===============

        // Forum Based Mark Threads Mod Begin
        $markthreads_on = $markthreads_off = '';
        if ($forum['mt_status'] == 'on') {
            $markthreads_on = $selHTML;
        } else {
            $markthreads_off = $selHTML;
        }
        // Forum Based Mark Threads Mod End

==========
Find Code:
==========

        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['texttheme']?></td>
        <td bgcolor="<?php echo $altbg2?>"><?php echo $themelist?></td>
        </tr>

===============
Add Code Below:
===============

        <!-- Forum Based Mark Threads Mod Begin -->
        <?php
        printsetting1($lang['markthreadstatus'], 'mt_statusnew', $markthreads_on, $markthreads_off);
        printsetting4($lang['markthreadopen'], 'mt_opennew', $forum['mt_open'], 4, 30);
        printsetting4($lang['markthreadclose'], 'mt_closenew', $forum['mt_close'], 4, 30);
        ?>
        <!-- Forum Based Mark Threads Mod End -->

==========
Find Code:
==========

        if ($newfname != $lang['textnewforum'] And $newfname != '') {
            $db->query("INSERT INTO ".X_PREFIX."forums (type, name, status, lastpost, moderator, displayorder, description, allowhtml, allowsmilies, allowbbcode, userlist, theme, posts, threads, fup, postperm, allowimgcode, attachstatus, password, mt_status, mt_open, mt_close) VALUES ('forum', '$newfname', '$newfstatus', '', '', $newforder, '', 'no', 'yes', 'yes', '', 0, 0, 0, $newffup, '31,31,31,63', 'yes', 'on', '', 'off', '', '')");
        }

========================
Find Code In Above Statement:
========================

) VALUES ('forum',

================
Replace Code With:
================

, mt_status, mt_open, mt_close) VALUES ('forum',

=============================
Find Code At End Of Above Statement:
=============================

)");

================
Replace Code With:
================

, 'off', '', '')");

==========
Find Code:
==========

        if ($newgname != $lang['textnewgroup'] And $newgname != '') {
            $db->query("INSERT INTO ".X_PREFIX."forums (type, name, status, lastpost, moderator, displayorder, description, allowhtml, allowsmilies, allowbbcode, userlist, theme, posts, threads, fup, postperm, allowimgcode, attachstatus, password) VALUES ('group', '$newgname', '$newgstatus', '', '', $newgorder, '', '', '', '', '', 0, 0, 0, 0, '', '', '', '')");
        }

========================
Find Code In Above Statement:
========================

) VALUES ('group',

================
Replace Code With:
================

, mt_status, mt_open, mt_close) VALUES ('group',

=============================
Find Code At End Of Above Statement:
=============================

)");

================
Replace Code With:
================

, 'off', '', '')");

==========
Find Code:
==========

        if ($newsubname != $lang['textnewsubf'] And $newsubname != '') {
            $db->query("INSERT INTO ".X_PREFIX."forums (type, name, status, lastpost, moderator, displayorder, description, allowhtml, allowsmilies, allowbbcode, userlist, theme, posts, threads, fup, postperm, allowimgcode, attachstatus, password) VALUES ('sub', '$newsubname', '$newsubstatus', '', '', $newsuborder, '', 'no', 'yes', 'yes', '', 0, 0, 0, $newsubfup, '31,31,31,63', 'yes', 'on', '')");
        }

========================
Find Code In Above Statement:
========================

) VALUES ('sub',

================
Replace Code With:
================

, mt_status, mt_open, mt_close) VALUES ('sub',

=============================
Find Code At End Of Above Statement:
=============================

)");

================
Replace Code With:
================

, 'off', '', '')");

==========
Find Code:
==========

        $delete = formInt('delete');

===============
Add Code Below:
===============

        // Forum Based Mark Threads Mod Begin
        $mt_statusnew = formOnOff('mt_statusnew');
        $mt_opennew = postedVar('mt_opennew', 'javascript');
        $mt_closenew = postedVar('mt_closenew', 'javascript');
        // Forum Based Mark Threads Mod End

==========
Find Code:
==========

        $db->query("UPDATE ".X_PREFIX."forums SET

===============
Add Code Below:
===============

            mt_status='$mt_statusnew',
            mt_open='$mt_opennew',
            mt_close='$mt_closenew',

=======================================================================================================================================
=======
Step 4:
=======

====================
Edit File: forumdisplay.php
====================

==========
Find Code:
==========

    eval('$forumdisplay = "'.template('forumdisplay_admin').'";');

===============
Add Code Above:
===============

    // Forum Based Mark Threads Mod Begin
    $mt_option = '';
    if ($forum['mt_status'] == 'on') {
        $mt_option = '<option value="markthread">'.$lang['markthread'].'</option>';
    }
    // Forum Based Mark Threads Mod End

=======================================================================================================================================
=======
Step 5:
=======

=========================
Edit File: topicadmin.php
=========================

==========
Find Code:
==========

loadtemplates(

===============
Add Code Below:
===============

'topicadmin_markthread',

==========
Find Code:
==========

    case 'empty':
        nav($lang['textemptythread']);
        break;

===============
Add Code Below:
===============

    // Forum Based Mark Threads Mod Begin
    case 'markthread':
        nav($lang['markthread']);
        if ($forums['mt_status'] != 'on') {
            $kill = TRUE;
        }
        break;
    // Forum Based Mark Threads Mod End

==========
Find Code:
==========

}

end_time();
eval('echo "'.template('footer').'";');

===============
Add Code Above:
===============

    // Forum Based Mark Threads Mod Begin
    case 'markthread':
        $openprefixes = array_map('trim', explode(',', $forums['mt_open']));
        $closeprefixes = array_map('trim', explode(',', $forums['mt_close']));
        $prefixes = array_merge($openprefixes, $closeprefixes);
        natcasesort($prefixes);

        if (noSubmit('markthreadsubmit')) {
            $markthread_select = array();
            $markthread_select[] = '<select name="newmarkthread">';
            $markthread_select[] = '<option value="none">'.$lang['textnone'].'</option>';
            foreach($prefixes as $prefix) {
                $prefix = trim($prefix);
                if (isset($tid) && !is_array($tid) && false === strstr($tid, ',')) {
                    if (strpos($thread['subject'], '['.$prefix.']') !== false) {
                        $markthread_select[] = '<option value="'.$prefix.'" '.$selHTML.'>'.$prefix.'</option>';
                    } else {
                        $markthread_select[] = '<option value="'.$prefix.'">'.$prefix.'</option>';
                    }
                } else {
                    $markthread_select[] = '<option value="'.$prefix.'">'.$prefix.'</option>';
                }
            }
            $markthread_select[] = '</select>';
            $markthread_select = implode("\n", $markthread_select);
            $tid = implode(',', $tids);
            eval('echo stripslashes("'.template('topicadmin_markthread').'");');
        } else {
            $tid = implode(',', $tids);
            foreach($tids AS $temptid) {
                $query = $db->query("SELECT pid, subject FROM ".X_PREFIX."posts WHERE tid='$temptid' ORDER BY dateline LIMIT 0, 1");
                $post = $db->fetch_array($query);
                $db->free_result($query);

                $post['subject'] = stripslashes($post['subject']);
                foreach($prefixes as $prefix) {
                    $prefix = trim($prefix);
                    $post['subject'] = str_replace('['.$prefix.']', '', $post['subject']);
                }
                $closed = in_array($newmarkthread, $closeprefixes) ? 'yes' : '';
                $post['subject'] = addslashes(($newmarkthread == 'none' ? '' : '['.$newmarkthread.'] ').trim($post['subject']));
                $db->query("UPDATE ".X_PREFIX."posts SET subject='$post[subject]' WHERE pid='$post[pid]'");
                $db->query("UPDATE ".X_PREFIX."threads SET closed='$closed', subject='$post[subject]' WHERE tid='$temptid'");
                audit($xmbuser, $action, $fid, $temptid);
            }

            if (isset($tid) && !is_array($tid) && false === strstr($tid, ',')) {
                message($lang['markthreadsuccess'], false, '', '', $full_url.'viewthread.php?tid='.$tid, true, false, true);
            } else {
                message($lang['markthreadssuccess'], false, '', '', $full_url.'forumdisplay.php?fid='.$fid, true, false, true);
            }
        }
        break;
    // Forum Based Mark Threads Mod End

=======================================================================================================================================
=======
Step 6:
=======

===================
Edit File: viewthread.php
===================

==========
Find Code:
==========

    $modoptions = '';
    if ('Moderator' == $status1) {
        eval('$modoptions = "'.template('viewthread_modoptions').'";');
    }

================
Replace Code With:
================

    $modoptions = '';
    if ('Moderator' == $status1) {
        // Forum Based Mark Threads Mod Begin
        $mt_option = '';
        if ($forum['mt_status'] == 'on') {
            $mt_option = '<option value="markthread">'.$lang['markthread'].'</option>';
        }
        // Forum Based Mark Threads Mod End
        eval('$modoptions = "'.template('viewthread_modoptions').'";');
    }

=======================================================================================================================================
=======
Step 7:
=======

==========================
Edit Template: forumdisplay_admin
==========================

==========
Find Code:
==========

<option value="" selected="selected"></option>

===============
Add Code Below:
===============

$mt_option

=======================================================================================================================================
=======
Step 8:
=======

=============================
Edit Template: viewthread_modoptions
=============================

==========
Find Code:
==========

<option value="" selected="selected"></option>

===============
Add Code Below:
===============

$mt_option

=======================================================================================================================================
=======
Step 9:
=======

==============================
Create Template: topicadmin_markthread
==============================

<form method="POST" action="topicadmin.php?action=markthread">
<table cellspacing="0" cellpadding="0" border="0" width="$tablewidth" align="center">
<tr>
<td bgcolor="$bordercolor">
<table border="0" cellspacing="{$THEME['borderwidth']}" cellpadding="$tablespace" width="100%">
<tr>
<td class ="category" colspan="2"><font color="$THEME[cattext]"><strong>$lang[markthread]</strong></font></td>
</tr>
<tr class="tablerow">
<td bgcolor="$altbg1" width="22%">$lang[loggedinuser]</td>
<td bgcolor="$altbg2">$xmbuser $lang[textminilogout]</td>
</tr>
<tr class="tablerow">
<td bgcolor="$altbg1" width="14%">$lang[markthreadmsg]</td>
<td bgcolor="$altbg2">$markthread_select</td>
</tr>
<tr class="ctrtablerow">
<td bgcolor="$altbg2" colspan="2">
<input type="hidden" name="fid" value="$fid" />
<input type="hidden" name="tid" value="$tid" />
<input type="submit" class="submit" name="markthreadsubmit" value="$lang[markthread]" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>

=======================================================================================================================================