query('SELECT topic_id FROM mst_topic WHERE topic=\''.$str_subject.'\' AND topic_type=\''.$str_subject_type.'\''); if ($_q->num_rows > 0) { $_d = $_q->fetch_row(); // return the subject/topic ID return $_d[0]; } return false; } if (isset($_POST['relatedterm']) AND (isset($_POST['topicID']) OR isset($_POST['search_str']))) { $relatedterm = trim($dbs->escape_string(strip_tags($_POST['relatedterm']))); $search_str = trim($dbs->escape_string(strip_tags($_POST['search_str']))); # create new sql op object $sql_op = new simbio_dbop($dbs); # curent item_id/topicID $itemID = (integer)isset($_GET['itemID'])?$_GET['itemID']:0; $vocID = (integer)isset($_GET['vocID'])?$_GET['vocID']:0; # alert sucsess add $alert_add = ''; $data['topic_id'] = $itemID; $data['vocabolary_id'] = ''; $data['rt_id'] = $relatedterm; if (!empty($_POST['topicID'])) { # a. $data['related_topic_id'] = $_POST['topicID']; } else if ($search_str AND empty($_POST['topicID'])) { // check subject $subject_id = checkSubject($search_str); if ($subject_id !== false) { $data['related_topic_id'] = $subject_id; } else { // adding new topic $topic_data['topic'] = $search_str; $topic_data['classification'] = $_POST['topicClass']; $topic_data['topic_type'] = 't'; $topic_data['input_date'] = date('Y-m-d'); $topic_data['last_update'] = date('Y-m-d'); // insert new topic to topic master table $sql_op->insert('mst_topic', $topic_data); // put last inserted ID $data['related_topic_id'] = $sql_op->insert_id; } } // data secondary vocabulary $_data['topic_id'] = $data['related_topic_id']; $_data['vocabolary_id'] = ''; $_data['related_topic_id'] = $itemID; $_data['rt_id'] = false; if ($relatedterm === 'U') { $_data['rt_id'] = 'UF'; } if($relatedterm === 'UF'){ $_data['rt_id'] = 'U'; } if ($relatedterm === 'RT') { $_data['rt_id'] = 'RT'; } if($relatedterm === 'BT'){ $_data['rt_id'] = 'NT'; } if($relatedterm === 'NT'){ $_data['rt_id'] = 'BT'; } // update mode if (isset($_POST['saveData'])) { $update = $sql_op->update('mst_voc_ctrl', $data, 'vocabolary_id='.$vocID); if ($update) { $alert_update = ''; echo $alert_update; } else { utility::jsAlert(__('Subject FAILED to Add. Please Contact System Administrator')."\n".$sql_op->error); } } else { // checking if already added $check_vc = $dbs->query('SELECT count(topic_id) FROM mst_voc_ctrl WHERE topic_id='.$data['topic_id'].' AND related_topic_id='.$data['related_topic_id']); $check_dc = $check_vc->fetch_row(); if ($check_dc[0] > 0) { // already add utility::jsAlert(__('Subject ALREADY Added in Relation!')); } else { // insert primary vocabolary if ($sql_op->insert('mst_voc_ctrl', $data)) { // insert secondary vocabolary if ($_data['rt_id']) { // insert related topic into vocabolary control $insert = $sql_op->insert('mst_voc_ctrl', $_data); if ($insert) { echo $alert_add; }else{ utility::jsAlert(__('Subject FAILED to Add. Please Contact System Administrator')."\n".$sql_op->error); } }else{ echo $alert_add; } } else { utility::jsAlert(__('Subject FAILED to Add. Please Contact System Administrator')."\n".$sql_op->error); } } } } if (isset($_GET['editTopic'])) { if (!($can_read AND $can_write)) { die('