Blame Extras/Mantis/1.1.2-1.fc9/proj_doc_update.php

4c79b5
4c79b5
# Mantis - a php based bugtracking system
4c79b5
4c79b5
# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
4c79b5
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
4c79b5
4c79b5
# Mantis is free software: you can redistribute it and/or modify
4c79b5
# it under the terms of the GNU General Public License as published by
4c79b5
# the Free Software Foundation, either version 2 of the License, or
4c79b5
# (at your option) any later version.
4c79b5
#
4c79b5
# Mantis is distributed in the hope that it will be useful,
4c79b5
# but WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c79b5
# GNU General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
4c79b5
4c79b5
	#------------------------------
4c79b5
	#   $Revision: 2643 $
4c79b5
	#     $Author: al $    
4c79b5
	#       $Date: 2009-06-18 19:06:27 -0400 (Thu, 18 Jun 2009) $  
4c79b5
	#------------------------------
4c79b5
4c79b5
	require_once( 'core.php' );
4c79b5
4c79b5
	$t_core_path = config_get( 'core_path' );
4c79b5
4c79b5
	require_once( $t_core_path.'file_api.php' );
4c79b5
4c79b5
	# helper_ensure_post();
4c79b5
4c79b5
	# Check if project documentation feature is enabled.
4c79b5
	if ( OFF == config_get( 'enable_project_documentation' ) ||
4c79b5
		!file_is_uploading_enabled() ||
4c79b5
		!file_allow_project_upload() ) {
4c79b5
		access_denied();
4c79b5
	}
4c79b5
4c79b5
	$f_file_id = gpc_get_int( 'file_id' );
4c79b5
	$f_title = gpc_get_string( 'title' );
4c79b5
	$f_description	= gpc_get_string( 'description' );
4c79b5
	$f_file = gpc_get_file( 'file' );
4c79b5
4c79b5
	$t_project_id = file_get_field( $f_file_id, 'project_id', 'project' );
4c79b5
4c79b5
	access_ensure_project_level( config_get( 'upload_project_file_threshold' ), $t_project_id );
4c79b5
4c79b5
	if ( is_blank( $f_title ) ) {
4c79b5
		trigger_error( ERROR_EMPTY_FIELD, ERROR );
4c79b5
	}
4c79b5
4c79b5
	$c_file_id = db_prepare_int( $f_file_id );
4c79b5
	$c_title = db_prepare_string( $f_title );
4c79b5
	$c_description = db_prepare_string( $f_description );
4c79b5
4c79b5
	$t_project_file_table = config_get( 'mantis_project_file_table' );
4c79b5
4c79b5
	#@@@ (thraxisp) this code should probably be integrated into file_api to share
4c79b5
	#  methods used to store files
4c79b5
4c79b5
	extract( $f_file, EXTR_PREFIX_ALL, 'v' );
4c79b5
4c79b5
	if ( is_uploaded_file( $v_tmp_name ) ) {
4c79b5
		if ( php_version_at_least( '4.2.0' ) ) {
4c79b5
		    switch ( (int) $v_error ) {
4c79b5
		        case UPLOAD_ERR_INI_SIZE:
4c79b5
		        case UPLOAD_ERR_FORM_SIZE:
4c79b5
                    trigger_error( ERROR_FILE_TOO_BIG, ERROR );
4c79b5
                    break;
4c79b5
		        case UPLOAD_ERR_PARTIAL:
4c79b5
		        case UPLOAD_ERR_NO_FILE:
4c79b5
                    trigger_error( ERROR_FILE_NO_UPLOAD_FAILURE, ERROR );
4c79b5
                    break;
4c79b5
                default:
4c79b5
                    break;
4c79b5
            }
4c79b5
        }
4c79b5
        
4c79b5
	    if ( ( '' == $v_tmp_name ) || ( '' == $v_name ) ) {
4c79b5
		    trigger_error( ERROR_FILE_NO_UPLOAD_FAILURE, ERROR );
4c79b5
        }
4c79b5
		if ( !file_type_check( $v_name ) ) {
4c79b5
			trigger_error( ERROR_FILE_NOT_ALLOWED, ERROR );
4c79b5
		}
4c79b5
4c79b5
		if ( !is_readable( $v_tmp_name ) ) {
4c79b5
			trigger_error( ERROR_UPLOAD_FAILURE, ERROR );
4c79b5
		}
4c79b5
4c79b5
		$t_project_id = helper_get_current_project();
4c79b5
4c79b5
		# grab the original file path and name
4c79b5
		$t_disk_file_name = file_get_field( $f_file_id, 'diskfile', 'project' );
4c79b5
		$t_file_path = dirname( $t_disk_file_name );
4c79b5
4c79b5
		# prepare variables for insertion
4c79b5
		$c_file_name = db_prepare_string( $v_name );
4c79b5
		$c_file_type = db_prepare_string( $v_type );
4c79b5
		$t_file_size = filesize( $v_tmp_name );
4c79b5
		$t_max_file_size = (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
4c79b5
        if ( $t_file_size > $t_max_file_size ) {
4c79b5
            trigger_error( ERROR_FILE_TOO_BIG, ERROR );
4c79b5
        }
4c79b5
		$c_file_size = db_prepare_int( $t_file_size );
4c79b5
4c79b5
		$t_method = config_get( 'file_upload_method' );
4c79b5
		switch ( $t_method ) {
4c79b5
			case FTP:
4c79b5
			case DISK:
4c79b5
				file_ensure_valid_upload_path( $t_file_path );
4c79b5
4c79b5
				if ( FTP == $t_method ) {
4c79b5
					$conn_id = file_ftp_connect();
4c79b5
					file_ftp_delete ( $conn_id, $t_disk_file_name );
4c79b5
					file_ftp_put ( $conn_id, $t_disk_file_name, $v_tmp_name );
4c79b5
					file_ftp_disconnect ( $conn_id );
4c79b5
				}
4c79b5
				if ( file_exists( $t_disk_file_name ) ) {
4c79b5
					file_delete_local( $t_disk_file_name );
4c79b5
				}
4c79b5
				if ( !move_uploaded_file( $v_tmp_name, $t_disk_file_name ) ) {
4c79b5
					trigger_error( FILE_MOVE_FAILED, ERROR );
4c79b5
				}
4c79b5
				chmod( $t_disk_file_name, config_get( 'attachments_file_permissions' ) );
4c79b5
4c79b5
				$c_content = '';
4c79b5
				break;
4c79b5
			case DATABASE:
4c79b5
				$c_content = db_prepare_string( fread ( fopen( $v_tmp_name, 'rb' ), $v_size ) );
4c79b5
				break;
4c79b5
			default:
4c79b5
				# @@@ Such errors should be checked in the admin checks
4c79b5
				trigger_error( ERROR_GENERIC, ERROR );
4c79b5
		}
4c79b5
		$t_now = db_now();
4c79b5
		$query = "UPDATE $t_project_file_table
4c79b5
			SET title='$c_title', description='$c_description', date_added=$t_now,
4c79b5
				filename='$c_file_name', filesize=$c_file_size, file_type='$c_file_type', content='$c_content'
4c79b5
				WHERE id='$c_file_id'";
4c79b5
	} else {
4c79b5
		$query = "UPDATE $t_project_file_table
4c79b5
				SET title='$c_title', description='$c_description'
4c79b5
				WHERE id='$c_file_id'";
4c79b5
	}
4c79b5
4c79b5
	$result = db_query( $query );
4c79b5
	if ( !$result ) {
4c79b5
		trigger_error( ERROR_GENERIC, ERROR  );
4c79b5
	}
4c79b5
4c79b5
	$t_redirect_url = 'proj_doc_page.php';
4c79b5
4c79b5
	html_page_top1();
4c79b5
	html_meta_redirect( $t_redirect_url );
4c79b5
	html_page_top2();
4c79b5
?>
4c79b5
4c79b5
4c79b5
4c79b5
	echo '

' . lang_get( 'operation_successful' ).'

';
4c79b5
	print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
4c79b5
?>
4c79b5
4c79b5
4c79b5