/** * Add a selection drop down for the year and month to be selected. * @param string $name The name of the selection element * @param I2CE_Date $default The default I2CE_Date object to use to preset the value. * @param boolean $showError A flag if this field is currently invalid to mark it as such. * @param DOMNode $node The node to append the element to. * @param array $year_range The range of years to use for the drop down. * @param boolean $hidden Set to true if the form element should be hidden. Defaults to false. * @param boolean $blank Set to true if this element should have a blank entry option. Defaults to false. */ public static function addYearMonthElement($template, $name, $default, $showError, $node, $year_range, $hidden = false, $blank = false) { if ($hidden) { $year = $template->createElement("input", array("name" => $name . "[year]", "type" => "hidden", "value" => $default->year())); $month = $template->createElement("input", array("name" => $name . "[month]", "type" => "hidden", "value" => $default->month())); } else { $year = $template->createElement("select", array("name" => $name . "[year]", "class" => "date_year" . ($showError ? "_error" : ""))); if ($blank) { $blank_opt = $template->createElement("option", array("value" => "", "class" => "blank_opt"), "Select"); $year->appendChild($blank_opt); } else { $blank_opt = $template->createElement("option", array("value" => "", "class" => "blank_opt"), "0000"); $year->appendChild($blank_opt); } for ($i = $year_range[0]; $i <= $year_range[1]; $i++) { $year_opt = $template->createElement("option", array("value" => $i), $i); if ($default->isYear($i)) { $year_opt->setAttribute("selected", "selected"); } $year->appendChild($year_opt); } $month = $template->createElement("select", array("name" => $name . "[month]", "id" => $name, "class" => "date_month" . ($showError ? "_error" : ""))); if ($blank) { $blank_opt = $template->createElement("option", array("value" => "", "class" => "blank_opt"), "Select"); $month->appendChild($blank_opt); } foreach (I2CE_Date::$months as $mon => $def_name) { $mon_name = $default->getMonthName($mon); $opt = $template->createElement("option", array("value" => $mon, "class" => $mon == "" ? "blank_opt" : ""), $mon_name); if ($default->isMonth($mon)) { $opt->setAttribute("selected", "selected"); } $month->appendChild($opt); } } $node->appendChild($month); $node->appendChild($year); }