<?php
/**
 * Pro Super Slider
 *This program is free software: you can redistribute it and/or modify it under the terms
 *of the GNU General Public License as published by the Free Software Foundation,
 *either version 3 of the License, or (at your option) any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 *You should have received a copy of the GNU General Public License
 *along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *@author ProJoom
 *@copyright (C) 2008 - 2012 ProJoom
 *@link http://www.projoom.com/extensions/pro-super-slider.html Official website
 **/
class NovassHelper
{
	public static function addSubmenu($vName)
	{
		JSubMenuHelper::addEntry(
			JText::_('Slides'),
			'index.php?option=com_novass&view=slides',
			$vName == 'slides'
		);

		JSubMenuHelper::addEntry(
			JText::_('Categories'),
			'index.php?option=com_categories&extension=com_novass',
			$vName == 'categories'
		);
        JSubMenuHelper::addEntry(
			JText::_('Uploader'),
			'index.php?option=com_novass&view=uploader',
			$vName == 'uploader'
		);
		if ($vName=='categories') {
			JToolBarHelper::title(
				JText::sprintf('Categories: ProJoom Super Slider',JText::_('com_novass')),
				'slides-categories');
		}

	}
	public static function getActions($categoryId = 0)
	{
		$user	= JFactory::getUser();
		$result	= new JObject;

		if (empty($categoryId)) {
			$assetName = 'com_novass';
		} else {
			$assetName = 'com_novass.category.'.(int) $categoryId;
		}

		$actions = array(
			'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.state', 'core.delete'
		);

		foreach ($actions as $action) {
			$result->set($action,	$user->authorise($action, $assetName));
		}

		return $result;
	}
	public static function updateReset()
	{
		$user = JFactory::getUser();
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->select('*');
		$query->from('#__novass');
		$query->where('NOW() >= `reset`');
		$query->where('`reset` != '.$db->quote('0000-00-00 00:00:00').' AND `reset`!=NULL');
		$query->where('(`checked_out` = 0 OR `checked_out` = '.(int) $db->Quote($user->id).')');
		$db->setQuery((string)$query);
		$rows = $db->loadObjectList();
		if ($db->getErrorNum()) {
			JError::raiseWarning(500, $db->getErrorMsg());
			return false;
		}

		JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');

		foreach ($rows as $row) {
			$query->clear();
			$query->update('`#__novass`');
			$query->set('`reset` = '.$db->quote($reset));
			$query->where('`id` = '.$db->quote($row->id));
			$db->setQuery((string)$query);
			$db->query();
			if ($db->getErrorNum()) {
				JError::raiseWarning(500, $db->getErrorMsg());
				return false;
			}
		}

		return true;
	}
    public static function isValid($pic){
		if(is_file(JPATH_ROOT ."/". $pic)){
			$ret = "<a class=\"modal\" rel=\"{handler: 'image'}\" href=\"".JURI::root().$pic."\"><img src=\"".JURI::root() . $pic."\" width=\"100\"/></a>";
		} else {
			$ret = "<a class=\"modal\" href=\"http://www.projoom.com/component/kb/article/images_are_not_loading.html?template=component\" rel=\"{handler: 'iframe', size: {x: 570, y: 550}}\">Invalid Image</a>";
		}
		return $ret;
	}
}
