From 07a90bdfd99cf480de2f4ddfbda4be739c14cad5 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 11 Sep 2014 11:48:48 +0200 Subject: [PATCH] Updating platform settings, adding twig functions and helpers. --- main/admin/synchro.php | 3 - main/admin/user_add.php | 27 +-- main/admin/user_edit.php | 23 +- main/admin/user_list.php | 9 +- main/inc/lib/api.lib.php | 219 ++++-------------- .../formvalidator/Element/select_language.php | 21 +- main/inc/lib/internationalization.lib.php | 10 +- main/inc/lib/usermanager.lib.php | 69 ++++-- .../EventListener/LegacyListener.php | 2 +- .../EventListener/LoginSuccessHandler.php | 5 +- .../views/Mailer/User/new_user.html.twig | 1 + .../views/Mailer/User/new_user.text.twig | 22 ++ .../Settings/AgendaSettingsSchema.php | 2 +- .../Settings/DisplaySettingsSchema.php | 2 +- .../Settings/DocumentSettingsSchema.php | 4 +- .../Settings/ExerciseSettingsSchema.php | 4 +- .../Settings/GradebookSettingsSchema.php | 4 +- .../Settings/MessageSettingsSchema.php | 2 +- .../Settings/ProfileSettingsSchema.php | 2 +- .../Settings/SearchSettingsSchema.php | 2 +- .../Resources/config/services.xml | 13 ++ .../Templating/Helper/SettingsHelper.php | 17 ++ .../SettingsBundle/Twig/SettingsExtension.php | 71 ++++++ 23 files changed, 283 insertions(+), 251 deletions(-) create mode 100644 src/Chamilo/CoreBundle/Resources/views/Mailer/User/new_user.html.twig create mode 100644 src/Chamilo/CoreBundle/Resources/views/Mailer/User/new_user.text.twig create mode 100644 src/Chamilo/SettingsBundle/Templating/Helper/SettingsHelper.php create mode 100644 src/Chamilo/SettingsBundle/Twig/SettingsExtension.php diff --git a/main/admin/synchro.php b/main/admin/synchro.php index eadb8509cb..7f9049c620 100755 --- a/main/admin/synchro.php +++ b/main/admin/synchro.php @@ -138,9 +138,6 @@ $form->addElement('textarea','description',get_lang('Note')); //$defaults['url']='http://'; $defaults['url'] = $_SERVER['REMOTE_ADDR']; -//$defaults['admin_mail'] = api_get_setting('emailAdministrator'); -//$defaults['admin_name'] = api_get_setting('administratorSurname').', '.api_get_setting('administratorName'); -//$defaults['admin_phone'] = api_get_setting('administratorTelephone'); $form->setDefaults($defaults); $submit_name = get_lang('SentSincroClientData'); diff --git a/main/admin/user_add.php b/main/admin/user_add.php index e77adc9f3f..e3e23516ff 100644 --- a/main/admin/user_add.php +++ b/main/admin/user_add.php @@ -111,11 +111,11 @@ $form->applyFilter('official_code', 'trim'); // Email $form->addElement('text', 'email', get_lang('Email'), array('size' => '40')); $form->addRule('email', get_lang('EmailWrong'), 'email'); -if (api_get_setting('registration', 'email') == 'true') { +/*if (api_get_setting('registration', 'email') == 'true') { $form->addRule('email', get_lang('EmailWrong'), 'required'); -} +}*/ -if (api_get_setting('login_is_email') == 'true') { +if (api_get_setting('profile.login_is_email') == 'true') { $form->addRule( 'email', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), @@ -134,7 +134,7 @@ $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types); // Username -if (api_get_setting('login_is_email') != 'true') { +if (api_get_setting('profile.login_is_email') != 'true') { $form->addElement('text', 'username', get_lang('LoginName'), array('id'=> 'username', 'maxlength' => USERNAME_MAX_LENGTH)); $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH); @@ -146,6 +146,7 @@ if (api_get_setting('login_is_email') != 'true') { $group = array(); $auth_sources = 0; //make available wider as we need it in case of form reset (see below) $nb_ext_auth_source_added = 0; +/* if (isset($extAuthSource) && count($extAuthSource) > 0) { $auth_sources = array(); foreach ($extAuthSource as $key => $info) { @@ -163,7 +164,7 @@ if (isset($extAuthSource) && count($extAuthSource) > 0) { $group[] = $form->createElement('select', 'auth_source', null, $auth_sources); $group[] = $form->createElement('static', '', '', '
'); } -} +}*/ $group[] = $form->createElement('radio', 'password_auto', get_lang('Password'), get_lang('AutoGeneratePassword').'
', 1); $group[] = $form->createElement('radio', 'password_auto', 'id="radio_user_password"', null, 0); @@ -199,7 +200,7 @@ if (isset($drh_list) && is_array($drh_list)) { } } $form->addElement('html', ''); - +/* if (api_is_platform_admin()) { // Platform admin $group = array(); @@ -209,7 +210,7 @@ if (api_is_platform_admin()) { $form->addElement('html', '
'); $form->addGroup($group, 'admin', get_lang('PlatformAdmin'), ' '); $form->addElement('html', '
'); -} +}*/ $form->addElement('select_language', 'language', get_lang('Language'), null); @@ -252,7 +253,7 @@ $defaults['mail']['send_mail'] = 1; $defaults['password']['password_auto'] = 1; $defaults['active'] = 1; $defaults['expiration_date'] = array(); -$days = api_get_setting('account_valid_duration'); +$days = api_get_setting('profile.account_valid_duration'); $time = strtotime('+'.$days.' day'); $defaults['expiration_date']['d'] = date('d', $time); $defaults['expiration_date']['F'] = date('m', $time); @@ -281,7 +282,7 @@ if( $form->validate()) { $status = intval($user['status']); $language = $user['language']; $picture = $_FILES['picture']; - $platform_admin = intval($user['admin']['platform_admin']); + //$platform_admin = intval($user['admin']['platform_admin']); $send_mail = intval($user['mail']['send_mail']); $hr_dept_id = isset($user['hr_dept_id']) ? intval($user['hr_dept_id']) : 0; @@ -301,7 +302,7 @@ if( $form->validate()) { $active = intval($user['active']); - if (api_get_setting('login_is_email') == 'true') { + if (api_get_setting('profile.login_is_email') == 'true') { $username = $email; } @@ -368,9 +369,9 @@ if( $form->validate()) { UserManager::update_extra_field_value($user_id, substr($key, 6), $value); } } - if ($platform_admin) { + /*if ($platform_admin) { UserManager::add_user_as_admin($user_id); - } + }*/ $message = get_lang('UserAdded'); } if (isset($user['submit_plus'])) { @@ -401,4 +402,4 @@ $app['title'] = $tool_name; //$tpl = $app['template']; echo $message; -echo $content; \ No newline at end of file +echo $content; diff --git a/main/admin/user_edit.php b/main/admin/user_edit.php index debc36ef68..b9c70c33a6 100644 --- a/main/admin/user_edit.php +++ b/main/admin/user_edit.php @@ -110,11 +110,11 @@ $form->applyFilter('official_code', 'trim'); // Email $form->addElement('text', 'email', get_lang('Email'), array('size' => '40')); $form->addRule('email', get_lang('EmailWrong'), 'email'); -if (api_get_setting('registration', 'email') == 'true') { +/*if (api_get_setting('registration', 'email') == 'true') { $form->addRule('email', get_lang('EmailWrong'), 'required'); -} +}*/ -if (api_get_setting('login_is_email') == 'true') { +if (api_get_setting('profile.login_is_email') == 'true') { $form->addRule( 'email', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), @@ -125,9 +125,9 @@ if (api_get_setting('login_is_email') == 'true') { } // OpenID -if (api_get_setting('openid_authentication') == 'true') { +/*if (api_get_setting('openid_authentication') == 'true') { $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => '40')); -} +}*/ // Phone $form->addElement('text', 'phone', get_lang('PhoneNumber')); @@ -147,7 +147,7 @@ if (strlen($user_data['picture_uri']) > 0) { // Username -if (api_get_setting('login_is_email') != 'true') { +if (api_get_setting('profile.login_is_email') != 'true') { $form->addElement('text', 'username', get_lang('LoginName'), array('maxlength' => USERNAME_MAX_LENGTH)); $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required'); $form->addRule( @@ -402,11 +402,11 @@ if ($form->validate()) { $extraFieldValues->save_field_values($user); $tok = Security::get_token(); - +/* header( 'Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserUpdated')).'&sec_token='.$tok ); - exit(); + exit();*/ } } @@ -430,13 +430,6 @@ $big_image_width = $big_image_size['width']; $big_image_height = $big_image_size['height']; $url_big_image = $big_image.'?rnd='.time(); -/*$content = null; -if ($image == '') { - $content .= ''; -} else { - $content .= ''; -}*/ - // Display form $content = $form->return_form(); diff --git a/main/admin/user_list.php b/main/admin/user_list.php index 96fe3f43e2..77d9bb0146 100644 --- a/main/admin/user_list.php +++ b/main/admin/user_list.php @@ -817,4 +817,11 @@ echo $message; echo $actions; echo $form.$table_result.$extra_search_options; - +/*var_dump(Container::getSettingsManager()->getSetting('platform +.administrator_name')); +$sender_name = api_get_person_name( + api_get_setting('administratorName'), + api_get_setting('administratorSurname'), + null, + PERSON_NAME_EMAIL_ADDRESS +); var_dump($sender_name);*/ diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index c24aa85e97..a0d796c79c 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -2118,7 +2118,11 @@ function api_get_session_condition($session_id, $and = true, $with_base_content * @author René Haentjens * @author Bart Mollet */ -function api_get_setting($variable, $key = null) { +function api_get_setting($variable, $key = null) +{ + return Container::getSettingsManager()->getSetting($variable); + + //chamilo_core.settings_schema.platform $_setting = Session::read('_setting'); if ($variable == 'header_extra_content') { @@ -3487,23 +3491,22 @@ function api_display_language_form($hide_if_no_choice = false) { * array['name'] = An array with the name of every language * array['folder'] = An array with the corresponding names of the language-folders in the filesystem */ -function api_get_languages() { - $language_list = Session::read('_setting.api_get_languages'); - if (isset($language_list) && !empty($language_list)) { - return $language_list; +function api_get_languages() +{ + $languageList = Session::read('_setting.api_get_languages'); + if (isset($languageList) && !empty($languageList)) { + return $languageList; } $tbl_language = Database::get_main_table(TABLE_MAIN_LANGUAGE); $sql = "SELECT * FROM $tbl_language WHERE available = '1' ORDER BY original_name ASC"; $result = Database::query($sql); - $language_list = array(); - while ($row = Database::fetch_array($result)) { - $language_list['name'][] = $row['original_name']; - //$language_list['folder'][] = $row['dokeos_folder']; - $language_list['folder'][] = $row['original_name']; + $languageList = array(); + while ($row = Database::fetch_array($result, 'ASSOC')) { + $languageList[] = $row; } - Session::write('_setting.api_get_languages', $language_list); - return $language_list; + Session::write('_setting.api_get_languages', $languageList); + return $languageList; } /** @@ -3581,7 +3584,10 @@ function api_get_language_info($language_id) { * The returned name depends on the platform, course or user -wide settings. * @return string The visual theme's name, it is the name of a folder inside .../chamilo/main/css/ */ -function api_get_visual_theme() { +function api_get_visual_theme() +{ + return 'chamilo'; + static $visual_theme; if (!isset($visual_theme)) { @@ -6475,9 +6481,7 @@ function api_mail_html( $data_file = array(), $embedded_image = false, $text_body = null - ) { - global $app; - +) { $reply_to_mail = $sender_email; $reply_to_name = $sender_name; @@ -6506,178 +6510,45 @@ function api_mail_html( ->setFrom(array($sender_email => $sender_name)) ->setTo(array($recipient_email => $recipient_name)) ->setReplyTo(array($reply_to_mail => $reply_to_name)) - ->setBody($htmlBody, 'text/html') - ->addPart($textBody, 'text/plain') + ->setBody( + Container::getTemplate()->render( + 'ChamiloCoreBundle:Mailer:Default/default.html.twig', + array( + 'content' => $htmlBody + ) + ), + 'text/html' + ) + ->addPart( + Container::getTemplate()->render( + 'ChamiloCoreBundle:Mailer:Default/default.text.twig', + array( + 'content' => $textBody + ) + ), + 'text/plain' + ) ->setEncoder(Swift_Encoding::get8BitEncoding()); + if (!empty($data_file)) { // Attach it to the message - $message->attach(Swift_Attachment::fromPath($data_file['path']))->setFilename($data_file['filename']); + $message->attach( + Swift_Attachment::fromPath($data_file['path']) + )->setFilename($data_file['filename']); } $type = $message->getHeaders()->get('Content-Type'); $type->setValue('text/html'); $type->setParameter('charset', 'utf-8'); + Container::getMailer()->send($message); - $app['monolog']->addDebug($message); - $result = $app['mailer']->send($message); + return true; - return $result; } catch (Exception $e) { - //$app['monolog']->addDebug('Email address not valid:' . $e->getMessage()); + error_log($e->getMessage()); } return false; - - /* - $mail = new PHPMailer(); - $mail->Mailer = $platform_email['SMTP_MAILER']; - $mail->Host = $platform_email['SMTP_HOST']; - $mail->Port = $platform_email['SMTP_PORT']; - $mail->CharSet = $platform_email['SMTP_CHARSET']; - $mail->WordWrap = 200; // Stay far below SMTP protocol 980 chars limit. - - if ($platform_email['SMTP_AUTH']) { - $mail->SMTPAuth = 1; - $mail->Username = $platform_email['SMTP_USER']; - $mail->Password = $platform_email['SMTP_PASS']; - } - - $mail->Priority = 3; // 5 = low, 1 = high - $mail->AddCustomHeader('Errors-To: '.$platform_email['SMTP_FROM_EMAIL']); - - $mail->SMTPKeepAlive = true; - - if (($sender_email != '') && ($sender_name != '')) { - $mail->AddReplyTo($sender_email, $sender_name); - } - - if (isset($extra_headers['reply_to'])) { - $mail->AddReplyTo($extra_headers['reply_to']['mail'], $extra_headers['reply_to']['name']); - } - - // Attachments - // $mail->AddAttachment($path); - // $mail->AddAttachment($path, $filename); - - if ($sender_email != '') { - $mail->From = $sender_email; - $mail->Sender = $sender_email; - //$mail->ConfirmReadingTo = $sender_email; // Disposition-Notification - } else { - $mail->From = $platform_email['SMTP_FROM_EMAIL']; - $mail->Sender = $platform_email['SMTP_FROM_EMAIL']; - //$mail->ConfirmReadingTo = $platform_email['SMTP_FROM_EMAIL']; // Disposition-Notification - } - - if ($sender_name != '') { - $mail->FromName = $sender_name; - } else { - $mail->FromName = $platform_email['SMTP_FROM_NAME']; - } - $mail->Subject = $subject; - - $mail->AltBody = strip_tags(str_replace('
',"\n", api_html_entity_decode($message))); - - // Send embedded image. - if ($embedded_image) { - // Get all images html inside content. - preg_match_all("/]*)[\"\']?[^>]*>/i", $message, $m); - // Prepare new tag images. - $new_images_html = array(); - $i = 1; - if (!empty($m[1])) { - foreach ($m[1] as $image_path) { - $real_path = realpath($image_path); - $filename = basename($image_path); - $image_cid = $filename.'_'.$i; - $encoding = 'base64'; - $image_type = mime_content_type($real_path); - $mail->AddEmbeddedImage($real_path, $image_cid, $filename, $encoding, $image_type); - $new_images_html[] = ''; - $i++; - } - } - - // Replace origin image for new embedded image html. - $x = 0; - if (!empty($m[0])) { - foreach ($m[0] as $orig_img) { - $message = str_replace($orig_img, $new_images_html[$x], $message); - $x++; - } - } - } - - $message = str_replace(array("\n\r", "\n", "\r"), '
', $message); - $mail->Body = ''.$message.''; - - // Attachment ... - if (!empty($data_file)) { - $mail->AddAttachment($data_file['path'], $data_file['filename']); - } - - // Only valid addresses are accepted. - if (is_array($recipient_email)) { - foreach ($recipient_email as $dest) { - if (api_valid_email($dest)) { - $mail->AddAddress($dest, $recipient_name); - //$mail->AddAddress($dest, ($i > 1 ? '' : $recipient_name)); - } - } - } else { - if (api_valid_email($recipient_email)) { - $mail->AddAddress($recipient_email, $recipient_name); - } else { - return 0; - } - } - - if (is_array($extra_headers) && count($extra_headers) > 0) { - foreach ($extra_headers as $key => $value) { - switch (strtolower($key)) { - case 'reply-to': - //the value here is the result of api_get_user_info() - $sender_email = $value['email']; - $sender_name = $value['complete_name']; - $mail->AddReplyTo($sender_email, $sender_name); - break; - case 'encoding': - case 'content-transfer-encoding': - $mail->Encoding = $value; - break; - case 'charset': - $mail->Charset = $value; - break; - case 'contenttype': - case 'content-type': - $mail->ContentType = $value; - break; - default: - $mail->AddCustomHeader($key.':'.$value); - break; - } - } - } else { - if (!empty($extra_headers)) { - $mail->AddCustomHeader($extra_headers); - } - } - - // WordWrap the html body (phpMailer only fixes AltBody) FS#2988 - $mail->Body = $mail->WrapText($mail->Body, $mail->WordWrap); - - // Send the mail message. - if (!$mail->Send()) { - //echo 'ERROR: mail not sent to '.$recipient_name.' ('.$recipient_email.') because of '.$mail->ErrorInfo.'
'; - error_log('ERROR: mail not sent to '.$recipient_name.' ('.$recipient_email.') because of '.$mail->ErrorInfo.'
'); - return 0; - } - - // Clear all the addresses. - $mail->ClearAddresses(); - - return 1; - */ } function api_set_login_language($lang) { diff --git a/main/inc/lib/formvalidator/Element/select_language.php b/main/inc/lib/formvalidator/Element/select_language.php index a7ec927858..33068e0911 100644 --- a/main/inc/lib/formvalidator/Element/select_language.php +++ b/main/inc/lib/formvalidator/Element/select_language.php @@ -1,5 +1,6 @@ _options = array(); $this->_values = array(); - foreach ($languages['name'] as $index => $name) { - if($languages['folder'][$index] == api_get_setting('platformLanguage')) { - $this->addOption($name,$languages['folder'][$index],array('selected'=>'selected')); - } else { - $this->addOption($name,$languages['folder'][$index]); - } + $platformLanguage = Container::getTranslator()->getLocale(); + foreach ($languages as $language) { + if ($language['isocode'] == $platformLanguage) { + $this->addOption( + $language['english_name'], + $language['isocode'], + array('selected' => 'selected') + ); + } else { + $this->addOption($language['english_name'], $language['isocode']); + } } } } diff --git a/main/inc/lib/internationalization.lib.php b/main/inc/lib/internationalization.lib.php index ecc70e8928..ce24d272d0 100644 --- a/main/inc/lib/internationalization.lib.php +++ b/main/inc/lib/internationalization.lib.php @@ -237,15 +237,17 @@ function api_get_timezones() */ function _api_get_timezone() { + return date_default_timezone_get(); $userId = api_get_user_id(); // First, get the default timezone of the server $to_timezone = date_default_timezone_get(); + // Second, see if a timezone has been chosen for the platform - $timezone_value = api_get_setting('timezone_value', 'timezones'); + /*$timezone_value = api_get_setting('timezone_value', 'timezones'); if ($timezone_value != null) { $to_timezone = $timezone_value; - } + }*/ // If allowed by the administrator $use_users_timezone = api_get_setting('use_users_timezone', 'timezones'); @@ -709,7 +711,7 @@ function api_get_person_name($first_name, $last_name, $title = null, $format = n switch ($format) { case PERSON_NAME_COMMON_CONVENTION: $valid[$format][$language] = _api_get_person_name_convention($language, 'format'); - $usernameOrderFromDatabase = api_get_setting('user_name_order'); + $usernameOrderFromDatabase = api_get_setting('display.user_name_order'); if (isset($usernameOrderFromDatabase) && !empty($usernameOrderFromDatabase)) { $valid[$format][$language] = $usernameOrderFromDatabase; } @@ -787,7 +789,7 @@ function api_is_western_name_order($format = null, $language = null) */ function api_sort_by_first_name($language = null) { - $userNameSortBy = api_get_setting('user_name_sort_by'); + $userNameSortBy = api_get_setting('display.user_name_sort_by'); if (!empty($userNameSortBy) && in_array($userNameSortBy, array('firstname', 'lastname'))) { return $userNameSortBy == 'firstname' ? true : false; } diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 3b592cc9a4..54dd6b260e 100644 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -83,7 +83,7 @@ class UserManager // Hosting verifications $status = isset($params['status']) ? $params['status'] : STUDENT; - if (api_get_setting('login_is_email') == 'true') { + if (api_get_setting('profile.login_is_email') == 'true') { $params['username'] = $params['email']; } @@ -125,11 +125,11 @@ class UserManager unset($params['return_item_if_already_exists']); - //Checking the user language + // Checking the user language $languages = api_get_languages(); if (!isset($params['language']) || !in_array($params['language'], $languages['folder'])) { - $params['language'] = api_get_setting('platformLanguage'); + $params['language'] = Container::getTranslator()->getLocale(); } if (!isset($params['creator_id'])) { @@ -279,8 +279,9 @@ class UserManager $table_user = Database::get_main_table(TABLE_MAIN_USER); //Checking the user language $languages = api_get_languages(); - if (!in_array($language, $languages['folder'])) { - $language = api_get_setting('platformLanguage'); + + if (!in_array($language, $languages)) { + $language = Container::getTranslator()->getLocale(); } $creator_id = api_get_user_id(); @@ -368,20 +369,48 @@ class UserManager if (!empty($email) && $send_mail) { $recipient_name = api_get_person_name($firstName, $lastName, null, PERSON_NAME_EMAIL_ADDRESS); - $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName'); + $emailsubject = '['.api_get_setting('platform.site_name').'] '.get_lang('YourReg').' '.api_get_setting('platform.site_name'); - $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS); - $email_admin = api_get_setting('emailAdministrator'); + $sender_name = api_get_person_name( + api_get_setting('platform.administrator_name'), + api_get_setting('platform.administrator_surname'), + null, + PERSON_NAME_EMAIL_ADDRESS + ); + $email_admin = api_get_setting('platform.administrator_email'); + $url = api_get_current_access_url_info(); - if (api_is_multiple_url_enabled()) { - $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1) { - $url = api_get_current_access_url_info(); - $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstName, $lastName)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $loginName ."\n". get_lang('Pass')." : ".stripslashes($original_password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator'); - } - } else { - $emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstName, $lastName)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $loginName ."\n". get_lang('Pass')." : ".stripslashes($original_password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". api_get_path(WEB_PUBLIC_PATH) ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator'); - } + $params = array( + 'complete_user_name' => api_get_person_name($firstName, $lastName), + 'login_name' => $loginName, + 'password' => stripslashes($original_password), + 'url' => $url, + ); + + $message = \Swift_Message::newInstance() + ->setSubject($emailsubject) + ->setFrom(array($email_admin => $sender_name)) + ->setTo(array($email => $recipient_name)) + ->setBody( + Container::getTemplate()->render( + 'ChamiloCoreBundle:Mailer:User/new_user.html.twig', + $params + ), + 'text/html' + ) + ->addPart( + Container::getTemplate()->render( + 'ChamiloCoreBundle:Mailer:User/new_user.text.twig', + $params + ), + 'text/plain' + ) + ->setEncoder(Swift_Encoding::get8BitEncoding()); + + $type = $message->getHeaders()->get('Content-Type'); + $type->setValue('text/html'); + $type->setParameter('charset', 'utf-8'); + Container::getMailer()->send($message); /* MANAGE EVENT WITH MAIL */ /*if (EventsMail::check_if_using_class('user_registration')) { @@ -1029,7 +1058,8 @@ class UserManager // 1. Conversion of unacceptable letters (latinian letters with accents for example) into ASCII letters in order they not to be totally removed. // 2. Applying the strict purifier. // 3. Length limitation. - $toreturn = api_get_setting('login_is_email') == 'true' ? substr(preg_replace(USERNAME_PURIFIER_MAIL, '', api_transliterate($username, '', $encoding)), 0, USERNAME_MAX_LENGTH): substr(preg_replace(USERNAME_PURIFIER, '', api_transliterate($username, '', $encoding)), 0, USERNAME_MAX_LENGTH); + $toreturn = api_get_setting('profile.login_is_email') == 'true' ? + substr(preg_replace(USERNAME_PURIFIER_MAIL, '', api_transliterate($username, '', $encoding)), 0, USERNAME_MAX_LENGTH): substr(preg_replace(USERNAME_PURIFIER, '', api_transliterate($username, '', $encoding)), 0, USERNAME_MAX_LENGTH); return $toreturn; } // 1. Applying the shallow purifier. @@ -1324,7 +1354,8 @@ class UserManager $user = Database::fetch_array($res); $picture_filename = trim($user['picture_uri']); - if (api_get_setting('split_users_upload_directory') === 'true') { + if (api_get_setting('profile.split_users_upload_directory') === + 'true') { if ($type == 'system') { $dir = $base.'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/'; } else { diff --git a/src/Chamilo/CoreBundle/EventListener/LegacyListener.php b/src/Chamilo/CoreBundle/EventListener/LegacyListener.php index 984e551a19..e62e58070a 100644 --- a/src/Chamilo/CoreBundle/EventListener/LegacyListener.php +++ b/src/Chamilo/CoreBundle/EventListener/LegacyListener.php @@ -82,7 +82,7 @@ class LegacyListener Container::$htmlEditor = $container->get('chamilo_core.html_editor'); if (!defined('DEFAULT_DOCUMENT_QUOTA')) { - $default_quota = api_get_setting('default_document_quotum'); + $default_quota = api_get_setting('document.default_document_quotum'); // Just in case the setting is not correctly set if (empty($default_quota)) { diff --git a/src/Chamilo/CoreBundle/EventListener/LoginSuccessHandler.php b/src/Chamilo/CoreBundle/EventListener/LoginSuccessHandler.php index 2a44144b3a..04c82edcf7 100644 --- a/src/Chamilo/CoreBundle/EventListener/LoginSuccessHandler.php +++ b/src/Chamilo/CoreBundle/EventListener/LoginSuccessHandler.php @@ -64,7 +64,7 @@ class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface $response = null; /* Possible values: index.php, user_portal.php, main/auth/courses.php */ - $pageAfterLogin = api_get_setting('page_after_login'); + $pageAfterLogin = api_get_setting('registration.page_after_login'); $url = null; if ($this->security->isGranted('ROLE_STUDENT') && !empty($pageAfterLogin)) { @@ -82,8 +82,7 @@ class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface } // Redirecting to a course or a session - - if (api_get_setting('go_to_course_after_login') == 'true') { + if (api_get_setting('course.go_to_course_after_login') == 'true') { // Get the courses list $personal_course_list = \UserManager::get_personal_session_course_list($userId); diff --git a/src/Chamilo/CoreBundle/Resources/views/Mailer/User/new_user.html.twig b/src/Chamilo/CoreBundle/Resources/views/Mailer/User/new_user.html.twig new file mode 100644 index 0000000000..f090370176 --- /dev/null +++ b/src/Chamilo/CoreBundle/Resources/views/Mailer/User/new_user.html.twig @@ -0,0 +1 @@ +{% extends 'ChamiloCoreBundle:Mailer/User:new_user.text.twig' %} diff --git a/src/Chamilo/CoreBundle/Resources/views/Mailer/User/new_user.text.twig b/src/Chamilo/CoreBundle/Resources/views/Mailer/User/new_user.text.twig new file mode 100644 index 0000000000..9fec91b90c --- /dev/null +++ b/src/Chamilo/CoreBundle/Resources/views/Mailer/User/new_user.text.twig @@ -0,0 +1,22 @@ +{% set site_name = chamilo_settings_get('platform.site_name') %} + +{{ 'Dear' | trans }} {{ complete_user_name }}, + +{{ 'YouAreReg' | trans }} {{ site_name }} + +{{ 'WithTheFollowingSettings' | trans }} + +{{ 'Username' | trans }}: {{ login_name }} +{{ 'Password' | trans }}: {{ password }} +{{ 'Address' | trans }}: {{ site_name }} +{{ 'Is' | trans }} {{ url.url }} + +{{ 'Problem' | trans }} +{{ 'Formula' | trans }}, + +{{ chamilo_settings_get('platform.administrator_name') }} +{{ chamilo_settings_get('platform.administrator_surname') }} + +{{ 'Manager' | trans }} {{ site_name }} +{{ chamilo_settings_get('platform.administrator_phone') }} +{{ chamilo_settings_get('platform.administrator_email') }} diff --git a/src/Chamilo/CoreBundle/Settings/AgendaSettingsSchema.php b/src/Chamilo/CoreBundle/Settings/AgendaSettingsSchema.php index 4277638b1b..fca357ce07 100644 --- a/src/Chamilo/CoreBundle/Settings/AgendaSettingsSchema.php +++ b/src/Chamilo/CoreBundle/Settings/AgendaSettingsSchema.php @@ -30,7 +30,7 @@ class AgendaSettingsSchema implements SchemaInterface 'allow_personal_agenda' => array('string'), 'display_mini_month_calendar' => array('string'), 'display_upcoming_events' => array('string'), - 'number_of_upcoming_events' => array('integer'), + 'number_of_upcoming_events' => array('string'), //'default_calendar_view' => array('string'), )) ; diff --git a/src/Chamilo/CoreBundle/Settings/DisplaySettingsSchema.php b/src/Chamilo/CoreBundle/Settings/DisplaySettingsSchema.php index be65475a7d..ec915b13d5 100644 --- a/src/Chamilo/CoreBundle/Settings/DisplaySettingsSchema.php +++ b/src/Chamilo/CoreBundle/Settings/DisplaySettingsSchema.php @@ -46,7 +46,7 @@ class DisplaySettingsSchema implements SchemaInterface 'bug_report_link' => '' )) ->setAllowedTypes(array( - 'time_limit_whosonline' => array('integer') + 'time_limit_whosonline' => array('string') )) ; } diff --git a/src/Chamilo/CoreBundle/Settings/DocumentSettingsSchema.php b/src/Chamilo/CoreBundle/Settings/DocumentSettingsSchema.php index 632e592fb0..9789cbbf8b 100644 --- a/src/Chamilo/CoreBundle/Settings/DocumentSettingsSchema.php +++ b/src/Chamilo/CoreBundle/Settings/DocumentSettingsSchema.php @@ -49,8 +49,8 @@ class DocumentSettingsSchema implements SchemaInterface 'allow_personal_user_files' => '', // ? )) ->setAllowedTypes(array( - 'default_document_quotum' => array('integer'), - 'default_group_quotum' => array('integer'), + 'default_document_quotum' => array('string'), + 'default_group_quotum' => array('string'), 'permanently_remove_deleted_files' => array('string'), )) ; diff --git a/src/Chamilo/CoreBundle/Settings/ExerciseSettingsSchema.php b/src/Chamilo/CoreBundle/Settings/ExerciseSettingsSchema.php index 1b98864911..018ee91d77 100644 --- a/src/Chamilo/CoreBundle/Settings/ExerciseSettingsSchema.php +++ b/src/Chamilo/CoreBundle/Settings/ExerciseSettingsSchema.php @@ -25,8 +25,8 @@ class ExerciseSettingsSchema implements SchemaInterface 'enable_quiz_scenario' => '', )) ->setAllowedTypes(array( - 'exercise_min_score' => array('integer'), - 'exercise_max_score' => array('integer'), + 'exercise_min_score' => array('string'), + 'exercise_max_score' => array('string'), 'enable_quiz_scenario' => array('string'), )) ; diff --git a/src/Chamilo/CoreBundle/Settings/GradebookSettingsSchema.php b/src/Chamilo/CoreBundle/Settings/GradebookSettingsSchema.php index d0cb49f461..68d8de2c72 100644 --- a/src/Chamilo/CoreBundle/Settings/GradebookSettingsSchema.php +++ b/src/Chamilo/CoreBundle/Settings/GradebookSettingsSchema.php @@ -37,8 +37,8 @@ class GradebookSettingsSchema implements SchemaInterface )) ->setAllowedTypes(array( 'gradebook_enable' => array('string'), - 'gradebook_number_decimals' => array('integer'), - 'gradebook_default_weight' => array('integer'), + 'gradebook_number_decimals' => array('string'), + 'gradebook_default_weight' => array('string'), )) ; diff --git a/src/Chamilo/CoreBundle/Settings/MessageSettingsSchema.php b/src/Chamilo/CoreBundle/Settings/MessageSettingsSchema.php index 65790ecbec..fd2a761f12 100644 --- a/src/Chamilo/CoreBundle/Settings/MessageSettingsSchema.php +++ b/src/Chamilo/CoreBundle/Settings/MessageSettingsSchema.php @@ -27,7 +27,7 @@ class MessageSettingsSchema implements SchemaInterface )) ->setAllowedTypes(array( 'allow_message_tool' => array('string'), - 'message_max_upload_filesize' => array('integer') + 'message_max_upload_filesize' => array('string') )) ; } diff --git a/src/Chamilo/CoreBundle/Settings/ProfileSettingsSchema.php b/src/Chamilo/CoreBundle/Settings/ProfileSettingsSchema.php index 0bce6e582f..7ee76e7ff3 100644 --- a/src/Chamilo/CoreBundle/Settings/ProfileSettingsSchema.php +++ b/src/Chamilo/CoreBundle/Settings/ProfileSettingsSchema.php @@ -31,7 +31,7 @@ class ProfileSettingsSchema implements SchemaInterface )) ->setAllowedTypes(array( 'profile' => array('string'), - 'account_valid_duration' => array('integer') + 'account_valid_duration' => array('string') )) ; } diff --git a/src/Chamilo/CoreBundle/Settings/SearchSettingsSchema.php b/src/Chamilo/CoreBundle/Settings/SearchSettingsSchema.php index f35f2f3fdd..18e3ce287b 100644 --- a/src/Chamilo/CoreBundle/Settings/SearchSettingsSchema.php +++ b/src/Chamilo/CoreBundle/Settings/SearchSettingsSchema.php @@ -28,7 +28,7 @@ class SearchSettingsSchema implements SchemaInterface )) ->setAllowedTypes(array( //'allow_personal_agenda' => array('string'), - 'number_of_upcoming_events' => array('integer') + 'number_of_upcoming_events' => array('string') )) ; } diff --git a/src/Chamilo/SettingsBundle/Resources/config/services.xml b/src/Chamilo/SettingsBundle/Resources/config/services.xml index 0a7ac62cbc..81cccad3cd 100644 --- a/src/Chamilo/SettingsBundle/Resources/config/services.xml +++ b/src/Chamilo/SettingsBundle/Resources/config/services.xml @@ -8,6 +8,8 @@ Chamilo\SettingsBundle\Manager\SettingsManager Chamilo\CoreBundle\Entity\Repository\SettingsCurrentRepository Chamilo\CoreBundle\Entity\SettingsCurrent + Chamilo\SettingsBundle\Twig\SettingsExtension + Chamilo\SettingsBundle\Templating\Helper\SettingsHelper @@ -22,6 +24,17 @@ + + + + + + + + + + diff --git a/src/Chamilo/SettingsBundle/Templating/Helper/SettingsHelper.php b/src/Chamilo/SettingsBundle/Templating/Helper/SettingsHelper.php new file mode 100644 index 0000000000..e150d1720c --- /dev/null +++ b/src/Chamilo/SettingsBundle/Templating/Helper/SettingsHelper.php @@ -0,0 +1,17 @@ + + */ +class SettingsExtension extends \Twig_Extension +{ + /** + * @var SettingsHelper + */ + private $helper; + + /** + * @param SettingsHelper $helper + */ + public function __construct(SettingsHelper $helper) + { + $this->helper = $helper; + } + + /** + * {@inheritdoc} + */ + public function getFunctions() + { + return array( + new \Twig_SimpleFunction('chamilo_settings_all', array($this, + 'getSettings')), + new \Twig_SimpleFunction('chamilo_settings_get', array($this, + 'getSettingsParameter')), + ); + } + + /** + * Load settings from given namespace. + * + * @param string $namespace + * + * @return array + */ + public function getSettings($namespace) + { + return $this->helper->getSettings($namespace); + } + + /** + * Load settings parameter for given namespace and name. + * + * @param string $name + * + * @return mixed + */ + public function getSettingsParameter($name) + { + return $this->helper->getSettingsParameter($name); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'chamilo_settings'; + } +}