File: 0.01.1a/core/Error.php (View as HTML)

  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:  * Error Codes
 25: **/
 26: class ErrorCode
 27: {
 28: 	const FailedLogin = 101;
 29: 	const SessionExpired = 102;
 30: 	
 31: 	const UnknownMode = 201;
 32: 	
 33: 	const EntityError = 300;
 34: 	
 35: 	const Forbidden = 403;
 36: 	const ResourceNotFound = 404;
 37: 	
 38: 	const UnknownRequest = 604;
 39: 	
 40: 	const OperationFailed = 700;
 41: }
 42: 
 43: /**
 44:  * FreeDESK Error
 45: **/
 46: class FreeDESK_Error
 47: {
 48: 	/**
 49: 	 * Code
 50: 	**/
 51: 	var $Code = 0;
 52: 	/**
 53: 	 * Text
 54: 	**/
 55: 	var $Text = "";
 56: 	/**
 57: 	 * Constructor
 58: 	 * @param int $code Error Code (ErrorCode::)
 59: 	 * @param string $text Text (optional, default "")
 60: 	**/
 61: 	function FreeDESK_Error($code, $text="")
 62: 	{
 63: 		$this->Code=$code;
 64: 		$this->Text=$text;
 65: 	}
 66: 	/**
 67: 	 * Get Error as XML
 68: 	 * @param bool $header Put on XML header (optional, default false)
 69: 	 * @return string XML data
 70: 	**/
 71: 	function XML($header=false)
 72: 	{
 73: 		$xml = new xmlCreate();
 74: 		$data=array("code"=>$this->Code);
 75: 		$xml->startElement("error",$data);
 76: 		$xml->charElement("code",$this->Code);
 77: 		$xml->charElement("text",$this->Text,0,false,true);
 78: 		$xml->endElement("error");
 79: 		return $xml->getXML($header);
 80: 	}
 81: }
 82: ?>
 83: