<?
namespace directoriya\Modulcreator\Controller;
use Bitrix\Main\Engine\Controller;
use Bitrix\Main\Localization\Loc;
use CAllModulcreator;
use CAllModulcreatorInner;
use CAllModulcreatorTarBuilder;
use Bitrix\Main\Loader;
use CFile;
use COption;
use ZipArchive;
use \PharData;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
Loc::loadMessages(__FILE__);

class Allajax extends Controller{

    function updaterziptarAction() {
        global $APPLICATION;
        global $tar, $strFileList;
        $out="";
        $all_ms = urldecode($_REQUEST['ms']);
        parse_str($all_ms, $output_ms);
        $ms_check = self::checkArchivFields($output_ms);
        if($ms_check["fl"]===1) {
            return $ms_check['text'];
        }

        $events = GetModuleEvents("directoriya.modulcreator", "OnBeforeUpdateListCreate");
        while ($arEvent = $events->Fetch()){
            ExecuteModuleEventEx($arEvent, array($output_ms));
        }

        $flNewArchiv = 0;
        if (class_exists('PharData')) {
            $flNewArchiv = 1;
        }
        $arModuleVersion = array();
        $module_id = str_replace(array('..','/','\\'),'',$output_ms['in25']);
        $m_dir = $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$module_id;
        if ($module_id){
            if (file_exists($m_dir.'/install/version.php')) {
                include($m_dir . '/install/version.php');
            }
        }
        $strError = '';
        $strFileList = '<br><br> <b>'.GetMessage("MODULCREATOR_SPISOK_FAYLOV_V_ARHI").':</b><br>';
            function TarAddFile($tmp_dir, $f){
                global $tar, $strFileList;
                $strFileList .= substr($f, strlen($tmp_dir)).'<br>';
                return $tar->addFile($f);
            }
            if (!$v = $output_ms['in26']) {
                $strError .= GetMessage("MODULCREATOR_VERSIA_MODULA_NE_UKA") . '<br>';
            }

            if (!$output_ms['in29']) {
                $strError .= GetMessage("MODULCREATOR_NE_UKAZANO_OPISANIE") . '<br>';
            }

            $strVersion =
                '<'.'?'."\n".
                '$arModuleVersion = array('."\n".
                '	"VERSION" => "'.EscapePHPString($v).'",'."\n".
                '	"VERSION_DATE" => "'.date('Y-m-d H:i:s').'"'."\n".
                ');'."\n".
                '?'.'>';

            if (!$strError && ($output_ms['in27'] == 'on' || $output_ms['in27'] == 27)){
                rename($m_dir.'/install/version.php', $m_dir.'/install/_version.php');
                if (!file_put_contents($f = $m_dir.'/install/version.php', $strVersion)) {
                    $strError .= GetMessage("BITRIX_MPBUILDER_NE_UDALOSQ_ZAPISATQ") . $f . '<br>';
                }
            }
            $fl_zip = false;
            if (!$strError)
            {
                if (is_dir($tmp_dir = $_SERVER['DOCUMENT_ROOT'].BX_ROOT.'/tmp/'.$module_id)) {
                    self::BuilderRmDir($tmp_dir);
                }
                mkdir($tmp_dir.'/'.$v, BX_DIR_PERMISSIONS, true);
                if (function_exists('mb_internal_encoding')) {
                    mb_internal_encoding('ISO-8859-1');
                }
                if($flNewArchiv === 0) {
                    $tar = new CAllModulcreatorTarBuilder;
                    $tar->path = $tmp_dir;
                    $openTar = $tar->openWrite($f = $tmp_dir.'/'.$v.'.tar.gz');
                }else {
                    $openTar=1;
                }
                if (!$openTar) {
                    $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_OTKRYTQ_F") . $f . '<br>';
                }else{
                    $ar = self::BuilderGetFiles($m_dir, array(), true);
                    $time_from = strtotime($arModuleVersion['VERSION_DATE']);
                    foreach($ar as $file){

                        $from = $m_dir.$file;
                        $to = $tmp_dir.'/'.$v.$file;
                        if ($file == '/install/_version.php' || self::check_file_ext($file) === 1) {
                            continue;
                        }
                        if ($file == '/install/version.php'){
                            if ($_REQUEST['store_version'] && !file_put_contents($from, $strVersion))
                                $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_ZAPISAT_FROM").$from.'<br>';

                            if (!file_exists($dir = dirname($to))) {
                                mkdir($dir, BX_DIR_PERMISSIONS, true);
                            }
                            if(file_put_contents($to, $strVersion)) {
                                if($flNewArchiv === 0) {
                                    TarAddFile($tmp_dir, $to);
                                }else {
                                    $strFileList .= substr($to, strlen($tmp_dir)).'<br>';
                                }
                            }else {
                                $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_ZAPISAT_TO") . $to . '<br>';
                            }
                            continue;
                        }
                        if (filemtime($from) < $time_from) {
                            continue;
                        }
                        if (false === $str = file_get_contents($from)) {
                            $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_PROCITAT_IZ") . $from . '<br>';
                        }else{
                            if (substr($file, -4) == '.php' && self::GetStringCharset($str) == 'utf8') {
                                $str = $APPLICATION->ConvertCharset($str, 'utf8', 'cp1251');
                            }

                            if (!file_exists($dir = dirname($to))) {
                                mkdir($dir, BX_DIR_PERMISSIONS, true);
                            }

                            if (false === file_put_contents($to, $str)) {
                                $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_SOHRANIT_TO") . $to . '<br>';
                            }else {
                                if($flNewArchiv === 0) {
                                    TarAddFile($tmp_dir, $to);
                                }else {
                                    $strFileList .= substr($to, strlen($tmp_dir)).'<br>';
                                }
                            }
                        }
                    }
                    if (!$strError){
                        $f = $tmp_dir.'/'.$v.'/description.ru';
                        $description = $output_ms['in29'];
                        if (defined('BX_UTF') && BX_UTF) {
                            $description = $APPLICATION->ConvertCharset($description, 'utf8', 'cp1251');
                        }
                        if(file_put_contents($f, $description)) {
                            if($flNewArchiv === 0) {
                                TarAddFile($tmp_dir, $f);
                            }else {
                                $strFileList .= substr($f, strlen($tmp_dir)).'<br>';
                            }
                        }else {
                            $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_ZAPISAT_FILE") . $f . '<br>';
                        }
                    }
                    if($output_ms['in30'] == 'on' || $output_ms['in30'] == 30) {
                        $put = $_SERVER['DOCUMENT_ROOT'].$output_ms['in31'];
                        $str = file_get_contents($put);
                        if (file_put_contents($f = $tmp_dir . '/' . $v . '/updater.php', $str)) {
                            if($flNewArchiv === 0) {
                                TarAddFile($tmp_dir, $f);
                            }else {
                                $strFileList .= substr($f, strlen($tmp_dir)).'<br>';
                            }
                        } else {
                            $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_SOHRANIT_FILE") . $f;
                        }

                    }else {
                        if (!$strError && ($str = trim($output_ms['in28']))) {
                            if (file_put_contents($f = $tmp_dir . '/' . $v . '/updater.php', $str)) {
                                if($flNewArchiv === 0) {
                                    TarAddFile($tmp_dir, $f);
                                }else {
                                    $strFileList .= substr($f, strlen($tmp_dir)).'<br>';
                                }
                            } else {
                                $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_SOHRANIT_FILE") . $f;
                            }
                        }
                    }
                    //Зиплю
                    if($flNewArchiv === 0) {
                        $fromZip = $tmp_dir . '/';
                        $fl_zip = self::Zip($fromZip . "/" . $v . "/", $fromZip . '/' . $v . '.zip', $v);
                    }
                    if($flNewArchiv === 0) {
                        $tar->close();
                    }
                    //
                    /*Новый метод */
                    if($flNewArchiv === 1) {
                        $fl_zip = self::tarGzArchivUpdate($tmp_dir, $v,$output_ms);
                    }
                    /* Пост обработки Обновление*/
                    $fl=0;
                    $ip = 40;
                    if(isset($output_ms['in'.$ip])) {
                        if(strlen($output_ms['in'.$ip])>0) {
                            if($output_ms['in'.$ip] == "on" || $output_ms['in'.$ip] == $ip) {
                                $fl=1;
                            }
                            $fl=1;
                        }
                    }
                    if($fl === 1) {
                        $ip = 41;
                        if(isset($output_ms['in'.$ip])) {
                            if(strlen($output_ms['in'.$ip])>0) {
                                $put1 = $_SERVER['DOCUMENT_ROOT'].$output_ms['in'.$ip];
                                if( file_exists($put1)) {
                                    $str = file_get_contents($put1);
                                    $str = preg_replace("/^[\s\r\n]*?<\?php/","",$str);
                                    $str = preg_replace("/^[\s\r\n]*?<\?/","",$str);
                                    $str = preg_replace("/[\s\r\n]*?\?>$/","",$str);
                                    $e = eval($str);
                                }
                                $put1="";
                            }
                        }

                    }

                }
            }

        $fl=0;
        if (isset($strError)) {
            if (strlen($strError)>0) {
                $fl=1;
            }

        }
        if($fl=== 1) {
            $out='
            <div class="adm-info-message-wrap adm-info-message-red">
				<div class="adm-info-message w-100">
					<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_ERR_OBR_FILE").'</div>
					'.$strError.'
					<div class="adm-info-message-icon"></div>
				</div>
			</div>
            ';

        }else {
            if($fl_zip === false) {
                $link1 = '/bitrix/tmp/' . $module_id . '/' . $v . '.tar.gz';
                $out = '
            <div class="adm-info-message-wrap adm-info-message-green">
            <div class="adm-info-message w-100">
				<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_ARCH_OK").'</div>
				'.GetMessage("MODULCREATOR_AJAX_ARCH_OK_LINK").':<br>
				<a href="' . $link1 . '">' . $link1 . '</a><br />
				<div class="adm-info-message-icon"></div>
			</div>
			</div>
            ';
            }else{
                $link1 = '/bitrix/tmp/' . $module_id . '/' . $v . '.tar.gz';
                $link2 = '/bitrix/tmp/' . $module_id . '/' . $v . '.zip';
                $out = '
            <div class="adm-info-message-wrap adm-info-message-green">
            <div class="adm-info-message w-100">
				<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_ARCH_OK").'</div>
				'.GetMessage("MODULCREATOR_AJAX_ARCH_OK_LINK").':<br>
				<a href="' . $link1 . '">' . $link1 . '</a><br /> '.GetMessage("MODULCREATOR_AJAX_I").' <br />
				<a href="' . $link2 . '">' . $link2 . '</a>'.$strFileList.'  
				<div class="adm-info-message-icon"></div>
			</div>
			</div>
            ';
            }
        }

        /**/
        return $out;
    }
    function tarGzArchivUpdate($from, $v,$output_ms) {

        $events = GetModuleEvents("directoriya.modulcreator", "OnBeforeUpdateArchivCreate");
        while ($arEvent = $events->Fetch()){
            ExecuteModuleEventEx($arEvent, array($from,$v,$output_ms));
        }
        $out = true;
        $path_from = $from."/".$v."/";
        file_put_contents($_SERVER['DOCUMENT_ROOT']."/1.txt", print_r( $from, true)."\r\n", FILE_APPEND);
        file_put_contents($_SERVER['DOCUMENT_ROOT']."/1.txt", print_r( $path_from, true)."\r\n", FILE_APPEND);
        $path_to = $_SERVER['DOCUMENT_ROOT'].'/bitrix/tmp/1/'.$v;
        $path_to_tmp = $_SERVER['DOCUMENT_ROOT'].'/bitrix/tmp/1/';
        CopyDirFiles($path_from,$path_to,true,true,false,"");
        $put_tar_tmp = $from."/".$v.'.tar';
        $phar = new PharData($put_tar_tmp);
        $phar->buildFromDirectory($path_to_tmp);
        $phar->compress(\Phar::GZ);
        unlink($put_tar_tmp);
        // Zip
        $put_old_zip = $from."/".$v.'.zip';
        $phar = new PharData($put_old_zip);
        $phar->buildFromDirectory($path_to_tmp);
        $path_to_tmp = str_replace("\\","/",$path_to_tmp);
        $dd = self::recurse_delete_files($path_to_tmp);

        $events = GetModuleEvents("directoriya.modulcreator", "OnAfterUpdateArchivCreate");
        while ($arEvent = $events->Fetch()){
            ExecuteModuleEventEx($arEvent, array($from,$v,$output_ms));
        }
        return $out;
    }
    function tarGzArchivFull($from, $output_ms) {
        $events = GetModuleEvents("directoriya.modulcreator", "OnBeforeFullArchivCreate");
        while ($arEvent = $events->Fetch()){
            ExecuteModuleEventEx($arEvent, array($from,$output_ms));
        }
        $out = true;
        $path_from = $from."/.last_version/";
        $path_to = $_SERVER['DOCUMENT_ROOT'].'/bitrix/tmp/1/.last_version';
        $path_to_tmp = $_SERVER['DOCUMENT_ROOT'].'/bitrix/tmp/1/';
        CopyDirFiles($path_from,$path_to,true,true,false,"");
        $put_tar_tmp = $from."/.last_version.tar";
        $phar = new PharData($put_tar_tmp);
        $phar->buildFromDirectory($path_to_tmp);
        $phar->compress(\Phar::GZ);
        unlink($put_tar_tmp);
        //Зип
        $put_old_zip = $from.'/.last_version.zip';
        $phar = new PharData($put_old_zip);
        $phar->buildFromDirectory($path_to_tmp);
        $path_to_tmp = str_replace("\\","/",$path_to_tmp);
        $dd = self::recurse_delete_files($path_to_tmp);

        $events = GetModuleEvents("directoriya.modulcreator", "OnAfterFullArchivCreate");
        while ($arEvent = $events->Fetch()){
            ExecuteModuleEventEx($arEvent, array($from,$output_ms));
        }
        return $out;
    }
    function recurse_delete_files($path) {
        $path = rtrim($path,"/");
        $path = rtrim($path,"\\");
        if (is_file($path)){
            unlink($path);
            return 1;
        }
        if (is_dir($path)) {
            foreach(scandir($path) as $p){
                if (($p!='.') && ($p!='..')){
                    self::recurse_delete_files($path.DIRECTORY_SEPARATOR.$p,$path2,$fl);
                }
            }
            rmdir($path);
            return 2;
        }
        return 3;
    }



    function check_file_ext($file) {
        $out = 0;
        if(strlen($file)>0) {
            $ext = GetFileExtension($file);
            if($ext == 'arj' || $ext == 'zip' || $ext == 'tar' || $ext == 'gz') {
                $out=1;
            }
        }
        return $out;
    }
    function setversioninputAction() {
        $all_ms = urldecode($_REQUEST['ms']);
        parse_str($all_ms, $output_ms);
        $out='<div class="adm-info-message-wrap adm-info-message-red">
				<div class="adm-info-message">
					<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_ERR_READ_CURR_VER").'</div>
					'.GetMessage("MODULCREATOR_AJAX_PROVER_FILE").' /bitrix/modules/'.$output_ms['in25'].'/install/version.php
					<div class="adm-info-message-icon"></div>
				</div>
			</div>';
        $fl=0;
        if(isset($output_ms['in25'])) {
            $output_ms['in25'] = str_replace(array('..','/','\\'),'',$output_ms['in25']);
            if(strlen($output_ms['in25'])>0) {
                $put = $_SERVER['DOCUMENT_ROOT']."/bitrix/modules/".$output_ms['in25']."/install/version.php";
                if(file_exists($put)) {
                    if(is_writable($put)) {
                        include ($put);
                        if(isset($arModuleVersion['VERSION'])) {
                            if(strlen($arModuleVersion['VERSION'])>0) {
                                $out=$arModuleVersion['VERSION'];
                                $fl=1;
                            }
                        }
                    }
                }
            }
        }
        if(strlen($output_ms['in25']) === 0) {
            return array("fl" => 2, "out" => $out);
        }else {
            return array("fl" => $fl, "out" => $out);
        }
    }
    function checkArchivFields($output_ms){
        $out=Array("fl"=>0,'text'=>"");
        $fl_opt = 0;
        $err_msg = "";
        $flNeg = 0;
        if(isset($output_ms['in25'])){
            if(strlen($output_ms['in25'])>0){
                $flNeg = 1;
            }
        }
        if($flNeg === 0) {
            $out["fl"]=1;
            $fl_opt = 1;
            $err_msg = GetMessage("MODULCREATOR_NOFILEDMODUL_PODROBNO");
        }
        $fl_38=0;
        $fl_39=0;
        $ip = 38;
        if(isset($output_ms['in'.$ip])) {
            if($output_ms['in'.$ip] == 38 || $output_ms['in'.$ip] == 'on') {
                $fl_38=1;
            }
        }
        if($fl_38 === 1) {
            $ip = 39;
            if (isset($output_ms['in' . $ip])) {
                if (strlen($output_ms['in' . $ip]) > 0) {
                    $put1 = $_SERVER['DOCUMENT_ROOT'] . $output_ms['in' . $ip];
                    if (file_exists($put1)) {
                        $fl_39=1;
                    }
                    $put1 = "";
                }
            }
        }
        if($fl_38 === 1 && $fl_39 === 0) {
            $fl_opt = 1;
            $out["fl"]=1;
            if(strlen($err_msg) === 0) {
                $err_msg = GetMessage("MODULCREATOR_POST_FILE_NOTFOUND_FULL");
            }else {
                $err_msg = $err_msg.'<br />'.GetMessage("MODULCREATOR_POST_FILE_NOTFOUND_FULL");
            }
        }
        /**/
        $fl_40=0;
        $fl_41=0;
        $ip = 40;
        if(isset($output_ms['in'.$ip])) {
            if($output_ms['in'.$ip] == 40 || $output_ms['in'.$ip] == 'on') {
                $fl_40=1;
            }
        }
        if($fl_40 === 1) {
            $ip = 41;
            if (isset($output_ms['in' . $ip])) {
                if (strlen($output_ms['in' . $ip]) > 0) {
                    $put1 = $_SERVER['DOCUMENT_ROOT'] . $output_ms['in' . $ip];
                    if (file_exists($put1)) {
                        $fl_41=1;
                    }
                    $put1 = "";
                }
            }
        }
        if($fl_40 === 1 && $fl_41 === 0) {
            $out["fl"]=1;
            $fl_opt = 1;
            if(strlen($err_msg) === 0) {
                $err_msg = GetMessage("MODULCREATOR_POST_FILE_NOTFOUND_UPDATE");
            }else {
                $err_msg = $err_msg.'<br />'.GetMessage("MODULCREATOR_POST_FILE_NOTFOUND_UPDATE");
            }
        }
        /**/
        if($fl_opt === 1) {
            $out['text']='
            <div class="adm-info-message-wrap adm-info-message-red">
				<div class="adm-info-message w-100">
					<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_NOFILEDMODUL").':</div>
					'.$err_msg.'
					<div class="adm-info-message-icon"></div>
				</div>
			</div>
            ';
        }
        return $out;
    }
    function fillziptarAction() {
        global $APPLICATION;
        $all_ms = urldecode($_REQUEST['ms']);
        parse_str($all_ms, $output_ms);
        $ms_check = self::checkArchivFields($output_ms);
        if($ms_check["fl"]===1) {
            return $ms_check['text'];
        }

        $events = GetModuleEvents("directoriya.modulcreator", "OnBeforeFullListCreate");
        while ($arEvent = $events->Fetch()){
            ExecuteModuleEventEx($arEvent, array($output_ms));
        }

        $flNewArchiv = 0;
        if (class_exists('PharData')) {
            $flNewArchiv = 1;
        }
        $module_id0 = str_replace(array('..','/','\\'),'',$output_ms['in25']);
        $module_id = $module_id0;
        $m_dir = $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/'.$module_id;
        if (is_dir($tmp = $_SERVER['DOCUMENT_ROOT'].BX_ROOT.'/tmp/'.$module_id)) {
            self::BuilderRmDir($tmp);
        }
        mkdir($tmp.'/.last_version', BX_DIR_PERMISSIONS, true);
        if (function_exists('mb_internal_encoding')) {
            mb_internal_encoding('ISO-8859-1');
        }
        if($flNewArchiv === 0) {
            $tar = new CAllModulcreatorTarBuilder;
            $tar->path = $tmp;
            $openTar = $tar->openWrite($f = $tmp.'/.last_version.tar.gz');
        }else {
            $openTar = 1;
        }

        $fl_zip = false;
        if (!$openTar) {
            $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_OTKRYTQ_F") . $f . '<br>';
        }else {
            $ar = self::BuilderGetFiles($m_dir, array('.svn', '.hg', '.git'), true);
            foreach($ar as $file){
                if (self::check_file_ext($file) === 1) {
                    continue;
                }
                $from = $m_dir.$file;
                $to = $tmp.'/.last_version'.$file;
                if (false === $str = file_get_contents($from)) {
                    $strError .=  GetMessage("MODULCREATOR_NE_UDALOSQ_ZAPISAT_FROM") . $from . '<br>';
                }else{
                    if (substr($file, -4) == '.php' && self::GetStringCharset($str) == 'utf8')
                        $str = $APPLICATION->ConvertCharset($str, 'utf8', 'cp1251');

                    if (!file_exists($dir = dirname($to)))
                        mkdir($dir, BX_DIR_PERMISSIONS, true);

                    if (false === file_put_contents($to, $str)){
                        $strError .= GetMessage("MODULCREATOR_NE_UDALOSQ_SOHRANIT_TO").$to.'<br>';
                    }else{
                        if($flNewArchiv === 0) {
                            $tar->addFile($to);
                        }
                    }
                }
            }
            if($flNewArchiv === 0) {
                $tar->close();
                $fromZip = $tmp.'/';
                $fl_zip = self::Zip($fromZip.".last_version/", $fromZip.'/.last_version.zip',".last_version");
            }
            if($flNewArchiv === 1) {
                $fl_zip = self::tarGzArchivFull($tmp,$output_ms);
            }

            /* Пост обработки Полный архив*/
            $fl=0;
            $ip = 38;
            if(isset($output_ms['in'.$ip])) {
                if(strlen($output_ms['in'.$ip])>0) {
                    if($output_ms['in'.$ip] == "on" || $output_ms['in'.$ip] == $ip) {

                        $fl=1;
                    }
                    $fl=1;
                }
            }
            if($fl === 1) {
                $ip = 39;
                if(isset($output_ms['in'.$ip])) {
                    if(strlen($output_ms['in'.$ip])>0) {
                        $put1 = $_SERVER['DOCUMENT_ROOT'].$output_ms['in'.$ip];
                        if( file_exists($put1)) {
                            $str = file_get_contents($put1);
                            $str = preg_replace("/^[\s\r\n]*?<\?php/","",$str);
                            $str = preg_replace("/^[\s\r\n]*?<\?/","",$str);
                            $str = preg_replace("/[\s\r\n]*?\?>$/","",$str);
                            $e = eval($str);
                        }
                        $put1="";
                    }
                }

            }
        }
        $fl=0;
        if (isset($strError)) {
            if (strlen($strError)>0) {
                $fl=1;
            }

        }
        if($fl=== 1) {
            $out='
            <div class="adm-info-message-wrap adm-info-message-red">
				<div class="adm-info-message w-100">
					<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_ERR_OBR_FILE").'</div>
					'.$strError.'
					<div class="adm-info-message-icon"></div>
				</div>
			</div>
            ';

        }else {
            if($fl_zip === false) {
                $link1 = '/bitrix/tmp/' . $module_id . '/.last_version.tar.gz';
                $out = '
            <div class="adm-info-message-wrap adm-info-message-green">
            <div class="adm-info-message w-100">
				<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_ARCH_OK").'</div>
				'.GetMessage("MODULCREATOR_AJAX_ARCH_OK_LINK").':<br>
				<a href="' . $link1 . '">' . $link1 . '</a><br />
				<div class="adm-info-message-icon"></div>
			</div>
			</div>
            ';
            }else{
                $link1 = '/bitrix/tmp/' . $module_id . '/.last_version.tar.gz';
                $link2 = '/bitrix/tmp/' . $module_id . '/.last_version.zip';
                $out = '
            <div class="adm-info-message-wrap adm-info-message-green">
            <div class="adm-info-message w-100">
				<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_ARCH_OK").'</div>
				'.GetMessage("MODULCREATOR_AJAX_ARCH_OK_LINK").':<br>
				<a href="' . $link1 . '">' . $link1 . '</a><br /> '.GetMessage("MODULCREATOR_AJAX_I").' <br />
				<a href="' . $link2 . '">' . $link2 . '</a> 
				<div class="adm-info-message-icon"></div>
			</div>
			</div>
            ';
            }
        }

        return $out;
    }
    function Zip($source, $destination,$ostavit){
        if (!extension_loaded('zip') || !file_exists($source)) {
            return false;
        }
        $zip = new ZipArchive();
        if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
            return false;
        }
        $source = str_replace('\\', '/', realpath($source));
        if (is_dir($source) === true){
            $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
            foreach ($files as $file){
                $file = str_replace('\\', '/', $file);
                // Ignore "." and ".." folders
                if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) ){
                    continue;
                }
                $file = realpath($file);
                $file = str_replace('\\', '/', $file);//Странно
                if (is_dir($file) === true){
                    /*Оставляю папкку last_version */
                    $zamena = str_replace("/".$ostavit, '', $source);
                    $zip->addEmptyDir(str_replace($zamena . '/', '', $file . '/'));
                }else if (is_file($file) === true){
                    $zamena = str_replace("/".$ostavit, '', $source);
                    $zip->addFromString(str_replace($zamena . '/', '', $file), file_get_contents($file));
                }
            }
        }else if (is_file($source) === true){
            $zip->addFromString(basename($source), file_get_contents($source));
        }
        return $zip->close();
    }
    function GetStringCharset($str){
        global $APPLICATION;
        if (preg_match("/[\xe0\xe1\xe3-\xff]/",$str))
            return 'cp1251';
        $str0 = $APPLICATION->ConvertCharset($str, 'utf8', 'cp1251');
        if (preg_match("/[\xe0\xe1\xe3-\xff]/",$str0,$regs))
            return 'utf8';
        return 'ascii';
    }
    function BuilderRmDir($path){
        if (!is_dir($path))
            return;
        $dir = opendir($path);
        while(false !== $item = readdir($dir))
        {
            if ($item == '.' || $item == '..')
                continue;
            $f = $path.'/'.$item;
            if (is_dir($path.'/'.$item))
                self::BuilderRmDir($f);
            else
                unlink($f);
        }
        closedir($dir);
        rmdir($path);
    }
    function BuilderGetFiles($path, $arFilter = array(), $bAllFiles = false, $recursive = false){
        static $len;
        if (!$recursive || !$len)
            $len = strlen($path);

        $retVal = array();
        if ($dir = opendir($path))
        {
            while(false !== $item = readdir($dir))
            {
                if (in_array($item, array_merge(array('.', '..', '.svn', '.hg', '.git'),$arFilter)))
                    continue;
                if (is_dir($f = $path.'/'.$item))
                    $retVal = array_merge($retVal, self::BuilderGetFiles($f, $arFilter, $bAllFiles, true));
                else
                {
                    if ($bAllFiles || substr($f,-4) == '.php')
                        $retVal[] = str_replace('\\','/',substr($f,$len));
                }
            }
            closedir($dir);
        }
        return $retVal;
    }
    function GetgramatikAction() {
        $out="";
        $all_ms = urldecode($_REQUEST['ms']);
        parse_str($all_ms, $output_ms);
        $err = CAllModulcreator::CheckFields($output_ms);
        if(strlen($err)>0) {
            $out='
            <div class="adm-info-message-wrap adm-info-message-red">
				<div class="adm-info-message w-100">
					<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_TIT_MAKE").':</div>
					'.$err.'
					<div class="adm-info-message-icon"></div>
				</div>
			</div>
            ';
            return $out;
        }

        if($output_ms['in3'] == "on" || $output_ms['in3'] == 3) {
            $putFrom1 = $_SERVER['DOCUMENT_ROOT']."/bitrix/components/".$output_ms['in4'];
            $putFrom2 = $_SERVER['DOCUMENT_ROOT']."/bitrix/modules/".$output_ms['in1'].".".$output_ms['in2'];

            $str1 = self::read_folder_php_file($putFrom1,"");
            $str2 = self::read_folder_php_file($putFrom2,"");
            $strAll =$str1.",".$str2;
        }else {
            $putFrom2 = $_SERVER['DOCUMENT_ROOT']."/bitrix/modules/".$output_ms['in1'].".".$output_ms['in2'];
            $strAll = self::read_folder_php_file($putFrom2,"");

        }

        $ms = explode(",",$strAll);

        foreach($ms as $val) {

            $ext = GetFileExtension($val);
            if($ext == "php") {
                $lang_content = file_get_contents($val);
                $patern = "/[^'^\"][\$]MESS[\s]*?\[[\s]*?[\"\']{1}([^^]+?)[\"\']{1}[\s]*?\][\s]*?=[\s]*?[\"\']{1}([^^]*?)[\"\']{1}[^^]*?;/";
                preg_match_all($patern,$lang_content,$ms_reg,PREG_PATTERN_ORDER);
                //echo "<pre>";print_r( $ms_reg );echo "</pre>";
                if(isset($ms_reg[2])) {
                    if(is_array($ms_reg[2])) {
                        if(count($ms_reg[2])>0) {
                            $out = $out.$val."<br>";
                            foreach ($ms_reg[2] as $val2) {
                                if(strlen($val2)===0) {
                                    $out_text = '<span class="cl-red">'.GetMessage("MODULCREATOR_NO_MESS_LANG").'</span>';
                                }else {
                                    $out_text = $val2;
                                }
                                //$out_text = $val2;
                                $out = $out.$out_text."<br>";
                            }
                            $out = $out."<br><br><br>";
                        }
                    }
                }

            }

        }
        return $out;
    }

    function zamenaparnermodulAction() {
        $all_ms = urldecode($_REQUEST['ms']);
        parse_str($all_ms, $output_ms);
        $err = CAllModulcreator::CheckFields($output_ms);

        if(strlen($err)>0) {
            $out='
            <div class="adm-info-message-wrap adm-info-message-red">
				<div class="adm-info-message w-100">
					<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_TIT_MAKE").':</div>
					'.$err.'
					<div class="adm-info-message-icon"></div>
				</div>
			</div>
            ';
            return $out;
        }


        $partNew = trim($output_ms['in22']);
        $modulNew = trim($output_ms['in23']);
        $newnameprj = trim($output_ms['in24']);
        $root = $_SERVER['DOCUMENT_ROOT'];
        $put_new = $root . "/bitrix/modules/" . $partNew . "." . $modulNew."/";
        $part = trim($_REQUEST['part']);
        $modul = trim($_REQUEST['modul']);
        if(!is_dir($put_new)){
            mkdir($put_new,BX_DIR_PERMISSIONS,true);
        }
        $put_from = $root . "/bitrix/modules/" . $part . "." . $modul."/";
        $put_to = $root . "/bitrix/modules/" . $partNew . "." . $modulNew."/";
        $put_to_2 = $root . "/bitrix/modules/" . $partNew . "." . $modulNew;
        CopyDirFiles($put_from,$put_to,true,true,false);
        $arrFiels0 = $output_ms;
        $arrFiels0['in1'] = $partNew;
        $arrFiels0['in2'] = $modulNew;
        $arrFiels = Array("NAME" => $newnameprj,"SORT" => $output_ms['SORT_PRJ'],"ALL_DATA" => serialize($arFields0));
        $id = CAllModulcreatorInner::Add($arrFiels);
        $out = self::set_replace_lang_and_class($put_to_2,$partNew,$modulNew,$output_ms);
        //$out ='<b>'.GetMessage("MODULCREATOR_AJAX_NEW_PRJ_OK").':</b><br />"'.$newnameprj.'", '.GetMessage("MODULCREATOR_AJAX_NEW_PRJ_ID").'- '.$id.'<br /><br />'.$out;
        $out = '
            <div class="adm-info-message-wrap adm-info-message-green">
            <div class="adm-info-message w-100-1">
				<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_NEW_PRJ_OK").'</div>
				'.$newnameprj.', '.GetMessage("MODULCREATOR_AJAX_NEW_PRJ_ID").'- '.$id.'
				<div class="adm-info-message-icon"></div>
			</div>
			</div>
            '.$out;;
        return $out;

    }
    function read_folder_php_file($folder,$out){
        $files = scandir($folder);
        foreach($files as $file){
            if ($file == '.' || $file == '..'){
                continue;
            }
            $fullfilename = $folder . '/' . $file;
            if(is_file($fullfilename)){
                if(strlen($out)>0){
                    $out = $out.",".$fullfilename;
                }else{
                    $out = $fullfilename;
                }
            }

            if (is_dir($fullfilename)){
                $out = self::read_folder_php_file($fullfilename,$out);
            }
        }
        return $out;
    }
    function get_file_dir($str){
        $put_ms = explode("/",$str);
        $file_name = $put_ms[(count($put_ms)-1)];
        $file_dir = str_replace($file_name,"",$str);
        return $file_dir;
    }
    function get_file_name($str){
        $put_ms = explode("/",$str);
        $file_name = $put_ms[(count($put_ms)-1)];
        return $file_name;
    }
    function read_only_folder($folder,$out){
        $files = scandir($folder);
        foreach($files as $file){
            if ($file == '.' || $file == '..'){
                continue;
            }
            $fullfilename = $folder . '/' . $file;
            if (is_dir($fullfilename)){
                if(strlen($out)>0){
                    $out = $out.",".$fullfilename;
                }else{
                    $out = $fullfilename;
                }
                $out = self::read_only_folder($fullfilename,$out);
            }
        }
        return $out;
    }
    function set_replace_lang_and_class($put_to,$partNew,$modulNew,$output_ms){
        $str = self::read_folder_php_file($put_to,"");
        $ms = explode(",",$str);
        $part_old = trim($output_ms['in1']);
        $modul_old = trim($output_ms['in2']);
        $part_old_tochka_modul = $part_old.".".$modul_old;
        $part_new_tochka_modul = $partNew.".".$modulNew;
        foreach($ms as $val){
            $ext = GetFileExtension($val);
            if($ext == "php" || $ext == "css" || $ext == "js" || $ext == "sql"){
                /**/
                $cont = file_get_contents($val);
                /*Замены*/
                $cont = str_replace($part_old_tochka_modul,$part_new_tochka_modul,$cont);
                $cont = str_replace(toUpper($part_old),toUpper($partNew),$cont);
                $cont = str_replace(toUpper($modul_old),toUpper($modulNew),$cont);
                $cont = str_replace(ucfirst($modul_old),ucfirst($modulNew),$cont);
                $cont = str_replace($part_old,$partNew,$cont);
                $cont = str_replace($modul_old,$modulNew,$cont);
                file_put_contents($val,$cont);
                if(strlen($out)===0){
                    $out = '<b>'.GetMessage("MODULCREATOR_AJAX_ZAMENI_V").'</b><br>'.$val;
                }else{
                    $out = $out.'<br>'.$val;
                }
            }
        }
        /* Переименование файлов */
        $iz=0;
        foreach($ms as $val){
            $ext = GetFileExtension($val);
            if($ext == "php" || $ext == "css" || $ext == "js" || $ext == "sql"){
                $file_name_old = self::get_file_name($val);
                $file_dir = self::get_file_dir($val);
                if(strpos($file_name_old,$modul_old) !== false || strpos($file_name_old,$part_old) !== false){
                    $iz++;
                    $file_name_new = str_replace($modul_old,$modulNew,$file_name_old);
                    $file_name_new = str_replace($part_old,$partNew,$file_name_new);
                    if($iz === 1){
                        $out = $out.'<b><br>'.GetMessage("MODULCREATOR_AJAX_REANAME_FILE").'</b><br>'.$val;
                    }else{
                        $out = $out.'<br>'.$val;
                    }
                    rename($file_dir.$file_name_old,$file_dir.$file_name_new);
                }
            }
        }
        /* Переименование папок */
        $str_dir = self::read_only_folder($put_to,"");
        $ms_dir = explode(",",$str_dir);
        $root = $_SERVER['DOCUMENT_ROOT'];
        $bx = "/bitrix/modules/".$part_new_tochka_modul;
        $repl_dir = $root.$bx;
        $iz = 0;
        foreach($ms_dir as $val){
            //$str_fold = str_replace($repl_dir,"",$val);
            $str_fold_ms = explode("/",$val);
            $str_fold_last = $str_fold_ms[(count($str_fold_ms)-1)];
            $bez_last="";
            $iww=0;
            foreach($str_fold_ms as $vv){
                $iww++;
                if($iww === 1){
                    $bez_last = $bez_last.$vv;
                }else{
                    $bez_last = $bez_last."/".$vv;
                }
                if($iww === (count($str_fold_ms)-1)){
                    break;
                }

            }
            if(strpos($str_fold_last,$modul_old) !== false){
                $fold_rename = str_replace($modul_old,$modulNew,$str_fold_last);
                $put_new = $bez_last."/".$fold_rename;
                rename($val,$put_new);
                $iz++;
                if($iz === 1){
                    $out = $out.'<br><b>'.GetMessage("MODULCREATOR_AJAX_REANAME_PAPKI").'</b><br>'.$val;
                }else{
                    $out = $out.'<br>'.$val;
                }
            }
        }
        /* У компонента раз и насегда застолблю ИД Андрей Буряк */
        $put_ds = $root."/bitrix/modules/".$part_new_tochka_modul."/install/components/".$output_ms['in4']."/".$modulNew.".".$output_ms['in5']."/.description.php";
        if(is_writable($put_ds)){
            $cont = file_get_contents($put_ds);
            $cont = str_replace("ab".$modulNew,"abinfografika",$cont);
            file_put_contents($put_ds,$cont);
        }
        return $out;
    }

    function read_folder($folder,$out){
        $files = scandir($folder);
        foreach($files as $file){
            if ($file == '.' || $file == '..'){
                continue;
            }
            $fullfilename = $folder . '/' . $file;
            if(is_file($fullfilename)){
                if(strlen($out)>0){
                    $out = $out.",".$fullfilename;
                }else{
                    $out = $fullfilename;
                }
            }

            if (is_dir($fullfilename)){
                $out = self::read_folder($fullfilename,$out);
            }
        }
        return $out;
    }
    public function mklangmessAction() {
        $all_ms = urldecode($_REQUEST['ms']);
        parse_str($all_ms, $output_ms);
        $part = $_REQUEST['part'];
        $modul = $_REQUEST['modul'];

        $err = CAllModulcreator::CheckFields($output_ms);
        if(strlen($err)>0) {
            $out='
            <div class="adm-info-message-wrap adm-info-message-red">
				<div class="adm-info-message w-100">
					<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_TIT_MAKE").':</div>
					'.$err.'
					<div class="adm-info-message-icon"></div>
				</div>
			</div>
            ';
            return $out;
        }

        $root = $_SERVER['DOCUMENT_ROOT'];
        $global_make_puth =$output_ms['global_make_puth'];
        $str_out="";
        $bx_no = 0;
        if($output_ms['in33']== "on" || $output_ms['in33']== "33") {
            $bx_no = 33;/* Пропускаю штатные системные сообщения*/
        }
        $fill_no = 0;
        if($output_ms['in34']== "on" || $output_ms['in34']== "34") {
            $fill_no = 34;/* Пропускаю уже заполненные сообщения*/
        }


        $ms_prefix_lang = Array("ru","en");
        $put = $root."/bitrix/modules/".$part.".".$modul;
        $str_out = self::read_folder($put,"");
        //return "8--------------------".$put;
        $ms_file= explode(",",$str_out);
        $iww=0;
        $str_out = '<table class="table table-light to-lang"><tr>';
        $str_out = $str_out."<td class='langtd-1'><b>".GetMessage("MODULCREATOR_AJAX_NE_ZAPOLNENO_OR_NE_SZDANO")."</b></td>";
        $str_out = $str_out."<td class='langtd-2'><b>".GetMessage("MODULCREATOR_AJAX_SOOBCHENIE")."</b></td>";
        $str_out = $str_out."<td class='langtd-3'><b>".GetMessage("MODULCREATOR_AJAX_ZAPOLNIT_TEXTOM")."</b></td>";
        $str_out = $str_out."<td class='langtd-4'><b>".GetMessage("MODULCREATOR_AJAX_DEYSTVIE")."</b></td>";
        $str_out = $str_out.'</tr>';
        $fl_rez_yes = 0;
        foreach($ms_file as $val){
            $fullput = $val;
            if (strpos( $fullput, "/lang/") === false && strpos( $fullput, "/allpr/") === false) {//ПРопускаю lang файлы и папку allpr
                $str = file_get_contents($fullput);
                preg_match_all("/GetMessage\(\"([^^]+?)\"\)/",$str, $ms_ms, PREG_PATTERN_ORDER);
                if(isset($ms_ms[1])){
                    if(is_array($ms_ms[1])){
                        if(count($ms_ms[1])>0){
                            $put_lang_ms = explode("/",$val);
                            $file_name = $put_lang_ms[(count($put_lang_ms)-1)];
                            $put_lang_dir="";
                            $iz=0;
                            $imax=count($put_lang_ms)-1;
                            $dir_inner_modul="";
                            if(strpos($fullput,"/components/")>0){/* Это компонент*/
                                for($iz=0;$iz<$imax;$iz++){
                                    if(strlen($put_lang_dir)===0){
                                        $put_lang_dir = $put_lang_ms[$iz];
                                    }else{
                                        $put_lang_dir = $put_lang_dir."/".$put_lang_ms[$iz];
                                    }
                                }
                            }else{
                                $put_lang_dir = $root."/bitrix/modules/".$part.".".$modul;

                                $dir_inner_modul=str_replace($put_lang_dir."/","",$fullput);
                                $dir_inner_modul=str_replace("".$file_name,"",$dir_inner_modul)."";


                            }
                            foreach($ms_prefix_lang as $lang_prefix){
                                $put_lang_dir_itog = $put_lang_dir."/lang/".$lang_prefix."/".$dir_inner_modul;

                                 if(is_dir($put_lang_dir_itog)){
                                }else{
                                    $ffs = mkdir($put_lang_dir_itog,BX_DIR_PERMISSIONS,true);
                                }
                                $lang_put = $put_lang_dir_itog."".$file_name;

                                if(file_exists($lang_put)){

                                }else{
                                    $ffs = file_put_contents($lang_put,"<?\r\n?>");


                                }
                                $lang_content = file_get_contents($lang_put);
                                foreach($ms_ms[1] as $val_in){
                                    if($bx_no == 33){
                                        if(strpos(toLower($val_in),toLower($modul))=== false){
                                            continue;
                                        }
                                    }

                                    if (
                                        strpos($lang_content, "'".$val_in."'") === false &&
                                        strpos($lang_content, '"'.$val_in.'"') === false
                                    ) {
                                        /* Кострукция не найдена*/
                                        $val_config_input = self::get_val_config_input($val_in,$global_make_puth);
                                        $iww++;
                                        $help_image_show = self::insert_help_image($val_in, $iww, $modul);
                                        $str_out = $str_out . '<tr>';
                                        $str_out = $str_out . '<td  class="langtd-1"><b>'.GetMessage("MODULCREATOR_AJAX_FAIL_LANG_EST_NO_SOOBCH_NET").':</b><br>'.$lang_put."</td>";
                                        $str_out = $str_out . '<td class="langtd-2">'.$val_in.$help_image_show.'</td>';
                                        $str_out = $str_out . '<td class="langtd-3"><input type="text" value="'.$val_config_input.'" 
																class="lang_msg_real_'.$iww.'" />
																</td>';
                                        $str_out = $str_out . '<td class="langtd-4"><button type="submit" 
															   class="adm-btn adm-btn-save btn  btn-success button_msg_real_'.$iww.'" 
															   onclick="return add_lang_mess_file_real(this,\''.$val_in.'\', \'.lang_msg_real_'.$iww.'\',\''.$lang_put.'\');">'.GetMessage("MODULCREATOR_AJAX_DOPISAT_SOOBCH").'
															   </button>
															   </td>';
                                        $str_out = $str_out.'</tr>';
                                        if(strlen($all_param)===0) {
                                            $all_param=$iww.'^'.$val_in.'^'.$lang_put;
                                        }else {
                                            $all_param=$all_param.'#'.$iww.'^'.$val_in.'^'.$lang_put;
                                        }
                                        $fl_rez_yes = 1;
                                    }else{
                                        /* Найдено можно редактировать */
                                        if($fill_no <> 34){/* Уже заполненные пропускаю*/

                                            $val_config_input = self::get_val_config_input($val_in,$global_make_puth);
                                            if(strlen($val_config_input)===0) {/*Еще не было записывания */
                                                $patern = "/MESS[\s]*?\[[\s]*?[\"\']{1}".$val_in."[\"\']{1}[\s]*?\][\s]*?=[\s]*?[\"\']{1}([^^]+?)[\"\']{1}[^^]*?;/";
                                                preg_match_all($patern,$lang_content,$ms_reg,PREG_PATTERN_ORDER);
                                                if(isset($ms_reg[1][0])) {
                                                    if(strlen($ms_reg[1][0])>0) {
                                                        $val_config_input = $ms_reg[1][0];
                                                    }
                                                }

                                            }
                                            $iww++;
                                            $help_image_show = self::insert_help_image($val_in, $iww, $modul);
                                            $str_out = $str_out . '<tr>';
                                            $str_out = $str_out . '<td class="langtd-1"><b>'.GetMessage("MODULCREATOR_AJAX_FILE_LANK_OK").':</b><br>'.$lang_put."</td>";
                                            $str_out = $str_out . '<td class="langtd-2">'.$val_in.$help_image_show.'</td>';
                                            $str_out = $str_out . '<td class="langtd-3"><input type="text" value="'.$val_config_input.'" 
																	class="lang_msg_real_'.$iww.'" />
																	</td>';
                                            $str_out = $str_out . '<td class="langtd-4"><button type="submit" 
																   class="adm-btn adm-btn-save btn btn-success button_msg_real_'.$iww.'" 
																   onclick="return add_lang_mess_file_real(this,\''.$val_in.'\', \'.lang_msg_real_'.$iww.'\',\''.$lang_put.'\');">'.GetMessage("MODULCREATOR_AJAX_PERAZAPOLNIT_NA").'
																   </button>
																   </td>';
                                            $str_out = $str_out.'</tr>';
                                            if(strlen($all_param)===0) {
                                                $all_param=$iww.'^'.$val_in.'^'.$lang_put;
                                            }else {
                                                $all_param=$all_param.'#'.$iww.'^'.$val_in.'^'.$lang_put;
                                            }
                                            $fl_rez_yes = 1;
                                        }

                                    }

                                }

                            }/* цикл по ру ен*/

                        }
                    }
                }

            }

        }
        if($fl_rez_yes === 1) {
            $dop='<div class="btn-wr2"><button data-optom="Y" data-allparam="'.$all_param.'" onclick="return save_all_lang_msg_real2(this);" type="button" class="adm-btn adm-btn-save btn btn-primary button-all-make">'.GetMessage("MODULCREATOR_AJAX_SOXRANIT_OPTOM").'
         <span class="s1-preloader hidd"><span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
         '.GetMessage("MODULCREATOR_AJAX_SPINER").'</span>
        </button></div>';
            $str_out = $str_out . '</table>'.$dop;
        }else {
            $str_out='<div class="no-rez">'.GetMessage("MODULCREATOR_AJAX_NICHEGO_NE_NAYDENO").'</div>';
        }
        return $str_out;
    }

    public function sinccomponentAction() {
        $out=GetMessage("MODULCREATOR_AJAX_GOTOVO");
        $all_ms = urldecode($_REQUEST['ms']);
        parse_str($all_ms, $output_ms);
        $root = $_SERVER['DOCUMENT_ROOT'];
        CopyDirFiles(
            $root."/bitrix/components/".$output_ms['in4']."/".$output_ms['in2'].".".$output_ms['in5'],
            $root."/bitrix/modules/".$output_ms['in1'].".".$output_ms['in2']."/install/components/"."/".$output_ms['in4']."/".$output_ms['in2'].".".$output_ms['in5'],
            true,
            true,
            false
        );
        return $out;
    }
    public function messagecopycomponentAction() {
        $out="";
        $all_ms = urldecode($_REQUEST['ms']);
        parse_str($all_ms, $ms_value);
        if(isset($ms_value['in3'])){
            if($ms_value['in3'] == 3) {
                if(isset($ms_value['in2'])){
                    if(strlen($ms_value['in2'])>0) {
                        if(isset($ms_value['in4'])){
                            if(strlen($ms_value['in4'])>0) {
                                if(isset($ms_value['in5'])){
                                    if(strlen($ms_value['in5'])>0) {
                                        if(isset($ms_value['in1'])){
                                            if(strlen($ms_value['in1'])>0) {
                                                $put = $_SERVER['DOCUMENT_ROOT']."/bitrix/components/".$ms_value['in4']."/".$ms_value['in2'].".".$ms_value['in5'];
                                                if(is_dir($put)) {
                                                    $out = '
                                                     '.GetMessage("MODULCREATOR_AJAX_COMP_IZ_PAPKI").':<br>/bitrix/components/'.$ms_value['in4'].'/'.$ms_value['in2'].'.'.$ms_value['in5'].'/<br>'.GetMessage("MODULCREATOR_AJAX_BUDET_PEREZAPISAN_V_PAPKU").':
                                                     <br>/bitrix/modules/'.$ms_value['in1'].'/install/components/'.$ms_value['in4'].'/'.$ms_value['in2'].'.'.$ms_value['in5'].'/<br>
                                                     '.GetMessage("MODULCREATOR_AJAX_ESLI_DEV").'
                                                    ';
                                                }else {
                                                    $out = '<span class="color-err">'.GetMessage("MODULCREATOR_AJAX_PAPAKA_ISTOCHNIK").':<br>'.$put.'<br>'.GetMessage("MODULCREATOR_AJAX_NE_EXIST").'</span>';
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return $out;
    }
    public function mkdirstruktureAction() {
        /* Делаю структуру папок*/
        $all_ms = urldecode($_REQUEST['ms']);
        parse_str($all_ms, $output_ms);
        $err = CAllModulcreator::CheckFields($output_ms);
        if(strlen($err)>0) {
            $out='
            <div class="adm-info-message-wrap adm-info-message-red">
				<div class="adm-info-message w-100">
					<div class="adm-info-message-title">'.GetMessage("MODULCREATOR_AJAX_TIT_MAKE").':</div>
					'.$err.'
					<div class="adm-info-message-icon"></div>
				</div>
			</div>
            ';
            return $out;
        }
        $global_make_puth =$output_ms['global_make_puth'];
        $part = $_REQUEST['part'];
        $modul = $_REQUEST['modul'];
        $name = ".default";
        $root = $_SERVER['DOCUMENT_ROOT'];
        /* Массив структуры папок*/
        $ms_dir = Array();
        if($output_ms['in35'] == 35) {
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/admin/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/lang/ru/admin/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/lang/en/admin/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/admin/";
        }
        $ms_dir[] = $root."/bitrix/modules/".$part.".".$modul."/classes/";
        $ms_dir[] = $root."/bitrix/modules/".$part.".".$modul."/classes/general/";
        $ms_dir[] = $root."/bitrix/modules/".$part.".".$modul."/classes/mysql/";
        $ms_dir[] = $root."/bitrix/modules/".$part.".".$modul."/lang/";

        if($_REQUEST['d7'] == 1) {
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/lib/";/* Для D7 */
        }
        $ms_dir[] = $root."/bitrix/modules/".$part.".".$modul."/install/";

        $ms_dir[] = $root."/bitrix/modules/".$part.".".$modul."/install/js/";

        $ms_dir[] = $root."/bitrix/modules/".$part.".".$modul."/install/images/";
        if($_REQUEST['comp'] == 1) {
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5'];
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/images/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/ru/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/en/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/images/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/lang/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/lang/ru/";
            $ms_dir[] = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/lang/en/";
        }
        if($output_ms['in15'] == 15) {
            $ms_dir[] = $root."/bitrix/modules/".$part.".".$modul."/install/db/";
            $ms_dir[] = $root."/bitrix/modules/".$part.".".$modul."/install/db/mysql/";
        }

        $out="";
        /* создание структуры папок */
        foreach ($ms_dir as $val) {
            mkdir($val, BX_DIR_PERMISSIONS,true);
            if(strlen($out) === 0) {
                $out='<b>'.GetMessage("MODULCREATOR_SOZDANI_PAPKI").'</b><br />';
            }
            $out = $out.$val.'<br />';
        }
        $ms_file = Array();
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/default_option.php";

        if(file_exists($put_cont)) {
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms);
        }
        /* Корень */
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/default_option.php",
            "content" => $content
        );
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/include.php";
        if(file_exists($put_cont)) {
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms);
        }
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/include.php",
            "content" => $content
        );
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/options.php";
        if(file_exists($put_cont)) {
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms);
        }
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/options.php",
            "content" => $content
        );
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/prolog.php";
        if(file_exists($put_cont)) {
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms);
        }
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/prolog.php",
            "content" => $content
        );
        /* Пункт меню в админке */
        if($output_ms['in35'] == 35) {
            $content = "";
            $put_cont = $root . "/" . $global_make_puth . "/" . $name . "/php_file_content/admin_menu.php";
            if (file_exists($put_cont)) {
                $content = self::get_makros_replace($put_cont, $part, $modul, $output_ms);
            }
            $ms_file[] = array(
                "fullput" => $root . "/bitrix/modules/" . $part . "." . $modul . "/admin/menu.php",
                "content" => $content
            );
            /*Языковые файлы*/
            $content = '<?' . "\r\n" .
                '$MESS["#modul_upper_full#_MNU_TEXT"] = "' . $output_ms["in7"] . '";' . "\r\n" .
                '$MESS["#modul_upper_full#_MNU_TITLE"] = "' . $output_ms["in7"] . '";' . "\r\n" .
                '?>';
            $content = self::get_makros_replace_2($part, $modul, $output_ms, $content);
            $ms_file[] = array(
                "fullput" => $root . "/bitrix/modules/" . $part . "." . $modul . "/lang/ru/admin/menu.php",
                "content" => $content
            );
            $ms_file[] = array(
                "fullput" => $root . "/bitrix/modules/" . $part . "." . $modul . "/lang/en/admin/menu.php",
                "content" => $content
            );
        }

        /* Временный lang текст заготовки */
        if($output_ms['in35'] == 35) {
            $content = '<?'."\r\n".
                '$MESS["#modul_upper_full#_ADMIN_TMP_TEXT"] = "'.GetMessage("MODULCREATOR_AJAX_ZDES_OSN_SODERJ")."<br />".
                "/bitrix/modules/".$part.".".$modul."/admin/".$modul."_index.php"
                ."<br />".GetMessage("MODULCREATOR_AJAX_I_OCHISTIT_MNU_ADMIN")."<br />".
                "/bitrix/modules/".$part.".".$modul."/admin/menu.php"
                ."<br />".GetMessage("MODULCREATOR_AJAX_ESLI_NO_ADMIN_PAGE")."".'";'."\r\n".
                '$MESS["#modul_upper_full#_ADMIN_LIST_TITLE"] = "'.$output_ms["in37"].'";'."\r\n".
                '?>';
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            $ms_file[]  = Array(
                "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/lang/ru/admin/".$modul."_index.php",
                "content" =>$content
            );
            $ms_file[]  = Array(
                "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/lang/en/admin/".$modul."_index.php",
                "content" =>$content
            );
        }
        /* lang option*/
        $content = '<?'."\r\n".
            '$MESS["#modul_upper_full#_about_settings_start"] = "'.COption::GetOptionString('directoriya.modulcreator',"admin_opt_snoska_kontent").'";'."\r\n".
            '$MESS["#modul_upper_full#_about_settings"] = "'.COption::GetOptionString('directoriya.modulcreator',"admin_opt_snoska_bottom").'";'."\r\n".
            '?>';
        $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/lang/ru/options.php",
            "content" =>$content
        );
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/lang/en/options.php",
            "content" =>$content
        );
        /* Русское название модуля в меню и списке */
        $content = '<?'."\r\n".
            '$MESS["#modul_upper_full#_MODULE_NAME"] = "'.$output_ms["in19"].'";'."\r\n".
            '$MESS["#modul_upper_full#_PARTNER_NAME"] = "'.$output_ms["in20"].'";'."\r\n".
            '$MESS["#modul_upper_full#_DESCRIPTION"] = "'.$output_ms["in21"].'";'."\r\n".
            '$MESS["#modul_upper_full#_INSTALL_TITLE"] = "'.GetMessage("MODULCREATOR_AJAX_MODUL").' '.$output_ms["in19"].' '.GetMessage("MODULCREATOR_AJAX_USTANOVLEN").'";'."\r\n".
            '$MESS["#modul_upper_full#_UNINSTALL_TITLE"] = "'.GetMessage("MODULCREATOR_AJAX_DEINSTALL_MODUL").' '.$output_ms["in19"].'";'."\r\n".
            '$MESS["#modul_upper_full#_DENIED"] = "'.GetMessage("MODULCREATOR_AJAX_ZAPRECHEN").'";'."\r\n".
            '$MESS["#modul_upper_full#_VIEW"] = "'.GetMessage("MODULCREATOR_AJAX_CHTENIE").'";'."\r\n".
            '$MESS["#modul_upper_full#_WRITE"] = "'.GetMessage("MODULCREATOR_AJAX_ZAPIS").'";'."\r\n".
            '?>';
        $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/lang/ru/install/index.php",
            "content" =>$content
        );
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/lang/en/install/index.php",
            "content" =>$content
        );


        /*Страница модуля*/
        if($output_ms['in35'] == 35) {
            $content = "";
            $put_cont = $root . "/" . $global_make_puth . "/" . $name . "/php_file_content/admin_module_index.php";
            if (file_exists($put_cont)) {
                $content = self::get_makros_replace($put_cont, $part, $modul, $output_ms);
            }
            $ms_file[] = array(
                "fullput" => $root . "/bitrix/modules/" . $part . "." . $modul . "/admin/" . $modul . "_index.php",
                "content" => $content
            );
        }
        /**/

        // classes
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/classes_general_modul.php";
        if(file_exists($put_cont)) {
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms);
        }
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/classes/general/".$modul.".php",
            "content" => $content
        );

        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/classes_mysql_modul.php";
        if(file_exists($put_cont)) {
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms);
        }
        $ms_file[]  = Array(
            "fullput"=>$root."/bitrix/modules/".$part.".".$modul."/classes/mysql/".$modul.".php",
            "content" => $content
        );
        /* install admin */
        if($output_ms['in35'] == 35) {
            $content = '<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/' . $part . '.' . $modul . '/admin/' . $modul . '_index.php");?>';
            $ms_file[] = array(
                "fullput" => $root . "/bitrix/modules/" . $part . "." . $modul . "/install/admin/" . $modul . "_index.php",
                "content" => $content
            );
        }
        /* Разные способы создания файлов */
        $out = $out.'<br /><b>'.GetMessage("MODULCREATOR_AJAX_SOZDAN_FILE").':</b><br />';
        foreach ($ms_file as $val) {
            self::save_file_snd_dir($val["fullput"], $val["content"]);
            $out = $out.$val["fullput"].'<br />';
        }
        /* База mysql */
        if($output_ms['in15'] == 15) {
            $file_name_ms = explode("/",$output_ms['in16']);
            $file_name =$file_name_ms[(count($file_name_ms)-1)];
            $ok = copy(
                $root.$output_ms['in16'],
                $root . "/bitrix/modules/" . $part . "." . $modul .
                "/install/db/mysql/".$file_name);

            $file_name_ms = explode("/",$output_ms['in17']);
            $file_name =$file_name_ms[(count($file_name_ms)-1)];
            $ok = copy(
                $root.$output_ms['in17'],
                $root . "/bitrix/modules/" . $part . "." . $modul .
                "/install/db/mysql/".$file_name);

        }
        /* Компонент 1 штука*/
        if($_REQUEST['comp'] == 1) {
            /* Иконка компонента */
            $file_name_ms = explode("/",$output_ms['in8']);
            $file_name =$file_name_ms[(count($file_name_ms)-1)];
            $file_name = copy($root.$output_ms['in8'],$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/images/".$file_name);

            $content="";
            $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/components_description.php";
            if(file_exists($put_cont)) {
                $file_name_ms = explode("/",$output_ms['in8']);
                $file_name =$file_name_ms[(count($file_name_ms)-1)];

                $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
                $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/.description.php";
                file_put_contents($put,$content);
                $out = $out.$put.'<br />';
                $ms_file[]  = Array(
                    "fullput"=>$put,
                    "content" => $content
                );

            }
            // Параметры компонента
            $content="";
            $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/component_parameters.php";
            if(file_exists($put_cont)) {
                $file_name="";
                $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
                $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/.parameters.php";
                file_put_contents($put,$content);
                $out = $out.$put.'<br />';
                $ms_file[]  = Array(
                    "fullput"=>$put,
                    "content" => $content
                );

            }
            // Собственно логика компонента
            $content="";
            $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/component.php";
            if(file_exists($put_cont)) {
                $file_name="";
                $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);

                $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/component.php";
                file_put_contents($put,$content);
                $out = $out.$put.'<br />';

                $ms_file[]  = Array(
                    "fullput"=>$put,
                    "content" => $content
                );
            }
            /* CSS компонента Пустой */
            file_put_contents($root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/style.css","");

            // Файл шаблона компонента
            $content="";
            $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/component_tpl.php";
            if(file_exists($put_cont)) {
                $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
                $put= $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/template.php";
                file_put_contents($put,$content);
                $out = $out.$put.'<br />';

                $ms_file[]  = Array(
                    "fullput"=>$put,
                    "content" => $content
                );
            }
            /* result_modifier.php */
            $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/result_modifier.php";
            if(file_exists($put_cont)) {
                $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
                $put= $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/result_modifier.php";
                file_put_contents($put,$content);
                $out = $out.$put.'<br />';
                $ms_file[]  = Array(
                    "fullput"=>$put,
                    "content" => $content
                );
            }
            /* component_epilog.php */
            $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/component_epilog.php";
            if(file_exists($put_cont)) {
                $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
                $put= $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/component_epilog.php";
                file_put_contents($put,$content);
                $out = $out.$put.'<br />';
                $ms_file[]  = Array(
                    "fullput"=>$put,
                    "content" => $content
                );
            }
            /* settings.js */
            $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/component_settings.js";
            if(file_exists($put_cont)) {
                $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
                $put= $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/settings/settings.js";
                $rr = self::save_file_snd_dir($put, $content);
                $out = $out.$put.'<br />';
                $ms_file[]  = Array(
                    "fullput"=>$put,
                    "content" => $content
                );
            }
            /* settings.php */
            $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/component_settings.php";
            if(file_exists($put_cont)) {
                $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
                $put= $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/settings/settings.php";
                $rr = self::save_file_snd_dir($put, $content);
                $out = $out.$put.'<br />';
                $ms_file[]  = Array(
                    "fullput"=>$put,
                    "content" => $content
                );
            }
            /* .tooltips.php */
            $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/component_settings.php";
            if(file_exists($put_cont)) {
                $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
                $put= $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/help/.tooltips.php";
                $rr = self::save_file_snd_dir($put, $content);
                $out = $out.$put.'<br />';
                $ms_file[]  = Array(
                    "fullput"=>$put,
                    "content" => $content
                );
            }

            /* Языковые файлы компонента DS */
            $content = '<?'."\r\n".
                '$MESS["#modul_upper_full#_DEFAULT_TEMPLATE_NAME"] = "'.$output_ms["in10"].'";'."\r\n".
                '$MESS["#modul_upper_full#_DEFAULT_TEMPLATE_DESCRIPTION"] = "'.$output_ms["in11"].'";'."\r\n".
                '$MESS["#modul_upper_full#_DEFAULT_TEMPLATE_GRUPP_NAME"] = "'.$output_ms["in14"].'";'."\r\n".
                '?>';
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/ru/.description.php";
            file_put_contents($put,$content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/en/.description.php";
            file_put_contents($put,$content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );

            /* lang param */
            $content = '<?'."\r\n".
                '$MESS["#modul_upper_full#_TPL_PRIMER_GRUPPA_PARAM_1"] = "'.GetMessage("MODULCREATOR_TPL_PRIMER_GRUPPA_PARAM_1").'";'."\r\n".
                '$MESS["#modul_upper_full#_TPL_GALKA_JQUERY"] = "'.GetMessage("MODULCREATOR_TPL_GALKA_JQUERY").'";'."\r\n".
                '$MESS["#modul_upper_full#_TPL_PRIMER_STR_PARAM"] = "'.GetMessage("MODULCREATOR_TPL_PRIMER_STR_PARAM").'";'."\r\n".
                '$MESS["#modul_upper_full#_TPL_PRIMER_LIST_MULT"] = "'.GetMessage("MODULCREATOR_TPL_PRIMER_LIST_MULT").'";'."\r\n".
                '$MESS["#modul_upper_full#_TPL_SELET_BOX_ZNACHENIE_1"] = "'.GetMessage("MODULCREATOR_TPL_SELET_BOX_ZNACHENIE_1").'";'."\r\n".
                '$MESS["#modul_upper_full#_TPL_SELET_BOX_ZNACHENIE_2"] = "'.GetMessage("MODULCREATOR_TPL_SELET_BOX_ZNACHENIE_2").'";'."\r\n".
                '$MESS["#modul_upper_full#_TPL_SELET_BOX_ZNACHENIE_3"] = "'.GetMessage("MODULCREATOR_TPL_SELET_BOX_ZNACHENIE_3").'";'."\r\n".
                '$MESS["#modul_upper_full#_PRIMER_CUSTOMNOGO_POLYA"] = "'.GetMessage("MODULCREATOR_PRIMER_CUSTOMNOGO_POLYA").'";'."\r\n".
                '$MESS["#modul_upper_full#_CUSTOM_FIELD_COMPONENT_BUTTON"] = "'.GetMessage("MODULCREATOR_CUSTOM_FIELD_COMPONENT_BUTTON").'";'."\r\n".
                '?>';
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/ru/.parameters.php";
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/en/.parameters.php";
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );

            /* component */
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/ru/component.php";
            $content = '<?'."\r\n".
                '$MESS["#modul_upper_full#_NOT_INSTALLED"] = "'.COption::GetOptionString('directoriya.modulcreator',"admin_opt_component_msg_modul_not_installed").' '.$output_ms["in19"].'";'."\r\n".
                '$MESS["#modul_upper_full#_TITLE"] = "'.$output_ms["in10"].'";'."\r\n".
                '?>';
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            file_put_contents($put,$content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/en/component.php";
            file_put_contents($put,$content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            /* Аякс в компонент */
            if(isset($output_ms['in18'])){
                if($output_ms['in18'] == 18){
                    $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/ajaxfile_in_folder_tpl_component.php";
                    $aj_cont = self::get_makros_replace($put_cont,$part, $modul,$output_ms);
                    $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/ajax.php";
                    file_put_contents($put,$aj_cont);
                    $out = $out.$put.'<br />';
                    $ms_file[]  = Array(
                        "fullput"=>$put,
                        "content" => $aj_cont
                    );
                    $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/component_script.js";
                    $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms);
                    $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/script.js";
                    $rr = self::save_file_snd_dir($put, $content);
                    $out = $out.$put.'<br />';
                    $ms_file[]  = Array(
                        "fullput"=>$put,
                        "content" => $aj_cont
                    );
                    /* lang .ajax.php*/
                    $content = '<?'."\r\n".
                        '$MESS["#modul_upper_full#_ETO_PRIMER_OTVETA"] = "'.GetMessage("MODULCREATOR_ETO_PRIMER_OTVETA").'";'."\r\n".
                        '?>';
                    $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
                    $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/ru/ajax.php";
                    $rr = self::save_file_snd_dir($put, $content);
                    $out = $out.$put.'<br />';
                    $ms_file[]  = Array(
                        "fullput"=>$put,
                        "content" => $content
                    );
                    $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/en/ajax.php";
                    $rr = self::save_file_snd_dir($put, $content);
                    $out = $out.$put.'<br />';
                    $ms_file[]  = Array(
                        "fullput"=>$put,
                        "content" => $content
                    );
                }

            }
            /* lang .tooltips.php*/
            $content = '<?'."\r\n".
                '$MESS["#modul_upper_full#_JQUERYYES_TIP"] = "'.GetMessage("MODULCREATOR_JQUERYYES_TIP").'";'."\r\n".
                '?>';
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/ru/help/.tooltips.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/en/help/.tooltips.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            /*lang settings.php*/
            $content = '<?'."\r\n".
                '$MESS["#modul_upper_full#_COMPONENT_SETINGS_POPUP_TITLE"] = "'.GetMessage("MODULCREATOR_COMPONENT_SETINGS_POPUP_TITLE").'";'."\r\n".
                '$MESS["#modul_upper_full#_NOT_INSTALLED"] = "'.GetMessage("MODULCREATOR_COMP_SETINGS_NOT_INSTALLED").'";'."\r\n".
                '$MESS["#modul_upper_full#_SET_SUBMIT_POPUP"] = "'.GetMessage("MODULCREATOR_SET_SUBMIT_POPUP").'";'."\r\n".
                '$MESS["#modul_upper_full#_COMPONENT_POPUP_TEXT"] = "'.GetMessage("MODULCREATOR_COMPONENT_POPUP_TEXT").'";'."\r\n".
                '$MESS["#modul_upper_full#_SET_POPUP_WINDOW_TITLE"] = "'.GetMessage("MODULCREATOR_SET_POPUP_WINDOW_TITLE").'";'."\r\n".
                '$MESS["#modul_upper_full#_SET_POPUP_WINDOW_DESCRIPTION"] = "'.GetMessage("MODULCREATOR_SET_POPUP_WINDOW_DESCRIPTION").'";'."\r\n".
                '?>';
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/ru/settings/settings.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/lang/en/settings/settings.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            /*lang result_modifier.php */
            $content = '<?'."\r\n".
                '$MESS["#modul_upper_full#_SRABOTAL_REZULT_MODIF"] = "'.GetMessage("MODULCREATOR_SRABOTAL_REZULT_MODIF").'";'."\r\n".
                '?>';
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/lang/ru/result_modifier.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/lang/en/result_modifier.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            /*lang component_epilog.php */
            $content = '<?'."\r\n".
                '$MESS["#modul_upper_full#_SRABOTAL_EPILOG"] = "'.GetMessage("MODULCREATOR_SRABOTAL_EPILOG").'";'."\r\n".
                '?>';
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/lang/ru/component_epilog.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/lang/en/component_epilog.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            /*lang template.php */
            $content = '<?'."\r\n".
                '$MESS["#modul_upper_full#_TPL_POKA_NOW_DATE"] = "'.GetMessage("MODULCREATOR_TPL_POKA_NOW_DATE").'";'."\r\n".
                '?>';
            if(isset($output_ms['in18'])) {
                if ($output_ms['in18'] == 18) {
                    $content = '<?'."\r\n".
                        '$MESS["#modul_upper_full#_TPL_POKA_NOW_DATE"] = "'.GetMessage("MODULCREATOR_TPL_POKA_NOW_DATE").'";'."\r\n".
                        '$MESS["#modul_upper_full#_ZNACHENIE_POLYA1"] = "'.GetMessage("MODULCREATOR_ZNACHENIE_POLYA1").'";'."\r\n".
                        '$MESS["#modul_upper_full#_OTPRAVIT_AJAX_ZAPROS"] = "'.GetMessage("MODULCREATOR_OTPRAVIT_AJAX_ZAPROS").'";'."\r\n".
                        '?>';
                }
            }
            $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
            file_put_contents($_SERVER['DOCUMENT_ROOT']."/1.txt", print_r( $put, true)."\r\n", FILE_APPEND);
            file_put_contents($_SERVER['DOCUMENT_ROOT']."/1.txt", print_r( $content, true)."\r\n", FILE_APPEND);
            $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/lang/ru/template.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
            $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/install/components/".$output_ms['in4']."/".$modul.".".$output_ms['in5']."/templates/.default/lang/en/template.php";
            $rr = self::save_file_snd_dir($put, $content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );


        }
        /* install модуля */
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/install_index.php";
        if(file_exists($put_cont)) {
            $file_name="";
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/index.php";
            file_put_contents($put,$content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
        }
        /* step1 */
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/step1.php";
        if(file_exists($put_cont)) {
            $file_name="";
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/step1.php";
            file_put_contents($put,$content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
        }
        /* unstep1 */
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/unstep1.php";
        if(file_exists($put_cont)) {
            $file_name="";
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/unstep1.php" ;
            file_put_contents($put,$content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
        }
        /* unstep2 */
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/unstep2.php";
        if(file_exists($put_cont)) {
            $file_name="";
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/unstep2.php";
            file_put_contents($put,$content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
        }
        /* Языковый файла step unstep1 */
        $content = '<?'."\r\n".
            '$MESS["#modul_upper_full#_MODULE_NAME"] = "'.$output_ms["in19"].'";'."\r\n".
            '?>';
        $content = self::get_makros_replace_2($part, $modul,$output_ms,$content);
        $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/lang/ru/install/unstep1.php";
        file_put_contents($put,$content);
        $out = $out.$put.'<br />';
        $ms_file[]  = Array(
            "fullput"=>$put,
            "content" => $content
        );
        $put=$root . "/bitrix/modules/" . $part . "." . $modul . "/lang/en/install/unstep1.php";
        file_put_contents($put,$content);
        $out = $out.$put.'<br />';
        $ms_file[]  = Array(
            "fullput"=>$put,
            "content" => $content
        );

        /* version */
        $content="";
        $put_cont = $root."/".$global_make_puth."/".$name."/php_file_content/version.php";
        if(file_exists($put_cont)) {
            $file_name="";
            $content = self::get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name);
            $put = $root . "/bitrix/modules/" . $part . "." . $modul . "/install/version.php";
            file_put_contents($put,$content);
            $out = $out.$put.'<br />';
            $ms_file[]  = Array(
                "fullput"=>$put,
                "content" => $content
            );
        }
        /* Проверка наличия языковых файлов и сообщений к ним */

        $dd = self::check_lang_file($ms_file, $root, $part, $modul, $output_ms['in4'],$output_ms['in5'], $_REQUEST['comp'], $global_make_puth);
        $out = $out.$dd.'<br />';
        return $out;
    }

    function  check_lang_file($ms_file, $root, $part="", $modul="", $prostranstvo_comp="",$name_comp="",$fl_comp=0, $global_make_puth) {
        $str_out = "";
        $all_param="";
        $ms_out=Array();
        if(strlen($part)>0 && strlen($modul)>0) {
            $iww = 0;
            foreach ($ms_file as $val) {
                $fullput = $val['fullput'];
                if (strpos( $fullput, "/lang/") === false) {//ПРопускаю lang файлы
                    $modul_upper = toUpper($modul);
                    $compare_content = str_replace("?", "-^^^-", $val['content']);
                    preg_match_all("/GetMessage\(\"(".$modul_upper."[^^]+?)\"\)/",$compare_content, $ms1, PREG_PATTERN_ORDER);
                    preg_match_all("/GetMessage\(\'(".$modul_upper."[^^]+?)\'\)/",$compare_content, $ms2, PREG_PATTERN_ORDER);
                    preg_match_all("/GetMessage\(\'(mnu_".$modul."[^^]+?)\'\)/",$compare_content, $ms3, PREG_PATTERN_ORDER);
                    preg_match_all("/GetMessage\(\"(mnu_".$modul."[^^]+?)\"\)/",$compare_content, $ms4, PREG_PATTERN_ORDER);
                    $ms_ms=Array($ms1,$ms2,$ms3,$ms4);
                    $ms_sborniy=Array();
                    foreach($ms_ms as $ms_val) {
                        $ms_tmp = $ms_val;
                        if (isset($ms_tmp[1])) {
                            if (is_array($ms_tmp[1])) {
                                if (count($ms_tmp[1]) > 0) {
                                    foreach ($ms_tmp[1] as $v2) {
                                        if (in_array($v2, $ms_sborniy)) {
                                        } else {
                                            $ms_sborniy[] = $v2;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if(count($ms_sborniy)>0) {/*Массив языковых конструкций*/
                        $file_name_ms = explode("/", $val['fullput']);
                        $file_name = $file_name_ms[(count($file_name_ms) - 1)];
                        $modul_put_ms = explode("/" . $part . "." . $modul . "/", $val['fullput']);
                        $lang_modul_put1 = $modul_put_ms[0]."/".$part.".".$modul . "/lang/ru/" . $modul_put_ms[1];
                        $lang_modul_put2 = $modul_put_ms[0]."/".$part.".".$modul . "/lang/en/" . $modul_put_ms[1];
                        /* Для Шаблона компонента языковые пути другие */
                        $fl_stop = 0;
                        $kusok = '/components/'.$prostranstvo_comp."/".$part.".".$modul."/templates/";
                        if(strpos($val['fullput'],$kusok)!== false) {
                            $fl_stop = 1;
                            $modul_put_ms = explode($kusok, $val['fullput']);
                            $lang_modul_put1 = $modul_put_ms[0] . $kusok."lang/ru/" . $modul_put_ms[1];
                            $lang_modul_put2 = $modul_put_ms[0] . $kusok."lang/en/" . $modul_put_ms[1];
                        }
                        /* Для компонента языковые пути другие */
                        if(strpos($val['fullput'],'/components/')!== false && $fl_stop === 0) {
                            $modul_put_ms = explode("/".$modul. ".". $name_comp."/", $val['fullput']);
                            $lang_modul_put1 = $modul_put_ms[0] . "/" . $modul. "." . $name_comp."/lang/ru/" . $modul_put_ms[1];
                            $lang_modul_put2 = $modul_put_ms[0] . "/" . $modul. "." . $name_comp."/lang/en/" . $modul_put_ms[1];
                        }

                        $ms_lang_modul_put = array($lang_modul_put1, $lang_modul_put2);
                        foreach ($ms_lang_modul_put as $lang_put) {
                            $lang_put_no_root = str_replace($root,"",$lang_put);
                            if (file_exists($lang_put)) {
                                /* файл есть ищу языковые конструкции */
                                $lang_content = file_get_contents($lang_put);
                                foreach ($ms_sborniy as $val_in) {
                                    /* Кострукция не найдена*/
                                    if (
                                        strpos($lang_content, "'".$val_in."'") === false && strpos($lang_content, '"'.$val_in.'"') === false
                                    ) {
                                        $pos = strpos($lang_content, '<?');
                                        if ($pos !== false) {
                                            $replace = "<?\r\n" . $MESS[$val_in] = GetMessage("MODULCREATOR_TREBUETCA_ZAMENA_TEXTA");
                                            $newstring = substr_replace($lang_content, $replace, $pos, strlen('<?'));
                                            if (strlen($str_out) === 0) {
                                                $str_out = '<table class="table table-light to-lang"><tr>';
                                                $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_NE_ZAPOLNENO_OR_NE_SZDANO")."</b></td>";
                                                $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_SOOBCHENIE")."</b></td>";
                                                $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_ZAPOLNIT_TEXTOM")."</b></td>";
                                                $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_DEYSTVIE")."</b></td>";
                                                $str_out = $str_out.'</tr>';
                                            }
                                            $val_config_input = self::get_val_config_input($val_in,$global_make_puth);
                                            $iww++;
                                            $str_out = $str_out . '<tr>';
                                            $str_out = $str_out . '<td><b>'.GetMessage("MODULCREATOR_AJAX_FILE_OK_LANG_NO").':</b><br>'.$lang_put_no_root."</td>";
                                            $str_out = $str_out . '<td>'.$val_in.self::insert_help_image($val_in, $iww,$modul)."</td>";
                                            $str_out = $str_out . '<td><input type="text" value="'.$val_config_input.'" class="lang_msg_'.$iww.'" /></td>';
                                            $str_out = $str_out . '<td><button type="submit" class="adm-btn adm-btn-save btn  btn-success button_msg_'.$iww.'" onclick="return add_lang_mess_file(this,\''.$val_in.'\', \'.lang_msg_'.$iww.'\',\''.$lang_put.'\');">
                                            '.GetMessage("MODULCREATOR_AJAX_DOPISAT_SOOB").'
                                            </button>
                                            </td>';
                                            $str_out = $str_out.'</tr>';
                                            if(strlen($all_param)===0) {
                                                $all_param=$iww.'^'.$val_in.'^'.$lang_put;
                                            }else {
                                                $all_param=$all_param.'#'.$iww.'^'.$val_in.'^'.$lang_put;
                                            }
                                        }else {/* нету даже php префикса */
                                            if (strlen($str_out) === 0) {
                                                $str_out = '<table class="table table-light to-lang"><tr>';
                                                $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_NE_ZAPOLNENO_OR_NE_SZDANO")."</b></td>";
                                                $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_SOOBCHENIE")."</b></td>";
                                                $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_ZAPOLNIT_TEXTOM")."</b></td>";
                                                $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_DEYSTVIE")."</b></td>";
                                                $str_out = $str_out.'</tr>';
                                            }
                                            $val_config_input = self::get_val_config_input($val_in,$global_make_puth);
                                            $iww++;
                                            $str_out = $str_out . '<tr>';
                                            $str_out = $str_out . '<td>'.GetMessage("MODULCREATOR_AJAX_EXIST_BUT_EMPT").':<br>'.$lang_put_no_root."</td>";
                                            $str_out = $str_out . '<td>'.$val_in.self::insert_help_image($val_in, $iww,$modul)."</td>";
                                            $str_out = $str_out . '<td><input type="text" value="'.$val_config_input.'" class="lang_msg_'.$iww.'" /></td>';
                                            $str_out = $str_out . '<td><button type="submit" class="adm-btn adm-btn-save  btn  btn-success button_msg_'.$iww.'" onclick="return add_lang_mess_file(this,\''.$val_in.'\', \'.lang_msg_'.$iww.'\',\''.$lang_put.'\');">
                                            '.GetMessage("MODULCREATOR_AJAX_ZAPOLNIT_EMPT_FILE").'</button></td>';
                                            $str_out = $str_out.'</tr>';
                                            if(strlen($all_param)===0) {
                                                $all_param=$iww.'^'.$val_in.'^'.$lang_put;
                                            }else {
                                                $all_param=$all_param.'#'.$iww.'^'.$val_in.'^'.$lang_put;
                                            }
                                        }
                                    }else {
                                        //echo "Кострукции найдены";
                                        if (strlen($str_out) === 0) {
                                            $str_out = '<table class="table table-light to-lang"><tr>';
                                            $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_NE_ZAPOLNENO_OR_NE_SZDANO")."</b></td>";
                                            $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_SOOBCHENIE")."</b></td>";
                                            $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_ZAPOLNIT_TEXTOM")."</b></td>";
                                            $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_DEYSTVIE")."</b></td>";
                                            $str_out = $str_out.'</tr>';
                                        }
                                        $val_config_input = self::get_val_config_input($val_in,$global_make_puth);
                                        if(strlen($val_config_input)===0) {/*Еще не было записывания */
                                            $patern = "/MESS[\s]*?\[[\s]*?[\"\']{1}".$val_in."[\"\']{1}[\s]*?\][\s]*?=[\s]*?[\"\']{1}([^^]+?)[\"\']{1}[^^]*?;/";
                                            preg_match_all($patern,$lang_content,$ms_reg,PREG_PATTERN_ORDER);
                                            if(isset($ms_reg[1][0])) {
                                                if(strlen($ms_reg[1][0])>0) {
                                                    $val_config_input = $ms_reg[1][0];
                                                }
                                            }

                                        }
                                        $iww++;
                                        $warn_mess = GetMessage("MODULCREATOR_AJAX_PEREZAPOLNIT");
                                        if(strlen($val_config_input)===0) {
                                            $warn_mess = GetMessage("MODULCREATOR_AJAX_SOOB_PUST_ZAPOLNIT");;
                                        }
                                        $str_out = $str_out . '<tr>';
                                        $str_out = $str_out . '<td>'.GetMessage("MODULCREATOR_AJAX_EDIT_KONSTR_EXIST").':<br>'.$lang_put_no_root."</td>";
                                        $str_out = $str_out . '<td>'.$val_in.self::insert_help_image($val_in, $iww,$modul)."</td>";
                                        $str_out = $str_out . '<td><input type="text" value="'.$val_config_input.'" class="lang_msg_'.$iww.'" /></td>';
                                        $str_out = $str_out . '<td><button type="submit" class="adm-btn adm-btn-save btn  btn-success button_msg_'.$iww.'" 
										                       onclick="return add_lang_mess_file(this,\''.$val_in.'\', \'.lang_msg_'.$iww.'\',\''.$lang_put.'\');">'.$warn_mess.'
															   </button></td>';
                                        $str_out = $str_out.'</tr>';
                                        if(strlen($all_param)===0) {
                                            $all_param=$iww.'^'.$val_in.'^'.$lang_put;
                                        }else {
                                            $all_param=$all_param.'#'.$iww.'^'.$val_in.'^'.$lang_put;
                                        }

                                    }
                                }

                            } else {
                                /* Файла нету надо создать */
                                foreach ($ms_sborniy as $val_in) {
                                    if (strlen($str_out) === 0) {
                                        $str_out = '<table class="table table-light to-lang"><tr>';
                                        $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_NE_ZAPOLNENO_OR_NE_SZDANO")."</b></td>";
                                        $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_SOOBCHENIE")."</b></td>";
                                        $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_ZAPOLNIT_TEXTOM")."</b></td>";
                                        $str_out = $str_out."<td><b>".GetMessage("MODULCREATOR_AJAX_DEYSTVIE")."</b></td>";
                                        $str_out = $str_out.'</tr>';
                                    }
                                    $iww++;
                                    $val_config_input = self::get_val_config_input($val_in,$global_make_puth);
                                    $str_out = $str_out . '<tr>';
                                    $str_out = $str_out . '<td>'.GetMessage("MODULCREATOR_AJAX_SOZDAT").':<br>'.$lang_put_no_root."</td>";
                                    $str_out = $str_out . '<td>'.$val_in.self::insert_help_image($val_in, $iww,$modul)."</td>";
                                    $str_out = $str_out . '<td><input type="text" value="'.$val_config_input.'" class="lang_msg_'.$iww.'" /></td>';
                                    $str_out = $str_out . '<td><button type="submit" class="adm-btn adm-btn-save btn btn-success button_msg_'.$iww.'" onclick="return add_lang_mess_file(this,\''.$val_in.'\', \'.lang_msg_'.$iww.'\',\''.$lang_put.'\');">
                                    '.GetMessage("MODULCREATOR_AJAX_SOZDAT_I_ZAPOLNIT").'
                                    </button></td>';
                                    $str_out = $str_out.'</tr>';
                                    if(strlen($all_param)===0) {
                                        $all_param=$iww.'^'.$val_in.'^'.$lang_put;
                                    }else {
                                        $all_param=$all_param.'#'.$iww.'^'.$val_in.'^'.$lang_put;
                                    }
                                }

                            }

                        }

                    }
                    /**/
                }
            }
        }
        if(strlen($str_out)>10) {
            $str_out = $str_out.'</table>';
            $str_out = $str_out.'<br />
         <button data-optom="Y" data-allparam="'.$all_param.'" onclick="return save_all_lang_msg(this);" type="button" class="adm-btn adm-btn-save btn btn-primary button-all-make">
         '.GetMessage("MODULCREATOR_AJAX_OPTOM").'
         
         <span class="s1-preloader hidd"><span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
         '.GetMessage("MODULCREATOR_AJAX_SPINER2").'</span>
        </button>';
        }
        $expl = '<div class="delim-lang">'.GetMessage("MODULCREATOR_AJAX_EDIT_OR_CREATE_LANG").'</div>';
        return $expl.$str_out;
    }

    function insert_help_image($lat, $iww, $modul) {
        require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
        if(Loader::includeModule("main")) {
            $modul_upper = toUpper($modul);
            $out = "";
            $aTitl = GetMessage("MODULCREATOR_GDE_RASPOLOJENO");
            if ($lat == $modul_upper . '_PARTNER_NAME') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m6.jpg';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_MODULE_NAME') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m7.jpg';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
                $img = '/bitrix/panel/directoriya.modulcreator/img/m23.png';
                $out = $out."<hr />".CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_DESCRIPTION') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m8.jpg';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_UNINSTALL_TITLE') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m9.jpg';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_about_settings_start' || $lat == $modul_upper.'_about_settings') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m10.jpg';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_INSTALL_TITLE') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m11.jpg';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0'  title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_TITLE') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m12.png';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0'  title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_NOT_INSTALLED') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m13.png';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0'  title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_DEFAULT_TEMPLATE_GRUPP_NAME') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m14.png';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_DEFAULT_TEMPLATE_DESCRIPTION') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m15.png';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_DEFAULT_TEMPLATE_NAME') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m16.png';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_DENIED' || $lat == $modul_upper . '_VIEW' || $lat == $modul_upper . '_WRITE') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m17.png';
                $out = CFile::Show2Images($img, $img, 150, 150, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_MNU_TEXT') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m21.png';
                $out = CFile::Show2Images($img, $img, 150, 100, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_MNU_TITLE') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m20.png';
                $out = CFile::Show2Images($img, $img, 150, 100, "hspace='0' vspace='0' border='0'  title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_ADMIN_LIST_TITLE') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m18.png';
                $out = CFile::Show2Images($img, $img, 150, 100, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
            if ($lat == $modul_upper . '_ADMIN_TMP_TEXT') {
                $img = '/bitrix/panel/directoriya.modulcreator/img/m22.png';
                $out = CFile::Show2Images($img, $img, 150, 100, "hspace='0' vspace='0' border='0' title='".$aTitl."'", $aTitl);
            }
        }
        if(strlen($out)>0) {
            $out='<br />'.$out;
        }
        return $out;
    }

    function get_val_config_input($lat_msg,$global_make_puth) {
        $out="";
        return $out;
    }

    function getFileName($str) {
        $msStr = str_replace("\\","/",$str);
        $ms =explode("/",$msStr);
        $out = $ms[(count($ms)-1)];
        return $out;
    }
    function get_makros_replace($put_cont,$part, $modul,$output_ms,$file_name="") {
        $content = file_get_contents($put_cont);
        $content = str_replace("#part#",$part,$content);
        $content = str_replace("#modul#",$modul,$content);
        $upper_modul = ucfirst($modul);
        $content = str_replace("#modul_upper#",$upper_modul,$content);
        $upper_modul_full = toUpper($modul);
        $content = str_replace("#modul_upper_full#",$upper_modul_full,$content);
        $content = str_replace("#comp_img_file#",$file_name,$content);
        $content = str_replace("#modul_id#",$output_ms["in9"],$content);
        $content = str_replace("#part_uri#",$output_ms["in12"],$content);
        $content = str_replace("#version_date#",date("Y-m-d H:i:s", time()),$content);
        $content = str_replace("#version_nomer#",$output_ms["in13"],$content);
        $content = str_replace("#component_prostranstvo#",$output_ms["in4"],$content);
        $content = str_replace("#component_name#",$modul.'.'.$output_ms["in5"],$content);
        $content = str_replace("#parent_menu#",$output_ms["in36"],$content);
        //База
        $install_bd="";
        $uninstall_bd = "";
        if(isset($output_ms['in15'])){
            if($output_ms['in15'] == 15){
                $sqlName = self::getFileName($output_ms['in16']);
                $install_bd = '$errors = $DB->RunSQLBatch($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/'.$part.'.'.$modul.'/install/db/mysql/'.$sqlName.'");';
                $sqlName = self::getFileName($output_ms['in17']);
                $uninstall_bd = '$errors = $DB->RunSQLBatch($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/'.$part.'.'.$modul.'/install/db/mysql/'.$sqlName.'");';
            }
        }
        $content = str_replace("#install_bd#",$install_bd,$content);
        $content = str_replace("#unistall_bd#",$uninstall_bd,$content);
        //Аякс
        $fl_2 = 0;
        if(isset($output_ms['in18'])){
            if($output_ms['in18'] == 18){
                $fl_2 = 1;
            }
        }
        if($fl_2 === 1){
            $global_make_puth =$output_ms['global_make_puth'];
            $put_current_config_ajax = $_SERVER['DOCUMENT_ROOT'].'/'.$global_make_puth."/.default/php_file_content/add_ajax_component_tpl.php";
            $conntent_tpl = file_get_contents($put_current_config_ajax);
            $conntent_tpl = str_replace("#component_prostranstvo#",$output_ms["in4"],$conntent_tpl);
            $conntent_tpl = str_replace("#modul#",$modul,$conntent_tpl);
            $conntent_tpl = str_replace("#component_name#",$modul.'.'.$output_ms["in5"],$conntent_tpl);
            $content = str_replace("#component_tpl#",$conntent_tpl,$content);
            $content = str_replace("#modul_upper_full#",$upper_modul_full,$content);
        }else{
            $content = str_replace("#component_tpl#","",$content);
        }

        return $content;
    }

    function get_makros_replace_2($part, $modul,$output_ms, $str,$file_name="") {
        $content = $str;
        $content = str_replace("#part#",$part,$content);
        $content = str_replace("#modul#",$modul,$content);
        $upper_modul = ucfirst($modul);
        $content = str_replace("#modul_upper#",$upper_modul,$content);
        $upper_modul_full = toUpper($modul);
        $content = str_replace("#modul_upper_full#",$upper_modul_full,$content);
        $content = str_replace("#comp_img_file#",$file_name,$content);
        $content = str_replace("#modul_id#",$output_ms["in9"],$content);
        $content = str_replace("#part_uri#",$output_ms["in12"],$content);
        $content = str_replace("#version_date#",date("Y-m-d H:i:s", time()),$content);
        $content = str_replace("#version_nomer#",$output_ms["in13"],$content);
        $content = str_replace("#component_prostranstvo#",$output_ms["in4"],$content);
        $content = str_replace("#component_name#",$modul.'.'.$output_ms["in5"],$content);
        $content = str_replace("#parent_menu#",$output_ms["in36"],$content);
        //База
        $install_bd="";
        $uninstall_bd = "";
        if(isset($output_ms['in15'])){
            if($output_ms['in15'] == 15){
                $sqlName = self::getFileName($output_ms['in16']);
                $install_bd = '$errors = $DB->RunSQLBatch($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/'.$part.'.'.$modul.'/install/db/mysql/'.$sqlName.'");';
                $sqlName = self::getFileName($output_ms['in17']);
                $uninstall_bd = '$errors = $DB->RunSQLBatch($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/'.$part.'.'.$modul.'/install/db/mysql/'.$sqlName.'");';
            }
        }
        $content = str_replace("#install_bd#",$install_bd,$content);
        $content = str_replace("#unistall_bd#",$uninstall_bd,$content);

        //Аякс
        $fl_2 = 0;
        if(isset($output_ms['in18'])){
            if($output_ms['in18'] == 18){
                $fl_2 = 1;
            }
        }
        if($fl_2 === 1){
            $global_make_puth =$output_ms['global_make_puth'];
            $put_current_config_ajax = $_SERVER['DOCUMENT_ROOT'].'/'.$global_make_puth."/.default/php_file_content/add_ajax_component_tpl.php";
            $conntent_tpl = file_get_contents($put_current_config_ajax);
            $conntent_tpl = str_replace("#component_prostranstvo#",$output_ms["in4"],$conntent_tpl);
            $conntent_tpl = str_replace("#modul#",$modul,$conntent_tpl);
            $conntent_tpl = str_replace("#component_name#",$modul.'.'.$output_ms["in5"],$conntent_tpl);
            $content = str_replace("#component_tpl#",$conntent_tpl,$content);
        }else{
            $content = str_replace("#component_tpl#","",$content);
        }
        return $content;
    }

    public function createprjAction(){
        $request = $this->getRequest();
        $global_make_puth = $request['global_make_puth'];
        $out ="";
        $name = trim($request['txt']);
        $name = htmlspecialcharsEx($name);
        $dd = self::create_new_prj($name,$global_make_puth);
        if($dd['ok'] === 1){
            $out=GetMessage("MODULCREATOR_AJAX_PRJ").' "'.$name.'" '.GetMessage("MODULCREATOR_AJAX_PRJ_CREATE_OK");
            $out = '1^'.$out.'^'.$dd['name'];
        }else{
            $out = $dd['msg_err'];
            $out = '0^'.$out.'^'.$dd['name'];
        }
        return $out;
    }
    function create_new_prj($name,$global_make_puth){
        if( strlen($name)=== 0 ){
            $out["msg_err"] = GetMessage("MODULCREATOR_AJAX_NO_NAME_PRJ");
            return $out;
        }
        $prefix = "pr";
        $out=Array("ok"=>0,"msg_ok"=>"", "msg_err"=>"" ,"name"=>"");
        $def_put = $_SERVER['DOCUMENT_ROOT']."/".$global_make_puth."/.default/";
        if(!is_dir($def_put)){
            $out["msg_err"] = GetMessage("MODULCREATOR_AJAX_NO_PAPKA_DEFOLT");
        }
        $flExistPrj = CAllModulcreatorInner::ExistPrj($name);
        if($flExistPrj === 1){
            $out["msg_err"] = GetMessage("MODULCREATOR_AJAX_TAKOY_PRJ").' '.$name.' '.GetMessage("MODULCREATOR_AJAX_UJE_EST");
            return $out;
        }
        $idNew = CAllModulcreatorInner::insertPrj($name);
        $to = $_SERVER['DOCUMENT_ROOT']."/".$global_make_puth."/".$prefix.$idNew."/";
        if(is_dir($to)){
            $out["msg_err"] = GetMessage("MODULCREATOR_AJAX_PAPPKA_PRJ_EST").' '.$name.' '.GetMessage("MODULCREATOR_AJAX_UJE_EST");
            return $out;
        }
        mkdir($to,BX_DIR_PERMISSIONS,true);
        CopyDirFiles($def_put, $to, true, true);
        /* Переписываю кое что */
        $put=$_SERVER['DOCUMENT_ROOT']."/".$global_make_puth."/".$prefix.$idNew."/in0.txt";
        file_put_contents($put,$name);
        $out["ok"] = 1;
        $out["name"] = $name;
        return $out;
    }
    public function addlangAction() {
        $out="1";
        $val_input = trim(urldecode($_REQUEST['val_input']));
        $val_input = str_replace('"','',$val_input);
        $val_input = str_replace("'","",$val_input);
        $put = trim(urldecode($_REQUEST['put']));
        $lat_msg = trim(urldecode($_REQUEST['lat_msg']));
        if(file_exists($put)) {
            /* lang файл есть */
            $content_file = file_get_contents($put);
            if(strlen($content_file)<2) {
                $new_str = '<?'."\r\n" . '$MESS['.$lat_msg.'] = "'.$val_input.'";'."\r\n?>";
                $rr = self::save_file_snd_dir($put, $new_str);
            }else{
                /* lang файл чем то уже заполнен */
                $fl_dubl = 0;
                if (strpos($content_file, '"'.$lat_msg.'"') !== false || strpos($content_file, "'".$lat_msg."'") !== false) {/* Сообщение уже есть -редактирую Замена */

                    $fl_dubl = 1;
                    if(strlen(val_input)>0) {
                        $patern = "/MESS[\s]*?\[[\s]*?[\"\']{1}".$lat_msg."[\"\']{1}[\s]*?\][\s]*?=[\s]*?[\"\']{1}[^#]*?[\"\']{1}[^#]*?;/";
                        $na = 'MESS["'.$lat_msg.'"] = "'.$val_input.'";';
                        $new_str = preg_replace($patern,$na,$content_file);
                        $rr = self::save_file_snd_dir($put, $new_str);
                    }
                }
                if($fl_dubl === 0) {
                    $pos = strpos($content_file, '<?');
                    if ($pos !== false) {
                        $replace = '<?' . "\r\n" . '$MESS["' . $lat_msg . '"] = "' . $val_input . '";' . "";
                        $new_str = substr_replace($content_file, $replace, $pos, strlen('<?'));
                        $rr = self::save_file_snd_dir($put, $new_str);
                    }
                }
            }
        }else {
            $new_str = '<?'."\r\n" . '$MESS["'.$lat_msg.'"] = "'.$val_input.'";'."\r\n?>";
            $rr = self::save_file_snd_dir($put, $new_str);
        }
        return $out;
    }
    function save_file_snd_dir($put, $new_str) {
        $file_name_ms = explode("/", $put);
        $file_name = $file_name_ms[(count($file_name_ms) - 1)];
        $dir = str_replace($file_name, "", $put);
        if(!is_dir($dir)) {
            mkdir($dir,BX_DIR_PERMISSIONS,true);
        }
        $rr = file_put_contents($put, $new_str);
    }
}
