'. t("Provides note support for Storm") .'

'; break; } return $o; } function stormnote_perm() { return array( 'Storm note: access', 'Storm note: add', 'Storm note: delete all', 'Storm note: delete own', 'Storm note: delete of user organization', 'Storm note: edit all', 'Storm note: edit own', 'Storm note: edit of user organization', 'Storm note: view all', 'Storm note: view own', 'Storm note: view of user organization', ); } function stormnote_access($op, $node) { global $user; $account = $user; if ($op == 'create') { return user_access('Storm note: add'); } if (is_numeric($node)) $node = node_load($node); if ($op == 'delete') { if (user_access('Storm note: delete all')) { return TRUE; } else if (user_access('Storm note: delete own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm note: delete of user organization') && ($account->stormorganization_nid == $node->organization_nid)) { return TRUE; } } if ($op == 'update') { if (user_access('Storm note: edit all')) { return TRUE; } else if (user_access('Storm note: edit own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm note: edit of user organization') && ($account->stormorganization_nid == $node->organization_nid)) { return TRUE; } } if ($op == 'view') { if (user_access('Storm note: view all')) { return TRUE; } else if (user_access('Storm note: view own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm note: view of user organization') && ($account->stormorganization_nid == $node->organization_nid)) { return TRUE; } } return FALSE; } function stormnote_access_sql($sql, $where = array()) { if (user_access('Storm note: view all')) { $where[] = "'storm_access'='storm_access'"; return storm_rewrite_sql($sql, $where); } global $user; $cond = ''; if (user_access('Storm note: view own')) { $cond .= 'n.uid='. $user->uid; } if (user_access('Storm note: view of user organization')) { if (!empty($cond)) $cond .= ' OR '; $cond .= 'sno.organization_nid='. $user->stormorganization_nid; } if (empty($cond)) $cond = '0=1'; $where[] = $cond; $where[] = "'storm_access'='storm_access'"; return storm_rewrite_sql($sql, $where); } function stormnote_storm_rewrite_where_sql($query, $primary_table, $account) { static $conds = array(); if ($conds[$account->uid]) { return $conds[$account->uid]; } if (preg_match("/'storm_access'='storm_access'/", $query)) { $cond = ''; } else { if (user_access('Storm note: view all', $account)) { return ''; } $cond = ''; if (user_access('Storm note: view own', $account)) { $cond .= "${primary_table}.uid=". $account->uid; } if (user_access('Storm note: view of user organization', $account)) { if ($cond) $cond .= ' OR '; $cond .= ' sno1.organization_nid='. $account->stormorganization_nid; } if ($cond) { $cond = " WHEN 'stormnote' THEN (SELECT IF($cond,1,0) FROM {stormnote} sno1 WHERE sno1.vid=${primary_table}.vid) "; } else { $cond = " WHEN 'stormnote' THEN 0 "; } } $conds[$account->uid] = $cond; return $cond; } function stormnote_menu($may_cache) { $items = array(); if (!$may_cache) { if (arg(0)=='storm' && arg(1)=='notes') { require_once(drupal_get_path('module', 'stormnote') .'/stormnote.theme.inc'); require_once(drupal_get_path('module', 'stormnote') .'/stormnote.admin.inc'); } $items[] = array( 'path' => 'storm/notes', 'title' => t('Notes'), 'description' => t('Storm notes'), 'callback' => 'stormnote_list', 'access' => user_access('Storm note: access'), 'type' => MENU_NORMAL_ITEM, ); } return $items; } function stormnote_node_info() { return array( 'stormnote' => array( 'name' => t('Note'), 'module' => 'stormnote', 'description' => t("A note for Storm."), 'has_body' => true, ) ); } function stormnote_stormorganization_change($organization_nid, $organization_title) { $s = "UPDATE {stormnote} SET organization_title='%s' WHERE organization_nid=%d AND organization_title <> '%s'"; db_query($s, $organization_title, $organization_nid, $organization_title); } function stormnote_stormproject_change($project_nid, $project_title) { $s = "UPDATE {stormnote} SET project_title='%s' WHERE project_nid=%d AND project_title <> '%s'"; db_query($s, $project_title, $project_nid, $project_title); } function stormnote_stormtask_change($task_nid, $task_title, $task_stepno) { $s = "UPDATE {stormnote} SET task_title='%s', task_stepno='%s' WHERE task_nid=%d AND (task_title<>'%s' OR task_stepno<>'%s')"; db_query($s, $task_title, $task_stepno, $task_nid, $task_title, $task_stepno); } function stormnote_form(&$node) { 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 (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; } if ($_SESSION['stormnote_list_filter']['organization_nid'] && !$node->organization_nid) { $node->organization_nid = $_SESSION['stormnote_list_filter']['organization_nid']; } if ($_SESSION['stormnote_list_filter']['project_nid'] && !$node->project_nid) { $node->project_nid = $_SESSION['stormnote_list_filter']['project_nid']; } if ($_SESSION['stormnote_list_filter']['task_nid'] && !$node->task_nid) { $node->task_nid = $_SESSION['stormnote_list_filter']['task_nid']; } } $type = node_get_types('type', $node); $form['group1'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -50, ); $s = "SELECT n.nid, n.title FROM {node} n INNER JOIN {stormorganization} sor ON sor.vid=n.vid WHERE n.status=1 AND n.type='stormorganization' ORDER BY n.title"; $s = stormorganization_access_sql($s); $s = db_rewrite_sql($s); $r = db_query($s); $organizations = array(); while ($organization = db_fetch_object($r)) { $organizations[$organization->nid] = $organization->title; } $form['group1']['organization_nid'] = array( '#type' => 'select', '#title' => t('Organization'), '#default_value' => $node->organization_nid, '#options' => $organizations, '#required' => true, '#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); $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' => $node->project_nid, '#options' => array(0 => '-') + $projects, '#process' => array('storm_dependent_select_process' => array()), '#required' => true, '#attributes' => array('onchange' => "stormtask_project_tasks(this, 'edit-task-nid', true, '-')"), ); $tree = _stormtask_get_tree($node->project_nid); $tasks = _stormtask_plain_tree($tree); $form['group1']['task_nid'] = array( '#type' => 'select', '#title' => t('Task'), '#default_value' => $node->task_nid, '#options' => array(0 => '-') + $tasks, '#process' => array('storm_dependent_select_process' => array()), ); $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -49, ); if ($type->has_body) { $form['body_filter']['#weight'] = -48; $form['body_filter']['body'] = array( '#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => ($type->min_word_count > 0)); $form['body_filter']['format'] = filter_form($node->format); } return $form; } function stormnote_insert($node) { _stormnote_beforesave($node); db_query("INSERT INTO {stormnote} (vid, nid, organization_nid, organization_title, project_nid, project_title, task_nid, task_title, task_stepno ) VALUES (%d, %d, %d, '%s', %d, '%s', %d, '%s', '%s' )", $node->vid, $node->nid, $node->organization_nid, $node->organization_title, $node->project_nid, $node->project_title, $node->task_nid, $node->task_title, $node->task_stepno ); } function stormnote_update($node) { _stormnote_beforesave($node); db_query("UPDATE {stormnote} SET organization_nid=%d, organization_title='%s', project_nid=%d, project_title='%s', task_nid=%d, task_title='%s', task_stepno='%s' WHERE vid = %d", $node->organization_nid, $node->organization_title, $node->project_nid, $node->project_title, $node->task_nid, $node->task_title, $node->task_stepno, $node->vid); } function _stormnote_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 = $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 = $t->title; } function stormnote_delete($node) { db_query('DELETE FROM {stormnote} WHERE nid = %d', $node->nid); } function stormnote_load($node) { $additions = db_fetch_object(db_query('SELECT * FROM {stormnote} WHERE vid = %d', $node->vid)); return $additions; } function stormnote_view($node, $teaser = FALSE, $page = FALSE) { $node = node_prepare($node, $teaser); $node->content['stormnote'] = array( '#value' => theme('stormnote_view', $node, $teaser = FALSE, $page = FALSE), '#weight' => 1, ); return $node; }