/** * Ajax function to delete a group * * @param $groupId The specific group id to unpublish **/ public function ajaxDeleteGroup($groupId, $step = 1) { $filter = JFilterInput::getInstance(); $groupId = $filter->clean($groupId, 'int'); $step = $filter->clean($step, 'int'); $response = new JAXResponse(); CFactory::load('libraries', 'activities'); CFactory::load('helpers', 'owner'); CFactory::load('models', 'groups'); $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupModel = CFactory::getModel('groups'); $membersCount = $groupModel->getMembersCount($groupId); $my = CFactory::getUser(); // @rule: Do not allow anyone that tries to be funky! if (!$my->authorise('community.delete', 'groups.' . $groupId, $group)) { $content = JText::_('COM_COMMUNITY_GROUPS_NOT_ALLOWED_DELETE'); $buttons = '<input type="button" class="button" onclick="cWindowHide();" value="' . JText::_('COM_COMMUNITY_CANCEL') . '"/>'; $response->addScriptCall('cWindowAddContent', $content, $buttons); return $response->sendResponse(); } $doneMessage = ' - <span class=\'success\'>' . JText::_('COM_COMMUNITY_DONE') . '</span><br />'; $failedMessage = ' - <span class=\'failed\'>' . JText::_('COM_COMMUNITY_FAILED') . '</span><br />'; $childId = 0; switch ($step) { case 1: // Nothing gets deleted yet. Just show a messge to the next step if (empty($groupId)) { $content = JText::_('COM_COMMUNITY_GROUPS_ID_NOITEM'); } else { $content = '<strong>' . JText::sprintf('COM_COMMUNITY_GROUPS_DELETE_GROUP', $group->name) . '</strong><br/>'; $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_BULLETIN'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 2);'); //trigger for onBeforeGroupDelete $this->triggerGroupEvents('onBeforeGroupDelete', $group); } $response->addScriptCall('cWindowAddContent', $content); break; case 2: CommunityModelGroups::getGroupChildId($groupId); // Delete all group bulletins if (CommunityModelGroups::deleteGroupBulletins($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_GROUP_MEMBERS'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 3);'); break; case 3: // Delete all group members if (CommunityModelGroups::deleteGroupMembers($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_WALLS_DELETE'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 4);'); break; case 4: // Delete all group wall if (CommunityModelGroups::deleteGroupWall($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DISCUSSIONS_DELETEL'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 5);'); break; case 5: // Delete all group discussions if (CommunityModelGroups::deleteGroupDiscussions($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_MEDIA'); $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 6);'); break; case 6: // Delete all group's media files if (CommunityModelGroups::deleteGroupMedia($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $response->addScriptCall('joms.jQuery("#cWindowContent").append("' . $content . '");'); $response->addScriptCall('cWindowResize(joms.jQuery("#cWindowContentWrap").height()+10);'); $response->addScriptCall('jax.call(\'community\', \'groups,ajaxDeleteGroup\', \'' . $groupId . '\', 7);'); break; case 7: // Delete group $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupData = $group; if ($group->delete($groupId)) { CFactory::load('libraries', 'featured'); $featured = new CFeatured(FEATURED_GROUPS); $featured->delete($groupId); jimport('joomla.filesystem.file'); //@rule: Delete only thumbnail and avatars that exists for the specific group if ($groupData->avatar != "components/com_community/assets/group.jpg" && !empty($groupData->avatar)) { $path = explode('/', $groupData->avatar); $file = JPATH_ROOT . DS . $path[0] . DS . $path[1] . DS . $path[2] . DS . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } if ($groupData->thumb != "components/com_community/assets/group_thumb.jpg" && !empty($groupData->thumb)) { $path = explode('/', $groupData->thumb); $file = JPATH_ROOT . DS . $path[0] . DS . $path[1] . DS . $path[2] . DS . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } $html = '<div class=\\"info\\" style=\\"display: none;\\">' . JText::_('COM_COMMUNITY_GROUPS_DELETED') . '</div>'; $response->addScriptCall('joms.jQuery("' . $html . '").prependTo("#community-wrap").fadeIn();'); $response->addScriptCall('joms.jQuery("#community-groups-wrap").fadeOut();'); $content = JText::_('COM_COMMUNITY_GROUPS_DELETED'); //trigger for onGroupDelete $this->triggerGroupEvents('onAfterGroupDelete', $groupData); } else { $content = JText::_('COM_COMMUNITY_GROUPS_DELETE_ERROR'); } $redirect = CRoute::_(JURI::root() . 'index.php?option=com_community&view=groups'); $buttons = '<input type="button" class="button" id="groupDeleteDone" onclick="cWindowHide(); window.location=\'' . $redirect . '\';" value="' . JText::_('COM_COMMUNITY_DONE_BUTTON') . '"/>'; $response->addScriptCall('cWindowAddContent', $content, $buttons); break; default: break; } //Clear Cache for groups $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_GROUPS, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_GROUPS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); return $response->sendResponse(); }
/** * Ajax function to delete a group * * @param $groupId The specific group id to unpublish * */ public function ajaxDeleteGroup($groupId, $step = 1) { $filter = JFilterInput::getInstance(); $groupId = $filter->clean($groupId, 'int'); $step = $filter->clean($step, 'int'); $json = array(); $response = new JAXResponse(); $group = JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupModel = CFactory::getModel('groups'); $membersCount = $groupModel->getMembersCount($groupId); $my = CFactory::getUser(); // @rule: Do not allow anyone that tries to be funky! if (!$my->authorise('community.delete', 'groups.' . $groupId, $group)) { $json['error'] = JText::_('COM_COMMUNITY_GROUPS_NOT_ALLOWED_DELETE'); die(json_encode($json)); } $doneMessage = ' - <span class=\'success\'>' . JText::_('COM_COMMUNITY_DONE') . '</span><br />'; $failedMessage = ' - <span class=\'failed\'>' . JText::_('COM_COMMUNITY_FAILED') . '</span><br />'; $childId = 0; switch ($step) { case 1: // Nothing gets deleted yet. Just show a messge to the next step if (empty($groupId)) { $json['error'] = JText::_('COM_COMMUNITY_GROUPS_ID_NOITEM'); } else { $json['message'] = '<strong>' . JText::sprintf('COM_COMMUNITY_GROUPS_DELETE_GROUP', $group->name) . '</strong><br/>'; $json['message'] .= JText::_('COM_COMMUNITY_GROUPS_DELETE_BULLETIN'); $json['next'] = 2; //trigger for onBeforeGroupDelete $this->triggerGroupEvents('onBeforeGroupDelete', $group); } break; case 2: // Delete all group bulletins CommunityModelGroups::getGroupChildId($groupId); if (CommunityModelGroups::deleteGroupBulletins($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_GROUP_MEMBERS'); $json['message'] = $content; $json['next'] = 3; break; case 3: // Delete all group members if (CommunityModelGroups::deleteGroupMembers($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_WALLS_DELETE'); $json['message'] = $content; $json['next'] = 4; break; case 4: // Delete all group wall if (CommunityModelGroups::deleteGroupWall($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DISCUSSIONS_DELETEL'); $json['message'] = $content; $json['next'] = 5; break; case 5: // Delete all group discussions if (CommunityModelGroups::deleteGroupDiscussions($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $content .= JText::_('COM_COMMUNITY_GROUPS_DELETE_MEDIA'); $json['message'] = $content; $json['next'] = 6; break; case 6: // Delete all group's media files if (CommunityModelGroups::deleteGroupMedia($groupId)) { $content = $doneMessage; } else { $content = $failedMessage; } $json['message'] = $content; $json['next'] = 7; break; case 7: // Delete group $group = JTable::getInstance('Group', 'CTable'); $group->load($groupId); $groupData = $group; if ($group->delete($groupId)) { //CFactory::load( 'libraries' , 'featured' ); $featured = new CFeatured(FEATURED_GROUPS); $featured->delete($groupId); jimport('joomla.filesystem.file'); //@rule: Delete only thumbnail and avatars that exists for the specific group if ($groupData->avatar != "components/com_community/assets/group.jpg" && !empty($groupData->avatar)) { $path = explode('/', $groupData->avatar); $file = JPATH_ROOT . '/' . $path[0] . '/' . $path[1] . '/' . $path[2] . '/' . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } if ($groupData->thumb != "components/com_community/assets/group_thumb.jpg" && !empty($groupData->thumb)) { $path = explode('/', $groupData->thumb); $file = JPATH_ROOT . '/' . $path[0] . '/' . $path[1] . '/' . $path[2] . '/' . $path[3]; if (JFile::exists($file)) { JFile::delete($file); } } $content = JText::_('COM_COMMUNITY_GROUPS_DELETED'); //trigger for onGroupDelete $this->triggerGroupEvents('onAfterGroupDelete', $groupData); } else { $content = JText::_('COM_COMMUNITY_GROUPS_DELETE_ERROR'); } $redirect = CRoute::_('index.php?option=com_community&view=groups'); $json['message'] = $content; $json['redirect'] = $redirect; $json['btnDone'] = JText::_('COM_COMMUNITY_DONE_BUTTON'); break; default: break; } //Clear Cache for groups $this->cacheClean(array(COMMUNITY_CACHE_TAG_FRONTPAGE, COMMUNITY_CACHE_TAG_GROUPS, COMMUNITY_CACHE_TAG_FEATURED, COMMUNITY_CACHE_TAG_GROUPS_CAT, COMMUNITY_CACHE_TAG_ACTIVITIES)); die(json_encode($json)); // return $response->sendResponse(); }