You are here

function webfm_dbinsert_attach in Web File Manager 5.2

Same name and namespace in other branches
  1. 5 webfm.module \webfm_dbinsert_attach()

webfm_dbinsert_attach - inserts nid, fid and weight to webfm_attach table (similar to files table)

Parameters

int $nid - node id:

int $fid - file id from the webfm_file table:

int $weight - weight value:

Return value

bool - TRUE if success - else FALSE

2 calls to webfm_dbinsert_attach()
webfm_dbupdate_attach in ./webfm.module
webfm_dbupdate_attach - updates the files in the webfm_attach table IF the order
webfm_nodeapi in ./webfm.module
Implementation of hook_nodeapi().

File

./webfm.module, line 2208

Code

function webfm_dbinsert_attach($nid, $fid, $weight) {
  $query = 'SELECT * FROM {webfm_attach} WHERE nid = %d AND fid = %d';
  $result = db_query($query, $nid, $fid);
  if (db_num_rows($result) !== 0) {
    drupal_set_message(t('File is already attached to this node.'));
    return FALSE;
  }
  else {

    //actually do the attachment if its not already attached....
    $query = 'INSERT INTO {webfm_attach} (nid, fid, weight) VALUES (%d, %d, %d)';
    $result = db_query($query, $nid, $fid, $weight);
    if ($result === FALSE) {
      drupal_set_message(t('Query Failed:  Could not attach files to node ') . $nid);
      return FALSE;
    }
    else {
      return TRUE;
    }
  }
}