protected function export_init($id, $export_id = null) { $this->reset(); $this->id($id); if ($export_id) { $this->export_id($export_id); } $this->info = array(); $this->info['export'] = array('version' => $this->version(), 'driver' => $this->backup->config('driver'), 'type' => $this->type(), 'id' => $this->id(), 'date' => date('Y-m-d H:i:s'), 'user' => $GLOBALS['perm']->getLogin() . ':' . $GLOBALS['AUTH_USER_ID'], 'http_host' => $this->nc_core->HTTP_HOST); // Netcat info $SystemID = $this->nc_core->get_settings("SystemID"); $LastPatch = $this->nc_core->get_settings("LastPatch"); list($SystemName, $SystemColor) = nc_system_name_by_id($SystemID); $this->info['netcat'] = array('version' => $this->nc_core->get_settings("VersionNumber"), 'type' => $SystemName); $this->doc = new DOMDocument(); $this->xpath = new DOMXpath($this->doc); $this->doc->preserveWhiteSpace = false; $this->doc->formatOutput = true; $this->doc->encoding = 'utf-8'; $this->make_elem('root', $this->doc); $this->make_elem('info'); $this->make_elem('dict'); $this->make_elem('data'); $this->make_elem('files'); }
function CascadeExportTemplate($TemplateID) { // system superior object $nc_core = nc_Core::get_object(); include $nc_core->DOCUMENT_ROOT . $nc_core->ADMIN_PATH . "tar.inc.php"; $db =& $nc_core->db; $VersionNumber = $nc_core->get_settings("VersionNumber"); $SystemID = $nc_core->get_settings("SystemID"); $LastPatch = $nc_core->get_settings("LastPatch"); $TemplateID = intval($TemplateID); // Блокируем таблицы $LockTables = "LOCK TABLES `Template` WRITE"; $LockResult = $db->query($LockTables); // Экспортируем данные из таблицы Template $SelectTemplate = $db->get_row("SELECT * FROM `Template` WHERE `Template_ID` = '" . $TemplateID . "'", ARRAY_A); $File_Mode = $SelectTemplate['File_Mode']; $FieldsForExport = array_keys($SelectTemplate); $Qry = array(); foreach ($FieldsForExport as $Field) { if ($Field == "Template_ID") { continue; } if ($Field == "Description") { $ptpl_desc = $SelectTemplate[$Field]; } // component template export aborted! $Qry[] = "`" . $Field . "` = '" . addcslashes($SelectTemplate[$Field], "\\'\r\n") . "'"; } $TemplatesArr = $db->get_results("SELECT * FROM `Template` WHERE `File_Path` LIKE '" . $SelectTemplate['File_Path'] . "%'", ARRAY_A); if (!empty($TemplatesArr)) { $TempText .= "<templates>"; $Path = ""; foreach ($TemplatesArr as $row) { $path = substr($row['File_Path'], 1, -1); $current_id = $row["Template_ID"]; $current_desc = $row["Description"]; $Path .= "<path>{$row["File_Path"]}</path>"; $level = count(explode('/', $path)); $tplChildren = implode(',', $nc_core->template->get_childs($current_id)); $Qry = array(); foreach ($FieldsForExport as $Field) { // skip ID if ($Field == "Template_ID") { continue; } // set `Parent_Template_ID` if ($Field == "Parent_Template_ID") { $Qry[] = "`Parent_Template_ID` = '%INSERT_ID%'"; $parent = $row[$Field]; continue; } $Qry[] = "`" . $Field . "` = '" . addcslashes($row[$Field], "\\'\r\n") . "'"; } if ($current_id == $TemplateID) { $parent = 0; } // template str $TempText .= "<template id='" . $current_id . "' level='" . $level . "' parent='" . $parent . "' desc='" . $current_desc . "' children='" . $tplChildren . "'><![CDATA[INSERT INTO `Template` SET " . join(", ", $Qry) . ";]]></template>\n"; } $TempText .= "</templates>"; } $db->query("UNLOCK TABLES"); list($SystemName, $SystemColor) = nc_system_name_by_id($SystemID); $export_id_str = "-- NetCat " . $VersionNumber . " " . $SystemName . " [" . $LastPatch . "] component file, generated " . date("Y-m-d H:i:s"); $output = "<?xml version=\"1.0\"?>\n<data>\n <version>{$VersionNumber}</version>\n <export_id>{$export_id_str}</export_id>\n <template_id>{$TemplateID}</template_id>"; if (isset($TempIds)) { $output .= $TempIds; } $output .= "<sql>\n {$TempText}</sql>\n"; if ($File_Mode) { $tmp_file_name = $nc_core->TMP_FOLDER . "netcat_template_{$TemplateID}.tgz"; $dump_file = @nc_tgz_create($tmp_file_name, substr($SelectTemplate['File_Path'], 1, -1), $nc_core->HTTP_TEMPLATE_PATH . 'template/'); $tar_contents = @file_get_contents($tmp_file_name); if ($dump_file && $tar_contents) { $output .= "<tar>" . base64_encode($tar_contents) . "</tar>\n"; unlink($tmp_file_name); } } $output .= "</data>"; // все компоненты в utf-8 if (!$nc_core->NC_UNICODE) { $ret = $nc_core->utf8->win2utf($ret); } return $output; }
function nc_report_status() { global $perm, $LAST_LOCAL_PATCH; $nc_core = nc_Core::get_object(); $mysqlversion_ok = false; if (preg_match("/^(\\d)\\.(\\d)/is", mysql_get_server_info(), $matches)) { if (intval($matches[1] . $matches[2]) >= 41) { $mysqlversion_ok = true; } } $phpversion_ok = false; if (preg_match("/^(\\d)\\.(\\d)/is", phpversion(), $matches)) { if (intval($matches[1] . $matches[2]) >= 52) { $phpversion_ok = true; } } $allow_url_fopen = ini_get('allow_url_fopen'); $short_open_tag = ini_get('short_open_tag'); $safe_mode = ini_get('safe_mode'); $register_globals = ini_get('register_globals'); $magic_quotes_gpc = ini_get('magic_quotes_gpc'); $mbstring_func_overload = ini_get('mbstring.func_overload'); $zend_ze1_compatibility_mode = ini_get('zend.ze1_compatibility_mode'); $memory_limit = ini_get('memory_limit'); $post_max_size = ini_get('post_max_size'); $upload_max_filesize = ini_get('upload_max_filesize'); $max_file_uploads = ini_get('max_file_uploads'); // search module $add_memory_limit = $nc_core->modules->get_by_keyword('search') ? 64 : 0; $upload_tmp_dir = ''; /*if ( function_exists('sys_get_temp_dir') ) { $upload_tmp_dir = sys_get_temp_dir(); }*/ $extensions_req = array('session' => 'Session', 'mbstring' => 'MBstring', 'iconv' => 'iconv', 'tokenizer' => 'Tokenizer', 'ctype' => 'Ctype', 'dom' => 'DOM', 'json' => 'JSON', 'libxml' => 'libxml', 'simplexml' => 'SimpleXML'); $extensions_opt = array('curl' => 'cURL', 'gmp' => 'GMP'); $gd = extension_loaded('gd'); $gd_version = $gd ? gd_info() : 0; $gd_ok = false; preg_match('/\\d/', $gd_version['GD Version'], $match); if (isset($match[0]) && $match[0] >= 2) { $gd_ok = true; } $pr = $nc_core->DOCUMENT_ROOT . $nc_core->SUB_FOLDER; $folder = array($nc_core->HTTP_FILES_PATH => $pr . $nc_core->HTTP_FILES_PATH, $nc_core->HTTP_DUMP_PATH => $pr . $nc_core->HTTP_DUMP_PATH, $nc_core->HTTP_CACHE_PATH => $pr . $nc_core->HTTP_CACHE_PATH, $nc_core->HTTP_TRASH_PATH => $pr . $nc_core->HTTP_TRASH_PATH, $nc_core->HTTP_TEMPLATE_PATH => $pr . $nc_core->HTTP_TEMPLATE_PATH, $nc_core->HTTP_ROOT_PATH . 'tmp/' => $pr . $nc_core->HTTP_ROOT_PATH . 'tmp/'); if ($upload_tmp_dir) { $folder[$upload_tmp_dir] = $upload_tmp_dir; } $ok = '<span style="color: #0A0">Ok</span>'; $error = '<span style="color: #A00">Error</span>'; $low = '<span style="color: #F90">Low</span>'; list($system_name, $system_color) = nc_system_name_by_id($nc_core->get_settings('SystemID')); $system_name_formatted = '<span style="color: ' . $system_color . '">' . $system_name . '</span>'; $html = "<br style='clear:both;'/><br />\n\t <div class='reportstatus'>\n\t\t<div class='title'>NetCat</div>\n\t\t<div class='name'>" . SECTION_INDEX_ADMIN_PATCHES_INFO_VERSION . "</div>\n\t\t<div class='value'>" . $nc_core->get_settings('VersionNumber') . "</div>\n\t\t<div class='req'>—</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>" . SECTION_INDEX_ADMIN_PATCHES_INFO_REDACTION . "</div>\n\t\t<div class='value'>" . $system_name_formatted . "</div>\n\t\t<div class='req'>—</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>" . SECTION_INDEX_ADMIN_PATCHES_INFO_LAST_PATCH . "</div>\n\t\t<div class='value'>" . ($LAST_LOCAL_PATCH ? $LAST_LOCAL_PATCH : "—") . "</div>\n\t\t<div class='req'>—</div>\n\t\t<div style='clear:both;'></div>" . (is_object($perm) && ($perm->isDirector() || $perm->isSupervisor()) ? "\n\t\t<br />\n\t\t<div class='name'>" . TOOLS_ACTIVATION_LICENSE . "</div>\n\t\t<div class='value'>" . ($nc_core->get_settings('ProductNumber') ? $nc_core->get_settings('ProductNumber') : "—") . "</div>\n\t\t<div class='req'>—</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>" . TOOLS_ACTIVATION_CODE . "</div>\n\t\t<div class='value'>" . ($nc_core->get_settings('Code') ? $nc_core->get_settings('Code') : "—") . "</div>\n\t\t<div class='req'>—</div>\n\t\t<div style='clear:both;'></div>" : "") . "\n\t </div>\n\t <div class='reportstatus'>\n\t\t<div class='title'>MySQL Server</div>\n\t\t<div class='name'>mysql_get_server_info</div>\n\t\t<div class='value'>" . mysql_get_server_info() . "</div>\n\t\t<div class='req'>" . (!$mysqlversion_ok ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t</div>\n\t <div class='reportstatus'>\n\t\t<div class='title'>PHP ( <a href='?phase=2' target='_blank'>phpinfo</a> )</div>\n\t\t<div class='name'>phpversion</div>\n\t\t<div class='value'>" . phpversion() . "</div>\n\t\t<div class='req'>" . (!$phpversion_ok ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<br />\n\t\t<div class='name'>allow_url_fopen</div>\n\t\t<div class='value'>" . ($allow_url_fopen ? NETCAT_MODERATION_ISON : NETCAT_MODERATION_ISOFF) . "</div>\n\t\t<div class='req'>" . (!$allow_url_fopen ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>short_open_tag</div>\n\t\t<div class='value'>" . ($short_open_tag ? NETCAT_MODERATION_ISON : NETCAT_MODERATION_ISOFF) . "</div>\n\t\t<div class='req'>" . (!$short_open_tag ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>safe_mode</div>\n\t\t<div class='value'>" . ($safe_mode ? NETCAT_MODERATION_ISON : NETCAT_MODERATION_ISOFF) . "</div>\n\t\t<div class='req'>" . ($safe_mode ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>register_globals</div>\n\t\t<div class='value'>" . ($register_globals ? NETCAT_MODERATION_ISON : NETCAT_MODERATION_ISOFF) . "</div>\n\t\t<div class='req'>" . ($register_globals ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>magic_quotes_gpc</div>\n\t\t<div class='value'>" . ($magic_quotes_gpc ? NETCAT_MODERATION_ISON : NETCAT_MODERATION_ISOFF) . "</div>\n\t\t<div class='req'>" . ($magic_quotes_gpc ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>mbstring.func_overload</div>\n\t\t<div class='value'>" . ($mbstring_func_overload ? NETCAT_MODERATION_ISON : NETCAT_MODERATION_ISOFF) . "</div>\n\t\t<div class='req'>" . ($mbstring_func_overload ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>zend.ze1_compatibility_mode</div>\n\t\t<div class='value'>" . ($zend_ze1_compatibility_mode ? NETCAT_MODERATION_ISON : NETCAT_MODERATION_ISOFF) . "</div>\n\t\t<div class='req'>" . ($zend_ze1_compatibility_mode ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<br />\n\t\t<div class='name'>memory_limit</div>\n\t\t<div class='value'>" . $memory_limit . "</div>\n\t\t<div class='req'>" . ($memory_limit < 64 + $add_memory_limit ? $error : ($memory_limit >= 64 + $add_memory_limit && $memory_limit < 128 + $add_memory_limit ? $low : $ok)) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>post_max_size</div>\n\t\t<div class='value'>" . $post_max_size . "</div>\n\t\t<div class='req'>" . ($post_max_size < 8 ? $error : ($post_max_size >= 8 && $post_max_size < 16 ? $low : $ok)) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>upload_max_filesize</div>\n\t\t<div class='value'>" . $upload_max_filesize . "</div>\n\t\t<div class='req'>" . ($upload_max_filesize < 2 ? $error : ($upload_max_filesize >= 2 && $upload_max_filesize < 4 ? $low : $ok)) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<div class='name'>max_file_uploads</div>\n\t\t<div class='value'>" . $max_file_uploads . "</div>\n\t\t<div class='req'>" . ($max_file_uploads < 10 ? $error : ($max_file_uploads >= 10 && $max_file_uploads < 20 ? $low : $ok)) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<br />"; foreach ($extensions_req as $key => $value) { $loaded = extension_loaded($key); $html .= "<div class='name'>" . $value . "</div>\n\t\t\t\t<div class='value'>" . ($loaded ? NETCAT_MODERATION_ISON : NETCAT_MODERATION_ISOFF) . "</div>\n\t\t\t\t<div class='req'>" . (!$loaded ? $error : $ok) . "</div>\n\t\t\t\t<div style='clear:both;'></div>"; } $html .= "<div class='name'>GD library</div>\n\t\t<div class='value'>" . ($gd_version ? $gd_version['GD Version'] : "—") . "</div>\n\t\t<div class='req'>" . (!$gd_ok ? $error : $ok) . "</div>\n\t\t<div style='clear:both;'></div>\n\t\t<br />"; foreach ($extensions_opt as $key => $value) { $loaded = extension_loaded($key); $html .= "<div class='name'>" . $value . "</div>\n\t\t\t\t<div class='value'>" . ($loaded ? NETCAT_MODERATION_ISON : NETCAT_MODERATION_ISOFF) . "</div>\n\t\t\t\t<div class='req'>" . (!$loaded ? "—" : $ok) . "</div>\n\t\t\t\t<div style='clear:both;'></div>"; } $html .= "</div>\n\t <div class='reportstatus'>\n\t\t<div class='title'>" . TOOLS_PATCH_IS_WRITABLE . "</div>"; foreach ($folder as $k => $v) { $is_writable = is_writable($v); $html .= "\n\t\t <div class='name'>" . $k . "</div>\n\t\t <div class='value'>" . TOOLS_PATCH_IS_WRITABLE . "</div>\n\t\t <div class='req'>" . (!$is_writable ? $error : $ok) . "</div>\n\t\t <div style='clear:both;'></div>\n\t\t"; } $html .= "\n\t </div><br />"; return $html; }
// this temporary file will be deleted in the end of this function or in InstallationAborted() if (!nc_tgz_extract($TMP_FOLDER . $patch_file_tgz, $TMP_FOLDER) && !file_exists($TMP_FOLDER . "id.txt")) { InstallationAborted(TOOLS_PATCH_ERR_EXTRACT, 'activation'); } // check files in patch if (!CheckDeps('patch')) { InstallationAborted(TOOLS_PATCH_INFO_NOTINSTALLED . ".<br>", 'activation'); } // other version if ($VersionID != $VERSION_ID) { InstallationAborted(str_replace(array("%REQUIRE", "%EXIST"), array($VersionID, $VERSION_ID), TOOLS_PATCH_INVALIDVERSION), 'activation'); } // other system if ($SystemID && $SystemID != $SYSTEM_ID) { list($required_sys_name, $required_sys_color) = nc_system_name_by_id($SystemID); list($installed_sys_name, $installed_sys_color) = nc_system_name_by_id($SYSTEM_ID); InstallationAborted(str_replace(array("%REQUIRE", "%EXIST"), array($required_sys_name, $installed_sys_name), TOOLS_PATCH_INVALIDVERSION) . "<br>", 'activation'); } // проверка версий if ($LAST_LOCAL_PATCH != $PatchName) { InstallationAborted(TOOLS_PATCH_INFO_NOTINSTALLED . ".<br>", 'activation'); } // install.inc.php not readable or include them $InstallFile = $TMP_FOLDER . "install.inc.php"; if (!is_readable($InstallFile)) { InstallationAborted(TOOLS_MODULES_ERR_CANTOPEN . " install.inc.php.", 'activation'); } else { require $InstallFile; } // files in patch if (!is_readable($TMP_FOLDER . "id.txt")) {
function LoadSettings() { global $nc_core, $db; global $IsInsideAdmin, $system_env; global $PROJECT_NAME, $VERSION_ID, $ANY_SYSTEM_MESSAGE, $SYSTEM_ID, $ADMIN_FOLDER; global $SPAM_FIELD, $SPAM_MAIL, $SPAM_FROM, $SPAM_FROM_NAME, $NO_RIGHTS_MESSAGE, $PATCH_CHECK_DATE; global $LAST_PATCH, $LAST_LOCAL_PATCH, $SYSTEM_NAME, $SYSTEM_COLOR; global $HTTP_HOST, $REMOTE_ADDR, $HTTP_USER_AGENT, $HTTP_ROOT_PATH; global $EDITOR_TYPE, $INLINE_EDIT_CONFIRMATION, $SUB_FOLDER; global $REMIND_SAVE, $PACKET_OPERATIONS, $TEXTAREA_RESIZE; $Array = $nc_core->get_settings(); // probably system was not installed: if (!sizeof($Array)) { // probably system was not installed if ($this->check_system_install()) { // DB error print "<p><b>" . NETCAT_ERROR_DB_CONNECT . "</b></p>"; exit; } } $PROJECT_NAME = $Array['ProjectName']; $SYSTEM_ID = $Array['SystemID']; $VERSION_ID = $Array['VersionNumber']; $SPAM_FIELD = $Array['UserEmailField']; $SPAM_MAIL = $Array['UserEmailField']; $SPAM_FROM = $Array['SpamFromEmail']; $SPAM_FROM_NAME = $Array['SpamFromName']; $EDITOR_TYPE = $Array['EditorType']; $INLINE_EDIT_CONFIRMATION = $Array['InlineEditConfirmation']; $REMIND_SAVE = $Array['RemindSave']; $PACKET_OPERATIONS = $Array['PacketOperations']; $TEXTAREA_RESIZE = $Array['TextareaResize']; list($SYSTEM_NAME, $SYSTEM_COLOR) = nc_system_name_by_id($SYSTEM_ID); if (isset($Array['InstallationID']) || $Array['InstallationDateOut']) { $nc_core->is_trial = true; } $LAST_LOCAL_PATCH = $db->get_var("SELECT `Patch_Name` FROM `Patch` ORDER BY `Patch_Name` DESC LIMIT 1"); $LAST_LOCAL_PATCH += 0; // следующий патч $LAST_PATCH = $Array['LastPatch']; // время последнего обращения за обновлениями $PATCH_CHECK_DATE = $Array['PatchCheck']; // спрашиваем раз в неделю $PATCH_CHECK_NEEDED = $PATCH_CHECK_DATE + 2 * 24 * 3600 < time(); if (!$PATCH_CHECK_DATE || $PATCH_CHECK_NEEDED || $IsInsideAdmin) { $an = new nc_AdminNotice(); $LAST_PATCH = $an->update(); } $ANY_SYSTEM_MESSAGE = $db->get_var("SELECT COUNT(*) FROM `SystemMessage` WHERE `Checked` = 0"); $system_env = $nc_core->get_settings(); $system_env['Powered'] = "PHP/" . phpversion(); }
function CascadeExportClass($ClassID) { // system superior object $nc_core = nc_Core::get_object(); include $nc_core->DOCUMENT_ROOT . $nc_core->ADMIN_PATH . "tar.inc.php"; $db =& $nc_core->db; $VersionNumber = $nc_core->get_settings("VersionNumber"); $SystemID = $nc_core->get_settings("SystemID"); $LastPatch = $nc_core->get_settings("LastPatch"); $ClassID = intval($ClassID); // Блокируем таблицы $LockTables = "LOCK TABLES `Class` WRITE, `Field` WRITE, "; $LockTables .= "`Message" . $ClassID . "` WRITE, "; $LockTables .= "`Sub_Class` WRITE"; $LockResult = $db->query($LockTables); // Экспортируем данные из таблицы Class $SelectClass = $db->get_row("SELECT * FROM `Class` WHERE `Class_ID` = '" . $ClassID . "'", ARRAY_A); $File_Mode = $SelectClass['File_Mode']; $FieldsForExport = array_keys($SelectClass); $Qry = array(); foreach ($FieldsForExport as $Field) { if ($Field == "Class_ID") { continue; } // component template export aborted! if ($Field == "ClassTemplate" && $SelectClass[$Field] != 0) { return false; } $Qry[] = "`" . $Field . "` = '" . addcslashes($SelectClass[$Field], "\\'\r\n") . "'"; } $TempText .= "<class><![CDATA[INSERT INTO `Class` SET " . join(", ", $Qry) . ";]]></class>\n"; // component templates $ClassTemplatesArr = $db->get_results("SELECT * FROM `Class` WHERE `ClassTemplate` = '" . $ClassID . "'", ARRAY_A); if (!empty($ClassTemplatesArr)) { $TempText .= "<templates>"; $TempIds = "<tpl_ids>"; foreach ($ClassTemplatesArr as $row) { $Qry = array(); foreach ($FieldsForExport as $Field) { // skip ID if ($Field == "Class_ID") { $TempIds .= "<tpl_id>{$row[$Field]}</tpl_id>"; continue; } // set `ClassTemplate` if ($Field == "ClassTemplate") { $Qry[] = "`ClassTemplate` = '%INSERT_ID%'"; continue; } if (!$File_Mode && strpos($row[$Field], '<![CDATA[')) { $row[$Field] = str_replace('<![CDATA[', '%CDATA_START%', $row[$Field]); $row[$Field] = str_replace(']]>', '%CDATA_END%', $row[$Field]); } $Qry[] = "`" . $Field . "` = '" . addcslashes($row[$Field], "\\'\r\n") . "'"; } // template str $TempText .= "<template><![CDATA[INSERT INTO `Class` SET " . join(", ", $Qry) . ";]]></template>\n"; } $TempText .= "</templates>"; $TempIds .= "</tpl_ids>"; } #Экспортируем данные из таблицы Field $classFields = $db->get_results("SELECT * FROM `Field` WHERE `Class_ID` = '" . $ClassID . "'"); $db->query("SET SQL_QUOTE_SHOW_CREATE = 1"); $temp_result = $db->get_row("SHOW CREATE TABLE `Message" . $ClassID . "`", ARRAY_N); $lastpos = strrpos($temp_result[1], ")"); $CreateTable = nc_substr($temp_result[1], 0, $lastpos); $CreateTable = str_ireplace("CREATE TABLE `message" . $ClassID . "`", "CREATE TABLE `Message%INSERT_ID%`", $CreateTable); $CreateTable = str_ireplace(array("\r", "\n"), "", $CreateTable); $CreateTable .= ") ENGINE=MyISAM;\n"; $TempText .= '<message_tbl>' . $CreateTable . '</message_tbl>'; // Экспортируем данные из таблицы Field $classFields = $db->get_results("SELECT * FROM `Field` WHERE `Class_ID` = '" . $ClassID . "'"); if (!empty($classFields)) { $insert = "<fields>"; foreach ($classFields as $SelectField) { //определяем тип данных $alter = " "; switch ($SelectField->TypeOfData_ID) { case 1: $alter .= "char(255)"; break; case 2: $alter .= "int"; break; case 3: $alter .= "text"; break; case 4: $alter .= "int"; break; case 5: $alter .= "tinyint"; break; case 6: $alter .= "char(255)"; break; case 7: $alter .= "double"; break; case 8: $alter .= "datetime"; break; case 9: $alter .= "int"; break; case 10: $alter .= "text"; break; } if ($SelectField->DefaultState != "" && $SelectField->TypeOfData_ID != 3) { $alter .= " NOT NULL DEFAULT '" . $SelectField->DefaultState . "'"; } elseif ($SelectField->NotNull) { $alter .= " NOT NULL"; } else { $alter .= " NULL"; } $insert .= "<field>INSERT INTO Field (`Class_ID`, `Field_Name`, `Description`, `TypeOfData_ID`, `Format`, `NotNull`, `Priority`, `DoSearch`, `DefaultState`, `TypeOfEdit_ID`) VALUES"; $insert .= " (%INSERT_ID%, '" . str_replace("'", "\\'", $SelectField->Field_Name) . "', '" . str_replace("'", "\\'", $SelectField->Description) . "', " . $SelectField->TypeOfData_ID . ", '" . str_replace("'", "\\'", $SelectField->Format) . "', " . $SelectField->NotNull . ", " . $SelectField->Priority . ", " . $SelectField->DoSearch . ", '" . str_replace("'", "\\'", $SelectField->DefaultState) . "', " . $SelectField->TypeOfEdit_ID . ");</field>\n"; } $insert .= "</fields>"; } $TempText .= $insert; $db->query("UNLOCK TABLES"); list($SystemName, $SystemColor) = nc_system_name_by_id($SystemID); $export_id_str = "-- NetCat " . $VersionNumber . " " . $SystemName . " [" . $LastPatch . "] component file, generated " . date("Y-m-d H:i:s"); $output = "<?xml version=\"1.0\"?>\n<data>\n <version>{$VersionNumber}</version>\n <export_id>{$export_id_str}</export_id>\n <class_id>{$ClassID}</class_id>"; if (isset($TempIds)) { $output .= $TempIds; } $output .= "<sql_data>\n {$TempText}</sql_data>\n"; if ($File_Mode) { $tmp_file_name = $nc_core->TMP_FOLDER . "netcat_class_{$ClassID}.tgz"; $dump_file = nc_tgz_create($tmp_file_name, $ClassID, $nc_core->HTTP_TEMPLATE_PATH . 'class/'); $tar_contents = file_get_contents($tmp_file_name); $output .= "<tar_data>" . base64_encode($tar_contents) . "</tar_data>\n"; unlink($tmp_file_name); } $output .= "</data>"; // все компоненты в utf-8 if (!$nc_core->NC_UNICODE) { $ret = $nc_core->utf8->win2utf($ret); } return $output; }
function CascadeExportClass($ClassID) { // system superior object $nc_core = nc_Core::get_object(); include $nc_core->DOCUMENT_ROOT . $nc_core->ADMIN_PATH . "tar.inc.php"; $db =& $nc_core->db; $VersionNumber = $nc_core->get_settings("VersionNumber"); $SystemID = $nc_core->get_settings("SystemID"); $LastPatch = $nc_core->get_settings("LastPatch"); $ClassID = intval($ClassID); // Блокируем таблицы $LockTables = "LOCK TABLES `Class` WRITE, `Field` WRITE, "; $LockTables .= "`Message" . $ClassID . "` WRITE, "; $LockTables .= "`Sub_Class` WRITE"; $LockResult = $db->query($LockTables); // Экспортируем данные из таблицы Class $SelectClass = $db->get_row("SELECT * FROM `Class` WHERE `Class_ID` = '" . $ClassID . "'", ARRAY_A); $File_Mode = $SelectClass['File_Mode']; $FieldsForExport = array_keys($SelectClass); $Qry = array(); foreach ($FieldsForExport as $Field) { // skip ID if ($Field == "Class_ID") { continue; } // component template export aborted! if ($Field == "ClassTemplate" && $SelectClass[$Field] != 0) { return false; } $Qry[] = "`" . $Field . "` = '" . addcslashes($SelectClass[$Field], "\\'\r\n") . "'"; } $TempText .= "<class>INSERT INTO `Class` SET " . join(", ", $Qry) . ";</class>\n"; // component templates $ClassTemplatesArr = $db->get_results("SELECT * FROM `Class` WHERE `ClassTemplate` = '" . $ClassID . "'", ARRAY_A); if (!empty($ClassTemplatesArr)) { $TempText .= "<templates>"; $TempIds .= "<tpl_ids>"; foreach ($ClassTemplatesArr as $row) { $Qry = array(); foreach ($FieldsForExport as $Field) { // skip ID if ($Field == "Class_ID") { $TempIds .= "<tpl_id>{$row[$Field]}</tpl_id>"; continue; } // set `ClassTemplate` if ($Field == "ClassTemplate") { $Qry[] = "`ClassTemplate` = '%INSERT_ID%'"; continue; } $Qry[] = "`" . $Field . "` = '" . addcslashes($row[$Field], "\\'\r\n") . "'"; } // template str $TempText .= htmlspecialchars("INSERT INTO `Class` SET " . join(", ", $Qry) . ";\n"); } $TempText .= "</templates>"; $TempIds .= "</tpl_ids>"; } #Экспортируем данные из таблицы Field $classFields = $db->get_results("SELECT * FROM `Field` WHERE `Class_ID` = '" . $ClassID . "'"); $TempText .= "CREATE TABLE Message%INSERT_ID% (" . "`Message_ID` int(11) NOT NULL auto_increment, " . "`User_ID` int(11) NOT NULL, " . "`Subdivision_ID` int(11) NOT NULL, " . "`Sub_Class_ID` int(11) NOT NULL, " . "`Priority` int(11) NOT NULL default '0', " . "`Keyword` char(255) NOT NULL, " . "`Checked` tinyint(4) NOT NULL default '1', " . "`IP` char(15) default NULL, " . "`UserAgent` char(255) default NULL, " . "`Parent_Message_ID` int(11) NOT NULL default '0', " . "`Created` datetime NOT NULL, " . "`LastUpdated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, " . "`LastUser_ID` int(11) NOT NULL, " . "`LastIP` char(15) default NULL, " . "`LastUserAgent` char(255) default NULL, "; $insert = ""; if (!empty($classFields)) { $insert = "<fields>"; foreach ($classFields as $SelectField) { $TempText .= "`" . $SelectField->Field_Name . "`"; //определяем тип данных $alter = " "; switch ($SelectField->TypeOfData_ID) { case 1: $alter .= "char(255)"; break; case 2: $alter .= "int"; break; case 3: $alter .= "text"; break; case 4: $alter .= "int"; break; case 5: $alter .= "tinyint"; break; case 6: $alter .= "char(255)"; break; case 7: $alter .= "double"; break; case 8: $alter .= "datetime"; break; case 9: $alter .= "int"; break; case 10: $alter .= "text"; break; } if ($SelectField->DefaultState != "" && $SelectField->TypeOfData_ID != 3) { $alter .= " NOT NULL DEFAULT '" . $SelectField->DefaultState . "'"; } elseif ($SelectField->NotNull) { $alter .= " NOT NULL"; } else { $alter .= " NULL"; } $TempText .= $alter . ", "; $insert .= "<field>INSERT INTO Field (`Class_ID`, `Field_Name`, `Description`, `TypeOfData_ID`, `Format`, `NotNull`, `Priority`, `DoSearch`, `DefaultState`, `TypeOfEdit_ID`) VALUES"; $insert .= " (%INSERT_ID%, '" . str_replace("'", "\\'", $SelectField->Field_Name) . "', '" . str_replace("'", "\\'", $SelectField->Description) . "', " . $SelectField->TypeOfData_ID . ", '" . str_replace("'", "\\'", $SelectField->Format) . "', " . $SelectField->NotNull . ", " . $SelectField->Priority . ", " . $SelectField->DoSearch . ", '" . str_replace("'", "\\'", $SelectField->DefaultState) . "', " . $SelectField->TypeOfEdit_ID . ");</field>\n"; } $insert = "</fields>"; } $TempText .= "PRIMARY KEY (`Message_ID`), "; $TempText .= "UNIQUE KEY `Sub_Class_ID` (`Sub_Class_ID`,`Message_ID`,`Keyword`), "; $TempText .= "KEY `User_ID` (`User_ID`), "; $TempText .= "KEY `LastUser_ID` (`LastUser_ID`), "; $TempText .= "KEY `Subdivision_ID` (`Subdivision_ID`), "; $TempText .= "KEY `Parent_Message_ID` (`Parent_Message_ID`) "; $TempText .= ") TYPE=MyISAM;\n"; $TempText .= $insert; $db->query("UNLOCK TABLES"); list($SystemName, $SystemColor) = nc_system_name_by_id($SystemID); $export_id_str = "-- NetCat " . $VersionNumber . " " . $SystemName . " [" . $LastPatch . "] component file, generated " . date("Y-m-d H:i:s"); $output = "<?xml version=\"1.0\"?>\n<data>\n <version>{$VersionNumber}</version>\n <export_id>{$export_id_str}</export_id>\n <class_id>{$ClassID}</class_id>"; if (isset($TempIds)) { $output .= $TempIds; } $output .= "<sql_data>\n {$TempText}</sql_data>\n"; if ($File_Mode) { $tmp_file_name = $nc_core->TMP_FOLDER . "netcat_widget_{$ClassID}.tgz"; $dump_file = nc_tgz_create($tmp_file_name, $ClassID, $nc_core->HTTP_TEMPLATE_PATH . 'widget/'); $tar_contents = file_get_contents($tmp_file_name); $output .= "<tar_data>" . base64_encode($tar_contents) . "</tar_data>\n"; } $output .= "</data>"; // все компоненты в utf-8 if (!$nc_core->NC_UNICODE) { $ret = $nc_core->utf8->win2utf($ret); } return $ret; }