~bibledit/bibledit/client

5 by teusjannette at gmail
new upstream version
1
/*
55 by teusjannette at gmail
new upstream version
2
 Copyright (©) 2003-2020 Teus Benschop.
5 by teusjannette at gmail
new upstream version
3
 
4
 This program is free software; you can redistribute it and/or modify
5
 it under the terms of the GNU General Public License as published by
6
 the Free Software Foundation; either version 3 of the License, or
7
 (at your option) any later version.
8
 
9
 This program is distributed in the hope that it will be useful,
10
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 GNU General Public License for more details.
13
 
14
 You should have received a copy of the GNU General Public License
15
 along with this program; if not, write to the Free Software
16
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
 */
18
19
20
#include <notes/note.h>
21
#include <assets/view.h>
22
#include <assets/page.h>
23
#include <assets/header.h>
24
#include <filter/roles.h>
25
#include <filter/string.h>
26
#include <filter/url.h>
50 by teusjannette at gmail
new upstream version
27
#include <filter/html.h>
5 by teusjannette at gmail
new upstream version
28
#include <webserver/request.h>
29
#include <locale/translate.h>
30
#include <database/notes.h>
31
#include <notes/logic.h>
32
#include <access/bible.h>
33
#include <ipc/focus.h>
34
#include <navigation/passage.h>
35
#include <notes/index.h>
36
#include <access/logic.h>
37
38
39
string notes_note_url ()
40
{
41
  return "notes/note";
42
}
43
44
45
bool notes_note_acl (void * webserver_request)
46
{
47
  return access_logic_privilege_view_notes (webserver_request);
48
}
49
50
51
string notes_note (void * webserver_request)
52
{
53
  Webserver_Request * request = (Webserver_Request *) webserver_request;
54
  Database_Notes database_notes (webserver_request);
55
  
56
  
57
  string page;
58
  Assets_Header header = Assets_Header (translate("Note"), request);
59
  header.setNavigator ();
60
61
  
62
  // After adding a comment to a note, when doing nothing for several seconds,
63
  // the browser then returns to the list of notes.
64
  if (request->query.count ("temporal")) {
65
    header.refresh (5, "index");
66
  }
67
68
  
69
  page += header.run ();
70
  Assets_View view;
71
  string success;
72
73
  
74
  int id = convert_to_int (request->query ["id"]);
75
  
76
  
77
  // When a note is opened, then the passage navigator should go to the passage that belongs to that note.
50 by teusjannette at gmail
new upstream version
78
  vector <Passage> passages = database_notes.get_passages (id);
5 by teusjannette at gmail
new upstream version
79
  if (!passages.empty ()) {
34 by teusjannette at gmail
new upstream version
80
    Passage focused_passage;
81
    focused_passage.book = Ipc_Focus::getBook (webserver_request);
82
    focused_passage.chapter = Ipc_Focus::getChapter (webserver_request);
83
    focused_passage.verse = convert_to_string (Ipc_Focus::getVerse (webserver_request));
84
    // Only set passage and track history if the focused passage
85
    // differs from all of the passages of the note.
86
    // If the focused passage is already at any of the passages belonging to the note,
87
    // no further focus operations are needed.
88
    bool passage_focused = false;
89
    for (auto passage : passages) {
90
      if (focused_passage.equal (passage)) passage_focused = true;
91
    }
92
    if (!passage_focused) {
93
      int desired_book = passages[0].book;
94
      int desired_chapter = passages[0].chapter;
95
      int desired_verse = convert_to_int (passages[0].verse);
5 by teusjannette at gmail
new upstream version
96
      Ipc_Focus::set (webserver_request, desired_book, desired_chapter, desired_verse);
97
      Navigation_Passage::recordHistory (webserver_request, desired_book, desired_chapter, desired_verse);
98
    }
99
  }
100
  
101
  
102
  view.set_variable ("id", convert_to_string (id));
103
  
104
50 by teusjannette at gmail
new upstream version
105
  string summary = database_notes.get_summary (id);
5 by teusjannette at gmail
new upstream version
106
  view.set_variable ("summary", summary);
107
29 by teusjannette at gmail
new upstream version
108
  
109
  bool show_note_status = request->database_config_user ()->getShowNoteStatus ();
110
  if (show_note_status) {
50 by teusjannette at gmail
new upstream version
111
    string status = database_notes.get_status (id);
29 by teusjannette at gmail
new upstream version
112
    view.set_variable ("status", status);
113
  }
114
  
115
  
56 by teusjannette at gmail
new upstream version
116
  if (request->session_logic ()->currentLevel () >= Filter_Roles::translator ()) {
5 by teusjannette at gmail
new upstream version
117
    view.enable_zone ("editlevel");
118
  }
119
  
120
  
50 by teusjannette at gmail
new upstream version
121
  string content = database_notes.get_contents (id);
5 by teusjannette at gmail
new upstream version
122
  view.set_variable ("content", content);
123
124
  
50 by teusjannette at gmail
new upstream version
125
  // Extra space at the bottom of the page.
126
  // See issues:
127
  // https://github.com/bibledit/cloud/issues/321
128
  // https://github.com/bibledit/cloud/issues/310
129
  view.set_variable ("brs", filter_html_android_brs ());
130
  
131
16 by teusjannette at gmail
new upstream version
132
  if (request->database_config_user ()->getQuickNoteEditLink ()) {
133
    view.enable_zone ("editcontent");
134
  }
135
    
136
  
5 by teusjannette at gmail
new upstream version
137
  if (Filter_Roles::access_control (webserver_request, Filter_Roles::consultant ())) {
138
    view.enable_zone ("consultant");
139
  }
140
  if (access_logic_privilege_create_comment_notes (webserver_request)) {
141
    view.enable_zone ("comment");
142
  }
143
  
144
  view.set_variable ("success", success);
145
  page += view.render ("notes", "note");
146
  page += Assets_Page::footer ();
147
  return page;
148
}