Focus module is Simple module that improves the user interface by setting focus on the first field in a form.
A set of default forms (log-in, search, create content etc.) are defined in the module which can be overridden by the administrator.
Drupal and PHP related posts - Drupal Chennai, Navaneethakrishnan.R
Tuesday, March 24, 2009
Tuesday, March 17, 2009
Drupal Auto logout using custom code
Drupal Auto logout using custom code without autologout module
Add this line in the nodeapi to get last access time
switch ($op){
case "insert":
case "update":
case "execute":
case "validate":
case "prepare":
case "delete":
$_SESSION['lastaccess'] = time();
break;
}
Set $auto_timeout in settings.php
global $auto_timeout;
$auto_timeout=900;
Add the following code to check the time in hook_footer
function <modulename>_footer(){
global $user;
global $auto_timeout;
if($user->uid>0){
if (!isset($_SESSION['lastaccess']) || ((int)$_SESSION['lastaccess'] + $auto_timeout) > time()) {
$_SESSION['lastaccess'] = time();
return;
}else {
unset($_SESSION['lastaccess']);
drupal_set_message("Session timed out");
user_logout();
exit;
return;
}
}
return;
}
Add this line in the nodeapi to get last access time
switch ($op){
case "insert":
case "update":
case "execute":
case "validate":
case "prepare":
case "delete":
$_SESSION['lastaccess'] = time();
break;
}
Set $auto_timeout in settings.php
global $auto_timeout;
$auto_timeout=900;
Add the following code to check the time in hook_footer
function <modulename>_footer(){
global $user;
global $auto_timeout;
if($user->uid>0){
if (!isset($_SESSION['lastaccess']) || ((int)$_SESSION['lastaccess'] + $auto_timeout) > time()) {
$_SESSION['lastaccess'] = time();
return;
}else {
unset($_SESSION['lastaccess']);
drupal_set_message("Session timed out");
user_logout();
exit;
return;
}
}
return;
}
Monday, March 9, 2009
Add filter format to textarea in Drupal custom form
To add filter format to textarea in Drupal custom form, We can use following code
$form['']['format'] = filter_form($node->format);
R.Navaneethakrishnan.
$form['
R.Navaneethakrishnan.
Saturday, March 7, 2009
Exclude one CCK from drupal search
To exclude one cck in drupal search please follow as in the given steps.
1.Add this into hook_form in your custom module
case 'search_form':
$excluded_types = variable_get('search_excluded_node_types', array());
$types = array_map('check_plain', node_get_types('names'));
foreach($excluded_types as $excluded_type) {
unset($types[$excluded_type]);
}
$form['advanced']['type']['#options'] = $types;
$form['basic']['inline']['keys']['#prefix'] = '<div id="pref">';
$form['basic']['inline']['keys']['#suffix'] = '</div>';
// echopre($form['basic']['inline']);
break;
2.Add this in to hook_search in your custom module
function <modulename>_search($op = 'search') {
if ('admin' == $op) {
$form = array();
$form['search_excluded_node_types'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Excluded Node Types'),
'#default_value' => variable_get('search_excluded_node_types', array()),
'#options' => node_get_types('names'),
'#size' => 9,
'#description' => t('Node types to exclude from search results.'),
);
return $form;
}
}
3.Add this in to hook_db_rewrite_sql in your custom module
function <modulename>_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
if ($query == '' && $primary_table == 'n' && $primary_field = 'nid' && empty($args)) {
$excluded_types = variable_get('search_excluded_node_types', array());
if (!empty($excluded_types)) {
$where = " n.type NOT IN ('". join("','", $excluded_types) ."') ";
return array('where' => $where);
}
}
}
Note : This is for Drupal 5.x
R.Navaneethakrishnan.
1.Add this into hook_form in your custom module
case 'search_form':
$excluded_types = variable_get('search_excluded_node_types', array());
$types = array_map('check_plain', node_get_types('names'));
foreach($excluded_types as $excluded_type) {
unset($types[$excluded_type]);
}
$form['advanced']['type']['#options'] = $types;
$form['basic']['inline']['keys']['#prefix'] = '<div id="pref">';
$form['basic']['inline']['keys']['#suffix'] = '</div>';
// echopre($form['basic']['inline']);
break;
2.Add this in to hook_search in your custom module
function <modulename>_search($op = 'search') {
if ('admin' == $op) {
$form = array();
$form['search_excluded_node_types'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Excluded Node Types'),
'#default_value' => variable_get('search_excluded_node_types', array()),
'#options' => node_get_types('names'),
'#size' => 9,
'#description' => t('Node types to exclude from search results.'),
);
return $form;
}
}
3.Add this in to hook_db_rewrite_sql in your custom module
function <modulename>_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
if ($query == '' && $primary_table == 'n' && $primary_field = 'nid' && empty($args)) {
$excluded_types = variable_get('search_excluded_node_types', array());
if (!empty($excluded_types)) {
$where = " n.type NOT IN ('". join("','", $excluded_types) ."') ";
return array('where' => $where);
}
}
}
Note : This is for Drupal 5.x
R.Navaneethakrishnan.
Subscribe to:
Posts (Atom)