DmitriyKim

ContactForms Plugin

May 20th, 2016
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 141.72 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name:DK Contact Forms
  4. Plugin URI: http://dmkim1979.ru
  5. Description: Plugin allows to create contact forms
  6. Version: 1.1
  7. Author: Dmitriy Kim
  8. Author URI: http://dmkim1979.ru
  9.  
  10. License: GPL2
  11.  
  12. Copyright 2013.  Dmitriy Kim  (email : dmkim1979@gmail.com)
  13.  
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License, version 2, as
  16. published by the Free Software Foundation.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software
  25. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  26. */
  27.  
  28. if (!class_exists('DKFactoryZ')) {
  29.    class DKFactoryZ {
  30.       public static function create($className, $DK_DEBUG=false) {
  31.    
  32.          if ($DK_DEBUG==true) {
  33.      
  34.             $DK_DEBUG_FILE = dirname(__FILE__).'/../debugdir/'.strtolower($className).'_debug.html';
  35.      
  36.             require_once dirname(__FILE__).'/../debugdir/debugger.php';
  37.          
  38.             $em = new DKEventManagerZ();
  39.             $logger = new DKFileLoggerZ($DK_DEBUG_FILE);     
  40.             $em->addEventListener('*', $logger, 'write');
  41.          
  42.             dk_ContactForms::$class_proxy = new DKProxyZ($em);
  43.  
  44.          }   
  45.      
  46.          $instance = new $className();
  47.          return $instance;
  48.       }
  49.    }
  50. }
  51.  
  52. $contact_forms = DKFactoryZ::create('dk_ContactForms',false);
  53.  
  54. class dk_ContactForms {
  55.  
  56.    private $plugin_url;
  57.    private $plugin_dir;
  58.    private $options;
  59.    private $dk_menu_suffix;
  60.    static $class_proxy=null;
  61.    private $proxy;
  62.    private $shortcode_found = null;
  63.    private $shortcode_total_found = null;
  64.    private $shortcode_list_found = null;
  65.    private $shortcode_appointment_found = null;
  66.    private $shortcode_otzyv_full_found = null;
  67.    private $shortcode_smi_found = null;
  68.  
  69.    
  70.    private $service_email = 'petrovkasite@petrovkamed.ru';
  71.    private $version = 7;
  72.    
  73.    public function __construct() {
  74.    
  75.       if (isset(self::$class_proxy)) {
  76.          $this->proxy = self::$class_proxy;
  77.          $this->proxy->set_proxy_object($this);
  78.       } else {
  79.          $this->proxy = $this;
  80.       }
  81.            
  82.       $this->options = get_option('dk_contact_forms_options');
  83.       $this->plugin_url = trailingslashit(WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)));
  84.      
  85.       $this->plugin_dir = strtr(WP_PLUGIN_DIR,DIRECTORY_SEPARATOR,'/').'/'.
  86.          dirname(plugin_basename(strtr(__FILE__, DIRECTORY_SEPARATOR,'/'))).'/';
  87.          
  88.       global $gl_plugin_dir;     
  89.       $gl_plugin_dir = $this->plugin_dir;
  90.      
  91.       add_action('activate_dk_contactforms/dk_contactforms.php',array($this->proxy,'install'));
  92.       register_deactivation_hook(__FILE__, array($this->proxy,'uninstall'));
  93.      
  94.       add_action('init',array($this->proxy,'init'));
  95.       add_action('admin_init',array($this->proxy,'admin_init'));
  96.       add_action('admin_menu',array($this->proxy,'register_admin_menu'));
  97.      
  98.       add_action('wp_ajax_process_letter', array($this->proxy,'processLetter'));
  99.       add_action('wp_ajax_nopriv_process_letter',array($this->proxy,'processLetter'));
  100.      
  101.       add_action('wp_ajax_process_appointment', array($this->proxy,'processAppointment'));
  102.       add_action('wp_ajax_nopriv_process_appointment', array($this->proxy,'processAppointment'));
  103.      
  104.       add_action('wp_ajax_process_otzyv', array($this->proxy,'processOtzyv'));
  105.       add_action('wp_ajax_nopriv_process_otzyv', array($this->proxy,'processOtzyv'));
  106.      
  107.       add_action('dk_event_check_mail', array($this->proxy, 'checkAnswers') );
  108.       add_action('dk_event_check_mail', array($this->proxy, 'checkQ'));
  109.      
  110.       add_action('landing_head', array($this->proxy,'print_form_script_and_style'));   
  111.        
  112.       add_action('admin_action_resend_qa_letter', array($this->proxy, 'resendLetter'));
  113.      
  114.       add_shortcode('dk_appointment_form', array($this->proxy,'appointmentform_shortcode'));
  115.          
  116.    }
  117.    
  118.    public function __call($cmd, $args) {
  119.    }  
  120.    
  121.    /*-------------------------------------------
  122.               install plugin
  123.    -------------------------------------------*/
  124.    public function install() {
  125.    
  126.       if (!isset($this->options['version'])) {
  127.          $this->upgrate_to_version_1();
  128.       }
  129.       $version = $this->options['version'];
  130.       if ($version<2) {
  131.          $this->upgrate_to_version_2();
  132.       }
  133.       if ($version<3) {
  134.          $this->upgrate_to_version_3();
  135.       }
  136.       if ($version<5) {
  137.          $this->upgrate_to_version_4();
  138.       }
  139.       if ($version<6) {
  140.          $this->upgrate_to_version_5();
  141.       }
  142.       if ($version<7) {
  143.          $this->upgrate_to_version_6();
  144.       }
  145.      
  146.       $defaults = array('version'=>$this->version);
  147.       add_option('dk_contact_forms_options', $defaults);
  148.       wp_schedule_event(time(),'hourly','dk_event_check_mail');
  149.      
  150.        global $wpdb;      
  151.        $wpdb->show_errors();
  152.        $_db = $wpdb;
  153.        $contact_forms_table = 'dk_contact_forms';          
  154.        $contact_forms_contacts_table = 'dk_contact_forms_contacts';
  155.        
  156.        
  157.        if ($_db->get_var("SHOW TABLES LIKE '". $contact_forms_table ."'") == $contact_forms_table)
  158.           return;
  159.        
  160.        $sqls = array (
  161.      
  162.         "create table {$contact_forms_table} (
  163.             contactform_id int(11) not null auto_increment,
  164.                 contactform_name varchar(50),                              
  165.             primary key(`contactform_id`));",
  166.  
  167.         "create table {$contact_forms_contacts_table} (
  168.            contactform_contact_id int(11) not null auto_increment,
  169.            contactform_id int(11),
  170.            contactform_contact_name varchar(200),
  171.            contactform_contact_email varchar(200),
  172.            primary key (`contactform_contact_id`));"       
  173.         );
  174.                
  175.        while (list($key,$sq)= each($sqls)) {             
  176.           $_db->query($sq);              
  177.           }          
  178.          
  179.        
  180.    }  
  181.    //-----------------------------------------
  182.    private function upgrate_to_version_1() {
  183.    
  184.       global $wpdb;
  185.       $wpdb->show_errors();
  186.      
  187.       $contact_forms_contacts_table = 'dk_contact_forms_contacts';
  188.      
  189.       $sqls = array (
  190.       "alter table {$contact_forms_contacts_table}
  191.       add column contactform_contact_description varchar(2000) after contactform_contact_email,
  192.       add column contactform_contact_picture varchar(300) after contactform_contact_description");
  193.      
  194.       while (list($key,$sq) = each($sqls)) {
  195.          $wpdb->query($sq);
  196.       }
  197.    }
  198.    //-----------------------------------------
  199.    private function upgrate_to_version_2() {
  200.      
  201.       global $wpdb;
  202.       $wpdb->show_errors();
  203.       $contact_forms_table = 'dk_contact_forms';
  204.       $price_list_table = 'dk_price_list';
  205.      
  206.       $sqls = array (
  207.          "alter table {$contact_forms_table}
  208.          add column contactform_1c_id varchar(50) after contactform_name",
  209.          
  210.          "create table {$price_list_table} (
  211.          
  212.             pricelist_id int(11) not null auto_increment,
  213.              
  214.                pricelist_1c_id varchar(50),
  215.                 pricelist_1c_name varchar(2000),               
  216.                
  217.                 pricelist_price float,             
  218.                 pricelist_sort_order int(11) default 0,
  219.                
  220.                 department_1c_id varchar(50),
  221.                 department_1c_name varchar(500),
  222.             primary key(`pricelist_id`));"
  223.          );
  224.      
  225.       while (list($key,$sq) = each($sqls)) {
  226.          $wpdb->query($sq);
  227.       }  
  228.    }
  229.    //-----------------------------------------
  230.    private function upgrate_to_version_3() {      
  231.       global $wpdb;
  232.       $wpdb->show_errors();
  233.       $price_list_table = 'dk_price_list';
  234.       $sqls = array ("alter table {$price_list_table}
  235.       add column sub_id int(11) default 0 after department_1c_name");
  236.      
  237.       while (list($key,$sq) = each($sqls)) {
  238.          $wpdb->query($sq);
  239.       }
  240.    }
  241.    //-----------------------------------------
  242.    private function upgrate_to_version_4() {
  243.       global $wpdb;
  244.       $wpdb->show_errors();
  245.       $contact_forms_contacts_table = 'dk_contact_forms_contacts';
  246.       $sqls = array("alter table $contact_forms_contacts_table ".
  247.       "add column page_id int(11)");
  248.       while (list($key,$sq) = each($sqls)) {
  249.          $wpdb->query($sq);
  250.       }
  251.    }
  252.    //-----------------------------------------  
  253.    private function upgrate_to_version_5() {
  254.       global $wpdb;
  255.       $wpdb->show_errors();
  256.       $contact_forms_contacts_table = 'dk_contact_forms_contacts';
  257.       $sqls = array("alter table $contact_forms_contacts_table ".
  258.       "add column contactform_contact_url varchar(500)");
  259.       while (list($key,$sq) = each($sqls)) {
  260.          $wpdb->query($sq);
  261.       }
  262.    }  
  263.    //-----------------------------------------
  264.    private function upgrate_to_version_6() {
  265.       global $wpdb;
  266.       $wpdb->show_errors();
  267.       $contact_forms_table = 'dk_contact_forms';
  268.       $sql = array ( "alter table $contact_forms_table ".
  269.       " add column contactform_doctor_name varchar(100) ");
  270.       while (list($key,$sq) = each($sqls)) {
  271.          $wpdb->query($sq);
  272.       }
  273.    }
  274.    //-----------------------------------------
  275.    public function uninstall() {
  276.       wp_clear_scheduled_hook('dk_event_check_mail');
  277.    }
  278.    
  279.    /*-----------------------------------------------------
  280.                       init
  281.    -----------------------------------------------------*/
  282.    public function init() {
  283.       add_shortcode('dk_contact_form', array($this->proxy, 'contactform_shortcode'));
  284.       add_shortcode('dk_totalcontact_form', array($this->proxy,'totalcontactform_shortcode'));
  285.       add_shortcode('dk_stub', array($this->proxy,'stub_shortcode'));
  286.       add_shortcode('dk_qa_list', array($this->proxy,'qa_list_shortcode'));
  287.       add_shortcode('dk_eko_contact_form', array($this->proxy,'ekocontactform_shortcode'));
  288.       add_shortcode('dk_landing_contact_form',array($this->proxy,'landingcontactform_shortcode'));
  289.      
  290.      
  291.       add_shortcode('dk_appointment_form_eko1', array($this->proxy,'appointmentform_eko1_shortcode'));
  292.       add_shortcode('dk_appointment_form_eko2', array($this->proxy,'appointmentform_eko2_shortcode'));
  293.      
  294.       add_shortcode('dk_otzyv_full', array($this->proxy,'otzyvfull_shortcode'));
  295.      
  296.       add_shortcode('dk_smi', array($this->proxy,'smi_shortcode'));
  297.       add_shortcode('dk_otzyv_list', array($this->proxy,'otzyv_list_shortcode'));
  298.      
  299.       add_shortcode('dk_pricelist',array($this->proxy,'pricelist_shortcode'));
  300.      
  301.       add_shortcode('dk_doctors', array($this->proxy, 'doctors_shortcode'));
  302.       add_shortcode('dk_doctors_full', array($this->proxy,'doctors_shortcode_full'));
  303.       add_shortcode('dk_doctors_ekolanding', array($this->proxy, 'doctors_shortcode_ekolanding'));
  304.          
  305.       $this->registerCustomPostTypes();
  306.       $this->addQuestionsRole();
  307.      
  308.       if (!is_admin()) {
  309.          add_action('wp_enqueue_scripts',array($this->proxy, 'load_form_script'));
  310.          add_action('wp_print_styles', array($this->proxy, 'load_form_style'));    
  311.          add_action('wp_head', array($this->proxy, 'print_custom_styles'));
  312.          add_action('wp_footer', array($this->proxy, 'print_footer_scripts'));
  313.          
  314.          add_filter('the_content', array($this->proxy,'doctor_content'), 1000);
  315.          
  316.       }
  317.       add_action('admin_head', array($this->proxy,'custom_admin_scripts'));
  318.      
  319.       if (preg_match('/\/getContactForm/i', $_SERVER['REQUEST_URI'])) {
  320.          $this->remote_form_draw();
  321.          exit();
  322.       }
  323.       if (preg_match('/\/getContactTotalForm/i', $_SERVER['REQUEST_URI'])) {
  324.          $this->remote_totalform_draw();
  325.          exit();
  326.       }
  327.      
  328.       if (preg_match('/\/getContactList/i', $_SERVER['REQUEST_URI'])) {
  329.          $this->remote_list_draw();
  330.          exit();
  331.       }
  332.      
  333.       if (preg_match('/\/processLetter/i', $_SERVER['REQUEST_URI'])) {
  334.          $this->remote_form_process();
  335.          exit();
  336.       }
  337.      
  338.       if (preg_match('/\/getOtzyvForm/i', $_SERVER['REQUEST_URI'])) {
  339.          $this->remote_otzyvform_draw();
  340.          exit();
  341.       }
  342.       if (preg_match('/\/getOtzyvList/i', $_SERVER['REQUEST_URI'])) {
  343.          $this->remote_otzyvlist_draw();
  344.          exit();
  345.       }
  346.       if (preg_match('/\/processOtzyv/i', $_SERVER['REQUEST_URI'])) {
  347.          $this->remote_otzyv_process();
  348.          exit();
  349.       }
  350.      
  351.       if (preg_match('/\/getAppointmentForm/i', $_SERVER['REQUEST_URI'])) {
  352.          $this->remote_appointmentform_draw();
  353.          exit();
  354.       }
  355.      
  356.       if (preg_match('/\/processAppointment/i', $_SERVER['REQUEST_URI'])) {
  357.          $this->remote_appointment_process();
  358.          exit();
  359.       }
  360.      
  361.       if (preg_match('/\/getDoctors/i', $_SERVER['REQUEST_URI'])) {
  362.          $this->remote_get_doctors();
  363.          exit();
  364.       }
  365.       if (preg_match('/\/getFullDoctors/i', $_SERVER['REQUEST_URI'])) {
  366.          $this->remote_get_doctors_full();
  367.          exit();
  368.       }
  369.       if (preg_match('/\/waitfordoctor/i', $_SERVER['REQUEST_URI'])) {
  370.          $this->questions_and_answers_single($_GET['post_id']);      
  371.          exit();
  372.       }              
  373.    }
  374.    
  375.    //------------------------------------------------
  376.    public function custom_admin_scripts() {
  377.    
  378.       $screen=get_current_screen();      
  379.       if ($screen->post_type!='dk_review')
  380.          return;  
  381.          
  382.       wp_register_style( 'datepicker-style', get_template_directory_uri().'/landing/css/lugo.datepicker.css', true);
  383.       //wp_enqueue_style('datepicker-style');
  384.      
  385.       ?>
  386.      
  387.       <script type="text/javascript">
  388.         jQuery(document).ready ( function () {
  389.        
  390.          //-------------------------------------------------
  391.          //              date picker
  392.          //-------------------------------------------------       
  393.  
  394.                  jQuery.datepicker.regional['ru'] = {
  395.                     closeText: 'Закрыть',
  396.                     prevText: '&#x3c;Пред',
  397.                     nextText: 'След&#x3e;',
  398.                     currentText: 'Сегодня',
  399.                     monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
  400.                     'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
  401.                     monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
  402.                     'Июл','Авг','Сен','Окт','Ноя','Дек'],
  403.                     dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
  404.                     dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
  405.                     dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
  406.                     dateFormat: 'dd.mm.yy', firstDay: 1,
  407.                     isRTL: false};
  408.                    
  409.                  jQuery.datepicker.setDefaults(jQuery.datepicker.regional['ru']);
  410.                  
  411.                  
  412.  
  413.                  jQuery('.datepicker').datepicker({
  414.                  
  415.                     dateFormat: "yymmdd"                   
  416.                  });
  417.        
  418.        
  419.          });
  420.       </script>
  421.       <style type="text/css">
  422.          .ui-datepicker {
  423.             padding:10px;
  424.             background:#fafafa;
  425.             border:solid 1px #999;
  426.          }
  427.       </style>
  428.      
  429.       <?php
  430.    }
  431.    
  432.    
  433.    
  434.    /*-----------------------------------------------------
  435.                draw form for remote eko
  436.    -----------------------------------------------------*/
  437.    private function remote_form_draw() {
  438.    
  439.       $form = $this->contactform_shortcode(array('id'=>10,'type'=>'eko'));
  440.       echo $form;
  441.    }
  442.    
  443.    //------------------------------------
  444.    private function remote_totalform_draw() {
  445.      
  446.       $form = $this->totalcontactform_shortcode(array('en'=>true));
  447.       echo $form;
  448.    }
  449.    
  450.    /*-----------------------------------------------------
  451.                draw list for remote eko
  452.    -----------------------------------------------------*/
  453.    private function remote_list_draw() {
  454.      
  455.       $form = $this->qa_list_shortcode(array('id'=>10));
  456.       echo $form;
  457.    }
  458.    //------------------------------------------- remote otzyv form
  459.    private function remote_otzyvform_draw() {
  460.      
  461.       $form = $this->otzyvfull_shortcode(array());
  462.       echo $form;
  463.    }
  464.    //------------------------------------------- remote otzyv list
  465.    private function remote_otzyvlist_draw() {
  466.      
  467.       $list = $this->otzyv_list_shortcode(array('id'=>10,'type'=>'eko'));
  468.       echo $list;
  469.    }
  470.    
  471.    /*-----------------------------------------------------
  472.                      remote get doctors
  473.    -----------------------------------------------------*/
  474.    private function remote_get_doctors() {
  475.    
  476.       $list = $this->doctors_shortcode(array('id'=>$_GET['id'],'en'=>true));
  477.       echo $list;
  478.    }
  479.    
  480.    private function remote_get_doctors_full() {
  481.      
  482.       $list = $this->doctors_shortcode_full(array('en'=>true));
  483.       echo $list;
  484.    }
  485.    
  486.    /*-----------------------------------------------------
  487.                  remote form process
  488.    -----------------------------------------------------*/  
  489.    private function remote_form_process() {
  490.       $this->processLetter();
  491.    }
  492.    /*-----------------------------------------------------
  493.                  remote otzyv process
  494.    -----------------------------------------------------*/  
  495.    private function remote_otzyv_process() {
  496.       $this->processOtzyv(true);
  497.    }
  498.    /*-----------------------------------------------------
  499.              remote appointment form draw
  500.    -----------------------------------------------------*/    
  501.    private function remote_appointmentform_draw() {
  502.    
  503.       $type = isset($_GET['type'])?$_GET['type']:'';
  504.       $eng = isset($_GET['eng'])?$_GET['eng']:false;
  505.      
  506.      
  507.       $form = $this->appointmentform_shortcode(array('type'=>$type,'eng'=>$eng));
  508.       echo $form;
  509.    }
  510.    
  511.    //-------------------------------------------- remote appointment process
  512.    private function remote_appointment_process() {
  513.       $this->processAppointment(true);
  514.    }
  515.    
  516.    
  517.    /*-----------------------------------------------------
  518.                 register custom post types
  519.    -----------------------------------------------------*/
  520.    public function registerCustomPostTypes() {
  521.    
  522.       register_post_type('dk_question',
  523.       array(
  524.           'label' => 'Questions',
  525.          'description' => '',
  526.          'public' => true,
  527.          'show_ui' => true,
  528.          'show_in_menu' => true, //---- отображать в админке
  529.          'map_meta_cap' => false,
  530.          'capability_type' => 'question', //----- права доступа к типу записей
  531.  
  532.                  'capabilities' => array(
  533.                                 'publish_posts' => 'publish_questions',
  534.                                 'edit_posts' => 'edit_questions',
  535.                                 'edit_others_posts' => 'edit_others_questions',
  536.                                 'delete_posts' => 'delete_questions',
  537.                                 'delete_others_posts' => 'delete_others_questions',
  538.                                 'read_private_posts' => 'read_private_questions',
  539.                                 'edit_post' => 'edit_question',
  540.                                 'delete_post' => 'delete_question',
  541.                                 'read_post' => 'read_question',
  542.                         ),
  543.  
  544.          'hierarchical' => true, //-------- поддержка древовидной структуры
  545.          'rewrite' => array('slug' => 'question'), //------ поддержка ЧПУ
  546.          'query_var' => true,   //--------- использовать переменную question для запроса конкретной записи
  547.          'has_archive' => false,  //--------- отключаем страницу архива по умолчанию
  548.          'exclude_from_search' => true,
  549.          'supports' => array('title','editor','comments','custom-fields','author','excerpt','page-attributes'),
  550.  
  551.           'taxonomies' => array('category'),//---- использует спец.таксономию (при редактировании)
  552.  
  553.          'labels' => array (
  554.             'name' => 'Questions',
  555.             'singular_name' => 'Question',
  556.             'menu_name' => 'Questions',
  557.             'add_new' => 'Add Question',
  558.             'add_new_item' => 'Add New Question',
  559.             'edit' => 'Edit',
  560.             'edit_item' => 'Edit Question',
  561.             'new_item' => 'New Question',
  562.             'view' => 'View Questions',
  563.             'view_item' => 'View Question',
  564.             'search_items' => 'Search Questions',
  565.             'not_found' => 'No Questions Found',
  566.             'not_found_in_trash' => 'No Questions Found in Trash',
  567.             'parent' => 'Parent Question'
  568.              )
  569.                 )
  570.         );
  571.        
  572.       //--------------------------------------- review
  573.       register_post_type('dk_review',
  574.       array(
  575.           'label' => 'Reviews',
  576.          'description' => '',
  577.          'public' => true,
  578.          'show_ui' => true,
  579.          'show_in_menu' => true, //---- отображать в админке
  580.          'map_meta_cap' => false,
  581.          'capability_type' => 'review', //----- права доступа к типу записей
  582.  
  583.                  'capabilities' => array(
  584.                                 'publish_posts' => 'publish_reviews',
  585.                                 'edit_posts' => 'edit_reviews',
  586.                                 'edit_others_posts' => 'edit_others_reviews',
  587.                                 'delete_posts' => 'delete_reviews',
  588.                                 'delete_others_posts' => 'delete_others_reviews',
  589.                                 'read_private_posts' => 'read_private_reviews',
  590.                                 'edit_post' => 'edit_review',
  591.                                 'delete_post' => 'delete_review',
  592.                                 'read_post' => 'read_review',
  593.                         ),
  594.  
  595.          'hierarchical' => true, //-------- поддержка древовидной структуры
  596.          'rewrite' => array('slug' => 'review'), //------ поддержка ЧПУ
  597.          'query_var' => true,   //--------- использовать переменную question для запроса конкретной записи
  598.          'has_archive' => false,  //--------- отключаем страницу архива по умолчанию
  599.          'exclude_from_search' => true,
  600.          'supports' => array('title','editor','comments','custom-fields','author','excerpt','page-attributes'),
  601.  
  602.           'taxonomies' => array('category'),//---- использует спец.таксономию (при редактировании)
  603.  
  604.          'labels' => array (
  605.             'name' => 'Reviews',
  606.             'singular_name' => 'Review',
  607.             'menu_name' => 'Reviews',
  608.             'add_new' => 'Add Review',
  609.             'add_new_item' => 'Add New Review',
  610.             'edit' => 'Edit',
  611.             'edit_item' => 'Edit Review',
  612.             'new_item' => 'New Review',
  613.             'view' => 'View Reviews',
  614.             'view_item' => 'View Review',
  615.             'search_items' => 'Search Reviews',
  616.             'not_found' => 'No Reviews Found',
  617.             'not_found_in_trash' => 'No Reviews Found in Trash',
  618.             'parent' => 'Parent Review'
  619.              )
  620.                 )
  621.         );
  622.        
  623.       //----------------------------------------------------------- smi
  624.       register_post_type('dk_publication',
  625.       array(
  626.           'label' => 'Publications',
  627.          'description' => '',
  628.          'public' => true,
  629.          'show_ui' => true,
  630.          'show_in_menu' => true, //---- отображать в админке
  631.          'map_meta_cap' => false,
  632.          'capability_type' => 'publication', //----- права доступа к типу записей
  633.  
  634.                  'capabilities' => array(
  635.                                 'publish_posts' => 'publish_publications',
  636.                                 'edit_posts' => 'edit_publications',
  637.                                 'edit_others_posts' => 'edit_others_publications',
  638.                                 'delete_posts' => 'delete_publications',
  639.                                 'delete_others_posts' => 'delete_others_publications',
  640.                                 'read_private_posts' => 'read_private_publications',
  641.                                 'edit_post' => 'edit_publication',
  642.                                 'delete_post' => 'delete_publication',
  643.                                 'read_post' => 'read_publication',
  644.                         ),
  645.  
  646.          'hierarchical' => true, //-------- поддержка древовидной структуры
  647.          'rewrite' => array('slug' => 'publication'), //------ поддержка ЧПУ
  648.          'query_var' => true,   //--------- использовать переменную question для запроса конкретной записи
  649.          'has_archive' => false,  //--------- отключаем страницу архива по умолчанию
  650.          'exclude_from_search' => true,
  651.          'supports' => array('title','editor','comments','custom-fields','author','excerpt','page-attributes','thumbnail'),
  652.  
  653.           'taxonomies' => array('category'),//---- использует спец.таксономию (при редактировании)
  654.  
  655.          'labels' => array (
  656.             'name' => 'Publications',
  657.             'singular_name' => 'Publications',
  658.             'menu_name' => 'Publications',
  659.             'add_new' => 'Add Publication',
  660.             'add_new_item' => 'Add New Publication',
  661.             'edit' => 'Edit',
  662.             'edit_item' => 'Edit Publication',
  663.             'new_item' => 'New Publication',
  664.             'view' => 'View Publications',
  665.             'view_item' => 'View Publication',
  666.             'search_items' => 'Search Publications',
  667.             'not_found' => 'No Publications Found',
  668.             'not_found_in_trash' => 'No Publications Found in Trash',
  669.             'parent' => 'Parent Publication'
  670.              )
  671.                 )
  672.         );
  673.      
  674.      
  675.    }
  676.    /*-----------------------------------------------------
  677.                add questions role
  678.    -----------------------------------------------------*/  
  679.    public function addQuestionsRole() {
  680.      
  681.       $result = add_role('question_author','Question Author',
  682.       array(
  683.          'read'=>true,
  684.          'publish_questions'=>true,
  685.          'edit_questions'=>true,
  686.          'edit_question'=>true,
  687.          'read_question'=>true
  688.       ));
  689.      
  690.        $role = get_role( 'administrator' );
  691.  
  692.      $role->add_cap('publish_questions');
  693.      $role->add_cap( 'edit_questions');
  694.      $role->add_cap('edit_others_questions');
  695.      $role->add_cap('delete_questions');
  696.      $role->add_cap('delete_others_questions');
  697.      $role->add_cap('read_private_questions');
  698.      $role->add_cap('edit_question');
  699.      $role->add_cap('delete_question');
  700.      $role->add_cap('read_question');
  701.      
  702.      $role->add_cap('publish_reviews');
  703.      $role->add_cap('edit_reviews');
  704.      $role->add_cap('edit_others_reviews');
  705.      $role->add_cap('delete_reviews');
  706.      $role->add_cap('delete_others_reviews');
  707.      $role->add_cap('read_private_reviews');
  708.      $role->add_cap('edit_review');
  709.      $role->add_cap('delete_review');
  710.      $role->add_cap('read_review');
  711.      
  712.      $role->add_cap('publish_publications');
  713.      $role->add_cap('edit_publications');
  714.      $role->add_cap('edit_others_publications');
  715.      $role->add_cap('delete_publications');
  716.      $role->add_cap('delete_others_publications');
  717.      $role->add_cap('read_private_publications');
  718.      $role->add_cap('edit_publication');
  719.      $role->add_cap('delete_publication');
  720.      $role->add_cap('read_publication');
  721.    }
  722.    
  723.    /*-----------------------------------------------------------
  724.                          admin init
  725.    -----------------------------------------------------------*/
  726.    public function admin_init() {
  727.    
  728.       add_filter('pre_get_posts', array($this->proxy,'review_default_sort'));
  729.    
  730.       add_filter('manage_edit-dk_question_columns',array($this->proxy,'question_columns'));
  731.       add_filter('manage_edit-dk_question_sortable_columns',array($this->proxy,'question_sortable_columns'));            
  732.       add_action('manage_dk_question_posts_custom_column',array($this->proxy,'fill_question_columns'));
  733.      
  734.       add_action('restrict_manage_posts',array($this->proxy, 'set_question_filters'));   
  735.       add_filter('pre_get_posts', array($this->proxy, 'handle_question_sorts'));
  736.       add_filter('posts_where', array($this->proxy, 'handle_question_filters'));
  737.      
  738.       //------------------------------
  739.       add_filter('manage_edit-dk_review_columns', array($this->proxy,'review_columns'));
  740.       add_filter('manage_edit-dk_review_sortable_columns',array($this->proxy,'review_sortable_columns'));    
  741.       add_action('manage_dk_review_posts_custom_column', array($this->proxy,'fill_review_columns'));
  742.      
  743.       add_action('restrict_manage_posts', array($this->proxy,'set_review_filters'));
  744.       add_filter('pre_get_posts',array($this->proxy,'handle_review_sorts'));
  745.       add_filter('posts_where', array($this->proxy, 'handle_review_filters'));
  746.      
  747.       //-------------------------------
  748.       add_action('add_meta_boxes', array($this->proxy, 'add_review_meta_boxes'));
  749.       add_action('save_post', array($this->proxy,'save_review_meta'));
  750.       add_action('post_edit_form_tag', array($this->proxy,'post_edit_form_tag'));
  751.    }
  752.    
  753.    
  754.    /*---------------------------------------------------------
  755.                     review default sort
  756.    ---------------------------------------------------------*/  
  757.    public function review_default_sort($wp_query) {
  758.    
  759.       global $typenow;
  760.      
  761.       if ($typenow!='dk_review') {
  762.          return;
  763.       }
  764.      
  765.       $wp_query->set('orderby','review_date_sort');
  766.       $wp_query->set('order','DESC');
  767.      
  768.    }
  769.    
  770.    /*---------------------------------------------------------
  771.                         question columns
  772.    ---------------------------------------------------------*/
  773.    public function question_columns($columns) {
  774.    
  775.      $next_arr = array(
  776.        'resend_letter' => 'Переслать письмо',
  777.        'sender_email' => 'Адрес пациента',
  778.        'form_name' => 'Отделение',
  779.        'contact_name' => 'Врач'
  780.      );
  781.      unset ($columns['author']);
  782.      unset ($columns['categories']);
  783.      unset ($columns['comments']);
  784.    
  785.      return $columns + $next_arr;
  786.    }
  787.    //-------------------------------------------
  788.    public function question_sortable_columns($sortable_columns) {
  789.       $new_columns = array(
  790.          'form_name' => 'form_name_sort'
  791.       );
  792.      
  793.       return $sortable_columns + $new_columns;
  794.    }
  795.    /*---------------------------------------------------------
  796.                        fill question columns
  797.    ---------------------------------------------------------*/  
  798.    public function fill_question_columns($column_name, $post_id=0) {
  799.    
  800.       global $post;
  801.      
  802.       switch ($column_name) {
  803.          case 'sender_email': $s = get_post_meta($post->ID, 'sender_email', true); echo $s;break;
  804.          case 'form_name': $s = get_post_meta($post->ID, 'form_name',true);echo $s;break;
  805.          case 'contact_name': $s=get_post_meta($post->ID, 'contact_name',true);echo $s;break;
  806.          case 'resend_letter':
  807.             $action_name = 'resend_qa_letter';
  808.             $action = '?action='.$action_name.'&post='.$post->ID;
  809.             echo '<a href="'.admin_url('admin.php'.$action).'">send</a>';
  810.            
  811.          break;
  812.       }
  813.    }  
  814.    
  815.    /*---------------------------------------------------------
  816.                         review columns
  817.    ---------------------------------------------------------*/
  818.    public function review_columns($columns) {
  819.    
  820.       $new_columns = array(
  821.          'contact_id' => 'Врач',
  822.          'review_date' => 'Дата отзыва'
  823.       );           
  824.       unset($columns['author']);
  825.       unset($columns['categories']);
  826.       unset($columns['comments']);
  827.      
  828.       return $columns + $new_columns;
  829.      
  830.    }
  831.    //-------------------
  832.    public function review_sortable_columns($sortable_columns) {
  833.       $new_columns = array(
  834.          'contact_id' => 'contact_id_sort',
  835.          'review_date' => 'review_date_sort'
  836.       );
  837.       return $sortable_columns + $new_columns;
  838.    }
  839.    
  840.    /*---------------------------------------------------------
  841.                         fill review columns
  842.    ---------------------------------------------------------*/
  843.    public function fill_review_columns($column_name, $post_id=0) {
  844.      
  845.       global $post;
  846.      
  847.       switch ($column_name) {
  848.          case 'contact_id':
  849.             $contact_id = get_post_meta($post->ID,'contact_id',true);
  850.             if (!$contact_id || $contact_id<0)
  851.                break;
  852.                            
  853.             define ('DS',DIRECTORY_SEPARATOR);
  854.             define('DEBUG', false);
  855.             require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';    
  856.          
  857.             $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  858.             $sm->init();     
  859.             $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  860.                      
  861.             $contact = $contacts_model->getSingle($contact_id);
  862.            
  863.             $contact = $contact['item'];
  864.             if (!$contact) {
  865.                echo 'врач удален ('.$contact_id.')';
  866.             } else {
  867.                echo $contact['contactform_contact_name'];
  868.             }
  869.             break;
  870.            
  871.          case 'review_date': $s = get_post_meta($post->ID,'review_date',true);
  872.          echo substr($s,6,2).'.'.substr($s,4,2).'.'.substr($s,0,4);
  873.          break;
  874.          
  875.       }
  876.    }
  877.    
  878.    
  879.    /*---------------------------------------------------------
  880.                       set question filters
  881.    ---------------------------------------------------------*/  
  882.    public function set_question_filters() {
  883.      
  884.       global $typenow;
  885.      
  886.       if ($typenow!='dk_question') {
  887.          return;
  888.       }
  889.      
  890.       $params =  array (
  891.          'post_type'=>'dk_question',
  892.          'status'=>array('publish','draft'),
  893.          'meta_key'=>'form_id','posts_per_page'=>1000);
  894.      
  895.       $posts = get_posts($params);
  896.      
  897.       $sender_emails = array();
  898.       $form_names = array();
  899.       $contact_names = array();
  900.       foreach ($posts as $post) {
  901.          
  902.          
  903.          $id= $post->ID;
  904.          $sender_email = get_post_meta($id,'sender_email',true);
  905.          $form_name = get_post_meta($id,'form_name',true);
  906.          $contact_name = get_post_meta($id, 'contact_name',true);
  907.          
  908.          $sender_emails[] = $sender_email;
  909.          $form_names[] = $form_name;
  910.          $contact_names[] = $contact_name;       
  911.       }
  912.       $sender_emails = array_unique($sender_emails);
  913.       $form_names = array_unique($form_names);
  914.       $contact_names = array_unique($contact_names);
  915.      
  916.      
  917.       echo '<select name="sender_filter" class="postform">';
  918.       echo '<option value="0">Все отправители</option>';
  919.       foreach ($sender_emails as $sender_email) {
  920.          echo '<option value="'.$sender_email.'">'.$sender_email.'</option>';
  921.       }
  922.       echo '</select>';  
  923.       echo '<select name="form_filter" class="postform">';
  924.       echo '<option value="0">Все отделения</option>';
  925.       foreach ($form_names as $form_name) {
  926.          echo '<option value="'.$form_name.'">'.$form_name.'</option>';
  927.       }
  928.       echo '</select>';  
  929.       echo '<select name="contact_filter" class="postform">';
  930.       echo '<option value="0">Все врачи</option>';
  931.       foreach ($contact_names as $contact_name) {
  932.           echo '<option value="'.$contact_name.'">'.$contact_name.'</option>';
  933.       }
  934.       echo '</select>';  
  935.    }
  936.    
  937.    /*---------------------------------------------------------
  938.                       set review filters
  939.    ---------------------------------------------------------*/
  940.    public function set_review_filters() {
  941.    
  942.       global $typenow;   
  943.       if ($typenow!='dk_review')
  944.          return;
  945.          
  946.       define ('DS',DIRECTORY_SEPARATOR);
  947.       define('DEBUG', false);
  948.       require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';    
  949.       $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  950.       $sm->init();   
  951.       $contacts_model = $sm->getModel('CContactsModel','ccontacts');         
  952.          
  953.       $params = array('post_type'=>'dk_review',
  954.       'status' => array ('publish','draft'),     
  955.       'posts_per_page'=>1000);  
  956.      
  957.       $posts = get_posts($params);
  958.      
  959.       $contact_array = array();
  960.          
  961.       foreach ($posts as $post) {
  962.      
  963.          $contact_id = get_post_meta($post->ID,'contact_id',true);
  964.          if (!$contact_id || $contact_id<0) {
  965.             continue;
  966.          } 
  967.          if (array_key_exists($contact_id,$contact_array)) {
  968.             continue;
  969.          }
  970.                    
  971.          $contact = $contacts_model->getSingle($contact_id);         
  972.          $contact = $contact['item'];
  973.          
  974.          if (!$contact) {
  975.              $contact_name = 'врач удален ('.$contact_id.')';
  976.             } else {
  977.              $contact_name = $contact['contactform_contact_name'];
  978.          }
  979.          $contact_array[$contact_id] = $contact_name;
  980.       }  
  981.       asort($contact_array);
  982.       echo '<select name="contact_review_filter" class="postform">';
  983.       echo '<option value="0">Все врачи</option>';
  984.       foreach ($contact_array as $key=>$value) {
  985.          echo '<option value='.$key.'>'.$value.'</option>';
  986.       }
  987.       echo '</select>';                          
  988.    }
  989.    
  990.    /*---------------------------------------------------------
  991.                       handle question filters
  992.    ---------------------------------------------------------*/  
  993.    public function handle_question_filters($where) {
  994.      
  995.       if (is_admin()) {
  996.          global $wpdb;
  997.          
  998.          if ((isset($_GET['sender_filter'])) && ($_GET['sender_filter']!="0")) {
  999.             $where .= " and ID in (select post_id from {$wpdb->postmeta} where meta_key='sender_email' and  meta_value='{$_GET['sender_filter']}')";
  1000.          }
  1001.          
  1002.          if ((isset($_GET['form_filter'])) && ($_GET['form_filter']!="0")) {
  1003.             $where .= " and ID in (select post_id from {$wpdb->postmeta} where meta_key='form_name' and  meta_value='{$_GET['form_filter']}')";
  1004.            
  1005.          }
  1006.          
  1007.          if ((isset($_GET['contact_filter'])) && ($_GET['contact_filter']!="0")) {
  1008.             $where .= " and ID in (select post_id from {$wpdb->postmeta} where meta_key='contact_name' and  meta_value='{$_GET['contact_filter']}')";
  1009.          }       
  1010.       }
  1011.          
  1012.       return $where;
  1013.    }
  1014.    
  1015.    /*---------------------------------------------------------
  1016.                       handle review filters
  1017.    ---------------------------------------------------------*/    
  1018.    public function handle_review_filters($where) {
  1019.    
  1020.       if (is_admin()) {
  1021.          global $wpdb;
  1022.          
  1023.          if (isset($_GET['contact_review_filter']) && ($_GET['contact_review_filter']!="0")) {
  1024.             $where .= " and ID in (select post_id from {$wpdb->postmeta} where meta_key='contact_id' and meta_value='{$_GET['contact_review_filter']}')";
  1025.          }
  1026.       }
  1027.       return $where;
  1028.    }
  1029.    
  1030.    
  1031.    
  1032.    /*---------------------------------------------------------
  1033.                       handle question sorts
  1034.    ---------------------------------------------------------*/    
  1035.    public function handle_question_sorts($wp_query) {
  1036.    
  1037.       if ($wp_query->get('orderby')=='form_name_sort') {
  1038.          $wp_query->set('meta_key','form_name');
  1039.          $wp_query->set('orderby','meta_value_num');
  1040.       }  
  1041.    }
  1042.    
  1043.    /*---------------------------------------------------------
  1044.                       handle review sorts
  1045.    ---------------------------------------------------------*/    
  1046.    public function handle_review_sorts($wp_query) {
  1047.      
  1048.       if ($wp_query->get('orderby')=='contact_id_sort') {
  1049.          $wp_query->set('meta_key','contact_id');
  1050.          $wp_query->set('orderby','meta_value_num');
  1051.       }
  1052.       if ($wp_query->get('orderby')=='review_date_sort') {
  1053.          $wp_query->set('meta_key','review_date');
  1054.          $wp_query->set('orderby','meta_value_num');
  1055.       }
  1056.    }
  1057.    
  1058.    
  1059.    /*---------------------------------------------------------
  1060.                        register admin menu
  1061.    ---------------------------------------------------------*/
  1062.    public function register_admin_menu() {
  1063.    
  1064.       $this->dk_menu_suffix = add_menu_page('Departments','Departments',
  1065.       'activate_plugins','dk_contact_forms', array($this->proxy,'contact_forms_menu'));
  1066.      
  1067.       $this->dk_menu_suffix2 = add_submenu_page('dk_contact_forms', 'Doctors','Doctors',
  1068.       'activate_plugins','dk_doctors_menu', array($this->proxy,'doctors_menu'));
  1069.      
  1070.       add_submenu_page('dk_contact_forms','Price List','Price List', 'activate_plugins', 'dk_price_list', array($this->proxy, 'price_list_menu'));
  1071.       $dk_menu_suffix3 = add_submenu_page('dk_contact_forms','DK Questions', 'DK Questions', 'activate_plugins', 'dk_questions_and_answers',
  1072.          array($this->proxy,'questions_and_answers'));
  1073.       add_submenu_page('dk_contact_forms', 'Utils', 'Utils', 'activate_plugins', 'dk_utils_page', array($this->proxy,'utils_page_menu'));
  1074.      
  1075.       add_action('admin_print_styles-'.$this->dk_menu_suffix, array($this->proxy,'load_admin_styles'));
  1076.       add_action('admin_print_styles-'.$this->dk_menu_suffix2, array($this->proxy,'load_admin_styles'));
  1077.       add_action('admin_print_styles-'.$dk_menu_suffix3, array($this->proxy,'load_admin_styles'));
  1078.      
  1079.       add_action('load-'.$this->dk_menu_suffix, array($this->proxy,'onload_menu_page'));
  1080.    }
  1081.    public function load_admin_styles() {
  1082.       wp_register_style('admin_style', $this->plugin_url.'assets/adminstyle.css');
  1083.       wp_enqueue_style('admin_style');      
  1084.    }
  1085.    public function onload_menu_page() {
  1086.       add_action('admin_enqueue_scripts',array($this->proxy,'load_admin_scripts'));
  1087.    }
  1088.    public function load_admin_scripts() {
  1089.       wp_enqueue_script('admin_script',$this->plugin_url.'assets/adminscript.js', array('jquery'));
  1090.    }
  1091.    
  1092.    
  1093.    //---------------------------------------------------------
  1094.    //           contacts forms menu
  1095.    //---------------------------------------------------------
  1096.    public function contact_forms_menu() {
  1097.       echo '<h3>Contact forms menu</h3>';
  1098.       require_once $this->plugin_dir.'simplemvc/bootstrap.php';  
  1099.    }
  1100.    
  1101.    //-------------------------------------------- doctors menu
  1102.    public function doctors_menu() {
  1103.       echo '<h3>Doctors menu</h3>';
  1104.      
  1105.       if (!isset($_GET['ccontacts_action']))
  1106.          $_GET['ccontacts_action'] = 'index';
  1107.          
  1108.       require_once $this->plugin_dir.'simplemvc/bootstrap.php';      
  1109.      
  1110.    }
  1111.    
  1112.    //-------------------------------------------- price list menu
  1113.    public function price_list_menu() {
  1114.       echo '<h3>Price list menu</h3>';
  1115.      
  1116.       if (!isset($_GET['pricelist_action']))
  1117.          $_GET['pricelist_action'] = 'index';
  1118.          
  1119.        require_once $this->plugin_dir.'simplemvc/bootstrap.php';   
  1120.    }
  1121.    
  1122.    //---------------------------------------------------------
  1123.    //           questions and answers menu
  1124.    //---------------------------------------------------------
  1125.    public function questions_and_answers() {
  1126.    
  1127.       if (isset($_POST['post_id'])) {
  1128.          $this->questions_and_answers_publish($_POST['post_id']);
  1129.          $this->questions_and_answers_list();        
  1130.       } else {
  1131.          if (isset($_GET['post_id'])) {
  1132.             $this->questions_and_answers_single($_GET['post_id']);
  1133.          } else {
  1134.             $this->questions_and_answers_list();
  1135.          }
  1136.       }
  1137.    }
  1138.    //---------------------------------------------------------
  1139.    //          questions and answers publish
  1140.    //---------------------------------------------------------  
  1141.    private function questions_and_answers_publish($post_id) {
  1142.    
  1143.       $question_id = $_POST['post_id'];
  1144.       $answer_id = $_POST['answer_id'];
  1145.      
  1146.       //-----------------------------
  1147.       if (isset($_POST['submit'])) {
  1148.      
  1149.          $question_title = $_POST['question_title'];
  1150.          $question_content = $_POST['post_content'];
  1151.          $answer_title = $_POST['answer_title'];
  1152.          $answer_content = $_POST['post_content_answer'];
  1153.          
  1154.          wp_update_post( array(
  1155.             'ID'=>$question_id,
  1156.             'post_title'=>$question_title,
  1157.             'post_content'=>$question_content,
  1158.             'post_status'=>'publish'
  1159.          ));
  1160.          
  1161.          if ($answer_id) {
  1162.             wp_update_post( array(
  1163.                'ID'=>$answer_id,
  1164.                'post_title'=>$answer_title,
  1165.                'post_content'=>$answer_content,
  1166.                'post_status'=>'publish'
  1167.             ));
  1168.          }       
  1169.          return;
  1170.       }
  1171.      
  1172.       //-----------------------------
  1173.       if (isset($_POST['archive'])) {
  1174.      
  1175.          $check = wp_set_post_categories($question_id, array(93));       
  1176.          if ($answer_id) {
  1177.             wp_set_post_categories($answer_id, array(93));
  1178.          }
  1179.          return;
  1180.       }
  1181.       //-----------------------------
  1182.       if (isset($_POST['patientwarning'])) {
  1183.      
  1184.          $daystowait = $_POST['daystowait'];
  1185.          $question_content = $_POST['post_content'];
  1186.          $message ='К сожалению, в настоящий момент доктор не может ответить на ваш вопрос.
  1187.          Вы сможете получить ответ через '.$daystowait.' дней или Вы можете задать вопрос другому специалисту.<br/>'.
  1188.          '<a href="'.'http://petrovkamed.ru/waitfordoctor?post_id='.$question_id.'&doctorwarning=1">Ждать ответа</a><br/>'.
  1189.          '<a href="http://petrovkamed.ru/zadat-vopros-spetsialistu/">Задать вопрос другому специалисту</a><br/>'.
  1190.          str_repeat('-',50).'<br/>'.$question_content;
  1191.          
  1192.          $subject = 'Оповещение с сайта МЦ Петровские Ворота';
  1193.          $sender_email = $this->service_email;
  1194.          
  1195.          $recipient_email = get_post_meta($question_id, 'sender_email', true);       
  1196.          $mail = $this->sendLetter($recipient_email, $sender_email, $message, $subject);     
  1197.          
  1198.          return;
  1199.       }
  1200.    }
  1201.    
  1202.    //---------------------------------------------------------
  1203.    //        questions and answers single
  1204.    //---------------------------------------------------------
  1205.    private function questions_and_answers_single($post_id) {
  1206.              
  1207.       if (isset($_GET['doctorwarning'])) {
  1208.          $this->resendLetter($post_id,
  1209.          'Пользователь ожидает от Вас ответ на вопрос. Внимание! Ответить на вопрос пользователя в необходимо в первый рабочий день!');
  1210.          
  1211.          echo 'Оповещение врачу выслано. Ждите ответа в ближайшее время';
  1212.          return;
  1213.       }
  1214.    
  1215.       $title = get_the_title($post_id);
  1216.       $post_object = get_post($post_id);
  1217.       $post_content = $post_object->post_content;
  1218.  
  1219.      
  1220.       $answers = get_posts(array('post_type'=>'dk_question','post_parent'=>$post_id,
  1221.       'posts_per_page'=>1000, 'post_status'=>array('draft','publish')));
  1222.       foreach ($answers as $answer) {
  1223.          setup_postdata($answer);
  1224.          $answer_id = $answer->ID;
  1225.          $title_answer = get_the_title($answer->ID);
  1226.          $post_content_answer = get_the_content();
  1227.       }
  1228.      
  1229.       $quicktags_settings = array('buttons'=>'b,i,ul,ol,li,link,close');
  1230.       $tinymce_settings = array(
  1231.       'theme_advanced_buttons1' => 'link,|,bold,italic,underline,strikethrough,separator,blockquote,separator,bullist,numlist');
  1232.  
  1233.       $settings = array(
  1234.       'media_buttons'=>false,
  1235.       'textarea_name'=>'post_content',
  1236.       'quicktags'=>$quicktags_settings,
  1237.       'tinymce'=>$tinymce_settings,
  1238.       'textarea_rows'=>15
  1239.       );
  1240.      
  1241.      
  1242.      
  1243.    if (isset($_GET['rerequest'])):  
  1244.    
  1245.          $action_name = 'resend_qa_letter';
  1246.          $action = '?action='.$action_name.'&post='.$post_id;
  1247.          $send_link = '<a href="'.admin_url('admin.php'.$action).'">Оповестить врача</a>';
  1248.    ?>
  1249.    
  1250.    <form method="post" enctype="application/x-www-form-urlencoded">
  1251.       <h3>Вопрос остался без ответа</h3>
  1252.       <input type="text" size="100" name="question_title" value="<?php echo $title; ?>" /><br/>
  1253.       <textarea name="post_content" rows="30" cols="100" ><?php
  1254.       echo $post_content;
  1255. ?></textarea><br/>
  1256.       <p>Пациенту подождать <input type="text" name="daystowait" value="3" /> дней</p>
  1257.       <input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
  1258.       <?php echo $send_link; ?>
  1259.       <input type="submit" name="patientwarning" value="Оповестить пациента" />
  1260.    </form>
  1261.    
  1262.    <?php     
  1263.    else:
  1264.    ?>
  1265.    
  1266.    <form method="post" enctype="application/x-www-form-urlencoded">
  1267.    <h3>Вопрос</h3>  
  1268.    <input type="text" size="100" name="question_title" value="<?php echo $title; ?>" />
  1269.    <?php wp_editor($post_content, 'post_content', $settings); ?>
  1270.    <h3>Ответ</h3>
  1271.    <input type="text" size="100" name="answer_title" value="<?php echo $title_answer; ?>" />
  1272.    <?php
  1273.       $settings['textarea_name'] = 'post_content_answer';
  1274.       wp_editor($post_content_answer,'post_content_answer', $settings); ?>
  1275.    
  1276.    
  1277.    <input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
  1278.    <input type="hidden" name="answer_id" value="<?php echo $answer_id; ?>" />
  1279.    <input type="submit" name="submit" value="опубликовать" />
  1280.    <input type="submit" name="archive" value="в архив" />
  1281.    </form>
  1282.    
  1283.    <?php
  1284.    endif;
  1285.    }
  1286.    
  1287.    //---------------------------------------------------------
  1288.    //       questions and answers list  
  1289.    //---------------------------------------------------------
  1290.    public function questions_and_answers_list() {
  1291.    
  1292.       $args = array('post_type'=>'dk_question', 'posts_per_page'=>1000,
  1293.       'orderby'=>'date','order'=>'DESC','post_parent'=>0, 'post_status'=>array('draft','publish'));
  1294.          
  1295.       $q = new WP_Query($args);
  1296.       echo '<div class="dkqa_container">';
  1297.       while ($q->have_posts()) {
  1298.          $q->the_post();
  1299.          
  1300.          $post_cats = wp_get_post_categories(get_the_id());
  1301.          $post_deleted = in_array(93,$post_cats) ? 'deleted' : '';
  1302.          
  1303.          $action_name = 'resend_qa_letter';
  1304.          $action = '?action='.$action_name.'&post='.get_the_id();
  1305.          $send_link = '<a href="'.admin_url('admin.php'.$action).'">send</a>';
  1306.          
  1307.          $post_status = get_post_status();     
  1308.          echo '<div class="dkqa_question '.$post_status.' '.$post_deleted.'">';
  1309.          echo '<div class="dkqa_date">'.get_the_date('d.m.Y',get_the_id()).'</div>'.
  1310.           '<div class="dkqa_form_name">'.get_post_meta(get_the_id(),'form_name',true).'</div>'.
  1311.          '<div class="dkqa_contact_name">'.get_post_meta(get_the_id(),'contact_name',true).' '.$send_link.'</div>'.
  1312.          '<div class="dkqa_title"><a href="'.admin_url('admin.php?page=dk_questions_and_answers&post_id='.get_the_id().'').
  1313.          '">'.get_the_title().'</a></div><div class="dkqa_excerpt">'.get_the_excerpt().'</div>'.         
  1314.          '<div class="dkqa_sender_email">'.get_post_meta(get_the_id(),'sender_email',true).'</div>';       
  1315.          echo '</div>';
  1316.          
  1317.          $posts = get_posts(array('post_type'=>'dk_question','post_parent'=>get_the_id(),
  1318.          'posts_per_page'=>1000, 'post_status'=>array('draft','publish')));
  1319.          foreach ($posts as $post) {
  1320.          
  1321.             setup_postdata($post);
  1322.            
  1323.             $post_cats = wp_get_post_categories($post->ID);
  1324.             $post_deleted = in_array(93,$post_cats) ? 'deleted' : '';
  1325.            
  1326.             echo '<div class="dkqa_answer '.$post->post_status.'">';
  1327.             echo '<div class="dkqa_adate">'.date('d.m.Y',strtotime($post->post_date)).'</div>';
  1328.             echo '<div class="dkqa_aexcerpt"><a href="'.admin_url('post.php?post='.$post->ID.'&action=edit').
  1329.             '">'.get_the_excerpt().'</a></div>';
  1330.             echo '</div>';
  1331.             wp_reset_postdata();
  1332.          }
  1333.          
  1334.       }
  1335.       echo '</div>';
  1336.    }
  1337.    
  1338.    //---------------------------------------------------------
  1339.    //                  utils menu
  1340.    //---------------------------------------------------------
  1341.    public function utils_page_menu() {
  1342.      
  1343.       echo '<h3>Utils</h3>';
  1344.      
  1345.       if (isset($_POST['check_answers'])) {
  1346.          check_admin_referer('admin_csrf_prevention');
  1347.          $this->checkAnswers();
  1348.       }
  1349.      
  1350.       ?>
  1351.      
  1352.       <form action="<?php echo admin_url('admin.php?page=dk_utils_page'); ?>" method="post"
  1353.       enctype="application/x-www-form-urlencoded">
  1354.       <p>Запустить проверку и публикацию ответов врачей
  1355.      
  1356.          <?php wp_nonce_field('admin_csrf_prevention'); ?>
  1357.          <input type="submit" name="check_answers" value="OK" />
  1358.       </p>
  1359.       </form>    
  1360.      
  1361.       <?php
  1362.    }
  1363.    
  1364.    //-------------------------------------------------------------
  1365.    //                   ajax process letter
  1366.    //-------------------------------------------------------------
  1367.    public function processLetter() {
  1368.      
  1369.       /*if (!check_ajax_referer('security','ajax_process_letter_referer',false)) {
  1370.           _e('Failed to verify ajax referer');
  1371.           exit();
  1372.       }  */
  1373.  
  1374.       $sender_name = $_POST['sender_name'];      
  1375.       $sender_email = $_POST['sender_email'];
  1376.       $question = $_POST['question'];
  1377.       $pub_consent = $_POST['sogl'];
  1378.       $eng = isset($_POST['eng']);
  1379.      
  1380.      
  1381.       $recipient_email = $_POST['recipient_email'];
  1382.      
  1383.       $error = '';
  1384.       if (!$sender_name) {
  1385.          $error .= $eng?'Input your name<br/>':'Введите Ваше имя<br/>';
  1386.       }
  1387.       if (!$sender_email) {
  1388.          $error .= $eng?'Input your e-mail<br/>':'Введите адрес электронной почты<br/>';
  1389.       } else
  1390.          if (!preg_match('/.+@.+/ims', $sender_email)) {
  1391.             $error .= $eng?'Input correct e-mail<br/>':'Введите корректный e-mail<br/>';
  1392.          }
  1393.          
  1394.       if (!$question) {
  1395.          $error .= $eng?'Input your question<br/>':'Введите вопрос<br/>';
  1396.       }
  1397.       if (!$_POST['contact_id']) {
  1398.          if (strstr($sender_email,'test@')) {
  1399.             $error .= $eng?'Current specialist is unavailable':'К сожалению задать вопрос этому специалисту в настоящий момент нельзя';
  1400.          } else {
  1401.             $error .= $eng?'Check the doctor please<br/>':'Выберите, пожалуйста, специалиста<br/>';
  1402.          }
  1403.       }
  1404.      
  1405.       if ($error) {
  1406.          echo '<div class="notification_error">'.$error.'</div>';
  1407.         exit();
  1408.       }
  1409.      
  1410.       if (isset($_POST['contact_id'])) {
  1411.      
  1412.          $contact_id = $_POST['contact_id'];
  1413.              
  1414.          define ('DS',DIRECTORY_SEPARATOR);
  1415.          define('DEBUG', false);
  1416.          require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  1417.          $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  1418.          $sm->init();
  1419.          $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  1420.          $contact = $contacts_model->getSingle($contact_id);
  1421.          $contact = $contact['item'];  
  1422.          $form_id = $contact['contactform_id'];
  1423.          $contact_name = $contact['contactform_contact_name'];
  1424.          $contact_description = $contact['contactform_contact_description'];
  1425.          $contact_picture = $contact['contactform_contact_picture'];
  1426.      
  1427.          $forms_model = $sm->getModel('CFormsModel','cforms');
  1428.          $form = $forms_model->getSingle($form_id);
  1429.          $form = $form['item'];
  1430.          $form_name = $form['contactform_name'];
  1431.      
  1432.          $question_body =  $question;                          
  1433.  
  1434.          $question_post = array (
  1435.             'post_title' => $sender_name,
  1436.             'post_content' => $question_body,
  1437.             'post_status' => 'draft',
  1438.             'post_type' => 'dk_question',
  1439.             'post_author' => 1,      
  1440.          );
  1441.          $pid = wp_insert_post($question_post);
  1442.          update_post_meta($pid, 'sender_email', $sender_email);  
  1443.          update_post_meta($pid, 'form_id', $form_id);
  1444.          update_post_meta($pid, 'form_name',$form_name);
  1445.          update_post_meta($pid, 'contact_id', $contact_id);
  1446.          update_post_meta($pid, 'contact_name', $contact_name);
  1447.          update_post_meta($pid, 'contact_description', $contact_description);
  1448.          update_post_meta($pid, 'contact_picture', $contact_picture);
  1449.          update_post_meta($pid, 'date_arrival', date('d.m.Y'));
  1450.          update_post_meta($pid, 'pub_consent', $pub_consent);
  1451.       }
  1452.      
  1453.       $question_body = '<br/><br/>========== отвечайте пожалуйста над линией =========['.
  1454.       (isset($pid)?$pid:0).']==<br/><br/>'.$sender_name.'<br/>'.$question_body;
  1455.      
  1456.       if (stristr($recipient_email,'callcenter')) {
  1457.          $question_body .= '<br/>Отправлено со страницы '.$_POST['from_page'].'<br/>';
  1458.       }
  1459.            
  1460.       $sender_email = (isset($contact_id)) ? $this->service_email : $sender_email;     
  1461.            
  1462.       $subject ="Вопрос С Сайта";
  1463.       $message = $question_body;
  1464.        
  1465.       $mail = $this->sendLetter($recipient_email, $sender_email, $message, $subject);
  1466.        
  1467.       if ($mail) {
  1468.          echo 'OK::'.$form_name.'::'.strip_tags($contact_name);
  1469.          exit();
  1470.       } else {
  1471.          echo 'error sending mail';
  1472.          exit();
  1473.       }
  1474.    }
  1475.    
  1476.    //-------------------------------------------------------------
  1477.    //                 ajax process appointment
  1478.    //-------------------------------------------------------------
  1479.    function processAppointment($noreferer = false) {
  1480.      
  1481.       if (!$noreferer) {
  1482.          if (!check_ajax_referer('security','ajax_appointment_referer',false)) {
  1483.             _e('failed to check ajax referer');
  1484.             exit();
  1485.          }
  1486.       }
  1487.              
  1488.       $name = htmlspecialchars($_POST["name"]);
  1489.       $email = htmlspecialchars($_POST["email"]);
  1490.       $from_page = $_POST['from_page'];
  1491.       $tel= htmlspecialchars($_POST['tel']);
  1492.       $date = htmlspecialchars($_POST['date']);  
  1493.       $komu = $_POST["komu"];
  1494.       $eng = isset($_POST['eng']);
  1495.                  
  1496.       //--------------------------------------
  1497.       $kei=$_POST["landing_antispam_field"];     
  1498.       $error = '';
  1499.       if($kei!='1j73ch2ne1851') {
  1500.          $error .= $eng?'Enable javascript<br/>':"Включите поддержку javascript.<br />";
  1501.       }
  1502.       if(!$name) {
  1503.         $error .= $eng?'Input your name<br/>':"Пожалуйста, введите ваше имя.<br />";
  1504.       }
  1505.       if ((!$email) && (!$tel)) {
  1506.          $error .= $eng?'Input your phone or email<br/>':'Введите, пожалуйста, телефон<br/>';
  1507.       }
  1508.       if(!$email) {
  1509.         $email = 'system@petrovkamed.ru';
  1510.       }      
  1511.      
  1512.       if (($email) && (!preg_match('/.+@.+/ims', $email))) {
  1513.             $error .= $eng?'Input correct e-mail<br/>':'Введите корректный e-mail<br/>';
  1514.          }
  1515.       //--------------------------------------------
  1516.       if(!$error) {      
  1517.      
  1518.          if (isset($_POST['department_id'])) {
  1519.             $department_id = htmlspecialchars($_POST['department_id']);
  1520.             $department_name = htmlspecialchars($_POST['department_name']);
  1521.          }
  1522.      
  1523.          $subject ="Запись На Прием";
  1524.      
  1525.          $message ="<br/>E-mail: ".$email."<br/>Имя: " .$name."<br/>Телефон:".$tel."<br/>".
  1526.                      '<br/>Отделение: '.$department_name.' ('.$department_id.')'.
  1527.                       "<br/>Отправлено со страницы: ".$from_page."<br/>Дата записи на прием: ".$date;
  1528.  
  1529.          $mail = $this->sendLetter($komu, $email, $message, $subject);
  1530.    
  1531.          if ($mail) {
  1532.             echo 'OK:'.$department_name;
  1533.          } else {
  1534.              echo 'mail send error<br/>';
  1535.          }
  1536.        } else {
  1537.          echo '<div class="notification_error">'.$error.'</div>';
  1538.      }
  1539.      exit();
  1540.    }
  1541.    
  1542.    //-------------------------------------------------------------
  1543.    //                 ajax process otzyv
  1544.    //-------------------------------------------------------------  
  1545.    public function processOtzyv($noreferer = false) {
  1546.    
  1547.      if (!$noreferer) {
  1548.         if (!check_ajax_referer('security','ajax_otzyv_referer',false)) {
  1549.              _e('Failed to verify ajax referer');
  1550.              exit();
  1551.          }   
  1552.       }
  1553.      
  1554.       $kei=$_POST["landing_antispam_field"];     
  1555.       $error = '';
  1556.       if($kei!='1j73ch2ne1851') {
  1557.          $error .= "Включите поддержку javascript.<br />";
  1558.       }  
  1559.              
  1560.       $name = htmlspecialchars($_POST["name"]);    
  1561.       $email = htmlspecialchars($_POST["email"]);
  1562.       $from_page = $_POST['from_page'];
  1563.       $tel= htmlspecialchars($_POST['tel']);        
  1564.       $otzyv = htmlspecialchars($_POST['otzyv']);
  1565.       $pub_agree = $_POST['pub_agree'];
  1566.       $komu = $_POST['komu'];
  1567.       $contact_id = isset($_POST['contact_id'])? $_POST['contact_id'] : -1;
  1568.        
  1569.       $error = '';
  1570.       if(!$name) {
  1571.         $error .= "Пожалуйста, введите ваше имя.<br />";
  1572.       }        
  1573.       if(!$email) {
  1574.         $error .= "Пожалуйста, введите e-mail.<br />";
  1575.        } else  
  1576.            if (!preg_match('/.+@.+/ims', $email)) {
  1577.               $error .= 'Введите корректный e-mail<br/>';
  1578.          }
  1579.    
  1580.       if(!$error) {
  1581.      
  1582.         $review_post = array(
  1583.            'post_title' => 'Отзыв '.$name.' ('.$email.')',
  1584.            'post_content' => $otzyv,
  1585.            'post_status' => 'draft',
  1586.            'post_type' => 'dk_review',
  1587.            'post_author' => 1
  1588.         );
  1589.         $pid = wp_insert_post($review_post);
  1590.        
  1591.         update_post_meta($pid,'sender_name',$name);
  1592.         update_post_meta($pid,'sender_email',$email);
  1593.         update_post_meta($pid,'sender_phone',$tel);
  1594.         update_post_meta($pid,'contact_id',$contact_id);
  1595.         update_post_meta($pid, 'review_date',date('Ymd'));
  1596.  
  1597.         $subject = 'Отзыв Пациента';
  1598.                    
  1599.         $message ="<br/>E-mail: ".$email."<br/>Имя: " .$name."<br/>Телефон:".$tel."<br/>".
  1600.                       "Отправлено со страницы: ".$from_page."<br/>".$pub_agree.'<br/>';
  1601.  
  1602.         $message .="<br/>Отзыв: ".$otzyv."<br/>";     
  1603.         $mail =  $this->sendLetter($komu, $email, $message, $subject);     
  1604.         if($mail) {
  1605.            echo 'OK';
  1606.          } else {
  1607.              echo 'mail send error<br/>';            
  1608.           }
  1609.         }
  1610.          else {  echo '<div class="notification_error">'.$error.'</div>';
  1611.        }
  1612.        exit();
  1613.    }
  1614.    
  1615.    //-------------------------------------------------------------
  1616.    //                     review meta boxes
  1617.    //-------------------------------------------------------------
  1618.    public function add_review_meta_boxes() {
  1619.    
  1620.       add_meta_box('dk_doctor_meta_id', 'Doctor page',
  1621.       array($this->proxy,'doctorpage_meta_box'),'page','side','core');
  1622.    
  1623.       add_meta_box('dk_reviewcontact_meta_id', 'Review contact',
  1624.       array($this->proxy, 'reviewcontact_meta_box'), 'dk_review', 'side', 'core');
  1625.      
  1626.       add_meta_box('dk_reviewdate_meta_id', 'Review date',
  1627.       array($this->proxy,'reviewdate_meta_box'),'dk_review','side','core');
  1628.      
  1629.       add_meta_box('dk_publicationfile_meta_id', 'Publication file',
  1630.       array($this->proxy, 'publicationfile_meta_box'), 'dk_publication','side','core');
  1631.      
  1632.       add_meta_box('dk_publicationdate_id', 'Publication date',
  1633.       array($this->proxy,'publicationdate_meta_box'), 'dk_publication','side','core');
  1634.    }
  1635.    
  1636.    //-------------------------------------------------------------
  1637.    //                doctor page meta box
  1638.    //-------------------------------------------------------------
  1639.    public function doctorpage_meta_box($post) {
  1640.    
  1641.       wp_nonce_field('qwerty','doctorpage_meta_nonce');
  1642.  
  1643.       define ('DS',DIRECTORY_SEPARATOR);
  1644.       define('DEBUG', false);
  1645.       require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  1646.       $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  1647.       $sm->init();
  1648.       $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  1649.       $contacts_model->setOrder('contactform_contact_name');
  1650.       $contacts = $contacts_model->getPage(0,true);
  1651.       $contacts = $contacts['items'];
  1652.      
  1653.       $current_contact = get_post_meta($post->ID,'contactform_contact_id',true);
  1654.      
  1655.       echo '<h4>Select doctor for page</h4><select name="doctor_id">';
  1656.       echo '<option value=-1>-выберите врача-</option>';
  1657.       $repeats = array();
  1658.       foreach ($contacts as $contact) {
  1659.          if (in_array(str_replace('<br/>',' ',$contact['contactform_contact_name']), $repeats))
  1660.             continue;
  1661.            
  1662.          echo '<option value='.$contact['contactform_contact_id'].' '.
  1663.          ($contact['contactform_contact_id']==$current_contact?'selected':'').' >'.
  1664.          str_replace('<br/>',' ',$contact['contactform_contact_name']).'</option>';
  1665.          array_push($repeats, str_replace('<br/>',' ',$contact['contactform_contact_name']));
  1666.       }
  1667.       echo '</select>';
  1668.      
  1669.    }
  1670.    
  1671.    //-------------------------------------------------------------
  1672.    //                review contact meta box
  1673.    //-------------------------------------------------------------
  1674.    public function reviewcontact_meta_box($post) {
  1675.      
  1676.       wp_nonce_field('qwerty','reviewcontact_meta_nonce');
  1677.      
  1678.       define ('DS',DIRECTORY_SEPARATOR);
  1679.       define('DEBUG', false);
  1680.       require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  1681.       $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  1682.       $sm->init();
  1683.       $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  1684.       $contacts_model->setOrder('contactform_contact_name');
  1685.       $contacts = $contacts_model->getPage(0,true);
  1686.       $contacts = $contacts['items'];
  1687.      
  1688.       $current_contact = get_post_meta($post->ID,'contact_id',true);
  1689.      
  1690.       echo '<h4>Select Contact for Review</h4><select name="review_contact_id">';
  1691.       echo '<option value=-1>-выберите врача-</option>';
  1692.       $repeats = array();
  1693.       foreach ($contacts as $contact) {
  1694.          if (in_array(str_replace('<br/>',' ',$contact['contactform_contact_name']), $repeats))
  1695.             continue;
  1696.            
  1697.          echo '<option value='.$contact['contactform_contact_id'].' '.
  1698.          ($contact['contactform_contact_id']==$current_contact?'selected':'').' >'.
  1699.          str_replace('<br/>',' ',$contact['contactform_contact_name']).'</option>';
  1700.          array_push($repeats, str_replace('<br/>',' ',$contact['contactform_contact_name']));
  1701.       }
  1702.       echo '</select>';
  1703.    }
  1704.    //-------------------------------------------------------------
  1705.    //               review date meta box
  1706.    //-------------------------------------------------------------
  1707.    public function reviewdate_meta_box($post) {
  1708.      
  1709.       wp_nonce_field('qwerty','reviewdate_meta_nonce');
  1710.      
  1711.       $current_date = get_post_meta($post->ID, 'review_date', true);
  1712.      
  1713.       echo '<h4>Select Date of Review</h4>';
  1714.       echo '<input type="text" name="review_date" value="'.$current_date.'" class="datepicker" />';
  1715.    }
  1716.    
  1717.    //-------------------------------------------------------------
  1718.    //            publication file meta box
  1719.    //-------------------------------------------------------------  
  1720.    public function publicationfile_meta_box($post) {
  1721.    
  1722.       wp_nonce_field('qwerty','publicationfile_meta_nonce');
  1723.      
  1724.       $publication_file = get_post_meta($post->ID, 'publication_file',true);
  1725.      
  1726.       echo '<h4>Upload publication file</h4>';
  1727.       echo '<p>'.$publication_file.'</p>';
  1728.       echo '<input type="file" name="pub_file" />';
  1729.    }
  1730.    //-------------------------- publication date meta box
  1731.    public function publicationdate_meta_box($post) {
  1732.      
  1733.       wp_nonce_field('qwerty','publicationdate_meta_nonce');
  1734.      
  1735.       $publication_date = get_post_meta($post->ID, 'publication_date', true);
  1736.      
  1737.       echo '<h4>Specify publication date</h4>';
  1738.       echo '<input type="text" name="publication_date" value="'.$publication_date.'" />';
  1739.    }
  1740.    
  1741.    
  1742.    //-------------------------------------------------------------
  1743.    //                      save meta
  1744.    //-------------------------------------------------------------
  1745.    public function save_review_meta($post_id) {
  1746.    
  1747.       $this->save_doctorpage($post_id);
  1748.       $this->save_reviewcontact($post_id);
  1749.       $this->save_reviewdate($post_id);
  1750.       $this->save_publicationfile($post_id);
  1751.       $this->save_publicationdate($post_id);
  1752.    }
  1753.    
  1754.    //-------------------------------------- save doctor page
  1755.    private function save_doctorpage($post_id) {
  1756.    
  1757.      if (!$this->check_nonce('doctorpage_meta_nonce','edit_review')) {
  1758.          return $post_id;
  1759.       }
  1760.       update_post_meta($post_id, 'contactform_contact_id', $_POST['doctor_id']);
  1761.      
  1762.       define ('DS',DIRECTORY_SEPARATOR);
  1763.       define('DEBUG', false);
  1764.       require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  1765.       $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  1766.       $sm->init();
  1767.       $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  1768.       $contacts_model->setOrder('contactform_contact_name');
  1769.       $contacts = $contacts_model->getPage(0,true);
  1770.       $contacts = $contacts['items'];
  1771.      
  1772.       $current_contact_id = $_POST['doctor_id'];
  1773.          
  1774.       foreach ($contacts as $contact) {
  1775.          if ($contact['contactform_contact_id']==$current_contact_id) {
  1776.             $tmp_name = strip_tags(str_replace(' ','',$contact['contactform_contact_name']));
  1777.             break;
  1778.          }                   
  1779.       }
  1780.      
  1781.       foreach ($contacts as $contact) {
  1782.          $tmp_name2 = strip_tags(str_replace(' ','',$contact['contactform_contact_name']));
  1783.          if (($tmp_name2 == $tmp_name) && ($current_contact_id!=$contact['contactform_contact_id'])) {
  1784.             update_post_meta($post_id,'contactform_contact_id2', $contact['contactform_contact_id']);
  1785.             break;
  1786.          }                   
  1787.       }                          
  1788.    }
  1789.    
  1790.    //-------------------------------------- save review contact
  1791.    private function save_reviewcontact($post_id) {
  1792.      
  1793.       if (!$this->check_nonce('reviewcontact_meta_nonce','edit_review')) {
  1794.          return $post_id;
  1795.       }
  1796.       update_post_meta($post_id, 'contact_id', $_POST['review_contact_id']);
  1797.          
  1798.  
  1799.    }
  1800.    
  1801.    //-------------------------------------- save review date
  1802.    private function save_reviewdate($post_id) {
  1803.    
  1804.       if (!$this->check_nonce('reviewdate_meta_nonce','edit_review')) {
  1805.          return $post_id;
  1806.       }
  1807.       update_post_meta($post_id, 'review_date', $_POST['review_date']);
  1808.    }
  1809.    
  1810.    //-------------------------------------- save publication file
  1811.    private function save_publicationfile($post_id) {
  1812.    
  1813.       if (!$this->check_nonce('publicationfile_meta_nonce','edit_publication'))
  1814.          return $post_id;
  1815.      
  1816.       if (isset($_FILES['pub_file'])) {
  1817.          $publication_file = $_FILES['pub_file'];
  1818.          if ($publication_file['error']!==0) {
  1819.             echo 'uploading error '.$publication_file['error'];
  1820.          } else {
  1821.             if (!file_exists($this->plugin_dir.'uploads')) {
  1822.                mkdir($this->plugin_dir.'uploads');
  1823.             }
  1824.             $path_parts = pathinfo($publication_file['name']);
  1825.             if (strtolower($path_parts['extension'])!='pdf') {
  1826.                echo 'Upload error: incorrect file type';               
  1827.             } else {
  1828.                move_uploaded_file($publication_file['tmp_name'],
  1829.                $this->plugin_dir.'uploads/'.$publication_file['name']);
  1830.                
  1831.                update_post_meta($post_id, 'publication_file',
  1832.                $this->plugin_dir.'uploads/'.$publication_file['name']);
  1833.             }
  1834.            
  1835.          }
  1836.       }  
  1837.    }
  1838.    //----------------------------------  save publication date
  1839.    private function save_publicationdate($post_id) {
  1840.    
  1841.       if (!$this->check_nonce('publicationdate_meta_nonce', 'edit_publication'))
  1842.          return $post_id;
  1843.      
  1844.       update_post_meta($post_id,'publication_date', $_POST['publication_date']);
  1845.    }
  1846.    //-------------------------- check nonce
  1847.    private function check_nonce($nonce_field, $capability) {
  1848.    
  1849.       if (!isset($_POST[$nonce_field])) {
  1850.          return false;
  1851.       }
  1852.       $nonce = $_POST[$nonce_field];
  1853.       if (!wp_verify_nonce($nonce,'qwerty')) {
  1854.          return false;
  1855.       }  
  1856.       if ((defined('DOING_AUTOSAVE')) && DOING_AUTOSAVE) {
  1857.          return false;
  1858.       }
  1859.       if (!current_user_can($capability,$post_id)) {
  1860.          return false;
  1861.       }  
  1862.       return true;
  1863.    }
  1864.    
  1865.    
  1866.    //-------------------------------------------------------------
  1867.    //                     post edit form tag
  1868.    //-------------------------------------------------------------
  1869.    function post_edit_form_tag() {
  1870.       echo 'enctype="multipart/form-data"';
  1871.    }
  1872.    
  1873.    //-------------------------------------------------------------
  1874.    //                 send letter
  1875.    //-------------------------------------------------------------  
  1876.    private function sendLetter($komu, $sender, $message, $subject) {
  1877.    
  1878.          $mail_header = array( "MIME-Version"=>"1.0",
  1879.          "Content-type"=>" text/html; charset=windows-1251",
  1880.          "From"=>"<$sender>",
  1881.          "Reply-to"=>"<$sender>");
  1882.          
  1883.          /*$mail_header = "MIME-Version: 1.0\r\n";
  1884.          $mail_header .= "Content-type: text/html; charset=windows-1251\r\n";
  1885.          $mail_header .= "From: <$sender>\r\n";
  1886.          $mail_header .= "Reply-to: <$sender>\r\n";*/
  1887.                  
  1888.          $subject2 = iconv ('UTF-8','windows-1251//IGNORE', $subject);
  1889.          $subject2 = '=?windows-1251?B?'.base64_encode($subject2).'?=';
  1890.          $message2 = iconv('UTF-8','windows-1251//IGNORE',$message);
  1891.  
  1892.          $mail = $this->mail_smtp($komu, $subject2, $message2, $mail_header);
  1893.          //$mail = mail($komu, $subject2, $message2, $mail_header);
  1894.          
  1895.          $this->sendControlLetter($subject2, $message2, $mail_header);
  1896.          
  1897.          return $mail;
  1898.          
  1899.    }
  1900.    
  1901.    //-------------------------------------------------------------
  1902.    //                 send control letter
  1903.    //-------------------------------------------------------------
  1904.    private function sendControlLetter($subject, $message, $mail_header) {
  1905.    
  1906.          $web_source =$_POST['web_source'];
  1907.          $web_medium =$_POST['web_medium'];
  1908.          $web_term = $_POST['web_term'];
  1909.          $web_content = $_POST['web_content'];
  1910.          $web_campaign = $_POST['web_campaign'];
  1911.        
  1912.          $time_initial_visit = $_POST['time_initial_visit'];
  1913.          $time_previous_visit = $_POST['time_previous_visit'];
  1914.          $time_current_visit = $_POST['time_current_visit'];
  1915.          $times_visited = $_POST['times_visited'];
  1916.          $raw_cookie = $_POST['raw_cookie'];
  1917.          $user_agent = $_POST['user_agent'];
  1918.        
  1919.          $message .= '<br/>Campaign source: '.$web_source.'<br/>'.
  1920.          'Campaign name: '.$web_campaign.'<br/>'.
  1921.          'Campaign medium: '.$web_medium.'<br/>'.
  1922.          'Campaign content: '.$web_content.'<br/>'.
  1923.          'Campaign term: '.$web_term.'<br/>'.
  1924.          'Time of first visit: '.$time_initial_visit.'<br/>'.
  1925.          'Time of previous visit: '.$time_previous_visit.'<br/>'.
  1926.          'Time of current visit: '.$time_current_visit.'<br/>'.
  1927.          'Times visited: '.$times_visited.'<br/><br/>'.
  1928.          'Raw cookie: '.$raw_cookie.'<br/><cr/>'.$user_agent;
  1929.  
  1930.          $mail2 = $this->mail_smtp('dkim@petrovkamed.ru,ebykova@petrovkamed.ru',$subject, $message,$mail_header);
  1931.          //$mail2 = mail('dkim@petrovkamed.ru,ebykova@petrovkamed.ru',$subject, $message,$mail_header);
  1932.    }
  1933.    
  1934.    
  1935.    //-------------------------------------------------------------
  1936.    //                    re - send letter
  1937.    //-------------------------------------------------------------
  1938.    public function resendLetter($pid=0, $subject='') {
  1939.            
  1940.        if ((!$pid) && (!isset($_GET['post']))) {
  1941.           exit();
  1942.        }       
  1943.        if (!$pid)
  1944.           $pid = $_GET['post'];
  1945.        else
  1946.           $noredirect =true;
  1947.        
  1948.          
  1949.        $sender_name = get_the_title($pid);
  1950.        
  1951.        global $post;
  1952.        $post = &get_post($pid);
  1953.        setup_postdata($post);
  1954.        
  1955.        $question_body = get_the_content();
  1956.        $sender_email = get_post_meta($pid, 'sender_email', true );           
  1957.        $contact_id =  get_post_meta($pid, 'contact_id', true);
  1958.        
  1959.        wp_reset_postdata($post);
  1960.        
  1961.        define ('DS',DIRECTORY_SEPARATOR);
  1962.        define('DEBUG', false);
  1963.        require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  1964.        $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  1965.        $sm->init();
  1966.        $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  1967.        $contact = $contacts_model->getSingle($contact_id);
  1968.        $contact = $contact['item'];
  1969.        $recipient_email = $contact['contactform_contact_email'];                       
  1970.        
  1971.        $question_body = '<br/><br/>========== отвечайте пожалуйста над линией =========['.
  1972.        (isset($pid)?$pid:0).']==<br/><br/>'.$sender_name.'<br/>'.$question_body;
  1973.            
  1974.        $sender_email = (isset($contact_id)) ? $this->service_email : $sender_email;    
  1975.      
  1976.            
  1977.        if (!$subject)
  1978.           $subject ="Вопрос с сайта так и остался без Вашего ответа. Пожалуйста, ответьте на данное письмо";
  1979.          
  1980.        $message = $question_body;
  1981.        
  1982.        
  1983.        $mail = $this->sendLetter($recipient_email, $sender_email, $message, $subject); 
  1984.            
  1985.        //wp_redirect( admin_url( 'edit.php?post_type='.$post->post_type) );
  1986.        if (empty($noredirect))
  1987.           wp_redirect(admin_url('admin.php?page=dk_questions_and_answers'));
  1988.    
  1989.    }
  1990.    
  1991.    //-------------------------------------------------------------
  1992.    //                       Mail SMTP
  1993.    //-------------------------------------------------------------
  1994.    private function mail_smtp($recipients, $subject, $message, $header) {
  1995.    
  1996.       set_include_path(get_include_path().PATH_SEPARATOR. getenv('DOCUMENT_ROOT').'/Mail'.PATH_SEPARATOR. getenv('DOCUMENT_ROOT').'/pear');
  1997.       require_once "Mail.php";
  1998.      
  1999.       $to = $recipients;      
  2000.       $body = $message;
  2001.  
  2002.       $headers =array_merge($header, array(      
  2003.         'To' => $to,
  2004.         'Subject' => $subject
  2005.         ));
  2006.  
  2007.       $smtp = Mail::factory('smtp', array(
  2008.         'host' => 'ssl://smtp.gmail.com',
  2009.         'port' => '465',
  2010.         'auth' => true,
  2011.         'username' => 'dmkim1979@gmail.com',
  2012.         'password' => 'mds4pknv6zouszilvnm'
  2013.     ));
  2014.    
  2015.       /*    $smtp = Mail::factory('smtp', array(
  2016.         'host' => 'ssl://smtp.yandex.ru',
  2017.         'port' => '465',
  2018.         'auth' => true,
  2019.         'username' => 'petrovkamedic@yandex.ru',
  2020.         'password' => 'error100'
  2021.     ));*/
  2022.  
  2023.     $mail = $smtp->send($to, $headers, $body);
  2024.  
  2025.     if (PEAR::isError($mail)) {
  2026.        echo('<p>' . $mail->getMessage() . '</p>');
  2027.      } else {
  2028.        return true;
  2029.       }
  2030.    }
  2031.    //-------------------------------------------------------------
  2032.    //            Check answers by scheduler
  2033.    //-------------------------------------------------------------  
  2034.    public function checkAnswers() {
  2035.    
  2036.       $host = 'https://mail.petrovkamed.ru/WorldClient.dll';
  2037.       $url = $host.'?View=Main';
  2038.       $username =urlencode('petrovkasite@petrovkamed.ru');
  2039.       $password = '52/y2;1<1T';
  2040.    
  2041.       $postdata = 'User='.$username.'&'.
  2042.          'Password='.$password.'&'.
  2043.          'Lang='.'&'.'Theme=';
  2044.  
  2045.       $res_page = $this->send_request($url, $postdata);
  2046.    
  2047.       $header = $res_page['header'];
  2048.       preg_match_all("/Set-Cookie: (.*?)=(.*?);/i",$header,$res);
  2049.       $cookie='';
  2050.       foreach ($res[1] as $key => $value) {  
  2051.          $cookie.= $value.'='.$res[2][$key].'; ';    
  2052.       };
  2053.      
  2054.    
  2055.       $body = $res_page['body'];
  2056.       preg_match('/WorldClient\.dll\?Session=([^\']*?)&/ims',$body,$matches);
  2057.       $sessid = $matches[1];
  2058.       $inboxparams = 'View=List&ReturnJavaScript=1&FolderID=0&CurrentRequest=0&CurrentView=0&ContentType=javascript&UTF8=1';  
  2059.       $inbox = $host.'?Session='.$sessid.'&'.$inboxparams;
  2060.       $res = $this->send_request($inbox, '', $cookie);
  2061.       $letters =json_decode($res['body']);
  2062.       $letters = $letters->scripts;
  2063.       $ids = array();
  2064.       foreach ($letters as $letter) {
  2065.          if (is_object($letter))
  2066.             $ids[] = $letter->id;
  2067.       }
  2068.      
  2069.       define ('DS',DIRECTORY_SEPARATOR);
  2070.       define('DEBUG', false);
  2071.       require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  2072.       $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  2073.       $sm->init();
  2074.       $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  2075.       $contacts = $contacts_model->getPage(0,true);
  2076.       $contacts = $contacts['items'];
  2077.       $f = create_function('$a','return $a[\'contactform_contact_email\'];');
  2078.       $emails = array_map($f, $contacts);
  2079.      
  2080.       $i=0;
  2081.       foreach ($ids as $id) {
  2082.          $letter_param =
  2083.          'View=Message&Preview=Yes&ReturnJavaScript=1&ChangeView=No&NoLoop=1&ContentType=JavaScript&Number='.$id.'&FolderID=0&CurrentRequest=0&_=1423491029292';
  2084.      
  2085.          $letter_body_request = $host.'?Session='.$sessid.'&'.$letter_param;
  2086.          $res = $this->send_request($letter_body_request,'',$cookie);
  2087.          $letter_body = json_decode($res['body']);
  2088.          $answer_author = $letter_body->message->from;
  2089.          $answer_body = $letter_body->message->body;
  2090.      
  2091.          preg_match('/==\[(\d+)\]==/i',$answer_body, $match, PREG_OFFSET_CAPTURE);
  2092.          if (!isset($match[1])) {
  2093.             continue;
  2094.          }   
  2095.          $post_id = $match[1][0];
  2096.          $post = get_post($post_id, ARRAY_A);
  2097.          
  2098.          if (!$post)
  2099.             continue;      
  2100.                              
  2101.          $posts = get_posts(array('post_type'=>'dk_question','post_parent'=>$post_id, 'post_status'=>array('draft','publish')));     
  2102.          if ($posts)
  2103.             break;         
  2104.          
  2105.          $contact_id = get_post_meta($post_id, 'contact_id',true);
  2106.          $answer_author_id = $contact_id;                
  2107.          $answer_author_name = get_post_meta($post_id, 'contact_name', true);
  2108.          $answer_author_description = get_post_meta($post_id, 'contact_description', true);
  2109.          $answer_author_picture = get_post_meta($post_id, 'contact_picture', true);
  2110.          $sender_email = get_post_meta($post_id, 'sender_email',true);
  2111.          $form_name = get_post_meta($post_id, 'form_name', true);
  2112.                        
  2113.          preg_match('/.*?<(.*?)>/i', htmlspecialchars_decode($answer_author), $match2);
  2114.                
  2115.          if (isset($match2[1])) {
  2116.             $answer_author_email = $match2[1];
  2117.             $key = array_search($answer_author_email,$emails);
  2118.             if (($key!==false) && ($contacts[$key]['contactform_contact_id']!=$contact_id)) {              
  2119.                $answer_author_id = $contacts[$key]['contactform_contact_id'];
  2120.                $answer_author_name = $contacts[$key]['contactform_contact_name'];
  2121.                $answer_author_description = $contacts[$key]['contactform_contact_description'];
  2122.                $answer_author_picture = $contacts[$key]['contactform_contact_picture'];
  2123.             }
  2124.          } else {
  2125.             $answer_author_email = $answer_author;
  2126.          }
  2127.          
  2128.  
  2129.          $answer_clear = substr($answer_body,0,$match[0][1]);
  2130.          preg_match('/===/i',$answer_clear, $match, PREG_OFFSET_CAPTURE);
  2131.      
  2132.          if (isset($match[0])) {
  2133.             $answer_clear = substr($answer_clear,0,$match[0][1]);                  
  2134.          }
  2135.          
  2136.          /*preg_match('/&gt;\s*<[^>]*br[^>]*>\s*&gt;/ims', $answer_clear, $match, PREG_OFFSET_CAPTURE);      
  2137.          if (isset($match[0])) {
  2138.             $answer_clear = substr($answer_clear,0,$match[0][1]);                  
  2139.          }       
  2140.          preg_match('/\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}/i',$answer_clear,$match, PREG_OFFSET_CAPTURE);               
  2141.          if (isset($match[0])) {
  2142.             $answer_clear = substr($answer_clear,0,$match[0][1]);
  2143.          }*/                     
  2144.          $answer_clear = strip_tags($answer_clear,'<br>');
  2145.          $answer_clear = str_replace('&gt;','',$answer_clear);
  2146.          $answer_clear = preg_replace('/\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}.*?<[^>]*br[^>]*>/ims','',$answer_clear);
  2147.          
  2148.          if (strpos($answer_clear,'From:')!==false) {
  2149.             $check_upper = substr($answer_clear, 0, strpos($answer_clear,'From:'));
  2150.             $check_upper = trim(strip_tags(str_replace('&nbsp;','',$check_upper)));
  2151.            
  2152.             if ($check_upper) {
  2153.                $answer_clear = $check_upper;
  2154.             } else {
  2155.                $qstr ='Subject: Вопрос С Сайта';
  2156.                $qpos = strpos($answer_clear, $qstr);
  2157.                $answer_clear = substr($answer_clear, $qpos+ strlen($qstr));
  2158.             }
  2159.            
  2160.          }
  2161.                  
  2162.          //wp_update_post( array('ID'=>$post_id, 'post_status'=>'publish'));
  2163.          $answer_post = array (
  2164.          'post_title' => 'Отвечает: '.$answer_author,
  2165.          'post_content' => $answer_clear,
  2166.          'post_status' => 'draft',
  2167.          'post_type' => 'dk_question',
  2168.          'post_author' => 1,       
  2169.          'post_parent' => $post_id  );
  2170.          
  2171.          $pid = wp_insert_post($answer_post);
  2172.          if ($answer_author_id) {
  2173.             update_post_meta($pid,'contact_id',$answer_author_id);
  2174.             update_post_meta($pid,'contact_name',$answer_author_name);
  2175.             update_post_meta($pid,'contact_description',$answer_author_description);
  2176.             update_post_meta($pid,'contact_picture',$answer_author_picture);           
  2177.             update_post_meta($pid,'sender_email', $sender_email);
  2178.             update_post_meta($pid,'form_name', $form_name);
  2179.          }
  2180.          echo 'inserted post number '.$pid.'<br/>';
  2181.          
  2182.          $sender_email = get_post_meta($post_id, 'sender_email', true);      
  2183.          /*$mail_header = array("MIME-Version"=>"1.0",
  2184.             "Content-type"=>"text/html; charset=utf-8",
  2185.             "From"=>$answer_author_email,
  2186.             "Reply-to"=>$answer_author_email);*/
  2187.            
  2188.          $mail_header = array( "MIME-Version"=>"1.0",
  2189.          "Content-type"=>"text/html; charset=utf-8",
  2190.          "From" => $answer_author_email,
  2191.          "Reply-to"=>$answer_author_email);
  2192.          
  2193.        
  2194.          $subject ="Вопрос С Сайта: Отвечает ".$answer_author;
  2195.          $message = $answer_clear;       
  2196.          $mail = $this->mail_smtp($sender_email, $subject, $message, $mail_header);
  2197.          $mail2 = $this->mail_smtp(
  2198.          'dkim@petrovkamed.ru,ebykova@petrovkamed.ru,susoltseva@petrovkamed.ru',
  2199.          $subject, $message.
  2200.          '<a href="http://petrovkamed.ru/wp-admin/admin.php?page=dk_questions_and_answers&post_id='.
  2201.          $post_id.'">Отреагировать</a>',
  2202.          $mail_header);
  2203.        
  2204.  
  2205.          $i++;   
  2206.          if ($i>50)
  2207.             break;
  2208.       }
  2209.      
  2210.    }
  2211.    
  2212.    //-------------------------------------------------------------
  2213.    //       check unanswered questions on schedule
  2214.    //-------------------------------------------------------------
  2215.    public function checkQ() {
  2216.      
  2217.       $yesterday = getdate(strtotime("-1 day"));
  2218.      
  2219.       $args = array(
  2220.          'post_type'=>'dk_question',
  2221.          'post_status'=>'draft',
  2222.          'posts_per_page'=>100,
  2223.          'post_parent'=>0,
  2224.          'date_query'=> array(
  2225.             array(
  2226.                'year'=>$yesterday['year'],
  2227.                'month'=>$yesterday['mon'],
  2228.                'day'=>$yesterday['mday']
  2229.             )
  2230.          ),
  2231.          'tax_query'=> array(
  2232.             array(
  2233.                'taxonomy'=>'category',
  2234.                'field'=>'term_id',
  2235.                'terms'=> array(93),
  2236.                'operator'=>'NOT IN'
  2237.             )
  2238.          ),
  2239.          'meta_query'=> array(
  2240.             array(
  2241.                'key'=>'warning_sent',
  2242.                'value'=>array(1),
  2243.                'compare'=>'NOT IN'
  2244.             )
  2245.          )       
  2246.       );
  2247.       $q = new WP_Query($args);
  2248.      
  2249.       while ($q->have_posts()) {
  2250.        
  2251.          $q->the_post();
  2252.          
  2253.          $sender_name = get_the_title();
  2254.          $question_body = get_the_content();         
  2255.          $sender_email = get_post_meta(get_the_id(), 'sender_email', true );             
  2256.          $contact_id =  get_post_meta(get_the_id(), 'contact_id', true);       
  2257.        
  2258.          $question_body = '<br/><br/>'.$sender_name.'<br/>'.$question_body.'<br/><br/>'.
  2259.          '<a href="'.admin_url('admin.php?page=dk_questions_and_answers&rerequest&post_id='.get_the_id()).'">Отреагировать</a>';          
  2260.          $sender_email =  $this->service_email;    
  2261.  
  2262.          $subject = "Неотвеченный вопрос на сайте";
  2263.          $message = $question_body;
  2264.                
  2265.          $mail = $this->sendLetter(
  2266.          'dkim@petrovkamed.ru,ebykova@petrovkamed.ru,susoltseva@petrovkamed.ru',
  2267.          $sender_email, $message, $subject);   
  2268.          
  2269.          update_post_meta(get_the_id(),'warning_sent',1);
  2270.       }
  2271.      
  2272.  
  2273.    }
  2274.    
  2275.    //-------------------------------------------------------------
  2276.    //             request to mail server
  2277.    //-------------------------------------------------------------
  2278.    private function send_request($url, $postdata='', $cookie='') {
  2279.  
  2280.       $header = array(
  2281.          'Content-type: application/x-www-form-urlencoded'
  2282.       );
  2283.       $ch = curl_init();
  2284.    
  2285.       curl_setopt($ch, CURLOPT_URL,$url);
  2286.       curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  2287.       curl_setopt($ch, CURLOPT_HEADER, 1);
  2288.       curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
  2289.       curl_setopt($ch, CURLOPT_USERAGENT,
  2290.               "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
  2291.              
  2292.       //curl_setopt($ch, CURLOPT_ENCODING,1);
  2293.       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    
  2294.       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  2295.       curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  2296.    
  2297.       if ($postdata) {      
  2298.          curl_setopt($ch, CURLOPT_POST,1);
  2299.          curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  2300.       }
  2301.       if ($cookie) {
  2302.          curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  2303.       }
  2304.    
  2305.       curl_setopt($ch, CURLOPT_VERBOSE, true);
  2306.       $verbose = fopen('php://temp','rw+');
  2307.       curl_setopt($ch, CURLOPT_STDERR, $verbose);
  2308.    
  2309.       $result = curl_exec($ch);
  2310.       if (curl_errno($ch)) {
  2311.          throw new Exception(curl_error($ch));
  2312.       }
  2313.       rewind($verbose);
  2314.       $verboselog = stream_get_contents($verbose);
  2315.       $verboselog = htmlspecialchars($verboselog);
  2316.    
  2317.       $header=substr($result,0,curl_getinfo($ch,CURLINFO_HEADER_SIZE));
  2318.       $body=substr($result,curl_getinfo($ch,CURLINFO_HEADER_SIZE));  
  2319.       curl_close($ch);
  2320.    
  2321.       return array('header'=>$header, 'body'=>$body, 'log'=>$verboselog);      
  2322.    }  
  2323.    
  2324.    //-------------------------------------------------------------
  2325.    //                  check if scripts needed
  2326.    //-------------------------------------------------------------
  2327.    private function scriptNeeded(&$shortcode_found_var, $shortcode_name ) {
  2328.      
  2329.       if (isset($shortcode_found_var))
  2330.          return $shortcode_found_var;
  2331.          
  2332.       $shortcode_found_var = false;
  2333.      
  2334.       if ((!is_single()) && (!is_page())) {
  2335.        
  2336.          return false;
  2337.       }          
  2338.       if (have_posts()) {
  2339.          while (have_posts()) {
  2340.             the_post();
  2341.             $post = get_post(get_the_id());
  2342.             $content = $post->post_content;
  2343.             if (stripos($content,$shortcode_name)!==false) {
  2344.                $shortcode_found_var = true;          
  2345.                break;
  2346.             }
  2347.             $info = serialize(get_post_meta(get_the_id(),'ether_builder_data',true));
  2348.             if (stripos($info, $shortcode_name)!==false) {
  2349.                $shortcode_found_var = true;
  2350.                break;
  2351.             }
  2352.          }
  2353.       }
  2354.       rewind_posts();
  2355.       return $shortcode_found_var;
  2356.    }
  2357.  
  2358.    //-------------------------------------------------------------
  2359.    //                load form script
  2360.    //-------------------------------------------------------------  
  2361.    public function load_form_script() {
  2362.    
  2363.       global $post;
  2364.       $doctor_id = get_post_meta($post->ID,'contactform_contact_id',true);
  2365.      
  2366.       if (($this->scriptNeeded($this->shortcode_found,'[dk_contact_form')) ||
  2367.          ($this->scriptNeeded($this->shortcode_total_found,'[dk_totalcontact_form')) || ($doctor_id) || (5==5) ) {
  2368.          wp_enqueue_script('mask_edit', $this->plugin_url.'assets/jquery.maskedinput.js', array('jquery'));          
  2369.          wp_enqueue_script('form_script', $this->plugin_url.'assets/formscript.js',array('jquery'));
  2370.          $ajax_nonce = wp_create_nonce('security');
  2371.          
  2372.          wp_localize_script('form_script', 'f_options',
  2373.          array(
  2374.          'ajax_url'=>admin_url('admin-ajax.php',(is_ssl()? 'https':'http')),
  2375.          'ajax_nonce'=>$ajax_nonce));
  2376.       }
  2377.       if ($this->scriptNeeded($this->shortcode_appointment_found,'[dk_appointment_form') || (5==5) || ($doctor_id)) {
  2378.          wp_enqueue_script('mask_edit', $this->plugin_url.'assets/jquery.maskedinput.js', array('jquery'));        
  2379.          wp_enqueue_script('appointment_script', $this->plugin_url.'assets/apposcript.js',array('jquery_ui'));
  2380.          $ajax_appo_nonce = wp_create_nonce('security');
  2381.          wp_localize_script('appointment_script', 'appo_options',
  2382.          array( 'ajax_url'=>admin_url('admin-ajax.php',(is_ssl()?'https':'http')),
  2383.          'ajax_nonce'=>$ajax_appo_nonce));
  2384.       }
  2385.      
  2386.       if ($this->scriptNeeded($this->shortcode_otzyv_full_found,'[dk_otzyv_full') || ($doctor_id)) {
  2387.          
  2388.           wp_enqueue_script('otzyv_script', $this->plugin_url.'assets/otzyvscript.js',array('jquery'));
  2389.           $ajax_otzyv_nonce = wp_create_nonce('security');
  2390.           wp_localize_script('otzyv_script', 'otzyv_options',
  2391.           array('ajax_url'=>admin_url('admin-ajax.php',(is_ssl()?'https':'http')),'ajax_nonce'=>$ajax_otzyv_nonce));
  2392.           }
  2393.      
  2394.       if ($this->scriptNeeded($this->shortcode_smi_found,'[dk_smi')) {
  2395.          wp_enqueue_script('modernizr_custom', $this->plugin_url.'assets/modernizr.custom.js', array('jquery'));
  2396.          wp_enqueue_script('book_block', $this->plugin_url.'assets/jquery.bookblock.js', array('jquery','modernizr_custom'));        
  2397.       }
  2398.      
  2399.  
  2400.       if ($doctor_id) {
  2401.          wp_enqueue_script('ether-builder', plugins_url('ether-builder/media/scripts/ether-builder.js'), array('jquery'));
  2402.       }
  2403.    }
  2404.    
  2405.    //-------------------------------------------------------------
  2406.    //               load form style
  2407.    //-------------------------------------------------------------  
  2408.    public function load_form_style() {
  2409.       if (($this->scriptNeeded($this->shortcode_found,'[dk_contact_form')) ||
  2410.          ($this->scriptNeeded($this->shortcode_total_found,'[dk_totalcontact_form'))) {
  2411.          wp_register_style('form_style',plugins_url('/assets/formstyle.css',__FILE__));
  2412.          wp_enqueue_style('form_style');
  2413.       }
  2414.       if ($this->scriptNeeded($this->shortcode_list_found,'[dk_qa_list')) {
  2415.          wp_register_style('list_style', $this->plugin_url.'assets/liststyle.css');
  2416.          wp_enqueue_style('list_style');
  2417.       }
  2418.       if ($this->scriptNeeded($this->shortcode_appointment_found,'[dk_appointment_form') || (5==5)) {
  2419.          wp_register_style('appo_style', $this->plugin_url.'assets/appostyle.css');
  2420.          wp_enqueue_style('appo_style');
  2421.       }
  2422.       if ($this->scriptNeeded($this->shortcode_smi_found, '[dk_smi')) {
  2423.          wp_register_style('book_style', $this->plugin_url.'assets/bookblock.css');
  2424.          wp_enqueue_style('book_style');
  2425.       }
  2426.       global $post;
  2427.       $doctor_id = get_post_meta($post->ID,'contactform_contact_id',true);
  2428.       if ($doctor_id) {      
  2429.          wp_register_style('ether-builder-style', plugins_url('ether-builder/media/stylesheets/ether-builder-light.css'));
  2430.          wp_enqueue_style('ether-builder-style');
  2431.       }
  2432.      
  2433.    
  2434.    }
  2435.    
  2436.    //-------------------------------------------------------------
  2437.    //          print form script and style on landing
  2438.    //-------------------------------------------------------------
  2439.    public function print_form_script_and_style() {
  2440.      
  2441.       $ajax_nonce = wp_create_nonce('security');
  2442.      
  2443.       echo '<script type="text/javascript" src="'.$this->plugin_url.'assets/jquery.maskedinput.js"></script>';
  2444.       echo '<script type="text/javascript" src="'.$this->plugin_url.'assets/formscript.js'.'"></script>';
  2445.       echo '<link rel="stylesheet" type="text/css" media="all" href="'.$this->plugin_url.'assets/formstyle.css" />';
  2446.       echo '<script type="text/javascript">
  2447.       var f_options = {      
  2448.          ajax_url:"'.admin_url('admin-ajax.php',(is_ssl()? 'https':'http')).'",
  2449.          ajax_nonce:"'.$ajax_nonce.'"};
  2450.       </script>';
  2451.  
  2452.       echo '<script type="text/javascript" src="'.$this->plugin_url.'assets/apposcript.js"></script>';
  2453.       //echo '<link rel="stylesheet" type="text/css" media="all" href="'.$this->plugin_url.'assets/appostyle.css" />';
  2454.       echo '<script type="text/javascript">
  2455.        var appo_options = {
  2456.          ajax_url:"'.admin_url('admin-ajax.php',(is_ssl()?'https':'http')).'",
  2457.          ajax_nonce:"'.$ajax_nonce.'"};
  2458.       </script>';
  2459.      
  2460.       echo '<script type="text/javascript" src="'.$this->plugin_url.'assets/otzyvscript.js"></script>';
  2461.       echo '<script type="text/javascript">
  2462.        var  otzyv_options = {
  2463.             ajax_url:"'.admin_url('admin-ajax.php', (is_ssl()?'https':'http')).'",
  2464.             ajax_nonce:"'.$ajax_nonce.'"};       
  2465.       </script>';
  2466.    }
  2467.    
  2468.    //-------------------------------------------------------------
  2469.    //          print custom styles
  2470.    //-------------------------------------------------------------    
  2471.    public function print_custom_styles() {
  2472.        
  2473.          while (have_posts()) {
  2474.             the_post();
  2475.             $post = get_post(get_the_id());
  2476.             $content = $post->post_content;
  2477.            
  2478.             if (stripos($content,'[dk_smi')!==false) {
  2479.                 echo '<style type="text/css">
  2480.                     .dk_smi_h2 {
  2481.                        margin-top:-10px!important;
  2482.                     }
  2483.                  </style>';  
  2484.                
  2485.             }      
  2486.             if (stripos($content,'[dk_otzyv_list')!==false) {
  2487.                echo '<style type="text/css">
  2488.                   .dk_otzyv_h5 {
  2489.                      margin-top:40px;
  2490.                   }
  2491.                </style>';
  2492.             }
  2493.  
  2494.  
  2495.            
  2496.          }   
  2497.          rewind_posts();
  2498.    }
  2499.      
  2500.    //-------------------------------------------------------------
  2501.    //                   footer script
  2502.    //-------------------------------------------------------------
  2503.    public function print_footer_scripts() {
  2504.    
  2505.       while (have_posts()) {
  2506.      
  2507.          the_post();
  2508.          $post = get_post(get_the_id());
  2509.          $content = $post->post_content;
  2510.    
  2511.          if (stripos($content,'[dk_smi')!==false):
  2512.             ?>
  2513.  
  2514.      <script type="text/javascript">
  2515.       (function($) {
  2516.              
  2517.          $(document).ready(
  2518.             function() {
  2519.            
  2520.                var config = {
  2521.                   $bookblock : $('#bb-bookblock'),
  2522.                  
  2523.                   $navprev : $('#bbprev'),
  2524.                   $navnext : $('#bbnext'),
  2525.                   $navfirst : $('#bbfirst'),
  2526.                   $navlast : $('#bblast'),
  2527.                  
  2528.                   $navprevtop : $('#bbprevtop'),
  2529.                   $navnexttop : $('#bbnexttop'),
  2530.                   $navfirsttop : $('#bbfirsttop'),
  2531.                   $navlasttop : $('#bblasttop'),
  2532.                }
  2533.        
  2534.                var bb = config.$bookblock.bookblock( {
  2535.                             speed : 800,
  2536.                             shadowSides : 0.8,
  2537.                             shadowFlip : 0.7
  2538.                         } );
  2539.                                            
  2540.                for (var i=0; i<bb.itemsCount; i++) {
  2541.                   var page_item = $('<a/>',{href:'javascript:',class:'bbnumber'}).html(i+1);
  2542.                  
  2543.                  
  2544.                   page_item.on('click touchstart', jump_closure(i+1));
  2545.                  
  2546.                   $('#bbfirsttop').before(page_item);                                
  2547.                }
  2548.                 check_controls();
  2549.                
  2550.                function jump_closure(page) {
  2551.                   return function() {
  2552.                      bb.jump(page);
  2553.                      check_controls();
  2554.                      return false;
  2555.                   }
  2556.                }
  2557.                
  2558.                config.$navprev.on('click touchstart', function() {
  2559.                   config.$bookblock.bookblock('prev');
  2560.                   check_controls();
  2561.                   return false;
  2562.                });
  2563.                
  2564.                config.$navnext.on('click touchstart', function() {
  2565.                   config.$bookblock.bookblock('next');
  2566.                   check_controls();
  2567.                   return false;
  2568.                });
  2569.                
  2570.                config.$navfirst.on('click touchstart', function() {
  2571.                   bb.jump(1);
  2572.                   check_controls();
  2573.                   return false;
  2574.                });
  2575.                
  2576.                config.$navlast.on('click touchstart', function() {
  2577.                   bb.jump(bb.itemsCount);
  2578.                   check_controls();
  2579.                   return false;
  2580.                });             
  2581.                
  2582.                //------------------------------------
  2583.                config.$navprevtop.on('click touchstart', function() {
  2584.                   config.$bookblock.bookblock('prev');
  2585.                   check_controls();
  2586.                   return false;
  2587.                });
  2588.                
  2589.                config.$navnexttop.on('click touchstart', function() {
  2590.                   config.$bookblock.bookblock('next');
  2591.                   check_controls();
  2592.                   return false;
  2593.                });
  2594.                config.$navfirsttop.on('click touchstart', function() {
  2595.                   bb.jump(1);
  2596.                   check_controls();
  2597.                   return false;
  2598.                });
  2599.                
  2600.                config.$navlasttop.on('click touchstart', function() {
  2601.                   bb.jump(bb.itemsCount);
  2602.                   check_controls();
  2603.                   return false;
  2604.                });
  2605.                //------------------------------------------
  2606.                 function check_controls() {
  2607.                    if (bb.current==0) {
  2608.                       $('#bbprev,#bbprevtop, #bbfirst, #bbfirsttop').hide();
  2609.                    } else {
  2610.                       $('#bbprev,#bbprevtop, #bbfirst, #bbfirsttop').show();
  2611.                    }
  2612.                    
  2613.                    if (bb.current==(bb.itemsCount-1)) {
  2614.                       $('#bbnext,#bbnexttop,#bblast, #bblasttop').hide();
  2615.                    } else {
  2616.                      $('#bbnext,#bbnexttop,#bblast, #bblasttop').show();
  2617.                    }
  2618.                    
  2619.                    $('.bbnumber').removeClass('active').eq(bb.current).addClass('active');
  2620.                 }
  2621.                
  2622.             }
  2623.          )
  2624.       })(jQuery)
  2625.       </script>
  2626.            
  2627.             <?php
  2628.         break;
  2629.        endif;
  2630.       }
  2631.       rewind_posts();
  2632.    }
  2633.    
  2634.    //----------------------------------------------------  
  2635.    public function stub_shortcode() {
  2636.       return '';
  2637.    }
  2638.    
  2639.    //-------------------------------------------------------------
  2640.    //             questions and answers shortcode
  2641.    //-------------------------------------------------------------
  2642.    public function qa_list_shortcode($atts, $content=null) {
  2643.      
  2644.       $default_atts = array('id'=>0);
  2645.       extract(shortcode_atts($default_atts, $atts));
  2646.      
  2647.       $params = array('post_type'=>'dk_question','orderby'=>'date', 'order'=>'DESC',
  2648.       'status'=>'publish', 'meta_key'=>'form_id', 'posts_per_page'=>50, 'post_parent'=>0);   
  2649.      
  2650.       if ($id) {
  2651.          $params = array_merge($params,array( 'meta_value'=>$id));
  2652.       }
  2653.       $q = new WP_Query($params);
  2654.      
  2655.       $s = '<div class="questions_and_answers">';
  2656.       while ($q->have_posts()) {
  2657.          $q->the_post();
  2658.          
  2659.          $post_cats = wp_get_post_categories(get_the_id());
  2660.          if (in_array(93,$post_cats)) {
  2661.             continue;
  2662.          }
  2663.          
  2664.          $contact_id = get_post_meta(get_the_id(),'contact_id',true);
  2665.          $contact_name = get_post_meta(get_the_id(),'contact_name',true);
  2666.          $contact_description = get_post_meta(get_the_id(),'contact_description',true);
  2667.          $contact_picture = get_post_meta(get_the_id(),'contact_picture',true);
  2668.          $form_name = get_post_meta(get_the_id(),'form_name',true);
  2669.          
  2670.          $s .= '<div class="qa_question">';
  2671.          $s .= '<div class="question_header">Вопрос</div> | ';
  2672.          $s .= '<div class="question_date">'.get_the_date('d.m.Y',get_the_id()).'</div>';
  2673.          $s .= '<div class="question_author">'.get_the_title().'</div>';
  2674.          $s .= '<div class="question_body">'.get_the_content().'</div>';
  2675.          $s .= '</div>';   
  2676.          
  2677.          $answers = get_posts(array('post_type'=>'dk_question','post_parent'=>get_the_id()));
  2678.          foreach ($answers as $answer) {
  2679.             setup_postdata($answer);
  2680.             $answer_author_id = get_post_meta($answer->ID, 'contact_id',true);
  2681.             if ($answer_author_id) {
  2682.                $contact_id = $answer_author_id;
  2683.                $contact_name = get_post_meta($answer->ID, 'contact_name',true);
  2684.                $contact_description = get_post_meta($answer->ID, 'contact_description', true);
  2685.                $contact_picture = get_post_meta($answer->ID, 'contact_picture', true);
  2686.             }
  2687.            
  2688.             $s .= '<div class="qa_answer">';
  2689.             $s .= '<div class="answer_author">';
  2690.                $s .= '<div class="answer_author_picture"><img src="'.$contact_picture.'" /></div>';
  2691.                $s .= '<div class="answer_author_name">'.$contact_name.'</div>';
  2692.                 $s .= '<div class="answer_author_description">'.$contact_description.'</div>';
  2693.             $s .= '</div>';    
  2694.             $s .= '<div class="answer_header">Ответ</div>';
  2695.             $s .= '<div class="answer_body">'.str_replace('dmkim1979@gmail.com пишет:','',get_the_content()).'</div>';
  2696.             $s .= '</div>';
  2697.          }
  2698.          wp_reset_postdata();
  2699.                  
  2700.       }
  2701.       wp_reset_query();
  2702.      
  2703.       $s .= '</div>';
  2704.      
  2705.       return $s;
  2706.      
  2707.    }  
  2708.    //-------------------------------------------------------------
  2709.    //             contact form shortcode
  2710.    //-------------------------------------------------------------
  2711.    public function contactform_shortcode($atts, $content=null) {
  2712.    
  2713.       $default_atts = array('id'=>0, 'id2'=>0, 'type'=>'');
  2714.       extract(shortcode_atts($default_atts,$atts));
  2715.      
  2716.       define ('DS',DIRECTORY_SEPARATOR);
  2717.       define('DEBUG', false);
  2718.       require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  2719.       $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  2720.       $sm->init();
  2721.       $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  2722.       //$contacts_model->setFilterString('contactform_id='.$id,true);
  2723.      
  2724.       $contacts_model->setFilterString(
  2725.           'contact_actual<>0 and contactform_contact_id in (select contactform_contact_id from dk_contacts_links where  '.
  2726.           ' contactform_id='.$id.')',true);
  2727.      
  2728.       if ($id2) {
  2729.          $contacts_model->setFilterString('contactform_contact_id='.$id2,true);
  2730.       }
  2731.       $contacts = $contacts_model->getPage(0,true);
  2732.       $contacts = $contacts['items'];
  2733.    
  2734.       $data_script ='';
  2735.       foreach ($contacts as $contact) {
  2736.          $data_script .= '\''.trim($contact['contactform_contact_email']).'\':'.$contact['contactform_contact_id'].',';
  2737.       }
  2738.       $data_script = 'emails_ids ={'.$data_script.'}';
  2739.       $sContactForm = '<script type="text/javascript">'.$data_script.'</script>';
  2740.    
  2741.       if ($type=='eko') {
  2742.          $sContactForm .= '<style type="text/css">#recipient_email,#rec_label {display:none;}</style>';
  2743.       }
  2744.          
  2745.       $sContactForm .= '
  2746.      <h2>Задайте вопрос специалисту</h2>
  2747.    
  2748.      <div class="dk_form_fields" style="overflow:auto">
  2749.        <div class="ajax_note"></div>
  2750.          <div class="wait_div">
  2751.            <p>Форма отправляется. Пожалуйста, подождите</p>
  2752.             <img src="'.$this->plugin_url.'ajax-loader.gif" />         
  2753.          </div>
  2754.         <form class="dk-contact-form" action="">
  2755.            <label>Представьтесь <sup>*</sup></label><input type="text" name="sender_name" value="" placeholder="Введите Ваше имя" />
  2756.            <label id="rec_label">ФИО врача <sup>*</sup></label>
  2757.  
  2758.            <select length="50" name="recipient_email" id="recipient_email2"> ';
  2759.            
  2760.             foreach ($contacts as $contact) {
  2761.                  
  2762.                $sContactForm .= '<option value="'.$contact['contactform_contact_email'].'">'.
  2763.                $contact['contactform_contact_name'].'</option>';
  2764.             }      
  2765.            $sContactForm .= ' </select>
  2766.             <input type="hidden" name="contact_id" value="" />
  2767.            <label>E-Mail <sup>*</sup></label><input type="text" name="sender_email" value="" placeholder="Введите E-mail" />
  2768.            <label>Вопрос <sup>*</sup></label>
  2769.             <textarea rows="10" cols="45" name="question" placeholder="Введите вопрос"></textarea>
  2770.             <p><input type="checkbox" name="sogl">
  2771.             <label class="longlab" style="display:block">Я ДАЮ СОГЛАСИЕ НА ПУБЛИКАЦИЮ ВОПРОСА НА САЙТЕ</label></p>
  2772.             <div style="clear:both"></div>
  2773.                
  2774.            <p> Все поля обязательны для заполнения</p>
  2775.             <input type="hidden" name="from_page" value="'.get_the_title().'" />
  2776.                        
  2777.             <input type="button" class="cancelbutton" value="отмена" style="float:right"  />
  2778.             <input type="submit" name="submit" value="Отправить" style="background:#a35ea0!important;float:right" />          
  2779.          </form>         
  2780.      </div>';
  2781.      
  2782.       return $sContactForm;
  2783.    }
  2784.    
  2785.    //-------------------------------------------------------------
  2786.    //             contact total form shortcode
  2787.    //-------------------------------------------------------------  
  2788.    public function totalcontactform_shortcode($atts, $content=null) {
  2789.    
  2790.       $default_atts = array('en'=>false ,'otdelid'=>'#otdel');
  2791.       extract(shortcode_atts($default_atts,$atts));  
  2792.    
  2793.       define ('DS',DIRECTORY_SEPARATOR);
  2794.       define('DEBUG', false);
  2795.       require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  2796.       $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  2797.       $sm->init();
  2798.      
  2799.       $forms_model = $sm->getModel('CFormsModel','cforms');
  2800.       $forms_model->setOrder('contactform_name');
  2801.       $departments = $forms_model->getPage(0,true);
  2802.       $departments = $departments['items'];
  2803.      
  2804.       $f = create_function('$a',' return ($a["show_q"]);');
  2805.       $departments = array_filter($departments, $f);
  2806.      
  2807.       $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  2808.              
  2809.       $contacts = $contacts_model->getPage(0,true);
  2810.       $contacts = $contacts['items'];
  2811.      
  2812.       $data_script ='';
  2813.       $repeats = array();    
  2814.       foreach ($contacts as $contact) {
  2815.          if (!in_array( $contact['contactform_contact_email'],$repeats)) {
  2816.             $data_script .= '\''.trim($contact['contactform_contact_email']).'\':'.$contact['contactform_contact_id'].',';
  2817.             array_push($repeats, $contact['contactform_contact_email']);
  2818.          }
  2819.       }
  2820.       $data_script = 'emails_ids ={'.$data_script.'}';
  2821.       $sContactsScript = '<script type="text/javascript">'.$data_script.'</script>';     
  2822.      
  2823.       $data_script = '';
  2824.       $dep_names = array();
  2825.       foreach ($departments as $department) {
  2826.          $id = $department['contactform_id'];
  2827.          $name = $en?$department['contactform_eng_name']:$department['contactform_name'];
  2828.          $dep_names[] = $name;
  2829.          $data_script .= '\''.$name.'\': {';
  2830.          $contacts_model->setFilterString('contactform_id='.$id,true);
  2831.          $contacts = $contacts_model->getPage(0,true);
  2832.          $contacts = $contacts['items'];
  2833.          foreach ($contacts as $contact) {
  2834.             $data_script .= '\''.strip_tags(trim($en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name'])).'\':\''.
  2835.             $contact['contactform_contact_email'].'\',';
  2836.          }
  2837.          $data_script .='},';
  2838.       }
  2839.       $data_script = '
  2840.       <script type="text/javascript">
  2841.       var structure = {'.$data_script.'}
  2842.       </script>';
  2843.              
  2844.       ob_start();    
  2845. ?>   
  2846. <script type="text/javascript">
  2847.  
  2848. (function($) {
  2849.     $(document).ready(function(){
  2850.  
  2851. $('<?php echo $otdelid; ?>').change(function(){
  2852.    
  2853.     $('<?php echo $otdelid; ?>coder').html('<option id="-1"><?php echo $en?'select specialist':'-выберите специалиста-'; ?></option>');
  2854.     console.log($('<?php echo $otdelid; ?>').val());
  2855.     for(var prop in structure[$('<?php echo $otdelid; ?>').val()])
  2856.         $('<?php echo $otdelid; ?>coder').append('<option value="'+prop+'">'+prop+'</option>');
  2857. });
  2858.  
  2859. $('<?php echo $otdelid; ?>coder').change(function (){
  2860.    
  2861.     var emailvr=structure[$('<?php echo $otdelid; ?>').val()][$('<?php echo $otdelid; ?>coder').val()];
  2862.     $('<?php echo $otdelid; ?>recipient_email').val(emailvr);
  2863.    
  2864.     var contact_id = emails_ids[emailvr];
  2865.     $('input[name="contact_id"]').val(contact_id);
  2866. });
  2867.  
  2868. }); })(jQuery)
  2869. </script>  
  2870. <?php  
  2871.       $form_script = ob_get_clean();
  2872.      
  2873.       ob_start();    
  2874.    
  2875.    if ($en):
  2876.  ?>
  2877.  
  2878.    <p>Use form below to ask our specialist the question you are interested in . We'll answer you in a few days.<br />
  2879. You'll receive your answer to the email you'll provide<br />
  2880. Question and Answer will also be published on site </p>
  2881. <p>&nbsp;</p>
  2882. <h2>Ask doctor</h2>
  2883.  
  2884.  <?php
  2885.  
  2886.  else:
  2887. ?>
  2888.  
  2889.   <p>Воспользуйтесь формой ниже, чтобы задать интересующий Вас <strong>вопрос</strong> нашему специалисту. В течение 1-2 дней мы ответим Вам.<br />
  2890. Ответ Вы получите на указанный Вами <strong>адрес электронной почты</strong>.<br />
  2891. Вопросы и ответы публикуются на сайте</p>
  2892. <p>&nbsp;</p>
  2893. <h2>Задайте вопрос специалисту</h2>
  2894. <?php
  2895. endif;
  2896. ?>
  2897.  
  2898. <div id="fields">
  2899. <div class="ajax_note"></div>
  2900.   <div class="wait_div">
  2901.            <p><?php echo $en? 'Processing, please wait...' :'Форма отправляется. Пожалуйста, подождите';?></p>
  2902.             <img src="<?php echo $this->plugin_url?>ajax-loader.gif" />        
  2903.          </div>
  2904. <form class="dk-contact-form" action=""><label><?php echo $en?'Enter your name':'Представьтесь'; ?><sup>*</sup></label>
  2905. <input id="sender_name" type="text" name="sender_name" value="" placeholder="<?php echo $en?'Enter your name':'Представьтесь'; ?>" />
  2906. <label>Введите Ваш E-Mail *</label><input class="nth_email" name="sender_email" type="text"
  2907. placeholder="<?php echo $en?'Enter your E-Mail':'Введите E-Mail';?>" />
  2908. <label><?php echo $en?'Department':'Отделение'; ?><sup>*</sup></label></p>
  2909. <select id="<?php echo substr($otdelid,1);  ?>" name="komu">
  2910. <option value="-1"><?php echo $en?'select department':'-выберите отделение-';?></option>
  2911.  
  2912. <?php
  2913.    foreach ($dep_names as $dep_name) {
  2914.       echo '<option value="'.$dep_name.'">'.$dep_name.'</option>';
  2915.    }
  2916. ?>
  2917. </select>
  2918. <p><label>ФИО врача <sup>*</sup></label></p>
  2919. <select id="<?php echo substr($otdelid,1); ?>coder" name="coder">
  2920.    <option id="-1"><?php echo $en?'select specialist':'-выберите специалиста-';?></option>
  2921. </select>
  2922. <input id="<?php echo substr($otdelid,1); ?>recipient_email" type="hidden" name="recipient_email" value="" />
  2923. <input type="hidden" name="contact_id" value="" />
  2924. <p>
  2925. <label>Вопрос <sup>*</sup></label><br />
  2926. <textarea cols="45" name="question" rows="10" placeholder="<?php echo $en?'Enter question':'Введите вопрос'; ?>"></textarea>
  2927. <p><input type="checkbox" name="sogl">
  2928.             <label class="longlab" style="display:block"><?php
  2929.             echo $en? 'I agree for my question to be published on site' :'Я ДАЮ СОГЛАСИЕ НА ПУБЛИКАЦИЮ ВОПРОСА НА САЙТЕ'; ?></label></p>
  2930.         <p style="clear:both"><?php
  2931.   echo $en?'all fields are required':'Все поля обязательны для заполнения';
  2932.  
  2933. ?></p>
  2934.  
  2935. <input type="hidden" name="from_page" value="<?php the_title(); ?>" />
  2936. <input class="btn" type="submit" name="submit" value="<?php echo $en?'Send':'Отправить';?>" />
  2937.     <input type="button" class="cancelbutton" value="<?php echo $en?'cancel':'отмена';?>" />
  2938. </p>
  2939. </form>
  2940. </div>
  2941.  
  2942. <?php  
  2943.  
  2944.    $form = ob_get_clean();
  2945.    return $sContactsScript.$data_script.$form_script.$form;
  2946.    }
  2947.    
  2948.    //------------------------------------------------------------
  2949.    //            eko contact form shortcode
  2950.    //------------------------------------------------------------
  2951.    public function ekocontactform_shortcode($atts, $content=null) {
  2952.    
  2953.       ob_start();
  2954. ?>
  2955.  
  2956. <div class="ajax_note" style="background:#fff;color:#f00;position:absolute"></div>
  2957.   <div class="wait_div">
  2958.            <p>Форма отправляется. Пожалуйста подождите</p>
  2959.             <img src="<?php echo $this->plugin_url?>ajax-loader.gif" />        
  2960.          </div>
  2961.     <form class="dk-contact-form">
  2962.              <div class="nth_slide_form_row">
  2963.                 <input class="nth_name" name="sender_name" type="text" placeholder="ПРЕДСТАВЬТЕСЬ" />
  2964.                 <input class="nth_phone" name="tel" type="text" placeholder="ВВЕДИТЕ ВАШ ТЕЛЕФОН" />
  2965.                 <input class="nth_email" name="sender_email" type="text" placeholder="ВВЕДИТЕ ВАШ E-MAIL" />
  2966.              </div>
  2967.              <div class="nth_slide_form_row">
  2968.                 <textarea class="nth_question" name="question"></textarea>
  2969.              </div>
  2970.              <div class="nth_submit_block">
  2971.                           <input type="hidden" name="recipient_email" value="sgoshovskaya@petrovkamed.ru" />
  2972.                           <input type="hidden" name="contact_id" value="10" />
  2973.                           <input type="hidden" name="from_page" value="<?php the_title() ?>" />
  2974.                 <input type="submit" class="nth_submit" value="ОТПРАВИТЬ" />
  2975.                              
  2976.  
  2977.              </div>
  2978.           </form>
  2979.  
  2980.  
  2981. <?php  
  2982.      $form = ob_get_clean();
  2983.      return $form;   
  2984.    }
  2985.    
  2986.    //------------------------------------------------------------
  2987.    //            landing contact form shortcode
  2988.    //------------------------------------------------------------  
  2989.    public function landingcontactform_shortcode($atts, $content=null) {
  2990.    
  2991.       $default_atts = array('block'=>'');
  2992.       extract(shortcode_atts($default_atts,$atts));
  2993.    
  2994.       ob_start();
  2995. ?>
  2996.            
  2997.     <div id="mrt_form_call" class="mrt_form mrt_form_hidden" <?php if ($block) echo 'data-block='.$block; ?> >
  2998.           <form name="mrt_form" class="dk-appointment-form">
  2999.  
  3000.          
  3001.             <div class="name_block">
  3002.                <label>Представьтесь*</label>
  3003.                <input type="text" name="name" placeholder="Ваше имя" />           
  3004.             </div>
  3005.            
  3006.             <div class="tel_block">
  3007.                <label>Введите телефон*</label>
  3008.                        <input type="text" name="tel" class="tel" placeholder="телефон"/>
  3009.             </div>
  3010.             <div class="hide_on_landing">
  3011.             Все поля обязательны для заполнения
  3012.             </div>
  3013.  
  3014.               <input type="hidden" name="komu" value="callcenter@petrovkamed.ru" />
  3015.               <input type="hidden" name="from_page" value="Заказ обратного звонка" />
  3016.               <input type="hidden" name="landing_antispam_field" class="landing_antispam_field" value="">
  3017.               <input type="hidden" name="ga_type" value="order-call" />
  3018.              
  3019.              <input type="hidden" name="department_id" value=1000 />
  3020.              <input type="hidden" name="department_name" value="call" />
  3021.  
  3022.             <input type="submit" name="submit" value="отправить" />
  3023.             <input type="button" class="cancelbutton" value="отмена" />
  3024.           </form>  
  3025.                
  3026.         </div>
  3027.  
  3028. <?php    
  3029.       $form = ob_get_clean();
  3030.       return $form;
  3031.    }
  3032.    
  3033.    //------------------------------------------------------------
  3034.    //            appointment form shortcode
  3035.    //------------------------------------------------------------
  3036.    public function appointmentform_shortcode($atts, $content=null) {
  3037.      
  3038.       $default_atts = array('type'=>'','block'=>'','eng'=>false,'alt'=>false);
  3039.       extract(shortcode_atts($default_atts,$atts));
  3040.      
  3041.       if ($type=='global') {
  3042.          define ('DS',DIRECTORY_SEPARATOR);
  3043.          define('DEBUG', false);
  3044.          
  3045.          require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  3046.          $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  3047.          $sm->init();
  3048.      
  3049.          $forms_model = $sm->getModel('CFormsModel','cforms');
  3050.          $forms_model->setOrder('contactform_name');
  3051.          $departments = $forms_model->getPage(0,true);
  3052.          $departments = $departments['items'];
  3053.                  
  3054.          $f = create_function('$a',' return ($a["show_q"]);');   
  3055.          $departments = array_filter($departments, $f);
  3056.          
  3057.          $data_script = '';
  3058.          foreach ($departments as $department) {
  3059.             $data_script .= '\''.trim($department['contactform_name']).'\':'.$department['contactform_id'].',';
  3060.          }
  3061.          $data_script = 'departments_ids ={'.$data_script.'}';
  3062.          $data_script = '<script type="text/javascript">'.$data_script.'</script>';
  3063.          echo $data_script;
  3064.       }
  3065.      
  3066.       ob_start();    
  3067. ?>
  3068.        
  3069.          <div class="mrt_form dk-appointment-form-container">
  3070.          <?php if ($alt): ?>
  3071.             <h3>ЗАПИСАТЬСЯ</h3>
  3072.             <h4><a href="tel:84959099909" class="mbphone"><span class="comagic_phone">8(495)909-9-909</span></a></h4>
  3073.             <h5><a href="javascript:" class="order_call2">Заказать обратный звонок</a></h5>
  3074.          
  3075.          <?php endif; ?>
  3076.           <form name="mrt_form" class="dk-appointment-form" <?php if ($block) echo 'data-block='.$block; ?> >
  3077.            
  3078.             <div class="name_block">
  3079.                <label>Представьтесь*</label>
  3080.                <input type="text" name="name" placeholder="<? echo $eng?'Input your name':'Ваше имя';?>" />             
  3081.             </div>
  3082.             <?php
  3083.            
  3084.             if ($type=='global') {
  3085.                echo '<div class="department_block"><select name="department_name">';
  3086.                echo '<option value="-1">'.($eng?'Select the Department':'-выберите отделение-').'</option>';
  3087.                foreach ($departments as $department) {
  3088.                   echo '<option value="'.($eng?$department['contactform_eng_name']:$department['contactform_name']).'">'.
  3089.                   ($eng?$department['contactform_eng_name']:$department['contactform_name']).'</option>';
  3090.                }
  3091.                echo '</select><input type="hidden" name="department_id"></div>';
  3092.                echo '<input type="hidden" name="ga_type" value="make-appointment-left" />';
  3093.             } else {
  3094.                echo '<input type="hidden" name="ga_type" value="make-appointment" />';
  3095.             }
  3096.            
  3097.             ?>
  3098.            
  3099.             <div class="email_block">
  3100.                <label>Введите E-Mail*</label>
  3101.                <input type="text" name="email" placeholder="<?php echo $eng?'Input your e-mail':'Введите e-mail';?> *"/>
  3102.             </div>
  3103.             <div class="tel_block">
  3104.                <label>Введите телефон</label>
  3105.                <input type="text" name="tel" class="tel" placeholder="<?php echo $eng?'Input your phone':'Телефон';?> "/>
  3106.             </div>
  3107.  
  3108.                         <div class="date_block">
  3109.                            <label>Дата записи</label>
  3110.                            <input type="text" name="date" class="datepicker"
  3111.                            placeholder="<?php echo $eng?'Select date':'Выберите дату';?>" autocomplete="off" />
  3112.                         </div>         
  3113.             <input type="hidden" name="komu" value="callcenter@petrovkamed.ru" />
  3114.             <input type="hidden" name="from_page" value="<?php echo get_the_title(); ?>" />
  3115.             <div class="hide_on_landing">
  3116.                <sup>*</sup> - <?php echo $eng?'required':'поля обязательные для заполнения'; ?>
  3117.             </div>
  3118.             <input type="button" class="cancelbutton" value="<?php echo $eng?'cancel':'отмена';?>" style="float:right"  />
  3119.             <input type="submit" name="submit" value="<?php echo $eng?'Send':'Отправить';?>" style="background:#a35ea0!important;float:right" />
  3120.            
  3121.             <div style="clear:both"></div>
  3122.            
  3123.             <input type="hidden" name="landing_antispam_field" class="landing_antispam_field" value="">
  3124.           </form>  
  3125.         </div>
  3126.  
  3127. <?php    
  3128.      
  3129.       $form = ob_get_clean();
  3130.       return $form;
  3131.    
  3132.    }
  3133.    
  3134.    //------------------------------------------------------------
  3135.    //            appointment eko 1 form shortcode
  3136.    //------------------------------------------------------------  
  3137.    public function appointmentform_eko1_shortcode($atts, $content=null) {
  3138.    
  3139.    ob_start();
  3140.    
  3141.    ?>
  3142.    <form class="dk-appointment-form">
  3143.             <div id="sevsf_arrow">
  3144.             </div>
  3145.            
  3146.             <div id="sevf_header" class="editable" data-post-meta="2800_sevf_header">
  3147.              МЫ ВМЕСТЕ С ВАМИ<br/>
  3148. ПРОЙДЕМ ПУТЬ К РОЖДЕНИЮ<br/>
  3149. ЗДОРОВОГО МАЛЫША<br/>
  3150.             </div>
  3151.            
  3152.             <div id="sevf_text" class="editable" data-post-meta="2900_sevf_text">
  3153.                 Доверяя свое репродуктивное здоровье<br/>
  3154. специалистам клиники ЭКО «Петровские<br/>
  3155. ворота» в Москве, Вы получаете<br/>
  3156. качественные услуги по диагностике и<br/>
  3157. лечению, и максимально высокий процент<br/>
  3158. положительного результата в ходе лечения.  
  3159.             </div>
  3160.            
  3161.             <div id="sevf_actual">
  3162.                <label class="sevf_common">
  3163.                   ЗАПИСАТЬСЯ НА ПРИЕМ
  3164.                </label>
  3165.                <div class="sevf_row">
  3166.                   <input class="sevf_name" type="text" name="name" placeholder="ПРЕДСТАВЬТЕСЬ *" />
  3167.                   <input class="sevf_phone" name="tel" type="text" placeholder="ВВЕДИТЕ ВАШ ТЕЛЕФОН" />
  3168.                </div>
  3169.                <div class="sevf_row">
  3170.                   <input class="sevf_email" type="text" name="email" placeholder="ВВЕДИТЕ ВАШ E-MAIL" />
  3171.                   <input class="sevf_date datepicker" type="text" name="date" placeholder="ДАТА И ВРЕМЯ" autocomplete="off" />
  3172.                </div>
  3173.                <div class="sevf_submit_block">
  3174.                               <input type="hidden" name="komu" value="msamoshina@petrovkamed.ru,dtimofeeva@petrovkamed.ru,callcenter@petrovkamed.ru" />
  3175.                               <input type="hidden" name="from_page" value="Центр ЭКО" />
  3176.                               <input type="hidden" name="ga_type" value="make-appointment" />
  3177.                               <input type="hidden" name="department_id" value=10 />
  3178.                               <input type="hidden" name="department_name" value="ЭКО" />
  3179.                                
  3180.                   <input type="submit" class="sevf_submit" value="ОТПРАВИТЬ" />
  3181.                </div>
  3182.             </div>
  3183.             <input type="hidden" name="landing_antispam_field" class="landing_antispam_field" value="" />
  3184.          </form>
  3185.    
  3186.    <?php
  3187.    
  3188.    $form = ob_get_clean();
  3189.    return $form;
  3190.    }
  3191.    
  3192.    //------------------------------------------------------------
  3193.    //            appointment eko 2 form shortcode
  3194.    //------------------------------------------------------------  
  3195.    public function appointmentform_eko2_shortcode($atts, $content=null) {
  3196.  
  3197.       ob_start();  
  3198.    ?>
  3199.    
  3200.    
  3201.  <form class="dk-appointment-form">
  3202.                <label class="sevf_common" style="margin:9px 0 9px 0">
  3203.                   ЗАПИСАТЬСЯ НА ПРИЕМ
  3204.                </label>
  3205.                <div class="sevf_row" style="float:left;width:50%">
  3206.                   <input class="sevf_name" type="text" name="name" placeholder="ПРЕДСТАВЬТЕСЬ *" />
  3207.                   <input class="sevf_phone" type="text" name="tel" placeholder="ВВЕДИТЕ ВАШ ТЕЛЕФОН" />
  3208.                </div>
  3209.                <div class="sevf_row" style="float:left;width:50%">
  3210.                   <input class="sevf_email" type="text" name="email" placeholder="ВВЕДИТЕ ВАШ E-MAIL" />
  3211.                   <input class="sevf_date datepicker" type="text" name="date" placeholder="ДАТА И ВРЕМЯ" autocomplete="off" />
  3212.                </div>
  3213.                <div style="clear:both"></div>
  3214.                <div class="sevf_submit_block">
  3215.                          <input type="hidden" name="komu" value="msamoshina@petrovkamed.ru,dtimofeeva@petrovkamed.ru,callcenter@petrovkamed.ru" />
  3216.                              <input type="hidden" name="from_page" value="Центр ЭКО" />
  3217.                              <input type="hidden" name="ga_type" value="make-appointment" />
  3218.                              <input type="hidden" name="department_id" value=10 />
  3219.                               <input type="hidden" name="department_name" value="ЭКО" />
  3220.                   <input type="submit" class="sevf_submit" value="ОТПРАВИТЬ" />
  3221.                            
  3222.                </div>  
  3223.                 <input type="hidden" name="landing_antispam_field" class="landing_antispam_field" value="">
  3224.                 </form>
  3225.                
  3226.    
  3227.    <?php
  3228.    
  3229.       $form = ob_get_clean();
  3230.       return $form;
  3231.    }
  3232.    
  3233.    //------------------------------------------------------------
  3234.    //                 otzyv full shortcode
  3235.    //------------------------------------------------------------    
  3236.    public function otzyvfull_shortcode($atts, $content=null) {
  3237.    
  3238.       $default_atts = array('id'=>0, 'landing'=>0);
  3239.       extract(shortcode_atts($default_atts,$atts));
  3240.    
  3241.       ob_start();
  3242.    ?>
  3243.     <div id="nth_slide_form<?php if (!$landing) echo "_inline"; ?>">
  3244.  
  3245.        <div class="wait_div" style="position:absolute;height:100%;width:100%;z-index:100;background:#000;opacity:0.5;display:none">
  3246.            <p>Форма отправляется. Пожалуйста подождите</p>
  3247.             <img style="position:absolute;top:50%;left:50%" src="<?php echo $this->plugin_url?>ajax-loader.gif"  />        
  3248.          </div>
  3249.  
  3250.           <div id="nth_slide_form_header<?php if (!$landing) echo "_inline"; ?>">
  3251.          Нам важно Ваше мнение!
  3252.           </div>
  3253.           <div id="nth_slide_form_text<?php if (!$landing) echo "_inline"; ?>">
  3254.          Если Вы хотите оставить свой отзыв или сообщение, пожалуйста, заполните следующую форму
  3255.           </div>
  3256.           <form class="dk-otzyv-form">
  3257.              <div class="nth_slide_form_row">
  3258.                 <input class="nth_name" name="name" type="text" placeholder="Представьтесь *" />
  3259.                 <input class="nth_phone" name="tel" type="text" placeholder="Введите Ваш телефон" />
  3260.                 <input class="nth_email" name="email" type="text" placeholder="Введите Ваш E-Mail *" />
  3261.              </div>
  3262.              <div class="nth_slide_form_row">
  3263.                 <textarea class="nth_question" name="otzyv" placeholder="Оставьте Ваш отзыв *"></textarea>
  3264.              </div>
  3265.              <div class="nth_submit_block<?php if (!$landing) echo "_inline"; ?>">
  3266.                             <input type="hidden" name="komu" value="callcenter@petrovkamed.ru,mkorneev@petrovkamed.ru,ydolnikova@petrovkamed.ru" />                            
  3267.                             <input type="hidden" name="from_page" value="<?php echo get_the_title(); ?>" />
  3268.                             <?php
  3269.                             if ($id) {
  3270.                                echo '<input type="hidden" name="contact_id" value='.$id.'/>';
  3271.                             }
  3272.                             ?>
  3273.                            
  3274.                     <div class="hide_on_landing">
  3275.                        <sup>*</sup> - поля обязательные для заполнения
  3276.                     </div>
  3277.                    
  3278.                 <input type="button" class="cancelbutton" value="<?php echo $eng?'cancel':'отмена'; ?>" style="float:right"  />
  3279.             <input type="submit" name="submit" class="nth_submit" value="Отправить" style="background:#a35ea0!important;float:right" />   
  3280.            
  3281.                              <input type="hidden" name="landing_antispam_field" id="landing_antispam_field" value="">
  3282.  
  3283.              </div>
  3284.           </form>
  3285.        </div>
  3286.  
  3287.    <?php
  3288.      
  3289.       $form = ob_get_clean();
  3290.       return $form;
  3291.    }
  3292.    
  3293.    //------------------------------------------------------------
  3294.    //                  smi shortcode
  3295.    //------------------------------------------------------------
  3296.    public function smi_shortcode($atts, $content=null) {
  3297.    
  3298.       $params = array('post_type'=>'dk_publication','orderby'=> 'meta_value',  
  3299.       'meta_key'=>'publication_date','order'=>'DESC', 'status'=>'publish', 'posts_per_page'=>50);    
  3300.    
  3301.       $q = new WP_Query($params);
  3302.       ob_start();    
  3303.      
  3304.       echo '<div class="bb-navigation">
  3305.       <a href="javascript:" id="bbfirsttop">Первая</a>
  3306.       <a href="javascript:" id="bbprevtop">Назад</a>
  3307.      <a href="javascript:" id="bbnexttop">Вперед</a>
  3308.       <a href="javascript:" id="bblasttop">Последняя</a>
  3309.       </div>';
  3310.      
  3311.       echo '<div id="bb-container"><div id="bb-bookblock" class="bb-bookblock">';    
  3312.       echo '<div class="bb-item">';
  3313.       $i=0;
  3314.       while ($q->have_posts()) {
  3315.      
  3316.          $q->the_post();
  3317.          
  3318.          $article_file = get_post_meta(get_the_ID(),'publication_file' ,true);
  3319.          $article_file = str_replace($_SERVER['DOCUMENT_ROOT'],'',$article_file);
  3320.          
  3321.          $article_date = get_post_meta(get_the_ID(),'publication_date', true);
  3322.          $article_header = get_the_title();
  3323.          $article_text = get_the_content();
  3324.          
  3325.          if (has_post_thumbnail(get_the_id())) {
  3326.             $tid = get_post_thumbnail_id(get_the_id());
  3327.             $article_image = reset(wp_get_attachment_image_src($tid,'full'));
  3328.          } else {
  3329.             $article_image ='';
  3330.          }
  3331.          
  3332.    
  3333.    ?>
  3334.    
  3335.    <div class="ether-cols ether-cols-2d3-2 smi-article">
  3336.     <div class="ether-col">
  3337.        <img src="<?php echo $article_image; ?>" alt="" class="ether-widget ether-img" style=" " />
  3338.     </div>
  3339.     <div class="ether-col"><br>
  3340.       <h2 class="dk_smi_h2"><?php echo $article_header ?></h2>
  3341.        <div style=""><p>
  3342.           <?php echo $article_text ?>
  3343.           </p>
  3344.        </div>
  3345.        <a href="<?php echo $article_file ?>" class="ether-widget ether-link" style="">Читать статью</a><br>
  3346.     </div>
  3347.   </div>
  3348.    
  3349.    <?php
  3350.          $i++;     
  3351.          if (($i%3)==0) {
  3352.             echo '</div><div class="bb-item">';
  3353.          }
  3354.    
  3355.       }
  3356.       wp_reset_query();
  3357.      
  3358.       echo '</div></div></div><div class="bb-navigation">
  3359.       <a href="javascript:" id="bbfirst">Первая</a>
  3360.       <a href="javascript:" id="bbprev">Назад</a>
  3361.      <a href="javascript:" id="bbnext">Вперед</a>
  3362.       <a href="javascript:" id="bblast">Последняя</a>
  3363.       </div>';   
  3364.      
  3365.       $info = ob_get_clean();
  3366.       return $info;
  3367.    }
  3368.    
  3369.    //------------------------------------------------------------
  3370.    //               otzyv list shortcode
  3371.    //------------------------------------------------------------
  3372.    public function otzyv_list_shortcode($atts, $content=null) {
  3373.    
  3374.       $default_atts = array('id'=>0, 'id2'=>0, 'id3'=>0, 'type'=>'');
  3375.       extract(shortcode_atts($default_atts,$atts));
  3376.      
  3377.       if ($id||$id2) {
  3378.      
  3379.          define ('DS',DIRECTORY_SEPARATOR);
  3380.          define('DEBUG', false);
  3381.          require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';    
  3382.          
  3383.          $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  3384.          $sm->init();    
  3385.          $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  3386.          $contacts_model->setFilterString('contactform_id='.$id, true);      
  3387.          if ($id2) {
  3388.             $contacts_model->setFilterString('contactform_contact_id='.$id2,true);
  3389.          }
  3390.          if ($id2 && $id3) {
  3391.             $contacts_model->setFilterString('(contactform_contact_id='.$id2.' or contactform_contact_id='.$id3.')',true);
  3392.          }
  3393.          $contacts = $contacts_model->getPage(0,true);
  3394.          $contacts = $contacts['items'];
  3395.              
  3396.          $contact_ids = array();     
  3397.          foreach ($contacts as $contact) {
  3398.             $contact_ids[] =$contact['contactform_contact_id'];        
  3399.          }
  3400.       }
  3401.      
  3402.       $params = array('post_type'=>'dk_review','orderby'=> 'meta_value',  
  3403.       'meta_key'=>'review_date','order'=>'DESC', 'status'=>'publish', 'posts_per_page'=>200);
  3404.      
  3405.       if ((isset($contact_ids)) && ($contact_ids)) {
  3406.          $params_meta = array('meta_query'=> array(array('key'=>'contact_id','value'=>$contact_ids,'compare'=>'IN')));
  3407.          $params = array_merge($params, $params_meta);       
  3408.       }
  3409.       //echo '<pre>'.print_r($params,true).'</pre>';
  3410.      
  3411.       $q = new WP_Query($params);
  3412.       ob_start();
  3413.      
  3414.        // echo '<div class="flexslider"><ul class="slides"><li>';      
  3415.       $i=0;
  3416.       while ($q->have_posts()) {
  3417.          $q->the_post();
  3418.          
  3419.          $otzyv_name = get_post_meta(get_the_id(), 'sender_name', true);
  3420.          $otzyv_name = str_replace('не указан','',$otzyv_name);
  3421.          
  3422.          if (!$type)
  3423.             $otzyv_name .= ($otzyv_name?', ':'');
  3424.            
  3425.          $otzyv_date = get_post_meta(get_the_id(), 'review_date', true);
  3426.          
  3427.          $otzyv_date = substr($otzyv_date,-2).'.'.substr($otzyv_date,4,2).'.'.substr($otzyv_date,0,4);
  3428.          $otzyv_text = get_the_content();
  3429.          
  3430.          /*if (!$i%5)
  3431.                echo '</li><li>';
  3432.             $i++;*/
  3433.          
  3434.          if ($type=='eko'):
  3435.          ?>
  3436.          
  3437.            <div class="elevs_list_item">
  3438.              <div class="elevs_date"><?php echo $otzyv_date; ?></div>
  3439.  
  3440.               <div class="elevs_item_header">
  3441.                  <?php echo $otzyv_name; ?>
  3442.               </div>
  3443.               <p>
  3444.                  <?php echo $otzyv_text; ?>
  3445.               </p>         
  3446.           </div>   
  3447.          
  3448.          <?php
  3449.          else:
  3450.          
  3451.          ?>
  3452.          <h5 class="dk_otzyv_h5"><?php echo $otzyv_name.$otzyv_date; ?></h5>
  3453.          <div class="dk_otzyv_contents">
  3454.          <p><?php echo $otzyv_text; ?></p>
  3455.          </div>
  3456.          
  3457.          <?php
  3458.          endif;
  3459.          
  3460.       }
  3461.       //echo '</li></ul></div>';
  3462.       wp_reset_query();
  3463.       $info = ob_get_clean();
  3464.       return $info;
  3465.    }     
  3466.    
  3467.    //------------------------------------------------------------
  3468.    //               pricelist shortcode
  3469.    //------------------------------------------------------------  
  3470.    public function pricelist_shortcode($atts, $content=null) {
  3471.    
  3472.       $default_atts = array ('id'=>0, 'id2'=>0, 'sub_id'=>0);
  3473.       extract( shortcode_atts( $default_atts, $atts));
  3474.      
  3475.       define ('DS',DIRECTORY_SEPARATOR);
  3476.      
  3477.       require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
  3478.        
  3479.       $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  3480.       $sm->init();
  3481.      
  3482.       $forms = $sm->getModel('CFormsModel','cforms');
  3483.       $form = $forms->getSingle($id);
  3484.       $form = $form['item'];
  3485.       $department_1c_id = $form['contactform_1c_id'];
  3486.      
  3487.       if ($id2) {            
  3488.          $form = $forms->getSingle($id2);
  3489.          $form = $form['item'];
  3490.          $department_1c_id2 = $form['contactform_1c_id'];
  3491.       }
  3492.      
  3493.       $prices = $sm->getModel('PriceListModel','xml_price_list');  
  3494.      
  3495.       if ($sub_id) {
  3496.          $subid_filter = ' and sub_id='.$sub_id;
  3497.       } else
  3498.          $subid_filter = '';
  3499.          
  3500.       if (!$id2) {  
  3501.          $prices->setFilterString('department_1c_id=\''.$department_1c_id.'\''.$subid_filter);
  3502.       } else {
  3503.           $prices->setFilterString(' (department_1c_id=\''.$department_1c_id.
  3504.           '\' or department_1c_id=\''.$department_1c_id2.'\') '.$subid_filter);
  3505.       }
  3506.      
  3507.       $prices->setOrder('pricelist_sort_order, department_1c_id, pricelist_id');
  3508.      
  3509.       $items = $prices->getPage(0,true);
  3510.      
  3511.       $items = $items['items'];
  3512.  
  3513.       ob_start();
  3514.       ?>
  3515.      
  3516.       <table class="tablepress">
  3517.       <thead>
  3518.          <tr class="row-1 odd">
  3519.             <th class="column-1"><div>Перечень услуг</div></th><th class="column-2"><div>Цены, руб.</div></th>
  3520.          </tr>
  3521.       </thead>
  3522.       <tbody class="row-hover">
  3523.      
  3524.      
  3525. <?php    
  3526.       $i=1;
  3527.       $chapter_name = '';
  3528.       foreach ($items as $item) {
  3529.          
  3530.          if ($item['chapter_name']!=$chapter_name) {
  3531.             $chapter_name = $item['chapter_name'];
  3532.             echo '<tr class="row-'.$i.' '.($i%2 ? 'odd' : 'even').'">';
  3533.             echo '<td class="column-1"><strong>'.$chapter_name.'</strong></td>';
  3534.             echo '<td class="column-2"></td>';
  3535.             echo '</tr>';
  3536.             $i++;
  3537.          }
  3538.          
  3539.          echo '<tr class="row-'.$i.' '.($i%2 ? 'odd' : 'even').'">';
  3540.          echo '<td class="column-1">'.$item['pricelist_1c_name'].'</td>';
  3541.          echo '<td class="column-2">'.str_replace('.',',',$item['pricelist_price']).'</td>';
  3542.          echo '</tr>';
  3543.          
  3544.          $i++;
  3545.       }
  3546.      
  3547.       ?>
  3548.       </tbody></table>
  3549. <?php    
  3550.      
  3551.       $s = ob_get_clean();
  3552.  
  3553.       return $s;
  3554.    }
  3555.    
  3556.    //------------------------------------------------------------
  3557.    //               doctors shortcode
  3558.    //------------------------------------------------------------      
  3559.    public function doctors_shortcode($atts, $content=null) {
  3560.    
  3561.       $default_atts = array ('id'=>0, 'en'=>false);
  3562.        extract( shortcode_atts( $default_atts, $atts));
  3563.      
  3564.       define ('DS',DIRECTORY_SEPARATOR);
  3565.       define('DEBUG', false);
  3566.       require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  3567.       $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  3568.       $sm->init();
  3569.       $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  3570.       $contacts_model->setFilterString(
  3571.           'contact_actual<>0 and contactform_contact_id in (select contactform_contact_id from dk_contacts_links where  '.
  3572.           ' contactform_id='.$id.')',true);
  3573.          
  3574.       $contacts_model->setOrder('contactform_contact_order');
  3575.       $contacts = $contacts_model->getPage(0,true);
  3576.       $contacts = $contacts['items'];
  3577.      
  3578.       ob_start();
  3579.       $i=0;
  3580.    ?>
  3581. <div class="doctors_list ether-content ether-toggle-content"><table width="0" border="0">
  3582. <?php
  3583.  
  3584.  foreach ($contacts as $contact) {
  3585.    if (!($i%3))
  3586.       echo '<tr>';
  3587. ?>
  3588.  
  3589. <td width="245" align="left" valign="top">
  3590. <p><a href="<?php echo $en?$contact['contactform_contact_eng_url']:$contact['contactform_contact_url']; ?>"><img src="<?php
  3591. echo $contact['contactform_contact_picture']?$contact['contactform_contact_picture']:'/wp-content/uploads/2014/09/shetinina.png'; ?>"
  3592. alt="<?php echo ($en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name']); ?>"></a>
  3593.  
  3594. <a href="<?php echo $en?$contact['contactform_contact_eng_url']:$contact['contactform_contact_url']; ?>"><div class="doctor_name">
  3595. <?php $dname = $en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name'];
  3596.       $dname = strip_tags(str_replace(array('<br/>','<br>'),array(' ',' '),$dname));
  3597.       $dname = substr($dname,0, strpos($dname,' ')).'<br/>'.substr($dname, strpos($dname,' '));
  3598.       echo $dname;
  3599. ?></div></a>
  3600.  
  3601. <div class="doctor_description">
  3602. <?php echo $en?$contact['contactform_contact_eng_description']:$contact['contactform_contact_description'];?>
  3603. </div>
  3604. </td>
  3605. <?php
  3606.      $i++;
  3607.       if (!($i%3)) {
  3608.          echo '</tr>';
  3609.       }
  3610.      
  3611.    }
  3612. ?>
  3613. </table> </div>  
  3614.    <?php    
  3615.    $s = ob_get_clean();
  3616.   return $s;  
  3617.    }
  3618.    
  3619.    //------------------------------------------------------------
  3620.    //               doctors shortcode full
  3621.    //------------------------------------------------------------    
  3622.    public function doctors_shortcode_full($atts, $content=null) {
  3623.    
  3624.          $default_atts = array ('en'=>false);
  3625.          extract( shortcode_atts( $default_atts, $atts));
  3626.    
  3627.          define ('DS',DIRECTORY_SEPARATOR);
  3628.          define('DEBUG', false);
  3629.          
  3630.          require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';        
  3631.          $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
  3632.          $sm->init();
  3633.      
  3634.          $forms_model = $sm->getModel('CFormsModel','cforms');
  3635.          $forms_model->setOrder('contactform_doctor_name');
  3636.          $forms_model->setFilterString('show_q<>0');
  3637.          
  3638.          $departments = $forms_model->getPage(0,true);
  3639.          $departments = $departments['items'];
  3640.          
  3641.        
  3642.          
  3643.          $f = create_function('$a',' return ($a["contactform_id"]!=11);');
  3644.          $departments = array_filter($departments, $f);
  3645.          
  3646.          $contacts_model = $sm->getModel('CContactsModel','ccontacts');
  3647.          $contacts_model->setOrder('contactform_contact_order');
  3648.          
  3649.          ob_start();
  3650.          
  3651.          ?>    
  3652. <div class="ether-widget ether-multi ether-multi-1 ether-type-acc ether-acc-x">      
  3653.         <?php
  3654.          foreach ($departments as $department) {
  3655.          
  3656.             $id = $department['contactform_id'];
  3657.             $name = $en?$department['contactform_eng_name']:$department['contactform_doctor_name'];
  3658.             ?>
  3659.            
  3660.             <h2 class="ether-title ether-toggle-button"><?php echo mb_strtoupper($name); ?></h2>
  3661.     <div class="ether-content ether-toggle-content doctors_list"><table width="0" border="0">
  3662.     <?php          
  3663.                  
  3664.           $contacts_model->setFilterString(
  3665.           'contact_actual<>0 and contactform_contact_id in (select contactform_contact_id from dk_contacts_links where  '.
  3666.           ' contactform_id='.$id.')',true);
  3667.          
  3668.             $contacts = $contacts_model->getPage(0,true);
  3669.             $contacts = $contacts['items'];
  3670.             $i=0;  
  3671.             if (!$contacts) {
  3672.                continue;
  3673.             }
  3674.             foreach ($contacts as $contact) {
  3675.                if (!($i%3))
  3676.                   echo '<tr>';
  3677. ?>
  3678.  
  3679. <td width="245" align="left" valign="top">
  3680. <p><a href="<?php echo $en?$contact['contactform_contact_eng_url']:$contact['contactform_contact_url']; ?>"><img src="<?php
  3681.    echo $contact['contactform_contact_picture']?$contact['contactform_contact_picture']:'/wp-content/uploads/2014/09/shetinina.png';
  3682.    
  3683.    ?>"
  3684.    
  3685. alt="<?php echo $en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name']; ?>"></a>
  3686. <a href="<?php echo $en?$contact['contactform_contact_eng_url']:$contact['contactform_contact_url']; ?>"><div class="doctor_name">
  3687. <?php
  3688.  
  3689.       $dname = $en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name'];
  3690.       $dname = strip_tags(str_replace(array('<br/>','<br>'),array(' ',' '),$dname));
  3691.       $dname = substr($dname,0, strpos($dname,' ')).'<br/>'.substr($dname, strpos($dname,' '));
  3692.       echo $dname;
  3693.      
  3694.       ?></div></a><div class="doctor_description">
  3695. <?php echo $en?$contact['contactform_contact_eng_description']:$contact['contactform_contact_description'];?>
  3696. </div></td>
  3697. <?php
  3698.               $i++;
  3699.                if (!($i%3)) {
  3700.                   echo '</tr>';
  3701.                }                           
  3702.             }
  3703.            
  3704.             ?> </table></div> <?php
  3705.          }
  3706.          ?> </div> <?php
  3707.          
  3708.          $content = ob_get_clean();
  3709.          return $content;
  3710.    }
  3711.    
  3712.    //---------------------------------------------------------
  3713.    //                  doctor content
  3714.    //---------------------------------------------------------
  3715.    public function doctor_content($content) {
  3716.    
  3717.       if (!is_single() && (!is_page())) {
  3718.          return $content;
  3719.       }
  3720.       global $post;
  3721.       $doctor_id = get_post_meta($post->ID, 'contactform_contact_id',true);
  3722.       if (!$doctor_id||$doctor_id<0)
  3723.          return $content;
  3724.    
  3725.       $doctor_id2 = get_post_meta($post->ID, 'contactform_contact_id2', true); 
  3726.      
  3727.       if (preg_match('/\[dk_doctor_content\]/ims',$content, $matches, PREG_OFFSET_CAPTURE)) {
  3728.      
  3729.          $pos = $matches[0][1];
  3730.          $len = 0;
  3731.          $len2 = strlen($matches[0][0]);
  3732.       } else {   
  3733.          if (!preg_match('/<img.*?>/ims', $content, $matches, PREG_OFFSET_CAPTURE)) {
  3734.             return $content;
  3735.          } else {
  3736.             $pos = $matches[0][1];
  3737.             $len = strlen($matches[0][0]);   
  3738.          }
  3739.      }
  3740.  
  3741.      
  3742.      $s ='<div class="doctor_control_block">';
  3743.      
  3744.      $s .= '<div class="ether-widget ether-multi ether-multi-1 ether-type-acc ether-acc-x">';
  3745.      $s .=  '<h2 class="ether-title ether-toggle-button" style="background:#a35ea0!important">Записаться на прием</h2>
  3746.     <div class="ether-content ether-toggle-content">';   
  3747.      $s .= $this->appointmentform_shortcode(array());
  3748.      $s .= '</div>';
  3749.      $s .=  '<h2 class="ether-title ether-toggle-button">Задать вопрос</h2>';
  3750.      
  3751.      $s .= '<div class="ether-content ether-toggle-content">';   
  3752.      $s .= $this->contactform_shortcode(array('id2'=>$doctor_id));
  3753.      $s .= '</div>';
  3754.      $s .=  '<h2 class="ether-title ether-toggle-button">Оставить отзыв</h2>
  3755.     <div class="ether-content ether-toggle-content">';   
  3756.      $s .= $this->otzyvfull_shortcode(array('id'=>$doctor_id));
  3757.      $s .= '</div></div>';   
  3758.      
  3759.      $s .= '<div class="doctor-otzyv-block">';
  3760.      $otzyvy = $this->otzyv_list_shortcode(array('id2'=>$doctor_id, 'id3'=>$doctor_id2));
  3761.      
  3762.      if ($otzyvy) {
  3763.         $s .= '<h3>Отзывы</h3>'.$otzyvy;
  3764.      }
  3765.      $s .= '</div>';
  3766.      
  3767.      $s .= '</div>';
  3768.      
  3769.      if (!$len2) {
  3770.         $len2 = $len;
  3771.      }
  3772.      $content = substr($content,0, $pos+$len).$s.substr($content,$pos+$len2);
  3773.      
  3774.      return $content;
  3775.      
  3776.    }
  3777.      
  3778.  
  3779. }
  3780.  
  3781.  
  3782.  
  3783. ?>
Add Comment
Please, Sign In to add comment