Guest User

Untitled

a guest
Jul 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. <?php
  2. /**
  3. * @version $Id: client.php 10381 2008-06-01 03:35:53Z pasamio $
  4. * @package Joomla
  5. * @subpackage Banners
  6. * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. // no direct access
  16. defined( '_JEXEC' ) or die( 'Restricted access' );
  17.  
  18. jimport( 'joomla.application.component.controller' );
  19.  
  20. /**
  21. * @package Joomla
  22. * @subpackage Banners
  23. */
  24. class EssayControllerWord extends JController
  25. {
  26. /**
  27. * Constructor
  28. */
  29. function __construct( $config = array() )
  30. {
  31. parent::__construct( $config );
  32. // Register Extra tasks
  33. $this->registerTask( 'add', 'edit' );
  34. $this->registerTask( 'apply', 'save' );
  35. }
  36.  
  37. function display()
  38. {
  39. global $mainframe;
  40.  
  41. $db =& JFactory::getDBO();
  42. $user =& JFactory::getUser();
  43. $context = 'com_essay.essayword.list.';
  44. $filter_order = $mainframe->getUserStateFromRequest( $context.'filter_order', 'filter_order', 'a.ordering', 'cmd' );
  45. $filter_order_Dir = $mainframe->getUserStateFromRequest( $context.'filter_order_Dir', 'filter_order_Dir', '', 'word' );
  46. $search = $mainframe->getUserStateFromRequest( $context.'search', 'search', '', 'string' );
  47. $search = JString::strtolower( $search );
  48.  
  49. $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
  50. $limitstart = $mainframe->getUserStateFromRequest( $context.'limitstart', 'limitstart', 0, 'int' );
  51.  
  52. $where = array();
  53.  
  54. if ($search) {
  55. $where[] = 'LOWER(a.name) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
  56. }
  57.  
  58. $where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
  59. $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', a.cid ASC';
  60.  
  61. // get the total number of records
  62. $query = 'SELECT a.*, count(b.bid) AS nbanners'
  63. . ' FROM #__essay_word AS a'
  64. . ' LEFT JOIN #__essay_type AS b ON a.cid = b.cid'
  65. . ' LEFT JOIN #__users AS u ON u.id = a.checked_out'
  66. . $where
  67. . ' GROUP BY a.cid'
  68. . $orderby
  69. ;
  70.  
  71. $db->setQuery( $query );
  72. $db->query();
  73. $total = $db->getNumRows();
  74.  
  75. jimport('joomla.html.pagination');
  76. $pageNav = new JPagination( $total, $limitstart, $limit );
  77.  
  78. $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
  79. $rows = $db->loadObjectList();
  80.  
  81. // table ordering
  82. $lists['order_Dir'] = $filter_order_Dir;
  83. $lists['order'] = $filter_order;
  84.  
  85. // search filter
  86. $lists['search']= $search;
  87.  
  88. require_once(JPATH_COMPONENT.DS.'views'.DS.'word.php');
  89. EssayViewWord::words( $rows, $pageNav, $lists );
  90. }
  91.  
  92. /**
  93. * Edit a banner client record
  94. */
  95. function edit()
  96. {
  97. // Initialize variables
  98. $db =& JFactory::getDBO();
  99. $user =& JFactory::getUser();
  100. $lists = array();
  101. $userId = $user->get ( 'id' );
  102.  
  103. if ($this->_task == 'edit') {
  104. $cid = JRequest::getVar('cid', array(0), 'method', 'array');
  105. } else {
  106. $cid = array( 0 );
  107. }
  108.  
  109. $row =& JTable::getInstance('essayword', 'Table');
  110. $row->load( (int) $cid[0] );
  111.  
  112. // fail if checked out not by 'me'
  113. if ($row->isCheckedOut( $userId )) {
  114. $this->setRedirect( 'index.php?option=com_essay&c=word' );
  115. return JError::raiseWarning( JText::sprintf( 'WARNEDITEDBYPERSON', $row->name ) );
  116. }
  117.  
  118. if ($row->cid) {
  119. // do stuff for existing record
  120. $row->checkout( $userId );
  121. } else {
  122. // do stuff for new record
  123. $row->published = 0;
  124. $row->approved = 0;
  125. }
  126.  
  127.  
  128.  
  129. require_once(JPATH_COMPONENT.DS.'views'.DS.'word.php');
  130. EssayViewWord::word( $row , $lists );
  131. }
  132.  
  133. function save()
  134. {
  135. // Check for request forgeries
  136. JRequest::checkToken() or jexit( 'Invalid Token' );
  137.  
  138. $this->setRedirect( 'index.php?option=com_essay&c=word' );
  139.  
  140. // Initialize variables
  141. $db =& JFactory::getDBO();
  142. $table =& JTable::getInstance('essayword', 'Table');
  143.  
  144. if (!$table->bind( JRequest::get( 'post' ) )) {
  145. return JError::raiseWarning( 500, $table->getError() );
  146. }
  147. if (!$table->check()) {
  148. return JError::raiseWarning( 500, $table->getError() );
  149. }
  150.  
  151. echo $table->type_id = implode(",", $table->type_id);
  152.  
  153. if (!$table->store()) {
  154. return JError::raiseWarning( 500, $table->getError() );
  155. }
  156. $table->checkin();
  157.  
  158. switch (JRequest::getCmd( 'task' ))
  159. {
  160. case 'apply':
  161. $this->setRedirect( 'index.php?option=com_essay&c=word&task=edit&cid[]='. $table->cid );
  162. break;
  163. }
  164.  
  165. $this->setMessage( JText::_( 'Item Saved' ) );
  166. }
  167.  
  168. function cancel()
  169. {
  170. // Check for request forgeries
  171. JRequest::checkToken() or jexit( 'Invalid Token' );
  172.  
  173. $this->setRedirect( 'index.php?option=com_essay&c=word' );
  174.  
  175. // Initialize variables
  176. $db =& JFactory::getDBO();
  177. $table =& JTable::getInstance('essayword', 'Table');
  178. $table->cid = JRequest::getVar( 'cid', 0, 'post', 'int' );
  179. $table->checkin();
  180. }
  181.  
  182. function remove()
  183. {
  184. // Check for request forgeries
  185. JRequest::checkToken() or jexit( 'Invalid Token' );
  186.  
  187. $this->setRedirect( 'index.php?option=com_essay&c=word' );
  188.  
  189. // Initialize variables
  190. $db =& JFactory::getDBO();
  191. $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
  192. $table =& JTable::getInstance('essayword', 'Table');
  193. $n = count( $cid );
  194.  
  195. for ($i = 0; $i < $n; $i++)
  196. {
  197.  
  198.  
  199.  
  200. if (!$table->delete( (int) $cid[$i] )) {
  201. return JError::raiseWarning( 500, $table->getError() );
  202. }
  203.  
  204. }
  205.  
  206. $this->setMessage( JText::sprintf( 'Items removed', $n ) );
  207. }
  208.  
  209.  
  210. function orderup()
  211. {
  212. $cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
  213. JArrayHelper::toInteger($cid);
  214.  
  215. if (isset($cid[0]) && $cid[0]) {
  216. $id = $cid[0];
  217. } else {
  218. $this->setRedirect( 'index.php?option=com_essay&c=word', JText::_('No Items Selected') );
  219. return false;
  220. }
  221.  
  222. $row =& JTable::getInstance('essayword', 'Table');
  223. $row->load( $id );
  224. if (!$row->move( -1)) {
  225. $this->setError($row->getError());
  226. return false;
  227. }
  228.  
  229. $msg = JText::_( 'Item Moved Up' );
  230. $this->setRedirect( 'index.php?option=com_essay&c=word', $msg );
  231. }
  232.  
  233. /**
  234. * Save the item(s) to the menu selected
  235. */
  236. function orderdown()
  237. {
  238. $cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
  239. JArrayHelper::toInteger($cid);
  240.  
  241. if (isset($cid[0]) && $cid[0]) {
  242. $id = $cid[0];
  243. } else {
  244. $this->setRedirect( 'index.php?option=com_essay&c=word', JText::_('No Items Selected') );
  245. return false;
  246. }
  247.  
  248. $row =& JTable::getInstance('essayword', 'Table');
  249. $row->load( $id );
  250. if (!$row->move( 1)) {
  251. $this->setError($row->getError());
  252. return false;
  253. }
  254.  
  255. $msg = JText::_( 'Item Moved Down' );
  256. $this->setRedirect( 'index.php?option=com_essay&c=word', $msg );
  257. }
  258.  
  259. /**
  260. * Save the item(s) to the menu selected
  261. */
  262. function saveorder()
  263. {
  264. $cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
  265. JArrayHelper::toInteger($cid);
  266.  
  267. $total = count( $cid );
  268. $row =& JTable::getInstance('essayword', 'Table');
  269.  
  270. $order = JRequest::getVar( 'order', array(), 'post', 'array' );
  271. JArrayHelper::toInteger($order);
  272.  
  273. // update ordering values
  274. for( $i=0; $i < $total; $i++ ) {
  275. $row->load( $cid[$i] );
  276. if ($row->ordering != $order[$i]) {
  277. $row->ordering = $order[$i];
  278. if (!$row->store()) {
  279. $this->setError($row->getError());
  280. return false;
  281. }
  282. } // if
  283. } // for
  284.  
  285. $msg = JText::_( 'New ordering saved' );
  286. $this->setRedirect( 'index.php?option=com_essay&c=word', $msg );
  287.  
  288. }
  289. }
Add Comment
Please, Sign In to add comment