/[drupal]/contributions/modules/family/individual.inc
ViewVC logotype

Contents of /contributions/modules/family/individual.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Sat Dec 6 03:18:15 2008 UTC (11 months, 3 weeks ago) by pyutaros
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +4 -2 lines
File MIME type: text/x-php
#322607 by Microbe:  Ascendants and Descendants tabs appear on every node type
#326432 by Microbe:  New 6.x-1.0-beta2 instalation - warning: mysql_fetch_array()
#339263 by Microbe:  Misspelling of word "Birth" in table
#339265 by Microbe:  Marriage type fields requested, in addition to "Religious"
#331459 by Microbe:  GEDCOM data confused on import
1 <?php
2 // $Id: individual.inc,v 1.4.2.1 2008/10/09 01:55:57 pyutaros Exp $
3 /**
4 * Implementation of hook_access().
5 */
6 function family_individual_access($op, $node, $account) {
7 if ($op == 'create' ){
8 return user_access('create family nodes');
9 }
10 if($op == 'update' || $op == 'delete') {
11 if (user_access('edit own family nodes') && ($user->uid == $node->uid)) {
12 return TRUE;
13 }else{
14 return user_access('edit family nodes');
15 }
16 }
17 if ($op == 'view') {
18 return family_check_privacy($node->nid);
19 }
20 }
21
22 /**
23 * Implementation of hook_form().
24 */
25 function family_individual_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['FORE'] = array(
36 '#type' => 'textfield',
37 '#title' => t('Forename'),
38 '#default_value' => $node->FORE,
39 '#required' => FALSE,
40 );
41 $form['MIDN'] = array(
42 '#type' => 'textfield',
43 '#title' => t('Middle Names'),
44 '#default_value' => $node->MIDN,
45 '#required' => FALSE,
46 );
47 $form['SURN'] = array(
48 '#type' => 'textfield',
49 '#title' => t('Surname'),
50 '#default_value' => $node->SURN,
51 '#required' => FALSE,
52 );
53 $form['SEX'] = array(
54 '#type' => 'select',
55 '#title' => t('Gender'),
56 '#default_value' => $node->SEX,
57 '#options' => array(
58 '?' => 'Unknown',
59 'M' => 'Male',
60 'F' => 'Female'),
61 );
62 $ancestorgroups=array();
63 $groups=db_query('SELECT nid, title_format FROM {family_group}');
64 if($groups){
65 while($data = db_fetch_array($groups)){
66 $ancestorgroups[$data['nid']]=$data['title_format'];
67 }
68 }
69 $form['GRUP'] = array(
70 '#type' => 'select',
71 '#title' => t('Ancestry Group'),
72 '#default_value' => $node->GRUP,
73 '#options'=> array('' => 'None', 'Groups'=>$ancestorgroups),
74 );
75 $form['BIRT']['BIRT_DATE'] = array(
76 '#type' => 'textfield',
77 '#title' => t('Birth Date'),
78 '#description'=>t('Year-Month-Day YYYY-MM-DD'),
79 '#default_value' => $node->BIRT_DATE,
80 );
81 $form['BIRT']['BIRT_PLAC'] = array(
82 '#type' => 'textfield',
83 '#title' => t(' Birth Place'),
84 '#default_value' => $node->BIRT_PLAC,
85 );
86 $form['DEAT']['DEAT_DATE'] = array(
87 '#type' => 'textfield',
88 '#title' => t('Death Date'),
89 '#description'=>t('Year-Month-Day YYYY-MM-DD'),
90 '#default_value' => $node->DEAT_DATE,
91 );
92 $form['DEAT']['DEAT_PLAC'] = array(
93 '#type' => 'textfield',
94 '#title' => t('Death Place'),
95 '#default_value' => $node->DEAT_PLAC,
96 );
97 $form['body_filter']['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
98
99 $form['body_filter']['format'] = filter_form($node->format); //Not sure why this goes here, but all the examples have it...
100 return $form;
101 } // function family_individual_form(&$node, &$param)
102
103 /**
104 * Implementation of hook_insert().
105 * Insert All the facts and relationships
106 * Update Node and revision to replace data not in form
107 *
108 */
109 function family_individual_insert($node) {
110 $node->title = $node->FORE.' '.$node->SURN;
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 $birthdate=explode("-", $node->BIRT_DATE);
114 $node->title_format= (strtoupper($node->SURN)).', '.($node->FORE).' - '.$birthdate[0];
115
116 db_query("INSERT INTO {family_individual} (vid, nid, title_format, firstname, middlename, lastname, gender, birthdate, birthplace, deathdate, deathplace, ancestor_group) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $node->vid, $node->nid, $node->title_format, $node->FORE, $node->MIDN, $node->SURN, $node->SEX, $node->BIRT_DATE, $node->BIRT_PLAC,$node->DEAT_DATE, $node->DEAT_PLAC, $node->GRUP);
117
118 }
119
120 /**
121 * Implementation of family_individual_load().
122 * This function will grab all the descriptive data for an individual
123 * Primary use is for filling in form data to preform an edit
124
125 * Returns an array of additions
126 */
127 function family_individual_load($node) {
128 $nid = $node->nid;
129 $data = db_fetch_array(db_query("SELECT * FROM {family_individual} WHERE nid = %d",$nid));
130 $additions->title_format = $data['title_format'];
131 //NAME
132 $additions->SURN = $data['lastname'];
133 $additions->MIDN = $data['middlename'];
134 $additions->FORE = $data['firstname'];
135 $additions->NAME = $additions->FORE.' '.$additions->SURN;
136 //Gender
137 $gender = $data['gender'];
138 if ($gender) {$additions->SEX = $gender;}
139 //BIRTH
140 $birt_date = $data['birthdate'];
141 if ($birt_date!='0000-00-00 00:00:00') {
142 $value=explode(' ',$birt_date);
143 $value=$value[0];
144 $additions->BIRT_DATE = $value;
145 }
146 $birt_plac = $data['birthplace'];
147 if ($birt_plac) {
148 $additions->BIRT_PLAC = $birt_plac;
149 }
150 //DEATH
151 $deat_date = $data['deathdate'];
152 if ($deat_date!='0000-00-00 00:00:00') {
153 $value=explode(' ',$deat_date);
154 $value=$value[0];
155 $additions->DEAT_DATE = $value;
156 }
157 $deat_plac = $data['deathplace'];
158 if ($deat_plac){
159 $additions->DEAT_PLAC = $deat_plac;
160 }
161 $ans_grup = $data['ancestor_group'];
162 if ($ans_grup) {
163 $additions->GRUP = $ans_grup;
164 }
165 return($additions);
166 }
167 /**
168 * Implementation of hook_update().
169 * Update the facts and new relationships
170 * Update Node and revision to replace data not in form
171 *
172 * See family_individual_insert
173 */
174 function family_individual_update($node) {
175 $node->title = $node->FORE.' '.$node->SURN;
176 db_query("UPDATE {node} SET title='%s' WHERE nid='%d'",$node->title,$node->nid);
177 db_query("UPDATE {node_revisions} SET title='%s' WHERE nid='%d' AND vid='%d'",$node->title, $node->nid, $node->vid);
178 db_query("UPDATE {node} SET title='%s' WHERE nid='%d'",$node->title,$node->nid);
179 $birthdate=explode("-", $node->BIRT_DATE);
180 $node->title_format=(strtoupper($node->SURN)).', '.($node->FORE).' - '.$birthdate[0];
181 db_query("UPDATE {family_individual} SET vid='%d', title_format='%s', firstname='%s', middlename='%s', lastname='%s', gender='%s', birthdate='%s', birthplace='%s', deathdate='%s', deathplace='%s', ancestor_group='%s' WHERE nid='%d'",
182 $node->vid, $node->title_format, $node->FORE, $node->MIDN, $node->SURN, $node->SEX, $node->BIRT_DATE, $node->BIRT_PLAC,$node->DEAT_DATE, $node->DEAT_PLAC, $node->GRUP, $node->nid);
183 }
184
185 /**
186 * Implementation of hook_view().
187 */
188 function family_individual_view(&$node, $teaser = FALSE, $page = FALSE) {
189 $node = node_prepare($node, $teaser);
190 if($teaser){
191 $node->content['family_individual_view'] = array(
192 '#value' => theme('family_individual_teaser', $node),
193 '#weight' => -1,
194 );
195 }else{
196 $node->content['family_individual_view'] = array(
197 '#value' => theme('family_individual_body', $node),
198 '#weight' => -1,
199 );
200 }
201 return $node;
202 }
203 function family_theme() {
204 return array(
205 'family_individual_teaser' => array(
206 'arguments' => array('node'),
207 ),
208 'family_individual_body' => array(
209 'arguments' => array('node'),
210 ),
211 'family_group_teaser' => array(
212 'arguments' => array('node'),
213 ),
214 'family_group_body' => array(
215 'arguments' => array('node'),
216 ),
217 'family_location_teaser' => array(
218 'arguments' => array('node'),
219 ),
220 'family_location_body' => array(
221 'arguments' => array('node'),
222 ),
223 );
224 }
225 function theme_family_individual_teaser($node) {
226 $content = family_view_indi($node->nid,'0');
227 return $content;
228 }
229 function theme_family_individual_body($node) {
230 $content = family_view_indi($node->nid,'1');
231 return $content;
232 }
233 /**
234 * Implementation of hook_delete().
235 */
236 function family_individual_delete(&$node) {
237 // $ind_fid = db_result(db_query("SELECT fid FROM {family_facts} WHERE nid = %d",$node->nid));
238 //family_remove_fact($node->nid);
239 db_query("DELETE FROM {family_individual} WHERE nid=%d",$node->nid);
240 }
241
242 /**
243 * Just so we don't have to keep formatting a name over and over
244 */
245 function family_get_display_name($name){
246 $name_arr['NAME']=$name_arr['GIVN'].' '.$name_arr['SURN'];
247 return $name_arr;
248 }

  ViewVC Help
Powered by ViewVC 1.1.2