PageRenderTime 65ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 1ms

/drupal/sites/all/modules/civicrm/CRM/Event/Form/ManageEvent.php

https://github.com/michaelmcandrew/th
PHP | 336 lines | 202 code | 44 blank | 90 comment | 41 complexity | bb8c67bc5456dea335a4832ffca229e2 MD5 | raw file
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 4.0 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2011 |
  7. +--------------------------------------------------------------------+
  8. | This file is a part of CiviCRM. |
  9. | |
  10. | CiviCRM is free software; you can copy, modify, and distribute it |
  11. | under the terms of the GNU Affero General Public License |
  12. | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
  13. | |
  14. | CiviCRM is distributed in the hope that it will be useful, but |
  15. | WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
  17. | See the GNU Affero General Public License for more details. |
  18. | |
  19. | You should have received a copy of the GNU Affero General Public |
  20. | License and the CiviCRM Licensing Exception along |
  21. | with this program; if not, contact CiviCRM LLC |
  22. | at info[AT]civicrm[DOT]org. If you have questions about the |
  23. | GNU Affero General Public License or the licensing of CiviCRM, |
  24. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  25. +--------------------------------------------------------------------+
  26. */
  27. /**
  28. *
  29. * @package CRM
  30. * @copyright CiviCRM LLC (c) 2004-2011
  31. * $Id$
  32. *
  33. */
  34. require_once 'CRM/Core/Form.php';
  35. /**
  36. * This class generates form components for processing Event
  37. *
  38. */
  39. class CRM_Event_Form_ManageEvent extends CRM_Core_Form
  40. {
  41. /**
  42. * the id of the event we are proceessing
  43. *
  44. * @var int
  45. * @protected
  46. */
  47. public $_id;
  48. /**
  49. * is this the first page?
  50. *
  51. * @var boolean
  52. * @access protected
  53. */
  54. protected $_first = false;
  55. /**
  56. * are we in single form mode or wizard mode?
  57. *
  58. * @var boolean
  59. * @access protected
  60. */
  61. protected $_single;
  62. protected $_action;
  63. /**
  64. * are we actually managing an event template?
  65. * @var boolean
  66. */
  67. protected $_isTemplate = false;
  68. /**
  69. * pre-populate fields based on this template event_id
  70. * @var integer
  71. */
  72. protected $_templateId;
  73. protected $_cancelURL = null;
  74. /**
  75. * Function to set variables up before form is built
  76. *
  77. * @return void
  78. * @access public
  79. */
  80. function preProcess( )
  81. {
  82. $config = CRM_Core_Config::singleton( );
  83. if ( in_array("CiviEvent", $config->enableComponents) ) {
  84. $this->assign('CiviEvent', true );
  85. }
  86. $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add', 'REQUEST' );
  87. $this->assign( 'action', $this->_action );
  88. $this->_id = CRM_Utils_Request::retrieve( 'id', 'Positive', $this, false );
  89. if ( $this->_id ) {
  90. $this->assign( 'eventId', $this->_id );
  91. if ( empty($this->_addProfileBottom) && empty($this->_addProfileBottomAdd) ) {
  92. $this->add( 'hidden', 'id', $this->_id );
  93. }
  94. $this->_single = true;
  95. $params = array( 'id' => $this->_id );
  96. require_once 'CRM/Event/BAO/Event.php';
  97. CRM_Event_BAO_Event::retrieve( $params, $eventInfo );
  98. // its an update mode, do a permission check
  99. require_once 'CRM/Event/BAO/Event.php';
  100. if ( ! CRM_Event_BAO_Event::checkPermission( $this->_id, CRM_Core_Permission::EDIT ) ) {
  101. CRM_Core_Error::fatal( ts( 'You do not have permission to access this page' ) );
  102. }
  103. $participantListingID = CRM_Utils_Array::value( 'participant_listing_id', $eventInfo );
  104. //CRM_Core_DAO::getFieldValue( 'CRM_Event_DAO_Event', $this->_id, 'participant_listing_id' );
  105. if ( $participantListingID ) {
  106. $participantListingURL = CRM_Utils_System::url( 'civicrm/event/participant',
  107. "reset=1&id={$this->_id}",
  108. true, null, true, true );
  109. $this->assign( 'participantListingURL', $participantListingURL );
  110. }
  111. $this->assign( 'isOnlineRegistration', CRM_Utils_Array::value( 'is_online_registration', $eventInfo ));
  112. $this->assign( 'id', $this->_id );
  113. }
  114. // figure out whether we’re handling an event or an event template
  115. if ( $this->_id ) {
  116. $this->_isTemplate = CRM_Utils_Array::value( 'is_template', $eventInfo );
  117. } elseif ( $this->_action & CRM_Core_Action::ADD) {
  118. $this->_isTemplate = CRM_Utils_Request::retrieve('is_template', 'Boolean', $this);
  119. }
  120. $this->assign('isTemplate', $this->_isTemplate);
  121. if ( $this->_id ) {
  122. if ( $this->_isTemplate ) {
  123. $title = CRM_Utils_Array::value( 'template_title', $eventInfo );
  124. CRM_Utils_System::setTitle(ts('Edit Event Template') . " - $title");
  125. } else {
  126. $title = CRM_Utils_Array::value( 'title', $eventInfo );
  127. CRM_Utils_System::setTitle(ts('Configure Event') . " - $title");
  128. }
  129. $this->assign( 'title', $title );
  130. } else if ( $this->_action & CRM_Core_Action::ADD ) {
  131. if ( $this->_isTemplate ) {
  132. $title = ts('New Event Template');
  133. CRM_Utils_System::setTitle( $title );
  134. } else {
  135. $title = ts('New Event');
  136. CRM_Utils_System::setTitle( $title );
  137. }
  138. $this->assign( 'title', $title );
  139. }
  140. require_once 'CRM/Event/PseudoConstant.php';
  141. $statusTypes = CRM_Event_PseudoConstant::participantStatus(null, 'is_counted = 1', 'label' );
  142. $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(null, 'is_counted = 0', 'label' );
  143. $findParticipants['statusCounted'] = implode( ', ', array_values( $statusTypes ) );
  144. $findParticipants['statusNotCounted'] = implode( ', ', array_values( $statusTypesPending ) );
  145. $this->assign('findParticipants', $findParticipants);
  146. $this->_templateId = (int) CRM_Utils_Request::retrieve('template_id', 'Integer', $this);
  147. // also set up tabs
  148. require_once 'CRM/Event/Form/ManageEvent/TabHeader.php';
  149. CRM_Event_Form_ManageEvent_TabHeader::build( $this );
  150. // Set Done button URL and breadcrumb. Templates go back to Manage Templates,
  151. // otherwise go to Manage Event for new event or ManageEventEdit if event if exists.
  152. $breadCrumb = array( );
  153. if ( !$this->_isTemplate ) {
  154. if ( $this->_id ) {
  155. $this->_doneUrl = CRM_Utils_System::url( CRM_Utils_System::currentPath( ),
  156. "action=update&reset=1&id={$this->_id}" );
  157. } else {
  158. $this->_doneUrl = CRM_Utils_System::url( 'civicrm/event/manage',
  159. 'reset=1' );
  160. $breadCrumb = array( array('title' => ts('Manage Events'),
  161. 'url' => $this->_doneUrl) );
  162. }
  163. } else {
  164. $this->_doneUrl = CRM_Utils_System::url( 'civicrm/admin/eventTemplate', 'reset=1' );
  165. $breadCrumb = array( array('title' => ts('Manage Event Templates'),
  166. 'url' => $this->_doneUrl) );
  167. }
  168. CRM_Utils_System::appendBreadCrumb($breadCrumb);
  169. }
  170. /**
  171. * This function sets the default values for the form. For edit/view mode
  172. * the default values are retrieved from the database
  173. *
  174. * @access public
  175. * @return None
  176. */
  177. function setDefaultValues( )
  178. {
  179. $defaults = array( );
  180. if ( isset( $this->_id ) ) {
  181. $params = array( 'id' => $this->_id );
  182. require_once 'CRM/Event/BAO/Event.php';
  183. CRM_Event_BAO_Event::retrieve($params, $defaults);
  184. } elseif ($this->_templateId) {
  185. $params = array('id' => $this->_templateId);
  186. require_once 'CRM/Event/BAO/Event.php';
  187. CRM_Event_BAO_Event::retrieve($params, $defaults);
  188. $defaults['is_template'] = $this->_isTemplate;
  189. $defaults['template_id'] = $defaults['id'];
  190. unset($defaults['id']);
  191. } else {
  192. $defaults['is_active'] = 1;
  193. $defaults['style'] = 'Inline';
  194. }
  195. return $defaults;
  196. }
  197. /**
  198. * Function to build the form
  199. *
  200. * @return None
  201. * @access public
  202. */
  203. public function buildQuickForm( )
  204. {
  205. $className = CRM_Utils_System::getClassName($this);
  206. $session = & CRM_Core_Session::singleton( );
  207. $this->_cancelURL = CRM_Utils_Array::value( 'cancelURL', $_POST );
  208. if ( !$this->_cancelURL ) {
  209. if ( $this->_isTemplate ) {
  210. $this->_cancelURL = CRM_Utils_System::url('civicrm/admin/eventTemplate',
  211. 'reset=1');
  212. } else {
  213. $this->_cancelURL = CRM_Utils_System::url('civicrm/event/manage',
  214. 'reset=1');
  215. }
  216. }
  217. if ( $this->_cancelURL ) {
  218. $this->addElement( 'hidden', 'cancelURL', $this->_cancelURL );
  219. }
  220. $buttons = array( );
  221. if ( $this->_single ) {
  222. // make this form an upload since we dont know if the custom data injected dynamically
  223. // is of type file etc $uploadNames = $this->get( 'uploadNames' );
  224. $buttons = array(
  225. array ( 'type' => 'upload',
  226. 'name' => ts('Save'),
  227. 'isDefault' => true ),
  228. array ( 'type' => 'upload',
  229. 'name' => ts('Save and Done'),
  230. 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
  231. 'subName' => 'done' ),
  232. array ( 'type' => 'cancel',
  233. 'name' => ts('Cancel') ),
  234. );
  235. $this->addButtons( $buttons );
  236. } else {
  237. $buttons = array( );
  238. if ( ! $this->_first ) {
  239. $buttons[] = array ( 'type' => 'back',
  240. 'name' => ts('<< Previous'),
  241. 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' );
  242. }
  243. $buttons[] = array ( 'type' => 'upload',
  244. 'name' => ts('Continue >>'),
  245. 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
  246. 'isDefault' => true );
  247. $buttons[] = array ( 'type' => 'cancel',
  248. 'name' => ts('Cancel') );
  249. $this->addButtons( $buttons );
  250. }
  251. $session->replaceUserContext( $this->_cancelURL );
  252. $this->add('hidden', 'is_template', $this->_isTemplate);
  253. }
  254. function endPostProcess( )
  255. {
  256. // make submit buttons keep the current working tab opened.
  257. if ( $this->_action & CRM_Core_Action::UPDATE ) {
  258. $className = CRM_Utils_String::getClassName( $this->_name );
  259. if ( $className == 'EventInfo' ) {
  260. $subPage = 'eventInfo';
  261. } elseif ( $className == 'Event' ) {
  262. $subPage = 'friend';
  263. } else {
  264. $subPage = strtolower( $className );
  265. }
  266. CRM_Core_Session::setStatus( ts("'%1' information has been saved.", array(1 => ( $subPage == 'friend' )?'Friend':$className ) ) );
  267. $this->postProcessHook( );
  268. if ( $this->controller->getButtonName('submit') == "_qf_{$className}_upload_done" ) {
  269. if ( $this->_isTemplate ) {
  270. CRM_Utils_System::redirect( CRM_Utils_System::url( 'civicrm/admin/eventTemplate',
  271. 'reset=1' ) );
  272. } else {
  273. CRM_Utils_System::redirect( CRM_Utils_System::url( 'civicrm/event/manage',
  274. 'reset=1' ) );
  275. }
  276. } else {
  277. CRM_Utils_System::redirect( CRM_Utils_System::url( "civicrm/event/manage/{$subPage}",
  278. "action=update&reset=1&id={$this->_id}" ) );
  279. }
  280. }
  281. }
  282. function getTemplateFileName( )
  283. {
  284. if ( $this->controller->getPrint( ) == CRM_Core_Smarty::PRINT_NOFORM ||
  285. $this->getVar( '_id' ) <= 0 ||
  286. ( $this->_action & CRM_Core_Action::DELETE ) ) {
  287. return parent::getTemplateFileName( );
  288. } else {
  289. return 'CRM/Event/Form/ManageEvent/Tab.tpl';
  290. }
  291. }
  292. }