/**
 * Add an attachment to an existing issue.
 *
 * @param string $p_username  The name of the user trying to add an attachment to an issue.
 * @param string $p_password  The password of the user.
 * @param integer $p_issue_id  The id of the issue to add the attachment to.
 * @param string $p_name  The name of the file.
 * @param string $p_file_type The mime type of the file.
 * @param base64Binary $p_content  The attachment to add.
 * @return integer The id of the added attachment.
 */
function mc_issue_attachment_add( $p_username, $p_password, $p_issue_id, $p_name, $p_file_type, $p_content ) {
	$t_user_id = mci_check_login( $p_username, $p_password );
	if( $t_user_id === false ) {
		return mci_soap_fault_login_failed();
	}
	if( !file_allow_bug_upload( $p_issue_id, $t_user_id ) ) {
		return mci_soap_fault_access_denied( $t_user_id );
	}
	if( !access_has_bug_level( config_get( 'upload_bug_file_threshold' ), $p_issue_id, $t_user_id ) ) {
		return mci_soap_fault_access_denied( $t_user_id );
	}
	return mci_file_add( $p_issue_id, $p_name, $p_content, $p_file_type, 'bug', '', '', $t_user_id );
}
/**
 * Add an attachment to an existing project.
 *
 * @param string $p_username  The name of the user trying to add an attachment to an issue.
 * @param string $p_password  The password of the user.
 * @param integer $p_project_id  The id of the project to add the attachment to.
 * @param string $p_name  The name of the file.
 * @param string $p_title  The title for the attachment.
 * @param string $p_description  The description for the attachment.
 * @param string $p_file_type The mime type of the file.
 * @param base64Binary $p_content  The attachment to add.
 * @return integer The id of the added attachment.
 */
function mc_project_attachment_add($p_username, $p_password, $p_project_id, $p_name, $p_title, $p_description, $p_file_type, $p_content)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    # Check if project documentation feature is enabled.
    if (OFF == config_get('enable_project_documentation')) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    if (!access_has_project_level(config_get('upload_project_file_threshold'), $p_project_id, $t_user_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    if (is_blank($p_title)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Title must not be empty.');
    }
    return mci_file_add($p_project_id, $p_name, $p_content, $p_file_type, 'project', $p_title, $p_description, $t_user_id);
}
Example #3
0
 private function add_file($p_bug_id, &$p_part)
 {
     # Handle the file upload
     $t_part_name = isset($p_part['name']) ? trim($p_part['name']) : NULL;
     $t_strlen_body = strlen($p_part['body']);
     if (is_blank($t_part_name)) {
         // Try setting the file extension according to it's mime type
         $t_ext = array_search($p_part['ctype'], $this->_plugin_mime_types, TRUE);
         if ($t_ext === FALSE) {
             $t_ext = 'erp';
         }
         $t_part_name = md5(microtime()) . '.' . $t_ext;
     }
     $t_body_md5 = !empty($this->_mail_block_attachments_md5) ? md5($p_part['body']) : NULL;
     if (!file_type_check($t_part_name)) {
         return $t_part_name . ' = filetype not allowed' . "\n";
     } elseif (0 === $t_strlen_body) {
         return $t_part_name . ' = attachment size is zero (0 / ' . $this->_max_file_size . ')' . "\n";
     } elseif ($t_strlen_body > $this->_max_file_size) {
         return $t_part_name . ' = attachment size exceeds maximum allowed file size (' . $t_strlen_body . ' / ' . $this->_max_file_size . ')' . "\n";
     } elseif (in_array($t_body_md5, $this->_mail_block_attachments_md5, TRUE)) {
         if ($this->_mail_block_attachments_logging) {
             return $t_part_name . ' = attachment refused as it matched the md5 on the attachment blocklist (' . $t_body_md5 . ')' . "\n";
         } else {
             return TRUE;
         }
     } else {
         $t_file_number = 0;
         $t_opt_name = '';
         while (!file_is_name_unique($t_opt_name . $t_part_name, $p_bug_id)) {
             $t_file_number++;
             $t_opt_name = $t_file_number . '-';
         }
         mci_file_add($p_bug_id, $t_opt_name . $t_part_name, $p_part['body'], $p_part['ctype'], 'bug');
     }
     return TRUE;
 }