
! script name: vproperty.d/tblpropdir
! var_topic: make an info packet class directory from a table

!A
!A NAME:
!A
!A 	External Packets from Table
!A
!A DESCRIPTION:
!A
!A 	This script creates an info packet class directory with info packets
!A 	created from a data table.  This lets you work with your data in
!A 	powerful database or spreadsheet programs, and import that data 
!A 	into an entire class of info packets that Synergy can use.
!A
!B INSTRUCTIONS:
!B
!B 	PACKET CLASS DIRECTORY: Select the class directory of the info packets
!B 	or enter the name of a new directory.
!B
!B 	OVERWRITE EXISTING PACKETS: Responding "Yes," will prompt Synergy to 
!B 	only overwrite packets in the event that the class directory already 
!B 	exists. Info packets will not be deleted if they are not listed in the 
!B 	table. 
!B
!B 	PACKET CLASS NAME: Enter the name of the info packet class. All packets
!B 	in the same class directory should have the same class name.
!B
!B 	PACKET CLASS ID NUMBER  (10000 - 100000): Enter a unique number
!B 	assigned to each info packet class.  Each packet belonging to a
!B 	specific class must have the same class number.  Packets belonging
!B 	to different classes must have different numbers.  Only one packet
!B 	of a given class number can be associated with a Synergy entity,
!B 	however, any number of different packet classes may be associated
!B 	with the same entity.
!B
!B 	PICK TABLE: Select the table that you are using to create the info
!B 	packets.  The entries in the table's Row 1 become the data field names
!B 	in the Packet. The entries in column 1 become the corresponding packet
!B 	names and packet file names.  The file name is a modified version of
!B 	the packet's name.
!B
!# see also - htdocs/help.d/property.htm
!# see also - htdocs/help.d/datatables.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: make prop class from table")

DIM Answer$[512]
DIM A$[512]
DIM Class_name$[512]
DIM Class_dir$[512]
DIM Prop_dir$[512]
DIM Filename$[512]
DIM Descr$[512]
DIM Element$[512]
DIM Name$[512]
DIM Destination$[512]
DIM Current_dir$[512]
DIM Ques$[512]
DEG

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave


Stat= NamedVarStr("properties dir",WsSystemVars,"/usr/weber/database/properties/",Prop_dir$)

Class_directory:!
DeActivateUndo
Start:!

D_label$="PACKET CLASSES"
Choice$="CLASS SELECTED"
Ques$= "PACKET CLASS DIRECTORY  List  "
Answer$= SelectDirectory(Prop_dir$,"*",Ques$,D_label$,Choice$,"",Current_dir$)
IF (ExitScript(Destination$)) THEN Leave
IF  Answer$= "CANCEL" THEN Leave
Answer$= TRIM$(Answer$)
A$= Answer$
Class_dir$= BaseNamePath(Answer$,Prop_dir$)
IF NOT DoesFileExist(A$) THEN
        CREATE DIR A$
ELSE

Overwrite=1
Stat=SetInputFormat("a1",",Y,N,")
Stat=GetValue("OVERWRITE EXISTING PACKETS  Yes or No ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "N" THEN Overwrite=0
END IF
LowerSelectBox

Name_loop:!
stat= SetInputFormat("a99","")
Stat=GetValue("PACKET CLASS NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Class_name$= Answer$


Ask_id_num:stat= SetInputFormat("n0a1",",E,")
Id_number= GetValue("CLASS ID NUMBER  (10000 - 100000)    Existing ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "E" THEN
        stat= PropClassNameList(Prop_dir$,":",2)
        GOTO Ask_id_num
END IF
IF Id_number< 10000 OR Id_number> 100000 THEN Ask_id_num


Pick_loop:!
stat= SetInputFormat("n4","")
Table1=PickEntity("PICK TABLE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Table1) THEN Pick_loop
Stat= EntityNameCheck(Table1,Element$)


RecordFunctionOn
Stat=RecordDescr("UPDATE PACKET DIRECTORY:"&Class_dir$)
V1= StringConstant(Prop_dir$)
V2= StringConstant(Class_dir$)
V3= StringConstant(FileNameString(V1,V2))
V4= StringConstant(Class_name$)
V5= FreeParameter("Class id number",Id_number)
V6= FreeParameter("Overwrite",Overwrite)
Stat= PropDirFromTable(Element$,":",V3,V4,V5,V6)
RecordFunctionOff
CloseVarRecord

GOTO Start


Leave:!
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

