<?php
///////////////////////////////////////////////////////////////////////////////////////
// PHPizabi 0.848b C1 [ALICIA]                               http://www.phpizabi.net //
///////////////////////////////////////////////////////////////////////////////////////
// Please read the license.txt file before using / modifying this software           //
// Original author:         Claude Desjardins, R - feedback@realitymedias.com        //
// Last modification date:  February 21th 2007                                       //
// Version:                 PHPizabi 0.848b C1                                       //
//                                                                                   //
// (C) 2005, 2007 Real!ty Medias / PHPizabi - All rights reserved                    //
///////////////////////////////////////////////////////////////////////////////////////

	class t_command extends triton {
		function runCommand($param, $channel=NULL) {

		
			// Z = Op Away
			// Y = Voice Away
			// X = Mute Away
			// W = User Away
			
			$usersList = $this -> getChannelData($this -> channel, "users");
	
			/* User is not away? */
			if (!preg_match('/[W-Z]:'.preg_quote($this -> nickname).',/i', $usersList)) {
				
				/* Get the actual user's status */
				preg_match('/([A-V]):'.preg_quote($this -> nickname).',/i', $usersList, $status);
				
				switch($status[1]) {
					case('U'): default: $awayMode = 'W'; break;
					case('M'): $awayMode = 'X'; break;
					case('V'): $awayMode = 'Y'; break;
					case('O'): $awayMode = 'Z'; break;
				}
				
				/* Mark as away! */
				$usersList = preg_replace('/[A-V]:('.preg_quote($this -> nickname).'),/i', $awayMode.':\\1,', $usersList);
				$this -> localEcho('ECHO_SET_AWAY', array());
			}
			
			/* Set as back */
			else {
				
				/* Get the actual user's status */
				preg_match('/([W-Z]):'.preg_quote($this -> nickname).',/i', $usersList, $status);
				
				switch($status[1]) {
					case('W'): default: $awayMode = 'U'; break;
					case('X'): $awayMode = 'M'; break;
					case('Y'): $awayMode = 'V'; break;
					case('Z'): $awayMode = 'O'; break;
				}
				$usersList = preg_replace('/[W-Z]:('.preg_quote($this -> nickname).'),/i', $awayMode.':\\1,', $usersList);
				$this -> localEcho('ECHO_UNSET_AWAY', array());
			}
			
			$this -> setChannelData($channel, "users", $usersList);
	
		}
	}
?>