<commit_before><?php

lock();

// Module API
define('API_MODULE_ADD', 'module.add');
define('API_MODULE_GET', 'module.get');
define('API_MODULE_MOVE', 'module.move');
define('API_MODULE_RESIZE', 'module.resize');
define('API_MODULE_REMOVE', 'module.remove');
define('API_MODULE_RENAME', 'module.rename');
define('API_MODULE_RECAPTURE', 'module.recapture');

switch ($action) {
    case API_MODULE_REMOVE:
        $id = intval($route[4]);
        if ($id < 1) { die('Please provide a module id'); }
        $module = $db->single("
            SELECT m.screen, m.module, s.project, pm.id
            FROM module m
                LEFT JOIN project_module pm ON pm.id = m.module
                LEFT JOIN screen s ON s.id = m.screen
            WHERE m.id = '" . $id . "' AND m.creator = '" . userid() . "'
            LIMIT 1
        ");
        if (!$module) { die(); }
        $result = array();
        $db->delete('module', array('id' => $id));
        $count = $db->exists('module', array('module' => $module['module']));
        if ($count < 1) {
            $screen = $db->single("SELECT id, project, ext FROM screen WHERE id = '" . $screen . "' AND creator = " . userid());
            $path =  'upload/modules/'.$screen['project'].'/'.md5($module.config('security.general.hash')).'.'.$screen['ext'];
            unlink(TERRIFIC . $path);

            $db->delete('project_module', array('id' => $module['id'], 'creator' => userid()));

            $result['remove'] = $module['id'];
        }
        $db->query("UPDATE screen SET count_module = count_module - 1 WHERE id = " . $module['screen'] . "");
        header('Content-Type: application/json');
        echo json_encode($result);
        break;

    case API_MODULE_GET:
        $screen = intval($route[4]);
        if ($screen < 1) { die('Please provide a screen id'); }
        $data = $db->data("SELECT m.id, m.module, m.x, m.y, m.width, m.height, pm.name, pm.skin FROM module m LEFT JOIN project_module pm ON pm.id = m.module WHERE m.screen = " . $screen . " AND m.creator = " . userid());<commit_msg>fixed #36 Deletion of modules not working.<commit_after><?php

lock();

// Module API
define('API_MODULE_ADD', 'module.add');
define('API_MODULE_GET', 'module.get');
define('API_MODULE_MOVE', 'module.move');
define('API_MODULE_RESIZE', 'module.resize');
define('API_MODULE_REMOVE', 'module.remove');
define('API_MODULE_RENAME', 'module.rename');
define('API_MODULE_RECAPTURE', 'module.recapture');

switch ($action) {
    case API_MODULE_REMOVE:
        $id = intval($route[4]);
        if ($id < 1) { die('Please provide a module id'); }
        $module = $db->single("
            SELECT m.screen, m.module, s.project, pm.id, s.ext
            FROM module m
                LEFT JOIN project_module pm ON pm.id = m.module
                LEFT JOIN screen s ON s.id = m.screen
            WHERE m.id = '" . $id . "' AND m.creator = '" . userid() . "'
            LIMIT 1
        ");
        if (!$module) { die(); }
        $result = array();
        $db->delete('module', array('id' => $id));
        $count = $db->exists('module', array('module' => $module['module']));
        if ($count < 1) {
            $path =  'upload/modules/'.$module['project'].'/'.md5($module['id'].config('security.general.hash')).'.'.$module['ext'];
            unlink(TERRIFIC . $path);

            $db->delete('project_module', array('id' => $module['id'], 'creator' => userid()));

            $result['remove'] = $module['id'];
        }
        $db->query("UPDATE screen SET count_module = count_module - 1 WHERE id = " . $module['screen'] . "");
        header('Content-Type: application/json');
        echo json_encode($result);
        break;

    case API_MODULE_GET:
        $screen = intval($route[4]);
        if ($screen < 1) { die('Please provide a screen id'); }
        $data = $db->data("SELECT m.id, m.module, m.x, m.y, m.width, m.height, pm.name, pm.skin FROM module m LEFT JOIN project_module pm ON pm.id = m.module WHERE m.screen = " . $screen . " AND m.creator = " . userid());
{'fraction_non_alphanumeric': 0.19146311374290648, 'fraction_numerical': 0.0044411547002220575, 'mean_word_length': 2.6131907308377897, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6940166', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1273, 'n_words': 303}