update form
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 28 Oct 2014 15:55:49 +0000 (11:55 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 28 Oct 2014 15:55:49 +0000 (11:55 -0400)
have one button to save the form data
allow selected year for display on page.

Toolkit/Schedule/EditController.php
Toolkit/Schedule/templates/editSchedule.html

index c884934..cbed552 100644 (file)
@@ -78,17 +78,17 @@ class Toolkit_Schedule_EditController
             }
         }
         $selected = $cals->getDepartureDates($scheduleId);
-        $year
-            = ($year)
-            ? $year
-            : date('Y');
+        $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);
+        $page->calendars = array();
+        for ($yearInterval = $year; $yearInterval <= $year + 5; $yearInterval++) {
+            for ($i = $startingMonth; $i <= $endingMonth; ++$i) {
+                $page->calendars[$yearInterval] .= $cals->buildCalendar($i, $yearInterval, $selected);
+            }
         }
-        $tpl                = new HTML_Template_Flexy(
+        $tpl = new HTML_Template_Flexy(
             $this->registry->flexyOptions
         );
         $page->prevYear     = $year - 1;
@@ -501,10 +501,6 @@ class Toolkit_Schedule_EditController
             FILTER_SANITIZE_STRING
         );
         if (!$scheduleId || !$depatureId || !$date) {
-//            var_dump($scheduleId);
-//            var_dump($depatureId);
-//            var_dump($date);
-//            echo 'hi no vars';
             echo 0;
             exit;
         }
@@ -655,6 +651,87 @@ class Toolkit_Schedule_EditController
         exit;
     }
 
+    public function updateScheduleAction()
+    {
+//        echo '<pre>'.print_r($_REQUEST, true).'</pre>';//exit;
+        $schedule = filter_var_array(
+            $_REQUEST,
+            array(
+                'schedule_id'   => FILTER_VALIDATE_INT,
+                'schedule_year' => FILTER_VALIDATE_INT,
+                'scheduleName'  => FILTER_SANITIZE_STRING,
+                'page'          => FILTER_VALIDATE_INT
+            )
+        );
+        if (!$schedule['schedule_id']) {
+            echo 0;
+            exit;
+        }
+        try {
+            $dbh = Toolkit_Database::getInstance();
+            $sql = "
+            UPDATE schedules
+               SET page = :page,
+                   schedule_year = :schedule_year,
+                   name = :name
+             WHERE id = :id";
+            $update = $dbh->prepare($sql);
+            $update->bindParam(
+                ':id',
+                $schedule['schedule_id'],
+                PDO::PARAM_INT
+            );
+            $update->bindParam(
+                ':schedule_year',
+                $schedule['schedule_year'],
+                PDO::PARAM_INT
+            );
+            $update->bindParam(
+                ':page',
+                $schedule['page'],
+                PDO::PARAM_INT
+            );
+            $update->bindParam(
+                ':name',
+                $schedule['scheduleName']
+            );
+            $update->execute();
+            // update comments and colors
+            foreach ($_REQUEST as $key => $value) {
+                if (preg_match('/comments([0-9]*)/', $key, $matches)) {
+
+                    $departureId = filter_var($matches[1], FILTER_VALIDATE_INT);
+                    $comment     = filter_var(
+                        $_REQUEST['comments' . $departureId],
+                        FILTER_SANITIZE_STRING
+                    );
+                    $color       = filter_var(
+                        $_REQUEST['color' . $departureId],
+                        FILTER_SANITIZE_STRING
+                    );
+                    if ($departureId) {
+                        $sql = "
+                        UPDATE departures
+                           SET comments = :comments,
+                               color = :color
+                         WHERE id = :id";
+                        $stmt = $dbh->prepare($sql);
+                        $stmt->bindParam(':comments', $comment);
+                        $stmt->bindParam(':color', $color);
+                        $stmt->bindParam(':id', $departureId);
+                        $stmt->execute();
+                    }
+                }
+            }
+//            die('stopped');
+            header('Location: schedules.php?ac=Edit&id=' . $schedule['schedule_id']. '&saved=1');
+            exit;
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+        exit;
+    }
+
     public function updatePageAction()
     {
         $scheduleId = filter_input(
index 0d7cd4e..3eb9437 100644 (file)
@@ -14,6 +14,7 @@
     .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;}
+    .hide {display:none;}
 </style>
 <flexy:toJavascript
     flexy:prefix="glm_"
     monthsWidth="monthsWidth"
     monthsHeight="monthsHeight"
     />
-<form>
+<div class="row" flexy:if="saved">
+    <div class="small-12 columns alert-box success" data-alert>
+        Schedule data is saved!
+        <a href="#" class="close" onclick="$(this).parent().parent('.row').hide();">x</a>
+    </div>
+</div>
+
+<form method="get" action="{formUrl:h}">
+    <input type="hidden" name="schedule_id" value="{scheduleId:h}">
     <div class="row">
         <ul id="breadcrumbs" class="breadcrumbs">
             <li><a href="{backUrl:h}">Schedules</a> > {name:h}</li>
         </ul>
+
         <div class="row">
-            <div id="scheduleName" class="edit-field large-12 columns">
+            <div class="small-3 columns">
+                <label>
+                    Year for Schedule<br>(For Output on Page)
+                    <select id="schedule_year" name="schedule_year">
+
+                    </select>
+                </label>
+            </div>
+            <div id="scheduleName" class="edit-field small-6 columns">
                 <div class="row collapse">
-                    <div class="small-10 columns">
+                    <div class="small-9 columns">
                         <label>
+                            Schedule Name:
                             <input type="text" id="scheduleNameText" name="scheduleName" value="{name:h}" >
                         </label>
                     </div>
-                    <div class="small-2 columns">
+<!--                    <div class="small-2 columns">
                         <a rel="{scheduleId}"
                            class="button postfix nameSave">
                             <span class="ui-button-text">Save</span>
                         </a>
-                    </div>
+                    </div>-->
                 </div>
             </div>
         </div>
         <div class="row">
             <div id="schedulePage" class="edit-field large-12 columns">
                 <div class="row collapse">
-                    <div class="small-10 columns">
+                    <div class="small-6 columns">
                         <label>
+                            Page for Display:
                             {pageSelect:h}
                         </label>
                     </div>
-                    <div class="small-2 columns">
+                    <div class="small-6 text-center columns">
+                        <input type="submit" value="Save Schedule" class="button">
+                    </div>
+<!--                    <div class="small-2 columns">
                         <a rel="{scheduleId}" class="button postfix pageSave">
                             <span class="ui-button-text">Save</span>
                         </a>
-                    </div>
+                    </div>-->
                 </div>
             </div>
         </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>
-</form>
-</div>
\ No newline at end of file
+</div>
+</form>
\ No newline at end of file