public static function getAllCity() { if (self::$_allCity === null) { $sql = 'SELECT name_' . Yii::app()->language . ' AS name, id FROM {{apartment_city}} ORDER BY sorter'; $results = Yii::app()->db->createCommand($sql)->queryAll(); self::$_allCity = CHtml::listData($results, 'id', 'name'); } return self::$_allCity; }
public static function cityInit() { $cityActive = array(); if (oreInstall::isInstalled()) { Yii::import('application.modules.apartmentCity.models.ApartmentCity'); $cityActive = ApartmentCity::getActiveCity(); if ($cityActive === null) { $cityActive = array(); } } return $cityActive; }
public function actionDelete($id) { // Не дадим удалить последний город if (ApartmentCity::model()->count() <= 1) { if (!isset($_GET['ajax'])) { Yii::app()->user->setFlash('error', tt('You can not delete the last city')); $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } else { echo "<div class='flash-error'>" . tt('You can not delete the last city') . "</div>"; } Yii::app()->end(); } parent::actionDelete($id); }
?> </p> <p><?php echo tt('Separators are ";".'); ?> </p> </div> <?php $columns = array(array('class' => 'CCheckBoxColumn', 'header' => tt('Select'), 'id' => 'itemsSelectedExport'), array('name' => 'id', 'htmlOptions' => array('class' => 'apartments_id_column', 'style' => 'text-align: center;'), 'sortable' => false), array('name' => 'active', 'type' => 'raw', 'value' => 'Yii::app()->controller->returnControllerStatusHtml($data, "apartments-grid", 1)', 'htmlOptions' => array('class' => 'apartments_status_column'), 'filter' => Apartment::getModerationStatusArray(), 'sortable' => false), array('name' => 'type', 'type' => 'raw', 'value' => 'Apartment::getNameByType($data->type)', 'htmlOptions' => array('style' => 'width: 100px;'), 'filter' => Apartment::getTypesArray(), 'sortable' => false)); if (issetModule('location')) { $columns[] = array('name' => 'loc_country', 'value' => '$data->loc_country ? $data->locCountry->name : ""', 'htmlOptions' => array('style' => 'width: 150px;'), 'sortable' => false, 'filter' => Country::getCountriesArray(0, 1)); $columns[] = array('name' => 'loc_region', 'value' => '$data->loc_region ? $data->locRegion->name : ""', 'htmlOptions' => array('style' => 'width: 150px;'), 'sortable' => false, 'filter' => Region::getRegionsArray($model->loc_country, 0, 1)); $columns[] = array('name' => 'loc_city', 'value' => '$data->loc_city ? $data->locCity->name : ""', 'htmlOptions' => array('style' => 'width: 150px;'), 'sortable' => false, 'filter' => City::getCitiesArray($model->loc_region, 0, 1)); } else { $columns[] = array('name' => 'city_id', 'value' => '(isset($data->city ) && $data->city_id) ? $data->city->name : ""', 'htmlOptions' => array('style' => 'width: 150px;'), 'filter' => ApartmentCity::getAllCity(), 'sortable' => false); } $columns[] = array('name' => 'ownerEmail', 'htmlOptions' => array('style' => 'width: 150px;'), 'type' => 'raw', 'value' => '(isset($data->user) && $data->user->role != "admin") ? CHtml::link(CHtml::encode($data->user->email), array("/users/backend/main/view","id" => $data->user->id)) : tt("administrator", "common")'); $columns[] = array('header' => tc('Name'), 'name' => 'title_' . Yii::app()->language, 'type' => 'raw', 'value' => 'CHtml::link(CHtml::encode($data->{"title_".Yii::app()->language}), $data->getUrl())', 'sortable' => false); ?> <div class="form"> <?php $this->widget('CustomHistoryGridView', array('id' => 'export-grid', 'dataProvider' => $model->searchExport(), 'filter' => $model, 'selectableRows' => 2, 'selectionChanged' => 'js:selItemsSelected', 'columns' => $columns)); ?> <?php $form = $this->beginWidget('CActiveForm', array('id' => 'export-form', 'method' => 'post', 'action' => $this->createAbsoluteUrl('/iecsv/backend/main/export'), 'enableClientValidation' => false)); echo $form->hiddenField($model, 'itemsSelectedExport'); echo $form->error($model, 'itemsSelectedExport');
echo CHtml::label($model->getAttributeLabel('userType'), 'userType'); echo $form->dropDownList($model, 'type', CArray::merge(array(0 => tc('Please select')), User::getTypeList()), array('id' => 'userType')); ?> <?php echo CHtml::label($model->getAttributeLabel('withListings'), 'withListings'); echo $form->dropDownList($model, 'withListings', CArray::merge(array('' => tc('Please select')), array(0 => tc('No'), 1 => tc('Ok'))), array('id' => 'withListings')); ?> <?php if (issetModule('location')) { echo CHtml::label($model->getAttributeLabel('countryListing'), 'countryListing'); echo CHtml::dropDownList('Mailing[countryListing]', isset($this->selectedCountry) ? $this->selectedCountry : '', Country::getCountriesArray(2), array('class' => 'width285 searchField', 'id' => 'countryListing', 'ajax' => array('type' => 'GET', 'url' => $this->createUrl('/location/main/getRegions'), 'data' => 'js:"country="+$("#countryListing").val()+"&type=2"', 'success' => 'function(result){ $("#regionListing").html(result); $("#regionListing").change(); }'))); echo CHtml::label($model->getAttributeLabel('regionListing'), 'regionListing'); echo CHtml::dropDownList('Mailing[regionListing]', isset($this->selectedRegion) ? $this->selectedRegion : '', Region::getRegionsArray(isset($this->selectedCountry) ? $this->selectedCountry : 0, 2), array('class' => 'width285 searchField', 'id' => 'regionListing', 'ajax' => array('type' => 'GET', 'url' => $this->createUrl('/location/main/getCities'), 'data' => 'js:"region="+$("#regionListing").val()+"&type=2"', 'success' => 'function(result){ $("#cityListing").html(result); $("#cityListing").change(); }'))); } ?> <?php echo CHtml::label($model->getAttributeLabel('cityListing'), 'cityListing'); echo CHtml::dropDownList('Mailing[cityListing]', isset($this->selectedCity) ? $this->selectedCity : '', issetModule('location') ? City::getCitiesArray(isset($this->selectedRegion) ? $this->selectedRegion : 0, 2) : CArray::merge(array(0 => tc('select city')), ApartmentCity::getActiveCity()), array('class' => 'width285 searchField', 'id' => 'cityListing')); ?> <?php $this->endWidget();
public function actionExport() { $model = new $this->modelName(); $photosExport = array(); if (isset($_POST['ajax']) && $_POST['ajax'] === 'export-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST[$this->modelName])) { $model->attributes = $_POST[$this->modelName]; $arrSel = ''; if (isset($_POST[$this->modelName]['itemsSelectedExport']) && $_POST[$this->modelName]['itemsSelectedExport']) { $arrSel = explode(',', $_POST[$this->modelName]['itemsSelectedExport']); $arrSel = array_map("intval", $arrSel); } if (!$arrSel || !count($arrSel)) { Yii::app()->user->setFlash('error', tt('Please select ads for export.')); $this->redirect('viewExport'); } else { $backUrl = $this->createUrl('viewExport', array($this->modelName . '_sel' => $arrSel)); $isZip = isset($_POST[$this->modelName]['isZip']) ? $_POST[$this->modelName]['isZip'] : 0; $fileName = date('Y_m_d_s') . rand(0, 9) . '_export.csv'; $filePath = $model->csvPath . DIRECTORY_SEPARATOR . $fileName; $fileLine = array(); $fileLine[0] = $this->mask; $i = 1; foreach ($arrSel as $v) { // get needed info $apartment = Apartment::model()->cache(param('cachingTime', 1209600), Apartment::getFullDependency($v))->with('windowTo', 'images')->findByPk($v); // set values $type = $apartment->type; $priceType = $apartment->price_type; $objType = $apartment->obj_type_id; $countryName = $regionName = $cityName = ''; if (issetModule('location')) { // country if (isFree()) { if ($apartment->loc_country) { $countryInfo = Country::model()->findByPk($apartment->loc_country); if ($countryInfo && isset($countryInfo->name)) { $countryName = $countryInfo->name; } } } else { if ($apartment->loc_country) { Yii::app()->setLanguage($this->defLang); $countryInfo = Country::model()->findByPk($apartment->loc_country); if ($countryInfo && isset($countryInfo->name)) { $countryName = $countryInfo->name; } Yii::app()->setLanguage($this->currLang); } } // region if (isFree()) { if ($apartment->loc_region) { $regionInfo = Region::model()->findByPk($apartment->loc_region); if ($regionInfo && isset($regionInfo->name)) { $regionName = $regionInfo->name; } } } else { if ($apartment->loc_region) { Yii::app()->setLanguage($this->defLang); $regionInfo = Region::model()->findByPk($apartment->loc_region); if ($regionInfo && isset($regionInfo->name)) { $regionName = $regionInfo->name; } Yii::app()->setLanguage($this->currLang); } } // city if (isFree()) { if ($apartment->loc_city) { $cityInfo = City::model()->findByPk($apartment->loc_city); if ($cityInfo && isset($cityInfo->name)) { $cityName = $cityInfo->name; } } } else { if ($apartment->loc_city) { Yii::app()->setLanguage($this->defLang); $cityInfo = City::model()->findByPk($apartment->loc_city); if ($cityInfo && isset($cityInfo->name)) { $cityName = $cityInfo->name; } Yii::app()->setLanguage($this->currLang); } } } else { if (isFree()) { if ($apartment->city_id) { Yii::import('application.modules.apartmentCity.models.ApartmentCity'); $cityInfo = ApartmentCity::model()->findByPk($apartment->city_id); if ($cityInfo && isset($cityInfo->name)) { $cityName = $cityInfo->name; } } } else { if ($apartment->city_id) { Yii::app()->setLanguage($this->defLang); Yii::import('application.modules.apartmentCity.models.ApartmentCity'); $cityInfo = ApartmentCity::model()->findByPk($apartment->city_id); if ($cityInfo && isset($cityInfo->name)) { $cityName = $cityInfo->name; } Yii::app()->setLanguage($this->currLang); } } } $isPricePoa = $apartment->is_price_poa; $price = $apartment->price; $priceTo = $apartment->price_to; $numberRooms = $apartment->num_of_rooms; $floor = $apartment->floor; $floorTotal = $apartment->floor_total; $square = $apartment->square; $landSquare = $apartment->land_square; $sleeps = $apartment->berths; // get title, description, near, address, exchange $title = $description = $near = $address = $exchangeTo = ''; if (isFree()) { $titleField = 'title_' . Yii::app()->language; $title = $this->clearHtml($apartment->{$titleField}); $descrField = 'description_' . Yii::app()->language; $description = $this->clearHtml($apartment->{$descrField}); $descrNearField = 'description_near_' . Yii::app()->language; $near = $this->clearHtml($apartment->{$descrNearField}); $addressField = 'address_' . Yii::app()->language; $address = $this->clearHtml($apartment->{$addressField}); $exchangeToField = 'exchange_to_' . Yii::app()->language; $exchangeTo = $this->clearHtml($apartment->{$exchangeToField}); } else { if ($this->allLangs) { $title = $description = $near = $address = $exchangeTo = array(); foreach ($this->allLangs as $lang) { $titleField = 'title_' . $lang->name_iso; $descrField = 'description_' . $lang->name_iso; $descrNearField = 'description_near_' . $lang->name_iso; $addressField = 'address_' . $lang->name_iso; $exchangeToField = 'exchange_to_' . $lang->name_iso; $title[$lang->name_iso] = $this->clearHtml($apartment->{$titleField}); $description[$lang->name_iso] = $this->clearHtml($apartment->{$descrField}); $near[$lang->name_iso] = $this->clearHtml($apartment->{$descrNearField}); $address[$lang->name_iso] = $this->clearHtml($apartment->{$addressField}); $exchangeTo[$lang->name_iso] = $this->clearHtml($apartment->{$exchangeToField}); } } } // get coords $lat = $apartment->lat; $lng = $apartment->lng; // get photos $photos = $apartment->images(); if ($photos) { foreach ($photos as $key => $value) { if ($isZip) { $photos[$key] = $value->file_name; $photosExport["{$apartment->id}_{$key}"] = $model->csvPath . DIRECTORY_SEPARATOR . $value->file_name; copy(Yii::getPathOfAlias('webroot.uploads.objects.' . $apartment->id . '.original') . DIRECTORY_SEPARATOR . $value->file_name, $model->csvPath . DIRECTORY_SEPARATOR . $value->file_name); } else { $photos[$key] = Yii::app()->getBaseUrl(true) . '/uploads/objects/' . $apartment->id . '/original/' . $value->file_name; } } } // get reference info $refInfo = $this->getReferenceInfo($v); $comfort = $refInfo['comfort']; $bathroom = $refInfo['bathroom']; $kitchen = $refInfo['kitchen']; $employment = $refInfo['employment']; $safety = $refInfo['safety']; $entertainment = $refInfo['entertainment']; $terms = $refInfo['terms']; $services = $refInfo['services']; // insert $fileLine[$i] = $type . $this->separator . $priceType . $this->separator . $objType . $this->separator; $fileLine[$i] .= $countryName . $this->separator . $regionName . $this->separator . $cityName . $this->separator . $isPricePoa . $this->separator . $price . $this->separator; $fileLine[$i] .= $priceTo . $this->separator . $numberRooms . $this->separator . $floor . $this->separator; $fileLine[$i] .= $floorTotal . $this->separator . $square . $this->separator . $landSquare . $this->separator . $this->deleteChars($sleeps) . $this->separator; if (isFree()) { $fileLine[$i] .= $this->deleteChars($title) . $this->separator . $this->deleteChars($description) . $this->separator; $fileLine[$i] .= $this->deleteChars($near) . $this->separator . $this->deleteChars($address) . $this->separator; $fileLine[$i] .= $this->deleteChars($exchangeTo) . $this->separator; } else { array_walk($title, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $title) . $this->separator; array_walk($description, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $description) . $this->separator; array_walk($near, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $near) . $this->separator; array_walk($address, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $address) . $this->separator; array_walk($exchangeTo, array($this, 'deleteChars')); $fileLine[$i] .= implode($this->separator, $exchangeTo) . $this->separator; } $fileLine[$i] .= $bathroom . $this->separator . $safety . $this->separator; $fileLine[$i] .= $comfort . $this->separator . $kitchen . $this->separator; $fileLine[$i] .= $employment . $this->separator . $entertainment . $this->separator; $fileLine[$i] .= $services . $this->separator . $terms . $this->separator; $fileLine[$i] .= is_array($photos) ? implode($this->separatorElem, $photos) . $this->separator : '' . $this->separator; $fileLine[$i] .= $lat . $this->separator . $lng; $i++; } // write in file $handle = fopen($filePath, "w+"); foreach ($fileLine as $item) { fputs($handle, $item); fputs($handle, "\r\n"); } fclose($handle); if ($isZip) { include_once $model->libraryPath . DIRECTORY_SEPARATOR . 'pclzip.lib.php'; $arrFile = $photosExport; $arrFile[] = $model->csvPath . DIRECTORY_SEPARATOR . $fileName; $archive = new PclZip($model->csvPath . DIRECTORY_SEPARATOR . str_replace(".csv", "", $fileName) . ".zip"); $list = $archive->create($arrFile, PCLZIP_OPT_REMOVE_ALL_PATH); if ($list == 0) { Yii::app()->user->setFlash('error', $archive->errorInfo(true)); //$this->redirect('viewExport'); $this->redirect($backUrl); } // unlink all files foreach ($arrFile as $item) { @unlink($item); } $fileName = str_replace('.csv', '.zip', $fileName); $filePath = $model->csvPath . DIRECTORY_SEPARATOR . $fileName; header("Content-Type: application/zip"); } else { header("Content-Type: application/csv"); } header("Content-Disposition: attachment; filename={$fileName}"); header("Content-Transfer-Encoding: binary"); header("Pragma: no-cache"); header("Expires: 0"); readfile($filePath); Yii::app()->end(); } } }
?> </div> <?php $cities = City::getCitiesArray($this->getFilterValue('region_id')); } $objTypes = CArray::merge(array(0 => ''), ApartmentObjType::getList()); $typeList = CArray::merge(array(0 => ''), Apartment::getTypesArray()); ?> <div class=""> <div class=""><?php echo Yii::t('common', 'City'); ?> :</div> <?php $cities = isset($cities) && count($cities) ? $cities : CArray::merge(array(0 => tc('select city')), ApartmentCity::getAllCity()); echo CHtml::dropDownList('filter[city_id]', $this->getFilterValue('city_id'), $cities, array('class' => ' searchField', 'id' => 'ap_city')); ?> </div> <div class="rowold"> <div class=""><?php echo tc('Type'); ?> :</div> <?php echo CHtml::dropDownList('filter[type]', $this->getFilterValue('type'), $typeList); ?> </div> <div class="rowold">
public function getCityName() { if (issetModule('location')) { $city = City::model()->findByPk($this->city_id); } else { $city = ApartmentCity::model()->findByPk($this->city_id); } return $city->getStrByLang('name'); }
public static function getCityArray($with_all = false) { Yii::import('application.modules.apartmentCity.models.ApartmentCity'); $cityArr = array(); $cityModel = ApartmentCity::model()->findAll(array('order' => 'sorter')); foreach ($cityModel as $city) { $cityArr[$city->id] = $city->name; } if ($with_all) { $cityArr[0] = tt('All city', 'apartments'); } return $cityArr; }
<?php Yii::app()->getModule('userads'); //if(!Yii::app()->request->isAjaxRequest){ // echo '<h1>'.tt('Manage apartments', 'apartments').'</h1>'; //} $this->pageTitle .= ' - ' . tt('Manage apartments', 'apartments'); if (!isset($this->breadcrumbs)) { $this->breadcrumbs = array(Yii::t('common', 'Control panel') => array('/usercpanel/main/index'), tt('Manage apartments', 'apartments')); } //echo CHtml::button(tc('Add ad', 'apartments'), array('onclick' => 'document.location.href="'.Yii::app()->createUrl('/userads/main/create').'"', 'class' => 'button-blue')); Yii::app()->clientScript->registerScript('ajaxSetStatus', "\n\t\tfunction ajaxSetStatus(elem, id){\n\t\t\t\$.ajax({\n\t\t\t\turl: \$(elem).attr('href'),\n\t\t\t\tsuccess: function(){\n\t\t\t\t\t\$('#'+id).yiiGridView.update(id);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t", CClientScript::POS_HEAD); $columns = array(array('name' => 'id', 'headerHtmlOptions' => array('class' => 'apartments_id_column')), array('name' => 'active', 'type' => 'raw', 'value' => 'UserAds::returnStatusHtml($data, "userads-grid", 0)', 'headerHtmlOptions' => array('class' => 'userads_status_column'), 'filter' => Apartment::getModerationStatusArray(), 'sortable' => false), array('name' => 'owner_active', 'type' => 'raw', 'value' => 'UserAds::returnStatusOwnerActiveHtml($data, "userads-grid", 1)', 'headerHtmlOptions' => array('class' => 'userads_owner_status_column'), 'filter' => array('0' => tc('Inactive'), '1' => tc('Active')), 'sortable' => false), array('name' => 'type', 'type' => 'raw', 'value' => 'Apartment::getNameByType($data->type)', 'filter' => Apartment::getTypesArray(), 'sortable' => false), array('name' => 'obj_type_id', 'type' => 'raw', 'value' => '(isset($data->objType) && $data->objType) ? $data->objType->name : ""', 'filter' => Apartment::getObjTypesArray(), 'sortable' => false), array('header' => tc('Name'), 'name' => 'title_' . Yii::app()->language, 'type' => 'raw', 'value' => 'CHtml::link(CHtml::encode($data->{"title_".Yii::app()->language}), $data->getUrl())')); if (issetModule('location') && param('useLocation', 1)) { $columns[] = array('name' => 'loc_country', 'value' => '$data->loc_country ? $data->locCountry->name : ""', 'htmlOptions' => array('style' => 'width: 150px;'), 'sortable' => false, 'filter' => Country::getCountriesArray(0, 1)); $columns[] = array('name' => 'loc_region', 'value' => '$data->loc_region ? $data->locRegion->name : ""', 'htmlOptions' => array('style' => 'width: 150px;'), 'sortable' => false, 'filter' => Region::getRegionsArray($model->loc_country, 0, 1)); $columns[] = array('name' => 'loc_city', 'value' => '$data->loc_city ? $data->locCity->name : ""', 'htmlOptions' => array('style' => 'width: 150px;'), 'sortable' => false, 'filter' => City::getCitiesArray($model->loc_region, 0, 1)); } else { $columns[] = array('name' => 'city_id', 'value' => '$data->city_id ? $data->city->name : ""', 'sortable' => false, 'filter' => ApartmentCity::getAllCity()); } if (issetModule('paidservices')) { $columns[] = array('header' => tc('Paid services'), 'value' => '$data->getPaidHtml(false, false, true)', 'type' => 'raw', 'htmlOptions' => array('class' => 'width70 center')); } $columns[] = array('class' => 'CButtonColumn', 'deleteConfirmation' => tc('Are you sure you want to delete this item?'), 'viewButtonUrl' => '$data->getUrl()', 'buttons' => array('update' => array('url' => 'Yii::app()->createUrl("/userads/main/update", array("id" => $data->id))'), 'delete' => array('url' => 'Yii::app()->createUrl("/userads/main/delete", array("id" => $data->id))'))); $this->widget('NoBootstrapGridView', array('id' => 'userads-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => $columns));
<?php $this->pageTitle = Yii::app()->name . ' - ' . IecsvModule::t('Import / Export'); $this->breadcrumbs = array(tt('Import')); $this->adminTitle = tt('Import'); ?> <div> <p><?php echo tt('Please select ads for import.'); ?> </p> </div> <?php $this->widget('CustomHistoryGridView', array('id' => 'import-grid', 'dataProvider' => $itemsProvider, 'enablePagination' => true, 'selectableRows' => 2, 'selectionChanged' => 'js:selItemsSelected', 'columns' => array(array('class' => 'CCheckBoxColumn', 'header' => tt('Select'), 'id' => 'itemsSelectedImport'), array('header' => tt('Type', 'apartments'), 'name' => 'type', 'type' => 'raw', 'value' => 'Apartment::getNameByType($data["type"])', 'htmlOptions' => array('style' => 'width: 100px;'), 'sortable' => false, 'filter' => false), array('header' => tt('City', 'apartments'), 'name' => 'city_id', 'value' => '$data["cityName"] ? $data["cityName"] : ""', 'htmlOptions' => array('style' => 'width: 150px;'), 'filter' => ApartmentCity::getAllCity(), 'sortable' => false), array('header' => tc('Name'), 'name' => 'title_' . Yii::app()->language, 'type' => 'raw', 'value' => 'CHtml::encode($data["title_".Yii::app()->language])', 'sortable' => false, 'filter' => false)))); ?> <div class="form"> <?php $form = $this->beginWidget('CActiveForm', array('id' => 'import-form', 'method' => 'post', 'action' => $this->createAbsoluteUrl('/iecsv/backend/main/importProcess'), 'enableClientValidation' => false)); echo $form->hiddenField($model, 'itemsSelectedImport'); echo CHtml::hiddenField('is_submit', 0, array('id' => 'is_submit')); echo $form->hiddenField($model, 'selectedImportUser'); ?> <div class="clear"> </div> <div class="rowold"> <?php echo $form->labelEx($model, 'selectedImportUser'); if (!isset($areasSelected) || !$areasSelected) {