diff --git a/oss/joomla/trunk/administrator/components/com_apoll/apoll.php b/oss/joomla/trunk/administrator/components/com_apoll/apoll.php
new file mode 100644
index 00000000..290c9f2b
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/apoll.php
@@ -0,0 +1,40 @@
+execute( JRequest::getCmd( 'task' ) );
+$controller->redirect();
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/config.xml b/oss/joomla/trunk/administrator/components/com_apoll/config.xml
new file mode 100644
index 00000000..3d21a34d
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/config.xml
@@ -0,0 +1,105 @@
+
+
+
+
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+
+ Yes
+ NO
+
+
+
+ Yes
+ NO
+
+
+
+ Yes
+ NO
+
+
+
+
+
+ JOOMLA DEFAULT WAY
+ PIE CHART
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+ BOUNCE
+ FADE
+
+
+
+
+ LEFT
+ CENTER
+ RIGHT
+
+
+ TOP
+ MIDDLE
+ BOTTOM
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/controller.php b/oss/joomla/trunk/administrator/components/com_apoll/controller.php
new file mode 100644
index 00000000..a87886cc
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/controller.php
@@ -0,0 +1,341 @@
+registerTask( 'apply', 'save');
+ $this->registerTask( 'unpublish', 'publish');
+ $this->registerTask( 'preview', 'display');
+ $this->registerTask( 'edit', 'display');
+ $this->registerTask( 'add' , 'display');
+ $this->registerTask( 'deleteVotes', 'deleteVotes');
+ $this->registerTask( 'saveConfig', 'saveConfig');
+ $this->registerTask( 'importPolls', 'importPolls');
+ $this->registerTask( 'installJoomfishFiles', 'installJoomfishFiles');
+ }
+
+ function display( )
+ {
+ switch($this->getTask())
+ {
+ case 'add' :
+ {
+ JRequest::setVar( 'hidemainmenu', 1 );
+ JRequest::setVar( 'layout', 'form' );
+ JRequest::setVar( 'view', 'apoll' );
+ JRequest::setVar( 'edit', false );
+ } break;
+ case 'edit' :
+ {
+ JRequest::setVar( 'hidemainmenu', 1 );
+ JRequest::setVar( 'layout', 'form' );
+ JRequest::setVar( 'view', 'apoll' );
+ JRequest::setVar( 'edit', true );
+ } break;
+
+ case 'preview' :
+ {
+ JRequest::setVar( 'tmpl', 'component' );
+ JRequest::setVar( 'view', 'apoll' );
+ } break;
+ }
+
+ //Set the default view, just in case
+ $view = JRequest::getCmd('view');
+ if(empty($view)) {
+ JRequest::setVar('view', 'apolls');
+ };
+
+ parent::display();
+ }
+
+ function save()
+ {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $db =& JFactory::getDBO();
+
+ // save the apoll parent information
+ $row =& JTable::getInstance('apoll', 'Table');
+ $post = JRequest::get( 'post' );
+ if (!$row->bind( $post ))
+ {
+ JError::raiseError(500, $row->getError() );
+ }
+ $isNew = ($row->id == 0);
+
+ //reset the poll, erases hits and voters
+ if($optionReset = JRequest::getVar('reset')) {
+ $model =& $this->getModel('apolls');
+ $model->resetVotes((int)$row->id);
+ }
+
+ if (!$row->check())
+ {
+ JError::raiseError(500, $row->getError() );
+ }
+
+ if (!$row->store())
+ {
+ JError::raiseError(500, $row->getError() );
+ }
+ $row->checkin();
+
+ // put all apoll options and their colors and ordering in arrays
+ $options = JArrayHelper::getValue( $post, 'apolloption', array(), 'array' );
+ $colors = JArrayHelper::getValue( $post, 'color', array(), 'array' );
+ $orderings = JArrayHelper::getValue( $post, 'ordering', array(), 'array' );
+
+ //options represented by id=>text
+ foreach ($options as $i=>$text)
+ {
+
+ // turns ' into '
+ $text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
+
+ if ($isNew)
+ {
+ if($text!=''){
+ $obj = new stdClass();
+ $obj->apoll_id = (int)$row->id;
+ $obj->text = $text;
+ $obj->color = substr($colors[$i], -6);
+ $obj->ordering = $orderings[$i];
+ $db->insertObject('#__apoll_options', $obj);
+ }
+ }
+ else
+ {
+ if($text!=''){
+ $obj = new stdClass();
+ $obj->id = (int)$i;
+ $obj->text = $text;
+ $obj->color = substr($colors[$i], -6);
+ $obj->ordering = $orderings[$i];
+ $db->updateObject('#__apoll_options', $obj, 'id');
+ } else {
+
+ //If there are empty options delete them so we don't waste database space
+ $model =& $this->getModel('apoll');
+ if(!$model->deleteOption($i)) {
+ JError::raiseError(500, $model->getError() );
+ }
+ }
+ }
+
+ }
+ //Are there any new options that are added
+ if (JRequest::getVar('is_there_extra')) {
+ $extra_options = JArrayHelper::getValue( $post, 'apolloptionextra', array(), 'array' );
+ $extra_ordering = JArrayHelper::getValue( $post, 'extra_ordering', array(), 'array' );
+ $extra_colors = JArrayHelper::getValue( $post, 'extra_colors', array(), 'array' );
+
+ //Insert in the database the newly created options
+ foreach ($extra_options as $k=>$text)
+ {
+ if($text!=""){
+ $obj = new stdClass();
+ $obj->apoll_id = (int)$row->id;
+ $obj->text = $text;
+ $obj->color = substr($extra_colors[$k], -6);
+ $obj->ordering = $extra_ordering[$k];
+ $db->insertObject('#__apoll_options', $obj);
+ }
+ }
+ }
+ switch ($this->_task)
+ {
+ case 'apply':
+ $msg = JText::_( 'Changes to Poll saved' );
+ $link = 'index.php?option=com_apoll&view=apoll&task=edit&cid[]='.$row->id .'';
+ break;
+
+ case 'save':
+ default:
+ $msg = JText::_( 'Poll saved' );
+ $link = 'index.php?option=com_apoll';
+ break;
+ }
+
+ $this->setRedirect($link, $msg);
+ }
+
+ 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++)
+ {
+ $apoll =& JTable::getInstance('apoll', 'Table');
+ if (!$apoll->delete( $cid[$i] ))
+ {
+ $msg .= $apoll->getError();
+ $tom = "error";
+ } else {
+ $msg = JTEXT::_('Poll successfully deleted');
+ $tom = "";
+ }
+ }
+ $this->setRedirect('index.php?option=com_apoll', $msg, $tom);
+ }
+
+ function deleteVotes()
+ {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+ $apoll_id = JRequest::getVar('apoll_id', 0, 'POST', 'INT');
+ $model =& $this->getModel('votes');
+
+ if($model->deleteVotes()) {
+ $msg = Jtext::_("The selected votes were successfuly deleted!");
+ $tom = "";
+ } else {
+ $msg = Jtext::_("The selected votes could not be deleted!");
+ $tom = "error";
+ }
+ $this->setRedirect('index.php?option=com_apoll&task=view&view=votes&id='.$apoll_id, $msg, $tom);
+ }
+
+ /**
+ * 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' );
+
+ $user =& JFactory::getUser();
+
+ $cid = JRequest::getVar( 'cid', array(), '', 'array' );
+ $publish = ( $this->getTask() == 'publish' ? 1 : 0 );
+ $table =& JTable::getInstance('apoll', 'Table');
+ JArrayHelper::toInteger($cid);
+
+ if(!$table->publish($cid, $publish, $user->get('id'))) {
+ $table->getError();
+ }
+
+ if (count( $cid ) < 1)
+ {
+ $action = $publish ? 'publish' : 'unpublish';
+ JError::raiseError(500, JText::_( 'Select an item to' .$action, true ) );
+ }
+
+ $mainframe->redirect( 'index.php?option=com_apoll' );
+ }
+
+ function cancel()
+ {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $id = JRequest::getVar( 'id', 0, '', 'int' );
+ $db =& JFactory::getDBO();
+ $row =& JTable::getInstance('apoll', 'Table');
+
+ $row->checkin( $id );
+ $this->setRedirect( 'index.php?option=com_apoll' );
+ }
+
+
+ //Function to delete all votes from selected polls
+ function resetVotes() {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+ $model =& $this->getModel('apolls');
+ if($model->resetVotes()) {
+ $msg = Jtext::_("Votes for this poll were successfuly deleted!");
+ $tom = "";
+ } else {
+ $msg = Jtext::_("Votes for this poll could not be deleted!");
+ $tom = "error";
+ }
+ $this->setRedirect( 'index.php?option=com_apoll&view=apolls', $msg, $tom );
+ }
+
+
+ //Function to save the configuration settings
+ function saveConfig() {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+ $model =& $this->getModel('config');
+
+ if (!$model->save()) {
+ $msg = JText::_("Apoll configuration could not be saved!");
+ $tom = "error";
+ } else {
+ $msg = JText::_("Apoll configuration successfully saved!");
+ $tom = "";
+ }
+ $this->setRedirect('index.php?option=com_apoll&task=view&view=config',$msg , $tom );
+ }
+
+ //Function to import polls from native joomla poll component
+ function importPolls() {
+ $model =& $this->getModel('config');
+
+ if (!$model->import()) {
+ $msg = JText::_("Polls could not be imported!");
+ $tom = "error";
+ } else {
+ $msg = JText::_("Polls were successfuly imported!");
+ $tom = "";
+ }
+ $this->setRedirect('index.php?option=com_apoll&task=view&view=config',$msg, $tom );
+ }
+
+ function installJoomfishFiles() {
+ $model =& $this->getModel('config');
+
+ if ($model->copyJoomfishFiles()) {
+ $msg = JText::_("Apoll files for Joomfish! were installed!");
+ $tom = "";
+ } else {
+ $msg = JText::_("Apoll files for Joomfish! were not installed!");
+ $tom = "error";
+ }
+ $this->setRedirect('index.php?option=com_apoll&task=view&view=config',$msg, $tom );
+ }
+}
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/elements/apoll.php b/oss/joomla/trunk/administrator/components/com_apoll/elements/apoll.php
new file mode 100644
index 00000000..edc44dd4
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/elements/apoll.php
@@ -0,0 +1,46 @@
+nameQuote("#__apoll_polls") . ' AS a'
+ . ' WHERE a.published = 1'
+ . ' ORDER BY a.title'
+ ;
+ $db->setQuery( $query );
+ $options = $db->loadObjectList();
+
+ if(JRequest::getCmd('option') == "com_modules") {
+ array_unshift($options, JHTML::_('select.option', '', '- - - - - - - - - - -', 'id', 'title'));
+ array_unshift($options, JHTML::_('select.option', '0', JText::_('Show random poll'), 'id', 'title'));
+ } else {
+ 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_apoll/index.html b/oss/joomla/trunk/administrator/components/com_apoll/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/install.apoll.php b/oss/joomla/trunk/administrator/components/com_apoll/install.apoll.php
new file mode 100644
index 00000000..c3a25f36
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/install.apoll.php
@@ -0,0 +1,134 @@
+getPrefix().'apolls', $db->getTableList())) {
+
+ //import the apolls table
+ $query = "INSERT INTO " . $db->nameQuote('#__apoll_polls') . " (id, title, alias, checked_out, checked_out_time, published, params, access, lag) SELECT id, title, alias, checked_out, checked_out_time, 0, params, access, lag/60 FROM " . $db->nameQuote('#__apolls') . ";";
+
+ $db->setQuery($query);
+ if(!$db->query()) {
+ $msg .= " ".$db->getErrorMsg();
+ } else {
+ $msg .= " ".JText::_('Polls from version 1.2 successfully imported')." ";
+ }
+
+
+ //copy the options table
+ $query = "INSERT INTO " . $db->nameQuote('#__apoll_options') . " (id, apoll_id, text, color, ordering) SELECT id, apollid, text, color, ordering FROM " . $db->nameQuote('#__apoll_data') . " WHERE text <> '';";
+
+ $db->setQuery( $query );
+ if(!$db->query()) {
+ $msg .= " ".$db->getErrorMsg();
+ } else {
+ $msg .= " ".JText::_('Poll options from version 1.2 successfully imported')." ";
+ }
+
+ //copy the votes table
+ $query = "INSERT INTO " . $db->nameQuote('#__apoll_votes') . " (id, date, option_id, apoll_id) SELECT id, date, vote_id, apoll_id FROM " . $db->nameQuote('#__apoll_date') . ";";
+
+ $db->setQuery( $query );
+ if(!$db->query()) {
+ $msg .= " ".$db->getErrorMsg();
+ } else {
+ $msg .= " ".JText::_('Recorded votes from version 1.2 successfully imported')." ";
+ }
+
+ // Find out Apoll component unique id
+ $query = "SELECT id FROM " . $db->nameQuote('#__components') . " WHERE link = " . $db->Quote('option=com_apoll');
+ $db->setQuery($query);
+ $component_id = $db->loadResult();
+
+ $query = "
+ UPDATE " . $db->nameQuote('#__components') . " SET admin_menu_img = '../media/system/images/apoll.png' WHERE id = $component_id;
+ INSERT INTO " . $db->nameQuote('#__components') . " VALUES
+ (null, 'Polls', '', 0, $component_id, 'option=com_apoll', 'Polls', 'com_apoll', 0, '', 0, '', 1),
+ (null, 'Votes', '', 0, $component_id, 'option=com_apoll&task=view&view=votes', 'Votes', 'com_apoll', 1, '', 0, '', 1),
+ (null, 'Configuration', '', 0, $component_id, 'option=com_apoll&task=view&view=config', 'Configuration', 'com_apoll', 2, '', 0, '', 1)
+ ";
+ $db->setQuery( $query );
+ if(!$db->queryBatch()) {
+ $msg .= " ".$db->getErrorMsg();
+ } else {
+ $msg .= " ".JText::_('Apoll admin menu successfully updated')." ";
+ }
+
+ //Drop old tables
+ $db->setQuery("
+ DROP TABLE ". $db->nameQuote('#__apolls') . ";
+ DROP TABLE ". $db->nameQuote('#__apoll_data') .";
+ DROP TABLE ". $db->nameQuote('#__apoll_date').";
+ ");
+ if(!$db->queryBatch()) {
+ $msg .= " ".$db->getErrorMsg();
+ } else {
+ $msg .= " ".JText::_('Version 1.2 tables dropped')." ";
+ }
+ }
+
+ // Change database apoll_votes' field vote_id to option_id.
+ $table = $db->getPrefix().'apoll_votes';
+ $fields = $db->getTableFields($table);
+
+ if(array_key_exists('vote_id', $fields[$table])) {
+
+ $db->setQuery("ALTER TABLE ". $db->nameQuote('#__apoll_votes') . " CHANGE ". $db->nameQuote('vote_id') . " ". $db->nameQuote('option_id') . " INT(11) NOT NULL DEFAULT '0'");
+ if(!$db->query()) {
+ $msg .= "ERROR!!! Field apoll_votes.vote_id exitsts. Could not be changed to apoll_votes.option_id. Please rename it manually. ".$db->getErrorMsg();
+ }
+ }
+
+ // Drop the #__apoll_menu table. We are getting rid of this table left from joomla 1.0
+ $db->setQuery("DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_menu'));
+ if(!$db->query()) {
+ $msg .= " ".$db->getErrorMsg();
+ }
+
+ //If Joomfish component is installed import apoll joomfish files
+ if (file_exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'config.xml'))
+ {
+ //Deletes older joomfish files
+ if (file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apolls.xml") || file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_data.xml") || file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_poll.xml") || file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml")) {
+ //First files left from Apoll version 1.2
+ @unlink(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apolls.xml");
+ @unlink(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_data.xml");
+ //Then check for files left from Apoll version 2.0
+ @unlink(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_polls.xml");
+ @unlink(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml");
+ }
+ //copy the files from com_apoll/joomfish to com_joomfish/contentelements and remove dir com_apoll/joomfish
+ if ((@rename(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_polls.xml", JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_polls.xml")) && (@rename(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_options.xml", JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml")) && (@rmdir (JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish"))) {
+ $msg .= " ".JText::_('Joomfish component found! Contentelement files were also installed')." ";
+ } else {
+ $msg .=" ".JText::_('Joomfish component was found, but content element files could not be copied')." ";}
+ }
+
+ ?>
+
+
+
+
+
+
+
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/install.sql b/oss/joomla/trunk/administrator/components/com_apoll/install.sql
new file mode 100644
index 00000000..129fd788
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/install.sql
@@ -0,0 +1,60 @@
+
+--
+-- Table structure for table `#__apolls`
+--
+
+CREATE TABLE IF NOT EXISTS `#__apoll_polls` (
+ `id` int(11) unsigned NOT NULL auto_increment,
+ `title` varchar(255) NOT NULL default '',
+ `alias` varchar(255) NOT NULL default '',
+ `checked_out` int(11) NOT NULL default '0',
+ `checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
+ `published` tinyint(1) NOT NULL default '0',
+ `publish_up` datetime NOT NULL default '0000-00-00 00:00:00',
+ `publish_down` datetime default '0000-00-00 00:00:00',
+ `params` text NOT NULL,
+ `access` int(11) NOT NULL default '0',
+ `lag` int(11) NOT NULL default '0',
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
+
+--
+-- Table structure for table '#__apoll_options'
+--
+
+
+CREATE TABLE IF NOT EXISTS `#__apoll_options` (
+ `id` int(11) NOT NULL auto_increment,
+ `apoll_id` int(11) NOT NULL default '0',
+ `text` text NOT NULL,
+ `link` varchar(255) DEFAULT NULL,
+ `color` varchar(6) NOT NULL,
+ `ordering` int(11) NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `apoll_id` (`apoll_id`,`text`(1))
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
+
+--
+-- Table structure for table '#__apoll_votes'
+--
+
+CREATE TABLE IF NOT EXISTS `#__apoll_votes` (
+ `id` bigint(20) NOT NULL auto_increment,
+ `date` datetime NOT NULL default '0000-00-00 00:00:00',
+ `option_id` int(11) NOT NULL default '0',
+ `apoll_id` int(11) NOT NULL default '0',
+ `ip` int(10) unsigned NOT NULL,
+ `user_id` int(11) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `apoll_id` (`apoll_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
+
+--
+-- Table structure for table '#__apoll_config'
+--
+
+CREATE TABLE IF NOT EXISTS `#__apoll_config` (
+ `drop_it` tinyint(1) NOT NULL DEFAULT '0'
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
+INSERT INTO `#__apoll_config` (`drop_it`) VALUES ('0');
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/install.xml b/oss/joomla/trunk/administrator/components/com_apoll/install.xml
new file mode 100644
index 00000000..7cac5155
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/install.xml
@@ -0,0 +1,86 @@
+
+
+ Apoll
+ October 2009
+ Hristo Genev
+ harrygg@gmail.com
+ http://www.afactory.org
+ Hristo Genev. All rights reserved.
+ GPL/GNU
+ 2.0.016
+ Apoll is a component for voting. It shows vote results with a nice pie chart. Basicly it substitutes the original poll component installed in Joomla by default and adds some enhancements to the back and front end.
+
+ install.apoll.php
+ uninstall.apoll.php
+
+
+ controller.php
+ apoll.php
+ index.html
+ router.php
+ models
+ views
+
+
+ en-GB.com_apoll.ini
+
+
+
+ js/jquery.apoll.js
+ js/jquery.tablednd.js
+ js/jquery.colorpicker.js
+ js/jquery.color.js
+ js/jquery.js
+ js/json.js
+ swf/open-flash-chart.swf
+ images/apoll-arrow.gif
+ images/apoll.png
+ images/apoll-add.png
+ images/apoll-remove.png
+ images/apoll-ended.gif
+ images/apoll-active.gif
+
+
+
+
+ install.sql
+
+
+
+
+ uninstall.sql
+
+
+
+
+
+ Apolls
+
+ Polls
+ Votes
+ Configuration
+
+
+
+ apoll.php
+ config.xml
+ controller.php
+ index.html
+ install.apoll.php
+ uninstall.apoll.php
+ install.sql
+ uninstall.sql
+ models
+ tables
+ views
+ elements
+
+ joomfish
+
+
+
+ en-GB.com_apoll.ini
+ en-GB.com_apoll.menu.ini
+
+
+
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/joomfish/apoll_options.xml b/oss/joomla/trunk/administrator/components/com_apoll/joomfish/apoll_options.xml
new file mode 100644
index 00000000..3f218680
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/joomfish/apoll_options.xml
@@ -0,0 +1,17 @@
+
+
+ Apoll - Options
+ Hristo Genev
+ 2.0
+ Definition for the Apoll poll options
+
+
+
+
+ text
+ apoll_id
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/joomfish/apoll_polls.xml b/oss/joomla/trunk/administrator/components/com_apoll/joomfish/apoll_polls.xml
new file mode 100644
index 00000000..8c4a5942
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/joomfish/apoll_polls.xml
@@ -0,0 +1,15 @@
+
+
+ Apoll - Polls
+ Hristo Genev
+ 2.0
+ Definition for the core Apoll component
+
+
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/models/apoll.php b/oss/joomla/trunk/administrator/components/com_apoll/models/apoll.php
new file mode 100644
index 00000000..6d278309
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/models/apoll.php
@@ -0,0 +1,192 @@
+setId((int)$array[0]);
+ }
+ function setId($id)
+ {
+ // Set apoll id and wipe data
+ $this->_id = $id;
+ $this->_data = null;
+ }
+
+ /**
+ * Method to get a apoll
+ *
+ * @since 1.5
+ */
+ function &getData()
+ {
+ // Load the apoll data
+ if ($this->_loadData())
+ {
+ // Initialize some variables
+ $user = &JFactory::getUser();
+ }
+ else $this->_initData();
+
+ return $this->_data;
+ }
+
+ function isCheckedOut( $uid=0 )
+ {
+ if ($this->_loadData())
+ {
+ if ($uid) {
+ return ($this->_data->checked_out && $this->_data->checked_out != $uid);
+ } else {
+ return $this->_data->checked_out;
+ }
+ }
+ }
+ function checkin()
+ {
+ if ($this->_id)
+ {
+ $apoll = & $this->getTable();
+ if(! $apoll->checkin($this->_id)) {
+ $this->setError($this->_db->getErrorMsg());
+ return false;
+ }
+ }
+ return false;
+ }
+ function checkout($uid = null)
+ {
+ if ($this->_id)
+ {
+ // Make sure we have a user id to checkout the article with
+ if (is_null($uid)) {
+ $user =& JFactory::getUser();
+ $uid = $user->get('id');
+ }
+ // Lets get to it and checkout the thing...
+ $apoll =& $this->getTable();
+ if(!$apoll->checkout($uid, $this->_id)) {
+ $this->setError($this->_db->getErrorMsg());
+ return false;
+ }
+
+ return true;
+ }
+ return false;
+ }
+ function store($data)
+ {
+ $row =& $this->getTable();
+ // Bind the form fields to the web link table
+ if (!$row->bind($data)) {
+ $this->setError($this->_db->getErrorMsg());
+ return false;
+ }
+
+ // Create the timestamp for the date
+ $row->date = gmdate('Y-m-d H:i:s');
+
+ // Make sure the web link table is valid
+ if (!$row->check()) {
+ $this->setError($this->_db->getErrorMsg());
+ return false;
+ }
+
+ // Store the web link table to the database
+ if (!$row->store()) {
+ $this->setError($this->_db->getErrorMsg());
+ return false;
+ }
+
+ return true;
+ }
+
+ function _loadData()
+ {
+ // Lets load the content if it doesn't already exist
+ if (empty($this->_data))
+ {
+/* $db =& JFactory::getDBO();
+ $query = "SELECT d.*, COUNT(v.id) AS hits"
+ ." FROM ".$db->nameQuote('#__apoll_options')." AS d"
+ ." LEFT JOIN ".$db->nameQuote('#__apoll_votes')." AS v"
+ ." ON d.id=v.option_id"
+ ." WHERE d.apoll_id = ".(int) $this->_id
+ ." AND text<>'' GROUP BY d.id ORDER BY ordering";
+ $this->_db->setQuery($query);
+ $this->_data = $this->_db->loadObject();
+ */ return (boolean) $this->_data;
+ }
+ return true;
+ }
+ function _initData()
+ {
+ // Lets load the content if it doesn't already exist
+ if (empty($this->_data))
+ {
+ $apoll = new stdClass();
+ $apoll->id = 0;
+ $apoll->title = null;
+ $apoll->alias = null;
+ $apoll->checked_out = 0;
+ $apoll->checked_out_time = 0;
+ $apoll->published = 0;
+ $apoll->params = null;
+ $apoll->access = null;
+ $apoll->lag = 0;
+ $this->_data = $apoll;
+ return (boolean) $this->_data;
+ }
+ return true;
+ }
+
+ //delete empty options to clear the db
+ function deleteOption($id) {
+ $query = "DELETE FROM ".$this->_db->nameQuote('#__apoll_options')." WHERE ".$this->_db->nameQuote('id')."=".$this->_db->Quote((int)$id)." LIMIT 1";
+ $this->_db->setQuery($query);
+ if(!$this->_db->query()) {
+ $this->setError($this->_db->getErrorMsg());
+ return false;
+ }
+ return true;
+ }
+
+
+}
+?>
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/models/apoll.xml b/oss/joomla/trunk/administrator/components/com_apoll/models/apoll.xml
new file mode 100644
index 00000000..8e417a81
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/models/apoll.xml
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+
+ Yes
+ NO
+
+
+
+ Yes
+ NO
+
+
+
+ Yes
+ NO
+
+
+
+
+ JOOMLA DEFAULT WAY
+ PIE CHART
+
+
+ Yes
+ NO
+
+
+ Yes
+ No
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+
+
+
+
+
+
+
+
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+ Yes
+ NO
+
+
+ BOUNCE
+ FADE
+
+
+
+
+ LEFT
+ CENTER
+ RIGHT
+
+
+ TOP
+ MIDDLE
+ BOTTOM
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/models/apolls.php b/oss/joomla/trunk/administrator/components/com_apoll/models/apolls.php
new file mode 100644
index 00000000..f7d6f880
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/models/apolls.php
@@ -0,0 +1,192 @@
+getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
+ $limitstart = $mainframe->getUserStateFromRequest( $option.'limitstart.apolls', 'limitstart', 0, 'int' );
+
+ // In case limit has been changed, adjust limitstart accordingly
+ $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
+
+ $this->setState('limit', $limit);
+ $this->setState('limitstart', $limitstart);
+ }
+ /**
+ * Method to get weblinks item data
+ *
+ * @access public
+ * @return array
+ */
+ function getData()
+ {
+ // Lets load the content if it doesn't already exist
+ if (empty($this->_data))
+ {
+ $query = $this->_buildQuery();
+ $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
+ }
+
+ return $this->_data;
+ }
+ /**
+ * Method to get the total number of weblink items
+ *
+ * @access public
+ * @return integer
+ */
+ function getTotal()
+ {
+ // Lets load the content if it doesn't already exist
+ if (empty($this->_total))
+ {
+ $query = $this->_buildQuery();
+ $this->_total = $this->_getListCount($query);
+ }
+
+ return $this->_total;
+ }
+
+ /**
+ * Method to get a pagination object for the weblinks
+ *
+ * @access public
+ * @return integer
+ */
+ function getPagination()
+ {
+ // Lets load the content if it doesn't already exist
+ if (empty($this->_pagination))
+ {
+ jimport('joomla.html.pagination');
+ $this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
+ }
+
+ return $this->_pagination;
+ }
+ function _buildQuery()
+ {
+ // Get the WHERE and ORDER BY clauses for the query
+ $where = $this->_buildContentWhere();
+ $orderby = $this->_buildContentOrderBy();
+ $db =& JFactory::getDBO();
+ $query = "SELECT m.*, u.name AS editor, COUNT(o.id) AS options, ( SELECT count(v.id) FROM ".$db->nameQuote('#__apoll_votes')." AS v
+ WHERE v.apoll_id=m.id) AS votes FROM ".$db->nameQuote('#__apoll_polls')." AS m
+ LEFT JOIN ".$db->nameQuote('#__users')." AS u ON u.id= m.checked_out
+ LEFT JOIN ".$db->nameQuote('#__apoll_options')." AS o ON o.apoll_id = m.id AND o.text <> ''"
+ . $where
+ . " GROUP BY m.id"
+ . $orderby;
+
+ return $query;
+ }
+ function _buildContentOrderBy()
+ {
+ global $mainframe, $option;
+
+ $filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.apolls", 'filter_order', 'm.id', 'cmd' );
+ $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.apolls", 'filter_order_Dir', '', 'word' );
+
+ $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir;
+
+ return $orderby;
+ }
+
+ function _buildContentWhere()
+ {
+ global $mainframe, $option;
+ $db =& JFactory::getDBO();
+ $filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.apolls", 'filter_order', 'm.id', 'cmd' );
+ $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.apolls", 'filter_order_Dir', '', 'word' );
+ $filter_state = $mainframe->getUserStateFromRequest( "$option.filter_state.apolls", 'filter_state', '', 'word' );
+ $search = $mainframe->getUserStateFromRequest( "$option.search.apolls",'search','','string');
+
+ $where = array();
+
+ if ($search)
+ {
+ $search = JString::strtolower( $search );
+ $where[] = 'LOWER(m.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
+ }
+ if ( $filter_state ) {
+ if ( $filter_state == 'P' ) {
+ $where[] = 'm.published = 1';
+ } else if ($filter_state == 'U' ) {
+ $where[] = 'm.published = 0';
+ }
+ }
+ $where = ( count( $where ) ? ' WHERE '. implode( ' AND ', $where ) : '' );
+
+ return $where;
+ }
+
+
+
+ function resetVotes($cid = Null) {
+ $db =& JFactory::getDBO();
+ $cid = JRequest::getVar( 'cid', array(), '', 'array' );
+ JArrayHelper::toInteger($cid);
+ $cids = implode( ',', $cid );
+
+ $query = "DELETE FROM ".$db->nameQuote('#__apoll_votes')." WHERE ".$db->nameQuote('apoll_id')." IN (".$cids.")";
+ $db->setQuery($query);
+ if($db->query()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
+?>
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/models/config.php b/oss/joomla/trunk/administrator/components/com_apoll/models/config.php
new file mode 100644
index 00000000..48fd1694
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/models/config.php
@@ -0,0 +1,238 @@
+nameQuote('drop_it') . " FROM #__apoll_config";
+ $db->setQuery($query);
+ $this->_data = $db->loadResult();
+
+ return $this->_data;
+ }
+
+ function save()
+ {
+
+ $db =& JFactory::getDBO();
+ $drop = JRequest::getVar('drop', 0, 'POST', 'INT');
+
+ $query = "UPDATE ".$db->nameQuote('#__apoll_config')."
+ SET ".$db->nameQuote('drop_it')."=".(int)$drop;
+
+ $db->setQuery($query);
+ if (!$db->query()) {
+ JError::raiseError ($db->stderr());
+ return false;
+ }
+ return true;
+ }
+
+ function getApolls()
+ {
+ $db =& JFactory::getDBO();
+
+ $query = "SELECT COUNT(id) FROM ".$db->nameQuote('#__apoll_polls');
+ $db->setQuery($query);
+ if($result = $db->loadResult()) {
+ return $result;
+ } else {
+ return false;
+ }
+ }
+ function getJpolls()
+ {
+ $db =& JFactory::getDBO();
+
+ $query = "SELECT COUNT(id) FROM ".$db->nameQuote('#__polls');
+ $db->setQuery($query);
+ if($result = $db->loadResult()) {
+ return $result;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Function to import polls from joomla poll component
+ * 1. Copy #__polls table with all polls to #__apoll_polls
+ * 2. Get the id of the first newly created poll
+ * 3. Get all polls' ids from #__polls table and push the into an array
+ * 4. Copy the options from #__poll_data to #__apoll_options
+ * 5. Generate random color for each options
+ * 6. Correct apoll_id of the options
+ * 7. Copy votes from #__poll_date to #__apoll_votes
+ * 8. Correct apoll_id field of all votes
+ */
+
+ function import()
+ {
+
+ $db =& JFactory::getDBO();
+ //import the polls table
+ $query = "
+ INSERT INTO " . $db->nameQuote('#__apoll_polls') . "
+ (title, alias, checked_out, checked_out_time, published, params, access, lag)
+ SELECT title, alias, checked_out, checked_out_time, 0, 'only_registered=0\none_vote_per_user=1\nip_check=0\nshow_component_msg=1\nallow_voting=1\nshow_what=1\nshow_hits=1\nshow_title=1\nshow_dropdown=1\nshow_voters=1\nshow_times=1\nopacity=90\nbg_color=ffffff\ncircle_color=505050\npieX=100%\npieY=400\nstart_angle=55\nradius=150\ngradient=1\nno_labels=0\nshow_zero_votes=1\nanimation_type=bounce\nbounce_dinstance=30\nbg_image=-1\nbg_image_x=left\nbg_image_y=top\nfont_size=11\nfont_color=404040\ntitle_lenght=30\nchartX=100%\noptionsFontSize=12\nbarHeight=15\nbarBorder=1px solid #000000\nbgBarColor=f5f5f5\nbgBarBorder=1px solid #cccccc\n', access, lag/60
+ FROM " . $db->nameQuote('#__polls') . " ;";
+
+ $db->setQuery( $query );
+ if(!$db->query()) return false;
+ //get the first new id of the imported polls
+ $new_id = $db->insertid();
+
+ //get the native polls ids and put them in an array
+ $query = "SELECT id FROM ". $db->nameQuote('#__polls');
+ $db->setQuery($query);
+ $old_ids = $db->loadResultArray();
+
+ //copy the options table
+ $query = "INSERT INTO " . $db->nameQuote('#__apoll_options') . " (apoll_id, text, color)
+ SELECT pollid, text, 'cccccc'
+ FROM " . $db->nameQuote('#__poll_data') . "
+ WHERE text <>'';"
+ ;
+
+ $db->setQuery( $query );
+ if(!$db->query()) return false;
+ //get the id of the first option
+ $new_option_id = $db->insertid();
+ //get how many polls are imported
+ $n = $db->getAffectedRows();
+
+ //generate random color for each new option
+ $id = $new_option_id;
+ for ($i=0; $i<$n; $i++) {
+ $query = "UPDATE ". $db->nameQuote('#__apoll_options')."
+ SET color = '". $this->random_color() ."'
+ WHERE id = ".$id;
+ $id++;
+ $db->setQuery( $query );
+ $db->query();
+ }
+
+
+ $query = "";
+ //correct apoll_ids of options and generate random colors
+ $id = $new_id;
+ foreach ($old_ids as $value) {
+ $query = "UPDATE " . $db->nameQuote('#__apoll_options') . "
+ SET apoll_id = ". $id ."
+ WHERE apoll_id = ". $value . ";";
+ $id++;
+
+ $db->setQuery( $query );
+ $db->query();
+ }
+
+ //copy the votes table
+ $query = "INSERT INTO ". $db->nameQuote('#__apoll_votes')." (date, apoll_id, option_id)
+ SELECT date, poll_id, vote_id
+ FROM " . $db->nameQuote('#__poll_date') . ";"
+ ;
+ $db->setQuery( $query );
+ if(!$db->query())
+ return false;
+
+ $query = "";
+ //correct apoll_ids of votes
+ $id = $new_id; //reset the id
+ foreach ($old_ids as $value) {
+ $query = "UPDATE " . $db->nameQuote('#__apoll_votes') . "
+ SET apoll_id = " . $id . "
+ WHERE apoll_id = " . $value. ";";
+ $id++;
+
+ $db->setQuery( $query );
+ $db->query();
+ }
+
+ //correct apoll_ids of votes
+ $query = "";
+ //put all old ids of old options from #__poll_data table in array
+ $query = "SELECT id FROM " . $db->nameQuote('#__poll_data') . " WHERE text <> ''";
+ $db->setQuery($query);
+ $old_option_ids = $db->loadResultArray();
+
+ $id = $new_option_id;
+ foreach ($old_option_ids as $value) {
+ $query = "UPDATE " . $db->nameQuote('#__apoll_votes') . "
+ SET option_id = $id
+ WHERE option_id = $value;";
+ $id++;
+
+ $db->setQuery( $query );
+ $db->query();
+ }
+ return true;
+
+ }
+
+ // random color generator
+ function random_color(){
+ mt_srand((double)microtime()*1000000);
+ $c = '';
+ while(strlen($c)<6){
+ $c .= sprintf("%02X", mt_rand(0, 255));
+ }
+ return $c;
+ }
+
+
+ function getJoomfishInstalled() {
+ if (file_exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'config.xml'))
+ return true;
+ return false;
+ }
+
+ function getApollFilesInstalled() {
+ if (file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_polls.xml") && file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml"))
+ return true;
+ return false;
+ }
+ function getApollFilesPresent() {
+ if (file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_polls.xml") && file_exists(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_options.xml"))
+ return true;
+ return false;
+ }
+
+ function copyJoomfishFiles() {
+ //copy the files from com_apoll/joomfish to com_joomfish/contentelements and remove dir com_apoll/joomfish
+ if((@rename(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_polls.xml", JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_polls.xml"))
+ &&
+ (@rename(JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish".DS."apoll_options.xml", JPATH_ADMINISTRATOR.DS."components".DS."com_joomfish".DS."contentelements".DS."apoll_options.xml"))
+ &&
+ (@rmdir (JPATH_ADMINISTRATOR.DS."components".DS."com_apoll".DS."joomfish")))
+ {
+ return true;
+ }
+ return false;
+ }
+}
+?>
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/models/index.html b/oss/joomla/trunk/administrator/components/com_apoll/models/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/models/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/models/votes.php b/oss/joomla/trunk/administrator/components/com_apoll/models/votes.php
new file mode 100644
index 00000000..86d6fb71
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/models/votes.php
@@ -0,0 +1,199 @@
+getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
+ $limitstart = $mainframe->getUserStateFromRequest( $option.'limitstart.votes', 'limitstart', 0, 'int' );
+
+ // In case limit has been changed, adjust limitstart accordingly
+ $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
+
+ $this->setState('limit', $limit);
+ $this->setState('limitstart', $limitstart);
+ }
+
+ function getData()
+ {
+ // Lets load the content if it doesn't already exist
+ if (empty($this->_data))
+ {
+ $query = $this->_buildQuery();
+ $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
+ }
+
+ //DEBUG
+ //echo str_replace('#__', 'jos_', $query); exit;
+
+ return $this->_data;
+ }
+
+ function getTotal()
+ {
+ // Lets load the content if it doesn't already exist
+ if (empty($this->_total))
+ {
+ $query = $this->_buildQuery();
+ $this->_total = $this->_getListCount($query);
+ }
+
+ return $this->_total;
+ }
+
+ function getPagination()
+ {
+ // Lets load the content if it doesn't already exist
+ if (empty($this->_pagination))
+ {
+ jimport('joomla.html.pagination');
+ $this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
+ }
+
+ return $this->_pagination;
+ }
+
+ function _buildQuery()
+ {
+ $db =& JFactory::getDBO();
+
+ $query = "SELECT v.id, v.date, o.text, INET_NTOA(ip) AS ip,
+ CASE WHEN v.user_id <> 0 THEN u.name ELSE ".$db->Quote(JText::_('Guest'))." END AS name
+ FROM " . $db->nameQuote('#__apoll_votes') . " AS v
+ LEFT JOIN " . $db->nameQuote('#__apoll_options') . " AS o ON o.id = v.option_id
+ LEFT JOIN " . $db->nameQuote('#__users') . " AS u ON u.id=v.user_id "
+ // Get the WHERE and ORDER BY clauses for the query
+ . $this->_buildContentWhere()
+ . $this->_buildContentOrderBy();
+
+ return $query;
+ }
+
+ function _buildContentOrderBy()
+ {
+ global $mainframe, $option;
+
+ $filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.votes", 'filter_order', 'v.date', 'cmd' );
+ $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.votes", 'filter_order_Dir', '', 'word' );
+
+ $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir;
+
+ return $orderby;
+ }
+
+ function _buildContentWhere()
+ {
+ global $mainframe, $option;
+ $db =& JFactory::getDBO();
+ $filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order.votes", 'filter_order', 'v.date', 'cmd' );
+ $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.votes", 'filter_order_Dir', '', 'word' );
+ $search = $mainframe->getUserStateFromRequest( "$option.search.votes",'search','','string');
+
+ $where = array();
+
+ $apoll_id = JRequest::getInt('id', 0, 'GET');
+ $where[] = " v.apoll_id = " . $apoll_id;
+
+ if ($search)
+ {
+ $search = JString::strtolower( $search );
+ $search = $db->Quote('%'.$db->getEscaped( $search, true ).'%', false );
+ $where[]= ' LOWER(u.name) LIKE ' . $search;
+ }
+ $where = ' WHERE '. implode( ' AND ', $where );
+
+ return $where;
+ }
+
+ function getList() {
+
+ $db =& JFactory::getDBO();
+ $apoll_id = JRequest::getInt('id', 0, 'GET');
+
+ // list of apolls for dropdown selection
+ $query = "SELECT m.id, m.title, COUNT(v.id) AS votes"
+ . " FROM ".$db->nameQuote('#__apoll_polls')." AS m"
+ . " LEFT JOIN ".$db->nameQuote('#__apoll_votes')." AS v"
+ . " ON m.id=v.apoll_id"
+ . " GROUP BY m.id ORDER BY id";
+
+ $db->setQuery( $query );
+ $pList = $db->loadObjectList();
+
+ //Get the title for the site=the active poll
+ foreach ($pList as $p) {
+ if ($p->id==$apoll_id) $title=$p->title;
+ }
+ //Make the URLs for the dropdown
+ foreach ($pList as $k=>$p)
+ {
+ $pList[$k]->url = JRoute::_('index.php?option=com_apoll&task=view&view=votes&id='.$p->id);
+ }
+ array_unshift( $pList, JHTML::_('select.option', '', JText::_('Select Poll from the list'), 'url', 'title' ));
+
+ // dropdown output
+ $lists = array();
+
+ $lists['apolls'] = JHTML::_('select.genericlist', $pList, 'id', 'class="inputbox" size="1" style="width:400px" onchange="if (this.options[selectedIndex].value != \'\') {document.location.href=this.options[selectedIndex].value}"',
+ 'url', 'title',
+ JRoute::_('index.php?option=com_apoll&task=view&view=votes&id='.$apoll_id)
+ );
+
+ return $lists;
+ }
+
+ function getTitle() {
+ $db =& JFactory::getDBO();
+ $apoll_id = JRequest::getInt('id', 0, 'GET');
+ $query = "SELECT title FROM ".$db->nameQuote('#__apoll_polls')." WHERE ".$db->nameQuote('id')."=".(int)$apoll_id;
+ $db->setQuery($query);
+ return $db->loadResult();
+ }
+
+ function deleteVotes() {
+
+ $db =& JFactory::getDBO();
+ $cid = JRequest::getVar( 'cid', array(), '', 'array' );
+
+ JArrayHelper::toInteger($cid);
+ $cids = implode(',', $cid);
+
+ //Delete the chosen votes, dates, ips, users, etc from #__apolls_date table
+ $query = "DELETE FROM ".$db->nameQuote('#__apoll_votes')." WHERE id IN (" . $cids . ")";
+ $db->setQuery($query);
+ if(!$db->query()) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+}
+?>
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/tables/apoll.php b/oss/joomla/trunk/administrator/components/com_apoll/tables/apoll.php
new file mode 100644
index 00000000..92e8c07d
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/tables/apoll.php
@@ -0,0 +1,156 @@
+loadArray($array['params']);
+ $array['params'] = $registry->toString();
+ }
+ return parent::bind($array, $ignore);
+ }
+ /**
+ * Overloaded check function
+ *
+ * @access public
+ * @return boolean
+ * @see JTable::check
+ * @since 1.5
+ */
+ function check()
+ {
+ global $mainframe;
+ // 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 = floatval( $this->lag*60 );
+ 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();
+ $datenow->setOffset($mainframe->getCfg('offset'));
+ $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 ))
+ {
+ $db =& JFactory::getDBO();
+ $query = "DELETE FROM ".$db->nameQuote('#__apoll_options')
+ ." WHERE ".$db->nameQuote('apoll_id')."=".(int) $oid.";";
+
+ $query .= "DELETE FROM ". $db->nameQuote('#__apoll_votes').
+ " WHERE ".$db->nameQuote('apoll_id')."=".(int)$oid.";";
+
+ $db->setQuery($query);
+ $db->queryBatch( $query );
+ if ( !$db->query() ) {
+ $this->_error .= $db->getErrorMsg() . "\n";
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ // function to get the options for current poll
+ function getOptions($apoll_id) {
+
+ $query = "SELECT o.*, COUNT(v.id) AS hits"
+ ." FROM ".$this->_db->nameQuote('#__apoll_options')." AS o"
+ ." LEFT JOIN ".$this->_db->nameQuote('#__apoll_votes')." AS v"
+ ." ON (o.id = v.option_id AND v.apoll_id = ".(int) $apoll_id . ")"
+ ." WHERE o.apoll_id = ".(int) $apoll_id
+ ." AND text <> '' GROUP BY o.id ORDER BY o.ordering";
+
+ //print nl2br(str_replace('#__', 'jos_', $query)); exit;
+ $this->_db->setQuery($query);
+ return $this->_db->loadObjectList();
+ }
+
+
+}
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/tables/index.html b/oss/joomla/trunk/administrator/components/com_apoll/tables/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/tables/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/uninstall.apoll.php b/oss/joomla/trunk/administrator/components/com_apoll/uninstall.apoll.php
new file mode 100644
index 00000000..dcc410fc
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/uninstall.apoll.php
@@ -0,0 +1,52 @@
+nameQuote('drop_it') . " FROM " . $db->nameQuote('#__apoll_config');
+ $db->setQuery($query);
+ if ($db->loadResult()) {
+ $query = "
+ DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_polls') . ";
+ DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_options') . ";
+ DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_votes') . ";
+ DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_menu') . ";
+ DROP TABLE IF EXISTS ". $db->nameQuote('#__apoll_config;')
+ ;
+ $db->setQuery($query);
+ if (!$db->queryBatch()) {
+ $db->stderr();
+ } else {
+ $msg = "Apoll database has been successfully dropped.";
+ }
+ } else {
+ $msg = "Apoll database has not been dropped.";
+ }
+
+ $query = "DELETE FROM " . $db->nameQuote('#__apoll_config');
+ $db->setQuery($query);
+ $db->query();
+
+ ?>
+
+
+ ".JText::_($msg)."";
+}
+?>
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/uninstall.sql b/oss/joomla/trunk/administrator/components/com_apoll/uninstall.sql
new file mode 100644
index 00000000..e69de29b
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/index.html b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/tmpl/default.php b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/tmpl/default.php
new file mode 100644
index 00000000..e9917b56
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/tmpl/default.php
@@ -0,0 +1,40 @@
+
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/tmpl/form.php b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/tmpl/form.php
new file mode 100644
index 00000000..3ebac01a
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/tmpl/form.php
@@ -0,0 +1,325 @@
+
+
+[ ' . $text.' ] ' );
+ JToolBarHelper::Preview('index.php?option=com_apoll&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.apolls.edit' );
+ JHTML::_('behavior.calendar');
+ $apoll = $this->apoll;
+ JFilterOutput::objectHTMLSafe( $apoll, ENT_QUOTES );
+?>
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/tmpl/index.html b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/tmpl/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/tmpl/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/view.html.php b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/view.html.php
new file mode 100644
index 00000000..dab0e7b4
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/apoll/view.html.php
@@ -0,0 +1,79 @@
+load( $uid );
+
+ // fail if checked out not by 'me'
+ if ($apoll->isCheckedOut( $user->get('id') )) {
+ $msg = JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The poll' ), $apoll->title );
+ $this->setRedirect( 'index.php?option='. $option, $msg );
+ }
+
+ if ($apoll->id == 0)
+ {
+ // defaults
+ $row->published = 1;
+ }
+
+ $options = array();
+ $ordering = array();
+
+ if ($edit)
+ {
+ $options = $apoll->getOptions($apoll->id);
+ }
+ else
+ {
+ $apoll->lag = 24*60;
+ }
+ //default colors for slices
+ $colors = array("ff0000","ffff99","00ccff","66ff99","ffcc00","d7ebff","ccffcc", "cccccc", "ffff00", "006699", "660000", "ffddee");
+
+ $file = JPATH_COMPONENT.DS.'models'.DS.'apoll.xml';
+ $params = new JParameter( $apoll->params, $file );
+
+ $this->assignRef('apoll', $apoll);
+ $this->assignRef('options', $options);
+ $this->assignRef('showpie', $showpie);
+ $this->assignRef('params', $params);
+ $this->assignRef('color', $colors);
+ $this->assignRef('edit', $edit);
+ parent::display($tpl);
+
+ }
+}
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/index.html b/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/tmpl/default.php b/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/tmpl/default.php
new file mode 100644
index 00000000..257042a5
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/tmpl/default.php
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/tmpl/index.html b/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/tmpl/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/tmpl/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/view.html.php b/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/view.html.php
new file mode 100644
index 00000000..92d1e062
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/apolls/view.html.php
@@ -0,0 +1,56 @@
+getUserStateFromRequest( "$option.filter_order.apolls", 'filter_order', 'm.id', 'cmd' );
+ $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.apolls", 'filter_order_Dir', '', 'word' );
+ $filter_state = $mainframe->getUserStateFromRequest( "$option.filter_state.apolls", 'filter_state', '', 'word' );
+ $search = $mainframe->getUserStateFromRequest( "$option.search.apolls",'search','','string');
+
+ // Get data from the model
+ $items = & $this->get( 'Data');
+ $total = & $this->get( 'Total');
+ $pagination = & $this->get( 'Pagination' );
+
+ // 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', $items);
+ $this->assignRef('pagination', $pagination);
+
+ parent::display($tpl);
+ }
+}
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/config/index.html b/oss/joomla/trunk/administrator/components/com_apoll/views/config/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/config/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/config/tmpl/default.php b/oss/joomla/trunk/administrator/components/com_apoll/views/config/tmpl/default.php
new file mode 100644
index 00000000..01258aa4
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/config/tmpl/default.php
@@ -0,0 +1,79 @@
+startPane("config");
+echo $tabs->startPanel(JText::_('CONFIGURATION'),"Configuration");
+
+?>
+
+
+endPanel();
+
+echo $tabs->startPanel(JText::_('Import'),"Import polls from Joomla! default poll component");
+echo "
".JText::_('Import polls from Joomla! default poll component');
+echo " ";
+echo JText::sprintf('You have created %u polls with Apoll component', $this->apolls);
+echo " ";
+echo JText::sprintf('You have created %u polls with native Joomla 1.5 Poll component', $this->jpolls);
+echo " ";
+echo JText::_('Click import button to import polls from the native Joomla poll component')." ";
+?>
+
+
+endPanel();
+echo $tabs->startPanel(JText::_('Joomfish!'),"Install Joomfish files");
+
+?>
+
+
+joomfish) {
+ echo Jtext::_('Joomfish component is not found on your system');
+} else {
+ if($this->apollFilesInstalled) {
+ echo " ".Jtext::_('Apoll files for Joomfish are installed')." ";
+ } else {
+ echo " ".Jtext::_('Apoll files for Joomfish are not installed')." ";
+ if($this->apollFilesPresent) {
+ echo "";
+ } else {
+ echo " ".Jtext::_('Apoll files for Joomfish! are not found. You must manualy download and install them')."Download ";
+ }
+ }
+
+} ?>
+
+endPanel();
+?>
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/config/tmpl/index.html b/oss/joomla/trunk/administrator/components/com_apoll/views/config/tmpl/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/config/tmpl/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/config/view.html.php b/oss/joomla/trunk/administrator/components/com_apoll/views/config/view.html.php
new file mode 100644
index 00000000..7758c820
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/config/view.html.php
@@ -0,0 +1,42 @@
+get( 'Data');
+ $jpolls = & $this->get( 'Jpolls');
+ $apolls = & $this->get( 'Apolls');
+ $joomfish= & $this->get( 'JoomfishInstalled');
+ $apollFilesInstalled = & $this->get('ApollFilesInstalled');
+ $apollFilesPresent = & $this->get('ApollFilesPresent');
+
+ $this->assignRef('drop', $drop);
+ $this->assignRef('jpolls', $jpolls);
+ $this->assignRef('apolls', $apolls);
+ $this->assignRef('joomfish', $joomfish);
+ $this->assignRef('apollFilesInstalled', $apollFilesInstalled);
+ $this->assignRef('apollFilesPresent', $apollFilesPresent);
+
+ parent::display($tpl);
+ }
+}
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/index.html b/oss/joomla/trunk/administrator/components/com_apoll/views/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/votes/index.html b/oss/joomla/trunk/administrator/components/com_apoll/views/votes/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/votes/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/votes/tmpl/default.php b/oss/joomla/trunk/administrator/components/com_apoll/views/votes/tmpl/default.php
new file mode 100644
index 00000000..4170629b
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/votes/tmpl/default.php
@@ -0,0 +1,83 @@
+title)? JText::_( 'Votes manager for:').$this->title : JText::_( 'Please select a Poll from the dropdown');
+JToolBarHelper::title($title);
+JToolBarHelper::back();
+JToolBarHelper::deleteList(JText::_('Are you sure you want to delete this votes'), "deleteVotes", "Delete", true);
+
+?>
+
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/votes/tmpl/index.html b/oss/joomla/trunk/administrator/components/com_apoll/views/votes/tmpl/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/votes/tmpl/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_apoll/views/votes/view.html.php b/oss/joomla/trunk/administrator/components/com_apoll/views/votes/view.html.php
new file mode 100644
index 00000000..7ba88763
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_apoll/views/votes/view.html.php
@@ -0,0 +1,57 @@
+getUserStateFromRequest( "$option.filter_order.votes", 'filter_order', 'v.date', 'cmd' );
+ $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir.votes", 'filter_order_Dir', '', 'word' );
+
+ $search = $mainframe->getUserStateFromRequest( "$option.search.votes",'search', '', 'string' );
+
+ // Get data from the model
+ $lists = & $this->get( 'List');
+ $title = & $this->get( 'Title');
+ $items = & $this->get( 'Data');
+ $total = & $this->get( 'Total');
+ $pagination = & $this->get( 'Pagination' );
+
+ // table ordering
+ $lists['order_Dir'] = $filter_order_Dir;
+ $lists['order'] = $filter_order;
+
+ // search filter
+ $lists['search']= $search;
+
+
+ $this->assignRef('user', $user);
+ $this->assignRef('row', $items);
+ $this->assignRef('apoll_id', $apoll_id);
+ $this->assignRef('title', $title);
+ $this->assignRef('lists', $lists);
+ $this->assignRef('pagination', $pagination);
+ parent::display($tpl);
+
+ }
+}
diff --git a/oss/joomla/trunk/administrator/components/com_cache/admin.cache.html.php b/oss/joomla/trunk/administrator/components/com_cache/admin.cache.html.php
new file mode 100644
index 00000000..d3e65c95
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_cache/admin.cache.html.php
@@ -0,0 +1,153 @@
+
+
+
+
+
+
+ authorize( 'com_cache', 'manage' )) {
+ $mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
+}
+
+// Load the html output class and the model class
+require_once (JApplicationHelper::getPath('admin_html'));
+require_once (JApplicationHelper::getPath('class'));
+
+$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
+
+/*
+ * This is our main control structure for the component
+ *
+ * Each view is determined by the $task variable
+ */
+switch ( JRequest::getVar( 'task' ) )
+{
+ case 'delete':
+ CacheController::deleteCache($cid);
+ CacheController::showCache();
+ break;
+ case 'purgeadmin':
+ CacheController::showPurgeCache();
+ break;
+ case 'purge':
+ CacheController::purgeCache();
+ break;
+ default :
+ CacheController::showCache();
+ break;
+}
+
+/**
+ * Static class to hold controller functions for the Cache component
+ *
+ * @static
+ * @package Joomla
+ * @subpackage Weblinks
+ * @since 1.5
+ */
+class CacheController
+{
+ /**
+ * Show the cache
+ *
+ * @since 1.5
+ */
+ function showCache()
+ {
+ global $mainframe, $option;
+ $submenu = JRequest::getVar('client', '0', '', 'int');
+ $client =& JApplicationHelper::getClientInfo($submenu);
+ if ($submenu == 1) {
+ JSubMenuHelper::addEntry(JText::_('Site'), 'index.php?option=com_cache&client=0');
+ JSubMenuHelper::addEntry(JText::_('Administrator'), 'index.php?option=com_cache&client=1', true);
+ } else {
+ JSubMenuHelper::addEntry(JText::_('Site'), 'index.php?option=com_cache&client=0', true);
+ JSubMenuHelper::addEntry(JText::_('Administrator'), 'index.php?option=com_cache&client=1');
+ }
+
+ $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'));
+ $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0 );
+
+ $cmData = new CacheData($client->path.DS.'cache');
+
+ jimport('joomla.html.pagination');
+ $pageNav = new JPagination( $cmData->getGroupCount(), $limitstart, $limit );
+
+ CacheView::displayCache( $cmData->getRows( $limitstart, $limit ), $client, $pageNav );
+ }
+
+ function deleteCache($cid)
+ {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
+
+ $cmData = new CacheData($client->path.DS.'cache');
+ $cmData->cleanCacheList( $cid );
+ }
+ function showPurgeCache()
+ {
+ // Check for request forgeries
+ CacheView::showPurgeExecute();
+ }
+ function purgeCache()
+ {
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+ $cache =& JFactory::getCache('');
+ $cache->gc();
+ CacheView::purgeSuccess();
+ }
+}
diff --git a/oss/joomla/trunk/administrator/components/com_cache/cache.class.php b/oss/joomla/trunk/administrator/components/com_cache/cache.class.php
new file mode 100644
index 00000000..324edd3c
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_cache/cache.class.php
@@ -0,0 +1,161 @@
+_path = $path;
+ $this->_parse();
+ }
+
+ /**
+ * Parse $path for cache file groups. Any files identifided as cache are logged
+ * in a group and stored in $this->items.
+ *
+ * @access private
+ * @param String $path
+ */
+ function _parse()
+ {
+ jimport('joomla.filesystem.folder');
+ jimport('joomla.filesystem.file');
+ $folders = JFolder::folders($this->_path);
+
+ foreach ($folders as $folder)
+ {
+ $files = array();
+ $files = JFolder::files($this->_path.DS.$folder);
+ $this->_items[$folder] = new CacheItem( $folder );
+
+ foreach ($files as $file)
+ {
+ $this->_items[$folder]->updateSize( filesize( $this->_path.DS.$folder.DS.$file )/ 1024 );
+ }
+ }
+ }
+
+ /**
+ * Get the number of current Cache Groups
+ *
+ * @access public
+ * @return int
+ */
+ function getGroupCount()
+ {
+ return count($this->_items);
+ }
+
+ /**
+ * Retrun an Array containing a sub set of the total
+ * number of Cache Groups as defined by the params.
+ *
+ * @access public
+ * @param Int $start
+ * @param Int $limit
+ * @return Array
+ */
+ function getRows( $start, $limit )
+ {
+ $i = 0;
+ $rows = array();
+ if (!is_array($this->_items)) {
+ return null;
+ }
+
+ foreach ($this->_items as $item)
+ {
+ if ( (($i >= $start) && ($i < $start+$limit)) || ($limit == 0) ) {
+ $rows[] = $item;
+ }
+ $i++;
+ }
+ return $rows;
+ }
+
+ /**
+ * Clean out a cache group as named by param.
+ * If no param is passed clean all cache groups.
+ *
+ * @param String $group
+ */
+ function cleanCache( $group='' )
+ {
+ $cache =& JFactory::getCache('', 'callback', 'file');
+ $cache->clean( $group );
+ }
+
+ function cleanCacheList( $array )
+ {
+ foreach ($array as $group) {
+ $this->cleanCache( $group );
+ }
+ }
+}
+
+ /**
+ * This Class is used by CacheData to store group cache data.
+ *
+ * @package Joomla
+ * @subpackage Cache
+ * @since 1.5
+ */
+class CacheItem
+{
+ var $group = "";
+ var $size = 0;
+ var $count = 0;
+
+ function CacheItem ( $group )
+ {
+ $this->group = $group;
+ }
+
+ function updateSize( $size )
+ {
+ $this->size = number_format( $this->size + $size, 2 );
+ $this->count++;
+ }
+}
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_cache/cache.xml b/oss/joomla/trunk/administrator/components/com_cache/cache.xml
new file mode 100644
index 00000000..d40334be
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_cache/cache.xml
@@ -0,0 +1,12 @@
+
+
+ Cache Manager
+ Joomla! Project
+ 2006
+ 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
+ Cache Manager
+
diff --git a/oss/joomla/trunk/administrator/components/com_cache/index.html b/oss/joomla/trunk/administrator/components/com_cache/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_cache/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_cache/toolbar.cache.html.php b/oss/joomla/trunk/administrator/components/com_cache/toolbar.cache.html.php
new file mode 100644
index 00000000..44925b8e
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_cache/toolbar.cache.html.php
@@ -0,0 +1,40 @@
+
+
+ image == '') {
+ $row->image = 'blank.png';
+ }
+
+ if ( $redirect == 'content' ) {
+ $component = 'Content';
+ } else {
+ $component = ucfirst( substr( $redirect, 4 ) );
+ if ( $redirect == 'com_contact_details' ) {
+ $component = 'Contact';
+ }
+ }
+
+ JFilterOutput::objectHTMLSafe( $row, ENT_QUOTES, 'description' );
+ $cparams = JComponentHelper::getParams ('com_media');
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+ getUserStateFromRequest( $option.'.filter_order', 'filter_order', 'c.ordering', 'cmd' );
+ $filter_order_Dir = $mainframe->getUserStateFromRequest( $option.'.filter_order_Dir', 'filter_order_Dir', '', 'word' );
+ $filter_state = $mainframe->getUserStateFromRequest( $option.'.'.$section.'.filter_state', 'filter_state', '', 'word' );
+ $sectionid = $mainframe->getUserStateFromRequest( $option.'.'.$section.'.sectionid', 'sectionid', 0, 'int' );
+ $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' );
+
+ $section_name = '';
+ $content_add = '';
+ $content_join = '';
+ $order = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', c.ordering';
+ if (intval( $section ) > 0) {
+ $table = 'content';
+
+ $query = 'SELECT title'
+ . ' FROM #__sections'
+ . ' WHERE id = '.(int) $section;
+ $db->setQuery( $query );
+ $section_name = $db->loadResult();
+ $section_name = JText::sprintf( 'Content:', JText::_( $section_name ) );
+ $where = ' WHERE c.section = '.$db->Quote($section);
+ $type = 'content';
+ } else if (strpos( $section, 'com_' ) === 0) {
+ $table = substr( $section, 4 );
+
+ $query = 'SELECT name'
+ . ' FROM #__components'
+ . ' WHERE link = '.$db->Quote('option='.$section);
+ ;
+ $db->setQuery( $query );
+ $section_name = $db->loadResult();
+ $where = ' WHERE c.section = '.$db->Quote($section);
+ $type = 'other';
+ // special handling for contact component
+ if ( $section == 'com_contact_details' ) {
+ $section_name = JText::_( 'Contact' );
+ }
+ $section_name = JText::sprintf( 'Component:', $section_name );
+ } else {
+ $table = $section;
+ $where = ' WHERE c.section = '.$db->Quote($section);
+ $type = 'other';
+ }
+
+ // get the total number of records
+ $query = 'SELECT COUNT(*)'
+ . ' FROM #__categories'
+ ;
+ if ($section == 'com_content')
+ {
+ if($sectionid > 0)
+ {
+ $query .= ' WHERE section = '.(int) $sectionid;
+ } else {
+ $query .= ' WHERE section > 0';
+ }
+ } else {
+ $query .= ' WHERE section = '.$db->quote($section);
+ }
+ if ( $filter_state ) {
+ if ( $filter_state == 'P' ) {
+ $query .= ' AND published = 1';
+ } else if ($filter_state == 'U' ) {
+ $query .= ' AND published = 0';
+ }
+ }
+ $db->setQuery( $query );
+ $total = $db->loadResult();
+
+ // allows for viweing of all content categories
+ if ( $section == 'com_content' ) {
+ $table = 'content';
+ $content_add = ' , z.title AS section_name';
+ $content_join = ' LEFT JOIN #__sections AS z ON z.id = c.section';
+ $where = ' WHERE c.section NOT LIKE "%com_%"';
+ if ($filter_order == 'c.ordering'){
+ $order = ' ORDER BY z.title, c.ordering '. $filter_order_Dir;
+ } else {
+ $order = ' ORDER BY '.$filter_order.' '. $filter_order_Dir.', z.title, c.ordering';
+ }
+
+ $section_name = JText::_( 'All Content:' );
+
+ $type = 'content';
+ }
+
+ // used by filter
+ if ( $sectionid > 0 ) {
+ $filter = ' AND c.section = '.$db->Quote($sectionid);
+ } else {
+ $filter = '';
+ }
+ if ( $filter_state ) {
+ if ( $filter_state == 'P' ) {
+ $filter .= ' AND c.published = 1';
+ } else if ($filter_state == 'U' ) {
+ $filter .= ' AND c.published = 0';
+ }
+ }
+ if ($search) {
+ $filter .= ' AND LOWER(c.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
+ }
+
+ jimport('joomla.html.pagination');
+ $pageNav = new JPagination( $total, $limitstart, $limit );
+
+ $tablesAllowed = $db->getTableList();
+ if (!in_array($db->getPrefix().$table, $tablesAllowed)) {
+ $table = 'content';
+ }
+
+ $query = 'SELECT c.*, c.checked_out as checked_out_contact_category, g.name AS groupname, u.name AS editor, COUNT( DISTINCT s2.checked_out ) AS checked_out_count'
+ . $content_add
+ . ' FROM #__categories AS c'
+ . ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
+ . ' LEFT JOIN #__groups AS g ON g.id = c.access'
+ . ' LEFT JOIN #__'.$table.' AS s2 ON s2.catid = c.id AND s2.checked_out > 0'
+ . $content_join
+ . $where
+ . $filter
+ . ' AND c.published != -2'
+ . ' GROUP BY c.id'
+ . $order
+ ;
+ $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
+ $rows = $db->loadObjectList();
+ if ($db->getErrorNum()) {
+ echo $db->stderr();
+ return;
+ }
+
+ $count = count( $rows );
+ // number of Active Items
+ for ( $i = 0; $i < $count; $i++ ) {
+ $query = 'SELECT COUNT( a.id )'
+ . ' FROM #__content AS a'
+ . ' WHERE a.catid = '. (int) $rows[$i]->id
+ . ' AND a.state <> -2'
+ ;
+ $db->setQuery( $query );
+ $active = $db->loadResult();
+ $rows[$i]->active = $active;
+ }
+ // number of Trashed Items
+ for ( $i = 0; $i < $count; $i++ ) {
+ $query = 'SELECT COUNT( a.id )'
+ . ' FROM #__content AS a'
+ . ' WHERE a.catid = '. (int) $rows[$i]->id
+ . ' AND a.state = -2'
+ ;
+ $db->setQuery( $query );
+ $trash = $db->loadResult();
+ $rows[$i]->trash = $trash;
+ }
+
+ // get list of sections for dropdown filter
+ $javascript = 'onchange="document.adminForm.submit();"';
+ $lists['sectionid'] = JHTML::_('list.section', 'sectionid', $sectionid, $javascript, 'ordering', 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;
+
+ categories_html::show( $rows, $section, $section_name, $pageNav, $lists, $type );
+}
+
+/**
+* Compiles information to add or edit a category
+* @param string The name of the category section
+* @param integer The unique id of the category to edit (0 if new)
+* @param string The name of the current user
+*/
+function editCategory($edit )
+{
+ global $mainframe;
+
+ // Initialize variables
+ $db =& JFactory::getDBO();
+ $user =& JFactory::getUser();
+ $uid = $user->get('id');
+
+ $type = JRequest::getCmd( 'type' );
+ $redirect = JRequest::getCmd( 'section', 'com_content' );
+ $section = JRequest::getCmd( 'section', 'com_content' );
+ $cid = JRequest::getVar( 'cid', array(0), '', 'array' );
+
+ JArrayHelper::toInteger($cid, array(0));
+
+ // check for existance of any sections
+ $query = 'SELECT COUNT( id )'
+ . ' FROM #__sections'
+ . ' WHERE scope = "content"'
+ ;
+ $db->setQuery( $query );
+ $sections = $db->loadResult();
+ if (!$sections && $type != 'other'
+ && $section != 'com_weblinks'
+ && $section != 'com_newsfeeds'
+ && $section != 'com_contact_details'
+ && $section != 'com_banner') {
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $section, JText::_( 'WARNSECTION', true ) );
+ }
+
+ $row =& JTable::getInstance('category');
+ // load the row from the db table
+ if ($edit)
+ $row->load( $cid[0] );
+
+ // fail if checked out not by 'me'
+ if ( JTable::isCheckedOut($user->get ('id'), $row->checked_out )) {
+ $msg = JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The category' ), $row->title );
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $row->section, $msg );
+ }
+
+ if ( $edit ) {
+ $row->checkout( $user->get('id'));
+ } else {
+ $row->published = 1;
+ }
+
+
+ // make order list
+ $order = array();
+ $query = 'SELECT COUNT(*)'
+ . ' FROM #__categories'
+ . ' WHERE section = '.$db->Quote($row->section)
+ ;
+ $db->setQuery( $query );
+ $max = intval( $db->loadResult() ) + 1;
+
+ for ($i=1; $i < $max; $i++) {
+ $order[] = JHTML::_('select.option', $i );
+ }
+
+ // build the html select list for sections
+ if ( $section == 'com_content' ) {
+
+ if (!$row->section && JRequest::getInt('sectionid')) {
+ $row->section = JRequest::getInt('sectionid');
+ }
+
+ $query = 'SELECT s.id AS value, s.title AS text'
+ . ' FROM #__sections AS s'
+ . ' ORDER BY s.ordering'
+ ;
+ $db->setQuery( $query );
+ $sections = $db->loadObjectList();
+ $lists['section'] = JHTML::_('select.genericlist', $sections, 'section', 'class="inputbox" size="1"', 'value', 'text', $row->section );
+ } else {
+ if ( $type == 'other' ) {
+ $section_name = JText::_( 'N/A' );
+ } else {
+ $temp =& JTable::getInstance('section');
+ $temp->load( $row->section );
+ $section_name = $temp->name;
+ }
+ if(!$section_name) $section_name = JText::_( 'N/A' );
+ $row->section = $section;
+ $lists['section'] = ' '. $section_name;
+ }
+
+ // build the html select list for ordering
+ $query = 'SELECT ordering AS value, title AS text'
+ . ' FROM #__categories'
+ . ' WHERE section = '.$db->Quote($row->section)
+ . ' ORDER BY ordering'
+ ;
+ if ($edit) {
+ $lists['ordering'] = JHTML::_('list.specificordering', $row, $cid[0], $query );
+ }
+ else {
+ $lists['ordering'] = JHTML::_('list.specificordering', $row, '', $query );
+ }
+ // build the select list for the image positions
+ $active = ( $row->image_position ? $row->image_position : 'left' );
+ $lists['image_position'] = JHTML::_('list.positions', 'image_position', $active, NULL, 0, 0 );
+ // Imagelist
+ $lists['image'] = JHTML::_('list.images', 'image', $row->image );
+ // build the html select list for the group access
+ $lists['access'] = JHTML::_('list.accesslevel', $row );
+ // build the html radio buttons for published
+ $published = ($row->id) ? $row->published : 1;
+ $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $published );
+
+ categories_html::edit( $row, $lists, $redirect );
+}
+
+/**
+* Saves the catefory after an edit form submit
+* @param string The name of the category section
+*/
+function saveCategory()
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ // Initialize variables
+ $db =& JFactory::getDBO();
+ $menu = JRequest::getCmd( 'menu', 'mainmenu', 'post' );
+ $menuid = JRequest::getVar( 'menuid', 0, 'post', 'int' );
+ $redirect = JRequest::getCmd( 'redirect', '', 'post' );
+ $oldtitle = JRequest::getString( 'oldtitle', '', 'post' );
+ $post = JRequest::get( 'post' );
+
+ // fix up special html fields
+ $post['description'] = JRequest::getVar( 'description', '', 'post', 'string', JREQUEST_ALLOWRAW );
+
+ $row =& JTable::getInstance('category');
+ if (!$row->bind( $post )) {
+ JError::raiseError(500, $row->getError() );
+ }
+ if (!$row->check()) {
+ JError::raiseError(500, $row->getError() );
+ }
+ // if new item order last in appropriate group
+ if (!$row->id) {
+ $where = "section = " . $db->Quote($row->section);
+ $row->ordering = $row->getNextOrder( $where );
+ }
+
+ if (!$row->store()) {
+ JError::raiseError(500, $row->getError() );
+ }
+ $row->checkin();
+
+ if ($row->section > 0) {
+ $query = 'UPDATE #__content'
+ .' SET sectionid = '.$row->section
+ .' WHERE catid = '.$row->id
+ ;
+ $db->setQuery( $query );
+ $db->query();
+ }
+
+ if ( $oldtitle ) {
+ if ($oldtitle != $row->title) {
+ $query = 'UPDATE #__menu'
+ . ' SET name = '.$db->Quote($row->title)
+ . ' WHERE name = '.$db->Quote($oldtitle)
+ . ' AND type = "content_category"'
+ ;
+ $db->setQuery( $query );
+ $db->query();
+ }
+ }
+
+ // Update Section Count
+ if ($row->section != 'com_contact_details' &&
+ $row->section != 'com_newsfeeds' &&
+ $row->section != 'com_weblinks') {
+ $query = 'UPDATE #__sections SET count=count+1'
+ . ' WHERE id = '.$db->Quote($row->section)
+ ;
+ $db->setQuery( $query );
+ }
+
+ if (!$db->query()) {
+ JError::raiseError(500, $db->getErrorMsg() );
+ }
+
+ switch ( JRequest::getCmd('task') )
+ {
+ case 'go2menu':
+ $mainframe->redirect( 'index.php?option=com_menus&menutype='. $menu );
+ break;
+
+ case 'go2menuitem':
+ $mainframe->redirect( 'index.php?option=com_menus&menutype='. $menu .'&task=edit&id='. $menuid );
+ break;
+
+ case 'apply':
+ $msg = JText::_( 'Changes to Category saved' );
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $redirect .'&task=edit&cid[]='. $row->id, $msg );
+ break;
+
+ case 'save':
+ default:
+ $msg = JText::_( 'Category saved' );
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $redirect, $msg );
+ break;
+ }
+}
+
+/**
+* Deletes one or more categories from the categories table
+* @param string The name of the category section
+* @param array An array of unique category id numbers
+*/
+function removeCategories( $section, $cid )
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ // Initialize variables
+ $db =& JFactory::getDBO();
+
+ JArrayHelper::toInteger($cid);
+
+ if (count( $cid ) < 1) {
+ JError::raiseError(500, JText::_( 'Select a category to delete', true ));
+ }
+
+ $cids = implode( ',', $cid );
+
+ if (intval( $section ) > 0) {
+ $table = 'content';
+ } else if (strpos( $section, 'com_' ) === 0) {
+ $table = substr( $section, 4 );
+ } else {
+ $table = $section;
+ }
+
+ $tablesAllowed = $db->getTableList();
+ if (!in_array($db->getPrefix().$table, $tablesAllowed)) {
+ $table = 'content';
+ }
+
+ $query = 'SELECT c.id, c.name, c.title, COUNT( s.catid ) AS numcat'
+ . ' FROM #__categories AS c'
+ . ' LEFT JOIN #__'.$table.' AS s ON s.catid = c.id'
+ . ' WHERE c.id IN ( '.$cids.' )'
+ . ' GROUP BY c.id'
+ ;
+ $db->setQuery( $query );
+
+ if (!($rows = $db->loadObjectList())) {
+ JError::raiseError( 500, $db->stderr() );
+ return false;
+ }
+
+ $err = array();
+ $cid = array();
+ foreach ($rows as $row) {
+ if ($row->numcat == 0) {
+ $cid[] = (int) $row->id;
+ } else {
+ $err[] = $row->title;
+ }
+ }
+
+ if (count( $cid )) {
+ $cids = implode( ',', $cid );
+ $query = 'DELETE FROM #__categories'
+ . ' WHERE id IN ( '.$cids.' )'
+ ;
+ $db->setQuery( $query );
+ if (!$db->query()) {
+ JError::raiseError( 500, $db->stderr() );
+ return false;
+ }
+ }
+
+ if (count( $err )) {
+ $cids = implode( ", ", $err );
+ $msg = JText::sprintf( 'WARNNOTREMOVEDRECORDS', $cids );
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $section, $msg );
+ }
+
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $section );
+}
+
+/**
+* Publishes or Unpublishes one or more categories
+* @param string The name of the category section
+* @param integer A unique category id (passed from an edit form)
+* @param array An array of unique category id numbers
+* @param integer 0 if unpublishing, 1 if publishing
+* @param string The name of the current user
+*/
+function publishCategories( $section, $cid=null, $publish=1 )
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ // Initialize variables
+ $db =& JFactory::getDBO();
+ $user =& JFactory::getUser();
+ $uid = $user->get('id');
+
+ JArrayHelper::toInteger($cid);
+
+ if (count( $cid ) < 1) {
+ $action = $publish ? 'publish' : 'unpublish';
+ JError::raiseError(500, JText::_( 'Select a category to '.$action, true ) );
+ }
+
+ $cids = implode( ',', $cid );
+
+ $query = 'UPDATE #__categories'
+ . ' SET published = ' . (int) $publish
+ . ' WHERE id IN ( '.$cids.' )'
+ . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $uid.' ) )'
+ ;
+ $db->setQuery( $query );
+ if (!$db->query()) {
+ JError::raiseError(500, $db->getErrorMsg() );
+ }
+
+ if (count( $cid ) == 1) {
+ $row =& JTable::getInstance('category');
+ $row->checkin( $cid[0] );
+ }
+
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $section );
+}
+
+/**
+* Cancels an edit operation
+* @param string The name of the category section
+* @param integer A unique category id
+*/
+function cancelCategory()
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ // Initialize variables
+ $db =& JFactory::getDBO();
+
+ $redirect = JRequest::getCmd( 'redirect', '', 'post' );
+
+ $row =& JTable::getInstance('category');
+ $row->bind( JRequest::get( 'post' ));
+ $row->checkin();
+
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $redirect );
+}
+
+/**
+* Moves the order of a record
+* @param integer The increment to reorder by
+*/
+function orderCategory( $uid, $inc )
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ // Initialize variables
+ $db =& JFactory::getDBO();
+ $row =& JTable::getInstance('category' );
+ $row->load( $uid );
+ $row->move( $inc, 'section = '.$db->Quote($row->section) );
+ $section = JRequest::getCmd('section');
+ if($section) {
+ $section = '§ion='. $section;
+ }
+ $mainframe->redirect( 'index.php?option=com_categories'. $section );
+}
+
+/**
+* Form for moving item(s) to a specific menu
+*/
+function moveCategorySelect( $option, $cid, $sectionOld )
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $db =& JFactory::getDBO();
+ $redirect = JRequest::getCmd( 'section', 'com_content', 'post' );
+
+ JArrayHelper::toInteger($cid);
+
+ if (count( $cid ) < 1) {
+ JError::raiseError(500, JText::_( 'Select an item to move', true ));
+ }
+
+ ## query to list selected categories
+ $cids = implode( ',', $cid );
+ $query = 'SELECT a.title, a.section'
+ . ' FROM #__categories AS a'
+ . ' WHERE a.id IN ( '.$cids.' )'
+ ;
+ $db->setQuery( $query );
+ $items = $db->loadObjectList();
+
+ ## query to list items from categories
+ $query = 'SELECT a.title'
+ . ' FROM #__content AS a'
+ . ' WHERE a.catid IN ( '.$cids.' )'
+ . ' ORDER BY a.catid, a.title'
+ ;
+ $db->setQuery( $query );
+ $contents = $db->loadObjectList();
+
+ ## query to choose section to move to
+ $query = 'SELECT a.title AS text, a.id AS value'
+ . ' FROM #__sections AS a'
+ . ' WHERE a.published = 1'
+ . ' ORDER BY a.title'
+ ;
+ $db->setQuery( $query );
+ $sections = $db->loadObjectList();
+
+ // build the html select list
+ $SectionList = JHTML::_('select.genericlist', $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null );
+
+ categories_html::moveCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect );
+}
+
+
+/**
+* Save the item(s) to the menu selected
+*/
+function moveCategorySave( $cid, $sectionOld )
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $db =& JFactory::getDBO();
+ $sectionMove = JRequest::getCmd( 'sectionmove' );
+
+ //Check to see of a section was selected to copy the items too
+ if (!$sectionMove)
+ {
+ $msg = JText::_('Please select a section from the list');
+ moveCategorySelect( 'com_categories', $cid, $sectionOld );
+ JError::raiseWarning(500, $msg);
+ return;
+ }
+
+ JArrayHelper::toInteger($cid, array(0));
+
+ $sectionNew =& JTable::getInstance('section');
+ $sectionNew->load( $sectionMove );
+
+ //Remove the categories was in destination section
+ $cids = implode( ',', $cid );
+
+ $query = 'SELECT id, title'
+ . ' FROM #__categories'
+ . ' WHERE id IN ( '.$cids.' )'
+ . ' AND section = '.$db->Quote($sectionMove)
+ ;
+ $db->setQuery( $query );
+
+ $scid = $db->loadResultArray(0);
+ $title = $db->loadResultArray(1);
+
+ $cid = array_diff($cid, $scid);
+
+ //
+ if ( !empty($cid) ) {
+ $cids = implode( ',', $cid );
+ $total = count( $cid );
+
+ $query = 'UPDATE #__categories'
+ . ' SET section = '.$db->Quote($sectionMove)
+ . ' WHERE id IN ( '.$cids.' )'
+ ;
+ $db->setQuery( $query );
+ if ( !$db->query() ) {
+ JError::raiseError(500, $db->getErrorMsg() );
+ }
+ $query = 'UPDATE #__content'
+ . ' SET sectionid = '.$db->Quote($sectionMove)
+ . ' WHERE catid IN ( '.$cids.' )'
+ ;
+ $db->setQuery( $query );
+ if ( !$db->query() ) {
+ JError::raiseError(500, $db->getErrorMsg());
+ }
+
+ $msg = JText::sprintf( 'Categories moved to', $sectionNew->title );
+ $mainframe->enqueueMessage($msg);
+ }
+ if ( !empty($title) && is_array($title) ) {
+ if ( count($title) == 1 ) {
+ $msg = JText::sprintf( 'Category already in', implode( ', ', $title ), $sectionNew->title );
+ } else {
+ $msg = JText::sprintf( 'Categories already in', implode( ', ', $title ), $sectionNew->title );
+ }
+ $mainframe->enqueueMessage($msg);
+ }
+
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $sectionOld );
+}
+
+/**
+* Form for copying item(s) to a specific menu
+*/
+function copyCategorySelect( $option, $cid, $sectionOld )
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ $db =& JFactory::getDBO();
+ $redirect = JRequest::getCmd( 'section', 'com_content', 'post' );
+
+ JArrayHelper::toInteger($cid);
+
+ if (count( $cid ) < 1) {
+ JError::raiseError(500, JText::_( 'Select an item to move', true ));
+ }
+
+ ## query to list selected categories
+ $cids = implode( ',', $cid );
+ $query = 'SELECT a.title, a.section'
+ . ' FROM #__categories AS a'
+ . ' WHERE a.id IN ( '.$cids.' )'
+ ;
+ $db->setQuery( $query );
+ $items = $db->loadObjectList();
+
+ ## query to list items from categories
+ $query = 'SELECT a.title, a.id'
+ . ' FROM #__content AS a'
+ . ' WHERE a.catid IN ( '.$cids.' )'
+ . ' ORDER BY a.catid, a.title'
+ ;
+ $db->setQuery( $query );
+ $contents = $db->loadObjectList();
+
+ ## query to choose section to move to
+ $query = 'SELECT a.title AS `text`, a.id AS `value`'
+ . ' FROM #__sections AS a'
+ . ' WHERE a.published = 1'
+ . ' ORDER BY a.name'
+ ;
+ $db->setQuery( $query );
+ $sections = $db->loadObjectList();
+
+ // build the html select list
+ $SectionList = JHTML::_('select.genericlist', $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null );
+
+ categories_html::copyCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect );
+}
+
+
+/**
+* Save the item(s) to the menu selected
+*/
+function copyCategorySave( $cid, $sectionOld )
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ // Initialize variables
+ $db =& JFactory::getDBO();
+
+ $sectionMove = JRequest::getInt( 'sectionmove' );
+
+ //Check to see of a section was selected to copy the items too
+ if (!$sectionMove)
+ {
+ $msg = JText::_('Please select a section from the list');
+ copyCategorySelect( 'com_categories', $cid, $sectionOld );
+ JError::raiseWarning(500, $msg);
+ return;
+ }
+
+ $contentid = JRequest::getVar( 'item', null, '', 'array' );
+ JArrayHelper::toInteger($contentid);
+
+ $category =& JTable::getInstance('category');
+
+ foreach( $cid as $id )
+ {
+ $category->load( $id );
+ $category->id = NULL;
+ $category->title = JText::sprintf( 'Copy of', $category->title );
+ $category->name = JText::sprintf( 'Copy of', $category->name );
+ $category->section = $sectionMove;
+ if (!$category->check()) {
+ JError::raiseError(500, $category->getError());
+ }
+
+ if (!$category->store()) {
+ JError::raiseError(500, $category->getError());
+ }
+ $category->checkin();
+ // stores original catid
+ $newcatids[]["old"] = $id;
+ // pulls new catid
+ $newcatids[]["new"] = $category->id;
+ }
+
+ $content =& JTable::getInstance('content');
+ foreach( $contentid as $id) {
+ $content->load( $id );
+ $content->id = NULL;
+ $content->sectionid = $sectionMove;
+ $content->hits = 0;
+ foreach( $newcatids as $newcatid ) {
+ if ( $content->catid == $newcatid["old"] ) {
+ $content->catid = $newcatid["new"];
+ }
+ }
+ if (!$content->check()) {
+ JError::raiseError(500, $content->getError());
+ }
+
+ if (!$content->store()) {
+ JError::raiseError(500, $content->getError());
+ }
+ $content->checkin();
+ }
+
+ $sectionNew =& JTable::getInstance('section');
+ $sectionNew->load( $sectionMove );
+
+ $msg = JText::sprintf( 'Categories copied to', count($cid), $sectionNew->title );
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $sectionOld, $msg );
+}
+
+/**
+* changes the access level of a record
+* @param integer The increment to reorder by
+*/
+function accessMenu( $uid, $access, $section )
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ // Initialize variables
+ $db =& JFactory::getDBO();
+
+ $row =& JTable::getInstance('category');
+ $row->load( $uid );
+ $row->access = $access;
+
+ if ( !$row->check() ) {
+ return $row->getError();
+ }
+ if ( !$row->store() ) {
+ return $row->getError();
+ }
+
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $section );
+}
+
+function saveOrder( &$cid, $section )
+{
+ global $mainframe;
+
+ // Check for request forgeries
+ JRequest::checkToken() or jexit( 'Invalid Token' );
+
+ // Initialize variables
+ $db =& JFactory::getDBO();
+
+ $total = count( $cid );
+ $order = JRequest::getVar( 'order', array(0), 'post', 'array' );
+ JArrayHelper::toInteger($order, array(0));
+ $row =& JTable::getInstance('category');
+ $groupings = array();
+
+ // update ordering values
+ for( $i=0; $i < $total; $i++ ) {
+ $row->load( (int) $cid[$i] );
+ // track sections
+ $groupings[] = $row->section;
+ if ($row->ordering != $order[$i]) {
+ $row->ordering = $order[$i];
+ if (!$row->store()) {
+ JError::raiseError(500, $db->getErrorMsg());
+ }
+ }
+ }
+
+ // execute updateOrder for each parent group
+ $groupings = array_unique( $groupings );
+ foreach ($groupings as $group){
+ $row->reorder('section = '.$db->Quote($group));
+ }
+
+ $msg = JText::_( 'New ordering saved' );
+ $mainframe->redirect( 'index.php?option=com_categories§ion='. $section, $msg );
+}
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_categories/index.html b/oss/joomla/trunk/administrator/components/com_categories/index.html
new file mode 100644
index 00000000..fa6d84e8
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_categories/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_categories/toolbar.categories.html.php b/oss/joomla/trunk/administrator/components/com_categories/toolbar.categories.html.php
new file mode 100644
index 00000000..26d6ea54
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_categories/toolbar.categories.html.php
@@ -0,0 +1,85 @@
+[ '. $text.' ] ', 'categories.png' );
+ JToolBarHelper::save();
+ JToolBarHelper::apply();
+ if ($edit) {
+ // for existing articles the button is renamed `close`
+ JToolBarHelper::cancel( 'cancel', 'Close' );
+ } else {
+ JToolBarHelper::cancel();
+ }
+ JToolBarHelper::help( 'screen.' . substr( $section, 4 ) . '.categories.edit' );
+ }
+
+ /**
+ * Draws the menu for Moving existing categories
+ * @param int The published state (to display the inverse button)
+ */
+ function _MOVE() {
+
+ JToolBarHelper::title( JText::_( 'Category' ) .': [ '. JText::_( 'Move' ).' ] ', 'categories.png' );
+ JToolBarHelper::save( 'movesave' );
+ JToolBarHelper::cancel();
+ }
+
+ /**
+ * Draws the menu for Copying existing categories
+ * @param int The published state (to display the inverse button)
+ */
+ function _COPY() {
+ JToolBarHelper::title( JText::_( 'Category' ) .': [ '. JText::_( 'Copy' ).' ] ', 'categories.png' );
+
+ JToolBarHelper::save( 'copysave' );
+ JToolBarHelper::cancel();
+ }
+
+ /**
+ * Draws the menu for Editing an existing category
+ */
+ function _DEFAULT()
+ {
+ $section = JRequest::getCmd( 'section' );
+
+ JToolBarHelper::title( JText::_( 'Category Manager' ) .': [ '. JText::_(JString::substr($section, 4)).' ] ', 'categories.png' );
+ JToolBarHelper::publishList();
+ JToolBarHelper::unpublishList();
+
+ if ( $section == 'com_content' || ( $section > 0 ) ) {
+ JToolBarHelper::customX( 'moveselect', 'move.png', 'move_f2.png', 'Move', true );
+ JToolBarHelper::customX( 'copyselect', 'copy.png', 'copy_f2.png', 'Copy', true );
+ }
+ JToolBarHelper::deleteList();
+ JToolBarHelper::editListX();
+ JToolBarHelper::addNewX();
+ JToolBarHelper::help( 'screen.' . substr( $section, 4 ) . '.categories' );
+ }
+}
\ No newline at end of file
diff --git a/oss/joomla/trunk/administrator/components/com_categories/toolbar.categories.php b/oss/joomla/trunk/administrator/components/com_categories/toolbar.categories.php
new file mode 100644
index 00000000..ba6c1238
--- /dev/null
+++ b/oss/joomla/trunk/administrator/components/com_categories/toolbar.categories.php
@@ -0,0 +1,44 @@
+