⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin.sections.php

📁 Joomla15 - 最新开源CMS
💻 PHP
📖 第 1 页 / 共 2 页
字号:
		JError::raiseError(500, JText::_( 'Select a section to delete', true ) );
	}

	JArrayHelper::toInteger( $cid );
	$cids = implode( ',', $cid );

	$query = 'SELECT s.id, s.name, COUNT(c.id) AS numcat'
	. ' FROM #__sections AS s'
	. ' LEFT JOIN #__categories AS c ON c.section=s.id'
	. ' WHERE s.id IN ( '.$cids.' )'
	. ' GROUP BY s.id'
	;
	$db->setQuery( $query );
	if (!($rows = $db->loadObjectList())) {
		echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
	}

	$err = array();
	$cid = array();
	foreach ($rows as $row) {
		if ($row->numcat == 0) {
			$cid[]	= (int) $row->id;
			$name[]	= $row->name;
		} else {
			$err[]	= $row->name;
		}
	}

	if (count( $cid ))
	{
		$cids = implode( ',', $cid );
		$query = 'DELETE FROM #__sections'
		. ' WHERE id IN ( '.$cids.' )'
		;
		$db->setQuery( $query );
		if (!$db->query()) {
			echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
		}
	}

	if (count( $err ))
	{
		$cids = implode( ', ', $err );
		$msg = JText::sprintf( 'DESCCANNOTBEREMOVED', $cids );
		$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope, $msg );
	}

	$names = implode( ', ', $name );
	$msg = JText::sprintf( 'Sections successfully deleted', $names );
	$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope, $msg );
}

/**
* Publishes or Unpublishes one or more categories
* @param database A database connector object
* @param string The name of the category section
* @param integer A unique category id (passed from an edit form)
* @param array An array of unique category id numbers
* @param integer 0 if unpublishing, 1 if publishing
* @param string The name of the current user
*/
function publishSections( $scope, $cid=null, $publish=1, $option )
{
	global $mainframe;

	$db 	=& JFactory::getDBO();
	$user 	=& JFactory::getUser();

	JArrayHelper::toInteger($cid);

	if ( count( $cid ) < 1 ) {
		$action = $publish ? 'publish' : 'unpublish';
		JError::raiseError(500, JText::_( 'Select a section to '.$action, true ) );
	}

	$cids = implode( ',', $cid );
	$count = count( $cid );
	if ( $publish ) {
		if ( !$count ){
			echo "<script> alert('". JText::_( 'Cannot Publish an Empty Section', true ) .": ". $count ."'); window.history.go(-1);</script>\n";
			return;
		}
	}

	$query = 'UPDATE #__sections'
	. ' SET published = '.(int) $publish
	. ' WHERE id IN ( '.$cids.' )'
	. ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id').' ) )'
	;
	$db->setQuery( $query );
	if (!$db->query()) {
		JError::raiseError(500, $db->getErrorMsg() );
	}

	if ( $count == 1 ) {
		$row =& JTable::getInstance('section');
		$row->checkin( $cid[0] );
	}

	// check if section linked to menu items if unpublishing
	if ( $publish == 0 ) {
		$query = 'SELECT id'
		. ' FROM #__menu'
		. ' WHERE type = "content_section"'
		. ' AND componentid IN ( '.$cids.' )'
		;
		$db->setQuery( $query );
		$menus = $db->loadObjectList();

		if ($menus) {
			foreach ($menus as $menu) {
				$query = 'UPDATE #__menu'
				. ' SET published = '.(int) $publish
				. ' WHERE id = '.(int) $menu->id
				;
				$db->setQuery( $query );
				$db->query();
			}
		}
	}

	$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope );
}

/**
* Cancels an edit operation
* @param database A database connector object
* @param string The name of the category section
* @param integer A unique category id
*/
function cancelSection( $option, $scope )
{
	global $mainframe;

	$db =& JFactory::getDBO();
	$row =& JTable::getInstance('section');
	$row->bind(JRequest::get('post'));
	$row->checkin();

	$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope );
}

/**
* Moves the order of a record
* @param integer The increment to reorder by
*/
function orderSection( $uid, $inc, $option, $scope )
{
	global $mainframe;

	$db =& JFactory::getDBO();
	$row =& JTable::getInstance('section');
	$row->load( $uid );
	$row->move( $inc, 'scope = '.$db->Quote($row->scope) );

	$mainframe->redirect( 'index.php?option='. $option .'&scope='. $scope );
}


/**
* Form for copying item(s) to a specific menu
*/
function copySectionSelect( $option, $cid, $section )
{
	global $mainframe;

	$db =& JFactory::getDBO();

	JArrayHelper::toInteger($cid);

	if ( count( $cid ) < 1) {
		JError::raiseError(500, JText::_( 'Select an item to move', true ) );
	}

	## query to list selected categories
	$cids = implode( ',', $cid );
	$query = 'SELECT a.title, a.id'
	. ' FROM #__categories AS a'
	. ' WHERE a.section IN ( '.$cids.' )'
	;
	$db->setQuery( $query );
	$categories = $db->loadObjectList();

	## query to list items from categories
	$query = 'SELECT a.title, a.id'
	. ' FROM #__content AS a'
	. ' WHERE a.sectionid IN ( '.$cids.' )'
	. ' ORDER BY a.sectionid, a.catid, a.title'
	;
	$db->setQuery( $query );
	$contents = $db->loadObjectList();

	sections_html::copySectionSelect( $option, $cid, $categories, $contents, $section );
}


/**
* Save the item(s) to the menu selected
*/
function copySectionSave( $sectionid )
{
	global $mainframe;

	$db			=& JFactory::getDBO();
	$title		= JRequest::getString( 'title' );
	$contentid	= JRequest::getVar( 'content' );
	$categoryid = JRequest::getVar( 'category' );
	JArrayHelper::toInteger($contentid);
	JArrayHelper::toInteger($categoryid);

	// copy section
	$section =& JTable::getInstance('section');
	foreach( $sectionid as $id ) {
		$section->load( $id );
		$section->id 	= NULL;
		$section->title = $title;
		$section->name 	= $title;
		if ( !$section->check() ) {
			JError::raiseError(500, $section->getError() );
		}

		if ( !$section->store() ) {
			JError::raiseError(500, $section->getError() );
		}
		$section->checkin();
		$section->reorder( 'scope = '.$db->Quote($section->scope) );
		// stores original catid
		$newsectids[]["old"] = $id;
		// pulls new catid
		$newsectids[]["new"] = $section->id;
	}
	$sectionMove = $section->id;

	// copy categories
	$category =& JTable::getInstance('category');
	foreach( $categoryid as $id ) {
		$category->load( $id );
		$category->id = NULL;
		$category->section = $sectionMove;
		foreach( $newsectids as $newsectid ) {
			if ( $category->section == $newsectid["old"] ) {
				$category->section = $newsectid["new"];
			}
		}
		if (!$category->check()) {
			JError::raiseError(500, $category->getError() );
		}

		if (!$category->store()) {
			JError::raiseError(500, $category->getError() );
		}
		$category->checkin();
		$category->reorder( 'section = '.$db->Quote($category->section) );
		// stores original catid
		$newcatids[]["old"] = $id;
		// pulls new catid
		$newcatids[]["new"] = $category->id;
	}

	$content =& JTable::getInstance('content');
	foreach( $contentid as $id) {
		$content->load( $id );
		$content->id = NULL;
		$content->hits = 0;
		foreach( $newsectids as $newsectid ) {
			if ( $content->sectionid == $newsectid["old"] ) {
				$content->sectionid = $newsectid["new"];
			}
		}
		foreach( $newcatids as $newcatid ) {
			if ( $content->catid == $newcatid["old"] ) {
				$content->catid = $newcatid["new"];
			}
		}
		if (!$content->check()) {
			JError::raiseError(500, $content->getError() );
		}

		if (!$content->store()) {
			JError::raiseError(500, $content->getError() );
		}
		$content->checkin();
	}
	$sectionOld =& JTable::getInstance('section');
	$sectionOld->load( $sectionMove );

	$msg = JText::sprintf( 'DESCCATANDITEMSCOPIED', $sectionOld-> name, $title );
	$mainframe->redirect( 'index.php?option=com_sections&scope=content', $msg );
}

/**
* changes the access level of a record
* @param integer The increment to reorder by
*/
function accessMenu( $uid, $access, $option )
{
	global $mainframe;

	$db	=& JFactory::getDBO();
	$row =& JTable::getInstance('section');
	$row->load( $uid );
	$row->access = $access;

	if ( !$row->check() ) {
		return $row->getError();
	}
	if ( !$row->store() ) {
		return $row->getError();
	}

	$mainframe->redirect( 'index.php?option='. $option .'&scope='. $row->scope );
}

function saveOrder( &$cid )
{
	global $mainframe;

	$db			=& JFactory::getDBO();
	$row		=& JTable::getInstance('section');

	$total		= count( $cid );
	$order		= JRequest::getVar( 'order', array(0), 'post', 'array' );
	JArrayHelper::toInteger($order, array(0));

	// update ordering values
	for( $i=0; $i < $total; $i++ )
	{
		$row->load( (int) $cid[$i] );
		if ($row->ordering != $order[$i]) {
			$row->ordering = $order[$i];
			if (!$row->store()) {
				JError::raiseError(500, $db->getErrorMsg() );
			}
		}
	}

	$row->reorder( );

	$msg 	= JText::_( 'New ordering saved' );
	$mainframe->redirect( 'index.php?option=com_sections&scope=content', $msg );
}
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -