Hello;
I am trying to learn about session variables for more
stability in an application I am writting. I am still not sure of
how this works and was hoping someone can show me so I can get the
idea.
I want to make the part of my application that updates info
into sessions. I want the sessions to control the usage of the
section. So if user a is logged in, no one else can make changes to
the area until they log out. Somethign like that, or they can log
in, but can't make changes if another user is.
I realize some of this is controled by islogged in and the
session started by the logged in user. How do I make my application
into a session managed app?
Here is some code, just some of the code in my app, I will
show you what I am doing, I don't think it is right.
this is the start page:
<cfset preappendURL = "../">
<cfset pageType = "admin">
<cfquery name="catMan"
datasource="#APPLICATION.dataSource#">
SELECT Categories.Name AS ViewField1, Categories.CategoryID
FROM Categories
</cfquery>
<cfset rowsPerPage = 6>
<cfparam name="URL.startRow" default="1"
type="numeric">
<cfset totalRows = catMan.recordCount>
<cfset endRow = min(URL.startRow + rowsPerPage - 1,
totalRows)>
<cfset startRowNext = endRow + 1>
<cfset startRowBack = URL.startRow - rowsPerPage>
<head>
</head>
<body>
<cfoutput>
Displaying <b>#URL.startRow#</b> to
<b>#endRow#</b> of <b>#totalRows#</b>
Records.
<cfif startRowBack GT 0><a
href="#CGI.script_name#?startRow=#startRowBack#"
class="nav">< Previous Records</a></cfif>
<cfif startRowNext lte totalRows><a
href="#CGI.script_name#?startRow=#startRowNext#"
class="nav">Next Records > </a>
</cfif>
</cfoutput>'
<cfloop query="catMan" startRow="#URL.startRow#"
endrow="#endRow#">
<cfset class = iif(catMan.currentRow mod 2 eq 0, " 'DataA'
", " 'DataB' ")>
<cfoutput>
#ViewField1#
<a href="project-manager.cfm?CategoryID=#CategoryID#"
class="nav">Edit Projects</a>
<a href="projectCat-edit.cfm?CategoryID=#CategoryID#"
class="nav">Edit Category</a>
<form action="ProjectCat-Action.cfm" method="post">
<input type="hidden" name="ID" value="#CategoryID#">
<input type="submit" name="cat_Delete" class="formButtons"
onClick="return confirmDelete('ID','#ViewField1#')"
value="Delete"></form>
</cfoutput></cfloop>
<cfoutput>
<cfset thisPage = 1>
<cfloop from="1" to="#totalRows#" step="#rowsPerPage#"
index="pageRow">
<cfset isCurrentPage = (pageRow gte URL.startRow) and
(pageRow lte endRow)>
<cfif isCurrentPage>
<cfoutput><font size="2" face="Verdana, Arial,
Helvetica,
sans-serif"><b>#thisPage#</b></font></cfoutput><cfelse><cfoutput>
<a href="#CGI.script_name#?startRow=#pageRow#"
class="nav">#thisPage#</a></cfoutput></cfif>
<cfset thisPage = thisPage + 1>
</cfloop>
<cfif startRowBack GT 0><a
href="#CGI.script_name#?startRow=#startRowBack#"
class="nav">< Previous Records</a></cfif>
<cfif startRowNext lte totalRows><a
href="#CGI.script_name#?startRow=#startRowNext#"
class="nav">Next Records > </a>
</cfif>
</cfoutput>
</body>
There is another page that goes with this. It is the edit
page. But I don't know if we can start here to create this part
into sessions.
Here is page 2:
<cfset preappendURL = "../">
<cfset pageType = "admin">
<cfparam name="url.id" type="integer" default="0">
<cfparam name="variables.CategoryID" type="integer"
default="#url.id#">
<cfparam name="variables.Name" default="">
<cfparam name="variables.Description" default="">
<cfparam name="variables.MYFile" default="">
<cfif url.id GT 0>
<cfquery name="categRec"
dataSource="#APPLICATION.dataSource#">
SELECT Name, Description, MYFile, CategoryID
FROM Categories
WHERE CategoryID = <cfqueryparam value="#URL.ID#"
cfsqltype="cf_sql_integer">
ORDER BY Name
</cfquery>
<!--- if the record was found, store the values --->
<cfif categRec.RecordCount EQ 1>
<cfset variables.CategoryID = categRec.CategoryID>
<cfset variables.Name = categRec.Name>
<cfset variables.Description = categRec.Description>
<cfset variables.MYFile = categRec.MYFile>
</cfif>
</cfif>
<head>
</head>
<body>
<cfoutput>
<form action="ProjectCat-Action.cfm" method="post"
name="content" id="content"
enctype="multipart/form-data">
<input type="hidden" name="ID"
value="#variables.CategoryID#">
<input type="hidden" name="oldimage"
value="#variables.MYFile#">
<input type="text" name="Name" class="textInputs"
value="#variables.Name#" maxLength="510">
<cfif len(trim(variables.MYFile)) GT 0>
<b>Image in
use:</b>#variables.MYFile#</cfif>
<input name="MYFile" type="file" id="MYFile">
<input name="Description" type="text" class="textInputs"
value="#variables.Description#" size="50" maxLength="510">
</cfoutput>
<input type="submit" class="formButtons" name="cat_OK"
onclick=";DisableButton(this);" value=" OK ">
<input type="submit" class="formButtons" name="cat_Cancel"
value="Cancel">
</form>
How would I make this into session managed variables? That is
where I am confused. I have session variables enabled in my
application.cfc file. Now I want to manage them better.
Can anyone help show me how to do this? Or point me to a web
site that explains what I am trying to do?
Thank you.
CFmonger