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.
Wednesday, February 18, 2009
Module to backup drupal site
Backup and Migrate Module[http://drupal.org/project/backup_migrate]. is to take backup your drupal site. :)
R.Navaneethakrishnan
R.Navaneethakrishnan
Drupal user table : Users list joined before a week
Drupal stores dates in Unix time format. To find email addresses for users who joined after a certain date Use SQL query in phpmyadmin and then exported into an OpenOffice spreadsheet:
SELECT mail, FROM_UNIXTIME(created) FROM users WHERE created > 1199145600 LIMIT 500;
That returns 500 emails from users who registered since January 1, 2008. The FROM_UNIXTIME(created) converts the Unix formatted time into something human-readable.
SELECT mail, FROM_UNIXTIME(created) FROM users WHERE created > 1199145600 LIMIT 500;
That returns 500 emails from users who registered since January 1, 2008. The FROM_UNIXTIME(created) converts the Unix formatted time into something human-readable.
Thursday, February 12, 2009
Effective Sample code to get category tree in drupal or php
<?php
echo '<select name="category">
<option value="0">Root</option>';
echo $allcats = getTree();
foreach($allcats as $key=>$value) {
echo "<option value='$key'>$value</option>";
}
echo '</select>';
$con = mysql_connect("localhost","root","password") or die();
mysql_select_db('test',$con)or die();
function getTree($id=0) {
static $cates = array();
static $times = 0;
$times++;
$result = mysql_query("SELECT category_id,category_name FROM recusrsive WHERE parent_id=$id ORDER BY category_name") or die();
while($row = mysql_fetch_assoc($result))
{
$cates[$row['category_id']] = str_repeat(" ",$times-1)."|-".$row['category_name'];
getTree($row['category_id']);
}
$times--;
return $cates;
}
?>
Table Content
category_id parent_id category_name
1 0 CMS
2 0 Blogs
3 0 Forums
4 0 E-Commerce
5 1 Joomla
6 1 Mambo
7 6 Templates
8 6 Mods/Components
9 4 OSCommerce
10 2 Wordpress
11 10 Themes
12 10 Plugins
echo '<select name="category">
<option value="0">Root</option>';
echo $allcats = getTree();
foreach($allcats as $key=>$value) {
echo "<option value='$key'>$value</option>";
}
echo '</select>';
$con = mysql_connect("localhost","root","password") or die();
mysql_select_db('test',$con)or die();
function getTree($id=0) {
static $cates = array();
static $times = 0;
$times++;
$result = mysql_query("SELECT category_id,category_name FROM recusrsive WHERE parent_id=$id ORDER BY category_name") or die();
while($row = mysql_fetch_assoc($result))
{
$cates[$row['category_id']] = str_repeat(" ",$times-1)."|-".$row['category_name'];
getTree($row['category_id']);
}
$times--;
return $cates;
}
?>
Table Content
category_id parent_id category_name
1 0 CMS
2 0 Blogs
3 0 Forums
4 0 E-Commerce
5 1 Joomla
6 1 Mambo
7 6 Templates
8 6 Mods/Components
9 4 OSCommerce
10 2 Wordpress
11 10 Themes
12 10 Plugins
Subscribe to:
Posts (Atom)