/** * Returns the attachment contents * * @param integer $p_file_id File identifier. * @param string $p_type The file type, bug or doc. * @param integer $p_user_id A valid user identifier. * @return string|soap_fault the string contents, or a soap_fault */ function mci_file_get($p_file_id, $p_type, $p_user_id) { # we handle the case where the file is attached to a bug # or attached to a project as a project doc. $t_query = ''; switch ($p_type) { case 'bug': $t_query = 'SELECT * FROM {bug_file} WHERE id=' . db_param(); break; case 'doc': $t_query = 'SELECT * FROM {project_file} WHERE id=' . db_param(); break; default: return SoapObjectsFactory::newSoapFault('Server', 'Invalid file type ' . $p_type . ' .'); } $t_result = db_query($t_query, array($p_file_id)); if ($t_result->EOF) { return SoapObjectsFactory::newSoapFault('Client', 'Unable to find an attachment with type ' . $p_type . ' and id ' . $p_file_id . ' .'); } $t_row = db_fetch_array($t_result); if ($p_type == 'doc') { $t_project_id = $t_row['project_id']; } else { if ($p_type == 'bug') { $t_bug_id = $t_row['bug_id']; $t_project_id = bug_get_field($t_bug_id, 'project_id'); } } $t_diskfile = file_normalize_attachment_path($t_row['diskfile'], $t_project_id); $t_content = $t_row['content']; # Check access rights switch ($p_type) { case 'bug': if (!mci_file_can_download_bug_attachments($t_bug_id, $p_user_id)) { return mci_soap_fault_access_denied($p_user_id); } break; case 'doc': # Check if project documentation feature is enabled. if (OFF == config_get('enable_project_documentation')) { return mci_soap_fault_access_denied($p_user_id); } if (!access_has_project_level(config_get('view_proj_doc_threshold'), $t_project_id, $p_user_id)) { return mci_soap_fault_access_denied($p_user_id); } break; } # dump file content to the connection. switch (config_get('file_upload_method')) { case DISK: if (file_exists($t_diskfile)) { return mci_file_read_local($t_diskfile); } else { return SoapObjectsFactory::newSoapFault('Client', 'Unable to find an attachment with type ' . $p_type . ' and id ' . $p_file_id . ' .'); } case DATABASE: return $t_content; default: trigger_error(ERROR_GENERIC, ERROR); } }
/** * Returns the attachment contents * * @param int $p_file_id * @param string $p_type The file type, bug or doc * @param int $p_user_id * @return string|soap_fault the string contents, or a soap_fault */ function mci_file_get($p_file_id, $p_type, $p_user_id) { # we handle the case where the file is attached to a bug # or attached to a project as a project doc. $query = ''; switch ($p_type) { case 'bug': $t_bug_file_table = db_get_table('bug_file'); $query = "SELECT *\n\t\t\t\tFROM {$t_bug_file_table}\n\t\t\t\tWHERE id='{$p_file_id}'"; break; case 'doc': $t_project_file_table = db_get_table('project_file'); $query = "SELECT *\n\t\t\t\tFROM {$t_project_file_table}\n\t\t\t\tWHERE id='{$p_file_id}'"; break; default: return new soap_fault('Server', '', 'Invalid file type ' . $p_type . ' .'); } $result = db_query($query); if ($result->EOF) { return new soap_fault('Client', '', 'Unable to find an attachment with type ' . $p_type . ' and id ' . $p_file_id . ' .'); } $row = db_fetch_array($result); if ($p_type == 'doc') { $t_project_id = $row['project_id']; } else { if ($p_type == 'bug') { $t_bug_id = $row['bug_id']; $t_project_id = bug_get_field($t_bug_id, 'project_id'); } } $t_diskfile = file_normalize_attachment_path($row['diskfile'], $t_project_id); $t_content = $row['content']; # Check access rights switch ($p_type) { case 'bug': if (!mci_file_can_download_bug_attachments($t_bug_id, $p_user_id)) { return mci_soap_fault_access_denied($p_user_id); } break; case 'doc': # Check if project documentation feature is enabled. if (OFF == config_get('enable_project_documentation')) { return mci_soap_fault_access_denied($p_user_id); } if (!access_has_project_level(config_get('view_proj_doc_threshold'), $t_project_id, $p_user_id)) { return mci_soap_fault_access_denied($p_user_id); } break; } # dump file content to the connection. switch (config_get('file_upload_method')) { case DISK: if (file_exists($t_diskfile)) { return mci_file_read_local($t_diskfile); } else { return new soap_fault('Client', '', 'Unable to find an attachment with type ' . $p_type . ' and id ' . $p_file_id . ' .'); } case FTP: if (file_exists($t_diskfile)) { return mci_file_read_local($t_diskfile); } else { $ftp = file_ftp_connect(); file_ftp_get($ftp, $t_diskfile, $t_diskfile); file_ftp_disconnect($ftp); return mci_file_read_local($t_diskfile); } default: return $t_content; } }
function mci_file_get($p_file_id, $p_type, $p_user_id) { # we handle the case where the file is attached to a bug # or attached to a project as a project doc. $query = ''; switch ($p_type) { case 'bug': $t_bug_file_table = config_get('mantis_bug_file_table'); $query = "SELECT *\r\n\t\t\t\t\tFROM {$t_bug_file_table}\r\n\t\t\t\t\tWHERE id='{$p_file_id}'"; break; case 'doc': $t_project_file_table = config_get('mantis_project_file_table'); $query = "SELECT *\r\n\t\t\t\t\tFROM {$t_project_file_table}\r\n\t\t\t\t\tWHERE id='{$p_file_id}'"; break; default: return new soap_fault('Client', '', 'Access Denied'); } $result = db_query($query); $row = db_fetch_array($result); extract($row, EXTR_PREFIX_ALL, 'v'); # Check access rights switch ($p_type) { case 'bug': if (!mci_file_can_download_bug_attachments($v_bug_id, $p_user_id)) { return new soap_fault('Client', '', 'Access Denied'); } break; case 'doc': # Check if project documentation feature is enabled. if (OFF == config_get('enable_project_documentation')) { return new soap_fault('Client', '', 'Access Denied'); } if (!access_has_project_level(config_get('view_proj_doc_threshold'), $v_project_id, $p_user_id)) { return new soap_fault('Client', '', 'Access Denied'); } break; } # dump file content to the connection. switch (config_get('file_upload_method')) { case DISK: if (file_exists($v_diskfile)) { return base64_encode(mci_file_read_local($v_diskfile)); } else { return null; } case FTP: if (file_exists($v_diskfile)) { return base64_encode(mci_file_read_local($v_diskfile)); } else { $ftp = file_ftp_connect(); file_ftp_get($ftp, $v_diskfile, $v_diskfile); file_ftp_disconnect($ftp); return base64_encode(mci_file_read_local($v_diskfile)); } default: return base64_encode($v_content); } }