-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpgedview.module
933 lines (854 loc) · 36.2 KB
/
phpgedview.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
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
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
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
929
930
931
932
933
<?php
/**
* @file
* A module to embed PhpGedView genealogy program into Drupal
*
* Based on a program created for PostNuke by Jim Carey
* Adapted and maintained for Drupal by Karen Stevenson
*
* Wish List:
* all of these are difficult enough that they won't get done any time soon!
* but we have a connection to the PGV database and the ability to perform
* user authentication, plus PGV's webservice & soap features that filter
* results by the privacy settings of the user, so these are theoretically doable.
*
* Add more synchronization of users between Drupal and PGV
* Add Drupal blocks that pull data from PGV.
* Add PGV events to Drupal calendars.
* Create Drupal nodes from selected PGV records.
* Add PGV search to Drupal search.
* Add PGV info to user profiles.
*/
/**
* Implements hook_perm().
*/
function phpgedview_perm() {
return array('admin phpgedview', 'view phpgedview');
}
/**
* Implements hook_menu().
*/
function phpgedview_menu() {
global $user;
phpgedview_set_cookies($user);
$items = array();
// Paths to the settings screen.
$items['admin/settings/phpgedview'] = array(
'title' => t('PhpGedView'),
'description' => t('Configure PhpGedView paths, directories, and labels.'),
'access arguments' => array('admin phpgedview'),
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array('phpgedview_settings_form'),
);
$items['admin/settings/phpgedview/main'] = array(
'title' => t('Configure'),
'access arguments' => array('admin phpgedview'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => array('phpgedview_settings_form'),
'weight' => -10,
);
$items['admin/settings/phpgedview/map'] = array(
'title' => t('Map Users'),
'access arguments' => array('admin phpgedview'),
'type' => MENU_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => array('phpgedview_user_map_form'),
'weight' => 0,
);
phpgedview_set_cookies($user);
// Set the external paths.
if (variable_get('phpgedview_configured', 0) && variable_get('phpgedview_type', 'embedded') == 'external') {
if ($_COOKIE['pgv_embedded'] != 0) {
setcookie('pgv_embedded', 0, 0, '/');
}
// Anonymous users and robots get a regular external link.
// No special handling required.
if (!$user->uid) {
$items[phpgedview_external_path()] = array(
'type' => MENU_NORMAL_ITEM,
'title' => variable_get('phpgedview_name', t('PhpGedView')),
'access arguments' => array('view phpgedview'),
'weight' => -10,
);
}
// Authenticated users get passed through a function
// that can check status and update databases before redirecting them.
else {
$items[variable_get('phpgedview_path', 'phpgedview')] = array(
'type' => MENU_NORMAL_ITEM,
'title' => variable_get('phpgedview_name', t('PhpGedView')),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_external_page',
'page arguments' => array('index.php'),
'weight' => -10,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/admin'] = array(
'type' => MENU_SUGGESTED_ITEM,
'title' => t('Admin PhpGedView'),
'access arguments' => array('admin phpgedview'),
'page callback' => 'phpgedview_external_page',
'page arguments' => array('admin.php'),
'weight' => -10,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/admin/useradmin'] = array(
'type' => MENU_SUGGESTED_ITEM,
'title' => t('Edit PhpGedView Users'),
'access arguments' => array('admin phpgedview'),
'page callback' => 'phpgedview_external_page',
'page arguments' => array('useradmin.php', arg(3)),
'weight' => -9,
);
}
}
// A variety of embedded paths are provided so the main sections in the
// iframe are bookmarkable, and to provide ways to send an admin directly
// to the user edit page or some other special destination.
elseif (variable_get('phpgedview_configured', 0) && variable_get('phpgedview_type', 'embedded') == 'embedded') {
if ($_COOKIE['pgv_embedded'] != 1) {
setcookie('pgv_embedded', 1, 0, '/');
}
$items[variable_get('phpgedview_path', 'phpgedview')] = array(
'type' => MENU_NORMAL_ITEM,
'title' => variable_get('phpgedview_name', t('PhpGedView')),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('index.php'),
'weight' => -10,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/index'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => t('Welcome'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('index.php?command=gedcom'),
'weight' => -10,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/index/index'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => t('Welcome'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('index.php?command=gedcom'),
'weight' => -10,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/index/portal'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('My Portal'),
'access arguments' => array(array('view phpgedview'), $access),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('index.php?command=user'),
'weight' => -9,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree'] = array(
'type' => MENU_LOCAL_TASK,
'access arguments' => 'phpgedview view',
'title' => t('Charts'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('pedigree.php'),
'weight' => -8,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree/pedigree'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Pedigree'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('pedigree.php'),
'weight' => -10,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree/descendancy'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Decendancy'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('descendancy.php'),
'weight' => -9,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree/ancestry'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Ancestry'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('ancestry.php'),
'weight' => -8,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree/compact'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Compact'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('compact.php'),
'weight' => -7,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree/fanchart'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Circle'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('fanchart.php'),
'weight' => -8,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree/hourglass'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Hourglass'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('hourglass.php'),
'weight' => -7,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree/familybook'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Family'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('familybook.php'),
'weight' => -6,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree/timeline'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Timeline'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('timeline.php'),
'weight' => -5,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/pedigree/relationship'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Relationship'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('relationship.php'),
'weight' => -4,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/indilist'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Lists'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('indilist.php'),
'weight' => -7,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/indilist/indilist'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => t('Individual'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('indilist.php'),
'weight' => -10,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/indilist/famlist'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Family'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('famlist.php'),
'weight' => -9,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/indilist/sourcelist'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Source'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('sourcelist.php'),
'weight' => -8,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/indilist/repolist'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Repository'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('repolist.php'),
'weight' => -7,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/indilist/placelist'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Place'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('placelist.php'),
'weight' => -6,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/indilist/medialist'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Media'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('medialist.php'),
'weight' => -5,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/indilist/patriarchlist'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Patriarch'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('patriarchlist.php'),
'weight' => -4,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/indilist/aliveinyear'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Alive in Year'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('aliveinyear.php'),
'weight' => -3,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/calendar'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Calendar'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('calendar.php'),
'weight' => -6,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/calendar/day'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => t('Day'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('calendar.php'),
'weight' => -6,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/calendar/calendar'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Month'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('calendar.php?action=calendar'),
'weight' => -6,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/calendar/year'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Year'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('calendar.php?action=year'),
'weight' => -6,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/reportengine'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Reports'),
'access arguments' => array('view phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('reportengine.php'),
'weight' => -5,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/search'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Search'),
'access arguments' => array(array('view phpgedview'), $access),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('search.php?action=general'),
'weight' => 1,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/search/search'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('General Search'),
'access arguments' => array(array('view phpgedview'), $access),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('search.php?action=general'),
'weight' => -8,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/search/soundex'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Soundex Search'),
'access arguments' => array(array('view phpgedview'), $access),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('search.php?action=soundex'),
'weight' => -7,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/admin'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Admin'),
'access arguments' => array('admin phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('admin.php'),
'weight' => 0,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/admin/admin'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => t('Admin'),
'access arguments' => array('admin phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('admin.php'),
'weight' => -10,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/admin/useradmin'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Edit Users'),
'access arguments' => array('admin phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('useradmin.php', arg(3)),
'weight' => -9,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/admin/editgedcoms'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Edit Gedcoms'),
'access arguments' => array('admin phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('editgedcoms.php'),
'weight' => -8,
);
$items[variable_get('phpgedview_path', 'phpgedview') . '/admin/media'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Manage Media'),
'access arguments' => array('admin phpgedview'),
'page callback' => 'phpgedview_embedded_page',
'page arguments' => array('media.php'),
'weight' => -7,
);
}
return $items;
}
/**
* Relative path to external application.
*
* We're keeping the path relative so session info is not appended
* to urls and so we can create a Drupal menu item for this path and
* use Drupal access control over the link.
*/
function phpgedview_external_path() {
// Strip the leading slash from the external directory.
$directory = substr(variable_get('phpgedview_directory', '/phpgedview/'), 1);
// Find out how deep the Drupal installation is.
$internal_depth = intval(sizeof(explode('/', base_path())) - 2);
// Prepend ../ enough times to get a relative link back to the external program.
return str_repeat('../', $internal_depth) . $directory;
}
/**
* Callback for external PhpGedView page.
*
* @path - the path to take in PGV
* @uid - if needed, the uid of the user to edit
*/
function phpgedview_external_page($path = 'index.php', $uid = 0) {
global $user;
$usernames = phpgedview_user_map();
// If this user is not in the map yet, they will be added to PGV
// when they follow this link, so add them to the map.
if (!$username = $usernames[$user->uid]) {
$username = $user->name;
db_query("INSERT INTO {phpgedview_user_map} (uid, pgv) VALUES (%d, '%s')", $user->uid, $username);
}
if ($uid > 0) {
$path .= '?action=edituser&username='. $username;
}
$url = phpgedview_external_path() ."modules/cms_interface/cms_login.php";
drupal_goto($url, 'path='. urlencode($path));
}
/**
* Callback for embedded PhpGedView page
*
* @path - the path to take in PGV
* @uid - if needed, the uid of the user to edit
*/
function phpgedview_embedded_page($path = 'index.php', $uid = 0) {
global $user;
$usernames = phpgedview_user_map();
// If this user is not in the map yet, they will be added to PGV
// when they follow this link, so add them to the map.
if (!$username = $usernames[$user->uid]) {
$username = $user->name;
db_query("INSERT INTO {phpgedview_user_map} (uid, pgv) VALUES (%d, '%s')", $user->uid, $username);
}
if ($uid > 0) {
$path .= '?action=edituser&username='. $username;
}
$url = variable_get('phpgedview_directory', '/phpgedview/') ."modules/cms_interface/cms_login.php?path=". urlencode($path);
drupal_add_css(drupal_get_path('module', 'phpgedview') .'/phpgedview.css');
drupal_add_js(drupal_get_path('module', 'phpgedview') .'/postwrap.js');
return '<div class="contentpane">
<iframe onload="iFrameHeight()" id="blockrandom" src="' . $url . '" width="100%" height="500" scrolling="auto" align="top" frameborder="0" class="wrapper">
This option will not work correctly. Unfortunately, your browser does not support Inline Frames. </iframe></div>';
}
/**
* Configuration settings form
*/
function phpgedview_settings_form() {
$form['setup'] = array(
'#type' => 'fieldset',
'#title' => t('Program Settings'),
);
$form['setup']['phpgedview_directory'] = array(
'#title' => t('PhpGedView base directory'),
'#type' => 'textfield',
'#default_value' => variable_get('phpgedview_directory', '/phpgedview/'),
'#description' => t('The absolute path to the external PhpGedView installation, relative to the web root (i.e. /phpgedview/), must have a trailing slash.'),
'#required' => TRUE,
);
$form['setup']['phpgedview_prefix'] = array(
'#title' => t('PhpGedView prefix'),
'#type' => 'textfield',
'#default_value' => variable_get('phpgedview_prefix', 'pgv_'),
'#description' => t('The prefix used in the PhpGedView database.'),
);
global $db_url;
if (!is_array($db_url) || empty($db_url['phpgedview'])) {
$form['setup']['phpgedview_db'] = array(
'#title' => t('PhpGedView database connection'),
'#type' => 'textfield',
'#default_value' => variable_get('phpgedview_db', 'mysql://username:password@localhost/databasename'),
'#description' => t('The database setting for the PGV database, in the format mysql://username:password@localhost/databasename. Read INSTALL.txt for instructions on how to identify this value in the settings.php file instead of in this form, a method which is more secure.'),
);
}
$form['setup']['phpgedview_name'] = array(
'#title' => t('Menu Name'),
'#type' => 'textfield',
'#default_value' => variable_get('phpgedview_name', t('PhpGedView')),
'#description' => t('The name to use for PhpGedView in links and labels. You can label it PhpGedView or Geneology or Family Tree, or anything else.'),
'#required' => TRUE,
);
$form['setup']['phpgedview_path'] = array(
'#title' => t('Internal path'),
'#type' => 'textfield',
'#default_value' => variable_get('phpgedview_path', 'phpgedview'),
'#description' => t('The path to use for internal links and menus. Do not use the path that leads to the external installation nor other valid paths. Use no leading or trailing slashes.'),
'#required' => TRUE,
);
$form['setup']['phpgedview_type'] = array(
'#title' => t('Integration type'),
'#type' => 'radios',
'#options' => array('embedded' => t('Embedded'), 'external' => t('External')),
'#default_value' => variable_get('phpgedview_type', 'embedded'),
'#description' => t('The method to use for integrating PhpGedView into Drupal. The embedded option displays PGV in an iframe in a Drupal page. The external option links users to the stand-alone PGV program. Both methods allow you to use a single login for both programs.'),
'#required' => TRUE,
);
$form += phpgedview_user_form('settings');
variable_set('phpgedview_configured', 1);
return system_settings_form($form);
}
/**
* User settings form.
*/
function phpgedview_user_form($type = 'settings', $edit = NULL) {
if ($type == 'settings') {
$form['users'] = array(
'#type' => 'fieldset',
'#title' => t('User Defaults'),
'#description' => t('Set up the values below for default rights for new users in PhpGedView when they are created automatically by this module. When in doubt, give users the lowest usual level of access, then manually update those who should have more rights.'),
);
$form['users']['phpgedview_def_create_user'] = array(
'#title' => t('Create users'),
'#type' => 'select',
'#options' => array('no' => t('no'), 'yes' => t('yes')),
'#default_value' => variable_get('phpgedview_def_create_user', 'yes'),
'#description' => t('Create Drupal users in PhpGEDView if they do not already exist.'),
);
}
$form['users']['phpgedview_def_gedcom'] = array(
'#title' => t('Gedcom'),
'#type' => 'textfield',
'#default_value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_gedcom', '') : $edit['phpgedview_def_gedcom'],
);
$form['users']['phpgedview_def_rootid'] = array(
'#title' => t('Root id'),
'#type' => 'textfield',
'#default_value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_rootid', '') : $edit['phpgedview_def_rootid'],
);
$form['users']['phpgedview_def_language'] = array(
'#title' => t('Language'),
'#type' => 'textfield',
'#default_value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_language', 'english') : $edit['phpgedview_def_language'],
);
$form['users']['phpgedview_def_theme'] = array(
'#title' => t('Theme'),
'#type' => 'textfield',
'#default_value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_theme', '') : $edit['phpgedview_def_theme'],
'#description' => t('Either blank to use the default theme, or in the format \'themes/themename/\'. Must have a trailing slash.'),
);
$form['users']['phpgedview_def_contact_method'] = array(
'#title' => t('Contact method'),
'#type' => 'select',
'#options' => array(
'none' => t('none'),
'mailto' => t('email'),
'messaging' => t('Internal messaging'),
'messaging2' => t('Internal + email')
),
'#default_value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_contact_method', 'messaging2') : $edit['phpgedview_def_contact_method'],
);
$form['users']['phpgedview_def_canedit'] = array(
'#title' => t('Access level'),
'#type' => 'select',
'#default_value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_canedit', 'access arguments') : $edit['phpgedview_def_canedit'],
'#options' => array(
'none' => t('no access'),
'access arguments' => t('access only'),
'edit' => t('edit'),
'admin' => t('admin'),
),
);
$form['users']['phpgedview_def_canadmin'] = array(
'#title' => t('Administration rights'),
'#type' => 'select',
'#options' => array('no' => t('has no admin rights'), 'yes' => t('has admin rights')),
'#default_value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_canadmin', 'no') : $edit['phpgedview_def_canadmin'],
);
$form['users']['phpgedview_def_verified_by_admin'] = array(
'#title' => t('Mark verified'),
'#type' => 'select',
'#options' => array('no' => t('no'), 'yes' => t('yes')),
'#default_value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_verified_by_admin', 'yes') : $edit['phpgedview_def_verified_by_admin'],
'#description' => t('Consider this person to be verified by an admin?'),
);
$form['users']['phpgedview_def_verified'] = array(
'#type' => 'hidden',
'#value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_verified', 'yes') : $edit['phpgedview_def_verified'],
);
$form['users']['phpgedview_def_password'] = array(
'#type' => 'hidden',
'#value' => ($type == 'settings' || $edit == NULL) ? variable_get('phpgedview_def_password', 'none') : $edit['phpgedview_def_password'],
);
return $form;
}
/**
* Form to map Drupal users to PGV users.
*/
function phpgedview_user_map_form() {
// Display user map.
$form = array();
$map = array();
$pgv = (array) phpgedview_pgv_users();
$drupal = (array) phpgedview_drupal_users();
$map = phpgedview_user_map();
$options = drupal_map_assoc(array_merge(array(''), array_keys($pgv)));
$form['ids'] = array();
$form['user_map'] = array(
'#tree' => TRUE,
);
foreach ($drupal as $name => $account) {
// Skip the anonymous user.
if ($name > '') {
$form['user_map']['uid_'. $account->uid] = array(
'#type' => 'select',
'#title' => $name,
'#options' => $options,
// Use mapped name if available, otherwise see if there is a matching
// value in $pgv.
'#default_value' => isset($map[$account->uid]) ? $map[$account->uid] : $pgv[$name]->user_name,
);
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Theme the user map form into a table
*/
function theme_phpgedview_user_map_form($form) {
$output = t('<p>Match Drupal usernames to the related username in PhpGedView. Anyone with a blank value
will be treated as a nonauthenticated user in PhpGedView.</p>
<p>The PGV list shows users currently set up in PGV. If you have users set up in Drupal but not in PGV,
they will automatically be added as PGV users the first time they actually access the program.
They will initally be set up with whatever you configure here as the default permissions. Once
they have been added as PGV users, you can edit their PGV permissions in the PGV program to change
the permissions as needed.</p>');
$rows = array();
foreach ($form as $id => $name) {
if (strstr($id, 'uid_')) {
$rows[] = array($name['#label'], drupal_render($form[$id]));
}
}
$output .= theme('table', array(t('Drupal'), t('PGV')), $rows);
$output .= drupal_render($form);
return $output;
}
/**
* Update the user map table
*/
function phpgedview_user_map_form_submit($form_id, $form_values) {
global $user;
$user_map = $form_values['values']['user_map'];
// Add new values to the map.
foreach ($user_map as $key => $val) {
$uid = intval(str_replace('uid_', '', $key));
// TODO: Make sure value is not in table before insertion.
db_query("INSERT INTO {phpgedview_user_map} (uid, pgv) VALUES (%d, '%s')", $uid, $val);
}
// Get current values and clean up since PGV may have changes that haven't
// been recorded in Drupal.
$pgv = (array) phpgedview_pgv_users();
$drupal = (array) phpgedview_drupal_users();
$map = phpgedview_user_map();
// TODO/BUG: Not sure what this is doing here.
foreach ($map as $key => $value) {
if (!array_key_exists($value, $pgv) || !array_key_exists($key, $drupal)) {
db_query("DELETE FROM {phpgedview_user_map} WHERE pgv = '%s'", $value);
}
}
// Make sure the current user gets logged in properly once the mapping is done
// in case they are mapping themselves for the first time.
phpgedview_set_cookies($user);
}
/**
* A function to get an array of the pgv user info.
*/
function phpgedview_pgv_users() {
$pgv = array();
if (phpgedview_pgv_connect()) {
$results = db_query("SELECT * FROM " . variable_get('phpgedview_prefix', 'pgv_') . "user ORDER BY user_name");
while($arr = db_fetch_object($results)) {
$pgv[$arr->user_name] = $arr;
}
}
phpgedview_pgv_disconnect();
return $pgv;
}
/**
* A function to get an array of the drupal user info
*/
function phpgedview_drupal_users() {
$results = db_query("SELECT * FROM {users} ORDER BY name");
while ($arr = db_fetch_object($results)) {
$drupal[$arr->name] = $arr;
}
return $drupal;
}
/**
* A function to get the user map array
*/
function phpgedview_user_map() {
$results = db_query("SELECT * FROM {phpgedview_user_map}");
while ($arr = db_fetch_object($results)) {
$map[$arr->uid] = $arr->pgv;
}
return $map;
}
/**
* Implements hook_form_alter.
*
* Handle login requests redirected from PhpGedView.
*/
function phpgedview_form_alter(&$form, $form_state, $form_id) {
// Coming from a link in PGV, no login info provided yet.
if ($form_id == 'user_login' && strstr($_GET['url'], 'ged')) {
// Pass the url to the form so user will return to that page.
$form['#redirect'] = variable_get('phpgedview_directory', '/phpgedview/') . urldecode($_GET['url']);
// Coming from a submitted PGV login form.
} elseif ($form_id == 'user_login' && $_POST['ged'] && $_POST['url']) {
$_REQUEST['destination'] = variable_get('phpgedview_directory', '/phpgedview/') . $_POST['url'];
user_authenticate(array('name' => $_POST['username'], 'pass' => $_POST['password']));
exit;
}
}
/**
* Implements hook_user().
*/
function phpgedview_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case ('insert'):
case ('update'):
case ('submit'):
case ('login'):
phpgedview_set_cookies($account);
break;
case ('logout'):
phpgedview_unset_cookies();
break;
case ('delete'):
db_query("DELETE FROM {phpgedview_user_map} WHERE uid = '%s'", $account->uid);
break;
// Display a link on the Drupal user account to their account in PhpGedView.
case ('view'):
if (array('admin phpgedview')) {
$links[] = phpgedview_userlink($account->uid);
return array(variable_get('phpgedview_name', t('PhpGedView')) => array(array('value' => theme('item_list', $links), 'title' => '')));
}
break;
}
}
function phpgedview_set_cookies($account, $reset = FALSE) {
if ($account->uid > 0 && ($reset || !isset($_COOKIE['pgv_permissions']))) {
$map = phpgedview_user_map();
$username = $map[$account->uid];
phpgedview_unset_cookies();
// Set pgv_user so that they will be logged in in gedview.
phpgedview_set_value('post_user', $username);
phpgedview_set_value('post_email', $account->mail);
phpgedview_set_value('post_canedit', $canedit);
// Setup the post_config variables as cookies so postgedview doesn't
// need to read them.
phpgedview_set_value('def_canadmin', variable_get('phpgedview_def_canadmin', 'no'));
phpgedview_set_value('def_canedit', variable_get('phpgedview_def_canedit', 'access arguments'));
phpgedview_set_value('def_rootid', variable_get('phpgedview_def_rootid', ''));
phpgedview_set_value('def_verified', variable_get('phpgedview_def_verified', 'yes'));
phpgedview_set_value('def_verified_by_admin', variable_get('phpgedview_def_verified_by_admin', 'yes'));
phpgedview_set_value('def_create_user', variable_get('phpgedview_def_create_user', 'yes'));
phpgedview_set_value('def_language', variable_get('phpgedview_def_language', 'english'));
phpgedview_set_value('def_upass', variable_get('phpgedview_def_upass', ''));
phpgedview_set_value('def_gedcom', variable_get('phpgedview_def_gedcom', ''));
phpgedview_set_value('def_contact_method', variable_get('phpgedview_def_contact_method', 'messaging2'));
phpgedview_set_value('def_theme', variable_get('phpgedview_def_theme', ''));
}
setcookie('pgv_permissions', base64_encode(serialize((array) $GLOBALS['phpgedview']['permissions'])), 0, '/');
}
function phpgedview_unset_cookies() {
phpgedview_set_value('post_user', '');
phpgedview_set_value('post_email', '');
phpgedview_set_value('post_canedit', '');
phpgedview_set_value('def_canadmin', '');
phpgedview_set_value('def_canedit', '');
phpgedview_set_value('def_rootid', '');
phpgedview_set_value('def_verified', '');
phpgedview_set_value('def_verified_by_admin', '');
phpgedview_set_value('def_create_user', '');
phpgedview_set_value('def_language', '');
phpgedview_set_value('def_upass', '');
phpgedview_set_value('def_gedcom', '');
phpgedview_set_value('def_contact_method', '');
phpgedview_set_value('def_theme', '');
setcookie('pgv_permissions', serialize(array()), 0, '/');
}
function phpgedview_set_value($key, $value) {
$GLOBALS['phpgedview']['permissions'][$key] = $value;
}
/**
* A link to a PhpGedView user edit screen
*/
function phpgedview_userlink($uid) {
return l(t('Edit Account'), (variable_get('phpgedview_type', 'embedded') == 'embedded' ? variable_get('phpgedview_path', 'phpgedview') . '/admin/useradmin/'. $uid : phpgedview_external_page('useradmin.php', $uid)));
}
/**
* Attempt to connect to the PGV database.
*
* The database config could be set either in the variable 'phpgedview_db' or
* manually by altering settings.php to make $db_url an array with 'phpgedview'
* as one of the keys.
*
* @return TRUE if successful, FALSE if not.
*/
function phpgedview_pgv_connect() {
global $db_url;
if (!is_array($db_url)) {
$drupal_db = $db_url;
$db_url = array();
$db_url['default'] = $drupal_db;
}
if (!isset($db_url['phpgedview'])) {
$pgv_db = variable_get('phpgedview_db', 'mysql://username:password@localhost/databasename');
if (!empty($pgv_db) && $pgv_db != 'mysql://username:password@localhost/databasename') {
$db_url['phpgedview'] = $pgv_db;
}
}
if (empty($db_url['phpgedview'])) {
drupal_set_message(t('No PGV database connection information has been entered.'), 'error');
return FALSE;
}
if (!db_set_active('phpgedview')) {
drupal_set_message(t('Unable to access the PhpGedView database.'), 'error');
return FALSE;
}
else {
return TRUE;
}
}
/**
* Disconnect for the PGV database.
*/
function phpgedview_pgv_disconnect() {
db_set_active('default');
}