public static function getChat($clientid)
    {
        $return = '';
        $user = new beuser($_SESSION['beuser_id']);
        $RS = $user->getChat(0, $clientid);
        $client = new user($clientid);
        foreach ($RS as $msg) {
            if ($msg['recipient_id'] == 0) {
                // FROM client
                $return .= '<div class="row chat_entry chat_relo" data-msgid="' . $msg['id'] . '">
		                        <div class="col-xs-1">
		                        	<img class="chat_userimg" src="../data/img/_users/_thumbs/' . $client->get('profilepic') . '">
		                        </div>

		                        <div class="col-xs-6 chat_message">
		                        	<div class="chat_time">
		                        		' . $client->get('firstname') . ' ' . $client->get('lastname') . ' | ' . date('d.m.Y H:i', $msg['time']) . '
			                        </div>
		                        		' . $msg['text'] . '
		                        </div>
		                    </div>';
            } else {
                if ($msg['recipient_id'] == $clientid) {
                    //FROM RELO
                    $messenger = new beuser($msg['sender_id']);
                    $return .= '<div class="row chat_entry chat_client" data-msgid="' . $msg['id'] . '">

		                        <div class="col-xs-6 col-xs-offset-5 text-right chat_message">
		                        	<div class="chat_time text-right">
			                        	' . $user->get('firstname') . ' ' . $user->get('lastname') . ' | ' . date('d.m.Y H:i', $msg['time']) . '
			                        </div>
		                        		' . $msg['text'] . '
		                        </div>

		                        <div class="col-xs-1">
		                        	<img class="chat_userimg" src="../data/img/_users/_thumbs/' . $user->get('profilepic') . '">
		                        </div>
		                    </div>';
                }
            }
        }
        //end foreach
        return $return;
    }
             $user->files[$val['id']]['comment'] = $val['comment'];
         }
     }
     $user->save();
     echo json_encode(array('status' => 1));
     break;
 case 'sendMessage':
     $return = $this->user->sendMessage($_POST['values']['text'], $_POST['values']['recipientId']);
     if ($return !== false) {
         echo json_encode(array('status' => 1, 'time' => date('d.m.Y H:i'), 'profilepic' => $this->user->get('profilepic'), 'msgid' => $return, 'username' => $this->user->get('firstname') . ' ' . $this->user->get('lastname')));
     }
     break;
 case 'chatinit':
     $return = '';
     $user = new beuser($_SESSION['beuser_id']);
     $RS = $user->getChat($_POST['values']['lastmsgid'], $_POST['values']['clientid']);
     foreach ($RS as $key => $msg) {
         $RS[$key]['time'] = date('d.m.Y H:i', $msg['time']);
     }
     echo json_encode(array('messages' => $RS, 'count' => count($RS)));
     break;
 case 'checkNewMessages':
     /*
      * Handler for backend/start to check for new incoming messages
      */
     $RS = database::Query('SELECT * FROM messages WHERE recipient_id = 0 AND read_time = 0', array(), $stats);
     if ($stats === 1) {
         $user = new User($RS['sender_id']);
         echo json_encode(array('msg' => Texter::get('beuser|newMessage', array($user->get('firstname', $user->get('lastname'))))));
     } else {
         echo json_encode(array('msg' => Texter::get('beuser|newMessages', array($stats))));