'. t("Provides task support for Storm") .'
'; break; } return $o; } function stormtask_perm() { return array( 'Storm task: access', 'Storm task: add', 'Storm task: delete all', 'Storm task: delete own', 'Storm task: delete of user organization', 'Storm task: edit all', 'Storm task: edit own', 'Storm task: edit of user organization', 'Storm task: view all', 'Storm task: view own', 'Storm task: view of user organization', ); } function stormtask_init() { if (function_exists('drupal_set_content')) { $settings = array( 'storm' => array( 'project_tasks_url' => url('storm/project_tasks_js/') ), ); drupal_add_js($settings, 'setting'); drupal_add_js(drupal_get_path('module', 'stormtask') .'/stormtask.js', 'module', 'header', FALSE); } } function stormtask_access($op, $node) { global $user; $account = $user; if (is_numeric($node)) $node = node_load($node); if ($op == 'create') { return user_access('Storm task: add'); } if ($op == 'delete') { if (user_access('Storm task: delete all')) { return TRUE; } else if (user_access('Storm task: delete own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm task: delete of user organization') && ($account->stormorganization_nid == $node->organization_nid)) { return TRUE; } } if ($op == 'update') { if (user_access('Storm task: edit all')) { return TRUE; } else if (user_access('Storm task: edit own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm task: edit of user organization') && ($account->stormorganization_nid == $node->organization_nid)) { return TRUE; } } if ($op == 'view') { if (user_access('Storm task: view all')) { return TRUE; } else if (user_access('Storm task: view own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm task: view of user organization') && ($account->stormorganization_nid == $node->organization_nid)) { return TRUE; } } return FALSE; } function stormtask_access_sql($sql, $where = array()) { if (user_access('Storm task: view all')) { $where[] = "'storm_access'='storm_access'"; return storm_rewrite_sql($sql, $where); } global $user; $cond = ''; if (user_access('Storm task: view own')) { $cond .= 'n.uid='. $user->uid; } if (user_access('Storm task: view of user organization')) { if (!empty($cond)) $cond .= ' OR '; $cond .= 'sta.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 stormtask_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 task: view all', $account)) { return ''; } $cond = ''; if (user_access('Storm task: view own', $account)) { $cond .= " ${primary_table}.uid=". $account->uid; } if (user_access('Storm task: view of user organization', $account)) { if ($cond) $cond .= ' OR '; $cond .= ' sta1.organization_nid='. $account->stormorganization_nid; } if ($cond) { $cond = " WHEN 'stormtask' THEN (SELECT IF($cond,1,0) FROM {stormtask} sta1 WHERE sta1.vid=${primary_table}.vid) "; } else { $cond = " WHEN 'stormtask' THEN 0 "; } } $conds[$account->uid] = $cond; return $cond; } function stormtask_menu($may_cache) { $items = array(); if (!$may_cache) { if ((arg(0)=='storm' && arg(1)=='tasks') || (arg(0)=='node' && arg(2)=='tasks')) { require_once(drupal_get_path('module', 'stormtask') .'/stormtask.admin.inc'); require_once(drupal_get_path('module', 'stormtask') .'/stormtask.theme.inc'); } $items[] = array( 'path' => 'storm/tasks', 'title' => t('Tasks'), 'description' => t('Storm Tasks'), 'callback' => 'stormtask_list', 'access' => user_access('Storm task: access'), 'type' => MENU_NORMAL_ITEM ); $items[] = array( 'path' => 'storm/project_tasks_js', 'title' => t('Tasks'), 'callback' => '_stormtask_project_tasks_js', 'callback arguments' => array(arg(2)), 'access' => user_access('Storm task: access'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'node/'. arg(1) .'/tasks', 'title' => t('Tasks'), 'callback' => 'stormtask_tasks', 'callback arguments' => array(arg(1)), 'access' => _stormtask_tasks_access(arg(1)), 'type' => MENU_LOCAL_TASK, 'weight' => 3 ); } return $items; } function stormtask_node_info() { return array( 'stormtask' => array( 'name' => t('Task'), 'module' => 'stormtask', 'description' => t("A task for Storm."), 'title_label' => t("Title"), 'body_label' => t("Description"), ) ); } function stormtask_storm_indexpage() { $o = array(); $o['stormtask']['title'] = l(t('Tasks'), 'storm/tasks'); return $o; } function stormtask_stormorganization_change($organization_nid, $organization_title) { $s = "UPDATE {stormtask} SET organization_title='%s' WHERE organization_nid=%d AND organization_title <> '%s'"; db_query($s, $organization_title, $organization_nid, $organization_title); } function stormtask_stormproject_change($project_nid, $project_title) { $s = "UPDATE {stormtask} SET project_title='%s' WHERE project_nid=%d AND project_title <> '%s'"; db_query($s, $project_title, $project_nid, $project_title); } function stormtask_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 ($_SESSION['stormtask_list_filter']['organization_nid'] && !$node->organization_nid) { $node->organization_nid = $_SESSION['stormtask_list_filter']['organization_nid']; } if ($_SESSION['stormtask_list_filter']['project_nid'] && !$node->project_nid) { $node->project_nid = $_SESSION['stormtask_list_filter']['project_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} AS n INNER JOIN {stormorganization} AS 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; if (!$node->organization_nid) $node->organization_nid = $organization->nid; } $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', false, '')"), ); $s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormproject} AS spr ON spr.vid=n.vid WHERE n.status=1 AND spr.organization_nid=%d 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; if (!$node->project_nid) $node->project_nid = $project->nid; } $form['group1']['project_nid'] = array( '#type' => 'select', '#title' => t('Project'), '#default_value' => $node->project_nid, '#options' => $projects, '#process' => array('storm_dependent_select_process' => array()), '#required' => true, '#attributes' => array('onchange' => "stormtask_project_tasks(this, 'edit-parent-nid', true, '-')"), ); $tree = _stormtask_get_tree($node->project_nid); $parent_tasks = _stormtask_plain_tree($tree); $form['group1']['parent_nid'] = array( '#type' => 'select', '#title' => t('Parent task'), '#default_value' => $node->parent_nid, '#options' => array(0 => '-') + $parent_tasks, '#process' => array('storm_dependent_select_process' => array()), ); $form['group1']['weight'] = array( '#type' => 'weight', '#title' => t('Weight'), '#default_value' => $node->weight, ); $form['group2'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -49, ); $form['group2']['stepno'] = array( '#type' => 'textfield', '#title' => t('Step no.'), '#size' => 15, '#required' => FALSE, '#default_value' => $node->stepno, ); $form['group2']['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, ); $form['group3'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -48, ); $form['group3']['taskcategory'] = array( '#type' => 'select', '#title' => t('Category'), '#default_value' => $node->taskcategory, '#options' => stormattribute_attributes_bydomain('Task category'), ); $form['group3']['taskstatus'] = array( '#type' => 'select', '#title' => t('Status'), '#default_value' => $node->taskstatus, '#options' => stormattribute_attributes_bydomain('Task status'), ); $form['group3']['taskpriority'] = array( '#type' => 'select', '#title' => t('Priority'), '#default_value' => $node->taskpriority, '#options' => stormattribute_attributes_bydomain('Task priority'), ); if ($type->has_body) { $form['body_filter']['#weight'] = -47; $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); } $form['stepno_old'] = array( '#type' => 'hidden', '#default_value' => $node->stepno_old, ); $form['title_old'] = array( '#type' => 'hidden', '#default_value' => $node->title_old, ); return $form; } function stormtask_insert($node) { _stormtask_beforesave($node); db_query("INSERT INTO {stormtask} (vid, nid, stepno, taskcategory, taskstatus, taskpriority, organization_nid, organization_title, project_nid, project_title, parent_nid, weight) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d, '%s', %d, '%s', %d, %d)", $node->vid, $node->nid, $node->stepno, $node->taskcategory, $node->taskstatus, $node->taskpriority, $node->organization_nid, $node->organization_title, $node->project_nid, $node->project_title, $node->parent_nid, $node->weight); } function stormtask_update($node) { // if this is a new node or we're adding a new revision, if ($node->revision) { stormtask_insert($node); } else { _stormtask_beforesave($node); db_query("UPDATE {stormtask} SET stepno='%s', taskcategory='%s', taskstatus='%s', taskpriority='%s', organization_nid=%d, organization_title='%s', project_nid=%d, project_title='%s', parent_nid=%d, weight=%d WHERE vid = %d", $node->stepno, $node->taskcategory, $node->taskstatus, $node->taskpriority, $node->organization_nid, $node->organization_title, $node->project_nid, $node->project_title, $node->parent_nid, $node->weight, $node->vid); if (($node->title != $node->title_old) || ($node->stepno != $node->stepno_old)) { module_invoke_all('stormtask_change', $node->nid, $node->stepno, $node->title); } } } function _stormtask_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, p.organization_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; } function stormtask_delete($node) { // Notice that we're matching all revision, by using the node's nid. db_query('DELETE FROM {stormtask} WHERE nid = %d', $node->nid); } function stormtask_load($node) { $additions = db_fetch_object(db_query('SELECT * FROM {stormtask} WHERE vid = %d', $node->vid)); $additions->stepno_old = $node->stepno; $additions->title_old = $node->title; return $additions; } function stormtask_validate(&$node) { if (($node->nid == $node->parent_nid) && $node->parent_nid) { form_set_error('parent_nid', t('Impossible to assign itself as parent.')); } } function stormtask_view($node, $teaser = FALSE, $page = FALSE) { $node = node_prepare($node, $teaser); $project = node_load($node->project_nid); $node->content['project'] = array( '#value' => t('Project') .' : '. l($project->title, 'node/'. $project->nid) .'