<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>.gitignore</filename>
    </added>
    <added>
      <filename>OAuth.php</filename>
    </added>
    <added>
      <filename>README.markdown</filename>
    </added>
    <added>
      <filename>addict_database.php</filename>
    </added>
    <added>
      <filename>addict_testing.php</filename>
    </added>
    <added>
      <filename>config-default.php</filename>
    </added>
    <added>
      <filename>hulu.php</filename>
    </added>
    <added>
      <filename>netflix.php</filename>
    </added>
    <added>
      <filename>onhulu.php</filename>
    </added>
    <added>
      <filename>scrape.php</filename>
    </added>
    <added>
      <filename>sql/movieaddict_addict.sql</filename>
    </added>
    <added>
      <filename>templates/layout_common.php</filename>
    </added>
    <added>
      <filename>templates/layout_friends.php</filename>
    </added>
    <added>
      <filename>templates/layout_index.php</filename>
    </added>
    <added>
      <filename>templates/layout_tabs.php</filename>
    </added>
    <added>
      <filename>templates/layout_view.php</filename>
    </added>
    <added>
      <filename>unittest.php</filename>
    </added>
    <added>
      <filename>watch-great-movies.php</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,339 +1,21 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The &quot;Program&quot;, below,
-refers to any such program or work, and a &quot;work based on the Program&quot;
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term &quot;modification&quot;.)  Each licensee is addressed as &quot;you&quot;.
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and &quot;any
-later version&quot;, you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM &quot;AS IS&quot; WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the &quot;copyright&quot; line and a pointer to where the full notice is found.
-
-    &lt;one line to give the program's name and a brief idea of what it does.&gt;
-    Copyright (C) &lt;year&gt;  &lt;name of author&gt;
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License along
-    with this program; if not, write to the Free Software Foundation, Inc.,
-    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a &quot;copyright disclaimer&quot; for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  &lt;signature of Ty Coon&gt;, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
+The MIT License
+
+Copyright (c) 2009 Kyle Conroy
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the &quot;Software&quot;), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file</diff>
      <filename>COPYING.txt</filename>
    </modified>
    <modified>
      <diff>@@ -4,88 +4,39 @@
 	The given filename is assumed to be in the correct order
 	$listname should be the organzation that produced the list
 	such as afi, or imdb **/
-	
 
-require_once('libfunction.php');
+require_once &quot;scrape.php&quot;;
+require_once &quot;addict_database.php&quot;;
 
-addList('afi');
-	
-function addList($listname) {
-	require_once('config.php');
-	
-	$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
-	if (!$con) {
-	  die('Could not connect: ' . mysql_error());
-	}
-	$db_selected = mysql_select_db($db, $con);
-	if (!$db_selected) {
-	    die ('Can\'t use ' . mysql_error());
-	}
-	
-	$movienames = $listname . '_names.txt';
-	$movieids = $listname . '_ids.txt';
+$ad = new AddictDatabase();
+$afi100 = readList(&quot;lists/afi_ids.txt&quot;);
+addList($afi100);
 	
-	echo &quot;Reading in list...&quot;;
-	$newlist = file('lists/' . $movienames);
-	echo &quot;Done&lt;br&gt;&quot;;
-	echo &quot;Get ids...&quot;;
-	if(file_exists('lists/' . $movieids)){
-		$ids = file('lists/' . $movieids);
-		$newlist = getidsFile($newlist, $ids);
-	} else
-		$newlist = getidsGoogle($newlist, $movieids);
-	echo &quot;Done&lt;br&gt;&quot;;
-	$films = filmids($db, $con);	
-	
-	if(!mysql_query(&quot;ALTER TABLE top250 ADD $listname INT&quot;))
-		echo &quot;Column already exists, continuing...&lt;br&gt;&quot;;
-
-	$counter = 1;
-	foreach ($newlist as $id =&gt; $name) {
-		if(!in_array($id, $films)) {
-			if(mysql_query(&quot;INSERT INTO top250 (imdbid, title, $listname) VALUES (\&quot;$id\&quot;, \&quot;$name\&quot;, \&quot;$counter\&quot;)&quot;))
-				printf(&quot;Added $id, $name, as the $counter entry in $listname&lt;br&gt;&quot;);
-			else
-				die (&quot;Can\'t add $id, $name, &quot; . mysql_error());
-			if(!mysql_query(&quot;ALTER TABLE users ADD UNIQUE $id BOOL&quot;)) {
-    			die ('Can\'t alter table ' . mysql_error());
-			}
-			if(!mysql_query(&quot;ALTER TABLE users MODIFY $id BOOL NOT NULL&quot;)) {
-    			die ('Can\'t make not null ' . mysql_error());
-			}
-			if(!mysql_query(&quot;ALTER TABLE users ALTER $id SET DEFAULT 0;&quot;)) {
-    			die ('Can\'t set default ' . mysql_error());
-			}	
-		} else if(mysql_query(&quot;UPDATE top250 SET $listname = $counter WHERE imdbid = '$id'&quot;)){
-			printf(&quot;Updated $id, $name, as the $counter entry in $listname&lt;br&gt;&quot;);  
-		} else {
-		  	die(&quot;Error $id, $name, not added as the $counter entry in $listname&quot;. mysql_error(). '&lt;br&gt;');
-		}
-	 	$counter++;
-	}
-}
-
-function getidsFile($movies, $movieids){
-	$ids = array();
-	$counter = 0;
-	foreach($movies as $movie) {
-		$key = trim($movieids[$counter++]);
-		$ids[$key] = $movie;
+function addList($list) {
+	global $ad;
+	$current = $ad-&gt;getMovies();
+	$ad-&gt;resetAFIRank();
+	foreach ($list as $movie) {
+		if (in_array($movie['id'], array_keys($current))) {
+	   		$ad-&gt;updateAFIRank($movie['id'], $movie['rank']);
+	   		echo &quot;Updated &quot; . $movie['id'] . &quot; to #&quot; . $movie['rank'] . &quot;&lt;br&gt;&quot;;
+	 	} else {
+			$ad-&gt;addMovie($movie['id'], $movie['title'], NULL, $movie['rank']);
+			echo &quot;Added &quot; . $movie['id'] . &quot; as #&quot; . $movie['rank'] . &quot;&lt;br&gt;&quot;;
+	 	}
 	}
-	return $ids;
 }
 
-function getidsGoogle($movies, $file){
-	$ids = array();
-	foreach($movies as $movie) {
-		$imdbid = findimdbid($movie);
-		$ids[$imdbid] = $movie;
-	}
-	$fp=fopen($file,&quot;w+&quot;);
-	foreach($ids as $key =&gt; $value){
-		fwrite($fp,$key.&quot;\n&quot;);
+function readList($filename){
+	$fp = fopen($filename, &quot;r&quot;);
+	$movies = array();
+	$count = 1;
+	while($line = fgets($fp)){
+		$movie = array();
+		$movie['id'] = (int) $line;
+		$movie['rank'] = $count++;
+		$movies[] = $movie;
 	}
-	fclose($fp);
-	return $ids;
+	return $movies;
 }
 ?&gt;
\ No newline at end of file</diff>
      <filename>addList.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 &lt;?php
 
 // Get the configuration variables
-require_once('config.php');
+require_once 'config.php';
 
 // Use the Facebook platform libraries
 require_once 'facebook.php';
@@ -10,43 +10,27 @@ require_once 'facebook.php';
 $facebook = new Facebook($appapikey, $appsecret);
 $user = $facebook-&gt;require_login();
 
-$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
+// Connect to the database
+$ad = new AddictDatabase();
 
-if (!$con) {
-  die('Could not connect: ' . mysql_error());
-}
-
-$db_selected = mysql_select_db($db, $con);
-
-if (!$db_selected) {
-    die ('Can\'t use ' . mysql_error());
-}
-
-// Insert the user into the table
-$result = mysql_query(&quot;SELECT * FROM users WHERE userid = '$user'&quot;) or
-		die ('Can\'t select ' . mysql_error());
-$row = mysql_fetch_array($result);		
-		
-if(!$row) {
-	mysql_query(&quot;INSERT INTO users (userid,percent) VALUES('$user',0)&quot;) or
-		die ('Can\'t insert ' . mysql_error());
-}
+// Insert the user into the table only if he / she isn't already there
+if(!$ad-&gt;getUser($user))
+	$ad-&gt;addUser($user);
 
 // Check if any movies are from the user's profile are in the top 250 and update them
 $user_details = $facebook-&gt;api_client-&gt;users_getInfo($user, array('movies'));
 $user_movies = explode(', ', $user_details[0]['movies']);
 
-$result = mysql_query(&quot;SELECT * FROM top250&quot;) or
-		die ('Can\'t select ' . mysql_error());;
+$allmovies = $ad-&gt;getMovies();
 
-while($row = mysql_fetch_array($result)) {
-	if(in_array($row['title'], $user_movies)) {
-		$imdbid = $row['imdbid'];
-		mysql_query(&quot;UPDATE users SET `$imdbid` = 1 WHERE userid = '$user'&quot;) or
-			die ('Can\'t update value ' . mysql_error());
+foreach($allmovies as $movie)
+	if(in_array($movie['title'], $user_movies)) {
+		$ad-&gt;addUserMovie($user, $movie['movie_id']);
 	}
 }
 
+$ad-&gt;updateUserMovieCount($user);
+
 mysql_close(); 
 
 echo '&lt;fb:redirect url=&quot;http://apps.facebook.com/'.$appurl.'?msg=2&quot; /&gt;';</diff>
      <filename>addUser.php</filename>
    </modified>
    <modified>
      <diff>@@ -19,8 +19,8 @@
 	along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
 
-require('config.php');
-require('libfunction.php');
+require_once 'config.php';
+require_once 'addict_database.php';
 
 // Use the Facebook platform libraries
 require_once 'facebook.php';
@@ -51,7 +51,7 @@ if($facebook-&gt;api_client-&gt;users_isAppUser($_GET['user']) &amp;&amp; isset($_GET['user'])
 */
 
 // Error Handling
-$users = $_GET['user'];
+$users = array_keys($_GET['user']);
 if(count($users) &lt; 2)
 	die(&quot;Too few arguments&quot;);
 
@@ -65,35 +65,22 @@ try {
 	die(&quot;invalid user id&quot;);
 }
 
-//Retrieve data from MySQL, first connecting to the databse
-$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
-if (!$con) {
-  die('Could not connect: ' . mysql_error());
-}
-$db_selected = mysql_select_db($db, $con);
-if (!$db_selected) {
-    die ('Can\'t use ' . mysql_error());
-}
-	
-//$users = array('3432235','639076927','30509961');
-$allfilms = films($db, $con, NULL);
-
-$usersdata = array();
-foreach($users as $key =&gt; $value) {
-		$userdata[] = userdata($db, $con, $key);
-}
+$ad = new AddictDatabase();
 
-$seen = moviestatus($userdata, $allfilms);
 
 // Update the userfilms
+$movies = $ad-&gt;getRankedMovies();
+
+$unseenids = array();
+foreach($users as $user){
+	$unseenids = array_merge($ad-&gt;getUserMovies($user), $unseenids);
+}
 $unseen = array();
-foreach($allfilms as &amp;$film) {
-	if(!$seen[$film[&quot;id&quot;]]) {
-		$film[&quot;link&quot;] = movielink($film[&quot;title&quot;], $film[&quot;id&quot;]);
-		$unseen[] =  $film;
-	}
+$unseenids = array_unique($unseenids);
+foreach($movies as $key =&gt; $value){
+	if(!in_array($key, $unseenids))
+		$unseen[] = $value;
 }
-unset($film);
 	
 //Create the pageData object
 $pageData = (object)(array());
@@ -101,33 +88,13 @@ $pageData = (object)(array());
 
 // Save Information
 $pageData-&gt;css = $cssurl;
-$pageData-&gt;tabs = tabs(2, $appurl);
+$pageData-&gt;tabs = 2;
 $pageData-&gt;users = $users;
 $pageData-&gt;films = $unseen;
 
 // Display the Page
 ob_start(); 
-require(&quot;layout_common.php&quot;); 
+require_once(&quot;templates/layout_common.php&quot;); 
 ob_end_flush();
 
-
-mysql_close();
-
-/** OR the values of the given arrays **/
-function moviestatus($users, $movies) {
-	$result = array();
-	foreach($movies as $value){
-		$result[$value[&quot;id&quot;]] = orarray($value[&quot;id&quot;], $users);
-	}
-	return $result;
-}
-
-function orarray($index, $arrays) {
-	$bool = FALSE;
-	foreach($arrays as $array){
-		$bool = $bool || $array[$index] &gt; 0;
-	}
-	return $bool;
-}
-
 ?&gt;
\ No newline at end of file</diff>
      <filename>common.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,133 +1,105 @@
-&lt;?php 
+&lt;?php
 
-require_once('config.php');
+require_once &quot;netflix.php&quot;;
+require_once &quot;scrape.php&quot;;
+require_once &quot;addict_database.php&quot;;
+require_once &quot;config.php&quot;;
 
-/** Update Everything **/
+//Title Change
+$dictionary = array(
+	'Il buono, il brutto, il cattivo.' =&gt; 'The Good, the Bad and the Ugly',
+	'Shichinin no samurai' =&gt; 'The Seven Samurai',
+	&quot;C&amp;#x27;era una volta il West&quot; =&gt; 'Once Upon a Time in the West',
+	'Cidade de Deus' =&gt; 'City of God',
+	'L&amp;#xE9;on' =&gt; 'The Professional',
+	'Le fabuleux destin d&amp;#x27;Am&amp;#xE9;lie Poulain' =&gt; 'Am&amp;#xE9;lie',
+	'Das Leben der Anderen' =&gt; 'The Lives of Others',
+	'Sen to Chihiro no kamikakushi' =&gt; 'Spirited Away',
+	'El laberinto del fauno' =&gt; 'Pan\'s Labyrinth',
+	'Der Untergang' =&gt; 'Downfall',
+	'La vita &amp;#xE8; bella' =&gt; 'Life Is Beautiful',
+	'Nuovo cinema Paradiso' =&gt; 'Cinema Paradiso',
+	'Ladri di biciclette' =&gt; 'The Bicycle Thief',
+	'Det sjunde inseglet' =&gt; 'The Seventh Seal',
+	'Per qualche dollaro in pi&amp;#xF9;' =&gt; 'For a Few Dollars More',
+	'Smultronst&amp;#xE4;llet' =&gt; 'Wild Strawberries',
+	'Les diaboliques' =&gt; 'Diabolique',
+	'Le notti di Cabiria' =&gt; 'Nights of Cabiria',
+	'Le salaire de la peur' =&gt; 'The Wages of Fear',
+	'Amores perros' =&gt; 'Love\'s a Bitch',
+	'L&amp;#xE5;t den r&amp;#xE4;tte komma in' =&gt; 'Let the Right One In',
+	'Hotaru no haka' =&gt; 'Grave of the Fireflies',
+	'La battaglia di Algeri' =&gt; 'The Battle of Algiers',
+	'Mou gaan dou' =&gt; 'Infernal Affairs',
+	'Nosferatu, eine Symphonie des Grauens' =&gt; 'Nosferatu the Vampire',
+	'Wo hu cang long' =&gt; 'Crouching Tiger, Hidden Dragon',
+	'Le scaphandre et le papillon' =&gt; 'The Diving Bell and the Butterfly',
+	'Mononoke-hime' =&gt; 'Princess Mononoke',
+);
 
-$top = top250();
-updateTop250($top, $dbuser, $dbpass, $db);
-//updateUsers($top, $dbuser, $dbpass, $db);
-
-function top250()
-{
-	$url = 'http://www.imdb.com/chart/top';
-	$ch = curl_init();
-	curl_setopt($ch, CURLOPT_URL, $url);
-	curl_setopt($ch, CURLOPT_FAILONERROR, 1);
-	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
-	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
-	curl_setopt($ch, CURLOPT_TIMEOUT, 3);
-	$result = curl_exec($ch);
-	curl_close($ch); 
-	preg_match_all('/\/title\/\w+\/&quot;&gt;[^&lt;&gt;]+/', $result, $match);
-	$match = $match[0];
-	return $match;
-}
+$ad = new AddictDatabase(&quot;brokenva_addicttest&quot;);
+$nf = new Netflix($netflixKey, $netflixSecret);
+$top250 = getIMDB250();
+updateTop250($top250);
 
 /** Update the top 250 table **/
-function updateTop250($top250, $dbuser, $dbpass, $db) {
-	$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
-	if (!$con) {
-	  die('Could not connect: ' . mysql_error());
-	}
-	$db_selected = mysql_select_db($db, $con);
-	if (!$db_selected) {
-	    die ('Can\'t use ' . mysql_error());
-	}
-	$counter = 1;
-	foreach ($top250 as $str) {
-		$imdbid = substr($str, 9, 7);
-		$title = substr($str, 19);
-		if(!mysql_query(&quot;UPDATE top250 SET imdb = $counter WHERE imdbid = \&quot;$imdbid\&quot;&quot;)) {
-	   		if (!mysql_query(&quot;INSERT INTO top250 (imdbid, title, imdb) VALUES (\&quot;$imdbid\&quot;, \&quot;$title\&quot;, '$counter')&quot;))
-	   			die ('Can\'t insert into table ' . mysql_error());
-	 	}
-		$counter++;
-	}
-	mysql_close();
-}
 
-/** Add any movies that weren't previously on the list to the user table **/
-function updateUsers($top250, $dbuser, $dbpass, $db) {
-	$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
-	if (!$con) {
-	  die('Could not connect: ' . mysql_error());
-	}
-	$db_selected = mysql_select_db($db, $con);
-	if (!$db_selected) {
-	    die ('Can\'t use ' . mysql_error());
-	}
-	$result = mysql_query(&quot;SELECT * FROM users WHERE userid = 0&quot;);
-	$row = mysql_fetch_array($result, MYSQL_ASSOC);
-	foreach ($top250 as $str) {
-		$imdbid = substr($str, 9, 7);
-		if($row[$imdbid] == NULL) {
-   			if(!mysql_query(&quot;ALTER TABLE users ADD `$imdbid` BOOL&quot;)) {
-    			die ('Can\'t alter table ' . mysql_error());
-			}
-			if(!mysql_query(&quot;ALTER TABLE users MODIFY `$imdbid` BOOL NOT NULL&quot;)) {
-    			die ('Can\'t make not null ' . mysql_error());
-			}
-			if(!mysql_query(&quot;ALTER TABLE users ALTER `$imdbid` SET DEFAULT 0;&quot;)) {
-    			die ('Can\'t set default ' . mysql_error());
-			}
+function updateTop250($top250) {
+	global $ad;
+	global $dictionary;
+	$current = $ad-&gt;getMovies();
+	$ad-&gt;resetIMDBRank();
+	$ad-&gt;resetNetflixInstant();
+	foreach ($top250 as $movie) {
+	    $nftitle = $movie['title'];
+		if (in_array($movie['id'], array_keys($current))) {
+	   		$ad-&gt;updateIMDBRank($movie['id'], $movie['imdb_rank']);
+	   		echo &quot;Updated '&quot; . $movie['title'] . &quot;' to #&quot; . $movie['imdb_rank'] . &quot;&lt;br&gt;&quot;;
+	 	} else {
+			$ad-&gt;addMovie($movie['id'], $movie['title'], $movie['imdb_rank']);
+			echo &quot;Added '&quot; . $movie['title'] . &quot;' as #&quot; . $movie['imdb_rank'] . &quot;&lt;br&gt;&quot;;
+	 	}
+	 	if (in_array(utf8_decode($movie['title']), array_keys($dictionary))) {
+	 		$ad-&gt;updateMovieTitle($movie['id'], $dictionary[$movie['title']]);
+	 		$nftitle = $dictionary[$movie['title']];
+	 		echo &quot;Updated &quot; . $movie['title'] . &quot; to &quot; . $dictionary[$movie['title']] . &quot;&lt;br&gt;&quot;;
 	 	}
+        if($xml = netflixLookup($nftitle)) {
+            if(canWatchInstant($xml)) {
+                $ad-&gt;updateNetflixInstant($movie['id'], true);
+                echo &quot;You can now watch $nftitle instantly! &lt;br&gt;&quot;;
+            }
+            if($nfid = netflixId($xml))
+                $ad-&gt;updateNetflixId($movie['id'], $nfid);
+        }
+        usleep(300);
 	}
-	mysql_close(); 
 }
 
-/* An associative array of the Top 250 Films */
-function top250array() {
-	
-	require('config.php');
-	
-	$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
-	if (!$con) {
-	  die('Could not connect: ' . mysql_error());
-	}
-	$db_selected = mysql_select_db($db, $con);
-	if (!$db_selected) {
-	    die ('Can\'t use ' . mysql_error());
-	}
-	$result = mysql_query(&quot;SELECT * FROM top250&quot;);
-	if(!$result) {
-	   		die ('Can\'t get top movies ' . mysql_error());
-	}
-	
-	$films = array();
-	while ($row = mysql_fetch_array($result)){
-		$films[$row[0]] = array(&quot;title&quot;=&gt;$row[1], &quot;count&quot;=&gt;0);
-	}
-	return $films;
+
+function netflixId($xml){
+    $url = array_shift($xml-&gt;xpath(&quot;/catalog_titles/catalog_title[1]&quot;))-&gt;id;
+    if(preg_match('/\d+/', $url, $matches))
+        return $matches[0];
+    return false;
 }
 
-function filmCount() {
+function canWatchInstant($xml){
+    $format = array_shift($xml-&gt;xpath(&quot;/catalog_titles/catalog_title[1]/
+                link[@title='formats']/delivery_formats/availability/category[@term='instant']&quot;));
+    if($format)
+        return true;
+    return false; 
+}
 
-	require('config.php');
-	
-	$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
-	if (!$con) {
-	  die('Could not connect: ' . mysql_error());
-	}
-	$db_selected = mysql_select_db($db, $con);
-	if (!$db_selected) {
-	    die ('Can\'t use ' . mysql_error());
-	}
-	$result = mysql_query(&quot;SELECT * FROM users&quot;);
-	if(!$result) {
-	   		die ('Can\'t get top movies ' . mysql_error());
-	}
-	
-	$films = top250array();
-	
-	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
-		unset($row['userid']);
-		unset($row['percent']);
-		foreach($row as $key=&gt;$value){
-			$films[$key][&quot;count&quot;] = $films[$key][&quot;count&quot;] + $value;
-		}
-	}
-	mysql_close();
-	return $films;
+function netflixLookup($title){
+    global $nf;
+    global $netflixUrl;
+    $params = array(&quot;term&quot; =&gt; $title, &quot;expand&quot;=&gt;&quot;formats&quot;);
+    $result = $nf-&gt;request($netflixUrl, &quot;GET&quot;, $params);
+    if(!$result)
+        return false;
+    return simplexml_load_string($result);
 }
 
+?&gt;
\ No newline at end of file</diff>
      <filename>cron.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,8 @@
 &lt;?php
 
 // Get the configuration variables
-require_once('config.php');
-require_once('libfunction.php');
-
-// Use the Facebook platform libraries
+require_once 'config.php';
+require_once 'addict_database.php';
 require_once 'facebook.php';
 
 // Create the Facebook application
@@ -22,28 +20,18 @@ if (is_array($_friends) &amp;&amp; count($_friends)) {
 		$friends[] = $friend['uid']; 
 		}
 } 
+unset($_friends);
 
-$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
-
-if (!$con) {
-  die('Could not connect: ' . mysql_error());
-}
-
-$db_selected = mysql_select_db($db, $con);
-
-if (!$db_selected) {
-    die ('Can\'t use ' . mysql_error());
-}
+$ad = new AddictDatabase();
 
 $filmfriends = array();
 foreach($friends as $friend){
-	$result = mysql_query(&quot;SELECT percent FROM users WHERE userid = '$friend'&quot;) or
-		die ('Can\'t update value ' . mysql_error());;
-	$row = mysql_fetch_assoc($result);
-	if($row) {
-		$filmfriends[] = array(&quot;userid&quot; =&gt; $friend, &quot;percent&quot; =&gt; $row[&quot;percent&quot;]);
+	$user = $ad-&gt;getUser($friend);
+	if($user) {
+		$filmfriends[] = $user;
 	}	
 }
+unset($friends);
 
 //Create the pageData object
 $pageData = (object)(array()); 
@@ -51,13 +39,13 @@ $pageData = (object)(array());
 // Save Information
 $pageData-&gt;css = $cssurl;
 $pageData-&gt;appurl = $appurl;
-$pageData-&gt;tabs = tabs(2, $appurl);
+$pageData-&gt;tabs = 2;
 $pageData-&gt;userid = $user;
 $pageData-&gt;friends = $filmfriends;
 
 // Display the Page
 ob_start(); 
-require(&quot;layout_friends.php&quot;); 
+require_once(&quot;templates/layout_friends.php&quot;); 
 ob_end_flush();
 
 mysql_close();
\ No newline at end of file</diff>
      <filename>friends.php</filename>
    </modified>
    <modified>
      <diff>@@ -18,16 +18,19 @@
 	You should have received a copy of the GNU General Public License
 	along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
-
-require('config.php');
-require('libfunction.php');
-
-// Use the Facebook platform libraries
+require_once 'netflix.php';
+require_once 'config.php';
+require_once 'addict_database.php';
 require_once 'facebook.php';
 
-// Create the Facebook application
 $facebook = new Facebook($appapikey, $appsecret);
 $user = $facebook-&gt;require_login();
+$KEY =  &quot;jrd2pte858kkj8pg3v3ukw8t&quot;;
+$SECRET = &quot;XkWQEMsHEJ&quot;;
+
+$url = &quot;http://api.netflix.com/catalog/titles/&quot;;
+$nf = new Netflix($KEY, $SECRET);
+$ad = new AddictDatabase();
 
 // Catch the exception that gets thrown if the cookie has an invalid session_key in it
 try {
@@ -50,30 +53,25 @@ if($facebook-&gt;api_client-&gt;users_isAppUser($_GET['user']) &amp;&amp; isset($_GET['user'])
 }
 */
 
-
-//Retrieve data from MySQL, first connecting to the databse
-$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
-if (!$con) {
-  die('Could not connect: ' . mysql_error());
-}
-$db_selected = mysql_select_db($db, $con);
-if (!$db_selected) {
-    die ('Can\'t use ' . mysql_error());
-}
-
 $list = $_GET['list'];
 if($list == 'afi') {
 	$list = 'afi';
 	$tabvalue = 1;
 	$total = '100';
+	$list_movies = $ad-&gt;getAFIMovies();
 } 
 else {
 	$list = 'imdb';
 	$total = '250';
+	$list_movies = $ad-&gt;getIMDBMovies();
 }
-$userfilms = userfilms($db, $con, $user, $list);
-$percent = userdata($db, $con, $user);
-$percent = $percent[&quot;percent&quot;];
+
+
+$user_info = $ad-&gt;getUser($user);
+$user_movies = $ad-&gt;getUserMovies($user);
+$user_count = $user_info['count'];
+$percent = $user_info['percent'];
+$total_count = 274;
 
 //Determine what message to show
 $msg = $_GET['msg'];
@@ -92,34 +90,25 @@ switch($msg) {
 $fbml = generateFbml($percent, $user, $appurl);
 $facebook-&gt;api_client-&gt;call_method('facebook.profile.setFBML', array('uid' =&gt; $user, 'profile' =&gt; $fbml, 'profile_main' =&gt; $fbml));
 
-// Update the userfilms
-$count = 0;
-foreach($userfilms as &amp;$film) {
-	if($film['seenit'] == 1) {
-		$film[&quot;checked&quot;] =  'checked=&quot;checked&quot;';
-		$count += 1;
-	}
-	$film[&quot;link&quot;] = movielink($film[&quot;title&quot;], $film[&quot;id&quot;]);
-}
-unset($film);
-
 //Create the pageData object
 $pageData = (object)(array()); 
 
 // Save Information
 $pageData-&gt;css = $cssurl;
-$pageData-&gt;tabs = tabs($tabvalue, $appurl);
+$pageData-&gt;tabs = $tabvalue;
+$pageData-&gt;appurl =  $appurl;
 $pageData-&gt;msg = $msg;
-$pageData-&gt;userid = $user;
+$pageData-&gt;userid = (int) $user;
 $pageData-&gt;percent = $percent;
-$pageData-&gt;films = $userfilms;
 $pageData-&gt;movielist = $list;
-$pageData-&gt;moviecount = $count;
-$pageData-&gt;totalcount = $total;
+$pageData-&gt;movies = $list_movies;
+$pageData-&gt;seen_movies = $user_movies;
+$pageData-&gt;moviecount = $user_count;
+$pageData-&gt;totalcount = $total_count;
 
 // Display the Page
 ob_start(); 
-require(&quot;layout_index.php&quot;); 
+require_once(&quot;templates/layout_index.php&quot;); 
 ob_end_flush();
 
 
@@ -130,6 +119,4 @@ function generateFbml($percent, $user, $appurl){
 	return $fbml;
 }
 
-mysql_close();
-
 ?&gt;
\ No newline at end of file</diff>
      <filename>index.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,14 +1,14 @@
 &lt;? 
 
 // Get these from http://developers.facebook.com 
-require('config.php');
-require('libfunction.php');
+require_once('config.php');
+require_once 'templates/layout_tabs.php';
 
 // Names and images 
 $app_image = &quot;Application image URL&quot;; 
 $invite_href = &quot;invite.php&quot;; // Rename this as needed 
 
-require_once 'facebook.php'; 
+require_once 'facebook.php';
 
 $facebook = new Facebook($appapikey, $appsecret ); 
 $facebook-&gt;require_frame(); 
@@ -19,10 +19,9 @@ $pageData = (object)(array());
 
 // Save Information
 $pageData-&gt;css = $cssurl;
-$pageData-&gt;tabs = tabs(4, $appurl);
+$pageData-&gt;tabs = 4;
 $pageData-&gt;userid = $user;
 $pageData-&gt;percent = $percent;
-$pageData-&gt;films = $imdbfilms;
 $pageData-&gt;sentmsg = isset($_POST[&quot;ids&quot;]);
 $pageData-&gt;fcount = sizeof($_POST[&quot;ids&quot;]);
 
@@ -65,7 +64,7 @@ if($pageData-&gt;sentmsg) { ?&gt;
 
 	&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; href=&quot;&lt;?php echo $pageData-&gt;css; ?&gt;?ver=2.4&quot; /&gt;
 
-	&lt;?php echo $pageData-&gt;tabs; ?&gt;
+	&lt;?php echo tabs($pageData-&gt;tabs); ?&gt;
 
 	&lt;fb:request-form 
 			action=&quot;&lt;? echo $invite_href; ?&gt;&quot; </diff>
      <filename>invite.php</filename>
    </modified>
    <modified>
      <diff>@@ -27,6 +27,11 @@
 	width: 118px;
 }
 
+.netflix {
+    color: #B9090B;
+    float: right;
+}
+
 .fbml_add_profile_button td {
 	padding: 0px;
 }
@@ -119,3 +124,10 @@
 	float: right;
 	background: #6D84b4;
 }
+
+.status {
+    background-color:#FFF9D7;
+    border-color:#E2C822;
+    padding:10px;
+}
+</diff>
      <filename>top250.css</filename>
    </modified>
    <modified>
      <diff>@@ -1,54 +1,38 @@
 &lt;?php
 
 // Get the configuration variables
-require_once('config.php');
-require('libfunction.php');
+require_once 'addict_database.php';
+require_once 'config.php';
 
-$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
+$ad = new AddictDatabase();
 
-if (!$con) {
-  die('Could not connect: ' . mysql_error());
-}
-
-$db_selected = mysql_select_db($db, $con);
+$user_id = $_POST['userid'];
+$on_movies = $_POST['film'];
+$checked_movies = array();
+$list = $_POST['list'];
+$previous_movies = $ad-&gt;getUserMovies($user_id);
 
-if (!$db_selected) {
-    die ('Can\'t use ' . mysql_error());
+if($list == &quot;imdb&quot;){
+	$list_films = array_keys($ad-&gt;getIMDBMovies());
+} else {
+	$list_films = array_keys($ad-&gt;getAFIMovies());
 }
 
-$userid = $_POST['userid'];
-$checked = $_POST['film'];
-$list = $_POST['list'];
+foreach($on_movies as $key =&gt; $value)
+	$checked_movies[] = (int) $key;
 
-// Get top 250 list
-$result = mysql_query(&quot;SELECT * FROM top250 WHERE $list IS NOT NULL ORDER BY $list &quot;);
-	if(!$result) {
-	   		die ('Can\'t get top movies ' . mysql_error());
-	}
-
-$count = 0;	
-// update BOOL values
-while ($row = mysql_fetch_array($result)) {
-	$imdbid = $row[&quot;imdbid&quot;];
-	if($checked[&quot;$imdbid&quot;] == 'on') {
-		mysql_query(&quot;UPDATE users SET `$imdbid` = 1 WHERE userid = '$userid'&quot;) or
-			die ('Can\'t update '.$row[&quot;title&quot;].' ' . mysql_error());
-		$count += 1;
-	} else {
-		mysql_query(&quot;UPDATE users SET `$imdbid` = 0 WHERE userid = '$userid'&quot;) or
-			die ('Can\'t update '.$row[&quot;title&quot;].' ' . mysql_error());
-	}
+foreach($checked_movies as $movie_id){
+	if(!in_array($movie_id, $previous_movies))
+		$ad-&gt;addUserMovie($user_id, $movie_id);
 }
 
-// calculate percent
-$afifilms = userfilms($db, $con, $userid, 'afi');
-$imdbfilms = userfilms($db, $con, $userid, 'imdb');
-$percent = calculatepercent($imdbfilms, $afifilms);
+foreach($previous_movies as $movie_id){
+	if(!is_null($checked_movies) &amp;&amp; !in_array($movie_id, $checked_movies) &amp;&amp; in_array($movie_id, $list_films))
+		$ad-&gt;deleteUserMovie($user_id, $movie_id);
+}
 
-mysql_query(&quot;UPDATE users SET percent = '$percent' WHERE userid = '$userid'&quot;) or
-		die ('Can\'t update percent ' . mysql_error());
+$ad-&gt;updateUserMovieCount($user_id);
 
-mysql_close(); 
 
 echo '&lt;fb:redirect url=&quot;http://apps.facebook.com/'.$appurl.'?msg=1&quot; /&gt;';
 </diff>
      <filename>updateUser.php</filename>
    </modified>
    <modified>
      <diff>@@ -19,27 +19,20 @@
 	along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
 
-require('config.php');
-require('libfunction.php');
-
-// Use the Facebook platform libraries
-require_once 'facebook.php';
-
-// Create the Facebook application
-$facebook = new Facebook($appapikey, $appsecret);
-$user = $facebook-&gt;require_login();
-
-// Catch the exception that gets thrown if the cookie has an invalid session_key in it
-try {
-	if (!$facebook-&gt;api_client-&gt;users_isAppUser()) {
-		$facebook-&gt;redirect($facebook-&gt;get_add_url());
-	}
-} catch (Exception $ex) {
-	// this will clear cookies for your application and redirect them to a login prompt
-	$facebook-&gt;set_user(null, null);
-	$facebook-&gt;redirect($appcallbackurl);
+require_once 'config.php';
+require_once 'addict_database.php';
+
+$user = $_GET['user'];
+if(preg_match('/\d+/', $user))
+	$user = (int) $user;
+else {
+	echo '&lt;h1 class=&quot;error&quot;&gt;Invalid User ID&lt;/h1&gt;';
+	die();
 }
 
+$ad = new AddictDatabase();
+
+
 /*
 // This page will go into a completley different page, called view
 //If a user is defined in the url, see if that user added the app
@@ -50,55 +43,50 @@ if($facebook-&gt;api_client-&gt;users_isAppUser($_GET['user']) &amp;&amp; isset($_GET['user'])
 }
 */
 
+$list = $_GET['list'];
+if($list == 'afi') {
+	$list = 'afi';
+	$tabvalue = 8;
+	$total = '100';
+	$list_movies = $ad-&gt;getAFIMovies();
+} 
+else {
+	$list = 'imdb';
+	$total = '250';
+	$tabvalue = 9;
+	$list_movies = $ad-&gt;getIMDBMovies();
+}
 
-$user = $_GET['user'];
-if(count($users) &gt; 1)
-	die(&quot;Too many arguments&quot;);
 
-try {
-	$facebook-&gt;api_client-&gt;users_getInfo($user, &quot;name&quot;);
-} catch (Exception $ex) {
-	die(&quot;invalid user id&quot;);
-}
+$user_info = $ad-&gt;getUser($user);
+$user_movies = $ad-&gt;getUserMovies($user);
+$user_count = $user_info['count'];
+$total_count = 274;
+$percent = $user_info['percent'];
 
-//Retrieve data from MySQL, first connecting to the databse
-$con = mysql_connect(&quot;localhost&quot;,$dbuser,$dbpass);
-if (!$con) {
-  die('Could not connect: ' . mysql_error());
-}
-$db_selected = mysql_select_db($db, $con);
-if (!$db_selected) {
-    die ('Can\'t use ' . mysql_error());
-}
+//Determine what message to show
 
-$imdbfilms = userfilms($db, $con, $user, 'imdb');
-$afifilms = userfilms($db, $con, $user, 'imdb');
-$percent = userdata($db, $con, $user);
-$percent = $percent[&quot;percent&quot;];
 
 //Create the pageData object
 $pageData = (object)(array()); 
 
 // Save Information
 $pageData-&gt;css = $cssurl;
-$pageData-&gt;tabs = tabs(2, $appurl);
-$pageData-&gt;userid = $user;
+$pageData-&gt;tabs = $tabvalue;
+$pageData-&gt;appurl =  $appurl;
+$pageData-&gt;msg = $msg;
+$pageData-&gt;userid = (int) $user;
 $pageData-&gt;percent = $percent;
-$pageData-&gt;films = $imdbfilms;
+$pageData-&gt;movielist = $list;
+$pageData-&gt;movies = $list_movies;
+$pageData-&gt;seen_movies = $user_movies;
+$pageData-&gt;moviecount = $user_count;
+$pageData-&gt;totalcount = $total_count;
 
 // Display the Page
 ob_start(); 
-require(&quot;layout_view.php&quot;); 
+require_once(&quot;templates/layout_view.php&quot;); 
 ob_end_flush();
 
 
-// Generate the page fbml
-function generateFbml($percent, $user){
-	$fbml = '&lt;div&gt;&lt;h1 style=&quot;text-align: center; font-size: 32px;&quot;&gt;'.$percent.'%&lt;h3 style=&quot;text-align: center;&quot;&gt;addicited to film&lt;/h3&gt;&lt;a href=&quot;http://apps.facebook.com/'.$appurl.'?user='.$user.'&quot; style=&quot;text-align: center; display: block; margin: 5px;&quot;&gt;See &lt;fb:name uid=&quot;'.$user.'&quot; useyou=false capitalize=&quot;true&quot; possessive=&quot;true&quot; /&gt; list&lt;/a&gt;
-	&lt;a href=&quot;http://apps.facebook.com/'.$appurl.'&quot; style=&quot;text-align: center; display: block; margin: 5px;&quot;&gt;How addicted are you?&lt;/a&gt;';
-	return $fbml;
-}
-
-mysql_close();
-
 ?&gt;
\ No newline at end of file</diff>
      <filename>view.php</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>README.txt</filename>
    </removed>
    <removed>
      <filename>config.php</filename>
    </removed>
    <removed>
      <filename>layout_common.php</filename>
    </removed>
    <removed>
      <filename>layout_friends.php</filename>
    </removed>
    <removed>
      <filename>layout_index.php</filename>
    </removed>
    <removed>
      <filename>layout_view.php</filename>
    </removed>
    <removed>
      <filename>libfunction.php</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>8f5a46280dc53c947c9ef136626bae01b40433b9</id>
    </parent>
  </parents>
  <author>
    <name>Kyle Conroy</name>
    <email>kyle.j.conroy@gmail.com</email>
  </author>
  <url>http://github.com/derferman/movie-addict/commit/0d3b692f06687b56b0af27741ff78537ac9d30f2</url>
  <id>0d3b692f06687b56b0af27741ff78537ac9d30f2</id>
  <committed-date>2009-08-18T23:24:44-07:00</committed-date>
  <authored-date>2009-08-18T23:24:44-07:00</authored-date>
  <message>Movie Addict 2.0 - A whole lot of changes</message>
  <tree>dc13d4b4799295a197333c24d2029d8a4a0d6098</tree>
  <committer>
    <name>Kyle Conroy</name>
    <email>kyle.j.conroy@gmail.com</email>
  </committer>
</commit>
