forked from craigk5n/webcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.php
164 lines (148 loc) · 5.67 KB
/
category.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
<?php
require_once 'includes/init.php';
// Load user and global cats.
load_user_categories();
if ($CATEGORIES_ENABLED == 'N') {
send_to_preferred_view();
exit;
}
$catIcon = $catname = $error = $idStr = '';
$catIconStr = translate('Category Icon');
$globalStr = translate('Global');
// If editing, make sure they are editing their own (or they are an admin user).
if (!empty($id)) {
if (empty($categories[$id]))
$error =
str_replace('XXX', $id, translate('Invalid entry id XXX.'));
$catcolor = $categories[$id]['cat_color'];
$catname = $categories[$id]['cat_name'];
$catowner = $categories[$id]['cat_owner'];
$catmime = $categories[$id]['cat_icon_mime'];
$catIcon = empty($catmime) ? '' : 'getIcon.php?cat_id=' . $id;
$idStr = '<input name="id" type="hidden" value="' . $id . '">';
} else
$catcolor = '#000000';
$showIconStyle = (!empty($catmime) ? '' : 'display: none;');
print_header(['js/visible.php']);
echo '
<h2>' . translate('Categories') . '</h2>
' . display_admin_link(false);
$add = getGetValue('add');
if (empty($add))
$add = 0;
// Adding/Editing category.
if ((($add == '1') || (!empty($id))) && empty($error)) {
echo '
<form action="category_handler.php" method="post" name="catform" '
. 'enctype="multipart/form-data">' . csrf_form_key() . $idStr . '
<div class="form-inline">
<label class="col-sm-3 col-form-label" for="catname">' . translate('Category Name') . '</label>
<input class="form-control" type="text" name="catname" size="20" value="'
. htmlspecialchars($catname) . '"></div>' .
($is_admin && empty($id) ? '
<div class="form-inline"><label class="col-sm-3 col-form-label" for="isglobal">'
. $globalStr . ":</label>"
. print_radio('isglobal', '', '', (empty($catowner) && !empty($id)) ? 'Y' : 'N', '') .
'</div>' : '') .
'<div class="form-inline">
<label class="col-sm-3 col-form-label" for="catname">' . translate('Color') . ':</label>'
. print_color_input_html('catcolor', translate('Color'), $catcolor) .
'</div>';
// Category icon
echo '
<div class="form-inline" id="cat_icon" style="' . $showIconStyle . '">
<label class="col-sm-3 col-form-label" for="catname">' . translate('Category Icon') . ':</label>
<img src="' . $catIcon . '" name="urlpic" id="urlpic" alt="' . $catIconStr . '"></div>
<div id="remove_icon" class="form-inline" style="' . $showIconStyle . '">
<label class="col-sm-3 col-form-label" for="delIcon">' . translate('Remove Icon') . '</label>
<input type="checkbox" name="delIcon" value="Y"></div>
<div class="form-inline">
<label class="col-sm-3 col-form-label" for="FileName">'
. (($ENABLE_ICON_UPLOADS === 'Y' || $is_admin)
? translate('Add Icon to Category') . ':</label>
<input class="form-control" type="file" name="FileName" id="fileupload" size="45" '
. 'maxlength="50" value="">
<small class="ml-2">('
. translate('GIF or PNG 6kb max') . ')</small>
</div>
<div class="form-inline p-1">
<input type="hidden" id="urlname" name="urlname" size="50">
<button class="btn btn-secondary openBtn" type="button">'
. translate ( 'Search for existing icons...' ) . '</button>
</div>' : '' ) . '
<div class="form-inline">
<button class="form-control btn btn-primary" name="action" type="submit">'
. ( $add === '1' ? translate ( 'Add' ) : translate ( 'Save' ) )
. '</button>'
. '<a href="category.php" class="form-control btn btn-secondary ml-1">Cancel</a> '
. (!empty($id) ? '
<button class="form-control btn btn-danger ml-1" name="delete" '
. 'type="submit" onclick="return confirm('
. translate ( 'Are you sure you want to delete this entry?', true )
. '\')">' . translate ( 'Delete' ) . '</button>' : '' ) . '
</div>
</form>';
} else
if (empty($error)) {
// Displaying Categories.
$global_found = false;
//echo "<pre>"; print_r($categories); echo "</pre>";
if (!empty($categories)) {
echo '
<ul>';
foreach ($categories as $K => $V) {
if ($K < 1)
continue;
$catStr = '<span style="color: '
. (!empty($V['cat_color']) ? $V['cat_color'] : '#000000')
. ';">' . htmlentities($V['cat_name']) . '</span>';
echo '
<li>' . ($V['cat_owner'] == $login || $is_admin
? '<a href="category.php?id=' . $K . '">' . $catStr . '</a>' : $catStr);
if (empty($V['cat_owner'])) {
echo '<sup>*</sup>';
$global_found = true;
}
if (!empty($V['cat_icon_mime'])) {
echo '<img src="getIcon.php?cat_id=' . $K . '" alt="'
. $catIconStr . '" title="' . $catIconStr . '">';
}
echo '</li>';
}
echo '
</ul>';
}
echo ($global_found ? '<sup>*</sup> ' . $globalStr : '') . '
<br><div class="p-2"><a class="btn btn-primary" href="category.php?add=1">' . translate('Make New Category')
. '</a></div><br>';
}
?>
<!-- Icon selection modal -->
<div class="modal fade" id="iconmodal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"><?php etranslate('Current Icons'); ?></h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button class="btn btn-default" id="modalclosebtn" data-dismiss="modal"
type="button"><?php etranslate ( 'Close' ); ?></button>
</div>
</div>
</div>
</div>
<script>
$('.openBtn').on('click', function() {
$('.modal-body').load('icons.php', function() {
$('#iconmodal').modal({
show: true
});
});
});
</script>
<?php
echo (!empty($error) ? print_error($error) : '') . print_trailer();
?>