<?php
/*************************************************************************/
/* DOCEBO CORE - Framework                                               */
/* ============================================                          */
/*                                                                       */
/* Copyright (c) 2007                                                    */
/* http://www.docebo.org                                                 */
/*                                                                       */
/* This program is free software. You can redistribute it and/or modify  */
/* it under the terms of the GNU General Public License as published by  */
/* the Free Software Foundation; either version 2 of the License.        */
/*************************************************************************/

/**
 * This file contains function that tells in wich cases the
 * system should avoid to perform some core operations like
 * cleaning the HTML or replacing the site base url with the
 * {site_base_url} tag...
 */



/**
 * @param array 	$list array with the list of cases in wich we can skip
 *                          a certain operation for a specified field
 *                          The array format is platform ($sep) module name
 *                          ($sep) op ($sep) field name
 * @param string $field_name the name of the specified field to check
 *
 * @return bool true if we can skip the operation.
 */
function checkSkipList($list, $field_name, $name_modname="modname", $name_op="op") {
	$res =FALSE;
	$sep ="-||-";

	$platform =$GLOBALS["platform"];
	$modname ="";
	$op ="";

	if ((isset($_GET[$name_modname])) && (!empty($_GET[$name_modname]))) {
		$modname =$_GET[$name_modname];
	}

	if ((isset($_GET[$name_op])) && (!empty($_GET[$name_op]))) {
		$op =$_GET[$name_op];
	}

	if (in_array($platform.$sep.$modname.$sep.$op.$sep.$field_name, $list)) {
		$res =TRUE;
	}

	return $res;
}



function dontCleanHtml($field_name, $req_admin=TRUE) {
	$res =FALSE;
	$sep ="-||-";

	if($GLOBALS['current_user']->isAnonymous())
			return $res;
	$level_id = $GLOBALS['current_user']->getUserLevelId();

	if (($req_admin) && ($level_id != ADMIN_GROUP_GODADMIN) && ($level_id != ADMIN_GROUP_ADMIN)) {
		return $res;
	}

	$list =array();
	$list[]="framework".$sep."configuration".$sep."config".$sep."google_stat_code";

	$res =checkSkipList($list, $field_name);

	return $res;
}


function dontReplaceBaseUrl($field_name, $req_admin=TRUE) {
	$res =FALSE;
	$sep ="-||-";

	if($GLOBALS['current_user']->isAnonymous())
			return $res;
	$level_id = $GLOBALS['current_user']->getUserLevelId();

	if (($req_admin) && ($level_id != ADMIN_GROUP_GODADMIN) && ($level_id != ADMIN_GROUP_ADMIN)) {
		return $res;
	}

	$list =array();
	$list[]="framework".$sep."configuration".$sep."config".$sep."url";

	$res =checkSkipList($list, $field_name);

	return $res;
}


?>