<?php

/**
 * @file
 */

function stormdok_help($path, $arg) {
  $o = '';

  switch ($path) {
    case "admin/help#stormdok":
      $o = '<p>'. t("Provides documents support for SuiteDesk") .'</p>';
      break;
  }

  return $o;
}

function stormdok_perm() {
  return array(
    'Storm dok: access',
    'Storm dok: add',
    'Storm dok: delete all',
    'Storm dok: delete own',
    'Storm dok: delete of user organization',
    'Storm dok: edit all',
    'Storm dok: edit own',
    'Storm dok: edit of user organization',
    'Storm dok: edit if assigned to project',
    'Storm dok: view all',
    'Storm dok: view own',
    'Storm dok: view of user organization',
    'Storm dok: view publics of user organization',
    'Storm dok: view if assigned to project',
    'Storm dok: view authorised if assigned to project',
  );
}

function stormdok_access($op, $node, $account = NULL) {
  if (empty($account)) {
    global $user;
    $account = $user;
  }

  if ($op == 'create') {
    return user_access('Storm dok: add');
  }

  if (is_numeric($node)) {
    $node = node_load($node);
  }

  if (!isset($account->stormorganization_nid) && module_exists('stormperson')) {
    _stormperson_user_load($account);
  }

  if ($op == 'delete') {
    if (user_access('Storm dok: delete all')) {
      return TRUE;
    }
    elseif (user_access('Storm dok: delete own') && ($account->uid == $node->uid)) {
      return TRUE;
    }
    elseif (user_access('Storm dok: delete of user organization') && ($account->stormorganization_nid == $node->organization_nid) && ($node->dok_access == 0)) {
      return TRUE;
    }
  }

  if ($op == 'update') {
    if (user_access('Storm dok: edit all')) {
      return TRUE;
    }
    elseif (user_access('Storm dok: edit own') && ($account->uid == $node->uid)) {
      return TRUE;
    }
    elseif (user_access('Storm dok: edit of user organization') && ($account->stormorganization_nid == $node->organization_nid) && ($node->dok_access == 0)) {
      return TRUE;
    }
    elseif (user_access('Storm dok: edit if assigned to project') && module_exists('stormteam') && ($node->dok_access == 0)) {
      $project = node_load($node->project_nid);
      if (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormperson_nid)) {
        return TRUE;
      }
      elseif (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormorganization_nid)) {
        return TRUE;
      }
    }
  }

  if ($op == 'view') {
    if (user_access('Storm dok: view all')) {
      return TRUE;
    }
    elseif (user_access('Storm dok: view own') && ($account->uid == $node->uid)) {
      return TRUE;
    }
    elseif (user_access('Storm dok: view of user organization') && ($account->stormorganization_nid == $node->organization_nid) && ($node->dok_access != 3)) {
      return TRUE;
    }
    elseif (user_access('Storm dok: view publics of user organization') && ($account->stormorganization_nid == $node->organization_nid) && ($node->dok_access == 1)) {
      return TRUE;
    }
    elseif (user_access('Storm dok: view if assigned to project') && module_exists('stormteam') && ($node->dok_access != 3)) {
      $project = node_load($node->project_nid);
      if (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormperson_nid)) {
        return TRUE;
      }
      elseif (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormorganization_nid)) {
        return TRUE;
      }
    }
    elseif (user_access('Storm dok: view authorised if assigned to project') && module_exists('stormteam') && ($node->dok_access == 2)) {
      $project = node_load($node->project_nid);
      if (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormperson_nid)) {
        return TRUE;
      }
      elseif (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormorganization_nid)) {
        return TRUE;
      }
    }
  }

  return FALSE;
}

function stormdok_access_sql($sql, $where = array()) {
  if (!user_access('Storm dok: view all')) {
    global $user;

    $cond = '';
    $join = array();
    if (user_access('Storm dok: view own')) {
      $cond .= 'n.uid = ' . $user->uid;
    }
    if (user_access('Storm dok: view of user organization')) {
      $cond .= !empty($cond) ? ' OR ' : '';
      $cond .= 'sdo.organization_nid = ' . $user->stormorganization_nid . ' AND sdo.dok_access != 3)';
    }
    if (user_access('Storm dok: view publics of user organization')) {
      $cond .= !empty($cond) ? ' OR ' : '';
      $cond .= '(sdo.organization_nid = ' . $user->stormorganization_nid . ' AND sdo.dok_access = 1)';
    }
    $user_access_authorised = user_access('Storm dok: view authorised if assigned to project');
    if (user_access('Storm dok: view if assigned to project') || $user_access_authorised) {
      $join[] = 'LEFT JOIN {node} npr ON npr.nid = sdo.project_nid';
      $join[] = 'LEFT JOIN {stormproject} spr ON spr.vid = npr.vid';

      $cond .= !empty($cond) ? ' OR ' : '';
      $cond .= '(sdo.dok_access';
      $cond .= $user_access_authorised ? ' = 2' : ' != 3';
      $cond .= ' AND (spr.assigned_nid = ' . $user->stormperson_nid;

      if (module_exists('stormteam')) {
        // Load teams that the account belongs to:
        $belonged_teams = stormteam_user_return_teams();
        // Allow access if any of those teams is the one in question:
        foreach ($belonged_teams as $belonged_team) {
          $cond .= ' OR spr.assigned_nid = ' . $belonged_team;
        }
      }

      $cond .= '))';
    }
    $where[] = empty($cond) ? '0 = 1' : $cond;
  }

  $where[] = "'storm_access' = 'storm_access'";
  return storm_rewrite_sql($sql, $where, $join);
}

function stormdok_storm_rewrite_where_sql($query, $primary_table, $account) {
  static $conds = array();

  if (isset($conds[$primary_table][$account->uid])) {
    return $conds[$primary_table][$account->uid];
  }

  $cond = '';
  if (!preg_match("/'storm_access' = 'storm_access'/", $query)) {
    if (user_access('Storm dok: view all', $account)) {
      return '';
    }
    $from = '{stormdok} sdo1';
    if (user_access('Storm dok: view own', $account)) {
      $cond .= "${primary_table}.uid = " . $account->uid;
    }
    if (user_access('Storm dok: view of user organization', $account)) {
      $cond .= !empty($cond) ? ' OR ' : '';
      # If function is called without viewing an organization, this variable
      # may not be set. These lines check for that and set the organization
      # node id to zero if not otherwise set.
      if (!isset($account->stormorganization_nid)) {
        $account->stormorganization_nid = 0;
      }
      $cond .= ' (sdo1.organization_nid = ' . $account->stormorganization_nid . ' AND sdo1.dok_access != 3)';
    }
    if (user_access('Storm dok: view publics of user organization', $account)) {
      $cond .= !empty($cond) ? ' OR ' : '';
      # If function is called without viewing an organization, this variable
      # may not be set. These lines check for that and set the organization
      # node id to zero if not otherwise set.
      if (!isset($account->stormorganization_nid)) {
        $account->stormorganization_nid = 0;
      }
      $cond .= ' (sdo1.organization_nid = ' . $account->stormorganization_nid . ' AND sdo1.dok_access = 1)';
    }
    $user_access_authorised = user_access('Storm dok: view authorised if assigned to project');
    if (user_access('Storm dok: view if assigned to project') || $user_access_authorised) {
      $from .= ' LEFT JOIN {node} npr1 ON npr1.nid = sdo1.project_nid LEFT JOIN {stormproject} spr1 ON spr1.vid = npr1.vid';
      $cond .= !empty($cond) ? ' OR ' : '';
      $cond .= '(sdo1.dok_access';
      $cond .= $user_access_authorised ? ' = 2' : ' != 3';
      $cond .= ' AND (spr1.assigned_nid = ' . $account->stormperson_nid;

      if (module_exists('stormteam')) {
        // Load teams that the account belongs to:
        $belonged_teams = stormteam_user_return_teams($account);
        // Allow access if any of those teams is the one in question:
        foreach ($belonged_teams as $belonged_team) {
          $cond .= ' OR spr1.assigned_nid = ' . $belonged_team;
        }
      }

      $cond .= '))';
    }
    if ($cond) {
      $cond = " WHEN 'stormdok' THEN (SELECT IF($cond, 1, 0) FROM ${from} WHERE sdo1.vid = ${primary_table}.vid) ";
    } else {
      $cond = " WHEN 'stormdok' THEN 0 ";
    }
  }
  $conds[$primary_table][$account->uid] = $cond;
  return $cond;
}

function stormdok_db_rewrite_sql($query, $primary_table, $primary_field, $args) {

  if (($primary_table == 't' || $primary_table == 'term_data') && $primary_field == 'tid' && !empty($args['view']) && $args['view']->name == 'storm_doks_tags') {

    if (preg_match("/'storm_access'='storm_access'/", $query)) {
      return array();
    }

    global $user;
    $conditions = array();
    $primary_table = 'node_term_node';
    $condition = stormdok_storm_rewrite_where_sql($query, $primary_table, $user);
    if ($condition) {
      $conditions[] = $condition;
    }

    $return = array();
    $where = '';
    if ($conditions) {
      switch ($GLOBALS['db_type']) {
        case 'mysql':
        case 'mysqli':
          $where  = '(';
          $where .= " CASE ${primary_table}.type ";
          foreach ($conditions as $condition) {
            $where .= $condition .' ';
          }
          $where .= ' ELSE 1 END ';
          $where .= ' )=1 ';
          $return['where'] = $where;
        break;
        case 'pgsql':
        break;
      }
    }
#   drupal_set_message(print_r($return, TRUE));
    return $return;
  }
}

function stormdok_menu() {
  $items = array();

  $items['doks'] = array(
    'title' => 'Documentation',
    'description' => 'SuiteDesk documents',
    'page callback' => 'stormdok_list',
    'access arguments' => array('Storm dok: access'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'stormdok.admin.inc',
    'weight' => 7,
  );

  return $items;
}

function stormdok_theme() {
  return array(
    'stormdok_list' => array(
      'file'      => 'stormdok.theme.inc',
      'arguments' => array('header', 'doks'),
    ),
    'stormdok_view' => array(
      'file'      => 'stormdok.theme.inc',
      'arguments' => array('node', 'teaser', 'page'),
    ),
  );
}

function stormdok_node_info() {
  return array(
    'stormdok' => array(
      'name' => t('Dok'),
      'module' => 'stormdok',
      'description' => t("A document for SuiteDesk."),
      'has_body' => TRUE,
    )
  );
}

function stormdok_content_extra_fields($type_name) {
  if ($type_name == 'stormdok') {
    return array(
      'group1' => array('label' => 'Organization/Project/Task Group', 'weight' => -20),
      'group2' => array('label' => 'Access Group', 'weight' => -19),
      'groupv' => array('label' => 'New revision', 'weight' => -18),
    );
  }
}

function stormdok_stormorganization_change($organization_nid, $organization_title) {
  $s = "UPDATE {stormdok} SET organization_title='%s' WHERE organization_nid=%d AND organization_title <> '%s'";
  db_query($s, $organization_title, $organization_nid, $organization_title);
}

function stormdok_stormproject_change($project_nid, $project_title) {
  $s = "UPDATE {stormdok} SET project_title='%s' WHERE project_nid=%d AND project_title <> '%s'";
  db_query($s, $project_title, $project_nid, $project_title);
}

function stormdok_stormtask_change($task_nid, $task_title, $task_stepno) {
  $s = "UPDATE {stormdok} SET task_title='%s' WHERE task_nid=%d AND task_title<>'%s'";
  db_query($s, $task_title, $task_nid, $task_title);
}

function stormdok_stormproject_change_hierarchy($project_nid, $organization_nid, $organization_title) {
  $s = "UPDATE {stormdok} SET organization_nid=%d, organization_title='%s' WHERE project_nid=%d";
  db_query($s, $organization_nid, $organization_title, $project_nid);
}

function stormdok_stormtask_change_hierarchy($task_nid, $organization_nid, $organization_title, $project_nid, $project_title) {
  $s = "UPDATE {stormdok} SET organization_nid=%d, organization_title='%s', project_nid=%d, project_title='%s' WHERE task_nid=%d";
  db_query($s, $organization_nid, $organization_title, $project_nid, $project_title, $task_nid);
}

function stormdok_form(&$node) {
  $breadcrumb = array();
  $breadcrumb[] = l(t('SuiteDesk'), 'dashboard');
  $breadcrumb[] = l(t('Documentation'), 'doks');
  drupal_set_breadcrumb($breadcrumb);

  if (arg(1)=='add') {
    if (array_key_exists('organization_nid', $_GET) && !$node->organization_nid) {
      $node->organization_nid = $_GET['organization_nid'];
    }
    if (array_key_exists('project_nid', $_GET) && !$node->project_nid) {
      $node->project_nid = $_GET['project_nid'];
      $p = node_load($node->project_nid);
      $node->organization_nid = $p->organization_nid;
      if (!stormorganization_access('view', $node->organization_nid)) {
        drupal_set_message(t("You cannot add a document for this project, as you do not have access to view the organization's profile"));
        drupal_goto('node/'. $node->project_nid);
      }
    }
    if (array_key_exists('task_nid', $_GET) && !$node->task_nid) {
      $node->task_nid = $_GET['task_nid'];
      $t = node_load($node->task_nid);
      $node->organization_nid = $t->organization_nid;
      $node->project_nid = $t->project_nid;
      // $project_access deals with the case whereby the project could be blank, hence access rules not required
      $project_access = $node->project_nid ? stormproject_access('view', $node->project_nid) : TRUE;
      if (!stormorganization_access('view', $node->organization_nid) || !stormproject_access('view', $node->project_nid)) {
        drupal_set_message(t("You cannot add a document for this task, as you do not have access to view the both the organization and project's profile"));
        drupal_goto('node/'. $node->task_nid);
      }
    }

    if (!empty($_SESSION['stormdok_list_filter']['organization_nid']) && !$node->organization_nid) {
      $node->organization_nid = $_SESSION['stormdok_list_filter']['organization_nid'];
    }
    if (!empty($_SESSION['stormdok_list_filter']['project_nid']) && !$node->project_nid) {
      $node->project_nid = $_SESSION['stormdok_list_filter']['project_nid'];
    }
    if (!empty($_SESSION['stormdok_list_filter']['task_nid']) && !$node->task_nid) {
      $node->task_nid = $_SESSION['stormdok_list_filter']['task_nid'];
    }
    $s_org = "SELECT n.nid, n.title FROM {stormorganization} so INNER JOIN {node} n
              ON so.nid=n.nid WHERE n.status=1 AND so.isactive=1 AND n.type='stormorganization' ORDER BY n.title";
  }
  else {
    $s_org = "SELECT n.nid, n.title FROM {stormorganization} so INNER JOIN {node} n
              ON so.nid=n.nid WHERE n.status=1 AND n.type='stormorganization' ORDER BY n.title";
  }

  $type = node_get_types('type', $node);

  $form['group1'] = array(
    '#type' => 'markup',
    '#theme' => 'storm_form_group',
    '#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group1') : -20,
  );

  $s_org = stormorganization_access_sql($s_org);
  $s_org = db_rewrite_sql($s_org);
  $r = db_query($s_org);
  $organizations = array();
  while ($organization = db_fetch_object($r)) {
    $organizations[$organization->nid] = $organization->title;
/*  if (!isset($node->organization_nid)) {
      $node->organization_nid = $organization->nid;
    } */
  }
  $form['group1']['organization_nid'] = array(
    '#type' => 'select',
    '#title' => t('Organization'),
    '#default_value' => $node->organization_nid,
    '#options' => array(0 => '-') + $organizations,
    '#attributes' => array('onchange' => "stormtask_organization_project_tasks(this, 'edit-project-nid', 'edit-parent-nid', '', true, '-')"),
  );

  $s = "SELECT n.nid, n.title FROM {node} n INNER JOIN {stormproject} spr ON spr.vid=n.vid WHERE spr.organization_nid=%d AND n.status=1 AND n.type='stormproject' ORDER BY n.title";
  $s = stormproject_access_sql($s);
  $s = db_rewrite_sql($s);
  $r = db_query($s, $node->organization_nid);
  $projects = array();
  while ($project = db_fetch_object($r)) {
    $projects[$project->nid] = $project->title;
  }
  $form['group1']['project_nid'] = array(
    '#type' => 'select',
    '#title' => t('Project'),
    '#default_value' => isset($node->project_nid) ? $node->project_nid : NULL,
    '#options' => array(0 => '-') + $projects,
    '#process' => array('storm_dependent_select_process'),
    '#attributes' => array('onchange' => "stormtask_project_tasks('edit-organization-nid', this, 'edit-task-nid', '', true, '-')"),
  );

  $tree = isset($node->project_nid) ? _stormtask_get_tree($node->project_nid) : array();
  $tasks = _stormtask_plain_tree($tree);
  $form['group1']['task_nid'] = array(
    '#type' => 'select',
    '#title' => t('Task'),
    '#default_value' => isset($node->task_nid) ? $node->task_nid : NULL,
    '#options' => array(0 => '-') + $tasks,
    '#process' => array('storm_dependent_select_process'),
  );

  $form['group2'] = array(
    '#type' => 'markup',
    '#theme' => 'storm_form_group',
    '#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group2') : -19,
    '#attributes' => array('class' => 'formgroup_access'),
  );

  $dok_access = array();
  $dok_access[1] = '<strong>' . t('Public') . '</strong><div class="description">' . t('Visible for all users of organization. Organization required.') . '</div>';
  $dok_access[0] = '<strong>' . t('Default access') . '</strong><div class="description">' . t('Visible and editable for staff assigned to project. Project required.') . '</div>';
  $dok_access[2] = '<strong>' . t('Authorised') . '</strong><div class="description">' . t('Visible for all users assigned to project. Project required.') . '</div>';
  $dok_access[3] = '<strong>' . t('Private') . '</strong><div class="description">' . t('For my eyes only and Administrators.') . '</div>';
  $form['group2']['dok_access'] = array(
    '#type' => 'radios',
    '#default_value' => isset($node->dok_access) ? $node->dok_access : 0,
    '#required' => TRUE,
    '#options' => $dok_access,
    '#weight' => 1,
  );

  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'title') : -16,
  );

  $form['groupv'] = array(
    '#type' => 'markup',
    '#title' => t('New review'),
    '#theme' => 'storm_form_group',
    '#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'groupv') : -12,
  );

  $options = array();
  $options['no review'] = t('Don\'t create any revision (change the current)');
  $options['minor review'] = t('Create a new review due to a minor modification');
  $options['major review'] = t('Create a new version by a major modification');
  $form['groupv']['review'] = array(
    '#type' => 'radios',
    '#options' => $options,
    '#default_value' => 'no review',
  );

  $form['groupv']['reviewlog'] = array(
    '#title' => t('Log message'),
    '#type' => 'textfield',
    '#size' => 255,
    '#default_value' => NULL,
  );

  if ($type->has_body) {
    $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
  }

  return $form;
}

function stormdok_insert($node) {
  _stormdok_beforesave($node);
  db_query("INSERT INTO {stormdok}
           (vid, nid,
           organization_nid, organization_title,
           project_nid, project_title,
           task_nid, task_title,
           version, dok_access
           ) VALUES
           (%d, %d,
           %d, '%s',
           %d, '%s',
           %d, '%s',
           '%s', %d
           )",
            $node->vid, $node->nid,
            $node->organization_nid, $node->organization_title,
            $node->project_nid, $node->project_title,
            $node->task_nid, $node->task_title,
            $node->version, $node->dok_access
            );
}

function stormdok_update($node) {
  // if this is a new node or we're adding a new revision,
  if ($node->revision) {
    stormdok_insert($node);
  } else {
    _stormdok_beforesave($node);
    db_query("UPDATE {stormdok} SET
            organization_nid=%d, organization_title='%s',
            project_nid=%d, project_title='%s',
            task_nid=%d, task_title='%s',
            version='%s', dok_access=%d
            WHERE vid = %d",
            $node->organization_nid, $node->organization_title,
            $node->project_nid, $node->project_title,
            $node->task_nid, $node->task_title,
            $node->version, $node->dok_access,
            $node->vid);
  }
}

function _stormdok_beforesave(&$node) {
  $s = "SELECT n.title FROM {node} n INNER JOIN {stormorganization} o ON n.nid=o.nid
        WHERE type='stormorganization' AND n.nid=%d";
  $r = db_query($s, $node->organization_nid);
  $o = db_fetch_object($r);
  $node->organization_title = $o->title;

  $s = "SELECT n.title FROM {node} n INNER JOIN {stormproject} p ON n.nid=p.nid
        WHERE type='stormproject' AND n.nid=%d";
  $r = db_query($s, $node->project_nid);
  $p = db_fetch_object($r);
  $node->project_title = isset($p->title) ? $p->title : '';

  $s = "SELECT n.title FROM {node} n INNER JOIN {stormtask} p ON n.nid=p.nid
        WHERE type='stormtask' AND n.nid=%d";
  $r = db_query($s, $node->task_nid);
  $t = db_fetch_object($r);
  $node->task_title = isset($t->title) ? $t->title : '';
}

function stormdok_nodeapi(&$node, $op, $teaser, $page) {
  if ($node->type != 'stormdok') {
    return;
  }

  // Suffix for public (U+00B0), authorised (U+207B) and private (U+00AA) nodes:
  $dok_suffix = array(1 => '°', 2 => 'ª', 3 => '⁻');

  switch ($op) {
    case 'prepare':
      $pos_suffix = strpos($node->title, $dok_suffix[$node->dok_access]);
      if ($node->dok_access >= 1 && $node->dok_access <= 3 && $pos_suffix) {
        $node->title = substr($node->title, 0, $pos_suffix);
      }
      break;

    case 'validate';
      if ($node->dok_access == 0 && empty($node->project_nid)) {
        $field_nid = empty($node->organization_nid) ? 'organization_nid' : 'project_nid';
        $field_msg = empty($node->organization_nid) ? 'Organization and Project' : 'Project';
        form_set_error($field_nid, t($field_msg . ' required in default access for staff assigned to the project.'));
      }
      if ($node->dok_access == 1 && empty($node->organization_nid)) {
        form_set_error('organization_nid', t('Organization required in public view for all users of the organization.'));
      }
      if ($node->dok_access == 2 && empty($node->project_nid)) {
        $field_nid = empty($node->organization_nid) ? 'organization_nid' : 'project_nid';
        $field_msg = empty($node->organization_nid) ? 'Organization and Project' : 'Project';
        form_set_error($field_nid, t($field_msg . ' required in authorised view for all users assigned to the project.'));
      }
      break;

    case 'presave':
      if ($node->dok_access >= 1 && $node->dok_access <= 3 && !strpos($node->title, $dok_suffix[$node->dok_access])) {
        $node->title .= $dok_suffix[$node->dok_access];
      }
      break;

    case 'view':
      $bid = $node->book['bid'];
      $project_nid = $node->project_nid;
      if (!empty($bid) && !empty($project_nid) && $page && !storm_cron_is_running()) {
        $rootbook = node_load($bid);
        if ($rootbook->type == 'stormproject' && $bid != $project_nid) {
          drupal_set_message(t('Warning! The visibility of this document depends on a project that does not match the root project of this book.'), 'error');
        }
      }
      break;

    case 'delete revision':
      // Notice that we're matching a single revision based on the node's vid.
      db_query('DELETE FROM {stormdok} WHERE vid = %d', $node->vid);
      break;
  }
}

function stormdok_delete($node) {
  db_query('DELETE FROM {stormdok} WHERE nid = %d', $node->nid);
}

function stormdok_load($node) {
  $additions = db_fetch_object(db_query('SELECT * FROM {stormdok} WHERE vid = %d', $node->vid));
  return $additions;
}

function stormdok_view($node, $teaser = FALSE, $page = FALSE) {
  $breadcrumb = array();
  $breadcrumb[] = l(t('SuiteDesk'), 'dashboard');
  $breadcrumb[] = l(t('Documentation'), 'doks');
  drupal_set_breadcrumb($breadcrumb);

  return theme('stormdok_view', $node, $teaser, $page);
}

function stormdok_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'stormdok'),
  );
}

function stormdok_storm_dashboard_links($type) {
  $links = array();
  if ($type == 'page' || $type == 'block') {
    $links[] = array(
      'theme' => 'storm_dashboard_link',
      'title' => t('Documentation'),
      'icon' => 'stormdok-item',
      'path' => 'doks',
      'params' => array(),
      'access_arguments' => 'Storm dok: access',
      'node_type' => 'stormdok',
      'add_type' => 'stormdok',
      'map' => array(),
      'weight' => 9,
    );
  }
  return $links;
}
