File: index.cpp

package info (click to toggle)
bibledit-cloud 5.1.036-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 250,636 kB
  • sloc: xml: 915,934; ansic: 261,349; cpp: 92,628; javascript: 32,542; sh: 4,915; makefile: 586; php: 69
file content (110 lines) | stat: -rw-r--r-- 4,696 bytes parent folder | download | duplicates (3)
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
/*
 Copyright (©) 2003-2025 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 <notes/index.h>
#include <assets/view.h>
#include <assets/page.h>
#include <assets/header.h>
#include <filter/roles.h>
#include <webserver/request.h>
#include <locale/translate.h>
#include <database/notes.h>
#include <menu/logic.h>
#include <access/logic.h>


std::string notes_index_url ()
{
  return "notes/index";
}


bool notes_index_acl (Webserver_Request& webserver_request)
{
  return access_logic::privilege_view_notes (webserver_request);
}


std::string notes_index (Webserver_Request& webserver_request)
{
  Database_Notes database_notes (webserver_request);
  
  std::string page;
  
  Assets_Header header = Assets_Header (translate("Consultation Notes"), webserver_request);
  header.set_navigator ();
  header.add_bread_crumb (menu_logic_translate_menu (), menu_logic_translate_text ());
  page = header.run();
  
  Assets_View view;
  std::string error;
  std::string success;

  // Presets for notes selectors.
  // This is for the daily statistics and the workspace.
  if (webserver_request.query.count ("presetselection")) {
    webserver_request.database_config_user()->set_consultation_notes_passage_selector (static_cast<int>(Database_Notes::PassageSelector::any_passage));
    webserver_request.database_config_user()->set_consultation_notes_edit_selector (static_cast<int>(Database_Notes::EditSelector::at_any_time));
    webserver_request.database_config_user()->set_consultation_notes_non_edit_selector (static_cast<int>(Database_Notes::NonEditSelector::any_time));
    webserver_request.database_config_user()->set_consultation_notes_status_selectors ({});
    webserver_request.database_config_user()->set_consultation_notes_bible_selector (std::string());
    webserver_request.database_config_user()->set_consultation_notes_assignment_selector (std::string());
    webserver_request.database_config_user()->set_consultation_notes_subscription_selector (false);
    webserver_request.database_config_user()->set_consultation_notes_severity_selector (static_cast<int>(Database_Notes::SeveritySelector::any));
    webserver_request.database_config_user()->set_consultation_notes_text_selector (false);
    std::string preset_selector = webserver_request.query ["presetselection"];
    if (preset_selector == "assigned") {
      webserver_request.database_config_user()->set_consultation_notes_assignment_selector (webserver_request.session_logic ()->get_username ());
    }
    if (preset_selector == "subscribed") {
      webserver_request.database_config_user()->set_consultation_notes_subscription_selector (true);
    }
    if (preset_selector == "subscribeddayidle") {
      webserver_request.database_config_user()->set_consultation_notes_subscription_selector (true);
      webserver_request.database_config_user()->set_consultation_notes_non_edit_selector (static_cast<int>(Database_Notes::NonEditSelector::a_day));
    }
    if (preset_selector == "subscribedweekidle") {
      webserver_request.database_config_user()->set_consultation_notes_subscription_selector (true);
      webserver_request.database_config_user()->set_consultation_notes_non_edit_selector (static_cast<int>(Database_Notes::NonEditSelector::a_week));
    }
    if (preset_selector == "forverse") {
      webserver_request.database_config_user()->set_consultation_notes_passage_selector (static_cast<int>(Database_Notes::PassageSelector::current_verse));
    }
  }

  const int level = webserver_request.session_logic ()->get_level ();
  // Manager roles and higher can do mass updates on the notes.
  if (level >= roles::manager) {
    // No mass updates in basic mode.
    if (!config::logic::basic_mode (webserver_request)) {
      view.enable_zone ("update");
    }
  }
  
  // Whether the user can create a new note.
  if (access_logic::privilege_create_comment_notes (webserver_request)) {
    view.enable_zone ("create");
  }
  
  page += view.render ("notes", "index");
  
  page += assets_page::footer ();
  
  return page;
}