| 54 | | $i = $i + 1; |
|---|
| 55 | | $sql = "update customcontexts_includes_list set missing = 0, sort = $i where context = '$section' and include = '$include'"; |
|---|
| 56 | | $db->query($sql); |
|---|
| 57 | | //fix prioritized contexts , description = '$include' |
|---|
| 58 | | $sql = "update customcontexts_includes_list set include = '$include', description = '$include', missing = 0, sort = $i where missing = 1 and context = '$section' and substring(include,1,6) = 'outrt-' and substring(include,10) = substring('$include',10)"; |
|---|
| 59 | | $db->query($sql); |
|---|
| 60 | | //fix allowed prioritized contexts (i did not do , sort = $i, maybe i should) context = '$section' and |
|---|
| 61 | | $sql = "update customcontexts_includes set include = '$include' where substr(include,1,6) = 'outrt-' and substr(include,10) = substr('$include',10)"; |
|---|
| | 55 | $sql = "update customcontexts_includes_list set missing = 0, sort = $i, description = '$include[comment]' where context = '$section' and include = '$include[include]'"; |
|---|
| 95 | | |
|---|
| 96 | | //this is to catch any rename reorder or delete route, so i can fix custom contexts |
|---|
| 97 | | function customcontexts_hookProcess_core($viewing_itemid, $request) { |
|---|
| 98 | | switch ($request['display']) { |
|---|
| 99 | | case 'routing': |
|---|
| 100 | | if(isset($request['Submit'])) { |
|---|
| 101 | | // $route = substr($viewing_itemid,4); |
|---|
| 102 | | // $priority = (int)(substr($viewing_itemid,0,3)); |
|---|
| 103 | | } |
|---|
| 104 | | switch ($request['action']) { |
|---|
| 105 | | case 'delroute': |
|---|
| 106 | | // $route = substr($viewing_itemid,4); |
|---|
| 107 | | $priority = (int)(substr($viewing_itemid,0,3)); |
|---|
| 108 | | customcontexts_routing_prioritize($request['action'],$priority); |
|---|
| 109 | | break; |
|---|
| 110 | | case 'prioritizeroute': |
|---|
| 111 | | $fullroute = $viewing_itemid; |
|---|
| 112 | | if (isset($request['reporoutekey'])) { |
|---|
| 113 | | $outbound_routes = core_routing_getroutenames(); |
|---|
| 114 | | $fullroute = $outbound_routes[(int)$request['reporoutekey']][0]; |
|---|
| 115 | | } |
|---|
| 116 | | // $route = substr($fullroute,4); |
|---|
| 117 | | $priority = (int)(substr($fullroute,0,3)); |
|---|
| 118 | | $direction = $request['reporoutedirection']; |
|---|
| 119 | | customcontexts_routing_prioritize($request['action'],$priority,$direction); |
|---|
| 120 | | break; |
|---|
| 121 | | case 'renameroute'; |
|---|
| 122 | | $newname = $request['newroutename']; |
|---|
| 123 | | $route = $viewing_itemid; |
|---|
| 124 | | $priority = (substr($viewing_itemid,0,3)); |
|---|
| 125 | | $fullnewname = 'outrt-'.$priority.'-'.$newname; |
|---|
| 126 | | $fullroutename = 'outrt-'.$route; |
|---|
| 127 | | customcontexts_routing_editname($fullroutename,$fullnewname); |
|---|
| 128 | | break; |
|---|
| 129 | | default: |
|---|
| 130 | | |
|---|
| 131 | | break; |
|---|
| 132 | | } |
|---|
| 133 | | break; |
|---|
| 134 | | } |
|---|
| 135 | | } |
|---|
| 136 | | |
|---|
| 137 | | function customcontexts_routing_editname($route,$newname) { |
|---|
| 138 | | global $db; |
|---|
| 139 | | //fix renamed contexts , description = '$include' |
|---|
| 140 | | $sql = "update customcontexts_includes_list set include = '$newname', description = '$newname', missing = 0 where context = 'outbound-allroutes' and include = '$route'"; |
|---|
| 141 | | $db->query($sql); |
|---|
| 142 | | //fix allowed renamed contexts (i did not do , sort = $i, maybe i should) context = 'outbound-allroutes' and |
|---|
| 143 | | $sql = "update customcontexts_includes set include = '$newname' where include = '$route'"; |
|---|
| 144 | | $db->query($sql); |
|---|
| 145 | | } |
|---|
| 146 | | |
|---|
| 147 | | function customcontexts_routing_prioritize($action,$priority,$direction=null) { |
|---|
| 148 | | global $db; |
|---|
| 149 | | $outbound_routes = core_routing_getroutenames(); |
|---|
| 150 | | foreach ($outbound_routes as $route) { |
|---|
| 151 | | $routename = $route[0]; |
|---|
| 152 | | $routepriority = (int)(substr($routename,0,3)); |
|---|
| 153 | | switch ($action) { |
|---|
| 154 | | case 'prioritizeroute': |
|---|
| 155 | | $addpriority = ($direction=='up')?-1:1; |
|---|
| 156 | | if ($priority + $addpriority == $routepriority) { |
|---|
| 157 | | $newpriority = str_pad($priority, 3, "0", STR_PAD_LEFT); |
|---|
| 158 | | $newroute = 'outrt-'.$newpriority.'-'.substr($routename,4); |
|---|
| 159 | | } elseif ($priority == $routepriority) { |
|---|
| 160 | | $newpriority = str_pad($priority + $addpriority, 3, "0", STR_PAD_LEFT); |
|---|
| 161 | | $newroute = 'outrt-'.$newpriority.'-'.substr($routename,4); |
|---|
| 162 | | } |
|---|
| 163 | | if (isset($newroute)) { |
|---|
| 164 | | //fix prioritized contexts , description = '$newroute' |
|---|
| 165 | | $sql = "update customcontexts_includes_list set include = '$newroute', description = '$newroute', missing = 0, sort = $newpriority where context = 'outbound-allroutes' and include= 'outrt-$routename'"; |
|---|
| 166 | | //echo $sql; |
|---|
| 167 | | $db->query($sql); |
|---|
| 168 | | //fix allowed prioritized contexts (i did not do , sort = $i, maybe i should) context = 'outbound-allroutes' and |
|---|
| 169 | | $sql = "update customcontexts_includes set include = '$newroute' where include = 'outrt-$routename'"; |
|---|
| 170 | | //echo $sql; |
|---|
| 171 | | $db->query($sql); |
|---|
| 172 | | } |
|---|
| 173 | | unset($newroute); |
|---|
| 174 | | break; |
|---|
| 175 | | case 'delroute'; |
|---|
| 176 | | if ($routepriority > $priority) { |
|---|
| 177 | | $newpriority = str_pad($routepriority - 1, 3, "0", STR_PAD_LEFT); |
|---|
| 178 | | $newroute = 'outrt-'.$newpriority.'-'.substr($routename,4); |
|---|
| 179 | | //fix prioritized contexts , description = '$newroute' |
|---|
| 180 | | $sql = "update customcontexts_includes_list set include = '$newroute', description = '$newroute', missing = 0, sort = $newpriority where context = 'outbound-allroutes' and include= 'outrt-$routename'"; |
|---|
| 181 | | //echo $sql; |
|---|
| 182 | | $db->query($sql); |
|---|
| 183 | | //fix allowed prioritized contexts (i did not do , sort = $i, maybe i should) context = 'outbound-allroutes' and |
|---|
| 184 | | $sql = "update customcontexts_includes set include = '$newroute' where include = 'outrt-$routename'"; |
|---|
| 185 | | //echo $sql; |
|---|
| 186 | | $db->query($sql); |
|---|
| 187 | | } |
|---|
| 188 | | unset($newroute); |
|---|
| 189 | | break; |
|---|
| 190 | | } |
|---|
| 191 | | } |
|---|
| 192 | | } |
|---|
| 193 | | |
|---|