1<?php
2  /**************************************************************************\
3  * phpGroupWare - phpgroupware SiteMgr                                      *
4  * http://www.phpgroupware.org                                              *
5  * -----------------------------------------------                          *
6  *  This program is free software; you can redistribute it and/or modify it *
7  *  under the terms of the GNU General Public License as published by the   *
8  *  Free Software Foundation; either version 2 of the License, or (at your  *
9  *  option) any later version.                                              *
10  \**************************************************************************/
11
12  /* $Id: class.Sites_UI.inc.php 13089 2003-06-23 20:31:22Z totschnig $ */
13
14	//copied from class admin.uiservers
15	class Sites_UI
16	{
17		var $common_ui;
18		var $public_functions = array(
19			'list_sites' => True,
20			'edit'         => True,
21			'delete'       => True
22		);
23
24		var $start = 0;
25		var $query = '';
26		var $sort  = '';
27		var $order = '';
28
29		var $debug = False;
30
31		var $bo = '';
32		var $nextmatchs = '';
33
34		function Sites_UI()
35		{
36			$this->common_ui = CreateObject('sitemgr.Common_UI',True);
37			$this->bo = &$GLOBALS['Common_BO']->sites;
38			$this->nextmatchs = createobject('phpgwapi.nextmatchs');
39
40			$this->start = $this->bo->start;
41			$this->query = $this->bo->query;
42			$this->order = $this->bo->order;
43			$this->sort = $this->bo->sort;
44			if($this->debug) { $this->_debug_sqsof(); }
45			/* _debug_array($this); */
46		}
47
48		function _debug_sqsof()
49		{
50			$data = array(
51				'start' => $this->start,
52				'query' => $this->query,
53				'sort'  => $this->sort,
54				'order' => $this->order
55			);
56			echo '<br>UI:';
57			_debug_array($data);
58		}
59
60		function save_sessiondata()
61		{
62			$data = array(
63				'start' => $this->start,
64				'query' => $this->query,
65				'sort'  => $this->sort,
66				'order' => $this->order
67			);
68			$this->bo->save_sessiondata($data);
69		}
70
71		function list_sites()
72		{
73			$this->common_ui->DisplayHeader();
74
75			if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
76			{
77				$this->deny();
78			}
79
80			$GLOBALS['phpgw']->template->set_file(array('site_list_t' => 'listsites.tpl'));
81			$GLOBALS['phpgw']->template->set_block('site_list_t','site_list','list');
82
83			$GLOBALS['phpgw']->template->set_var('add_action',$GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Sites_UI.edit'));
84			$GLOBALS['phpgw']->template->set_var('lang_add',lang('Add'));
85			$GLOBALS['phpgw']->template->set_var('title_sites',lang('Sitemgr Websites'));
86			$GLOBALS['phpgw']->template->set_var('lang_search',lang('Search'));
87			$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Sites_UI.list_sites'));
88			$GLOBALS['phpgw']->template->set_var('lang_done',lang('Done'));
89			$GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/admin/index.php'));
90
91			if(!$this->start)
92			{
93				$this->start = 0;
94			}
95
96			$this->save_sessiondata();
97			$sites = $this->bo->list_sites();
98
99			$left  = $this->nextmatchs->left('/index.php',$this->start,$this->bo->total,'menuaction=sitemgr.Sites_UI.list_sites');
100			$right = $this->nextmatchs->right('/index.php',$this->start,$this->bo->total,'menuaction=sitemgr.Sites_UI.list_sites');
101
102			$GLOBALS['phpgw']->template->set_var(array(
103				'left' => $left,
104				'right' => $right,
105				'lang_showing' => $this->nextmatchs->show_hits($this->bo->total,$this->start),
106				'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
107				'lang_edit' => lang('Edit'),
108				'lang_delete' => lang('Delete'),
109				'sort_name' => $this->nextmatchs->show_sort_order(
110					$this->sort,'site_name',$this->order,'/index.php',lang('Name'),'&menuaction=sitemgr.Sites_UI.list_sites'
111				),
112				'sort_url' => $this->nextmatchs->show_sort_order(
113					$this->sort,'site_url',$this->order,'/index.php',lang('URL'),'&menuaction=sitemgr.Sites_UI.list_sites'
114				)
115			));
116
117			while(list($site_id,$site) = @each($sites))
118			{
119				$tr_color = $this->nextmatchs->alternate_row_color($tr_color);
120
121				$GLOBALS['phpgw']->template->set_var(array(
122					'tr_color' => $tr_color,
123					'site_name' => $GLOBALS['phpgw']->strip_html($site['site_name']),
124					'site_url' => $site['site_url'],
125					'edit' => $GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Sites_UI.edit&site_id=' . $site_id),
126					'lang_edit_entry' => lang('Edit'),
127					'delete' => $GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Sites_UI.delete&site_id=' . $site_id),
128					'lang_delete_entry' => lang('Delete')
129				));
130				$GLOBALS['phpgw']->template->parse('list','site_list',True);
131			}
132
133			$GLOBALS['phpgw']->template->parse('out','site_list_t',True);
134			$GLOBALS['phpgw']->template->p('out');
135			$this->common_ui->DisplayFooter();
136		}
137
138		/* This function handles add or edit */
139		function edit()
140		{
141			if ($_POST['done'])
142			{
143				return $this->list_sites();
144			}
145			$this->common_ui->DisplayHeader();
146
147			if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
148			{
149				$this->deny();
150			}
151			if ($_POST['delete'])
152			{
153				return $this->delete();
154			}
155
156			$site_id = get_var('site_id',array('POST','GET'));
157
158			$GLOBALS['phpgw']->template->set_file(array('form' => 'site_form.tpl'));
159			$GLOBALS['phpgw']->template->set_block('form','add','addhandle');
160			$GLOBALS['phpgw']->template->set_block('form','edit','edithandle');
161
162			if ($_POST['save'])
163			{
164				if (!$_POST['site']['name'])
165				{
166					$GLOBALS['phpgw']->template->set_var('message',lang('Please enter a name for that site !'));
167				}
168				elseif ($site_id)
169				{
170					$this->bo->update($site_id,$_POST['site']);
171					$GLOBALS['phpgw']->template->set_var('message',lang('Site %1 has been updated',$_POST['site']['_name']));
172				}
173				else
174				{
175					$site_id = $this->bo->add($_POST['site']);
176					$GLOBALS['phpgw']->template->set_var('message',lang('Site %1 has been added',$_POST['site']['_name']));
177				}
178			}
179			else
180			{
181				$GLOBALS['phpgw']->template->set_var('message','');
182			}
183			if ($site_id)
184			{
185				$site = $this->bo->read($site_id);
186			}
187
188			$GLOBALS['phpgw']->template->set_var('title_sites',$site_id ? lang('Edit Website') : lang('Add Website'));
189
190			$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Sites_UI.edit'));
191
192			$GLOBALS['phpgw']->template->set_var(array(
193				'lang_name' => lang('Site name'),
194				'lang_sitedir' => lang('Filesystem path to sitemgr-site directory'),
195				'lang_siteurl' => lang('URL to sitemgr-site'),
196				'lang_anonuser' => lang('Anonymous user\'s username'),
197				'lang_anonpasswd' => lang('Anonymous user\'s password'),
198				'note_name' => lang('This is only used as an internal name for the website.'),
199				'note_dir' => lang('This must be an absolute directory location.  <b>No trailing slash</b>.'),
200				'note_url' => lang('The URL must be absolute and end in a slash, for example http://mydomain.com/mysite/'),
201				'note_anonuser' => lang('If you haven\'t done so already, create a user that will be used for public viewing of the site.  Recommended name: anonymous.'),
202				'note_anonpasswd' => lang('Password that you assigned for the anonymous user account.'),
203				'note_adminlist' => lang('Select persons and groups that are entitled to configure the website.')
204			));
205
206			$GLOBALS['phpgw']->template->set_var('lang_adminlist',lang('Site administrators'));
207			$GLOBALS['phpgw']->template->set_var('lang_save',lang('Save'));
208			$GLOBALS['phpgw']->template->set_var('lang_add',lang('Add'));
209			$GLOBALS['phpgw']->template->set_var('lang_default',lang('Default'));
210			$GLOBALS['phpgw']->template->set_var('lang_reset',lang('Clear Form'));
211			$GLOBALS['phpgw']->template->set_var('lang_done',lang('Cancel'));
212			$GLOBALS['phpgw']->template->set_var('lang_delete',lang('Delete'));
213
214			$GLOBALS['phpgw']->template->set_var(array(
215				'site_name' => $site['site_name'],
216				'site_dir' => $site['site_dir'],
217				'site_url' => $site['site_url'],
218				'site_anonuser' => $site['anonymous_user'],
219				'site_anonpasswd' => $site['anonymous_passwd']
220			));
221			$GLOBALS['phpgw']->template->set_var('site_adminlist',$this->adminselectlist($site_id));
222			$GLOBALS['phpgw']->template->set_var('site_id',$site_id);
223
224			$GLOBALS['phpgw']->template->set_var(array(
225				'th'      => $GLOBALS['phpgw_info']['theme']['th_bg'],
226				'row_on'  => $GLOBALS['phpgw_info']['theme']['row_on'],
227				'row_off' => $GLOBALS['phpgw_info']['theme']['row_off']
228			));
229			if ($site_id)
230			{
231				$GLOBALS['phpgw']->template->parse('edithandle','edit');
232				$GLOBALS['phpgw']->template->set_var('addhandle','');
233			}
234			else
235			{
236				$GLOBALS['phpgw']->template->set_var('edithandle','');
237				$GLOBALS['phpgw']->template->parse('addhandle','add');
238			}
239			$GLOBALS['phpgw']->template->pparse('phpgw_body','form');
240			$this->common_ui->DisplayFooter();
241
242		}
243
244		function adminselectlist($site_id)
245		{
246			$accounts = $GLOBALS['phpgw']->accounts->get_list();
247			$admin_list = $this->bo->get_adminlist($site_id);
248
249			while (list($null,$account) = each($accounts))
250			{
251				$selectlist .= '<option value="' . $account['account_id'] . '"';
252 				if($admin_list[$account['account_id']] == SITEMGR_ACL_IS_ADMIN)
253				{
254					$selectlist .= ' selected="selected"';
255				}
256				$selectlist .= '>' . $account['account_firstname'] . ' ' . $account['account_lastname']
257										. ' [ ' . $account['account_lid'] . ' ]' . '</option>' . "\n";
258			}
259			return $selectlist;
260		}
261
262		function delete()
263		{
264			if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
265			{
266				$GLOBALS['phpgw']->common->phpgw_header();
267				echo parse_navbar();
268				$this->deny();
269			}
270
271			$site_id = get_var('site_id',array('POST','GET'));
272			if ($_POST['yes'] || $_POST['no'])
273			{
274				if ($_POST['yes'])
275				{
276					$this->bo->delete($site_id);
277				}
278				$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=sitemgr.Sites_UI.list_sites');
279			}
280			else
281			{
282				$GLOBALS['phpgw']->common->phpgw_header();
283				echo parse_navbar();
284
285				$site = $this->bo->read($site_id);
286
287				$GLOBALS['phpgw']->template->set_file(array('site_delete' => 'delete_common.tpl'));
288
289				$GLOBALS['phpgw']->template->set_var(array(
290					'form_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=sitemgr.Sites_UI.delete'),
291					'hidden_vars' => '<input type="hidden" name="site_id" value="' . $site_id . '"><script>document.yesbutton.yesbutton.focus()</script>',
292					'messages' => lang('Are you sure you want to delete site %1 and all its content? You cannot retrieve it if you continue.',$site['site_name']),
293					'no' => lang('No'),
294					'yes' => lang('Yes'),
295				));
296				$GLOBALS['phpgw']->template->pparse('phpgw_body','site_delete');
297			}
298		}
299
300		function deny()
301		{
302			echo '<p><center><b>'.lang('Access not permitted').'</b></center>';
303			$GLOBALS['phpgw']->common->phpgw_exit(True);
304		}
305	}
306?>
307