-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTasks.php
460 lines (341 loc) · 14 KB
/
Tasks.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<?php
# Tasks
$language = "pt";
if (isset($website["language"]) == True) {
$language = $website["language"];
}
$full_language = $Language -> languages["full"][$language];
if ($language == "general") {
$language = "en";
$full_language = $Language -> languages["full"][$language];
}
# Generate tasks tab content
$website["tab_content"]["completed_tasks"] = [
"string" => "",
"number" => 0
];
# Create additional tabs array
if (array_key_exists("additional_tabs", $website) == False) {
$website["additional_tabs"] = [
"data" => []
];
}
if (isset($website["Data"]["Year"]) == False) {
$website["Data"]["Year"] = Date::Now()["year"];
}
if (in_array($website["Data"]["title"], $website["Years"]) == True) {
$website["Data"]["Year"] = $website["Data"]["title"];
}
if (isset($website["Task History"]) == False) {
$website["Task History"] = [
"Years list" => Date::Create_Years_List($mode = "array", $start = 2018, $plus = -1)
];
}
# Define the data network folder for easier typing
$network_folder = $folders["Mega"]["Notepad"]["Data Networks"]["Productivity"];
if (isset($tasks) == False) {
# Define the "Tasks" array
$tasks = [
"Files" => [
"Per Task Type" => [
"root" => $network_folder["Task History"][$website["Data"]["Year"]]["Per Task Type"]["root"]
]
],
"Types" => $JSON -> To_PHP($network_folder["Data"]["Types"]),
"Entries" => "",
"Texts" => $JSON -> To_PHP($folders["Apps"]["Module files"]["Tasks"]["Texts"]),
"Language texts" => []
];
$tasks["Language texts"] = $Language -> Item($tasks["Texts"]);
$types_dictionary = $tasks["Types"]["Plural"];
$website["Data"]["Numbers"] = [
"By year" => [],
"By type" => []
];
# Iterate through the English media types list
$i = 0;
foreach ($types_dictionary["en"] as $type) {
$website["Data"]["Numbers"]["By type"][$type] = 0;
}
}
# Update the "Per Task Type" folder
$tasks["Files"]["Per Task Type"] = [
"root" => $network_folder["Task History"][$website["Data"]["Year"]]["Per Task Type"]["root"]
];
# Define the Entries file
$entries_file = $network_folder["Task History"][$website["Data"]["Year"]]["Tasks"];
if (file_exists($entries_file) == True) {
$tasks["Entries"] = $JSON -> To_PHP($entries_file);
}
if ($website["Data"]["title"] != "Tasks") {
$tasks["Types dictionary"] = $types_dictionary;
}
if (function_exists("Generate_Task_Type_Headers") == False) {
function Generate_Task_Type_Headers($header_text = "") {
global $website;
global $Language;
global $JSON;
global $tasks;
$language = "pt";
if (isset($website["language"]) == True) {
$language = $website["language"];
}
if ($language == "general") {
$language = "en";
}
if ($header_text == "") {
$header_text = $tasks["Texts"]["tasks, title()"][$language]." [".$website["Data"]["Year"]."]";
}
$array = [
"links" => "",
"headers" => []
];
$text_color = $website["Style"]["text"]["theme"]["dark"];
# Define the default local types dictionary
$types_dictionary = $tasks["Types"]["Plural"];
# If the root website title is not "Tasks"
if ($website["Data"]["title"] != "Tasks") {
# Define the local types dictionary as the one inside the "Tasks" dictionary
$types_dictionary = $tasks["Types dictionary"];
}
$tasks["language_types"] = $types_dictionary[$language];
foreach (array_keys($tasks["Entries"]["Numbers"]["Per Task Type"]) as $task_type) {
if (in_array($task_type, $types_dictionary["en"]) == False) {
array_push($types_dictionary["en"], $task_type);
$text = $task_type;
$text_key = str_replace(" ", "_", strtolower($task_type));
if (str_contains($task_type, " ") == False) {
$text_key .= ", title()";
}
if (in_array($task_type, ["Python", "PHP", "AutoHotKey", "HTML"]) == False) {
$text = $website["Texts"][$text_key][$language];
}
if (in_array($text, $tasks["language_types"]) == False) {
array_push($tasks["language_types"], $text);
}
if (in_array($text, $types_dictionary[$language]) == False) {
array_push($types_dictionary[$language], $text);
}
}
}
if ($website["Data"]["title"] != "Tasks") {
$tasks["Types dictionary"] = $types_dictionary;
}
# Define a shortcut for the total number of entries in the year
$total_number = $tasks["Entries"]["Numbers"]["Total"];
# Iterate through the English plural task types list
$i = 0;
foreach ($types_dictionary["en"] as $type) {
$language_type = $tasks["language_types"][$i];
if (array_key_exists($type, $tasks["Entries"]["Numbers"]["Per Task Type"])) {
$number = $tasks["Entries"]["Numbers"]["Per Task Type"][$type];
# If the number is not zero (0)
# Or the total number of tasks is zero
if (
$number != 0 or
$total_number == 0
) {
$span = HTML::Element("span", $number, "", $text_color);
$b = HTML::Element("b", $language_type.": ".$span);
$href = $header_text.": ".$language_type;
# Anchor element to go to task type list
if ($number != 0) {
$a = HTML::Element("a", $b, 'href="#'.$href.'"');
}
else {
$a = HTML::Element("a", $b);
}
$array["links"] .= $a."<br />"."\n\t\t";
$tasks["Files"]["Per Task Type"][$type] = $JSON -> To_PHP($tasks["Files"]["Per Task Type"]["root"].$type."/Tasks.json");
$span = HTML::Element("span", $number, "", $text_color);
$b = HTML::Element("b", $language_type.": ".$span);
# Plural task type header with anchor href to go to task type part
$a = HTML::Element("a", $b, 'name="'.$href.'"')."<br />";
$array["headers"][$type] = "\t\t".'<!-- "'.$type.'" task type header -->'."\n".
"\t\t".$a."\n";
}
}
$i++;
}
return $array;
}
}
# Define the local types dictionary as the root types dictionary inside the "Tasks" dictionary
$types_dictionary = $tasks["Types dictionary"];
# Define the Entries file
$entries_file = $network_folder["Task History"][$website["Data"]["Year"]]["Tasks"];
if (file_exists($entries_file) == True) {
$tasks["Entries"] = $JSON -> To_PHP($entries_file);
# Add to the year entries number
$current_year = $website["Data"]["Year"];
if (isset($website["Data"]["Numbers"]["By year"][$current_year]) == False) {
$website["Data"]["Numbers"]["By year"][$current_year] = $tasks["Entries"]["Numbers"]["Total"];
}
# Sort the year keys
ksort($website["Data"]["Numbers"]["By year"]);
$website_title = "Tasks";
$tab = "past_registry_".$website["Data"]["Year"];
# If the local year is the current year
# Then, the tab that needs to be used is the "Completed tasks" tab
if ($website["Data"]["Year"] == $website["current_year"]) {
$tab = "completed_tasks";
}
if ($website["Data"]["title"] != $website_title) {
$website_dictionary = $website["Dictionary"][$website_title];
$link = $website_dictionary["Links"]["Language"];
if (str_contains($link, "?") == False) {
$link .= "?";
}
else {
$link .= "&";
}
$link .= "tab=".$tab;
# Add the website button to the top of the page
$website["tab_content"]["completed_tasks"]["string"] .= "<center>"."\n".
$Text -> Format($website_dictionary["Button template"], $link)."\n".
"<p></p>".
# Add the website image to the top of the tab
$website_dictionary["image"]["elements"]["theme"]["dark"]."\n".
"</center>"."\n".
"<br />"."\n";
}
$task_type_headers = Generate_Task_Type_Headers($header_text = "", $update_types_dictionary = False);
# Define the local types dictionary as the root types dictionary inside the "Tasks" dictionary
$types_dictionary = $tasks["Types dictionary"];
# Update the watched things number
$website["tab_content"]["completed_tasks"]["number"] = $tasks["Entries"]["Numbers"]["Total"];
if (
$website["Data"]["title"] != $website_title or
$website["tab_content"]["completed_tasks"]["number"] == 0
) {
# Create the number of tasks variable with the tab title
$number_of_tasks = $tasks["Language texts"]["completed_tasks"].":";
# Add the icon of the tab
$number_of_tasks .= " ".$website["Icons"]["list_check"];
# Add the number of tasks
$number_of_tasks .= " ".HTML::Element("span", $website["tab_content"]["completed_tasks"]["number"], "", $website["Style"]["text"]["theme"]["dark"])."<br /><br />";
# Transform everything into bold style
$number_of_tasks = HTML::Element("b", $number_of_tasks);
# Add the number of tasks text to the tab string content
$website["tab_content"]["completed_tasks"]["string"] .= $number_of_tasks;
}
# Add the task type headers
$website["tab_content"]["completed_tasks"]["string"] .= "<!-- Task type headers -->"."\n"."\t\t".
$task_type_headers["links"].
"\n"."\t\t"."<br />"."\n\n";
$text_color = $website["Style"]["text"]["theme"]["dark"];
# Iterate through the English task types list
$i = 0;
foreach ($types_dictionary["en"] as $type) {
# Get the language type
$language_type = $tasks["language_types"][$i];
if (array_key_exists($type, $tasks["Entries"]["Numbers"]["Per Task Type"]) == True) {
$number = $tasks["Entries"]["Numbers"]["Per Task Type"][$type];
if (isset($website["Data"]["Numbers"]["By type"][$type]) == False) {
$website["Data"]["Numbers"]["By type"][$type] = 0;
}
$website["Data"]["Numbers"]["By type"][$type] += $number;
if ($number != 0) {
$website["tab_content"]["completed_tasks"]["string"] .= $task_type_headers["headers"][$type];
# Iterate through the task type Entries list
foreach ($tasks["Files"]["Per Task Type"][$type]["Entries"] as $entry) {
$entry = $tasks["Entries"]["Dictionary"][$entry];
# Add the task title
$format = "Y-m-d\TH:i:s\Z";
if (strlen($entry["Date"]) == 4) {
$format = "Y";
}
$time = $entry["Date"];
if ($time != "") {
$time = Date::Now($time, $format);
}
if (strlen($entry["Date"]) != 4) {
$time = $time["formats"]["HH:MM DD/MM/YYYY"];
}
if (strlen($entry["Date"]) == 4) {
$time = $time["year"];
}
$text = $entry["Number"]." -";
# Add the States
if (array_key_exists("States", $entry) == True) {
if (array_key_exists("First task in year", $entry["States"]) == True) {
$first_text = $website["Language texts"]["first_task_in_the_year"];
$text .= " ".HTML::Element("span", "1# ".$website["Icons"]["calendar"], 'alt="'.$first_text.'" title="'.$first_text.'"', $website["Style"]["text_highlight"]." underline_on_hover");
}
if (array_key_exists("First task type task in year", $entry["States"]) == True) {
$first_text = $website["Language texts"]["first_task_per_task_type_in_the_year"];
$text .= " ".HTML::Element("span", "1# ".$website["Icons"]["list_check"]." ".$website["Icons"]["calendar"], 'alt="'.$first_text.'" title="'.$first_text.'"', $website["Style"]["text_highlight"]." underline_on_hover");
}
if (
array_key_exists("First task in year", $entry["States"]) == True or
array_key_exists("First task type task in year", $entry["States"]) == True
) {
$text .= " - ";
}
}
$title = HTML::Element("span", $entry["Titles"][$language], "", $text_color);
if (
$website["States"]["Tasks"]["Entry tabs"] == True and
(int)$website["Data"]["Year"] >= 2023
) {
# Add the task description tab link and create the tab
$link_text = $website["Language texts"]["task_description"];
$tab_id = "task_description_".$entry["Number"]."_".$website["Data"]["Year"];
$style = 'style="text-decoration: underline; cursor: pointer;"';
$title = HTML::Element("a", $title, 'onclick="'."Open_Tab('".$tab_id."')".'" target="_blank" alt="'.$link_text.'" title="'.$link_text.'" '.$style, $text_color);
# Create the tab title
$tab_title = $entry["Number"]." - ".$entry["Titles"][$language]." (".$time.")";
# Get the task description file
$folder = $folders["Mega"]["Notepad"]["Years"][$website["Data"]["Year"]][$language]["done_tasks"]["root"].$language_type."/";
$local_entry = str_replace(":", ";", $entry["Entry"]);
$local_entry = str_replace("/", "-", $local_entry);
$file = $folder.$local_entry.".txt";
# Create the tab array and content
$website["additional_tabs"]["data"][$tab_id] = [
"id" => $tab_id,
"name" => $tab_title,
"text_style" => "text-align: left;",
"file" => $file,
"icon" => "list_check",
"only_button" => "tasks"
];
# If the year in the "Data" dictionary is not the current one
if ($website["Data"]["Year"] != $website["current_year"]) {
if (isset($website["past_registries_buttons"]) == True) {
# Change the "only button" to the "past registry" button of the current year
$website["additional_tabs"]["data"][$tab_id]["only_button"] = "past_registry_".$website["Data"]["Year"];
$website["additional_tabs"]["data"][$tab_id]["Buttons list"] = $website["past_registries_buttons"];
}
else {
$website["additional_tabs"]["data"][$tab_id]["only_button"] = "completed_tasks";
}
}
}
$text .= " ".$title." (".$time.")";
$text = HTML::Element("span", $text, 'style="margin-left: 3%;"', $website["Style"]["text_hover"]);
$website["tab_content"]["completed_tasks"]["string"] .= $text."<br />"."\n";
}
if ($type != end($tasks["language_types"])) {
$website["tab_content"]["completed_tasks"]["string"] .= "\t\t"."<br />"."\n\n";
}
}
}
$i++;
}
$website["tab_content"]["completed_tasks"]["string"] .= "<br /><br />";
# Add the tab to the tab templates
if (array_key_exists("completed_tasks", $website["tabs"]["templates"]) == False) {
$website["tabs"]["templates"]["completed_tasks"] = [
"name" => $website["Language texts"]["completed_tasks_in"]." ".$website["Data"]["Year"],
"add" => " ".HTML::Element("span", $website["tab_content"]["completed_tasks"]["number"], "", $website["Style"]["text"]["theme"]["dark"]),
"text_style" => "text-align: left;",
"content" => $website["tab_content"]["completed_tasks"]["string"],
"icon" => "list_check"
];
}
}
else {
# Define the "Completed tasks" tab to be removed if it does not contain completed tasks
array_push($website["tabs"]["To remove"], "completed_tasks");
}
?>