Пример #1
0
     }
     break;
 case 18:
     // спросить, действительно ли удалять шаблон компонента
     BeginHtml($Title6, $Title3 . $Delimeter . $Title6, "http://" . $DOC_DOMAIN . "/management/class/");
     $perm->ExitIfNotAccess(NC_PERM_CLASS, 0, 0, 0, 0);
     ConfirmClassTemplateDeletion($ClassTemplate);
     break;
 case 19:
     // удаление шаблонов компонента
     BeginHtml($Title2, $Title2, "http://" . $DOC_DOMAIN . "/management/class/");
     $perm->ExitIfNotAccess(NC_PERM_CLASS, 0, 0, 0, 1);
     $UI_CONFIG = new ui_config_class_templates('edit', $ClassTemplate);
     foreach ($_POST as $key => $val) {
         if (nc_substr($key, 0, 6) == "Delete" && $val) {
             $isMoreClasses = CascadeDeleteClassTemplate($val);
         }
     }
     ClassTemplatesList($ClassTemplate);
     break;
 case 20:
     // список шаблонов компонента
     BeginHtml($Title2, $Title2, "http://" . $DOC_DOMAIN . "/management/class/");
     $perm->ExitIfNotAccess(NC_PERM_CLASS, 0, 0, 0, 0);
     if ($ClassID) {
         $UI_CONFIG = new ui_config_class_templates('edit', $ClassID);
     }
     ClassTemplatesList($ClassID);
     break;
 case 22:
     // алтернативные блоки шаблона компонента
Пример #2
0
function CascadeDeleteClass($ClassID)
{
    global $nc_core, $db;
    global $UI_CONFIG, $INCLUDE_FOLDER;
    $ClassID = intval($ClassID);
    $File_Mode = nc_get_file_mode('Class', $ClassID);
    if ($File_Mode) {
        $class_editor = new nc_class_editor($nc_core->CLASS_TEMPLATE_FOLDER, $nc_core->db);
        $class_editor->load($ClassID);
        $class_editor->delete_template();
    }
    // удаление шаблонов
    $template_ids = $db->get_col("SELECT Class_ID FROM Class WHERE ClassTemplate = '" . $ClassID . "'");
    if (!empty($template_ids)) {
        foreach ($template_ids as $v) {
            CascadeDeleteClassTemplate($v);
        }
    }
    $ClassGroup = $db->get_var("SELECT `Class_Group` FROM `Class` WHERE `Class_ID` = '" . $ClassID . "'");
    $isMoreClasses = $db->get_var("SELECT COUNT(*) - 1 FROM `Class` WHERE `Class_Group` = '" . $ClassGroup . "'");
    //$LockTables = "LOCK TABLES `Class` WRITE, `Field` WRITE,";
    //$LockTables.= "`Message".$ClassID."` WRITE,";
    //$LockTables.= "`Sub_Class` WRITE";
    //$LockResult = $db->query($LockTables.$AddLockTables);
    // get ids
    $messages = $db->get_results("SELECT sc.`Catalogue_ID`, m.`Subdivision_ID`, m.`Sub_Class_ID`, m.`Message_ID`, m.*\n    FROM `Message" . $ClassID . "` AS m\n    LEFT JOIN `Sub_Class` AS sc ON sc.`Sub_Class_ID` = m.`Sub_Class_ID`\n    ORDER BY sc.`Catalogue_ID`, m.`Subdivision_ID`, m.`Sub_Class_ID`", OBJECT);
    if ($messages) {
        $messages_data = array_combine($db->get_col(NULL, 3), $db->get_results(NULL));
    }
    //костыль, для $messages_data нужен массив объектов
    $messages = $db->get_results("SELECT sc.`Catalogue_ID`, m.`Subdivision_ID`, m.`Sub_Class_ID`, m.`Message_ID`, m.*\n    FROM `Message" . $ClassID . "` AS m\n    LEFT JOIN `Sub_Class` AS sc ON sc.`Sub_Class_ID` = m.`Sub_Class_ID`\n    ORDER BY sc.`Catalogue_ID`, m.`Subdivision_ID`, m.`Sub_Class_ID`", ARRAY_N);
    $nc_core->event->execute("dropMessagePrep", $messages);
    // delete messages
    $db->query("DROP TABLE `Message" . $ClassID . "`");
    // call event
    if (!empty($messages)) {
        $catalogue = $messages[0][0];
        $sub = $messages[0][1];
        $cc = $messages[0][2];
        $messages_arr = array($messages[0][3]);
        $messages_data_arr = array($messages_data[$messages[0][3]]);
        foreach ($messages as $value) {
            if ($value[0] != $catalogue || $value[1] != $sub || $value[2] != $cc) {
                // execute core action
                $nc_core->event->execute("dropMessage", $catalogue, $sub, $cc, $ClassID, $messages_arr, $messages_data_arr);
                $catalogue = $value[0];
                $sub = $value[1];
                $cc = $value[2];
                $messages_arr = array($value[3]);
                $messages_data_arr = array($messages_data[$value[3]]);
            } else {
                $messages_arr[] = $value[3];
                $messages_data_arr[] = $messages_data[$value[3]];
            }
        }
    }
    // delete fields
    $db->query("DELETE FROM `Field` WHERE `Class_ID` = '" . $ClassID . "'");
    $subclasses = $db->get_results("SELECT `Catalogue_ID`, `Subdivision_ID`, `Sub_Class_ID`, `Class_ID` FROM `Sub_Class`\n    WHERE `Class_ID` = '" . $ClassID . "'", ARRAY_N);
    // delete subclasses
    if (!empty($subclasses)) {
        foreach ($subclasses as $subclass) {
            // execute core action
            $nc_core->event->execute("dropSubClassPrep", $subclass[0], $subclass[1], $subclass[2]);
            // delete related files
            require_once $INCLUDE_FOLDER . "s_files.inc.php";
            DeleteSubClassFiles($subclass[2], $subclass[3]);
            $db->query("DELETE FROM `Sub_Class` WHERE `Sub_Class_ID` = '" . $subclass[2] . "'");
            // execute core action
            $nc_core->event->execute("dropSubClass", $subclass[0], $subclass[1], $subclass[2]);
        }
    }
    // execute core action
    $nc_core->event->execute("dropClassPrep", $ClassID);
    $db->query("DELETE FROM `Class` WHERE `Class_ID` = '" . $ClassID . "'");
    // execute core action
    $nc_core->event->execute("dropClass", $ClassID);
    //$UnlockResult = $db->query("UNLOCK TABLES");
    if (!$isMoreClasses) {
        $UI_CONFIG->treeChanges['deleteNode'][] = "group-" . md5($ClassGroup);
    } else {
        $UI_CONFIG->treeChanges['deleteNode'][] = "dataclass-" . $ClassID;
    }
    return $isMoreClasses;
}