Viewing File core/Skin.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: /** 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: $mode = 1; // 0 - standard, 1 std with no cache, 2 include inline 147: 148: if ($mode==0) 149: { 150: foreach($scripts as $script) 151: echo "<script type=\"text/javascript\" src=\"".$script."\"></script>\n"; 152: } 153: else if ($mode==1) 154: { 155: mt_srand(microtime()*1000000); 156: $len=32; 157: $chars="abcdefghijklmnopqrstuvwxyz"; 158: $clen=strlen($chars); 159: foreach($scripts as $script) 160: { 161: $nc=""; 162: for($a=0; $a<$len; ++$a) 163: { 164: $nc.=$chars[mt_rand(0,$clen-1)]; 165: } 166: echo "<script type=\"text/javascript\" src=\"".$script."?nc=".$nc."\"></script>\n"; 167: } 168: } 169: else 170: { 171: echo "<script type=\"text/javascript\">\n"; 172: foreach($scripts as $script) 173: { 174: echo file_get_contents($script); 175: echo "\n"; 176: } 177: echo "\n</script>\n"; 178: } 179: 180: if ($this->DESK->ContextManager->IsOpen()) 181: { 182: // Login-specific settings such as SID and request statuses 183: echo "<script type=\"text/javascript\">\n"; 184: echo "DESK.sid = \"".$this->DESK->ContextManager->Session->sid."\";\n"; 185: 186: $statuses = $this->DESK->RequestManager->StatusList(); 187: foreach($statuses as $key => $val) 188: { 189: echo "DESK.requestStatus[".$key."]=\"".$val."\";\n"; 190: } 191: 192: // Request list display fields 193: $fields = $this->DESK->RequestManager->FetchFields(); 194: $a=0; 195: foreach($fields as $key => $val) 196: { 197: echo "DESK.fieldList[".$a++."] = [ \"".$val[0]."\" , ".$val[1]." , \"".$key."\" ];\n"; 198: } 199: 200: echo "</script>\n"; 201: } 202: 203: 204: } 205: 206: /** 207: * Common Footer Items (pre end of HTML) display 208: **/ 209: function CommonFooter() 210: { 211: echo "\n"; 212: echo "<form id=\"login_sid_form\" action=\"./\" method=\"post\">\n"; 213: echo "<input type=\"hidden\" name=\"sid\" value=\"\" />\n"; 214: echo "</form>\n"; 215: } 216: 217: /** 218: * Common body items (just after the body tag) display 219: **/ 220: function CommonBody() 221: { 222: echo "\n"; 223: $this->IncludeFile("login.php"); 224: echo "<div id=\"screen_backdrop\" class=\"screen_backdrop\"></div>\n"; 225: echo "<div id=\"loading\" class=\"loading\"></div>\n"; 226: } 227: 228: } 229: ?> 230: 231: 232: 233: