Example #1
0
 public static function log($message, $type)
 {
     if (claro_debug_mode()) {
         pushClaroMessage($message, $type);
     }
     Claroline::log($type, $message);
 }
Example #2
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct('header.tpl.php');
     $this->_htmlXtraHeaders = array();
     $this->_httpXtraHeaders = array();
     $this->_toolName = '';
     if (claro_debug_mode()) {
         $this->addInlineJavascript("var claro_debug_mode = true;");
     }
     require dirname(__FILE__) . '/../../installedVersion.inc.php';
     if ($stable) {
         if (file_exists(dirname(__FILE__) . '/../../../../platform/currentVersion.inc.php')) {
             require dirname(__FILE__) . '/../../../../platform/currentVersion.inc.php';
         } else {
             $clarolineVersion = $new_version;
         }
         if ($clarolineVersion != $new_version) {
             $claroVersion = "{$clarolineVersion}-{$new_version}";
         } else {
             $claroVersion = $new_version;
         }
     } else {
         $claroVersion = $new_version;
     }
     $this->assign('version', $claroVersion);
 }
Example #3
0
 /**
  * Send a JSON-encoded exception to the client
  * @param Exception $e
  */
 public function __construct($e)
 {
     $errorArr = array('errno' => $e->getCode(), 'error' => $e->getMessage());
     if (claro_debug_mode()) {
         $errorArr['trace'] = $e->getTraceAsString();
         $errorArr['file'] = $e->getFile();
         $errorArr['line'] = $e->getLine();
     }
     parent::__construct($errorArr);
 }
 private function loadModuleManager($cidReq = null)
 {
     $toolList = claro_get_main_course_tool_list();
     foreach ($toolList as $tool) {
         if (!is_null($tool['label'])) {
             $file = get_module_path($tool['label']) . '/connector/trackingManager.cnr.php';
             if (file_exists($file)) {
                 require_once $file;
                 if (claro_debug_mode()) {
                     pushClaroMessage('Tracking : ' . $tool['label'] . ' tracking managers loaded', 'debug');
                 }
             }
         }
     }
 }
Example #5
0
/**
 * Exception handler to be used inside an output buffer
 */
function claro_ob_exception_handler($e)
{
    // get buffer contents
    $buffer = ob_get_contents();
    // close the output buffer
    ob_end_clean();
    // display the buffer contents
    echo $buffer;
    // display the exception
    if (claro_debug_mode()) {
        echo '<pre>' . $e->__toString() . '</pre>';
    } else {
        echo '<p>' . $e->getMessage() . '</p>';
    }
}
Example #6
0
 public function authenticate()
 {
     $auth = new Claro_Ldap($this->extAuthOptionList['url'], $this->extAuthOptionList['port'], $this->extAuthOptionList['basedn']);
     try {
         $auth->connect();
         // no anonymous bind
         // user can search
         if ($this->userSelfBindAuth == 'true') {
             $searchdn = "{$this->userAttr}={$this->username}," . $this->extAuthOptionList['basedn'];
             $searchpw = $this->password;
             $auth->bind($searchdn, $searchpw);
         } elseif ($this->useBindDn) {
             $searchdn = $this->extAuthOptionList['binddn'];
             $searchpw = $this->extAuthOptionList['bindpw'];
             $auth->bind($searchdn, $searchpw);
         }
         // search user
         $user = $auth->getUser($this->username, $this->userFilter, $this->userAttr);
         if ($user) {
             if ($this->userSelfBindAuth == 'true') {
                 $binddn = "{$this->userAttr}={$this->username}," . $this->extAuthOptionList['basedn'];
             } else {
                 $binddn = $user->getDn();
             }
             if ($auth->authenticate($binddn, $this->password)) {
                 $this->user = $user;
                 return true;
             } else {
                 return false;
             }
         }
     } catch (Exception $e) {
         $this->setFailureMessage($e->getMessage());
         if (claro_debug_mode()) {
             Console::error($e->__toString());
         } else {
             Console::error($e->getMessage());
         }
         return false;
     }
 }
Example #7
0
 /**
  * Get the authentication profile for the given user id
  * @param int $userId
  * @return AuthProfile
  */
 public static function getUserAuthProfile($userId)
 {
     if ($userId != claro_get_current_user_id()) {
         $user = new Claro_User($userId);
         $user->loadFromDatabase();
     } else {
         $user = Claro_CurrentUser::getInstance();
     }
     $authSource = $user->authSource;
     if (!$authSource) {
         throw new Exception("Cannot find user authentication source for user {$userId}");
     }
     try {
         $profileOptions = AuthDriverManager::getDriver($authSource)->getAuthProfileOptions();
     } catch (Exception $e) {
         if (claro_is_platform_admin() || claro_is_in_a_course() && claro_is_course_manager() && $userId != claro_get_current_user_id()) {
             Console::warning("Cannot find user authentication source for user {$userId}, use claroline default options instead");
             $profileOptions = AuthDriverManager::getDriver('claroline')->getAuthProfileOptions();
         } else {
             throw $e;
         }
     }
     $authProfile = new AuthProfile($userId, $authSource);
     $authProfile->setAuthDriverOptions($profileOptions);
     if (claro_debug_mode()) {
         pushClaroMessage(var_export($profileOptions, true), 'debug');
     }
     return $authProfile;
 }
Example #8
0
            break;
        case 'exDelete':
            $postId = $userInput->getMandatory('post');
            break;
        case 'exNotify':
            $topicId = $userInput->getMandatory('topic');
            break;
        case 'exdoNotNotify':
            $topicId = $userInput->getMandatory('topic');
            break;
        case 'show':
            $topicId = $userInput->getMandatory('topic');
            break;
    }
} catch (Exception $ex) {
    if (claro_debug_mode()) {
        pushClaroMessage('<pre>' . $ex->__toString() . '</pre>', 'error');
        // claro_die( '<pre>' . $ex->__toString() . '</pre>' );
    }
    if ($ex instanceof Claro_Validator_Exception) {
        switch ($cmd) {
            case 'rqPost':
                $dialogBox->error(get_lang('Unknown post or edition mode'));
                $cmd = 'dialog_only';
                break;
            case 'exSavePost':
                $dialogBox->error(get_lang('Missing information'));
                $inputMode = 'missing_input';
                break;
            case 'exDelete':
                $dialogBox->error(get_lang('Unknown post'));
Example #9
0
 function getThumbnail($imgPath, $newHeight, $newWidth)
 {
     $thumbName = md5($imgPath) . '_' . $newWidth . 'x' . $newHeight . '.jpg';
     $thumbPath = $this->thumbnailDirectory . '/' . $thumbName;
     if (file_exists($thumbPath) && filectime($this->documentRootDir . '/' . $imgPath) < filectime($thumbPath) && filemtime($this->documentRootDir . '/' . $imgPath) < filemtime($thumbPath)) {
         return $thumbPath;
     } else {
         if (claro_debug_mode()) {
             Console::debug("Regenerating thumbnail for {$imgPath}");
         }
         return $this->createThumbnail($imgPath, $newHeight, $newWidth);
     }
 }
Example #10
0
//common vars
$sco['_children'] = "student_id,student_name,lesson_location,credit,lesson_status,entry,score,total_time,exit,session_time";
$sco['score_children'] = "raw,min,max";
$sco['exit'] = "";
$sco['session_time'] = "0000:00:00.00";
?>
<script type="text/javascript">

        var init_total_time = "<?php 
echo $sco['total_time'];
?>
";
        // ====================================================
        // API Class Constructor
        var debug_ = <?php 
echo claro_debug_mode() ? 'true' : 'false';
?>
;
        
        function debugMessage( message ) {
            if (typeof console != "undefined") { 
                console.log( message ); 
            }
            else {
                alert( message );
            }
        }
        
        function APIClass() {

                //SCORM 1.2
Example #11
0
/**
 * CLAROLINE mySQL query wrapper. It also provides a debug display which works
 * when the CLARO_DEBUG_MODE constant flag is set to on (true)
 *
 * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
 * @author Christophe Gesché <*****@*****.**>
 * @param  string  $sqlQuery   - the sql query
 * @param  handler $dbHandler  - optional
 * @return handler             - the result handler
 * @deprecated since Claroline 1.9, use Claroline::getDatabase() and new classes
 *  in database/database.lib.php instead
 */
function claro_sql_query($sqlQuery, $dbHandler = '#')
{
    if (claro_debug_mode() && get_conf('CLARO_PROFILE_SQL', false)) {
        $start = microtime();
    }
    if ($dbHandler == '#') {
        $resultHandler = @mysql_query($sqlQuery);
    } else {
        $resultHandler = @mysql_query($sqlQuery, $dbHandler);
    }
    if (claro_debug_mode() && get_conf('CLARO_PROFILE_SQL', false)) {
        static $queryCounter = 1;
        $duration = microtime() - $start;
        $info = 'execution time : ' . ($duration > 0.001 ? '<b>' . round($duration, 4) . '</b>' : '&lt;0.001') . '&#181;s';
        // $info = ( $dbHandler == '#') ? mysql_info() : mysql_info($dbHandler);
        // $info .= ': affected rows :' . (( $dbHandler == '#') ? mysql_affected_rows() : mysql_affected_rows($dbHandler));
        $info .= ': affected rows :' . claro_sql_affected_rows();
        pushClaroMessage('<br />Query counter : <b>' . $queryCounter++ . '</b> : ' . $info . '<br />' . '<code><span class="sqlcode">' . nl2br($sqlQuery) . '</span></code>', claro_sql_errno() ? 'error' : 'sqlinfo');
    }
    if (claro_debug_mode() && claro_sql_errno()) {
        echo '<hr size="1" noshade>' . claro_sql_errno() . ' : ' . claro_sql_error() . '<br>' . '<pre style="color:red">' . $sqlQuery . '</pre>' . (function_exists('claro_html_debug_backtrace') ? claro_html_debug_backtrace() : '') . '<hr size="1" noshade>';
    }
    return $resultHandler;
}
Example #12
0
 /**
  * notify occurence of an event to the event manager. Usage :
  *  - EventManager::notify( $event );
  *  - EventManager::notify( $eventType, $args );
  * @access  public
  * @param   string event type of occured event, or event object
  * @param   array args optional event arguments (only if event type given
  *      as first argument)
  * @static
  */
 public static function notify($event, $args = null)
 {
     if (claro_debug_mode()) {
         Console::debug(__CLASS__ . "::notify " . $event->getEventType());
     }
     if (is_string($event)) {
         // $event is an event type
         $event = new Event($event, $args);
     }
     $mngr = EventManager::getInstance();
     return $mngr->eventOccurs($event);
 }
Example #13
0
 public function query($sql)
 {
     if (claro_debug_mode() && get_conf('CLARO_PROFILE_SQL', false)) {
         $start = microtime();
     }
     try {
         $result = parent::query(self::prepareQueryForExecution($sql));
         if (claro_debug_mode() && get_conf('CLARO_PROFILE_SQL', false)) {
             $duration = microtime() - $start;
             $info = 'execution time : ' . ($duration > 0.001 ? '<b>' . round($duration, 4) . '</b>' : '&lt;0.001') . '&#181;s';
             $info .= ': affected rows :' . $this->affectedRows();
             pushClaroMessage('<br />Query counter : <b>' . $this->queryCounter++ . '</b> : ' . $info . '<br />' . '<code><span class="sqlcode">' . nl2br($sql) . '</span></code>', 'sqlinfo');
         }
         return $result;
     } catch (Database_Exception $e) {
         if (claro_debug_mode()) {
             $duration = microtime() - $start;
             $info = 'execution time : ' . ($duration > 0.001 ? '<b>' . round($duration, 4) . '</b>' : '&lt;0.001') . '&#181;s';
             $info .= ': affected rows :' . $this->affectedRows();
             pushClaroMessage('<br />Query counter : <b>' . $this->queryCounter++ . '</b> : ' . $info . '<br />' . '<code><span class="sqlcode">' . nl2br($sql) . '</span></code>', 'error');
         }
         throw $e;
     }
 }
Example #14
0
/**
 * Terminate the script and display message
 *
 * @param string message
 */
function claro_die($message)
{
    FromKernel::uses('display/dialogBox.lib');
    $dialogBox = new DialogBox();
    $dialogBox->error($message);
    Claroline::getInstance()->display->setContent($dialogBox->render());
    if (claro_debug_mode()) {
        pushClaroMessage(var_export(debug_backtrace(), true), 'debug');
    }
    echo Claroline::getInstance()->display->render();
    die;
    // necessary to prevent any continuation of the application
}
 /**
  * Search in all activated modules
  *
  * @param string $cidReq
  */
 private function loadModuleRenderer()
 {
     if (!is_null($this->courseId)) {
         $profileId = claro_get_current_user_profile_id_in_course($this->courseId);
         $toolList = claro_get_course_tool_list($this->courseId, $profileId);
     } else {
         $toolList = claro_get_main_course_tool_list();
     }
     foreach ($toolList as $tool) {
         if (!is_null($tool['label'])) {
             $file = get_module_path($tool['label']) . '/connector/tracking.cnr.php';
             if (file_exists($file)) {
                 require_once $file;
                 if (claro_debug_mode()) {
                     pushClaroMessage('Tracking : ' . $tool['label'] . ' tracking renderers loaded', 'debug');
                 }
             }
         }
     }
 }
Example #16
0
 /**
  * Generate and set output to client
  *
  * @access  public
  */
 public function render()
 {
     try {
         $this->_globalVarsCompat();
         $contents = '';
         if (!$this->bannerAtEnd) {
             $contents .= $this->banner->render() . "\n";
         }
         $contents .= $this->body->render();
         if ($this->bannerAtEnd) {
             $contents .= $this->banner->render() . "\n";
         }
         $contents .= $this->footer->render() . "\n";
         if (claro_debug_mode()) {
             $contents .= claro_disp_debug_banner();
         }
         $output = '';
         $output .= $this->header->render();
         if (true === get_conf('warnSessionLost', true) && claro_get_current_user_id()) {
             $this->jsBodyOnload[] = 'claro_session_loss_countdown(' . ini_get('session.gc_maxlifetime') . ');';
         }
         $output .= '<body dir="' . get_locale('text_dir') . '"' . (!empty($this->jsBodyOnload) ? ' onload="' . implode('', $this->jsBodyOnload) . '" ' : '') . '>' . "\n";
         $output .= $contents;
         $output .= '</body>' . "\n";
         $output .= '</html>' . "\n";
         $this->header->sendHttpHeaders();
         return $output;
     } catch (Exception $e) {
         if (claro_debug_mode()) {
             die($e->__toString());
         } else {
             die($e->getMessage());
         }
     }
 }
Example #17
0
 /**
  * Load a list of plugins from a given module
  * Usage : From::module(ModuleLable)->loadPlugins( list of connectors );
  * @since Claroline 1.9.6
  * @params  list of plugins
  * @return  array of not found plugins
  */
 public function loadPlugins()
 {
     $args = func_get_args();
     $notFound = array();
     foreach ($args as $cnr) {
         if (substr($cnr, -4) !== '.php' && substr($cnr, -4) === '.lib') {
             $cnr .= '.php';
         } elseif (substr($cnr, -8) !== '.lib.php') {
             $cnr .= '.lib.php';
         }
         $cnr = protect_against_file_inclusion($cnr);
         $cnrPath = get_module_path($this->moduleLabel) . '/plugins/' . $cnr;
         if (file_exists($cnrPath)) {
             require_once $cnrPath;
         } else {
             if (claro_debug_mode()) {
                 throw new Exception("Cannot load plugin {$cnrPath}");
             }
             $notFound[] = $cnr;
             continue;
         }
     }
     return $notFound;
 }
Example #18
0
 /**
  *  SAX Parser Callback method : data handler
  */
 public function elementData($parser, $data)
 {
     $currentElement = end($this->elementPile);
     if (claro_debug_mode()) {
         $this->backlog->debug('The metadata ' . $currentElement . ' as been found with value ' . var_export($data, true));
     }
     switch ($currentElement) {
         case 'TYPE':
             $this->moduleInfo['TYPE'] = $data;
             break;
         case 'DESCRIPTION':
             $this->moduleInfo['DESCRIPTION'] = $data;
             break;
         case 'EMAIL':
             $parent = prev($this->elementPile);
             switch ($parent) {
                 case 'AUTHOR':
                     $this->moduleInfo['AUTHOR']['EMAIL'] = $data;
                     break;
             }
             break;
         case 'LABEL':
             $this->moduleInfo['LABEL'] = $data;
             break;
         case 'ENTRY':
             $this->moduleInfo['ENTRY'] = $data;
             break;
         case 'LICENSE':
             $this->moduleInfo['LICENSE'] = $data;
             break;
         case 'ICON':
             $this->moduleInfo['ICON'] = $data;
             break;
         case 'NAME':
             $parent = prev($this->elementPile);
             switch ($parent) {
                 case 'MODULE':
                     $this->moduleInfo['NAME'] = $data;
                     break;
                 case 'AUTHOR':
                     $this->moduleInfo['AUTHOR']['NAME'] = $data;
                     break;
             }
             break;
         case 'DEFAULT_DOCK':
             if (claro_debug_mode()) {
                 $this->backlog->debug('The use of default_dock is deprecated in manifest file, please use defaultDock instead');
             }
             // nobreak
         case 'DEFAULTDOCK':
             if (!array_key_exists('DEFAULT_DOCK', $this->moduleInfo)) {
                 $this->moduleInfo['DEFAULT_DOCK'] = array();
             }
             $this->moduleInfo['DEFAULT_DOCK'][] = $data;
             break;
         case 'WEB':
             $parent = prev($this->elementPile);
             switch ($parent) {
                 case 'MODULE':
                     $this->moduleInfo['WEB'] = $data;
                     break;
                 case 'AUTHOR':
                     $this->moduleInfo['AUTHOR']['WEB'] = $data;
                     break;
             }
             break;
             // PHP/MySQL/Claroline versions dependencies
             // TODO check in install
         // PHP/MySQL/Claroline versions dependencies
         // TODO check in install
         case 'MINVERSION':
             $parent = prev($this->elementPile);
             switch ($parent) {
                 case 'PHP':
                     $this->moduleInfo['PHP_MIN_VERSION'] = $data;
                     break;
                 case 'MYSQL':
                     $this->moduleInfo['MYSQL_MIN_VERSION'] = $data;
                     break;
                 case 'CLAROLINE':
                     $this->moduleInfo['CLAROLINE_MIN_VERSION'] = $data;
                     break;
             }
             break;
         case 'MAXVERSION':
             $parent = prev($this->elementPile);
             switch ($parent) {
                 case 'PHP':
                     $this->moduleInfo['PHP_MAX_VERSION'] = $data;
                     break;
                 case 'MYSQL':
                     $this->moduleInfo['MYSQL_MAX_VERSION'] = $data;
                     break;
                 case 'CLAROLINE':
                     $this->moduleInfo['CLAROLINE_MAX_VERSION'] = $data;
                     break;
             }
             break;
             // FIXME I'm not sure this is cool...
             // if VERSION is 1.8 what about 1.8.* ?
             // check the behaviour of version_compare...
         // FIXME I'm not sure this is cool...
         // if VERSION is 1.8 what about 1.8.* ?
         // check the behaviour of version_compare...
         case 'VERSION':
             $parent = prev($this->elementPile);
             switch ($parent) {
                 case 'MODULE':
                     $this->moduleInfo['VERSION'] = $data;
                     break;
                 case 'CLAROLINE':
                     $this->moduleInfo['CLAROLINE_MIN_VERSION'] = $data;
                     $this->moduleInfo['CLAROLINE_MAX_VERSION'] = $data;
                     break;
                 case 'PHP':
                     $this->moduleInfo['PHP_MIN_VERSION'] = $data;
                     $this->moduleInfo['PHP_MAX_VERSION'] = $data;
                     break;
                 case 'MYSQL':
                     $this->moduleInfo['MYSQL_MIN_VERSION'] = $data;
                     $this->moduleInfo['MYSQL_MAX_VERSION'] = $data;
                     break;
             }
             break;
         case 'CONTEXT':
             if (!array_key_exists('CONTEXTS', $this->moduleInfo)) {
                 $this->moduleInfo['CONTEXTS'] = array();
             }
             if (!in_array($data, $this->moduleInfo['CONTEXTS'])) {
                 $this->moduleInfo['CONTEXTS'][] = $data;
             }
             break;
     }
 }
Example #19
0
 protected static function loadDriver($driverConfigPath)
 {
     if (!file_exists($driverConfigPath)) {
         if (claro_debug_mode()) {
             throw new Exception("Driver configuration {$driverConfigPath} not found");
         }
         Console::error("Driver configuration {$driverConfigPath} not found");
         return;
     }
     $driverConfig = array();
     include $driverConfigPath;
     if ($driverConfig['driver']['enabled'] == true) {
         $driverClass = $driverConfig['driver']['class'];
         // search for kernel drivers
         if (class_exists($driverClass)) {
             $driver = new $driverClass();
             $driver->setDriverOptions($driverConfig);
             self::$drivers[$driverConfig['driver']['authSourceName']] = $driver;
         } else {
             // load dynamic drivers
             if (!file_exists(get_path('rootSys') . 'platform/conf/extauth/drivers')) {
                 FromKernel::uses('fileManage.lib');
                 claro_mkdir(get_path('rootSys') . 'platform/conf/extauth/drivers', CLARO_FILE_PERMISSIONS, true);
             }
             $driverPath = get_path('rootSys') . 'platform/conf/extauth/drivers/' . strtolower($driverClass) . '.drv.php';
             if (file_exists($driverPath)) {
                 require_once $driverPath;
                 if (class_exists($driverClass)) {
                     $driver = new $driverClass();
                     $driver->setDriverOptions($driverConfig);
                     self::$drivers[$driverConfig['driver']['authSourceName']] = $driver;
                 } else {
                     if (claro_debug_mode()) {
                         throw new Exception("Driver class {$driverClass} not found");
                     }
                     Console::error("Driver class {$driverClass} not found");
                 }
             } else {
                 if (claro_debug_mode()) {
                     throw new Exception("Driver class {$driverClass} not found");
                 }
                 Console::error("Driver class {$driverClass} not found");
             }
         }
     }
     if (isset($driverConfig['driver']['lostPasswordAllowed']) && $driverConfig['driver']['lostPasswordAllowed'] == true) {
         self::$driversAllowingLostPassword[$driverConfig['driver']['authSourceName']] = $driverConfig['driver']['authSourceName'];
     }
 }
Example #20
0
/**
 * Returns the url of the given icon
 *
 * @param string $fileName file name with or without extension
 * @param string $moduleLabel label of the module (optional)
 * @return string icon url
 *         mixed null if icon not found
 */
function get_icon_url($fileName, $moduleLabel = null)
{
    $fileInfo = pathinfo($fileName);
    $currentModuleLabel = get_current_module_label();
    $imgPath = array();
    // Search kernel first for performance !
    // claroline theme iconset
    $imgPath[get_current_iconset_path()] = get_current_iconset_url();
    // claroline web/img <--- is now the default location find using get_current_iconset_url
    //$imgPath[get_path( 'rootSys' ) . 'web/img/'] = get_path('url') . '/web/img/';
    if (!empty($moduleLabel)) {
        // module img directory
        $imgPath[get_module_path($moduleLabel) . '/img/'] = get_module_url($moduleLabel) . '/img/';
        // module root directory
        $imgPath[get_module_path($moduleLabel) . '/'] = get_module_url($moduleLabel) . '/';
    }
    if (!empty($currentModuleLabel)) {
        // module img directory
        $imgPath[get_module_path($currentModuleLabel) . '/img/'] = get_module_url($currentModuleLabel) . '/img/';
        // module root directory
        $imgPath[get_module_path($currentModuleLabel) . '/'] = get_module_url($currentModuleLabel) . '/';
    }
    // img directory in working directory
    $imgPath['./img/'] = './img/';
    // working directory
    $imgPath['./'] = './';
    if (!empty($fileInfo['extension'])) {
        $img = array($fileName);
    } else {
        $img = array($fileName . '.png', $fileName . '.gif');
    }
    foreach ($imgPath as $tryPath => $tryUrl) {
        foreach ($img as $tryImg) {
            if (claro_debug_mode()) {
                pushClaroMessage("Try " . $tryPath . $tryImg, 'debug');
            }
            if (file_exists($tryPath . $tryImg)) {
                if (claro_debug_mode()) {
                    pushClaroMessage("Using " . $tryPath . $tryImg, 'debug');
                }
                return $tryUrl . $tryImg . '?' . filemtime($tryPath . $tryImg);
            }
        }
    }
    if (claro_debug_mode()) {
        pushClaroMessage("Icon {$fileName} not found", 'error');
    }
    // WORKAROUND : avoid double submission if missing image !!!!
    return 'image_not_found.png';
}
Example #21
0
 public static function load_module_translation($moduleLabel = null, $language = null)
 {
     global $_lang;
     $moduleLabel = is_null($moduleLabel) ? get_current_module_label() : $moduleLabel;
     // In a module
     if (!empty($moduleLabel)) {
         $module_path = get_module_path($moduleLabel);
         $language = is_null($language) ? language::current_language() : $language;
         // load english by default if exists
         if (file_exists($module_path . '/lang/lang_english.php')) {
             /* FIXME : DEPRECATED !!!!! */
             $mod_lang = array();
             include $module_path . '/lang/lang_english.php';
             $_lang = array_merge($_lang, $mod_lang);
             if (claro_debug_mode()) {
                 pushClaroMessage(__FUNCTION__ . "::" . $moduleLabel . '::' . 'English lang file loaded', 'debug');
             }
         } else {
             // no language file to load
             if (claro_debug_mode()) {
                 pushClaroMessage(__FUNCTION__ . "::" . $moduleLabel . '::' . 'English lang file  not found', 'debug');
             }
         }
         // load requested language if exists
         if ($language != 'english' && file_exists($module_path . '/lang/lang_' . $language . '.php')) {
             /* FIXME : CODE DUPLICATION see 263-274 !!!!! */
             /* FIXME : DEPRECATED !!!!! */
             $mod_lang = array();
             include $module_path . '/lang/lang_' . $language . '.php';
             $_lang = array_merge($_lang, $mod_lang);
             if (claro_debug_mode()) {
                 pushClaroMessage(__FUNCTION__ . "::" . $moduleLabel . '::' . ucfirst($language) . ' lang file loaded', 'debug');
             }
         } elseif ($language != 'english') {
             // no language file to load
             if (claro_debug_mode()) {
                 pushClaroMessage(__FUNCTION__ . "::" . $moduleLabel . '::' . ucfirst($language) . ' lang file  not found', 'debug');
             }
         } else {
             // nothing to do
         }
     } else {
         // Not in a module
     }
 }
Example #22
0
 /**
  * Add an event generated by the platform to the tracking system
  * @param Event $event
  * @return boolean 
  */
 public function trackInPlatform($event)
 {
     $event_args = $event->getArgs();
     $cid = array_key_exists('cid', $event_args) ? $event_args['cid'] : null;
     $tid = array_key_exists('tid', $event_args) ? $event_args['tid'] : null;
     $uid = array_key_exists('uid', $event_args) ? $event_args['uid'] : null;
     $date = array_key_exists('date', $event_args) ? $event_args['date'] : claro_date("Y-m-d H:i:s");
     if (array_key_exists('data', $event_args)) {
         $data = serialize($event_args['data']);
     } else {
         $data = '';
     }
     $eventType = $event->getEventType();
     if (claro_debug_mode()) {
         Console::message('Data added in platform tracking ' . $eventType . ' : ' . var_export($event, true));
     }
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $tbl_tracking_event = $tbl_mdb_names['tracking_event'];
     $sql = "INSERT INTO `" . $tbl_tracking_event . "`\n                SET `course_code` = " . (is_null($cid) ? "NULL" : "'" . claro_sql_escape($cid) . "'") . ",\n                    `tool_id` = " . (is_null($tid) ? "NULL" : "'" . claro_sql_escape($tid) . "'") . ",\n                    `user_id` = " . (is_null($uid) ? "NULL" : "'" . claro_sql_escape($uid) . "'") . ",\n                    `date` = '" . $date . "',\n                    `type` = '" . claro_sql_escape($eventType) . "',\n                    `data` = '" . claro_sql_escape($data) . "'";
     return claro_sql_query($sql);
 }
Example #23
0
/**
 * Send e-mail to Claroline users form their ID a user of Claroline
 *
 * Send e-mail to Claroline users form their ID a user of Claroline
 * default from clause in email address will be the platorm admin adress
 * default from name clause in email will be the platform admin name and surname
 *
 * @author Hugues Peeters <*****@*****.**>
 * @param  int or array $userIdList - sender id's
 * @param  string $message - mail content
 * @param  string $subject - mail subject
 * @param  string $specificFrom (optional) sender's email address
 * @param  string  $specificFromName (optional) sender's name
 * @return int total count of sent email
 */
function claro_mail_user($userIdList, $message, $subject, $specificFrom = '', $specificFromName = '')
{
    if (!is_array($userIdList)) {
        $userIdList = array($userIdList);
    }
    if (count($userIdList) == 0) {
        return 0;
    }
    $tbl = claro_sql_get_main_tbl();
    $tbl_user = $tbl['user'];
    $sql = 'SELECT DISTINCT email
            FROM `' . $tbl_user . '`
            WHERE user_id IN (' . implode(', ', array_map('intval', $userIdList)) . ')';
    $emailList = claro_sql_query_fetch_all_cols($sql);
    $emailList = $emailList['email'];
    $emailList = array_filter($emailList, 'is_well_formed_email_address');
    $mail = new ClaroPHPMailer();
    if ($specificFrom != '') {
        $mail->From = $specificFrom;
    } else {
        $mail->From = get_conf('administrator_email');
    }
    if ($specificFromName != '') {
        $mail->FromName = $specificFromName;
    } else {
        $mail->FromName = get_conf('administrator_name');
    }
    $mail->Sender = $mail->From;
    if (strlen($subject) > 78) {
        $message = $subject . "\n" . $message;
        $subject = substr($subject, 0, 73) . '...';
    }
    $mail->Subject = $subject;
    $mail->Body = $message;
    $emailSentCount = 0;
    if (claro_debug_mode()) {
        $message = '<p>Subject : ' . claro_htmlspecialchars($subject) . '</p>' . "\n" . '<p>Message : <pre>' . claro_htmlspecialchars($message) . '</pre></p>' . "\n" . '<p>From : ' . claro_htmlspecialchars($mail->FromName) . ' - ' . claro_htmlspecialchars($mail->From) . '</p>' . "\n" . '<p>Dest : ' . implode(', ', $emailList) . '</p>' . "\n";
        pushClaroMessage($message, 'mail');
    }
    foreach ($emailList as $thisEmail) {
        $mail->AddAddress($thisEmail);
        if ($mail->Send()) {
            $emailSentCount++;
        } else {
            if (claro_debug_mode()) {
                pushClaroMessage($mail->getError(), 'error');
            }
        }
        $mail->ClearAddresses();
    }
    return $emailSentCount;
}
Example #24
0
 /**
  * Send a mail to the user list
  *
  * @param int $userIdList list of the user
  * @param string $message body of the mail
  * @param string $subject subject of the mail
  * @param string $specificFrom email of the sender
  * @param string $specificFromName name to display
  * @param string $altBody link of the message in case of problem of read
  * 
  */
 protected static function emailNotification($userIdList, $message, $subject, $specificFrom = '', $specificFromName = '', $altBody = '')
 {
     if (!is_array($userIdList)) {
         $userIdList = array($userIdList);
     }
     if (count($userIdList) == 0) {
         return 0;
     }
     $tbl = claro_sql_get_main_tbl();
     $tbl_user = $tbl['user'];
     $sql = 'SELECT DISTINCT email
             FROM `' . $tbl_user . '`
             WHERE user_id IN (' . implode(', ', array_map('intval', $userIdList)) . ')';
     $emailList = claro_sql_query_fetch_all_cols($sql);
     $emailList = $emailList['email'];
     $emailList = array_filter($emailList, 'is_well_formed_email_address');
     $mail = new ClaroPHPMailer();
     $mail->IsHTML(true);
     if (!empty($altBody)) {
         $mail->AltBody = $altBody;
     }
     if ($specificFrom != '') {
         $mail->From = $specificFrom;
     } else {
         $mail->From = get_conf('administrator_email');
     }
     if ($specificFromName != '') {
         $mail->FromName = $specificFromName;
     } else {
         $mail->FromName = get_conf('administrator_name');
     }
     $mail->Sender = $mail->From;
     if (strlen($subject) > 78) {
         $message = get_lang('Subject') . ' : ' . $subject . "<br />\n\n" . $message;
         $subject = substr($subject, 0, 73) . '...';
     }
     $mail->Subject = $subject;
     $mail->Body = $message;
     if (claro_debug_mode()) {
         $message = '<p>' . get_lang('Subject') . ' : ' . claro_htmlspecialchars($subject) . '</p>' . "\n" . '<p>' . get_lang('Message') . ' : <pre>' . claro_htmlspecialchars($message) . '</pre></p>' . "\n" . '<p>' . get_lang('Sender') . ' : ' . claro_htmlspecialchars($mail->FromName) . ' - ' . claro_htmlspecialchars($mail->From) . '</p>' . "\n" . '<p>' . get_lang('Recipient') . ' : ' . implode(', ', $emailList) . '</p>' . "\n";
         pushClaroMessage($message, 'mail');
     }
     $error_list = array();
     foreach ($emailList as $thisEmail) {
         try {
             $mail->AddAddress($thisEmail);
             $mail->Send();
         } catch (phpmailerException $exception) {
             if (claro_debug_mode()) {
                 pushClaroMessage('Mail Notification Failed ' . $exception->__toString());
                 $error_list[] = $thisEmail;
             }
         }
         $mail->ClearAddresses();
     }
 }
Example #25
0
 public function loadFromModule($moduleLabel, $lib, $media = 'all')
 {
     $lib = secure_file_path($lib);
     $moduleLabel = secure_file_path($moduleLabel);
     if (!get_module_data($moduleLabel)) {
         pushClaroMessage(__CLASS__ . "::{$moduleLabel} does not exists", 'error');
         return false;
     }
     if (claro_debug_mode()) {
         pushClaroMessage(__CLASS__ . "::Try to find {$lib} for {$moduleLabel}", 'debug');
     }
     $cssPath = array(0 => array('path' => get_path('rootSys') . 'platform/css/' . $moduleLabel . '/' . $lib . '.css', 'url' => get_path('url') . '/platform/css/' . $moduleLabel . '/' . $lib . '.css'), 1 => array('path' => get_module_path($moduleLabel) . '/css/' . $lib . '.css', 'url' => get_module_url($moduleLabel) . '/css/' . $lib . '.css'));
     /*$path = get_module_path( $moduleLabel ) . '/css/' . $lib . '.css';
       $url = get_module_url( $moduleLabel ) . '/css/' . $lib . '.css';*/
     foreach ($cssPath as $cssTry) {
         $path = $cssTry['path'];
         $url = $cssTry['url'];
         if (claro_debug_mode()) {
             pushClaroMessage(__CLASS__ . "::Try {$path}::{$url} for {$moduleLabel}", 'debug');
         }
         if (file_exists($path)) {
             if (array_key_exists($path, $this->css)) {
                 return false;
             }
             $this->css[$path] = array('url' => $url . '?' . filemtime($path), 'media' => $media);
             if (claro_debug_mode()) {
                 pushClaroMessage(__CLASS__ . "::Use {$path}::{$url} for {$moduleLabel}", 'debug');
             }
             ClaroHeader::getInstance()->addHtmlHeader('<link rel="stylesheet" type="text/css"' . ' href="' . $url . '"' . ' media="' . $media . '" />');
             return true;
         } else {
             if (claro_debug_mode()) {
                 pushClaroMessage(__CLASS__ . "::Cannot found css {$lib} for {$moduleLabel}", 'error');
             }
             return false;
         }
     }
 }
Example #26
0
}
// reset current module label after calling the cache
if (isset($tlabelReq) && get_current_module_label() != $tlabelReq) {
    // reset all previous occurence of module label in stack
    while (clear_current_module_label()) {
    }
    // set the current module label
    set_current_module_label($tlabelReq);
}
// Add feed RSS in header
if (claro_is_in_a_course() && get_conf('enableRssInCourse', true)) {
    require claro_get_conf_repository() . 'rss.conf.php';
    $claroline->display->header->addHtmlHeader('<link rel="alternate" type="application/rss+xml" title="' . claro_htmlspecialchars($_course['name'] . ' - ' . get_conf('siteName')) . '"' . ' href="' . get_path('url') . '/claroline/backends/rss.php?cidReq=' . claro_get_current_course_id() . '" />');
}
// timezone debug code
if (claro_debug_mode() && get_conf('clmain_serverTimezone', '')) {
    pushClaroMessage('timezone set to ' . date_default_timezone_get(), 'debug');
}
if (claro_is_in_a_course() && isset($tlabelReq) && $tlabelReq == 'CLQWZ') {
    require_once get_path('incRepositorySys') . '/../exercise/lib/add_missing_table.lib.php';
    init_qwz_questions_categories();
}
if (!claro_is_platform_admin()) {
    $courseStatus = claro_get_current_course_data('status');
    if ($courseStatus == 'trash' || $courseStatus == 'disable') {
        Claroline::getDisplay()->body->hideCourseTitleAndTools();
        claro_die(get_lang('This course is not available anymore, please contact the platform administrator.'));
    }
}
// post kernel access check
if (claro_is_in_a_course()) {