Viewing File plugins/workload/workload.php of 0.00.3a
|
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 workload extends FreeDESK_PIM 26: { 27: // The startup method - register functionalityh 28: function Start() 29: { 30: // Register ourselves as a plugin 31: $this->DESK->PluginManager->Register(new Plugin( 32: "Workload", "0.01", "Reporting" )); 33: // Register a page which will be displayed 34: $this->DESK->PluginManager->RegisterPIMPage("workload_page", 35: $this->ID); 36: // Register an API call for details 37: $this->DESK->PluginManager->RegisterPIMAPI("workload_api", 38: $this->ID); 39: // Add a permission for this action 40: $this->DESK->PermissionManager->Register("workload", false); 41: // Register a JS script (workload.js) in our directory for inclusion 42: // Note the file can be called anything we like or even not in the 43: // directory (unlike this PHP file) 44: $jspath = $this->webpath . "workload.js"; 45: $this->DESK->PluginManager->RegisterScript($jspath); 46: // Register a CSS file (workload.css) 47: $csspath = $this->webpath . "workload.css"; 48: $this->DESK->PluginManager->RegisterCSS($csspath); 49: } 50: // The method to add menu items 51: function BuildMenu() 52: { 53: // Check if the permission is allowed or don't show the menu 54: if ($this->DESK->ContextManager->Permission("workload")) 55: { 56: // Check if the reporting menu already exists, add if not 57: $currentItems = $this->DESK->ContextManager->MenuItems(); 58: if (!isset($currentItems['reporting'])) 59: { 60: $repmenu = new MenuItem(); 61: $repmenu->tag = "reporting"; 62: $repmenu->display = "Reporting"; 63: $this->DESK->ContextManager->AddMenuItem 64: ("reporting", $repmenu); 65: } 66: 67: // Built the menu item for this plugin 68: $sReport = new MenuItem(); 69: $sReport->tag="workload"; 70: $sReport->display="Workload"; 71: // Set the action for the click 72: // (show the page 'workload' registered above) 73: $sReport->onclick = "DESK.loadSubpage('workload_page');"; 74: // Add the menu option to the reporting menu 75: $this->DESK->ContextManager->AddMenuItem("reporting",$sReport); 76: } 77: } 78: // Handle page requests (specifically the workload page) 79: function Page($page) 80: { 81: if ($page == "workload_page" // page is the workload page 82: && // and permission for this page 83: $this->DESK->ContextManager->Permission("workload")) 84: { 85: // Page title 86: echo "<h3>Workload</h3>\n"; 87: // Team and user list 88: $teamuser = $this->DESK->RequestManager->TeamUserList(); 89: // Iterate through this list and display workload info 90: echo "<table>\n"; 91: foreach($teamuser as $teamid => $teamdata) 92: { 93: // Counter for the team 94: $teamcount=0; 95: echo "<tr>\n"; 96: echo "<td>\n"; 97: echo "<b>".$teamdata['name']."</b>\n"; 98: echo "</td>\n"; 99: echo "<td><b>\n"; 100: // Get the requests assigned to just the team 101: $requests = $this->DESK->RequestManager->FetchAssigned($teamid, ""); 102: $reqcount = sizeof($requests); 103: echo $reqcount; 104: // Increment team counter 105: $teamcount += $reqcount; 106: echo "</b></td>"; 107: // Detail link for the team 108: $js="Workload.Detail(".$teamid.",'');"; 109: echo "<td>\n"; 110: echo "<a href=\"#\" onclick=\"".$js."\">Detail</a>\n"; 111: echo "</td>"; 112: echo "</tr>"; 113: // Detail row for the team 114: echo "<tr><td colspan=\"3\" id=\"detail_".$teamid."_\"></td></tr>\n"; 115: // Iterate through the users in the team 116: foreach($teamdata['items'] as $user => $userdata) 117: { 118: echo "<tr>\n"; 119: echo "<td>\n"; 120: echo $userdata['realname']; 121: echo "</td>\n"; 122: echo "<td>\n"; 123: // Requests for this user and team 124: $requests = $this->DESK->RequestManager->FetchAssigned($teamid, $user); 125: $reqcount = sizeof($requests); 126: echo $reqcount; 127: // Increment team counter 128: $teamcount+=$reqcount; 129: echo "</td>\n"; 130: // Detail link for the team and user 131: $js="Workload.Detail(".$teamid.",'".$user."');"; 132: echo "<td>\n"; 133: echo "<a href=\"#\" onclick=\"".$js."\">Detail</a>\n"; 134: echo "</td>"; 135: echo "</tr>\n"; 136: // Detail row for the user 137: echo "<tr><td colspan=\"3\" id=\"detail_".$teamid."_".$user."\"></td></tr>\n"; 138: } 139: // The team total 140: echo "<tr><td><b>Total</b></td><td><b>".$teamcount."</b></td></tr>\n"; 141: // A spacer 142: echo "<tr><td colspan=\"3\"><hr class=\"workload\"></td></tr>\n"; 143: } 144: echo "</table>\n"; 145: } 146: } 147: // API Handler 148: function API($mode) 149: { 150: if ($mode == "workload_api" // Correct API Mode 151: && // and permission for workload 152: $this->DESK->ContextManager->Permission("workload")) 153: { 154: // Get the team and user requested 155: $teamid = isset($_REQUEST['teamid']) ? $_REQUEST['teamid'] : 0; 156: $username = isset($_REQUEST['username']) ? $_REQUEST['username'] : ""; 157: // Get the assigned requests 158: $reqs = $this->DESK->RequestManager->FetchAssigned($teamid,$username); 159: // Get the list of priorities 160: $pris = $this->DESK->RequestManager->GetPriorityList(); 161: // Our output array with unknown default 162: $out = array(0=>array("name"=>"Unknown","total"=>0)); 163: // Iterate through the requests 164: foreach($reqs as $req) 165: { 166: // Get the priority 167: $pri = $req->Get("priority"); 168: // Check if exists and add to totals 169: if (isset($pris[$pri])) // valid 170: { 171: if (isset($out[$pri])) 172: $out[$pri]['total']++; 173: else 174: $out[$pri]=array( 175: "name"=>$pris[$pri]['priorityname'], 176: "total"=>1 ); 177: } 178: else 179: $out[0]["total"]++; 180: } 181: // Build the HTML 182: $html = ""; 183: // For each detail line 184: foreach($out as $line) 185: { 186: $html.=$line["name"].": ".$line["total"]."<br />"; 187: } 188: // Create the XML output 189: // XML creation object 190: $xml = new xmlCreate(); 191: // Add a char element with CDATA encoding 192: $xml->charElement( 193: "data", 194: $html, 195: 0, 196: false, 197: true ); 198: // Output the XML with the header 199: $xml->echoXML(true); 200: // Exit (ensure no other output) 201: exit(); 202: } 203: } 204: 205: 206: } 207: ?> 208: