Exemplo n.º 1
0
string client_index (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;
  
  Assets_View view;
  
  if (request->query.count ("disable")) {
    client_logic_enable_client (false);
    client_index_remove_all_users (request);
    Database_Config_General::setRepeatSendReceive (0);
    Database_Config_General::setUnsentBibleDataTime (0);
    Database_Config_General::setUnreceivedBibleDataTime (0);
  }
  
  bool connect = request->post.count ("connect");
  bool demo = request->query.count ("demo");
  if (connect || demo) {
    
    string address;
    if (connect) address = request->post ["address"];
    if (demo) address = demo_address ();
    if (address.find ("http") == string::npos) address = filter_url_set_scheme (address, false);
    Database_Config_General::setServerAddress (address);
    
    int port = convert_to_int (config_logic_http_network_port ());
    if (connect) port = convert_to_int (request->post ["port"]);
    if (demo) port = demo_port ();
    Database_Config_General::setServerPort (port);
    
    string user;
    if (connect) user = request->post ["user"];
    if (demo) user = session_admin_credentials ();
    
    string pass;
    if (connect) pass = request->post ["pass"];
    if (demo) pass = session_admin_credentials (); 

    string response = client_logic_connection_setup (user, md5 (pass));
    int iresponse = convert_to_int (response);

    if ((iresponse >= Filter_Roles::guest ()) && (iresponse <= Filter_Roles::admin ())) {
      // Enable client mode upon a successful connection.
      client_index_enable_client (request, user, pass, iresponse);
      // Feedback.
      view.set_variable ("success", translate("Connection is okay."));
    } else {
      view.set_variable ("error", translate ("Could not create a connection with Bibledit Cloud") + ": " + response);
    }
  }

  if (client_logic_client_enabled ())
    view.enable_zone ("clienton");
  else
    view.enable_zone ("clientoff");
  
  string address = Database_Config_General::getServerAddress ();
  view.set_variable ("address", address);
  
  int port = Database_Config_General::getServerPort ();
  view.set_variable ("port", convert_to_string (port));
  
  view.set_variable ("url", client_logic_link_to_cloud ("", ""));
  
  vector <string> users = request->database_users ()->getUsers ();
  for (auto & user : users) {
    int level = request->database_users()->get_level (user);
    view.set_variable ("role", Filter_Roles::text (level));
  }
  
  view.set_variable ("demo", demo_client_warning ());

  string page;

  // Since the role of the user may change after a successful connection to the server,
  // the menu generation in the header should be postponed till when the actual role is known.
  page = Assets_Page::header (translate ("Server"), webserver_request);
  
  page += view.render ("client", "index");
  
  page += Assets_Page::footer ();
  
  return page;
}
Exemplo n.º 2
0
string manage_index (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;

  string page;

  Assets_Header header = Assets_Header (translate("Manage"), webserver_request);
  header.addBreadCrumb (menu_logic_settings_menu (), menu_logic_settings_text ());
  page = header.run ();

  Assets_View view;
  string success;
  string error;
  
  
  // Force re-index Bibles.
  if (request->query ["reindex"] == "bibles") {
    Database_Config_General::setIndexBibles (true);
    tasks_logic_queue (REINDEXBIBLES, {"1"});
    redirect_browser (request, journal_index_url ());
    return "";
  }
  
  
  // Re-index consultation notes.
  if (request->query ["reindex"] == "notes") {
    Database_Config_General::setIndexNotes (true);
    tasks_logic_queue (REINDEXNOTES);
    redirect_browser (request, journal_index_url ());
    return "";
  }

  
  // Delete a font.
  string deletefont = request->query ["deletefont"];
  if (!deletefont.empty ()) {
    string font = filter_url_basename (deletefont);
    bool font_in_use = false;
    vector <string> bibles = request->database_bibles ()->getBibles ();
    for (auto & bible : bibles) {
      if (font == Fonts_Logic::getTextFont (bible)) font_in_use = true;
    }
    if (!font_in_use) {
      // Only delete a font when it is not in use.
      Fonts_Logic::erase (font);
    } else {
      error = translate("The font could not be deleted because it is in use");
    }
  }
  
  
  // Upload a font.
  if (request->post.count ("uploadfont")) {
    string filename = request->post ["filename"];
    string path = filter_url_create_root_path ("fonts", filename);
    string fontdata = request->post ["fontdata"];
    filter_url_file_put_contents (path, fontdata);
    success = translate("The font has been uploaded.");
  }
  

  // Assemble the font block html.
  vector <string> fonts = Fonts_Logic::getFonts ();
  vector <string> fontsblock;
  for (auto & font : fonts) {
    fontsblock.push_back ("<p>");
#ifndef CLIENT_PREPARED
    fontsblock.push_back ("<a href=\"?deletefont=" + font+ "\" title=\"" + translate("Delete font") + "\"> ✗ </a>");
#endif
    fontsblock.push_back (font);
    fontsblock.push_back ("</p>");
  }
  view.set_variable ("fontsblock", filter_string_implode (fontsblock, "\n"));

  
#ifdef CLIENT_PREPARED
  view.enable_zone ("client");
  view.set_variable ("cloudlink", client_logic_link_to_cloud (manage_index_url (), ""));
#else
  view.enable_zone ("server");
#endif
  
  
  view.set_variable ("success", success);
  view.set_variable ("error", error);
  page += view.render ("manage", "index");

  page += Assets_Page::footer ();
  
  return page;
}
Exemplo n.º 3
0
string user_notifications (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;
  Database_Config_User database_config_user = Database_Config_User (webserver_request);
  
  string id = request->post ["id"];

  if (id == "editednotessubscription") {
    bool state = !database_config_user.getSubscribeToConsultationNotesEditedByMe ();
    database_config_user.setSubscribeToConsultationNotesEditedByMe (state);
    return get_tick_box (state);
  }

  if (id == "anynotessubscription") {
    bool state = !database_config_user.getNotifyMeOfAnyConsultationNotesEdits ();
    database_config_user.setNotifyMeOfAnyConsultationNotesEdits (state);
    return get_tick_box (state);
  }

  if (id == "emailconfirmationyourposts") {
    bool state = !database_config_user.getNotifyMeOfMyPosts ();
    database_config_user.setNotifyMeOfMyPosts (state);
    return get_tick_box (state);
  }

  if (id == "subscribednotenotification") {
    bool state = !database_config_user.getSubscribedConsultationNoteNotification ();
    database_config_user.setSubscribedConsultationNoteNotification (state);
    return get_tick_box (state);
  }

  if (id == "notesassignment") {
    bool state = !database_config_user.getAssignedToConsultationNotesChanges ();
    database_config_user.setAssignedToConsultationNotesChanges (state);
    return get_tick_box (state);
  }
  
  if (id == "assignednotenotification") {
    bool state = !database_config_user.getAssignedConsultationNoteNotification ();
    database_config_user.setAssignedConsultationNoteNotification (state);
    return get_tick_box (state);
  }
  
  if (id == "suppressemailsfromnotesyouupdated") {
    bool state = !database_config_user.getSuppressMailFromYourUpdatesNotes ();
    database_config_user.setSuppressMailFromYourUpdatesNotes (state);
    return get_tick_box (state);
  }

  if (id == "assignednotesnotification") {
    bool state = !database_config_user.getAssignedNotesStatisticsNotification ();
    database_config_user.setAssignedNotesStatisticsNotification (state);
    return get_tick_box (state);
  }

  if (id == "subscribednotesnotification") {
    bool state = !database_config_user.getSubscribedNotesStatisticsNotification ();
    database_config_user.setSubscribedNotesStatisticsNotification (state);
    return get_tick_box (state);
  }

  if (id == "deletednotenotification") {
    bool state = !database_config_user.getDeletedConsultationNoteNotification ();
    database_config_user.setDeletedConsultationNoteNotification (state);
    return get_tick_box (state);
  }

  if (id == "postponenewnotesmails") {
    bool state = !database_config_user.getPostponeNewNotesMails ();
    database_config_user.setPostponeNewNotesMails (state);
    return get_tick_box (state);
  }

  if (id == "anyonechangesemailnotification") {
    bool state = !database_config_user.getBibleChangesNotification ();
    database_config_user.setBibleChangesNotification (state);
    return get_tick_box (state);
  }

  if (id == "anyonechangesonlinenotifications") {
    bool state = !database_config_user.getGenerateChangeNotifications ();
    database_config_user.setGenerateChangeNotifications (state);
    return get_tick_box (state);
  }

  if (id == "pendingchangenotifications") {
    bool state = !database_config_user.getPendingChangesNotification ();
    database_config_user.setPendingChangesNotification (state);
    return get_tick_box (state);
  }
  
  if (id == "mychangesemailnotifications") {
    bool state = !database_config_user.getUserChangesNotification ();
    database_config_user.setUserChangesNotification (state);
    return get_tick_box (state);
  }
  
  if (id == "mychangesonlinenotifications") {
    bool state = !database_config_user.getUserChangesNotificationsOnline ();
    database_config_user.setUserChangesNotificationsOnline (state);
    return get_tick_box (state);
  }

  if (id == "contributorschangesonlinenotifications") {
    bool state = !database_config_user.getContributorChangesNotificationsOnline ();
    database_config_user.setContributorChangesNotificationsOnline (state);
    return get_tick_box (state);
  }

  if (id == "biblechecksnotification") {
    bool state = !database_config_user.getBibleChecksNotification ();
    database_config_user.setBibleChecksNotification (state);
    return get_tick_box (state);
  }

  if (id == "sprintprogressnotification") {
    bool state = !database_config_user.getSprintProgressNotification ();
    database_config_user.setSprintProgressNotification (state);
    return get_tick_box (state);
  }
  
  string page;

  Assets_Header header = Assets_Header (translate("Notifications"), webserver_request);
  header.addBreadCrumb (menu_logic_settings_menu (), menu_logic_settings_text ());
  page = header.run ();

  Assets_View view;

  view.set_variable ("edited_notes_subscription", get_tick_box (database_config_user.getSubscribeToConsultationNotesEditedByMe ()));
  
  view.set_variable ("any_notes_subscription", get_tick_box (database_config_user.getNotifyMeOfAnyConsultationNotesEdits ()));
  
  view.set_variable ("email_confirmation_your_posts", get_tick_box (database_config_user.getNotifyMeOfMyPosts ()));
  
  view.set_variable ("subscription_notification", get_tick_box (database_config_user.getSubscribedConsultationNoteNotification ()));
  
  view.set_variable ("notes_assignment", get_tick_box (database_config_user.getAssignedToConsultationNotesChanges ()));
  
  view.set_variable ("assignment_notification", get_tick_box (database_config_user.getAssignedConsultationNoteNotification ()));
  
  view.set_variable ("suppress_mails_from_your_updates", get_tick_box (database_config_user.getSuppressMailFromYourUpdatesNotes ()));
  
  view.set_variable ("assigned_notes_notifications", get_tick_box (database_config_user.getAssignedNotesStatisticsNotification ()));
  
  view.set_variable ("subscribed_notes_notifications", get_tick_box (database_config_user.getSubscribedNotesStatisticsNotification ()));
  
  view.set_variable ("deleted_note_notification", get_tick_box (database_config_user.getDeletedConsultationNoteNotification ()));
  
  view.set_variable ("postpone_new_notes_mails", get_tick_box (database_config_user.getPostponeNewNotesMails ()));
  
  view.set_variable ("anyone_changes_email_notification", get_tick_box (database_config_user.getBibleChangesNotification ()));
  
  view.set_variable ("anyone_changes_online_notifications", get_tick_box (database_config_user.getGenerateChangeNotifications ()));
  
  view.set_variable ("pending_changes_notifications", get_tick_box (database_config_user.getPendingChangesNotification ()));
  
  view.set_variable ("my_changes_email_notifications", get_tick_box (database_config_user.getUserChangesNotification ()));
  
  view.set_variable ("my_changes_online_notifications", get_tick_box (database_config_user.getUserChangesNotificationsOnline ()));
  
  view.set_variable ("contributors_changes_online_notifications", get_tick_box (database_config_user.getContributorChangesNotificationsOnline ()));
  
  view.set_variable ("bible_checks_notification", get_tick_box (database_config_user.getBibleChecksNotification ()));
  
  view.set_variable ("sprint_progress_notification", get_tick_box (database_config_user.getSprintProgressNotification ()));
  
#ifdef CLIENT_PREPARED
  view.enable_zone ("client");
#else
  view.enable_zone ("server");
#endif

  view.set_variable ("url", client_logic_link_to_cloud (user_notifications_url (), translate("You can set the notifications in Bibledit Cloud.")));

  // The bits accessible to the user depends on the user's privileges.
  bool read_bible, write_bible;
  access_a_bible (webserver_request, read_bible, write_bible);
  if (read_bible) view.enable_zone ("readbible");
  if (write_bible) view.enable_zone ("writebible");
  if (Filter_Roles::access_control (webserver_request, Filter_Roles::consultant ()))
    view.enable_zone ("consultant");

  
  page += view.render ("user", "notifications");

  page += Assets_Page::footer ();

  return page;
}