| | 195 | //removes a pinset from a route and shifts priority for all outbound routing pinsets |
|---|
| | 196 | function pinsets_adjustroute($route,$action,$routepinset='',$direction='',$newname='') { |
|---|
| | 197 | $priority = (int)substr($route,0,3); |
|---|
| | 198 | //create a selection of available pinsets |
|---|
| | 199 | $pinsets = pinsets_list(); |
|---|
| | 200 | // loop through all the pinsets |
|---|
| | 201 | if(is_array($pinsets)){ |
|---|
| | 202 | foreach($pinsets as $pinset) { |
|---|
| | 203 | |
|---|
| | 204 | // get the used_by field |
|---|
| | 205 | if(empty($pinset['used_by'])) { |
|---|
| | 206 | $usedby = ""; |
|---|
| | 207 | } else { |
|---|
| | 208 | $usedby = $pinset['used_by']; |
|---|
| | 209 | } |
|---|
| | 210 | |
|---|
| | 211 | // remove the target if it's already in this row's used_by field |
|---|
| | 212 | //$usedby = str_replace("routing_{$route}","",$usedby); |
|---|
| | 213 | |
|---|
| | 214 | // create an array from usedby |
|---|
| | 215 | $arrUsedby = explode(',',$usedby); |
|---|
| | 216 | |
|---|
| | 217 | for($i=0;$i<count($arrUsedby);$i++) { |
|---|
| | 218 | if (substr($arrUsedby[$i],0,8)=='routing_') { |
|---|
| | 219 | switch($action){ |
|---|
| | 220 | case 'delroute': |
|---|
| | 221 | if ($arrUsedby[$i] == "routing_{$route}") { |
|---|
| | 222 | unset($arrUsedby[$i]); |
|---|
| | 223 | } |
|---|
| | 224 | $usedbypriority = (int)substr($arrUsedby[$i],8,3); |
|---|
| | 225 | $usedbyroute = substr($arrUsedby[$i],12); |
|---|
| | 226 | if ($usedbypriority > $priority) { |
|---|
| | 227 | $newpriority = str_pad($usedbypriority - 1, 3, "0", STR_PAD_LEFT); |
|---|
| | 228 | $arrUsedby[$i] = 'routing_'.$newpriority.'-'.$usedbyroute; |
|---|
| | 229 | } |
|---|
| | 230 | break; |
|---|
| | 231 | case 'prioritizeroute'; |
|---|
| | 232 | $addpriority = ($direction=='up')?-1:1; |
|---|
| | 233 | $usedbypriority = (int)substr($arrUsedby[$i],8,3); |
|---|
| | 234 | $usedbyroute = substr($arrUsedby[$i],12); |
|---|
| | 235 | if ($priority + $addpriority == $usedbypriority) { |
|---|
| | 236 | $newpriority = str_pad($priority, 3, "0", STR_PAD_LEFT); |
|---|
| | 237 | $arrUsedby[$i] = 'routing_'.$newpriority.'-'.$usedbyroute; |
|---|
| | 238 | } |
|---|
| | 239 | if ($arrUsedby[$i] == "routing_{$route}") { |
|---|
| | 240 | $newpriority = str_pad($priority + $addpriority, 3, "0", STR_PAD_LEFT); |
|---|
| | 241 | $arrUsedby[$i] = 'routing_'.$newpriority.'-'.$usedbyroute; |
|---|
| | 242 | } |
|---|
| | 243 | |
|---|
| | 244 | break; |
|---|
| | 245 | case 'renameroute'; |
|---|
| | 246 | if ($arrUsedby[$i] == "routing_{$route}") { |
|---|
| | 247 | $newpriority = str_pad($priority, 3, "0", STR_PAD_LEFT); |
|---|
| | 248 | $arrUsedby[$i] = 'routing_'.$newpriority.'-'.$newname; |
|---|
| | 249 | } |
|---|
| | 250 | break; |
|---|
| | 251 | case 'editroute'; |
|---|
| | 252 | $usedbyroute = (int)substr($arrUsedby[$i],12); |
|---|
| | 253 | if ($arrUsedby[$i] == "routing_{$route}") { |
|---|
| | 254 | unset($arrUsedby[$i]); |
|---|
| | 255 | } |
|---|
| | 256 | break; |
|---|
| | 257 | } |
|---|
| | 258 | } |
|---|
| | 259 | } |
|---|
| | 260 | |
|---|
| | 261 | // save the route in the selected pin |
|---|
| | 262 | if ($routepinset == $pinset['pinsets_id'] && $action == 'editroute') { |
|---|
| | 263 | $arrUsedby[] = 'routing_'.$route; |
|---|
| | 264 | } |
|---|
| | 265 | |
|---|
| | 266 | // remove any duplicates |
|---|
| | 267 | $arrUsedby = array_values(array_unique($arrUsedby)); |
|---|
| | 268 | |
|---|
| | 269 | // create a new string |
|---|
| | 270 | $strUsedby = implode($arrUsedby,','); |
|---|
| | 271 | |
|---|
| | 272 | // Insure there's no leading or trailing commas |
|---|
| | 273 | $strUsedby = trim ($strUsedby, ','); |
|---|
| | 274 | |
|---|
| | 275 | |
|---|
| | 276 | // store the used_by column in the DB |
|---|
| | 277 | sql("UPDATE pinsets SET used_by = \"{$strUsedby}\" WHERE pinsets_id = \"{$pinset['pinsets_id']}\""); |
|---|
| | 278 | } |
|---|
| | 279 | } |
|---|
| | 280 | } |
|---|
| | 281 | |
|---|
| 237 | | |
|---|
| 238 | | // if routing was using post for the form (incl delete), i wouldn't need all these conditions |
|---|
| 239 | | if(isset($request['Submit']) || (isset($request['action']) && ($request['action'] == "delroute" || $request['action'] == "prioritizeroute"))) { |
|---|
| 240 | | // get all pinsets defined |
|---|
| 241 | | $pinsets = pinsets_list(); |
|---|
| 242 | | |
|---|
| 243 | | // loop through all the pinsets |
|---|
| 244 | | if(is_array($pinsets)){ |
|---|
| 245 | | foreach($pinsets as $pinset) { |
|---|
| 246 | | |
|---|
| 247 | | // get the used_by field |
|---|
| 248 | | if(empty($pinset['used_by'])) { |
|---|
| 249 | | $usedby = ""; |
|---|
| 250 | | } else { |
|---|
| 251 | | $usedby = $pinset['used_by']; |
|---|
| 252 | | } |
|---|
| 253 | | |
|---|
| 254 | | // remove the target if it's already in this row's used_by field |
|---|
| 255 | | $usedby = str_replace("{$request['display']}_{$viewing_itemid}","",$usedby); |
|---|
| 256 | | |
|---|
| 257 | | // create an array from usedby |
|---|
| 258 | | $arrUsedby = explode(',',$usedby); |
|---|
| 259 | | |
|---|
| 260 | | // add <targetmodule>_<viewing_itemid> to the array |
|---|
| 261 | | if(!empty($request['pinsets']) && ($request['pinsets'] == $pinset['pinsets_id'])) |
|---|
| 262 | | $arrUsedby[] = "{$request['display']}_{$viewing_itemid}"; |
|---|
| 263 | | |
|---|
| 264 | | // remove any duplicates |
|---|
| 265 | | $arrUsedby = array_values(array_unique($arrUsedby)); |
|---|
| 266 | | |
|---|
| 267 | | // create a new string |
|---|
| 268 | | $strUsedby = implode($arrUsedby,','); |
|---|
| 269 | | |
|---|
| 270 | | // Insure there's no leading or trailing commas |
|---|
| 271 | | $strUsedby = trim ($strUsedby, ','); |
|---|
| 272 | | |
|---|
| 273 | | // store the used_by column in the DB |
|---|
| 274 | | sql("UPDATE pinsets SET used_by = \"{$strUsedby}\" WHERE pinsets_id = \"{$pinset['pinsets_id']}\""); |
|---|
| 275 | | } |
|---|
| 276 | | } |
|---|
| 277 | | } |
|---|
| 278 | | } |
|---|
| | 329 | switch ($request['display']) { |
|---|
| | 330 | case 'routing': |
|---|
| | 331 | // if routing was using post for the form (incl delete), i wouldn't need all these conditions |
|---|
| | 332 | // if(isset($request['Submit']) || (isset($request['action']) && ($request['action'] == "delroute" || $request['action'] == "prioritizeroute" || $request['action'] == "renameroute"))) { |
|---|
| | 333 | |
|---|
| | 334 | $action = (isset($request['action']))?$request['action']:null; |
|---|
| | 335 | $route = $viewing_itemid; |
|---|
| | 336 | if (isset($request['reporoutekey']) && $action == 'prioritizeroute') { |
|---|
| | 337 | $outbound_routes = core_routing_getroutenames(); |
|---|
| | 338 | $route = $outbound_routes[(int)$request['reporoutekey']][0]; |
|---|
| | 339 | } |
|---|
| | 340 | if (isset($request['Submit']) ) { |
|---|
| | 341 | $action = (isset($action))?$action:'editroute'; |
|---|
| | 342 | } |
|---|
| | 343 | if (isset($action)) { |
|---|
| | 344 | $direction = (isset($request['reporoutedirection']))?$request['reporoutedirection']:null; |
|---|
| | 345 | $newname = (isset($request['newroutename']))?$request['newroutename']:null; |
|---|
| | 346 | pinsets_adjustroute($route,$action,$request['pinsets'],$direction,$newname); |
|---|
| | 347 | } |
|---|
| | 348 | |
|---|
| | 349 | break; |
|---|
| | 350 | } |
|---|
| | 351 | } |
|---|
| | 352 | |
|---|