Random Bits of Open Code

Check-in [d2888a0bef]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Lots of cleanup in multiapp
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d2888a0beff5a3e6af1522f9b825d5b006a60f11
User & Date: matt 2018-08-07 05:42:23
Context
2018-08-07
22:08
nada check-in: aa8a1b0e9f user: mrwellan tags: trunk
05:42
Lots of cleanup in multiapp check-in: d2888a0bef user: matt tags: trunk
2018-08-06
18:23
set area's last updated to curr time - 1 check-in: 663fdaecef user: pjhatwal tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

a3d/testbox/a3d.scm became a symlink.

megatest_cgisetup/cgi-bin/models became a symlink.

megatest_cgisetup/cgi-bin/pages became a symlink.

Changes to multiapp/apps/learn-teach/learn-teach.scm.

299
300
301
302
303
304
305
306



307



308
309
310
311
312
313
314
...
404
405
406
407
408
409
410

411
412
413
414

415


416
417
418
419
420
421
422
...
427
428
429
430
431
432
433
434











435

436
437
438
439
440
441

442
443
444
445



446
447
448
449

450
451
452
453
454
455
456
457
458
459






460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478




479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
...
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
...
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
...
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
...
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
...
810
811
812
813
814
815
816

817
818
819



820
821
822

823
824
825
826
827
828
829
...
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
...
899
900
901
902
903
904
905

906
907
908
909
910
911
912
913

914
915
916
917

918
919
920
921

922
923
924
925
926
927
928
...
942
943
944
945
946
947
948
949
950
951
952
953
954

955
956
957

958
959
960
961
962
963
964
  (let ((del-pkts (get-del-pkts)))
    (pkts:with-queue-db
     learn-teach-pkts-dir
     (lambda (pdb)
       (for-each
	(lambda (P)
	  (dbi:exec pdb "DELETE FROM pkts WHERE uuid=?;" P)
	  (delete-file* (conc learn-teach-pkts-dir "/" P ".pkt"))



	  (print "Removed pkt " P ".pkt"))



	(map (lambda (x)
	       (alist-ref 'parent x)) ;; we are removing the PARENTS!
	     del-pkts))))))

(define (get-del-pkts)
  (let ((del-pkts (pkts:with-queue-db
		   learn-teach-pkts-dir
................................................................................

(define valid-levels '("intro" "intermediate" "advanced" "expert" "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX" "X"))

(define (valid-level level)
  (string-match "^[a-zA-Z0-9\\-_]+$" level))

(define (save-category-subject my-subjects-tree my-subjects category-edit-box subject-edit-box level-edit-box details-edit-box data)

  (let* ((category (iup:attribute category-edit-box "VALUE"))
	 (subject  (iup:attribute subject-edit-box  "VALUE"))
	 (level    (iup:attribute level-edit-box    "VALUE"))
	 (details  (iup:attribute details-edit-box  "VALUE"))

	 (my-id    (get-my-id)))


    (if (valid-category category)
	(if (valid-subject subject)
	    (if (valid-level level)
		(let* ((plist `((app      . "tnl")
				(person   . ,my-id)
				(category . ,category)
				(name     . ,subject)
................................................................................
		  (get-and-fill-my-subjects my-subjects-tree my-subjects my-id data)
		  (for-each (lambda (x)
			      (iup:attribute-set! x "BGCOLOR" "255 255 255"))
			    (list level-edit-box subject-edit-box category-edit-box)))
		(iup:attribute-set! level-edit-box "BGCOLOR" "255 200 255"))
	    (iup:attribute-set! subject-edit-box "BGCOLOR" "255 200 255"))
	(iup:attribute-set! category-edit-box "BGCOLOR" "255 200 255"))))












(define (delete-category-subject my-subjects-tree my-subjects category-edit-box subject-edit-box level-edit-box details-edit-box data)

  (let* ((category (iup:attribute category-edit-box "VALUE"))
	 (subject  (iup:attribute subject-edit-box  "VALUE"))
	 (level    (iup:attribute level-edit-box    "VALUE"))
	 (details  (iup:attribute details-edit-box  "VALUE"))
	 (my-id    (get-my-id))
	 (pkt      (get-subject-matching category subject level my-id)))

    (if pkt
	(let* ((plist `((app      . "tnl")
			(person   . ,my-id)
			(parent   . ,(alist-ref 'Z pkt)))))



	  (pkts:write-alist->pkt learn-teach-pkts-dir plist pktspec: pkt-spec ptype: 'del)
	  (apply-del-pkts)
	  (load-pkts)
	  (get-and-fill-my-subjects my-subjects-tree my-subjects my-id data)))))


;; (use trace)(trace-call-sites #t)(trace delete-category-subject get-subject-matching pkts:write-alist->pkt apply-del-pkts)

(define (get-add-ht ht-in key)
  (let ((ht (hash-table-ref/default ht-in key #f)))
    (if ht
	ht
	(let ((ht (make-hash-table)))
	  (hash-table-set! ht-in key ht)
	  ht))))







;; fill in the time-slots with my time-slots
;;
(define (get-and-fill-my-subjects my-subjects-tree my-subjects user-name data #!key (update-tree #t))
  (let* ((entries  (get-add-ht data 'my-subjects))
	 (my-dpkts (read-my-subjects user-name))
	 (my-apkts (map (lambda (x)
			  (pkts:dpkt->alist x pkt-spec))
			my-dpkts))
	 (rownum   1))
    (for-each
     (lambda (pkt)
       (let* ((category (alist-ref 'category pkt))
	      (subject  (alist-ref 'name     pkt))
	      (level    (alist-ref 'level    pkt))
	      (details  (alist-ref 'details  pkt))
	      (Z        (alist-ref 'Z pkt))
	      (path     `(,category ,subject ,level))
	      (tpath    (conc category "/" subject "/" level)))




	 (if (and update-tree
		  (not (hash-table-exists? entries tpath)))
	     (begin
	       (hash-table-set! entries tpath #t)
	       (iup:attribute-set! my-subjects (conc rownum ":0") Z)
	       (iup:attribute-set! my-subjects (conc rownum ":1") category)
	       (iup:attribute-set! my-subjects (conc rownum ":2") subject)
	       (iup:attribute-set! my-subjects (conc rownum ":3") level)
	       (iup:attribute-set! my-subjects (conc rownum ":4") details)
	       (tree-add-node my-subjects-tree "Subjects" path)))
	 (set! rownum (+ rownum 1))))
     my-apkts)
    (iup:attribute-set! my-subjects "FITTOTEXT" "C1")
    (iup:attribute-set! my-subjects "FITTOTEXT" "C2")
    (iup:attribute-set! my-subjects "FITTOTEXT" "C3")
    ;; (iup:attribute-set! my-subjects "FITTOTEXT" "C4")
    (iup:attribute-set! my-subjects "REDRAW" "YES")
    my-subjects))
................................................................................
			(iup:attribute-set! sessions-matrix (conc rownum ":2") date)
			(iup:attribute-set! sessions-matrix (conc rownum ":3")
					    (time->day (string->time date "%Y/%m/%d")))
			(iup:attribute-set! sessions-matrix (conc rownum ":4") time)
			(iup:attribute-set! sessions-matrix (conc rownum ":5") name)
			(iup:attribute-set! sessions-matrix (conc rownum ":6") level)
			(iup:attribute-set! sessions-matrix (conc rownum ":7") person)
			(iup:attribute-set! sessions-matrix (conc rownum ":9") tot)
			(iup:attribute-set! sessions-matrix (conc rownum ":10") (hash-table-ref/default votes my-id 0))
			(iup:attribute-set! sessions-matrix (conc rownum ":11") details)
			(set! rownum (+ rownum 1))))
		  (if (and update-tree
			   (not (hash-table-exists? entries tpath)))
		      (begin
			;; (print "path: " path " tpath: " tpath)
			(hash-table-set! entries tpath (cons spkt tpkt))
			(tree-add-node subjects-tree "Subjects" path)
................................................................................
  (state      (iup:label size: "120x" expand: "HORIZONTAL"))
  (votes      (iup:label size: "120x" expand: "HORIZONTAL"))
  (myvote     (iup:label size: "120x" expand: "HORIZONTAL"))
  (votebutton #f);; (iup:button "Yes"))
  (form       #f))

(define (heading-label val)
  (iup:label val size: "50x"))

(define-inline (set-label! lbl value)
  (iup:attribute-set! lbl "TITLE" (conc value))
  (iup:attribute-set! lbl "FGCOLOR" "055 155 055")
  (iup:attribute-set! lbl "REDRAW" "ALL")) ;; convert numbers, symbols etc. to strings

(define (setup-vote-form vf)
................................................................................
       (iup:gridbox
	numdiv: 4
	expand: "YES"
	;; expandchildren: "HORIZONTAL"
	(heading-label "Category:")  (vf-category vf)         (heading-label "Level:")      (vf-level       vf)
	(heading-label "Date/time:") (vf-datetime vf)         (heading-label "Day:")        (vf-day	 vf)
	(heading-label "Subject:")   (vf-subject  vf)         (heading-label "Instructor:") (vf-instructor  vf)
	(heading-label "Confirmed?")  (vf-state       vf)     (heading-label "Tot Votes:") (vf-votes    vf)
	(heading-label "My vote:")    (vf-myvote      vf))
       (iup:hbox (heading-label "Details:")   (or (vf-details  vf) ""))
       (iup:hbox
	(iup:label "Set your vote ") btn)))))
   vf)

(define (populate-vote-form vf data spkt tpkt) ;; sZ tZ datetime category subject level details instructor state data)
  (let* (;; spkt
	 (stype       (alist-ref 'pkt-type    spkt))  ;; subject
	 (sZ          (alist-ref 'Z           spkt))
	 (instructor  (alist-ref 'person      spkt))
................................................................................
				 (reset-request 'reset) ;; flag matrix draw to start over and not finish current draw
				 (if (and (eq? state 1) spkt tpkt)
				     
				       ;; redirect to the form
				       (populate-vote-form vote-form data spkt tpkt) ;; sZ tZ datestr category subject level details tutor "-" data)
				       )
				 path))))
	    (sessions-matrix  (let* ((headings '("Id" "TZ" "Year/Month/Day" "Week Day" "Time" "  Subject  " "Level" "Instructor" "Confirmed" "Votes" "My vote" "           Details           " ))
				     (sm (iup:matrix
					  #:alignment1 "ALEFT"
					  ;; #:expand "YES" ;; "HORIZONTAL"
					  #:resizematrix "YES"
					  #:scrollbar "YES"
					  #:numcol (- (length headings) 1) ;; zeroth column (row header) is not counted.
					  #:numlin 50
................................................................................
				;; #:name "Subjects"
				#:title "Subjects" ;;  was #:name -- iup 3.19 changed this... "Changed: [DEPRECATED REMOVED] removed the old attribute NAMEid from IupTree to avoid conflict with the common attribute NAME. Use the TITLEid attribute."
				#:expand "YES"
				#:addexpanded "YES"
				;; #:size "10x"
				#:selection-cb
				(lambda (obj id state)

				  (let* ((path (iuputils:tree-node->path obj id)) ;; will get called twice - click and release
					 (plen (length path)))
				    (reset-request 'reset) ;; flag matrix draw to start over and not finish current draw



				    (if (> plen 1)(iup:attribute-set! category-edit-box "VALUE" (cadr path))) ;; have at least the category
				    (if (> plen 2)(iup:attribute-set! subject-edit-box  "VALUE" (caddr path))) ;; have at least the category
				    (if (> plen 3)(iup:attribute-set! level-edit-box    "VALUE" (cadddr path))) ;; have at least the category

				    path))))
	    (time-slots   (get-and-fill-time-slots
			   (gui:fill-matrix-headings
			    (iup:matrix
			     ;; #:expand "YES"
			     #:alignment "ALEFT"
			     #:resizematrix "YES"
................................................................................
	    (add/edit-slot  (iup:frame
			     title: "Add/Edit Time Slots"
			     ;; expand: "YES"
			     (iup:vbox
			      (iup:gridbox
			       numdiv: 3
			       expand: "YES"
			       (iup:label "ID:"    size: "30x16" )    id-edit-box (iup:label "(hex code)"   expand: "HORIZONTAL")
			       (iup:label "Date:"  size: "30x16" )  date-edit-box (iup:label "(YYYY/MM/DD)" expand: "HORIZONTAL")
			       (iup:label "Time:"  size: "30x16" )  time-edit-box (iup:label "(hh:mm)"      expand: "HORIZONTAL")
			       (iup:label "Day:"   Size: "30x16" )   day-edit-box (iup:label "(mon,tue,wed,thu,fri,sat,sun)" expand: "HORIZONTAL")
			       (iup:label "TZone:" Size: "30x16" ) tzone-edit-box (iup:label "(Three letter timezone code)"  expand: "HORIZONTAL"))
			      ;; (iup:label "")
			      (iup:hbox
			       (iup:button "Add"     action: add-time-slot    expand: "HORIZONTAL") ;; "YES")
			       (iup:button "Delete"  action: delete-time-slot expand: "HORIZONTAL")) ;; "YES"))
			      )))
	    ;; boxes for editing subjects
................................................................................
			     (lambda (mobj row col status)
			       (cond
				;; ((eq? col 0) #f) ;; do stuff for column 0 click
				((and (>= col 0)(> row 0)) ;;any column
				 (let* ((category (iup:attribute mobj (conc row ":1")))
					(subject  (iup:attribute mobj (conc row ":2")))
					(level    (iup:attribute mobj (conc row ":3")))

					(my-id    (get-my-id))
					(my-subjs (read-my-subjects-new my-id)))
				   ;; (print "category: " category " subject: " subject " level: " level)
				   (for-each
				    (lambda (pkt)
				      (let ((pcat  (alist-ref 'category pkt))
					    (psubj (alist-ref 'name     pkt))
					    (plevl (alist-ref 'level    pkt)))

					;; (print "pcat: " pcat " psubj: " psubj " plevl: " plevl)
					(when (and (equal? category pcat)
						   (equal? subject  psubj)
						   (equal? level    plevl))

					  (iup:attribute-set! subj-id-edit-box  "VALUE" (alist-ref 'Z pkt))
					  (iup:attribute-set! category-edit-box "VALUE" pcat)
					  (iup:attribute-set! subject-edit-box  "VALUE" psubj)
					  (iup:attribute-set! level-edit-box    "VALUE" plevl)

					  )))
				    my-subjs)))))
			     )
			    '("Id" "Category" "Subject" "Level" "Details" "")
			    fit-text: #t))
	    (add-category-subject (lambda (obj)(save-category-subject my-subjects-tree my-subjects category-edit-box subject-edit-box level-edit-box details-edit-box data)))
	    (del-category-subject (lambda (obj)(delete-category-subject my-subjects-tree my-subjects category-edit-box subject-edit-box level-edit-box details-edit-box data)))
................................................................................
	    (teach         (iup:hbox
			    (iup:split
			     #:orientation "VERTICAL"
			     ;; #:value 00  ;; aprox 50%
			     (iup:frame
			      ;; (iup:label  "Enter the Subjects You Teach" expand: "HORIZONTAL" fontsize: "13" alignment: "ACENTER")
			      title:  "      Add Subjects You Teach" fontsize: "13"
			      (iup:split
			       #:orientation "VERTICAL"
			       #:value 300
			       ;; #:minmax 300
			       my-subjects-tree
			       (iup:vbox

				my-subjects
				add/edit-subject)
			       )

			      )
			     
			     (iup:frame
			      ;; (iup:label  "Specify Your Time Slots" expand: "HORIZONTAL" fontsize: "13" alignment: "ACENTER")
			      title: "      Specify Your Time Slots" fontsize: "13"
			      (iup:vbox
			       time-slots







|
>
>
>
|
>
>
>







 







>
|



>
|
>
>







 








>
>
>
>
>
>
>
>
>
>
>

>
|




|
>




>
>
>



|
>










>
>
>
>
>
>









|








|
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|







 







|
|
|







 







|







 







|
|


|







 







|







 







>
|
|
<
>
>
>
|
|
|
>







 







|


|







 







>







|
>



|
>




>







 







|
|
|

<

>
|

<
>







299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
...
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
...
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
...
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
...
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
...
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
...
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
...
847
848
849
850
851
852
853
854
855
856

857
858
859
860
861
862
863
864
865
866
867
868
869
870
...
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
...
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
...
987
988
989
990
991
992
993
994
995
996
997

998
999
1000
1001

1002
1003
1004
1005
1006
1007
1008
1009
  (let ((del-pkts (get-del-pkts)))
    (pkts:with-queue-db
     learn-teach-pkts-dir
     (lambda (pdb)
       (for-each
	(lambda (P)
	  (dbi:exec pdb "DELETE FROM pkts WHERE uuid=?;" P)
	  (let ((fname  (conc learn-teach-pkts-dir "/" P ".pkt")))
	    (if (file-exists? fname)
		(begin
		  (delete-file* fname)
		  ;; (print "Removed pkt " P ".pkt")
		  )
		;; (print "File " fname " not found")
		)))
	(map (lambda (x)
	       (alist-ref 'parent x)) ;; we are removing the PARENTS!
	     del-pkts))))))

(define (get-del-pkts)
  (let ((del-pkts (pkts:with-queue-db
		   learn-teach-pkts-dir
................................................................................

(define valid-levels '("intro" "intermediate" "advanced" "expert" "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX" "X"))

(define (valid-level level)
  (string-match "^[a-zA-Z0-9\\-_]+$" level))

(define (save-category-subject my-subjects-tree my-subjects category-edit-box subject-edit-box level-edit-box details-edit-box data)
  (let* ((entries  (get-add-ht data 'my-subjects))
	 (category (iup:attribute category-edit-box "VALUE"))
	 (subject  (iup:attribute subject-edit-box  "VALUE"))
	 (level    (iup:attribute level-edit-box    "VALUE"))
	 (details  (iup:attribute details-edit-box  "VALUE"))
	 (tpath    (conc category "/" subject "/" level)) ;;  "/" details))
	 (my-id    (get-my-id))
	 (maxrow   1)) ;; (apply max 1))) ;; (hash-table-values entries))))
    ;; (hash-table-set! entries tpath (+ maxrow 1))
    (if (valid-category category)
	(if (valid-subject subject)
	    (if (valid-level level)
		(let* ((plist `((app      . "tnl")
				(person   . ,my-id)
				(category . ,category)
				(name     . ,subject)
................................................................................
		  (get-and-fill-my-subjects my-subjects-tree my-subjects my-id data)
		  (for-each (lambda (x)
			      (iup:attribute-set! x "BGCOLOR" "255 255 255"))
			    (list level-edit-box subject-edit-box category-edit-box)))
		(iup:attribute-set! level-edit-box "BGCOLOR" "255 200 255"))
	    (iup:attribute-set! subject-edit-box "BGCOLOR" "255 200 255"))
	(iup:attribute-set! category-edit-box "BGCOLOR" "255 200 255"))))

(define (matrix-delete-row-matching mtx c s l d)
  (let loop ((rnum  1))
    (when (and (equal? c (iup:attribute mtx (conc rnum ":1")))
	       (equal? s (iup:attribute mtx (conc rnum ":2")))
	       (equal? l (iup:attribute mtx (conc rnum ":3")))
	       (equal? d (iup:attribute mtx (conc rnum ":4"))))
      (iup:attribute-set! mtx "DELLIN" rnum))
    (if (and (< rnum 200)
	     (not (equal? (iup:attribute mtx (conc rnum ":1")) ""))) ;; stop on empty string or 200 rows
	(loop (+ rnum 1)))))

(define (delete-category-subject my-subjects-tree my-subjects category-edit-box subject-edit-box level-edit-box details-edit-box data)
  (let* ((entries  (get-add-ht data 'my-subjects))
	 (category (iup:attribute category-edit-box "VALUE"))
	 (subject  (iup:attribute subject-edit-box  "VALUE"))
	 (level    (iup:attribute level-edit-box    "VALUE"))
	 (details  (iup:attribute details-edit-box  "VALUE"))
	 (my-id    (get-my-id))
	 (pkt      (get-subject-matching category subject level my-id))
	 (tpath    (conc category "/" subject "/" level))) ;; "/" details)))
    (if pkt
	(let* ((plist `((app      . "tnl")
			(person   . ,my-id)
			(parent   . ,(alist-ref 'Z pkt)))))
	  (tree-delete-node my-subjects-tree `("Subjects" ,category ,subject ,level))
	  (matrix-delete-row-matching my-subjects category subject level details)
	  (hash-table-delete! entries tpath)
	  (pkts:write-alist->pkt learn-teach-pkts-dir plist pktspec: pkt-spec ptype: 'del)
	  (apply-del-pkts)
	  (load-pkts)
	  ;; (get-and-fill-my-subjects my-subjects-tree my-subjects my-id data)
	  ))))

;; (use trace)(trace-call-sites #t)(trace delete-category-subject get-subject-matching pkts:write-alist->pkt apply-del-pkts)

(define (get-add-ht ht-in key)
  (let ((ht (hash-table-ref/default ht-in key #f)))
    (if ht
	ht
	(let ((ht (make-hash-table)))
	  (hash-table-set! ht-in key ht)
	  ht))))

;; it is a string and it has some word chars
;;
(define (good-string str)
  (and (string? str)
       (not (string-match "^\\s*$" str))))

;; fill in the time-slots with my time-slots
;;
(define (get-and-fill-my-subjects my-subjects-tree my-subjects user-name data #!key (update-tree #t))
  (let* ((entries  (get-add-ht data 'my-subjects))
	 (my-dpkts (read-my-subjects user-name))
	 (my-apkts (map (lambda (x)
			  (pkts:dpkt->alist x pkt-spec))
			my-dpkts))
	 (rownum   1)) ;; (+ 1 (apply max 0)))) ;;  (hash-table-values entries)))))
    (for-each
     (lambda (pkt)
       (let* ((category (alist-ref 'category pkt))
	      (subject  (alist-ref 'name     pkt))
	      (level    (alist-ref 'level    pkt))
	      (details  (alist-ref 'details  pkt))
	      (Z        (alist-ref 'Z pkt))
	      (path     `(,category ,subject ,level))
	      (tpath    (conc category "/" subject "/" level))) ;; "/" details)))
	 (if (and (good-string category)
		  (good-string subject)
		  (good-string level))
	     (begin
	       (if (and update-tree
			(not (hash-table-exists? entries tpath)))
		   (begin
		     (hash-table-set! entries tpath details) ;; rownum)
		     (iup:attribute-set! my-subjects (conc rownum ":0") Z)
		     (iup:attribute-set! my-subjects (conc rownum ":1") category)
		     (iup:attribute-set! my-subjects (conc rownum ":2") subject)
		     (iup:attribute-set! my-subjects (conc rownum ":3") level)
		     (iup:attribute-set! my-subjects (conc rownum ":4") details)
		     (tree-add-node my-subjects-tree "Subjects" path)))
	       (set! rownum (+ rownum 1))))))
     my-apkts)
    (iup:attribute-set! my-subjects "FITTOTEXT" "C1")
    (iup:attribute-set! my-subjects "FITTOTEXT" "C2")
    (iup:attribute-set! my-subjects "FITTOTEXT" "C3")
    ;; (iup:attribute-set! my-subjects "FITTOTEXT" "C4")
    (iup:attribute-set! my-subjects "REDRAW" "YES")
    my-subjects))
................................................................................
			(iup:attribute-set! sessions-matrix (conc rownum ":2") date)
			(iup:attribute-set! sessions-matrix (conc rownum ":3")
					    (time->day (string->time date "%Y/%m/%d")))
			(iup:attribute-set! sessions-matrix (conc rownum ":4") time)
			(iup:attribute-set! sessions-matrix (conc rownum ":5") name)
			(iup:attribute-set! sessions-matrix (conc rownum ":6") level)
			(iup:attribute-set! sessions-matrix (conc rownum ":7") person)
			(iup:attribute-set! sessions-matrix (conc rownum ":8") tot)
			(iup:attribute-set! sessions-matrix (conc rownum ":9") (hash-table-ref/default votes my-id 0))
			(iup:attribute-set! sessions-matrix (conc rownum ":10") details)
			(set! rownum (+ rownum 1))))
		  (if (and update-tree
			   (not (hash-table-exists? entries tpath)))
		      (begin
			;; (print "path: " path " tpath: " tpath)
			(hash-table-set! entries tpath (cons spkt tpkt))
			(tree-add-node subjects-tree "Subjects" path)
................................................................................
  (state      (iup:label size: "120x" expand: "HORIZONTAL"))
  (votes      (iup:label size: "120x" expand: "HORIZONTAL"))
  (myvote     (iup:label size: "120x" expand: "HORIZONTAL"))
  (votebutton #f);; (iup:button "Yes"))
  (form       #f))

(define (heading-label val)
  (iup:label val size: "70x10"))

(define-inline (set-label! lbl value)
  (iup:attribute-set! lbl "TITLE" (conc value))
  (iup:attribute-set! lbl "FGCOLOR" "055 155 055")
  (iup:attribute-set! lbl "REDRAW" "ALL")) ;; convert numbers, symbols etc. to strings

(define (setup-vote-form vf)
................................................................................
       (iup:gridbox
	numdiv: 4
	expand: "YES"
	;; expandchildren: "HORIZONTAL"
	(heading-label "Category:")  (vf-category vf)         (heading-label "Level:")      (vf-level       vf)
	(heading-label "Date/time:") (vf-datetime vf)         (heading-label "Day:")        (vf-day	 vf)
	(heading-label "Subject:")   (vf-subject  vf)         (heading-label "Instructor:") (vf-instructor  vf)
	(heading-label "Confirmed?")  (vf-state       vf)     (heading-label "Total Interested:") (vf-votes    vf)
	(heading-label "I'm interested:")    (vf-myvote      vf))
       (iup:hbox (heading-label "Details:")   (or (vf-details  vf) ""))
       (iup:hbox
	(iup:label "Set this session to: ") btn )))))
   vf)

(define (populate-vote-form vf data spkt tpkt) ;; sZ tZ datetime category subject level details instructor state data)
  (let* (;; spkt
	 (stype       (alist-ref 'pkt-type    spkt))  ;; subject
	 (sZ          (alist-ref 'Z           spkt))
	 (instructor  (alist-ref 'person      spkt))
................................................................................
				 (reset-request 'reset) ;; flag matrix draw to start over and not finish current draw
				 (if (and (eq? state 1) spkt tpkt)
				     
				       ;; redirect to the form
				       (populate-vote-form vote-form data spkt tpkt) ;; sZ tZ datestr category subject level details tutor "-" data)
				       )
				 path))))
	    (sessions-matrix  (let* ((headings '("Id" "TZ" "Year/Month/Day" "Week Day" "Time" "  Subject  " "Level" "Instructor" "Votes" "My vote" "           Details           " "Confirmed" ))
				     (sm (iup:matrix
					  #:alignment1 "ALEFT"
					  ;; #:expand "YES" ;; "HORIZONTAL"
					  #:resizematrix "YES"
					  #:scrollbar "YES"
					  #:numcol (- (length headings) 1) ;; zeroth column (row header) is not counted.
					  #:numlin 50
................................................................................
				;; #:name "Subjects"
				#:title "Subjects" ;;  was #:name -- iup 3.19 changed this... "Changed: [DEPRECATED REMOVED] removed the old attribute NAMEid from IupTree to avoid conflict with the common attribute NAME. Use the TITLEid attribute."
				#:expand "YES"
				#:addexpanded "YES"
				;; #:size "10x"
				#:selection-cb
				(lambda (obj id state)
				  (let* ((entries (get-add-ht data 'my-subjects))
					 (path (iuputils:tree-node->path obj id)) ;; will get called twice - click and release
					 (plen (length path))

					 (cat  (if (> plen 1)(cadr path) #f)) ;; have at least the category
					 (subj (if (> plen 2)(caddr path) #f)) ;; have at least the subj
					 (lev  (if (> plen 3)(cadddr path) #f))) ;; have at least the level
				    (if cat  (iup:attribute-set! category-edit-box "VALUE" cat))
				    (if subj (iup:attribute-set! subject-edit-box  "VALUE" subj))
				    (if lev  (iup:attribute-set! level-edit-box    "VALUE" lev))
				    (if lev  (iup:attribute-set! details-edit-box  "VALUE" (hash-table-ref entries (conc cat "/" subj "/" lev))))
				    path))))
	    (time-slots   (get-and-fill-time-slots
			   (gui:fill-matrix-headings
			    (iup:matrix
			     ;; #:expand "YES"
			     #:alignment "ALEFT"
			     #:resizematrix "YES"
................................................................................
	    (add/edit-slot  (iup:frame
			     title: "Add/Edit Time Slots"
			     ;; expand: "YES"
			     (iup:vbox
			      (iup:gridbox
			       numdiv: 3
			       expand: "YES"
			       ;; (iup:label "ID:"    size: "30x16" )    id-edit-box (iup:label "(hex code)"   expand: "HORIZONTAL")
			       (iup:label "Date:"  size: "30x16" )  date-edit-box (iup:label "(YYYY/MM/DD)" expand: "HORIZONTAL")
			       (iup:label "Time:"  size: "30x16" )  time-edit-box (iup:label "(hh:mm)"      expand: "HORIZONTAL")
			       (iup:label "Day:"   Size: "30x16" )   day-edit-box (iup:label "(Mon-Sun)"    expand: "HORIZONTAL")
			       (iup:label "TZone:" Size: "30x16" ) tzone-edit-box (iup:label "(Three letter timezone code)"  expand: "HORIZONTAL"))
			      ;; (iup:label "")
			      (iup:hbox
			       (iup:button "Add"     action: add-time-slot    expand: "HORIZONTAL") ;; "YES")
			       (iup:button "Delete"  action: delete-time-slot expand: "HORIZONTAL")) ;; "YES"))
			      )))
	    ;; boxes for editing subjects
................................................................................
			     (lambda (mobj row col status)
			       (cond
				;; ((eq? col 0) #f) ;; do stuff for column 0 click
				((and (>= col 0)(> row 0)) ;;any column
				 (let* ((category (iup:attribute mobj (conc row ":1")))
					(subject  (iup:attribute mobj (conc row ":2")))
					(level    (iup:attribute mobj (conc row ":3")))
					(details  (iup:attribute mobj (conc row ":4")))
					(my-id    (get-my-id))
					(my-subjs (read-my-subjects-new my-id)))
				   ;; (print "category: " category " subject: " subject " level: " level)
				   (for-each
				    (lambda (pkt)
				      (let ((pcat  (alist-ref 'category pkt))
					    (psubj (alist-ref 'name     pkt))
					    (plevl (alist-ref 'level    pkt))
					    (dtals (alist-ref 'details  pkt)))
					;; (print "pcat: " pcat " psubj: " psubj " plevl: " plevl)
					(when (and (equal? category pcat)
						   (equal? subject  psubj)
						   (equal? level    plevl)
						   (equal? details  dtals))
					  (iup:attribute-set! subj-id-edit-box  "VALUE" (alist-ref 'Z pkt))
					  (iup:attribute-set! category-edit-box "VALUE" pcat)
					  (iup:attribute-set! subject-edit-box  "VALUE" psubj)
					  (iup:attribute-set! level-edit-box    "VALUE" plevl)
					  (iup:attribute-set! details-edit-box  "VALUE" details)
					  )))
				    my-subjs)))))
			     )
			    '("Id" "Category" "Subject" "Level" "Details" "")
			    fit-text: #t))
	    (add-category-subject (lambda (obj)(save-category-subject my-subjects-tree my-subjects category-edit-box subject-edit-box level-edit-box details-edit-box data)))
	    (del-category-subject (lambda (obj)(delete-category-subject my-subjects-tree my-subjects category-edit-box subject-edit-box level-edit-box details-edit-box data)))
................................................................................
	    (teach         (iup:hbox
			    (iup:split
			     #:orientation "VERTICAL"
			     ;; #:value 00  ;; aprox 50%
			     (iup:frame
			      ;; (iup:label  "Enter the Subjects You Teach" expand: "HORIZONTAL" fontsize: "13" alignment: "ACENTER")
			      title:  "      Add Subjects You Teach" fontsize: "13"
			      ;; (iup:split
			      ;;  #:orientation "VERTICAL"
			      ;;  #:value 300
			       ;; #:minmax 300

			       (iup:vbox
				my-subjects-tree
				;; my-subjects
				add/edit-subject)

			       ;; )
			      )
			     
			     (iup:frame
			      ;; (iup:label  "Specify Your Time Slots" expand: "HORIZONTAL" fontsize: "13" alignment: "ACENTER")
			      title: "      Specify Your Time Slots" fontsize: "13"
			      (iup:vbox
			       time-slots