Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
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 | /** | |
66f9e52b | 42 | * Page title. |
6a488035 TO |
43 | * |
44 | * @var string | |
6a488035 TO |
45 | */ |
46 | protected $_title; | |
47 | ||
48 | /** | |
66f9e52b | 49 | * Set variables up before form is built. |
6a488035 TO |
50 | * |
51 | * @return void | |
6a488035 TO |
52 | */ |
53 | public function preProcess() { | |
54 | parent::preProcess(); | |
55 | ||
56 | if ($this->_isTemplate) { | |
57 | $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'template_title'); | |
58 | } | |
59 | else { | |
60 | $this->_title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'title'); | |
61 | } | |
62 | ||
63 | if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::DELETE)) { | |
0499b0ad | 64 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
65 | } |
66 | } | |
67 | ||
68 | /** | |
66f9e52b | 69 | * Build the form object. |
6a488035 | 70 | * |
355ba699 | 71 | * @return void |
6a488035 TO |
72 | */ |
73 | public function buildQuickForm() { | |
74 | $this->assign('title', $this->_title); | |
75 | ||
76 | $buttons = array( | |
77 | array( | |
78 | 'type' => 'next', | |
79 | 'name' => $this->_isTemplate ? ts('Delete Event Template') : ts('Delete Event'), | |
80 | 'isDefault' => TRUE, | |
81 | ), | |
82 | array( | |
83 | 'type' => 'cancel', | |
84 | 'name' => ts('Cancel'), | |
85 | ), | |
86 | ); | |
87 | $this->addButtons($buttons); | |
88 | } | |
89 | ||
90 | /** | |
66f9e52b | 91 | * Process the form when submitted. |
6a488035 TO |
92 | * |
93 | * @return void | |
6a488035 TO |
94 | */ |
95 | public function postProcess() { | |
96 | $participant = new CRM_Event_DAO_Participant(); | |
97 | $participant->event_id = $this->_id; | |
98 | ||
99 | if ($participant->find()) { | |
100 | $searchURL = CRM_Utils_System::url('civicrm/event/search', 'reset=1'); | |
101 | 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>.', | |
353ffa53 TO |
102 | array(1 => $searchURL) |
103 | ), ts('Deletion Error'), 'error'); | |
6a488035 TO |
104 | return; |
105 | } | |
106 | CRM_Event_BAO_Event::del($this->_id); | |
107 | if ($this->_isTemplate) { | |
c7692a87 | 108 | CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Template Deleted'), 'success'); |
6a488035 TO |
109 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1')); |
110 | } | |
111 | else { | |
c7692a87 | 112 | CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Event Deleted'), 'success'); |
6a488035 TO |
113 | } |
114 | } | |
96025800 | 115 | |
6a488035 | 116 | } |