<?
$module_id = "directoriya.modulcreator";
CModule::IncludeModule($module_id);
$POST_RIGHT = $APPLICATION->GetGroupRight($module_id);
$arSelectMnu = CAllModulcreator::parentMnu();
if ($POST_RIGHT >= "R"){
    $rsGroups = CGroup::GetList($by = "ID", $order = "asc",Array("ACTIVE"=>"Y"),"N");
    $arGruppMs = array();
    while($arGroups = $rsGroups->Fetch()){
        $arGruppMs[$arGroups['ID']] = $arGroups["NAME"];
    }
    IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/options.php");
    IncludeModuleLangFile(__FILE__);
    $arAllOptions = array(
        array("admin_opt_prj_new_def", GetMessage("MODULCREATOR_PRJ_NEW_DEF"), array("text", 50)),
        array("admin_opt_component_msg_modul_sort_def", GetMessage("MODULCREATOR_OPT_SORT"), array("text", 50)),
        array("admin_opt_part_def", GetMessage("MODULCREATOR_OPT_PART_LAT_TIT"), array("text", 50)),
        array("admin_opt_modul_def", GetMessage("MODULCREATOR_OPT_MODUL_LAT_TIT"), array("text", 50)),
        array("admin_opt_chel_name_modul_def", GetMessage("MODULCREATOR_OPT_CHEL_NAME_MODUL_TIT"), array("text", 50)),

        array("admin_opt_component_ch_def", GetMessage("MODULCREATOR_OPT_COMPONENT_CH_TIT"), array("checkbox", "N")),

        array("admin_opt_namespase_component_def", GetMessage("MODULCREATOR_OPT_NAMESPASE_COMPONENT_TIT"), array("text", 50)),
        array("admin_opt_sys_name_component_def", GetMessage("MODULCREATOR_OPT_SYS_NAME_COMPONENT_TIT"), array("text", 50)),
        array("admin_opt_grupp_name_component_def", GetMessage("MODULCREATOR_OPT_GRUPP_NAME_COMPONENT_TIT"), array("text", 50)),
        array("admin_opt_name_component_def", GetMessage("MODULCREATOR_OPT_NAME_COMPONENT_TIT"), array("text", 50)),
        array("admin_opt_ds_component_def", GetMessage("MODULCREATOR_OPT_DS_COMPONENT_TIT"), array("text", 50)),
        array("admin_opt_id_component_lat_def", GetMessage("MODULCREATOR_OPT_ID_COMPONENT_LAT_TIT"), array("text", 50)),
        array("admin_opt_file_icon_component_def", GetMessage("MODULCREATOR_OPT_FILE_ICON_COMPONENT_TIT"), array("text", 50)),
        array("admin_opt_ajax_component_def", GetMessage("MODULCREATOR_OPT_AJAX_COMPONENT_TIT"), array("checkbox", "N")),
        array("admin_opt_mysql_def", GetMessage("MODULCREATOR_OPT_MYSQL_TIT"), array("checkbox", "N")),
        array("admin_opt_puth_install_mysql_def", GetMessage("MODULCREATOR_OPT_PUTH_INSTALL_MYSQL_TIT"), array("text", 50)),
        array("admin_opt_puth_uninstall_mysql_def", GetMessage("MODULCREATOR_OPT_PUTH_UNINSTALL_MYSQL_TIT"), array("text", 50)),
        array("admin_opt_d7_def", GetMessage("MODULCREATOR_OPT_D7_TIT"), array("checkbox", "N")),
        array("admin_opt_work_page_modul_ch_def", GetMessage("MODULCREATOR_OPT_WORK_PAGE_MODUL_CH_TIT"), array("checkbox", "N")),
        array("admin_opt_work_page_modul_title_def", GetMessage("MODULCREATOR_OPT_WORK_PAGE_MODUL_TITLE_TIT"), array("text", 50)),
        array("admin_page_mnu_title", GetMessage("MODULCREATOR_OPT_TIT_PAGE_DEFOLT"), array("text", 50)),

        array("admin_opt_id_menu_parent_def", GetMessage("MODULCREATOR_OPT_ID_MENU_PARENT_TIT"), array("selectbox", $arSelectMnu, 'size="7"')),
        array("admin_opt_part_url_def", GetMessage("MODULCREATOR_PART_URL_TIT"), array("text", 50)),
        array("admin_opt_chel_name_part_def", GetMessage("MODULCREATOR_CHEL_NAME_PART_TIT"), array("text", 50)),
        array("admin_opt_short_ds_modul_def", GetMessage("MODULCREATOR_SHORT_DS_MODUL_TIT"), array("text", 50)),
        array("admin_opt_version_def", GetMessage("MODULCREATOR_VERSION_TIT"), array("text", 50)),



        array("admin_opt_snoska_kontent", GetMessage("MODULCREATOR_OPT_PRIMER_SNOSKA"), array("text", 50)),
        array("admin_opt_snoska_bottom", GetMessage("MODULCREATOR_OPT_PRIMER_SNOSKA2"), array("text", 50)),
        array("admin_opt_component_msg_modul_not_installed", GetMessage("MODULCREATOR_OPT_PRIMER_SNOSKA3"), array("text", 50)),
    );
    $aTabs = array(
        array("DIV" => "edit1", "TAB" => GetMessage("MAIN_TAB_SET"), "ICON" => "", "TITLE" => GetMessage("MODULCREATOR_TAB1_TITLE")),
        array("DIV" => "edit4", "TAB" => GetMessage("MAIN_TAB_RIGHTS"), "ICON" => "", "TITLE" => GetMessage("MAIN_TAB_TITLE_RIGHTS"))
    );
    $tabControl = new CAdmintabControl("tabControl", $aTabs);
    if (ToUpper($REQUEST_METHOD) == "POST" && strlen($Update.$Apply.$RestoreDefaults)>0 && ($POST_RIGHT=="W" || $POST_RIGHT=="X") && check_bitrix_sessid()){
        $error = '';
        if (strlen($RestoreDefaults)>0){
            COption::RemoveOption($module_id);
            $z = CGroup::GetList($v1="id",$v2="asc", array("ACTIVE" => "Y", "ADMIN" => "N"));
            while ($zr = $z->Fetch()){
                $APPLICATION->DelGroupRight($module_id, array($zr["ID"]));
            }
        }else{
            foreach ($arAllOptions as $arOption){
                foreach ($arAllOptions as $arOption){
                    $name = $arOption[0];
                    if ($arOption[2][0]=="text-list"){
                        $val = "";
                        for ($j=0; $j<count($$name); $j++)
                        {
                            if (strlen(trim(${$name}[$j])) > 0)
                                $val .= ($val <> ""? ",":"").trim(${$name}[$j]);
                        }
                    }elseif ($arOption[2][0]=="selectbox" || $arOption[2][0]=="selectboxtree"){
                        $val = "";
                        for ($j=0; $j<count($$name); $j++){
                            if (strlen(trim(${$name}[$j])) > 0) {
                                $val .= ($val <> "" ? "," : "") . trim(${$name}[$j]);
                            }
                        }
                    }else {
                        $val = $$name;
                    }
                    if ($arOption[2][0] == "checkbox" && $val <> "Y") {
                        $val = "N";
                    }
                    COption::SetOptionString($module_id, $name, $val);
                }
            }

        }
        $Update = $Update.$Apply;
        ob_start();
        require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/admin/group_rights.php");
        ob_end_clean();
        if (strlen($error)) {
            ShowError($error);
        } elseif(strlen($Update)>0 && strlen($_REQUEST["back_url_settings"])>0) {
            LocalRedirect($_REQUEST["back_url_settings"]);
        } else {
            LocalRedirect($APPLICATION->GetCurPage()."?mid=".urlencode($module_id)."&lang=".urlencode(LANGUAGE_ID)."&back_url_settings=".urlencode($_REQUEST["back_url_settings"])."&".$tabControl->ActiveTabParam());
        }
    }
    $global_make_puth = 'bitrix/modules/directoriya.modulcreator/allpr';
    $fullP =$_SERVER['DOCUMENT_ROOT']."/".$global_make_puth;
    $ff = CAllModulcreator::chdir($fullP);
    CJSCore::Init(array("jquery"));
    $APPLICATION->SetAdditionalCSS("/bitrix/panel/directoriya.modulcreator/adm.css");
    $APPLICATION->AddHeadScript("/bitrix/panel/directoriya.modulcreator/adm.js");
    ?>
    <form method="post" action="<?echo $APPLICATION->GetCurPage()?>?mid=<?=urlencode($mid)?>&amp;lang=<?=LANGUAGE_ID?>">
        <?
        $tabControl->Begin();
        $tabControl->BeginNextTab();
        ?>
        <tr class="heading">
            <td colspan="2"><?=GetMessage("MODULCREATOR_BLOK_OSN_NASTROYKI");?></td>
        </tr>

                    <?
                    foreach($arAllOptions as $Option){
                        $type = $Option[2];
                        $val = COption::GetOptionString($module_id, $Option[0]);
                        ?>
                    <tr>
                        <td valign="top" width="40%"><?
                            if($type[0]=="checkbox") {
                                echo "<label for=\"" . htmlspecialcharsbx($Option[0]) . "\">" . $Option[1] . "</label>";
                            }else {
                                echo $Option[1];
                            }
                            ?></td>
                        <td valign="top" width="60%" class="opt-td2">
                            <?if($type[0]=="checkbox") {?>
                                <input type="checkbox" name="<?echo htmlspecialcharsbx($Option[0])?>" id="<?echo htmlspecialcharsbx($Option[0])?>" value="Y"<?if($val=="Y")echo" checked";?> />
                            <?}?>
                            <?if($type[0]=="text") {?>
                                <input type="text" size="<?echo $type[1]?>" maxlength="255" value="<?echo htmlspecialcharsbx($val)?>" name="<?echo htmlspecialcharsbx($Option[0])?>" />
                            <?}?>
                            <?if($type[0]=="textarea") {?>
                                <textarea rows="<?echo $type[1]?>" cols="<?echo $type[2]?>" name="<?echo htmlspecialcharsbx($Option[0])?>"><?echo htmlspecialcharsbx($val)?></textarea>
                            <?}?>
                            <?if($type[0]=="text-list") {
                                $aVal = explode(",", $val);
                                for($j=0; $j<count($aVal); $j++){?>
                                   <input type="text" size="<?echo $type[2]?>" value="<?echo htmlspecialcharsbx($aVal[$j])?>" name="<?echo htmlspecialcharsbx($Option[0])."[]"?>" /><br />
                                <?}
                                for($j=0; $j<$type[1]; $j++) {?>
                                    <input type="text" size="<?echo $type[2]?>" value="" name="<?echo htmlspecialcharsbx($Option[0])."[]"?>" /><br />
                                <?}

                            }?>
                            <?if($type[0]=="selectbox") {
                                $arr = $type[1];
                                $arr_keys = array_keys($arr);
                                $arVal = explode(",", $val);
                                ?>
                                <select name="<?echo htmlspecialcharsbx($Option[0])?>[]"<?= $type[2]?>><?
                                    for($j=0; $j<count($arr_keys); $j++) { ?>
                                       <option value="<?echo $arr_keys[$j]?>"<?if(in_array($arr_keys[$j], $arVal))echo ' selected="selected"'?>><?echo htmlspecialcharsbx($arr[$arr_keys[$j]])?></option>
                                    <?}?>
                                </select>
                            <?}?>
                            <?if($type[0]=="selectboxtree") {
                                $arr = $type[1];
                                $arr_keys = array_keys($arr);
                                $arVal = explode(',', $val);
                                $s = '<select name="'.htmlspecialcharsbx($Option[0]).'[]"'.$type[2].'>';
                                foreach ($arIBblocks as $arType) {
                                     $strIBlocksCpGr = '';
                                     foreach ($arType['ITEMS'] as $arIB) {
                                             if (in_array($arIB['ID'], $arVal)) {
                                                 $sel = ' selected="selected"';
                                             } else {
                                                 $sel = '';
                                             }
                                             $strIBlocksCpGr .= '<option value="'.$arIB['ID'].'"'.$sel.'>'.$arIB['NAME'].'</option>';
                                     }
                                     if ($strIBlocksCpGr != '') {
                                        $s .= '<optgroup label="'.$arType['NAME'].'">';
                                        $s .= $strIBlocksCpGr;
                                        $s .= '</optgroup>';
                                     }
                                }
                                $s .= '</select>';
                                echo $s;
                            }?>
                            <?
                            if($Option[0] == 'admin_page_mnu_title') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m18.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_OPT_PAGE_TITLE")."'", GetMessage("MODULCREATOR_OPT_PAGE_TITLE"));
                            }
                            if($Option[0] == 'admin_opt_snoska_kontent' || $Option[0] == 'admin_opt_snoska_bottom') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m10.jpg';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_component_msg_modul_not_installed') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m13.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_prj_new_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m24.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_part_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m25.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_modul_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m26.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_chel_name_modul_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m27.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }

                            if($Option[0] == 'admin_opt_namespase_component_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m28.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_sys_name_component_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m29.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }

                            if($Option[0] == 'admin_opt_grupp_name_component_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m1.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_name_component_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m2.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_ds_component_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m3.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_id_component_lat_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m4.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_file_icon_component_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m5.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }

                            if($Option[0] == 'admin_opt_chel_name_part_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m6.jpg';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_work_page_modul_title_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m30.png';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }
                            if($Option[0] == 'admin_opt_short_ds_modul_def') {
                                $img = '/bitrix/panel/directoriya.modulcreator/img/m8.jpg';
                                echo CFile::Show2Images($img, $img, 100, 100, "hspace='0' vspace='0' border='0' title='".GetMessage("MODULCREATOR_GDE_RASPOLOJENO")."'", GetMessage("MODULCREATOR_GDE_RASPOLOJENO"));
                            }



                            ?>
                        </td>
                    </tr>
                    <?}
                    $tabControl->BeginNextTab();
                    require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/admin/group_rights.php");
                    $tabControl->Buttons();
                    ?>
                    <input <?if ($POST_RIGHT<"W") echo "disabled" ?> type="submit" name="Update" value="<?=GetMessage("MAIN_SAVE")?>" title="<?=GetMessage("MAIN_OPT_SAVE_TITLE")?>" />
                    <input <?if ($POST_RIGHT<"W") echo "disabled" ?> type="submit" name="Apply" value="<?=GetMessage("MAIN_OPT_APPLY")?>" title="<?=GetMessage("MAIN_OPT_APPLY_TITLE")?>" />
                    <?if(strlen($_REQUEST["back_url_settings"])>0):?>
                        <input <?if ($POST_RIGHT<"W") echo "disabled" ?> type="button" name="Cancel" value="<?=GetMessage("MAIN_OPT_CANCEL")?>" title="<?=GetMessage("MAIN_OPT_CANCEL_TITLE")?>" onclick="window.location='<?echo htmlspecialcharsbx(CUtil::addslashes($_REQUEST["back_url_settings"]))?>'" />
                        <input type="hidden" name="back_url_settings" value="<?=htmlspecialcharsbx($_REQUEST["back_url_settings"])?>" />
                    <?endif?>
                    <input <?if ($POST_RIGHT<"W") echo "disabled" ?> type="submit" name="RestoreDefaults" title="<?echo GetMessage("MAIN_HINT_RESTORE_DEFAULTS")?>" OnClick="confirm('<?echo AddSlashes(GetMessage("MAIN_HINT_RESTORE_DEFAULTS_WARNING"))?>')" value="<?echo GetMessage("MAIN_RESTORE_DEFAULTS")?>" />
                    <?=bitrix_sessid_post();?>
                    <?$tabControl->End();?>
    </form>

<?}
?>