summaryrefslogtreecommitdiff
path: root/adminCalendars.php
blob: 9baf259cdd9baa4ccebd82b281e6fcbf13dac2a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php

function infocalendar_get_admin_calendar_html() {
	global $wpdb;

	if(isset($_POST['pwViewSet']) || isset($_POST['pwViewDel'])) {
		if(!isset($_POST['pwViewID'])) {
			print('<font color="red">Du musst Eine Ansicht angeben</font><br>');
		} else if(isset($_POST['pwViewSet']) &&
			(!isset($_POST['pwViewPw']) || $_POST['pwViewPw'] == '')) {
			print('<font color="red">Du musst ein Passwort angeben</font><br>');
		} else {
			$viewID = (int) $_POST['pwViewID'];
			$pw = null;
			if(isset($_POST['pwViewSet'])) {
				$pw = password_hash($_POST['pwViewPw'], PASSWORD_BCRYPT);
			}
			
			$wpdb->query(
				$wpdb->prepare('UPDATE `wp_infocalendar_calendar` '.
					'SET `password` = %s WHERE id = %d', $pw, $viewID));
			
			?><p><font color='green'>Passwort geändert!</font></p><?php
		}
	}
	?>
	
	<h1>Kalenderansichten</h1>
	<table border='1' cellspacing='0' cellpadding='5' id='infocal_views'>
	<tr>
		<th>ID</th>
		<th>Name</th>
		<th>Passwort gesetzt</th>
		<th>iCal</th>
	</tr>
	
	<?php
	$viewList = $wpdb->get_results("SELECT * FROM 
		{$wpdb->prefix}infocalendar_calendar", 'ARRAY_A');
		
	foreach($viewList AS $view) {
		$pwSet = 'Nicht gesetzt';
		if($view['password'] != NULL)
			$pwSet = 'Gesetzt';
		
		$icalUrl = get_site_url().'?rest_route=/infocalendar/calendar/'.
			$view['name'];
		
		?>
		<tr>
			<td><?php echo $view['id']; ?></td>
			<td><?php echo $view['name']; ?></td>
			<td><?php echo $pwSet; ?></td>
			<td>
				<?php echo '<a href="'.$icalUrl.'">'.$icalUrl.'</a>'; ?>
			</td>
		</tr>
		<?php
	}
	?>
	</table>
	<h2>Passwort ändern/Löschen</h2>
	
	<form method='POST'>
	<label for='pwViewID'>ID:</label>
	<input type='number' name='pwViewID' id='pwViewID'><br>
	<label for='pwViewPw'>Passwort:</label>
	<input type='text' name='pwViewPw' id='pwViewPw'><br><br>
	<input type='submit' name='pwViewSet' value='Passwort setzen' bgcolor='green'>
	<br><br>
	<input type='submit' name='pwViewDel' value='Passwort löschen' bgcolor='red'>
	<?php
	
}

function infocalendar_add_view_admin_panel() {
	add_submenu_page(
		'infoCalendar',
		'Kaelenderansichten',
		'Ansichten',
		'publish_posts',
		'infoCalendarViews',
		'infocalendar_get_admin_calendar_html'
	);
}