root / htdocs / class / Network_Path.php @ 56f4bdf250e42ed8152b1b76967d3e5249a9354b
View | Annotate | Download (4.1 KB)
| 1 | <?php
|
|---|---|
| 2 | |
| 3 | /***************************************************************************
|
| 4 | * |
| 5 | * Copyright (c) by Andreas Unterkircher, unki@netshadow.at |
| 6 | * All rights reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | * |
| 22 | ***************************************************************************/ |
| 23 | |
| 24 | class Network_Path extends MsObject { |
| 25 | |
| 26 | /**
|
| 27 | * Network_Path constructor |
| 28 | * |
| 29 | * Initialize the Network_Path class |
| 30 | */ |
| 31 | public function __construct($id = null) |
| 32 | {
|
| 33 | parent::__construct($id, Array( |
| 34 | 'table_name' => 'network_paths', |
| 35 | 'col_name' => 'netpath', |
| 36 | 'child_names' => Array(
|
| 37 | 'chain' => 'chain', |
| 38 | ), |
| 39 | 'fields' => Array(
|
| 40 | 'netpath_idx' => 'integer', |
| 41 | 'netpath_name' => 'text', |
| 42 | 'netpath_if1' => 'integer', |
| 43 | 'netpath_if1_inside_gre' => 'text', |
| 44 | 'netpath_if2' => 'integer', |
| 45 | 'netpath_if2_inside_gre' => 'text', |
| 46 | 'netpath_position' => 'integer', |
| 47 | 'netpath_imq' => 'text', |
| 48 | 'netpath_active' => 'text', |
| 49 | 'netpath_host_idx' => 'integer', |
| 50 | ), |
| 51 | )); |
| 52 | |
| 53 | if(!isset($id) || empty($id)) { |
| 54 | $this->netpath_active = 'Y'; |
| 55 | } |
| 56 | |
| 57 | } // __construct()
|
| 58 | |
| 59 | /**
|
| 60 | * handle updates |
| 61 | */ |
| 62 | public function pre_save() |
| 63 | {
|
| 64 | global $ms, $db;
|
| 65 | |
| 66 | $max_pos = $db->db_fetchSingleRow("
|
| 67 | SELECT |
| 68 | MAX(netpath_position) as pos |
| 69 | FROM |
| 70 | ". MYSQL_PREFIX ."network_paths |
| 71 | WHERE |
| 72 | netpath_host_idx LIKE '". $ms->get_current_host_profile() ."' |
| 73 | ");
|
| 74 | |
| 75 | $this->netpath_position = ($max_pos->pos+1); |
| 76 | |
| 77 | $this->netpath_host_idx = $ms->get_current_host_profile();
|
| 78 | |
| 79 | return true; |
| 80 | |
| 81 | } // pre_save()
|
| 82 | |
| 83 | /**
|
| 84 | * get next chain position |
| 85 | * |
| 86 | * this function returns the next free chain position |
| 87 | * available for the actual network path. |
| 88 | * |
| 89 | */ |
| 90 | public function get_next_chain_position() |
| 91 | {
|
| 92 | global $ms, $db;
|
| 93 | |
| 94 | $max_pos = $db->db_fetchSingleRow("
|
| 95 | SELECT |
| 96 | MAX(chain_position) as pos |
| 97 | FROM |
| 98 | ". MYSQL_PREFIX ."chains |
| 99 | WHERE |
| 100 | chain_netpath_idx LIKE '". $this->id ."' |
| 101 | AND |
| 102 | chain_host_idx LIKE '". $ms->get_current_host_profile() ."' |
| 103 | ");
|
| 104 | |
| 105 | if(!empty($max_pos->pos)) |
| 106 | return ($max_pos->pos+1); |
| 107 | |
| 108 | return 0; |
| 109 | |
| 110 | } // get_next_chain_position()
|
| 111 | |
| 112 | public function post_save() |
| 113 | {
|
| 114 | global $ms, $db;
|
| 115 | |
| 116 | if(!isset($_POST['chain_active']) || empty($_POST['chain_active'])) |
| 117 | return true; |
| 118 | |
| 119 | $used = $_POST['used'];
|
| 120 | $chain_active = $_POST['chain_active'];
|
| 121 | |
| 122 | $chain_position = 1;
|
| 123 | |
| 124 | foreach($used as $use) { |
| 125 | |
| 126 | if(empty($use)) |
| 127 | continue;
|
| 128 | |
| 129 | // skip if not a valid value
|
| 130 | if(!is_numeric($use))
|
| 131 | continue;
|
| 132 | |
| 133 | $sth = $db->db_prepare("
|
| 134 | UPDATE |
| 135 | ". MYSQL_PREFIX ."chains |
| 136 | SET |
| 137 | chain_position = ? |
| 138 | WHERE |
| 139 | chain_idx LIKE ? |
| 140 | AND |
| 141 | chain_host_idx LIKE ? |
| 142 | ");
|
| 143 | |
| 144 | $db->db_execute($sth, array(
|
| 145 | $chain_position, |
| 146 | $use, |
| 147 | $ms->get_current_host_profile(), |
| 148 | )); |
| 149 | |
| 150 | $chain_position++; |
| 151 | |
| 152 | } |
| 153 | |
| 154 | return true; |
| 155 | |
| 156 | } // post_save()
|
| 157 | |
| 158 | public function post_delete() |
| 159 | {
|
| 160 | global $ms;
|
| 161 | |
| 162 | $ms->update_positions('networkpaths');
|
| 163 | |
| 164 | } // post_delete()
|
| 165 | |
| 166 | } // class Network_Path
|
| 167 | |
| 168 | ?> |
| 169 |