1<?php
2
3// this module is only for demonstrative purposes,
4// a real appdir would be better defined as a real phpgw application
5// and a sitemgr module would not have to handle the data, but only to fetch it
6class module_appdir extends Module
7{
8
9	function module_appdir()
10	{
11		$this->arguments = array();
12		$this->title = lang('An application directory');
13		$this->description = lang('This module demonstrates how handling data stored in XML and building an interacvite interface from it');
14	}
15
16	function get_user_interface()
17	{
18		$interface = array();
19
20		$allapps = $this->block->arguments['directory'];
21		//xmltool2 is a slightly modified version of phpgwapi.xmltool of HEAD
22		$xmltool = CreateObject('sitemgr.xmltool2');
23		$xmltool->import_xml($allapps);
24		$apparray = $xmltool->export_var();
25		$i = 0;
26		while (list(,$app) = @each($apparray['app']))
27		{
28			$element['label'] = '<hr>';
29			$element['form'] = '<hr>';
30			$interface[] = $element;
31			$element['label'] = '<b>'.$app['name'][0].'</b>';
32			$element['form'] = '';
33			$interface[] = $element;
34			foreach(array('name','maintainer','url','description') as $key)
35			{
36				$elementname = 'element[' . $this->block->version . '][' .$key . '][' . $i .']';
37				$element['label'] = ucfirst($key);
38				$element['form'] = $this->build_input_element(
39					array(
40						'type' => ($key == 'description') ? 'textarea' : 'textfield',
41						'params' => ($key == 'description') ? array('cols' => 50,'rows' => 15) : array('size' => 50)),
42					$app[$key][0],
43					$elementname
44				);
45				$interface[] = $element;
46			}
47			$element['label'] = lang('Delete this application');
48			$element['form'] = $this->build_input_element(
49				array('type' => 'checkbox'),
50				False,
51				'element[' . $this->block->version . '][delete][' . $i . ']'
52			);
53			$interface[] = $element;
54			$i++;
55		}
56		$element['label'] = '<hr>';
57		$element['form'] = '<hr>';
58		$interface[] = $element;
59		$element['label'] = lang('Add a new application');
60		$element['form'] = $this->build_input_element(
61			array('type' => 'checkbox'),
62			False,
63			'element[' . $this->block->version . '][addnew]'
64		);
65		$interface[] = $element;
66		return $interface;
67	}
68
69	function validate(&$data)
70	{
71		$xmltool = CreateObject('sitemgr.xmltool2','node','directory','');
72		$i = 0;
73		while (isset($data['name'][$i]))
74		{
75			if (!$data['delete'][$i])
76			{
77				$xmltool->import_var(
78					'app',
79					array(
80						'name' => $data['name'][$i],
81						'maintainer' => $data['maintainer'][$i],
82						'url'  => $data['url'][$i],
83						'description' => $data['description'][$i],
84					)
85				);
86			}
87			$i++;
88		}
89		if ($data['addnew'])
90		{
91			$xmltool->import_var(
92				'app',
93				array(
94					'name' => lang('New application'),
95					'maintainer' => lang('Maintainer'),
96					'url' => 'http://',
97					'description' => lang('Description')
98				)
99			);
100		}
101
102		$newdata['directory'] = $xmltool->export_xml();
103		$data = $newdata;
104		return true;
105	}
106
107	function set_block(&$block,$produce=False)
108	{
109		parent::set_block($block,$produce);
110
111		if ($produce)
112		{
113			require_once(PHPGW_INCLUDE_ROOT . SEP . 'sitemgr' . SEP . 'inc' . SEP . 'class.xslt_transform.inc.php');
114			$this->add_transformer(new xslt_transform($this->find_template_dir() . SEP . 'list.xsl'));
115		}
116	}
117
118	function get_content(&$arguments,$properties)
119	{
120		return $arguments['directory'];
121	}
122}
123