PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website các món ăn và ẩm thực php/bbqvietnam.com/administrator/components/com_frontpage/admin.frontpage.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 378 lines | 261 code | 70 blank | 47 comment | 29 complexity | e0be6b02812a1e7b057ac32005261841 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: admin.frontpage.php 18162 2010-07-16 07:00:47Z ian $
  4. * @package Joomla
  5. * @subpackage Content
  6. * @copyright Copyright (C) 2005 - 2010 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. // no direct access
  15. defined( '_JEXEC' ) or die( 'Restricted access' );
  16. // Make sure the user is authorized to view this page
  17. $user = & JFactory::getUser();
  18. if (!$user->authorize( 'com_frontpage', 'manage' )) {
  19. $mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
  20. }
  21. // Set the table directory
  22. JTable::addIncludePath(JPATH_COMPONENT.DS.DS.'tables');
  23. // Set the helper directory
  24. JHTML::addIncludePath( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_content'.DS.'helper' );
  25. $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
  26. JArrayHelper::toInteger($cid, array(0));
  27. switch ( JRequest::getCmd( 'task' ) )
  28. {
  29. case 'publish':
  30. changeFrontPage( $cid, 1, $option );
  31. break;
  32. case 'unpublish':
  33. changeFrontPage( $cid, 0, $option );
  34. break;
  35. case 'archive':
  36. changeFrontPage( $cid, -1, $option );
  37. break;
  38. case 'remove':
  39. removeFrontPage( $cid, $option );
  40. break;
  41. case 'orderup':
  42. orderFrontPage( $cid[0], -1, $option );
  43. break;
  44. case 'orderdown':
  45. orderFrontPage( $cid[0], 1, $option );
  46. break;
  47. case 'saveorder':
  48. saveOrder( $cid );
  49. break;
  50. case 'accesspublic':
  51. accessMenu( $cid[0], 0 );
  52. break;
  53. case 'accessregistered':
  54. accessMenu( $cid[0], 1 );
  55. break;
  56. case 'accessspecial':
  57. accessMenu( $cid[0], 2 );
  58. break;
  59. default:
  60. viewFrontPage( $option );
  61. break;
  62. }
  63. /**
  64. * Compiles a list of frontpage items
  65. */
  66. function viewFrontPage( $option )
  67. {
  68. global $mainframe;
  69. $db =& JFactory::getDBO();
  70. $filter_order = $mainframe->getUserStateFromRequest( $option.'.filter_order', 'filter_order', 'fpordering', 'cmd' );
  71. $filter_order_Dir = $mainframe->getUserStateFromRequest( $option.'.filter_order_Dir', 'filter_order_Dir', '', 'word' );
  72. $filter_state = $mainframe->getUserStateFromRequest( $option.'.filter_state', 'filter_state', '', 'word' );
  73. $catid = $mainframe->getUserStateFromRequest( $option.'.catid', 'catid', 0, 'int' );
  74. $filter_authorid = $mainframe->getUserStateFromRequest( $option.'.filter_authorid', 'filter_authorid', 0, 'int' );
  75. $filter_sectionid = $mainframe->getUserStateFromRequest( $option.'.filter_sectionid', 'filter_sectionid', -1, 'int' );
  76. $search = $mainframe->getUserStateFromRequest( $option.'.search', 'search', '', 'string' );
  77. if (strpos($search, '"') !== false) {
  78. $search = str_replace(array('=', '<'), '', $search);
  79. }
  80. $search = JString::strtolower($search);
  81. $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
  82. $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
  83. JToolBarHelper::title( JText::_( 'Frontpage Manager' ), 'frontpage.png' );
  84. JToolBarHelper::archiveList();
  85. JToolBarHelper::publishList();
  86. JToolBarHelper::unpublishList();
  87. JToolBarHelper::custom('remove','delete.png','delete_f2.png','Remove', true);
  88. JToolBarHelper::help( 'screen.frontpage' );
  89. $where = array(
  90. "c.state >= 0"
  91. );
  92. // used by filter
  93. if ( $filter_sectionid >= 0 ) {
  94. $where[] = 'c.sectionid = '.(int) $filter_sectionid;
  95. }
  96. if ( $catid > 0 ) {
  97. $where[] = 'c.catid = '.(int) $catid;
  98. }
  99. if ( $filter_authorid > 0 ) {
  100. $where[] = 'c.created_by = '. (int) $filter_authorid;
  101. }
  102. if ( $filter_state ) {
  103. if ( $filter_state == 'P' ) {
  104. $where[] = 'c.state = 1';
  105. } else if ($filter_state == 'U' ) {
  106. $where[] = 'c.state = 0';
  107. }
  108. }
  109. if ($search) {
  110. $where[] = 'LOWER( c.title ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
  111. }
  112. $where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
  113. // ensure we have a good vale for $filter_order
  114. if (!in_array($filter_order, array('c.title', 'c.state', 'fpordering', 'groupname', 'c.id', 'sect_name', 'cc.name', 'author'))) {
  115. $filter_order = 'fpordering';
  116. }
  117. $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', fpordering';
  118. // get the total number of records
  119. $query = 'SELECT count(*)'
  120. . ' FROM #__content AS c'
  121. . ' LEFT JOIN #__categories AS cc ON cc.id = c.catid'
  122. . ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope="content"'
  123. . ' INNER JOIN #__content_frontpage AS f ON f.content_id = c.id'
  124. . $where
  125. ;
  126. $db->setQuery( $query );
  127. $total = $db->loadResult();
  128. jimport('joomla.html.pagination');
  129. $pageNav = new JPagination( $total, $limitstart, $limit );
  130. $query = 'SELECT c.*, g.name AS groupname, cc.title as name, s.title AS sect_name, u.name AS editor, f.ordering AS fpordering, v.name AS author'
  131. . ' FROM #__content AS c'
  132. . ' LEFT JOIN #__categories AS cc ON cc.id = c.catid'
  133. . ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope="content"'
  134. . ' INNER JOIN #__content_frontpage AS f ON f.content_id = c.id'
  135. . ' INNER JOIN #__groups AS g ON g.id = c.access'
  136. . ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
  137. . ' LEFT JOIN #__users AS v ON v.id = c.created_by'
  138. . $where
  139. . $orderby
  140. ;
  141. $db->setQuery( $query, $pageNav->limitstart,$pageNav->limit );
  142. $rows = $db->loadObjectList();
  143. if ($db->getErrorNum()) {
  144. echo $db->stderr();
  145. return false;
  146. }
  147. // get list of categories for dropdown filter
  148. $query = 'SELECT cc.id AS value, cc.title AS text, section'
  149. . ' FROM #__categories AS cc'
  150. . ' INNER JOIN #__sections AS s ON s.id = cc.section '
  151. . ' ORDER BY s.ordering, cc.ordering'
  152. ;
  153. $db->setQuery( $query );
  154. $categories[] = JHTML::_('select.option', '-1', '- '. JText::_( 'Select Category' ) .' -' );
  155. $categories = array_merge( $categories, $db->loadObjectList() );
  156. $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $catid );
  157. // get list of sections for dropdown filter
  158. $javascript = 'onchange="document.adminForm.submit();"';
  159. $lists['sectionid'] = JHTML::_('list.section', 'filter_sectionid', $filter_sectionid, $javascript );
  160. // get list of Authors for dropdown filter
  161. $query = 'SELECT c.created_by, u.name'
  162. . ' FROM #__content AS c'
  163. . ' INNER JOIN #__sections AS s ON s.id = c.sectionid'
  164. . ' LEFT JOIN #__users AS u ON u.id = c.created_by'
  165. . ' WHERE c.state <> -1'
  166. . ' AND c.state <> -2'
  167. . ' GROUP BY u.name'
  168. . ' ORDER BY u.name'
  169. ;
  170. $db->setQuery( $query );
  171. $authors[] = JHTML::_('select.option', '0', '- '. JText::_( 'Select Author' ) .' -', 'created_by', 'name' );
  172. $authors = array_merge( $authors, $db->loadObjectList() );
  173. $lists['authorid'] = JHTML::_('select.genericlist', $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'created_by', 'name', $filter_authorid );
  174. // state filter
  175. $lists['state'] = JHTML::_('grid.state', $filter_state );
  176. // table ordering
  177. $lists['order_Dir'] = $filter_order_Dir;
  178. $lists['order'] = $filter_order;
  179. // search filter
  180. $lists['search']= $search;
  181. require_once(JPATH_COMPONENT.DS.'views'.DS.'frontpage.php');
  182. FrontpageView::showList( $rows, $pageNav, $option, $lists );
  183. }
  184. /**
  185. * Changes the state of one or more content pages
  186. * @param array An array of unique category id numbers
  187. * @param integer 0 if unpublishing, 1 if publishing
  188. */
  189. function changeFrontPage( $cid=null, $state=0, $option )
  190. {
  191. global $mainframe;
  192. // Check for request forgeries
  193. JRequest::checkToken() or jexit( 'Invalid Token' );
  194. $db =& JFactory::getDBO();
  195. $user =& JFactory::getUser();
  196. JArrayHelper::toInteger($cid);
  197. if (count( $cid ) < 1) {
  198. $action = $state == 1 ? 'publish' : ($state == -1 ? 'archive' : 'unpublish');
  199. JError::raiseError(500, JText::_( 'Select an item to' .$action, true ) );
  200. }
  201. $cids = implode( ',', $cid );
  202. $query = 'UPDATE #__content'
  203. . ' SET state = '.(int) $state
  204. . ' WHERE id IN ( '. $cids .' )'
  205. . ' AND ( checked_out = 0 OR ( checked_out = ' .(int) $user->get('id'). ' ) )'
  206. ;
  207. $db->setQuery( $query );
  208. if (!$db->query()) {
  209. JError::raiseError(500, $db->getErrorMsg() );
  210. }
  211. if (count( $cid ) == 1) {
  212. $row =& JTable::getInstance('content');
  213. $row->checkin( $cid[0] );
  214. }
  215. $cache = & JFactory::getCache('com_content');
  216. $cache->clean();
  217. $mainframe->redirect( 'index.php?option='.$option );
  218. }
  219. function removeFrontPage( &$cid, $option )
  220. {
  221. global $mainframe;
  222. // Check for request forgeries
  223. JRequest::checkToken() or jexit( 'Invalid Token' );
  224. $db =& JFactory::getDBO();
  225. if (!is_array( $cid ) || count( $cid ) < 1) {
  226. JError::raiseError(500, JText::_( 'Select an item to delete', true ) );
  227. }
  228. $fp =& JTable::getInstance('frontpage', 'Table');
  229. foreach ($cid as $id) {
  230. if (!$fp->delete( $id )) {
  231. JError::raiseError(500, $fp->getError() );
  232. }
  233. $obj =& JTable::getInstance('content');
  234. $obj->load( $id );
  235. $obj->mask = 0;
  236. if (!$obj->store()) {
  237. JError::raiseError(500, $fp->getError() );
  238. }
  239. }
  240. $fp->reorder();
  241. $cache = & JFactory::getCache('com_content');
  242. $cache->clean();
  243. $mainframe->redirect( 'index.php?option='.$option );
  244. }
  245. /**
  246. * Moves the order of a record
  247. * @param integer The increment to reorder by
  248. */
  249. function orderFrontPage( $uid, $inc, $option )
  250. {
  251. global $mainframe;
  252. // Check for request forgeries
  253. JRequest::checkToken() or jexit( 'Invalid Token' );
  254. $db =& JFactory::getDBO();
  255. $fp =& JTable::getInstance('frontpage','Table');
  256. $fp->load( $uid );
  257. $fp->move( $inc );
  258. $cache = & JFactory::getCache('com_content');
  259. $cache->clean();
  260. $mainframe->redirect( 'index.php?option='.$option );
  261. }
  262. /**
  263. * @param integer The id of the article
  264. * @param integer The new access level
  265. * @param string The URL option
  266. */
  267. function accessMenu( $uid, $access )
  268. {
  269. global $mainframe;
  270. // Check for request forgeries
  271. JRequest::checkToken() or jexit( 'Invalid Token' );
  272. $db = & JFactory::getDBO();
  273. $row =& JTable::getInstance('content');
  274. $row->load( $uid );
  275. $row->access = $access;
  276. if ( !$row->check() ) {
  277. return $row->getError();
  278. }
  279. if ( !$row->store() ) {
  280. return $row->getError();
  281. }
  282. $cache = & JFactory::getCache('com_content');
  283. $cache->clean();
  284. $mainframe->redirect( 'index.php?option=com_frontpage' );
  285. }
  286. function saveOrder( &$cid )
  287. {
  288. global $mainframe;
  289. // Check for request forgeries
  290. JRequest::checkToken() or jexit( 'Invalid Token' );
  291. $db =& JFactory::getDBO();
  292. $total = count( $cid );
  293. $order = JRequest::getVar( 'order', array(0), 'post', 'array' );
  294. for( $i=0; $i < $total; $i++ )
  295. {
  296. $query = 'UPDATE #__content_frontpage'
  297. . ' SET ordering = ' . (int) $order[$i]
  298. . ' WHERE content_id = ' . (int) $cid[$i];
  299. $db->setQuery( $query );
  300. if (!$db->query()) {
  301. JError::raiseError(500, $db->getErrorMsg() );
  302. }
  303. }
  304. $cache = & JFactory::getCache('com_content');
  305. $cache->clean();
  306. $msg = JText::_( 'New ordering saved' );
  307. $mainframe->redirect( 'index.php?option=com_frontpage', $msg );
  308. }