File: update.cpp

package info (click to toggle)
bibledit 5.0.764-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 230,136 kB
  • sloc: xml: 863,336; ansic: 164,208; cpp: 81,648; sh: 4,684; makefile: 406; php: 69
file content (157 lines) | stat: -rw-r--r-- 4,929 bytes parent folder | download | duplicates (2)
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
/*
 Copyright (©) 2003-2018 Teus Benschop.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <navigation/update.h>
#include <filter/roles.h>
#include <filter/string.h>
#include <webserver/request.h>
#include <navigation/passage.h>
#include <database/books.h>


string navigation_update_url ()
{
  return "navigation/update";
}


bool navigation_update_acl (void * webserver_request)
{
  return Filter_Roles::access_control (webserver_request, Filter_Roles::guest ());
}


string navigation_update (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;

  
  string bible;
  /*
  if (request->query.count ("bible")) {
    bible = request->query ["bible"];
  } else {
    bible = request->database_config_user()->getBible ();
  }
  */
  // It used to take the Bible from the Bible variable stored in javascript.
  // But then, when switching from a Bible that has the NT only, to a Bible that has OT and NT,
  // the navigator would only show the NT books.
  // Now, by taking the Bible from the database, it will show the books of the last selected Bible.
  bible = request->database_config_user()->getBible ();
  int book = convert_to_int (request->query ["book"]);
  int chapter = convert_to_int (request->query ["chapter"]);
  int verse = convert_to_int (request->query ["verse"]);
  
  
  if (request->query.count ("goback")) {
    Navigation_Passage::goBack (request);
  }
  
  
  else if (request->query.count ("goforward")) {
    Navigation_Passage::goForward (request);
  }
  
  
  else if (request->query.count ("getbooks")) {
    return Navigation_Passage::getBooksFragment (request, bible);
  }
  
  
  else if (request->query.count ("applybook")) {
    string msg = request->query ["applybook"];
    if (msg.find ("cancel") == string::npos) {
      int book = convert_to_int (msg);
      if (book) Navigation_Passage::setBook (request, book);
    }
  }
  
  
  // Get the list of available chapters in the current book.
  else if (request->query.count ("getchapters")) {
    return Navigation_Passage::getChaptersFragment (request, bible, book, chapter);
  }
  

  // Select a chapter, go to previous or next chapter, or cancel.
  else if (request->query.count ("applychapter")) {
    string msg = request->query ["applychapter"];
    if (msg.find ("previous") != string::npos) {
      Navigation_Passage::gotoPreviousChapter (webserver_request, bible);
    } else if (msg.find ("next") != string::npos) {
      Navigation_Passage::gotoNextChapter (webserver_request, bible);
    }
    else if (msg.find ("cancel") != string::npos) {
    } else {
      int chapter = convert_to_int (msg);
      Navigation_Passage::setChapter (request, chapter);
    }
  }
  
  
  // Get the list of available verses in the current chapter.
  else if (request->query.count ("getverses")) {
    return Navigation_Passage::getVersesFragment (request, bible, convert_to_int (book), chapter, verse);
  }

  
  // Select a verse, go to the previous or next verse, or cancel.
  else if (request->query.count ("applyverse")) {
    string msg = request->query ["applyverse"];
    if (msg.find ("previous") != string::npos) {
      Navigation_Passage::gotoPreviousVerse (webserver_request, bible);
    } else if (msg.find ("next") != string::npos) {
      Navigation_Passage::gotoNextVerse (webserver_request, bible);
    }
    else if (msg.find ("cancel") != string::npos) {
    } else {
      int verse = convert_to_int (msg);
      Navigation_Passage::setVerse (request, verse);
    }
  }
  

  // Go to the previous verse.
  else if (request->query.count ("previousverse")) {
    Navigation_Passage::gotoPreviousVerse (webserver_request, bible);
  }
  
  
  // Go to the next verse.
  else if (request->query.count ("nextverse")) {
    Navigation_Passage::gotoNextVerse (webserver_request, bible);
  }
  

  // Go to the previous chapter.
  else if (request->query.count ("previouschapter")) {
    Navigation_Passage::gotoPreviousChapter (webserver_request, bible);
  }
  
  
  // Go to the next chapter.
  else if (request->query.count ("nextchapter")) {
    Navigation_Passage::gotoNextChapter (webserver_request, bible);
  }
  
  
  // Build the navigation fragment.
  return Navigation_Passage::getNavigator (request, bible);
}