init.php 2.2 KB

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