Merge lp:~chamindra/sahana-agasti/sahana-relief-0.1 into lp:~sahana-relief-team/sahana-agasti/trunk

Proposed by chamindra
Status: Merged
Merge reported by: chamindra
Merged at revision: not available
Proposed branch: lp:~chamindra/sahana-agasti/sahana-relief-0.1
Merge into: lp:~sahana-relief-team/sahana-agasti/trunk
Diff against target: 693 lines
To merge this branch: bzr merge lp:~chamindra/sahana-agasti/sahana-relief-0.1
Reviewer Review Type Date Requested Status
chamindra Approve
Ajay Kumar Approve
Gavin Treadgold (community) Approve
Review via email: mp+15002@code.launchpad.net
To post a comment you must log in.
Revision history for this message
chamindra (chamindra) wrote :

1) Modified code to work functionally with the messaging module in windows
2) Implemented a new user-friendly SMS protocol for entering map points

e.g. map N35.26272 W120.27373 hospital 30 patients to be evacuated

Response:

Map point hospital confirmed

3) Implemented confirmation notification of map point and other data
4) Updated the SMS help messaging
5) Automatic assignment of feature class and associated icon on situation map based on SMS message
6) Implemented the sharing of KML feeds between Sahana and mods when the KML does not have .kml extension
7) Updated the backend to support the protocol sent by the android application

A few more tweaks are needed on the above to complete

Revision history for this message
Ajay Kumar (ajuonline) :
review: Approve
Revision history for this message
Ajay Kumar (ajuonline) :
review: Needs Resubmitting
Revision history for this message
Gavin Treadgold (gt) wrote :

From a domain (not code perspective) - very keen to have this merge approved. Very useful functionality.

AJ - why did you suggest a resubmit?

review: Approve
Revision history for this message
Ajay Kumar (ajuonline) wrote :

Earlier Approve/Resubmit was done in error :)
OK for merge.

review: Approve
Revision history for this message
chamindra (chamindra) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'inc/lib_gis/plugins/openlayers/openlayers_fns.php' (properties changed: -x to +x)
--- inc/lib_gis/plugins/openlayers/openlayers_fns.php 2009-11-10 23:51:44 +0000
+++ inc/lib_gis/plugins/openlayers/openlayers_fns.php 2009-11-18 18:15:32 +0000
@@ -521,8 +521,12 @@
521 if (1==$conf["gis_ol_kml_".$i."_enabled"]) {521 if (1==$conf["gis_ol_kml_".$i."_enabled"]) {
522 $name = $conf["gis_ol_kml_".$i."_name"];522 $name = $conf["gis_ol_kml_".$i."_name"];
523 $url = $conf["gis_ol_kml_".$i."_url"];523 $url = $conf["gis_ol_kml_".$i."_url"];
524 $file=end(explode('/',$url));524
525 $ext=end(explode('.',$url));525 #$file=end(explode('/',$url));
526 # Changed to provide a kml extension by default
527 $file = md5($url).".kml";
528 $ext = "kml"; #end(explode('.',$url));
529
526 $path = $dir."/".$file;530 $path = $dir."/".$file;
527 $ch = curl_init();531 $ch = curl_init();
528 curl_setopt($ch, CURLOPT_URL,$url);532 curl_setopt($ch, CURLOPT_URL,$url);
529533
=== modified file 'inst/setup_pages.inc'
--- inst/setup_pages.inc 2009-11-10 23:51:44 +0000
+++ inst/setup_pages.inc 2009-11-18 18:15:32 +0000
@@ -65,7 +65,8 @@
65 }65 }
6666
67 // Check if php-gettext is loaded67 // Check if php-gettext is loaded
68 $value = (extension_loaded('gettext'));68 // TODO: Fix this in Portable app
69/* $value = (extension_loaded('gettext'));
69 $isOK &= $value;70 $isOK &= $value;
7071
71 if ($value) {72 if ($value) {
@@ -74,7 +75,7 @@
74 shn_form_label(_t('PHP-gettext Library'), $cross_img."is not installed");75 shn_form_label(_t('PHP-gettext Library'), $cross_img."is not installed");
75 echo "<p><br/>$oops_img Sahana needs PHP-gettext for to support local languages. Please install PHP-gettext and restart the webserver. To find out how to do this for your operating system see <a href=\"http://www.sahana.lk/wiki/doku.php?id=manual:install\">Sahana WIKI</a></p>";76 echo "<p><br/>$oops_img Sahana needs PHP-gettext for to support local languages. Please install PHP-gettext and restart the webserver. To find out how to do this for your operating system see <a href=\"http://www.sahana.lk/wiki/doku.php?id=manual:install\">Sahana WIKI</a></p>";
76 }77 }
7778*/
78 $value = (extension_loaded('mysql'));79 $value = (extension_loaded('mysql'));
79 $isOK &= $value;80 $isOK &= $value;
8081
8182
=== modified file 'inst/setup_validations.inc'
--- inst/setup_validations.inc 2009-11-10 23:51:44 +0000
+++ inst/setup_validations.inc 2009-11-18 18:15:32 +0000
@@ -48,7 +48,7 @@
48 if (!version_compare(phpversion(), '5', '>')) $continue = false;48 if (!version_compare(phpversion(), '5', '>')) $continue = false;
49 if (!extension_loaded('gd')) $continue = false;49 if (!extension_loaded('gd')) $continue = false;
50 if (!extension_loaded('mysql')) $continue = false;50 if (!extension_loaded('mysql')) $continue = false;
51 if (!extension_loaded('gettext')) $continue = false;51 // TODO: fix gettext in potable apps // if (!extension_loaded('gettext')) $continue = false;
52 if (!is_writable($global['approot'].'www/tmp')) $continue = false;52 if (!is_writable($global['approot'].'www/tmp')) $continue = false;
53 if (!is_writable($global['approot'].'conf')) $continue = false;53 if (!is_writable($global['approot'].'conf')) $continue = false;
54 return $continue;54 return $continue;
5555
=== modified file 'mod/msg/lib_sms_errors.inc' (properties changed: -x to +x)
--- mod/msg/lib_sms_errors.inc 2009-11-10 23:51:44 +0000
+++ mod/msg/lib_sms_errors.inc 2009-11-18 18:15:32 +0000
@@ -1,1 +1,47 @@
1<?php
2/**1/**
3*2*
4* This is a SMS error handler, you can create and manage a SMS error message container3* This is a SMS error handler, you can create and manage a SMS error message container
5* and send the errors via SMS to users accessing Sahana through SMS.4* and send the errors via SMS to users accessing Sahana through SMS.
6* Developers should note the fact that, error message length should preferably be less than 160 characters5* Developers should note the fact that, error message length should preferably be less than 160 characters
7* which is the standard SMS length. Text greater than 160 characters should also be supported but should6* which is the standard SMS length. Text greater than 160 characters should also be supported but should
8* ideally be avoided. Make sure you dont print/echo any message in PHP/HTML as this is supposed to be7* ideally be avoided. Make sure you dont print/echo any message in PHP/HTML as this is supposed to be
9* dealt via an SMS session, so no echoing of messages. Supress all echo strings or use it for debugging only.8* dealt via an SMS session, so no echoing of messages. Supress all echo strings or use it for debugging only.
10* Echoing any strings will break the SMS message text formation and break the session resulting in user not9* Echoing any strings will break the SMS message text formation and break the session resulting in user not
11* getting any response to his SMS.10* getting any response to his SMS.
12*11*
13* PHP version 4 and 512* PHP version 4 and 5
14*13*
15* LICENSE: This source file is subject to LGPL license14* LICENSE: This source file is subject to LGPL license
16* that is available through the world-wide-web at the following URI:15* that is available through the world-wide-web at the following URI:
17* http://www.gnu.org/copyleft/lesser.html16* http://www.gnu.org/copyleft/lesser.html
18*17*
19* @package moduleAPI18* @package moduleAPI
20* @subpackage errors19* @subpackage errors
21* @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>20* @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>
22* @copyright Lanka Software Foundation - http://www.opensource.lk21* @copyright Lanka Software Foundation - http://www.opensource.lk
23* @version $Id: lib_sms_errors.inc,v 1.3 2008/11/09 10:52:49 ajuonline Exp $22* @version $Id: lib_sms_errors.inc,v 1.3 2008/11/09 10:52:49 ajuonline Exp $
24* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)23* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
25*/24*/
2625
2726
2827
29function _shn_msg_sms_error_code($error_code){28function _shn_msg_sms_error_code($error_code){
3029
31 $error_code_messages = array(30 $error_code_messages = array(
3231
33 '1' => 'Invalid SMS Keyword Sent. Kindly send HELP to get the list of keywords.',32 '1' => 'Invalid SMS Keyword Sent. Kindly send HELP to get the list of keywords.',
3433
35 '2' => 'Sahana Server Error. Unable to connect to Data base. Please try later or contact Sahana Admin at.',34 '2' => 'Sahana Server Error. Unable to connect to Data base. Please try later or contact Sahana Admin at.',
3635
37 '3' => 'Login Failed : Invalid user name or password.',36 '3' => 'Login Failed : Invalid user name or password.',
3837
39 '4' => 'Login Failed : You have been banned by an administrator of the system.',38 '4' => 'Login Failed : You have been banned by an administrator of the system.',
4039
41 '5' => 'Login Failed : This account has been locked. Please contact the Administrator to unlock the account.',40 '5' => 'Login Failed : This account has been locked. Please contact the Administrator to unlock the account.',
4241
43 '6' => 'Login Failed : Password log attacked.',42 '6' => 'Login Failed : Password log attacked.',
4443
45 '7' => 'Login Failed : Account is not active yet. Contact Administrator to activate your account'44 '7' => 'Login Failed : Account is not active yet. Contact Administrator to activate your account'
4645
47 );46 );
4847
49 if(array_key_exists($error_code, $error_code_messages)){48 if(array_key_exists($error_code, $error_code_messages)){
5049
51 return $error_code_messages[$error_code];50 return $error_code_messages[$error_code];
5251
53 }52 }
5453
55 else{54 else{
5655
57 return 0;56 return 0;
5857
59 }58 }
6059
61}60}
6261
63?>62?>
64\ No newline at end of file63\ No newline at end of file
64<?php
65/**
66 *
67 * This is a SMS error handler, you can create and manage a SMS error message container
68 * and send the errors via SMS to users accessing Sahana through SMS.
69 * Developers should note the fact that, error message length should preferably be less than 160 characters
70 * which is the standard SMS length. Text greater than 160 characters should also be supported but should
71 * ideally be avoided. Make sure you dont print/echo any message in PHP/HTML as this is supposed to be
72 * dealt via an SMS session, so no echoing of messages. Supress all echo strings or use it for debugging only.
73 * Echoing any strings will break the SMS message text formation and break the session resulting in user not
74 * getting any response to his SMS.
75 *
76 * PHP version 4 and 5
77 *
78 * LICENSE: This source file is subject to LGPL license
79 * that is available through the world-wide-web at the following URI:
80 * http://www.gnu.org/copyleft/lesser.html
81 *
82 * @package moduleAPI
83 * @subpackage errors
84 * @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>
85 * @copyright Lanka Software Foundation - http://www.opensource.lk
86 * @version $Id: lib_sms_errors.inc,v 1.3 2008/11/09 10:52:49 ajuonline Exp $
87 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
88 */
89function _shn_msg_sms_error_code($error_code){
90
91 $error_code_messages = array(
92
93 '1' => 'Invalid SMS Keyword Sent. Kindly send HELP to get the list of keywords.',
94 'invalid_keyword' => 'Invalid SMS Keyword Sent. Kindly send HELP to get the list of keywords',
95
96 '2' => 'Sahana Server Error. Unable to connect to Data base. Please try later or contact Sahana Admin at.',
97 '3' => 'Login Failed : Invalid user name or password.',
98 '4' => 'Login Failed : You have been banned by an administrator of the system.',
99 '5' => 'Login Failed : This account has been locked. Please contact the Administrator to unlock the account.',
100 '6' => 'Login Failed : Password log attacked.',
101 '7' => 'Login Failed : Account is not active yet. Contact Administrator to activate your account'
102 );
103 if(array_key_exists($error_code, $error_code_messages)){
104 return $error_code_messages[$error_code];
105 }
106 else{
107 return 0;
108 }
109}
110?>
65111
=== modified file 'mod/msg/lib_sms_handler.inc' (properties changed: -x to +x)
--- mod/msg/lib_sms_handler.inc 2009-11-10 23:51:44 +0000
+++ mod/msg/lib_sms_handler.inc 2009-11-18 18:15:32 +0000
@@ -1,1 +1,343 @@
1<?php
2/**1/**
3*2*
4* This library helps in parsing and triggering functions based on SMS Input. A vital component of the framework.3* This library helps in parsing and triggering functions based on SMS Input. A vital component of the framework.
5* Developers are required to use this library to facilitate SMS based transactions with the Sahana Core.4* Developers are required to use this library to facilitate SMS based transactions with the Sahana Core.
6*5*
7*6*
8* PHP version 4 and 57* PHP version 4 and 5
9*8*
10* LICENSE: This source file is subject to LGPL license9* LICENSE: This source file is subject to LGPL license
11* that is available through the world-wide-web at the following URI:10* that is available through the world-wide-web at the following URI:
12* http://www.gnu.org/copyleft/lesser.html11* http://www.gnu.org/copyleft/lesser.html
13*12*
14* @package framework13* @package framework
15* @subpackage messaging14* @subpackage messaging
16* @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>15* @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>
17* @copyright Lanka Software Foundation - http://www.opensource.lk16* @copyright Lanka Software Foundation - http://www.opensource.lk
18* @version $Id: lib_sms_handler.inc,v 1.2 2008/09/15 13:50:13 franboon Exp $17* @version $Id: lib_sms_handler.inc,v 1.2 2008/09/15 13:50:13 franboon Exp $
19* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)18* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
20*19*
21*/20*/
2221
23global $global;22global $global;
24include_once $global['approot']."/mod/msg/lib_sms_errors.inc";23include_once $global['approot']."/mod/msg/lib_sms_errors.inc";
25include_once $global['approot']."/mod/msg/lib_sms_keywords.inc";24include_once $global['approot']."/mod/msg/lib_sms_keywords.inc";
2625
27/**26/**
28* This function will parse the incoming message string sent via GET & POST27* This function will parse the incoming message string sent via GET & POST
29* Currently this function will be used by Kannel and SMSTools28* Currently this function will be used by Kannel and SMSTools
30* It returns the array containing all words/strings, as single array values, sent in the SMS seperated by a SPACE29* It returns the array containing all words/strings, as single array values, sent in the SMS seperated by a SPACE
31* For e.g. For a message string i.e. $message = "login user pass";30* For e.g. For a message string i.e. $message = "login user pass";
32* $parsed_message[0]="login"31* $parsed_message[0]="login"
33* $parsed_message[1]="user"32* $parsed_message[1]="user"
34* $parsed_message[2]="pass"33* $parsed_message[2]="pass"
35*/34*/
3635
37function _shn_msg_parse_short_message($message){36function _shn_msg_parse_short_message($message){
3837
39 $parsed_message=array();38 $parsed_message=array();
40 $parsed_message = explode(" ", $message);39 $parsed_message = explode(" ", $message);
41 return $parsed_message;40 return $parsed_message;
42}41}
4342
44/**43/**
45* This function will check the first word of the incoming message string44* This function will check the first word of the incoming message string
46* and return the corresponding menu value only.45* and return the corresponding menu value only.
47* For. e.g. as per our keyword definition file46* For. e.g. as per our keyword definition file
48*/47*/
4948
50function _shn_msg_sms_keyword_check($keyword, $sender){49function _shn_msg_sms_keyword_check($keyword, $sender){
5150
52 global $global;51 global $global;
53 global $sms_list_keywords;52 global $sms_list_keywords;
54 if(is_numeric($keyword)){ 53 if(is_numeric($keyword)){
55 if(array_key_exists($keyword, $sms_list_keywords)){54 if(array_key_exists($keyword, $sms_list_keywords)){
56 $keyword_check_result = array ('return' => '1', 'type' => 'number');55 $keyword_check_result = array ('return' => '1', 'type' => 'number');
57 //echo " Key word valid and is number";56 //echo " Key word valid and is number";
58 return $keyword_check_result;57 return $keyword_check_result;
59 }58 }
60 else{59 else{
61 $error_message = _shn_msg_sms_error_code(1);60 $error_message = _shn_msg_sms_error_code(1);
62 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";61 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";
63 $recipients = array ($sender);//handler_plugin.inc send sms function accepts array as input for recipients62 $recipients = array ($sender);//handler_plugin.inc send sms function accepts array as input for recipients
64 shn_msg_plugin_send_sm($recipients, $error_message);63 shn_msg_plugin_send_sm($recipients, $error_message);
65 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table64 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
66 //echo "<br \>Error SMS: ".$error_message;65 //echo "<br \>Error SMS: ".$error_message;
67 return 0;66 return 0;
68 }67 }
69 }68 }
70 else{69 else{
71 $bool = array_search($keyword, $sms_list_keywords);70 $bool = array_search($keyword, $sms_list_keywords);
72 if(array_search($keyword, $sms_list_keywords)){71 if(array_search($keyword, $sms_list_keywords)){
73 $keyword_check_result = array ('return' => '1', 'type' => 'word');72 $keyword_check_result = array ('return' => '1', 'type' => 'word');
74 //echo " key word is valid and is WORD";73 //echo " key word is valid and is WORD";
75 return $keyword_check_result;74 return $keyword_check_result;
76 }75 }
77 else{76 else{
78 $error_message = _shn_msg_sms_error_code(1);77 $error_message = _shn_msg_sms_error_code(1);
79 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";78 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";
80 $recipients = array ($sender);//handler_plugin.inc send sms function accepts array as input for recipients79 $recipients = array ($sender);//handler_plugin.inc send sms function accepts array as input for recipients
81 shn_msg_plugin_send_sm($recipients, $error_message);80 shn_msg_plugin_send_sm($recipients, $error_message);
82 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table81 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
83 //echo "<br \> Error SMS: ".$error_message;82 //echo "<br \> Error SMS: ".$error_message;
84 return 0;83 return 0;
85 }84 }
86 }85 }
87}86}
8887
89/**88/**
90* This function will check the first word of the incoming message string89* This function will check the first word of the incoming message string
91* and return the corresponding menu value only.90* and return the corresponding menu value only.
92* For. e.g. as per our keyword definition file91* For. e.g. as per our keyword definition file
93*/92*/
9493
95function _shn_msg_sms_action($parsed_sms, $sender_phone_number){94function _shn_msg_sms_action($parsed_sms, $sender_phone_number){
96 95
97 global $global;96 global $global;
98 if(("help"==$parsed_sms[0]) || ("911"==$parsed_sms[0])){97 if(("help"==$parsed_sms[0]) || ("911"==$parsed_sms[0])){
99 _shn_msg_sms_help($parsed_sms, $sender_phone_number);98 _shn_msg_sms_help($parsed_sms, $sender_phone_number);
100 } 99 }
101 100
102 elseif(("login"==$parsed_sms[0]) || ("100"==$parsed_sms[0])){101 elseif(("login"==$parsed_sms[0]) || ("100"==$parsed_sms[0])){
103 _shn_msg_sms_login($parsed_sms, $sender_phone_number);102 _shn_msg_sms_login($parsed_sms, $sender_phone_number);
104 }103 }
105 elseif(("sm"==$parsed_sms[0]) || ("3"==$parsed_sms[0])){104 elseif(("sm"==$parsed_sms[0]) || ("3"==$parsed_sms[0])){
106 if("search"==$parsed_sms[1]){105 if("search"==$parsed_sms[1]){
107 require_once $global['approot'] . "/inc/lib_gis/gis_fns.inc";106 require_once $global['approot'] . "/inc/lib_gis/gis_fns.inc";
108 $keys = array('all' => '1');107 $keys = array('all' => '1');
109 $features = shn_gis_get_features_in_radius($keys, $parsed_sms[2], $parsed_sms[3], $parsed_sms[4]);108 $features = shn_gis_get_features_in_radius($keys, $parsed_sms[2], $parsed_sms[3], $parsed_sms[4]);
110 //print_r($features);109 //print_r($features);
111 $count = count($features);110 $count = count($features);
112 //echo "<br /> $count <br />";111 //echo "<br /> $count <br />";
113 112
114 if($count){113 if($count){
115 $final_results = array();114 $final_results = array();
116 $i = 1;115 $i = 1;
117 $message = "Results Found:\n";116 $message = "Results Found:\n";
118 foreach($features as $a){117 foreach($features as $a){
119 118
120 119
121 //$coords = shn_gis_coord_decode($a[f_coords]);120 //$coords = shn_gis_coord_decode($a[f_coords]);
122 //print_r($coords); @ returns 2 values for 1 input. needed to check with GIS fns and figure out a way121 //print_r($coords); @ returns 2 values for 1 input. needed to check with GIS fns and figure out a way
123 array_push($final_results, array("$a[f_name]", "$a[f_description]", "$a[f_coords]", "$a[f_event_date]"));122 array_push($final_results, array("$a[f_name]", "$a[f_description]", "$a[f_coords]", "$a[f_event_date]"));
124 $message .= "$i. Name - $a[f_name]\nDescription: $a[f_description]\nGPS Loc: $a[f_coords]\nTimeStamp: $a[f_event_date]\n";123 $message .= "$i. Name - $a[f_name]\nDescription: $a[f_description]\nGPS Loc: $a[f_coords]\nTimeStamp: $a[f_event_date]\n";
125 $i++;124 $i++;
126 }125 }
127 }126 }
128 else{127 else{
129 $message = "No Situations Found! Please try modifying your search.";128 $message = "No Situations Found! Please try modifying your search.";
130 }129 }
131 130
132 //print_r($final_results);131 //print_r($final_results);
133 132
134 }133 }
135 elseif("add"==$parsed_sms[1]){134 elseif("add"==$parsed_sms[1]){
136 //Valid Input SMS format "sm add <name> <description> <gps_coords>"135 //Valid Input SMS format "sm add <name> <description> <gps_coords>"
137 //Sample: "sm add (First Situation) (Description of the first situation) (77,78)"136 //Sample: "sm add (First Situation) (Description of the first situation) (77,78)"
138 //Restructre parsed SMS Text137 //Restructre parsed SMS Text
139 138
140 $full_sms_input_text = implode(" ", $parsed_sms);139 $full_sms_input_text = implode(" ", $parsed_sms);
141 //Re-parsing as per Standard SM ADD format mentioned above140 //Re-parsing as per Standard SM ADD format mentioned above
142 //$value = "sm add (First Situation) (Description of the first situation) (77,78)";141 //$value = "sm add (First Situation) (Description of the first situation) (77,78)";
143 if (ereg ("(sm) (add) \((.+)\) \((.+)\) \(([0-9]{2,3}),([0-9]{2,3})\)", $full_sms_input_text, $regs))142 if (ereg ("(sm) (add) \((.+)\) \((.+)\) \(([0-9]{2,3}),([0-9]{2,3})\)", $full_sms_input_text, $regs))
144 {143 {
145 //print_r($regs);144 //print_r($regs);
146 145
147 // Include for the GIS Database API.146 // Include for the GIS Database API.
148 require_once $global['approot']."/inc/lib_security/lib_sms_auth.inc";147 require_once $global['approot']."/inc/lib_security/lib_sms_auth.inc";
149 print_r($_SESSION);148 print_r($_SESSION);
150 $f_name = $regs[3];149 $f_name = $regs[3];
151 $f_description = $regs[4];150 $f_description = $regs[4];
152 $f_author = shn_get_user_details($user_data['user_id']);;151 $f_author = shn_get_user_details($user_data['user_id']);;
153 $f_event_date = date("Y-m-d H:i:s");152 $f_event_date = date("Y-m-d H:i:s");
154 $marker_x_lat_coordinate = $regs[5];153 $marker_x_lat_coordinate = $regs[5];
155 $marker_y_lng_coordinate = $regs[6];154 $marker_y_lng_coordinate = $regs[6];
156 require_once $global['approot']."/inc/lib_gis/gis_fns.inc";155 require_once $global['approot']."/inc/lib_gis/gis_fns.inc";
157 // Parse the Coordinates to wkt format.156 // Parse the Coordinates to wkt format.
158 $coords_center = array($marker_x_lat_coordinate, $marker_y_lng_coordinate, 0);157 $coords_center = array($marker_x_lat_coordinate, $marker_y_lng_coordinate, 0);
159 $coords = array($coords_center, $coords_center);158 $coords = array($coords_center, $coords_center);
160 $coordinates = shn_gis_coord_encode($coords, 'point');159 $coordinates = shn_gis_coord_encode($coords, 'point');
161 160
162 // Register the values that will make the new feature as an array of key => values.161 // Register the values that will make the new feature as an array of key => values.
163 $keys_ = array( 162 $keys_ = array(
164 'f_type' => 'point',163 'f_type' => 'point',
165 'f_projection' => 'EPSG:900913',164 'f_projection' => 'EPSG:900913',
166 'f_coords' => $coordinates,165 'f_coords' => $coordinates,
167 'f_name' => $f_name,166 'f_name' => $f_name,
168 'f_description' => $f_description,167 'f_description' => $f_description,
169 'f_author' => $f_author,168 'f_author' => $f_author,
170 'f_event_date' => $f_event_date,169 'f_event_date' => $f_event_date,
171 );170 );
172 // print_r($keys_);171 // print_r($keys_);
173 // Create the Feature.172 // Create the Feature.
174 shn_gis_create_feature($keys_);173 shn_gis_create_feature($keys_);
175 174
176 } else {175 } else {
177 $message = "Invalid Input format for SM Add";176 $message = "Invalid Input format for SM Add";
178 }177 }
179178
180 } 179 }
181 else{180 else{
182 $message = "Invalid Keyword for SM Module sent. Please retry or send HELP SM to get list of valid arguements.";181 $message = "Invalid Keyword for SM Module sent. Please retry or send HELP SM to get list of valid arguements.";
183 }182 }
184 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";183 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";
185 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients184 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients
186 if($message) shn_msg_plugin_send_sm($recipients, $message);185 if($message) shn_msg_plugin_send_sm($recipients, $message);
187 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table186 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
188 //echo "<br \> Error SMS: ".$error_message;187 //echo "<br \> Error SMS: ".$error_message;
189 return 0; 188 return 0;
190 } 189 }
191190
192 else{191 else{
193 $error_message = _shn_msg_sms_error_code(1);192 $error_message = _shn_msg_sms_error_code(1);
194 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";193 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";
195 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients194 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients
196 shn_msg_plugin_send_sm($recipients, $error_message);195 shn_msg_plugin_send_sm($recipients, $error_message);
197 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table196 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
198 //echo "<br \> Error SMS: ".$error_message;197 //echo "<br \> Error SMS: ".$error_message;
199 return 0;198 return 0;
200 } 199 }
201}200}
202201
203202
204203
205/**204/**
206* Function calls specific to the keyword sent are listed here. Module writers should write module specific calls 205* Function calls specific to the keyword sent are listed here. Module writers should write module specific calls
207* modified for the purpose of SMS here.206* modified for the purpose of SMS here.
208* E.g. The function should return values which can later be formatted as plain text. No HTML output should be returned as is the case207* E.g. The function should return values which can later be formatted as plain text. No HTML output should be returned as is the case
209* right now for the Sahana core functions which concentrate on the Web App208* right now for the Sahana core functions which concentrate on the Web App
210 */209 */
211210
212211
213/** Action Building Main Menu ***/212/** Action Building Main Menu ***/
214213
215function _shn_msg_sms_menu(){214function _shn_msg_sms_menu(){
216 215
217 global $sms_list_keywords;216 global $sms_list_keywords;
218 $sms_main_menu = "Sahana Main Menu: \nNumeric Code - Word Code\n";217 $sms_main_menu = "Sahana Main Menu: \nNumeric Code - Word Code\n";
219 foreach ($sms_list_keywords as $k => $v) {218 foreach ($sms_list_keywords as $k => $v) {
220 $sms_main_menu .= "[$k] - $v\n";219 $sms_main_menu .= "[$k] - $v\n";
221 }220 }
222 return $sms_main_menu;221 return $sms_main_menu;
223} 222}
224223
225224
226/** Action Help - Keyword == help or Numeric Code == 911 **/225/** Action Help - Keyword == help or Numeric Code == 911 **/
227226
228function _shn_msg_sms_help($parsed_sms, $sender_phone_number){227function _shn_msg_sms_help($parsed_sms, $sender_phone_number){
229228
230 global $global;229 global $global;
231 $sms_main_menu = _shn_msg_sms_menu();230 $sms_main_menu = _shn_msg_sms_menu();
232 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";231 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";
233 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients232 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients
234 shn_msg_plugin_send_sm($recipients, $sms_main_menu);233 shn_msg_plugin_send_sm($recipients, $sms_main_menu);
235 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table234 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
236 //echo "<br \> Error SMS: ".$error_message;235 //echo "<br \> Error SMS: ".$error_message;
237 return 0; 236 return 0;
238237
239} 238}
240239
241240
242/** Action Login - Keyword == login or Numeric Code == 100 **/241/** Action Login - Keyword == login or Numeric Code == 100 **/
243242
244function _shn_msg_sms_login($parsed_sms, $sender_phone_number){243function _shn_msg_sms_login($parsed_sms, $sender_phone_number){
245244
246 global $global;245 global $global;
247 require_once $global['approot']."/inc/lib_security/lib_sms_auth.inc";246 require_once $global['approot']."/inc/lib_security/lib_sms_auth.inc";
248 $user_data = _shn_authenticate_user($parsed_sms);247 $user_data = _shn_authenticate_user($parsed_sms);
249 shn_session_change($user_data);248 shn_session_change($user_data);
250 //print_r($user_data);249 //print_r($user_data);
251 if(!$user_data['error_code']){250 if(!$user_data['error_code']){
252 $full_name = shn_get_user_details($user_data['user_id']);251 $full_name = shn_get_user_details($user_data['user_id']);
253 //echo "<br \>Welcome, <strong>".$full_name."</strong> you are logged in to Sahana System via SMS. yAy!! <br \>";252 //echo "<br \>Welcome, <strong>".$full_name."</strong> you are logged in to Sahana System via SMS. yAy!! <br \>";
254 $message = "Welcome, ".$full_name." you are logged in to Sahana System via SMS.\n"; 253 $message = "Welcome, ".$full_name." you are logged in to Sahana System via SMS.\n";
255 $sms_main_menu = _shn_msg_sms_menu();254 $sms_main_menu = _shn_msg_sms_menu();
256 $sms_to_send = $message . $sms_main_menu;255 $sms_to_send = $message . $sms_main_menu;
257 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";256 include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";
258 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients257 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients
259 shn_msg_plugin_send_sm($recipients, $sms_to_send);258 shn_msg_plugin_send_sm($recipients, $sms_to_send);
260 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table259 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
261 //echo "<br \> Error SMS: ".$error_message;260 //echo "<br \> Error SMS: ".$error_message;
262 return 0; 261 return 0;
263 //print_r($_SESSION);262 //print_r($_SESSION);
264 $sessid = session_id();263 $sessid = session_id();
265 //echo $sessid;264 //echo $sessid;
266 } 265 }
267 266
268}267}
269268
270?>269?>
271\ No newline at end of file270\ No newline at end of file
271<?php
272/**
273 *
274 * This library helps in parsing and triggering functions based on SMS Input. A vital component of the framework.
275 * Developers are required to use this library to facilitate SMS based transactions with the Sahana Core.
276 *
277 *
278 * PHP version 4 and 5
279 *
280 * LICENSE: This source file is subject to LGPL license
281 * that is available through the world-wide-web at the following URI:
282 * http://www.gnu.org/copyleft/lesser.html
283 *
284 * @package framework
285 * @subpackage messaging
286 * @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>
287 * @copyright Lanka Software Foundation - http://www.opensource.lk
288 * @version $Id: lib_sms_handler.inc,v 1.2 2008/09/15 13:50:13 franboon Exp $
289 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
290 *
291 */
292global $global;
293
294global $sms_list_keywords;
295
296# include_once $global['approot']."/mod/msg/lib_sms_keywords.inc";
297$sms_list_keywords = array(
298 '1' => 'login',
299 '2' => 'map',
300 '3' => 'sm',
301 '100' => 'login',
302 '911' => 'help'
303);
304
305include_once $global['approot']."/mod/msg/lib_sms_errors.inc";
306include_once $global['approot']."/mod/msg/plugins/"."$plugin_name"."/handler_"."$plugin_name".".inc";
307/**
308 * This function will parse the incoming message string sent via GET & POST
309 * Currently this function will be used by Kannel and SMSTools
310 * It returns the array containing all words/strings, as single array values, sent in the SMS seperated by a SPACE
311 * For e.g. For a message string i.e. $message = "login user pass";
312 * $parsed_message[0]="login"
313 * $parsed_message[1]="user"
314 * $parsed_message[2]="pass"
315 */
316function _shn_msg_parse_short_message($message){
317
318 $parsed_message=array();
319 $parsed_message = explode(" ", $message);
320
321 // convert to lower to handle first letter capitilization
322 $parsed_message[0] = strtolower($parsed_message[0]);
323
324 // DEBUG: parsed message
325 print_r($parsed_message);
326
327 return $parsed_message;
328}
329/**
330 * This function will check the first word of the incoming message string
331 * and return the corresponding menu value only.
332 * For. e.g. as per our keyword definition file
333 */
334function _shn_msg_sms_keyword_check($keyword, $sender){
335
336 global $global;
337 global $sms_list_keywords;
338
339 // check if number entered is a valid keyword
340 if(is_numeric($keyword)){
341
342 if(array_key_exists($keyword, $sms_list_keywords)){
343
344 $keyword_check_result = array ('return' => '1', 'type' => 'number');
345 //echo " Key word valid and is number";
346 return $keyword_check_result;
347
348 } else {
349
350 _shn_msg_sms_help("Invalid Number\n", $sender) ;
351 return 0;
352 }
353
354 } else { //check if keyword is a valid one
355
356 $bool = array_search($keyword, $sms_list_keywords);
357 if(array_search($keyword, $sms_list_keywords)){
358 $keyword_check_result = array ('return' => '1', 'type' => 'word');
359 //echo " key word is valid and is WORD";
360 return $keyword_check_result;
361 }
362 else{
363 _shn_msg_sms_help("Invalid Keyword\n", $sender) ;
364 return 0;
365 }
366 }
367}
368/**
369 * This function will check the first word of the incoming message string
370 * and return the corresponding menu value only.
371 * For. e.g. as per our keyword definition file
372 */
373function _shn_msg_sms_action($parsed_sms, $sender_phone_number){
374
375 global $global;
376
377 $keyword0 = $parsed_sms[0];
378 $keyword1 = strtolower($parsed_sms[1]);
379 $full_sms_input_text = implode(" ", $parsed_sms);
380
381 if (("help"==$keyword0) || ("911"==$keyword0)) {
382
383 _shn_msg_sms_help("", $sender_phone_number);
384 }
385
386 elseif (("login"==$keyword0) || ("100"==$keyword0)) {
387
388 _shn_msg_sms_login("", $sender_phone_number);
389
390 }
391
392 elseif ( ("map" == $keyword0) || ("sm" == $keyword0) || ("3" == $keyword0)) {
393
394 if ('help' == $keyword1) {
395
396 $message = "Type the following:\nmap lat long user title. description\nexample:\nmap n35.7153 w120.7640 hospital granada. building evacuated";
397
398 } elseif ("search"==$parsed_sms[1]){
399
400 require_once $global['approot'] . "/inc/lib_gis/gis_fns.inc";
401 $keys = array('all' => '1');
402 $features = shn_gis_get_features_in_radius($keys, $parsed_sms[2], $parsed_sms[3], $parsed_sms[4]);
403 //print_r($features);
404 $count = count($features);
405 //echo "<br /> $count <br />";
406
407 if($count){
408 $final_results = array();
409 $i = 1;
410 $message = "Results Found:\n";
411 foreach($features as $a){
412
413
414 //$coords = shn_gis_coord_decode($a[f_coords]);
415 //print_r($coords); @ returns 2 values for 1 input. needed to check with GIS fns and figure out a way
416 array_push($final_results, array("$a[f_name]", "$a[f_description]", "$a[f_coords]", "$a[f_event_date]"));
417 $message .= "$i. Name - $a[f_name]\nDescription: $a[f_description]\nGPS Loc: $a[f_coords]\nTimeStamp: $a[f_event_date]\n";
418 $i++;
419 }
420 }
421 else{
422 $message = "No Situations Found! Please try modifying your search.";
423 }
424
425 //print_r($final_results);
426
427 }
428
429 elseif( "add" == $keyword1 ){
430
431 //Valid Input SMS format "sm add <name> <description> <gps_coords>"
432 #if (ereg ("(sm) (add) \((.+)\) \((.+)\) \(([0-9]{2,3}),([0-9]{2,3})\)", $full_sms_input_text, $regs))
433 if (ereg ("(.+) (add) \((.+):(.+)\) \((.*)\) \(([-+]?([0-9]*\.[0-9]+|[0-9]+)),([-+]?([0-9]*\.[0-9]+|[0-9]+))\)", $full_sms_input_text, $regs))
434 {
435 print_r($regs);
436
437 // Include for the GIS Database API.
438 require_once $global['approot']."/inc/lib_security/lib_sms_auth.inc";
439 print_r($_SESSION);
440 $f_name = $regs[4];
441 $f_description = $regs[5];
442 $f_author = $regs[3];
443 #$f_author = shn_get_user_details($user_data['user_id']);;
444 $f_event_date = date("Y-m-d H:i:s");
445 $marker_long_coordinate = $regs[6];
446 $marker_lat_coordinate = $regs[8];
447 require_once $global['approot']."/inc/lib_gis/gis_fns.inc";
448 // Parse the Coordinates to wkt format.
449 $coords_center = array($marker_long_coordinate, $marker_lat_coordinate, 0);
450 $coords = array($coords_center, $coords_center);
451 $coordinates = shn_gis_coord_encode($coords, 'point');
452
453 // Register the values that will make the new feature as an array of key => values.
454 $keys_ = array(
455 'f_type' => 'point',
456 'f_projection' => 'EPSG:900913',
457 'f_coords' => $coordinates,
458 'f_name' => $f_name,
459 'f_description' => $f_description,
460 'f_author' => $f_author,
461 'f_event_date' => $f_event_date,
462 );
463 //print_r($keys_);
464 // Create the Feature.
465 shn_gis_create_feature($keys_);
466
467 $message = "Map point [".$f_name."] added to situation map";
468
469
470 } else {
471 $message = "Invalid input.\n Use sm add (title) (description) (latitude, longatitude)";
472 }
473
474 } else {
475
476 if (ereg ("(map) ([-+nsNS]?)([0-9]*\.[0-9]+|[0-9]+) ([-+ewEW]?)([0-9]*\.[0-9]+|[0-9]+) ([^ ]+) ([^\.]*)\. ?(.*)", $full_sms_input_text, $regs)) {
477
478 print_r($regs);
479 // Include for the GIS Database API.
480 require_once $global['approot']."/inc/lib_security/lib_sms_auth.inc";
481 //print_r($_SESSION);
482 // $f_author = $regs[6];
483 $f_author = $sender_phone_number;
484 $f_name = $regs[7];
485 $f_description = $regs[8];
486 #$f_author = shn_get_user_details($user_data['user_id']);;
487 // change the polarity based on NSEW prefix
488 $f_event_date = date("Y-m-d H:i:s");
489 $marker_long_coordinate = $regs[3];
490 if (ereg (strtolower($regs[2]),'s|-')) {
491 $marker_long_coordinate = -$marker_long_coordinate;
492 }
493 $marker_lat_coordinate = $regs[5];
494 if (ereg (strtolower($regs[4]),'w|-')) {
495 $marker_lat_coordinate = -$marker_lat_coordinate;
496 }
497
498 require_once $global['approot']."/inc/lib_gis/gis_fns.inc";
499 // Parse the Coordinates to wkt format.
500 $coords_center = array($marker_lat_coordinate, $marker_long_coordinate, 0);
501 $coords = array($coords_center, $coords_center);
502 $coordinates = shn_gis_coord_encode($coords, 'point');
503
504
505 // Register the values that will make the new feature as an array of key => values.
506 $keys_ = array(
507 'f_type' => 'point',
508 'f_projection' => 'EPSG:900913',
509 'f_coords' => $coordinates,
510 'f_name' => $f_name,
511 'f_description' => $f_description,
512 'f_author' => $f_author,
513 'f_event_date' => $f_event_date,
514 );
515
516 // see if the first keyword can be matched to a class for the marker
517 $matched_gis_classes =
518 $global['db']->Execute("SELECT * FROM `gis_feature_class` WHERE `name` LIKE '".$regs[6]."'");
519 if (null != $matched_gis_classes)
520 $keys_['f_class'] = $matched_gis_classes->fields('feature_class_uuid');
521
522 print_r($keys_);
523 // Create the Feature.
524 shn_gis_create_feature($keys_);
525
526 $message = "Map point [".$f_name."] added to situation map";
527 } else {
528
529 $message = "Type the following:\nmap lat long user title. description\nexample:\nmap n35.7153 w120.7640 hospital granada. building evacuated";
530 }
531 }
532
533 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients
534
535 // if a message is created sent it
536 if($message) shn_msg_plugin_send_sm($recipients, $message);
537 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
538 //echo "<br \> Error SMS: ".$error_message;
539 return 0;
540
541 }
542
543 else{
544
545 $error_message = _shn_msg_sms_error_code(1);
546 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients
547 shn_msg_plugin_send_sm($recipients, $error_message);
548 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
549 //echo "<br \> Error SMS: ".$error_message;
550 return 0;
551 }
552}
553/**
554* Function calls specific to the keyword sent are listed here. Module writers should write module specific calls
555* modified for the purpose of SMS here.
556 * E.g. The function should return values which can later be formatted as plain text. No HTML output should be returned as is the case
557 * right now for the Sahana core functions which concentrate on the Web App
558 */
559
560
561/** Action Building Main Menu ***/
562function _shn_msg_sms_menu(){
563
564 global $sms_list_keywords;
565 $sms_main_menu = "Use keywords below:\n";
566# foreach ($sms_list_keywords as $k => $v) {
567# $sms_main_menu .= "$k-$v\n";
568# }
569 $sms_main_menu .= "map - map point\nhelp - general help\n";
570 $sms_main_menu .= "map help - map syntax\n";
571 return $sms_main_menu;
572}
573
574/** Action Help - Keyword == help or Numeric Code == 911 **/
575function _shn_msg_sms_help($prefix_text, $sender_phone_number){
576
577 global $global;
578
579 $sms_main_menu = _shn_msg_sms_menu();
580
581 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients
582 shn_msg_plugin_send_sm($recipients, $prefix_text.$sms_main_menu);
583 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
584
585 return 0;
586}
587
588/** Action Login - Keyword == login or Numeric Code == 100 **/
589function _shn_msg_sms_login($parsed_sms, $sender_phone_number){
590
591 global $global;
592 require_once $global['approot']."/inc/lib_security/lib_sms_auth.inc";
593 $user_data = _shn_authenticate_user($parsed_sms);
594 shn_session_change($user_data);
595 //print_r($user_data);
596 if(!$user_data['error_code']){
597 $full_name = shn_get_user_details($user_data['user_id']);
598 //echo "<br \>Welcome, <strong>".$full_name."</strong> you are logged in to Sahana System via SMS. yAy!! <br \>";
599 $message = "Welcome, ".$full_name." you are logged in to Sahana System via SMS.\n";
600 $sms_main_menu = _shn_msg_sms_menu();
601 $sms_to_send = $message . $sms_main_menu;
602 $recipients = array ($sender_phone_number);//handler_plugin.inc send sms function accepts array as input for recipients
603 shn_msg_plugin_send_sm($recipients, $sms_to_send);
604 //shn_msg_store_sent_messages($recipients, $error_message); @todo check the current storage mechanism. smstools_log table
605 //echo "<br \> Error SMS: ".$error_message;
606 return 0;
607 //print_r($_SESSION);
608 $sessid = session_id();
609 //echo $sessid;
610 }
611
612}
613?>
272614
=== modified file 'mod/msg/lib_sms_keywords.inc'
--- mod/msg/lib_sms_keywords.inc 2009-11-10 23:51:44 +0000
+++ mod/msg/lib_sms_keywords.inc 2009-11-18 18:15:32 +0000
@@ -1,5 +1,28 @@
1<?php
21
3/**
4*2*
5* This file is a list of valid keywords that the Sahana server will accept through SMS3* This file is a list of valid keywords that the Sahana server will accept through SMS
6* Developers are required to use this file to list keywords and prepare user manuals for it.4* Developers are required to use this file to list keywords and prepare user manuals for it.
7* Any changes or additions to the keywords should go in this file.5* Any changes or additions to the keywords should go in this file.
8* 6*
9*7*
10* PHP version 4 and 58* PHP version 4 and 5
11*9*
12* LICENSE: This source file is subject to LGPL license10* LICENSE: This source file is subject to LGPL license
13* that is available through the world-wide-web at the following URI:11* that is available through the world-wide-web at the following URI:
14* http://www.gnu.org/copyleft/lesser.html12* http://www.gnu.org/copyleft/lesser.html
15*13*
16* @package framework14* @package framework
17* @subpackage messaging15* @subpackage messaging
18* @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>16* @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>
19* @copyright Lanka Software Foundation - http://www.opensource.lk17* @copyright Lanka Software Foundation - http://www.opensource.lk
20* @version $Id: lib_sms_keywords.inc,v 1.2 2008/09/15 13:50:13 franboon Exp $18* @version $Id: lib_sms_keywords.inc,v 1.2 2008/09/15 13:50:13 franboon Exp $
21* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)19* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
22*20*
23*/21*/
2422
25//This needs to be done in a more efficient way. By using the 3 letter module codes from the DB?23//This needs to be done in a more efficient way. By using the 3 letter module codes from the DB?
26
27
28global $sms_list_keywords;
2924
30$sms_list_keywords = array('1' => 'mpr', '2' => 'or', '3' => 'sm', '100' => 'login', '911' => 'help');25$sms_list_keywords = array('1' => 'mpr', '2' => 'or', '3' => 'sm', '100' => 'login', '911' => 'help');
3126
32?>27?>
33\ No newline at end of file28\ No newline at end of file
29<?php
30/**
31 *
32 * This file is a list of valid keywords that the Sahana server will accept through SMS
33 * Developers are required to use this file to list keywords and prepare user manuals for it.
34 * Any changes or additions to the keywords should go in this file.
35 *
36 *
37 * PHP version 4 and 5
38 *
39 * LICENSE: This source file is subject to LGPL license
40 * that is available through the world-wide-web at the following URI:
41 * http://www.gnu.org/copyleft/lesser.html
42 *
43 * @package framework
44 * @subpackage messaging
45 * @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>
46 * @copyright Lanka Software Foundation - http://www.opensource.lk
47 * @version $Id: lib_sms_keywords.inc,v 1.2 2008/09/15 13:50:13 franboon Exp $
48 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
49 *
50 */
51//This needs to be done in a more efficient way. By using the 3 letter module codes from the DB?
52
53
54global $sms_list_keywords;
55$sms_list_keywords = array('1' => 'mpr', '2' => 'or', '3' => 'sm', '100' => 'login', '911' => 'help');
56?>
34\ No newline at end of file57\ No newline at end of file
3558
=== modified file 'mod/msg/lib_sms_main.inc'
--- mod/msg/lib_sms_main.inc 2009-11-10 23:51:44 +0000
+++ mod/msg/lib_sms_main.inc 2009-11-18 18:15:32 +0000
@@ -1,3 +1,63 @@
1<?php
2/**1/**
3*2*
4* Library functions for implementation independant messaging for SMS3* Library functions for implementation independant messaging for SMS
5* Main messaging controller functions with modular plugin architecture irrespective of the SMS Gateway application4* Main messaging controller functions with modular plugin architecture irrespective of the SMS Gateway application
6*5*
7*6*
8* PHP version 4 and 57* PHP version 4 and 5
9*8*
10* LICENSE: This source file is subject to LGPL license9* LICENSE: This source file is subject to LGPL license
11* that is available through the world-wide-web at the following URI:10* that is available through the world-wide-web at the following URI:
12* http://www.gnu.org/copyleft/lesser.html11* http://www.gnu.org/copyleft/lesser.html
13*12*
14* @package framework13* @package framework
15* @subpackage messaging14* @subpackage messaging
16* @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>15* @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>
17* @copyright Lanka Software Foundation - http://www.opensource.lk16* @copyright Lanka Software Foundation - http://www.opensource.lk
18* @version $Id: lib_sms_main.inc,v 1.2 2008/09/15 13:50:20 franboon Exp $17* @version $Id: lib_sms_main.inc,v 1.2 2008/09/15 13:50:20 franboon Exp $
19* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)18* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
20*19*
21*/20*/
2221
23global $global;22global $global;
2423
25require_once $global['approot']."/mod/msg/lib_sms_keywords.inc";24require_once $global['approot']."/mod/msg/lib_sms_keywords.inc";
26require_once $global['approot']."/mod/msg/lib_sms_errors.inc";25require_once $global['approot']."/mod/msg/lib_sms_errors.inc";
27require_once $global['approot']."/mod/msg/lib_sms_handler.inc";26require_once $global['approot']."/mod/msg/lib_sms_handler.inc";
2827
29global $sender_phone_number;
30global $sms_sent_timestamp;28global $sms_sent_timestamp;
31global $sms_message;29global $sms_message;
3230
33function shn_msg_push_to_sms_handler($received_message){
3431
35 global $global;32 global $global;
36 $sender_phone_number = $received_message['sender'];33 $sender_phone_number = $received_message['sender'];
37 $sms_sent_timestamp = $received_message['received'];34 $sms_sent_timestamp = $received_message['received'];
38 $sms_message = $received_message['message'];35 $sms_message = $received_message['message'];
39 //echo "<br \>SMS Sent to main SMS Handler. <br \>From: ".$sender_phone_number;36 //echo "<br \>SMS Sent to main SMS Handler. <br \>From: ".$sender_phone_number;
40 //shn_msg_sms_authenticate($received_message); add authentication function here37 //shn_msg_sms_authenticate($received_message); add authentication function here
41 // if authenticated check keyword38 // if authenticated check keyword
42 $parsed_sms = _shn_msg_parse_short_message($sms_message);39 $parsed_sms = _shn_msg_parse_short_message($sms_message);
43 //echo "<br \> SMS Text = ".$sms_message;40 //echo "<br \> SMS Text = ".$sms_message;
44 //echo "<br \> Keyword Text = ".$parsed_sms[0];41 //echo "<br \> Keyword Text = ".$parsed_sms[0];
45 //check for valid keyword42 //check for valid keyword
46 $keyword_check_result = _shn_msg_sms_keyword_check($parsed_sms[0], $sender_phone_number);43 $keyword_check_result = _shn_msg_sms_keyword_check($parsed_sms[0], $sender_phone_number);
47 if($keyword_check_result!=0){44 if($keyword_check_result!=0){
48 if($keyword_check_result['type'] == 'number'){45 if($keyword_check_result['type'] == 'number'){
49 //execute_number_menu_function($parsed_sms);46 //execute_number_menu_function($parsed_sms);
50 //echo "<br \>Key word is Valid and number";47 //echo "<br \>Key word is Valid and number";
51 _shn_msg_sms_action($parsed_sms, $sender_phone_number);48 _shn_msg_sms_action($parsed_sms, $sender_phone_number);
52 }49 }
53 elseif($keyword_check_result['type'] == 'word'){50 elseif($keyword_check_result['type'] == 'word'){
54 //execute_word_menu_function($parsed_sms);51 //execute_word_menu_function($parsed_sms);
55 //echo "<br \>Key word is Valid and WORD <br \>";52 //echo "<br \>Key word is Valid and WORD <br \>";
56 _shn_msg_sms_action($parsed_sms, $sender_phone_number);53 _shn_msg_sms_action($parsed_sms, $sender_phone_number);
57 }54 }
58 else{55 else{
59 //error already sent echo " Keywords is in invalid format";//impossible tho56 //error already sent echo " Keywords is in invalid format";//impossible tho
60 exit;57 exit;
61 }58 }
62 }59 }
63 else{60 else{
64 //error already sent echo " Keyword does not exists in LIST";61 //error already sent echo " Keyword does not exists in LIST";
65 exit;62 exit;
66 }63 }
67}64}
68?>65?>
69\ No newline at end of file66\ No newline at end of file
67<?php
68/**
69 *
70* Library functions for implementation independant messaging for SMS
71* Main messaging controller functions with modular plugin architecture irrespective of the SMS Gateway application
72 *
73 *
74 * PHP version 4 and 5
75 *
76 * LICENSE: This source file is subject to LGPL license
77 * that is available through the world-wide-web at the following URI:
78 * http://www.gnu.org/copyleft/lesser.html
79 *
80 * @package framework
81 * @subpackage messaging
82 * @author Ajay Kumar <ajuonline at gmail dot com><aj at mindtakers dot com>
83 * @copyright Lanka Software Foundation - http://www.opensource.lk
84 * @version $Id: lib_sms_main.inc,v 1.2 2008/09/15 13:50:20 franboon Exp $
85 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
86 *
87 */
88global $global;
89require_once $global['approot']."/mod/msg/lib_sms_keywords.inc";
90require_once $global['approot']."/mod/msg/lib_sms_errors.inc";
91require_once $global['approot']."/mod/msg/lib_sms_handler.inc";
92global $sender_phone_number;
93global $sms_sent_timestamp;
94global $sms_message;
95function shn_msg_push_to_sms_handler($received_message){
96 global $global;
97 $sender_phone_number = $received_message['sender'];
98 $sms_sent_timestamp = $received_message['received'];
99 $sms_message = $received_message['message'];
100 //echo "<br \>SMS Sent to main SMS Handler. <br \>From: ".$sender_phone_number;
101 //shn_msg_sms_authenticate($received_message); add authentication function here
102 // if authenticated check keyword
103 $parsed_sms = _shn_msg_parse_short_message($sms_message);
104 //echo "<br \> SMS Text = ".$sms_message;
105 //echo "<br \> Keyword Text = ".$parsed_sms[0];
106 //check for valid keyword
107 $keyword_check_result = _shn_msg_sms_keyword_check($parsed_sms[0], $sender_phone_number);
108 if($keyword_check_result!=0){
109 if($keyword_check_result['type'] == 'number'){
110 //execute_number_menu_function($parsed_sms);
111 //echo "<br \>Key word is Valid and number";
112 _shn_msg_sms_action($parsed_sms, $sender_phone_number);
113 }
114 elseif($keyword_check_result['type'] == 'word'){
115 //execute_word_menu_function($parsed_sms);
116 //echo "<br \>Key word is Valid and WORD <br \>";
117 _shn_msg_sms_action($parsed_sms, $sender_phone_number);
118 }
119 else{
120 //error already sent echo " Keywords is in invalid format";//impossible tho
121 exit;
122 }
123 }
124 else{
125 //error already sent echo " Keyword does not exists in LIST";
126 exit;
127 }
128}
129?>
70\ No newline at end of file130\ No newline at end of file
71131
=== modified file 'mod/msg/plugins/smstools/handler_smstools.inc' (properties changed: -x to +x)
--- mod/msg/plugins/smstools/handler_smstools.inc 2009-11-10 23:51:44 +0000
+++ mod/msg/plugins/smstools/handler_smstools.inc 2009-11-18 18:15:32 +0000
@@ -29,6 +29,8 @@
29 global $global;29 global $global;
30 global $conf;30 global $conf;
31 include_once($global['approot'].'/mod/msg/plugins/smstools/conf.inc');31 include_once($global['approot'].'/mod/msg/plugins/smstools/conf.inc');
32
33 echo "Response Message:".$message;
32 34
33 foreach($recipients as $to){35 foreach($recipients as $to){
34 //Let system handle tmp directory: change to absolute dir if needed36 //Let system handle tmp directory: change to absolute dir if needed
3537
=== modified file 'mod/msg/plugins/smstools/smsfwd/smsevent' (properties changed: -x to +x)
--- mod/msg/plugins/smstools/smsfwd/smsevent 2009-11-10 23:51:44 +0000
+++ mod/msg/plugins/smstools/smsfwd/smsevent 2009-11-18 18:15:32 +0000
@@ -137,8 +137,8 @@
137echo $RECEIVED;137echo $RECEIVED;
138138
139if [ "$1" == "RECEIVED" ];139if [ "$1" == "RECEIVED" ];
140then curl "http://localhost/sahana-phase2/www/index.php?mod=msg&act=receive_message&stream=text&plugin=smstools&From=$FROM&Received=$RECEIVED&message=$URLTEXT";140then curl "http://localhost/sahana/www/index.php?mod=msg&act=receive_message&stream=text&plugin=smstools&From=$FROM&Received=$RECEIVED&message=$URLTEXT";
141141
142echo $'\n\nSMS posting successful from '$FROM' message: '$TEXT $'\n\n';142echo $'\n\nSMS posting successful from '$FROM' message: '$TEXT $'\n\n';
143fi143fi
144fi
145\ No newline at end of file144\ No newline at end of file
145fi
146146
=== modified file 'mod/sm/main_fns.inc' (properties changed: -x to +x)
--- mod/sm/main_fns.inc 2009-11-10 23:51:44 +0000
+++ mod/sm/main_fns.inc 2009-11-18 18:15:32 +0000
@@ -59,4 +59,87 @@
59 shn_sm_radius_analyse_process();59 shn_sm_radius_analyse_process();
60}60}
6161
62?>62function shn_text_sm_kml() {
63
64 global $global;
65 $db = $global['db'];
66 // write the KML content header
67 header("Content-type: application/vnd.google-earth.kml+xml;");
68
69 $layer=$_REQUEST['layer'];
70
71 $query="
72 select coord_y, coord_x,m.name,url,m.description,icon,placement_date
73 from gis_features f
74 left join gis_feature_class c on
75 (c.feature_class_uuid=f.feature_class_uuid_ref)
76 left join gis_feature_class_to_layer cl on
77 (c.feature_class_uuid=cl.feature_class_uuid_ref)
78 left join gis_layers l on
79 (cl.layer_uuid_ref=l.layer_uuid)
80 left join gis_feature_metadata m on
81 (f.metadata_uuid_ref=m.metadata_uuid)
82 ";
83 //--where layer_uuid='$layer'
84 $r = $db->Execute($query);
85# if (!$rs) {
86# $message = 'Invalid query: ' . $query . "\n";
87# $message .= 'Whole query: ' . $query;
88# die($message);
89# }
90//echo "lat lon title description icon iconSize iconOffset\n";
91echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
92?>
93<kml xmlns="http://www.opengis.net/kml/2.2">
94<Document>
95<flyToView>0</flyToView>
96<?
97while (!$r->EOF){
98
99 $y=$r->fields['coord_y'];
100 $x=$r->fields['coord_x'];
101 $title=$r->fields['name'];
102 $url = $r->fields['url'];
103 $desc = $r->fields['description'];
104 $icon = $r->fields['icon'];
105 if (strlen($url)>1){
106 if (preg_match('/^http:/',$url)){
107 $url="<br/><a href='".$url."'>Link</a>";
108 } else $url="<br/><a href='/".$url."'>Link</a>";
109 } else $url=$url;
110 $date=date("c",strtotime($r->fields['placement_date']));
111?>
112<Placemark>
113 <name><?=$title?></name>
114 <description><![CDATA[
115 <?=$desc?><?=$url?>]]></description>
116 <Point>
117 <coordinates><?=$x.','.$y?>,0</coordinates>
118 </Point><?if (strlen($icon)>1){?>
119 <Style>
120 <IconStyle>
121 <Icon>
122 <href><?=$icon?></href>
123 </Icon>
124 </IconStyle>
125 </Style><?
126} ?><TimeStamp>
127 <when><?=$date?></when>
128</TimeStamp>
129 </Placemark>
130<?
131//echo join("\t",$r);
132//echo "\n";
133 $r->MoveNext();
134
135 }
136
137?>
138</Document>
139</kml>
140
141<?php
142}
143?>
144
145

Subscribers

People subscribed via source and target branches

to all changes: