Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @version $Id: client.php 10381 2008-06-01 03:35:53Z pasamio $
- * @package Joomla
- * @subpackage Banners
- * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
- * @license GNU/GPL, see LICENSE.php
- * Joomla! is free software. This version may have been modified pursuant
- * to the GNU General Public License, and as distributed it includes or
- * is derivative of works licensed under the GNU General Public License or
- * other free or open source software licenses.
- * See COPYRIGHT.php for copyright notices and details.
- */
- // no direct access
- defined( '_JEXEC' ) or die( 'Restricted access' );
- jimport( 'joomla.application.component.controller' );
- /**
- * @package Joomla
- * @subpackage Banners
- */
- class EssayControllerWord extends JController
- {
- /**
- * Constructor
- */
- function __construct( $config = array() )
- {
- parent::__construct( $config );
- // Register Extra tasks
- $this->registerTask( 'add', 'edit' );
- $this->registerTask( 'apply', 'save' );
- }
- function display()
- {
- global $mainframe;
- $db =& JFactory::getDBO();
- $user =& JFactory::getUser();
- $context = 'com_essay.essayword.list.';
- $filter_order = $mainframe->getUserStateFromRequest( $context.'filter_order', 'filter_order', 'a.ordering', 'cmd' );
- $filter_order_Dir = $mainframe->getUserStateFromRequest( $context.'filter_order_Dir', 'filter_order_Dir', '', 'word' );
- $search = $mainframe->getUserStateFromRequest( $context.'search', 'search', '', 'string' );
- $search = JString::strtolower( $search );
- $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
- $limitstart = $mainframe->getUserStateFromRequest( $context.'limitstart', 'limitstart', 0, 'int' );
- $where = array();
- if ($search) {
- $where[] = 'LOWER(a.name) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
- }
- $where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
- $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', a.cid ASC';
- // get the total number of records
- $query = 'SELECT a.*, count(b.bid) AS nbanners'
- . ' FROM #__essay_word AS a'
- . ' LEFT JOIN #__essay_type AS b ON a.cid = b.cid'
- . ' LEFT JOIN #__users AS u ON u.id = a.checked_out'
- . $where
- . ' GROUP BY a.cid'
- . $orderby
- ;
- $db->setQuery( $query );
- $db->query();
- $total = $db->getNumRows();
- jimport('joomla.html.pagination');
- $pageNav = new JPagination( $total, $limitstart, $limit );
- $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
- $rows = $db->loadObjectList();
- // table ordering
- $lists['order_Dir'] = $filter_order_Dir;
- $lists['order'] = $filter_order;
- // search filter
- $lists['search']= $search;
- require_once(JPATH_COMPONENT.DS.'views'.DS.'word.php');
- EssayViewWord::words( $rows, $pageNav, $lists );
- }
- /**
- * Edit a banner client record
- */
- function edit()
- {
- // Initialize variables
- $db =& JFactory::getDBO();
- $user =& JFactory::getUser();
- $lists = array();
- $userId = $user->get ( 'id' );
- if ($this->_task == 'edit') {
- $cid = JRequest::getVar('cid', array(0), 'method', 'array');
- } else {
- $cid = array( 0 );
- }
- $row =& JTable::getInstance('essayword', 'Table');
- $row->load( (int) $cid[0] );
- // fail if checked out not by 'me'
- if ($row->isCheckedOut( $userId )) {
- $this->setRedirect( 'index.php?option=com_essay&c=word' );
- return JError::raiseWarning( JText::sprintf( 'WARNEDITEDBYPERSON', $row->name ) );
- }
- if ($row->cid) {
- // do stuff for existing record
- $row->checkout( $userId );
- } else {
- // do stuff for new record
- $row->published = 0;
- $row->approved = 0;
- }
- require_once(JPATH_COMPONENT.DS.'views'.DS.'word.php');
- EssayViewWord::word( $row , $lists );
- }
- function save()
- {
- // Check for request forgeries
- JRequest::checkToken() or jexit( 'Invalid Token' );
- $this->setRedirect( 'index.php?option=com_essay&c=word' );
- // Initialize variables
- $db =& JFactory::getDBO();
- $table =& JTable::getInstance('essayword', 'Table');
- if (!$table->bind( JRequest::get( 'post' ) )) {
- return JError::raiseWarning( 500, $table->getError() );
- }
- if (!$table->check()) {
- return JError::raiseWarning( 500, $table->getError() );
- }
- echo $table->type_id = implode(",", $table->type_id);
- if (!$table->store()) {
- return JError::raiseWarning( 500, $table->getError() );
- }
- $table->checkin();
- switch (JRequest::getCmd( 'task' ))
- {
- case 'apply':
- $this->setRedirect( 'index.php?option=com_essay&c=word&task=edit&cid[]='. $table->cid );
- break;
- }
- $this->setMessage( JText::_( 'Item Saved' ) );
- }
- function cancel()
- {
- // Check for request forgeries
- JRequest::checkToken() or jexit( 'Invalid Token' );
- $this->setRedirect( 'index.php?option=com_essay&c=word' );
- // Initialize variables
- $db =& JFactory::getDBO();
- $table =& JTable::getInstance('essayword', 'Table');
- $table->cid = JRequest::getVar( 'cid', 0, 'post', 'int' );
- $table->checkin();
- }
- function remove()
- {
- // Check for request forgeries
- JRequest::checkToken() or jexit( 'Invalid Token' );
- $this->setRedirect( 'index.php?option=com_essay&c=word' );
- // Initialize variables
- $db =& JFactory::getDBO();
- $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
- $table =& JTable::getInstance('essayword', 'Table');
- $n = count( $cid );
- for ($i = 0; $i < $n; $i++)
- {
- if (!$table->delete( (int) $cid[$i] )) {
- return JError::raiseWarning( 500, $table->getError() );
- }
- }
- $this->setMessage( JText::sprintf( 'Items removed', $n ) );
- }
- function orderup()
- {
- $cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
- JArrayHelper::toInteger($cid);
- if (isset($cid[0]) && $cid[0]) {
- $id = $cid[0];
- } else {
- $this->setRedirect( 'index.php?option=com_essay&c=word', JText::_('No Items Selected') );
- return false;
- }
- $row =& JTable::getInstance('essayword', 'Table');
- $row->load( $id );
- if (!$row->move( -1)) {
- $this->setError($row->getError());
- return false;
- }
- $msg = JText::_( 'Item Moved Up' );
- $this->setRedirect( 'index.php?option=com_essay&c=word', $msg );
- }
- /**
- * Save the item(s) to the menu selected
- */
- function orderdown()
- {
- $cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
- JArrayHelper::toInteger($cid);
- if (isset($cid[0]) && $cid[0]) {
- $id = $cid[0];
- } else {
- $this->setRedirect( 'index.php?option=com_essay&c=word', JText::_('No Items Selected') );
- return false;
- }
- $row =& JTable::getInstance('essayword', 'Table');
- $row->load( $id );
- if (!$row->move( 1)) {
- $this->setError($row->getError());
- return false;
- }
- $msg = JText::_( 'Item Moved Down' );
- $this->setRedirect( 'index.php?option=com_essay&c=word', $msg );
- }
- /**
- * Save the item(s) to the menu selected
- */
- function saveorder()
- {
- $cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
- JArrayHelper::toInteger($cid);
- $total = count( $cid );
- $row =& JTable::getInstance('essayword', 'Table');
- $order = JRequest::getVar( 'order', array(), 'post', 'array' );
- JArrayHelper::toInteger($order);
- // update ordering values
- for( $i=0; $i < $total; $i++ ) {
- $row->load( $cid[$i] );
- if ($row->ordering != $order[$i]) {
- $row->ordering = $order[$i];
- if (!$row->store()) {
- $this->setError($row->getError());
- return false;
- }
- } // if
- } // for
- $msg = JText::_( 'New ordering saved' );
- $this->setRedirect( 'index.php?option=com_essay&c=word', $msg );
- }
- }
Add Comment
Please, Sign In to add comment