commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / CRM / Event / Form / ManageEvent / Delete.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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 */
46 protected $_title;
47
48 /**
49 * Set variables up before form is built.
50 *
51 * @return void
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)) {
64 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
65 }
66 }
67
68 /**
69 * Build the form object.
70 *
71 * @return void
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 /**
91 * Process the form when submitted.
92 *
93 * @return void
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>.',
102 array(1 => $searchURL)
103 ), ts('Deletion Error'), 'error');
104 return;
105 }
106 CRM_Event_BAO_Event::del($this->_id);
107 if ($this->_isTemplate) {
108 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Template Deleted'), 'success');
109 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/eventTemplate', 'reset=1'));
110 }
111 else {
112 CRM_Core_Session::setStatus(ts("'%1' has been deleted.", array(1 => $this->_title)), ts('Event Deleted'), 'success');
113 }
114 }
115
116 }