Exemplo n.º 1
0
 function update()
 {
     $this->load->library('m_database');
     $did = $this->input->post('id');
     $title = $this->input->post('title');
     $name = dbField('terms', 'term_id', $did, 'name');
     $slug = dbField('terms', 'term_id', $did, 'slug');
     $parent = dbField('terms', 'term_id', $did, 'term_parent');
     $json = json_encode(array('prefix' => 'event', 'title' => $title));
     updateTerms($did, "sidebar", $name, $slug, "", $parent, $json);
     echo json_encode('ok');
 }
Exemplo n.º 2
0
 function updateconfig()
 {
     $arr = "";
     foreach ($_POST as $k => $v) {
         $arr .= '"' . $k . '"' . ":" . '"' . $v . '",';
     }
     $jsonSanite = substr($arr, 0, -1);
     $jsonData = "{" . $jsonSanite . "}";
     $theme = $this->input->post('theme');
     $s = array('name' => $theme . "-template");
     $termid = $this->m_database->FieldRow('terms', $s, 'term_id');
     updateTerms($termid, "template", $theme . "-template", $theme . "-template", "", "", $jsonData);
     redirect(base_url(roleURIUser() . 'style/templates/konfigurasi') . '?v=' . $theme, 'refresh');
 }
Exemplo n.º 3
0
 function update()
 {
     $this->load->library('m_database');
     $this->load->helper('file_helper');
     $did = $this->input->post('id');
     $source = $this->input->post('source');
     $title = $this->input->post('title');
     $img = $this->input->post('img');
     $name = dbField('terms', 'term_id', $did, 'name');
     $slug = dbField('terms', 'term_id', $did, 'slug');
     $imgX = $img;
     $parent = dbField('terms', 'term_id', $did, 'term_parent');
     $json = json_encode(array('prefix' => 'images', 'title' => $title, 'source' => $source, 'image' => $imgX));
     updateTerms($did, "sidebar", $name, $slug, "", $parent, $json);
     echo json_encode('ok');
 }
Exemplo n.º 4
0
function upload_termsfile($parent_id, $domain, $has_codes, $has_descr)
{
    if (!@$_REQUEST['uploading']) {
        return null;
    }
    if (!$_FILES['import_file']['size']) {
        return array('error' => 'Error occurred during import - file had zero size');
    }
    $filename = $_FILES['import_file']['tmp_name'];
    $parsed = array();
    $row = 0;
    if (($handle = fopen($filename, "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $num = count($data);
            if ($num > 0) {
                $desc = '';
                $code = '';
                $label = substr(trim($data[0]), 0, 499);
                if (count($data) > 1) {
                    $code = substr(trim($data[1]), 0, 99);
                    if (count($data) > 2) {
                        $desc = implode(',', array_slice($data, 2));
                        $desc = substr($desc, 0, 999);
                    }
                }
                if ($label == '') {
                    $label = $code;
                }
                if ($label != '') {
                    array_push($parsed, array($code, $label, $desc, $domain, $parent_id, 1));
                    $row++;
                }
            }
        }
    }
    if ($handle) {
        fclose($handle);
    }
    if ($row == 0) {
        return array('error' => 'No appropriate line found to process in import file');
    }
    $mysqli = mysqli_connection_overwrite(DATABASE);
    $colNames = array('trm_Code', 'trm_Label', 'trm_Description', 'trm_Domain', 'trm_ParentTermID', 'trm_AddedByImport');
    $rv['parent'] = $parent_id;
    $rv['result'] = array();
    //result
    foreach ($parsed as $ind => $dt) {
        $res = updateTerms($colNames, "1-1", $dt, $mysqli);
        array_push($rv['result'], $res);
    }
    $rv['terms'] = getTerms();
    $mysqli->close();
    return $rv;
}
Exemplo n.º 5
0
             $rv['detailTypes'] = getAllDetailTypeStructures();
         }
     }
     break;
     //------------------------------------------------------------
 //------------------------------------------------------------
 case 'saveTerms':
     // Terms
     if (!array_key_exists('terms', $data) || !array_key_exists('colNames', $data['terms']) || !array_key_exists('defs', $data['terms'])) {
         error_exit("Invalid data structure sent with saveTerms method call to saveStructure.php");
     }
     $colNames = $data['terms']['colNames'];
     $rv['result'] = array();
     //result
     foreach ($data['terms']['defs'] as $trmID => $dt) {
         $res = updateTerms($colNames, $trmID, $dt, null);
         array_push($rv['result'], $res);
     }
     // slows down the performance, but we need the updated terms because Ian wishes to update terms
     // while selecting terms while editing the field type
     $rv['terms'] = getTerms();
     break;
 case 'mergeTerms':
     $retain_id = @$_REQUEST['retain'];
     $merge_id = @$_REQUEST['merge'];
     if ($retain_id == null || $merge_id == null || $retain_id == $merge_id) {
         error_exit("Invalid data structure sent with mergeTerms method call to saveStructure.php");
     }
     $colNames = $data['terms']['colNames'];
     $dt = @$data['terms']['defs'][$retain_id];
     $res = mergeTerms($retain_id, $merge_id, $colNames, $dt);
Exemplo n.º 6
0
function importVocabulary($term_id, $domain, $children = null)
{
    global $defs, $imp_terms, $terms_correspondence, $terms_correspondence_existed, $trg_terms, $excludeDuplication;
    $terms = $defs['terms'];
    if ($term_id == null) {
        //import entire list of terms
        foreach ($imp_terms[$domain] as $term_id) {
            importVocabulary($term_id, $domain, @$terms['treesByDomain'][$domain][$term_id]);
        }
    } else {
        $columnNames = $terms['commonFieldNames'];
        $idx_ccode = intval($terms['fieldNamesToIndex']["trm_ConceptID"]);
        $idx_parentid = intval($terms['fieldNamesToIndex']["trm_ParentTermID"]);
        $idx_inverseid = intval($terms['fieldNamesToIndex']["trm_InverseTermID"]);
        $idx_label = intval($terms['fieldNamesToIndex']["trm_Label"]);
        $idx_code = intval($terms['fieldNamesToIndex']["trm_Code"]);
        $idx_origin_dbid = intval($terms['fieldNamesToIndex']["trm_OriginatingDBID"]);
        $idx_origin_id = intval($terms['fieldNamesToIndex']["trm_IDInOriginatingDB"]);
        $term_import = $terms['termsByDomainLookup'][$domain][$term_id];
        //find term by concept code among local terms
        if (true || $excludeDuplication) {
            $new_term_id = findTermByConceptCode($term_import[$idx_ccode], $domain);
        } else {
            $new_term_id = null;
        }
        if ($new_term_id) {
            $terms_correspondence_existed[$term_id] = $new_term_id;
        } else {
            //if not found add new term
            //change trm_InverseTermID, trm_ParentTermID
            $term_import[$idx_parentid] = @$terms_correspondence[$term_import[$idx_parentid]];
            $term_import[$idx_inverseid] = @$terms_correspondence[$term_import[$idx_inverseid]];
            //@todo - after all terms addition?
            //get level - all terms of the same level - to search same name and codes
            if (@$term_import[$idx_parentid] && @$trg_terms['treesByDomain'][$domain][$term_import[$idx_parentid]]) {
                $lvl_src = $trg_terms['treesByDomain'][$domain][$term_import[$idx_parentid]];
            } else {
                $lvl_src = $trg_terms['treesByDomain'][$domain];
            }
            //verify that code and label is unique for the same level in target(local) db
            $term_import[$idx_code] = doDisambiguateTerms($term_import[$idx_code], $lvl_src, $domain, $idx_code);
            $term_import[$idx_label] = doDisambiguateTerms($term_import[$idx_label], $lvl_src, $domain, $idx_label);
            //fill original ids if missed
            if ($term_import[$idx_ccode] && (!$term_import[$idx_origin_dbid] || !$term_import[$idx_origin_id])) {
                $codes = explode("-", $term_import[$idx_ccode]);
                if ($codes && count($codes) == 2) {
                    $term_import[$idx_origin_dbid] = $codes[0];
                    $term_import[$idx_origin_id] = $codes[1];
                }
            }
            $res = updateTerms($columnNames, null, $term_import, null);
            if (is_numeric($res)) {
                $new_term_id = $res;
            } else {
                error_exit("Can't add term " . print_r($term_import, true) . "  " . $res);
            }
        }
        //fill $terms_correspondence
        $terms_correspondence[$term_id] = $new_term_id;
        if ($children) {
            foreach ($children as $id => $children2) {
                importVocabulary($id, $domain, $children2);
            }
        }
    }
}
Exemplo n.º 7
0
$return_res = @$_REQUEST['return_res'] ? $_REQUEST['return_res'] : "";
$need_close = false;
$local_message = "";
if (@$_REQUEST['treetype'] == null) {
    $local_message = "Terms domain is not defined";
} else {
    if ($parent_id == null) {
        $local_message = "Parent vocabulary is not defined";
    } else {
        if (@$_REQUEST['process'] == "action") {
            if (@$_REQUEST['name'] == null || $_REQUEST['name'] == "") {
                $local_message = "<div style='color:red'>Term (label) is mandatory - you cannot have a term without a label representing the term</div>";
            } else {
                $mysqli = mysqli_connection_overwrite(DATABASE);
                //artem's
                $res = updateTerms(array('trm_Label', 'trm_Description', 'trm_Domain', 'trm_ParentTermID', 'trm_Status', 'trm_Code'), $parent_id . "-1", array($_REQUEST['name'], $_REQUEST['description'], $_REQUEST['treetype'], $parent_id == 0 ? null : $parent_id, "open", $_REQUEST['code']), $mysqli);
                $mysqli->close();
                if (is_numeric($res)) {
                    $local_message = "<script>top.HEURIST.terms = \n" . json_format(getTerms(), true) . ";\n</script>" . "<span style='color:green; padding-left:50px;'>Added " . ($parent_id == 0 ? "vocabulary" : "term") . ": <b>" . $term_name . "</b></span>";
                    if ($return_res == "") {
                        $return_res = $parent_id == 0 ? $res : "ok";
                    }
                    if ($parent_id == 0) {
                        $parent_id = $res;
                    }
                    $term_name = "";
                    $term_desc = "";
                    $term_code = "";
                    $need_close = @$_REQUEST['close_on_save'] == 1;
                } else {
                    $local_message = "<span style='color:red; padding-left:10px; font-weight:bold;'>" . $res . "</span>";
Exemplo n.º 8
0
function upload_termsfile($parent_id, $domain, $has_codes, $has_descr)
{
    if (!@$_REQUEST['uploading']) {
        return null;
    }
    if (!$_FILES['import_file']['size']) {
        return array('error' => 'Error occurred during import - file had zero size');
    }
    $filename = $_FILES['import_file']['tmp_name'];
    $parsed = array();
    $row = 0;
    if (($handle = fopen($filename, "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $num = count($data);
            if ($num > 0) {
                if ($has_codes) {
                    $code = substr(trim($data[0]), 0, 99);
                    $ind = 1;
                } else {
                    $code = '';
                    $ind = 0;
                }
                if ($num > $ind) {
                    $label = substr(trim($data[$ind]), 0, 399);
                    $len = strlen($label);
                    if ($len > 0 && $len < 400) {
                        $desc = "";
                        if ($has_descr) {
                            $ind++;
                            for ($c = $ind; $c < $num; $c++) {
                                if ($c > 1) {
                                    $desc = $desc . ",";
                                }
                                $desc = $desc . $data[$c];
                            }
                        }
                        array_push($parsed, array($code, $label, substr($desc, 0, 999), $domain, $parent_id, 1));
                        $row++;
                    }
                }
            }
        }
    }
    if ($handle) {
        fclose($handle);
    }
    if ($row == 0) {
        return array('error' => 'No one appropriate line found');
    }
    $db = mysqli_connection_overwrite(DATABASE);
    //artem's
    $colNames = array('trm_Code', 'trm_Label', 'trm_Description', 'trm_Domain', 'trm_ParentTermID', 'trm_AddedByImport');
    $rv['parent'] = $parent_id;
    $rv['result'] = array();
    //result
    foreach ($parsed as $ind => $dt) {
        $res = updateTerms($colNames, "1-1", $dt, $db);
        array_push($rv['result'], $res);
    }
    $rv['terms'] = getTerms();
    $db->close();
    return $rv;
}
Exemplo n.º 9
0
/**
* Merge two terms in defTerms and update recDetails
*
    1. change parent id for all children terms
    2. delete term $merge_id
    3. update entries in recDetails for all detail type enum or reltype
    4. update term $retain_id

* @param mixed $retain_id
* @param mixed $merge_id
*/
function mergeTerms($retain_id, $merge_id, $colNames, $dt)
{
    global $mysqli;
    $ret = array();
    //1. change parent id for all children terms
    $query = "update defTerms set trm_ParentTermID = {$retain_id} where trm_ParentTermID = {$merge_id}";
    $res = $mysqli->query($query);
    if ($mysqli->error) {
        $ret['error'] = "SQL error - cannot change parent term for {$merge_id} from defTerms table: " . $mysqli->error;
        return $ret;
    }
    //2. update entries in recDetails for all detail type enum or reltype
    $query = "update recDetails, defDetailTypes set dtl_Value=" . $retain_id . " where (dty_ID = dtl_DetailTypeID ) and " . " (dty_Type='enum' or dty_Type='relationtype') and " . " (dtl_Value=" . $merge_id . ")";
    $res = $mysqli->query($query);
    if ($mysqli->error) {
        $ret['error'] = "SQL error in mergeTerms updating record details " . $mysqli->error;
        return $ret;
    }
    //3. delete term $merge_id
    $query = "delete from defTerms where trm_ID = {$merge_id}";
    $res = $mysqli->query($query);
    if ($mysqli->error) {
        $ret['error'] = "SQL error deleting term {$merge_id} from defTerms table: " . $mysqli->error;
        return $ret;
    }
    //4. update term $retain_id
    return updateTerms($colNames, $retain_id, $dt, null);
}
Exemplo n.º 10
0
 function editlink()
 {
     $title = $this->input->post('title');
     $url = $this->input->post('url');
     $menu = $this->input->post('menu');
     $pos = $this->input->post('pos');
     $parent = $this->input->post('parent');
     $slug = stringCreateSlug($title);
     $jsondata = json_encode(array('create' => dateNow(TRUE), 'relasi' => 'link', 'value' => $url));
     //updateTerms($menu,'menu_'.$pos,$title,$slug."_menu","",$parent,$jsondata);
     $tipe = "menu_" . $pos . "_" . getThemeActive();
     $catSlug = dbField('terms', 'term_id', $menu, 'slug');
     updateTerms($menu, $tipe, $title, $catSlug, "", $parent, $jsondata);
     echo json_encode('ok');
 }
Exemplo n.º 11
0
 function updateTags($termid, $name, $slug, $description = '', $parent = '0', $termdata)
 {
     return updateTerms($termid, "tag", $name, $slug, $description, $parent, $termdata);
 }