categorize_list.php 4.59 KB
Newer Older
1 2
<?php

3
// $Id$
4

5
// Copyright (c) 2002-2007, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
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.

michael_davey's avatar
michael_davey committed
9 10
//this script may only be included - so its better to err & die if called directly.
//smarty is not there - we need setup
11 12 13 14
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  header("location: index.php");
  exit;
}
michael_davey's avatar
michael_davey committed
15
require_once('tiki-setup.php');  
16
global $prefs, $userlib;
17
$catobjperms = Perms::get( array( 'type' => $cat_type, 'object' => $cat_objid ) );
18

sylvieg's avatar
sylvieg committed
19
$smarty->assign('mandatory_category', '-1');
sylvieg's avatar
sylvieg committed
20
if ($prefs['feature_categories'] == 'y' && isset($cat_type) && isset($cat_objid)) {
21
	global $categlib, $user; include_once ('lib/categories/categlib.php');
22 23 24 25
	$smarty->assign('cat_categorize', 'n');

	if (isset($_REQUEST["cat_categorize"]) && $_REQUEST["cat_categorize"] == 'on') {
		$smarty->assign('cat_categorize', 'y');
26
	}
27

28
	if( ! isset( $cat_object_exists ) ) {
29
		$cat_object_exists = (bool) $cat_objid;
30 31 32
	}

	if( $cat_object_exists ) {
33 34 35 36
		$cats = $categlib->get_object_categories($cat_type, $cat_objid);
	} else {
		$cats = $categlib->get_default_categories();
	}
37 38 39 40 41 42 43 44 45 46
	
	if ($prefs['feature_wikiapproval'] == 'y' && $prefs['wikiapproval_sync_categories'] == 'y' && !$cats
	 && $cat_type == 'wiki page' && substr($cat_objid, 0, strlen($prefs['wikiapproval_prefix'])) == $prefs['wikiapproval_prefix']
	 && !$tikilib->page_exists($cat_objid) ) {
	 	// to pre-populate categories of original page if this is the first creation of a staging page
		$approvedPageName = substr($cat_objid, strlen($prefs['wikiapproval_prefix']));
		$cats = $categlib->get_object_categories($cat_type, $approvedPageName);
		$cats = array_diff($cats,Array($prefs['wikiapproval_approved_category']));		
	}
	
47
	if ($cat_type == 'wiki page' || $cat_type == 'blog' || $cat_type == 'image gallery' || $cat_type == 'mypage') {
48 49
		$ext = ($cat_type == 'wiki page')? 'wiki':str_replace(' ', '_', $cat_type);
		$pref = 'feature_'.$ext.'_mandatory_category';
50 51 52
		if ($prefs[$pref] > 0) {
			$all_categories = $categlib->list_categs($prefs[$pref]);
		} else {
53
			$all_categories = $categlib->list_categs();
54 55
		}
		$smarty->assign('mandatory_category', $prefs[$pref]);
56
	} else {
57 58 59
		$all_categories = $categlib->list_categs();
	}

60 61 62 63 64 65
	if( ! empty( $all_categories ) ) {
		$categories = Perms::filter( array( 'type' => 'category' ), 'object', $all_categories, array( 'object' => 'categId' ), 'view_category' );
	} else {
		$categories = array();
	}

66
	$num_categories = count($categories);
67
 	$can = $catobjperms->modify_object_categories;
68 69

	for ($i = 0; $i < $num_categories; $i++) {
70 71
		$catperms = Perms::get( array( 'type' => 'category', 'object' => $categories[$i]['categId'] ) );

72
		if (!empty($cats) && in_array($categories[$i]["categId"], $cats)) {
73
			$categories[$i]["incat"] = 'y';
74
			$categories[$i]['canchange'] = ! $cat_object_exists || ( $can && $catperms->remove_object );
75 76
		} else {
			$categories[$i]["incat"] = 'n';
77
			$categories[$i]['canchange'] = $can && $catperms->add_object;
78
		}
79 80 81
		if (isset($_REQUEST["cat_categories"]) && isset($_REQUEST["cat_categorize"]) && $_REQUEST["cat_categorize"] == 'on') {
			if (in_array($categories[$i]["categId"], $_REQUEST["cat_categories"])) {
				$categories[$i]["incat"] = 'y';
82 83 84
				// allow to preselect categories when creating a new article
				// like this: /tiki-edit_article.php?cat_categories[]=1&cat_categorize=on
				$smarty->assign('categ_checked', 'y');
85 86 87 88
			} else {
				$categories[$i]["incat"] = 'n';
			}
		}
89
	}
90

91
	include_once ('lib/tree/categ_picker_tree.php');
92
	$tree_nodes = array();
93
	$roots = $categlib->findRoots( $categories );
94 95
	foreach ($categories as $c) {
		if (isset($c['name']) || $c['parentId'] != 0) {
96
			$smarty->assign( 'category_data', $c );
97 98 99
			$tree_nodes[] = array(
				'id' => $c['categId'],
				'parent' => $c['parentId'],
100
				'data' => $smarty->fetch( 'category_tree_entry.tpl' ),
101
			);
102
			if (in_array( $c['parentId'], $roots )) {
103 104 105 106
				$tree_nodes[count($tree_nodes) - 1]['data'] = '<strong>'.$tree_nodes[count($tree_nodes) - 1]['data'].'</strong>';
			}
		}
	}
107
	$tm = new CatPickerTreeMaker("categorize");
108 109 110 111
	$res = '';
	foreach( $roots as $root ) {
		$res .= $tm->make_tree($root, $tree_nodes);
	}
112 113
	$smarty->assign('cat_tree', $res);
	
sylvieg's avatar
sylvieg committed
114 115
	if (!empty($cats))
		$smarty->assign('catsdump', implode(',',$cats));
116
	$smarty->assign_by_ref('categories', $categories);
117 118 119 120

	// check if this page is categorized
	if ($categlib->is_categorized($cat_type, $cat_objid)) {
		$cat_categorize = 'y';
121
	} else {
122
		$cat_categorize = 'n';
123
	}
124
	$smarty->assign('cat_categorize', $cat_categorize);
125
}