00001 <?php
00002
00003 require_once('VCSDBDriver/VCSDBDriverLocationCodes.php');
00004 require_once('PageSectionBase.php');
00005
00015 class PageHeader extends PageSectionBase {
00019 private static $DEFAULT_SORT_BY_OPTIONS = array (
00020 "" => "指定なし",
00021 "minprice" => "料金の安い順",
00022 "maxprice" => "料金の高い順",
00023
00024 );
00025
00027 private static $SORT_ORDER_OPTIONS = array (
00028 "" => "指定なし",
00029 "asc" => "料金が安い順",
00030 "desc" => "料金が高い順"
00031 );
00032
00034 protected $view;
00035
00037 private $keyword = null;
00038
00040 protected $page = null;
00041
00043 protected $larea_cd = null;
00044
00046 protected $sarea_cd = null;
00047
00049 protected $city_cd = null;
00050
00052 protected $price_min = null;
00053
00055 protected $price_max = null;
00056
00058 protected $c_card = null;
00059
00061 protected $sort_by = null;
00062
00064 protected $sort_order = null;
00065
00071 public function __construct($fileName) {
00072 global $_GET;
00073
00074
00075
00076
00077 $this->view = $this->loadFile($fileName);
00078
00079
00080
00081
00082 if (array_key_exists('keyword',$_GET) && $_GET['keyword'] != '') {
00083 $this->keyword = $_GET['keyword'];
00084 }
00085
00086
00087
00088
00089 if (array_key_exists('page',$_GET) && is_numeric($_GET['page'])) {
00090 $this->page = $_GET['page'];
00091 }
00092
00093
00094
00095
00096 if (array_key_exists('larea_cd',$_GET) && is_numeric($_GET['larea_cd'])) {
00097 $this->larea_cd = $_GET['larea_cd'];
00098 }
00099
00100
00101
00102
00103 if (array_key_exists('sarea_cd',$_GET) && is_numeric($_GET['sarea_cd'])) {
00104 $this->sarea_cd = $_GET['sarea_cd'];
00105 }
00106
00107
00108
00109
00110 if (array_key_exists('city_cd',$_GET) && $_GET['city_cd'] != '') {
00111 $this->city_cd = $_GET['city_cd'];
00112 }
00113
00114
00115
00116
00117 if (array_key_exists('price_min',$_GET) && is_numeric($_GET['price_min'])) {
00118 $this->price_min = $_GET['price_min'];
00119 }
00120
00121
00122
00123
00124 if (array_key_exists('price_max',$_GET) && is_numeric($_GET['price_max'])) {
00125 $this->price_max = $_GET['price_max'];
00126 }
00127
00128
00129
00130
00131 if (array_key_exists('c_card',$_GET) && $_GET['c_card'] == 'y') {
00132 $this->c_card = 'y';
00133 }
00134
00135
00136
00137
00138 if (array_key_exists('sort_by',$_GET) && $_GET['sort_by'] != '') {
00139 $this->sort_by = $_GET['sort_by'];
00140 }
00141
00142 if (array_key_exists('sort_order',$_GET) && $_GET['sort_order'] != '') {
00143 $this->sort_order = $_GET['sort_order'];
00144 }
00145 }
00146
00153 public function assignParams($service) {
00154 global $_GET;
00155
00156
00157
00158
00159 if ($this->keyword) {
00160 $service->setParam('keyword',$this->keyword);
00161 }
00162
00163
00164
00165
00166 if ($this->page) {
00167 $service->setParam('page',$this->page);
00168 }
00169
00170
00171
00172
00173 if ($this->larea_cd) {
00174 $service->setParam('larea_cd',$this->larea_cd);
00175 }
00176
00177
00178
00179
00180 if ($this->sarea_cd) {
00181 $service->setParam('sarea_cd',$this->sarea_cd);
00182 }
00183
00184
00185
00186
00187 if ($this->city_cd) {
00188 $service->setParam('city_cd',$this->city_cd);
00189 }
00190
00191
00192
00193
00194 if ($this->price_min) {
00195 $service->setParam('price_min',$this->price_min);
00196 }
00197
00198
00199
00200
00201 if ($this->price_max) {
00202 $service->setParam('price_max',$this->price_max);
00203 }
00204
00205
00206
00207
00208 if ($this->c_card) {
00209 $service->setParam('c_card',$this->c_card);
00210 }
00211
00212
00213
00214
00215 if ($this->sort_by) {
00216 $service->setParam('sort_by',$this->sort_by);
00217 }
00218
00219 if ($this->sort_order) {
00220 $service->setParam('sort_order', $this->sort_order);
00221 }
00222 }
00223
00230 protected function isAdvancedSearchOptionOn() {
00231 return false;
00232 }
00233
00239 protected function getSortByOptions() {
00240 return self::$DEFAULT_SORT_BY_OPTIONS;
00241 }
00242
00249 protected function renderFlippering($itemHtml) {
00250
00251
00252
00253 if ($this->isAdvancedSearchOptionOn()) {
00254 $itemHtml = str_replace('${FLIPPER_ON}','',$itemHtml);
00255 $itemHtml = str_replace('${FLIPPER_OFF}','class="hidden"',$itemHtml);
00256 } else {
00257 $itemHtml = str_replace('${FLIPPER_ON}','class="hidden"',$itemHtml);
00258 $itemHtml = str_replace('${FLIPPER_OFF}','',$itemHtml);
00259 }
00260
00261 return $itemHtml;
00262 }
00263
00270 protected function renderKeyword($itemHtml) {
00271
00272
00273
00274 $itemHtml = str_replace('${KEYWORD}',$this->keyword?htmlspecialchars($this->keyword):'',
00275 $itemHtml);
00276
00277 return $itemHtml;
00278 }
00279
00286 protected function renderLocationCodes($itemHtml) {
00287
00288
00289
00290 $itemHtml = str_replace(
00291 '${LOCATION_CODES}',
00292 VCSDBDriverLocationCodes::getJSON(),
00293 $itemHtml
00294 );
00295
00296 return $itemHtml;
00297 }
00298
00307 protected function renderRegion($itemHtml, $selectedRegion, $optionTitle='方面') {
00308 $options = '';
00309
00310 $regionCodes = VCSDBDriverLocationCodes::getRegions();
00311 if ($regionCodes) {
00312 foreach ($regionCodes as $regionCode) {
00313 $code = (string)$regionCode->cd;
00314 $name = (string) $regionCode->name;
00315
00316 $options .= '<option value="' . $code . '" ';
00317 if (($selectedRegion && $code == $selectedRegion)
00318 || (!$selectedRegion && $code == '')) {
00319
00320 $options .= 'selected';
00321 }
00322 $options .= '>' . $name . '</option>';
00323 }
00324 }
00325
00326 $itemHtml = str_replace('${REGION_CD}','<option value="">'.$optionTitle.'</option>' . $options,$itemHtml);
00327 $itemHtml = str_replace('${REGION_STATUS}',$options != '' ? '':'disabled="disabled"',$itemHtml);
00328
00329 return $itemHtml;
00330 }
00331
00342 protected function renderCountry($itemHtml, $regionCode, $selectedCountry, $optionTitle='国・地域', $exclude_countries=null) {
00343 $options = '';
00344
00345 if ($regionCode) {
00346 $country_codes = VCSDBDriverLocationCodes::getCountriesInRegion($regionCode);
00347
00348 if ($country_codes) {
00349 foreach ($country_codes as $country_code) {
00350 $code = (string)$country_code->cd;
00351 $name = (string)$country_code->name;
00352
00353 if ($exclude_countries && in_array($code, $exclude_countries)) {
00354 continue;
00355 }
00356
00357 $options .= '<option value="' . $code . '" ';
00358 if (($selectedCountry && $code == $selectedCountry)
00359 || (!$selectedCountry && $code == '')) {
00360
00361 $options .= 'selected';
00362 }
00363 $options .= '>' . $name . '</option>';
00364 }
00365 }
00366 }
00367
00368 $itemHtml = str_replace('${CTRY_CD}','<option value="">'.$optionTitle.'</option>' . $options,$itemHtml);
00369 $itemHtml = str_replace('${CTRY_STATUS}',$options != '' ? '':'disabled="disabled"',$itemHtml);
00370
00371 return $itemHtml;
00372 }
00373
00381 protected function renderCity($itemHtml, $cities, $selectedCity) {
00382 $options = '';
00383
00384 if ($cities) {
00385 foreach ($cities as $city) {
00386 $code =(string)$city->cd;
00387 $name =(string)$city->name;
00388
00389 $options .= '<option value="' . $code . '" ';
00390 if (($selectedCity && $code == $selectedCity)
00391 || (!$selectedCity && $code == '')) {
00392 $options .= 'selected';
00393 }
00394 $options .= '>' . $name . '</option>';
00395 }
00396 }
00397
00398 $itemHtml = str_replace('${CITY_CD}','<option value="">都市</option>' . $options,$itemHtml);
00399 $itemHtml = str_replace('${CITY_STATUS}',$options != '' ? '':'disabled="disabled"',$itemHtml);
00400
00401 return $itemHtml;
00402 }
00403
00411 protected function renderCityByCountry($itemHtml, $countryCode, $selectedCity = null){
00412 return $this->renderCity($itemHtml, VCSDBDriverLocationCodes::getCitiesInCountry($countryCode), $selectedCity);
00413 }
00414
00422 protected function renderCityBySArea($itemHtml, $sAreaCode, $selectedCity = null){
00423 return $this->renderCity($itemHtml, VCSDBDriverLocationCodes::getCitiesInSArea($sAreaCode), $selectedCity);
00424 }
00425
00433 protected function renderLArea($itemHtml, $countryCode, $optionTitle='地域') {
00434 $options = '';
00435
00436 if ($countryCode) {
00437 $larea_codes = VCSDBDriverLocationCodes::getLAreasInCountry($countryCode);
00438 if ($larea_codes) {
00439 foreach ($larea_codes as $larea_code) {
00440 $code = (string)$larea_code->cd;
00441 $name = (string)$larea_code->name;
00442
00443 if ($code != '') {
00444 $options .= '<option value="' . $code . '" ';
00445 if (($this->larea_cd && $code == $this->larea_cd)
00446 || (!$this->larea_cd && $code == '')) {
00447
00448 $options .= 'selected';
00449 }
00450 $options .= '>' . $name . '</option>';
00451 }
00452 }
00453 }
00454 }
00455
00456 $itemHtml = str_replace('${LAREA_CD}','<option value="">'.$optionTitle.'</option>' . $options,$itemHtml);
00457 $itemHtml = str_replace('${LAREA_STATUS}',$options != '' ? '':'disabled="disabled"',$itemHtml);
00458
00459 return $itemHtml;
00460 }
00461
00462
00470 protected function renderSArea($itemHtml, $lAreaCode) {
00471 $options = '';
00472
00473 if ($lAreaCode) {
00474 $sarea_codes = VCSDBDriverLocationCodes::getSAreasInLArea($lAreaCode);
00475 if ($sarea_codes) {
00476 foreach ($sarea_codes as $sarea_code) {
00477 $code = (string)$sarea_code->cd;
00478 $name = (string)$sarea_code->name;
00479
00480 $options .= '<option value="' . $code . '" ';
00481 if (($this->sarea_cd && $code == $this->sarea_cd)
00482 || (!$this->sarea_cd && $code == '')) {
00483 $options .= 'selected';
00484 }
00485 $options .= '>' . $name . '</option>';
00486 }
00487 }
00488 }
00489
00490 $itemHtml = str_replace('${SAREA_CD}','<option value="">都道府県</option>' . $options,$itemHtml);
00491 $itemHtml = str_replace('${SAREA_STATUS}',$options != '' ? '':'disabled="disabled"',$itemHtml);
00492
00493 return $itemHtml;
00494 }
00495
00502 protected function renderPrice($itemHtml) {
00503
00504
00505
00506 $itemHtml = str_replace('${PRICE_MIN}',$this->price_min?$this->price_min:'',
00507 $itemHtml);
00508
00509
00510
00511
00512 $itemHtml = str_replace('${PRICE_MAX}',$this->price_max?$this->price_max:'',
00513 $itemHtml);
00514
00515 return $itemHtml;
00516 }
00517
00524 protected function renderCreditCardOption($itemHtml) {
00525
00526
00527
00528 $itemHtml = str_replace('${C_CARD}',$this->c_card?'checked':'',$itemHtml);
00529
00530 return $itemHtml;
00531 }
00532
00539 protected function renderSortBy($itemHtml) {
00540 $options = '';
00541
00542 foreach ($this->getSortByOptions() as $code => $name) {
00543 $options .= '<option value="' . $code . '" ';
00544 if (($this->sort_by && $code == $this->sort_by)
00545 || (!$this->sort_by && $code == '')) {
00546 $options .= 'selected';
00547 }
00548 $options .= '>' . $name . '</option>';
00549 }
00550
00551 $itemHtml = str_replace('${SORT_BY}',$options,$itemHtml);
00552
00553 return $itemHtml;
00554 }
00555
00562 protected function renderSortOrder($itemHtml) {
00563 $options = '';
00564
00565 foreach (self::$SORT_ORDER_OPTIONS as $code => $name) {
00566 $options .= '<option value="' . $code . '" ';
00567 if (($this->sort_order && $code == $this->sort_order)
00568 || (!$this->sort_order && $code == '')) {
00569 $options .= 'selected';
00570 }
00571 $options .= '>' . $name . '</option>';
00572 }
00573
00574 $itemHtml = str_replace('${SORT_ORDER}',$options,$itemHtml);
00575
00576 return $itemHtml;
00577 }
00578
00579
00586 protected function getLAreaName($countryCode = 'JP') {
00587
00588 if ($countryCode) {
00589 $larea_codes = VCSDBDriverLocationCodes::getLAreasInCountry($countryCode);
00590 if ($larea_codes) {
00591 foreach ($larea_codes as $larea_code) {
00592 $code = (string)$larea_code->cd;
00593 $name = (string)$larea_code->name;
00594 if ($code != '') {
00595 if (($this->larea_cd && $code == $this->larea_cd)
00596 || (!$this->larea_cd && $code == '')) {
00597 return $name;
00598 }
00599 }
00600 }
00601 }
00602 }
00603 return;
00604 }
00605
00612 protected function getSAreaName($lAreaCode) {
00613
00614 if ($lAreaCode) {
00615 $sarea_codes = VCSDBDriverLocationCodes::getSAreasInLArea($lAreaCode);
00616 if ($sarea_codes) {
00617 foreach ($sarea_codes as $sarea_code) {
00618 $code = (string)$sarea_code->cd;
00619 $name = (string)$sarea_code->name;
00620 if (($this->sarea_cd && $code == $this->sarea_cd)
00621 || (!$this->sarea_cd && $code == '')) {
00622 return $name;
00623 }
00624 }
00625 }
00626 }
00627 return;
00628 }
00629
00636 protected function getCityName($cities, $selectedCity) {
00637
00638 if ($cities) {
00639 foreach ($cities as $city) {
00640 $code =(string)$city->cd;
00641 $name =(string)$city->name;
00642 if (($selectedCity && $code == $selectedCity)
00643 || (!$selectedCity && $code == '')) {
00644 return $name;
00645 }
00646 }
00647 }
00648 return;
00649 }
00650
00658 protected function getCityNameBySArea($sAreaCode, $selectedCity = null){
00659 return $this->getCityName(VCSDBDriverLocationCodes::getCitiesInSArea($sAreaCode), $selectedCity);
00660 }
00661
00668 protected function render() {
00669 return $this->view;
00670 }
00671
00677 public final function show() {
00678 print $this->render();
00679 }
00680 }
00681 ?>