| 1 |
<?php
|
| 2 |
//$Id: civinode.module,v 1.21 2006/06/12 21:15:47 torenware Exp $
|
| 3 |
|
| 4 |
|
| 5 |
$mod_path = drupal_get_path('module', 'civinode');
|
| 6 |
require_once $mod_path . "/civinode_utils.inc";
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Drupal Hooks
|
| 12 |
*
|
| 13 |
* @defgroup CiviNode_Drupal_Hooks
|
| 14 |
*/
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Implementation of hook_menu
|
| 21 |
*
|
| 22 |
*
|
| 23 |
* @ingroup CiviNode_Drupal_Hooks
|
| 24 |
*/
|
| 25 |
function civinode_menu($may_cache){
|
| 26 |
$items = array();
|
| 27 |
if (!civinode_check_init())
|
| 28 |
return NULL;
|
| 29 |
if ($may_cache) {
|
| 30 |
|
| 31 |
$items[] = array('path' => 'civinode/tests',
|
| 32 |
'title' => t('Test CiviNode Profile Routines'),
|
| 33 |
'callback' => 'civinode_test_handler',
|
| 34 |
'type' => MENU_CALLBACK,
|
| 35 |
'access' => user_access('administer CiviCRM')
|
| 36 |
);
|
| 37 |
|
| 38 |
$items[] = array('path' => 'civinode/activity',
|
| 39 |
'title' => t('Activity Details'),
|
| 40 |
'callback' => 'civinode_default_activity_handler',
|
| 41 |
'access' => user_access('administer CiviCRM'),
|
| 42 |
'type' => MENU_CALLBACK);
|
| 43 |
|
| 44 |
//admin stuff
|
| 45 |
$items[] = array('path' => 'admin/settings/civinode',
|
| 46 |
'title' => t('CiviNode Settings'),
|
| 47 |
'callback' => 'drupal_get_form',
|
| 48 |
'description' => t('Set display options for CiviCRM content in Drupal pages.'),
|
| 49 |
'callback arguments' => array('civinode_settings_form'),
|
| 50 |
'access' => user_access('administer CiviCRM')
|
| 51 |
);
|
| 52 |
//Autocompleters. Actually URL given to AC code should be of the
|
| 53 |
//format 'civinode/autocomplete/contact/KEY/VAL, which can
|
| 54 |
//be all/all. For now, you can pass gid/GID to get qualification
|
| 55 |
//by group.
|
| 56 |
$items[] = array('path' => 'civinode/autocomplete/contact',
|
| 57 |
'callback' => 'civinode_contact_autocompleter',
|
| 58 |
'type' => MENU_CALLBACK,
|
| 59 |
'access' => user_access('View CiviCRM Data')
|
| 60 |
);
|
| 61 |
|
| 62 |
//dojo version of autocompleter
|
| 63 |
$items[] = array('path' => 'civinode/dojo',
|
| 64 |
'callback' => 'civinode_dojo_widgets',
|
| 65 |
'type' => MENU_CALLBACK,
|
| 66 |
'access' => user_access('View CiviCRM Data')
|
| 67 |
);
|
| 68 |
|
| 69 |
|
| 70 |
}
|
| 71 |
else {
|
| 72 |
drupal_add_css(drupal_get_path('module', 'civinode') .'/module.css');
|
| 73 |
}
|
| 74 |
return $items;
|
| 75 |
|
| 76 |
}
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
/**
|
| 82 |
* Implementation of hook_perm. This needs to get factored into
|
| 83 |
* at least one other module.
|
| 84 |
*
|
| 85 |
*/
|
| 86 |
function civinode_perm(){
|
| 87 |
return array('administer civinode', 'View CiviCRM Data');
|
| 88 |
|
| 89 |
}
|
| 90 |
|
| 91 |
|
| 92 |
/**
|
| 93 |
* Admin Pages
|
| 94 |
*
|
| 95 |
* @defgroup CiviNode_Admin_Pages
|
| 96 |
*/
|
| 97 |
|
| 98 |
|
| 99 |
/**
|
| 100 |
* Settings for for CiviNode
|
| 101 |
*
|
| 102 |
* @ingroup CiviNode_Admin_Pages
|
| 103 |
*/
|
| 104 |
function civinode_settings_form(){
|
| 105 |
$form['civinode_default_pid'] =
|
| 106 |
civinode_profile_selector(t('Default Profile'),
|
| 107 |
t('default CiviCRM profile to use when displaying contacts'),
|
| 108 |
variable_get('civinode_default_pid', 1));
|
| 109 |
|
| 110 |
return system_settings_form($form);;
|
| 111 |
}
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
/**
|
| 119 |
* Default menu handler for CiviCRM Activity callbacks.
|
| 120 |
*
|
| 121 |
*/
|
| 122 |
function civinode_default_activity_handler(){
|
| 123 |
$crm_activity_id = arg(2);
|
| 124 |
$internal_id = arg(3);
|
| 125 |
$output = "";
|
| 126 |
if (civinode_check_init()) {
|
| 127 |
$output .= "For Activity $crm_activity_id (extra info $internal_id):<br />\n";
|
| 128 |
$defaults = civinode_get_activity($crm_activity_id);
|
| 129 |
if (!$defaults) {
|
| 130 |
$output .= "We got an error: <strong>" . civinode_get_last_error() . "</strong><br />\n";
|
| 131 |
}
|
| 132 |
else {
|
| 133 |
ob_start();
|
| 134 |
print_r($defaults);
|
| 135 |
$output .= "<pre>";
|
| 136 |
$output .= ob_get_clean() . "</pre>\n";
|
| 137 |
}
|
| 138 |
}
|
| 139 |
else
|
| 140 |
$output = "Activity details will display here (turn on CRM!)";
|
| 141 |
return $output;
|
| 142 |
|
| 143 |
}
|
| 144 |
|
| 145 |
/**
|
| 146 |
* Testing and debugging routines
|
| 147 |
*
|
| 148 |
* @defgroup CiviNode_Test_And_Debugging
|
| 149 |
*/
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
/**
|
| 154 |
* Main menu callback for displaying test pages
|
| 155 |
*
|
| 156 |
* @ingroup CiviNode_Test_And_Debugging
|
| 157 |
*/
|
| 158 |
function civinode_test_handler(){
|
| 159 |
$type = arg(2);
|
| 160 |
$id = arg(3);
|
| 161 |
|
| 162 |
switch($type){
|
| 163 |
case 'profile':
|
| 164 |
return civinode_test_profile($id);
|
| 165 |
case 'contact':
|
| 166 |
return civinode_test_contact($id);
|
| 167 |
case 'auto':
|
| 168 |
return civinode_test_auto($id);
|
| 169 |
|
| 170 |
default:
|
| 171 |
//drupal_not_found();
|
| 172 |
return "<p>Type = $type, ID = $id</p>\n";
|
| 173 |
}
|
| 174 |
}
|
| 175 |
|
| 176 |
/**
|
| 177 |
* Test page for profile data.
|
| 178 |
*
|
| 179 |
* @ingroup CiviNode_Test_And_Debugging
|
| 180 |
*/
|
| 181 |
function civinode_test_profile($id){
|
| 182 |
$output = "";
|
| 183 |
$output .= "<pre>\n";
|
| 184 |
$raw_data = civinode_get_profile_metadata($id);
|
| 185 |
ob_start();
|
| 186 |
print_r($raw_data);
|
| 187 |
$output .= ob_get_clean();
|
| 188 |
$output .= "</pre>\n";
|
| 189 |
return $output;
|
| 190 |
}
|
| 191 |
|
| 192 |
/**
|
| 193 |
* Test page for profile data.
|
| 194 |
*
|
| 195 |
* @ingroup CiviNode_Test_And_Debugging
|
| 196 |
*/
|
| 197 |
function civinode_test_contact($id){
|
| 198 |
$output = "";
|
| 199 |
$output .= "<pre>\n";
|
| 200 |
$raw_data = civinode_util_load_cdata($id);
|
| 201 |
ob_start();
|
| 202 |
print_r($raw_data);
|
| 203 |
$output .= ob_get_clean();
|
| 204 |
$output .= "</pre>\n";
|
| 205 |
return $output;
|
| 206 |
}
|
| 207 |
|
| 208 |
|
| 209 |
/**
|
| 210 |
* Test page for autocompler widget.
|
| 211 |
*
|
| 212 |
* @ingroup CiviNode_Test_And_Debugging
|
| 213 |
*/
|
| 214 |
function civinode_test_auto($id){
|
| 215 |
//Test autocompletion handlers
|
| 216 |
if ($id == 'contact') {
|
| 217 |
$output = "<p>Here is a test for autocompletion of contacts</p>";
|
| 218 |
$form['testme'] = civinode_contact_auto_selector('Auto Test');
|
| 219 |
$output .= drupal_get_form('auto_test', $form);
|
| 220 |
return $output;
|
| 221 |
}
|
| 222 |
return "No handler for type $id";
|
| 223 |
}
|
| 224 |
|
| 225 |
|
| 226 |
/**
|
| 227 |
* Test theme for displaying contacts
|
| 228 |
*
|
| 229 |
* @ingroup CiviNode_Test_And_Debugging
|
| 230 |
*/
|
| 231 |
function theme_civinode_contact_debug($node){
|
| 232 |
//Simple placeholder so we can see what's going on
|
| 233 |
$output = "<pre>\n";
|
| 234 |
ob_start();
|
| 235 |
print_r($node);
|
| 236 |
$output .= ob_get_clean();
|
| 237 |
$output .= "</pre>\n";
|
| 238 |
return $output;
|
| 239 |
}
|
| 240 |
|
| 241 |
|
| 242 |
/**
|
| 243 |
* Default theme for a Nodified contact
|
| 244 |
*
|
| 245 |
* @ingroup CiviNode_Nodifier
|
| 246 |
*/
|
| 247 |
function theme_crm_profile_group($pid, $node){
|
| 248 |
$meta_data = civinode_get_profile_metadata($pid, 'view');
|
| 249 |
if (!$meta_data)
|
| 250 |
return ""; //nothing to display.
|
| 251 |
//Some debugging code
|
| 252 |
ob_start();
|
| 253 |
print_r ($meta_data);
|
| 254 |
$meta_debug = ob_get_clean();
|
| 255 |
$classes = "crm-profile crm-profile-$pid";
|
| 256 |
$output = "<div class='$classes'>\n";
|
| 257 |
$title = civinode_get_profile_title($pid);
|
| 258 |
//TO DO: do we need to filter the text here??
|
| 259 |
$output .= "<h2 class='crm-profile-title'>$title</h2>";
|
| 260 |
//Get the fields and render them
|
| 261 |
$field_list = civinode_get_profile_field_list($pid, 'view');
|
| 262 |
//Some debugging code
|
| 263 |
ob_start();
|
| 264 |
print_r ($field_list);
|
| 265 |
$fl_debug = ob_get_clean();
|
| 266 |
$output .= "<dl>\n";
|
| 267 |
foreach ($field_list as $node_field => $field) {
|
| 268 |
$field_desc = civinode_get_field_info($pid, $field, 'view');
|
| 269 |
//TO DO:
|
| 270 |
//For now, if a field has no data, do not print it. This
|
| 271 |
//may need to be an argument to this function, however.
|
| 272 |
if (!isset($node->$node_field) or !$node->$node_field)
|
| 273 |
continue;
|
| 274 |
$f_title = $field_desc['title'];
|
| 275 |
//Work around for CRM-847
|
| 276 |
if (!$title)
|
| 277 |
$f_title = $field;
|
| 278 |
$class = "crm-profile-item crm-profile-item-$node_field";
|
| 279 |
$output .= "<dt class='$class'>$f_title</dt>\n";
|
| 280 |
$output .= "<dd class='$class'>{$node->$node_field}</dd>\n";
|
| 281 |
}
|
| 282 |
$output .= "</dl>\n";
|
| 283 |
|
| 284 |
$output .= "</div>";
|
| 285 |
return $output;
|
| 286 |
|
| 287 |
}
|
| 288 |
|
| 289 |
|
| 290 |
/**
|
| 291 |
* Default theme for a contact using the specified profile id
|
| 292 |
*
|
| 293 |
*/
|
| 294 |
function theme_crm_profile_cid($pid, $cid){
|
| 295 |
$meta_data = civinode_get_profile_metadata($pid, 'view');
|
| 296 |
if (!$meta_data)
|
| 297 |
return ""; //nothing to display.
|
| 298 |
|
| 299 |
//Pull data for our cid
|
| 300 |
$contact = (object)civinode_util_load_cdata($cid, $pid);
|
| 301 |
if (isset($contact->display_name))
|
| 302 |
$contact->title = $contact->display_name;
|
| 303 |
|
| 304 |
$classes = "crm-profile crm-profile-$pid";
|
| 305 |
$output = "<div class='$classes'>\n";
|
| 306 |
$title = civinode_get_profile_title($pid);
|
| 307 |
//TO DO: do we need to filter the text here??
|
| 308 |
$output .= "<h2 class='crm-profile-title'>$title</h2>";
|
| 309 |
//Get the fields and render them
|
| 310 |
$field_list = civinode_get_profile_field_list($pid, 'view');
|
| 311 |
$output .= "<dl>\n";
|
| 312 |
foreach ($field_list as $node_field => $field) {
|
| 313 |
$field_desc = civinode_get_field_info($pid, $field, 'view');
|
| 314 |
//TO DO:
|
| 315 |
//For now, if a field has no data, do not print it. This
|
| 316 |
//may need to be an argument to this function, however.
|
| 317 |
if (!isset($contact->$node_field) or !$contact->$node_field)
|
| 318 |
continue;
|
| 319 |
$f_title = $field_desc['title'];
|
| 320 |
//Work around for CRM-847
|
| 321 |
if (!$title)
|
| 322 |
$f_title = $field;
|
| 323 |
$class = "crm-profile-item crm-profile-item-$node_field";
|
| 324 |
$output .= "<dt class='$class'>$f_title</dt>\n";
|
| 325 |
$output .= "<dd class='$class'>{$contact->$node_field}</dd>\n";
|
| 326 |
}
|
| 327 |
$output .= "</dl>\n";
|
| 328 |
|
| 329 |
$output .= "</div>";
|
| 330 |
return $output;
|
| 331 |
|
| 332 |
}
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
/**
|
| 337 |
* Default theme for a contact field.
|
| 338 |
*
|
| 339 |
*/
|
| 340 |
function theme_crm_contact_field($fld_name, $content, $pid = 0){
|
| 341 |
global $user;
|
| 342 |
$output = "";
|
| 343 |
$profile = civinode_get_default_profile_id($user->uid);
|
| 344 |
$fld_def = civinode_get_field_info($profile, $fld_name);
|
| 345 |
if($fld_def){
|
| 346 |
|
| 347 |
$title = $fld_def['title']; //Hopefully L10n occurs in CRM
|
| 348 |
//Work around for CRM-847
|
| 349 |
if (!$title)
|
| 350 |
$title = $fld_name;
|
| 351 |
}
|
| 352 |
else
|
| 353 |
$title = $fld_name;
|
| 354 |
$munged_content = htmlspecialchars($content, ENT_COMPAT, "UTF-8");
|
| 355 |
|
| 356 |
//For now, let's just do table rows...
|
| 357 |
$output .= "<tr class='crm-contact-row'>\n<th>$title</th>\n<td>$munged_content</td>\n</tr>\n";
|
| 358 |
return $output;
|
| 359 |
}
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
?>
|