Your IP : 216.73.216.240


Current Path : /home/s/u/n/sunflowe/www2/j15/administrator/components/com_easycaptcha/tables/
Upload File :
Current File : /home/s/u/n/sunflowe/www2/j15/administrator/components/com_easycaptcha/tables/captcha.php

<?php
/**
 * @version $Id: captcha.php 635 2008-03-18 08:46:38Z snipersister $
 * @package    EasyCaptcha
 * @link http://www.easy-joomla.org
 * @license    GNU/GPL
 */


// no direct access
defined('_JEXEC') or die('Restricted access');

class TableCaptcha extends JTable
{
    /**
     * Primary Key
     *
     * @var int
     */
    var $id = null;
    var $name = null;
    var $description = null;
    var $published = null;
    var $params = null;

    /**
     * Constructor
     *
     * @param object Database connector object
     */
    function TableCaptcha( &$db ) {
        parent::__construct('#__easycaptchas', 'id', $db);
    }
    

    function publish( $cid=null, $user_id=0 )
	{
		JArrayHelper::toInteger( $cid );
		$user_id	= (int) $user_id;
		$publish	= 1;
		$k			= $this->_tbl_key;

		if (count( $cid ) < 1)
		{
			if ($this->$k) {
				$cid = array( $this->$k );
			} else {
				$this->setError("No items selected.");
				return false;
			}
		}

		$cids = $k . '=' . implode( ' OR ' . $k . '=', $cid );
		$not_cids = $k . '!=' . implode( ' OR ' . $k . '!=', $cid );
		
		$query = 'UPDATE '. $this->_tbl
		. ' SET published = ' . (int) $publish
		. ' WHERE ('.$cids.')'
		;
		
		$checkin = in_array( 'checked_out', array_keys($this->getProperties()) );
		if ($checkin)
		{
			$query .= ' AND (checked_out = 0 OR checked_out = '.(int) $user_id.')';
		}

		$this->_db->setQuery( $query );
		if (!$this->_db->query())
		{
			$this->setError($this->_db->getErrorMsg());
			return false;
		}

		if (count( $cid ) == 1 && $checkin)
		{
			if ($this->_db->getAffectedRows() == 1) {
				$this->checkin( $cid[0] );
				if ($this->$k == $cid[0]) {
					$this->published = $publish;
				}
			}
		}
		$this->setError('');
		
		$query = 'UPDATE '. $this->_tbl
		. ' SET published = 0'
		. ' WHERE ('.$not_cids.')'
		;
		
		$this->_db->setQuery( $query );
		if (!$this->_db->query())
		{
			$this->setError($this->_db->getErrorMsg());
			return false;
		}
		
		return true;
	}
	
	function bind($array, $ignore = '')
	{
		if (key_exists( 'params', $array ) && is_array( $array['params'] ))
		{
			$registry = new JRegistry();
			$registry->loadArray($array['params']);
			$array['params'] = $registry->toString();
		}

		return parent::bind($array, $ignore);
	}
    
    
}
?>