1/*
2 * @progname       addsour
3 * @version        1.0
4 * @author         Stephen Dum
5 * @category
6 * @output         Modifies Database
7 * @description
8
9This script prompts for a message and adds the message along with todays date
10as a Source record on each individual and Family in the database.  It checks
11to see if the source already exists, and allows you to skip or replace an
12existing source record.  Warning, this script modifies your database, making a
13backup of your data before running this script is advised.
14*/
15
16option("explicitvars")
17
18proc main()
19{
20    print("\n")
21    print("This script will add a SOUR record to each indi and fam in your database\n")
22    print("The value will be the message you supply with todays date appended.\n")
23    print("Warning: This script modifies your database - backup your data\n",
24          "before running it -- enter abort to abort\n\n")
25    getstr(msg,"Enter Message to add to SOUR")
26    if (index(lower(msg),"abort",1)) {
27        return()
28    }
29
30    /* iterate thru each individual adding sources to end of each */
31    forindi(indiv,cnt) {
32	set(ok,"ok")
33        fornodes(indiv,n) {
34	   if (eqstr(tag(n),"SOUR")) {
35	        if (index(value(n),msg,1)) {
36		    print("Warning, ",key(indiv),": SOUR ",value(n),nl())
37		    print("Message already exists in level 1 SOUR record",nl())
38		    getstr(ok,"Press return to skip add, rep to replace,  else ok<cr>")
39		    if (index(lower(ok),"rep",1)) {
40			/* replace node */
41			detachnode(n)
42			set(n,nn)
43		    }
44		}
45	   }
46	   set(nn,n)
47	}
48	if (strlen(ok)) {
49	    print("adding msg for ",key(indiv),nl())
50	    set(s,createnode("SOUR",concat(msg," ",date(gettoday()))))
51	    addnode(s,indiv,nn)
52	    writeindi(indiv)
53	}
54    }
55    forfam(fam,cnt) {
56        fornodes(fam,n) {
57	   if (eqstr(tag(n),"SOUR")) {
58	        if (index(value(n),msg,1)) {
59		    print("Warning, ",key(fam),": SOUR ",value(n),nl())
60		    print("Message already exists in level 1 SOUR record",nl())
61		    getstr(ok,"Press return to skip add, rep to replace,  else ok<cr>")
62		    if (index(lower(ok),"rep",1)) {
63			/* replace node */
64			detachnode(n)
65			set(n,nn)
66		    }
67		}
68	   }
69	   set(nn,n)
70	}
71	if (strlen(ok)) {
72	    print("adding msg for ",key(fam),nl())
73	    set(s,createnode("SOUR",concat(msg," ",date(gettoday()))))
74	    addnode(s,fam,nn)
75	    writefam(fam)
76	}
77    }
78}
79