public function actionResponse($id)
    {
        $response = new Response();
        $teacher = Teacher::model()->findByPk($id);
        $teacherRat=Response::model()->find('who=:whoID and about=:aboutID', array(':whoID'=>Yii::app()->user->getId(),':aboutID'=>$teacher->user_id));

        if ($_POST['sendResponse']) {
            if (!empty($_POST['response'])) {
                $response->who = Yii::app()->user->id;
                $response->about = $teacher->user_id;
                $response->date = date("Y-m-d H:i:s");
                $response->text = $response->bbcode_to_html($_POST['response']);
                if($teacherRat && $teacherRat->knowledge==$_POST['material'] && $teacherRat->behavior==$_POST['behavior'] && $response->motivation==$_POST['motiv']){
                    $response->knowledge = Null;
                    $response->behavior = Null;
                    $response->motivation = Null;
                    $response->rate = Null;
                } if($teacherRat && ($teacherRat->knowledge!==$_POST['material'] || $teacherRat->behavior!==$_POST['behavior'] || $response->motivation!==$_POST['motiv'])){
                    $teacherRat->knowledge = $_POST['material'];
                    $teacherRat->behavior = $_POST['behavior'];
                    $teacherRat->motivation = $_POST['motiv'];
                    $teacherRat->rate = round(($_POST['material'] + $_POST['behavior'] + $_POST['motiv']) / 3);
                    $teacherRat->save();
                }else{
                    $response->knowledge = $_POST['material'];
                    $response->behavior = $_POST['behavior'];
                    $response->motivation = $_POST['motiv'];
                    $response->rate = round(($_POST['material'] + $_POST['behavior'] + $_POST['motiv']) / 3);
                }
                $response->who_ip = $_SERVER["REMOTE_ADDR"];
                if($_POST['material']!=='' && $_POST['behavior']!=='' && $_POST['motiv']!==''){
                    $response->save();
                    $teacher->updateByPk($id, array('rate_knowledge' => $teacher->getAverageRateKnwl($teacher->user_id)));
                    $teacher->updateByPk($id, array('rate_efficiency' => $teacher->getAverageRateBeh($teacher->user_id)));
                    $teacher->updateByPk($id, array('rate_relations' => $teacher->getAverageRateMot($teacher->user_id)));
                    $teacher->updateByPk($id, array('rating' => $teacher->getAverageRate($teacher->user_id)));
                    Yii::app()->user->setFlash('messageResponse', Yii::t('response', '0386'));
                } else {
                    Yii::app()->user->setFlash('responseError', Yii::t('response', '0385'));
                }
            }
            header('Location: ' . $_SERVER['HTTP_REFERER']);
        }
    }