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

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

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


Revision 1.4 - (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.3: +1 -1 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: location.inc,v 1.2.2.2 2008/10/18 02:28:04 pyutaros Exp $
3 /**
4 * Implementation of hook_access().
5 */
6 function family_location_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 return user_access('access family nodes');
20 }
21 }
22
23 /**
24 * Implementation of hook_form().
25 */
26 function family_location_form(&$node) {
27 $type = node_get_types('type', $node);
28
29 if ($type->has_title) {
30 $form['title'] = array(
31 '#title' => check_plain($type->title_label),
32 '#type' => 'hidden',
33 '#default_value' => $node->NAME,
34 );
35 }
36 $form['BUILD'] = array(
37 '#type' => 'textfield',
38 '#title' => t('Building'),
39 '#default_value' => $node->BUILD,
40 '#required' => FALSE,
41 );
42 $form['STREET'] = array(
43 '#type' => 'textfield',
44 '#title' => t('Street'),
45 '#default_value' => $node->STREET,
46 '#required' => FALSE,
47 );
48 $form['CITY'] = array(
49 '#type' => 'textfield',
50 '#title' => t('City'),
51 '#default_value' => $node->CITY,
52 '#required' => FALSE,
53 );
54 $form['COUNTY'] = array(
55 '#type' => 'textfield',
56 '#title' => t('County'),
57 '#default_value' => $node->COUNTY,
58 '#required' => FALSE,
59 );
60 $form['STATE_PROV'] = array(
61 '#type' => 'textfield',
62 '#title' => t('State or Province'),
63 '#default_value' => $node->STATE_PROV,
64 '#required' => FALSE,
65 );
66 $form['COUNTRY'] = array(
67 '#type' => 'textfield',
68 '#title' => t('Country'),
69 '#default_value' => $node->COUNTRY,
70 '#required' => FALSE,
71 );
72 $ancestorgroups=array();
73 $groups=db_query('SELECT nid, title_format FROM {family_group}');
74 while($data = db_fetch_array($groups)){
75 $ancestorgroups[$data['nid']]=$data['title_format'];
76 }
77 $form['GRUP'] = array(
78 '#type' => 'select',
79 '#title' => t('Ancestry Group'),
80 '#default_value' => $node->GRUP,
81 '#options'=> array('' => 'None', 'Groups'=>$ancestorgroups),
82 );
83 $form['body_filter']['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
84
85
86 $form['body_filter']['format'] = filter_form($node->format); //Not sure why this goes here, but all the examples have it...
87 return $form;
88 } // function family_individual_form(&$node, &$param)
89
90 /**
91 * Implementation of hook_insert().
92 * Insert All the facts and relationships
93 * Update Node and revision to replace data not in form
94 *
95 */
96 function family_location_insert($node) {
97 if($node->BUILD||$node->STREET){
98 $node->title = $node->BUILD." ".$node->STREET;
99 }elseif($node->CITY){
100 $node->title = $node->CITY;
101 }elseif($node->COUNTY){
102 $node->title = $node->COUNTY;
103 }elseif($node->STATE_PROV){
104 $node->title = $node->STATE_PROV;
105 }else{
106 $node->title = $node->COUNTRY;
107 }
108 db_query("UPDATE {node} SET title='%s' WHERE nid='%d'",$node->title,$node->nid);
109 db_query("UPDATE {node_revisions} SET title='%s' WHERE nid='%d' AND vid='%d'",$node->title, $node->nid, $node->vid);
110 $node->title_format= $node->BUILD;
111 db_query("INSERT INTO {family_location} (vid, nid, title_format, building, street, city, county, state_province, country, related_group) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
112 $node->vid, $node->nid, $node->title_format, $node->BUILD, $node->STREET, $node->CITY, $node->COUNTY, $node->STATE_PROV, $node->COUNTRY, $node->GRUP);
113
114 }
115
116 /**
117 * Implementation of family_individual_load().
118 * This function will grab all the descriptive data for an individual
119 * Primary use is for filling in form data to preform an edit
120
121 * Returns an array of additions
122 */
123 function family_location_load($node) {
124 $nid = $node->nid;
125 $data = db_fetch_array(db_query("SELECT * FROM {family_location} WHERE nid = %d",$nid));
126 $additions->title_format = $data['title_format'];
127 $additions->NAME = $data['title_format'];
128 //Address
129 $additions->BUILD = $data['building'];
130 $additions->STREET = $data['street'];
131 $additions->CITY = $data['city'];
132 $additions->COUNTY = $data['county'];
133 $additions->STATE_PROV = $data['state_province'];
134 $additions->COUNTRY = $data['country'];
135 $additions->GRUP = $data['related_group'];
136 return($additions);
137 }
138 /**
139 * Implementation of hook_update().
140 * Update the facts and new relationships
141 * Update Node and revision to replace data not in form
142 *
143 * See family_individual_insert
144 */
145 function family_location_update($node) {
146 if($node->BUILD||$node->STREET){
147 $node->title = $node->BUILD." ".$node->STREET;
148 }elseif($node->CITY){
149 $node->title = $node->CITY;
150 }elseif($node->COUNTY){
151 $node->title = $node->COUNTY;
152 }elseif($node->STATE_PROV){
153 $node->title = $node->STATE_PROV;
154 }else{
155 $node->title = $node->COUNTRY;
156 }
157
158 db_query("UPDATE {node} SET title='%s' WHERE nid='%d'",$node->title,$node->nid);
159 db_query("UPDATE {node_revisions} SET title='%s' WHERE nid='%d' AND vid='%d'",$node->title, $node->nid, $node->vid);
160 $node->title_format= $node->BUILD;
161 db_query("UPDATE {family_location} SET vid='%d', title_format='%s', building='%s', street='%s', city='%s', county='%s', state_province='%s', country='%s', related_group='%d' WHERE nid='%d'",
162 $node->vid, $node->title_format, $node->BUILD, $node->STREET, $node->CITY, $node->COUNTY, $node->STATE_PROV, $node->COUNTRY, $node->GRUP, $node->nid);
163
164 }
165
166 /**
167 * Implementation of hook_view().
168 */
169 function family_location_view(&$node, $teaser = FALSE, $page = FALSE) {
170 $node = node_prepare($node, $teaser);
171 // $fid = db_result(db_query("SELECT fid FROM {family_facts} WHERE nid= %d", $node->nid));
172 // $node->body = family_view_indi($node->fid) . $node->body;
173 // $node->teaser = family_view_indi($node->fid) . $node->teaser;
174 $node->content['family_location_view'] = array(
175 '#value' => theme($teaser? 'family_location_teaser':'family_location_body', $node),
176 '#weight' => -1,
177 );
178
179 return $node;
180 }
181 function theme_family_location_teaser($node) {
182 return family_view_loca($node->nid,'0');
183 }
184 function theme_family_location_body($node) {
185 return family_view_loca($node->nid,'1');
186 }
187 /**
188 * Implementation of hook_delete().
189 */
190 function family_location_delete(&$node) {
191 // $ind_fid = db_result(db_query("SELECT fid FROM {family_facts} WHERE nid = %d",$node->nid));
192 //family_remove_fact($node->nid);
193 db_query("DELETE FROM {family_location} WHERE nid=%d",$node->nid);
194 }
195
196 function family_view_loca($nid,$type){
197 $data = db_fetch_array(db_query("SELECT * FROM {family_location} WHERE nid = %d",$nid));
198 $content .= "<strong>". family_make_link($node->nid,($data['building']." ".$data['street'])) ."</strong><br>";
199 $list=array();
200 $list[] = 'Building : '.$data['building'];
201 $list[] = 'Street : '.$data['street'];
202 $list[] = 'City : '.$data['city'];
203 $list[] = 'County : '.$data['county'];
204 $list[] = 'State/Province : '.$data['state_province'];
205 $list[] = 'Country : '.$data['country'];
206 $content .= theme('item_list', $list);
207 $content .= "</P><p>&nbsp;</p>";
208 //Asociated group
209 $asocid = $data['related_group'];
210 if($asocid){
211 $content .= '<p>Family group asociated with here:</br>';
212 $content .= '<table width=100% border=1><tr><td>Name</td><td>Gender</td><td>Birth Date</td></tr>';
213 $fam=db_fetch_array(db_query("SELECT parent1, parent2 FROM {family_group} WHERE nid='%s'",$asocid));
214 $asoc= db_query("SELECT * FROM {family_individual} WHERE nid=%d OR nid=%d OR ancestor_group=%d", $fam['parent1'], $fam['parent2'], $asocid);
215 while ($child = db_fetch_array($asoc)) {
216 $content .= "<tr><td>".family_make_name($child['nid'],TRUE)."</td><td>".$child['gender']."</td><td>".$child['birthdate']."</td></tr>";
217 }
218 $content.="</table>";
219 }
220 //Born here
221 $born = db_query("SELECT * FROM {family_individual} WHERE birthplace=%d", $nid);
222 if($born){
223 $content .= '<p>Individuals born here:</br>';
224 $content .= '<table width=100% border=1><tr><td>Name</td><td>Gender</td><td>Birth Date</td></tr>';
225 while ($child = db_fetch_array($born)) {
226 $content .= "<tr><td>".family_make_name($child['nid'],TRUE)."</td><td>".$child['gender']."</td><td>".$child['birthdate']."</td></tr>";
227 }
228 $content.="</table>";
229 }
230 //died here
231 $death = db_query("SELECT * FROM {family_individual} WHERE deathplace=%d", $nid);
232 if($death){
233 $content .= '<p>Individuals died here:</br>';
234 $content .= '<table width=100% border=1><tr><td>Name</td><td>Gender</td><td>Death Date</td></tr>';
235 while ($child = db_fetch_array($death)) {
236 $content .= "<tr><td>".family_make_name($child['nid'],TRUE)."</td><td>".$child['gender']."</td><td>".$child['deathdate']."</td></tr>";
237 }
238 $content.="</table>";
239 }
240 //married here
241 $marr = db_query("SELECT * FROM {family_group} WHERE marr_plac=%d", $nid);
242 if($marr){
243 $content .= '<p>Groups married here:</br>';
244 $content .= '<table width=100% border=1><tr><td>Name</td><td>Marriage Date</td></tr>';
245 while ($child = db_fetch_array($marr)) {
246 $content .= "<tr><td>".$child['title_format']."</td><td>".$child['marr_date']."</td></tr>";
247 }
248 $content.="</table>";
249 }
250 //Divorced here
251 $div = db_query("SELECT * FROM {family_group} WHERE div_plac=%d", $nid);
252 if($div){
253 $content .= '<p>Groups divorced here:</br>';
254 $content .= '<table width=100% border=1><tr><td>Name</td><td>Divorce Date</td></tr>';
255 while ($child = db_fetch_array($div)) {
256 $content .= "<tr><td>".$child['title_format']."</td><td>".$child['div_date']."</td></tr>";
257 }
258 $content.="</table>";
259 }
260 return $content;
261 }

  ViewVC Help
Powered by ViewVC 1.1.2