/
dirtydates_adm_plugin.php
274 lines (241 loc) · 8.45 KB
/
dirtydates_adm_plugin.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
################
## Include Admidio common for admidio-variables
################
require_once(substr(__FILE__, 0,strpos(__FILE__, 'adm_plugins')-1).'/adm_program/system/common.php');
#require_once(SERVER_PATH. '/adm_program/system/classes/formelements.php');
require_once(SERVER_PATH. '/adm_program/system/classes/tabletext.php');
require_once(dirname(__FILE__).'/admidio_db_dates_config.php');
$options['org_id']=$gCurrentOrganization->getValue('org_id');//set current orgid
if (!function_exists('print_dirtydates_menu')) {
function print_dirtydates_menu()
{
$plugin_folder='admidio-db-dates';
global $gCurrentUser;
$dirtydatesmenu = new Menu('dirtydatesmenu', 'Terminzuabsagen');
//Falls Datenbank nicht vorhanden Install-Skript starten
$dirtydatesmenu->addItem('dirtydates_show', '/adm_plugins/'.$plugin_folder.'/dirtydates_adm_plugin.php?dd_userid=overview',
'Terminübersicht', '/icons/lists.png');
if($gCurrentUser->getValue('usr_id')!=0)
{
$dirtydatesmenu->addItem('dirtydates_change', '/adm_plugins/'.$plugin_folder.'/dirtydates_adm_plugin.php?dd_userid='.$gCurrentUser->getValue('usr_id').'','Meine Anwesenheit ändern', '/icons/profile.png');
}
echo '<div id="plgDirtydates" class="admidio-plugin-content">';
echo $dirtydatesmenu->show();
echo '</div>';
}
}
if (!function_exists('dirtydates')) {
function dirtydates($userid,$options)
{
$formcallback=$_SERVER['REQUEST_URI'];
global $gCurrentUser;
$dd =new class_admidio_db_dates($options);
//--------------------------------
//Ansichts-Menü darstellen
$form="<form action=".$formcallback." method=post\n>";
$form.="<select size=\"1\" name=\"dd_userid\" class=\"eingabetext\">";
$form.= "<option value=\"" . "overview" . "\">";
$form.= "User auswählen";
$form.= "</option>\n";
foreach( $dd->users as $datensatz)
{
$form.= "<option value=\"" . $datensatz['usr_id'] . "\">";
$form.= $datensatz['first_name']." ".$datensatz['last_name']." (".$datensatz['birthday'].")";
$form.= "</option>\n";
}
$form.= "</select>\n";
$form.= "<input type=\"submit\" value=\"Los gehts !\">\n";
$form.= "<input type=\"submit\" name=\"overview\" value=\"Zurück zur Übersicht\">\n";
$form.= "</form>\n";
//-----------------------------------
//Status eines Users ändern
//-----------------------------------
if (isset($_REQUEST['status_changed']))
{
if(!(($gCurrentUser->getValue('usr_id')===($userid))||($gCurrentUser->editUsers() === true)))
{
return 'Not allowed!';
}
$changes=array();
foreach($_REQUEST as $key=>$value)
{
preg_match('/^status_new_([0-9]+)/', $key, $match);
if(!isset($match[1])){continue;}
$dateid=$match[1];
/*print_r($match);
echo $dateid." changed to ".$value."<br>";
*/
$changes[$dateid]['status']=intval($value);
$changes[$dateid]['comment']=htmlspecialchars($_REQUEST['status_new_comment_'.$dateid]);
}
$dd->save_status($userid,$changes);
//reload status
$dd->load_status();
//load overview
$userid='overview';
}
//------------------------------------
//Übersichtsmenü darstellen mit allen Usern und Daten
//------------------------------------
if($userid =='overview' or !isset($userid))
{
//tabelle erzeugen
$out="<table width=200 border=1>\n<tr>";
if(isset($options->group_field)){
$out.="<th>Gruppe</th>";
}
$out.="<th>Name</th>";
foreach( $dd->dates as $date)
{
$out.= "<th class=\"admidio_dirtydates_headline\" id=\"".$date['dat_id']."\">";
$out.= $date['dat_headline'];
$out.= "</th>";
$dataID[]=$date['dat_id'];
}
$out.= "</tr>\n<tr>";
if(isset($options->group_field)){$out.= "<td></td>";}
$out.= "<td>Termin</td>";
foreach($dd->dates as $date)
{
$time=strtotime($date['dat_begin']);
$out.= "<td class=\"admidio_dirtydates_time\" id=\"".$date['dat_id']."\">";
if (date('H:i',$time)=="00:00")
{
$out.= date('D, d.m.y',$time)."<br>?? Uhr";
}
else
{
$out.= date('D, d.m.y',$time)."<br>".date('H:i',$time).' Uhr';
}
$out.= "</td>";
}
$out.= "</tr>\n";
foreach( $dd->users as $user)
{
$out.= "<tr>";
if(isset($options->group_field)){ $out.= "<td>".$user['group_name']."</td>";}
if(!(($gCurrentUser->getValue('usr_id')===($user['usr_id']))||($gCurrentUser->editUsers() === true)))
{//only show name for others
$out.= "<td>".$user['first_name'].' '.$user['last_name']."</td>";
}else
{// for myself and admins show link
$out.= "<td><a href=".$_SELF."?dd_userid=".$user['usr_id'].">".$user['first_name'].' '.$user['last_name']."</a></td>";
}
for ($i = 0; $i < count($dataID); $i++) {
if(isset($dd->status[$user['usr_id']][$dataID[$i]]['dd_status']))
{
$status=$dd->status[$user['usr_id']][$dataID[$i]]['dd_status'];
}else{
$status=false;
}
if ($status==2) $out.= "<TD class=\"admidio_dirtydates_status\" BGCOLOR=red id=\"".$dataID[$i]."\">";
else if ($status==1)$out.= "<TD class=\"admidio_dirtydates_status\" BGCOLOR=green id=\"".$dataID[$i]."\">";
else if ($status==3 && $options['allow_maybe'])$out.= "<TD class=\"admidio_dirtydates_status\" BGCOLOR=yellow id=\"".$dataID[$i]."\">";
else $out.= "<TD id=\"".$dataID[$i]."\">";
if(!empty($dd->status[$user['usr_id']][$dataID[$i]]['dd_comment']))
{
$comment=$dd->status[$user['usr_id']][$dataID[$i]]['dd_comment'];
$out.='<abbr title="'.$comment.'">Info</abbr></td>';
}else{
$out.="</TD>";
}
}
$out.= "</tr>\n";
}
$out.= "</table>";
}
//------------------------------------
//Seite für Zu-/Absagen darstellen
//------------------------------------
else//user-änderungs-dialog anzeigen, wenn user ausgewählt wurde:
{
if(!(($gCurrentUser->getValue('usr_id')===($userid))||($gCurrentUser->editUsers() === true)))
{
return 'Not allowed!';
}
$user=$dd->get_user_by_id($userid);
if($user===false)
{
$out.=('<p>Fehler, User mit id "'.$userid.'" nicht gefunden!</p>');
return $out;
}
$out.= "<p><font size=+4 color=red>".$user['first_name']." ".$user['last_name']."</font></p>\n";
$out.= "<form action=".$formcallback." method=post>";
$out.= "<table border=1>\n";
$out.= "<tr><th>Termin</th><th>Datum</th><th>weitere Infos</th>";
if($options['allow_maybe'])
{
$out.= '<th>JA - ? - Nein - Reset</th>';
}else{
$out.= '<th>JA - Nein - Reset</th>';
}
$out.="<th>Kommentar</th></tr>";
foreach($dd->dates as $date)
{//pro termin eine reihe!
$time=strtotime($date['dat_begin']);
if(isset($dd->status[$userid][$date['dat_id']]))
{
$oldstatus=$dd->status[$userid][$date['dat_id']]['dd_status'];
}else{
$oldstatus=0;
}
$oldcomment=$dd->status[$userid][$date['dat_id']]['dd_comment'];
$checked_no='';
$checked_yes='';
$checked_perhaps='';
if ($oldstatus[0]==2) $checked_no='checked';
else if ($oldstatus[0]==1)$checked_yes='checked';
else if ($oldstatus[0]==3)$checked_perhaps='checked';
$out.= "\n<tr>";
$out.= "<td>".$date['dat_headline']."</td>";
$out.= "<td>".date('D, d.m.y </br> \u\m G:i',$time)."</td>";
$out.= "<td>".$date['dat_description']."</td>";
$out.= "<td><input type=radio name=status_new_".$date['dat_id']." value=1 ".$checked_yes.">";
if($options['allow_maybe'])
{
$out.= " <input type=radio name=status_new_".$date['dat_id']." value=3 ".$checked_perhaps.">";
}
$out.= " <input type=radio name=status_new_".$date['dat_id']." value=2 ".$checked_no.">";
$out.= " <input type=radio name=status_new_".$date['dat_id']." value=0 ></td>";
$out.= "<td><input type=text name=status_new_comment_".$date['dat_id']." value=\"".$oldcomment."\">";
$out.= "</tr>\n";
}
$out.= "</table>\n";
$out.= "<input type=hidden name=status_changed value=1>\n";
$out.= "<input type=hidden name=dd_userid value=".$userid.">\n";
$out.= "<input type=\"submit\" value=\"Änderungen speichern\">\n";
$out.= "</form>\n";
}
if($gCurrentUser->editUsers() === true)
{//only show form for admins
return $form.$out;
}
else
{
return $out;
}
}
}
if (isset($_REQUEST['dd_userid']))
{
$userid=$_REQUEST['dd_userid'];
unset($_REQUEST['dd_userid']);
//call dirtydates
require_once(dirname(__FILE__).'/class_admidio_db_dates.php');
$page = new HtmlPage('Dirtydates');
if($gCurrentUser->getValue('usr_id')==0){
$page->addHtml('Login required!');
}else{
$page->addHtml(dirtydates($userid,$options));
}
$page->show();
}else
{
if($gCurrentUser->getValue('usr_id')!=0){
print_dirtydates_menu();
}
//global $gCurrentUser;
//print_r($gCurrentUser);
}
//echo $formcallback;