Location: PHPKode > projects > Teampopor > teampopor-0.5/teampopor/modules/group/group.pages.inc
<?php

// page callback: network/%network/group/%group/%
function network_group_page($template, $network, $group) {
  if ($group->is_public || $group->joined) {
    return theme($template, $network, $group);
  }
  else {
    return '<ul class="actionlist">'
        . '<li>'
          . '<a class="action btn-action" href="' . url('network/' . $network->nid . '/group/' . $group->gid . '/join') . '">'
            . '<span>' . t('Join Group') . '</span>'
          . '</a>'
        . '</li>'
      .'</ul>';
  }
}

// page callback: network/%network/group/%group/join
function network_group_join($network, $group) {
  if ($group->is_moderated) {
    group_request_save(NULL, array('gid' => $group->gid));
    set_message(t('Your request to join the %group has been sent.', array('%group' => $group->name)), 'success');
  }
  else {
    group_member_save(NULL, array('gid' => $group->gid));
    set_message(t('Welcome to the %group.', array('%group' => $group->name)), 'success');
  }

  redirect('network/' . $group->nid . '/group/' . $group->gid);
}

// page callback: network/%network/group/%group/leave
function network_group_leave($network, $group) {
  global $user;
  if ($group_member = group_member_load(array('gid' => $group->gid, 'uid' => $user->uid))) {
    group_member_delete($group_member);
  }
  redirect('network/' . $group->nid . '/groups');
}

// page callback: network/%network/group/%group/js/%
function network_group_js($network, $group, $action) {
  switch ($action) {
    case 'add-members':
      return json(get_form('group_add_members_form', $network, $group));
  }
}

/**
 * create_group_form
 */

function create_group_form($form_state, $network = NULL) {
  $form['#attributes']['class'] = 'standard-form stacked';
  $form['network'] = array('#type' => 'value', '#value' => $network);

  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Group Name'),
    '#required' => TRUE,
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
  );
  $form['is_public'] = array(
    '#type' => 'radios',
    '#title' => t('Privacy Settings'),
    '#options' => array(
      1 => '<strong>' . t('Public') . '</strong> - <small>' . t('Anyone in the @network network can view content and participate.', array('@network' => $network->name)) . '</small>',
      0 => '<strong>' . t('Private') . '</strong> - <small>' . t('Membership is by approval/invitation only and only members can view content and participate.') . '</small>',
    ),
    '#default_value' => 1,
    '#description' => t('Once created, private groups cannot be made Public'),
  );
  $form['is_moderated'] = array(
    '#type' => 'checkbox',
    '#title' => t('Require new members to be approved by me.'),
  );
  $form['show_in_directory'] = array(
    '#type' => 'checkbox',
    '#title' => t('List in Group Directory.'),
    '#default_value' => 1,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Create Group'),
    '#attributes' => array('class' => 'btn-primary'),
  );

  return $form;
}

function create_group_form_submit($form, &$form_state) {
  $group = group_save(NULL, array(
    'nid' => $form_state['values']['network']->nid,
    'name' => $form_state['values']['name'],
    'description' => $form_state['values']['description'],
    'is_public' => $form_state['values']['is_public'],
    'is_moderated' => $form_state['values']['is_moderated'],
    'show_in_directory' => $form_state['values']['show_in_directory'],
  ));
  $form_state['redirect'] = 'network/' . $group->nid . '/group/' . $group->gid;
}

/**
 * network_group_manage_settings_form
 */
function network_group_manage_settings_form($form_state, $network, $group) {
  $form['#attributes']['class'] = 'standard-form stacked';
  $form['network'] = array('#type' => 'value', '#value' => $network);
  $form['group'] = array('#type' => 'value', '#value' => $group);

  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Group Name'),
    '#required' => TRUE,
    '#default_value' => $group->name,
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#default_value' => $group->description,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#attributes' => array('class' => 'btn-primary'),
  );

  return $form;
}

function network_group_manage_settings_form_submit($form, &$form_state) {
  group_save($form_state['values']['group'], array(
    'name' => $form_state['values']['name'],
    'description' => $form_state['values']['description'],
  ));
  set_message(t('Group settings has been saved.'));
}

/**
 * group_add_members_form
 */
function group_add_members_form($form_state, $network, $group) {
  $form['#attributes']['class'] = 'standard-form stacked';
  $form['network'] = array('#type' => 'value', '#value' => $network);
  $form['group'] = array('#type' => 'value', '#value' => $group);

  $form['emailRecipients'] = array(
    '#type' => 'textarea',
    '#required' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => '+ ' . t('Add'),
    '#attributes' => array('class' => 'btn-primary'),
  );

  return $form;
}

function group_add_members_form_submit($form, &$form_state) {
}
Return current item: Teampopor