/**
  * Initializes the route.
  * This method is invoked after the route is created by the route manager.
  */
 public function init()
 {
     // required for correct PhpConsoleExtension work
     YiiBase::app()->getErrorHandler()->discardOutput = false;
     YiiBase::getLogger()->autoFlush = 1;
     // init PHP Console
     require_once dirname(__FILE__) . '/PhpConsole/PhpConsole.php';
     PhpConsole::$callOldErrorHandler = false;
     PhpConsole::$callOldExceptionsHandler = false;
     PhpConsole::start($this->handleErrors, $this->handleExceptions, $this->basePathToStrip);
 }
Example #2
0
 /**
  * Register a specific js file in the asset's js folder
  * @param string $jsFile
  * @param int $position the position of the JavaScript code.
  * @see CClientScript::registerScriptFile
  */
 public static function tsRegisterAssetJs($jsFile, $position = CClientScript::POS_END)
 {
     $assetsPath = Yii::getPathOfAlias(YiiBase::app()->getController()->getModule()->getId() . '.assets');
     $assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, true);
     Yii::app()->getClientScript()->registerScriptFile($assetsUrl . "/js/" . YiiBase::app()->getController()->getId() . "/" . $jsFile, $position);
 }
Example #3
0
 /**
  * @return MinimalApplication
  */
 public static function app()
 {
     return parent::app();
 }
echo Yii::app()->request->baseUrl;
?>
/css/form.css" />

    <title><?php 
echo CHtml::encode($this->pageTitle);
?>
</title>
</head>

<body>

<div class="container1" id="page1">

    <?php 
if (!YiiBase::app()->user->isGuest) {
    ?>
        <div id="header">
            <div id="logo"><?php 
    echo CHtml::encode(Yii::app()->name);
    ?>
</div>
        </div><!-- header -->

        <div id="mainmenu">
            <?php 
    $this->widget('zii.widgets.CMenu', array('items' => array(array('label' => 'Таблица', 'url' => array('/report/')), array('label' => 'Города', 'url' => array('/city/')), array('label' => 'Сайты', 'url' => array('/sites/')), array('label' => 'Выход (' . Yii::app()->user->name . ')', 'url' => array('/site/logout'), 'visible' => !Yii::app()->user->isGuest))));
    ?>
        </div><!-- mainmenu -->
        <?php 
    if (isset($this->breadcrumbs)) {
 public function action()
 {
     if ($this->hasErrors()) {
         echo '<pre>';
         print_r($this->errors);
     } else {
         //определяем город юзера по его IP
         $this->city = YiiBase::app()->sypexgeo->action($this->ip);
         //не удалось определить город по IP юзера
         if (empty($this->city)) {
             //тогда выбираем город-Москва и отдаём данные по этому городу
             $city = $this->getMoscow();
         } else {
             //поиск города в справочнике
             $city_row = City::findTownByName($this->city);
             //Не нашли город в справочнике
             if (empty($city_row)) {
                 //не удалось найти город в нашем списке - тогда город - Москва для этого сайта
                 $city = $this->getMoscow();
             } else {
                 //поиск соответствия = город+сайт+активность
                 $query = YiiBase::app()->db->cache(3600)->createCommand('SELECT * FROM {{city_site_phone}} WHERE city_id=:city_id AND site_id=:site_id AND active=1');
                 $query->bindValue(':city_id', $city_row['id'], PDO::PARAM_INT);
                 $query->bindValue(':site_id', $this->site_id, PDO::PARAM_INT);
                 $city = $query->queryRow();
                 //не нашли совпадения по АКТИВНОСТИ_города+совпадению_по_сайту+названию_города
                 if (empty($city)) {
                     $city = $this->getMoscow();
                     //учитываем метку рекламы и если есть метка рекламы-  выводим номер для рекламы
                     $this->phones[self::getPhoneUtm($city)] = 'Москва';
                 }
             }
         }
         //формируем список активных регионов по сайту, для отображения
         if (empty($this->regions)) {
             $this->regions = CHtml::listData($this->findActiveRegions(), 'city', 'phone');
         }
         //если город - АКТИВЕН - используем его телефон
         if (!empty($city) && empty($this->phones)) {
             //получим массив всей информаци о городе
             $row_info_city = City::findById($city['city_id']);
             //определяем сколько строчек телефонов будет
             if ($row_info_city['main_city'] == City::NOT_ACTIVE) {
                 //(3 номера)
                 //добавили номер города
                 $this->phones[self::getPhoneUtm($city)] = $row_info_city['city'];
             }
             ////если есть привязки к шаблонам - ищем телефон подвязанный к шаблону(если НЕ находим то возвращаем по дефолту номер)
             $phone_from_template = Phone::getPhoneByTemplateANDCity($this->template, $row_info_city['parent_id'], $this->site_id);
             $region_city_name = City::findNameTownById($row_info_city['parent_id']);
             // нашли номер телефона подвязанного к шаблону
             //к шаблону не будет подвязок номеров рекламы, поэтому не проверяем и не подвязываем доп. номера
             if (!empty($phone_from_template)) {
                 $this->phones[$phone_from_template] = $region_city_name;
                 $this->regions[$region_city_name] = $phone_from_template;
             } else {
                 $query_region = YiiBase::app()->db->createCommand('SELECT phone, google_phone, direct_phone FROM {{city_site_phone}} WHERE city_id=:city_id AND site_id=:site_id');
                 $query_region->bindValue(':site_id', $this->site_id, PDO::PARAM_INT);
                 $query_region->bindValue(':city_id', $row_info_city['parent_id'], PDO::PARAM_INT);
                 $region_default_phone = $query_region->queryRow();
                 //используем номер телефона региона по-умолчанию
                 $this->phones[self::getPhoneUtm($region_default_phone)] = $region_city_name;
             }
         }
     }
 }
Example #6
0
                                                            <li class="dropdown-tree  <?php 
echo YiiBase::app()->getController()->action->id == "create" && YiiBase::app()->getController()->getId() == "productoSubcategoria" ? "open-tree" : "";
?>
"><a  class="<?php 
echo YiiBase::app()->getController()->action->id == "create" ? "dropdown-tree-a" : "";
?>
" href="<?php 
echo Yii::app()->createUrl('producto/productoSubcategoria/create');
?>
">Nuevo</a></li>
                                                            <li class="dropdown-tree  <?php 
echo YiiBase::app()->getController()->action->id == "admin" && YiiBase::app()->getController()->getId() == "productoSubcategoria" ? "open-tree" : "";
?>
"><a  class="<?php 
echo YiiBase::app()->getController()->action->id == "admin" ? "dropdown-tree-a" : "";
?>
" href="<?php 
echo Yii::app()->createUrl('producto/productoSubcategoria');
?>
">Administrar</a></li>

                                                        </ul>
                                                    </li>

                                                </ul>
                                            </div>
                                        </div>
                                    </div>

                                </div>
 protected function afterSave()
 {
     parent::afterSave();
     //при создании - если это регион ? - обновим привязку родителя на него же самого
     if ($this->isNewRecord) {
         if ($this->main_city == 1) {
             $query = YiiBase::app()->db->createCommand('UPDATE {{city}} SET parent_id=:parent_id WHERE id=:id');
             $query->bindValue(':id', $this->id, PDO::PARAM_INT);
             $query->bindValue(':parent_id', $this->id, PDO::PARAM_INT);
             $query->execute();
         }
     }
 }
 protected function afterSave()
 {
     parent::afterSave();
     //при обновлении подвязки-шаблона и телефона мог измениться город
     if (!$this->isNewRecord) {
         //принудительно укажем, что к данной связке(город+сайт)-подвязан (шаблон+телефон+сайт)
         $query = YiiBase::app()->db->createCommand('UPDATE {{city_site_phone}} SET relation_tpl=1 WHERE city_id=:city_id AND site_id=:site_id');
         $query->bindValue(':city_id', $this->city_id, PDO::PARAM_INT);
         $query->bindValue(':site_id', $this->site_id, PDO::PARAM_INT);
         $query->execute();
     }
 }
 public function actionSypexAdvanced()
 {
     if (isset($_GET['ip']) && isset($_GET['site_id'])) {
         //определяем город по Айпи
         $city = YiiBase::app()->sypexgeo->action($_GET['ip']);
         //не удалось определить город по IP
         if (empty($city)) {
             echo '8-800-333-85-07';
             die;
         }
         $city_name = City::findTownByName(trim($city));
         if (empty($city_name)) {
             echo '8-800-333-85-07';
             die;
         }
         //на основании города/сайта - находим номер телефона
         $phone_query = YiiBase::app()->db->cache(3600)->createCommand('SELECT phone FROM {{city_site_phone}}  WHERE site_id=:site_id AND city_id=:city_id');
         $phone_query->bindValue(':city_id', $city_name['id'], PDO::PARAM_INT);
         $phone_query->bindValue(':site_id', $_GET['site_id'], PDO::PARAM_INT);
         $phone = $phone_query->queryScalar();
         //если нашли номер телефона по городу, изменим город на Москву и найдём номер
         if ($phone) {
             echo $city_name['city'] . ' ' . $phone;
             die;
         } else {
             //НЕ нашли совпадение по городу и сайту
             //ищем совпадение по Московском области, если город попадает в МО
             $city_moscow = City::findTownByName('Москва');
             //есть совпадение по МО
             if ($city_name['parent_id'] == $city_moscow['id']) {
                 $phone_query = YiiBase::app()->db->cache(3600)->createCommand('SELECT phone FROM {{city_site_phone}}  WHERE site_id=:site_id AND city_id=:city_id');
                 $phone_query->bindValue(':city_id', $city_moscow['id'], PDO::PARAM_INT);
                 $phone_query->bindValue(':site_id', $_GET['site_id'], PDO::PARAM_INT);
                 $phone = $phone_query->queryScalar();
                 echo 'Москва ' . $phone;
                 die;
             } else {
                 echo '8-800-333-85-07';
                 die;
             }
         }
     }
     die;
 }
        echo $c['date'];
        ?>
:
                                    </div>
                                </td>
                            <?php 
    } else {
        ?>
                                <td>
                                    <div class="person"><b><?php 
        echo $c['person'];
        ?>
 says:</b>
                                        <div><img style="width: 40px;border-radius: 50%;"
                                                  src="<?php 
        echo YiiBase::app()->baseUrl;
        ?>
/images/amicapic.jpg">
                                        </div>
                                    </div>
                                    <div class="chat_time"
                                         style="display:none;font-size: 10px;"><?php 
        echo $c['date'];
        ?>
</div>
                                </td>
                                <td>
                                    <div id='amica_talkbubble'><?php 
        echo $c['message'];
        ?>
</div>
 static function findNameTownById($id)
 {
     $sql = 'SELECT town FROM {{town}} WHERE id=:id';
     $query = YiiBase::app()->db->cache(3600)->createCommand($sql);
     $query->bindValue(':id', $id, PDO::PARAM_INT);
     return $query->queryScalar();
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         $model = $this->loadModel($id);
         $city_id = $model->city_id;
         $site_id = $model->site_id;
         $model->delete();
         //после удаления телефона/шаблона, проверим надо ли изменить признак
         $count_query = YiiBase::app()->db->createCommand('SELECT COUNT(id) FROM tbl_tpl_city_site WHERE city_id=:city_id AND site_id=:site_id');
         $count_query->bindValue(':city_id', $city_id, PDO::PARAM_INT);
         $count_query->bindValue('site_id', $site_id, PDO::PARAM_INT);
         $count = $count_query->queryScalar();
         //если нет больше подвязанных номеро/шаблонов изменим статус города, как не подвязанный к шаблону
         if ($count == 0) {
             $query = YiiBase::app()->db->createCommand('UPDATE tbl_city_site_phone SET relation_tpl=0 WHERE city_id=:city_id AND site_id=:site_id');
             $query->bindValue(':city_id', $city_id, PDO::PARAM_INT);
             $query->bindValue(':site_id', $site_id, PDO::PARAM_INT);
             $query->execute();
         }
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
 /**
  * Retrieves a list of models based on the current search/filter conditions.
  *
  * Typical usecase:
  * - Initialize the model fields with values from filter form.
  * - Execute this method to get CActiveDataProvider instance which will filter
  * models according to data in model fields.
  * - Pass data provider to CGridView, CListView or any similar widget.
  *
  * @return CActiveDataProvider the data provider that can return the models
  * based on the search/filter conditions.
  */
 public function search()
 {
     // @todo Please modify the following code to remove attributes that should not be searched.
     $criteria = new CDbCriteria();
     $criteria->with = array('city', 'site');
     $criteria->together = true;
     $criteria->compare('t.active', $this->active);
     $criteria->compare('t.relation_tpl', $this->relation_tpl);
     $criteria->compare('t.site_id', $this->site_id);
     $criteria->compare('city.main_city', $this->main_city);
     //==========фильтрация по регулярному выражению или отрацание по регулярке============================
     //проверим и примениним - ФИЛЬТРАЦИЮ по РЕГИОНУ(РЕГУЛЯРКА)
     if (isset($_GET['radio_selected_region']) && isset($_GET['search_word_accept_reg_region'])) {
         if (!empty($_GET['radio_selected_region']) && !empty($_GET['search_word_accept_reg_region'])) {
             //получаем список регионов, котор. попадают в совпадение по регулярке(ID-список регионов)
             if ($_GET['radio_selected_region'] == 'search_word_accept_region') {
                 //удовлетворяет регулярному выражению
                 $exception_list = YiiBase::app()->db->createCommand('SELECT id FROM {{city}} WHERE city REGEXP "' . $_GET['search_word_accept_reg_region'] . '" AND id=parent_id')->queryAll();
             } else {
                 //не удовлетворяет регулярному выражению
                 $exception_list = YiiBase::app()->db->createCommand('SELECT id FROM {{city}} WHERE city NOT REGEXP "' . $_GET['search_word_accept_reg_region'] . '" AND id=parent_id')->queryAll();
             }
             if (!empty($exception_list)) {
                 $ids = array();
                 foreach ($exception_list as $except) {
                     $ids[] = $except['id'];
                 }
                 //после получения списка регионов - находим по ним список привязанных городов и формируем ID-list вхождений
                 $list_ids = YiiBase::app()->db->createCommand('SELECT id FROM {{city}} WHERE parent_id IN (' . implode(',', $ids) . ')')->queryAll();
                 $ids = array();
                 foreach ($list_ids as $except) {
                     $ids[] = $except['id'];
                 }
                 if (!empty($exception_list)) {
                     $criteria->addInCondition('city_id', $ids);
                 }
             }
         }
     }
     //проверим и примениним - ФИЛЬТРАЦИЮ по ГОРОДУ(РЕГУЛЯРКА)
     if (isset($_GET['radio_selected_city']) && isset($_GET['search_word_accept_reg_city'])) {
         if (!empty($_GET['radio_selected_city']) && !empty($_GET['search_word_accept_reg_city'])) {
             //2 типа удовлетворяет регулярке или нет по регулярке
             if ($_GET['radio_selected_city'] == 'search_word_accept_city') {
                 //удовлетворяет регулярному выражению
                 $criteria->addCondition('city.city  REGEXP "' . $_GET['search_word_accept_reg_city'] . '"');
             } else {
                 //не удовлетворяет регулярному выражению
                 $criteria->addCondition('city.city NOT  REGEXP "' . $_GET['search_word_accept_reg_city'] . '"');
             }
         }
     }
     //проверим и примениним - ФИЛЬТРАЦИЮ по Местный телефон(РЕГУЛЯРКА)
     if (isset($_GET['radio_selected_localphone']) && isset($_GET['search_word_accept_reg_localphone'])) {
         if (!empty($_GET['radio_selected_localphone']) && !empty($_GET['search_word_accept_reg_localphone'])) {
             //2 типа удовлетворяет регулярке или нет по регулярке
             if ($_GET['radio_selected_localphone'] == 'search_word_accept_localphone') {
                 //удовлетворяет регулярному выражению
                 $criteria->addCondition('t.phone  REGEXP "' . $_GET['search_word_accept_reg_localphone'] . '"');
             } else {
                 //не удовлетворяет регулярному выражению
                 $criteria->addCondition('t.phone NOT  REGEXP "' . $_GET['search_word_accept_reg_localphone'] . '"');
             }
         }
     }
     //проверим и примениним - ФИЛЬТРАЦИЮ по региональный номер телефона(РЕГУЛЯРКА)
     if (isset($_GET['radio_selected_regionphone']) && isset($_GET['search_word_accept_reg_regionphone'])) {
         if (!empty($_GET['radio_selected_regionphone']) && !empty($_GET['search_word_accept_reg_regionphone'])) {
             //полчаем список ID-регионов, по которым есть воспадение в номере рег. выражения
             if ($_GET['radio_selected_regionphone'] == 'search_word_accept_regionphone') {
                 //удовлетворяет регулярному выражению
                 $exception_list = YiiBase::app()->db->createCommand('SELECT distinct(city_id) FROM {{city_site_phone}} WHERE phone REGEXP "' . $_GET['search_word_accept_reg_regionphone'] . '" AND active=1')->queryAll();
             } else {
                 //не удовлетворяет регулярному выражению
                 $exception_list = YiiBase::app()->db->createCommand('SELECT distinct(city_id) FROM {{city_site_phone}} WHERE phone NOT REGEXP "' . $_GET['search_word_accept_reg_regionphone'] . '" AND active=1')->queryAll();
             }
             if (!empty($exception_list)) {
                 $ids = array();
                 foreach ($exception_list as $except) {
                     $ids[] = $except['city_id'];
                 }
                 //поиск регионов по найденным совпадениям
                 $inner_ids = YiiBase::app()->db->createCommand('SELECT id FROM {{city}} WHERE main_city=1 AND id IN(' . implode(',', $ids) . ')')->queryAll();
                 if (!empty($inner_ids)) {
                     $in_ids = array();
                     foreach ($inner_ids as $id) {
                         $in_ids[] = $id['id'];
                     }
                     $criteria->addInCondition('city_id', $in_ids);
                 }
             }
         }
     }
     $sort = new CSort();
     $sort->defaultOrder = 'city.city asc';
     // устанавливаем сортировку по умолчанию
     $sort->attributes['city_id'] = array('asc' => 'city.city', 'desc' => 'city.city desc');
     //$sort->attributes['region_id'] = array('asc' => 'city.region.city','desc' => 'city.region.city desc');
     $sort->attributes['main_city'] = array('asc' => 'city.main_city', 'desc' => 'city.main_city desc');
     $sort->attributes['active'] = array('asc' => 'active', 'desc' => 'active desc');
     $sort->attributes['site_id'] = array('asc' => 'site.site', 'desc' => 'site.site desc');
     $sort->attributes['phone'] = array('asc' => 'phone', 'desc' => 'phone desc');
     $sort->attributes['relation_tpl'] = array('asc' => 'relation_tpl', 'desc' => 'relation_tpl desc');
     return new CActiveDataProvider($this, array('pagination' => array('pageSize' => 50), 'criteria' => $criteria, 'sort' => $sort));
 }
<?php

/* @var $this PhoneController */
/* @var $model Phone */
$this->menu = array(array('label' => 'List Phone', 'url' => array('index')), array('label' => 'Create Phone', 'url' => array('create')));
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$('#phone-grid').yiiGridView('update', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>
<h2><?php 
echo 'Город:' . $model->city->city;
?>
</h2>
<?php 
//echo CHtml::link('Advanced Search','#',array('class'=>'search-button btn'));
echo CHtml::link('Добавить', YiiBase::app()->createAbsoluteUrl('phone/create', array('Phone[city_id]' => $_GET['Phone']['city_id'])));
?>


<?php 
$this->widget('bootstrap.widgets.TbGridView', array('id' => 'phone-grid', 'dataProvider' => $model->search(), 'type' => TbHtml::GRID_TYPE_BORDERED, 'columns' => array(array('name' => 'phone', 'value' => '$data->phone', 'header' => 'Телефон'), array('name' => 'city_id', 'header' => 'Город', 'type' => 'raw', 'value' => '$data->city->city'), array('name' => 'template_id', 'value' => '$data->TemplateNameFromModx', 'header' => 'Шаблон'), array('name' => 'site_id', 'value' => '$data->site->site', 'header' => 'Сайт'), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update}{delete}'))));
<?php

/**
 * Created by PhpStorm.
 * User: user
 * Date: 12.12.14
 * Time: 9:31
 */
echo CHtml::link('Добавить', '/report/create/');
?>


<?php 
$this->widget('bootstrap.widgets.TbGridView', array('id' => 'city-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'ajaxUpdate' => false, 'template' => '{summary}{items}{pager}', 'type' => TbHtml::GRID_TYPE_BORDERED, 'columns' => array(array('header' => 'Город', 'value' => '$data->city->city', 'name' => 'city_id', 'filter' => $this->widget('application.components.CityFilterWidget', array(), true)), array('header' => 'Регион', 'name' => 'region_id', 'type' => 'raw', 'value' => '$data->city->region->city', 'filter' => $this->widget('application.components.RegionFilterWidget', array(), true)), array('header' => 'Областной центр', 'type' => 'raw', 'name' => 'main_city', 'value' => 'City::getYesNot($data->city->main_city)', 'filter' => array(1 => 'Да', 0 => 'Нет')), array('header' => 'Привязка к шаблону', 'type' => 'raw', 'name' => 'relation_tpl', 'value' => '$data->relationtpl', 'filter' => array(1 => 'Да', 0 => 'Нет')), array('header' => 'Активен', 'type' => 'raw', 'name' => 'active', 'value' => 'CHtml::link(City::getYesNot($data->active),"' . YiiBase::app()->createAbsoluteUrl('city/changeactive') . '", array("class"=>"action_active", "city_id"=>$data->id))', 'filter' => array(1 => 'Да', 0 => 'Нет')), array('header' => 'Местный телефон', 'name' => 'phone', 'value' => '$data->phone', 'type' => 'raw', 'filter' => $this->widget('application.components.LocalPhoneFilterWidget', array(), true)), array('name' => 'region_phone', 'value' => '$data->region_phone', 'type' => 'raw', 'header' => 'Регион. телефон', 'filter' => $this->widget('application.components.RegionPhoneFilterWidget', array(), true)), array('header' => 'Сайт', 'type' => 'raw', 'name' => 'site_id', 'value' => '$data->site->site', 'filter' => CHtml::listData(Site::model()->findAll(), 'id', 'site')), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update}'))));