Advertisement
Belazor

timeRow

Feb 2nd, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.01 KB | None | 0 0
  1.     /**
  2.     * Constructs some <option>s for use in the templates
  3.     *
  4.     * @param    array   The key:value data array
  5.     * @param    mixed   (Optional) The selected id(s)
  6.     * @param    boolean (Optional) Whether we should HTMLise the values
  7.     */ 
  8.     public static function createSelectOptions($array, $selectedid = '', $htmlise = false)
  9.     {
  10.         if (!is_array($array))
  11.         {
  12.             return '';
  13.         }
  14.        
  15.         $options = '';
  16.         foreach ($array as $key => $val)
  17.         {
  18.             if (is_array($val))
  19.             {
  20.                 // Create the template
  21.                 $templater = vB_Template::create('optgroup');
  22.                     $templater->register('optgroup_label',  ($htmlise ? htmlspecialchars_uni($key) : $key));
  23.                     $templater->register('optgroup_options', self::createSelectOptions($val, $selectedid, $tabindex, $htmlise));
  24.                 $options .= $templater->render();
  25.             }
  26.             else
  27.             {
  28.                 if (is_array($selectedid))
  29.                 {
  30.                     $selected = iif(in_array($key, $selectedid), ' selected="selected"', '');
  31.                 }
  32.                 else
  33.                 {
  34.                     $selected = iif($key == $selectedid, ' selected="selected"', '');
  35.                 }
  36.                
  37.                 $templater = vB_Template::create('option');
  38.                     $templater->register('optionvalue',     ($key !== 'no_value' ? $key : ''));
  39.                     $templater->register('optionselected',  $selected);
  40.                     $templater->register('optiontitle',     ($htmlise ? htmlspecialchars_uni($val) : $val));
  41.                 $options .= $templater->render();
  42.             }
  43.         }
  44.        
  45.         return $options;
  46.     }
  47.    
  48.     /**
  49.     * Constructs a time selector
  50.     *
  51.     * @param    string  The title of the time select
  52.     * @param    name    (Optional) The HTML form name
  53.     * @param    array   (Optional) The time we should start with
  54.     * @param    name    (Optional) The vertical align state
  55.     *
  56.     * @return   string  The constructed time row
  57.     */ 
  58.     public static function timeRow($title, $name = 'date', $unixtime = '', $valign = 'middle')
  59.     {
  60.         global $vbphrase, $vbulletin;
  61.        
  62.         $output = '';
  63.    
  64.         $monthnames = array(
  65.             0  => '- - - -',
  66.             1  => $vbphrase['january'],
  67.             2  => $vbphrase['february'],
  68.             3  => $vbphrase['march'],
  69.             4  => $vbphrase['april'],
  70.             5  => $vbphrase['may'],
  71.             6  => $vbphrase['june'],
  72.             7  => $vbphrase['july'],
  73.             8  => $vbphrase['august'],
  74.             9  => $vbphrase['september'],
  75.             10 => $vbphrase['october'],
  76.             11 => $vbphrase['november'],
  77.             12 => $vbphrase['december'],
  78.         );
  79.    
  80.         if (is_array($unixtime))
  81.         {
  82.             require_once(DIR . '/includes/functions_misc.php');
  83.             $unixtime = vbmktime(0, 0, 0, $unixtime['month'], $unixtime['day'], $unixtime['year']);
  84.         }
  85.    
  86.         if ($unixtime)
  87.         {
  88.             $month = vbdate('n', $unixtime, false, false);
  89.             $day = vbdate('j', $unixtime, false, false);
  90.             $year = vbdate('Y', $unixtime, false, false);
  91.             $hour = vbdate('G', $unixtime, false, false);
  92.             $minute = vbdate('i', $unixtime, false, false);
  93.         }
  94.    
  95.         $cell = array();
  96.         $cell[] = "<label for=\"{$name}_month\">$vbphrase[month]</label><br /><select name=\"{$name}[month]\" id=\"{$name}_month\" tabindex=\"1\" class=\"primary select\"" . iif($vbulletin->debug, " title=\"name=&quot;$name" . "[month]&quot;\"") . ">\n" . self::createSelectOptions($monthnames, $month) . "\t\t</select>";
  97.         $cell[] = "<label for=\"{$name}_date\">$vbphrase[day]</label><br /><input type=\"text\" class=\"primary textbox\" name=\"{$name}[day]\" id=\"{$name}_date\" value=\"$day\" size=\"4\" maxlength=\"2\" tabindex=\"1\"" . iif($vbulletin->debug, " title=\"name=&quot;$name" . "[day]&quot;\"") . ' />';
  98.         $cell[] = "<label for=\"{$name}_year\">$vbphrase[year]</label><br /><input type=\"text\" class=\"primary textbox\" name=\"{$name}[year]\" id=\"{$name}_year\" value=\"$year\" size=\"4\" maxlength=\"4\" tabindex=\"1\"" . iif($vbulletin->debug, " title=\"name=&quot;$name" . "[year]&quot;\"") . ' />';
  99.         $inputs = '';
  100.         foreach($cell AS $html)
  101.         {
  102.             $inputs .= "\t\t<td style=\"padding-left:6px;\"><span class=\"smallfont\">$html</span></td>\n";
  103.         }
  104.        
  105.         $output .= "<div id=\"ctrl_$name\" class=\"" . (intval(self::$vbulletin->versionnumber) == 3 ? 'alt1' : 'blockrow') . "\">$title: <table cellpadding=\"0\" cellspacing=\"2\" border=\"0\"><tr>\n$inputs\t\n</tr></table></div><br />"; 
  106.        
  107.         return $output;
  108.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement