Ejemplo n.º 1
0
 public function categories()
 {
     JRequest::setVar('view', 'categories');
     $table = JTable::getInstance('Category', 'StreamTable');
     $c = new StreamCategory();
     $category = JRequest::getVar('category');
     $mainframe = JFactory::getApplication();
     // if this is remove action
     if (JRequest::getVar('action') == 'remove') {
         if ($table->remove($category)) {
             $mainframe->redirect(JRoute::_('index.php?option=com_account&task=categories&view=account'), JText::sprintf('COM_ACCOUNT_LABEL_SUCCESS_REMOVE_CATEGORY', $table->getCategoryNameById($category)));
         } else {
             $mainframe->redirect(JRoute::_('index.php?option=com_account&task=categories&view=account'), JText::sprintf('COM_ACCOUNT_LABEL_ERROR_REMOVE_CATEGORY', $table->getCategoryNameById($category)), 'error');
         }
     }
     if ($_POST) {
         $type = JRequest::getVar('type', null);
         if (JRequest::getVar('blog_category')) {
             $category = JRequest::getVar('blog_category');
         } else {
             if (JRequest::getVar('event_category')) {
                 $category = JRequest::getVar('event_category');
             } else {
                 if (JRequest::getVar('group_category')) {
                     $category = JRequest::getVar('group_category');
                 } else {
                     $mainframe->redirect(JRoute::_('index.php?option=com_account&task=categories&view=account'), JText::_('COM_ACCOUNT_LABEL_ERROR_CREATE'), 'error');
                     return false;
                 }
             }
         }
         if ($table->create($category, $type)) {
             $mainframe->redirect(JRoute::_('index.php?option=com_account&task=categories&view=account'), JText::_('COM_ACCOUNT_LABEL_SUCCESS_CREATE'));
         } else {
             if ($c->isExist($category, $type)) {
                 $mainframe->redirect(JRoute::_('index.php?option=com_account&task=categories&view=account'), JText::_('COM_ACCOUNT_LABEL_ALREADY_EXIST'), 'error');
             } else {
                 $mainframe->redirect(JRoute::_('index.php?option=com_account&task=categories&view=account'), JText::_('COM_ACCOUNT_LABEL_ERROR_CREATE'), 'error');
             }
         }
     }
     parent::display();
 }