tiki-list_articles.php 7.64 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
6
// 
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9
// $Id$
10
$section = 'cms';
11
require_once ('tiki-setup.php');
lphuberdeau's avatar
lphuberdeau committed
12
$artlib = TikiLib::lib('art');
13 14
$access->check_feature('feature_articles');
$access->check_permission('tiki_p_read_article');
15
$auto_query_args = array('sort_mode', 'category', 'offset', 'maxRecords', 'find', 'find_from_Month', 'find_from_Day', 'find_from_Year', 'find_to_Month', 'find_to_Day', 'find_to_Year', 'type', 'topic', 'cat_categories', 'categId', 'lang', 'mode', 'mapview', 'searchmap', 'searchlist');
16 17 18 19 20 21 22 23 24 25 26
if ($prefs["gmap_article_list"] == 'y') {
	$smarty->assign('gmapbuttons', true);
} else {
	$smarty->assign('gmapbuttons', false);
}
if (isset($_REQUEST["mapview"]) && $_REQUEST["mapview"] == 'y' && !isset($_REQUEST["searchmap"]) && !isset($_REQUEST["searchlist"]) || isset($_REQUEST["searchmap"]) && !isset($_REQUEST["searchlist"])) {
	$smarty->assign('mapview', true);
}
if (isset($_REQUEST["mapview"]) && $_REQUEST["mapview"] == 'n' && !isset($_REQUEST["searchmap"]) && !isset($_REQUEST["searchlist"]) || isset($_REQUEST["searchlist"]) && !isset($_REQUEST["searchmap"]) ) {
	$smarty->assign('mapview', false);
}
27
if (isset($_REQUEST["remove"])) {
28
	$artperms = Perms::get(array( 'type' => 'article', 'object' => $_REQUEST['remove'] ));
29 30

	if ($artperms->remove_article != 'y') {
31
		$smarty->assign('errortype', 401);
32
		$smarty->assign('msg', tra("You do not have permission to remove articles"));
33
		$smarty->display("error.tpl");
34 35
		die;
	}
chealer's avatar
chealer committed
36
	$access->check_authenticity(tr('Are you sure you want to permanently remove the article with identifier %0?', $_REQUEST["remove"]));
37
	$artlib->remove_article($_REQUEST["remove"]);
38
}
39 40 41
if (isset($_REQUEST['submit_mult'])) {
	if ($_REQUEST['submit_mult'] === 'remove_articles' && count($_REQUEST["checked"]) > 0) {
		foreach ($_REQUEST["checked"] as $aId) {
42
			$artperms = Perms::get(array( 'type' => 'article', 'object' => $aId ));
43 44 45 46 47 48 49 50

			if ($artperms->remove_article != 'y') {
				$smarty->assign('errortype', 401);
				$smarty->assign('msg', tra("You do not have permission to remove articles"));
				$smarty->display("error.tpl");
				die;
			}
		}
chealer's avatar
chealer committed
51
		$access->check_authenticity(tr('Are you sure you want to permanently remove these %0 articles?', count($_REQUEST["checked"])));
52 53 54 55 56 57

		foreach ($_REQUEST["checked"] as $aId) {
			$artlib->remove_article($aId);
		}
	}
}
marclaporte's avatar
marclaporte committed
58
// This script can receive the threshold
59 60 61
// for the information as the number of
// days to get in the log 1,3,4,etc
// it will default to 1 recovering information for today
62 63
if (!isset($_REQUEST["sort_mode"])) {
	$sort_mode = 'publishDate_desc';
64
} else {
65 66 67
	$sort_mode = $_REQUEST["sort_mode"];
}
$smarty->assign_by_ref('sort_mode', $sort_mode);
68 69 70
// If offset is set use it if not then use offset =0
// use the maxRecords php variable to set the limit
// if sortMode is not set then use lastModif_desc
71 72
if (!isset($_REQUEST["offset"])) {
	$offset = 0;
73
} else {
74
	$offset = $_REQUEST["offset"];
75
}
76
$smarty->assign_by_ref('offset', $offset);
sylvieg's avatar
sylvieg committed
77 78
if (!empty($_REQUEST['maxRecords'])) {
	$maxRecords = $_REQUEST['maxRecords'];
79
} else {
80
	$maxRecords = $maxRecords;
sylvieg's avatar
sylvieg committed
81
}
sylvieg's avatar
sylvieg committed
82
$smarty->assign_by_ref('maxRecords', $maxRecords);
83 84

$visible_only = 'y';
changi67's avatar
changi67 committed
85 86
if (($tiki_p_admin == 'y') || ($tiki_p_admin_cms == 'y')) {
	$date_max = '';
87
	$visible_only = "n";
changi67's avatar
changi67 committed
88 89 90 91 92 93 94 95
} elseif (isset($_SESSION["thedate"])) {
	if ($_SESSION["thedate"] < $tikilib->now) {
		// If the session is older then set it to today
		// so you can list articles
		$date_max = $tikilib->now;
	} else {
		$date_max = $_SESSION["thedate"];
	}
96
} else {
97
	$date_max = $tikilib->now;
98
}
99
if (!empty($_REQUEST["find_from_Month"]) && !empty($_REQUEST["find_from_Day"]) && !empty($_REQUEST["find_from_Year"])) {
100
	$date_min = $tikilib->make_time(0, 0, 0, $_REQUEST["find_from_Month"], $_REQUEST["find_from_Day"], $_REQUEST["find_from_Year"]);
101 102 103 104 105 106
	$smarty->assign('find_date_from', $date_min);
} else {
	$date_min = 0;
	$smarty->assign('find_date_from', $tikilib->now - 365*24*3600);
}
if (isset($_REQUEST["find_to_Month"]) && isset($_REQUEST["find_to_Day"]) && isset($_REQUEST["find_to_Year"])) {
107
	$t_date_max = $tikilib->make_time(23, 59, 59, $_REQUEST["find_to_Month"], $_REQUEST["find_to_Day"], $_REQUEST["find_to_Year"]);
108 109 110 111 112 113
	if ($t_date_max < $date_max || $date_max == '') {
		$date_max = $t_date_max;
		$visible_only = 'y';
	}
}
$smarty->assign('find_date_to', $date_max);
114 115
if (isset($_REQUEST["find"])) {
	$find = $_REQUEST["find"];
116
} else {
117
	$find = '';
118
}
119 120 121
$smarty->assign('find', $find);
if (!isset($_REQUEST["type"])) {
	$_REQUEST["type"] = '';
122
}
123 124
if (!isset($_REQUEST["topic"])) {
	$_REQUEST["topic"] = '';
125
}
126 127

$filter['categId'] = 0;
128
if ($prefs['feature_categories'] == 'y') {
129 130 131 132
	if ( $_REQUEST['find_show_categories_multi'] == 'n' ) {
		// There category selection was done with the single category drop-down. We ignore any value from the multiple category selector which was hidden
		unset($_REQUEST['cat_categories']);
	}
133 134 135 136 137 138
	if (!empty($_REQUEST['cat_categories'])) {
		if (count($_REQUEST['cat_categories']) > 1) {
			unset($_REQUEST['categId']);
		} else {
			$_REQUEST['categId'] = $_REQUEST['cat_categories'][0];
		}
139
	} else {
140
		$_REQUEST['cat_categories'] = array();
141
	}
142
	$filter['categId'] = $_REQUEST['cat_categories'];
143 144
	$smarty->assign('findSelectedCategoriesNumber', count($_REQUEST['cat_categories']));
	if (!empty($_REQUEST['categId'])) {
145
		$filter['categId'] = array((int) $_REQUEST['categId']);
146
		$smarty->assign('find_categId', $_REQUEST['categId']);
147 148
	} else {
		$smarty->assign('find_categId', '');
149
	}
150
	$selectedCategories = $filter['categId'];
151
}
152

153 154 155
if (!isset($_REQUEST['lang'])) {
	$_REQUEST['lang'] = '';
}
156 157
$smarty->assign('find_topic', $_REQUEST["topic"]);
$smarty->assign('find_type', $_REQUEST["type"]);
158
$smarty->assign('find_lang', $_REQUEST['lang']);
159
// Get a list of last changes to the Wiki database
160
$listpages = $artlib->list_articles($offset, $maxRecords, $sort_mode, $find, $date_min, $date_max, $user, $_REQUEST["type"], $_REQUEST["topic"], $visible_only, '', $filter["categId"], '', '', $_REQUEST['lang']);
161
// If there're more records then assign next_offset
162
$smarty->assign_by_ref('cant', $listpages['cant']);
163
$smarty->assign_by_ref('listpages', $listpages["data"]);
164

165 166 167 168 169 170 171 172 173 174 175 176 177
if ($prefs["gmap_article_list"] == 'y') {
	// Generate Google map plugin data
	global $gmapobjectarray;
	$gmapobjectarray = array();
	foreach ($listpages["data"] as $art) {
		$gmapobjectarray[] = array('type' => 'article',
			'id' => $art["articleId"],
			'title' => $art["title"],
			'href' => 'tiki-read_article.php?articleId=' . $art["articleId"],
		);
	}
}

178
$topics = $artlib->list_topics();
179
$smarty->assign_by_ref('topics', $topics);
180 181
$types = $artlib->list_types();
$smarty->assign_by_ref('types', $types);
182
if ($prefs['feature_categories'] == 'y') {
183
	$categlib = TikiLib::lib('categ');
184
	$categories = $categlib->getCategories();
185
	$smarty->assign_by_ref('categories', $categories);
186
	$smarty->assign('cat_tree', $categlib->generate_cat_tree($categories, true, $selectedCategories));	
187
}
188
if ($prefs['feature_multilingual'] == 'y') {
sylvieg's avatar
sylvieg committed
189
	$languages = array();
190 191
	$langLib = TikiLib::lib('language');
	$languages = $langLib->list_languages(false, 'y');
sylvieg's avatar
sylvieg committed
192 193
	$smarty->assign_by_ref('languages', $languages);
}
194
if ($tiki_p_edit_article != 'y' && $tiki_p_remove_article != 'y') { //check one editable
195
	foreach ($listpages['data'] as $page) {
196
		if (!empty($user) && $page['author'] == $user && $page['creator_edit'] == 'y') {
197 198 199 200 201
			$smarty->assign('oneEditPage', 'y');
			break;
		}
	}
}
202
include_once ('tiki-section_options.php');
203
ask_ticket('list-articles');
204
// Display the template
205
$smarty->assign('mid', 'tiki-list_articles.tpl');
206
$smarty->display("tiki.tpl");