<?php
global $hooks;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$hooks->add_action('admin_action','the_help'); 

function helps_title(){
    echo "Help";
}


// Define the CSS 
function helps_css() {
    ?>
	<link href="/assets/global/plugins/jstree/dist/themes/default/style.min.css" rel="stylesheet" type="text/css" />
    <?php
}
// Define the JS 
function helps_js() {
    ?>
	<script src="/assets/global/plugins/jstree/dist/jstree.min.js" type="text/javascript"></script>
	<script src="/assets/modul-js/common/messenger/ui-tree.min.js" type="text/javascript"></script>
	<script src="/assets/modul-js/admin/help.js" type="text/javascript"></script>
    <?php
}

function the_help(){
	global $app;

	$app->get('/help/{id}', function (Request $request) {
		global $hooks;
		global $room_id;
		
		$room_id = $id;
		
		$hooks->add_action('the_title',"helps_title");
		$hooks->add_action('global_css',"helps_css");
		$hooks->add_action('global_js',"helps_js");
		
		the_head();
		include 'help.tpl.php';
				
		the_footer();
		return "";
	}); 
	
	$app->get('/help', function (Request $request) {
		global $hooks;
		
		$hooks->add_action('the_title',"helps_title");
		$hooks->add_action('global_css',"helps_css");
		$hooks->add_action('global_js',"helps_js");
		
		the_head();
		include 'help.tpl.php';
				
		the_footer();
		return "";
	}); 
	$app->post('/get-help', function (Request $request) {
		global $db;		
		$id = $request->get('id');
		include 'help.list.php';				
		return "";
	}); 
	$app->post('/send-help', function(Request $request) {		
		global $db;
		$user_id = $request->get('user_id');
		$text = $request->get('text');
		$db->bind("text", $text);
		// EXECUTE
		$row = $db->query("INSERT INTO notice_messages(message,chat_type,from_id) VALUES (:text,3,1)");
		$message_id = $db->lastInsertId();
		$db->bind("user_id", $user_id);
		$db->bind("message_id", $message_id);
		$row = $db->query("INSERT INTO notice_members(message_id,status,to_id) VALUES (:message_id,0,:user_id)");
		$id = $db->lastInsertId();
		$html .= '<li class="out" id="cc" data-id="'.$id.'">';
		$html .= '<br>';
		$html .= '<img class="avatar" alt="" src="'. showImage($user_id).'">';
		$html .= '<div class="message">';
		$html .= '<div class="desc">'.$text;
		$html .= '<br/><span class="datetime"><a href="javascript:;">'.($_SESSION['user_id'] == 1 ? "Bot" : getProfileData($_SESSION['user_id'], "first_name"))."</a> at ".date("H:i").'</span>'.'</div>';
		$html .= '</div>';
		$html .= '</li>';
		return $html;
	}); 
	
}
include 'help.func.php';