1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8/**
9* Smarty function plugin
10* -------------------------------------------------------------
11* Type:     	function
12* Name:     	obj_in_cat
13* Author:   	Enmore Services
14* Purpose:  	returns true if an object is in a category
15* Parameters:	all 3 parameters are mandatory
16*				object is reference to the specific object to be tested eg object=$page
17*				type is the content type eg type='wiki page'
18*				catnumber is the category Id# eg catnumber=3
19* -------------------------------------------------------------
20*/
21//this script may only be included - so its better to die if called directly.
22if (strpos($_SERVER['SCRIPT_NAME'], basename(__FILE__)) !== false) {
23	header('location: index.php');
24	exit;
25}
26
27function smarty_function_obj_in_cat($params, $smarty)
28{
29	$categlib = TikiLib::lib('categ');
30	extract($params, EXTR_SKIP);
31	if (! isset($object)) {
32		return ('<b>missing object parameter for Smarty function testing whether object is in a category</b><br/>');
33	}
34
35	if (! isset($type)) {
36		return ('<b>missing type parameter for Smarty function testing whether object is in a category</b><br/>');
37	}
38
39	if (! isset($catnumber)) {
40		return ('<b>missing catnumber parameter for Smarty function testing whether object is in a category</b><br/>');
41	}
42
43	$categories = $categlib->get_object_categories($type, $object);
44	$result = false;
45
46	foreach ($categories as $cat) {
47		if ($cat == $catnumber) {
48			$result = true;
49			$smarty->assign('obj_in_cat', $result);
50			return;
51		}
52	}
53	$smarty->assign('obj_in_cat', $result);
54}
55