<?php
class UtilsController{
    private $model;

    function __construct(){
        $this->model = new UtilsModel();
    }

    public function saveJSError(){
        $message = isset($_REQUEST['message']) ? $_REQUEST['message'] : '';
        $stack = isset($_REQUEST['stack']) ? $_REQUEST['stack'] : '';
        $this->model->saveJSError($message, $stack);
    }

    public function checkActivityStatus(){
        echo json_encode($this->model->checkActivityStatus());
    }

    public function sendTestMail(){
        echo $this->model->sendTestMail();
    }

    public function errorDialogTemplate(){
        require_once('templates/errorDialogTemplate.php');
    }

    public function activityCheckerTemplate(){
        require_once('templates/activityCheckerTemplate.php');
    }

    public function changePassword() {
        $passwords = isset($_REQUEST['passwords']) ? $_REQUEST['passwords'] : '';
        echo json_encode($this->model->changePassword($passwords));
    }

    public function generateTokenForUserPassword() {
        $userInfo = isset($_REQUEST['userInfo']) ? $_REQUEST['userInfo'] : '';
        echo json_encode($this->model->generateTokenForAllUsersPassword($userInfo));
    }

    public function downloadFile(){
        $fileName = isset($_REQUEST['fileName']) ? $_REQUEST['fileName'] : '';
        $idDocument = isset($_REQUEST['idDocument']) ? $_REQUEST['idDocument'] : '';
        $fileType = isset($_REQUEST['fileType']) ? $_REQUEST['fileType'] : '';
        echo $this->model->downloadFile($idDocument, $fileName, $fileType);
    }
}
