1<?php
2/**
3 * Wiki farm animal manager class
4 *
5 * @license  GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author   Etienne MELEARD <etienne.meleard@cru.fr>
7 * @desc     Process and render animal management related requests
8 */
9
10// must be run under farm plugin context within Dokuwiki or SOAP context
11if(!defined('DOKU_FARMPLUGINLOADED') && !defined('DOKU_FARMPLUGINSOAPACTION')) die();
12if(!defined('DOKU_FARM_PLUGIN')) define('DOKU_FARM_PLUGIN', defined('DOKU_FARMPLUGINLOADED') ? DOKU_INC.'lib/plugins/farm/' : './');
13
14require_once(DOKU_FARM_PLUGIN.'animal.class.php');
15
16class dokuwiki_farm_animalmanager {
17	var $manager = null;
18	private $animal = null;
19
20	/**
21	 * @param $manager object that must handle error(), success(), nicesize(), getLang() ... calls
22	 */
23	function __construct($manager) {
24		$this->manager = & $manager;
25	}
26
27	/**
28	 * Builds and return a link inside animal manager
29	 * @param $opts array of farm options
30	 * @return url string
31	 */
32	function wl($opts = array()) {
33		$a = array_merge(array('aid' => $this->animal->getName()), $opts);
34		return $this->manager->wl('animal', $a);
35	}
36
37	/**
38	 * Process requests
39	 */
40	public function process() {
41		// Animal creation request
42		if(isset($this->manager->opt['new'])) {
43			if(isset($this->manager->opt['save'])) {
44				if(!checkSecurityToken()) {
45					$this->manager->error('system_errors', 'system_badtoken_failure');
46					return; // any changes done by post
47				}
48				if(isset($_POST['animal_name']) && !empty($_POST['animal_name'])) {
49					$tpl = (isset($_POST['animal_template']) && !empty($_POST['animal_template'])) ? $_POST['animal_template'] : null;
50					$host = (isset($_POST['animal_host']) && !empty($_POST['animal_host'])) ? $_POST['animal_host'] : null;
51					if($n = dokuwiki_farm_animal::createNew($_POST['animal_name'], $tpl, $host, $this)) {
52						$this->manager->success('animal_new_create_success');
53						unset($this->manager->opt['save']);
54						unset($this->manager->opt['new']);
55						$this->manager->opt['aid'] = $n;
56					}
57				}else{
58					$this->manager->error('animal_new_errors', 'animal_new_noname_failure');
59					return;
60				}
61			}else return;
62		}
63
64		// Animal selected check
65		if(!isset($this->manager->opt['aid'])) {
66			$this->manager->error('animal_errors', 'animal_noid_failure');
67			return;
68		}
69		if(!dokuwiki_farm_animal::exists($this->manager->opt['aid'])) {
70			$this->manager->error('animal_errors', array('code' => 'animal_unknownanimal_failure', 'data' => array($this->manager->opt['aid'])));
71			return;
72		}
73		$this->animal = new dokuwiki_farm_animal($this->manager->opt['aid'], $this->manager);
74
75		// Options check
76		if(
77			!isset($this->manager->opt['status']) &&
78			!isset($this->manager->opt['lockstate']) &&
79			!(isset($this->manager->opt['users']) && (isset($this->manager->opt['save']) || isset($this->manager->opt['deleteuser']))) &&
80			!(isset($this->manager->opt['editfile']) && isset($this->manager->opt['save']) && isset($this->manager->opt['file'])  && !empty($this->manager->opt['file'])) &&
81			!(isset($this->manager->opt['editfile']) && isset($this->manager->opt['create']) && isset($this->manager->opt['newfile'])  && !empty($this->manager->opt['file'])) &&
82			!(isset($this->manager->opt['delete']) && (isset($this->manager->opt['confirm']) || isset($this->manager->opt['cancel'])))
83		) return;
84
85		// Security check
86		if(!checkSecurityToken()) {
87			$this->manager->error('system_errors', 'system_badtoken_failure');
88			return; // any changes done by post
89		}
90
91		// Status change request
92		if(isset($this->manager->opt['status'])) {
93			$s = $this->manager->opt['status'];
94			if(in_array($s, array('open', 'maintenance', 'closed', 'abuse'))) {
95				if(!$this->animal->setMetadata('status', $s)) {
96					$this->manager->error('animal_status_errors', array('code' => 'animal_status_update_failure', 'data' => array($s)));
97				}else $this->manager->success('animal_status_update_success');
98			}
99		}
100		if(isset($this->manager->opt['lockstate'])) {
101			$s = $this->manager->opt['lockstate'];
102			if(in_array($s, array('', 'edits', 'admin', 'all'))) {
103				if(!$this->animal->setMetadata('lockstate', $s)) {
104					$this->manager->error('animal_status_errors', array('code' => 'animal_status_update_failure', 'data' => array($s)));
105				}else $this->manager->success('animal_status_update_success');
106			}
107		}
108
109		// User create request
110		if(isset($this->manager->opt['users']) && isset($this->manager->opt['save'])) {
111			if(!isset($_POST['new_animal_user_login']) || !isset($_POST['new_animal_user_pass']) || !isset($_POST['new_animal_user_name']) || !isset($_POST['new_animal_user_mail']) || !isset($_POST['new_animal_user_grps'])) {
112				$this->manager->error('animal_users_errors', 'postparametermissing_failure');
113			}elseif(empty($_POST['new_animal_user_login'])) {
114				$this->manager->error('animal_users_errors', array('code' => 'emptyfield_failure', 'data' => array($this->manager->getLang('animal_users_login'))));
115			}elseif(empty($_POST['new_animal_user_pass'])) {
116				$this->manager->error('animal_users_errors', array('code' => 'emptyfield_failure', 'data' => array($this->manager->getLang('animal_users_pass'))));
117			}elseif(empty($_POST['new_animal_user_mail'])) {
118				$this->manager->error('animal_users_errors', array('code' => 'emptyfield_failure', 'data' => array($this->manager->getLang('animal_users_mail'))));
119			}else{
120				if(empty($_POST['new_animal_user_name'])) $_POST['new_animal_user_name'] = $_POST['new_animal_user_login'];
121
122				$_POST['new_animal_user_login'] = preg_replace('/.*:/','',$_POST['new_animal_user_login']);
123				$_POST['new_animal_user_login'] = cleanID($_POST['new_animal_user_login']);
124				$_POST['new_animal_user_name'] = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['new_animal_user_name']));
125				$_POST['new_animal_user_mail'] = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['new_animal_user_mail']));
126
127				if(empty($_POST['new_animal_user_login'])) {
128					$this->manager->error('animal_users_errors', array('code' => 'invalidfield_failure', 'data' => array($this->manager->getLang('animal_users_login'))));
129				}elseif(empty($_POST['new_animal_user_pass'])) {
130					$this->manager->error('animal_users_errors', array('code' => 'invalidfield_failure', 'data' => array($this->manager->getLang('animal_users_pass'))));
131				}elseif(empty($_POST['new_animal_user_name'])) {
132					$this->manager->error('animal_users_errors', array('code' => 'invalidfield_failure', 'data' => array($this->manager->getLang('animal_users_name'))));
133				}elseif(empty($_POST['new_animal_user_mail']) || !mail_isvalid($_POST['new_animal_user_mail'])) {
134					$this->manager->error('animal_users_errors', array('code' => 'invalidfield_failure', 'data' => array($this->manager->getLang('animal_users_mail'))));
135				}elseif(!preg_match('`^\s*[a-z0-9_-]+(\s*,\s*[a-z0-9_-]+)*\s*$`i', $_POST['new_animal_user_grps'])) {
136					$this->manager->error('animal_users_errors', array('code' => 'invalidfield_failure', 'data' => array($this->manager->getLang('animal_users_grps'))));
137				}else{
138					if($this->animal->addUser($_POST['new_animal_user_login'], $_POST['new_animal_user_pass'], $_POST['new_animal_user_name'], $_POST['new_animal_user_mail'], array_map('trim', explode(',', $_POST['new_animal_user_grps'])))) {
139						$this->manager->success('animal_users_add_success');
140					}else $this->manager->error('animal_users_errors', 'animal_users_add_create_failure');
141				}
142
143			}
144		}
145
146		// User delete request
147		if(isset($this->manager->opt['users']) && isset($this->manager->opt['deleteuser'])) {
148			if($this->animal->deleteUser(base64_decode($this->manager->opt['deleteuser']))) {
149				$this->manager->success('animal_users_delete_success');
150			}else $this->manager->error('animal_users_errors', 'animal_users_delete_failure');
151		}
152
153		// File edition request
154		if(isset($this->manager->opt['editfile']) && isset($this->manager->opt['save']) && isset($this->manager->opt['file'])  && !empty($this->manager->opt['file'])) {
155			if(isset($this->manager->opt['editfile_delete'])) {
156				if($this->animal->setFileContent(base64_decode($this->manager->opt['file']), '', true)) {
157					$this->manager->success('animal_editfile_delete_success');
158					$this->manager->opt['file'] = null;
159				}else $this->manager->error('animal_editfile_errors', 'animal_editfile_delete_failure');
160			}elseif(isset($_POST['animal_file']) && (isset($this->manager->opt['editfile_saveempty']) || !empty($_POST['animal_file']))) {
161				if($this->animal->setFileContent(base64_decode($this->manager->opt['file']), isset($this->manager->opt['editfile_saveempty']) ? '' : $_POST['animal_file'])) {
162					$this->manager->success('animal_editfile_save_success');
163				}else $this->manager->error('animal_editfile_errors', 'animal_editfile_save_failure');
164			}else $this->manager->error('animal_editfile_errors', 'animal_editfile_save_failure');
165		}
166		if(isset($this->manager->opt['editfile']) && isset($this->manager->opt['create']) && isset($this->manager->opt['newfile'])  && !empty($this->manager->opt['file'])) {
167			if($this->animal->setFileContent($this->manager->opt['file'], '')) {
168				$this->manager->success('animal_editfile_save_success');
169				$this->manager->opt['file'] = base64_encode($this->manager->opt['file']);
170			}else $this->manager->error('animal_editfile_errors', 'animal_editfile_save_failure');
171		}
172
173		// Animal delete request
174		if(isset($this->manager->opt['delete']) && isset($this->manager->opt['cancel'])) {
175			if(isset($this->manager->opt['confirm'])) unset($this->manager->opt['confirm']);
176			unset($this->manager->opt['delete']);
177		}
178		if(isset($this->manager->opt['delete']) && isset($this->manager->opt['confirm'])) {
179			if($this->animal->getName() == $this->manager->conf['animaltemplate']) {
180				$this->manager->error('animal_delete_errors', array('code' => 'animal_delete_tpl_failure', 'data' => $this->manager->conf['animaltemplate']));
181			}elseif($this->animal->delete()) {
182				$this->manager->success('animal_delete_success');
183				$this->animal = null;
184				unset($this->manager->opt['delete']);
185				unset($this->manager->opt['confirm']);
186				unset($this->manager->opt['aid']);
187			}else $this->manager->error('animal_delete_errors', array('code' => 'animal_delete_failure', 'data' => $this->animal->getName()));
188		}
189	}
190
191	/**
192	 * Renders header outputed before error / success section
193	 */
194	public function htmlheader() {
195		$displaydefault = !isset($this->manager->opt['config']) && !isset($this->manager->opt['users']) && !isset($this->manager->opt['editfile']) && !isset($this->manager->opt['delete']);
196
197		// Pannel menu
198		if($this->animal) {
199			ptln('<div class="animal_hud">');
200			ptln('	<a '.($displaydefault ? 'class="current_action"' : '').' href="'.$this->wl().'" title="'.$this->manager->getLang('animal_infos').'"><img src="'.DOKU_FARM_WWW.'images/chart.png" alt="infos" /></a>');
201			ptln('	<a '.(isset($this->manager->opt['users']) ? 'class="current_action"' : '').' href="'.$this->wl(array('users' => true)).'" title="'.$this->manager->getLang('animal_users').'"><img src="'.DOKU_FARM_WWW.'images/users.png" alt="users" /></a>');
202			ptln('	<a '.(isset($this->manager->opt['editfile']) ? 'class="current_action"' : '').' href="'.$this->wl(array('editfile' => true)).'" title="'.$this->manager->getLang('animal_editfile').'"><img src="'.DOKU_FARM_WWW.'images/edit.png" alt="edit file" /></a>');
203			ptln('	<a '.(isset($this->manager->opt['delete']) ? 'class="current_action"' : '').' href="'.$this->wl(array('delete' => true)).'" title="'.$this->manager->getLang('animal_delete').'"><img src="'.DOKU_FARM_WWW.'images/delete.png" alt="delete animal" /></a>');
204			ptln('	<a href="'.$this->animal->getUrl().'" target="_blank" title="'.$this->manager->getLang('visitanimal').'"><img src="'.DOKU_FARM_WWW.'images/www.png" alt="visit" /></a>');
205			ptln('</div>');
206		}
207	}
208
209	/**
210	 * Renders
211	 */
212	public function html() {
213		$displaydefault = !isset($this->manager->opt['config']) && !isset($this->manager->opt['users']) && !isset($this->manager->opt['editfile']) && !isset($this->manager->opt['delete']);
214
215		// Animal infos
216		if($displaydefault && $this->animal) {
217			ptln('		<div class="animal_info">');
218			if($this->manager->conf['animalmaxsize'] > 0) {
219				$s = $this->animal->getInfos()->getSize('all', false);
220				$p = $s / $this->manager->conf['animalmaxsize'];
221				if($p > 1) $p == 1;
222				$g = min(255, 511 - round($p * 511));
223				$r = min(255, round(511 * $p));
224				ptln('			'.$this->manager->getLang('animal_info_size').' : <span class="size_disp" style="background-color:rgb('.$r.','.$g.',0)">'.round(100 * $p).'% ('.$this->manager->nicesize($s).' / '.$this->manager->nicesize($this->manager->conf['animalmaxsize']).')</span><br />');
225			}
226			if($this->manager->conf['animalmaxsize'] <= 0) ptln('			'.$this->manager->getLang('animal_info_size').' : '.$this->animal->getInfos()->getSize('all', true).'<br />');
227
228			$status = $this->animal->getInfos()->getStatus();
229			if($status == '') $status = 'open';
230			ptln('			'.$this->manager->getLang('animal_info_status').' : <select onmouseover="if(!this.i)this.i=this.selectedIndex+1;" onchange="if(confirm(\''.$this->manager->getLang('animal_info_setstatus_confirm', null, 'js').'\')) document.location=\''.$this->wl().'&amp;farm_opt__status=\'+this.value+\'&amp;sectok='.getSecurityToken().'\'; else if(this.i)this.selectedIndex=this.i-1;">');
231			ptln('				<option '.($status == 'open' ? 'selected="selected"' : '').' value="open">'.$this->manager->getLang('animal_status_open').'</option>');
232			ptln('				<option '.($status == 'maintenance' ? 'selected="selected"' : '').' value="maintenance">'.$this->manager->getLang('animal_status_maintenance').'</option>');
233			ptln('				<option '.($status == 'closed' ? 'selected="selected"' : '').' value="closed">'.$this->manager->getLang('animal_status_closed').'</option>');
234			ptln('				<option '.($status == 'abuse' ? 'selected="selected"' : '').' value="abuse">'.$this->manager->getLang('animal_status_abuse').'</option>');
235			ptln('			</select><br />');
236
237			$lockstate = $this->animal->getInfos()->getLockState();
238			ptln('			'.$this->manager->getLang('animal_info_lockstate').' : <select onmouseover="if(!this.i)this.i=this.selectedIndex+1;" onchange="if(confirm(\''.$this->manager->getLang('animal_info_setlockstate_confirm', null, 'js').'\')) document.location=\''.$this->wl().'&amp;farm_opt__lockstate=\'+this.value+\'&amp;sectok='.getSecurityToken().'\'; else if(this.i)this.selectedIndex=this.i-1;">');
239			ptln('				<option '.($lockstate == '' ? 'selected="selected"' : '').' value="">'.$this->manager->getLang('animal_lockstate_none').'</option>');
240			ptln('				<option '.($lockstate == 'edits' ? 'selected="selected"' : '').' value="edits">'.$this->manager->getLang('animal_lockstate_edits').'</option>');
241			ptln('				<option '.($lockstate == 'admin' ? 'selected="selected"' : '').' value="admin">'.$this->manager->getLang('animal_lockstate_admin').'</option>');
242			ptln('				<option '.($lockstate == 'all' ? 'selected="selected"' : '').' value="all">'.$this->manager->getLang('animal_lockstate_all').'</option>');
243			ptln('			</select><br />');
244
245			ptln('			'.$this->manager->getLang('animal_info_creation').' : '.$this->animal->getInfos()->getCreation(true).'<br />');
246			ptln('			<br />');
247			foreach($this->animal->getInfos()->pagesInfo(true) as $k => $i) {
248				ptln('			'.$this->manager->getLang('animal_info_pages'.$k).' : '.$i.'<br />');
249			}
250			ptln('			<br />');
251			foreach($this->animal->getInfos()->mediasInfo(true) as $k => $i) {
252				ptln('			'.$this->manager->getLang('animal_info_medias'.$k).' : '.$i.'<br />');
253			}
254			ptln('			<br />');
255			ptln('			'.$this->manager->getLang('animal_info_cachesize').' : '.$this->animal->getInfos()->getSize('cache', true).'<br />');
256			ptln('			'.$this->manager->getLang('animal_info_indexsize').' : '.$this->animal->getInfos()->getSize('index', true).'<br />');
257			ptln('		</div>');
258		}
259
260		// Animal users
261		if(isset($this->manager->opt['users']) && $this->animal) {
262			ptln('<div class="farm_cmd_title">');
263			ptln('	'.$this->manager->getLang('animal_users'));
264			ptln('</div>');
265
266			ptln('<div class="farm_cmd_info">');
267			ptln('	'.$this->manager->getLang('animal_users_warning'));
268			ptln('</div>');
269
270			$sort = isset($this->manager->opt['sort']) ? $this->manager->opt['sort'] : 'name';
271			$grp = isset($this->manager->opt['grp']) ? $this->manager->opt['grp'] : null;
272			$users = $this->animal->getUsers();
273			switch($sort) {
274				case 'name' : uasort($users, create_function('$a,$b', 'return strcmp($a[\'name\'], $b[\'name\']);')); break;
275				case 'namedesc' : uasort($users, create_function('$a,$b', 'return -1 * strcmp($a[\'name\'], $b[\'name\']);')); break;
276			}
277
278			if($grp) ptln($this->manager->getLang('animal_users_onlygrpactive').' : '.$grp.' [<a href="'.$this->wl(array('users' => true, 'grp' => '', 'sort' => $sort)).'">X</a>]');
279			ptln('<table>');
280			ptln('	<tr>');
281			ptln('		<th>'.$this->manager->getLang('animal_users_login').' <a href="'.$this->wl(array('users' => true, 'grp' => $grp, 'sort' => $sort == 'name' ? 'namedesc' : 'name')).'" title="'.$this->manager->getLang('animal_users_sortname').'"><img src="'.DOKU_FARM_WWW.'images/arrow_'.($sort == 'name' ? 'up' : 'down').'.png" alt="sort" /></a></th>');
282			ptln('		<th>'.$this->manager->getLang('animal_users_name').'</th>');
283			ptln('		<th>'.$this->manager->getLang('animal_users_mail').'</th>');
284			ptln('		<th>'.$this->manager->getLang('animal_users_grps').'</th>');
285			ptln('		<th>&nbsp;</th>');
286			ptln('	</tr>');
287			foreach($this->animal->getUsers() as $l => $u) {
288				$grps = array();
289				if($grp && !in_array($grp, $u['grps'])) continue;
290				foreach($u['grps'] as $g) $grps[] = '<a href="'.$this->wl(array('users' => true, 'grp' => $g)).'" title="'.$this->manager->getLang('animal_users_onlygrp').'">'.$g.'</a>';
291				ptln('	<tr>');
292				ptln('		<td>'.$l.'</td>');
293				ptln('		<td>'.$u['name'].'</td>');
294				ptln('		<td><a href="mailto:'.$u['mail'].'">'.$u['mail'].'</a></td>');
295				ptln('		<td>'.implode(', ', $grps).'</td>');
296				ptln('		<td><input type="image" src="'.DOKU_FARM_WWW.'images/delete.png" onclick="if(confirm(\''.$this->manager->getLang('animal_users_reallydeleteuser', $l, 'js').'\')) document.location=\''.$this->wl(array('users' => true, 'deleteuser' => base64_encode($l))).'&amp;sectok='.getSecurityToken().'\';" title="'.$this->manager->getLang('animal_users_deleteuser').'" /></td>');
297				ptln('	</tr>');
298			}
299			ptln('</table>');
300
301			$this->manager->formHead(array('farm_cmd' => 'animal', 'farm_opt[aid]' => $this->animal->getName(), 'farm_opt[users]' => true));
302			ptln('	<br /><b>'.$this->manager->getLang('animal_users_add').'</b><br />');
303			ptln('	'.$this->manager->getLang('animal_users_login').' : <input type="text" name="new_animal_user_login" value="'.(isset($_POST['new_animal_user_login']) ? $_POST['new_animal_user_login'] : '').'" /><br />');
304			ptln('	'.$this->manager->getLang('animal_users_pass').' : <input type="text" name="new_animal_user_pass" value="'.(isset($_POST['new_animal_user_pass']) ? $_POST['new_animal_user_pass'] : '').'" /><br />');
305			ptln('	'.$this->manager->getLang('animal_users_name').' : <input type="text" name="new_animal_user_name" value="'.(isset($_POST['new_animal_user_name']) ? $_POST['new_animal_user_name'] : '').'" /><br />');
306			ptln('	'.$this->manager->getLang('animal_users_mail').' : <input type="text" name="new_animal_user_mail" value="'.(isset($_POST['new_animal_user_mail']) ? $_POST['new_animal_user_mail'] : '').'" /><br />');
307			ptln('	'.$this->manager->getLang('animal_users_grps').' : <input type="text" name="new_animal_user_grps" value="'.(isset($_POST['new_animal_user_grps']) ? $_POST['new_animal_user_grps'] : '').'" /><br />');
308			ptln('	<input type="submit" name="farm_opt[save]" value="'.$this->manager->getLang('btn_create').'" />');
309			ptln('</form>');
310		}
311
312		// Animal edit file
313		if(isset($this->manager->opt['editfile']) && $this->animal) {
314			ptln('<div class="farm_cmd_title">');
315			ptln('	'.$this->manager->getLang('animal_editfile'));
316			ptln('</div>');
317
318			ptln('<div class="farm_cmd_info">');
319			ptln('	'.$this->manager->getLang('animal_change_warning'));
320			ptln('</div>');
321
322			$file = isset($this->manager->opt['file']) ? base64_decode($this->manager->opt['file']) : null;
323			$file = @file_exists($this->animal->getPath().'/'.$file) ? $file : null;
324			$f64 = $file ? base64_encode($file) : null;
325
326			ptln('<div id="animal_fs" openned="'.$f64.'">');
327			ptln('	'.$this->manager->getLang('animal_editfile_fs', $this->animal->getName()));
328			foreach($this->animal->getFs() as $r64 => $i) {
329				ptln('	<div class="animal_'.$i['type'].' '.($f64 == $r64 && $i['type'] == 'file' ? 'animal_file_current' : '').'" ref="'.$r64.'" pref="'.$i['pref'].'" lvl="'.$i['lvl'].'" style="margin-left:'.($i['lvl'] * 16).'px">');
330				if($i['type'] == 'file') ptln('<a href="'.$this->wl(array('editfile' => true, 'file' => $r64)).'#animal_editfile">');
331				ptln($i['name']);
332				if($i['type'] == 'file') ptln('</a>');
333				if($i['type'] == 'file') {
334					ptln('<div class="file_infos">('.$this->animal->getInfos()->formatedprint($this->manager->getLang('file_info'), array('size' => $i['size'], 'date' => $i['mtime'], 'dformat' => $conf['dformat'])).')</div>');
335				}
336				ptln('</div>');
337			}
338			ptln('</div>');
339			$this->manager->formHead(array('farm_cmd' => 'animal', 'farm_opt[aid]' => $this->animal->getName(), 'farm_opt[editfile]' => true, 'farm_opt[newfile]' => true));
340			ptln($this->manager->getLang('animal_editfile_create').' : <input type="text" id="editfile_path" name="farm_opt[file]" value="" />');
341			ptln(' <input type="submit" name="farm_opt[create]" value="'.$this->manager->getLang('btn_create').'" />');
342			ptln('</form>');
343
344			if($file) {
345				$this->manager->formHead(array('farm_cmd' => 'animal', 'farm_opt[aid]' => $this->animal->getName(), 'farm_opt[editfile]' => true, 'farm_opt[file]' => base64_encode($file)));
346				ptln('	<a name="animal_editfile"></a>'.$this->manager->getLang('animal_editfile_file', $file).'<br />');
347				ptln('	<textarea name="animal_file" rows="15" cols="80">'.$this->animal->getFileContent($file).'</textarea><br />');
348				ptln('	<input type="checkbox" name="farm_opt[editfile_saveempty]" /> '.$this->manager->getLang('animal_editfile_saveempty').'<br />');
349				ptln('	<input type="checkbox" name="farm_opt[editfile_delete]" /> '.$this->manager->getLang('animal_editfile_delete').'<br />');
350				ptln('	<input type="submit" name="farm_opt[save]" value="'.$this->manager->getLang('btn_save').'" />');
351				ptln('</form>');
352			}
353		}
354
355		// New animal
356		if(isset($this->manager->opt['new'])) {
357			ptln('<div class="farm_cmd_title">');
358			ptln('	'.$this->manager->getLang('animal_new_title'));
359			ptln('</div>');
360
361			$this->manager->formHead(array('farm_cmd' => 'animal', 'farm_opt[new]' => 1));
362			ptln('	'.$this->manager->getLang('animal_new_name').' : <i>'.$this->manager->conf['farmwebroot'].'</i><input name="animal_name" value="" /><br />');
363			ptln('	'.$this->manager->getLang('animal_new_template').' : <select name="animal_template">');
364			foreach(dokuwiki_farm_animal::listAnimals() as $a) ptln('		<option '.($a->getName() == $this->manager->conf['animaltemplate'] ? 'selected="selected"' : '').' value="'.$a->getName().'">'.$a->getName().'</option>');
365			ptln('	</select><br />');
366			if($this->manager->conf['virtual']) ptln('	'.$this->manager->getLang('animal_new_host').' : <input name="animal_host" value="" /><br />');
367			ptln('	<input type="submit" name="farm_opt[save]" value="'.$this->manager->getLang('btn_create').'" />');
368			ptln('</form>');
369		}
370
371		// Delete animal
372		if(isset($this->manager->opt['delete'])) {
373			ptln('<div class="farm_cmd_title">');
374			ptln('	'.$this->manager->getLang('animal_delete'));
375			ptln('</div>');
376
377			$this->manager->formHead(array('farm_cmd' => 'animal', 'farm_opt[aid]' => $this->animal->getName(), 'farm_opt[delete]' => 1));
378			ptln('	'.$this->manager->getLang('animal_delete_sure', $this->animal->getName()).' <input type="submit" name="farm_opt[confirm]" value="'.$this->manager->getLang('btn_confirm').'" /> <input type="submit" name="farm_opt[cancel]" value="'.$this->manager->getLang('btn_cancel').'" />');
379			ptln('</form>');
380		}
381
382		ptln('<div class="farm_cmd_footer"></div>');
383	}
384}
385
386?>
387