I need to be able to reorder images in a photo gallery. So far it is
set to work by clicking arrows so that the images change order one at
a time. I need a mechanism so people can move it a specific number of
places as well via a text field or drop down. Something that would
allow you to move an image 100 places up or 50 places down because
clicking over and over to move an image 100 times wont work. Here is
the code.
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../config/config.asp" -->
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers="2,3"
MM_authFailedURL="adminlogin.asp"
' MM_grantAccess=false
MM_grantAccess=true
If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL")
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer &
"?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" &
Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>
<%
' *** Edit Operations: declare variables
MM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
Dim operation
operation=Request.QueryString("operation")
if (operation <> "") then
Dim aphotos__MMColParam
Dim new_sorting
Dim pid
pid=Request.QueryString("photoid")
Dim index
Dim value
aphotos__MMColParam = "1"
if (Request.QueryString("cat") <> "") then aphotos__MMColParam =
Request.QueryString("cat")
%>
<%
set MyConn=Server.CreateObject("adodb.connection")
MyConn.Open MM_photoalbum_STRING
set RS=MyConn.Execute("SELECT count(*) FROM photos WHERE category = '"
+ Replace(aphotos__MMColParam, "'", "''") + "'")
myrecordcount=RS(0)
RS.close
set RS=nothing
MyConn.close
Set MyConn=nothing
Redim new_sorting(myrecordcount)
set aphotos = Server.CreateObject("ADODB.Recordset")
aphotos.ActiveConnection = MM_photoalbum_STRING
aphotos.Source = "SELECT * FROM photos WHERE category = '" +
Replace(aphotos__MMColParam, "'", "''") + "' ORDER BY sortorder ASC"
aphotos.CursorType = 0
aphotos.CursorLocation = 2
aphotos.LockType = 3
aphotos.Open()
aphotos_numRows = 0
Dim curindex, nextindex
index = 1
While (NOT aphotos.EOF)
' Response.write aphotos.Fields.Item("photoid").Value & " "
' Response.write aphotos.Fields.Item("sortorder").Value & "<br>"
value = "" & aphotos.Fields.Item("photoid").Value
if value = pid then curindex=index
new_sorting(index)=value
aphotos.MoveNext
index = index + 1
wend
if operation="up" then nextindex=curindex + 1
if operation="down" then nextindex=curindex - 1
' Response.write "curindex:" & curindex & "<br>"
' Response.write "nextindex:" & nextindex & "<br>"
' Response.write "index:" & index & "<br>"
if (nextindex>=1) and (nextindex<index) then
' Response.Write "<hr>here"
Dim bak
bak=new_sorting(nextindex)
new_sorting(nextindex)=new_sorting(curindex)
new_sorting(curindex)=bak
For i = 1 to UBound(new_sorting, 1)
' Response.Write i & " - " & new_sorting(i) & "<br>"
query="update photos set sortorder='"& i & "' where photoid=" & new_sorting(i)
' response.write query & "<br>"
set MyConn=Server.CreateObject("adodb.connection")
MyConn.Open MM_photoalbum_STRING
MyConn.Execute(query)
MyConn.close
Set MyConn=nothing
Next
end if
end if
If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then
MM_editConnection = MM_photoalbum_STRING
MM_editTable = "photos"
MM_editColumn = "photoid"
MM_recordId = "" + Request.Form("MM_recordId") + ""
MM_editRedirectUrl = ""
MM_fieldsStr = "sort|value"
MM_columnsStr = "sortorder|none,none,NULL"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And
Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Update Record: construct a sql update statement and execute it
If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then
' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(i) & " = " & FormVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId
If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
set admin = Server.CreateObject("ADODB.Recordset")
admin.ActiveConnection = MM_photoalbum_STRING
admin.Source = "SELECT * FROM admin"
admin.CursorType = 0
admin.CursorLocation = 2
admin.LockType = 3
admin.Open()
admin_numRows = 0
%>
<%
set categorys = Server.CreateObject("ADODB.Recordset")
categorys.ActiveConnection = MM_photoalbum_STRING
categorys.Source = "SELECT * FROM cat"
categorys.CursorType = 0
categorys.CursorLocation = 2
categorys.LockType = 3
categorys.Open()
categorys_numRows = 0
%>
<%
Dim photos__MMColParam
photos__MMColParam = "1"
if (Request.QueryString("cat") <> "") then photos__MMColParam =
Request.QueryString("cat")
%>
<%
set photos = Server.CreateObject("ADODB.Recordset")
photos.ActiveConnection = MM_photoalbum_STRING
photos.Source = "SELECT * FROM photos WHERE category = '" +
Replace(photos__MMColParam, "'", "''") + "' ORDER BY sortorder DESC"
photos.CursorType = 0
photos.CursorLocation = 2
photos.LockType = 3
photos.Open()
photos_numRows = 0
%>
<%
Dim categories2__MMColParam
categories2__MMColParam = "1"
if (Request.QueryString("cat") <> "") then categories2__MMColParam =
Request.QueryString("cat")
%>
<%
set categories2 = Server.CreateObject("ADODB.Recordset")
categories2.ActiveConnection = MM_photoalbum_STRING
categories2.Source = "SELECT * FROM cat WHERE catid = " +
Replace(categories2__MMColParam, "'", "''") + ""
categories2.CursorType = 0
categories2.CursorLocation = 2
categories2.LockType = 3
categories2.Open()
categories2_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
photos_numRows = photos_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
' set the record count
photos_total = photos.RecordCount
' set the number of rows displayed on this page
If (photos_numRows < 0) Then
photos_numRows = photos_total
Elseif (photos_numRows = 0) Then
photos_numRows = 1
End If
' set the first and last displayed record
photos_first = 1
photos_last = photos_first + photos_numRows - 1
' if we have the correct record count, check the other stats
If (photos_total <> -1) Then
If (photos_first > photos_total) Then photos_first = photos_total
If (photos_last > photos_total) Then photos_last = photos_total
If (photos_numRows > photos_total) Then photos_numRows = photos_total
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them
If (photos_total = -1) Then
' count the total records by iterating through the recordset
photos_total=0
While (Not photos.EOF)
photos_total = photos_total + 1
photos.MoveNext
Wend
' reset the cursor to the beginning
If (photos.CursorType > 0) Then
photos.MoveFirst
Else
photos.Requery
End If
' set the number of rows displayed on this page
If (photos_numRows < 0 Or photos_numRows > photos_total) Then
photos_numRows = photos_total
End If
' set the first and last displayed record
photos_first = 1
photos_last = photos_first + photos_numRows - 1
If (photos_first > photos_total) Then photos_first = photos_total
If (photos_last > photos_total) Then photos_last = photos_total
End If
%>
<html>
<head>
<title>Sort Order </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../includepages/style.css" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
//Thumbnail image viewer-
//© Dynamic Drive (www.dynamicdrive.com)
//For full source code, usage terms, and 100's more DHTML scripts,
visit http://www.dynamicdrive.com
var ie=document.all
var ns=document.layers
var ns6=document.getElementById&&!document.all
function enlarge(which,e){
//Render image code for IE 4+ and NS6
if (ie||ns6){
crossobj=document.getElementById? document.getElementById("showimage")
: document.all.showimage
if (crossobj.style.visibility=="hidden"){
crossobj.style.left=ns6? pageXOffset+e.clientX :
document.body.scrollLeft+event.clientX
crossobj.style.top=ns6? pageYOffset+e.clientY :
document.body.scrollTop+event.clientY
crossobj.innerHTML='<div align=right id=drag><b
onClick=closepreview()>Close Photo Window</b></div><img
src="'+which+'">'
crossobj.style.visibility="visible"
}
else
crossobj.style.visibility="hidden"
return false
}
//Render image code for NS 4
else if (document.layers){
if (document.showimage.visibility=="hide"){
document.showimage.document.write('<a href="#"
onMouseover="drag_dropns(showimage)"><img src="'+which+'"
border=0></a>')
document.showimage.document.close()
document.showimage.left=e.x
document.showimage.top=e.y
document.showimage.visibility="show"
}
else
document.showimage.visibility="hide"
return false
}
//if NOT IE 4+ or NS 4, simply display image in full browser window
else
return true
}
function closepreview(){
crossobj.style.visibility="hidden"
}
</script>
<script language="JavaScript1.2">
<!--
//By Dynamicdrive.com
//drag drop function for NS 4////
/////////////////////////////////
var nsx,nsy,nstemp
function drag_dropns(name){
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}
function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}
//drag drop function for IE 4+ and NS6////
/////////////////////////////////
function drag_drop(e){
if (ie&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx
crossobj.style.top=tempy+e.clientY-offsety
}
return false
}
function initializedrag(e){
if (ie&&event.srcElement.id=="drag"||ns6&&e.target.id=="drag"){
offsetx=ie? event.clientX : e.clientX
offsety=ie? event.clientY : e.clientY
tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)
dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="showimage" style="position:absolute;visibility:hidden;border:1px
solid black"></div><table width="100%" border="0" cellpadding="0">
<tr>
<td>
<!--#include file="../includepages/inc_admin_top.asp" -->
</td>
</tr><tr>
<td>
<% If Request.Querystring ("cat") = "" then %>
<table width="100%" border="1" cellpadding="2" cellspacing="0"
bordercolor="#999999">
<tr>
<td bgcolor="#999999">
<div align="center" class="headers">Photo Administration</div>
</td>
</tr>
<tr>
<td>
<form name="form2" method="post" action="">
<p align="right" class="headerred">Choose category>>
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<option selected>Choose Category</option>
<%
While (NOT categorys.EOF)
%>
<option value="sortorder.asp?cat=<%=(categorys.Fields.Item("catid").Value)%>"
><%=(categorys.Fields.Item("catname").Value)%></option>
<%
categorys.MoveNext()
Wend
If (categorys.CursorType > 0) Then
categorys.MoveFirst
Else
categorys.Requery
End If
%>
</select>
</p>
<p class="headerredlarge">Please choose a category using the menu to the
right. </p>
</form>
<p align="right"> </p>
<p> </p>
</td>
<% Else %>
<% If Not photos.EOF Or Not photos.BOF Then %>
<table width="100%" border="1" cellpadding="2" cellspacing="0"
bordercolor="#999999">
<tr>
<td bgcolor="#999999">
<div align="center" class="headers">Photo Administration
for the <%=(categories2.Fields.Item("catname").Value)%> Category
</div>
</td>
</tr>
<tr>
<td height="136">
<form name="form2" method="post" action="">
<p align="right" class="headerred">Jump to another category>>
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<%
While (NOT categorys.EOF)
%>
<option
value="sortorder.asp?cat=<%=(categorys.Fields.Item("catid").Value)%>"
<%if (CStr(categorys.Fields.Item("catid").Value) =
CStr(photos.Fields.Item("category").Value)) then
Response.Write("SELECTED") : Response.Write("")%>
><%=(categorys.Fields.Item("catname").Value)%></option>
<%
categorys.MoveNext()
Wend
If (categorys.CursorType > 0) Then
categorys.MoveFirst
Else
categorys.Requery
End If
%>
</select>
</p>
<p class="text">This page shows the photo sorting order for the
<span
class="headerred"><%=(categories2.Fields.Item("catname").Value)%></span>
category. You can change this order
by changing the number and clicking on the Update
button. Please
make sure that you do not repeat any numbers and that you do not
have any gaps in the number sequence as this will cause problems
when viewing your gallery. </p>
</form>
<p align="right"> </p>
</td>
</tr>
<tr>
<td>
<div align="center"> <span class="headerred"> There are currently
<%=(photos_total)%> photos in the
<%=(categories2.Fields.Item("catname").Value)%> category.</span></div>
</td>
</tr>
<tr>
<td height="76">
<table width="100%" border="1" cellpadding="2"
cellspacing="0" bordercolor="#999999">
<tr>
<td width="25%" bgcolor="#999999" class="headers" height="8">
<div align="center">Photo Name</div>
</td>
<td width="37%" bgcolor="#999999" class="headers" height="8">
<div align="center">Photo Description</div>
</td>
<td width="8%" bgcolor="#999999" class="headers" height="8">
<div align="center">Image</div>
</td>
<td width="3%" bgcolor="#999999" class="headers" height="8">
<div align="center">Size</div>
</td>
<td width="15%" bgcolor="#999999" class="headers" height="8">
<div align="center">Sort Order</div>
</td>
<td width="12%" bgcolor="#999999" class="headers" height="8">
<div align="center">Delete/Edit</div>
</td>
</tr>
<!--Here is where I call in the records -->
<form METHOD="post"
action="sortorderupdate.asp?cat=<%=Request.QueryString("cat")%>"
name="form1" >
<% Dim iCount
iCount = 0
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT photos.EOF))
%>
<tr>
<td width="25%"
class="headerred"><%=(photos.Fields.Item("photoname").Value)%></td>
<td width="37%"
class="headerred"><%=(photos.Fields.Item("description").Value)%></td>
<td width="8%">
<div align="center"><a
href="../files/<%=(photos.Fields.Item("fileurl").Value)%>"
onClick="return enlarge('../files/<%=(photos.Fields.Item("fileurl").Value)%>',event)"
class="headerred">Click
Here</a> </div>
</td>
<td width="3%">
<div align="center">
<% If (admin.Fields.Item("constrain").Value) = "no" then %>
<% If (photos.Fields.Item("width").Value) <>
(admin.Fields.Item("photowidth").Value) or
(photos.Fields.Item("height").Value) <>
(admin.Fields.Item("photoheight").Value) then %>
<a
href="reupload.asp?photoid=<%=(photos.Fields.Item("photoid").Value)%>"><img
src="../inc_img/badsize.gif" width="22" height="22" alt="The size of
this image is <%= (photos.Fields.Item("width").Value) %> wide and
<%=(photos.Fields.Item("height").Value)%> tall. Your settings call
for an image that is <%=(admin.Fields.Item("photowidth").Value)%> wide
and <%=(admin.Fields.Item("photoheight").Value)%> tall. This will not
cause any problems but your images may not appear correctly. Also,
oversized images will take longer to load! Please consider changing
the size of the image and reuploading it by clicking on this icon. "
border="0">
</a>
<% Else %>
<img src="../inc_img/oksize.gif" width="22" height="22">
<% End If %>
<% Else %>
<img src="../inc_img/nasize.gif" width="22" height="22">
<% End If %>
</div>
</td>
<td width="15%">
<input type="text" name="<%= (iCount & ".Qty") %>"
value="<%=(photos.Fields.Item("sortorder").Value)%>" size="3">
<A
HREF="sortorder.asp?cat=<%=Request.QueryString("cat")%>&photoid=<%=(photos.Fields.Item("photoid").Value)%>&operation=up"><img
src="uparrow.gif" border="0"></A> <A
HREF="sortorder.asp?cat=<%=Request.QueryString("cat")%>&photoid=<%=(photos.Fields.Item("photoid").Value)%>&operation=down"><img
src="downarrow.gif" border="0"></A>
<input type="hidden" name="<%= (iCount & ".ID")
%>"value="<%=(photos.Fields.Item("photoid").Value)%>">
<input type="hidden" name="cat"
value="<%=Request.QueryString("cat")%>">
<input type="hidden" name="fileurl"
value="<%=(photos.Fields.Item("fileurl").Value)%>">
</td>
<td width="12%" class="text">
<div align="center"> <a href =
"deletepic.asp?photoid=<%=(photos.Fields.Item("photoid").Value)%>&action=Remove&cat=<%=Request.QueryString("cat")%>&fileurl=<%=(photos.Fields.Item("fileurl").Value)%>">Delete</a>
/ <a
href="edit.asp?photoid=<%=(photos.Fields.Item("photoid").Value)%>">Edit</a></div>
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
photos.MoveNext()
iCount = iCount + 1
Wend
%>
<input type="hidden" name="Count" value="<%= iCount - 1 %>">
<span class="headerred">Check Delete to delete an
image then change
number order to set photo sort order. Higher number shown first.
Then click here > ></span>
<input type="submit" name="Submit" value="Update / Delete">
</form>
</table>
</td>
</tr>
</table>
<div align="center">
<% Else %>
<span class="headerredlarge"><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
There are no images in this category. <a href="upload.asp">Click
Here</a> to go to upload images.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br></span> </div>
<% End If ' end Not photos.EOF Or NOT photos.BOF %>
</td>
</tr>
<tr>
<td>
<!--#include file="../includepages/inc_admin_bottom.asp" -->
</td>
</tr>
</table>
<p> </p>
</body>
</html>
<%
admin.Close()
%>
<%
categorys.Close()
%>
<%
photos.Close()
%>
<%
categories2.Close()
%>
<% End If %> |