示例#1
0
function ActionCatalogueCompleted($CatalogueID, $type)
{
    global $nc_core, $db, $ROOT_FOLDER, $admin_mode;
    global $systemTableID, $systemTableName;
    global $FILES_FOLDER, $INCLUDE_FOLDER;
    global $FILECHMOD, $DIRCHMOD, $ADMIN_FOLDER, $MODULE_FOLDER;
    global $CatalogueID;
    if (isset($_POST['nc_shop_mode_' . $CatalogueID]) && +$_POST['nc_shop_mode_' . $CatalogueID] != $nc_core->get_settings('nc_shop_mode_' . $CatalogueID)) {
        $nc_core->set_settings('nc_shop_mode_' . $CatalogueID, +$_POST['nc_shop_mode_' . $CatalogueID]);
    }
    require_once $INCLUDE_FOLDER . "s_files.inc.php";
    $is_there_any_files = getFileCount(0, $systemTableID);
    $lm_type = $nc_core->page->get_field_name('last_modified_type');
    if ($type == 1) {
        $action = "add";
    }
    if ($type == 2) {
        $CatalogueID = intval($CatalogueID);
        $action = "change";
        $message = $CatalogueID;
    }
    $sm_field = $nc_core->page->get_field_name('sitemap_include');
    $sm_change_field = $nc_core->page->get_field_name('sitemap_changefreq');
    $sm_priority_field = $nc_core->page->get_field_name('sitemap_priority');
    $params = array('Catalogue_Name', 'Domain', 'Template_ID', 'Read_Access_ID', 'Write_Access_ID', 'Edit_Access_ID', 'Subscribe_Access_ID', 'Checked_Access_ID', 'Delete_Access_ID', 'Moderation_ID', 'Checked', 'Priority', 'Mirrors', 'Robots', 'Cache_Access_ID', 'Cache_Lifetime', 'TitleSubIDName', 'DisplayType', 'TitleSubIDKeyword', 'TitleTemplateID', 'E404SubIDName', 'E404SubIDKeyword', 'TitleSubID', 'E404SubID', 'E404TemplateID', 'CommentsEditRules', 'CommentAccessID', 'CommentsDeleteRules', 'posting', 'last_modified_type', 'DisallowIndexing', 'ncOfflineText', 'ncMobile', 'ncMobileSrc', 'ncMobileRedirect', 'ncMobileIdentity');
    if ($nc_core->modules->get_by_keyword('search')) {
        $params = array_merge($params, array($sm_field, $sm_change_field, $sm_priority_field));
    }
    foreach ($params as $v) {
        global ${$v};
    }
    $st = new nc_Component(0, 1);
    foreach ($st->get_fields() as $v) {
        $name = 'f_' . $v['name'];
        global ${$name};
        if ($v['type'] == 6) {
            global ${$name . "_old"};
            global ${"f_KILL" . $v['id']};
        }
        if ($v['type'] == 8) {
            global ${$name . "_day"};
            global ${$name . "_month"};
            global ${$name . "_year"};
            global ${$name . "_hours"};
            global ${$name . "_minutes"};
            global ${$name . "_seconds"};
        }
    }
    $Checked = intval($Checked);
    $Mirrors = str_replace(array("http://", "https://", "/"), "", $Mirrors);
    $Priority += 0;
    $Template_ID = intval($Template_ID);
    $posting = 1;
    // prepare template custom settings
    $settings = $db->get_var("SELECT CustomSettings FROM Template WHERE Template_ID = '" . $Template_ID . "'");
    if ($settings) {
        require_once $ADMIN_FOLDER . "array_to_form.inc.php";
        $a2f = new nc_a2f($settings, 'TemplateSettings');
        if ($a2f->has_errors()) {
            $warnText = $a2f->get_validation_errors();
            $posting = 0;
        }
        $a2f->save($_POST['TemplateSettings']);
        $TemplateSettings = $a2f->get_values_as_string();
        $TemplateSettings = addcslashes($TemplateSettings, "'");
    } else {
        $TemplateSettings = "";
    }
    require $ROOT_FOLDER . "message_fields.php";
    if ($posting == 0) {
        nc_print_status($warnText, 'error');
        CatalogueForm($CatalogueID, 3, "index.php", $type, $action);
        return false;
    }
    require $ROOT_FOLDER . "message_put.php";
    if (nc_module_check_by_keyword("comments")) {
        include_once $MODULE_FOLDER . "comments/function.inc.php";
    }
    switch ($ncMobile) {
        case 2:
            $ncMobile = 0;
            $ncResponsive = 1;
            break;
        case 1:
            $ncMobile = 1;
            $ncResponsive = 0;
            break;
        default:
            $ncMobile = 0;
            $ncResponsive = 0;
            break;
    }
    if ($type == 1) {
        $insert = "INSERT INTO `Catalogue` (";
        for ($i = 0; $i < $fldCount; $i++) {
            if ($fldTypeOfEdit[$i] == 3) {
                continue;
            }
            $insert .= $fld[$i] . ",";
        }
        if (nc_module_check_by_keyword("cache")) {
            $insert .= "`Cache_Access_ID`, `Cache_Lifetime`,";
        }
        $insert .= "`Catalogue_Name`, `Domain`, `" . $nc_core->page->get_field_name('language') . "`, `Template_ID`,  `Read_Access_ID`, `Write_Access_ID`, `Edit_Access_ID`, `Checked_Access_ID`, `Delete_Access_ID`, `Subscribe_Access_ID`, `Moderation_ID`, `Checked`, `Priority`, `Created`, `Mirrors`, `Robots`, `" . $lm_type . "`, `TemplateSettings` , `ncOfflineText`, `ncMobile`, `ncMobileSrc`, `ncMobileRedirect`, `ncMobileIdentity`, `ncResponsive`) ";
        $insert .= "VALUES (";
        for ($i = 0; $i < $fldCount; $i++) {
            if ($fldTypeOfEdit[$i] == 3 || $fldTypeOfEdit[$i] == 2 && !nc_field_check_admin_perm()) {
                continue;
            }
            // поле недоступно никому или доступно администратору но нет прав администратора
            if (isset(${$fld[$i] . 'Defined'}) && ${$fld[$i] . 'Defined'} == true) {
                $insert .= ${$fld[$i] . 'NewValue'} . ",";
            } else {
                $insert .= $fldValue[$i] . ",";
            }
        }
        if (nc_module_check_by_keyword("cache")) {
            $insert .= "'" . intval($Cache_Access_ID) . "',";
            $insert .= "'" . intval($Cache_Lifetime) . "',";
        }
        $insert .= "'" . $db->escape($Catalogue_Name) . "',";
        $insert .= "'" . $db->escape($Domain) . "',";
        $insert .= "'" . $db->escape($nc_core->input->fetch_get_post('language') != '' ? $nc_core->input->fetch_get_post('language') : MAIN_LANG) . "',";
        $insert .= "'" . $db->escape($Template_ID) . "',";
        $insert .= "'" . intval($Read_Access_ID) . "',";
        $insert .= "'" . intval($Write_Access_ID) . "',";
        $insert .= "'" . intval($Edit_Access_ID) . "',";
        $insert .= "'" . intval($Checked_Access_ID) . "',";
        $insert .= "'" . intval($Delete_Access_ID) . "',";
        $insert .= "'" . intval($Subscribe_Access_ID) . "',";
        $insert .= "'" . intval($Moderation_ID) . "',";
        $insert .= "'" . intval($Checked) . "',";
        $insert .= "'" . intval($Priority) . "',";
        $insert .= "'" . date("Y-m-d H:i:s") . "',";
        $insert .= "'" . $db->escape($Mirrors) . "',";
        $insert .= "'" . $db->escape($Robots) . "',";
        $insert .= "'" . intval($last_modified_type) . "',";
        $insert .= "'" . $db->escape($TemplateSettings) . "',";
        $insert .= "'" . $db->escape($ncOfflineText) . "',";
        $insert .= "'" . intval($ncMobile) . "',";
        $insert .= "'" . intval($ncMobileSrc) . "',";
        $insert .= "'" . intval($ncMobileRedirect) . "',";
        $insert .= "'" . intval($ncMobileIdentity) . "',";
        $insert .= "'" . intval($ncResponsive) . "'";
        $insert .= ")";
        // execute core action
        $nc_core->event->execute("addCataloguePrep", 0);
        $db->query($insert);
        if ($db->is_error) {
            throw new nc_Exception_DB_Error($db->last_query, $db->last_error);
        }
        $CatalogueID = $db->insert_id;
        // execute core action
        $nc_core->event->execute("addCatalogue", $CatalogueID);
        $message = $CatalogueID;
        if (nc_module_check_by_keyword("comments")) {
            if ($CommentAccessID > 0) {
                // add comment relation
                $CommentRelationID = nc_comments::addRule($db, array($message), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
                // update inserted data
                $db->query("UPDATE `Catalogue` SET `Comment_Rule_ID` = '" . (int) $CommentRelationID . "' WHERE `Catalogue_ID` = '" . (int) $message . "'");
            }
        }
        // проверка названия раздела
        if (!$TitleSubIDName || !$E404SubIDName) {
            nc_print_status(CONTROL_CONTENT_SUBDIVISION_INDEX_ERROR_THREE_NAME, 'error');
            return false;
        }
        // проверка символов для ключевого слова
        if (!$nc_core->subdivision->validate_hidden_url($TitleSubIDKeyword) || !$nc_core->subdivision->validate_hidden_url($E404SubIDKeyword)) {
            nc_print_status(CONTROL_CONTENT_SUBDIVISION_SUBCLASS_ERROR_KEYWORD_INVALID, 'error');
            return false;
        }
        // execute core action
        $nc_core->event->execute("addSubdivisionPrep", $CatalogueID, 0);
        // Добавление раздела для титульной страницы
        $db->query("INSERT INTO `Subdivision`\n      SET `Catalogue_ID` = '" . intval($CatalogueID) . "',\n      `Parent_Sub_ID` = 0,\n      `Subdivision_Name` = '" . $db->escape($TitleSubIDName) . "',\n      `Template_ID` = '" . intval($TitleTemplateID) . "',\n      `Checked` = 0,\n      `EnglishName` = '" . $db->escape($TitleSubIDKeyword) . "',\n      `Hidden_URL` = '/" . $db->escape($TitleSubIDKeyword) . "/',\n      `Priority` = 0");
        $title_sub_id = $db->insert_id;
        // execute core action
        $nc_core->event->execute("addSubdivision", $CatalogueID, $title_sub_id);
        // execute core action
        $nc_core->event->execute("addSubdivisionPrep", $CatalogueID, 0);
        // Добавление раздела для титульной страницы
        $db->query("INSERT INTO `Subdivision`\n      SET `Catalogue_ID` = '" . $CatalogueID . "',\n      `Parent_Sub_ID` = 0,\n      `Subdivision_Name` = '" . $db->escape($E404SubIDName) . "',\n      `Template_ID` = '" . intval($E404TemplateID) . "',\n      `Checked` = 0,\n      `EnglishName` = '" . $db->escape($E404SubIDKeyword) . "',\n      `Hidden_URL` = '/" . $db->escape($E404SubIDKeyword) . "/',\n      `Priority` = 1");
        $e404_sub_id = $db->insert_id;
        // execute core action
        $nc_core->event->execute("addSubdivision", $CatalogueID, $e404_sub_id);
        // для этого апдейта не нужно вызывать трансляцию события
        $db->query("UPDATE `Catalogue` SET `Title_Sub_ID` = '" . $title_sub_id . "', `E404_Sub_ID` = '" . $e404_sub_id . "' WHERE `Catalogue_ID` = '" . $CatalogueID . "'");
        //добавление системной настройки режима работы магазина.
        if (nc_module_check_by_keyword("netshop")) {
            $db->query("INSERT INTO `Settings` (`Key`, `Value`, `Module`, `Catalogue_ID`) VALUES ('nc_shop_mode_" . $CatalogueID . "', '2', 'system', '0')");
        }
    }
    if ($type == 2) {
        $cur_checked = $db->get_var("SELECT `Checked` FROM `Catalogue` WHERE `Catalogue_ID` = '" . $CatalogueID . "'");
        if (nc_module_check_by_keyword("comments")) {
            // get rule id
            $CommentData = nc_comments::getRuleData($db, array($CatalogueID));
            $CommentRelationID = $CommentData['ID'];
            // do something
            switch (true) {
                case $CommentAccessID > 0 && $CommentRelationID:
                    // update comment rules
                    nc_comments::updateRule($db, array($CatalogueID), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
                    break;
                case $CommentAccessID > 0 && !$CommentRelationID:
                    // add comment relation
                    $CommentRelationID = nc_comments::addRule($db, array($CatalogueID), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
                    break;
                case $CommentAccessID <= 0 && $CommentRelationID:
                    // delete comment rules
                    nc_comments::dropRuleCatalogue($db, $CatalogueID);
                    $CommentRelationID = 0;
                    break;
            }
        }
        $update = " UPDATE `Catalogue` SET ";
        for ($i = 0; $i < $fldCount; $i++) {
            if ($fldTypeOfEdit[$i] == 3) {
                continue;
            }
            // поле недоступно никому
            if (isset(${$fld[$i] . 'Defined'}) && ${$fld[$i] . 'Defined'} == true) {
                $update .= $fld[$i] . "=" . ${$fld[$i] . 'NewValue'} . ",";
            } else {
                $update .= $fld[$i] . "=" . $fldValue[$i] . ",";
            }
        }
        $update .= "`Catalogue_Name` = '" . $db->escape($Catalogue_Name) . "',";
        $update .= "`Domain` = '" . $db->escape($Domain) . "',";
        $update .= "`Template_ID` = " . intval($Template_ID) . ",";
        $update .= "`Read_Access_ID` = '" . intval($Read_Access_ID) . "',";
        $update .= "`Write_Access_ID` = '" . intval($Write_Access_ID) . "',";
        $update .= "`Edit_Access_ID` = '" . intval($Edit_Access_ID) . "',";
        $update .= "`Checked_Access_ID` = '" . intval($Checked_Access_ID) . "',";
        $update .= "`Delete_Access_ID` = '" . intval($Delete_Access_ID) . "',";
        $update .= "`Subscribe_Access_ID` = '" . intval($Subscribe_Access_ID) . "',";
        if (nc_module_check_by_keyword("cache")) {
            $update .= "`Cache_Access_ID` = '" . intval($Cache_Access_ID) . "',";
            $update .= "`Cache_Lifetime` = '" . intval($Cache_Lifetime) . "',";
        }
        if (nc_module_check_by_keyword("comments")) {
            $update .= "`Comment_Rule_ID` = '" . intval($CommentRelationID) . "',";
        }
        $update .= "`Moderation_ID` = '" . intval($Moderation_ID) . "',";
        $update .= "`Checked` = '" . intval($Checked) . "',";
        $update .= "`Priority` = '" . intval($Priority) . "',";
        $update .= "`Mirrors` = '" . $db->escape($Mirrors) . "',";
        $update .= "`Robots` = '" . $db->escape($Robots) . "',";
        $update .= "`Title_Sub_ID` = '" . intval($TitleSubID) . "',";
        $update .= "`E404_Sub_ID` = '" . intval($E404SubID) . "',";
        $update .= "`" . $lm_type . "` = '" . intval($last_modified_type) . "',";
        $update .= "`DisallowIndexing`= '" . intval($DisallowIndexing) . "',";
        $update .= "`" . $nc_core->page->get_field_name('language') . "` = '" . $nc_core->input->fetch_get_post('language') . "',";
        if ($nc_core->modules->get_by_keyword('search')) {
            $update .= "`" . $sm_field . "` = '" . $nc_core->input->fetch_get_post('sitemap_include') . "',";
            $update .= "`" . $sm_change_field . "` = '" . $nc_core->input->fetch_get_post('sitemap_changefreq') . "',";
            $update .= "`" . $sm_priority_field . "` = '" . str_replace(',', '.', sprintf("%.1f", doubleval($nc_core->input->fetch_get_post('sitemap_priority')))) . "',";
        }
        $update .= "`TemplateSettings` = '" . $db->escape($TemplateSettings) . "',";
        $update .= "`ncOfflineText` = '" . $db->escape($ncOfflineText) . "',";
        $update .= "`ncMobile` = '" . intval($ncMobile) . "',";
        $update .= "`ncMobileSrc` = '" . intval($ncMobileSrc) . "',";
        $update .= "`ncMobileRedirect` = '" . intval($ncMobileRedirect) . "',";
        $update .= "`ncMobileIdentity` = '" . intval($ncMobileIdentity) . "',";
        $update .= "`ncResponsive` = '" . intval($ncResponsive) . "',";
        $update .= "`DisplayType` = '" . $db->escape($DisplayType) . "'";
        $update .= " WHERE `Catalogue_ID` = " . $CatalogueID;
        // execute core action
        $nc_core->event->execute("updateCataloguePrep", $CatalogueID);
        if ($cur_checked != $Checked) {
            $nc_core->event->execute($Checked ? "checkCataloguePrep" : "uncheckCataloguePrep", $CatalogueID);
        }
        $db->query($update);
        if ($db->is_error) {
            throw new nc_Exception_DB_Error($db->last_query, $db->last_error);
        }
        // execute core action
        $nc_core->event->execute("updateCatalogue", $CatalogueID);
        // произошло включение / выключение
        if ($cur_checked != $Checked) {
            $nc_core->event->execute($Checked ? "checkCatalogue" : "uncheckCatalogue", $CatalogueID);
        }
    }
    /*     * */
    if (is_array($filetable_lastid) && !empty($filetable_lastid)) {
        foreach ($filetable_lastid as $id) {
            $db->query("UPDATE `Filetable` SET `Message_ID` = '" . $message . "' WHERE `ID` = '" . intval($id) . "'");
        }
    }
    /*     * */
    if ($tmpFile) {
        @mkdir($FILES_FOLDER . "c/", $DIRCHMOD);
    }
    for ($i = 0; $i < count($tmpFile); $i++) {
        eval("\$tmpNewFile[\$i] = \"" . $tmpNewFile[$i] . "\";");
        if ($FileFS[$i] == NC_FS_PROTECTED || $FileFS[$i] == NC_FS_ORIGINAL) {
            @rename($nc_core->FILES_FOLDER . $tmpNewFile[$i], $nc_core->FILES_FOLDER . $File_PathNew[$i] . $tmpNewFile[$i]);
        } else {
            @rename($nc_core->FILES_FOLDER . $tmpFile[$i], $nc_core->FILES_FOLDER . $File_Path[$i] . $tmpNewFile[$i]);
        }
        @chmod($FILES_FOLDER . "c/" . $tmpNewFile[$i], $FILECHMOD);
    }
    // сброс
    $nc_core->catalogue->load_all();
    return true;
}
示例#2
0
文件: SubClass.php 项目: Blu2z/implsk
 $CustomSettings = $nc_core->input->fetch_post('CustomSettings');
 // получение значения дополнительных настроек (CustomSettings)
 if (!$ClassID) {
     $SQL = "SELECT `Class_ID`\n                            FROM `Sub_Class`\n                                WHERE `Sub_Class_ID` = " . +$SubClassID;
     $ClassID = $db->get_var($SQL);
 }
 $SQL = "SELECT `CustomSettingsTemplate`\n                        FROM `Class`\n                            WHERE `Class_ID` = " . +($Class_Template_ID ? $Class_Template_ID : $ClassID);
 $settings_array = $db->get_var($SQL);
 if ($settings_array) {
     require_once $ADMIN_FOLDER . "array_to_form.inc.php";
     $a2f = new nc_a2f($settings_array, 'CustomSettings');
     if (!$a2f->validate($CustomSettings)) {
         $error = $a2f->get_validation_errors();
     } else {
         $a2f->save($CustomSettings);
         $CustomSettings = $a2f->get_values_as_string();
     }
 } else {
     $CustomSettings = "";
 }
 // транслитерация, если пустой EnglishName
 if (empty($EnglishName)) {
     // здесь не нужна проверка на уникальность, поскольку далее
     // значение используется лишь для проверки на валидность
     $EnglishName = nc_transliterate($SubClassName, true);
 }
 // проверка значений
 if ($SubClassName == "") {
     $error = CONTROL_CONTENT_SUBDIVISION_SUBCLASS_ERROR_NAME;
 } elseif (!$nc_core->sub_class->validate_english_name($EnglishName)) {
     $error = CONTROL_CONTENT_SUBDIVISION_SUBCLASS_ERROR_KEYWORD_INVALID;
示例#3
0
function nc_subdivision_add()
{
    $nc_core = nc_Core::get_object();
    $db = $nc_core->db;
    $CatalogueID = intval($nc_core->input->fetch_get_post('CatalogueID'));
    $ParentSubID = intval($nc_core->input->fetch_get_post('ParentSubID'));
    $Template_ID = intval($nc_core->input->fetch_get_post('Template_ID'));
    $input = $nc_core->input->fetch_get_post();
    // проверка названия раздела
    $Subdivision_Name = trim($nc_core->input->fetch_get_post('Subdivision_Name'));
    if (!$Subdivision_Name) {
        throw new Exception(CONTROL_CONTENT_SUBDIVISION_INDEX_ERROR_THREE_NAME);
    }
    // проверка ключевого слова
    $EnglishName = trim($nc_core->input->fetch_get_post('EnglishName'));
    if (empty($EnglishName)) {
        $EnglishName = nc_transliterate($Subdivision_Name, true);
    }
    // проверка на валидность
    $EnglishName = nc_check_english_name(0, $EnglishName, 1);
    if (!$nc_core->subdivision->validate_english_name($EnglishName)) {
        throw new Exception(CONTROL_CONTENT_SUBDIVISION_SUBCLASS_ERROR_KEYWORD_INVALID);
    }
    // проверка уникальности ключевого слова
    if (!IsAllowedSubdivisionEnglishName($EnglishName, $ParentSubID, 0, $CatalogueID)) {
        throw new Exception(CONTROL_CONTENT_SUBDIVISION_INDEX_ERROR_THREE_KEYWORD);
    }
    // визуальные настройки
    $TemplateSettings = "";
    if ($_POST['is_parent_template'] == 'true') {
        $Template_ID = 0;
    }
    if ($Template_ID) {
        $settings = $nc_core->db->get_var("SELECT `CustomSettings` FROM `Template` WHERE `Template_ID` = '" . $Template_ID . "'");
        if ($settings) {
            require_once $nc_core->ADMIN_FOLDER . "array_to_form.inc.php";
            $a2f = new nc_a2f($settings, 'TemplateSettings');
            if (!$a2f->validate($_POST['TemplateSettings'])) {
                throw new Exception($a2f->get_validation_errors());
            }
            if (isset($_POST['TemplateSettings']) && !empty($_POST['TemplateSettings'])) {
                $a2f->save($_POST['TemplateSettings']);
                $TemplateSettings = $a2f->get_values_as_string();
            }
        }
    }
    // execute core action
    $nc_core->event->execute("addSubdivisionPrep", $CatalogueID, 0);
    // добавление раздела
    $db->query("\n        INSERT INTO `Subdivision`\n            SET `Created` = NOW(),\n                `Subdivision_Name` = '" . $db->escape($Subdivision_Name) . "',\n                `EnglishName` = '" . $db->escape($EnglishName) . "',\n                `Parent_Sub_ID` = '" . $ParentSubID . "',\n                `Catalogue_ID` = '" . $CatalogueID . "',\n                `Checked` = '" . intval($input['Checked']) . "',\n                `Priority` = '" . intval($input['Priority']) . "',\n                `Favorite` = '" . intval($input['Favorite']) . "',\n                `UseMultiSubClass` = 1,\n                `Template_ID` = '" . $Template_ID . "',\n                `TemplateSettings` = '" . $db->escape($TemplateSettings) . "',\n                `UseEditDesignTemplate` = '" . intval($input['UseEditDesignTemplate']) . "',\n                `DisplayType` = '" . $db->escape($nc_core->input->fetch_get_post('DisplayType')) . "'");
    if ($db->is_error) {
        throw new nc_Exception_DB_Error($db->last_query, $db->last_error);
    }
    $SubdivisionID = $db->insert_id;
    // обновим Hidden_URL
    $hidden_url = GetHiddenURL($ParentSubID);
    UpdateHiddenURL($hidden_url ? $hidden_url : "/", $ParentSubID, $CatalogueID);
    $nc_core->event->execute("addSubdivision", $CatalogueID, $SubdivisionID);
    // добавление компонента в разделе
    $Class_ID = intval($input['Class_ID']);
    $Class_Template_ID = intval($input['Class_Template_ID']);
    if ($Class_ID) {
        // визуальные настройки
        $CustomSettings = "";
        $settings_array = $db->get_var("SELECT `CustomSettingsTemplate` FROM `Class`\n      WHERE `Class_ID` = '" . ($Class_Template_ID ? $Class_Template_ID : $Class_ID) . "'");
        if ($settings_array) {
            require_once $nc_core->ADMIN_FOLDER . "array_to_form.inc.php";
            $a2f = new nc_a2f($settings_array, 'CustomSettings');
            if (!$a2f->validate($_POST['CustomSettings'])) {
                $error = $a2f->get_validation_errors();
            } else {
                $a2f->save($_POST['CustomSettings']);
                $CustomSettings = $a2f->get_values_as_string();
            }
        }
        $nc_core->event->execute("addSubClassPrep", $CatalogueID, $SubdivisionID, 0);
        $db->query("INSERT INTO `Sub_Class`\n      (`Subdivision_ID`, `Catalogue_ID`, `Class_ID`, `Sub_Class_Name`, `Checked`, `EnglishName`, `Created`, `CustomSettings`, `Class_Template_ID`)\n       VALUES\n       ('" . $SubdivisionID . "', '" . $CatalogueID . "', '" . $Class_ID . "', '" . $Subdivision_Name . "', 1, '" . $EnglishName . "',  '" . date("Y-m-d H:i:s") . "',  '" . addcslashes($CustomSettings, "'") . "', '" . $Class_Template_ID . "')");
        if ($SubClassID = $db->insert_id) {
            $nc_core->event->execute("addSubClass", $CatalogueID, $SubdivisionID, $SubClassID);
        }
    }
    return $SubdivisionID;
}