Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes seg fault with new user page.

Refactor loops and templates so less code is needed.
  • Loading branch information...
commit 16697d93ce7d17c03f0c7fb7b071b0c56cee3ec4 1 parent 3ad2852
@devfom devfom authored
View
14 modules/data/webadmin/tmpl/add_edit_user.tmpl
@@ -199,14 +199,14 @@
<? ENDIF ?>
</td>
<td align="center">
- <? IF LoadedByAllNetworks ?>
+ <? IF LoadedBySomeNetworks ?>
<input type="checkbox" name="loaded_by_network" id="loaded_by_net_<? VAR Name ?>" checked="checked" disabled="disabled"/>
- <? ELSE IF LoadedBySomeNetworks ?>
- <input type="checkbox" name="loaded_by_network" id="loaded_by_net_<? VAR Name ?>" checked="checked" disabled="disabled"/>
- <script type="text/javascript">
- var checkbox = document.getElementById("loaded_by_net_<? VAR Name ?>");
- checkbox.indeterminate = true;
- </script>
+ <? IF !LoadedByAllNetworks ?>
+ <script type="text/javascript">
+ var checkbox = document.getElementById("loaded_by_net_<? VAR Name ?>");
+ checkbox.indeterminate = true;
+ </script>
+ <? ENDIF ?>
<? ENDIF ?>
</td>
</tr>
View
28 modules/data/webadmin/tmpl/settings.tmpl
@@ -189,25 +189,25 @@
</td>
<td class="mod_descr"><? VAR Description ?></td>
<td align="center">
- <? IF LoadedByAllNetworks ?>
+ <? IF LoadedBySomeNetworks ?>
<input type="checkbox" name="loaded_by_network" id="loaded_by_net_<? VAR Name ?>" checked="checked" disabled="disabled"/>
- <? ELSE IF LoadedBySomeNetworks ?>
- <input type="checkbox" name="loaded_by_network" id="loaded_by_net_<? VAR Name ?>" checked="checked" disabled="disabled"/>
- <script type="text/javascript">
- var checkbox = document.getElementById("loaded_by_net_<? VAR Name ?>");
- checkbox.indeterminate = true;
- </script>
+ <? IF !LoadedByAllNetworks ?>
+ <script type="text/javascript">
+ var checkbox = document.getElementById("loaded_by_net_<? VAR Name ?>");
+ checkbox.indeterminate = true;
+ </script>
+ <? ENDIF ?>
<? ENDIF ?>
</td>
<td align="center">
- <? IF LoadedByAllUsers ?>
- <input type="checkbox" name="loaded_by_user" id="loaded_by_user_<? VAR Name ?>" checked="checked" disabled="disabled"/>
- <? ELSE IF LoadedBySomeUsers ?>
+ <? IF LoadedBySomeUsers ?>
<input type="checkbox" name="loaded_by_user" id="loaded_by_user_<? VAR Name ?>" checked="checked" disabled="disabled"/>
- <script type="text/javascript">
- var checkbox = document.getElementById("loaded_by_user_<? VAR Name ?>");
- checkbox.indeterminate = true;
- </script>
+ <? IF !LoadedByAllUsers ?>
+ <script type="text/javascript">
+ var checkbox = document.getElementById("loaded_by_user_<? VAR Name ?>");
+ checkbox.indeterminate = true;
+ </script>
+ <? ENDIF ?>
<? ENDIF ?>
</td>
</tr>
View
80 modules/webadmin.cpp
@@ -749,7 +749,7 @@ class CWebAdminMod : public CModule {
if (pModule) {
l["Checked"] = "true";
l["Args"] = pModule->GetArgs();
- }
+ }
}
// Check if module is loaded globally
@@ -1215,8 +1215,21 @@ class CWebAdminMod : public CModule {
l["ArgsHelpText"] = Info.GetArgsHelpText();
CModule *pModule = NULL;
- if (pUser)
+ if (pUser) {
pModule = pUser->GetModules().FindModule(Info.GetName());
+ // Check if module is loaded by all or some networks
+ const vector<CIRCNetwork*>& userNetworks = pUser->GetNetworks();
+ unsigned int networksWithRenderedModuleCount = 0;
+ for (unsigned int networkIndex = 0; networkIndex < userNetworks.size(); ++networkIndex) {
+ const CIRCNetwork* pCurrentNetwork = userNetworks[networkIndex];
+ const CModules& networkModules = pCurrentNetwork->GetModules();
+ if (networkModules.FindModule(Info.GetName())) {
+ networksWithRenderedModuleCount++;
+ }
+ }
+ l["LoadedByAllNetworks"] = CString(networksWithRenderedModuleCount == userNetworks.size());
+ l["LoadedBySomeNetworks"] = CString(networksWithRenderedModuleCount != 0);
+ }
if (pModule) {
l["Checked"] = "true";
l["Args"] = pModule->GetArgs();
@@ -1228,23 +1241,6 @@ class CWebAdminMod : public CModule {
// Check if module is loaded globally
l["LoadedGlobally"] = CString(CZNC::Get().GetModules().FindModule(Info.GetName()) != NULL);
- // Check if module is loaded by all or some networks
- const vector<CIRCNetwork*>& userNetworks = pUser->GetNetworks();
- unsigned int networksWithRenderedModuleCount = 0;
- for (unsigned int networkIndex = 0; networkIndex < userNetworks.size(); ++networkIndex) {
- const CIRCNetwork* pCurrentNetwork = userNetworks[networkIndex];
- const CModules& networkModules = pCurrentNetwork->GetModules();
- for (unsigned int networkModuleIndex = 0; networkModuleIndex < networkModules.size(); ++networkModuleIndex) {
- const CModule* pCurModule = networkModules[networkModuleIndex];
- if (Info.GetName() == pCurModule->GetModName()) {
- networksWithRenderedModuleCount++;
- }
- }
- }
- l["LoadedByAllNetworks"] = CString(networksWithRenderedModuleCount == userNetworks.size());
- const bool isLoadedBySomeNetworks = (networksWithRenderedModuleCount != 0) && (networksWithRenderedModuleCount < userNetworks.size());
- l["LoadedBySomeNetworks"] = CString(isLoadedBySomeNetworks);
-
if (!spSession->IsAdmin() && pUser && pUser->DenyLoadMod()) {
l["Disabled"] = "true";
}
@@ -1653,42 +1649,34 @@ class CWebAdminMod : public CModule {
l["HasArgs"] = CString(Info.GetHasArgs());
l["ArgsHelpText"] = Info.GetArgsHelpText();
- // Check if the module is loaded by all or some users and collect all available networks for future processing
- vector<CIRCNetwork*> allNetworks;
+ // Check if the module is loaded by all or some users, and/or by all or some networks
unsigned int usersWithRenderedModuleCount = 0;
+ unsigned int networksWithRenderedModuleCount = 0;
+ unsigned int networksCount = 0;
const map<CString,CUser*>& allUsers = CZNC::Get().GetUserMap();
- allNetworks.reserve(allUsers.size()); // Reserve for at least one network per scene
- for (map<CString,CUser*>::const_iterator usersIt = allUsers.begin(); usersIt != allUsers.end(); ++usersIt) {
+ for (map<CString,CUser*>::const_iterator usersIt = allUsers.begin(); usersIt != allUsers.end(); ++usersIt) {
const CUser& User = *usersIt->second;
- const vector<CIRCNetwork*>& userNetworks = User.GetNetworks();
- allNetworks.insert(allNetworks.end(), userNetworks.begin(), userNetworks.end());
+
+ // Count users which has loaded a render module
const CModules& userModules = User.GetModules();
- for (unsigned int userModuleIndex = 0; userModuleIndex < userModules.size(); ++userModuleIndex) {
- const CModule* pCurModule = userModules[userModuleIndex];
- if (Info.GetName() == pCurModule->GetModName()) {
- usersWithRenderedModuleCount++;
- }
+ if (userModules.FindModule(Info.GetName())) {
+ usersWithRenderedModuleCount++;
}
- }
- l["LoadedByAllUsers"] = CString(usersWithRenderedModuleCount == allUsers.size());
- const bool isLoadedBySomeUsers = (usersWithRenderedModuleCount != 0) && (usersWithRenderedModuleCount < allUsers.size());
- l["LoadedBySomeUsers"] = CString(isLoadedBySomeUsers);
-
- // Check if module is loaded by all or some networks
- unsigned int networksWithRenderedModuleCount = 0;
- for (unsigned int networkIndex = 0; networkIndex < allNetworks.size(); ++networkIndex) {
- const CIRCNetwork* pCurrentNetwork = allNetworks[networkIndex];
- const CModules& networkModules = pCurrentNetwork->GetModules();
- for (unsigned int networkModuleIndex = 0; networkModuleIndex < networkModules.size(); ++networkModuleIndex) {
- const CModule* pCurModule = networkModules[networkModuleIndex];
- if (Info.GetName() == pCurModule->GetModName()) {
+ // Count networks which has loaded a render module
+ const vector<CIRCNetwork*>& userNetworks = User.GetNetworks();
+ networksCount += userNetworks.size();
+ for (unsigned int networkIndex = 0; networkIndex < userNetworks.size(); ++networkIndex)
+ {
+ const CIRCNetwork *pCurrentNetwork = userNetworks[networkIndex];
+ if (pCurrentNetwork->GetModules().FindModule(Info.GetName())) {
networksWithRenderedModuleCount++;
}
}
}
- l["LoadedByAllNetworks"] = CString(networksWithRenderedModuleCount == allNetworks.size());
- const bool isLoadedBySomeNetworks = (networksWithRenderedModuleCount != 0) && (networksWithRenderedModuleCount < allNetworks.size());
- l["LoadedBySomeNetworks"] = CString(isLoadedBySomeNetworks);
+ l["LoadedByAllUsers"] = CString(usersWithRenderedModuleCount == allUsers.size());
+ l["LoadedBySomeUsers"] = CString(usersWithRenderedModuleCount != 0);
+ l["LoadedByAllNetworks"] = CString(networksWithRenderedModuleCount == networksCount);
+ l["LoadedBySomeNetworks"] = CString(networksWithRenderedModuleCount != 0);
}
return true;
Please sign in to comment.
Something went wrong with that request. Please try again.