Change the Session Variable Output - dreamweaver

I am using Dreamweaver CS5 with Coldfusion 9 to build a dynamic website. I have a MS Access Database that stores login information which includes ID, FullName, FirstName, LastName, Username, Pawword, AcessLevels.
My question is this:
I currently have session variable to track the Username when it is entered into the login page. However I would like to use that Username to pull the User's FullName to display throughout the web pages and use for querying data. How do I change the session variable to read that when they are not entering their FullName on the login page but only Username and password.
I have listed my login information code below if there is any additional information needed please let me know.
This is the path for which the FullName values reside DataSource "Access" Table "Logininfo" Field "FullName" I want the FullName to be unique based on the Username submitted from the Login page.
I apologize in advance for any rookie mistake I may have made I am new to this but learning fast! Ha.
<cfif IsDefined("FORM.username")>
<cfset MM_redirectLoginSuccess="members_page.cfm">
<cfset MM_redirectLoginFailed="sorry.cfm">
<cfquery name="MM_rsUser" datasource="Access">
SELECT FullName, Username,Password,AccessLevels FROM Logininfo WHERE Username=<cfqueryparam value="#FORM.username#" cfsqltype="cf_sql_clob" maxlength="50"> AND Password=<cfqueryparam value="#FORM.password#" cfsqltype="cf_sql_clob" maxlength="50">
</cfquery>
<cfif MM_rsUser.RecordCount NEQ 0>
<cftry>
<cflock scope="Session" timeout="30" type="Exclusive">
<cfset Session.MM_Username=FORM.username>
<cfset Session.MM_UserAuthorization=MM_rsUser.AccessLevels[1]>
</cflock>
<cfif IsDefined("URL.accessdenied") AND false>
<cfset MM_redirectLoginSuccess=URL.accessdenied>
</cfif>
<cflocation url="#MM_redirectLoginSuccess#" addtoken="no">
<cfcatch type="Lock">
<!--- code for handling timeout of cflock --->
</cfcatch>
</cftry>
</cfif>
<cflocation url="#MM_redirectLoginFailed#" addtoken="no">
<cfelse>
<cfset MM_LoginAction=CGI.SCRIPT_NAME>
<cfif CGI.QUERY_STRING NEQ "">
<cfset MM_LoginAction=MM_LoginAction & "?" & XMLFormat(CGI.QUERY_STRING)>
</cfif>
</cfif>

I looks like the query is already pulling FullName, so if you want a session variable that contains the value of FullName.
You have this code:
Change it to something like the following (should work haven't sued CF in a while, so based on memory, not tested)
<cflock scope="Session" timeout="30" type="Exclusive">
<cfset Session.MM_Username=FORM.username>
<cfset Session.MM_UserAuthorization=MM_rsUser.AccessLevels[1]>
<cfset Session.FullName=MM_rsUser.FullName[1]>
</cflock>
That will add Session.FullName, and you can reference that elsewhere in your site. It should be present on any page after the user has logged in, so you'd have to check for it's existence on pages that don't require log in before using that value.
Please note: the code you're using is auto-generated by a Dreamweaver log in server behavior, and it's quite possible that the changes I'm suggesting will break the inspection or reapplication of that server behavior. If that happens, then you may be able to recover by removing the added line of code and the re-adding it after making any changes you you need to make. You may need to make sure that FullName is in the query SELECT statement to make sure that FullName will be available.

Related

How to fetch the author profile picture on WebContent template?

Can someone tell me how to fetch the web content author image in web content template? When I tried with the user object, it's returning the current logged in user and not the actual one.
I can fetch the author name and id by using the key
<#assign authorId = .vars['reserved-article-author-id'].data>
<#assign authorName = .vars['reserved-article-author-name'].data>
I have used the below code to fetch the content author image but it returns the current loggedin user.
<#assign author-img = user.getPortraitURL(themeDisplay)>
But it is returning the current logged in user image
I have also tried with the taglib
<#liferay_ui["user-display"] userId="userId" />, but its failing with a message "Failed to set JSP tag parameter "author" (declared type: boolean, actual value's type: String). See cause exception for the more specific cause...
Thanks
I can't tell you about the solution from the top of my head, but here's what happens:
<#assign author-img = user.getPortraitURL(themeDisplay)>
uses the predefined variable user, e.g. the currently logged in user. Exactly what you get, but not what you want. themeDisplay is used to provide the current web context (e.g. host name that's being used) in, for proper URL generation that matches the currently displayed page.
Instead of using reserved-article-author-name, you want to use reserved-article-author-id to get hold of the user object with this id. You'll need UserLocalService for that (pardon my memory - I'm rarely using freemarker and would probably mess up how to actually do that, but you can search for that information. You might need access to the serviceLocator - which makes a good additional search term).
Having that user object (name it differently than user, e.g. author), you can get the author's portrait image URL with the same strategy as above:
<#assign author-img = author.getPortraitURL(themeDisplay)>
This is working.
<#assign userLocalService = serviceLocator.findService('com.liferay.portal.kernel.service.UserLocalService') />
<#assign author_id = .vars['reserved-article-author-id'].data?number>
<#assign author_user = userLocalService.getUserById(author_id)/>
<#assign author_image = author_user.getPortraitURL(themeDisplay)/>
<img src="${author_image}"/>

SharePoint Redirect after post

My SharePoint input tag is using an XSLT variable for the redirect. I would like to substitute it for a javascript function to determine the value of the users input. Is this possible from within this tag? If not is possible to run a javascript function from within as XSLT variable? The following article show that something like this is possible but I need an example. http://www.nothingbutsharepoint.com/2011/05/05/extending-the-dvwp-passing-xsl-variables-to-javascript-aspx/
Thank you in advance.
<input type="button" id="Submit" value=" Submit " style="width:100px" onclick="javascript: if(!PreSaveItem()) return false;{ddwrt:GenFireServerEvent(concat('__commit;__redirect={',$RedirectLoc,'}'))}"/>
Basically behind GenFireServerEvent is a __doPostBack function.
__doPostBack('elementgeneratedname','__redirect={' + value '}');
Take a look into the browser what code is generated and use it in your function. Most probably first argument is not the id of the button and is the name of the web part container (somthing like 'ctl00$PlaceHolderMain$WebPartId').

Issue while saving the dynamic field values in the preferences

I have already posted one question on the same issue. But I'm not able to solve my issue and not able to move forward in my task.
I have created a editable portlet where in the configuration page I am showing he dynamic questions which are fetching form the database. So for the same reason I am iterating my array list and creating the input fields dynamically as follows,
Iterator<String> itr = al.iterator();
while(itr.hasNext())
{
String columnVal = itr.next();
columnVal = columnVal.trim().toLowerCase();
%>
<aui:input name="<%=columnVal%>" type="checkbox" />
<%
}
With the above code the fields are creating dynamically with proper labels and seems to be fine.
When I try to save these dynamic field values in the preference I changed my input statement syntax to the proper way by adding the prefix as "preferences--" and suffix as "--" as shown below,
<aui:input name="preferences--<%=columnVal%>--" type="checkbox" />
I don't know what syntax is wrong in the above statement. But I am not able to see the label names in UI. instead of showing the proper label names for all labels it is showing <%=columnVal%> on UI.
I am using default configuration action class in my liferay-portlet.xml as mentioned below,
<configuration-action-class>com.liferay.portal.kernel.portlet.DefaultConfigurationAction</configuration-action-class>
Can any one please correct my syntax and help me to save my dynamic field values in the preferences.
From reference link's comment section:
According to JSP 2.1 Specification multiple expressions and mixing of
expressions and string constants are not permitted.
So you have to use below code in your case:
<aui:input name='<%="preferences--"+columnVal+"--"%>' type="checkbox" />

Using CF to detect if URL is index.cfm or /

I'm not sure whether this is possible or not using the CGI scope, but what I'm trying to do is detect if a user is browsing a page that is /index.cfm or /.
In the event of it being /index.cfm I would like to do a 301 redirect to the /.
I've viewed a dump of the CGI & URL scopes but can't see any easy method of redirecting based on this.
Any ideas greatly appreciated.
We are using ColdFusion 10.
Just an idea: why don't you use the rewrite module from Microsoft http://www.iis.net/downloads/microsoft/url-rewrite and do something like
^/index.cfm / [L,R=301]
In CF you can try like this:
<cfif listlast(cgi.script_name, "/") eq "index.cfm">
<cflocation url="redirectlogin.cfm" addtoken="no" statuscode="301">
</cfif>
Because we are using IIS, we have applied this
<cfset stHttpRequestData = getHttpRequestData()>
<cfif stHttpRequestData.headers["X-REWRITE-URL"] IS "/index.cfm">
<cflocation url="http://www.domainname.com/" addtoken="no" statuscode="301">
</cfif>

Can I add a button to a CFGRID that lets a user export the grid to an XLSX file? How?

I'm a coldfusion developer working on a reporting application to display information from a CFSTOREDPROC process. I've been able to get the data from my query to display correctly in a CFGRID, and I'm really happy with the display of the data. The grid saves a lot of time because it avoids using the CFOUTPUT tag and formatting the data in HTML for hundreds of reports.
All I would like to do is add a simple Disk Icon somewhere on the datagrid control that would save the contents of the datagrid and export it into an XLSX(2010) file that an end user could then manipulate in a spreadsheet program. This is important because the data needs to have a 'snapshot' at certain times of year saved.
Solutions Tried:
I looked into having a link from the report options page that would fire into a report_xls.cfm page but designing a page that catches all of the report options a second time seems dumb and would add thousands of CFM's to the website.
CFSPREADSHEET seems not to work for a variety of reasons. One is that the server seems to constantly fight me with the 'write' function in this tag. Another is that I don't know how to make the javascript work for this button to get the output that I want.
I also looked into doing this as a Javascript button that would fire based on the data entered. Although the data from a CFSTOREDPROC will display correctly if I use a CFOUTPUT block, CFGRID seems to have a hard time with all output styles except HTML. This has caused some difficulty with these solutions because the application doesn't spit out a neat HTML table but instead sends a javascript page section.
Raymond Camden's blog contains an entry Exporting from CFGRID that we used in our project.
The example in the article exports to PDF, but it is rather simple to modify the download.cfm file to export to Excel files as well:
You modify the file to generate the <table>...</table> HTML from his example in a <cfsavecontent variable="exportList"> tag, so that the #exportList# variable contains the table that will be shown in the spreadsheet.
Next we have a URL parameter mode that determines whether it is exported to PDF or Excel.
So the end of our download.cfm looks like the following:
<cfif url.mode EQ "PDF">
<cfheader name="Content-Disposition" value="inline; filename=report.pdf">
<cfdocument format="pdf" orientation="landscape">
<cfoutput>#exportList#</cfoutput>
</cfdocument>
<cfelse>
<cfcontent type="application/vnd.ms-excel">
<cfheader name="Content-Disposition" value="report.xls">
<cfoutput>#exportList#</cfoutput>
</cfif>

Resources