if (!nc_tgz_extract($ModuleFile, $TMP_FOLDER) && !file_exists($TMP_FOLDER . "id.txt")) { //print TOOLS_MODULES_ERR_EXTRACT; InstallationAborted(TOOLS_MODULES_ERR_EXTRACT, 'module'); } $InstallFile = $TMP_FOLDER . "install.php"; if (!is_readable($InstallFile)) { //nc_print_status(TOOLS_MODULES_ERR_CANTOPEN." install.php.", 'error'); InstallationAborted(TOOLS_MODULES_ERR_CANTOPEN . " install.php.", 'module'); } else { require $InstallFile; } if (!CheckDeps('module')) { InstallationAborted(); } CheckFiles(); if (!nc_version_control($VERSION_ID)) { //nc_print_status(TOOLS_MODULES_ERR_VERSION." NetCat.", 'error'); InstallationAborted(TOOLS_MODULES_ERR_VERSION . " NetCat.", 'module'); } if ($SystemID == "1") { //nc_print_status(TOOLS_MODULES_ERR_VERSION." NetCat.", 'error'); InstallationAborted(TOOLS_MODULES_ERR_VERSION . " NetCat.", 'module'); } if (IsAlreadyInstalled('module')) { //nc_print_status(TOOLS_MODULES_ERR_INSTALLED, 'error'); InstallationAborted(TOOLS_MODULES_ERR_INSTALLED, 'module'); } $Install = CheckAbilityOfInstallation(); if ($Install["Success"] == 0) { //nc_print_status(TOOLS_MODULES_ERR_ITEMS, 'error'); //print $Install["ErrorMessage"].".<br><br>\n\n";
function ParseClassFile($file) { // system superior object $nc_core = nc_Core::get_object(); include_once $nc_core->DOCUMENT_ROOT . $nc_core->ADMIN_PATH . "tar.inc.php"; $db =& $nc_core->db; $db->captured_errors = array(); $VersionNumber = $nc_core->get_settings("VersionNumber"); $fs = $nc_core->input->fetch_get_post('fs'); $insert_flag = "%INSERT_ID%"; $xml2array = xml2array(file_get_contents($file)); $xml_data = $xml2array['data']; // STEP 1: System version check $tpl_version = $xml_data['version']; if (!$tpl_version) { nc_print_status(CONTROL_CLASS_IMPORT_ERROR_NO_VERSION_ID, 'info'); return false; } if (!nc_version_control($tpl_version)) { nc_print_status(sprintf(CONTROL_CLASS_IMPORT_ERROR_VERSION_ID, $tpl_version, $VersionNumber), 'info'); return false; } if ($fs && !isset($xml_data['tar_data'])) { nc_print_status(CONTROL_CLASS_IMPORT_ERROR_NO_FILES, 'info'); return false; } $path_for_file_mode = array(); $sql_data = $xml_data['sql_data']; $class_query = $sql_data['class']; if (!$nc_core->NC_UNICODE) { $query = $nc_core->utf8->utf2win($class_query); } $res1 = $db->query($class_query); if ($res1) { $insert_id = $db->insert_id; $path_for_file_mode[$insert_id] = "/{$insert_id}/"; } else { nc_print_status(CONTROL_CLASS_IMPORT_ERROR_CLASS_IMPORT, 'info'); return false; } $new_tpl_ids = array(); $xmlTemplates = $sql_data['templates']['template']; if (isset($xmlTemplates['value'])) { $templates[0] = $xmlTemplates; } else { $templates = $xmlTemplates; } if (!empty($templates)) { foreach ($templates as $query) { if (!$nc_core->NC_UNICODE) { $query = $nc_core->utf8->utf2win($query); } // replace ID $query = str_replace($insert_flag, $insert_id, $query); if (!$fs && strpos($query, '%CDATA_START%')) { $query = str_replace('%CDATA_START%', '<![CDATA[', $query); $query = str_replace('%CDATA_END%', ']]>', $query); } if (!$db->query($query)) { nc_print_status(CONTROL_CLASS_IMPORT_ERROR_CLASS_TEMPLATE_IMPORT, 'info'); $db->query("DELETE FROM `Class` WHERE `Class_ID` = '" . $insert_id . "'"); return false; } $path_for_file_mode[$db->insert_id] = "/{$insert_id}/{$db->insert_id}/"; $new_tpl_ids[] = $db->insert_id; } } foreach ($path_for_file_mode as $id => $path) { $SQL = "UPDATE `Class` \n SET `File_Path` = '{$path}' \n WHERE `Class_ID` = {$id}"; $db->query($SQL); } // STEP 5: create MessageXX table $create_message = $sql_data['message_tbl']; $create_message = str_replace($insert_flag, $insert_id, $create_message); $create_message = str_replace('%%MYSQL_CHARSET%%', $nc_core->MYSQL_CHARSET, $create_message); $res2 = $db->query($create_message); if ($res2 != 0) { nc_print_status(CONTROL_CLASS_IMPORT_ERROR_MESSAGE_TABLE, 'info'); $db->query("DELETE FROM `Class` WHERE `Class_ID` = '" . $insert_id . "' OR `ClassTemplate` = '" . $insert_id . "'"); return false; } $xmlFields = $sql_data['fields']['field']; if (!is_array($xmlFields)) { $xmlFields = (array) $xmlFields; } foreach ($xmlFields as $query) { if (!$nc_core->NC_UNICODE) { $query = $nc_core->utf8->utf2win($query); } $query = str_replace($insert_flag, $insert_id, $query); if ($query) { $res3 = $db->query($query); if ($db->captured_errors) { nc_print_status(CONTROL_CLASS_IMPORT_ERROR_FIELD, 'info'); $db->query("DELETE FROM `Class` WHERE `Class_ID` = '" . $insert_id . "' OR `ClassTemplate` = '" . $insert_id . "'"); $db->query("DROP TABLE `Message" . $insert_id . "`"); $db->query("DELETE FROM `Field` WHERE `Class_ID` = '" . $insert_id . "'"); return false; } } } if (isset($xml_data['tar_data'])) { $tar = $xml_data['tar_data']; $tar_name = $nc_core->TMP_FOLDER . 'import_class_' . $insert_id . '_' . mktime() . '.tgz'; file_put_contents($tar_name, base64_decode(trim($tar))); nc_tgz_extract($tar_name, $nc_core->TMP_FOLDER); rename($nc_core->TMP_FOLDER . $xml_data['class_id'], $nc_core->TMP_FOLDER . $insert_id); $xmlTplIds = $xml_data['tpl_ids']['tpl_id']; if (!is_array($xmlTplIds)) { $xmlTplIds = (array) $xmlTplIds; } foreach ($xmlTplIds as $i => $tpl_id) { rename($nc_core->TMP_FOLDER . $insert_id . '/' . $tpl_id, $nc_core->TMP_FOLDER . $insert_id . '/' . $new_tpl_ids[$i]); } rename($nc_core->TMP_FOLDER . $insert_id, $nc_core->CLASS_TEMPLATE_FOLDER . $insert_id); unlink($tar_name); } return $insert_id; }