<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: mail_attach.php,v 1.6.2.4 2004/08/15 12:57:27 kirilt Exp $

if ( ! _MPN_USER )
{
    exit( translate( 'You Are Not Logged In' ) );
}

$tmp = cookiedecode();
$uid = $tmp[0];
unset( $tmp );

require './emailconfig.php';

$upload_param = array
(
      'subclass' => array(  'file' => NULL
                          , 'name' => NULL
                         )

    , 'upinit' => array
        (
              'input_field_name' => 'ufile'

            , 'maxsize'          => 100000

            , 'mime_types'       => array
              (
                  'image' => array
                    (
                       'subtypes'    => array(  'jpeg'
                                              , 'pjpeg'
                                              , 'gif'
                                             )

                     , 'extensions'  => array(  'allow'    => array(  'jpg'
                                                                    , 'gif'
                                                                   )
                                             )

                     , 'dimensions'  => array(  'width'  => 800
                                              , 'height' => 600
                                             )

                     , 'destination' => array(  'db'     => FALSE
                                              , 'path'   => '/uploads/mail/'
                                              , 'opt_id' => ''
                                              , 'track'  => FALSE
                                             )
                    )

               , 'text'  => array
                    (
                       'subtypes'    => array(  'html'
                                              , 'txt'
                                              , 'plain'
                                             )

                     , 'extensions'  => array(  'allow'    => array(  'htm'
                                                                    , 'html'
                                                                    , 'txt'
                                                                   )

                                              , 'save_as'  => 'txt'
                                             )

                     , 'destination' => array(  'db'     => FALSE
                                              , 'path'   => '/uploads/mail/'
                                              , 'opt_id' => ''
                                              , 'track'  => FALSE
                                             )
                    )
              )
        )

    , 'upproc' => array
        (
           'filename_adj'  => array( 'prepend' => $uid, 'append' => 'mime' )
         , 'check_dimen'   => TRUE
         , 'attempt_chmod' => TRUE
        )
);

$title = translate( 'Attach files to your email' );

echo $_SERVER['F_LIB'] -> generateSAHeader( 'uploads', 'mpn_uploads.css', 'all', $title );

// Process The Upload Or Show The Upload Form

if ( isset( $_POST['upload'] ) )
{
    require_once './classes/core_Uploads.class.php';

    $upload = new MPN_Upload( $upload_param['upinit'] );

    $upload_result = $upload -> do_upload( $upload_param['upproc'] );

    $ret_link = "<br /><br /><b>&#091;&#160;<a href=\"javascript:history.go(-1)\">" . translate( 'Go Back' ) . "</a>&#160;&#093;</b>\n";

    if ( empty( $upload_result ) )
    {
         $msg  = translate( 'You Must Provide At Least One File To Upload' );
         $msg .= $ret_link;

         exit( $msg );
    }
    else if ( isset( $upload_result['status'] ) )
    {
         $msg  = $upload_result['message'];
         $msg .= $ret_link;

         exit( $msg );
    }
    else
    {
        foreach( $upload_result AS $user_file )
        {
            if ( (bool)FALSE === strpos( $user_file, '_image' ) )
            {
                $filename = $user_file;

                $content = $_SERVER['F_LIB'] -> getFileContent( $filename, 1 );

                $content = $_SERVER['SAN'] -> sanitize( $content );

                $_SERVER['F_LIB'] -> writeFile( $filename, 'wb', $content, _DP_MAIL_ATTACH );
            }
        }

        echo "<p>\n";

            echo translate( 'All Files Uploaded Successfully' );

            echo "<br /><br />\n";

            echo "<a class='subtitle1' href=\"javascript: window.close();\" onClick=\"opener.location.reload(); opener.focus();\" title='Close Window'>Close Window</a>\n";

        echo "</p>\n";
    }
}
else
{
    $num_fields = ( isset( $_REQUEST['fldnum'] ) && is_numeric( $_REQUEST['fldnum'] ) ) ? ( $_REQUEST['fldnum'] ) : ( 0 );

    $field_count = ( isset( $_REQUEST['fldcnt'] ) ) ? ( $_REQUEST['fldcnt'] ) : ( 1 );

    if ( $field_count > 5 )
    {
        $total_fields = 5;
    }
    else
    {
        $total_fields = $field_count + $num_fields;
    }

    echo "<h3>" . translate( 'Upload Your File' ) . "</h1>\n";

    echo "<form name='upfiles' action='{$_SERVER['REQUEST_URI']}' method='post' enctype='multipart/form-data'>\n";

        echo "<input type='hidden' name='fldcnt' value='$total_fields' />\n";
        echo "<input type='hidden' name='max_file_size' value='{$upload_param['upinit']['maxsize']}'>\n";

        echo "<hr class='w80' />\n";

        echo "<label>" . translate( 'Add' ) . "&nbsp;</label>\n";

        echo "<input type='text' name='fldnum' value='1' size='3' />\n";

        echo "<label>&nbsp;" . translate( 'Field(s)' ) . "</label>\n";

        echo '<input type="submit" class="button" name="upld_update" value="' . translate( 'Update Form' ) . '" />' . "\n";

        echo "<br /><hr class='w80' />\n";

        echo "<br /><br />\n";

        for ( $i = 1; $i <= $total_fields; $i++ )
        {
            echo "<label>" . translate( 'File' ) . "&nbsp;$i&nbsp;:</label>\n";

            echo "<input class='button' type='file' name='ufile[]' />\n";

            echo "<br />\n";
        }

        echo "<br /><br />\n";

        echo "<input type='hidden' name='stripit_form' value='fldnum' />\n";
        echo "<input type='hidden' name='mpn_sectype' value='1' />\n";

        echo "<input type='submit' class='button' name='upload' value='" . translate( 'Upload Files' ) . "' />\n";

    echo "</form>\n";

} // End if/then

echo "<br /><br />\n";

echo "</body>\n";

echo "</html>\n";

?>
