title: php/Drupal - list all nodes that a given user to permission to edit
body: <p>I have a function that lists all nodes on the system. I would like to refine this to show only nodes that current user is able to edit - either with API or SQL statement. (Drupal 6)</p>
  
  <pre><code>function fnGetNodeTypes($typeOfNodes) {
      $string = "";
      $types_of_nodes  = array_keys(node_get_types());
      $string .= "&lt;select name='typeOfNodes'&gt;";
      $string .= "&lt;option value=''&gt;Please select&lt;/option&gt; ";
      $string .= "&lt;option value='all'&gt;All&lt;/option&gt; ";
  
      foreach($types_of_nodes as $node){      
          if($typeOfNodes == $node ){
              $selected = "selected";
          }
          else{
              $selected = "";
          }       
          $string .= "&lt;option $selected value=\"" . $node . "\"&gt;" . $node ;
          $string .= "&lt;/option&gt;\n";
      }
      $string .= "&lt;/select\n&gt;";
      return $string;
  }
  </code></pre>
  
  <h3>Update:</h3>
  
  <p>Following @chx suggestion I tried messing around with users, users_roles and permissions.  Let me know if there is a more Drupal way of doing this.</p>
  
  <pre><code>//----------------------------------------------
  // Contruct select/option box of node types
  //----------------------------------------------
  function fnGetNodeTypes($typeOfNodes) {
      $string = "";
      $types_of_nodes  = array_keys(node_get_types());
      $string .= "&lt;select name='typeOfNodes'&gt;";
      $string .= "&lt;option value=''&gt;Please select&lt;/option&gt; ";
      //$string .= "&lt;option value='all'&gt;All&lt;/option&gt; ";
      foreach($types_of_nodes as $node_type){         
          if (fnInArray($node_type))
          {
              if($typeOfNodes == $node_type ){
                  $selected = "selected";
              }
              else{
                  $selected = "";
              }       
              $string .= "&lt;option $selected value=\"" . $node_type . "\"&gt;" . $node_type ;
              $string .= "&lt;/option&gt;\n";
          }
      }
      $string .= "&lt;/select\n&gt;";
      return $string;
  }
  
  //---------------------------------------------------------------------
  //  function fnInArray - see if user is allowed to edit this node type
  //---------------------------------------------------------------------
  
  function fnInArray($node_type)
  {
      global $user;
  
      if ($user-&gt;name == 'admin') { return TRUE; }
  
      // get list of all nodes that user is allowed to access
      // 
      $string =   " SELECT permission.perm as permission_perm "  .
          " from users " .
          " join users_roles  on ( users_roles.uid = users.uid ) " .
          " join permission on (permission.rid = users_roles.rid) " .
          " where  users.name = '" . $user-&gt;name . "'";
  
      $result = db_query($string);
      while ($row = db_fetch_object($result)) {           
          $pieces = explode(", " , $row-&gt;permission_perm);        
          $node_name = "edit any " . trim($node_type) . " content";
          if (in_array($node_name, $pieces )) 
          {
              return TRUE;        
          }
          return FALSE;
      }
  }
  </code></pre>