diff --git a/protected_node.info b/protected_node.info
index 87b3120..7fa86c6 100644
--- a/protected_node.info
+++ b/protected_node.info
@@ -1,4 +1,9 @@
 name = Protected Node
 description = Controls whether selected nodes are protected with a password.
-core = 6.x
-package = Access
\ No newline at end of file
+core = 7.x
+package = Access
+; Information added by drupal.org packaging script on 2009-02-28
+version = "7.x-1"
+core = "7.x"
+project = "protected_node"
+
diff --git a/protected_node.install b/protected_node.install
index 00e5cd3..73a54c0 100644
--- a/protected_node.install
+++ b/protected_node.install
@@ -1,4 +1,5 @@
 <?php
+// $Id: protected_node.install,v 1.11 2008/10/14 08:58:10 tolmi Exp $
 
 
 /*
diff --git a/protected_node.module b/protected_node.module
index 6aa6a90..02ee7f0 100644
--- a/protected_node.module
+++ b/protected_node.module
@@ -1,4 +1,5 @@
 <?php
+// $Id: protected_node.module,v 1.18 2009/02/28 09:35:59 tolmi Exp $
 
 
 /*
@@ -32,9 +33,14 @@ function protected_node_requirements($phase) {
     foreach ( $perms as $perm ) {
       $likes[] = "perm LIKE '%" . $perm . "%'";
     }
+	  
     $sql = "SELECT rid FROM {permission} WHERE " . implode( ' OR ', $likes );
-    $roles = db_affected_rows( db_query( $sql ) );
-    if ($roles) {
+    $roles = db_query($sql)
+    	->countQuery()
+    	->execute()
+    	->fetchField();
+    
+    if ($roles > 0) {
       $reqs['protected_node'] = array(
         'title' => t( 'Protected nodes access rights' ),
         'value' => t( 'At least one of the roles has access to protected contents' ),
@@ -59,17 +65,26 @@ function protected_node_requirements($phase) {
 }
 
 /**
- * Implementation of hook_perm().
- * @link http://api.drupal.org/api/function/hook_perm/6
+ * Implementation of hook_permission()
  */
-function protected_node_perm( ) {
+function protected_node_permission( ) {
   $perms = array(
-    'access protected content',
-  	'bypass password protection',
-    'edit protected content'
+    'access protected content' => array(
+    	'title' => t('Access protected content'),
+    	),
+    'bypass password protection' => array(
+    	'title' => t('Bypass password protection'),
+    	),
+    'edit protected content' => array(
+    	'title' => t('Edit protected content'),
+    	),
   );
-  foreach ( array_keys( node_get_types() ) as $type ) {
-    $perms[] = 'edit protected ' . $type;
+  foreach ( array_keys( node_type_get_types() ) as $type ) {
+    $key = 'edit protected ' . $type;
+    $title = 'Edit protected '. $type;
+    $perms[$key] = array(
+    	'title' => $title,
+    	);
   }
 
   return $perms;
@@ -80,9 +95,10 @@ function protected_node_perm( ) {
  * @link http://api.drupal.org/api/function/hook_form_alter/6
  */
 function protected_node_form_alter(&$form, &$form_state, $form_id) {
-  $types = node_get_types();
-  $node_type = $types[$form['type']['#value']];
-  if ($form['#id'] == 'node-form' && (user_access( 'edit protected content' ) || user_access( 'edit protected ' . $form['type']['#value'] ))) {
+
+  $types = node_type_get_types();
+  $node_type = (isset($form['type']['#value'])) ? $types[$form['type']['#value']] : FALSE;
+  if ($node_type && $form["#node_edit_form"] && (user_access( 'edit protected content' ) || user_access( 'edit protected ' . $form['type']['#value'] ))) {
     $form['protected_node'] = array(
       '#type' => 'fieldset',
       '#description' => t( 'Here if you check the checkbox and provide a password your newly created node will be password protected.' ),
@@ -90,11 +106,14 @@ function protected_node_form_alter(&$form, &$form_state, $form_id) {
       '#collapsible' => TRUE,
       '#collapsed' => TRUE
     );
+    
+    $is_protected = isset($form['#node']->is_protected) ? $form['#node']->is_protected : FALSE;
+    
     $form['protected_node']['is_protected'] = array(
       '#type' => 'checkbox',
       '#title' => t( 'This @node is protected', array('@node' => $node_type->name) ),
       '#description' => t( 'Check here if this content should be protected by a password.' ),
-      '#default_value' => $form['#node']->is_protected
+      '#default_value' => $is_protected
     );
     $form['protected_node']['show_title'] = array(
       '#type' => 'checkbox',
@@ -102,9 +121,12 @@ function protected_node_form_alter(&$form, &$form_state, $form_id) {
       '#description' => t( 'Show the title to users when requesting the password.' ),
       '#default_value' => variable_get('protected_node-'. $form['nid']['#value'] .'-show_title', FALSE),
     );
+    
+    $was_protected = isset($form['#node']->was_protected) ? $form['#node']->was_protected : FALSE;
+    
     $form['protected_node']['was_protected'] = array(
       '#type' => 'hidden',
-      '#default_value' => $form['#node']->was_protected
+      '#default_value' => $was_protected
     );
     $form['protected_node']['password'] = array(
       '#type' => 'password_confirm',
@@ -115,64 +137,77 @@ function protected_node_form_alter(&$form, &$form_state, $form_id) {
   }
 }
 
-/**
- * Implementation of hook_nodeapi().
- * @link http://api.drupal.org/api/function/hook_nodeapi/6
- */
-function protected_node_nodeapi(&$node, $op, $arg = 0, $page = 0) {
-  global $user;
+/* Implementation of hook_load */
+ 
+function protected_node_node_load($nodes,$types) {
+      foreach ($nodes as $node) {
+	      $node->is_protected = protected_node_isset_protected( $node->nid );
+	      $node->was_protected = $node->is_protected;
+	      $node->show_title = variable_get('protected_node-'. $node->nid .'-show_title', FALSE );
+	      }
+      }
+      
+      
+/* Implementation of hook_delete */
 
-  switch ($op) {
-    case 'load' :
-      $output['is_protected'] = protected_node_isset_protected( $node->nid );
-      $output['was_protected'] = $output['is_protected'];
-      return $output;
-      break;
-    case 'delete' :
+function protected_node_delete($node) {
       protected_node_unset_protected( $node->nid );
-      break;
-    case 'insert' :
-      if ($node->is_protected && (!empty( $node->password ) || isset( $_SESSION['_protected_node']['entered_password'] ))) {
-        $pwd = isset( $_SESSION['_protected_node']['entered_password'] ) ? $_SESSION['_protected_node']['entered_password'] : $node->password;
-        unset( $_SESSION['_protected_node']['entered_password'] );
-        protected_node_set_protected( $node->nid, $pwd );
       }
-      if ($node->show_title) {
-        variable_set('protected_node-'. $node->nid .'-show_title', TRUE );
+      
+/* Implementation of hook_insert */
+      
+function protected_node_node_insert($node) {
+      if ($node->is_protected && (!empty( $node->password ) || isset( $_SESSION['_protected_node']['entered_password'] ))) {
+		$pwd = isset( $_SESSION['_protected_node']['entered_password'] ) ? $_SESSION['_protected_node']['entered_password'] : $node->password;
+		unset( $_SESSION['_protected_node']['entered_password'] );
+		protected_node_set_protected( $node->nid, $pwd );
+	      }
+	      if ($node->show_title) {
+		variable_set('protected_node-'. $node->nid .'-show_title', TRUE );
+	      }
       }
-      break;
-    case 'validate' :
+      
+function protected_node_node_validate($node, $form, &$form_state) {
       if ($node->is_protected && !empty($node->password)) {
-        $_SESSION['_protected_node']['entered_password'] = $node->password;
-      }
-      break;
-    case 'update' :
-      // Protected flag was switched off?
-      if ($node->was_protected && !$node->is_protected) {
-        protected_node_unset_protected( $node->nid );
-      }
+		$_SESSION['_protected_node']['entered_password'] = $node->password;
+	      }
+	}
+	
+function protected_node_node_update($node) {
 
-      if ($node->is_protected && (!empty( $node->password ) || isset( $_SESSION['_protected_node']['entered_password'] ))) {
-        if (db_result( db_query( 'SELECT count(*) FROM {protected_nodes} WHERE nid = %d', $node->nid ) ) > 0) {
-          $pwd = isset( $_SESSION['_protected_node']['entered_password'] ) ? $_SESSION['_protected_node']['entered_password'] : $node->password;
-          unset( $_SESSION['_protected_node']['entered_password'] );
-          protected_node_set_protected( $node->nid, $pwd );
-        }
-        else {
-          protected_node_nodeapi( $node, 'insert', $arg, $page );
-        }
-      }
+	      // Protected flag was switched off?
+	      if ($node->was_protected && !$node->is_protected) {
+		protected_node_unset_protected( $node->nid );
+	      }
 
-      //mark the node for show title on password page
-      if ($node->show_title) {
-        variable_set('protected_node-'. $node->nid .'-show_title', TRUE );
-      }
-      else {
-        variable_del('protected_node-'. $node->nid .'-show_title');
+	      if ($node->is_protected && (!empty( $node->password ) || isset( $_SESSION['_protected_node']['entered_password'] ))) {
+	      
+	          $result = db_query('SELECT nid FROM {protected_nodes} WHERE nid = :nid', array(':nid' => $node->nid));
+  		  if ($result->rowCount() > 0) {
+		  $pwd = isset( $_SESSION['_protected_node']['entered_password'] ) ? $_SESSION['_protected_node']['entered_password'] : $node->password;
+		  unset( $_SESSION['_protected_node']['entered_password'] );
+		  protected_node_set_protected($node->nid, $pwd);
+		}
+		else {
+		  protected_node_node_insert($node);
+		}
+	      }
+
+	      //mark the node for show title on password page
+	      if ($node->show_title) {
+		variable_set('protected_node-'. $node->nid .'-show_title', TRUE );
+	      }
+	      else {
+		variable_del('protected_node-'. $node->nid .'-show_title');
+	      }
       }
-      break;
-    case 'view' :
+      
+function protected_node_node_view($node, $view_mode, $langcode) {
+
+      global $user;
+      
       if ($node->is_protected && !user_access('bypass password protection')) {
+      
         // If we have been accessed from cron.php (f.e. search indexing)
         if (variable_get( 'cron_semaphore', FALSE )) {
           $node->title = '';
@@ -180,6 +215,7 @@ function protected_node_nodeapi(&$node, $op, $arg = 0, $page = 0) {
           $node->body = '';
           $node->content = array();
         }
+        
         else {
           if (!$user->uid && variable_get( 'cache', 0 )) {
             $GLOBALS['conf']['cache'] = FALSE;
@@ -188,29 +224,21 @@ function protected_node_nodeapi(&$node, $op, $arg = 0, $page = 0) {
           if ($node->uid !== $user->uid) {
             // If node is protected and not teaser nor page view and not owner of node
             if (!isset( $_SESSION['_protected_node']['passwords'][$node->nid] )) {
-              if (!$arg) {
                 $_SESSION['_protected_node']['current'] = $node->nid;
                 $destination = drupal_get_destination();
-                drupal_goto( 'protected-node', $destination );
-              }
-              else {
-                $node->teaser = '';
-                $node->body = '';
-                $node->content = array();
-              }
+                drupal_goto( 'protected-node', array('query' => $destination) );
             }
           }
         }
       }
-      break;
-  }
-}
+    }
 
 /**
  * Implementation of hook_menu().
  * @link http://api.drupal.org/api/function/hook_menu/6
  */
 function protected_node_menu( ) {
+  $items = array();
   $items['admin/settings/protected_node'] = array(
     'title' => 'Protected node',
     'description' => 'Here you change protected node settings',
@@ -247,7 +275,8 @@ function protected_node_menu( ) {
 function protected_node_file_download($file) {
   global $user;
 
-  $db_file = db_result( db_query( 'SELECT u.nid FROM {files} f, {upload} u, {protected_nodes} pn, {node} n WHERE pn.nid = u.nid AND u.nid = n.nid AND f.filename = \'%s\' AND u.fid = f.fid', $file ) );
+  $db_file = db_query( 'SELECT u.nid FROM {files} f, {upload} u, {protected_nodes} pn, {node} n WHERE pn.nid = u.nid AND u.nid = n.nid AND f.filename = :file AND u.fid = f.fid', array(':file' => $file))
+  	->execute();
   if (db_error() || $db_file === FALSE || $user->uid == $db_file || $_SESSION['_protected_node']['passwords'][$db_file] || user_access('bypass password protection')) {
     return array();
   }
@@ -279,11 +308,25 @@ function protected_node_set_protected($nid, $password) {
   }
 
   $success = FALSE;
+  $db_pass = sha1($protected_node_salt.$password);
+  
   if (protected_node_isset_protected( $nid )) {
-    $success = db_query( 'UPDATE {protected_nodes} SET passwd = \'%s\' WHERE nid = %d', sha1( $protected_node_salt . $password ), $nid );
+
+    $success = db_update('protected_nodes')
+    	->fields(array(
+    		'passwd' => $db_pass,
+    		))
+    	->condition('nid',$nid)
+    	->execute();
   }
   else {
-    $success = db_query( 'INSERT INTO {protected_nodes} (nid, passwd) VALUES (%d, \'%s\')', $nid, sha1( $protected_node_salt . $password ) );
+
+    $success = db_insert('protected_nodes')
+    	->fields(array(
+    		'nid' => $nid,
+    		'passwd' => $db_pass
+    		))
+    	->execute();
   }
 
   return $success !== FALSE;
@@ -301,7 +344,9 @@ function protected_node_unset_protected($nid) {
     return FALSE;
   }
 
-  $success = db_query( 'DELETE FROM {protected_nodes} WHERE nid = %d', $nid );
+  $success = db_delete('protected_nodes')
+  	->condition('nid',$nid)
+  	->execute();
 
   return $success !== FALSE;
 }
@@ -317,8 +362,8 @@ function protected_node_isset_protected($nid) {
     return FALSE;
   }
 
-  $nodes = db_affected_rows( db_query( 'SELECT nid FROM {protected_nodes} WHERE nid = %d', $nid ) );
-  if ($nodes > 0) {
+  $result = db_query('SELECT nid FROM {protected_nodes} WHERE nid = :nid', array(':nid' => $nid));
+  if ($result->rowCount() > 0) {
     return TRUE;
   }
   else {
diff --git a/protected_node.redirect.inc b/protected_node.redirect.inc
index d68f4fd..9203ce1 100644
--- a/protected_node.redirect.inc
+++ b/protected_node.redirect.inc
@@ -1,4 +1,5 @@
 <?php
+// $Id: protected_node.redirect.inc,v 1.3 2009/02/28 09:35:59 tolmi Exp $
 /**
  * @file
  * Redirected page callback file for the protected_node module.
@@ -16,12 +17,12 @@ function protected_node_enterpassword( ) {
   }
 
   $node = node_load( $_SESSION['_protected_node']['current'] );
-  $types = node_get_types();
+  $types = node_type_get_types();
   $node_type = $types[$node->type];
 
   $info = variable_get( 'protected_node_info', '' );
   if (module_exists( 'token' )) {
-    $info = token_replace( $info, 'node', node_load( $_SESSION['_protected_node']['current'] ) );
+    $info = token_replace( $info, array('node' => $node), array('node' => node_load( $_SESSION['_protected_node']['current'])));
   }
 
   $form['protected_node'] = array(
@@ -44,6 +45,13 @@ function protected_node_enterpassword( ) {
     '#type' => 'submit',
     '#value' => t( 'OK' )
   );
+  
+  if (isset($node->show_title) && $node->show_title) {
+  	drupal_set_title(check_plain($node->title));
+  	}
+  else {
+  	drupal_set_title(t('Please enter password'));
+  	}
 
   return $form;
 }
@@ -53,9 +61,12 @@ function protected_node_enterpassword( ) {
  */
 function protected_node_enterpassword_validate($form, &$form_state) {
   global $_protected_node_salt;
-
-  $cnt = db_result( db_query( 'SELECT nid FROM {protected_nodes} WHERE passwd = \'%s\' AND nid = %d', sha1( $_protected_node_salt . $form['#post']['password'] ), $_SESSION['_protected_node']['current'] ) );
-  if ($cnt < 1) {
+  
+  $passwd = sha1( $_protected_node_salt . $form["protected_node_enterpassword"]['password']['#value'] );
+  $nid = $_SESSION['_protected_node']['current'];
+  
+  $result = db_query('SELECT nid FROM {protected_nodes} WHERE passwd = :passwd AND nid = :nid', array(':passwd' => $passwd, ':nid' => $nid));
+  if ($result->rowCount() < 1) {
     form_set_error( 'password', t( 'Incorrect password!' ) );
   }
 }
@@ -66,4 +77,4 @@ function protected_node_enterpassword_validate($form, &$form_state) {
 function protected_node_enterpassword_submit($form, &$form_state) {
   $_SESSION['_protected_node']['passwords'][$_SESSION['_protected_node']['current']] = TRUE;
   unset( $_SESSION['_protected_node']['current'] );
-}
\ No newline at end of file
+}
diff --git a/protected_node.settings.inc b/protected_node.settings.inc
index b4abab9..dd36104 100644
--- a/protected_node.settings.inc
+++ b/protected_node.settings.inc
@@ -1,4 +1,5 @@
 <?php
+// $Id: protected_node.settings.inc,v 1.1 2008/10/14 09:35:29 tolmi Exp $
 /**
  * @file
  * Configuration file for the protected_node module.
