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

'; break; } return $o; } function stormproject_init() { // ensure we are not serving a cached page if (function_exists('drupal_set_content')) { $settings = array( 'storm' => array( 'organization_projects_url' => url('storm/organization_projects_js/') ), ); drupal_add_js($settings, 'setting'); drupal_add_js(drupal_get_path('module', 'storm') .'/storm.js', 'module', 'header', FALSE); drupal_add_js(drupal_get_path('module', 'stormproject') .'/stormproject.js', 'module', 'header', FALSE); } } function stormproject_perm() { return array( 'Storm project: access', 'Storm project: add', 'Storm project: delete all', 'Storm project: delete own', 'Storm project: delete of user organization', 'Storm project: edit all', 'Storm project: edit own', 'Storm project: edit of user organization', 'Storm project: view all', 'Storm project: view own', 'Storm project: view of user organization', ); } function stormproject_access($op, $node) { global $user; $account = $user; if (is_numeric($node)) $node = node_load($node); if ($op == 'create') { return user_access('Storm project: add'); } if ($op == 'delete') { if (user_access('Storm project: delete all')) { return TRUE; } else if (user_access('Storm project: delete own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm project: delete of user organization') && ($account->stormorganization_nid == $node->organization_nid)) { return TRUE; } } if ($op == 'update') { if (user_access('Storm project: edit all')) { return TRUE; } else if (user_access('Storm project: edit own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm project: edit of user organization') && ($account->stormorganization_nid == $node->organization_nid)) { return TRUE; } } if ($op == 'view') { if (user_access('Storm project: view all')) { return TRUE; } else if (user_access('Storm project: view own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm project: view of user organization') && ($account->stormorganization_nid == $node->organization_nid)) { return TRUE; } } return FALSE; } function stormproject_access_sql($sql, $where = array()) { if (user_access('Storm project: view all')) { $where[] = "'storm_access'='storm_access'"; return storm_rewrite_sql($sql, $where); } global $user; $cond = ''; if (user_access('Storm project: view own')) { $cond .= 'n.uid='. $user->uid; } if (user_access('Storm project: view of user organization')) { if (!empty($cond)) $cond .= ' OR '; $cond .= 'spr.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 stormproject_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 organization: view all', $account)) { return ''; } $cond = ''; if (user_access('Storm project: view own', $account)) { $cond .= " ${primary_table}.uid=". $account->uid; } if (user_access('Storm project: view of user organization', $account)) { if ($cond) $cond .= ' OR '; $cond .= ' spr1.organization_nid='. $account->stormorganization_nid; } if ($cond) { $cond = " WHEN 'stormproject' THEN (SELECT IF($cond,1,0) FROM {stormproject} spr1 WHERE spr1.vid=${primary_table}.vid) "; } else { $cond = " WHEN 'stormproject' THEN 0 "; } } $conds[$account->uid] = $cond; return $cond; } function stormproject_menu($may_cache) { $items = array(); if (!$may_cache) { if (arg(0)=='storm' && arg(1)=='projects') { require_once(drupal_get_path('module', 'stormproject') .'/stormproject.admin.inc'); require_once(drupal_get_path('module', 'stormproject') .'/stormproject.theme.inc'); } $items[] = array( 'path' => 'storm/projects', 'title' => t('Projects'), 'description' => t('Storm Projects'), 'callback' => 'stormproject_list', 'access' => user_access('Storm project: access'), 'type' => MENU_NORMAL_ITEM ); $items[] = array( 'path' => 'storm/organization_projects_js', 'title' => t('Projects'), 'callback' => '_stormproject_organization_projects_js', 'callback arguments' => array(arg(2)), 'access' => user_access('Storm project: access'), 'type' => MENU_CALLBACK, ); } return $items; } function stormproject_node_info() { return array( 'stormproject' => array( 'name' => t('Project'), 'module' => 'stormproject', 'description' => t("A project for Storm."), 'title_label' => t("Title"), 'body_label' => t("Description"), ) ); } function stormproject_storm_indexpage() { $o = array(); if (user_access('Storm project: access')) { $o['stormproject']['title'] = l(t('Projects'), 'storm/projects'); } return $o; } function stormproject_stormorganization_change($organization_nid, $organization_title) { $s = "UPDATE {stormproject} SET organization_title='%s' WHERE organization_nid=%d AND organization_title <> '%s'"; db_query($s, $organization_title, $organization_nid, $organization_title); } function stormproject_form(&$node) { if (arg(1)=='add') { if (array_key_exists('organization_nid', $_GET) && !$node->organization) { $node->organization_nid = $_GET['organization_nid']; } if ($_SESSION['stormproject_list_filter']['organization_nid'] && !$node->organization_nid) { $node->organization_nid = $_SESSION['stormproject_list_filter']['organization_nid']; } } $type = node_get_types('type', $node); $form['group1'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -49, ); $s = "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"; $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'), '#options' => $organizations, '#default_value' => $node->organization_nid, '#process' => array('storm_dependent_select_process'), ); $form['group1']['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, ); $form['group2'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -48, ); $form['group2']['projectcategory'] = array( '#type' => 'select', '#title' => t('Category'), '#default_value' => $node->projectcategory, '#options' => stormattribute_attributes_bydomain('Project category'), ); $form['group2']['projectstatus'] = array( '#type' => 'select', '#title' => t('Status'), '#default_value' => $node->projectstatus, '#options' => stormattribute_attributes_bydomain('Project status'), ); $form['group2']['projectpriority'] = array( '#type' => 'select', '#title' => t('Priority'), '#default_value' => $node->projectpriority, '#options' => stormattribute_attributes_bydomain('Project priority'), ); $form['group3'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -47, ); $form['group3']['pricemode'] = array( '#type' => 'select', '#title' => t('Price mode'), '#default_value' => $node->pricemode, '#options' => array('-' => '-') + stormattribute_attributes_bydomain('Price mode'), ); $form['group3']['price'] = array( '#title' => 'Price', '#type' => 'textfield', '#size' => 15, '#default_value' => $node->price, ); $form['group3']['currency'] = array( '#type' => 'select', '#title' => t('Price currency'), '#default_value' => $node->currency, '#options' => array('-' => '-') + stormattribute_attributes_bydomain('Currency'), ); if ($type->has_body) { $form['body_filter']['#weight'] = -46; $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['title_old'] = array( '#type' => 'hidden', '#default_value' => $node->title_old, ); return $form; } function stormproject_insert($node) { $s = "SELECT title FROM {node} WHERE type='stormorganization' AND nid=%d"; $r = db_query($s, $node->organization_nid); $o = db_fetch_object($r); db_query("INSERT INTO {stormproject} (vid, nid, organization_nid, organization_title, projectcategory, projectstatus, projectpriority, pricemode, price, currency) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', '%s', %f, '%s')", $node->vid, $node->nid, $node->organization_nid, $o->title, $node->projectcategory, $node->projectstatus, $node->projectpriority, $node->pricemode, $node->price, $node->currency); } function stormproject_update($node) { // if this is a new node or we're adding a new revision, if ($node->revision) { stormproject_insert($node); } else { $s = "SELECT title FROM {node} WHERE type='stormorganization' AND nid=%d"; $r = db_query($s, $node->organization_nid); $o = db_fetch_object($r); db_query("UPDATE {stormproject} SET organization_nid=%d, organization_title='%s', projectcategory='%s', projectstatus='%s', projectpriority='%s', pricemode='%s', price=%f, currency='%s' WHERE vid = %d", $node->organization_nid, $o->title, $node->projectcategory, $node->projectstatus, $node->projectpriority, $node->pricemode, $node->price, $node->currency, $node->vid); if ($node->title != $node->title_old) { module_invoke_all('stormproject_change', $node->nid, $node->title); } } } function stormproject_delete($node) { // Notice that we're matching all revision, by using the node's nid. db_query('DELETE FROM {stormproject} WHERE nid = %d', $node->nid); } function stormproject_load($node) { $additions = db_fetch_object(db_query('SELECT * FROM {stormproject} WHERE vid = %d', $node->vid)); $additions->title_old = $node->title; return $additions; } function stormproject_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) { require_once(drupal_get_path('module', 'stormproject') .'/stormproject.theme.inc'); return theme('stormproject_view', $node, $teaser, $page, $links); }