<% Response.Buffer=true %> <% '-- Fixed values dim page_id dim page_type dim ia_depth dim ia_sortOrder dim current_ia_parentid '-- Variable form values dim page_title dim ia_parentid dim show_on_nav dim visual_template '-- Process values dim hasMoved dim newIA_Depth dim newIA_SortOrder page_id = request.form("page_id") page_type = request.form("page_type") ia_depth = request.form("ia_depth") ia_sortOrder = request.form("ia_sortOrder") current_ia_parentid = request.form("current_ia_parentid") page_title = request.form("page_title") ia_parentid = request.form("ia_parentid") show_on_nav = request.form("show_on_nav") visual_template = request.form("visual_template") '--Check for single quotes/apostrophes page_title = SQLSafe(page_title) hasMoved = false newIA_SortOrder = IA_SortOrder newIA_Depth = IA_Depth '--------------------------------------------------- '-- If the old IA_ParentID is not the same as the new IA_ParentID '-- we are moving parent so must update certain values '--------------------------------------------------- if not cint(current_ia_parentid) = cint(ia_parentid) then '--------------------------------------------------- '-- Before we do anything we have to be sure that we're not trying to move the node's '-- parent to itself or one of it's descendants '--------------------------------------------------- Dim newParentChecked newParentChecked = true '--Is the target parent the node itself if page_id = ia_parentid then newParentChecked = false end if call checkNewParent(page_id,ia_parentid) '--------------------------------------------------- '-- Failed the check send back '--------------------------------------------------- if newParentChecked = false then response.Redirect("ia.asp?mode=editPage&page_id=" & page_id &"&errorMsg=Please%20select%20a%20different%20parent") response.end '--------------------------------------------------- '-- All good to move '--------------------------------------------------- else '--------------------------------------------------- '-- First find the IA_Depth of the new parent and set the value of newIA_Depth to this + 1 '--------------------------------------------------- strSQL = "SELECT ia_depth FROM ia where ia_childid = " & ia_parentid set rs = LoadRSFromDB(strSQL) if not rs.eof then newIA_Depth = rs("ia_depth")+1 end if Set rs = Nothing '--------------------------------------------------- '--We need to update the IA_Depth and IA_SortOrder of all this node's decendents '--Collect children and update their IA_Depth and IA_SortOrder '--This function is recursive for children's children '--------------------------------------------------- call collectChildren(page_id,newIA_Depth) '--------------------------------------------------- '-- Now get the sort order - we will add this node as the last child of the new parent '-- so must first find the current last child's IA_sortOrder and then set the value of newIA_SortOrder to this + 100 '--------------------------------------------------- strSQL = "SELECT ia_sortorder FROM ia where ia_parentid = " & IA_ParentID & " ORDER BY IA_SortOrder DESC LIMIT 1" set rs = LoadRSFromDB(strSQL) if not rs.EOF then newIA_SortOrder = rs("IA_SortOrder") + 1 else newIA_SortOrder = 1 end if Set rs = Nothing '--------------------------------------------------- '-- NOW UPDATE THE IA_SORTORDER OF THE OLD SIBLINGS '--------------------------------------------------- dim oldSibRS dim updateSibSQL dim siblingIA_ID dim siblingIA_Sortorder strSQL = "SELECT ia_childid, ia_sortorder FROM ia where ia_parentid = " & current_ia_parentid & " AND ia_sortorder > " & IA_SortOrder set oldSibRS = LoadRSFromDB(strSQL) if not oldSibRS.EOF then Do While not oldSibRS.EOF siblingIA_ID = oldSibRS("ia_childid") siblingIA_Sortorder = oldSibRS("ia_sortorder") - 1 updateSibSQL = "UPDATE ia SET ia_sortorder='" & siblingIA_Sortorder & "' WHERE ia_childid=" & siblingIA_ID RunSQL updateSibSQL oldSibRS.MoveNext Loop end if Set oldSibRS = Nothing hasMoved = true end if end if '--Update the ia table strSQL = "UPDATE ia SET ia_parentid = '" & ia_parentid & "', ia_depth='" & newIA_Depth & "', ia_sortorder = '" & newIA_SortOrder & "' WHERE ia_childid =" & page_id RunSQL strSQL '--Update the pages table strSQL = "UPDATE pages SET show_on_nav = '" & show_on_nav & "' where page_id=" & page_id RunSQL strSQL '-- --------------------------------------------------------------------------- '-- Create a new friendly URL for the new page '-- --------------------------------------------------------------------------- Dim friendlyURLString friendlyURLString = "" '-- Removed 22-02-08 'call createFriendlyURL(page_id,page_title) '--Update the page_info table strSQL = "UPDATE page_info SET page_title = '" & page_title & "', visual_template = '" & visual_template & "',friendly_url = '" & friendlyURLString & "' WHERE page_id=" & page_id & " AND language_ID = " & session("languageID") RunSQL strSQL '--------------------------------------------------- '-- Redirect back '--------------------------------------------------- if hasMoved = false then Response.Redirect("ia.asp?mode=editPage&page_id=" & page_id & "&editType=ia&confirmMsg=" & page_type & "%20info%20updated%20successfully") else response.redirect("tree_update.asp?openNodes=" & session("openNodeString") & "&page_id=" & page_id & "&newPage_id=" & page_id & "&mode=addNewNode") end if '--------------------------------------------------- '-- This function collects all decendants of the node we have moved '-- and then updates their IA_Depth '--------------------------------------------------- function collectChildren(parent_id,parentIA_Depth) dim ccRS dim ccSQL dim NextGenerationIA_Depth NextGenerationIA_Depth = parentIA_Depth + 1 ccSQL = "SELECT ia_childid FROM ia WHERE ia_parentid = " & parent_id set ccRS = LoadRSFromDB(ccSQL) if not ccRS.EOF then Do While not ccRS.EOF dim upDateSQL upDateSQL = "UPDATE ia SET ia_depth='" & NextGenerationIA_Depth & "' WHERE ia_childid=" & ccRS("ia_childid") 'response.write upDateSQL RunSQL upDateSQL call collectChildren(ccRS("ia_childid"),NextGenerationIA_Depth) ccRS.MoveNext Loop end if Set ccRS = Nothing end function '--------------------------------------------------- '-- '--------------------------------------------------- function checkNewParent(this_page_id,this_parent_id) Dim cpSQL Dim cpRS cpSQL = "SELECT ia_childid FROM ia WHERE ia_parentid = " & this_page_id set cpRS = LoadRSFromDB(cpSQL) if not cpRS.EOF then Do While not cpRS.EOF if cint(this_parent_id) = cint(cpRS("ia_childid")) then newParentChecked = false end if call checkNewParent(cpRS("ia_childid"),this_parent_id) cpRS.MoveNext Loop end if cpRS.Close Set cpRS = Nothing end function %>