Ejemplo n.º 1
0
function generate_Logic($projname, $rt_toexport, $rt_toexport_toplevel, $rt_geoenabled)
{
    global $rtStructs, $dtTerms, $supported;
    //need to create substitutes
    $TEMPLATE_EVENTS = '';
    //list of recctypes and events
    $TEMPLATE_DEFAULTVALUES = '';
    //default values and reset link fields
    $TEMPLATE_TOVALIDATE = '';
    //list of rectypes to validate
    $TEMPLATE_FIELDS_TOVALIDATE = '';
    //list of fields to validate
    $TEMPLATE_RELATED_INIT = '';
    $TEMPLATE_RELATED_SAVE = '';
    $TEMPLATE_SELECTORS = '';
    //enums
    $TEMPLATE_MAPCOLORS = '';
    //list of mapenabled rectypes and colors
    $TEMPLATE_INIT_SYNC_AND_GPS = '';
    $startSync = @$_REQUEST['ct1'] == "1";
    $startInternalGPS = @$_REQUEST['ct2'] == "1";
    $hasControlExternalGPS = @$_REQUEST['ct3'] == "1";
    $hasControlTracklog = @$_REQUEST['ct4'] == "1";
    $hasMapTab = @$_REQUEST['mainmt'] == "1";
    $colors = array('BLUE', 'DKGRAY', 'GREEN', 'MAGENTA', 'CYAN', 'LTGRAY', 'RED', 'YELLOW');
    $colors_idx = 0;
    $ind_rt_description = $rtStructs['typedefs']['commonNamesToIndex']['rty_Description'];
    $int_rt_dt_type = $rtStructs['typedefs']['dtFieldNamesToIndex']["dty_Type"];
    //not used $int_rt_termtree = $rtStructs['typedefs']['dtFieldNamesToIndex']["rst_FilteredJsonTermIDTree"];
    //not used $int_rt_termtree_dis = $rtStructs['typedefs']['dtFieldNamesToIndex']["dty_TermIDTreeNonSelectableIDs"];
    $int_dt_repeat = $rtStructs['typedefs']['dtFieldNamesToIndex']["rst_MaxValues"];
    $int_rt_disp_name = $rtStructs['typedefs']['dtFieldNamesToIndex']["rst_DisplayName"];
    $idx_rst_pointers = $rtStructs['typedefs']['dtFieldNamesToIndex']["rst_PtrFilteredIDs"];
    $idx_rst_required = $rtStructs['typedefs']['dtFieldNamesToIndex']["rst_RequirementType"];
    $idx_rst_defaultvalue = $rtStructs['typedefs']['dtFieldNamesToIndex']["rst_DefaultValue"];
    $event_section = '';
    // Loop through each of the record types (ArchEntTypes) and output fields
    $rectyps = is_array($rt_toexport) ? $rt_toexport : explode(",", $rt_toexport);
    foreach ($rectyps as $rt) {
        $rtname = $rtStructs['names'][$rt];
        $rtnamex = getProperName($rtname, $rt);
        $details = $rtStructs['typedefs'][$rt]['dtFields'];
        if (!$details) {
            /*****DEBUG****/
            //error_log("3. No details defined for RT#".$rt."  ".$rtname);
            continue;
        }
        $defaultvalue_section = '';
        $reset_link_section = '';
        $TEMPLATE_EVENTS .= 'rectypeToEntity.add(new NameValuePair("' . $rtnamex . '", "' . $rtname . '"));
';
        if (in_array($rt, $rt_geoenabled)) {
            $TEMPLATE_EVENTS .= 'rectypeToEntityGeo.add(new NameValuePair("' . $rtnamex . '", "' . $rtname . '"));
';
        }
        if (in_array($rt, $rt_toexport_toplevel)) {
            $TEMPLATE_EVENTS .= 'rectypeToEntityMain.add(new NameValuePair("' . $rtnamex . '", "' . $rtname . '"));
';
        }
        $headername_uids = $rtnamex . '_uids';
        //init navigation
        $event_section .= '
addOnEvent("' . $rtnamex . '", "show", "addNavigationButtons(\\"' . $rtnamex . '\\")");';
        // Show edit form
        $event_section .= '
addOnEvent("' . $rtnamex . '", "show", "onShowEditForm(\\"' . $rtnamex . '\\")");';
        // Enable auto saving  - disable 2016-03-08
        //        $event_section .= '
        //addOnEvent("'.$rtnamex.'", "show", "saveEntity(\"'.$rtnamex.'\", false, false)");';
        $load_related_part = '';
        $save_related_part = '';
        $descr = $rtStructs['typedefs'][$rt]['commonFields'][$ind_rt_description];
        $hasattachfile = false;
        $headername = $rtnamex . "/" . $rtnamex . '_General_Information';
        //first tab implied if no header at top of record
        $cnt_pertab = 0;
        $issectab = false;
        $mandatory_attributes = '';
        // Output for each field (attribute) in the record type
        foreach ($details as $dtid => $detail) {
            $is_repeatable = $detail[$int_dt_repeat] != '1';
            $default_value = $detail[$idx_rst_defaultvalue];
            $dt_type = $detail[$int_rt_dt_type];
            $dtdisplayname = $detail[$int_rt_disp_name];
            // the display name for this record type
            $dtdisplaynamex = getProperName($dtdisplayname, $rt, $dtid);
            if ($dt_type == 'separator') {
                // note, separator is classed as unsupported b/c it is not a data value
                /* art temp 2014-02-28
                                if($hasattachfile){  //add events to view attached files
                                     $eventsection .= '
                onEvent("'.$headername.'/viewattached", "click", "viewArchEntAttachedFiles(entityId)");';
                                }
                */
                $hasattachfile = false;
                //new tab
                if ($issectab || $cnt_pertab > 0) {
                    //show save button on every tab
                    $event_section .= '
addOnEvent("' . $headername . '/Update", "delayclick", "saveEntity(\\"' . $rtnamex . '\\", true, false)");';
                    $headername = $rtnamex . "/" . $rtnamex . '_' . $dtdisplaynamex;
                    $issectab = true;
                    $cnt_pertab = 0;
                }
            }
            if (!in_array($dt_type, $supported)) {
                continue;
            }
            if ($dt_type == 'file') {
                $ftype = detectFileType($dtdisplayname);
                $actionlabel = $ftype[0];
                $filetype = $ftype[1];
                if ($filetype == 'video') {
                    $action = 'attachVideoTo';
                } else {
                    if ($filetype == 'sound') {
                        $action = 'attachAudioTo';
                    } else {
                        if ($filetype == 'camera') {
                            $action = 'attachPictureTo';
                        } else {
                            //if ($filetype == 'file')
                            $action = 'attachFileTo';
                            $hasattachfile = true;
                        }
                    }
                }
                $event_section .= '
addOnEvent("' . $headername . '/attach' . $dtdisplaynamex . '", "click", "' . $action . '(\\"' . $headername . '/' . $dtdisplaynamex . '\\")");';
            } else {
                if ($dt_type == 'date') {
                    if ($default_value == 'today') {
                        $defaultvalue_section .= '
    setTimestamp( "' . $headername . '/' . $dtdisplaynamex . '" );';
                    } else {
                        $event_section .= '
addOnEvent("' . $headername . '/attach' . $dtdisplaynamex . '", "click", "pickupDate(\\"' . $headername . '/' . $dtdisplaynamex . '\\")");';
                    }
                } else {
                    if ($dt_type == 'enum') {
                        $is_hierarchy = @$rtStructs['typedefs'][$rt]['dtFields'][$dtid]['is_hierarchy'] == true;
                        $termsCount = @$rtStructs['typedefs'][$rt]['dtFields'][$dtid]['termdepth'];
                        if ($is_hierarchy && !($is_repeatable && $termsCount < 13)) {
                            $makeVocab = '
                            populateHierarchicalDropDown("' . $headername . '/' . $dtdisplaynamex . '", "' . prepareText($dtdisplayname) . '");
';
                        } else {
                            if ($is_repeatable) {
                                $action = 'populateCheckBoxGroup';
                            } else {
                                if ($termsCount < 5) {
                                    $action = 'populateRadioGroup';
                                } else {
                                    $action = 'populateDropDown';
                                }
                            }
                            // makeVocab method
                            $makeVocab = '
                            fetchAll("select vocabid, vocabname from vocabulary join attributekey using (attributeid) where attributename = \'' . prepareText($dtdisplayname) . '\' order by vocabcountorder",
                                  new FetchCallback() {
                                    onFetch(result) {
                                    ' . $action . '("' . $headername . '/' . $dtdisplaynamex . '", result);
                                    }
                            });
                            ';
                        }
                        // Add to load selectors
                        $TEMPLATE_SELECTORS .= $makeVocab;
                        //$TEMPLATE_SELECTORS .= ''.($action.'("'.$headername.'/'.$dtdisplaynamex.'", makeVocab("'.prepareText($dtdisplayname).'"));'); // OLD
                    } else {
                        if ($dt_type == 'resource') {
                            $dt_pointers = $detail[$idx_rst_pointers];
                            $dt_pointers = explode(",", $dt_pointers);
                            if (count($dt_pointers) > 0) {
                                //ignore unconstrained
                                foreach ($dt_pointers as $rt2) {
                                    $rtname2 = $rtStructs['names'][$rt2];
                                    $rtnamex2 = getProperName($rtname2, $rt2);
                                    $event_section .= '
addOnEvent("' . $headername . '/' . $dtdisplaynamex . '_browse_' . $rtnamex2 . '", "click", "startSelectEntity(\\"' . $rtnamex2 . '\\", \\"' . $headername . '/' . $dtdisplaynamex . '\\")");';
                                }
                                //for
                                $event_section .= '
addOnEvent("' . $headername . '/' . $dtdisplaynamex . '_clearPointer", "click", "clearPointer(\\"' . $headername . '/' . $dtdisplaynamex . '\\")");';
                                $load_related_part .= ($load_related_part ? 'else' : '') . '
                    if("' . $dtdisplaynamex . '".equals(attrName)){
                        fillPointer("' . $headername . '/' . $dtdisplaynamex . '", attrVal);
                    }';
                                $save_related_part .= '
                        saveRelation("has' . $dtdisplaynamex . '", uuid, "' . $headername . '/' . $dtdisplaynamex . '");
                    ';
                                $reset_link_section .= '
                    clearPointerUI("' . $headername . '/' . $dtdisplaynamex . '");';
                                if ($detail[$idx_rst_required] == "required") {
                                    $mandatory_attributes .= ' 
       f.add(fieldPair("' . $headername_uids . '/' . $dtdisplaynamex . '_UID", "' . prepareText($dtdisplayname) . '", true, null));';
                                }
                            }
                        } else {
                            if (($dt_type == 'freetext' || $dt_type == 'blocktext') && !is_empty($default_value)) {
                                $defaultvalue_section .= '
    setFieldValue( "' . $headername . '/' . $dtdisplaynamex . '", "' . mysql_real_escape_string($default_value) . '" );';
                            } else {
                                if (($dt_type == 'float' || $dt_type == 'integer' || $dt_type == 'year') && is_numeric($default_value)) {
                                    $defaultvalue_section .= '
    setFieldValue( "' . $headername . '/' . $dtdisplaynamex . '", "' . $default_value . '" );';
                                }
                            }
                        }
                    }
                }
            }
            if (!($dt_type == 'resource' || $dt_type == 'file') && $detail[$idx_rst_required] == "required") {
                $mandatory_attributes .= '
       f.add(fieldPair("' . $headername . '/' . $dtdisplaynamex . '", "' . prepareText($dtdisplayname) . '", true, null));';
            }
            $cnt_pertab++;
        }
        //for detail types
        /* art temp 2014-02-28
                if($hasattachfile){  //add events to view attached files
                      $eventsection .= '
        onEvent("'.$headername.'/viewattached", "click", "viewArchEntAttachedFiles(entityId)");';
                }
        */
        $compare_type = '
            if("' . $rtnamex . '".equals(rectypeTab)){
';
        if ($load_related_part != '') {
            $TEMPLATE_RELATED_INIT .= $compare_type . $load_related_part . '
            }
';
            $TEMPLATE_RELATED_SAVE .= $compare_type . $save_related_part . '
                return;
            }
';
        }
        if (in_array($rt, $rt_geoenabled)) {
            $headername = $rtnamex . "/" . $rtnamex . '_gps_location';
            if ($hasMapTab) {
                $event_section .= '
addOnEvent("' . $headername . '/AttachGeometry", "click", "doAttachGeometry(\\"' . $rtnamex . '\\")");';
            }
            $event_section .= '
addOnEvent("' . $headername . '/Take_From_GPS", "click", "takePoint(\\"' . $rtnamex . '\\", \\"' . $headername . '/\\")");';
            $TEMPLATE_MAPCOLORS .= '
  rectypeToColor.put("' . $rtnamex . '", Color.' . $colors[$colors_idx] . ');';
            $colors_idx++;
            if ($colors_idx >= count($colors)) {
                $colors_idx = 0;
            }
        }
        //show ALL save buttons on the last tab
        $event_section .= '
addOnEvent("' . $headername . '/Update", "delayclick", "saveEntity(\\"' . $rtnamex . '\\", true, false)");
addOnEvent("' . $headername . '/UpdateAndClose", "delayclick", "saveEntity(\\"' . $rtnamex . '\\", true, true)");
addOnEvent("' . $headername . '/Delete", "delayclick", "deleteEntity(\\"' . $rtnamex . '\\")");
';
        $compare_type = '
 if("' . $rtnamex . '".equals(rectypeTab)){
';
        if ($defaultvalue_section != '' || $reset_link_section != '') {
            $TEMPLATE_DEFAULTVALUES .= $compare_type . $reset_link_section . $defaultvalue_section . '  
                return;
            }';
        }
        if ($mandatory_attributes != '') {
            $TEMPLATE_FIELDS_TOVALIDATE .= $compare_type . $mandatory_attributes . ' }';
            $TEMPLATE_TOVALIDATE .= '
 tabgroupsToValidate.add("' . $rtnamex . '");';
        }
    }
    //for record types
    if ($hasMapTab) {
        $TEMPLATE_MAPCOLORS .= '
//        
mapRefresh(){
    refreshMap("control/map/map");
    onClearMap();
}
mapInit();';
    } else {
        $TEMPLATE_MAPCOLORS .= '
mapRefresh(){ 
}';
    }
    $TEMPLATE_EVENTS .= $event_section;
    $TEMPLATE_HEADER = '
/******
 FAIMS Logic File generated by Heurist Vsn ' . HEURIST_VERSION . ', ' . date('l jS \\of F Y h:i:s A') . '
 Database: ' . DATABASE . '   Heurist user:'******'
 ******/
 ';
    $out = file_get_contents('templates/ui_logic.bsh');
    $out = str_replace('{{TEMPLATE_HEADER}}', $TEMPLATE_HEADER, $out);
    $out = str_replace('{{TEMPLATE_EVENTS}}', $TEMPLATE_EVENTS, $out);
    $out = str_replace('{{TEMPLATE_DEFAULTVALUES}}', $TEMPLATE_DEFAULTVALUES, $out);
    $out = str_replace('{{TEMPLATE_FIELDS_TOVALIDATE}}', $TEMPLATE_FIELDS_TOVALIDATE, $out);
    $out = str_replace('{{TEMPLATE_TOVALIDATE}}', $TEMPLATE_TOVALIDATE, $out);
    $out = str_replace('{{TEMPLATE_RELATED_INIT}}', $TEMPLATE_RELATED_INIT, $out);
    $out = str_replace('{{TEMPLATE_RELATED_SAVE}}', $TEMPLATE_RELATED_SAVE, $out);
    $out = str_replace('{{TEMPLATE_SELECTORS}}', $TEMPLATE_SELECTORS, $out);
    $out = str_replace('{{TEMPLATE_MAPCOLORS}}', $TEMPLATE_MAPCOLORS, $out);
    if ($startSync) {
        // there are start/stop synch controls on the interface
        $TEMPLATE_INIT_SYNC_AND_GPS = '
            setFileSyncEnabled(true); 
            setSyncEnabled(true);
        ';
    }
    if ($startInternalGPS) {
        $TEMPLATE_INIT_SYNC_AND_GPS .= '
            startInternalGPS();
            showToast("{Internal_GPS_Enabled}");
            updateGPSDiagnostics();';
    }
    $out = str_replace('{{HASCONTROL_GPSEXT}}', $hasControlExternalGPS ? 'true' : 'false', $out);
    $out = str_replace('{{TEMPLATE_INIT_SYNC_AND_GPS}}', $TEMPLATE_INIT_SYNC_AND_GPS, $out);
    // Feb 2014: Brian says tracklog requires extra logic which is not yet available, so the option
    //           to switch this section on has been removed from the export interface
    if (false && $hasControlTracklog) {
        $out = $out . '
/*** TRACKLOG ***/
onEvent("control/gps/starttrackingtime", "click", "startTrackingGPS(\\"time\\", 10, \\"saveTimeGPSTrack()\\")");
onEvent("control/gps/starttrackingdistance", "click", "startTrackingGPS(\\"distance\\", 10, \\"saveDistanceGPSTrack()\\")");
onEvent("control/gps/stoptracking", "click", "stopTrackingGPS()");

saveTimeGPSTrack() {
    List attributes = createAttributeList();
    attributes.add(createEntityAttribute("gps_type", "time", null, null, null));
    saveGPSTrack(attributes);
}

saveDistanceGPSTrack() {
    List attributes = createAttributeList();
    attributes.add(createEntityAttribute("gps_type", "distance", null, null, null));
    saveGPSTrack(attributes);
}

saveGPSTrack(List attributes) {
    position = getGPSPosition();
    if (position == null) return;

    attributes.add(createEntityAttribute("gps_user", "" + user.getUserId(), null, null, null));
    attributes.add(createEntityAttribute("gps_timestamp", "" + getCurrentTime(), null, null, null));
    attributes.add(createEntityAttribute("gps_longitude", "" + position.getLongitude(), null, null, null));
    attributes.add(createEntityAttribute("gps_latitude", "" + position.getLatitude(), null, null, null));
    attributes.add(createEntityAttribute("gps_heading", "" + getGPSHeading(), null, null, null));
    attributes.add(createEntityAttribute("gps_accuracy", "" + getGPSEstimatedAccuracy(), null, null, null));

    positionProj = getGPSPositionProjected();
    Point p = new Point(new MapPos(positionProj.getLongitude(), positionProj.getLatitude()), null, (PointStyle) null, null);
    ArrayList l = new ArrayList();
    l.add(p);

    saveArchEnt(null, "gps_track", l, attributes);
}
';
    }
    return $out;
}
Ejemplo n.º 2
0
        } else {
            $column->columnEncodingType = 'UNCODED_VALUE';
        }
        /* @todo - to understand what does it mean
           $column->codingSheetRef = '';
           $column->delimiterValue = '';
           $column->mappingColumn = '';
           $column->measurementUnit = '';
           $column->name = '';
           $column->length = '';
           */
        $column->description = $detail[2];
        $column->displayName = $detail[1];
        $column->ignoreFileExtension = 'false';
        $column->mappingColumn = 'false';
        $column->name = $detail[1] ? getProperName($detail[1]) : 'noname' . $cnt;
        $column->visible = 'true';
        //ENUM('relmarker','enum','relationtype','resource','file','separator','calculated','fieldsetmarker','urlinclude')
        $cnt++;
    }
    //foreach
    $dataTable->description = $rectypedef[1];
    $dataTable->name = 'H4_' . HEURIST_DBNAME . '_rectype_' . $rt;
    $metadata_content = utf8_encode($meta->asXML());
    file_put_contents($rtfolder . "/dataset.xml", $metadata_content);
    //../ROOT/WEB-INF/lib/*:.
    $batch = $batch . "\n java -cp  org.tdar.utils.CommandLineAPITool -http -username {$fusername} -password {$fpwd} -file " . $rtfolder . "/ -host " . $host . " -projectid " . $projectId;
    $folders = $rtfolder . "/" . ($folders != null ? "," : "") . $folders;
    addRegistration("Dataset", $rtfolder . "/dataset.xml", $metadata_content, $filename, $rt);
    //break;
}