<?php
/**
 * Workshop module
 * 
 * Allow administrator to perform ajax actions 
 * 
 * @package linea21\modules\workshop
 * @author $Author$ - Simon Georget <simon@linea21.com>
 * @version $Id$ 
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

$noplugin = true; // flag for ../config/define.php file
include_once('../config/define.php');


include_once('../admin/mysql.inc.php');
include_once('../class/class.workshop_com.php');
include_once('../languages/' . U_L . '/lang_common.' . CHARSET . '.php');
include_once('../languages/' . U_L . '/lang_workshop.' . CHARSET . '.php');

$parameters = $_GET['parameters'];

$a = parse_url($parameters, PHP_URL_QUERY);
parse_str($a, $output);
$todo = strip_tags($output['todo']);
$id = strip_tags($output['id']);
$com_id = strip_tags($output['com_id']);
$mes_id = strip_tags($output['mes_id']);

if($com_id == $mes_id) $isroot = 'true';
else $isroot = 'false';

$workshop_com_object= new workshop_com;

//////////// Check Droits utilisateur ////////////
if ($l21auth->isWorkgroupOrganiser($l21auth->GetSessionElement('id'), $sql_object, $id)<>true && !$l21auth->isSuperAdmin() && $workshop_com_object->isComAuthor($mes_id, $l21auth->GetSessionElement('id'), $sql_object) == false)
ReloadIndex('admin');
////////////


if($todo == 'sup_com') {
	
	$r = $workshop_com_object->DeleteCom($id, $mes_id, $com_id, $GLOBALS['sql_object']);

	if($r) $msg = _t('workshop', 'confirm_sup_com'); // succeed
	else  $msg = _t('msg', 'action_failed'); // failed

}

if($r == true) {
  echo '{"status":1,"el": "#msg-'.$mes_id.'", "action": "'.$todo.'", "msg": "'.$msg.'", "isroot": "'.$isroot.'"}';
} else {
  echo '{"status":0,"el": "#msg-'.$mes_id.'", "action": "'.$todo.'", "msg": "'.$msg.'", "isroot": "'.$isroot.'"}';
}

?>