Example #1
0
/**
 * Delete all objects from SubClass
 *
 * @param int SubClassID
 */
function SubClassClear($SubClassID)
{
    global $nc_core, $db, $MODULE_FOLDER;
    // full info about this subclass
    $SubClassID = intval($SubClassID);
    $res = $db->get_row("SELECT `Catalogue_ID`, `Subdivision_ID`, `Class_ID` FROM `Sub_Class` WHERE `Sub_Class_ID` = '" . $SubClassID . "'", ARRAY_A);
    if (nc_module_check_by_keyword("comments")) {
        include_once $MODULE_FOLDER . "comments/function.inc.php";
        // delete comment rules
        nc_comments::dropRuleSubClass($db, $SubClassID);
        // delete comments
        nc_comments::dropComments($db, $SubClassID, "Sub_Class");
    }
    DeleteSubClassFiles($SubClassID, $res['Class_ID']);
    // delete from message
    $messages_id = $db->get_col("SELECT `Message_ID` FROM `Message" . $res['Class_ID'] . "` WHERE `Subdivision_ID` = '" . $res['Subdivision_ID'] . "' AND `Sub_Class_ID` = '" . $SubClassID . "'");
    if (!empty($messages_id)) {
        if ($db->query("SELECT * FROM `Message" . $res['Class_ID'] . "` WHERE `Message_ID` IN (" . join(", ", $messages_id) . ")")) {
            $messages_data = array_combine($db->get_col(NULL, 0), $db->get_results(NULL));
        }
        // execute core action
        $nc_core->event->execute("dropMessagePrep", $res['Catalogue_ID'], $res['Subdivision_ID'], $SubClassID, $res['Class_ID'], $messages_id, $messages_data);
        $db->query("DELETE FROM `Message" . $res['Class_ID'] . "` WHERE `Message_ID` IN (" . join(", ", $messages_id) . ")");
        // execute core action
        $nc_core->event->execute("dropMessage", $res['Catalogue_ID'], $res['Subdivision_ID'], $SubClassID, $res['Class_ID'], $messages_id, $messages_data);
    }
    return;
}
Example #2
0
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;
    }
}
Example #3
0
 /**
  * Функция для удаления объектов компонентов
  * @param mixed `identificators` - идентификаторы объектов подлежащих удалению в виде массива, или цифры
  * @param int `class_id` номер компонента, в котором производится удаление
  * @param bool `trash` параметр, определяющий, перед будет ли объект помещен в корзину перед удалением. 1 - объект будет помещен в корзину, затем удален, 0 - объект будет удален.
  * @return int `affected` - затронутые объекты or false
  */
 public function delete_by_id($identificators, $class_id, $trash = false)
 {
     $nc_core = nc_Core::get_object();
     $MODULE_FOLDER = $nc_core->MODULE_FOLDER;
     // validate parameters
     $affected = 0;
     $classID = intval($class_id);
     // Приводим первый параметр к массиву
     if (!is_array($identificators)) {
         $messages_to_delete = array(intval($identificators));
     } else {
         $messages_to_delete = array_map("intval", $identificators);
     }
     if (empty($messages_to_delete)) {
         return 0;
     }
     // Выясняем данные по всем объектам для удаления - номера разделов,
     // компонентов в разделе и номера сайтов, а тажке формируем массив номеров удаляемых объектов
     $temp_array = $this->db->get_results("SELECT m.* , m.`Message_ID` AS `m_id`, m.`Subdivision_ID` as `sub_id`, m.`Sub_Class_ID` as `cc_id`, s.`Catalogue_ID` as `cat_id`\n    FROM `Message" . $classID . "` as m, `Subdivision` as s\n    WHERE m.`Subdivision_ID` = s.`Subdivision_ID` AND  m.`Message_ID` IN (" . join(',', $messages_to_delete) . ")", ARRAY_A);
     $message_to_delete = array();
     $message_to_delete_ids = array();
     $message_to_delete_data = array();
     if (!empty($temp_array)) {
         foreach ($temp_array as $v) {
             // группируем объекты по сайты/разделу/сс
             $message_to_delete[$v['cat_id']][$v['sub_id']][$v['cc_id']][] = intval($v['m_id']);
             $message_to_delete_data[$v['cat_id']][$v['sub_id']][$v['cc_id']][intval($v['m_id'])] = $v;
             $message_to_delete_ids[] = $v['m_id'];
         }
     } else {
         return 0;
     }
     $nc_core->event->execute("dropMessagePrep", $messages_to_delete);
     try {
         if ($trash) {
             $trashing_result_arr = $nc_core->trash->add($messages_to_delete, $classID);
         }
     } catch (nc_Exception_Trash_Full $e) {
         $trash = 0;
     } catch (nc_Exception_Trash_Folder_Fail $e) {
         $trash = 0;
     }
     // Удаляем комментарии
     if (nc_module_check_by_keyword("comments")) {
         include_once $MODULE_FOLDER . "comments/function.inc.php";
         // get need ids
         $comments_temp = $this->db->get_results("SELECT `Message_ID`, `Sub_Class_ID` FROM `Message" . $classID . "`\n      WHERE `Message_ID` IN (" . join(',', $message_to_delete_ids) . ") OR `Parent_Message_ID` IN (" . join(',', $message_to_delete_ids) . ")", ARRAY_A);
         // compile arrays
         $temp_messages = array();
         $temp_ccs = array();
         foreach ((array) $comments_temp as $comments_temp_value) {
             if (!in_array($comments_temp_value['Message_ID'], $temp_messages)) {
                 $temp_messages[] = $comments_temp_value['Message_ID'];
             }
             if (!in_array($comments_temp_value['Sub_Class_ID'], $temp_ccs)) {
                 $temp_ccs[] = $comments_temp_value['Sub_Class_ID'];
             }
         }
         // delete comments
         nc_comments::dropComments($this->db, $temp_ccs, "Sub_Class", $temp_messages);
         // delete comment rules
         nc_comments::dropRuleMessage($this->db, $temp_messages, $temp_ccs);
         // clear
         unset($comments_temp, $temp_ccs, $temp_messages);
     }
     // delete related files
     // поочередно удаляем файлы у всех перечисленных к удалению объектов
     // если они не отправляются в корзину, иначе файлам ставим метку deleted
     if (!$trash) {
         require_once $this->core->INCLUDE_FOLDER . "s_files.inc.php";
         foreach ($message_to_delete_ids as $id) {
             DeleteMessageFiles($classID, $id);
         }
     } else {
         $nc_core->trash->TrashMessageFiles($classID, $message_to_delete_ids);
     }
     // Удаляем сами объекты
     $this->db->query("DELETE FROM `Message" . $classID . "` WHERE `Message_ID` IN (" . join(',', $message_to_delete_ids) . ")");
     if ($this->db->is_error) {
         throw new nc_Exception_DB_Error($this->db->last_query, $this->db->last_error);
     } else {
         $affected = $this->db->rows_affected;
     }
     // execute core action
     if ($message_to_delete) {
         foreach ($message_to_delete as $site_id => $site) {
             foreach ($site as $sub_id => $sub) {
                 foreach ($sub as $cc_id => $messages_in_cc) {
                     $nc_core->event->execute("dropMessage", $site_id, $sub_id, $cc_id, $classID, $messages_in_cc, $message_to_delete_data[$site_id][$sub_id][$cc_id]);
                 }
             }
         }
     }
     $children_ids = $this->db->get_col("SELECT `Message_ID` FROM `Message" . $classID . "` WHERE `Parent_Message_ID` IN  (" . join(',', $message_to_delete_ids) . ")");
     if (!empty($children_ids)) {
         // delete related files
         if ($this->db->is_error) {
             throw new nc_Exception_DB_Error($this->db->last_query, $this->db->last_error);
         }
         $affected += $this->db->rows_affected;
         // execute core action
         $affected += $this->delete_by_id($children_ids, $classID, $trash);
     }
     return $affected;
 }
Example #4
0
File: add.php Project: Blu2z/implsk
     $CommentData = nc_comments::getRuleData($db, array($catalogue, $sub, $cc, $message));
     $CommentRelationID = $CommentData['ID'];
     $comm_env = array($catalogue, $sub, $cc, $message);
     // do something
     switch (true) {
         case $CommentAccessID > 0 && $CommentRelationID:
             // update comment rules
             nc_comments::updateRule($db, $comm_env, $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
             break;
         case $CommentAccessID > 0 && !$CommentRelationID:
             // add comment relation
             $CommentRelationID = nc_comments::addRule($db, $comm_env, $CommentAccessID, $CommentsEditRules, $CommentsDeleteRules);
             break;
         case $CommentAccessID <= 0 && $CommentRelationID:
             // delete comment rules
             nc_comments::dropRule($db, $comm_env);
             $CommentRelationID = 0;
             break;
     }
 }
 if ($resMsg) {
     if ($cc && !$user_table_mode && $IsChecked && $MODULE_VARS['subscriber'] && (!$MODULE_VARS['subscriber']['VERSION'] || $MODULE_VARS['subscriber']['VERSION'] == 1)) {
         eval("\$mailbody = \"" . $subscribeTemplate . "\";");
         subscribe_sendmail($to_cc ? $to_cc : $cc, $mailbody);
     }
     if ($cc_env['File_Mode']) {
         $nc_parent_field_path = $file_class->get_parent_fiend_path('AddActionTemplate');
         $nc_field_path = $file_class->get_field_path('AddActionTemplate');
         $action_exists = filesize($nc_field_path) > 0 ? true : false;
     }
     if ($cc_env['File_Mode'] && $action_exists) {
Example #5
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;
}
Example #6
0
function CascadeDeleteSubdivision($SubdivisionID)
{
    global $nc_core, $db, $MODULE_FOLDER;
    $CatalogueID = $db->get_var("SELECT `Catalogue_ID` FROM `Subdivision` WHERE `Subdivision_ID` = '" . (int) $SubdivisionID . "'");
    // execute core action
    $nc_core->event->execute("dropSubdivisionPrep", $CatalogueID, $SubdivisionID);
    if (0 && nc_module_check_by_keyword("comments")) {
        include_once $MODULE_FOLDER . "comments/function.inc.php";
        // delete comment rules
        nc_comments::dropRule($db, array($CatalogueID, $SubdivisionID));
        // delete comments
        nc_comments::dropComments($db, $SubdivisionID, "Subdivision");
    }
    DeleteMessages($SubdivisionID);
    DeleteFromSubClass($SubdivisionID);
    DeleteSubdivisionDir($SubdivisionID);
    $db->query("DELETE FROM `Subdivision` WHERE `Subdivision_ID` = '" . (int) $SubdivisionID . "'");
    // execute core action
    $nc_core->event->execute("dropSubdivision", $CatalogueID, $SubdivisionID);
    return;
}
Example #7
0
function CascadeDeleteCatalogue($catalogueId)
{
    global $nc_core, $db, $MODULE_FOLDER;
    $catalogueId = (int) $catalogueId;
    $subClasses = (array) $db->get_results("SELECT `Subdivision_ID`, `Sub_Class_ID`, `Class_ID` FROM `Sub_Class` WHERE `Catalogue_ID` = {$catalogueId}", ARRAY_A);
    // execute core action
    $nc_core->event->execute("dropCataloguePrep", $catalogueId);
    $subdivisionsToDelete = array();
    //delete messages
    foreach ($subClasses as $subClass) {
        $subdivisionId = (int) $subClass['Subdivision_ID'];
        $subClassId = (int) $subClass['Sub_Class_ID'];
        $classId = (int) $subClass['Class_ID'];
        $subdivisionsToDelete[] = $subdivisionId;
        $subClassesToDelete[] = $subClassId;
        $messages = (array) $db->get_results("SELECT `Message_ID` FROM `Message{$classId}` WHERE `Sub_Class_ID` = {$subClassId}", ARRAY_A);
        $messagesToDelete = array();
        foreach ($messages as $message) {
            $messagesToDelete[] = (int) $message['Message_ID'];
        }
        if (count($messagesToDelete) > 0) {
            // execute core action
            $nc_core->event->execute("dropMessagePrep", $catalogueId, $subdivisionId, $subClassId, $classId, $messagesToDelete);
            // delete messages
            foreach ($messagesToDelete as $messageId) {
                DeleteMessageFiles($classId, $messageId);
                $db->query("DELETE FROM `Message{$classId}` WHERE `Message_ID` = {$messageId}");
            }
            // execute core action
            $nc_core->event->execute("dropMessage", $catalogueId, $subdivisionId, $subClassId, $classId, $messagesToDelete);
        }
        //delete subclass
        // execute core action
        $nc_core->event->execute("dropSubClassPrep", $catalogueId, $subdivisionId, $subClassId);
        $db->query("DELETE FROM `Sub_Class` WHERE `Sub_Class_ID` = {$subClassId}");
        DeleteSubClassDirAlways($subdivisionId, $subClassId);
        // execute core action
        $nc_core->event->execute("dropSubClass", $catalogueId, $subdivisionId, $subClassId);
    }
    if (count($subdivisionsToDelete) > 0) {
        // execute core action
        $nc_core->event->execute("dropSubdivisionPrep", $catalogueId, $subdivisionsToDelete);
        foreach ($subdivisionsToDelete as $subdivisionId) {
            $db->query("DELETE FROM `Subdivision` WHERE `Subdivision_ID` = {$subdivisionId}");
            DeleteSubdivisionDir($subdivisionId);
        }
        // execute core action
        $nc_core->event->execute("dropSubdivision", $catalogueId, $subdivisionsToDelete);
    }
    if (nc_module_check_by_keyword("comments")) {
        include_once $MODULE_FOLDER . "comments/function.inc.php";
        // delete comment rules
        nc_comments::dropRule($db, array($catalogueId));
        // delete comments
        nc_comments::dropComments($db, $catalogueId, "Catalogue");
    }
    // delete catalogue
    $db->query("DELETE FROM `Catalogue` WHERE `Catalogue_ID` = {$catalogueId}");
    // execute core action
    $nc_core->event->execute("dropCatalogue", $catalogueId);
    return;
}
Example #8
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;
}