Advertisement
abushyk

Untitled

Jan 20th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.31 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.        
  11.        
  12.        
  13.         $Structure_Manager = new Structure_Manager();
  14.         $category_structure = $Structure_Manager->loadCategoryStructure();
  15.         $user_object_manager = new User_Object_Manager();
  16.  
  17.         $data_model = new Data_Model();
  18.         $form_data = $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.         $form_data = $data_model->init_model_data_from_db ( 'data', 'id', $realty_id, $form_data['data'], true );
  60.         if(!$form_data){
  61.             return $result;
  62.         }
  63.         $result=true;
  64.        
  65.         $form_data = $data_model->init_language_values($form_data);
  66.            
  67.        
  68.        
  69.        
  70.         $topic_id=0;
  71.         if(isset($form_data['topic_id'])){
  72.             $topic_id=(int)$form_data['topic_id']['value'];
  73.         }
  74.        
  75.         if($topic_id!=0){
  76.             //require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/admin/structure/structure_manager.php');
  77.             //$SM=new Structure_Manager();
  78.             //$category_structure=$SM->loadCategoryStructure();
  79.        
  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.                         //echo '$check_active_id = '.$check_active_id.'<br>';
  87.                         $child_cats_compare = $Structure_Manager->get_all_childs($check_active_id, $category_structure);
  88.                         if ( is_array($child_cats_compare) ) {
  89.                             $child_cats = array_merge($child_cats, $child_cats_compare);
  90.                         }
  91.                         $child_cats[]=$check_active_id;
  92.            
  93.                     }
  94.                    
  95.                                
  96.                     if(!in_array($topic_id, $child_cats)){
  97.                         unset($form_data[$key]);
  98.                         continue;
  99.                     }
  100.                 }
  101.             }
  102.         }
  103.        
  104.         if($this->getConfigValue('apps.realtypro.show_contact.enable')){
  105.             $form_user = $data_model->init_model_data_from_db ( 'user', 'user_id', $form_data['user_id']['value'], $form_user['user'], true);
  106.         }else{
  107.             $form_user = $data_model->init_model_data_from_db ( 'user', 'user_id', $form_data['user_id']['value'], $form_user['user'], true);
  108.         }
  109.        
  110.        
  111.        
  112.         if(isset($form_data['date_added']) && $form_data['date_added']['value']!=''){
  113.             $form_data['date_added']['value_string']=date('d-m-Y', strtotime($form_data['date_added']['value']));
  114.         }
  115.        
  116.        
  117.        
  118.         if ( $this->getConfigValue('apps.company.timelimit') ) {
  119.             //check timelimit for this company
  120.             $current_time = time();
  121.             $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";
  122.             $this->db->exec($query);
  123.             $this->db->fetch_assoc();
  124.             if ( $this->db->row['id'] == '' ) {
  125.                 $this->template->assign('error_message', Multilanguage::_('L_MESSAGE_ARCHIVED_AD'));
  126.                 $this->template->assign('main_file_tpl', 'error_message.tpl');
  127.                 return false;
  128.             }
  129.              
  130.         }
  131.         if ( $this->getConfigValue('apps.company.enable') ) {
  132.             require_once (SITEBILL_DOCUMENT_ROOT.'/apps/company/admin/admin.php');
  133.             $company_admin = new company_admin();
  134.             $company_profile = $company_admin->load_by_id($form_user['company_id']['value']);
  135.             //print_r($company_profile);
  136.             if ( $company_profile ) {
  137.                 $this->template->assign('company_profile', $company_profile);
  138.             }
  139.             $this->template->assign('user_company_data', $company_admin->getUserCompanyData($form_user['user_id']['value']));
  140.            
  141.         }
  142.        
  143.         if(isset($form_data['topic_id'])){
  144.             $form_data['topic_id']['value_string']=$category_structure['catalog'][$form_data['topic_id']['value']]['name'];
  145.         }
  146.        
  147.        
  148.         //$data_view_data=$form_data['booking_hotel'];
  149.         foreach($form_data as $hvd){
  150.             if($hvd['tab']==''){
  151.                 $hvd_tabbed[$this->getConfigValue('default_tab_name')][]=$hvd;
  152.             }else{
  153.                 $hvd_tabbed[$hvd['tab']][]=$hvd;
  154.             }
  155.            
  156.         }
  157.        
  158.         $this->template->assert('hvd_tabbed',$hvd_tabbed);
  159.        
  160.        
  161.        
  162.        require_once SITEBILL_DOCUMENT_ROOT.'/apps/currency/admin/admin.php';
  163.        $CA=new currency_admin();
  164.       // echo $form_data['price']['value']. ' '.$form_data['curency_id']['value'];
  165.         //$form_data['price']['value']=$CA->convert($form_data['price']['value'], $form_data['currency_id']['value'],CURRENT_CURRENCY);
  166.         $simparams=array(
  167.             'id'=>(int)$form_data['id']['value'],
  168.             'topic_id'=>(int)$form_data['topic_id']['value'],
  169.             'city_id'=>(int)$form_data['city_id']['value'],
  170.             'district_id'=>(int)$form_data['district_id']['value'],
  171.             'street_id'=>(int)$form_data['street_id']['value'],
  172.         );
  173.         $this->template->assign('similar_data', $this->getSimilar($category_structure,$simparams));
  174.        
  175.        
  176.         if($form_user['login']['value']=='_unregistered'){
  177.             $form_user['fio']['value']=$form_data['fio']['value'];
  178.             $form_user['phone']['value']=$form_data['phone']['value'];
  179.         }
  180.        
  181.         if($this->getConfigValue('use_google_map')){
  182.             $this->template->assign('map_type', 'google');
  183.         }
  184.  
  185.         $this->template->assign('admin_user_id', $this->getAdminUserId());
  186.         $this->template->assign('current_user_id', $this->getSessionUserId());
  187.         $this->template->assign('photo', $form_data['image']['image_array']);
  188.         $this->template->assign('user_data', $form_user);
  189.         $this->template->assign('yandex_map_key', $this->getConfigValue('yandex_map_key'));
  190.         $this->template->assign('pmap', $this->getConfigValue('pmap'));
  191.        
  192.        
  193.        
  194.         $params['topic_id'] = (int)$form_data['topic_id']['value'];
  195.        
  196.         $d=$this->get_category_breadcrumbs( $params, $category_structure, SITEBILL_MAIN_URL.'/' );
  197.        
  198.         $this->template->assign('realty_breadcrumbs', explode(' / ', $d));
  199.         $this->template->assign('breadcrumbs', $this->get_category_breadcrumbs( $params, $category_structure, SITEBILL_MAIN_URL.'/' ) );
  200.        
  201.         $hasTlocation=false;
  202.         $tlocationElement='';
  203.        
  204.         foreach($form_data as $key=>$val){
  205.             if($val['type']=='tlocation'){
  206.                 //print_r($val);
  207.                 $hasTlocation=true;
  208.                 $tlocationElement=$key;
  209.                 $form_data['country_id']['value_string']=$val['value_string']['country_id'];
  210.                 $form_data['region_id']['value_string']=$val['value_string']['region_id'];
  211.                 $form_data['city_id']['value_string']=$val['value_string']['city_id'];
  212.                 $form_data['district_id']['value_string']=$val['value_string']['district_id'];
  213.                 $form_data['street_id']['value_string']=$val['value_string']['street_id'];
  214.             }
  215.         }
  216.         $this->template->assign('data', $form_data);
  217.        
  218.         if($hasTlocation){
  219.             $title=$this->get_category_breadcrumbs_string( $params, $category_structure, SITEBILL_MAIN_URL.'/' ).", ".$form_data[$tlocationElement]['tlocation_string'].", ".number_format($form_data['price']['value'],0,',',' ');
  220.         }else{
  221.             $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,',',' ');
  222.         }
  223.          
  224.         if($form_data['meta_title']['value']==''){
  225.             $meta_title=$title;
  226.         }else{
  227.             $meta_title=$form_data['meta_title']['value'];
  228.         }
  229.        
  230.         $this->template->assign('meta_title', $meta_title);
  231.         $this->template->assign('title', $title);
  232.        
  233.         if($form_data['meta_description']['value']!=''){
  234.             $this->template->assign('meta_description', $form_data['meta_description']['value']);
  235.         }
  236.        
  237.         if($form_data['meta_keywords']['value']!=''){
  238.             $this->template->assign('meta_keywords', $form_data['meta_keywords']['value']);
  239.         }
  240.        
  241.        
  242.        
  243.         if(1==$this->getConfigValue('apps.comment.enable')){
  244.             require_once SITEBILL_DOCUMENT_ROOT.'/apps/comment/admin/admin.php';
  245.             require_once SITEBILL_DOCUMENT_ROOT.'/apps/comment/site/site.php';
  246.             $CoM=new comment_site();
  247.             require_once(SITEBILL_DOCUMENT_ROOT.'/apps/system/lib/system/user/login.php');
  248.             $Login = new Login();
  249.             $user_id=(int)$Login->getSessionUserId();
  250.             $commentsPanel=$CoM->generateCommentPanel($user_id, 'data', $realty_id);
  251.         }
  252.        
  253.        
  254.         $gdata=array();
  255.        
  256.        
  257.         $gd=array();
  258.         foreach ($form_data as $key=>$value){
  259.             if($key=='city_id'){
  260.                 $gd['city']=SiteBill::iconv(SITE_ENCODING, 'utf-8', $value['value_string']);
  261.             }elseif($key=='street_id'){
  262.                 $gd['street']=SiteBill::iconv(SITE_ENCODING, 'utf-8', $value['value_string']);
  263.             }elseif($key=='price'){
  264.                 $gd['price']=$value['value'];
  265.             }elseif($key=='topic_id'){
  266.                 $gd['type_sh']=SiteBill::iconv(SITE_ENCODING, 'utf-8', $value['value_string']);
  267.             }else{
  268.                 $gd[$key]=$value['value'];
  269.             }
  270.         }
  271.        
  272.         if(file_exists(SITEBILL_DOCUMENT_ROOT.'/template/frontend/'.$this->getConfigValue('theme').'/configuration/realty_view.php')){
  273.             require SITEBILL_DOCUMENT_ROOT.'/template/frontend/'.$this->getConfigValue('theme').'/configuration/realty_view.php';
  274.             $RVC=Template_Realty_View_Configuration::getConfiguration();
  275.         }else{
  276.             $RVC=array();
  277.         }
  278.         /*
  279.         $data_sets=array();
  280.         if(!empty($RVC) && isset($RVC['data_sets']) && count($RVC['data_sets'])>0){
  281.             foreach($RVC['data_sets'] as $set_name=>$set_fields){
  282.                 if(isset($gd[$set_fields])){
  283.                     $data_sets[$set_name][]=$gd[$set_fields];
  284.                 }
  285.             }
  286.         }
  287.         $this->template->assign('_data_sets', $data_sets);
  288.         */
  289.         /*echo '<pre>';
  290.         print_r($gd);
  291.         echo '</pre>';*/
  292.        
  293.         $gd['title']=SiteBill::iconv(SITE_ENCODING, 'utf-8', $gd['city_id']['value_string'].' '.$gd['street_id']['value_string'].(($gd['number']['value']!='' && $gd['number']['value']!=0) ? ', '.$gd['number']['value'] : '').' ('.number_format($gd['price']['value'], 0, '.', ' ').')');
  294.         if(file_exists(SITEBILL_DOCUMENT_ROOT.'/template/frontend/'.$this->getConfigValue('theme').'/realty_on_map.tpl')){
  295.             global $smarty;
  296.             $smarty->assign('realty', $gd);
  297.             $html=$smarty->fetch(SITEBILL_DOCUMENT_ROOT.'/template/frontend/'.$this->getConfigValue('theme').'/realty_on_map.tpl');
  298.             $html = str_replace("\r\n", ' ', $html);
  299.             $html = str_replace("\n", ' ', $html);
  300.             $html = str_replace("\t", ' ', $html);
  301.             $html = addslashes($html);
  302.         }else{
  303.             $html = '';
  304.         }
  305.         $gd['html']=SiteBill::iconv(SITE_ENCODING, 'utf-8', $html);
  306.         $gd['href']='#';
  307.        
  308.         if(isset($form_data['geo']) && $form_data['geo']['value']['lat']!='' && $form_data['geo']['value']['lng']!=''){
  309.             $gd['geo_lat']=$form_data['geo']['value']['lat'];
  310.             $gd['geo_lng']=$form_data['geo']['value']['lng'];
  311.         }
  312.        
  313.         $gc=$gd['geo_lat'].'_'.$gd['geo_lng'];
  314.        
  315.         $geoobjects_collection[$gc]['html'].=$gd['html'];
  316.         $geoobjects_collection[$gc]['count']++;
  317.         $geoobjects_collection[$gc]['lat']=$gd['geo_lat'];
  318.         $geoobjects_collection[$gc]['lng']=$gd['geo_lng'];
  319.        
  320.        
  321.         //echo '<pre>';
  322.        // print_r($gd);
  323.        // echo '</pre>';
  324.        
  325.         $this->template->assert('geoobjects_collection_clustered', json_encode($geoobjects_collection));
  326.        
  327.        
  328.        
  329.        
  330.         if ( $this->getConfigValue('theme') != 'estate' and !file_exists(SITEBILL_DOCUMENT_ROOT.'/template/frontend/'.$this->getConfigValue('theme').'/realty_view.tpl') ) {
  331.             $this->template->assign('main_file_tpl', '../estate/realty_view.tpl');
  332.         } else {
  333.             $this->template->assign('main_file_tpl', 'realty_view.tpl');
  334.         }
  335.        
  336.         return $result;
  337.     }
  338.    
  339.    
  340. }
  341. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement