Viewing File plugins/test/test.php of 0.00.0a
|
1: <?php 2: /* ------------------------------------------------------------- 3: This file is part of FreeDESK 4: 5: FreeDESK is (C) Copyright 2012 David Cutting 6: 7: FreeDESK is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeDESK is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeDESK. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freedesk/ 21: -------------------------------------------------------------- */ 22: 23: class test extends FreeDESK_PIM 24: { 25: 26: function Start() 27: { 28: // Let's include some JavaScript - first the name of our script 29: $jspath = $this->webpath . "test.js"; 30: // Then register it for inclusion 31: $this->DESK->PluginManager->RegisterScript($jspath); 32: 33: // We also want to register our page 34: $this->DESK->PluginManager->RegisterPIMPage("testpage", $this->ID); 35: 36: // And our API call 37: $this->DESK->PluginManager->RegisterPIMAPI("my_test_api_call", $this->ID); 38: } 39: 40: function BuildMenu() 41: { 42: // Now adding a menu option - first to an existing menu, the 'home' menu 43: // Create the actual menu item 44: $testmenu = new MenuItem(); 45: $testmenu->tag = "test"; 46: $testmenu->display = "Test Item"; 47: $testmenu->onclick = "PIMTest.say('hello world');"; 48: // And register it 49: $this->DESK->ContextManager->AddMenuItem("home", $testmenu); 50: 51: // And now for a totally new menu displayed... 52: // The main menu item here 53: $menu = new MenuItem(); 54: $menu->tag="testmenu"; 55: $menu->display="Test Menu"; 56: // no on-click events for this top-level one (though we could if we want) 57: 58: // And create the submenu items for it 59: $hello = new MenuItem(); 60: $hello->tag="hello"; 61: $hello->display="Say Hello"; 62: $hello->onclick="PIMTest.say('Hello!');"; 63: // Add to our new menu 64: $menu->submenu[] = $hello; 65: 66: // Now we could do the same (use $menu->submenu[]) again but rather we'll register it... 67: $this->DESK->ContextManager->AddMenuItem("testmenu", $menu); 68: 69: // And then add another menuitem directly to it like we did for the home menu 70: $goodbye = new MenuItem(); 71: $goodbye->tag="goodbye"; 72: $goodbye->display="Say Goodbye"; 73: $goodbye->onclick="PIMTest.say('Goodbye!');"; 74: // Register... 75: $this->DESK->ContextManager->AddMenuItem("testmenu",$goodbye); 76: // because we used a pre-existing tag "testmenu" it will be appended 77: 78: // And now let's put a link in to our page called testpage 79: $page = new MenuItem(); 80: $page->tag="testpage"; 81: $page->display="Test PIM Page"; 82: $page->onclick="DESK.loadSubpage('testpage');"; 83: $this->DESK->ContextManager->AddMenuItem("testmenu",$page); 84: 85: } 86: 87: function Page($page) 88: { 89: if ($page == "testpage") 90: { 91: echo "<h3>This is our page created by the test PIM</h3>\n"; 92: 93: echo "<a href=\"#\" onclick=\"PIMTest.say('hello');\">Say Hello</a><br /><br />\n"; 94: 95: // Let's show an API example 96: echo "<form id=\"my_test_api_form\" onsubmit=\"return false;\">\n"; 97: echo "<input type=\"hidden\" name=\"mode\" value=\"my_test_api_call\" />\n"; 98: $onclick="DESK.formAPI('my_test_api_form');"; 99: echo "<input type=\"submit\" value=\"Make a call to the API with my_test_api_call\" onclick=\"".$onclick."\" />\n"; 100: echo "</form><br /><br />\n"; 101: } 102: } 103: 104: function API($mode) 105: { 106: if ($mode == "my_test_api_call") 107: { 108: // Do nothing just return XML for a successful operation! 109: $xml = new xmlCreate(); 110: $xml->charElement("operation","1"); 111: echo $xml->getXML(true); 112: exit(); 113: } 114: } 115: 116: } 117: ?> 118: