PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/webservice/testclient_forms.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 1064 lines | 784 code | 197 blank | 83 comment | 113 complexity | d1f4659c2b03fe55fa98f75444931f12 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. require_once($CFG->libdir.'/formslib.php');
  3. class webservice_test_client_form extends moodleform {
  4. public function definition() {
  5. global $CFG;
  6. $mform = $this->_form;
  7. list($functions, $protocols) = $this->_customdata;
  8. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  9. $authmethod = array('simple' => 'simple', 'token' => 'token');
  10. $mform->addElement('select', 'authmethod', get_string('authmethod', 'webservice'), $authmethod);
  11. $mform->setType('simple', PARAM_ALPHA);
  12. $mform->addElement('select', 'protocol', get_string('protocol', 'webservice'), $protocols);
  13. $mform->setType('protocol', PARAM_ALPHA);
  14. $mform->addElement('select', 'function', get_string('function', 'webservice'), $functions);
  15. $mform->setType('function', PARAM_PLUGIN);
  16. $this->add_action_buttons(false, get_string('select'));
  17. }
  18. }
  19. // === Test client forms ===
  20. class moodle_user_create_users_form extends moodleform {
  21. public function definition() {
  22. global $CFG;
  23. $mform = $this->_form;
  24. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  25. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  26. $data = $this->_customdata;
  27. if ($data['authmethod'] == 'simple') {
  28. $mform->addElement('text', 'wsusername', 'wsusername');
  29. $mform->setType('wsusername', PARAM_USERNAME);
  30. $mform->addElement('text', 'wspassword', 'wspassword');
  31. $mform->setType('wspassword', PARAM_RAW);
  32. } else if ($data['authmethod'] == 'token') {
  33. $mform->addElement('text', 'token', 'token');
  34. $mform->setType('token', PARAM_RAW_TRIMMED);
  35. }
  36. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  37. $mform->setType('authmethod', PARAM_SAFEDIR);
  38. /// specific to the create users function
  39. $mform->addElement('text', 'username', 'username');
  40. $mform->setType('username', PARAM_USERNAME);
  41. $mform->addElement('text', 'password', 'password');
  42. $mform->setType('password', PARAM_RAW);
  43. $mform->addElement('text', 'firstname', 'firstname');
  44. $mform->setType('firstname', PARAM_RAW);
  45. $mform->addElement('text', 'lastname', 'lastname');
  46. $mform->setType('lastname', PARAM_RAW);
  47. $mform->addElement('text', 'email', 'email');
  48. $mform->setType('email', PARAM_EMAIL);
  49. $mform->addElement('text', 'customfieldtype', 'customfieldtype');
  50. $mform->setType('customfieldtype', PARAM_RAW);
  51. $mform->addElement('text', 'customfieldvalue', 'customfieldvalue');
  52. $mform->setType('customfieldvalue', PARAM_RAW);
  53. $mform->addElement('hidden', 'function');
  54. $mform->setType('function', PARAM_PLUGIN);
  55. $mform->addElement('hidden', 'protocol');
  56. $mform->setType('protocol', PARAM_ALPHA);
  57. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  58. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  59. }
  60. public function get_params() {
  61. if (!$data = $this->get_data()) {
  62. return null;
  63. }
  64. //set customfields
  65. if (!empty($data->customfieldtype)) {
  66. $data->customfields = array(array('type' => $data->customfieldtype, 'value' => $data->customfieldvalue));
  67. }
  68. // remove unused from form data
  69. unset($data->submitbutton);
  70. unset($data->protocol);
  71. unset($data->function);
  72. unset($data->wsusername);
  73. unset($data->wspassword);
  74. unset($data->token);
  75. unset($data->authmethod);
  76. unset($data->customfieldtype);
  77. unset($data->customfieldvalue);
  78. $params = array();
  79. $params['users'] = array();
  80. $params['users'][] = (array)$data;
  81. return $params;
  82. }
  83. }
  84. class moodle_user_update_users_form extends moodleform {
  85. public function definition() {
  86. global $CFG;
  87. $mform = $this->_form;
  88. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  89. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  90. $data = $this->_customdata;
  91. if ($data['authmethod'] == 'simple') {
  92. $mform->addElement('text', 'wsusername', 'wsusername');
  93. $mform->setType('wsusername', PARAM_USERNAME);
  94. $mform->addElement('text', 'wspassword', 'wspassword');
  95. $mform->setType('wspassword', PARAM_RAW);
  96. } else if ($data['authmethod'] == 'token') {
  97. $mform->addElement('text', 'token', 'token');
  98. $mform->setType('token', PARAM_RAW_TRIMMED);
  99. }
  100. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  101. $mform->setType('authmethod', PARAM_ALPHA);
  102. /// specific to the create users function
  103. $mform->addElement('text', 'id', 'id');
  104. $mform->addRule('id', get_string('required'), 'required', null, 'client');
  105. $mform->setType('id', PARAM_INT);
  106. $mform->addElement('text', 'username', 'username');
  107. $mform->setType('username', PARAM_USERNAME);
  108. $mform->addElement('text', 'password', 'password');
  109. $mform->setType('password', PARAM_RAW);
  110. $mform->addElement('text', 'firstname', 'firstname');
  111. $mform->setType('firstname', PARAM_RAW);
  112. $mform->addElement('text', 'lastname', 'lastname');
  113. $mform->setType('lastname', PARAM_RAW);
  114. $mform->addElement('text', 'email', 'email');
  115. $mform->setType('email', PARAM_EMAIL);
  116. $mform->addElement('text', 'customfieldtype', 'customfieldtype');
  117. $mform->setType('customfieldtype', PARAM_RAW);
  118. $mform->addElement('text', 'customfieldvalue', 'customfieldvalue');
  119. $mform->setType('customfieldvalue', PARAM_RAW);
  120. $mform->addElement('hidden', 'function');
  121. $mform->setType('function', PARAM_PLUGIN);
  122. $mform->addElement('hidden', 'protocol');
  123. $mform->setType('protocol', PARAM_ALPHA);
  124. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  125. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  126. }
  127. public function get_params() {
  128. if (!$data = $this->get_data()) {
  129. return null;
  130. }
  131. //set customfields
  132. if (!empty($data->customfieldtype)) {
  133. $data->customfields = array(array('type' => $data->customfieldtype, 'value' => $data->customfieldvalue));
  134. }
  135. // remove unused from form data
  136. unset($data->submitbutton);
  137. unset($data->protocol);
  138. unset($data->function);
  139. unset($data->wsusername);
  140. unset($data->wspassword);
  141. unset($data->token);
  142. unset($data->authmethod);
  143. unset($data->customfieldtype);
  144. unset($data->customfieldvalue);
  145. foreach($data as $key => $value) {
  146. if (empty($value)) {
  147. unset($data->{$key});
  148. }
  149. }
  150. $params = array();
  151. $params['users'] = array();
  152. $params['users'][] = (array)$data;
  153. return $params;
  154. }
  155. }
  156. class moodle_user_delete_users_form extends moodleform {
  157. public function definition() {
  158. global $CFG;
  159. $mform = $this->_form;
  160. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  161. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  162. $data = $this->_customdata;
  163. if ($data['authmethod'] == 'simple') {
  164. $mform->addElement('text', 'wsusername', 'wsusername');
  165. $mform->setType('wsusername', PARAM_USERNAME);
  166. $mform->addElement('text', 'wspassword', 'wspassword');
  167. $mform->setType('wspassword', PARAM_RAW);
  168. } else if ($data['authmethod'] == 'token') {
  169. $mform->addElement('text', 'token', 'token');
  170. $mform->setType('token', PARAM_RAW_TRIMMED);
  171. }
  172. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  173. $mform->setType('authmethod', PARAM_ALPHA);
  174. /// beginning of specific code to the create users function
  175. $mform->addElement('text', 'userids[0]', 'userids[0]');
  176. $mform->addElement('text', 'userids[1]', 'userids[1]');
  177. $mform->addElement('text', 'userids[2]', 'userids[2]');
  178. $mform->addElement('text', 'userids[3]', 'userids[3]');
  179. $mform->setType('userids', PARAM_INT);
  180. /// end of specific code to the create users function
  181. $mform->addElement('hidden', 'function');
  182. $mform->setType('function', PARAM_PLUGIN);
  183. $mform->addElement('hidden', 'protocol');
  184. $mform->setType('protocol', PARAM_ALPHA);
  185. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  186. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  187. }
  188. public function get_params() {
  189. if (!$data = $this->get_data()) {
  190. return null;
  191. }
  192. // remove unused from form data
  193. unset($data->submitbutton);
  194. unset($data->protocol);
  195. unset($data->function);
  196. unset($data->wsusername);
  197. unset($data->wspassword);
  198. unset($data->token);
  199. unset($data->authmethod);
  200. /// beginning of specific code to the create users form
  201. $params = array();
  202. $params['userids'] = array();
  203. for ($i=0; $i<10; $i++) {
  204. if (empty($data->userids[$i])) {
  205. continue;
  206. }
  207. $params['userids'][] = $data->userids[$i];
  208. }
  209. /// end of specific code to the create users function
  210. return $params;
  211. }
  212. }
  213. class moodle_user_get_users_by_id_form extends moodleform {
  214. public function definition() {
  215. global $CFG;
  216. $mform = $this->_form;
  217. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  218. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  219. $data = $this->_customdata;
  220. if ($data['authmethod'] == 'simple') {
  221. $mform->addElement('text', 'wsusername', 'wsusername');
  222. $mform->setType('wsusername', PARAM_USERNAME);
  223. $mform->addElement('text', 'wspassword', 'wspassword');
  224. $mform->setType('wspassword', PARAM_RAW);
  225. } else if ($data['authmethod'] == 'token') {
  226. $mform->addElement('text', 'token', 'token');
  227. $mform->setType('token', PARAM_RAW_TRIMMED);
  228. }
  229. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  230. $mform->setType('authmethod', PARAM_ALPHA);
  231. /// beginning of specific code to the create users function
  232. $mform->addElement('text', 'userids[0]', 'userids[0]');
  233. $mform->addElement('text', 'userids[1]', 'userids[1]');
  234. $mform->addElement('text', 'userids[2]', 'userids[2]');
  235. $mform->addElement('text', 'userids[3]', 'userids[3]');
  236. $mform->setType('userids', PARAM_INT);
  237. /// end of specific code to the create users function
  238. $mform->addElement('hidden', 'function');
  239. $mform->setType('function', PARAM_PLUGIN);
  240. $mform->addElement('hidden', 'protocol');
  241. $mform->setType('protocol', PARAM_ALPHA);
  242. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  243. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  244. }
  245. public function get_params() {
  246. if (!$data = $this->get_data()) {
  247. return null;
  248. }
  249. // remove unused from form data
  250. unset($data->submitbutton);
  251. unset($data->protocol);
  252. unset($data->function);
  253. unset($data->wsusername);
  254. unset($data->wspassword);
  255. unset($data->token);
  256. unset($data->authmethod);
  257. /// beginning of specific code to the create users form
  258. $params = array();
  259. $params['userids'] = array();
  260. for ($i=0; $i<10; $i++) {
  261. if (empty($data->userids[$i])) {
  262. continue;
  263. }
  264. $params['userids'][] = $data->userids[$i];
  265. }
  266. /// end of specific code to the create users function
  267. return $params;
  268. }
  269. }
  270. class moodle_group_create_groups_form extends moodleform {
  271. public function definition() {
  272. global $CFG;
  273. $mform = $this->_form;
  274. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  275. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  276. $data = $this->_customdata;
  277. if ($data['authmethod'] == 'simple') {
  278. $mform->addElement('text', 'wsusername', 'wsusername');
  279. $mform->setType('wsusername', PARAM_USERNAME);
  280. $mform->addElement('text', 'wspassword', 'wspassword');
  281. $mform->setType('wspassword', PARAM_RAW);
  282. } else if ($data['authmethod'] == 'token') {
  283. $mform->addElement('text', 'token', 'token');
  284. $mform->setType('token', PARAM_RAW_TRIMMED);
  285. }
  286. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  287. $mform->setType('authmethod', PARAM_ALPHA);
  288. $mform->addElement('text', 'courseid', 'courseid');
  289. $mform->setType('courseid', PARAM_INT);
  290. $mform->addElement('text', 'name', 'name');
  291. $mform->setType('name', PARAM_TEXT);
  292. $mform->addElement('text', 'description', 'description');
  293. $mform->setType('description', PARAM_TEXT);
  294. $mform->addElement('text', 'enrolmentkey', 'enrolmentkey');
  295. $mform->setType('enrolmentkey', PARAM_RAW);
  296. $mform->addElement('hidden', 'function');
  297. $mform->setType('function', PARAM_PLUGIN);
  298. $mform->addElement('hidden', 'protocol');
  299. $mform->setType('protocol', PARAM_ALPHA);
  300. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  301. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  302. }
  303. public function get_params() {
  304. if (!$data = $this->get_data()) {
  305. return null;
  306. }
  307. // remove unused from form data
  308. unset($data->submitbutton);
  309. unset($data->protocol);
  310. unset($data->function);
  311. unset($data->wsusername);
  312. unset($data->wspassword);
  313. unset($data->token);
  314. unset($data->authmethod);
  315. $params = array();
  316. $params['groups'] = array();
  317. $params['groups'][] = (array)$data;
  318. return $params;
  319. }
  320. }
  321. class moodle_group_get_groups_form extends moodleform {
  322. public function definition() {
  323. global $CFG;
  324. $mform = $this->_form;
  325. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  326. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  327. $data = $this->_customdata;
  328. if ($data['authmethod'] == 'simple') {
  329. $mform->addElement('text', 'wsusername', 'wsusername');
  330. $mform->setType('wsusername', PARAM_USERNAME);
  331. $mform->addElement('text', 'wspassword', 'wspassword');
  332. $mform->setType('wspassword', PARAM_RAW);
  333. } else if ($data['authmethod'] == 'token') {
  334. $mform->addElement('text', 'token', 'token');
  335. $mform->setType('token', PARAM_RAW_TRIMMED);
  336. }
  337. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  338. $mform->setType('authmethod', PARAM_ALPHA);
  339. $mform->addElement('text', 'groupids[0]', 'groupids[0]');
  340. $mform->addElement('text', 'groupids[1]', 'groupids[1]');
  341. $mform->addElement('text', 'groupids[2]', 'groupids[2]');
  342. $mform->addElement('text', 'groupids[3]', 'groupids[3]');
  343. $mform->setType('groupids', PARAM_INT);
  344. $mform->addElement('hidden', 'function');
  345. $mform->setType('function', PARAM_PLUGIN);
  346. $mform->addElement('hidden', 'protocol');
  347. $mform->setType('protocol', PARAM_ALPHA);
  348. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  349. }
  350. public function get_params() {
  351. if (!$data = $this->get_data()) {
  352. return null;
  353. }
  354. // remove unused from form data
  355. unset($data->submitbutton);
  356. unset($data->protocol);
  357. unset($data->function);
  358. unset($data->wsusername);
  359. unset($data->wspassword);
  360. unset($data->token);
  361. unset($data->authmethod);
  362. $params = array();
  363. $params['groupids'] = array();
  364. for ($i=0; $i<10; $i++) {
  365. if (empty($data->groupids[$i])) {
  366. continue;
  367. }
  368. $params['groupids'][] = $data->groupids[$i];
  369. }
  370. return $params;
  371. }
  372. }
  373. class moodle_group_get_course_groups_form extends moodleform {
  374. public function definition() {
  375. global $CFG;
  376. $mform = $this->_form;
  377. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  378. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  379. $data = $this->_customdata;
  380. if ($data['authmethod'] == 'simple') {
  381. $mform->addElement('text', 'wsusername', 'wsusername');
  382. $mform->setType('wsusername', PARAM_USERNAME);
  383. $mform->addElement('text', 'wspassword', 'wspassword');
  384. $mform->setType('wspassword', PARAM_RAW);
  385. } else if ($data['authmethod'] == 'token') {
  386. $mform->addElement('text', 'token', 'token');
  387. $mform->setType('token', PARAM_RAW_TRIMMED);
  388. }
  389. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  390. $mform->setType('authmethod', PARAM_ALPHA);
  391. $mform->addElement('text', 'courseid', 'courseid');
  392. $mform->addElement('hidden', 'function');
  393. $mform->setType('function', PARAM_PLUGIN);
  394. $mform->addElement('hidden', 'protocol');
  395. $mform->setType('protocol', PARAM_ALPHA);
  396. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  397. }
  398. public function get_params() {
  399. if (!$data = $this->get_data()) {
  400. return null;
  401. }
  402. // remove unused from form data
  403. unset($data->submitbutton);
  404. unset($data->protocol);
  405. unset($data->function);
  406. unset($data->wsusername);
  407. unset($data->wspassword);
  408. unset($data->token);
  409. unset($data->authmethod);
  410. $params = array();
  411. $params['courseid'] = $data->courseid;
  412. return $params;
  413. }
  414. }
  415. class moodle_group_delete_groups_form extends moodleform {
  416. public function definition() {
  417. global $CFG;
  418. $mform = $this->_form;
  419. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  420. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  421. $data = $this->_customdata;
  422. if ($data['authmethod'] == 'simple') {
  423. $mform->addElement('text', 'wsusername', 'wsusername');
  424. $mform->setType('wsusername', PARAM_USERNAME);
  425. $mform->addElement('text', 'wspassword', 'wspassword');
  426. $mform->setType('wspassword', PARAM_RAW);
  427. } else if ($data['authmethod'] == 'token') {
  428. $mform->addElement('text', 'token', 'token');
  429. $mform->setType('token', PARAM_RAW_TRIMMED);
  430. }
  431. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  432. $mform->setType('authmethod', PARAM_ALPHA);
  433. $mform->addElement('text', 'groupids[0]', 'groupids[0]');
  434. $mform->addElement('text', 'groupids[1]', 'groupids[1]');
  435. $mform->addElement('text', 'groupids[2]', 'groupids[2]');
  436. $mform->addElement('text', 'groupids[3]', 'groupids[3]');
  437. $mform->setType('groupids', PARAM_INT);
  438. $mform->addElement('hidden', 'function');
  439. $mform->setType('function', PARAM_PLUGIN);
  440. $mform->addElement('hidden', 'protocol');
  441. $mform->setType('protocol', PARAM_ALPHA);
  442. $mform->addElement('static', 'warning', '', get_string('executewarnign', 'webservice'));
  443. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  444. }
  445. public function get_params() {
  446. if (!$data = $this->get_data()) {
  447. return null;
  448. }
  449. // remove unused from form data
  450. unset($data->submitbutton);
  451. unset($data->protocol);
  452. unset($data->function);
  453. unset($data->wsusername);
  454. unset($data->wspassword);
  455. unset($data->token);
  456. unset($data->authmethod);
  457. $params = array();
  458. $params['groupids'] = array();
  459. for ($i=0; $i<10; $i++) {
  460. if (empty($data->groupids[$i])) {
  461. continue;
  462. }
  463. $params['groupids'][] = $data->groupids[$i];
  464. }
  465. return $params;
  466. }
  467. }
  468. class moodle_group_get_groupmembers_form extends moodleform {
  469. public function definition() {
  470. global $CFG;
  471. $mform = $this->_form;
  472. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  473. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  474. $data = $this->_customdata;
  475. if ($data['authmethod'] == 'simple') {
  476. $mform->addElement('text', 'wsusername', 'wsusername');
  477. $mform->setType('wsusername', PARAM_USERNAME);
  478. $mform->addElement('text', 'wspassword', 'wspassword');
  479. $mform->setType('wspassword', PARAM_RAW);
  480. } else if ($data['authmethod'] == 'token') {
  481. $mform->addElement('text', 'token', 'token');
  482. $mform->setType('token', PARAM_RAW_TRIMMED);
  483. }
  484. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  485. $mform->setType('authmethod', PARAM_ALPHA);
  486. $mform->addElement('text', 'groupids[0]', 'groupids[0]');
  487. $mform->addElement('text', 'groupids[1]', 'groupids[1]');
  488. $mform->addElement('text', 'groupids[2]', 'groupids[2]');
  489. $mform->addElement('text', 'groupids[3]', 'groupids[3]');
  490. $mform->setType('groupids', PARAM_INT);
  491. $mform->addElement('hidden', 'function');
  492. $mform->setType('function', PARAM_PLUGIN);
  493. $mform->addElement('hidden', 'protocol');
  494. $mform->setType('protocol', PARAM_ALPHA);
  495. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  496. }
  497. public function get_params() {
  498. if (!$data = $this->get_data()) {
  499. return null;
  500. }
  501. // remove unused from form data
  502. unset($data->submitbutton);
  503. unset($data->protocol);
  504. unset($data->function);
  505. unset($data->wsusername);
  506. unset($data->wspassword);
  507. unset($data->token);
  508. unset($data->authmethod);
  509. $params = array();
  510. $params['groupids'] = array();
  511. for ($i=0; $i<10; $i++) {
  512. if (empty($data->groupids[$i])) {
  513. continue;
  514. }
  515. $params['groupids'][] = $data->groupids[$i];
  516. }
  517. return $params;
  518. }
  519. }
  520. class moodle_group_add_groupmembers_form extends moodleform {
  521. public function definition() {
  522. global $CFG;
  523. $mform = $this->_form;
  524. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  525. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  526. $data = $this->_customdata;
  527. if ($data['authmethod'] == 'simple') {
  528. $mform->addElement('text', 'wsusername', 'wsusername');
  529. $mform->setType('wsusername', PARAM_USERNAME);
  530. $mform->addElement('text', 'wspassword', 'wspassword');
  531. $mform->setType('wspassword', PARAM_RAW);
  532. } else if ($data['authmethod'] == 'token') {
  533. $mform->addElement('text', 'token', 'token');
  534. $mform->setType('token', PARAM_RAW_TRIMMED);
  535. }
  536. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  537. $mform->setType('authmethod', PARAM_SAFEDIR);
  538. $mform->addElement('text', 'userid[0]', 'userid[0]');
  539. $mform->addElement('text', 'groupid[0]', 'groupid[0]');
  540. $mform->addElement('text', 'userid[1]', 'userid[1]');
  541. $mform->addElement('text', 'groupid[1]', 'groupid[1]');
  542. $mform->setType('userid', PARAM_INT);
  543. $mform->setType('groupids', PARAM_INT);
  544. $mform->addElement('hidden', 'function');
  545. $mform->setType('function', PARAM_PLUGIN);
  546. $mform->addElement('hidden', 'protocol');
  547. $mform->setType('protocol', PARAM_ALPHA);
  548. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  549. }
  550. public function get_params() {
  551. if (!$data = $this->get_data()) {
  552. return null;
  553. }
  554. // remove unused from form data
  555. unset($data->submitbutton);
  556. unset($data->protocol);
  557. unset($data->function);
  558. unset($data->wsusername);
  559. unset($data->wspassword);
  560. unset($data->token);
  561. unset($data->authmethod);
  562. $params = array();
  563. $params['members'] = array();
  564. for ($i=0; $i<10; $i++) {
  565. if (empty($data->groupid[$i]) or empty($data->userid[$i])) {
  566. continue;
  567. }
  568. $params['members'][] = array('userid'=>$data->userid[$i], 'groupid'=>$data->groupid[$i]);
  569. }
  570. return $params;
  571. }
  572. }
  573. class moodle_group_delete_groupmembers_form extends moodleform {
  574. public function definition() {
  575. global $CFG;
  576. $mform = $this->_form;
  577. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  578. //note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters
  579. $data = $this->_customdata;
  580. if ($data['authmethod'] == 'simple') {
  581. $mform->addElement('text', 'wsusername', 'wsusername');
  582. $mform->setType('wsusername', PARAM_USERNAME);
  583. $mform->addElement('text', 'wspassword', 'wspassword');
  584. $mform->setType('wspassword', PARAM_RAW);
  585. } else if ($data['authmethod'] == 'token') {
  586. $mform->addElement('text', 'token', 'token');
  587. $mform->setType('token', PARAM_RAW_TRIMMED);
  588. }
  589. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  590. $mform->setType('authmethod', PARAM_ALPHA);
  591. $mform->addElement('text', 'userid[0]', 'userid[0]');
  592. $mform->addElement('text', 'groupid[0]', 'groupid[0]');
  593. $mform->addElement('text', 'userid[1]', 'userid[1]');
  594. $mform->addElement('text', 'groupid[1]', 'groupid[1]');
  595. $mform->setType('userid', PARAM_INT);
  596. $mform->setType('groupids', PARAM_INT);
  597. $mform->addElement('hidden', 'function');
  598. $mform->setType('function', PARAM_PLUGIN);
  599. $mform->addElement('hidden', 'protocol');
  600. $mform->setType('protocol', PARAM_ALPHA);
  601. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  602. }
  603. public function get_params() {
  604. if (!$data = $this->get_data()) {
  605. return null;
  606. }
  607. // remove unused from form data
  608. unset($data->submitbutton);
  609. unset($data->protocol);
  610. unset($data->function);
  611. unset($data->wsusername);
  612. unset($data->wspassword);
  613. unset($data->token);
  614. unset($data->authmethod);
  615. $params = array();
  616. $params['members'] = array();
  617. for ($i=0; $i<10; $i++) {
  618. if (empty($data->groupid[$i]) or empty($data->userid[$i])) {
  619. continue;
  620. }
  621. $params['members'][] = array('userid'=>$data->userid[$i], 'groupid'=>$data->groupid[$i]);
  622. }
  623. return $params;
  624. }
  625. }
  626. /**
  627. * Form class for create_categories() web service function test.
  628. *
  629. * @package core_webservice
  630. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  631. * @copyright 2012 Fabio Souto
  632. */
  633. class core_course_create_categories_form extends moodleform {
  634. /**
  635. * The form definition.
  636. */
  637. public function definition() {
  638. global $CFG;
  639. $mform = $this->_form;
  640. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  641. // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
  642. $data = $this->_customdata;
  643. if ($data['authmethod'] == 'simple') {
  644. $mform->addElement('text', 'wsusername', 'wsusername');
  645. $mform->setType('wsusername', PARAM_USERNAME);
  646. $mform->addElement('text', 'wspassword', 'wspassword');
  647. $mform->setType('wspassword', PARAM_RAW);
  648. } else if ($data['authmethod'] == 'token') {
  649. $mform->addElement('text', 'token', 'token');
  650. $mform->setType('token', PARAM_RAW_TRIMMED);
  651. }
  652. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  653. $mform->setType('authmethod', PARAM_ALPHA);
  654. $mform->addElement('text', 'name[0]', 'name[0]');
  655. $mform->addElement('text', 'parent[0]', 'parent[0]');
  656. $mform->addElement('text', 'idnumber[0]', 'idnumber[0]');
  657. $mform->addElement('text', 'description[0]', 'description[0]');
  658. $mform->addElement('text', 'name[1]', 'name[1]');
  659. $mform->addElement('text', 'parent[1]', 'parent[1]');
  660. $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
  661. $mform->addElement('text', 'description[1]', 'description[1]');
  662. $mform->setType('name', PARAM_TEXT);
  663. $mform->setType('parent', PARAM_INT);
  664. $mform->setType('idnumber', PARAM_RAW);
  665. $mform->setType('description', PARAM_TEXT);
  666. $mform->addElement('hidden', 'function');
  667. $mform->setType('function', PARAM_PLUGIN);
  668. $mform->addElement('hidden', 'protocol');
  669. $mform->setType('protocol', PARAM_ALPHA);
  670. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  671. }
  672. /**
  673. * Get the parameters that the user submitted using the form.
  674. * @return array|null
  675. */
  676. public function get_params() {
  677. if (!$data = $this->get_data()) {
  678. return null;
  679. }
  680. // Remove unused from form data.
  681. unset($data->submitbutton);
  682. unset($data->protocol);
  683. unset($data->function);
  684. unset($data->wsusername);
  685. unset($data->wspassword);
  686. unset($data->token);
  687. unset($data->authmethod);
  688. $params = array();
  689. $params['categories'] = array();
  690. for ($i=0; $i<10; $i++) {
  691. if (empty($data->name[$i]) or empty($data->parent[$i])) {
  692. continue;
  693. }
  694. $params['categories'][] = array('name'=>$data->name[$i], 'parent'=>$data->parent[$i],
  695. 'idnumber'=>$data->idnumber[$i], 'description'=>$data->description[$i]);
  696. }
  697. return $params;
  698. }
  699. }
  700. /**
  701. * Form class for delete_categories() web service function test.
  702. *
  703. * @package core_webservice
  704. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  705. * @copyright 2012 Fabio Souto
  706. */
  707. class core_course_delete_categories_form extends moodleform {
  708. /**
  709. * The form definition.
  710. */
  711. public function definition() {
  712. global $CFG;
  713. $mform = $this->_form;
  714. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  715. // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
  716. $data = $this->_customdata;
  717. if ($data['authmethod'] == 'simple') {
  718. $mform->addElement('text', 'wsusername', 'wsusername');
  719. $mform->setType('wsusername', PARAM_USERNAME);
  720. $mform->addElement('text', 'wspassword', 'wspassword');
  721. $mform->setType('wspassword', PARAM_RAW);
  722. } else if ($data['authmethod'] == 'token') {
  723. $mform->addElement('text', 'token', 'token');
  724. $mform->setType('token', PARAM_RAW_TRIMMED);
  725. }
  726. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  727. $mform->setType('authmethod', PARAM_ALPHA);
  728. $mform->addElement('text', 'id[0]', 'id[0]');
  729. $mform->addElement('text', 'newparent[0]', 'newparent[0]');
  730. $mform->addElement('text', 'recursive[0]', 'recursive[0]');
  731. $mform->addElement('text', 'id[1]', 'id[1]');
  732. $mform->addElement('text', 'newparent[1]', 'newparent[1]');
  733. $mform->addElement('text', 'recursive[1]', 'recursive[1]');
  734. $mform->setType('id', PARAM_INT);
  735. $mform->setType('newparent', PARAM_INT);
  736. $mform->setType('recursive', PARAM_BOOL);
  737. $mform->addElement('hidden', 'function');
  738. $mform->setType('function', PARAM_PLUGIN);
  739. $mform->addElement('hidden', 'protocol');
  740. $mform->setType('protocol', PARAM_ALPHA);
  741. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  742. }
  743. /**
  744. * Get the parameters that the user submitted using the form.
  745. * @return array|null
  746. */
  747. public function get_params() {
  748. if (!$data = $this->get_data()) {
  749. return null;
  750. }
  751. // Remove unused from form data.
  752. unset($data->submitbutton);
  753. unset($data->protocol);
  754. unset($data->function);
  755. unset($data->wsusername);
  756. unset($data->wspassword);
  757. unset($data->token);
  758. unset($data->authmethod);
  759. $params = array();
  760. $params['categories'] = array();
  761. for ($i=0; $i<10; $i++) {
  762. if (empty($data->id[$i])) {
  763. continue;
  764. }
  765. $attrs = array();
  766. $attrs['id'] = $data->id[$i];
  767. if (!empty($data->newparent[$i])) {
  768. $attrs['newparent'] = $data->newparent[$i];
  769. }
  770. if (!empty($data->recursive[$i])) {
  771. $attrs['recursive'] = $data->recursive[$i];
  772. }
  773. $params['categories'][] = $attrs;
  774. }
  775. return $params;
  776. }
  777. }
  778. /**
  779. * Form class for create_categories() web service function test.
  780. *
  781. * @package core_webservice
  782. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  783. * @copyright 2012 Fabio Souto
  784. */
  785. class core_course_update_categories_form extends moodleform {
  786. /**
  787. * The form definition.
  788. */
  789. public function definition() {
  790. global $CFG;
  791. $mform = $this->_form;
  792. $mform->addElement('header', 'wstestclienthdr', get_string('testclient', 'webservice'));
  793. // Note: these values are intentionally PARAM_RAW - we want users to test any rubbish as parameters.
  794. $data = $this->_customdata;
  795. if ($data['authmethod'] == 'simple') {
  796. $mform->addElement('text', 'wsusername', 'wsusername');
  797. $mform->setType('wsusername', PARAM_USERNAME);
  798. $mform->addElement('text', 'wspassword', 'wspassword');
  799. $mform->setType('wspassword', PARAM_RAW);
  800. } else if ($data['authmethod'] == 'token') {
  801. $mform->addElement('text', 'token', 'token');
  802. $mform->setType('token', PARAM_RAW_TRIMMED);
  803. }
  804. $mform->addElement('hidden', 'authmethod', $data['authmethod']);
  805. $mform->setType('authmethod', PARAM_ALPHA);
  806. $mform->addElement('text', 'id[0]', 'id[0]');
  807. $mform->addElement('text', 'name[0]', 'name[0]');
  808. $mform->addElement('text', 'parent[0]', 'parent[0]');
  809. $mform->addElement('text', 'idnumber[0]', 'idnumber[0]');
  810. $mform->addElement('text', 'description[0]', 'description[0]');
  811. $mform->addElement('text', 'id[1]', 'id[1]');
  812. $mform->addElement('text', 'name[1]', 'name[1]');
  813. $mform->addElement('text', 'parent[1]', 'parent[1]');
  814. $mform->addElement('text', 'idnumber[1]', 'idnumber[1]');
  815. $mform->addElement('text', 'description[1]', 'description[1]');
  816. $mform->setType('id', PARAM_INT);
  817. $mform->setType('name', PARAM_TEXT);
  818. $mform->setType('parent', PARAM_INT);
  819. $mform->setType('idnumber', PARAM_RAW);
  820. $mform->setType('description', PARAM_TEXT);
  821. $mform->addElement('hidden', 'function');
  822. $mform->setType('function', PARAM_PLUGIN);
  823. $mform->addElement('hidden', 'protocol');
  824. $mform->setType('protocol', PARAM_ALPHA);
  825. $this->add_action_buttons(true, get_string('execute', 'webservice'));
  826. }
  827. /**
  828. * Get the parameters that the user submitted using the form.
  829. * @return array|null
  830. */
  831. public function get_params() {
  832. if (!$data = $this->get_data()) {
  833. return null;
  834. }
  835. // Remove unused from form data.
  836. unset($data->submitbutton);
  837. unset($data->protocol);
  838. unset($data->function);
  839. unset($data->wsusername);
  840. unset($data->wspassword);
  841. unset($data->token);
  842. unset($data->authmethod);
  843. $params = array();
  844. $params['categories'] = array();
  845. for ($i=0; $i<10; $i++) {
  846. if (empty($data->id[$i])) {
  847. continue;
  848. }
  849. $attrs = array();
  850. $attrs['id'] = $data->id[$i];
  851. if (!empty($data->name[$i])) {
  852. $attrs['name'] = $data->name[$i];
  853. }
  854. if (!empty($data->parent[$i])) {
  855. $attrs['parent'] = $data->parent[$i];
  856. }
  857. if (!empty($data->idnumber[$i])) {
  858. $attrs['idnumber'] = $data->idnumber[$i];
  859. }
  860. if (!empty($data->description[$i])) {
  861. $attrs['description'] = $data->description[$i];
  862. }
  863. $params['categories'][] = $attrs;
  864. }
  865. return $params;
  866. }
  867. }