-
Notifications
You must be signed in to change notification settings - Fork 0
/
guifi_node.inc.php
1569 lines (1368 loc) · 50.6 KB
/
guifi_node.inc.php
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
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file guifi_node.inc.php
* Manage guifi_node
* rroca
*/
/* main node (locations) hooks */
/** guifi_node_access(): construct node permissions
*/
function guifi_node_access($op, $node) {
global $user;
if (is_numeric($node))
$node = node_load(array('nid' => $node));
if ($op == 'view')
return TRUE;
if ($op == 'create') {
return user_access('create guifi nodes');
}
if ($op == 'update' or $op == 'delete') {
guifi_log(GUIFILOG_TRACE,
'function guifi_node_access()',
$op. ' - '.$node->nid);
if (((user_access('administer guifi zones')) || ($node->uid == $user->uid)) ||
(($node->uid == $user->uid) and (user_access('edit own guifi nodes'))) ||
// if it's a mantainer
(in_array($user->uid,guifi_maintainers_load($node->nid,'location','uid'))) ||
// if it's a funder
(in_array($user->uid,guifi_funders_load($node->nid,'location','uid')))
)
{
return TRUE;
} else {
// Check is authorized for being a maintainer of the zone and there is not maintainer
if ((empty($node->maintainers)) and (guifi_zone_access($op,$node->zone_id)))
return TRUE;
return FALSE;
}
}
return FALSE;
}
/** guifi_node_ariadna(): Get an array of zone hierarchy and node devices
* to build the breadcrumb
**/
function guifi_node_ariadna($node, $nlink = 'node/%d',$dlink = 'guifi/device/%d', $zlink = 'node/%s') {
if (is_numeric($node)) {
$node = guifi_node_load($node);
$node->title = $node->nick; // hack to show the node title
}
$ret = array();
$ret[] = l(t('Home'), NULL);
$ret[] = l(t('Main menu'),'guifi');
foreach (array_reverse(guifi_zone_get_parents($node->zone_id)) as $parent)
if ($parent > 0) {
$parentData = db_fetch_array(db_query(
'SELECT z.id, z.title ' .
'FROM {guifi_zone} z ' .
'WHERE z.id = %d ',
$parent));
$ret[] = l($parentData['title'],sprintf($zlink,$parentData['id']));
}
$ret[] = l($node->title,sprintf($nlink,$node->id));
$ret[count($ret)-1] = '<b>'.$ret[count($ret)-1].'</b>';
$child = array();
$query = db_query('SELECT d.id, d.nick, d.type ' .
'FROM {guifi_devices} d ' .
'WHERE d.nid = %d ' .
'ORDER BY d.id DESC',
$node->id);
$c = 0;
while ($dChild = db_fetch_array($query) and ($c <= 10)) {
$child[] = l($dChild['nick'],sprintf($dlink,$dChild['id']),
array(
'attributes' => array('title' => $dChild['type'])
));
$c++;
}
if ($c>=10)
$child[] = l(t('more...'),'node/'.$node->id.'/view/devices');
if (count($child)) {
$child[0] = '<br /><small>('.$child[0];
$child[count($child)-1] = $child[count($child)-1].')</small>';
$ret = array_merge($ret,$child);
}
return $ret;
}
/** guifi_node_add(): creates a new node
*/
function guifi_node_add($id) {
$zone = guifi_zone_load($id);
// Set the defaults for a node of this zone
// Callback to node/guifi-node/add
drupal_goto('node/add/guifi-node?edit[title]='.$zone->id);
}
/** guifi_node_load(): load and constructs node array from the database
**/
function guifi_node_load($node) {
if (is_object($node))
$k = $node->nid;
else
$k = $node;
$node = db_fetch_object(db_query("SELECT * FROM {guifi_location} WHERE id = '%d'", $k));
$node->maintainers=guifi_maintainers_load($node->id,'location');
$node->funders=guifi_funders_load($node->id,'location');
if (!$node->id == NULL)
return $node;
return FALSE;
}
/** node editing functions
**/
function guifi_node_prepare(&$node){
global $user;
if(empty($node->nid)){
if(is_numeric($node->title)){
$zone = guifi_zone_load($node->title);
$node->zone_id = $node->title;
$default = t('<nodename>');
$node->title = NULL;
$node->nick = $zone->nick.$default;
}
$node->notification = $user->mail;
$node->status_flag = 'Planned';
}
// Position
// if given parameters get/post, fill lat/lon
if (isset($_POST['lat'])){$node->lat = $_POST['lat'];}
if (isset($_POST['lon'])){$node->lon = $_POST['lon'];}
if (isset($_GET['lat'])){$node->lat = $_GET['lat'];}
if (isset($_GET['lon'])){$node->lon = $_GET['lon'];}
if (isset($_GET['Lat'])){$node->lat = $_GET['Lat'];}
if (isset($_GET['Lon'])){$node->lon = $_GET['Lon'];}
if (isset($_GET['zone'])){$node->zone_id = $_GET['zone'];}
if (isset($_GET['zone'])){$node->zone_id = $_GET['zone'];}
if (isset($_GET['lat']))
if (isset($_GET['lon'])) {
$defzone_qry = db_fetch_array(db_query("SELECT id, ((maxx-minx)+(maxy-miny)) as distance FROM {guifi_zone} WHERE minx < '%s' AND maxx > '%s' AND miny < '%s' AND maxy > '%s' ORDER by distance LIMIT 1",$_GET['lon'],$_GET['lon'],$_GET['lat'],$_GET['lat']));
$node->ndfzone = $defzone_qry['id'];
}
$coord=guifi_coord_dtodms($node->lat);
if($coord != NULL) {
$node->latdeg = $coord[0];
$node->latmin = $coord[1];
$node->latseg = $coord[2];
}
$coord=guifi_coord_dtodms($node->lon);
if ($coord != NULL) {
$node->londeg = $coord[0];
$node->lonmin = $coord[1];
$node->lonseg = $coord[2];
}
}
function guifi_node_form(&$node, $form_state) {
global $user;
$form_weight = 0;
$type = node_get_types('type',$node);
if (!empty($node->zone_id))
drupal_set_breadcrumb(guifi_node_ariadna($node));
else
drupal_set_breadcrumb(NULL);
// ----
// El títol el primer de tot
// ------------------------------------------------
if (($type->has_title)) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
);
}
$form_weight=2;
/*
* maintainers fieldset
*/
$form_weight=-3;
$form['maintainers'] = guifi_maintainers_form($node,$form_weight);
/*
* funders fieldset
*/
$form_weight=-4;
$form['funders'] = guifi_funders_form($node,$form_weight);
$form_weight=0;
$form['nick'] = array(
'#type' => 'textfield',
'#title' => t('Nick'),
'#required' => FALSE,
'#size' => 20,
'#maxlength' => 20,
'#element_validate' => array('guifi_node_nick_validate'),
'#default_value' => $node->nick,
'#description' => t("Unique identifier for this node. Avoid generic names such 'MyNode', use something that really identifies your node.<br />Short name, single word with no spaces, 7-bit chars only, will be used for hostname, reports, etc."),
'#weight' => $form_weight++,
);
$form['notification'] = array(
'#type' => 'textfield',
'#title' => t('Contact'),
'#required' => FALSE,
'#size' => 60,
'#maxlength' => 1024,
'#element_validate' => array('guifi_emails_validate'),
'#default_value' => $node->notification,
'#description' => t("Who did possible this node or who to contact with regarding this node if it is distinct of the owner of this page. Use valid emails, if you like to have more than one, separated by commas.'"),
'#weight' => $form_weight++,
);
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Node settings'),
'#weight' => $form_weight++,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Si ets administrador pots definir el servidor de dades
if (user_access('administer guifi zones')){
$graphstr = guifi_service_str($node->graph_server);
$form['settings']['graph_serverstr'] = array(
'#type' => 'textfield',
'#title' => t('default graphs server'),
'#maxlength' => 60,
'#required' => FALSE,
'#default_value' => $graphstr,
'#autocomplete_path'=> 'guifi/js/select-service/SNPgraphs',
'#element_validate' => array('guifi_service_name_validate',
'guifi_zone_service_validate'),
'#description' => t('Select the <em>graph server</em> to be used at this node.<br />You can find the <em>graph server</em> by introducing part of the id number, zone name or graph server name. A list with all matching values with a maximum of 50 values will be created.<br />You can refine the text to find your choice.'),
);
$form['settings']['graph_server'] = array(
'#type' => 'hidden',
'#value'=> $node->graph_server,
);
}
$form['settings']['stable'] = array(
'#type' => 'select',
'#title' => t("It's supposed to be a stable online node?"),
'#required' => FALSE,
'#default_value' => ($node->stable ? $node->stable : 'Yes'),
'#options' => array(
'Yes' => t('Yes, is intended to be kept always on, avalable for extending the mesh'),
'No' => t("I'm sorry. Will be connected just when I'm online")),
'#description' =>
t("That helps while planning a mesh network. We should know which locations are likely available to provide stable links."),
'#weight' => 1,
);
// Ask for a license agreement if is a new node
if (empty($node->nid)) {
$form['license'] = array(
'#type' => 'item',
'#title' => t('License and usage agreement'),
'#value' => t(variable_get('guifi_license', NULL)),
'#description' => t('You must accept this agreement to be authorized to create new nodes.'),
'#weight' => 1,
);
if (empty($node->agreement))
$agreement = 'No';
else
$agreement = $node->agreement;
$form['agreement']= array(
'#type' => 'radios',
'#default_value' =>$agreement,
'#options' => array('Yes' => t('Yes, I have read this and accepted')),
'#element_validate' => array('guifi_node_agreement_validate'),
'#weight' => 2,
);
} else {
$form['agreement']= array(
'#type' => 'hidden',
'#default_value' => 'Yes',
);
}
if (empty($node->nid)) {
if (empty($node->ndfzone)) {
if (empty($node->zone_id)) {
if(!empty($user->guifi_default_zone)) {
$zone_id = $user->guifi_default_zone;
}
} else {
$zone_id = $node->zone_id;
}
} else {
$zone_id = $node->ndfzone;
}
} else {
$zone_id = $node->zone_id;
}
$form['zone_id'] = guifi_zone_autocomplete_field($zone_id,'zone_id');
// $form['zone_id'] = guifi_zone_select_field($zone_id,'zone_id');
$form['zone_id']['#weight'] = 3;
// ----
// position
// ------------------------------------------------
$form['position'] = array(
'#type' => 'fieldset',
'#title' => t('Node position settings'),
'#weight' => 4,
'#collapsible' => FALSE,
);
if (guifi_gmap_key()) {
drupal_add_js(drupal_get_path('module', 'guifi').'/js/guifi_gmap_node.js','module');
$form['position']['GMAP'] = array(
'#type' => 'item',
'#title' => t('Map'),
'#description' => t('Select the point where the node has to be placed.'),
'#suffix' => '<input style="width: 240px;" id="mapSearch" type="text" /><div id="map" style="width: 100%; height: 437px; margin:5px;"></div>',
'#weight' => 0,
);
$form['guifi_wms'] = array(
'#type' => 'hidden',
'#value' => variable_get('guifi_wms_service',''),
);
$form['lat'] = array(
'#type' => 'hidden',
'#value' => $node->lat,
);
$form['lon'] = array(
'#type' => 'hidden',
'#value' => $node->lon,
);
}
$form['position']['longitude'] = array(
'#type' => 'item',
'#title' => t('Longitude'),
'#prefix' => '<table><tr><th> </th><th>'.
t('degrees (decimal values allowed)').
'</th><th>'.
t('minutes').
'</th><th>'.
t('seconds').
'</th></tr><tr><td>',
'#suffix' => '</td>',
'#weight' => 1,
);
$form['position']['londeg'] = array(
'#type' => 'textfield',
'#default_value' => $node->londeg,
'#size' => 12,
'#maxlength' => 24,
'#element_validate' => array('guifi_lon_validate'),
'#prefix' => '<td>',
'#suffix' => '</td>',
'#weight' => 2,
);
$form['position']['lonmin'] = array(
'#type' => 'textfield',
'#default_value' => $node->lonmin,
'#size' => 12,
'#maxlength' => 24,
'#prefix' => '<td>',
'#suffix' => '</td>',
'#weight' => 3,
);
$form['position']['lonseg'] = array(
'#type' => 'textfield',
'#default_value' => $node->lonseg,
'#size' => 12,
'#maxlength' => 24,
'#prefix' => '<td>',
'#suffix' => '</td></tr>',
'#weight' => 4,
);
$form['position']['latitude'] = array(
'#type' => 'item',
'#title' => t('Latitude'),
'#prefix' => '<tr><td>',
'#suffix' => '</td>',
'#weight' => 5,
);
$form['position']['latdeg'] = array(
'#type' => 'textfield',
'#default_value' => $node->latdeg,
'#size' => 12,
'#maxlength' => 24,
'#element_validate' => array('guifi_lat_validate'),
'#prefix' => '<td>',
'#suffix' => '</td>',
'#weight' => 6,
);
$form['position']['latmin'] = array(
'#type' => 'textfield',
'#default_value' => $node->latmin,
'#size' => 12,
'#maxlength' => 24,
'#prefix' => '<td>',
'#suffix' => '</td>',
'#weight' => 7,
);
$form['position']['latseg'] = array(
'#type' => 'textfield',
'#default_value' => $node->latseg,
'#size' => 12,
'#maxlength' => 24,
'#prefix' => '<td>',
'#suffix' => '</td></tr></table>',
'#weight' => 8,
);
$form['position']['zone_description'] = array(
'#type' => 'textfield',
'#title' => t('Zone description'),
'#required' => FALSE,
'#size' => 60,
'#maxlength' => 128,
'#default_value' => $node->zone_description,
'#description' => t("Zone, address, neighborhood. Something that describes your area within your location.<br />If you don't know your lat/lon, please provide street and number or crossing street."),
'#weight' => 9,
);
$form['position']['elevation'] = array(
'#type' => 'textfield',
'#title' => t('Antenna elevation'),
'#required' => FALSE,
'#size' => 5,
'#length' => 20,
'#maxlength' => 20,
'#default_value' => $node->elevation,
'#element_validate' => array('guifi_elevation_validate'),
'#description' => t("Antenna height over the floor level."),
'#weight' => 10,
);
if (($type->has_body)) {
$form['body_field'] = node_body_field(
$node,
$type->body_label,
$type->min_word_count
);
}
$radios = array();
$query = db_query("SELECT * FROM {guifi_radios} WHERE nid=%d",$node->id);
while ($radio = db_fetch_array($query)) {
$radios[] = $radio;
}
if (count($radios) < 1) {
$form['status_flag'] = array(
'#type' => 'select',
'#title' => t("Node status"),
'#default_value' => ( $node->status_flag ? $node->status_flag : 'Planned') ,
'#required' => FALSE,
'#options' => array('Reserved' => t('Reserved'),'Inactive' => t('Inactive'),'Planned' => t('Planned')),
);
} else {
$form['status_flag'] = array(
'#type' => 'hidden',
'#default_value' => $node->status_flag,
);
}
return $form;
}
function guifi_node_agreement_validate($element, &$form_state) {
if ($element['#value'] != 'Yes'){
form_error($element,
t('You must read and accept the license terms and conditions to be allowed to create nodes.'));
}
}
function guifi_node_nick_validate($element, &$form_state) {
if (empty($element['#value'])) {
$nick = guifi_abbreviate($form_state['values']['title']);
drupal_set_message(t('Zone nick has been set to:').' '.$nick);
$form_state['values']['nick'] = $nick;
return;
}
guifi_validate_nick($element['#value']);
$query = db_query("SELECT nick FROM {guifi_location} WHERE lcase(nick)='%s' AND id <> %d",
strtolower($element['#value']),$form_state['values']['nid']);
if (db_result($query)){
form_set_error('nick', t('Nick already in use.'));
}
}
function guifi_node_get_service($id, $type ,$path = FALSE) {
if (is_numeric($id))
$z = guifi_node_load($id);
else
$z = $id;
$ret = NULL;
if (!empty($z->$type))
$ret = $z->$type;
else
$ret = guifi_zone_get_service($z->zone_id,$type);
if ($path)
if ($ret)
$ret = 'node/'.$ret;
return $ret;
}
/** guifi_node_validate(): Confirm that an edited guifi item has fields properly filled in.
*/
function guifi_node_validate($node,$form) {
guifi_validate_nick($node->nick);
// not at root zone
if (($node->zone_id == 0) or ($node->zone_id == guifi_zone_root())){
form_set_error('zone_id',
t('Can\'t be assigned to root zone, please assign the node to an appropiate zone.'));
}else{
$nz=0;
guifi_zone_childs_tree_depth($node->zone_id, 3, $nz);
if($nz>2){
form_set_error('zone_id',
t('Can\'t be assigned to parent zone, please assign the node to an final zone.'));
}
}
if ($node->elevation == 0){$node->elevation = NULL;}
if (($node->elevation < -1) && ($node->elevation != NULL)){
form_set_error('elevation',
t('Elevation must be above the floor! :)'));
}
if (($node->elevation > 261) && ($node->elevation != NULL)){
form_set_error('elevation',
t('Do you mean that you are flying over the earth??? :)'));
}
/*
* Validate maintainer(s)
*/
guifi_maintainers_validate($node);
/*
* Validate funder(s)
*/
guifi_funders_validate($node);
}
/** guifi_node_insert(): Create a new node in the database
*/
function guifi_node_insert($node) {
global $user;
$log = '';
$coord=guifi_coord_dmstod($node->latdeg,$node->latmin,$node->latseg);
if($coord!=NULL){
$node->lat=$coord;
}
$coord=guifi_coord_dmstod($node->londeg,$node->lonmin,$node->lonseg);
if($coord!=NULL){
$node->lon=$coord;
}
if ($node->lat == 0){$node->lat = NULL;}
if ($node->lon == 0){$node->lon = NULL;}
$to_mail = explode(',',$node->notification);
$node->new=TRUE;
$node->id = $node->nid;
$node->lat = (float)$node->lat;
$node->lon = (float)$node->lon;
$nnode = _guifi_db_sql(
'guifi_location',
array('id' => $node->nid),(array)$node,$log,$to_mail);
guifi_notify(
$to_mail,
t('The node %name has been CREATED by %user.',array('%name' => $node->title, '%user' => $user->name)),
$log);
guifi_maintainers_save($nnode,'location',$node->maintainers);
guifi_funders_save($nnode,'location',$node->funders);
// Refresh maps
variable_set('guifi_refresh_cnml',time());
variable_set('guifi_refresh_maps',time());
guifi_clear_cache($node->id);
}
/** guifi_node_update(): Update a node in the database
*/
function guifi_node_update($node) {
global $user;
$log = '';
$coord=guifi_coord_dmstod($node->latdeg,$node->latmin,$node->latseg);
if($coord!=NULL){
$node->lat=$coord;
}
$coord=guifi_coord_dmstod($node->londeg,$node->lonmin,$node->lonseg);
if($coord!=NULL){
$node->lon=$coord;
}
if ($node->lat == 0){$node->lat = NULL;}
if ($node->lon == 0){$node->lon = NULL;}
$to_mail = explode(',',$node->notification);
// Refresh maps?
$pn = db_fetch_object(db_query(
'SELECT l.*
FROM {guifi_location} l
WHERE l.id=%d',
$node->nid));
if (($pn->lat != $node->lat) || ($pn->lon != $node->lon) || ($pn->status_flag != $node->status_flag)) {
// touch(variable_get('guifi_rebuildmaps','/tmp/ms_tmp/REBUILD'));
variable_set('guifi_refresh_cnml',time());
variable_set('guifi_refresh_maps',time());
cache_clear_all();
}
$node->lat = (float)$node->lat;
$node->lon = (float)$node->lon;
guifi_maintainers_save($node->nid,'location',$node->maintainers);
guifi_funders_save($node->nid,'location',$node->funders);
$nnode = _guifi_db_sql(
'guifi_location',
array('id' => $node->nid),
(array)$node,
$log,$to_mail);
guifi_notify(
$to_mail,
t('The node %name has been UPDATED by %user.',array('%name' => $node->title, '%user' => $user->name)),
$log);
guifi_clear_cache($node->nid);
}
/** guifi_node_delete(): deletes a given node
**/
function guifi_node_delete($node) {
global $user;
$depth = 0;
$to_mail = explode(',',$node->notification);
$log = _guifi_db_delete('guifi_location',array('id' => $node->nid),$to_mail,$depth);
drupal_set_message($log);
guifi_notify(
$to_mail,
t('The node %name has been DELETED by %user.',array('%name' => $node->title, '%user' => $user->name)),
$log);
cache_clear_all();
variable_set('guifi_refresh_cnml',time());
variable_set('guifi_refresh_maps',time());
return;
}
/** node visualization (view) function calls */
/** guifi_node_view(): outputs the node information
**/
function guifi_node_view($node, $teaser = FALSE, $page = FALSE, $block = FALSE) {
node_prepare($node);
if ($teaser)
return $node;
if ($block)
return $node;
drupal_set_breadcrumb(guifi_node_ariadna($node));
$node->content['data'] = array(
'#value'=> theme_table(NULL,
array(
array(
array(
'data' => '<small>'.
theme_guifi_node_data($node).
'</small>',
'width' => '50%'
),
array(
'data' => theme_guifi_node_map($node),
'width' => '50%'
)
)
)
),
'#weight'=> 1);
$node->content['graphs'] = array(
'#value'=> theme_guifi_node_graphs_overview($node),
'#weight'=> 2);
$node->content['devices'] = array(
'#value'=> theme_guifi_node_devices_list($node),
'#weight'=> 3);
$node->content['wdsLinks'] = array(
'#value'=> theme_guifi_node_links_by_type($node->id,'wds'),
'#weight'=> 4);
$node->content['cableLinks'] = array(
'#value'=> theme_guifi_node_links_by_type($node->id,'cable'),
'#weight'=> 5);
$node->content['clientLinks'] = array(
'#value'=> theme_guifi_node_links_by_type($node->id,'ap/client'),
'#weight'=> 6);
return $node;
}
function guifi_node_hidden_map_fileds($node) {
$output = '<from>';
$output .= '<input type="hidden" id="lat" value="'.$node->lat.'"/>';
$output .= '<input type="hidden" id="lon" value="'.$node->lon.'"/>';
$output .= '<input type="hidden" id="zone_id" value="'.$node->zone_id.'"/>';
$output .= '<input type="hidden" id="guifi-wms" value="'.variable_get('guifi_wms_service','').'"/></form>';
return $output;
}
/** guifi_node_print_distances(): list of neighbors
**/
function guifi_node_distances_map($node) {
$rows = array();
$lat2='';
$lon2='';
if (!empty($_GET['lat2']))
$lat2 = $_GET['lat2'];
else
$lat2 = "NA";
if (!empty($_GET['lon2']))
$lon2 = $_GET['lon2'];
else
$lon2 = "NA";
if (!empty($_GET['name2']))
$name2 = $_GET['name2'];
else
$name2 = "NA";
drupal_set_title(t('distances map from').' '.
guifi_get_zone_nick($node->zone_id).
'-'.$node->nick);
if (guifi_gmap_key()) {
drupal_add_js(drupal_get_path('module', 'guifi').'/js/guifi_gmap_dist.js','module');
$rows[] = array(array('data' => t('Click on the map to get a new path profile ( Thanks to <a href="http://www.heywhatsthat.com">HeyWhatsThat</a> ) to check the Line Of Sight<br />Click on the path profile to see the point on the map'),'align' => 'center'));
$rows[] = array(array('data' => 'Profile graph and Countour Layer provided by: <a href="http://www.heywhatsthat.com">HeyWhatsThat</a> Copyright 2012 Michael Kosowsky. <b>All rights reserved</b><br>Visit <a href="http://wisp.heywhatsthat.com">HeyWhatsThat WISP</a> for tools for planning wireless networks.<br><a href="javascript:;" onclick="profileclick(event)"><img id="profile" src="'.drupal_get_path('module', 'guifi').'/js/marker_start.png" /></a>','align' => "center"));
$rows[] = array('<div id="map" style="width: 100%; height: 600px; margin:5px;"></div>');
$rows[] = array(array('data' => '<div style="float:left;">'.t('Distance:').' </div>'.'<div id="tdistance" style="float:left;">0</div>'.'<div style="float:left;"> Km. '.t('Azimuth:').' </div>'.'<div id="tazimut" style="float:left;">0</div> '.t('degrees')));
$output = theme('table', NULL,$rows);
$output .= '<form>' .
'<input type="hidden" value="'.$node->lat.'" id="lat" />'.
'<input type="hidden" value="'.$node->lon.'" id="lon" />' .
'<input type="hidden" value="'.$lat2.'" id="lat2" />'.
'<input type="hidden" value="'.$lon2.'" id="lon2" />' .
'<input type="hidden" value="'.base_path().drupal_get_path('module','guifi').'/js/'.'" id="edit-jspath" />' .
'<input type="hidden" value="'.variable_get('guifi_wms_service','').'" id="guifi-wms" />' .
'<input type="hidden" value="'.$node->elevation.'" id="elevation" />' .
'</form>';
}
$node = node_load(array('nid' => $node->id));
drupal_set_breadcrumb(guifi_node_ariadna($node));
$output .= theme_links(module_invoke_all('link', 'node', $node, FALSE));
print theme('page',$output, FALSE);
return;
}
function guifi_node_distances($node) {
drupal_set_title(t('distances from').' '.
guifi_get_zone_nick($node->zone_id).
'-'.$node->nick);
$output .= drupal_get_form('guifi_node_distances_form',$node);
$node = node_load(array('nid' => $node->id));
drupal_set_breadcrumb(guifi_node_ariadna($node));
$output .= theme_links(module_invoke_all('link', 'node', $node, FALSE));
print theme('page',$output, FALSE);
return;
}
function guifi_node_distances_form($form_state,$node) {
global $base_url;
guifi_log(GUIFILOG_TRACE,'function guifi_node_distances_form()',$form_state);
$form = array();
$form_state['#redirect'] = FALSE;
// default values
$filters = array(
'dmin' => 0,
'sn' => 1,
'dmax' => 30,
'search' => NULL,
'max' => 25,
'skip' => 0,
'status' => "All",
'from_node' => $node->id,
'azimuth' => "0,360",
);
// initialize filters using default values or passed by form
if (!empty($form_state['values']['filters']))
$form_state['values']['filters'] =
array_merge($filters,$form_state['values']['filters']);
else
$form_state['values']['filters'] = $filters;
$form['filters_region'] = guifi_devices_select_filter($form_state,'guifi_node_distances');
$form['list-devices'] = guifi_node_distances_list($form_state['values']['filters'],$node);
return $form;
}
function guifi_node_distances_list($filters,$node) {
guifi_log(GUIFILOG_TRACE,sprintf('function guifi_node_distances_list(%d)',$node->id),
$_POST);
$orig = $node->id;
// storing lat/lon from the current node to be user for computing
// distances with the other nodes
$lat1 = $node->lat;
$long1 = $node->lon;
// store the node nickname to be used for literal at the profiles
$node1 = $node->nick;
// $filters = $form_state['values']['filters'];
// get the nodes and compute distances
/***
$result = db_query(
"SELECT " .
"n.id, n.lat, n.lon, n.nick, n.status_flag, n.zone_id " .
"FROM {guifi_location} n " .
"WHERE n.id !=%d " .
"AND (n.lat != '' " .
"AND n.lon != '') " .
"AND (n.lat != 0 " .
"AND n.lon != 0)",
$node->id);
***/
$result = db_query("SELECT n.id, n.lat, n.lon, n.nick, n.status_flag, n.zone_id, n.timestamp_changed, count(*) radios FROM {guifi_location} n LEFT JOIN {guifi_radios} r ON n.id = r.nid WHERE n.id !=%d AND (n.lat != '' AND n.lon != '')AND (n.lat != 0 AND n.lon != 0) GROUP BY 1",$node->id);
$oGC = new GeoCalc();
$nodes = array();
$rows = array();
$totals[] = NULL;
if (isset($_POST['op'])) {
if ($_POST['op'] == t('Next page'))
$filters['skip'] = $filters['skip'] + $filters['max'];
if ($_POST['op'] == t('Previous page'))
$filters['skip'] = $filters['skip'] - $filters['max'];
$nc = 0;
$allow_next = FALSE;
if ($filters['skip'])
$allow_prev = TRUE;
else
$allow_prev = FALSE;
}
while ($node = db_fetch_array($result)) {
$distance = round($oGC->EllipsoidDistance($lat1, $long1, $node["lat"], $node["lon"]),3);
// Apply filters
if ( $filters['sn'] and $node["radios"] < 2) continue;
if ($distance <= $filters['dmax'])
if ($distance >= $filters['dmin'])
if (($filters['status'] == 'All') or ($filters['status'] == $node['status_flag']))
{
$nodes[] = array_merge(array('distance' => $distance),$node);
}
}
// Filter form
$fw = 0;
// guifi_devices_select_filter($form,$form_state,$fw);
$form = array(
'#type' => 'fieldset',
// '#title' => t('filters'),
// '#weight' => 0,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
// '#weight' => $fweight++,
'#prefix' => '<div id="list-devices">',
'#suffix' => '</div>',
);
if (count($nodes)==0) {
$form['empty'] = array(
'#type'=> 'item',
'#title'=> t('No nodes found. The list is empty'),
'#value'=> t('Th given query has returned no rows.'),
'#description'=> t('Use the filters to get some results'),
'#weight' => $fw++,
);
return $form;
}
asort($nodes);
// header
$form['z'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#weight' => $fw++
);
$form['z'][-1]['h_node'] = array(
'#type'=> 'item',
'#title'=> t('Node'),
'#description'=> t('Zone'),
'#prefix' => '<table><tr><th>',
'#suffix' => '</th>',
'#weight' => $fw++,
);
$form['z'][-1]['h_distance'] = array(
'#type'=> 'item',
'#title'=> t('Distance'),
'#value'=> t('Status'),
'#description'=> t('Azimuth'),
'#prefix' => '<th>',
'#suffix' => '</th>',
'#weight' => $fw++,
);
$form['z'][-1]['h_heights'] = array(
'#type'=> 'item',
'#title'=> t('Heights image'),
'#description'=> t('Click over the image to view in large format<br>
Visit <a href="http://wisp.heywhatsthat.com">HeyWhatsThat WISP</a> for tools
for planning wireless networks.<br><a href="http://www.heywhatsthat.com">HeyWhatsThat</a>. Copyright 2012 Michael Kosowsky. <b>All rights reserved</b>'),
'#prefix' => '<th>',
'#suffix' => '</th></tr>',
'#weight' => $fw++,
);
$nc = 0;
$tc = count($nodes);
foreach ($nodes as $key => $node) {
$dAz = round($oGC->GCAzimuth($lat1, $long1, $node["lat"], $node["lon"]));
// Calculo orientacio
if ($dAz < 23) $dOr =t("North"); else
if ($dAz < 68) $dOr =t("North East"); else
if ($dAz < 113) $dOr =t("East"); else
if ($dAz < 158) $dOr =t("South East"); else
if ($dAz < 203) $dOr =t("South"); else
if ($dAz < 248) $dOr =t("South West"); else
if ($dAz < 293) $dOr =t("West"); else
if ($dAz < 338) $dOr =t("North West"); else