categorize.php 4 KB
Newer Older
musus's avatar
musus committed
1
<?php 
2
// $Id: /cvsroot/tikiwiki/tiki/categorize.php,v 1.25.2.1 2007-11-27 18:06:49 nkoth Exp $
3

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

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

16
global $prefs;
17
$catobjperms = Perms::get( array( 'type' => $cat_type, 'object' => $cat_objid ) );
18

19
if ($prefs['feature_categories'] == 'y' && $catobjperms->modify_object_categories ) {
20 21
	global $categlib; include_once('lib/categories/categlib.php');

22 23
	$smarty->assign('cat_categorize', 'n');

24 25 26
	if (isset($_REQUEST['import']) and isset($_REQUEST['categories'])) {
		$_REQUEST["cat_categories"] = split(',',$_REQUEST['categories']);
		$_REQUEST["cat_categorize"] = 'on';
27 28
	}

29
	if ( isset($_REQUEST["cat_categorize"]) && $_REQUEST["cat_categorize"] == 'on' && ! (isset($_REQUEST["cat_clearall"]) && $_REQUEST["cat_clearall"] == 'on') ) {
30 31
		$smarty->assign('cat_categorize', 'y');
	} else {
32
		$_REQUEST['cat_categories'] = NULL;
33
	}
34 35 36 37 38 39 40 41 42 43 44
	if ($prefs["feature_wikiapproval"] == 'y' && $cat_type == 'wiki page' && substr($cat_objid, 0, strlen($prefs['wikiapproval_prefix'])) == $prefs['wikiapproval_prefix']) {		
		if ($prefs['wikiapproval_approved_category'] > 0 && in_array($prefs['wikiapproval_approved_category'], $_REQUEST['cat_categories'])) {
			$_REQUEST['cat_categories'] = array_diff($_REQUEST['cat_categories'],Array($prefs['wikiapproval_approved_category']));
		}
		if ($prefs['wikiapproval_staging_category'] > 0 && !in_array($prefs['wikiapproval_staging_category'], $_REQUEST['cat_categories'])) {	
			$_REQUEST['cat_categories'][] = $prefs['wikiapproval_staging_category'];	
		}
		if ($prefs['wikiapproval_outofsync_category'] > 0 && !in_array($prefs['wikiapproval_outofsync_category'], $_REQUEST['cat_categories'])) {	
			$_REQUEST['cat_categories'][] = $prefs['wikiapproval_outofsync_category'];	
		}
	}
45 46 47 48
	if ($prefs["feature_wikiapproval"] == 'y' && $cat_type == 'wiki page' && substr($cat_objid, 0, strlen($prefs['wikiapproval_prefix'])) != $prefs['wikiapproval_prefix'] && in_array($prefs['wikiapproval_staging_category'], $_REQUEST['cat_categories']) && in_array($prefs['wikiapproval_approved_category'], $_REQUEST['cat_categories'])) {
		// Drop the staging category if page without staging prefix is attempted to be categorized in both staging category and approved category
		$_REQUEST['cat_categories'] = array_diff($_REQUEST['cat_categories'],Array($prefs['wikiapproval_staging_category']));
	}
49
	$categlib->update_object_categories(isset($_REQUEST['cat_categories'])?$_REQUEST['cat_categories']:'', $cat_objid, $cat_type, $cat_desc, $cat_name, $cat_href, $_REQUEST['cat_managed']);
50

51
	$cats = $categlib->get_object_categories($cat_type, $cat_objid);
52 53
	if (isset($section) && $section == 'wiki' && $prefs['feature_wiki_mandatory_category'] > 0)
		$categories = $categlib->list_categs($prefs['feature_wiki_mandatory_category']);
54 55
	else
		$categories = $categlib->list_categs();
56 57 58

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

59
	$num_categories = count($categories);
60 61
 	$can = $catobjperms->modify_object_categories;

62
	for ($iCat = 0; $iCat < $num_categories; $iCat++) {
sylvieg's avatar
sylvieg committed
63
		$catperms = Perms::get( array( 'type' => 'category', 'object' => $categories[$iCat]['categId'] ) );
64

65 66
		if (in_array($categories[$iCat]["categId"], $cats)) {
			$categories[$iCat]["incat"] = 'y';
sylvieg's avatar
sylvieg committed
67
			$categories[$iCat]['canchange'] = ($can && $catperms->remove_object) || isset($cat_object_exists) && ! $cat_object_exists;
68
		} else {
69
			$categories[$iCat]["incat"] = 'n';
sylvieg's avatar
sylvieg committed
70
			$categories[$iCat]['canchange'] = $can && $catperms->add_object;
71 72
		}
	}
73
	$smarty->assign_by_ref('categories', $categories["data"]);
74

75
}