Advertisement
abushyk

Local_Kvartira_View

Jan 31st, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.14 KB | None | 0 0
  1. <?php
  2. class Local_Kvartira_View extends Kvartira_View {
  3.    
  4.     function main ( $realty_id ) {
  5.         $result=false;
  6.         require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/model/model.php');
  7.         require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/admin/structure/structure_manager.php');
  8.         require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/admin/users/user_object_manager.php');
  9.        
  10.         $Structure_Manager = new Structure_Manager();
  11.         $category_structure = $Structure_Manager->loadCategoryStructure();
  12.         $user_object_manager = new User_Object_Manager();
  13.  
  14.         $data_model = new Data_Model();
  15.         $form_data = $data_model->get_kvartira_model(false, false);
  16.         $form_data_language = $data_model->get_kvartira_model(false, true);
  17.        
  18.         $data_model_shared = $data_model->get_kvartira_model(false, true);
  19.        
  20.        
  21.         $form_data['data']['fio']['name'] = 'fio';
  22.         $form_data['data']['fio']['title'] = Multilanguage::_('L_FIO');
  23.         $form_data['data']['fio']['value'] = '';
  24.         $form_data['data']['fio']['length'] = 40;
  25.         $form_data['data']['fio']['type'] = 'safe_string';
  26.         $form_data['data']['fio']['required'] = 'on';
  27.         $form_data['data']['fio']['unique'] = 'off';
  28.        
  29.         $form_data['data']['phone']['name'] = 'phone';
  30.         $form_data['data']['phone']['title'] = Multilanguage::_('L_PHONE');
  31.         $form_data['data']['phone']['value'] = '';
  32.         $form_data['data']['phone']['length'] = 40;
  33.         $form_data['data']['phone']['type'] = 'safe_string';
  34.         $form_data['data']['phone']['required'] = 'on';
  35.         $form_data['data']['phone']['unique'] = 'off';
  36.        
  37.         if ( $this->getConfigValue('theme') == 'etown' or $this->getConfigValue('theme') == 'domdizart' ) {
  38.             $form_data['data']['url']['name'] = 'url';
  39.             $form_data['data']['url']['title'] = Multilanguage::_('URL_NAME','system');
  40.             $form_data['data']['url']['value'] = '';
  41.             $form_data['data']['url']['length'] = 40;
  42.             $form_data['data']['url']['type'] = 'safe_string';
  43.             $form_data['data']['url']['required'] = 'off';
  44.             $form_data['data']['url']['unique'] = 'off';
  45.         }
  46.        
  47.         if($this->getConfigValue('more_fields_in_lk')==1){
  48.             require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/system/user/data/user_data.php');
  49.             $UDM=new User_Data_Manager();
  50.             $form_data=$UDM->init_more_fields($form_data);
  51.             $this->template->assign('see_my_fields', '1');
  52.         }
  53.        
  54.        
  55.        
  56.        
  57.         $form_user = $user_object_manager->get_user_model();
  58.        
  59.        
  60.         $form_data = $data_model->init_model_data_from_db ( 'data', 'id', $realty_id, $form_data['data'], true );
  61.         $form_data_language = $data_model->init_model_data_from_db ( 'data', 'id', $realty_id, $form_data_language['data'], true );
  62.         $data_model_shared = $data_model->init_model_data_from_db ( 'data', 'id', $realty_id, $data_model_shared['data'], true );
  63.        
  64.         if(!$form_data){
  65.             return $result;
  66.         }
  67.         $result=true;
  68.        
  69.         $form_data = $data_model->init_language_values($form_data, $form_data_language);
  70.            
  71.        
  72.        
  73.        
  74.         $topic_id=0;
  75.         if(isset($form_data['topic_id'])){
  76.             $topic_id=(int)$form_data['topic_id']['value'];
  77.         }
  78.        
  79.         if($topic_id!=0){
  80.             foreach ( $form_data as $key => $item_array ) {
  81.                
  82.                 if($topic_id!=0 && isset($item_array['active_in_topic']) && $item_array['active_in_topic']!=0){
  83.                     $active_array_ids = explode(',',$item_array['active_in_topic']);
  84.                     $child_cats = array();
  85.                     foreach ($active_array_ids as $item_id => $check_active_id) {
  86.                         $child_cats_compare = $Structure_Manager->get_all_childs($check_active_id, $category_structure);
  87.                         if ( is_array($child_cats_compare) ) {
  88.                             $child_cats = array_merge($child_cats, $child_cats_compare);
  89.                         }
  90.                         $child_cats[]=$check_active_id;
  91.            
  92.                     }
  93.                    
  94.                                
  95.                     if(!in_array($topic_id, $child_cats)){
  96.                         unset($form_data[$key]);
  97.                         continue;
  98.                     }
  99.                 }
  100.             }
  101.         }
  102.        
  103.         if($this->getConfigValue('apps.realtypro.show_contact.enable')){
  104.             $form_user = $data_model->init_model_data_from_db ( 'user', 'user_id', $data_model_shared['user_id']['value'], $form_user['user'], true);
  105.         }else{
  106.             $form_user = $data_model->init_model_data_from_db ( 'user', 'user_id', $data_model_shared['user_id']['value'], $form_user['user'], true);
  107.         }
  108.        
  109.        
  110.         if(isset($form_data['date_added']) && $form_data['date_added']['value']!=''){
  111.             $form_data['date_added']['value_string']=date('d-m-Y', strtotime($form_data['date_added']['value']));
  112.         }
  113.        
  114.        
  115.        
  116.         if ( $this->getConfigValue('apps.company.timelimit') ) {
  117.             //check timelimit for this company
  118.             $current_time = time();
  119.             $query = "select re_data.* from re_data, re_user u, re_company c where re_data.id=$realty_id and re_data.user_id=u.user_id and u.company_id=c.company_id and c.start_date <= $current_time and c.end_date >= $current_time";
  120.             $this->db->exec($query);
  121.             $this->db->fetch_assoc();
  122.             if ( $this->db->row['id'] == '' ) {
  123.                 $this->template->assign('error_message', Multilanguage::_('L_MESSAGE_ARCHIVED_AD'));
  124.                 $this->template->assign('main_file_tpl', 'error_message.tpl');
  125.                 return false;
  126.             }
  127.              
  128.         }
  129.         if ( $this->getConfigValue('apps.company.enable') ) {
  130.             require_once (SITEBILL_DOCUMENT_ROOT.'/apps/company/admin/admin.php');
  131.             $company_admin = new company_admin();
  132.             $company_profile = $company_admin->load_by_id($form_user['company_id']['value']);
  133.            
  134.             if ( $company_profile ) {
  135.                 $this->template->assign('company_profile', $company_profile);
  136.             }
  137.             $this->template->assign('user_company_data', $company_admin->getUserCompanyData($form_user['user_id']['value']));
  138.            
  139.         }
  140.        
  141.         if(isset($form_data['topic_id'])){
  142.             $form_data['topic_id']['value_string']=$category_structure['catalog'][$form_data['topic_id']['value']]['name'];
  143.         }
  144.        
  145.        
  146.        
  147.         foreach($form_data as $hvd){
  148.             if($hvd['tab']==''){
  149.                 $hvd_tabbed[$this->getConfigValue('default_tab_name')][]=$hvd;
  150.             }else{
  151.                 $hvd_tabbed[$hvd['tab']][]=$hvd;
  152.             }
  153.            
  154.         }
  155.        
  156.         $this->template->assert('hvd_tabbed',$hvd_tabbed);
  157.        
  158.        
  159.        
  160.        require_once SITEBILL_DOCUMENT_ROOT.'/apps/currency/admin/admin.php';
  161.        $CA=new currency_admin();
  162.      
  163.         $simparams=array(
  164.             'id'=>(int)$form_data['id']['value'],
  165.             'topic_id'=>(int)$form_data['topic_id']['value'],
  166.             'city_id'=>(int)$form_data['city_id']['value'],
  167.             'district_id'=>(int)$form_data['district_id']['value'],
  168.             'street_id'=>(int)$form_data['street_id']['value'],
  169.         );
  170.         $this->template->assign('similar_data', $this->getSimilar($category_structure,$simparams));
  171.        
  172.        
  173.         if($form_user['login']['value']=='_unregistered'){
  174.             $form_user['fio']['value']=$form_data['fio']['value'];
  175.             $form_user['phone']['value']=$form_data['phone']['value'];
  176.         }
  177.        
  178.         if($this->getConfigValue('use_google_map')){
  179.             $this->template->assign('map_type', 'google');
  180.         }
  181.  
  182.         $this->template->assign('admin_user_id', $this->getAdminUserId());
  183.         $this->template->assign('current_user_id', $this->getSessionUserId());
  184.         $this->template->assign('photo', $form_data['image']['image_array']);
  185.         $this->template->assign('user_data', $form_user);
  186.         $this->template->assign('yandex_map_key', $this->getConfigValue('yandex_map_key'));
  187.         $this->template->assign('pmap', $this->getConfigValue('pmap'));
  188.        
  189.        
  190.        
  191.         $params['topic_id'] = (int)$form_data['topic_id']['value'];
  192.        
  193.         $d=$this->get_category_breadcrumbs( $params, $category_structure, SITEBILL_MAIN_URL.'/' );
  194.        
  195.         $this->template->assign('realty_breadcrumbs', explode(' / ', $d));
  196.         $this->template->assign('breadcrumbs', $this->get_category_breadcrumbs( $params, $category_structure, SITEBILL_MAIN_URL.'/' ) );
  197.        
  198.         $hasTlocation=false;
  199.         $tlocationElement='';
  200.        
  201.         foreach($form_data as $key=>$val){
  202.             if($val['type']=='tlocation'){
  203.                
  204.                 $hasTlocation=true;
  205.                 $tlocationElement=$key;
  206.                 $form_data['country_id']['value_string']=$val['value_string']['country_id'];
  207.                 $form_data['region_id']['value_string']=$val['value_string']['region_id'];
  208.                 $form_data['city_id']['value_string']=$val['value_string']['city_id'];
  209.                 $form_data['district_id']['value_string']=$val['value_string']['district_id'];
  210.                 $form_data['street_id']['value_string']=$val['value_string']['street_id'];
  211.             }
  212.         }
  213.         $this->template->assign('data', $form_data);
  214.         //начало формирования мета-информации и заголовков
  215.         if($hasTlocation){
  216.             $title=$this->get_category_breadcrumbs_string( $params, $category_structure, SITEBILL_MAIN_URL.'/' ).", ".$form_data[$tlocationElement]['tlocation_string'].", ".number_format($form_data['price']['value'],0,',',' ');
  217.         }else{
  218.             $title=$this->get_category_breadcrumbs_string( $params, $category_structure, SITEBILL_MAIN_URL.'/' ).", ".$form_data['city_id']['value_string'].", ".$form_data['street_id']['value_string'].", ".number_format($form_data['price']['value'],0,',',' ');
  219.         }
  220.          
  221.         if($form_data['meta_title']['value']==''){
  222.             $meta_title=$title;
  223.         }else{
  224.             $meta_title=$form_data['meta_title']['value'];
  225.         }
  226.        
  227.         $this->template->assign('meta_title', $meta_title);
  228.         $this->template->assign('title', $title);
  229.        
  230.         if($form_data['meta_description']['value']!=''){
  231.             $this->template->assign('meta_description', $form_data['meta_description']['value']);
  232.         }
  233.        
  234.         if($form_data['meta_keywords']['value']!=''){
  235.             $this->template->assign('meta_keywords', $form_data['meta_keywords']['value']);
  236.         }
  237.         //конец формирования мета-информации и заголовков
  238.        
  239.         if(1==$this->getConfigValue('apps.comment.enable')){
  240.             require_once SITEBILL_DOCUMENT_ROOT.'/apps/comment/admin/admin.php';
  241.             require_once SITEBILL_DOCUMENT_ROOT.'/apps/comment/site/site.php';
  242.             $CoM=new comment_site();
  243.             require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/system/user/login.php');
  244.             $Login = new Login();
  245.             $user_id=(int)$Login->getSessionUserId();
  246.             $commentsPanel=$CoM->generateCommentPanel($user_id, 'data', $realty_id);
  247.         }
  248.        
  249.        
  250.         $gdata=array();
  251.         $gd=array();
  252.         foreach ($form_data as $key=>$value){
  253.             if($key=='city_id'){
  254.                 $gd['city']=SiteBill::iconv(SITE_ENCODING, 'utf-8', $value['value_string']);
  255.             }elseif($key=='street_id'){
  256.                 $gd['street']=SiteBill::iconv(SITE_ENCODING, 'utf-8', $value['value_string']);
  257.             }elseif($key=='price'){
  258.                 $gd['price']=$value['value'];
  259.             }elseif($key=='topic_id'){
  260.                 $gd['type_sh']=SiteBill::iconv(SITE_ENCODING, 'utf-8', $value['value_string']);
  261.             }else{
  262.                 $gd[$key]=$value['value'];
  263.             }
  264.         }
  265.        
  266.         if(file_exists(SITEBILL_DOCUMENT_ROOT.'/template/frontend/'.$this->getConfigValue('theme').'/realty_on_map.tpl')){
  267.             global $smarty;
  268.             $smarty->assign('realty', $gd);
  269.             $html=$smarty->fetch(SITEBILL_DOCUMENT_ROOT.'/template/frontend/'.$this->getConfigValue('theme').'/realty_on_map.tpl');
  270.             $html = str_replace("\r\n", ' ', $html);
  271.             $html = str_replace("\n", ' ', $html);
  272.             $html = str_replace("\t", ' ', $html);
  273.             $html = addslashes($html);
  274.         }else{
  275.             $html = '';
  276.         }
  277.         $gd['html']=SiteBill::iconv(SITE_ENCODING, 'utf-8', $html);
  278.         $gd['href']='#';
  279.         $geoobjects_collection=array();
  280.         if(isset($form_data['geo']) && $form_data['geo']['value']['lat']!='' && $form_data['geo']['value']['lng']!=''){
  281.             $gd['geo_lat']=$form_data['geo']['value']['lat'];
  282.             $gd['geo_lng']=$form_data['geo']['value']['lng'];
  283.            
  284.             $gc=$gd['geo_lat'].'_'.$gd['geo_lng'];
  285.            
  286.             $geoobjects_collection[$gc]['html'].=$gd['html'];
  287.             $geoobjects_collection[$gc]['count']++;
  288.             $geoobjects_collection[$gc]['lat']=$gd['geo_lat'];
  289.             $geoobjects_collection[$gc]['lng']=$gd['geo_lng'];
  290.         }
  291.        
  292.         $this->template->assert('geoobjects_collection_clustered', json_encode($geoobjects_collection));
  293.        
  294.        
  295.        
  296.        
  297.         if ( $this->getConfigValue('theme') != 'estate' and !file_exists(SITEBILL_DOCUMENT_ROOT.'/template/frontend/'.$this->getConfigValue('theme').'/realty_view.tpl') ) {
  298.             $this->template->assign('main_file_tpl', '../estate/realty_view.tpl');
  299.         } else {
  300.             $this->template->assign('main_file_tpl', 'realty_view.tpl');
  301.         }
  302.        
  303.         return $result;
  304.     }
  305.    
  306.    
  307. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement