Viewing File core/Skin.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: /** 24: * Skin class - controls skin elements as required 25: **/ 26: class Skin 27: { 28: /** 29: * FreeDESK instance 30: **/ 31: private $DESK = null; 32: 33: /** 34: * Current Skin 35: **/ 36: private $Skin = "default"; 37: 38: /** 39: * Default/Fallback Skin 40: **/ 41: private $Default = "default"; 42: 43: /** 44: * Constructor 45: * @param mixed &$freeDESK FreeDESK instance pointer 46: **/ 47: function Skin(&$freeDESK) 48: { 49: $this->DESK = &$freeDESK; 50: } 51: 52: /** 53: * Set skin 54: * @param string Skin 55: **/ 56: function SetSkin($skin) 57: { 58: $this->Skin = $skin; 59: } 60: 61: /** 62: * Get a (physical) file location 63: * @param string $file Filename 64: * @return mixed Filepath (string) or bool false on failure to find 65: **/ 66: function GetFileLocation($file) 67: { 68: $skinfile = $this->DESK->BaseDir . "skin/" . $this->Skin . "/" . $file; 69: $deffile = $this->DESK->BaseDir . "skin/" . $this->Default . "/" . $file; 70: if ($skinfile != $deffile) // seperate files to try 71: { 72: if (file_exists($skinfile)) 73: return $skinfile; 74: } 75: // Try the default 76: if (file_exists($deffile)) 77: return $deffile; 78: else 79: return false; // no file found 80: } 81: 82: /** 83: * Get a web location for a file 84: * @param string $file Filename 85: * @return mixed Filepath (string) or bool false on failure to find 86: **/ 87: function GetWebLocation($file) 88: { 89: $webfile = ""; 90: $skinfile = $this->DESK->BaseDir . "skin/" . $this->Skin . "/" . $file; 91: $deffile = $this->DESK->BaseDir . "skin/" . $this->Default . "/" . $file; 92: if ($skinfile != $deffile) // seperate files to try 93: { 94: if (file_exists($skinfile)) 95: $webfile="skin/".$this->Skin."/".$file; 96: } 97: // Try the default 98: if (($webfile=="")&&(file_exists($deffile))) 99: $webfile="skin/".$this->Default."/".$file; 100: else 101: return false; // no file found 102: 103: return $webfile; 104: } 105: 106: /** 107: * Include a file 108: * @param string $file Filename 109: * @param array $data Data element for skin element (optional) 110: * @return bool True on success or false on failure 111: **/ 112: function IncludeFile($file, $data=array()) 113: { 114: $filename=$this->GetFileLocation($file); 115: if ($filename === false) return false; // file not found 116: $DESK=&$this->DESK; 117: 118: include($filename); 119: } 120: 121: /** 122: * Get a file contents 123: * @param string $file Filename 124: * @return mixed Contents on success or bool false on failure 125: **/ 126: function GetFile($file) 127: { 128: $filename=$this->GetFileLocation($file); 129: if ($filename === false) return false; // file not found 130: 131: return file_get_contents($filename); 132: } 133: 134: /** 135: * Common Header Items Display 136: **/ 137: function CommonHeader() 138: { 139: $scripts = array("js/freedesk.js","js/ajax.js","js/alerts.js","js/search.js","js/request.js"); 140: 141: $pim_scripts = $this->DESK->PluginManager->GetScripts(); 142: 143: foreach($pim_scripts as $scr) 144: $scripts[]=$scr; 145: 146: $css = $this->DESK->PluginManager->GetCSS(); 147: 148: $mode = 1; // 0 - standard, 1 std with no cache, 2 include inline 149: 150: if ($mode==0) 151: { 152: foreach($scripts as $script) 153: echo "<script type=\"text/javascript\" src=\"".$script."\"></script>\n"; 154: foreach($css as $stylesheet) 155: echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$stylesheet."\" />\n"; 156: } 157: else if ($mode==1) 158: { 159: mt_srand(microtime()*1000000); 160: $len=32; 161: $chars="abcdefghijklmnopqrstuvwxyz"; 162: $clen=strlen($chars); 163: foreach($scripts as $script) 164: { 165: $nc=""; 166: for($a=0; $a<$len; ++$a) 167: { 168: $nc.=$chars[mt_rand(0,$clen-1)]; 169: } 170: echo "<script type=\"text/javascript\" src=\"".$script."?nc=".$nc."\"></script>\n"; 171: } 172: foreach($css as $stylesheet) 173: { 174: $nc=""; 175: for($a=0; $a<$len; ++$a) 176: { 177: $nc.=$chars[mt_rand(0,$clen-1)]; 178: } 179: echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$stylesheet."?nc=".$nc."\" />\n"; 180: } 181: 182: } 183: else 184: { 185: echo "<script type=\"text/javascript\">\n"; 186: foreach($scripts as $script) 187: { 188: echo file_get_contents($script); 189: echo "\n"; 190: } 191: echo "\n</script>\n"; 192: 193: echo "\n<style type=\"text/css\">\n"; 194: foreach($css as $stylesheet) 195: { 196: echo file_get_contents($stylesheet); 197: echo "\n"; 198: } 199: echo "\n</style>\n"; 200: } 201: 202: if ($this->DESK->ContextManager->IsOpen()) 203: { 204: // Login-specific settings such as SID and request statuses 205: echo "<script type=\"text/javascript\">\n"; 206: echo "DESK.sid = \"".$this->DESK->ContextManager->Session->sid."\";\n"; 207: 208: $statuses = $this->DESK->RequestManager->StatusList(); 209: foreach($statuses as $key => $val) 210: { 211: echo "DESK.requestStatus[".$key."]=\"".$val."\";\n"; 212: } 213: 214: $priorities = $this->DESK->RequestManager->GetPriorityList(); 215: echo "DESK.requestPriority[0]=\"None\";\n"; 216: foreach($priorities as $key => $val) 217: { 218: echo "DESK.requestPriority[".$key."]=\"".$val['priorityname']."\";\n"; 219: } 220: 221: // Request list display fields 222: $fields = $this->DESK->RequestManager->FetchFields(); 223: $a=0; 224: foreach($fields as $key => $val) 225: { 226: echo "DESK.fieldList[".$a++."] = [ \"".$val[0]."\" , ".$val[1]." , \"".$key."\" ];\n"; 227: } 228: 229: echo "</script>\n"; 230: } 231: 232: 233: } 234: 235: /** 236: * Common Footer Items (pre end of HTML) display 237: **/ 238: function CommonFooter() 239: { 240: echo "\n"; 241: echo "<form id=\"login_sid_form\" action=\"./\" method=\"post\">\n"; 242: echo "<input type=\"hidden\" name=\"sid\" value=\"\" />\n"; 243: echo "</form>\n"; 244: } 245: 246: /** 247: * Common body items (just after the body tag) display 248: **/ 249: function CommonBody() 250: { 251: echo "\n"; 252: $this->IncludeFile("login.php"); 253: echo "<div id=\"screen_backdrop\" class=\"screen_backdrop\"></div>\n"; 254: echo "<div id=\"loading\" class=\"loading\"></div>\n"; 255: } 256: 257: } 258: ?> 259: 260: 261: 262: