| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Implementation of hook_access().
|
| 4 |
*/
|
| 5 |
function family_group_access($op, $node, $account) {
|
| 6 |
if ($op == 'create' ){
|
| 7 |
return user_access('create family nodes');
|
| 8 |
}
|
| 9 |
if($op == 'update' || $op == 'delete') {
|
| 10 |
if (user_access('edit own family nodes') && ($user->uid == $node->uid)) {
|
| 11 |
return TRUE;
|
| 12 |
}else{
|
| 13 |
return user_access('edit family nodes');
|
| 14 |
}
|
| 15 |
}
|
| 16 |
if ($op == 'view') {
|
| 17 |
//return family_check_privacy($node->nid);
|
| 18 |
return user_access('access family nodes');
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_form().
|
| 24 |
*/
|
| 25 |
function family_group_form(&$node) {
|
| 26 |
$type = node_get_types('type', $node);
|
| 27 |
|
| 28 |
if ($type->has_title) {
|
| 29 |
$form['title'] = array(
|
| 30 |
'#title' => check_plain($type->title_label),
|
| 31 |
'#type' => 'hidden',
|
| 32 |
'#default_value' => $node->NAME,
|
| 33 |
);
|
| 34 |
}
|
| 35 |
$form['MARR']['MARR_TYPE'] = array(
|
| 36 |
'#type' => 'select',
|
| 37 |
'#title' => t('Type of Union'),
|
| 38 |
'#default_value' => $node->MARR_TYPE,
|
| 39 |
'#options' => array(
|
| 40 |
'Unmarried' => 'Unmarried',
|
| 41 |
'Religious' => 'Religious',
|
| 42 |
'Common Law' => 'Common Law',
|
| 43 |
'Civil' => 'Civil',
|
| 44 |
),
|
| 45 |
);
|
| 46 |
$form['MARR']['MARR_DATE'] = array(
|
| 47 |
'#type' => 'textfield',
|
| 48 |
'#title' => t('Date of Union'),
|
| 49 |
'#description'=>t('Year-Month-Day YYYY-MM-DD'),
|
| 50 |
'#default_value' => $node->MARR_DATE,
|
| 51 |
);
|
| 52 |
$form['MARR']['MARR_PLAC'] = array(
|
| 53 |
'#type' => 'textfield',
|
| 54 |
'#title' => t('Place of Union'),
|
| 55 |
'#default_value' => $node->MARR_PLAC,
|
| 56 |
);
|
| 57 |
$form['MARR']['DIV_DATE'] = array(
|
| 58 |
'#type' => 'textfield',
|
| 59 |
'#title' => t('Date of Separation'),
|
| 60 |
'#description'=>t('Year-Month-Day YYYY-MM-DD'),
|
| 61 |
'#default_value' => $node->DIV_DATE,
|
| 62 |
);
|
| 63 |
$form['MARR']['DIV_PLAC'] = array(
|
| 64 |
'#type' => 'textfield',
|
| 65 |
'#title' => t('Place of Separation'),
|
| 66 |
'#default_value' => $node->DIV_PLAC,
|
| 67 |
);
|
| 68 |
$parents=array();
|
| 69 |
$indivs=db_query('SELECT nid, title_format FROM {family_individual}');
|
| 70 |
if($indivs){
|
| 71 |
while($data = db_fetch_array($indivs)){
|
| 72 |
$parents[$data['nid']]=$data['title_format'];
|
| 73 |
}
|
| 74 |
}
|
| 75 |
$form['PAR1'] = array(
|
| 76 |
'#type' => 'select',
|
| 77 |
'#title' => t('Parent 1'),
|
| 78 |
'#description'=>t('The parent whose last name is carried by the children.'),
|
| 79 |
'#default_value' => $node->PAR1,
|
| 80 |
'#options'=> array('' => 'Unknown', 'Individuals'=>$parents),
|
| 81 |
);
|
| 82 |
$form['PAR2'] = array(
|
| 83 |
'#type' => 'select',
|
| 84 |
'#title' => t('Parent 2'),
|
| 85 |
'#default_value' => $node->PAR2,
|
| 86 |
'#options'=> array('' => 'Unknown', 'Individuals'=>$parents),
|
| 87 |
);
|
| 88 |
$form['body_filter']['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
|
| 89 |
$form['body_filter']['format'] = filter_form($node->format); //Not sure why this goes here, but all the examples have it...
|
| 90 |
return $form;
|
| 91 |
} // function family_group_form(&$node, &$param)
|
| 92 |
|
| 93 |
function family_group_insert($node) {
|
| 94 |
$parent1first=db_result(db_query("SELECT firstname FROM {family_individual} WHERE nid='%d'",$node->PAR1));
|
| 95 |
$parent1last=db_result(db_query("SELECT lastname FROM {family_individual} WHERE nid='%d'",$node->PAR1));
|
| 96 |
$parent2=db_result(db_query("SELECT firstname FROM {family_individual} WHERE nid='%d'",$node->PAR2));
|
| 97 |
$node->title_format = ($parent1first).' and '.($parent2).' '.($parent1last);
|
| 98 |
$node->title=$node->title_format;
|
| 99 |
db_query("UPDATE {node} SET title='%s' WHERE nid='%d'",$node->title, $node->nid);
|
| 100 |
db_query("UPDATE {node_revisions} SET title='%s' WHERE nid='%d' AND vid='%d'",$node->title, $node->nid, $node->vid);
|
| 101 |
db_query("INSERT INTO {family_group} (vid, nid, title_format, marr_type, marr_date, marr_plac, div_date, div_plac, parent1, parent2) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
|
| 102 |
$node->vid, $node->nid, $node->title_format, $node->MARR_TYPE, $node->MARR_DATE, $node->MARR_PLAC, $node->DIV_DATE, $node->DIV_PLAC,$node->PAR1, $node->PAR2);
|
| 103 |
|
| 104 |
}
|
| 105 |
function family_group_update($node) {
|
| 106 |
$parent1first=db_result(db_query("SELECT firstname FROM {family_individual} WHERE nid='%d'",$node->PAR1));
|
| 107 |
$parent1last=db_result(db_query("SELECT lastname FROM {family_individual} WHERE nid='%d'",$node->PAR1));
|
| 108 |
$parent2=db_result(db_query("SELECT firstname FROM {family_individual} WHERE nid='%d'",$node->PAR2));
|
| 109 |
$node->title_format = ($parent1first).' and '.($parent2).' '.($parent1last);
|
| 110 |
$node->title=$node->title_format;
|
| 111 |
db_query("UPDATE {node} SET title='%s' WHERE nid='%d'",$node->title, $node->nid);
|
| 112 |
db_query("UPDATE {node_revisions} SET title='%s' WHERE nid='%d' AND vid='%d'",$node->title, $node->nid, $node->vid);
|
| 113 |
db_query("UPDATE {family_group} SET vid='%d', title_format='%s', marr_type='%s', marr_date='%s', marr_plac='%s', div_date='%s', div_plac='%s', parent1='%s', parent2='%s' WHERE nid='%d'",
|
| 114 |
$node->vid, $node->title_format, $node->MARR_TYPE, $node->MARR_DATE, $node->MARR_PLAC, $node->DIV_DATE, $node->DIV_PLAC,$node->PAR1, $node->PAR2, $node->nid);
|
| 115 |
|
| 116 |
}
|
| 117 |
function family_group_load($node) {
|
| 118 |
$nid = $node->nid;
|
| 119 |
$data = db_fetch_array(db_query("SELECT * FROM {family_group} WHERE nid = %d",$nid));
|
| 120 |
$parent1=db_fetch_array(db_query("SELECT firstname,lastname FROM {family_individual} WHERE nid=%d",$node->PAR1));
|
| 121 |
$parent2=db_fetch_array(db_query("SELECT firstname FROM {family_individual} WHERE nid=%d",$node->PAR2));
|
| 122 |
$additions->NAME = $parent1['firstname'].' and '.$parent2['firstname'].' '.$parent1['$lastname'];
|
| 123 |
$additions->title_format = $data['title_format'];
|
| 124 |
$additions->MARR_TYPE = $data['marr_type'];
|
| 125 |
//Marriage data
|
| 126 |
if ($data['marr_date']!='0000-00-00 00:00:00') {
|
| 127 |
$value=explode(' ',$data['marr_date']);
|
| 128 |
$value=$value[0];
|
| 129 |
$additions->MARR_DATE = $value;
|
| 130 |
}
|
| 131 |
$additions->MARR_PLAC = $data['marr_plac'];
|
| 132 |
//Divorce data
|
| 133 |
if ($data['div_date']!='0000-00-00 00:00:00') {
|
| 134 |
$value=explode(' ',$data['div_date']);
|
| 135 |
$value=$value[0];
|
| 136 |
$additions->DIV_DATE = $value;
|
| 137 |
}
|
| 138 |
$additions->DIV_PLAC = $data['div_plac'];
|
| 139 |
//Parents of the group
|
| 140 |
$additions->PAR1 = $data['parent1'];
|
| 141 |
$additions->PAR2 = $data['parent2'];
|
| 142 |
|
| 143 |
return($additions);
|
| 144 |
}
|
| 145 |
function family_group_view(&$node, $teaser = FALSE, $page = FALSE) {
|
| 146 |
$node = node_prepare($node, $teaser);
|
| 147 |
$node->content['family_group_view'] = array(
|
| 148 |
'#value' => theme($teaser? 'family_group_teaser':'family_group_body', $node),
|
| 149 |
'#weight' => -1,
|
| 150 |
);
|
| 151 |
|
| 152 |
return $node;
|
| 153 |
}
|
| 154 |
function theme_family_group_teaser($node) {
|
| 155 |
return family_view_unison($node->nid,'0');
|
| 156 |
}
|
| 157 |
function theme_family_group_body($node) {
|
| 158 |
return family_view_unison($node->nid,'1');
|
| 159 |
}
|
| 160 |
function family_group_delete(&$node) {
|
| 161 |
db_query("DELETE FROM {family_group} WHERE nid=%d",$node->nid);
|
| 162 |
}
|
| 163 |
function family_summ_group($nid){
|
| 164 |
$family=db_fetch_array(db_query("SELECT * FROM {family_location} WHERE nid='%d'",$nid));
|
| 165 |
$list1=array();
|
| 166 |
if($family['marr_type']){
|
| 167 |
$list1[] ='Marriage Type: '.$family['marr_type'];
|
| 168 |
}
|
| 169 |
if($family['marr_date']){
|
| 170 |
$list1[] ='Marriage Date: '.$family['marr_date'];
|
| 171 |
}
|
| 172 |
|
| 173 |
if($family['marr_plac']){
|
| 174 |
$list1[] ='Marriage Place: '.family_make_location($family['marr_plac']);
|
| 175 |
}
|
| 176 |
if($family['div_date']){
|
| 177 |
$list1[] ='Divorce Date: '.$family['div_date'];
|
| 178 |
}
|
| 179 |
if($family['div_place']){
|
| 180 |
$list1[] ='Divorce Place: '.family_make_location($family['div_plac']);
|
| 181 |
}
|
| 182 |
|
| 183 |
return theme('item_list', $list1);
|
| 184 |
|
| 185 |
}
|
| 186 |
function family_view_unison($nid,$type){
|
| 187 |
$content="";
|
| 188 |
$content .= family_summ_group ($nid);
|
| 189 |
$data=db_fetch_array(db_query("SELECT * FROM {family_group} WHERE nid='%d'",$nid));
|
| 190 |
|
| 191 |
//Find children of the family group
|
| 192 |
$children = db_query("SELECT * FROM {family_individual} WHERE ancestor_group = %d", $nid);
|
| 193 |
if($children){
|
| 194 |
$content .= '<p>Children of '. family_make_name($data['parent1'],TRUE).' and '.family_make_name($data['parent2'],TRUE).':</p>';
|
| 195 |
$content .= '<p><table width=100% border=1><tr><td>Name</td><td>Gender</td><td>Birth Date</td><td>Death Date</td></tr>';
|
| 196 |
while ($child = db_fetch_array($children)) {
|
| 197 |
$content .= "<tr><td>".family_make_name($child['nid'],TRUE)."</td><td>".$child['gender']."</td><td>".$child['birthdate']."</td><td>".$child['deathdate']."</td></tr>";
|
| 198 |
}
|
| 199 |
$content.="</table>";
|
| 200 |
}
|
| 201 |
return $content;
|
| 202 |
}
|