test.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * test.php
  4. *
  5. * contains examples about how to use
  6. * class methods for Sf_Admin
  7. *
  8. * @author André Genrich <andre.genrich@thurdata.ch>
  9. * @version 1
  10. * @copyright Copyright (c) Thurdata GmbH 2020
  11. * @license GPL
  12. * @name test.php
  13. */
  14. /////////////
  15. // Require //
  16. /////////////
  17. require_once('config.php');
  18. require_once('cwp7/Admin.php');
  19. //////////
  20. // Args //
  21. //////////
  22. if(PHP_SAPI != 'cli')
  23. $args = $_GET;
  24. else
  25. $args = parse_args($argv);
  26. if(isset($args['action']))
  27. {
  28. $action = $args['action'];
  29. }
  30. else
  31. {
  32. echo 'No action, exiting' . PHP_EOL;
  33. exit (-1);
  34. }
  35. function parse_args($argv){
  36. array_shift($argv);
  37. $out = array();
  38. foreach ($argv as $arg){
  39. if (substr($arg,0,2) == '--'){
  40. $eqPos = strpos($arg,'=');
  41. if ($eqPos === false){
  42. $key = substr($arg,2);
  43. $out[$key] = isset($out[$key]) ? $out[$key] : true;
  44. } else {
  45. $key = substr($arg,2,$eqPos-2);
  46. $out[$key] = substr($arg,$eqPos+1);
  47. }
  48. } else if (substr($arg,0,1) == '-'){
  49. if (substr($arg,2,1) == '='){
  50. $key = substr($arg,1,1);
  51. $out[$key] = substr($arg,3);
  52. } else {
  53. $chars = str_split(substr($arg,1));
  54. foreach ($chars as $char){
  55. $key = $char;
  56. $out[$key] = isset($out[$key]) ? $out[$key] : true;
  57. }
  58. }
  59. } else {
  60. $out[] = $arg;
  61. }
  62. }
  63. return $out;
  64. }
  65. /////////////////
  66. // Constructor //
  67. /////////////////
  68. $cwp7 = new cwp7_Admin($cwp7URL, $cwp7Token);
  69. $r = $cwp7->constructorSuccess();
  70. if(isset($r['error_msg'])) {
  71. echo 'Error : cannot construct :-(' . PHP_EOL;
  72. print_r($r);
  73. exit();
  74. }
  75. /////////////
  76. // Actions //
  77. /////////////
  78. // Get All Accounts
  79. if($action == 'gaa')
  80. {
  81. $r = $cwp7->getAllAccounts();
  82. print_r($r);
  83. }