示例#1
0
 function controlToHTML($name)
 {
     $html = "";
     if (!defined("SYS_GEO")) {
         require_once BASE . "subsystems/geo.php";
     }
     $countries = pathos_geo_listCountriesOnly();
     $c_dd = new dropdowncontrol($this->country_default, $countries);
     $c_dd->jsHooks["onChange"] = "geo_rebuildRegions(this,'" . $name . "_region_id'," . ($this->allow_entire_country ? 'true' : 'false') . ");";
     if (!defined("GEO_JS_INCLUDED")) {
         define("GEO_JS_INCLUDED", 1);
         $html .= "<script language='JavaScript'>function geo_rebuildRegions(c_select,r_id,allow_all) {";
         $html .= "\tvar r_select = document.getElementById(r_id);";
         $html .= "\twhile (r_select.childNodes.length) r_select.removeChild(r_select.firstChild);";
         $html .= "\tvar country = c_select.options[c_select.selectedIndex].value;";
         //alert(country);
         $html .= "   if (allow_all) {";
         $html .= "\t\tvar o = document.createElement('option');";
         $html .= "\t\to.setAttribute('value',0);";
         $html .= "\t\to.appendChild(document.createTextNode('[ Entire Country ]'));";
         $html .= "\t\tr_select.appendChild(o);";
         $html .= "\t}";
         $html .= "   var count = 0;";
         $html .= "\tfor (i = 0; i < geo_regions.length; i++) {";
         $html .= "\t\tif (geo_regions[i].var_parent_id == country) {";
         $html .= "\t\t\tcount++;";
         $html .= "\t\t\tvar o = document.createElement('option');";
         $html .= "\t\t\to.setAttribute('value',\tgeo_regions[i].var_id);";
         $html .= "\t\t\to.appendChild(document.createTextNode(geo_regions[i].var_name));";
         $html .= "\t\t\tr_select.appendChild(o);";
         $html .= "\t\t}";
         $html .= "\t}";
         $html .= "\tif (!allow_all && count == 0) {";
         $html .= " \t\tvar o = document.createElement('option');";
         $html .= "\t\to.setAttribute('value',0);";
         $html .= "\t\to.appendChild(document.createTextNode('[ None Specified ]'));";
         $html .= "\t\tr_select.appendChild(o);";
         $html .= "\t}";
         $html .= "}";
         if (!defined("SYS_JAVACSRIPT")) {
             require_once BASE . "subsystems/javascript.php";
         }
         $region = null;
         $region->parent_id = 0;
         $region->id = 0;
         $region->name = "";
         $html .= pathos_javascript_class($region, "geoRegion");
         $html .= "var geo_regions = new Array();\n";
         foreach ($countries as $cid => $cname) {
             $region = null;
             $region->parent_id = $cid;
             foreach (pathos_geo_listRegions($cid) as $rid => $rname) {
                 $region->id = $rid;
                 $region->name = $rname;
                 $html .= "geo_regions.push(";
                 $html .= pathos_javascript_object($region, "geoRegion");
                 $html .= ");\n";
             }
         }
         $html .= "</script>\n";
     }
     $regions = pathos_geo_listRegions($this->country_default);
     if ($this->allow_entire_country) {
         array_unshift($regions, "[ Entire Country ]");
     } elseif ($regions == null) {
         array_unshift($regions, "[ None Specified ]");
     }
     $r_dd = new dropdowncontrol($this->region_default, $regions);
     $html .= $c_dd->controlToHTML($name . "_country_id");
     $html .= "<br>";
     $html .= $r_dd->controlToHTML($name . "_region_id");
     return $html;
 }