Browse Source

Removing unused libraries #7120

Julio Montoya 11 years ago
parent
commit
de7c0eb471

+ 0 - 40
main/inc/lib/latex.inc.php

@@ -1,40 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html>
-<head>
-<title>LaTeX Code</title>
-</head>
-
-<body>
-<?php // $Id: latex.php,v 1.1 2006/04/05 07:18:46 pcool Exp $
-/* For licensing terms, see /license.txt */
-
-/*		INIT SECTION */
-
-include '../inc/global.inc.php';
-
-/*		FUNCTIONS */
-
-// put your functions here
-// if the list gets large, divide them into different sections:
-// display functions, tool logic functions, database functions
-// try to place your functions into an API library or separate functions file - it helps reuse
-
-/*		MAIN CODE */
-
-$code = Security::remove_XSS($_GET['code']);
-
-echo '<div id="latex_code">';
-echo '<h3>'.get_lang('LatexCode').'</h3>';
-echo stripslashes($code);
-echo '</div>';
-
-echo '<div id="latex_image">';
-echo '<h3>'.get_lang('LatexFormula').'</h3>';
-echo '<img src="'.api_get_path(WEB_COURSE_PATH).$_course['path'].'/temp/'.$code.'" alt="'.get_lang('LatexCode').'"/>';
-echo '</div>';
-
-/*		FOOTER */
-
-?>
-</body>
-</html>

+ 0 - 105
main/inc/lib/uri.class.php

@@ -1,105 +0,0 @@
-<?php
-
-/**
- * Utility functions to manage uris/urls.
- * 
- * @license see /license.txt
- * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
- */
-class Uri
-{
-    
-    public static function chamilo()
-    {
-        return 'http://chamilo.org/';
-    }
-
-    /**
-     * Application web root
-     */
-    public static function www()
-    {
-        static $result = false;
-        if (empty($result))
-        {
-            $result = api_get_path(WEB_PATH);
-        }
-        return $result;
-    }
-    
-    public static function here($params = array(), $html = true)
-    {
-        $protocol = Request::server()->server_protocol();
-        $protocol = stripos($protocol, 'https') !== false ? 'https' : 'http';
-        
-        $host = Request::server()->server_name();
-        $host = $host ? $host : Request::server()->server_addr();
-        
-        $here = Request::server()->request_uri();
-        $here = explode('?', $here);
-        $here = reset($here);
-        $here = $protocol . '://' . $host . $here;
-        return self::url($here, $params, $html);
-    }
-
-    /**
-     * Returns a full url from local/absolute path and parameters.
-     * Append the root as required for relative urls.
-     * 
-     * @param string $path
-     * @param array $params
-     * @return string 
-     */
-    public static function url($path = '', $params = array(), $html = true)
-    {
-        $result = $path;
-        if (strpos($result, 'http') !== 0)
-        {
-            $result = ltrim($result, '/');
-            $result = self::www() . $result;
-        }
-        if ($params)
-        {
-
-            $result = rtrim($result, '?');
-            $result = $result . '?' . self::params($params, $html);
-        }
-        return $result;
-    }
-
-    /**
-     * Format url parameters
-     * 
-     * @param array $params
-     * @return string
-     */
-    public static function params($params = array(), $html = true)
-    {
-        $result = array();
-        foreach ($params as $key => $value)
-        {
-            $result[] = $key . '=' . urlencode($value);
-        }
-        $result = implode($html ? '&amp;' : '&', $result);
-        return $result;
-    }
-
-    /**
-     * Returns the course parameters. If null default to the current user parameters.
-     * 
-     * @param string $course_code
-     * @param string|int $session_id
-     * @param string|int $group_id
-     * @return type 
-     */
-    public static function course_params($course_code = null, $session_id = null, $group_id = null)
-    {
-        $course_code = is_null($course_code) ? api_get_course_id() : $course_code;
-        $session_id = is_null($session_id) ? api_get_session_id() : $session_id;
-        $session_id = $session_id ? $session_id : '0';
-        $group_id = is_null($group_id) ? '' : $group_id;
-        $group_id = $group_id ? $group_id : '0';
-        return array('cidReq' => $course_code, 'id_session' => $session_id, 'gidReq' => $group_id);
-    }
-
-}

+ 0 - 552
main/inc/lib/xht.lib.php

@@ -1,552 +0,0 @@
-<?php /*                                                    <!-- xht.lib.php -->
-                                         <!-- XML HTML Templates, 2006/12/14 -->
-
-<!-- Copyright (C) 2006 rene.haentjens@UGent.be - see note at end of text    -->
-<!-- Released under the GNU GPL V2, see http://www.gnu.org/licenses/gpl.html -->
-
-*/
-
-/**
-*	This is an XML HTML template library.
-*	Include/require it in your code to use its functionality.
-*
-*   This library defines function xht_htmlwchars & class xhtdoc with methods:
-*   - xht_fill_template($template_name)
-*   - xht_substitute($subtext)
-*
-*   Check htt_error after defining a new xhtdoc(htt_file_contents).
-*
-*   Assign xht_xmldoc (, xht_get_lang, xht_resource, xht_dbgn)
-*   before calling the class methods.
-*
-*	@package chamilo.library
-*/
-
-
-
-function xht_htmlwchars($s)  // use only where ISO-8859-1 is not required!
-{
-    //return ereg_replace('\[((/?(b|big|i|small|sub|sup|u))|br/)\]', '<\\1>',
-    //    str_replace('@�@', '&',
-    //    htmlspecialchars(ereg_replace('&#([0-9]+);', '@�@#\\1;', $s))));
-	global $charset;
-    return api_ereg_replace('\[((/?(b|big|i|small|sub|sup|u))|br/)\]', '<\\1>',
-        str_replace('@�@', '&',
-        htmlspecialchars(api_ereg_replace('&#([0-9]+);', '@�@#\\1;', $s), ENT_QUOTES, $charset)));
-    // replaces htmlspecialchars for double-escaped xml chars like '&amp;#nnn;'
-    // and                       when html tags <...> are represented as [...]
-}
-
-function xht_is_assoclist($s) // ":key1:value1,, key2:value2,, ..."
-{
-    return is_string($s) && strpos($s, ',,');
-}
-
-function xht_explode_assoclist($s)
-{
-    $result = array(); if (!xht_is_assoclist($s)) return $result;
-
-    foreach (explode(',,', api_substr($s, 1)) as $keyplusvalue)
-        if ($cp = api_strpos($keyplusvalue, api_substr($s, 0, 1)))
-            $result[trim(api_substr($keyplusvalue, 0, $cp))] =
-                api_substr($keyplusvalue, $cp+1);
-
-    return $result;
-}
-
-
-class xhtdoc
-{
-
-var $htt_array;     // array with HTML templates
-var $htt_error;     // error while parsing htt_file_contents to templates
-
-var $xht_xmldoc;    // XML Mini-DOM document for which templates are processed
-var $xht_param;     // parameter array for template processing
-var $xht_get_lang;  // user-supplied function for {-L xx-}, e.g. Dokeos get_lang
-var $xht_resource;  // user-supplied function for '=/' in path
-
-var $xht_dbgn;      // set to a positive value for debugging output
-var $xht_dbgo;      // debugging output accumulates here
-
-var $_prev_param;   // old parameter values
-
-
-function xht_fill_template($template_name, $cur_elem = 0)
-{
-    $template_name = trim($template_name);
-    if (!$template_name || (api_strpos($template_name, ' ') !== FALSE)) return '';
-    if (!is_string($httext = $this->htt_array[$template_name]))     return '';
-
-    if ($this->xht_dbgn) $this->xht_dbgo .= '<!-- ' . XHT_LP . $template_name .
-            ' ' . XHT_RP . $this->_show_param() . " -->\n";
-
-    $prev_lpp = 0; $prev_sub = ''; $scanpos = 0;
-
-    while (($rpp = api_strpos($httext, XHT_RP, $scanpos)) !== FALSE)  // first -}
-    {
-        if (($lpp = api_strpos($httext, XHT_LP)) === FALSE) break;  // no {- for -}
-        if ($lpp > $rpp) break;  // no {- preceding -}
-
-        while (($next_lpp = api_strpos($httext, XHT_LP, $lpp + XHT_PL)) !== FALSE)
-            if ($next_lpp > $rpp) break;
-            else $lpp = $next_lpp;  // find {- closest to -}
-
-        $subtext = api_substr($httext, $lpp + XHT_PL, $rpp - $lpp - XHT_PL);
-
-        $httext = api_substr($httext, 0, $lpp) .
-            $this->xht_substitute($subtext, $cur_elem, XHT_LP, XHT_RP) .
-            api_substr($httext, $rpp + XHT_PL);  // substitute or leave intact
-
-        if ($lpp == $prev_lpp && $subtext == $prev_sub)  // prevent looping
-        {
-            $scanpos = $rpp + 1; $prev_lpp = 0; $prev_sub = '';
-        }
-        else
-        {
-            $prev_lpp = $lpp; $prev_sub = $subtext;
-        }
-    }
-
-    return $httext;
-}
-
-
-function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '')
-{
-	global $charset;
-
-	$regs = array(); // for use with ereg()
-    if (!api_ereg(XHT_SUBS2, $subtext, $regs) && !api_ereg(XHT_SUBS1, $subtext, $regs))
-        return $pre . $subtext . $post;
-
-    $type = $regs[1]; $text = $regs[2]; $result = ''; $subnum = FALSE;
-    $subtext = isset($regs[3]) ? $regs[3] : '';
-
-    if ($this->xht_dbgn)  // generate debugging output, with new number $subnum
-    {
-        $subnum = ++ $this->xht_dbgn;
-        $this->xht_dbgo .= '<!-- ' . XHT_LP . $type . $subnum . '+ ' .
-            htmlspecialchars($text, ENT_QUOTES, $charset) . ' ' . XHT_RP .
-            $this->_show_param() .  " -->\n";
-    }
-
-    if     ($type == 'D')  // Define, e.g. {-D key value-}
-    {
-        // Assign the value to parameter [key]
-        $this->xht_param[$text] = $subtext;
-        // used to be:          = $this->xht_substitute($subtext, $cur_elem);
-    }
-    elseif ($type == 'E')  // Escape, e.g. {-E userFunction subtext-}
-    {
-        $result = call_user_func($text, FALSE);  // get cached result, if any
-
-        if ($result === FALSE)  // no cached result available
-        {
-            $result = $this->xht_substitute($subtext, $cur_elem);
-            $result = call_user_func($text, $result);  // allow to cache
-        }
-    }
-    elseif ($type == 'R')  // Repeat, e.g. {-R general/title/string subtext-}
-    {
-        $rdepthn = 'rdepth' . (++ $this->xht_param['rdepth']);
-        $n = 0; $this->xht_param['number'] = '0';
-
-        if (is_array($a = $this->_lang($text, $cur_elem)))  // repeat on array
-        {
-            foreach ($a as $key => $value)
-            {
-                $this->xht_param['number'] = (string) (++ $n);
-                $this->xht_param[$rdepthn] = (string) ($n);
-                $this->xht_param['key'] = $key;
-                $this->xht_param['value'] = $value;
-                $result .= $this->xht_substitute($subtext, $cur_elem);
-            }
-        }
-        elseif (xht_is_assoclist($a))  // repeat on associative list
-        {
-            foreach (xht_explode_assoclist($a) as $key => $value)
-            {
-                $this->xht_param['number'] = (string) (++ $n);
-                $this->xht_param[$rdepthn] = (string) ($n);
-                $this->xht_param['key'] = $key;
-                $this->xht_param['value'] = $value;
-                $result .= $this->xht_substitute($subtext, $cur_elem);
-            }
-        }
-        elseif (!is_object($this->xht_xmldoc))
-        {
-            $result = '? R Error: no XML doc has been assigned to xht_xmldoc';
-        }
-        else  // repeat on XML elements
-        {
-            $sub_elems =
-                $this->xht_xmldoc->xmd_select_elements($text, $cur_elem);
-
-            foreach ($sub_elems as $subElem)
-            {
-                $this->xht_param['number'] = (string) (++ $n);
-                $this->xht_param[$rdepthn] = (string) ($n);
-                $result .= $this->xht_substitute($subtext, $subElem);
-            }
-        }
-        // removed 2004/10/05: template_array (security)
-        // added   2005/03/08: associative list (lang arrays deprecated)
-
-        $this->xht_param['rdepth'] --;
-
-        // As there is only one ['number'] or one set ['key'] + ['value'],
-        // using them in nested repeats may not have the desired result.
-    }
-    elseif ($type == 'T')  // Test, e.g. {-T key1 == key2 text-}
-    {
-        if (api_ereg('^(=|==|<=|<|!=|<>|>|>=) +([^ ]+) +(.*)$', $subtext, $regs))
-        {
-            // Comparand= parameter value if set, else languagevar value
-
-            $cmp1 = isset($this->xht_param[$text]) ?
-                $this->xht_param[$text] : $this->_lang($text, $cur_elem);
-            $cmp3 = isset($this->xht_param[$cmp3 = $regs[2]]) ?
-                $this->xht_param[$cmp3] : $this->_lang($cmp3, $cur_elem);
-            $cmp = strcmp($cmp1, $cmp3); $op = ' ' . $regs[1] . ' ';
-
-            if ($subnum) $this->xht_dbgo .= '<!-- ' . XHT_LP . $type . $subnum .
-                    '  ' . htmlspecialchars($cmp1.$op.$cmp3.' = '.$cmp, ENT_QUOTES, $charset) .
-                    ' ' . XHT_RP . " -->\n";  // debugging output
-
-            if (    ($cmp <  0  &&  api_strpos('  <= < != <> ', $op)) ||
-                    ($cmp == 0  &&  api_strpos('  = == <= >= ', $op)) ||
-                    ($cmp >  0  &&  api_strpos('  != <> > >= ', $op))   )
-                $result = $this->xht_substitute($regs[3], $cur_elem);
-            // else $result is empty
-        }
-        else
-        {
-            $result = $pre . $subtext . $post;
-        }
-    }
-    else
-    {
-        if (api_strpos('CLPVX', $type) !== FALSE)  // used to be always
-            $text = $this->xht_substitute($text, $cur_elem);  // nested escape
-
-        if     ($type == 'C') // Call, e.g. {-C SUBTEMPLATE-}
-                $result = $this->xht_fill_template($text, $cur_elem);
-        elseif ($type == 'H') $result = htmlspecialchars($text, ENT_QUOTES, $charset);
-        elseif ($type == 'L') $result = $this->_lang($text, $cur_elem);
-        elseif ($type == 'P') $result = $this->xht_param[$text];
-        elseif ($type == 'U') $result = urlencode($text);
-        elseif ($type == 'W') $result = xht_htmlwchars($text);
-        elseif (!is_object($this->xht_xmldoc))
-        {
-            $result = '? V/X Error: no XML doc has been assigned to xht_xmldoc';
-        }
-        else // $type == 'V' or 'X'
-        {
-
-            if (api_ereg('^(.*)=/(.+)$', $text, $regs))  // special resource-marker
-            {
-                $path = $regs[1]; $text = $regs[2];
-                if (api_substr($path, -1) == '/') $path = api_substr($path, 0, -1);
-
-                if ($path) $cur_elem = $this->xht_xmldoc->
-                    xmd_select_single_element($path, $cur_elem);
-
-                $cur_elem = call_user_func($this->xht_resource, $cur_elem);
-            }
-
-            $result = ($type == 'V') ?
-                $this->xht_xmldoc->xmd_value($text, $cur_elem) :
-                $this->xht_xmldoc->
-                    xmd_html_value($text, $cur_elem, 'xht_htmlwchars');
-        }
-    }
-
-    if ($subnum) $this->xht_dbgo .= '<!-- ' . XHT_LP . $type . $subnum . '- ' .
-            htmlspecialchars((api_strlen($result) <= 60) ?
-                $result . ' ': api_substr($result, 0, 57).'...', ENT_QUOTES, $charset) . XHT_RP . " -->\n";
-
-    return $result;
-}
-
-
-function xht_add_template($template_name, $httext)
-{
-    $this->htt_array[$template_name] = $httext;
-        // removed 2004/10/05: (substr($httext, 0, 6) == 'array(') ?
-        // removed 2004/10/05:     @eval('return ' . $httext . ';') : $httext;
-
-    if (!$this->htt_array[$template_name])
-    {
-        $this->htt_error = 'template ' . $template_name .
-        ' is empty or invalid'; return;
-    }
-}
-
-
-function xhtdoc($htt_file_contents)
-{
-    $htt_file_contents =  // normalize \r (Mac) and \r\n (Windows) to \n
-        str_replace("\r", "\n", str_replace("\r\n", "\n", $htt_file_contents));
-
-    while (api_substr($htt_file_contents, -1) == "\n")
-        $htt_file_contents = api_substr($htt_file_contents, 0, -1);
-
-    $last_line = api_strrchr($htt_file_contents, "\n"); $this->htt_error = '';
-
-    if (api_strlen($last_line) < 12 || api_substr($last_line, 0, 6) != "\n<!-- "
-        || api_strlen($last_line) % 2 != 0 || api_substr($last_line, -4) != " -->")
-    {
-        $this->htt_error = 'last line must be of the form <!-- {--} -->';
-        return;
-    }
-
-    define('XHT_PL', (int) (api_strlen($last_line) - 10) / 2);    // Parentheses Lth
-    define('XHT_LP', api_substr($last_line, 6, XHT_PL));          // Left Par
-    define('XHT_RP', api_substr($last_line, 6 + XHT_PL, XHT_PL)); // Right Par
-
-    if (XHT_LP == XHT_RP)
-    {
-        $this->htt_error =
-            'parentheses in last line <!-- {--} --> must not be identical';
-        return;
-    }
-
-    $this->htt_array = array();  // named elements are arrays and strings
-
-    foreach (explode("\n<!-- " . XHT_LP, "\n" . $htt_file_contents)
-            as $name_and_text)
-    {
-        if (($name_length = api_strpos($name_and_text, XHT_RP . " -->\n")))
-        {
-            $template_name = trim(api_substr($name_and_text, 0, $name_length));
-
-            if (api_strpos($template_name, ' ') !== FALSE) give_up('Template ' .
-                $template_name . ' has a space in its name');
-            $httext = api_substr($name_and_text, $name_length + XHT_PL + 5);
-
-            while (api_substr($httext, 0, 1) == "\n") $httext = api_substr($httext, 1);
-            while (api_substr($httext, -1) == "\n") $httext = api_substr($httext,0,-1);
-
-            $this->xht_add_template($template_name, $httext);
-        }
-    }
-
-    define('XHT_SUBS1', '^(C|H|L|P|U|V|W|X) +(.*)$');   // substitution types 1:
-    // Call, Htmlchars, Lang, Param, Urlencode, Value, Wchars, Xvalue
-    define('XHT_SUBS2', '^(D|E|R|T) +([^ ]+) +(.*)$');  // substitution types 2:
-    // Define, Escape, Repeat, Test
-
-    $this->xht_dbgo = '';
-
-    $this->xht_param = array(0 => '0', 1 => '1',
-        '' => '', 'empty' => '', 'rdepth' => 0);
-    $this->_prev_param = $this->xht_param;
-    // empty:  {-R * P empty-} puts the number of subelements in {-P number-}
-    // rdepth: current number of nested R's
-    // rdepth1, rdepth2, ...: key or number, see R
-}
-
-
-function _show_param()  // for debugging info
-{
-	global $charset;
-    $result = '';
-    foreach ($this->xht_param as $k => $v)
-        if ($v !== $this->_prev_param[$k]) {
-            $this->_prev_param[$k] = $v; $result .= ', ' . $k . ': ' .
-                ((api_strlen($v) <= 20) ? $v : api_substr($v, 0, 17).'...');
-        }
-    return $result ? htmlspecialchars(api_substr($result, 1), ENT_QUOTES, $charset) : '';
-}
-
-function _lang($var, $cur_elem = 0)
-{
-    $result = @call_user_func($this->xht_get_lang, $var, $cur_elem);
-
-	// This is a hack for proper working of the language selectors
-	// in the forms that are generated through templates.
-	if ($var == 'Langs')
-    {
-    	global $langLangs;
-    	if (isset($langLangs))
-    	{
-    		$result = $langLangs;
-    	}
-    }
-
-    return isset($result) ? $result : $var;
-}
-
-
-}
-
-/*
-
-A word of explanation...
-
-The last line of a template file (example below) defines the special markers
-that are used around template names such as INPUT and OPTION and around HTML
-escapes such as 'P value' and 'L Store', { and } in the example. You can also
-use markers of more than one character as long as both have the same length,
-e.g. <% and %>. The markers must not be equal. In templates with JavaScript
-or <style>, the use of { and } might be confusing; however, it does work.
-
-A template starts with a special comment line giving the name of the template
-and ends where the next template starts.
-
-Templates contain escapes of the form {one-letter the-rest}, e.g.
-{L IdentifierTip}, where the-rest can contain a nested-escape as in e.g.
-{R metadata/lom/general/keyword C KEYWORDTEMPLATE}.
-
-Multiple spaces count as one in many places, but not in all. Best is to use
-correct spacing. In particular, a T escape such as the example below requires
-a space at the end of the first line:
-{T x == y
-text
-}
-
-Names (of templates, parameters, langvars and user-functions)
-are case sensitive and cannot contain spaces.
-
-Templates are called with a certain currency in the XML doc, usually the root
-element; for an xml-path repeat, the found element is the current one.
-
-One single array with named elements and string values contains the
-template parameters; they are shared for all template processing.
-
-Initially, params contains
-    0 => '0', 1 => '1', '' => '', 'empty' => '', 'rdepth' => 0.
-rdepth keeps track of the current number of nested repeats. In a repeat,
-params number, key, value and rdepthN (N is 1, 2, ...) get assigned values.
-
-Types of escapes:
-
-C template-name/nested-escape   Call a sub-template
-D parameter-name text           Define a parameter value
-E user-function nested-escape   Escape to user-function or do nested-escape
-H text                          HtmlSpecialChars (e.g. transform < to &lt;)
-L languagevar/nested-escape     Language variable value (see also below)
-P parameter-name/nested-escape  Parameter value
-R repeat-part nested-escape     Repeat nested-escape for each ... (see below)
-T key1 operator key2 nested-esc Test, do nested-esc if test succeeds (id.)
-U text                          UrlEncode (e.g. transform < to %XX)
-V xml-path/nested-escape        Value from XML document element or attribute
-W text                          xht_htmlwchars (see below)
-X extended-xml-path/nested-esc  eXtended Value from XML (see below)
-
-nested-escape= without the special markers. Nesting with special markers is
-    always possible and in that case the inner nesting is evaluated first.
-    Note that as from the 2005/03/15 version, some implicit nestings are no
-    longer possible, e.g. {H {P key}} and {D label {L Keyword}} now require
-    the inner markers.
-
-Escape allows the caller to cache template output:
-    user-function is called with parameter (FALSE);
-    if it returns a string, that string is the result;
-    if it returns FALSE, nested-escape is executed to produce a result
-    and user-function is called again with the result, allowing it
-    to cache the result somewhere; user-function then returns the real result.
-
-repeat-part can be:
-    the name of a languagevar which contains an associative list such as:
-        ":key1:value1,, key2:value2,, key3:value3" (note double ,,):
-        nested-escape is repeated for each list element,
-        params 'key' and 'value' refer to the current element;
-        first character defines key-value-separator (here a colon);
-        key cannot contain key-value-separators and is trimmed;
-        value can contain anything except ,, and it is not trimmed;
-        put ',,' at the end of a 0- or 1-element-list.
-    the name of a languagevar which has an array value:
-        nested-escape is repeated for each array element,
-        params 'key' and 'value' refer to the current element.
-    an xml-path to 0, 1 or more elements in the XML document:
-        nested-escape is repeated for each element, param 'number' = 1, 2, ...
-
-test operators compare strings: = ==  <=  <  !=  <>  >  >=
-    key1 and key2 can be parameter-name or languagevar-name.
-
-xml-path: see XML Mini-DOM; examples:
-    organizations/@default, body/p[1] (1=first), keyword/*, node/*[-3]
-    / * /... starts from XML document root, regardless of context
-    other extensions: .. - + @* @. (parent, prev, next, number, name)
-    .. stops at the root if too many
-    -name, +name and @*name means only elements of that name
-
-xht_htmlwchars is like HtmlSpecialChars, but moreover translates:
-    [b] to <b>, likewise for big, i, small, sub, sup, u, br, and closing tags;
-    &amp;#nnn; to &#nnn; (double-escape for non-UTF8-channels)
-
-eXtended Value: see method xmd_html_value of the XML Mini-DOM;
-    the values (but not the pre-, in- and suffixes) are always W-processed;
-    extended-xml-path examples:
-    'keyword/string ,'            generates e.g. 'kwd1,kwd2,kwd3'
-    'keyword/string , '           generates e.g. 'kwd1, kwd2, kwd3'
-    '( -% keyword/string ,  %- )' generates e.g. '(kwd1,kwd2,kwd3)'
-        but will generate nothing if no keywords are found in the XML doc;
-        note that the special markers ' -% ' and ' %- ' must have the spaces.
-
-V and X escapes can have an xml-path containing '=/': this calls a user-supplied
-function for finding an associated element. It can e.g. be used when reading
-a SCORM manifest, for finding the <resource> of an <item>.
-
-L also calls a user-supplied function. Its main target is language-dependent
-texts, e.g. Dokeos 'get_lang'. But the current element is passed as second
-argument, allowing other functionality in the callback.
-
-Array templates functionality has been removed on 2004/10/05, because of a
-security issue when users can submit templates.
-
---------------------------------------------------------------------------------
-
-Example template file:
-
-<!-- {HEAD} -->
-<style type="text/css">
-    body    {font-family: Arial}
-</style>
-
-<!-- {METADATA} -->
-<h3>{H {L Tool}: {P entry}}</h3>
-<table>
-    <tr>
-        <td>{D label {L Language}}{D tip {L LanguageTip}}{C LABEL}</td>
-        <td><select>{D thislang {V general/language}}{R Langs C OPTION}</select></td>
-        <td><input type="text" disabled value="urn:ugent-be:minerva."/></td>
-    </tr>
-{R general/keyword C KEYWORD}
-</table>
-
-<!----------------------  E-n-d Of script Output  ---------------------->
-
-<!-- {LABEL} -->
-<span title="{H {P tip}}">{H {P label}}&#xa0;:</span>
-<!-- {OPTION} -->
-<option value="{H {P key}}" {T key == thislang selected}>{H {P value}}</option>
-<!-- {INPUT} -->
-<input type="text" title="{P title}" class="wide" value="{H {P value}}"/>
-<!-- {KEYWORD} -->
-<tr>
-    <td>{D label {L Keyword}}{D tip {L KeywordTip}}{C LABEL}</td>
-    <td nowrap><select>{D thislang {V string/@language}}{R Langs C OPTION}</select></td>
-    <td>{D value {X string}}{D title general/keyword[{P number}]/string}{C INPUT}</td>
-</tr>
-<!-- {} -->
-
---------------------------------------------------------------------------------
-
-<!--
-    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, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-  -->
-*/
-
-?>

+ 0 - 883
main/inc/lib/xmd.lib.php

@@ -1,883 +0,0 @@
-<?php /*                                                    <!-- xmd.lib.php -->
-                                                <!-- XML MiniDom, 2006/12/13 -->
-
-<!-- Copyright (C) 2005 rene.haentjens@UGent.be - see note at end of text    -->
-<!-- Released under the GNU GPL V2, see http://www.gnu.org/licenses/gpl.html -->
-
-*/
-
-/**
-*	This is the XML Dom library for Dokeos.
-*	Include/require it in your code to use its functionality.
-*
-*	@author René Haentjens
-*	@package chamilo.library
-*/
-
-class xmddoc
-{
- /* This MiniDom for XML essentially implements an array of elements, each
-    with a parent, a name, a namespace-URI, attributes & namespace definitions,
-    and children. Child nodes are a mix of texts and subelements. Parent
-    and subelements are stored as elementnumbers, the root is element 0.
-
-    Parsing is built on James Clark's expat, by default enabled in PHP.
-
-    The MiniDom is an alternative to the experimental DOM XML functions.
-    It is open source PHP and requires no extra libraries.
-
-    Restrictions of the MiniDom:
-    - no two attributes with same name (different namespaces) on one element;
-    - only 'ISO-8859-1' right now; author will investigate 'UTF-8' later;
-    - processing instructions & external entities are ignored;
-    - no distinction between text and cdata child nodes;
-    - xmd_xml(nonrootelement) may not generate all needed namespace definitions;
-    - xmd_value, xmd_html_value, xmd_select_xxx, xmd_update, xmd_update_many:
-      path parameter uses names without namespaces
-      and supports only a small subset of XPath, with some extensions;
-    - maximum 11 auto-generated namespace prefixes (can be changed in xmddoc)
-
-    Namespace definitions are stored as attributes, with name = 'xmlns...'
-    e.g. xmlns:xml='http://www.w3.org/XML/1998/namespace'
-    e.g. xmlns='http://www.imsglobal.org/xsd/imscp_v1p1' (default namespace)
-
-    Exposed methods:
-
-    new xmddoc(array_of_strings, charset = 'ISO-8859-1'): parse strings
-    new xmddoc(names, numbers, textstring): restore from cached arrays & string
-
-    xmd_add_element(complete_name, parent, attributes_with_complete_names)
-        complete name = [ URI + ':' + ] name
-    xmd_set_attribute(element, complete_attribute_name, value) (id. as above)
-    xmd_add_text(text, element)
-    xmd_add_text_element(complete_name, text, parent, attributes) =
-        xmd_add_text(text, xmd_add_element(complete_name, parent, attributes))
-
-    xmd_get_element(element) => children, attributes, '?name', '?parent'
-    xmd_get_ns_uri(element [, attribute_name_without_uri] )
-
-    xmd_text(element): combines element and subelements' text nodes
-    xmd_xml(): generate XML-formatted string (reverse parsing)
-    xmd_xml(indent_increase, initial_indent, lbr): e.g. '  ', '', "\n"
-
-    xmd_value(path): follow path from root, return attribute value or text
-        e.g. 'manifest/organizations/@default' 'body/p[1]' (1=first, -1=last)
-    xmd_value(path, parent, fix, function): find value(s) with path from parent,
-        apply function and decorate with fix = ('pre'=>..., 'in'=>..., 'post')
-        e.g. 'general/title/*' array('in' => ', ')
-    extensions to XPath:
-        -  and  +  for previous and next sibling, e.g. general/title/+/string
-        -name and +name for sibling with specific name, e.g. item[2]/+item
-        .. for parent, e.g. general/title/../../technical/format (stops at root)
-        @* for location (element number within siblings, starts at 1)
-        @*name for location in siblings with specific name
-        @. for element name, e.g. organization/*[1]/@.
-    namespaces are not supported in paths: they use names without URI
-
-    xmd_html_value(pathFix, parent, fun): 'path' 'path infix' 'prefix -% path'
-        'path infix %- postfix': fun = 'htmlspecialchars' by default
-
-    xmd_select_elements(path, parent): find element nodes with path (see above)
-    xmd_select_single_element (id.) returns -1 or elementnumber
-    xmd_select_elements_where(path, subpath, value, parent): e.g. '@id', '12'
-        is like XPath with path[@id='12']; subpath = '.' means text
-    xmd_select_elements_where_notempty(path, subpath, parent): e.g. '@id'
-    xmd_select_xxx methods only select elements, not attributes
-
-    xmd_remove_element(childelement_number)
-    xmd_remove_nodes(childelement_numbers_and_strings, parent)
-
-    xmd_update(path, text, parent): select single element, then:
-        text element:     replace text by new text
-        attribute:        give attribute new value = text
-        somepath/!newtag: create new child element containing text
-        somepath/~:       delete single (first or only) element
-    xmd_update_many(paths, subpath, ...): paths can be path1,path2,...:
-        for all elements selected by all paths, update with subpath
-
-    xmd_copy_foreign_child(fdoc, child, parent):
-        copies fdoc's child as a new child of parent;
-        note this method hasn't been tested for all cases (namespaces...)
-
-    xmd_cache(): dump xmddoc into names+numbers+textstring for serialization
-
-    Order of parameters (if present) for xmd_xxx methods:
-        name, text, children, path, subPath, value,
-            parent, fix, fun, attributes (name value)
-
-
-    Properties: (G)lobal to xmddoc or array (one for each xmddoc (E)lement)
-
-    e.g. $this->name[0] is the name of the document root element
-    e.g. $this->names[$this->ns[0]] is its namespace URI
-    e.g. $this->attributes[0]['title'] is the value of its attribute 'title'
-    e.g. $this->attributes[0]['xmlns:a'] is the URI for prefix 'a:'
- */
-
-    var $names;         //G array: n => namespace URI (0 => '')
-    var $numbers;       //G array: numeric dump of xmddoc for caching
-    var $textstring;    //G string: string dump of xmddoc for caching
-    var $error;         //G string: empty or parsing error message
-    var $_nesting;      //G array: nested elements while parsing (internal)
-    var $_ns;           //G array: namespace defs for upcoming element (id.)
-    var $_concat;       //G bool: concatenate cData with previous (id.)
-    var $_nsp;          //G array: namespace prefixes in use somewhere (id.)
-    var $_last;         //G int: last used elementnumber (id.)
-    var $_strings;      //G int: number of string child nodes cached (id.)
-
-    var $parent;        //E int: elementnumber: 0 is root, -1 is parent of root
-    var $name;          //E string: element name, without namespace
-    var $ns;            //E int: index into $names to find namespace URI
-    var $attributes;    //E array: attribute name(without namespace) => value
-    var $atns;          //E array: attribute name(id.) => index into $names
-    var $children;      //E array: elementnumbers and strings (text children)
-
-
-    function xmd_get_element($parent = 0)  // for convenience, readonly copy
-    {
-        // returns mixed array: children + texts have numeric key,
-        // other elements are attributes, '?name' and '?parent'
-
-        if ($parent < 0 || $parent > $this->_last) return array();
-
-        return array_merge($this->children[$parent], $this->attributes[$parent],
-            array('?name' => $this->name[$parent],
-                '?parent' => $this->parent[$parent]));
-    }
-
-
-    function xmd_get_ns_uri($parent = 0, $attName = '')
-    {
-        if ($parent < 0 || $parent > $this->_last) return '';
-
-        return $attName ? $this->names[$this->atns[$parent][$attName]] :
-            $this->names[$this->ns[$parent]];
-    }
-
-
-    function xmd_remove_element($child)  // success = TRUE
-    {
-        if ($child <= 0 || $child > $this->_last) return FALSE;
-
-        $parent = $this->parent[$child];
-
-        foreach ($this->children[$parent] as $key => $value)
-            if ($value === $child)
-            {
-                unset($this->children[$parent][$key]); return TRUE;
-            }
-
-        return FALSE;
-    }
-
-
-    function xmd_remove_nodes($children, $parent = 0)  // success = TRUE
-    {
-        if ($parent < 0 || $parent > $this->_last) return FALSE;
-
-        if (!is_array($children)) $children = array($children);
-
-        foreach ($children as $child)
-        {
-            $childFound = FALSE;
-            foreach ($this->children[$parent] as $key => $value)
-                if ($value === $child)
-                {
-                    unset($this->children[$parent][$key]);
-                    $childFound = TRUE; break;
-                }
-            if (!$childFound) return FALSE;
-        }
-
-        return TRUE;
-    }
-
-
-    function xmd_update($xmPath, $text = '', $parent = 0)  // success = TRUE
-    {
-        if ($parent < 0 || $parent > $this->_last ||
-                !is_string($text) || !is_string($xmPath)) return FALSE;
-
-        $m = array();
-        if (api_ereg('^(.*)([~!@])(.*)$', $xmPath, $m))  // split on ~ or ! or @
-        {
-            $xmPath = $m[1]; $op = $m[2]; $name = $m[3];
-        }
-
-        if (($elem = $this->xmd_select_single_element($xmPath, $parent)) == -1)
-            return FALSE;
-
-        if (isset($op))
-        {
-            if     ($op == '!' && $name)
-            {
-                $this->xmd_add_text_element($name, $text, $elem); return TRUE;
-            }
-            elseif ($op == '@' && $name)
-            {
-                $this->attributes[$elem][$name] = $text; return TRUE;
-            }
-            elseif ($op == '~' && !$name)
-                return $this->xmd_remove_element($elem);
-
-            return FALSE;
-        }
-
-        if (($nch = count($this->children[$elem])) > 1) return FALSE;
-
-        $this->children[$elem][0] = $text; return TRUE;
-    }
-
-
-    function xmd_update_many($xmPaths, $subPath = '', $text = '', $parent = 0)
-    {
-        $result = TRUE;
-
-        foreach (explode(',', $xmPaths) as $xmPath)
-        foreach ($this->xmd_select_elements($xmPath, $parent) as $elem)
-            $result &= $this->xmd_update($subPath, $text, $elem);
-            // '&=' always evaluates rhs, '&&=' skips it if $result is FALSE
-
-        return $result;
-    }
-
-
-    function xmd_copy_foreign_child($fdoc, $fchild = 0, $parent = 0)
-    {
-        $my_queue = array($fchild, $parent);  // optimization, see below
-
-        while (!is_null($fchild = array_shift($my_queue)))
-        {
-            $parent = array_shift($my_queue);
-
-            if (is_string($fchild))
-                $this->xmd_add_text($fchild, $parent);
-
-            elseif (isset($fdoc->name[$fchild]))
-            {
-                $fullname = $fdoc->name[$fchild];
-                $attribs = array(); $nsdefs = array();
-
-                if (($nsn = $fdoc->ns[$fchild]))
-                    $fullname = $fdoc->names[$nsn] . ':' . $fullname;
-
-                foreach ($fdoc->attributes[$fchild] as $name => $value)
-                {
-                    if (($p = strrpos($name, ':')) !== FALSE)  // 'xmlns:...'
-                        $nsdefs[$name] = $value;
-
-                    else
-                    {
-                        if (($nsn = $fdoc->atns[$fchild][$name]))
-                            $name = $fdoc->names[$nsn] . ':' . $name;
-                        $attribs[$name] = $value;
-                    }
-                }
-
-                $child = $this->xmd_add_element($fullname, $parent,
-                    array_merge($attribs, $nsdefs));
-
-                foreach ($fdoc->children[$fchild] as $ch)
-                    array_push($my_queue, $ch, $child);
-                // recursive call was 10 times slower...
-            }
-        }
-    }
-
-
-    function xmd_add_element($name, $parent = 0, $attribs = array())
-    {
-        if (!is_string($name) || $name == '') return -1;
-
-        if (($p = strrpos($name, ':')) !== FALSE)  // URI + ':' + name
-            if ($p == 0 || $p == api_strlen($name) - 1) return -1;
-
-        $child = ($this->_last += 1); $uris = array(); $uri = '';
-
-        if ($p)
-        {
-            $uri = api_substr($name, 0, $p); $name = api_substr($name, $p + 1);
-            $uris[] = $uri;  // check uris after defining all attributes
-        }
-
-        $this->parent[$child] = $parent; $this->name[$child] = $name;
-        $this->ns[$child] = $uri ? $this->_lookup($uri) : 0;
-        $this->children[$child] = array();
-
-        $this->attributes[$child] = array(); $this->atns[$child] = array();
-
-        foreach ($attribs as $name => $value)
-            if (($uri = $this->xmd_set_attribute($child, $name, $value, FALSE)))
-                $uris[] = $uri;  // check at end, not immediately
-
-        if ($parent >= 0 && $parent <= $this->_last)
-            $this->children[$parent][] = $child;  // link to parent
-
-        foreach ($uris as $uri) $this->_nsPfx($child, $uri);
-        // find prefix (child and upwards) or create new prefix at root
-
-        return $child;
-    }
-
-
-    function xmd_set_attribute($parent, $name, $value, $checkurihaspfx = TRUE)
-    {
-        if (!is_string($name) || $name == '') return '';
-
-        if (($p = strrpos($name, ':')) !== FALSE)  // URI + ':' + name
-            if ($p == 0 || $p == api_strlen($name) - 1) return '';
-
-        $uri = '';  // beware of 'xmlns...', which is a namespace def!
-
-        if ($p) if (api_substr($name, 0, 6) != 'xmlns:')
-        {
-            $uri = api_substr($name, 0, $p); $name = api_substr($name, $p + 1);
-        }
-        $this->attributes[$parent][$name] = $value;
-        $this->atns[$parent][$name] = $uri ? $this->_lookup($uri) : 0;
-        if ($checkurihaspfx) if ($uri) $this->_nsPfx($parent, $uri);
-
-        if (api_substr($name, 0, 6) == 'xmlns:')  // namespace def with prefix
-            $this->_nsp[api_substr($name, 6)] = $value;  // prefix is in use
-
-        return $uri;
-    }
-
-
-    function xmd_add_text($text, $parent = 0)  // success = TRUE
-    {
-        if ($parent < 0 || $parent > $this->_last || !is_string($text))
-            return FALSE;
-
-        if ($text) $this->children[$parent][] = $text; return TRUE;
-    }
-
-
-    function xmd_add_text_element($name, $text, $parent = 0, $attribs = array())
-    {
-        $this->xmd_add_text($text,
-            $child = $this->xmd_add_element($name, $parent, $attribs));
-
-        return $child;
-    }
-
-
-    function xmd_text($parent = 0)
-    {
-        if ($parent < 0 || $parent > $this->_last) return '';
-
-        $text = '';  // assemble text subnodes and text in child elements
-
-        foreach ($this->children[$parent] as $child)
-            $text .= is_string($child) ? $child : $this->xmd_text($child);
-
-        return $text;
-    }
-
-
-    function xmd_xml($increase = '  ', $indent = '', $lbr = "\n", $parent = 0)
-    {
-		global $charset;
-
-        if ($parent < 0 || $parent > $this->_last) return '';
-
-        $uri = $this->names[$this->ns[$parent]];
-        $pfxc = ($uri == '') ? '' : $this->_nsPfx($parent, $uri);
-
-        $dbg = '';  // ($uri == '') ? '' : (' <!-- ' . $uri . ' -->');
-
-        $result = $indent . '<' . ($element = $pfxc . $this->name[$parent]);
-
-        $atnsp = $this->atns[$parent];
-
-        foreach ($this->attributes[$parent] as $name => $value)
-        {
-            if (isset($atnsp[$name]))
-            	$atnsn = $atnsp[$name];
-            elseif (isset($atnsn))
-            	unset($atnsn);
-            $uri = isset($atnsn) && isset($this->names[$atnsn]) ?
-                $this->names[$atnsn] : '';
-            $pfxc = ($uri == '') ? '' : $this->_nsPfx($parent, $uri);
-            $result .= ' ' . $pfxc . $name
-                . '="' . htmlspecialchars($value, ENT_QUOTES, $charset) . '"';
-        }
-
-        if (count($this->children[$parent]) == 0)
-            return $result . ' />' . $dbg;
-
-        $result .= '>';
-
-        foreach ($this->children[$parent] as $child)
-            $result .= is_string($child) ? htmlspecialchars($child, ENT_QUOTES, $charset) : ($lbr .
-                $this->xmd_xml($increase, $indent.$increase, $lbr, $child));
-
-        if (!is_string($child)) $result .= $lbr . $indent;  // last $child
-
-        return $result . '</' . $element . '>' . $dbg;
-    }
-
-
-    function xmd_value($xmPath, $parent = 0, $fix = array(), $fun = '')
-    {
-        // extensions:  @*[name] for element position (starts at 1)
-        //              @. for element (tag)name
-
-        if ($parent < 0 || $parent > $this->_last || !is_string($xmPath))
-            return '';
-
-        if (($p = strrpos($xmPath, '@')) !== FALSE)
-        {
-            $attName = api_substr($xmPath, $p+1); $xmPath = api_substr($xmPath, 0, $p);
-        }
-
-        if (!($elems = $this->xmd_select_elements($xmPath, $parent))) return '';
-
-        $result = ''; $fixin = isset($fix['in']) ? $fix['in'] : '';
-
-        foreach ($elems as $elem)
-        {
-            $value = isset($attName) && api_strlen($attName) >= 1 ?
-                ($attName == '.' ? $this->name[$elem] :
-                    ($attName{0} == '*' ?
-                        $this->_sibnum($elem, api_substr($attName, 1)) :
-                        $this->attributes[$elem][$attName])) :
-                $this->xmd_text($elem);
-            $result .= $fixin . ($fun ? $fun($value) : $value);
-        }
-
-        return  (isset($fix['pre']) ? $fix['pre'] : '') .
-                api_substr($result, api_strlen($fixin)) .
-                (isset($fix['post']) ? $fix['post'] : '');
-    }
-
-
-    function xmd_html_value($xmPath, $parent = 0, $fun = 'htmlspecialchars')
-    {
-        if (!is_string($xmPath)) return '';
-
-        $fix = array();
-
-        if (($p = api_strpos($xmPath, ' -% ')) !== FALSE)
-        {
-            $fix['pre'] = api_substr($xmPath, 0, $p);
-            $xmPath = api_substr($xmPath, $p+4);
-        }
-        if (($p = api_strpos($xmPath, ' %- ')) !== FALSE)
-        {
-            $fix['post'] = api_substr($xmPath, $p+4);
-            $xmPath = api_substr($xmPath, 0, $p);
-        }
-        if (($p = api_strpos($xmPath, ' ')) !== FALSE)
-        {
-            $fix['in'] = api_substr($xmPath, $p+1);
-            $xmPath = api_substr($xmPath, 0, $p);
-        }
-
-        return $this->xmd_value($xmPath, $parent, $fix, $fun);
-    }
-
-
-    function xmd_select_single_element($xmPath, $parent = 0)  // for convenience
-    {
-        $elements = $this->xmd_select_elements($xmPath, $parent);
-        if (count($elements) == 0) return -1;
-        return $elements[0];
-    }
-
-
-    function xmd_select_elements_where($xmPath,
-            $subPath = '.', $value = '', $parent = 0)
-    {
-        if (!is_string($subPath)) return array();
-
-        $elems = array(); if ($subPath == '.') $subPath = '';
-
-        foreach ($this->xmd_select_elements($xmPath, $parent) as $elem)
-            if ($this->xmd_value($subPath, $elem) == $value) $elems[] = $elem;
-
-        return $elems;
-    }
-
-
-    function xmd_select_elements_where_notempty($xmPath,
-            $subPath = '.', $parent = 0)
-    {
-        if (!is_string($subPath)) return array();
-
-        $elems = array(); if ($subPath == '.') $subPath = '';
-
-        foreach ($this->xmd_select_elements($xmPath, $parent) as $elem)
-            if ($this->xmd_value($subPath, $elem)) $elems[] = $elem;
-
-        return $elems;
-    }
-
-
-    function xmd_select_elements($xmPath, $parent = 0)
-    {
-        // XPath subset:    e1/e2/.../en, also * and e[n] and *[n] (at 1 or -1)
-        //                  /*/... starts from root, regardless of $parent
-        // extensions:      e= - or + (previous & next sibling)
-        //                  e= -name or +name (sibling of specific name)
-        //                  e= .. (stops at root, so too many doesn't matter)
-
-        if (api_substr($xmPath, 0, 3) == '/*/')
-        {
-            $xmPath = api_substr($xmPath, 3); $parent = 0;
-        }
-
-        if ($parent < 0 || $parent > $this->_last) return array();
-
-        while (api_substr($xmPath, 0, 1) == '/') $xmPath = api_substr($xmPath, 1);
-        while (api_substr($xmPath, -1) == '/')   $xmPath = api_substr($xmPath, 0, -1);
-
-        if ($xmPath == '' || $xmPath == '.') return array($parent);
-
-        if ($xmPath == '..')
-        {
-            if ($parent > 0) return array($this->parent[$parent]);
-            return array($parent);
-        }
-
-        if ($xmPath{0} == '-' || $xmPath{0} == '+')
-        {
-            $sib = $this->_sibnum($parent, api_substr($xmPath, 1), $xmPath{0});
-            if ($sib == -1) return array(); return array($sib);
-        }
-
-        $m = array();
-        if (api_ereg('^(.+)/([^/]+)$', $xmPath, $m))  // split on last /
-        {
-            if (!($set = $this->xmd_select_elements($m[1], $parent)))
-                return $set;  // which is empty array
-            if (count($set) == 1)
-                return $this->xmd_select_elements($m[2], $set[0]);
-
-            $bigset = array(); $m2 = $m[2];
-            foreach ($set as $e)
-                $bigset = array_merge($bigset,
-                    $this->xmd_select_elements($m2, $e));
-            return $bigset;
-        }
-
-        $xmName = $xmPath; $xmNum = 0; $elems = array();
-
-        if (api_ereg('^(.+)\[(-?[0-9]+)\]$', $xmPath, $m))
-        {
-            $xmName = $m[1]; $xmNum = (int) $m[2];
-        }
-
-        foreach ($this->children[$parent] as $child) if (!is_string($child))
-            if ($xmName == '*' || ($this->name[$child]) == $xmName)
-                $elems[] = $child;
-
-        if ($xmNum == 0) return $elems;
-
-        $xmNum = ($xmNum > 0) ? $xmNum - 1 : count($elems) + $xmNum;
-
-        return ($xmNum < count($elems)) ? array($elems[$xmNum]) : array();
-    }
-
-    // Notes on parsing and caching:
-    // - parsing 388 KB -> 0.94 sec
-    // - caching 298 KB <- 1.63 sec: 11387 elements, 5137 string nodes
-    // - uncache 298 KB -> 0.42 sec
-    // - $this->children[$n][] in a loop is quicker than a temporary array
-    //   $children[] and copying $this->children[$n] = $children after the loop
-    // - incremental operator ++$numptr is not quicker than ($numptr += 1)
-    // - numbers & textstring: more compact with base64_encode(gzcompress())
-
-    function xmd_cache()  // store all data in numbers+names+textstring
-    {
-        $this->numbers = array(); $this->textstring = ''; $this->_strings = 0;
-        // add all element- and attributenames to names - see below
-
-        for ($n = 0; $n <= $this->_last; $n++)
-        {
-            $this->numbers[] = count($this->children[$n]);
-
-            foreach ($this->children[$n] as $ch)
-            {
-                if (is_string($ch))
-                {
-                    $this->numbers[] = 0; $this->_strings += 1;
-                    $this->numbers[] = strlen($ch); $this->textstring .= $ch; //!!! Here strlen() has not been changed to api_strlen(). To be investigated. Ivan Tcholakov, 29-AUG-2008.
-                }
-                else
-                {
-                    $this->numbers[] = ($ch-$n);  // more compact than $ch
-                }
-            }
-
-            $this->numbers[] = count($this->attributes[$n]);
-
-            foreach ($this->attributes[$n] as $name => $value)
-            {
-                $this->numbers[] = $this->_lookup($name);
-                $this->numbers[] = $this->atns[$n][$name];
-                $this->numbers[] = strlen($value); $this->textstring .= $value; //!!! Here strlen() has not been changed to api_strlen(). To be investigated. Ivan Tcholakov, 29-AUG-2008.
-            }
-
-            $this->numbers[] = $this->_lookup($this->name[$n]);
-            $this->numbers[] = $this->ns[$n];
-            $this->numbers[] = $n - $this->parent[$n];  // more compact
-        }
-    }
-
-
-    function xmddoc($strings, $charset = null, $textstring = '')
-    {
-    	if (empty($charset))
-    	{
-    		$charset = api_get_system_encoding();
-    	}
-
-        $this->parent = array();      $this->name = array();
-        $this->ns = array();          $this->attributes = array();
-        $this->atns = array();        $this->children = array();
-        $this->error = '';            $this->_nesting = array();
-        $this->_ns = array();         $this->_last = -1;
-
-        $this->_nsp = array();
-        foreach (explode(',', 'eb,tn,eg,ut,as,ne,jt,ne,ah,en,er') as $pfx)
-            $this->_nsp[$pfx] = '';
-
-        if (is_array($charset))  // new xmddoc($names, $numbers, $textstring)
-        {
-            $this->names = $strings;         $this->numbers = $charset;
-            $this->textstring = $textstring; $this->_uncache(); return;
-        }
-
-        $this->names = array(); $this->_lookup('');  // empty ns is number 0
-
-        // This is a quick workaround.
-        // The xml-parser supports only ISO-8859-1, UTF-8 and US-ASCII.
-    	// See http://php.net/manual/en/function.xml-parser-create-ns.php
-        //$xml_parser = xml_parser_create_ns($charset, ':');
-        $xml_parser = xml_parser_create_ns(api_is_utf8($charset) ? 'UTF-8' : 'ISO-8859-1', ':');
-
-        xml_set_object($xml_parser,$this);  // instead of ...,&$this
-        // See PHP manual: Passing by Reference vs. xml_set_object
-        xml_set_element_handler($xml_parser, '_startElement', '_endElement');
-        xml_set_character_data_handler($xml_parser, '_cData');
-        xml_set_start_namespace_decl_handler($xml_parser, '_startNs');
-        // xml_set_end_namespace_decl_handler($xml_parser, '_endNs');
-        // xml_set_default_handler ($xml_parser, '');
-        xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE);
-
-        if (!is_array($strings)) $strings = array($strings);
-
-        if (count($strings) && (api_substr($strings[0], 0, 5) != '<?xml') &&
-            !xml_parse($xml_parser,
-                '<?xml version="1.0" encoding="' . $charset . '"?>', FALSE))
-        {
-            $this->error = 'Encoding ' . $charset . ': ' .
-                xml_error_string(xml_get_error_code($xml_parser));
-            $strings = array();
-        }
-
-        foreach ($strings as $s)
-        {
-            if (api_substr($s, -1) != "\n") $s .= "\n";
-
-            if (!xml_parse($xml_parser, $s, FALSE))
-            {
-                $errCode = xml_get_error_code($xml_parser);
-                $this->error = 'Line '. xml_get_current_line_number($xml_parser) .
-                    ' (c'  . xml_get_current_column_number($xml_parser) .
-                    // ', b'  . xml_get_current_byte_index($xml_parser) .
-                    '): error ' . $errCode . '= ' . xml_error_string($errCode);
-                break;  // the error string is English...
-            }
-        }
-
-        xml_parse($xml_parser, '', TRUE); xml_parser_free($xml_parser);
-    }
-
-
-    // internal methods
-
-    function _sibnum($parent, $name = '', $pmn = 'N')  // sibling or number
-    {
-        if ($parent <= 0) return -1;
-
-        $found = FALSE; $prev = -1; $next = -1; $num = 0;
-
-        foreach ($this->children[$this->parent[$parent]] as $child)
-        {
-            if (is_string($child)) continue;
-
-            $name_ok = $name ? ($this->name[$child] == $name) : TRUE;
-
-            if ($found && $name_ok)
-            {
-                $next = $child; break;
-            }
-            elseif ($parent === $child)
-            {
-                $num ++; $found = TRUE;
-            }
-            elseif ($name_ok)
-            {
-                $num ++; $prev = $child;
-            }
-        }
-
-        return ($pmn == '-') ? $prev : (($pmn == '+') ? $next : $num);
-    }
-
-    function _uncache()  // restore all data from numbers+names+textstring
-    {
-        $n = -1; $numptr = -1; $txtptr = 0; $count = count($this->numbers);
-        $A0 = array();  // believe it or not, this makes the loops quicker!
-
-        while (++$numptr < $count)
-        {
-            $n++;
-
-            if (($countdown = $this->numbers[$numptr]) == 0)
-            {
-                $this->children[$n] = $A0;
-            }
-            else while (--$countdown >= 0)
-            {
-                if (($chc = $this->numbers[++$numptr]) == 0)
-                {
-                    $this->children[$n][] = api_substr($this->textstring,
-                        $txtptr, ($len = $this->numbers[++$numptr]));
-                    $txtptr += $len;
-                }
-                else
-                {
-                    $this->children[$n][] = $n + $chc;
-                }
-            }
-
-            if (($countdown = $this->numbers[++$numptr]) == 0)
-            {
-                $this->attributes[$n] = $this->atns[$n] = $A0;
-            }
-            else while (--$countdown >= 0)
-            {
-                $name = $this->names[$this->numbers[++$numptr]];
-                $this->atns[$n][$name] = $this->numbers[++$numptr];
-                $this->attributes[$n][$name] = api_substr($this->textstring,
-                    $txtptr, ($len = $this->numbers[++$numptr]));
-                $txtptr += $len;
-            }
-
-            $this->name[$n] = $this->names[$this->numbers[++$numptr]];
-            $this->ns[$n] = $this->numbers[++$numptr];
-
-            $this->parent[$n] = $n - $this->numbers[++$numptr];
-        }
-
-        $this->_last = $n;
-    }
-
-    function _startElement($parser, $name, $attribs)
-    {
-        $level = count($this->_nesting);
-        $parent = ($level == 0) ? -1 : $this->_nesting[$level-1];
-
-        $child = $this->xmd_add_element($name, $parent,
-            array_merge($attribs, $this->_ns));
-
-        $this->_nesting[] = $child; $this->_ns = array();
-
-        $this->_concat = FALSE;  // see _cData
-    }
-
-    function _endElement($parser, $name)
-    {
-        array_pop($this->_nesting); $this->_concat = FALSE;
-    }
-
-    function _cData($parser, $data)
-    {
-        if (!ltrim($data)) return;  // empty line, or whitespace preceding <tag>
-
-        $level = count($this->_nesting);
-        $parent = ($level == 0) ? -1 : $this->_nesting[$level-1];
-
-        if ($parent >= 0)
-        {
-            $nc = count($this->children[$parent]);
-            $pcs = ($nc > 0 && is_string($this->children[$parent][$nc - 1]));
-
-            if ($pcs && api_strlen($data) == 1) $this->_concat = TRUE;
-            // expat parser puts &xx; in a separate cData, try to re-assemble
-
-            if ($pcs && $data{0} > '~') $this->_concat = TRUE;
-            // PHP5 expat breaks before 8-bit characters
-
-            if ($this->_concat)
-            {
-                $this->children[$parent][$nc - 1] .= $data;
-                $this->_concat = (api_strlen($data) == 1);
-            }
-            else
-                $this->children[$parent][] = $pcs ? "\n" . $data : $data;
-        }
-    }
-
-    function _startNs($parser, $pfx, $uri)  // called before _startElement
-    {
-        $this->_ns['xmlns' . ($pfx ? ':'.$pfx : '')] = $uri;
-        $this->_nsp[$pfx] = $uri;
-    }
-
-    function _nsPfx($ppar, $uri)  // find namespace prefix
-    {
-        while ($ppar >= 0)
-        {
-            foreach ($this->attributes[$ppar] as $name => $value)
-                if (api_substr($name, 0, 5) == 'xmlns' && $value == $uri)
-                {
-                    $pfxc = api_substr($name, 6) . api_substr($name, 5, 1); break 2;
-                }
-
-            $ppar = $this->parent[$ppar];
-        }
-
-        if ($ppar >= 0) return $pfxc; if ($uri == '') return '';
-
-        if ($uri == 'http://www.w3.org/XML/1998/namespace') return 'xml:';
-
-        foreach($this->_nsp as $pfx => $used) if (!$used) break;
-
-        $this->_nsp[$pfx] = $uri; $xmlnspfx = 'xmlns:' . $pfx;
-        $this->attributes[0][$xmlnspfx] = $uri; $this->atns[0][$xmlnspfx] = 0;
-
-        return $pfx . ':';
-
-    }
-
-    function _lookup($name)  // for namespaces + see cache
-    {
-        $where = array_search($name, $this->names);
-
-        if ($where === FALSE || $where === NULL)
-        {
-            $where = count($this->names); $this->names[] = $name;
-        }
-        return $where;
-    }
-}
-
-/*
-<!--
-    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, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-  -->
-*/
-?>

+ 0 - 131
main/inc/lib/zip.class.php

@@ -1,131 +0,0 @@
-<?php
-/**
- * Wrapper around pclzip. Makes a bit easier to use compression.
- * 
- * Usage:
- * 
- *      $zip = Zip::create('...');
- *      $zip->add($file_path, $local_path);
- * 
- * Note
- * 
- * Pclzip do not accept method callbacks. It only accepts pure function callbacks.
- * As a result the implementation is a bit more complicated than it should be.
- *
- * @license see /license.txt
- * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
- */
-/**
- * Zip wrapper class
- */
-class Zip
-{
-
-    protected static $pool = array();
-
-    public static function pool($hash = '')
-    {
-        if (empty($hash)) {
-            return self::$pool;
-        } else {
-            return self::$pool[$hash];
-        }
-    }
-    
-    
-    /**
-     *
-     * @param string $path
-     * @return Zip 
-     */
-    public static function create($path)
-    {
-        return new self($path);
-    }
-
-    protected $path = '';
-    protected $archive = null;
-    protected $entries = array();
-
-    public function __construct($path = '')
-    {
-        $this->path = $path;
-        self::$pool[$this->get_hash()] = $this;
-    }
-
-    public function get_path()
-    {
-        return $this->path;
-    }
-
-    public function get_hash()
-    {
-        return md5($this->path);
-    }
-
-    public function add($file_path, $archive_path = '', $comment = '')
-    {
-        /**
-         * Remove c: when working on windows. 
-         */
-        if (substr($file_path, 1, 1) == ':') {
-            $file_path = substr($file_path, 2);
-        }
-        
-        $entry = array(
-            'file_path' => $file_path,
-            'archive_path' => $archive_path,
-            'comment' => $comment
-        );
-        $this->entries[$file_path] = $entry;
-
-        $callback_name = 'zipcallback_' . $this->get_hash();
-        if (!function_exists($callback_name)) {
-            $callback = '';
-            $callback .= 'function ' . $callback_name . '($event, &$header){';
-            $callback .= '$parts = explode(\'_\', __FUNCTION__);';
-            $callback .= '$hash = end($parts);';
-            $callback .= 'return Zip::pool($hash)->callback($event, $header);';
-            $callback .= '};';
-            eval($callback);
-        }
-
-        $archive = $this->archive();
-        $archive->add($file_path, PCLZIP_CB_PRE_ADD, $callback_name);
-    }
-    
-    /**
-     *
-     * @return PclZip
-     */
-    protected function archive()
-    {
-        if ($this->archive) {
-            return $this->archive;
-        }
-        if (empty($this->path)) {
-            return null;
-        }
-        return $this->archive = new PclZip($this->path);
-    }
-
-    public function callback($event, &$header)
-    {
-        if ($event != PCLZIP_CB_PRE_ADD) {
-            return 0;
-        }
-
-        $path = $header['filename'];
-        if (!isset($this->entries[$path])) {
-            return 1;
-        }
-
-        $entry = $this->entries[$path];
-        $archive_path = $entry['archive_path'];
-        if (!empty($archive_path)) {
-            $header['stored_filename'] = $archive_path;
-        }
-        return 1;
-    }
-
-}

+ 0 - 624
main/inc/local.inc.php

@@ -1,624 +0,0 @@
-<?php
-/** @deprecated */
-exit;
-
-
-
-/* For licensing terms, see /license.txt */
-/**
- *
- *  SCRIPT PURPOSE
- *
- *
- * You can request a course id. It will check if the course Id requested is the
- * same as the current one. If it isn't it will update session information from
- * the database. You can also force the course reset if you want ($cidReset).
- *
- * All the course information is stored in the $_course array.
- *
- * You can request a group id. The script will check if the group id requested is the
- * same as the current one. If it isn't it will update session information from
- * the database. You can also force the course reset if you want ($gidReset).
- *
- * The course id is stored in $_cid session variable.
- * The group  id is stored in $_gid session variable.
- *
- * @package chamilo.include
-*/
-
-// verified if exists the username and password in session current
-
-use \ChamiloSession as Session;
-
-// Conditional login
-/*
- * Disabling for now
-if (isset($_SESSION['conditional_login']['uid']) && $_SESSION['conditional_login']['can_login']=== true) {
-    $uData = UserManager::get_user_info_by_id($_SESSION['conditional_login']['uid']);
-    ConditionalLogin::check_conditions($uData);
-    $_user['user_id'] = $_SESSION['conditional_login']['uid'];
-    $_user['status']  = $uData['status'];
-    Session::write('_user', $_user);
-    Session::erase('conditional_login');
-    $uidReset=true;
-}*/
-
-// parameters passed via GET
-$gidReq = isset($_GET["gidReq"]) ? Database::escape_string($_GET["gidReq"]) : null;
-
-//this fixes some problems with generic functionalities like
-//My Agenda & What's New icons linking to courses
-// $cidReq can be set in the session
-$cidReq = isset($_SESSION['_cid']) ? Database::escape_string($_SESSION['_cid']) : null;
-// $cidReq can be set in URL-parameter
-$cidReq = isset($_GET["cidReq"]) ? Database::escape_string($_GET["cidReq"]) : $cidReq;
-$cidReset = isset($cidReset) ? Database::escape_string($cidReset) : '';
-
-// $cidReset can be set in URL-parameter
-$cidReset = (isset($_GET['cidReq']) && ((isset($_SESSION['_cid']) && $_GET['cidReq'] != $_SESSION['_cid']) || (!isset($_SESSION['_cid'])))) ? Database::escape_string($_GET["cidReq"]) : $cidReset;
-
-// $gidReset can be set in URL-parameter
-$gidReset = isset($gidReset) ? $gidReset : '';
-
-// parameters passed via POST
-$login = isset($_POST["login"]) ? $_POST["login"] : '';
-// register if the user is just logging in, in order to redirect him
-$logging_in = false;
-
-/*  MAIN CODE  */
-
-$errorMessage = null;
-$loginFailed = true;
-
-if (!empty($_SESSION['_user']['user_id']) && !$login) {
-    // uid is in session => login already done, continue with this value
-    $_user['user_id'] = $_SESSION['_user']['user_id'];
-    //Check if we have to reset user data
-    //This param can be used to reload user data if user has been logged by external script
-    if (isset($_SESSION['_user']['uidReset']) && $_SESSION['_user']['uidReset']) {
-        $uidReset = true;
-    }
-} else {
-
-    if (isset($_user['user_id'])) {
-        unset($_user['user_id']);
-    }
-
-    //Platform legal terms and conditions
-    if (api_get_setting('allow_terms_conditions') == 'true') {
-        if (isset($_POST['login']) && isset($_POST['password']) && isset($_SESSION['term_and_condition']['user_id'])) {
-            $user_id = $_SESSION['term_and_condition']['user_id'];    // user id
-            // Update the terms & conditions
-            $legal_type = null;
-            //verify type of terms and conditions
-            if (isset($_POST['legal_info'])) {
-                $info_legal = explode(':', $_POST['legal_info']);
-                $legal_type = LegalManager::get_type_of_terms_and_conditions($info_legal[0], $info_legal[1]);
-            }
-
-            //is necessary verify check
-            if ($legal_type == 1) {
-                if ((isset($_POST['legal_accept']) && $_POST['legal_accept']=='1')) {
-                    $legal_option = true;
-                } else {
-                    $legal_option = false;
-                }
-            }
-
-            //no is check option
-            if ($legal_type == 0) {
-                $legal_option=true;
-            }
-
-            if (isset($_POST['legal_accept_type']) && $legal_option===true) {
-                $cond_array = explode(':', $_POST['legal_accept_type']);
-                if (!empty($cond_array[0]) && !empty($cond_array[1])){
-                    $time = time();
-                    $condition_to_save = intval($cond_array[0]).':'.intval($cond_array[1]).':'.$time;
-                    UserManager::update_extra_field_value($user_id,'legal_accept',$condition_to_save);
-                }
-            }
-        }
-    }
-
-    //IF cas is activated and user isn't logged in
-    if (api_get_setting('cas_activate') == 'true') {
-        $cas_activated = true;
-    } else {
-        $cas_activated = false;
-    }
-
-    $cas_login = false;
-    if ($cas_activated AND !isset($_user['user_id']) AND !isset($_POST['login'])) {
-        require_once api_get_path(SYS_PATH).'main/auth/cas/authcas.php';
-        $cas_login = cas_is_authenticated();
-    }
-
-    if ((isset($_POST['login']) AND isset($_POST['password']) ) OR ($cas_login)) {
-
-        // $login && $password are given to log in
-        if ( $cas_login  && empty($_POST['login']) ) {
-            $login = $cas_login;
-        } else {
-            $login      = $_POST['login'];
-            $password   = $_POST['password'];
-        }
-
-        //Lookup the user in the main database
-        $user_table = Database::get_main_table(TABLE_MAIN_USER);
-        $sql = "SELECT user_id, username, auth_source, password FROM $user_table
-                WHERE username = '".Database::escape_string($login)."'";
-        $result = Database::query($sql);
-
-        // @todo use a UserProvider
-
-        if (Database::num_rows($result) > 0) {
-            $uData = Database::fetch_array($result);
-
-            if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE || $uData['auth_source'] == CAS_AUTH_SOURCE) {
-                //The authentification of this user is managed by Chamilo itself
-                $password = api_get_encrypted_password(trim(stripslashes($password)));
-
-                // Check the user's password
-                if (($password == $uData['password'] or $cas_login) and (trim($login) == $uData['username'])) {
-
-                    $uData = api_get_user_info($uData['user_id'], false, false, true);
-                    $extraFields = $uData['extra_fields'];
-                    // $update_type = UserManager::get_extra_user_data_by_field($uData['user_id'], 'update_type');
-                    $update_type = isset($extraFields['extra_update_type']) ? $extraFields['extra_update_type'] : null;
-
-                    if (!empty($extAuthSource[$update_type]['updateUser']) && file_exists($extAuthSource[$update_type]['updateUser'])) {
-                        include_once $extAuthSource[$update_type]['updateUser'];
-                    }
-
-                    // Check if the account is active (not locked)
-                    if ($uData['active'] == '1') {
-
-                        // Check if the expiration date has not been reached
-                        if ($uData['expiration_date'] > date('Y-m-d H:i:s') OR $uData['expiration_date'] == '0000-00-00 00:00:00') {
-                            global $_configuration;
-
-                            if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
-                                //Check if user is an admin
-                                $my_user_is_admin = UserManager::is_admin($uData['user_id']);
-
-                                // This user is subscribed in these sites => $my_url_list
-                                $my_url_list = api_get_access_url_from_user($uData['user_id']);
-
-                                //Check the access_url configuration setting if the user is registered in the access_url_rel_user table
-                                //Getting the current access_url_id of the platform
-                                $current_access_url_id = api_get_current_access_url_id();
-
-                                if ($my_user_is_admin === false) {
-
-                                    if (is_array($my_url_list) && count($my_url_list) > 0) {
-                                        // the user have the permissions to enter at this site
-                                        if (in_array($current_access_url_id, $my_url_list)) {
-                                            ConditionalLogin::check_conditions($uData);
-                                            Session::write('_user', $uData);
-                                            $logging_in = true;
-                                        } else {
-                                            $loginFailed = true;
-                                            Session::erase('_uid');
-                                            $errorMessage = 'access_url_inactive';
-                                        }
-                                    } else {
-                                        $loginFailed = true;
-                                        Session::erase('_uid');
-                                        $errorMessage = 'access_url_inactive';
-                                    }
-                                } else {
-                                    //Only admins of the "main" (first) Chamilo portal can login wherever they want
-                                    //Check if this admin have the access_url_id = 1 which means the principal
-                                    if (in_array(1, $my_url_list)) {
-                                        ConditionalLogin::check_conditions($uData);
-                                        Session::write('_user', $uData);
-                                    } else {
-                                        //This means a secondary admin wants to login so we check as he's a normal user
-                                        if (in_array($current_access_url_id, $my_url_list)) {
-                                            Session::write('_user', $uData);
-                                        } else {
-                                            $loginFailed = true;
-                                            Session::erase('_uid');
-                                            $errorMessage = 'access_url_inactive';
-                                        }
-                                    }
-                                }
-                            } else {
-                                ConditionalLogin::check_conditions($uData);
-                                Session::write('_user', $uData);
-                                $logging_in = true;
-                            }
-                        } else {
-                            $loginFailed = true;
-                            Session::erase('_uid');
-                            $errorMessage = 'account_expired';
-                        }
-                    } else {
-                        $loginFailed = true;
-                        Session::erase('_uid');
-                        $errorMessage = 'account_inactive';
-                    }
-                } else {
-                    // login failed: username or password incorrect
-                    $loginFailed = true;
-                    Session::erase('_uid');
-                    $errorMessage = 'user_password_incorrect';
-                }
-
-                if (isset($uData['creator_id']) && isset($_user) && $_user['user_id'] != $uData['creator_id']) {
-                    //first login for a not self registred
-                    //e.g. registered by a teacher
-                    //do nothing (code may be added later)
-                }
-            } elseif (!empty($extAuthSource[$uData['auth_source']]['login']) && file_exists($extAuthSource[$uData['auth_source']]['login'])) {
-                /*
-                 * Process external authentication
-                 * on the basis of the given login name
-                 */
-                $loginFailed = true;  // Default initialisation. It could
-                // change after the external authentication
-                $key = $uData['auth_source']; //'ldap','shibboleth'...
-                /* >>>>>>>> External authentication modules <<<<<<<<< */
-                // see configuration.php to define these
-                include_once($extAuthSource[$key]['login']);
-                /* >>>>>>>> External authentication modules <<<<<<<<< */
-            } else { // no standard Chamilo login - try external authentification
-                //huh... nothing to do... we shouldn't get here
-                error_log('Chamilo Authentication file '. $extAuthSource[$uData['auth_source']]['login']. ' could not be found - this might prevent your system from doing the corresponding authentication process',0);
-            }
-        } else {
-            // login failed, Database::num_rows($result) <= 0
-            $loginFailed = true;  // Default initialisation. It could
-            // change after the external authentication
-
-            /*
-             * In this section:
-             * there is no entry for the $login user in the Chamilo
-             * database. This also means there is no auth_source for the user.
-             * We let all external procedures attempt to add him/her
-             * to the system.
-             *
-             * Process external login on the basis
-             * of the authentication source list
-             * provided by the configuration settings.
-             * If the login succeeds, for going further,
-             * Chamilo needs the $_user['user_id'] variable to be
-             * set and registered in the session. It's the
-             * responsability of the external login script
-             * to provide this $_user['user_id'].
-             */
-
-            if (isset($extAuthSource) && is_array($extAuthSource)) {
-                foreach($extAuthSource as $thisAuthSource) {
-                    if (!empty($thisAuthSource['newUser']) && file_exists($thisAuthSource['newUser'])) {
-                        include_once($thisAuthSource['newUser']);
-                    } else {
-                        error_log('Chamilo Authentication file '. $thisAuthSource['newUser']. ' could not be found - this might prevent your system from using the authentication process in the user creation process',0);
-                    }
-                }
-            } //end if is_array($extAuthSource)
-            if ($loginFailed) { //If we are here username given is wrong
-                //header('Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=user_password_incorrect');
-                $errorMessage = 'user_password_incorrect';
-            }
-        } //end else login failed
-    } elseif (api_get_setting('sso_authentication') === 'true' &&  !in_array('webservices', explode('/', $_SERVER['REQUEST_URI']))) {
-        /**
-         * TODO:
-         * - Work on a better validation for webservices paths. Current is very poor and exit
-         */
-        $subsso = api_get_setting('sso_authentication_subclass');
-        if (!empty($subsso)) {
-            require_once api_get_path(SYS_CODE_PATH).'auth/sso/sso.'.$subsso.'.class.php';
-            $subsso = 'sso'.$subsso;
-            $osso = new $subsso(); //load the subclass
-        } else {
-            $osso = new sso();
-        }
-        if (isset($_SESSION['_user']['user_id'])) {
-
-        } else {
-            // Handle cookie comming from Master Server
-            if (!isset($_GET['sso_referer']) && !isset($_GET['loginFailed']) && isset($_GET['sso_cookie'])) {
-                // Redirect to master server
-                $osso->ask_master();
-            } elseif (isset($_GET['sso_cookie'])) {
-                // Here we are going to check the origin of
-                // what the call says should be used for
-                // authentication, and ensure  we know it
-                $matches_domain = false;
-                if (isset($_GET['sso_referer'])) {
-                    $protocol = api_get_setting('sso_authentication_protocol');
-                    // sso_authentication_domain can list
-                    // several, comma-separated, domains
-                    $master_urls = split(',',api_get_setting('sso_authentication_domain'));
-                    if (!empty($master_urls)) {
-                        $master_auth_uri = api_get_setting('sso_authentication_auth_uri');
-                        foreach ($master_urls as $mu) {
-                            if (empty($mu)) { continue; }
-                            // for each URL, check until we find *one* that matches the $_GET['sso_referer'], then skip the rest
-                            if ($protocol.trim($mu).$master_auth_uri === $_GET['sso_referer']) {
-                                $matches_domain = true;
-                                break;
-                            }
-                        }
-                    } else {
-                        error_log('Your sso_authentication_master param is empty. Check the platform configuration, security section. It can be a list of comma-separated domains');
-                    }
-                }
-                if ($matches_domain) {
-                    //make all the process of checking
-                    //if the user exists (delegated to the sso class)
-                    $osso->check_user();
-                } else {
-                    error_log('Check the sso_referer URL in your script, it doesn\'t match any of the possibilities');
-                    //Request comes from unknown source
-                    $loginFailed = true;
-                    Session::erase('_uid');
-                    $errorMessage = 'unrecognize_sso_origin';
-                }
-            }
-        }//end logout ... else ... login
-    } elseif (api_get_setting('openid_authentication') == 'true') {
-        if (!empty($_POST['openid_url'])) {
-            include api_get_path(SYS_CODE_PATH).'auth/openid/login.php';
-            openid_begin(trim($_POST['openid_url']), api_get_path(WEB_PATH).'index.php');
-            //this last function should trigger a redirect, so we can die here safely
-            die('Openid login redirection should be in progress');
-        } elseif (!empty($_GET['openid_identity'])) {
-            //it's usual for PHP to replace '.' (dot) by '_' (underscore) in URL parameters
-            include(api_get_path(SYS_CODE_PATH).'auth/openid/login.php');
-            $res = openid_complete($_GET);
-            if ($res['status'] == 'success') {
-                $id1 = Database::escape_string($res['openid.identity']);
-                //have another id with or without the final '/'
-                $id2 = (substr($id1,-1,1)=='/'?substr($id1,0,-1):$id1.'/');
-                //lookup the user in the main database
-                $user_table = Database::get_main_table(TABLE_MAIN_USER);
-                $sql = "SELECT user_id, username, password, auth_source, active, expiration_date
-                    FROM $user_table
-                    WHERE openid = '$id1'
-                    OR openid = '$id2' ";
-                $result = Database::query($sql);
-                if ($result !== false) {
-                    if (Database::num_rows($result)>0) {
-                        //$row = Database::fetch_array($res);
-                        $uData = Database::fetch_array($result);
-
-                        if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE) {
-                            // the authentification of this user is managed by Chamilo itself
-
-                            // check if the account is active (not locked)
-                            if ($uData['active']=='1') {
-                                // check if the expiration date has not been reached
-                                if ($uData['expiration_date']>date('Y-m-d H:i:s') OR $uData['expiration_date']=='0000-00-00 00:00:00') {
-                                    $_user['user_id'] = $uData['user_id'];
-                                    $_user['status']  = $uData['status'];
-                                    Session::write('_user', $_user);
-                                } else {
-                                    $loginFailed = true;
-                                    Session::erase('_uid');
-                                    $errorMessage = 'account_expired';
-                                }
-                            } else {
-                                $loginFailed = true;
-                                Session::erase('_uid');
-                                $errorMessage = 'account_inactive';
-                            }
-                            if (isset($uData['creator_id']) && $_user['user_id'] != $uData['creator_id']) {
-                                //first login for a not self registred
-                                //e.g. registered by a teacher
-                                //do nothing (code may be added later)
-                            }
-                        }
-                    } else {
-                        //Redirect to the subscription form
-                        header('Location: '.api_get_path(WEB_CODE_PATH).'auth/inscription.php?username='.$res['openid.sreg.nickname'].'&email='.$res['openid.sreg.email'].'&openid='.$res['openid.identity'].'&openid_msg=idnotfound');
-                        //$loginFailed = true;
-                    }
-                } else {
-                    $loginFailed = true;
-                }
-            } else {
-                $loginFailed = true;
-            }
-        }
-    } elseif (KeyAuth::is_enabled()) {
-        $success = KeyAuth::instance()->login();
-        if ($success) {
-            $use_anonymous = false;
-        }
-    }
-    $uidReset = true;
-} // end
-
-
-if ($loginFailed == true && !empty($errorMessage)) {
-    header('Location: '.api_get_path(WEB_PUBLIC_PATH).'index?error='.$errorMessage);
-    exit;
-}
-
-//Now check for anonymous user mode
-if (isset($use_anonymous) && $use_anonymous) {
-    //if anonymous mode is set, then try to set the current user as anonymous
-    //if he doesn't have a login yet
-    api_set_anonymous();
-} else {
-    //if anonymous mode is not set, then check if this user is anonymous. If it
-    //is, clean it from being anonymous (make him a nobody :-))
-    api_clear_anonymous();
-}
-
-// if the requested course is different from the course in session
-
-if (!empty($cidReq) && (!isset($_SESSION['_cid']) or (isset($_SESSION['_cid']) && $cidReq != $_SESSION['_cid']))) {
-    $cidReset = true;
-    $gidReset = true;    // As groups depend from courses, group id is reset
-}
-
-// Setting app user variable
-$_user = Session::read('_user');
-
-if ($_user && !isset($_user['complete_name'])) {
-    $_user = api_get_user_info(api_get_user_id(), false, false, true);
-    Session::write('_user', $_user);
-}
-
-$app['current_user'] = $_user;
-
-/* USER INIT */
-
-if (isset($uidReset) && $uidReset) {   // session data refresh requested
-    unset($_SESSION['_user']['uidReset']);
-    $is_platformAdmin = false;
-    $is_allowedCreateCourse = false;
-
-    if (isset($_user['user_id']) && $_user['user_id'] && !api_is_anonymous()) {
-        // a uid is given (log in succeeded)
-        $user_table     = Database::get_main_table(TABLE_MAIN_USER);
-        $admin_table    = Database::get_main_table(TABLE_MAIN_ADMIN);
-        $track_e_login  = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
-
-        $sql = "SELECT user.*, a.user_id is_admin, login.login_date
-            FROM $user_table
-            LEFT JOIN $admin_table a
-            ON user.user_id = a.user_id
-            LEFT JOIN $track_e_login login
-            ON user.user_id  = login.login_user_id
-            WHERE user.user_id = '".$_user['user_id']."'
-            ORDER BY login.login_date DESC LIMIT 1";
-
-        $result = Database::query($sql);
-
-        if (Database::num_rows($result) > 0) {
-            // Extracting the user data
-
-            $uData = Database::fetch_array($result);
-            $_user = api_format_user($uData, false);
-            $_user['lastLogin']        = api_strtotime($uData['login_date'], 'UTC');
-            $is_platformAdmin           = (bool) (! is_null( $uData['is_admin']));
-            $is_allowedCreateCourse     = (bool) (($uData ['status'] == COURSEMANAGER) or (api_get_setting('drhCourseManagerRights') and $uData['status'] == DRH));
-            ConditionalLogin::check_conditions($uData);
-
-            Session::write('_user', $_user);
-            UserManager::update_extra_field_value($_user['user_id'], 'already_logged_in', 'true');
-
-            Session::write('is_platformAdmin', $is_platformAdmin);
-            Session::write('is_allowedCreateCourse', $is_allowedCreateCourse);
-
-        } else {
-            header('location:'.api_get_path(WEB_PATH));
-            exit;
-        }
-    } else { // no uid => logout or Anonymous
-        Session::erase('_user');
-        Session::erase('_uid');
-    }
-    Session::write('is_platformAdmin', $is_platformAdmin);
-    Session::write('is_allowedCreateCourse', $is_allowedCreateCourse);
-} else { // continue with the previous values
-    $_user                    = isset($_SESSION['_user']) ? $_SESSION['_user'] : null;
-    $is_platformAdmin         = isset($_SESSION['is_platformAdmin']) ? $_SESSION['is_platformAdmin'] : false;
-    $is_allowedCreateCourse   = isset($_SESSION['is_allowedCreateCourse']) ? $_SESSION['is_allowedCreateCourse'] : false;
-}
-
-if (!isset($_SESSION['login_as'])) {
-    $save_course_access = true;
-
-    //The value  $_dont_save_user_course_access should be added before the call of global.inc.php see the main/inc/chat.ajax.php file
-    //Disables the updates in the TRACK_E_COURSE_ACCESS table
-    if (isset($_dont_save_user_course_access) && $_dont_save_user_course_access == true) {
-        $save_course_access = false;
-    }
-
-    if ($save_course_access) {
-        $course_tracking_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
-
-        /*
-        * When $_configuration['session_lifetime'] is too big 100 hours (in order to let users take exercises with no problems)
-        * the function Tracking::get_time_spent_on_the_course() returns big values (200h) due the condition:
-        * login_course_date > now() - INTERVAL $session_lifetime SECOND
-        *
-        */
-        /*
-        if (isset($_configuration['session_lifetime'])) {
-            $session_lifetime    = $_configuration['session_lifetime'];
-        } else {
-            $session_lifetime    = 3600; // 1 hour
-        }*/
-
-        $session_lifetime    = 3600; // 1 hour
-
-        $course_code = api_get_course_id();
-        $courseId = api_get_course_int_id();
-        $time = api_get_datetime();
-
-        if (isset($_user['user_id']) && !empty($_user['user_id']) && !empty($courseId)) {
-
-            //We select the last record for the current course in the course tracking table
-            //But only if the login date is < than now + max_life_time
-            $sql = "SELECT course_access_id FROM $course_tracking_table
-                    WHERE   user_id     = ".intval($_user ['user_id'])." AND
-                            c_id = '$courseId' AND
-                            session_id  = ".api_get_session_id()." AND
-                            login_course_date > now() - INTERVAL $session_lifetime SECOND
-                    ORDER BY login_course_date DESC LIMIT 0,1";
-            $result = Database::query($sql);
-
-            if (Database::num_rows($result) > 0) {
-                $i_course_access_id = Database::result($result,0,0);
-                //We update the course tracking table
-                $sql = "UPDATE $course_tracking_table  SET logout_course_date = '$time', counter = counter+1
-                        WHERE course_access_id = ".intval($i_course_access_id)." AND session_id = ".api_get_session_id();
-                Database::query($sql);
-            } else {
-                $sql="INSERT INTO $course_tracking_table (c_id, user_id, login_course_date, logout_course_date, counter, session_id)" .
-                    "VALUES('".$courseId."', '".$_user['user_id']."', '$time', '$time', '1','".api_get_session_id()."')";
-                Database::query($sql);
-            }
-        }
-    }
-}
-
-
-/*  COURSE / USER REL. INIT */
-
-$user_id    = isset($_user['user_id']) ? $_user['user_id'] : null;
-
-//Course permissions
-$is_courseAdmin     = false; //course teacher
-$is_courseTutor     = false; //course teacher - some rights
-$is_courseMember    = false; //course student
-$is_courseCoach     = false; //course coach
-
-//Course - User permissions
-$is_sessionAdmin    = false;
-$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
-
-//set variable according to student_view_enabled choices
-if (api_get_setting('student_view_enabled') == "true") {
-    if (isset($_GET['isStudentView'])) {
-        if ($_GET['isStudentView'] == 'true') {
-            if (isset($_SESSION['studentview'])) {
-                if (!empty($_SESSION['studentview'])) {
-                    // switching to studentview
-                    $_SESSION['studentview'] = 'studentview';
-                }
-            }
-        } elseif ($_GET['isStudentView'] == 'false') {
-            if (isset($_SESSION['studentview'])) {
-                if (!empty($_SESSION['studentview'])) {
-                    // switching to teacherview
-                    $_SESSION['studentview'] = 'teacherview';
-                }
-            }
-        }
-    } elseif (!empty($_SESSION['studentview'])) {
-        //all is fine, no change to that, obviously
-    } elseif (empty($_SESSION['studentview'])) {
-        // We are in teacherview here
-        $_SESSION['studentview'] = 'teacherview';
-    }
-}
-//Redirect::session_request_uri($logging_in, $user_id);

BIN
web/ChamiloLMS/img/winamp.gif