function ActionSubClassCompleted($type) { global $nc_core, $db, $ClassID; global $loc, $ADMIN_FOLDER, $MODULE_FOLDER, $CustomSettings; $params = array('Priority', 'Checked', 'SubClassName', 'EnglishName', 'Class_Template_ID', 'DefaultAction', 'isNakedCC', 'AllowTags', 'NL2BR', 'UseCaptcha', 'RecordsPerPage', 'SortBy', 'Read_Access_ID', 'Write_Access_ID', 'Cache_Lifetime', 'Edit_Access_ID', 'Checked_Access_ID', 'Delete_Access_ID', 'Moderation_ID', 'CacheAccessID', 'CacheLifetime', 'CacheForUser', 'CommentAccessID', 'Edit_Class_Template', 'CommentsEditRules', 'CommentsDeleteRules', 'SubClassID', 'SubdivisionID', 'CatalogueID', 'SrcMirror', 'Cache_Access_ID'); foreach ($params as $v) { ${$v} = $nc_core->input->fetch_get_post($v); } //транслитерация, если пустой EnglishName if (empty($EnglishName)) { $EnglishName = nc_transliterate($SubClassName, true); } // проверка на валидность $EnglishName = nc_check_english_name((int) $SubClassID, $EnglishName, 2); if (nc_module_check_by_keyword("comments")) { include_once $MODULE_FOLDER . "comments/function.inc.php"; } if (+$_POST['is_mirror']) { $ClassID = $nc_core->sub_class->get_by_id(+$SrcMirror, 'Class_ID'); } if ($Class_Template_ID == $ClassID) { $Class_Template_ID = 0; } if ($Priority === '') { $Priority = $db->get_var("SELECT (`Priority` + 1) FROM `Sub_Class` WHERE `Subdivision_ID` = '" . $loc->SubdivisionID . "' ORDER BY `Priority` DESC LIMIT 1"); } if ($type == 1) { if (nc_module_check_by_keyword("cache")) { $cache_insert_fields = "`Cache_Access_ID`, `Cache_Lifetime`, `CacheForUser`,"; $cache_insert_values = "'" . $Cache_Access_ID . "', '" . $Cache_Lifetime . "', '" . $CacheForUser . "',"; } else { $cache_insert_fields = ""; $cache_insert_values = ""; } $insert = "INSERT INTO `Sub_Class` (" . $cache_insert_fields . "`Subdivision_ID`, `Catalogue_ID`, `Class_ID`, `Sub_Class_Name`, `Read_Access_ID`, `Write_Access_ID`, `Edit_Access_ID`, `Checked_Access_ID`, `Delete_Access_ID`, `Subscribe_Access_ID`, `Moderation_ID`, `Checked`, `Priority`, `EnglishName`, `DaysToHold`, `AllowTags`, `NL2BR`, `RecordsPerPage`, `SortBy`, `Created`, `DefaultAction`, `UseCaptcha`, `CustomSettings`, `Class_Template_ID`, `isNaked`, `SrcMirror`)"; $insert .= " VALUES (" . $cache_insert_values . "'" . $loc->SubdivisionID . "', '" . $loc->CatalogueID . "', '" . $ClassID . "', '" . $db->escape($SubClassName) . "', '" . $Read_Access_ID . "', '" . $Write_Access_ID . "', '" . $Edit_Access_ID . "', '" . $Checked_Access_ID . "','" . $Delete_Access_ID . "','" . $SubscribeAccessID . "', '" . $Moderation_ID . "', '" . $Checked . "', '" . $Priority . "', '" . $EnglishName . "', "; $insert .= $DaysToHold == "" ? "NULL, " : "'" . $DaysToHold . "', "; $insert .= "'" . $AllowTags . "', "; $insert .= "'" . $NL2BR . "', "; $insert .= $RecordsPerPage == "" ? "NULL" : "'" . $RecordsPerPage . "'"; $insert .= ",'{$SortBy}','" . date("Y-m-d H:i:s") . "','" . $DefaultAction . "', '" . $UseCaptcha . "', '" . addcslashes($CustomSettings, "'") . "', '" . $Class_Template_ID . "', '" . $isNakedCC . "', '" . $SrcMirror . "')"; // execute core action $nc_core->event->execute("addSubClassPrep", $loc->CatalogueID, $loc->SubdivisionID, 0); $db->query($insert); // inserted ID $insertedSubClassID = $db->insert_id; // execute core action $nc_core->event->execute("addSubClass", $loc->CatalogueID, $loc->SubdivisionID, $insertedSubClassID); if (nc_module_check_by_keyword("comments")) { if ($CommentAccessID > 0) { // add comment relation $CommentRelationID = nc_comments::addRule($db, array($loc->CatalogueID, $loc->SubdivisionID, $insertedSubClassID), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules); // update inserted data $db->query("UPDATE `Sub_Class` SET `Comment_Rule_ID` = '" . (int) $CommentRelationID . "' WHERE `Sub_Class_ID` = '" . (int) $insertedSubClassID . "'"); } } return $insertedSubClassID; } if ($type == 2) { $cur_checked = $db->get_var("SELECT `Checked` FROM `Sub_Class` WHERE `Sub_Class_ID` = '" . $SubClassID . "'"); if (nc_module_check_by_keyword("comments")) { $CommentData = nc_comments::getRuleData($db, array($loc->CatalogueID, $loc->SubdivisionID, $SubClassID)); $CommentRelationID = $CommentData['ID']; switch (true) { case $CommentAccessID > 0 && $CommentRelationID: // update comment rules nc_comments::updateRule($db, array($loc->CatalogueID, $loc->SubdivisionID, $SubClassID), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules); break; case $CommentAccessID > 0 && !$CommentRelationID: // add comment relation $CommentRelationID = nc_comments::addRule($db, array($loc->CatalogueID, $loc->SubdivisionID, $SubClassID), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules); break; case $CommentAccessID <= 0 && $CommentRelationID: // delete comment rules nc_comments::dropRuleSubClass($db, $SubClassID); $CommentRelationID = 0; break; } } $update = "UPDATE `Sub_Class` SET "; $update .= "`Sub_Class_Name` = '" . $db->escape($SubClassName) . "',"; $update .= "`Read_Access_ID` = '" . $Read_Access_ID . "',"; $update .= "`Write_Access_ID` = '" . $Write_Access_ID . "',"; $update .= "`Edit_Access_ID` = '" . $Edit_Access_ID . "',"; $update .= "`Checked_Access_ID` = '" . $Checked_Access_ID . "',"; $update .= "`Delete_Access_ID` = '" . $Delete_Access_ID . "',"; $update .= "`Subscribe_Access_ID` = '" . $SubscribeAccessID . "',"; if (nc_module_check_by_keyword("cache")) { $update .= "`Cache_Access_ID` = '" . $Cache_Access_ID . "',"; $update .= "`Cache_Lifetime` = '" . $Cache_Lifetime . "',"; $update .= "`CacheForUser` = '" . $CacheForUser . "',"; } if (nc_module_check_by_keyword("comments")) { $update .= "`Comment_Rule_ID` = '" . $CommentRelationID . "',"; } $update .= "`Moderation_ID` = '" . $Moderation_ID . "',"; $update .= "`Checked` = '" . $Checked . "',"; //$update.= "`Priority` = '" . $Priority . "',"; $update .= "`EnglishName` = '" . $EnglishName . "',"; $update .= "`DefaultAction` = '" . $DefaultAction . "',"; $update .= $DaysToHold == "" ? "`DaysToHold` = NULL," : "`DaysToHold` = '" . $DaysToHold . "',"; $update .= "`AllowTags` = '" . $AllowTags . "',"; $update .= "`NL2BR` = '" . $NL2BR . "',"; $update .= $RecordsPerPage == "" ? "`RecordsPerPage` = NULL," : "`RecordsPerPage` = '" . $RecordsPerPage . "',"; $update .= "`SortBy` = '" . $SortBy . "',"; $update .= "`UseCaptcha` = '" . $UseCaptcha . "', "; $update .= "`CustomSettings` = '" . $db->escape(addcslashes($CustomSettings, "'")) . "', "; $update .= "`Class_Template_ID` = '" . $Class_Template_ID . "', "; $update .= "`Edit_Class_Template` = '" . $Edit_Class_Template . "', "; $update .= "`isNaked` = '" . $isNakedCC . "', "; $update .= "`SrcMirror` = '" . $SrcMirror . "', "; $update .= "`AllowRSS` = '" . intval($nc_core->input->fetch_get_post('AllowRSS' . $SubClassID)) . "',"; $update .= "`AllowXML` = '" . intval($nc_core->input->fetch_get_post('AllowXML' . $SubClassID)) . "'"; $update .= " WHERE `Sub_Class_ID` = '" . $SubClassID . "'"; $subclass_data = $nc_core->sub_class->get_by_id($SubClassID); $nc_core->event->execute("updateSubClassPrep", $subclass_data['Catalogue_ID'], $subclass_data['Subdivision_ID'], $SubClassID); if ($cur_checked != $Checked) { $nc_core->event->execute($Checked ? "checkSubClassPrep" : "uncheckSubClassPrep", $subclass_data['Catalogue_ID'], $subclass_data['Subdivision_ID'], $SubClassID); } $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("updateSubClass", $subclass_data['Catalogue_ID'], $subclass_data['Subdivision_ID'], $SubClassID); // произошло включение / выключение if ($cur_checked != $Checked) { $nc_core->event->execute($Checked ? "checkSubClass" : "uncheckSubClass", $subclass_data['Catalogue_ID'], $subclass_data['Subdivision_ID'], $SubClassID); } return $db->rows_affected; } }
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; }