init.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. class Example extends Plugin {
  3. // Demonstrates how to add a separate panel to the preferences screen and inject Javascript/save data using Dojo forms.
  4. private $link;
  5. private $host;
  6. function about() {
  7. return array(1.0,
  8. "Example plugin #1",
  9. "fox",
  10. true);
  11. }
  12. function init($host) {
  13. $this->link = $host->get_link();
  14. $this->host = $host;
  15. $host->add_hook($host::HOOK_PREFS_TAB, $this);
  16. }
  17. function save() {
  18. $example_value = db_escape_string($this->link, $_POST["example_value"]);
  19. $this->host->set($this, "example", $example_value);
  20. echo "Value set to $example_value";
  21. }
  22. function get_prefs_js() {
  23. return file_get_contents(dirname(__FILE__) . "/example.js");
  24. }
  25. function hook_prefs_tab($args) {
  26. if ($args != "prefPrefs") return;
  27. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("Example Pane")."\">";
  28. print "<br/>";
  29. // print_r($this->host->set($this, "example", rand(0,100)));
  30. // print_r($this->host->get_all($this));
  31. $value = $this->host->get($this, "example");
  32. print "<form dojoType=\"dijit.form.Form\">";
  33. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  34. evt.preventDefault();
  35. if (this.validate()) {
  36. console.log(dojo.objectToQuery(this.getValues()));
  37. new Ajax.Request('backend.php', {
  38. parameters: dojo.objectToQuery(this.getValues()),
  39. onComplete: function(transport) {
  40. notify_info(transport.responseText);
  41. }
  42. });
  43. //this.reset();
  44. }
  45. </script>";
  46. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
  47. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
  48. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"example\">";
  49. print "<table width=\"100%\" class=\"prefPrefsList\">";
  50. print "<tr><td width=\"40%\">".__("Sample value")."</td>";
  51. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"example_value\" value=\"$value\"></td></tr>";
  52. print "</table>";
  53. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  54. __("Set value")."</button>";
  55. print "</form>";
  56. print "</div>"; #pane
  57. }
  58. }
  59. ?>