| 1 |
<?php |
<?php |
| 2 |
// $Id: volunteer.module,v 1.56 2006/05/12 21:37:23 killes Exp $ |
// $Id: volunteer.module,v 1.57 2006/05/12 22:22:26 killes Exp $ |
| 3 |
|
|
| 4 |
|
|
| 5 |
/** |
/** |
| 39 |
* Allows the admin to set different defaults & settings for the module on the module config page |
* Allows the admin to set different defaults & settings for the module on the module config page |
| 40 |
*/ |
*/ |
| 41 |
function volunteer_settings() { |
function volunteer_settings() { |
| 42 |
$all_volunteer_coordinators = array(); |
$all_volunteer_coordinators = _volunteer_get_volunteer_coordinators(); |
|
// TODO: Check if this still works on 4.7. Probably doesn't since |
|
|
// users_roles does not have entries for "authenticated user" |
|
|
// anymore |
|
|
$result = db_query("SELECT u.uid, u.name FROM {users} u INNER JOIN {users_roles} r ON u.uid = r.uid LEFT JOIN {permission} p ON r.rid = p.rid WHERE p.perm LIKE '%s' OR u.uid = 1", '%volunteer coordinate%'); |
|
|
while ($user = db_fetch_object($result)) { |
|
|
$all_volunteer_coordinators[$user->uid] = $user->name; |
|
|
} |
|
| 43 |
$variables = _volunteer_message_vars(); |
$variables = _volunteer_message_vars(); |
| 44 |
$wildcards = implode(', ',array_keys($variables)); |
$wildcards = implode(', ',array_keys($variables)); |
| 45 |
|
|
|
//end set all_volunteer_coordinators |
|
| 46 |
$form['default_settings'] = array( |
$form['default_settings'] = array( |
| 47 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 48 |
'#title' => t('Default Settings'), |
'#title' => t('Default Settings'), |
| 235 |
$form['email_settings']['wildcards'] = array( |
$form['email_settings']['wildcards'] = array( |
| 236 |
'#value' => '<p>'. t("FYI - The following 'Wildcards' can be used in messages to insert live data about the volunteer event: $wildcards") .'</p>', |
'#value' => '<p>'. t("FYI - The following 'Wildcards' can be used in messages to insert live data about the volunteer event: $wildcards") .'</p>', |
| 237 |
); |
); |
| 238 |
|
|
| 239 |
return $form; |
return $form; |
| 240 |
} |
} |
| 241 |
|
|
| 242 |
/** |
/** |
| 243 |
* Provides the volunteer permission information for the drupal system. |
* Provides the volunteer permission information for the drupal system. |
| 244 |
* |
* |
| 245 |
|
* @ingroup volunteer_core |
| 246 |
*/ |
*/ |
| 247 |
function volunteer_perm() { |
function volunteer_perm() { |
| 248 |
return array('volunteer coordinate'); |
return array('volunteer coordinate'); |
| 288 |
|
|
| 289 |
/** |
/** |
| 290 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 291 |
|
* |
| 292 |
|
* @ingroup volunteer_core |
| 293 |
*/ |
*/ |
| 294 |
function volunteer_menu($may_cache) { |
function volunteer_menu($may_cache) { |
| 295 |
$items = array(); |
$items = array(); |
| 304 |
'callback' => 'volunteer_volunteer', |
'callback' => 'volunteer_volunteer', |
| 305 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 306 |
'access' => user_access('access content')); |
'access' => user_access('access content')); |
| 307 |
|
|
| 308 |
$items[] = array('path' => 'volunteer/rating', 'title' => t('volunteer rate'), |
$items[] = array('path' => 'volunteer/rating', 'title' => t('volunteer rate'), |
| 309 |
'callback' => 'volunteer_rate', |
'callback' => 'volunteer_rate', |
| 310 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 330 |
* Implementation of hook_civicrm_post |
* Implementation of hook_civicrm_post |
| 331 |
* Delete contacts from volunteer dataset that get deleted in CiviCRM |
* Delete contacts from volunteer dataset that get deleted in CiviCRM |
| 332 |
*/ |
*/ |
| 333 |
function volunteer_civicrm_post( $op, $objectName, $objectId, $objectRef ) { |
function volunteer_civicrm_post( $op, $objectName, $objectId, $objectRef ) { |
| 334 |
if ($objectName == 'Individual') { |
if ($objectName == 'Individual') { |
| 335 |
switch ($op) { |
switch ($op) { |
| 336 |
case 'delete': |
case 'delete': |
| 373 |
case '5': |
case '5': |
| 374 |
$stage = l(t('Follow Up'), "volunteer/question_coordinator/$data->cid/$data->nid"); |
$stage = l(t('Follow Up'), "volunteer/question_coordinator/$data->cid/$data->nid"); |
| 375 |
} |
} |
| 376 |
$rows[] = array($data->cid, |
$rows[] = array($data->cid, |
| 377 |
l($data->title, "node/$data->nid", array('title' => t('view this event'))), |
l($data->title, "node/$data->nid", array('title' => t('view this event'))), |
| 378 |
format_date($data->timestamp, 'medium'), |
format_date($data->timestamp, 'medium'), |
| 379 |
$stage |
$stage |
| 405 |
function volunteer_question_coordinator($cid, $nid) { |
function volunteer_question_coordinator($cid, $nid) { |
| 406 |
civicrm_initialize(TRUE); |
civicrm_initialize(TRUE); |
| 407 |
|
|
| 408 |
if($_POST['op']) { |
if(isset($_POST['op'])) { |
| 409 |
switch ($_POST['op']) { |
switch ($_POST['op']) { |
| 410 |
case t('Approve'): |
case t('Approve'): |
| 411 |
$output = volunteer_approve_volunteer($cid, $nid); |
$form = volunteer_approve_volunteer($cid, $nid); |
| 412 |
break; |
break; |
| 413 |
case t('Deny'): |
case t('Deny'): |
| 414 |
volunteer_deny_volunteer($cid, $nid); |
volunteer_deny_volunteer($cid, $nid); |
| 415 |
drupal_set_message(t('Volunteer denied')); |
drupal_set_message(t('Volunteer denied')); |
| 422 |
volunteer_approve_volunteer($cid, $nid); |
volunteer_approve_volunteer($cid, $nid); |
| 423 |
break; |
break; |
| 424 |
} |
} |
| 425 |
if(!$output) { |
if(!isset($form)) { |
| 426 |
drupal_goto('node/'.$nid.'/volunteer'); |
drupal_goto('node/'.$nid.'/volunteer'); |
| 427 |
} |
} |
| 428 |
} |
} |
| 431 |
$form['average'] = array( |
$form['average'] = array( |
| 432 |
'#type' => 'item', |
'#type' => 'item', |
| 433 |
'#title' => t('Avg. Rating'), |
'#title' => t('Avg. Rating'), |
| 434 |
'#default_value' => l($rating['average'], "volunteer/rating/$cid/$node->nid"), |
'#default_value' => l($rating['average'], "volunteer/rating/$cid/$nid"), |
| 435 |
); |
); |
| 436 |
$form_title = variable_get('volunteer_form', ''); |
$form_title = variable_get('volunteer_form', ''); |
| 437 |
db_set_active('civicrm'); |
db_set_active('civicrm'); |
| 438 |
$title = crm_uf_get_profile_title($form_title); |
$title = crm_uf_get_profile_title($form_title); |
| 439 |
$output .= crm_uf_get_profile_html( $cid, $title, CRM_CORE_ACTION_VIEW, false, true ); |
$form['profile'] = array( |
| 440 |
|
'#value' => crm_uf_get_profile_html( $cid, $title, CRM_CORE_ACTION_VIEW, false, true ), |
| 441 |
|
); |
| 442 |
db_set_active(); |
db_set_active(); |
| 443 |
$form['approve'] = array( |
$form['approve'] = array( |
| 444 |
'#type' => 'submit', |
'#type' => 'submit', |
| 457 |
'#value' => t('Cancel'), |
'#value' => t('Cancel'), |
| 458 |
); |
); |
| 459 |
} |
} |
|
// TODO: rework this function, $form isn't defined in all cases. |
|
| 460 |
drupal_set_title(t('Volunteer Status')); |
drupal_set_title(t('Volunteer Status')); |
| 461 |
return drupal_get_form('volunteer_question_coordinator', $form); |
return drupal_get_form('volunteer_question_coordinator', $form); |
| 462 |
} |
} |
| 479 |
function volunteer_volunteer($nid, $wait_list = NULL) { |
function volunteer_volunteer($nid, $wait_list = NULL) { |
| 480 |
global $user; |
global $user; |
| 481 |
// TODO: convert to validate/submit model for better readability |
// TODO: convert to validate/submit model for better readability |
| 482 |
$edit = $_POST['edit']; |
// webchick: I tried to convert this, but because the entire form, including the submit button, |
| 483 |
$op = $_POST['op']; |
// is generated from civicrm, I can't seem to get any Drupalish FAPI stuff to work with it... |
| 484 |
|
$edit = isset($_POST['edit']) ? $_POST['edit'] : array(); |
| 485 |
|
$op = isset($_POST['op']) ? $_POST['op'] : array(); |
| 486 |
|
|
| 487 |
civicrm_initialize(TRUE); |
civicrm_initialize(TRUE); |
| 488 |
// Not a Drupal form, so we need to let CRM have a crack |
// Not a Drupal form, so we need to let CRM have a crack |
| 494 |
if ($crm_params['contact_id']) { |
if ($crm_params['contact_id']) { |
| 495 |
//CRM knows about this user. Is he/she signed up? |
//CRM knows about this user. Is he/she signed up? |
| 496 |
$contact_id = $crm_params['contact_id']; |
$contact_id = $crm_params['contact_id']; |
| 497 |
|
// NOTE: I would put this into a #pre_render function, but we're not allowed |
| 498 |
|
// to pass in additional arguments ($contact_id) so I can't. |
| 499 |
if (volunteer_has_user_volunteered($nid, $contact_id)) { |
if (volunteer_has_user_volunteered($nid, $contact_id)) { |
| 500 |
drupal_set_message(t('You have already signed up for this event.'), 'error'); |
drupal_set_message(t('You have already signed up for this event.'), 'error'); |
| 501 |
drupal_goto('node/'. $nid); |
drupal_goto('node/'. $nid); |
| 575 |
$userID = $user->uid ? crm_uf_get_match_id( $user->uid ) : NULL; |
$userID = $user->uid ? crm_uf_get_match_id( $user->uid ) : NULL; |
| 576 |
$action = $userID ? CRM_CORE_ACTION_UPDATE : CRM_CORE_ACTION_ADD; |
$action = $userID ? CRM_CORE_ACTION_UPDATE : CRM_CORE_ACTION_ADD; |
| 577 |
|
|
| 578 |
//The following call not only generates HTML, it also |
//The following call not only generates HTML, it also |
| 579 |
//interacts with the CRM data store: |
//interacts with the CRM data store: |
| 580 |
$crm_form = crm_uf_get_profile_html( $userID, $title, $action, $register, $reset ); |
$crm_form = crm_uf_get_profile_html( $userID, $title, $action, $register, $reset ); |
| 581 |
db_set_active(); |
db_set_active(); |
| 584 |
$email = $user->mail ? $user->mail : _volunteer_get_email(); |
$email = $user->mail ? $user->mail : _volunteer_get_email(); |
| 585 |
$params = array('email' => $email); |
$params = array('email' => $email); |
| 586 |
//$contact = crm_get_contact($params); |
//$contact = crm_get_contact($params); |
| 587 |
db_set_active('civicrm'); |
db_set_active('civicrm'); |
| 588 |
list($values, $options) = crm_contact_search($params); |
list($values, $options) = crm_contact_search($params); |
| 589 |
db_set_active(); |
db_set_active(); |
| 590 |
} |
} |
| 591 |
elseif ($userID) { |
elseif ($userID) { |
| 595 |
list($values, $options) = crm_contact_search($params); |
list($values, $options) = crm_contact_search($params); |
| 596 |
db_set_active(); |
db_set_active(); |
| 597 |
} |
} |
| 598 |
|
|
| 599 |
if ($values && $op == $submit_value) { |
if ($values && $op == $submit_value) { |
| 600 |
//We've already done what was needed with CRM |
//We've already done what was needed with CRM |
| 601 |
//(?? what if there was an error), so do our business |
//(?? what if there was an error), so do our business |
| 602 |
//with the Drupal side code: |
//with the Drupal side code: |
| 603 |
$param_list = array_values($values); |
$param_list = array_values($values); |
| 604 |
$edit = $param_list[0]; |
$edit = $param_list[0]; |
| 605 |
//Do we need HTML in this case? |
//Do we need HTML in this case? |
| 606 |
//I think not. |
//I think not. |
| 607 |
//Redirects should go here, most likely |
//Redirects should go here, most likely |
| 639 |
/********************************/ |
/********************************/ |
| 640 |
|
|
| 641 |
function volunteer_rate($cid, $nid = 0) { |
function volunteer_rate($cid, $nid = 0) { |
|
// TODO: convert to validate/submit model for better radability |
|
| 642 |
civicrm_initialize(TRUE); |
civicrm_initialize(TRUE); |
| 643 |
|
|
| 644 |
db_set_active('civicrm'); |
db_set_active('civicrm'); |
| 645 |
$contact = crm_get_contact(array('contact_id' => $cid)); |
$contact = crm_get_contact(array('contact_id' => $cid)); |
| 646 |
db_set_active(); |
db_set_active(); |
| 647 |
$mail = $contact->location[1]->email[1]->email; |
$mail = $contact->location[1]->email[1]->email; |
| 648 |
if($_POST['op'] != 'Submit') { |
if ($nid) { |
| 649 |
if ($nid) { |
// rate a specific event |
| 650 |
// rate a specific event |
$form['#method'] = 'post'; |
| 651 |
$event = db_fetch_object(db_query('SELECT title FROM {node} WHERE nid = %d', $nid)); |
$form['#action'] = url("volunteer/rating/$cid/$nid"); |
| 652 |
$volunteer_contact_event = db_fetch_object(db_query('SELECT * FROM {volunteer_contact_event} WHERE cid = %d AND nid = %d', $cid, $nid)); |
$form['#submit']['volunteer_rate_submit'] = array($cid, $nid); |
|
$form = t('Rate') .' '. "<a href=\"mailto:$mail\">$mail</a>". '\'s performance at: <b>' . $event->title . '</b>.'; |
|
|
$rating_list = array(1 => 1, |
|
|
2 => 2, |
|
|
3 => 3, |
|
|
4 => 4, |
|
|
5 => 5); |
|
|
$form['#method'] = 'post'; |
|
|
$form['#action'] = url("volunteer/rating/$cid/$nid"); |
|
|
$form[$event->title] = array( |
|
|
'#type' => 'fieldset', |
|
|
'#title' => $event->title, |
|
|
); |
|
|
$form[$event->title]['rating'] = array( |
|
|
'#type' => 'select', |
|
|
'#title' => t('Rating'), |
|
|
'#default_value' => $volunteer_contact_event->rating, |
|
|
'#options' => $rating_list, |
|
|
'#description' => '1 being the worst and 5 being the best.', |
|
|
); |
|
|
$form[$event->title]['comments'] = array( |
|
|
'#type' => 'textarea', |
|
|
'#title' => t('Comments'), |
|
|
'#default_value' => $volunteer_contact_event->comments, |
|
|
'#cols' => 70, |
|
|
'#rows' => 5, |
|
|
'#description' => 'Leave comment specific to this event here', |
|
|
); |
|
|
$form[$event->title]['submit'] = array( |
|
|
'#type' => 'submit', |
|
|
'#value' => t('Submit'), |
|
|
); |
|
|
} |
|
|
// output view of past ratings |
|
|
$data = volunteer_get_rating($cid); |
|
|
if (count($data['events'])) { |
|
|
$header = array('Event', 'Rating', 'Coordinator', 'Comments'); |
|
|
$form['other_events'] = array( |
|
|
'#type' => 'fieldset', |
|
|
'#title' => t('Other Events which %name has volunteered for:', array('%name'=>$mail)), |
|
|
); |
|
|
$form['other_events']['events'] = array( |
|
|
'#value' => theme('table', $header, $data['events']), |
|
|
); |
|
|
} |
|
| 653 |
|
|
| 654 |
return drupal_get_form('volunteer_rate', $form); |
$event = db_fetch_object(db_query('SELECT title FROM {node} WHERE nid = %d', $nid)); |
| 655 |
|
$volunteer_contact_event = db_fetch_object(db_query('SELECT * FROM {volunteer_contact_event} WHERE cid = %d AND nid = %d', $cid, $nid)); |
| 656 |
|
$rating_list = array(1 => 1, |
| 657 |
|
2 => 2, |
| 658 |
|
3 => 3, |
| 659 |
|
4 => 4, |
| 660 |
|
5 => 5); |
| 661 |
|
$form['rate'] = array( |
| 662 |
|
'#value' => t('Rate') .' '. "<a href=\"mailto:$mail\">$mail</a>". '\'s performance at: <b>' . $event->title . '</b>.', |
| 663 |
|
); |
| 664 |
|
$form[$event->title] = array( |
| 665 |
|
'#type' => 'fieldset', |
| 666 |
|
'#title' => $event->title, |
| 667 |
|
); |
| 668 |
|
$form[$event->title]['rating'] = array( |
| 669 |
|
'#type' => 'select', |
| 670 |
|
'#title' => t('Rating'), |
| 671 |
|
'#default_value' => $volunteer_contact_event->rating, |
| 672 |
|
'#options' => $rating_list, |
| 673 |
|
'#description' => '1 being the worst and 5 being the best.', |
| 674 |
|
); |
| 675 |
|
$form[$event->title]['comments'] = array( |
| 676 |
|
'#type' => 'textarea', |
| 677 |
|
'#title' => t('Comments'), |
| 678 |
|
'#default_value' => $volunteer_contact_event->comments, |
| 679 |
|
'#cols' => 70, |
| 680 |
|
'#rows' => 5, |
| 681 |
|
'#description' => 'Leave comment specific to this event here', |
| 682 |
|
); |
| 683 |
|
$form[$event->title]['submit'] = array( |
| 684 |
|
'#type' => 'submit', |
| 685 |
|
'#value' => t('Submit'), |
| 686 |
|
); |
| 687 |
} |
} |
| 688 |
else{ |
// output view of past ratings |
| 689 |
db_query("UPDATE {volunteer_contact_event} SET comments = '%s', rating = %d WHERE cid = %d AND nid = %d", $_POST['edit']['comments'], $_POST['edit']['rating'], $cid, $nid); |
$data = volunteer_get_rating($cid); |
| 690 |
drupal_set_message(t('Volunteer rating updated')); |
if (count($data['events'])) { |
| 691 |
drupal_goto("node/$nid/volunteer"); |
$header = array('Event', 'Rating', 'Coordinator', 'Comments'); |
| 692 |
|
$form['other_events'] = array( |
| 693 |
|
'#type' => 'fieldset', |
| 694 |
|
'#title' => t('Other Events which %name has volunteered for:', array('%name'=>$mail)), |
| 695 |
|
); |
| 696 |
|
$form['other_events']['events'] = array( |
| 697 |
|
'#value' => theme('table', $header, $data['events']), |
| 698 |
|
); |
| 699 |
} |
} |
| 700 |
|
|
| 701 |
|
return drupal_get_form('volunteer_rate', $form); |
| 702 |
|
} |
| 703 |
|
|
| 704 |
|
function volunteer_rate_submit($form_id, $form_values, $cid, $nid) { |
| 705 |
|
db_query("UPDATE {volunteer_contact_event} SET comments = '%s', rating = %d WHERE cid = %d AND nid = %d", $form_values['comments'], $form_values['rating'], $cid, $nid); |
| 706 |
|
drupal_set_message(t('Volunteer rating updated')); |
| 707 |
|
drupal_goto("node/$nid/volunteer"); |
| 708 |
} |
} |
| 709 |
|
|
| 710 |
|
|
| 711 |
/**********************************/ |
/**********************************/ |
| 712 |
// Needs to be rewritten to use the CiviCRM activity history. |
// Needs to be rewritten to use the CiviCRM activity history. |
| 713 |
function volunteer_get_rating($cid) { |
function volunteer_get_rating($cid) { |
| 719 |
while($rating = db_fetch_object($result)) { |
while($rating = db_fetch_object($result)) { |
| 720 |
$ratings = array(); |
$ratings = array(); |
| 721 |
$coordinator = db_fetch_object(db_query('SELECT u.name, u.uid FROM {volunteer} v INNER JOIN {users} u ON v.uid = u.uid WHERE nid = %d', $rating->nid)); |
$coordinator = db_fetch_object(db_query('SELECT u.name, u.uid FROM {volunteer} v INNER JOIN {users} u ON v.uid = u.uid WHERE nid = %d', $rating->nid)); |
| 722 |
$rating_total = $rating_total + $rating->rating; |
$rating_total = $rating_total + $rating->rating; |
| 723 |
$ratings[] = l(t($rating->title), "node/$rating->nid"); |
$ratings[] = l(t($rating->title), "node/$rating->nid"); |
| 724 |
$ratings[] = l(t($rating->rating ), "volunteer/rating/$cid/$rating->nid"); |
$ratings[] = l(t($rating->rating ), "volunteer/rating/$cid/$rating->nid"); |
| 725 |
$ratings[] = l(t($coordinator->name), "node/$coordinator->uid"); |
$ratings[] = l(t($coordinator->name), "node/$coordinator->uid"); |
| 850 |
function volunteer_get_volunteers($nid, $single = TRUE, $cid = NULL) { |
function volunteer_get_volunteers($nid, $single = TRUE, $cid = NULL) { |
| 851 |
$data = array(); |
$data = array(); |
| 852 |
|
|
| 853 |
if($single) { |
if ($single) { |
| 854 |
$result = db_query('SELECT * FROM {volunteer_contact_event} WHERE nid = %d AND cid = %d', $nid, $cid); |
$result = db_query('SELECT * FROM {volunteer_contact_event} WHERE nid = %d AND cid = %d', $nid, $cid); |
| 855 |
} |
} |
| 856 |
else{ |
else{ |
| 868 |
else { |
else { |
| 869 |
drupal_set_message(t('You need to <a href="%url">assign</a> a CiviCRM profile form for volunteer data collection.', array('%url' => url('admin/settings/volunteer'))), 'error'); |
drupal_set_message(t('You need to <a href="%url">assign</a> a CiviCRM profile form for volunteer data collection.', array('%url' => url('admin/settings/volunteer'))), 'error'); |
| 870 |
} |
} |
| 871 |
if(!$single) { |
if (!$single) { |
| 872 |
$header['stage'] = t('Stage'); |
$header['stage'] = t('Stage'); |
| 873 |
$header['rating'] = t('Avg. rating'); |
$header['rating'] = t('Avg. rating'); |
| 874 |
} |
} |
| 875 |
$data['header'] = $header; |
$data['header'] = $header; |
| 876 |
while($volunteer = db_fetch_object($result)) { |
while ($volunteer = db_fetch_object($result)) { |
| 877 |
$contact_data = array(); |
$contact_data = array(); |
| 878 |
db_set_active('civicrm'); |
db_set_active('civicrm'); |
| 879 |
$contact = crm_get_contact(array('contact_id' => $volunteer->cid)); |
$contact = crm_get_contact(array('contact_id' => $volunteer->cid)); |
| 880 |
db_set_active(); |
db_set_active(); |
| 881 |
if (strtolower(get_class($contact)) != 'crm_contact_bao_contact') { |
if (strtolower(get_class($contact)) != 'crm_contact_bao_contact') { |
| 882 |
continue; |
continue; |
| 883 |
} |
} |
| 884 |
|
// TODO @ killes: This does not populate 'first name', 'last name', etc. properly. |
| 885 |
|
// Can I refer to $contact['contact_type_object'] directly? |
| 886 |
$contact_data = volunteer_get_properties($contact, $header); |
$contact_data = volunteer_get_properties($contact, $header); |
| 887 |
if(!$single) { |
if (!$single) { |
| 888 |
switch ($volunteer->stage) { |
switch ($volunteer->stage) { |
| 889 |
case '1': |
case '1': |
| 890 |
$contact_data['stage'] = l(t('Wait List'), "volunteer/question_coordinator/$volunteer->cid/$nid"); |
$contact_data['stage'] = l(t('Wait List'), "volunteer/question_coordinator/$volunteer->cid/$nid"); |
| 995 |
} |
} |
| 996 |
break; |
break; |
| 997 |
case 'insert': |
case 'insert': |
| 998 |
if (variable_get('volunteer_event_default',1)) { |
if (variable_get('volunteer_event_default', 1)) { |
| 999 |
$coordinator = user_access('volunteer coordinate', $node->uid) ? $node->uid : variable_get('volunteer_coordinator', 1); |
$author = user_load(array('uid' => $node->uid)); |
| 1000 |
|
$coordinator = user_access('volunteer coordinate', $author) ? $node->uid : variable_get('volunteer_coordinator', 1); |
| 1001 |
$result = db_query("INSERT INTO {volunteer} (nid, wanted, uid) VALUES (%d, %d, %d)", $node->nid, variable_get('volunteer_wanted',2), $coordinator); |
$result = db_query("INSERT INTO {volunteer} (nid, wanted, uid) VALUES (%d, %d, %d)", $node->nid, variable_get('volunteer_wanted',2), $coordinator); |
| 1002 |
} |
} |
| 1003 |
break; |
break; |
| 1019 |
civicrm_initialize(TRUE); |
civicrm_initialize(TRUE); |
| 1020 |
|
|
| 1021 |
$nid = arg(1); |
$nid = arg(1); |
| 1022 |
$op = $_POST['op']; |
$op = isset($_POST['op']) ? $_POST['op'] : array(); |
| 1023 |
$edit = $_POST['edit']; |
$edit = isset($_POST['edit']) ? $_POST['edit'] : array(); |
| 1024 |
|
|
| 1025 |
if ($nid) { |
if ($nid) { |
| 1026 |
switch ($op) { |
switch ($op) { |
| 1048 |
} |
} |
| 1049 |
} |
} |
| 1050 |
//start set all_volunteer_coordinators |
//start set all_volunteer_coordinators |
| 1051 |
$all_volunteer_coordinators = array(); |
$all_volunteer_coordinators = _volunteer_get_volunteer_coordinators(); |
|
// TODO: Check if this still works on 4.7. Probably doesn't since |
|
|
// users_roles does not have entries for "authenticated user" |
|
|
// anymore |
|
|
$result = db_query("SELECT DISTINCT u.uid, u.name FROM {users} u INNER JOIN {users_roles} r ON u.uid = r.uid INNER JOIN {permission} p ON r.rid = p.rid WHERE p.perm LIKE '%volunteer coordinate%'"); |
|
|
while ($user = db_fetch_object($result)) { |
|
|
$all_volunteer_coordinators[$user->uid] = $user->name; |
|
|
} |
|
| 1052 |
if (volunteer_event_is_volunteer($node)) { |
if (volunteer_event_is_volunteer($node)) { |
| 1053 |
$form['volunteer_status'] = array( |
$form['volunteer_status'] = array( |
| 1054 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 1200 |
} |
} |
| 1201 |
|
|
| 1202 |
/** |
/** |
| 1203 |
|
* Retrieves an array of volunteer coordinators |
| 1204 |
|
* |
| 1205 |
|
* @return array |
| 1206 |
|
* Array in the form of uid => name, for example: |
| 1207 |
|
* array( |
| 1208 |
|
* 1 => 'admin', |
| 1209 |
|
* 5 => 'joe user', |
| 1210 |
|
* ); |
| 1211 |
|
*/ |
| 1212 |
|
function _volunteer_get_volunteer_coordinators() { |
| 1213 |
|
$all_volunteer_coordinators = array(); |
| 1214 |
|
|
| 1215 |
|
// Retrieve list of all users, then check to see which have 'volunteer coordinate' permissions |
| 1216 |
|
$result = db_query("SELECT u.uid FROM {users} u WHERE status = 1"); |
| 1217 |
|
while ($user = db_fetch_object($result)) { |
| 1218 |
|
$account = user_load(array('uid' => $user->uid)); |
| 1219 |
|
if (user_access('volunteer coordinate', $account)) { |
| 1220 |
|
$all_volunteer_coordinators[$account->uid] = $account->name; |
| 1221 |
|
} |
| 1222 |
|
} |
| 1223 |
|
|
| 1224 |
|
return $all_volunteer_coordinators; |
| 1225 |
|
} |
| 1226 |
|
|
| 1227 |
|
|
| 1228 |
|
/** |
| 1229 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 1230 |
*/ |
*/ |
| 1231 |
function volunteer_form_alter($form_id, &$form) { |
function volunteer_form_alter($form_id, &$form) { |
| 1260 |
} |
} |
| 1261 |
|
|
| 1262 |
// from php.net |
// from php.net |
| 1263 |
|
// Note: Originally this was split into two functions, however this caused |
| 1264 |
|
// infinite looping under PHP 5.1. I've now done a straight copy/paste from |
| 1265 |
|
// http://ca3.php.net/manual/en/function.array-walk-recursive.php#48181 |
| 1266 |
function _volunteer_array_mergedown() { |
function _volunteer_array_mergedown() { |
| 1267 |
|
global $outarray; |
| 1268 |
|
$outarray = array(); |
| 1269 |
|
function array_walk_recphp4(&$val,$key) { |
| 1270 |
global $outarray; |
global $outarray; |
| 1271 |
$outarray = array(); |
if (is_array($val)) array_walk($val,'array_walk_recphp4'); |
| 1272 |
$params = func_get_args(); |
else { |
| 1273 |
foreach ($params as $subarr) { |
$outarray[$key] = $val; |
| 1274 |
array_walk_recphp4($subarr, ''); |
} |
| 1275 |
} |
} |
| 1276 |
return $outarray; |
$params = func_get_args(); |
| 1277 |
} |
foreach ($params as $subarr) { |
| 1278 |
|
array_walk_recphp4($subarr, ''); |
| 1279 |
function array_walk_recphp4(&$val,$key) { |
} |
| 1280 |
global $outarray; |
return $outarray; |
|
$val = (array)$val; |
|
|
if (is_array($val)) array_walk($val,'array_walk_recphp4'); |
|
|
else { |
|
|
$outarray[$key] = $val; |
|
|
} |
|
| 1281 |
} |
} |