]> git.plutz.net Git - busy/blob - Tasks.page
honor login status when directing to news script
[busy] / Tasks.page
1 #!/bin/zsh
2
3 info="$(sed -r 's:(^|.*&)i=([0-9]{10}_[0-9]{3}).*|.*:\2:;s:&.*::' <<<"${QUERY_STRING}")"
4 edit="$(sed -r 's:(^|.*&)e=([0-9]{10}_[0-9]{3}).*|.*:\2:;s:&.*::' <<<"${QUERY_STRING}")"
5 search="$(sed -r 's:(^|.*&)s=(.*)|.*:\2:;s:&.*::;s:\+: :g;s:%:\\x:g' <<<"${QUERY_STRING}")"
6 search="$(echo -e "${search}" |sed -rn '1{s:\t: :g;s:\r::g;s:\\:\\\\:g;p}')"
7 new="$(sed -r 's:(^|.*&)n=(.*)|.*:\2:;s:&.*::;s:\+: :g;s:%:\\x:g' <<<"${QUERY_STRING}")"
8 new="$(echo -e "${new}" |sed -rn '1{s:\t: :g;s:\r::g;s:\\:\\\\:g;p}')"
9
10 [ -z "$ACL_CREATETASK" ] && ACL_CREATETASK=false
11
12 cat <<TasksEND
13   <div id="LEFT">
14     <form method="GET" action="/${SCRIPTNAME}" accept-charset="utf-8">
15       <input type="hidden" name="p" value="Tasks">
16       <input type="text" name="s" placeholder="Search"><br>
17       <input type="submit" value="Search Tasks">
18     </form>
19     <hr>
20 TasksEND
21 #search results
22 if [ -n "$search" ]; then
23   echo "<h1>Tasks search results for: $search</h1>"
24   for each in $(grep -ile "$search" Tasks/<0000000000-9999999999>_<000-999>); do
25     id=$(sed -r 's:^.*/::;s:.task$::' <<<$each)
26     echo "<div class='search'><a href='${SCRIPTNAME}?p=Tasks&amp;i=$id'><h2>$(date -d @$(cut -d_ -f1 <<<"$id"))</h2></a>"
27     grep -C1 -ie "$search" "$each" |sed "s:$search:<b>&</b>:g;s:$:<br>:g"
28     echo '</div>'
29   done
30   echo '<hr>'
31 fi
32 echo '</div><div id="MAIN">'
33
34 #Display single task
35 if [ -n "$info" -a -r "Tasks/$info" -a -r "Tasks/$info.meta" ]; then
36   datafile="Tasks/$info"
37   metafile="Tasks/$info.meta"
38   headline="$(sed -rn '/^headline=/{s:^[a-z]+=(.+)$:\1:p;q}' "$metafile")"
39   taskstatus="$(sed -rn '/^status=/{s:^[a-z]+=(.+)$:\1:p;q}' "$metafile")"
40   section="$(sed -rn '/^section=/{s:^[a-z]+=(.+)$:\1:p;q}' "$metafile")"
41   attendant="$(sed -rn '/^attendant=/{s:^[a-z]+=(.+)$:\1:p;q}' "$metafile")"
42   [ -z "$section" ] && section='(none)'
43   [ -z "$attendant" ] && attendant='(none)'
44   cat <<TasksEND
45     <div class="Task">
46       <div class="wikitext">
47         <h1>$headline</h1>
48         $(_wiki "$datafile")
49       </div>
50       <table><tr>
51         <td><b>Status</b><br>
52         $taskstatus</td>
53         <td><b>Section</b><br>
54         $section</td>
55         <td><b>Attendant</b><br>
56         $attendant</td>
57       </tr></table>
58     </div>
59 TasksEND
60 fi
61
62 #create task main dialog
63 [ -z "$info" -a -n "$new" ] && cat <<TaskEnd
64 <form class="Task" style="height:20em;" method="post" action="write/$($LOGIN && echo user_)taskmeta.cgi" accept-charset="UTF-8">
65   <h1>$new</h1>
66   <input type="hidden" name="headline" value="$new">
67   <input type="hidden" name="status" value="new">
68   <div style="width:60%;left:3.5em;">
69     <b>Description:</b><br>
70     <textarea name="description" rows="11"></textarea>
71   </div><div style="width:30%;right:.5em;">
72     <b>Section:</b><br>
73     <select name="section" size="6" style="width:80%">
74     $(for each in $(egrep -hx 'section=.+' Tasks/<0000000000-9999999999>_<000-999>.meta |sort -u); do
75         echo "<option>$(sed 's:section=::' <<<"$each")</option>"
76       done)
77     </select><br>
78     <b>other section:</b><br>
79     <input type="text" name="section">
80     <input type="submit" name="submit" value="Robots click here" style="display:none;">
81     <input type="submit" name="submit" value="Create Task">
82     <input type="submit" name="submit" value="Robots click here" style="display:none;">
83   </div>
84 </form>
85 TaskEnd
86
87 #Plain list of tasks (default)
88 [ -z "$info" -a -z "$new" ] && stat -c '' Tasks/<0000000000-9999999999>_<000-999>.meta && for each in Tasks/<0000000000-9999999999>_<000-999>.meta(.om); do
89   info="$(basename "$each" |sed 's:.meta$::')"
90   headline="$(sed -rn '/^headline=/{s:^[a-z]+=(.+)$:\1:p;q}' "$each")"
91   taskstatus="$(sed -rn '/^status=/{s:^[a-z]+=(.+)$:\1:p;q}' "$each")"
92   section="$(sed -rn '/^section=/{s:^[a-z]+=(.+)$:\1:p;q}' "$each")"
93   attendant="$(sed -rn '/^attendant=/{s:^[a-z]+=(.+)$:\1:p;q}' "$each")"
94   [ -z "$section" ] && section='(none)'
95   [ -z "$attendant" ] && attendant='(none)'
96   cat <<TasksEND
97    <div class="Task">
98      <a href="${SCRIPTNAME}?p=Tasks&amp;i=${info}"><b>$headline</b></a><br>
99      <span><b>Status:</b> $taskstatus</span>
100      <span><b>Section:</b> $section</span>
101      <span><b>Attendant:</b> $attendant</span>
102    </div>
103 TasksEND
104 done
105
106 #dropdown dialog for adding a task
107 echo '</div> <div id="RIGHT">'
108 $ACL_CREATETASK && [ -z "$new" ] && cat <<TasksEND
109       <a id='newTask_button' class='function' href='#' onclick='javascript:show_screen("newTask");hide_screen("newTask_button");'>New Task</a>
110       <div id="newTask" style="display: none;">
111         <form action="/${SCRIPTNAME}" method="get" accept-charset="UTF-8">
112           <b>Headline:</b><br>
113           <input type="hidden" name="p" value="Tasks">
114           <textarea name="n" rows="2" style="width:99%;"></textarea><br>
115           <input type="submit" value="Submit">
116           <a class="function" href="#" onclick="javascript:hide_screen('newTask');show_screen('newTask_button');">Cancel</a>
117         </form>
118       </div>
119 TasksEND
120 echo '</div>'