Beispiel #1
0
function nc_subdivision_form_system_save()
{
    $nc_core = nc_Core::get_object();
    $sub_id = intval($nc_core->input->fetch_get_post('SubdivisionID'));
    $cat_id = $nc_core->subdivision->get_by_id($sub_id, 'Catalogue_ID');
    $params = array('ExternalURL', 'Read_Access_ID', 'Write_Access_ID', 'Edit_Access_ID', 'Checked_Access_ID', 'Delete_Access_ID', 'Moderation_ID');
    if ($nc_core->modules->get_by_keyword('cache')) {
        $params[] = 'Cache_Access_ID';
        $params[] = 'Cache_Lifetime';
    }
    foreach ($params as $v) {
        $fields[$v] = $nc_core->input->fetch_get_post($v);
    }
    // язык
    $fields[$nc_core->page->get_field_name('language')] = $nc_core->input->fetch_get_post('language');
    // комментарии
    if ($nc_core->modules->get_by_keyword("comments")) {
        include_once $nc_core->MODULE_FOLDER . "comments/function.inc.php";
        $CommentAccessID = $nc_core->input->fetch_get_post('CommentAccessID');
        $CommentsEditRules = $nc_core->input->fetch_get_post('CommentsEditRules');
        $CommentsDeleteRules = $nc_core->input->fetch_get_post('CommentsDeleteRules');
        // get rule id
        $CommentData = nc_comments::getRuleData($nc_core->db, array($cat_id, $sub_id));
        $CommentRelationID = $CommentData['ID'];
        // do something
        switch (true) {
            case $CommentAccessID > 0 && $CommentRelationID:
                // update comment rules
                nc_comments::updateRule($nc_core->db, array($cat_id, $sub_id), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
                break;
            case $CommentAccessID > 0 && !$CommentRelationID:
                // add comment relation
                $CommentRelationID = nc_comments::addRule($nc_core->db, array($cat_id, $sub_id), $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
                break;
            case $CommentAccessID <= 0 && $CommentRelationID:
                // delete comment rules
                nc_comments::dropRuleSubdivision($nc_core->db, $sub_id);
                $CommentRelationID = 0;
                break;
        }
        $fields['Comment_Rule_ID'] = $CommentRelationID;
    }
    // RSS
    $cc_in_sub = $nc_core->db->get_results("SELECT `Sub_Class_ID` as `id`, `AllowRSS` as `cur` FROM `Sub_Class` WHERE `Subdivision_ID` = '" . $sub_id . "' ", 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']) {
                $nc_core->event->execute("updateSubClassPrep", $cat_id, $sub_id, $v['id']);
                $nc_core->db->query("UPDATE `Sub_Class` SET `AllowRSS` = '" . $allow_rss . "' WHERE `Sub_Class_ID` = '" . $v['id'] . "' ");
                $nc_core->event->execute("updateSubClass", $cat_id, $sub_id, $v['id']);
            }
        }
    }
    $nc_core->subdivision->update($sub_id, $fields);
    return true;
}