/[drupal]/contributions/modules/ham/ham.module
ViewVC logotype

Contents of /contributions/modules/ham/ham.module

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


Revision 1.11 - (show annotations) (download) (as text)
Mon Nov 3 20:34:12 2008 UTC (12 months, 3 weeks ago) by ppicazo
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +7 -7 lines
File MIME type: text/x-php
Added band information columns to more tables.
1 <?php
2 // $Id: ham.module,v 1.9 2008/11/03 18:48:46 ppicazo Exp $
3
4 require_once("arrl_band_plan.inc");
5 require_once("amateur_radio.inc");
6
7 function ham_perm() {
8 return array('access ham content', 'access ham administration pages');
9 }
10
11 function ham_generation($exe_time = NULL) {
12 if ($exe_time != NULL) {
13 return "Module Execution Time: {$exe_time} seconds. Generated by <a href=\"http://drupal.org/project/ham\">Drupal Ham Radio Module</a>...";
14 }
15 else {
16 return "Generated by <a href=\"http://drupal.org/project/ham\">Drupal Ham Radio Module</a>...";
17 }
18 }
19
20 function ham_main() {
21
22 $start = microtime(true);
23
24 $content = '';
25
26 $content .= '<p>';
27
28 $result = db_query("SELECT COUNT(*) as qso_count FROM ham_qso");
29
30 $total_count = db_fetch_object($result)->qso_count;
31 $content .= '<li><a href="/ham/logbook">' . t('View Complete Logbook') . '</a> (' . $total_count . ' entries)</li>';
32
33 $content .= '<li>QSO by Date</li><ul>';
34
35 $result = db_query("SELECT YEAR(qso_time) as qso_year, COUNT(*) as qso_count FROM ham_qso GROUP BY qso_year ORDER BY qso_year DESC");
36
37 while ($row = db_fetch_object($result)) {
38 $content .= '<li><a href="/ham/date/' . $row->qso_year . '">' . $row->qso_year . '</a> - ';
39
40 $result_m = db_query("SELECT MONTH(qso_time) as qso_month, COUNT(*) as qso_count FROM ham_qso WHERE YEAR(qso_time) = " . $row->qso_year . " GROUP BY qso_month ORDER BY qso_month ASC");
41 while ($row_m = db_fetch_object($result_m)) {
42 $content .= '<a href="/ham/date/' . $row->qso_year . '/' . $row_m->qso_month . '">' . date("M", mktime(0, 0, 0, $row_m->qso_month, 1, 2001)) . '</a> ';
43 }
44
45 $content .= '</li>';
46 }
47
48 $content .= '</ul>';
49
50 $content .= '</p>';
51
52 $content .= '<br><h3>Mode Statistics:</h3>';
53
54 $result = db_query("SELECT *, COUNT(*) as qso_count FROM ham_qso GROUP BY qso_mode ORDER BY qso_count DESC");
55
56 $header = array( array('data' => 'Mode'), array('data' => 'QSO Count', 'sort' => 'desc'), array('data' => '%'));
57
58 while ($row = db_fetch_object($result)) {
59 $rows[] = array(array('data' => $row->qso_mode), array('data' => $row->qso_count), array('data' => number_format(($row->qso_count/$total_count)*100,2)));
60 }
61
62 $content .= theme_table($header, $rows);
63
64 $rows = NULL;
65
66 $content .= '<br><h3>Band Statistics:</h3>';
67
68 $result = db_query("SELECT *, COUNT(*) as qso_count FROM ham_qso GROUP BY qso_band ORDER BY qso_count DESC");
69
70 $header = array( array('data' => 'Band'), array('data' => 'QSO Count', 'sort' => 'desc'), array('data' => '%'));
71
72 while ($row = db_fetch_object($result)) {
73 $rows[] = array(array('data' => $row->qso_band), array('data' => $row->qso_count), array('data' => number_format(($row->qso_count/$total_count)*100,2)));
74 }
75
76 $content .= theme_table($header, $rows);
77
78 $rows = NULL;
79
80 $content .= '<br><h3>Top 10 DX Contacts:</h3>';
81
82 $result = db_query("SELECT *, COUNT(*) as qso_count FROM ham_qso LEFT JOIN ham_dxcc ON qso_dxcc = dxcc_code WHERE qso_dxcc <> 291 AND qso_dxcc <> 1 AND qso_dxcc <> 110 AND qso_dxcc <> 6 GROUP BY qso_call ORDER BY qso_count DESC LIMIT 0,10");
83
84 $header = array( array('data' => 'Call'), array('data' => 'QSO Count', 'sort' => 'desc'), array('data' => 'Country'));
85
86 while ($row = db_fetch_object($result)) {
87 $call_with_link = "<a href=\"/ham/callsign/{$row->qso_call}\">{$row->qso_call}</a>";
88 $rows[] = array(array('data' => $call_with_link), array('data' => $row->qso_count), array('data' => $row->dxcc_country));
89 }
90
91 $content .= theme_table($header, $rows);
92
93 $content .= '<br><h3>Country Statistics:</h3>';
94
95 $result = db_query("SELECT *, COUNT(*) as qso_count FROM ham_qso LEFT JOIN ham_dxcc ON qso_dxcc = dxcc_code GROUP BY qso_dxcc ORDER BY qso_count DESC, dxcc_country ASC LIMIT 0,1000");
96
97 $header_country = array( array('data' => 'Country'), array('data' => 'QSO Count', 'sort' => 'desc'));
98
99 $count = 0;
100
101 while ($row = db_fetch_object($result)) {
102 $rows_country[] = array(array('data' => '<a href="/ham/country/' . $row->dxcc_code . '/">' . $row->dxcc_country . '</a>'), array('data' => $row->qso_count));
103 $count++;
104 }
105
106 $content .= theme_table($header_country, $rows_country);
107
108 $exe_time = number_format(microtime(true) - $start,9);
109
110 $content .= "Total Countries Contacted: {$count}<br><br>";
111
112 $content .= ham_generation($exe_time);
113
114 date_default_timezone_set($default_tz);
115
116 return $content;
117
118 }
119
120 function ham_logbook() {
121
122 $start = microtime(true);
123
124 $content = '';
125
126 // limit set at 10,000 entries, will remove limit after further testing
127 $result = db_query('SELECT * FROM ham_qso LEFT JOIN ham_dxcc ON qso_dxcc = dxcc_code ORDER BY qso_time DESC LIMIT 0,10000 ');
128
129 $default_tz = date_default_timezone_get();
130 date_default_timezone_set('UTC');
131
132 $header = array( array('data' => 'Date'), array('data' => 'Call'), array('data' => 'Grid'),array('data' => 'Country'), array('data' => 'Mode'), array('data' => 'Band'), array('data' => 'Frequency'));
133
134 $count = 0;
135
136 while ($row = db_fetch_object($result)) {
137 if (ctype_alnum($row->qso_call)) {
138 $call_with_link = "<a href=\"/ham/callsign/{$row->qso_call}\">{$row->qso_call}</a>";
139 }
140 else {
141 $parts = explode("/", $row->qso_call);
142 if (ctype_digit($parts[1]) || strtolower($parts[1]) == 'qrp' || strtolower($parts[1]) == 'mm') {
143 $call_with_link = "<a href=\"/ham/callsign/{$parts[0]}\">{$row->qso_call}</a>";
144 }
145 else {
146 $call_with_link = $row->qso_call;
147 }
148 }
149
150 $rows[] = array(array('data' => date('d M y Hi', strtotime($row->qso_time)). "z") , array('data' => $call_with_link), array('data' => $row->qso_remote_grid), array('data' => $row->dxcc_country), array('data' => $row->qso_mode), array('data' => $row->qso_band), array('data' => number_format($row->qso_freq,6)));
151 $count++;
152 }
153
154 $content .= theme_table($header, $rows);
155
156 $exe_time = number_format(microtime(true) - $start,9);
157
158 $content .= "Records Displayed: {$count}. " . ham_generation($exe_time);
159
160 date_default_timezone_set($default_tz);
161
162 return $content;
163
164 }
165
166 function ham_callsign($query = NULL) {
167
168 $start = microtime(true);
169
170 $content = '';
171
172 $content .= '<p>'. t('Contact with ') . "<a href=\"http://www.qrz.com/callsign/" . strtoupper($query) . "\">" . strtoupper($query) . '</a>:</p>';
173
174 $result = db_query("SELECT * FROM ham_qso LEFT JOIN ham_dxcc ON qso_dxcc = dxcc_code WHERE qso_call LIKE '$query%' ORDER BY qso_time DESC");
175
176 $default_tz = date_default_timezone_get();
177 date_default_timezone_set('UTC');
178
179 $header = array( array('data' => 'Date', 'sort' => 'desc'), array('data' => 'Call'), array('data' => 'Grid'),array('data' => 'Country'), array('data' => 'Mode'), array('data' => 'Band'), array('data' => 'Frequency'));
180
181 $count = 0;
182
183 while ($row = db_fetch_object($result)) {
184 $call_with_link = "<a href=\"/ham/callsign/{$row->qso_call}\">{$row->qso_call}</a>";
185
186 if ($row->qso_remote_grid) {
187 $grid_link = '<a href="http://maps.google.com/?ie=UTF8&ll=' . number_format(loc2lat($row->qso_remote_grid),3) . ',' . number_format(loc2lon($row->qso_remote_grid),3) . '&spn=13.915107,34.628906&z=12&om=1">' . $row->qso_remote_grid . '</a>';
188 }
189 else {
190 $grid_link = "";
191 }
192
193 $rows[] = array(array('data' => date('d M y Hi', strtotime($row->qso_time)). "z") , array('data' => $call_with_link), array('data' => $grid_link), array('data' => $row->dxcc_country), array('data' => $row->qso_mode), array('data' => $row->qso_band), array('data' => number_format($row->qso_freq,6)));
194 $count++;
195 }
196
197 $content .= theme_table($header, $rows);
198
199 $exe_time = number_format(microtime(true) - $start,9);
200
201 $content .= "Records Displayed: {$count}. " . ham_generation($exe_time);
202
203 date_default_timezone_set($default_tz);
204
205 return $content;
206
207 }
208
209 function ham_country($query = NULL) {
210
211 $start = microtime(true);
212
213 $content = '';
214
215 $result = db_query("SELECT * FROM ham_qso WHERE qso_dxcc = $query ORDER BY qso_time DESC");
216
217 $default_tz = date_default_timezone_get();
218 date_default_timezone_set('UTC');
219
220 $header = array( array('data' => 'Date', 'sort' => 'desc'), array('data' => 'Call'), array('data' => 'Grid'), array('data' => 'Mode'), array('data' => 'Band'), array('data' => 'Frequency'));
221
222 $count = 0;
223
224 while ($row = db_fetch_object($result)) {
225 $call_with_link = "<a href=\"/ham/callsign/{$row->qso_call}\">{$row->qso_call}</a>";
226 if ($row->qso_remote_grid) {
227 $grid_link = '<a href="http://maps.google.com/?ie=UTF8&ll=' . number_format(loc2lat($row->qso_remote_grid),3) . ',' . number_format(loc2lon($row->qso_remote_grid),3) . '&spn=13.915107,34.628906&z=12&om=1">' . $row->qso_remote_grid . '</a>';
228 }
229 else {
230 $grid_link = "";
231 }
232 $rows[] = array(array('data' => date('d M y Hi', strtotime($row->qso_time)). "z") , array('data' => $call_with_link), array('data' => $grid_link), array('data' => $row->qso_mode), array('data' => $row->qso_band), array('data' => number_format($row->qso_freq,6)));
233 $count++;
234 }
235
236 $content .= theme_table($header, $rows);
237
238 $exe_time = number_format(microtime(true) - $start,9);
239
240 $content .= "Records Displayed: {$count}. " . ham_generation($exe_time);
241
242 date_default_timezone_set($default_tz);
243
244 return $content;
245
246 }
247
248 function ham_date($year, $month = NULL) {
249
250 $start = microtime(true);
251
252 $default_tz = date_default_timezone_get();
253 date_default_timezone_set('UTC');
254
255 $content = '';
256
257 if($month == NULL) {
258 $result = db_query("SELECT * FROM ham_qso LEFT JOIN ham_dxcc ON qso_dxcc = dxcc_code WHERE YEAR(qso_time) = " . $year . " ORDER BY qso_time DESC");
259 $content .= '<p>Contact during ' . $year . '</p>';
260 }
261 else
262 {
263 $result = db_query("SELECT * FROM ham_qso LEFT JOIN ham_dxcc ON qso_dxcc = dxcc_code WHERE YEAR(qso_time) = " . $year . " AND MONTH(qso_time) = " . $month . " ORDER BY qso_time DESC");
264 $content .= '<p>Contact during ' . date("M", mktime(0, 0, 0, $month, 1, 2001)) . ' ' . $year . '</p>';
265 }
266
267 $header = array( array('data' => 'Date', 'sort' => 'desc'), array('data' => 'Call'), array('data' => 'Grid'),array('data' => 'Country'), array('data' => 'Mode'), array('data' => 'Band'), array('data' => 'Frequency'));
268
269 $count = 0;
270
271 while ($row = db_fetch_object($result)) {
272 $call_with_link = "<a href=\"/ham/callsign/{$row->qso_call}\">{$row->qso_call}</a>";
273
274 if ($row->qso_remote_grid) {
275 $grid_link = '<a href="http://maps.google.com/?ie=UTF8&ll=' .
276 number_format(loc2lat($row->qso_remote_grid),3) . ',' . number_format(loc2lon($row->qso_remote_grid),3) .
277 '&spn=13.915107,34.628906&z=12&om=1">' . $row->qso_remote_grid . '</a>';
278 }
279 else {
280 $grid_link = "";
281 }
282
283
284 $rows[] = array(array('data' => date('d M y Hi', strtotime($row->qso_time)). "z") , array('data' => $call_with_link), array('data' => $grid_link), array('data' => $row->dxcc_country), array('data' => $row->qso_mode), array('data' => $row->qso_band), array('data' => number_format($row->qso_freq,6)));
285 $count++;
286 }
287
288 $content .= theme_table($header, $rows);
289
290 $exe_time = number_format(microtime(true) - $start,9);
291
292 $content .= "Records Displayed: {$count}. " . ham_generation($exe_time);
293
294 date_default_timezone_set($default_tz);
295
296 return $content;
297
298 }
299
300 function ham_admin() {
301
302 $myHam = new ham();
303
304 $form = array();
305
306 $form['general'] = array(
307 '#type' => 'fieldset',
308 '#title' => t('General'),
309 );
310
311 $form['general']['ham_mycallsign'] = array(
312 '#type' => 'textfield',
313 '#title' => t('Ham Station ID'),
314 '#default_value' => variable_get('ham_mycallsign', 'ABC123'),
315 '#size' => 12,
316 '#maxlength' => 12,
317 '#description' => t("Your Ham Callsign."),
318 '#required' => TRUE,
319 );
320
321 for ($i = 0; $i < 6; $i++) {
322 $lic_array[$i] = $myHam->get_license_type_name($i);
323 }
324
325 $form['general']['license_type'] = array(
326 '#type' => 'select',
327 '#title' => t('FCC License Class'),
328 '#description' => t("Only applicable to who want to check logs for out of band transmissions."),
329 '#options' => $lic_array,
330 );
331
332 $cols_array['datetime'] = "UTC Date & Time";
333 $cols_array['hiscall'] = "His Call";
334 $cols_array['hisgrid'] = "His Grid";
335 $cols_array['mygrid'] = "My Grid";
336 $cols_array['country'] = "His Country";
337 $cols_array['mode'] = "Mode";
338 $cols_array['band'] = "Band";
339 $cols_array['freq'] = "Frequency";
340
341 $form['general']['display_col'] = array(
342 '#type' => 'checkboxes',
343 '#title' => t('Columns to display on logbook page'),
344 '#description' => t("Selected Fields will be displayed."),
345 '#options' => $cols_array,
346 );
347
348 $form['import'] = array(
349 '#type' => 'fieldset',
350 '#title' => t('Import Logbook'),
351 '#description' => t('Import QSO log from ADIF logbook file. <em>Warning: Line breaks or special characters may cause parsing errors.</em>'),
352 );
353
354 $form['import']['upload'] = array(
355 '#type' => 'file',
356 '#title' => t('Attach ADIF file'),
357 '#size' => 40,
358 );
359 $form['import']['import'] = array(
360 '#type' => 'submit',
361 '#value' => t('Import Log'),
362 '#submit' => array('ham_import_submit'),
363 );
364 $form['#attributes'] = array('enctype' => "multipart/form-data");
365
366
367 $form['purge_log'] = array(
368 '#type' => 'fieldset',
369 '#title' => t('Purge Ham Radio Log'),
370 '#description' => t('Clear the logbook database table. <em>Warning: Only use this if you have updated your local logbook and wish import it again.</em>'),
371 );
372
373 $form['purge_log']['clear'] = array(
374 '#type' => 'submit',
375 '#value' => t('Purge All Log Entries'),
376 '#submit' => array('ham_purge_submit'),
377 );
378
379 return system_settings_form($form);
380 }
381
382 function ham_purge_submit(&$form_state, $form) {
383 $result = db_query("TRUNCATE TABLE `ham_qso`");
384 drupal_set_message(t('Logbook purged.'));
385 }
386
387 function ham_import_submit(&$form_state, $form) {
388
389 if ($file = file_save_upload('upload')) {
390 $filename = $file->filepath;
391 adif_import($filename);
392 file_delete($filename);
393 drupal_set_message(t('Logbook imported.'));
394 }
395 else {
396 drupal_set_message(t('Import failed.'));
397 }
398 ham_generate_statistics();
399 }
400
401 function ham_generate_statistics() {
402 drupal_set_message(t('Summary Statistics Generated.'));
403 return;
404 }
405
406 function ham_menu() {
407
408 $items = array();
409
410 $items['admin/settings/ham'] = array(
411 'title' => 'Drupal Ham Radio Module Settings',
412 'description' => 'Station Information',
413 'page callback' => 'drupal_get_form',
414 'page arguments' => array('ham_admin'),
415 'access arguments' => array('access ham administration pages'),
416 'type' => MENU_NORMAL_ITEM,
417 );
418
419 $items['ham'] = array(
420 'title' => 'Drupal Ham Radio Module',
421 'page callback' => 'ham_main',
422 'access arguments' => array('access ham content'),
423 'type' => MENU_NORMAL_ITEM,
424 );
425
426 $items['ham/logbook'] = array(
427 'title' => 'Logbook',
428 'page callback' => 'ham_logbook',
429 'access arguments' => array('access ham content'),
430 'type' => MENU_NORMAL_ITEM,
431 );
432
433
434 $items['ham/callsign/%'] = array(
435 'title' => 'Contact Detail',
436 'page callback' => 'ham_callsign',
437 'page arguments' => array(2),
438 'access arguments' => array('access ham content'),
439 'type' => MENU_CALLBACK,
440 );
441
442 $items['ham/country/%'] = array(
443 'title' => 'Country Detail',
444 'page callback' => 'ham_country',
445 'page arguments' => array(2),
446 'access arguments' => array('access ham content'),
447 'type' => MENU_CALLBACK,
448 );
449
450 $items['ham/date/%/%'] = array(
451 'title' => 'QSO by Date',
452 'page callback' => 'ham_date',
453 'page arguments' => array(2,3),
454 'access arguments' => array('access ham content'),
455 'type' => MENU_CALLBACK,
456 );
457
458 $items['ham/date/%'] = array(
459 'title' => 'QSO by Date',
460 'page callback' => 'ham_date',
461 'page arguments' => array(2),
462 'access arguments' => array('access ham content'),
463 'type' => MENU_CALLBACK,
464 );
465
466 return $items;
467 }

  ViewVC Help
Powered by ViewVC 1.1.2