From 24e67e0d251252b40a4fedf0a3e51c183e3c564a Mon Sep 17 00:00:00 2001
From: Brett Bieber <brett.bieber@gmail.com>
Date: Mon, 23 Mar 2009 20:12:07 +0000
Subject: [PATCH] Add column to remember if the prototype's alternate view was
 sent to the client.

---
 DesignSurvey/Prototype_sent.php |  1 +
 DesignSurvey/designsurvey.ini   |  1 +
 database/designsurvey.sql       |  2 ++
 prototype_server.php            | 11 +++++++++--
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/DesignSurvey/Prototype_sent.php b/DesignSurvey/Prototype_sent.php
index 883b0a9..db3fc18 100644
--- a/DesignSurvey/Prototype_sent.php
+++ b/DesignSurvey/Prototype_sent.php
@@ -13,6 +13,7 @@ class DesignSurvey_Prototype_sent extends DB_DataObject
     var $id;                              // int(11)  not_null primary_key auto_increment
     var $voter_id;                        // int(11)  not_null multiple_key
     var $prototype_id;                    // int(11)  not_null
+    var $viewed_alt;                      // int(1)   not_null
 
     /* ZE2 compatibility trick*/
     function __clone() { return $this;}
diff --git a/DesignSurvey/designsurvey.ini b/DesignSurvey/designsurvey.ini
index 53e4759..b839068 100644
--- a/DesignSurvey/designsurvey.ini
+++ b/DesignSurvey/designsurvey.ini
@@ -48,6 +48,7 @@ id = N
 id = 129
 voter_id = 129
 prototype_id = 129
+viewed_alt = 17
 
 [prototype_sent__keys]
 id = N
diff --git a/database/designsurvey.sql b/database/designsurvey.sql
index 686a820..04e1e55 100644
--- a/database/designsurvey.sql
+++ b/database/designsurvey.sql
@@ -122,10 +122,12 @@ CREATE TABLE IF NOT EXISTS `prototype_sent` (
   `id` int(11) NOT NULL auto_increment,
   `voter_id` int(11) NOT NULL default '0',
   `prototype_id` int(11) NOT NULL default '0',
+  `viewed_alt` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`id`),
   KEY `voter_id` (`voter_id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=latin1;
 
+
 -- --------------------------------------------------------
 
 --
diff --git a/prototype_server.php b/prototype_server.php
index 8f2bc15..055cab9 100644
--- a/prototype_server.php
+++ b/prototype_server.php
@@ -27,11 +27,12 @@ if ($prototype->get($_GET['id'])) {
         break;
     case 'alt':
             $format = 'alt_image';
+            $voter = new Voting_System();
         break;
     }
-    header('Content-type:  image/png');
+    header('Content-type: image/png');
     echo file_get_contents($image_path.$prototype->$format);
-    if ($format=='splash_image') {
+    if ($format=='splash_image' || $format == 'alt_image') {
         flush();
         $prototype_sent = DB_DataObject::factory('prototype_sent');
         $prototype_sent->voter_id     = $voter->getVoterId();
@@ -40,6 +41,12 @@ if ($prototype->get($_GET['id'])) {
             $prototype_sent->voter_id     = $voter->getVoterId();
             $prototype_sent->prototype_id = $prototype->id;
             $prototype_sent->insert();
+        } else {
+            $prototype_sent->fetch();
+        }
+        if ($format == 'alt_image') {
+            $prototype_sent->viewed_alt = 1;
+            $prototype_sent->update();
         }
     }
 }
\ No newline at end of file
-- 
GitLab