=======================================================================================================================================
Mod Title: U2U Attachments

Mod Version: 1.0

Mod Author: John Briggs

Mod Contributor: GuldantheWarlock

Mod Description:
This mod provides the ability to send attachments through the U2U system.
This mod provides an on/off control that limits members from using it but not staff.

Mod Copyright:  2008 XMBMods.com. All rights reserved.

Mod Compatibility: XMB 1.9.8 Engage Final SP2

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

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

Mod Author Note:
This modification is developed and released for use with XMB 1.9.8 Engage Final SP2 which is provided by XMBMods.com.

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

===================================
Go To Admin Panel -> Insert Raw SQL
===================================

CREATE TABLE `$table_u2u_attachments` (
    `aid` int(10) NOT NULL auto_increment,
    `u2uid` int(10) NOT NULL default '0',
    `filename` varchar(120) NOT NULL default '',
    `filetype` varchar(120) NOT NULL default '',
    `filesize` varchar(120) NOT NULL default '',
    `attachment` longblob NOT NULL,
    `owner` varchar(32) NOT NULL default '',
    PRIMARY KEY (`aid`),
    KEY `u2uid` (`u2uid`),
    KEY `owner` (`owner`(8)),
    KEY `filesize` (`filesize`(8)),
    KEY `filename` (`filename`(8))
) TYPE=MyISAM;

ALTER TABLE `$table_settings` ADD `u2uattachstatus` set('on','off') NOT NULL default 'on';

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

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

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

        $onlinetoday_statuson = $onlinetoday_statusoff = '';
        settingHTML('onlinetoday_status', $onlinetoday_statuson, $onlinetoday_statusoff);

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

        $u2uattachstatuson = $u2uattachstatusoff = '';
        settingHTML('u2uattachstatus', $u2uattachstatuson, $u2uattachstatusoff);

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

        printsetting1($lang['attachimginpost'], 'attachimgpostnew', $attachimgposton, $attachimgpostoff);

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

        printsetting1($lang['u2uattachstatus'], 'u2uattachstatusnew', $u2uattachstatuson, $u2uattachstatusoff);

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

        $onlinetoday_statusnew = formOnOff('onlinetoday_statusnew');

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

        $u2uattachstatusnew = formOnOff('u2uattachstatusnew');

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

            langfile='$langfilenew',

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

            u2uattachstatus='$u2uattachstatusnew',

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

================================
Edit File: lang/English.lang.php
================================

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

?>

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

$lang['u2uattachstatus'] = "U2U Attachments:";
$lang['u2uattachmentno'] = "Sorry, U2U attachments have been disabled by the board administrator.";

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

====================
EditFile: header.php
====================

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

    'u2u',

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

    'u2u_attachments',

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

==================
Edit File: u2u.php
==================

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

'u2u_header',

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

'u2u_header',
'u2u_attachment',
'u2u_attachmentbox',

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

$sendmode = (isset($action) && $action == 'send') ? "true" : "false";

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

if ($action == 'attachment' && isset($_GET['u2uid'])) {
    $u2uid = (int) $_GET['u2uid'];
    if ($SETTINGS['u2uattachstatus'] != 'off' || X_STAFF) {
        $sql = $db->query("SELECT * FROM ".X_PREFIX."u2u_attachments WHERE u2uid='$u2uid'");
        $file = $db->fetch_array($sql);
        $db->free_result($sql);

        if ($file['filesize'] != strlen($file['attachment'])) {
            error($lang['filecorrupt']);
        }

        $type = strtolower($file['filetype']);
        $name = str_replace(' ', '_', $file['filename']);
        $size = (int) $file['filesize'];
        $type = ($type == 'text/html') ? 'text/plain' : $type;

        header("Content-type: $type");
        header("Content-length: $size");
        header("Content-Disposition: attachment; filename=$name");
        header("Content-Description: Attachment");
        header("Cache-Control: public; max-age=604800");
        header("Expires: 604800");

        echo $file['attachment'];
        exit();
    } else {
        error($lang['u2uattachmentnodl']);
    }
}

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

==============================
Edit File: include/u2u.inc.php
==============================

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

    global $forward, $reply, $sendsubmit, $savesubmit, $previewsubmit;

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

    global $forward, $reply, $sendsubmit, $savesubmit, $previewsubmit, $SETTINGS;

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

    eval('$leftpane = "'.template('u2u_send').'";');

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

    $attachfile = '';
    if ($SETTINGS['u2uattachstatus'] == 'on' || X_STAFF) {
        eval('$attachfile = "'.template("u2u_attachmentbox").'";');
    }

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

    global $sendoptions, $u2uheader, $u2ufooter;

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

    global $sendoptions, $u2uheader, $u2ufooter, $SETTINGS;

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

    eval('$leftpane = "'.template('u2u_view').'";');

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

    $attachment = '';
    if ($SETTINGS['u2uattachstatus'] == 'on' || X_STAFF) {
        $u2uid = (int) $u2uid;
        $sql = $db->query("SELECT * FROM ".X_PREFIX."u2u_attachments WHERE u2uid='$u2uid'");
        if ($db->num_rows($sql) != 0) {
            $a = $db->fetch_array($sql);
            $db->free_result($sql);
            $attachsize = (int) $a['filesize'];
            if ($attachsize >= 1073741824) {
                $attachsize = round($attachsize / 1073741824 * 100) / 100 . "gb";
            } else if ($attachsize >= 1048576) {
                $attachsize = round($attachsize / 1048576 * 100) / 100 . "mb";
            } else if ($attachsize >= 1024) {
                $attachsize = round($attachsize / 1024 * 100) / 100 . "kb";
            } else {
                $attachsize = $attachsize . "b";
            }
            eval('$attachment = "'.template("u2u_attachment").'";');
        }
    }

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

function db_u2u_insert($to, $from, $type, $owner, $folder, $subject, $message, $isRead, $isSent) {
    global $db, $onlinetime, $oToken;

    $subject = checkInput(censor(addslashes($subject)));
    $message = checkInput(censor(addslashes($message)));
    $db->query("INSERT INTO ".X_PREFIX."u2u (msgto, msgfrom, type, owner, folder, subject, message, dateline, readstatus, sentstatus) VALUES ('".addslashes($to)."', '".addslashes($from)."', '$type', '".addslashes($owner)."', '$folder', '$subject', '$message', '$onlinetime', '$isRead', '$isSent')");
}

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

function db_u2u_insert($to, $from, $type, $owner, $folder, $subject, $message, $isRead, $isSent) {
    global $db, $onlinetime, $oToken, $SETTINGS;
    global $filename, $filetype, $filesize;

    $subject = checkInput(censor(addslashes($subject)));
    $message = checkInput(censor(addslashes($message)));

    $db->query("INSERT INTO ".X_PREFIX."u2u (msgto, msgfrom, type, owner, folder, subject, message, dateline, readstatus, sentstatus) VALUES ('".addslashes($to)."', '".addslashes($from)."', '$type', '".addslashes($owner)."', '$folder', '$subject', '$message', '$onlinetime', '$isRead', '$isSent')");
    $u2uid = $db->insert_id();

    if (isset($_FILES['attach']) && ($attachment = get_attached_file($_FILES['attach'], $SETTINGS['u2uattachstatus'])) !== false) {
        $db->query("INSERT INTO ".X_PREFIX."u2u_attachments (aid, u2uid, filename, filetype, filesize, attachment, owner) VALUES ('', '$u2uid', '$filename', '$filetype', '$filesize', '$attachment', '".addslashes($owner)."')");
    }
}

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

    if ($folder == "Trash") {
        $db->query("DELETE FROM ".X_PREFIX."u2u WHERE u2uid='$u2uid' AND owner='$self[username]'");
    } else {
        $db->query("UPDATE ".X_PREFIX."u2u SET folder='Trash' WHERE u2uid='$u2uid' AND owner='$self[username]'");
    }

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

    if ($folder == "Trash") {
        $db->query("DELETE FROM ".X_PREFIX."u2u WHERE u2uid='$u2uid' AND owner='$self[username]'");
        $db->query("DELETE FROM ".X_PREFIX."u2u_attachments WHERE u2uid='u2uid' AND owner='$self[username]'");
    } else {
        $db->query("UPDATE ".X_PREFIX."u2u SET folder='Trash' WHERE u2uid='$u2uid' AND owner='$self[username]'");
    }

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

    if ($folder == "Trash") {
        $db->query("DELETE FROM ".X_PREFIX."u2u WHERE u2uid IN($in) AND owner='$self[username]'");
    } else {
        $db->query("UPDATE ".X_PREFIX."u2u SET folder='Trash' WHERE u2uid IN($in) AND owner='$self[username]'");
    }

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

    if ($folder == "Trash") {
        $db->query("DELETE FROM ".X_PREFIX."u2u WHERE u2uid IN($in) AND owner='$self[username]'");
        $db->query("DELETE FROM ".X_PREFIX."u2u_attachments WHERE u2uid IN($in) AND owner='$self[username]'");
    } else {
        $db->query("UPDATE ".X_PREFIX."u2u SET folder='Trash' WHERE u2uid IN($in) AND owner='$self[username]'");
    }

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

=======================================
Go to Administration Panel -> Templates
=======================================

===============================
Create Template: u2u_attachment
===============================

==========================
Add Code & Submit Changes:
==========================

<br />
<br />
$lang[attachment] <a href="u2u.php?action=attachment&amp;u2uid=$u2uid" target="_blank">$a[filename]</a> ($attachsize)
<br />

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

=======================================
Go to Administration Panel -> Templates
=======================================

==================================
Create Template: u2u_attachmentbox
==================================

==========================
Add Code & Submit Changes:
==========================

<tr class="tablerow">
<td bgcolor="$altbg1">$lang[attachment]</td>
<td bgcolor="$altbg2"><input type="file" name="attach" size="20" />
<input type="hidden" name="MAX_FILE_SIZE" value="$SETTINGS[maxattachsize]" /></td>
</tr>

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

=======================================
Go to Administration Panel -> Templates
=======================================

=======================
Edit Template: u2u_send
=======================

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

<form method="post" action="u2u.php?action=send">

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

<form method="post" action="u2u.php?action=send" enctype="multipart/form-data">

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

<tr class="tablerow">
<td valign="top" bgcolor="$altbg1">$lang[textmessage]</td>
<td bgcolor="$altbg2"><textarea rows="10" name="message" id="message" cols="50">$message</textarea><br /></td>
</tr>

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

$attachfile

=======================================================================================================================================
=======
Step 10:
=======

=======================================
Go to Administration Panel -> Templates
=======================================

=======================
Edit Template: u2u_view
=======================

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

$u2umessage

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

$u2umessage$attachment

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