PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/com_joomleague/administrator/components/com_joomleague/controllers/projectteam.php

https://gitlab.com/julienv/joomleague
PHP | 394 lines | 277 code | 65 blank | 52 comment | 18 complexity | b141fe8f08401066dcafd0709101e8a1 MD5 | raw file
  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2006-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. /**
  15. * Joomleague Component Controller
  16. *
  17. * @package JoomLeague
  18. * @since 0.1
  19. */
  20. class JoomleagueControllerProjectteam extends JoomleagueController
  21. {
  22. protected $view_list = 'projectteams&task=projectteam.display';
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. // Register Extra tasks
  27. $this->registerTask('add', 'edit');
  28. $this->registerTask('apply', 'save');
  29. }
  30. public function edit()
  31. {
  32. $mainframe = JFactory::getApplication();
  33. $document = JFactory::getDocument();
  34. $viewType = $document->getType();
  35. $view = $this->getView ('projectteam', $viewType);
  36. $projectws = $this->getModel ('project');
  37. $projectws->setId($mainframe->getUserState('com_joomleagueproject', 0));
  38. $view->setModel($projectws);
  39. JRequest::setVar('view', 'projectteam');
  40. JRequest::setVar('layout', 'form' );
  41. JRequest::setVar('hidemainmenu',JRequest::getVar('hidemainmenu',0));
  42. $model = $this->getModel('projectteam');
  43. $user = JFactory::getUser();
  44. // Error if checkedout by another administrator
  45. if ($model->isCheckedOut($user->get('id'))) {
  46. $this->setRedirect('index.php?option=com_joomleague&task=projectteam.display&view=projectteams', JText::_('EDITED BY ANOTHER ADMIN'));
  47. }
  48. $model->checkout();
  49. parent::display();
  50. }
  51. public function display($cachable = false, $urlparams = false)
  52. {
  53. $option = JRequest::getCmd('option');
  54. $mainframe = JFactory::getApplication();
  55. $document = JFactory::getDocument();
  56. $model = $this->getModel ('projectteams');
  57. $viewType = $document->getType();
  58. $view = $this->getView ('projectteams', $viewType);
  59. $view->setModel($model, true); // true is for the default model;
  60. $projectws = $this->getModel ('project');
  61. $projectws->setId($mainframe->getUserState($option . 'project', 0));
  62. $view->setModel($projectws);
  63. parent::display();
  64. }
  65. public function storechangeteams()
  66. {
  67. $option = JRequest::getCmd('option');
  68. $app = JFactory::getApplication();
  69. $model = $this->getModel('projectteams');
  70. $post = JRequest::get('post');
  71. $oldteamids = JRequest::getVar('oldptid', array(), 'post', 'array');
  72. $newteamids = JRequest::getVar('newptid', array(), 'post', 'array');
  73. if ( $oldteamids )
  74. {
  75. if(!$model->changeTeamId($oldteamids, $newteamids, $app)) {
  76. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_ERROR_SAVE') . $model->getError();
  77. }
  78. }
  79. $link = 'index.php?option=com_joomleague&view=projectteams&task=projectteam.display';
  80. $this->setRedirect($link, $msg);
  81. }
  82. public function changeteams()
  83. {
  84. $option = JRequest::getCmd('option');
  85. $mainframe = JFactory::getApplication();
  86. $document = JFactory::getDocument();
  87. $model = $this->getModel ('projectteams');
  88. $viewType = $document->getType();
  89. $view = $this->getView ('projectteams', $viewType);
  90. $view->setModel($model, true); // true is for the default model;
  91. $projectws = $this->getModel ('project');
  92. $projectws->setId($mainframe->getUserState($option . 'project', 0));
  93. $view->setModel($projectws);
  94. JRequest::setVar('hidemainmenu',JRequest::getVar('hidemainmenu',0));
  95. JRequest::setVar('layout', 'changeteams' );
  96. JRequest::setVar('view', 'projectteams');
  97. JRequest::setVar('edit', true);
  98. // Checkout the project
  99. // $model = $this->getModel('projectteam');
  100. parent::display();
  101. }
  102. function editlist()
  103. {
  104. $option = JRequest::getCmd('option');
  105. $mainframe = JFactory::getApplication();
  106. $document = JFactory::getDocument();
  107. $model = $this->getModel ('projectteams');
  108. $viewType = $document->getType();
  109. $view = $this->getView ('projectteams', $viewType);
  110. $view->setModel($model, true); // true is for the default model;
  111. $projectws = $this->getModel ('project');
  112. $projectws->setId($mainframe->getUserState($option . 'project', 0));
  113. $view->setModel($projectws);
  114. JRequest::setVar('hidemainmenu',JRequest::getVar('hidemainmenu',0));
  115. JRequest::setVar('layout', 'editlist' );
  116. JRequest::setVar('view', 'projectteams');
  117. JRequest::setVar('edit', true);
  118. // Checkout the project
  119. // $model = $this->getModel('projectteam');
  120. parent::display();
  121. }
  122. public function save_teamslist()
  123. {
  124. $post = JRequest::get('post');
  125. $cid = JRequest::getVar('cid', array(0), 'post', 'array');
  126. $post['id'] = (int) $cid[0];
  127. $model = $this->getModel('projectteams');
  128. if ($model->store($post))
  129. {
  130. //clear ranking cache
  131. $cache = JFactory::getCache('joomleague.project'.$post['id']);
  132. $cache->clean();
  133. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_SAVED');
  134. }
  135. else
  136. {
  137. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_ERROR_SAVE') . $model->getError();
  138. }
  139. $link = 'index.php?option=com_joomleague&view=projectteams&task=projectteam.display';
  140. $this->setRedirect($link, $msg);
  141. }
  142. public function save()
  143. {
  144. // Check for request forgeries
  145. JSession::checkToken() or die('COM_JOOMLEAGUE_GLOBAL_INVALID_TOKEN');
  146. //get the projectid
  147. $option = JRequest::getCmd('option');
  148. $mainframe = JFactory::getApplication();
  149. $project_id = $mainframe->getUserState($option . 'project');
  150. $post = JRequest::get('post');
  151. $cid = JRequest::getVar('cid', array(0), 'post', 'array');
  152. $post['id'] = (int) $cid[0];
  153. // decription must be fetched without striping away html code
  154. $post['notes'] = JRequest:: getVar('notes', 'none', 'post', 'STRING', JREQUEST_ALLOWHTML);
  155. //$post['extended'] = JRequest:: getVar('extended', 'none', 'post', 'STRING', JREQUEST_ALLOWHTML);
  156. //echo '<pre>'.print_r($post,true).'</pre>';
  157. $model = $this->getModel('projectteam');
  158. if (isset($post['add_trainingData']))
  159. {
  160. if ($model->addNewTrainigData($post['id'],(int) $post['project_id']))
  161. {
  162. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_TRAINING');
  163. }
  164. else
  165. {
  166. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_ERROR_TRAINING').$model->getError();
  167. }
  168. //echo $msg;
  169. }
  170. if (isset($post['tdCount'])) // Existing Team Trainingdata
  171. {
  172. if ($model->saveTrainigData($post))
  173. {
  174. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_TRAINING_SAVED');
  175. }
  176. else
  177. {
  178. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_TRAINING_ERROR_SAVE').$model->getError();
  179. }
  180. if ($model->checkAndDeleteTrainigData($post))
  181. {
  182. $msg .= ' - '.JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_TRAINING_DELETED');
  183. }
  184. else
  185. {
  186. $msg = ' - '.JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_TRAINING_ERROR_DELETED').$model->getError();
  187. }
  188. $msg .= ' - ';
  189. }
  190. if ($model->store($post))
  191. {
  192. //clear ranking cache
  193. $cache = JFactory::getCache('joomleague.project'.$project_id);
  194. $cache->clean();
  195. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_TEAM_SAVED');
  196. }
  197. else
  198. {
  199. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_TEAM_ERROR_SAVE').$model->getError();
  200. }
  201. // Check the table in so it can be edited.... we are done with it anyway
  202. $model->checkin();
  203. if ($this->getTask()=='save')
  204. {
  205. $link = 'index.php?option=com_joomleague&view=projectteams&task=projectteam.display';
  206. }
  207. else
  208. {
  209. $link = 'index.php?option=com_joomleague&task=projectteam.edit&cid[]=' . $post['id'];
  210. }
  211. //echo $msg;
  212. $this->setRedirect($link,$msg);
  213. }
  214. // save the checked rows inside the project teams list
  215. public function saveshort()
  216. {
  217. //get the projectid
  218. $option = JRequest::getCmd('option');
  219. $mainframe = JFactory::getApplication();
  220. $project_id = $mainframe->getUserState($option . 'project');
  221. $post = JRequest::get('post');
  222. $cid = JRequest::getVar('cid', array(), 'post', 'array');
  223. JArrayHelper::toInteger($cid);
  224. $model = $this->getModel('projectteams');
  225. if ($model->storeshort($cid, $post))
  226. {
  227. //clear ranking cache
  228. $cache = JFactory::getCache('joomleague.project'.$project_id);
  229. $cache->clean();
  230. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_UPDATED');
  231. }
  232. else
  233. {
  234. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_P_TEAM_CTRL_ERROR_UPDATED') . $model->getError();
  235. }
  236. $link = 'index.php?option=com_joomleague&view=projectteams&task=projectteam.display';
  237. $this->setRedirect($link, $msg);
  238. }
  239. public function remove()
  240. {
  241. $option = JRequest::getCmd('option');
  242. $app = JFactory::getApplication();
  243. $project_id=$app->getUserState($option.'project',0);
  244. $user = JFactory::getUser();
  245. $cid = JRequest::getVar('cid', array(), 'post', 'array');
  246. JArrayHelper::toInteger($cid);
  247. if (count($cid) < 1)
  248. {
  249. JError::raiseError(500, JText::_('COM_JOOMLEAGUE_GLOBAL_SELECT_TO_DELETE'));
  250. }
  251. // Access checks.
  252. foreach ($cid as $i => $id)
  253. {
  254. if (!$user->authorise('core.admin', 'com_joomleague') ||
  255. !$user->authorise('core.admin', 'com_joomleague.project.'.(int) $project_id) ||
  256. !$user->authorise('core.delete', 'com_joomleague.project_team.'.(int) $id))
  257. {
  258. // Prune items that you can't delete.
  259. unset($cid[$i]);
  260. JError::raiseNotice(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
  261. }
  262. }
  263. $model = $this->getModel('team');
  264. if (!$model->delete($cid))
  265. {
  266. echo "<script> alert('" . $model->getError(true) . "'); window.history.go(-1); </script>\n";
  267. }
  268. $this->setRedirect('index.php?option=com_joomleague&view=teams&task=projectteam.display');
  269. }
  270. public function publish()
  271. {
  272. $this->setRedirect('index.php?option=com_joomleague&view=teams&task=projectteam.display');
  273. }
  274. public function unpublish()
  275. {
  276. $this->setRedirect('index.php?option=com_joomleague&view=teams&task=projectteam.display');
  277. }
  278. public function cancel()
  279. {
  280. // Checkin the project
  281. $model = $this->getModel('projectteam');
  282. //$model->checkin();
  283. $this->setRedirect('index.php?option=com_joomleague&view=projectteams&task=projectteam.display');
  284. }
  285. /**
  286. * copy team to another project
  287. */
  288. public function copy()
  289. {
  290. $dest = JRequest::getInt('dest');
  291. $ptids = JRequest::getVar('ptids', array(), 'post', 'array');
  292. // check if this is the final step
  293. if (!$dest)
  294. {
  295. JRequest::setVar('view', 'projectteams');
  296. JRequest::setVar('layout', 'copy');
  297. return parent::display();
  298. }
  299. $msg = '';
  300. $type = 'message';
  301. $model = $this->getModel('projectteams');
  302. if (!$model->copy($dest, $ptids))
  303. {
  304. $msg = $model->getError();
  305. $type = 'error';
  306. }
  307. else
  308. {
  309. $msg = JText::_('COM_JOOMLEAGUE_ADMIN_PROJECTTEAMS_COPY_SUCCESS');
  310. }
  311. $this->setRedirect('index.php?option=com_joomleague&view=projectteams&task=projectteam.display', $msg, $type);
  312. $this->redirect();
  313. }
  314. /**
  315. * Proxy for getModel
  316. *
  317. * @param string $name The model name. Optional.
  318. * @param string $prefix The class prefix. Optional.
  319. *
  320. * @return object The model.
  321. * @since 1.6
  322. */
  323. public function getModel($name = 'Projectteam', $prefix = 'JoomleagueModel', $config = array('ignore_request' => true))
  324. {
  325. $model = parent::getModel($name, $prefix, $config);
  326. return $model;
  327. }
  328. }
  329. ?>