PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/gacl/admin/test.php

https://github.com/md-tech/openemr
PHP | 422 lines | 4 code | 26 blank | 392 comment | 0 complexity | e32686c2116a229753ecfeace1bfeb21 MD5 | raw file
  1. <?php
  2. $debug=1;
  3. require_once("gacl_admin.inc.php");
  4. /*
  5. $test = $gacl->add_group_object(10, 'user','10');
  6. $gacl->showarray($test);
  7. $test = $gacl->add_group_object(10, 'user','10');
  8. $gacl->showarray($test);
  9. $test = $gacl->del_group_object(10, 'user','10');
  10. $gacl->showarray($test);
  11. $test = $gacl->del_group_object(10, 'user','10');
  12. $gacl->showarray($test);
  13. */
  14. //$test = $gacl->acl_query('system','login','users','john_doe',NULL, NULL, NULL, NULL, TRUE);
  15. //showarray($test);
  16. /*
  17. $test = $gacl_api->get_group_objects(14,'ARO','RECURSE');
  18. showarray($test);
  19. $test = $gacl_api->get_group_objects(14,'ARO');
  20. showarray($test);
  21. */
  22. /*
  23. $group_ids = array(14);
  24. $test = $gacl_api->acl_get_group_path($group_ids);
  25. showarray($test);
  26. $test = $gacl_api->get_group_objects(14,'ARO');
  27. showarray($test);
  28. */
  29. //$gacl_api->clean_path_to_root(ARO);
  30. //$gacl_api->clean_path_to_root(AXO);
  31. /*
  32. $gacl_api->add_acl( array('system' => array('login', 'enabled', 'login')),
  33. array('users' => array(1)),
  34. array(10,12,10),
  35. NULL,
  36. NULL,
  37. TRUE,
  38. TRUE,
  39. 666,
  40. 'NOTE');
  41. */
  42. /*
  43. $gacl_api->is_conflicting_acl(
  44. array('system' => array('login')),
  45. array('accounts' => array(1)),
  46. array(99),
  47. array('projects' => array(99)),
  48. array(99));
  49. */
  50. //$gacl_api->consolidated_edit_acl('system', 'add_pop','accounts',1, 99);
  51. //$gacl_api->search_acl('system','add_pop','accounts',1, 'Browsers','projects',5599,'Projects',99);
  52. /*
  53. $gacl_api->shift_acl( 18,
  54. array('accounts' => array(1)),
  55. array(14),
  56. array('projects' => array(5599)),
  57. array(23),
  58. array('system' => array('add_pop'))
  59. );
  60. */
  61. /*
  62. $gacl_api->append_acl( 18,
  63. array('accounts' => array(1,2,3,4)),
  64. array(14),
  65. array('projects' => array(5599)),
  66. array(23),
  67. array('system' => array('add_pop'))
  68. );
  69. */
  70. /*
  71. $gacl_api->add_acl( array('system' => array(99)),
  72. array('accounts' => array(99)),
  73. array(99),
  74. array('projects' => array(99)),
  75. array(99),
  76. TRUE,
  77. TRUE,
  78. 666,
  79. 'NOTE');
  80. */
  81. //$rows = $rs->GetRows();
  82. //showarray($rows);
  83. /*
  84. $query = '
  85. SELECT a.value AS a_value, a.name AS a_name,
  86. b.value AS b_value, b.name AS b_name,
  87. c.value AS c_value, c.name AS c_name,
  88. d.value AS d_value, d.name AS d_name
  89. FROM aco_sections a,
  90. aco b,
  91. aro_sections c,
  92. aro d
  93. WHERE a.value=b.section_value
  94. AND c.value=d.section_value
  95. ORDER BY a.value, b.value, c.value, d.value';
  96. //$rs = $db->Execute($query);
  97. //$rows = $rs->GetRows();
  98. $rs = $db->pageexecute($query, 100, 2);
  99. showarray($rows);
  100. $rows = $rs->GetRows();
  101. showarray($rows);
  102. */
  103. //$test=$gacl-> acl_query('system', 'email_pw', 'users', '1');
  104. //showarray($test);
  105. //Test object deleting.
  106. //$gacl_api->del_object(10,'ARO', TRUE);
  107. //$gacl_api->del_object_section(10,'ACO',TRUE);
  108. /*
  109. //Test AXO's
  110. //function acl_query($aco_section_value, $aco_value, $aro_section_value, $aro_value, $axo_section_value=NULL, $axo_value=NULL, $root_aro_group_id=NULL, $root_axo_group_id=NULL) {
  111. $test1= acl_query('system','login','users', '1');
  112. showarray($test1);
  113. $test2=acl_query('system','login','users', '1','projects','1');
  114. showarray($test2);
  115. */
  116. //Test subtree'ing
  117. /*
  118. $test=acl_get_groups('test_section2','user1',0);
  119. showarray($test);
  120. $test=acl_get_groups('test_section2','user1');
  121. showarray($test);
  122. */
  123. /*
  124. //require_once('../Cache_Lite.php');
  125. require_once('./profiler.inc');
  126. $profiler = new Profiler(true,true);
  127. $options = array(
  128. 'caching' => true,
  129. 'cacheDir' => '/tmp/phpgacl_cache',
  130. 'lifeTime' => 100
  131. );
  132. //$Cache_Lite = new Hashed_Cache_Lite($options);
  133. $Cache_Lite = new Cache_Lite($options);
  134. $data = '0123456789';
  135. $Cache_Lite->save($data,'123');
  136. $profiler->startTimer( "acl_query()");
  137. //Test memory caching.
  138. for ($i=0; $i < 2; $i++) {
  139. //$Cache_Lite->save($data,'123'.$i);
  140. $data = $Cache_Lite->get('123');
  141. //echo "$data<br>\n";
  142. }
  143. $profiler->stopTimer( "acl_query()");
  144. $profiler->printTimers();
  145. */
  146. /*
  147. //Test multi-layer ACOs
  148. $test = acl_query(array(21,19), 10);
  149. showarray($test);
  150. */
  151. //Stress test.
  152. /*
  153. //Cleanup
  154. $aco_section_id = $gacl_api->get_aco_section_section_id("Stress Test");
  155. $del_aco_ids = $gacl_api->get_aco($aco_section_id);
  156. foreach ($del_aco_ids as $del_aco_id) {
  157. $gacl_api->del_aco($del_aco_id);
  158. }
  159. $gacl_api->del_aco_section($aco_section_id);
  160. $aro_section_id = $gacl_api->get_aro_section_section_id("Stress Test");
  161. $del_aro_ids = $gacl_api->get_aro($aro_section_id);
  162. foreach ($del_aro_ids as $del_aro_id) {
  163. $gacl_api->del_aro($del_aro_id);
  164. }
  165. $gacl_api->del_aro_section($aro_section_id);
  166. //Get all ACLs
  167. $query = "select id from acl";
  168. $rs = $db->GetCol($query);
  169. foreach($rs as $del_acl_id) {
  170. $gacl_api->del_acl($del_acl_id);
  171. }
  172. */
  173. /*
  174. $max_aco=10;
  175. $max_aro=50;
  176. $max_acl=100;
  177. $min_rand_aco=1;
  178. $max_rand_aco=9;
  179. $min_rand_aro=1;
  180. $max_rand_aro=9;
  181. //Seed random.
  182. srand ((float) microtime() * 10000000);
  183. //Grab ACO Section_id
  184. $aco_section_id = $gacl_api->get_aco_section_section_id("Stress Test");
  185. if (!$aco_section_id) {
  186. //Add an ACO section.
  187. $aco_section_id = $gacl_api->add_aco_section("Stress Test", 999,999);
  188. $gacl_api->debug_text("Stress Test: ACO Section ID: $aco_section_id");
  189. }
  190. //Add 100 random ACO's
  191. if ($aco_section_id) {
  192. for ($i=0; $i < $max_aco; $i++) {
  193. $aco_id = $gacl_api->get_aco_id("Stress Test ACO #$i");
  194. if (!$aco_id) {
  195. //Add ACO.
  196. $aco_id = $gacl_api->add_aco($aco_section_id, "Stress Test ACO #$i",$i, $i);
  197. }
  198. }
  199. }
  200. $aco_ids = $gacl_api->get_aco($aco_section_id);
  201. //showarray($aco_ids);
  202. //Grab ARO section id
  203. $aro_section_id = $gacl_api->get_aro_section_section_id("Stress Test");
  204. if (!$aro_section_id) {
  205. //Add an ACO section.
  206. $aro_section_id = $gacl_api->add_aro_section("Stress Test", 999,999);
  207. $gacl_api->debug_text("Stress Test: ARO Section ID: $aro_section_id");
  208. }
  209. //Add 10,000 random ARO's
  210. if ($aro_section_id) {
  211. for ($i=0; $i < $max_aro; $i++) {
  212. $aro_id = $gacl_api->get_aro_id("Stress Test ARO #$i");
  213. if (!$aro_id) {
  214. //Add ARO.
  215. $aro_id = $gacl_api->add_aro($aro_section_id, "Stress Test ARO #$i",$i, $i);
  216. }
  217. }
  218. }
  219. $aro_ids = $gacl_api->get_aro($aro_section_id);
  220. //showarray($aro_ids);
  221. //Create random ACL's using the above stress test ACO/AROs
  222. if (count($aco_ids) > 1 AND count($aro_ids) > 1) {
  223. for ($i=0; $i < $max_acl; $i++) {
  224. //Get random ACO IDS
  225. $rand_aco_keys = array_rand($aco_ids, mt_rand($min_rand_aco, $max_rand_aco) );
  226. unset($rand_aco_ids);
  227. foreach ($rand_aco_keys as $rand_aco_key) {
  228. $rand_aco_ids[] = $aco_ids[$rand_aco_key];
  229. }
  230. //Get random ARO IDS
  231. $rand_aro_keys = array_rand($aro_ids, mt_rand($min_rand_aro, $max_rand_aro));
  232. unset($rand_aro_ids);
  233. foreach ($rand_aro_keys as $rand_aro_key) {
  234. $rand_aro_ids[] = $aro_ids[$rand_aro_key];
  235. }
  236. //Random ALLOW
  237. $allow = mt_rand(0,1);
  238. $gacl_api->debug_text("Inserting ACL with ". count($rand_aco_ids) ." ACOs and ". count($rand_aro_ids) ." AROs - Allow: $allow");
  239. $gacl_api->add_acl($rand_aco_ids, $rand_aro_ids, NULL, $allow, 1);
  240. }
  241. }
  242. //Create much more Decoy data
  243. $max_aco=100;
  244. $max_aro=4000;
  245. $max_acl=1000;
  246. $min_rand_aco=1;
  247. $max_rand_aco=10;
  248. $min_rand_aro=1;
  249. $max_rand_aro=10;
  250. //Seed random.
  251. srand ((float) microtime() * 10000000);
  252. //Grab ACO Section_id
  253. $aco_section_id = $gacl_api->get_aco_section_section_id("Stress Test Decoy");
  254. if (!$aco_section_id) {
  255. //Add an ACO section.
  256. $aco_section_id = $gacl_api->add_aco_section("Stress Test Decoy", 1000,1000);
  257. $gacl_api->debug_text("Stress Test: ACO Section ID: $aco_section_id");
  258. }
  259. //Add 100 random ACO's
  260. if ($aco_section_id) {
  261. for ($i=0; $i < $max_aco; $i++) {
  262. $aco_id = $gacl_api->get_aco_id("Stress Test Decoy ACO #$i");
  263. if (!$aco_id) {
  264. //Add ACO.
  265. $aco_id = $gacl_api->add_aco($aco_section_id, "Stress Test ACO Decoy #$i",$i, $i);
  266. }
  267. }
  268. }
  269. $aco_ids = $gacl_api->get_aco($aco_section_id);
  270. //showarray($aco_ids);
  271. //Grab ARO section id
  272. $aro_section_id = $gacl_api->get_aro_section_section_id("Stress Test Decoy");
  273. if (!$aro_section_id) {
  274. //Add an ACO section.
  275. $aro_section_id = $gacl_api->add_aro_section("Stress Test Decoy", 1000,1000);
  276. $gacl_api->debug_text("Stress Test: ARO Section ID: $aro_section_id");
  277. }
  278. //Add 10,000 random ARO's
  279. if ($aro_section_id) {
  280. for ($i=0; $i < $max_aro; $i++) {
  281. $aro_id = $gacl_api->get_aro_id("Stress Test Decoy ARO #$i");
  282. if (!$aro_id) {
  283. //Add ARO.
  284. $aro_id = $gacl_api->add_aro($aro_section_id, "Stress Test Decoy ARO #$i",$i, $i);
  285. }
  286. }
  287. }
  288. $aro_ids = $gacl_api->get_aro($aro_section_id);
  289. //showarray($aro_ids);
  290. //Create random ACL's using the above stress test ACO/AROs
  291. if (count($aco_ids) > 1 AND count($aro_ids) > 1) {
  292. for ($i=0; $i < $max_acl; $i++) {
  293. //Get random ACO IDS
  294. $rand_aco_keys = array_rand($aco_ids, mt_rand($min_rand_aco, $max_rand_aco) );
  295. unset($rand_aco_ids);
  296. foreach ($rand_aco_keys as $rand_aco_key) {
  297. $rand_aco_ids[] = $aco_ids[$rand_aco_key];
  298. }
  299. //Get random ARO IDS
  300. $rand_aro_keys = array_rand($aro_ids, mt_rand($min_rand_aro, $max_rand_aro));
  301. unset($rand_aro_ids);
  302. foreach ($rand_aro_keys as $rand_aro_key) {
  303. $rand_aro_ids[] = $aro_ids[$rand_aro_key];
  304. }
  305. //Random ALLOW
  306. $allow = mt_rand(0,1);
  307. $gacl_api->debug_text("Inserting ACL with ". count($rand_aco_ids) ." ACOs and ". count($rand_aro_ids) ." AROs - Allow: $allow");
  308. $gacl_api->add_acl($rand_aco_ids, $rand_aro_ids, NULL, $allow, 1);
  309. }
  310. }
  311. */
  312. /*
  313. //Test subtree'ing
  314. $aco_id=10;
  315. $aro_id=22;
  316. $root_group_id=30;
  317. $test=acl_query($aco_id,$aro_id,$root_group_id);
  318. showarray($test);
  319. $aco_id=10;
  320. $aro_id=22;
  321. $root_group_id=33;
  322. $test=acl_query($aco_id,$aro_id,$root_group_id);
  323. showarray($test);
  324. */
  325. /*
  326. //Populate the ARO's
  327. $max_aros = 100;
  328. for ($i=0; $i < $max_aros; $i++) {
  329. $aro_id = $gacl_api->add_aro(41,"$i First $i Last", $i, $i);
  330. if ($aro_id) {
  331. $gacl_api->debug_text("ARO ID: $aro_id");
  332. } else {
  333. $gacl_api->debug_text("Insert ARO ID FAILED!");
  334. }
  335. }
  336. */
  337. ?>