| 
									
										
										
										
											2010-09-03 13:32:11 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # enable/disable ports/interfaces on devices.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-16 18:28:52 +00:00
										 |  |  | $device_id = intval($_POST['device']); | 
					
						
							| 
									
										
										
										
											2010-09-03 13:32:11 +00:00
										 |  |  | $rows_updated = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-16 18:28:52 +00:00
										 |  |  | foreach ($_POST as $key => $val) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-03-21 10:39:54 +00:00
										 |  |  |   if (strncmp($key,"oldign_",7) == 0) | 
					
						
							| 
									
										
										
										
											2011-03-16 18:28:52 +00:00
										 |  |  |   { | 
					
						
							|  |  |  |     # Interface identifier passed as part of the field name
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-16 13:25:50 +00:00
										 |  |  |     $port_id = intval(substr($key,7)); | 
					
						
							| 
									
										
										
										
											2011-03-16 18:28:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-21 10:39:54 +00:00
										 |  |  |     $oldign = intval($val) ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2012-05-16 13:25:50 +00:00
										 |  |  |     $newign = $_POST['ignore_'.$port_id] ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2011-03-16 18:28:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # As checkboxes are not posted when unset - we effectively need to do a diff to work
 | 
					
						
							|  |  |  |     # out a set->unset case.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-21 10:39:54 +00:00
										 |  |  |     if ($oldign == $newign) | 
					
						
							| 
									
										
										
										
											2011-03-16 18:28:52 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-03-17 11:29:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-16 13:25:50 +00:00
										 |  |  |     $n = dbUpdate(array('ignore' => $newign), 'ports', '`device_id` = ? AND `port_id` = ?', array($device_id, $port_id)); | 
					
						
							| 
									
										
										
										
											2011-03-21 10:39:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if ($n <0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       $rows_updated = -1; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $rows_updated += $n; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   elseif (strncmp($key,"olddis_",7) == 0) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     # Interface identifier passed as part of the field name
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-16 13:25:50 +00:00
										 |  |  |     $port_id = intval(substr($key,7)); | 
					
						
							| 
									
										
										
										
											2011-03-21 10:39:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $olddis = intval($val) ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2012-05-16 13:25:50 +00:00
										 |  |  |     $newdis = $_POST['disabled_'.$port_id] ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2011-03-21 10:39:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # As checkboxes are not posted when unset - we effectively need to do a diff to work
 | 
					
						
							|  |  |  |     # out a set->unset case.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($olddis == $newdis) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-16 13:25:50 +00:00
										 |  |  |     $n = dbUpdate(array('disabled' => $newdis), 'ports', '`device_id` = ? AND `port_id` = ?', array($device_id, $port_id)); | 
					
						
							| 
									
										
										
										
											2011-03-16 18:28:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if ($n <0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       $rows_updated = -1; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-03-17 11:29:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-16 18:28:52 +00:00
										 |  |  |     $rows_updated += $n; | 
					
						
							| 
									
										
										
										
											2010-09-03 13:32:11 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-03-16 18:28:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ($rows_updated > 0) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   $update_message =  $rows_updated . " Device record updated."; | 
					
						
							|  |  |  |   $updated = 1; | 
					
						
							|  |  |  | } elseif ($rows_updated = '-1') { | 
					
						
							|  |  |  |   $update_message = "Device record unchanged. No update necessary."; | 
					
						
							|  |  |  |   $updated = -1; | 
					
						
							|  |  |  | } else { | 
					
						
							|  |  |  |   $update_message = "Device record update error."; | 
					
						
							|  |  |  |   $updated = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-21 10:39:54 +00:00
										 |  |  | ?>
 |