PageRenderTime 105ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/com_joomleague/administrator/components/com_joomleague/controllers/club.php

https://gitlab.com/julienv/joomleague
PHP | 190 lines | 142 code | 15 blank | 33 comment | 7 complexity | b6c8aa542c1d80d80dbbc9e0027f802d MD5 | raw file
  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2005-2014 joomleague.at. All rights reserved.
  4. * @license GNU/GPL,see LICENSE.php
  5. * Joomla! is free software. This version may have been modified pursuant
  6. * to the GNU General Public License,and as distributed it includes or
  7. * is derivative of works licensed under the GNU General Public License or
  8. * other free or open source software licenses.
  9. * See COPYRIGHT.php for copyright notices and details.
  10. */
  11. // Check to ensure this file is included in Joomla!
  12. defined('_JEXEC') or die('Restricted access');
  13. jimport('joomla.application.component.controller');
  14. jimport('joomla.filesystem.file');
  15. /**
  16. * Joomleague Component Club Controller
  17. *
  18. * @package JoomLeague
  19. * @since 0.1
  20. */
  21. class JoomleagueControllerClub extends JoomleagueController
  22. {
  23. protected $view_list = 'clubs';
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. // Register Extra tasks
  28. $this->registerTask('add','display');
  29. $this->registerTask('edit','display');
  30. $this->registerTask('apply','save');
  31. }
  32. public function display($cachable = false, $urlparams = false)
  33. {
  34. switch($this->getTask())
  35. {
  36. case 'add' :
  37. {
  38. JRequest::setVar('hidemainmenu',JRequest::getVar('hidemainmenu',0));
  39. JRequest::setVar('layout','form');
  40. JRequest::setVar('view','club');
  41. JRequest::setVar('edit',false);
  42. // Checkout the club
  43. $model=$this->getModel('club');
  44. $model->checkout();
  45. } break;
  46. case 'edit' :
  47. {
  48. JRequest::setVar('hidemainmenu', JRequest::getVar('hidemainmenu',0));
  49. JRequest::setVar('layout','form');
  50. JRequest::setVar('view','club');
  51. JRequest::setVar('edit',true);
  52. // Checkout the club
  53. $model=$this->getModel('club');
  54. $model->checkout();
  55. } break;
  56. }
  57. parent::display();
  58. }
  59. public function save()
  60. {
  61. // Check for request forgeries
  62. JSession::checkToken() or die('COM_JOOMLEAGUE_GLOBAL_INVALID_TOKEN');
  63. $msg='';
  64. $post=JRequest::get('post');
  65. $cid=JRequest::getVar('cid',array(0),'post','array');
  66. $post['id']=(int) $cid[0];
  67. $model=$this->getModel('club');
  68. $post['notes'] = JRequest:: getVar('notes','none','post','STRING',JREQUEST_ALLOWHTML);
  69. if ($clubid = $model->store($post))
  70. {
  71. $msg=JText::_('COM_JOOMLEAGUE_ADMIN_CLUB_CTRL_SAVED');
  72. $createTeam=JRequest::getVar('createTeam');
  73. if ($createTeam)
  74. {
  75. $team_name=JRequest::getVar('name');
  76. $team_short_name=strtoupper(substr(ereg_replace("[^a-zA-Z]","",$team_name),0,3));
  77. $teammodel=$this->getModel('team');
  78. $tpost['id']= "0";
  79. $tpost['name']= $team_name;
  80. $tpost['short_name']= $team_short_name ;
  81. $tpost['club_id']= $clubid;
  82. $teammodel->store($tpost);
  83. }
  84. }
  85. else
  86. {
  87. $msg=JText::_('COM_JOOMLEAGUE_ADMIN_CLUB_CTRL_ERROR_SAVE').$model->getError();
  88. }
  89. // Check the table in so it can be edited.... we are done with it anyway
  90. $model->checkin();
  91. if ($this->getTask()=='save')
  92. {
  93. $link='index.php?option=com_joomleague&view=clubs&club.display';
  94. }
  95. else
  96. {
  97. $link='index.php?option=com_joomleague&task=club.edit&cid[]='.$post['id'];
  98. }
  99. $link .= '&hidemainmenu='.JRequest::getVar('hidemainmenu',0);
  100. $this->setRedirect($link,$msg);
  101. }
  102. public function remove()
  103. {
  104. JSession::checkToken() or die('COM_JOOMLEAGUE_GLOBAL_INVALID_TOKEN');
  105. $user = JFactory::getUser();
  106. $cid=JRequest::getVar('cid',array(),'post','array');
  107. $msg='';
  108. JArrayHelper::toInteger($cid);
  109. if (count($cid) < 1){JError::raiseError(500,JText::_('COM_JOOMLEAGUE_ADMIN_CLUB_CTRL_SELECT_TO_DELETE'));}
  110. // Access checks.
  111. foreach ($cid as $i => $id)
  112. {
  113. if (!$user->authorise('core.admin', 'com_joomleague') ||
  114. !$user->authorise('core.delete', 'com_joomleague.club.'.(int) $id))
  115. {
  116. // Prune items that you can't delete.
  117. unset($cid[$i]);
  118. JError::raiseNotice(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
  119. }
  120. }
  121. $model=$this->getModel('club');
  122. if(!$model->delete($cid))
  123. {
  124. echo "<script> alert('".$model->getError()."'); window.history.go(-1); </script>\n";
  125. return;
  126. }
  127. else
  128. {
  129. $msg=JText::_('COM_JOOMLEAGUE_ADMIN_CLUB_CTRL_DELETED');
  130. }
  131. $link .= 'index.php?option=com_joomleague&view=clubs&task=club.display';
  132. $link .= '&hidemainmenu='.JRequest::getVar('hidemainmenu',0);
  133. $this->setRedirect($link,$msg);
  134. }
  135. public function cancel()
  136. {
  137. // Checkin the club
  138. $model=$this->getModel('club');
  139. $model->checkin();
  140. $link = 'index.php?option=com_joomleague&view=clubs&task=club.display';
  141. $link .= '&hidemainmenu='.JRequest::getVar('hidemainmenu',0);
  142. $this->setRedirect($link);
  143. }
  144. public function import()
  145. {
  146. JRequest::setVar('view','import');
  147. JRequest::setVar('table','club');
  148. parent::display();
  149. }
  150. public function export()
  151. {
  152. JSession::checkToken() or die('COM_JOOMLEAGUE_GLOBAL_INVALID_TOKEN');
  153. $post=JRequest::get('post');
  154. $cid=JRequest::getVar('cid',array(),'post','array');
  155. JArrayHelper::toInteger($cid);
  156. if (count($cid) < 1){JError::raiseError(500,JText::_('COM_JOOMLEAGUE_GLOBAL_SELECT_TO_EXPORT'));}
  157. $model = $this->getModel("club");
  158. $model->export($cid, "club", "Club");
  159. }
  160. /**
  161. * Proxy for getModel
  162. *
  163. * @param string $name The model name. Optional.
  164. * @param string $prefix The class prefix. Optional.
  165. *
  166. * @return object The model.
  167. * @since 1.6
  168. */
  169. public function getModel($name = 'Club', $prefix = 'JoomleagueModel', $config = array('ignore_request' => true))
  170. {
  171. $model = parent::getModel($name, $prefix, $config);
  172. return $model;
  173. }
  174. }
  175. ?>