Projet

Général

Profil

Révision b720ea3e

Ajouté par Assos Assos il y a plus de 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/date_repeat/date_repeat_form.inc
30 30
 * BYSETPOS
31 31
 *   Seldom used anywhere, so no reason to complicated the code.
32 32
 */
33

  
33 34
/**
34 35
 * Generate the repeat setting form.
35 36
 */
36 37
function _date_repeat_rrule_process($element, &$form_state, $form) {
37 38

  
38
  // If the RRULE field is not visible to the user, needs no processing or validation.
39
  // The Date field module is not adding this element to forms if the field is hidden,
39
  // If the RRULE field is not visible to the user,
40
  // needs no processing or validation.
41
  // The Date field module is not adding this element to forms
42
  // if the field is hidden,
40 43
  // this test is just in case some other module attempts to do so.
41 44

  
42 45
  if (date_hidden_element($element)) {
......
67 70
  $timezone = !empty($element['#date_timezone']) ? $element['#date_timezone'] : date_default_timezone();
68 71
  $merged_values = date_repeat_merge($rrule, $element);
69 72

  
70
  $UNTIL = '';
73
  $until = '';
71 74
  if (!empty($merged_values['UNTIL']['datetime'])) {
72 75
    $until_date = new DateObject($merged_values['UNTIL']['datetime'], $merged_values['UNTIL']['tz']);
73 76
    date_timezone_set($until_date, timezone_open($timezone));
74
    $UNTIL = date_format($until_date, DATE_FORMAT_DATETIME);
77
    $until = date_format($until_date, DATE_FORMAT_DATETIME);
75 78
  }
76 79

  
77
  $COUNT = '';
80
  $count = '';
78 81
  if (!empty($merged_values['COUNT'])) {
79
    $COUNT = $merged_values['COUNT'];
82
    $count = $merged_values['COUNT'];
80 83
  }
81 84

  
82 85
  $element['FREQ'] = array(
......
137 140
  );
138 141

  
139 142
  list($prefix, $suffix) = explode('@interval', t('Every @interval days', array(), array('context' => 'Date repeat')));
140
  $DAILY_INTERVAL = array(
143
  $daily_interval = array(
141 144
    '#type' => 'textfield',
142 145
    '#title' => t('Repeats', array(), array('context' => 'Date repeat')),
143 146
    '#title_display' => 'invisible',
......
210 213
    '#suffix' => '</div>',
211 214
  );
212 215

  
213
  $DAILY_radios_default = 'INTERVAL';
216
  $daily_radios_default = 'INTERVAL';
214 217
  if (isset($rrule['FREQ']) && $rrule['FREQ'] === 'DAILY' && !empty($rrule['BYDAY'])) {
215 218
    switch (count($rrule['BYDAY'])) {
216 219
      case 2:
217
        $DAILY_radios_default = 'every_tu_th';
220
        $daily_radios_default = 'every_tu_th';
218 221
        break;
222

  
219 223
      case 3:
220
        $DAILY_radios_default = 'every_mo_we_fr';
224
        $daily_radios_default = 'every_mo_we_fr';
221 225
        break;
226

  
222 227
      case 5:
223
        $DAILY_radios_default = 'every_weekday';
228
        $daily_radios_default = 'every_weekday';
224 229
        break;
225 230
    }
226 231
  }
227 232

  
228
  $DAILY_every_weekday = array(
233
  $daily_every_weekday = array(
229 234
    '#type' => 'item',
230 235
    '#markup' => '<div>' . t('Every weekday', array(), array('context' => 'Date repeat')) . '</div>',
231 236
  );
232 237

  
233
  $DAILY_mo_we_fr = array(
238
  $daily_mo_we_fr = array(
234 239
    '#type' => 'item',
235 240
    '#markup' => '<div>' . t('Every Mon, Wed, Fri', array(), array('context' => 'Date repeat')) . '</div>',
236 241
  );
237 242

  
238
  $DAILY_tu_th = array(
243
  $daily_tu_th = array(
239 244
    '#type' => 'item',
240 245
    '#markup' => '<div>' . t('Every Tue, Thu', array(), array('context' => 'Date repeat')) . '</div>',
241 246
  );
......
251 256
        ":input[name=\"{$element['#name']}[FREQ]\"]" => array('value' => 'DAILY'),
252 257
      ),
253 258
    ),
254
    '#default_value' => $DAILY_radios_default,
259
    '#default_value' => $daily_radios_default,
255 260
    '#options' => array(
256 261
      'INTERVAL' => t('interval'),
257 262
      'every_weekday' => t('every weekday'),
258 263
      'every_mo_we_fr' => t('monday wednesday friday'),
259 264
      'every_tu_th' => t('tuesday thursday'),
260 265
    ),
261
    'INTERVAL_child' => $DAILY_INTERVAL,
262
    'every_weekday_child' => $DAILY_every_weekday,
263
    'mo_we_fr_child' => $DAILY_mo_we_fr,
264
    'tu_th_child' => $DAILY_tu_th,
266
    'INTERVAL_child' => $daily_interval,
267
    'every_weekday_child' => $daily_every_weekday,
268
    'mo_we_fr_child' => $daily_mo_we_fr,
269
    'tu_th_child' => $daily_tu_th,
265 270
    '#div_classes' => array(
266 271
      'container-inline interval',
267 272
      'container-inline weekday',
......
270 275
    ),
271 276
  );
272 277

  
273
  $MONTHLY_day_month_default = 'BYMONTHDAY_BYMONTH';
278
  $monthly_day_month_default = 'BYMONTHDAY_BYMONTH';
274 279
  if (isset($rrule['FREQ']) && $rrule['FREQ'] === 'MONTHLY' && !empty($rrule['BYDAY'])) {
275
    $MONTHLY_day_month_default = 'BYDAY_BYMONTH';
280
    $monthly_day_month_default = 'BYDAY_BYMONTH';
276 281
  }
277 282

  
278
  $MONTHLY_on_day_BYMONTHDAY_of_BYMONTH = array(
283
  $monthly_on_day_bymonthday_of_bymonth = array(
279 284
    '#type' => 'container',
280 285
    '#tree' => TRUE,
281 286
  );
282 287

  
283 288
  list($bymonthday_title, $bymonthday_suffix) = explode('@bymonthday', t('On day @bymonthday of', array(), array('context' => 'Date repeat')));
284
  $MONTHLY_on_day_BYMONTHDAY_of_BYMONTH['BYMONTHDAY'] = array(
289
  $monthly_on_day_bymonthday_of_bymonth['BYMONTHDAY'] = array(
285 290
    '#type' => 'select',
286 291
    '#title' => $bymonthday_title,
287 292
    '#default_value' => !empty($rrule['BYMONTHDAY']) && $rrule['FREQ'] === 'MONTHLY' ? $rrule['BYMONTHDAY'] : '',
......
292 297
    '#field_suffix' => $bymonthday_suffix,
293 298
  );
294 299

  
295
  $MONTHLY_on_day_BYMONTHDAY_of_BYMONTH['BYMONTH'] = array(
300
  $monthly_on_day_bymonthday_of_bymonth['BYMONTH'] = array(
296 301
    '#type' => 'checkboxes',
297 302
    '#title' => t('Bymonth', array(), array('context' => 'Date repeat')),
298 303
    '#title_display' => 'invisible',
299
    '#default_value' => !empty($rrule['BYMONTH']) && $rrule['FREQ'] === 'MONTHLY' && $MONTHLY_day_month_default === 'BYMONTHDAY_BYMONTH' ? $rrule['BYMONTH'] : array(),
304
    '#default_value' => !empty($rrule['BYMONTH']) && $rrule['FREQ'] === 'MONTHLY' && $monthly_day_month_default === 'BYMONTHDAY_BYMONTH' ? $rrule['BYMONTH'] : array(),
300 305
    '#options' => date_month_names_abbr(TRUE),
301 306
    '#attributes' => array('class' => array('container-inline')),
302 307
    '#multiple' => TRUE,
......
304 309
    '#suffix' => '</div>',
305 310
  );
306 311

  
307
  $MONTHLY_on_the_BYDAY_of_BYMONTH = array(
312
  $monthly_on_the_byday_of_bymonth = array(
308 313
    '#type' => 'container',
309 314
    '#tree' => TRUE,
310 315
  );
311 316

  
312
  $MONTHLY_BYDAY_COUNT = '';
313
  $MONTHLY_BYDAY_DAY = '';
317
  $monthly_byday_count = '';
318
  $monthly_byday_day = '';
314 319
  if (isset($rrule['BYDAY']) && !empty($rrule['BYDAY']) && $rrule['FREQ'] === 'MONTHLY') {
315
    $MONTHLY_BYDAY_COUNT = substr($rrule['BYDAY'][0], 0, -2);
316
    $MONTHLY_BYDAY_DAY = substr($rrule['BYDAY'][0], -2);;
320
    $monthly_byday_count = substr($rrule['BYDAY'][0], 0, -2);
321
    $monthly_byday_day = substr($rrule['BYDAY'][0], -2);;
317 322
  }
318 323

  
319 324
  list($byday_count_title, $byday_day_title) = explode('@byday', t('On the @byday of', array(), array('context' => 'Date repeat')));
320
  $MONTHLY_on_the_BYDAY_of_BYMONTH['BYDAY_COUNT'] = array(
325
  $monthly_on_the_byday_of_bymonth['BYDAY_COUNT'] = array(
321 326
    '#type' => 'select',
322 327
    '#title' => $byday_count_title,
323
    '#default_value' => !empty($MONTHLY_BYDAY_COUNT) ? $MONTHLY_BYDAY_COUNT : '',
328
    '#default_value' => !empty($monthly_byday_count) ? $monthly_byday_count : '',
324 329
    '#options' => date_order_translated(),
325 330
    '#multiple' => FALSE,
326 331
    '#prefix' => '<div class="date-repeat-input byday-count">',
327 332
    '#suffix' => '</div>',
328 333
  );
329 334

  
330
  $MONTHLY_on_the_BYDAY_of_BYMONTH['BYDAY_DAY'] = array(
335
  $monthly_on_the_byday_of_bymonth['BYDAY_DAY'] = array(
331 336
    '#type' => 'select',
332 337
    '#title' => $byday_day_title,
333 338
    '#title_display' => 'after',
334
    '#default_value' => !empty($MONTHLY_BYDAY_DAY) ? $MONTHLY_BYDAY_DAY : '',
339
    '#default_value' => !empty($monthly_byday_day) ? $monthly_byday_day : '',
335 340
    '#options' => date_repeat_dow_day_options(TRUE),
336 341
    '#multiple' => FALSE,
337 342
    '#prefix' => '<div class="date-repeat-input byday-day">',
338 343
    '#suffix' => '</div>',
339 344
  );
340 345

  
341
  $MONTHLY_on_the_BYDAY_of_BYMONTH['BYMONTH'] = array(
346
  $monthly_on_the_byday_of_bymonth['BYMONTH'] = array(
342 347
    '#type' => 'checkboxes',
343 348
    '#title' => t('Bymonth', array(), array('context' => 'Date repeat')),
344 349
    '#title_display' => 'invisible',
345
    '#default_value' => !empty($rrule['BYMONTH']) && $rrule['FREQ'] === 'MONTHLY' && $MONTHLY_day_month_default === 'BYDAY_BYMONTH' ? $rrule['BYMONTH'] : array(),
350
    '#default_value' => !empty($rrule['BYMONTH']) && $rrule['FREQ'] === 'MONTHLY' && $monthly_day_month_default === 'BYDAY_BYMONTH' ? $rrule['BYMONTH'] : array(),
346 351
    '#options' => date_month_names_abbr(TRUE),
347 352
    '#attributes' => array('class' => array('container-inline')),
348 353
    '#multiple' => TRUE,
......
361 366
      ),
362 367
    ),
363 368
    '#attributes' => array('class' => array('date-repeat-radios clearfix')),
364
    '#default_value' => $MONTHLY_day_month_default,
369
    '#default_value' => $monthly_day_month_default,
365 370
    '#options' => array(
366 371
      'BYMONTHDAY_BYMONTH' => t('On day ... of ...'),
367 372
      'BYDAY_BYMONTH' => t('On the ... of ...'),
368 373
    ),
369
    'BYMONTHDAY_BYMONTH_child' => $MONTHLY_on_day_BYMONTHDAY_of_BYMONTH,
370
    'BYDAY_BYMONTH_child' => $MONTHLY_on_the_BYDAY_of_BYMONTH,
374
    'BYMONTHDAY_BYMONTH_child' => $monthly_on_day_bymonthday_of_bymonth,
375
    'BYDAY_BYMONTH_child' => $monthly_on_the_byday_of_bymonth,
371 376
    '#div_classes' => array(
372 377
      'date-repeat-radios-item date-clear clearfix bymonthday-bymonth',
373 378
      'date-repeat-radios-item date-clear clearfix byday-bymonth',
374 379
    ),
375 380
  );
376 381

  
377
  $YEARLY_day_month_default = 'BYMONTHDAY_BYMONTH';
382
  $yearly_day_month_default = 'BYMONTHDAY_BYMONTH';
378 383
  if (isset($rrule['FREQ']) && $rrule['FREQ'] === 'YEARLY' && !empty($rrule['BYDAY'])) {
379
    $YEARLY_day_month_default = 'BYDAY_BYMONTH';
384
    $yearly_day_month_default = 'BYDAY_BYMONTH';
380 385
  }
381 386

  
382
  $YEARLY_on_day_BYMONTHDAY_of_BYMONTH = array(
387
  $yearly_on_day_bymonthday_of_bymonth = array(
383 388
    '#type' => 'container',
384 389
    '#tree' => TRUE,
385 390
  );
386 391

  
387 392
  list($bymonthday_title, $bymonthday_suffix) = explode('@bymonthday', t('On day @bymonthday of', array(), array('context' => 'Date repeat')));
388
  $YEARLY_on_day_BYMONTHDAY_of_BYMONTH['BYMONTHDAY'] = array(
393
  $yearly_on_day_bymonthday_of_bymonth['BYMONTHDAY'] = array(
389 394
    '#type' => 'select',
390 395
    '#title' => $bymonthday_title,
391 396
    '#default_value' => !empty($rrule['BYMONTHDAY']) && $rrule['FREQ'] === 'YEARLY' ? $rrule['BYMONTHDAY'] : '',
......
396 401
    '#field_suffix' => $bymonthday_suffix,
397 402
  );
398 403

  
399
  $YEARLY_on_day_BYMONTHDAY_of_BYMONTH['BYMONTH'] = array(
404
  $yearly_on_day_bymonthday_of_bymonth['BYMONTH'] = array(
400 405
    '#type' => 'checkboxes',
401 406
    '#title' => t('Bymonth', array(), array('context' => 'Date repeat')),
402 407
    '#title_display' => 'invisible',
403
    '#default_value' => !empty($rrule['BYMONTH']) && $rrule['FREQ'] === 'YEARLY' && $YEARLY_day_month_default === 'BYMONTHDAY_BYMONTH' ? $rrule['BYMONTH'] : array(),
408
    '#default_value' => !empty($rrule['BYMONTH']) && $rrule['FREQ'] === 'YEARLY' && $yearly_day_month_default === 'BYMONTHDAY_BYMONTH' ? $rrule['BYMONTH'] : array(),
404 409
    '#options' => date_month_names_abbr(TRUE),
405 410
    '#attributes' => array('class' => array('container-inline')),
406 411
    '#multiple' => TRUE,
......
408 413
    '#suffix' => '</div>',
409 414
  );
410 415

  
411
  $YEARLY_on_the_BYDAY_of_BYMONTH = array(
416
  $yearly_on_the_byday_of_bymonth = array(
412 417
    '#type' => 'container',
413 418
    '#tree' => TRUE,
414 419
  );
415 420

  
416
  $YEARLY_BYDAY_COUNT = '';
417
  $YEARLY_BYDAY_DAY = '';
421
  $yearly_byday_count = '';
422
  $yearly_byday_day = '';
418 423
  if (isset($rrule['BYDAY']) && !empty($rrule['BYDAY']) && $rrule['FREQ'] === 'YEARLY') {
419
    $YEARLY_BYDAY_COUNT = substr($rrule['BYDAY'][0], 0, -2);
420
    $YEARLY_BYDAY_DAY = substr($rrule['BYDAY'][0], -2);;
424
    $yearly_byday_count = substr($rrule['BYDAY'][0], 0, -2);
425
    $yearly_byday_day = substr($rrule['BYDAY'][0], -2);;
421 426
  }
422 427

  
423 428
  list($byday_count_title, $byday_day_title) = explode('@byday', t('On the @byday of', array(), array('context' => 'Date repeat')));
424
  $YEARLY_on_the_BYDAY_of_BYMONTH['BYDAY_COUNT'] = array(
429
  $yearly_on_the_byday_of_bymonth['BYDAY_COUNT'] = array(
425 430
    '#type' => 'select',
426 431
    '#title' => $byday_count_title,
427
    '#default_value' => !empty($YEARLY_BYDAY_COUNT) ? $YEARLY_BYDAY_COUNT : '',
432
    '#default_value' => !empty($yearly_byday_count) ? $yearly_byday_count : '',
428 433
    '#options' => date_order_translated(),
429 434
    '#multiple' => FALSE,
430 435
    '#prefix' => '<div class="date-repeat-input byday-count">',
431 436
    '#suffix' => '</div>',
432 437
  );
433 438

  
434
  $YEARLY_on_the_BYDAY_of_BYMONTH['BYDAY_DAY'] = array(
439
  $yearly_on_the_byday_of_bymonth['BYDAY_DAY'] = array(
435 440
    '#type' => 'select',
436 441
    '#title' => $byday_day_title,
437 442
    '#title_display' => 'after',
438
    '#default_value' => !empty($YEARLY_BYDAY_DAY) ? $YEARLY_BYDAY_DAY : '',
443
    '#default_value' => !empty($yearly_byday_day) ? $yearly_byday_day : '',
439 444
    '#options' => date_repeat_dow_day_options(TRUE),
440 445
    '#multiple' => FALSE,
441 446
    '#prefix' => '<div class="date-repeat-input byday-day">',
442 447
    '#suffix' => '</div>',
443 448
  );
444 449

  
445
  $YEARLY_on_the_BYDAY_of_BYMONTH['BYMONTH'] = array(
450
  $yearly_on_the_byday_of_bymonth['BYMONTH'] = array(
446 451
    '#type' => 'checkboxes',
447 452
    '#title' => t('Bymonth', array(), array('context' => 'Date repeat')),
448 453
    '#title_display' => 'invisible',
449
    '#default_value' => !empty($rrule['BYMONTH']) && $rrule['FREQ'] === 'YEARLY' && $YEARLY_day_month_default === 'BYDAY_BYMONTH' ? $rrule['BYMONTH'] : array(),
454
    '#default_value' => !empty($rrule['BYMONTH']) && $rrule['FREQ'] === 'YEARLY' && $yearly_day_month_default === 'BYDAY_BYMONTH' ? $rrule['BYMONTH'] : array(),
450 455
    '#options' => date_month_names_abbr(TRUE),
451 456
    '#attributes' => array('class' => array('container-inline')),
452 457
    '#multiple' => TRUE,
......
465 470
      ),
466 471
    ),
467 472
    '#attributes' => array('class' => array('date-repeat-radios clearfix')),
468
    '#default_value' => $YEARLY_day_month_default,
473
    '#default_value' => $yearly_day_month_default,
469 474
    '#options' => array(
470 475
      'BYMONTHDAY_BYMONTH' => t('On day ... of ...'),
471 476
      'BYDAY_BYMONTH' => t('On the ... of ...'),
472 477
    ),
473
    'BYMONTHDAY_BYMONTH_child' => $YEARLY_on_day_BYMONTHDAY_of_BYMONTH,
474
    'BYDAY_BYMONTH_child' => $YEARLY_on_the_BYDAY_of_BYMONTH,
478
    'BYMONTHDAY_BYMONTH_child' => $yearly_on_day_bymonthday_of_bymonth,
479
    'BYDAY_BYMONTH_child' => $yearly_on_the_byday_of_bymonth,
475 480
    '#div_classes' => array(
476 481
      'date-repeat-radios-item date-clear clearfix bymonthday-bymonth',
477 482
      'date-repeat-radios-item date-clear clearfix byday-bymonth',
......
482 487
  $count_form_element = array(
483 488
    '#type' => 'textfield',
484 489
    '#title' => t('Count', array(), array('context' => 'Date repeat')),
485
    '#default_value' => $COUNT,
490
    '#default_value' => $count,
486 491
    '#element_validate' => array('element_validate_integer_positive'),
487 492
    '#attributes' => array('placeholder' => array('#')),
488 493
    '#prefix' => $prefix,
......
499 504
      '#type' => $element['#date_repeat_widget'],
500 505
      '#title' => t('Until', array(), array('context' => 'Date repeat')),
501 506
      '#title_display' => 'invisible',
502
      '#default_value' => $UNTIL,
503
      '#date_format' => !empty($element['#date_format']) ? date_limit_format($element['#date_format'], array('year', 'month', 'day')) : 'Y-m-d',
507
      '#default_value' => $until,
508
      '#date_format' => !empty($element['#date_format']) ?
509
      date_limit_format($element['#date_format'], array('year', 'month', 'day')) : 'Y-m-d',
504 510
      '#date_timezone' => $timezone,
505 511
      '#date_text_parts'  => !empty($element['#date_text_parts']) ? $element['#date_text_parts'] : array(),
506 512
      '#date_year_range'  => !empty($element['#date_year_range']) ? $element['#date_year_range'] : '-3:+3',
507
      '#date_label_position' => !empty($element['#date_label_position']) ? $element['#date_label_position'] : 'within',
513
      '#date_label_position' => !empty($element['#date_label_position']) ?
514
      $element['#date_label_position'] : 'within',
508 515
      '#date_flexible' => 0,
509 516
    ),
510 517
    'tz' => array('#type' => 'hidden', '#value' => $element['#date_timezone']),
511 518
    'all_day' => array('#type' => 'hidden', '#value' => 1),
512
    'granularity' => array('#type' => 'hidden', '#value' => serialize(array('year', 'month', 'day'))),
519
    'granularity' => array(
520
      '#type' => 'hidden',
521
      '#value' => serialize(array('year', 'month', 'day')),
522
    ),
513 523
  );
514 524

  
515 525
  $range_of_repeat_default = 'COUNT';
516
  if (!empty($UNTIL)) {
526
  if (!empty($until)) {
517 527
    $range_of_repeat_default = 'UNTIL';
518 528
  }
519 529
  $element['range_of_repeat'] = array(
......
528 538
        ":input[name=\"{$element['#name']}[FREQ]\"]" => array('value' => 'NONE'),
529 539
      ),
530 540
    ),
531
    '#default_value' =>  $range_of_repeat_default,
541
    '#default_value' => $range_of_repeat_default,
532 542
    '#options' => array(
533 543
      'COUNT' => t('Count'),
534 544
      'UNTIL' => t('Until'),
......
544 554
  $parents = $element['#array_parents'];
545 555
  $instance = implode('-', $parents);
546 556

  
547
  // Make sure this will work right either in the normal form or in an ajax callback from the 'Add more' button.
557
  // Make sure this will work right either in the normal
558
  // form or in an ajax callback from the 'Add more' button.
548 559
  if (empty($form_state['num_exceptions'][$instance])) {
549 560
    $form_state['num_exceptions'][$instance] = count($exceptions);
550 561
  }
......
576 587
      ),
577 588
    ),
578 589
  );
579
  for ($i = 0; $i < max($form_state['num_exceptions'][$instance], 1) ; $i++) {
580
    $EXCEPT = '';
590
  for ($i = 0; $i < max($form_state['num_exceptions'][$instance], 1); $i++) {
591
    $except = '';
581 592
    if (!empty($exceptions[$i]['datetime'])) {
582 593
      $ex_date = new DateObject($exceptions[$i]['datetime'], $exceptions[$i]['tz']);
583 594
      date_timezone_set($ex_date, timezone_open($timezone));
584
      $EXCEPT = date_format($ex_date, DATE_FORMAT_DATETIME);
595
      $except = date_format($ex_date, DATE_FORMAT_DATETIME);
596
    }
597
    $date_format = 'Y-m-d';
598
    if (!empty($element['#date_format'])) {
599
      $grans = array('year', 'month', 'day');
600
      $date_format = date_limit_format($element['#date_format'], $grans);
585 601
    }
586 602
    $element['exceptions']['EXDATE'][$i] = array(
587 603
      '#tree' => TRUE,
588 604
      'datetime' => array(
589 605
        '#name' => 'exceptions|' . $instance,
590 606
        '#type' => $element['#date_repeat_widget'],
591
        '#default_value' => $EXCEPT,
592
        '#date_timezone' => !empty($element['#date_timezone']) ? $element['#date_timezone'] : date_default_timezone(),
593
        '#date_format' => !empty($element['#date_format']) ? date_limit_format($element['#date_format'], array('year', 'month', 'day')) : 'Y-m-d',
607
        '#default_value' => $except,
608
        '#date_timezone' => !empty($element['#date_timezone']) ?
609
        $element['#date_timezone'] : date_default_timezone(),
610
        '#date_format' => $date_format,
594 611
        '#date_text_parts'  => !empty($element['#date_text_parts']) ? $element['#date_text_parts'] : array(),
595 612
        '#date_year_range'  => !empty($element['#date_year_range']) ? $element['#date_year_range'] : '-3:+3',
596 613
        '#date_label_position' => !empty($element['#date_label_position']) ? $element['#date_label_position'] : 'within',
597 614
        '#date_flexible' => 0,
598
        ),
599
      'tz' => array('#type' => 'hidden', '#value' => $element['#date_timezone']),
600
      'all_day' => array('#type' => 'hidden', '#value' => 1),
601
      'granularity' => array('#type' => 'hidden', '#value' => serialize(array('year', 'month', 'day'))),
602
      );
615
      ),
616
      'tz' => array(
617
        '#type' => 'hidden',
618
        '#value' => $element['#date_timezone'],
619
      ),
620
      'all_day' => array(
621
        '#type' => 'hidden',
622
        '#value' => 1,
623
      ),
624
      'granularity' => array(
625
        '#type' => 'hidden',
626
        '#value' => serialize(array('year', 'month', 'day')),
627
      ),
628
    );
603 629
  }
604 630

  
605
  // collect additions in the same way as exceptions - implements RDATE.
631
  // Collect additions in the same way as exceptions - implements RDATE.
606 632
  if (empty($form_state['num_additions'][$instance])) {
607 633
    $form_state['num_additions'][$instance] = count($additions);
608 634
  }
......
634 660
      ),
635 661
    ),
636 662
  );
637
  for ($i = 0; $i < max($form_state['num_additions'][$instance], 1) ; $i++) {
638
    $RDATE = '';
663
  for ($i = 0; $i < max($form_state['num_additions'][$instance], 1); $i++) {
664
    $r_date = '';
639 665
    if (!empty($additions[$i]['datetime'])) {
640 666
      $rdate = new DateObject($additions[$i]['datetime'], $additions[$i]['tz']);
641 667
      date_timezone_set($rdate, timezone_open($timezone));
642
      $RDATE = date_format($rdate, DATE_FORMAT_DATETIME);
668
      $r_date = date_format($rdate, DATE_FORMAT_DATETIME);
669
    }
670
    $date_format = 'Y-m-d';
671
    if (!empty($element['#date_format'])) {
672
      $grans = array('year', 'month', 'day');
673
      $date_format = date_limit_format($element['#date_format'], $grans);
643 674
    }
644 675
    $element['additions']['RDATE'][$i] = array(
645 676
      '#tree' => TRUE,
646 677
      'datetime' => array(
647 678
        '#type' => $element['#date_repeat_widget'],
648 679
        '#name' => 'additions|' . $instance,
649
        '#default_value' => $RDATE,
650
        '#date_timezone' => !empty($element['#date_timezone']) ? $element['#date_timezone'] : date_default_timezone(),
651
        '#date_format' => !empty($element['#date_format']) ? date_limit_format($element['#date_format'], array('year', 'month', 'day')) : 'Y-m-d',
680
        '#default_value' => $r_date,
681
        '#date_timezone' => !empty($element['#date_timezone']) ?
682
        $element['#date_timezone'] : date_default_timezone(),
683
        '#date_format' => $date_format,
652 684
        '#date_text_parts'  => !empty($element['#date_text_parts']) ? $element['#date_text_parts'] : array(),
653 685
        '#date_year_range'  => !empty($element['#date_year_range']) ? $element['#date_year_range'] : '-3:+3',
654 686
        '#date_label_position' => !empty($element['#date_label_position']) ? $element['#date_label_position'] : 'within',
655 687
        '#date_flexible' => 0,
656
        ),
657
      'tz' => array('#type' => 'hidden', '#value' => $element['#date_timezone']),
658
      'all_day' => array('#type' => 'hidden', '#value' => 1),
659
      'granularity' => array('#type' => 'hidden', '#value' => serialize(array('year', 'month', 'day'))),
660
      );
688
      ),
689
      'tz' => array(
690
        '#type' => 'hidden',
691
        '#value' => $element['#date_timezone'],
692
      ),
693
      'all_day' => array(
694
        '#type' => 'hidden',
695
        '#value' => 1,
696
      ),
697
      'granularity' => array(
698
        '#type' => 'hidden',
699
        '#value' => serialize(array('year', 'month', 'day')),
700
      ),
701
    );
661 702
  }
662 703

  
663 704
  $element['exceptions']['exceptions_add'] = array(
......
687 728
  return $element;
688 729
}
689 730

  
731
/**
732
 * Add callback to date repeat.
733
 */
690 734
function date_repeat_add_exception_callback($form, &$form_state) {
691 735
  $parents = $form_state['triggering_element']['#array_parents'];
692 736
  $button_key = array_pop($parents);
......
694 738
  return $element;
695 739
}
696 740

  
741
/**
742
 * Add addition callback to date repeat.
743
 */
697 744
function date_repeat_add_addition_callback($form, &$form_state) {
698 745
  $parents = $form_state['triggering_element']['#array_parents'];
699 746
  $button_key = array_pop($parents);
......
701 748
  return $element;
702 749
}
703 750

  
751
/**
752
 * Add exception to date repeat.
753
 */
704 754
function date_repeat_add_exception($form, &$form_state) {
705 755
  $parents = $form_state['triggering_element']['#array_parents'];
706 756
  $instance = implode('-', array_slice($parents, 0, count($parents) - 2));
......
708 758
  $form_state['rebuild'] = TRUE;
709 759
}
710 760

  
761
/**
762
 * Add addition to date repeat.
763
 */
711 764
function date_repeat_add_addition($form, &$form_state) {
712 765
  $parents = $form_state['triggering_element']['#array_parents'];
713 766
  $instance = implode('-', array_slice($parents, 0, count($parents) - 2));
......
723 776
    return $form_values;
724 777
  }
725 778
  if (array_key_exists('exceptions', $form_values) || array_key_exists('additions', $form_values)) {
726
    if (!array_key_exists('exceptions', $form_values)) $form_values['exceptions'] = array();
727
    if (!array_key_exists('additions', $form_values)) $form_values['additions'] = array();
779
    if (!array_key_exists('exceptions', $form_values)) {
780
      $form_values['exceptions'] = array();
781
    }
782

  
783
    if (!array_key_exists('additions', $form_values)) {
784
      $form_values['additions'] = array();
785
    }
786

  
728 787
    $form_values = array_merge($form_values, (array) $form_values['exceptions'], (array) $form_values['additions']);
729 788
    unset($form_values['exceptions']);
730 789
    unset($form_values['additions']);
......
738 797
            case 'INTERVAL':
739 798
              $form_values['INTERVAL'] = $form_values['daily']['INTERVAL_child'];
740 799
              break;
800

  
741 801
            case 'every_weekday':
742 802
              $form_values['BYDAY'] = array('MO', 'TU', 'WE', 'TH', 'FR');
743 803
              break;
804

  
744 805
            case 'every_mo_we_fr':
745 806
              $form_values['BYDAY'] = array('MO', 'WE', 'FR');
746 807
              break;
808

  
747 809
            case 'every_tu_th':
748 810
              $form_values['BYDAY'] = array('TU', 'TH');
749 811
              break;
750 812
          }
751 813
        }
752 814
        break;
815

  
753 816
      case 'WEEKLY':
754 817
        if (array_key_exists('weekly', $form_values)) {
755 818
          $form_values = array_merge($form_values, (array) $form_values['weekly']);
......
758 821
          }
759 822
        }
760 823
        break;
824

  
761 825
      case 'MONTHLY':
762 826
        if (array_key_exists('monthly', $form_values)) {
763 827
          switch ($form_values['monthly']['day_month']) {
764 828
            case 'BYMONTHDAY_BYMONTH':
765 829
              $form_values['monthly'] = array_merge($form_values['monthly'], (array) $form_values['monthly']['BYMONTHDAY_BYMONTH_child']);
766 830
              break;
831

  
767 832
            case 'BYDAY_BYMONTH':
768 833
              $form_values['monthly']['BYDAY_BYMONTH_child']['BYDAY'] = $form_values['monthly']['BYDAY_BYMONTH_child']['BYDAY_COUNT'] . $form_values['monthly']['BYDAY_BYMONTH_child']['BYDAY_DAY'];
769 834
              $form_values['monthly'] = array_merge($form_values['monthly'], (array) $form_values['monthly']['BYDAY_BYMONTH_child']);
......
783 848
          }
784 849
        }
785 850
        break;
851

  
786 852
      case 'YEARLY':
787 853
        if (array_key_exists('yearly', $form_values)) {
788 854
          switch ($form_values['yearly']['day_month']) {
789 855
            case 'BYMONTHDAY_BYMONTH':
790 856
              $form_values['yearly'] = array_merge($form_values['yearly'], (array) $form_values['yearly']['BYMONTHDAY_BYMONTH_child']);
791 857
              break;
858

  
792 859
            case 'BYDAY_BYMONTH':
793 860
              $form_values['yearly']['BYDAY_BYMONTH_child']['BYDAY'] = $form_values['yearly']['BYDAY_BYMONTH_child']['BYDAY_COUNT'] . $form_values['yearly']['BYDAY_BYMONTH_child']['BYDAY_DAY'];
794 861
              $form_values['yearly'] = array_merge($form_values['yearly'], (array) $form_values['yearly']['BYDAY_BYMONTH_child']);
......
808 875
          }
809 876
        }
810 877
        break;
878

  
811 879
      default:
812 880
        break;
813 881
    }
......
823 891
      case 'COUNT':
824 892
        $form_values['COUNT'] = $form_values['count_child'];
825 893
        break;
894

  
826 895
      case 'UNTIL':
827 896
        $form_values['UNTIL'] = $form_values['until_child'];
828 897
        break;
......
832 901
  unset($form_values['count_child']);
833 902
  unset($form_values['until_child']);
834 903

  
835
  if (array_key_exists('BYDAY', $form_values) && is_array($form_values['BYDAY'])) unset($form_values['BYDAY']['']);
836
  if (array_key_exists('BYMONTH', $form_values) && is_array($form_values['BYMONTH'])) unset($form_values['BYMONTH']['']);
837
  if (array_key_exists('BYMONTHDAY', $form_values) && is_array($form_values['BYMONTHDAY'])) unset($form_values['BYMONTHDAY']['']);
904
  if (array_key_exists('BYDAY', $form_values) && is_array($form_values['BYDAY'])) {
905
    unset($form_values['BYDAY']['']);
906
  }
907

  
908
  if (array_key_exists('BYMONTH', $form_values) && is_array($form_values['BYMONTH'])) {
909
    unset($form_values['BYMONTH']['']);
910
  }
911

  
912
  if (array_key_exists('BYMONTHDAY', $form_values) && is_array($form_values['BYMONTHDAY'])) {
913
    unset($form_values['BYMONTHDAY']['']);
914
  }
838 915

  
839 916
  if (array_key_exists('UNTIL', $form_values) && is_array($form_values['UNTIL']['datetime'])) {
840 917
    $function = $element['#date_repeat_widget'] . '_input_date';
841 918
    $until_element = $element;
842
    $until_element['#date_format'] = !empty($element['#date_format']) ? date_limit_format($element['#date_format'], array('year', 'month', 'day')) : 'Y-m-d';
919
    $until_element['#date_format'] = !empty($element['#date_format']) ?
920
    date_limit_format($element['#date_format'], array('year', 'month', 'day')) : 'Y-m-d';
843 921
    $date = $function($until_element, $form_values['UNTIL']['datetime']);
844 922
    $form_values['UNTIL']['datetime'] = is_object($date) ? $date->format(DATE_FORMAT_DATETIME) : '';
845 923
  }
......
849 927
  if (array_key_exists('EXDATE', $form_values) && is_array($form_values['EXDATE'])) {
850 928
    $function = $element['#date_repeat_widget'] . '_input_date';
851 929
    $exdate_element = $element;
930
    $date_format = 'Y-m-d';
931
    if (!empty($element['#date_format'])) {
932
      $grans = array('year', 'month', 'day');
933
      $date_format = date_limit_format($element['#date_format'], $grans);
934
    }
852 935
    foreach ($form_values['EXDATE'] as $delta => $value) {
853 936
      if (is_array($value['datetime'])) {
854
        $exdate_element['#date_format'] = !empty($element['#date_format']) ? date_limit_format($element['#date_format'], array('year', 'month', 'day')) : 'Y-m-d';
937
        $exdate_element['#date_format'] = $date_format;
855 938
        $date = $function($exdate_element, $form_values['EXDATE'][$delta]['datetime']);
856 939
        $form_values['EXDATE'][$delta]['datetime'] = is_object($date) ? $date->format(DATE_FORMAT_DATETIME) : '';
857 940
      }
......
864 947
  if (array_key_exists('RDATE', $form_values) && is_array($form_values['RDATE'])) {
865 948
    $function = $element['#date_repeat_widget'] . '_input_date';
866 949
    $rdate_element = $element;
950
    $date_format = 'Y-m-d';
951
    if (!empty($element['#date_format'])) {
952
      $grans = array('year', 'month', 'day');
953
      $date_format = date_limit_format($element['#date_format'], $grans);
954
    }
867 955
    foreach ($form_values['RDATE'] as $delta => $value) {
868 956
      if (is_array($value['datetime'])) {
869
        $rdate_element['#date_format'] = !empty($element['#date_format']) ? date_limit_format($element['#date_format'], array('year', 'month', 'day')) : 'Y-m-d';
957
        $rdate_element['#date_format'] = $date_format;
870 958
        $date = $function($rdate_element, $form_values['RDATE'][$delta]['datetime']);
871 959
        $form_values['RDATE'][$delta]['datetime'] = is_object($date) ? $date->format(DATE_FORMAT_DATETIME) : '';
872 960
      }
......
910 998
}
911 999

  
912 1000
/**
913
 * Theme the exception list as a table so the buttons line up
1001
 * Theme the exception list as a table so the buttons line up.
914 1002
 */
915 1003
function theme_date_repeat_current_exceptions($vars) {
916 1004
  $rows = $vars['rows'];
......
920 1008
      $rows_info[] = array(drupal_render($value['action']), drupal_render($value['display']));
921 1009
    }
922 1010
  }
923
  return theme('table', array('header' => array(t('Delete'), t('Current exceptions')), 'rows' => $rows_info));
1011
  return theme('table', array(
1012
    'header' => array(t('Delete'), t('Current exceptions')),
1013
    'rows' => $rows_info)
1014
  );
924 1015
}
925 1016

  
926
 /**
927
 * Theme the exception list as a table so the buttons line up
1017
/**
1018
 * Theme the exception list as a table so the buttons line up.
928 1019
 */
929 1020
function theme_date_repeat_current_additions($rows = array()) {
930 1021
  $rows_info = array();
......
933 1024
      $rows_info[] = array(drupal_render($value['action']), drupal_render($value['display']));
934 1025
    }
935 1026
  }
936
  return theme('table', array('header' => array(t('Delete'), t('Current additions')), 'rows' => $rows_info));
1027
  return theme('table', array(
1028
    'header' => array(t('Delete'), t('Current additions')),
1029
    'rows' => $rows_info)
1030
  );
937 1031
}
938 1032

  
939 1033
/**
......
943 1037
  $element = $vars['element'];
944 1038
  $id = drupal_html_id('repeat-settings-fieldset');
945 1039
  $parents = $element['#parents'];
946
  $selector = "{$parents[0]}[{$parents[1]}][{$parents[2]}][show_repeat_settings]";
1040

  
1041
  $selector = $parents[0];
1042
  for ($i = 1; $i < count($parents) - 1; $i++) {
1043
    $selector .= '[' . $parents[$i] . ']';
1044
  }
1045
  $selector .= '[show_repeat_settings]';
1046

  
947 1047
  $fieldset = array(
948 1048
    '#type' => 'item',
949 1049
    '#title' => t('Repeat settings'),
......
960 1060
  return drupal_render($fieldset);
961 1061
}
962 1062

  
1063
/**
1064
 * Filter non zero values.
1065
 */
963 1066
function date_repeat_filter_non_zero_value($value) {
964 1067
  return $value !== 0;
965 1068
}

Formats disponibles : Unified diff