Import from SVN (r45945, r596)
[civicrm-core.git] / CRM / Event / Form / ManageEvent / Delete.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class is to build the form for Deleting Group
38 */
39 class CRM_Event_Form_ManageEvent_Delete extends CRM_Event_Form_ManageEvent {
40
41 /**
42 * page title
43 *
44 * @var string
45 * @protected
46 */
47 protected $_title;
48
49 /**
50 * Function to set variables up before form is built
51 *
52 * @return void
53 * @access public
54 */
55 public function preProcess() {
56 parent::preProcess();
57
58 if ($this->_isTemplate) {
59 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'template_title');
60 }
61 else {
62 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'title');
63 }
64
65 if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::DELETE)) {
66 CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
67 }
68 }
69
70 /**
71 * Function to actually build the form
72 *
73 * @return None
74 * @access public
75 */
76 public function buildQuickForm() {
77 $this->assign('title', $this->_title);
78
79 $buttons = array(
80 array(
81 'type' => 'next',
82 'name' => $this->_isTemplate ? ts('Delete Event Template') : ts('Delete Event'),
83 'isDefault' => TRUE,
84 ),
85 array(
86 'type' => 'cancel',
87 'name' => ts('Cancel'),
88 ),
89 );
90 $this->addButtons($buttons);
91 }
92
93 /**
94 * Process the form when submitted
95 *
96 * @return void
97 * @access public
98 */
99 public function postProcess() {
100 $participant = new CRM_Event_DAO_Participant();
101 $participant->event_id = $this->_id;
102
103 if ($participant->find()) {
104 $searchURL = CRM_Utils_System::url('civicrm/event/search', 'reset=1');
105 CRM_Core_Session::setStatus(ts('This event cannot be deleted because there are participant records linked to it. If you want to delete this event, you must first find the participants linked to this event and delete them. You can use use <a href=\'%1\'> CiviEvent >> Find Participants page </a>.',
106 array(1 => $searchURL)
107 ), ts('Deletion Error'), 'error');
108 return;
109 }
110 CRM_Event_BAO_Event::del($this->_id);
111 if ($this->_isTemplate) {
112 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), t('Template Deleted'), 'success');
113 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
114 }
115 else {
116 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), t('Event Deleted'), 'success');
117 }
118 }
119 }
120