Development

Changeset 953

You must first sign up to be able to contribute.

Changeset 953

Show
Ignore:
Timestamp:
03/07/06 12:22:23 (3 years ago)
Author:
fabien
Message:

upgraded to scriptaculous 1.5.3

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGELOG

    r847 r953  
    55------------- 
    66 
     7* [fabien] lot of bugs fixes 
     8* [faiben] updated scriptaculous to 1.5.3 
     9* [fabien] added a new sfFileValidator validator 
     10* [fabien] lots of bug fixes and new features in the admin generator (file upload, credentials, ...) 
    711* [fabien] stylesheets, javascripts, ... are now part of the sfWebResponse object 
    812           DEPRECATED methods: 
  • trunk/data/web/sf/js/prototype/controls.js

    r500 r953  
    153153  }, 
    154154 
     155  activate: function() { 
     156    this.changed = false; 
     157    this.hasFocus = true; 
     158    this.getUpdatedChoices(); 
     159  }, 
     160 
    155161  onHover: function(event) { 
    156162    var element = Event.findElement(event, 'LI'); 
     
    311317Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), { 
    312318  initialize: function(element, update, url, options) { 
    313    this.baseInitialize(element, update, options); 
     319    this.baseInitialize(element, update, options); 
    314320    this.options.asynchronous  = true; 
    315321    this.options.onComplete    = this.onComplete.bind(this); 
     
    478484      highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor, 
    479485      highlightendcolor: "#FFFFFF", 
    480       externalControl: null, 
     486      externalControl: null, 
    481487      submitOnBlur: false, 
    482       ajaxOptions: {} 
     488      ajaxOptions: {}, 
     489      evalScripts: false 
    483490    }, options || {}); 
    484491 
     
    549556      okButton.type = "submit"; 
    550557      okButton.value = this.options.okText; 
     558      okButton.className = 'editor_ok_button'; 
    551559      this.form.appendChild(okButton); 
    552560    } 
     
    557565      cancelLink.appendChild(document.createTextNode(this.options.cancelText)); 
    558566      cancelLink.onclick = this.onclickCancel.bind(this); 
     567      cancelLink.className = 'editor_cancel';       
    559568      this.form.appendChild(cancelLink); 
    560569    } 
     
    585594      textField.value = text; 
    586595      textField.style.backgroundColor = this.options.highlightcolor; 
     596      textField.className = 'editor_field'; 
    587597      var size = this.options.size || this.options.cols || 0; 
    588598      if (size != 0) textField.size = size; 
     
    598608      textArea.rows = this.options.rows; 
    599609      textArea.cols = this.options.cols || 40; 
     610      textArea.className = 'editor_field';       
    600611      if (this.options.submitOnBlur) 
    601612        textArea.onblur = this.onSubmit.bind(this); 
     
    650661    this.onLoading(); 
    651662     
    652     new Ajax.Updater( 
    653       {  
    654         success: this.element, 
    655          // don't update on failure (this could be an option) 
    656         failure: null 
    657       }, 
    658       this.url, 
    659       Object.extend({ 
    660         parameters: this.options.callback(form, value), 
    661         onComplete: this.onComplete.bind(this), 
    662         onFailure: this.onFailure.bind(this) 
    663       }, this.options.ajaxOptions) 
    664     ); 
     663    if (this.options.evalScripts) { 
     664      new Ajax.Request( 
     665        this.url, Object.extend({ 
     666          parameters: this.options.callback(form, value), 
     667          onComplete: this.onComplete.bind(this), 
     668          onFailure: this.onFailure.bind(this), 
     669          asynchronous:true,  
     670          evalScripts:true 
     671        }, this.options.ajaxOptions)); 
     672    } else  { 
     673      new Ajax.Updater( 
     674        { success: this.element, 
     675          // don't update on failure (this could be an option) 
     676          failure: null },  
     677        this.url, Object.extend({ 
     678          parameters: this.options.callback(form, value), 
     679          onComplete: this.onComplete.bind(this), 
     680          onFailure: this.onFailure.bind(this) 
     681        }, this.options.ajaxOptions)); 
     682    } 
    665683    // stop the event to avoid a page refresh in Safari 
    666684    if (arguments.length > 1) { 
     
    743761  } 
    744762}; 
     763 
     764Ajax.InPlaceCollectionEditor = Class.create(); 
     765Object.extend(Ajax.InPlaceCollectionEditor.prototype, Ajax.InPlaceEditor.prototype); 
     766Object.extend(Ajax.InPlaceCollectionEditor.prototype, { 
     767  createEditField: function() { 
     768    if (!this.cached_selectTag) { 
     769      var selectTag = document.createElement("select"); 
     770      var collection = this.options.collection || []; 
     771      var optionTag; 
     772      collection.each(function(e,i) { 
     773        optionTag = document.createElement("option"); 
     774        optionTag.value = (e instanceof Array) ? e[0] : e; 
     775        if(this.options.value==optionTag.value) optionTag.selected = true; 
     776        optionTag.appendChild(document.createTextNode((e instanceof Array) ? e[1] : e)); 
     777        selectTag.appendChild(optionTag); 
     778      }.bind(this)); 
     779      this.cached_selectTag = selectTag; 
     780    } 
     781 
     782    this.editField = this.cached_selectTag; 
     783    if(this.options.loadTextURL) this.loadExternalText(); 
     784    this.form.appendChild(this.editField); 
     785    this.options.callback = function(form, value) { 
     786      return "value=" + encodeURIComponent(value); 
     787    } 
     788  } 
     789}); 
    745790 
    746791// Delayed observer, like Form.Element.Observer,  
  • trunk/data/web/sf/js/prototype/dragdrop.js

    r500 r953  
    129129  }, 
    130130   
    131   deactivate: function(draggbale) { 
     131  deactivate: function() { 
    132132    this.activeDraggable = null; 
    133133  }, 
     
    200200      zindex: 1000, 
    201201      revert: false, 
     202      scroll: false, 
     203      scrollSensitivity: 20, 
     204      scrollSpeed: 15, 
    202205      snap: false   // false, or xy or [x,y] or function(x,y){ return [x,y] } 
    203206    }, arguments[1] || {}); 
     
    209212    if(!this.handle) this.handle = $(options.handle); 
    210213    if(!this.handle) this.handle = this.element; 
     214     
     215    if(options.scroll) options.scroll = $(options.scroll); 
    211216 
    212217    Element.makePositioned(this.element); // fix IE     
     
    240245        src.tagName=='INPUT' || 
    241246        src.tagName=='SELECT' || 
     247        src.tagName=='OPTION' || 
    242248        src.tagName=='BUTTON' || 
    243249        src.tagName=='TEXTAREA')) return; 
     
    271277    } 
    272278     
     279    if(this.options.scroll) { 
     280      this.originalScrollLeft = this.options.scroll.scrollLeft; 
     281      this.originalScrollTop = this.options.scroll.scrollTop; 
     282    } 
     283     
    273284    Draggables.notify('onStart', this, event); 
    274285    if(this.options.starteffect) this.options.starteffect(this.element); 
     
    283294    if(this.options.change) this.options.change(this); 
    284295     
     296    if(this.options.scroll) { 
     297      //if(this.scrollInterval) this.scroll(); 
     298      this.stopScrolling(); 
     299      var p = Position.page(this.options.scroll); 
     300      p[0] += this.options.scroll.scrollLeft; 
     301      p[1] += this.options.scroll.scrollTop; 
     302      p.push(p[0]+this.options.scroll.offsetWidth); 
     303      p.push(p[1]+this.options.scroll.offsetHeight); 
     304      var speed = [0,0]; 
     305      if(pointer[0] < (p[0]+this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[0]+this.options.scrollSensitivity); 
     306      if(pointer[1] < (p[1]+this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[1]+this.options.scrollSensitivity); 
     307      if(pointer[0] > (p[2]-this.options.scrollSensitivity)) speed[0] = pointer[0]-(p[2]-this.options.scrollSensitivity); 
     308      if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity); 
     309      this.startScrolling(speed); 
     310    } 
     311     
    285312    // fix AppleWebKit rendering 
    286313    if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); 
     314     
    287315    Event.stop(event); 
    288316  }, 
     
    322350   
    323351  keyPress: function(event) { 
    324     if(!event.keyCode==Event.KEY_ESC) return; 
     352    if(event.keyCode!=Event.KEY_ESC) return; 
    325353    this.finishDrag(event, false); 
    326354    Event.stop(event); 
     
    329357  endDrag: function(event) { 
    330358    if(!this.dragging) return; 
     359    this.stopScrolling(); 
    331360    this.finishDrag(event, true); 
    332361    Event.stop(event); 
     
    338367    pos[0] -= d[0]; pos[1] -= d[1]; 
    339368     
    340     var p = [0,1].map(function(i){ return (point[i]-pos[i]-this.offset[i]) }.bind(this)); 
     369    if(this.options.scroll) { 
     370      pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft; 
     371      pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop; 
     372    } 
     373     
     374    var p = [0,1].map(function(i){  
     375      return (point[i]-pos[i]-this.offset[i])  
     376    }.bind(this)); 
    341377     
    342378    if(this.options.snap) { 
     
    359395      style.top  = p[1] + "px"; 
    360396    if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering 
     397  }, 
     398   
     399  stopScrolling: function() { 
     400    if(this.scrollInterval) { 
     401      clearInterval(this.scrollInterval); 
     402      this.scrollInterval = null; 
     403    } 
     404  }, 
     405   
     406  startScrolling: function(speed) { 
     407    this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed]; 
     408    this.lastScrolled = new Date(); 
     409    this.scrollInterval = setInterval(this.scroll.bind(this), 10); 
     410  }, 
     411   
     412  scroll: function() { 
     413    var current = new Date(); 
     414    var delta = current - this.lastScrolled; 
     415    this.lastScrolled = current; 
     416    this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000; 
     417    this.options.scroll.scrollTop  += this.scrollSpeed[1] * delta / 1000; 
     418     
     419    Position.prepare(); 
     420    Droppables.show(Draggables._lastPointer, this.element); 
     421    Draggables.notify('onDrag', this); 
     422    this.draw(Draggables._lastPointer);     
     423     
     424    if(this.options.change) this.options.change(this); 
    361425  } 
    362426} 
     
    415479      hoverclass:  null, 
    416480      ghosting:    false, 
    417       format:      null, 
     481      scroll:      false, 
     482      format:      /^[^_]*_(.*)$/, 
    418483      onChange:    Prototype.emptyFunction, 
    419484      onUpdate:    Prototype.emptyFunction 
     
    426491    var options_for_draggable = { 
    427492      revert:      true, 
     493      scroll:      options.scroll, 
    428494      ghosting:    options.ghosting, 
    429495      constraint:  options.constraint, 
     
    569635  }, 
    570636 
     637  sequence: function(element) { 
     638    element = $(element); 
     639    var options = Object.extend(this.options(element), arguments[1] || {}); 
     640     
     641    return $(this.findElements(element, options) || []).map( function(item) { 
     642      return item.id.match(options.format) ? item.id.match(options.format)[1] : ''; 
     643    }); 
     644  }, 
     645 
     646  setSequence: function(element, new_sequence) { 
     647    element = $(element); 
     648    var options = Object.extend(this.options(element), arguments[2] || {}); 
     649     
     650    var nodeMap = {}; 
     651    this.findElements(element, options).each( function(n) { 
     652        if (n.id.match(options.format)) 
     653            nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode]; 
     654        n.parentNode.removeChild(n); 
     655    }); 
     656    
     657    new_sequence.each(function(ident) { 
     658        var n = nodeMap[ident]; 
     659        if (n) { 
     660            n[1].appendChild(n[0]); 
     661            delete nodeMap[ident]; 
     662        } 
     663    }); 
     664  }, 
     665 
    571666  serialize: function(element) { 
    572667    element = $(element); 
    573     var sortableOptions = this.options(element); 
    574     var options = Object.extend({ 
    575       tag:  sortableOptions.tag, 
    576       only: sortableOptions.only, 
    577       name: element.id, 
    578       format: sortableOptions.format || /^[^_]*_(.*)$/ 
    579     }, arguments[1] || {}); 
    580     return $(this.findElements(element, options) || []).map( function(item) { 
    581       return (encodeURIComponent(options.name) + "[]=" +  
    582               encodeURIComponent(item.id.match(options.format) ? item.id.match(options.format)[1] : '')); 
    583     }).join("&"); 
     668    var name = encodeURIComponent( 
     669      (arguments[1] && arguments[1].name) ? arguments[1].name : element.id); 
     670    return Sortable.sequence(element, arguments[1]).map( function(item) { 
     671      return name + "[]=" + encodeURIComponent(item); 
     672    }).join('&'); 
    584673  } 
    585674} 
  • trunk/data/web/sf/js/prototype/effects.js

    r500 r953  
    3636    return (node.nodeType==3 ? node.nodeValue :  
    3737      ((node.hasChildNodes() && !Element.hasClassName(node,className)) ?  
    38         Element.collectTextNodes(node) : '')); 
     38        Element.collectTextNodesIgnoreClass(node, className) : '')); 
    3939  }).flatten().join(''); 
    4040} 
     
    138138    effect = (effect || 'appear').toLowerCase(); 
    139139    var options = Object.extend({ 
    140       queue: { position:'end', scope:(element.id || 'global')
     140      queue: { position:'end', scope:(element.id || 'global'), limit: 1
    141141    }, arguments[2] || {}); 
    142142    Effect[Element.visible(element) ?  
     
    210210    effect.startOn  += timestamp; 
    211211    effect.finishOn += timestamp; 
    212     this.effects.push(effect); 
     212 
     213    if(!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit)) 
     214      this.effects.push(effect); 
     215     
    213216    if(!this.interval)  
    214217      this.interval = setInterval(this.loop.bind(this), 40); 
     
    582585Effect.BlindDown = function(element) { 
    583586  element = $(element); 
    584   var oldHeight = Element.getStyle(element, 'height'); 
    585587  var elementDimensions = Element.getDimensions(element); 
    586588  return new Effect.Scale(element, 100,  
     
    595597        show(effect.element);  
    596598      }},   
    597       afterFinishInternal: function(effect) { with(Element) { 
    598         undoClipping(effect.element); 
    599         setStyle(effect.element, {height: oldHeight}); 
    600       }} 
     599      afterFinishInternal: function(effect) { 
     600        Element.undoClipping(effect.element); 
     601      } 
    601602    }, arguments[1] || {}) 
    602603  ); 
     
    691692    afterFinishInternal: function(effect) { with(Element) { 
    692693      undoClipping(effect.element);  
    693       undoPositioned(effect.element.firstChild); 
    694       undoPositioned(effect.element); 
     694      // IE will crash if child is undoPositioned first 
     695      if(/MSIE/.test(navigator.userAgent)){ 
     696        undoPositioned(effect.element); 
     697        undoPositioned(effect.element.firstChild); 
     698      }else{ 
     699        undoPositioned(effect.element.firstChild); 
     700        undoPositioned(effect.element); 
     701      } 
    695702      setStyle(effect.element.firstChild, {bottom: oldInnerBottom}); }} 
    696703    }, arguments[1] || {}) 
     
    742749  var options = Object.extend({ 
    743750    direction: 'center', 
    744     moveTransistion: Effect.Transitions.sinoidal, 
     751    moveTransition: Effect.Transitions.sinoidal, 
    745752    scaleTransition: Effect.Transitions.sinoidal, 
    746753    opacityTransition: Effect.Transitions.full 
     
    818825  var options = Object.extend({ 
    819826    direction: 'center', 
    820     moveTransistion: Effect.Transitions.sinoidal, 
     827    moveTransition: Effect.Transitions.sinoidal, 
    821828    scaleTransition: Effect.Transitions.sinoidal, 
    822829    opacityTransition: Effect.Transitions.none 
  • trunk/data/web/sf/js/prototype/scriptaculous.js

    r500 r953  
    2121 
    2222var Scriptaculous = { 
    23   Version: '1.5.1', 
     23  Version: '1.5.3', 
    2424  require: function(libraryName) { 
    2525    // inserting via DOM fails in Safari 2.0, so brute force approach 
  • trunk/data/web/sf/js/prototype/slider.js

    r500 r953  
    201201    if(this.isVertical()) { 
    202202      span.style.top = this.translateToPx(range.start); 
    203       span.style.height = this.translateToPx(range.end - range.start); 
     203      span.style.height = this.translateToPx(range.end - range.start + this.range.start); 
    204204    } else { 
    205205      span.style.left = this.translateToPx(range.start); 
    206       span.style.width = this.translateToPx(range.end - range.start); 
     206      span.style.width = this.translateToPx(range.end - range.start + this.range.start); 
    207207    } 
    208208  }, 
  • trunk/lib/helper/FormHelper.php

    r911 r953  
    537537} 
    538538 
     539function select_day_tag($name, $value, $options = array(), $html_options = array()) 
     540{ 
     541  $select_options = array(); 
     542 
     543  if (_get_option($options, 'include_blank')) 
     544  { 
     545    $select_options[''] = ''; 
     546  } 
     547  else if ($include_custom = _get_option($options, 'include_custom')) 
     548  { 
     549    $select_options[''] = $include_custom; 
     550  } 
     551 
     552  for ($x = 1; $x < 32; $x++) 
     553  { 
     554    $select_options[$x] = _add_zeros($x, 2); 
     555  } 
     556 
     557  $option_tags = options_for_select($select_options, $value); 
     558 
     559  return select_tag($name, $option_tags, $html_options); 
     560} 
     561 
     562function select_month_tag($name, $value, $options = array(), $html_options = array()) 
     563{ 
     564 
     565  $culture = _get_option($options, 'culture', sfContext::getInstance()->getUser()->getCulture()); 
     566 
     567  $I18n_arr = _get_I18n_date_locales($culture); 
     568 
     569  $select_options = array(); 
     570 
     571  if (_get_option($options, 'include_blank')) 
     572  { 
     573    $select_options[''] = ''; 
     574  } 
     575  else if ($include_custom = _get_option($options, 'include_custom')) 
     576  { 
     577    $select_options[''] = $include_custom; 
     578  } 
     579 
     580  if (_get_option($options, 'use_month_numbers'))  
     581  { 
     582    for ($k = 1; $k < 13; $k++)  
     583    { 
     584      $select_options[$k] = _add_zeros($k, 2); 
     585    } 
     586  } 
     587  else 
     588  {   
     589    if (_get_option($options, 'use_short_month'))  
     590    { 
     591      $month_names = $I18n_arr['dateFormatInfo']->getAbbreviatedMonthNames(); 
     592    } 
     593    else 
     594    { 
     595      $month_names = $I18n_arr['dateFormatInfo']->getMonthNames(); 
     596    } 
     597 
     598    $add_month_numbers = _get_option($options, 'add_month_numbers'); 
     599    foreach ($month_names as $k => $v)  
     600    { 
     601      $select_options[$k + 1] = ($add_month_numbers) ? ($k + 1 . ' - ' . $v) : $v; 
     602    } 
     603  } 
     604 
     605  $option_tags = options_for_select($select_options, $value); 
     606 
     607  return select_tag($name, $option_tags, $html_options); 
     608} 
     609 
     610function select_year_tag($name, $value, $options = array(), $html_options = array()) 
     611{ 
     612  $select_options = array(); 
     613 
     614  if (_get_option($options, 'include_blank')) 
     615  { 
     616    $select_options[''] = ''; 
     617  } 
     618  else if ($include_custom = _get_option($options, 'include_custom')) 
     619  { 
     620    $select_options[''] = $include_custom; 
     621  } 
     622 
     623  if (strlen($value) > 0 && is_numeric($value)) 
     624  { 
     625    $year_origin = $value; 
     626  } 
     627  else 
     628  { 
     629    $year_origin = date('Y'); 
     630  } 
     631 
     632  $year_start = _get_option($options, 'year_start', $year_origin - 5); 
     633  $year_end = _get_option($options, 'year_end', $year_origin + 5); 
     634 
     635  $ascending = ($year_start < $year_end); 
     636  $until_year = ($ascending) ? $year_end + 1 : $year_end - 1; 
     637 
     638  for ($x = $year_start; $x != $until_year; ($ascending) ? $x++ : $x--) 
     639  { 
     640    $select_options[$x] = $x; 
     641  } 
     642 
     643  $option_tags = options_for_select($select_options, $value); 
     644 
     645  return select_tag($name, $option_tags, $html_options); 
     646} 
     647 
     648/** 
     649 * Enter description here... 
     650 * 
     651 * @param string $name 
     652 * @param string $value (proper date format: array('year'=>2005, 'month'=>1, 'day'=1) or timestamp or english date text) 
     653 * @param array $options 
     654 * @return string 
     655 */ 
     656function select_date_tag($name, $value, $options = array(), $html_options = array()) 
     657{ 
     658  $html_options = _parse_attributes($html_options); 
     659  $options = _parse_attributes($options); 
     660 
     661  $culture = _get_option($options, 'culture', sfContext::getInstance()->getUser()->getCulture()); 
     662  //set it back for month tag 
     663  $option['culture'] = $culture; 
     664 
     665  $I18n_arr = _get_I18n_date_locales($culture); 
     666 
     667  $date_seperator = _get_option($options, 'date_seperator', $I18n_arr['date_seperator']); 
     668 
     669  $discard_month = _get_option($options, 'discard_month'); 
     670  $discard_day = _get_option($options, 'discard_day'); 
     671  $discard_year = _get_option($options, 'discard_year'); 
     672 
     673  //discarding month automatically discards day 
     674  if ($discard_month)  
     675    $discard_day = true; 
     676 
     677  $order = _get_option($options, 'order'); 
     678 
     679  $tags = array(); 
     680 
     681  if (is_array($order) && count($order) == 3) 
     682  { 
     683    foreach ($order as $k => $v) 
     684    { 
     685      $tags[] = $v[0]; //'day' => 'd' | 'month' => 'm' 
     686    } 
     687  } 
     688  else 
     689  { 
     690    $tags = $I18n_arr['date_order']; 
     691  } 
     692 
     693  if ($include_custom = _get_option($options, 'include_custom')) 
     694  { 
     695    $include_custom_month = (is_array($include_custom)) 
     696        ? ((isset($include_custom['month'])) ? array('include_custom'=>$include_custom['month']) : array())  
     697        : array('include_custom'=>$include_custom); 
     698 
     699    $include_custom_day = (is_array($include_custom)) 
     700        ? ((isset($include_custom['day'])) ? array('include_custom'=>$include_custom['day']) : array())  
     701        : array('include_custom'=>$include_custom); 
     702 
     703    $include_custom_year = (is_array($include_custom)) 
     704        ? ((isset($include_custom['year'])) ? array('include_custom'=>$include_custom['year']) : array())  
     705        : array('include_custom'=>$include_custom); 
     706  } 
     707  else 
     708  { 
     709    $include_custom_month = array(); 
     710    $include_custom_day = array(); 
     711    $include_custom_year = array(); 
     712  } 
     713 
     714  $html_options['id'] = $name . '_month'; 
     715  $m = ($discard_month != true) ? select_month_tag($name . '[month]', _parse_value_for_date($value, 'month', 'm'), $options + $include_custom_month, $html_options) : ''; 
     716 
     717  $html_options['id'] = $name . '_day'; 
     718  $d = ($discard_day != true) ? select_day_tag($name . '[day]', _parse_value_for_date($value, 'day', 'd'), $options + $include_custom_day, $html_options) : ''; 
     719 
     720  $html_options['id'] = $name . '_year'; 
     721  $y = ($discard_year != true) ? select_year_tag($name . '[year]', _parse_value_for_date($value, 'year', 'Y'), $options + $include_custom_year, $html_options) : ''; 
     722 
     723  //we have $tags = array ('m','d','y') 
     724  foreach ($tags as $k => $v) 
     725  { 
     726    $tags[$k] = $$v; 
     727  } 
     728 
     729  return implode($date_seperator, $tags); 
     730} 
     731 
     732function select_second_tag($name, $value, $options = array(), $html_options = array()) 
     733{ 
     734  $select_options = array(); 
     735 
     736  if (_get_option($options, 'include_blank')) 
     737  { 
     738    $select_options[''] = ''; 
     739  } 
     740  else if ($include_custom = _get_option($options, 'include_custom')) 
     741  { 
     742    $select_options[''] = $include_custom; 
     743  } 
     744 
     745  $second_step = _get_option($options, 'second_step', 1); 
     746  for ($x = 0; $x < 60; $x += $second_step) 
     747  { 
     748    $select_options[$x] = _add_zeros($x, 2); 
     749  } 
     750 
     751  $option_tags = options_for_select($select_options, $value); 
     752 
     753  return select_tag($name, $option_tags, $html_options); 
     754} 
     755 
     756function select_minute_tag($name, $value, $options = array(), $html_options = array()) 
     757{ 
     758  $select_options = array(); 
     759 
     760  if (_get_option($options, 'include_blank')) 
     761  { 
     762    $select_options[''] = ''; 
     763  } 
     764  else if ($include_custom = _get_option($options, 'include_custom')) 
     765  { 
     766    $select_options[''] = $include_custom; 
     767  } 
     768 
     769  $minute_step = _get_option($options, 'minute_step', 1); 
     770  for ($x = 0; $x < 60; $x += $minute_step) 
     771  { 
     772    $select_options[$x] = _add_zeros($x, 2); 
     773  } 
     774 
     775  $option_tags = options_for_select($select_options, $value); 
     776 
     777  return select_tag($name, $option_tags, $html_options); 
     778} 
     779 
     780function select_hour_tag($name, $value, $options = array(), $html_options = array()) 
     781{ 
     782  $select_options = array(); 
     783 
     784  if (_get_option($options, 'include_blank')) 
     785  { 
     786    $select_options[''] = ''; 
     787  } 
     788  else if ($include_custom = _get_option($options, 'include_custom')) 
     789  { 
     790    $select_options[''] = $include_custom; 
     791  } 
     792 
     793  $_12hour_time = _get_option($options, '12hour_time'); 
     794 
     795  $start_hour = ($_12hour_time) ? 1 : 0; 
     796  $end_hour = ($_12hour_time) ? 12 : 23; 
     797 
     798  for ($x = $start_hour; $x <= $end_hour; $x++) 
     799  { 
     800    $select_options[$x] = _add_zeros($x, 2); 
     801  } 
     802 
     803  $option_tags = options_for_select($select_options, $value); 
     804 
     805  return select_tag($name, $option_tags, $html_options); 
     806} 
     807 
     808function select_ampm_tag($name, $value, $options = array(), $html_options = array()) 
     809{ 
     810  $select_options = array(); 
     811 
     812  if (_get_option($options, 'include_blank')) 
     813  { 
     814    $select_options[''] = ''; 
     815  } 
     816  else if ($include_custom = _get_option($options, 'include_custom')) 
     817  { 
     818    $select_options[''] = $include_custom; 
     819  } 
     820 
     821  $select_options['AM'] = 'AM'; 
     822  $select_options['PM'] = 'PM'; 
     823 
     824  $option_tags = options_for_select($select_options, $value); 
     825 
     826  return select_tag($name, $option_tags, $html_options); 
     827} 
     828 
     829/** 
     830 * Enter description here... 
     831 * 
     832 * @param string $name 
     833 * @param string $value (proper time format: array('hour'=>0, 'minute'=>0, 'second'=0) or timestamp or english date text) 
     834 * @param array $options 
     835 * @return string 
     836 */ 
     837function select_time_tag($name, $value, $options = array(), $html_options = array()) 
     838{ 
     839  $html_options = _parse_attributes($html_options); 
     840  $options = _parse_attributes($options); 
     841 
     842  $time_seperator = _get_option($options, 'time_seperator', ':'); 
     843  $ampm_seperator = _get_option($options, 'ampm_seperator', ''); 
     844  $include_second = _get_option($options, 'include_second'); 
     845  $_12hour_time = _get_option($options, '12hour_time'); 
     846 
     847  $options['12hour_time'] = $_12hour_time; //set it back. hour tag needs it. 
     848 
     849  if ($include_custom = _get_option($options, 'include_custom')) 
     850  { 
     851    $include_custom_hour = (is_array($include_custom)) 
     852        ? ((isset($include_custom['hour'])) ? array('include_custom'=>$include_custom['hour']) : array())  
     853        : array('include_custom'=>$include_custom); 
     854 
     855    $include_custom_minute = (is_array($include_custom)) 
     856        ? ((isset($include_custom['minute'])) ? array('include_custom'=>$include_custom['minute']) : array())  
     857        : array('include_custom'=>$include_custom); 
     858 
     859    $include_custom_second = (is_array($include_custom)) 
     860        ? ((isset($include_custom['second'])) ? array('include_custom'=>$include_custom['second']) : array())  
     861        : array('include_custom'=>$include_custom); 
     862 
     863    $include_custom_ampm = (is_array($include_custom)) 
     864        ? ((isset($include_custom['ampm'])) ? array('include_custom'=>$include_custom['ampm']) : array())  
     865        : array('include_custom'=>$include_custom); 
     866  } 
     867  else 
     868  { 
     869    $include_custom_hour = array(); 
     870    $include_custom_minute = array(); 
     871    $include_custom_second = array(); 
     872    $include_custom_ampm = array(); 
     873  } 
     874 
     875  $tags = array(); 
     876 
     877  $html_options['id'] = $name . '_hour'; 
     878  $tags[] = select_hour_tag($name . '[hour]', _parse_value_for_date($value, 'hour', ($_12hour_time) ? 'h' : 'H'), $options + $include_custom_hour, $html_options); 
     879 
     880  $html_options['id'] = $name . '_minute'; 
     881  $tags[] = select_minute_tag($name . '[minute]', _parse_value_for_date($value, 'minute', 'i'), $options + $include_custom_minute, $html_options); 
     882 
     883  if ($include_second) 
     884  { 
     885    $html_options['id'] = $name . '_second'; 
     886    $tags[] = select_second_tag($name . "[second]" , _parse_value_for_date($value, 'second', 's'), $options + $include_custom_second, $html_options); 
     887  } 
     888 
     889  $time = implode($time_seperator, $tags); 
     890 
     891  if ($_12hour_time) 
     892  { 
     893    $html_options['id'] = $name . '_ampm'; 
     894    $time .=  $ampm_seperator . select_ampm_tag($name . "[ampm]" , _parse_value_for_date($value, 'ampm', 'A'), $options + $include_custom_ampm, $html_options); 
     895  } 
     896 
     897  return $time; 
     898} 
     899 
     900/** 
     901 * Enter description here... 
     902 * 
     903 * @param string $name 
     904 * @param string $value (proper datetime format YYYY-MM-DD HH:MM:SS) 
     905 * @param array $options 
     906 * @return string 
     907 */ 
     908function select_datetime_tag($name, $value, $options = array(), $html_options = array()) 
     909{ 
     910  $options = _parse_attributes($options); 
     911  $datetime_seperator = _get_option($options, 'datetime_seperator', ''); 
     912 
     913  $date = select_date_tag($name, $value, $options, $html_options); 
     914  $time = select_time_tag($name, $value, $options, $html_options); 
     915 
     916  return $date.$datetime_seperator.$time; 
     917} 
     918 
     919function _add_zeros($string, $strlen) 
     920{ 
     921  if ($strlen > strlen($string)) 
     922  { 
     923    for ($x = strlen($string); $x < $strlen; $x++) 
     924    { 
     925      $string = '0'.$string; 
     926    } 
     927  } 
     928 
     929  return $string; 
     930} 
     931 
     932function _get_I18n_date_locales($culture = '') 
     933{ 
     934  if (empty($culture)) 
     935  { 
     936    $culture = sfContext::getInstance()->getUser()->getCulture(); 
     937  } 
     938 
     939  $ret_val = array(); 
     940  $ret_val['culture'] = $culture; 
     941 
     942  $dateFormatInfo = sfDateTimeFormatInfo::getInstance($culture); 
     943  $date_format = strtolower($dateFormatInfo->getShortDatePattern()); 
     944 
     945  $ret_val['dateFormatInfo'] = $dateFormatInfo; 
     946     
     947  $match_pattern = "/([dmy]+)(.*?)([dmy]+)(.*?)([dmy]+)/"; 
     948  if (!preg_match($match_pattern, $date_format, $match_arr)) 
     949  { 
     950    //if matching fails use en shortdate 
     951    preg_match($match_pattern, 'm/d/yy', $match_arr); 
     952  } 
     953 
     954  $ret_val['date_seperator'] = $match_arr[2]; 
     955 
     956  //unset all but [dmy]+ 
     957  unset($match_arr[0], $match_arr[2], $match_arr[4]); 
     958   
     959  $cnt = 0; 
     960  foreach ($match_arr as $k => $v) 
     961  { 
     962    $ret_val['date_order'][$cnt++] = $v[0]; //$arr[date_order][0] = 'm'; [1] = 'd'; [2] = 'y'; 
     963  } 
     964   
     965  return $ret_val; 
     966} 
     967 
     968/** 
     969* _parse_value_for_date function can parse any date field from $value given as: 
     970*  - an array('year'=>2000, 'month'=> 1, .. 
     971*  - a timestamp 
     972*  - english text presentation of date (i.e '14:23', '03:30 AM', '2005-12-25' Refer to strtotime function in PHP manual) 
     973*/ 
     974function _parse_value_for_date($value, $name, $format_char) 
     975{ 
     976  if (is_array($value)) 
     977  { 
     978    return (isset($value[$name])) ? $value[$name] : ''; 
     979  } 
     980  else if (is_numeric($value)) 
     981  { 
     982    return date($format_char, $value); 
     983  } 
     984  else if ($value == '' || ($name == 'ampm' && ($value == 'AM' || $value == 'PM'))) 
     985  { 
     986    return $value; 
     987  } 
     988 
     989  return date($format_char, strtotime($value)); 
     990} 
     991 
    539992function _convert_options($options) 
    540993{