Setting up the boat schedule application from beaverisland
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 6 Jun 2014 15:20:16 +0000 (11:20 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 6 Jun 2014 15:20:16 +0000 (11:20 -0400)
Taking the beaverislandboatcompany schedule application.
This is a start of it as it will need some work.

27 files changed:
Toolkit/Database.php
Toolkit/Schedule/Calendar.php [new file with mode: 0644]
Toolkit/Schedule/CalendarMonthDecorator.php [new file with mode: 0644]
Toolkit/Schedule/Database/application.sql [new file with mode: 0644]
Toolkit/Schedule/Database/removeApplication.sql [new file with mode: 0644]
Toolkit/Schedule/Database/tables/departure_dates.sql [new file with mode: 0644]
Toolkit/Schedule/Database/tables/departure_times.sql [new file with mode: 0644]
Toolkit/Schedule/Database/tables/departures.sql [new file with mode: 0644]
Toolkit/Schedule/Database/tables/schedule.sql [new file with mode: 0644]
Toolkit/Schedule/DepartureCalendar.php [new file with mode: 0644]
Toolkit/Schedule/EditController.php [new file with mode: 0644]
Toolkit/Schedule/EditSchedule.php [new file with mode: 0644]
Toolkit/Schedule/IndexController.php [new file with mode: 0644]
Toolkit/Schedule/ListSchedules.php [new file with mode: 0644]
Toolkit/Schedule/application.ini [new file with mode: 0644]
Toolkit/Schedule/js/dateSearch.js [new file with mode: 0644]
Toolkit/Schedule/js/editSchedule.js [new file with mode: 0644]
Toolkit/Schedule/js/listSchedule.js [new file with mode: 0644]
Toolkit/Schedule/templates/departureRow.html [new file with mode: 0644]
Toolkit/Schedule/templates/departuresScheduleCalendar.html [new file with mode: 0644]
Toolkit/Schedule/templates/editSchedule.html [new file with mode: 0644]
Toolkit/Schedule/templates/listSchedules.html [new file with mode: 0644]
Toolkit/Schedule/templates/scheduleCalendar.html [new file with mode: 0644]
admin/nav.phtml
admin/schedules.php [new file with mode: 0644]
config/application.ini
setup.phtml

index f6e6521..ef279b7 100644 (file)
@@ -221,6 +221,11 @@ class Toolkit_Database
             $stmt->bindValue(':schema', 'videos', PDO::PARAM_STR);
             $stmt->execute();
         }
+        if (defined('SCHEDULES') && SCHEDULES) {
+            // define videos search path
+            $stmt->bindValue(':schema', 'boats', PDO::PARAM_STR);
+            $stmt->execute();
+        }
         if (defined('EVENT_MANAGEMENT') && EVENT_MANAGEMENT) {
             //    define event management search path
             $stmt->bindValue(':schema', 'reservations', PDO::PARAM_STR);
diff --git a/Toolkit/Schedule/Calendar.php b/Toolkit/Schedule/Calendar.php
new file mode 100644 (file)
index 0000000..b93d00e
--- /dev/null
@@ -0,0 +1,161 @@
+<?php
+
+class Toolkit_Schedule_Calendar
+{
+    /**
+     * buildCalendar
+     * 
+     * @param type $month
+     * @param type $year
+     * @param type $dates
+     * @return string 
+     */
+    public function buildCalendar($month, $year, $dates = array())
+    {
+        
+        $month = $month + 0;
+        $year  = $year + 0;
+        $mCal = new Calendar_Month_Weekdays(
+            $year,
+            $month,
+            0
+        );
+        $wrapper = new Calendar_Decorator_Wrapper(&$mCal);
+        $wrapper->build($dates);
+        $calYear      = $wrapper->thisYear();
+        $calMonthName = date(
+            'F', 
+            mktime(
+                0,
+                0,
+                0,
+                $mCal->thisMonth(),
+                $mCal->thisDay(),
+                $mCal->thisYear()
+            )
+        );
+        $html = '
+        <table class="calendarWrapper">
+          <tr>
+            <td valign="top">
+              <table class="cals">
+                <tr>
+                  <th colspan="7">'.$calMonthName.' '.$calYear.'</th>
+                </tr>
+                <tr>
+                  <td>S</td>
+                  <td>M</td>
+                  <td>T</td>
+                  <td>W</td>
+                  <td>T</td>
+                  <td>F</td>
+                  <td>S</td>
+                </tr>
+            ';
+        while ($day = $wrapper->fetch('Toolkit_Schedule_CalendarMonthDecorator')) {
+            if ($day->isFirst()) {
+                $html .= '<tr>
+                    ';
+            }
+            if ($day->isEmpty()) {
+                $html .= '<td>&nbsp;</td>';
+            } else {
+                $class = ($day->isSelected())
+                    ? ' '.$day->calendar->class
+                    : ' noDeparture';
+                $html .= '<td class="calDay'.$class.'" rel="';
+                $html .= $day->thisMonth() . '/' . $day->thisDay() . '/' . $day->thisYear();
+                $html .= '">'.$day->thisDay().'</td>';
+            }
+            
+            if ($day->isLast()) {
+                $html .= '</tr>
+                    ';
+            }
+        }
+        $html .= '
+            </table>
+          </td>
+        </tr>
+        </table>
+        ';
+        return $html;
+    }
+    
+    /**
+     * getDepartureColors
+     * 
+     * @param type $scheduleId
+     * @return type 
+     */
+    public function getDepartureColors($scheduleId)
+    {
+        $colors = array();
+        $scheduleId = (int)$scheduleId + 0;
+        if (!is_numeric($scheduleId)) {
+            throw new Exception('ScheduleId must be a digit');
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            SELECT id,color
+              FROM departures
+             WHERE schedule_id = :schedule_id";
+            $stmt = $dbh->prepare($sql);
+            $stmt->bindParam(
+                ':schedule_id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $stmt->execute();
+            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $colors[$row['id']] = $row['color'];
+            }
+        } catch(PDOException $e){
+            Toolkit_Common::handleError($e);
+        }
+        return $colors;
+    }
+    
+    /**
+     * getDepartureDates
+     * 
+     * @param type $scheduleId
+     * @return Calendar_Day 
+     */
+    public function getDepartureDates($scheduleId)
+    {
+        $dates = array();
+        if (!ctype_digit($scheduleId)) {
+            throw new Exception('ScheduleId must be a digit');
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            SELECT id,departure_id,departure_date
+              FROM departure_dates
+             WHERE schedule_id = :schedule_id";
+            $stmt = $dbh->prepare($sql);
+            $stmt->bindParam(
+                ':schedule_id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $stmt->execute();
+            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $timeStamp  = strtotime($row['departure_date']);
+                $date       = new Date($timeStamp);
+                $day        = new Calendar_Day(
+                    $date->getYear(),
+                    $date->getMonth(),
+                    $date->getDay()
+                );
+                $day->class = 'depart'.$row['departure_id'];
+                $dates[$row['id']] = $day;
+            }
+        } catch(PDOException $e){
+            Toolkit_Common::handleError($e);
+        }
+        return $dates;
+    }
+}
diff --git a/Toolkit/Schedule/CalendarMonthDecorator.php b/Toolkit/Schedule/CalendarMonthDecorator.php
new file mode 100644 (file)
index 0000000..bb66889
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+class Toolkit_Schedule_CalendarMonthDecorator
+    extends Calendar_Decorator
+{
+    public function Toolkit_Schedule_CalendarMonthDecorator(&$Calendar)
+    {
+        parent::Calendar_Decorator(&$Calendar);
+    }
+    
+    public function thisDay()
+    {
+        return parent::thisDay();
+    }
+}
diff --git a/Toolkit/Schedule/Database/application.sql b/Toolkit/Schedule/Database/application.sql
new file mode 100644 (file)
index 0000000..6c83eae
--- /dev/null
@@ -0,0 +1,8 @@
+CREATE SCHEMA boats;
+
+GRANT ALL ON SCHEMA boats TO nobody;
+
+\i ./tables/schedule.sql
+\i ./tables/departures.sql
+\i ./tables/departure_dates.sql
+\i ./tables/departure_times.sql
diff --git a/Toolkit/Schedule/Database/removeApplication.sql b/Toolkit/Schedule/Database/removeApplication.sql
new file mode 100644 (file)
index 0000000..a896da6
--- /dev/null
@@ -0,0 +1 @@
+DROP SCHEMA boats;
diff --git a/Toolkit/Schedule/Database/tables/departure_dates.sql b/Toolkit/Schedule/Database/tables/departure_dates.sql
new file mode 100644 (file)
index 0000000..c7a2302
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE boats.departure_dates (
+id SERIAL,
+departure_id INTEGER,
+schedule_id INTEGER,
+departure_date DATE,
+PRIMARY KEY (id)
+);
+
+GRANT ALL ON boats.departure_dates TO nobody;
+GRANT ALL ON boats.departure_dates_id_seq TO nobody;
\ No newline at end of file
diff --git a/Toolkit/Schedule/Database/tables/departure_times.sql b/Toolkit/Schedule/Database/tables/departure_times.sql
new file mode 100644 (file)
index 0000000..6a08139
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE boats.departure_times (
+id SERIAL,
+departure_id INTEGER,
+schedule_id INTEGER,
+dock INTEGER,
+departure_time TEXT,
+PRIMARY KEY (id)
+);
+
+GRANT ALL ON boats.departure_times TO nobody;
+GRANT ALL ON boats.departure_times_id_seq TO nobody;
\ No newline at end of file
diff --git a/Toolkit/Schedule/Database/tables/departures.sql b/Toolkit/Schedule/Database/tables/departures.sql
new file mode 100644 (file)
index 0000000..f7b296e
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE boats.departures (
+id SERIAL,
+schedule_id INTEGER,
+color TEXT,
+comments TEXT,
+PRIMARY KEY (id)
+);
+
+GRANT ALL ON boats.departures TO nobody;
+GRANT ALL ON boats.departures_id_seq TO nobody;
\ No newline at end of file
diff --git a/Toolkit/Schedule/Database/tables/schedule.sql b/Toolkit/Schedule/Database/tables/schedule.sql
new file mode 100644 (file)
index 0000000..ab4b169
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE boats.schedules (
+id SERIAL,
+name TEXT,
+active BOOLEAN DEFAULT false,
+PRIMARY KEY (id)
+);
+
+GRANT ALL ON boats.schedules TO nobody;
+GRANT ALL ON boats.schedules_id_seq TO nobody;
\ No newline at end of file
diff --git a/Toolkit/Schedule/DepartureCalendar.php b/Toolkit/Schedule/DepartureCalendar.php
new file mode 100644 (file)
index 0000000..61abfb7
--- /dev/null
@@ -0,0 +1,197 @@
+<?php
+
+class Toolkit_Schedule_DepartureCalendar
+{
+    public $config;
+    public $flexyOptions;
+    public $dbh;
+
+    public function getDatesForSchedule($scheduleId)
+    {
+        try {
+            $this->dbh = Toolkit_Database::getInstance();
+            $sql = "
+            SELECT *
+              FROM departure_dates
+             WHERE schedule_id = :schedule_id
+            ORDER BY departure_date";
+            $stmt = $this->dbh->prepare($sql);
+            $stmt->bindParam(
+                ':schedule_id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $stmt->execute();
+            $scheduleDates = $stmt->fetchAll(PDO::FETCH_ASSOC);
+            if (!$scheduleDates) {
+                return false;
+            } else {
+                $dates = array();
+                foreach ($scheduleDates as $row) {
+                    $dates[] = $row['departure_date'];
+                }
+                return $dates;
+            }
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+
+    public function getDeparturesForDate()
+    {
+        $date = filter_input(
+            INPUT_POST,
+            'departDate',
+            FILTER_SANITIZE_STRING
+        );
+        if ($date) {
+            $isDate = preg_match('/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/', $date);
+        } else {
+            $isDate = false;
+        }
+        $dock = filter_input(
+            INPUT_POST,
+            'dock',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        if ($dock && $isDate) {
+            try {
+                // get the comments for the date
+                $sql = "
+                SELECT comments
+                  FROM departures
+                 WHERE id IN (
+                       SELECT departure_id
+                         FROM departure_dates
+                        WHERE departure_date = :date)";
+                $stmt1 = $this->dbh->prepare($sql);
+                $stmt1->bindParam(
+                    ':date',
+                    $date,
+                    PDO::PARAM_STR
+                );
+                $stmt1->execute();
+                $sql = "
+                SELECT *
+                  FROM departure_times
+                 WHERE departure_id IN (
+                       SELECT departure_id
+                         FROM departure_dates
+                        WHERE departure_date = :date)
+                   AND dock = :dock";
+                $stmt = $this->dbh->prepare($sql);
+                $stmt->bindParam(
+                    ':dock',
+                    $dock,
+                    PDO::PARAM_INT
+                );
+                $stmt->bindParam(
+                    ':date',
+                    $date,
+                    PDO::PARAM_STR
+                );
+                $stmt->execute();
+                return array(
+                    'comments' => nl2br($stmt1->fetchColumn()),
+                    'times'    => $stmt->fetchAll(PDO::FETCH_ASSOC),
+                    'date'     => $date,
+                    'dock'     => (
+                        ($dock == 1)
+                        ? 'Charlevoix'
+                        : 'Beaver Island'
+                    )
+                );
+            } catch(PDOException $e) {
+                Toolkit_Common::handleError($e);
+            }
+        }
+    }
+
+    public function hasSchedule()
+    {
+        try {
+            $this->dbh = Toolkit_Database::getInstance();
+            $sql = "
+            SELECT *
+              FROM schedules
+             WHERE active = true";
+            $scheduleData = $this->dbh->query($sql)->fetch(PDO::FETCH_ASSOC);
+            if (!$scheduleData) {
+                return false;
+            } else {
+                return $scheduleData;
+            }
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+
+    /**
+     * toHtml
+     *
+     * return the html for the schedules
+     *
+     * @return type
+     */
+    public function toHtml()
+    {
+        // load ZendConfig
+        $this->config = new Zend_Config_Ini(
+            BASE . 'Toolkit/Schedule/application.ini',
+            strtolower($_ENV['GLM_HOST_ID'])
+        );
+        // setup flexy options from global then override with config values
+        $this->flexyOptions = $GLOBALS['flexyOptions'];
+        $this->flexyOptions['templateDir']
+            = $this->config->flexy->options->templateDir;
+        $this->flexyOptions['compileDir']
+            = $this->config->flexy->options->compileDir;
+        $cals = new Toolkit_Schedule_Calendar();
+        // get the active schedule if no active schedule is found then return
+        // nothing
+        $scheduleData = $this->hasSchedule();
+        if (!$scheduleData) {
+            return false;
+        }
+        $scheduleId   = (string)$scheduleData['id'];
+        $scheduleName = $scheduleData['name'];
+        $year         = $scheduleData['schedule_year'];
+
+        $colors
+            = ($scheduleId)
+            ? $cals->getDepartureColors($scheduleId)
+            : null;
+        $style = '';
+        if ($colors) {
+            foreach ($colors as $departId => $color) {
+                $style .= ".depart{$departId} {background-color:{$color};}\n";
+            }
+        }
+        $selected = $cals->getDepartureDates($scheduleId);
+        $year
+            = ($year)
+            ? $year
+            : date('Y');
+        $page     = new stdClass();
+        $startingMonth = $this->config->months->start;
+        $endingMonth   = $this->config->months->end;
+        for ($i = $startingMonth; $i <= $endingMonth; ++$i) {
+            $page->calendarsHtml .= $cals->buildCalendar($i, $year, $selected);
+        }
+        $tpl                = new HTML_Template_Flexy($this->flexyOptions);
+        $page->style        = $style;
+        $page->appBase      = GLM_APP_BASE_URL;
+        $page->baseUrl      = BASE_URL;
+        $page->scheduleId   = $scheduleId;
+        $page->scheduleName = $scheduleName;
+        $page->departByDate = $this->getDeparturesForDate();
+        $ScheduleEdit = new Toolkit_Schedule_EditSchedule();
+        $page->departures = $ScheduleEdit->getDeparturesForSchedules(
+            $this,
+            $scheduleId
+        );
+        $tpl->compile('departuresScheduleCalendar.html');
+        $calendars = $tpl->bufferedOutputObject($page);
+        return $calendars;
+    }
+}
diff --git a/Toolkit/Schedule/EditController.php b/Toolkit/Schedule/EditController.php
new file mode 100644 (file)
index 0000000..b9337ec
--- /dev/null
@@ -0,0 +1,703 @@
+<?php
+
+class Toolkit_Schedule_EditController
+    extends Toolkit_BaseControllerAbstract
+       implements Toolkit_IController
+{
+    /**
+     * Adds a new departure using ajax
+     *
+     * @return type string json array
+     */
+    public function addDepartureSetAction()
+    {
+        $scheduleId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        if (!$scheduleId) {
+            return '';
+            exit;
+        }
+        $schedule = new Toolkit_Schedule_EditSchedule();
+        $data = $schedule->addDepartureSet(
+            $this->registry,
+            $scheduleId
+        );
+        echo json_encode($data);
+        exit;
+    }
+
+    /**
+     * addScheduleAction
+     * 
+     * adds a empty schedule and echos id
+     * this is used in ajax call so exit do not return just echo and exit
+     */
+    public function addScheduleAction()
+    {
+        $schedule   = new Toolkit_Schedule_EditSchedule();
+        $scheduleId = $schedule->addSchedule($this->registry);
+        echo $scheduleId;
+        exit;
+    }
+
+    /**
+     * getCalendarYearAction
+     * 
+     * this is used in a ajax call so don't return just echo it and exit
+     * gets the set year calendars as html for output
+     */
+    public function getCalendarYearAction()
+    {
+        $cals       = new Toolkit_Schedule_Calendar();
+        $scheduleId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $departureId = filter_input(
+            INPUT_GET,
+            'departId',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $year = filter_input(
+            INPUT_GET,
+            'year',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $colors
+            = ($scheduleId)
+            ? $cals->getDepartureColors($scheduleId)
+            : null;
+        $style = '';
+        if ($colors) {
+            foreach ($colors as $departId => $color) {
+                $style .= ".depart{$departId} {background-color:{$color};}\n";
+            }
+        }
+        $selected = $cals->getDepartureDates($scheduleId);
+        $year
+            = ($year)
+            ? $year
+            : date('Y');
+        $page     = new stdClass();
+        $startingMonth = $this->registry->config->months->start;
+        $endingMonth   = $this->registry->config->months->end;
+        for ($i = $startingMonth; $i <= $endingMonth; ++$i) {
+            $page->calendarsHtml .= $cals->buildCalendar($i, $year, $selected);
+        }
+        $tpl                = new HTML_Template_Flexy(
+            $this->registry->flexyOptions
+        );
+        $page->prevYear     = $year - 1;
+        $page->nextYear     = $year + 1;
+        $page->style        = $style;
+        $page->appBase      = GLM_APP_BASE_URL;
+        $page->baseUrl      = BASE_URL;
+        $page->scheduleId   = $scheduleId;
+        $page->departureId  = $departureId;
+        $tpl->compile('scheduleCalendar.html');
+        $tpl->outputObject($page);
+        exit;
+    }
+
+    /**
+     * getTimeAction
+     *
+     * grab the data for a given departure_times record
+     * based on the id in GET
+     */
+    public function getTimeAction()
+    {
+        $departureTimeId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        if (!$departureTimeId) {
+            echo 0;
+            exit;
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            SELECT *
+              FROM departure_times
+             WHERE id = :id";
+            $stmt = $dbh->prepare($sql);
+            $stmt->bindParam(
+                ':id',
+                $departureTimeId,
+                PDO::PARAM_INT
+            );
+            $stmt->execute();
+            $formData = $stmt->fetch(PDO::FETCH_ASSOC);
+            if ($formData) {
+                echo json_encode($formData);
+            } else {
+                echo 0;
+            }
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+
+    /**
+     * indexAction
+     *
+     * default action if no action is set in GET['ac']
+     *
+     * @return type string HTML
+     */
+    public function indexAction()
+    {
+        $schedule = new Toolkit_Schedule_EditSchedule();
+        $html = $schedule->toHtml($this->registry);
+        return $html;
+    }
+    
+    /**
+     * removeDepartureSetAction
+     * 
+     * removes the departures record and then removes all times and dates
+     */
+    public function removeDepartureSetAction()
+    {
+        $dbh = Toolkit_Database::getInstance();
+        $departureId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        if (!$departureId) {
+            echo 0;
+            exit;
+        }
+        $schedules = new Toolkit_Schedule_EditSchedule();
+        $deleted = $schedules->removeDeparturesById($dbh, $departureId);
+        if ($deleted) {
+            $schedules->removeDepartureDatesById($dbh, $departureId);
+            $schedules->removeDepartureTimesById($dbh, $departureId);
+        }
+        echo 1;
+        exit;
+    }
+
+    /**
+     * removeTimeAction
+     *
+     * remove the departure_times record based on the id in GET
+     */
+    public function removeTimeAction()
+    {
+        $departureTimeId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        if (!$departureTimeId) {
+            echo 0;
+            exit;
+        }
+
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            if ($departureTimeId) {
+                $sql = "
+                DELETE
+                  FROM departure_times
+                 WHERE id = :id";
+                $delete = $dbh->prepare($sql);
+                $delete->bindParam(
+                    ':id',
+                    $departureTimeId,
+                    PDO::PARAM_INT
+                );
+                $delete->execute();
+            }
+            echo 1;
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+
+    /**
+     * saveTimeAction
+     *
+     * save the date from the edit form for the departure_times record
+     */
+    public function saveTimeAction()
+    {
+        $departureTimeId = filter_input(
+            INPUT_POST,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $departureTime = filter_input(
+            INPUT_POST,
+            'depart_time',
+            FILTER_SANITIZE_STRING
+        );
+        $dock = filter_input(
+            INPUT_POST,
+            'dock',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $departureId = filter_input(
+            INPUT_POST,
+            'departure_id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        if (!$departureTime) {
+            echo 0;
+            exit;
+        }
+
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $departureTime = strtoupper($departureTime);
+            if ($departureTimeId) {
+                $sql = "
+                UPDATE departure_times
+                   SET departure_time = :departure_time
+                 WHERE id = :id";
+                $update = $dbh->prepare($sql);
+                $update->bindParam(
+                    ':id',
+                    $departureTimeId,
+                    PDO::PARAM_INT
+                );
+                $update->bindParam(
+                    ':departure_time',
+                    $departureTime,
+                    PDO::PARAM_STR
+                );
+                $update->execute();
+            } else {
+                if ($departureId && $dock) {
+                    $sql = "
+                    SELECT schedule_id
+                      FROM departures
+                     WHERE id = :id";
+                    $get = $dbh->prepare($sql);
+                    $get->bindParam(':id', $departureId, PDO::PARAM_INT);
+                    $get->execute();
+                    $scheduleId = $get->fetchColumn();
+                    if (!$scheduleId) {
+                        echo 0;
+                    }
+                    $sql = "
+                    INSERT INTO departure_times
+                    (departure_id,dock,departure_time,schedule_id)
+                    VALUES
+                    (:departure_id,:dock,:departure_time,:schedule_id)
+                    RETURNING id";
+                    $insert = $dbh->prepare($sql);
+                    $insert->bindParam(
+                        ':departure_time',
+                        $departureTime,
+                        PDO::PARAM_STR
+                    );
+                    $insert->bindParam(
+                        ':departure_id',
+                        $departureId,
+                        PDO::PARAM_INT
+                    );
+                    $insert->bindParam(
+                        ':dock',
+                        $dock,
+                        PDO::PARAM_INT
+                    );
+                    $insert->bindParam(
+                        ':schedule_id',
+                        $scheduleId,
+                        PDO::PARAM_INT
+                    );
+                    $insert->execute();
+                    $departureTimeId = $insert->fetchColumn();
+                }
+            }
+            echo json_encode(
+                array(
+                    'id'           => $departureTimeId,
+                    'departure_id' => $departureId,
+                    'time'         => $departureTime,
+                    'dock'         => $dock
+                )
+            );
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+
+    /**
+     * updateActiveAction
+     *
+     * update which schedule is active
+     * turn off all others
+     */
+    public function updateActiveAction()
+    {
+        $scheduleId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        if ($scheduleId === false) {
+            echo 0;
+            exit;
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            UPDATE schedules
+               SET active = true
+             WHERE id = :id";
+            $update = $dbh->prepare($sql);
+            $update->bindParam(
+                ':id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $update->execute();
+            $sql = "
+            UPDATE schedules
+               SET active = false
+             WHERE id != :id";
+            $updateOthers = $dbh->prepare($sql);
+            $updateOthers->bindParam(
+                ':id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $updateOthers->execute();
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+
+    /**
+     * updateColorAction
+     *
+     * update the color for the departule record
+     */
+    public function updateColorAction()
+    {
+        $departureId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $color = filter_input(
+            INPUT_GET,
+            'color',
+            FILTER_SANITIZE_STRING
+        );
+        if (!$departureId) {
+            echo 0;
+            exit;
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            UPDATE departures
+               SET color = :color
+             WHERE id = :id";
+            $update = $dbh->prepare($sql);
+            $update->bindParam(
+                ':id',
+                $departureId,
+                PDO::PARAM_INT
+            );
+            $update->bindParam(
+                ':color',
+                $color,
+                PDO::PARAM_STR
+            );
+            $update->execute();
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+
+    /**
+     * updateCommentAction
+     *
+     * update the comment for the departures record from the edit form
+     */
+    public function updateCommentAction()
+    {
+        $departureId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $comments = filter_input(
+            INPUT_GET,
+            'comments',
+            FILTER_SANITIZE_STRING
+        );
+        if (!$departureId) {
+            echo 0;
+            exit;
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            UPDATE departures
+               SET comments = :comments
+             WHERE id = :id";
+            $update = $dbh->prepare($sql);
+            $update->bindParam(
+                ':id',
+                $departureId,
+                PDO::PARAM_INT
+            );
+            $update->bindParam(
+                ':comments',
+                $comments,
+                PDO::PARAM_STR
+            );
+            $update->execute();
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+
+    /**
+     * updateDatesAction
+     *
+     * when you update a departure_dates record you'll have to check to see if
+     * this schedule_id has any other departure_dates with that date and update
+     * that record to the new departure_id for.
+     * else
+     * you'll insert a new date for that departure
+     * one condition though if the date for it exists as the departure_id you're
+     * setting up then delete that departure_dates record
+     */
+    public function updateDatesAction()
+    {
+        $scheduleId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $depatureId = filter_input(
+            INPUT_GET,
+            'departId',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $date = filter_input(
+            INPUT_GET,
+            'date',
+            FILTER_SANITIZE_STRING
+        );
+        if (!$scheduleId || !$depatureId || !$date) {
+//            var_dump($scheduleId);
+//            var_dump($depatureId);
+//            var_dump($date);
+//            echo 'hi no vars';
+            echo 0;
+            exit;
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            SELECT departure_id
+              FROM departure_dates
+             WHERE schedule_id = :schedule_id
+               AND departure_date = :departure_date";
+            $stmt = $dbh->prepare($sql);
+            $stmt->bindParam(
+                ':schedule_id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $stmt->bindParam(
+                ':departure_date',
+                $date,
+                PDO::PARAM_INT
+            );
+            $stmt->execute();
+            $hasDate = $stmt->fetchColumn();
+            if ($hasDate == $depatureId) {
+                // then delete the record
+                $sql = "
+                DELETE
+                  FROM departure_dates
+                 WHERE schedule_id = :schedule_id
+                   AND departure_date = :departure_date";
+                $stmt = $dbh->prepare($sql);
+                $stmt->bindParam(
+                    ':schedule_id',
+                    $scheduleId,
+                    PDO::PARAM_INT
+                );
+                $stmt->bindParam(
+                    ':departure_date',
+                    $date,
+                    PDO::PARAM_INT
+                );
+                $stmt->execute();
+                echo '';
+                exit;
+            } else if ($hasDate) {
+                // need to update the date to have the new departure_id
+                $sql = "
+                UPDATE departure_dates
+                   SET departure_id = :departure_id
+                 WHERE schedule_id = :schedule_id
+                   AND departure_date = :departure_date";
+                $stmt = $dbh->prepare($sql);
+                $stmt->bindParam(
+                    ':schedule_id',
+                    $scheduleId,
+                    PDO::PARAM_INT
+                );
+                $stmt->bindParam(
+                    ':departure_date',
+                    $date,
+                    PDO::PARAM_INT
+                );
+                $stmt->bindParam(
+                    ':departure_id',
+                    $depatureId,
+                    PDO::PARAM_INT
+                );
+                $stmt->execute();
+                echo 'depart'.$depatureId;
+                exit;
+            } else {
+                // insert a new record for this one
+                $sql = "
+                INSERT INTO departure_dates
+                (departure_id,schedule_id,departure_date)
+                VALUES
+                (:departure_id,:schedule_id,:departure_date)
+                RETURNING id";
+                $stmt = $dbh->prepare($sql);
+                $stmt->bindParam(
+                    ':schedule_id',
+                    $scheduleId,
+                    PDO::PARAM_INT
+                );
+                $stmt->bindParam(
+                    ':departure_date',
+                    $date,
+                    PDO::PARAM_INT
+                );
+                $stmt->bindParam(
+                    ':departure_id',
+                    $depatureId,
+                    PDO::PARAM_INT
+                );
+                $stmt->execute();
+                echo 'depart'.$depatureId;
+                exit;
+            }
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        echo 0;
+        exit;
+    }
+
+    /**
+     * updateNameAction
+     *
+     * update the name for the schedules record from the edit form
+     */
+    public function updateNameAction()
+    {
+        $scheduleId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $name = filter_input(
+            INPUT_GET,
+            'name',
+            FILTER_SANITIZE_STRING
+        );
+        if (!$scheduleId) {
+            echo 0;
+            exit;
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            UPDATE schedules
+               SET name = :name
+             WHERE id = :id";
+            $update = $dbh->prepare($sql);
+            $update->bindParam(
+                ':id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $update->bindParam(
+                ':name',
+                $name,
+                PDO::PARAM_STR
+            );
+            $update->execute();
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+
+    /**
+     * updateScheduleYearAction
+     * 
+     * this is ajax call so don't return just echo and exit
+     * update the year field for the schedule record
+     */
+    public function updateScheduleYearAction()
+    {
+        $scheduleId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $year = filter_input(
+            INPUT_GET,
+            'year',
+            FILTER_SANITIZE_STRING
+        );
+        if (!$scheduleId) {
+            echo 0;
+            exit;
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            UPDATE schedules
+               SET schedule_year = :year
+             WHERE id = :id";
+            $update = $dbh->prepare($sql);
+            $update->bindParam(
+                ':id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $update->bindParam(
+                ':year',
+                $year,
+                PDO::PARAM_STR
+            );
+            $update->execute();
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+}
diff --git a/Toolkit/Schedule/EditSchedule.php b/Toolkit/Schedule/EditSchedule.php
new file mode 100644 (file)
index 0000000..24a8e08
--- /dev/null
@@ -0,0 +1,424 @@
+<?php
+
+class Toolkit_Schedule_EditSchedule
+{
+    protected $colors   = array();
+    protected $timesChx = array();
+    protected $timesBvi = array();
+    protected $dates    = array();
+    
+    /**
+     * For the Ajax call to add a departure set create the html and exit
+     */
+    public function addDepartureSet($registry, $scheduleId)
+    {
+        $dbh = $registry->dbh;
+        // create the record first then fetch it and output the html
+        // exit after this (it's used in an ajax request)
+        $tpl = new HTML_Template_Flexy($registry->flexyOptions);
+        $tpl->compile('departureRow.html');
+        $page = new stdClass();
+        $page->appBase = GLM_APP_BASE_URL;
+        try {
+            $sql = "
+            INSERT INTO departures
+            (schedule_id)
+            VALUES
+            (:schedule_id)
+            RETURNING *";
+            $insert = $dbh->prepare($sql);
+            $insert->bindParam(
+                ':schedule_id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $insert->execute();
+            $page->departures = $insert->fetchAll();
+        } catch (PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        return array(
+            'id' => $page->departures[0]['id'],
+            'html' => $tpl->bufferedOutputObject($page)
+        );
+    }
+    
+    /**
+     * addSchedule
+     * 
+     * Creates a new empty schedule record
+     * return the new id
+     *  
+     * @param type $registry
+     * @return type 
+     */
+    public function addSchedule($registry)
+    {
+        $dbh = $registry->dbh;
+        try {
+            $year = date('Y');
+            $sql = "
+            INSERT INTO schedules
+            (name,schedule_year)
+            VALUES
+            ('default name',{$year})
+            RETURNING id";
+            $insert = $dbh->query($sql);
+            return $insert->fetchColumn();
+        } catch (PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+    
+    /**
+     * add times to the timesBvi array
+     * 
+     * @param type $times array of times
+     */
+    protected function addTimesBvi($times)
+    {
+        if (is_array($times) && !empty($times)) {
+            foreach ($times as $time) {
+                $this->timesBvi[] = $time['id'];
+            }
+        }
+    }
+    
+    /**
+     * add times to the timesChx array
+     * 
+     * @param type $times array of times
+     */
+    protected function addTimesChx($times)
+    {
+        if (is_array($times) && !empty($times)) {
+            foreach ($times as $time) {
+                $this->timesChx[] = $time['id'];
+            }
+        }
+    }
+    
+    /**
+     * get the departure times for dock 1 for a departureId
+     *
+     * @param type $registry    Registry class obj
+     * @param type $departureId id of the departure record
+     * @return type             data array
+     */
+    protected function getDepartTimesChx($registry, $departureId)
+    {
+        try {
+            $sql = "
+              SELECT *
+                FROM departure_times
+               WHERE departure_id = :departure_id
+                 AND dock = 1
+            ORDER BY id";
+            $stmt = $registry->dbh->prepare($sql);
+            $stmt->bindParam(
+                ':departure_id',
+                $departureId,
+                PDO::PARAM_INT
+            );
+            $stmt->execute();
+            return $stmt->fetchAll(PDO::FETCH_ASSOC);
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+    
+    /**
+     * get the departure dates for a departureId
+     *
+     * @param type $registry    Registry class obj
+     * @param type $departureId id of the departure record
+     * @return type             data array
+     */
+    protected function getDepartDates($registry, $departureId)
+    {
+        try {
+            $sql = "
+              SELECT *
+                FROM departure_dates
+               WHERE departure_id = :departure_id
+            ORDER BY id";
+            $stmt = $registry->dbh->prepare($sql);
+            $stmt->bindParam(
+                ':departure_id',
+                $departureId,
+                PDO::PARAM_INT
+            );
+            $stmt->execute();
+            return $stmt->fetchAll(PDO::FETCH_ASSOC);
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+    
+    /**
+     * get the departure times for dock 2 for a departureId
+     *
+     * @param type $registry    Registry class obj
+     * @param type $departureId id of the departure record
+     * @return type             data array
+     */
+    protected function getDepartTimesBeaver($registry, $departureId)
+    {
+        try {
+            $sql = "
+              SELECT *
+                FROM departure_times
+               WHERE departure_id = :departure_id
+                 AND dock = 2
+            ORDER BY id";
+            $stmt = $registry->dbh->prepare($sql);
+            $stmt->bindParam(
+                ':departure_id',
+                $departureId,
+                PDO::PARAM_INT
+            );
+            $stmt->execute();
+            return $stmt->fetchAll(PDO::FETCH_ASSOC);
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+    
+    /**
+     * get all departures for a schedule
+     * 
+     * @param type $registry   Registry Obj
+     * @param type $scheduleId schedule id
+     * @return type            array of data
+     */
+    protected function getDepartures($registry, $scheduleId)
+    {
+        try {
+            $sql = "
+              SELECT *
+                FROM departures
+               WHERE schedule_id = :schedule_id
+            ORDER BY id";
+            $stmt = $registry->dbh->prepare($sql);
+            $stmt->bindParam(
+                ':schedule_id',
+                $scheduleId,
+                PDO::PARAM_INT
+            );
+            $stmt->execute();
+            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+                $this->colors[] = $row['id'];
+                $departures[$row['id']] = $row;
+                $chxTimes = $this->getDepartTimesChx(
+                    $registry,
+                    $row['id']
+                );
+                $departures[$row['id']]['cTimes'] = $chxTimes;
+                $this->addTimesChx($chxTimes);
+                $bviTimes = $this->getDepartTimesBeaver(
+                    $registry,
+                    $row['id']
+                );
+                $departures[$row['id']]['bTimes'] = $bviTimes;
+                $this->addTimesBvi($bviTimes);
+                $dates = $this->getDepartDates($registry, $row['id']);
+                if ($dates) {
+                    $departDates = array();
+                    foreach ($dates as $date) {
+                        $departDates[] = $date['departure_time'];
+                    }
+                    $departures[$row['id']]['dates'] = implode(',', $departDates);
+                }
+            }
+            return $departures;
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+    
+    public function getDeparturesForSchedules($registry, $scheduleId)
+    {
+        return $this->getDepartures($registry, $scheduleId);
+    }
+    
+    /**
+     * Get the schedule name from and scheduleId
+     * 
+     * @param PDO $dbh         PDO obj
+     * @param type $scheduleId id for schedule record
+     * @return type            string name of schedule
+     */
+    protected function getSheduleData(PDO $dbh, $scheduleId)
+    {
+        try {
+            $sql = "
+            SELECT *
+              FROM schedules
+             WHERE id = :id";
+            $stmt = $dbh->prepare($sql);
+            $stmt->bindParam(':id', $scheduleId, PDO::PARAM_INT);
+            $stmt->execute();
+            return $stmt->fetch(PDO::FETCH_ASSOC);
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+    
+    /**
+     * removeDeparturesById
+     * 
+     * Removes the departures record by id
+     * 
+     * @param PDO $dbh          PDO object
+     * @param type $departureId id to delete
+     * @return type 
+     */
+    public function removeDeparturesById(PDO $dbh, $departureId)
+    {
+        if (!ctype_digit($departureId)) {
+            throw new Exception('DepartureId need to be a Integer');
+        }
+        try {
+            $sql = "
+            DELETE
+              FROM departures
+             WHERE id = :id";
+            $delete = $dbh->prepare($sql);
+            $delete->bindParam(
+                ':id',
+                $departureId,
+                PDO::PARAM_INT
+            );
+            $delete->execute();
+            return true;
+        } catch (PDOException $e) {
+            Toolkit_Common::handleError($e);
+            return false;
+        }
+    }
+    
+    /**
+     * removeDepartureDatesById
+     * 
+     * Removes all the departure dates record by id
+     * 
+     * @param PDO $dbh          PDO object
+     * @param type $departureId id to delete
+     * @return type 
+     */
+    public function removeDepartureDatesById(PDO $dbh, $departureId)
+    {
+        if (!ctype_digit($departureId)) {
+            throw new Exception('DepartureId need to be a Integer');
+        }
+        try {
+            $sql = "
+            DELETE
+              FROM departure_dates
+             WHERE departure_id = :id";
+            $delete = $dbh->prepare($sql);
+            $delete->bindParam(
+                ':id',
+                $departureId,
+                PDO::PARAM_INT
+            );
+            $delete->execute();
+            return true;
+        } catch (PDOException $e) {
+            Toolkit_Common::handleError($e);
+            return false;
+        }
+    }
+    
+    /**
+     * removeDepartureTimesById
+     * 
+     * Removes all the departure times record by id
+     * 
+     * @param PDO $dbh          PDO object
+     * @param type $departureId id to delete
+     * @return type 
+     */
+    public function removeDepartureTimesById(PDO $dbh, $departureId)
+    {
+        if (!ctype_digit($departureId)) {
+            throw new Exception('DepartureId need to be a Integer');
+        }
+        try {
+            $sql = "
+            DELETE
+              FROM departure_times
+             WHERE departure_id = :id";
+            $delete = $dbh->prepare($sql);
+            $delete->bindParam(
+                ':id',
+                $departureId,
+                PDO::PARAM_INT
+            );
+            $delete->execute();
+            return true;
+        } catch (PDOException $e) {
+            Toolkit_Common::handleError($e);
+            return false;
+        }
+    }
+    
+    /**
+     * Return the html for the edit form
+     * 
+     * @param type $registry Registry obj
+     * @return type          string HTML
+     */
+    public function toHtml($registry)
+    {
+        $GLOBALS['styleSheets'][]
+            = GLM_APP_BASE_URL . 
+            'libjs/jqueryui/1.8.13/development-bundle/themes/cupertino/jquery.ui.all.css';
+        $GLOBALS['bottomScripts'][]
+            = GLM_APP_BASE_URL .
+            'libjs/jqueryui/1.8.13/js/jquery-ui-1.8.13.custom.min.js';
+        // css and js for "Really Simple Color Picker"
+        $GLOBALS['styleSheets'][]
+            = BASE_URL . 'css/colorPicker.css';
+        $GLOBALS['bottomScripts'][]
+            = BASE_URL . 'libjs/jquery.colorPicker.js';
+        
+        // javascript for the edit schedule page
+        $GLOBALS['bottomScripts'][]
+            = BASE_URL . 'Toolkit/Schedule/js/editSchedule.js';
+        $scheduleId = filter_input(
+            INPUT_GET,
+            'id',
+            FILTER_SANITIZE_NUMBER_INT
+        );
+        $tpl = new HTML_Template_Flexy($registry->flexyOptions);
+        $tpl->compile('editSchedule.html');
+        $page = new stdClass();
+        $page->appBase = GLM_APP_BASE_URL;
+        $page->baseUrl = BASE_URL;
+        $page->scheduleId = $scheduleId;
+        if ($scheduleId) {
+            $page->departures = $this->getDepartures($registry, $scheduleId);
+        }
+        $page->colors       = $this->colors;
+        $page->timesChx     = $this->timesChx;
+        $page->timesBvi     = $this->timesBvi;
+        $scheduleData       = $this->getSheduleData($registry->dbh, $scheduleId);
+        $page->name         = $scheduleData['name'];
+        $page->year         = $scheduleData['schedule_year'];
+        $page->backUrl      = BASE_URL . 'admin/schedules.php';
+        $page->monthsHeight = (int)$registry->config->months->height;
+        $page->monthsWidth  = (int)$registry->config->months->width;
+        $elements           = $tpl->getElements();
+        $startingYear       = 2011;
+        $endingYear         = $startingYear + 5;
+        $years              = array();
+        for ($i = $startingYear; $i <= $endingYear; ++$i) {
+            $years[$i] = $i;
+        }
+        $elements['schedule_year']->setOptions($years);
+        $elements['schedule_year']->setValue($scheduleData['schedule_year']);
+        $html .= $tpl->bufferedOutputObject($page, $elements);
+        return $html;
+    }
+}
diff --git a/Toolkit/Schedule/IndexController.php b/Toolkit/Schedule/IndexController.php
new file mode 100644 (file)
index 0000000..2d6768c
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+class Toolkit_Schedule_IndexController
+    extends Toolkit_BaseControllerAbstract
+       implements Toolkit_IController
+{
+    /**
+     * indexAction
+     * 
+     * default action if none found
+     * 
+     * @return type string HTML
+     */
+    public function indexAction()
+    {
+        $schedues = new Toolkit_Schedule_ListSchedules();
+        $html = $schedues->toHtml($this->registry);
+        return $html;
+    }
+    
+    /**
+     * editAction
+     * 
+     * edit action if set as ac=edit
+     * 
+     * @return type 
+     */
+    public function editAction()
+    {
+        $schedule = new Toolkit_Schedule_EditSchedule();
+        $html = $schedule->toHtml($this->registry);
+        return $html;
+    }
+}
diff --git a/Toolkit/Schedule/ListSchedules.php b/Toolkit/Schedule/ListSchedules.php
new file mode 100644 (file)
index 0000000..f9bd659
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+class Toolkit_Schedule_ListSchedules
+{
+    /**
+     * toHtml
+     * 
+     * output the html for listing schedules
+     * 
+     * @param type $registry
+     * @return type 
+     */
+    public function toHtml($registry)
+    {
+        $GLOBALS['bottomScripts'][]
+            = BASE_URL . 'Toolkit/Schedule/js/listSchedule.js';
+        $tpl = new HTML_Template_Flexy($registry->flexyOptions);
+        $page = new stdClass();
+        $page->baseUrl = BASE_URL;
+        $page->editLinkUrlBase
+            = BASE_URL . 'admin/schedules.php?rt=Edit&id=';
+        $whichActiveSql = "
+        SELECT id
+          FROM schedules
+         WHERE active = true";
+        $page->active = $registry->dbh
+            ->query($whichActiveSql)
+            ->fetchColumn();
+        $sql = "
+          SELECT *
+            FROM schedules
+        ORDER BY id";
+        $page->schedules = $registry->dbh
+            ->query($sql)
+            ->fetchAll(PDO::FETCH_ASSOC);
+        $tpl->compile('listSchedules.html');
+        return $tpl->bufferedOutputObject($page);
+    }
+}
diff --git a/Toolkit/Schedule/application.ini b/Toolkit/Schedule/application.ini
new file mode 100644 (file)
index 0000000..21966c0
--- /dev/null
@@ -0,0 +1,34 @@
+; Production server configuration data
+[production]
+; name of the application
+applicationName = "Boat Schedule"
+
+; flexy options for all the templates used in this application
+; based on the GLOBALS['flexyOptions']
+flexy.options.templateDir = BASE "Toolkit/Schedule/templates/"
+flexy.options.compileDir  = BASE "Toolkit/Schedule/templates/compiled/"
+
+; the starting month to use in the multiple date picker
+months.start = 4
+; the ending month to use in the multiple date picker
+months.end = 12
+; controls the width of the dialog box for the multiple date picker
+months.width = 500
+; controls the height of the dialog box for the multiple date picker
+months.height = 580
+
+; development server configuration data inherits from production and
+; overrides values as necessary
+[development : production]
+
+; chuck's server configuration data inherits from development
+; and overrides values as necessary
+[chuck : development]
+
+; john's server configuration data inherits from development
+; and overrides values as necessary
+[john : development]
+
+; steve's server configuration data inherits from development
+; and overrides values as necessary
+[steve : development]
diff --git a/Toolkit/Schedule/js/dateSearch.js b/Toolkit/Schedule/js/dateSearch.js
new file mode 100644 (file)
index 0000000..a30b967
--- /dev/null
@@ -0,0 +1,29 @@
+
+$(document).ready(function(){
+//    $("#dateSearch").datepicker({ 
+//        altField: '#departDate' 
+//    });
+    $("#departDate").datepicker({
+        showOn: "button",
+        buttonImage: "http://app.gaslightmedia.com/assets/icons/calendar.png",
+        buttonImageOnly: true,
+        minDate: new Date(minDateYear, minDateMonth -1, minDateDay),
+        maxDate: new Date(maxDateYear, maxDateMonth -1, maxDateDay),
+        beforeShowDay: function(date){
+            var dateString = new String;
+            if (date.getMonth() + 1 < 10) {
+                dateString += '0';
+            }
+            dateString += date.getMonth() + 1;
+            dateString += '/';
+            if (date.getDate() < 10) {
+                dateString += '0';
+            }
+            dateString += date.getDate();
+            dateString += '/';
+            dateString += date.getFullYear();
+
+            return [$.inArray(dateString, scheduleDates) > -1, ""];
+        }
+    });
+});
\ No newline at end of file
diff --git a/Toolkit/Schedule/js/editSchedule.js b/Toolkit/Schedule/js/editSchedule.js
new file mode 100644 (file)
index 0000000..2ff108e
--- /dev/null
@@ -0,0 +1,346 @@
+var EditSchedule =
+{
+    baseUrl: null,
+    init: function()
+    {
+        // setup a class to add to all input field to disable the enter submit
+        $('.noEnterSubmit').keypress(function(e){
+            if ( e.which == 13 ) e.preventDefault();
+        });
+
+        // setup on change event for schedule_year
+        // we want to update the schedule with new name if updated
+        $('#schedule_year').change(function(){
+            var newYear = $(this).val();
+            $.ajax({
+                cache: false,
+                url: glm_baseUrl + "schedules/Edit/updateScheduleYear/",
+                data: "id=" + glm_scheduleId
+                    + "&year="  + newYear,
+                statusCode: {
+                    404: function() {
+                        alert('page not found');
+                    }
+                },
+                success: function(){
+                    glm_scheduleYear = newYear;
+                }
+            });
+        });
+        // set loading animation to display while ajax
+        $('#loading').ajaxSend(function(){
+            $('#loading').show();
+        });
+        // set loading animation to hide when stopped
+        $('#loading').ajaxStop(function(){
+            $('#loading').hide();
+        });
+        // set loading animation to hide when successfull
+        $('#loading').ajaxSuccess(function(){
+            $('#loading').hide();
+        });
+        // set loading animation to hide when error
+        $('#loading').ajaxError(function(){
+            $('#loading').hide();
+        });
+        // set loading animation to hide when complete
+        $('#loading').ajaxComplete(function(){
+            $('#loading').hide();
+        });
+        // setup onclick event for all future clicks on addTime
+        $('.chxTime.addTime').live('click', function(){
+            $("#dialog-form").dialog( "open" );
+            $("#id").val('');
+            $("#depart_time").val('');
+            $("#dock").val('1');
+            $("#departure_id").val($(this).attr('rel'));
+        });
+        // setup onclick event for all future clicks on addTime
+        $('.bviTime.addTime').live('click', function(){
+            $("#dialog-form").dialog( "open" );
+            $("#id").val('');
+            $("#depart_time").val('');
+            $("#dock").val('2');
+            $("#departure_id").val($(this).attr('rel'));
+        });
+        // setup addDepartureSet click event
+        $('#addDepartureSet').click(function(){
+            $.ajax({
+                cache: false,
+                dataType: 'json',
+                url: glm_baseUrl + "schedules/Edit/addDepartureSet/",
+                data: "id=" + $(this).attr('rel'),
+                statusCode: {
+                    404: function() {
+                        alert('page not found');
+                    }
+                },
+                success: function(data){
+                    $('#loading').before(data.html);
+                    var departureId = data.id;
+                    EditSchedule.setupDepartureById(departureId);
+                }
+            });
+        });
+        // set up removedepartureSet click event
+        $('.removeDepartureSet').live('click', function(){
+            var go = confirm('This will delete the entire Set!\nAre you sure?');
+            if (go) {
+                $(this).parent().remove();
+                $.ajax({
+                    cache: false,
+                    url: glm_baseUrl + "schedules/Edit/removeDepartureSet/",
+                    data: "id=" + $(this).attr('rel'),
+                    statusCode: {
+                        404: function() {
+                            alert('page not found');
+                        }
+                    },
+                    success: function(){
+                    }
+                });
+            }
+        });
+        // setup removeTime click for all future events
+        $('.removeTime').live('click', function(){
+            $(this).parent().remove();
+            $.ajax({
+                cache: false,
+                url: glm_baseUrl + "schedules/Edit/removeTime/",
+                data: "id=" + $(this).attr('rel'),
+                statusCode: {
+                    404: function() {
+                        alert('page not found');
+                    }
+                },
+                success: function(){
+                }
+            });
+        });
+        // setup commentSvae for all furture events
+        $('.commentSave').live('click', function(){
+            var departureId = $(this).attr('rel');
+            var comments = $('#comments' + departureId).val();
+                
+            $.ajax({
+                cache: false,
+                url: glm_baseUrl + "schedules/Edit/updateComment/",
+                data: "id=" + departureId
+                    + "&comments="  + encodeURIComponent(comments),
+                statusCode: {
+                    404: function() {
+                        alert('page not found');
+                    }
+                },
+                success: function(){
+                    $('#commentSave' + glm_departures[i]);
+                }
+            });
+        });
+        // setup nameSave click for all future events
+        $('.nameSave').live('click', function(){
+            var scheduleId = $(this).attr('rel');
+            var name = $('#scheduleNameText').val();
+                
+            $.ajax({
+                cache: false,
+                url: glm_baseUrl + "schedules/Edit/updateName/",
+                data: "id=" + scheduleId
+                    + "&name="  + encodeURIComponent(name),
+                statusCode: {
+                    404: function() {
+                        alert('page not found');
+                    }
+                }
+            });
+        });
+        // for all glm_departures (from flexy phpToJson) setup departures
+        for (i in glm_departures) {
+            EditSchedule.setupDepartureById(glm_departures[i]);
+        }
+        // setup forn-element click for all future events
+        $(".form-element").live('click', function () {
+            var formId = $(this).attr('rel');
+            $.ajax({
+                cache: false,
+                type: 'get',
+                dataType: 'json',
+                url: glm_baseUrl + "schedules/Edit/getTime/?id=" + formId,
+                success: function (data){
+                    // can now load the data into the form
+                    $("#id").val(data.id);
+                    $("#depart_time").val(data.departure_time);
+                    $("#dock").val(data.dock);
+                    $("#departure_id").val(data.departure_id);
+                },
+                statusCode: {
+                    404: function() {
+                        alert('Error: 404 Page Not Found!');
+                    }
+                }
+            });
+            $( "#dialog-form" ).dialog( "open" );
+        });
+        var depart_time = $("#depart_time"),
+            id      = $("#id"),
+            departure_id = $("#departure_id"),
+            dock = $("#dock"),
+            allFields = $([])
+                .add(id)
+                .add(depart_time)
+                .add(departure_id)
+                .add(dock),
+            tips = $( ".validateTips" );
+
+        function updateTips( t ) {
+            tips
+                .text( t )
+                .addClass( "ui-state-highlight" );
+            setTimeout(function() {
+                tips.removeClass( "ui-state-highlight", 1500 );
+            }, 500 );
+        }
+
+        function checkLength( o, n, min) {
+            if ( o.val().length < min ) {
+                o.addClass( "ui-state-error" );
+                updateTips( "Length of " + n + " must be " + min + "." );
+                return false;
+            } else {
+                return true;
+            }
+        }
+
+        function checkRegexp( o, regexp, n ) {
+            if ( !( regexp.test( o.val() ) ) ) {
+                o.addClass( "ui-state-error" );
+                updateTips( n );
+                return false;
+            } else {
+                return true;
+            }
+        }
+        // for the time edit form
+        $( "#dialog-form" ).dialog({
+            autoOpen: false,
+            height: 200,
+            width: 350,
+            modal: true,
+            buttons: {
+                "Edit Time": function() {
+                    var bValid = true;
+                    allFields.removeClass( "ui-state-error" );
+                    
+                    bValid = bValid && checkLength( depart_time, "Time", 4);
+                    
+                    if (depart_time.val()) {
+                        bValid = bValid && checkRegexp( depart_time, /([0-9]{1,2}:[0-9]{2} [APMapm]{2})$/i, "time in HH:MM AM or PM" );
+                    }
+
+                    if ( bValid ) {
+                        // need to send the data to a php page to save it
+                        var dataVars = "id=" + id.val();
+                        dataVars += "&depart_time=" + depart_time.val();
+                        if (id.val()) {
+                            $.ajax({
+                                cache: false,
+                                type: 'post',
+                                dataType: 'json',
+                                url: glm_baseUrl + "schedules/Edit/saveTime/?id=" + id.val(),
+                                data: allFields.serialize(),
+                                success: function (data){
+                                    $('span[class="form-element"][rel="' + data.id + '"]').html(data.time);
+                                },
+                                statusCode: {
+                                    404: function() {
+                                        alert('Error: 404 Page Not Found!');
+                                    }
+                                }
+                            });
+                        } else {
+                            $.ajax({
+                                cache: false,
+                                type: 'post',
+                                dataType: 'json',
+                                url: glm_baseUrl + "schedules/Edit/saveTime/",
+                                data: allFields.serialize(),
+                                success: function (data){
+                                    if (data.dock == 1) {
+                                        $('.chxTime.addTime[rel="'+data.departure_id+'"]').before(
+                                            '<label class="timeLabel">' +
+                                            '<span rel="'+data.id+'" class="form-element">'+ data.time + '</span>' +
+                                            '<span rel="'+data.id+'" class="ui-icon ui-icon-circle-minus"></span>' + 
+                                            '</label>'
+                                        );
+                                    } else if (data.dock == 2) {
+                                        $('.bviTime.addTime[rel="'+data.departure_id+'"]').before(
+                                            '<label class="timeLabel">' +
+                                            '<span rel="'+data.id+'" class="form-element">'+ data.time + '</span>' +
+                                            '<span rel="'+data.id+'" class="ui-icon ui-icon-circle-minus"></span>' + 
+                                            '</label>'
+                                        );
+                                    }
+                                },
+                                statusCode: {
+                                    404: function() {
+                                        alert('Error: 404 Page Not Found!');
+                                    }
+                                }
+                            });
+                        }
+                        
+                        $( this ).dialog( "close" );
+                    }
+                },
+                Cancel: function() {
+                    $( this ).dialog( "close" );
+                }
+            },
+            close: function() {
+                allFields.val( "" ).removeClass( "ui-state-error" );
+            }
+        });
+        
+    },
+    // setup the departures by id
+    setupDepartureById: function(id){
+        $('#color' + id).colorPicker();
+        $('#color' + id).change(function(){
+            var colorCode = $(this).val();
+            var departureId = $(this).attr('rel');
+            $.ajax({
+                cache: false,
+                url: glm_baseUrl + "schedules/Edit/updateColor/",
+                data: "id=" + departureId + '&color=' + encodeURIComponent(colorCode),
+                statusCode: {
+                    404: function() {
+                        alert('page not found');
+                    }
+                }
+            });
+        });
+        
+        $('#departureCal' + id).click(function(){
+            var ajaxUrl = glm_baseUrl + "schedules/Edit/getCalendarYear/";
+            var departureId = $(this).attr('rel');
+            var timeDate = new Date();
+            ajaxUrl += "?id=" + glm_scheduleId 
+                + "&departId=" + id 
+                + "&year=" + glm_scheduleYear
+                + "&_=" + timeDate.getTime();
+            $('#departure' + departureId).load(ajaxUrl).dialog({
+                title: 'Gaslight Media Multiple Date Picker',
+                autoOpen: true,
+                height: glm_monthsHeight,
+                width: glm_monthsWidth,
+                position: 'center',
+                modal:true,
+                beforeClose: function(){
+                    $('#departure' + departureId).html('loading...');
+                }
+            });
+        });
+    }
+};
+
+$(document).ready(EditSchedule.init);
\ No newline at end of file
diff --git a/Toolkit/Schedule/js/listSchedule.js b/Toolkit/Schedule/js/listSchedule.js
new file mode 100644 (file)
index 0000000..a73da67
--- /dev/null
@@ -0,0 +1,41 @@
+var Schedule =
+{
+    init: function()
+    {
+        Schedule.setActive();
+        $('input[name="active"]').click(function(){
+            $.ajax({
+                cache: false,
+                url: glm_baseUrl + "schedules/Edit/updateActive/",
+                data: "id=" + $(this).val(),
+                statusCode: {
+                    404: function() {
+                        alert('page not found');
+                    }
+                },
+                success: function(){
+//                    alert('active stat saved!');
+                }
+            });
+        });
+        $('#addSchedule').click(function(){
+            $.ajax({
+                cache: false,
+                url: glm_baseUrl + "schedules/Edit/addSchedule/",
+                success: function(newId){
+                    location.href=glm_baseUrl + 'admin/schedules.php?ac=Edit&id=' + newId;
+                }
+            });    
+        });
+    },
+    setActive: function()
+    {
+        if (glm_active) {
+            $('input[name="active"][value="' + glm_active + '"]').attr('checked', 'checked');
+        } else {
+            $('input[name="active"][value="0"]').attr('checked', 'checked');
+        }
+    }
+};
+
+$(document).ready(Schedule.init);
\ No newline at end of file
diff --git a/Toolkit/Schedule/templates/departureRow.html b/Toolkit/Schedule/templates/departureRow.html
new file mode 100644 (file)
index 0000000..0c429b8
--- /dev/null
@@ -0,0 +1,33 @@
+<div class="row" flexy:foreach="departures,depart">
+    <div class="colorDiv">
+        <input id="color{depart[id]}" rel="{depart[id]}" name="color{depart[id]}" value="{depart[color]:h}" />
+    </div>
+    <div class="departC edit-field">
+        times:
+        <label class="timeLabel" flexy:foreach="depart[cTimes],time">
+            <span rel="{time[id]}" class="form-element">{time[departure_time]:h}</span>
+            <span class="ui-icon ui-icon-circle-minus removeTime" rel="{time[id]}"></span>
+        </label>
+        <span rel="{depart[id]}" class="ui-icon ui-icon-circle-plus addTime chxTime"></span>
+    </div>
+    <div class="departB edit-field">
+        times:
+        <label class="timeLabel" flexy:foreach="depart[bTimes],time">
+            <span rel="{time[id]}" class="form-element">{time[departure_time]:h}</span>
+            <span class="ui-icon ui-icon-circle-minus removeTime" rel="{time[id]}"></span>
+        </label>
+        <span rel="{depart[id]}" class="ui-icon ui-icon-circle-plus addTime bviTime"></span>
+    </div>
+    <div class="departD">
+        Calendar Dates
+        <img id="departureCal{depart[id]}" rel="{depart[id]}" src="{appBase:h}assets/icons/calendar.png" />
+        <div id="departure{depart[id]}" style="display:none;">loading...</div>
+    </div>
+    <div class="comments">
+        <textarea id="comments{depart[id]}" name="comments{depart[id]}" flexy:ignore="yes">{depart[comments]:h}</textarea>
+        <button rel="{depart[id]}" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only commentSave">
+          <span class="ui-button-text">Save</span>
+        </button>
+    </div>
+    <span class="removeDepartureSet ui-icon ui-icon-circle-minus" rel="{depart[id]}"></span>
+</div>
\ No newline at end of file
diff --git a/Toolkit/Schedule/templates/departuresScheduleCalendar.html b/Toolkit/Schedule/templates/departuresScheduleCalendar.html
new file mode 100644 (file)
index 0000000..3152893
--- /dev/null
@@ -0,0 +1,100 @@
+<style type="text/css">
+#calendars {}
+table.calendarWrapper {
+       float: left;
+       border: solid 0px black;
+       padding: 0;
+       margin: 0;
+       height: 280px;
+       }
+table.cals {
+       border: solid 1px #eee;
+       border-radius: 10px;
+       margin-right: 5px;
+       padding: 2px;
+       }
+.cals td {
+       text-align: center;
+       width: 26px;
+       height: 26px;
+       }
+.cals th {
+       text-align: center;
+       padding: 10px;
+       background: #efefef;
+       border-radius: 8px;
+       }
+.calDay {
+       border: solid 1px #efefef;
+       text-align: center;
+       background: #fff;
+       }
+.noDeparture {
+       color: #999;
+       }
+.calDay {
+       padding:0;
+       margin:0;
+       }
+.selected {position:relative;top:0;left:0;padding:0;margin:0;background-color:lightgreen;width:10px;height:10px;}
+{style:h}
+#departures, #departures th, #departures td, #departures tr {
+       border-collapse: collapse;
+       border: solid 2px #ccc;
+       font-weight: bold;
+       }
+#departures {
+       border-radius-bottom-left: 10px;
+       border-radius-bottom-right: 10px;
+       }
+#departures th {
+       padding: 10px;
+       font-size: 16px;
+       font-size: 1.6rem;
+       }
+.Chx {background-color:none;width:33%;border: solid 1px black;text-align:center;}
+.Bvi {background-color:none;width:33%;border: solid 1px black;text-align:center;}
+.comments {background-color:none;width:33%;border: solid 1px black;height:100%;text-align:center;}
+.timeLabel {background-color:none;width:145px;}
+.row {clear:both;border: solid 1px black;background-color:none;}
+</style>
+<div id="departByDateSearch" flexy:if="departByDate">
+       <p>
+               <p id="departComment" flexy:if="departByDate[comments]">
+                       Note: {departByDate[comments]:h}
+               </p>
+               {departByDate[date]:h} Departures from {departByDate[dock]:h}: 
+               <ul>
+                       <li flexy:foreach="departByDate[times],time">{time[departure_time]:h}</li>
+               </ul>   
+       </p>
+</div>
+<h2>{scheduleName:h}</h2>
+<div id="calendars">
+{calendarsHtml:h}
+</div>
+<h2>Departures</h2>
+<table id="departures">
+  <tr>
+    <th class="Chx">Departing Charlevoix</th>
+    <th class="comments">Comments</th>
+    <th class="Bvi">Departing Beaver Island</th>
+  </tr>
+  <tr flexy:foreach="departures,depart">
+    <td class="Chx" style="background-color: {depart[color]:h};">
+      {foreach:depart[cTimes],time}
+      <p>{time[departure_time]:h}</p>
+      {end:}
+    </td>
+    <td class="comments" style="background-color: {depart[color]:h};">
+      <?php
+      echo nl2br($depart['comments']);
+      ?>
+    </td>
+    <td class="Bvi" style="background-color: {depart[color]:h};">
+      {foreach:depart[bTimes],time}
+      <p>{time[departure_time]:h}</p>
+      {end:}
+    </td>
+  </tr>
+</table>
diff --git a/Toolkit/Schedule/templates/editSchedule.html b/Toolkit/Schedule/templates/editSchedule.html
new file mode 100644 (file)
index 0000000..64a5849
--- /dev/null
@@ -0,0 +1,80 @@
+<style>
+    #loading {position: absolute; top: 50%; left: 50%;}
+    .row {clear:both;width: 850px;height:100px;border-top: 1px solid black;}
+    .colorDiv {width:100px;float:left;}
+    .departB {width:200px;float:left;}
+    .departC {width:200px;float:left;}
+    .departD {width:100px;float:left;}
+    .comments {width:200px;float:left;}
+    .timeLabel {display:block;width:100px;height:20px;}
+    .colorBlock {display:block;height:30px;width:30px;border: solid 1px black;}
+    .addButton {display:block;height:20px;width:20px;border: solid 1px black;}
+    .removeButton {display:inline-block;height:20px;width:20px;border: solid 1px black;}
+    .ui-icon-circle-minus {float:right;}
+    .simpleColorDisplay {float:left;}
+    .simpleColorChooser {float:left;position:absolute;top:0;left: 0;background-color: white;}
+    .simpleColorContainer {z-index: 1;float:left;position:relative;top:0;left: 0;background-color: white;}
+</style>
+<flexy:toJavascript
+  flexy:prefix="glm_"
+  appBase="appBase"
+  baseUrl="baseUrl"
+  scheduleYear="year"
+  scheduleId="scheduleId"
+  departures="colors"
+  timesChx="timesChx"
+  timesBvi="timesBvi"
+  dates="dates"
+  monthsWidth="monthsWidth"
+  monthsHeight="monthsHeight"
+/>
+<div id="breadcrumbs"><a href="{backUrl:h}">Schedules</a> > {name:h} </div>
+<div>
+    <label>
+        Year for Schedule
+    <select id="schedule_year" name="schedule_year">
+        
+    </select>
+    </label>
+</div>
+<div id="scheduleName" class="edit-field">
+    <input id="scheduleNameText" name="scheduleName" value="{name:h}" > 
+    <button rel="{scheduleId}" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only nameSave">
+      <span class="ui-button-text">Save</span>
+    </button>
+</div>
+<button id="addDepartureSet" rel="{scheduleId}" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only">
+  <span class="ui-button-text">Add a new Departure Set</span>
+</button>
+<div id="header">
+    <div class="colorDiv">
+        Color
+    </div>
+    <div class="departC">
+        Departing Charlevoix
+    </div>
+    <div class="departB">
+        Departing Beaver Island
+    </div>
+    <div class="departD">
+        Departure Dates
+    </div>
+    <div class="comments">
+        Comments
+    </div>
+</div>
+<flexy:include src="departureRow.html" />
+<div id="loading" style="display:none;"><img src="{appBase:h}/gallery/colorbox/images/loading.gif" /></div>
+<div id="dialog-form" title="Edit Time">
+       <p class="validateTips">Must enter in date format. hh:mm AM or PM</p>
+       <form>
+       <fieldset>
+        <input type="hidden" name="id" id="id" value="" />
+        <input type="hidden" name="dock" id="dock" value="" />
+        <input type="hidden" name="departure_id" id="departure_id" value="" />
+               <label for="depart_time">Time</label>
+               <input type="text" name="depart_time" id="depart_time" 
+               class="text ui-widget-content ui-corner-all noEnterSubmit" />
+       </fieldset>
+       </form>
+</div>
\ No newline at end of file
diff --git a/Toolkit/Schedule/templates/listSchedules.html b/Toolkit/Schedule/templates/listSchedules.html
new file mode 100644 (file)
index 0000000..153ece7
--- /dev/null
@@ -0,0 +1,22 @@
+<flexy:toJavascript
+    flexy:prefix="glm_"
+    baseUrl="baseUrl"
+    active="active"
+>
+<button class="add" id="addSchedule">Create New Schedule</button>
+<fieldset>
+    <legend>Boat Schedules</legend>
+    <div>
+        <label>
+            <input type="radio" name="active" value="0">
+            No Active Schedule
+        </label>
+    </div>
+    <div flexy:foreach="schedules,schedule">
+        <label>
+            <input type="radio" name="active" value="{schedule[id]:h}">
+            {schedule[name]:h}
+        </label>
+        <a class="edit" href="{baseUrl:h}admin/schedules.php?ac=Edit&id={schedule[id]:h}">Edit</a>
+    </div>
+</fieldset>
\ No newline at end of file
diff --git a/Toolkit/Schedule/templates/scheduleCalendar.html b/Toolkit/Schedule/templates/scheduleCalendar.html
new file mode 100644 (file)
index 0000000..a0c30d9
--- /dev/null
@@ -0,0 +1,36 @@
+<flexy:toJavascript
+  flexy:prefix=""
+  appBase="appBase"
+  baseUrl="baseUrl"
+  scheduleId="scheduleId"
+  departureId="departureId"
+/>
+<script type="text/javascript">
+$(document).ready(function(){
+    $("td.calDay").click(function(){
+        var calendarDay = $(this);
+        var dateSelected = encodeURIComponent($(this).attr("rel"));
+        $.ajax({
+            cache: false,
+            url: glm_baseUrl + "schedules/Edit/updateDates/",
+            data: "id=" + scheduleId 
+                + "&departId=" + departureId
+                + "&date=" + dateSelected,
+            success: function(className){
+                calendarDay.removeClass();
+                calendarDay.addClass(className)
+            }
+        });
+    });
+});
+</script>
+<style type="text/css">
+table.calendarWrapper {float:left;width:150px;height:170px;border:solid 1px black;padding:0;margin:0;}
+table.calendarWrapper td {padding:0;margin:0;margin-top:0;padding-top:0;}
+table.cals {margin-top:0;padding-top:0;width:150px;border:solid 1px black;}
+table.cals td {border:solid 1px black;width:5px;height:5px;text-align:center;}
+.calDay {cursor: pointer;width:100%;height:100%;border:1px solid balck;padding:0;margin:0;}
+.selected {position:relative;top:0;left:0;padding:0;margin:0;background-color:lightgreen;width:10px;height:10px;}
+{style:h}
+</style>
+{calendarsHtml:h}
index 2f5d44e..96ca504 100644 (file)
@@ -130,6 +130,14 @@ if (defined('PHOTO_GALLERY') && PHOTO_GALLERY) {
 if (defined('VIDEOS') && VIDEOS) {
     $nav['Video Gallery'] = MEDIA_BASE_URL.'admin/videos.php';
 }
+if (defined('SCHEDULES') && SCHEDULES) {
+    $scheduleConfig = new Zend_Config_Ini(
+        BASE . 'Toolkit/Schedule/application.ini',
+        strtolower($_ENV['GLM_HOST_ID'])
+    );
+    $nav[$scheduleConfig->applicationName]
+        = MEDIA_BASE_URL . 'admin/schedules.php';
+}
 if (defined('PRESS_DB') && PRESS_DB) {
     $nav['Press'] = MEDIA_BASE_URL.'admin/Press/';
 }
diff --git a/admin/schedules.php b/admin/schedules.php
new file mode 100644 (file)
index 0000000..7378dc1
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+require_once '../setup.phtml';
+$registry = new Toolkit_Registry;
+$registry->dbh = Toolkit_Database::getInstance();
+$registry->logger = Toolkit_Logger::getLogger();
+$registry->router = new Toolkit_Router($registry);
+$registry->router->setPath(BASE . 'Toolkit/Schedule');
+$registry->router->setApplication('Schedule');
+
+// use ZendConfig instead
+$config = new Zend_Config_Ini(
+    BASE . 'Toolkit/Schedule/application.ini',
+    strtolower($_ENV['GLM_HOST_ID'])
+);
+$flexyOptions = $GLOBALS['flexyOptions'];
+$flexyOptions['templateDir'] = $config->flexy->options->templateDir;
+$flexyOptions['compileDir']  = $config->flexy->options->compileDir;
+
+$registry->config        = $config;
+$registry->flexyOptions  = $flexyOptions;
+
+$html = $registry->router->loader();
+
+$appName = $config->applicationName;
+
+//if (!empty($_GET)) {
+//    var_dump($_GET);
+//    exit;
+//}
+GLM_TOOLBOX::top($appName, '');
+echo $html;
+GLM_TOOLBOX::footer();
\ No newline at end of file
index 927ba78..74a1a62 100644 (file)
@@ -125,6 +125,7 @@ ticketing.cat_seo = Off
 
 employment.application = Off
 videos.application = On
+schedules.application = On
 seasons.application = Off
 blocks.application = On
 ; development server configuration data inherits from production and
index e06f691..7f06f98 100644 (file)
@@ -476,6 +476,7 @@ define('ROTATING_IMAGES', $applicationConfig->rotating_images->application);
 define('WEATHER', $applicationConfig->weather->application);
 define('EMPLOYMENT', $applicationConfig->employment->application);
 define('VIDEOS', $applicationConfig->videos->application);
+define('SCHEDULES', $applicationConfig->schedules->application);
 define('SEASONS', $applicationConfig->seasons->application);
 define('GLM_BLOCKS', $applicationConfig->blocks->application);
 /**