123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- <?php
- /**
- * @file
- * Manifest module page callbacks and forms.
- */
- /**
- * Form builder function for manifest admin form.
- */
- function manifest_admin_list() {
- $output = array();
- $manifests = manifest_load_multiple();
- if (!$manifests) {
- $output['no-manifests'] = t('There are currently no manifests configured.');
- }
- else {
- $rows = array();
- foreach ($manifests as $manifest) {
- $rows[] = array(
- array(
- 'data' => '<h3>' . manifest_title($manifest) . '</h3><p>' . check_plain($manifest->settings['description']) . '</p>',
- 'class' => 'manifest-name',
- ),
- array(
- 'data' =>
- l(t('Roles'), 'admin/people/manifest/' . $manifest->name . '/role')
- . ' | ' .
- l(t('IP addresses'), 'admin/people/manifest/' . $manifest->name . '/ip')
- . ' | ' .
- l(t('Edit'), 'admin/people/manifest/' . $manifest->name . '/edit')
- . ' | ' .
- l(t('Delete'), 'admin/people/manifest/' . $manifest->name . '/delete'),
- 'class' => 'manifest-ops',
- 'align' => 'right',
- ),
- );
- }
- $output['manifest-table'] = array(
- '#theme' => 'table',
- '#rows' => $rows,
- '#attributes' => array(
- 'class' => 'manifest-table',
- ),
- );
- }
- return $output;
- }
- /**
- * Admin manifest add/edit page.
- */
- function manifest_admin_edit($form, $form_state, $manifest = NULL) {
- $form_state['storage']['manifest'] = $manifest;
- $form['#tree'] = TRUE;
- $machine_name = '';
- if (!isset($manifest->name)) {
- $form['new'] = array(
- '#type' => 'value',
- '#value' => TRUE,
- );
- $form['name'] = array(
- '#type' => 'textfield',
- '#title' => t('Machine name'),
- '#default_value' => '',
- '#maxlength' => 32,
- '#size' => 32,
- '#required' => TRUE,
- '#description' => t('The machine-readable name of this manifest. This name must contain only lowercase letters, numbers, and underscores. This name must be unique.'),
- );
- }
- else {
- $form['name'] = array(
- '#type' => 'value',
- '#value' => $manifest->name,
- );
- $machine_name = ' ' . t('(machine name: %name)', array('%name' => $manifest->name));
- }
- $form['settings']['title'] = array(
- '#type' => 'textfield',
- '#title' => t('Display title'),
- '#default_value' => isset($manifest->settings['title']) ? $manifest->settings['title'] : '',
- '#maxlength' => 32,
- '#size' => 32,
- '#description' => t('The human-readable title of this manifest.') . $machine_name,
- );
- $form['settings']['description'] = array(
- '#type' => 'textfield',
- '#title' => t('Description'),
- '#default_value' => isset($manifest->settings['description']) ? $manifest->settings['description'] : '',
- '#description' => t('This will appear on the manifest administration page.'),
- );
- $form['settings']['user'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Add user accounts'),
- '#default_value' => isset($manifest->settings['user']) ? $manifest->settings['user'] : array('profile', 'operations'),
- '#options' => array(
- 'profile' => t('Through the user profile page'),
- 'operations' => t('Through the user update options'),
- ),
- '#description' => t('How to add user accounts to this manifest.'),
- );
- $form['config'] = module_invoke_all('manifest_config', 'form', $manifest);
- $form['config']['#tree'] = FALSE;
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save manifest'),
- );
- if ($manifest) {
- $form['submit']['#suffix'] = l(t('Delete'), 'admin/people/manifest/' . $manifest->name . '/delete');
- }
- else {
- $form['submit']['#suffix'] = l(t('Cancel'), 'admin/people/manifest');
- }
- return $form;
- }
- /**
- * Validate function for admin manifest add/edit page.
- */
- function manifest_admin_edit_validate($form, &$form_state) {
- $values = &$form_state['values'];
- if ($values['new'] == TRUE) {
- $manifest_name = trim($values['name']);
- if (manifest_load($manifest_name) !== FALSE) {
- form_set_error('name', t('The machine-readable name %manifest is already taken.', array('%manifest' => $manifest_name)));
- }
- if (!preg_match('!^[a-z0-9_]+$!', $manifest_name)) {
- form_set_error('name', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
- }
- }
- }
- /**
- * Submit function for admin manifest add/edit page.
- */
- function manifest_admin_edit_submit($form, &$form_state) {
- $values = &$form_state['values'];
- $manifest = (object)array(
- 'name' => trim($values['name']),
- 'settings' => $values['settings'],
- );
- $fields = module_invoke_all('manifest_config', 'fields', $manifest);
- manifest_save($manifest);
- manifest_config_delete($manifest->name);
- if (!empty($fields)) {
- foreach ($fields as $field) {
- manifest_config_save($manifest->name, $field, $values[$field]);
- }
- }
- drupal_set_message(t("The manifest was saved."));
- drupal_goto("admin/people/manifest");
- }
- /**
- * Admin finder delete page.
- */
- function manifest_admin_delete($form, $form_state, $manifest) {
- $form['#tree'] = TRUE;
- $form['name'] = array(
- '#type' => 'value',
- '#value' => $manifest->name,
- );
- return confirm_form($form,
- t('Are you sure you want to delete the %manifest manifest?', array('%manifest' => manifest_title($manifest))),
- $_GET['destination'] ? $_GET['destination'] : 'admin/people/manifest',
- t('This action cannot be undone.'),
- t('Delete'), t('Cancel'));
- }
- /**
- * Submit function for admin manifest delete page.
- */
- function manifest_admin_delete_submit($form, &$form_state) {
- $manifest_name = &$form_state['values']['name'];
- manifest_delete($manifest_name);
- drupal_set_message(t("The manifest was deleted."));
- drupal_goto("admin/people/manifest");
- }
- /**
- * Admin manifest role page.
- */
- function manifest_admin_role($form, $form_state, $manifest = NULL) {
- drupal_set_title(t('!manifest roles', array('!manifest' => manifest_title($manifest))));
- $role_entries = manifest_role_load(NULL, $manifest->name);
- $roles = array();
- if (is_array($role_entries)) {
- foreach ($role_entries as $role_entry) {
- $roles[$role_entry->rid] = $role_entry->rid;
- }
- }
- $form['roles'] = array(
- '#type' => 'checkboxes',
- '#title' => t('User roles'),
- '#default_value' => $roles,
- '#options' => user_roles(),
- '#description' => t('Users in these roles will be added to this Manifest by default.'),
- );
- $form['manifest'] = array(
- '#type' => 'value',
- '#value' => $manifest->name,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save roles'),
- '#suffix' => l(t('Cancel'), 'admin/people/manifest'),
- );
- return $form;
- }
- /**
- * Submit function for admin manifest role page.
- */
- function manifest_admin_role_submit($form, &$form_state) {
- $values = &$form_state['values'];
- $roles = $values['roles'];
- foreach ($roles as $key => $value) {
- if ($value) {
- manifest_role_save($key, $values['manifest']);
- }
- else {
- manifest_role_delete($key, $values['manifest']);
- }
- }
- drupal_set_message(t("The manifest roles were saved."));
- drupal_goto("admin/people/manifest");
- }
- /**
- * Admin manifest ip page.
- */
- function manifest_admin_ip($form, $form_state, $manifest = NULL) {
- drupal_set_title(t('!manifest IP addresses', array('!manifest' => manifest_title($manifest))));
- $ip_entries = manifest_ip_load(NULL, NULL, $manifest->name);
- $rows = array();
- $ips = '';
- if (is_array($ip_entries)) {
- foreach ($ip_entries as $ip_entry) {
- $ip = $ip_entry->ip1;
- if ($ip_entry->ip2 && $ip_entry->ip2 != $ip_entry->ip1) {
- $ip .= ' - ' . $ip_entry->ip2;
- }
- $rows[] = array(
- $ip,
- l(t('Delete'), 'admin/people/manifest/' . $manifest->name . '/ip/' . $ip . '/delete'),
- );
- }
- $ips .= theme('table', array(t('IP addresses'), t('Operations')), $rows);
- }
- $form['ips'] = array(
- '#value' => $ips,
- );
- $form['ip1'] = array(
- '#title' => t('IP address, or IP range start'),
- '#type' => 'textfield',
- '#size' => 15,
- '#maxlength' => 15,
- );
- $form['ip2'] = array(
- '#title' => t('IP range end'),
- '#type' => 'textfield',
- '#size' => 15,
- '#maxlength' => 15,
- '#description' => t('Leave blank if specifying a single IP address.'),
- );
- $form['manifest'] = array(
- '#type' => 'value',
- '#value' => $manifest->name,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save IP addresses'),
- '#suffix' => l(t('Cancel'), 'admin/people/manifest'),
- );
- return $form;
- }
- /**
- * Submit function for admin manifest ip page.
- */
- function manifest_admin_ip_submit($form, &$form_state) {
- $values = &$form_state['values'];
- $ip1 = $values['ip1'];
- $ip2 = $values['ip2'];
- manifest_ip_save($ip1, $ip2, $values['manifest']);
- drupal_set_message(t("The manifest IP addresses were saved."));
- drupal_goto('admin/people/manifest/' . $values['manifest'] . '/ip');
- }
- /**
- * Admin finder delete page.
- */
- function manifest_admin_ip_delete($form, $form_state, $manifest, $ip) {
- $form['#tree'] = TRUE;
- $form['name'] = array(
- '#type' => 'value',
- '#value' => $manifest->name,
- );
- $form['ip'] = array(
- '#type' => 'value',
- '#value' => $ip,
- );
- return confirm_form($form,
- t('Are you sure you want to delete %ip from the %manifest manifest?', array('%ip' => $ip, '%manifest' => manifest_title($manifest))),
- $_GET['destination'] ? $_GET['destination'] : 'admin/people/manifest',
- t('This action cannot be undone.'),
- t('Delete'), t('Cancel'));
- }
- /**
- * Submit function for admin manifest delete page.
- */
- function manifest_admin_ip_delete_submit($form, &$form_state) {
- $manifest_name = &$form_state['values']['name'];
- $manifest_ip = &$form_state['values']['ip'];
- $ips = explode(' - ', $manifest_ip);
- manifest_ip_delete($ips[0], $ips[1], $manifest_name);
- drupal_set_message(t("The IP address was deleted."));
- drupal_goto('admin/people/manifest/' . $manifest_name . '/ip');
- }
|