| 1 |
<?php
|
| 2 |
// $Id: storm.module,v 1.15 2009/09/04 14:22:14 magnity Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Main functions file for the Storm module.
|
| 7 |
* Contents: implementation of hooks, admin settings, other functions.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* @function
|
| 12 |
* Implementation of hook_init
|
| 13 |
*/
|
| 14 |
// Note #370120. It is intended to move these calls to pages which specifically need them rather than on hook_init.
|
| 15 |
function storm_init() {
|
| 16 |
//drupal_add_js(drupal_get_path('module', 'storm') .'/storm.js', 'module', 'header', FALSE);
|
| 17 |
drupal_add_css(drupal_get_path('module', 'storm') .'/storm.css', 'module');
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* @function
|
| 22 |
* Implementation of hook_help
|
| 23 |
*/
|
| 24 |
function storm_help($path, $arg) {
|
| 25 |
$output = '';
|
| 26 |
|
| 27 |
switch ($path) {
|
| 28 |
case 'admin/help#storm':
|
| 29 |
$output = '<p>'. t('Provides a complete project management environment') .'</p>';
|
| 30 |
break;
|
| 31 |
}
|
| 32 |
return $output;
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
| 36 |
* @function
|
| 37 |
* Implementation of hook_menu
|
| 38 |
*/
|
| 39 |
function storm_menu() {
|
| 40 |
$items = array();
|
| 41 |
|
| 42 |
$items['storm'] = array(
|
| 43 |
'title' => t('Storm'),
|
| 44 |
'description' => t('Storm Dashboard'),
|
| 45 |
'page callback' => 'storm_dashboard',
|
| 46 |
'access arguments' => array('Storm: Access Dashboard'),
|
| 47 |
'parent' => '',
|
| 48 |
'type' => MENU_NORMAL_ITEM,
|
| 49 |
);
|
| 50 |
|
| 51 |
$items['admin/storm'] = array(
|
| 52 |
'title' => t('Storm'),
|
| 53 |
'description' => t('Storm Administration Page'),
|
| 54 |
'page callback' => 'drupal_get_form',
|
| 55 |
'page arguments' => array('storm_admin_settings'),
|
| 56 |
'access arguments' => array('access administration pages'),
|
| 57 |
'type' => MENU_NORMAL_ITEM,
|
| 58 |
);
|
| 59 |
|
| 60 |
$items['admin/config/storm/storm'] = array(
|
| 61 |
'title' => t('Storm'),
|
| 62 |
'description' => t('Storm Administration Page'),
|
| 63 |
'access arguments' => array('access administration pages'),
|
| 64 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 65 |
'weight' => -100,
|
| 66 |
);
|
| 67 |
|
| 68 |
return $items;
|
| 69 |
}
|
| 70 |
|
| 71 |
/**
|
| 72 |
* @function
|
| 73 |
* Implementation of hook_permission
|
| 74 |
*/
|
| 75 |
function storm_permission() {
|
| 76 |
return array(
|
| 77 |
'Storm: Access Dashboard' => array(
|
| 78 |
'title' => t('Storm: Access Dashboard'),
|
| 79 |
'description' => t('View Storm Dashboard'),
|
| 80 |
),
|
| 81 |
);
|
| 82 |
}
|
| 83 |
|
| 84 |
/**
|
| 85 |
* @function
|
| 86 |
* Implementation of hook_theme
|
| 87 |
*/
|
| 88 |
function storm_theme() {
|
| 89 |
return array(
|
| 90 |
'storm_form_group' => array(
|
| 91 |
'arguments' => array('header', 'form'),
|
| 92 |
'file' => 'storm.theme.inc',
|
| 93 |
),
|
| 94 |
'datetime' => array(
|
| 95 |
'arguments' => array('element'),
|
| 96 |
'file' => 'storm.theme.inc',
|
| 97 |
),
|
| 98 |
'dateext' => array(
|
| 99 |
'arguments' => array('element'),
|
| 100 |
'file' => 'storm.theme.inc',
|
| 101 |
),
|
| 102 |
'storm_dashboard' => array(
|
| 103 |
'arguments' => array(),
|
| 104 |
'file' => 'storm.theme.inc',
|
| 105 |
),
|
| 106 |
'storm_link' => array(
|
| 107 |
'arguments' => array(),
|
| 108 |
'file' => 'storm.theme.inc',
|
| 109 |
),
|
| 110 |
'storm_list_report' => array(
|
| 111 |
'arguments' => array('header', 'rows', 'title', 'footer', 'headtitle'),
|
| 112 |
'file' => 'storm.theme.inc',
|
| 113 |
),
|
| 114 |
'storm_report' => array(
|
| 115 |
'arguments' => array('header', 'content', 'title', 'footer'),
|
| 116 |
'file' => 'storm.theme.inc',
|
| 117 |
),
|
| 118 |
'storm_view_item' => array(
|
| 119 |
'arguments' => array('label', 'value'),
|
| 120 |
'file' => 'storm.theme.inc',
|
| 121 |
),
|
| 122 |
);
|
| 123 |
}
|
| 124 |
|
| 125 |
/**
|
| 126 |
* @function
|
| 127 |
* Defines the administration settings form for the Storm module
|
| 128 |
*/
|
| 129 |
function storm_admin_settings() {
|
| 130 |
$form = array();
|
| 131 |
$w = -5;
|
| 132 |
|
| 133 |
$form['storm_icons_path'] = array(
|
| 134 |
'#type' => 'textfield',
|
| 135 |
'#title' => t('Icons directory'),
|
| 136 |
'#default_value' => variable_get('storm_icons_path', drupal_get_path('module', 'storm') .'/icons'),
|
| 137 |
'#description' => t("The directory that contains the Storm's icons"),
|
| 138 |
'#weight' => $w++,
|
| 139 |
);
|
| 140 |
|
| 141 |
$form['storm_report_header'] = array(
|
| 142 |
'#type' => 'textarea',
|
| 143 |
'#title' => t('Report header'),
|
| 144 |
'#default_value' => variable_get('storm_report_header', ''),
|
| 145 |
'#description' => t('The header that will appear on Storm reports'),
|
| 146 |
'#weight' => $w++,
|
| 147 |
);
|
| 148 |
|
| 149 |
$form['yearsrange'] = array(
|
| 150 |
'#type' => 'fieldset',
|
| 151 |
'#title' => t('Years range in dates'),
|
| 152 |
'#collapsed' => TRUE,
|
| 153 |
'#collapsible' => TRUE,
|
| 154 |
'#weight' => $w++,
|
| 155 |
);
|
| 156 |
|
| 157 |
$form['yearsrange']['group0'] = array(
|
| 158 |
'#type' => 'markup',
|
| 159 |
'#theme' => 'storm_form_group',
|
| 160 |
'#weight' => $w++,
|
| 161 |
);
|
| 162 |
|
| 163 |
$form['yearsrange']['group0']['storm_yearsrangebegin'] = array(
|
| 164 |
'#type' => 'select',
|
| 165 |
'#title' => t('Begin'),
|
| 166 |
'#options' => drupal_map_assoc(range(1970, 2037)),
|
| 167 |
'#default_value' => variable_get('storm_yearsrangebegin', 2001),
|
| 168 |
);
|
| 169 |
|
| 170 |
$form['yearsrange']['group0']['storm_yearsrangeend'] = array(
|
| 171 |
'#type' => 'select',
|
| 172 |
'#title' => t('End'),
|
| 173 |
'#options' => drupal_map_assoc(range(1970, 2037)),
|
| 174 |
'#default_value' => variable_get('storm_yearsrangeend', 2012),
|
| 175 |
);
|
| 176 |
|
| 177 |
$form['taxation'] = array(
|
| 178 |
'#type' => 'fieldset',
|
| 179 |
'#title' => t('Taxation defaults'),
|
| 180 |
'#collapsed' => TRUE,
|
| 181 |
'#collapsible' => TRUE,
|
| 182 |
'#weight' => $w++,
|
| 183 |
);
|
| 184 |
|
| 185 |
$form['taxation']['tax1app'] = array(
|
| 186 |
'#type' => 'select',
|
| 187 |
'#title' => t('Tax 1: Application'),
|
| 188 |
'#default_value' => variable_get('storm_tax1_app', 'item'),
|
| 189 |
'#description' => t('The method of application to use for Tax 1'),
|
| 190 |
'#options' => array(
|
| 191 |
1 => t('Apply to item amount'),
|
| 192 |
0 => t('Do not apply tax'),
|
| 193 |
),
|
| 194 |
'#weight' => $w++,
|
| 195 |
);
|
| 196 |
|
| 197 |
$form['taxation']['tax1name'] = array(
|
| 198 |
'#type' => 'textfield',
|
| 199 |
'#title' => t('Tax 1: Name'),
|
| 200 |
'#default_value' => variable_get('storm_tax1_name', 'VAT'),
|
| 201 |
'#description' => t('The name to use for Tax 1'),
|
| 202 |
'#weight' => $w++,
|
| 203 |
);
|
| 204 |
|
| 205 |
$form['taxation']['tax1percent'] = array(
|
| 206 |
'#type' => 'textfield',
|
| 207 |
'#title' => t('Tax 1: Default percentage'),
|
| 208 |
'#default_value' => variable_get('storm_tax1_percent', 20),
|
| 209 |
'#description' => t('Default percentage for Tax 1'),
|
| 210 |
'#size' => 5,
|
| 211 |
'#weight' => $w++
|
| 212 |
);
|
| 213 |
|
| 214 |
$form['taxation']['tax2app'] = array(
|
| 215 |
'#type' => 'select',
|
| 216 |
'#title' => t('Tax 2: Application'),
|
| 217 |
'#default_value' => variable_get('storm_tax2_app', 'none'),
|
| 218 |
'#description' => t('The method of application to use for Tax 2'),
|
| 219 |
'#options' => array(
|
| 220 |
2 => t('Apply to total of item amount plus previous tax'),
|
| 221 |
1 => t('Apply to item amount'),
|
| 222 |
0 => t('Do not apply tax'),
|
| 223 |
),
|
| 224 |
'#weight' => $w++,
|
| 225 |
);
|
| 226 |
|
| 227 |
$form['taxation']['tax2name'] = array(
|
| 228 |
'#type' => 'textfield',
|
| 229 |
'#title' => t('Tax 2: Name'),
|
| 230 |
'#default_value' => variable_get('storm_tax2_name', 'VAT'),
|
| 231 |
'#description' => t('The name to use for Tax 2'),
|
| 232 |
'#weight' => $w++,
|
| 233 |
);
|
| 234 |
|
| 235 |
$form['taxation']['tax2percent'] = array(
|
| 236 |
'#type' => 'textfield',
|
| 237 |
'#title' => t('Tax 2: Default percentage'),
|
| 238 |
'#default_value' => variable_get('storm_tax2_percent', 20),
|
| 239 |
'#description' => t('Default percentage for Tax 2'),
|
| 240 |
'#size' => 5,
|
| 241 |
'#weight' => $w++,
|
| 242 |
);
|
| 243 |
|
| 244 |
return system_settings_form($form);
|
| 245 |
}
|
| 246 |
|
| 247 |
/**
|
| 248 |
* @function
|
| 249 |
* Function to create dashboard (call to theme function)
|
| 250 |
*/
|
| 251 |
function storm_dashboard() {
|
| 252 |
drupal_set_title('Storm Dashboard');
|
| 253 |
return theme('storm_dashboard');
|
| 254 |
}
|
| 255 |
|
| 256 |
// DATE / TIME MANIPULATION
|
| 257 |
function storm_elements() {
|
| 258 |
$type['datetime'] = array(
|
| 259 |
'#input' => TRUE,
|
| 260 |
'#process' => array('storm_datetime_expand'),
|
| 261 |
'#element_validate' => array('storm_datetime_validate' => array()),
|
| 262 |
'#default_value' => array(
|
| 263 |
// time() chanced to REQUEST_TIME for D7 (performance improvement)
|
| 264 |
'day' => format_date(REQUEST_TIME, 'custom', 'j'),
|
| 265 |
'month' => format_date(REQUEST_TIME, 'custom', 'n'),
|
| 266 |
'year' => format_date(REQUEST_TIME, 'custom', 'Y'),
|
| 267 |
'hour' => format_date(REQUEST_TIME, 'custom', 'H'),
|
| 268 |
'minute' => format_date(REQUEST_TIME, 'custom', 'i'),
|
| 269 |
),
|
| 270 |
);
|
| 271 |
$type['dateext'] = array(
|
| 272 |
'#input' => TRUE,
|
| 273 |
'#process' => array('storm_dateext_expand'),
|
| 274 |
'#element_validate' => array('storm_dateext_validate' => array()),
|
| 275 |
'#default_value' => array(
|
| 276 |
// time() changed to REQUEST_TIME for D7 (performance improvment)
|
| 277 |
'day' => format_date(REQUEST_TIME, 'custom', 'j'),
|
| 278 |
'month' => format_date(REQUEST_TIME, 'custom', 'n'),
|
| 279 |
'year' => format_date(REQUEST_TIME, 'custom', 'Y'),
|
| 280 |
),
|
| 281 |
);
|
| 282 |
return $type;
|
| 283 |
}
|
| 284 |
|
| 285 |
function storm_datetime_expand($element) {
|
| 286 |
if (empty($element['#value'])) {
|
| 287 |
$element['#value'] = array(
|
| 288 |
// time() changed to REQUEST_TIME for D7 (performance improvement)
|
| 289 |
'day' => format_date(REQUEST_TIME, 'custom', 'j'),
|
| 290 |
'month' => format_date(REQUEST_TIME, 'custom', 'n'),
|
| 291 |
'year' => format_date(REQUEST_TIME, 'custom', 'Y'),
|
| 292 |
'hour' => format_date(REQUEST_TIME, 'custom', 'H'),
|
| 293 |
'minute' => format_date(REQUEST_TIME, 'custom', 'i'),
|
| 294 |
);
|
| 295 |
}
|
| 296 |
|
| 297 |
$element['#tree'] = TRUE;
|
| 298 |
|
| 299 |
// Determine the order of day, month, year in the site's chosen date format.
|
| 300 |
$format = variable_get('date_format_short', 'm/d/Y - H:i');
|
| 301 |
$sort = array();
|
| 302 |
$sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
|
| 303 |
$sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));
|
| 304 |
$sort['year'] = strpos($format, 'Y');
|
| 305 |
$sort['hour'] = strpos($format, 'H');
|
| 306 |
$sort['minute'] = strpos($format, 'i');
|
| 307 |
asort($sort);
|
| 308 |
$order = array_keys($sort);
|
| 309 |
|
| 310 |
// Output multi-selector for date.
|
| 311 |
foreach ($order as $type) {
|
| 312 |
switch ($type) {
|
| 313 |
case 'year':
|
| 314 |
$options = drupal_map_assoc(range(variable_get('storm_yearsrangebegin', 2001), variable_get('storm_yearsrangeend', 2012)));
|
| 315 |
break;
|
| 316 |
case 'month':
|
| 317 |
$options = drupal_map_assoc(range(1, 12), 'map_month');
|
| 318 |
break;
|
| 319 |
case 'day':
|
| 320 |
$options = drupal_map_assoc(range(1, 31));
|
| 321 |
break;
|
| 322 |
case 'hour':
|
| 323 |
$options = drupal_map_assoc(range(0, 23));
|
| 324 |
break;
|
| 325 |
case 'minute':
|
| 326 |
$options = drupal_map_assoc(range(0, 59));
|
| 327 |
break;
|
| 328 |
}
|
| 329 |
$parents = $element['#parents'];
|
| 330 |
$parents[] = $type;
|
| 331 |
$element[$type] = array(
|
| 332 |
'#type' => 'select',
|
| 333 |
'#value' => $element['#value'][$type],
|
| 334 |
'#attributes' => $element['#attributes'],
|
| 335 |
'#options' => $options,
|
| 336 |
);
|
| 337 |
}
|
| 338 |
return $element;
|
| 339 |
}
|
| 340 |
|
| 341 |
function storm_datetime_validate($form) {
|
| 342 |
if (!checkdate($form['#value']['month'], $form['#value']['day'], $form['#value']['year'])) {
|
| 343 |
form_error($form, t('The specified date is invalid.'));
|
| 344 |
}
|
| 345 |
}
|
| 346 |
|
| 347 |
function storm_dateext_expand($element) {
|
| 348 |
if (empty($element['#value']) && !$element['#withnull']) {
|
| 349 |
$element['#value'] = array(
|
| 350 |
// time() changed to REQUEST_TIME for D7 (performance improvement)
|
| 351 |
'day' => format_date(REQUEST_TIME, 'custom', 'j'),
|
| 352 |
'month' => format_date(REQUEST_TIME, 'custom', 'n'),
|
| 353 |
'year' => format_date(REQUEST_TIME, 'custom', 'Y'),
|
| 354 |
);
|
| 355 |
}
|
| 356 |
|
| 357 |
$element['#tree'] = TRUE;
|
| 358 |
|
| 359 |
// Determine the order of day, month, year in the site's chosen date format.
|
| 360 |
$format = variable_get('date_format_short', 'm/d/Y - H:i');
|
| 361 |
$sort = array();
|
| 362 |
$sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
|
| 363 |
$sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));
|
| 364 |
$sort['year'] = strpos($format, 'Y');
|
| 365 |
asort($sort);
|
| 366 |
$order = array_keys($sort);
|
| 367 |
|
| 368 |
// Output multi-selector for date.
|
| 369 |
foreach ($order as $type) {
|
| 370 |
switch ($type) {
|
| 371 |
case 'year':
|
| 372 |
$options = drupal_map_assoc(range(variable_get('storm_yearsrangebegin', 2001), variable_get('storm_yearsrangeend', 2012)));
|
| 373 |
break;
|
| 374 |
case 'month':
|
| 375 |
$options = drupal_map_assoc(range(1, 12), 'map_month');
|
| 376 |
break;
|
| 377 |
case 'day':
|
| 378 |
$options = drupal_map_assoc(range(1, 31));
|
| 379 |
break;
|
| 380 |
}
|
| 381 |
if ($element['#withnull']) {
|
| 382 |
$options = array('-1' => '-') + $options;
|
| 383 |
}
|
| 384 |
|
| 385 |
$parents = $element['#parents'];
|
| 386 |
$parents[] = $type;
|
| 387 |
$element[$type] = array(
|
| 388 |
'#type' => 'select',
|
| 389 |
'#value' => $element['#value'][$type],
|
| 390 |
'#attributes' => $element['#attributes'],
|
| 391 |
'#options' => $options,
|
| 392 |
'#attributes' => array('onchange' => "storm_datext_tonull(this, '". $element['#id'] ."')"),
|
| 393 |
);
|
| 394 |
}
|
| 395 |
return $element;
|
| 396 |
}
|
| 397 |
|
| 398 |
function storm_dateext_validate($form) {
|
| 399 |
}
|
| 400 |
|
| 401 |
function storm_dependent_select_process($form, $edit, $form_state, $complete_form) {
|
| 402 |
unset($form['#needs_validation']);
|
| 403 |
return $form;
|
| 404 |
}
|
| 405 |
|
| 406 |
function _timestamp_to_gm($timestamp, $timezone=NULL) {
|
| 407 |
if (!isset($timezone)) {
|
| 408 |
global $user;
|
| 409 |
if (variable_get('configurable_timezones', 1) && $user->uid && drupal_strlen($user->timezone)) {
|
| 410 |
$timezone = $user->timezone;
|
| 411 |
}
|
| 412 |
else {
|
| 413 |
$timezone = variable_get('date_default_timezone', 0);
|
| 414 |
}
|
| 415 |
}
|
| 416 |
$timestamp -= $timezone;
|
| 417 |
return $timestamp;
|
| 418 |
}
|
| 419 |
|
| 420 |
function _storm_date_to_gmtimestamp($date, $timezone=NULL) {
|
| 421 |
if ($date['month'] == -1 || $date['year'] == -1 || $date['day'] == -1) {
|
| 422 |
return NULL;
|
| 423 |
}
|
| 424 |
else {
|
| 425 |
$gmttimestamp = gmmktime(0, 0, 0, intval($date['month']), intval($date['day']), intval($date['year']));
|
| 426 |
return _timestamp_to_gm($gmttimestamp, $timezone);
|
| 427 |
}
|
| 428 |
}
|
| 429 |
|
| 430 |
function _storm_datetime_to_gmtimestamp($datetime, $timezone=NULL) {
|
| 431 |
$gmttimestamp = gmmktime(intval($datetime['hour']), intval($datetime['minute']), 0, intval($datetime['month']),
|
| 432 |
intval($datetime['day']), intval($datetime['year']));
|
| 433 |
return _timestamp_to_gm($gmttimestamp, $timezone);
|
| 434 |
}
|
| 435 |
|
| 436 |
function _storm_gmtimestamp_to_datetime($timestamp, $timezone=NULL) {
|
| 437 |
$datetime = array(
|
| 438 |
'day' => format_date($timestamp, 'custom', 'j', $timezone),
|
| 439 |
'month' => format_date($timestamp, 'custom', 'n', $timezone),
|
| 440 |
'year' => format_date($timestamp, 'custom', 'Y', $timezone),
|
| 441 |
'hour' => (int)format_date($timestamp, 'custom', 'H', $timezone),
|
| 442 |
'minute' => (int)format_date($timestamp, 'custom', 'i', $timezone),
|
| 443 |
);
|
| 444 |
return $datetime;
|
| 445 |
}
|
| 446 |
|
| 447 |
function _storm_gmtimestamp_to_date($timestamp, $timezone=NULL) {
|
| 448 |
if ($timestamp) {
|
| 449 |
$date = array(
|
| 450 |
'day' => format_date($timestamp, 'custom', 'j', $timezone),
|
| 451 |
'month' => format_date($timestamp, 'custom', 'n', $timezone),
|
| 452 |
'year' => format_date($timestamp, 'custom', 'Y', $timezone),
|
| 453 |
);
|
| 454 |
}
|
| 455 |
else {
|
| 456 |
$date = array(
|
| 457 |
'day' => -1,
|
| 458 |
'month' => -1,
|
| 459 |
'year' => -1,
|
| 460 |
);
|
| 461 |
}
|
| 462 |
|
| 463 |
return $date;
|
| 464 |
}
|
| 465 |
|
| 466 |
function _storm_gmtimestamp_without_time($timestamp, $timezone=NULL) {
|
| 467 |
$date = _storm_gmtimestamp_to_date($timestamp, $timezone);
|
| 468 |
$gmttimestamp = gmmktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
|
| 469 |
return _timestamp_to_gm($gmttimestamp, $timezone);
|
| 470 |
}
|
| 471 |
|
| 472 |
function _storm_strtotime($timestr='') {
|
| 473 |
$timestr = drupal_substr($timestr, 0, 5);
|
| 474 |
$time = array();
|
| 475 |
$time['hour'] = 0;
|
| 476 |
$time['minute'] = 0;
|
| 477 |
|
| 478 |
$ar = explode(':', $timestr);
|
| 479 |
if (is_array($ar)) {
|
| 480 |
if (array_key_exists(0, $ar)) $time['hour'] = $ar[0];
|
| 481 |
if (array_key_exists(0, $ar)) $time['minute'] = $ar[1];
|
| 482 |
}
|
| 483 |
return $time;
|
| 484 |
}
|
| 485 |
|
| 486 |
function _timetostr($time=array()) {
|
| 487 |
$timestr = str_pad($time['hour'], 2, "0", STR_PAD_LEFT) .':'. str_pad($time['minute'], 2, "0", STR_PAD_RIGHT);
|
| 488 |
return $timestr;
|
| 489 |
}
|
| 490 |
|
| 491 |
/**
|
| 492 |
* @function
|
| 493 |
* Calculates taxation for Storm nodes
|
| 494 |
*/
|
| 495 |
function storm_taxation(&$node) {
|
| 496 |
// If values are not set, then use default values
|
| 497 |
if (!$node->tax1app) {
|
| 498 |
$node->tax1app = variable_get('storm_tax1_app', 'none');
|
| 499 |
}
|
| 500 |
if (!$node->tax1percent) {
|
| 501 |
$node->tax1percent = variable_get('storm_tax1_percent', '20');
|
| 502 |
}
|
| 503 |
if (!$node->tax2app) {
|
| 504 |
$node->tax2app = variable_get('storm_tax2_app', 'none');
|
| 505 |
}
|
| 506 |
if (!$node->tax2percent) {
|
| 507 |
$node->tax2percent = variable_get('storm_tax2_percent', '20');
|
| 508 |
}
|
| 509 |
|
| 510 |
switch ($node->tax1app) {
|
| 511 |
case 0:
|
| 512 |
$node->tax1 = 0;
|
| 513 |
break;
|
| 514 |
case 1:
|
| 515 |
$node->tax1 = $node->amount * $node->tax1percent / 100;
|
| 516 |
break;
|
| 517 |
default:
|
| 518 |
// ERROR
|
| 519 |
drupal_set_message(t('Error during tax calculations (Storm Module)'), 'error');
|
| 520 |
}
|
| 521 |
|
| 522 |
$node->subtotal = $node->amount + $node->tax1;
|
| 523 |
|
| 524 |
switch ($node->tax2app) {
|
| 525 |
case 0:
|
| 526 |
$node->tax2 = 0;
|
| 527 |
break;
|
| 528 |
case 1:
|
| 529 |
$node->tax2 = $node->amount * $node->tax2percent / 100;
|
| 530 |
break;
|
| 531 |
case 2:
|
| 532 |
$node->tax2 = $node->subtotal * $node->tax2percent / 100;
|
| 533 |
break;
|
| 534 |
default:
|
| 535 |
// ERROR
|
| 536 |
drupal_set_message(t('Error during tax calculations (Storm Module)'), 'error');
|
| 537 |
}
|
| 538 |
|
| 539 |
$node->total = $node->subtotal + $node->tax2;
|
| 540 |
}
|
| 541 |
|
| 542 |
// STORM ICON ADD / EDIT / LINK FUNCTIONS
|
| 543 |
function storm_icon_add_node($node, $params=array()) {
|
| 544 |
return storm_icon_add('node/add/'. $node->type, $node, $params);
|
| 545 |
}
|
| 546 |
|
| 547 |
function storm_icon_edit_node($node, $params=array()) {
|
| 548 |
return storm_icon_edit('node/'. $node->nid .'/edit', $node, $params);
|
| 549 |
}
|
| 550 |
|
| 551 |
function storm_icon_delete_node($node, $params=array()) {
|
| 552 |
return storm_icon_delete('node/'. $node->nid .'/delete', $node, $params);
|
| 553 |
}
|
| 554 |
|
| 555 |
function storm_icon_add($path, $item, $params=array()) {
|
| 556 |
global $user;
|
| 557 |
$type = $item->type;
|
| 558 |
// Work around during 436922
|
| 559 |
if ($type=="storminvoiceitem") {
|
| 560 |
$type = "storminvoice";
|
| 561 |
} // End workaround
|
| 562 |
$af = $type .'_access';
|
| 563 |
if (!$af('create', $item, $user)) return '';
|
| 564 |
$attributes = array('class' => 'popups-form');
|
| 565 |
return storm_icon_l('application_add', $path, t('Add'), '', $params, $attributes);
|
| 566 |
}
|
| 567 |
|
| 568 |
function storm_icon_edit($path, $item, $params=array()) {
|
| 569 |
global $user;
|
| 570 |
$type = $item->type;
|
| 571 |
// Work around during 436922
|
| 572 |
if ($type=="storminvoiceitem") {
|
| 573 |
$type = "storminvoice";
|
| 574 |
} // End workaround
|
| 575 |
$af = $type .'_access';
|
| 576 |
if (!$af('update', $item, $user)) return '';
|
| 577 |
$attributes = array('class' => 'popups-form');
|
| 578 |
return storm_icon_l('application_edit', $path, t('Edit'), '', $params, $attributes);
|
| 579 |
}
|
| 580 |
|
| 581 |
function storm_icon_delete($path, $item, $params=array()) {
|
| 582 |
global $user;
|
| 583 |
$type = $item->type;
|
| 584 |
// Work around during 436922
|
| 585 |
if ($type=="storminvoiceitem") {
|
| 586 |
$type = "storminvoice";
|
| 587 |
} // End workaround
|
| 588 |
$af = $type .'_access';
|
| 589 |
if (!$af('delete', $item, $user)) return '';
|
| 590 |
$attributes = array('class' => 'popups-form');
|
| 591 |
return storm_icon_l('application_delete', $path, t('Delete'), '', $params, $attributes);
|
| 592 |
}
|
| 593 |
|
| 594 |
function storm_icon_l($icon, $path, $title, $permission='', $params=array(), $attributes=array()) {
|
| 595 |
if ($permission && !user_access($permission)) return '';
|
| 596 |
$icon = storm_icon($icon, $title);
|
| 597 |
$attributes ['title'] = $title;
|
| 598 |
|
| 599 |
$query = '';
|
| 600 |
|
| 601 |
if (array_key_exists('q', $params)) {
|
| 602 |
$destination = $params['q'];
|
| 603 |
unset($params['q']);
|
| 604 |
$c = 0;
|
| 605 |
if (array_key_exists('page', $params)) {
|
| 606 |
$destination .= '?page='. $params['page'];
|
| 607 |
unset($params['page']);
|
| 608 |
$c++;
|
| 609 |
}
|
| 610 |
if (array_key_exists('sort', $params)) {
|
| 611 |
if ($c) {
|
| 612 |
$destination .= '&';
|
| 613 |
}
|
| 614 |
else {
|
| 615 |
$destination .= '?';
|
| 616 |
}
|
| 617 |
$destination .= 'sort='. $params['sort'];
|
| 618 |
unset($params['sort']);
|
| 619 |
$c++;
|
| 620 |
}
|
| 621 |
if (array_key_exists('order', $params)) {
|
| 622 |
if ($c) {
|
| 623 |
$destination .= '&';
|
| 624 |
}
|
| 625 |
else {
|
| 626 |
$destination .= '?';
|
| 627 |
}
|
| 628 |
$destination .= 'order='. $params['order'];
|
| 629 |
unset($params['order']);
|
| 630 |
$c++;
|
| 631 |
}
|
| 632 |
$query .= 'destination='. urlencode($destination);
|
| 633 |
}
|
| 634 |
|
| 635 |
foreach ($params as $key => $value) {
|
| 636 |
if ($query) $query .= '&';
|
| 637 |
$query .= $key .'='. urlencode($value);
|
| 638 |
}
|
| 639 |
|
| 640 |
$o = l($icon, $path, array('attributes' => $attributes, 'query' => $query, 'html' => TRUE));
|
| 641 |
return $o;
|
| 642 |
}
|
| 643 |
|
| 644 |
function storm_icon($icon, $title) {
|
| 645 |
global $base_path;
|
| 646 |
$icon = str_replace(' ', '_', $icon);
|
| 647 |
$img_src = $base_path . variable_get('storm_icons_path', drupal_get_path('module', 'storm') .'/icons') .'/'. $icon .'.png';
|
| 648 |
$o = '<img src="'. $img_src .'" alt="'. $title .'" title="'. $title .'" />';
|
| 649 |
return $o;
|
| 650 |
}
|
| 651 |
|
| 652 |
// SQL FUNCTIONS
|
| 653 |
function storm_rewrite_sql($sql, $where=array(), $join=array()) {
|
| 654 |
$where = empty($where) ? '' : '('. implode(') AND (', $where) .')';
|
| 655 |
$join = empty($join) ? '' : implode(' ', $join);
|
| 656 |
|
| 657 |
if (!empty($where) || !empty($join)) {
|
| 658 |
if (!empty($where)) {
|
| 659 |
$new = "WHERE $where ";
|
| 660 |
}
|
| 661 |
$new = " $join $new";
|
| 662 |
if (strpos($sql, 'WHERE')) {
|
| 663 |
$sql = str_replace('WHERE', $new .'AND (', $sql);
|
| 664 |
$insert = ') ';
|
| 665 |
}
|
| 666 |
else {
|
| 667 |
$insert = $new;
|
| 668 |
}
|
| 669 |
if (strpos($sql, 'GROUP')) {
|
| 670 |
$replace = 'GROUP';
|
| 671 |
}
|
| 672 |
elseif (strpos($sql, 'HAVING')) {
|
| 673 |
$replace = 'HAVING';
|
| 674 |
}
|
| 675 |
elseif (strpos($sql, 'ORDER')) {
|
| 676 |
$replace = 'ORDER';
|
| 677 |
}
|
| 678 |
elseif (strpos($sql, 'LIMIT')) {
|
| 679 |
$replace = 'LIMIT';
|
| 680 |
}
|
| 681 |
else {
|
| 682 |
$sql .= $insert;
|
| 683 |
}
|
| 684 |
if (isset($replace)) {
|
| 685 |
$sql = str_replace($replace, $insert . $replace, $sql);
|
| 686 |
}
|
| 687 |
}
|
| 688 |
|
| 689 |
return $sql;
|
| 690 |
}
|
| 691 |
|
| 692 |
function storm_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
|
| 693 |
if (($primary_table == 'n' || $primary_table == 'node') && $primary_field == 'nid') {
|
| 694 |
|
| 695 |
if (preg_match("/'storm_access'='storm_access'/", $query)) {
|
| 696 |
return array();
|
| 697 |
}
|
| 698 |
|
| 699 |
global $user;
|
| 700 |
$conditions = array();
|
| 701 |
foreach (module_invoke_all('storm_rewrite_where_sql', $query, $primary_table, $user) as $condition) {
|
| 702 |
if ($condition) {
|
| 703 |
$conditions[] = $condition;
|
| 704 |
}
|
| 705 |
}
|
| 706 |
|
| 707 |
$return = array();
|
| 708 |
$where = '';
|
| 709 |
if ($conditions) {
|
| 710 |
switch ($GLOBALS['db_type']) {
|
| 711 |
case 'mysql':
|
| 712 |
case 'mysqli':
|
| 713 |
$where = '(';
|
| 714 |
$where .= " CASE ${primary_table}.type ";
|
| 715 |
foreach ($conditions as $condition) {
|
| 716 |
$where .= $condition .' ';
|
| 717 |
}
|
| 718 |
$where .= ' ELSE 1 END ';
|
| 719 |
$where .= ' )=1 ';
|
| 720 |
$return['where'] = $where;
|
| 721 |
break;
|
| 722 |
case 'pgsql':
|
| 723 |
break;
|
| 724 |
}
|
| 725 |
}
|
| 726 |
return $return;
|
| 727 |
}
|
| 728 |
}
|
| 729 |
|
| 730 |
// FUNCTION TO ADD STORM CLASSES TO NODE FORM
|
| 731 |
function storm_form_alter(&$form, $form_state, $form_id) {
|
| 732 |
if (!isset($form['type'])) {
|
| 733 |
return;
|
| 734 |
}
|
| 735 |
|
| 736 |
if ($form_id == $form['type']['#value'] .'_node_form') {
|
| 737 |
$class = $form['#attributes']['class'];
|
| 738 |
if ($class) $class .= ' ';
|
| 739 |
$class .= $form_id;
|
| 740 |
$form['#attributes']['class'] = $class;
|
| 741 |
foreach ($form as $key => $elem) {
|
| 742 |
if (is_array($elem) && $elem['#type']=='fieldset') {
|
| 743 |
$class = $elem['#attributes']['class'];
|
| 744 |
if ($class) $class .= ' ';
|
| 745 |
$class .= $key;
|
| 746 |
$form[$key]['#attributes']['class'] = $class;
|
| 747 |
}
|
| 748 |
}
|
| 749 |
}
|
| 750 |
}
|