summaryrefslogtreecommitdiff
path: root/list_content.php
blob: d52d4740639600eb6b77ebfbe856e11b20ec3942 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
 * list_content
 *
 * @author   spider <spider@steelsun.com>
 * @version  $Revision$
 * @package  liberty
 * @subpackage functions
 */

/**
 * required setup
 */
require_once "../kernel/includes/setup_inc.php";
use Bitweaver\BitBase;
use Bitweaver\KernelTools;
use Bitweaver\Liberty\LibertyContent;

$gBitSystem->verifyPermission( 'p_liberty_list_content' );

// some content specific offsets and pagination settings
if( !empty( $_REQUEST['sort_mode'] )) {
	$content_sort_mode = $_REQUEST['sort_mode'];
	$gBitSmarty->assign( 'sort_mode', $content_sort_mode );
}

#$max_content = ( !empty( $_REQUEST['max_records'] )) ? $_REQUEST['max_records'] : $gBitSystem->getConfig( 'max_records' );

if( !empty( $_POST ) ) {
	$feedback = [];

	$gBitUser->verifyTicket();
	switch( BitBase::getParameter( $_POST, 'action' ) ) {
		case 'delete':
			if( !empty( $_POST['batch_content_ids'] ) ) {
				// only admins can batch delete
				$gBitSystem->verifyPermission( 'p_admin' );
				$delUsers = $errDelUsers = "";
				foreach( $_POST['batch_content_ids'] as $contentId ) {
					if( ($content = LibertyContent::getLibertyObject( $contentId )) && $content->isValid() ) {
						$title = $content->getTitle();
						if( $content->expunge() ) {
							$delUsers .= '<li>'.$content->getField('content_type_guid').'#'.$contentId." ".$title."</li>";
						} else {
							$errDelUsers .= "<li>#$contentId could not be expunged</li>";
						}
					} else {
						$errDelUsers .= "<li>#$contentId could not be loaded</li>";
					}
				}
			}
			break;
	}
	if( !empty( $delUsers ) ) {
		$feedback['success'][] = KernelTools::tra( 'Content deleted' ).": <ul>$delUsers</ul>";
	}
	if( !empty( $errDelUsers ) ) {
		$feedback['error'][] = KernelTools::tra( 'Content not deleted' ).": <ul>$errDelUsers</ul>";
	}
	$gBitSmarty->assign( 'feedback', $feedback );
}

$max_content = !empty( $_SESSION['liberty_records_per_page'] )
	? $_SESSION['liberty_records_per_page']
	: $gBitSystem->getConfig( 'max_records', 10 );

if( !empty( $_REQUEST["max_records"] )) {
	$max_content = $_REQUEST["max_records"];
	$_SESSION['liberty_records_per_page'] = $max_content;
}

// now that we have all the offsets, we can get the content list
include_once LIBERTY_PKG_INCLUDE_PATH.'get_content_list_inc.php';

$gBitSmarty->assign( 'contentSelect', $contentSelect );
$gBitSmarty->assign( 'contentTypes', $contentTypes );
$gBitSmarty->assign( 'contentList', $contentList );
$contentListHash['listInfo']['ihash']['content_type_guid'] = $contentSelect;
$contentListHash['listInfo']['ihash']['user_id'] = BitBase::verifyId( $_REQUEST['user_id'] ?? 0 ) ? $_REQUEST['user_id'] : null;
$contentListHash['listInfo']['ihash']['find'] = $contentListHash['listInfo']['find'];
$gBitSmarty->assign( 'listInfo', $contentListHash['listInfo'] );
$gBitSmarty->assign( 'content_type_guids',  $_REQUEST['content_type_guid'] ?? null );

//depricate 'ajax_xml', use 'output'
//@todo clean out from other packages
if( !empty( $_REQUEST['ajax_xml'] )) {
	$_REQUEST['output'] = 'ajax';
}

if( !empty( $_REQUEST['output'] )) {
	switch( $_REQUEST['output'] ) {
	case 'json':
		$gBitSmarty->assign( 'listcontent', $contentList );
		header( 'Content-type:application/json' );
		$gBitSmarty->display( 'bitpackage:liberty/list_content_json.tpl' );
		break;
	case 'ajax':
		/* @TODO the results structure of this are limited and 
		 * seem specific to some package use. It also requires 
		 * an extra value 'id' which also seems very specific. 
		 * Recommend that this be standardized, but 
		 * a package dependency somewhere is likely an issue
		 */
		foreach( array_keys( $contentList ) as $row ) {
			$xmlList[$contentList[$row]['content_id']] = $contentList[$row]['title'];
		}
		$xml = '<?xml version="1.0" ?><ajax-response><response type="object" id="'.$_REQUEST['id'].'_updater"><matches>';
		foreach( $xmlList as $value=>$name ) {
			$xml .= "<entry><text>".htmlentities( $name )."</text><value>".htmlentities( $value )."</value></entry>";
		}
		$xml .= "</matches></response></ajax-response>";
		header( "Content-Type: text/xml\n\n" );
		print $xml;
		break;
	case 'raw':
		//means we just want the contents of $contentList when we include this file
		break;
	}
} else {
	$gBitSystem->setBrowserTitle( 'List Content' );
	$gBitSystem->display( 'bitpackage:liberty/list_content.tpl' , null, [ 'display_mode' => 'list' ] );
}