summaryrefslogtreecommitdiff
path: root/edit_storage_inc.php
blob: 0f698d375ac3e7f16f4b857c72aeda3e99cdbe87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
 * edit_storage_inc
 *
 * @author   spider <spider@steelsun.com>
 * @version  $Revision: 1.10 $
 * @package  liberty
 * @subpackage functions
 *
 * This file is automatically included by edit_storage.tpl - All you need to do is include edit_storage.tpl
 * from your template file.
 *
 * Calculate a base URL for the attachment deletion/removal icons to use
 */
global $gBitSmarty, $gContent, $gBitUser, $gBitSystem, $gLibertySystem;
$attachmentActionBaseURL = $_SERVER['PHP_SELF'].'?';
$GETArgs = split('&',$_SERVER['QUERY_STRING']);
$firstArg = TRUE;

foreach( $GETArgs as $arg ) {
	$parts = split('=',$arg);
	if( ( $parts[0] != 'deleteAttachment' ) && $parts[0] != 'detachAttachment' ) {
		if( !$firstArg )
			$attachmentActionBaseURL .= "&amp;";
		else
			$firstArg = FALSE;
		$attachmentActionBaseURL .= $arg;
	}
}
$gBitSmarty->assign( 'attachmentActionBaseURL', $attachmentActionBaseURL );

if( !empty( $_REQUEST['deleteAttachment'] ) ) {
	$attachmentId = $_REQUEST['deleteAttachment'];

	$siblingAttachments = $gContent->getSiblingAttachments( $attachmentId );
	$attachmentInfo = $gContent->getAttachment( $attachmentId );
	
	if( count( $siblingAttachments ) > 0 || ( !$gBitUser->isAdmin() && $gBitUser->mUserId != $attachmentInfo['user_id'] && $gBitUser->mPerms['p_liberty_detach_attachment'] == 'y' ) ) {
		// Other liberty_attachment rows reference the same foreign_id so we should just detach
		$gContent->detachAttachment( $attachmentId );	
	} else {
		$gContent->expungeAttachment( $attachmentId );
	}
} elseif( !empty( $_REQUEST['detachAttachment'] ) ) {
	$attachmentId = $_REQUEST['detachAttachment'];
	$attachmentInfo = $gContent->getAttachment( $attachmentId );
	
	if( $gBitUser->isAdmin() || $gBitUser->mPerms['p_liberty_detach_attachment'] == 'y' || $attachmentInfo['user_id'] == $gBitUser->mUserId ) {
		$gContent->detachAttachment( $attachmentId );
	}
}
$gBitSmarty->assign_by_ref( 'gLibertySystem', $gLibertySystem );	

// in case we have deleted attachments
// seems like there should be a better way to do this -- maybe original assign should have been by reference?
$gBitSmarty->clear_assign( 'gContent' );
$gBitSmarty->assign( 'gContent', $gContent );

?>