Пример #1
0
             $posting = 0;
             nc_print_status(CONTROL_CONTENT_SUBDIVISION_INDEX_ERROR_THREE_KEYWORD, 'error');
             SubdivisionForm(6, "index.php", 2, $full);
             break;
         }
         // проверка символов для ключевого слова
         if (!$nc_core->subdivision->validate_english_name($EnglishName)) {
             $posting = 0;
             nc_print_status(CONTROL_CONTENT_SUBDIVISION_SUBCLASS_ERROR_KEYWORD_INVALID, 'error');
             SubdivisionForm(6, "index.php", 2, $full);
             break;
         }
         // если раздел изменен переходим к информации по разделу или к дереву разделов
         if (ActionSubdivisionCompleted($type)) {
             nc_print_status(CONTROL_CONTENT_SUBDIVISION_SUCCESS_EDIT, 'ok');
             SubdivisionForm(6, "index.php", 2, $full);
             break;
         } else {
             if ($db->last_error) {
                 nc_print_status(sprintf(NETCAT_ERROR_SQL, $db->last_query, $db->last_error), 'error');
             }
         }
     }
     break;
     // спросить, действительно ли надо удалить рубрику
 // спросить, действительно ли надо удалить рубрику
 case 7:
     foreach ($nc_core->input->fetch_get_post() as $key => $val) {
         if (substr($key, 0, 6) == "Delete") {
             $sub_id = substr($key, 6, strlen($key) - 6) + 0;
             $sub_ids[] = substr($key, 6, strlen($key) - 6) + 0;
Пример #2
0
function ActionSubdivisionCompleted($type)
{
    global $HTTP_ROOT_PATH, $HTTP_DOMAIN, $SUB_FOLDER;
    global $loc, $perm, $admin_mode, $nc_core;
    global $db, $ROOT_FOLDER, $FILECHMOD, $DIRCHMOD;
    global $systemTableID, $systemTableName, $systemMessageID;
    global $FILES_FOLDER, $INCLUDE_FOLDER, $MODULE_FOLDER, $ADMIN_FOLDER;
    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');
    $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('Subdivision_Name', 'EnglishName', 'TemplateID', 'ReadAccessID', 'WriteAccessID', 'EditAccessID', 'SubscribeAccessID', 'CheckedAccessID', 'DeleteAccessID', 'ModerationID', 'Checked', 'Priority', 'ExternalURL', 'UseMultiSubClass', 'CacheAccessID', 'CacheLifetime', 'CatalogueID', 'SubdivisionID', 'ParentSubID', 'UseEditDesignTemplate', 'Title', 'Keywords', 'Description', 'CommentsEditRules', 'CommentAccessID', 'CommentsDeleteRules', 'posting', 'last_modified_type', 'language', 'title', 'keywords', 'description', 'DisallowIndexing', $sm_field, $sm_change_field, $sm_priority_field);
    foreach ($params as $v) {
        ${$v} = $nc_core->input->fetch_get_post($v);
    }
    $st = new nc_Component(0, 2);
    foreach ($st->get_fields() as $v) {
        $name = 'f_' . $v['name'];
        global ${$name};
        if ($v['type'] == 6) {
            global ${$name . "_old"};
            global ${"f_KILL" . $v['id']};
        }
    }
    $Priority += 0;
    if ($type == 1) {
        $action = "add";
    }
    if ($type == 2) {
        $action = "change";
        $message = $loc->SubdivisionID;
    }
    $component = new nc_Component(0, 2);
    $fl = $component->get_fields();
    // prepare template custom settings
    $settings = $db->get_var("SELECT `CustomSettings` FROM `Template` WHERE `Template_ID` = '" . (int) $TemplateID . "'");
    if ($settings) {
        require_once $ADMIN_FOLDER . "array_to_form.inc.php";
        $a2f = new nc_a2f($settings, 'TemplateSettings');
        if (!$a2f->validate($_POST['TemplateSettings'])) {
            $warnText = $a2f->get_validation_errors();
            $posting = 0;
        }
        $a2f->save($_POST['TemplateSettings']);
        $TemplateSettings = $a2f->get_values_as_string();
    } else {
        $TemplateSettings = "";
    }
    require $ROOT_FOLDER . "message_fields.php";
    if ($posting == 0) {
        nc_print_status($warnText, 'error');
        SubdivisionForm($phase, "index.php", $type);
        return false;
    }
    if (nc_module_check_by_keyword("comments")) {
        include_once $MODULE_FOLDER . "comments/function.inc.php";
    }
    require $ROOT_FOLDER . "message_put.php";
    $db->last_error = '';
    if ($type == 1) {
        $insert = "INSERT INTO `Subdivision` SET ";
        // fields from system table component (2)
        for ($i = 0; $i < $fldCount; $i++) {
            if ($fldTypeOfEdit[$i] == 3 || $fldTypeOfEdit[$i] == 2 && !nc_field_check_admin_perm()) {
                continue;
            }
            // поле недоступно никому или доступно администратору но нет прав администратора
            // quotes added into the message_put.php!
            if (isset(${$fld[$i] . 'Defined'}) && ${$fld[$i] . 'Defined'} == true) {
                $insert .= "`" . $fld[$i] . "` = " . ${$fld[$i] . 'NewValue'} . ", ";
            } else {
                $insert .= "`" . $fld[$i] . "` = " . $fldValue[$i] . ", ";
            }
        }
        if (nc_module_check_by_keyword("cache")) {
            $insert .= "`Cache_Access_ID` = '" . $CacheAccessID . "', ";
            $insert .= "`Cache_Lifetime` = '" . $CacheLifetime . "',";
        }
        $insert .= "`Catalogue_ID`  = '" . $loc->CatalogueID . "',";
        $insert .= "`Parent_Sub_ID` = '" . $loc->ParentSubID . "',";
        $insert .= "`Subdivision_Name` = '" . $Subdivision_Name . "',";
        $insert .= "`Template_ID` = '" . $TemplateID . "',";
        $insert .= "`Read_Access_ID` = '" . $ReadAccessID . "',";
        $insert .= "`Write_Access_ID` = '" . $WriteAccessID . "',";
        $insert .= "`Edit_Access_ID` = '" . $EditAccessID . "',";
        $insert .= "`Checked_Access_ID` = '" . $CheckedAccessID . "',";
        $insert .= "`Delete_Access_ID` = '" . $DeleteAccessID . "',";
        $insert .= "`Subscribe_Access_ID` = '" . $SubscribeAccessID . "',";
        $insert .= "`Moderation_ID` = '" . $ModerationID . "',";
        $insert .= "`Checked` = '" . $Checked . "',";
        $insert .= "`ExternalURL` = '" . $ExternalURL . "',";
        $insert .= "`EnglishName` = '" . $EnglishName . "',";
        $insert .= "`Favorite` = '" . $Favorite . "',";
        $insert .= "`Created` = '" . date("Y-m-d H:i:s") . "',";
        $insert .= "`Priority` = '" . $Priority . "',";
        $insert .= "`UseMultiSubClass` = '" . $UseMultiSubClass . "',";
        $insert .= "`UseEditDesignTemplate` = '" . $UseEditDesignTemplate . "',";
        $insert .= "`" . $lm_type . "` = '" . intval($last_modified_type) . "',";
        $insert .= "`TemplateSettings` = '" . $db->escape($TemplateSettings) . "'";
        // execute core action
        $nc_core->event->execute("addSubdivisionPrep", $loc->CatalogueID, 0);
        $Result = $db->query($insert);
        $systemMessageID = $db->insert_id;
        //sql error
        if ($db->last_error) {
            return false;
        }
        // execute core action
        $nc_core->event->execute("addSubdivision", $loc->CatalogueID, $systemMessageID);
        $message = $systemMessageID;
        // set insert_id in Filetable, becouse Message_ID and File_Path fields are empty
        if (!empty($filetable_lastid)) {
            $db->query("UPDATE `Filetable`\n          SET `Message_ID` = '" . $message . "', `File_Path` = '/" . $message . "/'\n          WHERE `ID`  IN(" . join(',', $filetable_lastid) . ")");
        }
        // default value
        if (!isset($DIRCHMOD)) {
            $DIRCHMOD = 0777;
        }
        // create dir
        @mkdir($FILES_FOLDER . $message . "/", $DIRCHMOD);
        // end set insert_id block
        if (nc_module_check_by_keyword("comments")) {
            if ($CommentAccessID > 0) {
                // add comment relation
                $CommentRelationID = nc_comments::addRule($db, array($loc->CatalogueID, $message), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
                // update inserted data
                $db->query("UPDATE `Subdivision` SET `Comment_Rule_ID` = '" . (int) $CommentRelationID . "' WHERE `Subdivision_ID` = '" . (int) $message . "'");
            }
        }
    }
    if ($type == 2) {
        $cur_checked = $db->get_var("SELECT `Checked` FROM `Subdivision` WHERE `Subdivision_ID` = '" . $loc->SubdivisionID . "'");
        if (nc_module_check_by_keyword("comments")) {
            // get rule id
            $CommentData = nc_comments::getRuleData($db, array($loc->CatalogueID, $loc->SubdivisionID));
            $CommentRelationID = $CommentData['ID'];
            // do something
            switch (true) {
                case $CommentAccessID > 0 && $CommentRelationID:
                    // update comment rules
                    nc_comments::updateRule($db, array($loc->CatalogueID, $loc->SubdivisionID), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
                    break;
                case $CommentAccessID > 0 && !$CommentRelationID:
                    // add comment relation
                    $CommentRelationID = nc_comments::addRule($db, array($loc->CatalogueID, $loc->SubdivisionID), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
                    break;
                case $CommentAccessID <= 0 && $CommentRelationID:
                    // delete comment rules
                    nc_comments::dropRuleSubdivision($db, $loc->SubdivisionID);
                    $CommentRelationID = 0;
                    break;
            }
        }
        $update = "UPDATE `Subdivision` SET ";
        for ($i = 0; $i < $fldCount; $i++) {
            if ($fldTypeOfEdit[$i] == 3) {
                continue;
            }
            // поле недоступно никому
            $update .= "`" . $fld[$i] . "` = " . $fldValue[$i] . ", ";
        }
        if (!empty($fl)) {
            foreach ($fl as $field) {
                if ($field['usage']) {
                    $update .= "`" . $db->escape($field['name']) . "` = '" . $db->escape($nc_core->input->fetch_get_post($field['name'])) . "', ";
                }
            }
        }
        $update .= "`Subdivision_Name`= '" . $Subdivision_Name . "',";
        $update .= "`ExternalURL`= '" . $ExternalURL . "',";
        $update .= "`EnglishName` = '" . $EnglishName . "',";
        $update .= "`Template_ID` = " . $TemplateID . ",";
        $update .= "`Read_Access_ID` = '" . $ReadAccessID . "',";
        $update .= "`Write_Access_ID` = '" . $WriteAccessID . "',";
        $update .= "`Edit_Access_ID` = '" . $EditAccessID . "',";
        $update .= "`Checked_Access_ID` = '" . $CheckedAccessID . "',";
        $update .= "`Delete_Access_ID` = '" . $DeleteAccessID . "',";
        $update .= "`Subscribe_Access_ID` = '" . $SubscribeAccessID . "',";
        if (nc_module_check_by_keyword("cache")) {
            $update .= "`Cache_Access_ID` = '" . $CacheAccessID . "',";
            $update .= "`Cache_Lifetime` = '" . $CacheLifetime . "',";
        }
        if (nc_module_check_by_keyword("comments")) {
            $update .= "`Comment_Rule_ID` = '" . $CommentRelationID . "',";
        }
        $update .= "`Moderation_ID` = '" . $ModerationID . "',";
        $update .= "`Checked` = '" . $Checked . "',";
        $update .= "`Priority`= " . $Priority . ",";
        $update .= "`Favorite`= '" . $Favorite . "',";
        $update .= "`UseMultiSubClass`= '" . $UseMultiSubClass . "',";
        $update .= "`UseEditDesignTemplate`= '" . $UseEditDesignTemplate . "',";
        $update .= "`DisallowIndexing`= '" . intval($DisallowIndexing) . "',";
        $update .= "`" . $sm_field . "`= '" . $nc_core->input->fetch_get_post('sitemap_include') . "',";
        $update .= "`" . $nc_core->page->get_field_name('language') . "` = '" . $db->escape($language) . "',";
        $update .= "`" . $nc_core->page->get_field_name('title') . "` = '" . $db->escape($title) . "',";
        $update .= "`" . $nc_core->page->get_field_name('keywords') . "` = '" . $db->escape($keywords) . "',";
        $update .= "`" . $nc_core->page->get_field_name('description') . "` = '" . $db->escape($description) . "',";
        $update .= "`" . $lm_type . "` = '" . intval($last_modified_type) . "',";
        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 .= " WHERE `Subdivision_ID` = " . $loc->SubdivisionID;
        // execute core action
        $nc_core->event->execute("updateSubdivisionPrep", $loc->CatalogueID, $loc->SubdivisionID);
        $nc_core->event->execute($Checked ? "checkSubdivisionPrep" : "uncheckSubdivisionPrep", $loc->CatalogueID, $loc->SubdivisionID);
        $Result = $db->query($update);
        //sql error
        if ($db->last_error) {
            return false;
        }
        // execute core action
        $nc_core->event->execute("updateSubdivision", $loc->CatalogueID, $loc->SubdivisionID);
        // произошло включение / выключение
        if ($cur_checked != $Checked) {
            $nc_core->event->execute($Checked ? "checkSubdivision" : "uncheckSubdivision", $loc->CatalogueID, $loc->SubdivisionID);
        }
        $changed_cc = array();
        // RSS
        $cc_in_sub = $db->get_results("SELECT `Sub_Class_ID` as `id`, `AllowRSS` as `cur` FROM `Sub_Class` WHERE `Subdivision_ID` = '" . $loc->SubdivisionID . "' ", ARRAY_A);
        if (!empty($cc_in_sub)) {
            foreach ($cc_in_sub as $v) {
                // значение, пришедшие из формы
                $allow_rss = intval($nc_core->input->fetch_get_post('AllowRSS' . $v['id']));
                // в случае, если значение изменилось
                if ($allow_rss != $v['cur']) {
                    $db->query("UPDATE `Sub_Class` SET `AllowRSS` = '" . $allow_rss . "' WHERE `Sub_Class_ID` = '" . $v['id'] . "' ");
                    $changed_cc[] = $v['id'];
                }
            }
        }
        // визуальные настройки
        $CustomSettings = "";
        if ($nc_core->input->fetch_get_post('custom_subclass_id')) {
            $settings = $db->get_var("SELECT `CustomSettingsTemplate` FROM `Class`\n                                WHERE `Class_ID` = '" . intval($nc_core->input->fetch_get_post('custom_class_id')) . "'");
            if ($settings) {
                require_once $nc_core->ADMIN_FOLDER . "array_to_form.inc.php";
                $a2f = new nc_a2f($settings, 'CustomSettings');
                if (!$a2f->validate($_POST['CustomSettings'])) {
                    $error = $a2f->get_validation_errors();
                    nc_print_status($error, 'error');
                } else {
                    $a2f->save($_POST['CustomSettings']);
                    $CustomSettings = $a2f->get_values_as_string();
                    $cur_settings = $db->get_var("SELECT `CustomSettings` FROM `Sub_Class`\n                                    WHERE `Sub_Class_ID` = '" . intval($nc_core->input->fetch_get_post('custom_subclass_id')) . "'");
                    if ($CustomSettings != $cur_settings) {
                        $nc_core->event->execute("updateSubClassPrep", $loc->CatalogueID, $loc->SubdivisionID, $changed_cc);
                        $db->query("UPDATE `Sub_Class` SET `CustomSettings` = '" . $db->escape($CustomSettings) . "'\n                    WHERE `Sub_Class_ID` = '" . intval($nc_core->input->fetch_get_post('custom_subclass_id')) . "'");
                        $changed_cc[] = intval($nc_core->input->fetch_get_post('custom_subclass_id'));
                    }
                }
            }
        }
        // трансляция события для компонент в разделе
        if (!empty($changed_cc)) {
            $changed_cc = array_unique($changed_cc);
            $nc_core->event->execute("updateSubClass", $loc->CatalogueID, $loc->SubdivisionID, $changed_cc);
        }
    }
    if ($type == 1 || $type == 2) {
        $hidden_url = GetHiddenURL($loc->ParentSubID);
        UpdateHiddenURL($hidden_url ? $hidden_url : "/", $loc->ParentSubID, $loc->CatalogueID);
    }
    // поисковая оптимизация, проверка
    if (!empty($fl)) {
        $real_value = $nc_core->page->get_meta_tags("http://" . $nc_core->DOMAIN_NAME . nc_folder_path($message));
        foreach ($fl as $field) {
            if ($real_value[$field['usage']] && $field['usage'] && $nc_core->input->fetch_get_post($field['name']) && $nc_core->input->fetch_get_post($field['name']) != $real_value[$field['usage']]) {
                nc_print_status(sprintf(CONTROL_CONTENT_SUBDIVISION_SEO_VALUE_NOT_SETTINGS, $field['usage']), 'info');
            }
        }
    }
    // work with files
    for ($i = 0; $i < count($tmpFile); $i++) {
        eval("\$tmpNewFile[\$i] = \"" . $tmpNewFile[$i] . "\";");
        eval("\$File_PathNew[\$i] = \"" . $File_PathNew[$i] . "\";");
        eval("\$File_Path[\$i] = \"" . $File_Path[$i] . "\";");
        if ($fld_name[$i]) {
            $db->query("UPDATE `Subdivision`\n       SET `" . $fld_name[$i] . "` = REPLACE(" . $fld_name[$i] . ", '\$message', Subdivision_ID )\n       WHERE Subdivision_ID = '" . $message . "'");
        }
        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($nc_core->FILES_FOLDER . $File_PathNew[$i] . $tmpNewFile[$i], $nc_core->FILECHMOD);
    }
    if (!empty($filetable_lastid)) {
        $db->query("UPDATE `Filetable`\n          SET `Message_ID` = '" . $message . "', `File_Path` = '/" . $message . "/'\n          WHERE `ID`  IN(" . join(',', $filetable_lastid) . ")");
    }
    return $type == 1 && $message ? $message : ($type == 2 && $loc->SubdivisionID ? $loc->SubdivisionID : false);
}