| 1 |
<?php
|
| 2 |
// $Id: family.module,v 1.10.2.1 2008/10/09 01:55:57 pyutaros Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Family module - display and manage family tree data
|
| 6 |
*
|
| 7 |
* Current features:
|
| 8 |
* - Individuals saved as nodes
|
| 9 |
* - Editing for Individuals records
|
| 10 |
* - Groups saved as nodes
|
| 11 |
* - Editing for Groups records
|
| 12 |
* - Locations saved as nodes
|
| 13 |
* - Editing for Locations records
|
| 14 |
*/
|
| 15 |
|
| 16 |
$path = drupal_get_path('module', 'family');
|
| 17 |
require_once "$path/import.inc";
|
| 18 |
require_once "$path/view.inc";
|
| 19 |
require_once "$path/family.views.inc";
|
| 20 |
require_once "$path/family.views_default.inc";
|
| 21 |
require_once "$path/EstimateDates.inc";
|
| 22 |
require_once "$path/individual.inc";
|
| 23 |
require_once "$path/location.inc";
|
| 24 |
// require_once "$path/source.inc";
|
| 25 |
require_once "$path/group.inc";
|
| 26 |
require_once "$path/tree.inc";
|
| 27 |
require_once "$path/common.inc";
|
| 28 |
|
| 29 |
|
| 30 |
/**
|
| 31 |
* Implementation of hook_menu().
|
| 32 |
*/
|
| 33 |
function family_menu() {
|
| 34 |
$items = array();
|
| 35 |
$items['admin/content/family_import'] = array(
|
| 36 |
'title' => 'Family Import',
|
| 37 |
'description' => 'Import your family tree from a standard GED file.',
|
| 38 |
'page callback' => 'family_import',
|
| 39 |
'access arguments' => array('administer family'),
|
| 40 |
);
|
| 41 |
$items['admin/content/family_import_done'] = array(
|
| 42 |
'title' => 'Family Import',
|
| 43 |
'description' => 'Import your family tree from a standard GED file.',
|
| 44 |
'page callback' => 'family_import_done',
|
| 45 |
'access arguments' => array('administer family'),
|
| 46 |
'type' => MENU_CALLBACK,
|
| 47 |
);
|
| 48 |
/* $items['admin/settings/family_privacy'] = array(
|
| 49 |
* 'title' => 'Family Privacy',
|
| 50 |
* 'description' => 'Protect your important family data by running this privacy script',
|
| 51 |
* 'page callback' => 'family_auto_privacy',
|
| 52 |
* 'access arguments' => array('administer family'),
|
| 53 |
* );
|
| 54 |
* $items['admin/content/family_privacy_done'] = array(
|
| 55 |
* 'title' => 'Family Import',
|
| 56 |
* 'description' => 'Import your family tree from a standard GED file.',
|
| 57 |
* 'page callback' => 'family_auto_privacy_done',
|
| 58 |
* 'access arguments' => array('administer family'),
|
| 59 |
* 'type' => MENU_CALLBACK,
|
| 60 |
* );
|
| 61 |
*/ $items['node/%/tree/asc'] = array(
|
| 62 |
'title' => 'Ascendants',
|
| 63 |
'page callback' => 'family_view_tree_asc',
|
| 64 |
'page arguments' => array(1),
|
| 65 |
'type' => MENU_LOCAL_TASK,
|
| 66 |
'access callback' => 'family_individual_check_type',
|
| 67 |
'access arguments' => array(1),
|
| 68 |
);
|
| 69 |
$items['node/%/tree/desc'] = array(
|
| 70 |
'title' => 'Descendants',
|
| 71 |
'page callback' => 'family_view_tree_desc',
|
| 72 |
'page arguments' => array(1),
|
| 73 |
'type' => MENU_LOCAL_TASK,
|
| 74 |
'access callback' => 'family_individual_check_type',
|
| 75 |
'access arguments' => array(1),
|
| 76 |
);
|
| 77 |
return $items;
|
| 78 |
} // function family_menu()
|
| 79 |
|
| 80 |
function family_individual_check_type($nid){
|
| 81 |
if(is_numeric($nid)){
|
| 82 |
$node = node_load($nid);
|
| 83 |
if($node->type == 'family_individual'){
|
| 84 |
return TRUE;
|
| 85 |
}
|
| 86 |
}
|
| 87 |
return FALSE;
|
| 88 |
}
|
| 89 |
|
| 90 |
/**
|
| 91 |
* Implementation of hook_info().
|
| 92 |
*/
|
| 93 |
function family_node_info() {
|
| 94 |
return array(
|
| 95 |
'family_individual' => array(
|
| 96 |
'name' => t('Family: Individual'),
|
| 97 |
'module' => 'family_individual',
|
| 98 |
'description' => t('A node representing a person.'),
|
| 99 |
'has_title' => TRUE,
|
| 100 |
'title_label' => t('Title'),
|
| 101 |
'has_body' => TRUE,
|
| 102 |
'body_label' => t('Biography'),
|
| 103 |
),
|
| 104 |
'family_group' => array(
|
| 105 |
'name' => t('Family: Group'),
|
| 106 |
'module' => 'family_group',
|
| 107 |
'description' => t('A node representing a single grouping of parents and children.'),
|
| 108 |
'has_title' => TRUE,
|
| 109 |
'title_label' => t('Title'),
|
| 110 |
'has_body' => TRUE,
|
| 111 |
'body_label' => t('Body'),
|
| 112 |
),
|
| 113 |
'family_location' => array(
|
| 114 |
'name' => t('Family: Location'),
|
| 115 |
'module' => 'family_location',
|
| 116 |
'description' => t('A geneological location.'),
|
| 117 |
'has_title' => TRUE,
|
| 118 |
'title_label' => t('Title'),
|
| 119 |
'has_body' => TRUE,
|
| 120 |
'body_label' => t('Body'),
|
| 121 |
),
|
| 122 |
);
|
| 123 |
}
|
| 124 |
|
| 125 |
/**
|
| 126 |
* Display help and module information
|
| 127 |
* @param section which section of the site we're displaying help
|
| 128 |
* @return help text for section
|
| 129 |
*/
|
| 130 |
function family_help($path, $arg) {
|
| 131 |
$output = '';
|
| 132 |
switch ($path) {
|
| 133 |
case "admin/modules#description":
|
| 134 |
$output = t("A jolly exciting module for recording and archiving all
|
| 135 |
aspects of your family's history.");
|
| 136 |
break;
|
| 137 |
case "node/add#family_individual":
|
| 138 |
$output = t("A record of a single person. Part of the Family module.");
|
| 139 |
break;
|
| 140 |
case "node/add#family_group":
|
| 141 |
$output = t("A record of a single grouping of parents and their children. Part of the family module");
|
| 142 |
break;
|
| 143 |
case "node/add#family_location":
|
| 144 |
$output = t("A record of a single location, which may be contained
|
| 145 |
in other locations in a hierarchy. Part of the Family
|
| 146 |
module.");
|
| 147 |
break;
|
| 148 |
}
|
| 149 |
return $output;
|
| 150 |
} // function family_help($section='')
|
| 151 |
|
| 152 |
/**
|
| 153 |
* Implementation of hook_perm().
|
| 154 |
*/
|
| 155 |
function family_perm() {
|
| 156 |
return array(
|
| 157 |
'access family nodes',
|
| 158 |
'access family private records',
|
| 159 |
'create family nodes',
|
| 160 |
'edit family nodes',
|
| 161 |
'edit own family nodes',
|
| 162 |
'administer family'
|
| 163 |
);
|
| 164 |
} // function family_perm()
|
| 165 |
|
| 166 |
/**
|
| 167 |
* Implementation of hook_access().
|
| 168 |
*/
|
| 169 |
function family_access($op, $node, $account) {
|
| 170 |
global $user;
|
| 171 |
|
| 172 |
if ($op == 'create') {
|
| 173 |
return user_access('create family nodes');
|
| 174 |
}
|
| 175 |
|
| 176 |
if ($op == 'update' || $op == 'delete') {
|
| 177 |
if (user_access('edit own family nodes') && ($user->uid == $node->uid)) {
|
| 178 |
return TRUE;
|
| 179 |
}
|
| 180 |
if (user_access('edit family nodes')) {
|
| 181 |
return TRUE;
|
| 182 |
}
|
| 183 |
}
|
| 184 |
if ($op == 'view') {
|
| 185 |
return (user_access('access family nodes'));
|
| 186 |
}
|
| 187 |
} // function family_access()
|
| 188 |
|
| 189 |
/**
|
| 190 |
* Implementation of hook_user().
|
| 191 |
*/
|
| 192 |
function family_user($type, &$edit, &$user) {
|
| 193 |
|
| 194 |
switch ($type) {
|
| 195 |
|
| 196 |
case ('insert'):
|
| 197 |
case ('update'):
|
| 198 |
case ('submit'):
|
| 199 |
case ('login'):
|
| 200 |
case ('logout'):
|
| 201 |
case ('delete'):
|
| 202 |
break;
|
| 203 |
|
| 204 |
case ('form'):
|
| 205 |
if($edit['family_tree_root']==''){
|
| 206 |
$edit['family_tree_root']=$edit['family_link'];
|
| 207 |
}
|
| 208 |
if($edit['family_tree_depth']==''){
|
| 209 |
$edit['family_tree_depth']=3;
|
| 210 |
}
|
| 211 |
$form['family'] = array(
|
| 212 |
'#type' => 'fieldset',
|
| 213 |
'#title' => t('Family association'),
|
| 214 |
'#collapsible' => TRUE,
|
| 215 |
'#weight' => 4);
|
| 216 |
$results = db_query("SELECT * FROM {family_individual}");
|
| 217 |
$listoptionsalive=array();
|
| 218 |
while($indi = db_fetch_array($results)){
|
| 219 |
//$deathfacts = family_getfacts($indi['fid']);
|
| 220 |
if(($indi['deathdate'])==''||($indi['deathdate'])=='0000-00-00 00:00:00'){
|
| 221 |
$listoptionsalive[$indi['nid']]=$indi['title_format'];
|
| 222 |
}
|
| 223 |
}
|
| 224 |
$results = db_query("SELECT * FROM {family_individual}");
|
| 225 |
$listoptions=array();
|
| 226 |
while($indi = db_fetch_array($results)){
|
| 227 |
$listoptions[$indi['nid']]=$indi['title_format'];
|
| 228 |
}
|
| 229 |
|
| 230 |
$form['family']['family_link'] = array(
|
| 231 |
'#type' => 'select',
|
| 232 |
'#options'=>array(''=>'None of these','Individuals'=>$listoptionsalive,),
|
| 233 |
'#title' => t('My family link'),
|
| 234 |
'#default_value' => $edit['family_link'],
|
| 235 |
'#description' => t('Choose the person that represents you in the family tree'));
|
| 236 |
$form['family']['family_tree_root'] = array(
|
| 237 |
'#type' => 'select',
|
| 238 |
'#options'=>array(''=>'None of these','Individuals'=>$listoptions,),
|
| 239 |
'#title' => t('Tree root individual'),
|
| 240 |
'#default_value' => $edit['family_tree_root'],
|
| 241 |
'#description' => t('Choose the person that you want the tree that is linked to your profile to be based on'));
|
| 242 |
$form['family']['family_tree_type'] = array(
|
| 243 |
'#type' => 'select',
|
| 244 |
'#options' => array(
|
| 245 |
'asc' => 'Ancestry',
|
| 246 |
'desc' => 'Descendency',
|
| 247 |
),
|
| 248 |
'#default_value' => $edit['family_tree_type'],
|
| 249 |
'#description' => t('The type of tree that you profile tree is based on'));
|
| 250 |
$form['family']['family_tree_depth'] = array(
|
| 251 |
'#type' => 'textfield',
|
| 252 |
'#title' => t('Generations in tree'),
|
| 253 |
'#default_value' => $edit['family_tree_depth'],
|
| 254 |
'#description' => t('The number of degrees to show on your profile family tree.'));
|
| 255 |
|
| 256 |
|
| 257 |
return $form;
|
| 258 |
break;
|
| 259 |
case ('view'):
|
| 260 |
$user->content['family'] = array(
|
| 261 |
'#type' => 'user_profile_category',
|
| 262 |
'#title' => t("Family Association"),
|
| 263 |
'#weight' => 3,
|
| 264 |
);
|
| 265 |
$user->content['family']['link'] = array(
|
| 266 |
'#type' => 'user_profile_item',
|
| 267 |
'#title' => t("My family link"),
|
| 268 |
'#value' => l("Me","node/".$user->family_link),
|
| 269 |
'#weight' => 1,
|
| 270 |
);
|
| 271 |
|
| 272 |
$user->content['family']['tree'] = array(
|
| 273 |
'#type' => 'user_profile_item',
|
| 274 |
'#title' => t("My Tree"),
|
| 275 |
'#value' => l( "My Tree","node/".$user->family_tree_root."/tree/".$user->family_tree_type, array('html'=>'TRUE','query'=>'len='.$user->family_tree_depth)),
|
| 276 |
'#weight' => 2,
|
| 277 |
);
|
| 278 |
}
|
| 279 |
}
|
| 280 |
/**
|
| 281 |
* Check if record $nid is private.
|
| 282 |
*/
|
| 283 |
function family_check_privacy($nid) {
|
| 284 |
$privacy=db_result(db_query("SELECT privacy FROM {family_individual} WHERE nid=%d",$nid));
|
| 285 |
if($privacy){
|
| 286 |
|
| 287 |
}else {
|
| 288 |
$privacy=0;
|
| 289 |
}
|
| 290 |
if (($privacy==1) || ($privacy==3)) {
|
| 291 |
return user_access('access family');
|
| 292 |
} else {
|
| 293 |
return user_access('access family private records');
|
| 294 |
}
|
| 295 |
}
|
| 296 |
/**
|
| 297 |
* Implementation of the token.module's hook_token_values().
|
| 298 |
*
|
| 299 |
* @param $type
|
| 300 |
* The current context -- 'node', 'user', 'global', etc.
|
| 301 |
* @param $object
|
| 302 |
* The specific node, user, etc. that should be used as the basis for the
|
| 303 |
* replacements.
|
| 304 |
* @return
|
| 305 |
* Array of tokens.
|
| 306 |
*/
|
| 307 |
function family_token_values($type, $object = NULL, $options = array()) {
|
| 308 |
if ($type == 'node' && $node->type == 'family_individual') {
|
| 309 |
$node = $object;
|
| 310 |
$tokens['family-individual-firstname'] = check_plain($node->FORE);
|
| 311 |
$tokens['family-individual-middlename'] = check_plain($node->MIDN);
|
| 312 |
$tokens['family-individual-lastname'] = check_plain($node->SURN);
|
| 313 |
$tokens['family-individual-birthdate'] = check_plain($node->BIRT_DATE);
|
| 314 |
$tokens['family-individual-birthplace'] = check_plain($node->BIRT_PLACE);
|
| 315 |
return $tokens;
|
| 316 |
}
|
| 317 |
if ($type == 'node' && $node->type == 'family_group') {
|
| 318 |
$node = $object;
|
| 319 |
$tokens['family-group-uniontype'] = check_plain($node->MARR_TYPE);
|
| 320 |
$tokens['family-group-unionplace'] = check_plain($node->MARR_PLAC);
|
| 321 |
$tokens['family-group-uniondate'] = check_plain($node->MARR_DATE);
|
| 322 |
$tokens['family-group-parent1'] = check_plain($node->PAR1);
|
| 323 |
$tokens['family-group-parent2'] = check_plain($node->PAR2);
|
| 324 |
return $tokens;
|
| 325 |
}
|
| 326 |
} //function family_token_values
|