Changeset - c772d532c74a
[Not reviewed]
default
0 3 0
Ethan Zonca - 15 years ago 2011-02-01 20:10:56
ez@ethanzonca.com
Page class and other UI updates. Saved schedule box works properly now.
3 files changed with 81 insertions and 88 deletions:
0 comments (0 inline, 0 general)
inc/class.page.php
Show inline comments
 
@@ -50,74 +50,69 @@ set_include_path(get_include_path() . PA
 
$config_inc = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'config.inc';
 
if (file_exists($config_inc)) {
 
  require_once($config_inc);
 
}
 

	
 

	
 

	
 

	
 
//**************************************************
 
// class.page.php   Author: Ethan Zonca
 
//
 
// Provides an interface for generating a styled
 
// XHTML page, supporting modular script inclusion
 
// and other various features
 
//**************************************************
 
class page
 
{
 

	
 
  /* Site-wide configuration options */
 
  private $base_title = 'SlatePermutate :: Find the schedule that works for you!';
 
  private $base_title = 'SlatePermutate - Find the schedule that works for you!';
 
  private $doctype = 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"';
 
  private $htmlargs = 'xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"';
 
  private $bodyargs = '';
 

	
 

	
 
  public $lastJobTable = '';
 
  private $pageGenTime = 0;
 

	
 
  /* Whether or not to output valid XHTML */
 
  private $xhtml = FALSE;
 

	
 
  /* Scripts and styles */
 
  private $headCode = array();
 

	
 
  /*
 
   * Google analytics ga.js tracking code. Expanded in __construct().
 
   */
 
  private $trackingcode = '';
 

	
 
  private $trackingcode = ''; // Tracking code
 
  private $pagetitle = ''; // Title of page
 
  private $scripts = array(); // Scripts to include on page
 

	
 
  /* the current school. See get_school(). */
 
  private $school;
 

	
 

	
 
  /**
 
   * \param $ntitle
 
   *   Must be a valid HTML string (i.e., escaped with htmlentities()).
 
   * \param $nscripts
 
   *   An array of strings identifying the scripts to include for this page.
 
   */
 
  public function __construct($ntitle, $nscripts = array(), $immediate = TRUE)
 
  {
 
    /* Begin tracking generation time */
 
    $this->pageGenTime = round(microtime(),4);
 

	
 
    global $ga_trackers;
 

	
 
    require_once('school.inc');
 

	
 
    // Scripts and styles available to include
 
    /* Scripts and styles available for inclusion */
 
    $this->headCode['jQuery'] = '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>';
 
    $this->headCode['jQueryUI'] = '<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js" type="text/javascript"></script><link rel="stylesheet" href="styles/jqueryui.css" type="text/css" media="screen" charset="utf-8" />';
 
    $this->headCode['jValidate'] = '<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js"></script>';
 
    $this->headCode['qTip'] = '<script type="text/javascript" src="http://ohnopub.net/js/jquery.qtip-1.0.min.js"></script>';
 
    $this->headCode['schedInput'] = '<script type="text/javascript" src="scripts/scheduleInput.js"></script>';
 
    $this->headCode['outputPrintStyle'] = '<link rel="stylesheet" href="styles/print.css" type="text/css" media="screen" charset="utf-8" />';
 
    $this->headCode['outputStyle'] = '<link rel="stylesheet" href="styles/output.css" type="text/css" media="screen" charset="utf-8" />'; 
 
    $this->headCode['gliderHeadcode'] = '<link rel="stylesheet" href="styles/glider.css" type="text/css" media="screen" charset="utf-8" />'; 
 
    $this->headCode['uiTabsKeyboard'] = '<script type="text/javascript" src="scripts/uiTabsKeyboard.js"></script>';
 
    $this->headCode['displayTables'] = '<script type="text/javascript" src="scripts/displayTables.js"></script>';
 

	
 
    $this->pagetitle = $ntitle;
 
    $this->scripts = $nscripts;
 

	
 
   /* Compliant browsers which care, such as gecko, explicitly request xhtml: */
 
   if(empty($_SERVER['HTTP_ACCEPT'])  /* then the browser doesn't care :-) */
 
      || strpos($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') !== FALSE)
 
@@ -194,124 +189,118 @@ class page
 
   * \param $enable
 
   *   Whether or not to enable this code while adding it.
 
   */
 
  public function headcode_add($key, $code, $enable = FALSE)
 
  {
 
    $this->headCode[$key] = $code;
 
    if ($enable)
 
    if ($enable) {
 
      $this->scripts[] = $key;
 
  }
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Output the HTML header for a page, including the <!DOCTYPE> and <head />
 
   *   Output the HTML header for a page, including <!DOCTYPE>, <head />, and opening structure
 
   */
 
  public function head()
 
  {
 
    $this->pageGenTime = round(microtime(), 3);
 

	
 
    if ($this->xhtml)
 
    if ($this->xhtml) {
 
      echo '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
 
    }
 

	
 
    echo '<!DOCTYPE ' . $this->doctype . '>'. PHP_EOL .
 
	  '<html ' . $this->htmlargs . '>'. PHP_EOL .
 
	  '  <head>'. PHP_EOL .
 
	  '    <title>' . $this->pagetitle . ' :: ' . $this->base_title . '</title>'. PHP_EOL .
 
	  '    <title>' . $this->pagetitle . ' - ' . $this->base_title . '</title>'. PHP_EOL .
 
          '    <link rel="stylesheet" href="styles/general.css" type="text/css" media="screen" charset="utf-8" />'.  PHP_EOL .
 
	  '    <link rel="stylesheet" type="text/css" media="print" href="styles/print.css" />'. PHP_EOL .
 
    '    <link rel="shortcut icon" href="images/favicon.png" />'. PHP_EOL;
 

	
 
    // Write out all passed scripts
 
    foreach ($this->scripts as $i)
 
      echo '    ' . $this->headCode["$i"] . "\n";
 

	
 
    echo '  </head>' . PHP_EOL .
 
	 '  <body '.$this->bodyargs.'>'. PHP_EOL .
 
         '    <div id="page">'. PHP_EOL;
 
    echo $this->top(); // Write out top
 
  }
 

	
 
  /** Write out the top of the page, including opening div tags, header title and images, etc */
 
  private function top(){
 
    echo '      <div id="header">'. PHP_EOL .
 
	 '  <body>'. PHP_EOL .
 
         '    <div id="page">'. PHP_EOL .
 
         '      <div id="header">'. PHP_EOL .
 
	 '        <div id="title">'. PHP_EOL .
 
         '          <h1><a href="index.php"><img src="images/slatepermutate-alpha.png" alt="SlatePermutate" class="noborder" /></a><br /></h1>'. PHP_EOL .
 
         '          <p>'. PHP_EOL .
 
         '            <span id="subtitle">'.$this->pagetitle.'</span>'. PHP_EOL .
 
  	 '            <span id="menu">Profile: '.$this->school['name'].' <a href="input.php?selectschool=1">(change)</a></span>'. PHP_EOL .
 
         '          </p>'. PHP_EOL .
 
         '        </div>'. PHP_EOL .
 
	 '      </div>'. PHP_EOL .
 
         '      <div id="content">'. PHP_EOL;
 
  }
 

	
 
  /** Write out the foot of the page and closing divs */
 
  /**
 
   * \brief
 
   *   Write out the foot of the page and closing divs
 
   */
 
  public function foot(){
 
    echo '      </div> <!-- id="content" -->'. PHP_EOL;
 
    $this->pageGenTime = round(microtime(), 3);
 
    echo '      <div id="footer">'. PHP_EOL .
 
  	 '        <div id="leftfoot" style="float:left; margin-top: 1em;">'. PHP_EOL .
 
	 '          <a href="feedback.php">Submit Feedback</a>'. PHP_EOL .
 
         '        </div>'. PHP_EOL .
 
         '        <div id="rightfoot">'. PHP_EOL .
 
         '          <h5>&copy; '. date('Y').' <a href="http://protofusion.org/~nathang/">Nathan Gelderloos</a><br /><a href="http://ethanzonca.com">Ethan Zonca</a><br /><a href="http://ohnopub.net">Nathan Phillip Brink</a></h5>'. PHP_EOL .
 
	 '        </div>'. PHP_EOL .
 
         '      </div> <!-- id="footer" -->'. PHP_EOL .
 
         '    </div> <!-- id="page" -->'. PHP_EOL;
 
    echo $this->trackingcode;
 
    echo '  </body>'. PHP_EOL .
 
         '</html>';
 
  }
 

	
 
  /** Takes a number in seconds, and outputs HH:MM:SS */
 
  public function secondsToCompound($seconds) {
 
      $ret = "";
 
      $hours = intval(intval($seconds) / 3600);
 
      $ret .= "$hours:";
 
      $minutes = bcmod((intval($seconds) / 60),60);
 
      $ret .= "$minutes:";
 
      $seconds = bcmod(intval($seconds),60);
 
      $ret .= "$seconds";
 
      return $ret;
 
         '</html>' . PHP_EOL;
 
    $this->pageGenTime = round(microtime() - $this->pageGenTime,4);
 
    echo '<!-- Page generated in ' . $this->pageGenTime . ' seconds -->';
 
  }
 

	
 
  /** Shows a box with recently processed schedules */
 
  public function showSavedScheds($session)
 
  {
 
  /**
 
   * \brief
 
   *   Shows a box with recently processed schedules
 
   */
 
  public function showSavedScheds($session) {
 
    global $clean_urls;
 

	
 
    echo '<p>';
 
    if (isset($session['saved']) && count($session['saved']) > 0)
 
      {
 
    if (isset($session['saved']) && count($session['saved']) > 0) {
 
      echo '<div id="savedBox">' . PHP_EOL;
 

	
 
	$process_php_s = 'process.php?s=';
 
	if ($clean_urls)
 
      if ($clean_urls) {
 
	  $process_php_s = '';
 
      }
 

	
 
	echo '<div id="savedBox" ><h3>Saved Schedules:</h3>';
 

	
 
      echo '<h3>Saved Schedules:</h3>';
 

	
 
        $hidden = '';
 
	foreach($session['saved'] as $key => $name)
 
	  {
 
            if($key == 5) {
 
              echo '<div id="showMore"><a href="#">More...</a></div>';
 
      $count = 0;
 
      $output = '';
 

	
 
      foreach($session['saved'] as $key => $name) {
 
	if($count == 4) {
 
	  $output .= '<div id="showMore"><a href="#">More...</a></div>';
 
              $hidden = 'hidden';
 
            }
 
            else {
 
                    echo '<p class="' . $hidden . '">';
 
 		    echo '<a href="' . $process_php_s . $key . '" title="View schedule #' . $key . '">#' . $key . "</a>:\n "
 
	  $output =  '<p class="' . $hidden . '">'  . PHP_EOL
 
	           . '  <a href="' . $process_php_s . $key . '" title="View schedule #' . $key . '">#' . $key . "</a>:" 
 
		      . htmlentities($name)
 
		      . ' <a href="input.php?s=' . $key . '">edit</a>'
 
		      . ' <a href="process.php?del=' . $key . '">delete</a>'
 
		      . "<br /><br />\n"
 
                      . '</p>';
 
	           . ' <br /><br />' . PHP_EOL
 
	           . '</p>' . PHP_EOL . $output;
 
	   }
 
          $count++;
 
	  }
 
	echo '<div id="showLess"><a href="#">Less...</a></div></div>';
 
	echo $output;
 
	echo '<div id="showLess"><a href="#">Less...</a></div>' . PHP_EOL;
 
	echo '</div>' . PHP_EOL;
 
      }
 
    echo '</p>';
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Display a list of schools the user might be from.
 
   * \param $linkto
 
@@ -328,15 +317,15 @@ class page
 
  /**
 
   * \brief
 
   *   Display school-specific instructions for using slate_permutate.
 
   */
 
  public function showSchoolInstructions()
 
  {
 
    echo "<div id=\"schoolInstructionsBox\">\n";
 
    echo school_instructions_html($this->school);
 
    echo "</div> <!-- id=\"schoolInstructionsBox\" -->\n";
 
    echo '<div id="schoolInstructionsBox">' . PHP_EOL
 
       . school_instructions_html($this->school) . PHP_EOL
 
       . '</div> <!-- id="schoolInstructionsBox" -->' . PHP_EOL;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Print out a vocative form of a student's identity. For example,
 
   *   Dearborn Christin Schoolers are called ``Knights'' as are
 
@@ -377,13 +366,13 @@ class page
 
   * page out to the user.
 
   *
 
   * \param $message
 
   *   A message consisting of valid XHTML to display to the user in
 
   *   the 404 page.
 
   */
 
  public static function show_404($message = 'I couldn\'t find what you were looking for :-/.')
 
  public static function show_404($message = 'The page you were looking for cannot be found!.')
 
  {
 
    $page_404 = page::page_create('404: Content Not Found');
 
    $page_404->head();
 

	
 
    echo "<h2>404: Content Not Found</h2>\n"
 
      . "<p>\n"
 
@@ -487,19 +476,23 @@ class page
 
   *   The javascript to wrap up.
 
   * \param $type
 
   *   The type="" attribute of the <script/> element
 
   */
 
  public function script_wrap($js, $type = 'text/javascript')
 
  {
 
    return '<script type="' . $type . '">
 
' . ($this->xhtml ? '<![CDATA[' : '') . '
 
' . $js . '
 
' . ($this->xhtml ? ']]>' : '') . '
 
// </script>';
 
    return '<script type="' . $type . '">' . PHP_EOL
 
         . ($this->xhtml ? '<![CDATA[' : '') . PHP_EOL
 
         . $js . PHP_EOL
 
	 . ($this->xhtml ? ']]>' : '') . PHP_EOL
 
         . '// </script>';
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Add a trailing slash to a path if one does not already exist
 
   */
 
  private function add_trailing_slash($path){
 
    if($path[strlen($path)-1] != '/') {
 
      return $path . "/";
 
    }
 
    else {
 
      return $path;
 
@@ -516,14 +509,18 @@ class page
 
   *   XHTML document.
 
   */
 
  public function gen_share_url($id)
 
  {
 
    global $clean_urls, $short_url_base;
 

	
 
    if ($clean_urls && isset($short_url_base))
 
    if ($clean_urls && isset($short_url_base)) {
 
      return $this->add_trailing_slash($short_url_base) . $id;
 
    elseif ($clean_urls)
 
    }
 
    elseif ($clean_urls) {
 
      return 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $id;
 
    else
 
    }
 
    else {
 
      return 'http://' . $_SERVER['HTTP_HOST']  . dirname($_SERVER['REQUEST_URI']) . '/process.php?s=' . $id;
 
  }
 
}
 

	
 
}
index.php
Show inline comments
 
@@ -23,14 +23,12 @@ require_once 'inc/class.page.php';
 
$welcomepage = page::page_create('Welcome');
 
$welcomepage->head();
 
?>
 

	
 
<h3>Find the schedule that works for you!</h3>
 
<p>Plan your next semester with SlatePermutate! SlatePermutate generates every possible schedule with the courses you enter to let you pick the schedule that fits your life.</p>
 
<p><!-- View <a href="schedulecreator.php">demo output</a> or --><a href="input.php">Get started</a></p> 
 

	
 
<p><a href="input.php">Get started</a></p> 
 

	
 
<p class="righttext"><a href="input.php"><img class="noborder" src="images/get-started.png" alt="Get Started" /></a></p>
 
<!-- <p style="color: #777; font-size: .7em;">This program was created by <a href="http://www.calvin.edu" rel="external">Calvin College</a> and <a href="http://cedarville.edu/" rel="external">Cedarville University</a> students. SlatePermutate works with any college or university.</p>
 
-->
 

	
 
<?php
 
$welcomepage->foot();
input.php
Show inline comments
 
@@ -15,17 +15,17 @@
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with SlatePermutate.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
include_once 'inc/class.schedule.php';
 
include_once 'inc' . DIRECTORY_SEPARATOR . 'class.schedule.php';
 
include_once 'inc' . DIRECTORY_SEPARATOR . 'class.course.inc';
 
include_once 'inc/class.section.php';
 
include_once 'inc/class.page.php';
 
require_once('inc/schedule_store.inc');
 
include_once 'inc' . DIRECTORY_SEPARATOR . 'class.section.php';
 
include_once 'inc' . DIRECTORY_SEPARATOR . 'class.page.php';
 
require_once('inc' . DIRECTORY_SEPARATOR . 'schedule_store.inc');
 

	
 
$scripts = array('jQuery', 'jQueryUI', 'jValidate','qTip','schedInput');
 
$inputPage = page::page_create('Scheduler', $scripts, FALSE);
 

	
 
$schedule_store = FALSE;
 
$sch = FALSE;
 
@@ -99,23 +99,21 @@ if (!empty($_REQUEST['selectschool'])
 
    exit;
 
  }
 

	
 
$inputPage->showSavedScheds($_SESSION);
 
?>
 
<p>
 
  Welcome to SlatePermutate<?php $inputPage->addressStudent(', ', '',
 
  FALSE); ?>! To get started, enter in some of your
 
  class IDs, and click the autosuggestion to add available sections for each class.
 
  Welcome to SlatePermutate<?php $inputPage->addressStudent(', ', '', FALSE); ?>!
 
  To get started, enter in some of your class IDs, and click the
 
  autosuggestion to add available sections for each class.
 
</p>
 

	
 
<form method="post" action="process.php" id="scheduleForm">
 
<br />
 
<label>Schedule Name</label><br />
 
<input id="scheduleName" style="margin-bottom: 1em;" class="defText required" type="text" size="25" title="Spring 2011" name="postData[name]"
 
<?php if ($sch) echo 'value="' . htmlentities($sch->getName(), ENT_QUOTES) . '"'; /*"*/ ?>
 
/>
 
<p class="nospace"><label>Schedule Name</label><br />
 
  <input id="scheduleName" style="margin-bottom: 1em;" class="defText required" type="text" size="25" title="Spring 2011" name="postData[name]" <?php if ($sch) echo 'value="' . htmlentities($sch->getName(), ENT_QUOTES) . '"'; /*"*/ ?> />
 
</p>
 

	
 
<table id="container">
 
  <tr>
 
    <td>
 
      <table id="jsrows">
 
        <!-- Header -->
0 comments (0 inline, 0 general)