<?php
include_once(_DIR_TO_CLASS.'/c_page.php');

class c_page_cab_poll extends c_page
{
    public $rec_doc;
    public $h1='Опросы';
    var $use_fusioncharts=1;

    function second_menu_config()
    {
        $this->second_menu['/cab/poll/']=array('title'=>'Статистика');
        //$this->second_menu['/cab/poll/graf/']=array('title'=>'Оценка знаний');
        $this->second_menu['/cab/poll/sessions/']=array('title'=>'Сессии опросов');
        $this->second_menu['/cab/poll/results/']=array('title'=>'Результаты опросов');
        $this->second_menu['/frameset/poll/editor/']=array('title'=>'Редактор тем','new_window'=>'poll_tree');
        $this->second_menu['/cab/poll/collections/']=array('title'=>'Библиотека тем');
        $this->second_menu['/cab/poll/setting/']=array('title'=>'Настройки');
        $this->second_menu['/cab/poll/info/']=array('title'=>'Информация');
    }

    function get_cur_page_meta_tags()
    {
        //if (is_object($this->doc_obj)) $this->h1=$this->doc_obj->title ;
    }

    function block_main()
    {
        //$this->page_title();


        $this->panel_report_graf();
        //$this->get_snalyze_stats_graph();
        //$this->panel_report();

        //execSQL_update('update poll_questions set answer_type=2 where answer_type=0') ;
    }

    function panel_report_graf()
    {
      include_once(_DIR_EXT.'/poll/report_poll_section_stats_pie2d.php');
      include_once(_DIR_EXT.'/poll/report_poll_section_stats_angulargauge.php');
      // получаем все опросы по которым есть результаты
      $arr_question_info=execSQL('select t1.question_id,count(t1.pkey) as result_cnt,t2.answer_type,t2.parent as theme_id,t3.obj_name as theme_name
                                 from poll_result t1
                                 left join poll_questions t2 on t2.pkey=t1.question_id
                                 left join poll_themes t3 on t3.pkey=t2.parent
                                 group by t1.question_id
                                 ',0,1) ;

      $arr_question_info2=group_by_field('theme_id',$arr_question_info) ;
      //damp_array($arr_question_info2);
      if (_sizeof($arr_question_info2)) foreach($arr_question_info2 as $arr)
      { ?><h2>Опрос "<?echo $arr[0]['theme_name']?>"</h2><?
        { ?><div id="reports_chart"><?
          if (_sizeof($arr)) foreach($arr as $rec)
            { $question_id=$rec['question_id'] ;
              $answer_type=$rec['answer_type'] ;
                // $answer_type=1 - голосование баллами
                if ($answer_type==1)
                { $report_obj=new report_poll_section_stats_angulargauge();
                    $report_obj->no_view_title=1;
                    $report_obj->filter['question_id']=$question_id;
                    $report_obj->view_as_HTML();
                }

                // $answer_type=2 - голосование за ответы
                if ($answer_type==2)
                { $report_obj=new report_poll_section_stats_pie2d();
                  $report_obj->no_view_title=1;
                  $report_obj->filter['question_id']=$question_id;
                  $report_obj->view_as_HTML();
                }

          }
          ?><div class="clear"></div></div>
            <style type="text/css">
                div#reports_chart{}
                div#reports_chart div.radar_chart{float:left;margin-right:20px;margin-bottom:20px;}
                div#reports_chart div.chart_pie2d{float:left;margin-right:20px;margin-bottom:20px;}
            </style>
          <?

         }
      }

      // результаты опроса в табличной форме
      /*include_once(_DIR_EXT.'/poll/report_poll_question_result.php');
      $report_obj=new report_poll_question_result();
      $report_obj->section_id=1;
      $report_obj->init();
      $report_obj->no_view_title=1;
      //$report_obj->setting();
      //$report_obj->view();
      */
    }

    function panel_report()
    {
        include_once(_DIR_EXT.'/poll/report_poll_stats.php');
        $report_obj=new report_poll_stats();
        $report_obj->setting();
        $report_obj->view_as_HTML();
    }

    function get_snalyze_stats_graph()
    {   ?><div id="stats_chart_div"></div><?
        include_once(_DIR_EXT.'/poll/report_poll_stats3.php');
        $report1 = new report_poll_stats3(['filter'=>$_POST['cur_page_filter']]);
        $report1->no_view_title=1;
        $report1->view_panel_info=0;
        $report1->view_as_HTML(['chart_elem_id'=>'stats_chart_div']);
    }

}

?>
