list.php (5514B)
1 <?php
2
3 function list_notes(
4 string $user,
5 string $category = ""
6 ) {
7
8 /* gather note paths, based on given category */
9 $filenames = gather_notes($user, $category);
10
11 /* Sort filenames by edit timestamp */
12 usort($filenames, "sort_by_time");
13
14 /* prepare headline content */
15 if (empty($category)) {
16 $category_head = $GLOBALS["i18n_list"];
17 } else {
18 $category_head = $category;
19 }
20 $category_head = $category_head . " (" . count($filenames) . " " .
21 $GLOBALS["i18n_notes"] . ")";
22
23 ?>
24
25 <!-- Headline -->
26 <h4><?php echo $GLOBALS["i18n_category"] . ": " . $category_head; ?></h4>
27
28 <?php
29
30
31 /* loop through each filename and draw a table row */
32 foreach ($filenames as $filename) {
33
34 /* create id for list item */
35 $note_id = base64_encode(
36 $filename["category"] . "_" . $filename["name"]
37 );
38 ?>
39
40 <!-- note list item -->
41 <div id="<?php echo $note_id; ?>" class="list_item">
42
43 <?php
44 /* if note starts with an URL, link it in the title
45 * otherwise just print the title */
46 if ($filename["link"] !== false) {
47 ?>
48 <a href="<?php echo $filename["link"]; ?>" target="_blank">
49 <strong><?php echo $filename["name"]; ?></strong>
50 </a><br>
51
52 <?php } else { ?>
53 <strong><?php echo $filename["name"]; ?></strong><br>
54 <?php } ?>
55
56 <!-- date marker -->
57 <span class="inline">
58 <?php echo date("Y-m-d H:i:s", $filename["time"]); ?>
59 </span>
60
61 <!-- separator -->
62 <span class="inline">|</span>
63
64 <!-- category button -->
65 <form action="/" target="_self" method="post" class="inline">
66 <input
67 id="category"
68 name="category"
69 type="hidden"
70 value="<?php echo $filename["category"]; ?>"
71 >
72 <input
73 id="action"
74 name="action"
75 type="hidden"
76 value="list"
77 >
78 <input
79 type="submit"
80 class="likeanchor"
81 value="<?php echo $filename["category"]; ?>"
82 >
83 </form>
84
85 <!-- separator -->
86 <span class="inline">|</span>
87
88 <!-- edit button -->
89 <form action="/" method="post" class="inline">
90 <input
91 id="category"
92 name="category"
93 type="hidden"
94 value="<?php echo $filename["category"]; ?>"
95 >
96 <input
97 id="filename"
98 name="filename"
99 type="hidden"
100 value="<?php echo $filename["name"] . ".txt"; ?>"
101 >
102 <input
103 id="action"
104 name="action"
105 type="hidden"
106 value="show"
107 >
108 <input
109 type="submit"
110 class="likeanchor"
111 value="<?php echo $GLOBALS["i18n_edit"]; ?>"
112 >
113 </form>
114
115 <!-- separator -->
116 <span class="inline">|</span>
117
118 <!-- delete button -->
119 <form
120 action="/"
121 method="post"
122 id="<?php echo "del_" . $note_id; ?>"
123 class="inline"
124 >
125 <input
126 id="category"
127 name="category"
128 type="hidden"
129 value="<?php echo $filename["category"]; ?>"
130 >
131 <input
132 id="filename"
133 name="filename"
134 type="hidden"
135 value="<?php echo $filename["name"] . ".txt"; ?>"
136 >
137 <input
138 id="action"
139 name="action"
140 type="hidden"
141 value="delete"
142 >
143 <input
144 class="danger likeanchor"
145 type="button"
146 value="<?php echo $GLOBALS["i18n_delete"]; ?>"
147 onclick="deletion_confirm('<?php echo "del_" . $note_id; ?>');"
148 >
149 </form>
150
151 </div>
152
153 <?php
154
155 } // foreach-loop
156
157 } // function
158
159 function list_categories(
160 string $user
161 ) {
162
163 /* Gather all categories */
164 $categories = gather_categories($user);
165
166 ?>
167
168 <!-- Headline -->
169 <h4><?php echo $GLOBALS["i18n_categories"]; ?></h4>
170
171 <div class="inline">
172
173 <?php
174
175 /* loop through each category and print its item */
176 foreach ($categories as $category) {
177
178 /* Skip categories that have no notes */
179 if ($category["matches"] < 1) {
180 continue;
181 }
182
183 /* create button label */
184 if (!empty($category["name"])) {
185 $btn_label = $category["name"] . ": " . $category["matches"] .
186 " " . $GLOBALS["i18n_notes"];
187 } else {
188 $btn_label = $GLOBALS["i18n_list"] . ": " . $category["matches"] .
189 " " . $GLOBALS["i18n_notes"];
190 }
191
192 ?>
193
194 <!-- Category button -->
195 <form action="/" target="_self" method="post" class="inline">
196 <input
197 id="category"
198 name="category"
199 type="hidden"
200 value="<?php echo $category["name"]; ?>"
201 >
202 <input
203 id="action"
204 name="action"
205 type="hidden"
206 value="list"
207 >
208 <input
209 type="submit"
210 value="<?php echo $btn_label; ?>"
211 >
212 </form>
213
214 <?php
215
216 } // foreach-loop
217
218 ?>
219
220 </div>
221
222 <?php
223
224 } // function
225
226
227 ?>