From 7c86e056d8231ee4a9777fa59e53d6d4d3b07187 Mon Sep 17 00:00:00 2001 From: Nick Palmer Date: Sun, 23 Sep 2007 18:17:22 +0000 Subject: Changes to get ajax attachments working again. You must turn on the new storage.existing plugin to get them to work. --- attachment_uploader.php | 74 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 24 deletions(-) (limited to 'attachment_uploader.php') diff --git a/attachment_uploader.php b/attachment_uploader.php index c700051..f07f8d2 100644 --- a/attachment_uploader.php +++ b/attachment_uploader.php @@ -1,6 +1,6 @@ mContentId = $storeHash['liberty_attachments']['content_id']; - $storeHash['content_id'] = $storeHash['liberty_attachments']['content_id']; -} -if( isset( $_FILES['upload'] )) { - if( !$gContent->storeAttachments( $storeHash, FALSE )) { +// Do we have an attachment to save? +if( !empty($_FILES['upload']) ) { + + // Do we have a content_id already or is this a preflight? + if( !empty( $storeHash['liberty_attachments']['content_id'] ) ) { + + // Get the content_id into the right places. + $gContent->mContentId = $storeHash['content_id'] = $storeHash['liberty_attachments']['content_id']; + } + else { + $storeHash['content_id'] = $gContent->mContentId = NULL; + } + + $storeHash['skip_content_store'] = true; + + // store the attachment. + if (!$gContent->store($storeHash)) { $gBitSmarty->assign('errors', $gContent->mErrors); - } elseif( empty( $gContent->mContentId )) { - // Fake it for preflight - $gContent->mStorage[$storeHash['attachment_id']] = $gContent->getAttachment( $storeHash['attachment_id'] ); } -} + else { + // Load up the new attachment. + if (!empty($storeHash['STORAGE'])) { + foreach ($storeHash['STORAGE'] as $id => $file) { + if ($id != 'existing') { + foreach ($file as $key => $data) { + $gContent->mStorage[$data['attachment_id']] = $gContent->getAttachment($data['attachment_id']); + } + } + } + } + } -// load the attachments up -if( !empty( $gContent->mContentId )) { - $gContent->load(); -} elseif( !empty( $storeHash['existing_attachment_id'] )) { - // Fake it for preflight - foreach( $storeHash['existing_attachment_id'] as $id ) { - if( !empty( $id )) { - $gContent->mStorage[$id] = $gContent->getAttachment( $id ); + if ( empty($gContent->mContentId) ) { + // Setup the existing_attachment_id stuff + if( !empty( $storeHash['STORAGE']['existing'] )) { + // Fake it for preflight + foreach( $storeHash['STORAGE']['existing'] as $id ) { + if( !empty( $id )) { + $gContent->mStorage[$id] = $gContent->getAttachment( $id ); + } + } } } -} + else { + $gContent->load(); + } -// Make them come out in the right order -if( !empty( $gContent->mStorage )) { - ksort( $gContent->mStorage ); + // Make them come out in the right order + if( !empty( $gContent->mStorage )) { + ksort( $gContent->mStorage ); + } +} +else { + $gBitSmarty->assign('errors', tra('There was an unknown error with the upload.')); } $gBitSmarty->assign( 'gContent', $gContent ); $gBitSmarty->assign( 'libertyUploader', TRUE ); -echo $gBitSmarty->display( 'bitpackage:liberty/attachment_uploader.tpl' ); +echo $gBitSystem->display( 'bitpackage:liberty/attachment_uploader.tpl', NULL, 'none' ); ?> -- cgit v1.3