PageRenderTime 26ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/sahana/mod/gis/admin.inc

#
PHP | 304 lines | 225 code | 25 blank | 54 comment | 18 complexity | c3b61aa13f449fee92a7029bd561a6aa MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /* $Id: admin.inc,v 1.18.6.3 2008-06-04 14:12:15 franboon Exp $ */
  3. /**Admin Module for GIS
  4. *
  5. * PHP version 4 and 5
  6. *
  7. * LICENSE: This source file is subject to LGPL license
  8. * that is available through the world-wide-web at the following URI:
  9. * http://www.gnu.org/copyleft/lesser.html
  10. *
  11. * Sahana - http://sahana.sourceforge.net
  12. * @author Mifan Careem <mifan@opensource.lk>
  13. * @copyright Lanka Software Foundation - http://www.opensource.lk
  14. * @package admin
  15. * @subpackage gis
  16. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
  17. */
  18. include_once($global['approot'].'/inc/lib_form.inc');
  19. include_once($global['approot'].'/inc/lib_errors.inc');
  20. function shn_gis_adm_default()
  21. {
  22. global $conf;
  23. if(isset($_REQUEST['submod']) && isset($_REQUEST['seq'])){
  24. global $global;
  25. include_once ($global['approot'].'/mod/gis/plugins/'.$_REQUEST['submod'].'/admin.inc');
  26. switch($_REQUEST['seq']){
  27. case 'commit':
  28. shn_plugin_commit();
  29. break;
  30. }
  31. shn_gis_adm_show_mod_menu();
  32. echo "<h2>"._("GIS / Mapping Admin Page")."</h2>";
  33. //shn_gis_adm_showform();
  34. shn_gis_adm_show_mods();
  35. shn_gis_adm_find_mods();
  36. }
  37. else if(isset($_REQUEST['submod']))
  38. {
  39. global $global;
  40. shn_gis_adm_show_mod_menu();
  41. include_once ($global['approot'].'/mod/gis/plugins/'.$_REQUEST['submod'].'/admin.inc');
  42. shn_plugin_default();
  43. }
  44. else
  45. {
  46. shn_gis_adm_show_mod_menu();
  47. echo "<h2>"._lc($conf['mod_gis_name'])." "._("Admin Page")."</h2>";
  48. //shn_gis_adm_showform();
  49. shn_gis_adm_show_mods();
  50. shn_gis_adm_find_mods();
  51. }
  52. }
  53. /**
  54. * Find and show GIS plugin configuration links
  55. * Auto-detects plugins
  56. * @access public
  57. * @return void
  58. */
  59. function shn_gis_adm_find_mods()
  60. {
  61. ?>
  62. <?php
  63. global $global;
  64. global $conf;
  65. include_once($global['approot'].'/inc/lib_modules.inc');
  66. include_once($global['approot'].'/inc/lib_form.inc');
  67. $count=1;
  68. $gis_plugins_dir=$global['approot'].'/mod/gis/plugins/';
  69. $dir = opendir($gis_plugins_dir);
  70. shn_form_fopen(adm_gis_conf,null,array('req_message'=>false));
  71. shn_form_fsopen(_("GIS Plugin Configuration"));
  72. while($file = readdir($dir)){
  73. if(!is_dir($file)){
  74. //shows nice name of plugin
  75. include($global['approot'].'/mod/gis/plugins/'."$file".'/conf.inc');
  76. $name = $conf['plugin_name'];
  77. echo "$count. <a href='index.php?mod=gis&act=admin&submod=$file'>"."$name"."</a><br>";
  78. //echo "$count. <a href='index.php?mod=gis/plugins/"."$file"."&act=dd'>"."$name"."</a><br>";
  79. $count++;
  80. }
  81. }
  82. shn_form_fsclose();
  83. shn_form_fclose();
  84. }
  85. /**
  86. * Find and show GIS plugin configuration links at top
  87. * Auto-detects plugins
  88. * @access public
  89. * @return void
  90. */
  91. function shn_gis_adm_show_mod_menu()
  92. {
  93. ?>
  94. <?php
  95. global $global;
  96. global $conf;
  97. include_once($global['approot'].'/inc/lib_modules.inc');
  98. include_once($global['approot'].'/inc/lib_form.inc');
  99. $count=1;
  100. $gis_plugins_dir=$global['approot'].'/mod/gis/plugins/';
  101. $dir = opendir($gis_plugins_dir);
  102. ?>
  103. <div id="submenu_v">
  104. <a href="index.php?mod=gis&act=admin"><?=_("General Mapping")?></a>
  105. <?php
  106. while($file = readdir($dir)){
  107. if(!is_dir($file)){
  108. //shows nice name of plugin
  109. include($global['approot'].'/mod/gis/plugins/'."$file".'/conf.inc');
  110. $name = $conf['plugin_name'];
  111. ?>
  112. <a href="index.php?mod=gis&act=admin&submod=<?=$file?>"><?=_($name)?></a>
  113. <?php
  114. $count++;
  115. }
  116. }
  117. ?>
  118. </div><!--/div id=submenu_v-->
  119. <?php
  120. }
  121. /**
  122. * Show radio button selection of available GIS plugins
  123. * Enter Selected values
  124. * @access private
  125. * @return void
  126. */
  127. function shn_gis_adm_show_mods()
  128. {
  129. global $global;
  130. global $conf;
  131. $db=$global['db'];
  132. include_once($global['approot'].'/inc/lib_modules.inc');
  133. include_once($global['approot'].'/inc/lib_form.inc');
  134. ?>
  135. <br /><h3><?php echo _("Main Configuration");?></h3>
  136. <ul>
  137. <li><?php echo _("GIS Maps in Sahana can be set to display a default region");?> </li>
  138. <li><?php echo _("In order to set the map display for a particular region, you should know the Longitude and the Latitude of that region");?></li>
  139. <li><?php echo _("If these values are known, you can set them below:");?> </li>
  140. </ul>
  141. <?php
  142. shn_form_fopen(adm_commit,null,array('req_message'=>false));
  143. shn_form_fsopen(_("Default Center Coordinates"));
  144. $lat_help=_("Latitude is North-South (Up-Down). Latitude is zero on the equator and positive in the northern hemisphere and negative in the southern hemisphere");
  145. $lon_help=_("Longitude is West - East (sideways). Longitude is zero on the prime meridian (Greenwich Mean Time) and is positive to the east, across Europe and Asia. Longitude is negative to the west, across the Atlantic and the Americas.");
  146. shn_form_text(_("Center Longitude "),"x_center",null,array("value"=>$conf['mod_gis_center_x'],"help"=>$lat_help));
  147. shn_form_text(_("Center Latitude"),"y_center",null,array("value"=>$conf['mod_gis_center_y'],"help"=>$lon_help));
  148. shn_form_fsclose();
  149. ?>
  150. <ul>
  151. <li><?php echo _("Sahana supports a modular GIS plugin architecture ");?> </li>
  152. <li><?php echo _("You can select which GIS plugin to use as your default GIS");?></li>
  153. <li><?php echo _("Select the default GIS plugin from the detected plugins below:");?> </li>
  154. <li><?php echo _("For more information on adding custom plugins, refer to the documentation within the mod/gis subdirectory");?> </li>
  155. </ul>
  156. <?php
  157. $query_mod="select value from config where module_id='gis' and confkey='dflt'";
  158. $result=$db->Execute($query_mod);
  159. if(!$res->EOF){
  160. $mod_name=$result->fields['value'];
  161. }
  162. $count=1;
  163. $gis_plugins_dir=$global['approot'].'/mod/gis/plugins/';
  164. $dir = opendir($gis_plugins_dir);
  165. while($file = readdir($dir)){
  166. if(!is_dir($file)){
  167. include($global['approot'].'/mod/gis/plugins/'."$file".'/conf.inc');
  168. $name = $conf['plugin_name'];
  169. $options_array[$file] = $name;
  170. //echo "$count. <a href='index.php?mod=gis/plugins/"."$file"."&act=adm'>$file</a><br>";
  171. //$count++;
  172. }
  173. }
  174. $extra_opts_form['req_message'] = 'false';
  175. shn_form_fsopen(_("Detected GIS module plugins"));
  176. //$extra_opts['br']='true';
  177. $mod_name = $conf['mod_gis_dflt'];
  178. shn_form_radio($options_array,_("Select GIS module"),"mod_gis",null,((isset($mod_name))?array("value"=>$mod_name):null));
  179. shn_form_fsclose();
  180. shn_form_submit(_("Done"));
  181. shn_form_fclose();
  182. }
  183. /**
  184. * Show form to set default Northing/Easting Values
  185. * @access private
  186. */
  187. function shn_gis_adm_showform(){
  188. global $conf;
  189. shn_form_fopen(null,null,array('req_message'=>false));
  190. ?>
  191. <ul>
  192. <li><?php echo _("GIS Maps in Sahana can be set to display a default region");?> </li>
  193. <li><?php echo _("In order to set the map display for a particular region, you should know the Longitude and the Latitude of that region");?></li>
  194. <li><?php echo _("If these values are known, you can set them below:");?> </li>
  195. </ul>
  196. <?php
  197. shn_form_fclose();
  198. shn_form_fopen(adm_commit,null,array('req_message'=>false));
  199. shn_form_fsopen(_("Default Center Coordinates"));
  200. $lat_help=_("Latitude is North-South (Up-Down). Latitude is zero on the equator and positive in the northern hemisphere and negative in the southern hemisphere");
  201. $lon_help=_("Longitude is West - East (sideways). Longitude is zero on the prime meridian (Greenwich Mean Time) and is positive to the east, across Europe and Asia. Longitude is negative to the west, across the Atlantic and the Americas.");
  202. shn_form_text(_("Center Longitude "),"x_center",null,array("value"=>$conf['mod_gis_center_x'],"help"=>$lat_help));
  203. shn_form_text(_("Center Latitude"),"y_center",null,array("value"=>$conf['mod_gis_center_y'],"help"=>$lon_help));
  204. shn_form_fsclose();
  205. shn_form_submit(_("Done"));
  206. shn_form_fclose();
  207. }
  208. /**
  209. * Enter default GIS plugin to database
  210. */
  211. function shn_gis_adm_mod()
  212. {
  213. global $global;
  214. $db = $global['db'];
  215. if(!null==$_POST['mod_gis']){
  216. $query = "select * from config where confkey='dflt' and module_id='gis'";
  217. $res = $db->Execute($query);
  218. if(!$res->EOF){
  219. $q = "UPDATE config SET value = '{$_POST['mod_gis']}' WHERE module_id = 'gis' AND confkey='mod_gis_dflt'";
  220. $db->Execute($q);
  221. }
  222. else{
  223. $insert = "insert into config(module_id,confkey,value) values ('gis','mod_gis_dflt','{$_POST['mod_gis']}')";
  224. $db->Execute($insert);
  225. }
  226. }
  227. add_confirmation(_("Changes were saved"));
  228. shn_gis_adm_default();
  229. }
  230. /**
  231. * Commit default Northing/Easting values
  232. * @access private
  233. */
  234. function shn_gis_adm_commit(){
  235. add_confirmation(_("Changes were saved"));
  236. global $global;
  237. $db = $global['db'];
  238. //$gm="UPDATE config SET value = '{$_POST['key']}' WHERE module_id = 'gis' AND confkey = 'google_key'";
  239. if(!null==$_POST['x_center'])
  240. {
  241. $query = "select * from config where confkey='mod_gis_center_x' and module_id='gis'";
  242. $res = $db->Execute($query);
  243. if(!$res->EOF){
  244. $q = "UPDATE config SET value = '{$_POST['x_center']}' WHERE module_id = 'gis' AND confkey = 'mod_gis_center_x'";
  245. $db->Execute($q);
  246. }
  247. else{
  248. $insert = "insert into config(module_id,confkey,value) values ('gis','mod_gis_center_x','{$_POST['x_center']}')";
  249. $db->Execute($insert);
  250. }
  251. }
  252. if(!null==$_POST['y_center'])
  253. {
  254. $query = "select * from config where confkey='mod_gis_center_y' and module_id='gis'";
  255. $res = $db->Execute($query);
  256. if(!$res->EOF){
  257. $r="UPDATE config SET value = '{$_POST['y_center']}' WHERE module_id = 'gis' AND confkey = 'mod_gis_center_y'";
  258. $db->Execute($r);
  259. }
  260. else{
  261. $insert = "insert into config(module_id,confkey,value) values ('gis','mod_gis_center_y','{$_POST['y_center']}')";
  262. $db->Execute($insert);
  263. }
  264. }
  265. if(!null==$_POST['mod_gis']){
  266. $query = "select * from config where confkey='mod_gis_dflt' and module_id='gis'";
  267. $res = $db->Execute($query);
  268. if(!$res->EOF){
  269. $q = "UPDATE config SET value = '{$_POST['mod_gis']}' WHERE module_id = 'gis' AND confkey='mod_gis_dflt'";
  270. $db->Execute($q);
  271. }
  272. else{
  273. $insert = "insert into config(module_id,confkey,value) values ('gis','mod_gis_dflt','{$_POST['mod_gis']}')";
  274. $db->Execute($insert);
  275. }
  276. }
  277. shn_gis_adm_default();
  278. }
  279. ?>