Просмотр исходного кода

add ajax modla form for user mass change

rajven 2 лет назад
Родитель
Сommit
48f8d767c7

+ 8 - 9
html/admin/iplist/index.php

@@ -25,8 +25,8 @@ if ($rsubnet == 0) { $subnet_filter = ''; } else {
 
 
 $enabled_filter='';
 $enabled_filter='';
 if ($enabled>0) {
 if ($enabled>0) {
-    if ($enabled===2) { $enabled_filter = ' and User_auth.enabled=1 and User_list.enabled=1'; }
-    if ($enabled===1) { $enabled_filter = ' and (User_auth.enabled=0 or User_list.enabled=0)'; }
+    if ($enabled===2) { $enabled_filter = ' and User_auth.enabled=1'; }
+    if ($enabled===1) { $enabled_filter = ' and User_auth.enabled=0'; }
     }
     }
 
 
 
 
@@ -72,13 +72,12 @@ print_ip_submenu($page_url);
         <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
         <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
 	<input type="hidden" name="ApplyForAll" value="MassChange">
 	<input type="hidden" name="ApplyForAll" value="MassChange">
 	<table class="data" align=center>
 	<table class="data" align=center>
-	<tr><td><input type=checkbox class="putField" name="e_enabled" value='1'></td><td><?php print WEB_cell_enabled."&nbsp"; print_qa_select('a_enabled', 1);?></td></rr>
-	<tr><td><input type=checkbox class="putField" name="e_group_id" value='1'></td><td><?php print WEB_cell_filter."&nbsp";print_group_select($db_link, 'a_group_id', 0);?></td></rr>
-	<tr><td><input type=checkbox class="putField" name="e_queue_id" value='1'></td><td><?php print WEB_cell_shaper."&nbsp";print_queue_select($db_link, 'a_queue_id', 0);?></td></rr>
-	<tr><td><input type=checkbox class="putField" name="e_dhcp" value='1'></td><td><?php print "Dhcp&nbsp"; print_qa_select('a_dhcp', 1);?></td></rr>
-	<tr><td><input type=checkbox class="putField" name="e_dhcp_acl" value='1'></td><td><?php print "Dhcp-acl&nbsp";print_dhcp_acl_select('a_dhcp_acl','');?></td></rr>
-	<tr><td><input type=checkbox class="putField" name="e_traf" value='1'></td><td><?php print "Save traffic&nbsp"; print_qa_select('a_traf',1);?></td></rr>
-	</tr>
+	<tr><td><input type=checkbox class="putField" name="e_enabled" value='1'></td><td><?php print WEB_cell_enabled."&nbsp"; print_qa_select('a_enabled', 1);?></td></tr>
+	<tr><td><input type=checkbox class="putField" name="e_group_id" value='1'></td><td><?php print WEB_cell_filter."&nbsp";print_group_select($db_link, 'a_group_id', 0);?></td></tr>
+	<tr><td><input type=checkbox class="putField" name="e_queue_id" value='1'></td><td><?php print WEB_cell_shaper."&nbsp";print_queue_select($db_link, 'a_queue_id', 0);?></td></tr>
+	<tr><td><input type=checkbox class="putField" name="e_dhcp" value='1'></td><td><?php print "Dhcp&nbsp"; print_qa_select('a_dhcp', 1);?></td></tr>
+	<tr><td><input type=checkbox class="putField" name="e_dhcp_acl" value='1'></td><td><?php print "Dhcp-acl&nbsp";print_dhcp_acl_select('a_dhcp_acl','');?></td></tr>
+	<tr><td><input type=checkbox class="putField" name="e_traf" value='1'></td><td><?php print "Save traffic&nbsp"; print_qa_select('a_traf',1);?></td></tr>
 	</table>
 	</table>
 	<input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
 	<input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
     </form>
     </form>

+ 3 - 4
html/admin/iplist/nagios.php

@@ -57,10 +57,9 @@ print_ip_submenu($page_url);
         <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
         <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
         <input type="hidden" name="ApplyForAll" value="MassChange">
         <input type="hidden" name="ApplyForAll" value="MassChange">
         <table class="data" align=center>
         <table class="data" align=center>
-        <tr><td><input type=checkbox class="putField" name="e_nag_enabled" value='1'></td><td>Nagios&nbsp<?php print_qa_select('n_enabled', 1); ?></td></rr>
-        <tr><td><input type=checkbox class="putField" name="e_nag_link" value='1'></td><td>Link&nbsp<?php print_qa_select('n_link', 0); ?></td></rr>
-        <tr><td><input type=checkbox class="putField" name="e_nag_handler" value='1'></td><td>Event-handler&nbsp<?php print_nagios_handler_select('n_handler', ''); ?></td></rr>
-        </tr>
+        <tr><td><input type=checkbox class="putField" name="e_nag_enabled" value='1'></td><td>Nagios&nbsp<?php print_qa_select('n_enabled', 1); ?></td></tr>
+        <tr><td><input type=checkbox class="putField" name="e_nag_link" value='1'></td><td>Link&nbsp<?php print_qa_select('n_link', 0); ?></td></tr>
+        <tr><td><input type=checkbox class="putField" name="e_nag_handler" value='1'></td><td>Event-handler&nbsp<?php print_nagios_handler_select('n_handler', ''); ?></td></tr>
         </table>
         </table>
         <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
         <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
     </form>
     </form>

+ 48 - 72
html/admin/users/index.php

@@ -37,62 +37,8 @@ if (isset($_POST["create"])) {
     exit;
     exit;
 }
 }
 
 
-if (isset($_POST["ApplyForAll"])) {
-    $auth_id = $_POST["fid"];
-    $a_enabled = $_POST["a_enabled"] * 1;
-    $a_day = $_POST["a_day_q"] * 1;
-    $a_month = $_POST["a_month_q"] * 1;
-    $a_queue = $_POST["a_queue_id"] * 1;
-    $a_group = $_POST["a_group_id"] * 1;
-    $a_ou_id = $_POST["a_new_ou"] * 1;
-    $msg="Массовое изменение пользователей!";
-    foreach ($auth_id as $key => $val) {
-        if ($val) {
-            unset($auth);
-            unset($user);
-            $user['day_quota'] = $a_day;
-            $user['month_quota'] = $a_month;
-            $user['enabled'] = $a_enabled;
-            $user['ou_id'] = $a_ou_id;
-            $login = get_record($db_link,"User_list","id='$val'");
-            $msg.="Всем адресам доступа пользователя id: ".$val." login: ".$login['login']." установлено: \r\n";
-            $msg.= get_diff_rec($db_link,"User_list","id='$val'", $user, 1);
-            update_record($db_link, "User_list", "id='" . $val . "'", $user);
-            run_sql($db_link, "UPDATE User_auth SET ou_id=$a_ou_id, queue_id=$a_queue, filter_group_id=$a_group, enabled=$a_enabled, changed=1 WHERE user_id=".$val);
-        }
-    }
-    LOG_WARNING($db_link,$msg);
-    header("Location: " . $_SERVER["REQUEST_URI"]);
-    exit;
-}
-
-if (isset($_POST["remove"])) {
-    $fid = $_POST["fid"];
-    foreach ($fid as $key => $val) {
-        if ($val) {
-            $login = get_record($db_link,"User_list","id='$val'");
-            $device= get_record($db_link,"devices","user_id='$val'");
-	        if (!empty($device)) {
-                LOG_INFO($db_link, "Delete device for user id: $val");
-                unbind_ports($db_link, $device['id']);
-	            run_sql($db_link, "DELETE FROM connections WHERE device_id=".$device['id']);
-    	        run_sql($db_link, "DELETE FROM device_l3_interfaces WHERE device_id=".$device['id']);
-    		    run_sql($db_link, "DELETE FROM device_ports WHERE device_id=".$device['id']);
-                delete_record($db_link, "devices", "id=".$device['id']);
-		        }
-            run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=$val");
-            run_sql($db_link,"UPDATE User_auth SET deleted=1 WHERE user_id=$val");
-            delete_record($db_link, "User_list", "id=$val");
-            LOG_WARNING($db_link,"Deleted user id: $val login: ".$login['login']."\r\n");
-    	    }
-	}
-    header("Location: " . $_SERVER["REQUEST_URI"]);
-    exit;
-}
-
 unset($_POST);
 unset($_POST);
 
 
-
 ?>
 ?>
 <div id="cont">
 <div id="cont">
 
 
@@ -103,30 +49,55 @@ if ($msg_error) {
 
 
 
 
 ?>
 ?>
-<form name="def" action="index.php" method="post">
-<div><b><?php print WEB_cell_ou; ?> - </b>
-<?php print_ou_select($db_link, 'ou', $rou); 
-print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
+
+<form name="main">
+
+<div>
+<b><?php print WEB_cell_ou; ?> - </b>
+<?php print_ou_select($db_link, 'ou', $rou); print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
 <input type="submit" value="<?php echo WEB_btn_show; ?>">
 <input type="submit" value="<?php echo WEB_btn_show; ?>">
 </div>
 </div>
-<table class="data">
-<tr>
-<td><?php echo WEB_user_list_apply; ?></td>
-<td><?php print WEB_cell_enabled."&nbsp";print_qa_select('a_enabled', 0); ?></td>
-<td><?php print WEB_cell_filter."&nbsp";print_group_select($db_link, 'a_group_id', 0); ?></td>
-<td><?php print WEB_cell_shaper."&nbsp";print_queue_select($db_link, 'a_queue_id', 0); ?></td>
-<td><?php print WEB_cell_perday."&nbsp"; ?><input type="text" name="a_day_q" value="0" size=5></td>
-<td><?php print WEB_cell_permonth."&nbsp"; ?><input type="text" name="a_month_q" value="0" size=5></td>
-<td><?php print WEB_cell_ou."&nbsp";print_ou_select($db_link, 'a_new_ou', $rou); ?></td>
-<td>&nbsp<input type="submit" onclick="return confirm('<?php echo WEB_msg_apply_selected; ?>?')" name="ApplyForAll" value="<?php echo WEB_btn_apply; ?>"></td>
-</tr>
-</table>
-
+<br>
 <div>
 <div>
 <?php echo WEB_new_user."&nbsp"; ?>
 <?php echo WEB_new_user."&nbsp"; ?>
 <input type=text name=newlogin value="Unknown">
 <input type=text name=newlogin value="Unknown">
 <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
 <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
 </div>
 </div>
+</form>
+<br>
+<a class="mainButton" href="#modal"><?php print WEB_btn_apply_selected; ?></a>
+<div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
+ <div class="remodalBorder">
+  <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
+      <form id="formUserApply">
+        <h2 id="modal1Title"><?php print WEB_selection_title; ?></h2>
+        <input type="hidden" name="ApplyForAll" value="MassChange">
+        <table class="data" align=center>
+        <tr><td><input type=checkbox class="putField" name="e_enabled" value='1'></td><td><?php print WEB_cell_enabled."&nbsp";print_qa_select('a_enabled', 0); ?></td></tr>
+        <tr><td><input type=checkbox class="putField" name="e_group_id" value='1'></td><td><?php print WEB_cell_filter."&nbsp";print_group_select($db_link, 'a_group_id', 0); ?></td></tr>
+        <tr><td><input type=checkbox class="putField" name="e_queue_id" value='1'></td><td><?php print WEB_cell_shaper."&nbsp";print_queue_select($db_link, 'a_queue_id', 0); ?></td></tr>
+        <tr><td><input type=checkbox class="putField" name="e_day_q" value='1'></td><td><?php print WEB_cell_perday."&nbsp"; ?><input type="text" name="a_day_q" value="0" size=5></td></tr>
+        <tr><td><input type=checkbox class="putField" name="e_month_q" value='1'></td><td><?php print WEB_cell_permonth."&nbsp"; ?><input type="text" name="a_month_q" value="0" size=5></td></tr>
+        <tr><td><input type=checkbox class="putField" name="e_new_ou" value='1'></td><td><?php print WEB_cell_ou."&nbsp";print_ou_select($db_link, 'a_new_ou', $rou); ?></td></tr>
+        </table>
+        <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
+    </form>
+</div>
+</div>
+
+<a class="delButton" href="#modalDel"><?php print WEB_btn_delete; ?></a>
+<div class="remodal" data-remodal-options="closeOnConfirm: true" data-remodal-id="modalDel" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
+ <div class="remodalBorder">
+  <button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
+    <form id="formUserDel">
+        <h2 id="modal1Title"><?php print WEB_msg_delete_selected; ?></h2>
+        <input type="hidden" name="RemoveUser" value="MassChange">
+        <?php print_qa_select('f_deleted', 0);?><br><br>
+        <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
+    </form>
+</div>
+</div>
+
 
 
 <?php
 <?php
 
 
@@ -149,6 +120,8 @@ $sSQL = "SELECT U.id, U.login, U.fio, O.ou_name, U.enabled, U.day_quota, U.month
 
 
 ?>
 ?>
 
 
+<form id="def" name="def" action="index.php" method="post">
+
 <table class="data">
 <table class="data">
 <tr align="center">
 <tr align="center">
 <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
 <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
@@ -161,7 +134,6 @@ $sSQL = "SELECT U.id, U.login, U.fio, O.ou_name, U.enabled, U.day_quota, U.month
 <td><b><?php print WEB_cell_perday; ?></b></td>
 <td><b><?php print WEB_cell_perday; ?></b></td>
 <td><b><?php print WEB_cell_permonth; ?></b></td>
 <td><b><?php print WEB_cell_permonth; ?></b></td>
 <td><b><?php print WEB_cell_report; ?></b></td>
 <td><b><?php print WEB_cell_report; ?></b></td>
-<td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove" value="<?php echo WEB_btn_delete; ?>"></td>
 </tr>
 </tr>
 <?php
 <?php
 
 
@@ -209,6 +181,10 @@ print_navigation($page_url,$page,$displayed,$count_records[0],$total);
 <td class="off"><?php echo WEB_color_user_disabled; ?></td>
 <td class="off"><?php echo WEB_color_user_disabled; ?></td>
 <td class="error"><?php echo WEB_color_user_blocked; ?></td>
 <td class="error"><?php echo WEB_color_user_blocked; ?></td>
 </table>
 </table>
+
+<script src="/js/remodal/remodal.min.js"></script>
+<script src="/js/remodal-user.js"></script>
+
 <?php
 <?php
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
 ?>
 ?>

+ 55 - 0
html/js/remodal-user.js

@@ -0,0 +1,55 @@
+$(document).ready(function () {
+    $("form").submit(function () {
+	var formID = $(this).attr('id');
+
+        if (formID == "formUserApply") {
+            var formNm = $('#' + formID);
+	    var formTID = $('#def').attr('id');
+    	    var formTm = $('#' + formTID);
+	    var post_data = {};
+            post_data = formTm.serializeArray();
+	    post_data = post_data.concat(formNm.serializeArray());
+    	    $.ajax({
+        	type: "POST",
+        	url: "/utils/user_apply.php",
+        	data: post_data,
+        	success: function (data) {
+            	    $(formNm).html(data);
+		    location.href=formTm.attr("action");
+		    setTimeout(location.reload,1000);
+        	},
+        	error: function (jqXHR, text, error) {
+        	    $(formNm).html(error);
+		    location.href=formTm.attr("action");
+		    setTimeout(location.reload,5000);
+        	}
+	    });
+	    }
+
+        if (formID == "formUserDel") {
+            var formNm = $('#' + formID);
+	    var formTID = $('#def').attr('id');
+    	    var formTm = $('#' + formTID);
+	    var post_data = {};
+            post_data = formTm.serializeArray();
+	    post_data = post_data.concat(formNm.serializeArray());
+    	    $.ajax({
+        	type: "POST",
+        	url: "/utils/user_remove.php",
+        	data: post_data,
+        	success: function (data) {
+            	    $(formNm).html(data);
+		    location.href=formTm.attr("action");
+		    setTimeout(location.reload,1000);
+        	},
+        	error: function (jqXHR, text, error) {
+        	    $(formNm).html(error);
+		    location.href=formTm.attr("action");
+		    setTimeout(location.reload,5000);
+        	}
+	    });
+	    }
+
+        return true;
+    });
+});

+ 67 - 0
html/utils/user_apply.php

@@ -0,0 +1,67 @@
+<?php
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
+
+if (! defined("CONFIG")) die("Not defined");
+
+if (isset($_POST["ApplyForAll"])) {
+
+    $auth_id = $_POST["fid"];
+
+    if (empty($_POST["a_enabled"]))  { $_POST["a_enabled"]=0; }
+    if (empty($_POST["a_dhcp"]))     { $_POST["a_dhcp"]=0; }
+    if (empty($_POST["a_queue_id"])) { $_POST["a_queue_id"]=0; }
+    if (empty($_POST["a_group_id"])) { $_POST["a_group_id"]=0; }
+    if (empty($_POST["a_traf"]))     { $_POST["a_traf"]=0; }
+
+    if (empty($_POST["a_day_q"]))    { $_POST["a_day_q"]=0; }
+    if (empty($_POST["a_month_q"]))  { $_POST["a_month_q"]=0; }
+    if (empty($_POST["a_new_ou"]))   { $_POST["a_new_ou"]=0; }
+
+
+    $a_enabled  = $_POST["a_enabled"] * 1;
+    $a_dhcp     = $_POST["a_dhcp"] * 1;
+    $a_dhcp_acl = $_POST["a_dhcp_acl"];
+    $a_queue    = $_POST["a_queue_id"] * 1;
+    $a_group    = $_POST["a_group_id"] * 1;
+    $a_traf     = $_POST["a_traf"] * 1;
+    $a_day      = $_POST["a_day_q"] * 1;
+    $a_month    = $_POST["a_month_q"] * 1;
+    $a_ou_id    = $_POST["a_new_ou"] * 1;
+
+    $msg="Massive User change!";
+    LOG_WARNING($db_link,$msg);
+
+    $all_ok=1;
+    foreach ($auth_id as $key => $val) {
+        if ($val) {
+            unset($auth);
+            unset($user);
+	    if (isset($_POST["e_enabled"]))    { $auth['enabled'] = $a_enabled; $user['enabled'] = $a_enabled; }
+	    if (isset($_POST["e_group_id"]))   { $auth['filter_group_id'] = $a_group; }
+	    if (isset($_POST["e_queue_id"]))   { $auth['queue_id'] = $a_queue; }
+	    if (isset($_POST["e_dhcp"]))       { $auth['dhcp'] = $a_dhcp; }
+	    if (isset($_POST["e_dhcp_acl"]))   { $auth['dhcp_acl'] = $a_dhcp_acl; }
+	    if (isset($_POST["e_traf"]))       { $auth['save_traf'] = $a_traf; }
+	    if (isset($_POST["e_day_q"]))      { $user['day_quota'] = $a_day; }
+	    if (isset($_POST["e_month_q"]))    { $user['month_quota'] = $a_month; }
+	    if (isset($_POST["e_new_ou"]))     { $user['ou_id'] = $a_ou_id; $auth['ou_id'] = $a_ou_id; }
+
+            $login = get_record($db_link,"User_list","id='$val'");
+            $msg.=" For all ip user id: ".$val." login: ".$login['login']." set: ";
+            $msg.= get_diff_rec($db_link,"User_list","id='$val'", $user, 1);
+            $ret = update_record($db_link, "User_list", "id='" . $val . "'", $user);
+	    if (!$ret) { $all_ok = 0; }
+
+	    $auth_list = get_records_sql($db_link,"SELECT id FROM User_auth WHERE deleted=0 AND user_id=".$val);
+	    if (!empty($auth)) {
+		foreach ($auth_list as $row) {
+		    if (empty($row)) { continue; }
+        	    $ret = update_record($db_link, "User_auth", "id='" . $row["id"] . "'", $auth);
+		    if (!$ret) { $all_ok = 0; }
+		    }
+		}
+            }
+        }
+    if ($all_ok) { print "Success!"; } else { print "Fail!"; }
+    }

+ 31 - 0
html/utils/user_remove.php

@@ -0,0 +1,31 @@
+<?php
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
+
+if (! defined("CONFIG")) die("Not defined");
+
+if (isset($_POST["RemoveUser"]) and (isset($_POST["f_deleted"]))) {
+    if ($_POST["f_deleted"]*1) {
+        $fid = $_POST["fid"];
+	$all_ok = 1;
+        foreach ($fid as $key => $val) {
+	    if ($val) {
+    	        $login = get_record($db_link,"User_list","id='$val'");
+        	$device= get_record($db_link,"devices","user_id='$val'");
+                if (!empty($device)) {
+            	    LOG_INFO($db_link, "Delete device for user id: $val");
+            	    unbind_ports($db_link, $device['id']);
+                    run_sql($db_link, "DELETE FROM connections WHERE device_id=".$device['id']);
+            	    run_sql($db_link, "DELETE FROM device_l3_interfaces WHERE device_id=".$device['id']);
+                    run_sql($db_link, "DELETE FROM device_ports WHERE device_id=".$device['id']);
+            	    delete_record($db_link, "devices", "id=".$device['id']);
+                    }
+        	run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=$val");
+        	run_sql($db_link,"UPDATE User_auth SET deleted=1 WHERE user_id=$val");
+        	delete_record($db_link, "User_list", "id=$val");
+        	LOG_WARNING($db_link,"Deleted user id: $val login: ".$login['login']."\r\n");
+            }
+        }
+	if ($all_ok) { print "Success!"; } else { print "Fail!"; }
+	}
+    }