diff --git a/oss/joomla/trunk/administrator/components/com_poll/controller.php b/oss/joomla/trunk/administrator/components/com_poll/controller.php
new file mode 100644
index 00000000..0f55e85e
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/controller.php
@@ -0,0 +1,223 @@
+registerTask( 'apply', 'save');
+ $this->registerTask( 'unpublish', 'publish');
+ $this->registerTask( 'preview', 'display');
+ $this->registerTask( 'edit', 'display');
+ $this->registerTask( 'add' , 'display' );
+
+ }
+
+ function display( )
+ {
+ switch($this->getTask())
+ {
+ case 'add' :
+ {
+ JRequest::setVar( 'hidemainmenu', 1 );
+ JRequest::setVar( 'layout', 'form' );
+ JRequest::setVar( 'view', 'poll' );
+ JRequest::setVar( 'edit', false );
+ } break;
+ case 'edit' :
+ {
+ JRequest::setVar( 'hidemainmenu', 1 );
+ JRequest::setVar( 'layout', 'form' );
+ JRequest::setVar( 'view', 'poll' );
+ JRequest::setVar( 'edit', true );
+ } break;
+
+ case 'preview' :
+ {
+ JRequest::setVar( 'tmpl', 'component' );
+ JRequest::setVar( 'view', 'poll' );
+ } break;
+ }
+
+ //Set the default view, just in case
+ $view = JRequest::getCmd('view');
+ if(empty($view)) {
+ JRequest::setVar('view', 'polls');
+ };
+
+ parent::display();
+ }
+
+ function save()
+ {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $db =& JFactory::getDBO();
+
+ // save the poll parent information
+ $row =& JTable::getInstance('poll', 'Table');
+ $post = JRequest::get( 'post' );
+ if (!$row->bind( $post ))
+ {
+ JError::raiseError(500, $row->getError() );
+ }
+ $isNew = ($row->id == 0);
+
+ if (!$row->check())
+ {
+ JError::raiseError(500, $row->getError() );
+ }
+
+ if (!$row->store())
+ {
+ JError::raiseError(500, $row->getError() );
+ }
+ $row->checkin();
+ // save the poll options
+ $options = JArrayHelper::getValue( $post, 'polloption', array(), 'array' );
+
+ foreach ($options as $i=>$text)
+ {
+ $text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
+ if ($isNew)
+ {
+ $obj = new stdClass();
+ $obj->pollid = (int)$row->id;
+ $obj->text = $text;
+ $db->insertObject('#__poll_data', $obj);
+ }
+ else
+ {
+ $obj = new stdClass();
+ $obj->id = (int)$i;
+ $obj->text = $text;
+ $db->updateObject('#__poll_data', $obj, 'id');
+ }
+ }
+
+ switch ($this->_task)
+ {
+ case 'apply':
+ $msg = JText::_( 'Changes to Poll saved' );
+ $link = 'index.php?option=com_poll&view=poll&task=edit&cid[]='. $row->id .'';
+ break;
+
+ case 'save':
+ default:
+ $msg = JText::_( 'Poll saved' );
+ $link = 'index.php?option=com_poll';
+ break;
+ }
+
+ $this->setRedirect($link);
+ }
+
+ function remove()
+ {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $db =& JFactory::getDBO();
+ $cid = JRequest::getVar( 'cid', array(), '', 'array' );
+
+ JArrayHelper::toInteger($cid);
+ $msg = '';
+
+ for ($i=0, $n=count($cid); $i < $n; $i++)
+ {
+ $poll =& JTable::getInstance('poll', 'Table');
+ if (!$poll->delete( $cid[$i] ))
+ {
+ $msg .= $poll->getError();
+ }
+ }
+ $this->setRedirect( 'index.php?option=com_poll', $msg );
+ }
+
+ /**
+ * Publishes or Unpublishes one or more records
+ * @param array An array of unique category id numbers
+ * @param integer 0 if unpublishing, 1 if publishing
+ * @param string The current url option
+ */
+ function publish()
+ {
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $db =& JFactory::getDBO();
+ $user =& JFactory::getUser();
+
+ $cid = JRequest::getVar( 'cid', array(), '', 'array' );
+ $publish = ( $this->getTask() == 'publish' ? 1 : 0 );
+
+ JArrayHelper::toInteger($cid);
+
+ if (count( $cid ) < 1)
+ {
+ $action = $publish ? 'publish' : 'unpublish';
+ JError::raiseError(500, JText::_( 'Select an item to' .$action, true ) );
+ }
+
+ $cids = implode( ',', $cid );
+
+ $query = 'UPDATE #__polls'
+ . ' SET published = ' . (int) $publish
+ . ' WHERE id IN ( '. $cids .' )'
+ . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id').' ) )'
+ ;
+ $db->setQuery( $query );
+ if (!$db->query())
+ {
+ JError::raiseError(500, $db->getErrorMsg() );
+ }
+
+ if (count( $cid ) == 1)
+ {
+ $row =& JTable::getInstance('poll', 'Table');
+ $row->checkin( $cid[0] );
+ }
+ $mainframe->redirect( 'index.php?option=com_poll' );
+ }
+
+ function cancel()
+ {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $id = JRequest::getVar( 'id', 0, '', 'int' );
+ $db =& JFactory::getDBO();
+ $row =& JTable::getInstance('poll', 'Table');
+
+ $row->checkin( $id );
+ $this->setRedirect( 'index.php?option=com_poll' );
+ }
+}
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/elements/index.html b/oss/joomla/trunk/administrator/components/com_poll/elements/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/elements/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/elements/poll.php b/oss/joomla/trunk/administrator/components/com_poll/elements/poll.php
new file mode 100644
index 00000000..ba0cb7b0
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/elements/poll.php
@@ -0,0 +1,43 @@
+setQuery( $query );
+ $options = $db->loadObjectList();
+
+ array_unshift($options, JHTML::_('select.option', '0', '- '.JText::_('Select Poll').' -', 'id', 'title'));
+
+ return JHTML::_('select.genericlist', $options, ''.$control_name.'['.$name.']', 'class="inputbox"', 'id', 'title', $value, $control_name.$name );
+ }
+}
diff --git a/oss/joomla/trunk/administrator/components/com_poll/index.html b/oss/joomla/trunk/administrator/components/com_poll/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/poll.php b/oss/joomla/trunk/administrator/components/com_poll/poll.php
new file mode 100644
index 00000000..38213cc6
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/poll.php
@@ -0,0 +1,33 @@
+authorize( 'com_poll', 'manage' )) {
+ $mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
+}
+
+require_once( JPATH_COMPONENT.DS.'controller.php' );
+
+// Set the table directory
+JTable::addIncludePath( JPATH_COMPONENT.DS.'tables' );
+
+// Create the controller
+$controller = new PollController( );
+
+$controller->execute( JRequest::getCmd( 'task' ) );
+$controller->redirect();
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/poll.xml b/oss/joomla/trunk/administrator/components/com_poll/poll.xml
new file mode 100644
index 00000000..479c9019
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/poll.xml
@@ -0,0 +1,12 @@
+
+
+ Polls
+ Joomla! Project
+ July 2004
+ Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
+ http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
+ admin@joomla.org
+ www.joomla.org
+ 1.5.0
+ This component manages polls
+
diff --git a/oss/joomla/trunk/administrator/components/com_poll/tables/index.html b/oss/joomla/trunk/administrator/components/com_poll/tables/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/tables/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/tables/poll.php b/oss/joomla/trunk/administrator/components/com_poll/tables/poll.php
new file mode 100644
index 00000000..350a029f
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/tables/poll.php
@@ -0,0 +1,138 @@
+id = (int) $this->id;
+
+ return $result;
+ }
+
+ /**
+ * Overloaded check function
+ *
+ * @access public
+ * @return boolean
+ * @see JTable::check
+ * @since 1.5
+ */
+ function check()
+ {
+ // check for valid name
+ if (trim( $this->title ) == '')
+ {
+ $this->setError(JText::_( 'Your Poll must contain a title.' ));
+ return false;
+ }
+ // check for valid lag
+ $this->lag = intval( $this->lag );
+ if ($this->lag == 0) {
+ $this->setError(JText::_( 'Your Poll must have a non-zero lag time.' ));
+ return false;
+ }
+
+ if(empty($this->alias)) {
+ $this->alias = $this->title;
+ }
+ $this->alias = JFilterOutput::stringURLSafe($this->alias);
+ if(trim(str_replace('-','',$this->alias)) == '') {
+ $datenow =& JFactory::getDate();
+ $this->alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
+ }
+
+ return true;
+ }
+
+ // overloaded delete function
+ function delete( $oid=null )
+ {
+ $k = $this->_tbl_key;
+ if ( $oid ) {
+ $this->$k = intval( $oid );
+ }
+
+ if ( parent::delete( $oid ))
+ {
+ $query = 'DELETE FROM #__poll_data'
+ . ' WHERE pollid = '.(int) $this->$k
+ ;
+ $this->_db->setQuery( $query );
+ if ( !$this->_db->query() ) {
+ $this->_error .= $this->_db->getErrorMsg() . "\n";
+ }
+
+ $query = 'DELETE FROM #__poll_date'
+ . ' WHERE poll_id = '.(int) $this->$k
+ ;
+ $this->_db->setQuery( $query );
+ if ( !$this->_db->query() ) {
+ $this->_error .= $this->_db->getErrorMsg() . "\n";
+ }
+
+ $query = 'DELETE from #__poll_menu'
+ . ' WHERE pollid = '.(int) $this->$k
+ ;
+ $this->_db->setQuery( $query );
+ if ( !$this->_db->query() ) {
+ $this->_error .= $this->_db->getErrorMsg() . "\n";
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/index.html b/oss/joomla/trunk/administrator/components/com_poll/views/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/poll/index.html b/oss/joomla/trunk/administrator/components/com_poll/views/poll/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/poll/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/poll/tmpl/default.php b/oss/joomla/trunk/administrator/components/com_poll/views/poll/tmpl/default.php
new file mode 100644
index 00000000..4ec1a679
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/poll/tmpl/default.php
@@ -0,0 +1,22 @@
+
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/poll/tmpl/form.php b/oss/joomla/trunk/administrator/components/com_poll/views/poll/tmpl/form.php
new file mode 100644
index 00000000..07593654
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/poll/tmpl/form.php
@@ -0,0 +1,133 @@
+
+
+[ ' . $text.' ]' );
+ JToolBarHelper::Preview('index.php?option=com_poll&controller=poll&cid[]='.$cid[0]);
+ JToolBarHelper::save();
+ JToolBarHelper::apply();
+ if ($edit) {
+ // for existing items the button is renamed `close`
+ JToolBarHelper::cancel( 'cancel', 'Close' );
+ } else {
+ JToolBarHelper::cancel();
+ }
+ JToolBarHelper::help( 'screen.polls.edit' );
+?>
+
+poll, ENT_QUOTES );
+?>
+
+
+
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/poll/tmpl/index.html b/oss/joomla/trunk/administrator/components/com_poll/views/poll/tmpl/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/poll/tmpl/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/poll/view.html.php b/oss/joomla/trunk/administrator/components/com_poll/views/poll/view.html.php
new file mode 100644
index 00000000..415c9154
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/poll/view.html.php
@@ -0,0 +1,83 @@
+load( $uid );
+
+ // fail if checked out not by 'me'
+ if ($poll->isCheckedOut( $user->get('id') )) {
+ $msg = JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The poll' ), $poll->title );
+ $this->setRedirect( 'index.php?option='. $option, $msg );
+ }
+
+ if ($poll->id == 0)
+ {
+ // defaults
+ $row->published = 1;
+ }
+
+ $options = array();
+
+ if ($edit)
+ {
+ $poll->checkout( $user->get('id') );
+ $query = 'SELECT id, text'
+ . ' FROM #__poll_data'
+ . ' WHERE pollid = '.(int) $uid
+ . ' ORDER BY id'
+ ;
+ $db->setQuery($query);
+ $options = $db->loadObjectList();
+ }
+ else
+ {
+ $poll->lag = 3600*24;
+ }
+
+ $this->assignRef('poll', $poll);
+ $this->assignRef('options', $options);
+
+ parent::display($tpl);
+
+ }
+}
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/polls/index.html b/oss/joomla/trunk/administrator/components/com_poll/views/polls/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/polls/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/polls/tmpl/default.php b/oss/joomla/trunk/administrator/components/com_poll/views/polls/tmpl/default.php
new file mode 100644
index 00000000..de81a361
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/polls/tmpl/default.php
@@ -0,0 +1,127 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/polls/tmpl/index.html b/oss/joomla/trunk/administrator/components/com_poll/views/polls/tmpl/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/polls/tmpl/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_poll/views/polls/view.html.php b/oss/joomla/trunk/administrator/components/com_poll/views/polls/view.html.php
new file mode 100644
index 00000000..be9169c9
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_poll/views/polls/view.html.php
@@ -0,0 +1,109 @@
+getUserStateFromRequest( "$option.filter_order", 'filter_order', 'm.id', 'cmd' );
+ $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir", 'filter_order_Dir', '', 'word' );
+ $filter_state = $mainframe->getUserStateFromRequest( "$option.filter_state", 'filter_state', '', 'word' );
+ $search = $mainframe->getUserStateFromRequest( "$option.search", 'search', '', 'string' );
+ $search = JString::strtolower( $search );
+
+ $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
+ $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
+
+ $where = array();
+
+ if ( $filter_state )
+ {
+ if ( $filter_state == 'P' )
+ {
+ $where[] = 'm.published = 1';
+ }
+ else if ($filter_state == 'U' )
+ {
+ $where[] = 'm.published = 0';
+ }
+ }
+ if ($search)
+ {
+ $where[] = 'LOWER(m.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
+ }
+
+ $where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
+ $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir;
+
+ $query = 'SELECT COUNT(m.id)'
+ . ' FROM #__polls AS m'
+ . $where
+ ;
+ $db->setQuery( $query );
+ $total = $db->loadResult();
+
+ jimport('joomla.html.pagination');
+ $pagination = new JPagination( $total, $limitstart, $limit );
+
+ $query = 'SELECT m.*, u.name AS editor, COUNT(d.id) AS numoptions'
+ . ' FROM #__polls AS m'
+ . ' LEFT JOIN #__users AS u ON u.id = m.checked_out'
+ . ' LEFT JOIN #__poll_data AS d ON d.pollid = m.id AND d.text <> ""'
+ . $where
+ . ' GROUP BY m.id'
+ . $orderby
+ ;
+ $db->setQuery( $query, $pagination->limitstart, $pagination->limit );
+ $rows = $db->loadObjectList();
+
+ if ($db->getErrorNum())
+ {
+ echo $db->stderr();
+ return false;
+ }
+
+ // state filter
+ $lists['state'] = JHTML::_('grid.state', $filter_state );
+
+ // table ordering
+ $lists['order_Dir'] = $filter_order_Dir;
+ $lists['order'] = $filter_order;
+
+ // search filter
+ $lists['search']= $search;
+
+ $this->assignRef('user', JFactory::getUser());
+ $this->assignRef('lists', $lists);
+ $this->assignRef('items', $rows);
+ $this->assignRef('pagination', $pagination);
+
+ parent::display($tpl);
+ }
+}
\ No newline at end of file