Title: U2U Attachments v.1.0

Author: John Briggs, GuldantheWarlock

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.

Copyright:  2006 John Briggs. All rights reserved.
Copyright:  2006 GuladantheWarlock. All rights reserved.

Compatability: XMB 1.9.5 Final

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

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

Author Note:
You downloaded this hack from XMBMods.com, the #1 source for XMB related downloads.
Please visit http://www.xmbmods.com/ for support.

=======================================================================================================================================
=======
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:
==========

        $resetSigOn = $resetSigOff = '';
        if($SETTINGS['resetsigs'] == 'on') {
            $resetSigOn = $selHTML;
        } else {
            $resetSigOff = $selHTML;
        }

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

        $u2uattachstatuson = $u2uattachstatusoff = '';
        switch ($SETTINGS['u2uattachstatus']) {
            case 'on':
                $u2uattachstatuson = $selHTML;
                break;
            default:
                $u2uattachstatusoff = $selHTML;
                break;
        }

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

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

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

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

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

        $resetSigNew = ($resetSigNew == 'on') ? 'on' : 'off';

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

        $u2uattachstatusnew = ($u2uattachstatusnew == 'on') ? 'on' : 'off';

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

        $db->query("UPDATE $table_settings SET

==============================
Add to end of line before ");:
==============================

, u2uattachstatus='$u2uattachstatusnew'

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

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

================================
Add Code At Very Bottom Of File:
================================

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

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

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

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

,'u2u'

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

,'u2u','u2u_attachments'

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

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

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

loadtemplates(

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

loadtemplates('u2u_attachment','u2u_attachmentbox',

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

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

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

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

        if ($file['filesize'] != strlen($file['attachment'])) {
            error('The file you are trying to download appears corrupt.<br /><br />&raquo; File download aborted');
        }

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

        header("Content-type: $type");
        header("Content-length: $size");
        header("Content-Disposition: inline; filename = $name");
        header("Content-Description: PHP Generated Attachments");
        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;

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

    global $forward, $reply, $table_u2u_attachments, $SETTINGS, $max_attach_size;

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

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

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

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

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

    global $table_u2u, $self;

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

    global $table_u2u, $self, $table_u2u_attachments, $SETTINGS;

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

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

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

    $attachment = '';
    if ($SETTINGS['u2uattachstatus'] == 'on' || X_STAFF) {
        $sql = $db->query("SELECT * FROM $table_u2u_attachments WHERE u2uid='$u2uid'");
        if ($db->num_rows($sql) != 0) {
            $a = $db->fetch_array($sql);
            $db->free_result($sql);
            $attachsize = $a['filesize'];
            if ($attachsize >= 1073741824) {
                $attachsize = round($attachsize / 1073741824 * 100) / 100 . "gb";
            } elseif ($attachsize >= 1048576) {
                $attachsize = round($attachsize / 1048576 * 100) / 100 . "mb";
            } elseif ($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, $table_u2u, $onlinetime;

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

    $db->query( "INSERT INTO $table_u2u ( u2uid, 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, $table_u2u, $onlinetime, $table_u2u_attachments, $SETTINGS;
    global $filename, $filetype, $filesize;

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

    $db->query("INSERT INTO $table_u2u (u2uid, 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 $table_u2u_attachments (aid, u2uid, filename, filetype, filesize, attachment, owner) VALUES ('', '$u2uid', '$filename', '$filetype', '$filesize', '$attachment', '".addslashes($owner)."')");
    }
}

======================
Find (On 2 Occasions):
======================

    global $db, $self, $table_u2u, $lang;

=================================
Replace With (On both occasions):
=================================

    global $db, $self, $table_u2u, $table_u2u_attachments, $lang;

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

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

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

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

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

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

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

    if ( $folder == "Trash" ) {
        $db->query( "DELETE FROM $table_u2u WHERE u2uid IN($in) AND owner='$self[username]'" );
        $db->query( "DELETE FROM $table_u2u_attachments WHERE u2uid IN($in) AND owner='$self[username]'" );
    } else {
        $db->query( "UPDATE $table_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 and 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 and 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="$max_attach_size" /></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>
<td valign="top" class="tablerow" bgcolor="$altbg1">$lang[textmessage]</td>
<td class="tablerow" 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

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