Index: nodecarousel.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodecarousel/nodecarousel.install,v
retrieving revision 1.4.2.1
diff -u -r1.4.2.1 nodecarousel.install
--- nodecarousel.install	1 Feb 2008 20:34:07 -0000	1.4.2.1
+++ nodecarousel.install	1 Feb 2008 20:49:26 -0000
@@ -1,79 +1,87 @@
-<?php
-// $Id: nodecarousel.install,v 1.4.2.1 2008/02/01 20:34:07 jcfiala Exp $
-
-/**
- * Implmentation of hook_install().
- */
-function nodecarousel_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("CREATE TABLE {nodecarousel} (
-        ncid int unsigned NOT NULL default '0',
-        name varchar(32) NOT NULL,
-        title varchar(255) default NULL,
-        description varchar(255) default NULL,
-        access varchar(255) default NULL,
-        dynamic int(1) NOT NULL default '0',
-        horizontal int(1) NOT NULL default '1',
-        wrap varchar(8) NOT NULL default '0',
-        autoscroll int(2) NOT NULL default '0',
-        index_control char(3) NOT NULL default '',
-        number_fetch int(10) NOT NULL default '1',
-        number_scroll int(10) NOT NULL default '1',
-        number_visible int(10) NOT NULL default '3',
-        start_position int(10) NOT NULL default '1',
-        animation_speed varchar(5) NOT NULL default 'slow',
-        prev_text varchar(255) default NULL,
-        next_text varchar(255) default NULL,
-        first_text varchar(255) default NULL,
-        last_text varchar(255) default NULL,
-        node_source int(4) NOT NULL default '0',
-        node_types varchar(255) default NULL,
-        taxonomy_tids varchar(255) default NULL,
-        nodequeue_qid int(10) unsigned NULL,
-        sort varchar(255) default NULL,
-        sort_ascending int(1) NOT NULL default '0',
-        js_scroll_function longtext default NULL,
-        PRIMARY KEY (ncid),
-        KEY name (name)
-      ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
-      break;
-    case 'pgsql':
-      db_query("CREATE TABLE {nodecarousel} (
-        ncid int_unsigned NOT NULL default '0',
-        name varchar(32) NOT NULL,
-        title varchar(255) default NULL,
-        description varchar(255) default NULL,
-        access varchar(255) default NULL,
-        dynamic smallint NOT NULL default '0',
-        horizontal smallint NOT NULL default '1',
-        wrap varchar(8) NOT NULL default '0',
-        autoscroll smallint NOT NULL default '0',
-        index_control char(3) NOT NULL default '',
-        number_fetch int(10) NOT NULL default '1',
-        number_scroll int(10) NOT NULL default '1',
-        number_visible int(10) NOT NULL default '3',
-        start_position int(10) NOT NULL default '1',
-        animation_speed varchar(5) NOT NULL default 'slow',
-        prev_text varchar(255) default NULL,
-        next_text varchar(255) default NULL,
-        first_text varchar(255) default NULL,
-        last_text varchar(255) default NULL,
-        node_source int NOT NULL default '0',
-        node_types varchar(255) default NULL,
-        taxonomy_vids varchar(255) default NULL,
-        nodequeue_qid integer unsigned default NULL,
-        sort varchar(255) default NULL,
-        sort_ascending NOT NULL smallint default '0',
-        js_scroll_function text default NULL,
-        PRIMARY KEY (ncid),
-      ");
-      db_query("CREATE INDEX {nodecarousel}_name_idx ON {nodecarousel} (name)");
-      break;
-  }
-}
-
-function nodecarousel_uninstall() {
-  db_query("DROP TABLE {nodecarousel}");
+<?php
+// $Id: nodecarousel.install,v 1.4.2.1 2008/02/01 20:34:07 jcfiala Exp $
+
+/**
+ * Implmentation of hook_install().
+ */
+function nodecarousel_install() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      db_query("CREATE TABLE {nodecarousel} (
+        ncid int unsigned NOT NULL default '0',
+        name varchar(32) NOT NULL,
+        title varchar(255) default NULL,
+        description varchar(255) default NULL,
+        access varchar(255) default NULL,
+        dynamic int(1) NOT NULL default '0',
+        horizontal int(1) NOT NULL default '1',
+        wrap varchar(8) NOT NULL default '0',
+        autoscroll int(2) NOT NULL default '0',
+        index_control char(3) NOT NULL default '',
+        number_fetch int(10) NOT NULL default '1',
+        number_scroll int(10) NOT NULL default '1',
+        number_visible int(10) NOT NULL default '3',
+        start_position int(10) NOT NULL default '1',
+        animation_speed varchar(5) NOT NULL default 'slow',
+        prev_text varchar(255) default NULL,
+        next_text varchar(255) default NULL,
+        first_text varchar(255) default NULL,
+        last_text varchar(255) default NULL,
+        node_source int(4) NOT NULL default '0',
+        node_types varchar(255) default NULL,
+        taxonomy_tids varchar(255) default NULL,
+        nodequeue_qid int(10) unsigned NULL,
+        sort varchar(255) default NULL,
+        sort_ascending int(1) NOT NULL default '0',
+        js_scroll_function longtext default NULL,
+        view_vid int(10) NOT NULL default '0',
+        PRIMARY KEY (ncid),
+        KEY name (name)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
+      break;
+    case 'pgsql':
+      db_query("CREATE TABLE {nodecarousel} (
+        ncid int_unsigned NOT NULL default '0',
+        name varchar(32) NOT NULL,
+        title varchar(255) default NULL,
+        description varchar(255) default NULL,
+        access varchar(255) default NULL,
+        dynamic smallint NOT NULL default '0',
+        horizontal smallint NOT NULL default '1',
+        wrap varchar(8) NOT NULL default '0',
+        autoscroll smallint NOT NULL default '0',
+        index_control char(3) NOT NULL default '',
+        number_fetch int(10) NOT NULL default '1',
+        number_scroll int(10) NOT NULL default '1',
+        number_visible int(10) NOT NULL default '3',
+        start_position int(10) NOT NULL default '1',
+        animation_speed varchar(5) NOT NULL default 'slow',
+        prev_text varchar(255) default NULL,
+        next_text varchar(255) default NULL,
+        first_text varchar(255) default NULL,
+        last_text varchar(255) default NULL,
+        node_source int NOT NULL default '0',
+        node_types varchar(255) default NULL,
+        taxonomy_vids varchar(255) default NULL,
+        nodequeue_qid integer unsigned default NULL,
+        sort varchar(255) default NULL,
+        sort_ascending NOT NULL smallint default '0',
+        js_scroll_function text default NULL,
+        view_vid int(10) NOT NULL default '0',
+        PRIMARY KEY (ncid),
+      ");
+      db_query("CREATE INDEX {nodecarousel}_name_idx ON {nodecarousel} (name)");
+      break;
+  }
+}
+
+function nodecarousel_uninstall() {
+  db_query("DROP TABLE {nodecarousel}");
+}
+
+function nodecarousel_update_1() {
+  $ret = array();
+  db_query("ALTER TABLE {nodecarousel} ADD view_vid INT(10) NOT NULL default '0'");
+  return $ret;
 }
\ No newline at end of file
Index: nodecarousel.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodecarousel/nodecarousel.module,v
retrieving revision 1.4.2.1
diff -u -r1.4.2.1 nodecarousel.module
--- nodecarousel.module	1 Feb 2008 20:34:07 -0000	1.4.2.1
+++ nodecarousel.module	1 Feb 2008 21:37:09 -0000
@@ -11,6 +11,7 @@
 DEFINE("NC_SOURCE_NODE_AND_TAXONOMY", 1);
 DEFINE("NC_SOURCE_NODEQUEUE", 2);
 DEFINE("NC_SOURCE_HOOK", 3);
+DEFINE("NC_SOURCE_VIEW", 4);
 DEFINE("NC_INDEX_TITLE", 'ttl');
 DEFINE("NC_INDEX_NUMBER", 'num');
 DEFINE("NC_INDEX_THEME", 'thm');
@@ -164,16 +165,10 @@
  */
 function nodecarousel_load($carousel_name) {
   if (is_numeric($carousel_name)) {
-    $query = "SELECT ncid, name, title, description, access,
-     dynamic, horizontal, wrap, autoscroll, index_control, number_fetch, number_scroll, number_visible, start_position,
-      animation_speed, prev_text, next_text, first_text, last_text, node_source, node_types, taxonomy_tids, nodequeue_qid,
-      sort, sort_ascending, js_scroll_function FROM {nodecarousel} where ncid = %d";
+    $query = "SELECT * FROM {nodecarousel} where ncid = %d";
   }
   else {
-    $query = "SELECT ncid, name, title, description, access,
-      dynamic, horizontal, wrap, autoscroll, index_control, number_fetch, number_scroll, number_visible, start_position,
-      animation_speed, prev_text, next_text, first_text, last_text, node_source, node_types, taxonomy_tids, nodequeue_qid,
-      sort, sort_ascending, js_scroll_function FROM {nodecarousel} where name = '%s'";
+    $query = "SELECT * FROM {nodecarousel} where name = '%s'";
   }
   $result = db_query($query, $carousel_name);
 
@@ -440,6 +435,9 @@
     $sources = array(NC_SOURCE_NODE_AND_TAXONOMY => t('Node type / Taxonomy'),
       NC_SOURCE_HOOK => t('hook_nodecarousel()'));
   }
+  if (module_exists('views')) {
+    $sources[NC_SOURCE_VIEW] = t('View'); 
+  }
 
   $form['node-source']['node_source'] = array(
     '#type' => 'radios',
@@ -476,6 +474,24 @@
     '#size' => 8,
     '#description' => t('Select any taxonomies which the nodes to display should be restricted by.  If you do not want to restrict based on taxonomy, select nothing'),
   );
+  
+  if (module_exists('views')) {
+    $views = array();
+    $query = 'SELECT vid, name FROM {view_view} ORDER BY name';
+    $result = db_query($query);
+    while ($view = db_fetch_object($result)) {
+      $views[$view->vid] = $view->name;
+    }
+    $form['node-source']['view_vid'] = array(
+      '#type' => 'select',
+      '#title' => t('View'),
+      '#default_value' => $node_carousel->view_vid,
+      '#options' => $views,
+      '#multiple' => FALSE,
+      '#size' => 8,
+      '#description' => t('Choose which view to display in the node carousel.'),
+    );
+  }
 
   if (module_exists('nodequeue')) {
     $nodequeues = array();
@@ -726,37 +742,33 @@
     }
   }
 
-  if ($form_values['node_source'] != NC_SOURCE_NODE_AND_TAXONOMY && $form_values['node_source'] != NC_SOURCE_NODEQUEUE && $form_values['node_source'] != NC_SOURCE_HOOK) {
-    form_set_error('node_source', t('Must choose a Node Source!'));
-  }
-  else {
-    switch ($form_values['node_source']) {
-      case NC_SOURCE_NODE_AND_TAXONOMY:
-        // Verify nodes are nodes and taxonomies are taxonomies.
-        //drupal_set_message('node_types: '. print_r($form_values['node_types'], true));
-        $problem_nodes = _nodecarousel_validate_node_types($form_values['node_types']);
-        if (count($problem_nodes)) {
-          form_set_error('node_types', t('Node type(s) %s does not exist.', implode(',', $problem_nodes)));
-        }
+  // Validation for selection boxes are already done by Drupal's Form API.
+  switch ($form_values['node_source']) {
+    case NC_SOURCE_NODE_AND_TAXONOMY:
+      // Verify nodes are nodes and taxonomies are taxonomies.
+      //drupal_set_message('node_types: '. print_r($form_values['node_types'], true));
+      $problem_nodes = _nodecarousel_validate_node_types($form_values['node_types']);
+      if (count($problem_nodes)) {
+        form_set_error('node_types', t('Node type(s) %s does not exist.', implode(',', $problem_nodes)));
+      }
 
-        if (!_nodecarousel_validate_taxonomy($form_values['taxonomy_tids'])) {
-          form_set_error('taxonomy_tids', t('You have selected taxonomy terms that do not exist.'));
-        }
-        break;
-      case NC_SOURCE_NODEQUEUE:
-        if (module_exists('nodequeue')) {
-          // Verify selected nodequeue is a nodequeue.
-          $query = "SELECT qid FROM {nodequeue_queue} WHERE qid = %d";
-          $result = db_query($query, $form_values['nodequeue_qid']);
-          if (!db_fetch_object($result)) {
-            form_set_error('nodequeue_qid', t('You must select a nodequeue if the Data Source is nodequeue.'));
-          }
+      if (!_nodecarousel_validate_taxonomy($form_values['taxonomy_tids'])) {
+        form_set_error('taxonomy_tids', t('You have selected taxonomy terms that do not exist.'));
+      }
+      break;
+    case NC_SOURCE_NODEQUEUE:
+      if (module_exists('nodequeue')) {
+        // Verify selected nodequeue is a nodequeue.
+        $query = "SELECT qid FROM {nodequeue_queue} WHERE qid = %d";
+        $result = db_query($query, $form_values['nodequeue_qid']);
+        if (!db_fetch_object($result)) {
+          form_set_error('nodequeue_qid', t('You must select a nodequeue if the Data Source is nodequeue.'));
         }
-        break;
-      case NC_SOURCE_HOOK:
-        // No verification needed.
-        break;
-    }
+      }
+      break;
+    case NC_SOURCE_HOOK:
+      // No verification needed.
+      break;
   }
 
   if (!_nodecarousel_validate_on_off($form_values['dynamic'])) {
@@ -1016,17 +1028,17 @@
   $query = "INSERT INTO {nodecarousel} (ncid, name, title, description, access,
     dynamic, horizontal, wrap, autoscroll, index_control, number_fetch, number_scroll, number_visible, start_position,
     animation_speed, prev_text, next_text, first_text, last_text, node_source, node_types, taxonomy_tids, nodequeue_qid,
-    sort, sort_ascending, js_scroll_function)
+    sort, sort_ascending, js_scroll_function, view_vid)
   VALUES (%d, '%s', '%s', '%s', '%s',
     %d, %d, '%s', %d, '%s', %d, %d, %d, %d,
     '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', %d,
-    '%s', %d, '%s')";
+    '%s', %d, '%s', %d)";
 
   //drupal_set_message('queue: '. print_r($form_values['nodequeue_qid'], true));
   $result = db_query($query, $form_values['ncid'], $form_values['name'], $form_values['title'], $form_values['description'], serialize($access),
     $form_values['dynamic'], $form_values['horizontal'], $form_values['wrap'], $form_values['autoscroll'], $form_values['index_control'], $form_values['number_fetch'], $form_values['number_scroll'], $form_values['number_visible'], $form_values['start_position'],
     $form_values['animation_speed'], $form_values['prev_text'], $form_values['next_text'], $form_values['first_text'], $form_values['last_text'], $form_values['node_source'], serialize($node_types), serialize(array_keys($form_values['taxonomy_tids'])), $form_values['nodequeue_qid'],
-    $form_values['sort'], $form_values['sort_ascending'], $form_values['js_scroll_function'] );
+    $form_values['sort'], $form_values['sort_ascending'], $form_values['js_scroll_function'], $form_values['view_vid'] );
   return 'admin/build/nodecarousel';
 }
 
@@ -1203,6 +1215,22 @@
         }
       }
       break;
+     
+    case NC_SOURCE_VIEW:
+      if (module_exists('views')) {
+        $view = views_get_view($nc->view_vid);
+        if ($view) {
+          $items = views_build_view('items', $view);
+          $pos = $start_position;
+          $total = count($items['items']);
+          foreach ($items['items'] as $item) {
+            $node_array[] = node_load($item->nid);//$item;//
+            $node_array[count($node_array) -1]->nc_position = ++$pos;
+            $node_array[count($node_array) -1]->nc_total = intval($total);
+          }
+        }
+      }
+      break;
 
     case NC_SOURCE_HOOK:
       $node_array = module_invoke_all('nodecarousel', $nc->name, $start_position, $nc->number_fetch, $nid);

