123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834 |
- <?php
- require_once __DIR__.'../../../vendor/autoload.php';
- use Silex\Application;
- use \ChamiloSession as Session;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Yaml\Parser;
- $includePath = dirname(__FILE__);
- $app = new Application();
- $configurationFilePath = $includePath.'/conf/configuration.php';
- $configurationYMLFile = $includePath.'/../../config/configuration.yml';
- $configurationFileAppPath = $includePath.'/../../config/configuration.php';
- $alreadyInstalled = false;
- if (file_exists($configurationFilePath) || file_exists($configurationYMLFile) || file_exists($configurationFileAppPath)) {
- if (file_exists($configurationFilePath)) {
- require_once $configurationFilePath;
- }
- if (file_exists($configurationFileAppPath)) {
- $configurationFilePath = $configurationFileAppPath;
- require_once $configurationFileAppPath;
- }
- $alreadyInstalled = true;
- } else {
- $_configuration = array();
- }
- if (file_exists($configurationYMLFile)) {
- $yaml = new Parser();
- $configurationYML = $yaml->parse(file_get_contents($configurationYMLFile));
- if (is_array($configurationYML) && !empty($configurationYML)) {
- if (isset($_configuration)) {
- $_configuration = array_merge($_configuration, $configurationYML);
- } else {
- $_configuration = $configurationYML;
- }
- }
- }
- $app['root_sys'] = isset($_configuration['root_sys']) ? $_configuration['root_sys'] : dirname(dirname(__DIR__)).'/';
- $app['sys_root'] = $app['root_sys'];
- $app['sys_data_path'] = isset($_configuration['sys_data_path']) ? $_configuration['sys_data_path'] : $app['root_sys'].'data/';
- $app['sys_config_path'] = isset($_configuration['sys_config_path']) ? $_configuration['sys_config_path'] : $app['root_sys'].'config/';
- $app['sys_temp_path'] = isset($_configuration['sys_temp_path']) ? $_configuration['sys_temp_path'] : $app['root_sys'].'temp/';
- $app['sys_log_path'] = isset($_configuration['sys_log_path']) ? $_configuration['sys_log_path'] : $app['root_sys'].'logs/';
- if ($alreadyInstalled) {
- $configPath = $app['sys_config_path'];
- $confFiles = array(
- 'auth.conf.php',
- 'events.conf.php',
- 'mail.conf.php',
- 'portfolio.conf.php',
- 'profile.conf.php'
- );
- foreach ($confFiles as $confFile) {
- if (file_exists($configPath.$confFile)) {
- require_once $configPath.$confFile;
- }
- }
-
-
- $administrator['email'] = isset($administrator['email']) ? $administrator['email'] : 'admin@example.com';
- $administrator['name'] = isset($administrator['name']) ? $administrator['name'] : 'Admin';
-
-
-
- $_configuration['dokeos_version'] = $_configuration['system_version'];
-
- $userPasswordCrypted = (!empty($_configuration['password_encryption']) ? $_configuration['password_encryption'] : 'sha1');
- }
- require_once $includePath.'/lib/api.lib.php';
- $urlInfo = isset($_configuration['root_web']) ? parse_url($_configuration['root_web']) : null;
- $_configuration['url_append'] = null;
- if (isset($urlInfo['path'])) {
- $_configuration['url_append'] = '/'.basename($urlInfo['path']);
- }
- $libPath = $includePath.'/lib/';
- $langPath = api_get_path(SYS_LANG_PATH);
- require_once $libPath.'database.constants.inc.php';
- require_once $libPath.'events.lib.inc.php';
- require_once $libPath.'formvalidator/Rule/allowed_tags.inc.php';
- ini_set('include_path', api_create_include_path_setting());
- $app['configuration_file'] = $configurationFilePath;
- $app['configuration_yml_file'] = $configurationYMLFile;
- $app['languages_file'] = array();
- $app['installed'] = $alreadyInstalled;
- $app['app.theme'] = 'chamilo';
- $app['debug'] = isset($_configuration['debug']) ? $_configuration['debug'] : false;
- $app['show_profiler'] = isset($_configuration['show_profiler']) ? $_configuration['show_profiler'] : false;
- $app['assetic.enabled'] = false;
- $app['assetic.auto_dump_assets'] = false;
- if ($app['debug']) {
- require_once __DIR__.'/../../src/ChamiloLMS/Resources/config/dev.php';
- } else {
- require_once __DIR__.'/../../src/ChamiloLMS/Resources/config/prod.php';
- }
- $app['classic_layout'] = false;
- $app['full_width'] = false;
- $app['breadcrumb'] = array();
- $app['allowed'] = true;
- $app->register(new Silex\Provider\SessionServiceProvider());
- $app['session.storage.options'] = array(
- 'name' => 'chamilo_session',
-
-
-
-
- 'cookie_httponly' => true
- );
- $app['template.show_header'] = true;
- $app['template.show_footer'] = true;
- $app['template.show_learnpath'] = false;
- $app['template.hide_global_chat'] = true;
- $app['template.load_plugins'] = true;
- $app['configuration'] = $_configuration;
- $_plugins = array();
- if ($alreadyInstalled) {
-
- require_once 'services.php';
-
- $database = $app['database'];
-
- $_configuration['access_url'] = 1;
- if (api_get_multiple_access_url()) {
- $access_urls = api_get_access_urls();
- $protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') ? 'https' : 'http').'://';
- $request_url1 = $protocol.$_SERVER['SERVER_NAME'].'/';
- $request_url2 = $protocol.$_SERVER['HTTP_HOST'].'/';
- foreach ($access_urls as & $details) {
- if ($request_url1 == $details['url'] or $request_url2 == $details['url']) {
- $_configuration['access_url'] = $details['id'];
- }
- }
-
-
- } else {
-
- }
- }
- $charset = 'UTF-8';
- $app->error(
- function (\Exception $e, $code) use ($app) {
- if ($app['debug']) {
-
- }
- $message = null;
- if (isset($code)) {
- switch ($code) {
- case 401:
- $message = 'Unauthorized';
- break;
- case 404:
- $message = 'The requested page could not be found.';
- break;
- default:
-
- $message = $e->getMessage();
- }
- } else {
- $code = null;
- }
-
-
-
-
- $templateStyle = api_get_setting('template');
- $templateStyle = isset($templateStyle) && !empty($templateStyle) ? $templateStyle : 'default';
- $app['template_style'] = $templateStyle;
-
- $app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl';
- $app['template']->assign('error', array('code' => $code, 'message' => $message));
- $response = $app['template']->render_layout('error.tpl');
- return new Response($response);
- }
- );
- $charset_initial_value = $charset;
- $app['this_section'] = SECTION_GLOBAL;
- require_once $libPath.'internationalization.lib.php';
- require_once $libPath.'internationalization_internal.lib.php';
- $cidReset = null;
- if ($alreadyInstalled) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- } else {
- $app['language_interface'] = $language_interface = $language_interface_initial_value = 'english';
- }
- use Symfony\Component\Translation\Loader\PoFileLoader;
- use Symfony\Component\Translation\Loader\MoFileLoader;
- use Symfony\Component\Finder\Finder;
- $app->before(
- function () use ($app) {
-
- if (!file_exists($app['configuration_file']) && !file_exists($app['configuration_yml_file'])) {
- return new RedirectResponse(api_get_path(WEB_CODE_PATH).'install');
- $app->abort(500, "Configuration file was not found");
- }
-
- if (api_check_php_version() == false) {
- $app->abort(500, "Incorrect PHP version");
- }
-
- if (!is_writable(api_get_path(SYS_ARCHIVE_PATH))) {
- $app->abort(500, "temp folder must be writable");
- }
-
- $request = $app['request'];
-
- $request->getSession()->start();
-
- $filesystem = $app['chamilo.filesystem'];
- if ($app['debug']) {
-
- $filesystem->createFolders($app['temp.paths']->folders);
- }
-
- if ($app['assetic.auto_dump_assets']) {
- $filesystem->copyFolders($app['temp.paths']->copyFolders);
- }
-
- Online::loginCheck(api_get_user_id());
-
- if (api_get_multiple_access_url()) {
-
- global $_configuration;
- Session::write('url_id', $_configuration['access_url']);
- Session::write('url_info', api_get_current_access_url_info($_configuration['access_url']));
- } else {
- Session::write('url_id', 1);
- }
-
- $settings_refresh_info = api_get_settings_params_simple(array('variable = ?' => 'settings_latest_update'));
- $settings_latest_update = $settings_refresh_info ? $settings_refresh_info['selected_value'] : null;
- $_setting = Session::read('_setting');
- if (empty($_setting)) {
- api_set_settings_and_plugins();
- } else {
- if (isset($_setting['settings_latest_update']) && $_setting['settings_latest_update'] != $settings_latest_update) {
- api_set_settings_and_plugins();
- }
- }
- $_setting = Session::read('_setting');
- $_plugins = Session::read('_plugins');
-
- $templateStyle = api_get_setting('template');
- $templateStyle = isset($templateStyle) && !empty($templateStyle) ? $templateStyle : 'default';
- $app['template_style'] = $templateStyle;
-
- $app['default_layout'] = $app['template_style'].'/layout/layout_1_col.tpl';
- $app['plugins'] = $_plugins;
-
- $app['api_get_languages'] = api_get_languages();
- $app['language_interface'] = $language_interface = api_get_language_interface();
-
- $app['template.hide_global_chat'] = !api_is_global_chat_enabled();
-
-
- $default_quota = api_get_setting('default_document_quotum');
-
- if (empty($default_quota)) {
- $default_quota = 100000000;
- }
- define('DEFAULT_DOCUMENT_QUOTA', $default_quota);
-
-
-
-
- $default_username_length = 40;
- if (api_get_setting('login_is_email') == 'true') {
- $default_username_length = 100;
- }
- define('USERNAME_MAX_LENGTH', $default_username_length);
- $user = null;
-
- if ($app['security']->isGranted('IS_AUTHENTICATED_FULLY')) {
-
- $token = $app['security']->getToken();
- if (null !== $token) {
-
- $user = $token->getUser();
- }
-
- $userInfo = api_get_user_info($user->getUserId());
- $userInfo['is_anonymous'] = false;
- Session::write('_user', $userInfo);
- $app['current_user'] = $userInfo;
-
- if ($app['security']->isGranted('ROLE_ADMIN')) {
- Session::write('is_platformAdmin', true);
- }
-
- if ($app['security']->isGranted('ROLE_TEACHER')) {
- Session::write('is_allowedCreateCourse', true);
- }
- } else {
- Session::erase('_user');
- Session::erase('is_platformAdmin');
- Session::erase('is_allowedCreateCourse');
- }
-
-
- $language = api_get_setting('platformLanguage');
- $iso = api_get_language_isocode($language);
- $app['translator']->setLocale($iso);
-
- $language = $request->get('language');
- if (!empty($language)) {
- $iso = api_get_language_isocode($language);
- $app['translator']->setLocale($iso);
- }
-
- if ($user) {
-
-
- $language = $userInfo['language'];
- $iso = api_get_language_isocode($language);
- $app['translator']->setLocale($iso);
- }
-
- $courseInfo = api_get_course_info();
- if ($courseInfo && !empty($courseInfo)) {
- $iso = api_get_language_isocode($courseInfo['language']);
- $app['translator']->setLocale($iso);
- }
- $file = $request->get('file');
- $section = null;
- if (!empty($file)) {
- $info = pathinfo($file);
- $section = $info['dirname'];
- }
- $app['translator.cache.enabled'] = false;
- $app['translator'] = $app->share($app->extend('translator', function($translator, $app) {
- $locale = $translator->getLocale();
-
- if ($app['translator.cache.enabled']) {
-
- $dumper = new Symfony\Component\Translation\Dumper\MoFileDumper();
- $catalogue = new Symfony\Component\Translation\MessageCatalogue($locale);
- $catalogue->add(array('foo' => 'bar'));
- $dumper->dump($catalogue, array('path' => $app['sys_temp_path']));
- } else {
- $translator->addLoader('pofile', new PoFileLoader());
- $filePath = api_get_path(SYS_PATH).'main/locale/'.$locale.'.po';
- if (!file_exists($filePath)) {
- $filePath = api_get_path(SYS_PATH).'main/locale/en.po';
- }
- $translator->addResource('pofile', $filePath, $locale);
-
- return $translator;
- }
- }));
- }
- );
- $app->after(
- function (Request $request, Response $response) {
- }
- );
- $app->finish(
- function (Request $request) use ($app) {
- }
- );
- $charset = $charset_initial_value;
- $text_dir = api_get_text_direction();
- if (!isset($_SESSION['login_as']) && isset($_user)) {
-
- $tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
- $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login
- WHERE login_user_id = '".api_get_user_id()."'
- ORDER BY login_date DESC LIMIT 0,1";
- $q_last_connection = Database::query($sql_last_connection);
- if (Database::num_rows($q_last_connection) > 0) {
- $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
-
- $sql_logout_date = "SELECT logout_date FROM $tbl_track_login WHERE login_id = $i_id_last_connection";
- $q_logout_date = Database::query($sql_logout_date);
- $res_logout_date = api_convert_sql_date(Database::result($q_logout_date, 0, 'logout_date'));
- if ($res_logout_date < time() - $app['configuration']['session_lifetime']) {
-
- $q_last_connection = Database::query($sql_last_connection);
- $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id');
- }
- $now = api_get_utc_datetime();
- $s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date = '$now' WHERE login_id = $i_id_last_connection";
- Database::query($s_sql_update_logout_date);
- } else {
-
- event_login();
- }
- }
- if (isset($app['configuration']['language_measure_frequency']) && $app['configuration']['language_measure_frequency'] == 1) {
- require_once api_get_path(SYS_CODE_PATH).'/cron/lang/langstats.class.php';
- $langstats = new langstats();
- }
- $app['is_admin'] = false;
- require_once 'routes.php';
- if (isset($app['configuration']['main_database']) && isset($app['db.event_manager'])) {
-
- $sortableGroup = new Gedmo\Mapping\Annotation\SortableGroup(array());
- $sortablePosition = new Gedmo\Mapping\Annotation\SortablePosition(array());
- $tree = new Gedmo\Mapping\Annotation\Tree(array());
- $tree = new Gedmo\Mapping\Annotation\TreeParent(array());
- $tree = new Gedmo\Mapping\Annotation\TreeLeft(array());
- $tree = new Gedmo\Mapping\Annotation\TreeRight(array());
- $tree = new Gedmo\Mapping\Annotation\TreeRoot(array());
- $tree = new Gedmo\Mapping\Annotation\TreeLevel(array());
- $tree = new Gedmo\Mapping\Annotation\Versioned(array());
- $tree = new Gedmo\Mapping\Annotation\Loggable(array());
- $tree = new Gedmo\Loggable\Entity\LogEntry();
-
- $timestampableListener = new \Gedmo\Timestampable\TimestampableListener();
-
- $app['dbs.event_manager']['db_read']->addEventSubscriber($timestampableListener);
- $app['dbs.event_manager']['db_write']->addEventSubscriber($timestampableListener);
- $sluggableListener = new \Gedmo\Sluggable\SluggableListener();
-
- $app['dbs.event_manager']['db_read']->addEventSubscriber($sluggableListener);
- $app['dbs.event_manager']['db_write']->addEventSubscriber($sluggableListener);
- $sortableListener = new Gedmo\Sortable\SortableListener();
-
- $app['dbs.event_manager']['db_read']->addEventSubscriber($sortableListener);
- $app['dbs.event_manager']['db_write']->addEventSubscriber($sortableListener);
- $treeListener = new \Gedmo\Tree\TreeListener();
-
-
- $app['dbs.event_manager']['db_read']->addEventSubscriber($treeListener);
- $app['dbs.event_manager']['db_write']->addEventSubscriber($treeListener);
- $loggableListener = new \Gedmo\Loggable\LoggableListener();
- if (PHP_SAPI != 'cli') {
- $userInfo = api_get_user_info();
- if (isset($userInfo) && !empty($userInfo['username'])) {
- $loggableListener->setUsername($userInfo['username']);
- }
- }
-
- $app['dbs.event_manager']['db_read']->addEventSubscriber($loggableListener);
- $app['dbs.event_manager']['db_write']->addEventSubscriber($loggableListener);
- }
- return $app;
|