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

'; break; } return $output; } function stormorganization_perm() { return array( 'Storm organization: access', 'Storm organization: add', 'Storm organization: delete all', 'Storm organization: delete own', 'Storm organization: edit all', 'Storm organization: edit own', 'Storm organization: edit belonged', 'Storm organization: view all', 'Storm organization: view own', 'Storm organization: view belonged', 'Storm organization: associate user' ); } function stormorganization_access($op, $node) { global $user; $account = $user; if (is_numeric($node)) $node = node_load($node); if ($op == 'create') { return user_access('Storm organization: add'); } if ($op == 'delete') { if (user_access('Storm organization: delete all')) { return TRUE; } else if (user_access('Storm organization: delete own') && ($account->uid == $node->uid)) { return TRUE; } } if ($op == 'update') { if (user_access('Storm organization: edit all')) { return TRUE; } else if (user_access('Storm organization: edit own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm organization: edit belonged') && ($account->stormorganization_nid == $node->nid)) { return TRUE; } } if ($op == 'view') { if (user_access('Storm organization: view all')) { return TRUE; } else if (user_access('Storm organization: view own') && ($account->uid == $node->uid)) { return TRUE; } else if (user_access('Storm organization: view belonged') && ($account->stormorganization_nid == $node->nid)) { return TRUE; } } return FALSE; } function stormorganization_access_sql($sql, $where=array()) { if (user_access('Storm organization: view all')) { $where[] = "'storm_access'='storm_access'"; return storm_rewrite_sql($sql, $where); } global $user; $cond = ''; if (user_access('Storm organization: view own')) { $cond .= 'n.uid='. $user->uid; } if (user_access('Storm organization: view belonged')) { if (!empty($cond)) $cond .= ' OR '; $cond .= 'n.nid='. $user->stormorganization_nid; } if (empty($cond)) $cond = '0=1'; $where[] = $cond; $where[] = "'storm_access'='storm_access'"; return storm_rewrite_sql($sql, $where); } function stormorganization_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 organization: view own', $account)) { $cond .= "${primary_table}.uid=". $account->uid; } if (user_access('Storm organization: view belonged', $account)) { if ($cond) $cond .= ' OR '; $cond .= ' sor1.nid='. $account->stormorganization_nid; } if ($cond) { $cond = " WHEN 'stormorganization' THEN (SELECT IF($cond,1,0) FROM {stormorganization} sor1 WHERE sor1.vid=${primary_table}.vid) "; } else { $cond = " WHEN 'stormorganization' THEN 0 "; } } $conds[$account->uid] = $cond; return $cond; } function stormorganization_menu($may_cache) { $items = array(); if (!$may_cache) { if (arg(0)=='storm' && arg(1)=='organizations') { require_once(drupal_get_path('module', 'stormorganization') .'/stormorganization.admin.inc'); require_once(drupal_get_path('module', 'stormorganization') .'/stormorganization.theme.inc'); } $items[] = array( 'path' => 'storm/organizations', 'title' => t('Organizations'), 'description' => t('Storm Organizations'), 'callback' => 'stormorganization_list', 'access' => user_access('Storm organization: access'), 'type' => MENU_NORMAL_ITEM ); $items[] = array( 'path' => 'storm/organizations/autocomplete', 'title' => 'Organization autocomplete', 'callback' => 'stormorganization_autocomplete', 'access' => user_access('Storm organization: access'), 'type' => MENU_CALLBACK, ); } return $items; } function stormorganization_node_info() { return array( 'stormorganization' => array( 'name' => t('Organization'), 'module' => 'stormorganization', 'description' => t("An organization for Storm."), 'title_label' => t("Name"), 'body_label' => t("Note"), ) ); } function stormorganization_form(&$node) { $type = node_get_types('type', $node); $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -50, ); $form['group1'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -49, ); $form['group1']['prefix'] = array( '#type' => 'textfield', '#title' => t('Prefix'), '#size' => 20, '#default_value' => $node->prefix, ); $form['group1']['fullname'] = array( '#type' => 'textfield', '#title' => t('Fullname'), '#size' => 40, '#default_value' => $node->fullname, ); $form['group2'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -48, ); $form['group2']['zip'] = array( '#type' => 'textfield', '#title' => t('Zip'), '#size' => 15, '#default_value' => $node->zip, ); $form['group2']['address'] = array( '#type' => 'textfield', '#title' => t('Address'), '#default_value' => $node->address, ); $form['group3'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -47, ); $form['group3']['country'] = array( '#type' => 'select', '#title' => t('Country'), '#options' => stormattribute_attributes_bydomain('Country'), '#default_value' => $node->country, ); $form['group3']['provstate'] = array( '#type' => 'textfield', '#title' => t('Province / State'), '#size' => 20, '#default_value' => $node->provstate, ); $form['group3']['city'] = array( '#type' => 'textfield', '#title' => t('City'), '#size' => 20, '#default_value' => $node->city, ); $form['group4'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -46, ); $form['group4']['currency'] = array( '#type' => 'select', '#title' => t('Currency'), '#options' => stormattribute_attributes_bydomain('Currency'), '#default_value' => $node->currency, ); $languages = language_list('language', TRUE); $languages_options = array(); foreach ($languages as $language_code => $language) { $languages_options[$language_code] = $language; } $form['group4']['orglanguage'] = array( '#type' => 'select', '#title' => t('Language'), '#options' => $languages_options, '#default_value' => $node->orglanguage, ); $form['group4']['vatid'] = array( '#type' => 'textfield', '#title' => t('VAT id'), '#size' => 20, '#default_value' => $node->vatid, ); $form['group5'] = array( '#type' => 'markup', '#theme' => 'storm_form_group', '#weight' => -45, ); $form['group5']['www'] = array( '#type' => 'textfield', '#title' => t('WWW'), '#size' => 30, '#default_value' => $node->www, ); $form['group5']['email'] = array( '#type' => 'textfield', '#title' => t('Email'), '#size' => 30, '#default_value' => $node->email, ); if ($type->has_body) { $form['body_filter']['#weight'] = -44; $form['body_filter']['body'] = array( '#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#required' => FALSE ); $form['body_filter']['format'] = filter_form($node->format); } $form['title_old'] = array( '#type' => 'hidden', '#default_value' => $node->title_old, ); return $form; } function stormorganization_insert($node) { db_query("INSERT INTO {stormorganization} (vid, nid, prefix, fullname, country, www, email, currency, provstate, zip, city, address, vatid, orglanguage ) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", $node->vid, $node->nid, $node->prefix, $node->fullname, $node->country, $node->www, $node->email, $node->currency, $node->provstate, $node->zip, $node->city, $node->address, $node->vatid, $node->orglanguage ); } function stormorganization_update($node) { // if this is a new node or we're adding a new revision, if ($node->revision) { stormorganization_insert($node); } else { db_query("UPDATE {stormorganization} SET prefix = '%s', fullname = '%s', country='%s', www='%s', email='%s', currency = '%s', provstate = '%s', zip = '%s', city = '%s', address = '%s', vatid = '%s', orglanguage = '%s' WHERE vid = %d", $node->prefix, $node->fullname, $node->country, $node->www, $node->email, $node->currency, $node->provstate, $node->zip, $node->city, $node->address, $node->vatid, $node->orglanguage, $node->vid); if ($node->title != $node->title_old) { module_invoke_all('stormorganization_change', $node->nid, $node->title); } } } function stormorganization_delete($node) { // Notice that we're matching all revision, by using the node's nid. db_query('DELETE FROM {stormorganization} WHERE nid = %d', $node->nid); } function stormorganization_load($node) { $additions = db_fetch_object(db_query('SELECT * FROM {stormorganization} WHERE vid = %d', $node->vid)); $additions->title_old = $node->title; return $additions; } function stormorganization_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) { require_once(drupal_get_path('module', 'stormorganization') .'/stormorganization.theme.inc'); return theme('stormorganization_view', $node, $teaser, $page, $links); } function stormorganization_form_alter($form_id, &$form) { if ($form_id == 'storm_admin_settings') { $s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormorganization} AS sor ON sor.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; } $form['storm_organization_nid'] = array( '#type' => 'select', '#title' => t('Organization'), '#options' => $organizations, '#default_value' => variable_get('storm_organization_nid', 0), '#description' => t('The organization that owns this system'), '#weight' => -30, ); } }