Merge pull request #11197 from agileware/CRM-21104
[civicrm-core.git] / CRM / Event / Form / ManageEvent / Delete.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
32 */
33
34 /**
35 * This class is to build the form for Deleting Group.
36 */
37 class CRM_Event_Form_ManageEvent_Delete extends CRM_Event_Form_ManageEvent {
38
39 /**
40 * Page title.
41 *
42 * @var string
43 */
44 protected $_title;
45
46 /**
47 * Set variables up before form is built.
48 */
49 public function preProcess() {
50 parent::preProcess();
51
52 if ($this->_isTemplate) {
53 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'template_title');
54 }
55 else {
56 $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'title');
57 }
58
59 if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::DELETE)) {
60 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
61 }
62 }
63
64 /**
65 * Build the form object.
66 */
67 public function buildQuickForm() {
68 $this->assign('title', $this->_title);
69
70 $buttons = array(
71 array(
72 'type' => 'next',
73 'name' => $this->_isTemplate ? ts('Delete Event Template') : ts('Delete Event'),
74 'isDefault' => TRUE,
75 ),
76 array(
77 'type' => 'cancel',
78 'name' => ts('Cancel'),
79 ),
80 );
81 $this->addButtons($buttons);
82 }
83
84 /**
85 * Process the form when submitted.
86 */
87 public function postProcess() {
88 $participant = new CRM_Event_DAO_Participant();
89 $participant->event_id = $this->_id;
90
91 if ($participant->find()) {
92 $searchURL = CRM_Utils_System::url('civicrm/event/search', 'reset=1');
93 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>.',
94 array(1 => $searchURL)
95 ), ts('Deletion Error'), 'error');
96 return;
97 }
98 CRM_Event_BAO_Event::del($this->_id);
99 if ($this->_isTemplate) {
100 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Template Deleted'), 'success');
101 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
102 }
103 else {
104 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Event Deleted'), 'success');
105 }
106 }
107
108 }