PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/sahana/mod/or/admin.inc

#
PHP | 164 lines | 121 code | 21 blank | 22 comment | 9 complexity | 91c762e9f952affb0e37cb655bbdc159 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**Admin controller of the Organization Registry
  3. *
  4. * PHP version 4 and 5
  5. *
  6. * LICENSE: This source file is subject to LGPL license
  7. * that is available through the world-wide-web at the following URI:
  8. * http://www.gnu.org/copyleft/lesser.html
  9. *
  10. * @author Ravindra De Silva <ravindra@opensource.lk><ravidesilva@iee.org>
  11. * @copyright Lanka Software Foundation - http://www.opensource.lk
  12. * @package sahana
  13. * @subpackage or
  14. */
  15. include_once($global['approot'].'/inc/lib_form.inc');
  16. include_once "admin_forms.inc";
  17. function _shn_or_adm_sub_menu()
  18. {
  19. ?>
  20. <div id="submenu_v">
  21. <a href="index.php?mod=or&act=adm_or_type"><?php echo _("Organization Types")?></a>
  22. <a href="index.php?mod=or&act=adm_sector"><?php echo _("Organization Sectors")?></a>
  23. <!--<a href="index.php?mod=or&act=adm_location_range">Set Location Range</a>
  24. <a href="index.php?mod=or&act=adm_location">Set starting Location</a> -->
  25. </div>
  26. <br>
  27. <?php
  28. }
  29. function shn_or_adm_default()
  30. {
  31. _shn_or_adm_sub_menu();
  32. ?>
  33. <h2> <?php echo _("Organisation Registry Configuration.")?> </h2><br/>
  34. <p><?php echo _("Use the following links or the above tabs to chage organization types and sectors.") ?></p>
  35. <ul>
  36. <li><b><a href="index.php?mod=or&act=adm_or_type"><?php echo _("Organization Types") ?></a></b><br/> - <?php echo _("Change the types of organizations, (add new, edit or delete)") ?></li><br/>
  37. <li><b><a href="index.php?mod=or&act=adm_sector"><?php echo _("Organization Sectors") ?></a></b><br/> - <?php echo _("Change the organization sectors, (add new, edit or delete)")?></li><br/>
  38. </ul>
  39. <?php
  40. }
  41. function shn_or_adm_or_type()
  42. {
  43. _shn_or_adm_sub_menu();
  44. shn_or_adm_or_type_form();
  45. }
  46. function shn_or_adm_type_cr()
  47. {
  48. global $global;
  49. include_once $global['approot'].'inc/lib_misc.inc';
  50. $db=$global['db'];
  51. $add = explode(",", $_POST{"added"});
  52. $remove = explode(",", $_POST{"removed"});
  53. for($i=1;$i<count($add)-1;$i++){
  54. $key=shn_create_unique_database_field_value($add[$i],2,"field_options","option_code");
  55. $q="INSERT INTO field_options(field_name,option_code,option_description) VALUES('opt_org_type','$key','$add[$i]')";
  56. $res=$db->Execute($q);
  57. }
  58. for($i=1;$i<count($remove);$i++){
  59. $q="DELETE FROM field_options WHERE field_name='opt_org_type' AND option_code='".$remove[$i]."'";
  60. $res=$db->Execute($q);
  61. }
  62. $msg= "Organization types were succesfully added/removed ";
  63. add_confirmation($msg);
  64. shn_or_adm_or_type();
  65. }
  66. function shn_or_adm_sector()
  67. {
  68. _shn_or_adm_sub_menu();
  69. shn_or_adm_or_sector_form();
  70. }
  71. function shn_or_adm_sector_cr(){
  72. global $global;
  73. include_once $global['approot'].'inc/lib_misc.inc';
  74. $db=$global['db'];
  75. $add = explode(",", $_POST{"added"});
  76. $remove = explode(",", $_POST{"removed"});
  77. for($i=1;$i<count($add)-1;$i++){
  78. $key=shn_create_unique_database_field_value($add[$i],2,"field_options","option_code");
  79. $q="INSERT INTO field_options(field_name,option_code,option_description) VALUES('opt_sector_type','$key','$add[$i]')";
  80. $res=$db->Execute($q);
  81. }
  82. for($i=1;$i<count($remove);$i++){
  83. $q="DELETE FROM field_options WHERE field_name='opt_sector_type' AND option_code='".$remove[$i]."'";
  84. $res=$db->Execute($q);
  85. }
  86. $msg= _("Organization services were succesfully added/removed ");
  87. add_confirmation($msg);
  88. shn_or_adm_sector();
  89. }
  90. function shn_or_adm_acl_install()
  91. {
  92. global $global;
  93. $db=$global["db"];
  94. $q="SELECT value FROM config WHERE module_id='or' AND confkey='acl_base'";
  95. $res_acl=$db->Execute($q);
  96. if(!$res_acl->EOF && $res_acl->fields[0]=='installed'){
  97. $msg="ACL Base for Organization Registry is already installed";
  98. }
  99. include_once $global['approot']. 'inc/lib_security/acl_api.inc';
  100. include_once $global['approot'].'inc/lib_security/acl.inc';
  101. // include_once $global['approot'].'inc/lib_security/authenticate.inc';
  102. $acl=new SahanaACL(NULL);
  103. /** start of or specifc ACL entries
  104. **/
  105. // add a module named "or"
  106. $res=shn_acl_add_module("or","organization reg");
  107. /** action groups **/
  108. // add an action group named "deny_admin" under the module "or"
  109. $res=shn_acl_add_action_group("or","deny_admin","deny admin group");
  110. $res=shn_acl_add_action("or","deny_admin","shn_or_acl_setup","Display ACL configuration info");
  111. $res=shn_acl_add_action("or","deny_admin","shn_or_adm_default","Display Admin page");
  112. $res=shn_acl_add_action("or","deny_admin","shn_or_adm_or_type","Display Admin Or type page");
  113. $res=shn_acl_add_action("or","deny_admin","shn_or_adm_sector","Display Admin Or sector page");
  114. $res=shn_acl_add_action("or","deny_admin","shn_or_adm_location_range","Display Admin Or location range page");
  115. $res=shn_acl_add_action("or","deny_admin","shn_or_adm_location","Display Admin Or location page");
  116. //deny permission for 'deny_admin' action group with in 'or' to 'guest' role
  117. $res=shn_acl_add_perms_action_group_role('guest','or','deny_admin');
  118. $res=shn_acl_add_perms_action_group_role('user','or','deny_admin');
  119. // add an action group named "deny_user" under the module "or"
  120. $res=shn_acl_add_action_group("or","deny_user","deny user group");
  121. //add an action name 'shn_or_reg_org" under above action groups
  122. $res=shn_acl_add_action("or","deny_user","shn_or_reg_org","Display Organization Registration form");
  123. $res=shn_acl_add_action("or","deny_user","shn_or_reg_org_cr","Save Organization Registration info");
  124. $res=shn_acl_add_action("or","deny_user","shn_or_reg_operation","Save Operation Registration form");
  125. $res=shn_acl_add_action("or","deny_user","shn_or_reg_operation_cr","Save Operation Registration form");
  126. $res=shn_acl_add_action("or","deny_user","_shn_or_edit_org","edit Org Registration form");
  127. $res=shn_acl_add_action("or","deny_user","_shn_or_del_org","delete Org Registration form");
  128. $res=shn_acl_add_perms_action_group_role('guest','or','deny_user');
  129. if($res_acl->EOF) {
  130. $q="INSERT INTO config VALUES('or','acl_base','installed')";
  131. }else {
  132. $q="UPDATE config set value='installed' WHERE module_id='or' AND confkey='acl_base'";
  133. }
  134. $res=$db->Execute($q);
  135. $msg=_("ACL Base for Organization Registry was succesfully installed");
  136. ?>
  137. <div id="result_msg">
  138. <?php echo $msg;?>
  139. </div>
  140. </br>
  141. <?php
  142. }
  143. ?>