<?php
/**
* Chat functionality page
*
* This page implements the chat functionality. It is the iframe's target. 
*
* @package eFront
* @version 0.1
* @todo Limited users per room
* @todo Limited rooms
*/

session_cache_limiter('none');
session_start();

$path = "../libraries/";
/** Configuration file.*/
include_once $path."configuration.php";
error_reporting(E_ALL);
pr($_GET);
$db->debug=true;

if (!eF_checkUser($_SESSION['s_login'],  $_SESSION['s_password'])) {                   //Only a valid user may access this page
    exit;
}

if(!isset($_GET['first']) || !isset($_GET['second'])) {
	exit;
}

$first  = $_GET['first'];
$second = $_GET['second'];

$firstPositions = explode("-",$first);
foreach($firstPositions as $key => $value) {
	$firstPositions[$key] = substr($value,strlen('firstlist')+3);
}
$secondPositions = explode("-",$second);
foreach($secondPositions as $key => $value) {
	$secondPositions[$key] = substr($value,strlen('secondlist')+3);
}

$positions = array(
	'first' 	=> $firstPositions,
	'second' 	=> $secondPositions
);

$positions = serialize($positions);
//print_r($positions);
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-type: text/xml");

echo "<?xml version=\"1.0\"?>";
echo "<root>";

if(eF_checkUser($_SESSION['s_login'],$_SESSION['s_password'])!='administrator'){
    eF_updateTableData("users_to_lessons", array('positions' => $positions), "lessons_ID=".$_SESSION['s_lessons_ID']." AND users_LOGIN='".$_SESSION['s_login']."'");
} else {
    $result = eF_getTableData("configuration","value","name = '".$_SESSION['s_login']."_positions'");
    if(sizeof($result)>0) {
        eF_updateTableData("configuration", array('value' => $positions), "name = '".$_SESSION['s_login']."_positions'");
    } else {
        $fields_insert = array(
                            'name'  => $_SESSION['s_login'].'_positions',
                            'value' => $positions
                            );
        eF_insertTableData("configuration",$fields_insert);
    }
}


echo "</root>";

exit;

?>
