Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / proj_doc_update.php
blobc002c1e6d32c359a166c75b71ca256c70c010119
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * @package MantisBT
19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
20 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
21 * @link http://www.mantisbt.org
23 * @uses core.php
24 * @uses access_api.php
25 * @uses config_api.php
26 * @uses constant_inc.php
27 * @uses database_api.php
28 * @uses file_api.php
29 * @uses form_api.php
30 * @uses gpc_api.php
31 * @uses helper_api.php
32 * @uses html_api.php
33 * @uses lang_api.php
34 * @uses print_api.php
35 * @uses utility_api.php
38 require_once( 'core.php' );
39 require_api( 'access_api.php' );
40 require_api( 'config_api.php' );
41 require_api( 'constant_inc.php' );
42 require_api( 'database_api.php' );
43 require_api( 'file_api.php' );
44 require_api( 'form_api.php' );
45 require_api( 'gpc_api.php' );
46 require_api( 'helper_api.php' );
47 require_api( 'html_api.php' );
48 require_api( 'lang_api.php' );
49 require_api( 'print_api.php' );
50 require_api( 'utility_api.php' );
52 form_security_validate( 'proj_doc_update' );
54 # Check if project documentation feature is enabled.
55 if ( OFF == config_get( 'enable_project_documentation' ) ||
56 !file_is_uploading_enabled() ||
57 !file_allow_project_upload() ) {
58 access_denied();
61 $f_file_id = gpc_get_int( 'file_id' );
62 $f_title = gpc_get_string( 'title' );
63 $f_description = gpc_get_string( 'description' );
64 $f_file = gpc_get_file( 'file' );
66 $t_project_id = file_get_field( $f_file_id, 'project_id', 'project' );
68 access_ensure_project_level( config_get( 'upload_project_file_threshold' ), $t_project_id );
70 if ( is_blank( $f_title ) ) {
71 trigger_error( ERROR_EMPTY_FIELD, ERROR );
74 $c_file_id = db_prepare_int( $f_file_id );
75 $c_title = db_prepare_string( $f_title );
76 $c_description = db_prepare_string( $f_description );
78 $t_project_file_table = db_get_table( 'project_file' );
80 /** @todo (thraxisp) this code should probably be integrated into file_api to share methods used to store files */
82 file_ensure_uploaded( $f_file );
84 extract( $f_file, EXTR_PREFIX_ALL, 'v' );
86 if ( is_uploaded_file( $v_tmp_name ) ) {
88 $t_project_id = helper_get_current_project();
90 # grab the original file path and name
91 $t_disk_file_name = file_get_field( $f_file_id, 'diskfile', 'project' );
92 $t_file_path = dirname( $t_disk_file_name );
94 # prepare variables for insertion
95 $c_file_name = db_prepare_string( $v_name );
96 $c_file_type = db_prepare_string( $v_type );
97 $t_file_size = filesize( $v_tmp_name );
98 $t_max_file_size = (int)min( ini_get_number( 'upload_max_filesize' ), ini_get_number( 'post_max_size' ), config_get( 'max_file_size' ) );
99 if ( $t_file_size > $t_max_file_size ) {
100 trigger_error( ERROR_FILE_TOO_BIG, ERROR );
102 $c_file_size = db_prepare_int( $t_file_size );
104 $t_method = config_get( 'file_upload_method' );
105 switch ( $t_method ) {
106 case FTP:
107 case DISK:
108 file_ensure_valid_upload_path( $t_file_path );
110 if ( FTP == $t_method ) {
111 $conn_id = file_ftp_connect();
112 file_ftp_delete ( $conn_id, $t_disk_file_name );
113 file_ftp_put ( $conn_id, $t_disk_file_name, $v_tmp_name );
114 file_ftp_disconnect ( $conn_id );
116 if ( file_exists( $t_disk_file_name ) ) {
117 file_delete_local( $t_disk_file_name );
119 if ( !move_uploaded_file( $v_tmp_name, $t_disk_file_name ) ) {
120 trigger_error( FILE_MOVE_FAILED, ERROR );
122 chmod( $t_disk_file_name, config_get( 'attachments_file_permissions' ) );
124 $c_content = '';
125 break;
126 case DATABASE:
127 $c_content = db_prepare_binary_string( fread ( fopen( $v_tmp_name, 'rb' ), $v_size ) );
128 break;
129 default:
130 /** @todo Such errors should be checked in the admin checks */
131 trigger_error( ERROR_GENERIC, ERROR );
133 $query = "UPDATE $t_project_file_table
134 SET title=" . db_param() . ", description=" . db_param() . ", date_added=" . db_param() . ",
135 filename=" . db_param() . ", filesize=" . db_param() . ", file_type=" .db_param() . ", content=" .db_param() . "
136 WHERE id=" . db_param();
137 $result = db_query_bound( $query, Array( $c_title, $c_description, db_now(), $c_file_name, $c_file_size, $c_file_type, $c_content, $c_file_id ) );
138 } else {
139 $query = "UPDATE $t_project_file_table
140 SET title=" . db_param() . ", description=" . db_param() . "
141 WHERE id=" . db_param();
142 $result = db_query_bound( $query, Array( $c_title, $c_description, $c_file_id ) );
145 if ( !$result ) {
146 trigger_error( ERROR_GENERIC, ERROR );
149 form_security_purge( 'proj_doc_update' );
151 $t_redirect_url = 'proj_doc_page.php';
153 html_page_top( null, $t_redirect_url );
155 <br />
156 <div align="center">
157 <?php
158 echo lang_get( 'operation_successful' ).'<br />';
159 print_bracket_link( $t_redirect_url, lang_get( 'proceed' ) );
161 </div>
163 <?php
164 html_page_bottom();