<?php
include_once(_DIR_TO_CLASS.'/c_page.php');
class c_page_cab_poll_answer_card extends c_page
{
    public $h1='Опрос - карточка ответа';
    public $rec_answer ;
    var $use_fusioncharts=1 ;

    function __construct($options=array())
    {   if (_CUR_ROOT_DIR_NAME=='frame') $this->body_class='no_menu';
        parent::__construct($options);
    }

    function set_head_tags()
    {   parent::set_head_tags();
        $this->HEAD['css'][]=_PATH_TO_EXT.'/poll/style.css';
    }

    function select_obj_info()
     { if (_CUR_ID)
       { $this->rec_answer=POLL()->get_answer_by_id(_CUR_ID) ;
         if ($this->rec_answer['pkey'])
         { //$this->h1=$this->rec_theme['obj_name'] ;
           //$arr=TREE('poll_themes')->get_arr_parents_names($this->rec_answer['pkey'],array('from_level'=>2)) ;
           //$this->h1=($this->rec_answer['level']>1)? implode(' / ',$arr):$this->rec_answer['obj_name'] ;
           //$this->title=implode(' / ',$arr) ;
           $this->rec_answer['__href']='/'._CUR_ROOT_DIR_NAME.'/poll/answer/card/'.$this->rec_answer['pkey'].'/' ;

           $_SESSION['cur_obj_page_dir'][_CUR_ROOT_DIR_NAME][$this->rec_answer['tkey']][$this->rec_answer['clss']]=str_replace(_CUR_ID,'***',_CUR_PAGE_DIR) ;
         }
         if (!$this->rec_answer['pkey']) $this->result=404 ;
       } else $this->result=404 ;

     }


     function prepare_menu_config()
     {
         $child_cnt=TREE('poll_tree')->get_child_cnt($this->rec_answer['pkey']) ;
         //damp_array($child_cnt) ;

         $menu=[] ;
         $menu[$this->rec_answer['__href']]='Карточка ответа' ;
         if ($child_cnt[573]) $menu[$this->rec_answer['__href'].'questions/']=['title'=>'Дополнительные вопросы','info_value'=>'<span>'.$child_cnt[573].'</span>'] ;
         $menu[$this->rec_answer['__href'].'db/']='Исходные данные' ;

         return($menu) ;
     }

     function menu_config()
     {
        if (_CUR_ROOT_DIR_NAME=='window') $this->menu=$this->prepare_menu_config() ;
     }

     function second_menu_config()
     {
        if (_CUR_ROOT_DIR_NAME=='frame') $this->second_menu=$this->prepare_menu_config() ;
     }

     function panel_main_menu()
     {
         if (_CUR_ROOT_DIR_NAME!='frame') parent::panel_main_menu() ;
     }

    function block_main()
    {

			  ?><button class="button v1" href="/frame/poll/answer/card/<? echo $this->rec_answer['pkey'] ?>/new_question/">Добавить вопрос</button><?

		$cnt_questions=execSQL('select count(pkey) from poll_tree where parent='.$this->rec_answer['pkey']) ;
		if ($cnt_questions)
        {

          include_once(_DIR_EXT.'/poll/report_poll_section_stats_pie2d.php');
          include_once(_DIR_EXT.'/poll/report_poll_section_stats_angulargauge.php');
          // результаты опроса в виде радара
          $this->page_title() ;
          $arr_question_ids=execSQL_row('select pkey,answer_type from view_poll_questions where parent'.$this->rec_answer['level'].'='.$this->rec_answer['pkey']) ;

          ?><div id="reports_chart"><?
              if (_sizeof($arr_question_ids)) foreach($arr_question_ids as $question_id=>$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->answer_id=$this->rec_answer['pkey'];
          $report_obj->init();
          $report_obj->no_view_title=1;
          //$report_obj->setting();
          $report_obj->view();

          //execSQL_update('update poll_themes set parent=1,parent2=0,parent3=0,parent4=0,parent5=0,parent6=0,parent7=0,parent8=0,parent9=0,level=0') ;
          //execSQL_update('update poll_questions set parent=1,parent2=0,parent3=0,parent4=0,parent5=0,parent6=0,parent7=0,parent8=0,parent9=0,level=0') ;
          //execSQL_update('update poll_answers set parent=1') ;
          //execSQL_update('update poll_tree set obj_name=""') ;
         }
    }

}
