|
@@ -6,61 +6,248 @@
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * List destination rules.
|
|
|
+ * Form for editing an entire login destination at once.
|
|
|
+ *
|
|
|
+ * Shows list of all login destination.
|
|
|
*/
|
|
|
-function login_destination_overview() {
|
|
|
- $header = array(
|
|
|
- t('Destination'),
|
|
|
- t('Triggers'),
|
|
|
- t('Pages'),
|
|
|
- t('Roles'),
|
|
|
- array('data' => t('Operations'), 'colspan' => 2),
|
|
|
- );
|
|
|
- $rows = array();
|
|
|
+function login_destination_overview_form($form, &$form_state) {
|
|
|
|
|
|
// Get all login destination rules from the database.
|
|
|
$result = db_select('login_destination', 'l')
|
|
|
- ->fields('l', array('id', 'triggers', 'roles', 'pages_type', 'pages', 'destination'))
|
|
|
+ ->fields('l', array(
|
|
|
+ 'id',
|
|
|
+ 'triggers',
|
|
|
+ 'roles',
|
|
|
+ 'pages_type',
|
|
|
+ 'pages',
|
|
|
+ 'destination',
|
|
|
+ 'weight',
|
|
|
+ 'enabled',
|
|
|
+ )
|
|
|
+ )
|
|
|
->orderBy('weight')
|
|
|
->execute()
|
|
|
->fetchAll();
|
|
|
|
|
|
+ $form['#tree'] = TRUE;
|
|
|
+
|
|
|
// Loop through the categories and add them to the table.
|
|
|
foreach ($result as $data) {
|
|
|
|
|
|
$triggers = array_map('check_plain', unserialize($data->triggers));
|
|
|
- if (empty($triggers))
|
|
|
+ if (empty($triggers)) {
|
|
|
$triggers = array();
|
|
|
+ }
|
|
|
|
|
|
$roles = array_map('check_plain', unserialize($data->roles));
|
|
|
- if (empty($roles))
|
|
|
+ if (empty($roles)) {
|
|
|
$roles = array();
|
|
|
+ }
|
|
|
|
|
|
- $rows[] = array(
|
|
|
- theme('login_destination_destination', array('destination' => $data->destination)),
|
|
|
- theme('login_destination_triggers', array('items' => $triggers)),
|
|
|
- theme('login_destination_pages', array('pages' => $data->pages, 'pages_type' => $data->pages_type)),
|
|
|
- theme('login_destination_roles', array('items' => $roles)),
|
|
|
- l(t('Edit'), 'admin/config/people/login-destination/edit/' . $data->id),
|
|
|
- l(t('Delete'), 'admin/config/people/login-destination/delete/' . $data->id),
|
|
|
+ $form[$data->id]['destination']['#markup'] = theme('login_destination_destination', array('destination' => $data->destination));
|
|
|
+ $form[$data->id]['triggers']['#markup'] = theme('login_destination_triggers', array('items' => $triggers));
|
|
|
+ $form[$data->id]['pages']['#markup'] = theme('login_destination_pages', array('pages' => $data->pages, 'pages_type' => $data->pages_type));
|
|
|
+ $form[$data->id]['roles']['#markup'] = theme('login_destination_roles', array('items' => $roles));
|
|
|
+
|
|
|
+ $form[$data->id]['weight'] = array(
|
|
|
+ '#type' => 'weight',
|
|
|
+ '#title' => t('Weight'),
|
|
|
+ '#delta' => 50,
|
|
|
+ '#default_value' => $data->weight,
|
|
|
+ '#title_display' => 'invisible',
|
|
|
+ );
|
|
|
+
|
|
|
+ $form[$data->id]['enabled'] = array(
|
|
|
+ '#type' => 'checkbox',
|
|
|
+ '#title' => t('Enabled'),
|
|
|
+ '#default_value' => $data->enabled,
|
|
|
+ '#title_display' => 'invisible',
|
|
|
);
|
|
|
+
|
|
|
+ // Build a list of operations.
|
|
|
+ $operations = array();
|
|
|
+ $operations['edit'] = array(
|
|
|
+ '#type' => 'link',
|
|
|
+ '#title' => t('edit'),
|
|
|
+ '#href' => 'admin/config/people/login-destination/edit/' . $data->id,
|
|
|
+ );
|
|
|
+
|
|
|
+ $operations['delete'] = array(
|
|
|
+ '#type' => 'link',
|
|
|
+ '#title' => t('delete'),
|
|
|
+ '#href' => 'admin/config/people/login-destination/delete/' . $data->id,
|
|
|
+ );
|
|
|
+
|
|
|
+ $form[$data->id]['operations'] = $operations;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (element_children($form)) {
|
|
|
+ $form['actions'] = array('#type' => 'actions');
|
|
|
+ $form['actions']['submit'] = array(
|
|
|
+ '#type' => 'submit',
|
|
|
+ '#value' => t('Save configuration'),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $form['#empty_text'] = t('There is no Login Destination Rule.');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $form;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Returns HTML for a login destination list.
|
|
|
+ *
|
|
|
+ * @param array $variables
|
|
|
+ * An associative array containing:
|
|
|
+ * - form: A render element representing the form.
|
|
|
+ *
|
|
|
+ * @ingroup themeable
|
|
|
+ */
|
|
|
+function theme_login_destination_overview_form($variables) {
|
|
|
+ $form = $variables['form'];
|
|
|
+
|
|
|
+ drupal_add_tabledrag('login-destination-overview', 'order', 'sibling', 'login-destination-weight');
|
|
|
+
|
|
|
+ $header = array(
|
|
|
+ t('Destination'),
|
|
|
+ t('Triggers'),
|
|
|
+ t('Pages'),
|
|
|
+ t('Roles'),
|
|
|
+ array('data' => t('Enabled'), 'class' => array('checkbox')),
|
|
|
+ t('Weight'),
|
|
|
+ array('data' => t('Operations'), 'colspan' => '2'),
|
|
|
+ );
|
|
|
+
|
|
|
+ $rows = array();
|
|
|
+ foreach (element_children($form) as $ldid) {
|
|
|
+ if (isset($form[$ldid]['enabled'])) {
|
|
|
+
|
|
|
+ $element = &$form[$ldid];
|
|
|
+
|
|
|
+ $operations = array();
|
|
|
+ foreach (element_children($element['operations']) as $op) {
|
|
|
+ $operations[] = array('data' => drupal_render($element['operations'][$op]), 'class' => array('login-destination-operations'));
|
|
|
+ }
|
|
|
+ while (count($operations) < 2) {
|
|
|
+ $operations[] = '';
|
|
|
+ }
|
|
|
+
|
|
|
+ $row = array();
|
|
|
+ $row[] = drupal_render($element['destination']);
|
|
|
+ $row[] = drupal_render($element['triggers']);
|
|
|
+ $row[] = drupal_render($element['pages']);
|
|
|
+ $row[] = drupal_render($element['roles']);
|
|
|
+ $row[] = array(
|
|
|
+ 'data' => drupal_render($element['enabled']),
|
|
|
+ 'class' => array(
|
|
|
+ 'checkbox', 'login-destination-enabled',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ $form[$ldid]['weight']['#attributes']['class'] = array('login-destination-weight');
|
|
|
+
|
|
|
+ $row[] = drupal_render($element['weight']);
|
|
|
+ $row = array_merge($row, $operations);
|
|
|
+ $row = array_merge(array('data' => $row), array());
|
|
|
+ $row['class'][] = 'draggable';
|
|
|
+ $rows[] = $row;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (!$rows) {
|
|
|
- $rows[] = array(array(
|
|
|
- 'data' => t('No rules available.'),
|
|
|
- 'colspan' => 6,
|
|
|
- ));
|
|
|
+ $output = '';
|
|
|
+ if (empty($rows)) {
|
|
|
+ $rows[] = array(
|
|
|
+ array(
|
|
|
+ 'data' => $form['#empty_text'],
|
|
|
+ 'colspan' => '7',
|
|
|
+ ),
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
- $build['login-destination_table'] = array(
|
|
|
- '#theme' => 'table',
|
|
|
- '#header' => $header,
|
|
|
- '#rows' => $rows,
|
|
|
+ $table_arguments = array(
|
|
|
+ 'header' => $header,
|
|
|
+ 'rows' => $rows,
|
|
|
+ 'attributes' => array(
|
|
|
+ 'id' => 'login-destination-overview',
|
|
|
+ ),
|
|
|
);
|
|
|
- return $build;
|
|
|
+
|
|
|
+ $output .= theme('table', $table_arguments);
|
|
|
+
|
|
|
+ $output .= drupal_render_children($form);
|
|
|
+
|
|
|
+ return $output;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Submit handler for the login destination overview form.
|
|
|
+ *
|
|
|
+ * This function update the login destination rule attribute
|
|
|
+ * like rules are enabled/disabled or its weight.
|
|
|
+ *
|
|
|
+ * @see login_destination_overview_form()
|
|
|
+ */
|
|
|
+function login_destination_overview_form_submit($form, &$form_state) {
|
|
|
+ $element = &$form_state['values'];
|
|
|
+ foreach (element_children($element) as $ldid) {
|
|
|
+ if (isset($form[$ldid]['enabled'])) {
|
|
|
+ $login_destination_rules[$ldid] = $element[$ldid];
|
|
|
+ $login_destination_rules[$ldid]['ldid'] = $ldid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($login_destination_rules as $ldid => $login_destination_rule) {
|
|
|
+ _login_destination_update_rules($login_destination_rule);
|
|
|
+ }
|
|
|
+
|
|
|
+ drupal_set_message(t('Your configuration has been saved.'), 'status');
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Save all our changed items to the database.
|
|
|
+ *
|
|
|
+ * @param array $login_destination_rule
|
|
|
+ * An associative array representing a login destination item:
|
|
|
+ * - enabled: (required) can contain 0 or 1, if rule is enabled then
|
|
|
+ * it should be 1 else 0.
|
|
|
+ * - weight: (required) can contain any integer value.
|
|
|
+ *
|
|
|
+ * @return bool
|
|
|
+ * The ldid of the saved login destination rule, or FALSE
|
|
|
+ * if the login destination rule could not be saved.
|
|
|
+ */
|
|
|
+function _login_destination_update_rules($login_destination_rule) {
|
|
|
+
|
|
|
+ if (!(isset($login_destination_rule['enabled']) && isset($login_destination_rule['weight']) && isset($login_destination_rule['ldid']))) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($login_destination_rule['enabled'] != 0 && $login_destination_rule['enabled'] != 1) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ $login_destination_rule['weight'] = intval($login_destination_rule['weight']);
|
|
|
+
|
|
|
+ if (!is_int($login_destination_rule['weight'])) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ db_update('login_destination')
|
|
|
+ ->fields(array(
|
|
|
+ 'enabled' => $login_destination_rule['enabled'],
|
|
|
+ 'weight' => $login_destination_rule['weight'],
|
|
|
+ ))
|
|
|
+ ->condition('id', $login_destination_rule['ldid'])
|
|
|
+ ->execute();
|
|
|
+
|
|
|
+ return $login_destination_rule['ldid'];
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Render a destination of login destination rule.
|
|
|
+ */
|
|
|
function theme_login_destination_destination($variables) {
|
|
|
$output = nl2br(check_plain($variables['destination']));
|
|
|
|
|
@@ -71,6 +258,9 @@ function theme_login_destination_destination($variables) {
|
|
|
return $output;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Render a trigger of login destination rule.
|
|
|
+ */
|
|
|
function theme_login_destination_triggers($variables) {
|
|
|
$items = array_map('check_plain', $variables['items']);
|
|
|
|
|
@@ -82,10 +272,11 @@ function theme_login_destination_triggers($variables) {
|
|
|
foreach ($items as &$item) {
|
|
|
switch ($item) {
|
|
|
case 'login':
|
|
|
- $item = 'Login';
|
|
|
+ $item = t('Login');
|
|
|
break;
|
|
|
+
|
|
|
case 'logout':
|
|
|
- $item = 'Logout';
|
|
|
+ $item = t('Logout');
|
|
|
break;
|
|
|
}
|
|
|
$output .= $item . "<br/>";
|
|
@@ -94,9 +285,12 @@ function theme_login_destination_triggers($variables) {
|
|
|
return $output;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Render a page type of login destination rule.
|
|
|
+ */
|
|
|
function theme_login_destination_pages($variables) {
|
|
|
$type = $variables['pages_type'];
|
|
|
-
|
|
|
+
|
|
|
if ($type == LOGIN_DESTINATION_REDIRECT_PHP) {
|
|
|
return nl2br(check_plain($variables['pages']));
|
|
|
}
|
|
@@ -120,11 +314,14 @@ function theme_login_destination_pages($variables) {
|
|
|
$output .= "~ ";
|
|
|
}
|
|
|
$output .= $page . "<br/>";
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
return $output;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Render a roles of login destination rule.
|
|
|
+ */
|
|
|
function theme_login_destination_roles($variables) {
|
|
|
$items = array_values(array_intersect_key(_login_destination_role_options(), $variables['items']));
|
|
|
|
|
@@ -139,7 +336,7 @@ function theme_login_destination_roles($variables) {
|
|
|
* Category edit page.
|
|
|
*/
|
|
|
function login_destination_edit_form($form, &$form_state, array $rule = array()) {
|
|
|
- // default values
|
|
|
+ // Default values.
|
|
|
$rule += array(
|
|
|
'triggers' => array(),
|
|
|
'roles' => array(),
|
|
@@ -167,18 +364,29 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
|
|
|
}
|
|
|
else {
|
|
|
$options = array(
|
|
|
- LOGIN_DESTINATION_STATIC => t('Internal page or external URL'),
|
|
|
- );
|
|
|
- $description = t("Specify page by using its path. Example path is %blog for the blog page. %front is the front page. %current is the current page. Precede with http:// for an external URL. Leave empty to redirect to a default page.", array('%blog' => 'blog', '%front' => '<front>', '%current' => '<current>'));
|
|
|
+ LOGIN_DESTINATION_STATIC => t('Internal page or external URL'),
|
|
|
+ );
|
|
|
+ $description = t("Specify page by using its path. Example path is %blog for the blog page. %front is the front page. %current is the current page. Precede with http:// for an external URL. Leave empty to redirect to a default page.", array(
|
|
|
+ '%blog' => 'blog',
|
|
|
+ '%front' => '<front>',
|
|
|
+ '%current' => '<current>',
|
|
|
+ )
|
|
|
+ );
|
|
|
|
|
|
if (module_exists('php') && $access) {
|
|
|
$options += array(LOGIN_DESTINATION_SNIPPET => t('Page returned by this PHP code (experts only)'));
|
|
|
- $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. It should return either a string value or an array of params that the %function function will understand, e.g. %example. For more information, see the online API entry for <a href="@url">url function</a>. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => '<?php ?>', '%function' => 'url($path = \'\', array $options = array())', '%example' => '<?php return array(\'blog\', array(\'fragment\' => \'overlay=admin/config\', ), ); ?>', '@url' => 'http://api.drupal.org/api/drupal/includes--common.inc/function/url/7'));
|
|
|
+ $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. It should return either a string value or an array of params that the %function function will understand, for example. %example. For more information, see the online API entry for <a href="@url">url function</a>. Note that executing incorrect PHP code can break your Drupal site.', array(
|
|
|
+ '%php' => '<?php ?>',
|
|
|
+ '%function' => 'url($path = \'\', array $options = array())',
|
|
|
+ '%example' => '<?php return array(\'blog\', array(\'fragment\' => \'overlay=admin/config\', ), ); ?>',
|
|
|
+ '@url' => 'http://api.drupal.org/api/drupal/includes--common.inc/function/url/7',
|
|
|
+ )
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
$form['destination_type'] = array(
|
|
|
'#type' => 'radios',
|
|
|
- '#title' => 'Redirect to page',
|
|
|
+ '#title' => t('Redirect to page'),
|
|
|
'#default_value' => $type,
|
|
|
'#options' => $options,
|
|
|
);
|
|
@@ -197,9 +405,9 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
|
|
|
$form['triggers'] = array(
|
|
|
'#type' => 'checkboxes',
|
|
|
'#title' => t('Redirect upon triggers'),
|
|
|
- '#options' => array('login' => 'Login, registration, one-time login link', 'logout' => 'Logout'),
|
|
|
+ '#options' => array('login' => t('Login, registration, one-time login link'), 'logout' => t('Logout')),
|
|
|
'#default_value' => $triggers,
|
|
|
- '#description' => 'Redirect only upon selected trigger(s). If you select no triggers, all of them will be used.',
|
|
|
+ '#description' => t('Redirect only upon selected trigger(s). If you select no triggers, all of them will be used.'),
|
|
|
);
|
|
|
|
|
|
$type = $rule['pages_type'];
|
|
@@ -216,10 +424,18 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
|
|
|
}
|
|
|
else {
|
|
|
$options = array(
|
|
|
- LOGIN_DESTINATION_REDIRECT_NOTLISTED => t('All pages except those listed'),
|
|
|
- LOGIN_DESTINATION_REDIRECT_LISTED => t('Only the listed pages'),
|
|
|
- );
|
|
|
- $description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. %login is the login form. %register is the registration form. %reset is the one-time login (e-mail validation).", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>', '%login' => 'user', '%register' => 'user/register', '%reset' => 'user/*/edit'));
|
|
|
+ LOGIN_DESTINATION_REDIRECT_NOTLISTED => t('All pages except those listed'),
|
|
|
+ LOGIN_DESTINATION_REDIRECT_LISTED => t('Only the listed pages'),
|
|
|
+ );
|
|
|
+ $description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page. %login is the login form. %register is the registration form. %reset is the one-time login (e-mail validation).", array(
|
|
|
+ '%blog' => 'blog',
|
|
|
+ '%blog-wildcard' => 'blog/*',
|
|
|
+ '%front' => '<front>',
|
|
|
+ '%login' => 'user',
|
|
|
+ '%register' => 'user/register',
|
|
|
+ '%reset' => 'user/*/edit',
|
|
|
+ )
|
|
|
+ );
|
|
|
|
|
|
if (module_exists('php') && $access) {
|
|
|
$options += array(LOGIN_DESTINATION_REDIRECT_PHP => t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'));
|
|
@@ -249,14 +465,7 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
|
|
|
'#title' => t('Redirect users with roles'),
|
|
|
'#options' => _login_destination_role_options(),
|
|
|
'#default_value' => $default_role_options,
|
|
|
- '#description' => 'Redirect only the selected role(s). If you select no roles, all users will be redirected.',
|
|
|
- );
|
|
|
-
|
|
|
- $form['weight'] = array(
|
|
|
- '#type' => 'weight',
|
|
|
- '#title' => t('Weight'),
|
|
|
- '#default_value' => $rule['weight'],
|
|
|
- '#description' => t('When evaluating login destination rules, those with lighter (smaller) weights get evaluated before rules with heavier (larger) weights.'),
|
|
|
+ '#description' => t('Redirect only the selected role(s). If you select no roles, all users will be redirected.'),
|
|
|
);
|
|
|
|
|
|
$form['actions'] = array('#type' => 'actions');
|
|
@@ -279,6 +488,17 @@ function login_destination_edit_form($form, &$form_state, array $rule = array())
|
|
|
* Validate the contact category edit page form submission.
|
|
|
*/
|
|
|
function login_destination_edit_form_validate($form, &$form_state) {
|
|
|
+ $destination = $form_state['values']['destination'];
|
|
|
+ $destination_type = $form_state['values']['destination_type'];
|
|
|
+
|
|
|
+ // Check user has enter any path.
|
|
|
+ if (!empty($destination) && $destination_type == 0) {
|
|
|
+ $destination = preg_replace("/\?.+/", "", $destination);
|
|
|
+ if (!drupal_valid_path($destination)) {
|
|
|
+ form_set_error('destination', t('Incorrect path, Please Enter valid Path'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -296,7 +516,7 @@ function login_destination_edit_form_submit($form, &$form_state) {
|
|
|
}
|
|
|
|
|
|
drupal_set_message(t('Login destination to %destination has been saved.', array('%destination' => $form_state['values']['destination'])));
|
|
|
-
|
|
|
+
|
|
|
$form_state['redirect'] = 'admin/config/people/login-destination';
|
|
|
}
|
|
|
|