categorize_list.php 2.77 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
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.
changi67's avatar
changi67 committed
9
// $Id$
10

changi67's avatar
changi67 committed
11
require_once('tiki-setup.php');
12
$access = TikiLib::lib('access');
13
$access->check_script($_SERVER["SCRIPT_NAME"], basename(__FILE__));
14 15 16 17 18 19

$userlib = TikiLib::lib('user');
$smarty = TikiLib::lib('smarty');

global $prefs;

20
$catobjperms = Perms::get(array( 'type' => $cat_type, 'object' => $cat_objid ));
21

sylvieg's avatar
sylvieg committed
22
$smarty->assign('mandatory_category', '-1');
sylvieg's avatar
sylvieg committed
23
if ($prefs['feature_categories'] == 'y' && isset($cat_type) && isset($cat_objid)) {
24
	$categlib = TikiLib::lib('categ');
25

26
	if ( ! isset( $cat_object_exists ) ) {
27 28
		// article generator uses 'null' for type and id and puts the category id's in $_REQUEST
		$cat_object_exists = ($cat_objid === 'null') ? false : (bool) $cat_objid;
29 30
	}

31
	if ( $cat_object_exists ) {
32 33 34 35
		$cats = $categlib->get_object_categories($cat_type, $cat_objid);
	} else {
		$cats = $categlib->get_default_categories();
	}
36
	
37
	if ($cat_type == 'wiki page' || $cat_type == 'blog' || $cat_type == 'image gallery' || $cat_type == 'mypage') {
38 39
		$ext = ($cat_type == 'wiki page')? 'wiki':str_replace(' ', '_', $cat_type);
		$pref = 'feature_'.$ext.'_mandatory_category';
40
		if ($prefs[$pref] > 0) {
41
			$categories = $categlib->getCategories(array('identifier'=>$prefs[$pref], 'type'=>'descendants'));
42
		} else {
43
			$categories = $categlib->getCategories();
44 45
		}
		$smarty->assign('mandatory_category', $prefs[$pref]);
46
	} else {
47
		$categories = $categlib->getCategories();
48 49 50
	}

 	$can = $catobjperms->modify_object_categories;
51

52 53
	$categories = Perms::filter(array('type' => 'category'), 'object', $categories, array( 'object' => 'categId' ), array('view_category'));

54
	foreach ($categories as &$category) {
55
		$catperms = Perms::get(array( 'type' => 'category', 'object' => $category['categId'] ));
56

57 58 59
		if (in_array($category["categId"], $cats)) {
			$category["incat"] = 'y';
			$category['canchange'] = ! $cat_object_exists || ( $can && $catperms->remove_object );
60
		} else {
61 62
			$category["incat"] = 'n';
			$category['canchange'] = $can && $catperms->add_object;
63
		}
64 65 66
		
		// allow to preselect categories when creating a new article
		// like this: /tiki-edit_article.php?cat_categories[]=1&cat_categorize=on
67
		if (!$cat_object_exists && isset($_REQUEST["cat_categories"]) && isset($_REQUEST["cat_categorize"]) && $_REQUEST["cat_categorize"] == 'on') {
68 69
			if (in_array($category["categId"], $_REQUEST["cat_categories"])) {
				$category["incat"] = 'y';
70
			} else {
71
				$category["incat"] = 'n';
72 73
			}
		}
74
	}
75

76
	$smarty->assign('cat_tree', $categlib->generate_cat_tree($categories));
77
	
78
	$smarty->assign_by_ref('categories', $categories);
79
}
80