2 #http://pastebin.com/U32jjBVu - D7 has renamed admin settings
3 function civicrm_engage_admin_settings($form_state = NULL) {
4 $form['last_donate'] = array(
6 '#title' => t('CiviEngage Walklist Last Donate presentation'),
8 '#collapsible' => TRUE,
11 $form['last_donate']['civicrm_engage_no_canvas_period'] = array(
12 '#title' => t("Exclusion Period"),
13 '#type' => 'textfield',
14 '#description' => t('If you wish to leave someone alone for a period after their last donation please enter it here (in months). 0 means disabled'),
15 '#default_value' => variable_get('civicrm_engage_no_canvas_period', "0"),
17 $form['last_donate']['civicrm_engage_no_canvass_text'] = array(
18 '#title' => t("Text when within exclusion period"),
19 '#type' => 'textfield',
20 '#description' => t('Text to put in if contact not to be canvassed'),
21 '#default_value' => variable_get('civicrm_engage_no_canvass_text', "Do Not Canvass"),
23 $form['break_settings'] = array(
24 '#type' => 'fieldset',
25 '#title' => t('CiviEngage Walklist data grouping'),
27 '#collapsible' => TRUE,
28 '#collapsed' => FALSE,
30 $form['break_settings']['civicrm_engage_groupbreak_odd_even'] = array(
31 '#title' => t("Group break on odds / evens"),
32 '#type' => 'checkbox',
33 '#description' => t('Do you want a group-break between each side of the street'),
34 '#default_value' => variable_get('civicrm_engage_groupbreak_odd_even', "1"),
36 $form['break_settings']['civicrm_engage_groupbreak_street'] = array(
37 '#title' => t("Group break on street "),
38 '#type' => 'checkbox',
39 '#description' => t('Do you want a group-break between each street'),
40 '#default_value' => variable_get('civicrm_engage_groupbreak_street', "1"),
42 $form['break_settings']['civicrm_engage_groupbreak_city'] = array(
43 '#title' => t("Group break on city"),
44 '#type' => 'checkbox',
45 '#description' => t('Do you want a group-break between each city'),
46 '#default_value' => variable_get('civicrm_engage_groupbreak_city', "1"),
48 $form['break_settings']['civicrm_engage_groupbreak_zip'] = array(
49 '#title' => t("Group break on zip code"),
50 '#type' => 'checkbox',
51 '#description' => t('Do you want a group-break between each side of the street'),
52 '#default_value' => variable_get('civicrm_engage_groupbreak_zip', "1"),
54 $form['break_settings']['civicrm_engage_lines_per_group'] = array(
55 '#title' => t("Row limit per group"),
56 '#type' => 'textfield',
57 '#description' => t('Limit rows per group - ie. if you want to print out in blocks of 6'),
58 '#default_value' => variable_get('civicrm_engage_lines_per_group', "6"),
60 $form['break_settings']['civicrm_engage_group_per_page'] = array(
61 '#title' => t("New page for each group?"),
62 '#type' => 'checkbox',
63 '#description' => t('Do you want each group to have new page? (default is yes)'),
64 '#default_value' => variable_get('civicrm_engage_group_per_page', "1"),
66 return system_settings_form($form);
69 function civicrm_engage_admin_load_data($form_state = NULL) {
70 $subtypes_added = NULL;
71 if(civicrm_engage_subtypes_added()) {
72 $subtypes_added = ' <em>' . t("It appears that the contact sub types are present.") . '</em>';
74 $custom_data_added = NULL;
75 if(civicrm_engage_custom_data_added()) {
76 $custom_data_added = ' <em>' . t("It appears that the custom data is present.") . '</em>';
78 $custom_voter_us_data_added = NULL;
79 if(civicrm_engage_custom_voter_us_data_added()) {
80 $custom_voter_us_data_added = ' <em>' . t("It appears that the US custom voter data is present.") . '</em>';
82 $address_parsing_enabled = NULL;
83 if(civicrm_engage_address_parsing_enabled()) {
84 $address_parsing_enabled = ' <em>' . t("It appears that address parsing is enabled.") . '</em>';
86 $autocomplete_options_set = NULL;
87 if(civicrm_engage_autocomplete_options_set()) {
88 $autocomplete_options_set = ' <em>' . t("It appears that the autocomplete options are properly set.") . '</em>';
90 $form['load_data'] = array(
91 '#type' => 'fieldset',
92 '#title' => t('CiviEngage Load Data and Set Configuration Options'),
94 '#collapsible' => TRUE,
95 '#collapsed' => FALSE,
98 $form['load_data']['contact_subtypes'] = array(
99 '#type' => 'checkbox',
100 '#title' => t('Add contact subtypes'),
101 '#description' => t("Civicrm Engage depends on the presence of a Media, Funder, Elected Official, Media Outlet and Foundation contact subtypes. Check this box to add them. This step is not reversible.") . $subtypes_added
103 $form['load_data']['address_parsing'] = array(
104 '#type' => 'checkbox',
105 '#title' => t('Enable address parsing'),
106 '#description' => t("Street parsing is required for walk lists because it needs to sort by even/odd address numbers.") . $address_parsing_enabled
108 $form['load_data']['autocomplete_options'] = array(
109 '#type' => 'checkbox',
110 '#title' => t('Set phone to autocomplete'),
111 '#description' => t("Autocomplete options double as indicator of whether a field should show up in batch update. For civicrm engage to work properly, phone should be set to autocomplete so it shows up in batch update.") . $autocomplete_options_set
113 $form['load_data']['custom_data'] = array(
114 '#type' => 'checkbox',
115 '#title' => t('Add general custom groups, fields and other data'),
116 '#description' => t("Civicrm Engage depends on a number of custom data groups and fields and profiles. Check this box to add them. This step is not reversible and will take several minutes to complete.") . $custom_data_added
118 $form['load_data']['custom_voter_us_data'] = array(
119 '#type' => 'checkbox',
120 '#title' => t('Add US voter custom groups, fields and other data'),
121 '#description' => t("Civicrm Engage depends on voter-related fields being imported (to track congressional district, city district, etc.). Current only US-specific voter fields are available.") . $custom_voter_us_data_added
123 $form['load_data']['submit'] = array(
131 function civicrm_engage_admin_load_data_submit($form, &$form_state) {
132 if($form_state['values']['contact_subtypes'] == 1) {
133 civicrm_engage_load_contact_subtypes();
135 if($form_state['values']['custom_data'] == 1) {
136 civicrm_engage_load_custom_data();
138 if($form_state['values']['custom_voter_us_data'] == 1) {
139 civicrm_engage_load_custom_voter_us_data();
141 if($form_state['values']['address_parsing'] == 1) {
142 civicrm_engage_enable_address_parsing();
144 if($form_state['values']['autocomplete_options'] == 1) {
145 civicrm_engage_set_autocomplete_options();
150 * Check to see if the subtypes have already been added.
152 function civicrm_engage_subtypes_added() {
153 civicrm_initialize();
154 require_once ("CRM/Contact/BAO/ContactType.php");
155 $existing_types = CRM_Contact_BAO_ContactType::subTypeInfo();
156 if(array_key_exists('Media_Outlet', $existing_types)) {
163 * Check to see if the custom data has already been added.
165 function civicrm_engage_custom_data_added() {
166 civicrm_initialize();
167 $sql = "SELECT is_active FROM civicrm_uf_group WHERE name = 'update_constituent_info'";
168 $dao = CRM_Core_DAO::executeQuery($sql);
170 if(!property_exists($dao, 'is_active')) return false;
171 if($dao->is_active == 1) return true;
176 * Check to see if the custom voter us data has already been added.
178 function civicrm_engage_custom_voter_us_data_added() {
179 civicrm_initialize();
180 $sql = "SELECT is_active FROM civicrm_uf_group WHERE name = 'update_voter_info'";
181 $dao = CRM_Core_DAO::executeQuery($sql);
183 if(!property_exists($dao, 'is_active')) return false;
184 if($dao->is_active == 1) return true;
189 * Create contact subtypes which are referenced in the
190 * xml file that is imported to boostrap the CiviCRM
191 * Campaign component. This function is indempotent, so
192 * it's run on enable.
194 function civicrm_engage_load_contact_subtypes() {
195 // parent_id : 1 is Individual, 3 is Organization
197 'Media_Contact' => array(
198 'label' => 'Media Contact',
201 'name' => 'Media_Contact',
203 'Funder_Contact' => array(
204 'label' => 'Funder Contact',
207 'name' => 'Funder_Contact',
209 'Elected_Official' => array(
210 'label' => 'Elected Official',
213 'name' => 'Elected_Official',
215 'Media_Outlet' => array(
216 'label' => 'Media Outlet',
219 'name' => 'Media_Outlet',
221 'Foundation' => array(
222 'label' => 'Foundation',
225 'name' => 'Foundation',
228 require_once ("CRM/Contact/BAO/ContactType.php");
229 $existing_types = CRM_Contact_BAO_ContactType::subTypeInfo();
230 while (list($k) = each($existing_types)) {
231 if (array_key_exists($k, $create)) {
232 drupal_set_message(t("Not creating @type, already exists.", array("@type" => $k)));
236 $contact_type = new CRM_Contact_BAO_ContactType();
237 while (list($k, $v) = each($create)) {
238 drupal_set_message(t("Creating %c", array('%c' => $k)));
239 $contact_type->add($v);
243 function civicrm_engage_load_custom_data() {
244 drupal_set_message("Loading default civicrm_engage custom data.");
245 $xml_file = civicrm_engage_get_absolute_module_path() . '/CustomGroupData.xml';
246 require_once 'CRM/Utils/Migrate/Import.php';
247 $import = new CRM_Utils_Migrate_Import();
248 $import->run($xml_file);
250 // The xml file sets up a field with a contact reference limited to the staff
251 // group (staff responsible). So, we have to make sure the staff group exists
252 // and if not create it and update the id number in the staff responsible
254 drupal_set_message("Creating staff group.");
255 return civicrm_engage_load_staff_group();
259 * Create group that will be used to populate the responsible
260 * staff custom data field.
262 function civicrm_engage_load_staff_group() {
263 // Record the id of the group we create so we can ensure that the
264 // staff responsible contact reference field is restricted to the
268 // Check if it exists already
269 $params = array('name' => 'staff');
270 $result = civicrm_api3('Group', 'Get', $params);
271 if($result['count'] > 0) {
272 // We already have the group in place.
273 drupal_set_message(t("Staff group already exists."));
274 $row = array_pop($result['values']);
278 // Otherwise, we have to add it.
282 'description' => 'Contacts in this group are used to populate the staff responsible field.',
288 $result = civicrm_api3('Group', 'create', $params);
289 drupal_set_message(t("Staff group created."));
290 $row = array_pop($result['values']);
294 $sql = "UPDATE civicrm_custom_field SET filter = 'action=lookup&group=%0' WHERE
295 name = 'staff_responsible' OR name = 'event_contact_person'";
297 0 => array($id, 'Integer')
299 CRM_Core_DAO::executeQuery($sql, $params);
302 catch (CiviCRM_API3_Exception $e) {
303 drupal_set_message(t("Failed to load staff group."));
304 drupal_set_message($e->getMessage());
310 function civicrm_engage_load_custom_voter_us_data() {
311 drupal_set_message("Loading default civicrm_engage US custom voter data.");
312 $xml_file = civicrm_engage_get_absolute_module_path() . '/Voter.us.xml';
313 require_once 'CRM/Utils/Migrate/Import.php';
314 $import = new CRM_Utils_Migrate_Import();
315 $import->run($xml_file);
318 function civicrm_engage_address_parsing_enabled() {
319 civicrm_initialize();
320 include_once 'CRM/Core/BAO/Setting.php';
321 $address_options = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
325 if($address_options['street_address_parsing'] == 1) {
332 * Helper file to get path to civicrm_engage directory
334 function civicrm_engage_get_absolute_module_path() {
335 // we need to build the path to the Voter.us.xml file
336 // shipped in the civicrm_engage directory. civicrm_engage could
337 // be installed outside of the civicrm root, so we can't rely on
340 // instead... start with the drupal root
342 // and then added the relative path to the module
343 return $root . '/' . drupal_get_path('module', 'civicrm_engage');
347 * Street parsing is required for walk lists because it needs to
348 * sort by even/odd address numbers so, when canvassing a street
349 * in which even addresses are on one side and odd on the other, you
350 * can divide the task between two people with two different lists.
352 function civicrm_engage_enable_address_parsing() {
353 civicrm_initialize();
354 include_once 'CRM/Core/BAO/Setting.php';
355 $address_options = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
359 $address_options['street_address_parsing'] = 1;
360 CRM_Core_BAO_Setting::setValueOption(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
364 drupal_set_message("Addressing parsing options saved.");
367 function civicrm_engage_autocomplete_options_set() {
368 civicrm_initialize();
369 include_once 'CRM/Core/BAO/Setting.php';
370 $contact_autocomplete_options = CRM_Core_BAO_Setting::valueOptions(
371 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
372 'contact_autocomplete_options',
375 if($contact_autocomplete_options['phone'] == 1) {
382 * Check Phone Number for auto complete. This setting doubles for batch
383 * update, and when making a phone list in CiviCampaign you really need
384 * to have the phone number included.
386 function civicrm_engage_set_autocomplete_options() {
387 civicrm_initialize();
388 include_once 'CRM/Core/BAO/Setting.php';
389 $contact_autocomplete_options = CRM_Core_BAO_Setting::valueOptions(
390 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
391 'contact_autocomplete_options',
394 $contact_autocomplete_options['phone'] = 1;
395 CRM_Core_BAO_Setting::setValueOption(
396 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
397 'contact_autocomplete_options',
398 $contact_autocomplete_options
400 drupal_set_message(t("Autocomplete options have been saved."));