Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name:DK Contact Forms
- Plugin URI: http://dmkim1979.ru
- Description: Plugin allows to create contact forms
- Version: 1.1
- Author: Dmitriy Kim
- Author URI: http://dmkim1979.ru
- License: GPL2
- Copyright 2013. Dmitriy Kim (email : dmkim1979@gmail.com)
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 2, as
- published by the Free Software Foundation.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
- if (!class_exists('DKFactoryZ')) {
- class DKFactoryZ {
- public static function create($className, $DK_DEBUG=false) {
- if ($DK_DEBUG==true) {
- $DK_DEBUG_FILE = dirname(__FILE__).'/../debugdir/'.strtolower($className).'_debug.html';
- require_once dirname(__FILE__).'/../debugdir/debugger.php';
- $em = new DKEventManagerZ();
- $logger = new DKFileLoggerZ($DK_DEBUG_FILE);
- $em->addEventListener('*', $logger, 'write');
- dk_ContactForms::$class_proxy = new DKProxyZ($em);
- }
- $instance = new $className();
- return $instance;
- }
- }
- }
- $contact_forms = DKFactoryZ::create('dk_ContactForms',false);
- class dk_ContactForms {
- private $plugin_url;
- private $plugin_dir;
- private $options;
- private $dk_menu_suffix;
- static $class_proxy=null;
- private $proxy;
- private $shortcode_found = null;
- private $shortcode_total_found = null;
- private $shortcode_list_found = null;
- private $shortcode_appointment_found = null;
- private $shortcode_otzyv_full_found = null;
- private $shortcode_smi_found = null;
- private $service_email = 'petrovkasite@petrovkamed.ru';
- private $version = 7;
- public function __construct() {
- if (isset(self::$class_proxy)) {
- $this->proxy = self::$class_proxy;
- $this->proxy->set_proxy_object($this);
- } else {
- $this->proxy = $this;
- }
- $this->options = get_option('dk_contact_forms_options');
- $this->plugin_url = trailingslashit(WP_PLUGIN_URL.'/'.dirname(plugin_basename(__FILE__)));
- $this->plugin_dir = strtr(WP_PLUGIN_DIR,DIRECTORY_SEPARATOR,'/').'/'.
- dirname(plugin_basename(strtr(__FILE__, DIRECTORY_SEPARATOR,'/'))).'/';
- global $gl_plugin_dir;
- $gl_plugin_dir = $this->plugin_dir;
- add_action('activate_dk_contactforms/dk_contactforms.php',array($this->proxy,'install'));
- register_deactivation_hook(__FILE__, array($this->proxy,'uninstall'));
- add_action('init',array($this->proxy,'init'));
- add_action('admin_init',array($this->proxy,'admin_init'));
- add_action('admin_menu',array($this->proxy,'register_admin_menu'));
- add_action('wp_ajax_process_letter', array($this->proxy,'processLetter'));
- add_action('wp_ajax_nopriv_process_letter',array($this->proxy,'processLetter'));
- add_action('wp_ajax_process_appointment', array($this->proxy,'processAppointment'));
- add_action('wp_ajax_nopriv_process_appointment', array($this->proxy,'processAppointment'));
- add_action('wp_ajax_process_otzyv', array($this->proxy,'processOtzyv'));
- add_action('wp_ajax_nopriv_process_otzyv', array($this->proxy,'processOtzyv'));
- add_action('dk_event_check_mail', array($this->proxy, 'checkAnswers') );
- add_action('dk_event_check_mail', array($this->proxy, 'checkQ'));
- add_action('landing_head', array($this->proxy,'print_form_script_and_style'));
- add_action('admin_action_resend_qa_letter', array($this->proxy, 'resendLetter'));
- add_shortcode('dk_appointment_form', array($this->proxy,'appointmentform_shortcode'));
- }
- public function __call($cmd, $args) {
- }
- /*-------------------------------------------
- install plugin
- -------------------------------------------*/
- public function install() {
- if (!isset($this->options['version'])) {
- $this->upgrate_to_version_1();
- }
- $version = $this->options['version'];
- if ($version<2) {
- $this->upgrate_to_version_2();
- }
- if ($version<3) {
- $this->upgrate_to_version_3();
- }
- if ($version<5) {
- $this->upgrate_to_version_4();
- }
- if ($version<6) {
- $this->upgrate_to_version_5();
- }
- if ($version<7) {
- $this->upgrate_to_version_6();
- }
- $defaults = array('version'=>$this->version);
- add_option('dk_contact_forms_options', $defaults);
- wp_schedule_event(time(),'hourly','dk_event_check_mail');
- global $wpdb;
- $wpdb->show_errors();
- $_db = $wpdb;
- $contact_forms_table = 'dk_contact_forms';
- $contact_forms_contacts_table = 'dk_contact_forms_contacts';
- if ($_db->get_var("SHOW TABLES LIKE '". $contact_forms_table ."'") == $contact_forms_table)
- return;
- $sqls = array (
- "create table {$contact_forms_table} (
- contactform_id int(11) not null auto_increment,
- contactform_name varchar(50),
- primary key(`contactform_id`));",
- "create table {$contact_forms_contacts_table} (
- contactform_contact_id int(11) not null auto_increment,
- contactform_id int(11),
- contactform_contact_name varchar(200),
- contactform_contact_email varchar(200),
- primary key (`contactform_contact_id`));"
- );
- while (list($key,$sq)= each($sqls)) {
- $_db->query($sq);
- }
- }
- //-----------------------------------------
- private function upgrate_to_version_1() {
- global $wpdb;
- $wpdb->show_errors();
- $contact_forms_contacts_table = 'dk_contact_forms_contacts';
- $sqls = array (
- "alter table {$contact_forms_contacts_table}
- add column contactform_contact_description varchar(2000) after contactform_contact_email,
- add column contactform_contact_picture varchar(300) after contactform_contact_description");
- while (list($key,$sq) = each($sqls)) {
- $wpdb->query($sq);
- }
- }
- //-----------------------------------------
- private function upgrate_to_version_2() {
- global $wpdb;
- $wpdb->show_errors();
- $contact_forms_table = 'dk_contact_forms';
- $price_list_table = 'dk_price_list';
- $sqls = array (
- "alter table {$contact_forms_table}
- add column contactform_1c_id varchar(50) after contactform_name",
- "create table {$price_list_table} (
- pricelist_id int(11) not null auto_increment,
- pricelist_1c_id varchar(50),
- pricelist_1c_name varchar(2000),
- pricelist_price float,
- pricelist_sort_order int(11) default 0,
- department_1c_id varchar(50),
- department_1c_name varchar(500),
- primary key(`pricelist_id`));"
- );
- while (list($key,$sq) = each($sqls)) {
- $wpdb->query($sq);
- }
- }
- //-----------------------------------------
- private function upgrate_to_version_3() {
- global $wpdb;
- $wpdb->show_errors();
- $price_list_table = 'dk_price_list';
- $sqls = array ("alter table {$price_list_table}
- add column sub_id int(11) default 0 after department_1c_name");
- while (list($key,$sq) = each($sqls)) {
- $wpdb->query($sq);
- }
- }
- //-----------------------------------------
- private function upgrate_to_version_4() {
- global $wpdb;
- $wpdb->show_errors();
- $contact_forms_contacts_table = 'dk_contact_forms_contacts';
- $sqls = array("alter table $contact_forms_contacts_table ".
- "add column page_id int(11)");
- while (list($key,$sq) = each($sqls)) {
- $wpdb->query($sq);
- }
- }
- //-----------------------------------------
- private function upgrate_to_version_5() {
- global $wpdb;
- $wpdb->show_errors();
- $contact_forms_contacts_table = 'dk_contact_forms_contacts';
- $sqls = array("alter table $contact_forms_contacts_table ".
- "add column contactform_contact_url varchar(500)");
- while (list($key,$sq) = each($sqls)) {
- $wpdb->query($sq);
- }
- }
- //-----------------------------------------
- private function upgrate_to_version_6() {
- global $wpdb;
- $wpdb->show_errors();
- $contact_forms_table = 'dk_contact_forms';
- $sql = array ( "alter table $contact_forms_table ".
- " add column contactform_doctor_name varchar(100) ");
- while (list($key,$sq) = each($sqls)) {
- $wpdb->query($sq);
- }
- }
- //-----------------------------------------
- public function uninstall() {
- wp_clear_scheduled_hook('dk_event_check_mail');
- }
- /*-----------------------------------------------------
- init
- -----------------------------------------------------*/
- public function init() {
- add_shortcode('dk_contact_form', array($this->proxy, 'contactform_shortcode'));
- add_shortcode('dk_totalcontact_form', array($this->proxy,'totalcontactform_shortcode'));
- add_shortcode('dk_stub', array($this->proxy,'stub_shortcode'));
- add_shortcode('dk_qa_list', array($this->proxy,'qa_list_shortcode'));
- add_shortcode('dk_eko_contact_form', array($this->proxy,'ekocontactform_shortcode'));
- add_shortcode('dk_landing_contact_form',array($this->proxy,'landingcontactform_shortcode'));
- add_shortcode('dk_appointment_form_eko1', array($this->proxy,'appointmentform_eko1_shortcode'));
- add_shortcode('dk_appointment_form_eko2', array($this->proxy,'appointmentform_eko2_shortcode'));
- add_shortcode('dk_otzyv_full', array($this->proxy,'otzyvfull_shortcode'));
- add_shortcode('dk_smi', array($this->proxy,'smi_shortcode'));
- add_shortcode('dk_otzyv_list', array($this->proxy,'otzyv_list_shortcode'));
- add_shortcode('dk_pricelist',array($this->proxy,'pricelist_shortcode'));
- add_shortcode('dk_doctors', array($this->proxy, 'doctors_shortcode'));
- add_shortcode('dk_doctors_full', array($this->proxy,'doctors_shortcode_full'));
- add_shortcode('dk_doctors_ekolanding', array($this->proxy, 'doctors_shortcode_ekolanding'));
- $this->registerCustomPostTypes();
- $this->addQuestionsRole();
- if (!is_admin()) {
- add_action('wp_enqueue_scripts',array($this->proxy, 'load_form_script'));
- add_action('wp_print_styles', array($this->proxy, 'load_form_style'));
- add_action('wp_head', array($this->proxy, 'print_custom_styles'));
- add_action('wp_footer', array($this->proxy, 'print_footer_scripts'));
- add_filter('the_content', array($this->proxy,'doctor_content'), 1000);
- }
- add_action('admin_head', array($this->proxy,'custom_admin_scripts'));
- if (preg_match('/\/getContactForm/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_form_draw();
- exit();
- }
- if (preg_match('/\/getContactTotalForm/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_totalform_draw();
- exit();
- }
- if (preg_match('/\/getContactList/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_list_draw();
- exit();
- }
- if (preg_match('/\/processLetter/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_form_process();
- exit();
- }
- if (preg_match('/\/getOtzyvForm/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_otzyvform_draw();
- exit();
- }
- if (preg_match('/\/getOtzyvList/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_otzyvlist_draw();
- exit();
- }
- if (preg_match('/\/processOtzyv/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_otzyv_process();
- exit();
- }
- if (preg_match('/\/getAppointmentForm/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_appointmentform_draw();
- exit();
- }
- if (preg_match('/\/processAppointment/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_appointment_process();
- exit();
- }
- if (preg_match('/\/getDoctors/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_get_doctors();
- exit();
- }
- if (preg_match('/\/getFullDoctors/i', $_SERVER['REQUEST_URI'])) {
- $this->remote_get_doctors_full();
- exit();
- }
- if (preg_match('/\/waitfordoctor/i', $_SERVER['REQUEST_URI'])) {
- $this->questions_and_answers_single($_GET['post_id']);
- exit();
- }
- }
- //------------------------------------------------
- public function custom_admin_scripts() {
- $screen=get_current_screen();
- if ($screen->post_type!='dk_review')
- return;
- wp_register_style( 'datepicker-style', get_template_directory_uri().'/landing/css/lugo.datepicker.css', true);
- //wp_enqueue_style('datepicker-style');
- ?>
- <script type="text/javascript">
- jQuery(document).ready ( function () {
- //-------------------------------------------------
- // date picker
- //-------------------------------------------------
- jQuery.datepicker.regional['ru'] = {
- closeText: 'Закрыть',
- prevText: '<Пред',
- nextText: 'След>',
- currentText: 'Сегодня',
- monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
- 'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
- monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
- 'Июл','Авг','Сен','Окт','Ноя','Дек'],
- dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
- dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
- dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
- dateFormat: 'dd.mm.yy', firstDay: 1,
- isRTL: false};
- jQuery.datepicker.setDefaults(jQuery.datepicker.regional['ru']);
- jQuery('.datepicker').datepicker({
- dateFormat: "yymmdd"
- });
- });
- </script>
- <style type="text/css">
- .ui-datepicker {
- padding:10px;
- background:#fafafa;
- border:solid 1px #999;
- }
- </style>
- <?php
- }
- /*-----------------------------------------------------
- draw form for remote eko
- -----------------------------------------------------*/
- private function remote_form_draw() {
- $form = $this->contactform_shortcode(array('id'=>10,'type'=>'eko'));
- echo $form;
- }
- //------------------------------------
- private function remote_totalform_draw() {
- $form = $this->totalcontactform_shortcode(array('en'=>true));
- echo $form;
- }
- /*-----------------------------------------------------
- draw list for remote eko
- -----------------------------------------------------*/
- private function remote_list_draw() {
- $form = $this->qa_list_shortcode(array('id'=>10));
- echo $form;
- }
- //------------------------------------------- remote otzyv form
- private function remote_otzyvform_draw() {
- $form = $this->otzyvfull_shortcode(array());
- echo $form;
- }
- //------------------------------------------- remote otzyv list
- private function remote_otzyvlist_draw() {
- $list = $this->otzyv_list_shortcode(array('id'=>10,'type'=>'eko'));
- echo $list;
- }
- /*-----------------------------------------------------
- remote get doctors
- -----------------------------------------------------*/
- private function remote_get_doctors() {
- $list = $this->doctors_shortcode(array('id'=>$_GET['id'],'en'=>true));
- echo $list;
- }
- private function remote_get_doctors_full() {
- $list = $this->doctors_shortcode_full(array('en'=>true));
- echo $list;
- }
- /*-----------------------------------------------------
- remote form process
- -----------------------------------------------------*/
- private function remote_form_process() {
- $this->processLetter();
- }
- /*-----------------------------------------------------
- remote otzyv process
- -----------------------------------------------------*/
- private function remote_otzyv_process() {
- $this->processOtzyv(true);
- }
- /*-----------------------------------------------------
- remote appointment form draw
- -----------------------------------------------------*/
- private function remote_appointmentform_draw() {
- $type = isset($_GET['type'])?$_GET['type']:'';
- $eng = isset($_GET['eng'])?$_GET['eng']:false;
- $form = $this->appointmentform_shortcode(array('type'=>$type,'eng'=>$eng));
- echo $form;
- }
- //-------------------------------------------- remote appointment process
- private function remote_appointment_process() {
- $this->processAppointment(true);
- }
- /*-----------------------------------------------------
- register custom post types
- -----------------------------------------------------*/
- public function registerCustomPostTypes() {
- register_post_type('dk_question',
- array(
- 'label' => 'Questions',
- 'description' => '',
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true, //---- отображать в админке
- 'map_meta_cap' => false,
- 'capability_type' => 'question', //----- права доступа к типу записей
- 'capabilities' => array(
- 'publish_posts' => 'publish_questions',
- 'edit_posts' => 'edit_questions',
- 'edit_others_posts' => 'edit_others_questions',
- 'delete_posts' => 'delete_questions',
- 'delete_others_posts' => 'delete_others_questions',
- 'read_private_posts' => 'read_private_questions',
- 'edit_post' => 'edit_question',
- 'delete_post' => 'delete_question',
- 'read_post' => 'read_question',
- ),
- 'hierarchical' => true, //-------- поддержка древовидной структуры
- 'rewrite' => array('slug' => 'question'), //------ поддержка ЧПУ
- 'query_var' => true, //--------- использовать переменную question для запроса конкретной записи
- 'has_archive' => false, //--------- отключаем страницу архива по умолчанию
- 'exclude_from_search' => true,
- 'supports' => array('title','editor','comments','custom-fields','author','excerpt','page-attributes'),
- 'taxonomies' => array('category'),//---- использует спец.таксономию (при редактировании)
- 'labels' => array (
- 'name' => 'Questions',
- 'singular_name' => 'Question',
- 'menu_name' => 'Questions',
- 'add_new' => 'Add Question',
- 'add_new_item' => 'Add New Question',
- 'edit' => 'Edit',
- 'edit_item' => 'Edit Question',
- 'new_item' => 'New Question',
- 'view' => 'View Questions',
- 'view_item' => 'View Question',
- 'search_items' => 'Search Questions',
- 'not_found' => 'No Questions Found',
- 'not_found_in_trash' => 'No Questions Found in Trash',
- 'parent' => 'Parent Question'
- )
- )
- );
- //--------------------------------------- review
- register_post_type('dk_review',
- array(
- 'label' => 'Reviews',
- 'description' => '',
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true, //---- отображать в админке
- 'map_meta_cap' => false,
- 'capability_type' => 'review', //----- права доступа к типу записей
- 'capabilities' => array(
- 'publish_posts' => 'publish_reviews',
- 'edit_posts' => 'edit_reviews',
- 'edit_others_posts' => 'edit_others_reviews',
- 'delete_posts' => 'delete_reviews',
- 'delete_others_posts' => 'delete_others_reviews',
- 'read_private_posts' => 'read_private_reviews',
- 'edit_post' => 'edit_review',
- 'delete_post' => 'delete_review',
- 'read_post' => 'read_review',
- ),
- 'hierarchical' => true, //-------- поддержка древовидной структуры
- 'rewrite' => array('slug' => 'review'), //------ поддержка ЧПУ
- 'query_var' => true, //--------- использовать переменную question для запроса конкретной записи
- 'has_archive' => false, //--------- отключаем страницу архива по умолчанию
- 'exclude_from_search' => true,
- 'supports' => array('title','editor','comments','custom-fields','author','excerpt','page-attributes'),
- 'taxonomies' => array('category'),//---- использует спец.таксономию (при редактировании)
- 'labels' => array (
- 'name' => 'Reviews',
- 'singular_name' => 'Review',
- 'menu_name' => 'Reviews',
- 'add_new' => 'Add Review',
- 'add_new_item' => 'Add New Review',
- 'edit' => 'Edit',
- 'edit_item' => 'Edit Review',
- 'new_item' => 'New Review',
- 'view' => 'View Reviews',
- 'view_item' => 'View Review',
- 'search_items' => 'Search Reviews',
- 'not_found' => 'No Reviews Found',
- 'not_found_in_trash' => 'No Reviews Found in Trash',
- 'parent' => 'Parent Review'
- )
- )
- );
- //----------------------------------------------------------- smi
- register_post_type('dk_publication',
- array(
- 'label' => 'Publications',
- 'description' => '',
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true, //---- отображать в админке
- 'map_meta_cap' => false,
- 'capability_type' => 'publication', //----- права доступа к типу записей
- 'capabilities' => array(
- 'publish_posts' => 'publish_publications',
- 'edit_posts' => 'edit_publications',
- 'edit_others_posts' => 'edit_others_publications',
- 'delete_posts' => 'delete_publications',
- 'delete_others_posts' => 'delete_others_publications',
- 'read_private_posts' => 'read_private_publications',
- 'edit_post' => 'edit_publication',
- 'delete_post' => 'delete_publication',
- 'read_post' => 'read_publication',
- ),
- 'hierarchical' => true, //-------- поддержка древовидной структуры
- 'rewrite' => array('slug' => 'publication'), //------ поддержка ЧПУ
- 'query_var' => true, //--------- использовать переменную question для запроса конкретной записи
- 'has_archive' => false, //--------- отключаем страницу архива по умолчанию
- 'exclude_from_search' => true,
- 'supports' => array('title','editor','comments','custom-fields','author','excerpt','page-attributes','thumbnail'),
- 'taxonomies' => array('category'),//---- использует спец.таксономию (при редактировании)
- 'labels' => array (
- 'name' => 'Publications',
- 'singular_name' => 'Publications',
- 'menu_name' => 'Publications',
- 'add_new' => 'Add Publication',
- 'add_new_item' => 'Add New Publication',
- 'edit' => 'Edit',
- 'edit_item' => 'Edit Publication',
- 'new_item' => 'New Publication',
- 'view' => 'View Publications',
- 'view_item' => 'View Publication',
- 'search_items' => 'Search Publications',
- 'not_found' => 'No Publications Found',
- 'not_found_in_trash' => 'No Publications Found in Trash',
- 'parent' => 'Parent Publication'
- )
- )
- );
- }
- /*-----------------------------------------------------
- add questions role
- -----------------------------------------------------*/
- public function addQuestionsRole() {
- $result = add_role('question_author','Question Author',
- array(
- 'read'=>true,
- 'publish_questions'=>true,
- 'edit_questions'=>true,
- 'edit_question'=>true,
- 'read_question'=>true
- ));
- $role = get_role( 'administrator' );
- $role->add_cap('publish_questions');
- $role->add_cap( 'edit_questions');
- $role->add_cap('edit_others_questions');
- $role->add_cap('delete_questions');
- $role->add_cap('delete_others_questions');
- $role->add_cap('read_private_questions');
- $role->add_cap('edit_question');
- $role->add_cap('delete_question');
- $role->add_cap('read_question');
- $role->add_cap('publish_reviews');
- $role->add_cap('edit_reviews');
- $role->add_cap('edit_others_reviews');
- $role->add_cap('delete_reviews');
- $role->add_cap('delete_others_reviews');
- $role->add_cap('read_private_reviews');
- $role->add_cap('edit_review');
- $role->add_cap('delete_review');
- $role->add_cap('read_review');
- $role->add_cap('publish_publications');
- $role->add_cap('edit_publications');
- $role->add_cap('edit_others_publications');
- $role->add_cap('delete_publications');
- $role->add_cap('delete_others_publications');
- $role->add_cap('read_private_publications');
- $role->add_cap('edit_publication');
- $role->add_cap('delete_publication');
- $role->add_cap('read_publication');
- }
- /*-----------------------------------------------------------
- admin init
- -----------------------------------------------------------*/
- public function admin_init() {
- add_filter('pre_get_posts', array($this->proxy,'review_default_sort'));
- add_filter('manage_edit-dk_question_columns',array($this->proxy,'question_columns'));
- add_filter('manage_edit-dk_question_sortable_columns',array($this->proxy,'question_sortable_columns'));
- add_action('manage_dk_question_posts_custom_column',array($this->proxy,'fill_question_columns'));
- add_action('restrict_manage_posts',array($this->proxy, 'set_question_filters'));
- add_filter('pre_get_posts', array($this->proxy, 'handle_question_sorts'));
- add_filter('posts_where', array($this->proxy, 'handle_question_filters'));
- //------------------------------
- add_filter('manage_edit-dk_review_columns', array($this->proxy,'review_columns'));
- add_filter('manage_edit-dk_review_sortable_columns',array($this->proxy,'review_sortable_columns'));
- add_action('manage_dk_review_posts_custom_column', array($this->proxy,'fill_review_columns'));
- add_action('restrict_manage_posts', array($this->proxy,'set_review_filters'));
- add_filter('pre_get_posts',array($this->proxy,'handle_review_sorts'));
- add_filter('posts_where', array($this->proxy, 'handle_review_filters'));
- //-------------------------------
- add_action('add_meta_boxes', array($this->proxy, 'add_review_meta_boxes'));
- add_action('save_post', array($this->proxy,'save_review_meta'));
- add_action('post_edit_form_tag', array($this->proxy,'post_edit_form_tag'));
- }
- /*---------------------------------------------------------
- review default sort
- ---------------------------------------------------------*/
- public function review_default_sort($wp_query) {
- global $typenow;
- if ($typenow!='dk_review') {
- return;
- }
- $wp_query->set('orderby','review_date_sort');
- $wp_query->set('order','DESC');
- }
- /*---------------------------------------------------------
- question columns
- ---------------------------------------------------------*/
- public function question_columns($columns) {
- $next_arr = array(
- 'resend_letter' => 'Переслать письмо',
- 'sender_email' => 'Адрес пациента',
- 'form_name' => 'Отделение',
- 'contact_name' => 'Врач'
- );
- unset ($columns['author']);
- unset ($columns['categories']);
- unset ($columns['comments']);
- return $columns + $next_arr;
- }
- //-------------------------------------------
- public function question_sortable_columns($sortable_columns) {
- $new_columns = array(
- 'form_name' => 'form_name_sort'
- );
- return $sortable_columns + $new_columns;
- }
- /*---------------------------------------------------------
- fill question columns
- ---------------------------------------------------------*/
- public function fill_question_columns($column_name, $post_id=0) {
- global $post;
- switch ($column_name) {
- case 'sender_email': $s = get_post_meta($post->ID, 'sender_email', true); echo $s;break;
- case 'form_name': $s = get_post_meta($post->ID, 'form_name',true);echo $s;break;
- case 'contact_name': $s=get_post_meta($post->ID, 'contact_name',true);echo $s;break;
- case 'resend_letter':
- $action_name = 'resend_qa_letter';
- $action = '?action='.$action_name.'&post='.$post->ID;
- echo '<a href="'.admin_url('admin.php'.$action).'">send</a>';
- break;
- }
- }
- /*---------------------------------------------------------
- review columns
- ---------------------------------------------------------*/
- public function review_columns($columns) {
- $new_columns = array(
- 'contact_id' => 'Врач',
- 'review_date' => 'Дата отзыва'
- );
- unset($columns['author']);
- unset($columns['categories']);
- unset($columns['comments']);
- return $columns + $new_columns;
- }
- //-------------------
- public function review_sortable_columns($sortable_columns) {
- $new_columns = array(
- 'contact_id' => 'contact_id_sort',
- 'review_date' => 'review_date_sort'
- );
- return $sortable_columns + $new_columns;
- }
- /*---------------------------------------------------------
- fill review columns
- ---------------------------------------------------------*/
- public function fill_review_columns($column_name, $post_id=0) {
- global $post;
- switch ($column_name) {
- case 'contact_id':
- $contact_id = get_post_meta($post->ID,'contact_id',true);
- if (!$contact_id || $contact_id<0)
- break;
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contact = $contacts_model->getSingle($contact_id);
- $contact = $contact['item'];
- if (!$contact) {
- echo 'врач удален ('.$contact_id.')';
- } else {
- echo $contact['contactform_contact_name'];
- }
- break;
- case 'review_date': $s = get_post_meta($post->ID,'review_date',true);
- echo substr($s,6,2).'.'.substr($s,4,2).'.'.substr($s,0,4);
- break;
- }
- }
- /*---------------------------------------------------------
- set question filters
- ---------------------------------------------------------*/
- public function set_question_filters() {
- global $typenow;
- if ($typenow!='dk_question') {
- return;
- }
- $params = array (
- 'post_type'=>'dk_question',
- 'status'=>array('publish','draft'),
- 'meta_key'=>'form_id','posts_per_page'=>1000);
- $posts = get_posts($params);
- $sender_emails = array();
- $form_names = array();
- $contact_names = array();
- foreach ($posts as $post) {
- $id= $post->ID;
- $sender_email = get_post_meta($id,'sender_email',true);
- $form_name = get_post_meta($id,'form_name',true);
- $contact_name = get_post_meta($id, 'contact_name',true);
- $sender_emails[] = $sender_email;
- $form_names[] = $form_name;
- $contact_names[] = $contact_name;
- }
- $sender_emails = array_unique($sender_emails);
- $form_names = array_unique($form_names);
- $contact_names = array_unique($contact_names);
- echo '<select name="sender_filter" class="postform">';
- echo '<option value="0">Все отправители</option>';
- foreach ($sender_emails as $sender_email) {
- echo '<option value="'.$sender_email.'">'.$sender_email.'</option>';
- }
- echo '</select>';
- echo '<select name="form_filter" class="postform">';
- echo '<option value="0">Все отделения</option>';
- foreach ($form_names as $form_name) {
- echo '<option value="'.$form_name.'">'.$form_name.'</option>';
- }
- echo '</select>';
- echo '<select name="contact_filter" class="postform">';
- echo '<option value="0">Все врачи</option>';
- foreach ($contact_names as $contact_name) {
- echo '<option value="'.$contact_name.'">'.$contact_name.'</option>';
- }
- echo '</select>';
- }
- /*---------------------------------------------------------
- set review filters
- ---------------------------------------------------------*/
- public function set_review_filters() {
- global $typenow;
- if ($typenow!='dk_review')
- return;
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $params = array('post_type'=>'dk_review',
- 'status' => array ('publish','draft'),
- 'posts_per_page'=>1000);
- $posts = get_posts($params);
- $contact_array = array();
- foreach ($posts as $post) {
- $contact_id = get_post_meta($post->ID,'contact_id',true);
- if (!$contact_id || $contact_id<0) {
- continue;
- }
- if (array_key_exists($contact_id,$contact_array)) {
- continue;
- }
- $contact = $contacts_model->getSingle($contact_id);
- $contact = $contact['item'];
- if (!$contact) {
- $contact_name = 'врач удален ('.$contact_id.')';
- } else {
- $contact_name = $contact['contactform_contact_name'];
- }
- $contact_array[$contact_id] = $contact_name;
- }
- asort($contact_array);
- echo '<select name="contact_review_filter" class="postform">';
- echo '<option value="0">Все врачи</option>';
- foreach ($contact_array as $key=>$value) {
- echo '<option value='.$key.'>'.$value.'</option>';
- }
- echo '</select>';
- }
- /*---------------------------------------------------------
- handle question filters
- ---------------------------------------------------------*/
- public function handle_question_filters($where) {
- if (is_admin()) {
- global $wpdb;
- if ((isset($_GET['sender_filter'])) && ($_GET['sender_filter']!="0")) {
- $where .= " and ID in (select post_id from {$wpdb->postmeta} where meta_key='sender_email' and meta_value='{$_GET['sender_filter']}')";
- }
- if ((isset($_GET['form_filter'])) && ($_GET['form_filter']!="0")) {
- $where .= " and ID in (select post_id from {$wpdb->postmeta} where meta_key='form_name' and meta_value='{$_GET['form_filter']}')";
- }
- if ((isset($_GET['contact_filter'])) && ($_GET['contact_filter']!="0")) {
- $where .= " and ID in (select post_id from {$wpdb->postmeta} where meta_key='contact_name' and meta_value='{$_GET['contact_filter']}')";
- }
- }
- return $where;
- }
- /*---------------------------------------------------------
- handle review filters
- ---------------------------------------------------------*/
- public function handle_review_filters($where) {
- if (is_admin()) {
- global $wpdb;
- if (isset($_GET['contact_review_filter']) && ($_GET['contact_review_filter']!="0")) {
- $where .= " and ID in (select post_id from {$wpdb->postmeta} where meta_key='contact_id' and meta_value='{$_GET['contact_review_filter']}')";
- }
- }
- return $where;
- }
- /*---------------------------------------------------------
- handle question sorts
- ---------------------------------------------------------*/
- public function handle_question_sorts($wp_query) {
- if ($wp_query->get('orderby')=='form_name_sort') {
- $wp_query->set('meta_key','form_name');
- $wp_query->set('orderby','meta_value_num');
- }
- }
- /*---------------------------------------------------------
- handle review sorts
- ---------------------------------------------------------*/
- public function handle_review_sorts($wp_query) {
- if ($wp_query->get('orderby')=='contact_id_sort') {
- $wp_query->set('meta_key','contact_id');
- $wp_query->set('orderby','meta_value_num');
- }
- if ($wp_query->get('orderby')=='review_date_sort') {
- $wp_query->set('meta_key','review_date');
- $wp_query->set('orderby','meta_value_num');
- }
- }
- /*---------------------------------------------------------
- register admin menu
- ---------------------------------------------------------*/
- public function register_admin_menu() {
- $this->dk_menu_suffix = add_menu_page('Departments','Departments',
- 'activate_plugins','dk_contact_forms', array($this->proxy,'contact_forms_menu'));
- $this->dk_menu_suffix2 = add_submenu_page('dk_contact_forms', 'Doctors','Doctors',
- 'activate_plugins','dk_doctors_menu', array($this->proxy,'doctors_menu'));
- add_submenu_page('dk_contact_forms','Price List','Price List', 'activate_plugins', 'dk_price_list', array($this->proxy, 'price_list_menu'));
- $dk_menu_suffix3 = add_submenu_page('dk_contact_forms','DK Questions', 'DK Questions', 'activate_plugins', 'dk_questions_and_answers',
- array($this->proxy,'questions_and_answers'));
- add_submenu_page('dk_contact_forms', 'Utils', 'Utils', 'activate_plugins', 'dk_utils_page', array($this->proxy,'utils_page_menu'));
- add_action('admin_print_styles-'.$this->dk_menu_suffix, array($this->proxy,'load_admin_styles'));
- add_action('admin_print_styles-'.$this->dk_menu_suffix2, array($this->proxy,'load_admin_styles'));
- add_action('admin_print_styles-'.$dk_menu_suffix3, array($this->proxy,'load_admin_styles'));
- add_action('load-'.$this->dk_menu_suffix, array($this->proxy,'onload_menu_page'));
- }
- public function load_admin_styles() {
- wp_register_style('admin_style', $this->plugin_url.'assets/adminstyle.css');
- wp_enqueue_style('admin_style');
- }
- public function onload_menu_page() {
- add_action('admin_enqueue_scripts',array($this->proxy,'load_admin_scripts'));
- }
- public function load_admin_scripts() {
- wp_enqueue_script('admin_script',$this->plugin_url.'assets/adminscript.js', array('jquery'));
- }
- //---------------------------------------------------------
- // contacts forms menu
- //---------------------------------------------------------
- public function contact_forms_menu() {
- echo '<h3>Contact forms menu</h3>';
- require_once $this->plugin_dir.'simplemvc/bootstrap.php';
- }
- //-------------------------------------------- doctors menu
- public function doctors_menu() {
- echo '<h3>Doctors menu</h3>';
- if (!isset($_GET['ccontacts_action']))
- $_GET['ccontacts_action'] = 'index';
- require_once $this->plugin_dir.'simplemvc/bootstrap.php';
- }
- //-------------------------------------------- price list menu
- public function price_list_menu() {
- echo '<h3>Price list menu</h3>';
- if (!isset($_GET['pricelist_action']))
- $_GET['pricelist_action'] = 'index';
- require_once $this->plugin_dir.'simplemvc/bootstrap.php';
- }
- //---------------------------------------------------------
- // questions and answers menu
- //---------------------------------------------------------
- public function questions_and_answers() {
- if (isset($_POST['post_id'])) {
- $this->questions_and_answers_publish($_POST['post_id']);
- $this->questions_and_answers_list();
- } else {
- if (isset($_GET['post_id'])) {
- $this->questions_and_answers_single($_GET['post_id']);
- } else {
- $this->questions_and_answers_list();
- }
- }
- }
- //---------------------------------------------------------
- // questions and answers publish
- //---------------------------------------------------------
- private function questions_and_answers_publish($post_id) {
- $question_id = $_POST['post_id'];
- $answer_id = $_POST['answer_id'];
- //-----------------------------
- if (isset($_POST['submit'])) {
- $question_title = $_POST['question_title'];
- $question_content = $_POST['post_content'];
- $answer_title = $_POST['answer_title'];
- $answer_content = $_POST['post_content_answer'];
- wp_update_post( array(
- 'ID'=>$question_id,
- 'post_title'=>$question_title,
- 'post_content'=>$question_content,
- 'post_status'=>'publish'
- ));
- if ($answer_id) {
- wp_update_post( array(
- 'ID'=>$answer_id,
- 'post_title'=>$answer_title,
- 'post_content'=>$answer_content,
- 'post_status'=>'publish'
- ));
- }
- return;
- }
- //-----------------------------
- if (isset($_POST['archive'])) {
- $check = wp_set_post_categories($question_id, array(93));
- if ($answer_id) {
- wp_set_post_categories($answer_id, array(93));
- }
- return;
- }
- //-----------------------------
- if (isset($_POST['patientwarning'])) {
- $daystowait = $_POST['daystowait'];
- $question_content = $_POST['post_content'];
- $message ='К сожалению, в настоящий момент доктор не может ответить на ваш вопрос.
- Вы сможете получить ответ через '.$daystowait.' дней или Вы можете задать вопрос другому специалисту.<br/>'.
- '<a href="'.'http://petrovkamed.ru/waitfordoctor?post_id='.$question_id.'&doctorwarning=1">Ждать ответа</a><br/>'.
- '<a href="http://petrovkamed.ru/zadat-vopros-spetsialistu/">Задать вопрос другому специалисту</a><br/>'.
- str_repeat('-',50).'<br/>'.$question_content;
- $subject = 'Оповещение с сайта МЦ Петровские Ворота';
- $sender_email = $this->service_email;
- $recipient_email = get_post_meta($question_id, 'sender_email', true);
- $mail = $this->sendLetter($recipient_email, $sender_email, $message, $subject);
- return;
- }
- }
- //---------------------------------------------------------
- // questions and answers single
- //---------------------------------------------------------
- private function questions_and_answers_single($post_id) {
- if (isset($_GET['doctorwarning'])) {
- $this->resendLetter($post_id,
- 'Пользователь ожидает от Вас ответ на вопрос. Внимание! Ответить на вопрос пользователя в необходимо в первый рабочий день!');
- echo 'Оповещение врачу выслано. Ждите ответа в ближайшее время';
- return;
- }
- $title = get_the_title($post_id);
- $post_object = get_post($post_id);
- $post_content = $post_object->post_content;
- $answers = get_posts(array('post_type'=>'dk_question','post_parent'=>$post_id,
- 'posts_per_page'=>1000, 'post_status'=>array('draft','publish')));
- foreach ($answers as $answer) {
- setup_postdata($answer);
- $answer_id = $answer->ID;
- $title_answer = get_the_title($answer->ID);
- $post_content_answer = get_the_content();
- }
- $quicktags_settings = array('buttons'=>'b,i,ul,ol,li,link,close');
- $tinymce_settings = array(
- 'theme_advanced_buttons1' => 'link,|,bold,italic,underline,strikethrough,separator,blockquote,separator,bullist,numlist');
- $settings = array(
- 'media_buttons'=>false,
- 'textarea_name'=>'post_content',
- 'quicktags'=>$quicktags_settings,
- 'tinymce'=>$tinymce_settings,
- 'textarea_rows'=>15
- );
- if (isset($_GET['rerequest'])):
- $action_name = 'resend_qa_letter';
- $action = '?action='.$action_name.'&post='.$post_id;
- $send_link = '<a href="'.admin_url('admin.php'.$action).'">Оповестить врача</a>';
- ?>
- <form method="post" enctype="application/x-www-form-urlencoded">
- <h3>Вопрос остался без ответа</h3>
- <input type="text" size="100" name="question_title" value="<?php echo $title; ?>" /><br/>
- <textarea name="post_content" rows="30" cols="100" ><?php
- echo $post_content;
- ?></textarea><br/>
- <p>Пациенту подождать <input type="text" name="daystowait" value="3" /> дней</p>
- <input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
- <?php echo $send_link; ?>
- <input type="submit" name="patientwarning" value="Оповестить пациента" />
- </form>
- <?php
- else:
- ?>
- <form method="post" enctype="application/x-www-form-urlencoded">
- <h3>Вопрос</h3>
- <input type="text" size="100" name="question_title" value="<?php echo $title; ?>" />
- <?php wp_editor($post_content, 'post_content', $settings); ?>
- <h3>Ответ</h3>
- <input type="text" size="100" name="answer_title" value="<?php echo $title_answer; ?>" />
- <?php
- $settings['textarea_name'] = 'post_content_answer';
- wp_editor($post_content_answer,'post_content_answer', $settings); ?>
- <input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
- <input type="hidden" name="answer_id" value="<?php echo $answer_id; ?>" />
- <input type="submit" name="submit" value="опубликовать" />
- <input type="submit" name="archive" value="в архив" />
- </form>
- <?php
- endif;
- }
- //---------------------------------------------------------
- // questions and answers list
- //---------------------------------------------------------
- public function questions_and_answers_list() {
- $args = array('post_type'=>'dk_question', 'posts_per_page'=>1000,
- 'orderby'=>'date','order'=>'DESC','post_parent'=>0, 'post_status'=>array('draft','publish'));
- $q = new WP_Query($args);
- echo '<div class="dkqa_container">';
- while ($q->have_posts()) {
- $q->the_post();
- $post_cats = wp_get_post_categories(get_the_id());
- $post_deleted = in_array(93,$post_cats) ? 'deleted' : '';
- $action_name = 'resend_qa_letter';
- $action = '?action='.$action_name.'&post='.get_the_id();
- $send_link = '<a href="'.admin_url('admin.php'.$action).'">send</a>';
- $post_status = get_post_status();
- echo '<div class="dkqa_question '.$post_status.' '.$post_deleted.'">';
- echo '<div class="dkqa_date">'.get_the_date('d.m.Y',get_the_id()).'</div>'.
- '<div class="dkqa_form_name">'.get_post_meta(get_the_id(),'form_name',true).'</div>'.
- '<div class="dkqa_contact_name">'.get_post_meta(get_the_id(),'contact_name',true).' '.$send_link.'</div>'.
- '<div class="dkqa_title"><a href="'.admin_url('admin.php?page=dk_questions_and_answers&post_id='.get_the_id().'').
- '">'.get_the_title().'</a></div><div class="dkqa_excerpt">'.get_the_excerpt().'</div>'.
- '<div class="dkqa_sender_email">'.get_post_meta(get_the_id(),'sender_email',true).'</div>';
- echo '</div>';
- $posts = get_posts(array('post_type'=>'dk_question','post_parent'=>get_the_id(),
- 'posts_per_page'=>1000, 'post_status'=>array('draft','publish')));
- foreach ($posts as $post) {
- setup_postdata($post);
- $post_cats = wp_get_post_categories($post->ID);
- $post_deleted = in_array(93,$post_cats) ? 'deleted' : '';
- echo '<div class="dkqa_answer '.$post->post_status.'">';
- echo '<div class="dkqa_adate">'.date('d.m.Y',strtotime($post->post_date)).'</div>';
- echo '<div class="dkqa_aexcerpt"><a href="'.admin_url('post.php?post='.$post->ID.'&action=edit').
- '">'.get_the_excerpt().'</a></div>';
- echo '</div>';
- wp_reset_postdata();
- }
- }
- echo '</div>';
- }
- //---------------------------------------------------------
- // utils menu
- //---------------------------------------------------------
- public function utils_page_menu() {
- echo '<h3>Utils</h3>';
- if (isset($_POST['check_answers'])) {
- check_admin_referer('admin_csrf_prevention');
- $this->checkAnswers();
- }
- ?>
- <form action="<?php echo admin_url('admin.php?page=dk_utils_page'); ?>" method="post"
- enctype="application/x-www-form-urlencoded">
- <p>Запустить проверку и публикацию ответов врачей
- <?php wp_nonce_field('admin_csrf_prevention'); ?>
- <input type="submit" name="check_answers" value="OK" />
- </p>
- </form>
- <?php
- }
- //-------------------------------------------------------------
- // ajax process letter
- //-------------------------------------------------------------
- public function processLetter() {
- /*if (!check_ajax_referer('security','ajax_process_letter_referer',false)) {
- _e('Failed to verify ajax referer');
- exit();
- } */
- $sender_name = $_POST['sender_name'];
- $sender_email = $_POST['sender_email'];
- $question = $_POST['question'];
- $pub_consent = $_POST['sogl'];
- $eng = isset($_POST['eng']);
- $recipient_email = $_POST['recipient_email'];
- $error = '';
- if (!$sender_name) {
- $error .= $eng?'Input your name<br/>':'Введите Ваше имя<br/>';
- }
- if (!$sender_email) {
- $error .= $eng?'Input your e-mail<br/>':'Введите адрес электронной почты<br/>';
- } else
- if (!preg_match('/.+@.+/ims', $sender_email)) {
- $error .= $eng?'Input correct e-mail<br/>':'Введите корректный e-mail<br/>';
- }
- if (!$question) {
- $error .= $eng?'Input your question<br/>':'Введите вопрос<br/>';
- }
- if (!$_POST['contact_id']) {
- if (strstr($sender_email,'test@')) {
- $error .= $eng?'Current specialist is unavailable':'К сожалению задать вопрос этому специалисту в настоящий момент нельзя';
- } else {
- $error .= $eng?'Check the doctor please<br/>':'Выберите, пожалуйста, специалиста<br/>';
- }
- }
- if ($error) {
- echo '<div class="notification_error">'.$error.'</div>';
- exit();
- }
- if (isset($_POST['contact_id'])) {
- $contact_id = $_POST['contact_id'];
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contact = $contacts_model->getSingle($contact_id);
- $contact = $contact['item'];
- $form_id = $contact['contactform_id'];
- $contact_name = $contact['contactform_contact_name'];
- $contact_description = $contact['contactform_contact_description'];
- $contact_picture = $contact['contactform_contact_picture'];
- $forms_model = $sm->getModel('CFormsModel','cforms');
- $form = $forms_model->getSingle($form_id);
- $form = $form['item'];
- $form_name = $form['contactform_name'];
- $question_body = $question;
- $question_post = array (
- 'post_title' => $sender_name,
- 'post_content' => $question_body,
- 'post_status' => 'draft',
- 'post_type' => 'dk_question',
- 'post_author' => 1,
- );
- $pid = wp_insert_post($question_post);
- update_post_meta($pid, 'sender_email', $sender_email);
- update_post_meta($pid, 'form_id', $form_id);
- update_post_meta($pid, 'form_name',$form_name);
- update_post_meta($pid, 'contact_id', $contact_id);
- update_post_meta($pid, 'contact_name', $contact_name);
- update_post_meta($pid, 'contact_description', $contact_description);
- update_post_meta($pid, 'contact_picture', $contact_picture);
- update_post_meta($pid, 'date_arrival', date('d.m.Y'));
- update_post_meta($pid, 'pub_consent', $pub_consent);
- }
- $question_body = '<br/><br/>========== отвечайте пожалуйста над линией =========['.
- (isset($pid)?$pid:0).']==<br/><br/>'.$sender_name.'<br/>'.$question_body;
- if (stristr($recipient_email,'callcenter')) {
- $question_body .= '<br/>Отправлено со страницы '.$_POST['from_page'].'<br/>';
- }
- $sender_email = (isset($contact_id)) ? $this->service_email : $sender_email;
- $subject ="Вопрос С Сайта";
- $message = $question_body;
- $mail = $this->sendLetter($recipient_email, $sender_email, $message, $subject);
- if ($mail) {
- echo 'OK::'.$form_name.'::'.strip_tags($contact_name);
- exit();
- } else {
- echo 'error sending mail';
- exit();
- }
- }
- //-------------------------------------------------------------
- // ajax process appointment
- //-------------------------------------------------------------
- function processAppointment($noreferer = false) {
- if (!$noreferer) {
- if (!check_ajax_referer('security','ajax_appointment_referer',false)) {
- _e('failed to check ajax referer');
- exit();
- }
- }
- $name = htmlspecialchars($_POST["name"]);
- $email = htmlspecialchars($_POST["email"]);
- $from_page = $_POST['from_page'];
- $tel= htmlspecialchars($_POST['tel']);
- $date = htmlspecialchars($_POST['date']);
- $komu = $_POST["komu"];
- $eng = isset($_POST['eng']);
- //--------------------------------------
- $kei=$_POST["landing_antispam_field"];
- $error = '';
- if($kei!='1j73ch2ne1851') {
- $error .= $eng?'Enable javascript<br/>':"Включите поддержку javascript.<br />";
- }
- if(!$name) {
- $error .= $eng?'Input your name<br/>':"Пожалуйста, введите ваше имя.<br />";
- }
- if ((!$email) && (!$tel)) {
- $error .= $eng?'Input your phone or email<br/>':'Введите, пожалуйста, телефон<br/>';
- }
- if(!$email) {
- $email = 'system@petrovkamed.ru';
- }
- if (($email) && (!preg_match('/.+@.+/ims', $email))) {
- $error .= $eng?'Input correct e-mail<br/>':'Введите корректный e-mail<br/>';
- }
- //--------------------------------------------
- if(!$error) {
- if (isset($_POST['department_id'])) {
- $department_id = htmlspecialchars($_POST['department_id']);
- $department_name = htmlspecialchars($_POST['department_name']);
- }
- $subject ="Запись На Прием";
- $message ="<br/>E-mail: ".$email."<br/>Имя: " .$name."<br/>Телефон:".$tel."<br/>".
- '<br/>Отделение: '.$department_name.' ('.$department_id.')'.
- "<br/>Отправлено со страницы: ".$from_page."<br/>Дата записи на прием: ".$date;
- $mail = $this->sendLetter($komu, $email, $message, $subject);
- if ($mail) {
- echo 'OK:'.$department_name;
- } else {
- echo 'mail send error<br/>';
- }
- } else {
- echo '<div class="notification_error">'.$error.'</div>';
- }
- exit();
- }
- //-------------------------------------------------------------
- // ajax process otzyv
- //-------------------------------------------------------------
- public function processOtzyv($noreferer = false) {
- if (!$noreferer) {
- if (!check_ajax_referer('security','ajax_otzyv_referer',false)) {
- _e('Failed to verify ajax referer');
- exit();
- }
- }
- $kei=$_POST["landing_antispam_field"];
- $error = '';
- if($kei!='1j73ch2ne1851') {
- $error .= "Включите поддержку javascript.<br />";
- }
- $name = htmlspecialchars($_POST["name"]);
- $email = htmlspecialchars($_POST["email"]);
- $from_page = $_POST['from_page'];
- $tel= htmlspecialchars($_POST['tel']);
- $otzyv = htmlspecialchars($_POST['otzyv']);
- $pub_agree = $_POST['pub_agree'];
- $komu = $_POST['komu'];
- $contact_id = isset($_POST['contact_id'])? $_POST['contact_id'] : -1;
- $error = '';
- if(!$name) {
- $error .= "Пожалуйста, введите ваше имя.<br />";
- }
- if(!$email) {
- $error .= "Пожалуйста, введите e-mail.<br />";
- } else
- if (!preg_match('/.+@.+/ims', $email)) {
- $error .= 'Введите корректный e-mail<br/>';
- }
- if(!$error) {
- $review_post = array(
- 'post_title' => 'Отзыв '.$name.' ('.$email.')',
- 'post_content' => $otzyv,
- 'post_status' => 'draft',
- 'post_type' => 'dk_review',
- 'post_author' => 1
- );
- $pid = wp_insert_post($review_post);
- update_post_meta($pid,'sender_name',$name);
- update_post_meta($pid,'sender_email',$email);
- update_post_meta($pid,'sender_phone',$tel);
- update_post_meta($pid,'contact_id',$contact_id);
- update_post_meta($pid, 'review_date',date('Ymd'));
- $subject = 'Отзыв Пациента';
- $message ="<br/>E-mail: ".$email."<br/>Имя: " .$name."<br/>Телефон:".$tel."<br/>".
- "Отправлено со страницы: ".$from_page."<br/>".$pub_agree.'<br/>';
- $message .="<br/>Отзыв: ".$otzyv."<br/>";
- $mail = $this->sendLetter($komu, $email, $message, $subject);
- if($mail) {
- echo 'OK';
- } else {
- echo 'mail send error<br/>';
- }
- }
- else { echo '<div class="notification_error">'.$error.'</div>';
- }
- exit();
- }
- //-------------------------------------------------------------
- // review meta boxes
- //-------------------------------------------------------------
- public function add_review_meta_boxes() {
- add_meta_box('dk_doctor_meta_id', 'Doctor page',
- array($this->proxy,'doctorpage_meta_box'),'page','side','core');
- add_meta_box('dk_reviewcontact_meta_id', 'Review contact',
- array($this->proxy, 'reviewcontact_meta_box'), 'dk_review', 'side', 'core');
- add_meta_box('dk_reviewdate_meta_id', 'Review date',
- array($this->proxy,'reviewdate_meta_box'),'dk_review','side','core');
- add_meta_box('dk_publicationfile_meta_id', 'Publication file',
- array($this->proxy, 'publicationfile_meta_box'), 'dk_publication','side','core');
- add_meta_box('dk_publicationdate_id', 'Publication date',
- array($this->proxy,'publicationdate_meta_box'), 'dk_publication','side','core');
- }
- //-------------------------------------------------------------
- // doctor page meta box
- //-------------------------------------------------------------
- public function doctorpage_meta_box($post) {
- wp_nonce_field('qwerty','doctorpage_meta_nonce');
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contacts_model->setOrder('contactform_contact_name');
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- $current_contact = get_post_meta($post->ID,'contactform_contact_id',true);
- echo '<h4>Select doctor for page</h4><select name="doctor_id">';
- echo '<option value=-1>-выберите врача-</option>';
- $repeats = array();
- foreach ($contacts as $contact) {
- if (in_array(str_replace('<br/>',' ',$contact['contactform_contact_name']), $repeats))
- continue;
- echo '<option value='.$contact['contactform_contact_id'].' '.
- ($contact['contactform_contact_id']==$current_contact?'selected':'').' >'.
- str_replace('<br/>',' ',$contact['contactform_contact_name']).'</option>';
- array_push($repeats, str_replace('<br/>',' ',$contact['contactform_contact_name']));
- }
- echo '</select>';
- }
- //-------------------------------------------------------------
- // review contact meta box
- //-------------------------------------------------------------
- public function reviewcontact_meta_box($post) {
- wp_nonce_field('qwerty','reviewcontact_meta_nonce');
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contacts_model->setOrder('contactform_contact_name');
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- $current_contact = get_post_meta($post->ID,'contact_id',true);
- echo '<h4>Select Contact for Review</h4><select name="review_contact_id">';
- echo '<option value=-1>-выберите врача-</option>';
- $repeats = array();
- foreach ($contacts as $contact) {
- if (in_array(str_replace('<br/>',' ',$contact['contactform_contact_name']), $repeats))
- continue;
- echo '<option value='.$contact['contactform_contact_id'].' '.
- ($contact['contactform_contact_id']==$current_contact?'selected':'').' >'.
- str_replace('<br/>',' ',$contact['contactform_contact_name']).'</option>';
- array_push($repeats, str_replace('<br/>',' ',$contact['contactform_contact_name']));
- }
- echo '</select>';
- }
- //-------------------------------------------------------------
- // review date meta box
- //-------------------------------------------------------------
- public function reviewdate_meta_box($post) {
- wp_nonce_field('qwerty','reviewdate_meta_nonce');
- $current_date = get_post_meta($post->ID, 'review_date', true);
- echo '<h4>Select Date of Review</h4>';
- echo '<input type="text" name="review_date" value="'.$current_date.'" class="datepicker" />';
- }
- //-------------------------------------------------------------
- // publication file meta box
- //-------------------------------------------------------------
- public function publicationfile_meta_box($post) {
- wp_nonce_field('qwerty','publicationfile_meta_nonce');
- $publication_file = get_post_meta($post->ID, 'publication_file',true);
- echo '<h4>Upload publication file</h4>';
- echo '<p>'.$publication_file.'</p>';
- echo '<input type="file" name="pub_file" />';
- }
- //-------------------------- publication date meta box
- public function publicationdate_meta_box($post) {
- wp_nonce_field('qwerty','publicationdate_meta_nonce');
- $publication_date = get_post_meta($post->ID, 'publication_date', true);
- echo '<h4>Specify publication date</h4>';
- echo '<input type="text" name="publication_date" value="'.$publication_date.'" />';
- }
- //-------------------------------------------------------------
- // save meta
- //-------------------------------------------------------------
- public function save_review_meta($post_id) {
- $this->save_doctorpage($post_id);
- $this->save_reviewcontact($post_id);
- $this->save_reviewdate($post_id);
- $this->save_publicationfile($post_id);
- $this->save_publicationdate($post_id);
- }
- //-------------------------------------- save doctor page
- private function save_doctorpage($post_id) {
- if (!$this->check_nonce('doctorpage_meta_nonce','edit_review')) {
- return $post_id;
- }
- update_post_meta($post_id, 'contactform_contact_id', $_POST['doctor_id']);
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contacts_model->setOrder('contactform_contact_name');
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- $current_contact_id = $_POST['doctor_id'];
- foreach ($contacts as $contact) {
- if ($contact['contactform_contact_id']==$current_contact_id) {
- $tmp_name = strip_tags(str_replace(' ','',$contact['contactform_contact_name']));
- break;
- }
- }
- foreach ($contacts as $contact) {
- $tmp_name2 = strip_tags(str_replace(' ','',$contact['contactform_contact_name']));
- if (($tmp_name2 == $tmp_name) && ($current_contact_id!=$contact['contactform_contact_id'])) {
- update_post_meta($post_id,'contactform_contact_id2', $contact['contactform_contact_id']);
- break;
- }
- }
- }
- //-------------------------------------- save review contact
- private function save_reviewcontact($post_id) {
- if (!$this->check_nonce('reviewcontact_meta_nonce','edit_review')) {
- return $post_id;
- }
- update_post_meta($post_id, 'contact_id', $_POST['review_contact_id']);
- }
- //-------------------------------------- save review date
- private function save_reviewdate($post_id) {
- if (!$this->check_nonce('reviewdate_meta_nonce','edit_review')) {
- return $post_id;
- }
- update_post_meta($post_id, 'review_date', $_POST['review_date']);
- }
- //-------------------------------------- save publication file
- private function save_publicationfile($post_id) {
- if (!$this->check_nonce('publicationfile_meta_nonce','edit_publication'))
- return $post_id;
- if (isset($_FILES['pub_file'])) {
- $publication_file = $_FILES['pub_file'];
- if ($publication_file['error']!==0) {
- echo 'uploading error '.$publication_file['error'];
- } else {
- if (!file_exists($this->plugin_dir.'uploads')) {
- mkdir($this->plugin_dir.'uploads');
- }
- $path_parts = pathinfo($publication_file['name']);
- if (strtolower($path_parts['extension'])!='pdf') {
- echo 'Upload error: incorrect file type';
- } else {
- move_uploaded_file($publication_file['tmp_name'],
- $this->plugin_dir.'uploads/'.$publication_file['name']);
- update_post_meta($post_id, 'publication_file',
- $this->plugin_dir.'uploads/'.$publication_file['name']);
- }
- }
- }
- }
- //---------------------------------- save publication date
- private function save_publicationdate($post_id) {
- if (!$this->check_nonce('publicationdate_meta_nonce', 'edit_publication'))
- return $post_id;
- update_post_meta($post_id,'publication_date', $_POST['publication_date']);
- }
- //-------------------------- check nonce
- private function check_nonce($nonce_field, $capability) {
- if (!isset($_POST[$nonce_field])) {
- return false;
- }
- $nonce = $_POST[$nonce_field];
- if (!wp_verify_nonce($nonce,'qwerty')) {
- return false;
- }
- if ((defined('DOING_AUTOSAVE')) && DOING_AUTOSAVE) {
- return false;
- }
- if (!current_user_can($capability,$post_id)) {
- return false;
- }
- return true;
- }
- //-------------------------------------------------------------
- // post edit form tag
- //-------------------------------------------------------------
- function post_edit_form_tag() {
- echo 'enctype="multipart/form-data"';
- }
- //-------------------------------------------------------------
- // send letter
- //-------------------------------------------------------------
- private function sendLetter($komu, $sender, $message, $subject) {
- $mail_header = array( "MIME-Version"=>"1.0",
- "Content-type"=>" text/html; charset=windows-1251",
- "From"=>"<$sender>",
- "Reply-to"=>"<$sender>");
- /*$mail_header = "MIME-Version: 1.0\r\n";
- $mail_header .= "Content-type: text/html; charset=windows-1251\r\n";
- $mail_header .= "From: <$sender>\r\n";
- $mail_header .= "Reply-to: <$sender>\r\n";*/
- $subject2 = iconv ('UTF-8','windows-1251//IGNORE', $subject);
- $subject2 = '=?windows-1251?B?'.base64_encode($subject2).'?=';
- $message2 = iconv('UTF-8','windows-1251//IGNORE',$message);
- $mail = $this->mail_smtp($komu, $subject2, $message2, $mail_header);
- //$mail = mail($komu, $subject2, $message2, $mail_header);
- $this->sendControlLetter($subject2, $message2, $mail_header);
- return $mail;
- }
- //-------------------------------------------------------------
- // send control letter
- //-------------------------------------------------------------
- private function sendControlLetter($subject, $message, $mail_header) {
- $web_source =$_POST['web_source'];
- $web_medium =$_POST['web_medium'];
- $web_term = $_POST['web_term'];
- $web_content = $_POST['web_content'];
- $web_campaign = $_POST['web_campaign'];
- $time_initial_visit = $_POST['time_initial_visit'];
- $time_previous_visit = $_POST['time_previous_visit'];
- $time_current_visit = $_POST['time_current_visit'];
- $times_visited = $_POST['times_visited'];
- $raw_cookie = $_POST['raw_cookie'];
- $user_agent = $_POST['user_agent'];
- $message .= '<br/>Campaign source: '.$web_source.'<br/>'.
- 'Campaign name: '.$web_campaign.'<br/>'.
- 'Campaign medium: '.$web_medium.'<br/>'.
- 'Campaign content: '.$web_content.'<br/>'.
- 'Campaign term: '.$web_term.'<br/>'.
- 'Time of first visit: '.$time_initial_visit.'<br/>'.
- 'Time of previous visit: '.$time_previous_visit.'<br/>'.
- 'Time of current visit: '.$time_current_visit.'<br/>'.
- 'Times visited: '.$times_visited.'<br/><br/>'.
- 'Raw cookie: '.$raw_cookie.'<br/><cr/>'.$user_agent;
- $mail2 = $this->mail_smtp('dkim@petrovkamed.ru,ebykova@petrovkamed.ru',$subject, $message,$mail_header);
- //$mail2 = mail('dkim@petrovkamed.ru,ebykova@petrovkamed.ru',$subject, $message,$mail_header);
- }
- //-------------------------------------------------------------
- // re - send letter
- //-------------------------------------------------------------
- public function resendLetter($pid=0, $subject='') {
- if ((!$pid) && (!isset($_GET['post']))) {
- exit();
- }
- if (!$pid)
- $pid = $_GET['post'];
- else
- $noredirect =true;
- $sender_name = get_the_title($pid);
- global $post;
- $post = &get_post($pid);
- setup_postdata($post);
- $question_body = get_the_content();
- $sender_email = get_post_meta($pid, 'sender_email', true );
- $contact_id = get_post_meta($pid, 'contact_id', true);
- wp_reset_postdata($post);
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contact = $contacts_model->getSingle($contact_id);
- $contact = $contact['item'];
- $recipient_email = $contact['contactform_contact_email'];
- $question_body = '<br/><br/>========== отвечайте пожалуйста над линией =========['.
- (isset($pid)?$pid:0).']==<br/><br/>'.$sender_name.'<br/>'.$question_body;
- $sender_email = (isset($contact_id)) ? $this->service_email : $sender_email;
- if (!$subject)
- $subject ="Вопрос с сайта так и остался без Вашего ответа. Пожалуйста, ответьте на данное письмо";
- $message = $question_body;
- $mail = $this->sendLetter($recipient_email, $sender_email, $message, $subject);
- //wp_redirect( admin_url( 'edit.php?post_type='.$post->post_type) );
- if (empty($noredirect))
- wp_redirect(admin_url('admin.php?page=dk_questions_and_answers'));
- }
- //-------------------------------------------------------------
- // Mail SMTP
- //-------------------------------------------------------------
- private function mail_smtp($recipients, $subject, $message, $header) {
- set_include_path(get_include_path().PATH_SEPARATOR. getenv('DOCUMENT_ROOT').'/Mail'.PATH_SEPARATOR. getenv('DOCUMENT_ROOT').'/pear');
- require_once "Mail.php";
- $to = $recipients;
- $body = $message;
- $headers =array_merge($header, array(
- 'To' => $to,
- 'Subject' => $subject
- ));
- $smtp = Mail::factory('smtp', array(
- 'host' => 'ssl://smtp.gmail.com',
- 'port' => '465',
- 'auth' => true,
- 'username' => 'dmkim1979@gmail.com',
- 'password' => 'mds4pknv6zouszilvnm'
- ));
- /* $smtp = Mail::factory('smtp', array(
- 'host' => 'ssl://smtp.yandex.ru',
- 'port' => '465',
- 'auth' => true,
- 'username' => 'petrovkamedic@yandex.ru',
- 'password' => 'error100'
- ));*/
- $mail = $smtp->send($to, $headers, $body);
- if (PEAR::isError($mail)) {
- echo('<p>' . $mail->getMessage() . '</p>');
- } else {
- return true;
- }
- }
- //-------------------------------------------------------------
- // Check answers by scheduler
- //-------------------------------------------------------------
- public function checkAnswers() {
- $host = 'https://mail.petrovkamed.ru/WorldClient.dll';
- $url = $host.'?View=Main';
- $username =urlencode('petrovkasite@petrovkamed.ru');
- $password = '52/y2;1<1T';
- $postdata = 'User='.$username.'&'.
- 'Password='.$password.'&'.
- 'Lang='.'&'.'Theme=';
- $res_page = $this->send_request($url, $postdata);
- $header = $res_page['header'];
- preg_match_all("/Set-Cookie: (.*?)=(.*?);/i",$header,$res);
- $cookie='';
- foreach ($res[1] as $key => $value) {
- $cookie.= $value.'='.$res[2][$key].'; ';
- };
- $body = $res_page['body'];
- preg_match('/WorldClient\.dll\?Session=([^\']*?)&/ims',$body,$matches);
- $sessid = $matches[1];
- $inboxparams = 'View=List&ReturnJavaScript=1&FolderID=0&CurrentRequest=0&CurrentView=0&ContentType=javascript&UTF8=1';
- $inbox = $host.'?Session='.$sessid.'&'.$inboxparams;
- $res = $this->send_request($inbox, '', $cookie);
- $letters =json_decode($res['body']);
- $letters = $letters->scripts;
- $ids = array();
- foreach ($letters as $letter) {
- if (is_object($letter))
- $ids[] = $letter->id;
- }
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- $f = create_function('$a','return $a[\'contactform_contact_email\'];');
- $emails = array_map($f, $contacts);
- $i=0;
- foreach ($ids as $id) {
- $letter_param =
- 'View=Message&Preview=Yes&ReturnJavaScript=1&ChangeView=No&NoLoop=1&ContentType=JavaScript&Number='.$id.'&FolderID=0&CurrentRequest=0&_=1423491029292';
- $letter_body_request = $host.'?Session='.$sessid.'&'.$letter_param;
- $res = $this->send_request($letter_body_request,'',$cookie);
- $letter_body = json_decode($res['body']);
- $answer_author = $letter_body->message->from;
- $answer_body = $letter_body->message->body;
- preg_match('/==\[(\d+)\]==/i',$answer_body, $match, PREG_OFFSET_CAPTURE);
- if (!isset($match[1])) {
- continue;
- }
- $post_id = $match[1][0];
- $post = get_post($post_id, ARRAY_A);
- if (!$post)
- continue;
- $posts = get_posts(array('post_type'=>'dk_question','post_parent'=>$post_id, 'post_status'=>array('draft','publish')));
- if ($posts)
- break;
- $contact_id = get_post_meta($post_id, 'contact_id',true);
- $answer_author_id = $contact_id;
- $answer_author_name = get_post_meta($post_id, 'contact_name', true);
- $answer_author_description = get_post_meta($post_id, 'contact_description', true);
- $answer_author_picture = get_post_meta($post_id, 'contact_picture', true);
- $sender_email = get_post_meta($post_id, 'sender_email',true);
- $form_name = get_post_meta($post_id, 'form_name', true);
- preg_match('/.*?<(.*?)>/i', htmlspecialchars_decode($answer_author), $match2);
- if (isset($match2[1])) {
- $answer_author_email = $match2[1];
- $key = array_search($answer_author_email,$emails);
- if (($key!==false) && ($contacts[$key]['contactform_contact_id']!=$contact_id)) {
- $answer_author_id = $contacts[$key]['contactform_contact_id'];
- $answer_author_name = $contacts[$key]['contactform_contact_name'];
- $answer_author_description = $contacts[$key]['contactform_contact_description'];
- $answer_author_picture = $contacts[$key]['contactform_contact_picture'];
- }
- } else {
- $answer_author_email = $answer_author;
- }
- $answer_clear = substr($answer_body,0,$match[0][1]);
- preg_match('/===/i',$answer_clear, $match, PREG_OFFSET_CAPTURE);
- if (isset($match[0])) {
- $answer_clear = substr($answer_clear,0,$match[0][1]);
- }
- /*preg_match('/>\s*<[^>]*br[^>]*>\s*>/ims', $answer_clear, $match, PREG_OFFSET_CAPTURE);
- if (isset($match[0])) {
- $answer_clear = substr($answer_clear,0,$match[0][1]);
- }
- preg_match('/\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}/i',$answer_clear,$match, PREG_OFFSET_CAPTURE);
- if (isset($match[0])) {
- $answer_clear = substr($answer_clear,0,$match[0][1]);
- }*/
- $answer_clear = strip_tags($answer_clear,'<br>');
- $answer_clear = str_replace('>','',$answer_clear);
- $answer_clear = preg_replace('/\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}.*?<[^>]*br[^>]*>/ims','',$answer_clear);
- if (strpos($answer_clear,'From:')!==false) {
- $check_upper = substr($answer_clear, 0, strpos($answer_clear,'From:'));
- $check_upper = trim(strip_tags(str_replace(' ','',$check_upper)));
- if ($check_upper) {
- $answer_clear = $check_upper;
- } else {
- $qstr ='Subject: Вопрос С Сайта';
- $qpos = strpos($answer_clear, $qstr);
- $answer_clear = substr($answer_clear, $qpos+ strlen($qstr));
- }
- }
- //wp_update_post( array('ID'=>$post_id, 'post_status'=>'publish'));
- $answer_post = array (
- 'post_title' => 'Отвечает: '.$answer_author,
- 'post_content' => $answer_clear,
- 'post_status' => 'draft',
- 'post_type' => 'dk_question',
- 'post_author' => 1,
- 'post_parent' => $post_id );
- $pid = wp_insert_post($answer_post);
- if ($answer_author_id) {
- update_post_meta($pid,'contact_id',$answer_author_id);
- update_post_meta($pid,'contact_name',$answer_author_name);
- update_post_meta($pid,'contact_description',$answer_author_description);
- update_post_meta($pid,'contact_picture',$answer_author_picture);
- update_post_meta($pid,'sender_email', $sender_email);
- update_post_meta($pid,'form_name', $form_name);
- }
- echo 'inserted post number '.$pid.'<br/>';
- $sender_email = get_post_meta($post_id, 'sender_email', true);
- /*$mail_header = array("MIME-Version"=>"1.0",
- "Content-type"=>"text/html; charset=utf-8",
- "From"=>$answer_author_email,
- "Reply-to"=>$answer_author_email);*/
- $mail_header = array( "MIME-Version"=>"1.0",
- "Content-type"=>"text/html; charset=utf-8",
- "From" => $answer_author_email,
- "Reply-to"=>$answer_author_email);
- $subject ="Вопрос С Сайта: Отвечает ".$answer_author;
- $message = $answer_clear;
- $mail = $this->mail_smtp($sender_email, $subject, $message, $mail_header);
- $mail2 = $this->mail_smtp(
- 'dkim@petrovkamed.ru,ebykova@petrovkamed.ru,susoltseva@petrovkamed.ru',
- $subject, $message.
- '<a href="http://petrovkamed.ru/wp-admin/admin.php?page=dk_questions_and_answers&post_id='.
- $post_id.'">Отреагировать</a>',
- $mail_header);
- $i++;
- if ($i>50)
- break;
- }
- }
- //-------------------------------------------------------------
- // check unanswered questions on schedule
- //-------------------------------------------------------------
- public function checkQ() {
- $yesterday = getdate(strtotime("-1 day"));
- $args = array(
- 'post_type'=>'dk_question',
- 'post_status'=>'draft',
- 'posts_per_page'=>100,
- 'post_parent'=>0,
- 'date_query'=> array(
- array(
- 'year'=>$yesterday['year'],
- 'month'=>$yesterday['mon'],
- 'day'=>$yesterday['mday']
- )
- ),
- 'tax_query'=> array(
- array(
- 'taxonomy'=>'category',
- 'field'=>'term_id',
- 'terms'=> array(93),
- 'operator'=>'NOT IN'
- )
- ),
- 'meta_query'=> array(
- array(
- 'key'=>'warning_sent',
- 'value'=>array(1),
- 'compare'=>'NOT IN'
- )
- )
- );
- $q = new WP_Query($args);
- while ($q->have_posts()) {
- $q->the_post();
- $sender_name = get_the_title();
- $question_body = get_the_content();
- $sender_email = get_post_meta(get_the_id(), 'sender_email', true );
- $contact_id = get_post_meta(get_the_id(), 'contact_id', true);
- $question_body = '<br/><br/>'.$sender_name.'<br/>'.$question_body.'<br/><br/>'.
- '<a href="'.admin_url('admin.php?page=dk_questions_and_answers&rerequest&post_id='.get_the_id()).'">Отреагировать</a>';
- $sender_email = $this->service_email;
- $subject = "Неотвеченный вопрос на сайте";
- $message = $question_body;
- $mail = $this->sendLetter(
- 'dkim@petrovkamed.ru,ebykova@petrovkamed.ru,susoltseva@petrovkamed.ru',
- $sender_email, $message, $subject);
- update_post_meta(get_the_id(),'warning_sent',1);
- }
- }
- //-------------------------------------------------------------
- // request to mail server
- //-------------------------------------------------------------
- private function send_request($url, $postdata='', $cookie='') {
- $header = array(
- 'Content-type: application/x-www-form-urlencoded'
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
- curl_setopt($ch, CURLOPT_USERAGENT,
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
- //curl_setopt($ch, CURLOPT_ENCODING,1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- if ($postdata) {
- curl_setopt($ch, CURLOPT_POST,1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
- }
- if ($cookie) {
- curl_setopt($ch, CURLOPT_COOKIE, $cookie);
- }
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- $verbose = fopen('php://temp','rw+');
- curl_setopt($ch, CURLOPT_STDERR, $verbose);
- $result = curl_exec($ch);
- if (curl_errno($ch)) {
- throw new Exception(curl_error($ch));
- }
- rewind($verbose);
- $verboselog = stream_get_contents($verbose);
- $verboselog = htmlspecialchars($verboselog);
- $header=substr($result,0,curl_getinfo($ch,CURLINFO_HEADER_SIZE));
- $body=substr($result,curl_getinfo($ch,CURLINFO_HEADER_SIZE));
- curl_close($ch);
- return array('header'=>$header, 'body'=>$body, 'log'=>$verboselog);
- }
- //-------------------------------------------------------------
- // check if scripts needed
- //-------------------------------------------------------------
- private function scriptNeeded(&$shortcode_found_var, $shortcode_name ) {
- if (isset($shortcode_found_var))
- return $shortcode_found_var;
- $shortcode_found_var = false;
- if ((!is_single()) && (!is_page())) {
- return false;
- }
- if (have_posts()) {
- while (have_posts()) {
- the_post();
- $post = get_post(get_the_id());
- $content = $post->post_content;
- if (stripos($content,$shortcode_name)!==false) {
- $shortcode_found_var = true;
- break;
- }
- $info = serialize(get_post_meta(get_the_id(),'ether_builder_data',true));
- if (stripos($info, $shortcode_name)!==false) {
- $shortcode_found_var = true;
- break;
- }
- }
- }
- rewind_posts();
- return $shortcode_found_var;
- }
- //-------------------------------------------------------------
- // load form script
- //-------------------------------------------------------------
- public function load_form_script() {
- global $post;
- $doctor_id = get_post_meta($post->ID,'contactform_contact_id',true);
- if (($this->scriptNeeded($this->shortcode_found,'[dk_contact_form')) ||
- ($this->scriptNeeded($this->shortcode_total_found,'[dk_totalcontact_form')) || ($doctor_id) || (5==5) ) {
- wp_enqueue_script('mask_edit', $this->plugin_url.'assets/jquery.maskedinput.js', array('jquery'));
- wp_enqueue_script('form_script', $this->plugin_url.'assets/formscript.js',array('jquery'));
- $ajax_nonce = wp_create_nonce('security');
- wp_localize_script('form_script', 'f_options',
- array(
- 'ajax_url'=>admin_url('admin-ajax.php',(is_ssl()? 'https':'http')),
- 'ajax_nonce'=>$ajax_nonce));
- }
- if ($this->scriptNeeded($this->shortcode_appointment_found,'[dk_appointment_form') || (5==5) || ($doctor_id)) {
- wp_enqueue_script('mask_edit', $this->plugin_url.'assets/jquery.maskedinput.js', array('jquery'));
- wp_enqueue_script('appointment_script', $this->plugin_url.'assets/apposcript.js',array('jquery_ui'));
- $ajax_appo_nonce = wp_create_nonce('security');
- wp_localize_script('appointment_script', 'appo_options',
- array( 'ajax_url'=>admin_url('admin-ajax.php',(is_ssl()?'https':'http')),
- 'ajax_nonce'=>$ajax_appo_nonce));
- }
- if ($this->scriptNeeded($this->shortcode_otzyv_full_found,'[dk_otzyv_full') || ($doctor_id)) {
- wp_enqueue_script('otzyv_script', $this->plugin_url.'assets/otzyvscript.js',array('jquery'));
- $ajax_otzyv_nonce = wp_create_nonce('security');
- wp_localize_script('otzyv_script', 'otzyv_options',
- array('ajax_url'=>admin_url('admin-ajax.php',(is_ssl()?'https':'http')),'ajax_nonce'=>$ajax_otzyv_nonce));
- }
- if ($this->scriptNeeded($this->shortcode_smi_found,'[dk_smi')) {
- wp_enqueue_script('modernizr_custom', $this->plugin_url.'assets/modernizr.custom.js', array('jquery'));
- wp_enqueue_script('book_block', $this->plugin_url.'assets/jquery.bookblock.js', array('jquery','modernizr_custom'));
- }
- if ($doctor_id) {
- wp_enqueue_script('ether-builder', plugins_url('ether-builder/media/scripts/ether-builder.js'), array('jquery'));
- }
- }
- //-------------------------------------------------------------
- // load form style
- //-------------------------------------------------------------
- public function load_form_style() {
- if (($this->scriptNeeded($this->shortcode_found,'[dk_contact_form')) ||
- ($this->scriptNeeded($this->shortcode_total_found,'[dk_totalcontact_form'))) {
- wp_register_style('form_style',plugins_url('/assets/formstyle.css',__FILE__));
- wp_enqueue_style('form_style');
- }
- if ($this->scriptNeeded($this->shortcode_list_found,'[dk_qa_list')) {
- wp_register_style('list_style', $this->plugin_url.'assets/liststyle.css');
- wp_enqueue_style('list_style');
- }
- if ($this->scriptNeeded($this->shortcode_appointment_found,'[dk_appointment_form') || (5==5)) {
- wp_register_style('appo_style', $this->plugin_url.'assets/appostyle.css');
- wp_enqueue_style('appo_style');
- }
- if ($this->scriptNeeded($this->shortcode_smi_found, '[dk_smi')) {
- wp_register_style('book_style', $this->plugin_url.'assets/bookblock.css');
- wp_enqueue_style('book_style');
- }
- global $post;
- $doctor_id = get_post_meta($post->ID,'contactform_contact_id',true);
- if ($doctor_id) {
- wp_register_style('ether-builder-style', plugins_url('ether-builder/media/stylesheets/ether-builder-light.css'));
- wp_enqueue_style('ether-builder-style');
- }
- }
- //-------------------------------------------------------------
- // print form script and style on landing
- //-------------------------------------------------------------
- public function print_form_script_and_style() {
- $ajax_nonce = wp_create_nonce('security');
- echo '<script type="text/javascript" src="'.$this->plugin_url.'assets/jquery.maskedinput.js"></script>';
- echo '<script type="text/javascript" src="'.$this->plugin_url.'assets/formscript.js'.'"></script>';
- echo '<link rel="stylesheet" type="text/css" media="all" href="'.$this->plugin_url.'assets/formstyle.css" />';
- echo '<script type="text/javascript">
- var f_options = {
- ajax_url:"'.admin_url('admin-ajax.php',(is_ssl()? 'https':'http')).'",
- ajax_nonce:"'.$ajax_nonce.'"};
- </script>';
- echo '<script type="text/javascript" src="'.$this->plugin_url.'assets/apposcript.js"></script>';
- //echo '<link rel="stylesheet" type="text/css" media="all" href="'.$this->plugin_url.'assets/appostyle.css" />';
- echo '<script type="text/javascript">
- var appo_options = {
- ajax_url:"'.admin_url('admin-ajax.php',(is_ssl()?'https':'http')).'",
- ajax_nonce:"'.$ajax_nonce.'"};
- </script>';
- echo '<script type="text/javascript" src="'.$this->plugin_url.'assets/otzyvscript.js"></script>';
- echo '<script type="text/javascript">
- var otzyv_options = {
- ajax_url:"'.admin_url('admin-ajax.php', (is_ssl()?'https':'http')).'",
- ajax_nonce:"'.$ajax_nonce.'"};
- </script>';
- }
- //-------------------------------------------------------------
- // print custom styles
- //-------------------------------------------------------------
- public function print_custom_styles() {
- while (have_posts()) {
- the_post();
- $post = get_post(get_the_id());
- $content = $post->post_content;
- if (stripos($content,'[dk_smi')!==false) {
- echo '<style type="text/css">
- .dk_smi_h2 {
- margin-top:-10px!important;
- }
- </style>';
- }
- if (stripos($content,'[dk_otzyv_list')!==false) {
- echo '<style type="text/css">
- .dk_otzyv_h5 {
- margin-top:40px;
- }
- </style>';
- }
- }
- rewind_posts();
- }
- //-------------------------------------------------------------
- // footer script
- //-------------------------------------------------------------
- public function print_footer_scripts() {
- while (have_posts()) {
- the_post();
- $post = get_post(get_the_id());
- $content = $post->post_content;
- if (stripos($content,'[dk_smi')!==false):
- ?>
- <script type="text/javascript">
- (function($) {
- $(document).ready(
- function() {
- var config = {
- $bookblock : $('#bb-bookblock'),
- $navprev : $('#bbprev'),
- $navnext : $('#bbnext'),
- $navfirst : $('#bbfirst'),
- $navlast : $('#bblast'),
- $navprevtop : $('#bbprevtop'),
- $navnexttop : $('#bbnexttop'),
- $navfirsttop : $('#bbfirsttop'),
- $navlasttop : $('#bblasttop'),
- }
- var bb = config.$bookblock.bookblock( {
- speed : 800,
- shadowSides : 0.8,
- shadowFlip : 0.7
- } );
- for (var i=0; i<bb.itemsCount; i++) {
- var page_item = $('<a/>',{href:'javascript:',class:'bbnumber'}).html(i+1);
- page_item.on('click touchstart', jump_closure(i+1));
- $('#bbfirsttop').before(page_item);
- }
- check_controls();
- function jump_closure(page) {
- return function() {
- bb.jump(page);
- check_controls();
- return false;
- }
- }
- config.$navprev.on('click touchstart', function() {
- config.$bookblock.bookblock('prev');
- check_controls();
- return false;
- });
- config.$navnext.on('click touchstart', function() {
- config.$bookblock.bookblock('next');
- check_controls();
- return false;
- });
- config.$navfirst.on('click touchstart', function() {
- bb.jump(1);
- check_controls();
- return false;
- });
- config.$navlast.on('click touchstart', function() {
- bb.jump(bb.itemsCount);
- check_controls();
- return false;
- });
- //------------------------------------
- config.$navprevtop.on('click touchstart', function() {
- config.$bookblock.bookblock('prev');
- check_controls();
- return false;
- });
- config.$navnexttop.on('click touchstart', function() {
- config.$bookblock.bookblock('next');
- check_controls();
- return false;
- });
- config.$navfirsttop.on('click touchstart', function() {
- bb.jump(1);
- check_controls();
- return false;
- });
- config.$navlasttop.on('click touchstart', function() {
- bb.jump(bb.itemsCount);
- check_controls();
- return false;
- });
- //------------------------------------------
- function check_controls() {
- if (bb.current==0) {
- $('#bbprev,#bbprevtop, #bbfirst, #bbfirsttop').hide();
- } else {
- $('#bbprev,#bbprevtop, #bbfirst, #bbfirsttop').show();
- }
- if (bb.current==(bb.itemsCount-1)) {
- $('#bbnext,#bbnexttop,#bblast, #bblasttop').hide();
- } else {
- $('#bbnext,#bbnexttop,#bblast, #bblasttop').show();
- }
- $('.bbnumber').removeClass('active').eq(bb.current).addClass('active');
- }
- }
- )
- })(jQuery)
- </script>
- <?php
- break;
- endif;
- }
- rewind_posts();
- }
- //----------------------------------------------------
- public function stub_shortcode() {
- return '';
- }
- //-------------------------------------------------------------
- // questions and answers shortcode
- //-------------------------------------------------------------
- public function qa_list_shortcode($atts, $content=null) {
- $default_atts = array('id'=>0);
- extract(shortcode_atts($default_atts, $atts));
- $params = array('post_type'=>'dk_question','orderby'=>'date', 'order'=>'DESC',
- 'status'=>'publish', 'meta_key'=>'form_id', 'posts_per_page'=>50, 'post_parent'=>0);
- if ($id) {
- $params = array_merge($params,array( 'meta_value'=>$id));
- }
- $q = new WP_Query($params);
- $s = '<div class="questions_and_answers">';
- while ($q->have_posts()) {
- $q->the_post();
- $post_cats = wp_get_post_categories(get_the_id());
- if (in_array(93,$post_cats)) {
- continue;
- }
- $contact_id = get_post_meta(get_the_id(),'contact_id',true);
- $contact_name = get_post_meta(get_the_id(),'contact_name',true);
- $contact_description = get_post_meta(get_the_id(),'contact_description',true);
- $contact_picture = get_post_meta(get_the_id(),'contact_picture',true);
- $form_name = get_post_meta(get_the_id(),'form_name',true);
- $s .= '<div class="qa_question">';
- $s .= '<div class="question_header">Вопрос</div> | ';
- $s .= '<div class="question_date">'.get_the_date('d.m.Y',get_the_id()).'</div>';
- $s .= '<div class="question_author">'.get_the_title().'</div>';
- $s .= '<div class="question_body">'.get_the_content().'</div>';
- $s .= '</div>';
- $answers = get_posts(array('post_type'=>'dk_question','post_parent'=>get_the_id()));
- foreach ($answers as $answer) {
- setup_postdata($answer);
- $answer_author_id = get_post_meta($answer->ID, 'contact_id',true);
- if ($answer_author_id) {
- $contact_id = $answer_author_id;
- $contact_name = get_post_meta($answer->ID, 'contact_name',true);
- $contact_description = get_post_meta($answer->ID, 'contact_description', true);
- $contact_picture = get_post_meta($answer->ID, 'contact_picture', true);
- }
- $s .= '<div class="qa_answer">';
- $s .= '<div class="answer_author">';
- $s .= '<div class="answer_author_picture"><img src="'.$contact_picture.'" /></div>';
- $s .= '<div class="answer_author_name">'.$contact_name.'</div>';
- $s .= '<div class="answer_author_description">'.$contact_description.'</div>';
- $s .= '</div>';
- $s .= '<div class="answer_header">Ответ</div>';
- $s .= '<div class="answer_body">'.str_replace('dmkim1979@gmail.com пишет:','',get_the_content()).'</div>';
- $s .= '</div>';
- }
- wp_reset_postdata();
- }
- wp_reset_query();
- $s .= '</div>';
- return $s;
- }
- //-------------------------------------------------------------
- // contact form shortcode
- //-------------------------------------------------------------
- public function contactform_shortcode($atts, $content=null) {
- $default_atts = array('id'=>0, 'id2'=>0, 'type'=>'');
- extract(shortcode_atts($default_atts,$atts));
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- //$contacts_model->setFilterString('contactform_id='.$id,true);
- $contacts_model->setFilterString(
- 'contact_actual<>0 and contactform_contact_id in (select contactform_contact_id from dk_contacts_links where '.
- ' contactform_id='.$id.')',true);
- if ($id2) {
- $contacts_model->setFilterString('contactform_contact_id='.$id2,true);
- }
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- $data_script ='';
- foreach ($contacts as $contact) {
- $data_script .= '\''.trim($contact['contactform_contact_email']).'\':'.$contact['contactform_contact_id'].',';
- }
- $data_script = 'emails_ids ={'.$data_script.'}';
- $sContactForm = '<script type="text/javascript">'.$data_script.'</script>';
- if ($type=='eko') {
- $sContactForm .= '<style type="text/css">#recipient_email,#rec_label {display:none;}</style>';
- }
- $sContactForm .= '
- <h2>Задайте вопрос специалисту</h2>
- <div class="dk_form_fields" style="overflow:auto">
- <div class="ajax_note"></div>
- <div class="wait_div">
- <p>Форма отправляется. Пожалуйста, подождите</p>
- <img src="'.$this->plugin_url.'ajax-loader.gif" />
- </div>
- <form class="dk-contact-form" action="">
- <label>Представьтесь <sup>*</sup></label><input type="text" name="sender_name" value="" placeholder="Введите Ваше имя" />
- <label id="rec_label">ФИО врача <sup>*</sup></label>
- <select length="50" name="recipient_email" id="recipient_email2"> ';
- foreach ($contacts as $contact) {
- $sContactForm .= '<option value="'.$contact['contactform_contact_email'].'">'.
- $contact['contactform_contact_name'].'</option>';
- }
- $sContactForm .= ' </select>
- <input type="hidden" name="contact_id" value="" />
- <label>E-Mail <sup>*</sup></label><input type="text" name="sender_email" value="" placeholder="Введите E-mail" />
- <label>Вопрос <sup>*</sup></label>
- <textarea rows="10" cols="45" name="question" placeholder="Введите вопрос"></textarea>
- <p><input type="checkbox" name="sogl">
- <label class="longlab" style="display:block">Я ДАЮ СОГЛАСИЕ НА ПУБЛИКАЦИЮ ВОПРОСА НА САЙТЕ</label></p>
- <div style="clear:both"></div>
- <p> Все поля обязательны для заполнения</p>
- <input type="hidden" name="from_page" value="'.get_the_title().'" />
- <input type="button" class="cancelbutton" value="отмена" style="float:right" />
- <input type="submit" name="submit" value="Отправить" style="background:#a35ea0!important;float:right" />
- </form>
- </div>';
- return $sContactForm;
- }
- //-------------------------------------------------------------
- // contact total form shortcode
- //-------------------------------------------------------------
- public function totalcontactform_shortcode($atts, $content=null) {
- $default_atts = array('en'=>false ,'otdelid'=>'#otdel');
- extract(shortcode_atts($default_atts,$atts));
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $forms_model = $sm->getModel('CFormsModel','cforms');
- $forms_model->setOrder('contactform_name');
- $departments = $forms_model->getPage(0,true);
- $departments = $departments['items'];
- $f = create_function('$a',' return ($a["show_q"]);');
- $departments = array_filter($departments, $f);
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- $data_script ='';
- $repeats = array();
- foreach ($contacts as $contact) {
- if (!in_array( $contact['contactform_contact_email'],$repeats)) {
- $data_script .= '\''.trim($contact['contactform_contact_email']).'\':'.$contact['contactform_contact_id'].',';
- array_push($repeats, $contact['contactform_contact_email']);
- }
- }
- $data_script = 'emails_ids ={'.$data_script.'}';
- $sContactsScript = '<script type="text/javascript">'.$data_script.'</script>';
- $data_script = '';
- $dep_names = array();
- foreach ($departments as $department) {
- $id = $department['contactform_id'];
- $name = $en?$department['contactform_eng_name']:$department['contactform_name'];
- $dep_names[] = $name;
- $data_script .= '\''.$name.'\': {';
- $contacts_model->setFilterString('contactform_id='.$id,true);
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- foreach ($contacts as $contact) {
- $data_script .= '\''.strip_tags(trim($en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name'])).'\':\''.
- $contact['contactform_contact_email'].'\',';
- }
- $data_script .='},';
- }
- $data_script = '
- <script type="text/javascript">
- var structure = {'.$data_script.'}
- </script>';
- ob_start();
- ?>
- <script type="text/javascript">
- (function($) {
- $(document).ready(function(){
- $('<?php echo $otdelid; ?>').change(function(){
- $('<?php echo $otdelid; ?>coder').html('<option id="-1"><?php echo $en?'select specialist':'-выберите специалиста-'; ?></option>');
- console.log($('<?php echo $otdelid; ?>').val());
- for(var prop in structure[$('<?php echo $otdelid; ?>').val()])
- $('<?php echo $otdelid; ?>coder').append('<option value="'+prop+'">'+prop+'</option>');
- });
- $('<?php echo $otdelid; ?>coder').change(function (){
- var emailvr=structure[$('<?php echo $otdelid; ?>').val()][$('<?php echo $otdelid; ?>coder').val()];
- $('<?php echo $otdelid; ?>recipient_email').val(emailvr);
- var contact_id = emails_ids[emailvr];
- $('input[name="contact_id"]').val(contact_id);
- });
- }); })(jQuery)
- </script>
- <?php
- $form_script = ob_get_clean();
- ob_start();
- if ($en):
- ?>
- <p>Use form below to ask our specialist the question you are interested in . We'll answer you in a few days.<br />
- You'll receive your answer to the email you'll provide<br />
- Question and Answer will also be published on site </p>
- <p> </p>
- <h2>Ask doctor</h2>
- <?php
- else:
- ?>
- <p>Воспользуйтесь формой ниже, чтобы задать интересующий Вас <strong>вопрос</strong> нашему специалисту. В течение 1-2 дней мы ответим Вам.<br />
- Ответ Вы получите на указанный Вами <strong>адрес электронной почты</strong>.<br />
- Вопросы и ответы публикуются на сайте</p>
- <p> </p>
- <h2>Задайте вопрос специалисту</h2>
- <?php
- endif;
- ?>
- <div id="fields">
- <div class="ajax_note"></div>
- <div class="wait_div">
- <p><?php echo $en? 'Processing, please wait...' :'Форма отправляется. Пожалуйста, подождите';?></p>
- <img src="<?php echo $this->plugin_url?>ajax-loader.gif" />
- </div>
- <form class="dk-contact-form" action=""><label><?php echo $en?'Enter your name':'Представьтесь'; ?><sup>*</sup></label>
- <input id="sender_name" type="text" name="sender_name" value="" placeholder="<?php echo $en?'Enter your name':'Представьтесь'; ?>" />
- <label>Введите Ваш E-Mail *</label><input class="nth_email" name="sender_email" type="text"
- placeholder="<?php echo $en?'Enter your E-Mail':'Введите E-Mail';?>" />
- <label><?php echo $en?'Department':'Отделение'; ?><sup>*</sup></label></p>
- <select id="<?php echo substr($otdelid,1); ?>" name="komu">
- <option value="-1"><?php echo $en?'select department':'-выберите отделение-';?></option>
- <?php
- foreach ($dep_names as $dep_name) {
- echo '<option value="'.$dep_name.'">'.$dep_name.'</option>';
- }
- ?>
- </select>
- <p><label>ФИО врача <sup>*</sup></label></p>
- <select id="<?php echo substr($otdelid,1); ?>coder" name="coder">
- <option id="-1"><?php echo $en?'select specialist':'-выберите специалиста-';?></option>
- </select>
- <input id="<?php echo substr($otdelid,1); ?>recipient_email" type="hidden" name="recipient_email" value="" />
- <input type="hidden" name="contact_id" value="" />
- <p>
- <label>Вопрос <sup>*</sup></label><br />
- <textarea cols="45" name="question" rows="10" placeholder="<?php echo $en?'Enter question':'Введите вопрос'; ?>"></textarea>
- <p><input type="checkbox" name="sogl">
- <label class="longlab" style="display:block"><?php
- echo $en? 'I agree for my question to be published on site' :'Я ДАЮ СОГЛАСИЕ НА ПУБЛИКАЦИЮ ВОПРОСА НА САЙТЕ'; ?></label></p>
- <p style="clear:both"><?php
- echo $en?'all fields are required':'Все поля обязательны для заполнения';
- ?></p>
- <input type="hidden" name="from_page" value="<?php the_title(); ?>" />
- <input class="btn" type="submit" name="submit" value="<?php echo $en?'Send':'Отправить';?>" />
- <input type="button" class="cancelbutton" value="<?php echo $en?'cancel':'отмена';?>" />
- </p>
- </form>
- </div>
- <?php
- $form = ob_get_clean();
- return $sContactsScript.$data_script.$form_script.$form;
- }
- //------------------------------------------------------------
- // eko contact form shortcode
- //------------------------------------------------------------
- public function ekocontactform_shortcode($atts, $content=null) {
- ob_start();
- ?>
- <div class="ajax_note" style="background:#fff;color:#f00;position:absolute"></div>
- <div class="wait_div">
- <p>Форма отправляется. Пожалуйста подождите</p>
- <img src="<?php echo $this->plugin_url?>ajax-loader.gif" />
- </div>
- <form class="dk-contact-form">
- <div class="nth_slide_form_row">
- <input class="nth_name" name="sender_name" type="text" placeholder="ПРЕДСТАВЬТЕСЬ" />
- <input class="nth_phone" name="tel" type="text" placeholder="ВВЕДИТЕ ВАШ ТЕЛЕФОН" />
- <input class="nth_email" name="sender_email" type="text" placeholder="ВВЕДИТЕ ВАШ E-MAIL" />
- </div>
- <div class="nth_slide_form_row">
- <textarea class="nth_question" name="question"></textarea>
- </div>
- <div class="nth_submit_block">
- <input type="hidden" name="recipient_email" value="sgoshovskaya@petrovkamed.ru" />
- <input type="hidden" name="contact_id" value="10" />
- <input type="hidden" name="from_page" value="<?php the_title() ?>" />
- <input type="submit" class="nth_submit" value="ОТПРАВИТЬ" />
- </div>
- </form>
- <?php
- $form = ob_get_clean();
- return $form;
- }
- //------------------------------------------------------------
- // landing contact form shortcode
- //------------------------------------------------------------
- public function landingcontactform_shortcode($atts, $content=null) {
- $default_atts = array('block'=>'');
- extract(shortcode_atts($default_atts,$atts));
- ob_start();
- ?>
- <div id="mrt_form_call" class="mrt_form mrt_form_hidden" <?php if ($block) echo 'data-block='.$block; ?> >
- <form name="mrt_form" class="dk-appointment-form">
- <div class="name_block">
- <label>Представьтесь*</label>
- <input type="text" name="name" placeholder="Ваше имя" />
- </div>
- <div class="tel_block">
- <label>Введите телефон*</label>
- <input type="text" name="tel" class="tel" placeholder="телефон"/>
- </div>
- <div class="hide_on_landing">
- Все поля обязательны для заполнения
- </div>
- <input type="hidden" name="komu" value="callcenter@petrovkamed.ru" />
- <input type="hidden" name="from_page" value="Заказ обратного звонка" />
- <input type="hidden" name="landing_antispam_field" class="landing_antispam_field" value="">
- <input type="hidden" name="ga_type" value="order-call" />
- <input type="hidden" name="department_id" value=1000 />
- <input type="hidden" name="department_name" value="call" />
- <input type="submit" name="submit" value="отправить" />
- <input type="button" class="cancelbutton" value="отмена" />
- </form>
- </div>
- <?php
- $form = ob_get_clean();
- return $form;
- }
- //------------------------------------------------------------
- // appointment form shortcode
- //------------------------------------------------------------
- public function appointmentform_shortcode($atts, $content=null) {
- $default_atts = array('type'=>'','block'=>'','eng'=>false,'alt'=>false);
- extract(shortcode_atts($default_atts,$atts));
- if ($type=='global') {
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $forms_model = $sm->getModel('CFormsModel','cforms');
- $forms_model->setOrder('contactform_name');
- $departments = $forms_model->getPage(0,true);
- $departments = $departments['items'];
- $f = create_function('$a',' return ($a["show_q"]);');
- $departments = array_filter($departments, $f);
- $data_script = '';
- foreach ($departments as $department) {
- $data_script .= '\''.trim($department['contactform_name']).'\':'.$department['contactform_id'].',';
- }
- $data_script = 'departments_ids ={'.$data_script.'}';
- $data_script = '<script type="text/javascript">'.$data_script.'</script>';
- echo $data_script;
- }
- ob_start();
- ?>
- <div class="mrt_form dk-appointment-form-container">
- <?php if ($alt): ?>
- <h3>ЗАПИСАТЬСЯ</h3>
- <h4><a href="tel:84959099909" class="mbphone"><span class="comagic_phone">8(495)909-9-909</span></a></h4>
- <h5><a href="javascript:" class="order_call2">Заказать обратный звонок</a></h5>
- <?php endif; ?>
- <form name="mrt_form" class="dk-appointment-form" <?php if ($block) echo 'data-block='.$block; ?> >
- <div class="name_block">
- <label>Представьтесь*</label>
- <input type="text" name="name" placeholder="<? echo $eng?'Input your name':'Ваше имя';?>" />
- </div>
- <?php
- if ($type=='global') {
- echo '<div class="department_block"><select name="department_name">';
- echo '<option value="-1">'.($eng?'Select the Department':'-выберите отделение-').'</option>';
- foreach ($departments as $department) {
- echo '<option value="'.($eng?$department['contactform_eng_name']:$department['contactform_name']).'">'.
- ($eng?$department['contactform_eng_name']:$department['contactform_name']).'</option>';
- }
- echo '</select><input type="hidden" name="department_id"></div>';
- echo '<input type="hidden" name="ga_type" value="make-appointment-left" />';
- } else {
- echo '<input type="hidden" name="ga_type" value="make-appointment" />';
- }
- ?>
- <div class="email_block">
- <label>Введите E-Mail*</label>
- <input type="text" name="email" placeholder="<?php echo $eng?'Input your e-mail':'Введите e-mail';?> *"/>
- </div>
- <div class="tel_block">
- <label>Введите телефон</label>
- <input type="text" name="tel" class="tel" placeholder="<?php echo $eng?'Input your phone':'Телефон';?> "/>
- </div>
- <div class="date_block">
- <label>Дата записи</label>
- <input type="text" name="date" class="datepicker"
- placeholder="<?php echo $eng?'Select date':'Выберите дату';?>" autocomplete="off" />
- </div>
- <input type="hidden" name="komu" value="callcenter@petrovkamed.ru" />
- <input type="hidden" name="from_page" value="<?php echo get_the_title(); ?>" />
- <div class="hide_on_landing">
- <sup>*</sup> - <?php echo $eng?'required':'поля обязательные для заполнения'; ?>
- </div>
- <input type="button" class="cancelbutton" value="<?php echo $eng?'cancel':'отмена';?>" style="float:right" />
- <input type="submit" name="submit" value="<?php echo $eng?'Send':'Отправить';?>" style="background:#a35ea0!important;float:right" />
- <div style="clear:both"></div>
- <input type="hidden" name="landing_antispam_field" class="landing_antispam_field" value="">
- </form>
- </div>
- <?php
- $form = ob_get_clean();
- return $form;
- }
- //------------------------------------------------------------
- // appointment eko 1 form shortcode
- //------------------------------------------------------------
- public function appointmentform_eko1_shortcode($atts, $content=null) {
- ob_start();
- ?>
- <form class="dk-appointment-form">
- <div id="sevsf_arrow">
- </div>
- <div id="sevf_header" class="editable" data-post-meta="2800_sevf_header">
- МЫ ВМЕСТЕ С ВАМИ<br/>
- ПРОЙДЕМ ПУТЬ К РОЖДЕНИЮ<br/>
- ЗДОРОВОГО МАЛЫША<br/>
- </div>
- <div id="sevf_text" class="editable" data-post-meta="2900_sevf_text">
- Доверяя свое репродуктивное здоровье<br/>
- специалистам клиники ЭКО «Петровские<br/>
- ворота» в Москве, Вы получаете<br/>
- качественные услуги по диагностике и<br/>
- лечению, и максимально высокий процент<br/>
- положительного результата в ходе лечения.
- </div>
- <div id="sevf_actual">
- <label class="sevf_common">
- ЗАПИСАТЬСЯ НА ПРИЕМ
- </label>
- <div class="sevf_row">
- <input class="sevf_name" type="text" name="name" placeholder="ПРЕДСТАВЬТЕСЬ *" />
- <input class="sevf_phone" name="tel" type="text" placeholder="ВВЕДИТЕ ВАШ ТЕЛЕФОН" />
- </div>
- <div class="sevf_row">
- <input class="sevf_email" type="text" name="email" placeholder="ВВЕДИТЕ ВАШ E-MAIL" />
- <input class="sevf_date datepicker" type="text" name="date" placeholder="ДАТА И ВРЕМЯ" autocomplete="off" />
- </div>
- <div class="sevf_submit_block">
- <input type="hidden" name="komu" value="msamoshina@petrovkamed.ru,dtimofeeva@petrovkamed.ru,callcenter@petrovkamed.ru" />
- <input type="hidden" name="from_page" value="Центр ЭКО" />
- <input type="hidden" name="ga_type" value="make-appointment" />
- <input type="hidden" name="department_id" value=10 />
- <input type="hidden" name="department_name" value="ЭКО" />
- <input type="submit" class="sevf_submit" value="ОТПРАВИТЬ" />
- </div>
- </div>
- <input type="hidden" name="landing_antispam_field" class="landing_antispam_field" value="" />
- </form>
- <?php
- $form = ob_get_clean();
- return $form;
- }
- //------------------------------------------------------------
- // appointment eko 2 form shortcode
- //------------------------------------------------------------
- public function appointmentform_eko2_shortcode($atts, $content=null) {
- ob_start();
- ?>
- <form class="dk-appointment-form">
- <label class="sevf_common" style="margin:9px 0 9px 0">
- ЗАПИСАТЬСЯ НА ПРИЕМ
- </label>
- <div class="sevf_row" style="float:left;width:50%">
- <input class="sevf_name" type="text" name="name" placeholder="ПРЕДСТАВЬТЕСЬ *" />
- <input class="sevf_phone" type="text" name="tel" placeholder="ВВЕДИТЕ ВАШ ТЕЛЕФОН" />
- </div>
- <div class="sevf_row" style="float:left;width:50%">
- <input class="sevf_email" type="text" name="email" placeholder="ВВЕДИТЕ ВАШ E-MAIL" />
- <input class="sevf_date datepicker" type="text" name="date" placeholder="ДАТА И ВРЕМЯ" autocomplete="off" />
- </div>
- <div style="clear:both"></div>
- <div class="sevf_submit_block">
- <input type="hidden" name="komu" value="msamoshina@petrovkamed.ru,dtimofeeva@petrovkamed.ru,callcenter@petrovkamed.ru" />
- <input type="hidden" name="from_page" value="Центр ЭКО" />
- <input type="hidden" name="ga_type" value="make-appointment" />
- <input type="hidden" name="department_id" value=10 />
- <input type="hidden" name="department_name" value="ЭКО" />
- <input type="submit" class="sevf_submit" value="ОТПРАВИТЬ" />
- </div>
- <input type="hidden" name="landing_antispam_field" class="landing_antispam_field" value="">
- </form>
- <?php
- $form = ob_get_clean();
- return $form;
- }
- //------------------------------------------------------------
- // otzyv full shortcode
- //------------------------------------------------------------
- public function otzyvfull_shortcode($atts, $content=null) {
- $default_atts = array('id'=>0, 'landing'=>0);
- extract(shortcode_atts($default_atts,$atts));
- ob_start();
- ?>
- <div id="nth_slide_form<?php if (!$landing) echo "_inline"; ?>">
- <div class="wait_div" style="position:absolute;height:100%;width:100%;z-index:100;background:#000;opacity:0.5;display:none">
- <p>Форма отправляется. Пожалуйста подождите</p>
- <img style="position:absolute;top:50%;left:50%" src="<?php echo $this->plugin_url?>ajax-loader.gif" />
- </div>
- <div id="nth_slide_form_header<?php if (!$landing) echo "_inline"; ?>">
- Нам важно Ваше мнение!
- </div>
- <div id="nth_slide_form_text<?php if (!$landing) echo "_inline"; ?>">
- Если Вы хотите оставить свой отзыв или сообщение, пожалуйста, заполните следующую форму
- </div>
- <form class="dk-otzyv-form">
- <div class="nth_slide_form_row">
- <input class="nth_name" name="name" type="text" placeholder="Представьтесь *" />
- <input class="nth_phone" name="tel" type="text" placeholder="Введите Ваш телефон" />
- <input class="nth_email" name="email" type="text" placeholder="Введите Ваш E-Mail *" />
- </div>
- <div class="nth_slide_form_row">
- <textarea class="nth_question" name="otzyv" placeholder="Оставьте Ваш отзыв *"></textarea>
- </div>
- <div class="nth_submit_block<?php if (!$landing) echo "_inline"; ?>">
- <input type="hidden" name="komu" value="callcenter@petrovkamed.ru,mkorneev@petrovkamed.ru,ydolnikova@petrovkamed.ru" />
- <input type="hidden" name="from_page" value="<?php echo get_the_title(); ?>" />
- <?php
- if ($id) {
- echo '<input type="hidden" name="contact_id" value='.$id.'/>';
- }
- ?>
- <div class="hide_on_landing">
- <sup>*</sup> - поля обязательные для заполнения
- </div>
- <input type="button" class="cancelbutton" value="<?php echo $eng?'cancel':'отмена'; ?>" style="float:right" />
- <input type="submit" name="submit" class="nth_submit" value="Отправить" style="background:#a35ea0!important;float:right" />
- <input type="hidden" name="landing_antispam_field" id="landing_antispam_field" value="">
- </div>
- </form>
- </div>
- <?php
- $form = ob_get_clean();
- return $form;
- }
- //------------------------------------------------------------
- // smi shortcode
- //------------------------------------------------------------
- public function smi_shortcode($atts, $content=null) {
- $params = array('post_type'=>'dk_publication','orderby'=> 'meta_value',
- 'meta_key'=>'publication_date','order'=>'DESC', 'status'=>'publish', 'posts_per_page'=>50);
- $q = new WP_Query($params);
- ob_start();
- echo '<div class="bb-navigation">
- <a href="javascript:" id="bbfirsttop">Первая</a>
- <a href="javascript:" id="bbprevtop">Назад</a>
- <a href="javascript:" id="bbnexttop">Вперед</a>
- <a href="javascript:" id="bblasttop">Последняя</a>
- </div>';
- echo '<div id="bb-container"><div id="bb-bookblock" class="bb-bookblock">';
- echo '<div class="bb-item">';
- $i=0;
- while ($q->have_posts()) {
- $q->the_post();
- $article_file = get_post_meta(get_the_ID(),'publication_file' ,true);
- $article_file = str_replace($_SERVER['DOCUMENT_ROOT'],'',$article_file);
- $article_date = get_post_meta(get_the_ID(),'publication_date', true);
- $article_header = get_the_title();
- $article_text = get_the_content();
- if (has_post_thumbnail(get_the_id())) {
- $tid = get_post_thumbnail_id(get_the_id());
- $article_image = reset(wp_get_attachment_image_src($tid,'full'));
- } else {
- $article_image ='';
- }
- ?>
- <div class="ether-cols ether-cols-2d3-2 smi-article">
- <div class="ether-col">
- <img src="<?php echo $article_image; ?>" alt="" class="ether-widget ether-img" style=" " />
- </div>
- <div class="ether-col"><br>
- <h2 class="dk_smi_h2"><?php echo $article_header ?></h2>
- <div style=""><p>
- <?php echo $article_text ?>
- </p>
- </div>
- <a href="<?php echo $article_file ?>" class="ether-widget ether-link" style="">Читать статью</a><br>
- </div>
- </div>
- <?php
- $i++;
- if (($i%3)==0) {
- echo '</div><div class="bb-item">';
- }
- }
- wp_reset_query();
- echo '</div></div></div><div class="bb-navigation">
- <a href="javascript:" id="bbfirst">Первая</a>
- <a href="javascript:" id="bbprev">Назад</a>
- <a href="javascript:" id="bbnext">Вперед</a>
- <a href="javascript:" id="bblast">Последняя</a>
- </div>';
- $info = ob_get_clean();
- return $info;
- }
- //------------------------------------------------------------
- // otzyv list shortcode
- //------------------------------------------------------------
- public function otzyv_list_shortcode($atts, $content=null) {
- $default_atts = array('id'=>0, 'id2'=>0, 'id3'=>0, 'type'=>'');
- extract(shortcode_atts($default_atts,$atts));
- if ($id||$id2) {
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contacts_model->setFilterString('contactform_id='.$id, true);
- if ($id2) {
- $contacts_model->setFilterString('contactform_contact_id='.$id2,true);
- }
- if ($id2 && $id3) {
- $contacts_model->setFilterString('(contactform_contact_id='.$id2.' or contactform_contact_id='.$id3.')',true);
- }
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- $contact_ids = array();
- foreach ($contacts as $contact) {
- $contact_ids[] =$contact['contactform_contact_id'];
- }
- }
- $params = array('post_type'=>'dk_review','orderby'=> 'meta_value',
- 'meta_key'=>'review_date','order'=>'DESC', 'status'=>'publish', 'posts_per_page'=>200);
- if ((isset($contact_ids)) && ($contact_ids)) {
- $params_meta = array('meta_query'=> array(array('key'=>'contact_id','value'=>$contact_ids,'compare'=>'IN')));
- $params = array_merge($params, $params_meta);
- }
- //echo '<pre>'.print_r($params,true).'</pre>';
- $q = new WP_Query($params);
- ob_start();
- // echo '<div class="flexslider"><ul class="slides"><li>';
- $i=0;
- while ($q->have_posts()) {
- $q->the_post();
- $otzyv_name = get_post_meta(get_the_id(), 'sender_name', true);
- $otzyv_name = str_replace('не указан','',$otzyv_name);
- if (!$type)
- $otzyv_name .= ($otzyv_name?', ':'');
- $otzyv_date = get_post_meta(get_the_id(), 'review_date', true);
- $otzyv_date = substr($otzyv_date,-2).'.'.substr($otzyv_date,4,2).'.'.substr($otzyv_date,0,4);
- $otzyv_text = get_the_content();
- /*if (!$i%5)
- echo '</li><li>';
- $i++;*/
- if ($type=='eko'):
- ?>
- <div class="elevs_list_item">
- <div class="elevs_date"><?php echo $otzyv_date; ?></div>
- <div class="elevs_item_header">
- <?php echo $otzyv_name; ?>
- </div>
- <p>
- <?php echo $otzyv_text; ?>
- </p>
- </div>
- <?php
- else:
- ?>
- <h5 class="dk_otzyv_h5"><?php echo $otzyv_name.$otzyv_date; ?></h5>
- <div class="dk_otzyv_contents">
- <p><?php echo $otzyv_text; ?></p>
- </div>
- <?php
- endif;
- }
- //echo '</li></ul></div>';
- wp_reset_query();
- $info = ob_get_clean();
- return $info;
- }
- //------------------------------------------------------------
- // pricelist shortcode
- //------------------------------------------------------------
- public function pricelist_shortcode($atts, $content=null) {
- $default_atts = array ('id'=>0, 'id2'=>0, 'sub_id'=>0);
- extract( shortcode_atts( $default_atts, $atts));
- define ('DS',DIRECTORY_SEPARATOR);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $forms = $sm->getModel('CFormsModel','cforms');
- $form = $forms->getSingle($id);
- $form = $form['item'];
- $department_1c_id = $form['contactform_1c_id'];
- if ($id2) {
- $form = $forms->getSingle($id2);
- $form = $form['item'];
- $department_1c_id2 = $form['contactform_1c_id'];
- }
- $prices = $sm->getModel('PriceListModel','xml_price_list');
- if ($sub_id) {
- $subid_filter = ' and sub_id='.$sub_id;
- } else
- $subid_filter = '';
- if (!$id2) {
- $prices->setFilterString('department_1c_id=\''.$department_1c_id.'\''.$subid_filter);
- } else {
- $prices->setFilterString(' (department_1c_id=\''.$department_1c_id.
- '\' or department_1c_id=\''.$department_1c_id2.'\') '.$subid_filter);
- }
- $prices->setOrder('pricelist_sort_order, department_1c_id, pricelist_id');
- $items = $prices->getPage(0,true);
- $items = $items['items'];
- ob_start();
- ?>
- <table class="tablepress">
- <thead>
- <tr class="row-1 odd">
- <th class="column-1"><div>Перечень услуг</div></th><th class="column-2"><div>Цены, руб.</div></th>
- </tr>
- </thead>
- <tbody class="row-hover">
- <?php
- $i=1;
- $chapter_name = '';
- foreach ($items as $item) {
- if ($item['chapter_name']!=$chapter_name) {
- $chapter_name = $item['chapter_name'];
- echo '<tr class="row-'.$i.' '.($i%2 ? 'odd' : 'even').'">';
- echo '<td class="column-1"><strong>'.$chapter_name.'</strong></td>';
- echo '<td class="column-2"></td>';
- echo '</tr>';
- $i++;
- }
- echo '<tr class="row-'.$i.' '.($i%2 ? 'odd' : 'even').'">';
- echo '<td class="column-1">'.$item['pricelist_1c_name'].'</td>';
- echo '<td class="column-2">'.str_replace('.',',',$item['pricelist_price']).'</td>';
- echo '</tr>';
- $i++;
- }
- ?>
- </tbody></table>
- <?php
- $s = ob_get_clean();
- return $s;
- }
- //------------------------------------------------------------
- // doctors shortcode
- //------------------------------------------------------------
- public function doctors_shortcode($atts, $content=null) {
- $default_atts = array ('id'=>0, 'en'=>false);
- extract( shortcode_atts( $default_atts, $atts));
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contacts_model->setFilterString(
- 'contact_actual<>0 and contactform_contact_id in (select contactform_contact_id from dk_contacts_links where '.
- ' contactform_id='.$id.')',true);
- $contacts_model->setOrder('contactform_contact_order');
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- ob_start();
- $i=0;
- ?>
- <div class="doctors_list ether-content ether-toggle-content"><table width="0" border="0">
- <?php
- foreach ($contacts as $contact) {
- if (!($i%3))
- echo '<tr>';
- ?>
- <td width="245" align="left" valign="top">
- <p><a href="<?php echo $en?$contact['contactform_contact_eng_url']:$contact['contactform_contact_url']; ?>"><img src="<?php
- echo $contact['contactform_contact_picture']?$contact['contactform_contact_picture']:'/wp-content/uploads/2014/09/shetinina.png'; ?>"
- alt="<?php echo ($en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name']); ?>"></a>
- <a href="<?php echo $en?$contact['contactform_contact_eng_url']:$contact['contactform_contact_url']; ?>"><div class="doctor_name">
- <?php $dname = $en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name'];
- $dname = strip_tags(str_replace(array('<br/>','<br>'),array(' ',' '),$dname));
- $dname = substr($dname,0, strpos($dname,' ')).'<br/>'.substr($dname, strpos($dname,' '));
- echo $dname;
- ?></div></a>
- <div class="doctor_description">
- <?php echo $en?$contact['contactform_contact_eng_description']:$contact['contactform_contact_description'];?>
- </div>
- </td>
- <?php
- $i++;
- if (!($i%3)) {
- echo '</tr>';
- }
- }
- ?>
- </table> </div>
- <?php
- $s = ob_get_clean();
- return $s;
- }
- //------------------------------------------------------------
- // doctors shortcode full
- //------------------------------------------------------------
- public function doctors_shortcode_full($atts, $content=null) {
- $default_atts = array ('en'=>false);
- extract( shortcode_atts( $default_atts, $atts));
- define ('DS',DIRECTORY_SEPARATOR);
- define('DEBUG', false);
- require_once dirname(__FILE__).DS.'simplemvc'.DS.'system'.DS.'sm.inc.php';
- $sm = new ServiceManager(array('location'=>dirname(__FILE__).DS.'simplemvc','ds'=>DS));
- $sm->init();
- $forms_model = $sm->getModel('CFormsModel','cforms');
- $forms_model->setOrder('contactform_doctor_name');
- $forms_model->setFilterString('show_q<>0');
- $departments = $forms_model->getPage(0,true);
- $departments = $departments['items'];
- $f = create_function('$a',' return ($a["contactform_id"]!=11);');
- $departments = array_filter($departments, $f);
- $contacts_model = $sm->getModel('CContactsModel','ccontacts');
- $contacts_model->setOrder('contactform_contact_order');
- ob_start();
- ?>
- <div class="ether-widget ether-multi ether-multi-1 ether-type-acc ether-acc-x">
- <?php
- foreach ($departments as $department) {
- $id = $department['contactform_id'];
- $name = $en?$department['contactform_eng_name']:$department['contactform_doctor_name'];
- ?>
- <h2 class="ether-title ether-toggle-button"><?php echo mb_strtoupper($name); ?></h2>
- <div class="ether-content ether-toggle-content doctors_list"><table width="0" border="0">
- <?php
- $contacts_model->setFilterString(
- 'contact_actual<>0 and contactform_contact_id in (select contactform_contact_id from dk_contacts_links where '.
- ' contactform_id='.$id.')',true);
- $contacts = $contacts_model->getPage(0,true);
- $contacts = $contacts['items'];
- $i=0;
- if (!$contacts) {
- continue;
- }
- foreach ($contacts as $contact) {
- if (!($i%3))
- echo '<tr>';
- ?>
- <td width="245" align="left" valign="top">
- <p><a href="<?php echo $en?$contact['contactform_contact_eng_url']:$contact['contactform_contact_url']; ?>"><img src="<?php
- echo $contact['contactform_contact_picture']?$contact['contactform_contact_picture']:'/wp-content/uploads/2014/09/shetinina.png';
- ?>"
- alt="<?php echo $en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name']; ?>"></a>
- <a href="<?php echo $en?$contact['contactform_contact_eng_url']:$contact['contactform_contact_url']; ?>"><div class="doctor_name">
- <?php
- $dname = $en?$contact['contactform_contact_eng_name']:$contact['contactform_contact_name'];
- $dname = strip_tags(str_replace(array('<br/>','<br>'),array(' ',' '),$dname));
- $dname = substr($dname,0, strpos($dname,' ')).'<br/>'.substr($dname, strpos($dname,' '));
- echo $dname;
- ?></div></a><div class="doctor_description">
- <?php echo $en?$contact['contactform_contact_eng_description']:$contact['contactform_contact_description'];?>
- </div></td>
- <?php
- $i++;
- if (!($i%3)) {
- echo '</tr>';
- }
- }
- ?> </table></div> <?php
- }
- ?> </div> <?php
- $content = ob_get_clean();
- return $content;
- }
- //---------------------------------------------------------
- // doctor content
- //---------------------------------------------------------
- public function doctor_content($content) {
- if (!is_single() && (!is_page())) {
- return $content;
- }
- global $post;
- $doctor_id = get_post_meta($post->ID, 'contactform_contact_id',true);
- if (!$doctor_id||$doctor_id<0)
- return $content;
- $doctor_id2 = get_post_meta($post->ID, 'contactform_contact_id2', true);
- if (preg_match('/\[dk_doctor_content\]/ims',$content, $matches, PREG_OFFSET_CAPTURE)) {
- $pos = $matches[0][1];
- $len = 0;
- $len2 = strlen($matches[0][0]);
- } else {
- if (!preg_match('/<img.*?>/ims', $content, $matches, PREG_OFFSET_CAPTURE)) {
- return $content;
- } else {
- $pos = $matches[0][1];
- $len = strlen($matches[0][0]);
- }
- }
- $s ='<div class="doctor_control_block">';
- $s .= '<div class="ether-widget ether-multi ether-multi-1 ether-type-acc ether-acc-x">';
- $s .= '<h2 class="ether-title ether-toggle-button" style="background:#a35ea0!important">Записаться на прием</h2>
- <div class="ether-content ether-toggle-content">';
- $s .= $this->appointmentform_shortcode(array());
- $s .= '</div>';
- $s .= '<h2 class="ether-title ether-toggle-button">Задать вопрос</h2>';
- $s .= '<div class="ether-content ether-toggle-content">';
- $s .= $this->contactform_shortcode(array('id2'=>$doctor_id));
- $s .= '</div>';
- $s .= '<h2 class="ether-title ether-toggle-button">Оставить отзыв</h2>
- <div class="ether-content ether-toggle-content">';
- $s .= $this->otzyvfull_shortcode(array('id'=>$doctor_id));
- $s .= '</div></div>';
- $s .= '<div class="doctor-otzyv-block">';
- $otzyvy = $this->otzyv_list_shortcode(array('id2'=>$doctor_id, 'id3'=>$doctor_id2));
- if ($otzyvy) {
- $s .= '<h3>Отзывы</h3>'.$otzyvy;
- }
- $s .= '</div>';
- $s .= '</div>';
- if (!$len2) {
- $len2 = $len;
- }
- $content = substr($content,0, $pos+$len).$s.substr($content,$pos+$len2);
- return $content;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment