: !/bin/sh
# populate mobile config table from the Directory
#SDATE="$1"
#EDATE="$2"

today=`date "+%d/%m/%Y"`

SDATE="01/01/2010"

if [ -n "$1" ]; then
	outfile="$1"
else
	outfile="mobconf.unl"
fi

#-------------------------------
# get from tbs 
tmpfile1="/tmp/popmob1.$$"
cp /dev/null "$tmpfile1"
cp /dev/null "$outfile"

# get tbs person service list data
gettbspersonservicelist "$tmpfile1"


awk -F '|' -v"SDATE=$SDATE" -v "today=$today" '
function sanetrim(s)
{
	sub(/^[ \t]*/,"",s)
	sub(/[ \t]*$/,"",s)
	gsub(/\047/,"`",s)
	gsub(/\"/,"",s)
	return s
}

{
	f = 0
	PersonID = sanetrim($++f)
	Person = sanetrim($++f)
	ServiceIDID = sanetrim($++f)
	ServiceID = sanetrim($++f)
	ShipTo = sanetrim($++f)
	FullName = sanetrim($++f)

	# skip if not a mobile
	if ( match(ServiceID,/^04..-......$/) <= 0 ) 
		next

	mobile = substr(ServiceID,1,2) substr(ServiceID,4)
	dirID = "Person" PersonID

	recordno = NR
	sid = mobile
	sidmainttype = "Mobile_phones"
	sdate = SDATE
	edate = ""
	directoryid = dirID
	grid = ""
	datatype = "0"
	serviceproviderdir = ""
	carriercode = "x"
	grname1 = ""
	grname3 = ""
	surname = Person
	firstname =  ""
	manufacturer =  ""
	model =  ""
	servicetype = ""
	dataplan = ""

	# getSIDMAINTconf format
	printf("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|\n",
		 recordno, sid, sidmainttype, sdate, edate,
		 directoryid, grid, datatype, serviceproviderdir, carriercode,
		 grname1, grname3, surname, firstname,
		 manufacturer, model, servicetype, dataplan)

}
' < "$tmpfile1" >"$outfile"

rm -f "$tmpfile1"

exit 0