25 January 2016

CST336 Week 4

Due to school server issues, only the lab was completed this week. Due to this I took the time to move all my class materials to my own VPS (virtual private server). The lab can be viewed at http://johnlester.rocks/cst336/labs/lab4a.php and http://johnlester.rocks/cst336/labs/lab4b.php. Good practice using MySQL and more PHP. My group (BITsoft) outlined how we were going to lay out the database and began some basic mock ups.

19 January 2016

CST336 Week 3

This week we covered a lot of PHP programming information, especially PHP arrays. I am enjoying learning about PHP, as their are many similarities with Perl. PHP is much more current skill than Perl, so should be quite useful in building web sites in the future.

For assignment 3 I built a simple MadLibs from www.bookish.com. The result can be viewed at http://hosting.otterlabs.org/lesterjohnj/assignments/assignment3.php with the code below:
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CST336 Assignment 3 by John Lester</title>
<style>
body { background-image:url(../media/background-library.jpg); }
table {
 width:640px;
 height:480px;
 position:fixed;
 margin-left:-320px;
 margin-top:-240px;
 left:50%;
 top:50%;
}
th { background-color:white; font-size:24px; height:40px; }
td { background-color:white; font-size:18px; }
</style>
<link rel="shortcut icon" href="../favicon.ico" />
</head>
<body>
<center>
<form action="assignment3.php" method="post">
<table border="0" width="640">
<tr><th colspan="2">BOOK<i>ish</i> Mad Libs</th></tr>
<?php
if (isset($_POST['word1'])) { // Second page
 $words1 = array($_POST['word1'], $_POST['word2'], $_POST['word3'], $_POST['word4'], $_POST['word5'], $_POST['word6'], $_POST['word7'], $_POST['word8'], $_POST['word9'], $_POST['word10'], $_POST['word11']);
 $_SESSION['words1'] = $words1;
 echo "<tr><td>Letter:</td><td><input type=text name=word12></td></tr>";
 echo "<tr><td>Celebrity:</td><td><input type=text name=word13></td></tr>";
 echo "<tr><td>Plural Noun:</td><td><input type=text name=word14></td></tr>";
 echo "<tr><td>Adjective:</td><td><input type=text name=word15></td></tr>";
 echo "<tr><td>Place:</td><td><input type=text name=word16></td></tr>";
 echo "<tr><td>Body Part:</td><td><input type=text name=word17></td></tr>";
 echo "<tr><td>Adjective:</td><td><input type=text name=word18></td></tr>";
 echo "<tr><td>Adjective:</td><td><input type=text name=word19></td></tr>";
 echo "<tr><td>Verb:</td><td><input type=text name=word20></td></tr>";
 echo "<tr><td>Plural Noun:</td><td><input type=text name=word21></td></tr>";
 echo "<tr><td>Number:</td><td><input type=text name=word22></td></tr>";
 echo "<tr><td colspan=2 align=center><input type=submit value=\"Finish\"><input type=reset value=Reset></td></tr>";
}
elseif (isset($_POST['word12'])) { // Third Page
 $words2 = array($_POST['word12'], $_POST['word13'], $_POST['word14'], $_POST['word15'], $_POST['word16'], $_POST['word17'], $_POST['word18'], $_POST['word19'], $_POST['word20'], $_POST['word21'], $_POST['word22']);
 $words = array_merge($_SESSION['words1'], $words2);
 echo "<tr><td colspan=2 style=\"padding-right:20px; padding-left:20px;\" valign=top>There are many ".$words[0]." ways to choose a/an ".$words[1]." to read. First, you could ask for recommendations from your friends and ".$words[2].". Just don't ask Aunt ".$words[3]." - she only reads ".$words[4]." books with ".$words[5]."-ripping goddesses on the cover. If your friends and family are no help, try checking out the ".$words[6]." Review in <i>The ".$words[7]." Times</i>. If the ".$words[8]." featured there are too ".$words[9]." for your taste, try something a little more low-".$words[10].", like ".$words[11].": <i>The ".$words[12]." Magazine</i>, or <i>".$words[13]." Magazine</i>. You could also choose a book the ".$words[14]."-fashioned way. Head to your local library or ".$words[15]." and browse the shelves until something catches your ".$words[16].". Or, you could save yourself a whole lot of ".$words[17]." trouble and log on to <a href=\"http://www.bookish.com\" target=\"_blank\">www.bookish.com</a>, the ".$words[18]." new website to ".$words[19]." for books! With all the time you'll save not having to search for ".$words[20].", you can read ".$words[21]." more books!<br><br><br>The word of the moment is ".$words[array_rand($words)]."<br><br>The words submitted include ";
 asort($words);
 $count = 0;
 while(list($var, $val) = each($words)) {
  echo $val;
  $count++;
  if ($count==count($words)-1) {
   echo " and ";
  }
  elseif ($count!=count($words)) {
   echo ", ";
  }
  else {
   echo ".";
  }
 }
 echo "<br><br><a href=\"assignment3.php\">Restart Mad Lib</a></td></tr>";
}
else { // First Page
 echo "<tr><td>Adjective:</td><td><input type=text name=word1></td></tr>";
 echo "<tr><td>Noun:</td><td><input type=text name=word2></td></tr>";
 echo "<tr><td>Plural Noun:</td><td><input type=text name=word3></td></tr>";
 echo "<tr><td>Female Name:</td><td><input type=text name=word4></td></tr>";
 echo "<tr><td>Adjective:</td><td><input type=text name=word5></td></tr>";
 echo "<tr><td>Article of Clothing:</td><td><input type=text name=word6></td></tr>";
 echo "<tr><td>Noun:</td><td><input type=text name=word7></td></tr>";
 echo "<tr><td>City:</td><td><input type=text name=word8></td></tr>";
 echo "<tr><td>Plural Noun:</td><td><input type=text name=word9></td></tr>";
 echo "<tr><td>Adjective:</td><td><input type=text name=word10></td></tr>";
 echo "<tr><td>Body Part:</td><td><input type=text name=word11></td></tr>";
 echo "<tr><td colspan=2 align=center><input type=submit value=\"Next\"><input type=reset value=Reset></td></tr>";
}
?>
</table>
</form>
</center>
</body>
</html>

12 January 2016

CST336 Week 2

I presented to the class this week, the video can be seen here.

Code from Assignment 2:

<html>
<head>
<title>CST336 Assignment 2 by John Lester</title>
<link rel="shortcut icon" href="../favicon.ico" />
<style>
body { 
    background-image: url(../media/background-casino.jpg);
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-position: center;
    background-color: black;
}
td.top {
 text-align: left;
 background-color: khaki;
}
table.top {
 position: absolute;
 top: 0px;
 border: none;
 width: 1000;
 left: 50%;
 margin-left: -500px;
}
table.main {
    position: relative;
    top: 450px;
    border: none;
}
</style>
<?php
$die1 = rand(1, 6);
$die2 = rand(1, 6);
$rollTotal = $die1 + $die2;
if (isset($_POST['roll'])) { $rollNum = $_POST['roll'] + 1; }
else { $rollNum = 1; }
if (isset($_POST['point'])) { $point = $_POST['point']; }
else { $point = 0; }
if (isset($_POST['wins'])) { $wins = $_POST['wins']; }
else { $wins = 0; }
if (isset($_POST['losses'])) { $losses = $_POST['losses']; }
else { $losses = 0; }
?>
</head>
<body>
<center>
<table class="main">
 <tr>
<?php
echo "<td><img src='../media/dice-" . $die1 . ".png' border=0></td>";
echo "<td><img src='../media/dice-" . $die2 . ".png' border=0></td>";
?>
 </tr>
 <tr>
  <td colspan=2 align=center><form method=post>
<?php
if ((($rollNum == 1) && (($rollTotal == 2) || ($rollTotal == 3) || ($rollTotal == 12))) || ($rollNum >= 2) && ($rollTotal == 7)) {
 echo "<h2>You Lose</h2>";
 $losses++;
 echo "<input type=submit value='Play Again'><input type=hidden name=roll value=0><input type=hidden name=wins value=" . $wins . "><input type=hidden name=losses value=" . $losses . ">";
}
elseif (($rollNum == 1) && (($rollTotal == 7) || ($rollTotal == 11)) || ($rollTotal == $point)) {
 echo "<h2>You Win!</h2>";
 $wins++;
 echo "<input type=submit value='Play Again'><input type=hidden name=roll value=0><input type=hidden name=wins value=" . $wins . "><input type=hidden name=losses value=" . $losses . ">";
}
elseif ($rollNum == 1) {
 echo "<h2>Point is " . $rollTotal . "</h2>";
 echo "<input type=submit value='Roll Again'><input type=hidden name=roll value=" . $rollNum . "><input type=hidden name=point value=" . $rollTotal . "><input type=hidden name=wins value=" . $wins . "><input type=hidden name=losses value=" . $losses . ">";
}
else  {
 echo "<h2>Point is " . $point . "</h2>";
 echo "<input type=submit value='Roll Again'><input type=hidden name=roll value=" . $rollNum . "><input type=hidden name=point value=" . $point . "><input type=hidden name=wins value=" . $wins . "><input type=hidden name=losses value=" . $losses . ">";
}
?>
  </form></td>
 </tr>
</table>
<table class="top">
 <tr>
  <td class="top" width="250">
<?php
 echo "Roll: <br>";
 for ($i=1; $i<=$rollNum; $i++) { echo "*"; }
 echo "<br>";
 echo "Wins: <br>";
 for ($i=1; $i<=$wins; $i++) { echo "*"; }
 echo "<br>";
 echo "Losses: <br>";
 for ($i=1; $i<=$losses; $i++) { echo "*"; }
?>
  </td>
  <td class="top"><center><b><u>BASIC CRAPS</u></b></center>This game is played in rounds consisting of two phases: come out and point.<br>
Come Out – to start a round, the shooter makes a “come out” roll. If the come out roll is a 2, 3, or 12, then the round ends in a loss. If the come out roll is a 7 or 11, this results in a win. The shooter continues to make come out rolls until he rolls 4, 5, 6, 8, 9, or 10. This number becomes the point and in turn the point phase begins.<br>
Point – during this phase, if the shooter rolls a point number then it’s a win. If the shooter rolls a 7, it’s a loss and the round is over.</td>
 </tr>

</table>
</center>
</body>
</html>

05 January 2016

CST336 Week 1

Many hours of reviewing HTML and CSS. Did start the class web site at hosting.otterlabs.org/classes/lesterjohnj/public_html (hopefully they fix the directory problem). The class started without notice ahead of time. Was quite surprised to sign in on what should have been the first day to find the first weeks assignments were due by midnight of that night. This is especially a problem as I work full-time and have other classes, so I generally work on this program during the weekend.

Do not go gentle into that good night

Dylan Thomas1951

Do not go gentle into that good night,
Old age should burn and rave at close of day;
Rage, rage against the dying of the light.

Though wise men at their end know dark is right,
Because their words had forked no lightning they
Do not go gentle into that good night.

Good men, the last wave by, crying how bright
Their frail deeds might have danced in a green bay,
Rage, rage against the dying of the light.

Wild men who caught and sang the sun in flight,
And learn, too late, they grieved it on its way,
Do not go gentle into that good night.

Grave men, near death, who see with blinding sight
Blind eyes could blaze like meteors and be gay,
Rage, rage against the dying of the light.

And you, my father, there on the sad height,
Curse, bless, me now with your fierce tears, I pray.
Do not go gentle into that good night.
Rage, rage against the dying of the light.