init.php 2.2 KB

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