1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10$section = 'cms';
11require_once('tiki-setup.php');
12$artlib = TikiLib::lib('art');
13$access->check_feature('feature_articles');
14$auto_query_args = ['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'];
15if ($prefs["gmap_article_list"] == 'y') {
16	$smarty->assign('gmapbuttons', true);
17} else {
18	$smarty->assign('gmapbuttons', false);
19}
20if (isset($_REQUEST["mapview"]) && $_REQUEST["mapview"] == 'y' && ! isset($_REQUEST["searchmap"]) && ! isset($_REQUEST["searchlist"]) || isset($_REQUEST["searchmap"]) && ! isset($_REQUEST["searchlist"])) {
21	$smarty->assign('mapview', true);
22}
23if (isset($_REQUEST["mapview"]) && $_REQUEST["mapview"] == 'n' && ! isset($_REQUEST["searchmap"]) && ! isset($_REQUEST["searchlist"]) || isset($_REQUEST["searchlist"]) && ! isset($_REQUEST["searchmap"])) {
24	$smarty->assign('mapview', false);
25}
26if (isset($_REQUEST["remove"])) {
27	$artperms = Perms::get([ 'type' => 'article', 'object' => $_REQUEST['remove'] ]);
28
29	if ($artperms->remove_article != 'y') {
30		$smarty->assign('errortype', 401);
31		$smarty->assign('msg', tra("You do not have permission to remove articles"));
32		$smarty->display("error.tpl");
33		die;
34	}
35	$access->check_authenticity(tr('Are you sure you want to permanently remove the article with identifier %0?', $_REQUEST["remove"]));
36	$artlib->remove_article($_REQUEST["remove"]);
37}
38if (isset($_REQUEST['submit_mult'])) {
39	if ($_REQUEST['submit_mult'] === 'remove_articles' && count($_REQUEST["checked"]) > 0) {
40		foreach ($_REQUEST["checked"] as $aId) {
41			$artperms = Perms::get([ 'type' => 'article', 'object' => $aId ]);
42
43			if ($artperms->remove_article != 'y') {
44				$smarty->assign('errortype', 401);
45				$smarty->assign('msg', tra("You do not have permission to remove articles"));
46				$smarty->display("error.tpl");
47				die;
48			}
49		}
50		$access->check_authenticity(tr('Are you sure you want to permanently remove these %0 articles?', count($_REQUEST["checked"])));
51
52		foreach ($_REQUEST["checked"] as $aId) {
53			$artlib->remove_article($aId);
54		}
55	}
56}
57// This script can receive the threshold
58// for the information as the number of
59// days to get in the log 1,3,4,etc
60// it will default to 1 recovering information for today
61if (! isset($_REQUEST["sort_mode"])) {
62	$sort_mode = 'publishDate_desc';
63} else {
64	$sort_mode = $_REQUEST["sort_mode"];
65}
66$smarty->assign_by_ref('sort_mode', $sort_mode);
67// If offset is set use it if not then use offset =0
68// use the maxRecords php variable to set the limit
69// if sortMode is not set then use lastModif_desc
70if (! isset($_REQUEST["offset"])) {
71	$offset = 0;
72} else {
73	$offset = $_REQUEST["offset"];
74}
75$smarty->assign_by_ref('offset', $offset);
76if (! empty($_REQUEST['maxRecords'])) {
77	$maxRecords = $_REQUEST['maxRecords'];
78} else {
79	$maxRecords = $maxRecords;
80}
81$smarty->assign_by_ref('maxRecords', $maxRecords);
82
83$visible_only = 'y';
84if (($tiki_p_admin == 'y') || ($tiki_p_admin_cms == 'y')) {
85	$date_max = '';
86	$visible_only = "n";
87} elseif (isset($_SESSION["thedate"])) {
88	if ($_SESSION["thedate"] < $tikilib->now) {
89		// If the session is older then set it to today
90		// so you can list articles
91		$date_max = $tikilib->now;
92	} else {
93		$date_max = $_SESSION["thedate"];
94	}
95} else {
96	$date_max = $tikilib->now;
97}
98if (! empty($_REQUEST["find_from_Month"]) && ! empty($_REQUEST["find_from_Day"]) && ! empty($_REQUEST["find_from_Year"])) {
99	$date_min = $tikilib->make_time(0, 0, 0, $_REQUEST["find_from_Month"], $_REQUEST["find_from_Day"], $_REQUEST["find_from_Year"]);
100	$smarty->assign('find_date_from', $date_min);
101} else {
102	$date_min = 0;
103	$smarty->assign('find_date_from', $tikilib->now - 365 * 24 * 3600);
104}
105if (isset($_REQUEST["find_to_Month"]) && isset($_REQUEST["find_to_Day"]) && isset($_REQUEST["find_to_Year"])) {
106	$t_date_max = $tikilib->make_time(23, 59, 59, $_REQUEST["find_to_Month"], $_REQUEST["find_to_Day"], $_REQUEST["find_to_Year"]);
107	if ($t_date_max < $date_max || $date_max == '') {
108		$date_max = $t_date_max;
109		$visible_only = 'y';
110	}
111}
112$smarty->assign('find_date_to', $date_max);
113if (isset($_REQUEST["find"])) {
114	$find = $_REQUEST["find"];
115} else {
116	$find = '';
117}
118$smarty->assign('find', $find);
119if (! isset($_REQUEST["type"])) {
120	$_REQUEST["type"] = '';
121}
122if (! isset($_REQUEST["topic"])) {
123	$_REQUEST["topic"] = '';
124}
125
126$filter['categId'] = 0;
127if ($prefs['feature_categories'] == 'y') {
128	if ($_REQUEST['find_show_categories_multi'] == 'n') {
129		// There category selection was done with the single category drop-down. We ignore any value from the multiple category selector which was hidden
130		unset($_REQUEST['cat_categories']);
131	}
132	if (! empty($_REQUEST['cat_categories'])) {
133		if (count($_REQUEST['cat_categories']) > 1) {
134			unset($_REQUEST['categId']);
135		} else {
136			$_REQUEST['categId'] = $_REQUEST['cat_categories'][0];
137		}
138	} else {
139		$_REQUEST['cat_categories'] = [];
140	}
141	$filter['categId'] = $_REQUEST['cat_categories'];
142	$smarty->assign('findSelectedCategoriesNumber', count($_REQUEST['cat_categories']));
143	if (! empty($_REQUEST['categId'])) {
144		$filter['categId'] = [(int) $_REQUEST['categId']];
145		$smarty->assign('find_categId', $_REQUEST['categId']);
146	} else {
147		$smarty->assign('find_categId', '');
148	}
149	$selectedCategories = $filter['categId'];
150}
151
152if (! isset($_REQUEST['lang'])) {
153	$_REQUEST['lang'] = '';
154}
155$smarty->assign('find_topic', $_REQUEST["topic"]);
156$smarty->assign('find_type', $_REQUEST["type"]);
157$smarty->assign('find_lang', $_REQUEST['lang']);
158// Get a list of last changes to the Wiki database
159$listpages = $artlib->list_articles($offset, $maxRecords, $sort_mode, $find, $date_min, $date_max, $user, $_REQUEST["type"], $_REQUEST["topic"], $visible_only, '', $filter["categId"], '', '', $_REQUEST['lang']);
160// If there're more records then assign next_offset
161$smarty->assign_by_ref('cant', $listpages['cant']);
162$smarty->assign_by_ref('listpages', $listpages["data"]);
163
164if ($prefs["gmap_article_list"] == 'y') {
165	// Generate Google map plugin data
166	global $gmapobjectarray;
167	$gmapobjectarray = [];
168	foreach ($listpages["data"] as $art) {
169		$gmapobjectarray[] = ['type' => 'article',
170			'id' => $art["articleId"],
171			'title' => $art["title"],
172			'href' => 'tiki-read_article.php?articleId=' . $art["articleId"],
173		];
174	}
175}
176
177$topics = $artlib->list_topics();
178$smarty->assign_by_ref('topics', $topics);
179$types = $artlib->list_types();
180$smarty->assign_by_ref('types', $types);
181if ($prefs['feature_categories'] == 'y') {
182	$categlib = TikiLib::lib('categ');
183	$categories = $categlib->getCategories();
184	$smarty->assign_by_ref('categories', $categories);
185	$smarty->assign('cat_tree', $categlib->generate_cat_tree($categories, true, $selectedCategories));
186}
187if ($prefs['feature_multilingual'] == 'y') {
188	$languages = [];
189	$langLib = TikiLib::lib('language');
190	$languages = $langLib->list_languages(false, 'y');
191	$smarty->assign_by_ref('languages', $languages);
192}
193if ($tiki_p_edit_article != 'y' && $tiki_p_remove_article != 'y') { //check one editable
194	foreach ($listpages['data'] as $page) {
195		if (! empty($user) && $page['author'] == $user && $page['creator_edit'] == 'y') {
196			$smarty->assign('oneEditPage', 'y');
197			break;
198		}
199	}
200}
201include_once('tiki-section_options.php');
202ask_ticket('list-articles');
203// Display the template
204$smarty->assign('mid', 'tiki-list_articles.tpl');
205$smarty->display("tiki.tpl");
206