moved handling of POST actions to lists.inc

This commit is contained in:
Roland Gruber 2005-01-27 21:07:48 +00:00
parent 756cab7150
commit 91ba8e753a
4 changed files with 70 additions and 159 deletions

View File

@ -222,6 +222,62 @@ function listPrintTableHeader($scope, $searchFilter, $desc_array, $attr_array, $
echo "</tr>\n"; echo "</tr>\n";
} }
/**
* Manages all POST actions (e.g. button pressed) for the account lists.
*
* @param string $scope account type
*/
function listDoPost($scope) {
// check if button was pressed and if we have to add/delete an account
if ($_POST['new'] || $_POST['del'] || $_POST['pdf'] || $_POST['pdf_all']){
// add new account
if ($_POST['new']){
metaRefresh("../account/edit.php?type=" . $scope);
exit;
}
// delete account(s)
elseif ($_POST['del']){
// search for checkboxes
$accounts = array_keys($_POST, "on");
$_SESSION['delete_dn'] = $accounts;
if (sizeof($accounts) > 0) {
metaRefresh("../delete.php?type=" . $scope);
exit;
}
}
// PDF for selected accounts
elseif ($_POST['pdf']){
$pdf_structure = $_POST['pdf_structure'];
// search for checkboxes
$accounts = array_keys($_POST, "on");
$list = array();
// load accounts from LDAP
for ($i = 0; $i < sizeof($accounts); $i++) {
$_SESSION["accountPDF-$i"] = new accountContainer($scope, "accountPDF-$i");
$_SESSION["accountPDF-$i"]->load_account($accounts[$i]);
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
createModulePDF($list,$pdf_structure);
exit;
}
}
// PDF for all accounts
elseif ($_POST['pdf_all']){
$list = array();
for ($i = 0; $i < sizeof($_SESSION[$scope . 'info']); $i++) {
$_SESSION["accountPDF-$i"] = new accountContainer($scope, "accountPDF-$i");
$_SESSION["accountPDF-$i"]->load_account($_SESSION[$scope . 'info'][$i]['dn']);
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
createModulePDF($list,$_POST['pdf_structure']);
exit;
}
}
}
}
/** /**
* Returns the LDAP attribute names and their description for the user list * Returns the LDAP attribute names and their description for the user list

View File

@ -60,54 +60,7 @@ $_POST = $_POST + $_GET;
$info = $_SESSION[$scope . 'info']; $info = $_SESSION[$scope . 'info'];
$grp_units = $_SESSION['grp_units']; $grp_units = $_SESSION['grp_units'];
// check if button was pressed and if we have to add/delete a group listDoPost($scope);
if ($_POST['new_group'] || $_POST['del_group'] || $_POST['pdf_group'] || $_POST['pdf_all']){
// add new group
if ($_POST['new_group']){
metaRefresh("../account/edit.php?type=group");
exit;
}
// delete group(s)
elseif ($_POST['del_group']){
// search for checkboxes
$groups = array_keys($_POST, "on");
$_SESSION['delete_dn'] = $groups;
if (sizeof($groups) > 0) {
metaRefresh("../delete.php?type=group");
exit;
}
}
// PDF for selected groups
elseif ($_POST['pdf_group']){
$pdf_structure = $_POST['pdf_structure'];
// search for checkboxes
$groups = array_keys($_POST, "on");
$list = array();
// load groups from LDAP
for ($i = 0; $i < sizeof($groups); $i++) {
$_SESSION["accountPDF-$i"] = new accountContainer("group", "accountPDF-$i");
$_SESSION["accountPDF-$i"]->load_account($groups[$i]);
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
createModulePDF($list,$pdf_structure);
exit;
}
}
// PDF for all groups
elseif ($_POST['pdf_all']){
$list = array();
for ($i = 0; $i < sizeof($_SESSION[$scope . 'info']); $i++) {
$_SESSION["accountPDF-$i"] = new accountContainer("group", "accountPDF-$i");
$_SESSION["accountPDF-$i"]->load_account($_SESSION[$scope . 'info'][$i]['dn']);
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
createModulePDF($list,$_POST['pdf_structure']);
exit;
}
}
}
echo $_SESSION['header']; echo $_SESSION['header'];
echo "<title>listgroups</title>\n"; echo "<title>listgroups</title>\n";
@ -305,9 +258,9 @@ if (sizeof($grp_units) > 1) {
echo ("<p>&nbsp;</p>\n"); echo ("<p>&nbsp;</p>\n");
} }
echo ("<input type=\"submit\" name=\"new_group\" value=\"" . _("New Group") . "\">\n"); echo ("<input type=\"submit\" name=\"new\" value=\"" . _("New Group") . "\">\n");
if (sizeof($info) > 0) { if (sizeof($info) > 0) {
echo ("<input type=\"submit\" name=\"del_group\" value=\"" . _("Delete Group(s)") . "\">\n"); echo ("<input type=\"submit\" name=\"del\" value=\"" . _("Delete Group(s)") . "\">\n");
echo ("<br><br><br>\n"); echo ("<br><br><br>\n");
echo "<fieldset><legend><b>PDF</b></legend>\n"; echo "<fieldset><legend><b>PDF</b></legend>\n";
echo ("<b>" . _('PDF structure') . ":</b>&nbsp;&nbsp;<select name=\"pdf_structure\">\n"); echo ("<b>" . _('PDF structure') . ":</b>&nbsp;&nbsp;<select name=\"pdf_structure\">\n");
@ -316,7 +269,7 @@ if (sizeof($info) > 0) {
echo "<option value=\"" . $pdf_structure . "\"" . (($pdf_structure == 'default.xml') ? " selected" : "") . ">" . substr($pdf_structure,0,strlen($pdf_structure)-4) . "</option>"; echo "<option value=\"" . $pdf_structure . "\"" . (($pdf_structure == 'default.xml') ? " selected" : "") . ">" . substr($pdf_structure,0,strlen($pdf_structure)-4) . "</option>";
} }
echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;\n"; echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;\n";
echo ("<input type=\"submit\" name=\"pdf_group\" value=\"" . _("Create PDF for selected group(s)") . "\">\n"); echo ("<input type=\"submit\" name=\"pdf\" value=\"" . _("Create PDF for selected group(s)") . "\">\n");
echo "&nbsp;"; echo "&nbsp;";
echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all groups") . "\">\n"); echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all groups") . "\">\n");
echo "</fieldset>"; echo "</fieldset>";

View File

@ -60,54 +60,7 @@ $_POST = $_POST + $_GET;
$info = $_SESSION[$scope . 'info']; $info = $_SESSION[$scope . 'info'];
$hst_units = $_SESSION['hst_units']; $hst_units = $_SESSION['hst_units'];
// check if button was pressed and if we have to add/delete a host listDoPost($scope);
if ($_POST['new_host'] || $_POST['del_host'] || $_POST['pdf_host'] || $_POST['pdf_all']){
// add new host
if ($_POST['new_host']){
metaRefresh("../account/edit.php?type=host");
exit;
}
// delete host(s)
elseif ($_POST['del_host']){
// search for checkboxes
$hosts = array_keys($_POST, "on");
$_SESSION['delete_dn'] = $hosts;
if (sizeof($hosts) > 0) {
metaRefresh("../delete.php?type=host");
exit;
}
}
// PDF for selected hosts
elseif ($_POST['pdf_host']){
$pdf_structure = $_POST['pdf_structure'];
// search for checkboxes
$hosts = array_keys($_POST, "on");
$list = array();
// load hosts from LDAP
for ($i = 0; $i < sizeof($hosts); $i++) {
$_SESSION["accountPDF-$i"] = new accountContainer("host", "accountPDF-$i");
$_SESSION["accountPDF-$i"]->load_account($hosts[$i]);
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
createModulePDF($list,$pdf_structure);
exit;
}
}
// PDF for all hosts
elseif ($_POST['pdf_all']){
$list = array();
for ($i = 0; $i < sizeof($_SESSION[$scope . 'info']); $i++) {
$_SESSION["accountPDF-$i"] = new accountContainer("host", "accountPDF-$i");
$_SESSION["accountPDF-$i"]->load_account($_SESSION[$scope . 'info'][$i]['dn']);
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
createModulePDF($list,$_POST['pdf_structure']);
exit;
}
}
}
echo $_SESSION['header']; echo $_SESSION['header'];
echo "<title>listhosts</title>\n"; echo "<title>listhosts</title>\n";
@ -290,9 +243,9 @@ echo ("<p>&nbsp;</p>\n");
} }
// add/delete/PDF buttons // add/delete/PDF buttons
echo ("<input type=\"submit\" name=\"new_host\" value=\"" . _("New Host") . "\">\n"); echo ("<input type=\"submit\" name=\"new\" value=\"" . _("New Host") . "\">\n");
if (sizeof($info) > 0) { if (sizeof($info) > 0) {
echo ("<input type=\"submit\" name=\"del_host\" value=\"" . _("Delete Host(s)") . "\">\n"); echo ("<input type=\"submit\" name=\"del\" value=\"" . _("Delete Host(s)") . "\">\n");
echo ("<br><br><br>\n"); echo ("<br><br><br>\n");
echo "<fieldset><legend><b>PDF</b></legend>\n"; echo "<fieldset><legend><b>PDF</b></legend>\n";
echo ("<b>" . _('PDF structure') . ":</b>&nbsp;&nbsp;<select name=\"pdf_structure\">\n"); echo ("<b>" . _('PDF structure') . ":</b>&nbsp;&nbsp;<select name=\"pdf_structure\">\n");
@ -301,7 +254,7 @@ if (sizeof($info) > 0) {
echo "<option value=\"" . $pdf_structure . "\"" . (($pdf_structure == 'default.xml') ? " selected" : "") . ">" . substr($pdf_structure,0,strlen($pdf_structure)-4) . "</option>"; echo "<option value=\"" . $pdf_structure . "\"" . (($pdf_structure == 'default.xml') ? " selected" : "") . ">" . substr($pdf_structure,0,strlen($pdf_structure)-4) . "</option>";
} }
echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;\n"; echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;\n";
echo ("<input type=\"submit\" name=\"pdf_host\" value=\"" . _("Create PDF for selected host(s)") . "\">\n"); echo ("<input type=\"submit\" name=\"pdf\" value=\"" . _("Create PDF for selected host(s)") . "\">\n");
echo "&nbsp;"; echo "&nbsp;";
echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all hosts") . "\">\n"); echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all hosts") . "\">\n");
echo "</fieldset>"; echo "</fieldset>";

View File

@ -81,58 +81,7 @@ if ($trans_primary == "on" && !$_GET["norefresh"]) {
$info = $_SESSION[$scope . 'info']; $info = $_SESSION[$scope . 'info'];
$usr_units = $_SESSION['usr_units']; $usr_units = $_SESSION['usr_units'];
// check if button was pressed and if we have to add/delete a user or create a PDF listDoPost($scope);
if ($_POST['new_user'] || $_POST['del_user'] || $_POST['pdf_user'] || $_POST['pdf_all']){
// add new user
if ($_POST['new_user']){
metaRefresh("../account/edit.php?type=user");
exit;
}
// delete user(s)
elseif ($_POST['del_user']){
// search for checkboxes
while ($entry = @array_pop($_POST)) {
if (eregi("^uid=.*$", $entry)) $users[] = $entry;
}
$_SESSION['delete_dn'] = $users;
if (sizeof($users) > 0) {
metaRefresh("../delete.php?type=user");
exit;
}
}
// PDF for selected users
elseif ($_POST['pdf_user']){
$pdf_structure = $_POST['pdf_structure'];
// search for checkboxes
while ($entry = @array_pop($_POST)) {
if (eregi("^uid=.*$", $entry)) $users[] = $entry;
}
$list = array();
// load users from LDAP
for ($i = 0; $i < sizeof($users); $i++) {
$_SESSION["accountPDF-$i"] = new accountContainer("user", "accountPDF-$i");
$_SESSION["accountPDF-$i"]->load_account($users[$i]);
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
createModulePDF($list,$pdf_structure);
exit;
}
}
// PDF for all users
elseif ($_POST['pdf_all']){
$list = array();
for ($i = 0; $i < sizeof($_SESSION[$scope . 'info']); $i++) {
$_SESSION["accountPDF-$i"] = new accountContainer("user", "accountPDF-$i");
$_SESSION["accountPDF-$i"]->load_account($_SESSION[$scope . 'info'][$i]['dn']);
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
createModulePDF($list,$_POST['pdf_structure']);
exit;
}
}
}
echo $_SESSION['header']; echo $_SESSION['header'];
@ -278,11 +227,11 @@ if ($user_count != 0) {
// checkboxes if selectall = "yes" // checkboxes if selectall = "yes"
if ($_GET['selectall'] == "yes") { if ($_GET['selectall'] == "yes") {
echo "<td height=22 align=\"center\">\n<input onClick=\"user_click(this, '" . $info[$i]["dn"] . "')\" type=\"checkbox\" name=\"" . echo "<td height=22 align=\"center\">\n<input onClick=\"user_click(this, '" . $info[$i]["dn"] . "')\" type=\"checkbox\" name=\"" .
$info[$i]["dn"] . "\" value=\"" . $info[$i]["dn"] . "\" checked>\n</td>\n"; $info[$i]["dn"] . "\" checked>\n</td>\n";
} }
else { else {
echo "<td height=22 align=\"center\">\n<input onClick=\"user_click(this, '" . $info[$i]["dn"] . "')\" type=\"checkbox\" name=\"" . echo "<td height=22 align=\"center\">\n<input onClick=\"user_click(this, '" . $info[$i]["dn"] . "')\" type=\"checkbox\" name=\"" .
$info[$i]["dn"] . "\" value=\"" . $info[$i]["dn"] . "\">\n</td>\n"; $info[$i]["dn"] . "\">\n</td>\n";
} }
echo ("<td align='center'>\n<a href=\"../account/edit.php?type=user&amp;DN='" . $info[$i]["dn"] . "'\">" . echo ("<td align='center'>\n<a href=\"../account/edit.php?type=user&amp;DN='" . $info[$i]["dn"] . "'\">" .
_("Edit") . "</a>\n</td>\n"); _("Edit") . "</a>\n</td>\n");
@ -356,9 +305,9 @@ if (in_array("gidnumber", $attr_array)) {
echo ("<p>&nbsp;</p>\n"); echo ("<p>&nbsp;</p>\n");
// new/delete/PDF buttons // new/delete/PDF buttons
echo ("<input type=\"submit\" name=\"new_user\" value=\"" . _("New user") . "\">\n"); echo ("<input type=\"submit\" name=\"new\" value=\"" . _("New user") . "\">\n");
if ($user_count != 0) { if ($user_count != 0) {
echo ("<input type=\"submit\" name=\"del_user\" value=\"" . _("Delete user(s)") . "\">\n"); echo ("<input type=\"submit\" name=\"del\" value=\"" . _("Delete user(s)") . "\">\n");
echo ("<br><br><br>\n"); echo ("<br><br><br>\n");
echo "<fieldset><legend><b>PDF</b></legend>\n"; echo "<fieldset><legend><b>PDF</b></legend>\n";
echo ("<b>" . _('PDF structure') . ":</b>&nbsp;&nbsp;<select name=\"pdf_structure\">\n"); echo ("<b>" . _('PDF structure') . ":</b>&nbsp;&nbsp;<select name=\"pdf_structure\">\n");
@ -367,7 +316,7 @@ if ($user_count != 0) {
echo "<option value=\"" . $pdf_structure . "\"" . (($pdf_structure == 'default.xml') ? " selected" : "") . ">" . substr($pdf_structure,0,strlen($pdf_structure)-4) . "</option>"; echo "<option value=\"" . $pdf_structure . "\"" . (($pdf_structure == 'default.xml') ? " selected" : "") . ">" . substr($pdf_structure,0,strlen($pdf_structure)-4) . "</option>";
} }
echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;\n"; echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;\n";
echo ("<input type=\"submit\" name=\"pdf_user\" value=\"" . _("Create PDF for selected user(s)") . "\">\n"); echo ("<input type=\"submit\" name=\"pdf\" value=\"" . _("Create PDF for selected user(s)") . "\">\n");
echo "&nbsp;"; echo "&nbsp;";
echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all users") . "\">\n"); echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all users") . "\">\n");
echo "</fieldset>"; echo "</fieldset>";