open; $form['domain']['open_domain'] = array( '#type' => 'checkbox', '#title' => t('Open'), '#default_value' => $def_value, '#description' => t('If content on this page shall be open for all users?') ); $form['#submit'][] = 'domain_toggle_toggle_submit'; } } /** * Handles the open checkbox in the domain settings form. * * @param $form - copy of the form array * @param $form_state - link to the form state array */ function domain_toggle_toggle_submit($form, &$form_state) { $sql = "UPDATE {domain_toggle} SET open = '%s' WHERE domain_id = %d"; db_query($sql, $form_state['values']['open_domain'], $form_state['values']['domain_id']); } /** * Implementation of hook_domaingrants() * * In Domain Toggle, we only let users see content on open domains and private domains that * they are registered with. So we check the $user object in order * to set our grants rather than using the default module grants. * * @ingroup strict */ function domain_toggle_domaingrants(&$grants, $account, $op) { global $_domain; $res = db_query("SELECT open FROM {domain_toggle} WHERE domain_id = %d", $_domain['domain_id']); $open = db_fetch_object($res)->open; if ($open == '1') { return; } // Code from the domain_strict module: // Erase the default domain_id grants. unset($grants['domain_id']); $domains = (isset($account->domain_user)) ? $account->domain_user : array(); if (!empty($domains)) { foreach ($domains as $key => $value) { // The -1 is the root domain, since 0 cannot be stored by checkboxes. ($value == -1) ? $id = 0 : $id = $value; // If the user has access to the current domain, set that grant. if (abs($value) > 0 && $id == $_domain['domain_id']) { $grants['domain_id'][] = $id; } } } } /** * Implements hook_domainupdate() */ function domain_toggle_domainupdate($op, $domain, $form_state = array()) { switch ($op) { case 'delete': if ($domain != -1) { // Remove domain-specific entries from the {domain_toggle} table. db_query("DELETE FROM {domain_toggle} WHERE domain_id = %d", $domain['domain_id']); } break; case 'create': if ($domain != -1) { // Insert domain-specific entries to the {domain_toggle} table. db_query("INSERT INTO {domain_toggle} (domain_id) VALUES %d", $domain['domain_id']); } break; } } /** * Implements hook_domainview() */ function domain_toggle_domainview($op, $domain = array()) { switch ($op) { case 'header': return array(array('data' => t('Open'), 'field' => 'dt.open')); break; case 'select': return 'dt.open'; case 'join': return "LEFT JOIN {domain_toggle} dt ON d.domain_id = dt.domain_id"; break; case 'data': if($domain['domain_id']){ $res = db_query("SELECT open FROM {domain_toggle} WHERE domain_id = %d", $domain['domain_id']); return (db_fetch_object($res)->open == '1') ? t('Yes') : t('No'); } break; } }