~ubuntu-gr-webteam/ubuntu-gr-website/drupal6-site

« back to all changes in this revision

Viewing changes to sites/all/modules/date/date_popup/date_popup.module

  • Committer: Thanos Lefteris
  • Date: 2009-07-29 17:46:54 UTC
  • Revision ID: alefteris@gmail.com-20090729174654-pgfr1vtqw8ikvo5r
* Upgraded calendar module
* Upgraded commentrss module
* Upgraded date module
* Upgraded webfm module

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
// $Id: date_popup.module,v 1.42.2.1.2.43 2009/03/25 15:31:42 karens Exp $
 
2
// $Id: date_popup.module,v 1.42.2.1.2.51 2009/07/28 19:43:52 karens Exp $
3
3
/**
4
4
 * @file
5
5
 * A module to enable jquery calendar and time entry popups.
37
37
  else {
38
38
    drupal_add_js($path .'/lib/ui.datepicker.js');
39
39
  }
40
 
  drupal_add_js($path .'/lib/jquery.timeentry.pack.js');
 
40
  if (variable_get('date_popup_timepicker', 'default') == 'default') {
 
41
    drupal_add_js($path .'/lib/jquery.timeentry.pack.js');
 
42
  }
41
43
  $loaded = TRUE;
42
44
}
43
45
 
46
48
 */
47
49
function date_popup_init() {
48
50
  drupal_add_css(drupal_get_path('module', 'date_popup')  .'/themes/datepicker.css');
49
 
  drupal_add_css(drupal_get_path('module', 'date_popup')  .'/themes/timeentry.css');
 
51
  if (variable_get('date_popup_timepicker', 'default') == 'default') {
 
52
    drupal_add_css(drupal_get_path('module', 'date_popup')  .'/themes/timeentry.css');
 
53
  }
50
54
}
51
55
 
52
56
 /**
201
205
  $date_granularity = array_intersect($granularity, array('month', 'day', 'year'));
202
206
  $time_granularity = array_intersect($granularity, array('hour', 'minute', 'second'));
203
207
  $date_format = (date_limit_format($element['#date_format'], $date_granularity));
204
 
 
205
208
  if (empty($date_granularity)) return array();
206
209
  
207
210
  // The datepicker can't handle zero or negative values like 0:+1
245
248
    '#id' => $id,    
246
249
    '#size' => !empty($element['#size']) ? $element['#size'] : 20,
247
250
    '#maxlength' => !empty($element['#maxlength']) ? $element['#maxlength'] : 30,
 
251
    '#attributes' => $element['#attributes'],
248
252
    );
249
253
  // Views exposed filters are treated as submitted even if not,
250
254
  // so force the #default value in that case.  
267
271
 
268
272
  $spinner_text = array(t('Now'), t('Previous field'), t('Next field'), t('Increment'), t('Decrement'));
269
273
  $settings = array(
270
 
    'show24Hours' => strpos($element['#date_format'], 'H') ? TRUE : FALSE,
 
274
    'show24Hours' => strpos($element['#date_format'], 'H') !== FALSE ? TRUE : FALSE,
271
275
    'showSeconds' => (in_array('second', $granularity) ? TRUE : FALSE),
272
276
    'timeSteps' => array(1, intval($element['#date_increment']), (in_array('second', $granularity) ? $element['#date_increment'] : 0)),
273
277
    'spinnerImage' => '',
309
313
  $date_granularity = array_intersect($granularity, array('month', 'day', 'year'));
310
314
  $time_granularity = array_intersect($granularity, array('hour', 'minute', 'second'));
311
315
  $label = !empty($element['#date_title']) ? $element['#date_title'] : (!empty($element['#title']) ? $element['#title'] : '');
 
316
  $label = t($label);
312
317
  
313
318
  // If the field is empty and not required, set it to empty and return.
314
319
  // If the field is empty and required, set error message and return.
375
380
    $time = date_convert_from_custom(trim(!empty($element['#value']['time']) ? $element['#value']['time'] : ''), $time_format);
376
381
    $value = trim(substr($date, 0, 10) .' '. substr($time, 11, 8));
377
382
  }
 
383
  
378
384
  if (date_is_valid($value, DATE_DATETIME, $granularity)) {
379
385
    $date = date_make_date($value, $element['#date_timezone'], DATE_DATETIME, $granularity);
380
386
    $value = date_convert($date, DATE_OBJECT, DATE_DATETIME);
404
410
}
405
411
 
406
412
/**
 
413
 * Store personalized format options for each user.
 
414
 *
 
415
 * TODO see what is needed to remove this completely.
 
416
 * It is now only used by Date Popup and not really needed there.
 
417
 *
 
418
 * @return array
 
419
 */
 
420
function date_format_options() {
 
421
  global $user;
 
422
  $options = array();
 
423
  $formats = date_get_formats();
 
424
  $options = array();
 
425
  module_load_include('inc', 'date', 'date_admin');
 
426
  $now = date_example_date();
 
427
  if (!empty($now)) {
 
428
    foreach ($formats as $type => $format_types) {
 
429
      foreach ($format_types as $format => $format_attributes) {
 
430
        // Create an option that shows date only without time, along with the
 
431
        // default string which has both date and time.
 
432
        $no_time = date_limit_format($format, array('month', 'day', 'year'));
 
433
        $zones = array('', 'O', 'P', 'e');
 
434
        foreach ($zones as $zone) {
 
435
          $time_format = !empty($zone) ? $format .' '. $zone : $format;
 
436
          $options[$no_time] = date_format_date($now, 'custom', $no_time);
 
437
          $options[$time_format] = date_format_date($now, 'custom', $time_format);
 
438
        }
 
439
      }
 
440
    }
 
441
    asort($options);
 
442
  }
 
443
  return $options;
 
444
}
 
445
 
 
446
/**
407
447
 * Recreate a date format string so it has the values popup expects.
408
448
 *
409
449
 * @param string $format
493
533
    $output = $element['#children'];
494
534
  }
495
535
  return '<div class="'. $class .'">'. theme('form_element', $element, $output) .'</div>';
 
536
}
 
537
 
 
538
/**
 
539
 * Implementation of hook_menu().
 
540
 */
 
541
function date_popup_menu() {
 
542
  $items = array();
 
543
 
 
544
  $items['admin/settings/date_popup'] = array(
 
545
    'title' => 'Date Popup Configuration',
 
546
    'description' => 'Allows the user to configure the Date Popup settings.',
 
547
    'page callback' => 'drupal_get_form',
 
548
    'page arguments' => array('date_popup_settings'),
 
549
    'access callback' => 'user_access',
 
550
    'access arguments' => array('administer site configuration'),
 
551
    'type' => MENU_NORMAL_ITEM,
 
552
  );
 
553
  return $items;
 
554
}
 
555
/**
 
556
 * General configuration form for controlling the Date Popup behaviour.
 
557
 */
 
558
function date_popup_settings() {
 
559
 
 
560
  $form['#prefix'] = t('<p>The Date Popup calendar datepicker uses the jQuery UI datepicker. A version of that is included with the Date Popup module, but you are strongly encouraged to use the <a href="http://drupal.org/project/jquery_ui">jQuery UI module</a> instead. If the jQuery UI module is installed, the Date Popup will use the datepicker from that module, which is likely to be more current. If you are having any problems with Popups and you are not already using jQuery UI, please do that as a first step before reporting problems.</p>');
 
561
  $form['#prefix'] .= t('<p>The Date Popup module uses a jQuery timepicker module. There is no "official" jQuery UI timepicker, and not everyone likes the one that is included here. If you do not want to use the timepicker, you can turn it off below and users will get a regular textfield instead.</p>');
 
562
  
 
563
  $form['date_popup_timepicker'] = array(
 
564
    '#type' => 'select',
 
565
    '#options' => array('default' => t('Use default jQuery timepicker'), 'none' => t('Manual time entry, no jQuery timepicker')),
 
566
    '#title' => t('Timepicker'),
 
567
    '#default_value' => variable_get('date_popup_timepicker', 'default'),
 
568
    '#description' => t("Choose the jQuery timepicker to user."),
 
569
  );
 
570
  
 
571
  $css = <<<EOM
 
572
/* ___________ IE6 IFRAME FIX ________ */
 
573
.ui-datepicker-cover {
 
574
  display: none; /*sorry for IE5*/
 
575
  display/**/: block; /*sorry for IE5*/
 
576
  position: absolute; /*must have*/
 
577
  z-index: -1; /*must have*/
 
578
  filter: mask(); /*must have*/
 
579
  top: -4px; /*must have*/
 
580
  left: -4px; /*must have*/ /* LTR */
 
581
  width: 200px; /*must have*/
 
582
  height: 200px; /*must have*/
 
583
}
 
584
EOM;
 
585
 
 
586
  $form['#suffix'] = t('<p>The Date Popup calendar includes some css for IE6 that breaks css validation. Since IE 6 is now superceded by IE 7 and IE 8, the special css for IE 6 has been removed from the regular css used by the Date Popup. If you find you need that css after all, you can add it back in your theme. Look at the way the Garland theme adds special IE-only css in in its page.tpl.php file. The css you need is:</p>') .'<blockquote><PRE>'. $css .'</PRE></blockquote>';
 
587
 
 
588
  return system_settings_form($form);
496
589
}
 
 
b'\\ No newline at end of file'