Beispiel #1
0
string setup_index (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;
  
  Assets_View view;

  // Get the existing Administrators.
  vector <string> admins = request->database_users ()->getAdministrators ();

  // Admins do not yet exist: Allow to enter an admin.
  if (admins.empty ()) {
    if (!request->post ["Submit"].empty ()) {
      string admin_username = request->post ["admin_username"];
      string admin_password = request->post ["admin_password"];
      string admin_email = request->post ["admin_email"];
      vector <string> errors;
      if (admin_username.length() < 5) errors.push_back ("Choose a longer username.");
      if (admin_password.length() < 7) errors.push_back ("Choose a longer password.");
      if (admin_email.length() < 5) errors.push_back ("Enter a valid email address.");
      if (errors.empty()) {
        // Store admin details.
        setup_set_admin_details (admin_username, admin_password, admin_email);
        setup_complete_gui ();
        // Store web site's base URL.
        string siteUrl = get_base_url (request);
        Database_Config_General::setSiteURL (siteUrl);
        // Redirect.
        redirect_browser (request, index_index_url ());
      } else {
        view.enable_zone ("errors");
        view.set_variable ("error", filter_string_implode (errors, " "));
      }
    }
  }

  // Enable appropriate zones: Either enter admin's details, or else display the details.
  if (admins.empty ()) {
    view.enable_zone ("enteradmin");
    view.enable_zone ("enteruser");
    view.enable_zone ("enterpass");
    view.enable_zone ("entermail");
    view.enable_zone ("displaysubmit");
  } else {
    string usernames;
    string emails;
    for (unsigned int i = 0; i < admins.size(); i++) {
      if (i) {
        usernames.append (" / ");
        emails.append (" / ");
      }
      usernames.append (admins[i]);
      emails.append (request->database_users ()->getUserToEmail (admins[i]));
    }
    view.set_variable ("usernames", usernames);
    view.set_variable ("emails", emails);
    view.enable_zone ("displayok");
    view.set_variable ("readonly", "readonly");
    // If the admin's are already there, then the setup has completed.
    // The automatic page refresh will kick in, and navigate to the main screen.
    Database_Config_General::setInstalledInterfaceVersion (config_logic_version ());
  }

  return view.render ("setup", "index");
}
Beispiel #2
0
// Runs the header.
string Assets_Header::run ()
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;

  string page;
  
  // Include the software version number in the stylesheet and javascript URL
  // to refresh the browser's cache after a software upgrade.
  view->set_variable("VERSION", config_logic_version ());

  if (includeJQueryUI) {
    view->enable_zone ("include_jquery_ui");
  }

  if (includeJQueryMobileTouch) {
    view->enable_zone ("include_jquery_mobile_touch");
  }

  if (request->session_logic ()->touchEnabled ()) {
    touchCSSOn();
  }
  if (!request->session_logic ()->loggedIn ()) {
    touchCSSOn();
  }
  if (includeTouchCSS) {
    view->enable_zone ("include_touch_css");
  } else {
    view->enable_zone ("include_mouse_css");
  }
  
  if (includeNotifIt) {
    view->enable_zone ("include_notif_it");
  }
  
  string headlines;
  for (auto & headline : headLines) {
    if (!headlines.empty ()) headlines.append ("\n");
    headlines.append (headline);
  }
  view->set_variable ("head_lines", headlines);

  if (!includedStylesheet.empty ()) {
    view->enable_zone ("include_stylesheet");
    view->set_variable ("included_stylesheet", includedStylesheet);
  }
  if (!includedEditorStylesheet.empty ()) {
    view->enable_zone ("include_editor_stylesheet");
    view->set_variable ("included_editor_stylesheet", includedEditorStylesheet);
  }

  bool basic_mode = config_logic_basic_mode (webserver_request);
  string basicadvanced;
  if (basic_mode) basicadvanced = "basic";
  else basicadvanced = "advanced";
  view->set_variable ("basicadvanced", basicadvanced);

  if (displayTopbar ()) {
    view->enable_zone ("display_topbar");
    
    // In basic mode there's no back button in a bare browser.
    if (basic_mode) {
      view->disable_zone ("bare_browser");
    }
    
    // The start button to be displayed only when there's no menu.
    bool start_button = true;
    
    string menublock;
    string item = request->query ["item"];
    bool main_menu_always_on = false;
    if (item.empty ())
      if (request->database_config_user ()->getMainMenuAlwaysVisible ())
        main_menu_always_on = true;
    if ((item == "main") || main_menu_always_on) {
      if (basic_mode) {
        menublock = menu_logic_basic_categories (webserver_request);
      } else {
        string devnull;
        menublock = menu_logic_main_categories (webserver_request, devnull);
      }
      start_button = false;
    } else if (item == menu_logic_translate_menu ()) {
      menublock = menu_logic_translate_category (webserver_request);
    } else if (item == menu_logic_search_menu ()) {
      menublock = menu_logic_search_category (webserver_request);
    } else if (item == menu_logic_tools_menu ()) {
      menublock = menu_logic_tools_category (webserver_request);
    } else if (item == menu_logic_settings_menu ()) {
      menublock = menu_logic_settings_category (webserver_request);
    } else if (item == menu_logic_settings_resources_menu ()) {
      menublock = menu_logic_settings_resources_category (webserver_request);
    } else if (item == menu_logic_settings_styles_menu ()) {
      menublock = menu_logic_settings_styles_category (webserver_request);
    } else if (item == "help") {
      menublock = menu_logic_help_category (webserver_request);
    }
    view->set_variable ("mainmenu", menublock);

    if (start_button) {
      view->enable_zone ("start_button");
      string tooltip;
      menu_logic_main_categories (webserver_request, tooltip);
      view->set_variable ("starttooltip", tooltip);
    }
    
    if (!fadingmenu.empty ()) {
      view->enable_zone ("fading_menu");
      view->set_variable ("fadingmenu", fadingmenu);
      string delay = convert_to_string (request->database_config_user ()->getDesktopMenuFadeoutDelay ()) + "000";
      view->set_variable ("fadingmenudelay", delay);
      fadingmenu.clear ();
    }

    if (displayNavigator) {
      view->enable_zone ("display_navigator");
      // string bible = access_bible_clamp (request, request->database_config_user()->getBible ());
      // The clamping above does not work for public feedback as it would reset the Bible always.
      string bible = request->database_config_user()->getBible ();
      view->set_variable ("navigation_code", Navigation_Passage::code (bible, true));
    }
  }

  vector <string> embedded_css;
  int fontsize = request->database_config_user ()->getGeneralFontSize ();
  if (fontsize != 100) {
    embedded_css.push_back ("body { font-size: " + convert_to_string (fontsize) + "%; }");
  }
  fontsize = request->database_config_user ()->getMenuFontSize ();
  if (fontsize != 100) {
    embedded_css.push_back (".menu { font-size: " + convert_to_string (fontsize) + "%; }");
  }
  fontsize = request->database_config_user ()->getBibleEditorsFontSize ();
  if (fontsize != 100) {
    embedded_css.push_back (".bibleeditor { font-size: " + convert_to_string (fontsize) + "% !important; }");
  }
  fontsize = request->database_config_user ()->getResourcesFontSize ();
  if (fontsize != 100) {
    embedded_css.push_back (".resource { font-size: " + convert_to_string (fontsize) + "% !important; }");
  }
  fontsize = request->database_config_user ()->getHebrewFontSize ();
  if (fontsize != 100) {
    embedded_css.push_back (".hebrew { font-size: " + convert_to_string (fontsize) + "%!important; }");
  }
  fontsize = request->database_config_user ()->getGreekFontSize ();
  if (fontsize != 100) {
    embedded_css.push_back (".greek { font-size: " + convert_to_string (fontsize) + "%!important; }");
  }
  if (!embedded_css.empty ()) {
    view->set_variable ("embedded_css", filter_string_implode (embedded_css, "\n"));
  }
  
  if (request->database_config_user ()->getDisplayBreadcrumbs ()) {
    if (!breadcrumbs.empty ()) {
      // No bread crumbs in basic mode.
      // The crumbs would be incorrect anyway, because they show the trail of advanced mode.
      if (!config_logic_basic_mode (webserver_request)) {
        string track;
        track.append ("<a href=\"/");
        track.append (index_index_url ());
        track.append ("\">");
        track.append (menu_logic_menu_text (""));
        track.append ("</a>");
        for (auto & crumb : breadcrumbs) {
          track.append (" » ");
          if (!crumb.first.empty ()) {
            track.append ("<a href=\"/");
            track.append (menu_logic_menu_url (crumb.first));
            track.append ("\">");
          }
          track.append (crumb.second);
          if (!crumb.first.empty ()) {
            track.append ("</a>");
          }
        }
        view->set_variable ("breadcrumbs", track);
      }
    }
  }
  
  page += view->render("assets", "xhtml_start");
  page += view->render("assets", "header");
  page += view->render("assets", "workspacewrapper_start");

  return page;
}
Beispiel #3
0
string changes_changes (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;
  Database_Modifications database_modifications;
  

  bool touch = request->session_logic ()->touchEnabled ();
  
  
  string page;
  Assets_Header header = Assets_Header (translate("Changes"), request);
  header.setStylesheet ();
  header.addBreadCrumb (menu_logic_translate_menu (), menu_logic_translate_text ());
  if (touch) header.jQueryTouchOn ();
  page += header.run ();
  Assets_View view;
  
  
  string username = request->session_logic()->currentUser ();
  
  
  // Handle AJAX call to remove a change notification.
  if (request->post.count ("remove")) {
    int remove = convert_to_int (request->post["remove"]);
    trash_change_notification (request, remove);
    database_modifications.deleteNotification (remove);
#ifdef HAVE_CLIENT
    request->database_config_user ()->addRemovedChange (remove);
#endif
    request->database_config_user ()->setChangeNotificationsChecksum ("");
    return "";
  }
  
  
  // Handle AJAX call to navigate to the passage belonging to the change notification.
  if (request->post.count ("navigate")) {
    string navigate = request->post["navigate"];
    int id = convert_to_int (navigate);
    Passage passage = database_modifications.getNotificationPassage (id);
    if (passage.book) {
      Ipc_Focus::set (request, passage.book, passage.chapter, convert_to_int (passage.verse));
      Navigation_Passage::recordHistory (request, passage.book, passage.chapter, convert_to_int (passage.verse));
    }
    // Set the correct default Bible for the user.
    string bible = database_modifications.getNotificationBible (id);
    if (!bible.empty ()) request->database_config_user()->setBible (bible);
    return "";
  }
  
  
  // Remove a user's personal changes notifications and their matching change notifications in the Bible.
  string matching = request->query ["matching"];
  if (!matching.empty ()) {
    vector <int> ids = database_modifications.clearNotificationMatches (username, matching, changes_bible_category ());
#ifdef HAVE_CLIENT
    // Client records deletions for sending to the Cloud.
    for (auto & id : ids) {
      request->database_config_user ()->addRemovedChange (id);
    }
#endif
    // Clear checksum cache.
    request->database_config_user ()->setChangeNotificationsChecksum ("");
  }
  
  
  // Remove all the personal change notifications.
  if (request->query.count ("personal")) {
    vector <int> ids = database_modifications.getNotificationTeamIdentifiers (username, changes_personal_category (), true);
    for (auto id : ids) {
      trash_change_notification (request, id);
      database_modifications.deleteNotification (id);
#ifdef HAVE_CLIENT
      request->database_config_user ()->addRemovedChange (id);
#endif
      request->database_config_user ()->setChangeNotificationsChecksum ("");
    }
  }
  
  
  // Remove all the Bible change notifications.
  if (request->query.count ("bible")) {
    vector <int> ids = database_modifications.getNotificationTeamIdentifiers (username, changes_bible_category (), true);
    for (auto id : ids) {
      trash_change_notification (request, id);
      database_modifications.deleteNotification (id);
#ifdef HAVE_CLIENT
      request->database_config_user ()->addRemovedChange (id);
#endif
      request->database_config_user ()->setChangeNotificationsChecksum ("");
    }
  }
  
  
  // Remove all the change notifications made by a certain user.
  if (request->query.count ("dismiss")) {
    string user = request->query ["dismiss"];
    vector <int> ids = database_modifications.getNotificationTeamIdentifiers (username, user, true);
    for (auto id : ids) {
      trash_change_notification (request, id);
      database_modifications.deleteNotification (id);
#ifdef HAVE_CLIENT
      request->database_config_user ()->addRemovedChange (id);
#endif
      request->database_config_user ()->setChangeNotificationsChecksum ("");
    }
  }
  
  
  // Read the identifiers.
  // Limit the number of results to keep the page reasonably fast even if there are many notifications.
  vector <int> personal_ids = database_modifications.getNotificationPersonalIdentifiers (username, changes_personal_category (), true);
  vector <int> bible_ids = database_modifications.getNotificationTeamIdentifiers (username, changes_bible_category (), true);
  vector <int> ids = database_modifications.getNotificationIdentifiers (username, true);

  
  string textblock;
  for (auto id : ids) {
    Passage passage = database_modifications.getNotificationPassage (id);
    string link = filter_passage_link_for_opening_editor_at (passage.book, passage.chapter, passage.verse);
    string category = database_modifications.getNotificationCategory (id);
    if (category == changes_personal_category ()) category = emoji_smiling_face_with_smiling_eyes ();
    if (category == changes_bible_category ()) category = emoji_open_book ();
    string modification = database_modifications.getNotificationModification (id);
    textblock.append ("<div id=\"entry" + convert_to_string (id) + "\">\n");
    textblock.append ("<a href=\"expand\" id=\"expand" + convert_to_string (id) + "\">" + emoji_file_folder () + "</a>\n");
    textblock.append ("<a href=\"remove\" id=\"remove" + convert_to_string (id) + "\">" + emoji_wastebasket () + "</a>\n");
    textblock.append (link + "\n");
    textblock.append (category + "\n");
    textblock.append (modification + "\n");
    textblock.append ("</div>\n");
  }
  view.set_variable ("textblock", textblock);
  
  
  string loading = "\"" + translate("Loading ...") + "\"";
  string script = "var loading = " + loading + ";";
  config_logic_swipe_enabled (webserver_request, script);
  view.set_variable ("script", script);

  
  // Enable links to dismiss categories of notifications depending on whether there's anything to dismiss.
  if (!personal_ids.empty ()) view.enable_zone ("personal");
  if (!bible_ids.empty ()) view.enable_zone ("bible");
  
  
  // Add links to clear the notifications from the individual contributors.
  string dismissblock;
  vector <string> categories = database_modifications.getCategories ();
  for (auto & category : categories) {
    if (category == changes_personal_category ()) continue;
    if (category == changes_bible_category ()) continue;
    string user = category;
    vector <int> ids = database_modifications.getNotificationTeamIdentifiers (username, user, true);
    if (!ids.empty ()) {
      dismissblock.append ("<p>* <a href=\"?dismiss=");
      dismissblock.append (user);
      dismissblock.append ("\">");
      dismissblock.append (user);
      dismissblock.append (": ");
      dismissblock.append (translate("all of them"));
      dismissblock.append (": ");
      dismissblock.append (convert_to_string (ids.size ()));
      dismissblock.append ("</a></p>\n");
    }
  }
  view.set_variable ("dismissblock", dismissblock);

  
  // Add links to clear matching notifications of the various users.
  for (auto & category : categories) {
    if (category == changes_bible_category ()) continue;
    string user = category;
    vector <int> personal_ids = database_modifications.getNotificationTeamIdentifiers (username, user, true);
    string icon = category;
    if (category == changes_personal_category ()) icon = emoji_smiling_face_with_smiling_eyes ();
    if (!personal_ids.empty () && !bible_ids.empty ()) {
      view.add_iteration ("matching", { make_pair ("user", user), make_pair ("icon", icon) } );
    }
  }
  
  
  view.set_variable ("VERSION", config_logic_version ());

  
  if (touch) view.enable_zone ("touch");

  
  view.set_variable ("interlinks", changes_interlinks (webserver_request, changes_changes_url ()));
  
  
  page += view.render ("changes", "changes");
  
  
  page += Assets_Page::footer ();
  return page;
}
Beispiel #4
0
// Get Bibledit's version number.
const char * bibledit_get_version_number ()
{
  return config_logic_version ();
}