3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * Implemenation of hook_enable()
39 function civicrm_rules_enable() {
40 db_query("UPDATE {system} SET weight = 110 WHERE name = 'civicrm_rules'");
44 * Implement the post hook and fire the corresponding rules event
46 function civicrm_rules_civicrm_post($op, $objectName, $objectId, &$objectRef) {
47 if (!module_exists('rules')) {
51 if (in_array($objectName,
52 array('Individual', 'Household', 'Organization')
54 $objectName = 'Contact';
57 // process only contacts for now
58 $validObjects = array_merge(
59 variable_get('civicrm_rules_post_entities', array()),
60 array('contact' => 'contact')
63 if (!in_array(strtolower($objectName), $validObjects, true)) {
67 $eventObject = strtolower($objectName);
68 if (!in_array($eventObject, $validObjects) &&
69 !in_array($eventObject, array('contact'))
74 if ($eventObject != 'contact') {
75 // without the civicrm prefix too much chance of another drupal module being enabled
76 $eventObject = 'civicrm_' . $eventObject;
84 $eventName = "{$eventObject}_{$op}";
92 rules_invoke_event($eventName, $objectRef);
97 * Implement civicrm pageRun hook and fire the corresponding rules event
99 function civicrm_rules_civicrm_pageRun(&$page) {
100 if (!module_exists('rules')) {
104 // process only contacts for now
105 $validObjects = array('CRM_Contact_Page_View_Summary');
107 $className = get_class($page);
108 if (!in_array($className, $validObjects)) {
113 switch ($className) {
114 case 'CRM_Contact_Page_View_Summary':
115 $eventName = 'contact_view';
123 rules_invoke_event($eventName, $page);
128 * Implement the postProcess hook and fire the corresponding rules event
129 * We'll do this for specific forms only (for now)
131 function civicrm_rules_civicrm_postProcess($formName, &$form) {
132 require_once 'CRM/Mailing/Info.php';
133 if (CRM_Mailing_Info::workflowEnabled()) {
134 $eventName = $eventParams = NULL;
137 case 'CRM_Mailing_Form_Group':
138 if ($form->get('continue') == TRUE) {
139 $eventName = 'mailing_edit';
140 $mailingId = $form->get('mid');
147 $mailingId = CRM_Core_DAO::singleValueQuery($query);
148 $eventName = 'mailing_create';
152 case 'CRM_Mailing_Form_Schedule':
153 if ($form->get('mid')) {
154 $mailingId = $form->get('mid');
157 $mailingId = $form->_mailingID;
159 $eventName = 'mailing_scheduled';
162 case 'CRM_Mailing_Form_Approve':
163 if ($form->_mailingID) {
164 $mailingId = $form->_mailingID;
167 $mailingId = $form->get('mid');
169 $eventName = 'mailing_approved';
172 case 'CRM_Mailing_Form_Upload':
173 $eventName = 'mailing_uploaded';
174 $mailingId = $form->_mailingID;
177 case 'CRM_Mailing_Form_Test':
178 $eventName = 'mailing_inform';
179 $mailingId = $form->get('mailing_id') ? $form->get('mailing_id') : $form->get('mid');
187 require_once 'CRM/Mailing/DAO/Mailing.php';
188 $eventParams = new CRM_Mailing_DAO_Mailing();
189 $eventParams->id = $mailingId;
190 $eventParams->find(TRUE);
191 rules_invoke_event($eventName, $eventParams);
196 * Implementation of hook_permission().
198 function civicrm_rules_permission() {
200 'access civicrm rules settings' =>
201 array('title' => t('Access CiviCRM Rules Settings'),
202 'description' => t('Access CiviCRM Rules Settings.'),
207 function civicrm_rules_menu() {
209 $items['admin/config/civicrm/rules'] = array(
210 'title' => t('CiviCRM Rules settings'),
211 'description' => t('CiviCRM Rules Configuration'),
212 'page callback' => 'drupal_get_form',
213 'page arguments' => array('civicrm_rules_admin_settings'),
214 'access arguments' => array('access civicrm rules settings'),
215 'file' => 'civicrm_rules_admin_form.inc',
216 'type' => MENU_NORMAL_ITEM,