<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coding Friends</title>
	<atom:link href="http://www.codingfriends.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingfriends.com</link>
	<description>Coding Friends, place for developers.</description>
	<lastBuildDate>Wed, 25 Aug 2010 19:55:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>CS107 &#8211; Assignment 2 &#8211; Six degrees</title>
		<link>http://www.codingfriends.com/index.php/2010/08/25/cs107-assignment-2-six-degrees/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cs107-assignment-2-six-degrees</link>
		<comments>http://www.codingfriends.com/index.php/2010/08/25/cs107-assignment-2-six-degrees/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 19:54:32 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[C / C++]]></category>
		<category><![CDATA[Assignment 2]]></category>
		<category><![CDATA[CS107]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1167</guid>
		<description><![CDATA[This is assignment 2 from a older CS107 course, because the latest course work is held on a UNIX server which in turn you need access to!!.. kinder does not help when you do not have access too!!.. Here is where I got the files from cs107 link, there is a zip file at the [...]]]></description>
			<content:encoded><![CDATA[<p><span id="zipfile"><a href="http://www.codingfriends.com/wp-content/uploads/2010/08/09-Assignment-2-Six-Degrees.pdf"></a></span>This is assignment 2 from a older <a href="https://courseware.stanford.edu/pg/courses/82252">CS107</a> course, because the latest course work is held on a UNIX server which in turn you need access to!!.. kinder does not help when you do not have access too!!..  Here is where I got the files from <a href="http://see.stanford.edu/see/courseinfo.aspx?coll=2d712634-2bf1-4b55-9a3a-ca9d470755ee">cs107</a> link, there is a zip file at the bottom of that page which has all of the assignments and handouts etc.</p>
<p>I have included the PDF of the assignment in the above file link, but since the actual assignment includes a few massive files you can download them from the CS107 link of the whole course work that I am using from the <a href="http://see.stanford.edu/see/courseinfo.aspx?coll=2d712634-2bf1-4b55-9a3a-ca9d470755ee">cs107</a> link.</p>
<p>As a note, within my linux setup, I need to setup the environment variable to tell the program to use a Linux <a href="http://en.wikipedia.org/wiki/Endianness">little endian</a> by</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">OSTYPE</span>=linux</pre></div></div>

<p>Basically the assignment is to load in cast/movie details (which the base code from the assignment already does for use) and then we are needed to pull out the data from the structure of the file, the structure of the actors is (as taken from the PDF file)</p>
<ol>
<li>The name of the actor is laid out character by character, as a normal null-terminated C-string. If the length of the actor’s name is even, then the string is<br />
padded with an extra &#8216;\0&#8242; so that the total number of bytes dedicated to the name is always an even number. The information that follows the name is most<br />
easily interpreted as a short integer, and virtually all hardware constrains any address manipulated as a short * to be even.	</li>
<li>The number of movies in which the actor has appeared, expressed as a two-byte short. (Some people have been in more than 255 movies, so a single byte just<br />
isn’t enough.) If the number of bytes dedicated to the actor’s name (always even) and the short (always 2) isn’t a multiple of four, then two additional &#8216;\0&#8242;’s<br />
appear after the two bytes storing the number of movies. This padding is conditionally done so that the 4-byte integers than follow sit at addresses that are<br />
multiples of four.
</li>
<li>An array of offsets into the movieFile image, where each offset identifies one of the actor’s films.</li>
</ol>
<p>with the base of the actors information containing a 4 byte integer value of how many actors are in the block of data and then the following values are in 4 bytes again with the offsets into the block of where the actual data is stored.</p>
<p>So the method that you need to write is to pull in that data from the actorInfo block of memory, and here is my version of it, the method is getCredits and takes the cast member (player) as the method will insert all of the films that cast as been in.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> imdb<span style="color: #008080;">::</span><span style="color: #007788;">getCredits</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> string<span style="color: #000040;">&amp;</span> player, vector<span style="color: #000080;">&lt;</span>film<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> films<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> numberOfActors,data<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>actorName<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">memcpy</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>numberOfActors,<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>actorInfo.<span style="color: #007788;">fileMap</span>, <span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">// loop though the number of actors</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span><span style="color: #0000dd;">2</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> numberOfActors<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">memcpy</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>data, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>actorInfo.<span style="color: #007788;">fileMap</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">+</span>i,<span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        actorName <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>actorInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> <span style="color: #008000;">&#40;</span>data<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">strcmp</span><span style="color: #008000;">&#40;</span>actorName,player.<span style="color: #007788;">c_str</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #000080;">==</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #666666;">// find the padding lengths</span>
            <span style="color: #0000ff;">int</span> actorNameLength <span style="color: #000080;">=</span> <span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>actorName<span style="color: #008000;">&#41;</span><span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">int</span> movieNumberPad <span style="color: #000080;">=</span> actorNameLength <span style="color: #000040;">%</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">int</span> fourOffset <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>actorNameLength <span style="color: #000040;">+</span> movieNumberPad <span style="color: #000040;">+</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">%</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">short</span> numberMovies<span style="color: #008080;">;</span>
            <span style="color: #0000dd;">memcpy</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>numberMovies,<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">short</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>actorInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> data <span style="color: #000040;">+</span> actorNameLength <span style="color: #000040;">+</span> movieNumberPad<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>,<span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> j<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> j <span style="color: #000080;">&lt;</span> numberMovies<span style="color: #008080;">;</span> j<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0000ff;">int</span> movieOffset<span style="color: #008080;">;</span>
                film theFilm<span style="color: #008080;">;</span>
                <span style="color: #0000dd;">memcpy</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>movieOffset, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>actorInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> data <span style="color: #000040;">+</span> actorNameLength <span style="color: #000040;">+</span> movieNumberPad <span style="color: #000040;">+</span> <span style="color: #008000;">&#40;</span>j<span style="color: #000040;">*</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> fourOffset <span style="color: #000040;">+</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>,<span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                theFilm.<span style="color: #007788;">title</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>movieInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> movieOffset<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                theFilm.<span style="color: #007788;">year</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1900</span> <span style="color: #000040;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>movieInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> movieOffset <span style="color: #000040;">+</span> theFilm.<span style="color: #007788;">title</span>.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
                films.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>theFilm<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The block of memory for the movie block is similar to the actor block and as taken from the PDF attached file here is the details of that block of memory,</p>
<ol>
<li>The title of the movie, terminated by a &#8216;\0&#8242; so the character array behaves as a normal C-string.</li>
<li>The year the film was released, expressed as a single byte. This byte stores the year – 1900. Since Hollywood is less than 28 years old, it was fine to just store the year as a delta from 1900. If the total number of bytes used to encode the name and year of the movie is odd, then an extra &#8216;\0&#8242; sits in between the one-byte year and the data that follows.</li>
<li>A two-byte short storing the number of actors appearing in the film, padded with two additional bytes of zeroes if needed.	</li>
<li>An array of four-byte integer offsets, where each integer offset identifies one of the actors in the actorFile. The number of offsets here is, of course, equal to<br />
the short integer read during step 3</li>
</ol>
<p>And once again like the actor block there is a 4 byte integer value that stores how many movies within the block of memory with the next 4 bytes storing the offset into that block of memory, here is my implementation of the method getCast that will take a movie as a parameter and find all of the cast (players) and return that vector list.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> imdb<span style="color: #008080;">::</span><span style="color: #007788;">getCast</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> film<span style="color: #000040;">&amp;</span> movie, vector<span style="color: #000080;">&lt;</span>string<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> players<span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> numberOfMovies, data<span style="color: #008080;">;</span>
    film theFilm<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span>movieName<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">memcpy</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>numberOfMovies, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>movieInfo.<span style="color: #007788;">fileMap</span>, <span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> numberOfMovies<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0000dd;">memcpy</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>data, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>movieInfo.<span style="color: #007788;">fileMap</span><span style="color: #000040;">+</span>i,<span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        movieName <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>movieInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> data<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        theFilm.<span style="color: #007788;">title</span> <span style="color: #000080;">=</span> movieName<span style="color: #008080;">;</span>
        theFilm.<span style="color: #007788;">year</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">1900</span> <span style="color: #000040;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>movieInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> data <span style="color: #000040;">+</span> theFilm.<span style="color: #007788;">title</span>.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>movie <span style="color: #000080;">==</span> theFilm<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0000ff;">int</span> paddingFirst <span style="color: #000080;">=</span> theFilm.<span style="color: #007788;">title</span>.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">%</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
            <span style="color: #666666;">// paddingSecond = paddingfirst + length of title + 2 (year + \0) and then + 2 for the actors number</span>
            <span style="color: #0000ff;">int</span> paddingSecond <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>paddingFirst <span style="color: #000040;">+</span> theFilm.<span style="color: #007788;">title</span>.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span><span style="color: #0000dd;">2</span> <span style="color: #000040;">+</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">%</span><span style="color:#800080;">4</span><span style="color: #008080;">;</span>
            <span style="color: #0000ff;">short</span> numberOfActors<span style="color: #008080;">;</span>
            <span style="color: #0000dd;">memcpy</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>numberOfActors, <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">short</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>movieInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> data <span style="color: #000040;">+</span> theFilm.<span style="color: #007788;">title</span>.<span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color: #0000dd;">2</span> <span style="color: #000040;">+</span> paddingFirst<span style="color: #008000;">&#41;</span>,<span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
            <span style="color: #666666;">// get the actors offsets and insert into the players list</span>
            <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> k <span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> k <span style="color: #000080;">&lt;</span> numberOfActors<span style="color: #008080;">;</span> k<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0000ff;">int</span> offset<span style="color: #008080;">;</span>
                <span style="color: #0000dd;">memcpy</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>offset, <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>movieInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> data <span style="color: #000040;">+</span> <span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>movieName<span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> <span style="color: #0000dd;">2</span> <span style="color: #000040;">+</span> paddingFirst <span style="color: #000040;">+</span> <span style="color: #0000dd;">2</span> <span style="color: #000040;">+</span> paddingSecond <span style="color: #000040;">+</span> <span style="color: #008000;">&#40;</span>k<span style="color: #000040;">*</span><span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>, <span style="color: #0000dd;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                players.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span><span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span>actorInfo.<span style="color: #007788;">fileMap</span> <span style="color: #000040;">+</span> offset<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>After you have sorted out reading in the information you have to find out if there is a link from actor1 to another actor2 (six degrees) with linking them together the cast that they have been with with the films that they have stared in, so here is my breath search setup as taken from the assignment.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/**
  * @param actor1 - first actor to look for
  * @param actor2 - second actor to look for to link to the first
  * @param db - the imdb database loaded
  */</span>
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">bool</span> generateShortestPath<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> string<span style="color: #000040;">&amp;</span> actor1, <span style="color: #0000ff;">const</span> string<span style="color: #000040;">&amp;</span> actor2, <span style="color: #0000ff;">const</span> imdb<span style="color: #000040;">&amp;</span> db<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    list<span style="color: #000080;">&lt;</span>path<span style="color: #000080;">&gt;</span> partialPaths<span style="color: #008080;">;</span>
    set<span style="color: #000080;">&lt;</span>string<span style="color: #000080;">&gt;</span> previouslySeenActors<span style="color: #008080;">;</span>
    set<span style="color: #000080;">&lt;</span>film<span style="color: #000080;">&gt;</span> previouslySeenFilms<span style="color: #008080;">;</span>
&nbsp;
    path actorsFirst<span style="color: #008000;">&#40;</span>actor1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    partialPaths.<span style="color: #007788;">push_front</span><span style="color: #008000;">&#40;</span>actorsFirst<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>partialPaths.<span style="color: #007788;">empty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;&amp;</span> partialPaths.<span style="color: #007788;">front</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">getLength</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;=</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        path frontPath <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>path<span style="color: #008000;">&#41;</span>partialPaths.<span style="color: #007788;">front</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        partialPaths.<span style="color: #007788;">pop_front</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        vector<span style="color: #000080;">&lt;</span>film<span style="color: #000080;">&gt;</span> actorsFilms<span style="color: #008080;">;</span>
        db.<span style="color: #007788;">getCredits</span><span style="color: #008000;">&#40;</span>frontPath.<span style="color: #007788;">getLastPlayer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, actorsFilms<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> filmI<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> filmI <span style="color: #000080;">&lt;</span> actorsFilms.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> filmI<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            film filmData<span style="color: #008080;">;</span>
            filmData <span style="color: #000080;">=</span> actorsFilms.<span style="color: #007788;">at</span><span style="color: #008000;">&#40;</span>filmI<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
            <span style="color: #666666;">// not seen the film before</span>
            <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>previouslySeenFilms.<span style="color: #007788;">find</span><span style="color: #008000;">&#40;</span>filmData<span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> previouslySeenFilms.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                previouslySeenFilms.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>filmData<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                vector<span style="color: #000080;">&lt;</span>string<span style="color: #000080;">&gt;</span> movieCast<span style="color: #008080;">;</span>
                db.<span style="color: #007788;">getCast</span><span style="color: #008000;">&#40;</span>filmData, movieCast<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> castI <span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> castI <span style="color: #000080;">&lt;</span> movieCast.<span style="color: #007788;">size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> castI<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    <span style="color: #666666;">// if not already seen</span>
                    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>previouslySeenActors.<span style="color: #007788;">find</span><span style="color: #008000;">&#40;</span>movieCast.<span style="color: #007788;">at</span><span style="color: #008000;">&#40;</span>castI<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> previouslySeenActors.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #008000;">&#123;</span>
                        previouslySeenActors.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>movieCast.<span style="color: #007788;">at</span><span style="color: #008000;">&#40;</span>castI<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                        path newfrontPath <span style="color: #000080;">=</span> frontPath<span style="color: #008080;">;</span>
                        newfrontPath.<span style="color: #007788;">addConnection</span><span style="color: #008000;">&#40;</span>filmData, movieCast.<span style="color: #007788;">at</span><span style="color: #008000;">&#40;</span>castI<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>movieCast.<span style="color: #007788;">at</span><span style="color: #008000;">&#40;</span>castI<span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> actor2<span style="color: #008000;">&#41;</span>
                        <span style="color: #008000;">&#123;</span>
                            <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> newfrontPath <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
                            <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
                        <span style="color: #008000;">&#125;</span> <span style="color: #0000ff;">else</span>
                            partialPaths.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span>newfrontPath<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
                    <span style="color: #008000;">&#125;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>You can do some speed ups from the assignments PDF file, but they are mainly the icing on the cake and I thought that I would assignment 3 first, so if I do the extras for this I will update this post.</p>
<p>But this was a fun assignment, because of the memory block and finding out the data within it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/08/25/cs107-assignment-2-six-degrees/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>threads &#8211; singleton</title>
		<link>http://www.codingfriends.com/index.php/2010/08/17/threads-singleton/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=threads-singleton</link>
		<comments>http://www.codingfriends.com/index.php/2010/08/17/threads-singleton/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 08:31:57 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[C Sharp (c#)]]></category>
		<category><![CDATA[singleton]]></category>
		<category><![CDATA[Thread]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1164</guid>
		<description><![CDATA[As from one of my previous posts about threading in csharp (c#), well with using Singletons you can use similar data between two different threads running. In basics a singleton is when you want to have a single class instance so that you can share this class so that every time that you use it [...]]]></description>
			<content:encoded><![CDATA[<p>As from one of my previous posts about <a href="http://www.codingfriends.com/index.php/2010/05/07/threading-running-different-parts-of-the-program-at-once/">threading in csharp</a> (c#), well with using <a href="http://en.wikipedia.org/wiki/Singleton_pattern">Singletons</a> you can use similar data between two different threads running.</p>
<p>In basics a singleton is when you want to have a single class instance so that you can share this class so that every time that you use it (even across threads) will only access the same class, it is very useful for when you have a printer spool so that you do not want to have x amount of printer spools (spool is when you have a list of print tasks waiting to print) and thus you only want to have one instance of a printer spool !!. </p>
<p>I have used the <a href="http://msdn.microsoft.com/en-us/library/ff650316.aspx">singleton creation from Microsoft</a> website, that creates a singleton class that is thread safe which means that I am using the lock method that will lock on a object to stop thread contention and thus only creates a new instance of a Singleton class so that each thread will only get access to a single instance of that class.</p>
<p>So when you want to gain access to that single instance, you just call the</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Singleton theSingleton <span style="color: #008000;">=</span> Singleton.<span style="color: #0000FF;">Instance</span><span style="color: #008000;">;</span></pre></div></div>

<p>So here is the full source code, and below is the output where the output is displaying the value is incrementing otherwise if is was not a singleton class, the main class would print out 0-4 and also the runthismethod would output 0-9 instead!.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Threading</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> monotestproject
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">sealed</span> <span style="color: #FF0000;">class</span> Singleton
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">int</span> _value<span style="color: #008000;">;</span>
		<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> volatile Singleton instance<span style="color: #008000;">;</span>
		<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">object</span> syncRoot <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">Object</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> Singleton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> _value <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> Singleton Instance
		<span style="color: #000000;">&#123;</span>
			get <span style="color: #000000;">&#123;</span> 
				<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>instance <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
				<span style="color: #000000;">&#123;</span>
					<span style="color: #0600FF;">lock</span><span style="color: #000000;">&#40;</span>syncRoot<span style="color: #000000;">&#41;</span>
					<span style="color: #000000;">&#123;</span>
						<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>instance <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
							instance <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Singleton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
					<span style="color: #000000;">&#125;</span>
				<span style="color: #000000;">&#125;</span>
				<span style="color: #0600FF;">return</span> instance<span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0600FF;">private</span> set <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> theValue 
		<span style="color: #000000;">&#123;</span>
			get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _value<span style="color: #008000;">;</span><span style="color: #000000;">&#125;</span>
			set <span style="color: #000000;">&#123;</span> _value <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span><span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #FF0000;">class</span> MainClass
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			Singleton theSingleton <span style="color: #008000;">=</span> Singleton.<span style="color: #0000FF;">Instance</span><span style="color: #008000;">;</span>
			<span style="color: #008080; font-style: italic;">// initialize the RunThisMethod as a thread</span>
			Thread theThread <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Thread<span style="color: #000000;">&#40;</span>RunThisMethod<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			theThread.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
			<span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span> j<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				theSingleton.<span style="color: #0000FF;">theValue</span><span style="color: #008000;">++;</span>
				Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Main Singleton value &quot;</span> <span style="color: #008000;">+</span> theSingleton.<span style="color: #0000FF;">theValue</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				Thread.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">100</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// the method to create as a threadable method</span>
		<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> RunThisMethod<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			Singleton runsSingleton <span style="color: #008000;">=</span> Singleton.<span style="color: #0000FF;">Instance</span><span style="color: #008000;">;</span>		
			<span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span><span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				runsSingleton.<span style="color: #0000FF;">theValue</span><span style="color: #008000;">++;</span>
				Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;RunThisMethod Singleton value &quot;</span> <span style="color: #008000;">+</span> runsSingleton.<span style="color: #0000FF;">theValue</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
				Thread.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">45</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>here is my output, as you can I am getting the singleton value incrementing, which is what should be happening.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Main Singleton value <span style="color: #FF0000;">1</span>
RunThisMethod Singleton value <span style="color: #FF0000;">2</span>
RunThisMethod Singleton value <span style="color: #FF0000;">3</span>
RunThisMethod Singleton value <span style="color: #FF0000;">4</span>
Main Singleton value <span style="color: #FF0000;">5</span>
RunThisMethod Singleton value <span style="color: #FF0000;">6</span>
RunThisMethod Singleton value <span style="color: #FF0000;">7</span>
Main Singleton value <span style="color: #FF0000;">8</span>
RunThisMethod Singleton value <span style="color: #FF0000;">9</span>
RunThisMethod Singleton value <span style="color: #FF0000;">10</span>
Main Singleton value <span style="color: #FF0000;">11</span>
RunThisMethod Singleton value <span style="color: #FF0000;">12</span>
RunThisMethod Singleton value <span style="color: #FF0000;">13</span>
Main Singleton value <span style="color: #FF0000;">14</span>
RunThisMethod Singleton value <span style="color: #FF0000;">15</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/08/17/threads-singleton/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>unsafe &#8211; pointers in the code</title>
		<link>http://www.codingfriends.com/index.php/2010/08/13/unsafe-pointers-in-the-code/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=unsafe-pointers-in-the-code</link>
		<comments>http://www.codingfriends.com/index.php/2010/08/13/unsafe-pointers-in-the-code/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 10:16:15 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[C Sharp (c#)]]></category>
		<category><![CDATA[unsafe]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1161</guid>
		<description><![CDATA[Sometimes you do miss that pointer part of c++ coding within c#, well you can get around the restriction with using the unsafe syntax which basically means that you are doing some coding that please do not use the restrictions of the virtual machine and just allow direct access to the variable/memory as such. So [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you do miss that pointer part of c++ coding within c#, well you can get around the restriction with using the <a href="http://msdn.microsoft.com/en-us/library/chfa2zb8(VS.71).aspx">unsafe</a> syntax which basically means that you are doing some coding that please do not use the restrictions of the virtual machine and just allow direct access to the variable/memory as such.</p>
<p>So the basics is the</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// for a block code</span>
<span style="color: #0600FF;">unsafe</span> <span style="color: #000000;">&#123;</span>
code here..
<span style="color: #000000;">&#125;</span>
<span style="color: #008080; font-style: italic;">// or for the whole method.</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">unsafe</span> <span style="color: #008000;">&lt;</span>returntype<span style="color: #008000;">&gt;</span> <span style="color: #008000;">&lt;</span>methodname<span style="color: #008000;">&gt;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So to show the code in real code, this will setup a int(eger) value to 50 and then point to the data via a pointer (*) and then you can see that the actual value within the pointer (*) is not the same and also will change every time since the int(eger) value of 50 memory location will most probably be different every time.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> unsafetest
<span style="color: #000000;">&#123;</span>
    <span style="color: #FF0000;">class</span> Program
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">unsafe</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #FF0000;">int</span> intValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span><span style="color: #008000;">;</span>
                Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;integer value is : &quot;</span> <span style="color: #008000;">+</span> intValue<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #FF0000;">int</span><span style="color: #008000;">*</span> pointerInt <span style="color: #008000;">=</span> <span style="color: #008000;">&amp;</span>intValue<span style="color: #008000;">;</span>
                Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Pointer to the data is : &quot;</span> <span style="color: #008000;">+</span> <span style="color: #008000;">*</span>pointerInt<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Pointed to the memory value of data is : &quot;</span> <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>pointerInt<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>the output would be similar to, I am using a (int) cast on the memory location, which since the memory location is very big then it would be better to use something like a hex value output, but this just shows that the value will be different on different runs, if you run it again and again, that will be different values.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">integer value <span style="color: #008000;">is</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">50</span>
Pointer to the data <span style="color: #008000;">is</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">50</span>
Pointed to the memory value of data <span style="color: #008000;">is</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">98691076</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/08/13/unsafe-pointers-in-the-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL storage engines</title>
		<link>http://www.codingfriends.com/index.php/2010/08/12/mysql-storage-engines/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mysql-storage-engines</link>
		<comments>http://www.codingfriends.com/index.php/2010/08/12/mysql-storage-engines/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 13:00:38 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[SQL (Structured Query Language)]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Storage engines]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1158</guid>
		<description><![CDATA[In MySQL, there is a couple of different storage engines that can be used for different tables within a database. There is myiasm, innodb, cvs, memory, merge, BDB (BerkeleyDB) example, federated, archive and blackhole. The main two are that are used are myiasm innodb The main differences between them both are speed, the myiasm is [...]]]></description>
			<content:encoded><![CDATA[<p>In MySQL, there is a couple of different <a href="http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html">storage engines</a> that can be used for different tables within a database.  There is myiasm, innodb, cvs, memory, merge, BDB (BerkeleyDB) example, federated, archive and blackhole.</p>
<p>The main two are that are used are </p>
<ul>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/myisam-storage-engine.html">myiasm</a></li>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/innodb.html">innodb</a></li>
</ul>
<p>The main differences between them both are speed, the myiasm is more designed for speed to access the database tables but does not support the rollback where you are able stop the current set of instructions and rollback the updates/inserts to where it was at a previous time, because of this the programmer is the person to make sure that what they want to do is and will happen, otherwise the programmer will have to sort out the tables that could out of stink.  But compared to the innodb, where it supports the rollback function, it does have to take a hit somewhere and that is the speed.</p>
<p>The main database that I use is the myiasm, purely because of the speed of access, and also it appears that most web/applications appear to use that.  But if you running some circuital data then of course I would use innodb database type purely for data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/08/12/mysql-storage-engines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CS71 &#8211; Ass1 &#8211; Finance &#8211; Part 5 &#8211; View users details &#8211; buy stock &#8211; change password</title>
		<link>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-5-view-users-details-buy-stock-change-password/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cs71-ass1-finance-part-5-view-users-details-buy-stock-change-password</link>
		<comments>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-5-view-users-details-buy-stock-change-password/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:51:30 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Assignment 1]]></category>
		<category><![CDATA[CS75]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1154</guid>
		<description><![CDATA[I am doing the Harvards building dynamic websites called CS-75 (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning even if allot of it you may already know. As from the previous post, most of this page is in similar in nature [...]]]></description>
			<content:encoded><![CDATA[<p><span id="zipfile"><a href="http://www.codingfriends.com/wp-content/uploads/2010/08/cs75-ass1.zip"></a></span>I am doing the <a href="http://www.harvard.edu/">Harvards</a> building dynamic websites called <a href="http://www.cs75.net/">CS-75</a> (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  even if allot of it you may already know.</p>
<p>As from the <a href="http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-login-register-forgotten-password/">previous post</a>, most of this page is in similar in nature it is just displaying data to the user that was built up from the classes files.</p>
<p>So to buy some stock, what this page will do is wait for the user to type in a stock symbol and then use the stock class to get the data back from that symbol and then have another input that will allow the user to buy some of that stock, also if the user clicks on the link it will display at the bottom of the page new items about the stock itself.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /index.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// of course the product price may change from searching to buying, depending on the time period so need to pull back </span>
	<span style="color: #666666; font-style: italic;">// the new value, just incase.</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;buyme&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$stockID</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;STOCK&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stockAmount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;AMOUNT&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stockPurchased</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">BuyStock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stockID</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stockAmount</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;searchSymbol&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;searchSymbol&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetStocksFromYahoo</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;searchSymbol&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Buy some stock, search and buy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stockPurchased</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p class=<span style="color: #000099; font-weight: bold;">\&quot;</span>details<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stockPurchased</span> <span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Stock was purchased (<span style="color: #006699; font-weight: bold;">$stockID</span> amount of <span style="color: #006699; font-weight: bold;">$StockAmount</span> total price of <span style="color: #006699; font-weight: bold;">$stockPurchased</span> each price was &quot;</span><span style="color: #339933;">.</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stockPurchased</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$stockAmount</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span> 
		<span style="color: #b1b100;">else</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Problem with purchasing the stock, please email the error above to the support team&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot; onsubmit=&quot;return CheckBuy()&quot;/&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;{<span style="color: #006699; font-weight: bold;">$_REQUEST</span>[&quot;</span>searchSymbol<span style="color: #0000ff;">&quot;]}&lt;/h2&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;The price of {<span style="color: #006699; font-weight: bold;">$_REQUEST</span>[&quot;</span>searchSymbol<span style="color: #0000ff;">&quot;]} is <span style="color: #006699; font-weight: bold;">$result</span>, do you want to buy ?&lt;br/&gt;Please enter how many and tick the box.&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>AMOUNT<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span>AMOUNT<span style="color: #000099; font-weight: bold;">\&quot;</span> onkeyup=<span style="color: #000099; font-weight: bold;">\&quot;</span>javascript:CheckKey(this)<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>hidden<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>STOCK<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #006699; font-weight: bold;">$_REQUEST</span>[&quot;</span>searchSymbol<span style="color: #0000ff;">&quot;]}<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>checkbox<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>buyme<span style="color: #000099; font-weight: bold;">\&quot;</span> id=<span style="color: #000099; font-weight: bold;">\&quot;</span>BUYME<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>submit<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span>Submit<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;&lt;b&gt;Or search for another stock&lt;/b&gt;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;Not stock of that symbol - {<span style="color: #006699; font-weight: bold;">$_REQUEST</span>[&quot;</span>searchSymbol<span style="color: #0000ff;">&quot;]}&lt;/h2&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;br/&gt;
Search Symbol :&lt;input type=&quot;text&quot; name=&quot;searchSymbol&quot; id=&quot;searchSymbol&quot;/&gt;
&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;/&gt;
&lt;/form&gt;
&lt;h2&gt;Your present cash flow is&lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetCash</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	HTMLFooter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>To view the stock details of the user, I just display the stock that the user has from data once again from the stock class, which also includes the current price of the stock.  There is a checkbox that will allow the user to sell some of there stock (if they have any!!) and once again use the stock class to sell the stock and update the tables in the database.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /index.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;remove_&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SellStock</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;stock&quot;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$getStock</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The details of your account&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;h2&gt;The stocks that the user has&lt;/h2&gt;
&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot; onsubmit=&quot;return checkSell()&quot;&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;Stock Name&lt;/td&gt;&lt;td&gt;Quantity&lt;/td&gt;&lt;td&gt;Price of Stock&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt;&lt;td&gt;Sell&lt;/td&gt;&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000088;">$totalValue</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$usersStock</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ReturnAllStocks</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$usersStock</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #006699; font-weight: bold;">$_SERVER</span>[&quot;</span>PHP_SELF<span style="color: #0000ff;">&quot;]}?stock=<span style="color: #006699; font-weight: bold;">{$theStocks[0]}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">{$theStocks[0]}</span>&lt;/a&gt;&lt;/td&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">{$theStocks[1]}</span>&lt;/td&gt;&lt;td&gt;<span style="color: #006699; font-weight: bold;">{$theStocks[2]}</span>&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">.</span>
			<span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;td&gt;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>checkbox<span style="color: #000099; font-weight: bold;">\&quot;</span> value=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">{$theStocks[0]}</span><span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>remove_<span style="color: #006699; font-weight: bold;">{$theStocks[0]}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$totalValue</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$theStocks</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td colspan=<span style="color: #000099; font-weight: bold;">\&quot;</span>2<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&lt;/td&gt;&lt;td&gt;Total value&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$totalValue</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/table&gt;
&lt;input id=&quot;center&quot; type=&quot;submit&quot; value=&quot;Submit&quot;/&gt;
&lt;/form&gt;
&lt;h2&gt;Your present cash flow is&lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetCash</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;Your cash + investments&lt;/h2&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">GetCash</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$totalValue</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$getStock</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h2&gt;<span style="color: #006699; font-weight: bold;">$getStock</span> more information&lt;/h2&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Date&lt;/td&gt;&lt;td&gt;Title/Link&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stockDetailsArray</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theStock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ArrayOfStockDetails</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$getStock</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stockDetailsArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;tr&gt;&lt;td&gt;{<span style="color: #006699; font-weight: bold;">$stockDetailsArray</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span><span style="color: #990000;">Date</span><span style="color: #0000ff;">&quot;]}&lt;/td&gt;&lt;td&gt;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>{<span style="color: #006699; font-weight: bold;">$stockDetailsArray</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span><span style="color: #990000;">Link</span><span style="color: #0000ff;">&quot;]}<span style="color: #000099; font-weight: bold;">\&quot;</span> target=<span style="color: #000099; font-weight: bold;">\&quot;</span>_blank<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;{<span style="color: #006699; font-weight: bold;">$stockDetailsArray</span>[<span style="color: #006699; font-weight: bold;">$i</span>][&quot;</span>Title<span style="color: #0000ff;">&quot;]}&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/table&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLFooter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The last part is the change of the password, which just will use the user class to update the users password to the requested input from the change password page.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password1&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password2&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password1&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password2&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ChangePassword</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password1&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #000088;">$notSamePassword</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /index.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Change password&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Password updated&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> 
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Cannot update the password, please contact the system admin&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notSamePassword</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Passwords are not the same&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!-- taken from http://www.html.it/articoli/nifty/index.html--&gt;
&lt;div id=&quot;login&quot;&gt;
&lt;b class=&quot;rtop&quot;&gt;
  &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; onsubmit=&quot;return CheckChangePasswords()&quot;&gt;
Change your password &lt;p&gt;
New Password : &lt;input type=&quot;password&quot; name=&quot;password1&quot; id=&quot;password1&quot; value=&quot;&quot;/&gt;&lt;/p&gt;
Retype New Password : &lt;input type=&quot;password&quot; name=&quot;password2&quot; id=&quot;password2&quot; value=&quot;&quot;/&gt;&lt;/p&gt;
&lt;input type=&quot;submit&quot;/&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;b class=&quot;rbottom&quot;&gt;
  &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	HTMLFooter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The actual pages that are displayed to the user are all very basic as them selves, but the actual logic and formula are all within the classes that is the gold dust as such, since it is one point of checking and also one file to update if there is a update to the yahoo etc stocks details, because would have to update the different pages that display the stocks and that is not good for testing and also updating.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-5-view-users-details-buy-stock-change-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CS71 &#8211; Ass1 &#8211; Finance &#8211; Part 4 &#8211; Login Register Forgotten password</title>
		<link>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-login-register-forgotten-password/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cs71-ass1-finance-part-2-login-register-forgotten-password</link>
		<comments>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-login-register-forgotten-password/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:41:39 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Assignment 1]]></category>
		<category><![CDATA[CS75]]></category>
		<category><![CDATA[Finance]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1151</guid>
		<description><![CDATA[I am doing the Harvards building dynamic websites called CS-75 (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning even if allot of it you may already know. Since most of the work is done in the class files, from the previous [...]]]></description>
			<content:encoded><![CDATA[<p><span id="zipfile"><a href="http://www.codingfriends.com/wp-content/uploads/2010/08/cs75-ass1.zip"></a></span>I am doing the <a href="http://www.harvard.edu/">Harvards</a> building dynamic websites called <a href="http://www.cs75.net/">CS-75</a> (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  even if allot of it you may already know.</p>
<p>Since most of the work is done in the <a href="http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-classes/">class files</a>, from the previous post then we just use the classes to only have basic php pages for the user.  So the login page is just, which also has a check for if the user is already logged in and goto the viewdetails page, or if the user requests to logout then logout the user, the main page is just logging the user in.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LoginCheck</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;logout&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Logout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /viewdetails.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Login to the stocks!&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #339933;">==</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Not able to login, please try again&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;logout&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Thanks for using the site, you are logged out!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!-- taken from http://www.html.it/articoli/nifty/index.html--&gt;
&lt;div id=&quot;login&quot;&gt;
&lt;b class=&quot;rtop&quot;&gt;
  &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; onsubmit=&quot;&quot;&gt;
Login
&lt;p&gt;
Username : &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
&lt;/p&gt;
&lt;p&gt;
Password : &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot;/&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;input type=&quot;submit&quot;/&gt;
&lt;/p&gt;
&lt;p id=&quot;right&quot;&gt;
&lt;a href=&quot;register.php&quot;&gt;Register&lt;/a&gt; here.
&lt;/p&gt;
&lt;/form&gt;
&lt;b class=&quot;rbottom&quot;&gt;
  &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	HTMLFooter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Here is the register page, where I send the request to the users class and utilize the return value to display either a message of check your emails (or in this case it will be a link on the top of the page) or display a error to the user depending on what could happen, e.g. not a valid valid/password(if the user turned off javascript checking) and also if there is already that email address present, the next check checks for the valid ID value that is sent to the user to validate there email.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">RegisterUser</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$notValidPassword</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$notValidEmail</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$emailAddressAlreadyPresent</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$checkEmails</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;validid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CheckUserGUID</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;validid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$userInvalid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>			
			<span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LoginCheck</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /viewdetails.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /viewdetails.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Register&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$checkEmails</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Please check your emails to validate your email address&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notValidPassword</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Not a valid password!, please enter one that is 6 characters and has at least 1 aphla/numeric&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$emailAddressAlreadyPresent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Please use the forgotten password recovery,  already email address registered&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notValidEmail</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Not a valid email address&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$userInvalid</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Does not validate correctly, please contact the system admin&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!-- taken from http://www.html.it/articoli/nifty/index.html--&gt;
&lt;div id=&quot;login&quot;&gt;
&lt;b class=&quot;rtop&quot;&gt;
  &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; onsubmit=&quot;return CheckRegister()&quot;&gt;
Register &lt;p&gt;
Username : &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
(valid email address)&lt;/p&gt;
&lt;p&gt;
Password : &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot;/&gt;
(Has to be at least 6 characters and with 1 numeric and aplha character&lt;/p&gt;
&lt;p&gt;
&lt;input type=&quot;submit&quot;/&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;b class=&quot;rbottom&quot;&gt;
  &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	HTMLFooter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Here is the last part, that will allow the user to enter there email to be able to get a link to enable them to change there password.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;functions_start.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ForgottenUser</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$checkEmails</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> 
			<span style="color: #000088;">$notValidEmail</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;validid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CheckUserGUID</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;validid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$userInvalid</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>			
			<span style="color: #000088;">$theUser</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">LoginCheck</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /changepassword.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;authenticated&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /viewdetails.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Forgotten password&quot;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$checkEmails</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div&gt;Please check your emails to validate your email address&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$notValidEmail</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>error<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Cannot find that email address&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!-- taken from http://www.html.it/articoli/nifty/index.html--&gt;
&lt;div id=&quot;login&quot;&gt;
&lt;b class=&quot;rtop&quot;&gt;
  &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;form method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;PHP_SELF&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; onsubmit=&quot;return CheckRegister(true)&quot;&gt;
Forgotten password, please enter your username &lt;p&gt;
Username : &lt;input type=&quot;text&quot; name=&quot;username&quot; id=&quot;username&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
(valid email address)&lt;/p&gt;
&lt;input type=&quot;submit&quot;/&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;b class=&quot;rbottom&quot;&gt;
  &lt;b class=&quot;r4&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r3&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r2&quot;&gt;&lt;/b&gt; &lt;b class=&quot;r1&quot;&gt;&lt;/b&gt;
&lt;/b&gt;
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	HTMLFooter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>As you can see the actual pages are really simple because most of the work is done in the class files</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-login-register-forgotten-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CS71 &#8211; Ass1 &#8211; Finance &#8211; Part 3 &#8211; javascript and common php page</title>
		<link>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-javascript-and-common-php-page/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cs71-ass1-finance-part-2-javascript-and-common-php-page</link>
		<comments>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-javascript-and-common-php-page/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:31:50 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Assignment 1]]></category>
		<category><![CDATA[CS75]]></category>
		<category><![CDATA[Finance]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1149</guid>
		<description><![CDATA[I am doing the Harvards building dynamic websites called CS-75 (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning even if allot of it you may already know. Before any of the actual pages start, they will all call this php file [...]]]></description>
			<content:encoded><![CDATA[<p><span id="zipfile"><a href="http://www.codingfriends.com/wp-content/uploads/2010/08/cs75-ass1.zip"></a></span>I am doing the <a href="http://www.harvard.edu/">Harvards</a> building dynamic websites called <a href="http://www.cs75.net/">CS-75</a> (also could be called E-75), because someone told me about it and I just thought might as well, it is all learning <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  even if allot of it you may already know.</p>
<p>Before any of the actual pages start, they will all call this php file so that it will build up the classes and connect to the database, so to start with need to pull in there classes and also start the session.  The two functions are the HTML header and footer parts of each page, so that do not have to alter every page to just add in another style as such, the last part is when we are creating the objects for the database/users/stocks.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;database.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;getstocks.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> HTMLHeader<span style="color: #009900;">&#40;</span><span style="color: #000088;">$titleTag</span><span style="color: #339933;">,</span><span style="color: #000088;">$loggedIn</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt; 
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$titleTag</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;
	&lt;link href=&quot;style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;/&gt;
	&lt;script src=&quot;ass1.js&quot; language=&quot;javascript&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
 &lt;body&gt;
&lt;div id=&quot;mainpage&quot;&gt; 
	&lt;ul id=&quot;menuoptions&quot;&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$loggedIn</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;li&gt;&lt;a href=&quot;viewdetails.php&quot;&gt;View your stock&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;buystock.php&quot;&gt;Buy stock&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;index.php?logout=true&quot;&gt;Logout&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;changepassword.php&quot;&gt;Change password&lt;/a&gt;&lt;/li&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;li&gt;&lt;a href=&quot;index.php&quot;&gt;Login&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;register.php&quot;&gt;Register&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;forgotten.php&quot;&gt;Forgotten password&lt;/a&gt;&lt;/li&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/ul&gt;
&lt;div id =&quot;container&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> HTMLFooter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$db</span><span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqlConnect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;cs75_project1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$theStock</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StocksDetails<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$theUser</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Because in the HTMLHeader function I am linking to the ass1.js file, which is the javascript code that will allow for a better user experience because we can do some input tests before sending to the server.</p>
<p>This is the function that checks the users input when they are trying to sell some of the stock that they have</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> checkSell<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> formElem <span style="color: #339933;">=</span> document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> elemsEmpty <span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> formElem.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> elem <span style="color: #339933;">=</span> formElem<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>elem.<span style="color: #660066;">type</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;checkbox&quot;</span> <span style="color: #339933;">&amp;&amp;</span> elem.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span>
			elemsEmpty<span style="color: #339933;">++;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>elemsEmpty <span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please select a item to sell&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>When the user is on the buying stock page, it would be good to make sure that the value is a integer value before the user actually sends the request to the server, it will also check to make sure that there is a symbol to search for, saves on just clicking on the submit without any data.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> CheckBuy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> symbol <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;searchSymbol&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> amount <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;AMOUNT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>symbol.<span style="color: #660066;">value</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">3</span> <span style="color: #339933;">&amp;&amp;</span> amount <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please insert a search symbol&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		symbol.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>amount <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> amount.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isNaN<span style="color: #009900;">&#40;</span>amount<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> amount.<span style="color: #660066;">value</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;BUYME&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please select the tick box next to the amount&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>	
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span> 
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter a valid amount to buy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;AMOUNT&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This function actually checks the users input on the amount of stock to buy and making sure that it is only numeric values.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// only allow integer values within the box</span>
<span style="color: #003366; font-weight: bold;">function</span> CheckKey<span style="color: #009900;">&#40;</span>boxToCheck<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> boxValue<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> boxToCheck.<span style="color: #660066;">value</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isNaN<span style="color: #009900;">&#40;</span>boxToCheck.<span style="color: #660066;">value</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			boxValue <span style="color: #339933;">+=</span> boxToCheck.<span style="color: #660066;">value</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	boxToCheck.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> boxValue<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This function, checks to make sure that the registration screen has a valid email address (does another check on the server if the user turns off javascript), and also checks the password for the correct format.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> CheckRegister<span style="color: #009900;">&#40;</span>justUsername<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> username <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;username&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> password <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>username.<span style="color: #660066;">value</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>justUsername<span style="color: #009900;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> CheckPassword<span style="color: #009900;">&#40;</span>password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>   
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Incorrect email format&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This the actual function that will check the password is in the correct format, e.g. 1+ numeric/alpha characters. and more than 6 in length.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> CheckPassword<span style="color: #009900;">&#40;</span>password<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>password.<span style="color: #660066;">value</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;=</span><span style="color: #CC0000;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> addLet <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> password.<span style="color: #660066;">value</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isNaN<span style="color: #009900;">&#40;</span>password.<span style="color: #660066;">value</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				addLet<span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>addLet <span style="color: #339933;">==</span> password.<span style="color: #660066;">value</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter a password that contains at least 1 aplha/numeric character&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter a password that is at least 6 characters long&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here on the change password, I am making sure that the first password conforms to the above function check and also that the two passwords are the same in value.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> CheckChangePasswords<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>CheckPassword<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;password1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;password1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;password2&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Passwords do not match&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next is the actual php pages that the user will interact with.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/08/11/cs71-ass1-finance-part-2-javascript-and-common-php-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
