Viewing File plugins/geodemo/geodemo.php of 0.01.1a
|
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: // A new class for the PIM extending FreeDESK_PIM, 24: // named the same as the directory and filename 25: class geodemo extends FreeDESK_PIM 26: { 27: // The startup method - register functionalityh 28: function Start() 29: { 30: 31: $this->DESK->PluginManager->Register(new Plugin( 32: "GeoDemo", "0.01", "Other" )); 33: 34: $this->DESK->PluginManager->RegisterPIMPage("geodemo_page", $this->ID); 35: $this->DESK->PluginManager->RegisterPIMPage("geodemo_content", $this->ID); 36: 37: $this->DESK->PermissionManager->Register("geodemo", false); 38: 39: //$jspath = $this->webpath . "geodemo.js"; 40: //$this->DESK->PluginManager->RegisterScript($jspath); 41: 42: $table = new DD_Table(); 43: $table->name = "Locations"; 44: $table->entity = "vis_country"; 45: //$table->keyfield = "country"; 46: $table->editable = true; 47: 48: $f = new DD_Field(); 49: $f->name="Code"; 50: $f->field="country"; 51: $f->type=DD_FieldType::Char; 52: $f->size=254; 53: $f->searchable=true; 54: $f->display=true; 55: $f->keyfield=true; 56: $table->Add($f); 57: 58: $f = new DD_Field(); 59: $f->name="Country"; 60: $f->field="country_desc"; 61: $f->type=DD_FieldType::Char; 62: $f->size=254; 63: $f->searchable=true; 64: $f->display=true; 65: $table->Add($f); 66: 67: $f = new DD_Field(); 68: $f->name="Latitude"; 69: $f->field="lat"; 70: $f->type=DD_FieldType::Char; 71: $f->size=254; 72: $f->searchable=false; 73: $f->display=true; 74: $table->Add($f); 75: 76: $f = new DD_Field(); 77: $f->name="Longitude"; 78: $f->field="long"; 79: $f->type=DD_FieldType::Char; 80: $f->size=254; 81: $f->searchable=false; 82: $f->display=true; 83: $table->Add($f); 84: 85: $this->DESK->DataDictionary->Add($table); 86: } 87: // The method to add menu items 88: function BuildMenu() 89: { 90: // Check if the permission is allowed or don't show the menu 91: if ($this->DESK->ContextManager->Permission("geodemo")) 92: { 93: // Check if the reporting menu already exists, add if not 94: $currentItems = $this->DESK->ContextManager->MenuItems(); 95: if (!isset($currentItems['reporting'])) 96: { 97: $repmenu = new MenuItem(); 98: $repmenu->tag = "reporting"; 99: $repmenu->display = "Reporting"; 100: $this->DESK->ContextManager->AddMenuItem 101: ("reporting", $repmenu); 102: } 103: 104: // Built the menu item for this plugin 105: $sReport = new MenuItem(); 106: $sReport->tag="geodemo"; 107: $sReport->display="GeoDemo Display"; 108: // Set the action for the click 109: 110: $sReport->onclick = "DESK.loadSubpage('geodemo_page');"; 111: // Add the menu option to the reporting menu 112: $this->DESK->ContextManager->AddMenuItem("reporting",$sReport); 113: } 114: } 115: // Handle page requests (specifically the workload page) 116: function Page($page) 117: { 118: if ($page == "geodemo_page" // page is the workload page 119: && // and permission for this page 120: $this->DESK->ContextManager->Permission("geodemo")) 121: { 122: // Page title 123: echo "<h3>GeoDemo</h3>\n"; 124: //echo $this->DESK->ContextManager->Session->sid."<br />\n"; 125: echo "<iframe width=\"860\" height=\"600\" frameborder=\"0\" src=\"page.php?page=geodemo_content&sid=".$this->DESK->ContextManager->Session->sid."\"></iframe>\n"; 126: } 127: else if ($page == "geodemo_content" // page is the workload page 128: && // and permission for this page 129: $this->DESK->ContextManager->Permission("geodemo")) 130: { 131: require($this->filepath . "map.php"); 132: } 133: } 134: // API Handler 135: function API($mode) 136: { 137: // 138: } 139: 140: 141: function Install() 142: { 143: $sqlfile = $this->filepath . "geodemo.sql"; 144: $fp = fopen($sqlfile, "r"); 145: 146: $q=""; 147: while (!feof($fp)) 148: { 149: $line = fgets($fp, 1024); 150: if (trim($line) != "") 151: $q.=trim($line); 152: if ($q[strlen($q)-1]==";") 153: { 154: $this->DESK->Database->Query($q); 155: $q=""; 156: } 157: } 158: } 159: 160: function Uninstall() 161: { 162: $sql = "DROP TABLE `vis_country`"; 163: $this->DESK->Database->Query($sql); 164: } 165: 166: } 167: ?> 168: