CS71 – Ass1 – Finance – Part 5 – View users details – buy stock – change password

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 it is just displaying data to the user that was built up from the classes files.

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.

BuyStock($_SESSION["username"], $stockID, $stockAmount);
	if (isset($_REQUEST["searchSymbol"]))
		if (strlen($_REQUEST["searchSymbol"]) >=3)
			$result = $theStock->GetStocksFromYahoo(strtoupper($_REQUEST["searchSymbol"]));

	HTMLHeader("Buy some stock, search and buy");

	if (isset ($stockPurchased)) {
		echo "

"; if ($stockPurchased >0 ) echo "Stock was purchased ($stockID amount of $StockAmount total price of $stockPurchased each price was ". number_format($stockPurchased / $stockAmount,2).")"; else echo "Problem with purchasing the stock, please email the error above to the support team"; echo "

"; } ?>
" method="post" onsubmit="return CheckBuy()"/> 0) { echo "


"; echo "The price of {$_REQUEST["searchSymbol"]} is $result, do you want to buy ?
Please enter how many and tick the box.
"; echo ""; echo ""; echo ""; echo ""; echo "

Or search for another stock

"; } else echo "

Not stock of that symbol - {$_REQUEST["searchSymbol"]}

"; } ?>
Search Symbol :

Your present cash flow is

GetCash($_SESSION["username"]),2); HTMLFooter(); ?>

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.

		if (strpos($key, "remove_") === 0)
			$theStock->SellStock($_SESSION["username"], $value);
		if ($key=="stock")
			$getStock = $value;
	HTMLHeader("The details of your account");

The stocks that the user has

" method="post" onsubmit="return checkSell()"> ReturnAllStocks($_SESSION["username"]); foreach ($usersStock as $theStocks) { echo ""; $totalValue += $theStocks[2] * $theStocks[1]; } echo ""; ?>
Stock NameQuantityPrice of StockValueSell
{$theStocks[0]}{$theStocks[1]}{$theStocks[2]}". number_format($theStocks[2] * $theStocks[1],2)."
Total value".number_format($totalValue,2)."

Your present cash flow is

GetCash($_SESSION["username"]),2); echo "

Your cash + investments

" . number_format($theUser->GetCash($_SESSION["username"]) + $totalValue,2); if (isset($getStock)) { echo "

$getStock more information

"; $stockDetailsArray = $theStock->ArrayOfStockDetails($getStock); for ($i = 0; $i < sizeof($stockDetailsArray); $i++) { echo "
{$stockDetailsArray[$i]["Date"]}{$stockDetailsArray[$i]["Title"]}"; } echo "
"; } HTMLFooter(); ?>

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.

ChangePassword($_SESSION["username"], $_REQUEST["password1"]);
			$notSamePassword = true;

	if (!isset($_SESSION["authenticated"]))
		header("Location: /index.php");

	HTMLHeader("Change password",true);

	if (isset($error))
		if ($error)
			echo "
Password updated
"; else echo "
Cannot update the password, please contact the system admin
"; } if (isset($notSamePassword)) echo "
Passwords are not the same
"; ?>
" onsubmit="return CheckChangePasswords()"> Change your password

New Password :

Retype New Password :

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.

Leave a Reply

Your email address will not be published. Required fields are marked *