You can change publish state, publish or unpublish. Follow this step to make the toggle live.
switch($task){
case 'remove':
removeHello();
break;
case 'publish':
changeHello(1 );
break;
case 'unpublish':
changeHello(0 );
break;
default:
showHello();
break;
}
function changeHello( $state=0 )
{
global $mainframe;
// Initialize variables
$db =& JFactory::getDBO();
// define variable $cid from GET
$cid = JRequest::getVar( 'cid' , array() , '' , 'array' );
JArrayHelper::toInteger($cid);
// Check there is/are item that will be changed.
//If not, show the error.
if (count( $cid ) < 1) {
$action = $state ? 'publish' : 'unpublish';
JError::raiseError(500, JText::_( 'Select an item
to' .$action, true ) );
}
// Prepare sql statement, if cid more than one,
// it will be "cid1, cid2, cid3, ..."
$cids = implode( ',', $cid );
$query = 'UPDATE #__hello'
. ' SET published = ' . (int) $state
. ' WHERE id IN ( '. $cids .' )'
;
// Execute query
$db->setQuery( $query );
if (!$db->query()) {
JError::raiseError(500, $db->getErrorMsg() );
}
if (count( $cid ) == 1) {
$row =& JTable::getInstance('hello', 'Table');
$row->checkin( intval( $cid[0] ) );
}
// After all, redirect to front page
$mainframe->redirect( 'index.php?option=com_hello' );
}